2 * TRENDnet TEW-712BR board support
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/gpio.h>
13 #include <asm/mach-ath79/ath79.h>
14 #include <asm/mach-ath79/ar71xx_regs.h>
18 #include "dev-gpio-buttons.h"
19 #include "dev-leds-gpio.h"
20 #include "dev-m25p80.h"
22 #include "machtypes.h"
24 #define TEW_712BR_GPIO_BTN_WPS 11
25 #define TEW_712BR_GPIO_BTN_RESET 12
27 #define TEW_712BR_GPIO_LED_LAN1 13
28 #define TEW_712BR_GPIO_LED_LAN2 14
29 #define TEW_712BR_GPIO_LED_LAN3 15
30 #define TEW_712BR_GPIO_LED_LAN4 16
31 #define TEW_712BR_GPIO_LED_POWER_GREEN 20
32 #define TEW_712BR_GPIO_LED_POWER_ORANGE 27
33 #define TEW_712BR_GPIO_LED_WAN_GREEN 17
34 #define TEW_712BR_GPIO_LED_WAN_ORANGE 23
35 #define TEW_712BR_GPIO_LED_WLAN 0
36 #define TEW_712BR_GPIO_LED_WPS 26
38 #define TEW_712BR_GPIO_WAN_LED_ENABLE 1
40 #define TEW_712BR_KEYS_POLL_INTERVAL 20 /* msecs */
41 #define TEW_712BR_KEYS_DEBOUNCE_INTERVAL (3 * TEW_712BR_KEYS_POLL_INTERVAL)
43 #define TEW_712BR_ART_ADDRESS 0x1f010000
44 #define TEW_712BR_CALDATA_OFFSET 0x1000
45 #define TEW_712BR_LAN_MAC_ADDRESS 0x1f020004
46 #define TEW_712BR_WAN_MAC_ADDRESS 0x1f020016
48 static struct gpio_led tew_712br_leds_gpio
[] __initdata
= {
50 .name
= "trendnet:green:lan1",
51 .gpio
= TEW_712BR_GPIO_LED_LAN1
,
54 .name
= "trendnet:green:lan2",
55 .gpio
= TEW_712BR_GPIO_LED_LAN2
,
58 .name
= "trendnet:green:lan3",
59 .gpio
= TEW_712BR_GPIO_LED_LAN3
,
62 .name
= "trendnet:green:lan4",
63 .gpio
= TEW_712BR_GPIO_LED_LAN4
,
66 .name
= "trendnet:blue:wps",
67 .gpio
= TEW_712BR_GPIO_LED_WPS
,
70 .name
= "trendnet:green:power",
71 .gpio
= TEW_712BR_GPIO_LED_POWER_GREEN
,
74 .name
= "trendnet:orange:power",
75 .gpio
= TEW_712BR_GPIO_LED_POWER_ORANGE
,
78 .name
= "trendnet:green:wan",
79 .gpio
= TEW_712BR_GPIO_LED_WAN_GREEN
,
82 .name
= "trendnet:orange:wan",
83 .gpio
= TEW_712BR_GPIO_LED_WAN_ORANGE
,
86 .name
= "trendnet:green:wlan",
87 .gpio
= TEW_712BR_GPIO_LED_WLAN
,
92 static struct gpio_keys_button tew_712br_gpio_keys
[] __initdata
= {
94 .desc
= "Reset button",
97 .debounce_interval
= TEW_712BR_KEYS_DEBOUNCE_INTERVAL
,
98 .gpio
= TEW_712BR_GPIO_BTN_RESET
,
101 .desc
= "WPS button",
103 .code
= KEY_WPS_BUTTON
,
104 .debounce_interval
= TEW_712BR_KEYS_DEBOUNCE_INTERVAL
,
105 .gpio
= TEW_712BR_GPIO_BTN_WPS
,
110 static void __init
tew_712br_read_ascii_mac(u8
*dest
, unsigned int src_addr
)
113 u8
*src
= (u8
*)KSEG1ADDR(src_addr
);
115 ret
= sscanf(src
, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
116 &dest
[0], &dest
[1], &dest
[2],
117 &dest
[3], &dest
[4], &dest
[5]);
120 memset(dest
, 0, ETH_ALEN
);
123 static void __init
tew_712br_setup(void)
125 u8
*art
= (u8
*) KSEG1ADDR(TEW_712BR_ART_ADDRESS
);
126 u8 lan_mac
[ETH_ALEN
];
127 u8 wan_mac
[ETH_ALEN
];
129 ath79_setup_ar933x_phy4_switch(false, false);
131 ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN
|
132 AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN
|
133 AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN
|
134 AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN
|
135 AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN
);
137 gpio_request_one(TEW_712BR_GPIO_WAN_LED_ENABLE
,
138 GPIOF_OUT_INIT_LOW
, "WAN LED enable");
140 ath79_register_leds_gpio(-1, ARRAY_SIZE(tew_712br_leds_gpio
),
141 tew_712br_leds_gpio
);
143 ath79_register_gpio_keys_polled(1, TEW_712BR_KEYS_POLL_INTERVAL
,
144 ARRAY_SIZE(tew_712br_gpio_keys
),
145 tew_712br_gpio_keys
);
147 ath79_register_m25p80(NULL
);
149 tew_712br_read_ascii_mac(lan_mac
, TEW_712BR_LAN_MAC_ADDRESS
);
150 tew_712br_read_ascii_mac(wan_mac
, TEW_712BR_WAN_MAC_ADDRESS
);
152 ath79_init_mac(ath79_eth0_data
.mac_addr
, wan_mac
, 0);
153 ath79_init_mac(ath79_eth1_data
.mac_addr
, lan_mac
, 0);
155 ath79_register_mdio(0, 0x0);
156 ath79_register_eth(1);
157 ath79_register_eth(0);
159 ath79_register_wmac(art
+ TEW_712BR_CALDATA_OFFSET
, wan_mac
);
162 MIPS_MACHINE(ATH79_MACH_TEW_712BR
, "TEW-712BR",
163 "TRENDnet TEW-712BR", tew_712br_setup
);