1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
4 * Andrew F. Davis <afd@ti.com>
6 * Based on the TPS65912 driver
10 #include <linux/interrupt.h>
11 #include <linux/mfd/core.h>
12 #include <linux/module.h>
14 #include <linux/mfd/tps65086.h>
16 static const struct mfd_cell tps65086_cells[] = {
17 { .name = "tps65086-regulator", },
18 { .name = "tps65086-gpio", },
19 { .name = "tps65086-reset", },
22 static const struct regmap_range tps65086_yes_ranges[] = {
23 regmap_reg_range(TPS65086_IRQ, TPS65086_IRQ),
24 regmap_reg_range(TPS65086_PMICSTAT, TPS65086_SHUTDNSRC),
25 regmap_reg_range(TPS65086_GPOCTRL, TPS65086_GPOCTRL),
26 regmap_reg_range(TPS65086_PG_STATUS1, TPS65086_OC_STATUS),
29 static const struct regmap_access_table tps65086_volatile_table = {
30 .yes_ranges = tps65086_yes_ranges,
31 .n_yes_ranges = ARRAY_SIZE(tps65086_yes_ranges),
34 static const struct regmap_config tps65086_regmap_config = {
37 .cache_type = REGCACHE_RBTREE,
38 .volatile_table = &tps65086_volatile_table,
41 static const struct regmap_irq tps65086_irqs[] = {
42 REGMAP_IRQ_REG(TPS65086_IRQ_DIETEMP, 0, TPS65086_IRQ_DIETEMP_MASK),
43 REGMAP_IRQ_REG(TPS65086_IRQ_SHUTDN, 0, TPS65086_IRQ_SHUTDN_MASK),
44 REGMAP_IRQ_REG(TPS65086_IRQ_FAULT, 0, TPS65086_IRQ_FAULT_MASK),
47 static struct regmap_irq_chip tps65086_irq_chip = {
49 .status_base = TPS65086_IRQ,
50 .mask_base = TPS65086_IRQ_MASK,
51 .ack_base = TPS65086_IRQ,
52 .init_ack_masked = true,
54 .irqs = tps65086_irqs,
55 .num_irqs = ARRAY_SIZE(tps65086_irqs),
58 static const struct of_device_id tps65086_of_match_table[] = {
59 { .compatible = "ti,tps65086", },
62 MODULE_DEVICE_TABLE(of, tps65086_of_match_table);
64 static int tps65086_probe(struct i2c_client *client,
65 const struct i2c_device_id *ids)
71 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
75 i2c_set_clientdata(client, tps);
76 tps->dev = &client->dev;
77 tps->irq = client->irq;
79 tps->regmap = devm_regmap_init_i2c(client, &tps65086_regmap_config);
80 if (IS_ERR(tps->regmap)) {
81 dev_err(tps->dev, "Failed to initialize register map\n");
82 return PTR_ERR(tps->regmap);
85 ret = regmap_read(tps->regmap, TPS65086_DEVICEID, &version);
87 dev_err(tps->dev, "Failed to read revision register\n");
91 dev_info(tps->dev, "Device: TPS65086%01lX, OTP: %c, Rev: %ld\n",
92 (version & TPS65086_DEVICEID_PART_MASK),
93 (char)((version & TPS65086_DEVICEID_OTP_MASK) >> 4) + 'A',
94 (version & TPS65086_DEVICEID_REV_MASK) >> 6);
97 ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
98 &tps65086_irq_chip, &tps->irq_data);
100 dev_err(tps->dev, "Failed to register IRQ chip\n");
105 ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65086_cells,
106 ARRAY_SIZE(tps65086_cells), NULL, 0,
107 regmap_irq_get_domain(tps->irq_data));
108 if (ret && tps->irq > 0)
109 regmap_del_irq_chip(tps->irq, tps->irq_data);
114 static void tps65086_remove(struct i2c_client *client)
116 struct tps65086 *tps = i2c_get_clientdata(client);
119 regmap_del_irq_chip(tps->irq, tps->irq_data);
122 static const struct i2c_device_id tps65086_id_table[] = {
126 MODULE_DEVICE_TABLE(i2c, tps65086_id_table);
128 static struct i2c_driver tps65086_driver = {
131 .of_match_table = tps65086_of_match_table,
133 .probe = tps65086_probe,
134 .remove = tps65086_remove,
135 .id_table = tps65086_id_table,
137 module_i2c_driver(tps65086_driver);
139 MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
140 MODULE_DESCRIPTION("TPS65086 PMIC Driver");
141 MODULE_LICENSE("GPL v2");