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

regulator: arizona-ldo1: Factor out generic initialization

In preparation for sharing this driver with Madera codecs, factor out
the parts of initialization that aren't dependent on struct arizona.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Richard Fitzgerald and committed by
Mark Brown
af367afa 80a55f41

+67 -49
+67 -49
drivers/regulator/arizona-ldo1.c
··· 234 234 return 0; 235 235 } 236 236 237 + static int arizona_ldo1_common_init(struct platform_device *pdev, 238 + struct arizona_ldo1 *ldo1, 239 + const struct regulator_desc *desc, 240 + struct arizona_ldo1_pdata *pdata, 241 + bool *external_dcvdd) 242 + { 243 + struct device *parent_dev = pdev->dev.parent; 244 + struct regulator_config config = { }; 245 + int ret; 246 + 247 + *external_dcvdd = false; 248 + 249 + ldo1->supply.supply = "DCVDD"; 250 + ldo1->init_data.consumer_supplies = &ldo1->supply; 251 + ldo1->supply.dev_name = dev_name(parent_dev); 252 + 253 + config.dev = parent_dev; 254 + config.driver_data = ldo1; 255 + config.regmap = ldo1->regmap; 256 + 257 + if (IS_ENABLED(CONFIG_OF)) { 258 + if (!dev_get_platdata(parent_dev)) { 259 + ret = arizona_ldo1_of_get_pdata(pdata, 260 + &config, desc, 261 + external_dcvdd); 262 + if (ret < 0) 263 + return ret; 264 + } 265 + } 266 + 267 + config.ena_gpio = pdata->ldoena; 268 + 269 + if (pdata->init_data) 270 + config.init_data = pdata->init_data; 271 + else 272 + config.init_data = &ldo1->init_data; 273 + 274 + /* 275 + * LDO1 can only be used to supply DCVDD so if it has no 276 + * consumers then DCVDD is supplied externally. 277 + */ 278 + if (config.init_data->num_consumer_supplies == 0) 279 + *external_dcvdd = true; 280 + 281 + ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config); 282 + 283 + of_node_put(config.of_node); 284 + 285 + if (IS_ERR(ldo1->regulator)) { 286 + ret = PTR_ERR(ldo1->regulator); 287 + dev_err(&pdev->dev, "Failed to register LDO1 supply: %d\n", 288 + ret); 289 + return ret; 290 + } 291 + 292 + platform_set_drvdata(pdev, ldo1); 293 + 294 + return 0; 295 + } 296 + 237 297 static int arizona_ldo1_probe(struct platform_device *pdev) 238 298 { 239 299 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); 240 - const struct regulator_desc *desc; 241 - struct regulator_config config = { }; 242 300 struct arizona_ldo1 *ldo1; 243 - bool external_dcvdd = false; 301 + const struct regulator_desc *desc; 302 + bool external_dcvdd; 244 303 int ret; 245 304 246 305 ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); ··· 332 273 break; 333 274 } 334 275 335 - ldo1->init_data.consumer_supplies = &ldo1->supply; 336 - ldo1->supply.supply = "DCVDD"; 337 - ldo1->supply.dev_name = dev_name(arizona->dev); 338 - 339 - config.dev = arizona->dev; 340 - config.driver_data = ldo1; 341 - config.regmap = arizona->regmap; 342 - 343 - if (IS_ENABLED(CONFIG_OF)) { 344 - if (!dev_get_platdata(arizona->dev)) { 345 - ret = arizona_ldo1_of_get_pdata(&arizona->pdata.ldo1, 346 - &config, desc, 347 - &external_dcvdd); 348 - if (ret < 0) 349 - return ret; 350 - } 351 - } 352 - 353 - config.ena_gpio = arizona->pdata.ldo1.ldoena; 354 - 355 - if (arizona->pdata.ldo1.init_data) 356 - config.init_data = arizona->pdata.ldo1.init_data; 357 - else 358 - config.init_data = &ldo1->init_data; 359 - 360 - /* 361 - * LDO1 can only be used to supply DCVDD so if it has no 362 - * consumers then DCVDD is supplied externally. 363 - */ 364 - if (config.init_data->num_consumer_supplies == 0) 365 - arizona->external_dcvdd = true; 366 - else 276 + ret = arizona_ldo1_common_init(pdev, ldo1, desc, 277 + &arizona->pdata.ldo1, 278 + &external_dcvdd); 279 + if (ret == 0) 367 280 arizona->external_dcvdd = external_dcvdd; 368 281 369 - ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config); 370 - 371 - of_node_put(config.of_node); 372 - 373 - if (IS_ERR(ldo1->regulator)) { 374 - ret = PTR_ERR(ldo1->regulator); 375 - dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", 376 - ret); 377 - return ret; 378 - } 379 - 380 - platform_set_drvdata(pdev, ldo1); 381 - 382 - return 0; 282 + return ret; 383 283 } 384 284 385 285 static struct platform_driver arizona_ldo1_driver = {