diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2012-12-25 10:06:00 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-12-27 12:30:45 -0500 |
commit | c51ce403d3d9e3d54339c4563f17e958f3bc64df (patch) | |
tree | 20210892c43f47e9b86e5f6dbc0e1249832691db /drivers/regulator | |
parent | faa3b2d57964e3c3e974e1d0bea8e047bd8e5edd (diff) |
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>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/tps51632-regulator.c | 59 |
1 files changed, 59 insertions, 0 deletions
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, |