From: Maciej Purski <m.purski@samsung.com>
To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>,
Fabio Estevam <festevam@gmail.com>,
Tony Lindgren <tony@atomide.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Doug Anderson <dianders@chromium.org>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
Maciej Purski <m.purski@samsung.com>
Subject: [PATCH v7 4/6] regulator: core: Resolve coupled regulators
Date: Mon, 23 Apr 2018 16:33:40 +0200 [thread overview]
Message-ID: <1524494022-22260-5-git-send-email-m.purski@samsung.com> (raw)
In-Reply-To: <1524494022-22260-1-git-send-email-m.purski@samsung.com>
On Odroid XU3/4 and other Exynos5422 based boards there is a case, that
different devices on the board are supplied by different regulators
with non-fixed voltages. If one of these devices temporarily requires
higher voltage, there might occur a situation that the spread between
two devices' voltages is so high, that there is a risk of changing
'high' and 'low' states on the interconnection between devices powered
by those regulators.
Fill coupling descriptor with data obtained from DTS using previously
defined of_functions. Fail to register a regulator, if some data
inconsistency occurs. If some coupled regulators are not yet registered,
don't fail to register, but try to resolve them in late init call.
Signed-off-by: Maciej Purski <m.purski@samsung.com>
---
drivers/regulator/core.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index acca5de..82b002e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -4117,6 +4117,96 @@ static int regulator_register_resolve_supply(struct device *dev, void *data)
return 0;
}
+static int regulator_fill_coupling_array(struct regulator_dev *rdev)
+{
+ struct coupling_desc *c_desc = &rdev->coupling_desc;
+ int n_coupled = c_desc->n_coupled;
+ struct regulator_dev *c_rdev;
+ int i;
+
+ for (i = 1; i < n_coupled; i++) {
+ /* already resolved */
+ if (c_desc->coupled_rdevs[i])
+ continue;
+
+ c_rdev = of_parse_coupled_regulator(rdev, i - 1);
+
+ if (c_rdev) {
+ c_desc->coupled_rdevs[i] = c_rdev;
+ c_desc->n_resolved++;
+ }
+ }
+
+ if (rdev->coupling_desc.n_resolved < n_coupled)
+ return -1;
+ else
+ return 0;
+}
+
+static int regulator_register_fill_coupling_array(struct device *dev,
+ void *data)
+{
+ struct regulator_dev *rdev = dev_to_rdev(dev);
+
+ if (!IS_ENABLED(CONFIG_OF))
+ return 0;
+
+ if (regulator_fill_coupling_array(rdev))
+ rdev_dbg(rdev, "unable to resolve coupling\n");
+
+ return 0;
+}
+
+static int regulator_resolve_coupling(struct regulator_dev *rdev)
+{
+ int n_phandles;
+
+ if (!IS_ENABLED(CONFIG_OF))
+ n_phandles = 0;
+ else
+ n_phandles = of_get_n_coupled(rdev);
+
+ if (n_phandles + 1 > MAX_COUPLED) {
+ rdev_err(rdev, "too many regulators coupled\n");
+ return -EPERM;
+ }
+
+ /*
+ * Every regulator should always have coupling descriptor filled with
+ * at least pointer to itself.
+ */
+ rdev->coupling_desc.coupled_rdevs[0] = rdev;
+ rdev->coupling_desc.n_coupled = n_phandles + 1;
+ rdev->coupling_desc.n_resolved++;
+
+ /* regulator isn't coupled */
+ if (n_phandles == 0)
+ return 0;
+
+ /* regulator, which can't change its voltage, can't be coupled */
+ if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
+ rdev_err(rdev, "voltage operation not allowed\n");
+ return -EPERM;
+ }
+
+ if (rdev->constraints->max_spread <= 0) {
+ rdev_err(rdev, "wrong max_spread value\n");
+ return -EPERM;
+ }
+
+ if (!of_check_coupling_data(rdev))
+ return -EPERM;
+
+ /*
+ * After everything has been checked, try to fill rdevs array
+ * with pointers to regulators parsed from device tree. If some
+ * regulators are not registered yet, retry in late init call
+ */
+ regulator_fill_coupling_array(rdev);
+
+ return 0;
+}
+
/**
* regulator_register - register regulator
* @regulator_desc: regulator to register
@@ -4250,6 +4340,13 @@ regulator_register(const struct regulator_desc *regulator_desc,
if (ret < 0)
goto wash;
+ mutex_lock(®ulator_list_mutex);
+ ret = regulator_resolve_coupling(rdev);
+ mutex_unlock(®ulator_list_mutex);
+
+ if (ret != 0)
+ goto wash;
+
/* add consumers devices */
if (init_data) {
mutex_lock(®ulator_list_mutex);
@@ -4744,6 +4841,9 @@ static int __init regulator_init_complete(void)
class_for_each_device(®ulator_class, NULL, NULL,
regulator_late_cleanup);
+ class_for_each_device(®ulator_class, NULL, NULL,
+ regulator_register_fill_coupling_array);
+
return 0;
}
late_initcall_sync(regulator_init_complete);
--
2.7.4
next prev parent reply other threads:[~2018-04-23 14:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20180423143353eucas1p1d417b5995e380f6a7b168a98a76ecf40@eucas1p1.samsung.com>
2018-04-23 14:33 ` [PATCH v7 0/6] Add coupled regulators mechanism Maciej Purski
[not found] ` <CGME20180423143400eucas1p162d48bddb8ba5ebc6e294ade791cb27c@eucas1p1.samsung.com>
2018-04-23 14:33 ` [PATCH v7 1/6] regulator: core: Make locks re-entrant Maciej Purski
[not found] ` <CGME20180423143400eucas1p1bde12f792993806e9e88277177b59dfb@eucas1p1.samsung.com>
2018-04-23 14:33 ` [PATCH v7 2/6] regulator: bindings: Add properties for coupled regulators Maciej Purski
[not found] ` <CGME20180423143401eucas1p1c80bce784a76eca5c86c2e73c53b34df@eucas1p1.samsung.com>
2018-04-23 14:33 ` [PATCH v7 3/6] regulator: core: Parse coupled regulators properties Maciej Purski
[not found] ` <CGME20180423143401eucas1p1cfe9b2c807cf88b3f3b68b7b2f580e83@eucas1p1.samsung.com>
2018-04-23 14:33 ` Maciej Purski [this message]
2018-05-17 16:41 ` Applied "regulator: core: Resolve coupled regulators" to the regulator tree Mark Brown
[not found] ` <CGME20180423143402eucas1p1c8518c75a68eddaf06d8598e97c6a98f@eucas1p1.samsung.com>
2018-04-23 14:33 ` [PATCH v7 5/6] regulator: core: Add voltage balancing mechanism Maciej Purski
[not found] ` <CGME20180423143402eucas1p18a76b8d1cf6027af8ebfcd74b7650a1f@eucas1p1.samsung.com>
2018-04-23 14:33 ` [PATCH v7 6/6] regulator: core: Change voltage setting path Maciej Purski
2018-09-27 17:14 ` [PATCH v7 0/6] Add coupled regulators mechanism Dmitry Osipenko
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=1524494022-22260-5-git-send-email-m.purski@samsung.com \
--to=m.purski@samsung.com \
--cc=b.zolnierkie@samsung.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=festevam@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).