* [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU
@ 2023-12-30 22:45 Bitterblue Smith
2024-01-01 5:13 ` Zenm Chen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bitterblue Smith @ 2023-12-30 22:45 UTC (permalink / raw)
To: linux-wireless@vger.kernel.org; +Cc: Jes Sorensen, Ping-Ke Shih, Zenm Chen
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.
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
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/20230912112709.22456-1-zenmchen@gmail.com/
https://lore.kernel.org/linux-wireless/20230910002038.56362-1-zenmchen@gmail.com/
---
.../realtek/rtl8xxxu/rtl8xxxu_8192f.c | 32 +++++++++++++------
.../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 15 +++++++++
2 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c
index 28e93835e05a..585b1a5eed69 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c
@@ -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;
}
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
index 920ee50e2115..61c0c0ec07b3 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU
2023-12-30 22:45 [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU Bitterblue Smith
@ 2024-01-01 5:13 ` Zenm Chen
2024-01-02 1:50 ` Ping-Ke Shih
2024-01-10 14:55 ` Kalle Valo
2 siblings, 0 replies; 4+ messages in thread
From: Zenm Chen @ 2024-01-01 5:13 UTC (permalink / raw)
To: rtl8821cerfe2; +Cc: Jes.Sorensen, linux-wireless, pkshih, zenmchen
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU
2023-12-30 22:45 [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU Bitterblue Smith
2024-01-01 5:13 ` Zenm Chen
@ 2024-01-02 1:50 ` Ping-Ke Shih
2024-01-10 14:55 ` Kalle Valo
2 siblings, 0 replies; 4+ messages in thread
From: Ping-Ke Shih @ 2024-01-02 1:50 UTC (permalink / raw)
To: Bitterblue Smith, linux-wireless@vger.kernel.org; +Cc: Jes Sorensen, Zenm Chen
> -----Original Message-----
> From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> Sent: Sunday, December 31, 2023 6:46 AM
> To: linux-wireless@vger.kernel.org
> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>; Ping-Ke Shih <pkshih@realtek.com>; Zenm Chen
> <zenmchen@gmail.com>
> 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.
>
> 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.
>
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Thank you and Zenm for this work!
Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU
2023-12-30 22:45 [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU Bitterblue Smith
2024-01-01 5:13 ` Zenm Chen
2024-01-02 1:50 ` Ping-Ke Shih
@ 2024-01-10 14:55 ` Kalle Valo
2 siblings, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2024-01-10 14:55 UTC (permalink / raw)
To: Bitterblue Smith
Cc: linux-wireless@vger.kernel.org, Jes Sorensen, Ping-Ke Shih,
Zenm Chen
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> 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.
>
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
Patch applied to wireless-next.git, thanks.
9475cc7ac315 wifi: rtl8xxxu: Fix LED control code of RTL8192FU
--
https://patchwork.kernel.org/project/linux-wireless/patch/7a2c3158-3a45-4466-b11e-fc09802b20e2@gmail.com/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-10 14:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-30 22:45 [PATCH v3] wifi: rtl8xxxu: Fix LED control code of RTL8192FU Bitterblue Smith
2024-01-01 5:13 ` Zenm Chen
2024-01-02 1:50 ` Ping-Ke Shih
2024-01-10 14:55 ` Kalle Valo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox