blob: 6dfa3502e1f1a5ed7532d15157856c30e8d3bb7c [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 Brar1e1598e2013-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 Brar1e1598e2013-06-24 16:50:56 +053091 case S2MPS11_BUCK2:
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053092 ramp_delay = s2mps11->ramp_delay2;
93 break;
94 case S2MPS11_BUCK3:
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053095 case S2MPS11_BUCK4:
Yadwinder Singh Brar1e1598e2013-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 Brar1e1598e2013-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 Brar1e1598e2013-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, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530270 .min_uV = MIN_800_MV, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530271 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900272 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
273 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800274 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900275 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
276 .enable_mask = S2MPS11_ENABLE_MASK \
277}
278
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100279#define regulator_desc_s2mps11_buck1_4(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900280 .name = "BUCK"#num, \
281 .id = S2MPS11_BUCK##num, \
282 .ops = &s2mps11_buck_ops, \
283 .type = REGULATOR_VOLTAGE, \
284 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530285 .min_uV = MIN_600_MV, \
286 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900287 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530288 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900289 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800290 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900291 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
292 .enable_mask = S2MPS11_ENABLE_MASK \
293}
294
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100295#define regulator_desc_s2mps11_buck5 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900296 .name = "BUCK5", \
297 .id = S2MPS11_BUCK5, \
298 .ops = &s2mps11_buck_ops, \
299 .type = REGULATOR_VOLTAGE, \
300 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530301 .min_uV = MIN_600_MV, \
302 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900303 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530304 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900305 .vsel_reg = S2MPS11_REG_B5CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800306 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900307 .enable_reg = S2MPS11_REG_B5CTRL1, \
308 .enable_mask = S2MPS11_ENABLE_MASK \
309}
310
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900311#define regulator_desc_s2mps11_buck67810(num, min, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900312 .name = "BUCK"#num, \
313 .id = S2MPS11_BUCK##num, \
314 .ops = &s2mps11_buck_ops, \
315 .type = REGULATOR_VOLTAGE, \
316 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530317 .min_uV = min, \
318 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900319 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530320 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900321 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800322 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900323 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
324 .enable_mask = S2MPS11_ENABLE_MASK \
325}
326
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900327#define regulator_desc_s2mps11_buck9 { \
328 .name = "BUCK9", \
329 .id = S2MPS11_BUCK9, \
330 .ops = &s2mps11_buck_ops, \
331 .type = REGULATOR_VOLTAGE, \
332 .owner = THIS_MODULE, \
333 .min_uV = MIN_3000_MV, \
334 .uV_step = STEP_25_MV, \
335 .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
336 .ramp_delay = S2MPS11_RAMP_DELAY, \
337 .vsel_reg = S2MPS11_REG_B9CTRL2, \
338 .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
339 .enable_reg = S2MPS11_REG_B9CTRL1, \
340 .enable_mask = S2MPS11_ENABLE_MASK \
341}
342
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100343static const struct regulator_desc s2mps11_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530344 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
345 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
346 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
348 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
349 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
350 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
353 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
355 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
361 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
362 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
363 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
364 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
365 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
366 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
367 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
368 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
369 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
370 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
371 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
372 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
373 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
374 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
375 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
376 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
377 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
378 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
379 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
380 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
381 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100382 regulator_desc_s2mps11_buck1_4(1),
383 regulator_desc_s2mps11_buck1_4(2),
384 regulator_desc_s2mps11_buck1_4(3),
385 regulator_desc_s2mps11_buck1_4(4),
386 regulator_desc_s2mps11_buck5,
Krzysztof Kozlowski3b672622016-03-28 13:09:56 +0900387 regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV),
388 regulator_desc_s2mps11_buck67810(7, MIN_600_MV, STEP_6_25_MV),
389 regulator_desc_s2mps11_buck67810(8, MIN_600_MV, STEP_6_25_MV),
390 regulator_desc_s2mps11_buck9,
391 regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100392};
393
Chanwoo Choi76b98402014-11-18 17:59:40 +0900394static struct regulator_ops s2mps14_reg_ops;
395
396#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
397 .name = "LDO"#num, \
398 .id = S2MPS13_LDO##num, \
399 .ops = &s2mps14_reg_ops, \
400 .type = REGULATOR_VOLTAGE, \
401 .owner = THIS_MODULE, \
402 .min_uV = min, \
403 .uV_step = step, \
404 .linear_min_sel = min_sel, \
405 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
406 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
407 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
408 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
409 .enable_mask = S2MPS14_ENABLE_MASK \
410}
411
412#define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
413 .name = "BUCK"#num, \
414 .id = S2MPS13_BUCK##num, \
415 .ops = &s2mps14_reg_ops, \
416 .type = REGULATOR_VOLTAGE, \
417 .owner = THIS_MODULE, \
418 .min_uV = min, \
419 .uV_step = step, \
420 .linear_min_sel = min_sel, \
421 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
422 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
423 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
424 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
425 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
426 .enable_mask = S2MPS14_ENABLE_MASK \
427}
428
Jonghwa Leead26aa62015-01-08 11:04:07 +0900429#define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
430 .name = "BUCK"#num, \
431 .id = S2MPS13_BUCK##num, \
432 .ops = &s2mps14_reg_ops, \
433 .type = REGULATOR_VOLTAGE, \
434 .owner = THIS_MODULE, \
435 .min_uV = min, \
436 .uV_step = step, \
437 .linear_min_sel = min_sel, \
438 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
439 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
440 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
441 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
442 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
443 .enable_mask = S2MPS14_ENABLE_MASK \
444}
445
446#define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
447 .name = "BUCK"#num, \
448 .id = S2MPS13_BUCK##num, \
449 .ops = &s2mps14_reg_ops, \
450 .type = REGULATOR_VOLTAGE, \
451 .owner = THIS_MODULE, \
452 .min_uV = min, \
453 .uV_step = step, \
454 .linear_min_sel = min_sel, \
455 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
456 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
457 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
458 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
459 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
460 .enable_mask = S2MPS14_ENABLE_MASK \
461}
462
Chanwoo Choi76b98402014-11-18 17:59:40 +0900463static const struct regulator_desc s2mps13_regulators[] = {
464 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
465 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
466 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
467 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
468 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
469 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
470 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
471 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
472 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
473 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
474 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
475 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
476 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
477 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
478 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
479 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
480 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
481 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
482 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
483 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
484 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
485 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
486 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
487 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
488 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
489 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
490 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
491 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
492 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
493 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
494 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
495 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
496 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
497 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
498 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
499 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
500 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
501 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
502 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
503 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
504 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
505 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
506 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
507 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
508 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
509 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
Jonghwa Leead26aa62015-01-08 11:04:07 +0900510 regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
511 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
512 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
513 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
Chanwoo Choi76b98402014-11-18 17:59:40 +0900514};
515
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100516static int s2mps14_regulator_enable(struct regulator_dev *rdev)
517{
518 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
519 unsigned int val;
520
Chanwoo Choi00e25732014-06-25 16:14:45 +0900521 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900522 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900523 case S2MPS14X:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900524 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900525 val = S2MPS14_ENABLE_SUSPEND;
526 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
527 val = S2MPS14_ENABLE_EXT_CONTROL;
528 else
529 val = rdev->desc->enable_mask;
530 break;
531 case S2MPU02:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900532 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900533 val = S2MPU02_ENABLE_SUSPEND;
534 else
535 val = rdev->desc->enable_mask;
536 break;
537 default:
538 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900539 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100540
541 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
542 rdev->desc->enable_mask, val);
543}
544
545static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
546{
547 int ret;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900548 unsigned int val, state;
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100549 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900550 int rdev_id = rdev_get_id(rdev);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100551
Chanwoo Choi00e25732014-06-25 16:14:45 +0900552 /* Below LDO should be always on or does not support suspend mode. */
553 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900554 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900555 case S2MPS14X:
556 switch (rdev_id) {
557 case S2MPS14_LDO3:
558 return 0;
559 default:
560 state = S2MPS14_ENABLE_SUSPEND;
561 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900562 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900563 break;
564 case S2MPU02:
565 switch (rdev_id) {
566 case S2MPU02_LDO13:
567 case S2MPU02_LDO14:
568 case S2MPU02_LDO15:
569 case S2MPU02_LDO17:
570 case S2MPU02_BUCK7:
571 state = S2MPU02_DISABLE_SUSPEND;
572 break;
573 default:
574 state = S2MPU02_ENABLE_SUSPEND;
575 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900576 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900577 break;
578 default:
579 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900580 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100581
582 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
583 if (ret < 0)
584 return ret;
585
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900586 set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100587 /*
588 * Don't enable suspend mode if regulator is already disabled because
589 * this would effectively for a short time turn on the regulator after
590 * resuming.
591 * However we still want to toggle the suspend_state bit for regulator
592 * in case if it got enabled before suspending the system.
593 */
594 if (!(val & rdev->desc->enable_mask))
595 return 0;
596
597 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900598 rdev->desc->enable_mask, state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100599}
600
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100601static struct regulator_ops s2mps14_reg_ops = {
602 .list_voltage = regulator_list_voltage_linear,
603 .map_voltage = regulator_map_voltage_linear,
604 .is_enabled = regulator_is_enabled_regmap,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100605 .enable = s2mps14_regulator_enable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100606 .disable = regulator_disable_regmap,
607 .get_voltage_sel = regulator_get_voltage_sel_regmap,
608 .set_voltage_sel = regulator_set_voltage_sel_regmap,
609 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100610 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100611};
612
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530613#define regulator_desc_s2mps14_ldo(num, min, step) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100614 .name = "LDO"#num, \
615 .id = S2MPS14_LDO##num, \
616 .ops = &s2mps14_reg_ops, \
617 .type = REGULATOR_VOLTAGE, \
618 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530619 .min_uV = min, \
620 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100621 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
622 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
623 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
624 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
625 .enable_mask = S2MPS14_ENABLE_MASK \
626}
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530627
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100628#define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100629 .name = "BUCK"#num, \
630 .id = S2MPS14_BUCK##num, \
631 .ops = &s2mps14_reg_ops, \
632 .type = REGULATOR_VOLTAGE, \
633 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530634 .min_uV = min, \
635 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100636 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100637 .linear_min_sel = min_sel, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100638 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
639 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
640 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
641 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
642 .enable_mask = S2MPS14_ENABLE_MASK \
643}
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100644
645static const struct regulator_desc s2mps14_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530646 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
647 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
648 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
649 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
650 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
651 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
652 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
653 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
654 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
655 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
656 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
657 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
658 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
659 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
660 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
661 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
662 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
663 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
664 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
665 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
666 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
667 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
668 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
669 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
670 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100671 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
672 S2MPS14_BUCK1235_START_SEL),
673 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
674 S2MPS14_BUCK1235_START_SEL),
675 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
676 S2MPS14_BUCK1235_START_SEL),
677 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
678 S2MPS14_BUCK4_START_SEL),
679 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
680 S2MPS14_BUCK1235_START_SEL),
Sangbeom Kimcb746852012-07-11 21:08:17 +0900681};
682
Thomas Abraham51af2062015-11-20 16:07:52 +0530683static struct regulator_ops s2mps15_reg_ldo_ops = {
684 .list_voltage = regulator_list_voltage_linear_range,
685 .map_voltage = regulator_map_voltage_linear_range,
686 .is_enabled = regulator_is_enabled_regmap,
687 .enable = regulator_enable_regmap,
688 .disable = regulator_disable_regmap,
689 .get_voltage_sel = regulator_get_voltage_sel_regmap,
690 .set_voltage_sel = regulator_set_voltage_sel_regmap,
691};
692
693static struct regulator_ops s2mps15_reg_buck_ops = {
694 .list_voltage = regulator_list_voltage_linear_range,
695 .map_voltage = regulator_map_voltage_linear_range,
696 .is_enabled = regulator_is_enabled_regmap,
697 .enable = regulator_enable_regmap,
698 .disable = regulator_disable_regmap,
699 .get_voltage_sel = regulator_get_voltage_sel_regmap,
700 .set_voltage_sel = regulator_set_voltage_sel_regmap,
701 .set_voltage_time_sel = regulator_set_voltage_time_sel,
702};
703
704#define regulator_desc_s2mps15_ldo(num, range) { \
705 .name = "LDO"#num, \
706 .id = S2MPS15_LDO##num, \
707 .ops = &s2mps15_reg_ldo_ops, \
708 .type = REGULATOR_VOLTAGE, \
709 .owner = THIS_MODULE, \
710 .linear_ranges = range, \
711 .n_linear_ranges = ARRAY_SIZE(range), \
712 .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
713 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
714 .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
715 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
716 .enable_mask = S2MPS15_ENABLE_MASK \
717}
718
719#define regulator_desc_s2mps15_buck(num, range) { \
720 .name = "BUCK"#num, \
721 .id = S2MPS15_BUCK##num, \
722 .ops = &s2mps15_reg_buck_ops, \
723 .type = REGULATOR_VOLTAGE, \
724 .owner = THIS_MODULE, \
725 .linear_ranges = range, \
726 .n_linear_ranges = ARRAY_SIZE(range), \
727 .ramp_delay = 12500, \
728 .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
729 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
730 .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
731 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
732 .enable_mask = S2MPS15_ENABLE_MASK \
733}
734
735/* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
736static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
737 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
738};
739
740/* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
741static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
742 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
743};
744
745/* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
746static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
747 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
748};
749
750/* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
751static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
752 REGULATOR_LINEAR_RANGE(700000, 0xc, 0x18, 25000),
753};
754
755/* voltage range for s2mps15 LDO 1 */
756static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
757 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
758};
759
760/* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
761static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
762 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xb0, 6250),
763};
764
765/* voltage range for s2mps15 BUCK 8, 9 and 10 */
766static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
767 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0xc0, 12500),
768};
769
770static const struct regulator_desc s2mps15_regulators[] = {
771 regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
772 regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
773 regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
774 regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
775 regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
776 regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
777 regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
778 regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
779 regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
780 regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
781 regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
782 regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
783 regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
784 regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
785 regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
786 regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
787 regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
788 regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
789 regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
790 regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
791 regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
792 regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
793 regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
794 regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
795 regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
796 regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
797 regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
798 regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
799 regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
800 regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
801 regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
802 regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
803 regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
804 regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
805 regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
806 regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
807 regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
808};
809
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200810static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
811 struct regulator_dev *rdev)
812{
813 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
814 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
815}
816
817static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200818 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
819{
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200820 int *gpio = s2mps11->ext_control_gpio;
821 unsigned int i;
822 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
823 S2MPS14_LDO12 };
824
825 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
826 unsigned int reg = valid_regulators[i];
827
828 if (!rdata[reg].init_data || !rdata[reg].of_node)
829 continue;
830
831 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
832 "samsung,ext-control-gpios", 0);
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200833 if (gpio_is_valid(gpio[reg]))
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200834 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
835 gpio[reg], reg, rdata[reg].name);
836 }
837}
838
839static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +0900840 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
841 unsigned int rdev_num)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200842{
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200843 struct device_node *reg_np;
844
845 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
846 if (!reg_np) {
847 dev_err(&pdev->dev, "could not find regulators sub-node\n");
848 return -EINVAL;
849 }
850
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +0900851 of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900852 if (s2mps11->dev_type == S2MPS14X)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200853 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
854
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200855 of_node_put(reg_np);
856
857 return 0;
858}
859
Chanwoo Choi00e25732014-06-25 16:14:45 +0900860static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
861{
862 unsigned int ramp_val, ramp_shift, ramp_reg;
863
864 switch (rdev_get_id(rdev)) {
865 case S2MPU02_BUCK1:
866 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
867 break;
868 case S2MPU02_BUCK2:
869 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
870 break;
871 case S2MPU02_BUCK3:
872 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
873 break;
874 case S2MPU02_BUCK4:
875 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
876 break;
877 default:
878 return 0;
879 }
880 ramp_reg = S2MPU02_REG_RAMP1;
881 ramp_val = get_ramp_delay(ramp_delay);
882
883 return regmap_update_bits(rdev->regmap, ramp_reg,
884 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
885 ramp_val << ramp_shift);
886}
887
888static struct regulator_ops s2mpu02_ldo_ops = {
889 .list_voltage = regulator_list_voltage_linear,
890 .map_voltage = regulator_map_voltage_linear,
891 .is_enabled = regulator_is_enabled_regmap,
892 .enable = s2mps14_regulator_enable,
893 .disable = regulator_disable_regmap,
894 .get_voltage_sel = regulator_get_voltage_sel_regmap,
895 .set_voltage_sel = regulator_set_voltage_sel_regmap,
896 .set_voltage_time_sel = regulator_set_voltage_time_sel,
897 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
898};
899
900static struct regulator_ops s2mpu02_buck_ops = {
901 .list_voltage = regulator_list_voltage_linear,
902 .map_voltage = regulator_map_voltage_linear,
903 .is_enabled = regulator_is_enabled_regmap,
904 .enable = s2mps14_regulator_enable,
905 .disable = regulator_disable_regmap,
906 .get_voltage_sel = regulator_get_voltage_sel_regmap,
907 .set_voltage_sel = regulator_set_voltage_sel_regmap,
908 .set_voltage_time_sel = regulator_set_voltage_time_sel,
909 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
910 .set_ramp_delay = s2mpu02_set_ramp_delay,
911};
912
913#define regulator_desc_s2mpu02_ldo1(num) { \
914 .name = "LDO"#num, \
915 .id = S2MPU02_LDO##num, \
916 .ops = &s2mpu02_ldo_ops, \
917 .type = REGULATOR_VOLTAGE, \
918 .owner = THIS_MODULE, \
919 .min_uV = S2MPU02_LDO_MIN_900MV, \
920 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
921 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
922 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
923 .vsel_reg = S2MPU02_REG_L1CTRL, \
924 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
925 .enable_reg = S2MPU02_REG_L1CTRL, \
926 .enable_mask = S2MPU02_ENABLE_MASK \
927}
928#define regulator_desc_s2mpu02_ldo2(num) { \
929 .name = "LDO"#num, \
930 .id = S2MPU02_LDO##num, \
931 .ops = &s2mpu02_ldo_ops, \
932 .type = REGULATOR_VOLTAGE, \
933 .owner = THIS_MODULE, \
934 .min_uV = S2MPU02_LDO_MIN_1050MV, \
935 .uV_step = S2MPU02_LDO_STEP_25MV, \
936 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
937 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
938 .vsel_reg = S2MPU02_REG_L2CTRL1, \
939 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
940 .enable_reg = S2MPU02_REG_L2CTRL1, \
941 .enable_mask = S2MPU02_ENABLE_MASK \
942}
943#define regulator_desc_s2mpu02_ldo3(num) { \
944 .name = "LDO"#num, \
945 .id = S2MPU02_LDO##num, \
946 .ops = &s2mpu02_ldo_ops, \
947 .type = REGULATOR_VOLTAGE, \
948 .owner = THIS_MODULE, \
949 .min_uV = S2MPU02_LDO_MIN_900MV, \
950 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
951 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
952 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
953 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
954 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
955 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
956 .enable_mask = S2MPU02_ENABLE_MASK \
957}
958#define regulator_desc_s2mpu02_ldo4(num) { \
959 .name = "LDO"#num, \
960 .id = S2MPU02_LDO##num, \
961 .ops = &s2mpu02_ldo_ops, \
962 .type = REGULATOR_VOLTAGE, \
963 .owner = THIS_MODULE, \
964 .min_uV = S2MPU02_LDO_MIN_1050MV, \
965 .uV_step = S2MPU02_LDO_STEP_25MV, \
966 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
967 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
968 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
969 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
970 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
971 .enable_mask = S2MPU02_ENABLE_MASK \
972}
973#define regulator_desc_s2mpu02_ldo5(num) { \
974 .name = "LDO"#num, \
975 .id = S2MPU02_LDO##num, \
976 .ops = &s2mpu02_ldo_ops, \
977 .type = REGULATOR_VOLTAGE, \
978 .owner = THIS_MODULE, \
979 .min_uV = S2MPU02_LDO_MIN_1600MV, \
980 .uV_step = S2MPU02_LDO_STEP_50MV, \
981 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
982 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
983 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
984 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
985 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
986 .enable_mask = S2MPU02_ENABLE_MASK \
987}
988
989#define regulator_desc_s2mpu02_buck1234(num) { \
990 .name = "BUCK"#num, \
991 .id = S2MPU02_BUCK##num, \
992 .ops = &s2mpu02_buck_ops, \
993 .type = REGULATOR_VOLTAGE, \
994 .owner = THIS_MODULE, \
995 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
996 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
997 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
998 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
999 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1000 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
1001 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1002 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
1003 .enable_mask = S2MPU02_ENABLE_MASK \
1004}
1005#define regulator_desc_s2mpu02_buck5(num) { \
1006 .name = "BUCK"#num, \
1007 .id = S2MPU02_BUCK##num, \
1008 .ops = &s2mpu02_ldo_ops, \
1009 .type = REGULATOR_VOLTAGE, \
1010 .owner = THIS_MODULE, \
1011 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
1012 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
1013 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1014 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
1015 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1016 .vsel_reg = S2MPU02_REG_B5CTRL2, \
1017 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1018 .enable_reg = S2MPU02_REG_B5CTRL1, \
1019 .enable_mask = S2MPU02_ENABLE_MASK \
1020}
1021#define regulator_desc_s2mpu02_buck6(num) { \
1022 .name = "BUCK"#num, \
1023 .id = S2MPU02_BUCK##num, \
1024 .ops = &s2mpu02_ldo_ops, \
1025 .type = REGULATOR_VOLTAGE, \
1026 .owner = THIS_MODULE, \
1027 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
1028 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
1029 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1030 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
1031 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1032 .vsel_reg = S2MPU02_REG_B6CTRL2, \
1033 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1034 .enable_reg = S2MPU02_REG_B6CTRL1, \
1035 .enable_mask = S2MPU02_ENABLE_MASK \
1036}
1037#define regulator_desc_s2mpu02_buck7(num) { \
1038 .name = "BUCK"#num, \
1039 .id = S2MPU02_BUCK##num, \
1040 .ops = &s2mpu02_ldo_ops, \
1041 .type = REGULATOR_VOLTAGE, \
1042 .owner = THIS_MODULE, \
1043 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
1044 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
1045 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1046 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
1047 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1048 .vsel_reg = S2MPU02_REG_B7CTRL2, \
1049 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1050 .enable_reg = S2MPU02_REG_B7CTRL1, \
1051 .enable_mask = S2MPU02_ENABLE_MASK \
1052}
1053
1054static const struct regulator_desc s2mpu02_regulators[] = {
1055 regulator_desc_s2mpu02_ldo1(1),
1056 regulator_desc_s2mpu02_ldo2(2),
1057 regulator_desc_s2mpu02_ldo4(3),
1058 regulator_desc_s2mpu02_ldo5(4),
1059 regulator_desc_s2mpu02_ldo4(5),
1060 regulator_desc_s2mpu02_ldo3(6),
1061 regulator_desc_s2mpu02_ldo3(7),
1062 regulator_desc_s2mpu02_ldo4(8),
1063 regulator_desc_s2mpu02_ldo5(9),
1064 regulator_desc_s2mpu02_ldo3(10),
1065 regulator_desc_s2mpu02_ldo4(11),
1066 regulator_desc_s2mpu02_ldo5(12),
1067 regulator_desc_s2mpu02_ldo5(13),
1068 regulator_desc_s2mpu02_ldo5(14),
1069 regulator_desc_s2mpu02_ldo5(15),
1070 regulator_desc_s2mpu02_ldo5(16),
1071 regulator_desc_s2mpu02_ldo4(17),
1072 regulator_desc_s2mpu02_ldo5(18),
1073 regulator_desc_s2mpu02_ldo3(19),
1074 regulator_desc_s2mpu02_ldo4(20),
1075 regulator_desc_s2mpu02_ldo5(21),
1076 regulator_desc_s2mpu02_ldo5(22),
1077 regulator_desc_s2mpu02_ldo5(23),
1078 regulator_desc_s2mpu02_ldo4(24),
1079 regulator_desc_s2mpu02_ldo5(25),
1080 regulator_desc_s2mpu02_ldo4(26),
1081 regulator_desc_s2mpu02_ldo5(27),
1082 regulator_desc_s2mpu02_ldo5(28),
1083 regulator_desc_s2mpu02_buck1234(1),
1084 regulator_desc_s2mpu02_buck1234(2),
1085 regulator_desc_s2mpu02_buck1234(3),
1086 regulator_desc_s2mpu02_buck1234(4),
1087 regulator_desc_s2mpu02_buck5(5),
1088 regulator_desc_s2mpu02_buck6(6),
1089 regulator_desc_s2mpu02_buck7(7),
1090};
1091
Bill Pembertona5023572012-11-19 13:22:22 -05001092static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +09001093{
1094 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001095 struct sec_platform_data *pdata = NULL;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001096 struct of_regulator_match *rdata = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001097 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +09001098 struct s2mps11_info *s2mps11;
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001099 unsigned int rdev_num = 0;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001100 int i, ret = 0;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001101 const struct regulator_desc *regulators;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001102
Sangbeom Kimcb746852012-07-11 21:08:17 +09001103 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1104 GFP_KERNEL);
1105 if (!s2mps11)
1106 return -ENOMEM;
1107
Chanwoo Choi00e25732014-06-25 16:14:45 +09001108 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
1109 switch (s2mps11->dev_type) {
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001110 case S2MPS11X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001111 rdev_num = ARRAY_SIZE(s2mps11_regulators);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001112 regulators = s2mps11_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001113 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001114 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +09001115 case S2MPS13X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001116 rdev_num = ARRAY_SIZE(s2mps13_regulators);
Chanwoo Choi76b98402014-11-18 17:59:40 +09001117 regulators = s2mps13_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001118 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
Chanwoo Choi76b98402014-11-18 17:59:40 +09001119 break;
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001120 case S2MPS14X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001121 rdev_num = ARRAY_SIZE(s2mps14_regulators);
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001122 regulators = s2mps14_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001123 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001124 break;
Thomas Abraham51af2062015-11-20 16:07:52 +05301125 case S2MPS15X:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001126 rdev_num = ARRAY_SIZE(s2mps15_regulators);
Thomas Abraham51af2062015-11-20 16:07:52 +05301127 regulators = s2mps15_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001128 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
Thomas Abraham51af2062015-11-20 16:07:52 +05301129 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +09001130 case S2MPU02:
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001131 rdev_num = ARRAY_SIZE(s2mpu02_regulators);
Chanwoo Choi00e25732014-06-25 16:14:45 +09001132 regulators = s2mpu02_regulators;
Krzysztof Kozlowski297eaaa2016-02-18 09:35:07 +09001133 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
Chanwoo Choi00e25732014-06-25 16:14:45 +09001134 break;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001135 default:
Chanwoo Choi00e25732014-06-25 16:14:45 +09001136 dev_err(&pdev->dev, "Invalid device type: %u\n",
1137 s2mps11->dev_type);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001138 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +09001139 }
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001140
Krzysztof Kozlowski80e82ac2014-10-16 10:23:28 +02001141 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001142 sizeof(*s2mps11->ext_control_gpio) * rdev_num,
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001143 GFP_KERNEL);
1144 if (!s2mps11->ext_control_gpio)
1145 return -ENOMEM;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001146 /*
1147 * 0 is a valid GPIO so initialize all GPIO-s to negative value
1148 * to indicate that external control won't be used for this regulator.
1149 */
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001150 for (i = 0; i < rdev_num; i++)
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001151 s2mps11->ext_control_gpio[i] = -EINVAL;
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001152
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301153 if (!iodev->dev->of_node) {
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001154 if (iodev->pdata) {
1155 pdata = iodev->pdata;
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301156 goto common_reg;
1157 } else {
1158 dev_err(pdev->dev.parent,
1159 "Platform data or DT node not supplied\n");
1160 return -ENODEV;
1161 }
1162 }
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301163
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001164 rdata = kzalloc(sizeof(*rdata) * rdev_num, GFP_KERNEL);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001165 if (!rdata)
1166 return -ENOMEM;
1167
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001168 for (i = 0; i < rdev_num; i++)
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301169 rdata[i].name = regulators[i].name;
1170
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001171 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001172 if (ret)
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001173 goto out;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301174
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301175common_reg:
1176 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001177
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301178 config.dev = &pdev->dev;
Krzysztof Kozlowski1b1ccee2013-12-11 15:07:43 +01001179 config.regmap = iodev->regmap_pmic;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301180 config.driver_data = s2mps11;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001181 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
Markus Pargmann1de38212014-11-03 19:12:04 +01001182 config.ena_gpio_initialized = true;
Krzysztof Kozlowski7ddec642016-02-18 14:57:03 +09001183 for (i = 0; i < rdev_num; i++) {
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001184 struct regulator_dev *regulator;
1185
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001186 if (pdata) {
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301187 config.init_data = pdata->regulators[i].initdata;
Krzysztof Kozlowski54820f52014-01-30 14:51:19 +01001188 config.of_node = pdata->regulators[i].reg_node;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301189 } else {
1190 config.init_data = rdata[i].init_data;
1191 config.of_node = rdata[i].of_node;
1192 }
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001193 config.ena_gpio = s2mps11->ext_control_gpio[i];
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001194
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001195 regulator = devm_regulator_register(&pdev->dev,
Sachin Kamatd55cd792013-09-04 12:12:15 +05301196 &regulators[i], &config);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001197 if (IS_ERR(regulator)) {
1198 ret = PTR_ERR(regulator);
Axel Lin232b2502012-07-12 09:37:37 +08001199 dev_err(&pdev->dev, "regulator init failed for %d\n",
1200 i);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001201 goto out;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001202 }
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001203
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001204 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001205 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1206 regulator);
1207 if (ret < 0) {
1208 dev_err(&pdev->dev,
1209 "failed to enable GPIO control over %s: %d\n",
1210 regulator->desc->name, ret);
1211 goto out;
1212 }
1213 }
Sangbeom Kimcb746852012-07-11 21:08:17 +09001214 }
1215
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001216out:
1217 kfree(rdata);
1218
1219 return ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001220}
1221
1222static const struct platform_device_id s2mps11_pmic_id[] = {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301223 { "s2mps11-regulator", S2MPS11X},
1224 { "s2mps13-regulator", S2MPS13X},
1225 { "s2mps14-regulator", S2MPS14X},
Thomas Abraham51af2062015-11-20 16:07:52 +05301226 { "s2mps15-regulator", S2MPS15X},
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301227 { "s2mpu02-regulator", S2MPU02},
Sangbeom Kimcb746852012-07-11 21:08:17 +09001228 { },
1229};
1230MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1231
1232static struct platform_driver s2mps11_pmic_driver = {
1233 .driver = {
1234 .name = "s2mps11-pmic",
Sangbeom Kimcb746852012-07-11 21:08:17 +09001235 },
1236 .probe = s2mps11_pmic_probe,
Sangbeom Kimcb746852012-07-11 21:08:17 +09001237 .id_table = s2mps11_pmic_id,
1238};
1239
1240static int __init s2mps11_pmic_init(void)
1241{
1242 return platform_driver_register(&s2mps11_pmic_driver);
1243}
1244subsys_initcall(s2mps11_pmic_init);
1245
1246static void __exit s2mps11_pmic_exit(void)
1247{
1248 platform_driver_unregister(&s2mps11_pmic_driver);
1249}
1250module_exit(s2mps11_pmic_exit);
1251
1252/* Module information */
1253MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Thomas Abraham51af2062015-11-20 16:07:52 +05301254MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
Sangbeom Kimcb746852012-07-11 21:08:17 +09001255MODULE_LICENSE("GPL");