ar71xx: add support for Buffalo WZR 600DHP
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wzr-hp-ag300h.c
1 /*
2 * Buffalo WZR-HP-AG300H board support
3 *
4 * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
5 *
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.
9 */
10
11 #include <linux/gpio.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14
15 #include <asm/mach-ath79/ath79.h>
16
17 #include "dev-eth.h"
18 #include "dev-ap9x-pci.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-leds-gpio.h"
21 #include "dev-m25p80.h"
22 #include "dev-usb.h"
23 #include "machtypes.h"
24
25 #define WZRHPAG300H_MAC_OFFSET 0x20c
26 #define WZRHPAG300H_KEYS_POLL_INTERVAL 20 /* msecs */
27 #define WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPAG300H_KEYS_POLL_INTERVAL)
28
29 static struct mtd_partition wzrhpag300h_flash_partitions[] = {
30 {
31 .name = "u-boot",
32 .offset = 0,
33 .size = 0x0040000,
34 .mask_flags = MTD_WRITEABLE,
35 }, {
36 .name = "u-boot-env",
37 .offset = 0x0040000,
38 .size = 0x0010000,
39 }, {
40 .name = "art",
41 .offset = 0x0050000,
42 .size = 0x0010000,
43 .mask_flags = MTD_WRITEABLE,
44 }, {
45 .name = "kernel",
46 .offset = 0x0060000,
47 .size = 0x0100000,
48 }, {
49 .name = "rootfs",
50 .offset = 0x0160000,
51 .size = 0x1e90000,
52 }, {
53 .name = "user_property",
54 .offset = 0x1ff0000,
55 .size = 0x0010000,
56 .mask_flags = MTD_WRITEABLE,
57 }, {
58 .name = "firmware",
59 .offset = 0x0060000,
60 .size = 0x1f90000,
61 }
62 };
63
64 static struct flash_platform_data wzrhpag300h_flash_data = {
65 .parts = wzrhpag300h_flash_partitions,
66 .nr_parts = ARRAY_SIZE(wzrhpag300h_flash_partitions),
67 };
68
69 static struct gpio_led wzrhpag300h_leds_gpio[] __initdata = {
70 {
71 .name = "buffalo:red:diag",
72 .gpio = 1,
73 .active_low = 1,
74 },
75 };
76
77 static struct gpio_led wzrhpag300h_wmac0_leds_gpio[] = {
78 {
79 .name = "buffalo:amber:band2g",
80 .gpio = 1,
81 .active_low = 1,
82 },
83 {
84 .name = "buffalo:green:usb",
85 .gpio = 3,
86 .active_low = 1,
87 },
88 {
89 .name = "buffalo:green:band2g",
90 .gpio = 5,
91 .active_low = 1,
92 },
93 };
94
95 static struct gpio_led wzrhpag300h_wmac1_leds_gpio[] = {
96 {
97 .name = "buffalo:green:band5g",
98 .gpio = 1,
99 .active_low = 1,
100 },
101 {
102 .name = "buffalo:green:router",
103 .gpio = 3,
104 .active_low = 1,
105 },
106 {
107 .name = "buffalo:blue:movie_engine",
108 .gpio = 4,
109 .active_low = 1,
110 },
111 {
112 .name = "buffalo:amber:band5g",
113 .gpio = 5,
114 .active_low = 1,
115 },
116 };
117
118 static struct gpio_keys_button wzrhpag300h_gpio_keys[] __initdata = {
119 {
120 .desc = "reset",
121 .type = EV_KEY,
122 .code = KEY_RESTART,
123 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
124 .gpio = 11,
125 .active_low = 1,
126 }, {
127 .desc = "usb",
128 .type = EV_KEY,
129 .code = BTN_2,
130 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
131 .gpio = 3,
132 .active_low = 1,
133 }, {
134 .desc = "aoss",
135 .type = EV_KEY,
136 .code = KEY_WPS_BUTTON,
137 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
138 .gpio = 5,
139 .active_low = 1,
140 }, {
141 .desc = "router_auto",
142 .type = EV_KEY,
143 .code = BTN_6,
144 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
145 .gpio = 6,
146 .active_low = 1,
147 }, {
148 .desc = "router_off",
149 .type = EV_KEY,
150 .code = BTN_5,
151 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
152 .gpio = 7,
153 .active_low = 1,
154 }, {
155 .desc = "movie_engine",
156 .type = EV_KEY,
157 .code = BTN_7,
158 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
159 .gpio = 8,
160 .active_low = 1,
161 }
162 };
163
164 static void __init wzrhpag300h_setup(void)
165 {
166 u8 *eeprom1 = (u8 *) KSEG1ADDR(0x1f051000);
167 u8 *eeprom2 = (u8 *) KSEG1ADDR(0x1f055000);
168 u8 *mac1 = eeprom1 + WZRHPAG300H_MAC_OFFSET;
169 u8 *mac2 = eeprom2 + WZRHPAG300H_MAC_OFFSET;
170
171 ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
172 ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 1);
173
174 ath79_register_mdio(0, ~(BIT(0) | BIT(4)));
175
176 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
177 ath79_eth0_data.speed = SPEED_1000;
178 ath79_eth0_data.duplex = DUPLEX_FULL;
179 ath79_eth0_data.phy_mask = BIT(0);
180
181 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
182 ath79_eth1_data.phy_mask = BIT(4);
183
184 ath79_register_eth(0);
185 ath79_register_eth(1);
186
187 gpio_request_one(2, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
188 "USB power");
189 ath79_register_usb();
190
191 ath79_register_leds_gpio(-1, ARRAY_SIZE(wzrhpag300h_leds_gpio),
192 wzrhpag300h_leds_gpio);
193
194 ath79_register_gpio_keys_polled(-1, WZRHPAG300H_KEYS_POLL_INTERVAL,
195 ARRAY_SIZE(wzrhpag300h_gpio_keys),
196 wzrhpag300h_gpio_keys);
197
198 ath79_register_m25p80_multi(&wzrhpag300h_flash_data);
199
200 ap94_pci_init(eeprom1, mac1, eeprom2, mac2);
201
202 ap9x_pci_setup_wmac_led_pin(0, 1);
203 ap9x_pci_setup_wmac_led_pin(1, 5);
204
205 ap9x_pci_setup_wmac_leds(0, wzrhpag300h_wmac0_leds_gpio,
206 ARRAY_SIZE(wzrhpag300h_wmac0_leds_gpio));
207 ap9x_pci_setup_wmac_leds(1, wzrhpag300h_wmac1_leds_gpio,
208 ARRAY_SIZE(wzrhpag300h_wmac1_leds_gpio));
209 }
210
211 MIPS_MACHINE(ATH79_MACH_WZR_HP_AG300H, "WZR-HP-AG300H",
212 "Buffalo WZR-HP-AG300H", wzrhpag300h_setup);
213
214 MIPS_MACHINE(ATH79_MACH_WZR_600DHP, "WZR-600DHP",
215 "Buffalo WZR-600DHP", wzrhpag300h_setup);
216