Commit c54eb70e authored by Yegor Yefremov's avatar Yegor Yefremov Committed by Marc Kleine-Budde

can: add combined rx/tx LED trigger support

Add <ifname>-rxtx trigger, that will be activated both for tx
as rx events. This trigger mimics "activity" LED for Ethernet
devices.
Signed-off-by: default avatarYegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent fba6f911
...@@ -30,20 +30,28 @@ void can_led_event(struct net_device *netdev, enum can_led_event event) ...@@ -30,20 +30,28 @@ void can_led_event(struct net_device *netdev, enum can_led_event event)
case CAN_LED_EVENT_OPEN: case CAN_LED_EVENT_OPEN:
led_trigger_event(priv->tx_led_trig, LED_FULL); led_trigger_event(priv->tx_led_trig, LED_FULL);
led_trigger_event(priv->rx_led_trig, LED_FULL); led_trigger_event(priv->rx_led_trig, LED_FULL);
led_trigger_event(priv->rxtx_led_trig, LED_FULL);
break; break;
case CAN_LED_EVENT_STOP: case CAN_LED_EVENT_STOP:
led_trigger_event(priv->tx_led_trig, LED_OFF); led_trigger_event(priv->tx_led_trig, LED_OFF);
led_trigger_event(priv->rx_led_trig, LED_OFF); led_trigger_event(priv->rx_led_trig, LED_OFF);
led_trigger_event(priv->rxtx_led_trig, LED_OFF);
break; break;
case CAN_LED_EVENT_TX: case CAN_LED_EVENT_TX:
if (led_delay) if (led_delay) {
led_trigger_blink_oneshot(priv->tx_led_trig, led_trigger_blink_oneshot(priv->tx_led_trig,
&led_delay, &led_delay, 1); &led_delay, &led_delay, 1);
led_trigger_blink_oneshot(priv->rxtx_led_trig,
&led_delay, &led_delay, 1);
}
break; break;
case CAN_LED_EVENT_RX: case CAN_LED_EVENT_RX:
if (led_delay) if (led_delay) {
led_trigger_blink_oneshot(priv->rx_led_trig, led_trigger_blink_oneshot(priv->rx_led_trig,
&led_delay, &led_delay, 1); &led_delay, &led_delay, 1);
led_trigger_blink_oneshot(priv->rxtx_led_trig,
&led_delay, &led_delay, 1);
}
break; break;
} }
} }
...@@ -55,6 +63,7 @@ static void can_led_release(struct device *gendev, void *res) ...@@ -55,6 +63,7 @@ static void can_led_release(struct device *gendev, void *res)
led_trigger_unregister_simple(priv->tx_led_trig); led_trigger_unregister_simple(priv->tx_led_trig);
led_trigger_unregister_simple(priv->rx_led_trig); led_trigger_unregister_simple(priv->rx_led_trig);
led_trigger_unregister_simple(priv->rxtx_led_trig);
} }
/* Register CAN LED triggers for a CAN device /* Register CAN LED triggers for a CAN device
...@@ -76,11 +85,15 @@ void devm_can_led_init(struct net_device *netdev) ...@@ -76,11 +85,15 @@ void devm_can_led_init(struct net_device *netdev)
"%s-tx", netdev->name); "%s-tx", netdev->name);
snprintf(priv->rx_led_trig_name, sizeof(priv->rx_led_trig_name), snprintf(priv->rx_led_trig_name, sizeof(priv->rx_led_trig_name),
"%s-rx", netdev->name); "%s-rx", netdev->name);
snprintf(priv->rxtx_led_trig_name, sizeof(priv->rxtx_led_trig_name),
"%s-rxtx", netdev->name);
led_trigger_register_simple(priv->tx_led_trig_name, led_trigger_register_simple(priv->tx_led_trig_name,
&priv->tx_led_trig); &priv->tx_led_trig);
led_trigger_register_simple(priv->rx_led_trig_name, led_trigger_register_simple(priv->rx_led_trig_name,
&priv->rx_led_trig); &priv->rx_led_trig);
led_trigger_register_simple(priv->rxtx_led_trig_name,
&priv->rxtx_led_trig);
devres_add(&netdev->dev, res); devres_add(&netdev->dev, res);
} }
...@@ -97,7 +110,7 @@ static int can_led_notifier(struct notifier_block *nb, unsigned long msg, ...@@ -97,7 +110,7 @@ static int can_led_notifier(struct notifier_block *nb, unsigned long msg,
if (!priv) if (!priv)
return NOTIFY_DONE; return NOTIFY_DONE;
if (!priv->tx_led_trig || !priv->rx_led_trig) if (!priv->tx_led_trig || !priv->rx_led_trig || !priv->rxtx_led_trig)
return NOTIFY_DONE; return NOTIFY_DONE;
if (msg == NETDEV_CHANGENAME) { if (msg == NETDEV_CHANGENAME) {
...@@ -106,6 +119,9 @@ static int can_led_notifier(struct notifier_block *nb, unsigned long msg, ...@@ -106,6 +119,9 @@ static int can_led_notifier(struct notifier_block *nb, unsigned long msg,
snprintf(name, sizeof(name), "%s-rx", netdev->name); snprintf(name, sizeof(name), "%s-rx", netdev->name);
led_trigger_rename_static(name, priv->rx_led_trig); led_trigger_rename_static(name, priv->rx_led_trig);
snprintf(name, sizeof(name), "%s-rxtx", netdev->name);
led_trigger_rename_static(name, priv->rxtx_led_trig);
} }
return NOTIFY_DONE; return NOTIFY_DONE;
......
...@@ -61,6 +61,8 @@ struct can_priv { ...@@ -61,6 +61,8 @@ struct can_priv {
char tx_led_trig_name[CAN_LED_NAME_SZ]; char tx_led_trig_name[CAN_LED_NAME_SZ];
struct led_trigger *rx_led_trig; struct led_trigger *rx_led_trig;
char rx_led_trig_name[CAN_LED_NAME_SZ]; char rx_led_trig_name[CAN_LED_NAME_SZ];
struct led_trigger *rxtx_led_trig;
char rxtx_led_trig_name[CAN_LED_NAME_SZ];
#endif #endif
}; };
......
...@@ -21,8 +21,10 @@ enum can_led_event { ...@@ -21,8 +21,10 @@ enum can_led_event {
#ifdef CONFIG_CAN_LEDS #ifdef CONFIG_CAN_LEDS
/* keep space for interface name + "-tx"/"-rx" suffix and null terminator */ /* keep space for interface name + "-tx"/"-rx"/"-rxtx"
#define CAN_LED_NAME_SZ (IFNAMSIZ + 4) * suffix and null terminator
*/
#define CAN_LED_NAME_SZ (IFNAMSIZ + 6)
void can_led_event(struct net_device *netdev, enum can_led_event event); void can_led_event(struct net_device *netdev, enum can_led_event event);
void devm_can_led_init(struct net_device *netdev); void devm_can_led_init(struct net_device *netdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment