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