From patchwork Mon Apr 4 17:11:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Niestroj X-Patchwork-Id: 8743311 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 03FCA9F7C9 for ; Mon, 4 Apr 2016 17:17:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25F3E20154 for ; Mon, 4 Apr 2016 17:17:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1663320165 for ; Mon, 4 Apr 2016 17:17:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756230AbcDDRRb (ORCPT ); Mon, 4 Apr 2016 13:17:31 -0400 Received: from 2780.rev.megiteam.pl ([91.227.39.128]:33487 "EHLO vk1046.megiteam.com.pl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756002AbcDDRRZ (ORCPT ); Mon, 4 Apr 2016 13:17:25 -0400 Received: from gm.localdomain (unknown [95.143.241.142]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: marcin.niestroj@grinn-global.com) by vk1046.megiteam.com.pl (Postfix) with ESMTP id 52AF9622738A; Mon, 4 Apr 2016 19:11:33 +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, Marcin Niestroj Subject: [PATCH 3/5] power_supply: tps65217-charger: Add support for IRQs Date: Mon, 4 Apr 2016 19:11:03 +0200 Message-Id: <1459789865-3704-5-git-send-email-m.niestroj@grinn-global.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1459789865-3704-1-git-send-email-m.niestroj@grinn-global.com> References: <1459789865-3704-1-git-send-email-m.niestroj@grinn-global.com> X-Virus-Scanned: by amavisd-new Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 --- 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; }