All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] dt-bindings: adv7180: Introduce the 'reset-gpios' property
@ 2021-05-30 20:44 Fabio Estevam
  2021-05-30 20:44 ` [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin Fabio Estevam
  2021-05-30 20:44 ` [PATCH 3/3] media: i2c: adv7180: Print the chip ID on probe Fabio Estevam
  0 siblings, 2 replies; 6+ messages in thread
From: Fabio Estevam @ 2021-05-30 20:44 UTC (permalink / raw)
  To: hverkuil-cisco
  Cc: lars, robh+dt, devicetree, linux-media, tharvey,
	frieder.schrempf, niklas.soderlund, Fabio Estevam

Introduce the 'reset-gpios' property to describe the GPIO that connects
to the ADV7180 reset pin.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 Documentation/devicetree/bindings/media/i2c/adv7180.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/i2c/adv7180.yaml b/Documentation/devicetree/bindings/media/i2c/adv7180.yaml
index bcfd93739b4f..1f1aa46f5724 100644
--- a/Documentation/devicetree/bindings/media/i2c/adv7180.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/adv7180.yaml
@@ -35,6 +35,9 @@ properties:
   powerdown-gpios:
     maxItems: 1
 
+  reset-gpios:
+    maxItems: 1
+
   port:
     $ref: /schemas/graph.yaml#/properties/port
 
-- 
2.25.1


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

* [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin
  2021-05-30 20:44 [PATCH 1/3] dt-bindings: adv7180: Introduce the 'reset-gpios' property Fabio Estevam
@ 2021-05-30 20:44 ` Fabio Estevam
  2021-05-31  7:02   ` Frieder Schrempf
  2021-05-30 20:44 ` [PATCH 3/3] media: i2c: adv7180: Print the chip ID on probe Fabio Estevam
  1 sibling, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2021-05-30 20:44 UTC (permalink / raw)
  To: hverkuil-cisco
  Cc: lars, robh+dt, devicetree, linux-media, tharvey,
	frieder.schrempf, niklas.soderlund, Fabio Estevam

On a design where the ADV7180 pin is pulled down, it is not possible
to make it functional unless the GPIO connected to this pin goes
high.

Add support for the reset GPIO by introducing an optional property
called 'reset-gpios'.

Note: the reset operation is still performed via software as recommended
by the Analog Devices, but the reset GPIO still needs to go high to make
the chip operational.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 drivers/media/i2c/adv7180.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 44bb6fe85644..2811f2c337fa 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -205,6 +205,7 @@ struct adv7180_state {
 	struct mutex		mutex; /* mutual excl. when accessing chip */
 	int			irq;
 	struct gpio_desc	*pwdn_gpio;
+	struct gpio_desc	*reset_gpio;
 	v4l2_std_id		curr_norm;
 	bool			powered;
 	bool			streaming;
@@ -473,13 +474,15 @@ static int adv7180_g_frame_interval(struct v4l2_subdev *sd,
 
 static void adv7180_set_power_pin(struct adv7180_state *state, bool on)
 {
-	if (!state->pwdn_gpio)
+	if (!state->pwdn_gpio && !state->reset_gpio)
 		return;
 
 	if (on) {
+		gpiod_set_value_cansleep(state->reset_gpio, 0);
 		gpiod_set_value_cansleep(state->pwdn_gpio, 0);
 		usleep_range(5000, 10000);
 	} else {
+		gpiod_set_value_cansleep(state->reset_gpio, 1);
 		gpiod_set_value_cansleep(state->pwdn_gpio, 1);
 	}
 }
@@ -1338,6 +1341,15 @@ static int adv7180_probe(struct i2c_client *client,
 		return ret;
 	}
 
+	state->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
+						     GPIOD_OUT_HIGH);
+	if (IS_ERR(state->reset_gpio)) {
+		ret = PTR_ERR(state->reset_gpio);
+		v4l_err(client, "request for reset pin failed: %d\n", ret);
+		return ret;
+	}
+
+
 	if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
 		state->csi_client = i2c_new_dummy_device(client->adapter,
 				ADV7180_DEFAULT_CSI_I2C_ADDR);
-- 
2.25.1


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

* [PATCH 3/3] media: i2c: adv7180: Print the chip ID on probe
  2021-05-30 20:44 [PATCH 1/3] dt-bindings: adv7180: Introduce the 'reset-gpios' property Fabio Estevam
  2021-05-30 20:44 ` [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin Fabio Estevam
@ 2021-05-30 20:44 ` Fabio Estevam
  2021-05-31  7:04   ` Frieder Schrempf
  1 sibling, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2021-05-30 20:44 UTC (permalink / raw)
  To: hverkuil-cisco
  Cc: lars, robh+dt, devicetree, linux-media, tharvey,
	frieder.schrempf, niklas.soderlund, Fabio Estevam

Improve the probe message by printing the chip ID version.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 drivers/media/i2c/adv7180.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 2811f2c337fa..e5ef99f0460c 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -1404,11 +1404,19 @@ static int adv7180_probe(struct i2c_client *client,
 	if (ret)
 		goto err_free_irq;
 
-	v4l_info(client, "chip found @ 0x%02x (%s)\n",
-		 client->addr, client->adapter->name);
+	mutex_lock(&state->mutex);
+	ret = adv7180_read(state, ADV7180_REG_IDENT);
+	mutex_unlock(&state->mutex);
+	if (ret < 0)
+		goto err_v4l2_async_unregister;
+
+	v4l_info(client, "chip id 0x%x found @ 0x%02x (%s)\n",
+		 ret, client->addr, client->adapter->name);
 
 	return 0;
 
+err_v4l2_async_unregister:
+	v4l2_async_unregister_subdev(sd);
 err_free_irq:
 	if (state->irq > 0)
 		free_irq(client->irq, state);
-- 
2.25.1


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

* Re: [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin
  2021-05-30 20:44 ` [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin Fabio Estevam
@ 2021-05-31  7:02   ` Frieder Schrempf
  2021-05-31 10:48     ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: Frieder Schrempf @ 2021-05-31  7:02 UTC (permalink / raw)
  To: Fabio Estevam, hverkuil-cisco
  Cc: lars, robh+dt, devicetree, linux-media, tharvey, niklas.soderlund

On 30.05.21 22:44, Fabio Estevam wrote:
> On a design where the ADV7180 pin is pulled down, it is not possible
> to make it functional unless the GPIO connected to this pin goes
> high.
> 
> Add support for the reset GPIO by introducing an optional property
> called 'reset-gpios'.
> 
> Note: the reset operation is still performed via software as recommended
> by the Analog Devices, but the reset GPIO still needs to go high to make
> the chip operational.
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>  drivers/media/i2c/adv7180.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
> index 44bb6fe85644..2811f2c337fa 100644
> --- a/drivers/media/i2c/adv7180.c
> +++ b/drivers/media/i2c/adv7180.c
> @@ -205,6 +205,7 @@ struct adv7180_state {
>  	struct mutex		mutex; /* mutual excl. when accessing chip */
>  	int			irq;
>  	struct gpio_desc	*pwdn_gpio;
> +	struct gpio_desc	*reset_gpio;
>  	v4l2_std_id		curr_norm;
>  	bool			powered;
>  	bool			streaming;
> @@ -473,13 +474,15 @@ static int adv7180_g_frame_interval(struct v4l2_subdev *sd,
>  
>  static void adv7180_set_power_pin(struct adv7180_state *state, bool on)
>  {
> -	if (!state->pwdn_gpio)
> +	if (!state->pwdn_gpio && !state->reset_gpio)
>  		return;
>  
>  	if (on) {
> +		gpiod_set_value_cansleep(state->reset_gpio, 0);
>  		gpiod_set_value_cansleep(state->pwdn_gpio, 0);

The datasheet specifies a delay of 5 ms between deasserting the PWRDWN and the RESET GPIO. Also this function is named adv7180_set_power_pin() which doesn't fit anymore if we also handle the RESET GPIO here.

As I was recently working with the ADV7280-M, I came up with a similar patch: https://git.kontron-electronics.de/linux/linux/-/commit/3619ed166140a0499ada7b14e5f1846a0ed7d18d.

What do you think?

>  		usleep_range(5000, 10000);
>  	} else {
> +		gpiod_set_value_cansleep(state->reset_gpio, 1);
>  		gpiod_set_value_cansleep(state->pwdn_gpio, 1);
>  	}
>  }
> @@ -1338,6 +1341,15 @@ static int adv7180_probe(struct i2c_client *client,
>  		return ret;
>  	}
>  
> +	state->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
> +						     GPIOD_OUT_HIGH);
> +	if (IS_ERR(state->reset_gpio)) {
> +		ret = PTR_ERR(state->reset_gpio);
> +		v4l_err(client, "request for reset pin failed: %d\n", ret);
> +		return ret;
> +	}
> +
> +
>  	if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
>  		state->csi_client = i2c_new_dummy_device(client->adapter,
>  				ADV7180_DEFAULT_CSI_I2C_ADDR);
> 

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

* Re: [PATCH 3/3] media: i2c: adv7180: Print the chip ID on probe
  2021-05-30 20:44 ` [PATCH 3/3] media: i2c: adv7180: Print the chip ID on probe Fabio Estevam
@ 2021-05-31  7:04   ` Frieder Schrempf
  0 siblings, 0 replies; 6+ messages in thread
From: Frieder Schrempf @ 2021-05-31  7:04 UTC (permalink / raw)
  To: Fabio Estevam, hverkuil-cisco
  Cc: lars, robh+dt, devicetree, linux-media, tharvey, niklas.soderlund

On 30.05.21 22:44, Fabio Estevam wrote:
> Improve the probe message by printing the chip ID version.
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

> ---
>  drivers/media/i2c/adv7180.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
> index 2811f2c337fa..e5ef99f0460c 100644
> --- a/drivers/media/i2c/adv7180.c
> +++ b/drivers/media/i2c/adv7180.c
> @@ -1404,11 +1404,19 @@ static int adv7180_probe(struct i2c_client *client,
>  	if (ret)
>  		goto err_free_irq;
>  
> -	v4l_info(client, "chip found @ 0x%02x (%s)\n",
> -		 client->addr, client->adapter->name);
> +	mutex_lock(&state->mutex);
> +	ret = adv7180_read(state, ADV7180_REG_IDENT);
> +	mutex_unlock(&state->mutex);
> +	if (ret < 0)
> +		goto err_v4l2_async_unregister;
> +
> +	v4l_info(client, "chip id 0x%x found @ 0x%02x (%s)\n",
> +		 ret, client->addr, client->adapter->name);
>  
>  	return 0;
>  
> +err_v4l2_async_unregister:
> +	v4l2_async_unregister_subdev(sd);
>  err_free_irq:
>  	if (state->irq > 0)
>  		free_irq(client->irq, state);
> 

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

* Re: [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin
  2021-05-31  7:02   ` Frieder Schrempf
@ 2021-05-31 10:48     ` Fabio Estevam
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2021-05-31 10:48 UTC (permalink / raw)
  To: Frieder Schrempf
  Cc: Hans Verkuil, Lars-Peter Clausen, Rob Herring,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-media, Tim Harvey, Niklas Söderlund

Hi Frieder,

On Mon, May 31, 2021 at 4:02 AM Frieder Schrempf
<frieder.schrempf@kontron.de> wrote:

> The datasheet specifies a delay of 5 ms between deasserting the PWRDWN and the RESET GPIO. Also this function is named adv7180_set_power_pin() which doesn't fit anymore if we also handle the RESET GPIO here.
>
> As I was recently working with the ADV7280-M, I came up with a similar patch: https://git.kontron-electronics.de/linux/linux/-/commit/3619ed166140a0499ada7b14e5f1846a0ed7d18d.
>
> What do you think?

Thanks for the review. I will send a v2 using your patch instead of mine.

Thanks,

Fabio Estevam

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

end of thread, other threads:[~2021-05-31 10:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-30 20:44 [PATCH 1/3] dt-bindings: adv7180: Introduce the 'reset-gpios' property Fabio Estevam
2021-05-30 20:44 ` [PATCH 2/3] media: i2c: adv7180: Allow the control of the reset pin Fabio Estevam
2021-05-31  7:02   ` Frieder Schrempf
2021-05-31 10:48     ` Fabio Estevam
2021-05-30 20:44 ` [PATCH 3/3] media: i2c: adv7180: Print the chip ID on probe Fabio Estevam
2021-05-31  7:04   ` Frieder Schrempf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.