ar71xx: add support for MikroTik hAP ac lite
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dir-615-c1.c
1 /*
2 * D-Link DIR-615 rev C1 board support
3 *
4 * Copyright (C) 2008-2012 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 <asm/mach-ath79/ath79.h>
13
14 #include "dev-eth.h"
15 #include "dev-gpio-buttons.h"
16 #include "dev-leds-gpio.h"
17 #include "dev-m25p80.h"
18 #include "dev-wmac.h"
19 #include "machtypes.h"
20 #include "nvram.h"
21
22 #define DIR_615C1_GPIO_LED_ORANGE_STATUS 1 /* ORANGE:STATUS:TRICOLOR */
23 #define DIR_615C1_GPIO_LED_BLUE_WPS 3 /* BLUE:WPS */
24 #define DIR_615C1_GPIO_LED_GREEN_WAN 4 /* GREEN:WAN:TRICOLOR */
25 #define DIR_615C1_GPIO_LED_GREEN_WANCPU 5 /* GREEN:WAN:CPU:TRICOLOR */
26 #define DIR_615C1_GPIO_LED_GREEN_WLAN 6 /* GREEN:WLAN */
27 #define DIR_615C1_GPIO_LED_GREEN_STATUS 14 /* GREEN:STATUS:TRICOLOR */
28 #define DIR_615C1_GPIO_LED_ORANGE_WAN 15 /* ORANGE:WAN:TRICOLOR */
29
30 /* buttons may need refinement */
31
32 #define DIR_615C1_GPIO_BTN_WPS 12
33 #define DIR_615C1_GPIO_BTN_RESET 21
34
35 #define DIR_615C1_KEYS_POLL_INTERVAL 20 /* msecs */
36 #define DIR_615C1_KEYS_DEBOUNCE_INTERVAL (3 * DIR_615C1_KEYS_POLL_INTERVAL)
37
38 #define DIR_615C1_CONFIG_ADDR 0x1f020000
39 #define DIR_615C1_CONFIG_SIZE 0x10000
40
41 #define DIR_615C1_WLAN_MAC_ADDR 0x1f3fffb4
42
43 static struct gpio_led dir_615c1_leds_gpio[] __initdata = {
44 {
45 .name = "d-link:orange:status",
46 .gpio = DIR_615C1_GPIO_LED_ORANGE_STATUS,
47 .active_low = 1,
48 }, {
49 .name = "d-link:blue:wps",
50 .gpio = DIR_615C1_GPIO_LED_BLUE_WPS,
51 .active_low = 1,
52 }, {
53 .name = "d-link:green:wan",
54 .gpio = DIR_615C1_GPIO_LED_GREEN_WAN,
55 .active_low = 1,
56 }, {
57 .name = "d-link:green:wancpu",
58 .gpio = DIR_615C1_GPIO_LED_GREEN_WANCPU,
59 .active_low = 1,
60 }, {
61 .name = "d-link:green:wlan",
62 .gpio = DIR_615C1_GPIO_LED_GREEN_WLAN,
63 .active_low = 1,
64 }, {
65 .name = "d-link:green:status",
66 .gpio = DIR_615C1_GPIO_LED_GREEN_STATUS,
67 .active_low = 1,
68 }, {
69 .name = "d-link:orange:wan",
70 .gpio = DIR_615C1_GPIO_LED_ORANGE_WAN,
71 .active_low = 1,
72 }
73
74 };
75
76 static struct gpio_keys_button dir_615c1_gpio_keys[] __initdata = {
77 {
78 .desc = "reset",
79 .type = EV_KEY,
80 .code = KEY_RESTART,
81 .debounce_interval = DIR_615C1_KEYS_DEBOUNCE_INTERVAL,
82 .gpio = DIR_615C1_GPIO_BTN_RESET,
83 }, {
84 .desc = "wps",
85 .type = EV_KEY,
86 .code = KEY_WPS_BUTTON,
87 .debounce_interval = DIR_615C1_KEYS_DEBOUNCE_INTERVAL,
88 .gpio = DIR_615C1_GPIO_BTN_WPS,
89 }
90 };
91
92 #define DIR_615C1_LAN_PHYMASK BIT(0)
93 #define DIR_615C1_WAN_PHYMASK BIT(4)
94 #define DIR_615C1_MDIO_MASK (~(DIR_615C1_LAN_PHYMASK | \
95 DIR_615C1_WAN_PHYMASK))
96
97 static void __init dir_615c1_setup(void)
98 {
99 const char *config = (char *) KSEG1ADDR(DIR_615C1_CONFIG_ADDR);
100 u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
101 u8 mac[ETH_ALEN], wlan_mac[ETH_ALEN];
102
103 if (ath79_nvram_parse_mac_addr(config, DIR_615C1_CONFIG_SIZE,
104 "lan_mac=", mac) == 0) {
105 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
106 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
107 }
108
109 ath79_parse_ascii_mac((char *) KSEG1ADDR(DIR_615C1_WLAN_MAC_ADDR), wlan_mac);
110
111 ath79_register_mdio(0, DIR_615C1_MDIO_MASK);
112
113 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
114 ath79_eth0_data.phy_mask = DIR_615C1_LAN_PHYMASK;
115
116 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
117 ath79_eth1_data.phy_mask = DIR_615C1_WAN_PHYMASK;
118
119 ath79_register_eth(0);
120 ath79_register_eth(1);
121
122 ath79_register_m25p80(NULL);
123
124 ath79_register_leds_gpio(-1, ARRAY_SIZE(dir_615c1_leds_gpio),
125 dir_615c1_leds_gpio);
126
127 ath79_register_gpio_keys_polled(-1, DIR_615C1_KEYS_POLL_INTERVAL,
128 ARRAY_SIZE(dir_615c1_gpio_keys),
129 dir_615c1_gpio_keys);
130
131 ath79_register_wmac(eeprom, wlan_mac);
132 }
133
134 MIPS_MACHINE(ATH79_MACH_DIR_615_C1, "DIR-615-C1", "D-Link DIR-615 rev. C1",
135 dir_615c1_setup);