mfd: tps65090: Don't tell child devices we have an IRQ if we don't
[deliverable/linux.git] / drivers / mfd / tps65090.c
CommitLineData
3c33be06
VB
1/*
2 * Core driver for TI TPS65090 PMIC family
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5
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.
9
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
13 * more details.
14
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/>.
17 */
18
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>
40719314
LD
28#include <linux/of.h>
29#include <linux/of_device.h>
3c33be06
VB
30#include <linux/err.h>
31
32#define NUM_INT_REG 2
33#define TOTAL_NUM_REG 0x18
34
35/* interrupt status registers */
36#define TPS65090_INT_STS 0x0
37#define TPS65090_INT_STS2 0x1
38
39/* interrupt mask registers */
40#define TPS65090_INT_MSK 0x2
41#define TPS65090_INT_MSK2 0x3
42
759f2598
LD
43#define TPS65090_INT1_MASK_VAC_STATUS_CHANGE 1
44#define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE 2
45#define TPS65090_INT1_MASK_BAT_STATUS_CHANGE 3
46#define TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE 4
47#define TPS65090_INT1_MASK_CHARGING_COMPLETE 5
48#define TPS65090_INT1_MASK_OVERLOAD_DCDC1 6
49#define TPS65090_INT1_MASK_OVERLOAD_DCDC2 7
50#define TPS65090_INT2_MASK_OVERLOAD_DCDC3 0
51#define TPS65090_INT2_MASK_OVERLOAD_FET1 1
52#define TPS65090_INT2_MASK_OVERLOAD_FET2 2
53#define TPS65090_INT2_MASK_OVERLOAD_FET3 3
54#define TPS65090_INT2_MASK_OVERLOAD_FET4 4
55#define TPS65090_INT2_MASK_OVERLOAD_FET5 5
56#define TPS65090_INT2_MASK_OVERLOAD_FET6 6
57#define TPS65090_INT2_MASK_OVERLOAD_FET7 7
3c33be06 58
36c772e3
RK
59static struct resource charger_resources[] = {
60 {
61 .start = TPS65090_IRQ_VAC_STATUS_CHANGE,
62 .end = TPS65090_IRQ_VAC_STATUS_CHANGE,
63 .flags = IORESOURCE_IRQ,
64 }
65};
66
7d811771
DA
67enum tps65090_cells {
68 PMIC = 0,
69 CHARGER = 1,
70};
71
72static struct mfd_cell tps65090s[] = {
73 [PMIC] = {
b7e53786 74 .name = "tps65090-pmic",
3c33be06 75 },
7d811771 76 [CHARGER] = {
e2e8ffc9 77 .name = "tps65090-charger",
36c772e3
RK
78 .num_resources = ARRAY_SIZE(charger_resources),
79 .resources = &charger_resources[0],
b50cf35b 80 .of_compatible = "ti,tps65090-charger",
3c33be06
VB
81 },
82};
83
759f2598
LD
84static const struct regmap_irq tps65090_irqs[] = {
85 /* INT1 IRQs*/
86 [TPS65090_IRQ_VAC_STATUS_CHANGE] = {
87 .mask = TPS65090_INT1_MASK_VAC_STATUS_CHANGE,
88 },
89 [TPS65090_IRQ_VSYS_STATUS_CHANGE] = {
90 .mask = TPS65090_INT1_MASK_VSYS_STATUS_CHANGE,
91 },
92 [TPS65090_IRQ_BAT_STATUS_CHANGE] = {
93 .mask = TPS65090_INT1_MASK_BAT_STATUS_CHANGE,
94 },
95 [TPS65090_IRQ_CHARGING_STATUS_CHANGE] = {
96 .mask = TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE,
97 },
98 [TPS65090_IRQ_CHARGING_COMPLETE] = {
99 .mask = TPS65090_INT1_MASK_CHARGING_COMPLETE,
100 },
101 [TPS65090_IRQ_OVERLOAD_DCDC1] = {
102 .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC1,
103 },
104 [TPS65090_IRQ_OVERLOAD_DCDC2] = {
105 .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC2,
106 },
107 /* INT2 IRQs*/
108 [TPS65090_IRQ_OVERLOAD_DCDC3] = {
109 .reg_offset = 1,
110 .mask = TPS65090_INT2_MASK_OVERLOAD_DCDC3,
111 },
112 [TPS65090_IRQ_OVERLOAD_FET1] = {
113 .reg_offset = 1,
114 .mask = TPS65090_INT2_MASK_OVERLOAD_FET1,
115 },
116 [TPS65090_IRQ_OVERLOAD_FET2] = {
117 .reg_offset = 1,
118 .mask = TPS65090_INT2_MASK_OVERLOAD_FET2,
119 },
120 [TPS65090_IRQ_OVERLOAD_FET3] = {
121 .reg_offset = 1,
122 .mask = TPS65090_INT2_MASK_OVERLOAD_FET3,
123 },
124 [TPS65090_IRQ_OVERLOAD_FET4] = {
125 .reg_offset = 1,
126 .mask = TPS65090_INT2_MASK_OVERLOAD_FET4,
127 },
128 [TPS65090_IRQ_OVERLOAD_FET5] = {
129 .reg_offset = 1,
130 .mask = TPS65090_INT2_MASK_OVERLOAD_FET5,
131 },
132 [TPS65090_IRQ_OVERLOAD_FET6] = {
133 .reg_offset = 1,
134 .mask = TPS65090_INT2_MASK_OVERLOAD_FET6,
135 },
136 [TPS65090_IRQ_OVERLOAD_FET7] = {
137 .reg_offset = 1,
138 .mask = TPS65090_INT2_MASK_OVERLOAD_FET7,
139 },
140};
3c33be06 141
759f2598
LD
142static struct regmap_irq_chip tps65090_irq_chip = {
143 .name = "tps65090",
144 .irqs = tps65090_irqs,
145 .num_irqs = ARRAY_SIZE(tps65090_irqs),
146 .num_regs = NUM_INT_REG,
147 .status_base = TPS65090_INT_STS,
148 .mask_base = TPS65090_INT_MSK,
149 .mask_invert = true,
150};
3c33be06
VB
151
152static bool is_volatile_reg(struct device *dev, unsigned int reg)
153{
759f2598 154 if ((reg == TPS65090_INT_STS) || (reg == TPS65090_INT_STS2))
3c33be06
VB
155 return true;
156 else
157 return false;
158}
159
160static const struct regmap_config tps65090_regmap_config = {
161 .reg_bits = 8,
162 .val_bits = 8,
163 .max_register = TOTAL_NUM_REG,
164 .num_reg_defaults_raw = TOTAL_NUM_REG,
165 .cache_type = REGCACHE_RBTREE,
166 .volatile_reg = is_volatile_reg,
167};
168
40719314
LD
169#ifdef CONFIG_OF
170static const struct of_device_id tps65090_of_match[] = {
171 { .compatible = "ti,tps65090",},
172 {},
173};
174MODULE_DEVICE_TABLE(of, tps65090_of_match);
175#endif
176
f791be49 177static int tps65090_i2c_probe(struct i2c_client *client,
3c33be06
VB
178 const struct i2c_device_id *id)
179{
334a41ce 180 struct tps65090_platform_data *pdata = dev_get_platdata(&client->dev);
40719314 181 int irq_base = 0;
3c33be06
VB
182 struct tps65090 *tps65090;
183 int ret;
184
40719314
LD
185 if (!pdata && !client->dev.of_node) {
186 dev_err(&client->dev,
187 "tps65090 requires platform data or of_node\n");
3c33be06
VB
188 return -EINVAL;
189 }
190
40719314
LD
191 if (pdata)
192 irq_base = pdata->irq_base;
193
e8e6f047
LD
194 tps65090 = devm_kzalloc(&client->dev, sizeof(*tps65090), GFP_KERNEL);
195 if (!tps65090) {
196 dev_err(&client->dev, "mem alloc for tps65090 failed\n");
3c33be06 197 return -ENOMEM;
e8e6f047 198 }
3c33be06 199
3c33be06
VB
200 tps65090->dev = &client->dev;
201 i2c_set_clientdata(client, tps65090);
202
3863db3e 203 tps65090->rmap = devm_regmap_init_i2c(client, &tps65090_regmap_config);
3c33be06 204 if (IS_ERR(tps65090->rmap)) {
b683a0a6
AL
205 ret = PTR_ERR(tps65090->rmap);
206 dev_err(&client->dev, "regmap_init failed with err: %d\n", ret);
759f2598
LD
207 return ret;
208 }
209
210 if (client->irq) {
211 ret = regmap_add_irq_chip(tps65090->rmap, client->irq,
40719314 212 IRQF_ONESHOT | IRQF_TRIGGER_LOW, irq_base,
759f2598
LD
213 &tps65090_irq_chip, &tps65090->irq_data);
214 if (ret) {
215 dev_err(&client->dev,
216 "IRQ init failed with err: %d\n", ret);
217 return ret;
218 }
7d811771
DA
219 } else {
220 /* Don't tell children they have an IRQ that'll never fire */
221 tps65090s[CHARGER].num_resources = 0;
b683a0a6 222 }
3c33be06
VB
223
224 ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
759f2598 225 ARRAY_SIZE(tps65090s), NULL,
4f979ed5 226 0, regmap_irq_get_domain(tps65090->irq_data));
3c33be06
VB
227 if (ret) {
228 dev_err(&client->dev, "add mfd devices failed with err: %d\n",
229 ret);
1d88f7a0 230 goto err_irq_exit;
3c33be06
VB
231 }
232
233 return 0;
234
3c33be06
VB
235err_irq_exit:
236 if (client->irq)
759f2598 237 regmap_del_irq_chip(client->irq, tps65090->irq_data);
3c33be06
VB
238 return ret;
239}
240
4740f73f 241static int tps65090_i2c_remove(struct i2c_client *client)
3c33be06
VB
242{
243 struct tps65090 *tps65090 = i2c_get_clientdata(client);
244
245 mfd_remove_devices(tps65090->dev);
3c33be06 246 if (client->irq)
759f2598 247 regmap_del_irq_chip(client->irq, tps65090->irq_data);
3c33be06
VB
248
249 return 0;
250}
251
3c33be06
VB
252static const struct i2c_device_id tps65090_id_table[] = {
253 { "tps65090", 0 },
254 { },
255};
256MODULE_DEVICE_TABLE(i2c, tps65090_id_table);
257
258static struct i2c_driver tps65090_driver = {
259 .driver = {
260 .name = "tps65090",
261 .owner = THIS_MODULE,
40719314 262 .of_match_table = of_match_ptr(tps65090_of_match),
3c33be06
VB
263 },
264 .probe = tps65090_i2c_probe,
84449216 265 .remove = tps65090_i2c_remove,
3c33be06
VB
266 .id_table = tps65090_id_table,
267};
268
269static int __init tps65090_init(void)
270{
271 return i2c_add_driver(&tps65090_driver);
272}
273subsys_initcall(tps65090_init);
274
275static void __exit tps65090_exit(void)
276{
277 i2c_del_driver(&tps65090_driver);
278}
279module_exit(tps65090_exit);
280
281MODULE_DESCRIPTION("TPS65090 core driver");
282MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
283MODULE_LICENSE("GPL v2");
This page took 0.179847 seconds and 5 git commands to generate.