linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity
@ 2014-08-22 11:53 Michal Sojka
  2014-08-22 11:53 ` [PATCH 2/2] leds: usb: Add LED trigger for USB host activity Michal Sojka
                   ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Michal Sojka @ 2014-08-22 11:53 UTC (permalink / raw)
  To: linux-leds
  Cc: michal.vokac, Michal Sojka, Bryan Wu, Richard Purdie,
	Felipe Balbi, Greg Kroah-Hartman, linux-kernel, linux-usb

With this patch, USB gadget activity can be signaled by blinking a LED.

Since there is no generic code where to put the trigger for all USB
controllers, each USB controller needs to call the trigger individually.
This patch adds the call only for the musb controller where I can test
it.

Signed-off-by: Michal Sojka <sojka@merica.cz>
---
 drivers/leds/trigger/Kconfig             |  8 ++++++
 drivers/leds/trigger/Makefile            |  1 +
 drivers/leds/trigger/ledtrig-usbgadget.c | 45 ++++++++++++++++++++++++++++++++
 drivers/usb/musb/musb_gadget.c           |  6 +++--
 include/linux/leds.h                     |  6 +++++
 5 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 drivers/leds/trigger/ledtrig-usbgadget.c

diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index 49794b4..9562963 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -41,6 +41,14 @@ config LEDS_TRIGGER_IDE_DISK
 	  This allows LEDs to be controlled by IDE disk activity.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_USBGADGET
+	bool "LED USB Gadget Trigger"
+	depends on (USB_MUSB_GADGET || USB_MUSB_DUAL_ROLE)
+	depends on LEDS_TRIGGERS
+	help
+	  This allows LEDs to be controlled by USB gadget activity.
+	  If unsure, say Y.
+
 config LEDS_TRIGGER_HEARTBEAT
 	tristate "LED Heartbeat Trigger"
 	depends on LEDS_TRIGGERS
diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
index 1abf48d..45917c0 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU)		+= ledtrig-cpu.o
 obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON)	+= ledtrig-default-on.o
 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT)	+= ledtrig-transient.o
 obj-$(CONFIG_LEDS_TRIGGER_CAMERA)	+= ledtrig-camera.o
+obj-$(CONFIG_LEDS_TRIGGER_USBGADGET)	+= ledtrig-usbgadget.o
diff --git a/drivers/leds/trigger/ledtrig-usbgadget.c b/drivers/leds/trigger/ledtrig-usbgadget.c
new file mode 100644
index 0000000..1eb90da
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-usbgadget.c
@@ -0,0 +1,45 @@
+/*
+ * LED Trigger for USB Gadget Activity
+ *
+ * Copyright 2014 Michal Sojka <sojka@merica.cz>
+ *
+ * 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/kernel.h>
+#include <linux/init.h>
+#include <linux/leds.h>
+
+#define BLINK_DELAY 30
+
+DEFINE_LED_TRIGGER(ledtrig_usbgadget);
+static unsigned long usbgadget_blink_delay = BLINK_DELAY;
+
+void ledtrig_usbgadget_activity(void)
+{
+	led_trigger_blink_oneshot(ledtrig_usbgadget,
+				  &usbgadget_blink_delay, &usbgadget_blink_delay, 0);
+}
+EXPORT_SYMBOL(ledtrig_usbgadget_activity);
+
+static int __init ledtrig_usbgadget_init(void)
+{
+	led_trigger_register_simple("usb-gadget", &ledtrig_usbgadget);
+	return 0;
+}
+
+static void __exit ledtrig_usbgadget_exit(void)
+{
+	led_trigger_unregister_simple(ledtrig_usbgadget);
+}
+
+module_init(ledtrig_usbgadget_init);
+module_exit(ledtrig_usbgadget_exit);
+
+MODULE_AUTHOR("Michal Sojka <sojka@merica.cz>");
+MODULE_DESCRIPTION("LED Trigger for USB Gadget Activity");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index d4aa779..98f8b24 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -42,6 +42,7 @@
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
+#include <linux/leds.h>
 
 #include "musb_core.h"
 
@@ -167,11 +168,12 @@ __acquires(ep->musb->lock)
 	if (!dma_mapping_error(&musb->g.dev, request->dma))
 		unmap_dma_buffer(req, musb);
 
-	if (request->status == 0)
+	if (request->status == 0) {
 		dev_dbg(musb->controller, "%s done request %p,  %d/%d\n",
 				ep->end_point.name, request,
 				req->request.actual, req->request.length);
-	else
+		ledtrig_usbgadget_activity();
+	} else
 		dev_dbg(musb->controller, "%s request %p, %d/%d fault %d\n",
 				ep->end_point.name, request,
 				req->request.actual, req->request.length,
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 0287ab2..5d9668e 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -218,6 +218,12 @@ extern void ledtrig_ide_activity(void);
 static inline void ledtrig_ide_activity(void) {}
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_USBGADGET
+extern void ledtrig_usbgadget_activity(void);
+#else
+static inline void ledtrig_usbgadget_activity(void) {}
+#endif
+
 #if defined(CONFIG_LEDS_TRIGGER_CAMERA) || defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
 extern void ledtrig_flash_ctrl(bool on);
 extern void ledtrig_torch_ctrl(bool on);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 37+ messages in thread
* [PATCH v5 0/3] LED triggers for USB host and device
@ 2014-09-17  7:21 Michal Sojka
  2014-09-17  7:21 ` [PATCH v5 3/3] usb: Add LED triggers for USB activity Michal Sojka
  0 siblings, 1 reply; 37+ messages in thread
From: Michal Sojka @ 2014-09-17  7:21 UTC (permalink / raw)
  To: linux-usb
  Cc: Michal Sojka, Alan Stern, Bryan Wu, Felipe Balbi,
	Greg Kroah-Hartman, Linux LED Subsystem, linux-kernel,
	michal.vokac

(this is resend of a patch series from about three weeks ago)

This adds LED triggers for USB host and device. First patch refactors
UDC drivers as requested by Felipe Balbi, second is a preparation for
the third, which adds the LED triggers.

Changes from v4:
- Added performance numbers to the commit message of the last patch
  (greg k-h).
- Replaced BUG_ON with pr_err (Alan Stern, greg k-h).
- Used proper coding style for switch statement (greg k-h).
- Added comment about NULL argument (greg k-h).
- EXPORT_SYMBOL changed to EXPORT_SYMBOL_GPL (greg k-h).
- Both triggers are now registerd even if host or gagdet subsystem
  is not enabled (Bryan Wu, greg k-h).

Changes from v3:
- usb_gadget_giveback_request() moved outside of CONFIG_HAS_DMA
  conditioned block.
- Added kernel-doc for usb_gadget_giveback_request() (Felipe Balbi).
- Removed outdated comment (Alan Stern).
- req->complete == NULL is now a bug. Previously, this was ignored
  (Alan Stern).
- File rename moved to a separate commit (greg k-h).

Changes from v2:
- Host/gadget triggers merged to a single file in usb/common/ (Felipe
  Balbi).
- UDC drivers refactored so that LED trigger works for all of them.

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/.
- Improved Kconfig help.
- Linked with other modules rather than being standalone modules.

Michal Sojka (3):
  usb: gadget: Refactor request completion
  usb: Rename usb-common.c
  usb: Add LED triggers for USB activity

 drivers/usb/Kconfig                           | 10 +++++
 drivers/usb/chipidea/udc.c                    |  6 +--
 drivers/usb/common/Makefile                   |  5 ++-
 drivers/usb/common/{usb-common.c => common.c} |  0
 drivers/usb/common/led.c                      | 57 +++++++++++++++++++++++++++
 drivers/usb/core/hcd.c                        |  2 +
 drivers/usb/dwc2/gadget.c                     |  6 +--
 drivers/usb/dwc3/gadget.c                     |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c           |  2 +-
 drivers/usb/gadget/udc/at91_udc.c             |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c       |  4 +-
 drivers/usb/gadget/udc/bcm63xx_udc.c          |  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c            | 10 ++---
 drivers/usb/gadget/udc/fotg210-udc.c          |  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c           |  6 +--
 drivers/usb/gadget/udc/fsl_udc_core.c         |  6 +--
 drivers/usb/gadget/udc/fusb300_udc.c          |  2 +-
 drivers/usb/gadget/udc/goku_udc.c             |  2 +-
 drivers/usb/gadget/udc/gr_udc.c               |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c          |  2 +-
 drivers/usb/gadget/udc/m66592-udc.c           |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c          |  8 +---
 drivers/usb/gadget/udc/mv_udc_core.c          |  8 +---
 drivers/usb/gadget/udc/net2272.c              |  2 +-
 drivers/usb/gadget/udc/net2280.c              |  2 +-
 drivers/usb/gadget/udc/omap_udc.c             |  2 +-
 drivers/usb/gadget/udc/pch_udc.c              |  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c           |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c           |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c         |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c            |  3 +-
 drivers/usb/gadget/udc/s3c2410_udc.c          |  2 +-
 drivers/usb/gadget/udc/udc-core.c             | 23 +++++++++++
 drivers/usb/musb/musb_gadget.c                |  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c        |  2 +-
 include/linux/usb.h                           | 12 ++++++
 include/linux/usb/gadget.h                    |  8 ++++
 37 files changed, 157 insertions(+), 57 deletions(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)
 create mode 100644 drivers/usb/common/led.c

-- 
2.1.0

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

end of thread, other threads:[~2014-09-17  7:22 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-22 11:53 [PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity Michal Sojka
2014-08-22 11:53 ` [PATCH 2/2] leds: usb: Add LED trigger for USB host activity Michal Sojka
     [not found] ` <1408708399-20423-1-git-send-email-sojka-Knnw/vAvyUalVyrhU4qvOw@public.gmane.org>
2014-08-22 17:39   ` [PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity Bryan Wu
2014-08-22 21:42     ` Greg Kroah-Hartman
2014-08-22 23:41       ` Bryan Wu
2014-08-22 23:44       ` Michal Sojka
2014-08-22 21:59 ` Felipe Balbi
2014-08-22 23:54   ` Michal Sojka
2014-08-23  0:08     ` [PATCH v2 0/3] LED triggers for USB host and device Michal Sojka
2014-08-23  0:08       ` [PATCH v2 1/3] usb: Add missing #include Michal Sojka
2014-08-23  0:08       ` [PATCH v2 2/3] usb: Add LED trigger for USB host activity Michal Sojka
2014-08-23  0:30         ` Bryan Wu
2014-08-23  9:52           ` Michal Sojka
     [not found]             ` <87egw7a5yd.fsf-RBRde3N6TzKEyWgh05NgWw@public.gmane.org>
2014-08-25 18:59               ` Bryan Wu
2014-08-27 13:03                 ` [PATCH v3 0/2] LED triggers for USB host and device Michal Sojka
2014-08-27 13:03                   ` [PATCH v3 1/2] usb: gadget: Refactor request completion Michal Sojka
2014-08-27 13:43                     ` Michal Sojka
2014-08-27 15:03                     ` Alan Stern
     [not found]                     ` <1409144625-25274-2-git-send-email-sojka-Knnw/vAvyUalVyrhU4qvOw@public.gmane.org>
2014-08-27 20:17                       ` Felipe Balbi
2014-08-27 13:03                   ` [PATCH v3 2/2] usb: Add LED triggers for USB activity Michal Sojka
2014-08-27 19:27                     ` Greg Kroah-Hartman
2014-08-27 19:30                       ` Felipe Balbi
2014-08-27 20:57                         ` [PATCH v4 0/3] LED triggers for USB host and device Michal Sojka
2014-08-27 20:57                           ` [PATCH v4 1/3] usb: gadget: Refactor request completion Michal Sojka
2014-08-27 21:03                             ` Alan Stern
2014-08-27 21:09                             ` Greg Kroah-Hartman
2014-08-27 20:57                           ` [PATCH v4 2/3] usb: Rename usb-common.c Michal Sojka
2014-08-27 20:58                           ` [PATCH v4 3/3] usb: Add LED triggers for USB activity Michal Sojka
2014-08-27 21:08                             ` Greg Kroah-Hartman
2014-08-29 12:57                               ` Michal Sojka
2014-08-29 13:07                                 ` [PATCH v5 0/3] LED triggers for USB host and device Michal Sojka
2014-08-29 13:07                                   ` [PATCH v5 1/3] usb: gadget: Refactor request completion Michal Sojka
2014-08-29 13:07                                   ` [PATCH v5 2/3] usb: Rename usb-common.c Michal Sojka
2014-08-29 13:07                                   ` [PATCH v5 3/3] usb: Add LED triggers for USB activity Michal Sojka
2014-08-23  0:08       ` [PATCH v2 3/3] usb: Add LED trigger for USB gadget activity Michal Sojka
2014-08-23  0:23       ` [PATCH v2 0/3] LED triggers for USB host and device Bryan Wu
  -- strict thread matches above, loose matches on Subject: below --
2014-09-17  7:21 [PATCH v5 " Michal Sojka
2014-09-17  7:21 ` [PATCH v5 3/3] usb: Add LED triggers for USB activity Michal Sojka

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).