25 #include <linux/kernel.h>
30 #include <linux/slab.h>
38 #define MAX77686_LDO_MINUV 800000
39 #define MAX77686_LDO_UVSTEP 50000
40 #define MAX77686_LDO_LOW_MINUV 800000
41 #define MAX77686_LDO_LOW_UVSTEP 25000
42 #define MAX77686_BUCK_MINUV 750000
43 #define MAX77686_BUCK_UVSTEP 50000
44 #define MAX77686_RAMP_DELAY 100000
45 #define MAX77686_DVS_RAMP_DELAY 27500
46 #define MAX77686_DVS_MINUV 600000
47 #define MAX77686_DVS_UVSTEP 12500
49 #define MAX77686_OPMODE_SHIFT 6
50 #define MAX77686_OPMODE_BUCK234_SHIFT 4
51 #define MAX77686_OPMODE_MASK 0x3
53 #define MAX77686_VSEL_MASK 0x3F
54 #define MAX77686_DVS_VSEL_MASK 0xFF
56 #define MAX77686_RAMP_RATE_MASK 0xC0
58 #define MAX77686_REGULATORS MAX77686_REG_MAX
59 #define MAX77686_LDOS 26
86 case 55001 ... 100000:
89 pr_warn(
"%s: ramp_delay: %d not supported, setting 100000\n",
90 rdev->
desc->name, ramp_delay);
117 .set_ramp_delay = max77686_set_ramp_delay,
120 #define regulator_desc_ldo(num) { \
122 .id = MAX77686_LDO##num, \
123 .ops = &max77686_ops, \
124 .type = REGULATOR_VOLTAGE, \
125 .owner = THIS_MODULE, \
126 .min_uV = MAX77686_LDO_MINUV, \
127 .uV_step = MAX77686_LDO_UVSTEP, \
128 .ramp_delay = MAX77686_RAMP_DELAY, \
129 .n_voltages = MAX77686_VSEL_MASK + 1, \
130 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
131 .vsel_mask = MAX77686_VSEL_MASK, \
132 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
133 .enable_mask = MAX77686_OPMODE_MASK \
134 << MAX77686_OPMODE_SHIFT, \
136 #define regulator_desc_ldo_low(num) { \
138 .id = MAX77686_LDO##num, \
139 .ops = &max77686_ops, \
140 .type = REGULATOR_VOLTAGE, \
141 .owner = THIS_MODULE, \
142 .min_uV = MAX77686_LDO_LOW_MINUV, \
143 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
144 .ramp_delay = MAX77686_RAMP_DELAY, \
145 .n_voltages = MAX77686_VSEL_MASK + 1, \
146 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
147 .vsel_mask = MAX77686_VSEL_MASK, \
148 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
149 .enable_mask = MAX77686_OPMODE_MASK \
150 << MAX77686_OPMODE_SHIFT, \
152 #define regulator_desc_buck(num) { \
153 .name = "BUCK"#num, \
154 .id = MAX77686_BUCK##num, \
155 .ops = &max77686_ops, \
156 .type = REGULATOR_VOLTAGE, \
157 .owner = THIS_MODULE, \
158 .min_uV = MAX77686_BUCK_MINUV, \
159 .uV_step = MAX77686_BUCK_UVSTEP, \
160 .ramp_delay = MAX77686_RAMP_DELAY, \
161 .n_voltages = MAX77686_VSEL_MASK + 1, \
162 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
163 .vsel_mask = MAX77686_VSEL_MASK, \
164 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
165 .enable_mask = MAX77686_OPMODE_MASK, \
167 #define regulator_desc_buck1(num) { \
168 .name = "BUCK"#num, \
169 .id = MAX77686_BUCK##num, \
170 .ops = &max77686_ops, \
171 .type = REGULATOR_VOLTAGE, \
172 .owner = THIS_MODULE, \
173 .min_uV = MAX77686_BUCK_MINUV, \
174 .uV_step = MAX77686_BUCK_UVSTEP, \
175 .ramp_delay = MAX77686_RAMP_DELAY, \
176 .n_voltages = MAX77686_VSEL_MASK + 1, \
177 .vsel_reg = MAX77686_REG_BUCK1OUT, \
178 .vsel_mask = MAX77686_VSEL_MASK, \
179 .enable_reg = MAX77686_REG_BUCK1CTRL, \
180 .enable_mask = MAX77686_OPMODE_MASK, \
182 #define regulator_desc_buck_dvs(num) { \
183 .name = "BUCK"#num, \
184 .id = MAX77686_BUCK##num, \
185 .ops = &max77686_buck_dvs_ops, \
186 .type = REGULATOR_VOLTAGE, \
187 .owner = THIS_MODULE, \
188 .min_uV = MAX77686_DVS_MINUV, \
189 .uV_step = MAX77686_DVS_UVSTEP, \
190 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
191 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
192 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
193 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
194 .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
195 .enable_mask = MAX77686_OPMODE_MASK \
196 << MAX77686_OPMODE_BUCK234_SHIFT, \
238 static int max77686_pmic_dt_parse_pdata(
struct max77686_dev *iodev,
246 pmic_np = iodev->
dev->of_node;
248 if (!regulators_np) {
249 dev_err(iodev->
dev,
"could not find regulators sub-node\n");
258 "could not allocate memory for regulator data\n");
263 rmatch.name = regulators[
i].
name;
264 rmatch.init_data =
NULL;
265 rmatch.of_node =
NULL;
276 static int max77686_pmic_dt_parse_pdata(
struct max77686_dev *iodev,
294 dev_err(&pdev->
dev,
"no platform data found for regulator\n");
298 if (iodev->
dev->of_node) {
299 ret = max77686_pmic_dt_parse_pdata(iodev, pdata);
306 "Invalid initial data for regulator's initialiation\n");
317 platform_set_drvdata(pdev, max77686);
324 if (IS_ERR(max77686->
rdev[i])) {
325 ret = PTR_ERR(max77686->
rdev[i]);
327 "regulator init failed for %d\n", i);
352 {
"max77686-pmic", 0},
359 .name =
"max77686-pmic",
362 .probe = max77686_pmic_probe,
364 .id_table = max77686_pmic_id,
367 static int __init max77686_pmic_init(
void)
373 static void __exit max77686_pmic_cleanup(
void)