15 #include <linux/kernel.h>
16 #include <linux/module.h>
22 #include <linux/slab.h>
36 static const struct regs_info palmas_regs_info[] = {
148 #define SMPS_CTRL_MODE_OFF 0x00
149 #define SMPS_CTRL_MODE_ON 0x01
150 #define SMPS_CTRL_MODE_ECO 0x02
151 #define SMPS_CTRL_MODE_PWM 0x03
159 #define PALMAS_SMPS_NUM_VOLTAGES 116
160 #define PALMAS_SMPS10_NUM_VOLTAGES 2
161 #define PALMAS_LDO_NUM_VOLTAGES 50
163 #define SMPS10_VSEL (1<<3)
164 #define SMPS10_BOOST_EN (1<<2)
165 #define SMPS10_BYPASS_EN (1<<1)
166 #define SMPS10_SWITCH_EN (1<<0)
168 #define REGULATOR_SLAVE 0
283 static unsigned int palmas_get_mode_smps(
struct regulator_dev *dev)
305 static int palmas_list_voltage_smps(
struct regulator_dev *dev,
324 return (490000 + (selector * 10000)) *
mult;
327 static int palmas_get_voltage_smps_sel(
struct regulator_dev *dev)
337 palmas_smps_read(pmic->
palmas, addr, ®);
342 if ((selector > 0) && (selector < 6))
353 static int palmas_set_voltage_smps_sel(
struct regulator_dev *dev,
358 unsigned int reg = 0;
371 palmas_smps_write(pmic->
palmas, addr, reg);
377 int min_uV,
int max_uV)
386 if (pmic->
range[
id]) {
387 if (min_uV < 1000000)
397 voltage = palmas_list_voltage_smps(rdev, ret);
398 if (voltage < min_uV || voltage > max_uV)
405 .is_enabled = palmas_is_enabled_smps,
406 .enable = palmas_enable_smps,
407 .disable = palmas_disable_smps,
408 .set_mode = palmas_set_mode_smps,
409 .get_mode = palmas_get_mode_smps,
410 .get_voltage_sel = palmas_get_voltage_smps_sel,
411 .set_voltage_sel = palmas_set_voltage_smps_sel,
412 .list_voltage = palmas_list_voltage_smps,
413 .map_voltage = palmas_map_voltage_smps,
439 static int palmas_list_voltage_ldo(
struct regulator_dev *dev,
446 return 850000 + (selector * 50000);
449 static int palmas_map_voltage_ldo(
struct regulator_dev *rdev,
450 int min_uV,
int max_uV)
462 voltage = palmas_list_voltage_ldo(rdev, ret);
463 if (voltage < min_uV || voltage > max_uV)
470 .is_enabled = palmas_is_enabled_ldo,
475 .list_voltage = palmas_list_voltage_ldo,
476 .map_voltage = palmas_map_voltage_ldo,
485 static int palmas_smps_init(
struct palmas *
palmas,
int id,
494 ret = palmas_smps_read(palmas, addr, ®);
520 ret = palmas_smps_write(palmas, addr, reg);
524 if (palmas_regs_info[
id].tstep_addr && reg_init->
tstep) {
529 ret = palmas_smps_write(palmas, addr, reg);
534 if (palmas_regs_info[
id].vsel_addr && reg_init->
vsel) {
537 reg = reg_init->
vsel;
539 ret = palmas_smps_write(palmas, addr, reg);
548 static int palmas_ldo_init(
struct palmas *palmas,
int id,
557 ret = palmas_ldo_read(palmas, addr, ®);
567 ret = palmas_ldo_write(palmas, addr, reg);
575 { .name =
"smps12", },
576 { .name =
"smps123", },
577 { .name =
"smps3", },
578 { .name =
"smps45", },
579 { .name =
"smps457", },
580 { .name =
"smps6", },
581 { .name =
"smps7", },
582 { .name =
"smps8", },
583 { .name =
"smps9", },
584 { .name =
"smps10", },
594 { .name =
"ldoln", },
595 { .name =
"ldousb", },
608 dev_info(dev,
"regulator node not found\n");
615 dev_err(dev,
"Error parsing regulator init data: %d\n", ret);
620 if (!palmas_matches[idx].init_data ||
621 !palmas_matches[idx].of_node)
629 ret = of_property_read_u32(palmas_matches[idx].of_node,
630 "ti,warm_reset", &prop);
634 ret = of_property_read_u32(palmas_matches[idx].of_node,
635 "ti,roof_floor", &prop);
639 ret = of_property_read_u32(palmas_matches[idx].of_node,
640 "ti,mode_sleep", &prop);
644 ret = of_property_read_u32(palmas_matches[idx].of_node,
645 "ti,warm_reset", &prop);
649 ret = of_property_read_u32(palmas_matches[idx].of_node,
654 ret = of_property_read_u32(palmas_matches[idx].of_node,
660 ret = of_property_read_u32(node,
"ti,ldo6_vibrator", &prop);
678 if (node && !pdata) {
684 palmas_dt_to_pdata(&pdev->
dev, node, pdata);
694 platform_set_drvdata(pdev, pmic);
743 pmic->
desc[
id].ops = &palmas_ops_smps10;
748 pmic->
desc[
id].enable_reg =
752 pmic->
desc[
id].min_uV = 3750000;
753 pmic->
desc[
id].uV_step = 1250000;
756 pmic->
desc[
id].ops = &palmas_ops_smps;
767 ret = palmas_smps_init(palmas,
id, reg_init);
769 goto err_unregister_regulator;
781 ret = palmas_smps_read(pmic->
palmas, addr, ®);
783 goto err_unregister_regulator;
798 "failed to register %s regulator\n",
801 goto err_unregister_regulator;
820 pmic->
desc[
id].ops = &palmas_ops_ldo;
825 palmas_regs_info[
id].vsel_addr);
828 palmas_regs_info[
id].ctrl_addr);
841 "failed to register %s regulator\n",
844 goto err_unregister_regulator;
854 ret = palmas_ldo_init(palmas,
id, reg_init);
857 goto err_unregister_regulator;
865 err_unregister_regulator:
873 struct palmas_pmic *pmic = platform_get_drvdata(pdev);
882 { .compatible =
"ti,palmas-pmic", },
888 .name =
"palmas-pmic",
889 .of_match_table = of_palmas_match_tbl,
892 .probe = palmas_probe,
896 static int __init palmas_init(
void)
902 static void __exit palmas_exit(
void)