[LEDE-DEV] [PATCH 2/2] base-files: support usbport LED trigger

Rafał Miłecki zajec5 at gmail.com
Tue Oct 4 03:44:15 PDT 2016


From: Rafał Miłecki <rafal at milecki.pl>

This adds ucidef_set_led_usbport function that can be called by target
board.d files. Example usage:
ucidef_set_led_usbport "usb" "bcm53xx:blue:usb" "usb1-port1" "usb2-port1"

List of available ports can be fetched using:
ls -d /sys/bus/usb/devices/*/*-port*
or
echo usbport > trigger
ls ports/

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 package/base-files/files/bin/config_generate        |  9 +++++++++
 package/base-files/files/etc/init.d/led             | 10 ++++++++++
 .../base-files/files/lib/functions/uci-defaults.sh  | 21 +++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 80ed61b..785be48 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -335,6 +335,15 @@ generate_led() {
 			EOF
 		;;
 
+		usbport)
+			local ports port
+			json_get_values ports ports
+			uci set system.$cfg.trigger='usbport'
+			for port in $ports; do
+				uci add_list system.$cfg.port=$port
+			done
+		;;
+
 		rssi)
 			local iface minq maxq offset factor
 			json_get_vars iface minq maxq offset factor
diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led
index 79f2904..ad050f7 100755
--- a/package/base-files/files/etc/init.d/led
+++ b/package/base-files/files/etc/init.d/led
@@ -18,6 +18,7 @@ load_led() {
 	config_get name $1 name "$sysfs"
 	config_get trigger $1 trigger "none"
 	config_get dev $1 dev
+	config_get port $1 port
 	config_get mode $1 mode "link"
 	config_get_bool default $1 default "nil"
 	config_get delayon $1 delayon
@@ -78,6 +79,15 @@ load_led() {
 			}
 			;;
 
+		"usbport")
+			[ -n "$port" ] && {
+				local p
+				for p in $port; do
+					echo 1 > /sys/class/leds/${sysfs}/ports/$p
+				done
+			}
+			;;
+
 		"port_state")
 			[ -n "$port_state" ] && \
 				echo $port_state > /sys/class/leds/${sysfs}/port_state
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index a88308b..a86cb04 100755
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -390,6 +390,27 @@ ucidef_set_led_usbdev() {
 	json_select ..
 }
 
+ucidef_set_led_usbport() {
+	local obj="$1"
+	local sysfs="$2"
+	shift
+	shift
+
+	json_select_object led
+
+	json_select_object "$obj"
+	json_add_string type usbport
+	json_add_string sysfs "$sysfs"
+	json_select_array ports
+		for port in "$@"; do
+			json_add_string port "$port"
+		done
+	json_select ..
+	json_select ..
+
+	json_select ..
+}
+
 ucidef_set_led_wlan() {
 	local cfg="led_$1"
 	local name="$2"
-- 
2.9.3




More information about the Lede-dev mailing list