2 * Buffalo WZR-HP-AG300H board support
4 * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/mtd/concat.h>
16 #include <asm/mips_machine.h>
17 #include <asm/mach-ar71xx/ar71xx.h>
21 #include "dev-ap94-pci.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-m25p80.h"
27 #define WZRHPAG300H_MAC_OFFSET 0x20c
28 #define WZRHPAG300H_KEYS_POLL_INTERVAL 20 /* msecs */
29 #define WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPAG300H_KEYS_POLL_INTERVAL)
31 #ifdef CONFIG_MTD_CONCAT
33 #ifdef CONFIG_MTD_PARTITIONS
34 static struct mtd_partition wzrhpag300h_flash_partitions[] = {
39 .mask_flags = MTD_WRITEABLE,
44 .mask_flags = MTD_WRITEABLE,
49 .mask_flags = MTD_WRITEABLE,
59 .name = "user_property",
62 .mask_flags = MTD_WRITEABLE,
70 #endif /* CONFIG_MTD_PARTITIONS */
72 static struct mtd_info *concat_devs[2] = { NULL, NULL };
73 static struct work_struct mtd_concat_work;
75 static void mtd_concat_add_work(struct work_struct *work)
79 mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash");
81 #ifdef CONFIG_MTD_PARTITIONS
82 add_mtd_partitions(mtd, wzrhpag300h_flash_partitions,
83 ARRAY_SIZE(wzrhpag300h_flash_partitions));
89 static void mtd_concat_add(struct mtd_info *mtd)
91 static bool registered = false;
96 if (!strcmp(mtd->name, "spi0.0"))
98 else if (!strcmp(mtd->name, "spi0.1"))
103 if (!concat_devs[0] || !concat_devs[1])
107 INIT_WORK(&mtd_concat_work, mtd_concat_add_work);
108 schedule_work(&mtd_concat_work);
111 static void mtd_concat_remove(struct mtd_info *mtd)
115 static void add_mtd_concat_notifier(void)
117 static struct mtd_notifier not = {
118 .add = mtd_concat_add,
119 .remove = mtd_concat_remove,
122 register_mtd_user(¬);
127 static struct gpio_led wzrhpag300h_leds_gpio[] __initdata = {
129 .name = "wzr-hp-ag300h:red:diag",
136 static struct gpio_keys_button wzrhpag300h_gpio_keys[] __initdata = {
141 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
148 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
154 .code = KEY_WPS_BUTTON,
155 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
159 .desc = "router_auto",
162 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
166 .desc = "router_off",
169 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
175 static struct spi_board_info ar71xx_spi_info[] = {
179 .max_speed_hz = 25000000,
180 .modalias = "m25p80",
185 .max_speed_hz = 25000000,
186 .modalias = "m25p80",
190 static void __init wzrhpag300h_setup(void)
192 u8 *eeprom = (u8 *) KSEG1ADDR(0x1f051000);
193 u8 *mac = eeprom + WZRHPAG300H_MAC_OFFSET;
195 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
196 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
198 ar71xx_add_device_mdio(~(BIT(0) | BIT(4)));
200 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
201 ar71xx_eth0_data.speed = SPEED_1000;
202 ar71xx_eth0_data.duplex = DUPLEX_FULL;
203 ar71xx_eth0_data.phy_mask = BIT(0);
205 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
206 ar71xx_eth1_data.phy_mask = BIT(4);
208 ar71xx_add_device_eth(0);
209 ar71xx_add_device_eth(1);
211 ar71xx_add_device_usb();
213 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpag300h_leds_gpio),
214 wzrhpag300h_leds_gpio);
216 ar71xx_register_gpio_keys_polled(-1, WZRHPAG300H_KEYS_POLL_INTERVAL,
217 ARRAY_SIZE(wzrhpag300h_gpio_keys),
218 wzrhpag300h_gpio_keys);
220 ar71xx_add_device_spi(NULL, ar71xx_spi_info,
221 ARRAY_SIZE(ar71xx_spi_info));
223 #ifdef CONFIG_MTD_CONCAT
224 add_mtd_concat_notifier();
227 ap94_pci_init(eeprom, mac, NULL, NULL);
230 MIPS_MACHINE(AR71XX_MACH_WZR_HP_AG300H, "WZR-HP-AG300H",
231 "Buffalo WZR-HP-AG300H", wzrhpag300h_setup);