ar71xx: add support for ALFA Network N5Q
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr940n-v4.c
1 /*
2 * TP-LINK TL-WR940N v4 board support
3 *
4 * Copyright (C) 2016 David Lutz <kpanic@ff3l.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
26 #define TL_WR940N_V4_GPIO_LED_QSS 3
27 #define TL_WR940N_V4_GPIO_LED_WAN 14
28 #define TL_WR940N_V4_GPIO_LED_WAN_RED 15
29 #define TL_WR940N_V4_GPIO_LED_LAN4 4
30 #define TL_WR940N_V4_GPIO_LED_LAN3 18
31 #define TL_WR940N_V4_GPIO_LED_LAN2 6
32 #define TL_WR940N_V4_GPIO_LED_LAN1 8
33 #define TL_WR940N_V4_GPIO_LED_WLAN 7
34 #define TL_WR940N_V4_GPIO_LED_SYSTEM 5
35
36 #define TL_WR940N_V4_GPIO_BTN_RESET 1
37 #define TL_WR940N_V4_GPIO_BTN_RFKILL 2
38
39 #define TL_WR940N_V4_KEYS_POLL_INTERVAL 20
40 #define TL_WR940N_V4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR940N_V4_KEYS_POLL_INTERVAL)
41
42
43 static struct gpio_led tl_wr940n_v4_leds_gpio[] __initdata = {
44 {
45 .name = "tp-link:blue:qss",
46 .gpio = TL_WR940N_V4_GPIO_LED_QSS,
47 .active_low = 1,
48 },
49 {
50 .name = "tp-link:blue:wan",
51 .gpio = TL_WR940N_V4_GPIO_LED_WAN,
52 .active_low = 1,
53 },
54 {
55 .name = "tp-link:red:wan",
56 .gpio = TL_WR940N_V4_GPIO_LED_WAN_RED,
57 .active_low = 0,
58 },
59 {
60 .name = "tp-link:blue:lan1",
61 .gpio = TL_WR940N_V4_GPIO_LED_LAN1,
62 .active_low = 1,
63 },
64 {
65 .name = "tp-link:blue:lan2",
66 .gpio = TL_WR940N_V4_GPIO_LED_LAN2,
67 .active_low = 1,
68 },
69 {
70 .name = "tp-link:blue:lan3",
71 .gpio = TL_WR940N_V4_GPIO_LED_LAN3,
72 .active_low = 1,
73 },
74 {
75 .name = "tp-link:blue:lan4",
76 .gpio = TL_WR940N_V4_GPIO_LED_LAN4,
77 .active_low = 1,
78 },
79 {
80 .name = "tp-link:blue:wlan",
81 .gpio = TL_WR940N_V4_GPIO_LED_WLAN,
82 .active_low = 1,
83 },
84 {
85 .name = "tp-link:blue:system",
86 .gpio = TL_WR940N_V4_GPIO_LED_SYSTEM,
87 .active_low = 1,
88 },
89 };
90
91 static struct gpio_keys_button tl_wr940n_v4_gpio_keys[] __initdata = {
92 {
93 .desc = "Reset button",
94 .type = EV_KEY,
95 .code = KEY_RESTART,
96 .debounce_interval = TL_WR940N_V4_KEYS_DEBOUNCE_INTERVAL,
97 .gpio = TL_WR940N_V4_GPIO_BTN_RESET,
98 .active_low = 1,
99 }, {
100 .desc = "RFKILL button",
101 .type = EV_KEY,
102 .code = KEY_RFKILL,
103 .debounce_interval = TL_WR940N_V4_KEYS_DEBOUNCE_INTERVAL,
104 .gpio = TL_WR940N_V4_GPIO_BTN_RFKILL,
105 .active_low = 1,
106 }
107 };
108
109
110 static const char *tl_wr940n_v4_part_probes[] = {
111 "tp-link",
112 NULL,
113 };
114
115 static struct flash_platform_data tl_wr940n_v4_flash_data = {
116 .part_probes = tl_wr940n_v4_part_probes,
117 };
118
119
120 static void __init tl_wr940n_v4_setup(void)
121 {
122 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
123 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
124
125 ath79_register_m25p80(&tl_wr940n_v4_flash_data);
126
127 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr940n_v4_leds_gpio),
128 tl_wr940n_v4_leds_gpio);
129
130 ath79_register_gpio_keys_polled(-1, TL_WR940N_V4_KEYS_POLL_INTERVAL,
131 ARRAY_SIZE(tl_wr940n_v4_gpio_keys),
132 tl_wr940n_v4_gpio_keys);
133
134 ath79_register_mdio(0, 0x0);
135
136 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
137 ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);
138
139 ath79_switch_data.phy4_mii_en = 1;
140
141 ath79_register_eth(0);
142 ath79_register_eth(1);
143
144 ath79_register_wmac(ee, mac);
145
146 }
147
148 MIPS_MACHINE(ATH79_MACH_TL_WR940N_V4, "TL-WR940N-v4", "TP-LINK TL-WR940N v4",
149 tl_wr940n_v4_setup);