mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zev Weiss <zev@bewilderbeest.net>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: Zev Weiss <zev@bewilderbeest.net>,
	linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	openbmc@lists.ozlabs.org
Subject: [PATCH 5/6] regulator: core: Add external get type
Date: Tue,  3 May 2022 23:52:51 -0700	[thread overview]
Message-ID: <20220504065252.6955-5-zev@bewilderbeest.net> (raw)
In-Reply-To: <20220504065252.6955-1-zev@bewilderbeest.net>

EXTERNAL_GET is similar to EXCLUSIVE_GET, but requires opt-in
agreement from the supply (whose constraints must designate it as
external_output).  It is intended for use only within the regulator
subsystem, and hence is not exposed in the public headers.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 drivers/regulator/core.c     | 16 +++++++++++++---
 drivers/regulator/devres.c   |  7 +++++++
 drivers/regulator/internal.h |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b7617926336f..d873606eb41f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2087,6 +2087,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
 	struct regulator_dev *rdev;
 	struct regulator *regulator;
 	struct device_link *link;
+	bool is_external;
 	int ret;
 
 	if (get_type >= MAX_GET_TYPE) {
@@ -2129,8 +2130,9 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
 			break;
 
 		case EXCLUSIVE_GET:
+		case EXTERNAL_GET:
 			dev_warn(dev,
-				 "dummy supplies not allowed for exclusive requests\n");
+				 "dummy supplies not allowed for exclusive or external requests\n");
 			fallthrough;
 
 		default:
@@ -2144,12 +2146,20 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
 		return regulator;
 	}
 
-	if (get_type == EXCLUSIVE_GET && rdev->open_count) {
+	if ((get_type == EXCLUSIVE_GET || get_type == EXTERNAL_GET) && rdev->open_count) {
 		regulator = ERR_PTR(-EBUSY);
 		put_device(&rdev->dev);
 		return regulator;
 	}
 
+	/* EXTERNAL_GET is valid if and only if the regulator is designated for external output */
+	is_external = rdev->constraints && rdev->constraints->external_output;
+	if ((get_type == EXTERNAL_GET) != is_external) {
+		regulator = ERR_PTR(-EINVAL);
+		put_device(&rdev->dev);
+		return regulator;
+	}
+
 	mutex_lock(&regulator_list_mutex);
 	ret = (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled);
 	mutex_unlock(&regulator_list_mutex);
@@ -2182,7 +2192,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
 	}
 
 	rdev->open_count++;
-	if (get_type == EXCLUSIVE_GET) {
+	if (get_type == EXCLUSIVE_GET || get_type == EXTERNAL_GET) {
 		rdev->exclusive = 1;
 
 		ret = _regulator_is_enabled(rdev);
diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
index 9113233f41cd..36df9e9ff175 100644
--- a/drivers/regulator/devres.c
+++ b/drivers/regulator/devres.c
@@ -70,6 +70,13 @@ struct regulator *devm_regulator_get_exclusive(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
 
+/* For regulator-core internal use only */
+struct regulator *devm_regulator_get_external(struct device *dev,
+					      const char *id)
+{
+	return _devm_regulator_get(dev, id, EXTERNAL_GET);
+}
+
 /**
  * devm_regulator_get_optional - Resource managed regulator_get_optional()
  * @dev: device to supply
diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
index 1e9c71642143..c176a416c571 100644
--- a/drivers/regulator/internal.h
+++ b/drivers/regulator/internal.h
@@ -116,10 +116,13 @@ static inline bool of_check_coupling_data(struct regulator_dev *rdev)
 enum regulator_get_type {
 	NORMAL_GET,
 	EXCLUSIVE_GET,
+	EXTERNAL_GET,
 	OPTIONAL_GET,
 	MAX_GET_TYPE
 };
 
 struct regulator *_regulator_get(struct device *dev, const char *id,
 				 enum regulator_get_type get_type);
+struct regulator *devm_regulator_get_external(struct device *dev,
+					      const char *id);
 #endif
-- 
2.36.0


  parent reply	other threads:[~2022-05-04  6:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04  6:52 [PATCH 1/6] dt-bindings: regulator: Add regulator-external-output property Zev Weiss
2022-05-04  6:52 ` [PATCH 2/6] dt-bindings: regulator: Add reg-external-output binding Zev Weiss
2022-05-04 12:55   ` Mark Brown
2022-05-04 20:33     ` Zev Weiss
2022-05-04 20:49       ` Mark Brown
2022-05-04 21:35         ` Zev Weiss
2022-05-05 12:05           ` Mark Brown
2022-05-05  8:33       ` Krzysztof Kozlowski
2022-05-04  6:52 ` [PATCH 3/6] regulator: core: Add error flags to sysfs attributes Zev Weiss
2022-05-04  6:52 ` [PATCH 4/6] regulator: core: Add external-output support Zev Weiss
2022-05-04 13:06   ` Mark Brown
2022-05-04  6:52 ` Zev Weiss [this message]
2022-05-04  6:52 ` [PATCH 6/6] regulator: core: Add external-consumer driver Zev Weiss
2022-05-04 12:36 ` [PATCH 1/6] dt-bindings: regulator: Add regulator-external-output property Mark Brown
2022-05-04 20:54 ` (subset) " Mark Brown

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=20220504065252.6955-5-zev@bewilderbeest.net \
    --to=zev@bewilderbeest.net \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openbmc@lists.ozlabs.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

all inboxes | Powered by JetHome®