diff options
author | Fabio Baltieri <fabio.baltieri@gmail.com> | 2012-12-18 12:50:55 -0500 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2013-01-26 10:58:59 -0500 |
commit | 996a953de02ffb852c9ac736f4e892008ed68884 (patch) | |
tree | dcf301c575ee47331f34c961c36f5658ce32da32 /include/linux/can | |
parent | 0024d8ad1639e32d717445c69ca813fd19c2a91c (diff) |
can: add tx/rx LED trigger support
This patch implements the functions to add two LED triggers, named
<ifname>-tx and <ifname>-rx, to a canbus device driver.
Triggers are called from specific handlers by each CAN device driver and
can be disabled altogether with a Kconfig option.
The implementation keeps the LED on when the interface is UP and blinks
the LED on network activity at a configurable rate.
This only supports can-dev based drivers, as it uses some support field
in the can_priv structure.
Supported drivers should call devm_can_led_init() and can_led_event() as
needed.
Cleanup is handled automatically by devres, so no *_exit function is
needed.
Supported events are:
- CAN_LED_EVENT_OPEN: turn on tx/rx LEDs
- CAN_LED_EVENT_STOP: turn off tx/rx LEDs
- CAN_LED_EVENT_TX: trigger tx LED blink
- CAN_LED_EVENT_RX: trigger tx LED blink
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'include/linux/can')
-rw-r--r-- | include/linux/can/dev.h | 8 | ||||
-rw-r--r-- | include/linux/can/led.h | 42 |
2 files changed, 50 insertions, 0 deletions
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 2b2fc345afca..7747d9bcdc84 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/can.h> | 16 | #include <linux/can.h> |
17 | #include <linux/can/netlink.h> | 17 | #include <linux/can/netlink.h> |
18 | #include <linux/can/error.h> | 18 | #include <linux/can/error.h> |
19 | #include <linux/can/led.h> | ||
19 | 20 | ||
20 | /* | 21 | /* |
21 | * CAN mode | 22 | * CAN mode |
@@ -52,6 +53,13 @@ struct can_priv { | |||
52 | 53 | ||
53 | unsigned int echo_skb_max; | 54 | unsigned int echo_skb_max; |
54 | struct sk_buff **echo_skb; | 55 | struct sk_buff **echo_skb; |
56 | |||
57 | #ifdef CONFIG_CAN_LEDS | ||
58 | struct led_trigger *tx_led_trig; | ||
59 | char tx_led_trig_name[CAN_LED_NAME_SZ]; | ||
60 | struct led_trigger *rx_led_trig; | ||
61 | char rx_led_trig_name[CAN_LED_NAME_SZ]; | ||
62 | #endif | ||
55 | }; | 63 | }; |
56 | 64 | ||
57 | /* | 65 | /* |
diff --git a/include/linux/can/led.h b/include/linux/can/led.h new file mode 100644 index 000000000000..12d5549abb95 --- /dev/null +++ b/include/linux/can/led.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #ifndef CAN_LED_H | ||
10 | #define CAN_LED_H | ||
11 | |||
12 | #include <linux/if.h> | ||
13 | #include <linux/leds.h> | ||
14 | |||
15 | enum can_led_event { | ||
16 | CAN_LED_EVENT_OPEN, | ||
17 | CAN_LED_EVENT_STOP, | ||
18 | CAN_LED_EVENT_TX, | ||
19 | CAN_LED_EVENT_RX, | ||
20 | }; | ||
21 | |||
22 | #ifdef CONFIG_CAN_LEDS | ||
23 | |||
24 | /* keep space for interface name + "-tx"/"-rx" suffix and null terminator */ | ||
25 | #define CAN_LED_NAME_SZ (IFNAMSIZ + 4) | ||
26 | |||
27 | void can_led_event(struct net_device *netdev, enum can_led_event event); | ||
28 | void devm_can_led_init(struct net_device *netdev); | ||
29 | |||
30 | #else | ||
31 | |||
32 | static inline void can_led_event(struct net_device *netdev, | ||
33 | enum can_led_event event) | ||
34 | { | ||
35 | } | ||
36 | static inline void devm_can_led_init(struct net_device *netdev) | ||
37 | { | ||
38 | } | ||
39 | |||
40 | #endif | ||
41 | |||
42 | #endif | ||