diff mbox series

[v6,1/8] regulator: Add (devm_)of_regulator_get()

Message ID 20250220-rk3588-gpu-pwr-domain-regulator-v6-1-a4f9c24e5b81@kernel.org
State New
Headers show
Series Fix RK3588 power domain problems | expand

Commit Message

Sebastian Reichel Feb. 20, 2025, 6:58 p.m. UTC
The Rockchip power-domain controller also plans to make use of
per-domain regulators similar to the MediaTek power-domain controller.
Since existing DTs are missing the regulator information, the kernel
should fallback to the automatically created dummy regulator if
necessary. Thus the version without the _optional suffix is needed.

The Rockchip driver plans to use the managed version, but to be
consistent with existing code the unmanaged version is added at the
same time.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/regulator/devres.c         | 17 +++++++++++++++++
 drivers/regulator/of_regulator.c   | 21 +++++++++++++++++++++
 include/linux/regulator/consumer.h |  6 ++++++
 3 files changed, 44 insertions(+)

Comments

Mark Brown Feb. 25, 2025, 5:59 p.m. UTC | #1
On Thu, Feb 20, 2025 at 07:58:04PM +0100, Sebastian Reichel wrote:
> The Rockchip power-domain controller also plans to make use of
> per-domain regulators similar to the MediaTek power-domain controller.
> Since existing DTs are missing the regulator information, the kernel
> should fallback to the automatically created dummy regulator if
> necessary. Thus the version without the _optional suffix is needed.

The following changes since commit 0ad2507d5d93f39619fc42372c347d6006b64319:

  Linux 6.14-rc3 (2025-02-16 14:02:44 -0800)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git tags/regulator-devm-of-get

for you to fetch changes up to 0dffacbbf8d044456d50c893adb9499775c489f4:

  regulator: Add (devm_)of_regulator_get() (2025-02-24 15:26:08 +0000)

----------------------------------------------------------------
regulator: Add (devm_)of_regulator_get()

This introduces devm_of_regulator_get without the _optional suffix, since
that is more sensible for the Rockchip usecase.

----------------------------------------------------------------
Sebastian Reichel (1):
      regulator: Add (devm_)of_regulator_get()

 drivers/regulator/devres.c         | 17 +++++++++++++++++
 drivers/regulator/of_regulator.c   | 21 +++++++++++++++++++++
 include/linux/regulator/consumer.h |  6 ++++++
 3 files changed, 44 insertions(+)
Ulf Hansson Feb. 28, 2025, 12:11 p.m. UTC | #2
On Tue, 25 Feb 2025 at 18:59, Mark Brown <broonie@kernel.org> wrote:
>
> On Thu, Feb 20, 2025 at 07:58:04PM +0100, Sebastian Reichel wrote:
> > The Rockchip power-domain controller also plans to make use of
> > per-domain regulators similar to the MediaTek power-domain controller.
> > Since existing DTs are missing the regulator information, the kernel
> > should fallback to the automatically created dummy regulator if
> > necessary. Thus the version without the _optional suffix is needed.
>
> The following changes since commit 0ad2507d5d93f39619fc42372c347d6006b64319:
>
>   Linux 6.14-rc3 (2025-02-16 14:02:44 -0800)
>
> are available in the Git repository at:
>
>   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git tags/regulator-devm-of-get
>
> for you to fetch changes up to 0dffacbbf8d044456d50c893adb9499775c489f4:
>
>   regulator: Add (devm_)of_regulator_get() (2025-02-24 15:26:08 +0000)
>
> ----------------------------------------------------------------
> regulator: Add (devm_)of_regulator_get()
>
> This introduces devm_of_regulator_get without the _optional suffix, since
> that is more sensible for the Rockchip usecase.
>
> ----------------------------------------------------------------
> Sebastian Reichel (1):
>       regulator: Add (devm_)of_regulator_get()
>
>  drivers/regulator/devres.c         | 17 +++++++++++++++++
>  drivers/regulator/of_regulator.c   | 21 +++++++++++++++++++++
>  include/linux/regulator/consumer.h |  6 ++++++
>  3 files changed, 44 insertions(+)

Thanks, pulled into the next branch of my pmdomain tree.

Kind regards
Uffe
diff mbox series

Patch

diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
index 36164aec30e83de70d07d59b57678b89336bc4c7..a3a3ccc711fc695aa7d3da576bacee42f7f6bc45 100644
--- a/drivers/regulator/devres.c
+++ b/drivers/regulator/devres.c
@@ -771,6 +771,23 @@  static struct regulator *_devm_of_regulator_get(struct device *dev, struct devic
 	return regulator;
 }
 
+/**
+ * devm_of_regulator_get - Resource managed of_regulator_get()
+ * @dev: device used for dev_printk() messages and resource lifetime management
+ * @node: device node for regulator "consumer"
+ * @id:  supply name or regulator ID.
+ *
+ * Managed of_regulator_get(). Regulators returned from this
+ * function are automatically regulator_put() on driver detach. See
+ * of_regulator_get() for more information.
+ */
+struct regulator *devm_of_regulator_get(struct device *dev, struct device_node *node,
+						 const char *id)
+{
+	return _devm_of_regulator_get(dev, node, id, NORMAL_GET);
+}
+EXPORT_SYMBOL_GPL(devm_of_regulator_get);
+
 /**
  * devm_of_regulator_get_optional - Resource managed of_regulator_get_optional()
  * @dev: device used for dev_printk() messages and resource lifetime management
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 011088c57891b517d01daf9a5cca6497b11899be..32e88cada47a254c3b184f3d1d6d8c1dccdfcc28 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -697,6 +697,27 @@  struct regulator *_of_regulator_get(struct device *dev, struct device_node *node
 	return _regulator_get_common(r, dev, id, get_type);
 }
 
+/**
+ * of_regulator_get - get regulator via device tree lookup
+ * @dev: device used for dev_printk() messages
+ * @node: device node for regulator "consumer"
+ * @id: Supply name
+ *
+ * Return: pointer to struct regulator corresponding to the regulator producer,
+ *	   or PTR_ERR() encoded error number.
+ *
+ * This is intended for use by consumers that want to get a regulator
+ * supply directly from a device node. This will _not_ consider supply
+ * aliases. See regulator_dev_lookup().
+ */
+struct regulator *of_regulator_get(struct device *dev,
+					    struct device_node *node,
+					    const char *id)
+{
+	return _of_regulator_get(dev, node, id, NORMAL_GET);
+}
+EXPORT_SYMBOL_GPL(of_regulator_get);
+
 /**
  * of_regulator_get_optional - get optional regulator via device tree lookup
  * @dev: device used for dev_printk() messages
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index ffe912f345aea1fca7aeb2e34310c15a5739ca18..56fe2693d9b2284d04ebae50165f9aa7b1b3fee4 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -677,6 +677,12 @@  regulator_is_equal(struct regulator *reg1, struct regulator *reg2)
 #endif
 
 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_REGULATOR)
+struct regulator *__must_check of_regulator_get(struct device *dev,
+						struct device_node *node,
+						const char *id);
+struct regulator *__must_check devm_of_regulator_get(struct device *dev,
+						     struct device_node *node,
+						     const char *id);
 struct regulator *__must_check of_regulator_get_optional(struct device *dev,
 							 struct device_node *node,
 							 const char *id);