ar71xx: improve support for the My Net Wi-Fi Range Extender device
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wndr4300.c
1 /*
2  *  NETGEAR WNDR4300 board support
3  *
4  *  Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
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/pci.h>
12 #include <linux/phy.h>
13 #include <linux/gpio.h>
14 #include <linux/platform_device.h>
15 #include <linux/ath9k_platform.h>
16 #include <linux/ar8216_platform.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/nand.h>
19 #include <linux/platform/ar934x_nfc.h>
20
21 #include <asm/mach-ath79/ar71xx_regs.h>
22
23 #include "common.h"
24 #include "dev-ap9x-pci.h"
25 #include "dev-eth.h"
26 #include "dev-gpio-buttons.h"
27 #include "dev-leds-gpio.h"
28 #include "dev-nfc.h"
29 #include "dev-usb.h"
30 #include "dev-wmac.h"
31 #include "machtypes.h"
32
33 #define WNDR4300_GPIO_LED_POWER_GREEN   0
34 #define WNDR4300_GPIO_LED_POWER_ORANGE  2
35 #define WNDR4300_GPIO_LED_USB           13
36 #define WNDR4300_GPIO_LED_WAN_GREEN     1
37 #define WNDR4300_GPIO_LED_WAN_ORANGE    3
38 #define WNDR4300_GPIO_LED_WLAN5G        14
39 #define WNDR4300_GPIO_LED_WPS_GREEN     16
40 #define WNDR4300_GPIO_LED_WPS_ORANGE    17
41
42 #define WNDR4300_GPIO_BTN_RESET         21
43 #define WNDR4300_GPIO_BTN_WIRELESS      15
44 #define WNDR4300_GPIO_BTN_WPS           12
45
46 #define WNDR4300_KEYS_POLL_INTERVAL     20      /* msecs */
47 #define WNDR4300_KEYS_DEBOUNCE_INTERVAL (3 * WNDR4300_KEYS_POLL_INTERVAL)
48
49 static struct gpio_led wndr4300_leds_gpio[] __initdata = {
50         {
51                 .name           = "netgear:green:power",
52                 .gpio           = WNDR4300_GPIO_LED_POWER_GREEN,
53                 .active_low     = 1,
54         },
55         {
56                 .name           = "netgear:orange:power",
57                 .gpio           = WNDR4300_GPIO_LED_POWER_ORANGE,
58                 .active_low     = 1,
59         },
60         {
61                 .name           = "netgear:green:wan",
62                 .gpio           = WNDR4300_GPIO_LED_WAN_GREEN,
63                 .active_low     = 1,
64         },
65         {
66                 .name           = "netgear:orange:wan",
67                 .gpio           = WNDR4300_GPIO_LED_WAN_ORANGE,
68                 .active_low     = 1,
69         },
70         {
71                 .name           = "netgear:green:usb",
72                 .gpio           = WNDR4300_GPIO_LED_USB,
73                 .active_low     = 1,
74         },
75         {
76                 .name           = "netgear:green:wps",
77                 .gpio           = WNDR4300_GPIO_LED_WPS_GREEN,
78                 .active_low     = 1,
79         },
80         {
81                 .name           = "netgear:orange:wps",
82                 .gpio           = WNDR4300_GPIO_LED_WPS_ORANGE,
83                 .active_low     = 1,
84         },
85         {
86                 .name           = "netgear:blue:wlan5g",
87                 .gpio           = WNDR4300_GPIO_LED_WLAN5G,
88                 .active_low     = 1,
89         },
90 };
91
92 static struct gpio_keys_button wndr4300_gpio_keys[] __initdata = {
93         {
94                 .desc           = "Reset button",
95                 .type           = EV_KEY,
96                 .code           = KEY_RESTART,
97                 .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
98                 .gpio           = WNDR4300_GPIO_BTN_RESET,
99                 .active_low     = 1,
100         },
101         {
102                 .desc           = "WPS button",
103                 .type           = EV_KEY,
104                 .code           = KEY_WPS_BUTTON,
105                 .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
106                 .gpio           = WNDR4300_GPIO_BTN_WPS,
107                 .active_low     = 1,
108         },
109         {
110                 .desc           = "Wireless button",
111                 .type           = EV_KEY,
112                 .code           = BTN_0,
113                 .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
114                 .gpio           = WNDR4300_GPIO_BTN_WIRELESS,
115                 .active_low     = 1,
116         },
117 };
118
119 static struct ar8327_pad_cfg wndr4300_ar8327_pad0_cfg = {
120         .mode = AR8327_PAD_MAC_RGMII,
121         .txclk_delay_en = true,
122         .rxclk_delay_en = true,
123         .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
124         .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
125 };
126
127 static struct ar8327_led_cfg wndr4300_ar8327_led_cfg = {
128         .led_ctrl0 = 0xc737c737,
129         .led_ctrl1 = 0x00000000,
130         .led_ctrl2 = 0x00000000,
131         .led_ctrl3 = 0x0030c300,
132         .open_drain = false,
133 };
134
135 static struct ar8327_platform_data wndr4300_ar8327_data = {
136         .pad0_cfg = &wndr4300_ar8327_pad0_cfg,
137         .port0_cfg = {
138                 .force_link = 1,
139                 .speed = AR8327_PORT_SPEED_1000,
140                 .duplex = 1,
141                 .txpause = 1,
142                 .rxpause = 1,
143         },
144         .led_cfg = &wndr4300_ar8327_led_cfg,
145 };
146
147 static struct mdio_board_info wndr4300_mdio0_info[] = {
148         {
149                 .bus_id = "ag71xx-mdio.0",
150                 .phy_addr = 0,
151                 .platform_data = &wndr4300_ar8327_data,
152         },
153 };
154
155 static void __init wndr4300_setup(void)
156 {
157         ath79_register_leds_gpio(-1, ARRAY_SIZE(wndr4300_leds_gpio),
158                                  wndr4300_leds_gpio);
159         ath79_register_gpio_keys_polled(-1, WNDR4300_KEYS_POLL_INTERVAL,
160                                         ARRAY_SIZE(wndr4300_gpio_keys),
161                                         wndr4300_gpio_keys);
162
163         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
164
165         mdiobus_register_board_info(wndr4300_mdio0_info,
166                                     ARRAY_SIZE(wndr4300_mdio0_info));
167
168         ath79_register_mdio(0, 0x0);
169
170         /* GMAC0 is connected to an AR8327N switch */
171         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
172         ath79_eth0_data.phy_mask = BIT(0);
173         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
174         ath79_eth0_pll_data.pll_1000 = 0x06000000;
175         ath79_register_eth(0);
176
177         ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
178         ath79_register_nfc();
179         ath79_register_usb();
180
181         ath79_register_wmac_simple();
182         ap91_pci_init_simple();
183 }
184
185 MIPS_MACHINE(ATH79_MACH_WNDR4300, "WNDR4300", "NETGEAR WNDR4300",
186              wndr4300_setup);