blob: 02fb6b4ea8202704491d196b78b41da9a3623d9c [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>
Thomas Abraham51af2062015-11-20 16:07:52 +053035#include <linux/mfd/samsung/s2mps15.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090036#include <linux/mfd/samsung/s2mpu02.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053037
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +090038/* The highest number of possible regulators for supported devices. */
39#define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
Sangbeom Kimcb746852012-07-11 21:08:17 +090040struct s2mps11_info {
Sangbeom Kimcb746852012-07-11 21:08:17 +090041 int ramp_delay2;
42 int ramp_delay34;
43 int ramp_delay5;
44 int ramp_delay16;
45 int ramp_delay7810;
46 int ramp_delay9;
Chanwoo Choi00e25732014-06-25 16:14:45 +090047
48 enum sec_device_type dev_type;
49
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010050 /*
Chanwoo Choi76b98402014-11-18 17:59:40 +090051 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
52 * the suspend mode was enabled.
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010053 */
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +090054 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
Chanwoo Choi00e25732014-06-25 16:14:45 +090055
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +090056 /*
57 * Array (size: number of regulators) with GPIO-s for external
58 * sleep control.
59 */
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +020060 int *ext_control_gpio;
Sangbeom Kimcb746852012-07-11 21:08:17 +090061};
62
63static int get_ramp_delay(int ramp_delay)
64{
65 unsigned char cnt = 0;
66
Yadwinder Singh Brar90068342013-06-24 16:50:55 +053067 ramp_delay /= 6250;
Sangbeom Kimcb746852012-07-11 21:08:17 +090068
69 while (true) {
70 ramp_delay = ramp_delay >> 1;
71 if (ramp_delay == 0)
72 break;
73 cnt++;
74 }
Axel Linf8f1d482013-08-05 14:08:37 +080075
76 if (cnt > 3)
77 cnt = 3;
78
Sangbeom Kimcb746852012-07-11 21:08:17 +090079 return cnt;
80}
81
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053082static 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
Thiago Farinad55efa42014-01-26 21:57:12 -020090 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053091 case S2MPS11_BUCK2:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053092 ramp_delay = s2mps11->ramp_delay2;
93 break;
94 case S2MPS11_BUCK3:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053095 case S2MPS11_BUCK4:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053096 ramp_delay = s2mps11->ramp_delay34;
97 break;
98 case S2MPS11_BUCK5:
99 ramp_delay = s2mps11->ramp_delay5;
100 break;
101 case S2MPS11_BUCK6:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +0530102 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
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530123static 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
Thiago Farinad55efa42014-01-26 21:57:12 -0200130 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530131 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
Krzysztof Kozlowskib203e0d2014-05-06 08:37:36 +0200219 /* 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 }
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530229 }
230
231 ramp_val = get_ramp_delay(ramp_delay);
232
Axel Linf8f1d482013-08-05 14:08:37 +0800233 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
234 ramp_val << ramp_shift);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530235
236ramp_disable:
Axel Lin80853302013-08-03 17:10:42 +0800237 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
238 1 << enable_shift, 0);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530239}
240
Sangbeom Kimcb746852012-07-11 21:08:17 +0900241static 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
252static 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,
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +0530260 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530261 .set_ramp_delay = s2mps11_set_ramp_delay,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900262};
263
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530264#define regulator_desc_s2mps11_ldo(num, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900265 .name = "LDO"#num, \
266 .id = S2MPS11_LDO##num, \
267 .ops = &s2mps11_ldo_ops, \
268 .type = REGULATOR_VOLTAGE, \
269 .owner = THIS_MODULE, \
Krzysztof Kozlowski94be46b2016-04-18 15:33:10 +0200270 .ramp_delay = RAMP_DELAY_12_MVUS, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530271 .min_uV = MIN_800_MV, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530272 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900273 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
274 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800275 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900276 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
277 .enable_mask = S2MPS11_ENABLE_MASK \
278}
279
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100280#define regulator_desc_s2mps11_buck1_4(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900281 .name = "BUCK"#num, \
282 .id = S2MPS11_BUCK##num, \
283 .ops = &s2mps11_buck_ops, \
284 .type = REGULATOR_VOLTAGE, \
285 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530286 .min_uV = MIN_600_MV, \
287 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900288 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530289 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900290 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800291 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900292 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
293 .enable_mask = S2MPS11_ENABLE_MASK \
294}
295
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100296#define regulator_desc_s2mps11_buck5 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900297 .name = "BUCK5", \
298 .id = S2MPS11_BUCK5, \
299 .ops = &s2mps11_buck_ops, \
300 .type = REGULATOR_VOLTAGE, \
301 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530302 .min_uV = MIN_600_MV, \
303 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900304 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530305 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900306 .vsel_reg = S2MPS11_REG_B5CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800307 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900308 .enable_reg = S2MPS11_REG_B5CTRL1, \
309 .enable_mask = S2MPS11_ENABLE_MASK \
310}
311
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900312#define regulator_desc_s2mps11_buck67810(num, min, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900313 .name = "BUCK"#num, \
314 .id = S2MPS11_BUCK##num, \
315 .ops = &s2mps11_buck_ops, \
316 .type = REGULATOR_VOLTAGE, \
317 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530318 .min_uV = min, \
319 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900320 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530321 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900322 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800323 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900324 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
325 .enable_mask = S2MPS11_ENABLE_MASK \
326}
327
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900328#define regulator_desc_s2mps11_buck9 { \
329 .name = "BUCK9", \
330 .id = S2MPS11_BUCK9, \
331 .ops = &s2mps11_buck_ops, \
332 .type = REGULATOR_VOLTAGE, \
333 .owner = THIS_MODULE, \
334 .min_uV = MIN_3000_MV, \
335 .uV_step = STEP_25_MV, \
336 .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
337 .ramp_delay = S2MPS11_RAMP_DELAY, \
338 .vsel_reg = S2MPS11_REG_B9CTRL2, \
339 .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
340 .enable_reg = S2MPS11_REG_B9CTRL1, \
341 .enable_mask = S2MPS11_ENABLE_MASK \
342}
343
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100344static const struct regulator_desc s2mps11_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530345 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
346 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
348 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
349 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
350 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
351 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
353 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
356 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
361 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
362 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
363 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
364 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
365 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
366 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
367 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
368 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
369 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
370 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
371 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
372 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
373 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
374 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
375 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
376 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
377 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
378 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
379 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
380 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
381 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
382 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100383 regulator_desc_s2mps11_buck1_4(1),
384 regulator_desc_s2mps11_buck1_4(2),
385 regulator_desc_s2mps11_buck1_4(3),
386 regulator_desc_s2mps11_buck1_4(4),
387 regulator_desc_s2mps11_buck5,
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900388 regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV),
389 regulator_desc_s2mps11_buck67810(7, MIN_600_MV, STEP_6_25_MV),
390 regulator_desc_s2mps11_buck67810(8, MIN_600_MV, STEP_6_25_MV),
391 regulator_desc_s2mps11_buck9,
392 regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100393};
394
Chanwoo Choi76b98402014-11-18 17:59:40 +0900395static struct regulator_ops s2mps14_reg_ops;
396
397#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
398 .name = "LDO"#num, \
399 .id = S2MPS13_LDO##num, \
400 .ops = &s2mps14_reg_ops, \
401 .type = REGULATOR_VOLTAGE, \
402 .owner = THIS_MODULE, \
403 .min_uV = min, \
404 .uV_step = step, \
405 .linear_min_sel = min_sel, \
406 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
407 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
408 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
409 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
410 .enable_mask = S2MPS14_ENABLE_MASK \
411}
412
413#define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
414 .name = "BUCK"#num, \
415 .id = S2MPS13_BUCK##num, \
416 .ops = &s2mps14_reg_ops, \
417 .type = REGULATOR_VOLTAGE, \
418 .owner = THIS_MODULE, \
419 .min_uV = min, \
420 .uV_step = step, \
421 .linear_min_sel = min_sel, \
422 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
423 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
424 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
425 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
426 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
427 .enable_mask = S2MPS14_ENABLE_MASK \
428}
429
Jonghwa Leead26aa62015-01-08 11:04:07 +0900430#define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
431 .name = "BUCK"#num, \
432 .id = S2MPS13_BUCK##num, \
433 .ops = &s2mps14_reg_ops, \
434 .type = REGULATOR_VOLTAGE, \
435 .owner = THIS_MODULE, \
436 .min_uV = min, \
437 .uV_step = step, \
438 .linear_min_sel = min_sel, \
439 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
440 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
441 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
442 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
443 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
444 .enable_mask = S2MPS14_ENABLE_MASK \
445}
446
447#define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
448 .name = "BUCK"#num, \
449 .id = S2MPS13_BUCK##num, \
450 .ops = &s2mps14_reg_ops, \
451 .type = REGULATOR_VOLTAGE, \
452 .owner = THIS_MODULE, \
453 .min_uV = min, \
454 .uV_step = step, \
455 .linear_min_sel = min_sel, \
456 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
457 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
458 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
459 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
460 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
461 .enable_mask = S2MPS14_ENABLE_MASK \
462}
463
Chanwoo Choi76b98402014-11-18 17:59:40 +0900464static const struct regulator_desc s2mps13_regulators[] = {
465 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
466 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
467 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
468 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
469 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
470 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
471 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
472 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
473 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
474 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
475 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
476 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
477 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
478 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
479 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
480 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
481 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
482 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
483 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
484 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
485 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
486 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
487 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
488 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
489 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
490 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
491 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
492 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
493 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
494 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
495 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
496 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
497 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
498 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
499 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
500 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
501 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
502 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
503 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
504 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
505 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
506 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
507 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
508 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
509 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
510 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
Jonghwa Leead26aa62015-01-08 11:04:07 +0900511 regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
512 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
513 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
514 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
Chanwoo Choi76b98402014-11-18 17:59:40 +0900515};
516
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100517static int s2mps14_regulator_enable(struct regulator_dev *rdev)
518{
519 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
520 unsigned int val;
521
Chanwoo Choi00e25732014-06-25 16:14:45 +0900522 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900523 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900524 case S2MPS14X:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900525 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900526 val = S2MPS14_ENABLE_SUSPEND;
527 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
528 val = S2MPS14_ENABLE_EXT_CONTROL;
529 else
530 val = rdev->desc->enable_mask;
531 break;
532 case S2MPU02:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900533 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900534 val = S2MPU02_ENABLE_SUSPEND;
535 else
536 val = rdev->desc->enable_mask;
537 break;
538 default:
539 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900540 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100541
542 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
543 rdev->desc->enable_mask, val);
544}
545
546static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
547{
548 int ret;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900549 unsigned int val, state;
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100550 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900551 int rdev_id = rdev_get_id(rdev);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100552
Chanwoo Choi00e25732014-06-25 16:14:45 +0900553 /* Below LDO should be always on or does not support suspend mode. */
554 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900555 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900556 case S2MPS14X:
557 switch (rdev_id) {
558 case S2MPS14_LDO3:
559 return 0;
560 default:
561 state = S2MPS14_ENABLE_SUSPEND;
562 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900563 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900564 break;
565 case S2MPU02:
566 switch (rdev_id) {
567 case S2MPU02_LDO13:
568 case S2MPU02_LDO14:
569 case S2MPU02_LDO15:
570 case S2MPU02_LDO17:
571 case S2MPU02_BUCK7:
572 state = S2MPU02_DISABLE_SUSPEND;
573 break;
574 default:
575 state = S2MPU02_ENABLE_SUSPEND;
576 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900577 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900578 break;
579 default:
580 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900581 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100582
583 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
584 if (ret < 0)
585 return ret;
586
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900587 set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100588 /*
589 * Don't enable suspend mode if regulator is already disabled because
590 * this would effectively for a short time turn on the regulator after
591 * resuming.
592 * However we still want to toggle the suspend_state bit for regulator
593 * in case if it got enabled before suspending the system.
594 */
595 if (!(val & rdev->desc->enable_mask))
596 return 0;
597
598 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900599 rdev->desc->enable_mask, state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100600}
601
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100602static struct regulator_ops s2mps14_reg_ops = {
603 .list_voltage = regulator_list_voltage_linear,
604 .map_voltage = regulator_map_voltage_linear,
605 .is_enabled = regulator_is_enabled_regmap,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100606 .enable = s2mps14_regulator_enable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100607 .disable = regulator_disable_regmap,
608 .get_voltage_sel = regulator_get_voltage_sel_regmap,
609 .set_voltage_sel = regulator_set_voltage_sel_regmap,
610 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100611 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100612};
613
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530614#define regulator_desc_s2mps14_ldo(num, min, step) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100615 .name = "LDO"#num, \
616 .id = S2MPS14_LDO##num, \
617 .ops = &s2mps14_reg_ops, \
618 .type = REGULATOR_VOLTAGE, \
619 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530620 .min_uV = min, \
621 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100622 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
623 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
624 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
625 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
626 .enable_mask = S2MPS14_ENABLE_MASK \
627}
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530628
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100629#define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100630 .name = "BUCK"#num, \
631 .id = S2MPS14_BUCK##num, \
632 .ops = &s2mps14_reg_ops, \
633 .type = REGULATOR_VOLTAGE, \
634 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530635 .min_uV = min, \
636 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100637 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100638 .linear_min_sel = min_sel, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100639 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
640 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
641 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
642 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
643 .enable_mask = S2MPS14_ENABLE_MASK \
644}
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100645
646static const struct regulator_desc s2mps14_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530647 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
648 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
649 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
650 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
651 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
652 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
653 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
654 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
655 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
656 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
657 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
658 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
659 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
660 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
661 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
662 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
663 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
664 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
665 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
666 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
667 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
668 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
669 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
670 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
671 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100672 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
673 S2MPS14_BUCK1235_START_SEL),
674 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
675 S2MPS14_BUCK1235_START_SEL),
676 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
677 S2MPS14_BUCK1235_START_SEL),
678 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
679 S2MPS14_BUCK4_START_SEL),
680 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
681 S2MPS14_BUCK1235_START_SEL),
Sangbeom Kimcb746852012-07-11 21:08:17 +0900682};
683
Thomas Abraham51af2062015-11-20 16:07:52 +0530684static struct regulator_ops s2mps15_reg_ldo_ops = {
685 .list_voltage = regulator_list_voltage_linear_range,
686 .map_voltage = regulator_map_voltage_linear_range,
687 .is_enabled = regulator_is_enabled_regmap,
688 .enable = regulator_enable_regmap,
689 .disable = regulator_disable_regmap,
690 .get_voltage_sel = regulator_get_voltage_sel_regmap,
691 .set_voltage_sel = regulator_set_voltage_sel_regmap,
692};
693
694static struct regulator_ops s2mps15_reg_buck_ops = {
695 .list_voltage = regulator_list_voltage_linear_range,
696 .map_voltage = regulator_map_voltage_linear_range,
697 .is_enabled = regulator_is_enabled_regmap,
698 .enable = regulator_enable_regmap,
699 .disable = regulator_disable_regmap,
700 .get_voltage_sel = regulator_get_voltage_sel_regmap,
701 .set_voltage_sel = regulator_set_voltage_sel_regmap,
702 .set_voltage_time_sel = regulator_set_voltage_time_sel,
703};
704
705#define regulator_desc_s2mps15_ldo(num, range) { \
706 .name = "LDO"#num, \
707 .id = S2MPS15_LDO##num, \
708 .ops = &s2mps15_reg_ldo_ops, \
709 .type = REGULATOR_VOLTAGE, \
710 .owner = THIS_MODULE, \
711 .linear_ranges = range, \
712 .n_linear_ranges = ARRAY_SIZE(range), \
713 .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
714 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
715 .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
716 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
717 .enable_mask = S2MPS15_ENABLE_MASK \
718}
719
720#define regulator_desc_s2mps15_buck(num, range) { \
721 .name = "BUCK"#num, \
722 .id = S2MPS15_BUCK##num, \
723 .ops = &s2mps15_reg_buck_ops, \
724 .type = REGULATOR_VOLTAGE, \
725 .owner = THIS_MODULE, \
726 .linear_ranges = range, \
727 .n_linear_ranges = ARRAY_SIZE(range), \
728 .ramp_delay = 12500, \
729 .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
730 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
731 .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
732 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
733 .enable_mask = S2MPS15_ENABLE_MASK \
734}
735
736/* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
737static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
738 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
739};
740
741/* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
742static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
743 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
744};
745
746/* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
747static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
748 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
749};
750
751/* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
752static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
753 REGULATOR_LINEAR_RANGE(700000, 0xc, 0x18, 25000),
754};
755
756/* voltage range for s2mps15 LDO 1 */
757static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
758 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
759};
760
761/* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
762static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
763 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xb0, 6250),
764};
765
766/* voltage range for s2mps15 BUCK 8, 9 and 10 */
767static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
768 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0xc0, 12500),
769};
770
771static const struct regulator_desc s2mps15_regulators[] = {
772 regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
773 regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
774 regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
775 regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
776 regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
777 regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
778 regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
779 regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
780 regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
781 regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
782 regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
783 regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
784 regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
785 regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
786 regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
787 regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
788 regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
789 regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
790 regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
791 regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
792 regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
793 regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
794 regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
795 regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
796 regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
797 regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
798 regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
799 regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
800 regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
801 regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
802 regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
803 regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
804 regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
805 regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
806 regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
807 regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
808 regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
809};
810
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200811static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
812 struct regulator_dev *rdev)
813{
814 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
815 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
816}
817
818static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200819 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
820{
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200821 int *gpio = s2mps11->ext_control_gpio;
822 unsigned int i;
823 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
824 S2MPS14_LDO12 };
825
826 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
827 unsigned int reg = valid_regulators[i];
828
829 if (!rdata[reg].init_data || !rdata[reg].of_node)
830 continue;
831
832 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
833 "samsung,ext-control-gpios", 0);
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200834 if (gpio_is_valid(gpio[reg]))
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200835 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
836 gpio[reg], reg, rdata[reg].name);
837 }
838}
839
840static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +0900841 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
842 unsigned int rdev_num)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200843{
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200844 struct device_node *reg_np;
845
846 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
847 if (!reg_np) {
848 dev_err(&pdev->dev, "could not find regulators sub-node\n");
849 return -EINVAL;
850 }
851
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +0900852 of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900853 if (s2mps11->dev_type == S2MPS14X)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200854 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
855
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200856 of_node_put(reg_np);
857
858 return 0;
859}
860
Chanwoo Choi00e25732014-06-25 16:14:45 +0900861static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
862{
863 unsigned int ramp_val, ramp_shift, ramp_reg;
864
865 switch (rdev_get_id(rdev)) {
866 case S2MPU02_BUCK1:
867 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
868 break;
869 case S2MPU02_BUCK2:
870 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
871 break;
872 case S2MPU02_BUCK3:
873 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
874 break;
875 case S2MPU02_BUCK4:
876 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
877 break;
878 default:
879 return 0;
880 }
881 ramp_reg = S2MPU02_REG_RAMP1;
882 ramp_val = get_ramp_delay(ramp_delay);
883
884 return regmap_update_bits(rdev->regmap, ramp_reg,
885 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
886 ramp_val << ramp_shift);
887}
888
889static struct regulator_ops s2mpu02_ldo_ops = {
890 .list_voltage = regulator_list_voltage_linear,
891 .map_voltage = regulator_map_voltage_linear,
892 .is_enabled = regulator_is_enabled_regmap,
893 .enable = s2mps14_regulator_enable,
894 .disable = regulator_disable_regmap,
895 .get_voltage_sel = regulator_get_voltage_sel_regmap,
896 .set_voltage_sel = regulator_set_voltage_sel_regmap,
897 .set_voltage_time_sel = regulator_set_voltage_time_sel,
898 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
899};
900
901static struct regulator_ops s2mpu02_buck_ops = {
902 .list_voltage = regulator_list_voltage_linear,
903 .map_voltage = regulator_map_voltage_linear,
904 .is_enabled = regulator_is_enabled_regmap,
905 .enable = s2mps14_regulator_enable,
906 .disable = regulator_disable_regmap,
907 .get_voltage_sel = regulator_get_voltage_sel_regmap,
908 .set_voltage_sel = regulator_set_voltage_sel_regmap,
909 .set_voltage_time_sel = regulator_set_voltage_time_sel,
910 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
911 .set_ramp_delay = s2mpu02_set_ramp_delay,
912};
913
914#define regulator_desc_s2mpu02_ldo1(num) { \
915 .name = "LDO"#num, \
916 .id = S2MPU02_LDO##num, \
917 .ops = &s2mpu02_ldo_ops, \
918 .type = REGULATOR_VOLTAGE, \
919 .owner = THIS_MODULE, \
920 .min_uV = S2MPU02_LDO_MIN_900MV, \
921 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
922 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
923 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
924 .vsel_reg = S2MPU02_REG_L1CTRL, \
925 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
926 .enable_reg = S2MPU02_REG_L1CTRL, \
927 .enable_mask = S2MPU02_ENABLE_MASK \
928}
929#define regulator_desc_s2mpu02_ldo2(num) { \
930 .name = "LDO"#num, \
931 .id = S2MPU02_LDO##num, \
932 .ops = &s2mpu02_ldo_ops, \
933 .type = REGULATOR_VOLTAGE, \
934 .owner = THIS_MODULE, \
935 .min_uV = S2MPU02_LDO_MIN_1050MV, \
936 .uV_step = S2MPU02_LDO_STEP_25MV, \
937 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
938 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
939 .vsel_reg = S2MPU02_REG_L2CTRL1, \
940 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
941 .enable_reg = S2MPU02_REG_L2CTRL1, \
942 .enable_mask = S2MPU02_ENABLE_MASK \
943}
944#define regulator_desc_s2mpu02_ldo3(num) { \
945 .name = "LDO"#num, \
946 .id = S2MPU02_LDO##num, \
947 .ops = &s2mpu02_ldo_ops, \
948 .type = REGULATOR_VOLTAGE, \
949 .owner = THIS_MODULE, \
950 .min_uV = S2MPU02_LDO_MIN_900MV, \
951 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
952 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
953 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
954 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
955 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
956 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
957 .enable_mask = S2MPU02_ENABLE_MASK \
958}
959#define regulator_desc_s2mpu02_ldo4(num) { \
960 .name = "LDO"#num, \
961 .id = S2MPU02_LDO##num, \
962 .ops = &s2mpu02_ldo_ops, \
963 .type = REGULATOR_VOLTAGE, \
964 .owner = THIS_MODULE, \
965 .min_uV = S2MPU02_LDO_MIN_1050MV, \
966 .uV_step = S2MPU02_LDO_STEP_25MV, \
967 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
968 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
969 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
970 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
971 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
972 .enable_mask = S2MPU02_ENABLE_MASK \
973}
974#define regulator_desc_s2mpu02_ldo5(num) { \
975 .name = "LDO"#num, \
976 .id = S2MPU02_LDO##num, \
977 .ops = &s2mpu02_ldo_ops, \
978 .type = REGULATOR_VOLTAGE, \
979 .owner = THIS_MODULE, \
980 .min_uV = S2MPU02_LDO_MIN_1600MV, \
981 .uV_step = S2MPU02_LDO_STEP_50MV, \
982 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
983 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
984 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
985 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
986 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
987 .enable_mask = S2MPU02_ENABLE_MASK \
988}
989
990#define regulator_desc_s2mpu02_buck1234(num) { \
991 .name = "BUCK"#num, \
992 .id = S2MPU02_BUCK##num, \
993 .ops = &s2mpu02_buck_ops, \
994 .type = REGULATOR_VOLTAGE, \
995 .owner = THIS_MODULE, \
996 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
997 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
998 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
999 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
1000 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1001 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
1002 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1003 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
1004 .enable_mask = S2MPU02_ENABLE_MASK \
1005}
1006#define regulator_desc_s2mpu02_buck5(num) { \
1007 .name = "BUCK"#num, \
1008 .id = S2MPU02_BUCK##num, \
1009 .ops = &s2mpu02_ldo_ops, \
1010 .type = REGULATOR_VOLTAGE, \
1011 .owner = THIS_MODULE, \
1012 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
1013 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
1014 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1015 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
1016 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1017 .vsel_reg = S2MPU02_REG_B5CTRL2, \
1018 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1019 .enable_reg = S2MPU02_REG_B5CTRL1, \
1020 .enable_mask = S2MPU02_ENABLE_MASK \
1021}
1022#define regulator_desc_s2mpu02_buck6(num) { \
1023 .name = "BUCK"#num, \
1024 .id = S2MPU02_BUCK##num, \
1025 .ops = &s2mpu02_ldo_ops, \
1026 .type = REGULATOR_VOLTAGE, \
1027 .owner = THIS_MODULE, \
1028 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
1029 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
1030 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1031 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
1032 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1033 .vsel_reg = S2MPU02_REG_B6CTRL2, \
1034 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1035 .enable_reg = S2MPU02_REG_B6CTRL1, \
1036 .enable_mask = S2MPU02_ENABLE_MASK \
1037}
1038#define regulator_desc_s2mpu02_buck7(num) { \
1039 .name = "BUCK"#num, \
1040 .id = S2MPU02_BUCK##num, \
1041 .ops = &s2mpu02_ldo_ops, \
1042 .type = REGULATOR_VOLTAGE, \
1043 .owner = THIS_MODULE, \
1044 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
1045 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
1046 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1047 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
1048 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1049 .vsel_reg = S2MPU02_REG_B7CTRL2, \
1050 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1051 .enable_reg = S2MPU02_REG_B7CTRL1, \
1052 .enable_mask = S2MPU02_ENABLE_MASK \
1053}
1054
1055static const struct regulator_desc s2mpu02_regulators[] = {
1056 regulator_desc_s2mpu02_ldo1(1),
1057 regulator_desc_s2mpu02_ldo2(2),
1058 regulator_desc_s2mpu02_ldo4(3),
1059 regulator_desc_s2mpu02_ldo5(4),
1060 regulator_desc_s2mpu02_ldo4(5),
1061 regulator_desc_s2mpu02_ldo3(6),
1062 regulator_desc_s2mpu02_ldo3(7),
1063 regulator_desc_s2mpu02_ldo4(8),
1064 regulator_desc_s2mpu02_ldo5(9),
1065 regulator_desc_s2mpu02_ldo3(10),
1066 regulator_desc_s2mpu02_ldo4(11),
1067 regulator_desc_s2mpu02_ldo5(12),
1068 regulator_desc_s2mpu02_ldo5(13),
1069 regulator_desc_s2mpu02_ldo5(14),
1070 regulator_desc_s2mpu02_ldo5(15),
1071 regulator_desc_s2mpu02_ldo5(16),
1072 regulator_desc_s2mpu02_ldo4(17),
1073 regulator_desc_s2mpu02_ldo5(18),
1074 regulator_desc_s2mpu02_ldo3(19),
1075 regulator_desc_s2mpu02_ldo4(20),
1076 regulator_desc_s2mpu02_ldo5(21),
1077 regulator_desc_s2mpu02_ldo5(22),
1078 regulator_desc_s2mpu02_ldo5(23),
1079 regulator_desc_s2mpu02_ldo4(24),
1080 regulator_desc_s2mpu02_ldo5(25),
1081 regulator_desc_s2mpu02_ldo4(26),
1082 regulator_desc_s2mpu02_ldo5(27),
1083 regulator_desc_s2mpu02_ldo5(28),
1084 regulator_desc_s2mpu02_buck1234(1),
1085 regulator_desc_s2mpu02_buck1234(2),
1086 regulator_desc_s2mpu02_buck1234(3),
1087 regulator_desc_s2mpu02_buck1234(4),
1088 regulator_desc_s2mpu02_buck5(5),
1089 regulator_desc_s2mpu02_buck6(6),
1090 regulator_desc_s2mpu02_buck7(7),
1091};
1092
Bill Pembertona5023572012-11-19 13:22:22 -05001093static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +09001094{
1095 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001096 struct sec_platform_data *pdata = NULL;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001097 struct of_regulator_match *rdata = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001098 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +09001099 struct s2mps11_info *s2mps11;
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001100 unsigned int rdev_num = 0;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001101 int i, ret = 0;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001102 const struct regulator_desc *regulators;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001103
Sangbeom Kimcb746852012-07-11 21:08:17 +09001104 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1105 GFP_KERNEL);
1106 if (!s2mps11)
1107 return -ENOMEM;
1108
Chanwoo Choi00e25732014-06-25 16:14:45 +09001109 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
1110 switch (s2mps11->dev_type) {
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001111 case S2MPS11X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001112 rdev_num = ARRAY_SIZE(s2mps11_regulators);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001113 regulators = s2mps11_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001114 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001115 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +09001116 case S2MPS13X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001117 rdev_num = ARRAY_SIZE(s2mps13_regulators);
Chanwoo Choi76b98402014-11-18 17:59:40 +09001118 regulators = s2mps13_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001119 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
Chanwoo Choi76b98402014-11-18 17:59:40 +09001120 break;
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001121 case S2MPS14X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001122 rdev_num = ARRAY_SIZE(s2mps14_regulators);
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001123 regulators = s2mps14_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001124 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001125 break;
Thomas Abraham51af2062015-11-20 16:07:52 +05301126 case S2MPS15X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001127 rdev_num = ARRAY_SIZE(s2mps15_regulators);
Thomas Abraham51af2062015-11-20 16:07:52 +05301128 regulators = s2mps15_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001129 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
Thomas Abraham51af2062015-11-20 16:07:52 +05301130 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +09001131 case S2MPU02:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001132 rdev_num = ARRAY_SIZE(s2mpu02_regulators);
Chanwoo Choi00e25732014-06-25 16:14:45 +09001133 regulators = s2mpu02_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001134 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
Chanwoo Choi00e25732014-06-25 16:14:45 +09001135 break;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001136 default:
Chanwoo Choi00e25732014-06-25 16:14:45 +09001137 dev_err(&pdev->dev, "Invalid device type: %u\n",
1138 s2mps11->dev_type);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001139 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +09001140 }
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001141
Krzysztof Kozlowski80e82ac2014-10-16 10:23:28 +02001142 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001143 sizeof(*s2mps11->ext_control_gpio) * rdev_num,
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001144 GFP_KERNEL);
1145 if (!s2mps11->ext_control_gpio)
1146 return -ENOMEM;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001147 /*
1148 * 0 is a valid GPIO so initialize all GPIO-s to negative value
1149 * to indicate that external control won't be used for this regulator.
1150 */
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001151 for (i = 0; i < rdev_num; i++)
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001152 s2mps11->ext_control_gpio[i] = -EINVAL;
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001153
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301154 if (!iodev->dev->of_node) {
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001155 if (iodev->pdata) {
1156 pdata = iodev->pdata;
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301157 goto common_reg;
1158 } else {
1159 dev_err(pdev->dev.parent,
1160 "Platform data or DT node not supplied\n");
1161 return -ENODEV;
1162 }
1163 }
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301164
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001165 rdata = kzalloc(sizeof(*rdata) * rdev_num, GFP_KERNEL);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001166 if (!rdata)
1167 return -ENOMEM;
1168
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001169 for (i = 0; i < rdev_num; i++)
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301170 rdata[i].name = regulators[i].name;
1171
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001172 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001173 if (ret)
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001174 goto out;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301175
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301176common_reg:
1177 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001178
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301179 config.dev = &pdev->dev;
Krzysztof Kozlowski1b1ccee2013-12-11 15:07:43 +01001180 config.regmap = iodev->regmap_pmic;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301181 config.driver_data = s2mps11;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001182 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
Markus Pargmann1de38212014-11-03 19:12:04 +01001183 config.ena_gpio_initialized = true;
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001184 for (i = 0; i < rdev_num; i++) {
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001185 struct regulator_dev *regulator;
1186
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001187 if (pdata) {
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301188 config.init_data = pdata->regulators[i].initdata;
Krzysztof Kozlowski54820f52014-01-30 14:51:19 +01001189 config.of_node = pdata->regulators[i].reg_node;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301190 } else {
1191 config.init_data = rdata[i].init_data;
1192 config.of_node = rdata[i].of_node;
1193 }
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001194 config.ena_gpio = s2mps11->ext_control_gpio[i];
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001195
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001196 regulator = devm_regulator_register(&pdev->dev,
Sachin Kamatd55cd792013-09-04 12:12:15 +05301197 &regulators[i], &config);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001198 if (IS_ERR(regulator)) {
1199 ret = PTR_ERR(regulator);
Axel Lin232b2502012-07-12 09:37:37 +08001200 dev_err(&pdev->dev, "regulator init failed for %d\n",
1201 i);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001202 goto out;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001203 }
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001204
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001205 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001206 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1207 regulator);
1208 if (ret < 0) {
1209 dev_err(&pdev->dev,
1210 "failed to enable GPIO control over %s: %d\n",
1211 regulator->desc->name, ret);
1212 goto out;
1213 }
1214 }
Sangbeom Kimcb746852012-07-11 21:08:17 +09001215 }
1216
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001217out:
1218 kfree(rdata);
1219
1220 return ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001221}
1222
1223static const struct platform_device_id s2mps11_pmic_id[] = {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301224 { "s2mps11-regulator", S2MPS11X},
1225 { "s2mps13-regulator", S2MPS13X},
1226 { "s2mps14-regulator", S2MPS14X},
Thomas Abraham51af2062015-11-20 16:07:52 +05301227 { "s2mps15-regulator", S2MPS15X},
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301228 { "s2mpu02-regulator", S2MPU02},
Sangbeom Kimcb746852012-07-11 21:08:17 +09001229 { },
1230};
1231MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1232
1233static struct platform_driver s2mps11_pmic_driver = {
1234 .driver = {
1235 .name = "s2mps11-pmic",
Sangbeom Kimcb746852012-07-11 21:08:17 +09001236 },
1237 .probe = s2mps11_pmic_probe,
Sangbeom Kimcb746852012-07-11 21:08:17 +09001238 .id_table = s2mps11_pmic_id,
1239};
1240
Javier Martinez Canillas5ab3c492016-04-06 09:49:46 -04001241module_platform_driver(s2mps11_pmic_driver);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001242
1243/* Module information */
1244MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Thomas Abraham51af2062015-11-20 16:07:52 +05301245MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
Sangbeom Kimcb746852012-07-11 21:08:17 +09001246MODULE_LICENSE("GPL");