ar71xx: use ETH_ALEN for consistency
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dir-600-a1.c
1 /*
2 * D-Link DIR-600 rev. A1 board support
3 *
4 * Copyright (C) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2012 Vadim Girlin <vadimgirlin@gmail.com>
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 "common.h"
16 #include "dev-ap9x-pci.h"
17 #include "dev-eth.h"
18 #include "dev-gpio-buttons.h"
19 #include "dev-leds-gpio.h"
20 #include "dev-m25p80.h"
21 #include "machtypes.h"
22 #include "nvram.h"
23
24 #define DIR_600_A1_GPIO_LED_WPS 0
25 #define DIR_600_A1_GPIO_LED_POWER_AMBER 1
26 #define DIR_600_A1_GPIO_LED_POWER_GREEN 6
27 #define DIR_600_A1_GPIO_LED_LAN1 13
28 #define DIR_600_A1_GPIO_LED_LAN2 14
29 #define DIR_600_A1_GPIO_LED_LAN3 15
30 #define DIR_600_A1_GPIO_LED_LAN4 16
31 #define DIR_600_A1_GPIO_LED_WAN_AMBER 7
32 #define DIR_600_A1_GPIO_LED_WAN_GREEN 17
33
34 #define DIR_600_A1_GPIO_BTN_RESET 8
35 #define DIR_600_A1_GPIO_BTN_WPS 12
36
37 #define DIR_600_A1_KEYS_POLL_INTERVAL 20 /* msecs */
38 #define DIR_600_A1_KEYS_DEBOUNCE_INTERVAL (3 * DIR_600_A1_KEYS_POLL_INTERVAL)
39
40 #define DIR_600_A1_NVRAM_ADDR 0x1f030000
41 #define DIR_600_A1_NVRAM_SIZE 0x10000
42
43 static struct gpio_led dir_600_a1_leds_gpio[] __initdata = {
44 {
45 .name = "d-link:green:power",
46 .gpio = DIR_600_A1_GPIO_LED_POWER_GREEN,
47 }, {
48 .name = "d-link:amber:power",
49 .gpio = DIR_600_A1_GPIO_LED_POWER_AMBER,
50 }, {
51 .name = "d-link:amber:wan",
52 .gpio = DIR_600_A1_GPIO_LED_WAN_AMBER,
53 }, {
54 .name = "d-link:green:wan",
55 .gpio = DIR_600_A1_GPIO_LED_WAN_GREEN,
56 .active_low = 1,
57 }, {
58 .name = "d-link:green:lan1",
59 .gpio = DIR_600_A1_GPIO_LED_LAN1,
60 .active_low = 1,
61 }, {
62 .name = "d-link:green:lan2",
63 .gpio = DIR_600_A1_GPIO_LED_LAN2,
64 .active_low = 1,
65 }, {
66 .name = "d-link:green:lan3",
67 .gpio = DIR_600_A1_GPIO_LED_LAN3,
68 .active_low = 1,
69 }, {
70 .name = "d-link:green:lan4",
71 .gpio = DIR_600_A1_GPIO_LED_LAN4,
72 .active_low = 1,
73 }, {
74 .name = "d-link:blue:wps",
75 .gpio = DIR_600_A1_GPIO_LED_WPS,
76 .active_low = 1,
77 }
78 };
79
80 static struct gpio_keys_button dir_600_a1_gpio_keys[] __initdata = {
81 {
82 .desc = "reset",
83 .type = EV_KEY,
84 .code = KEY_RESTART,
85 .debounce_interval = DIR_600_A1_KEYS_DEBOUNCE_INTERVAL,
86 .gpio = DIR_600_A1_GPIO_BTN_RESET,
87 .active_low = 1,
88 }, {
89 .desc = "wps",
90 .type = EV_KEY,
91 .code = KEY_WPS_BUTTON,
92 .debounce_interval = DIR_600_A1_KEYS_DEBOUNCE_INTERVAL,
93 .gpio = DIR_600_A1_GPIO_BTN_WPS,
94 .active_low = 1,
95 }
96 };
97
98 static void __init dir_600_a1_setup(void)
99 {
100 const char *nvram = (char *) KSEG1ADDR(DIR_600_A1_NVRAM_ADDR);
101 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
102 u8 mac_buff[6];
103 u8 *mac = NULL;
104
105 if (ath79_nvram_parse_mac_addr(nvram, DIR_600_A1_NVRAM_SIZE,
106 "lan_mac=", mac_buff) == 0) {
107 ath79_init_mac(ath79_eth0_data.mac_addr, mac_buff, 0);
108 ath79_init_mac(ath79_eth1_data.mac_addr, mac_buff, 1);
109 mac = mac_buff;
110 }
111
112 ath79_register_m25p80(NULL);
113
114 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
115 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
116 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
117 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
118 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
119
120 ath79_register_leds_gpio(-1, ARRAY_SIZE(dir_600_a1_leds_gpio),
121 dir_600_a1_leds_gpio);
122
123 ath79_register_gpio_keys_polled(-1, DIR_600_A1_KEYS_POLL_INTERVAL,
124 ARRAY_SIZE(dir_600_a1_gpio_keys),
125 dir_600_a1_gpio_keys);
126
127 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
128 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
129
130 ath79_register_mdio(0, 0x0);
131
132 /* LAN ports */
133 ath79_register_eth(1);
134
135 /* WAN port */
136 ath79_register_eth(0);
137
138 ap91_pci_init(ee, mac);
139 }
140
141 MIPS_MACHINE(ATH79_MACH_DIR_600_A1, "DIR-600-A1", "D-Link DIR-600 rev. A1",
142 dir_600_a1_setup);
143
144 static void __init dir_615_e1_setup(void)
145 {
146 dir_600_a1_setup();
147 }
148
149 MIPS_MACHINE(ATH79_MACH_DIR_615_E1, "DIR-615-E1", "D-Link DIR-615 rev. E1",
150 dir_615_e1_setup);
151
152 static void __init dir_615_e4_setup(void)
153 {
154 dir_600_a1_setup();
155 ap9x_pci_setup_wmac_led_pin(0, 1);
156 }
157
158 MIPS_MACHINE(ATH79_MACH_DIR_615_E4, "DIR-615-E4", "D-Link DIR-615 rev. E4",
159 dir_615_e4_setup);