diff options
author | Vaibhav Hiremath <vaibhav.hiremath@linaro.org> | 2015-07-16 14:16:56 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-07-16 16:32:58 -0400 |
commit | fa26e4d2b3cf1c84f20fbc003501bb028f682d92 (patch) | |
tree | c203b4fd0cd4164d05dbb76e184459f12001b2a1 | |
parent | a07d94a54b93d94d8cb990ffe018c595cfb94662 (diff) |
regulator: 88pm800: Use regulator_nodes/of_match in the descriptor
This patch is add regulator_nodes/of_match in the regulator
descriptor for using information from DT instead of specific codes.
With this patch, driver gets simplified,
- No need to maintain "struct of_regulator_match" table
and call of_regulator_match() fn.
- No need for pm800_regulator_dt_init() fn, as it was only
used for of_regulator_match().
- probe() fn got simplified around regulator_config and regulator_desc
initialization.
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/88pm800.c | 143 |
1 files changed, 44 insertions, 99 deletions
diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c index 3b371701093d..26c277f7c98e 100644 --- a/drivers/regulator/88pm800.c +++ b/drivers/regulator/88pm800.c | |||
@@ -91,10 +91,12 @@ struct pm800_regulators { | |||
91 | * not the constant voltage table. | 91 | * not the constant voltage table. |
92 | * n_volt - Number of available selectors | 92 | * n_volt - Number of available selectors |
93 | */ | 93 | */ |
94 | #define PM800_BUCK(vreg, ereg, ebit, amax, volt_ranges, n_volt) \ | 94 | #define PM800_BUCK(match, vreg, ereg, ebit, amax, volt_ranges, n_volt) \ |
95 | { \ | 95 | { \ |
96 | .desc = { \ | 96 | .desc = { \ |
97 | .name = #vreg, \ | 97 | .name = #vreg, \ |
98 | .of_match = of_match_ptr(#match), \ | ||
99 | .regulators_node = of_match_ptr("regulators"), \ | ||
98 | .ops = &pm800_volt_range_ops, \ | 100 | .ops = &pm800_volt_range_ops, \ |
99 | .type = REGULATOR_VOLTAGE, \ | 101 | .type = REGULATOR_VOLTAGE, \ |
100 | .id = PM800_ID_##vreg, \ | 102 | .id = PM800_ID_##vreg, \ |
@@ -119,10 +121,12 @@ struct pm800_regulators { | |||
119 | * For all the LDOes, there are too many ranges. Using volt_table will be | 121 | * For all the LDOes, there are too many ranges. Using volt_table will be |
120 | * simpler and faster. | 122 | * simpler and faster. |
121 | */ | 123 | */ |
122 | #define PM800_LDO(vreg, ereg, ebit, amax, ldo_volt_table) \ | 124 | #define PM800_LDO(match, vreg, ereg, ebit, amax, ldo_volt_table) \ |
123 | { \ | 125 | { \ |
124 | .desc = { \ | 126 | .desc = { \ |
125 | .name = #vreg, \ | 127 | .name = #vreg, \ |
128 | .of_match = of_match_ptr(#match), \ | ||
129 | .regulators_node = of_match_ptr("regulators"), \ | ||
126 | .ops = &pm800_volt_table_ops, \ | 130 | .ops = &pm800_volt_table_ops, \ |
127 | .type = REGULATOR_VOLTAGE, \ | 131 | .type = REGULATOR_VOLTAGE, \ |
128 | .id = PM800_ID_##vreg, \ | 132 | .id = PM800_ID_##vreg, \ |
@@ -200,99 +204,43 @@ static struct regulator_ops pm800_volt_table_ops = { | |||
200 | 204 | ||
201 | /* The array is indexed by id(PM800_ID_XXX) */ | 205 | /* The array is indexed by id(PM800_ID_XXX) */ |
202 | static struct pm800_regulator_info pm800_regulator_info[] = { | 206 | static struct pm800_regulator_info pm800_regulator_info[] = { |
203 | PM800_BUCK(BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), | 207 | PM800_BUCK(buck1, BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), |
204 | PM800_BUCK(BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), | 208 | PM800_BUCK(buck2, BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), |
205 | PM800_BUCK(BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), | 209 | PM800_BUCK(buck3, BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), |
206 | PM800_BUCK(BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), | 210 | PM800_BUCK(buck4, BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), |
207 | PM800_BUCK(BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), | 211 | PM800_BUCK(buck5, BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), |
208 | 212 | ||
209 | PM800_LDO(LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), | 213 | PM800_LDO(ldo1, LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), |
210 | PM800_LDO(LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), | 214 | PM800_LDO(ldo2, LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), |
211 | PM800_LDO(LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), | 215 | PM800_LDO(ldo3, LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), |
212 | PM800_LDO(LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), | 216 | PM800_LDO(ldo4, LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), |
213 | PM800_LDO(LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), | 217 | PM800_LDO(ldo5, LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), |
214 | PM800_LDO(LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), | 218 | PM800_LDO(ldo6, LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), |
215 | PM800_LDO(LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), | 219 | PM800_LDO(ldo7, LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), |
216 | PM800_LDO(LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), | 220 | PM800_LDO(ldo8, LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), |
217 | PM800_LDO(LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), | 221 | PM800_LDO(ldo9, LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), |
218 | PM800_LDO(LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), | 222 | PM800_LDO(ldo10, LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), |
219 | PM800_LDO(LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), | 223 | PM800_LDO(ldo11, LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), |
220 | PM800_LDO(LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), | 224 | PM800_LDO(ldo12, LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), |
221 | PM800_LDO(LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), | 225 | PM800_LDO(ldo13, LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), |
222 | PM800_LDO(LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), | 226 | PM800_LDO(ldo14, LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), |
223 | PM800_LDO(LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), | 227 | PM800_LDO(ldo15, LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), |
224 | PM800_LDO(LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), | 228 | PM800_LDO(ldo16, LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), |
225 | PM800_LDO(LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), | 229 | PM800_LDO(ldo17, LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), |
226 | PM800_LDO(LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), | 230 | PM800_LDO(ldo18, LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), |
227 | PM800_LDO(LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), | 231 | PM800_LDO(ldo19, LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), |
228 | }; | 232 | }; |
229 | 233 | ||
230 | #define PM800_REGULATOR_OF_MATCH(_name, _id) \ | ||
231 | [PM800_ID_##_id] = { \ | ||
232 | .name = #_name, \ | ||
233 | .driver_data = &pm800_regulator_info[PM800_ID_##_id], \ | ||
234 | } | ||
235 | |||
236 | static struct of_regulator_match pm800_regulator_matches[] = { | ||
237 | PM800_REGULATOR_OF_MATCH(buck1, BUCK1), | ||
238 | PM800_REGULATOR_OF_MATCH(buck2, BUCK2), | ||
239 | PM800_REGULATOR_OF_MATCH(buck3, BUCK3), | ||
240 | PM800_REGULATOR_OF_MATCH(buck4, BUCK4), | ||
241 | PM800_REGULATOR_OF_MATCH(buck5, BUCK5), | ||
242 | PM800_REGULATOR_OF_MATCH(ldo1, LDO1), | ||
243 | PM800_REGULATOR_OF_MATCH(ldo2, LDO2), | ||
244 | PM800_REGULATOR_OF_MATCH(ldo3, LDO3), | ||
245 | PM800_REGULATOR_OF_MATCH(ldo4, LDO4), | ||
246 | PM800_REGULATOR_OF_MATCH(ldo5, LDO5), | ||
247 | PM800_REGULATOR_OF_MATCH(ldo6, LDO6), | ||
248 | PM800_REGULATOR_OF_MATCH(ldo7, LDO7), | ||
249 | PM800_REGULATOR_OF_MATCH(ldo8, LDO8), | ||
250 | PM800_REGULATOR_OF_MATCH(ldo9, LDO9), | ||
251 | PM800_REGULATOR_OF_MATCH(ldo10, LDO10), | ||
252 | PM800_REGULATOR_OF_MATCH(ldo11, LDO11), | ||
253 | PM800_REGULATOR_OF_MATCH(ldo12, LDO12), | ||
254 | PM800_REGULATOR_OF_MATCH(ldo13, LDO13), | ||
255 | PM800_REGULATOR_OF_MATCH(ldo14, LDO14), | ||
256 | PM800_REGULATOR_OF_MATCH(ldo15, LDO15), | ||
257 | PM800_REGULATOR_OF_MATCH(ldo16, LDO16), | ||
258 | PM800_REGULATOR_OF_MATCH(ldo17, LDO17), | ||
259 | PM800_REGULATOR_OF_MATCH(ldo18, LDO18), | ||
260 | PM800_REGULATOR_OF_MATCH(ldo19, LDO19), | ||
261 | }; | ||
262 | |||
263 | static int pm800_regulator_dt_init(struct platform_device *pdev) | ||
264 | { | ||
265 | struct device_node *np = pdev->dev.of_node; | ||
266 | int ret; | ||
267 | |||
268 | ret = of_regulator_match(&pdev->dev, np, | ||
269 | pm800_regulator_matches, | ||
270 | ARRAY_SIZE(pm800_regulator_matches)); | ||
271 | if (ret < 0) | ||
272 | return ret; | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | static int pm800_regulator_probe(struct platform_device *pdev) | 234 | static int pm800_regulator_probe(struct platform_device *pdev) |
278 | { | 235 | { |
279 | struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); | 236 | struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
280 | struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); | 237 | struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); |
281 | struct pm800_regulators *pm800_data; | 238 | struct pm800_regulators *pm800_data; |
282 | struct pm800_regulator_info *info; | ||
283 | struct regulator_config config = { }; | 239 | struct regulator_config config = { }; |
284 | struct regulator_init_data *init_data; | 240 | struct regulator_init_data *init_data; |
285 | int i, ret; | 241 | int i, ret; |
286 | 242 | ||
287 | if (!pdata || pdata->num_regulators == 0) { | 243 | if (pdata && pdata->num_regulators) { |
288 | if (IS_ENABLED(CONFIG_OF)) { | ||
289 | ret = pm800_regulator_dt_init(pdev); | ||
290 | if (ret) | ||
291 | return ret; | ||
292 | } else { | ||
293 | return -ENODEV; | ||
294 | } | ||
295 | } else if (pdata->num_regulators) { | ||
296 | unsigned int count = 0; | 244 | unsigned int count = 0; |
297 | 245 | ||
298 | /* Check whether num_regulator is valid. */ | 246 | /* Check whether num_regulator is valid. */ |
@@ -302,8 +250,6 @@ static int pm800_regulator_probe(struct platform_device *pdev) | |||
302 | } | 250 | } |
303 | if (count != pdata->num_regulators) | 251 | if (count != pdata->num_regulators) |
304 | return -EINVAL; | 252 | return -EINVAL; |
305 | } else { | ||
306 | return -EINVAL; | ||
307 | } | 253 | } |
308 | 254 | ||
309 | pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), | 255 | pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), |
@@ -316,28 +262,27 @@ static int pm800_regulator_probe(struct platform_device *pdev) | |||
316 | 262 | ||
317 | platform_set_drvdata(pdev, pm800_data); | 263 | platform_set_drvdata(pdev, pm800_data); |
318 | 264 | ||
265 | config.dev = chip->dev; | ||
266 | config.regmap = pm800_data->map; | ||
319 | for (i = 0; i < PM800_ID_RG_MAX; i++) { | 267 | for (i = 0; i < PM800_ID_RG_MAX; i++) { |
320 | struct regulator_dev *regulator; | 268 | struct regulator_dev *regulator; |
321 | 269 | ||
322 | if (!pdata || pdata->num_regulators == 0) | 270 | if (pdata && pdata->num_regulators) { |
323 | init_data = pm800_regulator_matches[i].init_data; | ||
324 | else | ||
325 | init_data = pdata->regulators[i]; | 271 | init_data = pdata->regulators[i]; |
326 | if (!init_data) | 272 | if (!init_data) |
327 | continue; | 273 | continue; |
328 | info = pm800_regulator_matches[i].driver_data; | 274 | |
329 | config.dev = &pdev->dev; | 275 | config.init_data = init_data; |
330 | config.init_data = init_data; | 276 | } |
331 | config.driver_data = info; | 277 | |
332 | config.regmap = pm800_data->map; | 278 | config.driver_data = &pm800_regulator_info[i]; |
333 | config.of_node = pm800_regulator_matches[i].of_node; | ||
334 | 279 | ||
335 | regulator = devm_regulator_register(&pdev->dev, | 280 | regulator = devm_regulator_register(&pdev->dev, |
336 | &info->desc, &config); | 281 | &pm800_regulator_info[i].desc, &config); |
337 | if (IS_ERR(regulator)) { | 282 | if (IS_ERR(regulator)) { |
338 | ret = PTR_ERR(regulator); | 283 | ret = PTR_ERR(regulator); |
339 | dev_err(&pdev->dev, "Failed to register %s\n", | 284 | dev_err(&pdev->dev, "Failed to register %s\n", |
340 | info->desc.name); | 285 | pm800_regulator_info[i].desc.name); |
341 | return ret; | 286 | return ret; |
342 | } | 287 | } |
343 | } | 288 | } |