mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Sojka <sojka@merica.cz>
To: linux-leds@vger.kernel.org
Cc: michal.vokac@comap.cz, Michal Sojka <sojka@merica.cz>,
	Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Matthias Beyer <mail@beyermatthias.de>,
	Hans de Goede <hdegoede@redhat.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Valentine Barshak <valentine.barshak@cogentembedded.com>,
	Michael Opdenacker <michael.opdenacker@free-electrons.com>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: [PATCH 2/2] leds: usb: Add LED trigger for USB host activity
Date: Fri, 22 Aug 2014 13:53:13 +0200	[thread overview]
Message-ID: <1408708399-20423-2-git-send-email-sojka@merica.cz> (raw)
In-Reply-To: <1408708399-20423-1-git-send-email-sojka@merica.cz>

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

This should work with all host controllers. Tested only with musb.

Signed-off-by: Michal Sojka <sojka@merica.cz>
---
 drivers/leds/trigger/Kconfig           |  8 ++++++
 drivers/leds/trigger/Makefile          |  1 +
 drivers/leds/trigger/ledtrig-usbhost.c | 45 ++++++++++++++++++++++++++++++++++
 drivers/usb/core/hcd.c                 |  3 +++
 include/linux/leds.h                   |  6 +++++
 5 files changed, 63 insertions(+)
 create mode 100644 drivers/leds/trigger/ledtrig-usbhost.c

diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index 9562963..528d736 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -49,6 +49,14 @@ config LEDS_TRIGGER_USBGADGET
 	  This allows LEDs to be controlled by USB gadget activity.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_USBHOST
+	bool "LED USB Host Trigger"
+	depends on USB
+	depends on LEDS_TRIGGERS
+	help
+	  This allows LEDs to be controlled by USB host 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 45917c0..9e9ca19 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -9,3 +9,4 @@ 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
+obj-$(CONFIG_LEDS_TRIGGER_USBHOST)	+= ledtrig-usbhost.o
diff --git a/drivers/leds/trigger/ledtrig-usbhost.c b/drivers/leds/trigger/ledtrig-usbhost.c
new file mode 100644
index 0000000..0a12f67
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-usbhost.c
@@ -0,0 +1,45 @@
+/*
+ * LED Trigger for USB Host 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_usbhost);
+static unsigned long usbhost_blink_delay = BLINK_DELAY;
+
+void ledtrig_usbhost_activity(void)
+{
+	led_trigger_blink_oneshot(ledtrig_usbhost,
+				  &usbhost_blink_delay, &usbhost_blink_delay, 0);
+}
+EXPORT_SYMBOL(ledtrig_usbhost_activity);
+
+static int __init ledtrig_usbhost_init(void)
+{
+	led_trigger_register_simple("usb-host", &ledtrig_usbhost);
+	return 0;
+}
+
+static void __exit ledtrig_usbhost_exit(void)
+{
+	led_trigger_unregister_simple(ledtrig_usbhost);
+}
+
+module_init(ledtrig_usbhost_init);
+module_exit(ledtrig_usbhost_exit);
+
+MODULE_AUTHOR("Michal Sojka <sojka@merica.cz>");
+MODULE_DESCRIPTION("LED Trigger for USB Host Activity");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 9c4e292..bcfea14 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -41,6 +41,7 @@
 #include <linux/workqueue.h>
 #include <linux/pm_runtime.h>
 #include <linux/types.h>
+#include <linux/leds.h>
 
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
@@ -1664,6 +1665,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
 	usbmon_urb_complete(&hcd->self, urb, status);
 	usb_anchor_suspend_wakeups(anchor);
 	usb_unanchor_urb(urb);
+	if (status == 0)
+		ledtrig_usbhost_activity();
 
 	/* pass ownership to the completion handler */
 	urb->status = status;
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 5d9668e..5653495 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -224,6 +224,12 @@ extern void ledtrig_usbgadget_activity(void);
 static inline void ledtrig_usbgadget_activity(void) {}
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_USBHOST
+extern void ledtrig_usbhost_activity(void);
+#else
+static inline void ledtrig_usbhost_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


  reply	other threads:[~2014-08-22 12:30 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-22 11:53 [PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity Michal Sojka
2014-08-22 11:53 ` Michal Sojka [this message]
2014-08-22 17:39 ` 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
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
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408708399-20423-2-git-send-email-sojka@merica.cz \
    --to=sojka@merica.cz \
    --cc=cooloney@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@beyermatthias.de \
    --cc=michael.opdenacker@free-electrons.com \
    --cc=michal.vokac@comap.cz \
    --cc=rpurdie@rpsys.net \
    --cc=stern@rowland.harvard.edu \
    --cc=valentine.barshak@cogentembedded.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®