14 #include <linux/module.h>
15 #include <linux/slab.h>
23 #define LP8788_EN_BUCK 0x0C
24 #define LP8788_BUCK_DVS_SEL 0x1D
25 #define LP8788_BUCK1_VOUT0 0x1E
26 #define LP8788_BUCK1_VOUT1 0x1F
27 #define LP8788_BUCK1_VOUT2 0x20
28 #define LP8788_BUCK1_VOUT3 0x21
29 #define LP8788_BUCK2_VOUT0 0x22
30 #define LP8788_BUCK2_VOUT1 0x23
31 #define LP8788_BUCK2_VOUT2 0x24
32 #define LP8788_BUCK2_VOUT3 0x25
33 #define LP8788_BUCK3_VOUT 0x26
34 #define LP8788_BUCK4_VOUT 0x27
35 #define LP8788_BUCK1_TIMESTEP 0x28
36 #define LP8788_BUCK_PWM 0x2D
39 #define LP8788_EN_BUCK1_M BIT(0)
40 #define LP8788_EN_BUCK2_M BIT(1)
41 #define LP8788_EN_BUCK3_M BIT(2)
42 #define LP8788_EN_BUCK4_M BIT(3)
43 #define LP8788_BUCK1_DVS_SEL_M 0x04
44 #define LP8788_BUCK1_DVS_M 0x03
45 #define LP8788_BUCK1_DVS_S 0
46 #define LP8788_BUCK2_DVS_SEL_M 0x40
47 #define LP8788_BUCK2_DVS_M 0x30
48 #define LP8788_BUCK2_DVS_S 4
49 #define LP8788_BUCK1_DVS_I2C BIT(2)
50 #define LP8788_BUCK2_DVS_I2C BIT(6)
51 #define LP8788_BUCK1_DVS_PIN (0 << 2)
52 #define LP8788_BUCK2_DVS_PIN (0 << 6)
53 #define LP8788_VOUT_M 0x1F
54 #define LP8788_STARTUP_TIME_M 0xF8
55 #define LP8788_STARTUP_TIME_S 3
56 #define LP8788_FPWM_BUCK1_M BIT(0)
57 #define LP8788_FPWM_BUCK1_S 0
58 #define LP8788_FPWM_BUCK2_M BIT(1)
59 #define LP8788_FPWM_BUCK2_S 1
60 #define LP8788_FPWM_BUCK3_M BIT(2)
61 #define LP8788_FPWM_BUCK3_S 2
62 #define LP8788_FPWM_BUCK4_M BIT(3)
63 #define LP8788_FPWM_BUCK4_S 3
65 #define INVALID_ADDR 0xFF
66 #define LP8788_FORCE_PWM 1
67 #define LP8788_AUTO_PWM 0
70 #define ENABLE_TIME_USEC 32
72 #define BUCK_FPWM_MASK(x) (1 << (x))
73 #define BUCK_FPWM_SHIFT(x) (x)
99 static const int lp8788_buck_vtbl[] = {
100 500000, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
101 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
102 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000,
106 static const u8 buck1_vout_addr[] = {
111 static const u8 buck2_vout_addr[] = {
116 static void lp8788_buck1_set_dvs(
struct lp8788_buck *buck)
125 if (gpio_is_valid(dvs->
gpio))
129 static void lp8788_buck2_set_dvs(
struct lp8788_buck *buck)
158 if (gpio_is_valid(dvs->
gpio[0]))
161 if (gpio_is_valid(dvs->
gpio[1]))
169 lp8788_buck1_set_dvs(buck);
172 lp8788_buck2_set_dvs(buck);
200 static bool lp8788_is_valid_buck_addr(
u8 addr)
217 static u8 lp8788_select_buck_vout_addr(
struct lp8788_buck *buck,
238 addr = buck1_vout_addr[
idx];
261 addr = buck2_vout_addr[
idx];
280 lp8788_set_dvs(buck,
id);
282 addr = lp8788_select_buck_vout_addr(buck,
id);
283 if (!lp8788_is_valid_buck_addr(addr))
289 static int lp8788_buck12_get_voltage_sel(
struct regulator_dev *rdev)
296 addr = lp8788_select_buck_vout_addr(buck,
id);
297 if (!lp8788_is_valid_buck_addr(addr))
307 static int lp8788_buck_enable_time(
struct regulator_dev *rdev)
321 static int lp8788_buck_set_mode(
struct regulator_dev *rdev,
unsigned int mode)
342 static unsigned int lp8788_buck_get_mode(
struct regulator_dev *rdev)
359 .set_voltage_sel = lp8788_buck12_set_voltage_sel,
360 .get_voltage_sel = lp8788_buck12_get_voltage_sel,
364 .enable_time = lp8788_buck_enable_time,
365 .set_mode = lp8788_buck_set_mode,
366 .get_mode = lp8788_buck_get_mode,
376 .enable_time = lp8788_buck_enable_time,
377 .set_mode = lp8788_buck_set_mode,
378 .get_mode = lp8788_buck_get_mode,
385 .ops = &lp8788_buck12_ops,
387 .volt_table = lp8788_buck_vtbl,
396 .ops = &lp8788_buck12_ops,
398 .volt_table = lp8788_buck_vtbl,
407 .ops = &lp8788_buck34_ops,
409 .volt_table = lp8788_buck_vtbl,
420 .ops = &lp8788_buck34_ops,
422 .volt_table = lp8788_buck_vtbl,
436 if (!gpio_is_valid(gpio)) {
437 dev_err(dev,
"invalid gpio: %d\n", gpio);
444 static int lp8788_dvs_gpio_request(
struct lp8788_buck *buck,
448 char *b1_name =
"LP8788_B1_DVS";
449 char *b2_name[] = {
"LP8788_B2_DVS1",
"LP8788_B2_DVS2" };
455 ret = _gpio_request(buck, gpio, b1_name);
464 ret = _gpio_request(buck, gpio, b2_name[i]);
490 goto set_default_dvs_mode;
494 goto set_default_dvs_mode;
496 if (lp8788_dvs_gpio_request(buck,
id))
497 goto set_default_dvs_mode;
502 set_default_dvs_mode:
504 default_dvs_mode[
id]);
522 ret = lp8788_init_dvs(buck,
id);
534 dev_err(lp->
dev,
"BUCK%d regulator register err = %d\n",
540 platform_set_drvdata(pdev, buck);
547 struct lp8788_buck *buck = platform_get_drvdata(pdev);
549 platform_set_drvdata(pdev,
NULL);
556 .probe = lp8788_buck_probe,
564 static int __init lp8788_buck_init(
void)
570 static void __exit lp8788_buck_exit(
void)