| 1 | /* |
| 2 | * TP-LINK TL-WR741ND v4/TL-MR3220 v2 board support |
| 3 | * |
| 4 | * Copyright (C) 2011-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-usb.h" |
| 22 | #include "dev-wmac.h" |
| 23 | #include "machtypes.h" |
| 24 | |
| 25 | #define TL_WR741NDV4_GPIO_BTN_RESET 11 |
| 26 | #define TL_WR741NDV4_GPIO_BTN_WPS 26 |
| 27 | |
| 28 | #define TL_WR741NDV4_GPIO_LED_WLAN 0 |
| 29 | #define TL_WR741NDV4_GPIO_LED_QSS 1 |
| 30 | #define TL_WR741NDV4_GPIO_LED_WAN 13 |
| 31 | #define TL_WR741NDV4_GPIO_LED_LAN1 14 |
| 32 | #define TL_WR741NDV4_GPIO_LED_LAN2 15 |
| 33 | #define TL_WR741NDV4_GPIO_LED_LAN3 16 |
| 34 | #define TL_WR741NDV4_GPIO_LED_LAN4 17 |
| 35 | #define TL_WR741NDV4_GPIO_LED_SYSTEM 27 |
| 36 | |
| 37 | #define TL_MR3220V2_GPIO_LED_3G 26 |
| 38 | #define TL_MR3220V2_GPIO_USB_POWER 8 |
| 39 | |
| 40 | #define TL_WR741NDV4_KEYS_POLL_INTERVAL 20 /* msecs */ |
| 41 | #define TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR741NDV4_KEYS_POLL_INTERVAL) |
| 42 | |
| 43 | static const char *tl_wr741ndv4_part_probes[] = { |
| 44 | "tp-link", |
| 45 | NULL, |
| 46 | }; |
| 47 | |
| 48 | static struct flash_platform_data tl_wr741ndv4_flash_data = { |
| 49 | .part_probes = tl_wr741ndv4_part_probes, |
| 50 | }; |
| 51 | |
| 52 | static struct gpio_led tl_wr741ndv4_leds_gpio[] __initdata = { |
| 53 | { |
| 54 | .name = "tp-link:green:lan1", |
| 55 | .gpio = TL_WR741NDV4_GPIO_LED_LAN1, |
| 56 | .active_low = 0, |
| 57 | }, { |
| 58 | .name = "tp-link:green:lan2", |
| 59 | .gpio = TL_WR741NDV4_GPIO_LED_LAN2, |
| 60 | .active_low = 0, |
| 61 | }, { |
| 62 | .name = "tp-link:green:lan3", |
| 63 | .gpio = TL_WR741NDV4_GPIO_LED_LAN3, |
| 64 | .active_low = 0, |
| 65 | }, { |
| 66 | .name = "tp-link:green:lan4", |
| 67 | .gpio = TL_WR741NDV4_GPIO_LED_LAN4, |
| 68 | .active_low = 1, |
| 69 | }, { |
| 70 | .name = "tp-link:green:qss", |
| 71 | .gpio = TL_WR741NDV4_GPIO_LED_QSS, |
| 72 | .active_low = 0, |
| 73 | }, { |
| 74 | .name = "tp-link:green:system", |
| 75 | .gpio = TL_WR741NDV4_GPIO_LED_SYSTEM, |
| 76 | .active_low = 1, |
| 77 | }, { |
| 78 | .name = "tp-link:green:wan", |
| 79 | .gpio = TL_WR741NDV4_GPIO_LED_WAN, |
| 80 | .active_low = 0, |
| 81 | }, { |
| 82 | .name = "tp-link:green:wlan", |
| 83 | .gpio = TL_WR741NDV4_GPIO_LED_WLAN, |
| 84 | .active_low = 0, |
| 85 | }, { |
| 86 | /* the 3G LED is only present on the MR3220 v2 */ |
| 87 | .name = "tp-link:green:3g", |
| 88 | .gpio = TL_MR3220V2_GPIO_LED_3G, |
| 89 | .active_low = 0, |
| 90 | }, |
| 91 | }; |
| 92 | |
| 93 | static struct gpio_keys_button tl_wr741ndv4_gpio_keys[] __initdata = { |
| 94 | { |
| 95 | .desc = "reset", |
| 96 | .type = EV_KEY, |
| 97 | .code = KEY_RESTART, |
| 98 | .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL, |
| 99 | .gpio = TL_WR741NDV4_GPIO_BTN_RESET, |
| 100 | .active_low = 0, |
| 101 | }, { |
| 102 | /* the WPS button is only present on the WR741ND v4 */ |
| 103 | .desc = "WPS", |
| 104 | .type = EV_KEY, |
| 105 | .code = KEY_WPS_BUTTON, |
| 106 | .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL, |
| 107 | .gpio = TL_WR741NDV4_GPIO_BTN_WPS, |
| 108 | .active_low = 0, |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | static void __init tl_ap121_setup(void) |
| 113 | { |
| 114 | u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00); |
| 115 | u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000); |
| 116 | |
| 117 | ath79_setup_ar933x_phy4_switch(true, true); |
| 118 | |
| 119 | ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN | |
| 120 | AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN | |
| 121 | AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN | |
| 122 | AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN | |
| 123 | AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN); |
| 124 | |
| 125 | ath79_register_m25p80(&tl_wr741ndv4_flash_data); |
| 126 | ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1); |
| 127 | ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1); |
| 128 | |
| 129 | ath79_register_mdio(0, 0x0); |
| 130 | ath79_register_eth(1); |
| 131 | ath79_register_eth(0); |
| 132 | |
| 133 | ath79_register_wmac(ee, mac); |
| 134 | } |
| 135 | |
| 136 | static void __init tl_wr741ndv4_setup(void) |
| 137 | { |
| 138 | tl_ap121_setup(); |
| 139 | |
| 140 | ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio) - 1, |
| 141 | tl_wr741ndv4_leds_gpio); |
| 142 | ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL, |
| 143 | ARRAY_SIZE(tl_wr741ndv4_gpio_keys), |
| 144 | tl_wr741ndv4_gpio_keys); |
| 145 | } |
| 146 | |
| 147 | MIPS_MACHINE(ATH79_MACH_TL_WR741ND_V4, "TL-WR741ND-v4", |
| 148 | "TP-LINK TL-WR741ND v4", tl_wr741ndv4_setup); |
| 149 | |
| 150 | static void __init tl_mr3220v2_setup(void) |
| 151 | { |
| 152 | tl_ap121_setup(); |
| 153 | |
| 154 | gpio_request_one(TL_MR3220V2_GPIO_USB_POWER, |
| 155 | GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED, |
| 156 | "USB power"); |
| 157 | ath79_register_usb(); |
| 158 | |
| 159 | ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio), |
| 160 | tl_wr741ndv4_leds_gpio); |
| 161 | ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL, |
| 162 | ARRAY_SIZE(tl_wr741ndv4_gpio_keys) - 1, |
| 163 | tl_wr741ndv4_gpio_keys); |
| 164 | } |
| 165 | |
| 166 | MIPS_MACHINE(ATH79_MACH_TL_MR3220_V2, "TL-MR3220-v2", |
| 167 | "TP-LINK TL-MR3220 v2", tl_mr3220v2_setup); |
| 168 | |