ar71xx: add support for the wzr-hp-g300nh2
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wzr-hp-g300nh2.c
1 /*
2 * Buffalo WZR-HP-G300NH2 board support
3 *
4 * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
5 * Copyright (C) 2011 Mark Deneen <mdeneen@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15
16 #include <asm/mips_machine.h>
17 #include <asm/mach-ar71xx/ar71xx.h>
18 #include <asm/mach-ar71xx/gpio.h>
19
20 #include "machtype.h"
21 #include "devices.h"
22 #include "dev-ap91-pci.h"
23 #include "dev-gpio-buttons.h"
24 #include "dev-leds-gpio.h"
25 #include "dev-m25p80.h"
26 #include "dev-usb.h"
27
28
29 #define WZRHPG300NH2_MAC_OFFSET 0x20c
30 #define WZRHPG300NH2_KEYS_POLL_INTERVAL 20 /* msecs */
31 #define WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH2_KEYS_POLL_INTERVAL)
32
33 #ifdef CONFIG_MTD_PARTITIONS
34 static struct mtd_partition wzrhpg300nh2_flash_partitions[] = {
35 {
36 .name = "u-boot",
37 .offset = 0,
38 .size = 0x0040000,
39 .mask_flags = MTD_WRITEABLE,
40 }, {
41 .name = "u-boot-env",
42 .offset = 0x0040000,
43 .size = 0x0010000,
44 .mask_flags = MTD_WRITEABLE,
45 }, {
46 .name = "art",
47 .offset = 0x0050000,
48 .size = 0x0010000,
49 .mask_flags = MTD_WRITEABLE,
50 }, {
51 .name = "kernel",
52 .offset = 0x0060000,
53 .size = 0x0100000,
54 }, {
55 .name = "rootfs",
56 .offset = 0x0160000,
57 .size = 0x1e90000,
58 }, {
59 .name = "user_property",
60 .offset = 0x1ff0000,
61 .size = 0x0010000,
62 .mask_flags = MTD_WRITEABLE,
63 }, {
64 .name = "firmware",
65 .offset = 0x0060000,
66 .size = 0x1f90000,
67 }
68 };
69
70 #endif /* CONFIG_MTD_PARTITIONS */
71
72
73
74 static struct flash_platform_data wzrhpg300nh2_flash_data = {
75 #ifdef CONFIG_MTD_PARTITIONS
76 .parts = wzrhpg300nh2_flash_partitions,
77 .nr_parts = ARRAY_SIZE(wzrhpg300nh2_flash_partitions),
78 #endif
79 };
80
81
82 static struct gpio_led wzrhpg300nh2_leds_gpio[] __initdata = {
83 {
84 .name = "buffalo:red:diag",
85 .gpio = 16,
86 .active_low = 1,
87 },
88 };
89
90 static struct gpio_led wzrhpg300nh2_wmac_leds_gpio[] = {
91 {
92 .name = "buffalo:blue:usb",
93 .gpio = 4,
94 .active_low = 1,
95 },
96 {
97 .name = "buffalo:green:wireless",
98 .gpio = 5,
99 .active_low = 1,
100 },
101 {
102 .name = "buffalo:orange:security",
103 .gpio = 6,
104 .active_low = 1,
105 },
106 {
107 .name = "buffalo:green:router",
108 .gpio = 7,
109 .active_low = 1,
110 },
111 {
112 .name = "buffalo:blue:movie_engine_on",
113 .gpio = 8,
114 .active_low = 1,
115 },
116 {
117 .name = "buffalo:blue:movie_engine_off",
118 .gpio = 9,
119 .active_low = 1,
120 },
121 };
122
123 /* The AOSS button is wmac gpio 12 */
124 static struct gpio_keys_button wzrhpg300nh2_gpio_keys[] __initdata = {
125 {
126 .desc = "reset",
127 .type = EV_KEY,
128 .code = KEY_RESTART,
129 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
130 .gpio = 1,
131 .active_low = 1,
132 }, {
133 .desc = "usb",
134 .type = EV_KEY,
135 .code = BTN_2,
136 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
137 .gpio = 7,
138 .active_low = 1,
139 }, {
140 .desc = "qos",
141 .type = EV_KEY,
142 .code = BTN_3,
143 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
144 .gpio = 11,
145 .active_low = 0,
146 }, {
147 .desc = "router_on",
148 .type = EV_KEY,
149 .code = BTN_5,
150 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
151 .gpio = 8,
152 .active_low = 0,
153 },
154 };
155
156
157 static void __init wzrhpg300nh2_setup(void)
158 {
159
160 u8 *eeprom = (u8 *) KSEG1ADDR(0x1f051000);
161 u8 *mac0 = eeprom + WZRHPG300NH2_MAC_OFFSET;
162 /* There is an eth1 but it is not connected to the switch */
163
164 ar71xx_add_device_m25p80_multi(&wzrhpg300nh2_flash_data);
165
166 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac0, 0);
167 ar71xx_add_device_mdio(0, ~(BIT(0)));
168
169 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac0, 0);
170 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
171 ar71xx_eth0_data.speed = SPEED_1000;
172 ar71xx_eth0_data.duplex = DUPLEX_FULL;
173 ar71xx_eth0_data.phy_mask = BIT(0);
174
175 ar71xx_add_device_eth(0);
176 ar71xx_add_device_usb();
177 /* gpio13 is usb power. Turn it on. */
178 gpio_request(13, "usb");
179 gpio_direction_output(13, 1);
180
181 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh2_leds_gpio),
182 wzrhpg300nh2_leds_gpio);
183 ar71xx_register_gpio_keys_polled(-1, WZRHPG300NH2_KEYS_POLL_INTERVAL,
184 ARRAY_SIZE(wzrhpg300nh2_gpio_keys),
185 wzrhpg300nh2_gpio_keys);
186 ap91_pci_setup_wmac_led_pin(22);
187 ap91_pci_setup_wmac_leds(wzrhpg300nh2_wmac_leds_gpio,
188 ARRAY_SIZE(wzrhpg300nh2_wmac_leds_gpio));
189
190 ap91_pci_init(eeprom, mac0);
191 }
192
193 MIPS_MACHINE(AR71XX_MACH_WZR_HP_AG300H, "WZR-HP-G300NH2",
194 "Buffalo WZR-HP-G300NH2", wzrhpg300nh2_setup);
195