Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: hi6421: Convert to use simplified DT parsing

Use regulator core's simplified DT parsing code to simply the driver
implementation.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Axel Lin and committed by
Mark Brown
29dc269a f34a2692

+78 -130
+78 -130
drivers/regulator/hi6421-regulator.c
··· 78 78 HI6421_NUM_REGULATORS, 79 79 }; 80 80 81 - #define HI6421_REGULATOR_OF_MATCH(_name, id) \ 82 - { \ 83 - .name = #_name, \ 84 - .driver_data = (void *) HI6421_##id, \ 85 - } 86 - 87 - static struct of_regulator_match hi6421_regulator_match[] = { 88 - HI6421_REGULATOR_OF_MATCH(hi6421_vout0, LDO0), 89 - HI6421_REGULATOR_OF_MATCH(hi6421_vout1, LDO1), 90 - HI6421_REGULATOR_OF_MATCH(hi6421_vout2, LDO2), 91 - HI6421_REGULATOR_OF_MATCH(hi6421_vout3, LDO3), 92 - HI6421_REGULATOR_OF_MATCH(hi6421_vout4, LDO4), 93 - HI6421_REGULATOR_OF_MATCH(hi6421_vout5, LDO5), 94 - HI6421_REGULATOR_OF_MATCH(hi6421_vout6, LDO6), 95 - HI6421_REGULATOR_OF_MATCH(hi6421_vout7, LDO7), 96 - HI6421_REGULATOR_OF_MATCH(hi6421_vout8, LDO8), 97 - HI6421_REGULATOR_OF_MATCH(hi6421_vout9, LDO9), 98 - HI6421_REGULATOR_OF_MATCH(hi6421_vout10, LDO10), 99 - HI6421_REGULATOR_OF_MATCH(hi6421_vout11, LDO11), 100 - HI6421_REGULATOR_OF_MATCH(hi6421_vout12, LDO12), 101 - HI6421_REGULATOR_OF_MATCH(hi6421_vout13, LDO13), 102 - HI6421_REGULATOR_OF_MATCH(hi6421_vout14, LDO14), 103 - HI6421_REGULATOR_OF_MATCH(hi6421_vout15, LDO15), 104 - HI6421_REGULATOR_OF_MATCH(hi6421_vout16, LDO16), 105 - HI6421_REGULATOR_OF_MATCH(hi6421_vout17, LDO17), 106 - HI6421_REGULATOR_OF_MATCH(hi6421_vout18, LDO18), 107 - HI6421_REGULATOR_OF_MATCH(hi6421_vout19, LDO19), 108 - HI6421_REGULATOR_OF_MATCH(hi6421_vout20, LDO20), 109 - HI6421_REGULATOR_OF_MATCH(hi6421_vout_audio, LDOAUDIO), 110 - HI6421_REGULATOR_OF_MATCH(hi6421_buck0, BUCK0), 111 - HI6421_REGULATOR_OF_MATCH(hi6421_buck1, BUCK1), 112 - HI6421_REGULATOR_OF_MATCH(hi6421_buck2, BUCK2), 113 - HI6421_REGULATOR_OF_MATCH(hi6421_buck3, BUCK3), 114 - HI6421_REGULATOR_OF_MATCH(hi6421_buck4, BUCK4), 115 - HI6421_REGULATOR_OF_MATCH(hi6421_buck5, BUCK5), 116 - }; 117 - 118 81 /* LDO 0, 4~7, 9~14, 16~20 have same voltage table. */ 119 82 static const unsigned int ldo_0_voltages[] = { 120 83 1500000, 1800000, 2400000, 2500000, ··· 120 157 #define HI6421_LDO_ENABLE_TIME (350) 121 158 /* 122 159 * _id - LDO id name string 160 + * _match - of match name string 123 161 * v_table - voltage table 124 162 * vreg - voltage select register 125 163 * vmask - voltage select mask ··· 130 166 * ecomask - eco mode mask 131 167 * ecoamp - eco mode load uppler limit in uA 132 168 */ 133 - #define HI6421_LDO(_id, v_table, vreg, vmask, ereg, emask, \ 169 + #define HI6421_LDO(_id, _match, v_table, vreg, vmask, ereg, emask, \ 134 170 odelay, ecomask, ecoamp) \ 135 171 [HI6421_##_id] = { \ 136 172 .desc = { \ 137 173 .name = #_id, \ 174 + .of_match = of_match_ptr(#_match), \ 175 + .regulators_node = of_match_ptr("regulators"), \ 138 176 .ops = &hi6421_ldo_ops, \ 139 177 .type = REGULATOR_VOLTAGE, \ 140 178 .id = HI6421_##_id, \ ··· 157 191 /* HI6421 LDO1~3 are linear voltage regulators at fixed uV_step 158 192 * 159 193 * _id - LDO id name string 194 + * _match - of match name string 160 195 * _min_uV - minimum voltage supported in uV 161 196 * n_volt - number of votages available 162 197 * vstep - voltage increase in each linear step in uV ··· 169 202 * ecomask - eco mode mask 170 203 * ecoamp - eco mode load uppler limit in uA 171 204 */ 172 - #define HI6421_LDO_LINEAR(_id, _min_uV, n_volt, vstep, vreg, vmask, \ 205 + #define HI6421_LDO_LINEAR(_id, _match, _min_uV, n_volt, vstep, vreg, vmask,\ 173 206 ereg, emask, odelay, ecomask, ecoamp) \ 174 207 [HI6421_##_id] = { \ 175 208 .desc = { \ 176 209 .name = #_id, \ 210 + .of_match = of_match_ptr(#_match), \ 211 + .regulators_node = of_match_ptr("regulators"), \ 177 212 .ops = &hi6421_ldo_linear_ops, \ 178 213 .type = REGULATOR_VOLTAGE, \ 179 214 .id = HI6421_##_id, \ ··· 197 228 /* HI6421 LDOAUDIO is a linear voltage regulator with two 4-step ranges 198 229 * 199 230 * _id - LDO id name string 231 + * _match - of match name string 200 232 * n_volt - number of votages available 201 233 * volt_ranges - array of regulator_linear_range 202 234 * vstep - voltage increase in each linear step in uV ··· 209 239 * ecomask - eco mode mask 210 240 * ecoamp - eco mode load uppler limit in uA 211 241 */ 212 - #define HI6421_LDO_LINEAR_RANGE(_id, n_volt, volt_ranges, vreg, vmask, \ 242 + #define HI6421_LDO_LINEAR_RANGE(_id, _match, n_volt, volt_ranges, vreg, vmask,\ 213 243 ereg, emask, odelay, ecomask, ecoamp) \ 214 244 [HI6421_##_id] = { \ 215 245 .desc = { \ 216 246 .name = #_id, \ 247 + .of_match = of_match_ptr(#_match), \ 248 + .regulators_node = of_match_ptr("regulators"), \ 217 249 .ops = &hi6421_ldo_linear_range_ops, \ 218 250 .type = REGULATOR_VOLTAGE, \ 219 251 .id = HI6421_##_id, \ ··· 237 265 /* HI6421 BUCK0/1/2 are linear voltage regulators at fixed uV_step 238 266 * 239 267 * _id - BUCK0/1/2 id name string 268 + * _match - of match name string 240 269 * vreg - voltage select register 241 270 * vmask - voltage select mask 242 271 * ereg - enable register ··· 246 273 * etime - enable time 247 274 * odelay - off/on delay time in uS 248 275 */ 249 - #define HI6421_BUCK012(_id, vreg, vmask, ereg, emask, sleepmask, \ 276 + #define HI6421_BUCK012(_id, _match, vreg, vmask, ereg, emask, sleepmask,\ 250 277 etime, odelay) \ 251 278 [HI6421_##_id] = { \ 252 279 .desc = { \ 253 280 .name = #_id, \ 281 + .of_match = of_match_ptr(#_match), \ 282 + .regulators_node = of_match_ptr("regulators"), \ 254 283 .ops = &hi6421_buck012_ops, \ 255 284 .type = REGULATOR_VOLTAGE, \ 256 285 .id = HI6421_##_id, \ ··· 274 299 * that it supports SLEEP mode, so has different .ops. 275 300 * 276 301 * _id - LDO id name string 302 + * _match - of match name string 277 303 * v_table - voltage table 278 304 * vreg - voltage select register 279 305 * vmask - voltage select mask ··· 283 307 * odelay - off/on delay time in uS 284 308 * sleepmask - mask of sleep mode 285 309 */ 286 - #define HI6421_BUCK345(_id, v_table, vreg, vmask, ereg, emask, \ 310 + #define HI6421_BUCK345(_id, _match, v_table, vreg, vmask, ereg, emask, \ 287 311 odelay, sleepmask) \ 288 312 [HI6421_##_id] = { \ 289 313 .desc = { \ 290 314 .name = #_id, \ 315 + .of_match = of_match_ptr(#_match), \ 316 + .regulators_node = of_match_ptr("regulators"), \ 291 317 .ops = &hi6421_buck345_ops, \ 292 318 .type = REGULATOR_VOLTAGE, \ 293 319 .id = HI6421_##_id, \ ··· 309 331 /* HI6421 regulator information */ 310 332 static struct hi6421_regulator_info 311 333 hi6421_regulator_info[HI6421_NUM_REGULATORS] = { 312 - HI6421_LDO(LDO0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10, 334 + HI6421_LDO(LDO0, hi6421_vout0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10, 313 335 10000, 0x20, 8000), 314 - HI6421_LDO_LINEAR(LDO1, 1700000, 4, 100000, 0x21, 0x03, 0x21, 0x10, 315 - 10000, 0x20, 5000), 316 - HI6421_LDO_LINEAR(LDO2, 1050000, 8, 50000, 0x22, 0x07, 0x22, 0x10, 317 - 20000, 0x20, 8000), 318 - HI6421_LDO_LINEAR(LDO3, 1050000, 8, 50000, 0x23, 0x07, 0x23, 0x10, 319 - 20000, 0x20, 8000), 320 - HI6421_LDO(LDO4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10, 336 + HI6421_LDO_LINEAR(LDO1, hi6421_vout1, 1700000, 4, 100000, 0x21, 0x03, 337 + 0x21, 0x10, 10000, 0x20, 5000), 338 + HI6421_LDO_LINEAR(LDO2, hi6421_vout2, 1050000, 8, 50000, 0x22, 0x07, 339 + 0x22, 0x10, 20000, 0x20, 8000), 340 + HI6421_LDO_LINEAR(LDO3, hi6421_vout3, 1050000, 8, 50000, 0x23, 0x07, 341 + 0x23, 0x10, 20000, 0x20, 8000), 342 + HI6421_LDO(LDO4, hi6421_vout4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10, 321 343 20000, 0x20, 8000), 322 - HI6421_LDO(LDO5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10, 344 + HI6421_LDO(LDO5, hi6421_vout5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10, 323 345 20000, 0x20, 8000), 324 - HI6421_LDO(LDO6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10, 346 + HI6421_LDO(LDO6, hi6421_vout6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10, 325 347 20000, 0x20, 8000), 326 - HI6421_LDO(LDO7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10, 348 + HI6421_LDO(LDO7, hi6421_vout7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10, 327 349 20000, 0x20, 5000), 328 - HI6421_LDO(LDO8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10, 350 + HI6421_LDO(LDO8, hi6421_vout8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10, 329 351 20000, 0x20, 8000), 330 - HI6421_LDO(LDO9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10, 352 + HI6421_LDO(LDO9, hi6421_vout9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10, 331 353 40000, 0x20, 8000), 332 - HI6421_LDO(LDO10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10, 354 + HI6421_LDO(LDO10, hi6421_vout10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10, 333 355 40000, 0x20, 8000), 334 - HI6421_LDO(LDO11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10, 356 + HI6421_LDO(LDO11, hi6421_vout11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10, 335 357 40000, 0x20, 8000), 336 - HI6421_LDO(LDO12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10, 358 + HI6421_LDO(LDO12, hi6421_vout12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10, 337 359 40000, 0x20, 8000), 338 - HI6421_LDO(LDO13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10, 360 + HI6421_LDO(LDO13, hi6421_vout13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10, 339 361 40000, 0x20, 8000), 340 - HI6421_LDO(LDO14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10, 362 + HI6421_LDO(LDO14, hi6421_vout14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10, 341 363 40000, 0x20, 8000), 342 - HI6421_LDO(LDO15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10, 364 + HI6421_LDO(LDO15, hi6421_vout15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10, 343 365 40000, 0x20, 8000), 344 - HI6421_LDO(LDO16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10, 366 + HI6421_LDO(LDO16, hi6421_vout16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10, 345 367 40000, 0x20, 8000), 346 - HI6421_LDO(LDO17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10, 368 + HI6421_LDO(LDO17, hi6421_vout17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10, 347 369 40000, 0x20, 8000), 348 - HI6421_LDO(LDO18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10, 370 + HI6421_LDO(LDO18, hi6421_vout18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10, 349 371 40000, 0x20, 8000), 350 - HI6421_LDO(LDO19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10, 372 + HI6421_LDO(LDO19, hi6421_vout19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10, 351 373 40000, 0x20, 8000), 352 - HI6421_LDO(LDO20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10, 374 + HI6421_LDO(LDO20, hi6421_vout20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10, 353 375 40000, 0x20, 8000), 354 - HI6421_LDO_LINEAR_RANGE(LDOAUDIO, 8, ldo_audio_volt_range, 0x36, 355 - 0x70, 0x36, 0x01, 40000, 0x02, 5000), 356 - HI6421_BUCK012(BUCK0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400, 20000), 357 - HI6421_BUCK012(BUCK1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400, 20000), 358 - HI6421_BUCK012(BUCK2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350, 100), 359 - HI6421_BUCK345(BUCK3, buck_3_voltages, 0x13, 0x07, 0x12, 0x01, 360 - 20000, 0x10), 361 - HI6421_BUCK345(BUCK4, buck_4_voltages, 0x15, 0x07, 0x14, 0x01, 362 - 20000, 0x10), 363 - HI6421_BUCK345(BUCK5, buck_5_voltages, 0x17, 0x07, 0x16, 0x01, 364 - 20000, 0x10), 376 + HI6421_LDO_LINEAR_RANGE(LDOAUDIO, hi6421_vout_audio, 8, 377 + ldo_audio_volt_range, 0x36, 0x70, 0x36, 0x01, 378 + 40000, 0x02, 5000), 379 + HI6421_BUCK012(BUCK0, hi6421_buck0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400, 380 + 20000), 381 + HI6421_BUCK012(BUCK1, hi6421_buck1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400, 382 + 20000), 383 + HI6421_BUCK012(BUCK2, hi6421_buck2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350, 384 + 100), 385 + HI6421_BUCK345(BUCK3, hi6421_buck3, buck_3_voltages, 0x13, 0x07, 0x12, 386 + 0x01, 20000, 0x10), 387 + HI6421_BUCK345(BUCK4, hi6421_buck4, buck_4_voltages, 0x15, 0x07, 0x14, 388 + 0x01, 20000, 0x10), 389 + HI6421_BUCK345(BUCK5, hi6421_buck5, buck_5_voltages, 0x17, 0x07, 0x16, 390 + 0x01, 20000, 0x10), 365 391 }; 366 392 367 393 static int hi6421_regulator_enable(struct regulator_dev *rdev) ··· 534 552 .set_mode = hi6421_regulator_buck_set_mode, 535 553 }; 536 554 537 - static int hi6421_regulator_register(struct platform_device *pdev, 538 - struct regmap *rmap, 539 - struct regulator_init_data *init_data, 540 - int id, struct device_node *np) 541 - { 542 - struct hi6421_regulator_info *info = NULL; 543 - struct regulator_config config = { }; 544 - struct regulator_dev *rdev; 545 - 546 - /* assign per-regulator data */ 547 - info = &hi6421_regulator_info[id]; 548 - 549 - config.dev = &pdev->dev; 550 - config.init_data = init_data; 551 - config.driver_data = info; 552 - config.regmap = rmap; 553 - config.of_node = np; 554 - 555 - /* register regulator with framework */ 556 - rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); 557 - if (IS_ERR(rdev)) { 558 - dev_err(&pdev->dev, "failed to register regulator %s\n", 559 - info->desc.name); 560 - return PTR_ERR(rdev); 561 - } 562 - 563 - return 0; 564 - } 565 - 566 555 static int hi6421_regulator_probe(struct platform_device *pdev) 567 556 { 568 - struct device *dev = &pdev->dev; 569 - struct device_node *np; 570 - struct hi6421_pmic *pmic; 557 + struct hi6421_pmic *pmic = dev_get_drvdata(pdev->dev.parent); 571 558 struct hi6421_regulator_pdata *pdata; 572 - int i, ret = 0; 559 + struct hi6421_regulator_info *info; 560 + struct regulator_config config = { }; 561 + struct regulator_dev *rdev; 562 + int i; 573 563 574 564 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 575 565 if (!pdata) ··· 549 595 mutex_init(&pdata->lock); 550 596 platform_set_drvdata(pdev, pdata); 551 597 552 - np = of_get_child_by_name(dev->parent->of_node, "regulators"); 553 - if (!np) 554 - return -ENODEV; 555 - 556 - ret = of_regulator_match(dev, np, 557 - hi6421_regulator_match, 558 - ARRAY_SIZE(hi6421_regulator_match)); 559 - of_node_put(np); 560 - if (ret < 0) { 561 - dev_err(dev, "Error parsing regulator init data: %d\n", ret); 562 - return ret; 563 - } 564 - 565 - pmic = dev_get_drvdata(dev->parent); 566 - 567 598 for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) { 568 - ret = hi6421_regulator_register(pdev, pmic->regmap, 569 - hi6421_regulator_match[i].init_data, i, 570 - hi6421_regulator_match[i].of_node); 571 - if (ret) 572 - return ret; 599 + /* assign per-regulator data */ 600 + info = &hi6421_regulator_info[i]; 601 + 602 + config.dev = pdev->dev.parent; 603 + config.driver_data = info; 604 + config.regmap = pmic->regmap; 605 + 606 + rdev = devm_regulator_register(&pdev->dev, &info->desc, 607 + &config); 608 + if (IS_ERR(rdev)) { 609 + dev_err(&pdev->dev, "failed to register regulator %s\n", 610 + info->desc.name); 611 + return PTR_ERR(rdev); 612 + } 573 613 } 574 614 575 615 return 0;