diff options
Diffstat (limited to 'drivers/regulator/tps6586x-regulator.c')
-rw-r--r-- | drivers/regulator/tps6586x-regulator.c | 108 |
1 files changed, 37 insertions, 71 deletions
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index cfc1f16f7771..c0a214575380 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c | |||
@@ -75,8 +75,7 @@ static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev) | |||
75 | return rdev_get_dev(rdev)->parent->parent; | 75 | return rdev_get_dev(rdev)->parent->parent; |
76 | } | 76 | } |
77 | 77 | ||
78 | static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev, | 78 | static int tps6586x_list_voltage(struct regulator_dev *rdev, unsigned selector) |
79 | unsigned selector) | ||
80 | { | 79 | { |
81 | struct tps6586x_regulator *info = rdev_get_drvdata(rdev); | 80 | struct tps6586x_regulator *info = rdev_get_drvdata(rdev); |
82 | int rid = rdev_get_id(rdev); | 81 | int rid = rdev_get_id(rdev); |
@@ -89,47 +88,34 @@ static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev, | |||
89 | } | 88 | } |
90 | 89 | ||
91 | 90 | ||
92 | static int __tps6586x_ldo_set_voltage(struct device *parent, | 91 | static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, |
93 | struct tps6586x_regulator *ri, | 92 | unsigned selector) |
94 | int min_uV, int max_uV, | ||
95 | unsigned *selector) | ||
96 | { | 93 | { |
97 | int val, uV; | 94 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); |
95 | struct device *parent = to_tps6586x_dev(rdev); | ||
96 | int ret, val, rid = rdev_get_id(rdev); | ||
98 | uint8_t mask; | 97 | uint8_t mask; |
99 | 98 | ||
100 | for (val = 0; val < ri->desc.n_voltages; val++) { | 99 | val = selector << ri->volt_shift; |
101 | uV = ri->voltages[val] * 1000; | 100 | mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; |
102 | |||
103 | /* LDO0 has minimal voltage 1.2 rather than 1.25 */ | ||
104 | if (ri->desc.id == TPS6586X_ID_LDO_0 && val == 0) | ||
105 | uV -= 50 * 1000; | ||
106 | |||
107 | /* use the first in-range value */ | ||
108 | if (min_uV <= uV && uV <= max_uV) { | ||
109 | |||
110 | *selector = val; | ||
111 | 101 | ||
112 | val <<= ri->volt_shift; | 102 | ret = tps6586x_update(parent, ri->volt_reg, val, mask); |
113 | mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; | 103 | if (ret) |
104 | return ret; | ||
114 | 105 | ||
115 | return tps6586x_update(parent, ri->volt_reg, val, mask); | 106 | /* Update go bit for DVM regulators */ |
116 | } | 107 | switch (rid) { |
108 | case TPS6586X_ID_LDO_2: | ||
109 | case TPS6586X_ID_LDO_4: | ||
110 | case TPS6586X_ID_SM_0: | ||
111 | case TPS6586X_ID_SM_1: | ||
112 | ret = tps6586x_set_bits(parent, ri->go_reg, 1 << ri->go_bit); | ||
113 | break; | ||
117 | } | 114 | } |
118 | 115 | return ret; | |
119 | return -EINVAL; | ||
120 | } | ||
121 | |||
122 | static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev, | ||
123 | int min_uV, int max_uV, unsigned *selector) | ||
124 | { | ||
125 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
126 | struct device *parent = to_tps6586x_dev(rdev); | ||
127 | |||
128 | return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV, | ||
129 | selector); | ||
130 | } | 116 | } |
131 | 117 | ||
132 | static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev) | 118 | static int tps6586x_get_voltage_sel(struct regulator_dev *rdev) |
133 | { | 119 | { |
134 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | 120 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); |
135 | struct device *parent = to_tps6586x_dev(rdev); | 121 | struct device *parent = to_tps6586x_dev(rdev); |
@@ -146,22 +132,7 @@ static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev) | |||
146 | if (val >= ri->desc.n_voltages) | 132 | if (val >= ri->desc.n_voltages) |
147 | BUG(); | 133 | BUG(); |
148 | 134 | ||
149 | return ri->voltages[val] * 1000; | 135 | return val; |
150 | } | ||
151 | |||
152 | static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev, | ||
153 | int min_uV, int max_uV, unsigned *selector) | ||
154 | { | ||
155 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
156 | struct device *parent = to_tps6586x_dev(rdev); | ||
157 | int ret; | ||
158 | |||
159 | ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV, | ||
160 | selector); | ||
161 | if (ret) | ||
162 | return ret; | ||
163 | |||
164 | return tps6586x_set_bits(parent, ri->go_reg, 1 << ri->go_bit); | ||
165 | } | 136 | } |
166 | 137 | ||
167 | static int tps6586x_regulator_enable(struct regulator_dev *rdev) | 138 | static int tps6586x_regulator_enable(struct regulator_dev *rdev) |
@@ -196,20 +167,10 @@ static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev) | |||
196 | return !!(reg_val & (1 << ri->enable_bit[0])); | 167 | return !!(reg_val & (1 << ri->enable_bit[0])); |
197 | } | 168 | } |
198 | 169 | ||
199 | static struct regulator_ops tps6586x_regulator_ldo_ops = { | 170 | static struct regulator_ops tps6586x_regulator_ops = { |
200 | .list_voltage = tps6586x_ldo_list_voltage, | 171 | .list_voltage = tps6586x_list_voltage, |
201 | .get_voltage = tps6586x_ldo_get_voltage, | 172 | .get_voltage_sel = tps6586x_get_voltage_sel, |
202 | .set_voltage = tps6586x_ldo_set_voltage, | 173 | .set_voltage_sel = tps6586x_set_voltage_sel, |
203 | |||
204 | .is_enabled = tps6586x_regulator_is_enabled, | ||
205 | .enable = tps6586x_regulator_enable, | ||
206 | .disable = tps6586x_regulator_disable, | ||
207 | }; | ||
208 | |||
209 | static struct regulator_ops tps6586x_regulator_dvm_ops = { | ||
210 | .list_voltage = tps6586x_ldo_list_voltage, | ||
211 | .get_voltage = tps6586x_ldo_get_voltage, | ||
212 | .set_voltage = tps6586x_dvm_set_voltage, | ||
213 | 174 | ||
214 | .is_enabled = tps6586x_regulator_is_enabled, | 175 | .is_enabled = tps6586x_regulator_is_enabled, |
215 | .enable = tps6586x_regulator_enable, | 176 | .enable = tps6586x_regulator_enable, |
@@ -241,11 +202,11 @@ static int tps6586x_dvm_voltages[] = { | |||
241 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 202 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, |
242 | }; | 203 | }; |
243 | 204 | ||
244 | #define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \ | 205 | #define TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ |
245 | ereg0, ebit0, ereg1, ebit1) \ | 206 | ereg0, ebit0, ereg1, ebit1) \ |
246 | .desc = { \ | 207 | .desc = { \ |
247 | .name = "REG-" #_id, \ | 208 | .name = "REG-" #_id, \ |
248 | .ops = &tps6586x_regulator_##_ops, \ | 209 | .ops = &tps6586x_regulator_ops, \ |
249 | .type = REGULATOR_VOLTAGE, \ | 210 | .type = REGULATOR_VOLTAGE, \ |
250 | .id = TPS6586X_ID_##_id, \ | 211 | .id = TPS6586X_ID_##_id, \ |
251 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ | 212 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ |
@@ -267,14 +228,14 @@ static int tps6586x_dvm_voltages[] = { | |||
267 | #define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ | 228 | #define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ |
268 | ereg0, ebit0, ereg1, ebit1) \ | 229 | ereg0, ebit0, ereg1, ebit1) \ |
269 | { \ | 230 | { \ |
270 | TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \ | 231 | TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ |
271 | ereg0, ebit0, ereg1, ebit1) \ | 232 | ereg0, ebit0, ereg1, ebit1) \ |
272 | } | 233 | } |
273 | 234 | ||
274 | #define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ | 235 | #define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ |
275 | ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ | 236 | ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ |
276 | { \ | 237 | { \ |
277 | TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \ | 238 | TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ |
278 | ereg0, ebit0, ereg1, ebit1) \ | 239 | ereg0, ebit0, ereg1, ebit1) \ |
279 | TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ | 240 | TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ |
280 | } | 241 | } |
@@ -384,6 +345,7 @@ static inline struct tps6586x_regulator *find_regulator_info(int id) | |||
384 | static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) | 345 | static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) |
385 | { | 346 | { |
386 | struct tps6586x_regulator *ri = NULL; | 347 | struct tps6586x_regulator *ri = NULL; |
348 | struct regulator_config config = { }; | ||
387 | struct regulator_dev *rdev; | 349 | struct regulator_dev *rdev; |
388 | int id = pdev->id; | 350 | int id = pdev->id; |
389 | int err; | 351 | int err; |
@@ -400,8 +362,12 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) | |||
400 | if (err) | 362 | if (err) |
401 | return err; | 363 | return err; |
402 | 364 | ||
403 | rdev = regulator_register(&ri->desc, &pdev->dev, | 365 | config.dev = &pdev->dev; |
404 | pdev->dev.platform_data, ri, NULL); | 366 | config.of_node = pdev->dev.of_node; |
367 | config.init_data = pdev->dev.platform_data; | ||
368 | config.driver_data = ri; | ||
369 | |||
370 | rdev = regulator_register(&ri->desc, &config); | ||
405 | if (IS_ERR(rdev)) { | 371 | if (IS_ERR(rdev)) { |
406 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 372 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
407 | ri->desc.name); | 373 | ri->desc.name); |