blob: b16c53a8272f84e4920fd46883f4ae6eb148405a [file] [log] [blame]
Sangbeom Kimcb746852012-07-11 21:08:17 +09001/*
2 * s2mps11.c
3 *
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01004 * Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
Sangbeom Kimcb746852012-07-11 21:08:17 +09005 * http://www.samsung.com
6 *
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01007 * 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.
Sangbeom Kimcb746852012-07-11 21:08:17 +090016 *
17 */
18
19#include <linux/bug.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090020#include <linux/err.h>
21#include <linux/gpio.h>
22#include <linux/slab.h>
23#include <linux/module.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053024#include <linux/of.h>
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +053025#include <linux/regmap.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090026#include <linux/platform_device.h>
27#include <linux/regulator/driver.h>
28#include <linux/regulator/machine.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053029#include <linux/regulator/of_regulator.h>
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +020030#include <linux/of_gpio.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090031#include <linux/mfd/samsung/core.h>
32#include <linux/mfd/samsung/s2mps11.h>
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +010033#include <linux/mfd/samsung/s2mps14.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090034#include <linux/mfd/samsung/s2mpu02.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053035
Sangbeom Kimcb746852012-07-11 21:08:17 +090036struct s2mps11_info {
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +010037 unsigned int rdev_num;
Sangbeom Kimcb746852012-07-11 21:08:17 +090038 int ramp_delay2;
39 int ramp_delay34;
40 int ramp_delay5;
41 int ramp_delay16;
42 int ramp_delay7810;
43 int ramp_delay9;
Chanwoo Choi00e25732014-06-25 16:14:45 +090044
45 enum sec_device_type dev_type;
46
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010047 /*
Chanwoo Choi00e25732014-06-25 16:14:45 +090048 * One bit for each S2MPS14/S2MPU02 regulator whether the suspend mode
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010049 * was enabled.
50 */
Chanwoo Choi00e25732014-06-25 16:14:45 +090051 unsigned long long s2mps14_suspend_state:35;
52
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +020053 /* Array of size rdev_num with GPIO-s for external sleep control */
54 int *ext_control_gpio;
Sangbeom Kimcb746852012-07-11 21:08:17 +090055};
56
57static int get_ramp_delay(int ramp_delay)
58{
59 unsigned char cnt = 0;
60
Yadwinder Singh Brar90068342013-06-24 16:50:55 +053061 ramp_delay /= 6250;
Sangbeom Kimcb746852012-07-11 21:08:17 +090062
63 while (true) {
64 ramp_delay = ramp_delay >> 1;
65 if (ramp_delay == 0)
66 break;
67 cnt++;
68 }
Axel Linf8f1d482013-08-05 14:08:37 +080069
70 if (cnt > 3)
71 cnt = 3;
72
Sangbeom Kimcb746852012-07-11 21:08:17 +090073 return cnt;
74}
75
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053076static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
77 unsigned int old_selector,
78 unsigned int new_selector)
79{
80 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
81 unsigned int ramp_delay = 0;
82 int old_volt, new_volt;
83
Thiago Farinad55efa42014-01-26 21:57:12 -020084 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053085 case S2MPS11_BUCK2:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053086 ramp_delay = s2mps11->ramp_delay2;
87 break;
88 case S2MPS11_BUCK3:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053089 case S2MPS11_BUCK4:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053090 ramp_delay = s2mps11->ramp_delay34;
91 break;
92 case S2MPS11_BUCK5:
93 ramp_delay = s2mps11->ramp_delay5;
94 break;
95 case S2MPS11_BUCK6:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053096 case S2MPS11_BUCK1:
97 ramp_delay = s2mps11->ramp_delay16;
98 break;
99 case S2MPS11_BUCK7:
100 case S2MPS11_BUCK8:
101 case S2MPS11_BUCK10:
102 ramp_delay = s2mps11->ramp_delay7810;
103 break;
104 case S2MPS11_BUCK9:
105 ramp_delay = s2mps11->ramp_delay9;
106 }
107
108 if (ramp_delay == 0)
109 ramp_delay = rdev->desc->ramp_delay;
110
111 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
112 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
113
114 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
115}
116
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530117static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
118{
119 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
120 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
121 unsigned int ramp_enable = 1, enable_shift = 0;
122 int ret;
123
Thiago Farinad55efa42014-01-26 21:57:12 -0200124 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530125 case S2MPS11_BUCK1:
126 if (ramp_delay > s2mps11->ramp_delay16)
127 s2mps11->ramp_delay16 = ramp_delay;
128 else
129 ramp_delay = s2mps11->ramp_delay16;
130
131 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
132 break;
133 case S2MPS11_BUCK2:
134 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
135 if (!ramp_delay) {
136 ramp_enable = 0;
137 break;
138 }
139
140 s2mps11->ramp_delay2 = ramp_delay;
141 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
142 ramp_reg = S2MPS11_REG_RAMP;
143 break;
144 case S2MPS11_BUCK3:
145 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
146 if (!ramp_delay) {
147 ramp_enable = 0;
148 break;
149 }
150
151 if (ramp_delay > s2mps11->ramp_delay34)
152 s2mps11->ramp_delay34 = ramp_delay;
153 else
154 ramp_delay = s2mps11->ramp_delay34;
155
156 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
157 ramp_reg = S2MPS11_REG_RAMP;
158 break;
159 case S2MPS11_BUCK4:
160 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
161 if (!ramp_delay) {
162 ramp_enable = 0;
163 break;
164 }
165
166 if (ramp_delay > s2mps11->ramp_delay34)
167 s2mps11->ramp_delay34 = ramp_delay;
168 else
169 ramp_delay = s2mps11->ramp_delay34;
170
171 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
172 ramp_reg = S2MPS11_REG_RAMP;
173 break;
174 case S2MPS11_BUCK5:
175 s2mps11->ramp_delay5 = ramp_delay;
176 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
177 break;
178 case S2MPS11_BUCK6:
179 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
180 if (!ramp_delay) {
181 ramp_enable = 0;
182 break;
183 }
184
185 if (ramp_delay > s2mps11->ramp_delay16)
186 s2mps11->ramp_delay16 = ramp_delay;
187 else
188 ramp_delay = s2mps11->ramp_delay16;
189
190 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
191 break;
192 case S2MPS11_BUCK7:
193 case S2MPS11_BUCK8:
194 case S2MPS11_BUCK10:
195 if (ramp_delay > s2mps11->ramp_delay7810)
196 s2mps11->ramp_delay7810 = ramp_delay;
197 else
198 ramp_delay = s2mps11->ramp_delay7810;
199
200 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
201 break;
202 case S2MPS11_BUCK9:
203 s2mps11->ramp_delay9 = ramp_delay;
204 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
205 break;
206 default:
207 return 0;
208 }
209
210 if (!ramp_enable)
211 goto ramp_disable;
212
Krzysztof Kozlowskib203e0d2014-05-06 08:37:36 +0200213 /* Ramp delay can be enabled/disabled only for buck[2346] */
214 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
215 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
216 rdev_get_id(rdev) == S2MPS11_BUCK6) {
217 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
218 1 << enable_shift, 1 << enable_shift);
219 if (ret) {
220 dev_err(&rdev->dev, "failed to enable ramp rate\n");
221 return ret;
222 }
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530223 }
224
225 ramp_val = get_ramp_delay(ramp_delay);
226
Axel Linf8f1d482013-08-05 14:08:37 +0800227 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
228 ramp_val << ramp_shift);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530229
230ramp_disable:
Axel Lin80853302013-08-03 17:10:42 +0800231 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
232 1 << enable_shift, 0);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530233}
234
Sangbeom Kimcb746852012-07-11 21:08:17 +0900235static struct regulator_ops s2mps11_ldo_ops = {
236 .list_voltage = regulator_list_voltage_linear,
237 .map_voltage = regulator_map_voltage_linear,
238 .is_enabled = regulator_is_enabled_regmap,
239 .enable = regulator_enable_regmap,
240 .disable = regulator_disable_regmap,
241 .get_voltage_sel = regulator_get_voltage_sel_regmap,
242 .set_voltage_sel = regulator_set_voltage_sel_regmap,
243 .set_voltage_time_sel = regulator_set_voltage_time_sel,
244};
245
246static struct regulator_ops s2mps11_buck_ops = {
247 .list_voltage = regulator_list_voltage_linear,
248 .map_voltage = regulator_map_voltage_linear,
249 .is_enabled = regulator_is_enabled_regmap,
250 .enable = regulator_enable_regmap,
251 .disable = regulator_disable_regmap,
252 .get_voltage_sel = regulator_get_voltage_sel_regmap,
253 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +0530254 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530255 .set_ramp_delay = s2mps11_set_ramp_delay,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900256};
257
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100258#define regulator_desc_s2mps11_ldo1(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900259 .name = "LDO"#num, \
260 .id = S2MPS11_LDO##num, \
261 .ops = &s2mps11_ldo_ops, \
262 .type = REGULATOR_VOLTAGE, \
263 .owner = THIS_MODULE, \
264 .min_uV = S2MPS11_LDO_MIN, \
265 .uV_step = S2MPS11_LDO_STEP1, \
266 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
267 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800268 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900269 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
270 .enable_mask = S2MPS11_ENABLE_MASK \
271}
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100272#define regulator_desc_s2mps11_ldo2(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900273 .name = "LDO"#num, \
274 .id = S2MPS11_LDO##num, \
275 .ops = &s2mps11_ldo_ops, \
276 .type = REGULATOR_VOLTAGE, \
277 .owner = THIS_MODULE, \
278 .min_uV = S2MPS11_LDO_MIN, \
279 .uV_step = S2MPS11_LDO_STEP2, \
280 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
281 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800282 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900283 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
284 .enable_mask = S2MPS11_ENABLE_MASK \
285}
286
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100287#define regulator_desc_s2mps11_buck1_4(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900288 .name = "BUCK"#num, \
289 .id = S2MPS11_BUCK##num, \
290 .ops = &s2mps11_buck_ops, \
291 .type = REGULATOR_VOLTAGE, \
292 .owner = THIS_MODULE, \
293 .min_uV = S2MPS11_BUCK_MIN1, \
294 .uV_step = S2MPS11_BUCK_STEP1, \
295 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530296 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900297 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800298 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900299 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
300 .enable_mask = S2MPS11_ENABLE_MASK \
301}
302
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100303#define regulator_desc_s2mps11_buck5 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900304 .name = "BUCK5", \
305 .id = S2MPS11_BUCK5, \
306 .ops = &s2mps11_buck_ops, \
307 .type = REGULATOR_VOLTAGE, \
308 .owner = THIS_MODULE, \
309 .min_uV = S2MPS11_BUCK_MIN1, \
310 .uV_step = S2MPS11_BUCK_STEP1, \
311 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530312 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900313 .vsel_reg = S2MPS11_REG_B5CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800314 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900315 .enable_reg = S2MPS11_REG_B5CTRL1, \
316 .enable_mask = S2MPS11_ENABLE_MASK \
317}
318
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100319#define regulator_desc_s2mps11_buck6_8(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900320 .name = "BUCK"#num, \
321 .id = S2MPS11_BUCK##num, \
322 .ops = &s2mps11_buck_ops, \
323 .type = REGULATOR_VOLTAGE, \
324 .owner = THIS_MODULE, \
325 .min_uV = S2MPS11_BUCK_MIN1, \
326 .uV_step = S2MPS11_BUCK_STEP1, \
327 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530328 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900329 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800330 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900331 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
332 .enable_mask = S2MPS11_ENABLE_MASK \
333}
334
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100335#define regulator_desc_s2mps11_buck9 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900336 .name = "BUCK9", \
337 .id = S2MPS11_BUCK9, \
338 .ops = &s2mps11_buck_ops, \
339 .type = REGULATOR_VOLTAGE, \
340 .owner = THIS_MODULE, \
341 .min_uV = S2MPS11_BUCK_MIN3, \
342 .uV_step = S2MPS11_BUCK_STEP3, \
343 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530344 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900345 .vsel_reg = S2MPS11_REG_B9CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800346 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900347 .enable_reg = S2MPS11_REG_B9CTRL1, \
348 .enable_mask = S2MPS11_ENABLE_MASK \
349}
350
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100351#define regulator_desc_s2mps11_buck10 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900352 .name = "BUCK10", \
353 .id = S2MPS11_BUCK10, \
354 .ops = &s2mps11_buck_ops, \
355 .type = REGULATOR_VOLTAGE, \
356 .owner = THIS_MODULE, \
357 .min_uV = S2MPS11_BUCK_MIN2, \
358 .uV_step = S2MPS11_BUCK_STEP2, \
359 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530360 .ramp_delay = S2MPS11_RAMP_DELAY, \
Alim Akhtarc76edd52013-01-30 08:02:27 -0500361 .vsel_reg = S2MPS11_REG_B10CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800362 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Alim Akhtarc76edd52013-01-30 08:02:27 -0500363 .enable_reg = S2MPS11_REG_B10CTRL1, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900364 .enable_mask = S2MPS11_ENABLE_MASK \
365}
366
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100367static const struct regulator_desc s2mps11_regulators[] = {
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100368 regulator_desc_s2mps11_ldo2(1),
369 regulator_desc_s2mps11_ldo1(2),
370 regulator_desc_s2mps11_ldo1(3),
371 regulator_desc_s2mps11_ldo1(4),
372 regulator_desc_s2mps11_ldo1(5),
373 regulator_desc_s2mps11_ldo2(6),
374 regulator_desc_s2mps11_ldo1(7),
375 regulator_desc_s2mps11_ldo1(8),
376 regulator_desc_s2mps11_ldo1(9),
377 regulator_desc_s2mps11_ldo1(10),
378 regulator_desc_s2mps11_ldo2(11),
379 regulator_desc_s2mps11_ldo1(12),
380 regulator_desc_s2mps11_ldo1(13),
381 regulator_desc_s2mps11_ldo1(14),
382 regulator_desc_s2mps11_ldo1(15),
383 regulator_desc_s2mps11_ldo1(16),
384 regulator_desc_s2mps11_ldo1(17),
385 regulator_desc_s2mps11_ldo1(18),
386 regulator_desc_s2mps11_ldo1(19),
387 regulator_desc_s2mps11_ldo1(20),
388 regulator_desc_s2mps11_ldo1(21),
389 regulator_desc_s2mps11_ldo2(22),
390 regulator_desc_s2mps11_ldo2(23),
391 regulator_desc_s2mps11_ldo1(24),
392 regulator_desc_s2mps11_ldo1(25),
393 regulator_desc_s2mps11_ldo1(26),
394 regulator_desc_s2mps11_ldo2(27),
395 regulator_desc_s2mps11_ldo1(28),
396 regulator_desc_s2mps11_ldo1(29),
397 regulator_desc_s2mps11_ldo1(30),
398 regulator_desc_s2mps11_ldo1(31),
399 regulator_desc_s2mps11_ldo1(32),
400 regulator_desc_s2mps11_ldo1(33),
401 regulator_desc_s2mps11_ldo1(34),
402 regulator_desc_s2mps11_ldo1(35),
403 regulator_desc_s2mps11_ldo1(36),
404 regulator_desc_s2mps11_ldo1(37),
405 regulator_desc_s2mps11_ldo1(38),
406 regulator_desc_s2mps11_buck1_4(1),
407 regulator_desc_s2mps11_buck1_4(2),
408 regulator_desc_s2mps11_buck1_4(3),
409 regulator_desc_s2mps11_buck1_4(4),
410 regulator_desc_s2mps11_buck5,
411 regulator_desc_s2mps11_buck6_8(6),
412 regulator_desc_s2mps11_buck6_8(7),
413 regulator_desc_s2mps11_buck6_8(8),
414 regulator_desc_s2mps11_buck9,
415 regulator_desc_s2mps11_buck10,
416};
417
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100418static int s2mps14_regulator_enable(struct regulator_dev *rdev)
419{
420 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
421 unsigned int val;
422
Chanwoo Choi00e25732014-06-25 16:14:45 +0900423 switch (s2mps11->dev_type) {
424 case S2MPS14X:
425 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
426 val = S2MPS14_ENABLE_SUSPEND;
427 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
428 val = S2MPS14_ENABLE_EXT_CONTROL;
429 else
430 val = rdev->desc->enable_mask;
431 break;
432 case S2MPU02:
433 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
434 val = S2MPU02_ENABLE_SUSPEND;
435 else
436 val = rdev->desc->enable_mask;
437 break;
438 default:
439 return -EINVAL;
440 };
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100441
442 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
443 rdev->desc->enable_mask, val);
444}
445
446static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
447{
448 int ret;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900449 unsigned int val, state;
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100450 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900451 int rdev_id = rdev_get_id(rdev);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100452
Chanwoo Choi00e25732014-06-25 16:14:45 +0900453 /* Below LDO should be always on or does not support suspend mode. */
454 switch (s2mps11->dev_type) {
455 case S2MPS14X:
456 switch (rdev_id) {
457 case S2MPS14_LDO3:
458 return 0;
459 default:
460 state = S2MPS14_ENABLE_SUSPEND;
461 break;
462 };
463 break;
464 case S2MPU02:
465 switch (rdev_id) {
466 case S2MPU02_LDO13:
467 case S2MPU02_LDO14:
468 case S2MPU02_LDO15:
469 case S2MPU02_LDO17:
470 case S2MPU02_BUCK7:
471 state = S2MPU02_DISABLE_SUSPEND;
472 break;
473 default:
474 state = S2MPU02_ENABLE_SUSPEND;
475 break;
476 };
477 break;
478 default:
479 return -EINVAL;
480 };
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100481
482 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
483 if (ret < 0)
484 return ret;
485
486 s2mps11->s2mps14_suspend_state |= (1 << rdev_get_id(rdev));
487 /*
488 * Don't enable suspend mode if regulator is already disabled because
489 * this would effectively for a short time turn on the regulator after
490 * resuming.
491 * However we still want to toggle the suspend_state bit for regulator
492 * in case if it got enabled before suspending the system.
493 */
494 if (!(val & rdev->desc->enable_mask))
495 return 0;
496
497 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900498 rdev->desc->enable_mask, state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100499}
500
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100501static struct regulator_ops s2mps14_reg_ops = {
502 .list_voltage = regulator_list_voltage_linear,
503 .map_voltage = regulator_map_voltage_linear,
504 .is_enabled = regulator_is_enabled_regmap,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100505 .enable = s2mps14_regulator_enable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100506 .disable = regulator_disable_regmap,
507 .get_voltage_sel = regulator_get_voltage_sel_regmap,
508 .set_voltage_sel = regulator_set_voltage_sel_regmap,
509 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100510 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100511};
512
513#define regulator_desc_s2mps14_ldo1(num) { \
514 .name = "LDO"#num, \
515 .id = S2MPS14_LDO##num, \
516 .ops = &s2mps14_reg_ops, \
517 .type = REGULATOR_VOLTAGE, \
518 .owner = THIS_MODULE, \
519 .min_uV = S2MPS14_LDO_MIN_800MV, \
520 .uV_step = S2MPS14_LDO_STEP_25MV, \
521 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
522 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
523 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
524 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
525 .enable_mask = S2MPS14_ENABLE_MASK \
526}
527#define regulator_desc_s2mps14_ldo2(num) { \
528 .name = "LDO"#num, \
529 .id = S2MPS14_LDO##num, \
530 .ops = &s2mps14_reg_ops, \
531 .type = REGULATOR_VOLTAGE, \
532 .owner = THIS_MODULE, \
533 .min_uV = S2MPS14_LDO_MIN_1800MV, \
534 .uV_step = S2MPS14_LDO_STEP_25MV, \
535 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
536 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
537 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
538 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
539 .enable_mask = S2MPS14_ENABLE_MASK \
540}
541#define regulator_desc_s2mps14_ldo3(num) { \
542 .name = "LDO"#num, \
543 .id = S2MPS14_LDO##num, \
544 .ops = &s2mps14_reg_ops, \
545 .type = REGULATOR_VOLTAGE, \
546 .owner = THIS_MODULE, \
547 .min_uV = S2MPS14_LDO_MIN_800MV, \
548 .uV_step = S2MPS14_LDO_STEP_12_5MV, \
549 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
550 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
551 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
552 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
553 .enable_mask = S2MPS14_ENABLE_MASK \
554}
555#define regulator_desc_s2mps14_buck1235(num) { \
556 .name = "BUCK"#num, \
557 .id = S2MPS14_BUCK##num, \
558 .ops = &s2mps14_reg_ops, \
559 .type = REGULATOR_VOLTAGE, \
560 .owner = THIS_MODULE, \
561 .min_uV = S2MPS14_BUCK1235_MIN_600MV, \
562 .uV_step = S2MPS14_BUCK1235_STEP_6_25MV, \
563 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
564 .linear_min_sel = S2MPS14_BUCK1235_START_SEL, \
565 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
566 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
567 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
568 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
569 .enable_mask = S2MPS14_ENABLE_MASK \
570}
571#define regulator_desc_s2mps14_buck4(num) { \
572 .name = "BUCK"#num, \
573 .id = S2MPS14_BUCK##num, \
574 .ops = &s2mps14_reg_ops, \
575 .type = REGULATOR_VOLTAGE, \
576 .owner = THIS_MODULE, \
577 .min_uV = S2MPS14_BUCK4_MIN_1400MV, \
578 .uV_step = S2MPS14_BUCK4_STEP_12_5MV, \
579 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
580 .linear_min_sel = S2MPS14_BUCK4_START_SEL, \
581 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
582 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
583 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
584 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
585 .enable_mask = S2MPS14_ENABLE_MASK \
586}
587
588static const struct regulator_desc s2mps14_regulators[] = {
589 regulator_desc_s2mps14_ldo3(1),
590 regulator_desc_s2mps14_ldo3(2),
591 regulator_desc_s2mps14_ldo1(3),
592 regulator_desc_s2mps14_ldo1(4),
593 regulator_desc_s2mps14_ldo3(5),
594 regulator_desc_s2mps14_ldo3(6),
595 regulator_desc_s2mps14_ldo1(7),
596 regulator_desc_s2mps14_ldo2(8),
597 regulator_desc_s2mps14_ldo3(9),
598 regulator_desc_s2mps14_ldo3(10),
599 regulator_desc_s2mps14_ldo1(11),
600 regulator_desc_s2mps14_ldo2(12),
601 regulator_desc_s2mps14_ldo2(13),
602 regulator_desc_s2mps14_ldo2(14),
603 regulator_desc_s2mps14_ldo2(15),
604 regulator_desc_s2mps14_ldo2(16),
605 regulator_desc_s2mps14_ldo2(17),
606 regulator_desc_s2mps14_ldo2(18),
607 regulator_desc_s2mps14_ldo1(19),
608 regulator_desc_s2mps14_ldo1(20),
609 regulator_desc_s2mps14_ldo1(21),
610 regulator_desc_s2mps14_ldo3(22),
611 regulator_desc_s2mps14_ldo1(23),
612 regulator_desc_s2mps14_ldo2(24),
613 regulator_desc_s2mps14_ldo2(25),
614 regulator_desc_s2mps14_buck1235(1),
615 regulator_desc_s2mps14_buck1235(2),
616 regulator_desc_s2mps14_buck1235(3),
617 regulator_desc_s2mps14_buck4(4),
618 regulator_desc_s2mps14_buck1235(5),
Sangbeom Kimcb746852012-07-11 21:08:17 +0900619};
620
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200621static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
622 struct regulator_dev *rdev)
623{
624 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
625 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
626}
627
628static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200629 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
630{
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200631 int *gpio = s2mps11->ext_control_gpio;
632 unsigned int i;
633 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
634 S2MPS14_LDO12 };
635
636 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
637 unsigned int reg = valid_regulators[i];
638
639 if (!rdata[reg].init_data || !rdata[reg].of_node)
640 continue;
641
642 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
643 "samsung,ext-control-gpios", 0);
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200644 if (gpio_is_valid(gpio[reg]))
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200645 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
646 gpio[reg], reg, rdata[reg].name);
647 }
648}
649
650static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900651 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200652{
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200653 struct device_node *reg_np;
654
655 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
656 if (!reg_np) {
657 dev_err(&pdev->dev, "could not find regulators sub-node\n");
658 return -EINVAL;
659 }
660
661 of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900662 if (s2mps11->dev_type == S2MPS14X)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200663 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
664
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200665 of_node_put(reg_np);
666
667 return 0;
668}
669
Chanwoo Choi00e25732014-06-25 16:14:45 +0900670static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
671{
672 unsigned int ramp_val, ramp_shift, ramp_reg;
673
674 switch (rdev_get_id(rdev)) {
675 case S2MPU02_BUCK1:
676 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
677 break;
678 case S2MPU02_BUCK2:
679 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
680 break;
681 case S2MPU02_BUCK3:
682 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
683 break;
684 case S2MPU02_BUCK4:
685 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
686 break;
687 default:
688 return 0;
689 }
690 ramp_reg = S2MPU02_REG_RAMP1;
691 ramp_val = get_ramp_delay(ramp_delay);
692
693 return regmap_update_bits(rdev->regmap, ramp_reg,
694 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
695 ramp_val << ramp_shift);
696}
697
698static struct regulator_ops s2mpu02_ldo_ops = {
699 .list_voltage = regulator_list_voltage_linear,
700 .map_voltage = regulator_map_voltage_linear,
701 .is_enabled = regulator_is_enabled_regmap,
702 .enable = s2mps14_regulator_enable,
703 .disable = regulator_disable_regmap,
704 .get_voltage_sel = regulator_get_voltage_sel_regmap,
705 .set_voltage_sel = regulator_set_voltage_sel_regmap,
706 .set_voltage_time_sel = regulator_set_voltage_time_sel,
707 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
708};
709
710static struct regulator_ops s2mpu02_buck_ops = {
711 .list_voltage = regulator_list_voltage_linear,
712 .map_voltage = regulator_map_voltage_linear,
713 .is_enabled = regulator_is_enabled_regmap,
714 .enable = s2mps14_regulator_enable,
715 .disable = regulator_disable_regmap,
716 .get_voltage_sel = regulator_get_voltage_sel_regmap,
717 .set_voltage_sel = regulator_set_voltage_sel_regmap,
718 .set_voltage_time_sel = regulator_set_voltage_time_sel,
719 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
720 .set_ramp_delay = s2mpu02_set_ramp_delay,
721};
722
723#define regulator_desc_s2mpu02_ldo1(num) { \
724 .name = "LDO"#num, \
725 .id = S2MPU02_LDO##num, \
726 .ops = &s2mpu02_ldo_ops, \
727 .type = REGULATOR_VOLTAGE, \
728 .owner = THIS_MODULE, \
729 .min_uV = S2MPU02_LDO_MIN_900MV, \
730 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
731 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
732 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
733 .vsel_reg = S2MPU02_REG_L1CTRL, \
734 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
735 .enable_reg = S2MPU02_REG_L1CTRL, \
736 .enable_mask = S2MPU02_ENABLE_MASK \
737}
738#define regulator_desc_s2mpu02_ldo2(num) { \
739 .name = "LDO"#num, \
740 .id = S2MPU02_LDO##num, \
741 .ops = &s2mpu02_ldo_ops, \
742 .type = REGULATOR_VOLTAGE, \
743 .owner = THIS_MODULE, \
744 .min_uV = S2MPU02_LDO_MIN_1050MV, \
745 .uV_step = S2MPU02_LDO_STEP_25MV, \
746 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
747 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
748 .vsel_reg = S2MPU02_REG_L2CTRL1, \
749 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
750 .enable_reg = S2MPU02_REG_L2CTRL1, \
751 .enable_mask = S2MPU02_ENABLE_MASK \
752}
753#define regulator_desc_s2mpu02_ldo3(num) { \
754 .name = "LDO"#num, \
755 .id = S2MPU02_LDO##num, \
756 .ops = &s2mpu02_ldo_ops, \
757 .type = REGULATOR_VOLTAGE, \
758 .owner = THIS_MODULE, \
759 .min_uV = S2MPU02_LDO_MIN_900MV, \
760 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
761 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
762 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
763 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
764 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
765 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
766 .enable_mask = S2MPU02_ENABLE_MASK \
767}
768#define regulator_desc_s2mpu02_ldo4(num) { \
769 .name = "LDO"#num, \
770 .id = S2MPU02_LDO##num, \
771 .ops = &s2mpu02_ldo_ops, \
772 .type = REGULATOR_VOLTAGE, \
773 .owner = THIS_MODULE, \
774 .min_uV = S2MPU02_LDO_MIN_1050MV, \
775 .uV_step = S2MPU02_LDO_STEP_25MV, \
776 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
777 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
778 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
779 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
780 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
781 .enable_mask = S2MPU02_ENABLE_MASK \
782}
783#define regulator_desc_s2mpu02_ldo5(num) { \
784 .name = "LDO"#num, \
785 .id = S2MPU02_LDO##num, \
786 .ops = &s2mpu02_ldo_ops, \
787 .type = REGULATOR_VOLTAGE, \
788 .owner = THIS_MODULE, \
789 .min_uV = S2MPU02_LDO_MIN_1600MV, \
790 .uV_step = S2MPU02_LDO_STEP_50MV, \
791 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
792 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
793 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
794 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
795 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
796 .enable_mask = S2MPU02_ENABLE_MASK \
797}
798
799#define regulator_desc_s2mpu02_buck1234(num) { \
800 .name = "BUCK"#num, \
801 .id = S2MPU02_BUCK##num, \
802 .ops = &s2mpu02_buck_ops, \
803 .type = REGULATOR_VOLTAGE, \
804 .owner = THIS_MODULE, \
805 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
806 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
807 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
808 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
809 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
810 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
811 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
812 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
813 .enable_mask = S2MPU02_ENABLE_MASK \
814}
815#define regulator_desc_s2mpu02_buck5(num) { \
816 .name = "BUCK"#num, \
817 .id = S2MPU02_BUCK##num, \
818 .ops = &s2mpu02_ldo_ops, \
819 .type = REGULATOR_VOLTAGE, \
820 .owner = THIS_MODULE, \
821 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
822 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
823 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
824 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
825 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
826 .vsel_reg = S2MPU02_REG_B5CTRL2, \
827 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
828 .enable_reg = S2MPU02_REG_B5CTRL1, \
829 .enable_mask = S2MPU02_ENABLE_MASK \
830}
831#define regulator_desc_s2mpu02_buck6(num) { \
832 .name = "BUCK"#num, \
833 .id = S2MPU02_BUCK##num, \
834 .ops = &s2mpu02_ldo_ops, \
835 .type = REGULATOR_VOLTAGE, \
836 .owner = THIS_MODULE, \
837 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
838 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
839 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
840 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
841 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
842 .vsel_reg = S2MPU02_REG_B6CTRL2, \
843 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
844 .enable_reg = S2MPU02_REG_B6CTRL1, \
845 .enable_mask = S2MPU02_ENABLE_MASK \
846}
847#define regulator_desc_s2mpu02_buck7(num) { \
848 .name = "BUCK"#num, \
849 .id = S2MPU02_BUCK##num, \
850 .ops = &s2mpu02_ldo_ops, \
851 .type = REGULATOR_VOLTAGE, \
852 .owner = THIS_MODULE, \
853 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
854 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
855 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
856 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
857 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
858 .vsel_reg = S2MPU02_REG_B7CTRL2, \
859 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
860 .enable_reg = S2MPU02_REG_B7CTRL1, \
861 .enable_mask = S2MPU02_ENABLE_MASK \
862}
863
864static const struct regulator_desc s2mpu02_regulators[] = {
865 regulator_desc_s2mpu02_ldo1(1),
866 regulator_desc_s2mpu02_ldo2(2),
867 regulator_desc_s2mpu02_ldo4(3),
868 regulator_desc_s2mpu02_ldo5(4),
869 regulator_desc_s2mpu02_ldo4(5),
870 regulator_desc_s2mpu02_ldo3(6),
871 regulator_desc_s2mpu02_ldo3(7),
872 regulator_desc_s2mpu02_ldo4(8),
873 regulator_desc_s2mpu02_ldo5(9),
874 regulator_desc_s2mpu02_ldo3(10),
875 regulator_desc_s2mpu02_ldo4(11),
876 regulator_desc_s2mpu02_ldo5(12),
877 regulator_desc_s2mpu02_ldo5(13),
878 regulator_desc_s2mpu02_ldo5(14),
879 regulator_desc_s2mpu02_ldo5(15),
880 regulator_desc_s2mpu02_ldo5(16),
881 regulator_desc_s2mpu02_ldo4(17),
882 regulator_desc_s2mpu02_ldo5(18),
883 regulator_desc_s2mpu02_ldo3(19),
884 regulator_desc_s2mpu02_ldo4(20),
885 regulator_desc_s2mpu02_ldo5(21),
886 regulator_desc_s2mpu02_ldo5(22),
887 regulator_desc_s2mpu02_ldo5(23),
888 regulator_desc_s2mpu02_ldo4(24),
889 regulator_desc_s2mpu02_ldo5(25),
890 regulator_desc_s2mpu02_ldo4(26),
891 regulator_desc_s2mpu02_ldo5(27),
892 regulator_desc_s2mpu02_ldo5(28),
893 regulator_desc_s2mpu02_buck1234(1),
894 regulator_desc_s2mpu02_buck1234(2),
895 regulator_desc_s2mpu02_buck1234(3),
896 regulator_desc_s2mpu02_buck1234(4),
897 regulator_desc_s2mpu02_buck5(5),
898 regulator_desc_s2mpu02_buck6(6),
899 regulator_desc_s2mpu02_buck7(7),
900};
901
Bill Pembertona5023572012-11-19 13:22:22 -0500902static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +0900903{
904 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200905 struct sec_platform_data *pdata = NULL;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100906 struct of_regulator_match *rdata = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900907 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +0900908 struct s2mps11_info *s2mps11;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100909 int i, ret = 0;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100910 const struct regulator_desc *regulators;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900911
Sangbeom Kimcb746852012-07-11 21:08:17 +0900912 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
913 GFP_KERNEL);
914 if (!s2mps11)
915 return -ENOMEM;
916
Chanwoo Choi00e25732014-06-25 16:14:45 +0900917 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
918 switch (s2mps11->dev_type) {
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100919 case S2MPS11X:
920 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
921 regulators = s2mps11_regulators;
922 break;
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100923 case S2MPS14X:
924 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
925 regulators = s2mps14_regulators;
926 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900927 case S2MPU02:
928 s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
929 regulators = s2mpu02_regulators;
930 break;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100931 default:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900932 dev_err(&pdev->dev, "Invalid device type: %u\n",
933 s2mps11->dev_type);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100934 return -EINVAL;
935 };
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100936
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200937 s2mps11->ext_control_gpio = devm_kzalloc(&pdev->dev,
938 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
939 GFP_KERNEL);
940 if (!s2mps11->ext_control_gpio)
941 return -ENOMEM;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200942 /*
943 * 0 is a valid GPIO so initialize all GPIO-s to negative value
944 * to indicate that external control won't be used for this regulator.
945 */
946 for (i = 0; i < s2mps11->rdev_num; i++)
947 s2mps11->ext_control_gpio[i] = -EINVAL;
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200948
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +0530949 if (!iodev->dev->of_node) {
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200950 if (iodev->pdata) {
951 pdata = iodev->pdata;
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +0530952 goto common_reg;
953 } else {
954 dev_err(pdev->dev.parent,
955 "Platform data or DT node not supplied\n");
956 return -ENODEV;
957 }
958 }
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530959
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100960 rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100961 if (!rdata)
962 return -ENOMEM;
963
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100964 for (i = 0; i < s2mps11->rdev_num; i++)
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530965 rdata[i].name = regulators[i].name;
966
Chanwoo Choi00e25732014-06-25 16:14:45 +0900967 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200968 if (ret)
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100969 goto out;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530970
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530971common_reg:
972 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900973
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530974 config.dev = &pdev->dev;
Krzysztof Kozlowski1b1ccee2013-12-11 15:07:43 +0100975 config.regmap = iodev->regmap_pmic;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530976 config.driver_data = s2mps11;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200977 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100978 for (i = 0; i < s2mps11->rdev_num; i++) {
Krzysztof Kozlowski31195252014-02-28 11:01:48 +0100979 struct regulator_dev *regulator;
980
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200981 if (pdata) {
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530982 config.init_data = pdata->regulators[i].initdata;
Krzysztof Kozlowski54820f52014-01-30 14:51:19 +0100983 config.of_node = pdata->regulators[i].reg_node;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530984 } else {
985 config.init_data = rdata[i].init_data;
986 config.of_node = rdata[i].of_node;
987 }
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200988 config.ena_gpio = s2mps11->ext_control_gpio[i];
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200989
Krzysztof Kozlowski31195252014-02-28 11:01:48 +0100990 regulator = devm_regulator_register(&pdev->dev,
Sachin Kamatd55cd792013-09-04 12:12:15 +0530991 &regulators[i], &config);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +0100992 if (IS_ERR(regulator)) {
993 ret = PTR_ERR(regulator);
Axel Lin232b2502012-07-12 09:37:37 +0800994 dev_err(&pdev->dev, "regulator init failed for %d\n",
995 i);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100996 goto out;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900997 }
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200998
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200999 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001000 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1001 regulator);
1002 if (ret < 0) {
1003 dev_err(&pdev->dev,
1004 "failed to enable GPIO control over %s: %d\n",
1005 regulator->desc->name, ret);
1006 goto out;
1007 }
1008 }
Sangbeom Kimcb746852012-07-11 21:08:17 +09001009 }
1010
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001011out:
1012 kfree(rdata);
1013
1014 return ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001015}
1016
1017static const struct platform_device_id s2mps11_pmic_id[] = {
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001018 { "s2mps11-pmic", S2MPS11X},
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001019 { "s2mps14-pmic", S2MPS14X},
Chanwoo Choi00e25732014-06-25 16:14:45 +09001020 { "s2mpu02-pmic", S2MPU02},
Sangbeom Kimcb746852012-07-11 21:08:17 +09001021 { },
1022};
1023MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1024
1025static struct platform_driver s2mps11_pmic_driver = {
1026 .driver = {
1027 .name = "s2mps11-pmic",
1028 .owner = THIS_MODULE,
1029 },
1030 .probe = s2mps11_pmic_probe,
Sangbeom Kimcb746852012-07-11 21:08:17 +09001031 .id_table = s2mps11_pmic_id,
1032};
1033
1034static int __init s2mps11_pmic_init(void)
1035{
1036 return platform_driver_register(&s2mps11_pmic_driver);
1037}
1038subsys_initcall(s2mps11_pmic_init);
1039
1040static void __exit s2mps11_pmic_exit(void)
1041{
1042 platform_driver_unregister(&s2mps11_pmic_driver);
1043}
1044module_exit(s2mps11_pmic_exit);
1045
1046/* Module information */
1047MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Axel Lincad35c32014-07-23 16:47:31 +08001048MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPU02 Regulator Driver");
Sangbeom Kimcb746852012-07-11 21:08:17 +09001049MODULE_LICENSE("GPL");