diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2014-03-26 15:53:34 +0530 |
---|---|---|
committer | Laxman Dewangan <ldewangan@nvidia.com> | 2014-03-26 09:46:11 -0700 |
commit | 4ef0179cbbde22367b4c028d6b722c4bde52c6ec (patch) | |
tree | 08cc187e8177c22773661978ee2e84b83ebce35e /drivers/power/power_supply_extcon.c | |
parent | 7ec650cac30c1244b217c4036553aafd1d535d92 (diff) |
power: power_supply_extcon: add dt support
Add DT support for the power_supply-extcon driver
Added DT binding documents also.
Change-Id: Id7d612032cac82eecadae6c24a3c1e0c82b60a27
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/387063
Diffstat (limited to 'drivers/power/power_supply_extcon.c')
-rw-r--r-- | drivers/power/power_supply_extcon.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/drivers/power/power_supply_extcon.c b/drivers/power/power_supply_extcon.c index 44e19d67df4a..1236738968b0 100644 --- a/drivers/power/power_supply_extcon.c +++ b/drivers/power/power_supply_extcon.c @@ -23,6 +23,8 @@ #include <linux/err.h> #include <linux/err.h> #include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/power_supply.h> #include <linux/power/power_supply_extcon.h> @@ -185,6 +187,25 @@ static int psy_extcon_extcon_notifier(struct notifier_block *self, return NOTIFY_DONE; } +static struct power_supply_extcon_plat_data *psy_extcon_get_dt_pdata( + struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct power_supply_extcon_plat_data *pdata; + char const *pstr; + int ret; + + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + ret = of_property_read_string(np, "power-supply,extcon-dev", &pstr); + if (!ret) + pdata->extcon_name = pstr; + + return pdata; +} + static int psy_extcon_probe(struct platform_device *pdev) { int ret = 0; @@ -192,6 +213,14 @@ static int psy_extcon_probe(struct platform_device *pdev) struct power_supply_extcon *psy_extcon; struct power_supply_extcon_plat_data *pdata = pdev->dev.platform_data; + if (!pdata && pdev->dev.of_node) { + pdata = psy_extcon_get_dt_pdata(pdev); + if (IS_ERR(pdata)) { + ret = PTR_ERR(pdata); + pdata = NULL; + } + } + if (!pdata) { dev_err(&pdev->dev, "No platform data, exiting..\n"); return -ENODEV; @@ -206,6 +235,8 @@ static int psy_extcon_probe(struct platform_device *pdev) psy_extcon->dev = &pdev->dev; dev_set_drvdata(&pdev->dev, psy_extcon); + dev_info(psy_extcon->dev, "Extcon name %s\n", pdata->extcon_name); + psy_extcon->ac.name = "ac"; psy_extcon->ac.type = POWER_SUPPLY_TYPE_MAINS; psy_extcon->ac.get_property = power_supply_extcon_get_property; @@ -247,13 +278,17 @@ static int psy_extcon_probe(struct platform_device *pdev) pdata->extcon_name, cable->name, &cable->nb); if (ret < 0) - dev_err(psy_extcon->dev, "Cannot register for cable: %s\n", - cable->name); + dev_err(psy_extcon->dev, + "Cable %s registration failed: %d\n", + cable->name, ret); } psy_extcon->edev = extcon_get_extcon_dev(pdata->extcon_name); - if (!psy_extcon->edev) - goto econ_err; + if (!psy_extcon->edev) { + dev_err(psy_extcon->dev, "No extcon device with %s\n", + pdata->extcon_name); + goto econ_err; + } power_supply_extcon_attach_cable(psy_extcon, psy_extcon->edev); dev_info(&pdev->dev, "%s() get success\n", __func__); @@ -275,14 +310,20 @@ static int psy_extcon_remove(struct platform_device *pdev) return 0; } +static struct of_device_id power_supply_extcon_of_match[] = { + { .compatible = "power-supply-extcon", }, + {}, +}; +MODULE_DEVICE_TABLE(of, power_supply_extcon_of_match); + static struct platform_driver power_supply_extcon_driver = { .driver = { .name = "power-supply-extcon", .owner = THIS_MODULE, + .of_match_table = power_supply_extcon_of_match, }, .probe = psy_extcon_probe, .remove = psy_extcon_remove, - }; static int __init psy_extcon_init(void) |