15 #include <linux/module.h>
18 #include <linux/bitops.h>
20 #include <linux/i2c.h>
28 #define WM8350_DCDC_MAX_VSEL 0x66
31 static const int isink_cur[] = {
98 static int get_isink_val(
int min_uA,
int max_uA,
u16 *setting)
103 if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
119 ret = get_isink_val(min_uA, max_uA, &setting);
143 static int wm8350_isink_get_current(
struct regulator_dev *rdev)
162 return isink_cur[
val];
173 switch (wm8350->
pmic.isink_A_dcdc) {
181 1 << (wm8350->
pmic.isink_A_dcdc -
189 switch (wm8350->
pmic.isink_B_dcdc) {
197 1 << (wm8350->
pmic.isink_B_dcdc -
217 switch (wm8350->
pmic.isink_A_dcdc) {
221 1 << (wm8350->
pmic.isink_A_dcdc -
231 switch (wm8350->
pmic.isink_B_dcdc) {
235 1 << (wm8350->
pmic.isink_B_dcdc -
250 static int wm8350_isink_is_enabled(
struct regulator_dev *rdev)
266 static int wm8350_isink_enable_time(
struct regulator_dev *rdev)
318 (mode ? WM8350_CS1_FLASH_MODE : 0) |
320 duration | on_ramp | off_ramp | drive);
326 duration | on_ramp | off_ramp | drive);
335 static int wm8350_dcdc_set_suspend_voltage(
struct regulator_dev *rdev,
int uV)
341 dev_dbg(wm8350->
dev,
"%s %d mV %d\n", __func__, dcdc, uV / 1000);
372 static int wm8350_dcdc_set_suspend_enable(
struct regulator_dev *rdev)
383 val | wm8350->
pmic.dcdc1_hib_mode);
389 val | wm8350->
pmic.dcdc3_hib_mode);
395 val | wm8350->
pmic.dcdc4_hib_mode);
401 val | wm8350->
pmic.dcdc6_hib_mode);
412 static int wm8350_dcdc_set_suspend_disable(
struct regulator_dev *rdev)
452 static int wm8350_dcdc25_set_suspend_enable(
struct regulator_dev *rdev)
477 static int wm8350_dcdc25_set_suspend_disable(
struct regulator_dev *rdev)
502 static int wm8350_dcdc_set_suspend_mode(
struct regulator_dev *rdev,
511 hib_mode = &wm8350->
pmic.dcdc1_hib_mode;
514 hib_mode = &wm8350->
pmic.dcdc3_hib_mode;
517 hib_mode = &wm8350->
pmic.dcdc4_hib_mode;
520 hib_mode = &wm8350->
pmic.dcdc6_hib_mode;
545 static int wm8350_ldo_list_voltage(
struct regulator_dev *rdev,
552 return (selector * 50000) + 900000;
554 return ((selector - 16) * 100000) + 1800000;
557 static int wm8350_ldo_map_voltage(
struct regulator_dev *rdev,
int min_uV,
561 int min_mV = min_uV / 1000;
562 int max_mV = max_uV / 1000;
564 if (min_mV < 900 || min_mV > 3300)
566 if (max_mV < 900 || max_mV > 3300)
574 volt = wm8350_ldo_list_voltage(rdev, sel);
575 if (volt < min_uV || volt > max_uV)
581 static int wm8350_ldo_set_suspend_voltage(
struct regulator_dev *rdev,
int uV)
587 dev_dbg(wm8350->
dev,
"%s %d mV %d\n", __func__, ldo, uV / 1000);
606 sel = wm8350_ldo_map_voltage(rdev, uV, uV);
616 static int wm8350_ldo_set_suspend_enable(
struct regulator_dev *rdev)
645 static int wm8350_ldo_set_suspend_disable(
struct regulator_dev *rdev)
680 dev_dbg(wm8350->
dev,
"%s %d start %d stop %d\n",
681 __func__, dcdc, start, stop);
684 if (start > 15 || stop > 15)
727 dev_dbg(wm8350->
dev,
"%s %d start %d stop %d\n",
728 __func__, ldo, start, stop);
731 if (start > 15 || stop > 15)
762 dev_dbg(wm8350->
dev,
"%s %d mode: %s %s\n", __func__, dcdc,
763 mode ?
"normal" :
"boost", ilim ?
"low" :
"normal");
794 static int force_continuous_enable(
struct wm8350 *wm8350,
int dcdc,
int enable)
824 static int wm8350_dcdc_set_mode(
struct regulator_dev *rdev,
unsigned int mode)
843 force_continuous_enable(wm8350, dcdc, 1);
849 force_continuous_enable(wm8350, dcdc, 0);
853 force_continuous_enable(wm8350, dcdc, 0);
859 force_continuous_enable(wm8350, dcdc, 0);
867 static unsigned int wm8350_dcdc_get_mode(
struct regulator_dev *rdev)
897 dev_dbg(wm8350->
dev,
"mask %x active %x sleep %x force %x",
898 mask, active, sleep, force);
900 if (active && !sleep) {
905 }
else if (!active && !sleep)
913 static unsigned int wm8350_ldo_get_mode(
struct regulator_dev *rdev)
953 static unsigned int wm8350_dcdc_get_optimum_mode(
struct regulator_dev *rdev,
954 int input_uV,
int output_uV,
962 mode = get_mode(output_uA, dcdc1_6_efficiency);
966 mode = get_mode(output_uA, dcdc3_4_efficiency);
983 .get_mode = wm8350_dcdc_get_mode,
984 .set_mode = wm8350_dcdc_set_mode,
985 .get_optimum_mode = wm8350_dcdc_get_optimum_mode,
986 .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage,
987 .set_suspend_enable = wm8350_dcdc_set_suspend_enable,
988 .set_suspend_disable = wm8350_dcdc_set_suspend_disable,
989 .set_suspend_mode = wm8350_dcdc_set_suspend_mode,
996 .set_suspend_enable = wm8350_dcdc25_set_suspend_enable,
997 .set_suspend_disable = wm8350_dcdc25_set_suspend_disable,
1001 .map_voltage = wm8350_ldo_map_voltage,
1004 .list_voltage = wm8350_ldo_list_voltage,
1008 .get_mode = wm8350_ldo_get_mode,
1009 .set_suspend_voltage = wm8350_ldo_set_suspend_voltage,
1010 .set_suspend_enable = wm8350_ldo_set_suspend_enable,
1011 .set_suspend_disable = wm8350_ldo_set_suspend_disable,
1015 .set_current_limit = wm8350_isink_set_current,
1016 .get_current_limit = wm8350_isink_get_current,
1017 .enable = wm8350_isink_enable,
1018 .disable = wm8350_isink_disable,
1019 .is_enabled = wm8350_isink_is_enabled,
1020 .enable_time = wm8350_isink_enable_time,
1027 .ops = &wm8350_dcdc_ops,
1042 .ops = &wm8350_dcdc2_5_ops,
1052 .ops = &wm8350_dcdc_ops,
1067 .ops = &wm8350_dcdc_ops,
1082 .ops = &wm8350_dcdc2_5_ops,
1092 .ops = &wm8350_dcdc_ops,
1107 .ops = &wm8350_ldo_ops,
1120 .ops = &wm8350_ldo_ops,
1133 .ops = &wm8350_ldo_ops,
1146 .ops = &wm8350_ldo_ops,
1159 .ops = &wm8350_isink_ops,
1167 .ops = &wm8350_isink_ops,
1232 dev_err(&pdev->
dev,
"failed to register %s\n",
1233 wm8350_reg[pdev->
id].
name);
1234 return PTR_ERR(rdev);
1238 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->
id].
irq,
1239 pmic_uv_handler, 0,
"UV", rdev);
1242 dev_err(&pdev->
dev,
"failed to register regulator %s IRQ\n",
1243 wm8350_reg[pdev->
id].
name);
1255 wm8350_free_irq(wm8350, wm8350_reg[pdev->
id].
irq, rdev);
1270 if (wm8350->
pmic.pdev[reg])
1274 reg > wm8350->
pmic.max_dcdc)
1277 reg > wm8350->
pmic.max_isink)
1284 wm8350->
pmic.pdev[
reg] = pdev;
1288 pdev->
dev.platform_data = initdata;
1289 pdev->
dev.parent = wm8350->
dev;
1290 platform_set_drvdata(pdev, wm8350);
1295 dev_err(wm8350->
dev,
"Failed to register regulator %d: %d\n",
1329 dev_err(wm8350->
dev,
"Invalid LED index %d\n", lednum);
1333 led = &wm8350->
pmic.led[lednum];
1336 dev_err(wm8350->
dev,
"LED %d already allocated\n", lednum);
1342 dev_err(wm8350->
dev,
"Failed to allocate LED %d\n", lednum);
1363 led->
dcdc_init.num_consumer_supplies = 1;
1375 wm8350->
pmic.isink_A_dcdc = dcdc;
1378 wm8350->
pmic.isink_B_dcdc = dcdc;
1383 pdev->
dev.parent = wm8350->
dev;
1386 dev_err(wm8350->
dev,
"Failed to register LED %d: %d\n",
1399 .probe = wm8350_regulator_probe,
1400 .remove = wm8350_regulator_remove,
1402 .name =
"wm8350-regulator",
1406 static int __init wm8350_regulator_init(
void)
1412 static void __exit wm8350_regulator_exit(
void)