aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-06-12 23:27:11 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-13 13:57:56 -0400
commitb4bc9ef6253578ecc71eec79a7dd423d0a282a4b (patch)
treea26368efc8089f05e847c75e371a04a3c0e4158f
parent74e20e569158063970624e360c8395ac5cffd654 (diff)
regulator: tps65217: Convert to regulator_[is_enabled|get_voltage_sel]_regmap
This patch converts .is_enabled and .get_voltage_sel to regulator_is_enabled_regmap and regulator_get_voltage_sel_regmap. For .enable, .disable, and .set_voltage_sel, the write protect level is either 1 or 2. So we cannot use regulator_[enable|disable|set_voltage_sel]_regmap. Now we store the enable reg/mask and vsel reg/mask in regulator_desc, so we can remove enable_mask, set_vout_reg, and set_vout_mask from struct tps_info. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/regulator/tps65217-regulator.c114
-rw-r--r--include/linux/mfd/tps65217.h6
2 files changed, 42 insertions, 78 deletions
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 9d371d2cbcae..f5fa05b5bea4 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -26,7 +26,7 @@
26#include <linux/regulator/machine.h> 26#include <linux/regulator/machine.h>
27#include <linux/mfd/tps65217.h> 27#include <linux/mfd/tps65217.h>
28 28
29#define TPS65217_REGULATOR(_name, _id, _ops, _n) \ 29#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em) \
30 { \ 30 { \
31 .name = _name, \ 31 .name = _name, \
32 .id = _id, \ 32 .id = _id, \
@@ -34,9 +34,13 @@
34 .n_voltages = _n, \ 34 .n_voltages = _n, \
35 .type = REGULATOR_VOLTAGE, \ 35 .type = REGULATOR_VOLTAGE, \
36 .owner = THIS_MODULE, \ 36 .owner = THIS_MODULE, \
37 .vsel_reg = _vr, \
38 .vsel_mask = _vm, \
39 .enable_reg = TPS65217_REG_ENABLE, \
40 .enable_mask = _em, \
37 } \ 41 } \
38 42
39#define TPS65217_INFO(_nm, _min, _max, _f1, _f2, _t, _n, _em, _vr, _vm) \ 43#define TPS65217_INFO(_nm, _min, _max, _f1, _f2, _t, _n)\
40 { \ 44 { \
41 .name = _nm, \ 45 .name = _nm, \
42 .min_uV = _min, \ 46 .min_uV = _min, \
@@ -45,9 +49,6 @@
45 .uv_to_vsel = _f2, \ 49 .uv_to_vsel = _f2, \
46 .table = _t, \ 50 .table = _t, \
47 .table_len = _n, \ 51 .table_len = _n, \
48 .enable_mask = _em, \
49 .set_vout_reg = _vr, \
50 .set_vout_mask = _vm, \
51 } 52 }
52 53
53static const int LDO1_VSEL_table[] = { 54static const int LDO1_VSEL_table[] = {
@@ -127,46 +128,21 @@ static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel)
127 128
128static struct tps_info tps65217_pmic_regs[] = { 129static struct tps_info tps65217_pmic_regs[] = {
129 TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, 130 TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1,
130 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC1_EN, 131 tps65217_uv_to_vsel1, NULL, 64),
131 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK),
132 TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, 132 TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1,
133 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC2_EN, 133 tps65217_uv_to_vsel1, NULL, 64),
134 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK),
135 TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, 134 TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1,
136 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC3_EN, 135 tps65217_uv_to_vsel1, NULL, 64),
137 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK),
138 TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL, LDO1_VSEL_table, 136 TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL, LDO1_VSEL_table,
139 16, TPS65217_ENABLE_LDO1_EN, TPS65217_REG_DEFLDO1, 137 16),
140 TPS65217_DEFLDO1_LDO1_MASK),
141 TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1, 138 TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1,
142 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_LDO2_EN, 139 tps65217_uv_to_vsel1, NULL, 64),
143 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK),
144 TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2, 140 TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2,
145 tps65217_uv_to_vsel2, NULL, 32, 141 tps65217_uv_to_vsel2, NULL, 32),
146 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN,
147 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK),
148 TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2, 142 TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2,
149 tps65217_uv_to_vsel2, NULL, 32, 143 tps65217_uv_to_vsel2, NULL, 32),
150 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN,
151 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK),
152}; 144};
153 145
154static int tps65217_pmic_is_enabled(struct regulator_dev *dev)
155{
156 int ret;
157 struct tps65217 *tps = rdev_get_drvdata(dev);
158 unsigned int data, rid = rdev_get_id(dev);
159
160 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
161 return -EINVAL;
162
163 ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data);
164 if (ret)
165 return ret;
166
167 return (data & tps->info[rid]->enable_mask) ? 1 : 0;
168}
169
170static int tps65217_pmic_enable(struct regulator_dev *dev) 146static int tps65217_pmic_enable(struct regulator_dev *dev)
171{ 147{
172 struct tps65217 *tps = rdev_get_drvdata(dev); 148 struct tps65217 *tps = rdev_get_drvdata(dev);
@@ -177,9 +153,8 @@ static int tps65217_pmic_enable(struct regulator_dev *dev)
177 153
178 /* Enable the regulator and password protection is level 1 */ 154 /* Enable the regulator and password protection is level 1 */
179 return tps65217_set_bits(tps, TPS65217_REG_ENABLE, 155 return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
180 tps->info[rid]->enable_mask, 156 dev->desc->enable_mask, dev->desc->enable_mask,
181 tps->info[rid]->enable_mask, 157 TPS65217_PROTECT_L1);
182 TPS65217_PROTECT_L1);
183} 158}
184 159
185static int tps65217_pmic_disable(struct regulator_dev *dev) 160static int tps65217_pmic_disable(struct regulator_dev *dev)
@@ -192,25 +167,7 @@ static int tps65217_pmic_disable(struct regulator_dev *dev)
192 167
193 /* Disable the regulator and password protection is level 1 */ 168 /* Disable the regulator and password protection is level 1 */
194 return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, 169 return tps65217_clear_bits(tps, TPS65217_REG_ENABLE,
195 tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); 170 dev->desc->enable_mask, TPS65217_PROTECT_L1);
196}
197
198static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev)
199{
200 int ret;
201 struct tps65217 *tps = rdev_get_drvdata(dev);
202 unsigned int selector, rid = rdev_get_id(dev);
203
204 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
205 return -EINVAL;
206
207 ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector);
208 if (ret)
209 return ret;
210
211 selector &= tps->info[rid]->set_vout_mask;
212
213 return selector;
214} 171}
215 172
216static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev, 173static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
@@ -221,8 +178,7 @@ static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
221 unsigned int rid = rdev_get_id(dev); 178 unsigned int rid = rdev_get_id(dev);
222 179
223 /* Set the voltage based on vsel value and write protect level is 2 */ 180 /* Set the voltage based on vsel value and write protect level is 2 */
224 ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, 181 ret = tps65217_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask,
225 tps->info[rid]->set_vout_mask,
226 selector, TPS65217_PROTECT_L2); 182 selector, TPS65217_PROTECT_L2);
227 183
228 /* Set GO bit for DCDCx to initiate voltage transistion */ 184 /* Set GO bit for DCDCx to initiate voltage transistion */
@@ -285,10 +241,10 @@ static int tps65217_pmic_list_voltage(struct regulator_dev *dev,
285 241
286/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ 242/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
287static struct regulator_ops tps65217_pmic_ops = { 243static struct regulator_ops tps65217_pmic_ops = {
288 .is_enabled = tps65217_pmic_is_enabled, 244 .is_enabled = regulator_is_enabled_regmap,
289 .enable = tps65217_pmic_enable, 245 .enable = tps65217_pmic_enable,
290 .disable = tps65217_pmic_disable, 246 .disable = tps65217_pmic_disable,
291 .get_voltage_sel = tps65217_pmic_get_voltage_sel, 247 .get_voltage_sel = regulator_get_voltage_sel_regmap,
292 .set_voltage_sel = tps65217_pmic_set_voltage_sel, 248 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
293 .list_voltage = tps65217_pmic_list_voltage, 249 .list_voltage = tps65217_pmic_list_voltage,
294 .map_voltage = tps65217_pmic_map_voltage, 250 .map_voltage = tps65217_pmic_map_voltage,
@@ -296,22 +252,36 @@ static struct regulator_ops tps65217_pmic_ops = {
296 252
297/* Operations permitted on LDO1 */ 253/* Operations permitted on LDO1 */
298static struct regulator_ops tps65217_pmic_ldo1_ops = { 254static struct regulator_ops tps65217_pmic_ldo1_ops = {
299 .is_enabled = tps65217_pmic_is_enabled, 255 .is_enabled = regulator_is_enabled_regmap,
300 .enable = tps65217_pmic_enable, 256 .enable = tps65217_pmic_enable,
301 .disable = tps65217_pmic_disable, 257 .disable = tps65217_pmic_disable,
302 .get_voltage_sel = tps65217_pmic_get_voltage_sel, 258 .get_voltage_sel = regulator_get_voltage_sel_regmap,
303 .set_voltage_sel = tps65217_pmic_set_voltage_sel, 259 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
304 .list_voltage = tps65217_pmic_list_voltage, 260 .list_voltage = tps65217_pmic_list_voltage,
305}; 261};
306 262
307static const struct regulator_desc regulators[] = { 263static const struct regulator_desc regulators[] = {
308 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), 264 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64,
309 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), 265 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK,
310 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), 266 TPS65217_ENABLE_DC1_EN),
311 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16), 267 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64,
312 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64), 268 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK,
313 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32), 269 TPS65217_ENABLE_DC2_EN),
314 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32), 270 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64,
271 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK,
272 TPS65217_ENABLE_DC3_EN),
273 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16,
274 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK,
275 TPS65217_ENABLE_LDO1_EN),
276 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64,
277 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK,
278 TPS65217_ENABLE_LDO2_EN),
279 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32,
280 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK,
281 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN),
282 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32,
283 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK,
284 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN),
315}; 285};
316 286
317static int __devinit tps65217_regulator_probe(struct platform_device *pdev) 287static int __devinit tps65217_regulator_probe(struct platform_device *pdev)
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h
index e030ef9a64ee..4e035a41a9b0 100644
--- a/include/linux/mfd/tps65217.h
+++ b/include/linux/mfd/tps65217.h
@@ -229,9 +229,6 @@ struct tps65217_board {
229 * @uv_to_vsel: Function pointer to get selector from voltage 229 * @uv_to_vsel: Function pointer to get selector from voltage
230 * @table: Table for non-uniform voltage step-size 230 * @table: Table for non-uniform voltage step-size
231 * @table_len: Length of the voltage table 231 * @table_len: Length of the voltage table
232 * @enable_mask: Regulator enable mask bits
233 * @set_vout_reg: Regulator output voltage set register
234 * @set_vout_mask: Regulator output voltage set mask
235 * 232 *
236 * This data is used to check the regualtor voltage limits while setting. 233 * This data is used to check the regualtor voltage limits while setting.
237 */ 234 */
@@ -243,9 +240,6 @@ struct tps_info {
243 int (*uv_to_vsel)(int uV, unsigned int *vsel); 240 int (*uv_to_vsel)(int uV, unsigned int *vsel);
244 const int *table; 241 const int *table;
245 unsigned int table_len; 242 unsigned int table_len;
246 unsigned int enable_mask;
247 unsigned int set_vout_reg;
248 unsigned int set_vout_mask;
249}; 243};
250 244
251/** 245/**