blob: c0f608e3ca9e5fc1fc0706666b8fcc4f89778567 [file] [log] [blame]
Graeme Gregory27c67502011-05-02 16:19:46 -05001/*
2 * tps65910.c -- TI TPS6591x
3 *
4 * Copyright 2010 Texas Instruments Inc.
5 *
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
7 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/init.h>
Laxman Dewangandc9913a2012-02-21 18:21:34 +053019#include <linux/err.h>
Graeme Gregory27c67502011-05-02 16:19:46 -050020#include <linux/slab.h>
21#include <linux/i2c.h>
Laxman Dewangan4aab3fa2012-11-13 19:33:58 +053022#include <linux/interrupt.h>
23#include <linux/irq.h>
24#include <linux/irqdomain.h>
Graeme Gregory27c67502011-05-02 16:19:46 -050025#include <linux/mfd/core.h>
Laxman Dewangandc9913a2012-02-21 18:21:34 +053026#include <linux/regmap.h>
Graeme Gregory27c67502011-05-02 16:19:46 -050027#include <linux/mfd/tps65910.h>
Sachin Kamat1fead3f2013-10-16 14:26:55 +053028#include <linux/of.h>
Rhyland Kleincd4209c2012-05-11 11:36:26 +020029#include <linux/of_device.h>
Graeme Gregory27c67502011-05-02 16:19:46 -050030
Venu Byravarasu5863eab2012-09-21 16:25:36 +053031static struct resource rtc_resources[] = {
32 {
33 .start = TPS65910_IRQ_RTC_ALARM,
34 .end = TPS65910_IRQ_RTC_ALARM,
35 .flags = IORESOURCE_IRQ,
36 }
37};
38
Graeme Gregory27c67502011-05-02 16:19:46 -050039static struct mfd_cell tps65910s[] = {
40 {
Laxman Dewangan32df9862012-05-11 15:07:44 +020041 .name = "tps65910-gpio",
42 },
43 {
Graeme Gregory27c67502011-05-02 16:19:46 -050044 .name = "tps65910-pmic",
45 },
46 {
47 .name = "tps65910-rtc",
Venu Byravarasu5863eab2012-09-21 16:25:36 +053048 .num_resources = ARRAY_SIZE(rtc_resources),
49 .resources = &rtc_resources[0],
Graeme Gregory27c67502011-05-02 16:19:46 -050050 },
51 {
52 .name = "tps65910-power",
53 },
54};
55
56
Laxman Dewangan4aab3fa2012-11-13 19:33:58 +053057static const struct regmap_irq tps65911_irqs[] = {
58 /* INT_STS */
59 [TPS65911_IRQ_PWRHOLD_F] = {
60 .mask = INT_MSK_PWRHOLD_F_IT_MSK_MASK,
61 .reg_offset = 0,
62 },
63 [TPS65911_IRQ_VBAT_VMHI] = {
64 .mask = INT_MSK_VMBHI_IT_MSK_MASK,
65 .reg_offset = 0,
66 },
67 [TPS65911_IRQ_PWRON] = {
68 .mask = INT_MSK_PWRON_IT_MSK_MASK,
69 .reg_offset = 0,
70 },
71 [TPS65911_IRQ_PWRON_LP] = {
72 .mask = INT_MSK_PWRON_LP_IT_MSK_MASK,
73 .reg_offset = 0,
74 },
75 [TPS65911_IRQ_PWRHOLD_R] = {
76 .mask = INT_MSK_PWRHOLD_R_IT_MSK_MASK,
77 .reg_offset = 0,
78 },
79 [TPS65911_IRQ_HOTDIE] = {
80 .mask = INT_MSK_HOTDIE_IT_MSK_MASK,
81 .reg_offset = 0,
82 },
83 [TPS65911_IRQ_RTC_ALARM] = {
84 .mask = INT_MSK_RTC_ALARM_IT_MSK_MASK,
85 .reg_offset = 0,
86 },
87 [TPS65911_IRQ_RTC_PERIOD] = {
88 .mask = INT_MSK_RTC_PERIOD_IT_MSK_MASK,
89 .reg_offset = 0,
90 },
91
92 /* INT_STS2 */
93 [TPS65911_IRQ_GPIO0_R] = {
94 .mask = INT_MSK2_GPIO0_R_IT_MSK_MASK,
95 .reg_offset = 1,
96 },
97 [TPS65911_IRQ_GPIO0_F] = {
98 .mask = INT_MSK2_GPIO0_F_IT_MSK_MASK,
99 .reg_offset = 1,
100 },
101 [TPS65911_IRQ_GPIO1_R] = {
102 .mask = INT_MSK2_GPIO1_R_IT_MSK_MASK,
103 .reg_offset = 1,
104 },
105 [TPS65911_IRQ_GPIO1_F] = {
106 .mask = INT_MSK2_GPIO1_F_IT_MSK_MASK,
107 .reg_offset = 1,
108 },
109 [TPS65911_IRQ_GPIO2_R] = {
110 .mask = INT_MSK2_GPIO2_R_IT_MSK_MASK,
111 .reg_offset = 1,
112 },
113 [TPS65911_IRQ_GPIO2_F] = {
114 .mask = INT_MSK2_GPIO2_F_IT_MSK_MASK,
115 .reg_offset = 1,
116 },
117 [TPS65911_IRQ_GPIO3_R] = {
118 .mask = INT_MSK2_GPIO3_R_IT_MSK_MASK,
119 .reg_offset = 1,
120 },
121 [TPS65911_IRQ_GPIO3_F] = {
122 .mask = INT_MSK2_GPIO3_F_IT_MSK_MASK,
123 .reg_offset = 1,
124 },
125
126 /* INT_STS2 */
127 [TPS65911_IRQ_GPIO4_R] = {
128 .mask = INT_MSK3_GPIO4_R_IT_MSK_MASK,
129 .reg_offset = 2,
130 },
131 [TPS65911_IRQ_GPIO4_F] = {
132 .mask = INT_MSK3_GPIO4_F_IT_MSK_MASK,
133 .reg_offset = 2,
134 },
135 [TPS65911_IRQ_GPIO5_R] = {
136 .mask = INT_MSK3_GPIO5_R_IT_MSK_MASK,
137 .reg_offset = 2,
138 },
139 [TPS65911_IRQ_GPIO5_F] = {
140 .mask = INT_MSK3_GPIO5_F_IT_MSK_MASK,
141 .reg_offset = 2,
142 },
143 [TPS65911_IRQ_WTCHDG] = {
144 .mask = INT_MSK3_WTCHDG_IT_MSK_MASK,
145 .reg_offset = 2,
146 },
147 [TPS65911_IRQ_VMBCH2_H] = {
148 .mask = INT_MSK3_VMBCH2_H_IT_MSK_MASK,
149 .reg_offset = 2,
150 },
151 [TPS65911_IRQ_VMBCH2_L] = {
152 .mask = INT_MSK3_VMBCH2_L_IT_MSK_MASK,
153 .reg_offset = 2,
154 },
155 [TPS65911_IRQ_PWRDN] = {
156 .mask = INT_MSK3_PWRDN_IT_MSK_MASK,
157 .reg_offset = 2,
158 },
159};
160
161static const struct regmap_irq tps65910_irqs[] = {
162 /* INT_STS */
163 [TPS65910_IRQ_VBAT_VMBDCH] = {
164 .mask = TPS65910_INT_MSK_VMBDCH_IT_MSK_MASK,
165 .reg_offset = 0,
166 },
167 [TPS65910_IRQ_VBAT_VMHI] = {
168 .mask = TPS65910_INT_MSK_VMBHI_IT_MSK_MASK,
169 .reg_offset = 0,
170 },
171 [TPS65910_IRQ_PWRON] = {
172 .mask = TPS65910_INT_MSK_PWRON_IT_MSK_MASK,
173 .reg_offset = 0,
174 },
175 [TPS65910_IRQ_PWRON_LP] = {
176 .mask = TPS65910_INT_MSK_PWRON_LP_IT_MSK_MASK,
177 .reg_offset = 0,
178 },
179 [TPS65910_IRQ_PWRHOLD] = {
180 .mask = TPS65910_INT_MSK_PWRHOLD_IT_MSK_MASK,
181 .reg_offset = 0,
182 },
183 [TPS65910_IRQ_HOTDIE] = {
184 .mask = TPS65910_INT_MSK_HOTDIE_IT_MSK_MASK,
185 .reg_offset = 0,
186 },
187 [TPS65910_IRQ_RTC_ALARM] = {
188 .mask = TPS65910_INT_MSK_RTC_ALARM_IT_MSK_MASK,
189 .reg_offset = 0,
190 },
191 [TPS65910_IRQ_RTC_PERIOD] = {
192 .mask = TPS65910_INT_MSK_RTC_PERIOD_IT_MSK_MASK,
193 .reg_offset = 0,
194 },
195
196 /* INT_STS2 */
197 [TPS65910_IRQ_GPIO_R] = {
198 .mask = TPS65910_INT_MSK2_GPIO0_F_IT_MSK_MASK,
199 .reg_offset = 1,
200 },
201 [TPS65910_IRQ_GPIO_F] = {
202 .mask = TPS65910_INT_MSK2_GPIO0_R_IT_MSK_MASK,
203 .reg_offset = 1,
204 },
205};
206
207static struct regmap_irq_chip tps65911_irq_chip = {
208 .name = "tps65910",
209 .irqs = tps65911_irqs,
210 .num_irqs = ARRAY_SIZE(tps65911_irqs),
211 .num_regs = 3,
212 .irq_reg_stride = 2,
213 .status_base = TPS65910_INT_STS,
214 .mask_base = TPS65910_INT_MSK,
Kim, Milo0582c0f2012-11-29 06:42:12 +0000215 .ack_base = TPS65910_INT_STS,
Laxman Dewangan4aab3fa2012-11-13 19:33:58 +0530216};
217
218static struct regmap_irq_chip tps65910_irq_chip = {
219 .name = "tps65910",
220 .irqs = tps65910_irqs,
221 .num_irqs = ARRAY_SIZE(tps65910_irqs),
222 .num_regs = 2,
223 .irq_reg_stride = 2,
224 .status_base = TPS65910_INT_STS,
225 .mask_base = TPS65910_INT_MSK,
Kim, Milo0582c0f2012-11-29 06:42:12 +0000226 .ack_base = TPS65910_INT_STS,
Laxman Dewangan4aab3fa2012-11-13 19:33:58 +0530227};
228
229static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
230 struct tps65910_platform_data *pdata)
231{
232 int ret = 0;
233 static struct regmap_irq_chip *tps6591x_irqs_chip;
234
235 if (!irq) {
236 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
237 return -EINVAL;
238 }
239
240 if (!pdata) {
241 dev_warn(tps65910->dev, "No interrupt support, no pdata\n");
242 return -EINVAL;
243 }
244
245 switch (tps65910_chip_id(tps65910)) {
246 case TPS65910:
247 tps6591x_irqs_chip = &tps65910_irq_chip;
248 break;
249 case TPS65911:
250 tps6591x_irqs_chip = &tps65911_irq_chip;
251 break;
252 }
253
254 tps65910->chip_irq = irq;
255 ret = regmap_add_irq_chip(tps65910->regmap, tps65910->chip_irq,
256 IRQF_ONESHOT, pdata->irq_base,
257 tps6591x_irqs_chip, &tps65910->irq_data);
258 if (ret < 0)
259 dev_warn(tps65910->dev, "Failed to add irq_chip %d\n", ret);
260 return ret;
261}
262
263static int tps65910_irq_exit(struct tps65910 *tps65910)
264{
265 if (tps65910->chip_irq > 0)
266 regmap_del_irq_chip(tps65910->chip_irq, tps65910->irq_data);
267 return 0;
268}
269
Laxman Dewangandc9913a2012-02-21 18:21:34 +0530270static bool is_volatile_reg(struct device *dev, unsigned int reg)
271{
272 struct tps65910 *tps65910 = dev_get_drvdata(dev);
273
274 /*
275 * Caching all regulator registers.
276 * All regualator register address range is same for
277 * TPS65910 and TPS65911
278 */
279 if ((reg >= TPS65910_VIO) && (reg <= TPS65910_VDAC)) {
280 /* Check for non-existing register */
281 if (tps65910_chip_id(tps65910) == TPS65910)
282 if ((reg == TPS65911_VDDCTRL_OP) ||
283 (reg == TPS65911_VDDCTRL_SR))
284 return true;
285 return false;
286 }
287 return true;
288}
289
Laxman Dewangan39ecb032012-03-07 18:46:05 +0530290static const struct regmap_config tps65910_regmap_config = {
Laxman Dewangandc9913a2012-02-21 18:21:34 +0530291 .reg_bits = 8,
292 .val_bits = 8,
293 .volatile_reg = is_volatile_reg,
Laxman Dewangan3bf6bf92012-05-09 18:40:54 +0530294 .max_register = TPS65910_MAX_REGISTER - 1,
Laxman Dewangandc9913a2012-02-21 18:21:34 +0530295 .cache_type = REGCACHE_RBTREE,
296};
297
Bill Pembertonf791be42012-11-19 13:23:04 -0500298static int tps65910_ck32k_init(struct tps65910 *tps65910,
Johan Hovold712db992012-06-28 12:20:21 +0200299 struct tps65910_board *pmic_pdata)
300{
Johan Hovold712db992012-06-28 12:20:21 +0200301 int ret;
302
Johan Hovoldd02e83c2012-07-11 15:44:33 +0200303 if (!pmic_pdata->en_ck32k_xtal)
304 return 0;
305
306 ret = tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
Johan Hovold712db992012-06-28 12:20:21 +0200307 DEVCTRL_CK32K_CTRL_MASK);
Johan Hovoldd02e83c2012-07-11 15:44:33 +0200308 if (ret < 0) {
309 dev_err(tps65910->dev, "clear ck32k_ctrl failed: %d\n", ret);
310 return ret;
Johan Hovold712db992012-06-28 12:20:21 +0200311 }
312
313 return 0;
314}
315
Bill Pembertonf791be42012-11-19 13:23:04 -0500316static int tps65910_sleepinit(struct tps65910 *tps65910,
Laxman Dewangan201cf052012-04-18 12:13:51 +0200317 struct tps65910_board *pmic_pdata)
318{
319 struct device *dev = NULL;
320 int ret = 0;
321
322 dev = tps65910->dev;
323
324 if (!pmic_pdata->en_dev_slp)
325 return 0;
326
327 /* enabling SLEEP device state */
Rhyland Klein3f7e8272012-05-08 11:42:38 -0700328 ret = tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
Laxman Dewangan201cf052012-04-18 12:13:51 +0200329 DEVCTRL_DEV_SLP_MASK);
330 if (ret < 0) {
331 dev_err(dev, "set dev_slp failed: %d\n", ret);
332 goto err_sleep_init;
333 }
334
335 /* Return if there is no sleep keepon data. */
336 if (!pmic_pdata->slp_keepon)
337 return 0;
338
339 if (pmic_pdata->slp_keepon->therm_keepon) {
Rhyland Klein3f7e8272012-05-08 11:42:38 -0700340 ret = tps65910_reg_set_bits(tps65910,
341 TPS65910_SLEEP_KEEP_RES_ON,
Laxman Dewangan201cf052012-04-18 12:13:51 +0200342 SLEEP_KEEP_RES_ON_THERM_KEEPON_MASK);
343 if (ret < 0) {
344 dev_err(dev, "set therm_keepon failed: %d\n", ret);
345 goto disable_dev_slp;
346 }
347 }
348
349 if (pmic_pdata->slp_keepon->clkout32k_keepon) {
Rhyland Klein3f7e8272012-05-08 11:42:38 -0700350 ret = tps65910_reg_set_bits(tps65910,
351 TPS65910_SLEEP_KEEP_RES_ON,
Laxman Dewangan201cf052012-04-18 12:13:51 +0200352 SLEEP_KEEP_RES_ON_CLKOUT32K_KEEPON_MASK);
353 if (ret < 0) {
354 dev_err(dev, "set clkout32k_keepon failed: %d\n", ret);
355 goto disable_dev_slp;
356 }
357 }
358
359 if (pmic_pdata->slp_keepon->i2chs_keepon) {
Rhyland Klein3f7e8272012-05-08 11:42:38 -0700360 ret = tps65910_reg_set_bits(tps65910,
361 TPS65910_SLEEP_KEEP_RES_ON,
Laxman Dewangan201cf052012-04-18 12:13:51 +0200362 SLEEP_KEEP_RES_ON_I2CHS_KEEPON_MASK);
363 if (ret < 0) {
364 dev_err(dev, "set i2chs_keepon failed: %d\n", ret);
365 goto disable_dev_slp;
366 }
367 }
368
369 return 0;
370
371disable_dev_slp:
Rhyland Klein3f7e8272012-05-08 11:42:38 -0700372 tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
373 DEVCTRL_DEV_SLP_MASK);
Laxman Dewangan201cf052012-04-18 12:13:51 +0200374
375err_sleep_init:
376 return ret;
377}
378
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200379#ifdef CONFIG_OF
380static struct of_device_id tps65910_of_match[] = {
381 { .compatible = "ti,tps65910", .data = (void *)TPS65910},
382 { .compatible = "ti,tps65911", .data = (void *)TPS65911},
383 { },
384};
385MODULE_DEVICE_TABLE(of, tps65910_of_match);
386
387static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
388 int *chip_id)
389{
390 struct device_node *np = client->dev.of_node;
391 struct tps65910_board *board_info;
392 unsigned int prop;
393 const struct of_device_id *match;
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200394 int ret = 0;
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200395
396 match = of_match_device(tps65910_of_match, &client->dev);
397 if (!match) {
398 dev_err(&client->dev, "Failed to find matching dt id\n");
399 return NULL;
400 }
401
402 *chip_id = (int)match->data;
403
404 board_info = devm_kzalloc(&client->dev, sizeof(*board_info),
405 GFP_KERNEL);
406 if (!board_info) {
407 dev_err(&client->dev, "Failed to allocate pdata\n");
408 return NULL;
409 }
410
411 ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
412 if (!ret)
413 board_info->vmbch_threshold = prop;
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200414
415 ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
416 if (!ret)
417 board_info->vmbch2_threshold = prop;
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200418
Johan Hovoldbcc1dd42012-06-28 12:20:22 +0200419 prop = of_property_read_bool(np, "ti,en-ck32k-xtal");
420 board_info->en_ck32k_xtal = prop;
421
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200422 board_info->irq = client->irq;
423 board_info->irq_base = -1;
Bill Huangb079fa722012-08-19 18:07:56 -0700424 board_info->pm_off = of_property_read_bool(np,
425 "ti,system-power-controller");
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200426
427 return board_info;
428}
429#else
Samuel Ortiz7f65f742012-05-11 15:10:28 +0200430static inline
431struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
432 int *chip_id)
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200433{
434 return NULL;
435}
436#endif
Laxman Dewangan201cf052012-04-18 12:13:51 +0200437
Bill Huangb079fa722012-08-19 18:07:56 -0700438static struct i2c_client *tps65910_i2c_client;
439static void tps65910_power_off(void)
440{
441 struct tps65910 *tps65910;
442
443 tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
444
445 if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
446 DEVCTRL_PWR_OFF_MASK) < 0)
447 return;
448
449 tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
450 DEVCTRL_DEV_ON_MASK);
451}
452
Bill Pembertonf791be42012-11-19 13:23:04 -0500453static int tps65910_i2c_probe(struct i2c_client *i2c,
Mark Brown63745d42012-05-07 10:03:19 +0100454 const struct i2c_device_id *id)
Graeme Gregory27c67502011-05-02 16:19:46 -0500455{
456 struct tps65910 *tps65910;
Graeme Gregory2537df72011-05-02 16:19:52 -0500457 struct tps65910_board *pmic_plat_data;
Laxman Dewangancb8d8652012-05-19 02:01:41 +0530458 struct tps65910_board *of_pmic_plat_data = NULL;
Graeme Gregorye3471bd2011-05-02 16:20:04 -0500459 struct tps65910_platform_data *init_data;
Graeme Gregory27c67502011-05-02 16:19:46 -0500460 int ret = 0;
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200461 int chip_id = id->driver_data;
Graeme Gregory27c67502011-05-02 16:19:46 -0500462
Graeme Gregory2537df72011-05-02 16:19:52 -0500463 pmic_plat_data = dev_get_platdata(&i2c->dev);
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200464
Laxman Dewangancb8d8652012-05-19 02:01:41 +0530465 if (!pmic_plat_data && i2c->dev.of_node) {
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200466 pmic_plat_data = tps65910_parse_dt(i2c, &chip_id);
Laxman Dewangancb8d8652012-05-19 02:01:41 +0530467 of_pmic_plat_data = pmic_plat_data;
468 }
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200469
Graeme Gregory2537df72011-05-02 16:19:52 -0500470 if (!pmic_plat_data)
471 return -EINVAL;
472
Laxman Dewangan63fe7de2012-05-11 12:36:57 +0200473 init_data = devm_kzalloc(&i2c->dev, sizeof(*init_data), GFP_KERNEL);
Graeme Gregorye3471bd2011-05-02 16:20:04 -0500474 if (init_data == NULL)
475 return -ENOMEM;
476
Laxman Dewangan63fe7de2012-05-11 12:36:57 +0200477 tps65910 = devm_kzalloc(&i2c->dev, sizeof(*tps65910), GFP_KERNEL);
478 if (tps65910 == NULL)
Graeme Gregory27c67502011-05-02 16:19:46 -0500479 return -ENOMEM;
480
Laxman Dewangancb8d8652012-05-19 02:01:41 +0530481 tps65910->of_plat_data = of_pmic_plat_data;
Graeme Gregory27c67502011-05-02 16:19:46 -0500482 i2c_set_clientdata(i2c, tps65910);
483 tps65910->dev = &i2c->dev;
484 tps65910->i2c_client = i2c;
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200485 tps65910->id = chip_id;
Graeme Gregory27c67502011-05-02 16:19:46 -0500486
Laxman Dewangan63fe7de2012-05-11 12:36:57 +0200487 tps65910->regmap = devm_regmap_init_i2c(i2c, &tps65910_regmap_config);
Laxman Dewangandc9913a2012-02-21 18:21:34 +0530488 if (IS_ERR(tps65910->regmap)) {
489 ret = PTR_ERR(tps65910->regmap);
490 dev_err(&i2c->dev, "regmap initialization failed: %d\n", ret);
Laxman Dewangan63fe7de2012-05-11 12:36:57 +0200491 return ret;
Laxman Dewangandc9913a2012-02-21 18:21:34 +0530492 }
493
Jesper Juhlb1224cd2011-07-13 23:22:26 +0200494 init_data->irq = pmic_plat_data->irq;
Laxman Dewangan17731402012-01-18 20:19:16 +0530495 init_data->irq_base = pmic_plat_data->irq_base;
Jesper Juhlb1224cd2011-07-13 23:22:26 +0200496
Afzal Mohammed1e351a92011-12-14 16:05:35 +0530497 tps65910_irq_init(tps65910, init_data->irq, init_data);
Johan Hovoldd02e83c2012-07-11 15:44:33 +0200498 tps65910_ck32k_init(tps65910, pmic_plat_data);
Laxman Dewangan201cf052012-04-18 12:13:51 +0200499 tps65910_sleepinit(tps65910, pmic_plat_data);
500
Bill Huangb079fa722012-08-19 18:07:56 -0700501 if (pmic_plat_data->pm_off && !pm_power_off) {
502 tps65910_i2c_client = i2c;
503 pm_power_off = tps65910_power_off;
504 }
505
Laxman Dewangan10ecb802012-11-13 19:33:56 +0530506 ret = mfd_add_devices(tps65910->dev, -1,
507 tps65910s, ARRAY_SIZE(tps65910s),
Laxman Dewangan17143e32012-11-13 19:33:59 +0530508 NULL, 0,
509 regmap_irq_get_domain(tps65910->irq_data));
Laxman Dewangan10ecb802012-11-13 19:33:56 +0530510 if (ret < 0) {
511 dev_err(&i2c->dev, "mfd_add_devices failed: %d\n", ret);
512 return ret;
513 }
514
Graeme Gregory27c67502011-05-02 16:19:46 -0500515 return ret;
516}
517
Bill Pemberton4740f732012-11-19 13:26:01 -0500518static int tps65910_i2c_remove(struct i2c_client *i2c)
Graeme Gregory27c67502011-05-02 16:19:46 -0500519{
520 struct tps65910 *tps65910 = i2c_get_clientdata(i2c);
521
Mark Brownec2328c2011-06-20 11:47:55 +0100522 tps65910_irq_exit(tps65910);
Afzal Mohammed1e351a92011-12-14 16:05:35 +0530523 mfd_remove_devices(tps65910->dev);
Graeme Gregory27c67502011-05-02 16:19:46 -0500524
525 return 0;
526}
527
528static const struct i2c_device_id tps65910_i2c_id[] = {
Jorge Eduardo Candelaria79557052011-05-16 18:34:59 -0500529 { "tps65910", TPS65910 },
530 { "tps65911", TPS65911 },
Graeme Gregory27c67502011-05-02 16:19:46 -0500531 { }
532};
533MODULE_DEVICE_TABLE(i2c, tps65910_i2c_id);
534
535
536static struct i2c_driver tps65910_i2c_driver = {
537 .driver = {
538 .name = "tps65910",
539 .owner = THIS_MODULE,
Rhyland Kleincd4209c2012-05-11 11:36:26 +0200540 .of_match_table = of_match_ptr(tps65910_of_match),
Graeme Gregory27c67502011-05-02 16:19:46 -0500541 },
542 .probe = tps65910_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500543 .remove = tps65910_i2c_remove,
Graeme Gregory27c67502011-05-02 16:19:46 -0500544 .id_table = tps65910_i2c_id,
545};
546
547static int __init tps65910_i2c_init(void)
548{
549 return i2c_add_driver(&tps65910_i2c_driver);
550}
551/* init early so consumer devices can complete system boot */
552subsys_initcall(tps65910_i2c_init);
553
554static void __exit tps65910_i2c_exit(void)
555{
556 i2c_del_driver(&tps65910_i2c_driver);
557}
558module_exit(tps65910_i2c_exit);
559
560MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
561MODULE_AUTHOR("Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>");
562MODULE_DESCRIPTION("TPS6591x chip family multi-function driver");
563MODULE_LICENSE("GPL");