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

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>

authored by

Vaibhav Hiremath and committed by
Mark Brown
fa26e4d2 a07d94a5

+43 -98
+43 -98
drivers/regulator/88pm800.c
··· 91 91 * not the constant voltage table. 92 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 96 .desc = { \ 97 97 .name = #vreg, \ 98 + .of_match = of_match_ptr(#match), \ 99 + .regulators_node = of_match_ptr("regulators"), \ 98 100 .ops = &pm800_volt_range_ops, \ 99 101 .type = REGULATOR_VOLTAGE, \ 100 102 .id = PM800_ID_##vreg, \ ··· 121 119 * For all the LDOes, there are too many ranges. Using volt_table will be 122 120 * simpler and faster. 123 121 */ 124 - #define PM800_LDO(vreg, ereg, ebit, amax, ldo_volt_table) \ 122 + #define PM800_LDO(match, vreg, ereg, ebit, amax, ldo_volt_table) \ 125 123 { \ 126 124 .desc = { \ 127 125 .name = #vreg, \ 126 + .of_match = of_match_ptr(#match), \ 127 + .regulators_node = of_match_ptr("regulators"), \ 128 128 .ops = &pm800_volt_table_ops, \ 129 129 .type = REGULATOR_VOLTAGE, \ 130 130 .id = PM800_ID_##vreg, \ ··· 204 200 205 201 /* The array is indexed by id(PM800_ID_XXX) */ 206 202 static struct pm800_regulator_info pm800_regulator_info[] = { 207 - PM800_BUCK(BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), 208 - PM800_BUCK(BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), 209 - PM800_BUCK(BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), 210 - PM800_BUCK(BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), 211 - PM800_BUCK(BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), 203 + PM800_BUCK(buck1, BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), 204 + PM800_BUCK(buck2, BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), 205 + PM800_BUCK(buck3, BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), 206 + PM800_BUCK(buck4, BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), 207 + PM800_BUCK(buck5, BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), 212 208 213 - PM800_LDO(LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), 214 - PM800_LDO(LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), 215 - PM800_LDO(LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), 216 - PM800_LDO(LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), 217 - PM800_LDO(LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), 218 - PM800_LDO(LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), 219 - PM800_LDO(LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), 220 - PM800_LDO(LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), 221 - PM800_LDO(LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), 222 - PM800_LDO(LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), 223 - PM800_LDO(LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), 224 - PM800_LDO(LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), 225 - PM800_LDO(LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), 226 - PM800_LDO(LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), 227 - PM800_LDO(LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), 228 - PM800_LDO(LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), 229 - PM800_LDO(LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), 230 - PM800_LDO(LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), 231 - PM800_LDO(LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), 209 + PM800_LDO(ldo1, LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), 210 + PM800_LDO(ldo2, LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), 211 + PM800_LDO(ldo3, LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), 212 + PM800_LDO(ldo4, LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), 213 + PM800_LDO(ldo5, LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), 214 + PM800_LDO(ldo6, LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), 215 + PM800_LDO(ldo7, LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), 216 + PM800_LDO(ldo8, LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), 217 + PM800_LDO(ldo9, LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), 218 + PM800_LDO(ldo10, LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), 219 + PM800_LDO(ldo11, LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), 220 + PM800_LDO(ldo12, LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), 221 + PM800_LDO(ldo13, LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), 222 + PM800_LDO(ldo14, LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), 223 + PM800_LDO(ldo15, LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), 224 + PM800_LDO(ldo16, LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), 225 + PM800_LDO(ldo17, LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), 226 + PM800_LDO(ldo18, LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), 227 + PM800_LDO(ldo19, LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), 232 228 }; 233 - 234 - #define PM800_REGULATOR_OF_MATCH(_name, _id) \ 235 - [PM800_ID_##_id] = { \ 236 - .name = #_name, \ 237 - .driver_data = &pm800_regulator_info[PM800_ID_##_id], \ 238 - } 239 - 240 - static struct of_regulator_match pm800_regulator_matches[] = { 241 - PM800_REGULATOR_OF_MATCH(buck1, BUCK1), 242 - PM800_REGULATOR_OF_MATCH(buck2, BUCK2), 243 - PM800_REGULATOR_OF_MATCH(buck3, BUCK3), 244 - PM800_REGULATOR_OF_MATCH(buck4, BUCK4), 245 - PM800_REGULATOR_OF_MATCH(buck5, BUCK5), 246 - PM800_REGULATOR_OF_MATCH(ldo1, LDO1), 247 - PM800_REGULATOR_OF_MATCH(ldo2, LDO2), 248 - PM800_REGULATOR_OF_MATCH(ldo3, LDO3), 249 - PM800_REGULATOR_OF_MATCH(ldo4, LDO4), 250 - PM800_REGULATOR_OF_MATCH(ldo5, LDO5), 251 - PM800_REGULATOR_OF_MATCH(ldo6, LDO6), 252 - PM800_REGULATOR_OF_MATCH(ldo7, LDO7), 253 - PM800_REGULATOR_OF_MATCH(ldo8, LDO8), 254 - PM800_REGULATOR_OF_MATCH(ldo9, LDO9), 255 - PM800_REGULATOR_OF_MATCH(ldo10, LDO10), 256 - PM800_REGULATOR_OF_MATCH(ldo11, LDO11), 257 - PM800_REGULATOR_OF_MATCH(ldo12, LDO12), 258 - PM800_REGULATOR_OF_MATCH(ldo13, LDO13), 259 - PM800_REGULATOR_OF_MATCH(ldo14, LDO14), 260 - PM800_REGULATOR_OF_MATCH(ldo15, LDO15), 261 - PM800_REGULATOR_OF_MATCH(ldo16, LDO16), 262 - PM800_REGULATOR_OF_MATCH(ldo17, LDO17), 263 - PM800_REGULATOR_OF_MATCH(ldo18, LDO18), 264 - PM800_REGULATOR_OF_MATCH(ldo19, LDO19), 265 - }; 266 - 267 - static int pm800_regulator_dt_init(struct platform_device *pdev) 268 - { 269 - struct device_node *np = pdev->dev.of_node; 270 - int ret; 271 - 272 - ret = of_regulator_match(&pdev->dev, np, 273 - pm800_regulator_matches, 274 - ARRAY_SIZE(pm800_regulator_matches)); 275 - if (ret < 0) 276 - return ret; 277 - 278 - return 0; 279 - } 280 229 281 230 static int pm800_regulator_probe(struct platform_device *pdev) 282 231 { 283 232 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); 284 233 struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); 285 234 struct pm800_regulators *pm800_data; 286 - struct pm800_regulator_info *info; 287 235 struct regulator_config config = { }; 288 236 struct regulator_init_data *init_data; 289 237 int i, ret; 290 238 291 - if (!pdata || pdata->num_regulators == 0) { 292 - if (IS_ENABLED(CONFIG_OF)) { 293 - ret = pm800_regulator_dt_init(pdev); 294 - if (ret) 295 - return ret; 296 - } else { 297 - return -ENODEV; 298 - } 299 - } else if (pdata->num_regulators) { 239 + if (pdata && pdata->num_regulators) { 300 240 unsigned int count = 0; 301 241 302 242 /* Check whether num_regulator is valid. */ ··· 250 302 } 251 303 if (count != pdata->num_regulators) 252 304 return -EINVAL; 253 - } else { 254 - return -EINVAL; 255 305 } 256 306 257 307 pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), ··· 262 316 263 317 platform_set_drvdata(pdev, pm800_data); 264 318 319 + config.dev = chip->dev; 320 + config.regmap = pm800_data->map; 265 321 for (i = 0; i < PM800_ID_RG_MAX; i++) { 266 322 struct regulator_dev *regulator; 267 323 268 - if (!pdata || pdata->num_regulators == 0) 269 - init_data = pm800_regulator_matches[i].init_data; 270 - else 324 + if (pdata && pdata->num_regulators) { 271 325 init_data = pdata->regulators[i]; 272 - if (!init_data) 273 - continue; 274 - info = pm800_regulator_matches[i].driver_data; 275 - config.dev = &pdev->dev; 276 - config.init_data = init_data; 277 - config.driver_data = info; 278 - config.regmap = pm800_data->map; 279 - config.of_node = pm800_regulator_matches[i].of_node; 326 + if (!init_data) 327 + continue; 328 + 329 + config.init_data = init_data; 330 + } 331 + 332 + config.driver_data = &pm800_regulator_info[i]; 280 333 281 334 regulator = devm_regulator_register(&pdev->dev, 282 - &info->desc, &config); 335 + &pm800_regulator_info[i].desc, &config); 283 336 if (IS_ERR(regulator)) { 284 337 ret = PTR_ERR(regulator); 285 338 dev_err(&pdev->dev, "Failed to register %s\n", 286 - info->desc.name); 339 + pm800_regulator_info[i].desc.name); 287 340 return ret; 288 341 } 289 342 }