ramips: add preliminary support for the Asus RT-N56U board
[openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt3883 / mach-rt-n56u.c
1 /*
2  *  Asus RT-N56U board support
3  *
4  *  Copyright (C) 2011-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/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/rtl8367.h>
14 #include <linux/ethtool.h>
15
16 #include <asm/mach-ralink/machine.h>
17 #include <asm/mach-ralink/dev-gpio-buttons.h>
18 #include <asm/mach-ralink/dev-gpio-leds.h>
19 #include <asm/mach-ralink/rt3883.h>
20 #include <asm/mach-ralink/rt3883_regs.h>
21 #include <asm/mach-ralink/ramips_eth_platform.h>
22
23 #include "devices.h"
24
25 #define RT_N56U_GPIO_LED_POWER          0
26 #define RT_N56U_GPIO_LED_LAN            19
27 #define RT_N56U_GPIO_LED_USB            24
28 #define RT_N56U_GPIO_LED_WAN            27
29 #define RT_N56U_GPIO_BUTTON_RESET       13
30 #define RT_N56U_GPIO_BUTTON_WPS         26
31
32 #define RT_N56U_GPIO_RTL8367_SCK        2
33 #define RT_N56U_GPIO_RTL8367_SDA        1
34
35 #define RT_N56U_KEYS_POLL_INTERVAL      20
36 #define RT_N56U_KEYS_DEBOUNCE_INTERVAL  (3 * RT_N56U_KEYS_POLL_INTERVAL)
37
38 static struct gpio_led rt_n56u_leds_gpio[] __initdata = {
39         {
40                 .name           = "asus:blue:power",
41                 .gpio           = RT_N56U_GPIO_LED_POWER,
42                 .active_low     = 1,
43         },
44         {
45                 .name           = "asus:blue:lan",
46                 .gpio           = RT_N56U_GPIO_LED_LAN,
47                 .active_low     = 1,
48         },
49         {
50                 .name           = "asus:blue:wan",
51                 .gpio           = RT_N56U_GPIO_LED_WAN,
52                 .active_low     = 1,
53         },
54         {
55                 .name           = "asus:blue:usb",
56                 .gpio           = RT_N56U_GPIO_LED_USB,
57                 .active_low     = 1,
58         },
59 };
60
61 static struct gpio_keys_button rt_n56u_gpio_buttons[] __initdata = {
62         {
63                 .desc           = "reset",
64                 .type           = EV_KEY,
65                 .code           = KEY_RESTART,
66                 .debounce_interval = RT_N56U_KEYS_DEBOUNCE_INTERVAL,
67                 .gpio           = RT_N56U_GPIO_BUTTON_RESET,
68                 .active_low     = 1,
69         },
70         {
71                 .desc           = "wps",
72                 .type           = EV_KEY,
73                 .code           = KEY_WPS_BUTTON,
74                 .debounce_interval = RT_N56U_KEYS_DEBOUNCE_INTERVAL,
75                 .gpio           = RT_N56U_GPIO_BUTTON_WPS,
76                 .active_low     = 1,
77         }
78 };
79
80 static struct rtl8367_extif_config rt_n56u_rtl8367_extif1_cfg = {
81         .txdelay = 1,
82         .rxdelay = 0,
83         .mode = RTL8367_EXTIF_MODE_RGMII,
84         .ability = {
85                 .force_mode = 1,
86                 .txpause = 1,
87                 .rxpause = 1,
88                 .link = 1,
89                 .duplex = 1,
90                 .speed = RTL8367_PORT_SPEED_1000,
91         }
92 };
93
94 static struct rtl8367_platform_data rt_n56u_rtl8367_data = {
95         .gpio_sda       = RT_N56U_GPIO_RTL8367_SDA,
96         .gpio_sck       = RT_N56U_GPIO_RTL8367_SCK,
97         .extif1_cfg     = &rt_n56u_rtl8367_extif1_cfg,
98 };
99
100 static struct platform_device rt_n56u_rtl8367_device = {
101         .name           = RTL8367_DRIVER_NAME,
102         .id             = -1,
103         .dev = {
104                 .platform_data  = &rt_n56u_rtl8367_data,
105         }
106 };
107
108 static void __init rt_n56u_init(void)
109 {
110         rt3883_gpio_init(RT3883_GPIO_MODE_I2C |
111                          RT3883_GPIO_MODE_UART0(RT3883_GPIO_MODE_GPIO) |
112                          RT3883_GPIO_MODE_JTAG |
113                          RT3883_GPIO_MODE_PCI(RT3883_GPIO_MODE_PCI_FNC));
114
115         rt3883_register_pflash(0);
116
117         ramips_register_gpio_leds(-1, ARRAY_SIZE(rt_n56u_leds_gpio),
118                                   rt_n56u_leds_gpio);
119
120         ramips_register_gpio_buttons(-1, RT_N56U_KEYS_POLL_INTERVAL,
121                                      ARRAY_SIZE(rt_n56u_gpio_buttons),
122                                      rt_n56u_gpio_buttons);
123
124         platform_device_register(&rt_n56u_rtl8367_device);
125
126         rt3883_register_wlan();
127
128         rt3883_eth_data.speed = SPEED_1000;
129         rt3883_eth_data.duplex = DUPLEX_FULL;
130         rt3883_eth_data.tx_fc = 1;
131         rt3883_eth_data.rx_fc = 1;
132         rt3883_register_ethernet();
133
134         rt3883_register_wdt(false);
135         rt3883_register_usbhost();
136 }
137
138 MIPS_MACHINE(RAMIPS_MACH_RT_N56U, "RT-N56U", "Asus RT-N56U", rt_n56u_init);