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 u64 ath79_usb_dmamask = DMA_BIT_MASK(32);
30 static struct usb_ohci_pdata ath79_ohci_pdata = {
33 static struct usb_ehci_pdata ath79_ehci_pdata_v1 = {
34 .has_synopsys_hc_bug = 1,
37 static struct usb_ehci_pdata ath79_ehci_pdata_v2 = {
42 static void __init ath79_usb_register(const char *name, int id,
43 unsigned long base, unsigned long size,
44 int irq, const void *data,
47 struct resource res[2];
48 struct platform_device *pdev;
50 memset(res, 0, sizeof(res));
52 res[0].flags = IORESOURCE_MEM;
54 res[0].end = base + size - 1;
56 res[1].flags = IORESOURCE_IRQ;
60 pdev = platform_device_register_resndata(NULL, name, id,
65 pr_err("ath79: unable to register USB at %08lx, err=%d\n",
66 base, (int) PTR_ERR(pdev));
70 pdev->dev.dma_mask = &ath79_usb_dmamask;
71 pdev->dev.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_usb_register("ohci-platform", -1,
99 AR71XX_OHCI_BASE, AR71XX_OHCI_SIZE,
101 &ath79_ohci_pdata, sizeof(ath79_ohci_pdata));
103 ath79_usb_register("ehci-platform", -1,
104 AR71XX_EHCI_BASE, AR71XX_EHCI_SIZE,
106 &ath79_ehci_pdata_v1, sizeof(ath79_ehci_pdata_v1));
109 static void __init ar7240_usb_setup(void)
111 void __iomem *usb_ctrl_base;
113 ath79_device_reset_clear(AR7240_RESET_OHCI_DLL);
114 ath79_device_reset_set(AR7240_RESET_USB_HOST);
118 ath79_device_reset_set(AR7240_RESET_OHCI_DLL);
119 ath79_device_reset_clear(AR7240_RESET_USB_HOST);
121 usb_ctrl_base = ioremap(AR7240_USB_CTRL_BASE, AR7240_USB_CTRL_SIZE);
123 /* WAR for HW bug. Here it adjusts the duration between two SOFS */
124 __raw_writel(0x3, usb_ctrl_base + AR71XX_USB_CTRL_REG_FLADJ);
126 iounmap(usb_ctrl_base);
128 ath79_usb_register("ohci-platform", -1,
129 AR7240_OHCI_BASE, AR7240_OHCI_SIZE,
131 &ath79_ohci_pdata, sizeof(ath79_ohci_pdata));
134 static void __init ar724x_usb_setup(void)
136 ath79_device_reset_set(AR724X_RESET_USBSUS_OVERRIDE);
139 ath79_device_reset_clear(AR724X_RESET_USB_HOST);
142 ath79_device_reset_clear(AR724X_RESET_USB_PHY);
145 ath79_usb_register("ehci-platform", -1,
146 AR724X_EHCI_BASE, AR724X_EHCI_SIZE,
148 &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
151 static void __init ar913x_usb_setup(void)
153 ath79_device_reset_set(AR913X_RESET_USBSUS_OVERRIDE);
156 ath79_device_reset_clear(AR913X_RESET_USB_HOST);
159 ath79_device_reset_clear(AR913X_RESET_USB_PHY);
162 ath79_usb_register("ehci-platform", -1,
163 AR913X_EHCI_BASE, AR913X_EHCI_SIZE,
165 &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
168 static void __init ar933x_usb_setup(void)
170 ath79_device_reset_set(AR933X_RESET_USBSUS_OVERRIDE);
173 ath79_device_reset_clear(AR933X_RESET_USB_HOST);
176 ath79_device_reset_clear(AR933X_RESET_USB_PHY);
179 ath79_usb_register("ehci-platform", -1,
180 AR933X_EHCI_BASE, AR933X_EHCI_SIZE,
182 &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
185 static void __init ar934x_usb_setup(void)
189 bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
190 if (bootstrap & AR934X_BOOTSTRAP_USB_MODE_DEVICE)
193 ath79_device_reset_set(AR934X_RESET_USBSUS_OVERRIDE);
196 ath79_device_reset_clear(AR934X_RESET_USB_PHY);
199 ath79_device_reset_clear(AR934X_RESET_USB_PHY_ANALOG);
202 ath79_device_reset_clear(AR934X_RESET_USB_HOST);
205 ath79_usb_register("ehci-platform", -1,
206 AR934X_EHCI_BASE, AR934X_EHCI_SIZE,
208 &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
211 static void __init qca955x_usb_setup(void)
213 ath79_usb_register("ehci-platform", 0,
214 QCA955X_EHCI0_BASE, QCA955X_EHCI_SIZE,
216 &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
218 ath79_usb_register("ehci-platform", 1,
219 QCA955X_EHCI1_BASE, QCA955X_EHCI_SIZE,
221 &ath79_ehci_pdata_v2, sizeof(ath79_ehci_pdata_v2));
224 void __init ath79_register_usb(void)
228 else if (soc_is_ar7240())
230 else if (soc_is_ar7241() || soc_is_ar7242())
232 else if (soc_is_ar913x())
234 else if (soc_is_ar933x())
236 else if (soc_is_ar934x())
238 else if (soc_is_qca955x())