2 * TI LP8788 MFD - ldo regulator driver
4 * Copyright 2012 Texas Instruments
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/err.h>
17 #include <linux/platform_device.h>
18 #include <linux/regulator/driver.h>
19 #include <linux/gpio.h>
20 #include <linux/mfd/lp8788.h>
22 /* register address */
23 #define LP8788_EN_LDO_A 0x0D /* DLDO 1 ~ 8 */
24 #define LP8788_EN_LDO_B 0x0E /* DLDO 9 ~ 12, ALDO 1 ~ 4 */
25 #define LP8788_EN_LDO_C 0x0F /* ALDO 5 ~ 10 */
26 #define LP8788_EN_SEL 0x10
27 #define LP8788_DLDO1_VOUT 0x2E
28 #define LP8788_DLDO2_VOUT 0x2F
29 #define LP8788_DLDO3_VOUT 0x30
30 #define LP8788_DLDO4_VOUT 0x31
31 #define LP8788_DLDO5_VOUT 0x32
32 #define LP8788_DLDO6_VOUT 0x33
33 #define LP8788_DLDO7_VOUT 0x34
34 #define LP8788_DLDO8_VOUT 0x35
35 #define LP8788_DLDO9_VOUT 0x36
36 #define LP8788_DLDO10_VOUT 0x37
37 #define LP8788_DLDO11_VOUT 0x38
38 #define LP8788_DLDO12_VOUT 0x39
39 #define LP8788_ALDO1_VOUT 0x3A
40 #define LP8788_ALDO2_VOUT 0x3B
41 #define LP8788_ALDO3_VOUT 0x3C
42 #define LP8788_ALDO4_VOUT 0x3D
43 #define LP8788_ALDO5_VOUT 0x3E
44 #define LP8788_ALDO6_VOUT 0x3F
45 #define LP8788_ALDO7_VOUT 0x40
46 #define LP8788_ALDO8_VOUT 0x41
47 #define LP8788_ALDO9_VOUT 0x42
48 #define LP8788_ALDO10_VOUT 0x43
49 #define LP8788_DLDO1_TIMESTEP 0x44
52 #define LP8788_EN_DLDO1_M BIT(0) /* Addr 0Dh ~ 0Fh */
53 #define LP8788_EN_DLDO2_M BIT(1)
54 #define LP8788_EN_DLDO3_M BIT(2)
55 #define LP8788_EN_DLDO4_M BIT(3)
56 #define LP8788_EN_DLDO5_M BIT(4)
57 #define LP8788_EN_DLDO6_M BIT(5)
58 #define LP8788_EN_DLDO7_M BIT(6)
59 #define LP8788_EN_DLDO8_M BIT(7)
60 #define LP8788_EN_DLDO9_M BIT(0)
61 #define LP8788_EN_DLDO10_M BIT(1)
62 #define LP8788_EN_DLDO11_M BIT(2)
63 #define LP8788_EN_DLDO12_M BIT(3)
64 #define LP8788_EN_ALDO1_M BIT(4)
65 #define LP8788_EN_ALDO2_M BIT(5)
66 #define LP8788_EN_ALDO3_M BIT(6)
67 #define LP8788_EN_ALDO4_M BIT(7)
68 #define LP8788_EN_ALDO5_M BIT(0)
69 #define LP8788_EN_ALDO6_M BIT(1)
70 #define LP8788_EN_ALDO7_M BIT(2)
71 #define LP8788_EN_ALDO8_M BIT(3)
72 #define LP8788_EN_ALDO9_M BIT(4)
73 #define LP8788_EN_ALDO10_M BIT(5)
74 #define LP8788_EN_SEL_DLDO911_M BIT(0) /* Addr 10h */
75 #define LP8788_EN_SEL_DLDO7_M BIT(1)
76 #define LP8788_EN_SEL_ALDO7_M BIT(2)
77 #define LP8788_EN_SEL_ALDO5_M BIT(3)
78 #define LP8788_EN_SEL_ALDO234_M BIT(4)
79 #define LP8788_EN_SEL_ALDO1_M BIT(5)
80 #define LP8788_VOUT_5BIT_M 0x1F /* Addr 2Eh ~ 43h */
81 #define LP8788_VOUT_4BIT_M 0x0F
82 #define LP8788_VOUT_3BIT_M 0x07
83 #define LP8788_VOUT_1BIT_M 0x01
84 #define LP8788_STARTUP_TIME_M 0xF8 /* Addr 44h ~ 59h */
85 #define LP8788_STARTUP_TIME_S 3
87 #define ENABLE_TIME_USEC 32
88 #define ENABLE GPIOF_OUT_INIT_HIGH
89 #define DISABLE GPIOF_OUT_INIT_LOW
118 struct regulator_desc
*desc
;
119 struct regulator_dev
*regulator
;
120 struct lp8788_ldo_enable_pin
*en_pin
;
123 /* DLDO 1, 2, 3, 9 voltage table */
124 static const int lp8788_dldo1239_vtbl
[] = {
125 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
126 2600000, 2700000, 2800000, 2900000, 3000000, 2850000, 2850000, 2850000,
127 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000,
128 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000,
131 /* DLDO 4 voltage table */
132 static const int lp8788_dldo4_vtbl
[] = { 1800000, 3000000 };
134 /* DLDO 5, 7, 8 and ALDO 6 voltage table */
135 static const int lp8788_dldo578_aldo6_vtbl
[] = {
136 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
137 2600000, 2700000, 2800000, 2900000, 3000000, 3000000, 3000000, 3000000,
140 /* DLDO 6 voltage table */
141 static const int lp8788_dldo6_vtbl
[] = {
142 3000000, 3100000, 3200000, 3300000, 3400000, 3500000, 3600000, 3600000,
145 /* DLDO 10, 11 voltage table */
146 static const int lp8788_dldo1011_vtbl
[] = {
147 1100000, 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000,
148 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, 1500000,
151 /* ALDO 1 voltage table */
152 static const int lp8788_aldo1_vtbl
[] = { 1800000, 2850000 };
154 /* ALDO 7 voltage table */
155 static const int lp8788_aldo7_vtbl
[] = {
156 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1800000,
159 static int lp8788_ldo_enable_time(struct regulator_dev
*rdev
)
161 struct lp8788_ldo
*ldo
= rdev_get_drvdata(rdev
);
162 enum lp8788_ldo_id id
= rdev_get_id(rdev
);
163 u8 val
, addr
= LP8788_DLDO1_TIMESTEP
+ id
;
165 if (lp8788_read_byte(ldo
->lp
, addr
, &val
))
168 val
= (val
& LP8788_STARTUP_TIME_M
) >> LP8788_STARTUP_TIME_S
;
170 return ENABLE_TIME_USEC
* val
;
173 static struct regulator_ops lp8788_ldo_voltage_table_ops
= {
174 .list_voltage
= regulator_list_voltage_table
,
175 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
176 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
177 .enable
= regulator_enable_regmap
,
178 .disable
= regulator_disable_regmap
,
179 .is_enabled
= regulator_is_enabled_regmap
,
180 .enable_time
= lp8788_ldo_enable_time
,
183 static struct regulator_ops lp8788_ldo_voltage_fixed_ops
= {
184 .list_voltage
= regulator_list_voltage_linear
,
185 .enable
= regulator_enable_regmap
,
186 .disable
= regulator_disable_regmap
,
187 .is_enabled
= regulator_is_enabled_regmap
,
188 .enable_time
= lp8788_ldo_enable_time
,
191 static struct regulator_desc lp8788_dldo_desc
[] = {
195 .ops
= &lp8788_ldo_voltage_table_ops
,
196 .n_voltages
= ARRAY_SIZE(lp8788_dldo1239_vtbl
),
197 .volt_table
= lp8788_dldo1239_vtbl
,
198 .type
= REGULATOR_VOLTAGE
,
199 .owner
= THIS_MODULE
,
200 .vsel_reg
= LP8788_DLDO1_VOUT
,
201 .vsel_mask
= LP8788_VOUT_5BIT_M
,
202 .enable_reg
= LP8788_EN_LDO_A
,
203 .enable_mask
= LP8788_EN_DLDO1_M
,
208 .ops
= &lp8788_ldo_voltage_table_ops
,
209 .n_voltages
= ARRAY_SIZE(lp8788_dldo1239_vtbl
),
210 .volt_table
= lp8788_dldo1239_vtbl
,
211 .type
= REGULATOR_VOLTAGE
,
212 .owner
= THIS_MODULE
,
213 .vsel_reg
= LP8788_DLDO2_VOUT
,
214 .vsel_mask
= LP8788_VOUT_5BIT_M
,
215 .enable_reg
= LP8788_EN_LDO_A
,
216 .enable_mask
= LP8788_EN_DLDO2_M
,
221 .ops
= &lp8788_ldo_voltage_table_ops
,
222 .n_voltages
= ARRAY_SIZE(lp8788_dldo1239_vtbl
),
223 .volt_table
= lp8788_dldo1239_vtbl
,
224 .type
= REGULATOR_VOLTAGE
,
225 .owner
= THIS_MODULE
,
226 .vsel_reg
= LP8788_DLDO3_VOUT
,
227 .vsel_mask
= LP8788_VOUT_5BIT_M
,
228 .enable_reg
= LP8788_EN_LDO_A
,
229 .enable_mask
= LP8788_EN_DLDO3_M
,
234 .ops
= &lp8788_ldo_voltage_table_ops
,
235 .n_voltages
= ARRAY_SIZE(lp8788_dldo4_vtbl
),
236 .volt_table
= lp8788_dldo4_vtbl
,
237 .type
= REGULATOR_VOLTAGE
,
238 .owner
= THIS_MODULE
,
239 .vsel_reg
= LP8788_DLDO4_VOUT
,
240 .vsel_mask
= LP8788_VOUT_1BIT_M
,
241 .enable_reg
= LP8788_EN_LDO_A
,
242 .enable_mask
= LP8788_EN_DLDO4_M
,
247 .ops
= &lp8788_ldo_voltage_table_ops
,
248 .n_voltages
= ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl
),
249 .volt_table
= lp8788_dldo578_aldo6_vtbl
,
250 .type
= REGULATOR_VOLTAGE
,
251 .owner
= THIS_MODULE
,
252 .vsel_reg
= LP8788_DLDO5_VOUT
,
253 .vsel_mask
= LP8788_VOUT_4BIT_M
,
254 .enable_reg
= LP8788_EN_LDO_A
,
255 .enable_mask
= LP8788_EN_DLDO5_M
,
260 .ops
= &lp8788_ldo_voltage_table_ops
,
261 .n_voltages
= ARRAY_SIZE(lp8788_dldo6_vtbl
),
262 .volt_table
= lp8788_dldo6_vtbl
,
263 .type
= REGULATOR_VOLTAGE
,
264 .owner
= THIS_MODULE
,
265 .vsel_reg
= LP8788_DLDO6_VOUT
,
266 .vsel_mask
= LP8788_VOUT_3BIT_M
,
267 .enable_reg
= LP8788_EN_LDO_A
,
268 .enable_mask
= LP8788_EN_DLDO6_M
,
273 .ops
= &lp8788_ldo_voltage_table_ops
,
274 .n_voltages
= ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl
),
275 .volt_table
= lp8788_dldo578_aldo6_vtbl
,
276 .type
= REGULATOR_VOLTAGE
,
277 .owner
= THIS_MODULE
,
278 .vsel_reg
= LP8788_DLDO7_VOUT
,
279 .vsel_mask
= LP8788_VOUT_4BIT_M
,
280 .enable_reg
= LP8788_EN_LDO_A
,
281 .enable_mask
= LP8788_EN_DLDO7_M
,
286 .ops
= &lp8788_ldo_voltage_table_ops
,
287 .n_voltages
= ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl
),
288 .volt_table
= lp8788_dldo578_aldo6_vtbl
,
289 .type
= REGULATOR_VOLTAGE
,
290 .owner
= THIS_MODULE
,
291 .vsel_reg
= LP8788_DLDO8_VOUT
,
292 .vsel_mask
= LP8788_VOUT_4BIT_M
,
293 .enable_reg
= LP8788_EN_LDO_A
,
294 .enable_mask
= LP8788_EN_DLDO8_M
,
299 .ops
= &lp8788_ldo_voltage_table_ops
,
300 .n_voltages
= ARRAY_SIZE(lp8788_dldo1239_vtbl
),
301 .volt_table
= lp8788_dldo1239_vtbl
,
302 .type
= REGULATOR_VOLTAGE
,
303 .owner
= THIS_MODULE
,
304 .vsel_reg
= LP8788_DLDO9_VOUT
,
305 .vsel_mask
= LP8788_VOUT_5BIT_M
,
306 .enable_reg
= LP8788_EN_LDO_B
,
307 .enable_mask
= LP8788_EN_DLDO9_M
,
312 .ops
= &lp8788_ldo_voltage_table_ops
,
313 .n_voltages
= ARRAY_SIZE(lp8788_dldo1011_vtbl
),
314 .volt_table
= lp8788_dldo1011_vtbl
,
315 .type
= REGULATOR_VOLTAGE
,
316 .owner
= THIS_MODULE
,
317 .vsel_reg
= LP8788_DLDO10_VOUT
,
318 .vsel_mask
= LP8788_VOUT_4BIT_M
,
319 .enable_reg
= LP8788_EN_LDO_B
,
320 .enable_mask
= LP8788_EN_DLDO10_M
,
325 .ops
= &lp8788_ldo_voltage_table_ops
,
326 .n_voltages
= ARRAY_SIZE(lp8788_dldo1011_vtbl
),
327 .volt_table
= lp8788_dldo1011_vtbl
,
328 .type
= REGULATOR_VOLTAGE
,
329 .owner
= THIS_MODULE
,
330 .vsel_reg
= LP8788_DLDO11_VOUT
,
331 .vsel_mask
= LP8788_VOUT_4BIT_M
,
332 .enable_reg
= LP8788_EN_LDO_B
,
333 .enable_mask
= LP8788_EN_DLDO11_M
,
338 .ops
= &lp8788_ldo_voltage_fixed_ops
,
340 .type
= REGULATOR_VOLTAGE
,
341 .owner
= THIS_MODULE
,
342 .enable_reg
= LP8788_EN_LDO_B
,
343 .enable_mask
= LP8788_EN_DLDO12_M
,
348 static struct regulator_desc lp8788_aldo_desc
[] = {
352 .ops
= &lp8788_ldo_voltage_table_ops
,
353 .n_voltages
= ARRAY_SIZE(lp8788_aldo1_vtbl
),
354 .volt_table
= lp8788_aldo1_vtbl
,
355 .type
= REGULATOR_VOLTAGE
,
356 .owner
= THIS_MODULE
,
357 .vsel_reg
= LP8788_ALDO1_VOUT
,
358 .vsel_mask
= LP8788_VOUT_1BIT_M
,
359 .enable_reg
= LP8788_EN_LDO_B
,
360 .enable_mask
= LP8788_EN_ALDO1_M
,
365 .ops
= &lp8788_ldo_voltage_fixed_ops
,
367 .type
= REGULATOR_VOLTAGE
,
368 .owner
= THIS_MODULE
,
369 .enable_reg
= LP8788_EN_LDO_B
,
370 .enable_mask
= LP8788_EN_ALDO2_M
,
376 .ops
= &lp8788_ldo_voltage_fixed_ops
,
378 .type
= REGULATOR_VOLTAGE
,
379 .owner
= THIS_MODULE
,
380 .enable_reg
= LP8788_EN_LDO_B
,
381 .enable_mask
= LP8788_EN_ALDO3_M
,
387 .ops
= &lp8788_ldo_voltage_fixed_ops
,
389 .type
= REGULATOR_VOLTAGE
,
390 .owner
= THIS_MODULE
,
391 .enable_reg
= LP8788_EN_LDO_B
,
392 .enable_mask
= LP8788_EN_ALDO4_M
,
398 .ops
= &lp8788_ldo_voltage_fixed_ops
,
400 .type
= REGULATOR_VOLTAGE
,
401 .owner
= THIS_MODULE
,
402 .enable_reg
= LP8788_EN_LDO_C
,
403 .enable_mask
= LP8788_EN_ALDO5_M
,
409 .ops
= &lp8788_ldo_voltage_table_ops
,
410 .n_voltages
= ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl
),
411 .volt_table
= lp8788_dldo578_aldo6_vtbl
,
412 .type
= REGULATOR_VOLTAGE
,
413 .owner
= THIS_MODULE
,
414 .vsel_reg
= LP8788_ALDO6_VOUT
,
415 .vsel_mask
= LP8788_VOUT_4BIT_M
,
416 .enable_reg
= LP8788_EN_LDO_C
,
417 .enable_mask
= LP8788_EN_ALDO6_M
,
422 .ops
= &lp8788_ldo_voltage_table_ops
,
423 .n_voltages
= ARRAY_SIZE(lp8788_aldo7_vtbl
),
424 .volt_table
= lp8788_aldo7_vtbl
,
425 .type
= REGULATOR_VOLTAGE
,
426 .owner
= THIS_MODULE
,
427 .vsel_reg
= LP8788_ALDO7_VOUT
,
428 .vsel_mask
= LP8788_VOUT_3BIT_M
,
429 .enable_reg
= LP8788_EN_LDO_C
,
430 .enable_mask
= LP8788_EN_ALDO7_M
,
435 .ops
= &lp8788_ldo_voltage_fixed_ops
,
437 .type
= REGULATOR_VOLTAGE
,
438 .owner
= THIS_MODULE
,
439 .enable_reg
= LP8788_EN_LDO_C
,
440 .enable_mask
= LP8788_EN_ALDO8_M
,
446 .ops
= &lp8788_ldo_voltage_fixed_ops
,
448 .type
= REGULATOR_VOLTAGE
,
449 .owner
= THIS_MODULE
,
450 .enable_reg
= LP8788_EN_LDO_C
,
451 .enable_mask
= LP8788_EN_ALDO9_M
,
457 .ops
= &lp8788_ldo_voltage_fixed_ops
,
459 .type
= REGULATOR_VOLTAGE
,
460 .owner
= THIS_MODULE
,
461 .enable_reg
= LP8788_EN_LDO_C
,
462 .enable_mask
= LP8788_EN_ALDO10_M
,
467 static int lp8788_config_ldo_enable_mode(struct platform_device
*pdev
,
468 struct lp8788_ldo
*ldo
,
469 enum lp8788_ldo_id id
)
471 struct lp8788
*lp
= ldo
->lp
;
472 struct lp8788_platform_data
*pdata
= lp
->pdata
;
473 enum lp8788_ext_ldo_en_id enable_id
;
475 [EN_ALDO1
] = LP8788_EN_SEL_ALDO1_M
,
476 [EN_ALDO234
] = LP8788_EN_SEL_ALDO234_M
,
477 [EN_ALDO5
] = LP8788_EN_SEL_ALDO5_M
,
478 [EN_ALDO7
] = LP8788_EN_SEL_ALDO7_M
,
479 [EN_DLDO7
] = LP8788_EN_SEL_DLDO7_M
,
480 [EN_DLDO911
] = LP8788_EN_SEL_DLDO911_M
,
485 enable_id
= EN_DLDO7
;
489 enable_id
= EN_DLDO911
;
492 enable_id
= EN_ALDO1
;
494 case ALDO2
... ALDO4
:
495 enable_id
= EN_ALDO234
;
498 enable_id
= EN_ALDO5
;
501 enable_id
= EN_ALDO7
;
507 /* if no platform data for ldo pin, then set default enable mode */
508 if (!pdata
|| !pdata
->ldo_pin
|| !pdata
->ldo_pin
[enable_id
])
509 goto set_default_ldo_enable_mode
;
511 ldo
->en_pin
= pdata
->ldo_pin
[enable_id
];
514 set_default_ldo_enable_mode
:
515 return lp8788_update_bits(lp
, LP8788_EN_SEL
, en_mask
[enable_id
], 0);
518 static int lp8788_dldo_probe(struct platform_device
*pdev
)
520 struct lp8788
*lp
= dev_get_drvdata(pdev
->dev
.parent
);
522 struct lp8788_ldo
*ldo
;
523 struct regulator_config cfg
= { };
524 struct regulator_dev
*rdev
;
527 ldo
= devm_kzalloc(&pdev
->dev
, sizeof(struct lp8788_ldo
), GFP_KERNEL
);
532 ret
= lp8788_config_ldo_enable_mode(pdev
, ldo
, id
);
537 cfg
.ena_gpio
= ldo
->en_pin
->gpio
;
538 cfg
.ena_gpio_flags
= ldo
->en_pin
->init_state
;
541 cfg
.dev
= pdev
->dev
.parent
;
542 cfg
.init_data
= lp
->pdata
? lp
->pdata
->dldo_data
[id
] : NULL
;
543 cfg
.driver_data
= ldo
;
544 cfg
.regmap
= lp
->regmap
;
546 rdev
= devm_regulator_register(&pdev
->dev
, &lp8788_dldo_desc
[id
], &cfg
);
549 dev_err(&pdev
->dev
, "DLDO%d regulator register err = %d\n",
554 ldo
->regulator
= rdev
;
555 platform_set_drvdata(pdev
, ldo
);
560 static struct platform_driver lp8788_dldo_driver
= {
561 .probe
= lp8788_dldo_probe
,
563 .name
= LP8788_DEV_DLDO
,
567 static int lp8788_aldo_probe(struct platform_device
*pdev
)
569 struct lp8788
*lp
= dev_get_drvdata(pdev
->dev
.parent
);
571 struct lp8788_ldo
*ldo
;
572 struct regulator_config cfg
= { };
573 struct regulator_dev
*rdev
;
576 ldo
= devm_kzalloc(&pdev
->dev
, sizeof(struct lp8788_ldo
), GFP_KERNEL
);
581 ret
= lp8788_config_ldo_enable_mode(pdev
, ldo
, id
+ ALDO1
);
586 cfg
.ena_gpio
= ldo
->en_pin
->gpio
;
587 cfg
.ena_gpio_flags
= ldo
->en_pin
->init_state
;
590 cfg
.dev
= pdev
->dev
.parent
;
591 cfg
.init_data
= lp
->pdata
? lp
->pdata
->aldo_data
[id
] : NULL
;
592 cfg
.driver_data
= ldo
;
593 cfg
.regmap
= lp
->regmap
;
595 rdev
= devm_regulator_register(&pdev
->dev
, &lp8788_aldo_desc
[id
], &cfg
);
598 dev_err(&pdev
->dev
, "ALDO%d regulator register err = %d\n",
603 ldo
->regulator
= rdev
;
604 platform_set_drvdata(pdev
, ldo
);
609 static struct platform_driver lp8788_aldo_driver
= {
610 .probe
= lp8788_aldo_probe
,
612 .name
= LP8788_DEV_ALDO
,
616 static int __init
lp8788_ldo_init(void)
620 ret
= platform_driver_register(&lp8788_dldo_driver
);
624 return platform_driver_register(&lp8788_aldo_driver
);
626 subsys_initcall(lp8788_ldo_init
);
628 static void __exit
lp8788_ldo_exit(void)
630 platform_driver_unregister(&lp8788_aldo_driver
);
631 platform_driver_unregister(&lp8788_dldo_driver
);
633 module_exit(lp8788_ldo_exit
);
635 MODULE_DESCRIPTION("TI LP8788 LDO Driver");
636 MODULE_AUTHOR("Milo Kim");
637 MODULE_LICENSE("GPL");
638 MODULE_ALIAS("platform:lp8788-dldo");
639 MODULE_ALIAS("platform:lp8788-aldo");