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