ar71xx: Fix LED polarity for the TP-LINK TL-MR13U.
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr841n-v9.c
1 /*
2  *  TP-LINK TL-WR841N/ND v9
3  *
4  *  Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.net>
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-wmac.h"
23 #include "machtypes.h"
24
25 #define TL_WR841NV9_GPIO_LED_WLAN       13
26 #define TL_WR841NV9_GPIO_LED_QSS        3
27 #define TL_WR841NV9_GPIO_LED_WAN        4
28 #define TL_WR841NV9_GPIO_LED_LAN1       16
29 #define TL_WR841NV9_GPIO_LED_LAN2       15
30 #define TL_WR841NV9_GPIO_LED_LAN3       14
31 #define TL_WR841NV9_GPIO_LED_LAN4       11
32
33 #define TL_WR841NV9_GPIO_BTN_RESET      12
34 #define TL_WR841NV9_GPIO_BTN_WIFI       17
35
36 #define TL_WR841NV9_KEYS_POLL_INTERVAL  20      /* msecs */
37 #define TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV9_KEYS_POLL_INTERVAL)
38
39 static const char *tl_wr841n_v9_part_probes[] = {
40         "tp-link",
41         NULL,
42 };
43
44 static struct flash_platform_data tl_wr841n_v9_flash_data = {
45         .part_probes    = tl_wr841n_v9_part_probes,
46 };
47
48 static struct gpio_led tl_wr841n_v9_leds_gpio[] __initdata = {
49         {
50                 .name           = "tp-link:green:lan1",
51                 .gpio           = TL_WR841NV9_GPIO_LED_LAN1,
52                 .active_low     = 1,
53         }, {
54                 .name           = "tp-link:green:lan2",
55                 .gpio           = TL_WR841NV9_GPIO_LED_LAN2,
56                 .active_low     = 1,
57         }, {
58                 .name           = "tp-link:green:lan3",
59                 .gpio           = TL_WR841NV9_GPIO_LED_LAN3,
60                 .active_low     = 1,
61         }, {
62                 .name           = "tp-link:green:lan4",
63                 .gpio           = TL_WR841NV9_GPIO_LED_LAN4,
64                 .active_low     = 1,
65         }, {
66                 .name           = "tp-link:green:qss",
67                 .gpio           = TL_WR841NV9_GPIO_LED_QSS,
68                 .active_low     = 1,
69         }, {
70                 .name           = "tp-link:green:wan",
71                 .gpio           = TL_WR841NV9_GPIO_LED_WAN,
72                 .active_low     = 1,
73         }, {
74                 .name           = "tp-link:green:wlan",
75                 .gpio           = TL_WR841NV9_GPIO_LED_WLAN,
76                 .active_low     = 1,
77         },
78 };
79
80 static struct gpio_keys_button tl_wr841n_v9_gpio_keys[] __initdata = {
81         {
82                 .desc           = "Reset button",
83                 .type           = EV_KEY,
84                 .code           = KEY_RESTART,
85                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
86                 .gpio           = TL_WR841NV9_GPIO_BTN_RESET,
87                 .active_low     = 1,
88         }, {
89                 .desc           = "WIFI button",
90                 .type           = EV_KEY,
91                 .code           = KEY_RFKILL,
92                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
93                 .gpio           = TL_WR841NV9_GPIO_BTN_WIFI,
94                 .active_low     = 1,
95         }
96 };
97
98
99 static void __init tl_ap143_setup(void)
100 {
101         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
102         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
103         u8 tmpmac[ETH_ALEN];
104
105         ath79_register_m25p80(&tl_wr841n_v9_flash_data);
106
107         ath79_setup_ar933x_phy4_switch(false, false);
108
109         ath79_register_mdio(0, 0x0);
110
111         /* LAN */
112         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
113         ath79_register_eth(1);
114
115         /* WAN */
116         ath79_switch_data.phy4_mii_en = 1;
117         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
118         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
119         ath79_register_eth(0);
120
121         ath79_init_mac(tmpmac, mac, 0);
122         ath79_register_wmac(ee, tmpmac);
123 }
124
125 static void __init tl_wr841n_v9_setup(void)
126 {
127         tl_ap143_setup();
128
129         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v9_leds_gpio),
130                                  tl_wr841n_v9_leds_gpio);
131
132         ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
133                                         ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
134                                         tl_wr841n_v9_gpio_keys);
135 }
136
137 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V9, "TL-WR841N-v9", "TP-LINK TL-WR841N/ND v9",
138              tl_wr841n_v9_setup);