wm8400-regulator.c (9938b04472d5c59f8bd8152a548533a8599596a2) wm8400-regulator.c (e08abeca39673e1045ca1e5a90bd7fef69d0fe8f)
1/*
2 * Regulator support for WM8400
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or

--- 22 unchanged lines hidden (view full) ---

31 .list_voltage = regulator_list_voltage_linear_range,
32 .get_voltage_sel = regulator_get_voltage_sel_regmap,
33 .set_voltage_sel = regulator_set_voltage_sel_regmap,
34 .map_voltage = regulator_map_voltage_linear_range,
35};
36
37static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
38{
1/*
2 * Regulator support for WM8400
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or

--- 22 unchanged lines hidden (view full) ---

31 .list_voltage = regulator_list_voltage_linear_range,
32 .get_voltage_sel = regulator_get_voltage_sel_regmap,
33 .set_voltage_sel = regulator_set_voltage_sel_regmap,
34 .map_voltage = regulator_map_voltage_linear_range,
35};
36
37static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
38{
39 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
39 struct regmap *rmap = rdev_get_regmap(dev);
40 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
41 u16 data[2];
42 int ret;
43
40 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
41 u16 data[2];
42 int ret;
43
44 ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2,
45 data);
44 ret = regmap_bulk_read(rmap, WM8400_DCDC1_CONTROL_1 + offset, data, 2);
46 if (ret != 0)
47 return 0;
48
49 /* Datasheet: hibernate */
50 if (data[0] & WM8400_DC1_SLEEP)
51 return REGULATOR_MODE_STANDBY;
52
53 /* Datasheet: standby */

--- 4 unchanged lines hidden (view full) ---

58 if (data[1] & WM8400_DC1_FRC_PWM)
59 return REGULATOR_MODE_FAST;
60 else
61 return REGULATOR_MODE_NORMAL;
62}
63
64static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
65{
45 if (ret != 0)
46 return 0;
47
48 /* Datasheet: hibernate */
49 if (data[0] & WM8400_DC1_SLEEP)
50 return REGULATOR_MODE_STANDBY;
51
52 /* Datasheet: standby */

--- 4 unchanged lines hidden (view full) ---

57 if (data[1] & WM8400_DC1_FRC_PWM)
58 return REGULATOR_MODE_FAST;
59 else
60 return REGULATOR_MODE_NORMAL;
61}
62
63static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
64{
66 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
65 struct regmap *rmap = rdev_get_regmap(dev);
67 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
68 int ret;
69
70 switch (mode) {
71 case REGULATOR_MODE_FAST:
72 /* Datasheet: active with force PWM */
66 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
67 int ret;
68
69 switch (mode) {
70 case REGULATOR_MODE_FAST:
71 /* Datasheet: active with force PWM */
73 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
72 ret = regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_2 + offset,
74 WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);
75 if (ret != 0)
76 return ret;
77
73 WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);
74 if (ret != 0)
75 return ret;
76
78 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
77 return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset,
79 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
80 WM8400_DC1_ACTIVE);
81
82 case REGULATOR_MODE_NORMAL:
83 /* Datasheet: active */
78 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
79 WM8400_DC1_ACTIVE);
80
81 case REGULATOR_MODE_NORMAL:
82 /* Datasheet: active */
84 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
83 ret = regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_2 + offset,
85 WM8400_DC1_FRC_PWM, 0);
86 if (ret != 0)
87 return ret;
88
84 WM8400_DC1_FRC_PWM, 0);
85 if (ret != 0)
86 return ret;
87
89 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
88 return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset,
90 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
91 WM8400_DC1_ACTIVE);
92
93 case REGULATOR_MODE_IDLE:
94 /* Datasheet: standby */
89 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
90 WM8400_DC1_ACTIVE);
91
92 case REGULATOR_MODE_IDLE:
93 /* Datasheet: standby */
95 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
94 return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset,
96 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0);
97 default:
98 return -EINVAL;
99 }
100}
101
102static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev,
103 int input_uV, int output_uV,

--- 179 unchanged lines hidden ---
95 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0);
96 default:
97 return -EINVAL;
98 }
99}
100
101static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev,
102 int input_uV, int output_uV,

--- 179 unchanged lines hidden ---