Message ID | 20230912112709.22456-1-zenmchen@gmail.com |
---|---|
State | New |
Headers | show |
Series | [v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU | expand |
> -----Original Message----- > From: Zenm Chen <zenmchen@gmail.com> > Sent: Tuesday, September 12, 2023 7:27 PM > To: Jes.Sorensen@gmail.com > Cc: kvalo@kernel.org; linux-wireless@vger.kernel.org; linux-kernel@vger.kernel.org; > rtl8821cerfe2@gmail.com; Ping-Ke Shih <pkshih@realtek.com>; Zenm Chen <zenmchen@gmail.com> > 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) > > Signed-off-by: Zenm Chen <zenmchen@gmail.com> > --- > 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(-) > > diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c > b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c > index 28e93835e05a..779f93afc22b 100644 > --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c > +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c > @@ -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. I suppose this would not be a brute force if you can use register definitions I provided by v1. > + */ > + 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; > } > diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h > b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h > index 920ee50e2115..5ce845f1d069 100644 > --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h > +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h > @@ -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
Ping-Ke Shih <pkshih@realtek.com> wrote: > > 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.
On 14/09/2023 06:40, Zenm Chen wrote: > Ping-Ke Shih <pkshih@realtek.com> wrote: >> >> 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/20230912112709.22456-1-zenmchen@gmail.com/ Perhaps your patch will be accepted if you remove that comment: "The value 0x0303 is obtained by brute force."
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c index 28e93835e05a..779f93afc22b 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c @@ -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; } diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h index 920ee50e2115..5ce845f1d069 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h @@ -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)
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) Signed-off-by: Zenm Chen <zenmchen@gmail.com> --- 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(-)