-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wifi: rtw88: Add support for LED blinking
Register a struct led_classdev with the kernel's LED subsystem and create a throughput-based trigger for it. Then mac80211 makes the LED blink. Tested with Tenda U12 (RTL8812AU), Tenda U9 (RTL8811CU), TP-Link Archer T2U Nano (RTL8811AU), TP-Link Archer T3U Plus (RTL8812BU), Edimax EW-7611UCB (RTL8821AU), LM842 (RTL8822CU). Also tested with devices which don't have LEDs: the laptop's internal RTL8822CE and a no-name RTL8723DU. Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com> Acked-by: Ping-Ke Shih <pkshih@realtek.com> Signed-off-by: Ping-Ke Shih <pkshih@realtek.com> Link: https://patch.msgid.link/6c43451f-ab2f-4e76-ac6e-ff5a18dd981d@gmail.com
- Loading branch information
Bitterblue Smith
authored and
Ping-Ke Shih
committed
Jan 12, 2025
1 parent
fb2fcfb
commit 4b6652b
Showing
11 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause | ||
/* Copyright(c) 2025 Realtek Corporation | ||
*/ | ||
|
||
#include "main.h" | ||
#include "debug.h" | ||
#include "led.h" | ||
|
||
static int rtw_led_set_blocking(struct led_classdev *led, | ||
enum led_brightness brightness) | ||
{ | ||
struct rtw_dev *rtwdev = container_of(led, struct rtw_dev, led_cdev); | ||
|
||
rtwdev->chip->ops->led_set(led, brightness); | ||
|
||
return 0; | ||
} | ||
|
||
void rtw_led_init(struct rtw_dev *rtwdev) | ||
{ | ||
static const struct ieee80211_tpt_blink rtw_tpt_blink[] = { | ||
{ .throughput = 0 * 1024, .blink_time = 334 }, | ||
{ .throughput = 1 * 1024, .blink_time = 260 }, | ||
{ .throughput = 5 * 1024, .blink_time = 220 }, | ||
{ .throughput = 10 * 1024, .blink_time = 190 }, | ||
{ .throughput = 20 * 1024, .blink_time = 170 }, | ||
{ .throughput = 50 * 1024, .blink_time = 150 }, | ||
{ .throughput = 70 * 1024, .blink_time = 130 }, | ||
{ .throughput = 100 * 1024, .blink_time = 110 }, | ||
{ .throughput = 200 * 1024, .blink_time = 80 }, | ||
{ .throughput = 300 * 1024, .blink_time = 50 }, | ||
}; | ||
struct led_classdev *led = &rtwdev->led_cdev; | ||
int err; | ||
|
||
if (!rtwdev->chip->ops->led_set) | ||
return; | ||
|
||
if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_PCIE) | ||
led->brightness_set = rtwdev->chip->ops->led_set; | ||
else | ||
led->brightness_set_blocking = rtw_led_set_blocking; | ||
|
||
snprintf(rtwdev->led_name, sizeof(rtwdev->led_name), | ||
"rtw88-%s", dev_name(rtwdev->dev)); | ||
|
||
led->name = rtwdev->led_name; | ||
led->max_brightness = LED_ON; | ||
led->default_trigger = | ||
ieee80211_create_tpt_led_trigger(rtwdev->hw, | ||
IEEE80211_TPT_LEDTRIG_FL_RADIO, | ||
rtw_tpt_blink, | ||
ARRAY_SIZE(rtw_tpt_blink)); | ||
|
||
err = led_classdev_register(rtwdev->dev, led); | ||
if (err) { | ||
rtw_warn(rtwdev, "Failed to register the LED, error %d\n", err); | ||
return; | ||
} | ||
|
||
rtwdev->led_registered = true; | ||
} | ||
|
||
void rtw_led_deinit(struct rtw_dev *rtwdev) | ||
{ | ||
struct led_classdev *led = &rtwdev->led_cdev; | ||
|
||
if (!rtwdev->led_registered) | ||
return; | ||
|
||
rtwdev->chip->ops->led_set(led, LED_OFF); | ||
led_classdev_unregister(led); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ | ||
/* Copyright(c) 2025 Realtek Corporation | ||
*/ | ||
|
||
#ifndef __RTW_LED_H | ||
#define __RTW_LED_H | ||
|
||
#ifdef CONFIG_LEDS_CLASS | ||
|
||
void rtw_led_init(struct rtw_dev *rtwdev); | ||
void rtw_led_deinit(struct rtw_dev *rtwdev); | ||
|
||
#else | ||
|
||
static inline void rtw_led_init(struct rtw_dev *rtwdev) | ||
{ | ||
} | ||
|
||
static inline void rtw_led_deinit(struct rtw_dev *rtwdev) | ||
{ | ||
} | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters