20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/slab.h>
25 #include <linux/i2c.h>
33 #define TPS6586X_SUPPLYENE 0x14
34 #define EXITSLREQ_BIT BIT(1)
35 #define SLEEP_MODE_BIT BIT(3)
38 #define TPS6586X_INT_ACK1 0xb5
39 #define TPS6586X_INT_ACK2 0xb6
40 #define TPS6586X_INT_ACK3 0xb7
41 #define TPS6586X_INT_ACK4 0xb8
44 #define TPS6586X_INT_MASK1 0xb0
45 #define TPS6586X_INT_MASK2 0xb1
46 #define TPS6586X_INT_MASK3 0xb2
47 #define TPS6586X_INT_MASK4 0xb3
48 #define TPS6586X_INT_MASK5 0xb4
51 #define TPS6586X_VERSIONCRC 0xcd
54 #define TPS6586X_MAX_REGISTER (TPS6586X_VERSIONCRC + 1)
61 #define TPS6586X_IRQ(_reg, _mask) \
63 .mask_reg = (_reg) - TPS6586X_INT_MASK1, \
64 .mask_mask = (_mask), \
97 static struct mfd_cell tps6586x_cell[] = {
99 .name =
"tps6586x-gpio",
102 .name =
"tps6586x-rtc",
105 .name =
"tps6586x-onkey",
208 unsigned int __irq = irq_data->
irq - tps6586x->
irq_base;
212 tps6586x->
irq_en |= (1 << __irq);
219 unsigned int __irq = irq_data->
irq - tps6586x->
irq_base;
223 tps6586x->
irq_en &= ~(1 << __irq);
226 static void tps6586x_irq_sync_unlock(
struct irq_data *
data)
242 static irqreturn_t tps6586x_irq(
int irq,
void *data)
244 struct tps6586x *tps6586x =
data;
249 sizeof(acks), (
uint8_t *)&acks);
252 dev_err(tps6586x->
dev,
"failed to read interrupt status\n");
261 if (tps6586x->
irq_en & (1 << i))
270 static int __devinit tps6586x_irq_init(
struct tps6586x *tps6586x,
int irq,
277 dev_warn(tps6586x->
dev,
"No interrupt support on IRQ base\n");
282 for (i = 0; i < 5; i++) {
291 tps6586x->
irq_chip.name =
"tps6586x";
292 tps6586x->
irq_chip.irq_enable = tps6586x_irq_enable;
293 tps6586x->
irq_chip.irq_disable = tps6586x_irq_disable;
294 tps6586x->
irq_chip.irq_bus_lock = tps6586x_irq_lock;
295 tps6586x->
irq_chip.irq_bus_sync_unlock = tps6586x_irq_sync_unlock;
297 for (i = 0; i <
ARRAY_SIZE(tps6586x_irqs); i++) {
300 irq_set_chip_and_handler(__irq, &tps6586x->
irq_chip,
302 irq_set_nested_thread(__irq, 1);
309 "tps6586x", tps6586x);
313 enable_irq_wake(irq);
319 static int __devinit tps6586x_add_subdevs(
struct tps6586x *tps6586x,
335 pdev->
dev.parent = tps6586x->
dev;
348 tps6586x_remove_subdevs(tps6586x);
378 const char *sys_rail_name =
NULL;
400 for (i = 0, j = 0; i < num && j <
count; i++) {
403 if (!tps6586x_matches[i].init_data)
407 devs[
j].
name =
"tps6586x-regulator";
429 pdata->
pm_off = of_property_read_bool(np,
"ti,system-power-controller");
445 static bool is_volatile_reg(
struct device *dev,
unsigned int reg)
454 static const struct regmap_config tps6586x_regmap_config = {
458 .volatile_reg = is_volatile_reg,
462 static struct device *tps6586x_dev;
463 static void tps6586x_power_off(
void)
475 struct tps6586x *tps6586x;
478 if (!pdata && client->
dev.of_node)
479 pdata = tps6586x_parse_dt(client);
482 dev_err(&client->
dev,
"tps6586x requires platform data\n");
488 dev_err(&client->
dev,
"Chip ID read failed: %d\n", ret);
492 dev_info(&client->
dev,
"VERSIONCRC is %02x\n", ret);
495 if (tps6586x ==
NULL) {
496 dev_err(&client->
dev,
"memory for tps6586x alloc failed\n");
501 tps6586x->
dev = &client->
dev;
502 i2c_set_clientdata(client, tps6586x);
505 &tps6586x_regmap_config);
506 if (IS_ERR(tps6586x->
regmap)) {
507 ret = PTR_ERR(tps6586x->
regmap);
508 dev_err(&client->
dev,
"regmap init failed: %d\n", ret);
514 ret = tps6586x_irq_init(tps6586x, client->
irq,
517 dev_err(&client->
dev,
"IRQ init failed: %d\n", ret);
526 dev_err(&client->
dev,
"mfd_add_devices failed: %d\n", ret);
530 ret = tps6586x_add_subdevs(tps6586x, pdata);
532 dev_err(&client->
dev,
"add devices failed: %d\n", ret);
537 tps6586x_dev = &client->
dev;
553 struct tps6586x *tps6586x = i2c_get_clientdata(client);
555 tps6586x_remove_subdevs(tps6586x);
574 .probe = tps6586x_i2c_probe,
576 .id_table = tps6586x_id_table,
579 static int __init tps6586x_init(
void)
581 return i2c_add_driver(&tps6586x_driver);
585 static void __exit tps6586x_exit(
void)