Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * tps65910.c -- TI tps65910
4 *
5 * Copyright 2010 Texas Instruments Inc.
6 *
7 * Author: Graeme Gregory <gg@slimlogic.co.uk>
8 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/of.h>
16#include <linux/platform_device.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h>
19#include <linux/slab.h>
20#include <linux/mfd/tps65910.h>
21#include <linux/regulator/of_regulator.h>
22
23#define TPS65910_SUPPLY_STATE_ENABLED 0x1
24#define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
25 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
26 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
27 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
28
29/* supported VIO voltages in microvolts */
30static const unsigned int VIO_VSEL_table[] = {
31 1500000, 1800000, 2500000, 3300000,
32};
33
34/* VSEL tables for TPS65910 specific LDOs and dcdc's */
35
36/* supported VRTC voltages in microvolts */
37static const unsigned int VRTC_VSEL_table[] = {
38 1800000,
39};
40
41/* supported VDD3 voltages in microvolts */
42static const unsigned int VDD3_VSEL_table[] = {
43 5000000,
44};
45
46/* supported VDIG1 voltages in microvolts */
47static const unsigned int VDIG1_VSEL_table[] = {
48 1200000, 1500000, 1800000, 2700000,
49};
50
51/* supported VDIG2 voltages in microvolts */
52static const unsigned int VDIG2_VSEL_table[] = {
53 1000000, 1100000, 1200000, 1800000,
54};
55
56/* supported VPLL voltages in microvolts */
57static const unsigned int VPLL_VSEL_table[] = {
58 1000000, 1100000, 1800000, 2500000,
59};
60
61/* supported VDAC voltages in microvolts */
62static const unsigned int VDAC_VSEL_table[] = {
63 1800000, 2600000, 2800000, 2850000,
64};
65
66/* supported VAUX1 voltages in microvolts */
67static const unsigned int VAUX1_VSEL_table[] = {
68 1800000, 2500000, 2800000, 2850000,
69};
70
71/* supported VAUX2 voltages in microvolts */
72static const unsigned int VAUX2_VSEL_table[] = {
73 1800000, 2800000, 2900000, 3300000,
74};
75
76/* supported VAUX33 voltages in microvolts */
77static const unsigned int VAUX33_VSEL_table[] = {
78 1800000, 2000000, 2800000, 3300000,
79};
80
81/* supported VMMC voltages in microvolts */
82static const unsigned int VMMC_VSEL_table[] = {
83 1800000, 2800000, 3000000, 3300000,
84};
85
86/* supported BBCH voltages in microvolts */
87static const unsigned int VBB_VSEL_table[] = {
88 3000000, 2520000, 3150000, 5000000,
89};
90
91struct tps_info {
92 const char *name;
93 const char *vin_name;
94 u8 n_voltages;
95 const unsigned int *voltage_table;
96 int enable_time_us;
97};
98
99static struct tps_info tps65910_regs[] = {
100 {
101 .name = "vrtc",
102 .vin_name = "vcc7",
103 .n_voltages = ARRAY_SIZE(VRTC_VSEL_table),
104 .voltage_table = VRTC_VSEL_table,
105 .enable_time_us = 2200,
106 },
107 {
108 .name = "vio",
109 .vin_name = "vccio",
110 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
111 .voltage_table = VIO_VSEL_table,
112 .enable_time_us = 350,
113 },
114 {
115 .name = "vdd1",
116 .vin_name = "vcc1",
117 .enable_time_us = 350,
118 },
119 {
120 .name = "vdd2",
121 .vin_name = "vcc2",
122 .enable_time_us = 350,
123 },
124 {
125 .name = "vdd3",
126 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
127 .voltage_table = VDD3_VSEL_table,
128 .enable_time_us = 200,
129 },
130 {
131 .name = "vdig1",
132 .vin_name = "vcc6",
133 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
134 .voltage_table = VDIG1_VSEL_table,
135 .enable_time_us = 100,
136 },
137 {
138 .name = "vdig2",
139 .vin_name = "vcc6",
140 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
141 .voltage_table = VDIG2_VSEL_table,
142 .enable_time_us = 100,
143 },
144 {
145 .name = "vpll",
146 .vin_name = "vcc5",
147 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
148 .voltage_table = VPLL_VSEL_table,
149 .enable_time_us = 100,
150 },
151 {
152 .name = "vdac",
153 .vin_name = "vcc5",
154 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
155 .voltage_table = VDAC_VSEL_table,
156 .enable_time_us = 100,
157 },
158 {
159 .name = "vaux1",
160 .vin_name = "vcc4",
161 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
162 .voltage_table = VAUX1_VSEL_table,
163 .enable_time_us = 100,
164 },
165 {
166 .name = "vaux2",
167 .vin_name = "vcc4",
168 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
169 .voltage_table = VAUX2_VSEL_table,
170 .enable_time_us = 100,
171 },
172 {
173 .name = "vaux33",
174 .vin_name = "vcc3",
175 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
176 .voltage_table = VAUX33_VSEL_table,
177 .enable_time_us = 100,
178 },
179 {
180 .name = "vmmc",
181 .vin_name = "vcc3",
182 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
183 .voltage_table = VMMC_VSEL_table,
184 .enable_time_us = 100,
185 },
186 {
187 .name = "vbb",
188 .vin_name = "vcc7",
189 .n_voltages = ARRAY_SIZE(VBB_VSEL_table),
190 .voltage_table = VBB_VSEL_table,
191 },
192};
193
194static struct tps_info tps65911_regs[] = {
195 {
196 .name = "vrtc",
197 .vin_name = "vcc7",
198 .enable_time_us = 2200,
199 },
200 {
201 .name = "vio",
202 .vin_name = "vccio",
203 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
204 .voltage_table = VIO_VSEL_table,
205 .enable_time_us = 350,
206 },
207 {
208 .name = "vdd1",
209 .vin_name = "vcc1",
210 .n_voltages = 0x4C,
211 .enable_time_us = 350,
212 },
213 {
214 .name = "vdd2",
215 .vin_name = "vcc2",
216 .n_voltages = 0x4C,
217 .enable_time_us = 350,
218 },
219 {
220 .name = "vddctrl",
221 .n_voltages = 0x44,
222 .enable_time_us = 900,
223 },
224 {
225 .name = "ldo1",
226 .vin_name = "vcc6",
227 .n_voltages = 0x33,
228 .enable_time_us = 420,
229 },
230 {
231 .name = "ldo2",
232 .vin_name = "vcc6",
233 .n_voltages = 0x33,
234 .enable_time_us = 420,
235 },
236 {
237 .name = "ldo3",
238 .vin_name = "vcc5",
239 .n_voltages = 0x1A,
240 .enable_time_us = 230,
241 },
242 {
243 .name = "ldo4",
244 .vin_name = "vcc5",
245 .n_voltages = 0x33,
246 .enable_time_us = 230,
247 },
248 {
249 .name = "ldo5",
250 .vin_name = "vcc4",
251 .n_voltages = 0x1A,
252 .enable_time_us = 230,
253 },
254 {
255 .name = "ldo6",
256 .vin_name = "vcc3",
257 .n_voltages = 0x1A,
258 .enable_time_us = 230,
259 },
260 {
261 .name = "ldo7",
262 .vin_name = "vcc3",
263 .n_voltages = 0x1A,
264 .enable_time_us = 230,
265 },
266 {
267 .name = "ldo8",
268 .vin_name = "vcc3",
269 .n_voltages = 0x1A,
270 .enable_time_us = 230,
271 },
272};
273
274#define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
275static unsigned int tps65910_ext_sleep_control[] = {
276 0,
277 EXT_CONTROL_REG_BITS(VIO, 1, 0),
278 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
279 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
280 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
281 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
282 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
283 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
284 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
285 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
286 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
287 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
288 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
289};
290
291static unsigned int tps65911_ext_sleep_control[] = {
292 0,
293 EXT_CONTROL_REG_BITS(VIO, 1, 0),
294 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
295 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
296 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
297 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
298 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
299 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
300 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
301 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
302 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
303 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
304 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
305};
306
307struct tps65910_reg {
308 struct regulator_desc *desc;
309 struct tps65910 *mfd;
310 struct regulator_dev **rdev;
311 struct tps_info **info;
312 int num_regulators;
313 int mode;
314 int (*get_ctrl_reg)(int);
315 unsigned int *ext_sleep_control;
316 unsigned int board_ext_control[TPS65910_NUM_REGS];
317};
318
319static int tps65910_get_ctrl_register(int id)
320{
321 switch (id) {
322 case TPS65910_REG_VRTC:
323 return TPS65910_VRTC;
324 case TPS65910_REG_VIO:
325 return TPS65910_VIO;
326 case TPS65910_REG_VDD1:
327 return TPS65910_VDD1;
328 case TPS65910_REG_VDD2:
329 return TPS65910_VDD2;
330 case TPS65910_REG_VDD3:
331 return TPS65910_VDD3;
332 case TPS65910_REG_VDIG1:
333 return TPS65910_VDIG1;
334 case TPS65910_REG_VDIG2:
335 return TPS65910_VDIG2;
336 case TPS65910_REG_VPLL:
337 return TPS65910_VPLL;
338 case TPS65910_REG_VDAC:
339 return TPS65910_VDAC;
340 case TPS65910_REG_VAUX1:
341 return TPS65910_VAUX1;
342 case TPS65910_REG_VAUX2:
343 return TPS65910_VAUX2;
344 case TPS65910_REG_VAUX33:
345 return TPS65910_VAUX33;
346 case TPS65910_REG_VMMC:
347 return TPS65910_VMMC;
348 case TPS65910_REG_VBB:
349 return TPS65910_BBCH;
350 default:
351 return -EINVAL;
352 }
353}
354
355static int tps65911_get_ctrl_register(int id)
356{
357 switch (id) {
358 case TPS65910_REG_VRTC:
359 return TPS65910_VRTC;
360 case TPS65910_REG_VIO:
361 return TPS65910_VIO;
362 case TPS65910_REG_VDD1:
363 return TPS65910_VDD1;
364 case TPS65910_REG_VDD2:
365 return TPS65910_VDD2;
366 case TPS65911_REG_VDDCTRL:
367 return TPS65911_VDDCTRL;
368 case TPS65911_REG_LDO1:
369 return TPS65911_LDO1;
370 case TPS65911_REG_LDO2:
371 return TPS65911_LDO2;
372 case TPS65911_REG_LDO3:
373 return TPS65911_LDO3;
374 case TPS65911_REG_LDO4:
375 return TPS65911_LDO4;
376 case TPS65911_REG_LDO5:
377 return TPS65911_LDO5;
378 case TPS65911_REG_LDO6:
379 return TPS65911_LDO6;
380 case TPS65911_REG_LDO7:
381 return TPS65911_LDO7;
382 case TPS65911_REG_LDO8:
383 return TPS65911_LDO8;
384 default:
385 return -EINVAL;
386 }
387}
388
389static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
390{
391 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
392 struct regmap *regmap = rdev_get_regmap(dev);
393 int reg, id = rdev_get_id(dev);
394
395 reg = pmic->get_ctrl_reg(id);
396 if (reg < 0)
397 return reg;
398
399 switch (mode) {
400 case REGULATOR_MODE_NORMAL:
401 return regmap_update_bits(regmap, reg,
402 LDO_ST_MODE_BIT | LDO_ST_ON_BIT,
403 LDO_ST_ON_BIT);
404 case REGULATOR_MODE_IDLE:
405 return regmap_set_bits(regmap, reg,
406 LDO_ST_ON_BIT | LDO_ST_MODE_BIT);
407 case REGULATOR_MODE_STANDBY:
408 return regmap_clear_bits(regmap, reg, LDO_ST_ON_BIT);
409 }
410
411 return -EINVAL;
412}
413
414static unsigned int tps65910_get_mode(struct regulator_dev *dev)
415{
416 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
417 struct regmap *regmap = rdev_get_regmap(dev);
418 int ret, reg, value, id = rdev_get_id(dev);
419
420 reg = pmic->get_ctrl_reg(id);
421 if (reg < 0)
422 return reg;
423
424 ret = regmap_read(regmap, reg, &value);
425 if (ret < 0)
426 return ret;
427
428 if (!(value & LDO_ST_ON_BIT))
429 return REGULATOR_MODE_STANDBY;
430 else if (value & LDO_ST_MODE_BIT)
431 return REGULATOR_MODE_IDLE;
432 else
433 return REGULATOR_MODE_NORMAL;
434}
435
436static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
437{
438 struct regmap *regmap = rdev_get_regmap(dev);
439 int ret, id = rdev_get_id(dev);
440 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
441
442 switch (id) {
443 case TPS65910_REG_VDD1:
444 ret = regmap_read(regmap, TPS65910_VDD1_OP, &opvsel);
445 if (ret < 0)
446 return ret;
447 ret = regmap_read(regmap, TPS65910_VDD1, &mult);
448 if (ret < 0)
449 return ret;
450 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
451 ret = regmap_read(regmap, TPS65910_VDD1_SR, &srvsel);
452 if (ret < 0)
453 return ret;
454 sr = opvsel & VDD1_OP_CMD_MASK;
455 opvsel &= VDD1_OP_SEL_MASK;
456 srvsel &= VDD1_SR_SEL_MASK;
457 vselmax = 75;
458 break;
459 case TPS65910_REG_VDD2:
460 ret = regmap_read(regmap, TPS65910_VDD2_OP, &opvsel);
461 if (ret < 0)
462 return ret;
463 ret = regmap_read(regmap, TPS65910_VDD2, &mult);
464 if (ret < 0)
465 return ret;
466 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
467 ret = regmap_read(regmap, TPS65910_VDD2_SR, &srvsel);
468 if (ret < 0)
469 return ret;
470 sr = opvsel & VDD2_OP_CMD_MASK;
471 opvsel &= VDD2_OP_SEL_MASK;
472 srvsel &= VDD2_SR_SEL_MASK;
473 vselmax = 75;
474 break;
475 case TPS65911_REG_VDDCTRL:
476 ret = regmap_read(regmap, TPS65911_VDDCTRL_OP, &opvsel);
477 if (ret < 0)
478 return ret;
479 ret = regmap_read(regmap, TPS65911_VDDCTRL_SR, &srvsel);
480 if (ret < 0)
481 return ret;
482 sr = opvsel & VDDCTRL_OP_CMD_MASK;
483 opvsel &= VDDCTRL_OP_SEL_MASK;
484 srvsel &= VDDCTRL_SR_SEL_MASK;
485 vselmax = 64;
486 break;
487 }
488
489 /* multiplier 0 == 1 but 2,3 normal */
490 if (!mult)
491 mult = 1;
492
493 if (sr) {
494 /* normalise to valid range */
495 if (srvsel < 3)
496 srvsel = 3;
497 if (srvsel > vselmax)
498 srvsel = vselmax;
499 return srvsel - 3;
500 } else {
501
502 /* normalise to valid range*/
503 if (opvsel < 3)
504 opvsel = 3;
505 if (opvsel > vselmax)
506 opvsel = vselmax;
507 return opvsel - 3;
508 }
509 return -EINVAL;
510}
511
512static int tps65910_get_voltage_sel(struct regulator_dev *dev)
513{
514 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
515 struct regmap *regmap = rdev_get_regmap(dev);
516 int ret, reg, value, id = rdev_get_id(dev);
517
518 reg = pmic->get_ctrl_reg(id);
519 if (reg < 0)
520 return reg;
521
522 ret = regmap_read(regmap, reg, &value);
523 if (ret < 0)
524 return ret;
525
526 switch (id) {
527 case TPS65910_REG_VIO:
528 case TPS65910_REG_VDIG1:
529 case TPS65910_REG_VDIG2:
530 case TPS65910_REG_VPLL:
531 case TPS65910_REG_VDAC:
532 case TPS65910_REG_VAUX1:
533 case TPS65910_REG_VAUX2:
534 case TPS65910_REG_VAUX33:
535 case TPS65910_REG_VMMC:
536 value &= LDO_SEL_MASK;
537 value >>= LDO_SEL_SHIFT;
538 break;
539 case TPS65910_REG_VBB:
540 value &= BBCH_BBSEL_MASK;
541 value >>= BBCH_BBSEL_SHIFT;
542 break;
543 default:
544 return -EINVAL;
545 }
546
547 return value;
548}
549
550static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
551{
552 return dev->desc->volt_table[0];
553}
554
555static int tps65911_get_voltage_sel(struct regulator_dev *dev)
556{
557 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
558 struct regmap *regmap = rdev_get_regmap(dev);
559 int ret, id = rdev_get_id(dev);
560 unsigned int value, reg;
561
562 reg = pmic->get_ctrl_reg(id);
563
564 ret = regmap_read(regmap, reg, &value);
565 if (ret < 0)
566 return ret;
567
568 switch (id) {
569 case TPS65911_REG_LDO1:
570 case TPS65911_REG_LDO2:
571 case TPS65911_REG_LDO4:
572 value &= LDO1_SEL_MASK;
573 value >>= LDO_SEL_SHIFT;
574 break;
575 case TPS65911_REG_LDO3:
576 case TPS65911_REG_LDO5:
577 case TPS65911_REG_LDO6:
578 case TPS65911_REG_LDO7:
579 case TPS65911_REG_LDO8:
580 value &= LDO3_SEL_MASK;
581 value >>= LDO_SEL_SHIFT;
582 break;
583 case TPS65910_REG_VIO:
584 value &= LDO_SEL_MASK;
585 value >>= LDO_SEL_SHIFT;
586 break;
587 default:
588 return -EINVAL;
589 }
590
591 return value;
592}
593
594static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
595 unsigned selector)
596{
597 struct regmap *regmap = rdev_get_regmap(dev);
598 int id = rdev_get_id(dev), vsel;
599 int dcdc_mult = 0;
600
601 switch (id) {
602 case TPS65910_REG_VDD1:
603 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
604 if (dcdc_mult == 1)
605 dcdc_mult--;
606 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
607
608 regmap_update_bits(regmap, TPS65910_VDD1, VDD1_VGAIN_SEL_MASK,
609 dcdc_mult << VDD1_VGAIN_SEL_SHIFT);
610 regmap_write(regmap, TPS65910_VDD1_OP, vsel);
611 break;
612 case TPS65910_REG_VDD2:
613 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
614 if (dcdc_mult == 1)
615 dcdc_mult--;
616 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
617
618 regmap_update_bits(regmap, TPS65910_VDD2, VDD1_VGAIN_SEL_MASK,
619 dcdc_mult << VDD2_VGAIN_SEL_SHIFT);
620 regmap_write(regmap, TPS65910_VDD2_OP, vsel);
621 break;
622 case TPS65911_REG_VDDCTRL:
623 vsel = selector + 3;
624 regmap_write(regmap, TPS65911_VDDCTRL_OP, vsel);
625 break;
626 }
627
628 return 0;
629}
630
631static int tps65910_set_voltage_sel(struct regulator_dev *dev,
632 unsigned selector)
633{
634 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
635 struct regmap *regmap = rdev_get_regmap(dev);
636 int reg, id = rdev_get_id(dev);
637
638 reg = pmic->get_ctrl_reg(id);
639 if (reg < 0)
640 return reg;
641
642 switch (id) {
643 case TPS65910_REG_VIO:
644 case TPS65910_REG_VDIG1:
645 case TPS65910_REG_VDIG2:
646 case TPS65910_REG_VPLL:
647 case TPS65910_REG_VDAC:
648 case TPS65910_REG_VAUX1:
649 case TPS65910_REG_VAUX2:
650 case TPS65910_REG_VAUX33:
651 case TPS65910_REG_VMMC:
652 return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
653 selector << LDO_SEL_SHIFT);
654 case TPS65910_REG_VBB:
655 return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
656 selector << BBCH_BBSEL_SHIFT);
657 }
658
659 return -EINVAL;
660}
661
662static int tps65911_set_voltage_sel(struct regulator_dev *dev,
663 unsigned selector)
664{
665 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
666 struct regmap *regmap = rdev_get_regmap(dev);
667 int reg, id = rdev_get_id(dev);
668
669 reg = pmic->get_ctrl_reg(id);
670 if (reg < 0)
671 return reg;
672
673 switch (id) {
674 case TPS65911_REG_LDO1:
675 case TPS65911_REG_LDO2:
676 case TPS65911_REG_LDO4:
677 return regmap_update_bits(regmap, reg, LDO1_SEL_MASK,
678 selector << LDO_SEL_SHIFT);
679 case TPS65911_REG_LDO3:
680 case TPS65911_REG_LDO5:
681 case TPS65911_REG_LDO6:
682 case TPS65911_REG_LDO7:
683 case TPS65911_REG_LDO8:
684 return regmap_update_bits(regmap, reg, LDO3_SEL_MASK,
685 selector << LDO_SEL_SHIFT);
686 case TPS65910_REG_VIO:
687 return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
688 selector << LDO_SEL_SHIFT);
689 case TPS65910_REG_VBB:
690 return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
691 selector << BBCH_BBSEL_SHIFT);
692 }
693
694 return -EINVAL;
695}
696
697
698static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
699 unsigned selector)
700{
701 int volt, mult = 1, id = rdev_get_id(dev);
702
703 switch (id) {
704 case TPS65910_REG_VDD1:
705 case TPS65910_REG_VDD2:
706 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
707 volt = VDD1_2_MIN_VOLT +
708 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
709 break;
710 case TPS65911_REG_VDDCTRL:
711 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
712 break;
713 default:
714 BUG();
715 return -EINVAL;
716 }
717
718 return volt * 100 * mult;
719}
720
721static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
722{
723 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
724 int step_mv = 0, id = rdev_get_id(dev);
725
726 switch (id) {
727 case TPS65911_REG_LDO1:
728 case TPS65911_REG_LDO2:
729 case TPS65911_REG_LDO4:
730 /* The first 5 values of the selector correspond to 1V */
731 if (selector < 5)
732 selector = 0;
733 else
734 selector -= 4;
735
736 step_mv = 50;
737 break;
738 case TPS65911_REG_LDO3:
739 case TPS65911_REG_LDO5:
740 case TPS65911_REG_LDO6:
741 case TPS65911_REG_LDO7:
742 case TPS65911_REG_LDO8:
743 /* The first 3 values of the selector correspond to 1V */
744 if (selector < 3)
745 selector = 0;
746 else
747 selector -= 2;
748
749 step_mv = 100;
750 break;
751 case TPS65910_REG_VIO:
752 return pmic->info[id]->voltage_table[selector];
753 default:
754 return -EINVAL;
755 }
756
757 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
758}
759
760/* Regulator ops (except VRTC) */
761static const struct regulator_ops tps65910_ops_dcdc = {
762 .is_enabled = regulator_is_enabled_regmap,
763 .enable = regulator_enable_regmap,
764 .disable = regulator_disable_regmap,
765 .set_mode = tps65910_set_mode,
766 .get_mode = tps65910_get_mode,
767 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
768 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
769 .set_voltage_time_sel = regulator_set_voltage_time_sel,
770 .list_voltage = tps65910_list_voltage_dcdc,
771 .map_voltage = regulator_map_voltage_ascend,
772};
773
774static const struct regulator_ops tps65910_ops_vdd3 = {
775 .is_enabled = regulator_is_enabled_regmap,
776 .enable = regulator_enable_regmap,
777 .disable = regulator_disable_regmap,
778 .set_mode = tps65910_set_mode,
779 .get_mode = tps65910_get_mode,
780 .get_voltage = tps65910_get_voltage_vdd3,
781 .list_voltage = regulator_list_voltage_table,
782 .map_voltage = regulator_map_voltage_ascend,
783};
784
785static const struct regulator_ops tps65910_ops_vbb = {
786 .is_enabled = regulator_is_enabled_regmap,
787 .enable = regulator_enable_regmap,
788 .disable = regulator_disable_regmap,
789 .set_mode = tps65910_set_mode,
790 .get_mode = tps65910_get_mode,
791 .get_voltage_sel = tps65910_get_voltage_sel,
792 .set_voltage_sel = tps65910_set_voltage_sel,
793 .list_voltage = regulator_list_voltage_table,
794 .map_voltage = regulator_map_voltage_iterate,
795};
796
797static const struct regulator_ops tps65910_ops = {
798 .is_enabled = regulator_is_enabled_regmap,
799 .enable = regulator_enable_regmap,
800 .disable = regulator_disable_regmap,
801 .set_mode = tps65910_set_mode,
802 .get_mode = tps65910_get_mode,
803 .get_voltage_sel = tps65910_get_voltage_sel,
804 .set_voltage_sel = tps65910_set_voltage_sel,
805 .list_voltage = regulator_list_voltage_table,
806 .map_voltage = regulator_map_voltage_ascend,
807};
808
809static const struct regulator_ops tps65911_ops = {
810 .is_enabled = regulator_is_enabled_regmap,
811 .enable = regulator_enable_regmap,
812 .disable = regulator_disable_regmap,
813 .set_mode = tps65910_set_mode,
814 .get_mode = tps65910_get_mode,
815 .get_voltage_sel = tps65911_get_voltage_sel,
816 .set_voltage_sel = tps65911_set_voltage_sel,
817 .list_voltage = tps65911_list_voltage,
818 .map_voltage = regulator_map_voltage_ascend,
819};
820
821static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
822 int id, int ext_sleep_config)
823{
824 struct tps65910 *mfd = pmic->mfd;
825 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
826 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
827 int ret;
828
829 /*
830 * Regulator can not be control from multiple external input EN1, EN2
831 * and EN3 together.
832 */
833 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
834 int en_count;
835 en_count = ((ext_sleep_config &
836 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
837 en_count += ((ext_sleep_config &
838 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
839 en_count += ((ext_sleep_config &
840 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
841 en_count += ((ext_sleep_config &
842 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
843 if (en_count > 1) {
844 dev_err(mfd->dev,
845 "External sleep control flag is not proper\n");
846 return -EINVAL;
847 }
848 }
849
850 pmic->board_ext_control[id] = ext_sleep_config;
851
852 /* External EN1 control */
853 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
854 ret = regmap_set_bits(mfd->regmap,
855 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
856 else
857 ret = regmap_clear_bits(mfd->regmap,
858 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
859 if (ret < 0) {
860 dev_err(mfd->dev,
861 "Error in configuring external control EN1\n");
862 return ret;
863 }
864
865 /* External EN2 control */
866 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
867 ret = regmap_set_bits(mfd->regmap,
868 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
869 else
870 ret = regmap_clear_bits(mfd->regmap,
871 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
872 if (ret < 0) {
873 dev_err(mfd->dev,
874 "Error in configuring external control EN2\n");
875 return ret;
876 }
877
878 /* External EN3 control for TPS65910 LDO only */
879 if ((tps65910_chip_id(mfd) == TPS65910) &&
880 (id >= TPS65910_REG_VDIG1)) {
881 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
882 ret = regmap_set_bits(mfd->regmap,
883 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
884 else
885 ret = regmap_clear_bits(mfd->regmap,
886 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
887 if (ret < 0) {
888 dev_err(mfd->dev,
889 "Error in configuring external control EN3\n");
890 return ret;
891 }
892 }
893
894 /* Return if no external control is selected */
895 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
896 /* Clear all sleep controls */
897 ret = regmap_clear_bits(mfd->regmap,
898 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
899 if (!ret)
900 ret = regmap_clear_bits(mfd->regmap,
901 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
902 if (ret < 0)
903 dev_err(mfd->dev,
904 "Error in configuring SLEEP register\n");
905 return ret;
906 }
907
908 /*
909 * For regulator that has separate operational and sleep register make
910 * sure that operational is used and clear sleep register to turn
911 * regulator off when external control is inactive
912 */
913 if ((id == TPS65910_REG_VDD1) ||
914 (id == TPS65910_REG_VDD2) ||
915 ((id == TPS65911_REG_VDDCTRL) &&
916 (tps65910_chip_id(mfd) == TPS65911))) {
917 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
918 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
919 int opvsel, srvsel;
920
921 ret = regmap_read(mfd->regmap, op_reg_add, &opvsel);
922 if (ret < 0)
923 return ret;
924 ret = regmap_read(mfd->regmap, sr_reg_add, &srvsel);
925 if (ret < 0)
926 return ret;
927
928 if (opvsel & VDD1_OP_CMD_MASK) {
929 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
930
931 ret = regmap_write(mfd->regmap, op_reg_add, reg_val);
932 if (ret < 0) {
933 dev_err(mfd->dev,
934 "Error in configuring op register\n");
935 return ret;
936 }
937 }
938 ret = regmap_write(mfd->regmap, sr_reg_add, 0);
939 if (ret < 0) {
940 dev_err(mfd->dev, "Error in setting sr register\n");
941 return ret;
942 }
943 }
944
945 ret = regmap_clear_bits(mfd->regmap,
946 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
947 if (!ret) {
948 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
949 ret = regmap_set_bits(mfd->regmap,
950 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
951 else
952 ret = regmap_clear_bits(mfd->regmap,
953 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
954 }
955 if (ret < 0)
956 dev_err(mfd->dev,
957 "Error in configuring SLEEP register\n");
958
959 return ret;
960}
961
962#ifdef CONFIG_OF
963
964static struct of_regulator_match tps65910_matches[] = {
965 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
966 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
967 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
968 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
969 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
970 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
971 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
972 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
973 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
974 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
975 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
976 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
977 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
978 { .name = "vbb", .driver_data = (void *) &tps65910_regs[13] },
979};
980
981static struct of_regulator_match tps65911_matches[] = {
982 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
983 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
984 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
985 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
986 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
987 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
988 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
989 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
990 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
991 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
992 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
993 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
994 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
995};
996
997static struct tps65910_board *tps65910_parse_dt_reg_data(
998 struct platform_device *pdev,
999 struct of_regulator_match **tps65910_reg_matches)
1000{
1001 struct tps65910_board *pmic_plat_data;
1002 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1003 struct device_node *np, *regulators;
1004 struct of_regulator_match *matches;
1005 unsigned int prop;
1006 int idx = 0, ret, count;
1007
1008 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
1009 GFP_KERNEL);
1010 if (!pmic_plat_data)
1011 return NULL;
1012
1013 np = pdev->dev.parent->of_node;
1014 regulators = of_get_child_by_name(np, "regulators");
1015 if (!regulators) {
1016 dev_err(&pdev->dev, "regulator node not found\n");
1017 return NULL;
1018 }
1019
1020 switch (tps65910_chip_id(tps65910)) {
1021 case TPS65910:
1022 count = ARRAY_SIZE(tps65910_matches);
1023 matches = tps65910_matches;
1024 break;
1025 case TPS65911:
1026 count = ARRAY_SIZE(tps65911_matches);
1027 matches = tps65911_matches;
1028 break;
1029 default:
1030 of_node_put(regulators);
1031 dev_err(&pdev->dev, "Invalid tps chip version\n");
1032 return NULL;
1033 }
1034
1035 ret = of_regulator_match(&pdev->dev, regulators, matches, count);
1036 of_node_put(regulators);
1037 if (ret < 0) {
1038 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1039 ret);
1040 return NULL;
1041 }
1042
1043 *tps65910_reg_matches = matches;
1044
1045 for (idx = 0; idx < count; idx++) {
1046 if (!matches[idx].of_node)
1047 continue;
1048
1049 pmic_plat_data->tps65910_pmic_init_data[idx] =
1050 matches[idx].init_data;
1051
1052 ret = of_property_read_u32(matches[idx].of_node,
1053 "ti,regulator-ext-sleep-control", &prop);
1054 if (!ret)
1055 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1056
1057 }
1058
1059 return pmic_plat_data;
1060}
1061#else
1062static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1063 struct platform_device *pdev,
1064 struct of_regulator_match **tps65910_reg_matches)
1065{
1066 *tps65910_reg_matches = NULL;
1067 return NULL;
1068}
1069#endif
1070
1071static int tps65910_probe(struct platform_device *pdev)
1072{
1073 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1074 struct regulator_config config = { };
1075 struct tps_info *info;
1076 struct regulator_dev *rdev;
1077 struct tps65910_reg *pmic;
1078 struct tps65910_board *pmic_plat_data;
1079 struct of_regulator_match *tps65910_reg_matches = NULL;
1080 int i, err;
1081
1082 pmic_plat_data = dev_get_platdata(tps65910->dev);
1083 if (!pmic_plat_data && tps65910->dev->of_node)
1084 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1085 &tps65910_reg_matches);
1086
1087 if (!pmic_plat_data) {
1088 dev_err(&pdev->dev, "Platform data not found\n");
1089 return -EINVAL;
1090 }
1091
1092 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1093 if (!pmic)
1094 return -ENOMEM;
1095
1096 pmic->mfd = tps65910;
1097 platform_set_drvdata(pdev, pmic);
1098
1099 /* Give control of all register to control port */
1100 err = regmap_set_bits(pmic->mfd->regmap, TPS65910_DEVCTRL,
1101 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1102 if (err < 0)
1103 return err;
1104
1105 switch (tps65910_chip_id(tps65910)) {
1106 case TPS65910:
1107 BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
1108 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1109 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1110 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1111 info = tps65910_regs;
1112 /* Work around silicon erratum SWCZ010: output programmed
1113 * voltage level can go higher than expected or crash
1114 * Workaround: use no synchronization of DCDC clocks
1115 */
1116 regmap_clear_bits(pmic->mfd->regmap, TPS65910_DCDCCTRL,
1117 DCDCCTRL_DCDCCKSYNC_MASK);
1118 break;
1119 case TPS65911:
1120 BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
1121 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1122 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1123 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1124 info = tps65911_regs;
1125 break;
1126 default:
1127 dev_err(&pdev->dev, "Invalid tps chip version\n");
1128 return -ENODEV;
1129 }
1130
1131 pmic->desc = devm_kcalloc(&pdev->dev,
1132 pmic->num_regulators,
1133 sizeof(struct regulator_desc),
1134 GFP_KERNEL);
1135 if (!pmic->desc)
1136 return -ENOMEM;
1137
1138 pmic->info = devm_kcalloc(&pdev->dev,
1139 pmic->num_regulators,
1140 sizeof(struct tps_info *),
1141 GFP_KERNEL);
1142 if (!pmic->info)
1143 return -ENOMEM;
1144
1145 pmic->rdev = devm_kcalloc(&pdev->dev,
1146 pmic->num_regulators,
1147 sizeof(struct regulator_dev *),
1148 GFP_KERNEL);
1149 if (!pmic->rdev)
1150 return -ENOMEM;
1151
1152 for (i = 0; i < pmic->num_regulators; i++, info++) {
1153 /* Register the regulators */
1154 pmic->info[i] = info;
1155
1156 pmic->desc[i].name = info->name;
1157 pmic->desc[i].supply_name = info->vin_name;
1158 pmic->desc[i].id = i;
1159 pmic->desc[i].n_voltages = info->n_voltages;
1160 pmic->desc[i].enable_time = info->enable_time_us;
1161
1162 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1163 pmic->desc[i].ops = &tps65910_ops_dcdc;
1164 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1165 VDD1_2_NUM_VOLT_COARSE;
1166 pmic->desc[i].ramp_delay = 12500;
1167 } else if (i == TPS65910_REG_VDD3) {
1168 if (tps65910_chip_id(tps65910) == TPS65910) {
1169 pmic->desc[i].ops = &tps65910_ops_vdd3;
1170 pmic->desc[i].volt_table = info->voltage_table;
1171 } else {
1172 pmic->desc[i].ops = &tps65910_ops_dcdc;
1173 pmic->desc[i].ramp_delay = 5000;
1174 }
1175 } else if (i == TPS65910_REG_VBB &&
1176 tps65910_chip_id(tps65910) == TPS65910) {
1177 pmic->desc[i].ops = &tps65910_ops_vbb;
1178 pmic->desc[i].volt_table = info->voltage_table;
1179 } else {
1180 if (tps65910_chip_id(tps65910) == TPS65910) {
1181 pmic->desc[i].ops = &tps65910_ops;
1182 pmic->desc[i].volt_table = info->voltage_table;
1183 } else {
1184 pmic->desc[i].ops = &tps65911_ops;
1185 }
1186 }
1187
1188 err = tps65910_set_ext_sleep_config(pmic, i,
1189 pmic_plat_data->regulator_ext_sleep_control[i]);
1190 /*
1191 * Failing on regulator for configuring externally control
1192 * is not a serious issue, just throw warning.
1193 */
1194 if (err < 0)
1195 dev_warn(tps65910->dev,
1196 "Failed to initialise ext control config\n");
1197
1198 pmic->desc[i].type = REGULATOR_VOLTAGE;
1199 pmic->desc[i].owner = THIS_MODULE;
1200 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1201 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1202
1203 config.dev = tps65910->dev;
1204 config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
1205 config.driver_data = pmic;
1206 config.regmap = tps65910->regmap;
1207
1208 if (tps65910_reg_matches)
1209 config.of_node = tps65910_reg_matches[i].of_node;
1210
1211 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
1212 &config);
1213 if (IS_ERR(rdev))
1214 return dev_err_probe(tps65910->dev, PTR_ERR(rdev),
1215 "failed to register %s regulator\n",
1216 pdev->name);
1217
1218 /* Save regulator for cleanup */
1219 pmic->rdev[i] = rdev;
1220 }
1221 return 0;
1222}
1223
1224static void tps65910_shutdown(struct platform_device *pdev)
1225{
1226 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1227 int i;
1228
1229 /*
1230 * Before bootloader jumps to kernel, it makes sure that required
1231 * external control signals are in desired state so that given rails
1232 * can be configure accordingly.
1233 * If rails are configured to be controlled from external control
1234 * then before shutting down/rebooting the system, the external
1235 * control configuration need to be remove from the rails so that
1236 * its output will be available as per register programming even
1237 * if external controls are removed. This is require when the POR
1238 * value of the control signals are not in active state and before
1239 * bootloader initializes it, the system requires the rail output
1240 * to be active for booting.
1241 */
1242 for (i = 0; i < pmic->num_regulators; i++) {
1243 int err;
1244 if (!pmic->rdev[i])
1245 continue;
1246
1247 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1248 if (err < 0)
1249 dev_err(&pdev->dev,
1250 "Error in clearing external control\n");
1251 }
1252}
1253
1254static struct platform_driver tps65910_driver = {
1255 .driver = {
1256 .name = "tps65910-pmic",
1257 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
1258 },
1259 .probe = tps65910_probe,
1260 .shutdown = tps65910_shutdown,
1261};
1262
1263static int __init tps65910_init(void)
1264{
1265 return platform_driver_register(&tps65910_driver);
1266}
1267subsys_initcall(tps65910_init);
1268
1269static void __exit tps65910_cleanup(void)
1270{
1271 platform_driver_unregister(&tps65910_driver);
1272}
1273module_exit(tps65910_cleanup);
1274
1275MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1276MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1277MODULE_LICENSE("GPL v2");
1278MODULE_ALIAS("platform:tps65910-pmic");
1/*
2 * tps65910.c -- TI tps65910
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/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/err.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24#include <linux/slab.h>
25#include <linux/gpio.h>
26#include <linux/mfd/tps65910.h>
27#include <linux/regulator/of_regulator.h>
28
29#define TPS65910_SUPPLY_STATE_ENABLED 0x1
30#define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
32 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
33 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
34
35/* supported VIO voltages in microvolts */
36static const unsigned int VIO_VSEL_table[] = {
37 1500000, 1800000, 2500000, 3300000,
38};
39
40/* VSEL tables for TPS65910 specific LDOs and dcdc's */
41
42/* supported VRTC voltages in microvolts */
43static const unsigned int VRTC_VSEL_table[] = {
44 1800000,
45};
46
47/* supported VDD3 voltages in microvolts */
48static const unsigned int VDD3_VSEL_table[] = {
49 5000000,
50};
51
52/* supported VDIG1 voltages in microvolts */
53static const unsigned int VDIG1_VSEL_table[] = {
54 1200000, 1500000, 1800000, 2700000,
55};
56
57/* supported VDIG2 voltages in microvolts */
58static const unsigned int VDIG2_VSEL_table[] = {
59 1000000, 1100000, 1200000, 1800000,
60};
61
62/* supported VPLL voltages in microvolts */
63static const unsigned int VPLL_VSEL_table[] = {
64 1000000, 1100000, 1800000, 2500000,
65};
66
67/* supported VDAC voltages in microvolts */
68static const unsigned int VDAC_VSEL_table[] = {
69 1800000, 2600000, 2800000, 2850000,
70};
71
72/* supported VAUX1 voltages in microvolts */
73static const unsigned int VAUX1_VSEL_table[] = {
74 1800000, 2500000, 2800000, 2850000,
75};
76
77/* supported VAUX2 voltages in microvolts */
78static const unsigned int VAUX2_VSEL_table[] = {
79 1800000, 2800000, 2900000, 3300000,
80};
81
82/* supported VAUX33 voltages in microvolts */
83static const unsigned int VAUX33_VSEL_table[] = {
84 1800000, 2000000, 2800000, 3300000,
85};
86
87/* supported VMMC voltages in microvolts */
88static const unsigned int VMMC_VSEL_table[] = {
89 1800000, 2800000, 3000000, 3300000,
90};
91
92/* supported BBCH voltages in microvolts */
93static const unsigned int VBB_VSEL_table[] = {
94 3000000, 2520000, 3150000, 5000000,
95};
96
97struct tps_info {
98 const char *name;
99 const char *vin_name;
100 u8 n_voltages;
101 const unsigned int *voltage_table;
102 int enable_time_us;
103};
104
105static struct tps_info tps65910_regs[] = {
106 {
107 .name = "vrtc",
108 .vin_name = "vcc7",
109 .n_voltages = ARRAY_SIZE(VRTC_VSEL_table),
110 .voltage_table = VRTC_VSEL_table,
111 .enable_time_us = 2200,
112 },
113 {
114 .name = "vio",
115 .vin_name = "vccio",
116 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
117 .voltage_table = VIO_VSEL_table,
118 .enable_time_us = 350,
119 },
120 {
121 .name = "vdd1",
122 .vin_name = "vcc1",
123 .enable_time_us = 350,
124 },
125 {
126 .name = "vdd2",
127 .vin_name = "vcc2",
128 .enable_time_us = 350,
129 },
130 {
131 .name = "vdd3",
132 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
133 .voltage_table = VDD3_VSEL_table,
134 .enable_time_us = 200,
135 },
136 {
137 .name = "vdig1",
138 .vin_name = "vcc6",
139 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
140 .voltage_table = VDIG1_VSEL_table,
141 .enable_time_us = 100,
142 },
143 {
144 .name = "vdig2",
145 .vin_name = "vcc6",
146 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
147 .voltage_table = VDIG2_VSEL_table,
148 .enable_time_us = 100,
149 },
150 {
151 .name = "vpll",
152 .vin_name = "vcc5",
153 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
154 .voltage_table = VPLL_VSEL_table,
155 .enable_time_us = 100,
156 },
157 {
158 .name = "vdac",
159 .vin_name = "vcc5",
160 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
161 .voltage_table = VDAC_VSEL_table,
162 .enable_time_us = 100,
163 },
164 {
165 .name = "vaux1",
166 .vin_name = "vcc4",
167 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
168 .voltage_table = VAUX1_VSEL_table,
169 .enable_time_us = 100,
170 },
171 {
172 .name = "vaux2",
173 .vin_name = "vcc4",
174 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
175 .voltage_table = VAUX2_VSEL_table,
176 .enable_time_us = 100,
177 },
178 {
179 .name = "vaux33",
180 .vin_name = "vcc3",
181 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
182 .voltage_table = VAUX33_VSEL_table,
183 .enable_time_us = 100,
184 },
185 {
186 .name = "vmmc",
187 .vin_name = "vcc3",
188 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
189 .voltage_table = VMMC_VSEL_table,
190 .enable_time_us = 100,
191 },
192 {
193 .name = "vbb",
194 .vin_name = "vcc7",
195 .n_voltages = ARRAY_SIZE(VBB_VSEL_table),
196 .voltage_table = VBB_VSEL_table,
197 },
198};
199
200static struct tps_info tps65911_regs[] = {
201 {
202 .name = "vrtc",
203 .vin_name = "vcc7",
204 .enable_time_us = 2200,
205 },
206 {
207 .name = "vio",
208 .vin_name = "vccio",
209 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
210 .voltage_table = VIO_VSEL_table,
211 .enable_time_us = 350,
212 },
213 {
214 .name = "vdd1",
215 .vin_name = "vcc1",
216 .n_voltages = 0x4C,
217 .enable_time_us = 350,
218 },
219 {
220 .name = "vdd2",
221 .vin_name = "vcc2",
222 .n_voltages = 0x4C,
223 .enable_time_us = 350,
224 },
225 {
226 .name = "vddctrl",
227 .n_voltages = 0x44,
228 .enable_time_us = 900,
229 },
230 {
231 .name = "ldo1",
232 .vin_name = "vcc6",
233 .n_voltages = 0x33,
234 .enable_time_us = 420,
235 },
236 {
237 .name = "ldo2",
238 .vin_name = "vcc6",
239 .n_voltages = 0x33,
240 .enable_time_us = 420,
241 },
242 {
243 .name = "ldo3",
244 .vin_name = "vcc5",
245 .n_voltages = 0x1A,
246 .enable_time_us = 230,
247 },
248 {
249 .name = "ldo4",
250 .vin_name = "vcc5",
251 .n_voltages = 0x33,
252 .enable_time_us = 230,
253 },
254 {
255 .name = "ldo5",
256 .vin_name = "vcc4",
257 .n_voltages = 0x1A,
258 .enable_time_us = 230,
259 },
260 {
261 .name = "ldo6",
262 .vin_name = "vcc3",
263 .n_voltages = 0x1A,
264 .enable_time_us = 230,
265 },
266 {
267 .name = "ldo7",
268 .vin_name = "vcc3",
269 .n_voltages = 0x1A,
270 .enable_time_us = 230,
271 },
272 {
273 .name = "ldo8",
274 .vin_name = "vcc3",
275 .n_voltages = 0x1A,
276 .enable_time_us = 230,
277 },
278};
279
280#define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
281static unsigned int tps65910_ext_sleep_control[] = {
282 0,
283 EXT_CONTROL_REG_BITS(VIO, 1, 0),
284 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
285 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
286 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
287 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
288 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
289 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
290 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
291 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
292 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
293 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
294 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
295};
296
297static unsigned int tps65911_ext_sleep_control[] = {
298 0,
299 EXT_CONTROL_REG_BITS(VIO, 1, 0),
300 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
301 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
302 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
303 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
304 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
305 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
306 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
307 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
308 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
309 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
310 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
311};
312
313struct tps65910_reg {
314 struct regulator_desc *desc;
315 struct tps65910 *mfd;
316 struct regulator_dev **rdev;
317 struct tps_info **info;
318 int num_regulators;
319 int mode;
320 int (*get_ctrl_reg)(int);
321 unsigned int *ext_sleep_control;
322 unsigned int board_ext_control[TPS65910_NUM_REGS];
323};
324
325static int tps65910_get_ctrl_register(int id)
326{
327 switch (id) {
328 case TPS65910_REG_VRTC:
329 return TPS65910_VRTC;
330 case TPS65910_REG_VIO:
331 return TPS65910_VIO;
332 case TPS65910_REG_VDD1:
333 return TPS65910_VDD1;
334 case TPS65910_REG_VDD2:
335 return TPS65910_VDD2;
336 case TPS65910_REG_VDD3:
337 return TPS65910_VDD3;
338 case TPS65910_REG_VDIG1:
339 return TPS65910_VDIG1;
340 case TPS65910_REG_VDIG2:
341 return TPS65910_VDIG2;
342 case TPS65910_REG_VPLL:
343 return TPS65910_VPLL;
344 case TPS65910_REG_VDAC:
345 return TPS65910_VDAC;
346 case TPS65910_REG_VAUX1:
347 return TPS65910_VAUX1;
348 case TPS65910_REG_VAUX2:
349 return TPS65910_VAUX2;
350 case TPS65910_REG_VAUX33:
351 return TPS65910_VAUX33;
352 case TPS65910_REG_VMMC:
353 return TPS65910_VMMC;
354 case TPS65910_REG_VBB:
355 return TPS65910_BBCH;
356 default:
357 return -EINVAL;
358 }
359}
360
361static int tps65911_get_ctrl_register(int id)
362{
363 switch (id) {
364 case TPS65910_REG_VRTC:
365 return TPS65910_VRTC;
366 case TPS65910_REG_VIO:
367 return TPS65910_VIO;
368 case TPS65910_REG_VDD1:
369 return TPS65910_VDD1;
370 case TPS65910_REG_VDD2:
371 return TPS65910_VDD2;
372 case TPS65911_REG_VDDCTRL:
373 return TPS65911_VDDCTRL;
374 case TPS65911_REG_LDO1:
375 return TPS65911_LDO1;
376 case TPS65911_REG_LDO2:
377 return TPS65911_LDO2;
378 case TPS65911_REG_LDO3:
379 return TPS65911_LDO3;
380 case TPS65911_REG_LDO4:
381 return TPS65911_LDO4;
382 case TPS65911_REG_LDO5:
383 return TPS65911_LDO5;
384 case TPS65911_REG_LDO6:
385 return TPS65911_LDO6;
386 case TPS65911_REG_LDO7:
387 return TPS65911_LDO7;
388 case TPS65911_REG_LDO8:
389 return TPS65911_LDO8;
390 default:
391 return -EINVAL;
392 }
393}
394
395static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
396{
397 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
398 struct tps65910 *mfd = pmic->mfd;
399 int reg, value, id = rdev_get_id(dev);
400
401 reg = pmic->get_ctrl_reg(id);
402 if (reg < 0)
403 return reg;
404
405 switch (mode) {
406 case REGULATOR_MODE_NORMAL:
407 return tps65910_reg_update_bits(pmic->mfd, reg,
408 LDO_ST_MODE_BIT | LDO_ST_ON_BIT,
409 LDO_ST_ON_BIT);
410 case REGULATOR_MODE_IDLE:
411 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
412 return tps65910_reg_set_bits(mfd, reg, value);
413 case REGULATOR_MODE_STANDBY:
414 return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
415 }
416
417 return -EINVAL;
418}
419
420static unsigned int tps65910_get_mode(struct regulator_dev *dev)
421{
422 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
423 int ret, reg, value, id = rdev_get_id(dev);
424
425 reg = pmic->get_ctrl_reg(id);
426 if (reg < 0)
427 return reg;
428
429 ret = tps65910_reg_read(pmic->mfd, reg, &value);
430 if (ret < 0)
431 return ret;
432
433 if (!(value & LDO_ST_ON_BIT))
434 return REGULATOR_MODE_STANDBY;
435 else if (value & LDO_ST_MODE_BIT)
436 return REGULATOR_MODE_IDLE;
437 else
438 return REGULATOR_MODE_NORMAL;
439}
440
441static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
442{
443 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
444 int ret, id = rdev_get_id(dev);
445 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
446
447 switch (id) {
448 case TPS65910_REG_VDD1:
449 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_OP, &opvsel);
450 if (ret < 0)
451 return ret;
452 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1, &mult);
453 if (ret < 0)
454 return ret;
455 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
456 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_SR, &srvsel);
457 if (ret < 0)
458 return ret;
459 sr = opvsel & VDD1_OP_CMD_MASK;
460 opvsel &= VDD1_OP_SEL_MASK;
461 srvsel &= VDD1_SR_SEL_MASK;
462 vselmax = 75;
463 break;
464 case TPS65910_REG_VDD2:
465 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_OP, &opvsel);
466 if (ret < 0)
467 return ret;
468 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2, &mult);
469 if (ret < 0)
470 return ret;
471 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
472 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_SR, &srvsel);
473 if (ret < 0)
474 return ret;
475 sr = opvsel & VDD2_OP_CMD_MASK;
476 opvsel &= VDD2_OP_SEL_MASK;
477 srvsel &= VDD2_SR_SEL_MASK;
478 vselmax = 75;
479 break;
480 case TPS65911_REG_VDDCTRL:
481 ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_OP,
482 &opvsel);
483 if (ret < 0)
484 return ret;
485 ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_SR,
486 &srvsel);
487 if (ret < 0)
488 return ret;
489 sr = opvsel & VDDCTRL_OP_CMD_MASK;
490 opvsel &= VDDCTRL_OP_SEL_MASK;
491 srvsel &= VDDCTRL_SR_SEL_MASK;
492 vselmax = 64;
493 break;
494 }
495
496 /* multiplier 0 == 1 but 2,3 normal */
497 if (!mult)
498 mult = 1;
499
500 if (sr) {
501 /* normalise to valid range */
502 if (srvsel < 3)
503 srvsel = 3;
504 if (srvsel > vselmax)
505 srvsel = vselmax;
506 return srvsel - 3;
507 } else {
508
509 /* normalise to valid range*/
510 if (opvsel < 3)
511 opvsel = 3;
512 if (opvsel > vselmax)
513 opvsel = vselmax;
514 return opvsel - 3;
515 }
516 return -EINVAL;
517}
518
519static int tps65910_get_voltage_sel(struct regulator_dev *dev)
520{
521 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
522 int ret, reg, value, id = rdev_get_id(dev);
523
524 reg = pmic->get_ctrl_reg(id);
525 if (reg < 0)
526 return reg;
527
528 ret = tps65910_reg_read(pmic->mfd, reg, &value);
529 if (ret < 0)
530 return ret;
531
532 switch (id) {
533 case TPS65910_REG_VIO:
534 case TPS65910_REG_VDIG1:
535 case TPS65910_REG_VDIG2:
536 case TPS65910_REG_VPLL:
537 case TPS65910_REG_VDAC:
538 case TPS65910_REG_VAUX1:
539 case TPS65910_REG_VAUX2:
540 case TPS65910_REG_VAUX33:
541 case TPS65910_REG_VMMC:
542 value &= LDO_SEL_MASK;
543 value >>= LDO_SEL_SHIFT;
544 break;
545 case TPS65910_REG_VBB:
546 value &= BBCH_BBSEL_MASK;
547 value >>= BBCH_BBSEL_SHIFT;
548 break;
549 default:
550 return -EINVAL;
551 }
552
553 return value;
554}
555
556static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
557{
558 return dev->desc->volt_table[0];
559}
560
561static int tps65911_get_voltage_sel(struct regulator_dev *dev)
562{
563 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
564 int ret, id = rdev_get_id(dev);
565 unsigned int value, reg;
566
567 reg = pmic->get_ctrl_reg(id);
568
569 ret = tps65910_reg_read(pmic->mfd, reg, &value);
570 if (ret < 0)
571 return ret;
572
573 switch (id) {
574 case TPS65911_REG_LDO1:
575 case TPS65911_REG_LDO2:
576 case TPS65911_REG_LDO4:
577 value &= LDO1_SEL_MASK;
578 value >>= LDO_SEL_SHIFT;
579 break;
580 case TPS65911_REG_LDO3:
581 case TPS65911_REG_LDO5:
582 case TPS65911_REG_LDO6:
583 case TPS65911_REG_LDO7:
584 case TPS65911_REG_LDO8:
585 value &= LDO3_SEL_MASK;
586 value >>= LDO_SEL_SHIFT;
587 break;
588 case TPS65910_REG_VIO:
589 value &= LDO_SEL_MASK;
590 value >>= LDO_SEL_SHIFT;
591 break;
592 default:
593 return -EINVAL;
594 }
595
596 return value;
597}
598
599static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
600 unsigned selector)
601{
602 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
603 int id = rdev_get_id(dev), vsel;
604 int dcdc_mult = 0;
605
606 switch (id) {
607 case TPS65910_REG_VDD1:
608 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
609 if (dcdc_mult == 1)
610 dcdc_mult--;
611 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
612
613 tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD1,
614 VDD1_VGAIN_SEL_MASK,
615 dcdc_mult << VDD1_VGAIN_SEL_SHIFT);
616 tps65910_reg_write(pmic->mfd, TPS65910_VDD1_OP, vsel);
617 break;
618 case TPS65910_REG_VDD2:
619 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
620 if (dcdc_mult == 1)
621 dcdc_mult--;
622 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
623
624 tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD2,
625 VDD1_VGAIN_SEL_MASK,
626 dcdc_mult << VDD2_VGAIN_SEL_SHIFT);
627 tps65910_reg_write(pmic->mfd, TPS65910_VDD2_OP, vsel);
628 break;
629 case TPS65911_REG_VDDCTRL:
630 vsel = selector + 3;
631 tps65910_reg_write(pmic->mfd, TPS65911_VDDCTRL_OP, vsel);
632 }
633
634 return 0;
635}
636
637static int tps65910_set_voltage_sel(struct regulator_dev *dev,
638 unsigned selector)
639{
640 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
641 int reg, id = rdev_get_id(dev);
642
643 reg = pmic->get_ctrl_reg(id);
644 if (reg < 0)
645 return reg;
646
647 switch (id) {
648 case TPS65910_REG_VIO:
649 case TPS65910_REG_VDIG1:
650 case TPS65910_REG_VDIG2:
651 case TPS65910_REG_VPLL:
652 case TPS65910_REG_VDAC:
653 case TPS65910_REG_VAUX1:
654 case TPS65910_REG_VAUX2:
655 case TPS65910_REG_VAUX33:
656 case TPS65910_REG_VMMC:
657 return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK,
658 selector << LDO_SEL_SHIFT);
659 case TPS65910_REG_VBB:
660 return tps65910_reg_update_bits(pmic->mfd, reg, BBCH_BBSEL_MASK,
661 selector << BBCH_BBSEL_SHIFT);
662 }
663
664 return -EINVAL;
665}
666
667static int tps65911_set_voltage_sel(struct regulator_dev *dev,
668 unsigned selector)
669{
670 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
671 int reg, id = rdev_get_id(dev);
672
673 reg = pmic->get_ctrl_reg(id);
674 if (reg < 0)
675 return reg;
676
677 switch (id) {
678 case TPS65911_REG_LDO1:
679 case TPS65911_REG_LDO2:
680 case TPS65911_REG_LDO4:
681 return tps65910_reg_update_bits(pmic->mfd, reg, LDO1_SEL_MASK,
682 selector << LDO_SEL_SHIFT);
683 case TPS65911_REG_LDO3:
684 case TPS65911_REG_LDO5:
685 case TPS65911_REG_LDO6:
686 case TPS65911_REG_LDO7:
687 case TPS65911_REG_LDO8:
688 return tps65910_reg_update_bits(pmic->mfd, reg, LDO3_SEL_MASK,
689 selector << LDO_SEL_SHIFT);
690 case TPS65910_REG_VIO:
691 return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK,
692 selector << LDO_SEL_SHIFT);
693 case TPS65910_REG_VBB:
694 return tps65910_reg_update_bits(pmic->mfd, reg, BBCH_BBSEL_MASK,
695 selector << BBCH_BBSEL_SHIFT);
696 }
697
698 return -EINVAL;
699}
700
701
702static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
703 unsigned selector)
704{
705 int volt, mult = 1, id = rdev_get_id(dev);
706
707 switch (id) {
708 case TPS65910_REG_VDD1:
709 case TPS65910_REG_VDD2:
710 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
711 volt = VDD1_2_MIN_VOLT +
712 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
713 break;
714 case TPS65911_REG_VDDCTRL:
715 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
716 break;
717 default:
718 BUG();
719 return -EINVAL;
720 }
721
722 return volt * 100 * mult;
723}
724
725static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
726{
727 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
728 int step_mv = 0, id = rdev_get_id(dev);
729
730 switch (id) {
731 case TPS65911_REG_LDO1:
732 case TPS65911_REG_LDO2:
733 case TPS65911_REG_LDO4:
734 /* The first 5 values of the selector correspond to 1V */
735 if (selector < 5)
736 selector = 0;
737 else
738 selector -= 4;
739
740 step_mv = 50;
741 break;
742 case TPS65911_REG_LDO3:
743 case TPS65911_REG_LDO5:
744 case TPS65911_REG_LDO6:
745 case TPS65911_REG_LDO7:
746 case TPS65911_REG_LDO8:
747 /* The first 3 values of the selector correspond to 1V */
748 if (selector < 3)
749 selector = 0;
750 else
751 selector -= 2;
752
753 step_mv = 100;
754 break;
755 case TPS65910_REG_VIO:
756 return pmic->info[id]->voltage_table[selector];
757 default:
758 return -EINVAL;
759 }
760
761 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
762}
763
764/* Regulator ops (except VRTC) */
765static struct regulator_ops tps65910_ops_dcdc = {
766 .is_enabled = regulator_is_enabled_regmap,
767 .enable = regulator_enable_regmap,
768 .disable = regulator_disable_regmap,
769 .set_mode = tps65910_set_mode,
770 .get_mode = tps65910_get_mode,
771 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
772 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
773 .set_voltage_time_sel = regulator_set_voltage_time_sel,
774 .list_voltage = tps65910_list_voltage_dcdc,
775 .map_voltage = regulator_map_voltage_ascend,
776};
777
778static struct regulator_ops tps65910_ops_vdd3 = {
779 .is_enabled = regulator_is_enabled_regmap,
780 .enable = regulator_enable_regmap,
781 .disable = regulator_disable_regmap,
782 .set_mode = tps65910_set_mode,
783 .get_mode = tps65910_get_mode,
784 .get_voltage = tps65910_get_voltage_vdd3,
785 .list_voltage = regulator_list_voltage_table,
786 .map_voltage = regulator_map_voltage_ascend,
787};
788
789static struct regulator_ops tps65910_ops_vbb = {
790 .is_enabled = regulator_is_enabled_regmap,
791 .enable = regulator_enable_regmap,
792 .disable = regulator_disable_regmap,
793 .set_mode = tps65910_set_mode,
794 .get_mode = tps65910_get_mode,
795 .get_voltage_sel = tps65910_get_voltage_sel,
796 .set_voltage_sel = tps65910_set_voltage_sel,
797 .list_voltage = regulator_list_voltage_table,
798 .map_voltage = regulator_map_voltage_iterate,
799};
800
801static struct regulator_ops tps65910_ops = {
802 .is_enabled = regulator_is_enabled_regmap,
803 .enable = regulator_enable_regmap,
804 .disable = regulator_disable_regmap,
805 .set_mode = tps65910_set_mode,
806 .get_mode = tps65910_get_mode,
807 .get_voltage_sel = tps65910_get_voltage_sel,
808 .set_voltage_sel = tps65910_set_voltage_sel,
809 .list_voltage = regulator_list_voltage_table,
810 .map_voltage = regulator_map_voltage_ascend,
811};
812
813static struct regulator_ops tps65911_ops = {
814 .is_enabled = regulator_is_enabled_regmap,
815 .enable = regulator_enable_regmap,
816 .disable = regulator_disable_regmap,
817 .set_mode = tps65910_set_mode,
818 .get_mode = tps65910_get_mode,
819 .get_voltage_sel = tps65911_get_voltage_sel,
820 .set_voltage_sel = tps65911_set_voltage_sel,
821 .list_voltage = tps65911_list_voltage,
822 .map_voltage = regulator_map_voltage_ascend,
823};
824
825static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
826 int id, int ext_sleep_config)
827{
828 struct tps65910 *mfd = pmic->mfd;
829 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
830 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
831 int ret;
832
833 /*
834 * Regulator can not be control from multiple external input EN1, EN2
835 * and EN3 together.
836 */
837 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
838 int en_count;
839 en_count = ((ext_sleep_config &
840 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
841 en_count += ((ext_sleep_config &
842 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
843 en_count += ((ext_sleep_config &
844 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
845 en_count += ((ext_sleep_config &
846 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
847 if (en_count > 1) {
848 dev_err(mfd->dev,
849 "External sleep control flag is not proper\n");
850 return -EINVAL;
851 }
852 }
853
854 pmic->board_ext_control[id] = ext_sleep_config;
855
856 /* External EN1 control */
857 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
858 ret = tps65910_reg_set_bits(mfd,
859 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
860 else
861 ret = tps65910_reg_clear_bits(mfd,
862 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
863 if (ret < 0) {
864 dev_err(mfd->dev,
865 "Error in configuring external control EN1\n");
866 return ret;
867 }
868
869 /* External EN2 control */
870 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
871 ret = tps65910_reg_set_bits(mfd,
872 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
873 else
874 ret = tps65910_reg_clear_bits(mfd,
875 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
876 if (ret < 0) {
877 dev_err(mfd->dev,
878 "Error in configuring external control EN2\n");
879 return ret;
880 }
881
882 /* External EN3 control for TPS65910 LDO only */
883 if ((tps65910_chip_id(mfd) == TPS65910) &&
884 (id >= TPS65910_REG_VDIG1)) {
885 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
886 ret = tps65910_reg_set_bits(mfd,
887 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
888 else
889 ret = tps65910_reg_clear_bits(mfd,
890 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
891 if (ret < 0) {
892 dev_err(mfd->dev,
893 "Error in configuring external control EN3\n");
894 return ret;
895 }
896 }
897
898 /* Return if no external control is selected */
899 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
900 /* Clear all sleep controls */
901 ret = tps65910_reg_clear_bits(mfd,
902 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
903 if (!ret)
904 ret = tps65910_reg_clear_bits(mfd,
905 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
906 if (ret < 0)
907 dev_err(mfd->dev,
908 "Error in configuring SLEEP register\n");
909 return ret;
910 }
911
912 /*
913 * For regulator that has separate operational and sleep register make
914 * sure that operational is used and clear sleep register to turn
915 * regulator off when external control is inactive
916 */
917 if ((id == TPS65910_REG_VDD1) ||
918 (id == TPS65910_REG_VDD2) ||
919 ((id == TPS65911_REG_VDDCTRL) &&
920 (tps65910_chip_id(mfd) == TPS65911))) {
921 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
922 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
923 int opvsel, srvsel;
924
925 ret = tps65910_reg_read(pmic->mfd, op_reg_add, &opvsel);
926 if (ret < 0)
927 return ret;
928 ret = tps65910_reg_read(pmic->mfd, sr_reg_add, &srvsel);
929 if (ret < 0)
930 return ret;
931
932 if (opvsel & VDD1_OP_CMD_MASK) {
933 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
934
935 ret = tps65910_reg_write(pmic->mfd, op_reg_add,
936 reg_val);
937 if (ret < 0) {
938 dev_err(mfd->dev,
939 "Error in configuring op register\n");
940 return ret;
941 }
942 }
943 ret = tps65910_reg_write(pmic->mfd, sr_reg_add, 0);
944 if (ret < 0) {
945 dev_err(mfd->dev, "Error in setting sr register\n");
946 return ret;
947 }
948 }
949
950 ret = tps65910_reg_clear_bits(mfd,
951 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
952 if (!ret) {
953 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
954 ret = tps65910_reg_set_bits(mfd,
955 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
956 else
957 ret = tps65910_reg_clear_bits(mfd,
958 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
959 }
960 if (ret < 0)
961 dev_err(mfd->dev,
962 "Error in configuring SLEEP register\n");
963
964 return ret;
965}
966
967#ifdef CONFIG_OF
968
969static struct of_regulator_match tps65910_matches[] = {
970 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
971 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
972 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
973 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
974 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
975 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
976 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
977 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
978 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
979 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
980 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
981 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
982 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
983 { .name = "vbb", .driver_data = (void *) &tps65910_regs[13] },
984};
985
986static struct of_regulator_match tps65911_matches[] = {
987 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
988 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
989 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
990 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
991 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
992 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
993 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
994 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
995 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
996 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
997 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
998 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
999 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
1000};
1001
1002static struct tps65910_board *tps65910_parse_dt_reg_data(
1003 struct platform_device *pdev,
1004 struct of_regulator_match **tps65910_reg_matches)
1005{
1006 struct tps65910_board *pmic_plat_data;
1007 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1008 struct device_node *np, *regulators;
1009 struct of_regulator_match *matches;
1010 unsigned int prop;
1011 int idx = 0, ret, count;
1012
1013 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
1014 GFP_KERNEL);
1015 if (!pmic_plat_data)
1016 return NULL;
1017
1018 np = pdev->dev.parent->of_node;
1019 regulators = of_get_child_by_name(np, "regulators");
1020 if (!regulators) {
1021 dev_err(&pdev->dev, "regulator node not found\n");
1022 return NULL;
1023 }
1024
1025 switch (tps65910_chip_id(tps65910)) {
1026 case TPS65910:
1027 count = ARRAY_SIZE(tps65910_matches);
1028 matches = tps65910_matches;
1029 break;
1030 case TPS65911:
1031 count = ARRAY_SIZE(tps65911_matches);
1032 matches = tps65911_matches;
1033 break;
1034 default:
1035 of_node_put(regulators);
1036 dev_err(&pdev->dev, "Invalid tps chip version\n");
1037 return NULL;
1038 }
1039
1040 ret = of_regulator_match(&pdev->dev, regulators, matches, count);
1041 of_node_put(regulators);
1042 if (ret < 0) {
1043 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1044 ret);
1045 return NULL;
1046 }
1047
1048 *tps65910_reg_matches = matches;
1049
1050 for (idx = 0; idx < count; idx++) {
1051 if (!matches[idx].of_node)
1052 continue;
1053
1054 pmic_plat_data->tps65910_pmic_init_data[idx] =
1055 matches[idx].init_data;
1056
1057 ret = of_property_read_u32(matches[idx].of_node,
1058 "ti,regulator-ext-sleep-control", &prop);
1059 if (!ret)
1060 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1061
1062 }
1063
1064 return pmic_plat_data;
1065}
1066#else
1067static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1068 struct platform_device *pdev,
1069 struct of_regulator_match **tps65910_reg_matches)
1070{
1071 *tps65910_reg_matches = NULL;
1072 return NULL;
1073}
1074#endif
1075
1076static int tps65910_probe(struct platform_device *pdev)
1077{
1078 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1079 struct regulator_config config = { };
1080 struct tps_info *info;
1081 struct regulator_dev *rdev;
1082 struct tps65910_reg *pmic;
1083 struct tps65910_board *pmic_plat_data;
1084 struct of_regulator_match *tps65910_reg_matches = NULL;
1085 int i, err;
1086
1087 pmic_plat_data = dev_get_platdata(tps65910->dev);
1088 if (!pmic_plat_data && tps65910->dev->of_node)
1089 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1090 &tps65910_reg_matches);
1091
1092 if (!pmic_plat_data) {
1093 dev_err(&pdev->dev, "Platform data not found\n");
1094 return -EINVAL;
1095 }
1096
1097 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1098 if (!pmic)
1099 return -ENOMEM;
1100
1101 pmic->mfd = tps65910;
1102 platform_set_drvdata(pdev, pmic);
1103
1104 /* Give control of all register to control port */
1105 tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1106 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1107
1108 switch (tps65910_chip_id(tps65910)) {
1109 case TPS65910:
1110 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1111 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1112 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1113 info = tps65910_regs;
1114 break;
1115 case TPS65911:
1116 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1117 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1118 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1119 info = tps65911_regs;
1120 break;
1121 default:
1122 dev_err(&pdev->dev, "Invalid tps chip version\n");
1123 return -ENODEV;
1124 }
1125
1126 pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1127 sizeof(struct regulator_desc), GFP_KERNEL);
1128 if (!pmic->desc)
1129 return -ENOMEM;
1130
1131 pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1132 sizeof(struct tps_info *), GFP_KERNEL);
1133 if (!pmic->info)
1134 return -ENOMEM;
1135
1136 pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1137 sizeof(struct regulator_dev *), GFP_KERNEL);
1138 if (!pmic->rdev)
1139 return -ENOMEM;
1140
1141 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1142 i++, info++) {
1143 /* Register the regulators */
1144 pmic->info[i] = info;
1145
1146 pmic->desc[i].name = info->name;
1147 pmic->desc[i].supply_name = info->vin_name;
1148 pmic->desc[i].id = i;
1149 pmic->desc[i].n_voltages = info->n_voltages;
1150 pmic->desc[i].enable_time = info->enable_time_us;
1151
1152 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1153 pmic->desc[i].ops = &tps65910_ops_dcdc;
1154 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1155 VDD1_2_NUM_VOLT_COARSE;
1156 pmic->desc[i].ramp_delay = 12500;
1157 } else if (i == TPS65910_REG_VDD3) {
1158 if (tps65910_chip_id(tps65910) == TPS65910) {
1159 pmic->desc[i].ops = &tps65910_ops_vdd3;
1160 pmic->desc[i].volt_table = info->voltage_table;
1161 } else {
1162 pmic->desc[i].ops = &tps65910_ops_dcdc;
1163 pmic->desc[i].ramp_delay = 5000;
1164 }
1165 } else if (i == TPS65910_REG_VBB &&
1166 tps65910_chip_id(tps65910) == TPS65910) {
1167 pmic->desc[i].ops = &tps65910_ops_vbb;
1168 pmic->desc[i].volt_table = info->voltage_table;
1169 } else {
1170 if (tps65910_chip_id(tps65910) == TPS65910) {
1171 pmic->desc[i].ops = &tps65910_ops;
1172 pmic->desc[i].volt_table = info->voltage_table;
1173 } else {
1174 pmic->desc[i].ops = &tps65911_ops;
1175 }
1176 }
1177
1178 err = tps65910_set_ext_sleep_config(pmic, i,
1179 pmic_plat_data->regulator_ext_sleep_control[i]);
1180 /*
1181 * Failing on regulator for configuring externally control
1182 * is not a serious issue, just throw warning.
1183 */
1184 if (err < 0)
1185 dev_warn(tps65910->dev,
1186 "Failed to initialise ext control config\n");
1187
1188 pmic->desc[i].type = REGULATOR_VOLTAGE;
1189 pmic->desc[i].owner = THIS_MODULE;
1190 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1191 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1192
1193 config.dev = tps65910->dev;
1194 config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
1195 config.driver_data = pmic;
1196 config.regmap = tps65910->regmap;
1197
1198 if (tps65910_reg_matches)
1199 config.of_node = tps65910_reg_matches[i].of_node;
1200
1201 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
1202 &config);
1203 if (IS_ERR(rdev)) {
1204 dev_err(tps65910->dev,
1205 "failed to register %s regulator\n",
1206 pdev->name);
1207 return PTR_ERR(rdev);
1208 }
1209
1210 /* Save regulator for cleanup */
1211 pmic->rdev[i] = rdev;
1212 }
1213 return 0;
1214}
1215
1216static void tps65910_shutdown(struct platform_device *pdev)
1217{
1218 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1219 int i;
1220
1221 /*
1222 * Before bootloader jumps to kernel, it makes sure that required
1223 * external control signals are in desired state so that given rails
1224 * can be configure accordingly.
1225 * If rails are configured to be controlled from external control
1226 * then before shutting down/rebooting the system, the external
1227 * control configuration need to be remove from the rails so that
1228 * its output will be available as per register programming even
1229 * if external controls are removed. This is require when the POR
1230 * value of the control signals are not in active state and before
1231 * bootloader initializes it, the system requires the rail output
1232 * to be active for booting.
1233 */
1234 for (i = 0; i < pmic->num_regulators; i++) {
1235 int err;
1236 if (!pmic->rdev[i])
1237 continue;
1238
1239 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1240 if (err < 0)
1241 dev_err(&pdev->dev,
1242 "Error in clearing external control\n");
1243 }
1244}
1245
1246static struct platform_driver tps65910_driver = {
1247 .driver = {
1248 .name = "tps65910-pmic",
1249 },
1250 .probe = tps65910_probe,
1251 .shutdown = tps65910_shutdown,
1252};
1253
1254static int __init tps65910_init(void)
1255{
1256 return platform_driver_register(&tps65910_driver);
1257}
1258subsys_initcall(tps65910_init);
1259
1260static void __exit tps65910_cleanup(void)
1261{
1262 platform_driver_unregister(&tps65910_driver);
1263}
1264module_exit(tps65910_cleanup);
1265
1266MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1267MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1268MODULE_LICENSE("GPL v2");
1269MODULE_ALIAS("platform:tps65910-pmic");