All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU
@ 2023-09-12 11:27 Zenm Chen
  2023-09-13  0:46 ` Ping-Ke Shih
  2023-09-14  3:40 ` Zenm Chen
  0 siblings, 2 replies; 4+ messages in thread
From: Zenm Chen @ 2023-09-12 11:27 UTC (permalink / raw)
  To: Jes.Sorensen
  Cc: kvalo, linux-wireless, linux-kernel, rtl8821cerfe2, pkshih, Zenm Chen

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.
+		 */
+		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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU
  2023-09-12 11:27 [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU Zenm Chen
@ 2023-09-13  0:46 ` Ping-Ke Shih
  2023-09-14  3:40 ` Zenm Chen
  1 sibling, 0 replies; 4+ messages in thread
From: Ping-Ke Shih @ 2023-09-13  0:46 UTC (permalink / raw)
  To: Zenm Chen, Jes.Sorensen
  Cc: kvalo, linux-wireless, linux-kernel, rtl8821cerfe2



> -----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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU
  2023-09-12 11:27 [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU Zenm Chen
  2023-09-13  0:46 ` Ping-Ke Shih
@ 2023-09-14  3:40 ` Zenm Chen
  2023-11-25 18:19   ` Bitterblue Smith
  1 sibling, 1 reply; 4+ messages in thread
From: Zenm Chen @ 2023-09-14  3:40 UTC (permalink / raw)
  To: zenmchen
  Cc: Jes.Sorensen, kvalo, linux-kernel, linux-wireless, pkshih, rtl8821cerfe2

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU
  2023-09-14  3:40 ` Zenm Chen
@ 2023-11-25 18:19   ` Bitterblue Smith
  0 siblings, 0 replies; 4+ messages in thread
From: Bitterblue Smith @ 2023-11-25 18:19 UTC (permalink / raw)
  To: Zenm Chen; +Cc: Jes.Sorensen, kvalo, linux-kernel, linux-wireless, pkshih

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."


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-25 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 11:27 [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU Zenm Chen
2023-09-13  0:46 ` Ping-Ke Shih
2023-09-14  3:40 ` Zenm Chen
2023-11-25 18:19   ` Bitterblue Smith

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.