]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
platform/x86: oxpec: Make turbo val apply a bitmask
authorAntheas Kapenekakis <lkml@antheas.dev>
Sat, 26 Apr 2025 17:29:54 +0000 (19:29 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 8 May 2025 13:03:51 +0000 (16:03 +0300)
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@pm.me>
Suggested-by: Joshua Tam <csinaction@pm.me>
Signed-off-by: Joshua Tam <csinaction@pm.me>
Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
Link: https://lore.kernel.org/r/20250426172955.13957-2-lkml@antheas.dev
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/oxpec.c

index de70ca7e84938a04f00cfad5455ba18779ac6145..2f3d895403e76f37411ebd82f607200e009289a5 100644 (file)
@@ -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);