ar71xx: add support for MikroTik hAP ac
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ew-dorin.c
1 /*
2 * EW Dorin board support
3 * (based on Atheros Ref. Design AP121)
4 * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2012-2015 Embedded Wireless GmbH www.80211.de
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 <asm/mach-ath79/ath79.h>
13 #include <asm/mach-ath79/ar71xx_regs.h>
14
15 #include "dev-eth.h"
16 #include "dev-gpio-buttons.h"
17 #include "dev-leds-gpio.h"
18 #include "dev-m25p80.h"
19 #include "dev-spi.h"
20 #include "dev-usb.h"
21 #include "dev-wmac.h"
22 #include "machtypes.h"
23
24 #define DORIN_KEYS_POLL_INTERVAL 20 /* msecs */
25 #define DORIN_KEYS_DEBOUNCE_INTERVAL (3 * DORIN_KEYS_POLL_INTERVAL)
26
27 #define DORIN_CALDATA_OFFSET 0x1000
28 #define DORIN_WMAC_MAC_OFFSET 0x1002
29
30 #define DORIN_GPIO_LED_21 21
31 #define DORIN_GPIO_LED_22 22
32 #define DORIN_GPIO_LED_STATUS 23
33
34 #define DORIN_GPIO_BTN_JUMPSTART 11
35 #define DORIN_GPIO_BTN_RESET 6
36
37 static struct gpio_led dorin_leds_gpio[] __initdata = {
38 {
39 .name = "dorin:green:led21",
40 .gpio = DORIN_GPIO_LED_21,
41 .active_low = 1,
42 },
43 {
44 .name = "dorin:green:led22",
45 .gpio = DORIN_GPIO_LED_22,
46 .active_low = 1,
47 },
48 {
49 .name = "dorin:green:status",
50 .gpio = DORIN_GPIO_LED_STATUS,
51 .active_low = 1,
52 },
53 };
54
55 static struct gpio_keys_button dorin_gpio_keys[] __initdata = {
56 {
57 .desc = "jumpstart button",
58 .type = EV_KEY,
59 .code = KEY_WPS_BUTTON,
60 .debounce_interval = DORIN_KEYS_DEBOUNCE_INTERVAL,
61 .gpio = DORIN_GPIO_BTN_JUMPSTART,
62 .active_low = 1,
63 },
64 {
65 .desc = "reset button",
66 .type = EV_KEY,
67 .code = KEY_RESTART,
68 .debounce_interval = DORIN_KEYS_DEBOUNCE_INTERVAL,
69 .gpio = DORIN_GPIO_BTN_RESET,
70 .active_low = 0,
71 }
72 };
73
74 static void __init ew_dorin_setup(void)
75 {
76 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
77 static u8 mac[6];
78
79 ath79_register_m25p80(NULL);
80
81 ath79_register_usb();
82
83 if (ar93xx_wmac_read_mac_address(mac)) {
84 ath79_register_wmac(NULL, NULL);
85 } else {
86 ath79_register_wmac(art + DORIN_CALDATA_OFFSET,
87 art + DORIN_WMAC_MAC_OFFSET);
88 memcpy(mac, art + DORIN_WMAC_MAC_OFFSET, sizeof(mac));
89 }
90
91 mac[3] |= 0x40;
92 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
93
94 ath79_register_mdio(0, 0x0);
95
96 /* LAN ports */
97 ath79_register_eth(1);
98
99 ath79_register_leds_gpio(-1, ARRAY_SIZE(dorin_leds_gpio),
100 dorin_leds_gpio);
101 ath79_register_gpio_keys_polled(-1, DORIN_KEYS_POLL_INTERVAL,
102 ARRAY_SIZE(dorin_gpio_keys),
103 dorin_gpio_keys);
104 }
105
106 MIPS_MACHINE(ATH79_MACH_EW_DORIN, "EW-DORIN", "EmbWir-Dorin",
107 ew_dorin_setup);
108
109
110 static void __init ew_dorin_router_setup(void)
111 {
112 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
113 static u8 mac[6];
114
115 ath79_register_m25p80(NULL);
116
117 ath79_register_usb();
118
119 if (ar93xx_wmac_read_mac_address(mac)) {
120 ath79_register_wmac(NULL, NULL);
121 } else {
122 ath79_register_wmac(art + DORIN_CALDATA_OFFSET,
123 art + DORIN_WMAC_MAC_OFFSET);
124 memcpy(mac, art + DORIN_WMAC_MAC_OFFSET, sizeof(mac));
125 }
126
127 mac[3] |= 0x40;
128 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
129
130 mac[3] &= 0x3F;
131 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
132 ath79_setup_ar933x_phy4_switch(true, true);
133
134 ath79_register_mdio(0, 0x0);
135
136 /* LAN ports */
137 ath79_register_eth(1);
138
139 /* WAN port */
140 ath79_register_eth(0);
141
142 ath79_register_leds_gpio(-1, ARRAY_SIZE(dorin_leds_gpio),
143 dorin_leds_gpio);
144 ath79_register_gpio_keys_polled(-1, DORIN_KEYS_POLL_INTERVAL,
145 ARRAY_SIZE(dorin_gpio_keys),
146 dorin_gpio_keys);
147 }
148
149 MIPS_MACHINE(ATH79_MACH_EW_DORIN_ROUTER, "EW-DORIN-ROUTER",
150 "EmbWir-Dorin-Router", ew_dorin_router_setup);