2 * Atheros AP83 board support
4 * Copyright (C) 2008-2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
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.
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/mtd/physmap.h>
17 #include <linux/spi/spi.h>
18 #include <linux/spi/spi_gpio.h>
19 #include <linux/spi/vsc7385.h>
21 #include <asm/mach-ath79/ar71xx_regs.h>
22 #include <asm/mach-ath79/ath79.h>
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
29 #include "machtypes.h"
31 #define AP83_GPIO_LED_WLAN 6
32 #define AP83_GPIO_LED_POWER 14
33 #define AP83_GPIO_LED_JUMPSTART 15
34 #define AP83_GPIO_BTN_JUMPSTART 12
35 #define AP83_GPIO_BTN_RESET 21
37 #define AP83_050_GPIO_VSC7385_CS 1
38 #define AP83_050_GPIO_VSC7385_MISO 3
39 #define AP83_050_GPIO_VSC7385_MOSI 16
40 #define AP83_050_GPIO_VSC7385_SCK 17
42 #define AP83_KEYS_POLL_INTERVAL 20 /* msecs */
43 #define AP83_KEYS_DEBOUNCE_INTERVAL (3 * AP83_KEYS_POLL_INTERVAL)
45 static struct mtd_partition ap83_flash_partitions[] = {
50 .mask_flags = MTD_WRITEABLE,
55 .mask_flags = MTD_WRITEABLE,
68 .mask_flags = MTD_WRITEABLE,
76 static struct physmap_flash_data ap83_flash_data = {
78 .parts = ap83_flash_partitions,
79 .nr_parts = ARRAY_SIZE(ap83_flash_partitions),
82 static struct resource ap83_flash_resources[] = {
84 .start = AR71XX_SPI_BASE,
85 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
86 .flags = IORESOURCE_MEM,
90 static struct platform_device ap83_flash_device = {
91 .name = "ar91xx-flash",
93 .resource = ap83_flash_resources,
94 .num_resources = ARRAY_SIZE(ap83_flash_resources),
96 .platform_data = &ap83_flash_data,
100 static struct gpio_led ap83_leds_gpio[] __initdata = {
102 .name = "ap83:green:jumpstart",
103 .gpio = AP83_GPIO_LED_JUMPSTART,
106 .name = "ap83:green:power",
107 .gpio = AP83_GPIO_LED_POWER,
110 .name = "ap83:green:wlan",
111 .gpio = AP83_GPIO_LED_WLAN,
116 static struct gpio_keys_button ap83_gpio_keys[] __initdata = {
118 .desc = "soft_reset",
121 .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL,
122 .gpio = AP83_GPIO_BTN_RESET,
127 .code = KEY_WPS_BUTTON,
128 .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL,
129 .gpio = AP83_GPIO_BTN_JUMPSTART,
134 static struct resource ap83_040_spi_resources[] = {
136 .start = AR71XX_SPI_BASE,
137 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
138 .flags = IORESOURCE_MEM,
142 static struct platform_device ap83_040_spi_device = {
145 .resource = ap83_040_spi_resources,
146 .num_resources = ARRAY_SIZE(ap83_040_spi_resources),
149 static struct spi_gpio_platform_data ap83_050_spi_data = {
150 .miso = AP83_050_GPIO_VSC7385_MISO,
151 .mosi = AP83_050_GPIO_VSC7385_MOSI,
152 .sck = AP83_050_GPIO_VSC7385_SCK,
156 static struct platform_device ap83_050_spi_device = {
160 .platform_data = &ap83_050_spi_data,
164 static void ap83_vsc7385_reset(void)
166 ath79_device_reset_set(AR71XX_RESET_GE1_PHY);
168 ath79_device_reset_clear(AR71XX_RESET_GE1_PHY);
172 static struct vsc7385_platform_data ap83_vsc7385_data = {
173 .reset = ap83_vsc7385_reset,
174 .ucode_name = "vsc7385_ucode_ap83.bin",
182 static struct spi_board_info ap83_spi_info[] = {
186 .max_speed_hz = 25000000,
187 .modalias = "spi-vsc7385",
188 .platform_data = &ap83_vsc7385_data,
189 .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
193 static void __init ap83_generic_setup(void)
195 u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
197 ath79_register_mdio(0, 0xfffffffe);
199 ath79_init_mac(ath79_eth0_data.mac_addr, eeprom, 0);
200 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
201 ath79_eth0_data.phy_mask = 0x1;
203 ath79_register_eth(0);
205 ath79_init_mac(ath79_eth1_data.mac_addr, eeprom, 1);
206 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
207 ath79_eth1_data.speed = SPEED_1000;
208 ath79_eth1_data.duplex = DUPLEX_FULL;
210 ath79_eth1_pll_data.pll_1000 = 0x1f000000;
212 ath79_register_eth(1);
214 ath79_register_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
217 ath79_register_gpio_keys_polled(-1, AP83_KEYS_POLL_INTERVAL,
218 ARRAY_SIZE(ap83_gpio_keys),
221 ath79_register_usb();
223 ath79_register_wmac(eeprom, NULL);
225 platform_device_register(&ap83_flash_device);
227 spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
230 static void ap83_040_flash_lock(struct platform_device *pdev)
232 ath79_flash_acquire();
235 static void ap83_040_flash_unlock(struct platform_device *pdev)
237 ath79_flash_release();
240 static void __init ap83_040_setup(void)
242 ap83_flash_data.lock = ap83_040_flash_lock;
243 ap83_flash_data.unlock = ap83_040_flash_unlock;
244 ap83_generic_setup();
245 platform_device_register(&ap83_040_spi_device);
248 static void __init ap83_050_setup(void)
250 ap83_generic_setup();
251 platform_device_register(&ap83_050_spi_device);
254 static void __init ap83_setup(void)
256 u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
257 unsigned int board_version;
259 board_version = (unsigned int)(board_id[0] - '0');
260 board_version += ((unsigned int)(board_id[1] - '0')) * 10;
262 switch (board_version) {
270 printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
275 MIPS_MACHINE(ATH79_MACH_AP83, "AP83", "Atheros AP83", ap83_setup);