khugepaged: ignore pmd tables with THP mapped with ptes
[linux/fpc-iii.git] / drivers / regulator / s2mps11.c
blob3242ffc0cb25afdfa8adad11fd40878b6153f1b6
1 /*
2 * s2mps11.c
4 * Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/bug.h>
20 #include <linux/err.h>
21 #include <linux/gpio.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <linux/of.h>
25 #include <linux/regmap.h>
26 #include <linux/platform_device.h>
27 #include <linux/regulator/driver.h>
28 #include <linux/regulator/machine.h>
29 #include <linux/regulator/of_regulator.h>
30 #include <linux/of_gpio.h>
31 #include <linux/mfd/samsung/core.h>
32 #include <linux/mfd/samsung/s2mps11.h>
33 #include <linux/mfd/samsung/s2mps13.h>
34 #include <linux/mfd/samsung/s2mps14.h>
35 #include <linux/mfd/samsung/s2mps15.h>
36 #include <linux/mfd/samsung/s2mpu02.h>
38 /* The highest number of possible regulators for supported devices. */
39 #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
40 struct s2mps11_info {
41 unsigned int rdev_num;
42 int ramp_delay2;
43 int ramp_delay34;
44 int ramp_delay5;
45 int ramp_delay16;
46 int ramp_delay7810;
47 int ramp_delay9;
49 enum sec_device_type dev_type;
52 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
53 * the suspend mode was enabled.
55 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
57 /* Array of size rdev_num with GPIO-s for external sleep control */
58 int *ext_control_gpio;
61 static int get_ramp_delay(int ramp_delay)
63 unsigned char cnt = 0;
65 ramp_delay /= 6250;
67 while (true) {
68 ramp_delay = ramp_delay >> 1;
69 if (ramp_delay == 0)
70 break;
71 cnt++;
74 if (cnt > 3)
75 cnt = 3;
77 return cnt;
80 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
81 unsigned int old_selector,
82 unsigned int new_selector)
84 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
85 unsigned int ramp_delay = 0;
86 int old_volt, new_volt;
88 switch (rdev_get_id(rdev)) {
89 case S2MPS11_BUCK2:
90 ramp_delay = s2mps11->ramp_delay2;
91 break;
92 case S2MPS11_BUCK3:
93 case S2MPS11_BUCK4:
94 ramp_delay = s2mps11->ramp_delay34;
95 break;
96 case S2MPS11_BUCK5:
97 ramp_delay = s2mps11->ramp_delay5;
98 break;
99 case S2MPS11_BUCK6:
100 case S2MPS11_BUCK1:
101 ramp_delay = s2mps11->ramp_delay16;
102 break;
103 case S2MPS11_BUCK7:
104 case S2MPS11_BUCK8:
105 case S2MPS11_BUCK10:
106 ramp_delay = s2mps11->ramp_delay7810;
107 break;
108 case S2MPS11_BUCK9:
109 ramp_delay = s2mps11->ramp_delay9;
112 if (ramp_delay == 0)
113 ramp_delay = rdev->desc->ramp_delay;
115 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
116 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
118 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
121 static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
123 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
124 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
125 unsigned int ramp_enable = 1, enable_shift = 0;
126 int ret;
128 switch (rdev_get_id(rdev)) {
129 case S2MPS11_BUCK1:
130 if (ramp_delay > s2mps11->ramp_delay16)
131 s2mps11->ramp_delay16 = ramp_delay;
132 else
133 ramp_delay = s2mps11->ramp_delay16;
135 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
136 break;
137 case S2MPS11_BUCK2:
138 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
139 if (!ramp_delay) {
140 ramp_enable = 0;
141 break;
144 s2mps11->ramp_delay2 = ramp_delay;
145 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
146 ramp_reg = S2MPS11_REG_RAMP;
147 break;
148 case S2MPS11_BUCK3:
149 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
150 if (!ramp_delay) {
151 ramp_enable = 0;
152 break;
155 if (ramp_delay > s2mps11->ramp_delay34)
156 s2mps11->ramp_delay34 = ramp_delay;
157 else
158 ramp_delay = s2mps11->ramp_delay34;
160 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
161 ramp_reg = S2MPS11_REG_RAMP;
162 break;
163 case S2MPS11_BUCK4:
164 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
165 if (!ramp_delay) {
166 ramp_enable = 0;
167 break;
170 if (ramp_delay > s2mps11->ramp_delay34)
171 s2mps11->ramp_delay34 = ramp_delay;
172 else
173 ramp_delay = s2mps11->ramp_delay34;
175 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
176 ramp_reg = S2MPS11_REG_RAMP;
177 break;
178 case S2MPS11_BUCK5:
179 s2mps11->ramp_delay5 = ramp_delay;
180 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
181 break;
182 case S2MPS11_BUCK6:
183 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
184 if (!ramp_delay) {
185 ramp_enable = 0;
186 break;
189 if (ramp_delay > s2mps11->ramp_delay16)
190 s2mps11->ramp_delay16 = ramp_delay;
191 else
192 ramp_delay = s2mps11->ramp_delay16;
194 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
195 break;
196 case S2MPS11_BUCK7:
197 case S2MPS11_BUCK8:
198 case S2MPS11_BUCK10:
199 if (ramp_delay > s2mps11->ramp_delay7810)
200 s2mps11->ramp_delay7810 = ramp_delay;
201 else
202 ramp_delay = s2mps11->ramp_delay7810;
204 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
205 break;
206 case S2MPS11_BUCK9:
207 s2mps11->ramp_delay9 = ramp_delay;
208 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
209 break;
210 default:
211 return 0;
214 if (!ramp_enable)
215 goto ramp_disable;
217 /* Ramp delay can be enabled/disabled only for buck[2346] */
218 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
219 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
220 rdev_get_id(rdev) == S2MPS11_BUCK6) {
221 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
222 1 << enable_shift, 1 << enable_shift);
223 if (ret) {
224 dev_err(&rdev->dev, "failed to enable ramp rate\n");
225 return ret;
229 ramp_val = get_ramp_delay(ramp_delay);
231 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
232 ramp_val << ramp_shift);
234 ramp_disable:
235 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
236 1 << enable_shift, 0);
239 static struct regulator_ops s2mps11_ldo_ops = {
240 .list_voltage = regulator_list_voltage_linear,
241 .map_voltage = regulator_map_voltage_linear,
242 .is_enabled = regulator_is_enabled_regmap,
243 .enable = regulator_enable_regmap,
244 .disable = regulator_disable_regmap,
245 .get_voltage_sel = regulator_get_voltage_sel_regmap,
246 .set_voltage_sel = regulator_set_voltage_sel_regmap,
247 .set_voltage_time_sel = regulator_set_voltage_time_sel,
250 static struct regulator_ops s2mps11_buck_ops = {
251 .list_voltage = regulator_list_voltage_linear,
252 .map_voltage = regulator_map_voltage_linear,
253 .is_enabled = regulator_is_enabled_regmap,
254 .enable = regulator_enable_regmap,
255 .disable = regulator_disable_regmap,
256 .get_voltage_sel = regulator_get_voltage_sel_regmap,
257 .set_voltage_sel = regulator_set_voltage_sel_regmap,
258 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
259 .set_ramp_delay = s2mps11_set_ramp_delay,
262 #define regulator_desc_s2mps11_ldo(num, step) { \
263 .name = "LDO"#num, \
264 .id = S2MPS11_LDO##num, \
265 .ops = &s2mps11_ldo_ops, \
266 .type = REGULATOR_VOLTAGE, \
267 .owner = THIS_MODULE, \
268 .min_uV = MIN_800_MV, \
269 .uV_step = step, \
270 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
271 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
272 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
273 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
274 .enable_mask = S2MPS11_ENABLE_MASK \
277 #define regulator_desc_s2mps11_buck1_4(num) { \
278 .name = "BUCK"#num, \
279 .id = S2MPS11_BUCK##num, \
280 .ops = &s2mps11_buck_ops, \
281 .type = REGULATOR_VOLTAGE, \
282 .owner = THIS_MODULE, \
283 .min_uV = MIN_600_MV, \
284 .uV_step = STEP_6_25_MV, \
285 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
286 .ramp_delay = S2MPS11_RAMP_DELAY, \
287 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
288 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
289 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
290 .enable_mask = S2MPS11_ENABLE_MASK \
293 #define regulator_desc_s2mps11_buck5 { \
294 .name = "BUCK5", \
295 .id = S2MPS11_BUCK5, \
296 .ops = &s2mps11_buck_ops, \
297 .type = REGULATOR_VOLTAGE, \
298 .owner = THIS_MODULE, \
299 .min_uV = MIN_600_MV, \
300 .uV_step = STEP_6_25_MV, \
301 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
302 .ramp_delay = S2MPS11_RAMP_DELAY, \
303 .vsel_reg = S2MPS11_REG_B5CTRL2, \
304 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
305 .enable_reg = S2MPS11_REG_B5CTRL1, \
306 .enable_mask = S2MPS11_ENABLE_MASK \
309 #define regulator_desc_s2mps11_buck6_10(num, min, step) { \
310 .name = "BUCK"#num, \
311 .id = S2MPS11_BUCK##num, \
312 .ops = &s2mps11_buck_ops, \
313 .type = REGULATOR_VOLTAGE, \
314 .owner = THIS_MODULE, \
315 .min_uV = min, \
316 .uV_step = step, \
317 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
318 .ramp_delay = S2MPS11_RAMP_DELAY, \
319 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
320 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
321 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
322 .enable_mask = S2MPS11_ENABLE_MASK \
325 static const struct regulator_desc s2mps11_regulators[] = {
326 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
327 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
328 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
329 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
330 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
331 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
332 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
333 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
334 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
335 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
336 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
337 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
338 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
339 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
340 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
341 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
342 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
343 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
344 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
345 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
346 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
348 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
349 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
350 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
353 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
361 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
362 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
363 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
364 regulator_desc_s2mps11_buck1_4(1),
365 regulator_desc_s2mps11_buck1_4(2),
366 regulator_desc_s2mps11_buck1_4(3),
367 regulator_desc_s2mps11_buck1_4(4),
368 regulator_desc_s2mps11_buck5,
369 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV, STEP_6_25_MV),
370 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV, STEP_6_25_MV),
371 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV, STEP_6_25_MV),
372 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV, STEP_25_MV),
373 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV),
376 static struct regulator_ops s2mps14_reg_ops;
378 #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
379 .name = "LDO"#num, \
380 .id = S2MPS13_LDO##num, \
381 .ops = &s2mps14_reg_ops, \
382 .type = REGULATOR_VOLTAGE, \
383 .owner = THIS_MODULE, \
384 .min_uV = min, \
385 .uV_step = step, \
386 .linear_min_sel = min_sel, \
387 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
388 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
389 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
390 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
391 .enable_mask = S2MPS14_ENABLE_MASK \
394 #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
395 .name = "BUCK"#num, \
396 .id = S2MPS13_BUCK##num, \
397 .ops = &s2mps14_reg_ops, \
398 .type = REGULATOR_VOLTAGE, \
399 .owner = THIS_MODULE, \
400 .min_uV = min, \
401 .uV_step = step, \
402 .linear_min_sel = min_sel, \
403 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
404 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
405 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
406 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
407 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
408 .enable_mask = S2MPS14_ENABLE_MASK \
411 #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
412 .name = "BUCK"#num, \
413 .id = S2MPS13_BUCK##num, \
414 .ops = &s2mps14_reg_ops, \
415 .type = REGULATOR_VOLTAGE, \
416 .owner = THIS_MODULE, \
417 .min_uV = min, \
418 .uV_step = step, \
419 .linear_min_sel = min_sel, \
420 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
421 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
422 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
423 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
424 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
425 .enable_mask = S2MPS14_ENABLE_MASK \
428 #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
429 .name = "BUCK"#num, \
430 .id = S2MPS13_BUCK##num, \
431 .ops = &s2mps14_reg_ops, \
432 .type = REGULATOR_VOLTAGE, \
433 .owner = THIS_MODULE, \
434 .min_uV = min, \
435 .uV_step = step, \
436 .linear_min_sel = min_sel, \
437 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
438 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
439 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
440 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
441 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
442 .enable_mask = S2MPS14_ENABLE_MASK \
445 static const struct regulator_desc s2mps13_regulators[] = {
446 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
447 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
448 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
449 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
450 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
451 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
452 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
453 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
454 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
455 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
456 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
457 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
458 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
459 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
460 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
461 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
462 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
463 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
464 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
465 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
466 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
467 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
468 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
469 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
470 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
471 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
472 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
473 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
474 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
475 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
476 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
477 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
478 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
479 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
480 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
481 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
482 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
483 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
484 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
485 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
486 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
487 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
488 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
489 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
490 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
491 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
492 regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
493 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
494 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
495 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
498 static int s2mps14_regulator_enable(struct regulator_dev *rdev)
500 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
501 unsigned int val;
503 switch (s2mps11->dev_type) {
504 case S2MPS13X:
505 case S2MPS14X:
506 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
507 val = S2MPS14_ENABLE_SUSPEND;
508 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
509 val = S2MPS14_ENABLE_EXT_CONTROL;
510 else
511 val = rdev->desc->enable_mask;
512 break;
513 case S2MPU02:
514 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
515 val = S2MPU02_ENABLE_SUSPEND;
516 else
517 val = rdev->desc->enable_mask;
518 break;
519 default:
520 return -EINVAL;
523 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
524 rdev->desc->enable_mask, val);
527 static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
529 int ret;
530 unsigned int val, state;
531 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
532 int rdev_id = rdev_get_id(rdev);
534 /* Below LDO should be always on or does not support suspend mode. */
535 switch (s2mps11->dev_type) {
536 case S2MPS13X:
537 case S2MPS14X:
538 switch (rdev_id) {
539 case S2MPS14_LDO3:
540 return 0;
541 default:
542 state = S2MPS14_ENABLE_SUSPEND;
543 break;
545 break;
546 case S2MPU02:
547 switch (rdev_id) {
548 case S2MPU02_LDO13:
549 case S2MPU02_LDO14:
550 case S2MPU02_LDO15:
551 case S2MPU02_LDO17:
552 case S2MPU02_BUCK7:
553 state = S2MPU02_DISABLE_SUSPEND;
554 break;
555 default:
556 state = S2MPU02_ENABLE_SUSPEND;
557 break;
559 break;
560 default:
561 return -EINVAL;
564 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
565 if (ret < 0)
566 return ret;
568 set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
570 * Don't enable suspend mode if regulator is already disabled because
571 * this would effectively for a short time turn on the regulator after
572 * resuming.
573 * However we still want to toggle the suspend_state bit for regulator
574 * in case if it got enabled before suspending the system.
576 if (!(val & rdev->desc->enable_mask))
577 return 0;
579 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
580 rdev->desc->enable_mask, state);
583 static struct regulator_ops s2mps14_reg_ops = {
584 .list_voltage = regulator_list_voltage_linear,
585 .map_voltage = regulator_map_voltage_linear,
586 .is_enabled = regulator_is_enabled_regmap,
587 .enable = s2mps14_regulator_enable,
588 .disable = regulator_disable_regmap,
589 .get_voltage_sel = regulator_get_voltage_sel_regmap,
590 .set_voltage_sel = regulator_set_voltage_sel_regmap,
591 .set_voltage_time_sel = regulator_set_voltage_time_sel,
592 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
595 #define regulator_desc_s2mps14_ldo(num, min, step) { \
596 .name = "LDO"#num, \
597 .id = S2MPS14_LDO##num, \
598 .ops = &s2mps14_reg_ops, \
599 .type = REGULATOR_VOLTAGE, \
600 .owner = THIS_MODULE, \
601 .min_uV = min, \
602 .uV_step = step, \
603 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
604 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
605 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
606 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
607 .enable_mask = S2MPS14_ENABLE_MASK \
610 #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
611 .name = "BUCK"#num, \
612 .id = S2MPS14_BUCK##num, \
613 .ops = &s2mps14_reg_ops, \
614 .type = REGULATOR_VOLTAGE, \
615 .owner = THIS_MODULE, \
616 .min_uV = min, \
617 .uV_step = step, \
618 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
619 .linear_min_sel = min_sel, \
620 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
621 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
622 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
623 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
624 .enable_mask = S2MPS14_ENABLE_MASK \
627 static const struct regulator_desc s2mps14_regulators[] = {
628 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
629 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
630 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
631 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
632 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
633 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
634 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
635 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
636 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
637 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
638 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
639 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
640 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
641 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
642 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
643 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
644 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
645 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
646 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
647 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
648 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
649 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
650 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
651 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
652 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
653 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
654 S2MPS14_BUCK1235_START_SEL),
655 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
656 S2MPS14_BUCK1235_START_SEL),
657 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
658 S2MPS14_BUCK1235_START_SEL),
659 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
660 S2MPS14_BUCK4_START_SEL),
661 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
662 S2MPS14_BUCK1235_START_SEL),
665 static struct regulator_ops s2mps15_reg_ldo_ops = {
666 .list_voltage = regulator_list_voltage_linear_range,
667 .map_voltage = regulator_map_voltage_linear_range,
668 .is_enabled = regulator_is_enabled_regmap,
669 .enable = regulator_enable_regmap,
670 .disable = regulator_disable_regmap,
671 .get_voltage_sel = regulator_get_voltage_sel_regmap,
672 .set_voltage_sel = regulator_set_voltage_sel_regmap,
675 static struct regulator_ops s2mps15_reg_buck_ops = {
676 .list_voltage = regulator_list_voltage_linear_range,
677 .map_voltage = regulator_map_voltage_linear_range,
678 .is_enabled = regulator_is_enabled_regmap,
679 .enable = regulator_enable_regmap,
680 .disable = regulator_disable_regmap,
681 .get_voltage_sel = regulator_get_voltage_sel_regmap,
682 .set_voltage_sel = regulator_set_voltage_sel_regmap,
683 .set_voltage_time_sel = regulator_set_voltage_time_sel,
686 #define regulator_desc_s2mps15_ldo(num, range) { \
687 .name = "LDO"#num, \
688 .id = S2MPS15_LDO##num, \
689 .ops = &s2mps15_reg_ldo_ops, \
690 .type = REGULATOR_VOLTAGE, \
691 .owner = THIS_MODULE, \
692 .linear_ranges = range, \
693 .n_linear_ranges = ARRAY_SIZE(range), \
694 .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
695 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
696 .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
697 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
698 .enable_mask = S2MPS15_ENABLE_MASK \
701 #define regulator_desc_s2mps15_buck(num, range) { \
702 .name = "BUCK"#num, \
703 .id = S2MPS15_BUCK##num, \
704 .ops = &s2mps15_reg_buck_ops, \
705 .type = REGULATOR_VOLTAGE, \
706 .owner = THIS_MODULE, \
707 .linear_ranges = range, \
708 .n_linear_ranges = ARRAY_SIZE(range), \
709 .ramp_delay = 12500, \
710 .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
711 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
712 .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
713 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
714 .enable_mask = S2MPS15_ENABLE_MASK \
717 /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
718 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
719 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
722 /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
723 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
724 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
727 /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
728 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
729 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
732 /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
733 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
734 REGULATOR_LINEAR_RANGE(700000, 0xc, 0x18, 25000),
737 /* voltage range for s2mps15 LDO 1 */
738 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
739 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
742 /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
743 static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
744 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xb0, 6250),
747 /* voltage range for s2mps15 BUCK 8, 9 and 10 */
748 static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
749 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0xc0, 12500),
752 static const struct regulator_desc s2mps15_regulators[] = {
753 regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
754 regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
755 regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
756 regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
757 regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
758 regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
759 regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
760 regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
761 regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
762 regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
763 regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
764 regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
765 regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
766 regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
767 regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
768 regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
769 regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
770 regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
771 regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
772 regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
773 regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
774 regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
775 regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
776 regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
777 regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
778 regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
779 regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
780 regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
781 regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
782 regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
783 regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
784 regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
785 regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
786 regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
787 regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
788 regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
789 regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
792 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
793 struct regulator_dev *rdev)
795 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
796 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
799 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
800 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
802 int *gpio = s2mps11->ext_control_gpio;
803 unsigned int i;
804 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
805 S2MPS14_LDO12 };
807 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
808 unsigned int reg = valid_regulators[i];
810 if (!rdata[reg].init_data || !rdata[reg].of_node)
811 continue;
813 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
814 "samsung,ext-control-gpios", 0);
815 if (gpio_is_valid(gpio[reg]))
816 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
817 gpio[reg], reg, rdata[reg].name);
821 static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
822 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
824 struct device_node *reg_np;
826 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
827 if (!reg_np) {
828 dev_err(&pdev->dev, "could not find regulators sub-node\n");
829 return -EINVAL;
832 of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
833 if (s2mps11->dev_type == S2MPS14X)
834 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
836 of_node_put(reg_np);
838 return 0;
841 static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
843 unsigned int ramp_val, ramp_shift, ramp_reg;
845 switch (rdev_get_id(rdev)) {
846 case S2MPU02_BUCK1:
847 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
848 break;
849 case S2MPU02_BUCK2:
850 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
851 break;
852 case S2MPU02_BUCK3:
853 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
854 break;
855 case S2MPU02_BUCK4:
856 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
857 break;
858 default:
859 return 0;
861 ramp_reg = S2MPU02_REG_RAMP1;
862 ramp_val = get_ramp_delay(ramp_delay);
864 return regmap_update_bits(rdev->regmap, ramp_reg,
865 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
866 ramp_val << ramp_shift);
869 static struct regulator_ops s2mpu02_ldo_ops = {
870 .list_voltage = regulator_list_voltage_linear,
871 .map_voltage = regulator_map_voltage_linear,
872 .is_enabled = regulator_is_enabled_regmap,
873 .enable = s2mps14_regulator_enable,
874 .disable = regulator_disable_regmap,
875 .get_voltage_sel = regulator_get_voltage_sel_regmap,
876 .set_voltage_sel = regulator_set_voltage_sel_regmap,
877 .set_voltage_time_sel = regulator_set_voltage_time_sel,
878 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
881 static struct regulator_ops s2mpu02_buck_ops = {
882 .list_voltage = regulator_list_voltage_linear,
883 .map_voltage = regulator_map_voltage_linear,
884 .is_enabled = regulator_is_enabled_regmap,
885 .enable = s2mps14_regulator_enable,
886 .disable = regulator_disable_regmap,
887 .get_voltage_sel = regulator_get_voltage_sel_regmap,
888 .set_voltage_sel = regulator_set_voltage_sel_regmap,
889 .set_voltage_time_sel = regulator_set_voltage_time_sel,
890 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
891 .set_ramp_delay = s2mpu02_set_ramp_delay,
894 #define regulator_desc_s2mpu02_ldo1(num) { \
895 .name = "LDO"#num, \
896 .id = S2MPU02_LDO##num, \
897 .ops = &s2mpu02_ldo_ops, \
898 .type = REGULATOR_VOLTAGE, \
899 .owner = THIS_MODULE, \
900 .min_uV = S2MPU02_LDO_MIN_900MV, \
901 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
902 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
903 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
904 .vsel_reg = S2MPU02_REG_L1CTRL, \
905 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
906 .enable_reg = S2MPU02_REG_L1CTRL, \
907 .enable_mask = S2MPU02_ENABLE_MASK \
909 #define regulator_desc_s2mpu02_ldo2(num) { \
910 .name = "LDO"#num, \
911 .id = S2MPU02_LDO##num, \
912 .ops = &s2mpu02_ldo_ops, \
913 .type = REGULATOR_VOLTAGE, \
914 .owner = THIS_MODULE, \
915 .min_uV = S2MPU02_LDO_MIN_1050MV, \
916 .uV_step = S2MPU02_LDO_STEP_25MV, \
917 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
918 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
919 .vsel_reg = S2MPU02_REG_L2CTRL1, \
920 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
921 .enable_reg = S2MPU02_REG_L2CTRL1, \
922 .enable_mask = S2MPU02_ENABLE_MASK \
924 #define regulator_desc_s2mpu02_ldo3(num) { \
925 .name = "LDO"#num, \
926 .id = S2MPU02_LDO##num, \
927 .ops = &s2mpu02_ldo_ops, \
928 .type = REGULATOR_VOLTAGE, \
929 .owner = THIS_MODULE, \
930 .min_uV = S2MPU02_LDO_MIN_900MV, \
931 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
932 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
933 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
934 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
935 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
936 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
937 .enable_mask = S2MPU02_ENABLE_MASK \
939 #define regulator_desc_s2mpu02_ldo4(num) { \
940 .name = "LDO"#num, \
941 .id = S2MPU02_LDO##num, \
942 .ops = &s2mpu02_ldo_ops, \
943 .type = REGULATOR_VOLTAGE, \
944 .owner = THIS_MODULE, \
945 .min_uV = S2MPU02_LDO_MIN_1050MV, \
946 .uV_step = S2MPU02_LDO_STEP_25MV, \
947 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
948 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
949 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
950 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
951 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
952 .enable_mask = S2MPU02_ENABLE_MASK \
954 #define regulator_desc_s2mpu02_ldo5(num) { \
955 .name = "LDO"#num, \
956 .id = S2MPU02_LDO##num, \
957 .ops = &s2mpu02_ldo_ops, \
958 .type = REGULATOR_VOLTAGE, \
959 .owner = THIS_MODULE, \
960 .min_uV = S2MPU02_LDO_MIN_1600MV, \
961 .uV_step = S2MPU02_LDO_STEP_50MV, \
962 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
963 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
964 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
965 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
966 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
967 .enable_mask = S2MPU02_ENABLE_MASK \
970 #define regulator_desc_s2mpu02_buck1234(num) { \
971 .name = "BUCK"#num, \
972 .id = S2MPU02_BUCK##num, \
973 .ops = &s2mpu02_buck_ops, \
974 .type = REGULATOR_VOLTAGE, \
975 .owner = THIS_MODULE, \
976 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
977 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
978 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
979 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
980 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
981 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
982 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
983 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
984 .enable_mask = S2MPU02_ENABLE_MASK \
986 #define regulator_desc_s2mpu02_buck5(num) { \
987 .name = "BUCK"#num, \
988 .id = S2MPU02_BUCK##num, \
989 .ops = &s2mpu02_ldo_ops, \
990 .type = REGULATOR_VOLTAGE, \
991 .owner = THIS_MODULE, \
992 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
993 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
994 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
995 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
996 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
997 .vsel_reg = S2MPU02_REG_B5CTRL2, \
998 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
999 .enable_reg = S2MPU02_REG_B5CTRL1, \
1000 .enable_mask = S2MPU02_ENABLE_MASK \
1002 #define regulator_desc_s2mpu02_buck6(num) { \
1003 .name = "BUCK"#num, \
1004 .id = S2MPU02_BUCK##num, \
1005 .ops = &s2mpu02_ldo_ops, \
1006 .type = REGULATOR_VOLTAGE, \
1007 .owner = THIS_MODULE, \
1008 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
1009 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
1010 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1011 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
1012 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1013 .vsel_reg = S2MPU02_REG_B6CTRL2, \
1014 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1015 .enable_reg = S2MPU02_REG_B6CTRL1, \
1016 .enable_mask = S2MPU02_ENABLE_MASK \
1018 #define regulator_desc_s2mpu02_buck7(num) { \
1019 .name = "BUCK"#num, \
1020 .id = S2MPU02_BUCK##num, \
1021 .ops = &s2mpu02_ldo_ops, \
1022 .type = REGULATOR_VOLTAGE, \
1023 .owner = THIS_MODULE, \
1024 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
1025 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
1026 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1027 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
1028 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1029 .vsel_reg = S2MPU02_REG_B7CTRL2, \
1030 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1031 .enable_reg = S2MPU02_REG_B7CTRL1, \
1032 .enable_mask = S2MPU02_ENABLE_MASK \
1035 static const struct regulator_desc s2mpu02_regulators[] = {
1036 regulator_desc_s2mpu02_ldo1(1),
1037 regulator_desc_s2mpu02_ldo2(2),
1038 regulator_desc_s2mpu02_ldo4(3),
1039 regulator_desc_s2mpu02_ldo5(4),
1040 regulator_desc_s2mpu02_ldo4(5),
1041 regulator_desc_s2mpu02_ldo3(6),
1042 regulator_desc_s2mpu02_ldo3(7),
1043 regulator_desc_s2mpu02_ldo4(8),
1044 regulator_desc_s2mpu02_ldo5(9),
1045 regulator_desc_s2mpu02_ldo3(10),
1046 regulator_desc_s2mpu02_ldo4(11),
1047 regulator_desc_s2mpu02_ldo5(12),
1048 regulator_desc_s2mpu02_ldo5(13),
1049 regulator_desc_s2mpu02_ldo5(14),
1050 regulator_desc_s2mpu02_ldo5(15),
1051 regulator_desc_s2mpu02_ldo5(16),
1052 regulator_desc_s2mpu02_ldo4(17),
1053 regulator_desc_s2mpu02_ldo5(18),
1054 regulator_desc_s2mpu02_ldo3(19),
1055 regulator_desc_s2mpu02_ldo4(20),
1056 regulator_desc_s2mpu02_ldo5(21),
1057 regulator_desc_s2mpu02_ldo5(22),
1058 regulator_desc_s2mpu02_ldo5(23),
1059 regulator_desc_s2mpu02_ldo4(24),
1060 regulator_desc_s2mpu02_ldo5(25),
1061 regulator_desc_s2mpu02_ldo4(26),
1062 regulator_desc_s2mpu02_ldo5(27),
1063 regulator_desc_s2mpu02_ldo5(28),
1064 regulator_desc_s2mpu02_buck1234(1),
1065 regulator_desc_s2mpu02_buck1234(2),
1066 regulator_desc_s2mpu02_buck1234(3),
1067 regulator_desc_s2mpu02_buck1234(4),
1068 regulator_desc_s2mpu02_buck5(5),
1069 regulator_desc_s2mpu02_buck6(6),
1070 regulator_desc_s2mpu02_buck7(7),
1073 static int s2mps11_pmic_probe(struct platform_device *pdev)
1075 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
1076 struct sec_platform_data *pdata = NULL;
1077 struct of_regulator_match *rdata = NULL;
1078 struct regulator_config config = { };
1079 struct s2mps11_info *s2mps11;
1080 int i, ret = 0;
1081 const struct regulator_desc *regulators;
1083 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1084 GFP_KERNEL);
1085 if (!s2mps11)
1086 return -ENOMEM;
1088 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
1089 switch (s2mps11->dev_type) {
1090 case S2MPS11X:
1091 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
1092 regulators = s2mps11_regulators;
1093 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
1094 break;
1095 case S2MPS13X:
1096 s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
1097 regulators = s2mps13_regulators;
1098 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
1099 break;
1100 case S2MPS14X:
1101 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
1102 regulators = s2mps14_regulators;
1103 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
1104 break;
1105 case S2MPS15X:
1106 s2mps11->rdev_num = ARRAY_SIZE(s2mps15_regulators);
1107 regulators = s2mps15_regulators;
1108 break;
1109 case S2MPU02:
1110 s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
1111 regulators = s2mpu02_regulators;
1112 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
1113 break;
1114 default:
1115 dev_err(&pdev->dev, "Invalid device type: %u\n",
1116 s2mps11->dev_type);
1117 return -EINVAL;
1120 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
1121 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
1122 GFP_KERNEL);
1123 if (!s2mps11->ext_control_gpio)
1124 return -ENOMEM;
1126 * 0 is a valid GPIO so initialize all GPIO-s to negative value
1127 * to indicate that external control won't be used for this regulator.
1129 for (i = 0; i < s2mps11->rdev_num; i++)
1130 s2mps11->ext_control_gpio[i] = -EINVAL;
1132 if (!iodev->dev->of_node) {
1133 if (iodev->pdata) {
1134 pdata = iodev->pdata;
1135 goto common_reg;
1136 } else {
1137 dev_err(pdev->dev.parent,
1138 "Platform data or DT node not supplied\n");
1139 return -ENODEV;
1143 rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL);
1144 if (!rdata)
1145 return -ENOMEM;
1147 for (i = 0; i < s2mps11->rdev_num; i++)
1148 rdata[i].name = regulators[i].name;
1150 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11);
1151 if (ret)
1152 goto out;
1154 common_reg:
1155 platform_set_drvdata(pdev, s2mps11);
1157 config.dev = &pdev->dev;
1158 config.regmap = iodev->regmap_pmic;
1159 config.driver_data = s2mps11;
1160 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
1161 config.ena_gpio_initialized = true;
1162 for (i = 0; i < s2mps11->rdev_num; i++) {
1163 struct regulator_dev *regulator;
1165 if (pdata) {
1166 config.init_data = pdata->regulators[i].initdata;
1167 config.of_node = pdata->regulators[i].reg_node;
1168 } else {
1169 config.init_data = rdata[i].init_data;
1170 config.of_node = rdata[i].of_node;
1172 config.ena_gpio = s2mps11->ext_control_gpio[i];
1174 regulator = devm_regulator_register(&pdev->dev,
1175 &regulators[i], &config);
1176 if (IS_ERR(regulator)) {
1177 ret = PTR_ERR(regulator);
1178 dev_err(&pdev->dev, "regulator init failed for %d\n",
1180 goto out;
1183 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
1184 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1185 regulator);
1186 if (ret < 0) {
1187 dev_err(&pdev->dev,
1188 "failed to enable GPIO control over %s: %d\n",
1189 regulator->desc->name, ret);
1190 goto out;
1195 out:
1196 kfree(rdata);
1198 return ret;
1201 static const struct platform_device_id s2mps11_pmic_id[] = {
1202 { "s2mps11-regulator", S2MPS11X},
1203 { "s2mps13-regulator", S2MPS13X},
1204 { "s2mps14-regulator", S2MPS14X},
1205 { "s2mps15-regulator", S2MPS15X},
1206 { "s2mpu02-regulator", S2MPU02},
1207 { },
1209 MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1211 static struct platform_driver s2mps11_pmic_driver = {
1212 .driver = {
1213 .name = "s2mps11-pmic",
1215 .probe = s2mps11_pmic_probe,
1216 .id_table = s2mps11_pmic_id,
1219 static int __init s2mps11_pmic_init(void)
1221 return platform_driver_register(&s2mps11_pmic_driver);
1223 subsys_initcall(s2mps11_pmic_init);
1225 static void __exit s2mps11_pmic_exit(void)
1227 platform_driver_unregister(&s2mps11_pmic_driver);
1229 module_exit(s2mps11_pmic_exit);
1231 /* Module information */
1232 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1233 MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
1234 MODULE_LICENSE("GPL");