diff mbox

[3/3,V2] PMIC: MAX77686: Add FDT Support

Message ID 1354711860-10575-4-git-send-email-rajeshwari.s@samsung.com
State New
Headers show

Commit Message

Rajeshwari Shinde Dec. 5, 2012, 12:51 p.m. UTC
This patch adds fdt support to MAX77686.

Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
---
Changes in V2:
	- Corrected indentation errors.
 drivers/misc/pmic_max77686.c |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

Comments

Simon Glass Dec. 8, 2012, 7:42 p.m. UTC | #1
On Wed, Dec 5, 2012 at 4:51 AM, Rajeshwari Shinde
<rajeshwari.s@samsung.com> wrote:
> This patch adds fdt support to MAX77686.
>
> Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>

Acked-by: Simon Glass <sjg@chromium.org>

> ---
> Changes in V2:
>         - Corrected indentation errors.
>  drivers/misc/pmic_max77686.c |   35 ++++++++++++++++++++++++++++++-----
>  1 files changed, 30 insertions(+), 5 deletions(-)
>
diff mbox

Patch

diff --git a/drivers/misc/pmic_max77686.c b/drivers/misc/pmic_max77686.c
index 36f7f4d..a370d35 100644
--- a/drivers/misc/pmic_max77686.c
+++ b/drivers/misc/pmic_max77686.c
@@ -22,21 +22,46 @@ 
  */
 
 #include <common.h>
+#include <fdtdec.h>
+#include <i2c.h>
 #include <pmic.h>
 #include <max77686_pmic.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int pmic_init(void)
 {
 	struct pmic *p = get_pmic();
 	static const char name[] = "MAX77686_PMIC";
 
-	puts("Board PMIC init\n");
+#ifdef CONFIG_OF_CONTROL
+	const void *blob = gd->fdt_blob;
+	int node, parent;
+
+	node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_MAX77686_PMIC);
+	if (node < 0) {
+		debug("PMIC: No node for PMIC Chip in device tree\n");
+		debug("node = %d\n", node);
+		return -1;
+	}
+
+	parent = fdt_parent_offset(blob, node);
+	if (parent < 0) {
+		debug("%s: Cannot find node parent\n", __func__);
+		return -1;
+	}
+
+	p->bus = i2c_get_bus_num_fdt(parent);
+	p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 0);
+#else
+	p->bus = I2C_PMIC;
+	p->hw.i2c.addr = MAX77686_I2C_ADDR;
+#endif
+
 	p->name = name;
+	p->hw.i2c.tx_num = 1;
 	p->interface = PMIC_I2C;
 	p->number_of_regs = PMIC_NUM_OF_REGS;
-	p->hw.i2c.addr = MAX77686_I2C_ADDR;
-	p->hw.i2c.tx_num = 1;
-	p->bus = I2C_PMIC;
-
+	puts("Board PMIC init MAX77686\n");
 	return 0;
 }