xref: /linux/drivers/usb/common/led.c (revision 3d0fe49454652117522f60bfbefb978ba0e5300b)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * LED Triggers for USB Activity
4  *
5  * Copyright 2014 Michal Sojka <sojka@merica.cz>
6  */
7 
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/leds.h>
12 #include <linux/usb.h>
13 #include "common.h"
14 
15 #define BLINK_DELAY 30
16 
17 DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
18 DEFINE_LED_TRIGGER(ledtrig_usb_host);
19 
20 void usb_led_activity(enum usb_led_event ev)
21 {
22 	struct led_trigger *trig = NULL;
23 
24 	switch (ev) {
25 	case USB_LED_EVENT_GADGET:
26 		trig = ledtrig_usb_gadget;
27 		break;
28 	case USB_LED_EVENT_HOST:
29 		trig = ledtrig_usb_host;
30 		break;
31 	}
32 	/* led_trigger_blink_oneshot() handles trig == NULL gracefully */
33 	led_trigger_blink_oneshot(trig, BLINK_DELAY, BLINK_DELAY, 0);
34 }
35 EXPORT_SYMBOL_GPL(usb_led_activity);
36 
37 
38 void __init ledtrig_usb_init(void)
39 {
40 	led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
41 	led_trigger_register_simple("usb-host", &ledtrig_usb_host);
42 }
43 
44 void __exit ledtrig_usb_exit(void)
45 {
46 	led_trigger_unregister_simple(ledtrig_usb_gadget);
47 	led_trigger_unregister_simple(ledtrig_usb_host);
48 }
49