From patchwork Thu Jun 20 19:14:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13706279 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 311791B4C49; Thu, 20 Jun 2024 19:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718910869; cv=none; b=PNV4pnv5gdeDQ6rB2hU1/ZjHVFLTc57fDIDsaOLhosraq8aj2nG78LkoXubdSkBQZj2o0ASSObniw4/Fr+kBxA9iY2cRtFzQ+xFjevfYjlIsIlMrHlerntx5q0p7BBt1PgbHMZ9NHxYlRZr6zLsCzdeT6JqAXSNrP1N20H2H5WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718910869; c=relaxed/simple; bh=oM7d2nU/1EXglGqyMknsqP4KzMVjfNITvBaD0xtbb8U=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=FSSGUWdjXpIOmkB5tG0jHhXkNWu6Yh/Ms7qA6VzQ2ek91bTYG1FbBHECiLveTd7nNZdecgHbq0UE688Zc7qgvG3z9b9MwO/ZOc8rA9KM2UkBaFhacVjQtFe0AotjWA07QNlmsTTnbkB1ywNKCse77kiM/g3sStU2yqnGaeZktmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=XxTpuznq; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="XxTpuznq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1718910856; x=1719515656; i=w_armin@gmx.de; bh=JfxDuAxw0I5rokPnnN/NN9/gOvD5EFn1E9laPeck6iA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=XxTpuznqa5s0SpQ6YdBrvZNwCXRJ0edFeG7RwA4nafWEyqJXBNYwkwFHqkAwFph/ obu4vTPFY+7Qo8UXInbPMrj96MAUMv7WH+7KynWZbaU6jWpmgpfI3EtAqC0iGv7tB R6/iC0NBkzpWYJe/A+3dBrppWvzsVla1nGnwu66kc6DXtUyEZ/Znr8eFMdKXi77bu +xt7LGs4mr+Swymo1EOxUvTy59CZERil76zkUyBO9n3ndytFj8qd11eeWXYQwZGYP y9QhxcX50jwPqpUX5rCcdjiU6Z6DT0uJoGV+4O4YWpCBzUpj4V+Bq1MYzUKtq/GeN ytkbdoU/jbWr0NIakw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N8XTv-1sP43t1c9p-015xmJ; Thu, 20 Jun 2024 21:14:16 +0200 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] ACPI: battery: Add support for charge limiting state Date: Thu, 20 Jun 2024 21:14:09 +0200 Message-Id: <20240620191410.3646-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:uNBDOBDXPCELTkGamOlx2L0j/W2Zhplj2lD9/D7v5T+apEJnnw9 YiM8dfeyyR6Sy2iqGvBwBDR6TNNFBsC9VaQzIPF0Zi5MqlrWxVwPMPuZuRC8nQgDl6lfsIT NNaneKZl8AKNkuZEFKyFzA3bTq9rBVXFdlx/onmHI+b7i3oAv8ZBdY2ucgGs31HLhjlPCCZ eV4atUc4q9u9vxLvvUQpg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:1ivwSHmpePc=;uSM9rr41Wuw5kjzAoyyV5tk2mIl i3jkEV278EZxI7Tk/3ljPtMJcjPoU7q2SD0TKmrBG8zaCd1wn9zF183BELhNv0Vz6fxEa1Op0 CYjwyMDqZHupFczhdiADcP3WdB53f9HVAK0KB+USScSkLgiu1AGKwkoHNnhLvXxK6K0vaNcsZ A8iThkF8WUgig558RbKPTTVjpE4yyI5xeuJ8m5wxTj/BvHcenpIuXOFPuhmIZAETe+JbVjZyY kdVion2B/yeZ+WS2V2FVwbyh1s9sXNLNvioudWhER+U7rEqykfYIHoJll5px93LumYyvalSNo b6b4eAt5FMXefwAdhc1WQaf9LcUuXwTvLBJxDVMmk+MToV0W9eRkYanJbW/YAune218sx7M3w UyTwWk5eBSckWg2GFCz8zjLJ62pYXFWo2gC3d8UVVmSG+sudcgEBjyaDxaVHF6WPfRl2NyheG /ss80HzssXQwewBtvvvm4QzyloC5TNoD9KaORUWWFYYKO7xMg0avbO33Z0vEV9kqMsTSa1Wel wb0JtzFQhnBIRS1/ulhAjNtrKVtMQzBqLiDPgmUUv8zfMxoLhiYpMagXzvDQCoc5Buzr6FgvH jDhA3MuPWGLufg+nCVMyiOsYRArwG52PSBbF107eEPGxEkM3igcCkaprQVTZv+huO+fSOVK/Y YSw1InfHXFjx9mRga1WvahMB06QO7rCfD7/3H4ht8+hLQxPIn4J/gyFGXLRkdumLXtayoU7kh nEAPyxyGRIMZOmvO0O2EHYiwveoCWIc7U+2D+KnQ6UnaZ/nQmLJ/1XtzCA2dRL6V4tefU69Qy 1dWpymJu7A6bbYvJ5cBYL7zeMf8Q3zp1OitpB8c7FIj0g= The ACPI specification says that bit 3 inside the battery state signals that the battery is in charge limiting state. In this state, the platform limits the battery from reaching its full capacity, the exact limit is platform-specific. This might explain why a number of batteries reported a "Unknown" battery state in the past when using platform-specific interfaces to stop battery charging at a user defined level. Unfortunately not all platforms set this bit in such cases, so "non-charging" is still the default state when the battery is neither charging, discharging or full. Tested on a Lenovo Ideapad S145-14IWL. Signed-off-by: Armin Wolf --- drivers/acpi/battery.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- 2.39.2 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index d289b98a2cca..9ba2191a96d6 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -38,9 +38,10 @@ /* Battery power unit: 0 means mW, 1 means mA */ #define ACPI_BATTERY_POWER_UNIT_MA 1 -#define ACPI_BATTERY_STATE_DISCHARGING 0x1 -#define ACPI_BATTERY_STATE_CHARGING 0x2 -#define ACPI_BATTERY_STATE_CRITICAL 0x4 +#define ACPI_BATTERY_STATE_DISCHARGING 0x1 +#define ACPI_BATTERY_STATE_CHARGING 0x2 +#define ACPI_BATTERY_STATE_CRITICAL 0x4 +#define ACPI_BATTERY_STATE_CHARGE_LIMITING 0x8 #define MAX_STRING_LENGTH 64 @@ -155,7 +156,7 @@ static int acpi_battery_get_state(struct acpi_battery *battery); static int acpi_battery_is_charged(struct acpi_battery *battery) { - /* charging, discharging or critical low */ + /* charging, discharging, critical low or charge limited */ if (battery->state != 0) return 0; @@ -215,6 +216,8 @@ static int acpi_battery_get_property(struct power_supply *psy, val->intval = acpi_battery_handle_discharging(battery); else if (battery->state & ACPI_BATTERY_STATE_CHARGING) val->intval = POWER_SUPPLY_STATUS_CHARGING; + else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING) + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; else if (acpi_battery_is_charged(battery)) val->intval = POWER_SUPPLY_STATUS_FULL; else From patchwork Thu Jun 20 19:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13706278 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (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 688C93A28D; Thu, 20 Jun 2024 19:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718910866; cv=none; b=ZJyGkgyMyk03YygJYOsYI+UnEE6sOXJDTaJEdD4F1XgLjFBIvCn2W64zVkcOhIthPpVlGnMsfrZmjl9KfxlEpLGQ1U70rQJFVnChYiIrq3guqVD7GyQQR5AOk20ay0vSWLKWzterN1I5d8y9cXkBhLPh1tbacWUQ092OL6TkUvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718910866; c=relaxed/simple; bh=J8AysygityxMnNuVj9BEU0a8KtA04L6LP5jPQjwyFCs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g6BgMvo23R3e7saYFlWsmIWqyJEU3x2yFhkefd6dK9b/FgPNGyz39lkf/Cjt91ANYdfsfUdEI2S879D1TPecM1X4UrfppVZl6RMFuAJ4Vh6914UIHAi12fjygDKLiRZfXZGltZw7ieAYWlOSmisw6heRlYt80ADC+AuP94aJt3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=q1GqcbJb; arc=none smtp.client-ip=212.227.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="q1GqcbJb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1718910858; x=1719515658; i=w_armin@gmx.de; bh=YRFGRPiVJpM+SVkvY2grxlxXxshhsfOesxnKljT4D2I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=q1GqcbJbu4WupXTWD8fIQMlFjWt+MVb5uWOJKrcgl3yGvvBwpNW73Z/mJqEVn2Ba 7FllkKf22U9u0zlGRcGtb7w6RXYLbgVqT92vl07GO8YKfIu3maytLlCLFdK4h5WyU /x4x9LTGWiXT2Y9Ctzv3oexUhH8amtvqOXC4CSOoSGz1Tmd6O06feb0PT0sGxVV7w SxSMb8YzF4ThRFDOot9LFS5U/o7oinBJZgsqr1mQDhbitoiXqZxuSRAUtAaTD1qTo MzEAzY6v0fMfhsBKkA5Wwf55dKX4aTQRiu2AWfyqxnW6LQRHmOGUrrhu5p7xNmslw 9CjFEcL/jZ9Av/LHKQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MQ5vc-1ryI134BcG-00UTak; Thu, 20 Jun 2024 21:14:18 +0200 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] ACPI: bus: Indicate support for battery charge limiting thru _OSC Date: Thu, 20 Jun 2024 21:14:10 +0200 Message-Id: <20240620191410.3646-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240620191410.3646-1-W_Armin@gmx.de> References: <20240620191410.3646-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:m6yBZdM3LtbL2MUuXWybwR1AJUY7VaiRZZX6ZnjfyUXcTIS9Bxh nQXKPL4qg4Q1+fZdw+3arCEVLw6fBmsAE61jEb+kSDaHdcc6GBReFNggtrqXgomvKcHYCmC CcqDeRkja3tZpcPh+DUkEvEsxIOu/fVGwFP5Il9rigTxIYcJOIYYJ9jzAljpjgumWvC3UA7 fjHERptObkkAopui3M2Zw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:DJkWtcaidCc=;40xOfPlwgyOKcU+I+ytzwfxUVOT X1fgurEvjCHr8RgA19zB4vBJ3dwXilAGkl7PD/OgPnj5aon7dQ6rCaxo2G8RDyxiRLyslQBpI IJR3qsv3jtmQPGKH745Oe2q9prMOeVAhUTIo2mDsOj1Sw/jUMrP2EKFR3TfxT1l6pclVBz5gF lNZChYtrRC/l+os7A0qDSx27jHGlht5UGnUlizGav/MhZkIzww9hMyXDR7Pj98ZG+RH/OQbxZ ChL6nqLUgcMjprzQP5rXge2qNLsHO6NZmbGb6vcS2CP1UI+4SKCWaz3LJCeGz3tAjMczUm0FZ ao9BGkiKdMWsXY8AXOe09JMHe1+dz2aIxkbnE61eJJqNG+9LhsFWnbCBI12Uf7J13kCeXhZX3 tLoPwJB0tRNt8J7JwCrgv9Fkqz/TJv/Y8z8QgUZZMFz6Ke8CmBuPZCmGaalJd1Le9tRuiHp+b gIX4+tEMtDkoMfgCFa2tF95KigONm9rYtDX5WcOHOw/vR78DomiQjL560Fi+w1oomPV+v+Gn5 59MrBlLXIwKUpqqQRQAQapDLPvhLVIl5NrjVqviw7HEV8vp2xWP1MX887zuYhZJIniwtR7Ux2 LShsYKOK0CuVA0EU13ofmKXsCeOZtZWQcmb0eEEk7lsGydkwAGrhk5W2ySdDxZljfMC9hePo9 wbcyyI8tJ13yRTr1YN4i67d2btwAo1PoLAIVbxgHjyLqDGqP5d8moyOXVwrCEp+z2TC03NzGd muPmhjIxziid1vRybvTckmmEGgoJTPzOWpNGe+2O8uxpYnxelG3gvdHnr/KdJLgzhbH/HS2Jv My0nbYbljrvKIlMCcosMRrumbfXk15W1J8PboCVO3fDmM= The ACPI battery driver can handle the "charge limiting" state of the battery, so the platform can advertise this state. Indicate this by setting bit 19 ("Battery Charge Limiting Support") when evaluating _OSC. Tested on a Lenovo Ideapad S145-14IWL. Signed-off-by: Armin Wolf --- drivers/acpi/bus.c | 2 ++ include/linux/acpi.h | 1 + 2 files changed, 3 insertions(+) -- 2.39.2 diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 787eca838410..bdbd60ae8897 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -329,6 +329,8 @@ static void acpi_bus_osc_negotiate_platform_control(void) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT; if (IS_ENABLED(CONFIG_ACPI_THERMAL)) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_FAST_THERMAL_SAMPLING_SUPPORT; + if (IS_ENABLED(CONFIG_ACPI_BATTERY)) + capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_BATTERY_CHARGE_LIMITING_SUPPORT; capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT; capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index bb18e7bf8826..b9d6882f323e 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -576,6 +576,7 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context); #define OSC_SB_CPC_FLEXIBLE_ADR_SPACE 0x00004000 #define OSC_SB_GENERIC_INITIATOR_SUPPORT 0x00020000 #define OSC_SB_NATIVE_USB4_SUPPORT 0x00040000 +#define OSC_SB_BATTERY_CHARGE_LIMITING_SUPPORT 0x00080000 #define OSC_SB_PRM_SUPPORT 0x00200000 #define OSC_SB_FFH_OPR_SUPPORT 0x00400000