1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* Copyright(c) 2025 Realtek Corporation 3 */ 4 5 #include "main.h" 6 #include "debug.h" 7 #include "led.h" 8 9 static int rtw_led_set_blocking(struct led_classdev *led, 10 enum led_brightness brightness) 11 { 12 struct rtw_dev *rtwdev = container_of(led, struct rtw_dev, led_cdev); 13 14 rtwdev->chip->ops->led_set(led, brightness); 15 16 return 0; 17 } 18 19 void rtw_led_init(struct rtw_dev *rtwdev) 20 { 21 static const struct ieee80211_tpt_blink rtw_tpt_blink[] = { 22 { .throughput = 0 * 1024, .blink_time = 334 }, 23 { .throughput = 1 * 1024, .blink_time = 260 }, 24 { .throughput = 5 * 1024, .blink_time = 220 }, 25 { .throughput = 10 * 1024, .blink_time = 190 }, 26 { .throughput = 20 * 1024, .blink_time = 170 }, 27 { .throughput = 50 * 1024, .blink_time = 150 }, 28 { .throughput = 70 * 1024, .blink_time = 130 }, 29 { .throughput = 100 * 1024, .blink_time = 110 }, 30 { .throughput = 200 * 1024, .blink_time = 80 }, 31 { .throughput = 300 * 1024, .blink_time = 50 }, 32 }; 33 struct led_classdev *led = &rtwdev->led_cdev; 34 int err; 35 36 if (!rtwdev->chip->ops->led_set) 37 return; 38 39 if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_PCIE) 40 led->brightness_set = rtwdev->chip->ops->led_set; 41 else 42 led->brightness_set_blocking = rtw_led_set_blocking; 43 44 snprintf(rtwdev->led_name, sizeof(rtwdev->led_name), 45 "rtw88-%s", dev_name(rtwdev->dev)); 46 47 led->name = rtwdev->led_name; 48 led->max_brightness = LED_ON; 49 led->default_trigger = 50 ieee80211_create_tpt_led_trigger(rtwdev->hw, 51 IEEE80211_TPT_LEDTRIG_FL_RADIO, 52 rtw_tpt_blink, 53 ARRAY_SIZE(rtw_tpt_blink)); 54 55 err = led_classdev_register(rtwdev->dev, led); 56 if (err) { 57 rtw_warn(rtwdev, "Failed to register the LED, error %d\n", err); 58 return; 59 } 60 61 rtwdev->led_registered = true; 62 } 63 64 void rtw_led_deinit(struct rtw_dev *rtwdev) 65 { 66 struct led_classdev *led = &rtwdev->led_cdev; 67 68 if (!rtwdev->led_registered) 69 return; 70 71 rtwdev->chip->ops->led_set(led, LED_OFF); 72 led_classdev_unregister(led); 73 } 74