Skip to contentSkip to conversation

leds: trigger: Introduce a USB port trigger

PATCH Superseded Rafał Miłecki 5 participants 9 messages Sep 8, 2016 – Sep 16, 2016

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 leds: trigger: Introduce a USB port trigger

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

There was also an idea of supporting other devices (PCI, SDIO, etc.) but as this driver already contains some USB specific code (and will get more) these should be probably separated drivers (triggers).

---
V2: Trying to add DT support, idea postponed as it will take more time
to discuss the bindings.
V3: Fix typos in commit and Documentation (thanks Jacek!)
Use "ports" sysfs file for adding and removing USB ports (thx Jacek) Check if there is USB device connected after adding new USB port Fix memory leak or two
V3.5: Fix e-mail address (thanks Matthias)
Simplify conditions in usbport_trig_notify (thx Matthias) Make "ports" a subdirectory with file per port, to match one value per file sysfs rule (thanks Greg)
As "ports" couldn't be used for adding and removing ports anymore, there are now "new_port" and "remove_port". Having them makes this API also common with e.g. pci and usb buses.
V4: Add Documentation/ABI/testing/sysfs-class-led-trigger-usbport and
reference it in Documentation/leds/ledtrig-usbport.txt to avoid doc duplication.
V5: Update commit message to explain driver design & Documentation
Avoid specifying ports manually and dummy files (chmod 0000) Don't use kobject_create_and_add but a struct attribute_group Fix typo, improve comments, update Date

---
 .../ABI/testing/sysfs-class-led-trigger-usbport    |  11 +
 Documentation/leds/ledtrig-usbport.txt             |  41 +++
 drivers/leds/trigger/Kconfig                       |   8 +
 drivers/leds/trigger/Makefile                      |   1 +
 drivers/leds/trigger/ledtrig-usbport.c             | 316 +++++++++++++++++++++
 5 files changed, 377 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-usbport
 create mode 100644 Documentation/leds/ledtrig-usbport.txt
 create mode 100644 drivers/leds/trigger/ledtrig-usbport.c
Documentation/ABI/testing/sysfs-class-led-trigger-usbport new file +11 -0
new file mode 100644
index 0000000..a9b7e92
@@ -0,0 +1,11 @@
+What:		/sys/class/leds/<led>/ports/<port>
+Date:		September 2016
+KernelVersion:	4.9
+Contact:	[email protected]
+Description:
+		Every dir entry represents a single USB port that can be
+		selected for the USB port trigger. Selecting ports makes trigger
+		observing them for any connected devices and lighting on LED if
+		there are any.
+		Echoing "1" value selects USB port. Echoing "0" unselects it.
+		Current state can be also read.
Documentation/leds/ledtrig-usbport.txt new file +41 -0

41 lines not on this page · raw message

drivers/leds/trigger/Kconfig +8 -0
index 3f9ddb9..bdd6fd2 100644
@@ -126,4 +126,12 @@ config LEDS_TRIGGER_PANIC
 	  a different trigger.
 	  If unsure, say Y.
 
+config LEDS_TRIGGER_USBPORT
+	tristate "USB port LED trigger"
+	depends on LEDS_TRIGGERS && USB
+	help
+	  This allows LEDs to be controlled by USB events. Enabling this option
+	  allows specifying list of USB ports that should turn on LED when some
+	  USB device gets connected.
+
 endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
index a72c43c..56e1741 100644
@@ -10,3 +10,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_PANIC)	+= ledtrig-panic.o
+obj-$(CONFIG_LEDS_TRIGGER_USBPORT)	+= ledtrig-usbport.o
drivers/leds/trigger/ledtrig-usbport.c new file +316 -0

316 lines not on this page · raw message

Signature · 1 line
2.9.3
#1 lore raw
Quoted 33 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Quoted 5 lines

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

It has such driver at: drivers/usb/common/led.c

Signature · 2 lines
Best Regards,
Peter Chen
#2 lore raw
Quoted 34 lines · Peter Chen
Quoted 33 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Quoted 7 lines
Quoted 5 lines

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

It has such driver at: drivers/usb/common/led.c

Oh, great, I had no idea about that. So if it comes to adding activity support, we'll have to well discuss that. We may e.g. not implement that or move existing feature into more generic usbport trigger or partially duplicate this feature.

Anyway, I hope this note on "usb-gadget" and "usb-host" triggers won't stop our work on "usbport". This driver implements different thing for now (discovering device in a USB port) and I don't think "usb-gadget" / "usb-host" could be extended to handle such cases.

Thanks for a hint though, I'll definitely keep that in mind during further development!

Signature · 1 line
Rafał
#3 lore raw
In reply to Peter Chen
Quoted 34 lines · Peter Chen
Quoted 33 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Quoted 7 lines
Quoted 5 lines

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

It has such driver at: drivers/usb/common/led.c

Ugh, I thought I had seen something like this before...

Rafał, can you just use this in-kernel code instead?

thanks,

greg k-h

#4 lore raw
Quoted 41 lines · Greg KH
Quoted 40 lines · Peter Chen
Quoted 38 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

Quoted 5 lines
Quoted 1 line

It has such driver at: drivers/usb/common/led.c

Ugh, I thought I had seen something like this before...

Rafał, can you just use this in-kernel code instead?

I really don't think I can because of all the reasons I carefully listed in the commit message.

Have you took a look at that simple driver? It does nothing I need. Its design doesn't allow implementing features I clearly listed in the commit message.

Signature · 1 line
Rafał
#5 lore raw
Quoted 46 lines · Rafał Miłecki
Quoted 45 lines · Greg KH
Quoted 34 lines · Peter Chen
Quoted 33 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Quoted 7 lines
Quoted 5 lines

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

It has such driver at: drivers/usb/common/led.c

Ugh, I thought I had seen something like this before...

Quoted 8 lines
Quoted 1 line

Rafał, can you just use this in-kernel code instead?

I really don't think I can because of all the reasons I carefully listed in the commit message.

Have you took a look at that simple driver? It does nothing I need. Its design doesn't allow implementing features I clearly listed in the commit message.

In any case, the new driver should probably go near the old one, at the very least.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw
Quoted 52 lines · Pavel Machek
Quoted 51 lines · Rafał Miłecki
Quoted 41 lines · Greg KH
Quoted 40 lines · Peter Chen
Quoted 38 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

Quoted 5 lines
Quoted 1 line

It has such driver at: drivers/usb/common/led.c

Ugh, I thought I had seen something like this before...

Rafał, can you just use this in-kernel code instead?

I really don't think I can because of all the reasons I carefully listed in the commit message.

Quoted 6 lines
Quoted 3 lines

Have you took a look at that simple driver? It does nothing I need. Its design doesn't allow implementing features I clearly listed in the commit message.

In any case, the new driver should probably go near the old one, at the very least.

I can do that. Anyone objects?

Signature · 1 line
Rafał
#7 lore raw
Quoted 53 lines · Rafał Miłecki
Quoted 52 lines · Pavel Machek
Quoted 51 lines · Rafał Miłecki
Quoted 41 lines · Greg KH
Quoted 40 lines · Peter Chen
Quoted 38 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

Quoted 5 lines
Quoted 1 line

It has such driver at: drivers/usb/common/led.c

Ugh, I thought I had seen something like this before...

Rafał, can you just use this in-kernel code instead?

I really don't think I can because of all the reasons I carefully listed in the commit message.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Have you took a look at that simple driver? It does nothing I need. Its design doesn't allow implementing features I clearly listed in the commit message.

In any case, the new driver should probably go near the old one, at the very least.

I can do that. Anyone objects?

It's OK with me.

Signature · 2 lines
Best regards,
Jacek Anaszewski
#8 lore raw
In reply to Rafał Miłecki
Quoted 53 lines · Rafał Miłecki
Quoted 52 lines · Pavel Machek
Quoted 51 lines · Rafał Miłecki
Quoted 41 lines · Greg KH
Quoted 40 lines · Peter Chen
Quoted 38 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit adds a new trigger responsible for turning on LED when USB device gets connected to the selected USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.

The trigger gets its documentation file but basically it just requires enabling it and selecting USB ports (e.g. echo 1 > ports/usb1-1).

There was a long discussion on design of this driver. Its current state is a result of picking them most adjustable solution as others couldn't handle all cases.

1) It wasn't possible for the driver to register separated trigger for each USB port. Some physical USB ports are handled by more than one controller and so by more than one USB port. E.g. USB 2.0 physical port may be handled by OHCI's port and EHCI's port.
It's also not possible to assign more than 1 trigger to a single LED and implementing such feature would be tricky due to syncing triggers and sysfs conflicts with old triggers.

2) Another idea was to register trigger per USB hub. This wouldn't allow handling devices with multiple USB LEDs and controllers (hubs) controlling more than 1 physical port. It's common for hubs to have few ports and each may have its own LED.

This final trigger is highly flexible. It allows selecting any USB ports for any LED. It was also modified (compared to the initial version) to allow choosing ports rather than having user /guess/ proper names. It was successfully tested on SmartRG SR400ac which has 3 USB LEDs, 2 physical ports and 3 controllers.

Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.

Quoted 5 lines
Quoted 1 line

It has such driver at: drivers/usb/common/led.c

Ugh, I thought I had seen something like this before...

Rafał, can you just use this in-kernel code instead?

I really don't think I can because of all the reasons I carefully listed in the commit message.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Have you took a look at that simple driver? It does nothing I need. Its design doesn't allow implementing features I clearly listed in the commit message.

In any case, the new driver should probably go near the old one, at the very least.

I can do that. Anyone objects?

I did not have time to study your patches in detail. IIRC there was something like "directory full of usb IDs". I'm not sure that's a way to go.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html