Re: [PATCH v1 08/10] media: i2c: ov772x: Remove soc_camera dependencies
Hi Jacopo, Thank you for the patch. On Wednesday, 15 November 2017 12:56:01 EET Jacopo Mondi wrote: > Remove soc_camera framework dependencies from ov772x sensor driver. > - Handle clock directly > - Register async subdevice > - Add platform specific enable/disable functions > - Adjust build system > > This commit does not remove the original soc_camera based driver. > > Signed-off-by: Jacopo Mondi> --- > drivers/media/i2c/Kconfig | 12 +++ > drivers/media/i2c/Makefile | 1 + > drivers/media/i2c/ov772x.c | 88 --- > include/media/i2c/ov772x.h | 3 ++ > 4 files changed, 76 insertions(+), 28 deletions(-) > > diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig > index 9415389..ff251ce 100644 > --- a/drivers/media/i2c/Kconfig > +++ b/drivers/media/i2c/Kconfig > @@ -629,6 +629,18 @@ config VIDEO_OV5670 > To compile this driver as a module, choose M here: the > module will be called ov5670. > > +config VIDEO_OV772X > + tristate "OmniVision OV772x sensor support" > + depends on I2C && VIDEO_V4L2 > + depends on MEDIA_CAMERA_SUPPORT > + ---help--- > + This is a Video4Linux2 sensor-level driver for the OmniVision > + OV772x camera. > + > + To compile this driver as a module, choose M here: the > + module will be called ov772x. > + > + A single blank line is enough. > config VIDEO_OV7640 > tristate "OmniVision OV7640 sensor support" > depends on I2C && VIDEO_V4L2 > diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile > index f104650..b2459a1 100644 > --- a/drivers/media/i2c/Makefile > +++ b/drivers/media/i2c/Makefile > @@ -66,6 +66,7 @@ obj-$(CONFIG_VIDEO_OV5645) += ov5645.o > obj-$(CONFIG_VIDEO_OV5647) += ov5647.o > obj-$(CONFIG_VIDEO_OV5670) += ov5670.o > obj-$(CONFIG_VIDEO_OV6650) += ov6650.o > +obj-$(CONFIG_VIDEO_OV772X) += ov772x.o > obj-$(CONFIG_VIDEO_OV7640) += ov7640.o > obj-$(CONFIG_VIDEO_OV7670) += ov7670.o > obj-$(CONFIG_VIDEO_OV9650) += ov9650.o > diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c > index 8063835..9be7e4e 100644 > --- a/drivers/media/i2c/ov772x.c > +++ b/drivers/media/i2c/ov772x.c [snip] > @@ -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; Then please don't call clk_enable() if priv->clk is NULL, and propagate errors from clk_enable() back to the caller. And shouldn't you call clk_prepare_enable() (and clk_disable_unprepare() below) ? > +} > + > +static int ov772x_power_off(struct ov772x_priv *priv) > +{ > + if (priv->info->platform_enable) > + priv->info->platform_disable(); > + > + clk_disable(priv->clk); > + > + return 0; > +} [snip] > @@ -1073,21 +1092,33 @@ static int ov772x_probe(struct i2c_client *client, > if (priv->hdl.error) > return priv->hdl.error; > > - priv->clk = v4l2_clk_get(>dev, "mclk"); > - if (IS_ERR(priv->clk)) { > + priv->clk = clk_get(>dev, "mclk"); > + if (PTR_ERR(priv->clk) == -ENOENT) { > + priv->clk = NULL; > + } else if (IS_ERR(priv->clk)) { > + dev_err(>dev, "Unable to get mclk clock\n"); > ret = PTR_ERR(priv->clk); > - goto eclkget; You need a priv->clk = NULL here otherwise the error path will oops. > + goto error_clk_enable; > } > > ret = ov772x_video_probe(priv); > - if (ret < 0) { > - v4l2_clk_put(priv->clk); > -eclkget: > - v4l2_ctrl_handler_free(>hdl); > - } else { > - priv->cfmt = _cfmts[0]; > - priv->win = _win_sizes[0]; > - } > + if (ret < 0) > + goto error_video_probe; > + > + priv->cfmt = _cfmts[0]; > + priv->win = _win_sizes[0]; > + > + ret = v4l2_async_register_subdev(>subdev); > + if (ret) > + goto error_video_probe; > + > + return 0; > + > +error_video_probe: > + if (priv->clk) > + clk_put(priv->clk); clk_put() accepts a NULL clock, you don't have to check the pointer first. > +error_clk_enable: > + v4l2_ctrl_handler_free(>hdl); > > return ret; > } > @@ -1096,7 +1127,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); Same here. > v4l2_device_unregister_subdev(>subdev); > v4l2_ctrl_handler_free(>hdl); > return 0; > diff --git a/include/media/i2c/ov772x.h
Re: [PATCH v1 08/10] media: i2c: ov772x: Remove soc_camera dependencies
On Fri, Nov 17, 2017 at 10:14:51AM +0100, jacopo mondi wrote: > Hi Sakari! > > On Fri, Nov 17, 2017 at 02:43:15AM +0200, Sakari Ailus wrote: > > Hi Jacopo, > > > > On Wed, Nov 15, 2017 at 11:56:01AM +0100, Jacopo Mondi wrote: > > > > > [snip] > > > > +#include > > > #include > > > #include > > > #include > > > @@ -25,8 +26,8 @@ > > > #include > > > > > > #include > > > -#include > > > -#include > > > + > > > +#include > > > > Alphabetical order would be nice. > > ups! > > > > > > #include > > > #include > > > #include > > > @@ -393,7 +394,7 @@ struct ov772x_win_size { > > > struct ov772x_priv { > > > struct v4l2_subdevsubdev; > > > 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; > > > > What does this do, enable the regulator? > > Well, it depends on what function the platform code stores in > 'platform_enable' pointer, doesn't it? > > As you can see in [05/10] of this series, for Migo-R it's not about > a regulator, but switching between the two available video inputs > (OV7725 and TW9910) toggling their 'enable' pins. Ok. That's not a very nice design. Fair enough. I guess it's good to proceed one thing at a time. If someone has this sensor on a board with DT support, we can use the regulator framework and just ignore the platform callbacks. -- Sakari Ailus e-mail: sakari.ai...@iki.fi
Re: [PATCH v1 08/10] media: i2c: ov772x: Remove soc_camera dependencies
Hi Sakari! On Fri, Nov 17, 2017 at 02:43:15AM +0200, Sakari Ailus wrote: > Hi Jacopo, > > On Wed, Nov 15, 2017 at 11:56:01AM +0100, Jacopo Mondi wrote: > > [snip] > > +#include > > #include > > #include > > #include > > @@ -25,8 +26,8 @@ > > #include > > > > #include > > -#include > > -#include > > + > > +#include > > Alphabetical order would be nice. ups! > > > #include > > #include > > #include > > @@ -393,7 +394,7 @@ struct ov772x_win_size { > > struct ov772x_priv { > > struct v4l2_subdevsubdev; > > 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; > > What does this do, enable the regulator? Well, it depends on what function the platform code stores in 'platform_enable' pointer, doesn't it? As you can see in [05/10] of this series, for Migo-R it's not about a regulator, but switching between the two available video inputs (OV7725 and TW9910) toggling their 'enable' pins. Thanks j
Re: [PATCH v1 08/10] media: i2c: ov772x: Remove soc_camera dependencies
Hi Jacopo, On Wed, Nov 15, 2017 at 11:56:01AM +0100, Jacopo Mondi wrote: > Remove soc_camera framework dependencies from ov772x sensor driver. > - Handle clock directly > - Register async subdevice > - Add platform specific enable/disable functions > - Adjust build system > > This commit does not remove the original soc_camera based driver. > > Signed-off-by: Jacopo Mondi> --- > drivers/media/i2c/Kconfig | 12 +++ > drivers/media/i2c/Makefile | 1 + > drivers/media/i2c/ov772x.c | 88 > +++--- > include/media/i2c/ov772x.h | 3 ++ > 4 files changed, 76 insertions(+), 28 deletions(-) > > diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig > index 9415389..ff251ce 100644 > --- a/drivers/media/i2c/Kconfig > +++ b/drivers/media/i2c/Kconfig > @@ -629,6 +629,18 @@ config VIDEO_OV5670 > To compile this driver as a module, choose M here: the > module will be called ov5670. > > +config VIDEO_OV772X > + tristate "OmniVision OV772x sensor support" > + depends on I2C && VIDEO_V4L2 > + depends on MEDIA_CAMERA_SUPPORT > + ---help--- > + This is a Video4Linux2 sensor-level driver for the OmniVision > + OV772x camera. > + > + To compile this driver as a module, choose M here: the > + module will be called ov772x. > + > + > config VIDEO_OV7640 > tristate "OmniVision OV7640 sensor support" > depends on I2C && VIDEO_V4L2 > diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile > index f104650..b2459a1 100644 > --- a/drivers/media/i2c/Makefile > +++ b/drivers/media/i2c/Makefile > @@ -66,6 +66,7 @@ obj-$(CONFIG_VIDEO_OV5645) += ov5645.o > obj-$(CONFIG_VIDEO_OV5647) += ov5647.o > obj-$(CONFIG_VIDEO_OV5670) += ov5670.o > obj-$(CONFIG_VIDEO_OV6650) += ov6650.o > +obj-$(CONFIG_VIDEO_OV772X) += ov772x.o > obj-$(CONFIG_VIDEO_OV7640) += ov7640.o > obj-$(CONFIG_VIDEO_OV7670) += ov7670.o > obj-$(CONFIG_VIDEO_OV9650) += ov9650.o > diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c > index 8063835..9be7e4e 100644 > --- a/drivers/media/i2c/ov772x.c > +++ b/drivers/media/i2c/ov772x.c > @@ -15,6 +15,7 @@ > * published by the Free Software Foundation. > */ > > +#include > #include > #include > #include > @@ -25,8 +26,8 @@ > #include > > #include > -#include > -#include > + > +#include Alphabetical order would be nice. > #include > #include > #include > @@ -393,7 +394,7 @@ struct ov772x_win_size { > struct ov772x_priv { > struct v4l2_subdevsubdev; > 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; What does this do, enable the regulator? > + } > + > + /* 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(>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) > @@ -1000,14 +1024,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); > >
[PATCH v1 08/10] media: i2c: ov772x: Remove soc_camera dependencies
Remove soc_camera framework dependencies from ov772x sensor driver. - Handle clock directly - Register async subdevice - Add platform specific enable/disable functions - Adjust build system This commit does not remove the original soc_camera based driver. Signed-off-by: Jacopo Mondi--- drivers/media/i2c/Kconfig | 12 +++ drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov772x.c | 88 +++--- include/media/i2c/ov772x.h | 3 ++ 4 files changed, 76 insertions(+), 28 deletions(-) diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 9415389..ff251ce 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -629,6 +629,18 @@ config VIDEO_OV5670 To compile this driver as a module, choose M here: the module will be called ov5670. +config VIDEO_OV772X + tristate "OmniVision OV772x sensor support" + depends on I2C && VIDEO_V4L2 + depends on MEDIA_CAMERA_SUPPORT + ---help--- + This is a Video4Linux2 sensor-level driver for the OmniVision + OV772x camera. + + To compile this driver as a module, choose M here: the + module will be called ov772x. + + config VIDEO_OV7640 tristate "OmniVision OV7640 sensor support" depends on I2C && VIDEO_V4L2 diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index f104650..b2459a1 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_VIDEO_OV5645) += ov5645.o obj-$(CONFIG_VIDEO_OV5647) += ov5647.o obj-$(CONFIG_VIDEO_OV5670) += ov5670.o obj-$(CONFIG_VIDEO_OV6650) += ov6650.o +obj-$(CONFIG_VIDEO_OV772X) += ov772x.o obj-$(CONFIG_VIDEO_OV7640) += ov7640.o obj-$(CONFIG_VIDEO_OV7670) += ov7670.o obj-$(CONFIG_VIDEO_OV9650) += ov9650.o diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index 8063835..9be7e4e 100644 --- a/drivers/media/i2c/ov772x.c +++ b/drivers/media/i2c/ov772x.c @@ -15,6 +15,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -25,8 +26,8 @@ #include #include -#include -#include + +#include #include #include #include @@ -393,7 +394,7 @@ struct ov772x_win_size { struct ov772x_priv { struct v4l2_subdevsubdev; 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(>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) @@ -1000,14 +1024,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; } @@ -1038,12 +1058,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