14 #include <linux/i2c.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
19 #include <linux/slab.h>
30 #define LP3972_SCR_REG 0x07
31 #define LP3972_OVER1_REG 0x10
32 #define LP3972_OVSR1_REG 0x11
33 #define LP3972_OVER2_REG 0x12
34 #define LP3972_OVSR2_REG 0x13
35 #define LP3972_VCC1_REG 0x20
36 #define LP3972_ADTV1_REG 0x23
37 #define LP3972_ADTV2_REG 0x24
38 #define LP3972_AVRC_REG 0x25
39 #define LP3972_CDTC1_REG 0x26
40 #define LP3972_CDTC2_REG 0x27
41 #define LP3972_SDTV1_REG 0x29
42 #define LP3972_SDTV2_REG 0x2A
43 #define LP3972_MDTV1_REG 0x32
44 #define LP3972_MDTV2_REG 0x33
45 #define LP3972_L2VCR_REG 0x39
46 #define LP3972_L34VCR_REG 0x3A
47 #define LP3972_SCR1_REG 0x80
48 #define LP3972_SCR2_REG 0x81
49 #define LP3972_OEN3_REG 0x82
50 #define LP3972_OSR3_REG 0x83
51 #define LP3972_LOER4_REG 0x84
52 #define LP3972_B2TV_REG 0x85
53 #define LP3972_B3TV_REG 0x86
54 #define LP3972_B32RC_REG 0x87
55 #define LP3972_ISRA_REG 0x88
56 #define LP3972_BCCR_REG 0x89
57 #define LP3972_II1RR_REG 0x8E
58 #define LP3972_II2RR_REG 0x8F
60 #define LP3972_SYS_CONTROL1_REG LP3972_SCR1_REG
63 #define SYS_CONTROL1_INIT_VAL 0x02
64 #define SYS_CONTROL1_INIT_MASK 0x1F
66 #define LP3972_VOL_CHANGE_REG LP3972_VCC1_REG
67 #define LP3972_VOL_CHANGE_FLAG_GO 0x01
68 #define LP3972_VOL_CHANGE_FLAG_MASK 0x03
71 #define LP3972_OEN3_L1EN BIT(0)
72 #define LP3972_OVER2_LDO2_EN BIT(2)
73 #define LP3972_OVER2_LDO3_EN BIT(3)
74 #define LP3972_OVER2_LDO4_EN BIT(4)
75 #define LP3972_OVER1_S_EN BIT(2)
77 static const unsigned int ldo1_voltage_map[] = {
78 1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000,
79 1900000, 1925000, 1950000, 1975000, 2000000,
82 static const unsigned int ldo23_voltage_map[] = {
83 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
84 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000,
87 static const unsigned int ldo4_voltage_map[] = {
88 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000,
89 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000,
92 static const unsigned int ldo5_voltage_map[] = {
93 0, 0, 0, 0, 0, 850000, 875000, 900000,
94 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000,
95 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
96 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
99 static const unsigned int buck1_voltage_map[] = {
100 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000,
101 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000,
102 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
103 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
106 static const unsigned int buck23_voltage_map[] = {
107 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
108 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
109 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000,
113 static const int ldo_output_enable_mask[] = {
121 static const int ldo_output_enable_addr[] = {
129 static const int ldo_vol_ctl_addr[] = {
137 static const int buck_vol_enable_addr[] = {
143 static const int buck_base_addr[] = {
149 #define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x])
150 #define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x])
157 #define LP3972_LDO_VOL_CONTR_SHIFT(x) (((x) & 1) << 2)
158 #define LP3972_LDO_VOL_CONTR_REG(x) (ldo_vol_ctl_addr[x])
159 #define LP3972_LDO_VOL_CHANGE_SHIFT(x) ((x) ? 4 : 6)
161 #define LP3972_LDO_VOL_MASK(x) (((x) % 4) ? 0x0f : 0x1f)
162 #define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00)
163 #define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c)
165 #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x])
166 #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x])
167 #define LP3972_BUCK_VOL_MASK 0x1f
168 #define LP3972_BUCK_VOL_MIN_IDX(x) ((x) ? 0x01 : 0x00)
169 #define LP3972_BUCK_VOL_MAX_IDX(x) ((x) ? 0x19 : 0x1f)
200 lp3972_i2c_read(lp3972->
i2c, reg, 1, &val);
202 dev_dbg(lp3972->
dev,
"reg read 0x%02x -> 0x%02x\n", (
int)reg,
203 (
unsigned)val & 0xff);
217 ret = lp3972_i2c_read(lp3972->
i2c, reg, 1, &tmp);
218 tmp = (tmp & ~mask) | val;
220 ret = lp3972_i2c_write(lp3972->
i2c, reg, 1, &tmp);
221 dev_dbg(lp3972->
dev,
"reg write 0x%02x -> 0x%02x\n", (
int)reg,
222 (
unsigned)val & 0xff);
237 return !!(val &
mask);
270 return dev->
desc->volt_table[
val];
273 static int lp3972_ldo_set_voltage_sel(
struct regulator_dev *dev,
314 .is_enabled = lp3972_ldo_is_enabled,
315 .enable = lp3972_ldo_enable,
316 .disable = lp3972_ldo_disable,
317 .get_voltage = lp3972_ldo_get_voltage,
318 .set_voltage_sel = lp3972_ldo_set_voltage_sel,
325 u16 mask = 1 << (buck * 2);
329 return !!(val &
mask);
336 u16 mask = 1 << (buck * 2);
348 u16 mask = 1 << (buck * 2);
356 static int lp3972_dcdc_get_voltage(
struct regulator_dev *dev)
366 val = dev->
desc->volt_table[
reg];
369 dev_warn(&dev->
dev,
"chip reported incorrect voltage value."
376 static int lp3972_dcdc_set_voltage_sel(
struct regulator_dev *dev,
377 unsigned int selector)
402 .is_enabled = lp3972_dcdc_is_enabled,
403 .enable = lp3972_dcdc_enable,
404 .disable = lp3972_dcdc_disable,
405 .get_voltage = lp3972_dcdc_get_voltage,
406 .set_voltage_sel = lp3972_dcdc_set_voltage_sel,
413 .ops = &lp3972_ldo_ops,
415 .volt_table = ldo1_voltage_map,
422 .ops = &lp3972_ldo_ops,
424 .volt_table = ldo23_voltage_map,
431 .ops = &lp3972_ldo_ops,
433 .volt_table = ldo23_voltage_map,
440 .ops = &lp3972_ldo_ops,
442 .volt_table = ldo4_voltage_map,
449 .ops = &lp3972_ldo_ops,
451 .volt_table = ldo5_voltage_map,
458 .ops = &lp3972_dcdc_ops,
460 .volt_table = buck1_voltage_map,
467 .ops = &lp3972_dcdc_ops,
469 .volt_table = buck23_voltage_map,
476 .ops = &lp3972_dcdc_ops,
478 .volt_table = buck23_voltage_map,
484 static int __devinit setup_regulators(
struct lp3972 *lp3972,
508 if (IS_ERR(lp3972->
rdev[i])) {
509 err = PTR_ERR(lp3972->
rdev[i]);
510 dev_err(lp3972->
dev,
"regulator init failed: %d\n",
529 struct lp3972 *lp3972;
535 dev_dbg(&i2c->
dev,
"No platform init data supplied\n");
539 lp3972 = kzalloc(
sizeof(
struct lp3972),
GFP_KERNEL);
553 dev_err(&i2c->
dev,
"chip reported: val = 0x%x\n", val);
556 dev_err(&i2c->
dev,
"failed to detect device. ret = %d\n", ret);
560 ret = setup_regulators(lp3972, pdata);
564 i2c_set_clientdata(i2c, lp3972);
574 struct lp3972 *lp3972 = i2c_get_clientdata(i2c);
591 static struct i2c_driver lp3972_i2c_driver = {
596 .probe = lp3972_i2c_probe,
598 .id_table = lp3972_i2c_id,
601 static int __init lp3972_module_init(
void)
603 return i2c_add_driver(&lp3972_i2c_driver);
607 static void __exit lp3972_module_exit(
void)