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

regulator: tps51632: add DT support

Add DT support for the TI TPS51632. Add device binding document also.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Laxman Dewangan and committed by
Mark Brown
c51ce403 faa3b2d5

+86
+27
Documentation/devicetree/bindings/regulator/tps51632-regulator.txt
··· 1 + TPS51632 Voltage regulators 2 + 3 + Required properties: 4 + - compatible: Must be "ti,tps51632" 5 + - reg: I2C slave address 6 + 7 + Optional properties: 8 + - ti,enable-pwm-dvfs: Enable the DVFS voltage control through the PWM interface. 9 + - ti,dvfs-step-20mV: The 20mV step voltage when PWM DVFS enabled. Missing this 10 + will set 10mV step voltage in PWM DVFS mode. In normal mode, the voltage 11 + step is 10mV as per datasheet. 12 + 13 + Any property defined as part of the core regulator binding, defined in 14 + regulator.txt, can also be used. 15 + 16 + Example: 17 + 18 + tps51632 { 19 + compatible = "ti,tps51632"; 20 + reg = <0x43>; 21 + regulator-name = "tps51632-vout"; 22 + regulator-min-microvolt = <500000>; 23 + regulator-max-microvolt = <1500000>; 24 + regulator-boot-on; 25 + ti,enable-pwm-dvfs; 26 + ti,dvfs-step-20mV; 27 + };
+59
drivers/regulator/tps51632-regulator.c
··· 28 28 #include <linux/init.h> 29 29 #include <linux/kernel.h> 30 30 #include <linux/module.h> 31 + #include <linux/of.h> 32 + #include <linux/of_device.h> 31 33 #include <linux/platform_device.h> 32 34 #include <linux/regmap.h> 33 35 #include <linux/regulator/driver.h> 34 36 #include <linux/regulator/machine.h> 37 + #include <linux/regulator/of_regulator.h> 35 38 #include <linux/regulator/tps51632-regulator.h> 36 39 #include <linux/slab.h> 37 40 ··· 255 252 .cache_type = REGCACHE_RBTREE, 256 253 }; 257 254 255 + #if defined(CONFIG_OF) 256 + static const struct of_device_id tps51632_of_match[] = { 257 + { .compatible = "ti,tps51632",}, 258 + {}, 259 + }; 260 + MODULE_DEVICE_TABLE(of, tps51632_of_match); 261 + 262 + static struct tps51632_regulator_platform_data * 263 + of_get_tps51632_platform_data(struct device *dev) 264 + { 265 + struct tps51632_regulator_platform_data *pdata; 266 + struct device_node *np = dev->of_node; 267 + 268 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 269 + if (!pdata) { 270 + dev_err(dev, "Memory alloc failed for platform data\n"); 271 + return NULL; 272 + } 273 + 274 + pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); 275 + if (!pdata->reg_init_data) { 276 + dev_err(dev, "Not able to get OF regulator init data\n"); 277 + return NULL; 278 + } 279 + 280 + pdata->enable_pwm_dvfs = 281 + of_property_read_bool(np, "ti,enable-pwm-dvfs"); 282 + pdata->dvfs_step_20mV = of_property_read_bool(np, "ti,dvfs-step-20mV"); 283 + 284 + pdata->base_voltage_uV = pdata->reg_init_data->constraints.min_uV ? : 285 + TPS51632_MIN_VOLATGE; 286 + pdata->max_voltage_uV = pdata->reg_init_data->constraints.max_uV ? : 287 + TPS51632_MAX_VOLATGE; 288 + return pdata; 289 + } 290 + #else 291 + static struct tps51632_regulator_platform_data * 292 + of_get_tps51632_platform_data(struct device *dev) 293 + { 294 + return NULL; 295 + } 296 + #endif 297 + 258 298 static int tps51632_probe(struct i2c_client *client, 259 299 const struct i2c_device_id *id) 260 300 { ··· 307 261 int ret; 308 262 struct regulator_config config = { }; 309 263 264 + if (client->dev.of_node) { 265 + const struct of_device_id *match; 266 + match = of_match_device(of_match_ptr(tps51632_of_match), 267 + &client->dev); 268 + if (!match) { 269 + dev_err(&client->dev, "Error: No device match found\n"); 270 + return -ENODEV; 271 + } 272 + } 273 + 310 274 pdata = client->dev.platform_data; 275 + if (!pdata && client->dev.of_node) 276 + pdata = of_get_tps51632_platform_data(&client->dev); 311 277 if (!pdata) { 312 278 dev_err(&client->dev, "No Platform data\n"); 313 279 return -EINVAL; ··· 408 350 .driver = { 409 351 .name = "tps51632", 410 352 .owner = THIS_MODULE, 353 + .of_match_table = of_match_ptr(tps51632_of_match), 411 354 }, 412 355 .probe = tps51632_probe, 413 356 .remove = tps51632_remove,