Skip to contentSkip to conversation

wifi: rtl8xxxu: fix LED control code of RTL8192FU

PATCH Superseded Zenm Chen 3 participants 4 messages Sep 12, 2023 – Nov 25, 2023 RTL8XXXU wireless driver (rtl8xxxu)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zenm Chen

author
#0 lore raw

PATCH v2 1/1 wifi: rtl8xxxu: fix LED control code of RTL8192FU

Some of the RTL8192FU-based wifi adapters use the register "REG_LEDCFG1" to control the LED, and some of them use the register "REG_LEDCFG0" instead. Currently rtl8xxxu controls the LED via writing the values to the register "REG_LEDCFG1" only. This caused a few RTL8192FU-based wifi adapters's LED don't blink according to the network activity. This patch will make rtl8xxxu write the correct values to the both register "REG_LEDCFG0" and "REG_LEDCFG1" to fix this issue.

This was tested with these two wifi adapters:
ASUS USB-N13 C1 (vid=0x0b05, pid=0x18f1, rfe_type=0x1)
MERCURY MW310UH (vid=0x0bda, pid=0xf192, rfe_type=0x5)

---
v2:
- Explain why to fix the issue in this way in the commit message.
- Split a long statement into short ones.
- Use some of the definitions suggested by Ping-Ke Shih.

---
 .../realtek/rtl8xxxu/rtl8xxxu_8192f.c         | 26 ++++++++++++-------
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h |  3 +++
 2 files changed, 20 insertions(+), 9 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +17 -9
index 28e93835e05a..779f93afc22b 100644
@@ -2014,26 +2014,34 @@ static int rtl8192fu_led_brightness_set(struct led_classdev *led_cdev,
 	struct rtl8xxxu_priv *priv = container_of(led_cdev,
 						  struct rtl8xxxu_priv,
 						  led_cdev);
-	u16 ledcfg;
+	u32 ledcfg;
 
 	/* Values obtained by observing the USB traffic from the Windows driver. */
 	rtl8xxxu_write32(priv, REG_SW_GPIO_SHARE_CTRL_0, 0x20080);
 	rtl8xxxu_write32(priv, REG_SW_GPIO_SHARE_CTRL_1, 0x1b0000);
 
-	ledcfg = rtl8xxxu_read16(priv, REG_LEDCFG0);
+	ledcfg = rtl8xxxu_read32(priv, REG_LEDCFG0);
+
+	/* Set LED0 GPIO enabled */
+	ledcfg |= LEDCFG0_LED0_GPIO_ENABLE;
 
 	if (brightness == LED_OFF) {
-		/* Value obtained like above. */
-		ledcfg = BIT(1) | BIT(7);
+		/* Setting REG_LEDCFG0[15:0] to 0x0000 turns LED0/LED1 off. */
+		ledcfg &= ~GENMASK(15, 0);
 	} else if (brightness == LED_ON) {
-		/* Value obtained like above. */
-		ledcfg = BIT(1) | BIT(7) | BIT(11);
+		/* Setting REG_LEDCFG0[15:0] to 0x0808 turns LED0/LED1 on. */
+		ledcfg &= ~GENMASK(15, 0);
+		ledcfg |= LEDCFG0_LED1SV | LEDCFG0_LED0SV;
 	} else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
-		/* Value obtained by brute force. */
-		ledcfg = BIT(8) | BIT(9);
+		/* Setting REG_LEDCFG0[15:0] to 0x0303 enables
+		 * hardware-controlled blinking for LED0/LED1.
+		 * The value 0x0303 is obtained by brute force.
+		 */
+		ledcfg &= ~GENMASK(15, 0);
+		ledcfg |= BIT(9) | BIT(8) | BIT(1) | BIT(0);
 	}
 
-	rtl8xxxu_write16(priv, REG_LEDCFG0, ledcfg);
+	rtl8xxxu_write32(priv, REG_LEDCFG0, ledcfg);
 
 	return 0;
 }
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +3 -0
index 920ee50e2115..5ce845f1d069 100644
@@ -146,6 +146,9 @@
 #define  GPIO_INTM_EDGE_TRIG_IRQ	BIT(9)
 
 #define REG_LEDCFG0			0x004c
+#define  LEDCFG0_LED0SV			BIT(3)
+#define  LEDCFG0_LED1SV			BIT(11)
+#define  LEDCFG0_LED0_GPIO_ENABLE	BIT(21)
 #define  LEDCFG0_DPDT_SELECT		BIT(23)
 #define REG_LEDCFG1			0x004d
 #define  LEDCFG1_HW_LED_CONTROL		BIT(1)
Signature · 1 line
2.42.0
#1 lore raw
Quoted 62 lines

-----Original Message-----
From: Zenm Chen <[email protected]>
Sent: Tuesday, September 12, 2023 7:27 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ping-Ke Shih <[email protected]>; Zenm Chen <[email protected]>
Subject: [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU

Some of the RTL8192FU-based wifi adapters use the register "REG_LEDCFG1" to control the LED, and some of them use the register "REG_LEDCFG0" instead. Currently rtl8xxxu controls the LED via writing the values to the register "REG_LEDCFG1" only. This caused a few RTL8192FU-based wifi adapters's LED don't blink according to the network activity. This patch will make rtl8xxxu write the correct values to the both register "REG_LEDCFG0" and "REG_LEDCFG1" to fix this issue.

This was tested with these two wifi adapters:
ASUS USB-N13 C1 (vid=0x0b05, pid=0x18f1, rfe_type=0x1) MERCURY MW310UH (vid=0x0bda, pid=0xf192, rfe_type=0x5)

---
v2:
- Explain why to fix the issue in this way in the commit message.
- Split a long statement into short ones.
- Use some of the definitions suggested by Ping-Ke Shih.

---
 .../realtek/rtl8xxxu/rtl8xxxu_8192f.c         | 26 ++++++++++++-------
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h |  3 +++
 2 files changed, 20 insertions(+), 9 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +7 -5
index 28e93835e05a..779f93afc22b 100644
@@ -2014,26 +2014,34 @@ static int rtl8192fu_led_brightness_set(struct led_classdev *led_cdev,
        struct rtl8xxxu_priv *priv = container_of(led_cdev,
                                                  struct rtl8xxxu_priv,
                                                  led_cdev);
-       u16 ledcfg;
+       u32 ledcfg;
 
        /* Values obtained by observing the USB traffic from the Windows driver. */
        rtl8xxxu_write32(priv, REG_SW_GPIO_SHARE_CTRL_0, 0x20080);
        rtl8xxxu_write32(priv, REG_SW_GPIO_SHARE_CTRL_1, 0x1b0000);
 
-       ledcfg = rtl8xxxu_read16(priv, REG_LEDCFG0);
+       ledcfg = rtl8xxxu_read32(priv, REG_LEDCFG0);
+
+       /* Set LED0 GPIO enabled */
+       ledcfg |= LEDCFG0_LED0_GPIO_ENABLE;
 
        if (brightness == LED_OFF) {
-               /* Value obtained like above. */
-               ledcfg = BIT(1) | BIT(7);
+               /* Setting REG_LEDCFG0[15:0] to 0x0000 turns LED0/LED1 off. */
+               ledcfg &= ~GENMASK(15, 0);
        } else if (brightness == LED_ON) {
-               /* Value obtained like above. */

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c static int rtl8192fu_led_brightness_set(struct led_classdev *led_cdev, · line 2038

Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +6 -3
-               ledcfg = BIT(1) | BIT(7) | BIT(11);
+               /* Setting REG_LEDCFG0[15:0] to 0x0808 turns LED0/LED1 on. */
+               ledcfg &= ~GENMASK(15, 0);
+               ledcfg |= LEDCFG0_LED1SV | LEDCFG0_LED0SV;
        } else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
-               /* Value obtained by brute force. */
-               ledcfg = BIT(8) | BIT(9);
+               /* Setting REG_LEDCFG0[15:0] to 0x0303 enables
+                * hardware-controlled blinking for LED0/LED1.
+                * The value 0x0303 is obtained by brute force.

I suppose this would not be a brute force if you can use register definitions I provided by v1.

Quoted 27 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +4 -1
+                */
+               ledcfg &= ~GENMASK(15, 0);
+               ledcfg |= BIT(9) | BIT(8) | BIT(1) | BIT(0);
        }
 
-       rtl8xxxu_write16(priv, REG_LEDCFG0, ledcfg);
+       rtl8xxxu_write32(priv, REG_LEDCFG0, ledcfg);
 
        return 0;
 }
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +3 -1
index 920ee50e2115..5ce845f1d069 100644
@@ -146,6 +146,9 @@
 #define  GPIO_INTM_EDGE_TRIG_IRQ       BIT(9)
 
 #define REG_LEDCFG0                    0x004c
+#define  LEDCFG0_LED0SV                        BIT(3)
+#define  LEDCFG0_LED1SV                        BIT(11)
+#define  LEDCFG0_LED0_GPIO_ENABLE      BIT(21)
 #define  LEDCFG0_DPDT_SELECT           BIT(23)
 #define REG_LEDCFG1                    0x004d
 #define  LEDCFG1_HW_LED_CONTROL                BIT(1)
--

2.42.0

author
#2 lore raw
In reply to Zenm Chen
Quoted 4 lines · Ping-Ke Shih

I suppose this would not be a brute force if you can use register definitions I provided by v1.

Thanks for the help, now I know how to make use of these definations.

#3 lore raw
Quoted 7 lines · Zenm Chen
Quoted 4 lines · Ping-Ke Shih

I suppose this would not be a brute force if you can use register definitions I provided by v1.

Thanks for the help, now I know how to make use of these definations.

Hello!

Currently the status of your patch is "Changes Requested":
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Perhaps your patch will be accepted if you remove that comment:
"The value 0x0303 is obtained by brute force."