diff options
Diffstat (limited to 'drivers/mfd/tps6586x.c')
-rw-r--r-- | drivers/mfd/tps6586x.c | 189 |
1 files changed, 90 insertions, 99 deletions
diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 467464368773..721b9186a5d1 100644 --- a/drivers/mfd/tps6586x.c +++ b/drivers/mfd/tps6586x.c | |||
@@ -17,15 +17,15 @@ | |||
17 | 17 | ||
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/irq.h> | 19 | #include <linux/irq.h> |
20 | #include <linux/irqdomain.h> | ||
20 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
21 | #include <linux/module.h> | 22 | #include <linux/module.h> |
22 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
23 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
24 | #include <linux/err.h> | 25 | #include <linux/err.h> |
25 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/platform_device.h> | ||
26 | #include <linux/regmap.h> | 28 | #include <linux/regmap.h> |
27 | #include <linux/regulator/of_regulator.h> | ||
28 | #include <linux/regulator/machine.h> | ||
29 | 29 | ||
30 | #include <linux/mfd/core.h> | 30 | #include <linux/mfd/core.h> |
31 | #include <linux/mfd/tps6586x.h> | 31 | #include <linux/mfd/tps6586x.h> |
@@ -94,12 +94,25 @@ static const struct tps6586x_irq_data tps6586x_irqs[] = { | |||
94 | [TPS6586X_INT_RTC_ALM2] = TPS6586X_IRQ(TPS6586X_INT_MASK4, 1 << 1), | 94 | [TPS6586X_INT_RTC_ALM2] = TPS6586X_IRQ(TPS6586X_INT_MASK4, 1 << 1), |
95 | }; | 95 | }; |
96 | 96 | ||
97 | static struct resource tps6586x_rtc_resources[] = { | ||
98 | { | ||
99 | .start = TPS6586X_INT_RTC_ALM1, | ||
100 | .end = TPS6586X_INT_RTC_ALM1, | ||
101 | .flags = IORESOURCE_IRQ, | ||
102 | }, | ||
103 | }; | ||
104 | |||
97 | static struct mfd_cell tps6586x_cell[] = { | 105 | static struct mfd_cell tps6586x_cell[] = { |
98 | { | 106 | { |
99 | .name = "tps6586x-gpio", | 107 | .name = "tps6586x-gpio", |
100 | }, | 108 | }, |
101 | { | 109 | { |
110 | .name = "tps6586x-pmic", | ||
111 | }, | ||
112 | { | ||
102 | .name = "tps6586x-rtc", | 113 | .name = "tps6586x-rtc", |
114 | .num_resources = ARRAY_SIZE(tps6586x_rtc_resources), | ||
115 | .resources = &tps6586x_rtc_resources[0], | ||
103 | }, | 116 | }, |
104 | { | 117 | { |
105 | .name = "tps6586x-onkey", | 118 | .name = "tps6586x-onkey", |
@@ -116,6 +129,7 @@ struct tps6586x { | |||
116 | int irq_base; | 129 | int irq_base; |
117 | u32 irq_en; | 130 | u32 irq_en; |
118 | u8 mask_reg[5]; | 131 | u8 mask_reg[5]; |
132 | struct irq_domain *irq_domain; | ||
119 | }; | 133 | }; |
120 | 134 | ||
121 | static inline struct tps6586x *dev_to_tps6586x(struct device *dev) | 135 | static inline struct tps6586x *dev_to_tps6586x(struct device *dev) |
@@ -184,6 +198,14 @@ int tps6586x_update(struct device *dev, int reg, uint8_t val, uint8_t mask) | |||
184 | } | 198 | } |
185 | EXPORT_SYMBOL_GPL(tps6586x_update); | 199 | EXPORT_SYMBOL_GPL(tps6586x_update); |
186 | 200 | ||
201 | int tps6586x_irq_get_virq(struct device *dev, int irq) | ||
202 | { | ||
203 | struct tps6586x *tps6586x = dev_to_tps6586x(dev); | ||
204 | |||
205 | return irq_create_mapping(tps6586x->irq_domain, irq); | ||
206 | } | ||
207 | EXPORT_SYMBOL_GPL(tps6586x_irq_get_virq); | ||
208 | |||
187 | static int __remove_subdev(struct device *dev, void *unused) | 209 | static int __remove_subdev(struct device *dev, void *unused) |
188 | { | 210 | { |
189 | platform_device_unregister(to_platform_device(dev)); | 211 | platform_device_unregister(to_platform_device(dev)); |
@@ -205,7 +227,7 @@ static void tps6586x_irq_lock(struct irq_data *data) | |||
205 | static void tps6586x_irq_enable(struct irq_data *irq_data) | 227 | static void tps6586x_irq_enable(struct irq_data *irq_data) |
206 | { | 228 | { |
207 | struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data); | 229 | struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data); |
208 | unsigned int __irq = irq_data->irq - tps6586x->irq_base; | 230 | unsigned int __irq = irq_data->hwirq; |
209 | const struct tps6586x_irq_data *data = &tps6586x_irqs[__irq]; | 231 | const struct tps6586x_irq_data *data = &tps6586x_irqs[__irq]; |
210 | 232 | ||
211 | tps6586x->mask_reg[data->mask_reg] &= ~data->mask_mask; | 233 | tps6586x->mask_reg[data->mask_reg] &= ~data->mask_mask; |
@@ -216,7 +238,7 @@ static void tps6586x_irq_disable(struct irq_data *irq_data) | |||
216 | { | 238 | { |
217 | struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data); | 239 | struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data); |
218 | 240 | ||
219 | unsigned int __irq = irq_data->irq - tps6586x->irq_base; | 241 | unsigned int __irq = irq_data->hwirq; |
220 | const struct tps6586x_irq_data *data = &tps6586x_irqs[__irq]; | 242 | const struct tps6586x_irq_data *data = &tps6586x_irqs[__irq]; |
221 | 243 | ||
222 | tps6586x->mask_reg[data->mask_reg] |= data->mask_mask; | 244 | tps6586x->mask_reg[data->mask_reg] |= data->mask_mask; |
@@ -239,6 +261,39 @@ static void tps6586x_irq_sync_unlock(struct irq_data *data) | |||
239 | mutex_unlock(&tps6586x->irq_lock); | 261 | mutex_unlock(&tps6586x->irq_lock); |
240 | } | 262 | } |
241 | 263 | ||
264 | static struct irq_chip tps6586x_irq_chip = { | ||
265 | .name = "tps6586x", | ||
266 | .irq_bus_lock = tps6586x_irq_lock, | ||
267 | .irq_bus_sync_unlock = tps6586x_irq_sync_unlock, | ||
268 | .irq_disable = tps6586x_irq_disable, | ||
269 | .irq_enable = tps6586x_irq_enable, | ||
270 | }; | ||
271 | |||
272 | static int tps6586x_irq_map(struct irq_domain *h, unsigned int virq, | ||
273 | irq_hw_number_t hw) | ||
274 | { | ||
275 | struct tps6586x *tps6586x = h->host_data; | ||
276 | |||
277 | irq_set_chip_data(virq, tps6586x); | ||
278 | irq_set_chip_and_handler(virq, &tps6586x_irq_chip, handle_simple_irq); | ||
279 | irq_set_nested_thread(virq, 1); | ||
280 | |||
281 | /* ARM needs us to explicitly flag the IRQ as valid | ||
282 | * and will set them noprobe when we do so. */ | ||
283 | #ifdef CONFIG_ARM | ||
284 | set_irq_flags(virq, IRQF_VALID); | ||
285 | #else | ||
286 | irq_set_noprobe(virq); | ||
287 | #endif | ||
288 | |||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | static struct irq_domain_ops tps6586x_domain_ops = { | ||
293 | .map = tps6586x_irq_map, | ||
294 | .xlate = irq_domain_xlate_twocell, | ||
295 | }; | ||
296 | |||
242 | static irqreturn_t tps6586x_irq(int irq, void *data) | 297 | static irqreturn_t tps6586x_irq(int irq, void *data) |
243 | { | 298 | { |
244 | struct tps6586x *tps6586x = data; | 299 | struct tps6586x *tps6586x = data; |
@@ -259,7 +314,8 @@ static irqreturn_t tps6586x_irq(int irq, void *data) | |||
259 | int i = __ffs(acks); | 314 | int i = __ffs(acks); |
260 | 315 | ||
261 | if (tps6586x->irq_en & (1 << i)) | 316 | if (tps6586x->irq_en & (1 << i)) |
262 | handle_nested_irq(tps6586x->irq_base + i); | 317 | handle_nested_irq( |
318 | irq_find_mapping(tps6586x->irq_domain, i)); | ||
263 | 319 | ||
264 | acks &= ~(1 << i); | 320 | acks &= ~(1 << i); |
265 | } | 321 | } |
@@ -267,16 +323,13 @@ static irqreturn_t tps6586x_irq(int irq, void *data) | |||
267 | return IRQ_HANDLED; | 323 | return IRQ_HANDLED; |
268 | } | 324 | } |
269 | 325 | ||
270 | static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq, | 326 | static int tps6586x_irq_init(struct tps6586x *tps6586x, int irq, |
271 | int irq_base) | 327 | int irq_base) |
272 | { | 328 | { |
273 | int i, ret; | 329 | int i, ret; |
274 | u8 tmp[4]; | 330 | u8 tmp[4]; |
275 | 331 | int new_irq_base; | |
276 | if (!irq_base) { | 332 | int irq_num = ARRAY_SIZE(tps6586x_irqs); |
277 | dev_warn(tps6586x->dev, "No interrupt support on IRQ base\n"); | ||
278 | return -EINVAL; | ||
279 | } | ||
280 | 333 | ||
281 | mutex_init(&tps6586x->irq_lock); | 334 | mutex_init(&tps6586x->irq_lock); |
282 | for (i = 0; i < 5; i++) { | 335 | for (i = 0; i < 5; i++) { |
@@ -286,25 +339,24 @@ static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq, | |||
286 | 339 | ||
287 | tps6586x_reads(tps6586x->dev, TPS6586X_INT_ACK1, sizeof(tmp), tmp); | 340 | tps6586x_reads(tps6586x->dev, TPS6586X_INT_ACK1, sizeof(tmp), tmp); |
288 | 341 | ||
289 | tps6586x->irq_base = irq_base; | 342 | if (irq_base > 0) { |
290 | 343 | new_irq_base = irq_alloc_descs(irq_base, 0, irq_num, -1); | |
291 | tps6586x->irq_chip.name = "tps6586x"; | 344 | if (new_irq_base < 0) { |
292 | tps6586x->irq_chip.irq_enable = tps6586x_irq_enable; | 345 | dev_err(tps6586x->dev, |
293 | tps6586x->irq_chip.irq_disable = tps6586x_irq_disable; | 346 | "Failed to alloc IRQs: %d\n", new_irq_base); |
294 | tps6586x->irq_chip.irq_bus_lock = tps6586x_irq_lock; | 347 | return new_irq_base; |
295 | tps6586x->irq_chip.irq_bus_sync_unlock = tps6586x_irq_sync_unlock; | 348 | } |
296 | 349 | } else { | |
297 | for (i = 0; i < ARRAY_SIZE(tps6586x_irqs); i++) { | 350 | new_irq_base = 0; |
298 | int __irq = i + tps6586x->irq_base; | ||
299 | irq_set_chip_data(__irq, tps6586x); | ||
300 | irq_set_chip_and_handler(__irq, &tps6586x->irq_chip, | ||
301 | handle_simple_irq); | ||
302 | irq_set_nested_thread(__irq, 1); | ||
303 | #ifdef CONFIG_ARM | ||
304 | set_irq_flags(__irq, IRQF_VALID); | ||
305 | #endif | ||
306 | } | 351 | } |
307 | 352 | ||
353 | tps6586x->irq_domain = irq_domain_add_simple(tps6586x->dev->of_node, | ||
354 | irq_num, new_irq_base, &tps6586x_domain_ops, | ||
355 | tps6586x); | ||
356 | if (!tps6586x->irq_domain) { | ||
357 | dev_err(tps6586x->dev, "Failed to create IRQ domain\n"); | ||
358 | return -ENOMEM; | ||
359 | } | ||
308 | ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT, | 360 | ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT, |
309 | "tps6586x", tps6586x); | 361 | "tps6586x", tps6586x); |
310 | 362 | ||
@@ -316,7 +368,7 @@ static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq, | |||
316 | return ret; | 368 | return ret; |
317 | } | 369 | } |
318 | 370 | ||
319 | static int __devinit tps6586x_add_subdevs(struct tps6586x *tps6586x, | 371 | static int tps6586x_add_subdevs(struct tps6586x *tps6586x, |
320 | struct tps6586x_platform_data *pdata) | 372 | struct tps6586x_platform_data *pdata) |
321 | { | 373 | { |
322 | struct tps6586x_subdev_info *subdev; | 374 | struct tps6586x_subdev_info *subdev; |
@@ -350,80 +402,19 @@ failed: | |||
350 | } | 402 | } |
351 | 403 | ||
352 | #ifdef CONFIG_OF | 404 | #ifdef CONFIG_OF |
353 | static struct of_regulator_match tps6586x_matches[] = { | ||
354 | { .name = "sys", .driver_data = (void *)TPS6586X_ID_SYS }, | ||
355 | { .name = "sm0", .driver_data = (void *)TPS6586X_ID_SM_0 }, | ||
356 | { .name = "sm1", .driver_data = (void *)TPS6586X_ID_SM_1 }, | ||
357 | { .name = "sm2", .driver_data = (void *)TPS6586X_ID_SM_2 }, | ||
358 | { .name = "ldo0", .driver_data = (void *)TPS6586X_ID_LDO_0 }, | ||
359 | { .name = "ldo1", .driver_data = (void *)TPS6586X_ID_LDO_1 }, | ||
360 | { .name = "ldo2", .driver_data = (void *)TPS6586X_ID_LDO_2 }, | ||
361 | { .name = "ldo3", .driver_data = (void *)TPS6586X_ID_LDO_3 }, | ||
362 | { .name = "ldo4", .driver_data = (void *)TPS6586X_ID_LDO_4 }, | ||
363 | { .name = "ldo5", .driver_data = (void *)TPS6586X_ID_LDO_5 }, | ||
364 | { .name = "ldo6", .driver_data = (void *)TPS6586X_ID_LDO_6 }, | ||
365 | { .name = "ldo7", .driver_data = (void *)TPS6586X_ID_LDO_7 }, | ||
366 | { .name = "ldo8", .driver_data = (void *)TPS6586X_ID_LDO_8 }, | ||
367 | { .name = "ldo9", .driver_data = (void *)TPS6586X_ID_LDO_9 }, | ||
368 | { .name = "ldo_rtc", .driver_data = (void *)TPS6586X_ID_LDO_RTC }, | ||
369 | }; | ||
370 | |||
371 | static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *client) | 405 | static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *client) |
372 | { | 406 | { |
373 | const unsigned int num = ARRAY_SIZE(tps6586x_matches); | ||
374 | struct device_node *np = client->dev.of_node; | 407 | struct device_node *np = client->dev.of_node; |
375 | struct tps6586x_platform_data *pdata; | 408 | struct tps6586x_platform_data *pdata; |
376 | struct tps6586x_subdev_info *devs; | ||
377 | struct device_node *regs; | ||
378 | const char *sys_rail_name = NULL; | ||
379 | unsigned int count; | ||
380 | unsigned int i, j; | ||
381 | int err; | ||
382 | |||
383 | regs = of_find_node_by_name(np, "regulators"); | ||
384 | if (!regs) | ||
385 | return NULL; | ||
386 | |||
387 | err = of_regulator_match(&client->dev, regs, tps6586x_matches, num); | ||
388 | if (err < 0) { | ||
389 | of_node_put(regs); | ||
390 | return NULL; | ||
391 | } | ||
392 | |||
393 | of_node_put(regs); | ||
394 | count = err; | ||
395 | |||
396 | devs = devm_kzalloc(&client->dev, count * sizeof(*devs), GFP_KERNEL); | ||
397 | if (!devs) | ||
398 | return NULL; | ||
399 | |||
400 | for (i = 0, j = 0; i < num && j < count; i++) { | ||
401 | struct regulator_init_data *reg_idata; | ||
402 | |||
403 | if (!tps6586x_matches[i].init_data) | ||
404 | continue; | ||
405 | |||
406 | reg_idata = tps6586x_matches[i].init_data; | ||
407 | devs[j].name = "tps6586x-regulator"; | ||
408 | devs[j].platform_data = tps6586x_matches[i].init_data; | ||
409 | devs[j].id = (int)tps6586x_matches[i].driver_data; | ||
410 | if (devs[j].id == TPS6586X_ID_SYS) | ||
411 | sys_rail_name = reg_idata->constraints.name; | ||
412 | |||
413 | if ((devs[j].id == TPS6586X_ID_LDO_5) || | ||
414 | (devs[j].id == TPS6586X_ID_LDO_RTC)) | ||
415 | reg_idata->supply_regulator = sys_rail_name; | ||
416 | |||
417 | devs[j].of_node = tps6586x_matches[i].of_node; | ||
418 | j++; | ||
419 | } | ||
420 | 409 | ||
421 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); | 410 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); |
422 | if (!pdata) | 411 | if (!pdata) { |
412 | dev_err(&client->dev, "Memory allocation failed\n"); | ||
423 | return NULL; | 413 | return NULL; |
414 | } | ||
424 | 415 | ||
425 | pdata->num_subdevs = count; | 416 | pdata->num_subdevs = 0; |
426 | pdata->subdevs = devs; | 417 | pdata->subdevs = NULL; |
427 | pdata->gpio_base = -1; | 418 | pdata->gpio_base = -1; |
428 | pdata->irq_base = -1; | 419 | pdata->irq_base = -1; |
429 | pdata->pm_off = of_property_read_bool(np, "ti,system-power-controller"); | 420 | pdata->pm_off = of_property_read_bool(np, "ti,system-power-controller"); |
@@ -468,7 +459,7 @@ static void tps6586x_power_off(void) | |||
468 | tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); | 459 | tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); |
469 | } | 460 | } |
470 | 461 | ||
471 | static int __devinit tps6586x_i2c_probe(struct i2c_client *client, | 462 | static int tps6586x_i2c_probe(struct i2c_client *client, |
472 | const struct i2c_device_id *id) | 463 | const struct i2c_device_id *id) |
473 | { | 464 | { |
474 | struct tps6586x_platform_data *pdata = client->dev.platform_data; | 465 | struct tps6586x_platform_data *pdata = client->dev.platform_data; |
@@ -521,7 +512,7 @@ static int __devinit tps6586x_i2c_probe(struct i2c_client *client, | |||
521 | 512 | ||
522 | ret = mfd_add_devices(tps6586x->dev, -1, | 513 | ret = mfd_add_devices(tps6586x->dev, -1, |
523 | tps6586x_cell, ARRAY_SIZE(tps6586x_cell), | 514 | tps6586x_cell, ARRAY_SIZE(tps6586x_cell), |
524 | NULL, 0, NULL); | 515 | NULL, 0, tps6586x->irq_domain); |
525 | if (ret < 0) { | 516 | if (ret < 0) { |
526 | dev_err(&client->dev, "mfd_add_devices failed: %d\n", ret); | 517 | dev_err(&client->dev, "mfd_add_devices failed: %d\n", ret); |
527 | goto err_mfd_add; | 518 | goto err_mfd_add; |
@@ -548,7 +539,7 @@ err_mfd_add: | |||
548 | return ret; | 539 | return ret; |
549 | } | 540 | } |
550 | 541 | ||
551 | static int __devexit tps6586x_i2c_remove(struct i2c_client *client) | 542 | static int tps6586x_i2c_remove(struct i2c_client *client) |
552 | { | 543 | { |
553 | struct tps6586x *tps6586x = i2c_get_clientdata(client); | 544 | struct tps6586x *tps6586x = i2c_get_clientdata(client); |
554 | 545 | ||
@@ -572,7 +563,7 @@ static struct i2c_driver tps6586x_driver = { | |||
572 | .of_match_table = of_match_ptr(tps6586x_of_match), | 563 | .of_match_table = of_match_ptr(tps6586x_of_match), |
573 | }, | 564 | }, |
574 | .probe = tps6586x_i2c_probe, | 565 | .probe = tps6586x_i2c_probe, |
575 | .remove = __devexit_p(tps6586x_i2c_remove), | 566 | .remove = tps6586x_i2c_remove, |
576 | .id_table = tps6586x_id_table, | 567 | .id_table = tps6586x_id_table, |
577 | }; | 568 | }; |
578 | 569 | ||