Commit | Line | Data |
---|---|---|
133d4016 JL |
1 | /* |
2 | * max77686.c - Regulator driver for the Maxim 77686 | |
3 | * | |
4 | * Copyright (C) 2012 Samsung Electronics | |
5 | * Chiwoong Byun <woong.byun@smasung.com> | |
6 | * Jonghwa Lee <jonghwa3.lee@samsung.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | * This driver is based on max8997.c | |
23 | */ | |
24 | ||
25 | #include <linux/kernel.h> | |
26 | #include <linux/bug.h> | |
133d4016 JL |
27 | #include <linux/err.h> |
28 | #include <linux/gpio.h> | |
29 | #include <linux/slab.h> | |
30 | #include <linux/platform_device.h> | |
31 | #include <linux/regulator/driver.h> | |
32 | #include <linux/regulator/machine.h> | |
4706fcab | 33 | #include <linux/regulator/of_regulator.h> |
133d4016 JL |
34 | #include <linux/mfd/max77686.h> |
35 | #include <linux/mfd/max77686-private.h> | |
36 | ||
37 | #define MAX77686_LDO_MINUV 800000 | |
38 | #define MAX77686_LDO_UVSTEP 50000 | |
39 | #define MAX77686_LDO_LOW_MINUV 800000 | |
40 | #define MAX77686_LDO_LOW_UVSTEP 25000 | |
41 | #define MAX77686_BUCK_MINUV 750000 | |
42 | #define MAX77686_BUCK_UVSTEP 50000 | |
852abad2 YSB |
43 | #define MAX77686_RAMP_DELAY 100000 /* uV/us */ |
44 | #define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */ | |
133d4016 JL |
45 | #define MAX77686_DVS_MINUV 600000 |
46 | #define MAX77686_DVS_UVSTEP 12500 | |
47 | ||
7636f19c KK |
48 | /* |
49 | * Values used for configuring LDOs and bucks. | |
50 | * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26 | |
51 | */ | |
52 | #define MAX77686_LDO_LOWPOWER 0x1 | |
53 | /* | |
54 | * On/off controlled by PWRREQ: | |
55 | * - LDO2, 6-8, 10-12, 14-16 | |
56 | * - buck[1234] | |
57 | */ | |
58 | #define MAX77686_OFF_PWRREQ 0x1 | |
59 | /* Low power mode controlled by PWRREQ: All LDOs */ | |
60 | #define MAX77686_LDO_LOWPOWER_PWRREQ 0x2 | |
61 | /* Forcing low power mode: buck[234] */ | |
62 | #define MAX77686_BUCK_LOWPOWER 0x2 | |
63 | #define MAX77686_NORMAL 0x3 | |
64 | ||
133d4016 JL |
65 | #define MAX77686_OPMODE_SHIFT 6 |
66 | #define MAX77686_OPMODE_BUCK234_SHIFT 4 | |
67 | #define MAX77686_OPMODE_MASK 0x3 | |
68 | ||
69 | #define MAX77686_VSEL_MASK 0x3F | |
70 | #define MAX77686_DVS_VSEL_MASK 0xFF | |
71 | ||
72 | #define MAX77686_RAMP_RATE_MASK 0xC0 | |
73 | ||
74 | #define MAX77686_REGULATORS MAX77686_REG_MAX | |
75 | #define MAX77686_LDOS 26 | |
76 | ||
77 | enum max77686_ramp_rate { | |
78 | RAMP_RATE_13P75MV, | |
79 | RAMP_RATE_27P5MV, | |
80 | RAMP_RATE_55MV, | |
81 | RAMP_RATE_NO_CTRL, /* 100mV/us */ | |
82 | }; | |
83 | ||
84 | struct max77686_data { | |
eca29da9 | 85 | /* Array indexed by regulator id */ |
6d2c896b | 86 | unsigned int opmode[MAX77686_REGULATORS]; |
133d4016 JL |
87 | }; |
88 | ||
68c5d186 KK |
89 | static unsigned int max77686_get_opmode_shift(int id) |
90 | { | |
91 | switch (id) { | |
92 | case MAX77686_BUCK1: | |
93 | case MAX77686_BUCK5 ... MAX77686_BUCK9: | |
94 | return 0; | |
95 | case MAX77686_BUCK2 ... MAX77686_BUCK4: | |
96 | return MAX77686_OPMODE_BUCK234_SHIFT; | |
97 | default: | |
98 | /* all LDOs */ | |
99 | return MAX77686_OPMODE_SHIFT; | |
100 | } | |
101 | } | |
102 | ||
78ce6128 KK |
103 | /* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */ |
104 | static int max77686_set_suspend_disable(struct regulator_dev *rdev) | |
15282ba9 | 105 | { |
68c5d186 | 106 | unsigned int val, shift; |
15282ba9 | 107 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
3ecf198e | 108 | int ret, id = rdev_get_id(rdev); |
15282ba9 | 109 | |
68c5d186 KK |
110 | shift = max77686_get_opmode_shift(id); |
111 | val = MAX77686_OFF_PWRREQ; | |
15282ba9 | 112 | |
3ecf198e | 113 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
68c5d186 | 114 | rdev->desc->enable_mask, val << shift); |
3ecf198e AL |
115 | if (ret) |
116 | return ret; | |
117 | ||
40e72149 | 118 | max77686->opmode[id] = val; |
3ecf198e | 119 | return 0; |
15282ba9 YSB |
120 | } |
121 | ||
122 | /* Some LDOs supports [LPM/Normal]ON mode during suspend state */ | |
123 | static int max77686_set_suspend_mode(struct regulator_dev *rdev, | |
124 | unsigned int mode) | |
125 | { | |
126 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); | |
127 | unsigned int val; | |
3ecf198e | 128 | int ret, id = rdev_get_id(rdev); |
15282ba9 YSB |
129 | |
130 | /* BUCK[5-9] doesn't support this feature */ | |
40e72149 | 131 | if (id >= MAX77686_BUCK5) |
15282ba9 YSB |
132 | return 0; |
133 | ||
134 | switch (mode) { | |
135 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ | |
68c5d186 | 136 | val = MAX77686_LDO_LOWPOWER_PWRREQ; |
15282ba9 YSB |
137 | break; |
138 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ | |
68c5d186 | 139 | val = MAX77686_NORMAL; |
15282ba9 YSB |
140 | break; |
141 | default: | |
142 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", | |
143 | rdev->desc->name, mode); | |
144 | return -EINVAL; | |
145 | } | |
146 | ||
3ecf198e | 147 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
68c5d186 KK |
148 | rdev->desc->enable_mask, |
149 | val << MAX77686_OPMODE_SHIFT); | |
3ecf198e AL |
150 | if (ret) |
151 | return ret; | |
152 | ||
40e72149 | 153 | max77686->opmode[id] = val; |
3ecf198e | 154 | return 0; |
15282ba9 YSB |
155 | } |
156 | ||
157 | /* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */ | |
158 | static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, | |
159 | unsigned int mode) | |
160 | { | |
161 | unsigned int val; | |
162 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); | |
3ecf198e | 163 | int ret; |
15282ba9 YSB |
164 | |
165 | switch (mode) { | |
166 | case REGULATOR_MODE_STANDBY: /* switch off */ | |
68c5d186 | 167 | val = MAX77686_OFF_PWRREQ; |
15282ba9 YSB |
168 | break; |
169 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ | |
68c5d186 | 170 | val = MAX77686_LDO_LOWPOWER_PWRREQ; |
15282ba9 YSB |
171 | break; |
172 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ | |
68c5d186 | 173 | val = MAX77686_NORMAL; |
15282ba9 YSB |
174 | break; |
175 | default: | |
176 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", | |
177 | rdev->desc->name, mode); | |
178 | return -EINVAL; | |
179 | } | |
180 | ||
3ecf198e | 181 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
68c5d186 KK |
182 | rdev->desc->enable_mask, |
183 | val << MAX77686_OPMODE_SHIFT); | |
3ecf198e AL |
184 | if (ret) |
185 | return ret; | |
186 | ||
40e72149 | 187 | max77686->opmode[rdev_get_id(rdev)] = val; |
3ecf198e | 188 | return 0; |
15282ba9 YSB |
189 | } |
190 | ||
38d34035 | 191 | static int max77686_enable(struct regulator_dev *rdev) |
6d2c896b YSB |
192 | { |
193 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); | |
68c5d186 KK |
194 | unsigned int shift; |
195 | int id = rdev_get_id(rdev); | |
196 | ||
197 | shift = max77686_get_opmode_shift(id); | |
6d2c896b | 198 | |
78ce6128 KK |
199 | if (max77686->opmode[id] == MAX77686_OFF_PWRREQ) |
200 | max77686->opmode[id] = MAX77686_NORMAL; | |
201 | ||
6d2c896b YSB |
202 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
203 | rdev->desc->enable_mask, | |
68c5d186 | 204 | max77686->opmode[id] << shift); |
6d2c896b YSB |
205 | } |
206 | ||
f503071b YSB |
207 | static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
208 | { | |
209 | unsigned int ramp_value = RAMP_RATE_NO_CTRL; | |
210 | ||
211 | switch (ramp_delay) { | |
212 | case 1 ... 13750: | |
213 | ramp_value = RAMP_RATE_13P75MV; | |
214 | break; | |
215 | case 13751 ... 27500: | |
216 | ramp_value = RAMP_RATE_27P5MV; | |
217 | break; | |
218 | case 27501 ... 55000: | |
219 | ramp_value = RAMP_RATE_55MV; | |
220 | break; | |
221 | case 55001 ... 100000: | |
222 | break; | |
223 | default: | |
224 | pr_warn("%s: ramp_delay: %d not supported, setting 100000\n", | |
225 | rdev->desc->name, ramp_delay); | |
226 | } | |
227 | ||
228 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | |
229 | MAX77686_RAMP_RATE_MASK, ramp_value << 6); | |
230 | } | |
231 | ||
133d4016 JL |
232 | static struct regulator_ops max77686_ops = { |
233 | .list_voltage = regulator_list_voltage_linear, | |
2e3f7f26 | 234 | .map_voltage = regulator_map_voltage_linear, |
133d4016 | 235 | .is_enabled = regulator_is_enabled_regmap, |
6d2c896b | 236 | .enable = max77686_enable, |
133d4016 JL |
237 | .disable = regulator_disable_regmap, |
238 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
239 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
852abad2 | 240 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
15282ba9 YSB |
241 | .set_suspend_mode = max77686_set_suspend_mode, |
242 | }; | |
243 | ||
244 | static struct regulator_ops max77686_ldo_ops = { | |
245 | .list_voltage = regulator_list_voltage_linear, | |
246 | .map_voltage = regulator_map_voltage_linear, | |
247 | .is_enabled = regulator_is_enabled_regmap, | |
248 | .enable = max77686_enable, | |
133d4016 JL |
249 | .disable = regulator_disable_regmap, |
250 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
251 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
852abad2 | 252 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
15282ba9 | 253 | .set_suspend_mode = max77686_ldo_set_suspend_mode, |
78ce6128 | 254 | .set_suspend_disable = max77686_set_suspend_disable, |
15282ba9 YSB |
255 | }; |
256 | ||
257 | static struct regulator_ops max77686_buck1_ops = { | |
258 | .list_voltage = regulator_list_voltage_linear, | |
259 | .map_voltage = regulator_map_voltage_linear, | |
260 | .is_enabled = regulator_is_enabled_regmap, | |
261 | .enable = max77686_enable, | |
262 | .disable = regulator_disable_regmap, | |
263 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
264 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
265 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
78ce6128 | 266 | .set_suspend_disable = max77686_set_suspend_disable, |
133d4016 JL |
267 | }; |
268 | ||
269 | static struct regulator_ops max77686_buck_dvs_ops = { | |
270 | .list_voltage = regulator_list_voltage_linear, | |
2e3f7f26 | 271 | .map_voltage = regulator_map_voltage_linear, |
133d4016 | 272 | .is_enabled = regulator_is_enabled_regmap, |
6d2c896b | 273 | .enable = max77686_enable, |
133d4016 JL |
274 | .disable = regulator_disable_regmap, |
275 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
276 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
852abad2 | 277 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
f503071b | 278 | .set_ramp_delay = max77686_set_ramp_delay, |
78ce6128 | 279 | .set_suspend_disable = max77686_set_suspend_disable, |
133d4016 JL |
280 | }; |
281 | ||
282 | #define regulator_desc_ldo(num) { \ | |
283 | .name = "LDO"#num, \ | |
284 | .id = MAX77686_LDO##num, \ | |
285 | .ops = &max77686_ops, \ | |
286 | .type = REGULATOR_VOLTAGE, \ | |
287 | .owner = THIS_MODULE, \ | |
288 | .min_uV = MAX77686_LDO_MINUV, \ | |
289 | .uV_step = MAX77686_LDO_UVSTEP, \ | |
852abad2 | 290 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
133d4016 JL |
291 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
292 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
293 | .vsel_mask = MAX77686_VSEL_MASK, \ | |
294 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
295 | .enable_mask = MAX77686_OPMODE_MASK \ | |
296 | << MAX77686_OPMODE_SHIFT, \ | |
297 | } | |
15282ba9 YSB |
298 | #define regulator_desc_lpm_ldo(num) { \ |
299 | .name = "LDO"#num, \ | |
300 | .id = MAX77686_LDO##num, \ | |
301 | .ops = &max77686_ldo_ops, \ | |
302 | .type = REGULATOR_VOLTAGE, \ | |
303 | .owner = THIS_MODULE, \ | |
304 | .min_uV = MAX77686_LDO_MINUV, \ | |
305 | .uV_step = MAX77686_LDO_UVSTEP, \ | |
306 | .ramp_delay = MAX77686_RAMP_DELAY, \ | |
307 | .n_voltages = MAX77686_VSEL_MASK + 1, \ | |
308 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
309 | .vsel_mask = MAX77686_VSEL_MASK, \ | |
310 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
311 | .enable_mask = MAX77686_OPMODE_MASK \ | |
312 | << MAX77686_OPMODE_SHIFT, \ | |
313 | } | |
133d4016 | 314 | #define regulator_desc_ldo_low(num) { \ |
15282ba9 YSB |
315 | .name = "LDO"#num, \ |
316 | .id = MAX77686_LDO##num, \ | |
317 | .ops = &max77686_ldo_ops, \ | |
318 | .type = REGULATOR_VOLTAGE, \ | |
319 | .owner = THIS_MODULE, \ | |
320 | .min_uV = MAX77686_LDO_LOW_MINUV, \ | |
321 | .uV_step = MAX77686_LDO_LOW_UVSTEP, \ | |
322 | .ramp_delay = MAX77686_RAMP_DELAY, \ | |
323 | .n_voltages = MAX77686_VSEL_MASK + 1, \ | |
324 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
325 | .vsel_mask = MAX77686_VSEL_MASK, \ | |
326 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
327 | .enable_mask = MAX77686_OPMODE_MASK \ | |
328 | << MAX77686_OPMODE_SHIFT, \ | |
329 | } | |
330 | #define regulator_desc_ldo1_low(num) { \ | |
133d4016 JL |
331 | .name = "LDO"#num, \ |
332 | .id = MAX77686_LDO##num, \ | |
333 | .ops = &max77686_ops, \ | |
334 | .type = REGULATOR_VOLTAGE, \ | |
335 | .owner = THIS_MODULE, \ | |
336 | .min_uV = MAX77686_LDO_LOW_MINUV, \ | |
337 | .uV_step = MAX77686_LDO_LOW_UVSTEP, \ | |
852abad2 | 338 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
133d4016 JL |
339 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
340 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
341 | .vsel_mask = MAX77686_VSEL_MASK, \ | |
342 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | |
343 | .enable_mask = MAX77686_OPMODE_MASK \ | |
344 | << MAX77686_OPMODE_SHIFT, \ | |
345 | } | |
346 | #define regulator_desc_buck(num) { \ | |
347 | .name = "BUCK"#num, \ | |
348 | .id = MAX77686_BUCK##num, \ | |
349 | .ops = &max77686_ops, \ | |
350 | .type = REGULATOR_VOLTAGE, \ | |
351 | .owner = THIS_MODULE, \ | |
352 | .min_uV = MAX77686_BUCK_MINUV, \ | |
353 | .uV_step = MAX77686_BUCK_UVSTEP, \ | |
852abad2 | 354 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
133d4016 JL |
355 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
356 | .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \ | |
357 | .vsel_mask = MAX77686_VSEL_MASK, \ | |
358 | .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \ | |
359 | .enable_mask = MAX77686_OPMODE_MASK, \ | |
360 | } | |
361 | #define regulator_desc_buck1(num) { \ | |
362 | .name = "BUCK"#num, \ | |
363 | .id = MAX77686_BUCK##num, \ | |
15282ba9 | 364 | .ops = &max77686_buck1_ops, \ |
133d4016 JL |
365 | .type = REGULATOR_VOLTAGE, \ |
366 | .owner = THIS_MODULE, \ | |
367 | .min_uV = MAX77686_BUCK_MINUV, \ | |
368 | .uV_step = MAX77686_BUCK_UVSTEP, \ | |
852abad2 | 369 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
133d4016 JL |
370 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
371 | .vsel_reg = MAX77686_REG_BUCK1OUT, \ | |
372 | .vsel_mask = MAX77686_VSEL_MASK, \ | |
373 | .enable_reg = MAX77686_REG_BUCK1CTRL, \ | |
374 | .enable_mask = MAX77686_OPMODE_MASK, \ | |
375 | } | |
376 | #define regulator_desc_buck_dvs(num) { \ | |
377 | .name = "BUCK"#num, \ | |
378 | .id = MAX77686_BUCK##num, \ | |
74adfee5 | 379 | .ops = &max77686_buck_dvs_ops, \ |
133d4016 JL |
380 | .type = REGULATOR_VOLTAGE, \ |
381 | .owner = THIS_MODULE, \ | |
382 | .min_uV = MAX77686_DVS_MINUV, \ | |
383 | .uV_step = MAX77686_DVS_UVSTEP, \ | |
852abad2 | 384 | .ramp_delay = MAX77686_DVS_RAMP_DELAY, \ |
133d4016 JL |
385 | .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \ |
386 | .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \ | |
387 | .vsel_mask = MAX77686_DVS_VSEL_MASK, \ | |
388 | .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \ | |
389 | .enable_mask = MAX77686_OPMODE_MASK \ | |
390 | << MAX77686_OPMODE_BUCK234_SHIFT, \ | |
391 | } | |
392 | ||
73dbdf8f | 393 | static const struct regulator_desc regulators[] = { |
15282ba9 | 394 | regulator_desc_ldo1_low(1), |
133d4016 JL |
395 | regulator_desc_ldo_low(2), |
396 | regulator_desc_ldo(3), | |
397 | regulator_desc_ldo(4), | |
398 | regulator_desc_ldo(5), | |
399 | regulator_desc_ldo_low(6), | |
400 | regulator_desc_ldo_low(7), | |
401 | regulator_desc_ldo_low(8), | |
402 | regulator_desc_ldo(9), | |
15282ba9 YSB |
403 | regulator_desc_lpm_ldo(10), |
404 | regulator_desc_lpm_ldo(11), | |
405 | regulator_desc_lpm_ldo(12), | |
133d4016 | 406 | regulator_desc_ldo(13), |
15282ba9 | 407 | regulator_desc_lpm_ldo(14), |
133d4016 | 408 | regulator_desc_ldo_low(15), |
15282ba9 | 409 | regulator_desc_lpm_ldo(16), |
133d4016 JL |
410 | regulator_desc_ldo(17), |
411 | regulator_desc_ldo(18), | |
412 | regulator_desc_ldo(19), | |
413 | regulator_desc_ldo(20), | |
414 | regulator_desc_ldo(21), | |
415 | regulator_desc_ldo(22), | |
416 | regulator_desc_ldo(23), | |
417 | regulator_desc_ldo(24), | |
418 | regulator_desc_ldo(25), | |
419 | regulator_desc_ldo(26), | |
420 | regulator_desc_buck1(1), | |
421 | regulator_desc_buck_dvs(2), | |
422 | regulator_desc_buck_dvs(3), | |
423 | regulator_desc_buck_dvs(4), | |
424 | regulator_desc_buck(5), | |
425 | regulator_desc_buck(6), | |
426 | regulator_desc_buck(7), | |
427 | regulator_desc_buck(8), | |
428 | regulator_desc_buck(9), | |
429 | }; | |
430 | ||
4706fcab | 431 | #ifdef CONFIG_OF |
b19f5758 | 432 | static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev, |
4706fcab YSB |
433 | struct max77686_platform_data *pdata) |
434 | { | |
b19f5758 | 435 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
4706fcab YSB |
436 | struct device_node *pmic_np, *regulators_np; |
437 | struct max77686_regulator_data *rdata; | |
438 | struct of_regulator_match rmatch; | |
439 | unsigned int i; | |
440 | ||
441 | pmic_np = iodev->dev->of_node; | |
398a6616 | 442 | regulators_np = of_get_child_by_name(pmic_np, "voltage-regulators"); |
4706fcab | 443 | if (!regulators_np) { |
b19f5758 | 444 | dev_err(&pdev->dev, "could not find regulators sub-node\n"); |
4706fcab YSB |
445 | return -EINVAL; |
446 | } | |
447 | ||
448 | pdata->num_regulators = ARRAY_SIZE(regulators); | |
b19f5758 | 449 | rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) * |
4706fcab YSB |
450 | pdata->num_regulators, GFP_KERNEL); |
451 | if (!rdata) { | |
da0ee72d | 452 | of_node_put(regulators_np); |
4706fcab YSB |
453 | return -ENOMEM; |
454 | } | |
455 | ||
456 | for (i = 0; i < pdata->num_regulators; i++) { | |
457 | rmatch.name = regulators[i].name; | |
458 | rmatch.init_data = NULL; | |
d1ef065d | 459 | rmatch.of_node = NULL; |
b19f5758 | 460 | of_regulator_match(&pdev->dev, regulators_np, &rmatch, 1); |
4706fcab | 461 | rdata[i].initdata = rmatch.init_data; |
2c58e266 | 462 | rdata[i].of_node = rmatch.of_node; |
4706fcab YSB |
463 | } |
464 | ||
465 | pdata->regulators = rdata; | |
da0ee72d | 466 | of_node_put(regulators_np); |
4706fcab YSB |
467 | |
468 | return 0; | |
469 | } | |
470 | #else | |
b19f5758 | 471 | static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev, |
4706fcab YSB |
472 | struct max77686_platform_data *pdata) |
473 | { | |
474 | return 0; | |
475 | } | |
476 | #endif /* CONFIG_OF */ | |
477 | ||
a5023574 | 478 | static int max77686_pmic_probe(struct platform_device *pdev) |
133d4016 JL |
479 | { |
480 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); | |
481 | struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); | |
133d4016 | 482 | struct max77686_data *max77686; |
cb44cdea | 483 | int i, ret = 0; |
c59d2a6b | 484 | struct regulator_config config = { }; |
133d4016 JL |
485 | |
486 | dev_dbg(&pdev->dev, "%s\n", __func__); | |
487 | ||
4706fcab YSB |
488 | if (!pdata) { |
489 | dev_err(&pdev->dev, "no platform data found for regulator\n"); | |
490 | return -ENODEV; | |
491 | } | |
492 | ||
493 | if (iodev->dev->of_node) { | |
b19f5758 | 494 | ret = max77686_pmic_dt_parse_pdata(pdev, pdata); |
4706fcab YSB |
495 | if (ret) |
496 | return ret; | |
497 | } | |
498 | ||
499 | if (pdata->num_regulators != MAX77686_REGULATORS) { | |
ab0d1cbe AL |
500 | dev_err(&pdev->dev, |
501 | "Invalid initial data for regulator's initialiation\n"); | |
502 | return -EINVAL; | |
503 | } | |
504 | ||
133d4016 JL |
505 | max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), |
506 | GFP_KERNEL); | |
507 | if (!max77686) | |
508 | return -ENOMEM; | |
509 | ||
f503071b YSB |
510 | config.dev = &pdev->dev; |
511 | config.regmap = iodev->regmap; | |
6d2c896b | 512 | config.driver_data = max77686; |
133d4016 JL |
513 | platform_set_drvdata(pdev, max77686); |
514 | ||
ab0d1cbe | 515 | for (i = 0; i < MAX77686_REGULATORS; i++) { |
b0c13e80 | 516 | struct regulator_dev *rdev; |
eca29da9 | 517 | int id = regulators[i].id; |
b0c13e80 | 518 | |
ab0d1cbe | 519 | config.init_data = pdata->regulators[i].initdata; |
2c58e266 | 520 | config.of_node = pdata->regulators[i].of_node; |
133d4016 | 521 | |
eca29da9 KK |
522 | max77686->opmode[id] = regulators[i].enable_mask >> |
523 | max77686_get_opmode_shift(id); | |
b0c13e80 | 524 | rdev = devm_regulator_register(&pdev->dev, |
44815b4a | 525 | ®ulators[i], &config); |
b0c13e80 | 526 | if (IS_ERR(rdev)) { |
f503071b | 527 | dev_err(&pdev->dev, |
133d4016 | 528 | "regulator init failed for %d\n", i); |
b0c13e80 | 529 | return PTR_ERR(rdev); |
133d4016 | 530 | } |
133d4016 | 531 | } |
ab0d1cbe | 532 | |
133d4016 JL |
533 | return 0; |
534 | } | |
535 | ||
536 | static const struct platform_device_id max77686_pmic_id[] = { | |
537 | {"max77686-pmic", 0}, | |
538 | { }, | |
539 | }; | |
540 | MODULE_DEVICE_TABLE(platform, max77686_pmic_id); | |
541 | ||
542 | static struct platform_driver max77686_pmic_driver = { | |
543 | .driver = { | |
544 | .name = "max77686-pmic", | |
545 | .owner = THIS_MODULE, | |
546 | }, | |
547 | .probe = max77686_pmic_probe, | |
133d4016 JL |
548 | .id_table = max77686_pmic_id, |
549 | }; | |
550 | ||
551 | static int __init max77686_pmic_init(void) | |
552 | { | |
553 | return platform_driver_register(&max77686_pmic_driver); | |
554 | } | |
555 | subsys_initcall(max77686_pmic_init); | |
556 | ||
557 | static void __exit max77686_pmic_cleanup(void) | |
558 | { | |
559 | platform_driver_unregister(&max77686_pmic_driver); | |
560 | } | |
561 | module_exit(max77686_pmic_cleanup); | |
562 | ||
563 | MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver"); | |
564 | MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); | |
565 | MODULE_LICENSE("GPL"); |