* [PATCH v2 2/4] wifi: rtl8xxxu: Add LED control code for RTL8188EU
2023-01-20 15:51 [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Bitterblue Smith
@ 2023-01-20 15:52 ` Bitterblue Smith
2023-01-21 7:02 ` Ping-Ke Shih
2023-01-20 15:54 ` [PATCH v2 3/4] wifi: rtl8xxxu: Add LED control code for RTL8192EU Bitterblue Smith
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Bitterblue Smith @ 2023-01-20 15:52 UTC (permalink / raw)
To: linux-wireless; +Cc: Jes Sorensen, Ping-Ke Shih
By default the LED will blink when there is some activity.
This was tested with a TP-Link TL-WN725N.
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
- No change.
---
.../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 25 +++++++++++++++++++
.../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 4 +++
2 files changed, 29 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
index 08f3b93ad8d0..a99ddb41cd24 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
@@ -1350,6 +1350,30 @@ static s8 rtl8188e_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
return rx_pwr_all;
}
+static int rtl8188eu_led_brightness_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ struct rtl8xxxu_priv *priv = container_of(led_cdev,
+ struct rtl8xxxu_priv,
+ led_cdev);
+ u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG2);
+
+ if (brightness == LED_OFF) {
+ ledcfg &= ~LEDCFG2_HW_LED_CONTROL;
+ ledcfg |= LEDCFG2_SW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE;
+ } else if (brightness == LED_ON) {
+ ledcfg &= ~(LEDCFG2_HW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE);
+ ledcfg |= LEDCFG2_SW_LED_CONTROL;
+ } else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
+ ledcfg &= ~LEDCFG2_SW_LED_DISABLE;
+ ledcfg |= LEDCFG2_HW_LED_CONTROL | LEDCFG2_HW_LED_ENABLE;
+ }
+
+ rtl8xxxu_write8(priv, REG_LEDCFG2, ledcfg);
+
+ return 0;
+}
+
static void rtl8188e_set_tx_rpt_timing(struct rtl8xxxu_ra_info *ra, u8 timing)
{
u8 idx;
@@ -1851,6 +1875,7 @@ struct rtl8xxxu_fileops rtl8188eu_fops = {
.fill_txdesc = rtl8xxxu_fill_txdesc_v3,
.set_crystal_cap = rtl8188f_set_crystal_cap,
.cck_rssi = rtl8188e_cck_rssi,
+ .led_classdev_brightness_set = rtl8188eu_led_brightness_set,
.writeN_block_size = 128,
.rx_desc_size = sizeof(struct rtl8xxxu_rxdesc16),
.tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
index 5818b2378bab..d510ce27b1b4 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
@@ -148,6 +148,10 @@
#define LEDCFG0_DPDT_SELECT BIT(23)
#define REG_LEDCFG1 0x004d
#define REG_LEDCFG2 0x004e
+#define LEDCFG2_HW_LED_CONTROL BIT(1)
+#define LEDCFG2_HW_LED_ENABLE BIT(5)
+#define LEDCFG2_SW_LED_DISABLE BIT(3)
+#define LEDCFG2_SW_LED_CONTROL BIT(5)
#define LEDCFG2_DPDT_SELECT BIT(7)
#define REG_LEDCFG3 0x004f
#define REG_LEDCFG REG_LEDCFG2
--
2.39.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] wifi: rtl8xxxu: Add LED control code for RTL8192EU
2023-01-20 15:51 [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Bitterblue Smith
2023-01-20 15:52 ` [PATCH v2 2/4] wifi: rtl8xxxu: Add LED control code for RTL8188EU Bitterblue Smith
@ 2023-01-20 15:54 ` Bitterblue Smith
2023-01-21 7:03 ` Ping-Ke Shih
2023-01-20 15:55 ` [PATCH v2 4/4] wifi: rtl8xxxu: Add LED control code for RTL8723AU Bitterblue Smith
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Bitterblue Smith @ 2023-01-20 15:54 UTC (permalink / raw)
To: linux-wireless; +Cc: Jes Sorensen, Ping-Ke Shih
By default the LED will blink when there is some activity.
This was tested with a cheap "HT-WR813" from Aliexpress.
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
- No change.
---
.../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 24 +++++++++++++++++++
.../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 2 ++
2 files changed, 26 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
index 4a1c9bcafe31..5cfc00237f42 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
@@ -1764,6 +1764,29 @@ static s8 rtl8192e_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
return rx_pwr_all;
}
+static int rtl8192eu_led_brightness_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ struct rtl8xxxu_priv *priv = container_of(led_cdev,
+ struct rtl8xxxu_priv,
+ led_cdev);
+ u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG1);
+
+ if (brightness == LED_OFF) {
+ ledcfg &= ~LEDCFG1_HW_LED_CONTROL;
+ ledcfg |= LEDCFG1_LED_DISABLE;
+ } else if (brightness == LED_ON) {
+ ledcfg &= ~(LEDCFG1_HW_LED_CONTROL | LEDCFG1_LED_DISABLE);
+ } else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
+ ledcfg &= ~LEDCFG1_LED_DISABLE;
+ ledcfg |= LEDCFG1_HW_LED_CONTROL;
+ }
+
+ rtl8xxxu_write8(priv, REG_LEDCFG1, ledcfg);
+
+ return 0;
+}
+
struct rtl8xxxu_fileops rtl8192eu_fops = {
.identify_chip = rtl8192eu_identify_chip,
.parse_efuse = rtl8192eu_parse_efuse,
@@ -1788,6 +1811,7 @@ struct rtl8xxxu_fileops rtl8192eu_fops = {
.fill_txdesc = rtl8xxxu_fill_txdesc_v2,
.set_crystal_cap = rtl8723a_set_crystal_cap,
.cck_rssi = rtl8192e_cck_rssi,
+ .led_classdev_brightness_set = rtl8192eu_led_brightness_set,
.writeN_block_size = 128,
.tx_desc_size = sizeof(struct rtl8xxxu_txdesc40),
.rx_desc_size = sizeof(struct rtl8xxxu_rxdesc24),
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
index d510ce27b1b4..5849fa4e1566 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h
@@ -147,6 +147,8 @@
#define REG_LEDCFG0 0x004c
#define LEDCFG0_DPDT_SELECT BIT(23)
#define REG_LEDCFG1 0x004d
+#define LEDCFG1_HW_LED_CONTROL BIT(1)
+#define LEDCFG1_LED_DISABLE BIT(7)
#define REG_LEDCFG2 0x004e
#define LEDCFG2_HW_LED_CONTROL BIT(1)
#define LEDCFG2_HW_LED_ENABLE BIT(5)
--
2.39.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/4] wifi: rtl8xxxu: Add LED control code for RTL8723AU
2023-01-20 15:51 [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Bitterblue Smith
2023-01-20 15:52 ` [PATCH v2 2/4] wifi: rtl8xxxu: Add LED control code for RTL8188EU Bitterblue Smith
2023-01-20 15:54 ` [PATCH v2 3/4] wifi: rtl8xxxu: Add LED control code for RTL8192EU Bitterblue Smith
@ 2023-01-20 15:55 ` Bitterblue Smith
2023-01-21 7:03 ` Ping-Ke Shih
2023-01-21 7:01 ` [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Ping-Ke Shih
2023-02-13 17:24 ` Kalle Valo
4 siblings, 1 reply; 9+ messages in thread
From: Bitterblue Smith @ 2023-01-20 15:55 UTC (permalink / raw)
To: linux-wireless; +Cc: Jes Sorensen, Ping-Ke Shih
By default the LED will blink when there is some activity.
This is only compile tested.
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
- No change.
---
.../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
index 5ed523db2d87..5e7b58d395ba 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
@@ -457,6 +457,30 @@ s8 rtl8723a_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
return rx_pwr_all;
}
+static int rtl8723au_led_brightness_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ struct rtl8xxxu_priv *priv = container_of(led_cdev,
+ struct rtl8xxxu_priv,
+ led_cdev);
+ u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG2);
+
+ if (brightness == LED_OFF) {
+ ledcfg &= ~LEDCFG2_HW_LED_CONTROL;
+ ledcfg |= LEDCFG2_SW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE;
+ } else if (brightness == LED_ON) {
+ ledcfg &= ~(LEDCFG2_HW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE);
+ ledcfg |= LEDCFG2_SW_LED_CONTROL;
+ } else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
+ ledcfg &= ~LEDCFG2_SW_LED_DISABLE;
+ ledcfg |= LEDCFG2_HW_LED_CONTROL | LEDCFG2_HW_LED_ENABLE;
+ }
+
+ rtl8xxxu_write8(priv, REG_LEDCFG2, ledcfg);
+
+ return 0;
+}
+
struct rtl8xxxu_fileops rtl8723au_fops = {
.identify_chip = rtl8723au_identify_chip,
.parse_efuse = rtl8723au_parse_efuse,
@@ -482,6 +506,7 @@ struct rtl8xxxu_fileops rtl8723au_fops = {
.fill_txdesc = rtl8xxxu_fill_txdesc_v1,
.set_crystal_cap = rtl8723a_set_crystal_cap,
.cck_rssi = rtl8723a_cck_rssi,
+ .led_classdev_brightness_set = rtl8723au_led_brightness_set,
.writeN_block_size = 1024,
.rx_agg_buf_size = 16000,
.tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
--
2.39.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink
2023-01-20 15:51 [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Bitterblue Smith
` (2 preceding siblings ...)
2023-01-20 15:55 ` [PATCH v2 4/4] wifi: rtl8xxxu: Add LED control code for RTL8723AU Bitterblue Smith
@ 2023-01-21 7:01 ` Ping-Ke Shih
2023-02-13 17:24 ` Kalle Valo
4 siblings, 0 replies; 9+ messages in thread
From: Ping-Ke Shih @ 2023-01-21 7:01 UTC (permalink / raw)
To: linux-wireless, rtl8821cerfe2; +Cc: Jes.Sorensen
On Fri, 2023-01-20 at 17:51 +0200, Bitterblue Smith wrote:
> If the chip can have an LED, register a struct led_classdev and enable
> hardware-controlled blinking. When the chip is not transmitting or
> receiving anything the LED is off. Otherwise the LED will blink
> faster or slower according to the throughput.
>
> The LED can be controlled from userspace by writing 0, 1, or 2 to
> /sys/class/leds/rtl8xxxu-usbX-Y/brightness:
> 0 - solid off.
> 1 - solid on.
> 2 - hardware-controlled blinking.
>
> In this patch none of the chips advertise having an LED. That will be
> added in the next patches.
>
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
> ---
> v2:
> - Suggestion from Ping-Ke Shih:
> - Check for led_classdev_brightness_set inside rtl8xxxu_init_led()
> and for led_registered inside rtl8xxxu_deinit_led() instead of
> checking for them in the caller functions.
>
[...]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink
2023-01-20 15:51 [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Bitterblue Smith
` (3 preceding siblings ...)
2023-01-21 7:01 ` [PATCH v2 1/4] wifi: rtl8xxxu: Register the LED and make it blink Ping-Ke Shih
@ 2023-02-13 17:24 ` Kalle Valo
4 siblings, 0 replies; 9+ messages in thread
From: Kalle Valo @ 2023-02-13 17:24 UTC (permalink / raw)
To: Bitterblue Smith; +Cc: linux-wireless, Jes Sorensen, Ping-Ke Shih
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> If the chip can have an LED, register a struct led_classdev and enable
> hardware-controlled blinking. When the chip is not transmitting or
> receiving anything the LED is off. Otherwise the LED will blink
> faster or slower according to the throughput.
>
> The LED can be controlled from userspace by writing 0, 1, or 2 to
> /sys/class/leds/rtl8xxxu-usbX-Y/brightness:
> 0 - solid off.
> 1 - solid on.
> 2 - hardware-controlled blinking.
>
> In this patch none of the chips advertise having an LED. That will be
> added in the next patches.
>
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
4 patches applied to wireless-next.git, thanks.
3be01622995b wifi: rtl8xxxu: Register the LED and make it blink
873b3811728b wifi: rtl8xxxu: Add LED control code for RTL8188EU
ae0a6df673c2 wifi: rtl8xxxu: Add LED control code for RTL8192EU
2cef0aeebf2c wifi: rtl8xxxu: Add LED control code for RTL8723AU
--
https://patchwork.kernel.org/project/linux-wireless/patch/b8235bca-60c3-d0fe-a958-53c6dd3ba3f6@gmail.com/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 9+ messages in thread