From patchwork Mon Jun 20 10:50:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Niestroj X-Patchwork-Id: 9187131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F9AF607D1 for ; Mon, 20 Jun 2016 10:53:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B05D22B26 for ; Mon, 20 Jun 2016 10:53:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DB072684F; Mon, 20 Jun 2016 10:53:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3CD522B26 for ; Mon, 20 Jun 2016 10:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753679AbcFTKxB (ORCPT ); Mon, 20 Jun 2016 06:53:01 -0400 Received: from 2780.rev.megiteam.pl ([91.227.39.128]:35049 "EHLO vk1046.megiteam.com.pl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752815AbcFTKw7 (ORCPT ); Mon, 20 Jun 2016 06:52:59 -0400 Received: from localhost.localdomain (unknown [95.143.241.142]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: marcin.niestroj@grinn-global.com) by vk1046.megiteam.com.pl (Postfix) with ESMTP id 753C46251CD1; Mon, 20 Jun 2016 12:53:03 +0200 (CEST) From: Marcin Niestroj To: Lee Jones Cc: Tony Lindgren , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Rob Herring , Pawel Moll , linux-omap@vger.kernel.org, linux-pm@vger.kernel.org, linux-input@vger.kernel.org, devicetree@vger.kernel.org, Grygorii Strashko , Marcin Niestroj Subject: [PATCH v4 3/5] power_supply: tps65217-charger: Add support for IRQs Date: Mon, 20 Jun 2016 12:50:54 +0200 Message-Id: <20160620105056.25843-4-m.niestroj@grinn-global.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160620105056.25843-1-m.niestroj@grinn-global.com> References: <20160620105056.25843-1-m.niestroj@grinn-global.com> X-Virus-Scanned: by amavisd-new Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Depends on patch 1 and 2 in series Changes v1 -> v4: none drivers/power/tps65217_charger.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/power/tps65217_charger.c b/drivers/power/tps65217_charger.c index 73dfae4..c8c4a0c 100644 --- a/drivers/power/tps65217_charger.c +++ b/drivers/power/tps65217_charger.c @@ -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; }