diff mbox series

[3/3] media: i2c: max9286: Provide optional enable-gpio

Message ID 20191206140520.10457-3-kieran.bingham@ideasonboard.com (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series [1/3] media: i2c: max9286: Remove redundant max9286_i2c_mux_state | expand

Commit Message

Kieran Bingham Dec. 6, 2019, 2:05 p.m. UTC
The MAX9286 has a negated PWDN line which must be raised to enable the
device.  On the Eagle-V3M this pin is connected to a GPIO on the
io_expander.

Provide an enable-gpio dt property to specify the link, and ensure that
the line is handled in the driver accordingly.

This can also provide the abiltiy to manage low power states and
runtime-pm at a later date by fully powering down the chip.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 drivers/media/i2c/max9286.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Kieran Bingham Dec. 10, 2019, 10:21 a.m. UTC | #1
Hi all,

On 06/12/2019 14:05, Kieran Bingham wrote:
> The MAX9286 has a negated PWDN line which must be raised to enable the
> device.  On the Eagle-V3M this pin is connected to a GPIO on the
> io_expander.
> 
> Provide an enable-gpio dt property to specify the link, and ensure that
> the line is handled in the driver accordingly.
> 
> This can also provide the abiltiy to manage low power states and
> runtime-pm at a later date by fully powering down the chip.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

I'm happy that this one isn't going to cause any contention, and I'm
going to fold this one into the driver.

--
Kieran


> ---
>  drivers/media/i2c/max9286.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> index c34e7b5c7447..67065cd99d8d 100644
> --- a/drivers/media/i2c/max9286.c
> +++ b/drivers/media/i2c/max9286.c
> @@ -13,6 +13,7 @@
>  #include <linux/delay.h>
>  #include <linux/device.h>
>  #include <linux/fwnode.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/gpio/driver.h>
>  #include <linux/i2c.h>
>  #include <linux/i2c-mux.h>
> @@ -143,6 +144,7 @@ struct max9286_source {
>  
>  struct max9286_priv {
>  	struct i2c_client *client;
> +	struct gpio_desc *gpiod_pwdn;
>  	struct v4l2_subdev sd;
>  	struct media_pad pads[MAX9286_N_PADS];
>  	struct regulator *regulator;
> @@ -1044,6 +1046,14 @@ static int max9286_probe(struct i2c_client *client)
>  	if (ret)
>  		return ret;
>  
> +	priv->gpiod_pwdn = devm_gpiod_get_optional(&client->dev, "enable",
> +						   GPIOD_OUT_HIGH);
> +	if (IS_ERR(priv->gpiod_pwdn))
> +		return PTR_ERR(priv->gpiod_pwdn);
> +
> +	gpiod_set_consumer_name(priv->gpiod_pwdn, "max9286-pwdn");
> +	gpiod_set_value_cansleep(priv->gpiod_pwdn, 1);
> +
>  	/*
>  	 * It is possible to set up the power regulator from the GPIO lines,
>  	 * so it needs to be set up early.
> @@ -1117,6 +1127,9 @@ static int max9286_remove(struct i2c_client *client)
>  	regulator_put(priv->regulator);
>  
>  	max9286_cleanup_dt(priv);
> +
> +	gpiod_set_value_cansleep(priv->gpiod_pwdn, 0);
> +
>  	kfree(priv);
>  
>  	return 0;
>
diff mbox series

Patch

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index c34e7b5c7447..67065cd99d8d 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -13,6 +13,7 @@ 
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/fwnode.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
@@ -143,6 +144,7 @@  struct max9286_source {
 
 struct max9286_priv {
 	struct i2c_client *client;
+	struct gpio_desc *gpiod_pwdn;
 	struct v4l2_subdev sd;
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
@@ -1044,6 +1046,14 @@  static int max9286_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
+	priv->gpiod_pwdn = devm_gpiod_get_optional(&client->dev, "enable",
+						   GPIOD_OUT_HIGH);
+	if (IS_ERR(priv->gpiod_pwdn))
+		return PTR_ERR(priv->gpiod_pwdn);
+
+	gpiod_set_consumer_name(priv->gpiod_pwdn, "max9286-pwdn");
+	gpiod_set_value_cansleep(priv->gpiod_pwdn, 1);
+
 	/*
 	 * It is possible to set up the power regulator from the GPIO lines,
 	 * so it needs to be set up early.
@@ -1117,6 +1127,9 @@  static int max9286_remove(struct i2c_client *client)
 	regulator_put(priv->regulator);
 
 	max9286_cleanup_dt(priv);
+
+	gpiod_set_value_cansleep(priv->gpiod_pwdn, 0);
+
 	kfree(priv);
 
 	return 0;