From 8b61a28d616a34beaa425873acd37a8b12929455 Mon Sep 17 00:00:00 2001 From: Adam Thomson Date: Thu, 6 Feb 2014 18:03:13 +0000 Subject: regulator: da9055: Add DT support Signed-off-by: Adam Thomson Signed-off-by: Mark Brown --- drivers/regulator/da9055-regulator.c | 69 +++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'drivers/regulator/da9055-regulator.c') diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 7f340206d329..d90f785829c4 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -446,6 +448,9 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, struct da9055_regulator_info *info = regulator->info; int ret = 0; + if (!pdata) + return 0; + if (pdata->gpio_ren && pdata->gpio_ren[id]) { char name[18]; int gpio_mux = pdata->gpio_ren[id]; @@ -530,6 +535,59 @@ static inline struct da9055_regulator_info *find_regulator_info(int id) return NULL; } +#ifdef CONFIG_OF +static struct of_regulator_match da9055_reg_matches[] = { + { .name = "BUCK1", }, + { .name = "BUCK2", }, + { .name = "LDO1", }, + { .name = "LDO2", }, + { .name = "LDO3", }, + { .name = "LDO4", }, + { .name = "LDO5", }, + { .name = "LDO6", }, +}; + +static int da9055_regulator_dt_init(struct platform_device *pdev, + struct da9055_regulator *regulator, + struct regulator_config *config, + int regid) +{ + struct device_node *nproot, *np; + int ret; + + nproot = of_node_get(pdev->dev.parent->of_node); + if (!nproot) + return -ENODEV; + + np = of_find_node_by_name(nproot, "regulators"); + if (!np) + return -ENODEV; + + ret = of_regulator_match(&pdev->dev, np, &da9055_reg_matches[regid], 1); + of_node_put(nproot); + if (ret < 0) { + dev_err(&pdev->dev, "Error matching regulator: %d\n", ret); + return -ENODEV; + } + + config->init_data = da9055_reg_matches[regid].init_data; + config->of_node = da9055_reg_matches[regid].of_node; + + if (!config->of_node) + return -ENODEV; + + return 0; +} +#else +static inline da9055_regulator_dt_init(struct platform_device *pdev, + struct da9055_regulator *regulator, + struct regulator_config *config, + int regid) +{ + return -ENODEV; +} +#endif /* CONFIG_OF */ + static int da9055_regulator_probe(struct platform_device *pdev) { struct regulator_config config = { }; @@ -538,9 +596,6 @@ static int da9055_regulator_probe(struct platform_device *pdev) struct da9055_pdata *pdata = dev_get_platdata(da9055->dev); int ret, irq; - if (pdata == NULL || pdata->regulators[pdev->id] == NULL) - return -ENODEV; - regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator), GFP_KERNEL); if (!regulator) @@ -557,8 +612,14 @@ static int da9055_regulator_probe(struct platform_device *pdev) config.driver_data = regulator; config.regmap = da9055->regmap; - if (pdata && pdata->regulators) + if (pdata && pdata->regulators) { config.init_data = pdata->regulators[pdev->id]; + } else { + ret = da9055_regulator_dt_init(pdev, regulator, &config, + pdev->id); + if (ret < 0) + return ret; + } ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); if (ret < 0) -- cgit v1.2.3 From dae6cdb422ba9708f152f313046dfc98a9336235 Mon Sep 17 00:00:00 2001 From: SeongJae Park Date: Wed, 12 Feb 2014 14:11:07 +0900 Subject: regulator: da9055: declare return type of inline function exclusively MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit da9055_regulator_dt_init does not declare return type and it cause following build warning. drivers/regulator/da9055-regulator.c:582:15: warning: return type defaults to ‘int’ [-Wreturn-type] static inline da9055_regulator_dt_init(struct platform_device *pdev, ^ Fix the warning by declare return type as int exclusively. Signed-off-by: SeongJae Park Signed-off-by: Mark Brown --- drivers/regulator/da9055-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator/da9055-regulator.c') diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index d90f785829c4..3f334ea23c95 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -579,7 +579,7 @@ static int da9055_regulator_dt_init(struct platform_device *pdev, return 0; } #else -static inline da9055_regulator_dt_init(struct platform_device *pdev, +static inline int da9055_regulator_dt_init(struct platform_device *pdev, struct da9055_regulator *regulator, struct regulator_config *config, int regid) -- cgit v1.2.3 From a4b4e66aadd05b1b8d2492ab914186359a11d0ec Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Fri, 14 Feb 2014 17:19:57 +0530 Subject: regulator: da9055: Use of_get_child_by_name of_find_node_by_name walks the allnodes list, and can thus walk outside of the parent node. Use of_get_child_by_name instead. Signed-off-by: Sachin Kamat Signed-off-by: Mark Brown --- drivers/regulator/da9055-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator/da9055-regulator.c') diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 3f334ea23c95..604a6f7c9cbf 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -559,7 +559,7 @@ static int da9055_regulator_dt_init(struct platform_device *pdev, if (!nproot) return -ENODEV; - np = of_find_node_by_name(nproot, "regulators"); + np = of_get_child_by_name(nproot, "regulators"); if (!np) return -ENODEV; -- cgit v1.2.3 From fe2eb7221870ed30da06a64ddc0eac0501eb615f Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 18 Feb 2014 16:11:06 +0530 Subject: regulator: da9055: Do not hardcode return value Propagate the error value returned by the function instead. Signed-off-by: Sachin Kamat Signed-off-by: Mark Brown --- drivers/regulator/da9055-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator/da9055-regulator.c') diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 604a6f7c9cbf..8812855f2b33 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -567,7 +567,7 @@ static int da9055_regulator_dt_init(struct platform_device *pdev, of_node_put(nproot); if (ret < 0) { dev_err(&pdev->dev, "Error matching regulator: %d\n", ret); - return -ENODEV; + return ret; } config->init_data = da9055_reg_matches[regid].init_data; -- cgit v1.2.3