[3/4] power: supply: mm8013: implement POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE
Message ID | 20240204-power_supply-charge_behaviour_prop-v1-3-06a20c958f96@weissschuh.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-51820-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp454488dyb; Sun, 4 Feb 2024 09:28:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnzmoOjJAOt7geqToKp5Lgtcb4Ciw3yLo2NSHMlxA1a1vtYlUIahQqxp0zE+otVPAK76lY X-Received: by 2002:a05:6808:1183:b0:3be:b7f2:459e with SMTP id j3-20020a056808118300b003beb7f2459emr15839323oil.52.1707067720269; Sun, 04 Feb 2024 09:28:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707067720; cv=pass; d=google.com; s=arc-20160816; b=0ue02SiFa3KUiFw7nWto/IlIUsdFpVsvIkXDiztN4suiZYtgkn5DUhtCsI89Ts9zIF obi39xtY9zJ9IBZ2z8OEMNnw3bEr3xoLDTGAEnNeYDCyuYUwprehJdkWVEMCKT447vlw NG2hLiFQY5Fbu4z0CM2BwGr6ZFBxKLDQHQvQhDa2+fob96W1Wvacau4STLzmQi0CmgCU iZ5LIiFiaycjhkEO+0uFHsze2Zutk8uLzhg8qsbjYljHR7gkHprRSxeYQkE4Bo08giIo X6KEzLb97z8VHhp7ONhAg4PtguSN1bjUbG5qKucb90du5qI1nFvC4Yu2nFgW+XSZk1XY QJIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=r0TY0I3XSp1WSKj9eJrgghplPJ/srDCIE8rGEI+6+ms=; fh=+ge7IFEel59uBfGI2uo6YVQTzoP2DsUlED3Dco9ZC1c=; b=LEXFxLjcgfRmVuDmDjgU0KiOuZv8mVwtN179SkCEui23XL2pEJD5qOpdCypFx36Zxi T5q/eKgxm0Um59jK4L/sZuKSInzgu0THqhazZ1Sbje0MxsPCsd7mILf95f0DzMNtjJZB ar/E9BZM0ozyhZbBmjzQNNktc7gaNN9DdP1LOavIoBdryyA2eIDDiUckwSXvM44+7x9d jft0gKr4T1BljWjGaYu9+C/Xr83TbyACPcxGv/PQNyaWwxvkgUYrXPj3cx1i5CZ5OW/A dUuyKOUwndYuiA5XlEPt2GPkQ9jqByCYHD4Qqpk52AMy6li5/Oq4kqANPMirlvSjWjbk y7qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=fhMew4Ad; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-51820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51820-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVGx6+1pUJLYCDkTluH8AAeojZgzEjZtJNgG5XSVGFndhaI+eRFjTVVm9uopuaGFeKxznURKTD3UDHMqRzZWscTTZ6yCw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y13-20020a05622a120d00b0042c075c6b62si5580493qtx.709.2024.02.04.09.28.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 09:28:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=fhMew4Ad; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-51820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51820-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 137CD1C2197C for <ouuuleilei@gmail.com>; Sun, 4 Feb 2024 17:28:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AE9728E26; Sun, 4 Feb 2024 17:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="fhMew4Ad" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28B82249EA; Sun, 4 Feb 2024 17:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067628; cv=none; b=jPCQTbjwN7rblAPDmUbd5r7dZdncOTNRdlYGb3xPg7rRmvXBGfhFvaIoWQi4lB232/mtOXLlQ0mPD/xtE/7minYXAEhPThO56MUt18ABENK1Q7rppb0YbfkC7AAzd770ag2fNROctgHVM5XHUIrAjWQ/iwaVfZpNt45wGIDFYtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067628; c=relaxed/simple; bh=2bfpIaHPb+FVKiLlqv6onKrx8jugClAtzAL49QT9tj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KiK54Rv1wCQuV2Cy5JWhv8TdcjTW3Oan3d46V8y/USJaJ/YpGnOkfcu5NQWjVOfs2YNIAwMvLqyiPnRb+RCADtJ8AgvoSzGv2OH6/6LZ63/l/+0fho+yHnGY+YTTeuMLVW3vfbDqeGPs4YLVgWOEWP0IJ5w8UJxyJ65s9eZEjNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=fhMew4Ad; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1707067616; bh=2bfpIaHPb+FVKiLlqv6onKrx8jugClAtzAL49QT9tj8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fhMew4AdtulXYoY2VpXWRvQfvCaONA9fIk0LjMdi2qR/prFTX4jXe/5paqNJRUXoT Ofa50BkT4C7yjQdfSZ2q3CFDq5AVxx+TpEOwXRu5Vj8y+9xbcll7Gjz1A8vP7PV+oj r0rb5D5DBG64iNSuJVBX64a1iWFdMce2R4x2dZpo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> Date: Sun, 04 Feb 2024 18:26:49 +0100 Subject: [PATCH 3/4] power: supply: mm8013: implement POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240204-power_supply-charge_behaviour_prop-v1-3-06a20c958f96@weissschuh.net> References: <20240204-power_supply-charge_behaviour_prop-v1-0-06a20c958f96@weissschuh.net> In-Reply-To: <20240204-power_supply-charge_behaviour_prop-v1-0-06a20c958f96@weissschuh.net> To: Sebastian Reichel <sre@kernel.org>, Hans de Goede <hdegoede@redhat.com>, Konrad Dybcio <konradybcio@kernel.org> Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel <sebastian.reichel@collabora.com>, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= <linux@weissschuh.net> X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707067615; l=1478; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=2bfpIaHPb+FVKiLlqv6onKrx8jugClAtzAL49QT9tj8=; b=YAQ1hO1l8kQ2VYBnblYST3jQhV0wwQngktbNHMJepEyv1/a45AjNO688GAhvqu6GTPruwmRT6 WJKAK1usPsRCQSUvaXcHAkVVdbH8TBXgd/RbKNCcpOKqPQVfpGM2BS8 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789990242120911206 X-GMAIL-MSGID: 1789990242120911206 |
Series |
power: supply: core: align charge_behaviour format with docs
|
|
Commit Message
Thomas Weißschuh
Feb. 4, 2024, 5:26 p.m. UTC
The sysfs is documented to report both the current and all available
behaviours. For this POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE needs
to be implemented.
Note that this changes the format of the sysfs file
(to the documented format):
Before: "auto"
After: "[auto] inhibit-charge"
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/power/supply/mm8013.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
Hi, On 2/4/24 18:26, Thomas Weißschuh wrote: > The sysfs is documented to report both the current and all available > behaviours. For this POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE needs > to be implemented. > > Note that this changes the format of the sysfs file > (to the documented format): > > Before: "auto" > After: "[auto] inhibit-charge" > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Changing userspace API like this is never ideal, but given how new the mm8013 driver is and that this brings things inline with the docs I think that this should be fine: Reviewed-by: Hans de Goede <hdegoede@redhat.com> Regards, Hans > --- > drivers/power/supply/mm8013.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c > index caa272b03564..695df8bd6cb0 100644 > --- a/drivers/power/supply/mm8013.c > +++ b/drivers/power/supply/mm8013.c > @@ -72,6 +72,7 @@ static int mm8013_checkdevice(struct mm8013_chip *chip) > static enum power_supply_property mm8013_battery_props[] = { > POWER_SUPPLY_PROP_CAPACITY, > POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR, > + POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE, > POWER_SUPPLY_PROP_CHARGE_FULL, > POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, > POWER_SUPPLY_PROP_CHARGE_NOW, > @@ -113,6 +114,10 @@ static int mm8013_get_property(struct power_supply *psy, > else > val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO; > break; > + case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE: > + val->intval = BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO) > + | BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE); > + break; > case POWER_SUPPLY_PROP_CHARGE_FULL: > ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, ®val); > if (ret < 0) >
On 2024-02-05 11:00:01+0100, Hans de Goede wrote: > Hi, > > On 2/4/24 18:26, Thomas Weißschuh wrote: > > The sysfs is documented to report both the current and all available > > behaviours. For this POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE needs > > to be implemented. > > > > Note that this changes the format of the sysfs file > > (to the documented format): > > > > Before: "auto" > > After: "[auto] inhibit-charge" > > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > > Changing userspace API like this is never ideal, but given how > new the mm8013 driver is and that this brings things inline > with the docs I think that this should be fine: I agree that it's unfortunate. However looking at the datasheet [0] it seems to me the driver is not correctly using the API. Page 23 documents the flag CHG_INH as follows: CHG_INH : Charge Inhibit When the current is more than or equal to charge threshold current, charge inhibit temperature (upper/lower limit) :1 charge permission temperature or the current is less than charge threshold current :0 This is only diagnostic information and not a control-knob, which the API was meant for. So POWER_SUPPLY_STATUS_NOT_CHARGING seems like the better match. > [..] Thomas [0] https://product.minebeamitsumi.com/en/product/category/ics/battery/fuel_gauge/parts/download/__icsFiles/afieldfile/2023/07/12/1_download_01_12.pdf
On 4.02.2024 18:26, Thomas Weißschuh wrote: > The sysfs is documented to report both the current and all available > behaviours. For this POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE needs > to be implemented. > > Note that this changes the format of the sysfs file > (to the documented format): > > Before: "auto" > After: "[auto] inhibit-charge" > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- LGTM, thanks Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org> Konrad
On 5.02.2024 12:21, Thomas Weißschuh wrote: > On 2024-02-05 11:00:01+0100, Hans de Goede wrote: >> Hi, >> >> On 2/4/24 18:26, Thomas Weißschuh wrote: >>> The sysfs is documented to report both the current and all available >>> behaviours. For this POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE needs >>> to be implemented. >>> >>> Note that this changes the format of the sysfs file >>> (to the documented format): >>> >>> Before: "auto" >>> After: "[auto] inhibit-charge" >>> >>> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >> >> Changing userspace API like this is never ideal, but given how >> new the mm8013 driver is and that this brings things inline >> with the docs I think that this should be fine: > > I agree that it's unfortunate. > > However looking at the datasheet [0] it seems to me the driver is > not correctly using the API. > > Page 23 documents the flag CHG_INH as follows: > > CHG_INH : Charge Inhibit When the current is more than or equal to charge > threshold current, > charge inhibit temperature (upper/lower limit) :1 > charge permission temperature or the current is > less than charge threshold current :0 > > This is only diagnostic information and not a control-knob, which the API > was meant for. > So POWER_SUPPLY_STATUS_NOT_CHARGING seems like the better match. Oh, that's definitely something I glossed over, thanks for taking a look! I'll send a patch untangling this shortly. Konrad > >> [..] > > Thomas > > > [0] https://product.minebeamitsumi.com/en/product/category/ics/battery/fuel_gauge/parts/download/__icsFiles/afieldfile/2023/07/12/1_download_01_12.pdf
diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c index caa272b03564..695df8bd6cb0 100644 --- a/drivers/power/supply/mm8013.c +++ b/drivers/power/supply/mm8013.c @@ -72,6 +72,7 @@ static int mm8013_checkdevice(struct mm8013_chip *chip) static enum power_supply_property mm8013_battery_props[] = { POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR, + POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_NOW, @@ -113,6 +114,10 @@ static int mm8013_get_property(struct power_supply *psy, else val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO; break; + case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR_AVAILABLE: + val->intval = BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO) + | BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE); + break; case POWER_SUPPLY_PROP_CHARGE_FULL: ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, ®val); if (ret < 0)