diff mbox series

[v5,4/4] media: i2c: imx412: Add bulk regulator support

Message ID 20220415115954.1649217-5-bryan.odonoghue@linaro.org (mailing list archive)
State New, archived
Headers show
Series media: i2c: imx412: Add regulator control to imx412 | expand

Commit Message

Bryan O'Donoghue April 15, 2022, 11:59 a.m. UTC
Depending on the platform we may need to enable and disable three separate
regulators for the imx412.

- DOVDD
Digital I/O power

- AVDD
Analog power

- DVDD
Digital core power

The addition of these regulators shouldn't affect existing users using
fixed-on/firmware-controlled regulators.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/media/i2c/imx412.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Jacopo Mondi April 15, 2022, 3:12 p.m. UTC | #1
Hello Bryan

On Fri, Apr 15, 2022 at 12:59:54PM +0100, Bryan O'Donoghue wrote:
> Depending on the platform we may need to enable and disable three separate
> regulators for the imx412.
>
> - DOVDD
> Digital I/O power
>
> - AVDD
> Analog power
>
> - DVDD
> Digital core power
>
> The addition of these regulators shouldn't affect existing users using
> fixed-on/firmware-controlled regulators.
>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

Thanks
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Cheers
   j

> ---
>  drivers/media/i2c/imx412.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
> index 84279a680873..1795a6180d60 100644
> --- a/drivers/media/i2c/imx412.c
> +++ b/drivers/media/i2c/imx412.c
> @@ -11,6 +11,7 @@
>  #include <linux/i2c.h>
>  #include <linux/module.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-fwnode.h>
> @@ -101,6 +102,12 @@ struct imx412_mode {
>  	struct imx412_reg_list reg_list;
>  };
>
> +static const char * const imx412_supply_names[] = {
> +	"dovdd",	/* Digital I/O power */
> +	"avdd",		/* Analog power */
> +	"dvdd",		/* Digital core power */
> +};
> +
>  /**
>   * struct imx412 - imx412 sensor device structure
>   * @dev: Pointer to generic device
> @@ -128,6 +135,7 @@ struct imx412 {
>  	struct media_pad pad;
>  	struct gpio_desc *reset_gpio;
>  	struct clk *inclk;
> +	struct regulator_bulk_data supplies[ARRAY_SIZE(imx412_supply_names)];
>  	struct v4l2_ctrl_handler ctrl_handler;
>  	struct v4l2_ctrl *link_freq_ctrl;
>  	struct v4l2_ctrl *pclk_ctrl;
> @@ -946,6 +954,16 @@ static int imx412_parse_hw_config(struct imx412 *imx412)
>  		return -EINVAL;
>  	}
>
> +	/* Get optional DT defined regulators */
> +	for (i = 0; i < ARRAY_SIZE(imx412_supply_names); i++)
> +		imx412->supplies[i].supply = imx412_supply_names[i];
> +
> +	ret = devm_regulator_bulk_get(imx412->dev,
> +				      ARRAY_SIZE(imx412_supply_names),
> +				      imx412->supplies);
> +	if (ret)
> +		return ret;
> +
>  	ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
>  	if (!ep)
>  		return -ENXIO;
> @@ -1011,6 +1029,13 @@ static int imx412_power_on(struct device *dev)
>  	struct imx412 *imx412 = to_imx412(sd);
>  	int ret;
>
> +	ret = regulator_bulk_enable(ARRAY_SIZE(imx412_supply_names),
> +				    imx412->supplies);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to enable regulators\n");
> +		return ret;
> +	}
> +
>  	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
>
>  	ret = clk_prepare_enable(imx412->inclk);
> @@ -1025,6 +1050,8 @@ static int imx412_power_on(struct device *dev)
>
>  error_reset:
>  	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
> +	regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
> +			       imx412->supplies);
>
>  	return ret;
>  }
> @@ -1044,6 +1071,9 @@ static int imx412_power_off(struct device *dev)
>
>  	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
>
> +	regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
> +			       imx412->supplies);
> +
>  	return 0;
>  }
>
> --
> 2.35.1
>
Alessandrelli, Daniele April 26, 2022, 4:52 p.m. UTC | #2
On Fri, 2022-04-15 at 12:59 +0100, Bryan O'Donoghue wrote:
> Depending on the platform we may need to enable and disable three separate
> regulators for the imx412.
> 
> - DOVDD
> Digital I/O power
> 
> - AVDD
> Analog power
> 
> - DVDD
> Digital core power
> 
> The addition of these regulators shouldn't affect existing users using
> fixed-on/firmware-controlled regulators.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

Acked-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>

> ---
>  drivers/media/i2c/imx412.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
> index 84279a680873..1795a6180d60 100644
> --- a/drivers/media/i2c/imx412.c
> +++ b/drivers/media/i2c/imx412.c
> @@ -11,6 +11,7 @@
>  #include <linux/i2c.h>
>  #include <linux/module.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>  
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-fwnode.h>
> @@ -101,6 +102,12 @@ struct imx412_mode {
>         struct imx412_reg_list reg_list;
>  };
>  
> +static const char * const imx412_supply_names[] = {
> +       "dovdd",        /* Digital I/O power */
> +       "avdd",         /* Analog power */
> +       "dvdd",         /* Digital core power */
> +};
> +
>  /**
>   * struct imx412 - imx412 sensor device structure
>   * @dev: Pointer to generic device
> @@ -128,6 +135,7 @@ struct imx412 {
>         struct media_pad pad;
>         struct gpio_desc *reset_gpio;
>         struct clk *inclk;
> +       struct regulator_bulk_data supplies[ARRAY_SIZE(imx412_supply_names)];
>         struct v4l2_ctrl_handler ctrl_handler;
>         struct v4l2_ctrl *link_freq_ctrl;
>         struct v4l2_ctrl *pclk_ctrl;
> @@ -946,6 +954,16 @@ static int imx412_parse_hw_config(struct imx412 *imx412)
>                 return -EINVAL;
>         }
>  
> +       /* Get optional DT defined regulators */
> +       for (i = 0; i < ARRAY_SIZE(imx412_supply_names); i++)
> +               imx412->supplies[i].supply = imx412_supply_names[i];
> +
> +       ret = devm_regulator_bulk_get(imx412->dev,
> +                                     ARRAY_SIZE(imx412_supply_names),
> +                                     imx412->supplies);
> +       if (ret)
> +               return ret;
> +
>         ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
>         if (!ep)
>                 return -ENXIO;
> @@ -1011,6 +1029,13 @@ static int imx412_power_on(struct device *dev)
>         struct imx412 *imx412 = to_imx412(sd);
>         int ret;
>  
> +       ret = regulator_bulk_enable(ARRAY_SIZE(imx412_supply_names),
> +                                   imx412->supplies);
> +       if (ret < 0) {
> +               dev_err(dev, "failed to enable regulators\n");
> +               return ret;
> +       }
> +
>         gpiod_set_value_cansleep(imx412->reset_gpio, 0);
>  
>         ret = clk_prepare_enable(imx412->inclk);
> @@ -1025,6 +1050,8 @@ static int imx412_power_on(struct device *dev)
>  
>  error_reset:
>         gpiod_set_value_cansleep(imx412->reset_gpio, 1);
> +       regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
> +                              imx412->supplies);
>  
>         return ret;
>  }
> @@ -1044,6 +1071,9 @@ static int imx412_power_off(struct device *dev)
>  
>         gpiod_set_value_cansleep(imx412->reset_gpio, 1);
>  
> +       regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
> +                              imx412->supplies);
> +
>         return 0;
>  }
>
Sakari Ailus May 6, 2022, 2:26 p.m. UTC | #3
On Fri, Apr 15, 2022 at 12:59:54PM +0100, Bryan O'Donoghue wrote:
> Depending on the platform we may need to enable and disable three separate
> regulators for the imx412.
> 
> - DOVDD
> Digital I/O power
> 
> - AVDD
> Analog power
> 
> - DVDD
> Digital core power
> 
> The addition of these regulators shouldn't affect existing users using
> fixed-on/firmware-controlled regulators.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

Squashed this bit into the patch:

diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
index 1795a6180d60d..a1394d6c14320 100644
--- a/drivers/media/i2c/imx412.c
+++ b/drivers/media/i2c/imx412.c
@@ -116,6 +116,7 @@ static const char * const imx412_supply_names[] = {
  * @pad: Media pad. Only one pad supported
  * @reset_gpio: Sensor reset gpio
  * @inclk: Sensor input clock
+ * @supplies: Regulator supplies
  * @ctrl_handler: V4L2 control handler
  * @link_freq_ctrl: Pointer to link frequency control
  * @pclk_ctrl: Pointer to pixel clock control
diff mbox series

Patch

diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
index 84279a680873..1795a6180d60 100644
--- a/drivers/media/i2c/imx412.c
+++ b/drivers/media/i2c/imx412.c
@@ -11,6 +11,7 @@ 
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-fwnode.h>
@@ -101,6 +102,12 @@  struct imx412_mode {
 	struct imx412_reg_list reg_list;
 };
 
+static const char * const imx412_supply_names[] = {
+	"dovdd",	/* Digital I/O power */
+	"avdd",		/* Analog power */
+	"dvdd",		/* Digital core power */
+};
+
 /**
  * struct imx412 - imx412 sensor device structure
  * @dev: Pointer to generic device
@@ -128,6 +135,7 @@  struct imx412 {
 	struct media_pad pad;
 	struct gpio_desc *reset_gpio;
 	struct clk *inclk;
+	struct regulator_bulk_data supplies[ARRAY_SIZE(imx412_supply_names)];
 	struct v4l2_ctrl_handler ctrl_handler;
 	struct v4l2_ctrl *link_freq_ctrl;
 	struct v4l2_ctrl *pclk_ctrl;
@@ -946,6 +954,16 @@  static int imx412_parse_hw_config(struct imx412 *imx412)
 		return -EINVAL;
 	}
 
+	/* Get optional DT defined regulators */
+	for (i = 0; i < ARRAY_SIZE(imx412_supply_names); i++)
+		imx412->supplies[i].supply = imx412_supply_names[i];
+
+	ret = devm_regulator_bulk_get(imx412->dev,
+				      ARRAY_SIZE(imx412_supply_names),
+				      imx412->supplies);
+	if (ret)
+		return ret;
+
 	ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
 	if (!ep)
 		return -ENXIO;
@@ -1011,6 +1029,13 @@  static int imx412_power_on(struct device *dev)
 	struct imx412 *imx412 = to_imx412(sd);
 	int ret;
 
+	ret = regulator_bulk_enable(ARRAY_SIZE(imx412_supply_names),
+				    imx412->supplies);
+	if (ret < 0) {
+		dev_err(dev, "failed to enable regulators\n");
+		return ret;
+	}
+
 	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
 
 	ret = clk_prepare_enable(imx412->inclk);
@@ -1025,6 +1050,8 @@  static int imx412_power_on(struct device *dev)
 
 error_reset:
 	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
+	regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
+			       imx412->supplies);
 
 	return ret;
 }
@@ -1044,6 +1071,9 @@  static int imx412_power_off(struct device *dev)
 
 	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
 
+	regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
+			       imx412->supplies);
+
 	return 0;
 }