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