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