All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] media: i2c: imx412: Add regulator control to imx412
@ 2022-04-14 14:11 Bryan O'Donoghue
  2022-04-14 14:11 ` [PATCH v4 1/3] media: dt-bindings: imx412: Add regulator descriptions Bryan O'Donoghue
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bryan O'Donoghue @ 2022-04-14 14:11 UTC (permalink / raw)
  To: sakari.ailus, paul.j.murphy, daniele.alessandrelli, mchehab,
	linux-media, devicetree
  Cc: robert.foss, hfink, jgrahsl, dmitry.baryshkov,
	vladimir.zapolskiy, bryan.odonoghue

V4:
- Further asks on placing arguments on the same line - Saraki
- Moves regulator_bulk_disable() to common error path - Saraki
- Fixes power_off ordering so that power_off and power_on have the same
  flow - Bryan

V3:
- int num_supplies -> unsigned int num_supplied - Saraki
- Move imx412->num_supplies to same line as devm_regulator_bulk_get - Saraki
- Return ret on regulator_bulk_enable() - Saraki
- Remember to regulator_bulk_disable() on !clk_prepare_enable() - Saraki

V2:
- Drops redundant verbage "Definition of the" from each of the newly defined
  regulators - Krzysztof Kozlowski
- Adds Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
- "description: thing described" to the same line in new additions
  following the established way of doing it in this file - bod

V1:
The imx412 has three regulators which depending on platform may need to be
individually enabled.

- dovdd
- avdd
- dvdd

Existing code for an Intel platform doesn't appear to need to enable these
rails directly. On my reference hardware, a Qualcomm Thundercomm RB5 some
of these rails do need to be enabled individually.

Add in the above named rails as optional in the YAML in the first patch
along with code to switch them on in the second patch.

Existing imx412 users should get dummy regulators populated which the
regulator_bulk_enable()/regulator_bulk_disable() code can safely ignore.


Bryan O'Donoghue (3):
  media: dt-bindings: imx412: Add regulator descriptions
  media: i2c: imx412: Add bulk regulator support
  media: i2c: imx412: Fix power_off ordering

 .../bindings/media/i2c/sony,imx412.yaml       |  9 ++++++
 drivers/media/i2c/imx412.c                    | 30 ++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

-- 
2.35.1


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

* [PATCH v4 1/3] media: dt-bindings: imx412: Add regulator descriptions
  2022-04-14 14:11 [PATCH v4 0/3] media: i2c: imx412: Add regulator control to imx412 Bryan O'Donoghue
@ 2022-04-14 14:11 ` Bryan O'Donoghue
  2022-04-14 14:11 ` [PATCH v4 2/3] media: i2c: imx412: Add bulk regulator support Bryan O'Donoghue
  2022-04-14 14:11 ` [PATCH v4 3/3] media: i2c: imx412: Fix power_off ordering Bryan O'Donoghue
  2 siblings, 0 replies; 5+ messages in thread
From: Bryan O'Donoghue @ 2022-04-14 14:11 UTC (permalink / raw)
  To: sakari.ailus, paul.j.murphy, daniele.alessandrelli, mchehab,
	linux-media, devicetree
  Cc: robert.foss, hfink, jgrahsl, dmitry.baryshkov,
	vladimir.zapolskiy, bryan.odonoghue, Rob Herring,
	Krzysztof Kozlowski, Krzysztof Kozlowski

The imx412 like many I2C camera sensors has three voltage rails which
depending on platform may be necessary to switch power onto directly.

Add in as optional rails so as not to break anything for existing users.

Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 .../devicetree/bindings/media/i2c/sony,imx412.yaml       | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx412.yaml b/Documentation/devicetree/bindings/media/i2c/sony,imx412.yaml
index afcf70947f7e..26d1807d0bb6 100644
--- a/Documentation/devicetree/bindings/media/i2c/sony,imx412.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/sony,imx412.yaml
@@ -32,6 +32,15 @@ properties:
     description: Clock frequency 6MHz, 12MHz, 18MHz, 24MHz or 27MHz
     maxItems: 1
 
+  dovdd-supply:
+    description: Interface power supply.
+
+  avdd-supply:
+    description: Analog power supply.
+
+  dvdd-supply:
+    description: Digital power supply.
+
   reset-gpios:
     description: Reference to the GPIO connected to the XCLR pin, if any.
     maxItems: 1
-- 
2.35.1


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

* [PATCH v4 2/3] media: i2c: imx412: Add bulk regulator support
  2022-04-14 14:11 [PATCH v4 0/3] media: i2c: imx412: Add regulator control to imx412 Bryan O'Donoghue
  2022-04-14 14:11 ` [PATCH v4 1/3] media: dt-bindings: imx412: Add regulator descriptions Bryan O'Donoghue
@ 2022-04-14 14:11 ` Bryan O'Donoghue
  2022-04-14 19:53   ` Jacopo Mondi
  2022-04-14 14:11 ` [PATCH v4 3/3] media: i2c: imx412: Fix power_off ordering Bryan O'Donoghue
  2 siblings, 1 reply; 5+ messages in thread
From: Bryan O'Donoghue @ 2022-04-14 14:11 UTC (permalink / raw)
  To: sakari.ailus, paul.j.murphy, daniele.alessandrelli, mchehab,
	linux-media, devicetree
  Cc: robert.foss, hfink, jgrahsl, dmitry.baryshkov,
	vladimir.zapolskiy, bryan.odonoghue

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 | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
index be3f6ea55559..6d0746d6c634 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,8 @@ struct imx412 {
 	struct media_pad pad;
 	struct gpio_desc *reset_gpio;
 	struct clk *inclk;
+	struct regulator_bulk_data supplies[ARRAY_SIZE(imx412_supply_names)];
+	unsigned int num_supplies;
 	struct v4l2_ctrl_handler ctrl_handler;
 	struct v4l2_ctrl *link_freq_ctrl;
 	struct v4l2_ctrl *pclk_ctrl;
@@ -946,6 +955,16 @@ static int imx412_parse_hw_config(struct imx412 *imx412)
 		return -EINVAL;
 	}
 
+	/* Get optional DT defined regulators */
+	imx412->num_supplies = ARRAY_SIZE(imx412_supply_names);
+	for (i = 0; i < imx412->num_supplies; i++)
+		imx412->supplies[i].supply = imx412_supply_names[i];
+
+	ret = devm_regulator_bulk_get(imx412->dev, imx412->num_supplies,
+				      imx412->supplies);
+	if (ret)
+		return ret;
+
 	ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
 	if (!ep)
 		return -ENXIO;
@@ -1011,6 +1030,12 @@ static int imx412_power_on(struct device *dev)
 	struct imx412 *imx412 = to_imx412(sd);
 	int ret;
 
+	ret = regulator_bulk_enable(imx412->num_supplies, imx412->supplies);
+	if (ret < 0) {
+		dev_err(dev, "failed to enable regulators\n");
+		return ret;
+	}
+
 	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
 
 	ret = clk_prepare_enable(imx412->inclk);
@@ -1025,6 +1050,7 @@ static int imx412_power_on(struct device *dev)
 
 error_reset:
 	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
+	regulator_bulk_disable(imx412->num_supplies, imx412->supplies);
 
 	return ret;
 }
@@ -1044,6 +1070,8 @@ static int imx412_power_off(struct device *dev)
 
 	clk_disable_unprepare(imx412->inclk);
 
+	regulator_bulk_disable(imx412->num_supplies, imx412->supplies);
+
 	return 0;
 }
 
-- 
2.35.1


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

* [PATCH v4 3/3] media: i2c: imx412: Fix power_off ordering
  2022-04-14 14:11 [PATCH v4 0/3] media: i2c: imx412: Add regulator control to imx412 Bryan O'Donoghue
  2022-04-14 14:11 ` [PATCH v4 1/3] media: dt-bindings: imx412: Add regulator descriptions Bryan O'Donoghue
  2022-04-14 14:11 ` [PATCH v4 2/3] media: i2c: imx412: Add bulk regulator support Bryan O'Donoghue
@ 2022-04-14 14:11 ` Bryan O'Donoghue
  2 siblings, 0 replies; 5+ messages in thread
From: Bryan O'Donoghue @ 2022-04-14 14:11 UTC (permalink / raw)
  To: sakari.ailus, paul.j.murphy, daniele.alessandrelli, mchehab,
	linux-media, devicetree
  Cc: robert.foss, hfink, jgrahsl, dmitry.baryshkov,
	vladimir.zapolskiy, bryan.odonoghue

The enable path does
- regulator
- gpio
- clock

The disable path does
- gpio
- clock
- regulator

Fix the order on the power-off path so that power-off and power-on have the
same ordering for regulator, clock and gpio.

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

diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
index 6d0746d6c634..a9cdf4694d58 100644
--- a/drivers/media/i2c/imx412.c
+++ b/drivers/media/i2c/imx412.c
@@ -1066,10 +1066,10 @@ static int imx412_power_off(struct device *dev)
 	struct v4l2_subdev *sd = dev_get_drvdata(dev);
 	struct imx412 *imx412 = to_imx412(sd);
 
-	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
-
 	clk_disable_unprepare(imx412->inclk);
 
+	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
+
 	regulator_bulk_disable(imx412->num_supplies, imx412->supplies);
 
 	return 0;
-- 
2.35.1


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

* Re: [PATCH v4 2/3] media: i2c: imx412: Add bulk regulator support
  2022-04-14 14:11 ` [PATCH v4 2/3] media: i2c: imx412: Add bulk regulator support Bryan O'Donoghue
@ 2022-04-14 19:53   ` Jacopo Mondi
  0 siblings, 0 replies; 5+ messages in thread
From: Jacopo Mondi @ 2022-04-14 19:53 UTC (permalink / raw)
  To: Bryan O'Donoghue
  Cc: sakari.ailus, paul.j.murphy, daniele.alessandrelli, mchehab,
	linux-media, devicetree, robert.foss, hfink, jgrahsl,
	dmitry.baryshkov, vladimir.zapolskiy

Hello Bryan,

On Thu, Apr 14, 2022 at 03:11:07PM +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>
> ---
>  drivers/media/i2c/imx412.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
> index be3f6ea55559..6d0746d6c634 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,8 @@ struct imx412 {
>  	struct media_pad pad;
>  	struct gpio_desc *reset_gpio;
y>  	struct clk *inclk;
> +	struct regulator_bulk_data supplies[ARRAY_SIZE(imx412_supply_names)];
> +	unsigned int num_supplies;
>  	struct v4l2_ctrl_handler ctrl_handler;
>  	struct v4l2_ctrl *link_freq_ctrl;
>  	struct v4l2_ctrl *pclk_ctrl;
> @@ -946,6 +955,16 @@ static int imx412_parse_hw_config(struct imx412 *imx412)
>  		return -EINVAL;
>  	}
>
> +	/* Get optional DT defined regulators */
> +	imx412->num_supplies = ARRAY_SIZE(imx412_supply_names);

Just one drive-by comment: is num_supplies needed ?

It seems to be initialized here and never changed. I think you can use
ARRAY_SIZE(imx412_supply_names). Or since the macro is also used to
initialize the 'supplies' array, define a IMX412_NUM_SUPPLIES or
similar.

Thanks
   j

> +	for (i = 0; i < imx412->num_supplies; i++)
> +		imx412->supplies[i].supply = imx412_supply_names[i];
> +
> +	ret = devm_regulator_bulk_get(imx412->dev, imx412->num_supplies,
> +				      imx412->supplies);
> +	if (ret)
> +		return ret;
> +
>  	ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
>  	if (!ep)
>  		return -ENXIO;
> @@ -1011,6 +1030,12 @@ static int imx412_power_on(struct device *dev)
>  	struct imx412 *imx412 = to_imx412(sd);
>  	int ret;
>
> +	ret = regulator_bulk_enable(imx412->num_supplies, imx412->supplies);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to enable regulators\n");
> +		return ret;
> +	}
> +
>  	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
>
>  	ret = clk_prepare_enable(imx412->inclk);
> @@ -1025,6 +1050,7 @@ static int imx412_power_on(struct device *dev)
>
>  error_reset:
>  	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
> +	regulator_bulk_disable(imx412->num_supplies, imx412->supplies);
>
>  	return ret;
>  }
> @@ -1044,6 +1070,8 @@ static int imx412_power_off(struct device *dev)
>
>  	clk_disable_unprepare(imx412->inclk);
>
> +	regulator_bulk_disable(imx412->num_supplies, imx412->supplies);
> +
>  	return 0;
>  }
>
> --
> 2.35.1
>

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

end of thread, other threads:[~2022-04-14 19:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14 14:11 [PATCH v4 0/3] media: i2c: imx412: Add regulator control to imx412 Bryan O'Donoghue
2022-04-14 14:11 ` [PATCH v4 1/3] media: dt-bindings: imx412: Add regulator descriptions Bryan O'Donoghue
2022-04-14 14:11 ` [PATCH v4 2/3] media: i2c: imx412: Add bulk regulator support Bryan O'Donoghue
2022-04-14 19:53   ` Jacopo Mondi
2022-04-14 14:11 ` [PATCH v4 3/3] media: i2c: imx412: Fix power_off ordering Bryan O'Donoghue

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.