From patchwork Mon Nov 11 21:40:04 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: 842624 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 27E2F155A30; Mon, 11 Nov 2024 21:40:14 +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=1731361216; cv=none; b=SJ2byz+wcvPdFsUW1zi5j339UJtUT5+z0WIybH6X6r76JXWFo4LYswtmqLmMEBFYQm8PRmFl9YvwnOsZjGhCiGG4gUvHVgZkHZHJ9r/T2l32aNs7wdRpJ07etIsBPu9E+/JNMSY2AopXZahCF01xISvRUxcWOPlKP2Wc+8/EF6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731361216; c=relaxed/simple; bh=xPxtcrDyr6tHzIlAClodERcs8bwCHKUIZ8Uk9sumlJ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m4M7Bi2KklQbgjyT38EAb3gz/fObKOA/IaupZkiRDJOMfwaIgCX0d5Qzi+yWPzc6ZWomJIRWkE0U+b02nbYSel+GKyLEJgv4bHTFfHx7ThORlZ23EqyzsnfX5z+pzUeTu15DRj8yJdVfzNwWUGu2iQSOPD0TpRkaNZ9aRn6MZrg= 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=dHbKomXx; 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="dHbKomXx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1731361208; bh=xPxtcrDyr6tHzIlAClodERcs8bwCHKUIZ8Uk9sumlJ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dHbKomXxc9choKCT/sCmkR9He7ArmIIUvGmB7caxFx08lxPAcg1ec1susUTVA1uBe ygEPPTojRMGMMPvRg6xmR/rg1ve+fgbsdZJ+n1tABX2TZ0bgRGVoOubFB0m3ixsM7G GW1lTZ5Y8ZVUieGv/mds9MtlvJXIjCh9HOSVOhoY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Nov 2024 22:40:04 +0100 Subject: [PATCH v4 2/9] power: supply: core: rename psy_has_property() to psy_desc_has_property() Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-power-supply-extensions-v4-2-7240144daa8e@weissschuh.net> References: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> In-Reply-To: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> To: Sebastian Reichel , Armin Wolf , Hans de Goede , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Benson Leung , Guenter Roeck Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Sebastian Reichel X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731361208; l=1924; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=xPxtcrDyr6tHzIlAClodERcs8bwCHKUIZ8Uk9sumlJ0=; b=yrvnvdOsKSW70kihrdE3Z8H47tI7CuaFJWj2ZAfnCDMhEOmszqWNdVBClLvJaCbGjPAh/VXDz ZzV3WBwrMs4BCBfeFX3K06vCCIhKNy6exf4ip41JWAWSTKlXnTtDQWe X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The function only takes a desc as parameter, align the naming. Signed-off-by: Thomas Weißschuh Reviewed-by: Hans de Goede Reviewed-by: Sebastian Reichel --- drivers/power/supply/power_supply_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 16085eff008442ecd04016cd12c2854a0230d9c6..2f61f6b90b99f40ee04a6d63ebc20036f0447102 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -1180,8 +1180,8 @@ bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info, } EXPORT_SYMBOL_GPL(power_supply_battery_bti_in_range); -static bool psy_has_property(const struct power_supply_desc *psy_desc, - enum power_supply_property psp) +static bool psy_desc_has_property(const struct power_supply_desc *psy_desc, + enum power_supply_property psp) { bool found = false; int i; @@ -1206,7 +1206,7 @@ int power_supply_get_property(struct power_supply *psy, return -ENODEV; } - if (psy_has_property(psy->desc, psp)) + if (psy_desc_has_property(psy->desc, psp)) return psy->desc->get_property(psy, psp, val); else if (power_supply_battery_info_has_prop(psy->battery_info, psp)) return power_supply_battery_info_get_prop(psy->battery_info, psp, val); @@ -1300,7 +1300,7 @@ static int psy_register_thermal(struct power_supply *psy) return 0; /* Register battery zone device psy reports temperature */ - if (psy_has_property(psy->desc, POWER_SUPPLY_PROP_TEMP)) { + if (psy_desc_has_property(psy->desc, POWER_SUPPLY_PROP_TEMP)) { /* Prefer our hwmon device and avoid duplicates */ struct thermal_zone_params tzp = { .no_hwmon = IS_ENABLED(CONFIG_POWER_SUPPLY_HWMON) From patchwork Mon Nov 11 21:40:06 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: 842626 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 607F21B86CF; Mon, 11 Nov 2024 21:40:11 +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=1731361213; cv=none; b=nJZVA8gzNLX68GZwozKA5uIlIsRHpGNXz2nlj8nrcyyYuMOoqWq3VBBZShjru7J2axmqgG4qsqlScV88F8oGQcYk60C+PHnVx0IfrStjpVTZ/ajxP4aL/1uG1M79oRCB3R9hGvDzeuFSmPRgCinFAO0x+ZqSCQ507+thEciz+pE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731361213; c=relaxed/simple; bh=WoMvZJIJux5dqs2E/f2Vyc4MaZs8AL36MsJXVYFWisU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qNk5Buo/CyXeMEfEfgdOanqYCiKumfGThO3cLg/ZmHxcQPMF9cZXs7qrnNAAWFcvnPGJkqOG0pQyXeIxjh3IYWME4Ct8FHfgg05J5OpbSkQaBRHY+9WbjK33G6iibOr2TVXKxq374isPhVyRUNn30wiDOB/D8GMzlQXllsnYPjU= 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=BlrR/K1X; 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="BlrR/K1X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1731361208; bh=WoMvZJIJux5dqs2E/f2Vyc4MaZs8AL36MsJXVYFWisU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BlrR/K1Xb342Rc1PaIFOcYjyHUUH9PebcSHGGMq0Q3IpyurqrbuGWupI1pT77VYfj eFAtu0BBC5dvKre88yc5JWNkbRIHbtTjhl4E+eUN/1Q1fA6bIAAPLn3I5A+AODMYBv 6HEA8VvPNalEHzPeZMtAZDqG/uRGTxsKq9kRMcFQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Nov 2024 22:40:06 +0100 Subject: [PATCH v4 4/9] power: supply: hwmon: prepare for power supply extensions Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-power-supply-extensions-v4-4-7240144daa8e@weissschuh.net> References: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> In-Reply-To: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> To: Sebastian Reichel , Armin Wolf , Hans de Goede , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Benson Leung , Guenter Roeck Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Sebastian Reichel X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731361208; l=3062; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=WoMvZJIJux5dqs2E/f2Vyc4MaZs8AL36MsJXVYFWisU=; b=iNSCnaLWGctCjtcixkDpwdJqHaTwvZ7xtoRnT9tiLCkUOR+W545SWEoR/Ces3ouT04VWVjvl7 g2uEwoAhVRVBNcZq4ano1pNMpoKwlaIhnoWh+5ZVOmmmOpzOxespcNw X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The upcoming extension API will add properties which are not part of the the power_supply_desc. Use power_supply_has_property() so the properties from extensions are also checked. Signed-off-by: Thomas Weißschuh Reviewed-by: Hans de Goede Reviewed-by: Sebastian Reichel --- drivers/power/supply/power_supply_hwmon.c | 50 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c index 01be04903d7d2465ae2acb9eeb0b55a87868bb87..95245e6a6baa3e85ae8551e71f4f7905639a3325 100644 --- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -349,9 +349,28 @@ static const struct hwmon_chip_info power_supply_hwmon_chip_info = { .info = power_supply_hwmon_info, }; +static const enum power_supply_property power_supply_hwmon_props[] = { + POWER_SUPPLY_PROP_CURRENT_AVG, + POWER_SUPPLY_PROP_CURRENT_MAX, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_POWER_AVG, + POWER_SUPPLY_PROP_POWER_NOW, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_TEMP_MAX, + POWER_SUPPLY_PROP_TEMP_MIN, + POWER_SUPPLY_PROP_TEMP_ALERT_MIN, + POWER_SUPPLY_PROP_TEMP_ALERT_MAX, + POWER_SUPPLY_PROP_TEMP_AMBIENT, + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, + POWER_SUPPLY_PROP_VOLTAGE_AVG, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_VOLTAGE_MAX, + POWER_SUPPLY_PROP_VOLTAGE_NOW, +}; + int power_supply_add_hwmon_sysfs(struct power_supply *psy) { - const struct power_supply_desc *desc = psy->desc; struct power_supply_hwmon *psyhw; struct device *dev = &psy->dev; struct device *hwmon; @@ -377,32 +396,11 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy) goto error; } - for (i = 0; i < desc->num_properties; i++) { - const enum power_supply_property prop = desc->properties[i]; - - switch (prop) { - case POWER_SUPPLY_PROP_CURRENT_AVG: - case POWER_SUPPLY_PROP_CURRENT_MAX: - case POWER_SUPPLY_PROP_CURRENT_NOW: - case POWER_SUPPLY_PROP_POWER_AVG: - case POWER_SUPPLY_PROP_POWER_NOW: - case POWER_SUPPLY_PROP_TEMP: - case POWER_SUPPLY_PROP_TEMP_MAX: - case POWER_SUPPLY_PROP_TEMP_MIN: - case POWER_SUPPLY_PROP_TEMP_ALERT_MIN: - case POWER_SUPPLY_PROP_TEMP_ALERT_MAX: - case POWER_SUPPLY_PROP_TEMP_AMBIENT: - case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN: - case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX: - case POWER_SUPPLY_PROP_VOLTAGE_AVG: - case POWER_SUPPLY_PROP_VOLTAGE_MIN: - case POWER_SUPPLY_PROP_VOLTAGE_MAX: - case POWER_SUPPLY_PROP_VOLTAGE_NOW: + for (i = 0; i < ARRAY_SIZE(power_supply_hwmon_props); i++) { + const enum power_supply_property prop = power_supply_hwmon_props[i]; + + if (power_supply_has_property(psy, prop)) set_bit(prop, psyhw->props); - break; - default: - break; - } } name = psy->desc->name; From patchwork Mon Nov 11 21:40:07 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: 842625 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 3CB8B1BF328; Mon, 11 Nov 2024 21:40:14 +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=1731361216; cv=none; b=j1Vf3C29ph2GNMOrFrJoY6OBwb142fRP7hY8AMMBEHS5dj8jWNbQg9luBAk3Lorvdi9moqPZru1dJBkEpPcyn/7fjSgMeGvHOisNp2mJqUCmvajtMangj5zLrAUSvtHze9TVWLBUzRlPsW7eZS6j6XeVutbZn0AEWuW7Yj7G/hE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731361216; c=relaxed/simple; bh=IK/x/Cq7ZA9U8RzTSdkN5gmLpQF3F49M1qwA6I2D3Ao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iAZU9uhVuIAa/i0BQ+x44fBUeyIBk2B7wwHxp5tE1CenjL4gayV3pqzfZl7DLTyp/+N3QMfPclrdlDVfhLer1N2ZJy8vj5ZbJbsi4KCtubDXQ5QfJkuVtHaDN6d2LoKrBgYMroOTqFWL7bx3C3yiMk7zfu8QqB2xLVaBZqgjF1U= 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=q1RVt5c5; 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="q1RVt5c5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1731361209; bh=IK/x/Cq7ZA9U8RzTSdkN5gmLpQF3F49M1qwA6I2D3Ao=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=q1RVt5c52o+1gNm1mnjwFrNl0iRlPy2NF6nGGOy7dth6Z5BkAm1JaxDgI3etvoA/H yScw65Ec9aLPGAaAPRZeRedU0U1YHxYguipFFnqRh+d+xEh7V3Sa3DT5pbj11BW3iv wvLx81i66POc6qLjqvQND97dPWrhVPEMqMvcxTOs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Nov 2024 22:40:07 +0100 Subject: [PATCH v4 5/9] power: supply: sysfs: prepare for power supply extensions Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-power-supply-extensions-v4-5-7240144daa8e@weissschuh.net> References: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> In-Reply-To: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> To: Sebastian Reichel , Armin Wolf , Hans de Goede , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Benson Leung , Guenter Roeck Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Sebastian Reichel X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731361208; l=1743; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=IK/x/Cq7ZA9U8RzTSdkN5gmLpQF3F49M1qwA6I2D3Ao=; b=OVmbweWyERIkD+3u/cQSsHiAvOSooJ6WsxKcE4WPWREU6O2jUviYpNAQsPOSciqiGJBS2HYWv ap6u6k8NtIwDEyFGLSmcgp6qAZ2iCL6hvv/fBayMuPV4A6LCxlfqFwL X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The upcoming extension API will add properties which are not part of the the power_supply_desc. Use power_supply_has_property() so the properties from extensions are also checked. Signed-off-by: Thomas Weißschuh Reviewed-by: Hans de Goede Reviewed-by: Sebastian Reichel --- drivers/power/supply/power_supply_sysfs.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index a7351b9c8fe34a464a4e69b1a1a4a4179c1a4b4f..bfe48fe01a8d03828c2e539e1e6e5e9fc5c60167 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -378,7 +378,6 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj, struct device *dev = kobj_to_dev(kobj); struct power_supply *psy = dev_get_drvdata(dev); umode_t mode = S_IRUSR | S_IRGRP | S_IROTH; - int i; if (!power_supply_attrs[attrno].prop_name) return 0; @@ -386,19 +385,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj, if (attrno == POWER_SUPPLY_PROP_TYPE) return mode; - for (i = 0; i < psy->desc->num_properties; i++) { - int property = psy->desc->properties[i]; - - if (property == attrno) { - if (power_supply_property_is_writeable(psy, property) > 0) - mode |= S_IWUSR; - - return mode; - } - } - - if (power_supply_battery_info_has_prop(psy->battery_info, attrno)) + if (power_supply_has_property(psy, attrno)) { + if (power_supply_property_is_writeable(psy, attrno) > 0) + mode |= S_IWUSR; return mode; + } return 0; } From patchwork Mon Nov 11 21:40:11 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: 842623 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 0F4811B86F7; Mon, 11 Nov 2024 21:40:14 +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=1731361217; cv=none; b=tWDczyGwwuxHBzcyzk1/p8Pi4UHwnGfTZMXYpLMRkjTeVsOi6PbiK4+5D2Rs1i/Aax/JFOzDN4jwKCkiRiPJ6hasJIcEH1Q38RYRych/vMS+tZ6pviCYfsWWvTEyPyP7QxUxCPmb9pI4SBjdM6qh/F/lUH2v6YBwVJxvKL1E6Uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731361217; c=relaxed/simple; bh=z21J+OltFWwTkbmEn7wl0xG9/rhtTpo3QenCuL3bWPQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CcbxV2ixLbovAxBQK0cD0b/yKL12BFXaVPrvZU3AXs1aGzGN7JP1BgcyUCKCTfWgE7SQ1un8+x9s+UOHoRkxjQ1oy5zg4LwQ2Np3VXMWwUMDtLjuiYyB/7HN26lFhxAJQDGclSY8JDgtNUSJgrFHzJ8wiez0CEOygV6Nx8x2PcY= 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=ZSZaTDSf; 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="ZSZaTDSf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1731361209; bh=z21J+OltFWwTkbmEn7wl0xG9/rhtTpo3QenCuL3bWPQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZSZaTDSfsJTUjeoQybIKjg7qG5FtrOgL6DZtM/whHkNdZRxCPxIEV7ZgRcKIy7GCu GxKM4aMXsUjP1ZcdozNmY8rqNSt0EsJg20dN/JwOLc6bzRvTQmrDsKMSyjgHjyf9MP /DbxFN1ZBPGgZ9iWjdwodikjJiamPAF3XsTVW+8U= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Nov 2024 22:40:11 +0100 Subject: [PATCH v4 9/9] power: supply: cros_charge-control: use power_supply extensions Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241111-power-supply-extensions-v4-9-7240144daa8e@weissschuh.net> References: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> In-Reply-To: <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> To: Sebastian Reichel , Armin Wolf , Hans de Goede , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Benson Leung , Guenter Roeck Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731361208; l=10701; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=z21J+OltFWwTkbmEn7wl0xG9/rhtTpo3QenCuL3bWPQ=; b=Lguc2j8iuLKHKj0BxN9dqGPb67JZiqYrD9/hcKmWGI+wd/BW0f4Eamy2Y+Fo8WZoOGkfGRC7n dqKbCZ6FIjVDox/A5Fy8c67L0FNsNaIVri53wxeOGW4C8IbwGACKAUK X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Power supply extensions provide an easier mechanism to implement additional properties for existing power supplies. Use that instead of reimplementing the sysfs attributes manually. Signed-off-by: Thomas Weißschuh --- drivers/power/supply/cros_charge-control.c | 205 +++++++++++------------------ 1 file changed, 75 insertions(+), 130 deletions(-) diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c index 17c53591ce197d08d97c94d3d4359a282026dd7d..f0933ac3f042c19e7c1dfdc9aff1ad03443ceb16 100644 --- a/drivers/power/supply/cros_charge-control.c +++ b/drivers/power/supply/cros_charge-control.c @@ -18,13 +18,6 @@ BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE) | \ BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE)) -enum CROS_CHCTL_ATTR { - CROS_CHCTL_ATTR_START_THRESHOLD, - CROS_CHCTL_ATTR_END_THRESHOLD, - CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR, - _CROS_CHCTL_ATTR_COUNT -}; - /* * Semantics of data *returned* from the EC API and Linux sysfs differ * slightly, also the v1 API can not return any data. @@ -41,13 +34,7 @@ struct cros_chctl_priv { struct power_supply *hooked_battery; u8 cmd_version; - /* The callbacks need to access this priv structure. - * As neither the struct device nor power_supply are under the drivers - * control, embed the attributes within priv to use with container_of(). - */ - struct device_attribute device_attrs[_CROS_CHCTL_ATTR_COUNT]; - struct attribute *attributes[_CROS_CHCTL_ATTR_COUNT]; - struct attribute_group group; + struct power_supply_ext psy_ext; enum power_supply_charge_behaviour current_behaviour; u8 current_start_threshold, current_end_threshold; @@ -114,123 +101,85 @@ static int cros_chctl_configure_ec(struct cros_chctl_priv *priv) return cros_chctl_send_charge_control_cmd(priv->cros_ec, priv->cmd_version, &req); } -static struct cros_chctl_priv *cros_chctl_attr_to_priv(struct attribute *attr, - enum CROS_CHCTL_ATTR idx) -{ - struct device_attribute *dev_attr = container_of(attr, struct device_attribute, attr); - - return container_of(dev_attr, struct cros_chctl_priv, device_attrs[idx]); -} +static const enum power_supply_property cros_chctl_psy_ext_props[] = { + POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR, /* has to be first */ + POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, + POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, +}; -static ssize_t cros_chctl_store_threshold(struct device *dev, struct cros_chctl_priv *priv, - int is_end_threshold, const char *buf, size_t count) +static int cros_chctl_psy_ext_get_prop(struct power_supply *psy, + const struct power_supply_ext *ext, + void *data, + enum power_supply_property psp, + union power_supply_propval *val) { - int ret, val; + struct cros_chctl_priv *priv = data; - ret = kstrtoint(buf, 10, &val); - if (ret < 0) - return ret; - if (val < 0 || val > 100) + switch (psp) { + case POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD: + val->intval = priv->current_start_threshold; + return 0; + case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD: + val->intval = priv->current_end_threshold; + return 0; + case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR: + val->intval = priv->current_behaviour; + return 0; + default: return -EINVAL; - - if (is_end_threshold) { - if (val <= priv->current_start_threshold) - return -EINVAL; - priv->current_end_threshold = val; - } else { - if (val >= priv->current_end_threshold) - return -EINVAL; - priv->current_start_threshold = val; } - - if (priv->current_behaviour == POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO) { - ret = cros_chctl_configure_ec(priv); - if (ret < 0) - return ret; - } - - return count; } -static ssize_t charge_control_start_threshold_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, - CROS_CHCTL_ATTR_START_THRESHOLD); - return sysfs_emit(buf, "%u\n", (unsigned int)priv->current_start_threshold); -} - -static ssize_t charge_control_start_threshold_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int cros_chctl_psy_ext_set_prop(struct power_supply *psy, + const struct power_supply_ext *ext, + void *data, + enum power_supply_property psp, + const union power_supply_propval *val) { - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, - CROS_CHCTL_ATTR_START_THRESHOLD); - - return cros_chctl_store_threshold(dev, priv, 0, buf, count); -} - -static ssize_t charge_control_end_threshold_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, - CROS_CHCTL_ATTR_END_THRESHOLD); - - return sysfs_emit(buf, "%u\n", (unsigned int)priv->current_end_threshold); -} - -static ssize_t charge_control_end_threshold_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, - CROS_CHCTL_ATTR_END_THRESHOLD); - - return cros_chctl_store_threshold(dev, priv, 1, buf, count); -} - -static ssize_t charge_behaviour_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, - CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR); - - return power_supply_charge_behaviour_show(dev, EC_CHARGE_CONTROL_BEHAVIOURS, - priv->current_behaviour, buf); -} - -static ssize_t charge_behaviour_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, - CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR); + struct cros_chctl_priv *priv = data; int ret; - ret = power_supply_charge_behaviour_parse(EC_CHARGE_CONTROL_BEHAVIOURS, buf); - if (ret < 0) - return ret; - - priv->current_behaviour = ret; + switch (psp) { + case POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD: + case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD: + if (val->intval < 0 || val->intval > 100) + return -EINVAL; - ret = cros_chctl_configure_ec(priv); - if (ret < 0) - return ret; + if (psp == POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD) { + if (val->intval <= priv->current_start_threshold) + return -EINVAL; + priv->current_end_threshold = val->intval; + } else { + if (val->intval >= priv->current_end_threshold) + return -EINVAL; + priv->current_start_threshold = val->intval; + } + + if (priv->current_behaviour == POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO) { + ret = cros_chctl_configure_ec(priv); + if (ret < 0) + return ret; + } - return count; + return 0; + case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR: + priv->current_behaviour = val->intval; + ret = cros_chctl_configure_ec(priv); + if (ret < 0) + return ret; + return 0; + default: + return -EINVAL; + } } -static umode_t cros_chtl_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) +static int cros_chctl_psy_prop_is_writeable(struct power_supply *psy, + const struct power_supply_ext *ext, + void *data, + enum power_supply_property psp) { - struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(attr, n); - - if (priv->cmd_version < 2) { - if (n == CROS_CHCTL_ATTR_START_THRESHOLD) - return 0; - if (n == CROS_CHCTL_ATTR_END_THRESHOLD) - return 0; - } - - return attr->mode; + return true; } static int cros_chctl_add_battery(struct power_supply *battery, struct acpi_battery_hook *hook) @@ -241,7 +190,7 @@ static int cros_chctl_add_battery(struct power_supply *battery, struct acpi_batt return 0; priv->hooked_battery = battery; - return device_add_group(&battery->dev, &priv->group); + return power_supply_register_extension(battery, &priv->psy_ext, priv); } static int cros_chctl_remove_battery(struct power_supply *battery, struct acpi_battery_hook *hook) @@ -249,7 +198,7 @@ static int cros_chctl_remove_battery(struct power_supply *battery, struct acpi_b struct cros_chctl_priv *priv = container_of(hook, struct cros_chctl_priv, battery_hook); if (priv->hooked_battery == battery) { - device_remove_group(&battery->dev, &priv->group); + power_supply_unregister_extension(battery, &priv->psy_ext); priv->hooked_battery = NULL; } @@ -275,7 +224,6 @@ static int cros_chctl_probe(struct platform_device *pdev) struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); struct cros_ec_device *cros_ec = ec_dev->ec_dev; struct cros_chctl_priv *priv; - size_t i; int ret; ret = cros_chctl_fwk_charge_control_versions(cros_ec); @@ -305,23 +253,20 @@ static int cros_chctl_probe(struct platform_device *pdev) dev_dbg(dev, "Command version: %u\n", (unsigned int)priv->cmd_version); priv->cros_ec = cros_ec; - priv->device_attrs[CROS_CHCTL_ATTR_START_THRESHOLD] = - (struct device_attribute)__ATTR_RW(charge_control_start_threshold); - priv->device_attrs[CROS_CHCTL_ATTR_END_THRESHOLD] = - (struct device_attribute)__ATTR_RW(charge_control_end_threshold); - priv->device_attrs[CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR] = - (struct device_attribute)__ATTR_RW(charge_behaviour); - for (i = 0; i < _CROS_CHCTL_ATTR_COUNT; i++) { - sysfs_attr_init(&priv->device_attrs[i].attr); - priv->attributes[i] = &priv->device_attrs[i].attr; - } - priv->group.is_visible = cros_chtl_attr_is_visible; - priv->group.attrs = priv->attributes; priv->battery_hook.name = dev_name(dev); priv->battery_hook.add_battery = cros_chctl_add_battery; priv->battery_hook.remove_battery = cros_chctl_remove_battery; + priv->psy_ext.properties = cros_chctl_psy_ext_props; + priv->psy_ext.num_properties = ARRAY_SIZE(cros_chctl_psy_ext_props); + if (priv->cmd_version == 1) + priv->psy_ext.num_properties = 1; + priv->psy_ext.charge_behaviours = EC_CHARGE_CONTROL_BEHAVIOURS; + priv->psy_ext.get_property = cros_chctl_psy_ext_get_prop; + priv->psy_ext.set_property = cros_chctl_psy_ext_set_prop; + priv->psy_ext.property_is_writeable = cros_chctl_psy_prop_is_writeable; + priv->current_behaviour = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO; priv->current_start_threshold = 0; priv->current_end_threshold = 100;