Commit 679419aa authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

[media] V4L: pxa_camera: convert to the new mbus-config subdev operations

Switch from soc-camera specific .{query,set}_bus_param() to V4L2
subdevice .[gs]_mbus_config() operations.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 92d2c339
...@@ -214,6 +214,7 @@ struct pxa_camera_dev { ...@@ -214,6 +214,7 @@ struct pxa_camera_dev {
unsigned long ciclk; unsigned long ciclk;
unsigned long mclk; unsigned long mclk;
u32 mclk_divisor; u32 mclk_divisor;
u16 width_flags; /* max 10 bits */
struct list_head capture; struct list_head capture;
...@@ -1020,37 +1021,20 @@ static int test_platform_param(struct pxa_camera_dev *pcdev, ...@@ -1020,37 +1021,20 @@ static int test_platform_param(struct pxa_camera_dev *pcdev,
* quick capture interface supports both. * quick capture interface supports both.
*/ */
*flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ? *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
SOCAM_MASTER : SOCAM_SLAVE) | V4L2_MBUS_MASTER : V4L2_MBUS_SLAVE) |
SOCAM_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
SOCAM_HSYNC_ACTIVE_LOW | V4L2_MBUS_HSYNC_ACTIVE_LOW |
SOCAM_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
SOCAM_VSYNC_ACTIVE_LOW | V4L2_MBUS_VSYNC_ACTIVE_LOW |
SOCAM_DATA_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
SOCAM_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_RISING |
SOCAM_PCLK_SAMPLE_FALLING; V4L2_MBUS_PCLK_SAMPLE_FALLING;
/* If requested data width is supported by the platform, use it */ /* If requested data width is supported by the platform, use it */
switch (buswidth) { if ((1 << (buswidth - 1)) & pcdev->width_flags)
case 10: return 0;
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))
return -EINVAL;
*flags |= SOCAM_DATAWIDTH_9;
break;
case 8:
if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8))
return -EINVAL;
*flags |= SOCAM_DATAWIDTH_8;
break;
default:
return -EINVAL;
}
return 0; return -EINVAL;
} }
static void pxa_camera_setup_cicr(struct soc_camera_device *icd, static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
...@@ -1070,12 +1054,12 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, ...@@ -1070,12 +1054,12 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
* Datawidth is now guaranteed to be equal to one of the three values. * Datawidth is now guaranteed to be equal to one of the three values.
* We fix bit-per-pixel equal to data-width... * We fix bit-per-pixel equal to data-width...
*/ */
switch (flags & SOCAM_DATAWIDTH_MASK) { switch (icd->current_fmt->host_fmt->bits_per_sample) {
case SOCAM_DATAWIDTH_10: case 10:
dw = 4; dw = 4;
bpp = 0x40; bpp = 0x40;
break; break;
case SOCAM_DATAWIDTH_9: case 9:
dw = 3; dw = 3;
bpp = 0x20; bpp = 0x20;
break; break;
...@@ -1084,7 +1068,7 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, ...@@ -1084,7 +1068,7 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
* Actually it can only be 8 now, * Actually it can only be 8 now,
* default is just to silence compiler warnings * default is just to silence compiler warnings
*/ */
case SOCAM_DATAWIDTH_8: case 8:
dw = 2; dw = 2;
bpp = 0; bpp = 0;
} }
...@@ -1093,11 +1077,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, ...@@ -1093,11 +1077,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
cicr4 |= CICR4_PCLK_EN; cicr4 |= CICR4_PCLK_EN;
if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
cicr4 |= CICR4_MCLK_EN; cicr4 |= CICR4_MCLK_EN;
if (flags & SOCAM_PCLK_SAMPLE_FALLING) if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
cicr4 |= CICR4_PCP; cicr4 |= CICR4_PCP;
if (flags & SOCAM_HSYNC_ACTIVE_LOW) if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
cicr4 |= CICR4_HSP; cicr4 |= CICR4_HSP;
if (flags & SOCAM_VSYNC_ACTIVE_LOW) if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
cicr4 |= CICR4_VSP; cicr4 |= CICR4_VSP;
cicr0 = __raw_readl(pcdev->base + CICR0); cicr0 = __raw_readl(pcdev->base + CICR0);
...@@ -1151,9 +1135,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, ...@@ -1151,9 +1135,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
{ {
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct pxa_camera_dev *pcdev = ici->priv; struct pxa_camera_dev *pcdev = ici->priv;
unsigned long bus_flags, camera_flags, common_flags; struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
unsigned long bus_flags, common_flags;
int ret; int ret;
struct pxa_cam *cam = icd->host_priv; struct pxa_cam *cam = icd->host_priv;
...@@ -1162,44 +1148,58 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) ...@@ -1162,44 +1148,58 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
if (ret < 0) if (ret < 0)
return ret; return ret;
camera_flags = icd->ops->query_bus_param(icd); ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
if (!ret) {
common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags); common_flags = soc_mbus_config_compatible(&cfg,
if (!common_flags) bus_flags);
return -EINVAL; if (!common_flags) {
dev_warn(icd->parent,
"Flags incompatible: camera 0x%x, host 0x%lx\n",
cfg.flags, bus_flags);
return -EINVAL;
}
} else if (ret != -ENOIOCTLCMD) {
return ret;
} else {
common_flags = bus_flags;
}
pcdev->channels = 1; pcdev->channels = 1;
/* Make choises, based on platform preferences */ /* Make choises, based on platform preferences */
if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
(common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
if (pcdev->platform_flags & PXA_CAMERA_HSP) if (pcdev->platform_flags & PXA_CAMERA_HSP)
common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
else else
common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
} }
if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
(common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
if (pcdev->platform_flags & PXA_CAMERA_VSP) if (pcdev->platform_flags & PXA_CAMERA_VSP)
common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
else else
common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
} }
if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
(common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
if (pcdev->platform_flags & PXA_CAMERA_PCP) if (pcdev->platform_flags & PXA_CAMERA_PCP)
common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
else else
common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
} }
cam->flags = common_flags; cfg.flags = common_flags;
ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
ret = icd->ops->set_bus_param(icd, common_flags); if (ret < 0 && ret != -ENOIOCTLCMD) {
if (ret < 0) dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
common_flags, ret);
return ret; return ret;
}
cam->flags = common_flags;
pxa_camera_setup_cicr(icd, common_flags, pixfmt); pxa_camera_setup_cicr(icd, common_flags, pixfmt);
...@@ -1209,17 +1209,31 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) ...@@ -1209,17 +1209,31 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
static int pxa_camera_try_bus_param(struct soc_camera_device *icd, static int pxa_camera_try_bus_param(struct soc_camera_device *icd,
unsigned char buswidth) unsigned char buswidth)
{ {
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct pxa_camera_dev *pcdev = ici->priv; struct pxa_camera_dev *pcdev = ici->priv;
unsigned long bus_flags, camera_flags; struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
unsigned long bus_flags, common_flags;
int ret = test_platform_param(pcdev, buswidth, &bus_flags); int ret = test_platform_param(pcdev, buswidth, &bus_flags);
if (ret < 0) if (ret < 0)
return ret; return ret;
camera_flags = icd->ops->query_bus_param(icd); ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
if (!ret) {
common_flags = soc_mbus_config_compatible(&cfg,
bus_flags);
if (!common_flags) {
dev_warn(icd->parent,
"Flags incompatible: camera 0x%x, host 0x%lx\n",
cfg.flags, bus_flags);
return -EINVAL;
}
} else if (ret == -ENOIOCTLCMD) {
ret = 0;
}
return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL; return ret;
} }
static const struct soc_mbus_pixelfmt pxa_camera_formats[] = { static const struct soc_mbus_pixelfmt pxa_camera_formats[] = {
...@@ -1687,6 +1701,12 @@ static int __devinit pxa_camera_probe(struct platform_device *pdev) ...@@ -1687,6 +1701,12 @@ static int __devinit pxa_camera_probe(struct platform_device *pdev)
"data widths, using default 10 bit\n"); "data widths, using default 10 bit\n");
pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10; pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10;
} }
if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8)
pcdev->width_flags = 1 << 7;
if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9)
pcdev->width_flags |= 1 << 8;
if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10)
pcdev->width_flags |= 1 << 9;
pcdev->mclk = pcdev->pdata->mclk_10khz * 10000; pcdev->mclk = pcdev->pdata->mclk_10khz * 10000;
if (!pcdev->mclk) { if (!pcdev->mclk) {
dev_warn(&pdev->dev, dev_warn(&pdev->dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment