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#include <linux/platform_data/phy-at803x.h>
18
19#include <asm/mach-ath79/ar71xx_regs.h>
20
21#include "common.h"
22#include "dev-ap9x-pci.h"
23#include "dev-eth.h"
24#include "dev-gpio-buttons.h"
25#include "dev-leds-gpio.h"
26#include "dev-m25p80.h"
27#include "dev-spi.h"
28#include "dev-usb.h"
29#include "dev-wmac.h"
30#include "machtypes.h"
31#include "nvram.h"
32
33#define MYNET_REXT_GPIO_LED_POWER	11
34#define MYNET_REXT_GPIO_LED_ETHERNET	12
35#define MYNET_REXT_GPIO_LED_WIFI	19
36
37#define MYNET_REXT_GPIO_LED_RF_QTY1	20
38#define MYNET_REXT_GPIO_LED_RF_QTY2	21
39#define MYNET_REXT_GPIO_LED_RF_QTY3	22
40
41#define MYNET_REXT_GPIO_BTN_RESET	13
42#define MYNET_REXT_GPIO_BTN_WPS		15
43#define MYNET_REXT_GPIO_SW_RF		14
44
45#define MYNET_REXT_GPIO_PHY_SWRST	16	/* disables Ethernet PHY */
46#define MYNET_REXT_GPIO_PHY_INT		17
47#define MYNET_REXT_GPIO_18		18
48
49#define MYNET_REXT_KEYS_POLL_INTERVAL	20	/* msecs */
50#define MYNET_REXT_KEYS_DEBOUNCE_INTERVAL (3 * MYNET_REXT_KEYS_POLL_INTERVAL)
51
52#define MYNET_REXT_WMAC_CALDATA_OFFSET	0x1000
53
54#define MYNET_REXT_NVRAM_ADDR		0x1f7e0010
55#define MYNET_REXT_NVRAM_SIZE		0xfff0
56
57#define MYNET_REXT_ART_ADDR		0x1f7f0000
58
59static const char *mynet_rext_part_probes[] = {
60	"cybertan",
61	NULL,
62};
63
64static struct flash_platform_data mynet_rext_flash_data = {
65	.type		= "s25fl064k",
66	.part_probes	= mynet_rext_part_probes,
67};
68
69static struct gpio_led mynet_rext_leds_gpio[] __initdata = {
70	{
71		.name		= "wd:blue:power",
72		.gpio		= MYNET_REXT_GPIO_LED_POWER,
73		.active_low	= 0,
74	},
75	{
76		.name		= "wd:blue:wireless",
77		.gpio		= MYNET_REXT_GPIO_LED_WIFI,
78		.active_low	= 1,
79	},
80	{
81		.name		= "wd:blue:ethernet",
82		.gpio		= MYNET_REXT_GPIO_LED_ETHERNET,
83		.active_low	= 1,
84	},
85	{
86		.name		= "wd:blue:quality1",
87		.gpio		= MYNET_REXT_GPIO_LED_RF_QTY1,
88		.active_low	= 1,
89	},
90	{
91		.name		= "wd:blue:quality2",
92		.gpio		= MYNET_REXT_GPIO_LED_RF_QTY2,
93		.active_low	= 1,
94	},
95	{
96		.name		= "wd:blue:quality3",
97		.gpio		= MYNET_REXT_GPIO_LED_RF_QTY3,
98		.active_low	= 1,
99	},
100};
101
102static struct gpio_keys_button mynet_rext_gpio_keys[] __initdata = {
103	{
104		.desc		= "Reset button",
105		.type		= EV_KEY,
106		.code		= KEY_RESTART,
107		.debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
108		.gpio		= MYNET_REXT_GPIO_BTN_RESET,
109		.active_low	= 1,
110	},
111	{
112		.desc		= "WPS button",
113		.type		= EV_KEY,
114		.code		= KEY_WPS_BUTTON,
115		.debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
116		.gpio		= MYNET_REXT_GPIO_BTN_WPS,
117		.active_low	= 1,
118	},
119	{
120		.desc           = "RF Band switch",
121		.type           = EV_SW,
122		.code           = BTN_1,
123		.debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
124		.gpio           = MYNET_REXT_GPIO_SW_RF,
125	},
126};
127
128static struct at803x_platform_data mynet_rext_at803x_data = {
129	.disable_smarteee = 0,
130	.enable_rgmii_rx_delay = 1,
131	.enable_rgmii_tx_delay = 0,
132	.fixup_rgmii_tx_delay = 1,
133};
134
135static struct mdio_board_info mynet_rext_mdio0_info[] = {
136        {
137                .bus_id = "ag71xx-mdio.0",
138                .phy_addr = 4,
139                .platform_data = &mynet_rext_at803x_data,
140        },
141};
142
143static void mynet_rext_get_mac(const char *name, char *mac)
144{
145	u8 *nvram = (u8 *) KSEG1ADDR(MYNET_REXT_NVRAM_ADDR);
146	int err;
147
148	err = ath79_nvram_parse_mac_addr(nvram, MYNET_REXT_NVRAM_SIZE,
149					 name, mac);
150	if (err)
151		pr_err("no MAC address found for %s\n", name);
152}
153
154static void __init mynet_rext_setup(void)
155{
156	u8 *art = (u8 *) KSEG1ADDR(MYNET_REXT_ART_ADDR);
157	u8 tmpmac[ETH_ALEN];
158
159	ath79_register_m25p80(&mynet_rext_flash_data);
160
161	/* GPIO configuration from drivers/char/GPIO8.c */
162
163	ath79_gpio_output_select(MYNET_REXT_GPIO_LED_POWER,
164				 AR934X_GPIO_OUT_GPIO);
165	ath79_gpio_output_select(MYNET_REXT_GPIO_LED_WIFI,
166				 AR934X_GPIO_OUT_GPIO);
167	ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY1,
168				 AR934X_GPIO_OUT_GPIO);
169	ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY2,
170				 AR934X_GPIO_OUT_GPIO);
171	ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY3,
172				 AR934X_GPIO_OUT_GPIO);
173	ath79_gpio_output_select(MYNET_REXT_GPIO_LED_ETHERNET,
174				 AR934X_GPIO_OUT_GPIO);
175	ath79_register_leds_gpio(-1, ARRAY_SIZE(mynet_rext_leds_gpio),
176				 mynet_rext_leds_gpio);
177
178	ath79_register_gpio_keys_polled(-1, MYNET_REXT_KEYS_POLL_INTERVAL,
179					ARRAY_SIZE(mynet_rext_gpio_keys),
180					mynet_rext_gpio_keys);
181
182	ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
183				   AR934X_ETH_CFG_RXD_DELAY |
184				   AR934X_ETH_CFG_RDV_DELAY);
185
186	ath79_register_mdio(0, 0x0);
187
188	mdiobus_register_board_info(mynet_rext_mdio0_info,
189				    ARRAY_SIZE(mynet_rext_mdio0_info));
190
191	/* LAN */
192	mynet_rext_get_mac("et0macaddr=", ath79_eth0_data.mac_addr);
193
194	/* GMAC0 is connected to an external PHY on Port 4 */
195	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
196	ath79_eth0_data.phy_mask = BIT(4);
197	ath79_eth0_pll_data.pll_10   = 0x00001313; /* athrs_mac.c */
198	ath79_eth0_pll_data.pll_1000 = 0x0e000000; /* athrs_mac.c */
199	ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
200	ath79_register_eth(0);
201
202	/* WLAN */
203	mynet_rext_get_mac("wl0_hwaddr=", tmpmac);
204	ap91_pci_init(art + MYNET_REXT_WMAC_CALDATA_OFFSET, tmpmac);
205}
206
207MIPS_MACHINE(ATH79_MACH_MYNET_REXT, "MYNET-REXT",
208	     "WD My Net Wi-Fi Range Extender", mynet_rext_setup);
209