Version:  2.0.40 2.2.26 2.4.37 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6

Linux/drivers/regulator/s2mps11.c

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us