regulator: Update tps65217-regulator for DT changes
[deliverable/linux.git] / drivers / regulator / s5m8767.c
CommitLineData
9767ec7f
SK
1/*
2 * s5m8767.c
3 *
4 * Copyright (c) 2011 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>
15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/mfd/s5m87xx/s5m-core.h>
24#include <linux/mfd/s5m87xx/s5m-pmic.h>
25
26struct s5m8767_info {
27 struct device *dev;
28 struct s5m87xx_dev *iodev;
29 int num_regulators;
30 struct regulator_dev **rdev;
31
32 int ramp_delay;
33 bool buck2_ramp;
34 bool buck3_ramp;
35 bool buck4_ramp;
36
37 bool buck2_gpiodvs;
38 bool buck3_gpiodvs;
39 bool buck4_gpiodvs;
40 u8 buck2_vol[8];
41 u8 buck3_vol[8];
42 u8 buck4_vol[8];
43 int buck_gpios[3];
44 int buck_gpioindex;
45};
46
47struct s5m_voltage_desc {
48 int max;
49 int min;
50 int step;
51};
52
53static const struct s5m_voltage_desc buck_voltage_val1 = {
54 .max = 2225000,
55 .min = 650000,
56 .step = 6250,
57};
58
59static const struct s5m_voltage_desc buck_voltage_val2 = {
60 .max = 1600000,
61 .min = 600000,
62 .step = 6250,
63};
64
65static const struct s5m_voltage_desc buck_voltage_val3 = {
66 .max = 3000000,
67 .min = 750000,
68 .step = 12500,
69};
70
71static const struct s5m_voltage_desc ldo_voltage_val1 = {
72 .max = 3950000,
73 .min = 800000,
74 .step = 50000,
75};
76
77static const struct s5m_voltage_desc ldo_voltage_val2 = {
78 .max = 2375000,
79 .min = 800000,
80 .step = 25000,
81};
82
83static const struct s5m_voltage_desc *reg_voltage_map[] = {
84 [S5M8767_LDO1] = &ldo_voltage_val2,
85 [S5M8767_LDO2] = &ldo_voltage_val2,
86 [S5M8767_LDO3] = &ldo_voltage_val1,
87 [S5M8767_LDO4] = &ldo_voltage_val1,
88 [S5M8767_LDO5] = &ldo_voltage_val1,
89 [S5M8767_LDO6] = &ldo_voltage_val2,
90 [S5M8767_LDO7] = &ldo_voltage_val2,
91 [S5M8767_LDO8] = &ldo_voltage_val2,
92 [S5M8767_LDO9] = &ldo_voltage_val1,
93 [S5M8767_LDO10] = &ldo_voltage_val1,
94 [S5M8767_LDO11] = &ldo_voltage_val1,
95 [S5M8767_LDO12] = &ldo_voltage_val1,
96 [S5M8767_LDO13] = &ldo_voltage_val1,
97 [S5M8767_LDO14] = &ldo_voltage_val1,
98 [S5M8767_LDO15] = &ldo_voltage_val2,
99 [S5M8767_LDO16] = &ldo_voltage_val1,
100 [S5M8767_LDO17] = &ldo_voltage_val1,
101 [S5M8767_LDO18] = &ldo_voltage_val1,
102 [S5M8767_LDO19] = &ldo_voltage_val1,
103 [S5M8767_LDO20] = &ldo_voltage_val1,
104 [S5M8767_LDO21] = &ldo_voltage_val1,
105 [S5M8767_LDO22] = &ldo_voltage_val1,
106 [S5M8767_LDO23] = &ldo_voltage_val1,
107 [S5M8767_LDO24] = &ldo_voltage_val1,
108 [S5M8767_LDO25] = &ldo_voltage_val1,
109 [S5M8767_LDO26] = &ldo_voltage_val1,
110 [S5M8767_LDO27] = &ldo_voltage_val1,
111 [S5M8767_LDO28] = &ldo_voltage_val1,
112 [S5M8767_BUCK1] = &buck_voltage_val1,
113 [S5M8767_BUCK2] = &buck_voltage_val2,
114 [S5M8767_BUCK3] = &buck_voltage_val2,
115 [S5M8767_BUCK4] = &buck_voltage_val2,
116 [S5M8767_BUCK5] = &buck_voltage_val1,
117 [S5M8767_BUCK6] = &buck_voltage_val1,
118 [S5M8767_BUCK7] = NULL,
119 [S5M8767_BUCK8] = NULL,
120 [S5M8767_BUCK9] = &buck_voltage_val3,
121};
122
123static inline int s5m8767_get_reg_id(struct regulator_dev *rdev)
124{
125 return rdev_get_id(rdev);
126}
127
128static int s5m8767_list_voltage(struct regulator_dev *rdev,
129 unsigned int selector)
130{
131 const struct s5m_voltage_desc *desc;
132 int reg_id = s5m8767_get_reg_id(rdev);
133 int val;
134
135 if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0)
136 return -EINVAL;
137
138 desc = reg_voltage_map[reg_id];
139 if (desc == NULL)
140 return -EINVAL;
141
142 val = desc->min + desc->step * selector;
143 if (val > desc->max)
144 return -EINVAL;
145
146 return val;
147}
148
149static int s5m8767_get_register(struct regulator_dev *rdev, int *reg)
150{
151 int reg_id = s5m8767_get_reg_id(rdev);
152
153 switch (reg_id) {
154 case S5M8767_LDO1 ... S5M8767_LDO2:
155 *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
156 break;
157 case S5M8767_LDO3 ... S5M8767_LDO28:
158 *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
159 break;
160 case S5M8767_BUCK1:
161 *reg = S5M8767_REG_BUCK1CTRL1;
162 break;
163 case S5M8767_BUCK2 ... S5M8767_BUCK4:
164 *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9;
165 break;
166 case S5M8767_BUCK5:
167 *reg = S5M8767_REG_BUCK5CTRL1;
168 break;
169 case S5M8767_BUCK6 ... S5M8767_BUCK9:
170 *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2;
171 break;
172 default:
173 return -EINVAL;
174 }
175
176 return 0;
177}
178
179static int s5m8767_reg_is_enabled(struct regulator_dev *rdev)
180{
181 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
182 int ret, reg;
183 int mask = 0xc0, pattern = 0xc0;
184 u8 val;
185
186 ret = s5m8767_get_register(rdev, &reg);
187 if (ret == -EINVAL)
188 return 1;
189 else if (ret)
190 return ret;
191
192 ret = s5m_reg_read(s5m8767->iodev, reg, &val);
193 if (ret)
194 return ret;
195
196 return (val & mask) == pattern;
197}
198
199static int s5m8767_reg_enable(struct regulator_dev *rdev)
200{
201 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
202 int ret, reg;
203 int mask = 0xc0, pattern = 0xc0;
204
205 ret = s5m8767_get_register(rdev, &reg);
206 if (ret)
207 return ret;
208
209 return s5m_reg_update(s5m8767->iodev, reg, pattern, mask);
210}
211
212static int s5m8767_reg_disable(struct regulator_dev *rdev)
213{
214 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
215 int ret, reg;
216 int mask = 0xc0, pattern = 0xc0;
217
218 ret = s5m8767_get_register(rdev, &reg);
219 if (ret)
220 return ret;
221
222 return s5m_reg_update(s5m8767->iodev, reg, ~pattern, mask);
223}
224
225static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
226{
227 int reg_id = s5m8767_get_reg_id(rdev);
228 int reg;
229
230 switch (reg_id) {
231 case S5M8767_LDO1 ... S5M8767_LDO2:
232 reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
233 break;
234 case S5M8767_LDO3 ... S5M8767_LDO28:
235 reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
236 break;
237 case S5M8767_BUCK1:
238 reg = S5M8767_REG_BUCK1CTRL2;
239 break;
240 case S5M8767_BUCK2:
241 reg = S5M8767_REG_BUCK2DVS1;
242 break;
243 case S5M8767_BUCK3:
244 reg = S5M8767_REG_BUCK3DVS1;
245 break;
246 case S5M8767_BUCK4:
247 reg = S5M8767_REG_BUCK4DVS1;
248 break;
249 case S5M8767_BUCK5:
250 reg = S5M8767_REG_BUCK5CTRL2;
251 break;
252 case S5M8767_BUCK6 ... S5M8767_BUCK9:
253 reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2;
254 break;
255 default:
256 return -EINVAL;
257 }
258
259 *_reg = reg;
260
261 return 0;
262}
263
264static int s5m8767_get_voltage_sel(struct regulator_dev *rdev)
265{
266 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
267 int reg, mask = 0xff, ret;
268 int reg_id = s5m8767_get_reg_id(rdev);
269 u8 val;
270
271 ret = s5m8767_get_voltage_register(rdev, &reg);
272 if (ret)
273 return ret;
274
275 switch (reg_id) {
276 case S5M8767_LDO1 ... S5M8767_LDO28:
277 mask = 0x3f;
278 break;
279 case S5M8767_BUCK2:
280 if (s5m8767->buck2_gpiodvs)
281 reg += s5m8767->buck_gpioindex;
282 break;
283 case S5M8767_BUCK3:
284 if (s5m8767->buck3_gpiodvs)
285 reg += s5m8767->buck_gpioindex;
286 break;
287 case S5M8767_BUCK4:
288 if (s5m8767->buck4_gpiodvs)
289 reg += s5m8767->buck_gpioindex;
290 break;
291 }
292
293 ret = s5m_reg_read(s5m8767->iodev, reg, &val);
294 if (ret)
295 return ret;
296
297 val &= mask;
298
299 return val;
300}
301
302static inline int s5m8767_convert_voltage(
303 const struct s5m_voltage_desc *desc,
304 int min_vol, int max_vol)
305{
306 int out_vol = 0;
307
308 if (desc == NULL)
309 return -EINVAL;
310
311 if (max_vol < desc->min || min_vol > desc->max)
312 return -EINVAL;
313
314 out_vol = (min_vol - desc->min) / desc->step;
315
316 if (desc->min + desc->step * out_vol > max_vol)
317 return -EINVAL;
318
319 return out_vol;
320}
321
322static int s5m8767_set_voltage(struct regulator_dev *rdev,
323 int min_uV, int max_uV, unsigned *selector)
324{
325 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
326 int min_vol = min_uV, max_vol = max_uV;
327 const struct s5m_voltage_desc *desc;
328 int reg_id = s5m8767_get_reg_id(rdev);
329 int reg, mask, ret;
330 int i;
331 u8 val;
332
333 switch (reg_id) {
334 case S5M8767_LDO1 ... S5M8767_LDO28:
335 mask = 0x3f;
336 break;
337 case S5M8767_BUCK1 ... S5M8767_BUCK6:
338 mask = 0xff;
339 break;
340 case S5M8767_BUCK7 ... S5M8767_BUCK8:
341 return -EINVAL;
342 case S5M8767_BUCK9:
343 mask = 0xff;
344 break;
345 default:
346 return -EINVAL;
347 }
348
349 desc = reg_voltage_map[reg_id];
350
351 i = s5m8767_convert_voltage(desc, min_vol, max_vol);
352 if (i < 0)
353 return i;
354
355 ret = s5m8767_get_voltage_register(rdev, &reg);
356 if (ret)
357 return ret;
358
359 s5m_reg_read(s5m8767->iodev, reg, &val);
360 val = val & mask;
361
362 ret = s5m_reg_write(s5m8767->iodev, reg, val);
363 *selector = i;
364
365 return ret;
366}
367
368static inline void s5m8767_set_high(struct s5m8767_info *s5m8767)
369{
370 int temp_index = s5m8767->buck_gpioindex;
371
372 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
373 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
374 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
375}
376
377static inline void s5m8767_set_low(struct s5m8767_info *s5m8767)
378{
379 int temp_index = s5m8767->buck_gpioindex;
380
381 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
382 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
383 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
384}
385
386static int s5m8767_set_voltage_buck(struct regulator_dev *rdev,
387 int min_uV, int max_uV, unsigned *selector)
388{
389 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
390 int reg_id = s5m8767_get_reg_id(rdev);
391 const struct s5m_voltage_desc *desc;
392 int new_val, old_val, i = 0;
393 int min_vol = min_uV, max_vol = max_uV;
394
395 if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6)
396 return -EINVAL;
397
398 switch (reg_id) {
399 case S5M8767_BUCK1:
400 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
401 case S5M8767_BUCK2 ... S5M8767_BUCK4:
402 break;
403 case S5M8767_BUCK5 ... S5M8767_BUCK6:
404 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
405 case S5M8767_BUCK9:
406 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
407 }
408
409 desc = reg_voltage_map[reg_id];
410 new_val = s5m8767_convert_voltage(desc, min_vol, max_vol);
411 if (new_val < 0)
412 return new_val;
413
414 switch (reg_id) {
415 case S5M8767_BUCK2:
416 if (s5m8767->buck2_gpiodvs) {
417 while (s5m8767->buck2_vol[i] != new_val)
418 i++;
419 } else
420 return s5m8767_set_voltage(rdev, min_uV,
421 max_uV, selector);
422 break;
423 case S5M8767_BUCK3:
424 if (s5m8767->buck3_gpiodvs) {
425 while (s5m8767->buck3_vol[i] != new_val)
426 i++;
427 } else
428 return s5m8767_set_voltage(rdev, min_uV,
429 max_uV, selector);
430 break;
431 case S5M8767_BUCK4:
432 if (s5m8767->buck3_gpiodvs) {
433 while (s5m8767->buck4_vol[i] != new_val)
434 i++;
435 } else
436 return s5m8767_set_voltage(rdev, min_uV,
437 max_uV, selector);
438 break;
439 }
440
441 old_val = s5m8767->buck_gpioindex;
442 s5m8767->buck_gpioindex = i;
443
444 if (i > old_val)
445 s5m8767_set_high(s5m8767);
446 else
447 s5m8767_set_low(s5m8767);
448
449 *selector = new_val;
450 return 0;
451}
452
453static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
454 unsigned int old_sel,
455 unsigned int new_sel)
456{
457 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
458 const struct s5m_voltage_desc *desc;
459 int reg_id = s5m8767_get_reg_id(rdev);
460 int mask;
461 int new_val, old_val;
462
463 switch (reg_id) {
464 case S5M8767_LDO1 ... S5M8767_LDO28:
465 mask = 0x3f;
466 break;
467 case S5M8767_BUCK1 ... S5M8767_BUCK6:
468 mask = 0xff;
469 break;
470 case S5M8767_BUCK7 ... S5M8767_BUCK8:
471 return -EINVAL;
472 case S5M8767_BUCK9:
473 mask = 0xff;
474 break;
475 default:
476 return -EINVAL;
477 }
478 desc = reg_voltage_map[reg_id];
479
480 new_val = s5m8767_convert_voltage(desc, new_sel, new_sel);
481 if (new_val < 0)
482 return new_val;
483
484 old_val = s5m8767_convert_voltage(desc, old_sel, old_sel);
485 if (old_val < 0)
486 return old_val;
487
488 if (old_sel < new_sel)
489 return DIV_ROUND_UP(desc->step * (new_val - old_val),
490 s5m8767->ramp_delay);
491 else
492 return 0;
493}
494
495static struct regulator_ops s5m8767_ldo_ops = {
496 .list_voltage = s5m8767_list_voltage,
497 .is_enabled = s5m8767_reg_is_enabled,
498 .enable = s5m8767_reg_enable,
499 .disable = s5m8767_reg_disable,
500 .get_voltage_sel = s5m8767_get_voltage_sel,
501 .set_voltage = s5m8767_set_voltage,
502 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
503};
504
505static struct regulator_ops s5m8767_buck_ops = {
506 .list_voltage = s5m8767_list_voltage,
507 .is_enabled = s5m8767_reg_is_enabled,
508 .enable = s5m8767_reg_enable,
509 .disable = s5m8767_reg_disable,
510 .get_voltage_sel = s5m8767_get_voltage_sel,
511 .set_voltage = s5m8767_set_voltage_buck,
512 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
513};
514
515#define regulator_desc_ldo(num) { \
516 .name = "LDO"#num, \
517 .id = S5M8767_LDO##num, \
518 .ops = &s5m8767_ldo_ops, \
519 .type = REGULATOR_VOLTAGE, \
520 .owner = THIS_MODULE, \
521}
522#define regulator_desc_buck(num) { \
523 .name = "BUCK"#num, \
524 .id = S5M8767_BUCK##num, \
525 .ops = &s5m8767_buck_ops, \
526 .type = REGULATOR_VOLTAGE, \
527 .owner = THIS_MODULE, \
528}
529
530static struct regulator_desc regulators[] = {
531 regulator_desc_ldo(1),
532 regulator_desc_ldo(2),
533 regulator_desc_ldo(3),
534 regulator_desc_ldo(4),
535 regulator_desc_ldo(5),
536 regulator_desc_ldo(6),
537 regulator_desc_ldo(7),
538 regulator_desc_ldo(8),
539 regulator_desc_ldo(9),
540 regulator_desc_ldo(10),
541 regulator_desc_ldo(11),
542 regulator_desc_ldo(12),
543 regulator_desc_ldo(13),
544 regulator_desc_ldo(14),
545 regulator_desc_ldo(15),
546 regulator_desc_ldo(16),
547 regulator_desc_ldo(17),
548 regulator_desc_ldo(18),
549 regulator_desc_ldo(19),
550 regulator_desc_ldo(20),
551 regulator_desc_ldo(21),
552 regulator_desc_ldo(22),
553 regulator_desc_ldo(23),
554 regulator_desc_ldo(24),
555 regulator_desc_ldo(25),
556 regulator_desc_ldo(26),
557 regulator_desc_ldo(27),
558 regulator_desc_ldo(28),
559 regulator_desc_buck(1),
560 regulator_desc_buck(2),
561 regulator_desc_buck(3),
562 regulator_desc_buck(4),
563 regulator_desc_buck(5),
564 regulator_desc_buck(6),
565 regulator_desc_buck(7),
566 regulator_desc_buck(8),
567 regulator_desc_buck(9),
568};
569
570static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
571{
572 struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent);
573 struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev);
574 struct regulator_dev **rdev;
575 struct s5m8767_info *s5m8767;
576 struct i2c_client *i2c;
577 int i, ret, size, reg;
578
579 if (!pdata) {
580 dev_err(pdev->dev.parent, "Platform data not supplied\n");
581 return -ENODEV;
582 }
583
584 s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info),
585 GFP_KERNEL);
586 if (!s5m8767)
587 return -ENOMEM;
588
589 size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2);
590 s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
591 if (!s5m8767->rdev)
592 return -ENOMEM;
593
594 rdev = s5m8767->rdev;
595 s5m8767->dev = &pdev->dev;
596 s5m8767->iodev = iodev;
597 s5m8767->num_regulators = S5M8767_REG_MAX - 2;
598 platform_set_drvdata(pdev, s5m8767);
599 i2c = s5m8767->iodev->i2c;
600
601 s5m8767->buck_gpioindex = pdata->buck_default_idx;
602 s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs;
603 s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs;
604 s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs;
605 s5m8767->buck_gpios[0] = pdata->buck_gpios[0];
606 s5m8767->buck_gpios[1] = pdata->buck_gpios[1];
607 s5m8767->buck_gpios[2] = pdata->buck_gpios[2];
608 s5m8767->ramp_delay = pdata->buck_ramp_delay;
609 s5m8767->buck2_ramp = pdata->buck2_ramp_enable;
610 s5m8767->buck3_ramp = pdata->buck3_ramp_enable;
611 s5m8767->buck4_ramp = pdata->buck4_ramp_enable;
612
613 for (i = 0; i < 8; i++) {
614 if (s5m8767->buck2_gpiodvs) {
615 s5m8767->buck2_vol[i] =
616 s5m8767_convert_voltage(
617 &buck_voltage_val2,
618 pdata->buck2_voltage[i],
619 pdata->buck2_voltage[i] +
620 buck_voltage_val2.step);
621 }
622
623 if (s5m8767->buck3_gpiodvs) {
624 s5m8767->buck3_vol[i] =
625 s5m8767_convert_voltage(
626 &buck_voltage_val2,
627 pdata->buck3_voltage[i],
628 pdata->buck3_voltage[i] +
629 buck_voltage_val2.step);
630 }
631
632 if (s5m8767->buck4_gpiodvs) {
633 s5m8767->buck4_vol[i] =
634 s5m8767_convert_voltage(
635 &buck_voltage_val2,
636 pdata->buck4_voltage[i],
637 pdata->buck4_voltage[i] +
638 buck_voltage_val2.step);
639 }
640 }
641
642 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
643 pdata->buck4_gpiodvs) {
644 if (gpio_is_valid(pdata->buck_gpios[0]) &&
645 gpio_is_valid(pdata->buck_gpios[1]) &&
646 gpio_is_valid(pdata->buck_gpios[2])) {
647 ret = gpio_request(pdata->buck_gpios[0],
648 "S5M8767 SET1");
649 if (ret == -EBUSY)
650 dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n");
651
652 ret = gpio_request(pdata->buck_gpios[1],
653 "S5M8767 SET2");
654 if (ret == -EBUSY)
655 dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n");
656
657 ret = gpio_request(pdata->buck_gpios[2],
658 "S5M8767 SET3");
659 if (ret == -EBUSY)
660 dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n");
661 /* SET1 GPIO */
662 gpio_direction_output(pdata->buck_gpios[0],
663 (s5m8767->buck_gpioindex >> 2) & 0x1);
664 /* SET2 GPIO */
665 gpio_direction_output(pdata->buck_gpios[1],
666 (s5m8767->buck_gpioindex >> 1) & 0x1);
667 /* SET3 GPIO */
668 gpio_direction_output(pdata->buck_gpios[2],
669 (s5m8767->buck_gpioindex >> 0) & 0x1);
670 ret = 0;
671 } else {
672 dev_err(&pdev->dev, "GPIO NOT VALID\n");
673 ret = -EINVAL;
674 return ret;
675 }
676 }
677
678 if (pdata->buck2_gpiodvs) {
679 if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) {
680 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
681 ret = -EINVAL;
682 return ret;
683 }
684 }
685
686 if (pdata->buck3_gpiodvs) {
687 if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) {
688 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
689 ret = -EINVAL;
690 return ret;
691 }
692 }
693
694 if (pdata->buck4_gpiodvs) {
695 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) {
696 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
697 ret = -EINVAL;
698 return ret;
699 }
700 }
701
702 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL,
703 (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
704 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL,
705 (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
706 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL,
707 (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
708
709 /* Initialize GPIO DVS registers */
710 for (i = 0; i < 8; i++) {
711 if (s5m8767->buck2_gpiodvs) {
712 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i,
713 s5m8767->buck2_vol[i]);
714 }
715
716 if (s5m8767->buck3_gpiodvs) {
717 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i,
718 s5m8767->buck3_vol[i]);
719 }
720
721 if (s5m8767->buck4_gpiodvs) {
722 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i,
723 s5m8767->buck4_vol[i]);
724 }
725 }
726 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff);
727 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff);
728 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff);
729
730 if (s5m8767->buck2_ramp)
731 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08);
732
733 if (s5m8767->buck3_ramp)
734 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04);
735
736 if (s5m8767->buck4_ramp)
737 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02);
738
739 if (s5m8767->buck2_ramp || s5m8767->buck3_ramp
740 || s5m8767->buck4_ramp) {
741 switch (s5m8767->ramp_delay) {
742 case 15:
743 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
744 0xc0, 0xf0);
047ec220 745 break;
9767ec7f
SK
746 case 25:
747 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
748 0xd0, 0xf0);
047ec220 749 break;
9767ec7f
SK
750 case 50:
751 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
752 0xe0, 0xf0);
047ec220 753 break;
9767ec7f
SK
754 case 100:
755 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
756 0xf0, 0xf0);
047ec220 757 break;
9767ec7f
SK
758 default:
759 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
760 0x90, 0xf0);
761 }
762 }
763
764 for (i = 0; i < pdata->num_regulators; i++) {
765 const struct s5m_voltage_desc *desc;
766 int id = pdata->regulators[i].id;
767
768 desc = reg_voltage_map[id];
769 if (desc)
770 regulators[id].n_voltages =
771 (desc->max - desc->min) / desc->step + 1;
772
773 rdev[i] = regulator_register(&regulators[id], s5m8767->dev,
774 pdata->regulators[i].initdata, s5m8767);
775 if (IS_ERR(rdev[i])) {
776 ret = PTR_ERR(rdev[i]);
777 dev_err(s5m8767->dev, "regulator init failed for %d\n",
778 id);
779 rdev[i] = NULL;
780 goto err;
781 }
782 }
783
784 return 0;
785err:
786 for (i = 0; i < s5m8767->num_regulators; i++)
787 if (rdev[i])
788 regulator_unregister(rdev[i]);
789
790 return ret;
791}
792
793static int __devexit s5m8767_pmic_remove(struct platform_device *pdev)
794{
795 struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev);
796 struct regulator_dev **rdev = s5m8767->rdev;
797 int i;
798
799 for (i = 0; i < s5m8767->num_regulators; i++)
800 if (rdev[i])
801 regulator_unregister(rdev[i]);
802
803 return 0;
804}
805
806static const struct platform_device_id s5m8767_pmic_id[] = {
807 { "s5m8767-pmic", 0},
808 { },
809};
810MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id);
811
812static struct platform_driver s5m8767_pmic_driver = {
813 .driver = {
814 .name = "s5m8767-pmic",
815 .owner = THIS_MODULE,
816 },
817 .probe = s5m8767_pmic_probe,
818 .remove = __devexit_p(s5m8767_pmic_remove),
819 .id_table = s5m8767_pmic_id,
820};
821
822static int __init s5m8767_pmic_init(void)
823{
824 return platform_driver_register(&s5m8767_pmic_driver);
825}
826subsys_initcall(s5m8767_pmic_init);
827
828static void __exit s5m8767_pmic_exit(void)
829{
830 platform_driver_unregister(&s5m8767_pmic_driver);
831}
832module_exit(s5m8767_pmic_exit);
833
834/* Module information */
835MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
836MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver");
837MODULE_LICENSE("GPL");
This page took 0.054047 seconds and 5 git commands to generate.