From 8b0c053671e5fb7f36c123a281c51a8071bf96e3 Mon Sep 17 00:00:00 2001 From: Christian Lamparter Date: Thu, 13 Aug 2020 18:26:19 +0200 Subject: apm821xx: implement new LED label naming scheme This patch updates all current APM82181 devices over to that "new LED naming scheme". This includes many updates to the device-tree: - dropped the deprecated, but beloved "label" property. - rename all DT leds node names to led-#. - add function and color properties. - utilized panic-indicator property. - dropped led- aliases (see below). migration scripts for all devices are included. For more information. See: For the future: It looks like the color+function properties won over the dt-alias / label. This will need to be wired up into openwrt eventually. For APM821xx the situation is that all devices have a dedicated power and fault indicator. Signed-off-by: Christian Lamparter --- .../linux/apm821xx/base-files/etc/board.d/01_leds | 44 ++++++++--------- target/linux/apm821xx/base-files/etc/diag.sh | 50 +++++++++++++++++++ .../base-files/etc/uci-defaults/04_led_migration | 56 ++++++++++++++++++++++ target/linux/apm821xx/dts/meraki-mr24.dts | 45 ++++++++++------- target/linux/apm821xx/dts/meraki-mx60.dts | 50 +++++++++++-------- target/linux/apm821xx/dts/netgear-wndap620.dts | 11 +++-- target/linux/apm821xx/dts/netgear-wndap660.dts | 24 ++++++---- target/linux/apm821xx/dts/netgear-wndap6x0.dtsi | 34 +++++++------ target/linux/apm821xx/dts/netgear-wndr4700.dts | 55 +++++++++++---------- target/linux/apm821xx/dts/wd-mybooklive.dts | 26 +++++----- 10 files changed, 273 insertions(+), 122 deletions(-) create mode 100644 target/linux/apm821xx/base-files/etc/diag.sh create mode 100644 target/linux/apm821xx/base-files/etc/uci-defaults/04_led_migration (limited to 'target/linux/apm821xx') diff --git a/target/linux/apm821xx/base-files/etc/board.d/01_leds b/target/linux/apm821xx/base-files/etc/board.d/01_leds index c6f855cd2d..0b203fd8a7 100644 --- a/target/linux/apm821xx/base-files/etc/board.d/01_leds +++ b/target/linux/apm821xx/base-files/etc/board.d/01_leds @@ -7,40 +7,40 @@ board=$(board_name) case "$board" in meraki,mr24) - ucidef_set_led_netdev "wan" "WAN" "mr24:green:wan" "eth0" - ucidef_set_led_wlan "wlan5g_1" "WIFI 5GHz-1" "mr24:green:wifi1" "phy1tpt" - ucidef_set_led_wlan "wlan5g_0" "WIFI 5GHz-0" "mr24:green:wifi2" "phy1radio" - ucidef_set_led_wlan "wlan2g_1" "WIFI 2.4GHz-1" "mr24:green:wifi3" "phy0tpt" - ucidef_set_led_wlan "wlan2g_0" "WIFI 2.4GHz-0" "mr24:green:wifi4" "phy0radio" + ucidef_set_led_netdev "wan" "WAN" "green:wan" "eth0" + ucidef_set_led_wlan "wlan5g_1" "WIFI 5GHz-1" "green:wlan-0" "phy1tpt" + ucidef_set_led_wlan "wlan5g_0" "WIFI 5GHz-0" "green:wlan-1" "phy1radio" + ucidef_set_led_wlan "wlan2g_1" "WIFI 2.4GHz-1" "green:wlan-2" "phy0tpt" + ucidef_set_led_wlan "wlan2g_0" "WIFI 2.4GHz-0" "green:wlan-3" "phy0radio" ;; meraki,mx60) - ucidef_set_led_switch "wan" "WAN" "mx60:green:wan" "switch0" "0x20" - ucidef_set_led_switch "lan1" "LAN1" "mx60:green:lan1" "switch0" "0x10" - ucidef_set_led_switch "lan2" "LAN2" "mx60:green:lan2" "switch0" "0x08" - ucidef_set_led_switch "lan3" "LAN3" "mx60:green:lan3" "switch0" "0x04" - ucidef_set_led_switch "lan4" "LAN4" "mx60:green:lan4" "switch0" "0x02" + ucidef_set_led_switch "wan" "WAN" "green:wan" "switch0" "0x20" + ucidef_set_led_switch "lan1" "LAN1" "green:lan-0" "switch0" "0x10" + ucidef_set_led_switch "lan2" "LAN2" "green:lan-1" "switch0" "0x08" + ucidef_set_led_switch "lan3" "LAN3" "green:lan-2" "switch0" "0x04" + ucidef_set_led_switch "lan4" "LAN4" "green:lan-3" "switch0" "0x02" ;; netgear,wndap620) - ucidef_set_led_switch "lan_act" "LAN (Activity)" "wndap6x0:green:activity" "switch0" "0x04" "0x0f" "rx tx" - ucidef_set_led_switch "lan_100" "LAN 100Mbps" "wndap620:amber:link100" "switch0" "0x04" "0x04" "link" - ucidef_set_led_switch "lan_1000" "LAN 1000Mbps" "wndap620:green:link1000" "switch0" "0x04" "0x08" "link" + ucidef_set_led_switch "lan_act" "LAN (Activity)" "green:activity" "switch0" "0x04" "0x0f" "rx tx" + ucidef_set_led_switch "lan_100" "LAN 100Mbps" "amber:lan" "switch0" "0x04" "0x04" "link" + ucidef_set_led_switch "lan_1000" "LAN 1000Mbps" "green:lan" "switch0" "0x04" "0x08" "link" ;; netgear,wndap660) - ucidef_set_led_netdev "lan_act" "LAN (Activity)" "wndap6x0:green:activity" "eth0" - ucidef_set_led_switch "lan1_100" "LAN 100Mbps" "wndap660:amber:lan1-link100" "switch0" "0x04" "0x04" "link" - ucidef_set_led_switch "lan1_1000" "LAN 1000Mbps" "wndap660:green:lan1-link1000" "switch0" "0x04" "0x08" "link" - ucidef_set_led_switch "lan2_100" "LAN 100Mbps" "wndap660:amber:lan2-link100" "switch0" "0x02" "0x04" "link" - ucidef_set_led_switch "lan2_1000" "LAN 1000Mbps" "wndap660:green:lan2-link1000" "switch0" "0x02" "0x08" "link" - ucidef_set_led_wlan "wlan2g" "WLAN2G" "wndap6x0:green:wlan2g" "phy0tpt" - ucidef_set_led_wlan "wlan5g" "WLAN5G" "wndap6x0:green:wlan5g" "phy1tpt" + ucidef_set_led_netdev "lan_act" "LAN (Activity)" "green:activity" "eth0" + ucidef_set_led_switch "lan1_100" "LAN 100Mbps" "amber:lan-0" "switch0" "0x04" "0x04" "link" + ucidef_set_led_switch "lan1_1000" "LAN 1000Mbps" "green:lan-0" "switch0" "0x04" "0x08" "link" + ucidef_set_led_switch "lan2_100" "LAN 100Mbps" "amber:lan-1" "switch0" "0x02" "0x04" "link" + ucidef_set_led_switch "lan2_1000" "LAN 1000Mbps" "green:lan-1" "switch0" "0x02" "0x08" "link" + ucidef_set_led_wlan "wlan2g" "WLAN2G" "green:wlan-0" "phy0tpt" + ucidef_set_led_wlan "wlan5g" "WLAN5G" "green:wlan-1" "phy1tpt" ;; netgear,wndr4700) - ucidef_set_led_switch "wan_green" "WAN (green)" "wndr4700:green:wan" "switch0" "0x20" - ucidef_set_led_netdev "wan_yellow" "WAN (yellow)" "wndr4700:yellow:wan" "eth0.2" "tx rx" + ucidef_set_led_switch "wan_green" "WAN (green)" "green:wan" "switch0" "0x20" + ucidef_set_led_netdev "wan_yellow" "WAN (yellow)" "yellow:wan" "eth0.2" "tx rx" ;; esac diff --git a/target/linux/apm821xx/base-files/etc/diag.sh b/target/linux/apm821xx/base-files/etc/diag.sh new file mode 100644 index 0000000000..9a2f4202bb --- /dev/null +++ b/target/linux/apm821xx/base-files/etc/diag.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only + +. /lib/functions/leds.sh + +get_status_led() { + local status_led_file + + status_led_file=$(find /sys/class/leds/ -name "*:power" | head -n1) + if [ -d "$status_led_file" ]; then + basename $status_led_file + return + fi; +} + +get_failsafe_led() { + local status_led_file + + status_led_file=$(find /sys/class/leds/ -name "*:fault" | head -n1) + if [ -d "$status_led_file" ]; then + basename $status_led_file + return + fi; +} + +set_state() { + status_led=$(get_status_led) + + [ -z "$status_led" ] && return + + case "$1" in + preinit) + status_led_blink_preinit + ;; + failsafe) + status_led_off + status_led=$(get_failsafe_led) + status_led_blink_failsafe + ;; + preinit_regular) + status_led_blink_preinit_regular + ;; + upgrade) + status_led_blink_preinit_regular + ;; + done) + status_led_on + ;; + esac +} diff --git a/target/linux/apm821xx/base-files/etc/uci-defaults/04_led_migration b/target/linux/apm821xx/base-files/etc/uci-defaults/04_led_migration new file mode 100644 index 0000000000..b15ffa34af --- /dev/null +++ b/target/linux/apm821xx/base-files/etc/uci-defaults/04_led_migration @@ -0,0 +1,56 @@ +. /lib/functions.sh +. /lib/functions/migrations.sh + +board=$(board_name) + +case "$board" in +meraki,mr24) + migrate_leds "orange:power=amber:fault" \ + ":wifi1=:wlan-0" \ + ":wifi2=:wlan-1" \ + ":wifi3=:wlan-2" \ + ":wifi4=:wlan-3" + ;; +meraki,mx60) + migrate_leds ":lan1=:lan-0" \ + ":lan2=:lan-1" \ + ":lan3=:lan-2" \ + ":lan4=:lan-3" \ + "orange:power=amber:power" \ + "orange:wan=amber:wan" + ;; +netgear,wndap620) + migrate_leds ":activity=:lan-0" \ + ":test=:fault" \ + ":wlan2g=:wlan-0" \ + ":wlan5g=:wlan-1" \ + ":link100=:lan" \ + ":link1000=:lan-1" + ;; +netgear,wndap660) + migrate_leds ":activity=:lan-0" \ + ":test=:fault" \ + ":wlan2g=:wlan-0" \ + ":wlan5g=:wlan-1" \ + ":lan1-link100=:lan-0" \ + ":lan1-link1000=:lan-1" \ + ":lan2-link100=:lan-1" \ + ":lan2-link1000=:lan-2" + ;; +netgear,wndr4700) + migrate_leds "orange:power=amber:fault" \ + "white:logo=white:indicator" \ + "green:hd=green:disk" \ + "red:hd=red:disk-err" + ;; +wd,mybooklive) + migrate_leds "red:power=red:fault" \ + "blue:power=blue:disk" + ;; +esac + +remove_devicename_leds + +migrations_apply system + +exit 0 diff --git a/target/linux/apm821xx/dts/meraki-mr24.dts b/target/linux/apm821xx/dts/meraki-mr24.dts index 2f797f8352..e20d4f1fa9 100644 --- a/target/linux/apm821xx/dts/meraki-mr24.dts +++ b/target/linux/apm821xx/dts/meraki-mr24.dts @@ -9,6 +9,7 @@ /dts-v1/; +#include #include "apm82181.dtsi" / { @@ -17,10 +18,6 @@ aliases { serial0 = &UART1; - led-boot = &status; - led-failsafe = &failsafe; - led-running = &status; - led-upgrade = &status; }; chosen { @@ -128,38 +125,50 @@ leds { compatible = "gpio-leds"; - status: power-green { - label = "mr24:green:power"; + led-0 { + color = ; + function = LED_FUNCTION_POWER; gpios = <&GPIO0 18 GPIO_ACTIVE_LOW>; }; - failsafe: power-orange { - label = "mr24:orange:power"; + led-1 { + color = ; + function = LED_FUNCTION_FAULT; gpios = <&GPIO0 19 GPIO_ACTIVE_LOW>; + panic-indicator; }; - lan { - label = "mr24:green:wan"; + led-2 { + color = ; + function = LED_FUNCTION_WAN; gpios = <&GPIO0 17 GPIO_ACTIVE_LOW>; }; - ssi-0 { - label = "mr24:green:wifi1"; + led-3 { + color = ; + function = LED_FUNCTION_WLAN; + function-enumerator = <0>; gpios = <&GPIO0 23 GPIO_ACTIVE_LOW>; }; - ssi-1 { - label = "mr24:green:wifi2"; + led-4 { + color = ; + function = LED_FUNCTION_WLAN; + function-enumerator = <1>; gpios = <&GPIO0 22 GPIO_ACTIVE_LOW>; }; - ssi-2 { - label = "mr24:green:wifi3"; + led-5 { + color = ; + function = LED_FUNCTION_WLAN; + function-enumerator = <2>; gpios = <&GPIO0 21 GPIO_ACTIVE_LOW>; }; - ssi-3 { - label = "mr24:green:wifi4"; + led-6 { + color = ; + function = LED_FUNCTION_WLAN; + function-enumerator = <3>; gpios = <&GPIO0 20 GPIO_ACTIVE_LOW>; }; }; diff --git a/target/linux/apm821xx/dts/meraki-mx60.dts b/target/linux/apm821xx/dts/meraki-mx60.dts index fd5464f8a1..06dfa07965 100644 --- a/target/linux/apm821xx/dts/meraki-mx60.dts +++ b/target/linux/apm821xx/dts/meraki-mx60.dts @@ -9,6 +9,7 @@ /dts-v1/; +#include #include "apm82181.dtsi" / { @@ -17,10 +18,6 @@ aliases { serial0 = &UART1; - led-boot = &status; - led-failsafe = &failsafe; - led-running = &status; - led-upgrade = &status; }; chosen { @@ -116,43 +113,56 @@ leds { compatible = "gpio-leds"; - status: power-green { - label = "mx60:green:power"; + led-0 { + color = ; + function = LED_FUNCTION_POWER; gpios = <&GPIO0 18 GPIO_ACTIVE_LOW>; }; - failsafe: power-orange { - label = "mx60:orange:power"; + led-1 { + color = ; + function = LED_FUNCTION_FAULT; gpios = <&GPIO0 19 GPIO_ACTIVE_LOW>; + panic-indicator; }; - wan-green { - label = "mx60:green:wan"; + led-2 { + color = ; + function = LED_FUNCTION_WAN; gpios = <&GPIO0 17 GPIO_ACTIVE_LOW>; }; - wan-orange { - label = "mx60:orange:wan"; + led-3 { + color = ; + function = LED_FUNCTION_WAN; gpios = <&GPIO0 15 GPIO_ACTIVE_LOW>; }; - lan1 { - label = "mx60:green:lan1"; + led-4 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <0>; gpios = <&GPIO0 20 GPIO_ACTIVE_LOW>; }; - lan2 { - label = "mx60:green:lan2"; + led-5 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; gpios = <&GPIO0 21 GPIO_ACTIVE_LOW>; }; - lan3 { - label = "mx60:green:lan3"; + led-6 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <2>; gpios = <&GPIO0 22 GPIO_ACTIVE_LOW>; }; - lan4 { - label = "mx60:green:lan4"; + led-7 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <3>; gpios = <&GPIO0 23 GPIO_ACTIVE_LOW>; }; }; diff --git a/target/linux/apm821xx/dts/netgear-wndap620.dts b/target/linux/apm821xx/dts/netgear-wndap620.dts index d72aef4def..50e1d0cf17 100644 --- a/target/linux/apm821xx/dts/netgear-wndap620.dts +++ b/target/linux/apm821xx/dts/netgear-wndap620.dts @@ -10,13 +10,16 @@ }; &LEDS { - link1000 { - label = "wndap620:green:link1000"; + led-5 { + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + color = ; gpios = <&GPIO0 9 GPIO_ACTIVE_HIGH>; }; - link100 { - label = "wndap620:amber:link100"; + led-6 { + function = LED_FUNCTION_LAN; + color = ; gpios = <&GPIO0 10 GPIO_ACTIVE_HIGH>; }; }; diff --git a/target/linux/apm821xx/dts/netgear-wndap660.dts b/target/linux/apm821xx/dts/netgear-wndap660.dts index e9f45abe0e..f01d1b3be0 100644 --- a/target/linux/apm821xx/dts/netgear-wndap660.dts +++ b/target/linux/apm821xx/dts/netgear-wndap660.dts @@ -10,23 +10,31 @@ }; &LEDS { - lan1-link1000 { - label = "wndap660:green:lan1-link1000"; + led-5 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; gpios = <&GPIO0 22 GPIO_ACTIVE_HIGH>; }; - lan1-link100 { - label = "wndap660:amber:lan1-link100"; + led-6 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <0>; gpios = <&GPIO0 23 GPIO_ACTIVE_HIGH>; }; - lan2-link1000 { - label = "wndap660:green:lan2-link1000"; + led-7 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <2>; gpios = <&GPIO0 9 GPIO_ACTIVE_HIGH>; }; - lan2-link100 { - label = "wndap660:amber:lan2-link100"; + led-8 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; gpios = <&GPIO0 10 GPIO_ACTIVE_HIGH>; }; }; diff --git a/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi b/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi index 88284d0237..910817e5ed 100644 --- a/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi +++ b/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi @@ -3,15 +3,12 @@ * Device Tree Source for Netgear WNDAP620 and WNDAP660 */ +#include #include "apm82181.dtsi" / { aliases { serial0 = &UART0; - led-boot = &status; - led-failsafe = &failsafe; - led-running = &status; - led-upgrade = &status; }; chosen { @@ -137,29 +134,37 @@ LEDS: leds { compatible = "gpio-leds"; - status: power { - label = "wndap6x0:green:power"; + led-0 { + color = ; + function = LED_FUNCTION_POWER; gpios = <&GPIO0 18 GPIO_ACTIVE_HIGH>; }; - failsafe: test { - label = "wndap6x0:amber:test"; + led-1 { + color = ; + function = LED_FUNCTION_FAULT; gpios = <&GPIO0 17 GPIO_ACTIVE_HIGH>; panic-indicator; }; - activity { - label = "wndap6x0:green:activity"; + led-2 { + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <0>; gpios = <&GPIO0 21 GPIO_ACTIVE_HIGH>; }; - wlan2g { - label = "wndap6x0:green:wlan2g"; + led-3 { + color = ; + function = LED_FUNCTION_WLAN; + function-enumerator = <0>; gpios = <&GPIO0 19 GPIO_ACTIVE_HIGH>; }; - wlan5g { - label = "wndap6x0:green:wlan5g"; + led-4 { + color = ; + function = LED_FUNCTION_WLAN; + function-enumerator = <1>; gpios = <&GPIO0 20 GPIO_ACTIVE_HIGH>; }; }; @@ -216,4 +221,3 @@ read-only; }; }; - diff --git a/target/linux/apm821xx/dts/netgear-wndr4700.dts b/target/linux/apm821xx/dts/netgear-wndr4700.dts index ad23e8b441..286eba203b 100644 --- a/target/linux/apm821xx/dts/netgear-wndr4700.dts +++ b/target/linux/apm821xx/dts/netgear-wndr4700.dts @@ -7,8 +7,9 @@ /dts-v1/; -#include "apm82181.dtsi" #include +#include +#include "apm82181.dtsi" / { model = "Netgear WNDR4700/WNDR4720 Series"; @@ -16,10 +17,6 @@ aliases { serial0 = &UART0; - led-boot = &status; - led-failsafe = &failsafe; - led-running = &status; - led-upgrade = &status; }; chosen { @@ -367,53 +364,63 @@ leds { compatible = "gpio-leds"; - status: power-green { - label = "wndr4700:green:power"; + + led-0 { + color = ; + function = LED_FUNCTION_POWER; gpios = <&GPIO0 8 GPIO_ACTIVE_HIGH>; }; - failsafe: power-orange { - label = "wndr4700:orange:power"; + led-1 { + color = ; + function = LED_FUNCTION_FAULT; gpios = <&GPIO0 9 GPIO_ACTIVE_LOW>; - linux,default-trigger = "panic"; + panic-indicator; }; - usb-blue { - label = "wndr4700:blue:usb"; + led-2 { + color = ; + function = LED_FUNCTION_USB; gpios = <&GPIO0 10 GPIO_ACTIVE_HIGH>; trigger-sources = <&usb2_port 1>, <&usb2_port 2>, <&usb3_port 1>, <&usb3_port 2>; linux,default-trigger = "usbport"; }; - logo-white { - label = "wndr4700:white:logo"; + led-3 { + color = ; + function = LED_FUNCTION_INDICATOR; gpios = <&GPIO0 11 GPIO_ACTIVE_HIGH>; }; - wan-yellow { - label = "wndr4700:yellow:wan"; + led-4 { + color = ; + function = LED_FUNCTION_WAN; gpios = <&GPIO0 3 GPIO_ACTIVE_HIGH>; }; - wan-green { - label = "wndr4700:green:wan"; + led-5 { + color = ; + function = LED_FUNCTION_WAN; gpios = <&GPIO0 12 GPIO_ACTIVE_HIGH>; }; - hd-green { - label = "wndr4700:green:hd"; + led-6 { + color = ; + function = LED_FUNCTION_DISK; gpios = <&GPIO0 14 GPIO_ACTIVE_HIGH>; linux,default-trigger = "disk-activity"; }; - hd-red { - label = "wndr4700:red:hd"; + led-7 { + color = ; + function = LED_FUNCTION_DISK_ERR; gpios = <&GPIO0 17 GPIO_ACTIVE_HIGH>; }; - wlan-blue { - label = "wndr4700:blue:wlan"; + led-8 { + color = ; + function = LED_FUNCTION_WLAN; gpios = <&GPIO0 18 GPIO_ACTIVE_HIGH>; linux,default-trigger = "phy0tpt"; }; diff --git a/target/linux/apm821xx/dts/wd-mybooklive.dts b/target/linux/apm821xx/dts/wd-mybooklive.dts index bccf82fbaa..c96e7f75e9 100644 --- a/target/linux/apm821xx/dts/wd-mybooklive.dts +++ b/target/linux/apm821xx/dts/wd-mybooklive.dts @@ -6,6 +6,7 @@ /dts-v1/; +#include #include "apm82181.dtsi" / { @@ -14,10 +15,6 @@ aliases { serial0 = &UART0; - led-boot = &status; - led-failsafe = &status; - led-running = &status; - led-upgrade = &status; }; }; @@ -86,19 +83,26 @@ leds { compatible = "gpio-leds"; - failsafe: power-red { - label = "mbl:red:power"; + /* There's just one tri-color LED with three separate pins. + * One pin for each color (red, green and blue). Each has + * a different meaning. + */ + led-0 { + color = ; + function = LED_FUNCTION_FAULT; gpios = <&GPIO1 4 GPIO_ACTIVE_HIGH>; - linux,default-trigger = "panic"; + panic-indicator; }; - status: power-green { - label = "mbl:green:power"; + led-1 { + color = ; + function = LED_FUNCTION_POWER; gpios = <&GPIO1 5 GPIO_ACTIVE_HIGH>; }; - power-blue { - label = "mbl:blue:power"; + led-2 { + color = ; + function = LED_FUNCTION_DISK; gpios = <&GPIO1 6 GPIO_ACTIVE_HIGH>; linux,default-trigger = "disk-activity"; }; -- cgit v1.2.3