diff options
author | Yadwinder Singh Brar <yadi.brar@samsung.com> | 2013-06-29 08:51:16 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-07-15 13:31:12 -0400 |
commit | 939c02777a27ea7915764ecca5263dbb60c664f3 (patch) | |
tree | 4df08e2c4e78e0f2afc3d08c6498fffb39751984 /drivers/regulator/s2mps11.c | |
parent | 92d8ecae7eda0820663933e568915dbf7ef79127 (diff) |
regulator: s2mps11: Implement set_ramp_rate callback for bucks
Implementing set_ramp_rate() and using standard constraints for getting
ramp_delay and ramp_disable, instead of getting it as s2mps11 specific data
through platform data, makes driver more compliant with framework and reduces
the complexity for adding DT support.
Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/regulator/s2mps11.c')
-rw-r--r-- | drivers/regulator/s2mps11.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c index a671eb63a4e5..4b84e7660637 100644 --- a/drivers/regulator/s2mps11.c +++ b/drivers/regulator/s2mps11.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/regmap.h> | ||
19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
20 | #include <linux/regulator/driver.h> | 21 | #include <linux/regulator/driver.h> |
21 | #include <linux/regulator/machine.h> | 22 | #include <linux/regulator/machine.h> |
@@ -104,6 +105,121 @@ static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev, | |||
104 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); | 105 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); |
105 | } | 106 | } |
106 | 107 | ||
108 | static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) | ||
109 | { | ||
110 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); | ||
111 | unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK; | ||
112 | unsigned int ramp_enable = 1, enable_shift = 0; | ||
113 | int ret; | ||
114 | |||
115 | switch (rdev->desc->id) { | ||
116 | case S2MPS11_BUCK1: | ||
117 | if (ramp_delay > s2mps11->ramp_delay16) | ||
118 | s2mps11->ramp_delay16 = ramp_delay; | ||
119 | else | ||
120 | ramp_delay = s2mps11->ramp_delay16; | ||
121 | |||
122 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; | ||
123 | break; | ||
124 | case S2MPS11_BUCK2: | ||
125 | enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT; | ||
126 | if (!ramp_delay) { | ||
127 | ramp_enable = 0; | ||
128 | break; | ||
129 | } | ||
130 | |||
131 | s2mps11->ramp_delay2 = ramp_delay; | ||
132 | ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT; | ||
133 | ramp_reg = S2MPS11_REG_RAMP; | ||
134 | break; | ||
135 | case S2MPS11_BUCK3: | ||
136 | enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT; | ||
137 | if (!ramp_delay) { | ||
138 | ramp_enable = 0; | ||
139 | break; | ||
140 | } | ||
141 | |||
142 | if (ramp_delay > s2mps11->ramp_delay34) | ||
143 | s2mps11->ramp_delay34 = ramp_delay; | ||
144 | else | ||
145 | ramp_delay = s2mps11->ramp_delay34; | ||
146 | |||
147 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; | ||
148 | ramp_reg = S2MPS11_REG_RAMP; | ||
149 | break; | ||
150 | case S2MPS11_BUCK4: | ||
151 | enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT; | ||
152 | if (!ramp_delay) { | ||
153 | ramp_enable = 0; | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | if (ramp_delay > s2mps11->ramp_delay34) | ||
158 | s2mps11->ramp_delay34 = ramp_delay; | ||
159 | else | ||
160 | ramp_delay = s2mps11->ramp_delay34; | ||
161 | |||
162 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; | ||
163 | ramp_reg = S2MPS11_REG_RAMP; | ||
164 | break; | ||
165 | case S2MPS11_BUCK5: | ||
166 | s2mps11->ramp_delay5 = ramp_delay; | ||
167 | ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT; | ||
168 | break; | ||
169 | case S2MPS11_BUCK6: | ||
170 | enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT; | ||
171 | if (!ramp_delay) { | ||
172 | ramp_enable = 0; | ||
173 | break; | ||
174 | } | ||
175 | |||
176 | if (ramp_delay > s2mps11->ramp_delay16) | ||
177 | s2mps11->ramp_delay16 = ramp_delay; | ||
178 | else | ||
179 | ramp_delay = s2mps11->ramp_delay16; | ||
180 | |||
181 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; | ||
182 | break; | ||
183 | case S2MPS11_BUCK7: | ||
184 | case S2MPS11_BUCK8: | ||
185 | case S2MPS11_BUCK10: | ||
186 | if (ramp_delay > s2mps11->ramp_delay7810) | ||
187 | s2mps11->ramp_delay7810 = ramp_delay; | ||
188 | else | ||
189 | ramp_delay = s2mps11->ramp_delay7810; | ||
190 | |||
191 | ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT; | ||
192 | break; | ||
193 | case S2MPS11_BUCK9: | ||
194 | s2mps11->ramp_delay9 = ramp_delay; | ||
195 | ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT; | ||
196 | break; | ||
197 | default: | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | if (!ramp_enable) | ||
202 | goto ramp_disable; | ||
203 | |||
204 | if (enable_shift) { | ||
205 | ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, | ||
206 | 1 << enable_shift, 1 << enable_shift); | ||
207 | if (ret) { | ||
208 | dev_err(&rdev->dev, "failed to enable ramp rate\n"); | ||
209 | return ret; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | ramp_val = get_ramp_delay(ramp_delay); | ||
214 | |||
215 | return regmap_update_bits(rdev->regmap, ramp_reg, | ||
216 | ramp_val << ramp_shift, 1 << ramp_shift); | ||
217 | |||
218 | ramp_disable: | ||
219 | return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, 0, | ||
220 | 1 << enable_shift); | ||
221 | } | ||
222 | |||
107 | static struct regulator_ops s2mps11_ldo_ops = { | 223 | static struct regulator_ops s2mps11_ldo_ops = { |
108 | .list_voltage = regulator_list_voltage_linear, | 224 | .list_voltage = regulator_list_voltage_linear, |
109 | .map_voltage = regulator_map_voltage_linear, | 225 | .map_voltage = regulator_map_voltage_linear, |
@@ -124,6 +240,7 @@ static struct regulator_ops s2mps11_buck_ops = { | |||
124 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 240 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
125 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 241 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
126 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, | 242 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, |
243 | .set_ramp_delay = s2mps11_set_ramp_delay, | ||
127 | }; | 244 | }; |
128 | 245 | ||
129 | #define regulator_desc_ldo1(num) { \ | 246 | #define regulator_desc_ldo1(num) { \ |