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>
20 #include <linux/usb/ehci_pdriver.h>
21 #include <linux/usb/ohci_pdriver.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
28 static struct resource ath79_ohci_resources
[2];
30 static u64 ath79_ohci_dmamask
= DMA_BIT_MASK(32);
32 static struct usb_ohci_pdata ath79_ohci_pdata
= {
35 static struct platform_device ath79_ohci_device
= {
36 .name
= "ohci-platform",
38 .resource
= ath79_ohci_resources
,
39 .num_resources
= ARRAY_SIZE(ath79_ohci_resources
),
41 .dma_mask
= &ath79_ohci_dmamask
,
42 .coherent_dma_mask
= DMA_BIT_MASK(32),
43 .platform_data
= &ath79_ohci_pdata
,
47 static struct resource ath79_ehci_resources
[2];
49 static u64 ath79_ehci_dmamask
= DMA_BIT_MASK(32);
51 static struct usb_ehci_pdata ath79_ehci_pdata_v1
= {
52 .has_synopsys_hc_bug
= 1,
55 static struct usb_ehci_pdata ath79_ehci_pdata_v2
= {
60 static struct platform_device ath79_ehci_device
= {
61 .name
= "ehci-platform",
63 .resource
= ath79_ehci_resources
,
64 .num_resources
= ARRAY_SIZE(ath79_ehci_resources
),
66 .dma_mask
= &ath79_ehci_dmamask
,
67 .coherent_dma_mask
= DMA_BIT_MASK(32),
71 static void __init
ath79_usb_init_resource(struct resource res
[2],
76 res
[0].flags
= IORESOURCE_MEM
;
78 res
[0].end
= base
+ size
- 1;
80 res
[1].flags
= IORESOURCE_IRQ
;
85 #define AR71XX_USB_RESET_MASK (AR71XX_RESET_USB_HOST | \
86 AR71XX_RESET_USB_PHY | \
87 AR71XX_RESET_USB_OHCI_DLL)
89 static void __init
ath79_usb_setup(void)
91 void __iomem
*usb_ctrl_base
;
93 ath79_device_reset_set(AR71XX_USB_RESET_MASK
);
95 ath79_device_reset_clear(AR71XX_USB_RESET_MASK
);
97 usb_ctrl_base
= ioremap(AR71XX_USB_CTRL_BASE
, AR71XX_USB_CTRL_SIZE
);
99 /* Turning on the Buff and Desc swap bits */
100 __raw_writel(0xf0000, usb_ctrl_base
+ AR71XX_USB_CTRL_REG_CONFIG
);
102 /* WAR for HW bug. Here it adjusts the duration between two SOFS */
103 __raw_writel(0x20c00, usb_ctrl_base
+ AR71XX_USB_CTRL_REG_FLADJ
);
105 iounmap(usb_ctrl_base
);
109 ath79_usb_init_resource(ath79_ohci_resources
, AR71XX_OHCI_BASE
,
110 AR71XX_OHCI_SIZE
, ATH79_MISC_IRQ_OHCI
);
111 platform_device_register(&ath79_ohci_device
);
113 ath79_usb_init_resource(ath79_ehci_resources
, AR71XX_EHCI_BASE
,
114 AR71XX_EHCI_SIZE
, ATH79_CPU_IRQ_USB
);
115 ath79_ehci_device
.dev
.platform_data
= &ath79_ehci_pdata_v1
;
116 platform_device_register(&ath79_ehci_device
);
119 static void __init
ar7240_usb_setup(void)
121 void __iomem
*usb_ctrl_base
;
123 ath79_device_reset_clear(AR7240_RESET_OHCI_DLL
);
124 ath79_device_reset_set(AR7240_RESET_USB_HOST
);
128 ath79_device_reset_set(AR7240_RESET_OHCI_DLL
);
129 ath79_device_reset_clear(AR7240_RESET_USB_HOST
);
131 usb_ctrl_base
= ioremap(AR7240_USB_CTRL_BASE
, AR7240_USB_CTRL_SIZE
);
133 /* WAR for HW bug. Here it adjusts the duration between two SOFS */
134 __raw_writel(0x3, usb_ctrl_base
+ AR71XX_USB_CTRL_REG_FLADJ
);
136 iounmap(usb_ctrl_base
);
138 ath79_usb_init_resource(ath79_ohci_resources
, AR7240_OHCI_BASE
,
139 AR7240_OHCI_SIZE
, ATH79_CPU_IRQ_USB
);
140 platform_device_register(&ath79_ohci_device
);
143 static void __init
ar724x_usb_setup(void)
145 ath79_device_reset_set(AR724X_RESET_USBSUS_OVERRIDE
);
148 ath79_device_reset_clear(AR724X_RESET_USB_HOST
);
151 ath79_device_reset_clear(AR724X_RESET_USB_PHY
);
154 ath79_usb_init_resource(ath79_ehci_resources
, AR724X_EHCI_BASE
,
155 AR724X_EHCI_SIZE
, ATH79_CPU_IRQ_USB
);
156 ath79_ehci_device
.dev
.platform_data
= &ath79_ehci_pdata_v2
;
157 platform_device_register(&ath79_ehci_device
);
160 static void __init
ar913x_usb_setup(void)
162 ath79_device_reset_set(AR913X_RESET_USBSUS_OVERRIDE
);
165 ath79_device_reset_clear(AR913X_RESET_USB_HOST
);
168 ath79_device_reset_clear(AR913X_RESET_USB_PHY
);
171 ath79_usb_init_resource(ath79_ehci_resources
, AR913X_EHCI_BASE
,
172 AR913X_EHCI_SIZE
, ATH79_CPU_IRQ_USB
);
173 ath79_ehci_device
.dev
.platform_data
= &ath79_ehci_pdata_v2
;
174 platform_device_register(&ath79_ehci_device
);
177 static void __init
ar933x_usb_setup(void)
179 ath79_device_reset_set(AR933X_RESET_USBSUS_OVERRIDE
);
182 ath79_device_reset_clear(AR933X_RESET_USB_HOST
);
185 ath79_device_reset_clear(AR933X_RESET_USB_PHY
);
188 ath79_usb_init_resource(ath79_ehci_resources
, AR933X_EHCI_BASE
,
189 AR933X_EHCI_SIZE
, ATH79_CPU_IRQ_USB
);
190 ath79_ehci_device
.dev
.platform_data
= &ath79_ehci_pdata_v2
;
191 platform_device_register(&ath79_ehci_device
);
194 static void __init
ar934x_usb_setup(void)
198 bootstrap
= ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP
);
199 if (bootstrap
& AR934X_BOOTSTRAP_USB_MODE_DEVICE
)
202 ath79_device_reset_set(AR934X_RESET_USBSUS_OVERRIDE
);
205 ath79_device_reset_clear(AR934X_RESET_USB_PHY
);
208 ath79_device_reset_clear(AR934X_RESET_USB_PHY_ANALOG
);
211 ath79_device_reset_clear(AR934X_RESET_USB_HOST
);
214 ath79_usb_init_resource(ath79_ehci_resources
, AR934X_EHCI_BASE
,
215 AR934X_EHCI_SIZE
, ATH79_CPU_IRQ_USB
);
216 ath79_ehci_device
.dev
.platform_data
= &ath79_ehci_pdata_v2
;
217 platform_device_register(&ath79_ehci_device
);
220 void __init
ath79_register_usb(void)
224 else if (soc_is_ar7240())
226 else if (soc_is_ar7241() || soc_is_ar7242())
228 else if (soc_is_ar913x())
230 else if (soc_is_ar933x())
232 else if (soc_is_ar934x())