blob: 3242ffc0cb25afdfa8adad11fd40878b6153f1b6 [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 {
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +010041 unsigned int rdev_num;
Sangbeom Kimcb746852012-07-11 21:08:17 +090042 int ramp_delay2;
43 int ramp_delay34;
44 int ramp_delay5;
45 int ramp_delay16;
46 int ramp_delay7810;
47 int ramp_delay9;
Chanwoo Choi00e25732014-06-25 16:14:45 +090048
49 enum sec_device_type dev_type;
50
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010051 /*
Chanwoo Choi76b98402014-11-18 17:59:40 +090052 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
53 * the suspend mode was enabled.
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +010054 */
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +090055 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
Chanwoo Choi00e25732014-06-25 16:14:45 +090056
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +020057 /* Array of size rdev_num with GPIO-s for external sleep control */
58 int *ext_control_gpio;
Sangbeom Kimcb746852012-07-11 21:08:17 +090059};
60
61static int get_ramp_delay(int ramp_delay)
62{
63 unsigned char cnt = 0;
64
Yadwinder Singh Brar90068342013-06-24 16:50:55 +053065 ramp_delay /= 6250;
Sangbeom Kimcb746852012-07-11 21:08:17 +090066
67 while (true) {
68 ramp_delay = ramp_delay >> 1;
69 if (ramp_delay == 0)
70 break;
71 cnt++;
72 }
Axel Linf8f1d482013-08-05 14:08:37 +080073
74 if (cnt > 3)
75 cnt = 3;
76
Sangbeom Kimcb746852012-07-11 21:08:17 +090077 return cnt;
78}
79
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053080static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
81 unsigned int old_selector,
82 unsigned int new_selector)
83{
84 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
85 unsigned int ramp_delay = 0;
86 int old_volt, new_volt;
87
Thiago Farinad55efa42014-01-26 21:57:12 -020088 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053089 case S2MPS11_BUCK2:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053090 ramp_delay = s2mps11->ramp_delay2;
91 break;
92 case S2MPS11_BUCK3:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053093 case S2MPS11_BUCK4:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +053094 ramp_delay = s2mps11->ramp_delay34;
95 break;
96 case S2MPS11_BUCK5:
97 ramp_delay = s2mps11->ramp_delay5;
98 break;
99 case S2MPS11_BUCK6:
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +0530100 case S2MPS11_BUCK1:
101 ramp_delay = s2mps11->ramp_delay16;
102 break;
103 case S2MPS11_BUCK7:
104 case S2MPS11_BUCK8:
105 case S2MPS11_BUCK10:
106 ramp_delay = s2mps11->ramp_delay7810;
107 break;
108 case S2MPS11_BUCK9:
109 ramp_delay = s2mps11->ramp_delay9;
110 }
111
112 if (ramp_delay == 0)
113 ramp_delay = rdev->desc->ramp_delay;
114
115 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
116 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
117
118 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
119}
120
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530121static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
122{
123 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
124 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
125 unsigned int ramp_enable = 1, enable_shift = 0;
126 int ret;
127
Thiago Farinad55efa42014-01-26 21:57:12 -0200128 switch (rdev_get_id(rdev)) {
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530129 case S2MPS11_BUCK1:
130 if (ramp_delay > s2mps11->ramp_delay16)
131 s2mps11->ramp_delay16 = ramp_delay;
132 else
133 ramp_delay = s2mps11->ramp_delay16;
134
135 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
136 break;
137 case S2MPS11_BUCK2:
138 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
139 if (!ramp_delay) {
140 ramp_enable = 0;
141 break;
142 }
143
144 s2mps11->ramp_delay2 = ramp_delay;
145 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
146 ramp_reg = S2MPS11_REG_RAMP;
147 break;
148 case S2MPS11_BUCK3:
149 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
150 if (!ramp_delay) {
151 ramp_enable = 0;
152 break;
153 }
154
155 if (ramp_delay > s2mps11->ramp_delay34)
156 s2mps11->ramp_delay34 = ramp_delay;
157 else
158 ramp_delay = s2mps11->ramp_delay34;
159
160 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
161 ramp_reg = S2MPS11_REG_RAMP;
162 break;
163 case S2MPS11_BUCK4:
164 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
165 if (!ramp_delay) {
166 ramp_enable = 0;
167 break;
168 }
169
170 if (ramp_delay > s2mps11->ramp_delay34)
171 s2mps11->ramp_delay34 = ramp_delay;
172 else
173 ramp_delay = s2mps11->ramp_delay34;
174
175 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
176 ramp_reg = S2MPS11_REG_RAMP;
177 break;
178 case S2MPS11_BUCK5:
179 s2mps11->ramp_delay5 = ramp_delay;
180 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
181 break;
182 case S2MPS11_BUCK6:
183 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
184 if (!ramp_delay) {
185 ramp_enable = 0;
186 break;
187 }
188
189 if (ramp_delay > s2mps11->ramp_delay16)
190 s2mps11->ramp_delay16 = ramp_delay;
191 else
192 ramp_delay = s2mps11->ramp_delay16;
193
194 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
195 break;
196 case S2MPS11_BUCK7:
197 case S2MPS11_BUCK8:
198 case S2MPS11_BUCK10:
199 if (ramp_delay > s2mps11->ramp_delay7810)
200 s2mps11->ramp_delay7810 = ramp_delay;
201 else
202 ramp_delay = s2mps11->ramp_delay7810;
203
204 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
205 break;
206 case S2MPS11_BUCK9:
207 s2mps11->ramp_delay9 = ramp_delay;
208 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
209 break;
210 default:
211 return 0;
212 }
213
214 if (!ramp_enable)
215 goto ramp_disable;
216
Krzysztof Kozlowskib203e0d2014-05-06 08:37:36 +0200217 /* Ramp delay can be enabled/disabled only for buck[2346] */
218 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
219 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
220 rdev_get_id(rdev) == S2MPS11_BUCK6) {
221 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
222 1 << enable_shift, 1 << enable_shift);
223 if (ret) {
224 dev_err(&rdev->dev, "failed to enable ramp rate\n");
225 return ret;
226 }
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530227 }
228
229 ramp_val = get_ramp_delay(ramp_delay);
230
Axel Linf8f1d482013-08-05 14:08:37 +0800231 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
232 ramp_val << ramp_shift);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530233
234ramp_disable:
Axel Lin80853302013-08-03 17:10:42 +0800235 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
236 1 << enable_shift, 0);
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530237}
238
Sangbeom Kimcb746852012-07-11 21:08:17 +0900239static struct regulator_ops s2mps11_ldo_ops = {
240 .list_voltage = regulator_list_voltage_linear,
241 .map_voltage = regulator_map_voltage_linear,
242 .is_enabled = regulator_is_enabled_regmap,
243 .enable = regulator_enable_regmap,
244 .disable = regulator_disable_regmap,
245 .get_voltage_sel = regulator_get_voltage_sel_regmap,
246 .set_voltage_sel = regulator_set_voltage_sel_regmap,
247 .set_voltage_time_sel = regulator_set_voltage_time_sel,
248};
249
250static struct regulator_ops s2mps11_buck_ops = {
251 .list_voltage = regulator_list_voltage_linear,
252 .map_voltage = regulator_map_voltage_linear,
253 .is_enabled = regulator_is_enabled_regmap,
254 .enable = regulator_enable_regmap,
255 .disable = regulator_disable_regmap,
256 .get_voltage_sel = regulator_get_voltage_sel_regmap,
257 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar1e1598ed2013-06-24 16:50:56 +0530258 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530259 .set_ramp_delay = s2mps11_set_ramp_delay,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900260};
261
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530262#define regulator_desc_s2mps11_ldo(num, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900263 .name = "LDO"#num, \
264 .id = S2MPS11_LDO##num, \
265 .ops = &s2mps11_ldo_ops, \
266 .type = REGULATOR_VOLTAGE, \
267 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530268 .min_uV = MIN_800_MV, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530269 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900270 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
271 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800272 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900273 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
274 .enable_mask = S2MPS11_ENABLE_MASK \
275}
276
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100277#define regulator_desc_s2mps11_buck1_4(num) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900278 .name = "BUCK"#num, \
279 .id = S2MPS11_BUCK##num, \
280 .ops = &s2mps11_buck_ops, \
281 .type = REGULATOR_VOLTAGE, \
282 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530283 .min_uV = MIN_600_MV, \
284 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900285 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530286 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900287 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800288 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900289 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
290 .enable_mask = S2MPS11_ENABLE_MASK \
291}
292
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100293#define regulator_desc_s2mps11_buck5 { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900294 .name = "BUCK5", \
295 .id = S2MPS11_BUCK5, \
296 .ops = &s2mps11_buck_ops, \
297 .type = REGULATOR_VOLTAGE, \
298 .owner = THIS_MODULE, \
Amit Daniel Kachhap0e4f4172014-07-15 16:32:51 +0530299 .min_uV = MIN_600_MV, \
300 .uV_step = STEP_6_25_MV, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900301 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530302 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900303 .vsel_reg = S2MPS11_REG_B5CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800304 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900305 .enable_reg = S2MPS11_REG_B5CTRL1, \
306 .enable_mask = S2MPS11_ENABLE_MASK \
307}
308
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530309#define regulator_desc_s2mps11_buck6_10(num, min, step) { \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900310 .name = "BUCK"#num, \
311 .id = S2MPS11_BUCK##num, \
312 .ops = &s2mps11_buck_ops, \
313 .type = REGULATOR_VOLTAGE, \
314 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530315 .min_uV = min, \
316 .uV_step = step, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900317 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530318 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900319 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800320 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900321 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
322 .enable_mask = S2MPS11_ENABLE_MASK \
323}
324
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +0100325static const struct regulator_desc s2mps11_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530326 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
327 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
328 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
329 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
330 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
331 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
332 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
333 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
334 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
335 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
336 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
337 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
338 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
339 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
340 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
341 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
342 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
343 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
344 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
345 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
346 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
348 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
349 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
350 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
353 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
360 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
361 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
362 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
363 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100364 regulator_desc_s2mps11_buck1_4(1),
365 regulator_desc_s2mps11_buck1_4(2),
366 regulator_desc_s2mps11_buck1_4(3),
367 regulator_desc_s2mps11_buck1_4(4),
368 regulator_desc_s2mps11_buck5,
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530369 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV, STEP_6_25_MV),
370 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV, STEP_6_25_MV),
371 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV, STEP_6_25_MV),
372 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV, STEP_25_MV),
373 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV),
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100374};
375
Chanwoo Choi76b98402014-11-18 17:59:40 +0900376static struct regulator_ops s2mps14_reg_ops;
377
378#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
379 .name = "LDO"#num, \
380 .id = S2MPS13_LDO##num, \
381 .ops = &s2mps14_reg_ops, \
382 .type = REGULATOR_VOLTAGE, \
383 .owner = THIS_MODULE, \
384 .min_uV = min, \
385 .uV_step = step, \
386 .linear_min_sel = min_sel, \
387 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
388 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
389 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
390 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
391 .enable_mask = S2MPS14_ENABLE_MASK \
392}
393
394#define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
395 .name = "BUCK"#num, \
396 .id = S2MPS13_BUCK##num, \
397 .ops = &s2mps14_reg_ops, \
398 .type = REGULATOR_VOLTAGE, \
399 .owner = THIS_MODULE, \
400 .min_uV = min, \
401 .uV_step = step, \
402 .linear_min_sel = min_sel, \
403 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
404 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
405 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
406 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
407 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
408 .enable_mask = S2MPS14_ENABLE_MASK \
409}
410
Jonghwa Leead26aa62015-01-08 11:04:07 +0900411#define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
412 .name = "BUCK"#num, \
413 .id = S2MPS13_BUCK##num, \
414 .ops = &s2mps14_reg_ops, \
415 .type = REGULATOR_VOLTAGE, \
416 .owner = THIS_MODULE, \
417 .min_uV = min, \
418 .uV_step = step, \
419 .linear_min_sel = min_sel, \
420 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
421 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
422 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
423 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
424 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
425 .enable_mask = S2MPS14_ENABLE_MASK \
426}
427
428#define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
429 .name = "BUCK"#num, \
430 .id = S2MPS13_BUCK##num, \
431 .ops = &s2mps14_reg_ops, \
432 .type = REGULATOR_VOLTAGE, \
433 .owner = THIS_MODULE, \
434 .min_uV = min, \
435 .uV_step = step, \
436 .linear_min_sel = min_sel, \
437 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
438 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
439 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
440 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
441 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
442 .enable_mask = S2MPS14_ENABLE_MASK \
443}
444
Chanwoo Choi76b98402014-11-18 17:59:40 +0900445static const struct regulator_desc s2mps13_regulators[] = {
446 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
447 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
448 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
449 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
450 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
451 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
452 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
453 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
454 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
455 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
456 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
457 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
458 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
459 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
460 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
461 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
462 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
463 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
464 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
465 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
466 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
467 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
468 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
469 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
470 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
471 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
472 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
473 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
474 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
475 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
476 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
477 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
478 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
479 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
480 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
481 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
482 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
483 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
484 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
485 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
486 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
487 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
488 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
489 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
490 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
491 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
Jonghwa Leead26aa62015-01-08 11:04:07 +0900492 regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
493 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
494 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
495 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
Chanwoo Choi76b98402014-11-18 17:59:40 +0900496};
497
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100498static int s2mps14_regulator_enable(struct regulator_dev *rdev)
499{
500 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
501 unsigned int val;
502
Chanwoo Choi00e25732014-06-25 16:14:45 +0900503 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900504 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900505 case S2MPS14X:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900506 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900507 val = S2MPS14_ENABLE_SUSPEND;
508 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
509 val = S2MPS14_ENABLE_EXT_CONTROL;
510 else
511 val = rdev->desc->enable_mask;
512 break;
513 case S2MPU02:
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900514 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
Chanwoo Choi00e25732014-06-25 16:14:45 +0900515 val = S2MPU02_ENABLE_SUSPEND;
516 else
517 val = rdev->desc->enable_mask;
518 break;
519 default:
520 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900521 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100522
523 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
524 rdev->desc->enable_mask, val);
525}
526
527static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
528{
529 int ret;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900530 unsigned int val, state;
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100531 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900532 int rdev_id = rdev_get_id(rdev);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100533
Chanwoo Choi00e25732014-06-25 16:14:45 +0900534 /* Below LDO should be always on or does not support suspend mode. */
535 switch (s2mps11->dev_type) {
Chanwoo Choi76b98402014-11-18 17:59:40 +0900536 case S2MPS13X:
Chanwoo Choi00e25732014-06-25 16:14:45 +0900537 case S2MPS14X:
538 switch (rdev_id) {
539 case S2MPS14_LDO3:
540 return 0;
541 default:
542 state = S2MPS14_ENABLE_SUSPEND;
543 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900544 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900545 break;
546 case S2MPU02:
547 switch (rdev_id) {
548 case S2MPU02_LDO13:
549 case S2MPU02_LDO14:
550 case S2MPU02_LDO15:
551 case S2MPU02_LDO17:
552 case S2MPU02_BUCK7:
553 state = S2MPU02_DISABLE_SUSPEND;
554 break;
555 default:
556 state = S2MPU02_ENABLE_SUSPEND;
557 break;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900558 }
Chanwoo Choi00e25732014-06-25 16:14:45 +0900559 break;
560 default:
561 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +0900562 }
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100563
564 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
565 if (ret < 0)
566 return ret;
567
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +0900568 set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100569 /*
570 * Don't enable suspend mode if regulator is already disabled because
571 * this would effectively for a short time turn on the regulator after
572 * resuming.
573 * However we still want to toggle the suspend_state bit for regulator
574 * in case if it got enabled before suspending the system.
575 */
576 if (!(val & rdev->desc->enable_mask))
577 return 0;
578
579 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900580 rdev->desc->enable_mask, state);
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100581}
582
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100583static struct regulator_ops s2mps14_reg_ops = {
584 .list_voltage = regulator_list_voltage_linear,
585 .map_voltage = regulator_map_voltage_linear,
586 .is_enabled = regulator_is_enabled_regmap,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100587 .enable = s2mps14_regulator_enable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100588 .disable = regulator_disable_regmap,
589 .get_voltage_sel = regulator_get_voltage_sel_regmap,
590 .set_voltage_sel = regulator_set_voltage_sel_regmap,
591 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski05be09b2014-03-07 11:10:51 +0100592 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100593};
594
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530595#define regulator_desc_s2mps14_ldo(num, min, step) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100596 .name = "LDO"#num, \
597 .id = S2MPS14_LDO##num, \
598 .ops = &s2mps14_reg_ops, \
599 .type = REGULATOR_VOLTAGE, \
600 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530601 .min_uV = min, \
602 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100603 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
604 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
605 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
606 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
607 .enable_mask = S2MPS14_ENABLE_MASK \
608}
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530609
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100610#define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100611 .name = "BUCK"#num, \
612 .id = S2MPS14_BUCK##num, \
613 .ops = &s2mps14_reg_ops, \
614 .type = REGULATOR_VOLTAGE, \
615 .owner = THIS_MODULE, \
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530616 .min_uV = min, \
617 .uV_step = step, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100618 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100619 .linear_min_sel = min_sel, \
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100620 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
621 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
622 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
623 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
624 .enable_mask = S2MPS14_ENABLE_MASK \
625}
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +0100626
627static const struct regulator_desc s2mps14_regulators[] = {
Amit Daniel Kachhap5a867cf2014-07-15 16:32:53 +0530628 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
629 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
630 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
631 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
632 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
633 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
634 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
635 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
636 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
637 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
638 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
639 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
640 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
641 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
642 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
643 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
644 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
645 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
646 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
647 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
648 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
649 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
650 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
651 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
652 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
Krzysztof Kozlowski1222d8f2014-12-11 14:40:21 +0100653 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
654 S2MPS14_BUCK1235_START_SEL),
655 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
656 S2MPS14_BUCK1235_START_SEL),
657 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
658 S2MPS14_BUCK1235_START_SEL),
659 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
660 S2MPS14_BUCK4_START_SEL),
661 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
662 S2MPS14_BUCK1235_START_SEL),
Sangbeom Kimcb746852012-07-11 21:08:17 +0900663};
664
Thomas Abraham51af2062015-11-20 16:07:52 +0530665static struct regulator_ops s2mps15_reg_ldo_ops = {
666 .list_voltage = regulator_list_voltage_linear_range,
667 .map_voltage = regulator_map_voltage_linear_range,
668 .is_enabled = regulator_is_enabled_regmap,
669 .enable = regulator_enable_regmap,
670 .disable = regulator_disable_regmap,
671 .get_voltage_sel = regulator_get_voltage_sel_regmap,
672 .set_voltage_sel = regulator_set_voltage_sel_regmap,
673};
674
675static struct regulator_ops s2mps15_reg_buck_ops = {
676 .list_voltage = regulator_list_voltage_linear_range,
677 .map_voltage = regulator_map_voltage_linear_range,
678 .is_enabled = regulator_is_enabled_regmap,
679 .enable = regulator_enable_regmap,
680 .disable = regulator_disable_regmap,
681 .get_voltage_sel = regulator_get_voltage_sel_regmap,
682 .set_voltage_sel = regulator_set_voltage_sel_regmap,
683 .set_voltage_time_sel = regulator_set_voltage_time_sel,
684};
685
686#define regulator_desc_s2mps15_ldo(num, range) { \
687 .name = "LDO"#num, \
688 .id = S2MPS15_LDO##num, \
689 .ops = &s2mps15_reg_ldo_ops, \
690 .type = REGULATOR_VOLTAGE, \
691 .owner = THIS_MODULE, \
692 .linear_ranges = range, \
693 .n_linear_ranges = ARRAY_SIZE(range), \
694 .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
695 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
696 .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
697 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
698 .enable_mask = S2MPS15_ENABLE_MASK \
699}
700
701#define regulator_desc_s2mps15_buck(num, range) { \
702 .name = "BUCK"#num, \
703 .id = S2MPS15_BUCK##num, \
704 .ops = &s2mps15_reg_buck_ops, \
705 .type = REGULATOR_VOLTAGE, \
706 .owner = THIS_MODULE, \
707 .linear_ranges = range, \
708 .n_linear_ranges = ARRAY_SIZE(range), \
709 .ramp_delay = 12500, \
710 .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
711 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
712 .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
713 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
714 .enable_mask = S2MPS15_ENABLE_MASK \
715}
716
717/* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
718static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
719 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
720};
721
722/* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
723static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
724 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
725};
726
727/* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
728static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
729 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
730};
731
732/* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
733static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
734 REGULATOR_LINEAR_RANGE(700000, 0xc, 0x18, 25000),
735};
736
737/* voltage range for s2mps15 LDO 1 */
738static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
739 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
740};
741
742/* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
743static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
744 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xb0, 6250),
745};
746
747/* voltage range for s2mps15 BUCK 8, 9 and 10 */
748static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
749 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0xc0, 12500),
750};
751
752static const struct regulator_desc s2mps15_regulators[] = {
753 regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
754 regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
755 regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
756 regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
757 regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
758 regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
759 regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
760 regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
761 regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
762 regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
763 regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
764 regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
765 regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
766 regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
767 regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
768 regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
769 regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
770 regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
771 regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
772 regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
773 regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
774 regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
775 regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
776 regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
777 regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
778 regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
779 regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
780 regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
781 regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
782 regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
783 regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
784 regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
785 regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
786 regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
787 regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
788 regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
789 regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
790};
791
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200792static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
793 struct regulator_dev *rdev)
794{
795 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
796 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
797}
798
799static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200800 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
801{
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200802 int *gpio = s2mps11->ext_control_gpio;
803 unsigned int i;
804 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
805 S2MPS14_LDO12 };
806
807 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
808 unsigned int reg = valid_regulators[i];
809
810 if (!rdata[reg].init_data || !rdata[reg].of_node)
811 continue;
812
813 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
814 "samsung,ext-control-gpios", 0);
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +0200815 if (gpio_is_valid(gpio[reg]))
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200816 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
817 gpio[reg], reg, rdata[reg].name);
818 }
819}
820
821static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
Chanwoo Choi00e25732014-06-25 16:14:45 +0900822 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200823{
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200824 struct device_node *reg_np;
825
826 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
827 if (!reg_np) {
828 dev_err(&pdev->dev, "could not find regulators sub-node\n");
829 return -EINVAL;
830 }
831
832 of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +0900833 if (s2mps11->dev_type == S2MPS14X)
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +0200834 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
835
Krzysztof Kozlowski01170382014-04-14 10:09:06 +0200836 of_node_put(reg_np);
837
838 return 0;
839}
840
Chanwoo Choi00e25732014-06-25 16:14:45 +0900841static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
842{
843 unsigned int ramp_val, ramp_shift, ramp_reg;
844
845 switch (rdev_get_id(rdev)) {
846 case S2MPU02_BUCK1:
847 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
848 break;
849 case S2MPU02_BUCK2:
850 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
851 break;
852 case S2MPU02_BUCK3:
853 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
854 break;
855 case S2MPU02_BUCK4:
856 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
857 break;
858 default:
859 return 0;
860 }
861 ramp_reg = S2MPU02_REG_RAMP1;
862 ramp_val = get_ramp_delay(ramp_delay);
863
864 return regmap_update_bits(rdev->regmap, ramp_reg,
865 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
866 ramp_val << ramp_shift);
867}
868
869static struct regulator_ops s2mpu02_ldo_ops = {
870 .list_voltage = regulator_list_voltage_linear,
871 .map_voltage = regulator_map_voltage_linear,
872 .is_enabled = regulator_is_enabled_regmap,
873 .enable = s2mps14_regulator_enable,
874 .disable = regulator_disable_regmap,
875 .get_voltage_sel = regulator_get_voltage_sel_regmap,
876 .set_voltage_sel = regulator_set_voltage_sel_regmap,
877 .set_voltage_time_sel = regulator_set_voltage_time_sel,
878 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
879};
880
881static struct regulator_ops s2mpu02_buck_ops = {
882 .list_voltage = regulator_list_voltage_linear,
883 .map_voltage = regulator_map_voltage_linear,
884 .is_enabled = regulator_is_enabled_regmap,
885 .enable = s2mps14_regulator_enable,
886 .disable = regulator_disable_regmap,
887 .get_voltage_sel = regulator_get_voltage_sel_regmap,
888 .set_voltage_sel = regulator_set_voltage_sel_regmap,
889 .set_voltage_time_sel = regulator_set_voltage_time_sel,
890 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
891 .set_ramp_delay = s2mpu02_set_ramp_delay,
892};
893
894#define regulator_desc_s2mpu02_ldo1(num) { \
895 .name = "LDO"#num, \
896 .id = S2MPU02_LDO##num, \
897 .ops = &s2mpu02_ldo_ops, \
898 .type = REGULATOR_VOLTAGE, \
899 .owner = THIS_MODULE, \
900 .min_uV = S2MPU02_LDO_MIN_900MV, \
901 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
902 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
903 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
904 .vsel_reg = S2MPU02_REG_L1CTRL, \
905 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
906 .enable_reg = S2MPU02_REG_L1CTRL, \
907 .enable_mask = S2MPU02_ENABLE_MASK \
908}
909#define regulator_desc_s2mpu02_ldo2(num) { \
910 .name = "LDO"#num, \
911 .id = S2MPU02_LDO##num, \
912 .ops = &s2mpu02_ldo_ops, \
913 .type = REGULATOR_VOLTAGE, \
914 .owner = THIS_MODULE, \
915 .min_uV = S2MPU02_LDO_MIN_1050MV, \
916 .uV_step = S2MPU02_LDO_STEP_25MV, \
917 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
918 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
919 .vsel_reg = S2MPU02_REG_L2CTRL1, \
920 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
921 .enable_reg = S2MPU02_REG_L2CTRL1, \
922 .enable_mask = S2MPU02_ENABLE_MASK \
923}
924#define regulator_desc_s2mpu02_ldo3(num) { \
925 .name = "LDO"#num, \
926 .id = S2MPU02_LDO##num, \
927 .ops = &s2mpu02_ldo_ops, \
928 .type = REGULATOR_VOLTAGE, \
929 .owner = THIS_MODULE, \
930 .min_uV = S2MPU02_LDO_MIN_900MV, \
931 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
932 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
933 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
934 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
935 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
936 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
937 .enable_mask = S2MPU02_ENABLE_MASK \
938}
939#define regulator_desc_s2mpu02_ldo4(num) { \
940 .name = "LDO"#num, \
941 .id = S2MPU02_LDO##num, \
942 .ops = &s2mpu02_ldo_ops, \
943 .type = REGULATOR_VOLTAGE, \
944 .owner = THIS_MODULE, \
945 .min_uV = S2MPU02_LDO_MIN_1050MV, \
946 .uV_step = S2MPU02_LDO_STEP_25MV, \
947 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
948 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
949 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
950 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
951 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
952 .enable_mask = S2MPU02_ENABLE_MASK \
953}
954#define regulator_desc_s2mpu02_ldo5(num) { \
955 .name = "LDO"#num, \
956 .id = S2MPU02_LDO##num, \
957 .ops = &s2mpu02_ldo_ops, \
958 .type = REGULATOR_VOLTAGE, \
959 .owner = THIS_MODULE, \
960 .min_uV = S2MPU02_LDO_MIN_1600MV, \
961 .uV_step = S2MPU02_LDO_STEP_50MV, \
962 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
963 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
964 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
965 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
966 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
967 .enable_mask = S2MPU02_ENABLE_MASK \
968}
969
970#define regulator_desc_s2mpu02_buck1234(num) { \
971 .name = "BUCK"#num, \
972 .id = S2MPU02_BUCK##num, \
973 .ops = &s2mpu02_buck_ops, \
974 .type = REGULATOR_VOLTAGE, \
975 .owner = THIS_MODULE, \
976 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
977 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
978 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
979 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
980 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
981 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
982 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
983 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
984 .enable_mask = S2MPU02_ENABLE_MASK \
985}
986#define regulator_desc_s2mpu02_buck5(num) { \
987 .name = "BUCK"#num, \
988 .id = S2MPU02_BUCK##num, \
989 .ops = &s2mpu02_ldo_ops, \
990 .type = REGULATOR_VOLTAGE, \
991 .owner = THIS_MODULE, \
992 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
993 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
994 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
995 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
996 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
997 .vsel_reg = S2MPU02_REG_B5CTRL2, \
998 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
999 .enable_reg = S2MPU02_REG_B5CTRL1, \
1000 .enable_mask = S2MPU02_ENABLE_MASK \
1001}
1002#define regulator_desc_s2mpu02_buck6(num) { \
1003 .name = "BUCK"#num, \
1004 .id = S2MPU02_BUCK##num, \
1005 .ops = &s2mpu02_ldo_ops, \
1006 .type = REGULATOR_VOLTAGE, \
1007 .owner = THIS_MODULE, \
1008 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
1009 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
1010 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1011 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
1012 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1013 .vsel_reg = S2MPU02_REG_B6CTRL2, \
1014 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1015 .enable_reg = S2MPU02_REG_B6CTRL1, \
1016 .enable_mask = S2MPU02_ENABLE_MASK \
1017}
1018#define regulator_desc_s2mpu02_buck7(num) { \
1019 .name = "BUCK"#num, \
1020 .id = S2MPU02_BUCK##num, \
1021 .ops = &s2mpu02_ldo_ops, \
1022 .type = REGULATOR_VOLTAGE, \
1023 .owner = THIS_MODULE, \
1024 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
1025 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
1026 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1027 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
1028 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1029 .vsel_reg = S2MPU02_REG_B7CTRL2, \
1030 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1031 .enable_reg = S2MPU02_REG_B7CTRL1, \
1032 .enable_mask = S2MPU02_ENABLE_MASK \
1033}
1034
1035static const struct regulator_desc s2mpu02_regulators[] = {
1036 regulator_desc_s2mpu02_ldo1(1),
1037 regulator_desc_s2mpu02_ldo2(2),
1038 regulator_desc_s2mpu02_ldo4(3),
1039 regulator_desc_s2mpu02_ldo5(4),
1040 regulator_desc_s2mpu02_ldo4(5),
1041 regulator_desc_s2mpu02_ldo3(6),
1042 regulator_desc_s2mpu02_ldo3(7),
1043 regulator_desc_s2mpu02_ldo4(8),
1044 regulator_desc_s2mpu02_ldo5(9),
1045 regulator_desc_s2mpu02_ldo3(10),
1046 regulator_desc_s2mpu02_ldo4(11),
1047 regulator_desc_s2mpu02_ldo5(12),
1048 regulator_desc_s2mpu02_ldo5(13),
1049 regulator_desc_s2mpu02_ldo5(14),
1050 regulator_desc_s2mpu02_ldo5(15),
1051 regulator_desc_s2mpu02_ldo5(16),
1052 regulator_desc_s2mpu02_ldo4(17),
1053 regulator_desc_s2mpu02_ldo5(18),
1054 regulator_desc_s2mpu02_ldo3(19),
1055 regulator_desc_s2mpu02_ldo4(20),
1056 regulator_desc_s2mpu02_ldo5(21),
1057 regulator_desc_s2mpu02_ldo5(22),
1058 regulator_desc_s2mpu02_ldo5(23),
1059 regulator_desc_s2mpu02_ldo4(24),
1060 regulator_desc_s2mpu02_ldo5(25),
1061 regulator_desc_s2mpu02_ldo4(26),
1062 regulator_desc_s2mpu02_ldo5(27),
1063 regulator_desc_s2mpu02_ldo5(28),
1064 regulator_desc_s2mpu02_buck1234(1),
1065 regulator_desc_s2mpu02_buck1234(2),
1066 regulator_desc_s2mpu02_buck1234(3),
1067 regulator_desc_s2mpu02_buck1234(4),
1068 regulator_desc_s2mpu02_buck5(5),
1069 regulator_desc_s2mpu02_buck6(6),
1070 regulator_desc_s2mpu02_buck7(7),
1071};
1072
Bill Pembertona5023572012-11-19 13:22:22 -05001073static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +09001074{
1075 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001076 struct sec_platform_data *pdata = NULL;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001077 struct of_regulator_match *rdata = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001078 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +09001079 struct s2mps11_info *s2mps11;
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001080 int i, ret = 0;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001081 const struct regulator_desc *regulators;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001082
Sangbeom Kimcb746852012-07-11 21:08:17 +09001083 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1084 GFP_KERNEL);
1085 if (!s2mps11)
1086 return -ENOMEM;
1087
Chanwoo Choi00e25732014-06-25 16:14:45 +09001088 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
1089 switch (s2mps11->dev_type) {
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001090 case S2MPS11X:
1091 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
1092 regulators = s2mps11_regulators;
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +09001093 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001094 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +09001095 case S2MPS13X:
1096 s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
1097 regulators = s2mps13_regulators;
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +09001098 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
Chanwoo Choi76b98402014-11-18 17:59:40 +09001099 break;
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001100 case S2MPS14X:
1101 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
1102 regulators = s2mps14_regulators;
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +09001103 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
Krzysztof Kozlowski15f77302014-03-07 11:10:50 +01001104 break;
Thomas Abraham51af2062015-11-20 16:07:52 +05301105 case S2MPS15X:
1106 s2mps11->rdev_num = ARRAY_SIZE(s2mps15_regulators);
1107 regulators = s2mps15_regulators;
1108 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +09001109 case S2MPU02:
1110 s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
1111 regulators = s2mpu02_regulators;
Krzysztof Kozlowski32c848e2015-06-24 19:48:43 +09001112 BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num);
Chanwoo Choi00e25732014-06-25 16:14:45 +09001113 break;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001114 default:
Chanwoo Choi00e25732014-06-25 16:14:45 +09001115 dev_err(&pdev->dev, "Invalid device type: %u\n",
1116 s2mps11->dev_type);
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001117 return -EINVAL;
Krzysztof Kozlowski7cf225b2015-04-23 21:24:32 +09001118 }
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001119
Krzysztof Kozlowski80e82ac2014-10-16 10:23:28 +02001120 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001121 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
1122 GFP_KERNEL);
1123 if (!s2mps11->ext_control_gpio)
1124 return -ENOMEM;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001125 /*
1126 * 0 is a valid GPIO so initialize all GPIO-s to negative value
1127 * to indicate that external control won't be used for this regulator.
1128 */
1129 for (i = 0; i < s2mps11->rdev_num; i++)
1130 s2mps11->ext_control_gpio[i] = -EINVAL;
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001131
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301132 if (!iodev->dev->of_node) {
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001133 if (iodev->pdata) {
1134 pdata = iodev->pdata;
Yadwinder Singh Brar6c683c92013-06-29 18:21:18 +05301135 goto common_reg;
1136 } else {
1137 dev_err(pdev->dev.parent,
1138 "Platform data or DT node not supplied\n");
1139 return -ENODEV;
1140 }
1141 }
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301142
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001143 rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001144 if (!rdata)
1145 return -ENOMEM;
1146
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001147 for (i = 0; i < s2mps11->rdev_num; i++)
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301148 rdata[i].name = regulators[i].name;
1149
Chanwoo Choi00e25732014-06-25 16:14:45 +09001150 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11);
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001151 if (ret)
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001152 goto out;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301153
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301154common_reg:
1155 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +09001156
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301157 config.dev = &pdev->dev;
Krzysztof Kozlowski1b1ccee2013-12-11 15:07:43 +01001158 config.regmap = iodev->regmap_pmic;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301159 config.driver_data = s2mps11;
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001160 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
Markus Pargmann1de38212014-11-03 19:12:04 +01001161 config.ena_gpio_initialized = true;
Krzysztof Kozlowski0f4cc282014-03-03 16:53:51 +01001162 for (i = 0; i < s2mps11->rdev_num; i++) {
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001163 struct regulator_dev *regulator;
1164
Krzysztof Kozlowski01170382014-04-14 10:09:06 +02001165 if (pdata) {
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301166 config.init_data = pdata->regulators[i].initdata;
Krzysztof Kozlowski54820f52014-01-30 14:51:19 +01001167 config.of_node = pdata->regulators[i].reg_node;
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +05301168 } else {
1169 config.init_data = rdata[i].init_data;
1170 config.of_node = rdata[i].of_node;
1171 }
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001172 config.ena_gpio = s2mps11->ext_control_gpio[i];
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001173
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001174 regulator = devm_regulator_register(&pdev->dev,
Sachin Kamatd55cd792013-09-04 12:12:15 +05301175 &regulators[i], &config);
Krzysztof Kozlowski31195252014-02-28 11:01:48 +01001176 if (IS_ERR(regulator)) {
1177 ret = PTR_ERR(regulator);
Axel Lin232b2502012-07-12 09:37:37 +08001178 dev_err(&pdev->dev, "regulator init failed for %d\n",
1179 i);
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001180 goto out;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001181 }
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001182
Krzysztof Kozlowskide5d0562014-04-30 10:40:42 +02001183 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
Krzysztof Kozlowski97f53d72014-04-14 10:09:07 +02001184 ret = s2mps14_pmic_enable_ext_control(s2mps11,
1185 regulator);
1186 if (ret < 0) {
1187 dev_err(&pdev->dev,
1188 "failed to enable GPIO control over %s: %d\n",
1189 regulator->desc->name, ret);
1190 goto out;
1191 }
1192 }
Sangbeom Kimcb746852012-07-11 21:08:17 +09001193 }
1194
Krzysztof Kozlowski3e80f952014-02-28 11:01:50 +01001195out:
1196 kfree(rdata);
1197
1198 return ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +09001199}
1200
1201static const struct platform_device_id s2mps11_pmic_id[] = {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301202 { "s2mps11-regulator", S2MPS11X},
1203 { "s2mps13-regulator", S2MPS13X},
1204 { "s2mps14-regulator", S2MPS14X},
Thomas Abraham51af2062015-11-20 16:07:52 +05301205 { "s2mps15-regulator", S2MPS15X},
Alim Akhtar2fadbbf2015-11-20 16:18:26 +05301206 { "s2mpu02-regulator", S2MPU02},
Sangbeom Kimcb746852012-07-11 21:08:17 +09001207 { },
1208};
1209MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1210
1211static struct platform_driver s2mps11_pmic_driver = {
1212 .driver = {
1213 .name = "s2mps11-pmic",
Sangbeom Kimcb746852012-07-11 21:08:17 +09001214 },
1215 .probe = s2mps11_pmic_probe,
Sangbeom Kimcb746852012-07-11 21:08:17 +09001216 .id_table = s2mps11_pmic_id,
1217};
1218
1219static int __init s2mps11_pmic_init(void)
1220{
1221 return platform_driver_register(&s2mps11_pmic_driver);
1222}
1223subsys_initcall(s2mps11_pmic_init);
1224
1225static void __exit s2mps11_pmic_exit(void)
1226{
1227 platform_driver_unregister(&s2mps11_pmic_driver);
1228}
1229module_exit(s2mps11_pmic_exit);
1230
1231/* Module information */
1232MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
Thomas Abraham51af2062015-11-20 16:07:52 +05301233MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
Sangbeom Kimcb746852012-07-11 21:08:17 +09001234MODULE_LICENSE("GPL");