Renesas CEU driver
Jacopo Mondi
maintainerv4 cover Renesas CEU driver
Hello Laurent and Renesas list,
this is new version of Capture Engine Unit driver.
Compared to "RFC v3", still in review, patches [02/08] and [03/08] are un-changed. I have added changes to the newly developed CEU driver in a separate patch ([04/08) to ease the review process.
Not having modified the CEU driver sent in "RFC v3", refer to that series for a more detailed description of patches [02/08] and [03/08].
In this series I have added modification to Migo-R startup code to use the new CE driver with the two sensors installed on that board. Both sensor drivers were soc_camera dependent, and I have removed that dependency in patches [06/08] and [07/08]. The drivers have not been moved yet from soc_camera sub-directory not to break other platforms.
Patch [05/08] is a fix required to have ov772x probe properly, and has already been sent to linux-media as stand-alone fix.
Series is in RFC as I have not tested image capture yet, nor I have update other sh platforms to use the new CEU header, introduced with patch [01/08].
On Migo-R I have verified the sensors probe correctly, and a video device gets registered after both async sensor notification have been received by the CEU driver.
ov772x 0-0021: ov7725 Product ID 77:21 Manufacturer ID 7f:a2 tw9910 0-0045: tw9910 Product ID b:0
renesas-ceu renesas-ceu.0: Video device registered
Next step is to test image capture and possibly input selection on Migo-R platform.
Thanks
j
Jacopo Mondi (8):
include: media: Move and update CEU driver interface
media: platform: soc-camera: Remove SH CEU driver
media: platform: Add Renesas CEU driver
media: platform: ceu: Support for multiple subdevs
media: i2c: ov772x: Force use of SCCB protocol
media: i2c: ov772x: Remove soc_camera dependencies
media: i2c: tw9910: Remove soc_camera dependencies
arch: sh: migor: Use new CEU camera driver
arch/sh/boards/mach-migor/setup.c | 126 +- drivers/media/i2c/soc_camera/ov772x.c | 96 +- drivers/media/i2c/soc_camera/tw9910.c | 68 +- drivers/media/platform/Kconfig | 8 + drivers/media/platform/Makefile | 2 + drivers/media/platform/renesas-ceu.c | 1669 ++++++++++++++++++ drivers/media/platform/soc_camera/Kconfig | 10 - drivers/media/platform/soc_camera/Makefile | 1 - .../platform/soc_camera/sh_mobile_ceu_camera.c | 1821 -------------------- include/media/drv-intf/renesas_ceu.h | 28 + include/media/drv-intf/sh_mobile_ceu.h | 28 - include/media/i2c/ov772x.h | 3 + include/media/i2c/tw9910.h | 6 + 13 files changed, 1878 insertions(+), 1988 deletions(-) create mode 100644 drivers/media/platform/renesas-ceu.c delete mode 100644 drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c create mode 100644 include/media/drv-intf/renesas_ceu.h delete mode 100644 include/media/drv-intf/sh_mobile_ceu.h
--
2.7.4
Jacopo Mondi
maintainerRFC v4 1/8 include: media: Move and update CEU driver interface
Update Renesas CEU driver interface to use driver interface SQUASH
--- include/media/drv-intf/renesas_ceu.h | 28 ++++++++++++++++++++++++++++ include/media/drv-intf/sh_mobile_ceu.h | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 include/media/drv-intf/renesas_ceu.h delete mode 100644 include/media/drv-intf/sh_mobile_ceu.h
include/media/drv-intf/renesas_ceu.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef __ASM_RENESAS_CEU_H__ +#define __ASM_RENESAS_CEU_H__ + +#define CEU_FLAG_USE_8BIT_BUS (1 << 0)/* use 8bit bus width */ +#define CEU_FLAG_USE_16BIT_BUS (1 << 1)/* use 16bit bus width */ +#define CEU_FLAG_HSYNC_LOW (1 << 2)/* default High if possible */ +#define CEU_FLAG_VSYNC_LOW (1 << 3) +#define CEU_FLAG_LOWER_8BIT (1 << 4)/* default upper 8bit */ +#define CEU_FLAG_PRIMARY_SENS (1 << 5)/* sensor is primary */ + +#define CEU_MAX_SENS 2 + +struct device ; +struct resource ; + +struct ceu_async_subdev { +unsigned long flags; +unsigned int i2c_adapter_id; +unsigned int i2c_address; + +}; + +struct ceu_info { +unsigned int num_subdevs; +struct ceu_async_subdev subdevs[CEU_MAX_SENS ]; +}; + +#endif /* __ASM_RENESAS_CEU_H__ */
include/media/drv-intf/sh_mobile_ceu.h deleted +0 -28
@@ -1,28 +0,0 @@ -#ifndef __ASM_SH_MOBILE_CEU_H__ -#define __ASM_SH_MOBILE_CEU_H__ - -#define SH_CEU_FLAG_USE_8BIT_BUS (1 << 0)/* use 8bit bus width */ -#define SH_CEU_FLAG_USE_16BIT_BUS (1 << 1)/* use 16bit bus width */ -#define SH_CEU_FLAG_HSYNC_LOW (1 << 2)/* default High if possible */ -#define SH_CEU_FLAG_VSYNC_LOW (1 << 3)/* default High if possible */ -#define SH_CEU_FLAG_LOWER_8BIT (1 << 4)/* default upper 8bit */ - -struct device ; -struct resource ; - -struct sh_mobile_ceu_companion { -u32 num_resources; -struct resource *resource; -int id; -void *platform_data; -}; - -struct sh_mobile_ceu_info { -unsigned long flags; -int max_width; -int max_height; -struct v4l2_async_subdev **asd;/* Flat array, arranged in groups */ -unsigned int *asd_sizes;/* 0-terminated array pf asd group sizes */ -}; - -#endif /* __ASM_SH_MOBILE_CEU_H__ */
Signature · 1 line
2.7.4
Re: [RFC v4 1/8] include: media: Move and update CEU driver interface
Hi Jacopo,
Thank you for the patch.
Quoted 1 line · On Friday 19 May 2017 18:02:53 Jacopo Mondi wrote:
Update Renesas CEU driver interface to use driver interface
I'm not sure this matches the content of the patch.
Quoted 1 line
SQUASH
? :-)
Quoted 30 lines
Signed-off-by Jacopo Mondi <[email protected]>--- include/media/drv-intf/renesas_ceu.h | 28 ++++++++++++++++++++++++++++ include/media/drv-intf/sh_mobile_ceu.h | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 include/media/drv-intf/renesas_ceu.h delete mode 100644 include/media/drv-intf/sh_mobile_ceu.h(quoted diff) +0
-0
b/include/media/drv-intf/renesas_ceu.hnew file mode 100644 index 0000000..291661dinclude/media/drv-intf/renesas_ceu.h new file +16
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_RENESAS_CEU_H__ +#define __ASM_RENESAS_CEU_H__ + +#define CEU_FLAG_USE_8BIT_BUS (1 << 0)/* use 8bit bus width */ +#define CEU_FLAG_USE_16BIT_BUS (1 << 1)/* use 16bit bus width */ +#define CEU_FLAG_HSYNC_LOW (1 << 2)/* default High if possible */ +#define CEU_FLAG_VSYNC_LOW (1 << 3) +#define CEU_FLAG_LOWER_8BIT (1 << 4)/* default upper 8bit */ +#define CEU_FLAG_PRIMARY_SENS (1 << 5)/* sensor is primary */ + +#define CEU_MAX_SENS 2 + +struct device ; +struct resource ; + +struct ceu_async_subdev {
include/media/drv-intf/renesas_ceu.h line 26
Quoted 10 lines
include/media/drv-intf/renesas_ceu.h new file +10
-0+unsigned long flags; +unsigned int i2c_adapter_id; +unsigned int i2c_address; + +}; + +struct ceu_info { +unsigned int num_subdevs; +struct ceu_async_subdev subdevs[CEU_MAX_SENS ]; +};
You're renaming structures and macros that are in use, this will break compilation when bisecting.
include/media/drv-intf/sh_mobile_ceu.h line 6
Quoted 13 lines
include/media/drv-intf/renesas_ceu.h new file +1
-0+#endif /* __ASM_RENESAS_CEU_H__ */ (quoted diff) +0
-0
b/include/media/drv-intf/sh_mobile_ceu.hdeleted file mode 100644 index 2f43f7d..0000000include/media/drv-intf/sh_mobile_ceu.h deleted +0
-6@@ -1,28 +0,0 @@ -#ifndef __ASM_SH_MOBILE_CEU_H__ -#define __ASM_SH_MOBILE_CEU_H__ - -#define SH_CEU_FLAG_USE_8BIT_BUS (1 << 0)/* use 8bit bus width */ -#define SH_CEU_FLAG_USE_16BIT_BUS (1 << 1)/* use 16bit bus width */ -#define SH_CEU_FLAG_HSYNC_LOW (1 << 2)/* default High if
possible */
include/media/drv-intf/sh_mobile_ceu.h line 7
Quoted 1 line
include/media/drv-intf/sh_mobile_ceu.h deleted +0
-1-#define SH_CEU_FLAG_VSYNC_LOW (1 << 3)/* default High if
possible */
include/media/drv-intf/sh_mobile_ceu.h line 8
Quoted 1 line
include/media/drv-intf/sh_mobile_ceu.h deleted +0
-1-#define SH_CEU_FLAG_LOWER_8BIT (1 << 4)/* default upper 8bit
*/
Quoted 7 lines
include/media/drv-intf/sh_mobile_ceu.h deleted +0
-7- -struct device ; -struct resource ; - -struct sh_mobile_ceu_companion { -u32 num_resources; -struct resource *resource;
include/media/drv-intf/sh_mobile_ceu.h
Quoted 10 lines
include/media/drv-intf/sh_mobile_ceu.h deleted +0
-10-int id; -void *platform_data; -}; - -struct sh_mobile_ceu_info { -unsigned long flags; -int max_width; -int max_height; -struct v4l2_async_subdev **asd;/* Flat array, arranged in groups */ -unsigned int *asd_sizes;/* 0-terminated array pf asd group
sizes */
Quoted 3 lines
include/media/drv-intf/sh_mobile_ceu.h deleted +0
-3-}; - -#endif /* __ASM_SH_MOBILE_CEU_H__ */
Signature · 3 lines
Regards, Laurent Pinchart
Jacopo Mondi
maintainerRFC v4 2/8 media: platform: soc-camera: Remove SH CEU driver
In reply to Jacopo MondiRemove SH Mobile CEU driver from soc-camera framework
--- drivers/media/platform/soc_camera/Kconfig | 10 - drivers/media/platform/soc_camera/Makefile | 1 - .../platform/soc_camera/sh_mobile_ceu_camera.c | 1821 -------------------- 3 files changed, 1832 deletions(-) delete mode 100644 drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
drivers/media/platform/soc_camera/Kconfig +0 -10
@@ -17,16 +17,6 @@ config SOC_CAMERA_PLATFORM help This is a generic SoC camera platform driver, useful for testing -config VIDEO_SH_MOBILE_CEU - tristate "SuperH Mobile CEU Interface driver" - depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA && HAVE_CLK - depends on ARCH_SHMOBILE || COMPILE_TEST - depends on HAS_DMA - select VIDEOBUF2_DMA_CONTIG - select SOC_CAMERA_SCALE_CROP - ---help--- - This is a v4l2 driver for the SuperH Mobile CEU Interface - config VIDEO_ATMEL_ISI tristate "ATMEL Image Sensor Interface (ISI) support" depends on VIDEO_DEV && SOC_CAMERA
drivers/media/platform/soc_camera/Makefile +0 -1
@@ -7,4 +7,3 @@ obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o # soc-camera host drivers have to be linked after camera drivers obj-$(CONFIG_VIDEO_ATMEL_ISI) += atmel-isi.o -obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c deleted +0 -1821
1,821 lines not on this page · raw message
Signature · 1 line
2.7.4
Jacopo Mondi
maintainerRFC v4 3/8 media: platform: Add Renesas CEU driver
In reply to Jacopo MondiAdd driver for Renesas Capture Engine Unit (CEU).
--- drivers/media/platform/Kconfig | 8 + drivers/media/platform/Makefile | 2 + drivers/media/platform/renesas-ceu.c | 1525 ++++++++++++++++++++++++++++++++++ 3 files changed, 1535 insertions(+) create mode 100644 drivers/media/platform/renesas-ceu.c
drivers/media/platform/Kconfig +8 -0
@@ -114,6 +114,14 @@ config VIDEO_S3C_CAMIF To compile this driver as a module, choose M here: the module will be called s3c-camif. +config VIDEO_RENESAS_CEU + tristate "Renesas Capture Engine Unit (CEU) driver" + depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA + depends on ARCH_SHMOBILE || ARCH_R7S72100 || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + ---help--- + This is a v4l2 driver for the Renesas CEU Interface + source "drivers/media/platform/soc_camera/Kconfig" source "drivers/media/platform/exynos4-is/Kconfig" source "drivers/media/platform/am437x/Kconfig"
drivers/media/platform/Makefile +2 -0
@@ -25,6 +25,8 @@ obj-$(CONFIG_VIDEO_CODA) += coda/ obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o +obj-$(CONFIG_VIDEO_RENESAS_CEU) += renesas-ceu.o + obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE) += m2m-deinterlace.o obj-$(CONFIG_VIDEO_S3C_CAMIF) += s3c-camif/
drivers/media/platform/renesas-ceu.c new file +1525 -0
1,525 lines not on this page · raw message
--
2.7.4
Jacopo Mondi
maintainerRFC v4 4/8 media: platform: ceu: Support for multiple subdevs
In reply to Jacopo MondiAdd support for registration of multiple subdevices to renesas CEU driver.
--- drivers/media/platform/renesas-ceu.c | 323 +++++++++++++++++++++++++---------- 1 file changed, 235 insertions(+), 88 deletions(-)
drivers/media/platform/renesas-ceu.c +235 -88
@@ -174,6 +174,27 @@ static inline struct ceu_buffer *vb2_to_ceu(struct vb2_v4l2_buffer *vbuf) }/** +* ceu_subdev - Wraps v4l2 sub-device and provides async notification +*/ +struct ceu_subdev { +struct v4l2_subdev *v4l2_subdev; + +/* async subdev notification */ +struct v4l2_async_notifier notifier; +struct v4l2_async_subdev *asd; + +unsigned int mbus_flags; +struct ceu_mbus_fmt mbus_fmt; + +struct list_head list; +}; + +static inline struct ceu_subdev *to_ceu_subdev (struct v4l2_async_notifier *n) +{ + return container_of(n, struct ceu_subdev, notifier); +} + +/** * ceu_device - CEU device instance */ struct ceu_device {
@@ -181,12 +202,12 @@ struct ceu_device {struct video_device vdev;struct v4l2_device v4l2_dev; -struct v4l2_subdev *sensor; -struct ceu_mbus_fmt sensor_fmt; - -struct v4l2_async_notifier notifier; -struct v4l2_async_subdev asd; -struct v4l2_async_subdev *asds[1 ]; +/* subdevs list, number and current subdev */ +struct list_head subdev_list; +unsigned int num_subdevs; +struct ceu_subdev *subdevs; +struct ceu_subdev *subdev; +unsigned int subdev_index;/* vb2 queue, capture buffer list and active buffer pointer */ struct vb2_queue vb2_vq;
@@ -205,7 +226,6 @@ struct ceu_device {enum v4l2_field field;struct v4l2_pix_format v4l2_pix; -unsigned long mbus_flags;struct ceu_info *pdata; };
@@ -518,11 +538,12 @@ static void ceu_videobuf_queue(struct vb2_buffer *vb)static int ceu_start_streaming (struct vb2_queue *vq,unsigned int count) {struct ceu_device *ceudev =vb2_get_drv_priv (vq); +struct v4l2_subdev *v4l2_sd = ceudev->subdev->v4l2_subdev;struct ceu_buffer *buf;unsigned long irqflags;int ret =0 ; - ret =v4l2_subdev_call (ceudev->sensor, video, s_stream,1 ); + ret =v4l2_subdev_call (v4l2_sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {v4l2_err (&ceudev->v4l2_dev,"stream on failed in subdev\n" ); goto error_return_bufs;
@@ -553,7 +574,7 @@ static int ceu_start_streaming(struct vb2_queue *vq, unsigned int count)return 0 ; error_stop_sensor: -v4l2_subdev_call (ceudev->sensor, video, s_stream,0 ); +v4l2_subdev_call (v4l2_sd, video, s_stream,0 ); error_return_bufs:spin_lock_irqsave (&ceudev->lock, irqflags);
@@ -569,10 +590,11 @@ static int ceu_start_streaming(struct vb2_queue *vq, unsigned int count)static void ceu_stop_streaming (struct vb2_queue *vq) {struct ceu_device *ceudev =vb2_get_drv_priv (vq); +struct v4l2_subdev *v4l2_sd = ceudev->subdev->v4l2_subdev;struct ceu_buffer *buf;unsigned long irqflags; -v4l2_subdev_call (ceudev->sensor, video, s_stream,0 ); +v4l2_subdev_call (v4l2_sd, video, s_stream,0 );spin_lock_irqsave (&ceudev->lock, irqflags);if (ceudev->active) {
@@ -638,14 +660,14 @@ static unsigned int ceu_mbus_config_compatible(*/ static int ceu_test_mbus_param (struct ceu_device *ceudev) { -struct v4l2_subdev *sd = ceudev->sensor; +struct v4l2_subdev *v4l2_sd = ceudev->subdev->v4l2_subdev;unsigned long common_flags =CEU_BUS_FLAGS ;struct v4l2_mbus_config cfg = { .type =V4L2_MBUS_PARALLEL , };int ret; - ret =v4l2_subdev_call (sd, video, g_mbus_config, &cfg); + ret =v4l2_subdev_call (v4l2_sd, video, g_mbus_config, &cfg);if (ret <0 && ret == -ENOIOCTLCMD )return ret;else if (ret == -ENOIOCTLCMD )
@@ -721,10 +743,12 @@ static void ceu_set_sizes(struct ceu_device *ceudev)*/ static int ceu_set_bus_params (struct ceu_device *ceudev) { -struct ceu_mbus_fmt *sensor_fmt = &ceudev->sensor_fmt; +struct ceu_subdev *ceu_sd = ceudev->subdev; +struct ceu_mbus_fmt *mbus_fmt = &ceu_sd->mbus_fmt; +struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_subdev; +unsigned int mbus_flags = ceu_sd->mbus_flags;struct v4l2_pix_format *pix = &ceudev->v4l2_pix;unsigned long common_flags =CEU_BUS_FLAGS ; -struct v4l2_subdev *sd = ceudev->sensor;u32 camcr, caifr, cdocr;int ret;
@@ -748,7 +772,7 @@ static int ceu_set_bus_params(struct ceu_device *ceudev)*/ if ((common_flags &V4L2_MBUS_HSYNC_ACTIVE_HIGH ) && (common_flags &V4L2_MBUS_HSYNC_ACTIVE_LOW )) { -if (ceudev->mbus_flags &CEU_FLAG_HSYNC_LOW ) +if (mbus_flags &CEU_FLAG_HSYNC_LOW ) common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH ;else common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW ;
@@ -756,14 +780,14 @@ static int ceu_set_bus_params(struct ceu_device *ceudev)if ((common_flags &V4L2_MBUS_VSYNC_ACTIVE_HIGH ) && (common_flags &V4L2_MBUS_VSYNC_ACTIVE_LOW )) { -if (ceudev->mbus_flags &CEU_FLAG_VSYNC_LOW ) +if (mbus_flags &CEU_FLAG_VSYNC_LOW ) common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH ;else common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW ; } cfg.flags = common_flags; - ret =v4l2_subdev_call (sd, video, s_mbus_config, &cfg); + ret =v4l2_subdev_call (v4l2_sd, video, s_mbus_config, &cfg);if (ret <0 && ret != -ENOIOCTLCMD )return ret;
@@ -794,20 +818,20 @@ static int ceu_set_bus_params(struct ceu_device *ceudev)case V4L2_PIX_FMT_NV16 : cdocr |=CEU_CDOCR_NO_DOWSAMPLE ;case V4L2_PIX_FMT_NV12 : -if (sensor_fmt->swapped) - camcr |= sensor_fmt->fmt_order_swap; +if (mbus_fmt->swapped) + camcr |= mbus_fmt->fmt_order_swap;else - camcr |= sensor_fmt->fmt_order; + camcr |= mbus_fmt->fmt_order;break ;/* swapped output formats */ case V4L2_PIX_FMT_NV61 : cdocr |=CEU_CDOCR_NO_DOWSAMPLE ;case V4L2_PIX_FMT_NV21 : -if (sensor_fmt->swapped) - camcr |= sensor_fmt->fmt_order; +if (mbus_fmt->swapped) + camcr |= mbus_fmt->fmt_order;else - camcr |= sensor_fmt->fmt_order_swap; + camcr |= mbus_fmt->fmt_order_swap;break ; } camcr |= common_flags &V4L2_MBUS_VSYNC_ACTIVE_LOW ?1 <<1 :0 ;
@@ -869,9 +893,10 @@ static int ceu_set_bus_params(struct ceu_device *ceudev)*/ static int ceu_try_fmt (struct ceu_device *ceudev,struct v4l2_format *v4l2_fmt) { -struct ceu_mbus_fmt *sensor_fmt = &ceudev->sensor_fmt; +struct ceu_subdev *ceu_sd = ceudev->subdev; +struct ceu_mbus_fmt *mbus_fmt = &ceu_sd->mbus_fmt; +struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_subdev;struct v4l2_pix_format *pix = &v4l2_fmt->fmt.pix; -struct v4l2_subdev *sensor = ceudev->sensor;struct v4l2_subdev_pad_config pad_cfg;const struct ceu_fmt *ceu_fmt;int ret;
@@ -912,8 +937,8 @@ static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)* Set format on sensor sub device: bus format is selected at * format initialization time */ -v4l2_fill_mbus_format (&sd_format.format, pix, sensor_fmt->mbus_code); - ret =v4l2_subdev_call (sensor, pad, set_fmt, &pad_cfg, &sd_format); +v4l2_fill_mbus_format (&sd_format.format, pix, mbus_fmt->mbus_code); + ret =v4l2_subdev_call (v4l2_sd, pad, set_fmt, &pad_cfg, &sd_format);if (ret)return ret;
@@ -937,7 +962,9 @@ static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)*/ static int ceu_set_fmt (struct ceu_device *ceudev,struct v4l2_format *v4l2_fmt) { -struct ceu_mbus_fmt *sensor_fmt = &ceudev->sensor_fmt; +struct ceu_subdev *ceu_sd = ceudev->subdev; +struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_subdev; +struct ceu_mbus_fmt *mbus_fmt = &ceu_sd->mbus_fmt;int ret;struct v4l2_subdev_format format = {
@@ -949,9 +976,8 @@ static int ceu_set_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)return ret;v4l2_fill_mbus_format (&format.format, &v4l2_fmt->fmt.pix, - sensor_fmt->mbus_code); - ret =v4l2_subdev_call (ceudev->sensor, pad, - set_fmt,NULL , &format); + mbus_fmt->mbus_code); + ret =v4l2_subdev_call (v4l2_sd, pad, set_fmt,NULL , &format);if (ret)return ret;
@@ -1003,20 +1029,21 @@ static int ceu_set_default_fmt(struct ceu_device *ceudev)*/ static int ceu_init_formats (struct ceu_device *ceudev) { -struct ceu_mbus_fmt *sensor_fmt = &ceudev->sensor_fmt; -struct v4l2_subdev *sensor = ceudev->sensor; +struct ceu_subdev *ceu_sd = ceudev->subdev; +struct ceu_mbus_fmt *mbus_fmt = &ceu_sd->mbus_fmt; +struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_subdev;bool yuyv_bus_fmt = false; -struct v4l2_subdev_mbus_code_enum mbus_fmt = { +struct v4l2_subdev_mbus_code_enum sd_mbus_fmt = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , .index =0 , };/* Find out if sensor can produce any permutation of 8-bits yuyv */ while (!yuyv_bus_fmt && - !v4l2_subdev_call (sensor, pad, enum_mbus_code, -NULL , &mbus_fmt)) { -switch (mbus_fmt.code) { + !v4l2_subdev_call (v4l2_sd, pad, enum_mbus_code, +NULL , &sd_mbus_fmt)) { +switch (sd_mbus_fmt.code) {case MEDIA_BUS_FMT_YUYV8_2X8 :case MEDIA_BUS_FMT_YVYU8_2X8 :case MEDIA_BUS_FMT_UYVY8_2X8 :
@@ -1037,37 +1064,37 @@ static int ceu_init_formats(struct ceu_device *ceudev)if (!yuyv_bus_fmt)return -ENXIO ; -/* -* Save the first encountered YUYV format as "sensor_fmt" and use it +/* +* Save the first encountered YUYV format as "mbus_fmt" and use it * to output all planar YUV422 and YUV420 (NV*) formats to memory. */ - sensor_fmt->mbus_code = mbus_fmt.code; - sensor_fmt->bps =8 ; + mbus_fmt->mbus_code = sd_mbus_fmt.code; + mbus_fmt->bps =8 ;/* Annotate the selected bus format components ordering */ -switch (mbus_fmt.code) { +switch (sd_mbus_fmt.code) {case MEDIA_BUS_FMT_YUYV8_2X8 : - sensor_fmt->fmt_order =CEU_CAMCR_DTARY_8_YUYV ; - sensor_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_YVYU ; - sensor_fmt->swapped = false; + mbus_fmt->fmt_order =CEU_CAMCR_DTARY_8_YUYV ; + mbus_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_YVYU ; + mbus_fmt->swapped = false;break ;case MEDIA_BUS_FMT_YVYU8_2X8 : - sensor_fmt->fmt_order =CEU_CAMCR_DTARY_8_YVYU ; - sensor_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_YUYV ; - sensor_fmt->swapped = true; + mbus_fmt->fmt_order =CEU_CAMCR_DTARY_8_YVYU ; + mbus_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_YUYV ; + mbus_fmt->swapped = true;break ;case MEDIA_BUS_FMT_UYVY8_2X8 : - sensor_fmt->fmt_order =CEU_CAMCR_DTARY_8_UYVY ; - sensor_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_VYUY ; - sensor_fmt->swapped = false; + mbus_fmt->fmt_order =CEU_CAMCR_DTARY_8_UYVY ; + mbus_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_VYUY ; + mbus_fmt->swapped = false;break ;case MEDIA_BUS_FMT_VYUY8_2X8 : - sensor_fmt->fmt_order =CEU_CAMCR_DTARY_8_VYUY ; - sensor_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_UYVY ; - sensor_fmt->swapped = true; + mbus_fmt->fmt_order =CEU_CAMCR_DTARY_8_VYUY ; + mbus_fmt->fmt_order_swap =CEU_CAMCR_DTARY_8_UYVY ; + mbus_fmt->swapped = true;break ; }
@@ -1088,9 +1115,9 @@ static int ceu_init_formats(struct ceu_device *ceudev)static int ceu_runtime_suspend (struct device *dev) {struct ceu_device *ceudev =dev_get_drvdata (dev); -struct v4l2_subdev *sensor = ceudev->sensor; +struct v4l2_subdev *v4l2_sd = ceudev->subdev->v4l2_subdev; -v4l2_subdev_call (sensor, core, s_power,0 ); +v4l2_subdev_call (v4l2_sd, core, s_power,0 );ceu_write (ceudev,CEU_CEIER ,0 );ceu_soft_reset (ceudev);
@@ -1104,9 +1131,9 @@ static int ceu_runtime_suspend(struct device *dev)static int ceu_runtime_resume (struct device *dev) {struct ceu_device *ceudev =dev_get_drvdata (dev); -struct v4l2_subdev *sensor = ceudev->sensor; +struct v4l2_subdev *v4l2_sd = ceudev->subdev->v4l2_subdev; -v4l2_subdev_call (sensor, core, s_power,1 ); +v4l2_subdev_call (v4l2_sd, core, s_power,1 );ceu_soft_reset (ceudev);
@@ -1220,52 +1247,82 @@ static int ceu_enum_input(struct file *file, void *priv,static int ceu_g_input (struct file *file,void *priv,unsigned int *i) { - *i =0 ; +struct ceu_device *ceudev =video_drvdata (file); + + *i = ceudev->subdev_index;return 0 ; }static int ceu_s_input (struct file *file,void *priv,unsigned int i) { -if (i >0 ) +struct ceu_device *ceudev =video_drvdata (file); +struct ceu_subdev *ceu_sd_old; +int ret; + +if (i >= ceudev->num_subdevs)return -EINVAL ; + ceu_sd_old = ceudev->subdev; + ceudev->subdev = &ceudev->subdevs[i]; + +/* +* This is enough to make sure we can generate all available formats, +* as long as we only support planar YUV422/YUV420 as memory output +* formats. +*/ + ret =ceu_init_formats (ceudev); +if (ret) { + ceudev->subdev = ceu_sd_old; +return -EINVAL ; + } + +/* now that we're sure we can use the sensor, power off the old one */ +v4l2_subdev_call (ceu_sd_old->v4l2_subdev, core, s_power,0 ); +v4l2_subdev_call (ceudev->subdev->v4l2_subdev, core, s_power,1 ); + + ceudev->subdev_index = i; +return 0 ; }static int ceu_g_parm (struct file *file,void *fh,struct v4l2_streamparm *a) {struct ceu_device *ceudev =video_drvdata (file); +struct v4l2_subdev *v4l2_subdev = ceudev->subdev->v4l2_subdev;if (a->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -return v4l2_subdev_call (ceudev->sensor, video, g_parm, a); +return v4l2_subdev_call (v4l2_subdev, video, g_parm, a); }static int ceu_s_parm (struct file *file,void *fh,struct v4l2_streamparm *a) {struct ceu_device *ceudev =video_drvdata (file); +struct v4l2_subdev *v4l2_subdev = ceudev->subdev->v4l2_subdev;if (a->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -return v4l2_subdev_call (ceudev->sensor, video, s_parm, a); +return v4l2_subdev_call (v4l2_subdev, video, s_parm, a); }static int ceu_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *fsize) {struct ceu_device *ceudev =video_drvdata (file); +struct ceu_subdev *ceu_sd = ceudev->subdev; +struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_subdev;int ret;struct v4l2_subdev_frame_size_enum fse = { - .code = ceudev->sensor_fmt.mbus_code, + .code = ceu_sd->mbus_fmt.mbus_code, .index = fsize->index, .which =V4L2_SUBDEV_FORMAT_ACTIVE , }; - ret =v4l2_subdev_call (ceudev->sensor, pad, enum_frame_size, + ret =v4l2_subdev_call (v4l2_sd, pad, enum_frame_size,NULL , &fse);if (ret)return ret;
@@ -1281,17 +1338,19 @@ static int ceu_enum_frameintervals(struct file *file, void *fh, struct v4l2_frmivalenum *fival) {struct ceu_device *ceudev =video_drvdata (file); +struct ceu_subdev *ceu_sd = ceudev->subdev; +struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_subdev;int ret;struct v4l2_subdev_frame_interval_enum fie = { - .code = ceudev->sensor_fmt.mbus_code, + .code = ceu_sd->mbus_fmt.mbus_code, .index = fival->index, .width = fival->width, .height = fival->height, .which =V4L2_SUBDEV_FORMAT_ACTIVE , }; - ret =v4l2_subdev_call (ceudev->sensor, pad, enum_frame_interval,NULL , + ret =v4l2_subdev_call (v4l2_sd, pad, enum_frame_interval,NULL , &fie);if (ret)return ret;
@@ -1340,14 +1399,41 @@ void ceu_vdev_release(struct video_device *vdev)kfree (ceudev); } +/** +* ceu_sensor_bound() - Set v4l2_subdev and select primary sensor +*/ static int ceu_sensor_bound (struct v4l2_async_notifier *notifier, -struct v4l2_subdev *subdev, +struct v4l2_subdev *v4l2_sd,struct v4l2_async_subdev *asd) {struct v4l2_device *v4l2_dev = notifier->v4l2_dev;struct ceu_device *ceudev =v4l2_to_ceu (v4l2_dev); +struct ceu_subdev *ceu_sd =to_ceu_subdev (notifier); + +if (video_is_registered (&ceudev->vdev)) { +v4l2_err (&ceudev->v4l2_dev,"only supports one sub-device.\n" ); +return -EBUSY ; + } + +if (ceu_sd->mbus_flags |CEU_FLAG_PRIMARY_SENS && + ceudev->subdev ==NULL ) { + ceudev->subdev_index = ceudev->num_subdevs; + ceudev->subdev = ceu_sd; + } + + ceudev->num_subdevs++; + ceu_sd->v4l2_subdev = v4l2_sd; + +return 0 ; +} + +static int ceu_sensor_complete (struct v4l2_async_notifier *notifier) +{ +struct v4l2_device *v4l2_dev = notifier->v4l2_dev; +struct ceu_device *ceudev =v4l2_to_ceu (v4l2_dev);struct video_device *vdev = &ceudev->vdev;struct vb2_queue *q = &ceudev->vb2_vq; +struct v4l2_subdev *v4l2_sd;int ret;/* Initialize vb2 queue */
@@ -1365,8 +1451,15 @@ static int ceu_sensor_bound(struct v4l2_async_notifier *notifier,if (ret)return ret; -/* Initialize formats and set default format on sensor */ - ceudev->sensor = subdev; +/* +* Make sure at least one sensor is primary and use it to initialize +* ceu formats +*/ +if (ceudev->subdev ==NULL ) + ceudev->subdev =list_first_entry (&ceudev->subdev_list, + struct ceu_subdev, list); + v4l2_sd = ceudev->subdev->v4l2_subdev; + ret =ceu_init_formats (ceudev);if (ret)return ret;
@@ -1380,7 +1473,7 @@ static int ceu_sensor_bound(struct v4l2_async_notifier *notifier, vdev->v4l2_dev = v4l2_dev; vdev->lock = &ceudev->mlock; vdev->queue = &ceudev->vb2_vq; - vdev->ctrl_handler = subdev->ctrl_handler; + vdev->ctrl_handler = v4l2_sd->ctrl_handler; vdev->fops = &ceu_fops; vdev->ioctl_ops = &ceu_ioctl_ops; vdev->release = ceu_vdev_release;
@@ -1394,12 +1487,56 @@ static int ceu_sensor_bound(struct v4l2_async_notifier *notifier,return ret; } +dev_info (ceudev->dev,"Video device registered\n" ); + +return 0 ; +} + +/** +* Parse platform data to collect bus flags and async sensors description +*/ +static int ceu_parse_platform_data (struct ceu_device *ceudev,void *pdata) +{ +struct ceu_async_subdev *async_sd; +struct ceu_info *info = pdata; +struct ceu_subdev *ceu_sd; +unsigned int i; + + ceudev->pdata = pdata; + ceudev->subdev =NULL ; + ceudev->subdev_index =0 ; + ceudev->num_subdevs =0 ; + ceudev->num_subdevs = info->num_subdevs; + ceudev->subdevs =devm_kcalloc (ceudev->dev, info->num_subdevs, +sizeof (*ceudev->subdevs), +GFP_KERNEL ); +if (!ceudev->subdevs) +return -ENOMEM ; + +for (i =0 ; i < info->num_subdevs; i++) { + ceu_sd = &ceudev->subdevs[i]; + async_sd = &info->subdevs[i]; + + ceu_sd->asd =devm_kmalloc (ceudev->dev,sizeof (*ceu_sd->asd), +GFP_KERNEL ); +if (!ceu_sd) +return -ENOMEM ; + + ceu_sd->mbus_flags = async_sd->flags; + ceu_sd->asd->match_type =V4L2_ASYNC_MATCH_I2C ; + ceu_sd->asd->match.i2c.adapter_id = async_sd->i2c_adapter_id; + ceu_sd->asd->match.i2c.address = async_sd->i2c_address; + +list_add_tail (&ceu_sd->list, &ceudev->subdev_list); + } +return 0 ; }static int ceu_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct ceu_subdev *ceu_sd;struct ceu_device *ceudev;struct resource *res;void __iomem *base;
@@ -1415,6 +1552,7 @@ static int ceu_probe(struct platform_device *pdev) ceudev->dev = dev;INIT_LIST_HEAD (&ceudev->capture); +INIT_LIST_HEAD (&ceudev->subdev_list);spin_lock_init (&ceudev->lock);mutex_init (&ceudev->mlock);
@@ -1440,13 +1578,12 @@ static int ceu_probe(struct platform_device *pdev)if (IS_ENABLED (CONFIG_OF ) && dev->of_node) {/* TODO: implement OF parsing */ }else if (dev->platform_data) { - ceudev->pdata = dev->platform_data; - ceudev->mbus_flags = ceudev->pdata->flags; - ceudev->asd.match_type =V4L2_ASYNC_MATCH_I2C ; - ceudev->asd.match.i2c.adapter_id = - ceudev->pdata->sensor_i2c_adapter_id; - ceudev->asd.match.i2c.address = - ceudev->pdata->sensor_i2c_address; + ret =ceu_parse_platform_data (ceudev, dev->platform_data); +if (ret) { +dev_err (&pdev->dev, +"CEU unable to parse platform data\n" ); +return ret; + } }else {dev_err (&pdev->dev,"CEU platform data not set.\n" );return -EINVAL ;
@@ -1459,20 +1596,27 @@ static int ceu_probe(struct platform_device *pdev)if (ret) goto error_pm_disable; - ceudev->asds[0 ] = &ceudev->asd; - ceudev->notifier.v4l2_dev = &ceudev->v4l2_dev; - ceudev->notifier.subdevs = ceudev->asds; - ceudev->notifier.num_subdevs =1 ; - ceudev->notifier.bound = ceu_sensor_bound; - ret =v4l2_async_notifier_register (&ceudev->v4l2_dev, - &ceudev->notifier); -if (ret) - goto error_v4l2_unregister; +list_for_each_entry (ceu_sd, &ceudev->subdev_list, list) { + ceu_sd->notifier.v4l2_dev = &ceudev->v4l2_dev; + ceu_sd->notifier.subdevs = &ceu_sd->asd; + ceu_sd->notifier.num_subdevs =1 ; + ceu_sd->notifier.bound = ceu_sensor_bound; + ceu_sd->notifier.complete = ceu_sensor_complete; + ret =v4l2_async_notifier_register (&ceudev->v4l2_dev, + &ceu_sd->notifier); +if (ret) + goto error_v4l2_unregister_notifiers; + + }return 0 ; -error_v4l2_unregister: +error_v4l2_unregister_notifiers: +list_for_each_entry (ceu_sd, &ceudev->subdev_list, list) +v4l2_async_unregister_subdev (ceu_sd->v4l2_subdev); +v4l2_device_unregister (&ceudev->v4l2_dev); + error_pm_disable:pm_runtime_disable (dev);
@@ -1482,10 +1626,13 @@ static int ceu_probe(struct platform_device *pdev)static int ceu_remove (struct platform_device *pdev) {struct ceu_device *ceudev =platform_get_drvdata (pdev); +struct ceu_subdev *ceu_sd;pm_runtime_disable (ceudev->dev); -v4l2_async_notifier_unregister (&ceudev->notifier); +list_for_each_entry (ceu_sd, &ceudev->subdev_list, list) +v4l2_async_unregister_subdev (ceu_sd->v4l2_subdev); +v4l2_device_unregister (&ceudev->v4l2_dev);video_unregister_device (&ceudev->vdev);
--
2.7.4
Jacopo Mondi
maintainerRFC v4 5/8 media: i2c: ov772x: Force use of SCCB protocol
In reply to Jacopo MondiCommit e78902976150 ("i2c: sh_mobile: don't send a stop condition by default inside transfers") makes the i2c_sh_mobile I2C-adapter emit a stop/start sequence between messages in a single transfer only when explicitly requested with I2C_M_STOP.
This breaks the ov772x driver in the SH4 Migo-R board as the Omnivision sensor uses the I2C-like SCCB protocol that doesn't support repeated starts:
i2c-sh_mobile i2c-sh_mobile.0: Transfer request timed out ov772x 0-0021: Product ID error 92:92
Fix it by marking the client as SCCB, forcing the emission of a stop/start sequence between all messages.
As I2C_M_STOP requires the I2C adapter to support protocol mangling, ensure that the I2C_FUNC_PROTOCOL_MANGLING functionality is available.
Tested on SH4 Migo-R board, with OV772x now successfully probing
soc-camera-pdrv soc-camera-pdrv.0: Probing soc-camera-pdrv.0 ov772x 0-0021: ov7725 Product ID 77:21 Manufacturer ID 7f:a2
--- drivers/media/i2c/soc_camera/ov772x.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/i2c/soc_camera/ov772x.c +4 -2
@@ -1062,11 +1062,13 @@ static int ov772x_probe(struct i2c_client *client,return -EINVAL ; } -if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) { +if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_PROTOCOL_MANGLING )) {dev_err (&adapter->dev, -"I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE_DATA\n" ); +"I2C-Adapter doesn't support SMBUS_BYTE_DATA or PROTOCOL_MANGLING\n" );return -EIO ; } + client->flags |=I2C_CLIENT_SCCB ; priv =devm_kzalloc (&client->dev,sizeof (*priv),GFP_KERNEL );if (!priv)
Signature · 1 line
2.7.4
Jacopo Mondi
maintainerRFC v4 6/8 media: i2c: ov772x: Remove soc_camera dependencies
In reply to Jacopo MondiRemove soc_camera framework dependencies from OV772x sensor driver.
TODO: move the driver out from soc_camera directory
--- drivers/media/i2c/soc_camera/ov772x.c | 90 ++++++++++++++++++++++++----------- include/media/i2c/ov772x.h | 3 ++ 2 files changed, 65 insertions(+), 28 deletions(-)
drivers/media/i2c/soc_camera/ov772x.c +62 -28
@@ -15,6 +15,7 @@* published by the Free Software Foundation. */ +#include <linux/clk.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -25,8 +26,8 @@#include <linux/videodev2.h> #include <media/i2c/ov772x.h> -#include <media/soc_camera.h> -#include <media/v4l2-clk.h> + +#include <media/v4l2-device.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-subdev.h> #include <media/v4l2-image-sizes.h>
@@ -393,7 +394,7 @@ struct ov772x_win_size {struct ov772x_priv {struct v4l2_subdev subdev;struct v4l2_ctrl_handler hdl; -struct v4l2_clk *clk; +struct clk *clk;struct ov772x_camera_info *info;const struct ov772x_color_format *cfmt;const struct ov772x_win_size *win;
@@ -550,7 +551,7 @@ static int ov772x_reset(struct i2c_client *client) }/* -* soc_camera_ops function +* subdev ops */ static int ov772x_s_stream (struct v4l2_subdev *sd,int enable)
@@ -650,13 +651,36 @@ static int ov772x_s_register(struct v4l2_subdev *sd, }#endif +static int ov772x_power_on (struct ov772x_priv *priv) +{ +int ret; + +if (priv->info->platform_enable) { + ret = priv->info->platform_enable (); +if (ret) +return ret; + } + +/* drivers/sh/clk/core.c returns -EINVAL if clk is NULL */ +return clk_enable (priv->clk) <=0 ?0 :1 ; +} + +static int ov772x_power_off (struct ov772x_priv *priv) +{ +if (priv->info->platform_enable) + priv->info->platform_disable (); + +clk_disable (priv->clk); + +return 0 ; +} +static int ov772x_s_power (struct v4l2_subdev *sd,int on) { -struct i2c_client *client =v4l2_get_subdevdata (sd); -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client);struct ov772x_priv *priv =to_ov772x (sd); -return soc_camera_set_power (&client->dev, ssdd, priv->clk, on); +return on ?ov772x_power_on (priv) : +ov772x_power_off (priv); }static const struct ov772x_win_size *ov772x_select_win (u32 width,u32 height)
@@ -975,6 +999,7 @@ static int ov772x_video_probe(struct ov772x_priv *priv) goto done; } + dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", devname,
@@ -1015,14 +1040,10 @@ static int ov772x_enum_mbus_code(struct v4l2_subdev *sd,static int ov772x_g_mbus_config (struct v4l2_subdev *sd,struct v4l2_mbus_config *cfg) { -struct i2c_client *client =v4l2_get_subdevdata (sd); -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client); - cfg->flags =V4L2_MBUS_PCLK_SAMPLE_RISING |V4L2_MBUS_MASTER |V4L2_MBUS_VSYNC_ACTIVE_HIGH |V4L2_MBUS_HSYNC_ACTIVE_HIGH |V4L2_MBUS_DATA_ACTIVE_HIGH ; cfg->type =V4L2_MBUS_PARALLEL ; - cfg->flags =soc_camera_apply_board_flags (ssdd, cfg);return 0 ; }
@@ -1053,12 +1074,11 @@ static int ov772x_probe(struct i2c_client *client, const struct i2c_device_id *did) {struct ov772x_priv *priv; -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client); -struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent); +struct i2c_adapter *adapter = client->adapter;int ret; -if (!ssdd || !ssdd->drv_priv) { -dev_err (&client->dev,"OV772X: missing platform data!\n" ); +if (!client->dev.platform_data) { +dev_err (&adapter->dev,"Missing OV7725 platform data\n" );return -EINVAL ; }
@@ -1074,7 +1094,7 @@ static int ov772x_probe(struct i2c_client *client,if (!priv)return -ENOMEM ; - priv->info = ssdd->drv_priv; + priv->info = client->dev.platform_data;v4l2_i2c_subdev_init (&priv->subdev, client, &ov772x_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,3 );
@@ -1088,21 +1108,34 @@ static int ov772x_probe(struct i2c_client *client,if (priv->hdl.error)return priv->hdl.error; - priv->clk =v4l2_clk_get (&client->dev,"mclk" ); -if (IS_ERR (priv->clk)) { + priv->clk =clk_get (&client->dev,"mclk" ); +if (PTR_ERR (priv->clk) == -ENOENT ) { + priv->clk =NULL ; + }else if (IS_ERR (priv->clk)) { +dev_err (&client->dev,"Unable to get mclk clock\n" ); ret =PTR_ERR (priv->clk); - goto eclkget; + goto error_clk_enable; } ret =ov772x_video_probe (priv); -if (ret <0 ) { -v4l2_clk_put (priv->clk); -eclkget: -v4l2_ctrl_handler_free (&priv->hdl); - }else { - priv->cfmt = &ov772x_cfmts[0 ]; - priv->win = &ov772x_win_sizes[0 ]; - } +if (ret <0 ) + goto error_video_probe; + + + priv->cfmt = &ov772x_cfmts[0 ]; + priv->win = &ov772x_win_sizes[0 ]; + + ret =v4l2_async_register_subdev (&priv->subdev); +if (ret) + goto error_video_probe; + +return 0 ; + +error_video_probe: +if (priv->clk) +clk_put (priv->clk); +error_clk_enable: +v4l2_ctrl_handler_free (&priv->hdl);return ret; }
@@ -1111,7 +1144,8 @@ static int ov772x_remove(struct i2c_client *client) {struct ov772x_priv *priv =to_ov772x (i2c_get_clientdata (client)); -v4l2_clk_put (priv->clk); +if (priv->clk) +clk_put (priv->clk);v4l2_device_unregister_subdev (&priv->subdev);v4l2_ctrl_handler_free (&priv->hdl);return 0 ;
include/media/i2c/ov772x.h +3 -0
@@ -54,6 +54,9 @@ struct ov772x_edge_ctrl {struct ov772x_camera_info {unsigned long flags;struct ov772x_edge_ctrl edgectrl; + +int (*platform_enable)(void ); +void (*platform_disable)(void ); };#endif /* __OV772X_H__ */
Signature · 1 line
2.7.4
Jacopo Mondi
maintainerRFC v4 7/8 media: i2c: tw9910: Remove soc_camera dependencies
In reply to Jacopo MondiRemove soc_camera framework dependencies from TW9910 driver.
TODO: move the driver out from soc_camera directory
--- drivers/media/i2c/soc_camera/tw9910.c | 68 +++++++++++++++++++++++------------ include/media/i2c/tw9910.h | 6 ++++ 2 files changed, 52 insertions(+), 22 deletions(-)
drivers/media/i2c/soc_camera/tw9910.c +46 -22
@@ -16,6 +16,7 @@* published by the Free Software Foundation. */ +#include <linux/clk.h> #include <linux/init.h> #include <linux/module.h> #include <linux/i2c.h>
@@ -25,9 +26,7 @@#include <linux/v4l2-mediabus.h> #include <linux/videodev2.h> -#include <media/soc_camera.h> #include <media/i2c/tw9910.h> -#include <media/v4l2-clk.h> #include <media/v4l2-subdev.h> #define GET_ID (val) ((val & 0xF8) >> 3)
@@ -228,7 +227,7 @@ struct tw9910_scale_ctrl {struct tw9910_priv {struct v4l2_subdev subdev; -struct v4l2_clk *clk; +struct clk *clk;struct tw9910_video_info *info;const struct tw9910_scale_ctrl *scale;v4l2_std_id norm;
@@ -582,13 +581,37 @@ static int tw9910_s_register(struct v4l2_subdev *sd, }#endif +static int tw9910_power_on (struct tw9910_priv *priv) +{ +int ret; + +if (priv->info->platform_enable) { + ret = priv->info->platform_enable (); +if (ret) +return ret; + } + +/* drivers/sh/clk/core.c returns -EINVAL if clk is NULL */ +return clk_enable (priv->clk) <=0 ?0 :1 ; +} + +static int tw9910_power_off (struct tw9910_priv *priv) +{ +if (priv->info->platform_enable) + priv->info->platform_disable (); + +clk_disable (priv->clk); + +return 0 ; +} +static int tw9910_s_power (struct v4l2_subdev *sd,int on) {struct i2c_client *client =v4l2_get_subdevdata (sd); -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client);struct tw9910_priv *priv =to_tw9910 (client); -return soc_camera_set_power (&client->dev, ssdd, priv->clk, on); +return on ?tw9910_power_on (priv) : +tw9910_power_off (priv); }static int tw9910_set_frame (struct v4l2_subdev *sd,u32 *width,u32 *height)
@@ -614,7 +637,7 @@ static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height)* set bus width */ val =0x00 ; -if (SOCAM_DATAWIDTH_16 == priv->info->buswidth) +if (priv->info->buswidth ==TW9910_DATAWIDTH_16 ) val =LEN ; ret =tw9910_mask_set (client,OPFORM ,LEN , val);
@@ -799,8 +822,8 @@ static int tw9910_video_probe(struct i2c_client *client)/* * tw9910 only use 8 or 16 bit bus width */ -if (SOCAM_DATAWIDTH_16 != priv->info->buswidth && -SOCAM_DATAWIDTH_8 != priv->info->buswidth) { +if (priv->info->buswidth !=TW9910_DATAWIDTH_16 && + priv->info->buswidth !=TW9910_DATAWIDTH_8 ) {dev_err (&client->dev,"bus width error\n" );return -ENODEV ; }
@@ -859,15 +882,11 @@ static int tw9910_enum_mbus_code(struct v4l2_subdev *sd,static int tw9910_g_mbus_config (struct v4l2_subdev *sd,struct v4l2_mbus_config *cfg) { -struct i2c_client *client =v4l2_get_subdevdata (sd); -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client); - cfg->flags =V4L2_MBUS_PCLK_SAMPLE_RISING |V4L2_MBUS_MASTER |V4L2_MBUS_VSYNC_ACTIVE_HIGH |V4L2_MBUS_VSYNC_ACTIVE_LOW |V4L2_MBUS_HSYNC_ACTIVE_HIGH |V4L2_MBUS_HSYNC_ACTIVE_LOW |V4L2_MBUS_DATA_ACTIVE_HIGH ; cfg->type =V4L2_MBUS_PARALLEL ; - cfg->flags =soc_camera_apply_board_flags (ssdd, cfg);return 0 ; }
@@ -876,9 +895,8 @@ static int tw9910_s_mbus_config(struct v4l2_subdev *sd, const struct v4l2_mbus_config *cfg) {struct i2c_client *client =v4l2_get_subdevdata (sd); -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client);u8 val =VSSL_VVALID |HSSL_DVALID ; -unsigned long flags =soc_camera_apply_board_flags (ssdd, cfg); +unsigned long flags = cfg->flags;/* * set OUTCTR1
@@ -935,15 +953,14 @@ static int tw9910_probe(struct i2c_client *client,struct tw9910_video_info *info;struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent); -struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client);int ret; -if (!ssdd || !ssdd->drv_priv) { +if (!client->dev.platform_data) {dev_err (&client->dev,"TW9910: missing platform data!\n" );return -EINVAL ; } - info = ssdd->drv_priv; + info = client->dev.platform_data;if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) { dev_err(&client->dev,
@@ -959,13 +976,17 @@ static int tw9910_probe(struct i2c_client *client,v4l2_i2c_subdev_init (&priv->subdev, client, &tw9910_subdev_ops); - priv->clk =v4l2_clk_get (&client->dev,"mclk" ); -if (IS_ERR (priv->clk)) + priv->clk =clk_get (&client->dev,"mclk" ); +if (PTR_ERR (priv->clk) == -ENOENT ) { + priv->clk =NULL ; + }else if (IS_ERR (priv->clk)) { +dev_err (&client->dev,"Unable to get mclk clock\n" );return PTR_ERR (priv->clk); + } ret =tw9910_video_probe (client); -if (ret <0 ) -v4l2_clk_put (priv->clk); +if (ret <0 && priv->clk) +clk_put (priv->clk);return ret; }
@@ -973,7 +994,10 @@ static int tw9910_probe(struct i2c_client *client,static int tw9910_remove (struct i2c_client *client) {struct tw9910_priv *priv =to_tw9910 (client); -v4l2_clk_put (priv->clk); + +if (priv->clk) +clk_put (priv->clk); +return 0 ; }
include/media/i2c/tw9910.h +6 -0
@@ -18,6 +18,9 @@#include <media/soc_camera.h> +#define TW9910_DATAWIDTH_8 BIT(0) +#define TW9910_DATAWIDTH_16 BIT(1) +enum tw9910_mpout_pin {TW9910_MPO_VLOSS ,TW9910_MPO_HLOCK ,
@@ -32,6 +35,9 @@ enum tw9910_mpout_pin {struct tw9910_video_info {unsigned long buswidth;enum tw9910_mpout_pin mpout; + +int (*platform_enable)(void ); +void (*platform_disable)(void ); };
--
2.7.4
Jacopo Mondi
maintainerRFC v4 8/8 arch: sh: migor: Use new CEU camera driver
In reply to Jacopo MondiUpdate the interface for CEU camera driver and update migor machine init to use it.
Get rid of soc_camera_links and and register subdevices as I2c devices. Change power on/off routines to be called by sensor driver to select/deselect which sensor to use.
--- arch/sh/boards/mach-migor/setup.c | 125 +++++++++++++++----------------------- 1 file changed, 49 insertions(+), 76 deletions(-)
arch/sh/boards/mach-migor/setup.c +49 -76
@@ -26,7 +26,7 @@#include <linux/videodev2.h> #include <linux/sh_intc.h> #include <video/sh_mobile_lcdc.h> -#include <media/drv-intf/sh_mobile_ceu.h> +#include <media/drv-intf/renesas_ceu.h> #include <media/i2c/ov772x.h> #include <media/soc_camera.h> #include <media/i2c/tw9910.h>
@@ -302,12 +302,9 @@ static struct platform_device migor_lcdc_device = { };static struct clk *camera_clk; -static DEFINE_MUTEX (camera_lock); -static void camera_power_on (int is_tw) +static void camera_vio_clk_on (void ) { -mutex_lock (&camera_lock); -/* Use 10 MHz VIO_CKO instead of 24 MHz to work * around signal quality issues on Panel Board V2.1. */
@@ -317,49 +314,52 @@ static void camera_power_on(int is_tw)/* use VIO_RST to take camera out of reset */ mdelay (10 ); -if (is_tw) { -gpio_set_value (GPIO_PTT2 ,0 ); -gpio_set_value (GPIO_PTT0 ,0 ); - }else { -gpio_set_value (GPIO_PTT0 ,1 ); - }gpio_set_value (GPIO_PTT3 ,0 );mdelay (10 );gpio_set_value (GPIO_PTT3 ,1 );mdelay (10 );/* wait to let chip come out of reset */ } -static void camera_power_off (void ) +/* Platform camera driver to make sure these two are enabled alternatively */ +static int ov7725_enable (void ) { -clk_disable (camera_clk);/* stop VIO_CKO */ -clk_put (camera_clk); +gpio_set_value (GPIO_PTT0 ,1 ); -gpio_set_value (GPIO_PTT3 ,0 ); -mutex_unlock (&camera_lock); +return 0 ; } -static int ov7725_power (struct device *dev,int mode) +static void ov7725_disable (void ) { -if (mode) -camera_power_on (0 ); -else -camera_power_off (); - -return 0 ; +gpio_set_value (GPIO_PTT0 ,0 ); } -static int tw9910_power (struct device *dev,int mode) +static int tw9910_enable (void ) { -if (mode) -camera_power_on (1 ); -else -camera_power_off (); +gpio_set_value (GPIO_PTT2 ,1 );return 0 ; } -static struct sh_mobile_ceu_info sh_mobile_ceu_info = { - .flags =SH_CEU_FLAG_USE_8BIT_BUS , +static void tw9910_disable (void ) +{ +gpio_set_value (GPIO_PTT2 ,0 ); +} + +static struct ceu_info ceu_info = { + .num_subdevs =2 , + .subdevs = { + {/* [0] = ov772x */ + .flags =CEU_FLAG_USE_8BIT_BUS | +CEU_FLAG_PRIMARY_SENS , + .i2c_adapter_id =0 , + .i2c_address =0x21 , + }, + {/* [1] = tw9910 */ + .flags =CEU_FLAG_USE_8BIT_BUS , + .i2c_adapter_id =0 , + .i2c_address =0x45 , + }, + }, };static struct resource migor_ceu_resources[] = {
@@ -379,12 +379,12 @@ static struct resource migor_ceu_resources[] = { };static struct platform_device migor_ceu_device = { - .name ="sh_mobile_ceu" , + .name ="renesas-ceu" , .id =0 ,/* "ceu0" clock */ .num_resources =ARRAY_SIZE (migor_ceu_resources), .resource = migor_ceu_resources, .dev = { - .platform_data = &sh_mobile_ceu_info, + .platform_data = &ceu_info, }, };
@@ -423,6 +423,20 @@ static struct platform_device sdhi_cn9_device = { }, }; +static struct ov772x_camera_info ov7725_info = { + .platform_enable = ov7725_enable, + .platform_disable = ov7725_disable, +}; + +static struct tw9910_video_info tw9910_info = { + .buswidth =TW9910_DATAWIDTH_8 , + .mpout =TW9910_MPO_FIELD , + + .platform_enable = tw9910_enable, + .platform_disable = tw9910_disable, +}; + +static struct i2c_board_info migor_i2c_devices[] = { {I2C_BOARD_INFO ("rs5c372b" ,0x32 ),
@@ -434,51 +448,13 @@ static struct i2c_board_info migor_i2c_devices[] = { {I2C_BOARD_INFO ("wm8978" ,0x1a ), }, -}; - -static struct i2c_board_info migor_i2c_camera[] = { {I2C_BOARD_INFO ("ov772x" ,0x21 ), + .platform_data = &ov7725_info, }, {I2C_BOARD_INFO ("tw9910" ,0x45 ), - }, -}; - -static struct ov772x_camera_info ov7725_info; - -static struct soc_camera_link ov7725_link = { - .power = ov7725_power, - .board_info = &migor_i2c_camera[0 ], - .i2c_adapter_id =0 , - .priv = &ov7725_info, -}; - -static struct tw9910_video_info tw9910_info = { - .buswidth =SOCAM_DATAWIDTH_8 , - .mpout =TW9910_MPO_FIELD , -}; - -static struct soc_camera_link tw9910_link = { - .power = tw9910_power, - .board_info = &migor_i2c_camera[1 ], - .i2c_adapter_id =0 , - .priv = &tw9910_info, -}; - -static struct platform_device migor_camera[] = { - { - .name ="soc-camera-pdrv" , - .id =0 , - .dev = { - .platform_data = &ov7725_link, - }, - }, { - .name ="soc-camera-pdrv" , - .id =1 , - .dev = { - .platform_data = &tw9910_link, - }, + .platform_data = &tw9910_info, }, };
@@ -490,8 +466,6 @@ static struct platform_device *migor_devices[] __initdata = { &migor_nor_flash_device, &migor_nand_flash_device, &sdhi_cn9_device, - &migor_camera[0 ], - &migor_camera[1], };extern char migor_sdram_enter_start;
@@ -632,8 +606,6 @@ static int __init migor_devices_setup(void)#endif __raw_writew (__raw_readw (PORT_MSELCRB ) |0x2000 ,PORT_MSELCRB );/* D15->D8 */ -platform_resource_setup_memory (&migor_ceu_device,"ceu" ,4 <<20 ); -/* SIU: Port B */ gpio_request (GPIO_FN_SIUBOLR ,NULL );gpio_request (GPIO_FN_SIUBOBT ,NULL );
@@ -647,6 +619,7 @@ static int __init migor_devices_setup(void)*/ __raw_writew (__raw_readw (PORT_MSELCRA ) |1 ,PORT_MSELCRA ); +camera_vio_clk_on ();i2c_register_board_info (0 , migor_i2c_devices,ARRAY_SIZE (migor_i2c_devices));
Signature · 1 line
2.7.4