Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 13 | #include "common.h" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14 | |
| 15 | #define BLINK_DELAY 30 |
| 16 | |
| 17 | static unsigned long usb_blink_delay = BLINK_DELAY; |
| 18 | |
| 19 | DEFINE_LED_TRIGGER(ledtrig_usb_gadget); |
| 20 | DEFINE_LED_TRIGGER(ledtrig_usb_host); |
| 21 | |
| 22 | void usb_led_activity(enum usb_led_event ev) |
| 23 | { |
| 24 | struct led_trigger *trig = NULL; |
| 25 | |
| 26 | switch (ev) { |
| 27 | case USB_LED_EVENT_GADGET: |
| 28 | trig = ledtrig_usb_gadget; |
| 29 | break; |
| 30 | case USB_LED_EVENT_HOST: |
| 31 | trig = ledtrig_usb_host; |
| 32 | break; |
| 33 | } |
| 34 | /* led_trigger_blink_oneshot() handles trig == NULL gracefully */ |
| 35 | led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0); |
| 36 | } |
| 37 | EXPORT_SYMBOL_GPL(usb_led_activity); |
| 38 | |
| 39 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 40 | void __init ledtrig_usb_init(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 41 | { |
| 42 | led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget); |
| 43 | led_trigger_register_simple("usb-host", &ledtrig_usb_host); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 44 | } |
| 45 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 46 | void __exit ledtrig_usb_exit(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 47 | { |
| 48 | led_trigger_unregister_simple(ledtrig_usb_gadget); |
| 49 | led_trigger_unregister_simple(ledtrig_usb_host); |
| 50 | } |