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