On 08/16/2011 02:28 PM, Felix Fietkau wrote:
On 2011-08-16 11:51 AM, Mark Deneen wrote:

Please let me know if there is anything which I have overlooked.
Looks mostly fine to me on a first quick look (aside from some whitespace vs tab
issues).
Before we accept this, I want to split out the mtd concat code from
WZR-HP-AG300H, so that the mach file for this device can share it without adding
more unnecessary code duplication.

I have an immediate need to support v1 and v2 hardware in one image.  As
"products" they are essentially identical, as well as in user space in Linux,
and deploying a image which is all but identical to support 2 machines makes
no sense to me.

This needs more work and is only for review, however the attached patch
essentially removes the 300NH2 as its own machine type in the kernel and most
of OpenWrt.  The one exception here is that the network configuration is a bit
different, so we need to detect the different SoC and use as appropriate.
That's the bit I haven't done yet, since I won't have an actual v2 until
tomorrow.

This *doesn't* include kernel .config changes, since mine has a bunch
of unrelated options turned on.  The previous patch of that should be
correct.

This simply merges the machine support between the 300NH and 300NH2, so I can't
take any credit except for cut and paste ;-)

Index: target/linux/ar71xx/files/arch/mips/ar71xx/Kconfig
===================================================================
--- target/linux/ar71xx/files/arch/mips/ar71xx/Kconfig	(revision 28123)
+++ target/linux/ar71xx/files/arch/mips/ar71xx/Kconfig	(working copy)
@@ -145,12 +145,15 @@
 	default y
 
 config AR71XX_MACH_WZR_HP_G300NH
-	bool "Buffalo WZR-HP-G300NH board support"
+	bool "Buffalo WZR-HP-G300NH, G301NH and G300NH2 board support"
 	select SOC_AR913X
+	select SOC_AR724X
 	select AR71XX_DEV_AR9XXX_WMAC
 	select AR71XX_DEV_GPIO_BUTTONS
 	select AR71XX_DEV_LEDS_GPIO
 	select AR71XX_DEV_USB
+	select AR71XX_DEV_M25P80
+	select AR71XX_DEV_AP91_PCI if PCI
 	select RTL8366_SMI
 	default y
 
Index: target/linux/ar71xx/files/arch/mips/ar71xx/mach-wzr-hp-g300nh.c
===================================================================
--- target/linux/ar71xx/files/arch/mips/ar71xx/mach-wzr-hp-g300nh.c	(revision 28123)
+++ target/linux/ar71xx/files/arch/mips/ar71xx/mach-wzr-hp-g300nh.c	(working copy)
@@ -2,6 +2,8 @@
  *  Buffalo WZR-HP-G300NH board support
  *
  *  Copyright (C) 2010 Gabor Juhos <juh...@openwrt.org>
+ *  Copyright (C) 2011 Felix Fietkau <n...@openwrt.org>
+ *  Copyright (C) 2011 Mark Deneen <mden...@gmail.com>
  *
  *  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
@@ -11,8 +13,11 @@
 #include <linux/platform_device.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
+#include <linux/mtd/concat.h>
+
 #include <linux/nxp_74hc153.h>
 #include <linux/rtl8366.h>
+#include <asm/mach-ar71xx/gpio.h>
 
 #include <asm/mips_machine.h>
 #include <asm/mach-ar71xx/ar71xx.h>
@@ -24,6 +29,8 @@
 #include "dev-gpio-buttons.h"
 #include "dev-leds-gpio.h"
 #include "dev-usb.h"
+#include "dev-ap91-pci.h"
+#include "dev-m25p80.h"
 
 #define WZRHPG300NH_GPIO_LED_USB	0
 #define WZRHPG300NH_GPIO_LED_DIAG	1
@@ -53,6 +60,12 @@
 
 #define WZRHPG300NH_MAC_OFFSET		0x20c
 
+
+#define WZRHPG300NH2_MAC_OFFSET		0x20c
+#define WZRHPG300NH2_KEYS_POLL_INTERVAL     20      /* msecs */
+#define WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH2_KEYS_POLL_INTERVAL)
+
+
 #ifdef CONFIG_MTD_PARTITIONS
 static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
 	{
@@ -89,6 +102,44 @@
 		.size		= 0x1f60000,
 	}
 };
+
+
+static struct mtd_partition wzrhpg300nh2_flash_partitions[] = {
+	{
+		.name		= "u-boot",
+		.offset		= 0,
+		.size		= 0x0040000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "u-boot-env",
+		.offset		= 0x0040000,
+		.size		= 0x0010000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "art",
+		.offset		= 0x0050000,
+		.size		= 0x0010000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "kernel",
+		.offset		= 0x0060000,
+		.size		= 0x0100000,
+	}, {
+		.name		= "rootfs",
+		.offset		= 0x0160000,
+		.size		= 0x1e90000,
+	}, {
+		.name		= "user_property",
+		.offset		= 0x1ff0000,
+		.size		= 0x0010000,
+		.mask_flags	= MTD_WRITEABLE,
+	}, {
+		.name		= "firmware",
+		.offset		= 0x0060000,
+		.size		= 0x1f90000,
+	}
+};
+
 #endif /* CONFIG_MTD_PARTITIONS */
 
 static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
@@ -120,6 +171,75 @@
 	}
 };
 
+
+static struct mtd_info *concat_devs[2] = { NULL, NULL };
+static struct work_struct mtd_concat_work;
+
+static void mtd_concat_add_work(struct work_struct *work)
+{
+	struct mtd_info *mtd;
+
+	mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash");
+
+#ifdef CONFIG_MTD_PARTITIONS
+	add_mtd_partitions(mtd, wzrhpg300nh2_flash_partitions,
+			   ARRAY_SIZE(wzrhpg300nh2_flash_partitions));
+#else
+	add_mtd_device(mtd);
+#endif
+}
+
+static void mtd_concat_add(struct mtd_info *mtd)
+{
+	static bool registered = false;
+
+	if (registered)
+		return;
+
+	if (!strcmp(mtd->name, "spi0.0"))
+		concat_devs[0] = mtd;
+	else if (!strcmp(mtd->name, "spi0.1"))
+		concat_devs[1] = mtd;
+	else
+		return;
+
+	if (!concat_devs[0] || !concat_devs[1])
+		return;
+
+	registered = true;
+	INIT_WORK(&mtd_concat_work, mtd_concat_add_work);
+	schedule_work(&mtd_concat_work);
+}
+
+static void mtd_concat_remove(struct mtd_info *mtd)
+{
+}
+
+static void add_mtd_concat_notifier(void)
+{
+	static struct mtd_notifier not = {
+		.add = mtd_concat_add,
+		.remove = mtd_concat_remove,
+	};
+
+	register_mtd_user(&not);
+}
+
+static struct spi_board_info ar71xx_spi_info[] = {
+	{
+		.bus_num	= 0,
+		.chip_select	= 0,
+		.max_speed_hz   = 25000000,
+		.modalias   = "m25p80",
+	}, {
+		.bus_num	= 0,
+		.chip_select	= 1,
+		.max_speed_hz   = 25000000,
+		.modalias   = "m25p80",
+	}
+};
+
+
 static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
 	{
 		.name		= "wzr-hp-g300nh:orange:security",
@@ -144,6 +264,15 @@
 	}
 };
 
+/* There are more of these, but they must be accessed through ath9k */
+static struct gpio_led wzrhpg300nh2_leds_gpio[] __initdata = {
+	{
+		.name		= "wzr-hp-g300nh2:red:diag",
+		.gpio		= 16,
+		.active_low	= 1,
+	}, 
+};
+
 static struct gpio_keys_button wzrhpg300nh_gpio_keys[] __initdata = {
 	{
 		.desc		= "reset",
@@ -197,6 +326,41 @@
 	}
 };
 
+/* The AOSS button is likely also behind ath9k */
+static struct gpio_keys_button wzrhpg300nh2_gpio_keys[] __initdata = {
+	{
+		.desc		= "reset",
+		.type		= EV_KEY,
+		.code		= KEY_RESTART,
+		.debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
+		.gpio		= 1,
+		.active_low	= 1,
+	}, {
+		.desc		= "usb",
+		.type		= EV_KEY,
+		.code		= BTN_2,
+		.debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
+		.gpio		= 7,
+		.active_low	= 1,
+	}, {
+		.desc		= "qos",
+		.type		= EV_KEY,
+		.code		= BTN_3,
+		.debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
+		.gpio		= 11,
+		.active_low	= 0,
+	}, {
+		.desc		= "router_on",
+		.type		= EV_KEY,
+		.code		= BTN_5,
+		.debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
+		.gpio		= 8,
+		.active_low	= 0,
+	},
+};
+
+
+
 static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
 	.gpio_base	= WZRHPG300NH_GPIO_EXP_BASE,
 	.gpio_pin_s0	= WZRHPG300NH_GPIO_74HC153_S0,
@@ -234,12 +398,53 @@
 	}
 };
 
+
+static void __init wzrhpg300nh2_setup(void)
+{
+	u8 *eeprom = (u8 *)   KSEG1ADDR(0x1f051000);
+	u8 *mac0   = eeprom + WZRHPG300NH2_MAC_OFFSET;
+	/* There is an eth1 but it is not connected to the switch */
+
+	ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac0, 0);
+	ar71xx_add_device_mdio(~(BIT(0)));
+
+	ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac0, 0);
+	ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
+	ar71xx_eth0_data.speed = SPEED_1000;
+	ar71xx_eth0_data.duplex = DUPLEX_FULL;
+	ar71xx_eth0_data.phy_mask = BIT(0);
+
+	ar71xx_add_device_eth(0);
+	ar71xx_add_device_usb();
+	/* gpio13 is USB power.  Turn it on. */
+	gpio_request(13, "usb");
+	gpio_direction_output(13, 1);
+
+	ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh2_leds_gpio),
+                                        wzrhpg300nh2_leds_gpio);
+	ar71xx_register_gpio_keys_polled(-1, WZRHPG300NH2_KEYS_POLL_INTERVAL,
+                                         ARRAY_SIZE(wzrhpg300nh2_gpio_keys),
+                                         wzrhpg300nh2_gpio_keys);
+	ar71xx_add_device_spi(NULL, ar71xx_spi_info,
+			      ARRAY_SIZE(ar71xx_spi_info));
+
+	add_mtd_concat_notifier();
+
+	ap91_pci_init(eeprom, mac0);
+}
+
+
 static void __init wzrhpg300nh_setup(void)
 {
 	u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
 	u8 *mac = eeprom + WZRHPG300NH_MAC_OFFSET;
 	bool hasrtl8366rb = false;
 
+	if (ar71xx_soc != AR71XX_SOC_AR9132) {
+	  wzrhpg300nh2_setup();
+		return;
+	}
+	
 	ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
 	ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
 
Index: target/linux/ar71xx/generic/profiles/buffalo.mk
===================================================================
--- target/linux/ar71xx/generic/profiles/buffalo.mk	(revision 28123)
+++ target/linux/ar71xx/generic/profiles/buffalo.mk	(working copy)
@@ -7,7 +7,7 @@
 
 define Profile/WZRHPG300NH
 	NAME:=Buffalo WZR-HP-G300NH
-	PACKAGES:=kmod-ath9k wpad-mini kmod-usb-core kmod-usb2 kmod-ledtrig-usbdev
+	PACKAGES:=kmod-ath9k wpad-mini kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-ledtrig-usbdev
 endef
 
 define Profile/WZRHPG300NH/Description
 
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to