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

regulator: fan53555: add devicetree support

Add the ability to parse regulator-data from the devicetree.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Heiko Stuebner and committed by
Mark Brown
91f23d8f ed801b40

+46 -4
+46 -4
drivers/regulator/fan53555.c
··· 18 18 #include <linux/platform_device.h> 19 19 #include <linux/regulator/driver.h> 20 20 #include <linux/regulator/machine.h> 21 + #include <linux/regulator/of_regulator.h> 22 + #include <linux/of_device.h> 21 23 #include <linux/i2c.h> 22 24 #include <linux/slab.h> 23 25 #include <linux/regmap.h> ··· 254 252 .val_bits = 8, 255 253 }; 256 254 255 + static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, 256 + struct device_node *np) 257 + { 258 + struct fan53555_platform_data *pdata; 259 + int ret; 260 + u32 tmp; 261 + 262 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 263 + if (!pdata) 264 + return NULL; 265 + 266 + pdata->regulator = of_get_regulator_init_data(dev, np); 267 + 268 + ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", 269 + &tmp); 270 + if (!ret) 271 + pdata->sleep_vsel_id = tmp; 272 + 273 + return pdata; 274 + } 275 + 276 + static const struct of_device_id fan53555_dt_ids[] = { 277 + { 278 + .compatible = "fcs,fan53555", 279 + }, 280 + { } 281 + }; 282 + MODULE_DEVICE_TABLE(of, fan53555_dt_ids); 283 + 257 284 static int fan53555_regulator_probe(struct i2c_client *client, 258 285 const struct i2c_device_id *id) 259 286 { 287 + struct device_node *np = client->dev.of_node; 260 288 struct fan53555_device_info *di; 261 289 struct fan53555_platform_data *pdata; 262 290 struct regulator_config config = { }; ··· 294 262 int ret; 295 263 296 264 pdata = dev_get_platdata(&client->dev); 265 + if (!pdata) 266 + pdata = fan53555_parse_dt(&client->dev, np); 267 + 297 268 if (!pdata || !pdata->regulator) { 298 269 dev_err(&client->dev, "Platform data not found!\n"); 299 270 return -ENODEV; ··· 307 272 if (!di) 308 273 return -ENOMEM; 309 274 310 - /* if no ramp constraint set, get the pdata ramp_delay */ 311 - if (!di->regulator->constraints.ramp_delay) { 312 - int slew_idx = (pdata->slew_rate & 0x7) ? pdata->slew_rate : 0; 275 + if (!client->dev.of_node) { 276 + /* if no ramp constraint set, get the pdata ramp_delay */ 277 + if (!di->regulator->constraints.ramp_delay) { 278 + int slew_idx = (pdata->slew_rate & 0x7) 279 + ? pdata->slew_rate : 0; 313 280 314 - di->regulator->constraints.ramp_delay = slew_rates[slew_idx]; 281 + di->regulator->constraints.ramp_delay 282 + = slew_rates[slew_idx]; 283 + } 315 284 } 316 285 317 286 di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); ··· 353 314 config.init_data = di->regulator; 354 315 config.regmap = di->regmap; 355 316 config.driver_data = di; 317 + config.of_node = np; 318 + 356 319 ret = fan53555_regulator_register(di, &config); 357 320 if (ret < 0) 358 321 dev_err(&client->dev, "Failed to register regulator!\n"); ··· 370 329 static struct i2c_driver fan53555_regulator_driver = { 371 330 .driver = { 372 331 .name = "fan53555-regulator", 332 + .of_match_table = of_match_ptr(fan53555_dt_ids), 373 333 }, 374 334 .probe = fan53555_regulator_probe, 375 335 .id_table = fan53555_id,