Revert "ar71xx: Clear bits in ath79_setup_qca955x_eth_cfg"
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wa830re-v2.c
1 /*
2  *  TP-LINK TL-WA830RE v2 board support
3  *
4  *  Copyright (C) 2014 Fredrik Jonson <fredrik@famjonson.se>
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 #include <linux/platform_device.h>
13
14 #include <asm/mach-ath79/ath79.h>
15 #include <asm/mach-ath79/ar71xx_regs.h>
16
17 #include "common.h"
18 #include "dev-eth.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-leds-gpio.h"
21 #include "dev-m25p80.h"
22 #include "dev-usb.h"
23 #include "dev-wmac.h"
24 #include "machtypes.h"
25
26 #define TL_WA830REV2_GPIO_LED_WLAN      13
27 #define TL_WA830REV2_GPIO_LED_QSS       15
28 #define TL_WA830REV2_GPIO_LED_LAN       18
29 #define TL_WA830REV2_GPIO_LED_SYSTEM    14
30
31 #define TL_WA830REV2_GPIO_BTN_RESET     17
32 #define TL_WA830REV2_GPIO_SW_RFKILL     16      /* WPS for MR3420 v2 */
33
34 #define TL_WA830REV2_GPIO_USB_POWER     4
35
36 #define TL_WA830REV2_KEYS_POLL_INTERVAL 20      /* msecs */
37 #define TL_WA830REV2_KEYS_DEBOUNCE_INTERVAL (3 * TL_WA830REV2_KEYS_POLL_INTERVAL)
38
39 static const char *tl_wa830re_v2_part_probes[] = {
40         "tp-link",
41         NULL,
42 };
43
44 static struct flash_platform_data tl_wa830re_v2_flash_data = {
45         .part_probes    = tl_wa830re_v2_part_probes,
46 };
47
48 static struct gpio_led tl_wa830re_v2_leds_gpio[] __initdata = {
49         {
50                 .name           = "tp-link:green:qss",
51                 .gpio           = TL_WA830REV2_GPIO_LED_QSS,
52                 .active_low     = 1,
53         }, {
54                 .name           = "tp-link:green:system",
55                 .gpio           = TL_WA830REV2_GPIO_LED_SYSTEM,
56                 .active_low     = 1,
57         }, {
58                 .name           = "tp-link:green:lan",
59                 .gpio           = TL_WA830REV2_GPIO_LED_LAN,
60                 .active_low     = 1,
61         }, {
62                 .name           = "tp-link:green:wlan",
63                 .gpio           = TL_WA830REV2_GPIO_LED_WLAN,
64                 .active_low     = 1,
65         },
66 };
67
68 static struct gpio_keys_button tl_wa830re_v2_gpio_keys[] __initdata = {
69         {
70                 .desc           = "Reset button",
71                 .type           = EV_KEY,
72                 .code           = KEY_RESTART,
73                 .debounce_interval = TL_WA830REV2_KEYS_DEBOUNCE_INTERVAL,
74                 .gpio           = TL_WA830REV2_GPIO_BTN_RESET,
75                 .active_low     = 1,
76         }, {
77                 .desc           = "RFKILL switch",
78                 .type           = EV_SW,
79                 .code           = KEY_RFKILL,
80                 .debounce_interval = TL_WA830REV2_KEYS_DEBOUNCE_INTERVAL,
81                 .gpio           = TL_WA830REV2_GPIO_SW_RFKILL,
82                 .active_low     = 0,
83         }
84 };
85
86 static void __init tl_ap123_setup(void)
87 {
88         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
89         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
90
91         /* Disable JTAG, enabling GPIOs 0-3 */
92         /* Configure OBS4 line, for GPIO 4*/
93         ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
94                                  AR934X_GPIO_FUNC_CLK_OBS4_EN);
95
96         /* config gpio4 as normal gpio function */
97         ath79_gpio_output_select(TL_WA830REV2_GPIO_USB_POWER,
98                                  AR934X_GPIO_OUT_GPIO);
99
100         ath79_register_m25p80(&tl_wa830re_v2_flash_data);
101
102         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
103
104         ath79_register_mdio(1, 0x0);
105
106         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
107
108         /* GMAC0 is connected to the PHY0 of the internal switch */
109         ath79_switch_data.phy4_mii_en = 1;
110         ath79_switch_data.phy_poll_mask = BIT(0);
111         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
112         ath79_eth0_data.phy_mask = BIT(0);
113         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
114         ath79_register_eth(0);
115
116         ath79_register_wmac(ee, mac);
117 }
118
119 static void __init tl_wa830re_v2_setup(void)
120 {
121         tl_ap123_setup();
122
123         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa830re_v2_leds_gpio) - 1,
124                                  tl_wa830re_v2_leds_gpio);
125
126         ath79_register_gpio_keys_polled(1, TL_WA830REV2_KEYS_POLL_INTERVAL,
127                                         ARRAY_SIZE(tl_wa830re_v2_gpio_keys),
128                                         tl_wa830re_v2_gpio_keys);
129 }
130
131 MIPS_MACHINE(ATH79_MACH_TL_WA830RE_V2, "TL-WA830RE-v2", "TP-LINK TL-WA830RE v2",
132              tl_wa830re_v2_setup);