1 // SPDX-License-Identifier: GPL-2.0-only
3 * Core driver for TI TPS65090 PMIC family
5 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
7 * Author: Venu Byravarasu <vbyravarasu@nvidia.com>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/mutex.h>
15 #include <linux/slab.h>
16 #include <linux/i2c.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mfd/tps65090.h>
20 #include <linux/err.h>
24 #define TPS65090_INT1_MASK_VAC_STATUS_CHANGE 1
25 #define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE 2
26 #define TPS65090_INT1_MASK_BAT_STATUS_CHANGE 3
27 #define TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE 4
28 #define TPS65090_INT1_MASK_CHARGING_COMPLETE 5
29 #define TPS65090_INT1_MASK_OVERLOAD_DCDC1 6
30 #define TPS65090_INT1_MASK_OVERLOAD_DCDC2 7
31 #define TPS65090_INT2_MASK_OVERLOAD_DCDC3 0
32 #define TPS65090_INT2_MASK_OVERLOAD_FET1 1
33 #define TPS65090_INT2_MASK_OVERLOAD_FET2 2
34 #define TPS65090_INT2_MASK_OVERLOAD_FET3 3
35 #define TPS65090_INT2_MASK_OVERLOAD_FET4 4
36 #define TPS65090_INT2_MASK_OVERLOAD_FET5 5
37 #define TPS65090_INT2_MASK_OVERLOAD_FET6 6
38 #define TPS65090_INT2_MASK_OVERLOAD_FET7 7
40 static const struct resource charger_resources
[] = {
42 .start
= TPS65090_IRQ_VAC_STATUS_CHANGE
,
43 .end
= TPS65090_IRQ_VAC_STATUS_CHANGE
,
44 .flags
= IORESOURCE_IRQ
,
53 static struct mfd_cell tps65090s
[] = {
55 .name
= "tps65090-pmic",
58 .name
= "tps65090-charger",
59 .num_resources
= ARRAY_SIZE(charger_resources
),
60 .resources
= &charger_resources
[0],
61 .of_compatible
= "ti,tps65090-charger",
65 static const struct regmap_irq tps65090_irqs
[] = {
67 [TPS65090_IRQ_VAC_STATUS_CHANGE
] = {
68 .mask
= TPS65090_INT1_MASK_VAC_STATUS_CHANGE
,
70 [TPS65090_IRQ_VSYS_STATUS_CHANGE
] = {
71 .mask
= TPS65090_INT1_MASK_VSYS_STATUS_CHANGE
,
73 [TPS65090_IRQ_BAT_STATUS_CHANGE
] = {
74 .mask
= TPS65090_INT1_MASK_BAT_STATUS_CHANGE
,
76 [TPS65090_IRQ_CHARGING_STATUS_CHANGE
] = {
77 .mask
= TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE
,
79 [TPS65090_IRQ_CHARGING_COMPLETE
] = {
80 .mask
= TPS65090_INT1_MASK_CHARGING_COMPLETE
,
82 [TPS65090_IRQ_OVERLOAD_DCDC1
] = {
83 .mask
= TPS65090_INT1_MASK_OVERLOAD_DCDC1
,
85 [TPS65090_IRQ_OVERLOAD_DCDC2
] = {
86 .mask
= TPS65090_INT1_MASK_OVERLOAD_DCDC2
,
89 [TPS65090_IRQ_OVERLOAD_DCDC3
] = {
91 .mask
= TPS65090_INT2_MASK_OVERLOAD_DCDC3
,
93 [TPS65090_IRQ_OVERLOAD_FET1
] = {
95 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET1
,
97 [TPS65090_IRQ_OVERLOAD_FET2
] = {
99 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET2
,
101 [TPS65090_IRQ_OVERLOAD_FET3
] = {
103 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET3
,
105 [TPS65090_IRQ_OVERLOAD_FET4
] = {
107 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET4
,
109 [TPS65090_IRQ_OVERLOAD_FET5
] = {
111 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET5
,
113 [TPS65090_IRQ_OVERLOAD_FET6
] = {
115 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET6
,
117 [TPS65090_IRQ_OVERLOAD_FET7
] = {
119 .mask
= TPS65090_INT2_MASK_OVERLOAD_FET7
,
123 static const struct regmap_irq_chip tps65090_irq_chip
= {
125 .irqs
= tps65090_irqs
,
126 .num_irqs
= ARRAY_SIZE(tps65090_irqs
),
127 .num_regs
= NUM_INT_REG
,
128 .status_base
= TPS65090_REG_INTR_STS
,
129 .unmask_base
= TPS65090_REG_INTR_MASK
,
132 static bool is_volatile_reg(struct device
*dev
, unsigned int reg
)
134 /* Nearly all registers have status bits mixed in, except a few */
136 case TPS65090_REG_INTR_MASK
:
137 case TPS65090_REG_INTR_MASK2
:
138 case TPS65090_REG_CG_CTRL0
:
139 case TPS65090_REG_CG_CTRL1
:
140 case TPS65090_REG_CG_CTRL2
:
141 case TPS65090_REG_CG_CTRL3
:
142 case TPS65090_REG_CG_CTRL4
:
143 case TPS65090_REG_CG_CTRL5
:
149 static const struct regmap_config tps65090_regmap_config
= {
152 .max_register
= TPS65090_MAX_REG
,
153 .num_reg_defaults_raw
= TPS65090_NUM_REGS
,
154 .cache_type
= REGCACHE_MAPLE
,
155 .volatile_reg
= is_volatile_reg
,
159 static const struct of_device_id tps65090_of_match
[] = {
160 { .compatible
= "ti,tps65090",},
165 static int tps65090_i2c_probe(struct i2c_client
*client
)
167 struct tps65090_platform_data
*pdata
= dev_get_platdata(&client
->dev
);
169 struct tps65090
*tps65090
;
172 if (!pdata
&& !client
->dev
.of_node
) {
173 dev_err(&client
->dev
,
174 "tps65090 requires platform data or of_node\n");
179 irq_base
= pdata
->irq_base
;
181 tps65090
= devm_kzalloc(&client
->dev
, sizeof(*tps65090
), GFP_KERNEL
);
185 tps65090
->dev
= &client
->dev
;
186 i2c_set_clientdata(client
, tps65090
);
188 tps65090
->rmap
= devm_regmap_init_i2c(client
, &tps65090_regmap_config
);
189 if (IS_ERR(tps65090
->rmap
)) {
190 ret
= PTR_ERR(tps65090
->rmap
);
191 dev_err(&client
->dev
, "regmap_init failed with err: %d\n", ret
);
196 ret
= regmap_add_irq_chip(tps65090
->rmap
, client
->irq
,
197 IRQF_ONESHOT
| IRQF_TRIGGER_LOW
, irq_base
,
198 &tps65090_irq_chip
, &tps65090
->irq_data
);
200 dev_err(&client
->dev
,
201 "IRQ init failed with err: %d\n", ret
);
205 /* Don't tell children they have an IRQ that'll never fire */
206 tps65090s
[CHARGER
].num_resources
= 0;
209 ret
= mfd_add_devices(tps65090
->dev
, -1, tps65090s
,
210 ARRAY_SIZE(tps65090s
), NULL
,
211 0, regmap_irq_get_domain(tps65090
->irq_data
));
213 dev_err(&client
->dev
, "add mfd devices failed with err: %d\n",
222 regmap_del_irq_chip(client
->irq
, tps65090
->irq_data
);
227 static const struct i2c_device_id tps65090_id_table
[] = {
232 static struct i2c_driver tps65090_driver
= {
235 .suppress_bind_attrs
= true,
236 .of_match_table
= of_match_ptr(tps65090_of_match
),
238 .probe
= tps65090_i2c_probe
,
239 .id_table
= tps65090_id_table
,
242 static int __init
tps65090_init(void)
244 return i2c_add_driver(&tps65090_driver
);
246 subsys_initcall(tps65090_init
);