lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250426172955.13957-2-lkml@antheas.dev>
Date: Sat, 26 Apr 2025 19:29:54 +0200
From: Antheas Kapenekakis <lkml@...heas.dev>
To: platform-driver-x86@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
	Derek John Clark <derekjohn.clark@...il.com>,
	Joaquín Ignacio Aramendía <samsagax@...il.com>,
	Hans de Goede <hdegoede@...hat.com>,
	Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
	Eileen <eileen@...-netbook.com>,
	Antheas Kapenekakis <lkml@...heas.dev>,
	Joshua Tam <csinaction@...me>
Subject: [PATCH v1 1/2] platform/x86: oxpec: Make turbo val apply a bitmask

On the OneXPlayer G1, the turbo register is multiplexed and contains an
extra bit (0x02) which is set on boot. Therefore, we should only change
the 0x40 bit to not affect other behavior. Collapse the disable and
enable functions, and apply a mask for the turbo bit instead.

Tested-by: Joshua Tam <csinaction@...me>
Suggested-by: Joshua Tam <csinaction@...me>
Signed-off-by: Joshua Tam <csinaction@...me>
Signed-off-by: Antheas Kapenekakis <lkml@...heas.dev>
---
 drivers/platform/x86/oxpec.c | 96 +++++++++++++-----------------------
 1 file changed, 35 insertions(+), 61 deletions(-)

diff --git a/drivers/platform/x86/oxpec.c b/drivers/platform/x86/oxpec.c
index 4b48f4571b09b..86ac32eadd6ef 100644
--- a/drivers/platform/x86/oxpec.c
+++ b/drivers/platform/x86/oxpec.c
@@ -87,8 +87,6 @@ static struct device *oxp_dev;
 #define OXP_MINI_TURBO_TAKE_VAL		0x01 /* Mini AO7 */
 #define OXP_TURBO_TAKE_VAL		0x40 /* All other models */
 
-#define OXP_TURBO_RETURN_VAL		0x00 /* Common return val */
-
 /* X1 Turbo LED */
 #define OXP_X1_TURBO_LED_REG		0x57
 
@@ -328,95 +326,68 @@ static int write_to_ec(u8 reg, u8 value)
 	return ret;
 }
 
-/* Turbo button toggle functions */
-static int tt_toggle_enable(void)
+/* Callbacks for turbo toggle attribute */
+static umode_t tt_toggle_is_visible(struct kobject *kobj,
+				    struct attribute *attr, int n)
 {
-	u8 reg;
-	u8 val;
-
 	switch (board) {
-	case oxp_mini_amd_a07:
-		reg = OXP_MINI_TURBO_SWITCH_REG;
-		val = OXP_MINI_TURBO_TAKE_VAL;
-		break;
 	case aok_zoe_a1:
+	case oxp_2:
 	case oxp_fly:
+	case oxp_mini_amd_a07:
 	case oxp_mini_amd_pro:
-		reg = OXP_TURBO_SWITCH_REG;
-		val = OXP_TURBO_TAKE_VAL;
-		break;
-	case oxp_2:
 	case oxp_x1:
-		reg = OXP_2_TURBO_SWITCH_REG;
-		val = OXP_TURBO_TAKE_VAL;
-		break;
+		return attr->mode;
 	default:
-		return -EINVAL;
+		break;
 	}
-	return write_to_ec(reg, val);
+	return 0;
 }
 
-static int tt_toggle_disable(void)
+static ssize_t tt_toggle_store(struct device *dev,
+			       struct device_attribute *attr, const char *buf,
+			       size_t count)
 {
-	u8 reg;
-	u8 val;
+	u8 reg, mask, val;
+	long raw_val;
+	bool enable;
+	int ret;
+
+	ret = kstrtobool(buf, &enable);
+	if (ret)
+		return ret;
 
 	switch (board) {
 	case oxp_mini_amd_a07:
 		reg = OXP_MINI_TURBO_SWITCH_REG;
-		val = OXP_TURBO_RETURN_VAL;
+		mask = OXP_MINI_TURBO_TAKE_VAL;
 		break;
 	case aok_zoe_a1:
 	case oxp_fly:
 	case oxp_mini_amd_pro:
 		reg = OXP_TURBO_SWITCH_REG;
-		val = OXP_TURBO_RETURN_VAL;
+		mask = OXP_TURBO_TAKE_VAL;
 		break;
 	case oxp_2:
 	case oxp_x1:
 		reg = OXP_2_TURBO_SWITCH_REG;
-		val = OXP_TURBO_RETURN_VAL;
+		mask = OXP_TURBO_TAKE_VAL;
 		break;
 	default:
 		return -EINVAL;
 	}
-	return write_to_ec(reg, val);
-}
-
-/* Callbacks for turbo toggle attribute */
-static umode_t tt_toggle_is_visible(struct kobject *kobj,
-				    struct attribute *attr, int n)
-{
-	switch (board) {
-	case aok_zoe_a1:
-	case oxp_2:
-	case oxp_fly:
-	case oxp_mini_amd_a07:
-	case oxp_mini_amd_pro:
-	case oxp_x1:
-		return attr->mode;
-	default:
-		break;
-	}
-	return 0;
-}
 
-static ssize_t tt_toggle_store(struct device *dev,
-			       struct device_attribute *attr, const char *buf,
-			       size_t count)
-{
-	bool value;
-	int ret;
-
-	ret = kstrtobool(buf, &value);
+	ret = read_from_ec(reg, 1, &raw_val);
 	if (ret)
 		return ret;
 
-	if (value) {
-		ret = tt_toggle_enable();
-	} else {
-		ret = tt_toggle_disable();
-	}
+	val = raw_val;
+	if (enable)
+		val |= mask;
+	else
+		val &= ~mask;
+
+	ret = write_to_ec(reg, val);
 	if (ret)
 		return ret;
 
@@ -426,22 +397,25 @@ static ssize_t tt_toggle_store(struct device *dev,
 static ssize_t tt_toggle_show(struct device *dev,
 			      struct device_attribute *attr, char *buf)
 {
+	u8 reg, mask;
 	int retval;
 	long val;
-	u8 reg;
 
 	switch (board) {
 	case oxp_mini_amd_a07:
 		reg = OXP_MINI_TURBO_SWITCH_REG;
+		mask = OXP_MINI_TURBO_TAKE_VAL;
 		break;
 	case aok_zoe_a1:
 	case oxp_fly:
 	case oxp_mini_amd_pro:
 		reg = OXP_TURBO_SWITCH_REG;
+		mask = OXP_TURBO_TAKE_VAL;
 		break;
 	case oxp_2:
 	case oxp_x1:
 		reg = OXP_2_TURBO_SWITCH_REG;
+		mask = OXP_TURBO_TAKE_VAL;
 		break;
 	default:
 		return -EINVAL;
@@ -451,7 +425,7 @@ static ssize_t tt_toggle_show(struct device *dev,
 	if (retval)
 		return retval;
 
-	return sysfs_emit(buf, "%d\n", !!val);
+	return sysfs_emit(buf, "%d\n", (val & mask) == mask);
 }
 
 static DEVICE_ATTR_RW(tt_toggle);
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ