ar71xx: use ETH_ALEN for consistency
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-hiwifi-hc6361.c
1 /*
2 * HiWiFi HC6361 board support
3 *
4 * Copyright (C) 2012-2013 eric
5 * Copyright (C) 2014 Yousong Zhou <yszhou4tech@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 <linux/gpio.h>
13 #include <linux/proc_fs.h>
14
15 #include <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
17
18 #include "common.h"
19 #include "dev-eth.h"
20 #include "dev-gpio-buttons.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
23 #include "dev-usb.h"
24 #include "dev-wmac.h"
25 #include "machtypes.h"
26
27 #define HIWIFI_HC6361_GPIO_LED_WLAN_2P4 0 /* 2.4G WLAN LED */
28 #define HIWIFI_HC6361_GPIO_LED_SYSTEM 1 /* System LED */
29 #define HIWIFI_HC6361_GPIO_LED_INTERNET 27 /* Internet LED */
30
31 #define HIWIFI_HC6361_GPIO_USBPOWER 20 /* USB power control */
32 #define HIWIFI_HC6361_GPIO_BTN_RST 11 /* Reset button */
33
34 #define HIWIFI_HC6361_KEYS_POLL_INTERVAL 20 /* msecs */
35 #define HIWIFI_HC6361_KEYS_DEBOUNCE_INTERVAL \
36 (3 * HIWIFI_HC6361_KEYS_POLL_INTERVAL)
37
38 static struct gpio_led hiwifi_leds_gpio[] __initdata = {
39 {
40 .name = "hiwifi:blue:wlan-2p4",
41 .gpio = HIWIFI_HC6361_GPIO_LED_WLAN_2P4,
42 .active_low = 1,
43 }, {
44 .name = "hiwifi:blue:system",
45 .gpio = HIWIFI_HC6361_GPIO_LED_SYSTEM,
46 .active_low = 1,
47 }, {
48 .name = "hiwifi:blue:internet",
49 .gpio = HIWIFI_HC6361_GPIO_LED_INTERNET,
50 .active_low = 1,
51 }
52 };
53
54 static struct gpio_keys_button hiwifi_gpio_keys[] __initdata = {
55 {
56 .desc = "reset",
57 .type = EV_KEY,
58 .code = KEY_RESTART,
59 .debounce_interval = HIWIFI_HC6361_KEYS_DEBOUNCE_INTERVAL,
60 .gpio = HIWIFI_HC6361_GPIO_BTN_RST,
61 .active_low = 1,
62 }
63 };
64
65 static void __init get_mac_from_bdinfo(u8 *mac, void *bdinfo)
66 {
67 if (sscanf(bdinfo, "fac_mac = %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
68 &mac[0], &mac[1], &mac[2], &mac[3],
69 &mac[4], &mac[5]) == 6) {
70 return;
71 }
72
73 printk(KERN_WARNING "Parsing MAC address failed.\n");
74 memcpy(mac, "\x00\xba\xbe\x00\x00\x00", 6);
75 }
76
77 static void __init hiwifi_hc6361_setup(void)
78 {
79 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
80 u8 mac[6];
81
82 ath79_setup_ar933x_phy4_switch(false, false);
83
84 ath79_register_m25p80(NULL);
85 ath79_gpio_function_enable(
86 AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
87 AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
88 AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
89 AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
90 AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
91
92 ath79_register_leds_gpio(-1, ARRAY_SIZE(hiwifi_leds_gpio),
93 hiwifi_leds_gpio);
94 ath79_register_gpio_keys_polled(-1, HIWIFI_HC6361_KEYS_POLL_INTERVAL,
95 ARRAY_SIZE(hiwifi_gpio_keys),
96 hiwifi_gpio_keys);
97 gpio_request_one(HIWIFI_HC6361_GPIO_USBPOWER,
98 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
99 "USB power");
100 ath79_register_usb();
101
102 get_mac_from_bdinfo(mac, (void *) KSEG1ADDR(0x1f010180));
103 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
104 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
105
106 ath79_register_mdio(0, 0x0);
107
108 ath79_register_eth(1);
109 ath79_register_eth(0);
110
111 ath79_register_wmac(ee, mac);
112 }
113
114 MIPS_MACHINE(ATH79_MACH_HIWIFI_HC6361, "HiWiFi-HC6361",
115 "HiWiFi HC6361", hiwifi_hc6361_setup);