ARM: mm: Recreate kernel mappings in early_paging_init()
[linux/fpc-iii.git] / drivers / net / can / led.c
bloba3d99a8fd2d19ee46f846448d2707f8dadf3e4af
1 /*
2 * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com>
3 * Copyright 2012, Kurt Van Dijck <kurt.van.dijck@eia.be>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
10 #include <linux/module.h>
11 #include <linux/device.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/netdevice.h>
15 #include <linux/can/dev.h>
17 #include <linux/can/led.h>
19 static unsigned long led_delay = 50;
20 module_param(led_delay, ulong, 0644);
21 MODULE_PARM_DESC(led_delay,
22 "blink delay time for activity leds (msecs, default: 50).");
24 /* Trigger a LED event in response to a CAN device event */
25 void can_led_event(struct net_device *netdev, enum can_led_event event)
27 struct can_priv *priv = netdev_priv(netdev);
29 switch (event) {
30 case CAN_LED_EVENT_OPEN:
31 led_trigger_event(priv->tx_led_trig, LED_FULL);
32 led_trigger_event(priv->rx_led_trig, LED_FULL);
33 break;
34 case CAN_LED_EVENT_STOP:
35 led_trigger_event(priv->tx_led_trig, LED_OFF);
36 led_trigger_event(priv->rx_led_trig, LED_OFF);
37 break;
38 case CAN_LED_EVENT_TX:
39 if (led_delay)
40 led_trigger_blink_oneshot(priv->tx_led_trig,
41 &led_delay, &led_delay, 1);
42 break;
43 case CAN_LED_EVENT_RX:
44 if (led_delay)
45 led_trigger_blink_oneshot(priv->rx_led_trig,
46 &led_delay, &led_delay, 1);
47 break;
50 EXPORT_SYMBOL_GPL(can_led_event);
52 static void can_led_release(struct device *gendev, void *res)
54 struct can_priv *priv = netdev_priv(to_net_dev(gendev));
56 led_trigger_unregister_simple(priv->tx_led_trig);
57 led_trigger_unregister_simple(priv->rx_led_trig);
60 /* Register CAN LED triggers for a CAN device
62 * This is normally called from a driver's probe function
64 void devm_can_led_init(struct net_device *netdev)
66 struct can_priv *priv = netdev_priv(netdev);
67 void *res;
69 res = devres_alloc(can_led_release, 0, GFP_KERNEL);
70 if (!res) {
71 netdev_err(netdev, "cannot register LED triggers\n");
72 return;
75 snprintf(priv->tx_led_trig_name, sizeof(priv->tx_led_trig_name),
76 "%s-tx", netdev->name);
77 snprintf(priv->rx_led_trig_name, sizeof(priv->rx_led_trig_name),
78 "%s-rx", netdev->name);
80 led_trigger_register_simple(priv->tx_led_trig_name,
81 &priv->tx_led_trig);
82 led_trigger_register_simple(priv->rx_led_trig_name,
83 &priv->rx_led_trig);
85 devres_add(&netdev->dev, res);
87 EXPORT_SYMBOL_GPL(devm_can_led_init);
89 /* NETDEV rename notifier to rename the associated led triggers too */
90 static int can_led_notifier(struct notifier_block *nb, unsigned long msg,
91 void *ptr)
93 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
94 struct can_priv *priv = safe_candev_priv(netdev);
95 char name[CAN_LED_NAME_SZ];
97 if (!priv)
98 return NOTIFY_DONE;
100 if (msg == NETDEV_CHANGENAME) {
101 snprintf(name, sizeof(name), "%s-tx", netdev->name);
102 led_trigger_rename_static(name, priv->tx_led_trig);
104 snprintf(name, sizeof(name), "%s-rx", netdev->name);
105 led_trigger_rename_static(name, priv->rx_led_trig);
108 return NOTIFY_DONE;
111 /* notifier block for netdevice event */
112 static struct notifier_block can_netdev_notifier __read_mostly = {
113 .notifier_call = can_led_notifier,
116 int __init can_led_notifier_init(void)
118 return register_netdevice_notifier(&can_netdev_notifier);
121 void __exit can_led_notifier_exit(void)
123 unregister_netdevice_notifier(&can_netdev_notifier);