From c4d8fe136c7c603768a6c81d7f72531b8da0a992 Mon Sep 17 00:00:00 2001
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Wed, 26 Sep 2012 22:10:35 +0200
Subject: [PATCH 2/2] [ar71xx] add support for the Linksys WAP4410N

---
 target/linux/ar71xx/base-files/etc/diag.sh         |   3 +
 .../linux/ar71xx/base-files/etc/uci-defaults/leds  |   4 +
 target/linux/ar71xx/base-files/lib/ar71xx.sh       |   3 +
 target/linux/ar71xx/config-3.3                     |   3 +-
 .../ar71xx/files/arch/mips/ath79/mach-wap4410n.c   | 141 +++++++++++++++++++++
 target/linux/ar71xx/generic/profiles/linksys.mk    |  10 ++
 target/linux/ar71xx/image/Makefile                 |   8 ++
 .../610-MIPS-ath79-openwrt-machines.patch          |  25 +++-
 .../611-MIPS-ath79-TL-MR3040-support.patch         |   2 +-
 9 files changed, 190 insertions(+), 9 deletions(-)
 create mode 100644 target/linux/ar71xx/files/arch/mips/ath79/mach-wap4410n.c

diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh
index 420d690..477e129 100755
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -163,6 +163,9 @@ get_status_led() {
 	wp543)
 		status_led="wp543:green:diag"
 		;;
+	wap4410n)
+		status_led="wap4410n:green:power"
+		;;
 	wrt400n)
 		status_led="wrt400n:blue:wps"
 		;;
diff --git a/target/linux/ar71xx/base-files/etc/uci-defaults/leds b/target/linux/ar71xx/base-files/etc/uci-defaults/leds
index e776fbf..16b13fc 100755
--- a/target/linux/ar71xx/base-files/etc/uci-defaults/leds
+++ b/target/linux/ar71xx/base-files/etc/uci-defaults/leds
@@ -150,6 +150,10 @@ tl-wr2543n)
 	ucidef_set_led_usbdev "usb" "USB" "tp-link:green:usb" "1-1"
 	;;
 
+wap4410n)
+	set_led_wlan "wlan" "WLAN" "wap4410n:green:wlan" "phy0tpt"
+	;;
+
 wrt160nl)
 	ucidef_set_led_wlan "wlan" "WLAN" "wrt160nl:blue:wlan" "phy0tpt"
 	;;
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 3ba23b7..2974a8d 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -390,6 +390,9 @@ ar71xx_board_detect() {
 	*WNR2000)
 		name="wnr2000"
 		;;
+	*WAP4410N)
+		name="wap4410n"
+		;;
 	*WRT160NL)
 		name="wrt160nl"
 		;;
diff --git a/target/linux/ar71xx/config-3.3 b/target/linux/ar71xx/config-3.3
index db53c2b..56f1598 100644
--- a/target/linux/ar71xx/config-3.3
+++ b/target/linux/ar71xx/config-3.3
@@ -69,6 +69,7 @@ CONFIG_ATH79_MACH_TL_WR841N_V1=y
 CONFIG_ATH79_MACH_TL_WR941ND=y
 CONFIG_ATH79_MACH_UBNT=y
 CONFIG_ATH79_MACH_UBNT_XM=y
+CONFIG_ATH79_MACH_WAP4410N=y
 CONFIG_ATH79_MACH_WHR_HP_G300N=y
 CONFIG_ATH79_MACH_WLAE_AG300N=y
 CONFIG_ATH79_MACH_WNDR3700=y
@@ -90,7 +91,7 @@ CONFIG_BCMA_POSSIBLE=y
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_CEVT_R4K=y
 CONFIG_CEVT_R4K_LIB=y
-CONFIG_CMDLINE="rootfstype=squashfs,yaffs,jffs2 noinitrd"
+CONFIG_CMDLINE="rootfstype=squashfs,yaffs,jffs2 noinitrd board=WAP4410N"
 CONFIG_CMDLINE_BOOL=y
 # CONFIG_CMDLINE_OVERRIDE is not set
 CONFIG_CPU_BIG_ENDIAN=y
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-wap4410n.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-wap4410n.c
new file mode 100644
index 0000000..ba91138
--- /dev/null
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-wap4410n.c
@@ -0,0 +1,141 @@
+/*
+ *  Linksys WAP4410N board support
+ *
+ *  Copyright (C) 2012 Florian Fainelli <florian@openwrt.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+
+#include <asm/mach-ath79/ar71xx_regs.h>
+#include <asm/mach-ath79/ath79.h>
+
+#include "dev-eth.h"
+#include "dev-gpio-buttons.h"
+#include "dev-leds-gpio.h"
+#include "dev-wmac.h"
+#include "machtypes.h"
+
+#define WAP4410N_GPIO_LED_WLAN		0	/* active low */
+#define WAP4410N_GPIO_LED_POWER		1	/* active high */
+
+#define WAP4410N_GPIO_BTN_RESET		21	/* active low */
+
+#define WAP4410N_KEYS_POLL_INTERVAL	20	/* msecs */
+#define WAP4410N_KEYS_DEBOUNE_INTERVAL	(3 * WAP4410N_KEYS_POLL_INTERVAL)
+
+#define WAP4410N_SERCOMM_OFFSET		0x3ff70
+#define WAP4410N_MAC0_OFFSET		0x30
+
+static struct mtd_partition wap4410n_partitions[] = {
+	{
+		.name		= "uboot",
+		.offset		= 0,
+		.size		= 0x040000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "env",
+		.offset		= 0x040000,
+		.size		= 0x010000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "rootfs",
+		.offset		= 0x050000,
+		.size		= 0x650000,
+	}, {
+		.name		= "linux",
+		.offset		= 0x6a0000,
+		.size		= 0x140000,
+	}, {
+		.name		= "nvram",
+		.offset		= 0x7e0000,
+		.size		= 0x010000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "caldata",
+		.offset		= 0x7f0000,
+		.size		= 0x010000,
+		.mask_flags	= MTD_WRITEABLE,
+	},
+};
+
+static struct physmap_flash_data wap4410n_flash_data = {
+	.width		= 2,
+	.parts		= wap4410n_partitions,
+	.nr_parts	= ARRAY_SIZE(wap4410n_partitions),
+};
+
+static struct resource wap4410n_flash_resources[] = {
+	[0] = {
+		.start	= AR71XX_SPI_BASE,
+		.end	= AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct platform_device wap4410n_flash_device = {
+	.name		= "physmap-flash",
+	.id		= -1,
+	.resource	= wap4410n_flash_resources,
+	.num_resources	= ARRAY_SIZE(wap4410n_flash_resources),
+	.dev		= {
+		.platform_data = &wap4410n_flash_data,
+	},
+};
+
+static struct gpio_led wap4410n_leds_gpio[] __initdata = {
+	{
+		.name		= "wap4410n:green:wlan",
+		.gpio		= WAP4410N_GPIO_LED_WLAN,
+		.active_low	= 1,
+	}, {
+		.name		= "wap4410n:green:power",
+		.gpio		= WAP4410N_GPIO_LED_POWER,
+		.active_low	= 1,
+		.default_trigger = "default-on",
+	}
+};
+
+static struct gpio_keys_button wap4410n_gpio_keys[] __initdata = {
+	{
+		.desc		= "reset",
+		.type		= EV_KEY,
+		.code		= KEY_RESTART,
+		.debounce_interval = WAP4410N_KEYS_DEBOUNE_INTERVAL,
+		.gpio		= WAP4410N_GPIO_BTN_RESET,
+		.active_low	= 1,
+	}
+};
+
+static void __init wap4410n_setup(void)
+{
+	u8 *eeprom = (u8 *)KSEG1ADDR(0x1fff1000);
+	u8 *mac = (u8 *)KSEG1ADDR(0x1f000000 + WAP4410N_SERCOMM_OFFSET +
+				WAP4410N_MAC0_OFFSET);
+
+	ath79_register_mdio(0, 0x0);
+
+	ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
+	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
+	ath79_eth0_data.phy_mask = 0x1;
+
+	ath79_register_eth(0);
+
+	ath79_register_leds_gpio(-1, ARRAY_SIZE(wap4410n_leds_gpio),
+				 wap4410n_leds_gpio);
+
+	ath79_register_gpio_keys_polled(-1, WAP4410N_KEYS_POLL_INTERVAL,
+					ARRAY_SIZE(wap4410n_gpio_keys),
+					wap4410n_gpio_keys);
+
+	ath79_register_wmac(eeprom, NULL);
+
+	platform_device_register(&wap4410n_flash_device);
+}
+
+MIPS_MACHINE(ATH79_MACH_WAP4410N, "WAP4410N", "Linksys WAP4410N", wap4410n_setup);
diff --git a/target/linux/ar71xx/generic/profiles/linksys.mk b/target/linux/ar71xx/generic/profiles/linksys.mk
index bedf3a3..a4426a7 100644
--- a/target/linux/ar71xx/generic/profiles/linksys.mk
+++ b/target/linux/ar71xx/generic/profiles/linksys.mk
@@ -5,6 +5,15 @@
 # See /LICENSE for more information.
 #
 
+define Profile/WAP4410N
+	NAME:=Linksys WAP4410N
+	PACKAGES:=
+endef
+
+define Profile/WAP4410N/Description
+	Package set optimized for the Linksys WAP4410N.
+endef
+
 define Profile/WRT160NL
 	NAME:=Linksys WRT160NL
 	PACKAGES:=kmod-usb-core kmod-usb2
@@ -23,5 +32,6 @@ define Profile/WRT400N/Description
 	Package set optimized for the Linksys WRT400N.
 endef
 
+$(eval $(call Profile,WAP4410N))
 $(eval $(call Profile,WRT160NL))
 $(eval $(call Profile,WRT400N))
diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile
index f93e195..207ed3c 100644
--- a/target/linux/ar71xx/image/Makefile
+++ b/target/linux/ar71xx/image/Makefile
@@ -192,6 +192,13 @@ define Image/BuildKernel
 	$(call Image/Build/Initramfs)
 endef
 
+define Image/Build/WAP4410N
+	$(call MkuImageGzip,$(2),$(3))
+	if [ -e "$(call sysupname,$(1),$(2))" ]; then \
+		wap4410n -u auto -v 1007 -k $(KDIR_TMP)/vmlinux-$(2).uImage -r $(KDIR)/root.$(1) -o $(call factoryname,$(1),$(2)); \
+	fi
+endef
+
 define Image/Build/WRT400N
 	$(call MkuImageLzma,$(2),$(3))
 	$(call Sysupgrade/KRuImage,$(1),$(2),1310720,6488064)
@@ -843,6 +850,7 @@ $(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WHRHPG300N,whr-hp-g300n,WHR-HP-
 $(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WHRHPGN,whr-hp-gn,WHR-HP-GN,ttyS0,115200,$$(whrhpg300n_mtdlayout),WHR-HP-GN))
 $(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WLAEAG300N,wlae-ag300n,WLAE-AG300N,ttyS0,115200,$$(whrhpg300n_mtdlayout),WLAE-AG300N))
 
+$(eval $(call SingleProfile,WAP4410N,$(fs_64k),WAP4410N,wap4410n,WAP4410N,ttyS0,115200))
 $(eval $(call SingleProfile,WRT400N,$(fs_64k),WRT400N,wrt400n,WRT400N,ttyS0,115200))
 
 $(eval $(call SingleProfile,WZRHPG30XNH,$(fs_128k),WZRHPG300NH,wzr-hp-g300nh,WZR-HP-G300NH,ttyS0,115200,WZR-HP-G300NH))
diff --git a/target/linux/ar71xx/patches-3.3/610-MIPS-ath79-openwrt-machines.patch b/target/linux/ar71xx/patches-3.3/610-MIPS-ath79-openwrt-machines.patch
index 6f6da2d..5b71091 100644
--- a/target/linux/ar71xx/patches-3.3/610-MIPS-ath79-openwrt-machines.patch
+++ b/target/linux/ar71xx/patches-3.3/610-MIPS-ath79-openwrt-machines.patch
@@ -1,6 +1,6 @@
 --- a/arch/mips/ath79/machtypes.h
 +++ b/arch/mips/ath79/machtypes.h
-@@ -16,18 +16,98 @@
+@@ -16,18 +16,99 @@
  
  enum ath79_mach_type {
  	ATH79_MACH_GENERIC = 0,
@@ -81,6 +81,7 @@
 +	ATH79_MACH_UBNT_RS,		/* Ubiquiti RouterStation */
  	ATH79_MACH_UBNT_UNIFI, 		/* Ubiquiti Unifi */
  	ATH79_MACH_UBNT_XM,		/* Ubiquiti Networks XM board rev 1.0 */
++	ATH79_MACH_WAP4410N,		/* Linksys WAP4410N */
 +	ATH79_MACH_WHR_G301N,		/* Buffalo WHR-G301N */
 +	ATH79_MACH_WHR_HP_G300N,	/* Buffalo WHR-HP-G300N */
 +	ATH79_MACH_WHR_HP_GN,		/* Buffalo WHR-HP-GN */
@@ -202,7 +203,7 @@
  config ATH79_MACH_PB44
  	bool "Atheros PB44 reference board"
  	select SOC_AR71XX
-@@ -67,6 +147,447 @@ config ATH79_MACH_PB44
+@@ -67,6 +147,456 @@ config ATH79_MACH_PB44
  	  Say 'Y' here if you want your kernel to support the
  	  Atheros PB44 reference board.
  
@@ -358,6 +359,15 @@
 +	select ATH79_DEV_M25P80
 +	select ATH79_DEV_USB
 +
++config ATH79_MACH_WAP4410N
++	bool "Linksys WAP4410N board support"
++	select SOC_AR913X
++	select ATH79_DEV_ETH
++	select ATH79_DEV_GPIO_BUTTONS
++	select ATH79_DEV_LEDS_GPIO
++	select ATH79_DEV_WMAC
++	select ATH79_NVRAM
++
 +config ATH79_MACH_WRT160NL
 +	bool "Linksys WRT160NL board support"
 +	select SOC_AR913X
@@ -650,7 +660,7 @@
  config ATH79_MACH_UBNT_XM
  	bool "Ubiquiti Networks XM (rev 1.0) board"
  	select SOC_AR724X
-@@ -80,6 +601,24 @@ config ATH79_MACH_UBNT_XM
+@@ -80,6 +610,24 @@ config ATH79_MACH_UBNT_XM
  	  Say 'Y' here if you want your kernel to support the
  	  Ubiquiti Networks XM (rev 1.0) board.
  
@@ -675,7 +685,7 @@
  endmenu
  
  config SOC_AR71XX
-@@ -115,10 +654,6 @@ config SOC_QCA955X
+@@ -115,10 +663,6 @@ config SOC_QCA955X
  	select PCI_AR724X if PCI
  	def_bool n
  
@@ -686,7 +696,7 @@
  config ATH79_DEV_AP9X_PCI
  	select ATH79_PCI_ATH9K_FIXUP
  	def_bool n
-@@ -129,7 +664,14 @@ config ATH79_DEV_DSA
+@@ -129,7 +673,14 @@ config ATH79_DEV_DSA
  config ATH79_DEV_ETH
  	def_bool n
  
@@ -702,7 +712,7 @@
  	def_bool n
  
  config ATH79_DEV_GPIO_BUTTONS
-@@ -161,4 +703,7 @@ config ATH79_PCI_ATH9K_FIXUP
+@@ -161,4 +712,7 @@ config ATH79_PCI_ATH9K_FIXUP
  config ATH79_ROUTERBOOT
  	def_bool n
  
@@ -712,7 +722,7 @@
  endif
 --- a/arch/mips/ath79/Makefile
 +++ b/arch/mips/ath79/Makefile
-@@ -38,9 +38,65 @@ obj-$(CONFIG_ATH79_ROUTERBOOT)		+= route
+@@ -38,9 +38,66 @@ obj-$(CONFIG_ATH79_ROUTERBOOT)		+= route
  #
  # Machines
  #
@@ -766,6 +776,7 @@
 +obj-$(CONFIG_ATH79_MACH_TL_WR703N)	+= mach-tl-wr703n.o
 +obj-$(CONFIG_ATH79_MACH_UBNT)		+= mach-ubnt.o
  obj-$(CONFIG_ATH79_MACH_UBNT_XM)	+= mach-ubnt-xm.o
++obj-$(CONFIG_ATH79_MACH_WAP4410N)	+= mach-wap4410n.o
 +obj-$(CONFIG_ATH79_MACH_WHR_HP_G300N)	+= mach-whr-hp-g300n.o
 +obj-$(CONFIG_ATH79_MACH_WLAE_AG300N)	+= mach-wlae-ag300n.o
 +obj-$(CONFIG_ATH79_MACH_WNDR3700)	+= mach-wndr3700.o
diff --git a/target/linux/ar71xx/patches-3.3/611-MIPS-ath79-TL-MR3040-support.patch b/target/linux/ar71xx/patches-3.3/611-MIPS-ath79-TL-MR3040-support.patch
index 4e6d491..d8db56e 100644
--- a/target/linux/ar71xx/patches-3.3/611-MIPS-ath79-TL-MR3040-support.patch
+++ b/target/linux/ar71xx/patches-3.3/611-MIPS-ath79-TL-MR3040-support.patch
@@ -1,6 +1,6 @@
 --- a/arch/mips/ath79/Kconfig
 +++ b/arch/mips/ath79/Kconfig
-@@ -412,7 +412,7 @@ config ATH79_MACH_EAP7660D
+@@ -421,7 +421,7 @@ config ATH79_MACH_EAP7660D
  	select ATH79_DEV_M25P80
  
  config ATH79_MACH_TL_MR11U
-- 
1.8.1.2

