ar71xx/cpe510: enable LNA for CPE210/220/510/520
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-cpe510.c
1 /*
2 * TP-LINK CPE210/220/510/520 board support
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
26 #define CPE510_GPIO_LED_LAN0 11
27 #define CPE510_GPIO_LED_LAN1 12
28 #define CPE510_GPIO_LED_L1 13
29 #define CPE510_GPIO_LED_L2 14
30 #define CPE510_GPIO_LED_L3 15
31 #define CPE510_GPIO_LED_L4 16
32
33 #define CPE510_GPIO_EXTERNAL_LNA0 18
34 #define CPE510_GPIO_EXTERNAL_LNA1 19
35
36 #define CPE510_GPIO_BTN_RESET 4
37
38 #define CPE510_KEYS_POLL_INTERVAL 20 /* msecs */
39 #define CPE510_KEYS_DEBOUNCE_INTERVAL (3 * CPE510_KEYS_POLL_INTERVAL)
40
41
42 static struct gpio_led cpe510_leds_gpio[] __initdata = {
43 {
44 .name = "tp-link:green:lan0",
45 .gpio = CPE510_GPIO_LED_LAN0,
46 .active_low = 1,
47 }, {
48 .name = "tp-link:green:lan1",
49 .gpio = CPE510_GPIO_LED_LAN1,
50 .active_low = 1,
51 }, {
52 .name = "tp-link:green:link1",
53 .gpio = CPE510_GPIO_LED_L1,
54 .active_low = 1,
55 }, {
56 .name = "tp-link:green:link2",
57 .gpio = CPE510_GPIO_LED_L2,
58 .active_low = 1,
59 }, {
60 .name = "tp-link:green:link3",
61 .gpio = CPE510_GPIO_LED_L3,
62 .active_low = 1,
63 }, {
64 .name = "tp-link:green:link4",
65 .gpio = CPE510_GPIO_LED_L4,
66 .active_low = 1,
67 },
68 };
69
70 static struct gpio_keys_button cpe510_gpio_keys[] __initdata = {
71 {
72 .desc = "Reset button",
73 .type = EV_KEY,
74 .code = KEY_RESTART,
75 .debounce_interval = CPE510_KEYS_DEBOUNCE_INTERVAL,
76 .gpio = CPE510_GPIO_BTN_RESET,
77 .active_low = 1,
78 }
79 };
80
81
82 static void __init cpe510_setup(void)
83 {
84 u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
85 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
86
87 /* Disable JTAG, enabling GPIOs 0-3 */
88 /* Configure OBS4 line, for GPIO 4*/
89 ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
90 AR934X_GPIO_FUNC_CLK_OBS4_EN);
91
92 ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510_leds_gpio),
93 cpe510_leds_gpio);
94
95 ath79_register_gpio_keys_polled(1, CPE510_KEYS_POLL_INTERVAL,
96 ARRAY_SIZE(cpe510_gpio_keys),
97 cpe510_gpio_keys);
98
99 ath79_wmac_set_ext_lna_gpio(0, CPE510_GPIO_EXTERNAL_LNA0);
100 ath79_wmac_set_ext_lna_gpio(1, CPE510_GPIO_EXTERNAL_LNA1);
101
102 ath79_register_m25p80(NULL);
103
104 ath79_register_mdio(1, 0);
105 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
106 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
107 ath79_register_eth(1);
108
109 ath79_register_wmac(ee, mac);
110 }
111
112 MIPS_MACHINE(ATH79_MACH_CPE510, "CPE510", "TP-LINK CPE210/220/510/520",
113 cpe510_setup);