aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/max77686.c
diff options
context:
space:
mode:
authorYadwinder Singh Brar <yadi.brar01@gmail.com>2012-07-06 07:32:55 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-07-09 09:13:42 -0400
commitc1516f840dcd91e76712a047993e09d95034a66d (patch)
tree8aedaf38d74ea987ff38ca9de81731b59ccd3d8f /drivers/mfd/max77686.c
parent2b40459b7ee502c970d9f1dcf94dfa4d58ec1d85 (diff)
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>
Diffstat (limited to 'drivers/mfd/max77686.c')
-rw-r--r--drivers/mfd/max77686.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index c66639d681e9..3e31d05906b2 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -34,6 +34,11 @@
34 34
35#define I2C_ADDR_RTC (0x0C >> 1) 35#define I2C_ADDR_RTC (0x0C >> 1)
36 36
37static struct of_device_id __devinitdata max77686_pmic_dt_match[] = {
38 {.compatible = "maxim,max77686", .data = 0},
39 {},
40};
41
37static struct mfd_cell max77686_devs[] = { 42static struct mfd_cell max77686_devs[] = {
38 { .name = "max77686-pmic", }, 43 { .name = "max77686-pmic", },
39 { .name = "max77686-rtc", }, 44 { .name = "max77686-rtc", },
@@ -44,14 +49,46 @@ static struct regmap_config max77686_regmap_config = {
44 .val_bits = 8, 49 .val_bits = 8,
45}; 50};
46 51
52#ifdef CONFIG_OF
53static struct max77686_platform_data *max77686_i2c_parse_dt_pdata(struct device
54 *dev)
55{
56 struct max77686_platform_data *pd;
57
58 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
59 if (!pd) {
60 dev_err(dev, "could not allocate memory for pdata\n");
61 return NULL;
62 }
63
64 dev->platform_data = pd;
65 return pd;
66}
67#else
68static struct max77686_platform_data *max77686_i2c_parse_dt_pdata(struct device
69 *dev)
70{
71 return 0;
72}
73#endif
74
47static int max77686_i2c_probe(struct i2c_client *i2c, 75static int max77686_i2c_probe(struct i2c_client *i2c,
48 const struct i2c_device_id *id) 76 const struct i2c_device_id *id)
49{ 77{
50 struct max77686_dev *max77686; 78 struct max77686_dev *max77686 = NULL;
51 struct max77686_platform_data *pdata = i2c->dev.platform_data; 79 struct max77686_platform_data *pdata = i2c->dev.platform_data;
52 unsigned int data; 80 unsigned int data;
53 int ret = 0; 81 int ret = 0;
54 82
83 if (i2c->dev.of_node)
84 pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);
85
86 if (!pdata) {
87 ret = -EIO;
88 dev_err(&i2c->dev, "No platform data found.\n");
89 goto err;
90 }
91
55 max77686 = kzalloc(sizeof(struct max77686_dev), GFP_KERNEL); 92 max77686 = kzalloc(sizeof(struct max77686_dev), GFP_KERNEL);
56 if (max77686 == NULL) 93 if (max77686 == NULL)
57 return -ENOMEM; 94 return -ENOMEM;
@@ -70,11 +107,6 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
70 max77686->i2c = i2c; 107 max77686->i2c = i2c;
71 max77686->type = id->driver_data; 108 max77686->type = id->driver_data;
72 109
73 if (!pdata) {
74 ret = -EIO;
75 goto err;
76 }
77
78 max77686->wakeup = pdata->wakeup; 110 max77686->wakeup = pdata->wakeup;
79 max77686->irq_gpio = pdata->irq_gpio; 111 max77686->irq_gpio = pdata->irq_gpio;
80 max77686->irq = i2c->irq; 112 max77686->irq = i2c->irq;
@@ -130,6 +162,7 @@ static struct i2c_driver max77686_i2c_driver = {
130 .driver = { 162 .driver = {
131 .name = "max77686", 163 .name = "max77686",
132 .owner = THIS_MODULE, 164 .owner = THIS_MODULE,
165 .of_match_table = of_match_ptr(max77686_pmic_dt_match),
133 }, 166 },
134 .probe = max77686_i2c_probe, 167 .probe = max77686_i2c_probe,
135 .remove = max77686_i2c_remove, 168 .remove = max77686_i2c_remove,