ar71xx: do general formatting on wnr2000-v4
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-mynet-rext.c
1 /*
2  *  WD My Net WI-FI Range Extender (Codename:Starfish db12x) board support
3  *
4  *  Copyright (C) 2013 Christian Lamparter <chunkeey@googlemail.com>
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_REXT_GPIO_LED_POWER       11
33 #define MYNET_REXT_GPIO_LED_ETHERNET    12
34 #define MYNET_REXT_GPIO_LED_WIFI        19
35
36 #define MYNET_REXT_GPIO_LED_RF_QTY1     20
37 #define MYNET_REXT_GPIO_LED_RF_QTY2     21
38 #define MYNET_REXT_GPIO_LED_RF_QTY3     22
39
40 #define MYNET_REXT_GPIO_BTN_RESET       13
41 #define MYNET_REXT_GPIO_BTN_WPS         15
42 #define MYNET_REXT_GPIO_SW_RF           14
43
44 #define MYNET_REXT_GPIO_PHY_SWRST       16      /* disables Ethernet PHY */
45 #define MYNET_REXT_GPIO_PHY_INT         17
46 #define MYNET_REXT_GPIO_18              18
47
48 #define MYNET_REXT_KEYS_POLL_INTERVAL   20      /* msecs */
49 #define MYNET_REXT_KEYS_DEBOUNCE_INTERVAL (3 * MYNET_REXT_KEYS_POLL_INTERVAL)
50
51 #define MYNET_REXT_WMAC_CALDATA_OFFSET  0x1000
52
53 #define MYNET_REXT_NVRAM_ADDR           0x1f7e0010
54 #define MYNET_REXT_NVRAM_SIZE           0xfff0
55
56 #define MYNET_REXT_ART_ADDR             0x1f7f0000
57
58 static const char *mynet_rext_part_probes[] = {
59         "cybertan",
60         NULL,
61 };
62
63 static struct flash_platform_data mynet_rext_flash_data = {
64         .type           = "s25fl064k",
65         .part_probes    = mynet_rext_part_probes,
66 };
67
68 static struct gpio_led mynet_rext_leds_gpio[] __initdata = {
69         {
70                 .name           = "wd:blue:power",
71                 .gpio           = MYNET_REXT_GPIO_LED_POWER,
72                 .active_low     = 0,
73         },
74         {
75                 .name           = "wd:blue:wireless",
76                 .gpio           = MYNET_REXT_GPIO_LED_WIFI,
77                 .active_low     = 1,
78         },
79         {
80                 .name           = "wd:blue:ethernet",
81                 .gpio           = MYNET_REXT_GPIO_LED_ETHERNET,
82                 .active_low     = 1,
83         },
84         {
85                 .name           = "wd:blue:quality1",
86                 .gpio           = MYNET_REXT_GPIO_LED_RF_QTY1,
87                 .active_low     = 1,
88         },
89         {
90                 .name           = "wd:blue:quality2",
91                 .gpio           = MYNET_REXT_GPIO_LED_RF_QTY2,
92                 .active_low     = 1,
93         },
94         {
95                 .name           = "wd:blue:quality3",
96                 .gpio           = MYNET_REXT_GPIO_LED_RF_QTY3,
97                 .active_low     = 1,
98         },
99 };
100
101 static struct gpio_keys_button mynet_rext_gpio_keys[] __initdata = {
102         {
103                 .desc           = "Reset button",
104                 .type           = EV_KEY,
105                 .code           = KEY_RESTART,
106                 .debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
107                 .gpio           = MYNET_REXT_GPIO_BTN_RESET,
108                 .active_low     = 1,
109         },
110         {
111                 .desc           = "WPS button",
112                 .type           = EV_KEY,
113                 .code           = KEY_WPS_BUTTON,
114                 .debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
115                 .gpio           = MYNET_REXT_GPIO_BTN_WPS,
116                 .active_low     = 1,
117         },
118         {
119                 .desc           = "RF Band switch",
120                 .type           = EV_SW,
121                 .code           = BTN_1,
122                 .debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
123                 .gpio           = MYNET_REXT_GPIO_SW_RF,
124         },
125 };
126
127 static void mynet_rext_get_mac(const char *name, char *mac)
128 {
129         u8 *nvram = (u8 *) KSEG1ADDR(MYNET_REXT_NVRAM_ADDR);
130         int err;
131
132         err = ath79_nvram_parse_mac_addr(nvram, MYNET_REXT_NVRAM_SIZE,
133                                          name, mac);
134         if (err)
135                 pr_err("no MAC address found for %s\n", name);
136 }
137
138 static void __init mynet_rext_setup(void)
139 {
140         u8 *art = (u8 *) KSEG1ADDR(MYNET_REXT_ART_ADDR);
141         u8 tmpmac[ETH_ALEN];
142
143         ath79_register_m25p80(&mynet_rext_flash_data);
144
145         /* GPIO configuration from drivers/char/GPIO8.c */
146
147         ath79_gpio_output_select(MYNET_REXT_GPIO_LED_POWER,
148                                  AR934X_GPIO_OUT_GPIO);
149         ath79_gpio_output_select(MYNET_REXT_GPIO_LED_WIFI,
150                                  AR934X_GPIO_OUT_GPIO);
151         ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY1,
152                                  AR934X_GPIO_OUT_GPIO);
153         ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY2,
154                                  AR934X_GPIO_OUT_GPIO);
155         ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY3,
156                                  AR934X_GPIO_OUT_GPIO);
157         ath79_gpio_output_select(MYNET_REXT_GPIO_LED_ETHERNET,
158                                  AR934X_GPIO_OUT_GPIO);
159         ath79_register_leds_gpio(-1, ARRAY_SIZE(mynet_rext_leds_gpio),
160                                  mynet_rext_leds_gpio);
161
162         ath79_register_gpio_keys_polled(-1, MYNET_REXT_KEYS_POLL_INTERVAL,
163                                         ARRAY_SIZE(mynet_rext_gpio_keys),
164                                         mynet_rext_gpio_keys);
165
166         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
167                                    AR934X_ETH_CFG_RXD_DELAY |
168                                    AR934X_ETH_CFG_RDV_DELAY);
169
170         ath79_register_mdio(0, 0x0);
171
172         /* LAN */
173         mynet_rext_get_mac("et0macaddr=", ath79_eth0_data.mac_addr);
174
175         /* GMAC0 is connected to an external PHY on Port 4 */
176         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
177         ath79_eth0_data.phy_mask = BIT(4);
178         ath79_eth0_pll_data.pll_1000 = 0x0e000000; /* athrs_mac.c */
179         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
180         ath79_register_eth(0);
181
182         /* WLAN */
183         mynet_rext_get_mac("wl0_hwaddr=", tmpmac);
184         ap91_pci_init(art + MYNET_REXT_WMAC_CALDATA_OFFSET, tmpmac);
185 }
186
187 MIPS_MACHINE(ATH79_MACH_MYNET_REXT, "MYNET-REXT",
188              "WD My Net Wi-Fi Range Extender", mynet_rext_setup);