f87fbf82e5afd7be74ed93b24f0fc2d2ca1b2b9a
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-mynet-n600.c
1 /*
2  *  WD My Net N600 board support
3  *
4  *  Copyright (C) 2013 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
18 #include <asm/mach-ath79/ar71xx_regs.h>
19
20 #include "common.h"
21 #include "dev-ap9x-pci.h"
22 #include "dev-eth.h"
23 #include "dev-gpio-buttons.h"
24 #include "dev-leds-gpio.h"
25 #include "dev-m25p80.h"
26 #include "dev-spi.h"
27 #include "dev-usb.h"
28 #include "dev-wmac.h"
29 #include "machtypes.h"
30 #include "nvram.h"
31
32 #define MYNET_N600_GPIO_LED_WIFI        0
33 #define MYNET_N600_GPIO_LED_POWER       11
34 #define MYNET_N600_GPIO_LED_INTERNET    12
35 #define MYNET_N600_GPIO_LED_WPS         13
36
37 #define MYNET_N600_GPIO_LED_LAN1        4
38 #define MYNET_N600_GPIO_LED_LAN2        3
39 #define MYNET_N600_GPIO_LED_LAN3        2
40 #define MYNET_N600_GPIO_LED_LAN4        1
41
42 #define MYNET_N600_GPIO_BTN_RESET       16
43 #define MYNET_N600_GPIO_BTN_WPS         17
44
45 #define MYNET_N600_KEYS_POLL_INTERVAL   20      /* msecs */
46 #define MYNET_N600_KEYS_DEBOUNCE_INTERVAL (3 * MYNET_N600_KEYS_POLL_INTERVAL)
47
48 #define MYNET_N600_MAC0_OFFSET          0
49 #define MYNET_N600_MAC1_OFFSET          6
50 #define MYNET_N600_WMAC_CALDATA_OFFSET  0x1000
51 #define MYNET_N600_PCIE_CALDATA_OFFSET  0x5000
52
53 #define MYNET_N600_NVRAM_ADDR           0x1f058010
54 #define MYNET_N600_NVRAM_SIZE           0x7ff0
55
56 static struct gpio_led mynet_n600_leds_gpio[] __initdata = {
57         {
58                 .name           = "wd:blue:power",
59                 .gpio           = MYNET_N600_GPIO_LED_POWER,
60                 .active_low     = 0,
61         },
62         {
63                 .name           = "wd:blue:wps",
64                 .gpio           = MYNET_N600_GPIO_LED_WPS,
65                 .active_low     = 0,
66         },
67         {
68                 .name           = "wd:blue:wireless",
69                 .gpio           = MYNET_N600_GPIO_LED_WIFI,
70                 .active_low     = 0,
71         },
72         {
73                 .name           = "wd:blue:internet",
74                 .gpio           = MYNET_N600_GPIO_LED_INTERNET,
75                 .active_low     = 0,
76         },
77         {
78                 .name           = "wd:green:lan1",
79                 .gpio           = MYNET_N600_GPIO_LED_LAN1,
80                 .active_low     = 1,
81         },
82         {
83                 .name           = "wd:green:lan2",
84                 .gpio           = MYNET_N600_GPIO_LED_LAN2,
85                 .active_low     = 1,
86         },
87         {
88                 .name           = "wd:green:lan3",
89                 .gpio           = MYNET_N600_GPIO_LED_LAN3,
90                 .active_low     = 1,
91         },
92         {
93                 .name           = "wd:green:lan4",
94                 .gpio           = MYNET_N600_GPIO_LED_LAN4,
95                 .active_low     = 1,
96         },
97 };
98
99 static struct gpio_keys_button mynet_n600_gpio_keys[] __initdata = {
100         {
101                 .desc           = "Reset button",
102                 .type           = EV_KEY,
103                 .code           = KEY_WPS_BUTTON,
104                 .debounce_interval = MYNET_N600_KEYS_DEBOUNCE_INTERVAL,
105                 .gpio           = MYNET_N600_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 = MYNET_N600_KEYS_DEBOUNCE_INTERVAL,
113                 .gpio           = MYNET_N600_GPIO_BTN_WPS,
114                 .active_low     = 1,
115         },
116 };
117
118 static void mynet_n600_get_mac(const char *name, char *mac)
119 {
120         u8 *nvram = (u8 *) KSEG1ADDR(MYNET_N600_NVRAM_ADDR);
121         int err;
122
123         err = ath79_nvram_parse_mac_addr(nvram, MYNET_N600_NVRAM_SIZE,
124                                          name, mac);
125         if (err)
126                 pr_err("no MAC address found for %s\n", name);
127 }
128
129 #define MYNET_N600_WAN_PHY_MASK BIT(0)
130
131 static void __init mynet_n600_setup(void)
132 {
133         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
134         u8 tmpmac[ETH_ALEN];
135
136         ath79_register_m25p80(NULL);
137
138         ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN1,
139                                  AR934X_GPIO_OUT_GPIO);
140         ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN2,
141                                  AR934X_GPIO_OUT_GPIO);
142         ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN3,
143                                  AR934X_GPIO_OUT_GPIO);
144         ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN4,
145                                  AR934X_GPIO_OUT_GPIO);
146         ath79_gpio_output_select(MYNET_N600_GPIO_LED_INTERNET,
147                                  AR934X_GPIO_OUT_GPIO);
148         ath79_register_leds_gpio(-1, ARRAY_SIZE(mynet_n600_leds_gpio),
149                                  mynet_n600_leds_gpio);
150
151         ath79_register_gpio_keys_polled(-1, MYNET_N600_KEYS_POLL_INTERVAL,
152                                         ARRAY_SIZE(mynet_n600_gpio_keys),
153                                         mynet_n600_gpio_keys);
154
155         mynet_n600_get_mac("wlan24mac=", tmpmac);
156         ath79_register_wmac(art + MYNET_N600_WMAC_CALDATA_OFFSET, tmpmac);
157
158         mynet_n600_get_mac("wlan5mac=", tmpmac);
159         ap91_pci_init(art + MYNET_N600_PCIE_CALDATA_OFFSET, tmpmac);
160
161         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE |
162                                    AR934X_ETH_CFG_SW_PHY_SWAP);
163
164         ath79_register_mdio(1, 0x0);
165
166         /* LAN */
167         mynet_n600_get_mac("lanmac=", ath79_eth1_data.mac_addr);
168
169         /* GMAC1 is connected to the internal switch */
170         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
171
172         ath79_register_eth(1);
173
174         /* WAN */
175         mynet_n600_get_mac("wanmac=", ath79_eth0_data.mac_addr);
176
177         /* GMAC0 is connected to the PHY4 of the internal switch */
178         ath79_switch_data.phy4_mii_en = 1;
179         ath79_switch_data.phy_poll_mask = MYNET_N600_WAN_PHY_MASK;
180
181         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
182         ath79_eth0_data.phy_mask = MYNET_N600_WAN_PHY_MASK;
183         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
184
185         ath79_register_eth(0);
186
187         ath79_register_usb();
188 }
189
190 MIPS_MACHINE(ATH79_MACH_MYNET_N600, "MYNET-N600", "WD My Net N600",
191              mynet_n600_setup);