From: Saravana Kannan <saravanak@google.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Bjorn Andersson <andersson@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Tony Lindgren <tony@atomide.com>,
Doug Anderson <dianders@chromium.org>,
Guenter Roeck <linux@roeck-us.net>,
Luca Weiss <luca.weiss@fairphone.com>,
kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: [RFC v1 4/4] regulator: core: Move regulator supply resolving to the probe function
Date: Sat, 18 Feb 2023 00:32:51 -0800 [thread overview]
Message-ID: <20230218083252.2044423-5-saravanak@google.com> (raw)
In-Reply-To: <20230218083252.2044423-1-saravanak@google.com>
We can simplify the regulator's supply resolving code if we resolve the
supply in the regulator's probe function. This allows us to:
- Consolidate the supply resolution code to one place.
- Avoid the need for recursion by allow driver core to take care of
handling dependencies.
- Avoid races and simplify locking by reusing the guarantees provided by
driver core.
- Avoid last minute/lazy resolving during regulator_get().
- Simplify error handling because we can assume the supply has been
resolved once a regulator is probed.
- Allow driver core to use device links/fw_devlink, where available, to
resolve the regulator supplies in the optimal order.
Signed-off-by: Saravana Kannan <saravanak@google.com>
---
drivers/regulator/core.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d5f9fdd79c14..f3bf74d1a81d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1952,7 +1952,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
if (node) {
r = of_find_regulator_by_node(node);
of_node_put(node);
- if (r)
+ if (r && r->dev.links.status == DL_DEV_DRIVER_BOUND)
return r;
/*
@@ -1982,11 +1982,11 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
}
mutex_unlock(®ulator_list_mutex);
- if (r)
+ if (r && r->dev.links.status == DL_DEV_DRIVER_BOUND)
return r;
r = regulator_lookup_by_name(supply);
- if (r)
+ if (r && r->dev.links.status == DL_DEV_DRIVER_BOUND)
return r;
return ERR_PTR(-ENODEV);
@@ -2050,13 +2050,6 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
}
}
- /* Recursively resolve the supply of the supply */
- ret = regulator_resolve_supply(r);
- if (ret < 0) {
- put_device(&r->dev);
- goto out;
- }
-
/*
* Recheck rdev->supply with rdev->mutex lock held to avoid a race
* between rdev->supply null check and setting rdev->supply in
@@ -2178,13 +2171,6 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
return regulator;
}
- ret = regulator_resolve_supply(rdev);
- if (ret < 0) {
- regulator = ERR_PTR(ret);
- put_device(&rdev->dev);
- return regulator;
- }
-
if (!try_module_get(rdev->owner)) {
regulator = ERR_PTR(-EPROBE_DEFER);
put_device(&rdev->dev);
@@ -5649,9 +5635,6 @@ regulator_register(struct device *dev,
regulator_resolve_coupling(rdev);
mutex_unlock(®ulator_list_mutex);
- /* try to resolve regulators supply since a new one was registered */
- bus_for_each_dev(®ulator_bus, NULL, NULL,
- regulator_register_resolve_supply);
kfree(config);
return rdev;
@@ -5782,7 +5765,9 @@ static const struct dev_pm_ops __maybe_unused regulator_pm_ops = {
static int regulator_drv_probe(struct device *dev)
{
- return 0;
+ struct regulator_dev *rdev = dev_to_rdev(dev);
+
+ return regulator_resolve_supply(rdev);
}
static struct device_driver regulator_drv = {
--
2.39.2.637.g21b0678d19-goog
next prev parent reply other threads:[~2023-02-18 8:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230218083300eucas1p28c7c584877b8914a3b88904690be82f6@eucas1p2.samsung.com>
2023-02-18 8:32 ` [RFC v1 0/4] Simplify regulator supply resolution code by offloading to driver core Saravana Kannan
2023-02-18 8:32 ` [RFC v1 1/4] regulator: core: Add regulator devices to bus instead of class Saravana Kannan
2023-02-18 8:32 ` [RFC v1 2/4] regulator: core: Add sysfs class backward compatibility Saravana Kannan
2023-02-22 17:47 ` Mark Brown
2023-02-18 8:32 ` [RFC v1 3/4] regulator: core: Probe regulator devices Saravana Kannan
2023-02-22 17:50 ` Mark Brown
2023-02-18 8:32 ` Saravana Kannan [this message]
2023-02-22 22:51 ` [RFC v1 4/4] regulator: core: Move regulator supply resolving to the probe function Mark Brown
2023-02-18 8:36 ` [RFC v1 0/4] Simplify regulator supply resolution code by offloading to driver core Saravana Kannan
2023-02-18 8:54 ` Greg Kroah-Hartman
2023-02-20 9:01 ` Marek Szyprowski
2023-02-21 22:36 ` Saravana Kannan
2023-02-21 22:52 ` Mark Brown
2023-02-22 3:13 ` Saravana Kannan
2023-02-22 14:54 ` Mark Brown
2023-02-22 7:15 ` Marek Szyprowski
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=20230218083252.2044423-5-saravanak@google.com \
--to=saravanak@google.com \
--cc=andersson@kernel.org \
--cc=broonie@kernel.org \
--cc=dianders@chromium.org \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@android.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=luca.weiss@fairphone.com \
--cc=m.szyprowski@samsung.com \
--cc=sudeep.holla@arm.com \
--cc=tony@atomide.com \
/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