aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mfd/tc3589x.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/drivers/mfd/tc3589x.c b/drivers/mfd/tc3589x.c
index 2df44acaf907..8f4c853ca116 100644
--- a/drivers/mfd/tc3589x.c
+++ b/drivers/mfd/tc3589x.c
@@ -12,6 +12,7 @@
12#include <linux/irqdomain.h> 12#include <linux/irqdomain.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/of.h>
15#include <linux/mfd/core.h> 16#include <linux/mfd/core.h>
16#include <linux/mfd/tc3589x.h> 17#include <linux/mfd/tc3589x.h>
17 18
@@ -146,6 +147,7 @@ static struct mfd_cell tc3589x_dev_gpio[] = {
146 .name = "tc3589x-gpio", 147 .name = "tc3589x-gpio",
147 .num_resources = ARRAY_SIZE(gpio_resources), 148 .num_resources = ARRAY_SIZE(gpio_resources),
148 .resources = &gpio_resources[0], 149 .resources = &gpio_resources[0],
150 .of_compatible = "tc3589x-gpio",
149 }, 151 },
150}; 152};
151 153
@@ -154,6 +156,7 @@ static struct mfd_cell tc3589x_dev_keypad[] = {
154 .name = "tc3589x-keypad", 156 .name = "tc3589x-keypad",
155 .num_resources = ARRAY_SIZE(keypad_resources), 157 .num_resources = ARRAY_SIZE(keypad_resources),
156 .resources = &keypad_resources[0], 158 .resources = &keypad_resources[0],
159 .of_compatible = "tc3589x-keypad",
157 }, 160 },
158}; 161};
159 162
@@ -221,7 +224,7 @@ static struct irq_domain_ops tc3589x_irq_ops = {
221 .xlate = irq_domain_xlate_twocell, 224 .xlate = irq_domain_xlate_twocell,
222}; 225};
223 226
224static int tc3589x_irq_init(struct tc3589x *tc3589x) 227static int tc3589x_irq_init(struct tc3589x *tc3589x, struct device_node *np)
225{ 228{
226 int base = tc3589x->irq_base; 229 int base = tc3589x->irq_base;
227 230
@@ -232,7 +235,7 @@ static int tc3589x_irq_init(struct tc3589x *tc3589x)
232 } 235 }
233 else { 236 else {
234 tc3589x->domain = irq_domain_add_linear( 237 tc3589x->domain = irq_domain_add_linear(
235 NULL, TC3589x_NR_INTERNAL_IRQS, 238 np, TC3589x_NR_INTERNAL_IRQS,
236 &tc3589x_irq_ops, tc3589x); 239 &tc3589x_irq_ops, tc3589x);
237 } 240 }
238 241
@@ -309,13 +312,47 @@ static int __devinit tc3589x_device_init(struct tc3589x *tc3589x)
309 return ret; 312 return ret;
310} 313}
311 314
315static int tc3589x_of_probe(struct device_node *np,
316 struct tc3589x_platform_data *pdata)
317{
318 struct device_node *child;
319
320 for_each_child_of_node(np, child) {
321 if (!strcmp(child->name, "tc3589x_gpio")) {
322 pdata->block |= TC3589x_BLOCK_GPIO;
323 }
324 if (!strcmp(child->name, "tc3589x_keypad")) {
325 pdata->block |= TC3589x_BLOCK_KEYPAD;
326 }
327 }
328
329 return 0;
330}
331
312static int __devinit tc3589x_probe(struct i2c_client *i2c, 332static int __devinit tc3589x_probe(struct i2c_client *i2c,
313 const struct i2c_device_id *id) 333 const struct i2c_device_id *id)
314{ 334{
315 struct tc3589x_platform_data *pdata = i2c->dev.platform_data; 335 struct tc3589x_platform_data *pdata = i2c->dev.platform_data;
336 struct device_node *np = i2c->dev.of_node;
316 struct tc3589x *tc3589x; 337 struct tc3589x *tc3589x;
317 int ret; 338 int ret;
318 339
340 if (!pdata) {
341 if (np) {
342 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL);
343 if (!pdata)
344 return -ENOMEM;
345
346 ret = tc3589x_of_probe(np, pdata);
347 if (ret)
348 return ret;
349 }
350 else {
351 dev_err(&i2c->dev, "No platform data or DT found\n");
352 return -EINVAL;
353 }
354 }
355
319 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA 356 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
320 | I2C_FUNC_SMBUS_I2C_BLOCK)) 357 | I2C_FUNC_SMBUS_I2C_BLOCK))
321 return -EIO; 358 return -EIO;
@@ -338,7 +375,7 @@ static int __devinit tc3589x_probe(struct i2c_client *i2c,
338 if (ret) 375 if (ret)
339 goto out_free; 376 goto out_free;
340 377
341 ret = tc3589x_irq_init(tc3589x); 378 ret = tc3589x_irq_init(tc3589x, np);
342 if (ret) 379 if (ret)
343 goto out_free; 380 goto out_free;
344 381