[PATCH 0/9] Device tree support for regulators

STALE5416d

Revision v1 of 5 in this series.

36 messages, 5 authors, 2011-10-04 · open the first message on its own page

[PATCH 0/9] Device tree support for regulators

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:43

Hi Mark, Grant,

This is a respin of my RFC series I posted sometime back
and is now based on top of the latest omap i2c-twl support
series posted by Benoit
git://gitorious.org/omap-pm/linux.git for_3.2/4_omap_dt_i2c_twl

some changes done since the RFC:
1. twl driver fixed to remove hardcoded board params
2. regulator helpers moved from drivers/of to drivers/regulator
3. Better compatible definitions for specific device type
4. twl regulator driver doing internal table lookup based on
compatible rather then pdev->id
5. Seperate fixed voltage regulator bindings defined
6. Changed the way devices associate with regulators
i.e using <name>-supply = <&regulator-phandle>;

regards,
Rajendra

Rajendra Nayak (9):
  regulator: twl: Remove hardcoded board constraints from driver
  regulator: helper routine to extract regulator_init_data
  omap4: sdp: Pass regulator data from dt
  regulator: twl: Make twl-regulator driver extract data from DT
  regulator: helper routine to extract fixed_voltage_config
  regulator: make fixed regulator driver extract data from dt
  omap4: panda: Pass regulator data from DT
  regulator: helper to extract regulator node based on supply name
  regulator: map consumer regulator based on device tree

 .../bindings/regulator/fixed-regulator.txt         |   24 ++++
 .../devicetree/bindings/regulator/regulator.txt    |   42 +++++++
 .../bindings/regulator/twl-regulator.txt           |   60 +++++++++
 arch/arm/boot/dts/omap4-panda.dts                  |   54 ++++++++
 arch/arm/boot/dts/omap4-sdp.dts                    |   64 ++++++++++
 drivers/regulator/Kconfig                          |    7 +
 drivers/regulator/Makefile                         |    1 +
 drivers/regulator/core.c                           |   14 ++
 drivers/regulator/fixed.c                          |   54 ++++++++-
 drivers/regulator/of_regulator.c                   |  127 ++++++++++++++++++++
 drivers/regulator/twl-regulator.c                  |  125 ++++++++++++--------
 include/linux/regulator/driver.h                   |    3 +
 include/linux/regulator/fixed.h                    |    6 +-
 include/linux/regulator/machine.h                  |   12 +-
 include/linux/regulator/of_regulator.h             |   28 +++++
 15 files changed, 562 insertions(+), 59 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txt
 create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt
 create mode 100644 Documentation/devicetree/bindings/regulator/twl-regulator.txt
 create mode 100644 drivers/regulator/of_regulator.c
 create mode 100644 include/linux/regulator/of_regulator.h

[PATCH 1/9] regulator: twl: Remove hardcoded board constraints from driver

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:44

Remove the hardcoded .valid_modes_mask and .valid_ops_mask for
each regulator from the twl driver and let the boards pass it.

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/twl-regulator.c |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index ee8747f..f696287 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -1027,14 +1027,6 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
 	/* copy the features into regulator data */
 	info->features = (unsigned long)initdata->driver_data;
 
-	/* Constrain board-specific capabilities according to what
-	 * this driver and the chip itself can actually do.
-	 */
-	c = &initdata->constraints;
-	c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
-	c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
-				| REGULATOR_CHANGE_MODE
-				| REGULATOR_CHANGE_STATUS;
 	switch (pdev->id) {
 	case TWL4030_REG_VIO:
 	case TWL4030_REG_VDD1:
-- 
1.7.1

[PATCH 2/9] regulator: helper routine to extract regulator_init_data

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:45

The helper routine is meant to be used by regulator drivers
to extract the regulator_init_data structure from the data
that is passed from device tree.
'consumer_supplies' which is part of regulator_init_data is not extracted
as the regulator consumer mappings are passed through DT differently,
implemented in subsequent patches.

Also add documentation for regulator bindings to be used to pass
regulator_init_data struct information from device tree.

Signed-off-by: Rajendra Nayak <redacted>
---
 .../devicetree/bindings/regulator/regulator.txt    |   42 +++++++++
 drivers/regulator/Kconfig                          |    7 ++
 drivers/regulator/Makefile                         |    1 +
 drivers/regulator/of_regulator.c                   |   88 ++++++++++++++++++++
 include/linux/regulator/machine.h                  |   12 ++--
 include/linux/regulator/of_regulator.h             |   21 +++++
 6 files changed, 165 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt
 create mode 100644 drivers/regulator/of_regulator.c
 create mode 100644 include/linux/regulator/of_regulator.h
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
new file mode 100644
index 0000000..91b8d8f
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -0,0 +1,42 @@
+Voltage/Current Regulators
+
+Optional properties:
+- regulator-supplies: Names of the regulator supplies
+- regulator-min-uV: smallest voltage consumers may set
+- regulator-max-uV: largest voltage consumers may set
+- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops
+- regulator-min-uA: smallest current consumers may set
+- regulator-max-uA: largest current consumers may set
+- regulator-change-voltage: boolean, Output voltage can be changed by software
+- regulator-change-current: boolean, Output current can be chnaged by software
+- regulator-change-mode: boolean, Operating mode can be changed by software
+- regulator-change-status: boolean, Enable/Disable control for regulator exists
+- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled
+- regulator-mode-fast: boolean, allow/set fast mode for the regulator
+- regulator-mode-normal: boolean, allow/set normal mode for the regulator
+- regulator-mode-idle: boolean, allow/set idle mode for the regulator
+- regulator-mode-standby: boolean, allow/set standby mode for the regulator
+- regulator-input-uV: Input voltage for regulator when supplied by another regulator
+- regulator-always-on: boolean, regulator should never be disabled
+- regulator-boot-on: bootloader/firmware enabled regulator
+
+Example:
+
+	xyzreg: regulator at 0 {
+		regulator-min-uV = <1000000>;
+		regulator-max-uV = <2500000>;
+		regulator-mode-fast;
+		regulator-change-voltage;
+		regulator-always-on;
+	};
+
+Example of a device node referencing a regulator node:
+
+	devicenode: node at 0x0 {
+		...
+		...
+		<name>-supply = <&xyzreg>;
+	};
+
+	where <name> is the supply name or regulator id passed
+	as part of regulator_get(dev, <name>);
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index c7fd2c0..2b684aa 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -64,6 +64,13 @@ config REGULATOR_USERSPACE_CONSUMER
 
           If unsure, say no.
 
+config OF_REGULATOR
+	tristate "OF regulator helpers"
+	depends on OF
+	help
+	  OpenFirmware regulator framework helper routines that can
+	  used by regulator drivers to extract data from device tree.
+
 config REGULATOR_BQ24022
 	tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC"
 	help
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 040d5aa..e6bc009 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o
 obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
+obj-$(CONFIG_OF_REGULATOR) += of_regulator.o
 
 obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
new file mode 100644
index 0000000..7fa63ff
--- /dev/null
+++ b/drivers/regulator/of_regulator.c
@@ -0,0 +1,88 @@
+/*
+ * OF helpers for regulator framework
+ *
+ * Copyright (C) 2011 Texas Instruments, Inc.
+ * Rajendra Nayak <rnayak@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/regulator/machine.h>
+
+static void of_get_regulation_constraints(struct device_node *np,
+					struct regulator_init_data **init_data)
+{
+	unsigned int valid_modes_mask = 0, valid_ops_mask = 0;
+
+	of_property_read_u32(np, "regulator-min-uV",
+				&(*init_data)->constraints.min_uV);
+	of_property_read_u32(np, "regulator-max-uV",
+				&(*init_data)->constraints.max_uV);
+	of_property_read_u32(np, "regulator-uV-offset",
+				&(*init_data)->constraints.uV_offset);
+	of_property_read_u32(np, "regulator-min-uA",
+				&(*init_data)->constraints.min_uA);
+	of_property_read_u32(np, "regulator-max-uA",
+				&(*init_data)->constraints.max_uA);
+	of_property_read_u32(np, "regulator-input-uV",
+				&(*init_data)->constraints.input_uV);
+
+	/* valid modes mask */
+	if (of_find_property(np, "regulator-mode-fast", NULL))
+				valid_modes_mask |= REGULATOR_MODE_FAST;
+	if (of_find_property(np, "regulator-mode-normal", NULL))
+				valid_modes_mask |= REGULATOR_MODE_NORMAL;
+	if (of_find_property(np, "regulator-mode-idle", NULL))
+				valid_modes_mask |= REGULATOR_MODE_IDLE;
+	if (of_find_property(np, "regulator-mode-standby", NULL))
+				valid_modes_mask |= REGULATOR_MODE_STANDBY;
+
+	/* valid ops mask */
+	if (of_find_property(np, "regulator-change-voltage", NULL))
+				valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
+	if (of_find_property(np, "regulator-change-current", NULL))
+				valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
+	if (of_find_property(np, "regulator-change-mode", NULL))
+				valid_ops_mask |= REGULATOR_CHANGE_MODE;
+	if (of_find_property(np, "regulator-change-status", NULL))
+				valid_ops_mask |= REGULATOR_CHANGE_STATUS;
+
+	(*init_data)->constraints.valid_modes_mask = valid_modes_mask;
+	(*init_data)->constraints.valid_ops_mask = valid_ops_mask;
+
+	if (of_find_property(np, "regulator-always-on", NULL))
+				(*init_data)->constraints.always_on = true;
+	if (of_find_property(np, "regulator-boot-on", NULL))
+				(*init_data)->constraints.boot_on = true;
+}
+
+/**
+ * of_get_regulator_init_data - extract regulator_init_data structure info
+ * @dev: device requesting for regulator_init_data
+ *
+ * Populates regulator_init_data structure by extracting data from device
+ * tree node, returns a pointer to the populated struture or NULL if memory
+ * alloc fails.
+ */
+struct regulator_init_data *of_get_regulator_init_data(struct device *dev)
+{
+	struct regulator_init_data *init_data;
+
+	if (!dev->of_node)
+		return NULL;
+
+	init_data = devm_kzalloc(dev, sizeof(struct regulator_init_data),
+						 GFP_KERNEL);
+	if (!init_data)
+		return NULL; /* Out of memory? */
+
+	init_data->supply_regulator = (char *)of_get_property(dev->of_node,
+						"regulator-supplies", NULL);
+	of_get_regulation_constraints(dev->of_node, &init_data);
+	return init_data;
+}
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index ce3127a..d2d921b 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -98,14 +98,14 @@ struct regulation_constraints {
 	char *name;
 
 	/* voltage output range (inclusive) - for voltage control */
-	int min_uV;
-	int max_uV;
+	u32 min_uV;
+	u32 max_uV;
 
-	int uV_offset;
+	u32 uV_offset;
 
 	/* current output range (inclusive) - for current control */
-	int min_uA;
-	int max_uA;
+	u32 min_uA;
+	u32 max_uA;
 
 	/* valid regulator operating modes for this machine */
 	unsigned int valid_modes_mask;
@@ -114,7 +114,7 @@ struct regulation_constraints {
 	unsigned int valid_ops_mask;
 
 	/* regulator input voltage - only if supply is another regulator */
-	int input_uV;
+	u32 input_uV;
 
 	/* regulator suspend states for global PMIC STANDBY/HIBERNATE */
 	struct regulator_state state_disk;
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
new file mode 100644
index 0000000..3f63be9
--- /dev/null
+++ b/include/linux/regulator/of_regulator.h
@@ -0,0 +1,21 @@
+/*
+ * OpenFirmware regulator support routines
+ *
+ */
+
+#ifndef __LINUX_OF_REG_H
+#define __LINUX_OF_REG_H
+
+#if defined(CONFIG_OF_REGULATOR)
+extern struct regulator_init_data
+	*of_get_regulator_init_data(struct device *dev);
+#else
+static inline struct regulator_init_data
+	*of_get_regulator_init_data(struct device_node *np)
+{
+	return NULL;
+}
+#endif /* CONFIG_OF_REGULATOR */
+
+#endif /* __LINUX_OF_REG_H */
+
-- 
1.7.1

[PATCH 3/9] omap4: sdp: Pass regulator data from dt

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:46

Pass adjustable regulator information for omap4sdp from device tree so the
regulator driver can then use the regulator helper
routine to extract and use them during the driver probe().

Also add documentation for TWL regulator specific bindings.

Signed-off-by: Rajendra Nayak <redacted>
---
 .../bindings/regulator/twl-regulator.txt           |   60 ++++++++++++++++++
 arch/arm/boot/dts/omap4-sdp.dts                    |   64 ++++++++++++++++++++
 2 files changed, 124 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/regulator/twl-regulator.txt
diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
new file mode 100644
index 0000000..7b809ff
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
@@ -0,0 +1,60 @@
+TWL family of regulators
+
+Required properties:
+- compatible:
+  - "ti,twl4030" for twl4030 regulators
+  - "ti,twl6025" for twl6025 regulators
+  - "ti,twl6030" for twl6030 regulators
+
+Additionally compatible can be used to specify the
+exact regulator/ldo instance like
+For twl6030 regulators/LDO's
+- compatible:
+  - "ti,twl6030-vaux1" for VAUX1 LDO
+  - "ti,twl6030-vaux2" for VAUX2 LDO
+  - "ti,twl6030-vaux3" for VAUX3 LDO
+  - "ti,twl6030-vmmc" for VMMC LDO
+  - "ti,twl6030-vpp" for VPP LDO
+  - "ti,twl6030-vusim" for VUSIM LDO
+For twl6025 regulators/LDO's
+- compatible:
+  - "ti,twl6025-ldo1" for LDO1 LDO
+  - "ti,twl6025-ldo2" for LDO2 LDO
+  - "ti,twl6025-ldo3" for LDO3 LDO
+  - "ti,twl6025-ldo4" for LDO4 LDO
+  - "ti,twl6025-ldo5" for LDO5 LDO
+  - "ti,twl6025-ldo6" for LDO6 LDO
+  - "ti,twl6025-ldo7" for LDO7 LDO
+  - "ti,twl6025-ldoln" for LDOLN LDO
+  - "ti,twl6025-ldousb" for LDOUSB LDO
+For twl4030 regulators/LDO's
+- compatible:
+  - "ti,twl4030-vaux1" for VAUX1 LDO
+  - "ti,twl4030-vaux2" for VAUX2 LDO
+  - "ti,twl5030-vaux2" for VAUX2 LDO
+  - "ti,twl4030-vaux3" for VAUX3 LDO
+  - "ti,twl4030-vaux4" for VAUX4 LDO
+  - "ti,twl4030-vmmc1" for VMMC1 LDO
+  - "ti,twl4030-vmmc2" for VMMC2 LDO
+  - "ti,twl4030-vpll1" for VPLL1 LDO
+  - "ti,twl4030-vpll2" for VPLL2 LDO
+  - "ti,twl4030-vsim" for VSIM LDO
+  - "ti,twl4030-vdac" for VDAC LDO
+  - "ti,twl4030-vintana2" for VINTANA2 LDO
+  - "ti,twl4030-vio" for VIO LDO
+  - "ti,twl4030-vdd1" for VDD1 LDO
+  - "ti,twl4030-vdd2" for VDD2 LDO
+
+Optional properties:
+- Any optional property defined in bindings/regulator/regulator.txt
+
+Example:
+
+	xyz: regulator at 0 {
+		compatible = "ti,twl6030-vaux1","ti,twl6030";
+		regulator-min_uV  = <1000000>;
+		regulator-max_uV  = <3000000>;
+		regulator-more-normal;
+		regulator-mode-standby;
+		regulator-change-voltage;
+	};
diff --git a/arch/arm/boot/dts/omap4-sdp.dts b/arch/arm/boot/dts/omap4-sdp.dts
index 2990841..edbf77e 100644
--- a/arch/arm/boot/dts/omap4-sdp.dts
+++ b/arch/arm/boot/dts/omap4-sdp.dts
@@ -48,6 +48,70 @@
 			compatible = "ti,twl4030-rtc";
 			interrupts = <11>;
 		};
+
+		vaux1: regulator at 0 {
+			compatible = "ti,twl6030-vaux1","ti,twl6030";
+			regulator-min-uV = <1000000>;
+			regulator-max-uV = <3000000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-voltage;
+			regulator-change-mode;
+		};
+
+		vaux2: regulator at 1 {
+			compatible = "ti,twl6030-vaux2","ti,twl6030";
+			regulator-min-uV = <1200000>;
+			regulator-max-uV = <2800000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vaux3: regulator at 2 {
+			compatible = "ti,twl6030-vaux3","ti,twl6030";
+			regulator-min-uV = <1000000>;
+			regulator-max-uV = <3000000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vmmc: regulator at 3 {
+			compatible = "ti,twl6030-vmmc","ti,twl6030";
+			regulator-min-uV = <1200000>;
+			regulator-max-uV = <3000000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vpp: regulator at 4 {
+			compatible = "ti,twl6030-vpp","ti,twl6030";
+			regulator-min-uV = <1800000>;
+			regulator-max-uV = <2500000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vusim: regulator at 5 {
+			compatible = "ti,twl6030-vusim","ti,twl6030";
+			regulator-min-uV = <1200000>;
+			regulator-max-uV = <2900000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-voltage;
+			regulator-change-mode;
+		};
 	};
 };
 
-- 
1.7.1

[PATCH 4/9] regulator: twl: Make twl-regulator driver extract data from DT

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:47

Modify the twl regulator driver to extract the regulator_init_data from
device tree when passed, instead of getting it through platform_data
structures (on non-DT builds)

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/twl-regulator.c |  117 ++++++++++++++++++++++++-------------
 1 files changed, 76 insertions(+), 41 deletions(-)
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index f696287..ddb5ad1 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -14,8 +14,10 @@
 #include <linux/err.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
 #include <linux/i2c/twl.h>
 
 
@@ -58,6 +60,9 @@ struct twlreg_info {
 
 	/* chip specific features */
 	unsigned long 		features;
+#ifdef CONFIG_OF
+	char			compatible[128];
+#endif
 };
 
 
@@ -839,13 +844,14 @@ static struct regulator_ops twlsmps_ops = {
 		TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
 			0x0, TWL6030, twl6030fixed_ops)
 
-#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
+#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf, comp) { \
 	.base = offset, \
 	.id = num, \
 	.table_len = ARRAY_SIZE(label##_VSEL_table), \
 	.table = label##_VSEL_table, \
 	.delay = turnon_delay, \
 	.remap = remap_conf, \
+	.compatible = comp, \
 	.desc = { \
 		.name = #label, \
 		.id = TWL4030_REG_##label, \
@@ -856,10 +862,11 @@ static struct regulator_ops twlsmps_ops = {
 		}, \
 	}
 
-#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
+#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts, comp) { \
 	.base = offset, \
 	.min_mV = min_mVolts, \
 	.max_mV = max_mVolts, \
+	.compatible = comp, \
 	.desc = { \
 		.name = #label, \
 		.id = TWL6030_REG_##label, \
@@ -870,10 +877,11 @@ static struct regulator_ops twlsmps_ops = {
 		}, \
 	}
 
-#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
+#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts, comp) { \
 	.base = offset, \
 	.min_mV = min_mVolts, \
 	.max_mV = max_mVolts, \
+	.compatible = comp, \
 	.desc = { \
 		.name = #label, \
 		.id = TWL6025_REG_##label, \
@@ -932,23 +940,23 @@ static struct regulator_ops twlsmps_ops = {
  * software control over them after boot.
  */
 static struct twlreg_info twl_regs[] = {
-	TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
-	TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
-	TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
+	TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08, "ti,twl4030-vaux1"),
+	TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08, "ti,twl4030-vaux2"),
+	TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08, "ti,twl5030-vaux2"),
+	TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08, "ti,twl4030-vaux3"),
+	TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08, "ti,twl4030-vaux4"),
+	TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08, "ti,twl4030-vmmc1"),
+	TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08, "ti,twl4030-vmmc2"),
+	TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00, "ti,twl4030-vpll1"),
+	TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08, "ti,twl4030-vpll2"),
+	TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00, "ti,twl4030-vsim"),
+	TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08, "ti,twl4030-vdac"),
 	TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
+	TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08, "ti,twl4030-vintana2"),
 	TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
-	TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
+	TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08, "ti,twl4030-vio"),
+	TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08, "ti,twl4030-vdd1"),
+	TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08, "ti,twl4030-vdd2"),
 	TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
 	TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
 	TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
@@ -957,12 +965,12 @@ static struct twlreg_info twl_regs[] = {
 	/* 6030 REG with base as PMC Slave Misc : 0x0030 */
 	/* Turnon-delay and remap configuration values for 6030 are not
 	   verified since the specification is not public */
-	TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300),
-	TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300),
-	TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300),
-	TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300),
-	TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300),
-	TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300),
+	TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300, "ti,twl6030-vaux1"),
+	TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300, "ti,twl6030-vaux2"),
+	TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300, "ti,twl6030-vaux3"),
+	TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300, "ti,twl6030-vmmc"),
+	TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300, "ti,twl6030-vpp"),
+	TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300, "ti,twl6030-vusim"),
 	TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0),
 	TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0),
 	TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0),
@@ -970,15 +978,15 @@ static struct twlreg_info twl_regs[] = {
 	TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0),
 
 	/* 6025 are renamed compared to 6030 versions */
-	TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300),
-	TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300),
+	TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300, "ti,twl6025-ldo2"),
+	TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300, "ti,twl6025-ldo4"),
+	TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300, "ti,twl6025-ldo3"),
+	TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300, "ti,twl6025-ldo5"),
+	TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300, "ti,twl6025-ldo1"),
+	TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300, "ti,twl6025-ldo7"),
+	TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300, "ti,twl6025-ldo6"),
+	TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300, "ti,twl6025-ldoln"),
+	TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300, "ti,twl6025-ldousb"),
 
 	TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34),
 	TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10),
@@ -1011,16 +1019,27 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
 	struct regulation_constraints	*c;
 	struct regulator_dev		*rdev;
 
-	for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
-		if (twl_regs[i].desc.id != pdev->id)
-			continue;
-		info = twl_regs + i;
-		break;
+	if (pdev->dev.of_node) { /* dt based lookup */
+		for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
+			if (!of_device_is_compatible(pdev->dev.of_node,
+						 twl_regs[i].compatible))
+				continue;
+			info = twl_regs + i;
+			break;
+		}
+		initdata = of_get_regulator_init_data(&pdev->dev);
+	} else { /* pdev->id based lookup */
+		for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
+			if (twl_regs[i].desc.id != pdev->id)
+				continue;
+			info = twl_regs + i;
+			break;
+		}
+		initdata = pdev->dev.platform_data;
 	}
 	if (!info)
 		return -ENODEV;
 
-	initdata = pdev->dev.platform_data;
 	if (!initdata)
 		return -EINVAL;
 
@@ -1093,14 +1112,30 @@ static int __devexit twlreg_remove(struct platform_device *pdev)
 
 MODULE_ALIAS("platform:twl_reg");
 
+#if defined(CONFIG_OF)
+static const struct of_device_id twl_of_match[] __devinitconst = {
+	{ .compatible = "ti,twl6030" },
+	{ .compatible = "ti,twl6025" },
+	{ .compatible = "ti,twl5030" },
+	{ .compatible = "ti,twl4030" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, twl_of_match);
+#else
+#define twl_of_match NULL
+#endif
+
 static struct platform_driver twlreg_driver = {
 	.probe		= twlreg_probe,
 	.remove		= __devexit_p(twlreg_remove),
 	/* NOTE: short name, to work around driver model truncation of
 	 * "twl_regulator.12" (and friends) to "twl_regulator.1".
 	 */
-	.driver.name	= "twl_reg",
-	.driver.owner	= THIS_MODULE,
+	.driver  = {
+		.name  = "twl_reg",
+		.owner = THIS_MODULE,
+		.of_match_table = twl_of_match,
+	},
 };
 
 static int __init twlreg_init(void)
-- 
1.7.1

[PATCH 5/9] regulator: helper routine to extract fixed_voltage_config

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:48

The helper routine of_get_fixed_voltage_config() extracts
fixed_voltage_config structure contents from device tree.

Also add documenation for additional bindings for fixed
regulators that can be passed through dt.

Signed-off-by: Rajendra Nayak <redacted>
---
 .../bindings/regulator/fixed-regulator.txt         |   24 +++++++++++++
 drivers/regulator/fixed.c                          |   36 ++++++++++++++++++++
 include/linux/regulator/fixed.h                    |    6 ++--
 3 files changed, 63 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txt
diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
new file mode 100644
index 0000000..a204cbd
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
@@ -0,0 +1,24 @@
+Fixed Voltage regulators
+
+Required properties:
+- compatible: Must be "regulator-fixed";
+
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supply
+- regulator-fixed-microvolts: Output voltage of regulator
+- regulator-fixed-gpio: gpio to use for enable control
+- regulator-fixed-startup-delay: startup time in microseconds
+- regulator-fixed-enable-high: Polarity of enable GPIO, 1 = Active High, 0 = Active low
+- regulator-fixed-enabled-at-boot: 1 = yes, 0 = no
+
+Example:
+
+	abc: fixedregulator at 0 {
+		compatible = "regulator-fixed";
+		regulator-fixed-supply = "fixed-supply";
+		regulator-fixed-microvolts = <1800000>;
+		regulator-fixed-gpio = <43>;
+		regulator-fixed-startup-delay = <70000>;
+		regulator-fixed-enable-high;
+		regulator-fixed-enabled-at-boot;
+	};
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 2fe9d99..c09f791 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -26,6 +26,8 @@
 #include <linux/gpio.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/regulator/of_regulator.h>
 
 struct fixed_voltage_data {
 	struct regulator_desc desc;
@@ -37,6 +39,40 @@ struct fixed_voltage_data {
 	bool is_enabled;
 };
 
+
+/**
+ * of_get_fixed_voltage_config - extract fixed_voltage_config structure info
+ * @dev: device requesting for fixed_voltage_config
+ *
+ * Populates fixed_voltage_config structure by extracting data from device
+ * tree node, returns a pointer to the populated structure of NULL if memory
+ * alloc fails.
+ */
+struct fixed_voltage_config *of_get_fixed_voltage_config(struct device *dev)
+{
+	struct fixed_voltage_config *config;
+	struct device_node *np = dev->of_node;
+
+	config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), GFP_KERNEL);
+	if (!config)
+		return NULL;
+
+	config->supply_name = (char *)of_get_property(np,
+					"regulator-fixed-supply", NULL);
+	of_property_read_u32(np, "regulator-fixed-microvolts",
+					&config->microvolts);
+	of_property_read_u32(np, "regulator-fixed-gpio", &config->gpio);
+	of_property_read_u32(np, "regulator-fixed-startup-delay",
+					&config->startup_delay);
+	if (of_find_property(np, "regulator-fixed-enable-high", NULL))
+		config->enable_high = true;
+	if (of_find_property(np, "regulator-fixed-enabled-at-boot", NULL))
+		config->enabled_at_boot = true;
+	config->init_data = of_get_regulator_init_data(dev);
+
+	return config;
+}
+
 static int fixed_voltage_is_enabled(struct regulator_dev *dev)
 {
 	struct fixed_voltage_data *data = rdev_get_drvdata(dev);
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h
index ffd7d50..bb762cf 100644
--- a/include/linux/regulator/fixed.h
+++ b/include/linux/regulator/fixed.h
@@ -40,9 +40,9 @@ struct regulator_init_data;
  */
 struct fixed_voltage_config {
 	const char *supply_name;
-	int microvolts;
-	int gpio;
-	unsigned startup_delay;
+	u32 microvolts;
+	u32 gpio;
+	u32 startup_delay;
 	unsigned enable_high:1;
 	unsigned enabled_at_boot:1;
 	struct regulator_init_data *init_data;
-- 
1.7.1

[PATCH 6/9] regulator: make fixed regulator driver extract data from dt

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:49

Modify the fixed regulator driver to extract fixed_voltage_config from
device tree when passed, instead of getting it through platform_data
structures (on non-DT builds)

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/fixed.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index c09f791..0a9a10d 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -140,10 +140,15 @@ static struct regulator_ops fixed_voltage_ops = {
 
 static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
 {
-	struct fixed_voltage_config *config = pdev->dev.platform_data;
+	struct fixed_voltage_config *config;
 	struct fixed_voltage_data *drvdata;
 	int ret;
 
+	if (pdev->dev.of_node)
+		config = of_get_fixed_voltage_config(&pdev->dev);
+	else
+		config = pdev->dev.platform_data;
+
 	drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
 	if (drvdata == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate device data\n");
@@ -252,12 +257,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id fixed_of_match[] __devinitconst = {
+	{ .compatible = "regulator-fixed", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, fixed_of_match);
+#else
+#define fixed_of_match NULL
+#endif
+
 static struct platform_driver regulator_fixed_voltage_driver = {
 	.probe		= reg_fixed_voltage_probe,
 	.remove		= __devexit_p(reg_fixed_voltage_remove),
 	.driver		= {
 		.name		= "reg-fixed-voltage",
 		.owner		= THIS_MODULE,
+		.of_match_table = fixed_of_match,
 	},
 };
 
-- 
1.7.1

[PATCH 7/9] omap4: panda: Pass regulator data from DT

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:50

Pass the fixed and adjustable voltage regulator information for
omap4panda board from device tree.

Signed-off-by: Rajendra Nayak <redacted>
---
 arch/arm/boot/dts/omap4-panda.dts |   54 +++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/arch/arm/boot/dts/omap4-panda.dts b/arch/arm/boot/dts/omap4-panda.dts
index 2c6ce2b..045dbfc 100644
--- a/arch/arm/boot/dts/omap4-panda.dts
+++ b/arch/arm/boot/dts/omap4-panda.dts
@@ -48,6 +48,60 @@
 			compatible = "ti,twl4030-rtc";
 			interrupts = <11>;
 		};
+
+		vwl1271: fixedregulator at 0 {
+			compatible = "regulator-fixed";
+			regulator-fixed-supply = "vwl1271";
+			regulator-fixed-microvolts = <1800000>;
+			regulator-fixed-gpio = <43>;
+			regulator-fixed-startup-delay = <70000>;
+			regulator-fixed-enable-high;
+			regulator-fixed-enabled-at-boot;
+		};
+
+		vaux2: regulator at 0 {
+			compatible = "ti,twl6030-vaux2","ti,twl6030";
+			regulator-min-uV = <1200000>;
+			regulator-max-uV = <2800000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vaux3: regulator at 1 {
+			compatible = "ti,twl6030-vaux3","ti,twl6030";
+			regulator-min-uV = <1000000>;
+			regulator-max-uV = <3000000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vmmc: regulator at 2 {
+			compatible = "ti,twl6030-vmmc","ti,twl6030";
+			regulator-min-uV = <1200000>;
+			regulator-max-uV = <3000000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
+
+		vpp: regulator at 3 {
+			compatible = "ti,twl6030-vpp","ti,twl6030";
+			regulator-min-uV = <1800000>;
+			regulator-max-uV = <2500000>;
+			regulator-mode-normal;
+			regulator-mode-standby;
+			regulator-change-mode;
+			regulator-change-status;
+			regulator-change-voltage;
+		};
 	};
 };
 
-- 
1.7.1

[PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:51

Device nodes in DT can associate themselves with one or more
regulators by providing a list of phandles (to regulator nodes)
and corresponding supply names.

For Example:
	devicenode: node at 0x0 {
		...
		...
		vmmc-supply = <&regulator1>;
		vpll-supply = <&regulator1>;
	};

The driver would then do a regulator_get(dev, "vmmc"); to get
regulator1 and do a regulator_get(dev, "vpll"); to get
regulator2.

of_get_regulator() extracts the regulator node for a given
device, based on the supply name.

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/of_regulator.c       |   39 ++++++++++++++++++++++++++++++++
 include/linux/regulator/of_regulator.h |    7 +++++
 2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 7fa63ff..49dd105 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -14,6 +14,45 @@
 #include <linux/of.h>
 #include <linux/regulator/machine.h>
 
+
+/**
+ * of_get_regulator - get a regulator device node based on supply name
+ * @dev: Device pointer for the consumer (of regulator) device
+ * @supply: regulator supply name
+ *
+ * Extract the regulator device node corresponding to the supply name.
+ * retruns the device node corresponding to the regulator if found, else
+ * returns NULL.
+ */
+struct device_node *of_get_regulator(struct device *dev, const char *supply)
+{
+	struct device_node *regnode = NULL;
+	u32 reghandle;
+	char prop_name[32]; /* 32 is max size of property name */
+	const void *prop;
+	int sz;
+
+	if (!dev)
+		return NULL;
+
+	dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);
+
+	snprintf(prop_name, 32, "%s-supply", supply);
+
+	prop = of_get_property(dev->of_node, prop_name, &sz);
+	if (!prop || sz < 4)
+		return NULL;
+
+	reghandle = be32_to_cpup(prop);
+	regnode = of_find_node_by_phandle(reghandle);
+	if (!regnode) {
+		pr_warn("%s: %s property in node %s references invalid phandle",
+			__func__, prop_name, dev->of_node->full_name);
+		return NULL;
+	}
+	return regnode;
+}
+
 static void of_get_regulation_constraints(struct device_node *np,
 					struct regulator_init_data **init_data)
 {
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index 3f63be9..edaba1a 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -9,12 +9,19 @@
 #if defined(CONFIG_OF_REGULATOR)
 extern struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev);
+extern struct device_node *of_get_regulator(struct device *dev,
+	const char *supply);
 #else
 static inline struct regulator_init_data
 	*of_get_regulator_init_data(struct device_node *np)
 {
 	return NULL;
 }
+static inline struct device_node *of_get_regulator(struct device *dev,
+	const char *id)
+{
+	return NULL;
+}
 #endif /* CONFIG_OF_REGULATOR */
 
 #endif /* __LINUX_OF_REG_H */
-- 
1.7.1

[PATCH 9/9] regulator: map consumer regulator based on device tree

From: Rajendra Nayak <hidden>
Date: 2011-09-27 10:12:52

Look up the regulator for a given consumer from device tree, during
a regulator_get(). If not found fallback and lookup through
the regulator_map_list instead.

Devices can associate with one or more regulators by providing a
list of phandles and supply names.

For Example:
        devicenode: node at 0x0 {
                ...
                ...
                vmmc-supply = <&regulator1>;
                vpll-supply = <&regulator2>;
        };

When a device driver calls a regulator_get, specifying the
supply name, the phandle and eventually the regulator node
is extracted from the device node.

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/core.c         |   14 ++++++++++++++
 include/linux/regulator/driver.h |    3 +++
 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d8e6a42..47b851c 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -25,9 +25,11 @@
 #include <linux/mutex.h>
 #include <linux/suspend.h>
 #include <linux/delay.h>
+#include <linux/of.h>
 #include <linux/regulator/consumer.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/regulator.h>
@@ -1155,6 +1157,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 	struct regulator_map *map;
 	struct regulator *regulator = ERR_PTR(-ENODEV);
 	const char *devname = NULL;
+	struct device_node *node;
 	int ret;
 
 	if (id == NULL) {
@@ -1167,6 +1170,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 
 	mutex_lock(&regulator_list_mutex);
 
+	if (dev->of_node) {
+		node = of_get_regulator(dev, id);
+		if (!node)
+			goto retry; /* fallback and chk regulator_map_list */
+		list_for_each_entry(rdev, &regulator_list, list)
+			if (node == rdev->node)
+				goto found;
+	}
+retry:
 	list_for_each_entry(map, &regulator_map_list, list) {
 		/* If the mapping has a device set up it must match */
 		if (map->dev_name &&
@@ -2619,6 +2631,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
 	rdev->reg_data = driver_data;
 	rdev->owner = regulator_desc->owner;
 	rdev->desc = regulator_desc;
+	if (dev && dev->of_node)
+		rdev->node = dev->of_node;
 	INIT_LIST_HEAD(&rdev->consumer_list);
 	INIT_LIST_HEAD(&rdev->list);
 	BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 1a80bc7..4aebbf5 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -196,6 +196,9 @@ struct regulator_dev {
 	struct mutex mutex; /* consumer lock */
 	struct module *owner;
 	struct device dev;
+#ifdef CONFIG_OF
+	struct device_node *node;
+#endif
 	struct regulation_constraints *constraints;
 	struct regulator *supply;	/* for tree */
 
-- 
1.7.1

Re: [PATCH 1/9] regulator: twl: Remove hardcoded board constraints from driver

From: Mark Brown <hidden>
Date: 2011-09-27 11:37:19

On Tue, Sep 27, 2011 at 03:42:44PM +0530, Rajendra Nayak wrote:
Remove the hardcoded .valid_modes_mask and .valid_ops_mask for
each regulator from the twl driver and let the boards pass it.

Signed-off-by: Rajendra Nayak <redacted>
-	/* Constrain board-specific capabilities according to what
-	 * this driver and the chip itself can actually do.
-	 */
-	c = &initdata->constraints;
-	c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
-	c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
-				| REGULATOR_CHANGE_MODE
-				| REGULATOR_CHANGE_STATUS;
This isn't actually hard coding constraints, this is restricting the
constraints passed in further rather than adding new ones.

However should be fine:

Acked-by: Mark Brown <redacted>

Re: [PATCH 2/9] regulator: helper routine to extract regulator_init_data

From: Mark Brown <hidden>
Date: 2011-09-27 12:10:04

On Tue, Sep 27, 2011 at 03:42:45PM +0530, Rajendra Nayak wrote:
+	init_data = devm_kzalloc(dev, sizeof(struct regulator_init_data),
+						 GFP_KERNEL);
+	if (!init_data)
+		return NULL; /* Out of memory? */
This means that the init data will be kept around for the entire
lifetime of the device rather than being discarded.
+	init_data->supply_regulator = (char *)of_get_property(dev->of_node,
+						"regulator-supplies", NULL);
I'd expect that in the device tree world the supply regulator would
reference the node for that regulator.
 	/* voltage output range (inclusive) - for voltage control */
-	int min_uV;
-	int max_uV;
+	u32 min_uV;
+	u32 max_uV;
 
-	int uV_offset;
+	u32 uV_offset;
 
 	/* current output range (inclusive) - for current control */
-	int min_uA;
-	int max_uA;
+	u32 min_uA;
+	u32 max_uA;
Hrm, I think loosing the signs here is bad karma - negative voltages do
exist after all.

Re: [PATCH 4/9] regulator: twl: Make twl-regulator driver extract data from DT

From: Mark Brown <hidden>
Date: 2011-09-27 12:14:15

On Tue, Sep 27, 2011 at 03:42:47PM +0530, Rajendra Nayak wrote:
+#ifdef CONFIG_OF
+	char			compatible[128];
+#endif
Might it not be better to just make this a pointer to const char?

Re: [PATCH 5/9] regulator: helper routine to extract fixed_voltage_config

From: Mark Brown <hidden>
Date: 2011-09-27 12:16:22

On Tue, Sep 27, 2011 at 03:42:48PM +0530, Rajendra Nayak wrote:
The helper routine of_get_fixed_voltage_config() extracts
fixed_voltage_config structure contents from device tree.

Also add documenation for additional bindings for fixed
regulators that can be passed through dt.
Why not just add device tree support into the driver directly?
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supply
This is going to be confusing with respect to the generic regulator
supply property.
+- regulator-fixed-enable-high: Polarity of enable GPIO, 1 = Active High, 0 = Active low
Word wrap for legibility please.

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Mark Brown <hidden>
Date: 2011-09-27 12:21:55

On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
+	if (!dev)
+		return NULL;
So how do we handle CPUs?  cpufreq is one of the most active users of
regulators...
+	snprintf(prop_name, 32, "%s-supply", supply);
+
+	prop = of_get_property(dev->of_node, prop_name, &sz);
+	if (!prop || sz < 4)
+		return NULL;
sz < 4?  Magic!  :)
+extern struct device_node *of_get_regulator(struct device *dev,
+	const char *supply);
This shouldn't be part of the public API, it should be transparently
handled within the core.

Re: [PATCH 9/9] regulator: map consumer regulator based on device tree

From: Mark Brown <hidden>
Date: 2011-09-27 12:23:57

On Tue, Sep 27, 2011 at 03:42:52PM +0530, Rajendra Nayak wrote:
Look up the regulator for a given consumer from device tree, during
a regulator_get(). If not found fallback and lookup through
the regulator_map_list instead.
As with the fixed voltage regulator patch just use the code along with
adding it, no need to split it just makes it harder to review.
+	if (dev->of_node) {
+		node = of_get_regulator(dev, id);
+		if (!node)
+			goto retry; /* fallback and chk regulator_map_list */
+		list_for_each_entry(rdev, &regulator_list, list)
+			if (node == rdev->node)
+				goto found;
+	}
+retry:
retry is a confusing name for the target, we don't ever actually retry
using it.  Given the simplicity of the code I'd be inclined to just
intert the if (!node) check.

Re: [PATCH 1/9] regulator: twl: Remove hardcoded board constraints from driver

From: Rajendra Nayak <hidden>
Date: 2011-09-27 14:47:28

On Tuesday 27 September 2011 05:07 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:44PM +0530, Rajendra Nayak wrote:
quoted
Remove the hardcoded .valid_modes_mask and .valid_ops_mask for
each regulator from the twl driver and let the boards pass it.

Signed-off-by: Rajendra Nayak<redacted>
quoted
-	/* Constrain board-specific capabilities according to what
-	 * this driver and the chip itself can actually do.
-	 */
-	c =&initdata->constraints;
-	c->valid_modes_mask&= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
-	c->valid_ops_mask&= REGULATOR_CHANGE_VOLTAGE
-				| REGULATOR_CHANGE_MODE
-				| REGULATOR_CHANGE_STATUS;
This isn't actually hard coding constraints, this is restricting the
constraints passed in further rather than adding new ones.

However should be fine:

Acked-by: Mark Brown<redacted>
Thanks.

Re: [PATCH 2/9] regulator: helper routine to extract regulator_init_data

From: Rajendra Nayak <hidden>
Date: 2011-09-27 14:48:04

On Tuesday 27 September 2011 05:40 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:45PM +0530, Rajendra Nayak wrote:
quoted
+	init_data = devm_kzalloc(dev, sizeof(struct regulator_init_data),
+						 GFP_KERNEL);
+	if (!init_data)
+		return NULL; /* Out of memory? */
This means that the init data will be kept around for the entire
lifetime of the device rather than being discarded.
Wasn't it the same while this was passed around as platform_data?
quoted
+	init_data->supply_regulator = (char *)of_get_property(dev->of_node,
+						"regulator-supplies", NULL);
I'd expect that in the device tree world the supply regulator would
reference the node for that regulator.
You mean using phandles? Thats what Grant proposed too but
I thought you instead had an inclination towards names? Or maybe
I misunderstood.
quoted
  	/* voltage output range (inclusive) - for voltage control */
-	int min_uV;
-	int max_uV;
+	u32 min_uV;
+	u32 max_uV;

-	int uV_offset;
+	u32 uV_offset;

  	/* current output range (inclusive) - for current control */
-	int min_uA;
-	int max_uA;
+	u32 min_uA;
+	u32 max_uA;
Hrm, I think loosing the signs here is bad karma - negative voltages do
exist after all.
Oops.. they do? didn't know about that.

Re: [PATCH 4/9] regulator: twl: Make twl-regulator driver extract data from DT

From: Rajendra Nayak <hidden>
Date: 2011-09-27 14:48:27

On Tuesday 27 September 2011 05:44 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:47PM +0530, Rajendra Nayak wrote:
quoted
+#ifdef CONFIG_OF
+	char			compatible[128];
+#endif
Might it not be better to just make this a pointer to const char?
Yes, my bad.

Re: [PATCH 5/9] regulator: helper routine to extract fixed_voltage_config

From: Rajendra Nayak <hidden>
Date: 2011-09-27 14:49:00

On Tuesday 27 September 2011 05:46 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:48PM +0530, Rajendra Nayak wrote:
quoted
The helper routine of_get_fixed_voltage_config() extracts
fixed_voltage_config structure contents from device tree.

Also add documenation for additional bindings for fixed
regulators that can be passed through dt.
Why not just add device tree support into the driver directly?
Ok, will do.
quoted
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supply
This is going to be confusing with respect to the generic regulator
supply property.
Yes, I guess. Any suggestions on how to make it less
confusing? :-)
quoted
+- regulator-fixed-enable-high: Polarity of enable GPIO, 1 = Active High, 0 = Active low
Word wrap for legibility please.
Ok.

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Rajendra Nayak <hidden>
Date: 2011-09-27 14:49:37

On Tuesday 27 September 2011 05:51 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
quoted
+	if (!dev)
+		return NULL;
So how do we handle CPUs?  cpufreq is one of the most active users of
regulators...
Hmm, never thought of it :(
Maybe I should associate a supply name with all
regulators and then lookup from the global registered
list.
quoted
+	snprintf(prop_name, 32, "%s-supply", supply);
+
+	prop = of_get_property(dev->of_node, prop_name,&sz);
+	if (!prop || sz<  4)
+		return NULL;
sz<  4?  Magic!  :)
Its the valid phandle size.
I guess I need a sz != 4
quoted
+extern struct device_node *of_get_regulator(struct device *dev,
+	const char *supply);
This shouldn't be part of the public API, it should be transparently
handled within the core.
agreed.

Re: [PATCH 9/9] regulator: map consumer regulator based on device tree

From: Rajendra Nayak <hidden>
Date: 2011-09-27 14:49:45

On Tuesday 27 September 2011 05:53 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:52PM +0530, Rajendra Nayak wrote:
quoted
Look up the regulator for a given consumer from device tree, during
a regulator_get(). If not found fallback and lookup through
the regulator_map_list instead.
As with the fixed voltage regulator patch just use the code along with
adding it, no need to split it just makes it harder to review.
Ok.
quoted
+	if (dev->of_node) {
+		node = of_get_regulator(dev, id);
+		if (!node)
+			goto retry; /* fallback and chk regulator_map_list */
+		list_for_each_entry(rdev,&regulator_list, list)
+			if (node == rdev->node)
+				goto found;
+	}
+retry:
retry is a confusing name for the target, we don't ever actually retry
using it.  Given the simplicity of the code I'd be inclined to just
intert the if (!node) check.
Ok.

Re: [PATCH 5/9] regulator: helper routine to extract fixed_voltage_config

From: Mark Brown <hidden>
Date: 2011-09-27 16:13:27

On Tue, Sep 27, 2011 at 08:19:00PM +0530, Rajendra Nayak wrote:
On Tuesday 27 September 2011 05:46 PM, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 03:42:48PM +0530, Rajendra Nayak wrote:
quoted
quoted
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supply
quoted
This is going to be confusing with respect to the generic regulator
supply property.
Yes, I guess. Any suggestions on how to make it less
confusing? :-)
Call it display-name or something?

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Mark Brown <hidden>
Date: 2011-09-27 18:59:13

On Tue, Sep 27, 2011 at 08:19:37PM +0530, Rajendra Nayak wrote:
On Tuesday 27 September 2011 05:51 PM, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
quoted
quoted
+	if (!dev)
+		return NULL;
quoted
So how do we handle CPUs?  cpufreq is one of the most active users of
regulators...
Hmm, never thought of it :(
Maybe I should associate a supply name with all
regulators and then lookup from the global registered
list.
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it.  The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
quoted
quoted
+	snprintf(prop_name, 32, "%s-supply", supply);
+
+	prop = of_get_property(dev->of_node, prop_name,&sz);
+	if (!prop || sz<  4)
+		return NULL;
quoted
sz<  4?  Magic!  :)
Its the valid phandle size.
I guess I need a sz != 4
I think we need an of_get_phandle(), it'd be clearer what the check is,
more type safe and would avoid needing to replicate the check.

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Cousson, Benoit <hidden>
Date: 2011-09-28 08:09:30

On 9/27/2011 8:59 PM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 08:19:37PM +0530, Rajendra Nayak wrote:
quoted
On Tuesday 27 September 2011 05:51 PM, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
quoted
quoted
quoted
+	if (!dev)
+		return NULL;
quoted
quoted
So how do we handle CPUs?  cpufreq is one of the most active users of
regulators...
quoted
Hmm, never thought of it :(
Maybe I should associate a supply name with all
regulators and then lookup from the global registered
list.
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it.  The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
That's why we do have a MPU node in OMAP dts, in order to build an 
omap_device that will be mainly used for the DVFS on the MPU.

And even before DT migration, we used to build statically some 
omap_device to represent the various processors in the system (MPU, DSP, 
CortexM3...).

Regards,
Benoit

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Rajendra Nayak <hidden>
Date: 2011-09-28 08:18:41

On Wednesday 28 September 2011 01:39 PM, Cousson, Benoit wrote:
On 9/27/2011 8:59 PM, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 08:19:37PM +0530, Rajendra Nayak wrote:
quoted
On Tuesday 27 September 2011 05:51 PM, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
quoted
quoted
quoted
+ if (!dev)
+ return NULL;
quoted
quoted
So how do we handle CPUs? cpufreq is one of the most active users of
regulators...
quoted
Hmm, never thought of it :(
Maybe I should associate a supply name with all
regulators and then lookup from the global registered
list.
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it. The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
That's why we do have a MPU node in OMAP dts, in order to build an
omap_device that will be mainly used for the DVFS on the MPU.

And even before DT migration, we used to build statically some
omap_device to represent the various processors in the system (MPU, DSP,
CortexM3...).
yes, but clearly not everyone seems to do this. and then there are
also these instances of board files requesting regulators without
associating them with any device :(
Regards,
Benoit

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Rajendra Nayak <hidden>
Date: 2011-09-28 10:56:46

On Wednesday 28 September 2011 12:29 AM, Mark Brown wrote:
On Tue, Sep 27, 2011 at 08:19:37PM +0530, Rajendra Nayak wrote:
quoted
On Tuesday 27 September 2011 05:51 PM, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
quoted
quoted
quoted
+	if (!dev)
+		return NULL;
quoted
quoted
So how do we handle CPUs?  cpufreq is one of the most active users of
regulators...
quoted
Hmm, never thought of it :(
Maybe I should associate a supply name with all
regulators and then lookup from the global registered
list.
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it.  The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
quoted
quoted
quoted
+	snprintf(prop_name, 32, "%s-supply", supply);
+
+	prop = of_get_property(dev->of_node, prop_name,&sz);
+	if (!prop || sz<   4)
+		return NULL;
quoted
quoted
sz<   4?  Magic!  :)
quoted
Its the valid phandle size.
I guess I need a sz != 4
I think we need an of_get_phandle(), it'd be clearer what the check is,
more type safe and would avoid needing to replicate the check.
Yes, there already seems to be one, of_parse_phandle() which I should
have used. thanks.

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Mark Brown <hidden>
Date: 2011-09-28 12:26:28

On Wed, Sep 28, 2011 at 10:09:30AM +0200, Cousson, Benoit wrote:
On 9/27/2011 8:59 PM, Mark Brown wrote:
quoted
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it.  The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
That's why we do have a MPU node in OMAP dts, in order to build an
omap_device that will be mainly used for the DVFS on the MPU.
And even before DT migration, we used to build statically some
omap_device to represent the various processors in the system (MPU,
DSP, CortexM3...).
Yeah, but that's very OMAP specific - we don't have that in general (in
fact it's the only Linux platform I'm aware of that has a device for the
CPU).

Re: [PATCH 6/9] regulator: make fixed regulator driver extract data from dt

From: Grant Likely <hidden>
Date: 2011-09-30 01:34:21

On Tue, Sep 27, 2011 at 03:42:49PM +0530, Rajendra Nayak wrote:
quoted hunk
Modify the fixed regulator driver to extract fixed_voltage_config from
device tree when passed, instead of getting it through platform_data
structures (on non-DT builds)

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/fixed.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index c09f791..0a9a10d 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -140,10 +140,15 @@ static struct regulator_ops fixed_voltage_ops = {
 
 static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
 {
-	struct fixed_voltage_config *config = pdev->dev.platform_data;
+	struct fixed_voltage_config *config;
This line doesn't actually need to change; just override it below if
the of_node is present.
quoted hunk
 	struct fixed_voltage_data *drvdata;
 	int ret;
 
+	if (pdev->dev.of_node)
+		config = of_get_fixed_voltage_config(&pdev->dev);
+	else
+		config = pdev->dev.platform_data;
+
 	drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
 	if (drvdata == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate device data\n");
@@ -252,12 +257,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id fixed_of_match[] __devinitconst = {
+	{ .compatible = "regulator-fixed", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, fixed_of_match);
+#else
+#define fixed_of_match NULL
+#endif
+
 static struct platform_driver regulator_fixed_voltage_driver = {
 	.probe		= reg_fixed_voltage_probe,
 	.remove		= __devexit_p(reg_fixed_voltage_remove),
 	.driver		= {
 		.name		= "reg-fixed-voltage",
 		.owner		= THIS_MODULE,
+		.of_match_table = fixed_of_match,
 	},
 };
 
-- 
1.7.1

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Grant Likely <hidden>
Date: 2011-09-30 01:36:49

On Tue, Sep 27, 2011 at 03:42:51PM +0530, Rajendra Nayak wrote:
quoted hunk
Device nodes in DT can associate themselves with one or more
regulators by providing a list of phandles (to regulator nodes)
and corresponding supply names.

For Example:
	devicenode: node at 0x0 {
		...
		...
		vmmc-supply = <&regulator1>;
		vpll-supply = <&regulator1>;
	};

The driver would then do a regulator_get(dev, "vmmc"); to get
regulator1 and do a regulator_get(dev, "vpll"); to get
regulator2.

of_get_regulator() extracts the regulator node for a given
device, based on the supply name.

Signed-off-by: Rajendra Nayak <redacted>
---
 drivers/regulator/of_regulator.c       |   39 ++++++++++++++++++++++++++++++++
 include/linux/regulator/of_regulator.h |    7 +++++
 2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 7fa63ff..49dd105 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -14,6 +14,45 @@
 #include <linux/of.h>
 #include <linux/regulator/machine.h>
 
+
+/**
+ * of_get_regulator - get a regulator device node based on supply name
+ * @dev: Device pointer for the consumer (of regulator) device
+ * @supply: regulator supply name
+ *
+ * Extract the regulator device node corresponding to the supply name.
+ * retruns the device node corresponding to the regulator if found, else
+ * returns NULL.
+ */
+struct device_node *of_get_regulator(struct device *dev, const char *supply)
+{
+	struct device_node *regnode = NULL;
+	u32 reghandle;
+	char prop_name[32]; /* 32 is max size of property name */
+	const void *prop;
+	int sz;
+
+	if (!dev)
+		return NULL;
+
+	dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);
+
+	snprintf(prop_name, 32, "%s-supply", supply);
+
+	prop = of_get_property(dev->of_node, prop_name, &sz);
+	if (!prop || sz < 4)
+		return NULL;
+
+	reghandle = be32_to_cpup(prop);
+	regnode = of_find_node_by_phandle(reghandle);
of_parse_phandle()
quoted hunk
+	if (!regnode) {
+		pr_warn("%s: %s property in node %s references invalid phandle",
+			__func__, prop_name, dev->of_node->full_name);
+		return NULL;
+	}
+	return regnode;
+}
+
 static void of_get_regulation_constraints(struct device_node *np,
 					struct regulator_init_data **init_data)
 {
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index 3f63be9..edaba1a 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -9,12 +9,19 @@
 #if defined(CONFIG_OF_REGULATOR)
 extern struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev);
+extern struct device_node *of_get_regulator(struct device *dev,
+	const char *supply);
 #else
 static inline struct regulator_init_data
 	*of_get_regulator_init_data(struct device_node *np)
 {
 	return NULL;
 }
+static inline struct device_node *of_get_regulator(struct device *dev,
+	const char *id)
+{
+	return NULL;
+}
 #endif /* CONFIG_OF_REGULATOR */
 
 #endif /* __LINUX_OF_REG_H */
-- 
1.7.1

Re: [PATCH 0/9] Device tree support for regulators

From: Grant Likely <hidden>
Date: 2011-09-30 01:39:05

On Tue, Sep 27, 2011 at 03:42:43PM +0530, Rajendra Nayak wrote:
Hi Mark, Grant,

This is a respin of my RFC series I posted sometime back
and is now based on top of the latest omap i2c-twl support
series posted by Benoit
git://gitorious.org/omap-pm/linux.git for_3.2/4_omap_dt_i2c_twl

some changes done since the RFC:
1. twl driver fixed to remove hardcoded board params
2. regulator helpers moved from drivers/of to drivers/regulator
3. Better compatible definitions for specific device type
4. twl regulator driver doing internal table lookup based on
compatible rather then pdev->id
5. Seperate fixed voltage regulator bindings defined
6. Changed the way devices associate with regulators
i.e using <name>-supply = <&regulator-phandle>;
Overall looks fairly good other than the comments made by Mark and myself.

g.

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Rajendra Nayak <hidden>
Date: 2011-09-30 09:34:45

On Wednesday 28 September 2011 05:56 PM, Mark Brown wrote:
On Wed, Sep 28, 2011 at 10:09:30AM +0200, Cousson, Benoit wrote:
quoted
On 9/27/2011 8:59 PM, Mark Brown wrote:
quoted
quoted
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it.  The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
quoted
That's why we do have a MPU node in OMAP dts, in order to build an
omap_device that will be mainly used for the DVFS on the MPU.
quoted
And even before DT migration, we used to build statically some
omap_device to represent the various processors in the system (MPU,
DSP, CortexM3...).
Yeah, but that's very OMAP specific - we don't have that in general (in
fact it's the only Linux platform I'm aware of that has a device for the
CPU).
But isn't this the right thing to do for everyone else too?

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Mark Brown <hidden>
Date: 2011-09-30 10:35:50

On Fri, Sep 30, 2011 at 03:04:45PM +0530, Rajendra Nayak wrote:
On Wednesday 28 September 2011 05:56 PM, Mark Brown wrote:
quoted
On Wed, Sep 28, 2011 at 10:09:30AM +0200, Cousson, Benoit wrote:
quoted
quoted
And even before DT migration, we used to build statically some
omap_device to represent the various processors in the system (MPU,
DSP, CortexM3...).
quoted
Yeah, but that's very OMAP specific - we don't have that in general (in
fact it's the only Linux platform I'm aware of that has a device for the
CPU).
But isn't this the right thing to do for everyone else too?
That doesn't really matter so long as nobody else is actually doing it;
you can't make a decision like this in an OMAP-specific fashion, you
need to make sure everyone else is on board with the decision and make
sure we've got at least at a high level way of representing the CPUs and
SoCs in the device tree that people can buy into.

Re: [PATCH 8/9] regulator: helper to extract regulator node based on supply name

From: Grant Likely <hidden>
Date: 2011-10-04 17:00:42

On Fri, Sep 30, 2011 at 03:04:45PM +0530, Rajendra Nayak wrote:
On Wednesday 28 September 2011 05:56 PM, Mark Brown wrote:
quoted
On Wed, Sep 28, 2011 at 10:09:30AM +0200, Cousson, Benoit wrote:
quoted
On 9/27/2011 8:59 PM, Mark Brown wrote:
quoted
quoted
I'm not sure how this should work in a device tree world, I'd *hope*
we'd get a device tree node for the CPU and could then just make this a
regular consumer thing but then the cpufreq drivers would need to be
updated to make use of it.  The only reason we allow null devices right
now is the fact that cpufreq doesn't have a struct device it can use.
quoted
That's why we do have a MPU node in OMAP dts, in order to build an
omap_device that will be mainly used for the DVFS on the MPU.
quoted
And even before DT migration, we used to build statically some
omap_device to represent the various processors in the system (MPU,
DSP, CortexM3...).
Yeah, but that's very OMAP specific - we don't have that in general (in
fact it's the only Linux platform I'm aware of that has a device for the
CPU).
But isn't this the right thing to do for everyone else too?
It is normal to have nodes for each CPU.  The /cpus/ node normally
contains cpu@* nodes for each logical cpu core, and I would expect
nodes for each additional DSP and MPU core.  Whether or not they
belong in the /cpus/ node is a matter of design (we don't have any
patterns for that yet).

g.

Re: [PATCH 2/9] regulator: helper routine to extract regulator_init_data

From: Russell King - ARM Linux <hidden>
Date: 2011-10-04 23:01:27

On Tue, Sep 27, 2011 at 01:10:04PM +0100, Mark Brown wrote:
On Tue, Sep 27, 2011 at 03:42:45PM +0530, Rajendra Nayak wrote:
quoted
+	init_data = devm_kzalloc(dev, sizeof(struct regulator_init_data),
+						 GFP_KERNEL);
+	if (!init_data)
+		return NULL; /* Out of memory? */
This means that the init data will be kept around for the entire
lifetime of the device rather than being discarded.
May I remind you that devm_* lifetime expires whenever the associated
driver is unbound, which can be much shorter than the lifetime of the
struct device.

It expires when any of the following occurs:
1. userspace asks the associated driver to be unbound
2. the driver is removed
3. any driver probe for this struct device fails
4. the struct device is unregistered.

So: don't use devm_* for anything other than stuff inside a driver being
associated with the struct device itself.  Other uses are a bug waiting
to happen.

Re: [PATCH 2/9] regulator: helper routine to extract regulator_init_data

From: Grant Likely <hidden>
Date: 2011-10-04 23:48:05

On Wed, Oct 05, 2011 at 12:01:27AM +0100, Russell King - ARM Linux wrote:
On Tue, Sep 27, 2011 at 01:10:04PM +0100, Mark Brown wrote:
quoted
On Tue, Sep 27, 2011 at 03:42:45PM +0530, Rajendra Nayak wrote:
quoted
+	init_data = devm_kzalloc(dev, sizeof(struct regulator_init_data),
+						 GFP_KERNEL);
+	if (!init_data)
+		return NULL; /* Out of memory? */
This means that the init data will be kept around for the entire
lifetime of the device rather than being discarded.
May I remind you that devm_* lifetime expires whenever the associated
driver is unbound, which can be much shorter than the lifetime of the
struct device.

It expires when any of the following occurs:
1. userspace asks the associated driver to be unbound
2. the driver is removed
3. any driver probe for this struct device fails
4. the struct device is unregistered.

So: don't use devm_* for anything other than stuff inside a driver being
associated with the struct device itself.  Other uses are a bug waiting
to happen.
Yes, Russell is right.  There were a number of places where I
suggested using devm_* in entirely the wrong places.  Double check
anyplace where you've added devm_ calls.

g.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help