diff options
| -rw-r--r-- | Documentation/devicetree/bindings/regulator/tps51632-regulator.txt | 27 | ||||
| -rw-r--r-- | drivers/regulator/tps51632-regulator.c | 59 |
2 files changed, 86 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/regulator/tps51632-regulator.txt b/Documentation/devicetree/bindings/regulator/tps51632-regulator.txt new file mode 100644 index 000000000000..2f7e44a96414 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/tps51632-regulator.txt | |||
| @@ -0,0 +1,27 @@ | |||
| 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 | }; | ||
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c index b96fb0e15a82..7560d0768b77 100644 --- a/drivers/regulator/tps51632-regulator.c +++ b/drivers/regulator/tps51632-regulator.c | |||
| @@ -28,10 +28,13 @@ | |||
| 28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
| 29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
| 31 | #include <linux/of.h> | ||
| 32 | #include <linux/of_device.h> | ||
| 31 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
| 32 | #include <linux/regmap.h> | 34 | #include <linux/regmap.h> |
| 33 | #include <linux/regulator/driver.h> | 35 | #include <linux/regulator/driver.h> |
| 34 | #include <linux/regulator/machine.h> | 36 | #include <linux/regulator/machine.h> |
| 37 | #include <linux/regulator/of_regulator.h> | ||
| 35 | #include <linux/regulator/tps51632-regulator.h> | 38 | #include <linux/regulator/tps51632-regulator.h> |
| 36 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
| 37 | 40 | ||
| @@ -252,6 +255,49 @@ static const struct regmap_config tps51632_regmap_config = { | |||
| 252 | .cache_type = REGCACHE_RBTREE, | 255 | .cache_type = REGCACHE_RBTREE, |
| 253 | }; | 256 | }; |
| 254 | 257 | ||
| 258 | #if defined(CONFIG_OF) | ||
| 259 | static const struct of_device_id tps51632_of_match[] = { | ||
| 260 | { .compatible = "ti,tps51632",}, | ||
| 261 | {}, | ||
| 262 | }; | ||
| 263 | MODULE_DEVICE_TABLE(of, tps51632_of_match); | ||
| 264 | |||
| 265 | static struct tps51632_regulator_platform_data * | ||
| 266 | of_get_tps51632_platform_data(struct device *dev) | ||
| 267 | { | ||
| 268 | struct tps51632_regulator_platform_data *pdata; | ||
| 269 | struct device_node *np = dev->of_node; | ||
| 270 | |||
| 271 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 272 | if (!pdata) { | ||
| 273 | dev_err(dev, "Memory alloc failed for platform data\n"); | ||
| 274 | return NULL; | ||
| 275 | } | ||
| 276 | |||
| 277 | pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); | ||
| 278 | if (!pdata->reg_init_data) { | ||
| 279 | dev_err(dev, "Not able to get OF regulator init data\n"); | ||
| 280 | return NULL; | ||
| 281 | } | ||
| 282 | |||
| 283 | pdata->enable_pwm_dvfs = | ||
| 284 | of_property_read_bool(np, "ti,enable-pwm-dvfs"); | ||
| 285 | pdata->dvfs_step_20mV = of_property_read_bool(np, "ti,dvfs-step-20mV"); | ||
| 286 | |||
| 287 | pdata->base_voltage_uV = pdata->reg_init_data->constraints.min_uV ? : | ||
| 288 | TPS51632_MIN_VOLATGE; | ||
| 289 | pdata->max_voltage_uV = pdata->reg_init_data->constraints.max_uV ? : | ||
| 290 | TPS51632_MAX_VOLATGE; | ||
| 291 | return pdata; | ||
| 292 | } | ||
| 293 | #else | ||
| 294 | static struct tps51632_regulator_platform_data * | ||
| 295 | of_get_tps51632_platform_data(struct device *dev) | ||
| 296 | { | ||
| 297 | return NULL; | ||
| 298 | } | ||
| 299 | #endif | ||
| 300 | |||
| 255 | static int tps51632_probe(struct i2c_client *client, | 301 | static int tps51632_probe(struct i2c_client *client, |
| 256 | const struct i2c_device_id *id) | 302 | const struct i2c_device_id *id) |
| 257 | { | 303 | { |
| @@ -261,7 +307,19 @@ static int tps51632_probe(struct i2c_client *client, | |||
| 261 | int ret; | 307 | int ret; |
| 262 | struct regulator_config config = { }; | 308 | struct regulator_config config = { }; |
| 263 | 309 | ||
| 310 | if (client->dev.of_node) { | ||
| 311 | const struct of_device_id *match; | ||
| 312 | match = of_match_device(of_match_ptr(tps51632_of_match), | ||
| 313 | &client->dev); | ||
| 314 | if (!match) { | ||
| 315 | dev_err(&client->dev, "Error: No device match found\n"); | ||
| 316 | return -ENODEV; | ||
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 264 | pdata = client->dev.platform_data; | 320 | pdata = client->dev.platform_data; |
| 321 | if (!pdata && client->dev.of_node) | ||
| 322 | pdata = of_get_tps51632_platform_data(&client->dev); | ||
| 265 | if (!pdata) { | 323 | if (!pdata) { |
| 266 | dev_err(&client->dev, "No Platform data\n"); | 324 | dev_err(&client->dev, "No Platform data\n"); |
| 267 | return -EINVAL; | 325 | return -EINVAL; |
| @@ -350,6 +408,7 @@ static struct i2c_driver tps51632_i2c_driver = { | |||
| 350 | .driver = { | 408 | .driver = { |
| 351 | .name = "tps51632", | 409 | .name = "tps51632", |
| 352 | .owner = THIS_MODULE, | 410 | .owner = THIS_MODULE, |
| 411 | .of_match_table = of_match_ptr(tps51632_of_match), | ||
| 353 | }, | 412 | }, |
| 354 | .probe = tps51632_probe, | 413 | .probe = tps51632_probe, |
| 355 | .remove = tps51632_remove, | 414 | .remove = tps51632_remove, |
