2 * Core driver for TI TPS65090 PMIC family
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/mutex.h>
24 #include <linux/slab.h>
25 #include <linux/i2c.h>
26 #include <linux/mfd/core.h>
27 #include <linux/mfd/tps65090.h>
28 #include <linux/err.h>
31 #define TOTAL_NUM_REG 0x18
33 /* interrupt status registers */
34 #define TPS65090_INT_STS 0x0
35 #define TPS65090_INT_STS2 0x1
37 /* interrupt mask registers */
38 #define TPS65090_INT_MSK 0x2
39 #define TPS65090_INT_MSK2 0x3
41 #define TPS65090_INT1_MASK_VAC_STATUS_CHANGE 1
42 #define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE 2
43 #define TPS65090_INT1_MASK_BAT_STATUS_CHANGE 3
44 #define TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE 4
45 #define TPS65090_INT1_MASK_CHARGING_COMPLETE 5
46 #define TPS65090_INT1_MASK_OVERLOAD_DCDC1 6
47 #define TPS65090_INT1_MASK_OVERLOAD_DCDC2 7
48 #define TPS65090_INT2_MASK_OVERLOAD_DCDC3 0
49 #define TPS65090_INT2_MASK_OVERLOAD_FET1 1
50 #define TPS65090_INT2_MASK_OVERLOAD_FET2 2
51 #define TPS65090_INT2_MASK_OVERLOAD_FET3 3
52 #define TPS65090_INT2_MASK_OVERLOAD_FET4 4
53 #define TPS65090_INT2_MASK_OVERLOAD_FET5 5
54 #define TPS65090_INT2_MASK_OVERLOAD_FET6 6
55 #define TPS65090_INT2_MASK_OVERLOAD_FET7 7
57 static struct mfd_cell tps65090s
[] = {
59 .name
= "tps65090-pmic",
62 .name
= "tps65090-charger",
66 static const struct regmap_irq tps65090_irqs
[] = {
68 [TPS65090_IRQ_VAC_STATUS_CHANGE
] = {
69 .mask
= TPS65090_INT1_MASK_VAC_STATUS_CHANGE
,
71 [TPS65090_IRQ_VSYS_STATUS_CHANGE
] = {
72 .mask
= TPS65090_INT1_MASK_VSYS_STATUS_CHANGE
,
74 [TPS65090_IRQ_BAT_STATUS_CHANGE
] = {
75 .mask
= TPS65090_INT1_MASK_BAT_STATUS_CHANGE
,
77 [TPS65090_IRQ_CHARGING_STATUS_CHANGE
] = {
78 .mask
= TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE
,
80 [TPS65090_IRQ_CHARGING_COMPLETE
] = {
81 .mask
= TPS65090_INT1_MASK_CHARGING_COMPLETE
,
83 [TPS65090_IRQ_OVERLOAD_DCDC1
] = {
84 .mask
= TPS65090_INT1_MASK_OVERLOAD_DCDC1
,
86 [TPS65090_IRQ_OVERLOAD_DCDC2
] = {
87 .mask
= TPS65090_INT1_MASK_OVERLOAD_DCDC2
,
90 [TPS65090_IRQ_OVERLOAD_DCDC3
] = {
92 .mask
= TPS65090_INT2_MASK_OVERLOAD_DCDC3
,
94 [TPS65090_IRQ_OVERLOAD_FET1
] = {
96 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET1
,
98 [TPS65090_IRQ_OVERLOAD_FET2
] = {
100 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET2
,
102 [TPS65090_IRQ_OVERLOAD_FET3
] = {
104 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET3
,
106 [TPS65090_IRQ_OVERLOAD_FET4
] = {
108 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET4
,
110 [TPS65090_IRQ_OVERLOAD_FET5
] = {
112 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET5
,
114 [TPS65090_IRQ_OVERLOAD_FET6
] = {
116 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET6
,
118 [TPS65090_IRQ_OVERLOAD_FET7
] = {
120 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET7
,
124 static struct regmap_irq_chip tps65090_irq_chip
= {
126 .irqs
= tps65090_irqs
,
127 .num_irqs
= ARRAY_SIZE(tps65090_irqs
),
128 .num_regs
= NUM_INT_REG
,
129 .status_base
= TPS65090_INT_STS
,
130 .mask_base
= TPS65090_INT_MSK
,
134 static bool is_volatile_reg(struct device
*dev
, unsigned int reg
)
136 if ((reg
== TPS65090_INT_STS
) || (reg
== TPS65090_INT_STS2
))
142 static const struct regmap_config tps65090_regmap_config
= {
145 .max_register
= TOTAL_NUM_REG
,
146 .num_reg_defaults_raw
= TOTAL_NUM_REG
,
147 .cache_type
= REGCACHE_RBTREE
,
148 .volatile_reg
= is_volatile_reg
,
151 static int tps65090_i2c_probe(struct i2c_client
*client
,
152 const struct i2c_device_id
*id
)
154 struct tps65090_platform_data
*pdata
= client
->dev
.platform_data
;
155 struct tps65090
*tps65090
;
159 dev_err(&client
->dev
, "tps65090 requires platform data\n");
163 tps65090
= devm_kzalloc(&client
->dev
, sizeof(*tps65090
), GFP_KERNEL
);
165 dev_err(&client
->dev
, "mem alloc for tps65090 failed\n");
169 tps65090
->dev
= &client
->dev
;
170 i2c_set_clientdata(client
, tps65090
);
172 tps65090
->rmap
= devm_regmap_init_i2c(client
, &tps65090_regmap_config
);
173 if (IS_ERR(tps65090
->rmap
)) {
174 ret
= PTR_ERR(tps65090
->rmap
);
175 dev_err(&client
->dev
, "regmap_init failed with err: %d\n", ret
);
180 ret
= regmap_add_irq_chip(tps65090
->rmap
, client
->irq
,
181 IRQF_ONESHOT
| IRQF_TRIGGER_LOW
, pdata
->irq_base
,
182 &tps65090_irq_chip
, &tps65090
->irq_data
);
184 dev_err(&client
->dev
,
185 "IRQ init failed with err: %d\n", ret
);
190 ret
= mfd_add_devices(tps65090
->dev
, -1, tps65090s
,
191 ARRAY_SIZE(tps65090s
), NULL
,
192 regmap_irq_chip_get_base(tps65090
->irq_data
), NULL
);
194 dev_err(&client
->dev
, "add mfd devices failed with err: %d\n",
203 regmap_del_irq_chip(client
->irq
, tps65090
->irq_data
);
207 static int tps65090_i2c_remove(struct i2c_client
*client
)
209 struct tps65090
*tps65090
= i2c_get_clientdata(client
);
211 mfd_remove_devices(tps65090
->dev
);
213 regmap_del_irq_chip(client
->irq
, tps65090
->irq_data
);
218 #ifdef CONFIG_PM_SLEEP
219 static int tps65090_suspend(struct device
*dev
)
221 struct i2c_client
*client
= to_i2c_client(dev
);
223 disable_irq(client
->irq
);
227 static int tps65090_resume(struct device
*dev
)
229 struct i2c_client
*client
= to_i2c_client(dev
);
231 enable_irq(client
->irq
);
236 static const struct dev_pm_ops tps65090_pm_ops
= {
237 SET_SYSTEM_SLEEP_PM_OPS(tps65090_suspend
, tps65090_resume
)
240 static const struct i2c_device_id tps65090_id_table
[] = {
244 MODULE_DEVICE_TABLE(i2c
, tps65090_id_table
);
246 static struct i2c_driver tps65090_driver
= {
249 .owner
= THIS_MODULE
,
250 .pm
= &tps65090_pm_ops
,
252 .probe
= tps65090_i2c_probe
,
253 .remove
= tps65090_i2c_remove
,
254 .id_table
= tps65090_id_table
,
257 static int __init
tps65090_init(void)
259 return i2c_add_driver(&tps65090_driver
);
261 subsys_initcall(tps65090_init
);
263 static void __exit
tps65090_exit(void)
265 i2c_del_driver(&tps65090_driver
);
267 module_exit(tps65090_exit
);
269 MODULE_DESCRIPTION("TPS65090 core driver");
270 MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
271 MODULE_LICENSE("GPL v2");