2 * Atheros AR7XXX/AR9XXX USB Host Controller device
4 * Copyright (C) 2008-2011 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/irq.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/platform_device.h>
21 #include <asm/mach-ath79/ath79.h>
22 #include <asm/mach-ath79/ar71xx_regs.h>
26 static struct resource ath79_ohci_resources
[] = {
28 /* .start and .end fields are filled dynamically */
29 .flags
= IORESOURCE_MEM
,
32 .start
= ATH79_MISC_IRQ_OHCI
,
33 .end
= ATH79_MISC_IRQ_OHCI
,
34 .flags
= IORESOURCE_IRQ
,
38 static u64 ath79_ohci_dmamask
= DMA_BIT_MASK(32);
39 static struct platform_device ath79_ohci_device
= {
42 .resource
= ath79_ohci_resources
,
43 .num_resources
= ARRAY_SIZE(ath79_ohci_resources
),
45 .dma_mask
= &ath79_ohci_dmamask
,
46 .coherent_dma_mask
= DMA_BIT_MASK(32),
50 static struct resource ath79_ehci_resources
[] = {
52 /* .start and .end fields are filled dynamically */
53 .flags
= IORESOURCE_MEM
,
56 .start
= ATH79_CPU_IRQ_USB
,
57 .end
= ATH79_CPU_IRQ_USB
,
58 .flags
= IORESOURCE_IRQ
,
62 static u64 ath79_ehci_dmamask
= DMA_BIT_MASK(32);
63 static struct platform_device ath79_ehci_device
= {
66 .resource
= ath79_ehci_resources
,
67 .num_resources
= ARRAY_SIZE(ath79_ehci_resources
),
69 .dma_mask
= &ath79_ehci_dmamask
,
70 .coherent_dma_mask
= DMA_BIT_MASK(32),
74 #define AR71XX_USB_RESET_MASK (AR71XX_RESET_USB_HOST | \
75 AR71XX_RESET_USB_PHY | \
76 AR71XX_RESET_USB_OHCI_DLL)
78 static void __init
ath79_usb_setup(void)
80 void __iomem
*usb_ctrl_base
;
82 ath79_device_reset_set(AR71XX_USB_RESET_MASK
);
84 ath79_device_reset_clear(AR71XX_USB_RESET_MASK
);
86 usb_ctrl_base
= ioremap(AR71XX_USB_CTRL_BASE
, AR71XX_USB_CTRL_SIZE
);
88 /* Turning on the Buff and Desc swap bits */
89 __raw_writel(0xf0000, usb_ctrl_base
+ AR71XX_USB_CTRL_REG_CONFIG
);
91 /* WAR for HW bug. Here it adjusts the duration between two SOFS */
92 __raw_writel(0x20c00, usb_ctrl_base
+ AR71XX_USB_CTRL_REG_FLADJ
);
94 iounmap(usb_ctrl_base
);
98 ath79_ohci_resources
[0].start
= AR71XX_OHCI_BASE
;
99 ath79_ohci_resources
[0].end
= AR71XX_OHCI_BASE
+ AR71XX_OHCI_SIZE
- 1;
100 platform_device_register(&ath79_ohci_device
);
102 ath79_ehci_resources
[0].start
= AR71XX_EHCI_BASE
;
103 ath79_ehci_resources
[0].end
= AR71XX_EHCI_BASE
+ AR71XX_EHCI_SIZE
- 1;
104 ath79_ehci_device
.name
= "ar71xx-ehci";
105 platform_device_register(&ath79_ehci_device
);
108 static void __init
ar7240_usb_setup(void)
110 void __iomem
*usb_ctrl_base
;
112 ath79_device_reset_clear(AR7240_RESET_OHCI_DLL
);
113 ath79_device_reset_set(AR7240_RESET_USB_HOST
);
117 ath79_device_reset_set(AR7240_RESET_OHCI_DLL
);
118 ath79_device_reset_clear(AR7240_RESET_USB_HOST
);
120 usb_ctrl_base
= ioremap(AR7240_USB_CTRL_BASE
, AR7240_USB_CTRL_SIZE
);
122 /* WAR for HW bug. Here it adjusts the duration between two SOFS */
123 __raw_writel(0x3, usb_ctrl_base
+ AR71XX_USB_CTRL_REG_FLADJ
);
125 iounmap(usb_ctrl_base
);
127 ath79_ohci_resources
[0].start
= AR7240_OHCI_BASE
;
128 ath79_ohci_resources
[0].end
= AR7240_OHCI_BASE
+ AR7240_OHCI_SIZE
- 1;
129 platform_device_register(&ath79_ohci_device
);
132 static void __init
ar724x_usb_setup(void)
134 ath79_device_reset_set(AR724X_RESET_USBSUS_OVERRIDE
);
137 ath79_device_reset_clear(AR724X_RESET_USB_HOST
);
140 ath79_device_reset_clear(AR724X_RESET_USB_PHY
);
143 ath79_ehci_resources
[0].start
= AR724X_EHCI_BASE
;
144 ath79_ehci_resources
[0].end
= AR724X_EHCI_BASE
+ AR724X_EHCI_SIZE
- 1;
145 ath79_ehci_device
.name
= "ar724x-ehci";
146 platform_device_register(&ath79_ehci_device
);
149 static void __init
ar913x_usb_setup(void)
151 ath79_device_reset_set(AR913X_RESET_USBSUS_OVERRIDE
);
154 ath79_device_reset_clear(AR913X_RESET_USB_HOST
);
157 ath79_device_reset_clear(AR913X_RESET_USB_PHY
);
160 ath79_ehci_resources
[0].start
= AR913X_EHCI_BASE
;
161 ath79_ehci_resources
[0].end
= AR913X_EHCI_BASE
+ AR913X_EHCI_SIZE
- 1;
162 ath79_ehci_device
.name
= "ar913x-ehci";
163 platform_device_register(&ath79_ehci_device
);
166 static void __init
ar933x_usb_setup(void)
168 ath79_device_reset_set(AR933X_RESET_USBSUS_OVERRIDE
);
171 ath79_device_reset_clear(AR933X_RESET_USB_HOST
);
174 ath79_device_reset_clear(AR933X_RESET_USB_PHY
);
177 ath79_ehci_resources
[0].start
= AR933X_EHCI_BASE
;
178 ath79_ehci_resources
[0].end
= AR933X_EHCI_BASE
+ AR933X_EHCI_SIZE
- 1;
179 ath79_ehci_device
.name
= "ar933x-ehci";
180 platform_device_register(&ath79_ehci_device
);
183 void __init
ath79_register_usb(void)
187 else if (soc_is_ar7240())
189 else if (soc_is_ar7241() || soc_is_ar7242())
191 else if (soc_is_ar913x())
193 else if (soc_is_ar933x())