media: ov7670: add media controller support
cover media: ov7670: add media controller support
This series adds media controller support and other related changes to the OV7670 which is cheap and highly available CMOS image sensor for hobbyists.
This enables to control a video pipeline system with the OV7670. I've tested this with the xilinx video IP pipeline.
Akinobu Mita (4):
media: ov7670: create subdevice device node
media: ov7670: use v4l2_async_unregister_subdev()
media: ov7670: add media controller support
media: ov7670: add get_fmt() pad ops callback
drivers/media/i2c/ov7670.c | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
PATCH 1/4 media: ov7670: create subdevice device node
Set the V4L2_SUBDEV_FL_HAS_DEVNODE flag for the subdevice so it is possible to create a subdevice device node.
--- drivers/media/i2c/ov7670.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/i2c/ov7670.c +1 -0
@@ -1585,6 +1585,7 @@ static int ov7670_probe(struct i2c_client *client,return -ENOMEM ; sd = &info->sd;v4l2_i2c_subdev_init (sd, client, &ov7670_ops); + sd->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; info->clock_speed =30 ;/* default: a guess */ if (client->dev.platform_data) {
Signature · 1 line
2.7.4
PATCH 2/4 media: ov7670: use v4l2_async_unregister_subdev()
In reply to Akinobu MitaThe sub-device for ov7670 is registered by v4l2_async_register_subdev(). So it should be unregistered by v4l2_async_unregister_subdev() instead of v4l2_device_unregister_subdev().
--- drivers/media/i2c/ov7670.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/i2c/ov7670.c +2 -1
@@ -19,6 +19,7 @@#include <linux/videodev2.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> +#include <media/v4l2-async.h> #include <media/v4l2-device.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-mediabus.h>
@@ -1710,7 +1711,7 @@ static int ov7670_remove(struct i2c_client *client)struct v4l2_subdev *sd =i2c_get_clientdata (client);struct ov7670_info *info =to_state (sd); -v4l2_device_unregister_subdev (sd); +v4l2_async_unregister_subdev (sd);v4l2_ctrl_handler_free (&info->hdl);clk_disable_unprepare (info->clk);return 0 ;
Signature · 1 line
2.7.4
PATCH 3/4 media: ov7670: add media controller support
In reply to Akinobu MitaCreate a source pad and set the media controller type to the sensor.
--- drivers/media/i2c/ov7670.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/media/i2c/ov7670.c +17 -0
@@ -214,6 +214,9 @@ struct ov7670_devtype {struct ov7670_format_struct ;/* coming later */ struct ov7670_info {struct v4l2_subdev sd; +#ifdef CONFIG_MEDIA_CONTROLLER +struct media_pad pad; +#endif struct v4l2_ctrl_handler hdl;struct {/* gain cluster */
@@ -1654,6 +1657,14 @@ static int ov7670_probe(struct i2c_client *client,if (info->pclk_hb_disable)ov7670_write (sd,REG_COM10 ,COM10_PCLK_HB ); +#ifdef CONFIG_MEDIA_CONTROLLER + info->pad.flags =MEDIA_PAD_FL_SOURCE ; + sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ret =media_entity_pads_init (&sd->entity,1 , &info->pad); +if (ret) + goto clk_disable; +#endif +v4l2_ctrl_handler_init (&info->hdl,10 );v4l2_ctrl_new_std (&info->hdl, &ov7670_ctrl_ops,V4L2_CID_BRIGHTNESS ,0 ,255 ,1 ,128 );
@@ -1700,6 +1711,9 @@ static int ov7670_probe(struct i2c_client *client, hdl_free:v4l2_ctrl_handler_free (&info->hdl); +#ifdef CONFIG_MEDIA_CONTROLLER +media_entity_cleanup (&sd->entity); +#endif clk_disable:clk_disable_unprepare (info->clk);return ret;
@@ -1713,6 +1727,9 @@ static int ov7670_remove(struct i2c_client *client)v4l2_async_unregister_subdev (sd);v4l2_ctrl_handler_free (&info->hdl); +#ifdef CONFIG_MEDIA_CONTROLLER +media_entity_cleanup (&sd->entity); +#endif clk_disable_unprepare (info->clk);return 0 ; }
Signature · 1 line
2.7.4
PATCH 4/4 media: ov7670: add get_fmt() pad ops callback
In reply to Akinobu MitaThis enables to print the current format on the source pad of the ov7670 subdev by media-ctl.
--- drivers/media/i2c/ov7670.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/media/i2c/ov7670.c +34 -0
@@ -234,6 +234,7 @@ struct ov7670_info {struct v4l2_ctrl *hue; };struct ov7670_format_struct *fmt;/* Current format */ +struct ov7670_win_size *wsize;/* Current format */ struct clk *clk;struct gpio_desc *resetb_gpio;struct gpio_desc *pwdn_gpio;
@@ -875,6 +876,36 @@ static int ov7670_set_framerate_legacy(struct v4l2_subdev *sd,return ov7670_write (sd,REG_CLKRC , info->clkrc); } +static int ov7670_get_fmt (struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_format *fmt) +{ +struct ov7670_info *info =to_state (sd); + +if (fmt->pad) +return -EINVAL ; + +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API +struct v4l2_mbus_framefmt *mf; + + mf =v4l2_subdev_get_try_format (sd, cfg,0 ); + fmt->format = *mf; +return 0 ; +#else +return -ENOTTY ; +#endif + } + + fmt->format.colorspace = info->fmt->colorspace; + fmt->format.code = info->fmt->mbus_code; + fmt->format.field =V4L2_FIELD_NONE ; + fmt->format.width = info->wsize->width; + fmt->format.height = info->wsize->height; + +return 0 ; +} +/* * Store a set of start/stop values into the camera. */
@@ -1026,6 +1057,7 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd,if (wsize->regs) ret =ov7670_write_array (sd, wsize->regs); info->fmt = ovfmt; + info->wsize = wsize;/* * If we're running RGB565, we must rewrite clkrc after setting
@@ -1529,6 +1561,7 @@ static const struct v4l2_subdev_pad_ops ov7670_pad_ops = { .enum_frame_interval = ov7670_enum_frame_interval, .enum_frame_size = ov7670_enum_frame_size, .enum_mbus_code = ov7670_enum_mbus_code, + .get_fmt = ov7670_get_fmt, .set_fmt = ov7670_set_fmt, };
@@ -1647,6 +1680,7 @@ static int ov7670_probe(struct i2c_client *client, info->devtype = &ov7670_devdata[id->driver_data]; info->fmt = &ov7670_formats[0 ]; + info->wsize = &info->devtype->win_sizes[0 ]; info->clkrc =0 ;/* Set default frame rate to 30 fps */
Signature · 1 line
2.7.4
Hi Akinobu,
Quoted 6 lines · Akinobu Mita
This series adds media controller support and other related changes to the OV7670 which is cheap and highly available CMOS image sensor for hobbyists.
This enables to control a video pipeline system with the OV7670. I've tested this with the xilinx video IP pipeline.
Quoted 8 lines
Akinobu Mita (4):
media: ov7670: create subdevice device node
media: ov7670: usev4l2_async_unregister_subdev()
media: ov7670: add media controller support
media: ov7670: addget_fmt()pad ops callbackdrivers/media/i2c/ov7670.c | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
I understand Wenyou has submitted a set with similar functionality + runtime PM as well, but it has issues. There hasn't been updated for some time on that. Wenyou, what's the status of your patchset?
The set was submitted on the list under subject "[PATCH v5 0/3] media:
ov7670: Add entity init and power operation"
Signature · 4 lines
Kind regards, Sakari Ailus e-mail: [email protected]
Hi Sakari,
Quoted 15 lines · Sakari Ailus
Hi Akinobu,
Quoted 12 lines · Akinobu Mita
This series adds media controller support and other related changes to the OV7670 which is cheap and highly available CMOS image sensor for hobbyists.
This enables to control a video pipeline system with the OV7670. I've tested this with the xilinx video IP pipeline.
Akinobu Mita (4):
media: ov7670: create subdevice device node
media: ov7670: usev4l2_async_unregister_subdev()
media: ov7670: add media controller support
media: ov7670: addget_fmt()pad ops callback
Quoted 5 lines
Quoted 2 lines
drivers/media/i2c/ov7670.c | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)I understand Wenyou has submitted a set with similar functionality + runtime PM as well, but it has issues. There hasn't been updated for some time on that. Wenyou, what's the status of your patchset?
Sorry for I missed your previous mail.
I will update the patchset soon.
Quoted 3 lines
The set was submitted on the list under subject "[PATCH v5 0/3] media:
ov7670: Add entity init and power operation"
Best Regards,
Wenyou Yang