linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] tx/rx LED trigger support
@ 2012-12-16 11:08 Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 1/9] can: add " Fabio Baltieri
                   ` (10 more replies)
  0 siblings, 11 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri

Hi all,

this is a resend of the patch series on tx/rx LEDs trigger.  The patch
set was put on hold after the latest discussions on Kurt's rename patch
due to a missing feature in the LED subsystem, which has been just
merged in:

a8df7b1 leds: add led_trigger_rename function

So, as months passed since the latest developments, I'm reposting the
whole set, rebased on current mainline.  The first patches are the same
that were merged in can-next/led-trigger, but there was some (trivial)
conflict in the rebase.

As for the test, I've tried the patch on the current mainline kernel
with my custom usb-can interface.  For the drivers, I don't have any
SoC-enabled board anymore, so they have only been compile tested.

Cheers,
Fabio


Fabio Baltieri (7):
  can: add tx/rx LED trigger support
  can: flexcan: add LED trigger support
  can: at91_can: add LED trigger support
  can: ti_hecc: add LED trigger support
  can: c_can: add LED trigger support
  can: mcp251x: add LED trigger support
  can: sja1000: add LED trigger support

Kurt Van Dijck (2):
  can: export a safe netdev_priv wrapper for candev
  can: rename LED trigger name on netdev renames

 drivers/net/can/Kconfig           |  12 ++++
 drivers/net/can/Makefile          |   2 +
 drivers/net/can/at91_can.c        |  10 +++
 drivers/net/can/c_can/c_can.c     |  10 +++
 drivers/net/can/dev.c             |  18 ++++++
 drivers/net/can/flexcan.c         |  11 ++++
 drivers/net/can/led.c             | 129 ++++++++++++++++++++++++++++++++++++++
 drivers/net/can/mcp251x.c         |  23 +++++--
 drivers/net/can/sja1000/sja1000.c |  17 ++++-
 drivers/net/can/ti_hecc.c         |  10 +++
 include/linux/can/dev.h           |  11 ++++
 include/linux/can/led.h           |  51 +++++++++++++++
 12 files changed, 299 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/can/led.c
 create mode 100644 include/linux/can/led.h

-- 
1.7.12.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-17  7:28   ` Bernd Krumboeck
  2012-12-16 11:08 ` [PATCH 2/9] can: flexcan: add " Fabio Baltieri
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri

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>
---
 drivers/net/can/Kconfig  | 12 +++++++
 drivers/net/can/Makefile |  2 ++
 drivers/net/can/led.c    | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/can/dev.h  |  8 +++++
 include/linux/can/led.h  | 42 +++++++++++++++++++++++
 5 files changed, 153 insertions(+)
 create mode 100644 drivers/net/can/led.c
 create mode 100644 include/linux/can/led.h

diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index b56bd9e..8e59120 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -54,6 +54,18 @@ config CAN_CALC_BITTIMING
 	  arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw".
 	  If unsure, say Y.
 
+config CAN_LEDS
+	bool "Enable LED triggers for Netlink based drivers"
+	depends on CAN_DEV
+	depends on LEDS_CLASS
+	select LEDS_TRIGGERS
+	---help---
+	  This option adds two LED triggers for packet receive and transmit
+	  events on each supported CAN device.
+
+	  Say Y here if you are working on a system with led-class supported
+	  LEDs and you want to use them as canbus activity indicators.
+
 config CAN_AT91
 	tristate "Atmel AT91 onchip CAN controller"
 	depends on CAN_DEV && (ARCH_AT91SAM9263 || ARCH_AT91SAM9X5)
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 7de5986..c744039 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -8,6 +8,8 @@ obj-$(CONFIG_CAN_SLCAN)		+= slcan.o
 obj-$(CONFIG_CAN_DEV)		+= can-dev.o
 can-dev-y			:= dev.o
 
+can-dev-$(CONFIG_CAN_LEDS)	+= led.o
+
 obj-y				+= usb/
 obj-y				+= softing/
 
diff --git a/drivers/net/can/led.c b/drivers/net/can/led.c
new file mode 100644
index 0000000..eaa14ac
--- /dev/null
+++ b/drivers/net/can/led.c
@@ -0,0 +1,89 @@
+/*
+ * 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);
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 2b2fc34..7747d9b 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -16,6 +16,7 @@
 #include <linux/can.h>
 #include <linux/can/netlink.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 /*
  * CAN mode
@@ -52,6 +53,13 @@ struct can_priv {
 
 	unsigned int echo_skb_max;
 	struct sk_buff **echo_skb;
+
+#ifdef CONFIG_CAN_LEDS
+	struct led_trigger *tx_led_trig;
+	char tx_led_trig_name[CAN_LED_NAME_SZ];
+	struct led_trigger *rx_led_trig;
+	char rx_led_trig_name[CAN_LED_NAME_SZ];
+#endif
 };
 
 /*
diff --git a/include/linux/can/led.h b/include/linux/can/led.h
new file mode 100644
index 0000000..12d5549
--- /dev/null
+++ b/include/linux/can/led.h
@@ -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
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/9] can: flexcan: add LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 1/9] can: add " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 3/9] can: at91_can: " Fabio Baltieri
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri

Add support for canbus activity led indicators on flexcan devices by
calling appropriate can_led_* functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op
otherwise.

Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/flexcan.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 0289a6d..769d29e 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -23,6 +23,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 #include <linux/can/platform/flexcan.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
@@ -564,6 +565,8 @@ static int flexcan_read_frame(struct net_device *dev)
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
 
+	can_led_event(dev, CAN_LED_EVENT_RX);
+
 	return 1;
 }
 
@@ -652,6 +655,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	if (reg_iflag1 & (1 << FLEXCAN_TX_BUF_ID)) {
 		stats->tx_bytes += can_get_echo_skb(dev, 0);
 		stats->tx_packets++;
+		can_led_event(dev, CAN_LED_EVENT_TX);
 		flexcan_write((1 << FLEXCAN_TX_BUF_ID), &regs->iflag1);
 		netif_wake_queue(dev);
 	}
@@ -865,6 +869,9 @@ static int flexcan_open(struct net_device *dev)
 	err = flexcan_chip_start(dev);
 	if (err)
 		goto out_close;
+
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	napi_enable(&priv->napi);
 	netif_start_queue(dev);
 
@@ -893,6 +900,8 @@ static int flexcan_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -1092,6 +1101,8 @@ static int flexcan_probe(struct platform_device *pdev)
 		goto failed_register;
 	}
 
+	devm_can_led_init(dev);
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
 		 priv->base, dev->irq);
 
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/9] can: at91_can: add LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 1/9] can: add " Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 2/9] can: flexcan: add " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 4/9] can: ti_hecc: " Fabio Baltieri
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri

Add support for canbus activity led indicators on at91_can devices by
calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op
otherwise.

Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/at91_can.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index 81baefd..44f3637 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -37,6 +37,7 @@
 
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 #define AT91_MB_MASK(i)		((1 << (i)) - 1)
 
@@ -641,6 +642,8 @@ static void at91_read_msg(struct net_device *dev, unsigned int mb)
 
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
+
+	can_led_event(dev, CAN_LED_EVENT_RX);
 }
 
 /**
@@ -875,6 +878,7 @@ static void at91_irq_tx(struct net_device *dev, u32 reg_sr)
 			/* _NOTE_: subtract AT91_MB_TX_FIRST offset from mb! */
 			can_get_echo_skb(dev, mb - get_mb_tx_first(priv));
 			dev->stats.tx_packets++;
+			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
 	}
 
@@ -1128,6 +1132,8 @@ static int at91_open(struct net_device *dev)
 		goto out_close;
 	}
 
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	/* start chip and queuing */
 	at91_chip_start(dev);
 	napi_enable(&priv->napi);
@@ -1159,6 +1165,8 @@ static int at91_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -1321,6 +1329,8 @@ static int at91_can_probe(struct platform_device *pdev)
 		goto exit_free;
 	}
 
+	devm_can_led_init(dev);
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
 		 priv->reg_base, dev->irq);
 
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/9] can: ti_hecc: add LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (2 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 3/9] can: at91_can: " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 5/9] can: c_can: " Fabio Baltieri
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri, Anant Gole

Add support for canbus activity led indicators on ti_hecc devices by
calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op
otherwise.

Cc: Anant Gole <anantgole@ti.com>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/ti_hecc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
index f898c63..f52a975 100644
--- a/drivers/net/can/ti_hecc.c
+++ b/drivers/net/can/ti_hecc.c
@@ -50,6 +50,7 @@
 
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 #include <linux/can/platform/ti_hecc.h>
 
 #define DRV_NAME "ti_hecc"
@@ -593,6 +594,7 @@ static int ti_hecc_rx_pkt(struct ti_hecc_priv *priv, int mbxno)
 	spin_unlock_irqrestore(&priv->mbx_lock, flags);
 
 	stats->rx_bytes += cf->can_dlc;
+	can_led_event(priv->ndev, CAN_LED_EVENT_RX);
 	netif_receive_skb(skb);
 	stats->rx_packets++;
 
@@ -796,6 +798,7 @@ static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id)
 			stats->tx_bytes += hecc_read_mbx(priv, mbxno,
 						HECC_CANMCF) & 0xF;
 			stats->tx_packets++;
+			can_led_event(ndev, CAN_LED_EVENT_TX);
 			can_get_echo_skb(ndev, mbxno);
 			--priv->tx_tail;
 		}
@@ -851,6 +854,8 @@ static int ti_hecc_open(struct net_device *ndev)
 		return err;
 	}
 
+	can_led_event(ndev, CAN_LED_EVENT_OPEN);
+
 	ti_hecc_start(ndev);
 	napi_enable(&priv->napi);
 	netif_start_queue(ndev);
@@ -869,6 +874,8 @@ static int ti_hecc_close(struct net_device *ndev)
 	close_candev(ndev);
 	ti_hecc_transceiver_switch(priv, 0);
 
+	can_led_event(ndev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -961,6 +968,9 @@ static int ti_hecc_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "register_candev() failed\n");
 		goto probe_exit_clk;
 	}
+
+	devm_can_led_init(ndev);
+
 	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%u)\n",
 		priv->base, (u32) ndev->irq);
 
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 5/9] can: c_can: add LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (3 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 4/9] can: ti_hecc: " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 6/9] can: mcp251x: " Fabio Baltieri
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri, Bhupesh Sharma, AnilKumar Ch

Add support for canbus activity led indicators on c_can devices by
calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op
otherwise.

Cc: Bhupesh Sharma <bhupesh.sharma@st.com>
Cc: AnilKumar Ch <anilkumar@ti.com>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/c_can/c_can.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 5233b8f..57eb1e7 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -39,6 +39,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 #include "c_can.h"
 
@@ -477,6 +478,8 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, int ctrl)
 	stats->rx_packets++;
 	stats->rx_bytes += frame->can_dlc;
 
+	can_led_event(dev, CAN_LED_EVENT_RX);
+
 	return 0;
 }
 
@@ -751,6 +754,7 @@ static void c_can_do_tx(struct net_device *dev)
 					C_CAN_IFACE(MSGCTRL_REG, 0))
 					& IF_MCONT_DLC_MASK;
 			stats->tx_packets++;
+			can_led_event(dev, CAN_LED_EVENT_TX);
 			c_can_inval_msg_object(dev, 0, msg_obj_no);
 		} else {
 			break;
@@ -1115,6 +1119,8 @@ static int c_can_open(struct net_device *dev)
 
 	napi_enable(&priv->napi);
 
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	/* start the c_can controller */
 	c_can_start(dev);
 
@@ -1143,6 +1149,8 @@ static int c_can_close(struct net_device *dev)
 	c_can_reset_ram(priv, false);
 	c_can_pm_runtime_put_sync(priv);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -1268,6 +1276,8 @@ int register_c_can_dev(struct net_device *dev)
 	err = register_candev(dev);
 	if (err)
 		c_can_pm_runtime_disable(priv);
+	else
+		devm_can_led_init(dev);
 
 	return err;
 }
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 6/9] can: mcp251x: add LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (4 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 5/9] can: c_can: " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 7/9] can: sja1000: " Fabio Baltieri
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri, Christian Pellegrin

Add support for canbus activity led indicators on mcp251x devices by
calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op
otherwise.

Cc: Christian Pellegrin <chripell@fsfe.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/mcp251x.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 5eaf47b..f32b9fc 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -60,6 +60,7 @@
 
 #include <linux/can/core.h>
 #include <linux/can/dev.h>
+#include <linux/can/led.h>
 #include <linux/can/platform/mcp251x.h>
 #include <linux/completion.h>
 #include <linux/delay.h>
@@ -494,6 +495,9 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx)
 
 	priv->net->stats.rx_packets++;
 	priv->net->stats.rx_bytes += frame->can_dlc;
+
+	can_led_event(priv->net, CAN_LED_EVENT_RX);
+
 	netif_rx_ni(skb);
 }
 
@@ -707,6 +711,8 @@ static int mcp251x_stop(struct net_device *net)
 
 	mutex_unlock(&priv->mcp_lock);
 
+	can_led_event(net, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -905,6 +911,7 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
 		if (intf & CANINTF_TX) {
 			net->stats.tx_packets++;
 			net->stats.tx_bytes += priv->tx_len - 1;
+			can_led_event(net, CAN_LED_EVENT_TX);
 			if (priv->tx_len) {
 				can_get_echo_skb(net, 0);
 				priv->tx_len = 0;
@@ -968,6 +975,9 @@ static int mcp251x_open(struct net_device *net)
 		mcp251x_open_clean(net);
 		goto open_unlock;
 	}
+
+	can_led_event(net, CAN_LED_EVENT_OPEN);
+
 	netif_wake_queue(net);
 
 open_unlock:
@@ -1077,10 +1087,15 @@ static int mcp251x_can_probe(struct spi_device *spi)
 		pdata->transceiver_enable(0);
 
 	ret = register_candev(net);
-	if (!ret) {
-		dev_info(&spi->dev, "probed\n");
-		return ret;
-	}
+	if (ret)
+		goto error_probe;
+
+	devm_can_led_init(net);
+
+	dev_info(&spi->dev, "probed\n");
+
+	return ret;
+
 error_probe:
 	if (!mcp251x_enable_dma)
 		kfree(priv->spi_rx_buf);
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 7/9] can: sja1000: add LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (5 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 6/9] can: mcp251x: " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 8/9] can: export a safe netdev_priv wrapper for candev Fabio Baltieri
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri

Add support for canbus activity led indicators on sja1000 devices by
calling appropriate can_led functions.

These are only enabled when CONFIG_CAN_LEDS is Y, becomes no-op
otherwise.

Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/sja1000/sja1000.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 83ee11e..daf4013 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -60,6 +60,7 @@
 
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/led.h>
 
 #include "sja1000.h"
 
@@ -368,6 +369,8 @@ static void sja1000_rx(struct net_device *dev)
 
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
+
+	can_led_event(dev, CAN_LED_EVENT_RX);
 }
 
 static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
@@ -521,6 +524,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
 				can_get_echo_skb(dev, 0);
 			}
 			netif_wake_queue(dev);
+			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
 		if (isrc & IRQ_RI) {
 			/* receive interrupt */
@@ -575,6 +579,8 @@ static int sja1000_open(struct net_device *dev)
 	/* init and start chi */
 	sja1000_start(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_OPEN);
+
 	netif_start_queue(dev);
 
 	return 0;
@@ -592,6 +598,8 @@ static int sja1000_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	can_led_event(dev, CAN_LED_EVENT_STOP);
+
 	return 0;
 }
 
@@ -639,6 +647,8 @@ static const struct net_device_ops sja1000_netdev_ops = {
 
 int register_sja1000dev(struct net_device *dev)
 {
+	int ret;
+
 	if (!sja1000_probe_chip(dev))
 		return -ENODEV;
 
@@ -648,7 +658,12 @@ int register_sja1000dev(struct net_device *dev)
 	set_reset_mode(dev);
 	chipset_init(dev);
 
-	return register_candev(dev);
+	ret =  register_candev(dev);
+
+	if (!ret)
+		devm_can_led_init(dev);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(register_sja1000dev);
 
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 8/9] can: export a safe netdev_priv wrapper for candev
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (6 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 7/9] can: sja1000: " Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 11:08 ` [PATCH 9/9] can: rename LED trigger name on netdev renames Fabio Baltieri
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp, linux-kernel

From: Kurt Van Dijck <kurt.van.dijck@eia.be>

In net_device notifier calls, it was impossible to determine
if a CAN device is based on candev in a safe way.
This patch adds such test in order to access candev storage
from within those notifiers.

Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 drivers/net/can/dev.c   | 13 +++++++++++++
 include/linux/can/dev.h |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 8233e5e..13e7380 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -794,6 +794,19 @@ void unregister_candev(struct net_device *dev)
 }
 EXPORT_SYMBOL_GPL(unregister_candev);
 
+/*
+ * Test if a network device is a candev based device
+ * and return the can_priv* if so.
+ */
+struct can_priv *safe_candev_priv(struct net_device *dev)
+{
+	if ((dev->type != ARPHRD_CAN) || (dev->rtnl_link_ops != &can_link_ops))
+		return NULL;
+
+	return netdev_priv(dev);
+}
+EXPORT_SYMBOL_GPL(safe_candev_priv);
+
 static __init int can_dev_init(void)
 {
 	int err;
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 7747d9b..fb0ab65 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -106,6 +106,9 @@ u8 can_len2dlc(u8 len);
 struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
 void free_candev(struct net_device *dev);
 
+/* a candev safe wrapper around netdev_priv */
+struct can_priv *safe_candev_priv(struct net_device *dev);
+
 int open_candev(struct net_device *dev);
 void close_candev(struct net_device *dev);
 
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 9/9] can: rename LED trigger name on netdev renames
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (7 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 8/9] can: export a safe netdev_priv wrapper for candev Fabio Baltieri
@ 2012-12-16 11:08 ` Fabio Baltieri
  2012-12-16 22:37 ` [PATCH 0/9] tx/rx LED trigger support Marc Kleine-Budde
  2012-12-17  9:35 ` Kurt Van Dijck
  10 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 11:08 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can
  Cc: Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel, Fabio Baltieri

From: Kurt Van Dijck <kurt.van.dijck@eia.be>

The LED trigger name for CAN devices is based on the initial
CAN device name, but does never change. The LED trigger name
is not guaranteed to be unique in case of hotplugging CAN devices.

This patch tries to address this problem by modifying the
LED trigger name according to the CAN device name when
the latter changes.

v1 - Kurt Van Dijck
v2 - Fabio Baltieri
- remove rename blocking if trigger is bound
- use led-subsystem function for the actual rename (still WiP)
- call init/exit functions from dev.c
v3 - Kurt Van Dijck
- safe operation for non-candev based devices (vcan, slcan)
	based on earlier patch
v4 - Kurt Van Dijck
- trivial patch mistakes fixed

Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
 drivers/net/can/dev.c   |  5 +++++
 drivers/net/can/led.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 include/linux/can/led.h |  9 +++++++++
 3 files changed, 54 insertions(+)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 13e7380..6abc6e5 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -25,6 +25,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/netlink.h>
+#include <linux/can/led.h>
 #include <net/rtnetlink.h>
 
 #define MOD_DESC "CAN device driver interface"
@@ -811,6 +812,8 @@ static __init int can_dev_init(void)
 {
 	int err;
 
+	can_led_notifier_init();
+
 	err = rtnl_link_register(&can_link_ops);
 	if (!err)
 		printk(KERN_INFO MOD_DESC "\n");
@@ -822,6 +825,8 @@ module_init(can_dev_init);
 static __exit void can_dev_exit(void)
 {
 	rtnl_link_unregister(&can_link_ops);
+
+	can_led_notifier_exit();
 }
 module_exit(can_dev_exit);
 
diff --git a/drivers/net/can/led.c b/drivers/net/can/led.c
index eaa14ac..227d359 100644
--- a/drivers/net/can/led.c
+++ b/drivers/net/can/led.c
@@ -1,5 +1,6 @@
 /*
  * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com>
+ * Copyright 2012, Kurt Van Dijck <kurt.van.dijck@eia.be>
  *
  * 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
@@ -87,3 +88,42 @@ void devm_can_led_init(struct net_device *netdev)
 	devres_add(&netdev->dev, res);
 }
 EXPORT_SYMBOL_GPL(devm_can_led_init);
+
+/*
+ * NETDEV rename notifier to rename the associated led triggers too
+ */
+static int can_led_notifier(struct notifier_block *nb, unsigned long msg,
+			void *data)
+{
+	struct net_device *netdev = data;
+	struct can_priv *priv = safe_candev_priv(netdev);
+	char name[CAN_LED_NAME_SZ];
+
+	if (!priv)
+		return NOTIFY_DONE;
+
+	if (msg == NETDEV_CHANGENAME) {
+		snprintf(name, sizeof(name), "%s-tx", netdev->name);
+		led_trigger_rename_static(name, priv->tx_led_trig);
+
+		snprintf(name, sizeof(name), "%s-rx", netdev->name);
+		led_trigger_rename_static(name, priv->rx_led_trig);
+	}
+
+	return NOTIFY_DONE;
+}
+
+/* notifier block for netdevice event */
+static struct notifier_block can_netdev_notifier __read_mostly = {
+	.notifier_call = can_led_notifier,
+};
+
+int __init can_led_notifier_init(void)
+{
+	return register_netdevice_notifier(&can_netdev_notifier);
+}
+
+void __exit can_led_notifier_exit(void)
+{
+	unregister_netdevice_notifier(&can_netdev_notifier);
+}
diff --git a/include/linux/can/led.h b/include/linux/can/led.h
index 12d5549..9c1167b 100644
--- a/include/linux/can/led.h
+++ b/include/linux/can/led.h
@@ -26,6 +26,8 @@ enum can_led_event {
 
 void can_led_event(struct net_device *netdev, enum can_led_event event);
 void devm_can_led_init(struct net_device *netdev);
+int __init can_led_notifier_init(void);
+void __exit can_led_notifier_exit(void);
 
 #else
 
@@ -36,6 +38,13 @@ static inline void can_led_event(struct net_device *netdev,
 static inline void devm_can_led_init(struct net_device *netdev)
 {
 }
+static inline int can_led_notifier_init(void)
+{
+	return 0;
+}
+static inline void can_led_notifier_exit(void)
+{
+}
 
 #endif
 
-- 
1.7.12.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/9] tx/rx LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (8 preceding siblings ...)
  2012-12-16 11:08 ` [PATCH 9/9] can: rename LED trigger name on netdev renames Fabio Baltieri
@ 2012-12-16 22:37 ` Marc Kleine-Budde
  2012-12-16 22:51   ` Fabio Baltieri
  2012-12-17  9:35 ` Kurt Van Dijck
  10 siblings, 1 reply; 19+ messages in thread
From: Marc Kleine-Budde @ 2012-12-16 22:37 UTC (permalink / raw)
  To: Fabio Baltieri
  Cc: linux-can, Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1272 bytes --]

On 12/16/2012 12:08 PM, Fabio Baltieri wrote:
> Hi all,
> 
> this is a resend of the patch series on tx/rx LEDs trigger.  The patch
> set was put on hold after the latest discussions on Kurt's rename patch
> due to a missing feature in the LED subsystem, which has been just
> merged in:
> 
> a8df7b1 leds: add led_trigger_rename function
> 
> So, as months passed since the latest developments, I'm reposting the
> whole set, rebased on current mainline.  The first patches are the same
> that were merged in can-next/led-trigger, but there was some (trivial)
> conflict in the rebase.
> 
> As for the test, I've tried the patch on the current mainline kernel
> with my custom usb-can interface.  For the drivers, I don't have any
> SoC-enabled board anymore, so they have only been compile tested.

Thanks for your work. Can you move patches 8+9 to the beginning, before
touching the device drivers. I'll apply on the Thursday, as I don't have
proper internet now.

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 261 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/9] tx/rx LED trigger support
  2012-12-16 22:37 ` [PATCH 0/9] tx/rx LED trigger support Marc Kleine-Budde
@ 2012-12-16 22:51   ` Fabio Baltieri
  0 siblings, 0 replies; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-16 22:51 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-can, Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel

Hello Marc,

On Sun, Dec 16, 2012 at 11:37:59PM +0100, Marc Kleine-Budde wrote:
> Thanks for your work. Can you move patches 8+9 to the beginning, before
> touching the device drivers. I'll apply on the Thursday, as I don't have
> proper internet now.

Ok, it makes sense.  In that case I'll wait a couple of days before
re-sending the reordered series, just in case someone else wants to
comment.

Thanks!
Fabio

-- 
Fabio Baltieri

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-16 11:08 ` [PATCH 1/9] can: add " Fabio Baltieri
@ 2012-12-17  7:28   ` Bernd Krumboeck
  2012-12-17  9:34     ` Kurt Van Dijck
  2012-12-17 17:41     ` Fabio Baltieri
  0 siblings, 2 replies; 19+ messages in thread
From: Bernd Krumboeck @ 2012-12-17  7:28 UTC (permalink / raw)
  To: Fabio Baltieri
  Cc: Marc Kleine-Budde, linux-can, Kurt Van Dijck,
	Wolfgang Grandegger, Oliver Hartkopp, linux-kernel

Hello Fabio!

Am 2012-12-16 12:08, schrieb Fabio Baltieri:
> 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

Why there is no patch for any usb can device?

Can this be done in a more general way, except patching every driver?


regards,
Bernd


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-17  7:28   ` Bernd Krumboeck
@ 2012-12-17  9:34     ` Kurt Van Dijck
  2012-12-17 17:41     ` Fabio Baltieri
  1 sibling, 0 replies; 19+ messages in thread
From: Kurt Van Dijck @ 2012-12-17  9:34 UTC (permalink / raw)
  To: Bernd Krumboeck
  Cc: Fabio Baltieri, Marc Kleine-Budde, linux-can,
	Wolfgang Grandegger, Oliver Hartkopp, linux-kernel

On Mon, Dec 17, 2012 at 08:28:48AM +0100, Bernd Krumboeck wrote:
> Hello Fabio!
> 
> Am 2012-12-16 12:08, schrieb Fabio Baltieri:
> >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
> 
> Why there is no patch for any usb can device?
> 
> Can this be done in a more general way, except patching every driver?

There must be a way.
Up to this series, there were a few minor problems:
* determine if a CAN device is can_dev based
* led trigger calls.

After this series, I think it's possible to make this functionality generic.
But up to then, this per-driver code is a working model.

Kind regards,
Kurt

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/9] tx/rx LED trigger support
  2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
                   ` (9 preceding siblings ...)
  2012-12-16 22:37 ` [PATCH 0/9] tx/rx LED trigger support Marc Kleine-Budde
@ 2012-12-17  9:35 ` Kurt Van Dijck
  10 siblings, 0 replies; 19+ messages in thread
From: Kurt Van Dijck @ 2012-12-17  9:35 UTC (permalink / raw)
  To: Fabio Baltieri; +Cc: linux-kernel

Fabio,

Nice work to repackage this :-) !

Kurt

On Sun, Dec 16, 2012 at 12:08:24PM +0100, Fabio Baltieri wrote:
> Hi all,
> 
> this is a resend of the patch series on tx/rx LEDs trigger.  The patch
> set was put on hold after the latest discussions on Kurt's rename patch
> due to a missing feature in the LED subsystem, which has been just
> merged in:
> 
> a8df7b1 leds: add led_trigger_rename function
> 
> So, as months passed since the latest developments, I'm reposting the
> whole set, rebased on current mainline.  The first patches are the same
> that were merged in can-next/led-trigger, but there was some (trivial)
> conflict in the rebase.
> 
> As for the test, I've tried the patch on the current mainline kernel
> with my custom usb-can interface.  For the drivers, I don't have any
> SoC-enabled board anymore, so they have only been compile tested.
> 
> Cheers,
> Fabio
> 
> 
> Fabio Baltieri (7):
>   can: add tx/rx LED trigger support
>   can: flexcan: add LED trigger support
>   can: at91_can: add LED trigger support
>   can: ti_hecc: add LED trigger support
>   can: c_can: add LED trigger support
>   can: mcp251x: add LED trigger support
>   can: sja1000: add LED trigger support
> 
> Kurt Van Dijck (2):
>   can: export a safe netdev_priv wrapper for candev
>   can: rename LED trigger name on netdev renames
> 
>  drivers/net/can/Kconfig           |  12 ++++
>  drivers/net/can/Makefile          |   2 +
>  drivers/net/can/at91_can.c        |  10 +++
>  drivers/net/can/c_can/c_can.c     |  10 +++
>  drivers/net/can/dev.c             |  18 ++++++
>  drivers/net/can/flexcan.c         |  11 ++++
>  drivers/net/can/led.c             | 129 ++++++++++++++++++++++++++++++++++++++
>  drivers/net/can/mcp251x.c         |  23 +++++--
>  drivers/net/can/sja1000/sja1000.c |  17 ++++-
>  drivers/net/can/ti_hecc.c         |  10 +++
>  include/linux/can/dev.h           |  11 ++++
>  include/linux/can/led.h           |  51 +++++++++++++++
>  12 files changed, 299 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/net/can/led.c
>  create mode 100644 include/linux/can/led.h
> 
> -- 
> 1.7.12.1
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-17  7:28   ` Bernd Krumboeck
  2012-12-17  9:34     ` Kurt Van Dijck
@ 2012-12-17 17:41     ` Fabio Baltieri
  2012-12-17 20:20       ` "Bernd Krumböck"
  1 sibling, 1 reply; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-17 17:41 UTC (permalink / raw)
  To: Bernd Krumboeck
  Cc: Marc Kleine-Budde, linux-can, Kurt Van Dijck,
	Wolfgang Grandegger, Oliver Hartkopp, linux-kernel

Hi Bernd,

On Mon, Dec 17, 2012 at 08:28:48AM +0100, Bernd Krumboeck wrote:
> Why there is no patch for any usb can device?

Because USB canbus interfaces usually already has some dedicated
activity LED on the device itself, while this patch is meant to give an
equivalent functionality for Embedded SoC with GPIO based LEDs, so I
just started by modifying some Embedded CAN drivers.

If you think it's useful for USB controller, just tell me or modify the
driver by yourself!  As you see the patch is really easy.

> Can this be done in a more general way, except patching every driver?

Actually this started as a generic patch bolted to the CAN stack, but
the implementation was too invasive and a bit too hacky.  A generic
implementation at can-dev level is hard to obtain because the can-dev
layer is not used in all the device operation, as the most of the driver
calls generick network API directly.

Fabio

-- 
Fabio Baltieri

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-17 17:41     ` Fabio Baltieri
@ 2012-12-17 20:20       ` "Bernd Krumböck"
  2012-12-17 21:42         ` Fabio Baltieri
  0 siblings, 1 reply; 19+ messages in thread
From: "Bernd Krumböck" @ 2012-12-17 20:20 UTC (permalink / raw)
  To: Fabio Baltieri, Bernd Krumboeck, Marc Kleine-Budde, linux-can,
	Kurt Van Dijck, Wolfgang Grandegger, Oliver Hartkopp,
	linux-kernel

> Hi Bernd,
>
> On Mon, Dec 17, 2012 at 08:28:48AM +0100, Bernd Krumboeck wrote:
>> Why there is no patch for any usb can device?
>
> Because USB canbus interfaces usually already has some dedicated
> activity LED on the device itself, while this patch is meant to give an
> equivalent functionality for Embedded SoC with GPIO based LEDs, so I
> just started by modifying some Embedded CAN drivers.
>
> If you think it's useful for USB controller, just tell me or modify the
> driver by yourself!  As you see the patch is really easy.

At least it is useful for the usb_8dev driver. I'll write a patch.

Photo of the device:
http://www.8devices.com/product/2/usb2can

>> Can this be done in a more general way, except patching every driver?
>
> Actually this started as a generic patch bolted to the CAN stack, but
> the implementation was too invasive and a bit too hacky.  A generic
> implementation at can-dev level is hard to obtain because the can-dev
> layer is not used in all the device operation, as the most of the driver
> calls generick network API directly.
>

Thanks!

regards,
Bernd

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-17 20:20       ` "Bernd Krumböck"
@ 2012-12-17 21:42         ` Fabio Baltieri
  2012-12-18  6:02           ` "Bernd Krumböck"
  0 siblings, 1 reply; 19+ messages in thread
From: Fabio Baltieri @ 2012-12-17 21:42 UTC (permalink / raw)
  To: "Bernd Krumböck"
  Cc: Marc Kleine-Budde, linux-can, Kurt Van Dijck,
	Wolfgang Grandegger, Oliver Hartkopp, linux-kernel

On Mon, Dec 17, 2012 at 09:20:57PM +0100, "Bernd Krumböck" wrote:
> > If you think it's useful for USB controller, just tell me or modify the
> > driver by yourself!  As you see the patch is really easy.
> 
> At least it is useful for the usb_8dev driver. I'll write a patch.
> 
> Photo of the device:
> http://www.8devices.com/product/2/usb2can

Sure that it's needed?  That status LED is probably controlled directly
by the firmware itself.  Anyway I think it makes sense to support all
the mainline drivers and I'm really happy if you test the patch on
your hardware!

My only suggestion is to keep the LED support on a separate patch from
the "add driver" one.

Cheers,
Fabio

-- 
Fabio Baltieri

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/9] can: add tx/rx LED trigger support
  2012-12-17 21:42         ` Fabio Baltieri
@ 2012-12-18  6:02           ` "Bernd Krumböck"
  0 siblings, 0 replies; 19+ messages in thread
From: "Bernd Krumböck" @ 2012-12-18  6:02 UTC (permalink / raw)
  To: Fabio Baltieri, "Bernd Krumböck",
	Marc Kleine-Budde, linux-can, Kurt Van Dijck,
	Wolfgang Grandegger, Oliver Hartkopp, linux-kernel

Hi Fabio!

> On Mon, Dec 17, 2012 at 09:20:57PM +0100, "Bernd Krumböck" wrote:
>> > If you think it's useful for USB controller, just tell me or modify
>> the
>> > driver by yourself!  As you see the patch is really easy.
>>
>> At least it is useful for the usb_8dev driver. I'll write a patch.
>>
>> Photo of the device:
>> http://www.8devices.com/product/2/usb2can
>
> Sure that it's needed?  That status LED is probably controlled directly
> by the firmware itself.  Anyway I think it makes sense to support all
> the mainline drivers and I'm really happy if you test the patch on
> your hardware!

Yes, it is controlled by the firmware, but it does not show rx/tx. Whereas
my OpenWRT hardware has enough leds. ;-)

regards,
Bernd

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-12-18  6:02 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-16 11:08 [PATCH 0/9] tx/rx LED trigger support Fabio Baltieri
2012-12-16 11:08 ` [PATCH 1/9] can: add " Fabio Baltieri
2012-12-17  7:28   ` Bernd Krumboeck
2012-12-17  9:34     ` Kurt Van Dijck
2012-12-17 17:41     ` Fabio Baltieri
2012-12-17 20:20       ` "Bernd Krumböck"
2012-12-17 21:42         ` Fabio Baltieri
2012-12-18  6:02           ` "Bernd Krumböck"
2012-12-16 11:08 ` [PATCH 2/9] can: flexcan: add " Fabio Baltieri
2012-12-16 11:08 ` [PATCH 3/9] can: at91_can: " Fabio Baltieri
2012-12-16 11:08 ` [PATCH 4/9] can: ti_hecc: " Fabio Baltieri
2012-12-16 11:08 ` [PATCH 5/9] can: c_can: " Fabio Baltieri
2012-12-16 11:08 ` [PATCH 6/9] can: mcp251x: " Fabio Baltieri
2012-12-16 11:08 ` [PATCH 7/9] can: sja1000: " Fabio Baltieri
2012-12-16 11:08 ` [PATCH 8/9] can: export a safe netdev_priv wrapper for candev Fabio Baltieri
2012-12-16 11:08 ` [PATCH 9/9] can: rename LED trigger name on netdev renames Fabio Baltieri
2012-12-16 22:37 ` [PATCH 0/9] tx/rx LED trigger support Marc Kleine-Budde
2012-12-16 22:51   ` Fabio Baltieri
2012-12-17  9:35 ` Kurt Van Dijck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).