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