[OpenWrt-Devel] [PATCH 4/4] mvebu: add Turris Omnia LED configuration
Klaus Kudielka
klaus.kudielka at gmail.com
Thu Dec 13 00:29:52 EST 2018
With this commit users are able to configure all extra features of the
Turris Omnia LED driver (global brightness, individual LED color,
individual autonomous flag). For example:
uci set omnia_led.main.global_brightness='6'
uci set omnia_led.power.color='255 0 0'
service omnia_led start
uci commit
This is achieved by the /etc/init.d/omnia_led script, which generates its
own default configuration /etc/config/omnia_led upon the first boot.
In the default configuration, all LAN and PCI LEDs (5+3) function
autonomously. The remaining 4 LEDs are driven by software
(autonomous=0) and have sensible UCI defaults.
The WAN LED uses the netdev trigger (benefit: this also works with SFP).
Signed-off-by: Klaus Kudielka <klaus.kudielka at gmail.com>
---
.../mvebu/base-files/etc/board.d/01_leds | 6 ++
.../mvebu/base-files/etc/init.d/omnia_led | 90 +++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100755 target/linux/mvebu/base-files/etc/init.d/omnia_led
diff --git a/target/linux/mvebu/base-files/etc/board.d/01_leds b/target/linux/mvebu/base-files/etc/board.d/01_leds
index ff8d4a21c0..96723d0295 100755
--- a/target/linux/mvebu/base-files/etc/board.d/01_leds
+++ b/target/linux/mvebu/base-files/etc/board.d/01_leds
@@ -41,6 +41,12 @@ armada-385-linksys-venom)
ucidef_set_led_usbport "usb2" "USB 2" "pca963x:venom:blue:usb3_1" "usb2-port1" "usb3-port1"
ucidef_set_led_usbport "usb2_ss" "USB 2 SS" "pca963x:venom:blue:usb3_2" "usb3-port1"
;;
+armada-385-turris-omnia)
+ ucidef_set_led_default "power" "POWER" "omnia-led:power" "1"
+ ucidef_set_led_netdev "wan" "WAN" "omnia-led:wan" "eth2"
+ ucidef_set_led_default "user1" "A" "omnia-led:user1" "0"
+ ucidef_set_led_default "user2" "B" "omnia-led:user2" "0"
+ ;;
armada-xp-linksys-mamba)
ucidef_set_led_netdev "wan" "WAN" "mamba:white:wan" "eth1"
ucidef_set_led_usbport "usb1" "USB 1" "mamba:white:usb2" "usb1-port1"
diff --git a/target/linux/mvebu/base-files/etc/init.d/omnia_led b/target/linux/mvebu/base-files/etc/init.d/omnia_led
new file mode 100755
index 0000000000..bbe605d75a
--- /dev/null
+++ b/target/linux/mvebu/base-files/etc/init.d/omnia_led
@@ -0,0 +1,90 @@
+#!/bin/sh /etc/rc.common
+
+START=96
+
+. /lib/functions/leds.sh
+
+config=omnia_led
+
+omnia_set() {
+ local type
+ local sect
+
+ type=$1
+ sect=$2
+ uci set $config.$sect=$type
+ shift
+ shift
+ while [ -n "$1" ]; do
+ uci set $config.$sect.$1="$2"
+ shift
+ shift
+ done
+}
+
+omnia_generate_config() {
+ echo "Generating /etc/config/$config"
+ touch /etc/config/$config
+ omnia_set controller main global_brightness 100
+ omnia_set led all sysfs omnia-led:all color "255 255 255"
+ omnia_set led power sysfs omnia-led:power autonomous 0
+ omnia_set led lan0 sysfs omnia-led:lan0 autonomous 1
+ omnia_set led lan1 sysfs omnia-led:lan1 autonomous 1
+ omnia_set led lan2 sysfs omnia-led:lan2 autonomous 1
+ omnia_set led lan3 sysfs omnia-led:lan3 autonomous 1
+ omnia_set led lan4 sysfs omnia-led:lan4 autonomous 1
+ omnia_set led wan sysfs omnia-led:wan autonomous 0
+ omnia_set led pci1 sysfs omnia-led:pci1 autonomous 1
+ omnia_set led pci2 sysfs omnia-led:pci2 autonomous 1
+ omnia_set led pci3 sysfs omnia-led:pci3 autonomous 1
+ omnia_set led user1 sysfs omnia-led:user1 autonomous 0
+ omnia_set led user2 sysfs omnia-led:user2 autonomous 0
+ uci commit $config
+}
+
+omnia_load_global_brightness() {
+ local path
+ local global_brightness
+
+ path=/sys/bus/i2c/devices/1-002b
+ config_get global_brightness main global_brightness 100
+
+ [ -d $path ] && {
+ echo "Setting up led controller"
+ echo "$global_brightness" >$path/global_brightness 2>/dev/null ||
+ echo " Failed to set global_brightness to '$global_brightness'"
+ } || echo "Could not find led controller at $path"
+}
+
+omnia_load_led() {
+ local sysfs
+ local color
+ local autonomous
+
+ config_get sysfs $1 sysfs
+ config_get color $1 color
+ config_get autonomous $1 autonomous
+
+ [ -n "$sysfs" ] && {
+ [ -d "/sys/class/leds/$sysfs" ] && {
+ echo "Setting up $sysfs"
+ [ -n "$color" ] && {
+ led_set_attr "$sysfs" color "$color" 2>/dev/null ||
+ echo " Failed to set color to '$color'"
+ } || true
+ [ -n "$autonomous" ] && {
+ led_set_attr "$sysfs" autonomous "$autonomous" 2>/dev/null ||
+ echo " Failed to set autonomous to '$autonomous'"
+ } || true
+ } || echo "Could not find $sysfs in /sys/class/leds"
+ } || echo "Could not find sysfs option in led section '$1'"
+}
+
+start() {
+ [ $(board_name) = armada-385-turris-omnia -a -d /sys/bus/i2c/drivers/leds-omnia ] && {
+ [ ! -s /etc/config/$config ] && omnia_generate_config
+ config_load $config
+ omnia_load_global_brightness
+ config_foreach omnia_load_led led
+ }
+}
--
2.17.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list