diff options
author | Axel Lin <axel.lin@ingics.com> | 2017-11-29 09:02:46 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-01-24 12:31:01 -0500 |
commit | 9d4853322ffcc76a2eb62d720ec3903d427b39bc (patch) | |
tree | a2ae61204692f60b75110c816c3e02f6dacad541 | |
parent | 4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323 (diff) |
regulator: qcom_spmi: Use regmap helpers for enable/disable/is_enabled callback
Setup .enable_reg/.enable_mask/.enable_val fields, then we can use the
regmap helpers for enable/disable/is_enabled callback implementation.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/qcom_spmi-regulator.c | 84 |
1 files changed, 31 insertions, 53 deletions
diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index 0241ada47d04..63c7a0c17777 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c | |||
@@ -486,24 +486,6 @@ static int spmi_vreg_update_bits(struct spmi_regulator *vreg, u16 addr, u8 val, | |||
486 | return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val); | 486 | return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val); |
487 | } | 487 | } |
488 | 488 | ||
489 | static int spmi_regulator_common_is_enabled(struct regulator_dev *rdev) | ||
490 | { | ||
491 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | ||
492 | u8 reg; | ||
493 | |||
494 | spmi_vreg_read(vreg, SPMI_COMMON_REG_ENABLE, ®, 1); | ||
495 | |||
496 | return (reg & SPMI_COMMON_ENABLE_MASK) == SPMI_COMMON_ENABLE; | ||
497 | } | ||
498 | |||
499 | static int spmi_regulator_common_enable(struct regulator_dev *rdev) | ||
500 | { | ||
501 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | ||
502 | |||
503 | return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, | ||
504 | SPMI_COMMON_ENABLE, SPMI_COMMON_ENABLE_MASK); | ||
505 | } | ||
506 | |||
507 | static int spmi_regulator_vs_enable(struct regulator_dev *rdev) | 489 | static int spmi_regulator_vs_enable(struct regulator_dev *rdev) |
508 | { | 490 | { |
509 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | 491 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); |
@@ -513,7 +495,7 @@ static int spmi_regulator_vs_enable(struct regulator_dev *rdev) | |||
513 | vreg->vs_enable_time = ktime_get(); | 495 | vreg->vs_enable_time = ktime_get(); |
514 | } | 496 | } |
515 | 497 | ||
516 | return spmi_regulator_common_enable(rdev); | 498 | return regulator_enable_regmap(rdev); |
517 | } | 499 | } |
518 | 500 | ||
519 | static int spmi_regulator_vs_ocp(struct regulator_dev *rdev) | 501 | static int spmi_regulator_vs_ocp(struct regulator_dev *rdev) |
@@ -524,14 +506,6 @@ static int spmi_regulator_vs_ocp(struct regulator_dev *rdev) | |||
524 | return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, ®, 1); | 506 | return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, ®, 1); |
525 | } | 507 | } |
526 | 508 | ||
527 | static int spmi_regulator_common_disable(struct regulator_dev *rdev) | ||
528 | { | ||
529 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | ||
530 | |||
531 | return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, | ||
532 | SPMI_COMMON_DISABLE, SPMI_COMMON_ENABLE_MASK); | ||
533 | } | ||
534 | |||
535 | static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, | 509 | static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, |
536 | int min_uV, int max_uV) | 510 | int min_uV, int max_uV) |
537 | { | 511 | { |
@@ -1062,9 +1036,9 @@ static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data) | |||
1062 | } | 1036 | } |
1063 | 1037 | ||
1064 | static struct regulator_ops spmi_smps_ops = { | 1038 | static struct regulator_ops spmi_smps_ops = { |
1065 | .enable = spmi_regulator_common_enable, | 1039 | .enable = regulator_enable_regmap, |
1066 | .disable = spmi_regulator_common_disable, | 1040 | .disable = regulator_disable_regmap, |
1067 | .is_enabled = spmi_regulator_common_is_enabled, | 1041 | .is_enabled = regulator_is_enabled_regmap, |
1068 | .set_voltage_sel = spmi_regulator_common_set_voltage, | 1042 | .set_voltage_sel = spmi_regulator_common_set_voltage, |
1069 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, | 1043 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, |
1070 | .get_voltage_sel = spmi_regulator_common_get_voltage, | 1044 | .get_voltage_sel = spmi_regulator_common_get_voltage, |
@@ -1077,9 +1051,9 @@ static struct regulator_ops spmi_smps_ops = { | |||
1077 | }; | 1051 | }; |
1078 | 1052 | ||
1079 | static struct regulator_ops spmi_ldo_ops = { | 1053 | static struct regulator_ops spmi_ldo_ops = { |
1080 | .enable = spmi_regulator_common_enable, | 1054 | .enable = regulator_enable_regmap, |
1081 | .disable = spmi_regulator_common_disable, | 1055 | .disable = regulator_disable_regmap, |
1082 | .is_enabled = spmi_regulator_common_is_enabled, | 1056 | .is_enabled = regulator_is_enabled_regmap, |
1083 | .set_voltage_sel = spmi_regulator_common_set_voltage, | 1057 | .set_voltage_sel = spmi_regulator_common_set_voltage, |
1084 | .get_voltage_sel = spmi_regulator_common_get_voltage, | 1058 | .get_voltage_sel = spmi_regulator_common_get_voltage, |
1085 | .map_voltage = spmi_regulator_common_map_voltage, | 1059 | .map_voltage = spmi_regulator_common_map_voltage, |
@@ -1094,9 +1068,9 @@ static struct regulator_ops spmi_ldo_ops = { | |||
1094 | }; | 1068 | }; |
1095 | 1069 | ||
1096 | static struct regulator_ops spmi_ln_ldo_ops = { | 1070 | static struct regulator_ops spmi_ln_ldo_ops = { |
1097 | .enable = spmi_regulator_common_enable, | 1071 | .enable = regulator_enable_regmap, |
1098 | .disable = spmi_regulator_common_disable, | 1072 | .disable = regulator_disable_regmap, |
1099 | .is_enabled = spmi_regulator_common_is_enabled, | 1073 | .is_enabled = regulator_is_enabled_regmap, |
1100 | .set_voltage_sel = spmi_regulator_common_set_voltage, | 1074 | .set_voltage_sel = spmi_regulator_common_set_voltage, |
1101 | .get_voltage_sel = spmi_regulator_common_get_voltage, | 1075 | .get_voltage_sel = spmi_regulator_common_get_voltage, |
1102 | .map_voltage = spmi_regulator_common_map_voltage, | 1076 | .map_voltage = spmi_regulator_common_map_voltage, |
@@ -1107,8 +1081,8 @@ static struct regulator_ops spmi_ln_ldo_ops = { | |||
1107 | 1081 | ||
1108 | static struct regulator_ops spmi_vs_ops = { | 1082 | static struct regulator_ops spmi_vs_ops = { |
1109 | .enable = spmi_regulator_vs_enable, | 1083 | .enable = spmi_regulator_vs_enable, |
1110 | .disable = spmi_regulator_common_disable, | 1084 | .disable = regulator_disable_regmap, |
1111 | .is_enabled = spmi_regulator_common_is_enabled, | 1085 | .is_enabled = regulator_is_enabled_regmap, |
1112 | .set_pull_down = spmi_regulator_common_set_pull_down, | 1086 | .set_pull_down = spmi_regulator_common_set_pull_down, |
1113 | .set_soft_start = spmi_regulator_common_set_soft_start, | 1087 | .set_soft_start = spmi_regulator_common_set_soft_start, |
1114 | .set_over_current_protection = spmi_regulator_vs_ocp, | 1088 | .set_over_current_protection = spmi_regulator_vs_ocp, |
@@ -1117,9 +1091,9 @@ static struct regulator_ops spmi_vs_ops = { | |||
1117 | }; | 1091 | }; |
1118 | 1092 | ||
1119 | static struct regulator_ops spmi_boost_ops = { | 1093 | static struct regulator_ops spmi_boost_ops = { |
1120 | .enable = spmi_regulator_common_enable, | 1094 | .enable = regulator_enable_regmap, |
1121 | .disable = spmi_regulator_common_disable, | 1095 | .disable = regulator_disable_regmap, |
1122 | .is_enabled = spmi_regulator_common_is_enabled, | 1096 | .is_enabled = regulator_is_enabled_regmap, |
1123 | .set_voltage_sel = spmi_regulator_single_range_set_voltage, | 1097 | .set_voltage_sel = spmi_regulator_single_range_set_voltage, |
1124 | .get_voltage_sel = spmi_regulator_single_range_get_voltage, | 1098 | .get_voltage_sel = spmi_regulator_single_range_get_voltage, |
1125 | .map_voltage = spmi_regulator_single_map_voltage, | 1099 | .map_voltage = spmi_regulator_single_map_voltage, |
@@ -1128,9 +1102,9 @@ static struct regulator_ops spmi_boost_ops = { | |||
1128 | }; | 1102 | }; |
1129 | 1103 | ||
1130 | static struct regulator_ops spmi_ftsmps_ops = { | 1104 | static struct regulator_ops spmi_ftsmps_ops = { |
1131 | .enable = spmi_regulator_common_enable, | 1105 | .enable = regulator_enable_regmap, |
1132 | .disable = spmi_regulator_common_disable, | 1106 | .disable = regulator_disable_regmap, |
1133 | .is_enabled = spmi_regulator_common_is_enabled, | 1107 | .is_enabled = regulator_is_enabled_regmap, |
1134 | .set_voltage_sel = spmi_regulator_common_set_voltage, | 1108 | .set_voltage_sel = spmi_regulator_common_set_voltage, |
1135 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, | 1109 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, |
1136 | .get_voltage_sel = spmi_regulator_common_get_voltage, | 1110 | .get_voltage_sel = spmi_regulator_common_get_voltage, |
@@ -1143,9 +1117,9 @@ static struct regulator_ops spmi_ftsmps_ops = { | |||
1143 | }; | 1117 | }; |
1144 | 1118 | ||
1145 | static struct regulator_ops spmi_ult_lo_smps_ops = { | 1119 | static struct regulator_ops spmi_ult_lo_smps_ops = { |
1146 | .enable = spmi_regulator_common_enable, | 1120 | .enable = regulator_enable_regmap, |
1147 | .disable = spmi_regulator_common_disable, | 1121 | .disable = regulator_disable_regmap, |
1148 | .is_enabled = spmi_regulator_common_is_enabled, | 1122 | .is_enabled = regulator_is_enabled_regmap, |
1149 | .set_voltage_sel = spmi_regulator_ult_lo_smps_set_voltage, | 1123 | .set_voltage_sel = spmi_regulator_ult_lo_smps_set_voltage, |
1150 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, | 1124 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, |
1151 | .get_voltage_sel = spmi_regulator_ult_lo_smps_get_voltage, | 1125 | .get_voltage_sel = spmi_regulator_ult_lo_smps_get_voltage, |
@@ -1157,9 +1131,9 @@ static struct regulator_ops spmi_ult_lo_smps_ops = { | |||
1157 | }; | 1131 | }; |
1158 | 1132 | ||
1159 | static struct regulator_ops spmi_ult_ho_smps_ops = { | 1133 | static struct regulator_ops spmi_ult_ho_smps_ops = { |
1160 | .enable = spmi_regulator_common_enable, | 1134 | .enable = regulator_enable_regmap, |
1161 | .disable = spmi_regulator_common_disable, | 1135 | .disable = regulator_disable_regmap, |
1162 | .is_enabled = spmi_regulator_common_is_enabled, | 1136 | .is_enabled = regulator_is_enabled_regmap, |
1163 | .set_voltage_sel = spmi_regulator_single_range_set_voltage, | 1137 | .set_voltage_sel = spmi_regulator_single_range_set_voltage, |
1164 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, | 1138 | .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, |
1165 | .get_voltage_sel = spmi_regulator_single_range_get_voltage, | 1139 | .get_voltage_sel = spmi_regulator_single_range_get_voltage, |
@@ -1172,9 +1146,9 @@ static struct regulator_ops spmi_ult_ho_smps_ops = { | |||
1172 | }; | 1146 | }; |
1173 | 1147 | ||
1174 | static struct regulator_ops spmi_ult_ldo_ops = { | 1148 | static struct regulator_ops spmi_ult_ldo_ops = { |
1175 | .enable = spmi_regulator_common_enable, | 1149 | .enable = regulator_enable_regmap, |
1176 | .disable = spmi_regulator_common_disable, | 1150 | .disable = regulator_disable_regmap, |
1177 | .is_enabled = spmi_regulator_common_is_enabled, | 1151 | .is_enabled = regulator_is_enabled_regmap, |
1178 | .set_voltage_sel = spmi_regulator_single_range_set_voltage, | 1152 | .set_voltage_sel = spmi_regulator_single_range_set_voltage, |
1179 | .get_voltage_sel = spmi_regulator_single_range_get_voltage, | 1153 | .get_voltage_sel = spmi_regulator_single_range_get_voltage, |
1180 | .map_voltage = spmi_regulator_single_map_voltage, | 1154 | .map_voltage = spmi_regulator_single_map_voltage, |
@@ -1711,6 +1685,9 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) | |||
1711 | vreg->desc.id = -1; | 1685 | vreg->desc.id = -1; |
1712 | vreg->desc.owner = THIS_MODULE; | 1686 | vreg->desc.owner = THIS_MODULE; |
1713 | vreg->desc.type = REGULATOR_VOLTAGE; | 1687 | vreg->desc.type = REGULATOR_VOLTAGE; |
1688 | vreg->desc.enable_reg = reg->base + SPMI_COMMON_REG_ENABLE; | ||
1689 | vreg->desc.enable_mask = SPMI_COMMON_ENABLE_MASK; | ||
1690 | vreg->desc.enable_val = SPMI_COMMON_ENABLE; | ||
1714 | vreg->desc.name = name = reg->name; | 1691 | vreg->desc.name = name = reg->name; |
1715 | vreg->desc.supply_name = reg->supply; | 1692 | vreg->desc.supply_name = reg->supply; |
1716 | vreg->desc.of_match = reg->name; | 1693 | vreg->desc.of_match = reg->name; |
@@ -1723,6 +1700,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) | |||
1723 | 1700 | ||
1724 | config.dev = dev; | 1701 | config.dev = dev; |
1725 | config.driver_data = vreg; | 1702 | config.driver_data = vreg; |
1703 | config.regmap = regmap; | ||
1726 | rdev = devm_regulator_register(dev, &vreg->desc, &config); | 1704 | rdev = devm_regulator_register(dev, &vreg->desc, &config); |
1727 | if (IS_ERR(rdev)) { | 1705 | if (IS_ERR(rdev)) { |
1728 | dev_err(dev, "failed to register %s\n", name); | 1706 | dev_err(dev, "failed to register %s\n", name); |