[PATCH 6/7] regulator: add regulator_register()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux