linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] IMX290 sensor driver fixes
@ 2020-02-26 21:59 Andrey Konovalov
  2020-02-26 21:59 ` [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called Andrey Konovalov
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andrey Konovalov @ 2020-02-26 21:59 UTC (permalink / raw)
  To: mchehab, sakari.ailus
  Cc: linux-media, manivannan.sadhasivam, peter.griffin, Andrey Konovalov

This patchset deals with two issues in the IMX290 driver:
  - the current_format field in the struct imx290 can be used before
    initialization,
  - the reset signal to IMX290 isn't handled correctly.

Andrey Konovalov (3):
  media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is
    called
  media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS()
  media: i2c: imx290: fix reset GPIO pin handling

 drivers/media/i2c/imx290.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called
  2020-02-26 21:59 [PATCH 0/3] IMX290 sensor driver fixes Andrey Konovalov
@ 2020-02-26 21:59 ` Andrey Konovalov
  2020-03-03  9:30   ` Manivannan Sadhasivam
  2020-02-26 21:59 ` [PATCH 2/3] media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS() Andrey Konovalov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Andrey Konovalov @ 2020-02-26 21:59 UTC (permalink / raw)
  To: mchehab, sakari.ailus
  Cc: linux-media, manivannan.sadhasivam, peter.griffin, Andrey Konovalov

With the current driver 'media-ctl -p' issued right after the imx290 driver
is loaded prints:
pad0: Source
             [fmt:unknown/0x0]

The format value of zero is due to the current_format field of the imx290
struct not being initialized yet.

As imx290_entity_init_cfg() calls imx290_set_fmt(), the current_mode field
is also initialized, so the line which set current_mode to a default value
in driver's probe() function is no longer needed.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
---
 drivers/media/i2c/imx290.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
index f7678e5a5d87..2d8c38ffe2f0 100644
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -722,9 +722,6 @@ static int imx290_probe(struct i2c_client *client)
 		goto free_err;
 	}
 
-	/* Set default mode to max resolution */
-	imx290->current_mode = &imx290_modes[0];
-
 	/* get system clock (xclk) */
 	imx290->xclk = devm_clk_get(dev, "xclk");
 	if (IS_ERR(imx290->xclk)) {
@@ -809,6 +806,9 @@ static int imx290_probe(struct i2c_client *client)
 		goto free_ctrl;
 	}
 
+	/* Initialize the frame format (this also sets imx290->current_mode) */
+	imx290_entity_init_cfg(&imx290->sd, NULL);
+
 	ret = v4l2_async_register_subdev(&imx290->sd);
 	if (ret < 0) {
 		dev_err(dev, "Could not register v4l2 device\n");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS()
  2020-02-26 21:59 [PATCH 0/3] IMX290 sensor driver fixes Andrey Konovalov
  2020-02-26 21:59 ` [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called Andrey Konovalov
@ 2020-02-26 21:59 ` Andrey Konovalov
  2020-03-03  9:39   ` Manivannan Sadhasivam
  2020-02-26 21:59 ` [PATCH 3/3] media: i2c: imx290: fix reset GPIO pin handling Andrey Konovalov
  2020-04-07  8:19 ` [PATCH 0/3] IMX290 sensor driver fixes Manivannan Sadhasivam
  3 siblings, 1 reply; 8+ messages in thread
From: Andrey Konovalov @ 2020-02-26 21:59 UTC (permalink / raw)
  To: mchehab, sakari.ailus
  Cc: linux-media, manivannan.sadhasivam, peter.griffin, Andrey Konovalov

This macro is defined as SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn),
so imx290_power_off must be the 1st arg, and imx290_power_on the 2nd.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
---
 drivers/media/i2c/imx290.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
index 2d8c38ffe2f0..d0322f9a8856 100644
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -648,7 +648,7 @@ static int imx290_power_off(struct device *dev)
 }
 
 static const struct dev_pm_ops imx290_pm_ops = {
-	SET_RUNTIME_PM_OPS(imx290_power_on, imx290_power_off, NULL)
+	SET_RUNTIME_PM_OPS(imx290_power_off, imx290_power_on, NULL)
 };
 
 static const struct v4l2_subdev_video_ops imx290_video_ops = {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] media: i2c: imx290: fix reset GPIO pin handling
  2020-02-26 21:59 [PATCH 0/3] IMX290 sensor driver fixes Andrey Konovalov
  2020-02-26 21:59 ` [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called Andrey Konovalov
  2020-02-26 21:59 ` [PATCH 2/3] media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS() Andrey Konovalov
@ 2020-02-26 21:59 ` Andrey Konovalov
  2020-03-03 11:33   ` Manivannan Sadhasivam
  2020-04-07  8:19 ` [PATCH 0/3] IMX290 sensor driver fixes Manivannan Sadhasivam
  3 siblings, 1 reply; 8+ messages in thread
From: Andrey Konovalov @ 2020-02-26 21:59 UTC (permalink / raw)
  To: mchehab, sakari.ailus
  Cc: linux-media, manivannan.sadhasivam, peter.griffin, Andrey Konovalov

According to https://www.kernel.org/doc/Documentation/gpio/consumer.txt,

- all of the gpiod_set_value_xxx() functions operate with the *logical* value.
So in imx290_power_on() the reset signal should be cleared/de-asserted with
gpiod_set_value_cansleep(imx290->rst_gpio, 0), and in imx290_power_off() the
value of 1 must be used to apply/assert the reset to the sensor. In the device
tree the reset pin is described as GPIO_ACTIVE_LOW, and gpiod_set_value_xxx()
functions take this into account,

- when devm_gpiod_get_optional() is called with GPIOD_ASIS, the GPIO is not
initialized, and the direction must be set later; using a GPIO
without setting its direction first is illegal and will result in undefined
behavior. Fix this by using GPIOD_OUT_HIGH instead of GPIOD_ASIS (this asserts
the reset signal to the sensor initially).

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
---
 drivers/media/i2c/imx290.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
index d0322f9a8856..7b1de1f0c8b7 100644
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -628,7 +628,7 @@ static int imx290_power_on(struct device *dev)
 	}
 
 	usleep_range(1, 2);
-	gpiod_set_value_cansleep(imx290->rst_gpio, 1);
+	gpiod_set_value_cansleep(imx290->rst_gpio, 0);
 	usleep_range(30000, 31000);
 
 	return 0;
@@ -641,7 +641,7 @@ static int imx290_power_off(struct device *dev)
 	struct imx290 *imx290 = to_imx290(sd);
 
 	clk_disable_unprepare(imx290->xclk);
-	gpiod_set_value_cansleep(imx290->rst_gpio, 0);
+	gpiod_set_value_cansleep(imx290->rst_gpio, 1);
 	regulator_bulk_disable(IMX290_NUM_SUPPLIES, imx290->supplies);
 
 	return 0;
@@ -757,7 +757,8 @@ static int imx290_probe(struct i2c_client *client)
 		goto free_err;
 	}
 
-	imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
+	imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset",
+						   GPIOD_OUT_HIGH);
 	if (IS_ERR(imx290->rst_gpio)) {
 		dev_err(dev, "Cannot get reset gpio\n");
 		ret = PTR_ERR(imx290->rst_gpio);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called
  2020-02-26 21:59 ` [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called Andrey Konovalov
@ 2020-03-03  9:30   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2020-03-03  9:30 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: mchehab, sakari.ailus, linux-media, peter.griffin

On Thu, Feb 27, 2020 at 12:59:11AM +0300, Andrey Konovalov wrote:
> With the current driver 'media-ctl -p' issued right after the imx290 driver
> is loaded prints:
> pad0: Source
>              [fmt:unknown/0x0]
> 
> The format value of zero is due to the current_format field of the imx290
> struct not being initialized yet.
> 
> As imx290_entity_init_cfg() calls imx290_set_fmt(), the current_mode field
> is also initialized, so the line which set current_mode to a default value
> in driver's probe() function is no longer needed.
> 
> Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Thanks,
Mani

> ---
>  drivers/media/i2c/imx290.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
> index f7678e5a5d87..2d8c38ffe2f0 100644
> --- a/drivers/media/i2c/imx290.c
> +++ b/drivers/media/i2c/imx290.c
> @@ -722,9 +722,6 @@ static int imx290_probe(struct i2c_client *client)
>  		goto free_err;
>  	}
>  
> -	/* Set default mode to max resolution */
> -	imx290->current_mode = &imx290_modes[0];
> -
>  	/* get system clock (xclk) */
>  	imx290->xclk = devm_clk_get(dev, "xclk");
>  	if (IS_ERR(imx290->xclk)) {
> @@ -809,6 +806,9 @@ static int imx290_probe(struct i2c_client *client)
>  		goto free_ctrl;
>  	}
>  
> +	/* Initialize the frame format (this also sets imx290->current_mode) */
> +	imx290_entity_init_cfg(&imx290->sd, NULL);
> +
>  	ret = v4l2_async_register_subdev(&imx290->sd);
>  	if (ret < 0) {
>  		dev_err(dev, "Could not register v4l2 device\n");
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS()
  2020-02-26 21:59 ` [PATCH 2/3] media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS() Andrey Konovalov
@ 2020-03-03  9:39   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2020-03-03  9:39 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: mchehab, sakari.ailus, linux-media, peter.griffin

On Thu, Feb 27, 2020 at 12:59:12AM +0300, Andrey Konovalov wrote:
> This macro is defined as SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn),
> so imx290_power_off must be the 1st arg, and imx290_power_on the 2nd.
>

Oops. That's a mistake.
 
> Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Thanks,
Mani

> ---
>  drivers/media/i2c/imx290.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
> index 2d8c38ffe2f0..d0322f9a8856 100644
> --- a/drivers/media/i2c/imx290.c
> +++ b/drivers/media/i2c/imx290.c
> @@ -648,7 +648,7 @@ static int imx290_power_off(struct device *dev)
>  }
>  
>  static const struct dev_pm_ops imx290_pm_ops = {
> -	SET_RUNTIME_PM_OPS(imx290_power_on, imx290_power_off, NULL)
> +	SET_RUNTIME_PM_OPS(imx290_power_off, imx290_power_on, NULL)
>  };
>  
>  static const struct v4l2_subdev_video_ops imx290_video_ops = {
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] media: i2c: imx290: fix reset GPIO pin handling
  2020-02-26 21:59 ` [PATCH 3/3] media: i2c: imx290: fix reset GPIO pin handling Andrey Konovalov
@ 2020-03-03 11:33   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2020-03-03 11:33 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: mchehab, sakari.ailus, linux-media, peter.griffin

On Thu, Feb 27, 2020 at 12:59:13AM +0300, Andrey Konovalov wrote:
> According to https://www.kernel.org/doc/Documentation/gpio/consumer.txt,
> 
> - all of the gpiod_set_value_xxx() functions operate with the *logical* value.
> So in imx290_power_on() the reset signal should be cleared/de-asserted with
> gpiod_set_value_cansleep(imx290->rst_gpio, 0), and in imx290_power_off() the
> value of 1 must be used to apply/assert the reset to the sensor. In the device
> tree the reset pin is described as GPIO_ACTIVE_LOW, and gpiod_set_value_xxx()
> functions take this into account,
> 
> - when devm_gpiod_get_optional() is called with GPIOD_ASIS, the GPIO is not
> initialized, and the direction must be set later; using a GPIO
> without setting its direction first is illegal and will result in undefined
> behavior. Fix this by using GPIOD_OUT_HIGH instead of GPIOD_ASIS (this asserts
> the reset signal to the sensor initially).
> 

I didn't catch this issue since I've been using IMX290 board on top of Sensors
mezzanine which has the pullup on that pin. But this fix LGTM.

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Thanks,
Mani

> Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> ---
>  drivers/media/i2c/imx290.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
> index d0322f9a8856..7b1de1f0c8b7 100644
> --- a/drivers/media/i2c/imx290.c
> +++ b/drivers/media/i2c/imx290.c
> @@ -628,7 +628,7 @@ static int imx290_power_on(struct device *dev)
>  	}
>  
>  	usleep_range(1, 2);
> -	gpiod_set_value_cansleep(imx290->rst_gpio, 1);
> +	gpiod_set_value_cansleep(imx290->rst_gpio, 0);
>  	usleep_range(30000, 31000);
>  
>  	return 0;
> @@ -641,7 +641,7 @@ static int imx290_power_off(struct device *dev)
>  	struct imx290 *imx290 = to_imx290(sd);
>  
>  	clk_disable_unprepare(imx290->xclk);
> -	gpiod_set_value_cansleep(imx290->rst_gpio, 0);
> +	gpiod_set_value_cansleep(imx290->rst_gpio, 1);
>  	regulator_bulk_disable(IMX290_NUM_SUPPLIES, imx290->supplies);
>  
>  	return 0;
> @@ -757,7 +757,8 @@ static int imx290_probe(struct i2c_client *client)
>  		goto free_err;
>  	}
>  
> -	imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
> +	imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset",
> +						   GPIOD_OUT_HIGH);
>  	if (IS_ERR(imx290->rst_gpio)) {
>  		dev_err(dev, "Cannot get reset gpio\n");
>  		ret = PTR_ERR(imx290->rst_gpio);
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] IMX290 sensor driver fixes
  2020-02-26 21:59 [PATCH 0/3] IMX290 sensor driver fixes Andrey Konovalov
                   ` (2 preceding siblings ...)
  2020-02-26 21:59 ` [PATCH 3/3] media: i2c: imx290: fix reset GPIO pin handling Andrey Konovalov
@ 2020-04-07  8:19 ` Manivannan Sadhasivam
  3 siblings, 0 replies; 8+ messages in thread
From: Manivannan Sadhasivam @ 2020-04-07  8:19 UTC (permalink / raw)
  To: mchehab, sakari.ailus; +Cc: Andrey Konovalov, linux-media, peter.griffin

Hi,

On Thu, Feb 27, 2020 at 12:59:10AM +0300, Andrey Konovalov wrote:
> This patchset deals with two issues in the IMX290 driver:
>   - the current_format field in the struct imx290 can be used before
>     initialization,
>   - the reset signal to IMX290 isn't handled correctly.
> 
> Andrey Konovalov (3):
>   media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is
>     called
>   media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS()
>   media: i2c: imx290: fix reset GPIO pin handling
> 

Any update on this series?

Thanks,
Mani

>  drivers/media/i2c/imx290.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-04-07  8:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 21:59 [PATCH 0/3] IMX290 sensor driver fixes Andrey Konovalov
2020-02-26 21:59 ` [PATCH 1/3] media: i2c: imx290: set the format before VIDIOC_SUBDEV_G_FMT is called Andrey Konovalov
2020-03-03  9:30   ` Manivannan Sadhasivam
2020-02-26 21:59 ` [PATCH 2/3] media: i2c: imx290: fix the order of the args in SET_RUNTIME_PM_OPS() Andrey Konovalov
2020-03-03  9:39   ` Manivannan Sadhasivam
2020-02-26 21:59 ` [PATCH 3/3] media: i2c: imx290: fix reset GPIO pin handling Andrey Konovalov
2020-03-03 11:33   ` Manivannan Sadhasivam
2020-04-07  8:19 ` [PATCH 0/3] IMX290 sensor driver fixes Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).