ar71xx: add a helper function for setting up PHY4 swapping on ar933x
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr741nd-v4.c
1 /*
2 * TP-LINK TL-WR741ND v4 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-wmac.h"
22 #include "machtypes.h"
23
24 #define TL_WR741NDV4_GPIO_BTN_RESET 11
25 #define TL_WR741NDV4_GPIO_BTN_WPS 26
26
27 #define TL_WR741NDV4_GPIO_LED_WLAN 0
28 #define TL_WR741NDV4_GPIO_LED_QSS 1
29 #define TL_WR741NDV4_GPIO_LED_WAN 13
30 #define TL_WR741NDV4_GPIO_LED_LAN1 14
31 #define TL_WR741NDV4_GPIO_LED_LAN2 15
32 #define TL_WR741NDV4_GPIO_LED_LAN3 16
33 #define TL_WR741NDV4_GPIO_LED_LAN4 17
34
35 #define TL_WR741NDV4_GPIO_LED_SYSTEM 27
36
37 #define TL_WR741NDV4_KEYS_POLL_INTERVAL 20 /* msecs */
38 #define TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR741NDV4_KEYS_POLL_INTERVAL)
39
40 static const char *tl_wr741ndv4_part_probes[] = {
41 "tp-link",
42 NULL,
43 };
44
45 static struct flash_platform_data tl_wr741ndv4_flash_data = {
46 .part_probes = tl_wr741ndv4_part_probes,
47 };
48
49 static struct gpio_led tl_wr741ndv4_leds_gpio[] __initdata = {
50 {
51 .name = "tp-link:green:lan1",
52 .gpio = TL_WR741NDV4_GPIO_LED_LAN1,
53 .active_low = 0,
54 }, {
55 .name = "tp-link:green:lan2",
56 .gpio = TL_WR741NDV4_GPIO_LED_LAN2,
57 .active_low = 0,
58 }, {
59 .name = "tp-link:green:lan3",
60 .gpio = TL_WR741NDV4_GPIO_LED_LAN3,
61 .active_low = 0,
62 }, {
63 .name = "tp-link:green:lan4",
64 .gpio = TL_WR741NDV4_GPIO_LED_LAN4,
65 .active_low = 1,
66 }, {
67 .name = "tp-link:green:qss",
68 .gpio = TL_WR741NDV4_GPIO_LED_QSS,
69 .active_low = 0,
70 }, {
71 .name = "tp-link:green:system",
72 .gpio = TL_WR741NDV4_GPIO_LED_SYSTEM,
73 .active_low = 1,
74 }, {
75 .name = "tp-link:green:wan",
76 .gpio = TL_WR741NDV4_GPIO_LED_WAN,
77 .active_low = 0,
78 }, {
79 .name = "tp-link:green:wlan",
80 .gpio = TL_WR741NDV4_GPIO_LED_WLAN,
81 .active_low = 0,
82 },
83 };
84
85 static struct gpio_keys_button tl_wr741ndv4_gpio_keys[] __initdata = {
86 {
87 .desc = "reset",
88 .type = EV_KEY,
89 .code = KEY_RESTART,
90 .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
91 .gpio = TL_WR741NDV4_GPIO_BTN_RESET,
92 .active_low = 0,
93 }, {
94 .desc = "WPS",
95 .type = EV_KEY,
96 .code = KEY_WPS_BUTTON,
97 .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
98 .gpio = TL_WR741NDV4_GPIO_BTN_WPS,
99 .active_low = 0,
100 }
101 };
102
103 static void __init tl_wr741ndv4_setup(void)
104 {
105 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
106 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
107
108 ath79_setup_ar933x_phy4_switch(true, true);
109
110 ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
111 AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
112 AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
113 AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
114 AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
115
116 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio),
117 tl_wr741ndv4_leds_gpio);
118
119 ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL,
120 ARRAY_SIZE(tl_wr741ndv4_gpio_keys),
121 tl_wr741ndv4_gpio_keys);
122
123 ath79_register_m25p80(&tl_wr741ndv4_flash_data);
124 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
125 ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);
126
127 ath79_register_mdio(0, 0x0);
128 ath79_register_eth(1);
129 ath79_register_eth(0);
130
131 ath79_register_wmac(ee, mac);
132 }
133
134 MIPS_MACHINE(ATH79_MACH_TL_WR741ND_V4, "TL-WR741ND-v4",
135 "TP-LINK TL-WR741ND v4", tl_wr741ndv4_setup);