power_supply: tps65217-charger: Add support for IRQs

Make use of IRQ resources defined in tps65217 mfd code. If they are valid
we use them instead separate poll task, in order to define AC power state.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
This commit is contained in:
Marcin Niestroj 2016-06-20 12:50:54 +02:00 committed by Sebastian Reichel
parent f333253246
commit 47d7d5ed68

View File

@ -46,6 +46,8 @@ struct tps65217_charger {
int prev_ac_online;
struct task_struct *poll_task;
int irq;
};
static enum power_supply_property tps65217_ac_props[] = {
@ -198,6 +200,7 @@ static int tps65217_charger_probe(struct platform_device *pdev)
struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
struct tps65217_charger *charger;
struct power_supply_config cfg = {};
int irq;
int ret;
dev_dbg(&pdev->dev, "%s\n", __func__);
@ -220,18 +223,40 @@ static int tps65217_charger_probe(struct platform_device *pdev)
return PTR_ERR(charger->ac);
}
irq = platform_get_irq_byname(pdev, "AC");
if (irq < 0)
irq = -ENXIO;
charger->irq = irq;
ret = tps65217_config_charger(charger);
if (ret < 0) {
dev_err(charger->dev, "charger config failed, err %d\n", ret);
return ret;
}
charger->poll_task = kthread_run(tps65217_charger_poll_task,
charger, "ktps65217charger");
if (IS_ERR(charger->poll_task)) {
ret = PTR_ERR(charger->poll_task);
dev_err(charger->dev, "Unable to run kthread err %d\n", ret);
return ret;
if (irq != -ENXIO) {
ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
tps65217_charger_irq,
0, "tps65217-charger",
charger);
if (ret) {
dev_err(charger->dev,
"Unable to register irq %d err %d\n", irq,
ret);
return ret;
}
/* Check current state */
tps65217_charger_irq(irq, charger);
} else {
charger->poll_task = kthread_run(tps65217_charger_poll_task,
charger, "ktps65217charger");
if (IS_ERR(charger->poll_task)) {
ret = PTR_ERR(charger->poll_task);
dev_err(charger->dev,
"Unable to run kthread err %d\n", ret);
return ret;
}
}
return 0;
@ -241,7 +266,8 @@ static int tps65217_charger_remove(struct platform_device *pdev)
{
struct tps65217_charger *charger = platform_get_drvdata(pdev);
kthread_stop(charger->poll_task);
if (charger->irq == -ENXIO)
kthread_stop(charger->poll_task);
return 0;
}