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

regulator: as3711: add OF support

AS3711 regulator OF support only evaluates standard regulator DT
properties.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
Reviwed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Guennadi Liakhovetski and committed by
Mark Brown
416d6759 a937536b

+71 -3
+71 -3
drivers/regulator/as3711-regulator.c
··· 13 13 #include <linux/init.h> 14 14 #include <linux/mfd/as3711.h> 15 15 #include <linux/module.h> 16 + #include <linux/of.h> 16 17 #include <linux/platform_device.h> 17 18 #include <linux/regmap.h> 18 19 #include <linux/regulator/driver.h> 20 + #include <linux/regulator/of_regulator.h> 19 21 #include <linux/slab.h> 20 22 21 23 struct as3711_regulator_info { ··· 278 276 279 277 #define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_info) 280 278 279 + static const char *as3711_regulator_of_names[AS3711_REGULATOR_NUM] = { 280 + [AS3711_REGULATOR_SD_1] = "sd1", 281 + [AS3711_REGULATOR_SD_2] = "sd2", 282 + [AS3711_REGULATOR_SD_3] = "sd3", 283 + [AS3711_REGULATOR_SD_4] = "sd4", 284 + [AS3711_REGULATOR_LDO_1] = "ldo1", 285 + [AS3711_REGULATOR_LDO_2] = "ldo2", 286 + [AS3711_REGULATOR_LDO_3] = "ldo3", 287 + [AS3711_REGULATOR_LDO_4] = "ldo4", 288 + [AS3711_REGULATOR_LDO_5] = "ldo5", 289 + [AS3711_REGULATOR_LDO_6] = "ldo6", 290 + [AS3711_REGULATOR_LDO_7] = "ldo7", 291 + [AS3711_REGULATOR_LDO_8] = "ldo8", 292 + }; 293 + 294 + static int as3711_regulator_parse_dt(struct device *dev, 295 + struct device_node **of_node, const int count) 296 + { 297 + struct as3711_regulator_pdata *pdata = dev_get_platdata(dev); 298 + struct device_node *regulators = 299 + of_find_node_by_name(dev->parent->of_node, "regulators"); 300 + struct of_regulator_match *matches, *match; 301 + int ret, i; 302 + 303 + if (!regulators) { 304 + dev_err(dev, "regulator node not found\n"); 305 + return -ENODEV; 306 + } 307 + 308 + matches = devm_kzalloc(dev, sizeof(*matches) * count, GFP_KERNEL); 309 + if (!matches) 310 + return -ENOMEM; 311 + 312 + for (i = 0, match = matches; i < count; i++, match++) { 313 + match->name = as3711_regulator_of_names[i]; 314 + match->driver_data = as3711_reg_info + i; 315 + } 316 + 317 + ret = of_regulator_match(dev->parent, regulators, matches, count); 318 + of_node_put(regulators); 319 + if (ret < 0) { 320 + dev_err(dev, "Error parsing regulator init data: %d\n", ret); 321 + return ret; 322 + } 323 + 324 + for (i = 0, match = matches; i < count; i++, match++) 325 + if (match->of_node) { 326 + pdata->init_data[i] = match->init_data; 327 + of_node[i] = match->of_node; 328 + } 329 + 330 + return 0; 331 + } 332 + 281 333 static int as3711_regulator_probe(struct platform_device *pdev) 282 334 { 283 335 struct as3711_regulator_pdata *pdata = dev_get_platdata(&pdev->dev); ··· 340 284 struct regulator_config config = {.dev = &pdev->dev,}; 341 285 struct as3711_regulator *reg = NULL; 342 286 struct as3711_regulator *regs; 287 + struct device_node *of_node[AS3711_REGULATOR_NUM] = {}; 343 288 struct regulator_dev *rdev; 344 289 struct as3711_regulator_info *ri; 345 290 int ret; 346 291 int id; 347 292 348 - if (!pdata) 349 - dev_dbg(&pdev->dev, "No platform data...\n"); 293 + if (!pdata) { 294 + dev_err(&pdev->dev, "No platform data...\n"); 295 + return -ENODEV; 296 + } 297 + 298 + if (pdev->dev.parent->of_node) { 299 + ret = as3711_regulator_parse_dt(&pdev->dev, of_node, AS3711_REGULATOR_NUM); 300 + if (ret < 0) { 301 + dev_err(&pdev->dev, "DT parsing failed: %d\n", ret); 302 + return ret; 303 + } 304 + } 350 305 351 306 regs = devm_kzalloc(&pdev->dev, AS3711_REGULATOR_NUM * 352 307 sizeof(struct as3711_regulator), GFP_KERNEL); ··· 367 300 } 368 301 369 302 for (id = 0, ri = as3711_reg_info; id < AS3711_REGULATOR_NUM; ++id, ri++) { 370 - reg_data = pdata ? pdata->init_data[id] : NULL; 303 + reg_data = pdata->init_data[id]; 371 304 372 305 /* No need to register if there is no regulator data */ 373 306 if (!reg_data) ··· 379 312 config.init_data = reg_data; 380 313 config.driver_data = reg; 381 314 config.regmap = as3711->regmap; 315 + config.of_node = of_node[id]; 382 316 383 317 rdev = regulator_register(&ri->desc, &config); 384 318 if (IS_ERR(rdev)) {