Skip to contentSkip to conversation

platform/x86: asus-wmi: Fix setting RGB mode on some TUF laptops

PATCH Superseded Kristian Angelov 3 participants 7 messages Jul 14, 2023 – Jul 16, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86: asus-wmi: Fix setting RGB mode on some TUF laptops

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

---
V1 -> V2. Make setting 0xb3 and 0xb4 the default logic

 drivers/platform/x86/asus-wmi.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +11 -2
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct device *dev,
 				 struct device_attribute *attr,
 				 const char *buf, size_t count)
 {
-	u32 cmd, mode, r, g,  b,  speed;
+	u32 cmd, mode, r, g, b, speed;
 	int err;
 
 	if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed) != 6)
 		return -EINVAL;
 
-	cmd = !!cmd;
+	/* B3 is set and B4 is save to BIOS. Only set by default*/
+	switch (cmd) {
+	default:
+	case 0:
+		cmd = 0xb3;
+		break;
+	case 1:
+		cmd = 0xb4;
+		break;
+	}
 
 	/* These are the known usable modes across all TUF/ROG */
 	if (mode >= 12 || mode == 9)
Signature · 1 line
2.40.0
#1 lore raw

Hi Kristian,

Quoted 27 lines · Kristian Angelov

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

---
V1 -> V2. Make setting 0xb3 and 0xb4 the default logic

 drivers/platform/x86/asus-wmi.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -2
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct device *dev,
 				 struct device_attribute *attr,
 				 const char *buf, size_t count)
 {
-	u32 cmd, mode, r, g,  b,  speed;
+	u32 cmd, mode, r, g, b, speed;
 	int err;
 
 	if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed) != 6)
 		return -EINVAL;
 
-	cmd = !!cmd;

drivers/platform/x86/asus-wmi.c static ssize_t kbd_rgb_mode_store(struct device *dev, · line 756

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10 -0
+	/* B3 is set and B4 is save to BIOS. Only set by default*/
+	switch (cmd) {
+	default:
+	case 0:
+		cmd = 0xb3;
+		break;
+	case 1:
+		cmd = 0xb4;
+		break;
+	}

You are now leaving the value of cmd unmodified for values which are not 0 and 1.

I think you need to add a:

	default:
		return -EINVAL;

here to catch cmd not being either 0 or 1.

Luke, what do you think ?

Regards,

Hans

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +0 -0
 	/* These are the known usable modes across all TUF/ROG */
 	if (mode >= 12 || mode == 9)
maintainer
#2 lore raw
Quoted 48 lines · Hans de Goede

Hi Kristian,

Quoted 33 lines · Kristian Angelov

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

Closes:
https://lore.kernel.org/platform-driver-x86/[email protected]

---
 V1 -> V2. Make setting 0xb3 and 0xb4 the default logic
 drivers/platform/x86/asus-wmi.c | 13 +++++++++++--

 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct
 device *dev,
                                  struct device_attribute *attr,
                                  const char *buf, size_t count)
  {
-       u32 cmd, mode, r, g,  b,  speed;
+       u32 cmd, mode, r, g, b, speed;
         int err;


        if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed) != 6)
                return -EINVAL;

-       cmd = !!cmd;
+       /* B3 is set and B4 is save to BIOS. Only set by default*/ +       switch (cmd) {

Quoted 8 lines

+       default:
+       case 0:
+               cmd = 0xb3;
+               break;
+       case 1:
+               cmd = 0xb4;
+               break;
+       }

You are now leaving the value of cmd unmodified for values which are not 0 and 1.

Quoted 8 lines

I think you need to add a:

        default:
                return -EINVAL;

here to catch cmd not being either 0 or 1.

Luke, what do you think ?

Looks fine to me.

Quoted 11 lines

Regards,

Hans

Quoted 3 lines


        /* These are the known usable modes across all TUF/ROG */ if (mode >= 12 || mode == 9)

#3 lore raw

Hi,

Quoted 51 lines · Luke Jones
Quoted 50 lines · Hans de Goede

Hi Kristian,

Quoted 33 lines · Kristian Angelov

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

Closes:
https://lore.kernel.org/platform-driver-x86/[email protected]

---
 V1 -> V2. Make setting 0xb3 and 0xb4 the default logic
 drivers/platform/x86/asus-wmi.c | 13 +++++++++++--

 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct
 device *dev,
                                  struct device_attribute *attr,
                                  const char *buf, size_t count)
  {
-       u32 cmd, mode, r, g,  b,  speed;
+       u32 cmd, mode, r, g, b, speed;
         int err;


        if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed) != 6)
                return -EINVAL;

-       cmd = !!cmd;
+       /* B3 is set and B4 is save to BIOS. Only set by default*/ +       switch (cmd) {

Quoted 8 lines

+       default:
+       case 0:
+               cmd = 0xb3;
+               break;
+       case 1:
+               cmd = 0xb4;
+               break;
+       }

You are now leaving the value of cmd unmodified for values which are not 0 and 1.

I think you need to add a:

Quoted 8 lines
Quoted 6 lines

        default:
                return -EINVAL;

here to catch cmd not being either 0 or 1.

Luke, what do you think ?

Looks fine to me.

Fine with or without the default: return -EINVAL; added ?

Quoted 1 line

I guess you mean Reviewed-by ?

Regards,

Hans

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

        /* These are the known usable modes across all TUF/ROG */ if (mode >= 12 || mode == 9)

maintainer
#4 lore raw
Quoted 61 lines

Hi,

Quoted 58 lines · Luke Jones
Quoted 57 lines · Hans de Goede

Hi Kristian,

Quoted 36 lines · Kristian Angelov

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

Closes:
https://lore.kernel.org/platform-driver-x86/[email protected]

---
 V1 -> V2. Make setting 0xb3 and 0xb4 the default logic
 drivers/platform/x86/asus-wmi.c | 13 +++++++++++--

 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct
 device *dev,
                                  struct device_attribute *attr,
                                  const char *buf, size_t count)
  {
-       u32 cmd, mode, r, g,  b,  speed;
+       u32 cmd, mode, r, g, b, speed;
         int err;


        if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g,
&b, &speed) != 6)
                return -EINVAL;

-       cmd = !!cmd;
+       /* B3 is set and B4 is save to BIOS. Only set by default*/
+       switch (cmd) {

Quoted 8 lines

+       default:
+       case 0:
+               cmd = 0xb3;
+               break;
+       case 1:
+               cmd = 0xb4;
+               break;
+       }

You are now leaving the value of cmd unmodified for values which are
not 0 and 1.

I think you need to add a:

        default:
                return -EINVAL;

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

here to catch cmd not being either 0 or 1.

Luke, what do you think ?

Looks fine to me.

Fine with or without the default: return -EINVAL; added ?

Sorry, i wasn't very clear at all. With -EINVAL. I don't see any reason it should continue with un-initialised cmd, or a default value as a default might give false expectations.

Quoted 4 lines
Quoted 2 lines

I guess you mean Reviewed-by ?

Yes sorry, I shouldn't have even added that. I will add review for V3.

Quoted 14 lines

Regards,

Hans

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

        /* These are the known usable modes across all TUF/ROG */
        if (mode >= 12 || mode == 9)

#5 lore raw
Quoted 47 lines · Hans de Goede

Hi Kristian,

Quoted 27 lines · Kristian Angelov

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

---
  V1 -> V2. Make setting 0xb3 and 0xb4 the default logic
  drivers/platform/x86/asus-wmi.c | 13 +++++++++++--

  1 file changed, 11 insertions(+), 2 deletions(-)

drivers/platform/x86/asus-wmi.c +1 -1
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct device *dev,
   				 struct device_attribute *attr,
   				 const char *buf, size_t count)
   {
-	u32 cmd, mode, r, g,  b,  speed;
+	u32 cmd, mode, r, g, b, speed;
   	int err;


  if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed) != 6) return -EINVAL;

drivers/platform/x86/asus-wmi.c +0 -1
-	cmd = !!cmd;

drivers/platform/x86/asus-wmi.c static ssize_t kbd_rgb_mode_store(struct device *dev, · line 756

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10 -0
+	/* B3 is set and B4 is save to BIOS. Only set by default*/
+	switch (cmd) {
+	default:
+	case 0:
+		cmd = 0xb3;
+		break;
+	case 1:
+		cmd = 0xb4;
+		break;
+	}


You are now leaving the value of cmd unmodified for values which are not 0 and 1.
I think you need to add a:

  default:
  return -EINVAL;

Quoted 8 lines


here to catch cmd not being either 0 or 1.

Luke, what do you think ?

Regards,

Hans

Hi Hans,

If you would notice I did:

Quoted 5 lines
	switch (cmd) {
	default:
	case 0:
		cmd = 0xb3;
		break;

In the case of cmd not being 1 or 0. It would default to 0 which would only set the RGB mode, not save it to BIOS. I guess this would depend on preference. Is it better to fail out on invalid input or simply ignore it and perform the "default" action. Setting the RGB mode is not persistent, only saving it is. So defaulting to this seems reasonable, but if not I'll do a v3 with EINVAL fail.

Best regards,

Kristian

maintainer
#6 lore raw
Quoted 76 lines · Kristian Angelov
Quoted 54 lines · Hans de Goede

Hi Kristian,

Quoted 35 lines · Kristian Angelov

This patch fixes setting the cmd values to 0xb3 and 0xb4. This is necessary on some TUF laptops in order to set the RGB mode.

Closes:
https://lore.kernel.org/platform-driver-x86/[email protected]

---
  V1 -> V2. Make setting 0xb3 and 0xb4 the default logic
  drivers/platform/x86/asus-wmi.c | 13 +++++++++++--

  1 file changed, 11 insertions(+), 2 deletions(-)

drivers/platform/x86/asus-wmi.c +1 -1
index 1038dfdcdd32..eb82ed723b42 100644
@@ -738,13 +738,22 @@ static ssize_t kbd_rgb_mode_store(struct
 device *dev,
                                  struct device_attribute *attr,
                                  const char *buf, size_t count)
   {
-       u32 cmd, mode, r, g,  b,  speed;
+       u32 cmd, mode, r, g, b, speed;
         int err;


        if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed) != 6)
                return -EINVAL;

-       cmd = !!cmd;
+       /* B3 is set and B4 is save to BIOS. Only set by default*/
+       switch (cmd) {

Quoted 8 lines

+       default:
+       case 0:
+               cmd = 0xb3;
+               break;
+       case 1:
+               cmd = 0xb4;
+               break;
+       }


You are now leaving the value of cmd unmodified for values which are not 0 and 1.

I think you need to add a:

        default:
                return -EINVAL;

Quoted 8 lines


here to catch cmd not being either 0 or 1.

Luke, what do you think ?

Regards,

Hans

Hi Hans,

If you would notice I did:

Quoted 5 lines

        switch (cmd) {
        default:
        case 0:
                cmd = 0xb3;
                break;

Quoted 10 lines

In the case of cmd not being 1 or 0. It would default to 0 which would only set
the RGB mode, not save it to BIOS. I guess this would depend on preference.
Is it better to fail out on invalid input or simply ignore it and perform the
"default" action. Setting the RGB mode is not persistent, only saving it is. So
defaulting to this seems reasonable, but if not I'll do a v3 with EINVAL fail.

Much of, if not all of asus-wmi follows a strict i/o and will EINVAL if the input is not correct. It would be best to keep this behaviour consistent. It would be misleading to folks if any value except 1 produced the same result, and then if there was reason to make a 2 produce some other effect then it breaks someone's expectation somewhere.