From c71838faa1dc9ade9918abbc61b587ff35880a53 Mon Sep 17 00:00:00 2001
From: Gabor Juhos <juhosg@openwrt.org>
Date: Tue, 29 May 2012 16:39:03 +0000
Subject: [PATCH] ramips: WAN LED for D-Link DIR-300-B1

Add led devices for D-Link DIR-300-B1 WAN LED.

Note that the GPIO state is also ANDed with the esw switch port 4
LED state, which is why I've set the amber LED to default-on.

Closes: https://dev.openwrt.org/ticket/11326

Signed-off-by: Tobias Diedrich <ranma+openwrt@tdiedrich.de>

[ juhosg:
- fix comment style in mach-dir-300-revb.c,
- remove the PPP specific LED setup, not everyone uses a PPP connection
  on the WAN interface]

SVN-Revision: 31989
---
 .../ramips/base-files/etc/uci-defaults/leds   | 24 +++++++++++++++++++
 .../mips/ralink/rt305x/mach-dir-300-revb.c    | 14 +++++++++++
 2 files changed, 38 insertions(+)

diff --git a/target/linux/ramips/base-files/etc/uci-defaults/leds b/target/linux/ramips/base-files/etc/uci-defaults/leds
index ba6ea60cde..f87a64faef 100755
--- a/target/linux/ramips/base-files/etc/uci-defaults/leds
+++ b/target/linux/ramips/base-files/etc/uci-defaults/leds
@@ -30,6 +30,24 @@ commit system
 EOF
 }
 
+set_wan_led() {
+	local sysfs="$1"
+	local name="$2"
+	local trigger="$3"
+	local dev="$4"
+	local mode="$5"
+
+	uci batch <<EOF
+set system.${name}_led=led
+set system.${name}_led.name='$name'
+set system.${name}_led.sysfs='$sysfs'
+set system.${name}_led.trigger='$trigger'
+set system.${name}_led.dev='$dev'
+set system.${name}_led.mode='$mode'
+commit system
+EOF
+}
+
 board=$(ramips_board_name)
 
 case $board in
@@ -39,6 +57,12 @@ case $board in
 	bc2)
 		set_usb_led "bc2:blue:usb"
 		;;
+	dir-300-b1|\
+	dir-600-b1|\
+	dir-600-b2)
+		# ANDed with vlan switch port 4 led state
+		set_wan_led "d-link:amber:wan" wan_switch default-on
+		;;
 	esr-9753)
 		set_wifi_led "rt2800pci-phy0::radio"
 		;;
diff --git a/target/linux/ramips/files/arch/mips/ralink/rt305x/mach-dir-300-revb.c b/target/linux/ramips/files/arch/mips/ralink/rt305x/mach-dir-300-revb.c
index 3581972860..e4c5c73da1 100644
--- a/target/linux/ramips/files/arch/mips/ralink/rt305x/mach-dir-300-revb.c
+++ b/target/linux/ramips/files/arch/mips/ralink/rt305x/mach-dir-300-revb.c
@@ -22,6 +22,12 @@
 #define DIR_300B_GPIO_LED_STATUS_AMBER	8
 #define DIR_300B_GPIO_LED_STATUS_GREEN	9
 #define DIR_300B_GPIO_LED_WPS		13
+/*
+ * NOTE: The wan led is also connected to the switch, both
+ * switch and gpio must be active to make it light up
+ */
+#define DIR_300B_GPIO_LED_WAN_GREEN	12
+#define DIR_300B_GPIO_LED_WAN_AMBER	14
 
 #define DIR_300B_GPIO_BUTTON_WPS	0	/* active low */
 #define DIR_300B_GPIO_BUTTON_RESET	10	/* active low */
@@ -38,6 +44,14 @@ static struct gpio_led dir_300b_leds_gpio[] __initdata = {
 		.name		= "d-link:green:status",
 		.gpio		= DIR_300B_GPIO_LED_STATUS_GREEN,
 		.active_low	= 1,
+	}, {
+		.name		= "d-link:amber:wan",
+		.gpio		= DIR_300B_GPIO_LED_WAN_AMBER,
+		.active_low	= 1,
+	}, {
+		.name		= "d-link:green:wan",
+		.gpio		= DIR_300B_GPIO_LED_WAN_GREEN,
+		.active_low	= 1,
 	}, {
 		.name		= "d-link:blue:wps",
 		.gpio		= DIR_300B_GPIO_LED_WPS,
-- 
GitLab