2 * Atheros AR71xx SoC platform devices
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * Parts of this file are based on Atheros' 2.6.15 BSP
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/platform_device.h>
19 #include <linux/serial_8250.h>
21 #include <asm/mips_machine.h>
22 #include <asm/mach-ar71xx/ar71xx.h>
23 #include <asm/mach-ar71xx/platform.h>
26 * OHCI (USB full speed host controller)
28 static struct resource ar71xx_usb_ohci_resources[] = {
30 .start = AR71XX_OHCI_BASE,
31 .end = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1,
32 .flags = IORESOURCE_MEM,
35 .start = AR71XX_MISC_IRQ_OHCI,
36 .end = AR71XX_MISC_IRQ_OHCI,
37 .flags = IORESOURCE_IRQ,
41 static u64 ar71xx_ohci_dmamask = DMA_BIT_MASK(32);
42 static struct platform_device ar71xx_usb_ohci_device = {
43 .name = "ar71xx-ohci",
45 .resource = ar71xx_usb_ohci_resources,
46 .num_resources = ARRAY_SIZE(ar71xx_usb_ohci_resources),
48 .dma_mask = &ar71xx_ohci_dmamask,
49 .coherent_dma_mask = DMA_BIT_MASK(32),
54 * EHCI (USB full speed host controller)
56 static struct resource ar71xx_usb_ehci_resources[] = {
58 .start = AR71XX_EHCI_BASE,
59 .end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1,
60 .flags = IORESOURCE_MEM,
63 .start = AR71XX_CPU_IRQ_USB,
64 .end = AR71XX_CPU_IRQ_USB,
65 .flags = IORESOURCE_IRQ,
69 static u64 ar71xx_ehci_dmamask = DMA_BIT_MASK(32);
70 static struct platform_device ar71xx_usb_ehci_device = {
71 .name = "ar71xx-ehci",
73 .resource = ar71xx_usb_ehci_resources,
74 .num_resources = ARRAY_SIZE(ar71xx_usb_ehci_resources),
76 .dma_mask = &ar71xx_ehci_dmamask,
77 .coherent_dma_mask = DMA_BIT_MASK(32),
81 #define AR71XX_USB_RESET_MASK \
82 (RESET_MODULE_USB_HOST | RESET_MODULE_USB_PHY \
83 | RESET_MODULE_USB_OHCI_DLL)
85 void __init ar71xx_add_device_usb(void)
87 ar71xx_device_stop(AR71XX_USB_RESET_MASK);
89 ar71xx_device_start(AR71XX_USB_RESET_MASK);
91 /* Turning on the Buff and Desc swap bits */
92 ar71xx_usb_ctrl_wr(USB_CTRL_REG_CONFIG, 0xf0000);
94 /* WAR for HW bug. Here it adjusts the duration between two SOFS */
95 ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x20c00);
99 platform_device_register(&ar71xx_usb_ohci_device);
100 platform_device_register(&ar71xx_usb_ehci_device);
103 #ifdef CONFIG_AR71XX_EARLY_SERIAL
104 static void __init ar71xx_add_device_uart(void) {};
106 static struct resource ar71xx_uart_resources[] = {
108 .start = AR71XX_UART_BASE,
109 .end = AR71XX_UART_BASE + AR71XX_UART_SIZE - 1,
110 .flags = IORESOURCE_MEM,
114 #define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
115 static struct plat_serial8250_port ar71xx_uart_data[] = {
117 .mapbase = AR71XX_UART_BASE,
118 .irq = AR71XX_MISC_IRQ_UART,
119 .flags = AR71XX_UART_FLAGS,
120 .iotype = UPIO_MEM32,
123 /* terminating entry */
127 static struct platform_device ar71xx_uart_device = {
128 .name = "serial8250",
129 .id = PLAT8250_DEV_PLATFORM,
130 .resource = ar71xx_uart_resources,
131 .num_resources = ARRAY_SIZE(ar71xx_uart_resources),
133 .platform_data = ar71xx_uart_data
137 static void __init ar71xx_add_device_uart(void)
139 ar71xx_uart_data[0].uartclk = ar71xx_ahb_freq;
140 platform_device_register(&ar71xx_uart_device);
142 #endif /* CONFIG_AR71XX_EARLY_SERIAL */
144 static struct resource ar71xx_eth0_resources[] = {
147 .flags = IORESOURCE_MEM,
148 .start = AR71XX_GE0_BASE,
149 .end = AR71XX_GE0_BASE + AR71XX_GE0_SIZE - 1,
152 .flags = IORESOURCE_MEM,
153 .start = AR71XX_MII_BASE + MII_REG_MII0_CTRL,
154 .end = AR71XX_MII_BASE + MII_REG_MII0_CTRL + 3,
157 .flags = IORESOURCE_IRQ,
158 .start = AR71XX_CPU_IRQ_GE0,
159 .end = AR71XX_CPU_IRQ_GE0,
163 static struct ag71xx_platform_data ar71xx_eth0_data = {
164 .reset_bit = RESET_MODULE_GE0_MAC,
165 .flush_reg = DDR_REG_FLUSH_GE0,
168 static struct platform_device ar71xx_eth0_device = {
171 .resource = ar71xx_eth0_resources,
172 .num_resources = ARRAY_SIZE(ar71xx_eth0_resources),
174 .platform_data = &ar71xx_eth0_data,
178 static struct resource ar71xx_eth1_resources[] = {
181 .flags = IORESOURCE_MEM,
182 .start = AR71XX_GE1_BASE,
183 .end = AR71XX_GE1_BASE + AR71XX_GE1_SIZE - 1,
186 .flags = IORESOURCE_MEM,
187 .start = AR71XX_MII_BASE + MII_REG_MII1_CTRL,
188 .end = AR71XX_MII_BASE + MII_REG_MII1_CTRL + 3,
191 .flags = IORESOURCE_IRQ,
192 .start = AR71XX_CPU_IRQ_GE1,
193 .end = AR71XX_CPU_IRQ_GE1,
197 static struct ag71xx_platform_data ar71xx_eth1_data = {
198 .reset_bit = RESET_MODULE_GE1_MAC,
199 .flush_reg = DDR_REG_FLUSH_GE1,
202 static struct platform_device ar71xx_eth1_device = {
205 .resource = ar71xx_eth1_resources,
206 .num_resources = ARRAY_SIZE(ar71xx_eth1_resources),
208 .platform_data = &ar71xx_eth1_data,
212 void __init ar71xx_add_device_eth(unsigned int id, phy_interface_t phy_if_mode,
215 struct platform_device *pdev;
219 switch (phy_if_mode) {
220 case PHY_INTERFACE_MODE_MII:
221 ar71xx_eth0_data.mii_if = MII0_CTRL_IF_MII;
223 case PHY_INTERFACE_MODE_GMII:
224 ar71xx_eth0_data.mii_if = MII0_CTRL_IF_GMII;
226 case PHY_INTERFACE_MODE_RGMII:
227 ar71xx_eth0_data.mii_if = MII0_CTRL_IF_RGMII;
229 case PHY_INTERFACE_MODE_RMII:
230 ar71xx_eth0_data.mii_if = MII0_CTRL_IF_RMII;
235 ar71xx_eth0_data.phy_if_mode = phy_if_mode;
236 ar71xx_eth0_data.phy_mask = phy_mask;
237 pdev = &ar71xx_eth0_device;
240 switch (phy_if_mode) {
241 case PHY_INTERFACE_MODE_RMII:
242 ar71xx_eth1_data.mii_if = MII1_CTRL_IF_RMII;
244 case PHY_INTERFACE_MODE_RGMII:
245 ar71xx_eth1_data.mii_if = MII1_CTRL_IF_RGMII;
250 ar71xx_eth1_data.phy_if_mode = phy_if_mode;
251 ar71xx_eth1_data.phy_mask = phy_mask;
252 pdev = &ar71xx_eth1_device;
260 platform_device_register(pdev);
263 static struct resource ar71xx_spi_resources[] = {
265 .start = AR71XX_SPI_BASE,
266 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
267 .flags = IORESOURCE_MEM,
271 static struct platform_device ar71xx_spi_device = {
272 .name = "ar71xx-spi",
274 .resource = ar71xx_spi_resources,
275 .num_resources = ARRAY_SIZE(ar71xx_spi_resources),
278 void __init ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
279 struct spi_board_info const *info,
282 ar71xx_gpio_function_enable(GPIO_FUNC_SPI_EN);
284 spi_register_board_info(info, n);
285 ar71xx_spi_device.dev.platform_data = pdata;
286 platform_device_register(&ar71xx_spi_device);
289 static int __init ar71xx_machine_setup(void)
291 ar71xx_print_cmdline();
295 ar71xx_add_device_uart();
297 mips_machine_setup();
301 arch_initcall(ar71xx_machine_setup);