b8ccdfd60e7b30acf5f98abebc64bb739f06c812
[openwrt.git] / target / linux / ar71xx / files-3.2 / 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     = 1,
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     = 1,
100         }
101 };
102
103 static void __init tl_wr741ndv4_gmac_setup(void)
104 {
105         void __iomem *base;
106         u32 t;
107
108         base = ioremap(AR933X_GMAC_BASE, AR933X_GMAC_SIZE);
109
110         t = __raw_readl(base + AR933X_GMAC_REG_ETH_CFG);
111         t |= (AR933X_ETH_CFG_SW_PHY_SWAP | AR933X_ETH_CFG_SW_PHY_ADDR_SWAP);
112         __raw_writel(t, base + AR933X_GMAC_REG_ETH_CFG);
113
114         iounmap(base);
115 }
116
117 static void __init tl_wr741ndv4_setup(void)
118 {
119         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
120         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
121
122         tl_wr741ndv4_gmac_setup();
123
124         ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
125                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
126                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
127                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
128                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
129
130         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio),
131                                  tl_wr741ndv4_leds_gpio);
132
133         ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL,
134                                         ARRAY_SIZE(tl_wr741ndv4_gpio_keys),
135                                         tl_wr741ndv4_gpio_keys);
136
137         ath79_register_m25p80(&tl_wr741ndv4_flash_data);
138         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
139         ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);
140
141         ath79_register_mdio(0, 0x0);
142         ath79_register_eth(1);
143         ath79_register_eth(0);
144
145         ath79_register_wmac(ee, mac);
146 }
147
148 MIPS_MACHINE(ATH79_MACH_TL_WR741ND_V4, "TL-WR741ND-v4",
149              "TP-LINK TL-WR741ND v4", tl_wr741ndv4_setup);