From: Zenm Chen <zenmchen@gmail.com>
To: Jes.Sorensen@gmail.com
Cc: kvalo@kernel.org, linux-wireless@vger.kernel.org,
linux-kernel@vger.kernel.org, rtl8821cerfe2@gmail.com,
pkshih@realtek.com, Zenm Chen <zenmchen@gmail.com>
Subject: [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU
Date: Tue, 12 Sep 2023 19:27:09 +0800 [thread overview]
Message-ID: <20230912112709.22456-1-zenmchen@gmail.com> (raw)
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
next reply other threads:[~2023-09-12 11:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 11:27 Zenm Chen [this message]
2023-09-13 0:46 ` [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU Ping-Ke Shih
2023-09-14 3:40 ` Zenm Chen
2023-11-25 18:19 ` Bitterblue Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230912112709.22456-1-zenmchen@gmail.com \
--to=zenmchen@gmail.com \
--cc=Jes.Sorensen@gmail.com \
--cc=kvalo@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=pkshih@realtek.com \
--cc=rtl8821cerfe2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.