blob: 134c62db36c5d5ebb6ce2adebcf430b59ca1c8d6 [file] [log] [blame]
Krzysztof Kozlowski4f3fb282018-08-07 18:18:26 +02001// SPDX-License-Identifier: GPL-2.0+
2//
3// Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
4// http://www.samsung.com
Sangbeom Kimcb746852012-07-11 21:08:17 +09005
6#include <linux/bug.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +09007#include <linux/err.h>
Linus Walleij1c984942018-11-15 09:01:17 +01008#include <linux/gpio/consumer.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +09009#include <linux/slab.h>
10#include <linux/module.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053011#include <linux/of.h>
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +053012#include <linux/regmap.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090013#include <linux/platform_device.h>
14#include <linux/regulator/driver.h>
15#include <linux/regulator/machine.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053016#include <linux/regulator/of_regulator.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090017#include <linux/mfd/samsung/core.h>
18#include <linux/mfd/samsung/s2mps11.h>
Chanwoo Choi76b98402014-11-18 17:59:40 +090019#include <linux/mfd/samsung/s2mps13.h>
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +010020#include <linux/mfd/samsung/s2mps14.h>
Thomas Abraham51af2062015-11-20 16:07:52 +053021#include <linux/mfd/samsung/s2mps15.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090022#include <linux/mfd/samsung/s2mpu02.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053023
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +090024/* The highest number of possible regulators for supported devices. */
25#define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
Sangbeom Kimcb746852012-07-11 21:08:17 +090026struct s2mps11_info {
Sangbeom Kimcb746852012-07-11 21:08:17 +090027 int ramp_delay2;
28 int ramp_delay34;
29 int ramp_delay5;
30 int ramp_delay16;
31 int ramp_delay7810;
32 int ramp_delay9;
Chanwoo Choi00e25732014-06-25 16:14:45 +090033
34 enum sec_device_type dev_type;
35
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010036 /*
Chanwoo Choi76b98402014-11-18 17:59:40 +090037 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
38 * the suspend mode was enabled.
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010039 */
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +090040 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
Chanwoo Choi00e25732014-06-25 16:14:45 +090041
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +090042 /*
43 * Array (size: number of regulators) with GPIO-s for external
44 * sleep control.
45 */
Linus Walleij1c984942018-11-15 09:01:17 +010046 struct gpio_desc **ext_control_gpiod;
Sangbeom Kimcb746852012-07-11 21:08:17 +090047};
48
49static int get_ramp_delay(int ramp_delay)
50{
51 unsigned char cnt = 0;
52
Yadwinder Singh Brar90068342013-06-24 16:50:55 +053053 ramp_delay /= 6250;
Sangbeom Kimcb746852012-07-11 21:08:17 +090054
55 while (true) {
56 ramp_delay = ramp_delay >> 1;
57 if (ramp_delay == 0)
58 break;
59 cnt++;
60 }
Axel Linf8f1d482013-08-05 14:08:37 +080061
62 if (cnt > 3)
63 cnt = 3;
64
Sangbeom Kimcb746852012-07-11 21:08:17 +090065 return cnt;
66}
67
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053068static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
69 unsigned int old_selector,
70 unsigned int new_selector)
71{
72 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
73 unsigned int ramp_delay = 0;
74 int old_volt, new_volt;
75
Thiago Farinad55efa42014-01-26 21:57:12 -020076 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053077 case S2MPS11_BUCK2:
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053078 ramp_delay = s2mps11->ramp_delay2;
79 break;
80 case S2MPS11_BUCK3:
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053081 case S2MPS11_BUCK4:
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053082 ramp_delay = s2mps11->ramp_delay34;
83 break;
84 case S2MPS11_BUCK5:
85 ramp_delay = s2mps11->ramp_delay5;
86 break;
87 case S2MPS11_BUCK6:
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053088 case S2MPS11_BUCK1:
89 ramp_delay = s2mps11->ramp_delay16;
90 break;
91 case S2MPS11_BUCK7:
92 case S2MPS11_BUCK8:
93 case S2MPS11_BUCK10:
94 ramp_delay = s2mps11->ramp_delay7810;
95 break;
96 case S2MPS11_BUCK9:
97 ramp_delay = s2mps11->ramp_delay9;
98 }
99
100 if (ramp_delay == 0)
101 ramp_delay = rdev->desc->ramp_delay;
102
103 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
104 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
105
106 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
107}
108
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530109static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
110{
111 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
112 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
113 unsigned int ramp_enable = 1, enable_shift = 0;
114 int ret;
115
Thiago Farinad55efa42014-01-26 21:57:12 -0200116 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530117 case S2MPS11_BUCK1:
118 if (ramp_delay > s2mps11->ramp_delay16)
119 s2mps11->ramp_delay16 = ramp_delay;
120 else
121 ramp_delay = s2mps11->ramp_delay16;
122
123 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
124 break;
125 case S2MPS11_BUCK2:
126 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
127 if (!ramp_delay) {
128 ramp_enable = 0;
129 break;
130 }
131
132 s2mps11->ramp_delay2 = ramp_delay;
133 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
134 ramp_reg = S2MPS11_REG_RAMP;
135 break;
136 case S2MPS11_BUCK3:
137 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
138 if (!ramp_delay) {
139 ramp_enable = 0;
140 break;
141 }
142
143 if (ramp_delay > s2mps11->ramp_delay34)
144 s2mps11->ramp_delay34 = ramp_delay;
145 else
146 ramp_delay = s2mps11->ramp_delay34;
147
148 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
149 ramp_reg = S2MPS11_REG_RAMP;
150 break;
151 case S2MPS11_BUCK4:
152 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
153 if (!ramp_delay) {
154 ramp_enable = 0;
155 break;
156 }
157
158 if (ramp_delay > s2mps11->ramp_delay34)
159 s2mps11->ramp_delay34 = ramp_delay;
160 else
161 ramp_delay = s2mps11->ramp_delay34;
162
163 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
164 ramp_reg = S2MPS11_REG_RAMP;
165 break;
166 case S2MPS11_BUCK5:
167 s2mps11->ramp_delay5 = ramp_delay;
168 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
169 break;
170 case S2MPS11_BUCK6:
171 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
172 if (!ramp_delay) {
173 ramp_enable = 0;
174 break;
175 }
176
177 if (ramp_delay > s2mps11->ramp_delay16)
178 s2mps11->ramp_delay16 = ramp_delay;
179 else
180 ramp_delay = s2mps11->ramp_delay16;
181
182 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
183 break;
184 case S2MPS11_BUCK7:
185 case S2MPS11_BUCK8:
186 case S2MPS11_BUCK10:
187 if (ramp_delay > s2mps11->ramp_delay7810)
188 s2mps11->ramp_delay7810 = ramp_delay;
189 else
190 ramp_delay = s2mps11->ramp_delay7810;
191
192 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
193 break;
194 case S2MPS11_BUCK9:
195 s2mps11->ramp_delay9 = ramp_delay;
196 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
197 break;
198 default:
199 return 0;
200 }
201
202 if (!ramp_enable)
203 goto ramp_disable;
204
Krzysztof Kozlowskib203e0d2014-05-06 08:37:36 +0200205 /* Ramp delay can be enabled/disabled only for buck[2346] */
206 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
207 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
208 rdev_get_id(rdev) == S2MPS11_BUCK6) {
209 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
210 1 << enable_shift, 1 << enable_shift);
211 if (ret) {
212 dev_err(&rdev->dev, "failed to enable ramp rate\n");
213 return ret;
214 }
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530215 }
216
217 ramp_val = get_ramp_delay(ramp_delay);
218
Axel Linf8f1d482013-08-05 14:08:37 +0800219 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
220 ramp_val << ramp_shift);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530221
222ramp_disable:
Axel Lin80853302013-08-03 17:10:42 +0800223 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
224 1 << enable_shift, 0);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530225}
226
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200227static const struct regulator_ops s2mps11_ldo_ops = {
Sangbeom Kimcb746852012-07-11 21:08:17 +0900228 .list_voltage = regulator_list_voltage_linear,
229 .map_voltage = regulator_map_voltage_linear,
230 .is_enabled = regulator_is_enabled_regmap,
231 .enable = regulator_enable_regmap,
232 .disable = regulator_disable_regmap,
233 .get_voltage_sel = regulator_get_voltage_sel_regmap,
234 .set_voltage_sel = regulator_set_voltage_sel_regmap,
235 .set_voltage_time_sel = regulator_set_voltage_time_sel,
236};
237
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200238static const struct regulator_ops s2mps11_buck_ops = {
Sangbeom Kimcb746852012-07-11 21:08:17 +0900239 .list_voltage = regulator_list_voltage_linear,
240 .map_voltage = regulator_map_voltage_linear,
241 .is_enabled = regulator_is_enabled_regmap,
242 .enable = regulator_enable_regmap,
243 .disable = regulator_disable_regmap,
244 .get_voltage_sel = regulator_get_voltage_sel_regmap,
245 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +0530246 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530247 .set_ramp_delay = s2mps11_set_ramp_delay,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900248};
249
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530250#define regulator_desc_s2mps11_ldo(num, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900251 .name = "LDO"#num, \
252 .id = S2MPS11_LDO##num, \
253 .ops = &s2mps11_ldo_ops, \
254 .type = REGULATOR_VOLTAGE, \
255 .owner = THIS_MODULE, \
Krzysztof Kozlowski94be46b2016-04-18 15:33:10 +0200256 .ramp_delay = RAMP_DELAY_12_MVUS, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530257 .min_uV = MIN_800_MV, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530258 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900259 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
260 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800261 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900262 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
263 .enable_mask = S2MPS11_ENABLE_MASK \
264}
265
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100266#define regulator_desc_s2mps11_buck1_4(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900267 .name = "BUCK"#num, \
268 .id = S2MPS11_BUCK##num, \
269 .ops = &s2mps11_buck_ops, \
270 .type = REGULATOR_VOLTAGE, \
271 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530272 .min_uV = MIN_600_MV, \
273 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900274 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530275 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900276 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800277 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900278 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
279 .enable_mask = S2MPS11_ENABLE_MASK \
280}
281
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100282#define regulator_desc_s2mps11_buck5 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900283 .name = "BUCK5", \
284 .id = S2MPS11_BUCK5, \
285 .ops = &s2mps11_buck_ops, \
286 .type = REGULATOR_VOLTAGE, \
287 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530288 .min_uV = MIN_600_MV, \
289 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900290 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530291 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900292 .vsel_reg = S2MPS11_REG_B5CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800293 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900294 .enable_reg = S2MPS11_REG_B5CTRL1, \
295 .enable_mask = S2MPS11_ENABLE_MASK \
296}
297
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900298#define regulator_desc_s2mps11_buck67810(num, min, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900299 .name = "BUCK"#num, \
300 .id = S2MPS11_BUCK##num, \
301 .ops = &s2mps11_buck_ops, \
302 .type = REGULATOR_VOLTAGE, \
303 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530304 .min_uV = min, \
305 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900306 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530307 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900308 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800309 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900310 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
311 .enable_mask = S2MPS11_ENABLE_MASK \
312}
313
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900314#define regulator_desc_s2mps11_buck9 { \
315 .name = "BUCK9", \
316 .id = S2MPS11_BUCK9, \
317 .ops = &s2mps11_buck_ops, \
318 .type = REGULATOR_VOLTAGE, \
319 .owner = THIS_MODULE, \
320 .min_uV = MIN_3000_MV, \
321 .uV_step = STEP_25_MV, \
322 .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
323 .ramp_delay = S2MPS11_RAMP_DELAY, \
324 .vsel_reg = S2MPS11_REG_B9CTRL2, \
325 .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
326 .enable_reg = S2MPS11_REG_B9CTRL1, \
327 .enable_mask = S2MPS11_ENABLE_MASK \
328}
329
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100330static const struct regulator_desc s2mps11_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530331 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
332 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
333 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
334 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
335 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
336 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
337 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
338 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
339 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
340 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
341 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
342 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
343 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
344 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
345 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
346 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
348 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
349 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
350 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
353 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
354 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
358 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
361 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
362 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
363 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
364 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
Krzysztof Kozlowski56b5d4e2019-02-09 18:14:14 +0100365 regulator_desc_s2mps11_ldo(35, STEP_25_MV),
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530366 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
367 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
368 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100369 regulator_desc_s2mps11_buck1_4(1),
370 regulator_desc_s2mps11_buck1_4(2),
371 regulator_desc_s2mps11_buck1_4(3),
372 regulator_desc_s2mps11_buck1_4(4),
373 regulator_desc_s2mps11_buck5,
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900374 regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV),
Krzysztof Kozlowski56b5d4e2019-02-09 18:14:14 +0100375 regulator_desc_s2mps11_buck67810(7, MIN_600_MV, STEP_12_5_MV),
376 regulator_desc_s2mps11_buck67810(8, MIN_600_MV, STEP_12_5_MV),
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900377 regulator_desc_s2mps11_buck9,
378 regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100379};
380
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200381static const struct regulator_ops s2mps14_reg_ops;
Chanwoo Choi76b98402014-11-18 17:59:40 +0900382
383#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
384 .name = "LDO"#num, \
385 .id = S2MPS13_LDO##num, \
386 .ops = &s2mps14_reg_ops, \
387 .type = REGULATOR_VOLTAGE, \
388 .owner = THIS_MODULE, \
389 .min_uV = min, \
390 .uV_step = step, \
391 .linear_min_sel = min_sel, \
392 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
393 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
394 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
395 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
396 .enable_mask = S2MPS14_ENABLE_MASK \
397}
398
399#define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
400 .name = "BUCK"#num, \
401 .id = S2MPS13_BUCK##num, \
402 .ops = &s2mps14_reg_ops, \
403 .type = REGULATOR_VOLTAGE, \
404 .owner = THIS_MODULE, \
405 .min_uV = min, \
406 .uV_step = step, \
407 .linear_min_sel = min_sel, \
408 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
409 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
410 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
411 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
412 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
413 .enable_mask = S2MPS14_ENABLE_MASK \
414}
415
Jonghwa Leead26aa62015-01-08 11:04:07 +0900416#define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
417 .name = "BUCK"#num, \
418 .id = S2MPS13_BUCK##num, \
419 .ops = &s2mps14_reg_ops, \
420 .type = REGULATOR_VOLTAGE, \
421 .owner = THIS_MODULE, \
422 .min_uV = min, \
423 .uV_step = step, \
424 .linear_min_sel = min_sel, \
425 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
426 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
427 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
428 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
429 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
430 .enable_mask = S2MPS14_ENABLE_MASK \
431}
432
433#define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
434 .name = "BUCK"#num, \
435 .id = S2MPS13_BUCK##num, \
436 .ops = &s2mps14_reg_ops, \
437 .type = REGULATOR_VOLTAGE, \
438 .owner = THIS_MODULE, \
439 .min_uV = min, \
440 .uV_step = step, \
441 .linear_min_sel = min_sel, \
442 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
443 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
444 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
445 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
446 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
447 .enable_mask = S2MPS14_ENABLE_MASK \
448}
449
Chanwoo Choi76b98402014-11-18 17:59:40 +0900450static const struct regulator_desc s2mps13_regulators[] = {
451 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
452 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
453 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
454 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
455 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
456 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
457 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
458 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
459 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
460 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
461 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
462 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
463 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
464 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
465 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
466 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
467 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
468 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
469 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
470 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
471 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
472 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
473 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
474 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
475 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
476 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
477 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
478 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
479 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
480 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
481 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
482 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
483 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
484 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
485 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
486 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
487 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
488 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
489 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
490 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
491 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
492 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
493 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
494 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
495 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
496 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
Jonghwa Leead26aa62015-01-08 11:04:07 +0900497 regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
498 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
499 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
500 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
Chanwoo Choi76b98402014-11-18 17:59:40 +0900501};
502
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100503static int s2mps14_regulator_enable(struct regulator_dev *rdev)
504{
505 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
506 unsigned int val;
507
Chanwoo Choi00e25732014-06-25 16:14:45 +0900508 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900509 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900510 case S2MPS14X:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900511 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900512 val = S2MPS14_ENABLE_SUSPEND;
Linus Walleij1c984942018-11-15 09:01:17 +0100513 else if (s2mps11->ext_control_gpiod[rdev_get_id(rdev)])
Chanwoo Choi00e25732014-06-25 16:14:45 +0900514 val = S2MPS14_ENABLE_EXT_CONTROL;
515 else
516 val = rdev->desc->enable_mask;
517 break;
518 case S2MPU02:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900519 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900520 val = S2MPU02_ENABLE_SUSPEND;
521 else
522 val = rdev->desc->enable_mask;
523 break;
524 default:
525 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900526 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100527
528 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
529 rdev->desc->enable_mask, val);
530}
531
532static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
533{
534 int ret;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900535 unsigned int val, state;
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100536 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900537 int rdev_id = rdev_get_id(rdev);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100538
Chanwoo Choi00e25732014-06-25 16:14:45 +0900539 /* Below LDO should be always on or does not support suspend mode. */
540 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900541 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900542 case S2MPS14X:
543 switch (rdev_id) {
544 case S2MPS14_LDO3:
545 return 0;
546 default:
547 state = S2MPS14_ENABLE_SUSPEND;
548 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900549 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900550 break;
551 case S2MPU02:
552 switch (rdev_id) {
553 case S2MPU02_LDO13:
554 case S2MPU02_LDO14:
555 case S2MPU02_LDO15:
556 case S2MPU02_LDO17:
557 case S2MPU02_BUCK7:
558 state = S2MPU02_DISABLE_SUSPEND;
559 break;
560 default:
561 state = S2MPU02_ENABLE_SUSPEND;
562 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900563 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900564 break;
565 default:
566 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900567 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100568
569 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
570 if (ret < 0)
571 return ret;
572
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900573 set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100574 /*
575 * Don't enable suspend mode if regulator is already disabled because
576 * this would effectively for a short time turn on the regulator after
577 * resuming.
578 * However we still want to toggle the suspend_state bit for regulator
579 * in case if it got enabled before suspending the system.
580 */
581 if (!(val & rdev->desc->enable_mask))
582 return 0;
583
584 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900585 rdev->desc->enable_mask, state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100586}
587
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200588static const struct regulator_ops s2mps14_reg_ops = {
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100589 .list_voltage = regulator_list_voltage_linear,
590 .map_voltage = regulator_map_voltage_linear,
591 .is_enabled = regulator_is_enabled_regmap,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100592 .enable = s2mps14_regulator_enable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100593 .disable = regulator_disable_regmap,
594 .get_voltage_sel = regulator_get_voltage_sel_regmap,
595 .set_voltage_sel = regulator_set_voltage_sel_regmap,
596 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100597 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100598};
599
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530600#define regulator_desc_s2mps14_ldo(num, min, step) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100601 .name = "LDO"#num, \
602 .id = S2MPS14_LDO##num, \
603 .ops = &s2mps14_reg_ops, \
604 .type = REGULATOR_VOLTAGE, \
605 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530606 .min_uV = min, \
607 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100608 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
609 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
610 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
611 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
612 .enable_mask = S2MPS14_ENABLE_MASK \
613}
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530614
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100615#define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100616 .name = "BUCK"#num, \
617 .id = S2MPS14_BUCK##num, \
618 .ops = &s2mps14_reg_ops, \
619 .type = REGULATOR_VOLTAGE, \
620 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530621 .min_uV = min, \
622 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100623 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100624 .linear_min_sel = min_sel, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100625 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
626 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
627 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
628 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
629 .enable_mask = S2MPS14_ENABLE_MASK \
630}
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100631
632static const struct regulator_desc s2mps14_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530633 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
634 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
635 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
636 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
637 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
638 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
639 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
640 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
641 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
642 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
643 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
644 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
645 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
646 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
647 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
648 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
649 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
650 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
651 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
652 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
653 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
654 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
655 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
656 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
657 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100658 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
659 S2MPS14_BUCK1235_START_SEL),
660 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
661 S2MPS14_BUCK1235_START_SEL),
662 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
663 S2MPS14_BUCK1235_START_SEL),
664 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
665 S2MPS14_BUCK4_START_SEL),
666 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
667 S2MPS14_BUCK1235_START_SEL),
Sangbeom Kimcb746852012-07-11 21:08:17 +0900668};
669
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200670static const struct regulator_ops s2mps15_reg_ldo_ops = {
Thomas Abraham51af2062015-11-20 16:07:52 +0530671 .list_voltage = regulator_list_voltage_linear_range,
672 .map_voltage = regulator_map_voltage_linear_range,
673 .is_enabled = regulator_is_enabled_regmap,
674 .enable = regulator_enable_regmap,
675 .disable = regulator_disable_regmap,
676 .get_voltage_sel = regulator_get_voltage_sel_regmap,
677 .set_voltage_sel = regulator_set_voltage_sel_regmap,
678};
679
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200680static const struct regulator_ops s2mps15_reg_buck_ops = {
Thomas Abraham51af2062015-11-20 16:07:52 +0530681 .list_voltage = regulator_list_voltage_linear_range,
682 .map_voltage = regulator_map_voltage_linear_range,
683 .is_enabled = regulator_is_enabled_regmap,
684 .enable = regulator_enable_regmap,
685 .disable = regulator_disable_regmap,
686 .get_voltage_sel = regulator_get_voltage_sel_regmap,
687 .set_voltage_sel = regulator_set_voltage_sel_regmap,
688 .set_voltage_time_sel = regulator_set_voltage_time_sel,
689};
690
691#define regulator_desc_s2mps15_ldo(num, range) { \
692 .name = "LDO"#num, \
693 .id = S2MPS15_LDO##num, \
694 .ops = &s2mps15_reg_ldo_ops, \
695 .type = REGULATOR_VOLTAGE, \
696 .owner = THIS_MODULE, \
697 .linear_ranges = range, \
698 .n_linear_ranges = ARRAY_SIZE(range), \
699 .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
700 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
701 .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
702 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
703 .enable_mask = S2MPS15_ENABLE_MASK \
704}
705
706#define regulator_desc_s2mps15_buck(num, range) { \
707 .name = "BUCK"#num, \
708 .id = S2MPS15_BUCK##num, \
709 .ops = &s2mps15_reg_buck_ops, \
710 .type = REGULATOR_VOLTAGE, \
711 .owner = THIS_MODULE, \
712 .linear_ranges = range, \
713 .n_linear_ranges = ARRAY_SIZE(range), \
714 .ramp_delay = 12500, \
715 .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
716 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
717 .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
718 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
719 .enable_mask = S2MPS15_ENABLE_MASK \
720}
721
722/* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
723static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
724 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
725};
726
727/* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
728static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
729 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
730};
731
732/* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
733static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
734 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
735};
736
737/* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
738static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
Alim Akhtar04c16b82016-07-12 11:26:43 +0530739 REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
Thomas Abraham51af2062015-11-20 16:07:52 +0530740};
741
742/* voltage range for s2mps15 LDO 1 */
743static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
744 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
745};
746
747/* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
748static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
Alim Akhtar04c16b82016-07-12 11:26:43 +0530749 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
Thomas Abraham51af2062015-11-20 16:07:52 +0530750};
751
752/* voltage range for s2mps15 BUCK 8, 9 and 10 */
753static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
Alim Akhtar04c16b82016-07-12 11:26:43 +0530754 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
Thomas Abraham51af2062015-11-20 16:07:52 +0530755};
756
757static const struct regulator_desc s2mps15_regulators[] = {
758 regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
759 regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
760 regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
761 regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
762 regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
763 regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
764 regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
765 regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
766 regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
767 regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
768 regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
769 regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
770 regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
771 regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
772 regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
773 regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
774 regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
775 regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
776 regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
777 regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
778 regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
779 regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
780 regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
781 regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
782 regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
783 regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
784 regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
785 regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
786 regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
787 regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
788 regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
789 regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
790 regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
791 regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
792 regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
793 regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
794 regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
795};
796
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200797static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
798 struct regulator_dev *rdev)
799{
800 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
801 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
802}
803
804static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200805 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
806{
Linus Walleij1c984942018-11-15 09:01:17 +0100807 struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200808 unsigned int i;
809 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
810 S2MPS14_LDO12 };
811
812 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
813 unsigned int reg = valid_regulators[i];
814
815 if (!rdata[reg].init_data || !rdata[reg].of_node)
816 continue;
817
Linus Walleij1c984942018-11-15 09:01:17 +0100818 gpio[reg] = devm_gpiod_get_from_of_node(&pdev->dev,
819 rdata[reg].of_node,
820 "samsung,ext-control-gpios",
821 0,
822 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
823 "s2mps11-regulator");
824 if (IS_ERR(gpio[reg])) {
825 dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
826 reg, rdata[reg].name);
827 continue;
828 }
829 if (gpio[reg])
830 dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
831 reg, rdata[reg].name);
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200832 }
833}
834
835static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +0900836 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
837 unsigned int rdev_num)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200838{
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200839 struct device_node *reg_np;
840
841 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
842 if (!reg_np) {
843 dev_err(&pdev->dev, "could not find regulators sub-node\n");
844 return -EINVAL;
845 }
846
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +0900847 of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900848 if (s2mps11->dev_type == S2MPS14X)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200849 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
850
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200851 of_node_put(reg_np);
852
853 return 0;
854}
855
Chanwoo Choi00e25732014-06-25 16:14:45 +0900856static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
857{
858 unsigned int ramp_val, ramp_shift, ramp_reg;
859
860 switch (rdev_get_id(rdev)) {
861 case S2MPU02_BUCK1:
862 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
863 break;
864 case S2MPU02_BUCK2:
865 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
866 break;
867 case S2MPU02_BUCK3:
868 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
869 break;
870 case S2MPU02_BUCK4:
871 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
872 break;
873 default:
874 return 0;
875 }
876 ramp_reg = S2MPU02_REG_RAMP1;
877 ramp_val = get_ramp_delay(ramp_delay);
878
879 return regmap_update_bits(rdev->regmap, ramp_reg,
880 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
881 ramp_val << ramp_shift);
882}
883
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200884static const struct regulator_ops s2mpu02_ldo_ops = {
Chanwoo Choi00e25732014-06-25 16:14:45 +0900885 .list_voltage = regulator_list_voltage_linear,
886 .map_voltage = regulator_map_voltage_linear,
887 .is_enabled = regulator_is_enabled_regmap,
888 .enable = s2mps14_regulator_enable,
889 .disable = regulator_disable_regmap,
890 .get_voltage_sel = regulator_get_voltage_sel_regmap,
891 .set_voltage_sel = regulator_set_voltage_sel_regmap,
892 .set_voltage_time_sel = regulator_set_voltage_time_sel,
893 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
894};
895
Krzysztof Kozlowski71b45402017-03-11 21:01:22 +0200896static const struct regulator_ops s2mpu02_buck_ops = {
Chanwoo Choi00e25732014-06-25 16:14:45 +0900897 .list_voltage = regulator_list_voltage_linear,
898 .map_voltage = regulator_map_voltage_linear,
899 .is_enabled = regulator_is_enabled_regmap,
900 .enable = s2mps14_regulator_enable,
901 .disable = regulator_disable_regmap,
902 .get_voltage_sel = regulator_get_voltage_sel_regmap,
903 .set_voltage_sel = regulator_set_voltage_sel_regmap,
904 .set_voltage_time_sel = regulator_set_voltage_time_sel,
905 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
906 .set_ramp_delay = s2mpu02_set_ramp_delay,
907};
908
909#define regulator_desc_s2mpu02_ldo1(num) { \
910 .name = "LDO"#num, \
911 .id = S2MPU02_LDO##num, \
912 .ops = &s2mpu02_ldo_ops, \
913 .type = REGULATOR_VOLTAGE, \
914 .owner = THIS_MODULE, \
915 .min_uV = S2MPU02_LDO_MIN_900MV, \
916 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
917 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
918 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
919 .vsel_reg = S2MPU02_REG_L1CTRL, \
920 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
921 .enable_reg = S2MPU02_REG_L1CTRL, \
922 .enable_mask = S2MPU02_ENABLE_MASK \
923}
924#define regulator_desc_s2mpu02_ldo2(num) { \
925 .name = "LDO"#num, \
926 .id = S2MPU02_LDO##num, \
927 .ops = &s2mpu02_ldo_ops, \
928 .type = REGULATOR_VOLTAGE, \
929 .owner = THIS_MODULE, \
930 .min_uV = S2MPU02_LDO_MIN_1050MV, \
931 .uV_step = S2MPU02_LDO_STEP_25MV, \
932 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
933 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
934 .vsel_reg = S2MPU02_REG_L2CTRL1, \
935 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
936 .enable_reg = S2MPU02_REG_L2CTRL1, \
937 .enable_mask = S2MPU02_ENABLE_MASK \
938}
939#define regulator_desc_s2mpu02_ldo3(num) { \
940 .name = "LDO"#num, \
941 .id = S2MPU02_LDO##num, \
942 .ops = &s2mpu02_ldo_ops, \
943 .type = REGULATOR_VOLTAGE, \
944 .owner = THIS_MODULE, \
945 .min_uV = S2MPU02_LDO_MIN_900MV, \
946 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
947 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
948 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
949 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
950 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
951 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
952 .enable_mask = S2MPU02_ENABLE_MASK \
953}
954#define regulator_desc_s2mpu02_ldo4(num) { \
955 .name = "LDO"#num, \
956 .id = S2MPU02_LDO##num, \
957 .ops = &s2mpu02_ldo_ops, \
958 .type = REGULATOR_VOLTAGE, \
959 .owner = THIS_MODULE, \
960 .min_uV = S2MPU02_LDO_MIN_1050MV, \
961 .uV_step = S2MPU02_LDO_STEP_25MV, \
962 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
963 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
964 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
965 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
966 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
967 .enable_mask = S2MPU02_ENABLE_MASK \
968}
969#define regulator_desc_s2mpu02_ldo5(num) { \
970 .name = "LDO"#num, \
971 .id = S2MPU02_LDO##num, \
972 .ops = &s2mpu02_ldo_ops, \
973 .type = REGULATOR_VOLTAGE, \
974 .owner = THIS_MODULE, \
975 .min_uV = S2MPU02_LDO_MIN_1600MV, \
976 .uV_step = S2MPU02_LDO_STEP_50MV, \
977 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
978 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
979 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
980 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
981 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
982 .enable_mask = S2MPU02_ENABLE_MASK \
983}
984
985#define regulator_desc_s2mpu02_buck1234(num) { \
986 .name = "BUCK"#num, \
987 .id = S2MPU02_BUCK##num, \
988 .ops = &s2mpu02_buck_ops, \
989 .type = REGULATOR_VOLTAGE, \
990 .owner = THIS_MODULE, \
991 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
992 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
993 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
994 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
995 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
996 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
997 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
998 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
999 .enable_mask = S2MPU02_ENABLE_MASK \
1000}
1001#define regulator_desc_s2mpu02_buck5(num) { \
1002 .name = "BUCK"#num, \
1003 .id = S2MPU02_BUCK##num, \
1004 .ops = &s2mpu02_ldo_ops, \
1005 .type = REGULATOR_VOLTAGE, \
1006 .owner = THIS_MODULE, \
1007 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
1008 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
1009 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1010 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
1011 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1012 .vsel_reg = S2MPU02_REG_B5CTRL2, \
1013 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1014 .enable_reg = S2MPU02_REG_B5CTRL1, \
1015 .enable_mask = S2MPU02_ENABLE_MASK \
1016}
1017#define regulator_desc_s2mpu02_buck6(num) { \
1018 .name = "BUCK"#num, \
1019 .id = S2MPU02_BUCK##num, \
1020 .ops = &s2mpu02_ldo_ops, \
1021 .type = REGULATOR_VOLTAGE, \
1022 .owner = THIS_MODULE, \
1023 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
1024 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
1025 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1026 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
1027 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1028 .vsel_reg = S2MPU02_REG_B6CTRL2, \
1029 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1030 .enable_reg = S2MPU02_REG_B6CTRL1, \
1031 .enable_mask = S2MPU02_ENABLE_MASK \
1032}
1033#define regulator_desc_s2mpu02_buck7(num) { \
1034 .name = "BUCK"#num, \
1035 .id = S2MPU02_BUCK##num, \
1036 .ops = &s2mpu02_ldo_ops, \
1037 .type = REGULATOR_VOLTAGE, \
1038 .owner = THIS_MODULE, \
1039 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
1040 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
1041 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1042 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
1043 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1044 .vsel_reg = S2MPU02_REG_B7CTRL2, \
1045 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1046 .enable_reg = S2MPU02_REG_B7CTRL1, \
1047 .enable_mask = S2MPU02_ENABLE_MASK \
1048}
1049
1050static const struct regulator_desc s2mpu02_regulators[] = {
1051 regulator_desc_s2mpu02_ldo1(1),
1052 regulator_desc_s2mpu02_ldo2(2),
1053 regulator_desc_s2mpu02_ldo4(3),
1054 regulator_desc_s2mpu02_ldo5(4),
1055 regulator_desc_s2mpu02_ldo4(5),
1056 regulator_desc_s2mpu02_ldo3(6),
1057 regulator_desc_s2mpu02_ldo3(7),
1058 regulator_desc_s2mpu02_ldo4(8),
1059 regulator_desc_s2mpu02_ldo5(9),
1060 regulator_desc_s2mpu02_ldo3(10),
1061 regulator_desc_s2mpu02_ldo4(11),
1062 regulator_desc_s2mpu02_ldo5(12),
1063 regulator_desc_s2mpu02_ldo5(13),
1064 regulator_desc_s2mpu02_ldo5(14),
1065 regulator_desc_s2mpu02_ldo5(15),
1066 regulator_desc_s2mpu02_ldo5(16),
1067 regulator_desc_s2mpu02_ldo4(17),
1068 regulator_desc_s2mpu02_ldo5(18),
1069 regulator_desc_s2mpu02_ldo3(19),
1070 regulator_desc_s2mpu02_ldo4(20),
1071 regulator_desc_s2mpu02_ldo5(21),
1072 regulator_desc_s2mpu02_ldo5(22),
1073 regulator_desc_s2mpu02_ldo5(23),
1074 regulator_desc_s2mpu02_ldo4(24),
1075 regulator_desc_s2mpu02_ldo5(25),
1076 regulator_desc_s2mpu02_ldo4(26),
1077 regulator_desc_s2mpu02_ldo5(27),
1078 regulator_desc_s2mpu02_ldo5(28),
1079 regulator_desc_s2mpu02_buck1234(1),
1080 regulator_desc_s2mpu02_buck1234(2),
1081 regulator_desc_s2mpu02_buck1234(3),
1082 regulator_desc_s2mpu02_buck1234(4),
1083 regulator_desc_s2mpu02_buck5(5),
1084 regulator_desc_s2mpu02_buck6(6),
1085 regulator_desc_s2mpu02_buck7(7),
1086};
1087
Bill Pembertona5023572012-11-19 13:22:22 -05001088static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +09001089{
1090 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001091 struct sec_platform_data *pdata = NULL;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001092 struct of_regulator_match *rdata = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001093 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +09001094 struct s2mps11_info *s2mps11;
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001095 unsigned int rdev_num = 0;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001096 int i, ret = 0;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001097 const struct regulator_desc *regulators;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001098
Sangbeom Kimcb746852012-07-11 21:08:17 +09001099 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1100 GFP_KERNEL);
1101 if (!s2mps11)
1102 return -ENOMEM;
1103
Chanwoo Choi00e25732014-06-25 16:14:45 +09001104 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
1105 switch (s2mps11->dev_type) {
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001106 case S2MPS11X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001107 rdev_num = ARRAY_SIZE(s2mps11_regulators);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001108 regulators = s2mps11_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001109 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001110 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +09001111 case S2MPS13X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001112 rdev_num = ARRAY_SIZE(s2mps13_regulators);
Chanwoo Choi76b98402014-11-18 17:59:40 +09001113 regulators = s2mps13_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001114 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
Chanwoo Choi76b98402014-11-18 17:59:40 +09001115 break;
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001116 case S2MPS14X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001117 rdev_num = ARRAY_SIZE(s2mps14_regulators);
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001118 regulators = s2mps14_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001119 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001120 break;
Thomas Abraham51af2062015-11-20 16:07:52 +05301121 case S2MPS15X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001122 rdev_num = ARRAY_SIZE(s2mps15_regulators);
Thomas Abraham51af2062015-11-20 16:07:52 +05301123 regulators = s2mps15_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001124 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
Thomas Abraham51af2062015-11-20 16:07:52 +05301125 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +09001126 case S2MPU02:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001127 rdev_num = ARRAY_SIZE(s2mpu02_regulators);
Chanwoo Choi00e25732014-06-25 16:14:45 +09001128 regulators = s2mpu02_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001129 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
Chanwoo Choi00e25732014-06-25 16:14:45 +09001130 break;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001131 default:
Chanwoo Choi00e25732014-06-25 16:14:45 +09001132 dev_err(&pdev->dev, "Invalid device type: %u\n",
1133 s2mps11->dev_type);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001134 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +09001135 }
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001136
Marek Szyprowskid7c7fc42018-11-20 13:38:44 +01001137 s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
1138 sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
Linus Walleij1c984942018-11-15 09:01:17 +01001139 if (!s2mps11->ext_control_gpiod)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001140 return -ENOMEM;
1141
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301142 if (!iodev->dev->of_node) {
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001143 if (iodev->pdata) {
1144 pdata = iodev->pdata;
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301145 goto common_reg;
1146 } else {
1147 dev_err(pdev->dev.parent,
1148 "Platform data or DT node not supplied\n");
1149 return -ENODEV;
1150 }
1151 }
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301152
Kees Cook6396bb22018-06-12 14:03:40 -07001153 rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001154 if (!rdata)
1155 return -ENOMEM;
1156
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001157 for (i = 0; i < rdev_num; i++)
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301158 rdata[i].name = regulators[i].name;
1159
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001160 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001161 if (ret)
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001162 goto out;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301163
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301164common_reg:
1165 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001166
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301167 config.dev = &pdev->dev;
Krzysztof Kozlowski1b1ccee2013-12-11 15:07:43 +01001168 config.regmap = iodev->regmap_pmic;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301169 config.driver_data = s2mps11;
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001170 for (i = 0; i < rdev_num; i++) {
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001171 struct regulator_dev *regulator;
1172
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001173 if (pdata) {
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301174 config.init_data = pdata->regulators[i].initdata;
Krzysztof Kozlowski54820f52014-01-30 14:51:19 +01001175 config.of_node = pdata->regulators[i].reg_node;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301176 } else {
1177 config.init_data = rdata[i].init_data;
1178 config.of_node = rdata[i].of_node;
1179 }
Linus Walleij1c984942018-11-15 09:01:17 +01001180 config.ena_gpiod = s2mps11->ext_control_gpiod[i];
Linus Walleij2b96edb2018-12-06 13:43:51 +01001181 /*
1182 * Hand the GPIO descriptor management over to the regulator
1183 * core, remove it from devres management.
1184 */
1185 if (config.ena_gpiod)
1186 devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001187 regulator = devm_regulator_register(&pdev->dev,
Sachin Kamatd55cd792013-09-04 12:12:15 +05301188 &regulators[i], &config);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001189 if (IS_ERR(regulator)) {
1190 ret = PTR_ERR(regulator);
Axel Lin232b2502012-07-12 09:37:37 +08001191 dev_err(&pdev->dev, "regulator init failed for %d\n",
1192 i);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001193 goto out;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001194 }
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001195
Linus Walleij1c984942018-11-15 09:01:17 +01001196 if (s2mps11->ext_control_gpiod[i]) {
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001197 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1198 regulator);
1199 if (ret < 0) {
1200 dev_err(&pdev->dev,
1201 "failed to enable GPIO control over %s: %d\n",
1202 regulator->desc->name, ret);
1203 goto out;
1204 }
1205 }
Sangbeom Kimcb746852012-07-11 21:08:17 +09001206 }
1207
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001208out:
1209 kfree(rdata);
1210
1211 return ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001212}
1213
1214static const struct platform_device_id s2mps11_pmic_id[] = {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301215 { "s2mps11-regulator", S2MPS11X},
1216 { "s2mps13-regulator", S2MPS13X},
1217 { "s2mps14-regulator", S2MPS14X},
Thomas Abraham51af2062015-11-20 16:07:52 +05301218 { "s2mps15-regulator", S2MPS15X},
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301219 { "s2mpu02-regulator", S2MPU02},
Sangbeom Kimcb746852012-07-11 21:08:17 +09001220 { },
1221};
1222MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1223
1224static struct platform_driver s2mps11_pmic_driver = {
1225 .driver = {
1226 .name = "s2mps11-pmic",
Sangbeom Kimcb746852012-07-11 21:08:17 +09001227 },
1228 .probe = s2mps11_pmic_probe,
Sangbeom Kimcb746852012-07-11 21:08:17 +09001229 .id_table = s2mps11_pmic_id,
1230};
1231
Javier Martinez Canillas5ab3c492016-04-06 09:49:46 -04001232module_platform_driver(s2mps11_pmic_driver);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001233
1234/* Module information */
1235MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Thomas Abraham51af2062015-11-20 16:07:52 +05301236MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
Sangbeom Kimcb746852012-07-11 21:08:17 +09001237MODULE_LICENSE("GPL");