Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp475071lqt; Thu, 6 Jun 2024 08:56:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjSQIcIgGSNKIfdgpO6ZYmWSNHWJGuwYtXEXFJsX0AMKInLXzBD+jbcy39sRZpbcT3p/RGZ4jE502QN9K2g4chOi/e6ukst4NV4PJJMw== X-Google-Smtp-Source: AGHT+IFGZS6eTofkXcskqPpttO+wQSAjyarcpY9ps5rCJ/gtYRn7PlxYz6r3Rr2CbWIFABphQKMs X-Received: by 2002:a17:902:ec8e:b0:1f6:a96f:225c with SMTP id d9443c01a7336-1f6d02f2179mr392015ad.28.1717689395970; Thu, 06 Jun 2024 08:56:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717689395; cv=pass; d=google.com; s=arc-20160816; b=s/ezwRPR3xwf3T61a32LaxhsPPZ8A7PobczFT871JG/G9JLFYbXuYyjAU/IYwAxxJA l8bSCgXo2g7xfnfYLOXEREIGpYi5b19wjc/Mt/AuioavSqTTp0S8V9hYDqZb5h2L2hz1 hWCf66xILd4gznENKmboHF0D8ArHDZTxCwzauGDop8Wl3oDSjF4TxZZS7NM072m0Jbwa yLWlmqy5G6YK2P/IOiMlsJWRrIIzyp8z2kAwrNQsFM8bWzat4kBDkL2XwQdZX3Zy3Pdc P6r+QSTPG+3D8R7t6xUqlOuQrhtL/zkuS5nVCjhn3wMz2lW1yx9irL39MjC8QAWJG8we lnZw== 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=F3KgcHSPFZ2+aO31+YhkVeZfNw1Kb7ysQA47aq5FW7w=; fh=yA3vuFiZmJfoItPaS2BpWDAzGgfs+KcnNwQwMnTjy1k=; b=vIelPdajkVP/NHxYaJqwQ9tJkGUbOAKavceY/Sm0mq7l8C5KrcAjbX68bg2cVZ1dlZ vVBRfs1v+ZVzu3TsfzHFlNjLXxiaHH1wQH5u4t+1BV7GVGthpofILd5FTFh/CnDGiVln q/mW5H8xXDaLgukPpm+DB2t88NdL1HWmfsba+WywL4ZEe9RNx6s1tsX4/hD5fuOoqY1M Mh9q4/AwqYUhawtmq9cMCfq7x3NAbDyNtPZWUd5mMcLEyJNvSef0aNkjfK7FN6YFvwLp h18Ciy3gr3glp2XErPjkQ2y3HnGR27jhcLMXnH+AHdbrYVnzZw/F5Zx9vA0kOifuoXBF XY3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=CfmKsHZf; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-204534-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204534-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7f4433si13687275ad.487.2024.06.06.08.56.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 08:56:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204534-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=CfmKsHZf; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-204534-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204534-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3F2CFB280B2 for ; Thu, 6 Jun 2024 15:14:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 243DF1B5808; Thu, 6 Jun 2024 14:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="CfmKsHZf" 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 5C10A1A2C1E; Thu, 6 Jun 2024 14:51:09 +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=1717685471; cv=none; b=tJ6WbU+lk2UnmCtm5xPDyX9Rz8TJhvafltlpGIOBsdn31aIYrFQwrpjkQyunlvh3frbJ/VR4svaglhm3QXsk23Z0cVbp9h1LKXk3BOffYxengi89mx4HcCP/2R7GttmhXhywZ4bB+6HaPiNsxCf4PCJI8DHXBUDSOc4fsmy6KwE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717685471; c=relaxed/simple; bh=CpbSko9MUrOONdiIMtfB2TK6xEtuWLt0mNiMMQVHVro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=muAfTCfpQekUy3btKSLtGk1gIj5PLvRTrpLWFoiuX+fah2EH3QOpsi+3Kem+e6h5y1FkteAbePtuqz8ytSBGS3eUyv1rZ1y+sRJAWYxPvLs/HiWht/1Ry7s38lJ0Eha75j2t/j5JPbYCDGhEGv2MUe/0ctpldoSxUSgGuNNZ+iA= 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=CfmKsHZf; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1717685464; bh=CpbSko9MUrOONdiIMtfB2TK6xEtuWLt0mNiMMQVHVro=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CfmKsHZfVFu9AeIsdm8pI3VKVLXW9NpdjmekNnCGQEN50Nc9ZWFPkLGidi8wH7BBP DkJIkX7mhzb9d+0i9wisIOe5dVCO9nTqkn0FpNSS/1siKbLU/dTkrOvGAeozwHR217 gzp9F7yIazJxhNtlLIORnVq1S2PjQQSep3TF36ng= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 06 Jun 2024 16:51:00 +0200 Subject: [PATCH RFC 6/6] platform/x86: system76: Use power_supply extension API Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240606-power-supply-extensions-v1-6-b45669290bdc@weissschuh.net> References: <20240606-power-supply-extensions-v1-0-b45669290bdc@weissschuh.net> In-Reply-To: <20240606-power-supply-extensions-v1-0-b45669290bdc@weissschuh.net> To: Sebastian Reichel , Jeremy Soller , System76 Product Development , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717685463; l=5181; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=CpbSko9MUrOONdiIMtfB2TK6xEtuWLt0mNiMMQVHVro=; b=/5mcEKpBkBU80sDzsXU5JK0I6crCorZge0wy9rVTQvGQg2l4RdbSj4PQfNLvpefCLYMt9YLIl yt+eH9nVJn1AGoGFY6Q/TDTYCyh9dMaCg+Ky9J9/xZy141uBrjx+CYZ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Signed-off-by: Thomas Weißschuh --- drivers/platform/x86/system76_acpi.c | 83 +++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c index 3da753b3d00d..c26f42c917dd 100644 --- a/drivers/platform/x86/system76_acpi.c +++ b/drivers/platform/x86/system76_acpi.c @@ -162,7 +162,7 @@ enum { THRESHOLD_END, }; -static ssize_t battery_get_threshold(int which, char *buf) +static int battery_get_threshold(int which, int *val) { struct acpi_object_list input; union acpi_object param; @@ -186,29 +186,21 @@ static ssize_t battery_get_threshold(int which, char *buf) if (ret == BATTERY_THRESHOLD_INVALID) return -EINVAL; - return sysfs_emit(buf, "%d\n", (int)ret); + *val = ret; + return 0; } -static ssize_t battery_set_threshold(int which, const char *buf, size_t count) +static int battery_set_threshold(int which, unsigned int value) { struct acpi_object_list input; union acpi_object params[2]; acpi_handle handle; acpi_status status; - unsigned int value; - int ret; handle = ec_get_handle(); if (!handle) return -ENODEV; - ret = kstrtouint(buf, 10, &value); - if (ret) - return ret; - - if (value > 100) - return -EINVAL; - input.count = 2; input.pointer = params; // Start/stop selection @@ -222,52 +214,65 @@ static ssize_t battery_set_threshold(int which, const char *buf, size_t count) if (ACPI_FAILURE(status)) return -EIO; - return count; + return 0; } -static ssize_t charge_control_start_threshold_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return battery_get_threshold(THRESHOLD_START, buf); -} +static const enum power_supply_property system76_battery_properties[] = { + POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, + POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, +}; -static ssize_t charge_control_start_threshold_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static int system76_property_is_writeable(struct power_supply *psy, + enum power_supply_property psp) { - return battery_set_threshold(THRESHOLD_START, buf, count); + return true; } -static DEVICE_ATTR_RW(charge_control_start_threshold); - -static ssize_t charge_control_end_threshold_show(struct device *dev, - struct device_attribute *attr, char *buf) +static int system76_get_property(struct power_supply *psy, enum power_supply_property psp, + union power_supply_propval *val) { - return battery_get_threshold(THRESHOLD_END, buf); + switch (psp) { + case POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD: + return battery_get_threshold(THRESHOLD_START, &val->intval); + case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD: + return battery_get_threshold(THRESHOLD_END, &val->intval); + default: + return -EINVAL; + }; } -static ssize_t charge_control_end_threshold_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static int system76_set_property(struct power_supply *psy, enum power_supply_property psp, + const union power_supply_propval *val) { - return battery_set_threshold(THRESHOLD_END, buf, count); + switch (psp) { + case POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD: + if (val->intval < 0 || val->intval > 100) + return -EINVAL; + return battery_set_threshold(THRESHOLD_START, val->intval); + case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD: + if (val->intval < 0 || val->intval > 100) + return -EINVAL; + return battery_set_threshold(THRESHOLD_END, val->intval); + default: + return -EINVAL; + }; } -static DEVICE_ATTR_RW(charge_control_end_threshold); - -static struct attribute *system76_battery_attrs[] = { - &dev_attr_charge_control_start_threshold.attr, - &dev_attr_charge_control_end_threshold.attr, - NULL, +static const struct power_supply_ext system76_power_supply_ext = { + .properties = system76_battery_properties, + .num_properties = ARRAY_SIZE(system76_battery_properties), + .property_is_writeable = system76_property_is_writeable, + .get_property = system76_get_property, + .set_property = system76_set_property, }; -ATTRIBUTE_GROUPS(system76_battery); - static int system76_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook) { // System76 EC only supports 1 battery if (strcmp(battery->desc->name, "BAT0") != 0) return -ENODEV; - if (device_add_groups(&battery->dev, system76_battery_groups)) + if (power_supply_register_extension(battery, &system76_power_supply_ext)) return -ENODEV; return 0; @@ -275,7 +280,7 @@ static int system76_battery_add(struct power_supply *battery, struct acpi_batter static int system76_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook) { - device_remove_groups(&battery->dev, system76_battery_groups); + power_supply_unregister_extension(battery, &system76_power_supply_ext); return 0; } -- 2.45.2