ARM: dts: add 'dr_mode' property to hsotg devices for exynos boards
[linux/fpc-iii.git] / drivers / regulator / s2mps11.c
blobc1444c3d84c2823a8b4eaed28e9bf5036290ce26
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/s2mpu02.h>
37 struct s2mps11_info {
38 unsigned int rdev_num;
39 int ramp_delay2;
40 int ramp_delay34;
41 int ramp_delay5;
42 int ramp_delay16;
43 int ramp_delay7810;
44 int ramp_delay9;
46 enum sec_device_type dev_type;
49 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
50 * the suspend mode was enabled.
52 unsigned long long s2mps14_suspend_state:50;
54 /* Array of size rdev_num with GPIO-s for external sleep control */
55 int *ext_control_gpio;
58 static int get_ramp_delay(int ramp_delay)
60 unsigned char cnt = 0;
62 ramp_delay /= 6250;
64 while (true) {
65 ramp_delay = ramp_delay >> 1;
66 if (ramp_delay == 0)
67 break;
68 cnt++;
71 if (cnt > 3)
72 cnt = 3;
74 return cnt;
77 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
78 unsigned int old_selector,
79 unsigned int new_selector)
81 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
82 unsigned int ramp_delay = 0;
83 int old_volt, new_volt;
85 switch (rdev_get_id(rdev)) {
86 case S2MPS11_BUCK2:
87 ramp_delay = s2mps11->ramp_delay2;
88 break;
89 case S2MPS11_BUCK3:
90 case S2MPS11_BUCK4:
91 ramp_delay = s2mps11->ramp_delay34;
92 break;
93 case S2MPS11_BUCK5:
94 ramp_delay = s2mps11->ramp_delay5;
95 break;
96 case S2MPS11_BUCK6:
97 case S2MPS11_BUCK1:
98 ramp_delay = s2mps11->ramp_delay16;
99 break;
100 case S2MPS11_BUCK7:
101 case S2MPS11_BUCK8:
102 case S2MPS11_BUCK10:
103 ramp_delay = s2mps11->ramp_delay7810;
104 break;
105 case S2MPS11_BUCK9:
106 ramp_delay = s2mps11->ramp_delay9;
109 if (ramp_delay == 0)
110 ramp_delay = rdev->desc->ramp_delay;
112 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
113 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
115 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
118 static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
120 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
121 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
122 unsigned int ramp_enable = 1, enable_shift = 0;
123 int ret;
125 switch (rdev_get_id(rdev)) {
126 case S2MPS11_BUCK1:
127 if (ramp_delay > s2mps11->ramp_delay16)
128 s2mps11->ramp_delay16 = ramp_delay;
129 else
130 ramp_delay = s2mps11->ramp_delay16;
132 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
133 break;
134 case S2MPS11_BUCK2:
135 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
136 if (!ramp_delay) {
137 ramp_enable = 0;
138 break;
141 s2mps11->ramp_delay2 = ramp_delay;
142 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
143 ramp_reg = S2MPS11_REG_RAMP;
144 break;
145 case S2MPS11_BUCK3:
146 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
147 if (!ramp_delay) {
148 ramp_enable = 0;
149 break;
152 if (ramp_delay > s2mps11->ramp_delay34)
153 s2mps11->ramp_delay34 = ramp_delay;
154 else
155 ramp_delay = s2mps11->ramp_delay34;
157 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
158 ramp_reg = S2MPS11_REG_RAMP;
159 break;
160 case S2MPS11_BUCK4:
161 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
162 if (!ramp_delay) {
163 ramp_enable = 0;
164 break;
167 if (ramp_delay > s2mps11->ramp_delay34)
168 s2mps11->ramp_delay34 = ramp_delay;
169 else
170 ramp_delay = s2mps11->ramp_delay34;
172 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
173 ramp_reg = S2MPS11_REG_RAMP;
174 break;
175 case S2MPS11_BUCK5:
176 s2mps11->ramp_delay5 = ramp_delay;
177 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
178 break;
179 case S2MPS11_BUCK6:
180 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
181 if (!ramp_delay) {
182 ramp_enable = 0;
183 break;
186 if (ramp_delay > s2mps11->ramp_delay16)
187 s2mps11->ramp_delay16 = ramp_delay;
188 else
189 ramp_delay = s2mps11->ramp_delay16;
191 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
192 break;
193 case S2MPS11_BUCK7:
194 case S2MPS11_BUCK8:
195 case S2MPS11_BUCK10:
196 if (ramp_delay > s2mps11->ramp_delay7810)
197 s2mps11->ramp_delay7810 = ramp_delay;
198 else
199 ramp_delay = s2mps11->ramp_delay7810;
201 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
202 break;
203 case S2MPS11_BUCK9:
204 s2mps11->ramp_delay9 = ramp_delay;
205 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
206 break;
207 default:
208 return 0;
211 if (!ramp_enable)
212 goto ramp_disable;
214 /* Ramp delay can be enabled/disabled only for buck[2346] */
215 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
216 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
217 rdev_get_id(rdev) == S2MPS11_BUCK6) {
218 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
219 1 << enable_shift, 1 << enable_shift);
220 if (ret) {
221 dev_err(&rdev->dev, "failed to enable ramp rate\n");
222 return ret;
226 ramp_val = get_ramp_delay(ramp_delay);
228 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
229 ramp_val << ramp_shift);
231 ramp_disable:
232 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
233 1 << enable_shift, 0);
236 static struct regulator_ops s2mps11_ldo_ops = {
237 .list_voltage = regulator_list_voltage_linear,
238 .map_voltage = regulator_map_voltage_linear,
239 .is_enabled = regulator_is_enabled_regmap,
240 .enable = regulator_enable_regmap,
241 .disable = regulator_disable_regmap,
242 .get_voltage_sel = regulator_get_voltage_sel_regmap,
243 .set_voltage_sel = regulator_set_voltage_sel_regmap,
244 .set_voltage_time_sel = regulator_set_voltage_time_sel,
247 static struct regulator_ops s2mps11_buck_ops = {
248 .list_voltage = regulator_list_voltage_linear,
249 .map_voltage = regulator_map_voltage_linear,
250 .is_enabled = regulator_is_enabled_regmap,
251 .enable = regulator_enable_regmap,
252 .disable = regulator_disable_regmap,
253 .get_voltage_sel = regulator_get_voltage_sel_regmap,
254 .set_voltage_sel = regulator_set_voltage_sel_regmap,
255 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
256 .set_ramp_delay = s2mps11_set_ramp_delay,
259 #define regulator_desc_s2mps11_ldo(num, step) { \
260 .name = "LDO"#num, \
261 .id = S2MPS11_LDO##num, \
262 .ops = &s2mps11_ldo_ops, \
263 .type = REGULATOR_VOLTAGE, \
264 .owner = THIS_MODULE, \
265 .min_uV = MIN_800_MV, \
266 .uV_step = step, \
267 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
268 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
269 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
270 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
271 .enable_mask = S2MPS11_ENABLE_MASK \
274 #define regulator_desc_s2mps11_buck1_4(num) { \
275 .name = "BUCK"#num, \
276 .id = S2MPS11_BUCK##num, \
277 .ops = &s2mps11_buck_ops, \
278 .type = REGULATOR_VOLTAGE, \
279 .owner = THIS_MODULE, \
280 .min_uV = MIN_600_MV, \
281 .uV_step = STEP_6_25_MV, \
282 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
283 .ramp_delay = S2MPS11_RAMP_DELAY, \
284 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
285 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
286 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
287 .enable_mask = S2MPS11_ENABLE_MASK \
290 #define regulator_desc_s2mps11_buck5 { \
291 .name = "BUCK5", \
292 .id = S2MPS11_BUCK5, \
293 .ops = &s2mps11_buck_ops, \
294 .type = REGULATOR_VOLTAGE, \
295 .owner = THIS_MODULE, \
296 .min_uV = MIN_600_MV, \
297 .uV_step = STEP_6_25_MV, \
298 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
299 .ramp_delay = S2MPS11_RAMP_DELAY, \
300 .vsel_reg = S2MPS11_REG_B5CTRL2, \
301 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
302 .enable_reg = S2MPS11_REG_B5CTRL1, \
303 .enable_mask = S2MPS11_ENABLE_MASK \
306 #define regulator_desc_s2mps11_buck6_10(num, min, step) { \
307 .name = "BUCK"#num, \
308 .id = S2MPS11_BUCK##num, \
309 .ops = &s2mps11_buck_ops, \
310 .type = REGULATOR_VOLTAGE, \
311 .owner = THIS_MODULE, \
312 .min_uV = min, \
313 .uV_step = step, \
314 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
315 .ramp_delay = S2MPS11_RAMP_DELAY, \
316 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
317 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
318 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
319 .enable_mask = S2MPS11_ENABLE_MASK \
322 static const struct regulator_desc s2mps11_regulators[] = {
323 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
324 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
325 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
326 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
327 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
328 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
329 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
330 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
331 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
332 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
333 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
334 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
335 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
336 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
337 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
338 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
339 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
340 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
341 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
342 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
343 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
344 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
345 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
346 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
348 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
349 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
350 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
353 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
361 regulator_desc_s2mps11_buck1_4(1),
362 regulator_desc_s2mps11_buck1_4(2),
363 regulator_desc_s2mps11_buck1_4(3),
364 regulator_desc_s2mps11_buck1_4(4),
365 regulator_desc_s2mps11_buck5,
366 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV, STEP_6_25_MV),
367 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV, STEP_6_25_MV),
368 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV, STEP_6_25_MV),
369 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV, STEP_25_MV),
370 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV),
373 static struct regulator_ops s2mps14_reg_ops;
375 #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
376 .name = "LDO"#num, \
377 .id = S2MPS13_LDO##num, \
378 .ops = &s2mps14_reg_ops, \
379 .type = REGULATOR_VOLTAGE, \
380 .owner = THIS_MODULE, \
381 .min_uV = min, \
382 .uV_step = step, \
383 .linear_min_sel = min_sel, \
384 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
385 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
386 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
387 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
388 .enable_mask = S2MPS14_ENABLE_MASK \
391 #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
392 .name = "BUCK"#num, \
393 .id = S2MPS13_BUCK##num, \
394 .ops = &s2mps14_reg_ops, \
395 .type = REGULATOR_VOLTAGE, \
396 .owner = THIS_MODULE, \
397 .min_uV = min, \
398 .uV_step = step, \
399 .linear_min_sel = min_sel, \
400 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
401 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
402 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
403 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
404 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
405 .enable_mask = S2MPS14_ENABLE_MASK \
408 static const struct regulator_desc s2mps13_regulators[] = {
409 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
410 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
411 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
412 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
413 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
414 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
415 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
416 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
417 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
418 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
419 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
420 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
421 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
422 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
423 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
424 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
425 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
426 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
427 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
428 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
429 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
430 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
431 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
432 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
433 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
434 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
435 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
436 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
437 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
438 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
439 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
440 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
441 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
442 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
443 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
444 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
445 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
446 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
447 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
448 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
449 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
450 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
451 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
452 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
453 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
454 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
455 regulator_desc_s2mps13_buck(7, MIN_500_MV, STEP_6_25_MV, 0x10),
456 regulator_desc_s2mps13_buck(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
457 regulator_desc_s2mps13_buck(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
458 regulator_desc_s2mps13_buck(10, MIN_500_MV, STEP_6_25_MV, 0x10),
461 static int s2mps14_regulator_enable(struct regulator_dev *rdev)
463 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
464 unsigned int val;
466 switch (s2mps11->dev_type) {
467 case S2MPS13X:
468 case S2MPS14X:
469 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
470 val = S2MPS14_ENABLE_SUSPEND;
471 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
472 val = S2MPS14_ENABLE_EXT_CONTROL;
473 else
474 val = rdev->desc->enable_mask;
475 break;
476 case S2MPU02:
477 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
478 val = S2MPU02_ENABLE_SUSPEND;
479 else
480 val = rdev->desc->enable_mask;
481 break;
482 default:
483 return -EINVAL;
486 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
487 rdev->desc->enable_mask, val);
490 static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
492 int ret;
493 unsigned int val, state;
494 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
495 int rdev_id = rdev_get_id(rdev);
497 /* Below LDO should be always on or does not support suspend mode. */
498 switch (s2mps11->dev_type) {
499 case S2MPS13X:
500 case S2MPS14X:
501 switch (rdev_id) {
502 case S2MPS14_LDO3:
503 return 0;
504 default:
505 state = S2MPS14_ENABLE_SUSPEND;
506 break;
508 break;
509 case S2MPU02:
510 switch (rdev_id) {
511 case S2MPU02_LDO13:
512 case S2MPU02_LDO14:
513 case S2MPU02_LDO15:
514 case S2MPU02_LDO17:
515 case S2MPU02_BUCK7:
516 state = S2MPU02_DISABLE_SUSPEND;
517 break;
518 default:
519 state = S2MPU02_ENABLE_SUSPEND;
520 break;
522 break;
523 default:
524 return -EINVAL;
527 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
528 if (ret < 0)
529 return ret;
531 s2mps11->s2mps14_suspend_state |= (1 << rdev_get_id(rdev));
533 * Don't enable suspend mode if regulator is already disabled because
534 * this would effectively for a short time turn on the regulator after
535 * resuming.
536 * However we still want to toggle the suspend_state bit for regulator
537 * in case if it got enabled before suspending the system.
539 if (!(val & rdev->desc->enable_mask))
540 return 0;
542 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
543 rdev->desc->enable_mask, state);
546 static struct regulator_ops s2mps14_reg_ops = {
547 .list_voltage = regulator_list_voltage_linear,
548 .map_voltage = regulator_map_voltage_linear,
549 .is_enabled = regulator_is_enabled_regmap,
550 .enable = s2mps14_regulator_enable,
551 .disable = regulator_disable_regmap,
552 .get_voltage_sel = regulator_get_voltage_sel_regmap,
553 .set_voltage_sel = regulator_set_voltage_sel_regmap,
554 .set_voltage_time_sel = regulator_set_voltage_time_sel,
555 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
558 #define regulator_desc_s2mps14_ldo(num, min, step) { \
559 .name = "LDO"#num, \
560 .id = S2MPS14_LDO##num, \
561 .ops = &s2mps14_reg_ops, \
562 .type = REGULATOR_VOLTAGE, \
563 .owner = THIS_MODULE, \
564 .min_uV = min, \
565 .uV_step = step, \
566 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
567 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
568 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
569 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
570 .enable_mask = S2MPS14_ENABLE_MASK \
573 #define regulator_desc_s2mps14_buck(num, min, step) { \
574 .name = "BUCK"#num, \
575 .id = S2MPS14_BUCK##num, \
576 .ops = &s2mps14_reg_ops, \
577 .type = REGULATOR_VOLTAGE, \
578 .owner = THIS_MODULE, \
579 .min_uV = min, \
580 .uV_step = step, \
581 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
582 .linear_min_sel = S2MPS14_BUCK1235_START_SEL, \
583 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
584 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
585 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
586 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
587 .enable_mask = S2MPS14_ENABLE_MASK \
590 static const struct regulator_desc s2mps14_regulators[] = {
591 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
592 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
593 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
594 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
595 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
596 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
597 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
598 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
599 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
600 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
601 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
602 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
603 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
604 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
605 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
606 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
607 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
608 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
609 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
610 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
611 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
612 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
613 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
614 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
615 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
616 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV),
617 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV),
618 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV),
619 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV),
620 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV),
623 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
624 struct regulator_dev *rdev)
626 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
627 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
630 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
631 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
633 int *gpio = s2mps11->ext_control_gpio;
634 unsigned int i;
635 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
636 S2MPS14_LDO12 };
638 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
639 unsigned int reg = valid_regulators[i];
641 if (!rdata[reg].init_data || !rdata[reg].of_node)
642 continue;
644 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
645 "samsung,ext-control-gpios", 0);
646 if (gpio_is_valid(gpio[reg]))
647 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
648 gpio[reg], reg, rdata[reg].name);
652 static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
653 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
655 struct device_node *reg_np;
657 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
658 if (!reg_np) {
659 dev_err(&pdev->dev, "could not find regulators sub-node\n");
660 return -EINVAL;
663 of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
664 if (s2mps11->dev_type == S2MPS14X)
665 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
667 of_node_put(reg_np);
669 return 0;
672 static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
674 unsigned int ramp_val, ramp_shift, ramp_reg;
676 switch (rdev_get_id(rdev)) {
677 case S2MPU02_BUCK1:
678 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
679 break;
680 case S2MPU02_BUCK2:
681 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
682 break;
683 case S2MPU02_BUCK3:
684 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
685 break;
686 case S2MPU02_BUCK4:
687 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
688 break;
689 default:
690 return 0;
692 ramp_reg = S2MPU02_REG_RAMP1;
693 ramp_val = get_ramp_delay(ramp_delay);
695 return regmap_update_bits(rdev->regmap, ramp_reg,
696 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
697 ramp_val << ramp_shift);
700 static struct regulator_ops s2mpu02_ldo_ops = {
701 .list_voltage = regulator_list_voltage_linear,
702 .map_voltage = regulator_map_voltage_linear,
703 .is_enabled = regulator_is_enabled_regmap,
704 .enable = s2mps14_regulator_enable,
705 .disable = regulator_disable_regmap,
706 .get_voltage_sel = regulator_get_voltage_sel_regmap,
707 .set_voltage_sel = regulator_set_voltage_sel_regmap,
708 .set_voltage_time_sel = regulator_set_voltage_time_sel,
709 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
712 static struct regulator_ops s2mpu02_buck_ops = {
713 .list_voltage = regulator_list_voltage_linear,
714 .map_voltage = regulator_map_voltage_linear,
715 .is_enabled = regulator_is_enabled_regmap,
716 .enable = s2mps14_regulator_enable,
717 .disable = regulator_disable_regmap,
718 .get_voltage_sel = regulator_get_voltage_sel_regmap,
719 .set_voltage_sel = regulator_set_voltage_sel_regmap,
720 .set_voltage_time_sel = regulator_set_voltage_time_sel,
721 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
722 .set_ramp_delay = s2mpu02_set_ramp_delay,
725 #define regulator_desc_s2mpu02_ldo1(num) { \
726 .name = "LDO"#num, \
727 .id = S2MPU02_LDO##num, \
728 .ops = &s2mpu02_ldo_ops, \
729 .type = REGULATOR_VOLTAGE, \
730 .owner = THIS_MODULE, \
731 .min_uV = S2MPU02_LDO_MIN_900MV, \
732 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
733 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
734 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
735 .vsel_reg = S2MPU02_REG_L1CTRL, \
736 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
737 .enable_reg = S2MPU02_REG_L1CTRL, \
738 .enable_mask = S2MPU02_ENABLE_MASK \
740 #define regulator_desc_s2mpu02_ldo2(num) { \
741 .name = "LDO"#num, \
742 .id = S2MPU02_LDO##num, \
743 .ops = &s2mpu02_ldo_ops, \
744 .type = REGULATOR_VOLTAGE, \
745 .owner = THIS_MODULE, \
746 .min_uV = S2MPU02_LDO_MIN_1050MV, \
747 .uV_step = S2MPU02_LDO_STEP_25MV, \
748 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
749 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
750 .vsel_reg = S2MPU02_REG_L2CTRL1, \
751 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
752 .enable_reg = S2MPU02_REG_L2CTRL1, \
753 .enable_mask = S2MPU02_ENABLE_MASK \
755 #define regulator_desc_s2mpu02_ldo3(num) { \
756 .name = "LDO"#num, \
757 .id = S2MPU02_LDO##num, \
758 .ops = &s2mpu02_ldo_ops, \
759 .type = REGULATOR_VOLTAGE, \
760 .owner = THIS_MODULE, \
761 .min_uV = S2MPU02_LDO_MIN_900MV, \
762 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
763 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
764 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
765 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
766 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
767 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
768 .enable_mask = S2MPU02_ENABLE_MASK \
770 #define regulator_desc_s2mpu02_ldo4(num) { \
771 .name = "LDO"#num, \
772 .id = S2MPU02_LDO##num, \
773 .ops = &s2mpu02_ldo_ops, \
774 .type = REGULATOR_VOLTAGE, \
775 .owner = THIS_MODULE, \
776 .min_uV = S2MPU02_LDO_MIN_1050MV, \
777 .uV_step = S2MPU02_LDO_STEP_25MV, \
778 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
779 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
780 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
781 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
782 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
783 .enable_mask = S2MPU02_ENABLE_MASK \
785 #define regulator_desc_s2mpu02_ldo5(num) { \
786 .name = "LDO"#num, \
787 .id = S2MPU02_LDO##num, \
788 .ops = &s2mpu02_ldo_ops, \
789 .type = REGULATOR_VOLTAGE, \
790 .owner = THIS_MODULE, \
791 .min_uV = S2MPU02_LDO_MIN_1600MV, \
792 .uV_step = S2MPU02_LDO_STEP_50MV, \
793 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
794 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
795 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
796 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
797 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
798 .enable_mask = S2MPU02_ENABLE_MASK \
801 #define regulator_desc_s2mpu02_buck1234(num) { \
802 .name = "BUCK"#num, \
803 .id = S2MPU02_BUCK##num, \
804 .ops = &s2mpu02_buck_ops, \
805 .type = REGULATOR_VOLTAGE, \
806 .owner = THIS_MODULE, \
807 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
808 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
809 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
810 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
811 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
812 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
813 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
814 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
815 .enable_mask = S2MPU02_ENABLE_MASK \
817 #define regulator_desc_s2mpu02_buck5(num) { \
818 .name = "BUCK"#num, \
819 .id = S2MPU02_BUCK##num, \
820 .ops = &s2mpu02_ldo_ops, \
821 .type = REGULATOR_VOLTAGE, \
822 .owner = THIS_MODULE, \
823 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
824 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
825 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
826 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
827 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
828 .vsel_reg = S2MPU02_REG_B5CTRL2, \
829 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
830 .enable_reg = S2MPU02_REG_B5CTRL1, \
831 .enable_mask = S2MPU02_ENABLE_MASK \
833 #define regulator_desc_s2mpu02_buck6(num) { \
834 .name = "BUCK"#num, \
835 .id = S2MPU02_BUCK##num, \
836 .ops = &s2mpu02_ldo_ops, \
837 .type = REGULATOR_VOLTAGE, \
838 .owner = THIS_MODULE, \
839 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
840 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
841 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
842 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
843 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
844 .vsel_reg = S2MPU02_REG_B6CTRL2, \
845 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
846 .enable_reg = S2MPU02_REG_B6CTRL1, \
847 .enable_mask = S2MPU02_ENABLE_MASK \
849 #define regulator_desc_s2mpu02_buck7(num) { \
850 .name = "BUCK"#num, \
851 .id = S2MPU02_BUCK##num, \
852 .ops = &s2mpu02_ldo_ops, \
853 .type = REGULATOR_VOLTAGE, \
854 .owner = THIS_MODULE, \
855 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
856 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
857 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
858 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
859 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
860 .vsel_reg = S2MPU02_REG_B7CTRL2, \
861 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
862 .enable_reg = S2MPU02_REG_B7CTRL1, \
863 .enable_mask = S2MPU02_ENABLE_MASK \
866 static const struct regulator_desc s2mpu02_regulators[] = {
867 regulator_desc_s2mpu02_ldo1(1),
868 regulator_desc_s2mpu02_ldo2(2),
869 regulator_desc_s2mpu02_ldo4(3),
870 regulator_desc_s2mpu02_ldo5(4),
871 regulator_desc_s2mpu02_ldo4(5),
872 regulator_desc_s2mpu02_ldo3(6),
873 regulator_desc_s2mpu02_ldo3(7),
874 regulator_desc_s2mpu02_ldo4(8),
875 regulator_desc_s2mpu02_ldo5(9),
876 regulator_desc_s2mpu02_ldo3(10),
877 regulator_desc_s2mpu02_ldo4(11),
878 regulator_desc_s2mpu02_ldo5(12),
879 regulator_desc_s2mpu02_ldo5(13),
880 regulator_desc_s2mpu02_ldo5(14),
881 regulator_desc_s2mpu02_ldo5(15),
882 regulator_desc_s2mpu02_ldo5(16),
883 regulator_desc_s2mpu02_ldo4(17),
884 regulator_desc_s2mpu02_ldo5(18),
885 regulator_desc_s2mpu02_ldo3(19),
886 regulator_desc_s2mpu02_ldo4(20),
887 regulator_desc_s2mpu02_ldo5(21),
888 regulator_desc_s2mpu02_ldo5(22),
889 regulator_desc_s2mpu02_ldo5(23),
890 regulator_desc_s2mpu02_ldo4(24),
891 regulator_desc_s2mpu02_ldo5(25),
892 regulator_desc_s2mpu02_ldo4(26),
893 regulator_desc_s2mpu02_ldo5(27),
894 regulator_desc_s2mpu02_ldo5(28),
895 regulator_desc_s2mpu02_buck1234(1),
896 regulator_desc_s2mpu02_buck1234(2),
897 regulator_desc_s2mpu02_buck1234(3),
898 regulator_desc_s2mpu02_buck1234(4),
899 regulator_desc_s2mpu02_buck5(5),
900 regulator_desc_s2mpu02_buck6(6),
901 regulator_desc_s2mpu02_buck7(7),
904 static int s2mps11_pmic_probe(struct platform_device *pdev)
906 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
907 struct sec_platform_data *pdata = NULL;
908 struct of_regulator_match *rdata = NULL;
909 struct regulator_config config = { };
910 struct s2mps11_info *s2mps11;
911 int i, ret = 0;
912 const struct regulator_desc *regulators;
914 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
915 GFP_KERNEL);
916 if (!s2mps11)
917 return -ENOMEM;
919 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
920 switch (s2mps11->dev_type) {
921 case S2MPS11X:
922 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
923 regulators = s2mps11_regulators;
924 break;
925 case S2MPS13X:
926 s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
927 regulators = s2mps13_regulators;
928 break;
929 case S2MPS14X:
930 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
931 regulators = s2mps14_regulators;
932 break;
933 case S2MPU02:
934 s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
935 regulators = s2mpu02_regulators;
936 break;
937 default:
938 dev_err(&pdev->dev, "Invalid device type: %u\n",
939 s2mps11->dev_type);
940 return -EINVAL;
943 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
944 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
945 GFP_KERNEL);
946 if (!s2mps11->ext_control_gpio)
947 return -ENOMEM;
949 * 0 is a valid GPIO so initialize all GPIO-s to negative value
950 * to indicate that external control won't be used for this regulator.
952 for (i = 0; i < s2mps11->rdev_num; i++)
953 s2mps11->ext_control_gpio[i] = -EINVAL;
955 if (!iodev->dev->of_node) {
956 if (iodev->pdata) {
957 pdata = iodev->pdata;
958 goto common_reg;
959 } else {
960 dev_err(pdev->dev.parent,
961 "Platform data or DT node not supplied\n");
962 return -ENODEV;
966 rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL);
967 if (!rdata)
968 return -ENOMEM;
970 for (i = 0; i < s2mps11->rdev_num; i++)
971 rdata[i].name = regulators[i].name;
973 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11);
974 if (ret)
975 goto out;
977 common_reg:
978 platform_set_drvdata(pdev, s2mps11);
980 config.dev = &pdev->dev;
981 config.regmap = iodev->regmap_pmic;
982 config.driver_data = s2mps11;
983 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
984 config.ena_gpio_initialized = true;
985 for (i = 0; i < s2mps11->rdev_num; i++) {
986 struct regulator_dev *regulator;
988 if (pdata) {
989 config.init_data = pdata->regulators[i].initdata;
990 config.of_node = pdata->regulators[i].reg_node;
991 } else {
992 config.init_data = rdata[i].init_data;
993 config.of_node = rdata[i].of_node;
995 config.ena_gpio = s2mps11->ext_control_gpio[i];
997 regulator = devm_regulator_register(&pdev->dev,
998 &regulators[i], &config);
999 if (IS_ERR(regulator)) {
1000 ret = PTR_ERR(regulator);
1001 dev_err(&pdev->dev, "regulator init failed for %d\n",
1003 goto out;
1006 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
1007 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1008 regulator);
1009 if (ret < 0) {
1010 dev_err(&pdev->dev,
1011 "failed to enable GPIO control over %s: %d\n",
1012 regulator->desc->name, ret);
1013 goto out;
1018 out:
1019 kfree(rdata);
1021 return ret;
1024 static const struct platform_device_id s2mps11_pmic_id[] = {
1025 { "s2mps11-pmic", S2MPS11X},
1026 { "s2mps13-pmic", S2MPS13X},
1027 { "s2mps14-pmic", S2MPS14X},
1028 { "s2mpu02-pmic", S2MPU02},
1029 { },
1031 MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1033 static struct platform_driver s2mps11_pmic_driver = {
1034 .driver = {
1035 .name = "s2mps11-pmic",
1037 .probe = s2mps11_pmic_probe,
1038 .id_table = s2mps11_pmic_id,
1041 static int __init s2mps11_pmic_init(void)
1043 return platform_driver_register(&s2mps11_pmic_driver);
1045 subsys_initcall(s2mps11_pmic_init);
1047 static void __exit s2mps11_pmic_exit(void)
1049 platform_driver_unregister(&s2mps11_pmic_driver);
1051 module_exit(s2mps11_pmic_exit);
1053 /* Module information */
1054 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1055 MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPU02 Regulator Driver");
1056 MODULE_LICENSE("GPL");