aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/s5m8767.c78
1 files changed, 19 insertions, 59 deletions
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index 6884eb880dc9..b6ddb03ee762 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -167,12 +167,11 @@ static unsigned int s5m8767_opmode_reg[][4] = {
167 {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */ 167 {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */
168}; 168};
169 169
170static int s5m8767_get_register(struct regulator_dev *rdev, int *reg, 170static int s5m8767_get_register(struct s5m8767_info *s5m8767, int reg_id,
171 int *enable_ctrl) 171 int *reg, int *enable_ctrl)
172{ 172{
173 int i, reg_id = rdev_get_id(rdev); 173 int i;
174 unsigned int mode; 174 unsigned int mode;
175 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
176 175
177 switch (reg_id) { 176 switch (reg_id) {
178 case S5M8767_LDO1 ... S5M8767_LDO2: 177 case S5M8767_LDO1 ... S5M8767_LDO2:
@@ -211,53 +210,6 @@ static int s5m8767_get_register(struct regulator_dev *rdev, int *reg,
211 return 0; 210 return 0;
212} 211}
213 212
214static int s5m8767_reg_is_enabled(struct regulator_dev *rdev)
215{
216 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
217 int ret, reg;
218 int enable_ctrl;
219 unsigned int val;
220
221 ret = s5m8767_get_register(rdev, &reg, &enable_ctrl);
222 if (ret == -EINVAL)
223 return 1;
224 else if (ret)
225 return ret;
226
227 ret = regmap_read(s5m8767->iodev->regmap_pmic, reg, &val);
228 if (ret)
229 return ret;
230
231 return (val & S5M8767_ENCTRL_MASK) == enable_ctrl;
232}
233
234static int s5m8767_reg_enable(struct regulator_dev *rdev)
235{
236 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
237 int ret, reg;
238 int enable_ctrl;
239
240 ret = s5m8767_get_register(rdev, &reg, &enable_ctrl);
241 if (ret)
242 return ret;
243
244 return regmap_update_bits(s5m8767->iodev->regmap_pmic, reg,
245 S5M8767_ENCTRL_MASK, enable_ctrl);
246}
247
248static int s5m8767_reg_disable(struct regulator_dev *rdev)
249{
250 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
251 int ret, reg, enable_ctrl;
252
253 ret = s5m8767_get_register(rdev, &reg, &enable_ctrl);
254 if (ret)
255 return ret;
256
257 return regmap_update_bits(s5m8767->iodev->regmap_pmic, reg,
258 S5M8767_ENCTRL_MASK, ~S5M8767_ENCTRL_MASK);
259}
260
261static int s5m8767_get_vsel_reg(int reg_id, struct s5m8767_info *s5m8767) 213static int s5m8767_get_vsel_reg(int reg_id, struct s5m8767_info *s5m8767)
262{ 214{
263 int reg; 215 int reg;
@@ -407,9 +359,9 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
407 359
408static struct regulator_ops s5m8767_ops = { 360static struct regulator_ops s5m8767_ops = {
409 .list_voltage = regulator_list_voltage_linear, 361 .list_voltage = regulator_list_voltage_linear,
410 .is_enabled = s5m8767_reg_is_enabled, 362 .is_enabled = regulator_is_enabled_regmap,
411 .enable = s5m8767_reg_enable, 363 .enable = regulator_enable_regmap,
412 .disable = s5m8767_reg_disable, 364 .disable = regulator_disable_regmap,
413 .get_voltage_sel = regulator_get_voltage_sel_regmap, 365 .get_voltage_sel = regulator_get_voltage_sel_regmap,
414 .set_voltage_sel = s5m8767_set_voltage_sel, 366 .set_voltage_sel = s5m8767_set_voltage_sel,
415 .set_voltage_time_sel = s5m8767_set_voltage_time_sel, 367 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
@@ -417,9 +369,9 @@ static struct regulator_ops s5m8767_ops = {
417 369
418static struct regulator_ops s5m8767_buck78_ops = { 370static struct regulator_ops s5m8767_buck78_ops = {
419 .list_voltage = regulator_list_voltage_linear, 371 .list_voltage = regulator_list_voltage_linear,
420 .is_enabled = s5m8767_reg_is_enabled, 372 .is_enabled = regulator_is_enabled_regmap,
421 .enable = s5m8767_reg_enable, 373 .enable = regulator_enable_regmap,
422 .disable = s5m8767_reg_disable, 374 .disable = regulator_disable_regmap,
423 .get_voltage_sel = regulator_get_voltage_sel_regmap, 375 .get_voltage_sel = regulator_get_voltage_sel_regmap,
424 .set_voltage_sel = regulator_set_voltage_sel_regmap, 376 .set_voltage_sel = regulator_set_voltage_sel_regmap,
425}; 377};
@@ -524,12 +476,13 @@ static void s5m8767_regulator_config_ext_control(struct s5m8767_info *s5m8767,
524static int s5m8767_enable_ext_control(struct s5m8767_info *s5m8767, 476static int s5m8767_enable_ext_control(struct s5m8767_info *s5m8767,
525 struct regulator_dev *rdev) 477 struct regulator_dev *rdev)
526{ 478{
479 int id = rdev_get_id(rdev);
527 int ret, reg, enable_ctrl; 480 int ret, reg, enable_ctrl;
528 481
529 if (rdev_get_id(rdev) != S5M8767_BUCK9) 482 if (id != S5M8767_BUCK9)
530 return -EINVAL; 483 return -EINVAL;
531 484
532 ret = s5m8767_get_register(rdev, &reg, &enable_ctrl); 485 ret = s5m8767_get_register(s5m8767, id, &reg, &enable_ctrl);
533 if (ret) 486 if (ret)
534 return ret; 487 return ret;
535 488
@@ -982,6 +935,7 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
982 for (i = 0; i < pdata->num_regulators; i++) { 935 for (i = 0; i < pdata->num_regulators; i++) {
983 const struct sec_voltage_desc *desc; 936 const struct sec_voltage_desc *desc;
984 int id = pdata->regulators[i].id; 937 int id = pdata->regulators[i].id;
938 int enable_reg, enable_val;
985 939
986 desc = reg_voltage_map[id]; 940 desc = reg_voltage_map[id];
987 if (desc) { 941 if (desc) {
@@ -995,6 +949,12 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
995 regulators[id].vsel_mask = 0x3f; 949 regulators[id].vsel_mask = 0x3f;
996 else 950 else
997 regulators[id].vsel_mask = 0xff; 951 regulators[id].vsel_mask = 0xff;
952
953 s5m8767_get_register(s5m8767, id, &enable_reg,
954 &enable_val);
955 regulators[id].enable_reg = enable_reg;
956 regulators[id].enable_mask = S5M8767_ENCTRL_MASK;
957 regulators[id].enable_val = enable_val;
998 } 958 }
999 959
1000 config.dev = s5m8767->dev; 960 config.dev = s5m8767->dev;