Skip to contentSkip to conversation

Add device tree support for mc13892 regulator driver

PATCH New Shawn Guo 5 participants 11 messages Dec 21, 2011 – Dec 30, 2011

Subsystems (4)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

v4 cover Add device tree support for mc13892 regulator driver

Changes since v3:
* The mfd patch in v3 was applied, and it's replaced by a incremental patch to improve the binding document in the new series.
* Add a patch to remove the unnecessary prefix 'MC13892__' from regulator name.
* Adopt the binding and regulator name changes in dts.

Changes since v2:
* Drop '[PATCH v2 2/4] regulator: pass device_node to of_get_regulator_init_data()' which has been picked up by Mark
* Add a note on how driver matches regulator device and the node in binding document

Changes since v1:
* Drop '[PATCH 2/5] regulator: fix label names used in device tree bindings' which has been picked up
* Add binding document for mfd/mc13xxx-core device tree support
* Fix regulator/fixed.c breakage caused by interface change on of_get_regulator_init_data()
* Reword the commit message of patch #2 a little bit to make the reason for changing clear
* Retrieve the irq from gpio irq domain

Shawn Guo (4):
mfd: improve mc13xxx dt binding document
regulator: mc13892: remove the unnecessary prefix from regulator name
regulator: mc13892: add device tree probe support arm/imx: add mc13892 support into imx51-babbage.dts

 Documentation/devicetree/bindings/mfd/mc13xxx.txt |   31 ++++++-
 arch/arm/boot/dts/imx51-babbage.dts               |   93 ++++++++++++++++++++-
 drivers/regulator/mc13892-regulator.c             |   43 +++++++---
 drivers/regulator/mc13xxx-regulator-core.c        |   57 +++++++++++++
 drivers/regulator/mc13xxx.h                       |   26 +++++-
 include/linux/mfd/mc13xxx.h                       |    1 +
 6 files changed, 232 insertions(+), 19 deletions(-)
author
#1 lore raw

PATCH v4 1/4 mfd: improve mc13xxx dt binding document

It improves mc13xxx dt binding document on how the regulator name is being used for binding a mc13892 regulator device.

Cc Samuel Ortiz <[email protected]>
---
 Documentation/devicetree/bindings/mfd/mc13xxx.txt |   31 +++++++++++++++++++--
 1 files changed, 28 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/mfd/mc13xxx.txt +28 -3
index 4ed46a61..19f6af4 100644
@@ -10,9 +10,34 @@ Optional properties:
 - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used
 
 Sub-nodes:
-- regulators : Contain the regulator nodes.  The name of regulator node
-  is being used by mc13xxx regulator driver to find the correct relator
-  device.
+- regulators : Contain the regulator nodes.  The MC13892 regulators are
+  bound using their names as listed below with their registers and bits
+  for enabling.
+
+    vcoincell : regulator VCOINCELL (register 13, bit 23)
+    sw1       : regulator SW1	    (register 24, bit 0)
+    sw2       : regulator SW2	    (register 25, bit 0)
+    sw3       : regulator SW3	    (register 26, bit 0)
+    sw4       : regulator SW4	    (register 27, bit 0)
+    swbst     : regulator SWBST	    (register 29, bit 20)
+    vgen1     : regulator VGEN1	    (register 32, bit 0)
+    viohi     : regulator VIOHI	    (register 32, bit 3)
+    vdig      : regulator VDIG	    (register 32, bit 9)
+    vgen2     : regulator VGEN2	    (register 32, bit 12)
+    vpll      : regulator VPLL	    (register 32, bit 15)
+    vusb2     : regulator VUSB2	    (register 32, bit 18)
+    vgen3     : regulator VGEN3	    (register 33, bit 0)
+    vcam      : regulator VCAM	    (register 33, bit 6)
+    vvideo    : regulator VVIDEO    (register 33, bit 12)
+    vaudio    : regulator VAUDIO    (register 33, bit 15)
+    vsd       : regulator VSD	    (register 33, bit 18)
+    gpo1      : regulator GPO1	    (register 34, bit 6)
+    gpo2      : regulator GPO2	    (register 34, bit 8)
+    gpo3      : regulator GPO3	    (register 34, bit 10)
+    gpo4      : regulator GPO4	    (register 34, bit 12)
+    pwgt1spi  : regulator PWGT1SPI  (register 34, bit 15)
+    pwgt2spi  : regulator PWGT2SPI  (register 34, bit 16)
+    vusb      : regulator VUSB	    (register 50, bit 3)
 
   The bindings details of individual regulator device can be found in:
   Documentation/devicetree/bindings/regulator/regulator.txt
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 1/4 mfd: improve mc13xxx dt binding document

In reply to Shawn Guo

Hi Shawn,

Quoted 5 lines · Shawn Guo

It improves mc13xxx dt binding document on how the regulator name is being used for binding a mc13892 regulator device.

Cc Samuel Ortiz <[email protected]>

Thanks, patch applied.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
author
#4 lore raw

PATCH v4 2/4 regulator: mc13892: remove the unnecessary prefix from regulator name

In reply to Shawn Guo

It's not really necessary to add a prefix 'MC13892__' for each mc13892 regulator name, since the chip must have been identified as mc13892 when we look at the regulator name.

Cc Mark Brown <[email protected]>
Cc Liam Girdwood <[email protected]>
---
 drivers/regulator/mc13xxx.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/regulator/mc13xxx.h +3 -3
index 2775826..75e3832 100644
@@ -48,7 +48,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
 #define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops)	\
 	[prefix ## _name] = {				\
 		.desc = {						\
-			.name = #prefix "_" #_name,			\
+			.name = #_name,					\
 			.n_voltages = ARRAY_SIZE(_voltages),		\
 			.ops = &_ops,			\
 			.type = REGULATOR_VOLTAGE,			\
@@ -66,7 +66,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
 #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops)	\
 	[prefix ## _name] = {				\
 		.desc = {						\
-			.name = #prefix "_" #_name,			\
+			.name = #_name,					\
 			.n_voltages = ARRAY_SIZE(_voltages),		\
 			.ops = &_ops,		\
 			.type = REGULATOR_VOLTAGE,			\
@@ -81,7 +81,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
 #define MC13xxx_GPO_DEFINE(prefix, _name, _reg,  _voltages, _ops)	\
 	[prefix ## _name] = {				\
 		.desc = {						\
-			.name = #prefix "_" #_name,			\
+			.name = #_name,					\
 			.n_voltages = ARRAY_SIZE(_voltages),		\
 			.ops = &_ops,		\
 			.type = REGULATOR_VOLTAGE,			\
Signature · 1 line
1.7.4.1
Applied
#5 lore raw

PATCH 2/4 regulator: mc13892: remove the unnecessary prefix from regulator name

Quoted 3 lines · Shawn Guo

It's not really necessary to add a prefix 'MC13892__' for each mc13892 regulator name, since the chip must have been identified as mc13892 when we look at the regulator name.

Applied, thanks.

Quoted 5 lines
Cc Mark Brown <[email protected]>
Cc Liam Girdwood <[email protected]>

Think something went wrong with your scripts here... might be worth checking.

#6 lore raw

PATCH 2/4 regulator: mc13892: remove the unnecessary prefix from regulator name

Quoted 7 lines · Mark Brown
Quoted 3 lines · Shawn Guo

It's not really necessary to add a prefix 'MC13892__' for each mc13892 regulator name, since the chip must have been identified as mc13892 when we look at the regulator name.

Applied, thanks.

Quoted 8 lines
Quoted 5 lines
Cc Mark Brown <[email protected]>
Cc Liam Girdwood <[email protected]>

Think something went wrong with your scripts here... might be worth checking.

Yes, something did go wrong there. Thanks for noticing.

Signature · 2 lines
Regards,
Shawn
author
#7 lore raw

PATCH v4 3/4 regulator: mc13892: add device tree probe support

In reply to Shawn Guo

It adds device tree probe support for mc13892-regulator driver.

Cc Mark Brown <[email protected]>
Cc Liam Girdwood <[email protected]>
---
 drivers/regulator/mc13892-regulator.c      |   43 +++++++++++++++-----
 drivers/regulator/mc13xxx-regulator-core.c |   57 ++++++++++++++++++++++++++++
 drivers/regulator/mc13xxx.h                |   20 ++++++++++
 include/linux/mfd/mc13xxx.h                |    1 +
 4 files changed, 110 insertions(+), 11 deletions(-)
drivers/regulator/mc13892-regulator.c +32 -11
index 2824804..46bfa4a 100644
@@ -527,18 +527,27 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
 	struct mc13xxx *mc13892 = dev_get_drvdata(pdev->dev.parent);
 	struct mc13xxx_regulator_platform_data *pdata =
 		dev_get_platdata(&pdev->dev);
-	struct mc13xxx_regulator_init_data *init_data;
+	struct mc13xxx_regulator_init_data *mc13xxx_data;
 	int i, ret;
+	int num_regulators = 0;
 	u32 val;
 
+	num_regulators = mc13xxx_get_num_regulators_dt(pdev);
+	if (num_regulators <= 0 && pdata)
+		num_regulators = pdata->num_regulators;
+	if (num_regulators <= 0)
+		return -EINVAL;
+
 	priv = kzalloc(sizeof(*priv) +
-		pdata->num_regulators * sizeof(priv->regulators[0]),
+		num_regulators * sizeof(priv->regulators[0]),
 		GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
+	priv->num_regulators = num_regulators;
 	priv->mc13xxx_regulators = mc13892_regulators;
 	priv->mc13xxx = mc13892;
+	platform_set_drvdata(pdev, priv);
 
 	mc13xxx_lock(mc13892);
 	ret = mc13xxx_reg_read(mc13892, MC13892_REVISION, &val);
@@ -569,11 +578,27 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
 		= mc13892_vcam_set_mode;
 	mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
 		= mc13892_vcam_get_mode;
-	for (i = 0; i < pdata->num_regulators; i++) {
-		init_data = &pdata->regulators[i];
+
+	mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
+					ARRAY_SIZE(mc13892_regulators));
+	for (i = 0; i < num_regulators; i++) {
+		struct regulator_init_data *init_data;
+		struct regulator_desc *desc;
+		struct device_node *node = NULL;
+		int id;
+
+		if (mc13xxx_data) {
+			id = mc13xxx_data[i].id;
+			init_data = mc13xxx_data[i].init_data;
+			node = mc13xxx_data[i].node;
+		} else {
+			id = pdata->regulators[i].id;
+			init_data = pdata->regulators[i].init_data;
+		}
+		desc = &mc13892_regulators[id].desc;
+
 		priv->regulators[i] = regulator_register(
-			&mc13892_regulators[init_data->id].desc,
-			&pdev->dev, init_data->init_data, priv, NULL);
+			desc, &pdev->dev, init_data, priv, node);
 
 		if (IS_ERR(priv->regulators[i])) {
 			dev_err(&pdev->dev, "failed to register regulator %s\n",
@@ -583,8 +608,6 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
 		}
 	}
 
-	platform_set_drvdata(pdev, priv);
-
 	return 0;
 err:
 	while (--i >= 0)
@@ -600,13 +623,11 @@ err_free:
 static int __devexit mc13892_regulator_remove(struct platform_device *pdev)
 {
 	struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
-	struct mc13xxx_regulator_platform_data *pdata =
-		dev_get_platdata(&pdev->dev);
 	int i;
 
 	platform_set_drvdata(pdev, NULL);
 
-	for (i = 0; i < pdata->num_regulators; i++)
+	for (i = 0; i < priv->num_regulators; i++)
 		regulator_unregister(priv->regulators[i]);
 
 	kfree(priv);
drivers/regulator/mc13xxx-regulator-core.c +57 -0

75 lines not on this page · raw message

drivers/regulator/mc13xxx.h +20 -0
index 75e3832..b3961c6 100644
@@ -29,6 +29,7 @@ struct mc13xxx_regulator_priv {
 	struct mc13xxx *mc13xxx;
 	u32 powermisc_pwgt_state;
 	struct mc13xxx_regulator *mc13xxx_regulators;
+	int num_regulators;
 	struct regulator_dev *regulators[];
 };
 
@@ -42,6 +43,25 @@ extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
 		int min_uV, int max_uV, unsigned *selector);
 extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
 
+#ifdef CONFIG_OF
+extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
+extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
+	struct platform_device *pdev, struct mc13xxx_regulator *regulators,
+	int num_regulators);
+#else
+static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
+{
+	return -ENODEV;
+}
+
+static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
+	struct platform_device *pdev, struct mc13xxx_regulator *regulators,
+	int num_regulators)
+{
+	return NULL;
+}
+#endif
+
 extern struct regulator_ops mc13xxx_regulator_ops;
 extern struct regulator_ops mc13xxx_fixed_regulator_ops;
 
include/linux/mfd/mc13xxx.h +1 -0
index 261fc11..b86ee45 100644
@@ -69,6 +69,7 @@ struct regulator_init_data;
 struct mc13xxx_regulator_init_data {
 	int id;
 	struct regulator_init_data *init_data;
+	struct device_node *node;
 };
 
 struct mc13xxx_regulator_platform_data {
Signature · 1 line
1.7.4.1
Applied
#8 lore raw

PATCH 3/4 regulator: mc13892: add device tree probe support

Quoted 1 line · Shawn Guo

It adds device tree probe support for mc13892-regulator driver.

Applied, thanks.

author
#9 lore raw

PATCH v4 4/4 arm/imx: add mc13892 support into imx51-babbage.dts

In reply to Shawn Guo

It adds mc13892 support into imx51-babbage device tree source.

Cc Sascha Hauer <[email protected]>
---
 arch/arm/boot/dts/imx51-babbage.dts |   93 ++++++++++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 2 deletions(-)
arch/arm/boot/dts/imx51-babbage.dts +91 -2
index 564cb8c..728c9e8 100644
@@ -31,12 +31,14 @@
 				esdhc at 70004000 { /* ESDHC1 */
 					fsl,cd-internal;
 					fsl,wp-internal;
+					vmmc-supply = <&vsd_reg>;
 					status = "okay";
 				};
 
 				esdhc at 70008000 { /* ESDHC2 */
 					cd-gpios = <&gpio1 6 0>;
 					wp-gpios = <&gpio1 5 0>;
+					vmmc-supply = <&vsd_reg>;
 					status = "okay";
 				};
 
@@ -56,8 +58,95 @@
 						compatible = "fsl,mc13892";
 						spi-max-frequency = <6000000>;
 						reg = <0>;
-						mc13xxx-irq-gpios = <&gpio1 8 0>;
-						fsl,mc13xxx-uses-regulator;
+						interrupt-parent = <&gpio1>;
+						interrupts = <8>;
+
+						regulators {
+							sw1_reg: sw1 {
+								regulator-min-microvolt = <600000>;
+								regulator-max-microvolt = <1375000>;
+								regulator-boot-on;
+								regulator-always-on;
+							};
+
+							sw2_reg: sw2 {
+								regulator-min-microvolt = <900000>;
+								regulator-max-microvolt = <1850000>;
+								regulator-boot-on;
+								regulator-always-on;
+							};
+
+							sw3_reg: sw3 {
+								regulator-min-microvolt = <1100000>;
+								regulator-max-microvolt = <1850000>;
+								regulator-boot-on;
+								regulator-always-on;
+							};
+
+							sw4_reg: sw4 {
+								regulator-min-microvolt = <1100000>;
+								regulator-max-microvolt = <1850000>;
+								regulator-boot-on;
+								regulator-always-on;
+							};
+
+							vpll_reg: vpll {
+								regulator-min-microvolt = <1050000>;
+								regulator-max-microvolt = <1800000>;
+								regulator-boot-on;
+								regulator-always-on;
+							};
+
+							vdig_reg: vdig {
+								regulator-min-microvolt = <1650000>;
+								regulator-max-microvolt = <1650000>;
+								regulator-boot-on;
+							};
+
+							vsd_reg: vsd {
+								regulator-min-microvolt = <1800000>;
+								regulator-max-microvolt = <3150000>;
+							};
+
+							vusb2_reg: vusb2 {
+								regulator-min-microvolt = <2400000>;
+								regulator-max-microvolt = <2775000>;
+								regulator-boot-on;
+								regulator-always-on;
+							};
+
+							vvideo_reg: vvideo {
+								regulator-min-microvolt = <2775000>;
+								regulator-max-microvolt = <2775000>;
+							};
+
+							vaudio_reg: vaudio {
+								regulator-min-microvolt = <2300000>;
+								regulator-max-microvolt = <3000000>;
+							};
+
+							vcam_reg: vcam {
+								regulator-min-microvolt = <2500000>;
+								regulator-max-microvolt = <3000000>;
+							};
+
+							vgen1_reg: vgen1 {
+								regulator-min-microvolt = <1200000>;
+								regulator-max-microvolt = <1200000>;
+							};
+
+							vgen2_reg: vgen2 {
+								regulator-min-microvolt = <1200000>;
+								regulator-max-microvolt = <3150000>;
+								regulator-always-on;
+							};
+
+							vgen3_reg: vgen3 {
+								regulator-min-microvolt = <1800000>;
+								regulator-max-microvolt = <2900000>;
+								regulator-always-on;
+							};
+						};
 					};
 
 					flash: at45db321d at 1 {
Signature · 1 line
1.7.4.1
#10 lore raw

PATCH 4/4 arm/imx: add mc13892 support into imx51-babbage.dts

Quoted 28 lines · Shawn Guo

It adds mc13892 support into imx51-babbage device tree source.

Cc Sascha Hauer <[email protected]>
---
 arch/arm/boot/dts/imx51-babbage.dts |   93 ++++++++++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 2 deletions(-)
arch/arm/boot/dts/imx51-babbage.dts +2 -0
index 564cb8c..728c9e8 100644
@@ -31,12 +31,14 @@
 				esdhc at 70004000 { /* ESDHC1 */
 					fsl,cd-internal;
 					fsl,wp-internal;
+					vmmc-supply = <&vsd_reg>;
 					status = "okay";
 				};
 
 				esdhc at 70008000 { /* ESDHC2 */
 					cd-gpios = <&gpio1 6 0>;
 					wp-gpios = <&gpio1 5 0>;
+					vmmc-supply = <&vsd_reg>;
 					status = "okay";
 				};
 

arch/arm/boot/dts/imx51-babbage.dts line 62

Quoted 7 lines
arch/arm/boot/dts/imx51-babbage.dts +2 -2
@@ -56,8 +58,95 @@
 						compatible = "fsl,mc13892";
 						spi-max-frequency = <6000000>;
 						reg = <0>;
-						mc13xxx-irq-gpios = <&gpio1 8 0>;
-						fsl,mc13xxx-uses-regulator;
+						interrupt-parent = <&gpio1>;
+						interrupts = <8>;

Why do we put everything in /soc node? Isn't it suppose to put everything outside SoC outside /soc node?

In my understanding, i2c/spi node in /soc should only describe the bus host controller. Especially i2c is a multi-master bus.

Thanks
Richard

arch/arm/boot/dts/imx51-babbage.dts line 64

Quoted 2 lines
arch/arm/boot/dts/imx51-babbage.dts +2 -0
+
+						regulators {

Thanks
Richard