1/* 2 * TRENDnet TEW-712BR board support 3 * 4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org> 5 * 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. 9 */ 10 11#include <linux/gpio.h> 12 13#include <asm/mach-ath79/ath79.h> 14#include <asm/mach-ath79/ar71xx_regs.h> 15 16#include "common.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 "dev-wmac.h" 22#include "machtypes.h" 23 24#define TEW_712BR_GPIO_BTN_WPS 11 25#define TEW_712BR_GPIO_BTN_RESET 12 26 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 37 38#define TEW_712BR_GPIO_WAN_LED_ENABLE 1 39 40#define TEW_712BR_KEYS_POLL_INTERVAL 20 /* msecs */ 41#define TEW_712BR_KEYS_DEBOUNCE_INTERVAL (3 * TEW_712BR_KEYS_POLL_INTERVAL) 42 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 47 48static struct gpio_led tew_712br_leds_gpio[] __initdata = { 49 { 50 .name = "trendnet:green:lan1", 51 .gpio = TEW_712BR_GPIO_LED_LAN1, 52 .active_low = 0, 53 }, { 54 .name = "trendnet:green:lan2", 55 .gpio = TEW_712BR_GPIO_LED_LAN2, 56 .active_low = 0, 57 }, { 58 .name = "trendnet:green:lan3", 59 .gpio = TEW_712BR_GPIO_LED_LAN3, 60 .active_low = 0, 61 }, { 62 .name = "trendnet:green:lan4", 63 .gpio = TEW_712BR_GPIO_LED_LAN4, 64 .active_low = 0, 65 }, { 66 .name = "trendnet:blue:wps", 67 .gpio = TEW_712BR_GPIO_LED_WPS, 68 .active_low = 1, 69 }, { 70 .name = "trendnet:green:power", 71 .gpio = TEW_712BR_GPIO_LED_POWER_GREEN, 72 .active_low = 0, 73 }, { 74 .name = "trendnet:orange:power", 75 .gpio = TEW_712BR_GPIO_LED_POWER_ORANGE, 76 .active_low = 0, 77 }, { 78 .name = "trendnet:green:wan", 79 .gpio = TEW_712BR_GPIO_LED_WAN_GREEN, 80 .active_low = 1, 81 }, { 82 .name = "trendnet:orange:wan", 83 .gpio = TEW_712BR_GPIO_LED_WAN_ORANGE, 84 .active_low = 0, 85 }, { 86 .name = "trendnet:green:wlan", 87 .gpio = TEW_712BR_GPIO_LED_WLAN, 88 .active_low = 0, 89 }, 90}; 91 92static struct gpio_keys_button tew_712br_gpio_keys[] __initdata = { 93 { 94 .desc = "Reset button", 95 .type = EV_KEY, 96 .code = KEY_RESTART, 97 .debounce_interval = TEW_712BR_KEYS_DEBOUNCE_INTERVAL, 98 .gpio = TEW_712BR_GPIO_BTN_RESET, 99 .active_low = 1, 100 }, { 101 .desc = "WPS button", 102 .type = EV_KEY, 103 .code = KEY_WPS_BUTTON, 104 .debounce_interval = TEW_712BR_KEYS_DEBOUNCE_INTERVAL, 105 .gpio = TEW_712BR_GPIO_BTN_WPS, 106 .active_low = 1, 107 } 108}; 109 110static void __init tew_712br_read_ascii_mac(u8 *dest, unsigned int src_addr) 111{ 112 int ret; 113 u8 *src = (u8 *)KSEG1ADDR(src_addr); 114 115 ret = sscanf(src, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", 116 &dest[0], &dest[1], &dest[2], 117 &dest[3], &dest[4], &dest[5]); 118 119 if (ret != ETH_ALEN) 120 memset(dest, 0, ETH_ALEN); 121} 122 123static void __init tew_712br_setup(void) 124{ 125 u8 *art = (u8 *) KSEG1ADDR(TEW_712BR_ART_ADDRESS); 126 u8 lan_mac[ETH_ALEN]; 127 u8 wan_mac[ETH_ALEN]; 128 129 ath79_setup_ar933x_phy4_switch(false, false); 130 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); 136 137 gpio_request_one(TEW_712BR_GPIO_WAN_LED_ENABLE, 138 GPIOF_OUT_INIT_LOW, "WAN LED enable"); 139 140 ath79_register_leds_gpio(-1, ARRAY_SIZE(tew_712br_leds_gpio), 141 tew_712br_leds_gpio); 142 143 ath79_register_gpio_keys_polled(1, TEW_712BR_KEYS_POLL_INTERVAL, 144 ARRAY_SIZE(tew_712br_gpio_keys), 145 tew_712br_gpio_keys); 146 147 ath79_register_m25p80(NULL); 148 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); 151 152 ath79_init_mac(ath79_eth0_data.mac_addr, wan_mac, 0); 153 ath79_init_mac(ath79_eth1_data.mac_addr, lan_mac, 0); 154 155 ath79_register_mdio(0, 0x0); 156 ath79_register_eth(1); 157 ath79_register_eth(0); 158 159 ath79_register_wmac(art + TEW_712BR_CALDATA_OFFSET, wan_mac); 160} 161 162MIPS_MACHINE(ATH79_MACH_TEW_712BR, "TEW-712BR", 163 "TRENDnet TEW-712BR", tew_712br_setup); 164