1/*
2 *  TP-LINK TL-WA901N/ND v1, TL-WA7510N v1 board support
3 *
4 *  Copyright (C) 2009-2012 Gabor Juhos <juhosg@openwrt.org>
5 *  Copyright (C) 2010 Pieter Hollants <pieter@hollants.com>
6 *  Copyright (C) 2012 Stefan Helmert <helst_listen@aol.de>
7 *
8 *  This program is free software; you can redistribute it and/or modify it
9 *  under the terms of the GNU General Public License version 2 as published
10 *  by the Free Software Foundation.
11 */
12
13#include <asm/mach-ath79/ar71xx_regs.h>
14#include <asm/mach-ath79/ath79.h>
15
16#include "common.h"
17#include "dev-ap9x-pci.h"
18#include "dev-eth.h"
19#include "dev-gpio-buttons.h"
20#include "dev-leds-gpio.h"
21#include "dev-m25p80.h"
22#include "machtypes.h"
23#include "pci.h"
24
25#define TL_WA901ND_GPIO_LED_QSS		0
26#define TL_WA901ND_GPIO_LED_SYSTEM	1
27#define TL_WA901ND_GPIO_LED_LAN		13
28
29#define TL_WA901ND_GPIO_BTN_RESET	11
30#define TL_WA901ND_GPIO_BTN_QSS		12
31
32#define TL_WA901ND_KEYS_POLL_INTERVAL	20	/* msecs */
33#define TL_WA901ND_KEYS_DEBOUNCE_INTERVAL (3 * TL_WA901ND_KEYS_POLL_INTERVAL)
34
35static const char *tl_wa901nd_part_probes[] = {
36	"tp-link",
37	NULL,
38};
39
40static struct flash_platform_data tl_wa901nd_flash_data = {
41	.part_probes	= tl_wa901nd_part_probes,
42};
43
44static struct gpio_led tl_wa901nd_leds_gpio[] __initdata = {
45	{
46		.name		= "tp-link:green:lan",
47		.gpio		= TL_WA901ND_GPIO_LED_LAN,
48		.active_low	= 1,
49	}, {
50		.name		= "tp-link:green:system",
51		.gpio		= TL_WA901ND_GPIO_LED_SYSTEM,
52		.active_low	= 1,
53	}, {
54		.name		= "tp-link:green:qss",
55		.gpio		= TL_WA901ND_GPIO_LED_QSS,
56		.active_low	= 1,
57	}
58};
59
60static struct gpio_keys_button tl_wa901nd_gpio_keys[] __initdata = {
61	{
62		.desc		= "reset",
63		.type		= EV_KEY,
64		.code		= BTN_0,
65		.debounce_interval = TL_WA901ND_KEYS_DEBOUNCE_INTERVAL,
66		.gpio		= TL_WA901ND_GPIO_BTN_RESET,
67		.active_low	= 1,
68	}, {
69		.desc		= "qss",
70		.type		= EV_KEY,
71		.code		= BTN_1,
72		.debounce_interval = TL_WA901ND_KEYS_DEBOUNCE_INTERVAL,
73		.gpio		= TL_WA901ND_GPIO_BTN_QSS,
74		.active_low	= 1,
75	}
76};
77
78static void __init common_setup(void)
79{
80	u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
81
82	/*
83	 * ath79_eth0 would be the WAN port, but is not connected.
84	 * ath79_eth1 connects to the internal switch chip, however
85	 * we have a single LAN port only.
86	 */
87	ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
88	ath79_register_mdio(0, 0x0);
89	ath79_register_eth(1);
90
91	ath79_register_m25p80(&tl_wa901nd_flash_data);
92}
93
94static void __init tl_wa901nd_setup(void)
95{
96	u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
97	u8 *ee  = (u8 *) KSEG1ADDR(0x1fff1000);
98
99	ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
100				    AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
101				    AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
102				    AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
103				    AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
104
105	common_setup();
106
107	ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa901nd_leds_gpio),
108				 tl_wa901nd_leds_gpio);
109
110	ath79_register_gpio_keys_polled(-1, TL_WA901ND_KEYS_POLL_INTERVAL,
111					ARRAY_SIZE(tl_wa901nd_gpio_keys),
112					tl_wa901nd_gpio_keys);
113
114	ap91_pci_init(ee, mac);
115}
116
117MIPS_MACHINE(ATH79_MACH_TL_WA901ND, "TL-WA901ND", "TP-LINK TL-WA901ND",
118	     tl_wa901nd_setup);
119
120static void __init tl_wa7510n_v1_setup(void)
121{
122	common_setup();
123	ath79_register_pci();
124}
125
126MIPS_MACHINE(ATH79_MACH_TL_WA7510N_V1, "TL-WA7510N", "TP-LINK TL-WA7510N v1",
127	     tl_wa7510n_v1_setup);
128