e789b402b8d5078d45c5631db0545bbed729ac89
[openwrt.git] / target / linux / ar71xx / files-3.2 / arch / mips / ath79 / mach-tl-wr1043nd.c
1 /*
2  *  TP-LINK TL-WR1043N/ND board support
3  *
4  *  Copyright (C) 2009-2012 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/platform_device.h>
12 #include <linux/rtl8366.h>
13 #include <asm/mach-ath79/ath79.h>
14
15 #include "dev-eth.h"
16 #include "dev-m25p80.h"
17 #include "dev-gpio-buttons.h"
18 #include "dev-leds-gpio.h"
19 #include "dev-usb.h"
20 #include "dev-wmac.h"
21 #include "machtypes.h"
22
23 #define TL_WR1043ND_GPIO_LED_USB        1
24 #define TL_WR1043ND_GPIO_LED_SYSTEM     2
25 #define TL_WR1043ND_GPIO_LED_QSS        5
26 #define TL_WR1043ND_GPIO_LED_WLAN       9
27
28 #define TL_WR1043ND_GPIO_BTN_RESET      3
29 #define TL_WR1043ND_GPIO_BTN_QSS        7
30
31 #define TL_WR1043ND_GPIO_RTL8366_SDA    18
32 #define TL_WR1043ND_GPIO_RTL8366_SCK    19
33
34 #define TL_WR1043ND_KEYS_POLL_INTERVAL  20      /* msecs */
35 #define TL_WR1043ND_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043ND_KEYS_POLL_INTERVAL)
36
37 static const char *tl_wr1043nd_part_probes[] = {
38         "tp-link",
39         NULL,
40 };
41
42 static struct flash_platform_data tl_wr1043nd_flash_data = {
43         .part_probes    = tl_wr1043nd_part_probes,
44 };
45
46 static struct gpio_led tl_wr1043nd_leds_gpio[] __initdata = {
47         {
48                 .name           = "tp-link:green:usb",
49                 .gpio           = TL_WR1043ND_GPIO_LED_USB,
50                 .active_low     = 1,
51         }, {
52                 .name           = "tp-link:green:system",
53                 .gpio           = TL_WR1043ND_GPIO_LED_SYSTEM,
54                 .active_low     = 1,
55         }, {
56                 .name           = "tp-link:green:qss",
57                 .gpio           = TL_WR1043ND_GPIO_LED_QSS,
58                 .active_low     = 0,
59         }, {
60                 .name           = "tp-link:green:wlan",
61                 .gpio           = TL_WR1043ND_GPIO_LED_WLAN,
62                 .active_low     = 1,
63         }
64 };
65
66 static struct gpio_keys_button tl_wr1043nd_gpio_keys[] __initdata = {
67         {
68                 .desc           = "reset",
69                 .type           = EV_KEY,
70                 .code           = KEY_RESTART,
71                 .debounce_interval = TL_WR1043ND_KEYS_DEBOUNCE_INTERVAL,
72                 .gpio           = TL_WR1043ND_GPIO_BTN_RESET,
73                 .active_low     = 1,
74         }, {
75                 .desc           = "qss",
76                 .type           = EV_KEY,
77                 .code           = KEY_WPS_BUTTON,
78                 .debounce_interval = TL_WR1043ND_KEYS_DEBOUNCE_INTERVAL,
79                 .gpio           = TL_WR1043ND_GPIO_BTN_QSS,
80                 .active_low     = 1,
81         }
82 };
83
84 static struct rtl8366_platform_data tl_wr1043nd_rtl8366rb_data = {
85         .gpio_sda        = TL_WR1043ND_GPIO_RTL8366_SDA,
86         .gpio_sck        = TL_WR1043ND_GPIO_RTL8366_SCK,
87 };
88
89 static struct platform_device tl_wr1043nd_rtl8366rb_device = {
90         .name           = RTL8366RB_DRIVER_NAME,
91         .id             = -1,
92         .dev = {
93                 .platform_data  = &tl_wr1043nd_rtl8366rb_data,
94         }
95 };
96
97 static void __init tl_wr1043nd_setup(void)
98 {
99         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
100         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
101
102         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
103         ath79_eth0_data.mii_bus_dev = &tl_wr1043nd_rtl8366rb_device.dev;
104         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
105         ath79_eth0_data.speed = SPEED_1000;
106         ath79_eth0_data.duplex = DUPLEX_FULL;
107         ath79_eth0_pll_data.pll_1000 = 0x1a000000;
108
109         ath79_register_eth(0);
110
111         ath79_register_usb();
112
113         ath79_register_m25p80(&tl_wr1043nd_flash_data);
114
115         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_leds_gpio),
116                                  tl_wr1043nd_leds_gpio);
117
118         platform_device_register(&tl_wr1043nd_rtl8366rb_device);
119
120         ath79_register_gpio_keys_polled(-1, TL_WR1043ND_KEYS_POLL_INTERVAL,
121                                         ARRAY_SIZE(tl_wr1043nd_gpio_keys),
122                                         tl_wr1043nd_gpio_keys);
123
124         ath79_register_wmac(eeprom, mac);
125 }
126
127 MIPS_MACHINE(ATH79_MACH_TL_WR1043ND, "TL-WR1043ND", "TP-LINK TL-WR1043ND",
128              tl_wr1043nd_setup);