17 #include <linux/i2c.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
22 #include <linux/slab.h>
35 #define LP3971_SYS_CONTROL1_REG 0x07
39 #define SYS_CONTROL1_INIT_VAL 0x40
40 #define SYS_CONTROL1_INIT_MASK 0xCF
42 #define LP3971_BUCK_VOL_ENABLE_REG 0x10
43 #define LP3971_BUCK_VOL_CHANGE_REG 0x20
50 #define BUCK_VOL_CHANGE_SHIFT(x) (((!!x) << 2) | (x & ~0x01))
51 #define BUCK_VOL_CHANGE_FLAG_GO 0x01
52 #define BUCK_VOL_CHANGE_FLAG_TARGET 0x02
53 #define BUCK_VOL_CHANGE_FLAG_MASK 0x03
55 #define LP3971_BUCK1_BASE 0x23
56 #define LP3971_BUCK2_BASE 0x29
57 #define LP3971_BUCK3_BASE 0x32
59 static const int buck_base_addr[] = {
65 #define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x])
66 #define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1)
68 static const unsigned int buck_voltage_map[] = {
69 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
70 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
71 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000,
75 #define BUCK_TARGET_VOL_MASK 0x3f
76 #define BUCK_TARGET_VOL_MIN_IDX 0x01
77 #define BUCK_TARGET_VOL_MAX_IDX 0x19
79 #define LP3971_BUCK_RAMP_REG(x) (buck_base_addr[x]+2)
81 #define LP3971_LDO_ENABLE_REG 0x12
82 #define LP3971_LDO_VOL_CONTR_BASE 0x39
91 #define LP3971_LDO_VOL_CONTR_REG(x) (LP3971_LDO_VOL_CONTR_BASE + (x >> 1))
98 #define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2)
99 #define LDO_VOL_CONTR_MASK 0x0f
101 static const unsigned int ldo45_voltage_map[] = {
102 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000,
103 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000,
106 static const unsigned int ldo123_voltage_map[] = {
107 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
108 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000,
111 #define LDO_VOL_MIN_IDX 0x00
112 #define LDO_VOL_MAX_IDX 0x0f
122 return (val & mask) != 0;
152 return dev->
desc->volt_table[
val];
155 static int lp3971_ldo_set_voltage_sel(
struct regulator_dev *dev,
168 .is_enabled = lp3971_ldo_is_enabled,
169 .enable = lp3971_ldo_enable,
170 .disable = lp3971_ldo_disable,
171 .get_voltage = lp3971_ldo_get_voltage,
172 .set_voltage_sel = lp3971_ldo_set_voltage_sel,
183 return (val & mask) != 0;
190 u16 mask = 1 << (buck * 2);
199 u16 mask = 1 << (buck * 2);
204 static int lp3971_dcdc_get_voltage(
struct regulator_dev *dev)
215 val = buck_voltage_map[
reg];
218 dev_warn(&dev->
dev,
"chip reported incorrect voltage value.\n");
224 static int lp3971_dcdc_set_voltage_sel(
struct regulator_dev *dev,
225 unsigned int selector)
249 .is_enabled = lp3971_dcdc_is_enabled,
250 .enable = lp3971_dcdc_enable,
251 .disable = lp3971_dcdc_disable,
252 .get_voltage = lp3971_dcdc_get_voltage,
253 .set_voltage_sel = lp3971_dcdc_set_voltage_sel,
260 .ops = &lp3971_ldo_ops,
262 .volt_table = ldo123_voltage_map,
269 .ops = &lp3971_ldo_ops,
271 .volt_table = ldo123_voltage_map,
278 .ops = &lp3971_ldo_ops,
280 .volt_table = ldo123_voltage_map,
287 .ops = &lp3971_ldo_ops,
289 .volt_table = ldo45_voltage_map,
296 .ops = &lp3971_ldo_ops,
298 .volt_table = ldo45_voltage_map,
305 .ops = &lp3971_dcdc_ops,
307 .volt_table = buck_voltage_map,
314 .ops = &lp3971_dcdc_ops,
316 .volt_table = buck_voltage_map,
323 .ops = &lp3971_dcdc_ops,
325 .volt_table = buck_voltage_map,
331 static int lp3971_i2c_read(
struct i2c_client *i2c,
char reg,
int count,
346 static int lp3971_i2c_write(
struct i2c_client *i2c,
char reg,
int count,
354 static u8 lp3971_reg_read(
struct lp3971 *lp3971,
u8 reg)
360 lp3971_i2c_read(lp3971->
i2c, reg, 1, &val);
362 dev_dbg(lp3971->
dev,
"reg read 0x%02x -> 0x%02x\n", (
int)reg,
370 static int lp3971_set_bits(
struct lp3971 *lp3971,
u8 reg,
u16 mask,
u16 val)
377 ret = lp3971_i2c_read(lp3971->
i2c, reg, 1, &tmp);
378 tmp = (tmp & ~mask) | val;
380 ret = lp3971_i2c_write(lp3971->
i2c, reg, 1, &tmp);
381 dev_dbg(lp3971->
dev,
"reg write 0x%02x -> 0x%02x\n", (
int)reg,
389 static int __devinit setup_regulators(
struct lp3971 *lp3971,
413 if (IS_ERR(lp3971->
rdev[i])) {
414 err = PTR_ERR(lp3971->
rdev[i]);
415 dev_err(lp3971->
dev,
"regulator init failed: %d\n",
435 struct lp3971 *lp3971;
441 dev_dbg(&i2c->
dev,
"No platform init data supplied\n");
445 lp3971 = kzalloc(
sizeof(
struct lp3971),
GFP_KERNEL);
459 dev_err(&i2c->
dev,
"failed to detect device\n");
463 ret = setup_regulators(lp3971, pdata);
467 i2c_set_clientdata(i2c, lp3971);
477 struct lp3971 *lp3971 = i2c_get_clientdata(i2c);
495 static struct i2c_driver lp3971_i2c_driver = {
500 .probe = lp3971_i2c_probe,
502 .id_table = lp3971_i2c_id,