blob: b316d40c8e14c7638a320c99cef5890bff4595c4 [file] [log] [blame]
Sangbeom Kimcb746852012-07-11 21:08:17 +09001/*
2 * s2mps11.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * 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 */
13
14#include <linux/bug.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090015#include <linux/err.h>
16#include <linux/gpio.h>
17#include <linux/slab.h>
18#include <linux/module.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053019#include <linux/of.h>
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +053020#include <linux/regmap.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090021#include <linux/platform_device.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053024#include <linux/regulator/of_regulator.h>
Sangbeom Kimcb746852012-07-11 21:08:17 +090025#include <linux/mfd/samsung/core.h>
26#include <linux/mfd/samsung/s2mps11.h>
27
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +053028#define S2MPS11_REGULATOR_CNT ARRAY_SIZE(regulators)
29
Sangbeom Kimcb746852012-07-11 21:08:17 +090030struct s2mps11_info {
Axel Linad46ed12012-07-13 10:12:40 +080031 struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX];
Sangbeom Kimcb746852012-07-11 21:08:17 +090032
33 int ramp_delay2;
34 int ramp_delay34;
35 int ramp_delay5;
36 int ramp_delay16;
37 int ramp_delay7810;
38 int ramp_delay9;
39
40 bool buck6_ramp;
41 bool buck2_ramp;
42 bool buck3_ramp;
43 bool buck4_ramp;
44};
45
46static int get_ramp_delay(int ramp_delay)
47{
48 unsigned char cnt = 0;
49
Yadwinder Singh Brar90068342013-06-24 16:50:55 +053050 ramp_delay /= 6250;
Sangbeom Kimcb746852012-07-11 21:08:17 +090051
52 while (true) {
53 ramp_delay = ramp_delay >> 1;
54 if (ramp_delay == 0)
55 break;
56 cnt++;
57 }
58 return cnt;
59}
60
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +053061static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
62 unsigned int old_selector,
63 unsigned int new_selector)
64{
65 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
66 unsigned int ramp_delay = 0;
67 int old_volt, new_volt;
68
69 switch (rdev->desc->id) {
70 case S2MPS11_BUCK2:
71 if (!s2mps11->buck2_ramp)
72 return 0;
73 ramp_delay = s2mps11->ramp_delay2;
74 break;
75 case S2MPS11_BUCK3:
76 if (!s2mps11->buck3_ramp)
77 return 0;
78 ramp_delay = s2mps11->ramp_delay34;
79 break;
80 case S2MPS11_BUCK4:
81 if (!s2mps11->buck4_ramp)
82 return 0;
83 ramp_delay = s2mps11->ramp_delay34;
84 break;
85 case S2MPS11_BUCK5:
86 ramp_delay = s2mps11->ramp_delay5;
87 break;
88 case S2MPS11_BUCK6:
89 if (!s2mps11->buck6_ramp)
90 return 0;
91 case S2MPS11_BUCK1:
92 ramp_delay = s2mps11->ramp_delay16;
93 break;
94 case S2MPS11_BUCK7:
95 case S2MPS11_BUCK8:
96 case S2MPS11_BUCK10:
97 ramp_delay = s2mps11->ramp_delay7810;
98 break;
99 case S2MPS11_BUCK9:
100 ramp_delay = s2mps11->ramp_delay9;
101 }
102
103 if (ramp_delay == 0)
104 ramp_delay = rdev->desc->ramp_delay;
105
106 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
107 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
108
109 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
110}
111
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530112static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
113{
114 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
115 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
116 unsigned int ramp_enable = 1, enable_shift = 0;
117 int ret;
118
119 switch (rdev->desc->id) {
120 case S2MPS11_BUCK1:
121 if (ramp_delay > s2mps11->ramp_delay16)
122 s2mps11->ramp_delay16 = ramp_delay;
123 else
124 ramp_delay = s2mps11->ramp_delay16;
125
126 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
127 break;
128 case S2MPS11_BUCK2:
129 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
130 if (!ramp_delay) {
131 ramp_enable = 0;
132 break;
133 }
134
135 s2mps11->ramp_delay2 = ramp_delay;
136 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
137 ramp_reg = S2MPS11_REG_RAMP;
138 break;
139 case S2MPS11_BUCK3:
140 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
141 if (!ramp_delay) {
142 ramp_enable = 0;
143 break;
144 }
145
146 if (ramp_delay > s2mps11->ramp_delay34)
147 s2mps11->ramp_delay34 = ramp_delay;
148 else
149 ramp_delay = s2mps11->ramp_delay34;
150
151 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
152 ramp_reg = S2MPS11_REG_RAMP;
153 break;
154 case S2MPS11_BUCK4:
155 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
156 if (!ramp_delay) {
157 ramp_enable = 0;
158 break;
159 }
160
161 if (ramp_delay > s2mps11->ramp_delay34)
162 s2mps11->ramp_delay34 = ramp_delay;
163 else
164 ramp_delay = s2mps11->ramp_delay34;
165
166 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
167 ramp_reg = S2MPS11_REG_RAMP;
168 break;
169 case S2MPS11_BUCK5:
170 s2mps11->ramp_delay5 = ramp_delay;
171 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
172 break;
173 case S2MPS11_BUCK6:
174 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
175 if (!ramp_delay) {
176 ramp_enable = 0;
177 break;
178 }
179
180 if (ramp_delay > s2mps11->ramp_delay16)
181 s2mps11->ramp_delay16 = ramp_delay;
182 else
183 ramp_delay = s2mps11->ramp_delay16;
184
185 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
186 break;
187 case S2MPS11_BUCK7:
188 case S2MPS11_BUCK8:
189 case S2MPS11_BUCK10:
190 if (ramp_delay > s2mps11->ramp_delay7810)
191 s2mps11->ramp_delay7810 = ramp_delay;
192 else
193 ramp_delay = s2mps11->ramp_delay7810;
194
195 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
196 break;
197 case S2MPS11_BUCK9:
198 s2mps11->ramp_delay9 = ramp_delay;
199 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
200 break;
201 default:
202 return 0;
203 }
204
205 if (!ramp_enable)
206 goto ramp_disable;
207
208 if (enable_shift) {
209 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
210 1 << enable_shift, 1 << enable_shift);
211 if (ret) {
212 dev_err(&rdev->dev, "failed to enable ramp rate\n");
213 return ret;
214 }
215 }
216
217 ramp_val = get_ramp_delay(ramp_delay);
218
219 return regmap_update_bits(rdev->regmap, ramp_reg,
220 ramp_val << ramp_shift, 1 << ramp_shift);
221
222ramp_disable:
223 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, 0,
224 1 << enable_shift);
225}
226
Sangbeom Kimcb746852012-07-11 21:08:17 +0900227static struct regulator_ops s2mps11_ldo_ops = {
228 .list_voltage = regulator_list_voltage_linear,
229 .map_voltage = regulator_map_voltage_linear,
230 .is_enabled = regulator_is_enabled_regmap,
231 .enable = regulator_enable_regmap,
232 .disable = regulator_disable_regmap,
233 .get_voltage_sel = regulator_get_voltage_sel_regmap,
234 .set_voltage_sel = regulator_set_voltage_sel_regmap,
235 .set_voltage_time_sel = regulator_set_voltage_time_sel,
236};
237
238static struct regulator_ops s2mps11_buck_ops = {
239 .list_voltage = regulator_list_voltage_linear,
240 .map_voltage = regulator_map_voltage_linear,
241 .is_enabled = regulator_is_enabled_regmap,
242 .enable = regulator_enable_regmap,
243 .disable = regulator_disable_regmap,
244 .get_voltage_sel = regulator_get_voltage_sel_regmap,
245 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar1e1598e2013-06-24 16:50:56 +0530246 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
Yadwinder Singh Brar939c0272013-06-29 18:21:16 +0530247 .set_ramp_delay = s2mps11_set_ramp_delay,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900248};
249
250#define regulator_desc_ldo1(num) { \
251 .name = "LDO"#num, \
252 .id = S2MPS11_LDO##num, \
253 .ops = &s2mps11_ldo_ops, \
254 .type = REGULATOR_VOLTAGE, \
255 .owner = THIS_MODULE, \
256 .min_uV = S2MPS11_LDO_MIN, \
257 .uV_step = S2MPS11_LDO_STEP1, \
258 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
259 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
Axel Lin2693fca2012-07-12 09:35:50 +0800260 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900261 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
262 .enable_mask = S2MPS11_ENABLE_MASK \
263}
264#define regulator_desc_ldo2(num) { \
265 .name = "LDO"#num, \
266 .id = S2MPS11_LDO##num, \
267 .ops = &s2mps11_ldo_ops, \
268 .type = REGULATOR_VOLTAGE, \
269 .owner = THIS_MODULE, \
270 .min_uV = S2MPS11_LDO_MIN, \
271 .uV_step = S2MPS11_LDO_STEP2, \
272 .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
279#define regulator_desc_buck1_4(num) { \
280 .name = "BUCK"#num, \
281 .id = S2MPS11_BUCK##num, \
282 .ops = &s2mps11_buck_ops, \
283 .type = REGULATOR_VOLTAGE, \
284 .owner = THIS_MODULE, \
285 .min_uV = S2MPS11_BUCK_MIN1, \
286 .uV_step = S2MPS11_BUCK_STEP1, \
287 .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
295#define regulator_desc_buck5 { \
296 .name = "BUCK5", \
297 .id = S2MPS11_BUCK5, \
298 .ops = &s2mps11_buck_ops, \
299 .type = REGULATOR_VOLTAGE, \
300 .owner = THIS_MODULE, \
301 .min_uV = S2MPS11_BUCK_MIN1, \
302 .uV_step = S2MPS11_BUCK_STEP1, \
303 .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
311#define regulator_desc_buck6_8(num) { \
312 .name = "BUCK"#num, \
313 .id = S2MPS11_BUCK##num, \
314 .ops = &s2mps11_buck_ops, \
315 .type = REGULATOR_VOLTAGE, \
316 .owner = THIS_MODULE, \
317 .min_uV = S2MPS11_BUCK_MIN1, \
318 .uV_step = S2MPS11_BUCK_STEP1, \
319 .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
327#define regulator_desc_buck9 { \
328 .name = "BUCK9", \
329 .id = S2MPS11_BUCK9, \
330 .ops = &s2mps11_buck_ops, \
331 .type = REGULATOR_VOLTAGE, \
332 .owner = THIS_MODULE, \
333 .min_uV = S2MPS11_BUCK_MIN3, \
334 .uV_step = S2MPS11_BUCK_STEP3, \
335 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530336 .ramp_delay = S2MPS11_RAMP_DELAY, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900337 .vsel_reg = S2MPS11_REG_B9CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800338 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900339 .enable_reg = S2MPS11_REG_B9CTRL1, \
340 .enable_mask = S2MPS11_ENABLE_MASK \
341}
342
343#define regulator_desc_buck10 { \
344 .name = "BUCK10", \
345 .id = S2MPS11_BUCK10, \
346 .ops = &s2mps11_buck_ops, \
347 .type = REGULATOR_VOLTAGE, \
348 .owner = THIS_MODULE, \
349 .min_uV = S2MPS11_BUCK_MIN2, \
350 .uV_step = S2MPS11_BUCK_STEP2, \
351 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
Yadwinder Singh Brar90068342013-06-24 16:50:55 +0530352 .ramp_delay = S2MPS11_RAMP_DELAY, \
Alim Akhtarc76edd52013-01-30 08:02:27 -0500353 .vsel_reg = S2MPS11_REG_B10CTRL2, \
Axel Lin2693fca2012-07-12 09:35:50 +0800354 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
Alim Akhtarc76edd52013-01-30 08:02:27 -0500355 .enable_reg = S2MPS11_REG_B10CTRL1, \
Sangbeom Kimcb746852012-07-11 21:08:17 +0900356 .enable_mask = S2MPS11_ENABLE_MASK \
357}
358
359static struct regulator_desc regulators[] = {
360 regulator_desc_ldo2(1),
361 regulator_desc_ldo1(2),
362 regulator_desc_ldo1(3),
363 regulator_desc_ldo1(4),
364 regulator_desc_ldo1(5),
365 regulator_desc_ldo2(6),
366 regulator_desc_ldo1(7),
367 regulator_desc_ldo1(8),
368 regulator_desc_ldo1(9),
369 regulator_desc_ldo1(10),
370 regulator_desc_ldo2(11),
371 regulator_desc_ldo1(12),
372 regulator_desc_ldo1(13),
373 regulator_desc_ldo1(14),
374 regulator_desc_ldo1(15),
375 regulator_desc_ldo1(16),
376 regulator_desc_ldo1(17),
377 regulator_desc_ldo1(18),
378 regulator_desc_ldo1(19),
379 regulator_desc_ldo1(20),
380 regulator_desc_ldo1(21),
381 regulator_desc_ldo2(22),
382 regulator_desc_ldo2(23),
383 regulator_desc_ldo1(24),
384 regulator_desc_ldo1(25),
385 regulator_desc_ldo1(26),
386 regulator_desc_ldo2(27),
387 regulator_desc_ldo1(28),
388 regulator_desc_ldo1(29),
389 regulator_desc_ldo1(30),
390 regulator_desc_ldo1(31),
391 regulator_desc_ldo1(32),
392 regulator_desc_ldo1(33),
393 regulator_desc_ldo1(34),
394 regulator_desc_ldo1(35),
395 regulator_desc_ldo1(36),
396 regulator_desc_ldo1(37),
397 regulator_desc_ldo1(38),
398 regulator_desc_buck1_4(1),
399 regulator_desc_buck1_4(2),
400 regulator_desc_buck1_4(3),
401 regulator_desc_buck1_4(4),
402 regulator_desc_buck5,
403 regulator_desc_buck6_8(6),
404 regulator_desc_buck6_8(7),
405 regulator_desc_buck6_8(8),
406 regulator_desc_buck9,
407 regulator_desc_buck10,
408};
409
Bill Pembertona5023572012-11-19 13:22:22 -0500410static int s2mps11_pmic_probe(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +0900411{
412 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
413 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530414 struct of_regulator_match rdata[S2MPS11_REGULATOR_MAX];
415 struct device_node *reg_np = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900416 struct regulator_config config = { };
Sangbeom Kimcb746852012-07-11 21:08:17 +0900417 struct s2mps11_info *s2mps11;
Axel Linad46ed12012-07-13 10:12:40 +0800418 int i, ret;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900419 unsigned char ramp_enable, ramp_reg = 0;
420
Sangbeom Kimcb746852012-07-11 21:08:17 +0900421 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
422 GFP_KERNEL);
423 if (!s2mps11)
424 return -ENOMEM;
425
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530426 if (!iodev->dev->of_node)
427 goto p_data;
428
429 for (i = 0; i < S2MPS11_REGULATOR_CNT; i++)
430 rdata[i].name = regulators[i].name;
431
432 reg_np = of_find_node_by_name(iodev->dev->of_node, "regulators");
433 if (!reg_np) {
434 dev_err(&pdev->dev, "could not find regulators sub-node\n");
435 return -EINVAL;
436 }
437
438 of_regulator_match(&pdev->dev, reg_np, rdata, S2MPS11_REGULATOR_MAX);
439
440 goto common_reg;
441p_data:
442 if (!pdata) {
443 dev_err(pdev->dev.parent, "Platform data not supplied\n");
444 return -ENODEV;
445 }
Sangbeom Kimcb746852012-07-11 21:08:17 +0900446
447 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay;
448 s2mps11->ramp_delay34 = pdata->buck34_ramp_delay;
449 s2mps11->ramp_delay5 = pdata->buck5_ramp_delay;
450 s2mps11->ramp_delay16 = pdata->buck16_ramp_delay;
451 s2mps11->ramp_delay7810 = pdata->buck7810_ramp_delay;
452 s2mps11->ramp_delay9 = pdata->buck9_ramp_delay;
453
454 s2mps11->buck6_ramp = pdata->buck6_ramp_enable;
455 s2mps11->buck2_ramp = pdata->buck2_ramp_enable;
456 s2mps11->buck3_ramp = pdata->buck3_ramp_enable;
457 s2mps11->buck4_ramp = pdata->buck4_ramp_enable;
458
459 ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) |
460 (s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ;
461
462 if (ramp_enable) {
463 if (s2mps11->buck2_ramp)
Sangbeom Kimf7ebaae2012-11-24 11:13:28 +0900464 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay2) << 6;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900465 if (s2mps11->buck3_ramp || s2mps11->buck4_ramp)
Sangbeom Kimf7ebaae2012-11-24 11:13:28 +0900466 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay34) << 4;
Axel Linc06eed32012-07-12 09:39:10 +0800467 sec_reg_write(iodev, S2MPS11_REG_RAMP, ramp_reg | ramp_enable);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900468 }
469
470 ramp_reg &= 0x00;
Sangbeom Kimf7ebaae2012-11-24 11:13:28 +0900471 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay5) << 6;
472 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay16) << 4;
473 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay7810) << 2;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900474 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9);
Axel Linc06eed32012-07-12 09:39:10 +0800475 sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900476
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530477common_reg:
478 platform_set_drvdata(pdev, s2mps11);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900479
Yadwinder Singh Brara50c6b32013-06-29 18:21:17 +0530480 config.dev = &pdev->dev;
481 config.regmap = iodev->regmap;
482 config.driver_data = s2mps11;
483 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
484 if (!reg_np) {
485 config.init_data = pdata->regulators[i].initdata;
486 } else {
487 config.init_data = rdata[i].init_data;
488 config.of_node = rdata[i].of_node;
489 }
Sangbeom Kimcb746852012-07-11 21:08:17 +0900490
Axel Linad46ed12012-07-13 10:12:40 +0800491 s2mps11->rdev[i] = regulator_register(&regulators[i], &config);
492 if (IS_ERR(s2mps11->rdev[i])) {
493 ret = PTR_ERR(s2mps11->rdev[i]);
Axel Lin232b2502012-07-12 09:37:37 +0800494 dev_err(&pdev->dev, "regulator init failed for %d\n",
495 i);
Axel Linad46ed12012-07-13 10:12:40 +0800496 s2mps11->rdev[i] = NULL;
Sangbeom Kimcb746852012-07-11 21:08:17 +0900497 goto err;
498 }
499 }
500
501 return 0;
502err:
503 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
Axel Linad46ed12012-07-13 10:12:40 +0800504 regulator_unregister(s2mps11->rdev[i]);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900505
506 return ret;
507}
508
Bill Pemberton8dc995f2012-11-19 13:26:10 -0500509static int s2mps11_pmic_remove(struct platform_device *pdev)
Sangbeom Kimcb746852012-07-11 21:08:17 +0900510{
511 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900512 int i;
513
514 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
Axel Linad46ed12012-07-13 10:12:40 +0800515 regulator_unregister(s2mps11->rdev[i]);
Sangbeom Kimcb746852012-07-11 21:08:17 +0900516
517 return 0;
518}
519
520static const struct platform_device_id s2mps11_pmic_id[] = {
521 { "s2mps11-pmic", 0},
522 { },
523};
524MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
525
526static struct platform_driver s2mps11_pmic_driver = {
527 .driver = {
528 .name = "s2mps11-pmic",
529 .owner = THIS_MODULE,
530 },
531 .probe = s2mps11_pmic_probe,
Bill Pemberton5eb9f2b2012-11-19 13:20:42 -0500532 .remove = s2mps11_pmic_remove,
Sangbeom Kimcb746852012-07-11 21:08:17 +0900533 .id_table = s2mps11_pmic_id,
534};
535
536static int __init s2mps11_pmic_init(void)
537{
538 return platform_driver_register(&s2mps11_pmic_driver);
539}
540subsys_initcall(s2mps11_pmic_init);
541
542static void __exit s2mps11_pmic_exit(void)
543{
544 platform_driver_unregister(&s2mps11_pmic_driver);
545}
546module_exit(s2mps11_pmic_exit);
547
548/* Module information */
549MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
550MODULE_DESCRIPTION("SAMSUNG S2MPS11 Regulator Driver");
551MODULE_LICENSE("GPL");