From patchwork Fri Jun 24 07:17:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 9196823 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 7DD0960871 for ; Fri, 24 Jun 2016 07:29:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F36F2848B for ; Fri, 24 Jun 2016 07:29:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6357228491; Fri, 24 Jun 2016 07:29:30 +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=ham 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 C24902848B for ; Fri, 24 Jun 2016 07:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751040AbcFXH32 (ORCPT ); Fri, 24 Jun 2016 03:29:28 -0400 Received: from eusmtp01.atmel.com ([212.144.249.243]:35609 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750963AbcFXH31 (ORCPT ); Fri, 24 Jun 2016 03:29:27 -0400 Received: from apsmtp01.atmel.com (10.168.254.30) by eusmtp01.atmel.com (10.161.101.31) with Microsoft SMTP Server id 14.3.235.1; Fri, 24 Jun 2016 09:29:20 +0200 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.corp.atmel.com (10.168.254.30) with Microsoft SMTP Server id 14.3.235.1; Fri, 24 Jun 2016 15:34:31 +0800 From: Wenyou Yang To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Rob Herring , Pawel Moll , Mark Brown , Ian Campbell , "Kumar Gala" CC: , , , Nicolas Ferre , , Wenyou Yang Subject: [PATCH 3/7] power: act8945a_charger: Add status change update support Date: Fri, 24 Jun 2016 15:17:36 +0800 Message-ID: <1466752660-2922-4-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466752660-2922-1-git-send-email-wenyou.yang@atmel.com> References: <1466752660-2922-1-git-send-email-wenyou.yang@atmel.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the charger status change interrupt support, it will report the power supply changed event. This interrupt is generated by one of the conditions as below: - the state machine jumps out of or into the EOC state - the CHGIN input voltage goes out of or into the valid range. - the battery temperature goes out of or into the valid range. - the PRECHARGE time-out occurs. - the total charge time-out occurs. Signed-off-by: Wenyou Yang --- drivers/power/act8945a_charger.c | 79 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/drivers/power/act8945a_charger.c b/drivers/power/act8945a_charger.c index 939f1bb..0c61b28 100644 --- a/drivers/power/act8945a_charger.c +++ b/drivers/power/act8945a_charger.c @@ -10,6 +10,7 @@ * published by the Free Software Foundation. * */ +#include #include #include #include @@ -75,7 +76,12 @@ static const char *act8945a_charger_manufacturer = "Active-semi"; #define APCH_STATE_CSTATE_PRE 0x03 struct act8945a_charger { + struct power_supply *psy; struct regmap *regmap; + struct work_struct work; + + bool init_done; + int irq_pin; }; static int act8945a_get_charger_state(struct regmap *regmap, int *val) @@ -252,6 +258,47 @@ static const struct power_supply_desc act8945a_charger_desc = { .num_properties = ARRAY_SIZE(act8945a_charger_props), }; +static int act8945a_enable_interrupt(struct act8945a_charger *charger) +{ + struct regmap *regmap = charger->regmap; + unsigned char ctrl; + int ret; + + ctrl = APCH_CTRL_CHGEOCOUT | APCH_CTRL_CHGEOCIN | + APCH_CTRL_INDIS | APCH_CTRL_INCON | + APCH_CTRL_TEMPOUT | APCH_CTRL_TEMPIN | + APCH_CTRL_TIMRPRE | APCH_CTRL_TIMRTOT; + ret = regmap_write(regmap, ACT8945A_APCH_CTRL, ctrl); + if (ret) + return ret; + + ctrl = APCH_STATUS_CHGSTAT | APCH_STATUS_INSTAT | + APCH_STATUS_TEMPSTAT | APCH_STATUS_TIMRSTAT; + ret = regmap_write(regmap, ACT8945A_APCH_STATUS, ctrl); + if (ret) + return ret; + + return 0; +} + +static void act8945a_work(struct work_struct *work) +{ + struct act8945a_charger *charger = + container_of(work, struct act8945a_charger, work); + + power_supply_changed(charger->psy); +} + +static irqreturn_t act8945a_status_changed(int irq, void *dev_id) +{ + struct act8945a_charger *charger = dev_id; + + if (charger->init_done) + schedule_work(&charger->work); + + return IRQ_HANDLED; +} + #define DEFAULT_TOTAL_TIME_OUT 3 #define DEFAULT_PRE_TIME_OUT 40 #define DEFAULT_INPUT_OVP_THRESHOLD 6600 @@ -267,6 +314,7 @@ static int act8945a_charger_config(struct device *dev, u32 pre_time_out; u32 input_voltage_threshold; int chglev_pin; + int ret; unsigned int tmp; unsigned int value = 0; @@ -282,6 +330,18 @@ static int act8945a_charger_config(struct device *dev, if (tmp & APCH_CFG_SUSCHG) value |= APCH_CFG_SUSCHG; + charger->irq_pin = of_get_named_gpio(np, "active-semi,irq_gpios", 0); + if (gpio_is_valid(charger->irq_pin)) { + if (!devm_gpio_request(dev, charger->irq_pin, "irq-pin")) { + ret = devm_request_irq(dev, + gpio_to_irq(charger->irq_pin), + act8945a_status_changed, + IRQF_TRIGGER_FALLING, + "irq-pin", charger); + if (ret) + dev_dbg(dev, "failed to request nIRQ pin IRQ\n"); + } + } chglev_pin = of_get_named_gpio_flags(np, "active-semi,chglev-gpios", 0, &flags); @@ -359,7 +419,6 @@ static int act8945a_charger_config(struct device *dev, static int act8945a_charger_probe(struct platform_device *pdev) { struct act8945a_charger *charger; - struct power_supply *psy; struct power_supply_config psy_cfg = {}; int ret; @@ -380,14 +439,22 @@ static int act8945a_charger_probe(struct platform_device *pdev) psy_cfg.of_node = pdev->dev.parent->of_node; psy_cfg.drv_data = charger; - psy = devm_power_supply_register(&pdev->dev, - &act8945a_charger_desc, - &psy_cfg); - if (IS_ERR(psy)) { + charger->psy = devm_power_supply_register(&pdev->dev, + &act8945a_charger_desc, + &psy_cfg); + if (IS_ERR(charger->psy)) { dev_err(&pdev->dev, "failed to register power supply\n"); - return PTR_ERR(psy); + return PTR_ERR(charger->psy); } + INIT_WORK(&charger->work, act8945a_work); + + ret = act8945a_enable_interrupt(charger); + if (ret) + return -EIO; + + charger->init_done = true; + return 0; }