16 #include <linux/kernel.h>
17 #include <linux/module.h>
23 #include <linux/slab.h>
28 #define TPS65910_SUPPLY_STATE_ENABLED 0x1
29 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
30 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
32 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
35 static const unsigned int VIO_VSEL_table[] = {
36 1500000, 1800000, 2500000, 3300000,
42 static const unsigned int VDD3_VSEL_table[] = {
47 static const unsigned int VDIG1_VSEL_table[] = {
48 1200000, 1500000, 1800000, 2700000,
52 static const unsigned int VDIG2_VSEL_table[] = {
53 1000000, 1100000, 1200000, 1800000,
57 static const unsigned int VPLL_VSEL_table[] = {
58 1000000, 1100000, 1800000, 2500000,
62 static const unsigned int VDAC_VSEL_table[] = {
63 1800000, 2600000, 2800000, 2850000,
67 static const unsigned int VAUX1_VSEL_table[] = {
68 1800000, 2500000, 2800000, 2850000,
72 static const unsigned int VAUX2_VSEL_table[] = {
73 1800000, 2800000, 2900000, 3300000,
77 static const unsigned int VAUX33_VSEL_table[] = {
78 1800000, 2000000, 2800000, 3300000,
82 static const unsigned int VMMC_VSEL_table[] = {
83 1800000, 2800000, 3000000, 3300000,
94 static struct tps_info tps65910_regs[] = {
98 .enable_time_us = 2200,
104 .voltage_table = VIO_VSEL_table,
105 .enable_time_us = 350,
110 .enable_time_us = 350,
115 .enable_time_us = 350,
120 .voltage_table = VDD3_VSEL_table,
121 .enable_time_us = 200,
127 .voltage_table = VDIG1_VSEL_table,
128 .enable_time_us = 100,
134 .voltage_table = VDIG2_VSEL_table,
135 .enable_time_us = 100,
141 .voltage_table = VPLL_VSEL_table,
142 .enable_time_us = 100,
148 .voltage_table = VDAC_VSEL_table,
149 .enable_time_us = 100,
155 .voltage_table = VAUX1_VSEL_table,
156 .enable_time_us = 100,
162 .voltage_table = VAUX2_VSEL_table,
163 .enable_time_us = 100,
169 .voltage_table = VAUX33_VSEL_table,
170 .enable_time_us = 100,
176 .voltage_table = VMMC_VSEL_table,
177 .enable_time_us = 100,
181 static struct tps_info tps65911_regs[] = {
185 .enable_time_us = 2200,
191 .voltage_table = VIO_VSEL_table,
192 .enable_time_us = 350,
198 .enable_time_us = 350,
204 .enable_time_us = 350,
209 .enable_time_us = 900,
215 .enable_time_us = 420,
221 .enable_time_us = 420,
227 .enable_time_us = 230,
233 .enable_time_us = 230,
239 .enable_time_us = 230,
245 .enable_time_us = 230,
251 .enable_time_us = 230,
257 .enable_time_us = 230,
261 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
262 static unsigned int tps65910_ext_sleep_control[] = {
278 static unsigned int tps65911_ext_sleep_control[] = {
306 static int tps65910_get_ctrl_register(
int id)
340 static int tps65911_get_ctrl_register(
int id)
386 return tps65910_reg_update_bits(pmic->
mfd, reg,
391 return tps65910_reg_set_bits(mfd, reg, value);
399 static unsigned int tps65910_get_mode(
struct regulator_dev *dev)
408 ret = tps65910_reg_read(pmic->
mfd, reg, &value);
420 static int tps65910_get_voltage_dcdc_sel(
struct regulator_dev *dev)
424 int opvsel = 0, srvsel = 0, vselmax = 0,
mult = 0,
sr = 0;
483 if (srvsel > vselmax)
491 if (opvsel > vselmax)
498 static int tps65910_get_voltage_sel(
struct regulator_dev *dev)
507 ret = tps65910_reg_read(pmic->
mfd, reg, &value);
531 static int tps65910_get_voltage_vdd3(
struct regulator_dev *dev)
533 return dev->
desc->volt_table[0];
536 static int tps65911_get_voltage_sel(
struct regulator_dev *dev)
544 ret = tps65910_reg_read(pmic->
mfd, reg, &value);
574 static int tps65910_set_voltage_dcdc_sel(
struct regulator_dev *dev,
612 static int tps65910_set_voltage_sel(
struct regulator_dev *dev,
639 static int tps65911_set_voltage_sel(
struct regulator_dev *dev,
671 static int tps65910_list_voltage_dcdc(
struct regulator_dev *dev,
691 return volt * 100 *
mult;
694 static int tps65911_list_voltage(
struct regulator_dev *dev,
unsigned selector)
725 return pmic->
info[
id]->voltage_table[selector];
738 .set_mode = tps65910_set_mode,
739 .get_mode = tps65910_get_mode,
740 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
741 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
743 .list_voltage = tps65910_list_voltage_dcdc,
750 .set_mode = tps65910_set_mode,
751 .get_mode = tps65910_get_mode,
752 .get_voltage = tps65910_get_voltage_vdd3,
760 .set_mode = tps65910_set_mode,
761 .get_mode = tps65910_get_mode,
762 .get_voltage_sel = tps65910_get_voltage_sel,
763 .set_voltage_sel = tps65910_set_voltage_sel,
771 .set_mode = tps65910_set_mode,
772 .get_mode = tps65910_get_mode,
773 .get_voltage_sel = tps65911_get_voltage_sel,
774 .set_voltage_sel = tps65911_set_voltage_sel,
775 .list_voltage = tps65911_list_voltage,
778 static int tps65910_set_ext_sleep_config(
struct tps65910_reg *pmic,
779 int id,
int ext_sleep_config)
792 en_count = ((ext_sleep_config &
794 en_count += ((ext_sleep_config &
796 en_count += ((ext_sleep_config &
798 en_count += ((ext_sleep_config &
802 "External sleep control flag is not proper\n");
811 ret = tps65910_reg_set_bits(mfd,
814 ret = tps65910_reg_clear_bits(mfd,
818 "Error in configuring external control EN1\n");
824 ret = tps65910_reg_set_bits(mfd,
827 ret = tps65910_reg_clear_bits(mfd,
831 "Error in configuring external control EN2\n");
836 if ((tps65910_chip_id(mfd) ==
TPS65910) &&
839 ret = tps65910_reg_set_bits(mfd,
842 ret = tps65910_reg_clear_bits(mfd,
846 "Error in configuring external control EN3\n");
852 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
854 ret = tps65910_reg_clear_bits(mfd,
857 ret = tps65910_reg_clear_bits(mfd,
861 "Error in configuring SLEEP register\n");
873 (tps65910_chip_id(mfd) ==
TPS65911))) {
878 ret = tps65910_reg_read(pmic->
mfd, op_reg_add, &opvsel);
881 ret = tps65910_reg_read(pmic->
mfd, sr_reg_add, &srvsel);
885 if (opvsel & VDD1_OP_CMD_MASK) {
888 ret = tps65910_reg_write(pmic->
mfd, op_reg_add,
892 "Error in configuring op register\n");
896 ret = tps65910_reg_write(pmic->
mfd, sr_reg_add, 0);
898 dev_err(mfd->
dev,
"Error in settting sr register\n");
903 ret = tps65910_reg_clear_bits(mfd,
907 ret = tps65910_reg_set_bits(mfd,
910 ret = tps65910_reg_clear_bits(mfd,
915 "Error in configuring SLEEP register\n");
923 { .
name =
"vrtc", .driver_data = (
void *) &tps65910_regs[0] },
924 { .
name =
"vio", .driver_data = (
void *) &tps65910_regs[1] },
925 { .
name =
"vdd1", .driver_data = (
void *) &tps65910_regs[2] },
926 { .
name =
"vdd2", .driver_data = (
void *) &tps65910_regs[3] },
927 { .
name =
"vdd3", .driver_data = (
void *) &tps65910_regs[4] },
928 { .
name =
"vdig1", .driver_data = (
void *) &tps65910_regs[5] },
929 { .
name =
"vdig2", .driver_data = (
void *) &tps65910_regs[6] },
930 { .
name =
"vpll", .driver_data = (
void *) &tps65910_regs[7] },
931 { .
name =
"vdac", .driver_data = (
void *) &tps65910_regs[8] },
932 { .
name =
"vaux1", .driver_data = (
void *) &tps65910_regs[9] },
933 { .
name =
"vaux2", .driver_data = (
void *) &tps65910_regs[10] },
934 { .
name =
"vaux33", .driver_data = (
void *) &tps65910_regs[11] },
935 { .
name =
"vmmc", .driver_data = (
void *) &tps65910_regs[12] },
939 { .
name =
"vrtc", .driver_data = (
void *) &tps65911_regs[0] },
940 { .
name =
"vio", .driver_data = (
void *) &tps65911_regs[1] },
941 { .
name =
"vdd1", .driver_data = (
void *) &tps65911_regs[2] },
942 { .
name =
"vdd2", .driver_data = (
void *) &tps65911_regs[3] },
943 { .
name =
"vddctrl", .driver_data = (
void *) &tps65911_regs[4] },
944 { .
name =
"ldo1", .driver_data = (
void *) &tps65911_regs[5] },
945 { .
name =
"ldo2", .driver_data = (
void *) &tps65911_regs[6] },
946 { .
name =
"ldo3", .driver_data = (
void *) &tps65911_regs[7] },
947 { .
name =
"ldo4", .driver_data = (
void *) &tps65911_regs[8] },
948 { .
name =
"ldo5", .driver_data = (
void *) &tps65911_regs[9] },
949 { .
name =
"ldo6", .driver_data = (
void *) &tps65911_regs[10] },
950 { .
name =
"ldo7", .driver_data = (
void *) &tps65911_regs[11] },
951 { .
name =
"ldo8", .driver_data = (
void *) &tps65911_regs[12] },
969 if (!pmic_plat_data) {
970 dev_err(&pdev->
dev,
"Failure to alloc pdata for regulators.\n");
976 dev_err(&pdev->
dev,
"regulator node not found\n");
980 switch (tps65910_chip_id(tps65910)) {
983 matches = tps65910_matches;
987 matches = tps65911_matches;
990 dev_err(&pdev->
dev,
"Invalid tps chip version\n");
996 dev_err(&pdev->
dev,
"Error parsing regulator init data: %d\n",
1001 *tps65910_reg_matches = matches;
1003 for (idx = 0; idx <
count; idx++) {
1010 ret = of_property_read_u32(matches[idx].of_node,
1011 "ti,regulator-ext-sleep-control", &prop);
1017 return pmic_plat_data;
1024 *tps65910_reg_matches =
NULL;
1041 pmic_plat_data = dev_get_platdata(tps65910->
dev);
1042 if (!pmic_plat_data && tps65910->
dev->of_node)
1043 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1044 &tps65910_reg_matches);
1046 if (!pmic_plat_data) {
1047 dev_err(&pdev->
dev,
"Platform data not found\n");
1053 dev_err(&pdev->
dev,
"Memory allocation failed for pmic\n");
1057 pmic->
mfd = tps65910;
1058 platform_set_drvdata(pdev, pmic);
1064 switch(tps65910_chip_id(tps65910)) {
1069 info = tps65910_regs;
1075 info = tps65911_regs;
1078 dev_err(&pdev->
dev,
"Invalid tps chip version\n");
1085 dev_err(&pdev->
dev,
"Memory alloc fails for desc\n");
1092 dev_err(&pdev->
dev,
"Memory alloc fails for info\n");
1099 dev_err(&pdev->
dev,
"Memory alloc fails for rdev\n");
1123 pmic->
desc[
i].ops = &tps65910_ops_dcdc;
1126 pmic->
desc[
i].ramp_delay = 12500;
1128 if (tps65910_chip_id(tps65910) ==
TPS65910) {
1129 pmic->
desc[
i].ops = &tps65910_ops_vdd3;
1132 pmic->
desc[
i].ops = &tps65910_ops_dcdc;
1133 pmic->
desc[
i].ramp_delay = 5000;
1136 if (tps65910_chip_id(tps65910) ==
TPS65910) {
1137 pmic->
desc[
i].ops = &tps65910_ops;
1140 pmic->
desc[
i].ops = &tps65911_ops;
1144 err = tps65910_set_ext_sleep_config(pmic, i,
1152 "Failed to initialise ext control config\n");
1159 config.
dev = tps65910->
dev;
1164 if (tps65910_reg_matches)
1170 "failed to register %s regulator\n",
1172 err = PTR_ERR(rdev);
1173 goto err_unregister_regulator;
1181 err_unregister_regulator:
1189 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1200 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1221 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1224 "Error in clearing external control\n");
1230 .name =
"tps65910-pmic",
1233 .probe = tps65910_probe,
1235 .shutdown = tps65910_shutdown,
1238 static int __init tps65910_init(
void)
1244 static void __exit tps65910_cleanup(
void)