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