mfd: Add device tree support for max77686

This patch adds device tree support for mfd driver and adds
Documentation/devicetree/bindings/mfd/max77686.txt.
This patch also intialize max77686 pointer to NULL in max77686_i2c_probe
to silent a compile time warning.

Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com>
Reviwed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index c66639d..3e31d05 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -34,6 +34,11 @@
 
 #define I2C_ADDR_RTC	(0x0C >> 1)
 
+static struct of_device_id __devinitdata max77686_pmic_dt_match[] = {
+	{.compatible = "maxim,max77686",        .data = 0},
+	{},
+};
+
 static struct mfd_cell max77686_devs[] = {
 	{ .name = "max77686-pmic", },
 	{ .name = "max77686-rtc", },
@@ -44,14 +49,46 @@
 	.val_bits = 8,
 };
 
+#ifdef CONFIG_OF
+static struct max77686_platform_data *max77686_i2c_parse_dt_pdata(struct device
+								  *dev)
+{
+	struct max77686_platform_data *pd;
+
+	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+	if (!pd) {
+		dev_err(dev, "could not allocate memory for pdata\n");
+		return NULL;
+	}
+
+	dev->platform_data = pd;
+	return pd;
+}
+#else
+static struct max77686_platform_data *max77686_i2c_parse_dt_pdata(struct device
+								  *dev)
+{
+	return 0;
+}
+#endif
+
 static int max77686_i2c_probe(struct i2c_client *i2c,
 			      const struct i2c_device_id *id)
 {
-	struct max77686_dev *max77686;
+	struct max77686_dev *max77686 = NULL;
 	struct max77686_platform_data *pdata = i2c->dev.platform_data;
 	unsigned int data;
 	int ret = 0;
 
+	if (i2c->dev.of_node)
+		pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);
+
+	if (!pdata) {
+		ret = -EIO;
+		dev_err(&i2c->dev, "No platform data found.\n");
+		goto err;
+	}
+
 	max77686 = kzalloc(sizeof(struct max77686_dev), GFP_KERNEL);
 	if (max77686 == NULL)
 		return -ENOMEM;
@@ -70,11 +107,6 @@
 	max77686->i2c = i2c;
 	max77686->type = id->driver_data;
 
-	if (!pdata) {
-		ret = -EIO;
-		goto err;
-	}
-
 	max77686->wakeup = pdata->wakeup;
 	max77686->irq_gpio = pdata->irq_gpio;
 	max77686->irq = i2c->irq;
@@ -130,6 +162,7 @@
 	.driver = {
 		   .name = "max77686",
 		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(max77686_pmic_dt_match),
 	},
 	.probe = max77686_i2c_probe,
 	.remove = max77686_i2c_remove,