[ar71xx] use platform data to setup the MAC_CFG register in the spi_vsc7385 driver
[openwrt.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
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         .mac_cfg = {
173                 .tx_ipg         = 6,
174                 .bit2           = 0,
175                 .clk_sel        = 3,
176         },
177 };
178
179 static struct spi_board_info ap83_spi_info[] = {
180         {
181                 .bus_num        = 0,
182                 .chip_select    = 0,
183                 .max_speed_hz   = 25000000,
184                 .modalias       = "spi-vsc7385",
185                 .platform_data  = &ap83_vsc7385_data,
186                 .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
187         }
188 };
189
190 static void __init ap83_generic_setup(void)
191 {
192         u8 *mac = (u8 *) KSEG1ADDR(0x1fff1000);
193
194         ar71xx_set_mac_base(mac);
195
196         ar71xx_add_device_mdio(0xfffffffe);
197
198         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
199         ar71xx_eth0_data.phy_mask = 0x1;
200
201         ar71xx_add_device_eth(0);
202
203         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
204         ar71xx_eth1_data.phy_mask = 0x0;
205         ar71xx_eth1_data.speed = SPEED_1000;
206         ar71xx_eth1_data.duplex = DUPLEX_FULL;
207
208         ar71xx_eth1_pll_data.pll_1000 = 0x1f000000;
209
210         ar71xx_add_device_eth(1);
211
212         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
213                                         ap83_leds_gpio);
214
215         ar71xx_add_device_gpio_buttons(-1, 20, ARRAY_SIZE(ap83_gpio_buttons),
216                                         ap83_gpio_buttons);
217
218         ar71xx_add_device_usb();
219
220         ar91xx_add_device_wmac();
221
222         platform_device_register(&ap83_flash_device);
223
224         spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
225 }
226
227 static void __init ap83_040_setup(void)
228 {
229         ap83_flash_data.is_shared=1;
230         ap83_generic_setup();
231         platform_device_register(&ap83_040_spi_device);
232 }
233
234 static void __init ap83_050_setup(void)
235 {
236         ap83_generic_setup();
237         platform_device_register(&ap83_050_spi_device);
238 }
239
240 static void __init ap83_setup(void)
241 {
242         u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
243         unsigned int board_version;
244
245         board_version = (unsigned int)(board_id[0] - '0');
246         board_version += ((unsigned int)(board_id[1] - '0')) * 10;
247
248         switch (board_version) {
249         case 40:
250                 ap83_040_setup();
251                 break;
252         case 50:
253                 ap83_050_setup();
254                 break;
255         default:
256                 printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
257                        board_version);
258         }
259 }
260
261 MIPS_MACHINE(AR71XX_MACH_AP83, "Atheros AP83", ap83_setup);