ar71xx: remove hardwired interface parameters from mach-* files
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-ap121.c
1 /*
2 * Atheros AP121 board support
3 *
4 * Copyright (C) 2011 Gabor Juhos <juhosg@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/mtd/mtd.h>
12 #include <linux/mtd/partitions.h>
13 #include <linux/spi/flash.h>
14
15 #include "machtype.h"
16 #include "devices.h"
17 #include "dev-ar9xxx-wmac.h"
18 #include "dev-gpio-buttons.h"
19 #include "dev-leds-gpio.h"
20 #include "dev-m25p80.h"
21 #include "dev-usb.h"
22
23 #define AP121_GPIO_LED_WLAN 0
24 #define AP121_GPIO_LED_USB 1
25
26 #define AP121_GPIO_BTN_JUMPSTART 11
27 #define AP121_GPIO_BTN_RESET 12
28
29 #define AP121_KEYS_POLL_INTERVAL 20 /* msecs */
30 #define AP121_KEYS_DEBOUNCE_INTERVAL (3 * AP121_KEYS_POLL_INTERVAL)
31
32 #define AP121_MAC0_OFFSET 0x0000
33 #define AP121_MAC1_OFFSET 0x0006
34 #define AP121_CALDATA_OFFSET 0x1000
35 #define AP121_WMAC_MAC_OFFSET 0x1002
36
37 #define AP121_MINI_GPIO_LED_WLAN 0
38 #define AP121_MINI_GPIO_BTN_JUMPSTART 12
39 #define AP121_MINI_GPIO_BTN_RESET 11
40
41 #ifdef CONFIG_MTD_PARTITIONS
42 static struct mtd_partition ap121_parts[] = {
43 {
44 .name = "u-boot",
45 .offset = 0,
46 .size = 0x010000,
47 .mask_flags = MTD_WRITEABLE,
48 },
49 {
50 .name = "rootfs",
51 .offset = 0x010000,
52 .size = 0x130000,
53 },
54 {
55 .name = "uImage",
56 .offset = 0x140000,
57 .size = 0x0a0000,
58 },
59 {
60 .name = "NVRAM",
61 .offset = 0x1e0000,
62 .size = 0x010000,
63 },
64 {
65 .name = "ART",
66 .offset = 0x1f0000,
67 .size = 0x010000,
68 .mask_flags = MTD_WRITEABLE,
69 },
70 };
71 #define ap121_nr_parts ARRAY_SIZE(ap121_parts)
72
73 static struct mtd_partition ap121_mini_parts[] = {
74 {
75 .name = "u-boot",
76 .offset = 0,
77 .size = 0x040000,
78 .mask_flags = MTD_WRITEABLE,
79 },
80 {
81 .name = "u-boot-env",
82 .offset = 0x040000,
83 .size = 0x010000,
84 .mask_flags = MTD_WRITEABLE,
85 },
86 {
87 .name = "rootfs",
88 .offset = 0x050000,
89 .size = 0x2b0000,
90 },
91 {
92 .name = "uImage",
93 .offset = 0x300000,
94 .size = 0x0e0000,
95 },
96 {
97 .name = "NVRAM",
98 .offset = 0x3e0000,
99 .size = 0x010000,
100 },
101 {
102 .name = "ART",
103 .offset = 0x3f0000,
104 .size = 0x010000,
105 .mask_flags = MTD_WRITEABLE,
106 },
107 };
108
109 #define ap121_mini_nr_parts ARRAY_SIZE(ap121_parts)
110
111 #else
112 #define ap121_parts NULL
113 #define ap121_nr_parts 0
114 #define ap121_mini_parts NULL
115 #define ap121_mini_nr_parts 0
116 #endif /* CONFIG_MTD_PARTITIONS */
117
118 static struct flash_platform_data ap121_flash_data = {
119 .parts = ap121_parts,
120 .nr_parts = ap121_nr_parts,
121 };
122
123 static struct gpio_led ap121_leds_gpio[] __initdata = {
124 {
125 .name = "ap121:green:usb",
126 .gpio = AP121_GPIO_LED_USB,
127 .active_low = 0,
128 },
129 {
130 .name = "ap121:green:wlan",
131 .gpio = AP121_GPIO_LED_WLAN,
132 .active_low = 0,
133 },
134 };
135
136 static struct gpio_keys_button ap121_gpio_keys[] __initdata = {
137 {
138 .desc = "jumpstart button",
139 .type = EV_KEY,
140 .code = KEY_WPS_BUTTON,
141 .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
142 .gpio = AP121_GPIO_BTN_JUMPSTART,
143 .active_low = 1,
144 },
145 {
146 .desc = "reset button",
147 .type = EV_KEY,
148 .code = KEY_RESTART,
149 .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
150 .gpio = AP121_GPIO_BTN_RESET,
151 .active_low = 1,
152 }
153 };
154
155 static struct gpio_led ap121_mini_leds_gpio[] __initdata = {
156 {
157 .name = "ap121:green:wlan",
158 .gpio = AP121_MINI_GPIO_LED_WLAN,
159 .active_low = 0,
160 },
161 };
162
163 static struct gpio_keys_button ap121_mini_gpio_keys[] __initdata = {
164 {
165 .desc = "jumpstart button",
166 .type = EV_KEY,
167 .code = KEY_WPS_BUTTON,
168 .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
169 .gpio = AP121_MINI_GPIO_BTN_JUMPSTART,
170 .active_low = 1,
171 },
172 {
173 .desc = "reset button",
174 .type = EV_KEY,
175 .code = KEY_RESTART,
176 .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
177 .gpio = AP121_MINI_GPIO_BTN_RESET,
178 .active_low = 1,
179 }
180 };
181
182 static void __init ap121_common_setup(void)
183 {
184 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
185
186 ar71xx_add_device_m25p80(&ap121_flash_data);
187
188 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, art + AP121_MAC0_OFFSET, 0);
189 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, art + AP121_MAC1_OFFSET, 0);
190
191 ar71xx_add_device_mdio(0, 0x0);
192
193 /* LAN ports */
194 ar71xx_add_device_eth(1);
195
196 /* WAN port */
197 ar71xx_add_device_eth(0);
198
199 ar9xxx_add_device_wmac(art + AP121_CALDATA_OFFSET,
200 art + AP121_WMAC_MAC_OFFSET);
201 }
202
203 static void __init ap121_setup(void)
204 {
205 ap121_flash_data.parts = ap121_parts;
206 ap121_flash_data.nr_parts = ap121_nr_parts;
207
208 ap121_common_setup();
209
210 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap121_leds_gpio),
211 ap121_leds_gpio);
212 ar71xx_register_gpio_keys_polled(-1, AP121_KEYS_POLL_INTERVAL,
213 ARRAY_SIZE(ap121_gpio_keys),
214 ap121_gpio_keys);
215
216 ar71xx_add_device_usb();
217 }
218
219 static void __init ap121_mini_setup(void)
220 {
221 ap121_flash_data.parts = ap121_mini_parts;
222 ap121_flash_data.nr_parts = ap121_mini_nr_parts;
223
224 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap121_mini_leds_gpio),
225 ap121_mini_leds_gpio);
226 ar71xx_register_gpio_keys_polled(-1, AP121_KEYS_POLL_INTERVAL,
227 ARRAY_SIZE(ap121_mini_gpio_keys),
228 ap121_mini_gpio_keys);
229
230 ap121_common_setup();
231 }
232
233 MIPS_MACHINE(AR71XX_MACH_AP121, "AP121", "Atheros AP121",
234 ap121_setup);
235
236 MIPS_MACHINE(AR71XX_MACH_AP121_MINI, "AP121-MINI", "Atheros AP121-MINI",
237 ap121_mini_setup);