blob: 326ffb55337117d6dc2a96d7fce9cea773e18a14 [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>
Chanwoo Choi76b98402014-11-18 17:59:40 +090033#include <linux/mfd/samsung/s2mps13.h>
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +010034#include <linux/mfd/samsung/s2mps14.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090035#include <linux/mfd/samsung/s2mpu02.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053036
Sangbeom Kimcb746852012-07-11 21:08:17 +090037struct s2mps11_info {
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +010038 unsigned int rdev_num;
Sangbeom Kimcb746852012-07-11 21:08:17 +090039 int ramp_delay2;
40 int ramp_delay34;
41 int ramp_delay5;
42 int ramp_delay16;
43 int ramp_delay7810;
44 int ramp_delay9;
Chanwoo Choi00e25732014-06-25 16:14:45 +090045
46 enum sec_device_type dev_type;
47
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010048 /*
Chanwoo Choi76b98402014-11-18 17:59:40 +090049 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
50 * the suspend mode was enabled.
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010051 */
Chanwoo Choi76b98402014-11-18 17:59:40 +090052 unsigned long long s2mps14_suspend_state:50;
Chanwoo Choi00e25732014-06-25 16:14:45 +090053
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +020054 /* Array of size rdev_num with GPIO-s for external sleep control */
55 int *ext_control_gpio;
Sangbeom Kimcb746852012-07-11 21:08:17 +090056};
57
58static int get_ramp_delay(int ramp_delay)
59{
60 unsigned char cnt = 0;
61
Yadwinder Singh Brar90068342013-06-24 16:50:55 +053062 ramp_delay /= 6250;
Sangbeom Kimcb746852012-07-11 21:08:17 +090063
64 while (true) {
65 ramp_delay = ramp_delay >> 1;
66 if (ramp_delay == 0)
67 break;
68 cnt++;
69 }
Axel Linf8f1d482013-08-05 14:08:37 +080070
71 if (cnt > 3)
72 cnt = 3;
73
Sangbeom Kimcb746852012-07-11 21:08:17 +090074 return cnt;
75}
76
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053077static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
78 unsigned int old_selector,
79 unsigned int new_selector)
80{
81 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
82 unsigned int ramp_delay = 0;
83 int old_volt, new_volt;
84
Thiago Farinad55efa42014-01-26 21:57:12 -020085 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053086 case S2MPS11_BUCK2:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053087 ramp_delay = s2mps11->ramp_delay2;
88 break;
89 case S2MPS11_BUCK3:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053090 case S2MPS11_BUCK4:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053091 ramp_delay = s2mps11->ramp_delay34;
92 break;
93 case S2MPS11_BUCK5:
94 ramp_delay = s2mps11->ramp_delay5;
95 break;
96 case S2MPS11_BUCK6:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053097 case S2MPS11_BUCK1:
98 ramp_delay = s2mps11->ramp_delay16;
99 break;
100 case S2MPS11_BUCK7:
101 case S2MPS11_BUCK8:
102 case S2MPS11_BUCK10:
103 ramp_delay = s2mps11->ramp_delay7810;
104 break;
105 case S2MPS11_BUCK9:
106 ramp_delay = s2mps11->ramp_delay9;
107 }
108
109 if (ramp_delay == 0)
110 ramp_delay = rdev->desc->ramp_delay;
111
112 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
113 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
114
115 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
116}
117
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530118static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
119{
120 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
121 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
122 unsigned int ramp_enable = 1, enable_shift = 0;
123 int ret;
124
Thiago Farinad55efa42014-01-26 21:57:12 -0200125 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530126 case S2MPS11_BUCK1:
127 if (ramp_delay > s2mps11->ramp_delay16)
128 s2mps11->ramp_delay16 = ramp_delay;
129 else
130 ramp_delay = s2mps11->ramp_delay16;
131
132 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
133 break;
134 case S2MPS11_BUCK2:
135 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
136 if (!ramp_delay) {
137 ramp_enable = 0;
138 break;
139 }
140
141 s2mps11->ramp_delay2 = ramp_delay;
142 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
143 ramp_reg = S2MPS11_REG_RAMP;
144 break;
145 case S2MPS11_BUCK3:
146 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
147 if (!ramp_delay) {
148 ramp_enable = 0;
149 break;
150 }
151
152 if (ramp_delay > s2mps11->ramp_delay34)
153 s2mps11->ramp_delay34 = ramp_delay;
154 else
155 ramp_delay = s2mps11->ramp_delay34;
156
157 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
158 ramp_reg = S2MPS11_REG_RAMP;
159 break;
160 case S2MPS11_BUCK4:
161 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
162 if (!ramp_delay) {
163 ramp_enable = 0;
164 break;
165 }
166
167 if (ramp_delay > s2mps11->ramp_delay34)
168 s2mps11->ramp_delay34 = ramp_delay;
169 else
170 ramp_delay = s2mps11->ramp_delay34;
171
172 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
173 ramp_reg = S2MPS11_REG_RAMP;
174 break;
175 case S2MPS11_BUCK5:
176 s2mps11->ramp_delay5 = ramp_delay;
177 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
178 break;
179 case S2MPS11_BUCK6:
180 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
181 if (!ramp_delay) {
182 ramp_enable = 0;
183 break;
184 }
185
186 if (ramp_delay > s2mps11->ramp_delay16)
187 s2mps11->ramp_delay16 = ramp_delay;
188 else
189 ramp_delay = s2mps11->ramp_delay16;
190
191 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
192 break;
193 case S2MPS11_BUCK7:
194 case S2MPS11_BUCK8:
195 case S2MPS11_BUCK10:
196 if (ramp_delay > s2mps11->ramp_delay7810)
197 s2mps11->ramp_delay7810 = ramp_delay;
198 else
199 ramp_delay = s2mps11->ramp_delay7810;
200
201 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
202 break;
203 case S2MPS11_BUCK9:
204 s2mps11->ramp_delay9 = ramp_delay;
205 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
206 break;
207 default:
208 return 0;
209 }
210
211 if (!ramp_enable)
212 goto ramp_disable;
213
Krzysztof Kozlowskib203e0d2014-05-06 08:37:36 +0200214 /* Ramp delay can be enabled/disabled only for buck[2346] */
215 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
216 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
217 rdev_get_id(rdev) == S2MPS11_BUCK6) {
218 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
219 1 << enable_shift, 1 << enable_shift);
220 if (ret) {
221 dev_err(&rdev->dev, "failed to enable ramp rate\n");
222 return ret;
223 }
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530224 }
225
226 ramp_val = get_ramp_delay(ramp_delay);
227
Axel Linf8f1d482013-08-05 14:08:37 +0800228 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
229 ramp_val << ramp_shift);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530230
231ramp_disable:
Axel Lin80853302013-08-03 17:10:42 +0800232 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
233 1 << enable_shift, 0);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530234}
235
Sangbeom Kimcb746852012-07-11 21:08:17 +0900236static struct regulator_ops s2mps11_ldo_ops = {
237 .list_voltage = regulator_list_voltage_linear,
238 .map_voltage = regulator_map_voltage_linear,
239 .is_enabled = regulator_is_enabled_regmap,
240 .enable = regulator_enable_regmap,
241 .disable = regulator_disable_regmap,
242 .get_voltage_sel = regulator_get_voltage_sel_regmap,
243 .set_voltage_sel = regulator_set_voltage_sel_regmap,
244 .set_voltage_time_sel = regulator_set_voltage_time_sel,
245};
246
247static struct regulator_ops s2mps11_buck_ops = {
248 .list_voltage = regulator_list_voltage_linear,
249 .map_voltage = regulator_map_voltage_linear,
250 .is_enabled = regulator_is_enabled_regmap,
251 .enable = regulator_enable_regmap,
252 .disable = regulator_disable_regmap,
253 .get_voltage_sel = regulator_get_voltage_sel_regmap,
254 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +0530255 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530256 .set_ramp_delay = s2mps11_set_ramp_delay,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900257};
258
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530259#define regulator_desc_s2mps11_ldo(num, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900260 .name = "LDO"#num, \
261 .id = S2MPS11_LDO##num, \
262 .ops = &s2mps11_ldo_ops, \
263 .type = REGULATOR_VOLTAGE, \
264 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530265 .min_uV = MIN_800_MV, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530266 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900267 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
268 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800269 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900270 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
271 .enable_mask = S2MPS11_ENABLE_MASK \
272}
273
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100274#define regulator_desc_s2mps11_buck1_4(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900275 .name = "BUCK"#num, \
276 .id = S2MPS11_BUCK##num, \
277 .ops = &s2mps11_buck_ops, \
278 .type = REGULATOR_VOLTAGE, \
279 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530280 .min_uV = MIN_600_MV, \
281 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900282 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530283 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900284 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800285 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900286 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
287 .enable_mask = S2MPS11_ENABLE_MASK \
288}
289
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100290#define regulator_desc_s2mps11_buck5 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900291 .name = "BUCK5", \
292 .id = S2MPS11_BUCK5, \
293 .ops = &s2mps11_buck_ops, \
294 .type = REGULATOR_VOLTAGE, \
295 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530296 .min_uV = MIN_600_MV, \
297 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900298 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530299 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900300 .vsel_reg = S2MPS11_REG_B5CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800301 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900302 .enable_reg = S2MPS11_REG_B5CTRL1, \
303 .enable_mask = S2MPS11_ENABLE_MASK \
304}
305
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530306#define regulator_desc_s2mps11_buck6_10(num, min, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900307 .name = "BUCK"#num, \
308 .id = S2MPS11_BUCK##num, \
309 .ops = &s2mps11_buck_ops, \
310 .type = REGULATOR_VOLTAGE, \
311 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530312 .min_uV = min, \
313 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900314 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530315 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900316 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800317 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900318 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
319 .enable_mask = S2MPS11_ENABLE_MASK \
320}
321
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100322static const struct regulator_desc s2mps11_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530323 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
324 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
325 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
326 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
327 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
328 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
329 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
330 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
331 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
332 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
333 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
334 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
335 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
336 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
337 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
338 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
339 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
340 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
341 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
342 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
343 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
344 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
345 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
346 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
348 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
349 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
350 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
353 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100361 regulator_desc_s2mps11_buck1_4(1),
362 regulator_desc_s2mps11_buck1_4(2),
363 regulator_desc_s2mps11_buck1_4(3),
364 regulator_desc_s2mps11_buck1_4(4),
365 regulator_desc_s2mps11_buck5,
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530366 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV, STEP_6_25_MV),
367 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV, STEP_6_25_MV),
368 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV, STEP_6_25_MV),
369 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV, STEP_25_MV),
370 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100371};
372
Chanwoo Choi76b98402014-11-18 17:59:40 +0900373static struct regulator_ops s2mps14_reg_ops;
374
375#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
376 .name = "LDO"#num, \
377 .id = S2MPS13_LDO##num, \
378 .ops = &s2mps14_reg_ops, \
379 .type = REGULATOR_VOLTAGE, \
380 .owner = THIS_MODULE, \
381 .min_uV = min, \
382 .uV_step = step, \
383 .linear_min_sel = min_sel, \
384 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
385 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
386 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
387 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
388 .enable_mask = S2MPS14_ENABLE_MASK \
389}
390
391#define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
392 .name = "BUCK"#num, \
393 .id = S2MPS13_BUCK##num, \
394 .ops = &s2mps14_reg_ops, \
395 .type = REGULATOR_VOLTAGE, \
396 .owner = THIS_MODULE, \
397 .min_uV = min, \
398 .uV_step = step, \
399 .linear_min_sel = min_sel, \
400 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
401 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
402 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
403 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
404 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
405 .enable_mask = S2MPS14_ENABLE_MASK \
406}
407
Jonghwa Leead26aa62015-01-08 11:04:07 +0900408#define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
409 .name = "BUCK"#num, \
410 .id = S2MPS13_BUCK##num, \
411 .ops = &s2mps14_reg_ops, \
412 .type = REGULATOR_VOLTAGE, \
413 .owner = THIS_MODULE, \
414 .min_uV = min, \
415 .uV_step = step, \
416 .linear_min_sel = min_sel, \
417 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
418 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
419 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
420 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
421 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
422 .enable_mask = S2MPS14_ENABLE_MASK \
423}
424
425#define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
426 .name = "BUCK"#num, \
427 .id = S2MPS13_BUCK##num, \
428 .ops = &s2mps14_reg_ops, \
429 .type = REGULATOR_VOLTAGE, \
430 .owner = THIS_MODULE, \
431 .min_uV = min, \
432 .uV_step = step, \
433 .linear_min_sel = min_sel, \
434 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
435 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
436 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
437 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
438 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
439 .enable_mask = S2MPS14_ENABLE_MASK \
440}
441
Chanwoo Choi76b98402014-11-18 17:59:40 +0900442static const struct regulator_desc s2mps13_regulators[] = {
443 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
444 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
445 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
446 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
447 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
448 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
449 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
450 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
451 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
452 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
453 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
454 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
455 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
456 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
457 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
458 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
459 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
460 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
461 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
462 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
463 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
464 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
465 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
466 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
467 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
468 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
469 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
470 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
471 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
472 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
473 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
474 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
475 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
476 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
477 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
478 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
479 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
480 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
481 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
482 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
483 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
484 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
485 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
486 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
487 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
488 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
Jonghwa Leead26aa62015-01-08 11:04:07 +0900489 regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
490 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
491 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
492 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
Chanwoo Choi76b98402014-11-18 17:59:40 +0900493};
494
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100495static int s2mps14_regulator_enable(struct regulator_dev *rdev)
496{
497 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
498 unsigned int val;
499
Chanwoo Choi00e25732014-06-25 16:14:45 +0900500 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900501 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900502 case S2MPS14X:
503 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
504 val = S2MPS14_ENABLE_SUSPEND;
505 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
506 val = S2MPS14_ENABLE_EXT_CONTROL;
507 else
508 val = rdev->desc->enable_mask;
509 break;
510 case S2MPU02:
511 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
512 val = S2MPU02_ENABLE_SUSPEND;
513 else
514 val = rdev->desc->enable_mask;
515 break;
516 default:
517 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900518 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100519
520 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
521 rdev->desc->enable_mask, val);
522}
523
524static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
525{
526 int ret;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900527 unsigned int val, state;
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100528 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900529 int rdev_id = rdev_get_id(rdev);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100530
Chanwoo Choi00e25732014-06-25 16:14:45 +0900531 /* Below LDO should be always on or does not support suspend mode. */
532 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900533 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900534 case S2MPS14X:
535 switch (rdev_id) {
536 case S2MPS14_LDO3:
537 return 0;
538 default:
539 state = S2MPS14_ENABLE_SUSPEND;
540 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900541 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900542 break;
543 case S2MPU02:
544 switch (rdev_id) {
545 case S2MPU02_LDO13:
546 case S2MPU02_LDO14:
547 case S2MPU02_LDO15:
548 case S2MPU02_LDO17:
549 case S2MPU02_BUCK7:
550 state = S2MPU02_DISABLE_SUSPEND;
551 break;
552 default:
553 state = S2MPU02_ENABLE_SUSPEND;
554 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900555 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900556 break;
557 default:
558 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900559 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100560
561 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
562 if (ret < 0)
563 return ret;
564
565 s2mps11->s2mps14_suspend_state |= (1 << rdev_get_id(rdev));
566 /*
567 * Don't enable suspend mode if regulator is already disabled because
568 * this would effectively for a short time turn on the regulator after
569 * resuming.
570 * However we still want to toggle the suspend_state bit for regulator
571 * in case if it got enabled before suspending the system.
572 */
573 if (!(val & rdev->desc->enable_mask))
574 return 0;
575
576 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900577 rdev->desc->enable_mask, state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100578}
579
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100580static struct regulator_ops s2mps14_reg_ops = {
581 .list_voltage = regulator_list_voltage_linear,
582 .map_voltage = regulator_map_voltage_linear,
583 .is_enabled = regulator_is_enabled_regmap,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100584 .enable = s2mps14_regulator_enable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100585 .disable = regulator_disable_regmap,
586 .get_voltage_sel = regulator_get_voltage_sel_regmap,
587 .set_voltage_sel = regulator_set_voltage_sel_regmap,
588 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100589 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100590};
591
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530592#define regulator_desc_s2mps14_ldo(num, min, step) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100593 .name = "LDO"#num, \
594 .id = S2MPS14_LDO##num, \
595 .ops = &s2mps14_reg_ops, \
596 .type = REGULATOR_VOLTAGE, \
597 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530598 .min_uV = min, \
599 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100600 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
601 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
602 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
603 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
604 .enable_mask = S2MPS14_ENABLE_MASK \
605}
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530606
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100607#define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100608 .name = "BUCK"#num, \
609 .id = S2MPS14_BUCK##num, \
610 .ops = &s2mps14_reg_ops, \
611 .type = REGULATOR_VOLTAGE, \
612 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530613 .min_uV = min, \
614 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100615 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100616 .linear_min_sel = min_sel, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100617 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
618 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
619 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
620 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
621 .enable_mask = S2MPS14_ENABLE_MASK \
622}
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100623
624static const struct regulator_desc s2mps14_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530625 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
626 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
627 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
628 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
629 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
630 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
631 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
632 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
633 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
634 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
635 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
636 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
637 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
638 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
639 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
640 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
641 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
642 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
643 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
644 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
645 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
646 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
647 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
648 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
649 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100650 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
651 S2MPS14_BUCK1235_START_SEL),
652 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
653 S2MPS14_BUCK1235_START_SEL),
654 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
655 S2MPS14_BUCK1235_START_SEL),
656 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
657 S2MPS14_BUCK4_START_SEL),
658 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
659 S2MPS14_BUCK1235_START_SEL),
Sangbeom Kimcb746852012-07-11 21:08:17 +0900660};
661
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200662static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
663 struct regulator_dev *rdev)
664{
665 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
666 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
667}
668
669static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200670 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
671{
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200672 int *gpio = s2mps11->ext_control_gpio;
673 unsigned int i;
674 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
675 S2MPS14_LDO12 };
676
677 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
678 unsigned int reg = valid_regulators[i];
679
680 if (!rdata[reg].init_data || !rdata[reg].of_node)
681 continue;
682
683 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
684 "samsung,ext-control-gpios", 0);
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200685 if (gpio_is_valid(gpio[reg]))
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200686 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
687 gpio[reg], reg, rdata[reg].name);
688 }
689}
690
691static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900692 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200693{
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200694 struct device_node *reg_np;
695
696 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
697 if (!reg_np) {
698 dev_err(&pdev->dev, "could not find regulators sub-node\n");
699 return -EINVAL;
700 }
701
702 of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900703 if (s2mps11->dev_type == S2MPS14X)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200704 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
705
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200706 of_node_put(reg_np);
707
708 return 0;
709}
710
Chanwoo Choi00e25732014-06-25 16:14:45 +0900711static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
712{
713 unsigned int ramp_val, ramp_shift, ramp_reg;
714
715 switch (rdev_get_id(rdev)) {
716 case S2MPU02_BUCK1:
717 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
718 break;
719 case S2MPU02_BUCK2:
720 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
721 break;
722 case S2MPU02_BUCK3:
723 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
724 break;
725 case S2MPU02_BUCK4:
726 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
727 break;
728 default:
729 return 0;
730 }
731 ramp_reg = S2MPU02_REG_RAMP1;
732 ramp_val = get_ramp_delay(ramp_delay);
733
734 return regmap_update_bits(rdev->regmap, ramp_reg,
735 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
736 ramp_val << ramp_shift);
737}
738
739static struct regulator_ops s2mpu02_ldo_ops = {
740 .list_voltage = regulator_list_voltage_linear,
741 .map_voltage = regulator_map_voltage_linear,
742 .is_enabled = regulator_is_enabled_regmap,
743 .enable = s2mps14_regulator_enable,
744 .disable = regulator_disable_regmap,
745 .get_voltage_sel = regulator_get_voltage_sel_regmap,
746 .set_voltage_sel = regulator_set_voltage_sel_regmap,
747 .set_voltage_time_sel = regulator_set_voltage_time_sel,
748 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
749};
750
751static struct regulator_ops s2mpu02_buck_ops = {
752 .list_voltage = regulator_list_voltage_linear,
753 .map_voltage = regulator_map_voltage_linear,
754 .is_enabled = regulator_is_enabled_regmap,
755 .enable = s2mps14_regulator_enable,
756 .disable = regulator_disable_regmap,
757 .get_voltage_sel = regulator_get_voltage_sel_regmap,
758 .set_voltage_sel = regulator_set_voltage_sel_regmap,
759 .set_voltage_time_sel = regulator_set_voltage_time_sel,
760 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
761 .set_ramp_delay = s2mpu02_set_ramp_delay,
762};
763
764#define regulator_desc_s2mpu02_ldo1(num) { \
765 .name = "LDO"#num, \
766 .id = S2MPU02_LDO##num, \
767 .ops = &s2mpu02_ldo_ops, \
768 .type = REGULATOR_VOLTAGE, \
769 .owner = THIS_MODULE, \
770 .min_uV = S2MPU02_LDO_MIN_900MV, \
771 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
772 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
773 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
774 .vsel_reg = S2MPU02_REG_L1CTRL, \
775 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
776 .enable_reg = S2MPU02_REG_L1CTRL, \
777 .enable_mask = S2MPU02_ENABLE_MASK \
778}
779#define regulator_desc_s2mpu02_ldo2(num) { \
780 .name = "LDO"#num, \
781 .id = S2MPU02_LDO##num, \
782 .ops = &s2mpu02_ldo_ops, \
783 .type = REGULATOR_VOLTAGE, \
784 .owner = THIS_MODULE, \
785 .min_uV = S2MPU02_LDO_MIN_1050MV, \
786 .uV_step = S2MPU02_LDO_STEP_25MV, \
787 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
788 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
789 .vsel_reg = S2MPU02_REG_L2CTRL1, \
790 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
791 .enable_reg = S2MPU02_REG_L2CTRL1, \
792 .enable_mask = S2MPU02_ENABLE_MASK \
793}
794#define regulator_desc_s2mpu02_ldo3(num) { \
795 .name = "LDO"#num, \
796 .id = S2MPU02_LDO##num, \
797 .ops = &s2mpu02_ldo_ops, \
798 .type = REGULATOR_VOLTAGE, \
799 .owner = THIS_MODULE, \
800 .min_uV = S2MPU02_LDO_MIN_900MV, \
801 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
802 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
803 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
804 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
805 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
806 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
807 .enable_mask = S2MPU02_ENABLE_MASK \
808}
809#define regulator_desc_s2mpu02_ldo4(num) { \
810 .name = "LDO"#num, \
811 .id = S2MPU02_LDO##num, \
812 .ops = &s2mpu02_ldo_ops, \
813 .type = REGULATOR_VOLTAGE, \
814 .owner = THIS_MODULE, \
815 .min_uV = S2MPU02_LDO_MIN_1050MV, \
816 .uV_step = S2MPU02_LDO_STEP_25MV, \
817 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
818 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
819 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
820 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
821 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
822 .enable_mask = S2MPU02_ENABLE_MASK \
823}
824#define regulator_desc_s2mpu02_ldo5(num) { \
825 .name = "LDO"#num, \
826 .id = S2MPU02_LDO##num, \
827 .ops = &s2mpu02_ldo_ops, \
828 .type = REGULATOR_VOLTAGE, \
829 .owner = THIS_MODULE, \
830 .min_uV = S2MPU02_LDO_MIN_1600MV, \
831 .uV_step = S2MPU02_LDO_STEP_50MV, \
832 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
833 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
834 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
835 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
836 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
837 .enable_mask = S2MPU02_ENABLE_MASK \
838}
839
840#define regulator_desc_s2mpu02_buck1234(num) { \
841 .name = "BUCK"#num, \
842 .id = S2MPU02_BUCK##num, \
843 .ops = &s2mpu02_buck_ops, \
844 .type = REGULATOR_VOLTAGE, \
845 .owner = THIS_MODULE, \
846 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
847 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
848 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
849 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
850 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
851 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
852 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
853 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
854 .enable_mask = S2MPU02_ENABLE_MASK \
855}
856#define regulator_desc_s2mpu02_buck5(num) { \
857 .name = "BUCK"#num, \
858 .id = S2MPU02_BUCK##num, \
859 .ops = &s2mpu02_ldo_ops, \
860 .type = REGULATOR_VOLTAGE, \
861 .owner = THIS_MODULE, \
862 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
863 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
864 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
865 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
866 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
867 .vsel_reg = S2MPU02_REG_B5CTRL2, \
868 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
869 .enable_reg = S2MPU02_REG_B5CTRL1, \
870 .enable_mask = S2MPU02_ENABLE_MASK \
871}
872#define regulator_desc_s2mpu02_buck6(num) { \
873 .name = "BUCK"#num, \
874 .id = S2MPU02_BUCK##num, \
875 .ops = &s2mpu02_ldo_ops, \
876 .type = REGULATOR_VOLTAGE, \
877 .owner = THIS_MODULE, \
878 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
879 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
880 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
881 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
882 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
883 .vsel_reg = S2MPU02_REG_B6CTRL2, \
884 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
885 .enable_reg = S2MPU02_REG_B6CTRL1, \
886 .enable_mask = S2MPU02_ENABLE_MASK \
887}
888#define regulator_desc_s2mpu02_buck7(num) { \
889 .name = "BUCK"#num, \
890 .id = S2MPU02_BUCK##num, \
891 .ops = &s2mpu02_ldo_ops, \
892 .type = REGULATOR_VOLTAGE, \
893 .owner = THIS_MODULE, \
894 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
895 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
896 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
897 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
898 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
899 .vsel_reg = S2MPU02_REG_B7CTRL2, \
900 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
901 .enable_reg = S2MPU02_REG_B7CTRL1, \
902 .enable_mask = S2MPU02_ENABLE_MASK \
903}
904
905static const struct regulator_desc s2mpu02_regulators[] = {
906 regulator_desc_s2mpu02_ldo1(1),
907 regulator_desc_s2mpu02_ldo2(2),
908 regulator_desc_s2mpu02_ldo4(3),
909 regulator_desc_s2mpu02_ldo5(4),
910 regulator_desc_s2mpu02_ldo4(5),
911 regulator_desc_s2mpu02_ldo3(6),
912 regulator_desc_s2mpu02_ldo3(7),
913 regulator_desc_s2mpu02_ldo4(8),
914 regulator_desc_s2mpu02_ldo5(9),
915 regulator_desc_s2mpu02_ldo3(10),
916 regulator_desc_s2mpu02_ldo4(11),
917 regulator_desc_s2mpu02_ldo5(12),
918 regulator_desc_s2mpu02_ldo5(13),
919 regulator_desc_s2mpu02_ldo5(14),
920 regulator_desc_s2mpu02_ldo5(15),
921 regulator_desc_s2mpu02_ldo5(16),
922 regulator_desc_s2mpu02_ldo4(17),
923 regulator_desc_s2mpu02_ldo5(18),
924 regulator_desc_s2mpu02_ldo3(19),
925 regulator_desc_s2mpu02_ldo4(20),
926 regulator_desc_s2mpu02_ldo5(21),
927 regulator_desc_s2mpu02_ldo5(22),
928 regulator_desc_s2mpu02_ldo5(23),
929 regulator_desc_s2mpu02_ldo4(24),
930 regulator_desc_s2mpu02_ldo5(25),
931 regulator_desc_s2mpu02_ldo4(26),
932 regulator_desc_s2mpu02_ldo5(27),
933 regulator_desc_s2mpu02_ldo5(28),
934 regulator_desc_s2mpu02_buck1234(1),
935 regulator_desc_s2mpu02_buck1234(2),
936 regulator_desc_s2mpu02_buck1234(3),
937 regulator_desc_s2mpu02_buck1234(4),
938 regulator_desc_s2mpu02_buck5(5),
939 regulator_desc_s2mpu02_buck6(6),
940 regulator_desc_s2mpu02_buck7(7),
941};
942
Bill Pembertona5023572012-11-19 13:22:22 -0500943static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +0900944{
945 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200946 struct sec_platform_data *pdata = NULL;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100947 struct of_regulator_match *rdata = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900948 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +0900949 struct s2mps11_info *s2mps11;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100950 int i, ret = 0;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100951 const struct regulator_desc *regulators;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900952
Sangbeom Kimcb746852012-07-11 21:08:17 +0900953 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
954 GFP_KERNEL);
955 if (!s2mps11)
956 return -ENOMEM;
957
Chanwoo Choi00e25732014-06-25 16:14:45 +0900958 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
959 switch (s2mps11->dev_type) {
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100960 case S2MPS11X:
961 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
962 regulators = s2mps11_regulators;
963 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +0900964 case S2MPS13X:
965 s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
966 regulators = s2mps13_regulators;
967 break;
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100968 case S2MPS14X:
969 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
970 regulators = s2mps14_regulators;
971 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900972 case S2MPU02:
973 s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
974 regulators = s2mpu02_regulators;
975 break;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100976 default:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900977 dev_err(&pdev->dev, "Invalid device type: %u\n",
978 s2mps11->dev_type);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100979 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900980 }
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +0100981
Krzysztof Kozlowski80e82ac2014-10-16 10:23:28 +0200982 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200983 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
984 GFP_KERNEL);
985 if (!s2mps11->ext_control_gpio)
986 return -ENOMEM;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200987 /*
988 * 0 is a valid GPIO so initialize all GPIO-s to negative value
989 * to indicate that external control won't be used for this regulator.
990 */
991 for (i = 0; i < s2mps11->rdev_num; i++)
992 s2mps11->ext_control_gpio[i] = -EINVAL;
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200993
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +0530994 if (!iodev->dev->of_node) {
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200995 if (iodev->pdata) {
996 pdata = iodev->pdata;
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +0530997 goto common_reg;
998 } else {
999 dev_err(pdev->dev.parent,
1000 "Platform data or DT node not supplied\n");
1001 return -ENODEV;
1002 }
1003 }
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301004
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001005 rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001006 if (!rdata)
1007 return -ENOMEM;
1008
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001009 for (i = 0; i < s2mps11->rdev_num; i++)
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301010 rdata[i].name = regulators[i].name;
1011
Chanwoo Choi00e25732014-06-25 16:14:45 +09001012 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001013 if (ret)
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001014 goto out;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301015
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301016common_reg:
1017 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001018
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301019 config.dev = &pdev->dev;
Krzysztof Kozlowski1b1ccee2013-12-11 15:07:43 +01001020 config.regmap = iodev->regmap_pmic;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301021 config.driver_data = s2mps11;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001022 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
Markus Pargmann1de38212014-11-03 19:12:04 +01001023 config.ena_gpio_initialized = true;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001024 for (i = 0; i < s2mps11->rdev_num; i++) {
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001025 struct regulator_dev *regulator;
1026
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001027 if (pdata) {
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301028 config.init_data = pdata->regulators[i].initdata;
Krzysztof Kozlowski54820f52014-01-30 14:51:19 +01001029 config.of_node = pdata->regulators[i].reg_node;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301030 } else {
1031 config.init_data = rdata[i].init_data;
1032 config.of_node = rdata[i].of_node;
1033 }
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001034 config.ena_gpio = s2mps11->ext_control_gpio[i];
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001035
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001036 regulator = devm_regulator_register(&pdev->dev,
Sachin Kamatd55cd792013-09-04 12:12:15 +05301037 &regulators[i], &config);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001038 if (IS_ERR(regulator)) {
1039 ret = PTR_ERR(regulator);
Axel Lin232b2502012-07-12 09:37:37 +08001040 dev_err(&pdev->dev, "regulator init failed for %d\n",
1041 i);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001042 goto out;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001043 }
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001044
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001045 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001046 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1047 regulator);
1048 if (ret < 0) {
1049 dev_err(&pdev->dev,
1050 "failed to enable GPIO control over %s: %d\n",
1051 regulator->desc->name, ret);
1052 goto out;
1053 }
1054 }
Sangbeom Kimcb746852012-07-11 21:08:17 +09001055 }
1056
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001057out:
1058 kfree(rdata);
1059
1060 return ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001061}
1062
1063static const struct platform_device_id s2mps11_pmic_id[] = {
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001064 { "s2mps11-pmic", S2MPS11X},
Chanwoo Choi76b98402014-11-18 17:59:40 +09001065 { "s2mps13-pmic", S2MPS13X},
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001066 { "s2mps14-pmic", S2MPS14X},
Chanwoo Choi00e25732014-06-25 16:14:45 +09001067 { "s2mpu02-pmic", S2MPU02},
Sangbeom Kimcb746852012-07-11 21:08:17 +09001068 { },
1069};
1070MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1071
1072static struct platform_driver s2mps11_pmic_driver = {
1073 .driver = {
1074 .name = "s2mps11-pmic",
Sangbeom Kimcb746852012-07-11 21:08:17 +09001075 },
1076 .probe = s2mps11_pmic_probe,
Sangbeom Kimcb746852012-07-11 21:08:17 +09001077 .id_table = s2mps11_pmic_id,
1078};
1079
1080static int __init s2mps11_pmic_init(void)
1081{
1082 return platform_driver_register(&s2mps11_pmic_driver);
1083}
1084subsys_initcall(s2mps11_pmic_init);
1085
1086static void __exit s2mps11_pmic_exit(void)
1087{
1088 platform_driver_unregister(&s2mps11_pmic_driver);
1089}
1090module_exit(s2mps11_pmic_exit);
1091
1092/* Module information */
1093MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Axel Lincad35c32014-07-23 16:47:31 +08001094MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPU02 Regulator Driver");
Sangbeom Kimcb746852012-07-11 21:08:17 +09001095MODULE_LICENSE("GPL");