From patchwork Sun Jun 30 20:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 808783 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 CA31E433CE; Sun, 30 Jun 2024 20:57:02 +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=1719781025; cv=none; b=LoX2AF5nbCVYv8heuaoXXcxOzuHXTw57kx3717pZjcESI6iMep10RNTHYj7cW6YHulaicj6iB1G6q00iaKxPYym5JEcdlRpnQej6Oq9RVWg2fr1g+AxGW8PMPem7aCw5/3dUaKNWxyudCSLKucnRWDd+bhz2oOI1mm8e4izwMFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719781025; c=relaxed/simple; bh=uw8nLh7+K+VERVHPyxd+3eO/7NhujZLZvDsfiJLrD+k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NuOMK70QDV7ZZe8EO0JejQ01L7SHOSlwBuLFUpUEcld+H73xdjD5ABsPgfEjmYMrzcjjdA+vLigZxBvxmTf8Ik1Ud8iJmAJgEkprzKzTKXO2zmgaFnVXPYlw6iX6a8SqBlLI84AhW33vgh7CxM/hwog044TdeaIaW2CI3Q064bQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=ZAydGxhz; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="ZAydGxhz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719781013; bh=uw8nLh7+K+VERVHPyxd+3eO/7NhujZLZvDsfiJLrD+k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZAydGxhzKy2BRBPebAf7jE+fd7WxQqrzZxNBo/mukB5ZHdKF5KZFR0MufVAIF2b1N GGNOORrbdWk+h7TccUCPrZj8f0FY3aBHEaMHdpMVodMdsth58+r9qfXnXMWU5/KWs3 ibv478/fkqXAKT/IM4ac8JVXf6OmKpEK6xWDOfnE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 30 Jun 2024 22:54:08 +0200 Subject: [PATCH v5 1/5] ACPI: battery: add devm_battery_hook_register() Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240630-cros_ec-charge-control-v5-1-8f649d018c52@weissschuh.net> References: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> In-Reply-To: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> To: Benson Leung , Guenter Roeck , Sebastian Reichel , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Tzung-Bi Shih Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mario Limonciello , Dustin Howett , Stephen Horvath , Rajas Paranjpe , linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, Matt Hartley , Kieran Levin , "Rafael J. Wysocki" , =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719781012; l=1828; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=uw8nLh7+K+VERVHPyxd+3eO/7NhujZLZvDsfiJLrD+k=; b=RVHWtd+9L3ZrbCRqbpof/wsE5mrtK9K0/YEZaN/a9i6SR8hj7KrpRk8ZtiXYKXO9+44YXlQiI QQn4bscPzLNDyntpXJ4CsPxXedowJSEKebuEvvKhMTz6EuIMxZ1eENi X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add a utility function for device-managed registration of battery hooks. The function makes it easier to manage the lifecycle of a hook. Acked-by: Rafael J. Wysocki Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 15 +++++++++++++++ include/acpi/battery.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index b379401ff1c2..6ea979f76f84 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -756,6 +756,21 @@ void battery_hook_register(struct acpi_battery_hook *hook) } EXPORT_SYMBOL_GPL(battery_hook_register); +static void devm_battery_hook_unregister(void *data) +{ + struct acpi_battery_hook *hook = data; + + battery_hook_unregister(hook); +} + +int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook) +{ + battery_hook_register(hook); + + return devm_add_action_or_reset(dev, devm_battery_hook_unregister, hook); +} +EXPORT_SYMBOL_GPL(devm_battery_hook_register); + /* * This function gets called right after the battery sysfs * attributes have been added, so that the drivers that diff --git a/include/acpi/battery.h b/include/acpi/battery.h index 611a2561a014..c93f16dfb944 100644 --- a/include/acpi/battery.h +++ b/include/acpi/battery.h @@ -2,6 +2,7 @@ #ifndef __ACPI_BATTERY_H #define __ACPI_BATTERY_H +#include #include #define ACPI_BATTERY_CLASS "battery" @@ -19,5 +20,6 @@ struct acpi_battery_hook { void battery_hook_register(struct acpi_battery_hook *hook); void battery_hook_unregister(struct acpi_battery_hook *hook); +int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook); #endif From patchwork Sun Jun 30 20:54:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 808782 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 8F0B6433C9; Sun, 30 Jun 2024 20:57:02 +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=1719781026; cv=none; b=YYWzB/oSSgskG8A0FF1CUh43Dn+V7JJ0hVuNPD6y+36yYk/ryRCzivroONi0V6NsrwRU9USlLGlmT9I3wrmcipFEyAfv+V1DdGgf61muFwUbePMLrcvtNWdbZSk0QfhQRBvymKzukaf6IOd2+xoAqXhmQA7e9S3HMQc2sR091u8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719781026; c=relaxed/simple; bh=wiXThF8Cv8s9BfLtjBMdMwv3BjfaTV7Ak2mbNROgkoo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J1W5vokcJGU8T3AURJDjxxmeojJarsk6INhhGOK6SXF26+QN+RYPzj5s2xEx1BOxEGtdoq9yfI11O0OKWOT5j7LS1e9kSL9MO1bKAXlwX5CKGJs8t0zqaiEqfbmZHjhz9bKFTY2fwrO171TSl1BXzCWFCj4/jOEQdCYMLi3DD18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=f7SXDA9I; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="f7SXDA9I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719781013; bh=wiXThF8Cv8s9BfLtjBMdMwv3BjfaTV7Ak2mbNROgkoo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=f7SXDA9IjHZwD2/AQdkrZR7uSOCnD+goO6gJdbV5nzmPX79C1Yc/MlItky1ijCxYk Kci8SnpCCEh8ipFOd5TLZ7DL3rdvnwbJNBj1/FJiC4jYRJgEAOd15IldXXcDTJLi1b b4hHjaGpFKR+IpUSGEkYObAOEy3DKaQVQKRuCVRU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 30 Jun 2024 22:54:09 +0200 Subject: [PATCH v5 2/5] platform/chrome: Update binary interface for EC-based charge control Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240630-cros_ec-charge-control-v5-2-8f649d018c52@weissschuh.net> References: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> In-Reply-To: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> To: Benson Leung , Guenter Roeck , Sebastian Reichel , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Tzung-Bi Shih Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mario Limonciello , Dustin Howett , Stephen Horvath , Rajas Paranjpe , linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, Matt Hartley , Kieran Levin , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719781012; l=2737; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=wiXThF8Cv8s9BfLtjBMdMwv3BjfaTV7Ak2mbNROgkoo=; b=ozzy/ZAXP5ai4/Y+sOF0dTHCwM3dDraD8aFD8yIwBytj4HXXl1m0WtZIiP8jz4lC6G6+P1iXd OSnOt54BpvGAIiUYCPjTlhWgFLB763g7ZIUL+Xa3bkhSVGjDkCh9r4z X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The charge-control command v2/v3 is more featureful than v1, it additionally supports charge thresholds. The definitions were imported from ChromeOS EC commit 32870d602317 ("squirtle: modify motionsense rotation matrix") Acked-by: Tzung-Bi Shih Signed-off-by: Thomas Weißschuh --- include/linux/platform_data/cros_ec_commands.h | 49 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index ec598057d1da..e574b790be6f 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -3843,16 +3843,61 @@ struct ec_params_i2c_write { * discharge the battery. */ #define EC_CMD_CHARGE_CONTROL 0x0096 -#define EC_VER_CHARGE_CONTROL 1 +#define EC_VER_CHARGE_CONTROL 3 enum ec_charge_control_mode { CHARGE_CONTROL_NORMAL = 0, CHARGE_CONTROL_IDLE, CHARGE_CONTROL_DISCHARGE, + /* Add no more entry below. */ + CHARGE_CONTROL_COUNT, +}; + +#define EC_CHARGE_MODE_TEXT \ + { \ + [CHARGE_CONTROL_NORMAL] = "NORMAL", \ + [CHARGE_CONTROL_IDLE] = "IDLE", \ + [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \ + } + +enum ec_charge_control_cmd { + EC_CHARGE_CONTROL_CMD_SET = 0, + EC_CHARGE_CONTROL_CMD_GET, +}; + +enum ec_charge_control_flag { + EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0), }; struct ec_params_charge_control { - uint32_t mode; /* enum charge_control_mode */ + uint32_t mode; /* enum charge_control_mode */ + + /* Below are the fields added in V2. */ + uint8_t cmd; /* enum ec_charge_control_cmd. */ + uint8_t flags; /* enum ec_charge_control_flag (v3+) */ + /* + * Lower and upper thresholds for battery sustainer. This struct isn't + * named to avoid tainting foreign projects' name spaces. + * + * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer + * will be disabled. To disable battery sustainer, set mode=NORMAL, + * lower=-1, upper=-1. + */ + struct { + int8_t lower; /* Display SoC in percentage. */ + int8_t upper; /* Display SoC in percentage. */ + } sustain_soc; +} __ec_align4; + +/* Added in v2 */ +struct ec_response_charge_control { + uint32_t mode; /* enum charge_control_mode */ + struct { /* Battery sustainer thresholds */ + int8_t lower; + int8_t upper; + } sustain_soc; + uint8_t flags; /* enum ec_charge_control_flag (v3+) */ + uint8_t reserved; } __ec_align4; /*****************************************************************************/ From patchwork Sun Jun 30 20:54:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 808781 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 783A06A33B; Sun, 30 Jun 2024 20:57:07 +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=1719781029; cv=none; b=qZx/2HbqfY8zXUCQ8v5IG+p4W8bCF4mL8eXcuAd+nKDkfGNCiPILI6CXfZobouIk6boPeK3+mulLSpV0lyEX9eIB7ZMiPJ5Nr+CFGWqIHTRz038EdPNlxmzX0YKHsovTATjvsoE9NVw+v+yMYhd6YgKa1bb3zRGT7ESJOtxat+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719781029; c=relaxed/simple; bh=FHswT/YC3w5l89/ylaLvEiW7spavPfr3VgQBUJELu3s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VAR2Jd+6dX6gxgsHBy64AiHKarcd1zPNGxK5D5hVD8dPx8nivYTsx2NDx9F35CI/hbzMFYXSWY/dE1EFFTy37RCbxdYnmscDpQL0s1pVjTCVVM7SIj+bkYJaBIakEolKkeW64s5VmuShNPh7cZWI/0GvSWZq8sOGq984d8LEZs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=ejWDZHRf; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="ejWDZHRf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719781014; bh=FHswT/YC3w5l89/ylaLvEiW7spavPfr3VgQBUJELu3s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ejWDZHRfukisKwAihu3IBKvVmRI2U3XVHjJJhiKuB2hP4u4h7a1MfWKyCfjKzpzn3 XYY+AyxYMPfEUXIFrks+w0A/FaPIBbB+UcwH9IH4dRLkPflPrxte+pKs7fu+sIdDew gyeQCt49lMuafdri87CdHR2KJYCYg8WqN7DqfjeY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 30 Jun 2024 22:54:12 +0200 Subject: [PATCH v5 5/5] power: supply: cros_charge-control: don't load if Framework control is present Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240630-cros_ec-charge-control-v5-5-8f649d018c52@weissschuh.net> References: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> In-Reply-To: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> To: Benson Leung , Guenter Roeck , Sebastian Reichel , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Tzung-Bi Shih Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mario Limonciello , Dustin Howett , Stephen Horvath , Rajas Paranjpe , linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, Matt Hartley , Kieran Levin , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719781012; l=2327; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=FHswT/YC3w5l89/ylaLvEiW7spavPfr3VgQBUJELu3s=; b=1QB20YP670zdAMsu+gSGB/2BNGtpNQBitzKUlDkaUW00pP/1MiQeShLkXCRsGogQyDekRu7nJ vjZV5uosjOECbDQD/3zZ6EaE39KCofha3E0CyEfdUPoeCn1cO0bwOFm X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Framework laptops implement a custom charge control EC command. The upstream CrOS EC command is also present and functional but can get overridden by the custom one. Until Framework make both commands compatible or remove their custom one, don't load the driver on those machines. If the user knows they are not going to use the custom command they can use a module parameter to load cros_charge-control anyways. Note that the UEFI setup configuration for battery control also uses their custom command. Signed-off-by: Thomas Weißschuh --- drivers/power/supply/cros_charge-control.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c index 521b0eb4ff3b..73d7f2dc0fa3 100644 --- a/drivers/power/supply/cros_charge-control.c +++ b/drivers/power/supply/cros_charge-control.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -256,6 +257,19 @@ static int cros_chctl_remove_battery(struct power_supply *battery, struct acpi_b return 0; } +static bool probe_with_fwk_charge_control; +module_param(probe_with_fwk_charge_control, bool, 0644); +MODULE_PARM_DESC(probe_with_fwk_charge_control, + "Probe the driver in the presence of the custom Framework EC charge control"); + +static int cros_chctl_fwk_charge_control_versions(struct cros_ec_device *cros_ec) +{ + if (!dmi_match(DMI_SYS_VENDOR, "Framework")) + return 0; + + return cros_ec_get_cmd_versions(cros_ec, 0x3E03 /* FW_EC_CMD_CHARGE_LIMIT */); +} + static int cros_chctl_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -265,6 +279,14 @@ static int cros_chctl_probe(struct platform_device *pdev) size_t i; int ret; + ret = cros_chctl_fwk_charge_control_versions(cros_ec); + if (ret < 0) + return ret; + if (ret > 0 && !probe_with_fwk_charge_control) { + dev_info(dev, "Framework charge control detected, preventing load\n"); + return -ENODEV; + } + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM;