ar71xx: ar913x_wmac device support into a separate file
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-ap83.c
1 /*
2 * Atheros AP83 board support
3 *
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
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/delay.h>
13 #include <linux/platform_device.h>
14 #include <linux/input.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/partitions.h>
17 #include <linux/spi/spi.h>
18 #include <linux/spi/spi_gpio.h>
19 #include <linux/spi/vsc7385.h>
20
21 #include <asm/mips_machine.h>
22 #include <asm/mach-ar71xx/ar71xx.h>
23 #include <asm/mach-ar71xx/ar91xx_flash.h>
24
25 #include "devices.h"
26 #include "dev-ar913x-wmac.h"
27
28 #define AP83_GPIO_LED_WLAN 6
29 #define AP83_GPIO_LED_POWER 14
30 #define AP83_GPIO_LED_JUMPSTART 15
31 #define AP83_GPIO_BTN_JUMPSTART 12
32 #define AP83_GPIO_BTN_RESET 21
33
34 #define AP83_050_GPIO_VSC7385_CS 1
35 #define AP83_050_GPIO_VSC7385_MISO 3
36 #define AP83_050_GPIO_VSC7385_MOSI 16
37 #define AP83_050_GPIO_VSC7385_SCK 17
38
39 #ifdef CONFIG_MTD_PARTITIONS
40 static struct mtd_partition ap83_flash_partitions[] = {
41 {
42 .name = "u-boot",
43 .offset = 0,
44 .size = 0x040000,
45 .mask_flags = MTD_WRITEABLE,
46 } , {
47 .name = "u-boot-env",
48 .offset = 0x040000,
49 .size = 0x020000,
50 .mask_flags = MTD_WRITEABLE,
51 } , {
52 .name = "kernel",
53 .offset = 0x060000,
54 .size = 0x140000,
55 } , {
56 .name = "rootfs",
57 .offset = 0x1a0000,
58 .size = 0x650000,
59 } , {
60 .name = "art",
61 .offset = 0x7f0000,
62 .size = 0x010000,
63 .mask_flags = MTD_WRITEABLE,
64 } , {
65 .name = "firmware",
66 .offset = 0x060000,
67 .size = 0x790000,
68 }
69 };
70 #endif /* CONFIG_MTD_PARTITIONS */
71
72 static struct ar91xx_flash_platform_data ap83_flash_data = {
73 .width = 2,
74 #ifdef CONFIG_MTD_PARTITIONS
75 .parts = ap83_flash_partitions,
76 .nr_parts = ARRAY_SIZE(ap83_flash_partitions),
77 #endif
78 };
79
80 static struct resource ap83_flash_resources[] = {
81 [0] = {
82 .start = AR71XX_SPI_BASE,
83 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
84 .flags = IORESOURCE_MEM,
85 },
86 };
87
88 static struct platform_device ap83_flash_device = {
89 .name = "ar91xx-flash",
90 .id = -1,
91 .resource = ap83_flash_resources,
92 .num_resources = ARRAY_SIZE(ap83_flash_resources),
93 .dev = {
94 .platform_data = &ap83_flash_data,
95 }
96 };
97
98 static struct gpio_led ap83_leds_gpio[] __initdata = {
99 {
100 .name = "ap83:green:jumpstart",
101 .gpio = AP83_GPIO_LED_JUMPSTART,
102 .active_low = 0,
103 }, {
104 .name = "ap83:green:power",
105 .gpio = AP83_GPIO_LED_POWER,
106 .active_low = 0,
107 }, {
108 .name = "ap83:green:wlan",
109 .gpio = AP83_GPIO_LED_WLAN,
110 .active_low = 0,
111 },
112 };
113
114 static struct gpio_button ap83_gpio_buttons[] __initdata = {
115 {
116 .desc = "soft_reset",
117 .type = EV_KEY,
118 .code = BTN_0,
119 .threshold = 5,
120 .gpio = AP83_GPIO_BTN_RESET,
121 .active_low = 1,
122 } , {
123 .desc = "jumpstart",
124 .type = EV_KEY,
125 .code = BTN_1,
126 .threshold = 5,
127 .gpio = AP83_GPIO_BTN_JUMPSTART,
128 .active_low = 1,
129 }
130 };
131
132 static struct resource ap83_040_spi_resources[] = {
133 [0] = {
134 .start = AR71XX_SPI_BASE,
135 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
136 .flags = IORESOURCE_MEM,
137 },
138 };
139
140 static struct platform_device ap83_040_spi_device = {
141 .name = "ap83-spi",
142 .id = 0,
143 .resource = ap83_040_spi_resources,
144 .num_resources = ARRAY_SIZE(ap83_040_spi_resources),
145 };
146
147 static struct spi_gpio_platform_data ap83_050_spi_data = {
148 .miso = AP83_050_GPIO_VSC7385_MISO,
149 .mosi = AP83_050_GPIO_VSC7385_MOSI,
150 .sck = AP83_050_GPIO_VSC7385_SCK,
151 .num_chipselect = 1,
152 };
153
154 static struct platform_device ap83_050_spi_device = {
155 .name = "spi_gpio",
156 .id = 0,
157 .dev = {
158 .platform_data = &ap83_050_spi_data,
159 }
160 };
161
162 static void ap83_vsc7385_reset(void)
163 {
164 ar71xx_device_stop(RESET_MODULE_GE1_PHY);
165 udelay(10);
166 ar71xx_device_start(RESET_MODULE_GE1_PHY);
167 mdelay(50);
168 }
169
170 static struct vsc7385_platform_data ap83_vsc7385_data = {
171 .reset = ap83_vsc7385_reset,
172 .ucode_name = "vsc7385_ucode_ap83.bin",
173 .mac_cfg = {
174 .tx_ipg = 6,
175 .bit2 = 0,
176 .clk_sel = 3,
177 },
178 };
179
180 static struct spi_board_info ap83_spi_info[] = {
181 {
182 .bus_num = 0,
183 .chip_select = 0,
184 .max_speed_hz = 25000000,
185 .modalias = "spi-vsc7385",
186 .platform_data = &ap83_vsc7385_data,
187 .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
188 }
189 };
190
191 static void __init ap83_generic_setup(void)
192 {
193 u8 *mac = (u8 *) KSEG1ADDR(0x1fff1000);
194
195 ar71xx_set_mac_base(mac);
196
197 ar71xx_add_device_mdio(0xfffffffe);
198
199 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
200 ar71xx_eth0_data.phy_mask = 0x1;
201
202 ar71xx_add_device_eth(0);
203
204 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
205 ar71xx_eth1_data.phy_mask = 0x0;
206 ar71xx_eth1_data.speed = SPEED_1000;
207 ar71xx_eth1_data.duplex = DUPLEX_FULL;
208
209 ar71xx_eth1_pll_data.pll_1000 = 0x1f000000;
210
211 ar71xx_add_device_eth(1);
212
213 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
214 ap83_leds_gpio);
215
216 ar71xx_add_device_gpio_buttons(-1, 20, ARRAY_SIZE(ap83_gpio_buttons),
217 ap83_gpio_buttons);
218
219 ar71xx_add_device_usb();
220
221 ar913x_add_device_wmac();
222
223 platform_device_register(&ap83_flash_device);
224
225 spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
226 }
227
228 static void __init ap83_040_setup(void)
229 {
230 ap83_flash_data.is_shared=1;
231 ap83_generic_setup();
232 platform_device_register(&ap83_040_spi_device);
233 }
234
235 static void __init ap83_050_setup(void)
236 {
237 ap83_generic_setup();
238 platform_device_register(&ap83_050_spi_device);
239 }
240
241 static void __init ap83_setup(void)
242 {
243 u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
244 unsigned int board_version;
245
246 board_version = (unsigned int)(board_id[0] - '0');
247 board_version += ((unsigned int)(board_id[1] - '0')) * 10;
248
249 switch (board_version) {
250 case 40:
251 ap83_040_setup();
252 break;
253 case 50:
254 ap83_050_setup();
255 break;
256 default:
257 printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
258 board_version);
259 }
260 }
261
262 MIPS_MACHINE(AR71XX_MACH_AP83, "Atheros AP83", ap83_setup);