ar71xx: add v4.14 support
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wndr3700.c
1 /*
2 * Netgear WNDR3700 board support
3 *
4 * Copyright (C) 2009 Marco Porsch
5 * Copyright (C) 2009-2012 Gabor Juhos <juhosg@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/delay.h>
16 #include <linux/rtl8366.h>
17
18 #include <asm/mach-ath79/ath79.h>
19
20 #include "dev-ap9x-pci.h"
21 #include "dev-eth.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-m25p80.h"
25 #include "dev-usb.h"
26 #include "machtypes.h"
27
28 #define WNDR3700_GPIO_LED_WPS_ORANGE 0
29 #define WNDR3700_GPIO_LED_POWER_ORANGE 1
30 #define WNDR3700_GPIO_LED_POWER_GREEN 2
31 #define WNDR3700_GPIO_LED_WPS_GREEN 4
32 #define WNDR3700_GPIO_LED_WAN_GREEN 6
33
34 #define WNDR3700_GPIO_BTN_WPS 3
35 #define WNDR3700_GPIO_BTN_RESET 8
36 #define WNDR3700_GPIO_BTN_RFKILL 11
37
38 #define WNDR3700_GPIO_RTL8366_SDA 5
39 #define WNDR3700_GPIO_RTL8366_SCK 7
40
41 #define WNDR3700_KEYS_POLL_INTERVAL 20 /* msecs */
42 #define WNDR3700_KEYS_DEBOUNCE_INTERVAL (3 * WNDR3700_KEYS_POLL_INTERVAL)
43
44 #define WNDR3700_ETH0_MAC_OFFSET 0
45 #define WNDR3700_ETH1_MAC_OFFSET 0x6
46
47 #define WNDR3700_WMAC0_MAC_OFFSET 0
48 #define WNDR3700_WMAC1_MAC_OFFSET 0xc
49 #define WNDR3700_CALDATA0_OFFSET 0x1000
50 #define WNDR3700_CALDATA1_OFFSET 0x5000
51
52 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
53 {
54 .name = "netgear:green:power",
55 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
56 .active_low = 1,
57 }, {
58 .name = "netgear:orange:power",
59 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
60 .active_low = 1,
61 }, {
62 .name = "netgear:green:wps",
63 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
64 .active_low = 1,
65 }, {
66 .name = "netgear:orange:wps",
67 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
68 .active_low = 1,
69 }, {
70 .name = "netgear:green:wan",
71 .gpio = WNDR3700_GPIO_LED_WAN_GREEN,
72 .active_low = 1,
73 }
74 };
75
76 static struct gpio_keys_button wndr3700_gpio_keys[] __initdata = {
77 {
78 .desc = "reset",
79 .type = EV_KEY,
80 .code = KEY_RESTART,
81 .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
82 .gpio = WNDR3700_GPIO_BTN_RESET,
83 .active_low = 1,
84 }, {
85 .desc = "wps",
86 .type = EV_KEY,
87 .code = KEY_WPS_BUTTON,
88 .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
89 .gpio = WNDR3700_GPIO_BTN_WPS,
90 .active_low = 1,
91 }, {
92 .desc = "rfkill",
93 .type = EV_KEY,
94 .code = KEY_RFKILL,
95 .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
96 .gpio = WNDR3700_GPIO_BTN_RFKILL,
97 .active_low = 1,
98 }
99 };
100
101 static struct rtl8366_platform_data wndr3700_rtl8366s_data = {
102 .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
103 .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
104 };
105
106 static struct platform_device wndr3700_rtl8366s_device = {
107 .name = RTL8366S_DRIVER_NAME,
108 .id = -1,
109 .dev = {
110 .platform_data = &wndr3700_rtl8366s_data,
111 }
112 };
113
114 static void __init wndr3700_setup(void)
115 {
116 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
117
118 /*
119 * The eth0 and wmac0 interfaces share the same MAC address which
120 * can lead to problems if operated unbridged. Set the locally
121 * administered bit on the eth0 MAC to make it unique.
122 */
123 ath79_init_local_mac(ath79_eth0_data.mac_addr,
124 art + WNDR3700_ETH0_MAC_OFFSET);
125 ath79_eth0_pll_data.pll_1000 = 0x11110000;
126 ath79_eth0_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
127 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
128 ath79_eth0_data.speed = SPEED_1000;
129 ath79_eth0_data.duplex = DUPLEX_FULL;
130
131 ath79_init_mac(ath79_eth1_data.mac_addr,
132 art + WNDR3700_ETH1_MAC_OFFSET, 0);
133 ath79_eth1_pll_data.pll_1000 = 0x11110000;
134 ath79_eth1_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
135 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
136 ath79_eth1_data.phy_mask = 0x10;
137
138 ath79_register_eth(0);
139 ath79_register_eth(1);
140
141 ath79_register_usb();
142
143 ath79_register_m25p80(NULL);
144
145 ath79_register_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
146 wndr3700_leds_gpio);
147
148 ath79_register_gpio_keys_polled(-1, WNDR3700_KEYS_POLL_INTERVAL,
149 ARRAY_SIZE(wndr3700_gpio_keys),
150 wndr3700_gpio_keys);
151
152 platform_device_register(&wndr3700_rtl8366s_device);
153 platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
154
155 ap9x_pci_setup_wmac_led_pin(0, 5);
156 ap9x_pci_setup_wmac_led_pin(1, 5);
157
158 /* 2.4 GHz uses the first fixed antenna group (1, 0, 1, 0) */
159 ap9x_pci_setup_wmac_gpio(0, (0xf << 6), (0xa << 6));
160
161 /* 5 GHz uses the second fixed antenna group (0, 1, 1, 0) */
162 ap9x_pci_setup_wmac_gpio(1, (0xf << 6), (0x6 << 6));
163
164 ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
165 art + WNDR3700_WMAC0_MAC_OFFSET,
166 art + WNDR3700_CALDATA1_OFFSET,
167 art + WNDR3700_WMAC1_MAC_OFFSET);
168 }
169
170 MIPS_MACHINE(ATH79_MACH_WNDR3700, "WNDR3700",
171 "NETGEAR WNDR3700/WNDR3800/WNDRMAC",
172 wndr3700_setup);