ar71xx: add kernel support for DRAGINO2
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dragino2.c
1 /*
2 * DRAGINO V2 board support, based on Atheros AP121 board support
3 *
4 * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2012 Elektra Wagenrad <elektra@villagetelco.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/gpio.h>
13 #include <asm/mach-ath79/ath79.h>
14 #include <asm/mach-ath79/ar71xx_regs.h>
15 #include "common.h"
16 #include "dev-eth.h"
17 #include "dev-gpio-buttons.h"
18 #include "dev-leds-gpio.h"
19 #include "dev-m25p80.h"
20 #include "dev-spi.h"
21 #include "dev-usb.h"
22 #include "dev-wmac.h"
23 #include "machtypes.h"
24
25 #define DRAGINO2_GPIO_LED_WLAN 0
26 #define DRAGINO2_GPIO_LED_LAN 13
27 #define DRAGINO2_GPIO_LED_WAN 17
28
29 /*
30 * The following GPIO is actually named "Router" on the board.
31 * However, since the "Router" feature is not supported as of yet
32 * we use it to display USB activity.
33 */
34
35 #define DRAGINO2_GPIO_LED_USB 28
36 #define DRAGINO2_GPIO_BTN_JUMPSTART 11
37 #define DRAGINO2_GPIO_BTN_RESET 12
38
39 #define DRAGINO2_KEYS_POLL_INTERVAL 20 /* msecs */
40 #define DRAGINO2_KEYS_DEBOUNCE_INTERVAL (3 * DRAGINO2_KEYS_POLL_INTERVAL)
41
42 #define DRAGINO2_MAC0_OFFSET 0x0000
43 #define DRAGINO2_MAC1_OFFSET 0x0006
44 #define DRAGINO2_CALDATA_OFFSET 0x1000
45 #define DRAGINO2_WMAC_MAC_OFFSET 0x1002
46
47 static struct gpio_led dragino2_leds_gpio[] __initdata = {
48 {
49 .name = "dragino2:red:lan",
50 .gpio = DRAGINO2_GPIO_LED_LAN,
51 .active_low = 0,
52 },
53 {
54 .name = "dragino2:red:wlan",
55 .gpio = DRAGINO2_GPIO_LED_WLAN,
56 .active_low = 0,
57 },
58 {
59 .name = "dragino2:red:wan",
60 .gpio = DRAGINO2_GPIO_LED_WAN,
61 .active_low = 0,
62 },
63 {
64 .name = "dragino2:red:usb",
65 .gpio = DRAGINO2_GPIO_LED_USB,
66 .active_low = 0,
67 },
68 };
69
70 static struct gpio_keys_button dragino2_gpio_keys[] __initdata = {
71 {
72 .desc = "jumpstart button",
73 .type = EV_KEY,
74 .code = KEY_WPS_BUTTON,
75 .debounce_interval = DRAGINO2_KEYS_DEBOUNCE_INTERVAL,
76 .gpio = DRAGINO2_GPIO_BTN_JUMPSTART,
77 .active_low = 1,
78 },
79 {
80 .desc = "reset button",
81 .type = EV_KEY,
82 .code = KEY_RESTART,
83 .debounce_interval = DRAGINO2_KEYS_DEBOUNCE_INTERVAL,
84 .gpio = DRAGINO2_GPIO_BTN_RESET,
85 .active_low = 1,
86 }
87 };
88
89 static void __init dragino2_common_setup(void)
90 {
91 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
92
93 ath79_register_m25p80(NULL);
94 ath79_register_wmac(art + DRAGINO2_CALDATA_OFFSET,
95 art + DRAGINO2_WMAC_MAC_OFFSET);
96
97 ath79_init_mac(ath79_eth0_data.mac_addr, art + DRAGINO2_MAC0_OFFSET, 0);
98 ath79_init_mac(ath79_eth1_data.mac_addr, art + DRAGINO2_MAC1_OFFSET, 0);
99
100 ath79_register_mdio(0, 0x0);
101
102 /* Enable GPIO15 and GPIO16 and possibly GPIO26 and GPIO27 */
103 ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
104 AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN);
105
106 /* LAN ports */
107 ath79_register_eth(1);
108
109 /* WAN port */
110 ath79_register_eth(0);
111 }
112
113 static void __init dragino2_setup(void)
114 {
115 dragino2_common_setup();
116
117 ath79_register_leds_gpio(-1, ARRAY_SIZE(dragino2_leds_gpio),
118 dragino2_leds_gpio);
119 ath79_register_gpio_keys_polled(-1, DRAGINO2_KEYS_POLL_INTERVAL,
120 ARRAY_SIZE(dragino2_gpio_keys),
121 dragino2_gpio_keys);
122 ath79_register_usb();
123 }
124
125 MIPS_MACHINE(ATH79_MACH_DRAGINO2, "DRAGINO2", "Dragino Dragino v2",
126 dragino2_setup);
127