From: Chen-Yu Tsai <wenst@chromium.org>
To: Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Wolfram Sang <wsa@kernel.org>, Benson Leung <bleung@chromium.org>,
Tzung-Bi Shih <tzungbi@kernel.org>,
Mark Brown <broonie@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>
Cc: Chen-Yu Tsai <wenst@chromium.org>,
chrome-platform@lists.linux.dev, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
Douglas Anderson <dianders@chromium.org>,
Johan Hovold <johan@kernel.org>, Jiri Kosina <jikos@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-i2c@vger.kernel.org
Subject: [PATCH v5 04/10] regulator: Do pure DT regulator lookup in of_regulator_bulk_get_all()
Date: Thu, 22 Aug 2024 17:19:57 +0800 [thread overview]
Message-ID: <20240822092006.3134096-5-wenst@chromium.org> (raw)
In-Reply-To: <20240822092006.3134096-1-wenst@chromium.org>
The to-be-introduced I2C component prober needs to enable regulator
supplies (and toggle GPIO pins) for the various components it intends
to probe. To support this, a new "pure DT lookup" method for getting
regulator supplies is needed, since the device normally requesting
the supply won't get created until after the component is probed to
be available.
Convert the existing of_regulator_bulk_get_all() for this purpose.
This function has no in-tree users, as the original patch [1] that
used it was never landed. This patch changes the function ABI, but
it is straightforward to convert users.
The underlying code that supports the existing regulator_get*()
functions has been reworked in previous patches to support this
specific case. An internal OF-specific version of regulator_get(),
of_regulator_get_optional(), is added for this.
[1] https://lore.kernel.org/all/20231220203537.83479-2-jernej.skrabec@gmail.com/
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v4:
- Was "regulator: Add regulator_of_get_optional() for pure DT" in v4
- Restore platform-agnostic regulator consumer code to original state
- Move OF-specific regulator code to of_regulator.c (separate patch)
- Split _regulator_get() into three parts for reuse (separate patch)
- Add OF-specific _of_regulator_get() function
- Rename regulator_of_get_optional() to of_regulator_get_optional() for
consistency
- Make of_regulator_get_optional() static, as it is only used internally
- Convert of_regulator_bulk_get_all()
Changes since v3:
- New patch
---
drivers/regulator/core.c | 2 +-
drivers/regulator/internal.h | 2 ++
drivers/regulator/of_regulator.c | 54 +++++++++++++++++++++++++++-----
3 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 4d1c640cc030..d70302e30731 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1950,7 +1950,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
/* first do a dt based lookup */
if (dev && dev->of_node) {
- r = of_regulator_dev_lookup(dev, supply);
+ r = of_regulator_dev_lookup(dev, dev->of_node, supply);
if (!IS_ERR(r))
return r;
if (PTR_ERR(r) == -EPROBE_DEFER)
diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
index 3718459fb0c5..44680ce3587b 100644
--- a/drivers/regulator/internal.h
+++ b/drivers/regulator/internal.h
@@ -67,6 +67,7 @@ static inline struct regulator_dev *dev_to_rdev(struct device *dev)
#ifdef CONFIG_OF
struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
+ struct device_node *np,
const char *supply);
struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
const struct regulator_desc *desc,
@@ -82,6 +83,7 @@ bool of_check_coupling_data(struct regulator_dev *rdev);
#else
static inline struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
+ struct device_node *np,
const char *supply)
{
return -ENODEV;
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index d924f5c1de59..67a5882a917e 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -587,22 +587,24 @@ static struct device_node *of_get_child_regulator(struct device_node *parent,
/**
* of_get_regulator - get a regulator device node based on supply name
- * @dev: Device pointer for the consumer (of regulator) device
+ * @dev: Device pointer for dev_printk messages
+ * @node: Device node pointer for supply property lookup
* @supply: regulator supply name
*
* Extract the regulator device node corresponding to the supply name.
* returns the device node corresponding to the regulator if found, else
* returns NULL.
*/
-static struct device_node *of_get_regulator(struct device *dev, const char *supply)
+static struct device_node *of_get_regulator(struct device *dev, struct device_node *node,
+ const char *supply)
{
struct device_node *regnode = NULL;
char prop_name[64]; /* 64 is max size of property name */
- dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);
+ dev_dbg(dev, "Looking up %s-supply from device node %pOF\n", supply, node);
snprintf(prop_name, 64, "%s-supply", supply);
- regnode = of_parse_phandle(dev->of_node, prop_name, 0);
+ regnode = of_parse_phandle(node, prop_name, 0);
if (!regnode) {
regnode = of_get_child_regulator(dev->of_node, prop_name);
@@ -626,7 +628,8 @@ static struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
}
/** of_regulator_dev_lookup - lookup a regulator device with device tree only
- * @dev: Device pointer for regulator supply lookup.
+ * @dev: Device pointer for dev_printk messages.
+ * @node: Device node pointer for regulator supply lookup.
* @supply: Supply name or regulator ID.
*
* If successful, returns a struct regulator_dev that corresponds to the name
@@ -636,13 +639,13 @@ static struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
* -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed
* in the future.
*/
-struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
+struct regulator_dev *of_regulator_dev_lookup(struct device *dev, struct device_node *np,
const char *supply)
{
struct regulator_dev *r;
struct device_node *node;
- node = of_get_regulator(dev, supply);
+ node = of_get_regulator(dev, np, supply);
if (node) {
r = of_find_regulator_by_node(node);
of_node_put(node);
@@ -659,6 +662,41 @@ struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
return ERR_PTR(-ENODEV);
}
+static struct regulator *_of_regulator_get(struct device *dev, struct device_node *node,
+ const char *id, enum regulator_get_type get_type)
+{
+ struct regulator_dev *r;
+ int ret;
+
+ ret = _regulator_get_common_check(dev, id, get_type);
+ if (ret)
+ return ERR_PTR(ret);
+
+ r = of_regulator_dev_lookup(dev, node, id);
+ return _regulator_get_common(r, dev, id, get_type);
+}
+
+/**
+ * of_regulator_get_optional - get optional regulator via device tree lookup
+ * @dev: device used for dev_printk messages
+ * @node: device node for regulator "consumer"
+ * @id: Supply name
+ *
+ * Returns a struct regulator corresponding to the regulator producer,
+ * or IS_ERR() condition containing errno.
+ *
+ * This is intended for use by consumers that want to get a regulator
+ * supply directly from a device node, and can and want to deal with
+ * absence of such supplies. This will _not_ consider supply aliases.
+ * See regulator_dev_lookup().
+ */
+static struct regulator *of_regulator_get_optional(struct device *dev,
+ struct device_node *node,
+ const char *id)
+{
+ return _of_regulator_get(NULL, node, id, OPTIONAL_GET);
+}
+
/*
* Returns number of regulators coupled with rdev.
*/
@@ -875,7 +913,7 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,
} else {
memcpy(name, prop->name, i);
name[i] = '\0';
- tmp = regulator_get(dev, name);
+ tmp = of_regulator_get_optional(dev, np, name);
if (IS_ERR(tmp)) {
ret = PTR_ERR(tmp);
goto error;
--
2.46.0.184.g6999bdac58-goog
next prev parent reply other threads:[~2024-08-22 9:20 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 9:19 [PATCH v5 00/10] platform/chrome: Introduce DT hardware prober Chen-Yu Tsai
2024-08-22 9:19 ` [PATCH v5 01/10] of: dynamic: Add of_changeset_update_prop_string Chen-Yu Tsai
2024-08-22 12:32 ` Rob Herring
2024-08-22 9:19 ` [PATCH v5 02/10] regulator: Move OF-specific regulator lookup code to of_regulator.c Chen-Yu Tsai
2024-08-22 13:47 ` Andy Shevchenko
2024-08-23 6:49 ` Chen-Yu Tsai
2024-08-23 13:43 ` Andy Shevchenko
2024-08-26 6:46 ` Chen-Yu Tsai
2024-08-26 12:06 ` kernel test robot
2024-08-26 12:06 ` kernel test robot
2024-08-26 13:19 ` kernel test robot
2024-08-22 9:19 ` [PATCH v5 03/10] regulator: Split up _regulator_get() Chen-Yu Tsai
2024-08-22 13:49 ` Andy Shevchenko
2024-08-23 6:54 ` Chen-Yu Tsai
2024-08-22 9:19 ` Chen-Yu Tsai [this message]
2024-08-22 13:53 ` [PATCH v5 04/10] regulator: Do pure DT regulator lookup in of_regulator_bulk_get_all() Andy Shevchenko
2024-08-23 7:05 ` Chen-Yu Tsai
2024-08-22 9:19 ` [PATCH v5 05/10] gpiolib: Add gpio_property_name_length() Chen-Yu Tsai
2024-08-22 14:36 ` Andy Shevchenko
2024-08-23 7:50 ` Chen-Yu Tsai
2024-08-23 13:46 ` Andy Shevchenko
2024-08-22 9:19 ` [PATCH v5 06/10] i2c: Introduce OF component probe function Chen-Yu Tsai
2024-08-22 14:01 ` Andy Shevchenko
2024-08-23 8:40 ` Chen-Yu Tsai
2024-08-23 13:52 ` Andy Shevchenko
2024-08-22 9:20 ` [PATCH v5 07/10] i2c: of-prober: Add regulator support Chen-Yu Tsai
2024-08-22 14:09 ` Andy Shevchenko
2024-08-23 9:35 ` Chen-Yu Tsai
2024-08-23 13:56 ` Andy Shevchenko
2024-08-22 9:20 ` [PATCH v5 08/10] i2c: of-prober: Add GPIO support Chen-Yu Tsai
2024-08-22 14:20 ` Andy Shevchenko
2024-08-23 10:32 ` Chen-Yu Tsai
2024-08-23 14:00 ` Andy Shevchenko
2024-08-26 7:21 ` Chen-Yu Tsai
2024-08-22 9:20 ` [PATCH v5 09/10] platform/chrome: Introduce device tree hardware prober Chen-Yu Tsai
2024-08-22 9:20 ` [PATCH v5 10/10] arm64: dts: mediatek: mt8173-elm-hana: Mark touchscreens and trackpads as fail Chen-Yu Tsai
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=20240822092006.3134096-5-wenst@chromium.org \
--to=wenst@chromium.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bleung@chromium.org \
--cc=broonie@kernel.org \
--cc=chrome-platform@lists.linux.dev \
--cc=devicetree@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=jikos@kernel.org \
--cc=johan@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=tzungbi@kernel.org \
--cc=wsa@kernel.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