Commit | Line | Data |
---|---|---|
cb74685e SK |
1 | /* |
2 | * s2mps11.c | |
3 | * | |
15f77300 | 4 | * Copyright (c) 2012-2014 Samsung Electronics Co., Ltd |
cb74685e SK |
5 | * http://www.samsung.com |
6 | * | |
15f77300 KK |
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. | |
cb74685e SK |
16 | * |
17 | */ | |
18 | ||
19 | #include <linux/bug.h> | |
cb74685e SK |
20 | #include <linux/err.h> |
21 | #include <linux/gpio.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/module.h> | |
a50c6b32 | 24 | #include <linux/of.h> |
939c0277 | 25 | #include <linux/regmap.h> |
cb74685e SK |
26 | #include <linux/platform_device.h> |
27 | #include <linux/regulator/driver.h> | |
28 | #include <linux/regulator/machine.h> | |
a50c6b32 | 29 | #include <linux/regulator/of_regulator.h> |
97f53d71 | 30 | #include <linux/of_gpio.h> |
cb74685e SK |
31 | #include <linux/mfd/samsung/core.h> |
32 | #include <linux/mfd/samsung/s2mps11.h> | |
76b9840b | 33 | #include <linux/mfd/samsung/s2mps13.h> |
15f77300 | 34 | #include <linux/mfd/samsung/s2mps14.h> |
51af2067 | 35 | #include <linux/mfd/samsung/s2mps15.h> |
00e2573d | 36 | #include <linux/mfd/samsung/s2mpu02.h> |
a50c6b32 | 37 | |
32c848e3 KK |
38 | /* The highest number of possible regulators for supported devices. */ |
39 | #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX | |
cb74685e | 40 | struct s2mps11_info { |
cb74685e SK |
41 | int ramp_delay2; |
42 | int ramp_delay34; | |
43 | int ramp_delay5; | |
44 | int ramp_delay16; | |
45 | int ramp_delay7810; | |
46 | int ramp_delay9; | |
00e2573d CC |
47 | |
48 | enum sec_device_type dev_type; | |
49 | ||
05be09bb | 50 | /* |
76b9840b CC |
51 | * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether |
52 | * the suspend mode was enabled. | |
05be09bb | 53 | */ |
32c848e3 | 54 | DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX); |
00e2573d | 55 | |
7ddec641 KK |
56 | /* |
57 | * Array (size: number of regulators) with GPIO-s for external | |
58 | * sleep control. | |
59 | */ | |
97f53d71 | 60 | int *ext_control_gpio; |
cb74685e SK |
61 | }; |
62 | ||
63 | static int get_ramp_delay(int ramp_delay) | |
64 | { | |
65 | unsigned char cnt = 0; | |
66 | ||
90068348 | 67 | ramp_delay /= 6250; |
cb74685e SK |
68 | |
69 | while (true) { | |
70 | ramp_delay = ramp_delay >> 1; | |
71 | if (ramp_delay == 0) | |
72 | break; | |
73 | cnt++; | |
74 | } | |
f8f1d48b AL |
75 | |
76 | if (cnt > 3) | |
77 | cnt = 3; | |
78 | ||
cb74685e SK |
79 | return cnt; |
80 | } | |
81 | ||
1e1598ed YSB |
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 | ||
d55efa4d | 90 | switch (rdev_get_id(rdev)) { |
1e1598ed | 91 | case S2MPS11_BUCK2: |
1e1598ed YSB |
92 | ramp_delay = s2mps11->ramp_delay2; |
93 | break; | |
94 | case S2MPS11_BUCK3: | |
1e1598ed | 95 | case S2MPS11_BUCK4: |
1e1598ed YSB |
96 | ramp_delay = s2mps11->ramp_delay34; |
97 | break; | |
98 | case S2MPS11_BUCK5: | |
99 | ramp_delay = s2mps11->ramp_delay5; | |
100 | break; | |
101 | case S2MPS11_BUCK6: | |
1e1598ed YSB |
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 | ||
939c0277 YSB |
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 | ||
d55efa4d | 130 | switch (rdev_get_id(rdev)) { |
939c0277 YSB |
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 | ||
b203e0df KK |
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 | } | |
939c0277 YSB |
229 | } |
230 | ||
231 | ramp_val = get_ramp_delay(ramp_delay); | |
232 | ||
f8f1d48b AL |
233 | return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, |
234 | ramp_val << ramp_shift); | |
939c0277 YSB |
235 | |
236 | ramp_disable: | |
80853304 AL |
237 | return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
238 | 1 << enable_shift, 0); | |
939c0277 YSB |
239 | } |
240 | ||
cb74685e SK |
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, | |
1e1598ed | 260 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, |
939c0277 | 261 | .set_ramp_delay = s2mps11_set_ramp_delay, |
cb74685e SK |
262 | }; |
263 | ||
5a867cf2 | 264 | #define regulator_desc_s2mps11_ldo(num, step) { \ |
cb74685e SK |
265 | .name = "LDO"#num, \ |
266 | .id = S2MPS11_LDO##num, \ | |
267 | .ops = &s2mps11_ldo_ops, \ | |
268 | .type = REGULATOR_VOLTAGE, \ | |
269 | .owner = THIS_MODULE, \ | |
0e4f4178 | 270 | .min_uV = MIN_800_MV, \ |
5a867cf2 | 271 | .uV_step = step, \ |
cb74685e SK |
272 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
273 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ | |
2693fcab | 274 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
cb74685e SK |
275 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
276 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
277 | } | |
278 | ||
15f77300 | 279 | #define regulator_desc_s2mps11_buck1_4(num) { \ |
cb74685e SK |
280 | .name = "BUCK"#num, \ |
281 | .id = S2MPS11_BUCK##num, \ | |
282 | .ops = &s2mps11_buck_ops, \ | |
283 | .type = REGULATOR_VOLTAGE, \ | |
284 | .owner = THIS_MODULE, \ | |
0e4f4178 ADK |
285 | .min_uV = MIN_600_MV, \ |
286 | .uV_step = STEP_6_25_MV, \ | |
cb74685e | 287 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
90068348 | 288 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 289 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ |
2693fcab | 290 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
291 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ |
292 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
293 | } | |
294 | ||
15f77300 | 295 | #define regulator_desc_s2mps11_buck5 { \ |
cb74685e SK |
296 | .name = "BUCK5", \ |
297 | .id = S2MPS11_BUCK5, \ | |
298 | .ops = &s2mps11_buck_ops, \ | |
299 | .type = REGULATOR_VOLTAGE, \ | |
300 | .owner = THIS_MODULE, \ | |
0e4f4178 ADK |
301 | .min_uV = MIN_600_MV, \ |
302 | .uV_step = STEP_6_25_MV, \ | |
cb74685e | 303 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
90068348 | 304 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 305 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ |
2693fcab | 306 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
307 | .enable_reg = S2MPS11_REG_B5CTRL1, \ |
308 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
309 | } | |
310 | ||
3b672623 | 311 | #define regulator_desc_s2mps11_buck67810(num, min, step) { \ |
cb74685e SK |
312 | .name = "BUCK"#num, \ |
313 | .id = S2MPS11_BUCK##num, \ | |
314 | .ops = &s2mps11_buck_ops, \ | |
315 | .type = REGULATOR_VOLTAGE, \ | |
316 | .owner = THIS_MODULE, \ | |
5a867cf2 ADK |
317 | .min_uV = min, \ |
318 | .uV_step = step, \ | |
cb74685e | 319 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
90068348 | 320 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 321 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ |
2693fcab | 322 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
323 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ |
324 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
325 | } | |
326 | ||
3b672623 KK |
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 | ||
0f4cc282 | 343 | static const struct regulator_desc s2mps11_regulators[] = { |
5a867cf2 ADK |
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), | |
15f77300 KK |
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, | |
3b672623 KK |
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), | |
15f77300 KK |
392 | }; |
393 | ||
76b9840b CC |
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 | ||
ad26aa6c JL |
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 | ||
76b9840b CC |
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), | |
ad26aa6c JL |
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), | |
76b9840b CC |
514 | }; |
515 | ||
05be09bb KK |
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 | ||
00e2573d | 521 | switch (s2mps11->dev_type) { |
76b9840b | 522 | case S2MPS13X: |
00e2573d | 523 | case S2MPS14X: |
32c848e3 | 524 | if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state)) |
00e2573d CC |
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: | |
32c848e3 | 532 | if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state)) |
00e2573d CC |
533 | val = S2MPU02_ENABLE_SUSPEND; |
534 | else | |
535 | val = rdev->desc->enable_mask; | |
536 | break; | |
537 | default: | |
538 | return -EINVAL; | |
7cf225b9 | 539 | } |
05be09bb KK |
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; | |
00e2573d | 548 | unsigned int val, state; |
05be09bb | 549 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
00e2573d | 550 | int rdev_id = rdev_get_id(rdev); |
05be09bb | 551 | |
00e2573d CC |
552 | /* Below LDO should be always on or does not support suspend mode. */ |
553 | switch (s2mps11->dev_type) { | |
76b9840b | 554 | case S2MPS13X: |
00e2573d CC |
555 | case S2MPS14X: |
556 | switch (rdev_id) { | |
557 | case S2MPS14_LDO3: | |
558 | return 0; | |
559 | default: | |
560 | state = S2MPS14_ENABLE_SUSPEND; | |
561 | break; | |
7cf225b9 | 562 | } |
00e2573d CC |
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; | |
7cf225b9 | 576 | } |
00e2573d CC |
577 | break; |
578 | default: | |
579 | return -EINVAL; | |
7cf225b9 | 580 | } |
05be09bb KK |
581 | |
582 | ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); | |
583 | if (ret < 0) | |
584 | return ret; | |
585 | ||
32c848e3 | 586 | set_bit(rdev_get_id(rdev), s2mps11->suspend_state); |
05be09bb KK |
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, | |
00e2573d | 598 | rdev->desc->enable_mask, state); |
05be09bb KK |
599 | } |
600 | ||
15f77300 KK |
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, | |
05be09bb | 605 | .enable = s2mps14_regulator_enable, |
15f77300 KK |
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, | |
05be09bb | 610 | .set_suspend_disable = s2mps14_regulator_set_suspend_disable, |
15f77300 KK |
611 | }; |
612 | ||
5a867cf2 | 613 | #define regulator_desc_s2mps14_ldo(num, min, step) { \ |
15f77300 KK |
614 | .name = "LDO"#num, \ |
615 | .id = S2MPS14_LDO##num, \ | |
616 | .ops = &s2mps14_reg_ops, \ | |
617 | .type = REGULATOR_VOLTAGE, \ | |
618 | .owner = THIS_MODULE, \ | |
5a867cf2 ADK |
619 | .min_uV = min, \ |
620 | .uV_step = step, \ | |
15f77300 KK |
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 | } | |
5a867cf2 | 627 | |
1222d8fe | 628 | #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \ |
15f77300 KK |
629 | .name = "BUCK"#num, \ |
630 | .id = S2MPS14_BUCK##num, \ | |
631 | .ops = &s2mps14_reg_ops, \ | |
632 | .type = REGULATOR_VOLTAGE, \ | |
633 | .owner = THIS_MODULE, \ | |
5a867cf2 ADK |
634 | .min_uV = min, \ |
635 | .uV_step = step, \ | |
15f77300 | 636 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
1222d8fe | 637 | .linear_min_sel = min_sel, \ |
15f77300 KK |
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 | } | |
15f77300 KK |
644 | |
645 | static const struct regulator_desc s2mps14_regulators[] = { | |
5a867cf2 ADK |
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), | |
1222d8fe KK |
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), | |
cb74685e SK |
681 | }; |
682 | ||
51af2067 TA |
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 | ||
97f53d71 KK |
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, | |
01170383 | 818 | struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) |
97f53d71 KK |
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); | |
de5d0563 | 833 | if (gpio_is_valid(gpio[reg])) |
97f53d71 KK |
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, | |
7ddec641 KK |
840 | struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, |
841 | unsigned int rdev_num) | |
01170383 KK |
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 | ||
7ddec641 | 851 | of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num); |
00e2573d | 852 | if (s2mps11->dev_type == S2MPS14X) |
97f53d71 KK |
853 | s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); |
854 | ||
01170383 KK |
855 | of_node_put(reg_np); |
856 | ||
857 | return 0; | |
858 | } | |
859 | ||
00e2573d CC |
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 | ||
a5023574 | 1092 | static int s2mps11_pmic_probe(struct platform_device *pdev) |
cb74685e SK |
1093 | { |
1094 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); | |
01170383 | 1095 | struct sec_platform_data *pdata = NULL; |
3e80f95b | 1096 | struct of_regulator_match *rdata = NULL; |
cb74685e | 1097 | struct regulator_config config = { }; |
cb74685e | 1098 | struct s2mps11_info *s2mps11; |
7ddec641 | 1099 | unsigned int rdev_num = 0; |
3e80f95b | 1100 | int i, ret = 0; |
0f4cc282 | 1101 | const struct regulator_desc *regulators; |
cb74685e | 1102 | |
cb74685e SK |
1103 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), |
1104 | GFP_KERNEL); | |
1105 | if (!s2mps11) | |
1106 | return -ENOMEM; | |
1107 | ||
00e2573d CC |
1108 | s2mps11->dev_type = platform_get_device_id(pdev)->driver_data; |
1109 | switch (s2mps11->dev_type) { | |
0f4cc282 | 1110 | case S2MPS11X: |
7ddec641 | 1111 | rdev_num = ARRAY_SIZE(s2mps11_regulators); |
0f4cc282 | 1112 | regulators = s2mps11_regulators; |
297eaaa6 | 1113 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators)); |
0f4cc282 | 1114 | break; |
76b9840b | 1115 | case S2MPS13X: |
7ddec641 | 1116 | rdev_num = ARRAY_SIZE(s2mps13_regulators); |
76b9840b | 1117 | regulators = s2mps13_regulators; |
297eaaa6 | 1118 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators)); |
76b9840b | 1119 | break; |
15f77300 | 1120 | case S2MPS14X: |
7ddec641 | 1121 | rdev_num = ARRAY_SIZE(s2mps14_regulators); |
15f77300 | 1122 | regulators = s2mps14_regulators; |
297eaaa6 | 1123 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators)); |
15f77300 | 1124 | break; |
51af2067 | 1125 | case S2MPS15X: |
7ddec641 | 1126 | rdev_num = ARRAY_SIZE(s2mps15_regulators); |
51af2067 | 1127 | regulators = s2mps15_regulators; |
297eaaa6 | 1128 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators)); |
51af2067 | 1129 | break; |
00e2573d | 1130 | case S2MPU02: |
7ddec641 | 1131 | rdev_num = ARRAY_SIZE(s2mpu02_regulators); |
00e2573d | 1132 | regulators = s2mpu02_regulators; |
297eaaa6 | 1133 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators)); |
00e2573d | 1134 | break; |
0f4cc282 | 1135 | default: |
00e2573d CC |
1136 | dev_err(&pdev->dev, "Invalid device type: %u\n", |
1137 | s2mps11->dev_type); | |
0f4cc282 | 1138 | return -EINVAL; |
7cf225b9 | 1139 | } |
3e80f95b | 1140 | |
80e82ac2 | 1141 | s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev, |
7ddec641 | 1142 | sizeof(*s2mps11->ext_control_gpio) * rdev_num, |
97f53d71 KK |
1143 | GFP_KERNEL); |
1144 | if (!s2mps11->ext_control_gpio) | |
1145 | return -ENOMEM; | |
de5d0563 KK |
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 | */ | |
7ddec641 | 1150 | for (i = 0; i < rdev_num; i++) |
de5d0563 | 1151 | s2mps11->ext_control_gpio[i] = -EINVAL; |
97f53d71 | 1152 | |
6c683c92 | 1153 | if (!iodev->dev->of_node) { |
01170383 KK |
1154 | if (iodev->pdata) { |
1155 | pdata = iodev->pdata; | |
6c683c92 YSB |
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 | } | |
a50c6b32 | 1163 | |
7ddec641 | 1164 | rdata = kzalloc(sizeof(*rdata) * rdev_num, GFP_KERNEL); |
3e80f95b KK |
1165 | if (!rdata) |
1166 | return -ENOMEM; | |
1167 | ||
7ddec641 | 1168 | for (i = 0; i < rdev_num; i++) |
a50c6b32 YSB |
1169 | rdata[i].name = regulators[i].name; |
1170 | ||
7ddec641 | 1171 | ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num); |
01170383 | 1172 | if (ret) |
3e80f95b | 1173 | goto out; |
a50c6b32 | 1174 | |
a50c6b32 YSB |
1175 | common_reg: |
1176 | platform_set_drvdata(pdev, s2mps11); | |
cb74685e | 1177 | |
a50c6b32 | 1178 | config.dev = &pdev->dev; |
1b1ccee1 | 1179 | config.regmap = iodev->regmap_pmic; |
a50c6b32 | 1180 | config.driver_data = s2mps11; |
de5d0563 | 1181 | config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; |
1de3821a | 1182 | config.ena_gpio_initialized = true; |
7ddec641 | 1183 | for (i = 0; i < rdev_num; i++) { |
31195252 KK |
1184 | struct regulator_dev *regulator; |
1185 | ||
01170383 | 1186 | if (pdata) { |
a50c6b32 | 1187 | config.init_data = pdata->regulators[i].initdata; |
54820f58 | 1188 | config.of_node = pdata->regulators[i].reg_node; |
a50c6b32 YSB |
1189 | } else { |
1190 | config.init_data = rdata[i].init_data; | |
1191 | config.of_node = rdata[i].of_node; | |
1192 | } | |
de5d0563 | 1193 | config.ena_gpio = s2mps11->ext_control_gpio[i]; |
97f53d71 | 1194 | |
31195252 | 1195 | regulator = devm_regulator_register(&pdev->dev, |
d55cd794 | 1196 | ®ulators[i], &config); |
31195252 KK |
1197 | if (IS_ERR(regulator)) { |
1198 | ret = PTR_ERR(regulator); | |
232b2504 AL |
1199 | dev_err(&pdev->dev, "regulator init failed for %d\n", |
1200 | i); | |
3e80f95b | 1201 | goto out; |
cb74685e | 1202 | } |
97f53d71 | 1203 | |
de5d0563 | 1204 | if (gpio_is_valid(s2mps11->ext_control_gpio[i])) { |
97f53d71 KK |
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 | } | |
cb74685e SK |
1214 | } |
1215 | ||
3e80f95b KK |
1216 | out: |
1217 | kfree(rdata); | |
1218 | ||
1219 | return ret; | |
cb74685e SK |
1220 | } |
1221 | ||
1222 | static const struct platform_device_id s2mps11_pmic_id[] = { | |
2fadbbf0 AA |
1223 | { "s2mps11-regulator", S2MPS11X}, |
1224 | { "s2mps13-regulator", S2MPS13X}, | |
1225 | { "s2mps14-regulator", S2MPS14X}, | |
51af2067 | 1226 | { "s2mps15-regulator", S2MPS15X}, |
2fadbbf0 | 1227 | { "s2mpu02-regulator", S2MPU02}, |
cb74685e SK |
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", | |
cb74685e SK |
1235 | }, |
1236 | .probe = s2mps11_pmic_probe, | |
cb74685e SK |
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>"); | |
51af2067 | 1254 | MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver"); |
cb74685e | 1255 | MODULE_LICENSE("GPL"); |