All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org,
	patches@linaro.org, broonie@opensource.wolfsonmicro.com,
	"Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Shawn Guo <shawn.guo@linaro.org>,
	Ashish Jangam <ashish.jangam@kpitcummins.com>
Subject: [PATCH 1/2] mfd: da9052: add device-tree support for i2c driver
Date: Thu, 12 Apr 2012 23:39:41 +0800	[thread overview]
Message-ID: <1334245182-31725-1-git-send-email-paul.liu@linaro.org> (raw)

From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>

This patch adds device-tree support for dialog MFD and the binding
documentations.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Ashish Jangam <ashish.jangam@kpitcummins.com>
---
 .../devicetree/bindings/mfd/da9052-i2c.txt         |   58 ++++++++++++++++++++
 drivers/mfd/da9052-i2c.c                           |   54 +++++++++++++++---
 2 files changed, 104 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/da9052-i2c.txt

diff --git a/Documentation/devicetree/bindings/mfd/da9052-i2c.txt b/Documentation/devicetree/bindings/mfd/da9052-i2c.txt
new file mode 100644
index 0000000..042d042
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/da9052-i2c.txt
@@ -0,0 +1,58 @@
+* Dialog DA9052/53 Power Management Integrated Circuit (PMIC)
+
+Required properties:
+- compatible : Should be "dialog,da9052", "dialog,da9053-aa",
+			 "dialog,da9053-ab", or "dialog,da9053-bb"
+
+Sub-nodes:
+- regulators : Contain the regulator nodes.  The DA9052 regulators are
+  sorted as following:
+
+    buck_core : regulator BUCK_CORE (id: 0 )
+    buck_pro  : regulator BUCK_PRO  (id: 1 )
+    buck_mem  : regulator BUCK_MEM  (id: 2 )
+    buck_peri : regulator BUCK_PERI (id: 3 )
+    ldo1      : regulator LDO1	    (id: 4 )
+    ldo2      : regulator LDO2	    (id: 5 )
+    ldo3      : regulator LDO3	    (id: 6 )
+    ldo4      : regulator LDO4	    (id: 7 )
+    ldo5      : regulator LDO5	    (id: 8 )
+    ldo6      : regulator LDO6	    (id: 9 )
+    ldo7      : regulator LDO7	    (id: 10)
+    ldo8      : regulator LDO8	    (id: 11)
+    ldo9      : regulator LDO9	    (id: 12)
+    ldo10     : regulator LDO10     (id: 13)
+
+  The bindings details of individual regulator device can be found in:
+  Documentation/devicetree/bindings/regulator/regulator.txt
+
+Examples:
+
+i2c@63fc8000 { /* I2C1 */
+	status = "okay";
+
+	pmic: dialog@48 {
+		compatible = "dialog,da9053-aa";
+		reg = <0x48>;
+
+		regulators {
+			regulator-buck0 {
+				regulator-name = "DA9052_BUCK_CORE";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <2075000>;
+			};
+
+			regulator-buck1 {
+				regulator-name = "DA9052_BUCK_PRO";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <2075000>;
+			};
+
+			regulator-buck2 {
+				regulator-name = "DA9052_BUCK_MEM";
+				regulator-min-microvolt = <925000>;
+				regulator-max-microvolt = <2500000>;
+			};
+		};
+	};
+};
diff --git a/drivers/mfd/da9052-i2c.c b/drivers/mfd/da9052-i2c.c
index 36b88e3..e07bcfa 100644
--- a/drivers/mfd/da9052-i2c.c
+++ b/drivers/mfd/da9052-i2c.c
@@ -22,6 +22,11 @@
 #include <linux/mfd/da9052/da9052.h>
 #include <linux/mfd/da9052/reg.h>
 
+#ifdef CONFIG_OF
+#include <linux/of.h>
+#include <linux/of_device.h>
+#endif
+
 static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
 {
 	int reg_val, ret;
@@ -41,6 +46,24 @@ static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
 	return 0;
 }
 
+static struct i2c_device_id da9052_i2c_id[] = {
+	{"da9052", DA9052},
+	{"da9053-aa", DA9053_AA},
+	{"da9053-ba", DA9053_BA},
+	{"da9053-bb", DA9053_BB},
+	{}
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id dialog_dt_ids[] = {
+	{ .compatible = "dialog,da9052" },
+	{ .compatible = "dialog,da9053-aa" },
+	{ .compatible = "dialog,da9053-ab" },
+	{ .compatible = "dialog,da9053-bb" },
+	{ /* sentinel */ }
+};
+#endif
+
 static int __devinit da9052_i2c_probe(struct i2c_client *client,
 				       const struct i2c_device_id *id)
 {
@@ -76,6 +99,26 @@ static int __devinit da9052_i2c_probe(struct i2c_client *client,
 	if (ret < 0)
 		goto err_regmap;
 
+#ifdef CONFIG_OF
+	if (!id) {
+		int i;
+		struct device_node *np = client->dev.of_node;
+
+		for (i = 0;
+		     i < sizeof(dialog_dt_ids)/sizeof(dialog_dt_ids[0]);
+		     i++)
+			if (of_device_is_compatible(np,
+						dialog_dt_ids[i].compatible))
+				id = &da9052_i2c_id[i];
+	}
+#endif
+
+	if (!id) {
+		ret = -ENODEV;
+		dev_err(&client->dev, "id is null.\n");
+		goto err_regmap;
+	}
+
 	ret = da9052_device_init(da9052, id->driver_data);
 	if (ret != 0)
 		goto err_regmap;
@@ -100,14 +143,6 @@ static int __devexit da9052_i2c_remove(struct i2c_client *client)
 	return 0;
 }
 
-static struct i2c_device_id da9052_i2c_id[] = {
-	{"da9052", DA9052},
-	{"da9053-aa", DA9053_AA},
-	{"da9053-ba", DA9053_BA},
-	{"da9053-bb", DA9053_BB},
-	{}
-};
-
 static struct i2c_driver da9052_i2c_driver = {
 	.probe = da9052_i2c_probe,
 	.remove = __devexit_p(da9052_i2c_remove),
@@ -115,6 +150,9 @@ static struct i2c_driver da9052_i2c_driver = {
 	.driver = {
 		.name = "da9052",
 		.owner = THIS_MODULE,
+#ifdef CONFIG_OF
+		.of_match_table = dialog_dt_ids,
+#endif
 	},
 };
 
-- 
1.7.9.5


WARNING: multiple messages have this Message-ID (diff)
From: paul.liu@linaro.org (Ying-Chun Liu (PaulLiu))
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] mfd: da9052: add device-tree support for i2c driver
Date: Thu, 12 Apr 2012 23:39:41 +0800	[thread overview]
Message-ID: <1334245182-31725-1-git-send-email-paul.liu@linaro.org> (raw)

From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>

This patch adds device-tree support for dialog MFD and the binding
documentations.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Ashish Jangam <ashish.jangam@kpitcummins.com>
---
 .../devicetree/bindings/mfd/da9052-i2c.txt         |   58 ++++++++++++++++++++
 drivers/mfd/da9052-i2c.c                           |   54 +++++++++++++++---
 2 files changed, 104 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/da9052-i2c.txt

diff --git a/Documentation/devicetree/bindings/mfd/da9052-i2c.txt b/Documentation/devicetree/bindings/mfd/da9052-i2c.txt
new file mode 100644
index 0000000..042d042
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/da9052-i2c.txt
@@ -0,0 +1,58 @@
+* Dialog DA9052/53 Power Management Integrated Circuit (PMIC)
+
+Required properties:
+- compatible : Should be "dialog,da9052", "dialog,da9053-aa",
+			 "dialog,da9053-ab", or "dialog,da9053-bb"
+
+Sub-nodes:
+- regulators : Contain the regulator nodes.  The DA9052 regulators are
+  sorted as following:
+
+    buck_core : regulator BUCK_CORE (id: 0 )
+    buck_pro  : regulator BUCK_PRO  (id: 1 )
+    buck_mem  : regulator BUCK_MEM  (id: 2 )
+    buck_peri : regulator BUCK_PERI (id: 3 )
+    ldo1      : regulator LDO1	    (id: 4 )
+    ldo2      : regulator LDO2	    (id: 5 )
+    ldo3      : regulator LDO3	    (id: 6 )
+    ldo4      : regulator LDO4	    (id: 7 )
+    ldo5      : regulator LDO5	    (id: 8 )
+    ldo6      : regulator LDO6	    (id: 9 )
+    ldo7      : regulator LDO7	    (id: 10)
+    ldo8      : regulator LDO8	    (id: 11)
+    ldo9      : regulator LDO9	    (id: 12)
+    ldo10     : regulator LDO10     (id: 13)
+
+  The bindings details of individual regulator device can be found in:
+  Documentation/devicetree/bindings/regulator/regulator.txt
+
+Examples:
+
+i2c at 63fc8000 { /* I2C1 */
+	status = "okay";
+
+	pmic: dialog at 48 {
+		compatible = "dialog,da9053-aa";
+		reg = <0x48>;
+
+		regulators {
+			regulator-buck0 {
+				regulator-name = "DA9052_BUCK_CORE";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <2075000>;
+			};
+
+			regulator-buck1 {
+				regulator-name = "DA9052_BUCK_PRO";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <2075000>;
+			};
+
+			regulator-buck2 {
+				regulator-name = "DA9052_BUCK_MEM";
+				regulator-min-microvolt = <925000>;
+				regulator-max-microvolt = <2500000>;
+			};
+		};
+	};
+};
diff --git a/drivers/mfd/da9052-i2c.c b/drivers/mfd/da9052-i2c.c
index 36b88e3..e07bcfa 100644
--- a/drivers/mfd/da9052-i2c.c
+++ b/drivers/mfd/da9052-i2c.c
@@ -22,6 +22,11 @@
 #include <linux/mfd/da9052/da9052.h>
 #include <linux/mfd/da9052/reg.h>
 
+#ifdef CONFIG_OF
+#include <linux/of.h>
+#include <linux/of_device.h>
+#endif
+
 static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
 {
 	int reg_val, ret;
@@ -41,6 +46,24 @@ static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
 	return 0;
 }
 
+static struct i2c_device_id da9052_i2c_id[] = {
+	{"da9052", DA9052},
+	{"da9053-aa", DA9053_AA},
+	{"da9053-ba", DA9053_BA},
+	{"da9053-bb", DA9053_BB},
+	{}
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id dialog_dt_ids[] = {
+	{ .compatible = "dialog,da9052" },
+	{ .compatible = "dialog,da9053-aa" },
+	{ .compatible = "dialog,da9053-ab" },
+	{ .compatible = "dialog,da9053-bb" },
+	{ /* sentinel */ }
+};
+#endif
+
 static int __devinit da9052_i2c_probe(struct i2c_client *client,
 				       const struct i2c_device_id *id)
 {
@@ -76,6 +99,26 @@ static int __devinit da9052_i2c_probe(struct i2c_client *client,
 	if (ret < 0)
 		goto err_regmap;
 
+#ifdef CONFIG_OF
+	if (!id) {
+		int i;
+		struct device_node *np = client->dev.of_node;
+
+		for (i = 0;
+		     i < sizeof(dialog_dt_ids)/sizeof(dialog_dt_ids[0]);
+		     i++)
+			if (of_device_is_compatible(np,
+						dialog_dt_ids[i].compatible))
+				id = &da9052_i2c_id[i];
+	}
+#endif
+
+	if (!id) {
+		ret = -ENODEV;
+		dev_err(&client->dev, "id is null.\n");
+		goto err_regmap;
+	}
+
 	ret = da9052_device_init(da9052, id->driver_data);
 	if (ret != 0)
 		goto err_regmap;
@@ -100,14 +143,6 @@ static int __devexit da9052_i2c_remove(struct i2c_client *client)
 	return 0;
 }
 
-static struct i2c_device_id da9052_i2c_id[] = {
-	{"da9052", DA9052},
-	{"da9053-aa", DA9053_AA},
-	{"da9053-ba", DA9053_BA},
-	{"da9053-bb", DA9053_BB},
-	{}
-};
-
 static struct i2c_driver da9052_i2c_driver = {
 	.probe = da9052_i2c_probe,
 	.remove = __devexit_p(da9052_i2c_remove),
@@ -115,6 +150,9 @@ static struct i2c_driver da9052_i2c_driver = {
 	.driver = {
 		.name = "da9052",
 		.owner = THIS_MODULE,
+#ifdef CONFIG_OF
+		.of_match_table = dialog_dt_ids,
+#endif
 	},
 };
 
-- 
1.7.9.5

             reply	other threads:[~2012-04-12 15:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12 15:39 Ying-Chun Liu (PaulLiu) [this message]
2012-04-12 15:39 ` [PATCH 1/2] mfd: da9052: add device-tree support for i2c driver Ying-Chun Liu (PaulLiu)
2012-04-12 15:39 ` [PATCH 2/2] regulator: da9052: add device tree support Ying-Chun Liu (PaulLiu)
2012-04-12 15:39   ` Ying-Chun Liu (PaulLiu)
2012-04-12 15:59   ` Mark Brown
2012-04-12 15:59     ` Mark Brown
2012-04-12 15:53 ` [PATCH 1/2] mfd: da9052: add device-tree support for i2c driver Mark Brown
2012-04-12 15:53   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334245182-31725-1-git-send-email-paul.liu@linaro.org \
    --to=paul.liu@linaro.org \
    --cc=ashish.jangam@kpitcummins.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@linaro.org \
    --cc=sameo@linux.intel.com \
    --cc=shawn.guo@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.