23 #include <linux/module.h>
25 #include <linux/i2c.h>
28 #include <linux/slab.h>
56 .min = 800, .step = 50, .max = 1300,
59 .min = 1600, .step = 100, .max = 3600,
62 .min = 3000, .step = 100, .max = 3600,
65 .min = 2800, .step = 100, .max = 3100,
68 .min = 950, .step = 50, .max = 1300,
71 .min = 800, .step = 100, .max = 3300,
74 .min = 1200, .step = 100, .max = 3300,
77 .min = 1600, .step = 100, .max = 3600,
80 .min = 750, .step = 25, .max = 1525,
83 .min = 1600, .step = 100, .max = 3600,
86 .min = 800, .step = 100, .max = 2300,
92 &ldo23_voltage_map_desc,
93 &ldo23_voltage_map_desc,
94 &ldo456711_voltage_map_desc,
95 &ldo456711_voltage_map_desc,
96 &ldo456711_voltage_map_desc,
97 &ldo456711_voltage_map_desc,
98 &ldo8_voltage_map_desc,
99 &ldo9_voltage_map_desc,
100 &ldo10_voltage_map_desc,
101 &ldo456711_voltage_map_desc,
102 &ldo1213_voltage_map_desc,
103 &ldo1213_voltage_map_desc,
104 &ldo1415_voltage_map_desc,
105 &ldo1415_voltage_map_desc,
106 &ldo1617_voltage_map_desc,
107 &ldo1617_voltage_map_desc,
108 &buck12_voltage_map_desc,
109 &buck12_voltage_map_desc,
110 &buck3_voltage_map_desc,
111 &buck4_voltage_map_desc,
115 int *
reg,
int *shift)
151 static int max8998_ldo_is_enabled(
struct regulator_dev *rdev)
158 ret = max8998_get_enable_register(rdev, ®, &shift);
166 return val & (1 << shift);
175 ret = max8998_get_enable_register(rdev, ®, &shift);
188 ret = max8998_get_enable_register(rdev, ®, &shift);
195 static int max8998_get_voltage_register(
struct regulator_dev *rdev,
196 int *_reg,
int *_shift,
int *_mask)
200 int reg, shift = 0,
mask = 0xff;
258 static int max8998_get_voltage_sel(
struct regulator_dev *rdev)
265 ret = max8998_get_voltage_register(rdev, ®, &shift, &
mask);
279 static int max8998_set_voltage_ldo_sel(
struct regulator_dev *rdev,
286 ret = max8998_get_voltage_register(rdev, ®, &shift, &
mask);
295 static inline void buck1_gpio_set(
int gpio1,
int gpio2,
int v)
301 static inline void buck2_gpio_set(
int gpio,
int v)
306 static int max8998_set_voltage_buck_sel(
struct regulator_dev *rdev,
311 dev_get_platdata(max8998->
iodev->dev);
316 static u8 buck1_last_val;
318 ret = max8998_get_voltage_register(rdev, ®, &shift, &
mask);
322 previous_sel = max8998_get_voltage_sel(rdev);
326 if (previous_sel == selector) {
327 dev_dbg(max8998->
dev,
"No voltage change, old:%d, new:%d\n",
336 "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n"
337 "buck1_vol3:%d, buck1_vol4:%d\n",
359 max8998->
buck1_idx = (buck1_last_val % 2) + 2;
360 dev_dbg(max8998->
dev,
"max8998->buck1_idx:%d\n",
363 ret = max8998_get_voltage_register(rdev, ®,
371 dev_dbg(max8998->
dev,
"%s: SET1:%d, SET2:%d\n",
382 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n",
399 max8998_get_voltage_register(rdev,
400 ®, &shift, &
mask);
422 static int max8998_set_voltage_buck_time_sel(
struct regulator_dev *rdev,
423 unsigned int old_selector,
424 unsigned int new_selector)
436 desc = ldo_voltage_map[buck];
448 difference = (new_selector - old_selector) * desc->
step;
450 return difference / ((val & 0x0f) + 1);
458 .is_enabled = max8998_ldo_is_enabled,
459 .enable = max8998_ldo_enable,
460 .disable = max8998_ldo_disable,
461 .get_voltage_sel = max8998_get_voltage_sel,
462 .set_voltage_sel = max8998_set_voltage_ldo_sel,
468 .is_enabled = max8998_ldo_is_enabled,
469 .enable = max8998_ldo_enable,
470 .disable = max8998_ldo_disable,
471 .get_voltage_sel = max8998_get_voltage_sel,
472 .set_voltage_sel = max8998_set_voltage_buck_sel,
473 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
477 .is_enabled = max8998_ldo_is_enabled,
478 .enable = max8998_ldo_enable,
479 .disable = max8998_ldo_disable,
486 .ops = &max8998_ldo_ops,
492 .ops = &max8998_ldo_ops,
498 .ops = &max8998_ldo_ops,
504 .ops = &max8998_ldo_ops,
510 .ops = &max8998_ldo_ops,
516 .ops = &max8998_ldo_ops,
522 .ops = &max8998_ldo_ops,
528 .ops = &max8998_ldo_ops,
534 .ops = &max8998_ldo_ops,
540 .ops = &max8998_ldo_ops,
546 .ops = &max8998_ldo_ops,
552 .ops = &max8998_ldo_ops,
558 .ops = &max8998_ldo_ops,
564 .ops = &max8998_ldo_ops,
570 .ops = &max8998_ldo_ops,
576 .ops = &max8998_ldo_ops,
582 .ops = &max8998_buck_ops,
588 .ops = &max8998_buck_ops,
594 .ops = &max8998_buck_ops,
600 .ops = &max8998_buck_ops,
604 .name =
"EN32KHz AP",
606 .ops = &max8998_others_ops,
610 .name =
"EN32KHz CP",
612 .ops = &max8998_others_ops,
618 .ops = &max8998_others_ops,
624 .ops = &max8998_others_ops,
630 .ops = &max8998_others_ops,
647 dev_err(pdev->
dev.parent,
"No platform init data supplied\n");
661 rdev = max8998->
rdev;
662 max8998->
dev = &pdev->
dev;
663 max8998->
iodev = iodev;
665 platform_set_drvdata(pdev, max8998);
666 i2c = max8998->
iodev->i2c;
703 while (buck12_voltage_map_desc.
min +
704 buck12_voltage_map_desc.
step*i
714 while (buck12_voltage_map_desc.
min +
715 buck12_voltage_map_desc.
step*i
726 while (buck12_voltage_map_desc.
min +
727 buck12_voltage_map_desc.
step*i
738 while (buck12_voltage_map_desc.
min +
739 buck12_voltage_map_desc.
step*i
764 while (buck12_voltage_map_desc.
min +
765 buck12_voltage_map_desc.
step*i
775 while (buck12_voltage_map_desc.
min +
776 buck12_voltage_map_desc.
step*i
790 desc = ldo_voltage_map[
id];
791 if (desc && regulators[index].ops != &max8998_others_ops) {
795 regulators[index].
min_uV = desc->
min * 1000;
799 config.
dev = max8998->
dev;
804 if (IS_ERR(rdev[i])) {
805 ret = PTR_ERR(rdev[i]);
806 dev_err(max8998->
dev,
"regulator init failed\n");
823 struct max8998_data *max8998 = platform_get_drvdata(pdev);
841 .name =
"max8998-pmic",
844 .probe = max8998_pmic_probe,
846 .id_table = max8998_pmic_id,
849 static int __init max8998_pmic_init(
void)
855 static void __exit max8998_pmic_cleanup(
void)