From patchwork Fri Jul 29 01:25:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 9251883 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 1ECAF60757 for ; Fri, 29 Jul 2016 01:41:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F0AC27DE0 for ; Fri, 29 Jul 2016 01:41:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03CD727F85; Fri, 29 Jul 2016 01:41:23 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8AD1E27DE0 for ; Fri, 29 Jul 2016 01:41:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bSwmM-0002LR-LZ; Fri, 29 Jul 2016 01:39:58 +0000 Received: from nasmtp01.atmel.com ([192.199.1.245] helo=ussmtp01.atmel.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bSwmH-00024t-Ns for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2016 01:39:54 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by DVREDG01.corp.atmel.com (10.42.103.30) with Microsoft SMTP Server (TLS) id 14.3.235.1; Thu, 28 Jul 2016 19:39:25 -0600 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.3.235.1; Fri, 29 Jul 2016 09:45:30 +0800 From: Wenyou Yang To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Rob Herring , Pawel Moll , Mark Brown , Ian Campbell , "Kumar Gala" Subject: [PATCH v3 4/7] power: act8945a_charger: Fix the power supply type Date: Fri, 29 Jul 2016 09:25:25 +0800 Message-ID: <1469755528-8413-5-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469755528-8413-1-git-send-email-wenyou.yang@atmel.com> References: <1469755528-8413-1-git-send-email-wenyou.yang@atmel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160728_183954_000194_36128245 X-CRM114-Status: GOOD ( 12.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, Nicolas Ferre , linux-kernel@vger.kernel.org, Wenyou Yang , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The power supply type property is varying as the external power supply changes. It is not a constant. Signed-off-by: Wenyou Yang --- Changes in v3: None Changes in v2: None drivers/power/act8945a_charger.c | 48 ++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/power/act8945a_charger.c b/drivers/power/act8945a_charger.c index bbeb13cb..465e346 100644 --- a/drivers/power/act8945a_charger.c +++ b/drivers/power/act8945a_charger.c @@ -77,6 +77,7 @@ static const char *act8945a_charger_manufacturer = "Active-semi"; struct act8945a_charger { struct power_supply *psy; + struct power_supply_desc desc; struct regmap *regmap; struct work_struct work; @@ -250,14 +251,6 @@ static int act8945a_charger_get_property(struct power_supply *psy, return ret; } -static const struct power_supply_desc act8945a_charger_desc = { - .name = "act8945a-charger", - .type = POWER_SUPPLY_TYPE_BATTERY, - .get_property = act8945a_charger_get_property, - .properties = act8945a_charger_props, - .num_properties = ARRAY_SIZE(act8945a_charger_props), -}; - static int act8945a_enable_interrupt(struct act8945a_charger *charger) { struct regmap *regmap = charger->regmap; @@ -281,11 +274,39 @@ static int act8945a_enable_interrupt(struct act8945a_charger *charger) return 0; } +static unsigned int act8945a_set_supply_type(struct act8945a_charger *charger, + unsigned int *type) +{ + unsigned int status, state; + int ret; + + ret = regmap_read(charger->regmap, ACT8945A_APCH_STATUS, &status); + if (ret < 0) + return ret; + + ret = regmap_read(charger->regmap, ACT8945A_APCH_STATE, &state); + if (ret < 0) + return ret; + + if (status & APCH_STATUS_INDAT) { + if (state & APCH_STATE_ACINSTAT) + *type = POWER_SUPPLY_TYPE_MAINS; + else + *type = POWER_SUPPLY_TYPE_USB; + } else { + *type = POWER_SUPPLY_TYPE_BATTERY; + } + + return 0; +} + static void act8945a_work(struct work_struct *work) { struct act8945a_charger *charger = container_of(work, struct act8945a_charger, work); + act8945a_set_supply_type(charger, &charger->desc.type); + power_supply_changed(charger->psy); } @@ -436,11 +457,20 @@ static int act8945a_charger_probe(struct platform_device *pdev) if (ret) return ret; + charger->desc.name = "act8945a-charger"; + charger->desc.get_property = act8945a_charger_get_property; + charger->desc.properties = act8945a_charger_props; + charger->desc.num_properties = ARRAY_SIZE(act8945a_charger_props); + + ret = act8945a_set_supply_type(charger, &charger->desc.type); + if (ret) + return -EINVAL; + psy_cfg.of_node = pdev->dev.parent->of_node; psy_cfg.drv_data = charger; charger->psy = devm_power_supply_register(&pdev->dev, - &act8945a_charger_desc, + &charger->desc, &psy_cfg); if (IS_ERR(charger->psy)) { dev_err(&pdev->dev, "failed to register power supply\n");