2 * Core driver for TI TPS65090 PMIC family
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
6 * Author: Venu Byravarasu <vbyravarasu@nvidia.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/mutex.h>
26 #include <linux/slab.h>
27 #include <linux/i2c.h>
28 #include <linux/mfd/core.h>
29 #include <linux/mfd/tps65090.h>
31 #include <linux/of_device.h>
32 #include <linux/err.h>
36 #define TPS65090_INT1_MASK_VAC_STATUS_CHANGE 1
37 #define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE 2
38 #define TPS65090_INT1_MASK_BAT_STATUS_CHANGE 3
39 #define TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE 4
40 #define TPS65090_INT1_MASK_CHARGING_COMPLETE 5
41 #define TPS65090_INT1_MASK_OVERLOAD_DCDC1 6
42 #define TPS65090_INT1_MASK_OVERLOAD_DCDC2 7
43 #define TPS65090_INT2_MASK_OVERLOAD_DCDC3 0
44 #define TPS65090_INT2_MASK_OVERLOAD_FET1 1
45 #define TPS65090_INT2_MASK_OVERLOAD_FET2 2
46 #define TPS65090_INT2_MASK_OVERLOAD_FET3 3
47 #define TPS65090_INT2_MASK_OVERLOAD_FET4 4
48 #define TPS65090_INT2_MASK_OVERLOAD_FET5 5
49 #define TPS65090_INT2_MASK_OVERLOAD_FET6 6
50 #define TPS65090_INT2_MASK_OVERLOAD_FET7 7
52 static struct resource charger_resources
[] = {
54 .start
= TPS65090_IRQ_VAC_STATUS_CHANGE
,
55 .end
= TPS65090_IRQ_VAC_STATUS_CHANGE
,
56 .flags
= IORESOURCE_IRQ
,
65 static struct mfd_cell tps65090s
[] = {
67 .name
= "tps65090-pmic",
70 .name
= "tps65090-charger",
71 .num_resources
= ARRAY_SIZE(charger_resources
),
72 .resources
= &charger_resources
[0],
73 .of_compatible
= "ti,tps65090-charger",
77 static const struct regmap_irq tps65090_irqs
[] = {
79 [TPS65090_IRQ_VAC_STATUS_CHANGE
] = {
80 .mask
= TPS65090_INT1_MASK_VAC_STATUS_CHANGE
,
82 [TPS65090_IRQ_VSYS_STATUS_CHANGE
] = {
83 .mask
= TPS65090_INT1_MASK_VSYS_STATUS_CHANGE
,
85 [TPS65090_IRQ_BAT_STATUS_CHANGE
] = {
86 .mask
= TPS65090_INT1_MASK_BAT_STATUS_CHANGE
,
88 [TPS65090_IRQ_CHARGING_STATUS_CHANGE
] = {
89 .mask
= TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE
,
91 [TPS65090_IRQ_CHARGING_COMPLETE
] = {
92 .mask
= TPS65090_INT1_MASK_CHARGING_COMPLETE
,
94 [TPS65090_IRQ_OVERLOAD_DCDC1
] = {
95 .mask
= TPS65090_INT1_MASK_OVERLOAD_DCDC1
,
97 [TPS65090_IRQ_OVERLOAD_DCDC2
] = {
98 .mask
= TPS65090_INT1_MASK_OVERLOAD_DCDC2
,
101 [TPS65090_IRQ_OVERLOAD_DCDC3
] = {
103 .mask
= TPS65090_INT2_MASK_OVERLOAD_DCDC3
,
105 [TPS65090_IRQ_OVERLOAD_FET1
] = {
107 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET1
,
109 [TPS65090_IRQ_OVERLOAD_FET2
] = {
111 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET2
,
113 [TPS65090_IRQ_OVERLOAD_FET3
] = {
115 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET3
,
117 [TPS65090_IRQ_OVERLOAD_FET4
] = {
119 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET4
,
121 [TPS65090_IRQ_OVERLOAD_FET5
] = {
123 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET5
,
125 [TPS65090_IRQ_OVERLOAD_FET6
] = {
127 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET6
,
129 [TPS65090_IRQ_OVERLOAD_FET7
] = {
131 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET7
,
135 static struct regmap_irq_chip tps65090_irq_chip
= {
137 .irqs
= tps65090_irqs
,
138 .num_irqs
= ARRAY_SIZE(tps65090_irqs
),
139 .num_regs
= NUM_INT_REG
,
140 .status_base
= TPS65090_REG_INTR_STS
,
141 .mask_base
= TPS65090_REG_INTR_MASK
,
145 static bool is_volatile_reg(struct device
*dev
, unsigned int reg
)
147 /* Nearly all registers have status bits mixed in, except a few */
149 case TPS65090_REG_INTR_MASK
:
150 case TPS65090_REG_INTR_MASK2
:
151 case TPS65090_REG_CG_CTRL0
:
152 case TPS65090_REG_CG_CTRL1
:
153 case TPS65090_REG_CG_CTRL2
:
154 case TPS65090_REG_CG_CTRL3
:
155 case TPS65090_REG_CG_CTRL4
:
156 case TPS65090_REG_CG_CTRL5
:
162 static const struct regmap_config tps65090_regmap_config
= {
165 .max_register
= TPS65090_MAX_REG
,
166 .num_reg_defaults_raw
= TPS65090_NUM_REGS
,
167 .cache_type
= REGCACHE_RBTREE
,
168 .volatile_reg
= is_volatile_reg
,
172 static const struct of_device_id tps65090_of_match
[] = {
173 { .compatible
= "ti,tps65090",},
178 static int tps65090_i2c_probe(struct i2c_client
*client
,
179 const struct i2c_device_id
*id
)
181 struct tps65090_platform_data
*pdata
= dev_get_platdata(&client
->dev
);
183 struct tps65090
*tps65090
;
186 if (!pdata
&& !client
->dev
.of_node
) {
187 dev_err(&client
->dev
,
188 "tps65090 requires platform data or of_node\n");
193 irq_base
= pdata
->irq_base
;
195 tps65090
= devm_kzalloc(&client
->dev
, sizeof(*tps65090
), GFP_KERNEL
);
199 tps65090
->dev
= &client
->dev
;
200 i2c_set_clientdata(client
, tps65090
);
202 tps65090
->rmap
= devm_regmap_init_i2c(client
, &tps65090_regmap_config
);
203 if (IS_ERR(tps65090
->rmap
)) {
204 ret
= PTR_ERR(tps65090
->rmap
);
205 dev_err(&client
->dev
, "regmap_init failed with err: %d\n", ret
);
210 ret
= regmap_add_irq_chip(tps65090
->rmap
, client
->irq
,
211 IRQF_ONESHOT
| IRQF_TRIGGER_LOW
, irq_base
,
212 &tps65090_irq_chip
, &tps65090
->irq_data
);
214 dev_err(&client
->dev
,
215 "IRQ init failed with err: %d\n", ret
);
219 /* Don't tell children they have an IRQ that'll never fire */
220 tps65090s
[CHARGER
].num_resources
= 0;
223 ret
= mfd_add_devices(tps65090
->dev
, -1, tps65090s
,
224 ARRAY_SIZE(tps65090s
), NULL
,
225 0, regmap_irq_get_domain(tps65090
->irq_data
));
227 dev_err(&client
->dev
, "add mfd devices failed with err: %d\n",
236 regmap_del_irq_chip(client
->irq
, tps65090
->irq_data
);
241 static const struct i2c_device_id tps65090_id_table
[] = {
246 static struct i2c_driver tps65090_driver
= {
249 .suppress_bind_attrs
= true,
250 .of_match_table
= of_match_ptr(tps65090_of_match
),
252 .probe
= tps65090_i2c_probe
,
253 .id_table
= tps65090_id_table
,
256 static int __init
tps65090_init(void)
258 return i2c_add_driver(&tps65090_driver
);
260 subsys_initcall(tps65090_init
);