-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 351683 b: refs/heads/master c: 996a953 h: refs/heads/master i: 351681: 16813c1 351679: 3d1da36 v: v3
- Loading branch information
Fabio Baltieri
authored and
Marc Kleine-Budde
committed
Jan 26, 2013
1 parent
8914102
commit 8e6b3cd
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 0024d8ad1639e32d717445c69ca813fd19c2a91c | ||
refs/heads/master: 996a953de02ffb852c9ac736f4e892008ed68884 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/device.h> | ||
#include <linux/kernel.h> | ||
#include <linux/slab.h> | ||
#include <linux/netdevice.h> | ||
#include <linux/can/dev.h> | ||
|
||
#include <linux/can/led.h> | ||
|
||
static unsigned long led_delay = 50; | ||
module_param(led_delay, ulong, 0644); | ||
MODULE_PARM_DESC(led_delay, | ||
"blink delay time for activity leds (msecs, default: 50)."); | ||
|
||
/* Trigger a LED event in response to a CAN device event */ | ||
void can_led_event(struct net_device *netdev, enum can_led_event event) | ||
{ | ||
struct can_priv *priv = netdev_priv(netdev); | ||
|
||
switch (event) { | ||
case CAN_LED_EVENT_OPEN: | ||
led_trigger_event(priv->tx_led_trig, LED_FULL); | ||
led_trigger_event(priv->rx_led_trig, LED_FULL); | ||
break; | ||
case CAN_LED_EVENT_STOP: | ||
led_trigger_event(priv->tx_led_trig, LED_OFF); | ||
led_trigger_event(priv->rx_led_trig, LED_OFF); | ||
break; | ||
case CAN_LED_EVENT_TX: | ||
if (led_delay) | ||
led_trigger_blink_oneshot(priv->tx_led_trig, | ||
&led_delay, &led_delay, 1); | ||
break; | ||
case CAN_LED_EVENT_RX: | ||
if (led_delay) | ||
led_trigger_blink_oneshot(priv->rx_led_trig, | ||
&led_delay, &led_delay, 1); | ||
break; | ||
} | ||
} | ||
EXPORT_SYMBOL_GPL(can_led_event); | ||
|
||
static void can_led_release(struct device *gendev, void *res) | ||
{ | ||
struct can_priv *priv = netdev_priv(to_net_dev(gendev)); | ||
|
||
led_trigger_unregister_simple(priv->tx_led_trig); | ||
led_trigger_unregister_simple(priv->rx_led_trig); | ||
} | ||
|
||
/* Register CAN LED triggers for a CAN device | ||
* | ||
* This is normally called from a driver's probe function | ||
*/ | ||
void devm_can_led_init(struct net_device *netdev) | ||
{ | ||
struct can_priv *priv = netdev_priv(netdev); | ||
void *res; | ||
|
||
res = devres_alloc(can_led_release, 0, GFP_KERNEL); | ||
if (!res) { | ||
netdev_err(netdev, "cannot register LED triggers\n"); | ||
return; | ||
} | ||
|
||
snprintf(priv->tx_led_trig_name, sizeof(priv->tx_led_trig_name), | ||
"%s-tx", netdev->name); | ||
snprintf(priv->rx_led_trig_name, sizeof(priv->rx_led_trig_name), | ||
"%s-rx", netdev->name); | ||
|
||
led_trigger_register_simple(priv->tx_led_trig_name, | ||
&priv->tx_led_trig); | ||
led_trigger_register_simple(priv->rx_led_trig_name, | ||
&priv->rx_led_trig); | ||
|
||
devres_add(&netdev->dev, res); | ||
} | ||
EXPORT_SYMBOL_GPL(devm_can_led_init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
*/ | ||
|
||
#ifndef CAN_LED_H | ||
#define CAN_LED_H | ||
|
||
#include <linux/if.h> | ||
#include <linux/leds.h> | ||
|
||
enum can_led_event { | ||
CAN_LED_EVENT_OPEN, | ||
CAN_LED_EVENT_STOP, | ||
CAN_LED_EVENT_TX, | ||
CAN_LED_EVENT_RX, | ||
}; | ||
|
||
#ifdef CONFIG_CAN_LEDS | ||
|
||
/* keep space for interface name + "-tx"/"-rx" suffix and null terminator */ | ||
#define CAN_LED_NAME_SZ (IFNAMSIZ + 4) | ||
|
||
void can_led_event(struct net_device *netdev, enum can_led_event event); | ||
void devm_can_led_init(struct net_device *netdev); | ||
|
||
#else | ||
|
||
static inline void can_led_event(struct net_device *netdev, | ||
enum can_led_event event) | ||
{ | ||
} | ||
static inline void devm_can_led_init(struct net_device *netdev) | ||
{ | ||
} | ||
|
||
#endif | ||
|
||
#endif |