From patchwork Thu Dec 26 11:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921261 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC9911D0DEC; Thu, 26 Dec 2024 11:27:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212476; cv=none; b=g1VfpYzPwBOCljzT9hYniQp0qt5EgXKye9kxscYIh+04Av4z6u146Ea591NIbRK8r1GvxxbngqYMcxVEaKCz1sZscAnnjz/Q3DolzwL0U5a7J75DEx2rb2s7mfM1s/NOj+zUz6UsFDV65og8MzfCjXTI3khz2tGoYti+xj2cySk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212476; c=relaxed/simple; bh=oFSjZVZojPLkVJ4Vu59k6TEXOmZFb/QUWrdEC0XgaXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fjCoVelN1++M0sMng4Oj8r2/zoGTV8gLMgVn+84wYF0oX+sfRpEK2hEWbIjoocoj53UBHRrCX0Tye/eekxiYpDTrsKtYCpLxMt4izHQv7j/zYiDMbEHQB2LssNCBeSaNaM/Q02Duy2JR+gVA9ztBCmCCMeaJHRI9maPmd0qPY8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=evYl73Yf; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="evYl73Yf" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 971C22E0058F; Thu, 26 Dec 2024 13:27:44 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212465; bh=s41bXvIWLLG8V+CzanXSlCo59G8kSYLm4mQGMG4i7+I=; h=From:To:Subject; b=evYl73Yft5pYMedTLWg9Wm2WiHPZ1rEa6Ei5pWZ4mjKRL00D+6sSCQ7vjlxpX2nSh uMlGIo81l30GRn61ASV8kcDpHEbW8mM1hbtJ0Wls0yWEhg2vlR+//feCtbmHOrd2ja lIIC33dAOlNiNsVFPmTX58GIp2Cl5YkOYIW61hhE= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 01/10] hwmon: (oxp-sensors) Distinguish the X1 variants Date: Thu, 26 Dec 2024 12:27:31 +0100 Message-ID: <20241226112740.340804-2-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521246528.10782.10935237896828499666@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, the oxp-sensors driver fuzzy matches the X1 variants. Luckily, X1 and X1 mini share most hardware features so this works. However, they are completely different product lines, and there is an expectation that OneXPlayer will release more devices in the X1 line that may have differences. Therefore, distinguish the 3 devices that currently exist in the market. These are the OneXPlayer X1 AMD and Intel variants, and the X1 mini which only has an AMD variant. As far as registers go, all three support the current driver functionality. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 83730d931824..5cb0da3e5d54 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -205,7 +205,21 @@ static const struct dmi_system_id dmi_table[] = { { .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), - DMI_MATCH(DMI_BOARD_NAME, "ONEXPLAYER X1"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER X1 A"), + }, + .driver_data = (void *)oxp_x1, + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER X1 i"), + }, + .driver_data = (void *)oxp_x1, + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER X1 mini"), }, .driver_data = (void *)oxp_x1, }, From patchwork Thu Dec 26 11:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921263 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2C781D1F56; Thu, 26 Dec 2024 11:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212478; cv=none; b=HcadNTrb6/6FgP146aF8gXsAozMrVpoSUDxxLGKo7uvp0Eo29+hWWbQ9FOvwdIf/mgxJ+X1xv2enU0heMiBSKb4QMmUTLa47d0Fer7DoK1C1H9JsQcccE8Vyra0Z0qHbaBDy3+Fwhb6DD+tWTIZmh8QY46JTb+7c8nK3OR7WeG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212478; c=relaxed/simple; bh=plg4ZibVA59qq19vWw9hnRhO7/5t8PtFai05KNK96rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pc3ct2mA1vZoNcfvbRwnnXLB2BJDYQvngR4mOEeqx6VLSkUnLHN2wIW0LI90heRN3r3JmY1Zp1DeisJCr7Qc90bMgxkCP4A4ECqaPB57fD6/omNhIzlqQG6Gqp7KcMOIh+OmTVpy3BzVwOcCdJnRTeV9Tcs6tR98AR+pdkCmXeI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=KvFUt3pP; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="KvFUt3pP" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id B69792E0061B; Thu, 26 Dec 2024 13:27:45 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212467; bh=FD84l6htK36yT/0kihWnvmL2XSFrny7gRNkn/G394Hs=; h=From:To:Subject; b=KvFUt3pPjXyX5QFitlTtYIVXy0HxVlDdAFbdoFUnjxxQxhaHUmGXE2TYtxF0805oE 0LA5uy7U0JZwDWWC+VLxGNRs/tRw+O1rWIcdqgLzTQQa5KBmLkQbml8KELOqzUqbHi lXBu3UM88kH9gbC9RIb9nbNhl/uC17sIXHJwJlbE= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 02/10] hwmon: (oxp-sensors) Add all OneXFly variants Date: Thu, 26 Dec 2024 12:27:32 +0100 Message-ID: <20241226112740.340804-3-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521246682.10841.6428492373330161823@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, the driver only has the F1 OneXFly variant, which was based on the 7000 AMD platform. Add its special editions: F1 EVA-01, F1 OLED. F1 OLED might have been a dev unit, but it is supported by OneXConsole with the same features so add it. Then add the F1L variant which is based on the 8000 AMD platform and the F1Pro and its special edition EVA-02. One might ask why not just fuzzy match. Well, EVA-02 is a variant of F1Pro which is a Strix Point handheld, but does not have F1Pro in its name. This makes it risky to fuzzy match, as special variants in the future from different platforms might not have the same feature set or registers. By happenstance, all current devices use the same registers. For the charge limitting feature on this series, only F1Pro/X1 (AMD) were released with it, but OneXPlayer is providing bios updates for F1, F1L, X1 Mini units that use the same register, so treat all of them the same. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 5cb0da3e5d54..6aed7b3c8674 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -188,6 +188,41 @@ static const struct dmi_system_id dmi_table[] = { }, .driver_data = (void *)oxp_fly, }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER F1 EVA-01"), + }, + .driver_data = (void *)oxp_fly, + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER F1 OLED"), + }, + .driver_data = (void *)oxp_fly, + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER F1L"), + }, + .driver_data = (void *)oxp_fly, + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER F1Pro"), + }, + .driver_data = (void *)oxp_fly, + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER F1 EVA-02"), + }, + .driver_data = (void *)oxp_fly, + }, { .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"), From patchwork Thu Dec 26 11:27:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921264 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79F9C1D318F; Thu, 26 Dec 2024 11:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212478; cv=none; b=DCtV+NaIzHC2AB7Z/8grpY5/ExhQoHdLxb2yY83DuR9wAqf7tDdPsP6vtOlz4VTiGM6bud0PgC+BXJ6F54gCyUXFw8+TZciyDb/doOlECpzQQXoojE5Wjw3TePNmVDBQui0LbW/EPU2zGWVBIytQjD4rBtFTQt/BVGYETFyJ/Bc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212478; c=relaxed/simple; bh=vc8davraFvBL1ufBT1fYM8D9/dpVmLSnSpy0OZQYBXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gWBA1WwcGF9Xi1TbX6KuvbciilD3Bcj5CzK1eZkHD+U6n6OiWuB8g72pyWgUf7uZueDTWhCt5dTje5q7BFQcIhS2Uxeaha35zi18zyEUj99wBf36j9dqjeoi/i1SEWfTdStMEhYnGIE10zhm0YUODmG6A4Abhx8gP+fdZTs+hLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=iCfVf2mD; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="iCfVf2mD" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 4081F2E0069F; Thu, 26 Dec 2024 13:27:47 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212468; bh=lT7UjWteYmK5XZUxENvFOAbI7A5PTsvIpqIY55g/x18=; h=From:To:Subject; b=iCfVf2mDtapDyzrULsEVsGez0tU+rWWi9apjPdOLPM3Q2MZBl2PKLOWLFcLfciEXQ WtyEpf5IifAlGtK43OuUrGwZeFe9EOGWsMJyfsaIKmhE+B2UiPxXpCB1EErl6WR6eY SeOb5HeTXpyutEJKFM1n/Rx9NLBzxI9B3GjkprPw= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 03/10] ABI: testing: sysfs-class-power: add BypassS0 charge_type Date: Thu, 26 Dec 2024 12:27:33 +0100 Message-ID: <20241226112740.340804-4-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521246792.10914.16647945750230088150@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean OneXPlayer devices support a conditional bypass type, in which the device will only perform the battery bypass while in the S0 state. Therefore, add BypassS0, which is a state in which the device conditionally bypasses the battery only in the S0 state. Signed-off-by: Antheas Kapenekakis --- Documentation/ABI/testing/sysfs-class-power | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index 45180b62d426..1f5a56aa5c70 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -404,12 +404,16 @@ Description: The charger bypasses the charging path around the integrated converter allowing for a "smart" wall adaptor to perform the power conversion externally. + BypassS0: + Same as Bypass, but the device automatically enables + bypass only while on the S0 state and disables it when + it powers off or during sleep. Access: Read, Write Valid values: "Unknown", "N/A", "Trickle", "Fast", "Standard", - "Adaptive", "Custom", "Long Life", "Bypass" + "Adaptive", "Custom", "Long Life", "Bypass", "BypassS0" What: /sys/class/power_supply//charge_term_current Date: July 2014 From patchwork Thu Dec 26 11:27:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921265 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36EEF1D45FB; Thu, 26 Dec 2024 11:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212479; cv=none; b=fv6w3D3XuH6Tuog6nWxp9vOAz79wd9d7+t9rujMTYL7vSfHG7MurYEpW/v33iCHpednaSHSseDQV4uYxGwdgbIutm/A/r7c0MKCMyWSihY/14BUyemYde+TkKSWlaHekAfjf9KwTUg1IoDIOYLdkTa5vnE+VLYuINYcavPg4Wgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212479; c=relaxed/simple; bh=m8/cU8IUhyYjWuViGUkVUXgujy55X0Q5m8eAoLGaAIg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxZh33UxxT3iV+PcL91ns7l2t7UHmjWQCTDHvXg4pbEX4hsAdS8bRs18GXIkWK2wqLu6twJoIB+MZ3tzKLCVrSaA3yzQn9+n1qSjEfgtgumOEs8PGKuX0fIpO+S7wiv8Ifa22B12NrdJEtFI84F4vIBmtXVkIaVRNzT17TP0AMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=vT4zDpBr; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="vT4zDpBr" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 4D87F2E00B66; Thu, 26 Dec 2024 13:27:48 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212469; bh=dM0tu18mJeR9+Q5BXLpRRL4jSPXELwLrfzFGfIx/0w8=; h=From:To:Subject; b=vT4zDpBrbyGSFMcxaMk6LEtHFfOSOGttcTbYTv+UvjmMSYYn+2G8RRhwtShRJ+6HF iV+wHdcvT2/eGXEoRtJNiXQTBCETcZNnNF0Pe7CpL5qDsutj7Apjg7Ml/CHFkb9txX hgI47AtPXidBTpCliIq6Zrtmn+CAwnj8TefArLIw= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 04/10] hwmon: (oxp-sensors) Add charge threshold and bypass to OneXPlayer Date: Thu, 26 Dec 2024 12:27:34 +0100 Message-ID: <20241226112740.340804-5-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521246905.10958.6552888605307923026@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean With the X1 (AMD), OneXPlayer added a charge limit and charge bypass to their devices. Charge limit allows for choosing an arbitrary battery charge setpoint in percentages. Charge bypass allows to instruct the device to stop charging either when its on or always. This feature was then extended for the F1Pro as well. OneXPlayer also released BIOS updates for the X1 Mini, X1 (Intel), and F1 devices that add support for this feature. Therefore, enable it for all F1 and X1 devices. Add both of these under the standard sysfs battery endpoints for them, by looking for the battery. OneXPlayer devices have a single battery. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 206 ++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 6aed7b3c8674..8683d708d5a2 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -26,6 +26,7 @@ #include #include #include +#include /* Handle ACPI lock mechanism */ static u32 oxp_mutex; @@ -89,6 +90,35 @@ static enum oxp_board board; #define OXP_TURBO_RETURN_VAL 0x00 /* Common return val */ +#define OXP_X1_CHARGE_LIMIT_REG 0xA3 /* X1 charge limit (%) */ +#define OXP_X1_CHARGE_BYPASS_REG 0xA4 /* X1 bypass charging */ + +#define OXP_X1_CHARGE_BYPASS_MASK_S0 0x01 +/* + * Cannot control S3, S5 individually. + * X1 Mask is 0x0A, OneXFly F1Pro is just 0x02 + * but the extra bit on the X1 does nothing. + */ +#define OXP_X1_CHARGE_BYPASS_MASK_S3S5 0x02 + +enum charge_type_value_index { + CT_OFF, + CT_S0, + CT_S5, +}; + +static u8 charge_type_values_x1[] = { + [CT_OFF] = 0x00, + [CT_S0] = OXP_X1_CHARGE_BYPASS_MASK_S0, + [CT_S5] = OXP_X1_CHARGE_BYPASS_MASK_S0 | OXP_X1_CHARGE_BYPASS_MASK_S3S5, +}; + +static const char * const charge_type_strings[] = { + [CT_OFF] = "Standard", + [CT_S0] = "BypassS0", + [CT_S5] = "Bypass", +}; + static const struct dmi_system_id dmi_table[] = { { .matches = { @@ -429,6 +459,177 @@ static ssize_t tt_toggle_show(struct device *dev, static DEVICE_ATTR_RW(tt_toggle); +/* Callbacks for turbo toggle attribute */ +static bool charge_control_supported(void) +{ + switch (board) { + case oxp_x1: + case oxp_fly: + return 1; + default: + break; + } + return 0; +} + +static ssize_t charge_type_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + u64 val, reg; + int ret; + + ret = __sysfs_match_string(charge_type_strings, + ARRAY_SIZE(charge_type_strings), buf); + if (ret < 0) + return ret; + + switch (board) { + case oxp_x1: + case oxp_fly: + val = charge_type_values_x1[ret]; + reg = OXP_X1_CHARGE_BYPASS_REG; + break; + default: + return -EINVAL; + } + + ret = write_to_ec(reg, val); + if (ret < 0) + return ret; + + return count; +} + +static ssize_t charge_type_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret; + u8 reg; + long val; + const u8 *vals; + char *str; + + switch (board) { + case oxp_x1: + case oxp_fly: + vals = charge_type_values_x1; + reg = OXP_X1_CHARGE_BYPASS_REG; + break; + default: + return -EINVAL; + } + + ret = read_from_ec(reg, 1, &val); + if (ret < 0) + return ret; + + str = (char *) charge_type_strings[0]; + for (ret = 0; ret < ARRAY_SIZE(charge_type_strings); ret++) { + if (val == vals[ret]) { + str = (char *) charge_type_strings[ret]; + break; + } + } + + return sysfs_emit(buf, "%s\n", str); +} + +static DEVICE_ATTR_RW(charge_type); + +static ssize_t charge_control_end_threshold_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + u64 val, reg; + int ret; + + ret = kstrtou64(buf, 10, &val); + if (ret < 0) + return ret; + + if (val > 100) + return -EINVAL; + + switch (board) { + case oxp_x1: + case oxp_fly: + reg = OXP_X1_CHARGE_LIMIT_REG; + break; + default: + return -EINVAL; + } + + ret = write_to_ec(reg, val); + if (ret < 0) + return ret; + + return count; +} + +static ssize_t charge_control_end_threshold_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret; + u8 reg; + long val; + + switch (board) { + case oxp_x1: + case oxp_fly: + reg = OXP_X1_CHARGE_LIMIT_REG; + break; + default: + return -EINVAL; + } + + ret = read_from_ec(reg, 1, &val); + if (ret < 0) + return ret; + + return sysfs_emit(buf, "%ld\n", val); +} + +static DEVICE_ATTR_RW(charge_control_end_threshold); + +static int oxp_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook) +{ + /* OneXPlayer devices only have one battery. */ + if (strcmp(battery->desc->name, "BAT0") != 0 && + strcmp(battery->desc->name, "BAT1") != 0 && + strcmp(battery->desc->name, "BATC") != 0 && + strcmp(battery->desc->name, "BATT") != 0) + return -ENODEV; + + if (device_create_file(&battery->dev, + &dev_attr_charge_control_end_threshold)) + return -ENODEV; + + if (device_create_file(&battery->dev, + &dev_attr_charge_type)) { + device_remove_file(&battery->dev, + &dev_attr_charge_control_end_threshold); + return -ENODEV; + } + + return 0; +} + +static int oxp_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook) +{ + device_remove_file(&battery->dev, + &dev_attr_charge_control_end_threshold); + device_remove_file(&battery->dev, + &dev_attr_charge_type); + return 0; +} + +static struct acpi_battery_hook battery_hook = { + .add_battery = oxp_battery_add, + .remove_battery = oxp_battery_remove, + .name = "OneXPlayer Battery", +}; + /* PWM enable/disable functions */ static int oxp_pwm_enable(void) { @@ -746,6 +947,9 @@ static int __init oxp_platform_init(void) platform_create_bundle(&oxp_platform_driver, oxp_platform_probe, NULL, 0, NULL, 0); + if (charge_control_supported()) + battery_hook_register(&battery_hook); + return PTR_ERR_OR_ZERO(oxp_platform_device); } @@ -753,6 +957,8 @@ static void __exit oxp_platform_exit(void) { platform_device_unregister(oxp_platform_device); platform_driver_unregister(&oxp_platform_driver); + if (charge_control_supported()) + battery_hook_unregister(&battery_hook); } MODULE_DEVICE_TABLE(dmi, dmi_table); From patchwork Thu Dec 26 11:27:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921266 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31EAE1D1F56; Thu, 26 Dec 2024 11:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212480; cv=none; b=GPKFytbnpR6BZY5KCiu9gALiXXQd7hOGUsZn36VQ7e2PnKPE8ku+mgmOyja4e58d67tErMWtZrwZcTIZ32GdsA9hmFFkYol/NVXC1DYsODj2GQ/BEOXRZzGhRlZGgjiznKaHFn9J7txjNtsD1ULI0XFz6dN9P4gxgT9VQUadxp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212480; c=relaxed/simple; bh=jWSL+2gtoB7puBo7qkUCPOJZjy5PZD3UNJkSagooUf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=divqqqAomtNDlSNC/Igm2f4ajughBYLSYlXRSGL7e7yHXIEveNgkZVwqMbgfX2w0vEJ5ZGlQOJrdCKXtKkmezvABi7SKiWraoFkegVvTCIxJF4XDdwMvXsNIDRnJDWcjJ9juqY+QO3h2H6CH1Zw2RouUI6Q2C6dxT5GcS8C/dGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=NPA5kZ3Y; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="NPA5kZ3Y" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 72BD22E0087C; Thu, 26 Dec 2024 13:27:49 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212470; bh=ln9ypNRnxLSyUryhVcduspBrecNqwBgcHGHtva+ELhY=; h=From:To:Subject; b=NPA5kZ3YYSyYKAIveoVLBdKop7Mr2W1bRBvJFDKd8whgMNXFCxwChdAalK00wI0kZ YhApiLydDT/fupz6RhxZ6CBGjTLfM89rmVrrhH5TeMHy80jz+EAa0DJ/lCCVH2z1rQ HuW0n39kKU2Vv9lVvGPdLSBIWMBBrf92zx6tu31E= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 05/10] hwmon: (oxp-sensors) Rename ec group to tt_toggle Date: Thu, 26 Dec 2024 12:27:35 +0100 Message-ID: <20241226112740.340804-6-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247012.11015.17946237438914856518@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, the EC group is used for the turbo button. However, the next patch in the series adds support for the LED button in X1 devices, which is only applicable for X1 devices. Therefore, rename it to prepare for adding the second group. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 8683d708d5a2..30b7020ea836 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -877,18 +877,18 @@ static const struct hwmon_channel_info * const oxp_platform_sensors[] = { NULL, }; -static struct attribute *oxp_ec_attrs[] = { +static struct attribute *oxp_tt_toggle_attrs[] = { &dev_attr_tt_toggle.attr, NULL }; -static struct attribute_group oxp_ec_attribute_group = { +static struct attribute_group oxp_tt_toggle_attribute_group = { .is_visible = tt_toggle_is_visible, - .attrs = oxp_ec_attrs, + .attrs = oxp_tt_toggle_attrs, }; static const struct attribute_group *oxp_ec_groups[] = { - &oxp_ec_attribute_group, + &oxp_tt_toggle_attribute_group, NULL }; From patchwork Thu Dec 26 11:27:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921267 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31F121D318F; Thu, 26 Dec 2024 11:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212480; cv=none; b=doxfYgi0DJtcEvt8hynZZIK5Qa+btAu690nEOyhFWNrF9S2GpLEwtvnyRzIU5u4D5ziaf0+nz9jjTzgy8UuXvKY9Ax1ZwQvNjheU4pInPvOo7ltGHmDWaprMQSGprWSZ0Ktevyh8gZOtBDhRi9C7ZYi4SbgSKpST/NUtEXQ4Sdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212480; c=relaxed/simple; bh=keObh7z3hbPSSGQepUH+MprYhQhX645L9LmRefnzxqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r2h+jp6piTCRLS1HsK1+FsJNwbccKBWJ+vqDuJ686B+kKkGvDFyIGPbIBe9az5/5fgcH5N3qchYgTuAqREF6as7a4q6CxOTRV4EFll4AMGTKE+iWsJCjtr0x85V2zsj7wXFhl7c7jvFS8352clK/js6bF4U5fJxP6CgzAnv7VtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=0scUV1if; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="0scUV1if" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 812A22E00D18; Thu, 26 Dec 2024 13:27:50 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212471; bh=nkq3TmKJP5/w+xBCL2mMJoQYmA07vG9AluzBr/2uTKA=; h=From:To:Subject; b=0scUV1ifxC3YgbjfTcN/b/Jv88QRnhBHTiEbE5qr396+gdGlZbVAzOSzg5t5WS1tw PoWQok2LaGii+Jjq/DQ9aG+Z06oW4BJVKJZ7Gk8HczWw1SYW9gjVQbl16WVkAcmY0M MNxLEBYN982ebQP3raujw/Sdg3Ry8hiUfSdl/kro= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 06/10] hwmon: (oxp-sensors) Add turbo led support to X1 devices Date: Thu, 26 Dec 2024 12:27:36 +0100 Message-ID: <20241226112740.340804-7-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247118.11073.16534949646201267439@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean The X1 and X1 mini lineups feature an LED nested within their turbo button. When turbo takeover is not enabled, the turbo button allows the device to switch from 18W to 25W TDP. When the device is in the 25W TDP mode, the LED is turned on. However, when we engage turbo takeover, the turbo led remains on its last state, which might be illuminated and cannot be currently controlled. Therefore, add the register that controls it under sysfs, to allow userspace to turn it off once engaging turbo takeover and then control it as they wish. As part of researching this topic, I verified that other OneXPlayer devices do not have a turbo led, which makes this feature only applicable to X1 and X1 mini devices. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 30b7020ea836..850e8d72be1f 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -101,6 +101,12 @@ static enum oxp_board board; */ #define OXP_X1_CHARGE_BYPASS_MASK_S3S5 0x02 +/* X1 Turbo LED */ +#define OXP_X1_TURBO_LED_REG 0x57 + +#define OXP_X1_TURBO_LED_OFF 0x01 +#define OXP_X1_TURBO_LED_ON 0x02 + enum charge_type_value_index { CT_OFF, CT_S0, @@ -459,6 +465,73 @@ static ssize_t tt_toggle_show(struct device *dev, static DEVICE_ATTR_RW(tt_toggle); +/* Callbacks for turbo toggle attribute */ +static umode_t tt_led_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + switch (board) { + case oxp_x1: + return attr->mode; + default: + break; + } + return 0; +} + +static ssize_t tt_led_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + u8 reg, val; + int rval; + bool value; + + rval = kstrtobool(buf, &value); + if (rval) + return rval; + + switch (board) { + case oxp_x1: + reg = OXP_X1_TURBO_LED_REG; + val = value ? OXP_X1_TURBO_LED_ON : OXP_X1_TURBO_LED_OFF; + break; + default: + return -EINVAL; + } + rval = write_to_ec(reg, val); + + if (rval) + return rval; + + return count; +} + +static ssize_t tt_led_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int retval; + u8 reg; + long enval; + long val; + + switch (board) { + case oxp_x1: + reg = OXP_2_TURBO_SWITCH_REG; + enval = OXP_X1_TURBO_LED_ON; + break; + default: + return -EINVAL; + } + + retval = read_from_ec(reg, 1, &val); + if (retval) + return retval; + + return sysfs_emit(buf, "%d\n", val == enval); +} + +static DEVICE_ATTR_RW(tt_led); + /* Callbacks for turbo toggle attribute */ static bool charge_control_supported(void) { @@ -887,8 +960,19 @@ static struct attribute_group oxp_tt_toggle_attribute_group = { .attrs = oxp_tt_toggle_attrs, }; +static struct attribute *oxp_tt_led_attrs[] = { + &dev_attr_tt_led.attr, + NULL +}; + +static struct attribute_group oxp_tt_led_attribute_group = { + .is_visible = tt_led_is_visible, + .attrs = oxp_tt_led_attrs, +}; + static const struct attribute_group *oxp_ec_groups[] = { &oxp_tt_toggle_attribute_group, + &oxp_tt_led_attribute_group, NULL }; From patchwork Thu Dec 26 11:27:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921268 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4E231D5173; Thu, 26 Dec 2024 11:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; cv=none; b=qxGuA7e0VVloG6WUUQgLHEY8gqpbVM8RyZL2jnbFIfBpLa6dMkOrOSBI660wt2hrGSN4RV9LtXThD77sQoziUAkq3laElkv2ktPce+HbT2VWUudamtH/02Gsoo5u3p7ixZ3yYOFG1dZH6ezKVmSGDWhSH/upmO1Y1guL6zyyhv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; c=relaxed/simple; bh=YZcjuddjVgKAPlLHMmpUlG4maLOUSx9z9HERhUa1ICI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hcoYL6VXVSS89vWG3adC4UjtHigxPfgWrKT4YG4Fv4Zy49rPHIfTUz5TO94oUfmG/M/55QAvpgs12hcHZd8jlGfTT8V8CcDSbiqaFFzSMGijN41vRQaETBxrv5bNWFC0Q28i1+/jPMU0xGRsJY6fag9ZGKVQzotT8L75RgL/vQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=IqfloShH; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="IqfloShH" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 8D2D72E008C8; Thu, 26 Dec 2024 13:27:51 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212472; bh=bBJXHzoxw0zz+h75ayHF8LKD0Y1CZ2bQuWhAXCVJPtE=; h=From:To:Subject; b=IqfloShHa/sMkg/K88o/awRKbTYtBvAtfZCL5xxAww1iZjuP95qFJLGq8IfXoqU2H 5rhcrMMiQl/ZiLzIqQ/Z15VyvNUY9CPVJVfUPDSEnwU1pzzZpEDSzDaELdwuCLwa79 9U8jsiK2lYYg1cWgf5P4A9n9XzpdnV1ldKYlNqd0= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 07/10] hwmon: (oxp-sensors) Move pwm_enable read to its own function Date: Thu, 26 Dec 2024 12:27:37 +0100 Message-ID: <20241226112740.340804-8-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247225.11229.2342718855724452207@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, this driver breaks sysfs by using auto as 0 and manual as 1. However, for pwm_enable, 0 is full speed, 1 is manual, and 2 is auto. For the correction to be possible, this means that the pwm_enable endpoint will need access to both pwm enable and value (as for the 0th value, the fan needs to be set to full power). Therefore, begin by moving the current pwm_enable read to its own function, oxp_pwm_enable. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 50 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 850e8d72be1f..ff21a94bb80b 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -755,6 +755,32 @@ static int oxp_pwm_disable(void) } } +static int oxp_pwm_read(long *val) +{ + switch (board) { + case orange_pi_neo: + return read_from_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, 1, val); + case aok_zoe_a1: + case aya_neo_2: + case aya_neo_air: + case aya_neo_air_1s: + case aya_neo_air_plus_mendo: + case aya_neo_air_pro: + case aya_neo_flip: + case aya_neo_geek: + case aya_neo_kun: + case oxp_2: + case oxp_fly: + case oxp_mini_amd: + case oxp_mini_amd_a07: + case oxp_mini_amd_pro: + case oxp_x1: + return read_from_ec(OXP_SENSOR_PWM_ENABLE_REG, 1, val); + default: + return -EOPNOTSUPP; + } +} + /* Callbacks for hwmon interface */ static umode_t oxp_ec_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, int channel) @@ -852,29 +878,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, } return 0; case hwmon_pwm_enable: - switch (board) { - case orange_pi_neo: - return read_from_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, 1, val); - case aok_zoe_a1: - case aya_neo_2: - case aya_neo_air: - case aya_neo_air_1s: - case aya_neo_air_plus_mendo: - case aya_neo_air_pro: - case aya_neo_flip: - case aya_neo_geek: - case aya_neo_kun: - case oxp_2: - case oxp_fly: - case oxp_mini_amd: - case oxp_mini_amd_a07: - case oxp_mini_amd_pro: - case oxp_x1: - return read_from_ec(OXP_SENSOR_PWM_ENABLE_REG, 1, val); - default: - break; - } - break; + return oxp_pwm_read(val); default: break; } From patchwork Thu Dec 26 11:27:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921269 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB6E31D515B; Thu, 26 Dec 2024 11:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; cv=none; b=DXAKG7ELSPstarRY4GPTNDBEI6eUNSSFAzaeMxK1AHihkd+ddC8nTGCaC7v3FrFClO1nsj5YC1o9Y0LlPQZOJ6+UYufCzhcCr9/yrN8XYP8rGh6LxIMn+jVkt9BbXpPUE5yjudkdbXKL9ec1m9VsDiK3bk5g+wkMVha0SaTA5VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; c=relaxed/simple; bh=DEhIpwVMB2y2dnsRLLCdHZEz/4d/XHJ/aAM36Z3jcBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lUtGgWpfniLFRmNSDVBOm6mOdNhK9qtWQpY6He7ZK3HY5BKVacZNAsuWDJT/NoIRpPydkzhjvjScSv9bP+FiEFTB/ErZsIUT48P+2CSGs0ODLdVmNSff6AfPl/qR4ki3z3UBM4VLpyNO7RPbNVpG7gejWwhuwf1AuXv/UtAte7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=l1OVM5JI; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="l1OVM5JI" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id AD0AD2E00B97; Thu, 26 Dec 2024 13:27:52 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212473; bh=WS3l86rmtRCJTGJsKGoVNfTPktxQeypg5IPEzwJU+ZE=; h=From:To:Subject; b=l1OVM5JIN00wS6e9aGaqnKIhMyQIQETSBHeElPvVAqNVmTvbcap1MKEAOTArJKcTO oFEmOl3ZAiqb26UfmD6nubBJHSvtA4Tz8g4vaLpZR33Bmkzf2MNYkokGO+C4C2O5x2 02SwXxQGcB79cVw2ecSxk/fq1zVuNS25juL0FaBI= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 08/10] hwmon: (oxp-sensors) Move pwm value read/write to separate functions Date: Thu, 26 Dec 2024 12:27:38 +0100 Message-ID: <20241226112740.340804-9-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247339.11315.1855661158214180250@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, this driver breaks sysfs by using auto as 0 and manual as 1. However, for pwm_enable, 0 is full speed, 1 is manual, and 2 is auto. For the correction to be possible, this means that the pwm_enable endpoint will need access to both pwm enable and value (as for the 0th value, the fan needs to be set to full power). Therefore, move the pwm value read/write to separate functions. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 162 +++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 75 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index ff21a94bb80b..56873b879dee 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -795,6 +795,91 @@ static umode_t oxp_ec_hwmon_is_visible(const void *drvdata, } } +/* PWM input read/write functions */ +static int oxp_pwm_input_write(long val) +{ + if (val < 0 || val > 255) + return -EINVAL; + switch (board) { + case orange_pi_neo: + /* scale to range [1-244] */ + val = ((val - 1) * 243 / 254) + 1; + return write_to_ec(ORANGEPI_SENSOR_PWM_REG, val); + case oxp_2: + case oxp_x1: + /* scale to range [0-184] */ + val = (val * 184) / 255; + return write_to_ec(OXP_SENSOR_PWM_REG, val); + case aya_neo_2: + case aya_neo_air: + case aya_neo_air_1s: + case aya_neo_air_plus_mendo: + case aya_neo_air_pro: + case aya_neo_flip: + case aya_neo_geek: + case aya_neo_kun: + case oxp_mini_amd: + case oxp_mini_amd_a07: + /* scale to range [0-100] */ + val = (val * 100) / 255; + return write_to_ec(OXP_SENSOR_PWM_REG, val); + case aok_zoe_a1: + case oxp_fly: + case oxp_mini_amd_pro: + return write_to_ec(OXP_SENSOR_PWM_REG, val); + default: + return -EOPNOTSUPP; + } +} + +static int oxp_pwm_input_read(long *val) +{ + int ret; + + switch (board) { + case orange_pi_neo: + ret = read_from_ec(ORANGEPI_SENSOR_PWM_REG, 1, val); + if (ret) + return ret; + /* scale from range [1-244] */ + *val = ((*val - 1) * 254 / 243) + 1; + break; + case oxp_2: + case oxp_x1: + ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); + if (ret) + return ret; + /* scale from range [0-184] */ + *val = (*val * 255) / 184; + break; + case aya_neo_2: + case aya_neo_air: + case aya_neo_air_1s: + case aya_neo_air_plus_mendo: + case aya_neo_air_pro: + case aya_neo_flip: + case aya_neo_geek: + case aya_neo_kun: + case oxp_mini_amd: + case oxp_mini_amd_a07: + ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); + if (ret) + return ret; + /* scale from range [0-100] */ + *val = (*val * 255) / 100; + break; + case aok_zoe_a1: + case oxp_fly: + case oxp_mini_amd_pro: + default: + ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); + if (ret) + return ret; + break; + } + return 0; +} + static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -835,48 +920,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, case hwmon_pwm: switch (attr) { case hwmon_pwm_input: - switch (board) { - case orange_pi_neo: - ret = read_from_ec(ORANGEPI_SENSOR_PWM_REG, 1, val); - if (ret) - return ret; - /* scale from range [1-244] */ - *val = ((*val - 1) * 254 / 243) + 1; - break; - case oxp_2: - case oxp_x1: - ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); - if (ret) - return ret; - /* scale from range [0-184] */ - *val = (*val * 255) / 184; - break; - case aya_neo_2: - case aya_neo_air: - case aya_neo_air_1s: - case aya_neo_air_plus_mendo: - case aya_neo_air_pro: - case aya_neo_flip: - case aya_neo_geek: - case aya_neo_kun: - case oxp_mini_amd: - case oxp_mini_amd_a07: - ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); - if (ret) - return ret; - /* scale from range [0-100] */ - *val = (*val * 255) / 100; - break; - case aok_zoe_a1: - case oxp_fly: - case oxp_mini_amd_pro: - default: - ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val); - if (ret) - return ret; - break; - } - return 0; + return oxp_pwm_input_read(val); case hwmon_pwm_enable: return oxp_pwm_read(val); default: @@ -902,39 +946,7 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type, return oxp_pwm_disable(); return -EINVAL; case hwmon_pwm_input: - if (val < 0 || val > 255) - return -EINVAL; - switch (board) { - case orange_pi_neo: - /* scale to range [1-244] */ - val = ((val - 1) * 243 / 254) + 1; - return write_to_ec(ORANGEPI_SENSOR_PWM_REG, val); - case oxp_2: - case oxp_x1: - /* scale to range [0-184] */ - val = (val * 184) / 255; - return write_to_ec(OXP_SENSOR_PWM_REG, val); - case aya_neo_2: - case aya_neo_air: - case aya_neo_air_1s: - case aya_neo_air_plus_mendo: - case aya_neo_air_pro: - case aya_neo_flip: - case aya_neo_geek: - case aya_neo_kun: - case oxp_mini_amd: - case oxp_mini_amd_a07: - /* scale to range [0-100] */ - val = (val * 100) / 255; - return write_to_ec(OXP_SENSOR_PWM_REG, val); - case aok_zoe_a1: - case oxp_fly: - case oxp_mini_amd_pro: - return write_to_ec(OXP_SENSOR_PWM_REG, val); - default: - break; - } - break; + return oxp_pwm_input_write(val); default: break; } From patchwork Thu Dec 26 11:27:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921270 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F18D1D45FB; Thu, 26 Dec 2024 11:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; cv=none; b=kbqocvtf8DHz6keaAJw1ho2OTywxdtirI2VJS1zzStLaErYcuFqOeuvEq6g5TlLZN0Lbh+FeUgiYvyjSgMzMGAxnwTttWJkwtbuS0fPR5Bj26uNlFMPQAW+YTYwbYrqPl788Pyvc5XZ4aMjXm/1a6T7NmHmVJXlYl3fm+WaTd/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; c=relaxed/simple; bh=x0fnV7Yv0PqWxPcYKxTj5QOhnYcL+pa22jneTc5qxIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vaf3Bpq1RzOat1G6sGofk3NqjibnjjPTjpj9pB2vCUB+0yzRW5Xnn48KD4MKXfenUZNhtHD1B7R0JkkxJvurs9Zsl/TMhIzdFEmF72QnEGM6CNw0sqZfqLGn6d7Ca7FybgB0lWxpz5wsFL2D+IPLbGDUFL06tgCnRPz+p+7WHwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=rkfbbafc; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="rkfbbafc" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id C8FF02E00E2A; Thu, 26 Dec 2024 13:27:53 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212474; bh=2oZ5tWtUyFxQVNs6y6jjq9yxUgNmtY3kPTHz3nqztA8=; h=From:To:Subject; b=rkfbbafcYRiwMOmXqVOhRUz9prFnLtNtlVxgSUNGFeFJipAW17MK8p8v0zD9GhiAt jBjdQDEhTJMATVYDJWtzPExNx2Nr0TayJFpZfKB3mCZvQ5eRgo2i7QIKtatxfjvYKB 9a8T863Km9yopSMrEKsaXhqjaoTCYhl1owOSI7L0= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 09/10] hwmon: (oxp-sensors) Move fan speed read to separate function Date: Thu, 26 Dec 2024 12:27:39 +0100 Message-ID: <20241226112740.340804-10-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247450.11369.1518889444393454533@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean While not necessary for fixing the sysfs issue, fan speed will be the only remaining value without a function. Therefore, finish the refactor by moving it to a separate function. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 53 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 56873b879dee..97bf51eba741 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -795,6 +795,34 @@ static umode_t oxp_ec_hwmon_is_visible(const void *drvdata, } } +/* Fan speed read function */ +static int oxp_pwm_fan_speed(long *val) +{ + switch (board) { + case orange_pi_neo: + return read_from_ec(ORANGEPI_SENSOR_FAN_REG, 2, val); + case oxp_2: + case oxp_x1: + return read_from_ec(OXP_2_SENSOR_FAN_REG, 2, val); + case aok_zoe_a1: + case aya_neo_2: + case aya_neo_air: + case aya_neo_air_1s: + case aya_neo_air_plus_mendo: + case aya_neo_air_pro: + case aya_neo_flip: + case aya_neo_geek: + case aya_neo_kun: + case oxp_fly: + case oxp_mini_amd: + case oxp_mini_amd_a07: + case oxp_mini_amd_pro: + return read_from_ec(OXP_SENSOR_FAN_REG, 2, val); + default: + return -EOPNOTSUPP; + } +} + /* PWM input read/write functions */ static int oxp_pwm_input_write(long val) { @@ -889,30 +917,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, case hwmon_fan: switch (attr) { case hwmon_fan_input: - switch (board) { - case orange_pi_neo: - return read_from_ec(ORANGEPI_SENSOR_FAN_REG, 2, val); - case oxp_2: - case oxp_x1: - return read_from_ec(OXP_2_SENSOR_FAN_REG, 2, val); - case aok_zoe_a1: - case aya_neo_2: - case aya_neo_air: - case aya_neo_air_1s: - case aya_neo_air_plus_mendo: - case aya_neo_air_pro: - case aya_neo_flip: - case aya_neo_geek: - case aya_neo_kun: - case oxp_fly: - case oxp_mini_amd: - case oxp_mini_amd_a07: - case oxp_mini_amd_pro: - return read_from_ec(OXP_SENSOR_FAN_REG, 2, val); - default: - break; - } - break; + return oxp_pwm_fan_speed(val); default: break; } From patchwork Thu Dec 26 11:27:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13921271 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F2251D5176; Thu, 26 Dec 2024 11:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; cv=none; b=RZ0dwlSGbnYP0acSTbPZAtkDnqYhQq0G97d6JG1F1ghb//7TawLpzQaCMR+5n3HxYZKH3TJAykV7zh8wdODwlzHUgzramvf6lZRIKIkqNPADblVrJZg07y9++2T9raYu0RccXFXXhNStjwDf/7PcqEPOI5+oQXvJG8LpxLlTA1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212481; c=relaxed/simple; bh=OSd5G3egulkOWYS5LKv4tE0XPSfC2kNk9XOn36l3KbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M4StOscdEFjRfw3npFryFSO+xjqOG9RX3EpRsAcYMZBuOPTW1nMMqJuPDL9vtnlTirpc9t+BvXoEEUFGdtoiUNfknheq8hLyJ15p72AedYHC+HWxqHaE7Ry9Ad7mD3O1YSKtN+BDeG7LhdLUmySzBKOVZCvn2F+yvJW2T9CtRy0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=MEdFQv5q; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="MEdFQv5q" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id DDF342E0111A; Thu, 26 Dec 2024 13:27:54 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212475; bh=dpfI8uIaxipgugPd6BO7woAKGR2nXTlTRTIZe0QvJLI=; h=From:To:Subject; b=MEdFQv5qutTPGIUHA6ugeByhs+OYYhIkUKNmsR9TcQeVhxcVCoOQfANZv988ydLqY 7S1jk1Hg2XbFrwKwiE1Qv7k/kbinYL9nDl4rqjm8iBu/8IuJR2wQYAl2K6sYNwMttc lkSFaNfCpWgZeze1iXY3mfD5PLmYlNsueo69GBTc= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 10/10] hwmon: (oxp-sensors) Adhere to sysfs-class-hwmon and enable pwm on 2 Date: Thu, 26 Dec 2024 12:27:40 +0100 Message-ID: <20241226112740.340804-11-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247561.11447.13156273388358948546@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, the driver does not adhere to the sysfs-class-hwmon specification: 0 is used for auto fan control and 1 is used for manual control. However, it is expected that 0 sets the fan to full speed, 1 sets the fan to manual, and then 2 is used for automatic control. Therefore, change the sysfs API to reflect this and enable pwm on 2. As we are breaking the ABI for this driver, rename oxpec to oxp_ec, reflecting the naming convention used by other drivers, to allow for a smooth migration in current userspace programs. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 97bf51eba741..2ea9029ac287 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -927,7 +927,27 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, case hwmon_pwm_input: return oxp_pwm_input_read(val); case hwmon_pwm_enable: - return oxp_pwm_read(val); + ret = oxp_pwm_read(val); + if (ret) + return ret; + + /* Check for auto and return 2 */ + if (!*val) { + *val = 2; + return 0; + } + + /* Return 0 if at full fan speed, 1 otherwise */ + ret = oxp_pwm_fan_speed(val); + if (ret) + return ret; + + if (*val == 255) + *val = 0; + else + *val = 1; + + return 0; default: break; } @@ -941,15 +961,24 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { + int ret; + switch (type) { case hwmon_pwm: switch (attr) { case hwmon_pwm_enable: if (val == 1) return oxp_pwm_enable(); - else if (val == 0) + else if (val == 2) return oxp_pwm_disable(); - return -EINVAL; + else if (val != 0) + return -EINVAL; + + /* Enable PWM and set to max speed */ + ret = oxp_pwm_enable(); + if (ret) + return ret; + return oxp_pwm_input_write(255); case hwmon_pwm_input: return oxp_pwm_input_write(val); default: @@ -1014,7 +1043,7 @@ static int oxp_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device *hwdev; - hwdev = devm_hwmon_device_register_with_info(dev, "oxpec", NULL, + hwdev = devm_hwmon_device_register_with_info(dev, "oxp_ec", NULL, &oxp_ec_chip_info, NULL); return PTR_ERR_OR_ZERO(hwdev);