blob: 7bd81166b77d7833cbc1389e18ee65f452df4a85 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Michal Sojka0cfbd322014-09-24 22:43:21 +02002/*
3 * LED Triggers for USB Activity
4 *
5 * Copyright 2014 Michal Sojka <sojka@merica.cz>
Michal Sojka0cfbd322014-09-24 22:43:21 +02006 */
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
14#define BLINK_DELAY 30
15
16static unsigned long usb_blink_delay = BLINK_DELAY;
17
18DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
19DEFINE_LED_TRIGGER(ledtrig_usb_host);
20
21void usb_led_activity(enum usb_led_event ev)
22{
23 struct led_trigger *trig = NULL;
24
25 switch (ev) {
26 case USB_LED_EVENT_GADGET:
27 trig = ledtrig_usb_gadget;
28 break;
29 case USB_LED_EVENT_HOST:
30 trig = ledtrig_usb_host;
31 break;
32 }
33 /* led_trigger_blink_oneshot() handles trig == NULL gracefully */
34 led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
35}
36EXPORT_SYMBOL_GPL(usb_led_activity);
37
38
39static int __init ledtrig_usb_init(void)
40{
41 led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
42 led_trigger_register_simple("usb-host", &ledtrig_usb_host);
43 return 0;
44}
45
46static void __exit ledtrig_usb_exit(void)
47{
48 led_trigger_unregister_simple(ledtrig_usb_gadget);
49 led_trigger_unregister_simple(ledtrig_usb_host);
50}
51
52module_init(ledtrig_usb_init);
53module_exit(ledtrig_usb_exit);