File Index
Files and directories
Sign in
FILE

led.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/wireless/realtek/rtw88/led.c C
 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
 9static int rtw_led_set(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	mutex_lock(&rtwdev->mutex);
15
16	rtwdev->chip->ops->led_set(led, brightness);
17
18	mutex_unlock(&rtwdev->mutex);
19
20	return 0;
21}
22
23void rtw_led_init(struct rtw_dev *rtwdev)
24{
25	static const struct ieee80211_tpt_blink rtw_tpt_blink[] = {
26		{ .throughput = 0 * 1024, .blink_time = 334 },
27		{ .throughput = 1 * 1024, .blink_time = 260 },
28		{ .throughput = 5 * 1024, .blink_time = 220 },
29		{ .throughput = 10 * 1024, .blink_time = 190 },
30		{ .throughput = 20 * 1024, .blink_time = 170 },
31		{ .throughput = 50 * 1024, .blink_time = 150 },
32		{ .throughput = 70 * 1024, .blink_time = 130 },
33		{ .throughput = 100 * 1024, .blink_time = 110 },
34		{ .throughput = 200 * 1024, .blink_time = 80 },
35		{ .throughput = 300 * 1024, .blink_time = 50 },
36	};
37	struct led_classdev *led = &rtwdev->led_cdev;
38	int err;
39
40	if (!rtwdev->chip->ops->led_set)
41		return;
42
43	led->brightness_set_blocking = rtw_led_set;
44
45	snprintf(rtwdev->led_name, sizeof(rtwdev->led_name),
46		 "rtw88-%s", dev_name(rtwdev->dev));
47
48	led->name = rtwdev->led_name;
49	led->max_brightness = LED_ON;
50	led->default_trigger =
51		ieee80211_create_tpt_led_trigger(rtwdev->hw,
52						 IEEE80211_TPT_LEDTRIG_FL_RADIO,
53						 rtw_tpt_blink,
54						 ARRAY_SIZE(rtw_tpt_blink));
55
56	err = led_classdev_register(rtwdev->dev, led);
57	if (err) {
58		rtw_warn(rtwdev, "Failed to register the LED, error %d\n", err);
59		return;
60	}
61
62	rtwdev->led_registered = true;
63}
64
65void rtw_led_deinit(struct rtw_dev *rtwdev)
66{
67	struct led_classdev *led = &rtwdev->led_cdev;
68
69	if (!rtwdev->led_registered)
70		return;
71
72	rtwdev->chip->ops->led_set(led, LED_OFF);
73	led_classdev_unregister(led);
74}
~/ Read-only file preview.