summaryrefslogtreecommitdiff
path: root/linux/drivers
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2008-04-15 19:38:06 -0300
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-15 19:38:06 -0300
commit2a22ae17b682a6c213c0e7403342f3b17d80879a (patch)
treeb7b1aeb09d21f107d2de32a3503a25676c6bb539 /linux/drivers
parent486515dead96045358246b7b3cd1370ca8cb7808 (diff)
downloadmediapointer-dvb-s2-2a22ae17b682a6c213c0e7403342f3b17d80879a.tar.gz
mediapointer-dvb-s2-2a22ae17b682a6c213c0e7403342f3b17d80879a.tar.bz2
soc-camera: re-sync with -git tree
From: Mauro Carvalho Chehab <mchehab@infradead.org> The proper fix were applied at -git. Re-apply the missing parts with the new base. Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'linux/drivers')
-rw-r--r--linux/drivers/media/video/mt9m001.c101
-rw-r--r--linux/drivers/media/video/mt9v022.c155
-rw-r--r--linux/drivers/media/video/pxa_camera.c317
-rw-r--r--linux/drivers/media/video/soc_camera.c142
4 files changed, 428 insertions, 287 deletions
diff --git a/linux/drivers/media/video/mt9m001.c b/linux/drivers/media/video/mt9m001.c
index 879f61ac4..3fb5f63df 100644
--- a/linux/drivers/media/video/mt9m001.c
+++ b/linux/drivers/media/video/mt9m001.c
@@ -210,40 +210,64 @@ static int bus_switch_act(struct mt9m001 *mt9m001, int go8bit)
#endif
}
-static int mt9m001_set_capture_format(struct soc_camera_device *icd,
- __u32 pixfmt, struct v4l2_rect *rect, unsigned int flags)
+static int bus_switch_possible(struct mt9m001 *mt9m001)
+{
+#ifdef CONFIG_MT9M001_PCA9536_SWITCH
+ return gpio_is_valid(mt9m001->switch_gpio);
+#else
+ return 0;
+#endif
+}
+
+static int mt9m001_set_bus_param(struct soc_camera_device *icd,
+ unsigned long flags)
{
struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
- unsigned int width_flag = flags & (IS_DATAWIDTH_10 | IS_DATAWIDTH_9 |
- IS_DATAWIDTH_8);
+ unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
int ret;
- const u16 hblank = 9, vblank = 25;
- /* MT9M001 has all capture_format parameters fixed */
- if (!(flags & IS_MASTER) ||
- !(flags & IS_PCLK_SAMPLE_RISING) ||
- !(flags & IS_HSYNC_ACTIVE_HIGH) ||
- !(flags & IS_VSYNC_ACTIVE_HIGH))
- return -EINVAL;
-
- /* Only one width bit may be set */
- if (!is_power_of_2(width_flag))
- return -EINVAL;
+ /* Flags validity verified in test_bus_param */
- if ((mt9m001->datawidth != 10 && (width_flag == IS_DATAWIDTH_10)) ||
- (mt9m001->datawidth != 9 && (width_flag == IS_DATAWIDTH_9)) ||
- (mt9m001->datawidth != 8 && (width_flag == IS_DATAWIDTH_8))) {
+ if ((mt9m001->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) ||
+ (mt9m001->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) ||
+ (mt9m001->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) {
/* Well, we actually only can do 10 or 8 bits... */
- if (width_flag == IS_DATAWIDTH_9)
+ if (width_flag == SOCAM_DATAWIDTH_9)
return -EINVAL;
ret = bus_switch_act(mt9m001,
- width_flag == IS_DATAWIDTH_8);
+ width_flag == SOCAM_DATAWIDTH_8);
if (ret < 0)
return ret;
- mt9m001->datawidth = width_flag == IS_DATAWIDTH_8 ? 8 : 10;
+ mt9m001->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
}
+ return 0;
+}
+
+static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
+{
+ struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+ unsigned int width_flag = SOCAM_DATAWIDTH_10;
+
+ if (bus_switch_possible(mt9m001))
+ width_flag |= SOCAM_DATAWIDTH_8;
+
+ /* MT9M001 has all capture_format parameters fixed */
+ return SOCAM_PCLK_SAMPLE_RISING |
+ SOCAM_HSYNC_ACTIVE_HIGH |
+ SOCAM_VSYNC_ACTIVE_HIGH |
+ SOCAM_MASTER |
+ width_flag;
+}
+
+static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
+ __u32 pixfmt, struct v4l2_rect *rect)
+{
+ struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+ int ret;
+ const u16 hblank = 9, vblank = 25;
+
/* Blanking and start values - default... */
ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank);
if (ret >= 0)
@@ -348,12 +372,6 @@ static int mt9m001_set_register(struct soc_camera_device *icd,
}
#endif
-static unsigned int mt9m001_get_datawidth(struct soc_camera_device *icd)
-{
- struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
- return mt9m001->datawidth;
-}
-
const struct v4l2_queryctrl mt9m001_controls[] = {
{
.id = V4L2_CID_VFLIP,
@@ -392,20 +410,23 @@ const struct v4l2_queryctrl mt9m001_controls[] = {
}
};
-static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl);
-static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl);
+static int mt9m001_video_probe(struct soc_camera_device *);
+static void mt9m001_video_remove(struct soc_camera_device *);
+static int mt9m001_get_control(struct soc_camera_device *, struct v4l2_control *);
+static int mt9m001_set_control(struct soc_camera_device *, struct v4l2_control *);
static struct soc_camera_ops mt9m001_ops = {
.owner = THIS_MODULE,
+ .probe = mt9m001_video_probe,
+ .remove = mt9m001_video_remove,
.init = mt9m001_init,
.release = mt9m001_release,
.start_capture = mt9m001_start_capture,
.stop_capture = mt9m001_stop_capture,
- .set_capture_format = mt9m001_set_capture_format,
+ .set_fmt_cap = mt9m001_set_fmt_cap,
.try_fmt_cap = mt9m001_try_fmt_cap,
- .formats = NULL, /* Filled in later depending on the */
- .num_formats = 0, /* camera type and data widths */
- .get_datawidth = mt9m001_get_datawidth,
+ .set_bus_param = mt9m001_set_bus_param,
+ .query_bus_param = mt9m001_query_bus_param,
.controls = mt9m001_controls,
.num_controls = ARRAY_SIZE(mt9m001_controls),
.get_control = mt9m001_get_control,
@@ -554,19 +575,19 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
case 0x8411:
case 0x8421:
mt9m001->model = V4L2_IDENT_MT9M001C12ST;
- mt9m001_ops.formats = mt9m001_colour_formats;
+ icd->formats = mt9m001_colour_formats;
if (mt9m001->client->dev.platform_data)
- mt9m001_ops.num_formats = ARRAY_SIZE(mt9m001_colour_formats);
+ icd->num_formats = ARRAY_SIZE(mt9m001_colour_formats);
else
- mt9m001_ops.num_formats = 1;
+ icd->num_formats = 1;
break;
case 0x8431:
mt9m001->model = V4L2_IDENT_MT9M001C12STM;
- mt9m001_ops.formats = mt9m001_monochrome_formats;
+ icd->formats = mt9m001_monochrome_formats;
if (mt9m001->client->dev.platform_data)
- mt9m001_ops.num_formats = ARRAY_SIZE(mt9m001_monochrome_formats);
+ icd->num_formats = ARRAY_SIZE(mt9m001_monochrome_formats);
else
- mt9m001_ops.num_formats = 1;
+ icd->num_formats = 1;
break;
default:
ret = -ENODEV;
@@ -627,8 +648,6 @@ static int mt9m001_probe(struct i2c_client *client)
/* Second stage probe - when a capture adapter is there */
icd = &mt9m001->icd;
- icd->probe = mt9m001_video_probe;
- icd->remove = mt9m001_video_remove;
icd->ops = &mt9m001_ops;
icd->control = &client->dev;
icd->x_min = 20;
diff --git a/linux/drivers/media/video/mt9v022.c b/linux/drivers/media/video/mt9v022.c
index d677344d2..d4b9e2744 100644
--- a/linux/drivers/media/video/mt9v022.c
+++ b/linux/drivers/media/video/mt9v022.c
@@ -241,19 +241,89 @@ static int bus_switch_act(struct mt9v022 *mt9v022, int go8bit)
#endif
}
-static int mt9v022_set_capture_format(struct soc_camera_device *icd,
- __u32 pixfmt, struct v4l2_rect *rect, unsigned int flags)
+static int bus_switch_possible(struct mt9v022 *mt9v022)
+{
+#ifdef CONFIG_MT9V022_PCA9536_SWITCH
+ return gpio_is_valid(mt9v022->switch_gpio);
+#else
+ return 0;
+#endif
+}
+
+static int mt9v022_set_bus_param(struct soc_camera_device *icd,
+ unsigned long flags)
{
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
- unsigned int width_flag = flags & (IS_DATAWIDTH_10 | IS_DATAWIDTH_9 |
- IS_DATAWIDTH_8);
- u16 pixclk = 0;
+ unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
int ret;
+ u16 pixclk = 0;
/* Only one width bit may be set */
if (!is_power_of_2(width_flag))
return -EINVAL;
+ if ((mt9v022->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) ||
+ (mt9v022->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) ||
+ (mt9v022->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) {
+ /* Well, we actually only can do 10 or 8 bits... */
+ if (width_flag == SOCAM_DATAWIDTH_9)
+ return -EINVAL;
+
+ ret = bus_switch_act(mt9v022,
+ width_flag == SOCAM_DATAWIDTH_8);
+ if (ret < 0)
+ return ret;
+
+ mt9v022->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
+ }
+
+ if (flags & SOCAM_PCLK_SAMPLE_RISING)
+ pixclk |= 0x10;
+
+ if (!(flags & SOCAM_HSYNC_ACTIVE_HIGH))
+ pixclk |= 0x1;
+
+ if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH))
+ pixclk |= 0x2;
+
+ ret = reg_write(icd, MT9V022_PIXCLK_FV_LV, pixclk);
+ if (ret < 0)
+ return ret;
+
+ if (!(flags & SOCAM_MASTER))
+ mt9v022->chip_control &= ~0x8;
+
+ ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
+ if (ret < 0)
+ return ret;
+
+ dev_dbg(&icd->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
+ pixclk, mt9v022->chip_control);
+
+ return 0;
+}
+
+static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
+{
+ struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
+ unsigned int width_flag = SOCAM_DATAWIDTH_10;
+
+ if (bus_switch_possible(mt9v022))
+ width_flag |= SOCAM_DATAWIDTH_8;
+
+ return SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
+ SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
+ SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
+ SOCAM_MASTER | SOCAM_SLAVE |
+ width_flag;
+}
+
+static int mt9v022_set_fmt_cap(struct soc_camera_device *icd,
+ __u32 pixfmt, struct v4l2_rect *rect)
+{
+ struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
+ int ret;
+
/* The caller provides a supported format, as verified per call to
* icd->try_fmt_cap(), datawidth is from our supported format list */
switch (pixfmt) {
@@ -308,44 +378,6 @@ static int mt9v022_set_capture_format(struct soc_camera_device *icd,
dev_dbg(&icd->dev, "Frame %ux%u pixel\n", rect->width, rect->height);
- if ((mt9v022->datawidth != 10 && (width_flag == IS_DATAWIDTH_10)) ||
- (mt9v022->datawidth != 9 && (width_flag == IS_DATAWIDTH_9)) ||
- (mt9v022->datawidth != 8 && (width_flag == IS_DATAWIDTH_8))) {
- /* Well, we actually only can do 10 or 8 bits... */
- if (width_flag == IS_DATAWIDTH_9)
- return -EINVAL;
-
- ret = bus_switch_act(mt9v022,
- width_flag == IS_DATAWIDTH_8);
- if (ret < 0)
- return ret;
-
- mt9v022->datawidth = width_flag == IS_DATAWIDTH_8 ? 8 : 10;
- }
-
- if (flags & IS_PCLK_SAMPLE_RISING)
- pixclk |= 0x10;
-
- if (!(flags & IS_HSYNC_ACTIVE_HIGH))
- pixclk |= 0x1;
-
- if (!(flags & IS_VSYNC_ACTIVE_HIGH))
- pixclk |= 0x2;
-
- ret = reg_write(icd, MT9V022_PIXCLK_FV_LV, pixclk);
- if (ret < 0)
- return ret;
-
- if (!(flags & IS_MASTER))
- mt9v022->chip_control &= ~0x8;
-
- ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
- if (ret < 0)
- return ret;
-
- dev_dbg(&icd->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
- pixclk, mt9v022->chip_control);
-
return 0;
}
@@ -420,12 +452,6 @@ static int mt9v022_set_register(struct soc_camera_device *icd,
}
#endif
-static unsigned int mt9v022_get_datawidth(struct soc_camera_device *icd)
-{
- struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
- return mt9v022->datawidth;
-}
-
const struct v4l2_queryctrl mt9v022_controls[] = {
{
.id = V4L2_CID_VFLIP,
@@ -480,22 +506,23 @@ const struct v4l2_queryctrl mt9v022_controls[] = {
}
};
-static int mt9v022_get_control(struct soc_camera_device *icd,
- struct v4l2_control *ctrl);
-static int mt9v022_set_control(struct soc_camera_device *icd,
- struct v4l2_control *ctrl);
+static int mt9v022_video_probe(struct soc_camera_device *);
+static void mt9v022_video_remove(struct soc_camera_device *);
+static int mt9v022_get_control(struct soc_camera_device *, struct v4l2_control *);
+static int mt9v022_set_control(struct soc_camera_device *, struct v4l2_control *);
static struct soc_camera_ops mt9v022_ops = {
.owner = THIS_MODULE,
+ .probe = mt9v022_video_probe,
+ .remove = mt9v022_video_remove,
.init = mt9v022_init,
.release = mt9v022_release,
.start_capture = mt9v022_start_capture,
.stop_capture = mt9v022_stop_capture,
- .set_capture_format = mt9v022_set_capture_format,
+ .set_fmt_cap = mt9v022_set_fmt_cap,
.try_fmt_cap = mt9v022_try_fmt_cap,
- .formats = NULL, /* Filled in later depending on the */
- .num_formats = 0, /* sensor type and data widths */
- .get_datawidth = mt9v022_get_datawidth,
+ .set_bus_param = mt9v022_set_bus_param,
+ .query_bus_param = mt9v022_query_bus_param,
.controls = mt9v022_controls,
.num_controls = ARRAY_SIZE(mt9v022_controls),
.get_control = mt9v022_get_control,
@@ -678,19 +705,19 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
!strcmp("color", sensor_type))) {
ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11);
mt9v022->model = V4L2_IDENT_MT9V022IX7ATC;
- mt9v022_ops.formats = mt9v022_colour_formats;
+ icd->formats = mt9v022_colour_formats;
if (mt9v022->client->dev.platform_data)
- mt9v022_ops.num_formats = ARRAY_SIZE(mt9v022_colour_formats);
+ icd->num_formats = ARRAY_SIZE(mt9v022_colour_formats);
else
- mt9v022_ops.num_formats = 1;
+ icd->num_formats = 1;
} else {
ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11);
mt9v022->model = V4L2_IDENT_MT9V022IX7ATM;
- mt9v022_ops.formats = mt9v022_monochrome_formats;
+ icd->formats = mt9v022_monochrome_formats;
if (mt9v022->client->dev.platform_data)
- mt9v022_ops.num_formats = ARRAY_SIZE(mt9v022_monochrome_formats);
+ icd->num_formats = ARRAY_SIZE(mt9v022_monochrome_formats);
else
- mt9v022_ops.num_formats = 1;
+ icd->num_formats = 1;
}
if (ret >= 0)
@@ -746,8 +773,6 @@ static int mt9v022_probe(struct i2c_client *client)
i2c_set_clientdata(client, mt9v022);
icd = &mt9v022->icd;
- icd->probe = mt9v022_video_probe;
- icd->remove = mt9v022_video_remove;
icd->ops = &mt9v022_ops;
icd->control = &client->dev;
icd->x_min = 1;
diff --git a/linux/drivers/media/video/pxa_camera.c b/linux/drivers/media/video/pxa_camera.c
index 023d18c62..936db67a5 100644
--- a/linux/drivers/media/video/pxa_camera.c
+++ b/linux/drivers/media/video/pxa_camera.c
@@ -10,10 +10,9 @@
* (at your option) any later version.
*/
-#include <asm/io.h>
-
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/io.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/errno.h>
@@ -42,6 +41,26 @@
#define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5)
#define PXA_CAM_DRV_NAME "pxa27x-camera"
+#define CICR0_SIM_MP (0 << 24)
+#define CICR0_SIM_SP (1 << 24)
+#define CICR0_SIM_MS (2 << 24)
+#define CICR0_SIM_EP (3 << 24)
+#define CICR0_SIM_ES (4 << 24)
+
+#define CICR1_DW_VAL(x) ((x) & CICR1_DW) /* Data bus width */
+#define CICR1_PPL_VAL(x) (((x) << 15) & CICR1_PPL) /* Pixels per line */
+
+#define CICR2_BLW_VAL(x) (((x) << 24) & CICR2_BLW) /* Beginning-of-line pixel clock wait count */
+#define CICR2_ELW_VAL(x) (((x) << 16) & CICR2_ELW) /* End-of-line pixel clock wait count */
+#define CICR2_HSW_VAL(x) (((x) << 10) & CICR2_HSW) /* Horizontal sync pulse width */
+#define CICR2_BFPW_VAL(x) (((x) << 3) & CICR2_BFPW) /* Beginning-of-frame pixel clock wait count */
+#define CICR2_FSW_VAL(x) (((x) << 0) & CICR2_FSW) /* Frame stabilization wait count */
+
+#define CICR3_BFW_VAL(x) (((x) << 24) & CICR3_BFW) /* Beginning-of-frame line clock wait count */
+#define CICR3_EFW_VAL(x) (((x) << 16) & CICR3_EFW) /* End-of-frame line clock wait count */
+#define CICR3_VSW_VAL(x) (((x) << 11) & CICR3_VSW) /* Vertical sync pulse width */
+#define CICR3_LPF_VAL(x) (((x) << 0) & CICR3_LPF) /* Lines per frame */
+
#define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \
CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \
CICR0_EOFM | CICR0_FOM)
@@ -83,8 +102,6 @@ struct pxa_camera_dev {
void __iomem *base;
unsigned int dma_chan_y;
- enum v4l2_buf_type type;
-
struct pxacamera_platform_data *pdata;
struct resource *res;
unsigned long platform_flags;
@@ -94,8 +111,6 @@ struct pxa_camera_dev {
spinlock_t lock;
- int dma_running;
-
struct pxa_buffer *active;
};
@@ -106,9 +121,8 @@ static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
/*
* Videobuf operations
*/
-static int
-pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
- unsigned int *size)
+static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
+ unsigned int *size)
{
struct soc_camera_device *icd = vq->priv_data;
@@ -151,9 +165,8 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
buf->vb.state = VIDEOBUF_NEEDS_INIT;
}
-static int
-pxa_videobuf_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
- enum v4l2_field field)
+static int pxa_videobuf_prepare(struct videobuf_queue *vq,
+ struct videobuf_buffer *vb, enum v4l2_field field)
{
struct soc_camera_device *icd = vq->priv_data;
struct soc_camera_host *ici =
@@ -255,15 +268,15 @@ out:
return ret;
}
-static void
-pxa_videobuf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
+static void pxa_videobuf_queue(struct videobuf_queue *vq,
+ struct videobuf_buffer *vb)
{
struct soc_camera_device *icd = vq->priv_data;
struct soc_camera_host *ici =
to_soc_camera_host(icd->dev.parent);
struct pxa_camera_dev *pcdev = ici->priv;
struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
- struct pxa_buffer *active = pcdev->active;
+ struct pxa_buffer *active;
struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
int nents = dma->sglen;
unsigned long flags;
@@ -275,8 +288,9 @@ pxa_videobuf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
list_add_tail(&vb->queue, &pcdev->capture);
vb->state = VIDEOBUF_ACTIVE;
+ active = pcdev->active;
- if (!pcdev->active) {
+ if (!active) {
CIFR |= CIFR_RESET_F;
DDADR(pcdev->dma_chan_y) = buf->sg_dma;
DCSR(pcdev->dma_chan_y) = DCSR_RUN;
@@ -373,22 +387,21 @@ static void pxa_camera_dma_irq_y(int channel, void *data)
spin_lock_irqsave(&pcdev->lock, flags);
status = DCSR(pcdev->dma_chan_y);
+ DCSR(pcdev->dma_chan_y) = status;
+
if (status & DCSR_BUSERR) {
- dev_err(pcdev->dev, "%s: Bus Error\n", __FUNCTION__);
- DCSR(pcdev->dma_chan_y) |= DCSR_BUSERR;
+ dev_err(pcdev->dev, "DMA Bus Error IRQ!\n");
goto out;
}
if (!(status & DCSR_ENDINTR)) {
- dev_err(pcdev->dev, "%s: unknown dma interrupt source. "
- "status: 0x%08x\n", __FUNCTION__, status);
+ dev_err(pcdev->dev, "Unknown DMA IRQ source, "
+ "status: 0x%08x\n", status);
goto out;
}
- DCSR(pcdev->dma_chan_y) |= DCSR_ENDINTR;
-
if (!pcdev->active) {
- dev_err(pcdev->dev, "%s: no active buf\n", __FUNCTION__);
+ dev_err(pcdev->dev, "DMA End IRQ with no active buffer!\n");
goto out;
}
@@ -398,7 +411,7 @@ static void pxa_camera_dma_irq_y(int channel, void *data)
dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
vb, vb->baddr, vb->bsize);
- /* _init is used to debug races, see comment in pxa_is_reqbufs() */
+ /* _init is used to debug races, see comment in pxa_camera_reqbufs() */
list_del_init(&vb->queue);
vb->state = VIDEOBUF_DONE;
do_gettimeofday(&vb->ts);
@@ -419,7 +432,7 @@ out:
spin_unlock_irqrestore(&pcdev->lock, flags);
}
-static struct videobuf_queue_ops pxa_video_ops = {
+static struct videobuf_queue_ops pxa_videobuf_ops = {
.buf_setup = pxa_videobuf_setup,
.buf_prepare = pxa_videobuf_prepare,
.buf_queue = pxa_videobuf_queue,
@@ -444,7 +457,7 @@ static int mclk_get_divisor(struct pxa_camera_dev *pcdev)
return div;
}
-static void pxa_is_activate(struct pxa_camera_dev *pcdev)
+static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
{
struct pxacamera_platform_data *pdata = pcdev->pdata;
u32 cicr4 = 0;
@@ -486,7 +499,7 @@ static void pxa_is_activate(struct pxa_camera_dev *pcdev)
clk_enable(pcdev->clk);
}
-static void pxa_is_deactivate(struct pxa_camera_dev *pcdev)
+static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev)
{
struct pxacamera_platform_data *board = pcdev->pdata;
@@ -518,7 +531,7 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
/* The following two functions absolutely depend on the fact, that
* there can be only one camera on PXA quick capture interface */
-static int pxa_is_add_device(struct soc_camera_device *icd)
+static int pxa_camera_add_device(struct soc_camera_device *icd)
{
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct pxa_camera_dev *pcdev = ici->priv;
@@ -534,7 +547,7 @@ static int pxa_is_add_device(struct soc_camera_device *icd)
dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
icd->devnum);
- pxa_is_activate(pcdev);
+ pxa_camera_activate(pcdev);
ret = icd->ops->init(icd);
if (!ret)
@@ -546,7 +559,7 @@ ebusy:
return ret;
}
-static void pxa_is_remove_device(struct soc_camera_device *icd)
+static void pxa_camera_remove_device(struct soc_camera_device *icd)
{
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct pxa_camera_dev *pcdev = ici->priv;
@@ -563,69 +576,114 @@ static void pxa_is_remove_device(struct soc_camera_device *icd)
icd->ops->release(icd);
- pxa_is_deactivate(pcdev);
+ pxa_camera_deactivate(pcdev);
pcdev->icd = NULL;
}
-static int pxa_is_set_capture_format(struct soc_camera_device *icd,
- __u32 pixfmt, struct v4l2_rect *rect)
+static int test_platform_param(struct pxa_camera_dev *pcdev,
+ unsigned char buswidth, unsigned long *flags)
{
- struct soc_camera_host *ici =
- to_soc_camera_host(icd->dev.parent);
- struct pxa_camera_dev *pcdev = ici->priv;
- unsigned int datawidth = 0, dw, bpp;
- u32 cicr0, cicr4 = 0;
- int ret;
+ /*
+ * Platform specified synchronization and pixel clock polarities are
+ * only a recommendation and are only used during probing. The PXA270
+ * quick capture interface supports both.
+ */
+ *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
+ SOCAM_MASTER : SOCAM_SLAVE) |
+ SOCAM_HSYNC_ACTIVE_HIGH |
+ SOCAM_HSYNC_ACTIVE_LOW |
+ SOCAM_VSYNC_ACTIVE_HIGH |
+ SOCAM_VSYNC_ACTIVE_LOW |
+ SOCAM_PCLK_SAMPLE_RISING |
+ SOCAM_PCLK_SAMPLE_FALLING;
/* If requested data width is supported by the platform, use it */
- switch (icd->cached_datawidth) {
+ switch (buswidth) {
case 10:
- if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10)
- datawidth = IS_DATAWIDTH_10;
+ if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10))
+ return -EINVAL;
+ *flags |= SOCAM_DATAWIDTH_10;
break;
case 9:
- if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9)
- datawidth = IS_DATAWIDTH_9;
+ if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9))
+ return -EINVAL;
+ *flags |= SOCAM_DATAWIDTH_9;
break;
case 8:
- if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8)
- datawidth = IS_DATAWIDTH_8;
+ if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8))
+ return -EINVAL;
+ *flags |= SOCAM_DATAWIDTH_8;
}
- if (!datawidth)
+
+ return 0;
+}
+
+static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
+{
+ struct soc_camera_host *ici =
+ to_soc_camera_host(icd->dev.parent);
+ struct pxa_camera_dev *pcdev = ici->priv;
+ unsigned long dw, bpp, bus_flags, camera_flags, common_flags;
+ u32 cicr0, cicr4 = 0;
+ int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags);
+
+ if (ret < 0)
+ return ret;
+
+ camera_flags = icd->ops->query_bus_param(icd);
+
+ common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
+ if (!common_flags)
return -EINVAL;
- ret = icd->ops->set_capture_format(icd, pixfmt, rect,
- datawidth |
- (pcdev->platform_flags & PXA_CAMERA_MASTER ?
- IS_MASTER : 0) |
- (pcdev->platform_flags & PXA_CAMERA_HSP ?
- 0 : IS_HSYNC_ACTIVE_HIGH) |
- (pcdev->platform_flags & PXA_CAMERA_VSP ?
- 0 : IS_VSYNC_ACTIVE_HIGH) |
- (pcdev->platform_flags & PXA_CAMERA_PCP ?
- 0 : IS_PCLK_SAMPLE_RISING));
+ /* Make choises, based on platform preferences */
+ if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
+ (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
+ if (pcdev->platform_flags & PXA_CAMERA_HSP)
+ common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
+ else
+ common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
+ }
+
+ if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
+ (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
+ if (pcdev->platform_flags & PXA_CAMERA_VSP)
+ common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
+ else
+ common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
+ }
+
+ if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
+ (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
+ if (pcdev->platform_flags & PXA_CAMERA_PCP)
+ common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
+ else
+ common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
+ }
+
+ ret = icd->ops->set_bus_param(icd, common_flags);
if (ret < 0)
return ret;
/* Datawidth is now guaranteed to be equal to one of the three values.
* We fix bit-per-pixel equal to data-width... */
- switch (datawidth) {
- case IS_DATAWIDTH_10:
- icd->cached_datawidth = 10;
+ switch (common_flags & SOCAM_DATAWIDTH_MASK) {
+ case SOCAM_DATAWIDTH_10:
+ icd->buswidth = 10;
dw = 4;
bpp = 0x40;
break;
- case IS_DATAWIDTH_9:
- icd->cached_datawidth = 9;
+ case SOCAM_DATAWIDTH_9:
+ icd->buswidth = 9;
dw = 3;
bpp = 0x20;
break;
default:
/* Actually it can only be 8 now,
* default is just to silence compiler warnings */
- case IS_DATAWIDTH_8:
- icd->cached_datawidth = 8;
+ case SOCAM_DATAWIDTH_8:
+ icd->buswidth = 8;
dw = 2;
bpp = 0;
}
@@ -634,32 +692,54 @@ static int pxa_is_set_capture_format(struct soc_camera_device *icd,
cicr4 |= CICR4_PCLK_EN;
if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
cicr4 |= CICR4_MCLK_EN;
- if (pcdev->platform_flags & PXA_CAMERA_PCP)
+ if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
cicr4 |= CICR4_PCP;
- if (pcdev->platform_flags & PXA_CAMERA_HSP)
+ if (common_flags & SOCAM_HSYNC_ACTIVE_LOW)
cicr4 |= CICR4_HSP;
- if (pcdev->platform_flags & PXA_CAMERA_VSP)
+ if (common_flags & SOCAM_VSYNC_ACTIVE_LOW)
cicr4 |= CICR4_VSP;
cicr0 = CICR0;
if (cicr0 & CICR0_ENB)
CICR0 = cicr0 & ~CICR0_ENB;
- CICR1 = CICR1_PPL_VAL(rect->width - 1) | bpp | dw;
+ CICR1 = CICR1_PPL_VAL(icd->width - 1) | bpp | dw;
CICR2 = 0;
- CICR3 = CICR3_LPF_VAL(rect->height - 1) |
+ CICR3 = CICR3_LPF_VAL(icd->height - 1) |
CICR3_BFW_VAL(min((unsigned short)255, icd->y_skip_top));
CICR4 = mclk_get_divisor(pcdev) | cicr4;
/* CIF interrupts are not used, only DMA */
CICR0 = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
- 0 : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) |
+ CICR0_SIM_MP : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) |
CICR0_DMAEN | CICR0_IRQ_MASK | (cicr0 & CICR0_ENB);
return 0;
}
-static int pxa_is_try_fmt_cap(struct soc_camera_host *ici,
- struct v4l2_format *f)
+static int pxa_camera_try_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
+{
+ struct soc_camera_host *ici =
+ to_soc_camera_host(icd->dev.parent);
+ struct pxa_camera_dev *pcdev = ici->priv;
+ unsigned long bus_flags, camera_flags;
+ int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags);
+
+ if (ret < 0)
+ return ret;
+
+ camera_flags = icd->ops->query_bus_param(icd);
+
+ return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL;
+}
+
+static int pxa_camera_set_fmt_cap(struct soc_camera_device *icd,
+ __u32 pixfmt, struct v4l2_rect *rect)
+{
+ return icd->ops->set_fmt_cap(icd, pixfmt, rect);
+}
+
+static int pxa_camera_try_fmt_cap(struct soc_camera_device *icd,
+ struct v4l2_format *f)
{
/* limit to pxa hardware capabilities */
if (f->fmt.pix.height < 32)
@@ -672,11 +752,12 @@ static int pxa_is_try_fmt_cap(struct soc_camera_host *ici,
f->fmt.pix.width = 2048;
f->fmt.pix.width &= ~0x01;
- return 0;
+ /* limit to sensor capabilities */
+ return icd->ops->try_fmt_cap(icd, f);
}
-static int pxa_is_reqbufs(struct soc_camera_file *icf,
- struct v4l2_requestbuffers *p)
+static int pxa_camera_reqbufs(struct soc_camera_file *icf,
+ struct v4l2_requestbuffers *p)
{
int i;
@@ -694,7 +775,7 @@ static int pxa_is_reqbufs(struct soc_camera_file *icf,
return 0;
}
-static unsigned int pxa_is_poll(struct file *file, poll_table *pt)
+static unsigned int pxa_camera_poll(struct file *file, poll_table *pt)
{
struct soc_camera_file *icf = file->private_data;
struct pxa_buffer *buf;
@@ -711,8 +792,8 @@ static unsigned int pxa_is_poll(struct file *file, poll_table *pt)
return 0;
}
-static int pxa_is_querycap(struct soc_camera_host *ici,
- struct v4l2_capability *cap)
+static int pxa_camera_querycap(struct soc_camera_host *ici,
+ struct v4l2_capability *cap)
{
/* cap->name is set by the firendly caller:-> */
strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card));
@@ -722,18 +803,35 @@ static int pxa_is_querycap(struct soc_camera_host *ici,
return 0;
}
-/* Should beallocated dynamically too, but we have only one. */
+static spinlock_t *pxa_camera_spinlock_alloc(struct soc_camera_file *icf)
+{
+ struct soc_camera_host *ici =
+ to_soc_camera_host(icf->icd->dev.parent);
+ struct pxa_camera_dev *pcdev = ici->priv;
+
+ return &pcdev->lock;
+}
+
+static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
+ .owner = THIS_MODULE,
+ .add = pxa_camera_add_device,
+ .remove = pxa_camera_remove_device,
+ .set_fmt_cap = pxa_camera_set_fmt_cap,
+ .try_fmt_cap = pxa_camera_try_fmt_cap,
+ .reqbufs = pxa_camera_reqbufs,
+ .poll = pxa_camera_poll,
+ .querycap = pxa_camera_querycap,
+ .try_bus_param = pxa_camera_try_bus_param,
+ .set_bus_param = pxa_camera_set_bus_param,
+ .spinlock_alloc = pxa_camera_spinlock_alloc,
+};
+
+/* Should be allocated dynamically too, but we have only one. */
static struct soc_camera_host pxa_soc_camera_host = {
.drv_name = PXA_CAM_DRV_NAME,
- .vbq_ops = &pxa_video_ops,
- .add = pxa_is_add_device,
- .remove = pxa_is_remove_device,
+ .vbq_ops = &pxa_videobuf_ops,
.msize = sizeof(struct pxa_buffer),
- .set_capture_format = pxa_is_set_capture_format,
- .try_fmt_cap = pxa_is_try_fmt_cap,
- .reqbufs = pxa_is_reqbufs,
- .poll = pxa_is_poll,
- .querycap = pxa_is_querycap,
+ .ops = &pxa_soc_camera_host_ops,
};
static int pxa_camera_probe(struct platform_device *pdev)
@@ -753,8 +851,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
if (!pcdev) {
- dev_err(&pdev->dev, "%s: Could not allocate pcdev\n",
- __FUNCTION__);
+ dev_err(&pdev->dev, "Could not allocate pcdev\n");
err = -ENOMEM;
goto exit;
}
@@ -770,8 +867,8 @@ static int pxa_camera_probe(struct platform_device *pdev)
pcdev->pdata = pdev->dev.platform_data;
pcdev->platform_flags = pcdev->pdata->flags;
- if (!pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 |
- PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10)) {
+ if (!(pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 |
+ PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10))) {
/* Platform hasn't set available data widths. This is bad.
* Warn and use a default. */
dev_warn(&pdev->dev, "WARNING! Platform hasn't set available "
@@ -830,7 +927,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
pxa_soc_camera_host.priv = pcdev;
pxa_soc_camera_host.dev.parent = &pdev->dev;
pxa_soc_camera_host.nr = pdev->id;
- err = soc_camera_host_register(&pxa_soc_camera_host, THIS_MODULE);
+ err = soc_camera_host_register(&pxa_soc_camera_host);
if (err)
goto exit_free_irq;
@@ -871,51 +968,17 @@ static int __devexit pxa_camera_remove(struct platform_device *pdev)
kfree(pcdev);
- dev_info(&pdev->dev, "%s: PXA Camera driver unloaded\n", __FUNCTION__);
-
- return 0;
-}
-
-/*
- * Suspend the Camera Module.
- */
-static int pxa_camera_suspend(struct platform_device *pdev, pm_message_t level)
-{
- struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
-
- dev_info(&pdev->dev, "camera suspend\n");
- disable_irq(pcdev->irq);
- return 0;
-}
-
-/*
- * Resume the Camera Module.
- */
-static int pxa_camera_resume(struct platform_device *pdev)
-{
- struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
-
- dev_info(&pdev->dev, "camera resume\n");
- enable_irq(pcdev->irq);
-
-/* if (pcdev) { */ /* FIXME: dev in use? */
-/* DRCMR68 = pcdev->dma_chan_y | DRCMR_MAPVLD; */
-/* DRCMR69 = pcdev->dma_chan_cb | DRCMR_MAPVLD; */
-/* DRCMR70 = pcdev->dma_chan_cr | DRCMR_MAPVLD; */
-/* } */
+ dev_info(&pdev->dev, "PXA Camera driver unloaded\n");
return 0;
}
-
static struct platform_driver pxa_camera_driver = {
.driver = {
.name = PXA_CAM_DRV_NAME,
},
.probe = pxa_camera_probe,
.remove = __exit_p(pxa_camera_remove),
- .suspend = pxa_camera_suspend,
- .resume = pxa_camera_resume,
};
diff --git a/linux/drivers/media/video/soc_camera.c b/linux/drivers/media/video/soc_camera.c
index 124406683..91a1251d9 100644
--- a/linux/drivers/media/video/soc_camera.c
+++ b/linux/drivers/media/video/soc_camera.c
@@ -38,9 +38,9 @@ format_by_fourcc(struct soc_camera_device *icd, unsigned int fourcc)
{
unsigned int i;
- for (i = 0; i < icd->ops->num_formats; i++)
- if (icd->ops->formats[i].fourcc == fourcc)
- return icd->ops->formats + i;
+ for (i = 0; i < icd->num_formats; i++)
+ if (icd->formats[i].fourcc == fourcc)
+ return icd->formats + i;
return NULL;
}
@@ -75,12 +75,13 @@ static int soc_camera_try_fmt_cap(struct file *file, void *priv,
return -EINVAL;
}
- /* limit to host capabilities */
- ret = ici->try_fmt_cap(ici, f);
+ /* test physical bus parameters */
+ ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat);
+ if (ret)
+ return ret;
- /* limit to sensor capabilities */
- if (!ret)
- ret = icd->ops->try_fmt_cap(icd, f);
+ /* limit format to hardware capabilities */
+ ret = ici->ops->try_fmt_cap(icd, f);
/* calculate missing fields */
f->fmt.pix.field = field;
@@ -142,7 +143,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv,
if (ret < 0)
return ret;
- return ici->reqbufs(icf, p);
+ return ici->ops->reqbufs(icf, p);
return ret;
}
@@ -183,6 +184,7 @@ static int soc_camera_open(struct inode *inode, struct file *file)
struct soc_camera_device *icd;
struct soc_camera_host *ici;
struct soc_camera_file *icf;
+ spinlock_t *lock;
int ret;
icf = vmalloc(sizeof(*icf));
@@ -202,19 +204,25 @@ static int soc_camera_open(struct inode *inode, struct file *file)
goto emgd;
}
- if (!try_module_get(ici->owner)) {
+ if (!try_module_get(ici->ops->owner)) {
dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
ret = -EINVAL;
goto emgi;
}
- icd->use_count++;
-
icf->icd = icd;
+ icf->lock = ici->ops->spinlock_alloc(icf);
+ if (!icf->lock) {
+ ret = -ENOMEM;
+ goto esla;
+ }
+
+ icd->use_count++;
+
/* Now we really have to activate the camera */
if (icd->use_count == 1) {
- ret = ici->add(icd);
+ ret = ici->ops->add(icd);
if (ret < 0) {
dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
icd->use_count--;
@@ -228,8 +236,8 @@ static int soc_camera_open(struct inode *inode, struct file *file)
dev_dbg(&icd->dev, "camera device open\n");
/* We must pass NULL as dev pointer, then all pci_* dma operations
- * transform to normal dma_* ones. Do we need an irqlock? */
- videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, NULL,
+ * transform to normal dma_* ones. */
+ videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, icf->lock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
ici->msize, icd);
@@ -237,7 +245,12 @@ static int soc_camera_open(struct inode *inode, struct file *file)
/* All errors are entered with the video_lock held */
eiciadd:
- module_put(ici->owner);
+ lock = icf->lock;
+ icf->lock = NULL;
+ if (ici->ops->spinlock_free)
+ ici->ops->spinlock_free(lock);
+esla:
+ module_put(ici->ops->owner);
emgi:
module_put(icd->ops->owner);
emgd:
@@ -252,16 +265,20 @@ static int soc_camera_close(struct inode *inode, struct file *file)
struct soc_camera_device *icd = icf->icd;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct video_device *vdev = icd->vdev;
+ spinlock_t *lock = icf->lock;
mutex_lock(&video_lock);
icd->use_count--;
if (!icd->use_count)
- ici->remove(icd);
+ ici->ops->remove(icd);
+ icf->lock = NULL;
+ if (ici->ops->spinlock_free)
+ ici->ops->spinlock_free(lock);
module_put(icd->ops->owner);
- module_put(ici->owner);
+ module_put(ici->ops->owner);
mutex_unlock(&video_lock);
- vfree(file->private_data);
+ vfree(icf);
dev_dbg(vdev->dev, "camera device close\n");
@@ -311,7 +328,7 @@ static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
return POLLERR;
}
- return ici->poll(file, pt);
+ return ici->ops->poll(file, pt);
}
@@ -344,8 +361,8 @@ static int soc_camera_s_fmt_cap(struct file *file, void *priv,
if (!data_fmt)
return -EINVAL;
- /* cached_datawidth may be further adjusted by the ici */
- icd->cached_datawidth = data_fmt->depth;
+ /* buswidth may be further adjusted by the ici */
+ icd->buswidth = data_fmt->depth;
ret = soc_camera_try_fmt_cap(file, icf, f);
if (ret < 0)
@@ -355,22 +372,23 @@ static int soc_camera_s_fmt_cap(struct file *file, void *priv,
rect.top = icd->y_current;
rect.width = f->fmt.pix.width;
rect.height = f->fmt.pix.height;
- ret = ici->set_capture_format(icd, f->fmt.pix.pixelformat, &rect);
+ ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
+ if (ret < 0)
+ return ret;
- if (!ret) {
- icd->current_fmt = data_fmt;
- icd->width = rect.width;
- icd->height = rect.height;
- icf->vb_vidq.field = f->fmt.pix.field;
- if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
- dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
- f->type);
-
- dev_dbg(&icd->dev, "set width: %d height: %d\n",
- icd->width, icd->height);
- }
+ icd->current_fmt = data_fmt;
+ icd->width = rect.width;
+ icd->height = rect.height;
+ icf->vb_vidq.field = f->fmt.pix.field;
+ if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
+ dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
+ f->type);
- return ret;
+ dev_dbg(&icd->dev, "set width: %d height: %d\n",
+ icd->width, icd->height);
+
+ /* set physical bus parameters */
+ return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat);
}
static int soc_camera_enum_fmt_cap(struct file *file, void *priv,
@@ -382,10 +400,10 @@ static int soc_camera_enum_fmt_cap(struct file *file, void *priv,
WARN_ON(priv != file->private_data);
- if (f->index >= icd->ops->num_formats)
+ if (f->index >= icd->num_formats)
return -EINVAL;
- format = &icd->ops->formats[f->index];
+ format = &icd->formats[f->index];
strlcpy(f->description, format->name, sizeof(f->description));
f->pixelformat = format->fourcc;
@@ -424,7 +442,7 @@ static int soc_camera_querycap(struct file *file, void *priv,
WARN_ON(priv != file->private_data);
strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
- return ici->querycap(ici, cap);
+ return ici->ops->querycap(ici, cap);
}
static int soc_camera_streamon(struct file *file, void *priv,
@@ -577,7 +595,7 @@ static int soc_camera_s_crop(struct file *file, void *fh,
if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
- ret = ici->set_capture_format(icd, 0, &a->c);
+ ret = ici->ops->set_fmt_cap(icd, 0, &a->c);
if (!ret) {
icd->width = a->c.width;
icd->height = a->c.height;
@@ -699,16 +717,16 @@ static int soc_camera_probe(struct device *dev)
to_soc_camera_host(icd->dev.parent);
int ret;
- if (!icd->probe)
+ if (!icd->ops->probe)
return -ENODEV;
/* We only call ->add() here to activate and probe the camera.
* We shall ->remove() and deactivate it immediately afterwards. */
- ret = ici->add(icd);
+ ret = ici->ops->add(icd);
if (ret < 0)
return ret;
- ret = icd->probe(icd);
+ ret = icd->ops->probe(icd);
if (ret >= 0) {
const struct v4l2_queryctrl *qctrl;
@@ -718,7 +736,7 @@ static int soc_camera_probe(struct device *dev)
icd->exposure = qctrl ? qctrl->default_value :
(unsigned short)~0;
}
- ici->remove(icd);
+ ici->ops->remove(icd);
return ret;
}
@@ -729,8 +747,8 @@ static int soc_camera_remove(struct device *dev)
{
struct soc_camera_device *icd = to_soc_camera_dev(dev);
- if (icd->remove)
- icd->remove(icd);
+ if (icd->ops->remove)
+ icd->ops->remove(icd);
return 0;
}
@@ -760,12 +778,27 @@ static void dummy_release(struct device *dev)
{
}
-int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner)
+static spinlock_t *spinlock_alloc(struct soc_camera_file *icf)
+{
+ spinlock_t *lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
+
+ if (lock)
+ spin_lock_init(lock);
+
+ return lock;
+}
+
+static void spinlock_free(spinlock_t *lock)
+{
+ kfree(lock);
+}
+
+int soc_camera_host_register(struct soc_camera_host *ici)
{
int ret;
struct soc_camera_host *ix;
- if (!ici->vbq_ops || !ici->add || !ici->remove || !owner)
+ if (!ici->vbq_ops || !ici->ops->add || !ici->ops->remove)
return -EINVAL;
/* Number might be equal to the platform device ID */
@@ -783,7 +816,6 @@ int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner)
list_add_tail(&ici->list, &hosts);
mutex_unlock(&list_lock);
- ici->owner = owner;
ici->dev.release = dummy_release;
ret = device_register(&ici->dev);
@@ -791,6 +823,11 @@ int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner)
if (ret)
goto edevr;
+ if (!ici->ops->spinlock_alloc) {
+ ici->ops->spinlock_alloc = spinlock_alloc;
+ ici->ops->spinlock_free = spinlock_free;
+ }
+
scan_add_host(ici);
return 0;
@@ -817,7 +854,7 @@ void soc_camera_host_unregister(struct soc_camera_host *ici)
if (icd->dev.parent == &ici->dev) {
device_unregister(&icd->dev);
/* Not before device_unregister(), .remove
- * needs parent to call ici->remove() */
+ * needs parent to call ici->ops->remove() */
icd->dev.parent = NULL;
memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
}
@@ -860,9 +897,6 @@ int soc_camera_device_register(struct soc_camera_device *icd)
icd->dev.release = dummy_release;
- if (icd->ops->get_datawidth)
- icd->cached_datawidth = icd->ops->get_datawidth(icd);
-
return scan_add_device(icd);
}
EXPORT_SYMBOL(soc_camera_device_register);
@@ -929,7 +963,7 @@ int soc_camera_video_start(struct soc_camera_device *icd)
vdev->vidioc_s_register = soc_camera_s_register;
#endif
- icd->current_fmt = &icd->ops->formats[0];
+ icd->current_fmt = &icd->formats[0];
err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
if (err < 0) {