17 #include <linux/slab.h>
18 #include <linux/module.h>
124 static unsigned int s5m8767_opmode_reg[][4] = {
127 {0x0, 0x3, 0x2, 0x1},
128 {0x0, 0x3, 0x2, 0x1},
129 {0x0, 0x3, 0x2, 0x1},
130 {0x0, 0x0, 0x0, 0x0},
131 {0x0, 0x3, 0x2, 0x1},
132 {0x0, 0x3, 0x2, 0x1},
133 {0x0, 0x3, 0x2, 0x1},
134 {0x0, 0x3, 0x2, 0x1},
135 {0x0, 0x3, 0x2, 0x1},
136 {0x0, 0x3, 0x2, 0x1},
137 {0x0, 0x3, 0x2, 0x1},
138 {0x0, 0x3, 0x2, 0x1},
139 {0x0, 0x3, 0x2, 0x1},
140 {0x0, 0x3, 0x2, 0x1},
141 {0x0, 0x3, 0x2, 0x1},
142 {0x0, 0x3, 0x2, 0x1},
143 {0x0, 0x3, 0x2, 0x1},
144 {0x0, 0x0, 0x0, 0x0},
145 {0x0, 0x3, 0x2, 0x1},
146 {0x0, 0x3, 0x2, 0x1},
147 {0x0, 0x3, 0x2, 0x1},
148 {0x0, 0x3, 0x2, 0x1},
149 {0x0, 0x0, 0x0, 0x0},
150 {0x0, 0x3, 0x2, 0x1},
151 {0x0, 0x3, 0x2, 0x1},
152 {0x0, 0x3, 0x2, 0x1},
153 {0x0, 0x3, 0x2, 0x1},
154 {0x0, 0x3, 0x2, 0x1},
157 {0x0, 0x3, 0x1, 0x1},
158 {0x0, 0x3, 0x1, 0x1},
159 {0x0, 0x3, 0x1, 0x1},
160 {0x0, 0x3, 0x1, 0x1},
161 {0x0, 0x3, 0x2, 0x1},
162 {0x0, 0x3, 0x1, 0x1},
163 {0x0, 0x3, 0x1, 0x1},
164 {0x0, 0x3, 0x1, 0x1},
165 {0x0, 0x3, 0x1, 0x1},
198 mode = s5m8767->
opmode[reg_id].mode;
203 static int s5m8767_reg_is_enabled(
struct regulator_dev *rdev)
207 int mask = 0xc0, enable_ctrl;
210 ret = s5m8767_get_register(rdev, ®, &enable_ctrl);
220 return (val & mask) == enable_ctrl;
227 int mask = 0xc0, enable_ctrl;
229 ret = s5m8767_get_register(rdev, ®, &enable_ctrl);
240 int mask = 0xc0, enable_ctrl;
242 ret = s5m8767_get_register(rdev, ®, &enable_ctrl);
249 static int s5m8767_get_voltage_register(
struct regulator_dev *rdev,
int *_reg)
295 static int s5m8767_get_voltage_sel(
struct regulator_dev *rdev)
302 ret = s5m8767_get_voltage_register(rdev, ®);
317 static int s5m8767_convert_voltage_to_sel(
319 int min_vol,
int max_vol)
326 if (max_vol < desc->
min || min_vol > desc->
max)
329 if (min_vol < desc->
min)
334 if (desc->
min + desc->
step * selector > max_vol)
340 static inline int s5m8767_set_high(
struct s5m8767_info *s5m8767)
351 static inline int s5m8767_set_low(
struct s5m8767_info *s5m8767)
362 static int s5m8767_set_voltage_sel(
struct regulator_dev *rdev,
394 while (*buck234_vol != selector) {
401 if (index > old_index)
402 return s5m8767_set_high(s5m8767);
404 return s5m8767_set_low(s5m8767);
406 ret = s5m8767_get_voltage_register(rdev, ®);
414 static int s5m8767_set_voltage_time_sel(
struct regulator_dev *rdev,
415 unsigned int old_sel,
416 unsigned int new_sel)
422 desc = reg_voltage_map[reg_id];
424 if ((old_sel < new_sel) && s5m8767->
ramp_delay)
432 .is_enabled = s5m8767_reg_is_enabled,
433 .enable = s5m8767_reg_enable,
434 .disable = s5m8767_reg_disable,
435 .get_voltage_sel = s5m8767_get_voltage_sel,
436 .set_voltage_sel = s5m8767_set_voltage_sel,
437 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
441 .is_enabled = s5m8767_reg_is_enabled,
442 .enable = s5m8767_reg_enable,
443 .disable = s5m8767_reg_disable,
446 #define s5m8767_regulator_desc(_name) { \
448 .id = S5M8767_##_name, \
449 .ops = &s5m8767_ops, \
450 .type = REGULATOR_VOLTAGE, \
451 .owner = THIS_MODULE, \
454 #define s5m8767_regulator_buck78_desc(_name) { \
456 .id = S5M8767_##_name, \
457 .ops = &s5m8767_buck78_ops, \
458 .type = REGULATOR_VOLTAGE, \
459 .owner = THIS_MODULE, \
512 dev_err(pdev->
dev.parent,
"Platform data not supplied\n");
518 dev_err(&pdev->
dev,
"S5M8767 GPIO DVS NOT VALID\n");
525 dev_err(&pdev->
dev,
"S5M8767 GPIO DVS NOT VALID\n");
532 dev_err(&pdev->
dev,
"S5M8767 GPIO DVS NOT VALID\n");
547 rdev = s5m8767->
rdev;
548 s5m8767->
dev = &pdev->
dev;
549 s5m8767->
iodev = iodev;
551 platform_set_drvdata(pdev, s5m8767);
570 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
573 buck_voltage_val2.
step);
577 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
580 buck_voltage_val2.
step);
584 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
587 buck_voltage_val2.
step);
591 for (i = 0; i < 8; i++) {
594 s5m8767_convert_voltage_to_sel(
598 buck_voltage_val2.
step);
603 s5m8767_convert_voltage_to_sel(
607 buck_voltage_val2.
step);
612 s5m8767_convert_voltage_to_sel(
616 buck_voltage_val2.
step);
686 for (i = 0; i < 8; i++) {
745 desc = reg_voltage_map[
id];
753 config.
dev = s5m8767->
dev;
758 if (IS_ERR(rdev[i])) {
759 ret = PTR_ERR(rdev[i]);
760 dev_err(s5m8767->
dev,
"regulator init failed for %d\n",
778 struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev);
790 {
"s5m8767-pmic", 0},
797 .name =
"s5m8767-pmic",
800 .probe = s5m8767_pmic_probe,
802 .id_table = s5m8767_pmic_id,
805 static int __init s5m8767_pmic_init(
void)
811 static void __exit s5m8767_pmic_exit(
void)