usb: core: Introduce a USB port LED trigger
Subsystems (3)
PATCH v6 1/1 usb: core: Introduce a USB port LED 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 (comparing 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.
It was noted USB subsystem already has usb-gadget and usb-host triggers but they are pretty trivial ones. They indicate activity only and can't have ports specified.
In future it may be good idea to consider adding activity support to usbport as well. This should allow switching to this more generic driver and maybe marking old ones as obsolete.
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 so 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
V6: Move code to USB subsystem (thx Peter and Pavel)
Rebase on top of usb-next branch
Describe relation to existing USB triggers in commit message Switch to GPL v2 (I just prefer it after reading Linus's arguments)
Can someone from LED subsystem (Jacek? Richard?) give an Ack, if this patch looks OK to you, please? I hope it could help Greg taking it into usb-next.
--- .../ABI/testing/sysfs-class-led-trigger-usbport | 12 + Documentation/leds/ledtrig-usbport.txt | 41 +++ drivers/usb/core/Kconfig | 8 + drivers/usb/core/Makefile | 2 + drivers/usb/core/ledtrig-usbport.c | 314 +++++++++++++++++++++ 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/usb/core/ledtrig-usbport.c
Documentation/ABI/testing/sysfs-class-led-trigger-usbport new file +12 -0
@@ -0,0 +1,12 @@ +What: /sys/class/leds/<led>/ports/<port> +Date: September 2016 +KernelVersion: 4.9 +Contact: [email protected] + [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/usb/core/Kconfig +8 -0
@@ -82,3 +82,11 @@ config USB_OTG_FSM help Implements OTG Finite State Machine as specified in On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification. + +config USB_LEDS_TRIGGER_USBPORT + tristate "USB port LED trigger" + depends on USB && LEDS_TRIGGERS + help + This driver allows LEDs to be controlled by USB events. Enabling this + trigger allows specifying list of USB ports that should turn on LED + when some USB device gets connected.
drivers/usb/core/Makefile +2 -0
@@ -12,3 +12,5 @@ usbcore-$(CONFIG_PCI) += hcd-pci.o usbcore-$(CONFIG_ACPI) += usb-acpi.o obj-$(CONFIG_USB) += usbcore.o + +obj-$(CONFIG_USB_LEDS_TRIGGER_USBPORT) += ledtrig-usbport.o
drivers/usb/core/ledtrig-usbport.c new file +314 -0
314 lines not on this page · raw message
Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html