mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 6/7] regulator: add regulator_register()
Date: Tue, 15 Oct 2024 13:11:03 +0200	[thread overview]
Message-ID: <20241015-rockchip-spi-rk808-v1-6-e276b4b59603@pengutronix.de> (raw)
In-Reply-To: <20241015-rockchip-spi-rk808-v1-0-e276b4b59603@pengutronix.de>

This adds a regulator_register() with a prototype compatible to Linux.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/regulator/core.c | 37 +++++++++++++++++++++++++++++++++++++
 include/regulator.h      | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index bbba3b0b57..30ae270b51 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -425,6 +425,43 @@ int dev_regulator_register(struct regulator_dev *rdev, const char *name)
 	return 0;
 }
 
+struct regulator_dev *
+regulator_register(struct device *dev,
+		   const struct regulator_desc *desc,
+		   const struct regulator_config *config)
+{
+	struct regulator_dev *rdev;
+	struct device_node *search, *child;
+	int ret;
+
+	rdev = xzalloc(sizeof(*rdev));
+
+	rdev->name = desc->name;
+	rdev->desc = desc;
+	rdev->regmap = config->regmap;
+	rdev->dev = dev;
+
+	if (desc->regulators_node)
+		search = of_get_child_by_name(dev->of_node,
+					      desc->regulators_node);
+	else
+		search = dev->of_node;
+
+	if (!search) {
+		dev_err(dev, "Failed to find regulator container node\n");
+		return NULL;
+	}
+
+	for_each_child_of_node(search, child) {
+		if (strcmp(desc->of_match, child->name))
+			continue;
+		ret = of_regulator_register(rdev, child);
+		break;
+	}
+
+	return rdev;
+}
+
 static struct regulator_dev *dev_regulator_get(struct device *dev,
 					       const char *supply)
 {
diff --git a/include/regulator.h b/include/regulator.h
index 305da0d774..9785b8ac07 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -35,7 +35,12 @@ struct regulator_bulk_data {
  * structure contains the non-varying parts of the regulator
  * description.
  *
+ * @name: Identifying name for the regulator.
+ * @supply_name: Identifying the regulator supply
  * @supply_name: Identifying the supply of this regulator
+ * @of_match: Name used to identify regulator in DT.
+ * @regulators_node: Name of node containing regulator definitions in DT.
+ * @id: Numerical identifier for the regulator.
  *
  * @n_voltages: Number of selectors available for ops.list_voltage().
  * @ops: Regulator operations table.
@@ -62,7 +67,11 @@ struct regulator_bulk_data {
  */
 
 struct regulator_desc {
+	const char *name;
 	const char *supply_name;
+	const char *of_match;
+	const char *regulators_node;
+	int id;
 	unsigned n_voltages;
 	const struct regulator_ops *ops;
 
@@ -87,6 +96,28 @@ struct regulator_desc {
 	unsigned int off_on_delay;
 };
 
+/**
+ * struct regulator_config - Dynamic regulator descriptor
+ *
+ * Each regulator registered with the core is described with a
+ * structure of this type and a struct regulator_desc.  This structure
+ * contains the runtime variable parts of the regulator description.
+ *
+ * @dev: struct device for the regulator
+ * @init_data: platform provided init data, passed through by driver
+ * @driver_data: private regulator data
+ * @of_node: OpenFirmware node to parse for device tree bindings (may be
+ *           NULL).
+ * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
+ *          insufficient.
+ * @ena_gpiod: GPIO controlling regulator enable.
+ */
+struct regulator_config {
+	struct device *dev;
+	void *driver_data;
+	struct regmap *regmap;
+};
+
 struct regulator_dev {
 	const char *name;
 	struct list_head list;
@@ -158,6 +189,11 @@ static inline int of_regulator_register(struct regulator_dev *rd,
 #endif
 int dev_regulator_register(struct regulator_dev *rd, const char *name);
 
+struct regulator_dev *
+regulator_register(struct device *dev,
+		   const struct regulator_desc *regulator_desc,
+		   const struct regulator_config *config);
+
 #define REGULATOR_PRINT_DEVS	BIT(0)
 void regulators_print(unsigned flags);
 

-- 
2.39.5




  parent reply	other threads:[~2024-10-15 11:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 11:10 [PATCH 0/7] rockchip: add RK808 support Sascha Hauer
2024-10-15 11:10 ` [PATCH 1/7] spi: add rockchip spi controller support Sascha Hauer
2024-10-15 11:10 ` [PATCH 2/7] mfd: mx13xxx: drop unnecessary ifdefs Sascha Hauer
2024-10-15 11:11 ` [PATCH 3/7] mfd: rk808: factor out common probe function Sascha Hauer
2024-10-15 11:11 ` [PATCH 4/7] mfd: rk808: update header file from kernel Sascha Hauer
2024-10-15 11:11 ` [PATCH 5/7] mfd: rk808: add support for RK806 Sascha Hauer
2024-10-15 14:46   ` Alexander Shiyan
2024-10-16  7:07     ` Alexander Shiyan
2024-10-16  9:01       ` Sascha Hauer
2024-10-16  9:11         ` Alexander Shiyan
2024-10-16  9:13         ` Alexander Shiyan
2024-10-16 10:48           ` Sascha Hauer
2024-10-16 16:08             ` Alexander Shiyan
2024-10-17 11:05               ` Sascha Hauer
2024-10-18  5:12                 ` Alexander Shiyan
2024-10-18  8:42                   ` Sascha Hauer
2024-10-15 11:11 ` Sascha Hauer [this message]
2024-10-15 11:11 ` [PATCH 7/7] regulator: rk808: update from kernel Sascha Hauer
2024-10-18  8:39 ` [PATCH 0/7] rockchip: add RK808 support Sascha Hauer

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=20241015-rockchip-spi-rk808-v1-6-e276b4b59603@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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