aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiko Stuebner <heiko@sntech.de>2014-09-16 15:22:53 -0400
committerMark Brown <broonie@kernel.org>2014-09-16 19:09:31 -0400
commit91f23d8fb67c90a50676e4db9260a21647ef753f (patch)
tree9291ab0322625c34576b2e474253fb6f954433d2
parented801b4046beead31cb83e78a5758497c0a6c3a6 (diff)
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>
-rw-r--r--drivers/regulator/fan53555.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 5808435cfae0..fa29ba052841 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -18,6 +18,8 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
20#include <linux/regulator/machine.h> 20#include <linux/regulator/machine.h>
21#include <linux/regulator/of_regulator.h>
22#include <linux/of_device.h>
21#include <linux/i2c.h> 23#include <linux/i2c.h>
22#include <linux/slab.h> 24#include <linux/slab.h>
23#include <linux/regmap.h> 25#include <linux/regmap.h>
@@ -252,9 +254,39 @@ static struct regmap_config fan53555_regmap_config = {
252 .val_bits = 8, 254 .val_bits = 8,
253}; 255};
254 256
257static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
258 struct device_node *np)
259{
260 struct fan53555_platform_data *pdata;
261 int ret;
262 u32 tmp;
263
264 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
265 if (!pdata)
266 return NULL;
267
268 pdata->regulator = of_get_regulator_init_data(dev, np);
269
270 ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
271 &tmp);
272 if (!ret)
273 pdata->sleep_vsel_id = tmp;
274
275 return pdata;
276}
277
278static const struct of_device_id fan53555_dt_ids[] = {
279 {
280 .compatible = "fcs,fan53555",
281 },
282 { }
283};
284MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
285
255static int fan53555_regulator_probe(struct i2c_client *client, 286static int fan53555_regulator_probe(struct i2c_client *client,
256 const struct i2c_device_id *id) 287 const struct i2c_device_id *id)
257{ 288{
289 struct device_node *np = client->dev.of_node;
258 struct fan53555_device_info *di; 290 struct fan53555_device_info *di;
259 struct fan53555_platform_data *pdata; 291 struct fan53555_platform_data *pdata;
260 struct regulator_config config = { }; 292 struct regulator_config config = { };
@@ -262,6 +294,9 @@ static int fan53555_regulator_probe(struct i2c_client *client,
262 int ret; 294 int ret;
263 295
264 pdata = dev_get_platdata(&client->dev); 296 pdata = dev_get_platdata(&client->dev);
297 if (!pdata)
298 pdata = fan53555_parse_dt(&client->dev, np);
299
265 if (!pdata || !pdata->regulator) { 300 if (!pdata || !pdata->regulator) {
266 dev_err(&client->dev, "Platform data not found!\n"); 301 dev_err(&client->dev, "Platform data not found!\n");
267 return -ENODEV; 302 return -ENODEV;
@@ -272,11 +307,15 @@ static int fan53555_regulator_probe(struct i2c_client *client,
272 if (!di) 307 if (!di)
273 return -ENOMEM; 308 return -ENOMEM;
274 309
275 /* if no ramp constraint set, get the pdata ramp_delay */ 310 if (!client->dev.of_node) {
276 if (!di->regulator->constraints.ramp_delay) { 311 /* if no ramp constraint set, get the pdata ramp_delay */
277 int slew_idx = (pdata->slew_rate & 0x7) ? pdata->slew_rate : 0; 312 if (!di->regulator->constraints.ramp_delay) {
313 int slew_idx = (pdata->slew_rate & 0x7)
314 ? pdata->slew_rate : 0;
278 315
279 di->regulator->constraints.ramp_delay = slew_rates[slew_idx]; 316 di->regulator->constraints.ramp_delay
317 = slew_rates[slew_idx];
318 }
280 } 319 }
281 320
282 di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); 321 di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
@@ -314,6 +353,8 @@ static int fan53555_regulator_probe(struct i2c_client *client,
314 config.init_data = di->regulator; 353 config.init_data = di->regulator;
315 config.regmap = di->regmap; 354 config.regmap = di->regmap;
316 config.driver_data = di; 355 config.driver_data = di;
356 config.of_node = np;
357
317 ret = fan53555_regulator_register(di, &config); 358 ret = fan53555_regulator_register(di, &config);
318 if (ret < 0) 359 if (ret < 0)
319 dev_err(&client->dev, "Failed to register regulator!\n"); 360 dev_err(&client->dev, "Failed to register regulator!\n");
@@ -329,6 +370,7 @@ static const struct i2c_device_id fan53555_id[] = {
329static struct i2c_driver fan53555_regulator_driver = { 370static struct i2c_driver fan53555_regulator_driver = {
330 .driver = { 371 .driver = {
331 .name = "fan53555-regulator", 372 .name = "fan53555-regulator",
373 .of_match_table = of_match_ptr(fan53555_dt_ids),
332 }, 374 },
333 .probe = fan53555_regulator_probe, 375 .probe = fan53555_regulator_probe,
334 .id_table = fan53555_id, 376 .id_table = fan53555_id,