Skip to contentSkip to conversation

wifi: rtl8xxxu: Fix LED control code of RTL8192FU

PATCH In review Bitterblue Smith 4 participants 4 messages Dec 30, 2023 – Jan 10, 2024 RTL8XXXU wireless driver (rtl8xxxu)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 wifi: rtl8xxxu: Fix LED control code of RTL8192FU

Some devices, like the Comfast CF-826F, use LED1, which already works. Others, like Asus USB-N13 C1, use LED0, which doesn't work correctly.

Write the right values to the LED control registers to make LED0 work as well.

This is unfortunately tested only with the Comfast CF-826F.

---
v3:
- Use more bit definitions.
- Use u32p_replace_bits to touch only the relevant bits.
- New author.

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.

Linking v2 and v1 because it's been a while:
https://lore.kernel.org/linux-wireless/[email protected]/
https://lore.kernel.org/linux-wireless/[email protected]/

---
 .../realtek/rtl8xxxu/rtl8xxxu_8192f.c         | 32 +++++++++++++------
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 15 +++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +23 -9
index 28e93835e05a..585b1a5eed69 100644
@@ -2014,26 +2014,40 @@ 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);
+
+	/* Comfast CF-826F uses LED1. Asus USB-N13 C1 uses LED0. Set both. */
+
+	u32p_replace_bits(&ledcfg, LED_GPIO_ENABLE, LEDCFG0_LED2EN);
+	u32p_replace_bits(&ledcfg, LED_IO_MODE_OUTPUT, LEDCFG0_LED0_IO_MODE);
+	u32p_replace_bits(&ledcfg, LED_IO_MODE_OUTPUT, LEDCFG0_LED1_IO_MODE);
 
 	if (brightness == LED_OFF) {
-		/* Value obtained like above. */
-		ledcfg = BIT(1) | BIT(7);
+		u32p_replace_bits(&ledcfg, LED_MODE_SW_CTRL, LEDCFG0_LED0CM);
+		u32p_replace_bits(&ledcfg, LED_SW_OFF, LEDCFG0_LED0SV);
+		u32p_replace_bits(&ledcfg, LED_MODE_SW_CTRL, LEDCFG0_LED1CM);
+		u32p_replace_bits(&ledcfg, LED_SW_OFF, LEDCFG0_LED1SV);
 	} else if (brightness == LED_ON) {
-		/* Value obtained like above. */
-		ledcfg = BIT(1) | BIT(7) | BIT(11);
+		u32p_replace_bits(&ledcfg, LED_MODE_SW_CTRL, LEDCFG0_LED0CM);
+		u32p_replace_bits(&ledcfg, LED_SW_ON, LEDCFG0_LED0SV);
+		u32p_replace_bits(&ledcfg, LED_MODE_SW_CTRL, LEDCFG0_LED1CM);
+		u32p_replace_bits(&ledcfg, LED_SW_ON, LEDCFG0_LED1SV);
 	} else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
-		/* Value obtained by brute force. */
-		ledcfg = BIT(8) | BIT(9);
+		u32p_replace_bits(&ledcfg, LED_MODE_TX_OR_RX_EVENTS,
+				  LEDCFG0_LED0CM);
+		u32p_replace_bits(&ledcfg, LED_SW_OFF, LEDCFG0_LED0SV);
+		u32p_replace_bits(&ledcfg, LED_MODE_TX_OR_RX_EVENTS,
+				  LEDCFG0_LED1CM);
+		u32p_replace_bits(&ledcfg, LED_SW_OFF, LEDCFG0_LED1SV);
 	}
 
-	rtl8xxxu_write16(priv, REG_LEDCFG0, ledcfg);
+	rtl8xxxu_write32(priv, REG_LEDCFG0, ledcfg);
 
 	return 0;
 }
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +15 -0
index 920ee50e2115..61c0c0ec07b3 100644
@@ -146,6 +146,21 @@
 #define  GPIO_INTM_EDGE_TRIG_IRQ	BIT(9)
 
 #define REG_LEDCFG0			0x004c
+#define  LEDCFG0_LED0CM			GENMASK(2, 0)
+#define  LEDCFG0_LED1CM			GENMASK(10, 8)
+#define   LED_MODE_SW_CTRL		0x0
+#define   LED_MODE_TX_OR_RX_EVENTS	0x3
+#define  LEDCFG0_LED0SV			BIT(3)
+#define  LEDCFG0_LED1SV			BIT(11)
+#define   LED_SW_OFF			0x0
+#define   LED_SW_ON			0x1
+#define  LEDCFG0_LED0_IO_MODE		BIT(7)
+#define  LEDCFG0_LED1_IO_MODE		BIT(15)
+#define   LED_IO_MODE_OUTPUT		0x0
+#define   LED_IO_MODE_INPUT		0x1
+#define  LEDCFG0_LED2EN			BIT(21)
+#define   LED_GPIO_DISABLE		0x0
+#define   LED_GPIO_ENABLE		0x1
 #define  LEDCFG0_DPDT_SELECT		BIT(23)
 #define REG_LEDCFG1			0x004d
 #define  LEDCFG1_HW_LED_CONTROL		BIT(1)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/1 wifi: rtl8xxxu: Fix LED control code of RTL8192FU

Hi,

Thanks for making this patch.
I have no ASUS USB-N13 C1 now, so only tested with MERCUSYS MW310UH.
I think this patch will make the LEDs of ASUS USB-N13 C1/EDIMAX EW-7722UTn V3 work as expected.

Reviewed-by on v3 1/1
#2 lore raw
In reply to Bitterblue Smith
Quoted 13 lines

-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Sunday, December 31, 2023 6:46 AM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Zenm Chen <[email protected]>
Subject: [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU

Some devices, like the Comfast CF-826F, use LED1, which already works. Others, like Asus USB-N13 C1, use LED0, which doesn't work correctly.

Quoted 6 lines

Write the right values to the LED control registers to make LED0 work as well.

This is unfortunately tested only with the Comfast CF-826F.

Thank you and Zenm for this work!

#3 lore raw
In reply to Bitterblue Smith
Quoted 10 lines · Bitterblue Smith

Some devices, like the Comfast CF-826F, use LED1, which already works. Others, like Asus USB-N13 C1, use LED0, which doesn't work correctly.

Write the right values to the LED control registers to make LED0 work as well.

This is unfortunately tested only with the Comfast CF-826F.

Patch applied to wireless-next.git, thanks.

9475cc7ac315 wifi: rtl8xxxu: Fix LED control code of RTL8192FU

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches