From patchwork Sun Nov 17 14:13:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castello X-Patchwork-Id: 11248453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6D8C930 for ; Sun, 17 Nov 2019 14:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 947DC20885 for ; Sun, 17 Nov 2019 14:36:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=castello.eng.br header.i=@castello.eng.br header.b="Ri9wE98a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726037AbfKQOgC (ORCPT ); Sun, 17 Nov 2019 09:36:02 -0500 Received: from gateway30.websitewelcome.com ([192.185.198.26]:26400 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbfKQOgB (ORCPT ); Sun, 17 Nov 2019 09:36:01 -0500 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id D410C5133 for ; Sun, 17 Nov 2019 08:14:31 -0600 (CST) Received: from br164.hostgator.com.br ([192.185.176.180]) by cmsmtp with SMTP id WLJvi0bPy3Qi0WLJviJSoW; Sun, 17 Nov 2019 08:14:31 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=castello.eng.br; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hDIhrFBd0ww359PJX8lv7FR9yopVFZC5THcbdkAE3CQ=; b=Ri9wE98avi3ja4O2O1LIJKrXhu +Ke5QGaiEahh5S990USln1p26XoacWAMCu2+po3ajjRJmQfloaIGohFlQ2H/MOVSc0T+5pAVfMRBI RSONuRlLNomGF/TNr2Gv/2eck19IOeCTrKetUT+BO/nhj8aqs3RzBzMmfB9084yntvT65dslIPvak JvKiAFag61Zr3yBAPjFSHRsoCtmtrSX7XfE8hXHGkIUng/4rJGwfXP98iSgidb6XpzpFr6qUlyroU fdQEg3bRsxqGNaIJJU0nZSWuzCf5bn4hKzzvKWNN/8DIy4FXkhJQMClWCOJgdTT2TMnEsztUAEIJL tyQFV+HQ==; Received: from [186.222.229.111] (port=47408 helo=localhost.localdomain) by br164.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iWLJt-001Ad4-68; Sun, 17 Nov 2019 11:14:31 -0300 From: Matheus Castello To: sre@kernel.org, krzk@kernel.org, robh+dt@kernel.org Cc: mark.rutland@arm.com, cw00.choi@samsung.com, b.zolnierkie@samsung.com, lee.jones@linaro.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matheus Castello Subject: [PATCH v7 1/5] power: supply: max17040: Add IRQ handler for low SOC alert Date: Sun, 17 Nov 2019 11:13:31 -0300 Message-Id: <20191117141335.23404-2-matheus@castello.eng.br> X-Mailer: git-send-email 2.24.0.rc2 In-Reply-To: <20191117141335.23404-1-matheus@castello.eng.br> References: <20191117141335.23404-1-matheus@castello.eng.br> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br164.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - castello.eng.br X-BWhitelist: no X-Source-IP: 186.222.229.111 X-Source-L: No X-Exim-ID: 1iWLJt-001Ad4-68 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.localdomain) [186.222.229.111]:47408 X-Source-Auth: matheus@castello.eng.br X-Email-Count: 14 X-Source-Cap: Y2FzdGUyNDg7Y2FzdGUyNDg7YnIxNjQuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org According datasheet max17040 has a pin for alert host for low SOC. This pin can be used as external interrupt, so we need to check for interrupts assigned for device and handle it. In handler we are checking and storing fuel gauge registers values and send an uevent to notificate user space, so user space can decide save work or turn off since the alert demonstrate that the battery may no have the power to keep the system turned on for much longer. Signed-off-by: Matheus Castello Reviewed-by: Krzysztof Kozlowski --- drivers/power/supply/max17040_battery.c | 73 +++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) -- 2.24.0.rc2 diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c index 62499018e68b..9909f8cd7b5d 100644 --- a/drivers/power/supply/max17040_battery.c +++ b/drivers/power/supply/max17040_battery.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -160,21 +161,54 @@ static void max17040_get_status(struct i2c_client *client) chip->status = POWER_SUPPLY_STATUS_FULL; } +static void max17040_check_changes(struct i2c_client *client) +{ + max17040_get_vcell(client); + max17040_get_soc(client); + max17040_get_online(client); + max17040_get_status(client); +} + static void max17040_work(struct work_struct *work) { struct max17040_chip *chip; chip = container_of(work, struct max17040_chip, work.work); - - max17040_get_vcell(chip->client); - max17040_get_soc(chip->client); - max17040_get_online(chip->client); - max17040_get_status(chip->client); + max17040_check_changes(chip->client); queue_delayed_work(system_power_efficient_wq, &chip->work, MAX17040_DELAY); } +static irqreturn_t max17040_thread_handler(int id, void *dev) +{ + struct max17040_chip *chip = dev; + struct i2c_client *client = chip->client; + + dev_warn(&client->dev, "IRQ: Alert battery low level"); + /* read registers */ + max17040_check_changes(chip->client); + + /* send uevent */ + power_supply_changed(chip->battery); + + return IRQ_HANDLED; +} + +static int max17040_enable_alert_irq(struct max17040_chip *chip) +{ + struct i2c_client *client = chip->client; + unsigned int flags; + int ret; + + flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; + ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, + max17040_thread_handler, flags, + chip->battery->desc->name, chip); + + return ret; +} + static enum power_supply_property max17040_battery_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, @@ -220,6 +254,19 @@ static int max17040_probe(struct i2c_client *client, max17040_reset(client); max17040_get_version(client); + /* check interrupt */ + if (client->irq) { + int ret; + + ret = max17040_enable_alert_irq(chip); + + if (ret) { + client->irq = 0; + dev_warn(&client->dev, + "Failed to get IRQ err %d\n", ret); + } + } + INIT_DEFERRABLE_WORK(&chip->work, max17040_work); queue_delayed_work(system_power_efficient_wq, &chip->work, MAX17040_DELAY); @@ -244,6 +291,14 @@ static int max17040_suspend(struct device *dev) struct max17040_chip *chip = i2c_get_clientdata(client); cancel_delayed_work(&chip->work); + + if (client->irq) { + if (device_may_wakeup(dev)) + enable_irq_wake(client->irq); + else + disable_irq_wake(client->irq); + } + return 0; } @@ -254,6 +309,14 @@ static int max17040_resume(struct device *dev) queue_delayed_work(system_power_efficient_wq, &chip->work, MAX17040_DELAY); + + if (client->irq) { + if (device_may_wakeup(dev)) + disable_irq_wake(client->irq); + else + enable_irq_wake(client->irq); + } + return 0; } From patchwork Sun Nov 17 14:13:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castello X-Patchwork-Id: 11248455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2DF1184E for ; Sun, 17 Nov 2019 14:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD4512075C for ; Sun, 17 Nov 2019 14:36:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=castello.eng.br header.i=@castello.eng.br header.b="a14FreoE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726084AbfKQOgC (ORCPT ); Sun, 17 Nov 2019 09:36:02 -0500 Received: from gateway30.websitewelcome.com ([192.185.198.26]:38541 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbfKQOgC (ORCPT ); Sun, 17 Nov 2019 09:36:02 -0500 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway30.websitewelcome.com (Postfix) with ESMTP id D68CA4F5D for ; Sun, 17 Nov 2019 08:14:42 -0600 (CST) Received: from br164.hostgator.com.br ([192.185.176.180]) by cmsmtp with SMTP id WLK6iYEgOBnGaWLK6i88qo; Sun, 17 Nov 2019 08:14:42 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=castello.eng.br; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=TW+3zC7f5QFpsJZdkCGHzqRD76y7rl/5etwZN6tUe7A=; b=a14FreoEnSwooYHeX1+EstLKva cmnF39DsVD+Jpr7A6Eq2+6Dz1UozwRot0wvyBelu6gTteaeHExdV/RpHfc5sKg+bH5+1A1D6pwUUE cRGEcSckUfzZXDE2h8sb+eu6x+fZDfIzDFMhTK9dlGJ2pme/UNyJ/HVOB3o3ufocsfrq01NOL0/0+ dI83VECj5czt53uLxr7Astqp1/nm3djjANfibxD45gHwS+g/aOPuhjhMJ+dqByZpQASAw3zeuBHvr D0X53qddOsQrg6/HNUkkT+WvR2PtdDYCuTzfD6SwT7v/51Q2yo9VVGk6QHNtqYORP/HYOtk2ky9Ad m44oXJYg==; Received: from [186.222.229.111] (port=47408 helo=localhost.localdomain) by br164.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iWLK5-001Ad4-KP; Sun, 17 Nov 2019 11:14:42 -0300 From: Matheus Castello To: sre@kernel.org, krzk@kernel.org, robh+dt@kernel.org Cc: mark.rutland@arm.com, cw00.choi@samsung.com, b.zolnierkie@samsung.com, lee.jones@linaro.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matheus Castello , Rob Herring Subject: [PATCH v7 2/5] dt-bindings: power: supply: Max17040: Add DT bindings for max17040 fuel gauge Date: Sun, 17 Nov 2019 11:13:32 -0300 Message-Id: <20191117141335.23404-3-matheus@castello.eng.br> X-Mailer: git-send-email 2.24.0.rc2 In-Reply-To: <20191117141335.23404-1-matheus@castello.eng.br> References: <20191117141335.23404-1-matheus@castello.eng.br> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br164.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - castello.eng.br X-BWhitelist: no X-Source-IP: 186.222.229.111 X-Source-L: No X-Exim-ID: 1iWLK5-001Ad4-KP X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.localdomain) [186.222.229.111]:47408 X-Source-Auth: matheus@castello.eng.br X-Email-Count: 26 X-Source-Cap: Y2FzdGUyNDg7Y2FzdGUyNDg7YnIxNjQuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Documentation of max17040 based fuel gauge characteristics. For configure low level state of charge threshold alert signaled from max17043/max17044 we add "maxim,alert-low-soc-level" property. Signed-off-by: Matheus Castello Reviewed-by: Krzysztof Kozlowski Reviewed-by: Rob Herring --- .../power/supply/max17040_battery.txt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/max17040_battery.txt -- 2.24.0.rc2 diff --git a/Documentation/devicetree/bindings/power/supply/max17040_battery.txt b/Documentation/devicetree/bindings/power/supply/max17040_battery.txt new file mode 100644 index 000000000000..f2d0b22b5f79 --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/max17040_battery.txt @@ -0,0 +1,33 @@ +max17040_battery +~~~~~~~~~~~~~~~~ + +Required properties : + - compatible : "maxim,max17040" or "maxim,max77836-battery" + - reg: i2c slave address + +Optional properties : +- maxim,alert-low-soc-level : The alert threshold that sets the state of + charge level (%) where an interrupt is + generated. Can be configured from 1 up to 32 + (%). If skipped the power up default value of + 4 (%) will be used. +- interrupts : Interrupt line see Documentation/devicetree/ + bindings/interrupt-controller/interrupts.txt +- wakeup-source : This device has wakeup capabilities. Use this + property to use alert low SOC level interrupt + as wake up source. + +Optional properties support interrupt functionality for alert low state of +charge level, present in some ICs in the same family, and should be used with +compatible "maxim,max77836-battery". + +Example: + + battery-fuel-gauge@36 { + compatible = "maxim,max77836-battery"; + reg = <0x36>; + maxim,alert-low-soc-level = <10>; + interrupt-parent = <&gpio7>; + interrupts = <2 IRQ_TYPE_EDGE_FALLING>; + wakeup-source; + }; From patchwork Sun Nov 17 14:13:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castello X-Patchwork-Id: 11248451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97AB514DB for ; Sun, 17 Nov 2019 14:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C6C8206E1 for ; Sun, 17 Nov 2019 14:36:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=castello.eng.br header.i=@castello.eng.br header.b="ltguKLde" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbfKQOgB (ORCPT ); Sun, 17 Nov 2019 09:36:01 -0500 Received: from gateway30.websitewelcome.com ([192.185.198.26]:12430 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbfKQOgB (ORCPT ); Sun, 17 Nov 2019 09:36:01 -0500 X-Greylist: delayed 1289 seconds by postgrey-1.27 at vger.kernel.org; Sun, 17 Nov 2019 09:36:01 EST Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 4240E57A3 for ; Sun, 17 Nov 2019 08:15:04 -0600 (CST) Received: from br164.hostgator.com.br ([192.185.176.180]) by cmsmtp with SMTP id WLKSi0bzl3Qi0WLKSiJTNl; Sun, 17 Nov 2019 08:15:04 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=castello.eng.br; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=faNX9C9K+X/+IvNp0Q5Wq0vZzNGNC8bDF+b+08Xm8wA=; b=ltguKLde4Z3uadEKfjd+O+3kDi SEsZanYWYz4Mv7GqrzMQQIP4fClsNU2y52k/GghZ6J+DDrbfT+DeP2PTJg/3TISQoa5NNzCSEil3v rK8tW6QtsFdxHWvV81+FtSkAOT+BfyNMNCZ+Gisp2VsQHPk0/pYdakI2Z8xr60GFfMepDk2nVueUb BTypFw9caZTpRwqsCHHbz7Dl7UUzNCMNtrLriWZQmTMiaFL+BjDFjMIikm0ikZ3arIHEZUYcLd3b2 +I5F9VXuV9fxvaatg/zdc061xjnot8RL8Y1U1+Z08H74jdSFaFkzhPXLkTPw4b4T1s6Ntdjs5Ez+Q +/grtFjA==; Received: from [186.222.229.111] (port=47408 helo=localhost.localdomain) by br164.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iWLKP-001Ad4-Vk; Sun, 17 Nov 2019 11:15:03 -0300 From: Matheus Castello To: sre@kernel.org, krzk@kernel.org, robh+dt@kernel.org Cc: mark.rutland@arm.com, cw00.choi@samsung.com, b.zolnierkie@samsung.com, lee.jones@linaro.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matheus Castello , Rob Herring Subject: [PATCH v7 3/5] devicetree: mfd: max14577: Add reference to max14040_battery.txt descriptions Date: Sun, 17 Nov 2019 11:13:33 -0300 Message-Id: <20191117141335.23404-4-matheus@castello.eng.br> X-Mailer: git-send-email 2.24.0.rc2 In-Reply-To: <20191117141335.23404-1-matheus@castello.eng.br> References: <20191117141335.23404-1-matheus@castello.eng.br> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br164.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - castello.eng.br X-BWhitelist: no X-Source-IP: 186.222.229.111 X-Source-L: No X-Exim-ID: 1iWLKP-001Ad4-Vk X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.localdomain) [186.222.229.111]:47408 X-Source-Auth: matheus@castello.eng.br X-Email-Count: 38 X-Source-Cap: Y2FzdGUyNDg7Y2FzdGUyNDg7YnIxNjQuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org max77836 MFD has a fuel gauge that has a low SOC alert feature that is described in Documentation/devicetree/bindings/power/supply/max17040_battery.txt. Adding the reference to de documentation here. Signed-off-by: Matheus Castello Acked-by: Lee Jones Acked-by: Rob Herring --- Documentation/devicetree/bindings/mfd/max14577.txt | 2 ++ 1 file changed, 2 insertions(+) -- 2.24.0.rc2 diff --git a/Documentation/devicetree/bindings/mfd/max14577.txt b/Documentation/devicetree/bindings/mfd/max14577.txt index fc6f0f4e8beb..45c7f414aee0 100644 --- a/Documentation/devicetree/bindings/mfd/max14577.txt +++ b/Documentation/devicetree/bindings/mfd/max14577.txt @@ -5,6 +5,8 @@ Battery Charger and SFOUT LDO output for powering USB devices. It is interfaced to host controller using I2C. MAX77836 additionally contains PMIC (with two LDO regulators) and Fuel Gauge. +For the description of Fuel Gauge low SOC alert interrupt see: +power/supply/max17040_battery.txt Required properties: From patchwork Sun Nov 17 14:13:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castello X-Patchwork-Id: 11248437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E0B214ED for ; Sun, 17 Nov 2019 14:15:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 453DC2075C for ; Sun, 17 Nov 2019 14:15:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=castello.eng.br header.i=@castello.eng.br header.b="WYR8x9Kn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726266AbfKQOPZ (ORCPT ); Sun, 17 Nov 2019 09:15:25 -0500 Received: from gateway32.websitewelcome.com ([192.185.145.182]:47160 "EHLO gateway32.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbfKQOPZ (ORCPT ); Sun, 17 Nov 2019 09:15:25 -0500 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 02CE43D69 for ; Sun, 17 Nov 2019 08:15:24 -0600 (CST) Received: from br164.hostgator.com.br ([192.185.176.180]) by cmsmtp with SMTP id WLKli0cIM3Qi0WLKliJTgD; Sun, 17 Nov 2019 08:15:24 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=castello.eng.br; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rfUlDakKv5yVKMK73mGLsSF6+WI5OQYJrDn/ijazhPA=; b=WYR8x9KniX5zXkOL+mkmRtl2AD MLxmE7U5K3JxaVyKefnMW3ftT3VknIEBQcj1w+Uix352RsomNhbTgotINflbs7vu0n/i7ofR7eSUO qCX/xVQnGaqZHL8uy6ix9aUxYRr+hn+8Sv3CqCoqAPMZ0+hMApaNK6TgRP6QY85TcIiDAgfBt018X 6PoX6xFJ82QQEPv5zZ5tsqdTy7502hK0LBix+P4Q7a//jGTV2rsATfX60z/32KoTuOMxQcf3LPyO2 xzTk/ZOIiu00/CXQHKAUeHD2Jp/zT2+xbXe6isXgWmSZ2IvehCyc5uGMAeFjGisL/2gOuxAcqLI7X sblCQzyQ==; Received: from [186.222.229.111] (port=47408 helo=localhost.localdomain) by br164.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iWLKk-001Ad4-Km; Sun, 17 Nov 2019 11:15:23 -0300 From: Matheus Castello To: sre@kernel.org, krzk@kernel.org, robh+dt@kernel.org Cc: mark.rutland@arm.com, cw00.choi@samsung.com, b.zolnierkie@samsung.com, lee.jones@linaro.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matheus Castello Subject: [PATCH v7 4/5] power: supply: max17040: Config alert SOC low level threshold from FDT Date: Sun, 17 Nov 2019 11:13:34 -0300 Message-Id: <20191117141335.23404-5-matheus@castello.eng.br> X-Mailer: git-send-email 2.24.0.rc2 In-Reply-To: <20191117141335.23404-1-matheus@castello.eng.br> References: <20191117141335.23404-1-matheus@castello.eng.br> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br164.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - castello.eng.br X-BWhitelist: no X-Source-IP: 186.222.229.111 X-Source-L: No X-Exim-ID: 1iWLKk-001Ad4-Km X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.localdomain) [186.222.229.111]:47408 X-Source-Auth: matheus@castello.eng.br X-Email-Count: 49 X-Source-Cap: Y2FzdGUyNDg7Y2FzdGUyNDg7YnIxNjQuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org For configuration of fuel gauge alert for a low level state of charge interrupt we add a function to config level threshold and a device tree binding property to set it in flatned device tree node. Now we can use "maxim,alert-low-soc-level" property with the values from 1% up to 32% to configure alert interrupt threshold. Signed-off-by: Matheus Castello --- drivers/power/supply/max17040_battery.c | 75 ++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 8 deletions(-) -- 2.24.0.rc2 diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c index 9909f8cd7b5d..3fc9e1c7b257 100644 --- a/drivers/power/supply/max17040_battery.c +++ b/drivers/power/supply/max17040_battery.c @@ -29,6 +29,9 @@ #define MAX17040_DELAY 1000 #define MAX17040_BATTERY_FULL 95 +#define MAX17040_ATHD_MASK 0xFFC0 +#define MAX17040_ATHD_DEFAULT_POWER_UP 4 + struct max17040_chip { struct i2c_client *client; struct delayed_work work; @@ -43,6 +46,8 @@ struct max17040_chip { int soc; /* State Of Charge */ int status; + /* Low alert threshold from 32% to 1% of the State of Charge */ + u32 low_soc_alert; }; static int max17040_get_property(struct power_supply *psy, @@ -99,6 +104,21 @@ static void max17040_reset(struct i2c_client *client) max17040_write_reg(client, MAX17040_CMD, 0x0054); } +static int max17040_set_low_soc_alert(struct i2c_client *client, u32 level) +{ + int ret; + u16 data; + + level = 32 - level; + data = max17040_read_reg(client, MAX17040_RCOMP); + /* clear the alrt bit and set LSb 5 bits */ + data &= MAX17040_ATHD_MASK; + data |= level; + ret = max17040_write_reg(client, MAX17040_RCOMP, data); + + return ret; +} + static void max17040_get_vcell(struct i2c_client *client) { struct max17040_chip *chip = i2c_get_clientdata(client); @@ -115,7 +135,6 @@ static void max17040_get_soc(struct i2c_client *client) u16 soc; soc = max17040_read_reg(client, MAX17040_SOC); - chip->soc = (soc >> 8); } @@ -161,6 +180,24 @@ static void max17040_get_status(struct i2c_client *client) chip->status = POWER_SUPPLY_STATUS_FULL; } +static int max17040_get_of_data(struct max17040_chip *chip) +{ + struct device *dev = &chip->client->dev; + struct device_node *np = dev->of_node; + int ret = 0; + + if (of_property_read_u32(np, "maxim,alert-low-soc-level", + &chip->low_soc_alert)) { + chip->low_soc_alert = MAX17040_ATHD_DEFAULT_POWER_UP; + } else if (chip->low_soc_alert <= 0 || + chip->low_soc_alert >= 33) { + /* low_soc_alert is not between 1% and 32% */ + ret = -EINVAL; + } + + return ret; +} + static void max17040_check_changes(struct i2c_client *client) { max17040_get_vcell(client); @@ -192,6 +229,9 @@ static irqreturn_t max17040_thread_handler(int id, void *dev) /* send uevent */ power_supply_changed(chip->battery); + /* reset alert bit */ + max17040_set_low_soc_alert(client, chip->low_soc_alert); + return IRQ_HANDLED; } @@ -230,6 +270,7 @@ static int max17040_probe(struct i2c_client *client, struct i2c_adapter *adapter = client->adapter; struct power_supply_config psy_cfg = {}; struct max17040_chip *chip; + int ret; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) return -EIO; @@ -240,6 +281,12 @@ static int max17040_probe(struct i2c_client *client, chip->client = client; chip->pdata = client->dev.platform_data; + ret = max17040_get_of_data(chip); + if (ret) { + dev_err(&client->dev, + "failed: low SOC alert OF data out of bounds\n"); + return ret; + } i2c_set_clientdata(client, chip); psy_cfg.drv_data = chip; @@ -256,14 +303,26 @@ static int max17040_probe(struct i2c_client *client, /* check interrupt */ if (client->irq) { - int ret; - - ret = max17040_enable_alert_irq(chip); - - if (ret) { - client->irq = 0; + if (of_device_is_compatible(client->dev.of_node, + "maxim,max77836-battery")) { + ret = max17040_set_low_soc_alert(client, + chip->low_soc_alert); + if (ret) { + dev_err(&client->dev, + "Failed to set low SOC alert: err %d\n", + ret); + return ret; + } + + ret = max17040_enable_alert_irq(chip); + if (ret) { + client->irq = 0; + dev_warn(&client->dev, + "Failed to get IRQ err %d\n", ret); + } + } else { dev_warn(&client->dev, - "Failed to get IRQ err %d\n", ret); + "Device not compatible for IRQ"); } } From patchwork Sun Nov 17 14:13:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castello X-Patchwork-Id: 11248457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE27A14DB for ; Sun, 17 Nov 2019 14:40:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D0652071E for ; Sun, 17 Nov 2019 14:40:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=castello.eng.br header.i=@castello.eng.br header.b="z+6TWq6P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726137AbfKQOkS (ORCPT ); Sun, 17 Nov 2019 09:40:18 -0500 Received: from gateway34.websitewelcome.com ([192.185.148.109]:43070 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726076AbfKQOkR (ORCPT ); Sun, 17 Nov 2019 09:40:17 -0500 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 7BD054092 for ; Sun, 17 Nov 2019 08:15:46 -0600 (CST) Received: from br164.hostgator.com.br ([192.185.176.180]) by cmsmtp with SMTP id WLL8i6TkXiJ43WLL8idc04; Sun, 17 Nov 2019 08:15:46 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=castello.eng.br; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Bpq1Lr0RjA7GEI60Pxufk6S9EZ2BnHAO3RgT1P1A6D4=; b=z+6TWq6PHyySAdQT68R8gY2SBC cgiae4O+Jj7fkSjCoSjYL/zU2bRDJvET94TX9qWLZiCWIJOwkGrKGqmfDtGseRXWyY16jreqv+s3M ZOE6E8f3+pL4xw+cX0AV87IEwzQOUm/zwCfWv6HPlKEnjLKtQsmL/pOgJhWMoUNqwz6J8/sw2F7c2 /QOHCYPshFZw0BRY3AHvBI71wJrBvcNO/T/xeSnV+tueCQIy+mV2JnPTSfIJoCpSIWnEzKcbTtU1w l059NoDE7evRgScVG/vQKhJEk6dms39NwpESgBIYFCZ+pmO3TlduIyb+4oRwhIWNVwTxcF9HDrHD/ HWdJRFhg==; Received: from [186.222.229.111] (port=47408 helo=localhost.localdomain) by br164.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iWLL6-001Ad4-W4; Sun, 17 Nov 2019 11:15:46 -0300 From: Matheus Castello To: sre@kernel.org, krzk@kernel.org, robh+dt@kernel.org Cc: mark.rutland@arm.com, cw00.choi@samsung.com, b.zolnierkie@samsung.com, lee.jones@linaro.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Matheus Castello Subject: [PATCH v7 5/5] power: supply: max17040: Send uevent in SOC and status change Date: Sun, 17 Nov 2019 11:13:35 -0300 Message-Id: <20191117141335.23404-6-matheus@castello.eng.br> X-Mailer: git-send-email 2.24.0.rc2 In-Reply-To: <20191117141335.23404-1-matheus@castello.eng.br> References: <20191117141335.23404-1-matheus@castello.eng.br> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br164.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - castello.eng.br X-BWhitelist: no X-Source-IP: 186.222.229.111 X-Source-L: No X-Exim-ID: 1iWLL6-001Ad4-W4 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (localhost.localdomain) [186.222.229.111]:47408 X-Source-Auth: matheus@castello.eng.br X-Email-Count: 60 X-Source-Cap: Y2FzdGUyNDg7Y2FzdGUyNDg7YnIxNjQuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Notify core through power_supply_changed() in case of changes in state of charge and power supply status. This is useful for user-space to efficiently update current battery level. Signed-off-by: Matheus Castello Reviewed-by: Krzysztof Kozlowski --- drivers/power/supply/max17040_battery.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.24.0.rc2 diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c index 3fc9e1c7b257..1f5afabdbabc 100644 --- a/drivers/power/supply/max17040_battery.c +++ b/drivers/power/supply/max17040_battery.c @@ -209,10 +209,19 @@ static void max17040_check_changes(struct i2c_client *client) static void max17040_work(struct work_struct *work) { struct max17040_chip *chip; + int last_soc, last_status; chip = container_of(work, struct max17040_chip, work.work); + + /* store SOC and status to check changes */ + last_soc = chip->soc; + last_status = chip->status; max17040_check_changes(chip->client); + /* check changes and send uevent */ + if (last_soc != chip->soc || last_status != chip->status) + power_supply_changed(chip->battery); + queue_delayed_work(system_power_efficient_wq, &chip->work, MAX17040_DELAY); }