devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: sakari.ailus@iki.fi, paul.j.murphy@intel.com,
	daniele.alessandrelli@intel.com, mchehab@kernel.org,
	linux-media@vger.kernel.org, devicetree@vger.kernel.org
Cc: robert.foss@linaro.org, hfink@snap.com, jgrahsl@snap.com,
	dmitry.baryshkov@linaro.org, vladimir.zapolskiy@linaro.org,
	bryan.odonoghue@linaro.org
Subject: [PATCH v3 2/2] media: i2c: imx412: Add bulk regulator support
Date: Thu, 14 Apr 2022 13:45:05 +0100	[thread overview]
Message-ID: <20220414124505.1329295-3-bryan.odonoghue@linaro.org> (raw)
In-Reply-To: <20220414124505.1329295-1-bryan.odonoghue@linaro.org>

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

diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
index be3f6ea55559..27170e641b53 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,10 +1030,19 @@ 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);
 	if (ret) {
+		regulator_bulk_disable(imx412->num_supplies,
+				       imx412->supplies);
 		dev_err(imx412->dev, "fail to enable inclk");
 		goto error_reset;
 	}
@@ -1044,6 +1072,9 @@ 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


  parent reply	other threads:[~2022-04-14 12:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14 12:45 [PATCH v3 0/2] media: i2c: imx412: Add regulator control to imx412 Bryan O'Donoghue
2022-04-14 12:45 ` [PATCH v3 1/2] media: dt-bindings: imx412: Add regulator descriptions Bryan O'Donoghue
2022-04-14 12:45 ` Bryan O'Donoghue [this message]
2022-04-14 13:00   ` [PATCH v3 2/2] media: i2c: imx412: Add bulk regulator support Sakari Ailus
2022-04-14 13:44     ` Bryan O'Donoghue
2022-04-14 13:56       ` Sakari Ailus
2022-04-14 14:04         ` Bryan O'Donoghue
2022-04-14 14:16           ` Sakari Ailus
2022-04-14 14:50             ` Bryan O'Donoghue
2022-04-14 21:58               ` Sakari Ailus
2022-04-14 22:32                 ` Bryan O'Donoghue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220414124505.1329295-3-bryan.odonoghue@linaro.org \
    --to=bryan.odonoghue@linaro.org \
    --cc=daniele.alessandrelli@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=hfink@snap.com \
    --cc=jgrahsl@snap.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=paul.j.murphy@intel.com \
    --cc=robert.foss@linaro.org \
    --cc=sakari.ailus@iki.fi \
    --cc=vladimir.zapolskiy@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).