1 From 2940d1996c86c4c4dd7a82214f846d0c0b707165 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Mon, 21 Jul 2008 18:24:42 +0200
4 Subject: [PATCH] [MIPS] BCM63XX: Add USB EHCI support.
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
8 arch/mips/bcm63xx/Kconfig | 2 +
9 arch/mips/bcm63xx/Makefile | 1 +
10 arch/mips/bcm63xx/dev-usb-ehci.c | 50 +++++++
11 drivers/usb/host/ehci-bcm63xx.c | 152 ++++++++++++++++++++
12 drivers/usb/host/ehci-hcd.c | 5 +
13 drivers/usb/host/ehci.h | 5 +
14 .../asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ehci.h | 6 +
15 7 files changed, 221 insertions(+), 0 deletions(-)
16 create mode 100644 arch/mips/bcm63xx/dev-usb-ehci.c
17 create mode 100644 drivers/usb/host/ehci-bcm63xx.c
18 create mode 100644 include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ehci.h
20 diff --git a/arch/mips/bcm63xx/Kconfig b/arch/mips/bcm63xx/Kconfig
21 index f2ddb87..be120f7 100644
22 --- a/arch/mips/bcm63xx/Kconfig
23 +++ b/arch/mips/bcm63xx/Kconfig
24 @@ -14,4 +14,6 @@ config BCM63XX_CPU_6358
25 select USB_ARCH_HAS_OHCI
26 select USB_OHCI_BIG_ENDIAN_DESC
27 select USB_OHCI_BIG_ENDIAN_MMIO
28 + select USB_ARCH_HAS_EHCI
29 + select USB_EHCI_BIG_ENDIAN_MMIO
31 diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
32 index 75f0d54..99e335d 100644
33 --- a/arch/mips/bcm63xx/Makefile
34 +++ b/arch/mips/bcm63xx/Makefile
35 @@ -2,4 +2,5 @@ obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o
38 obj-y += dev-usb-ohci.o
39 +obj-y += dev-usb-ehci.o
40 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
41 diff --git a/arch/mips/bcm63xx/dev-usb-ehci.c b/arch/mips/bcm63xx/dev-usb-ehci.c
43 index 0000000..7885405
45 +++ b/arch/mips/bcm63xx/dev-usb-ehci.c
48 + * This file is subject to the terms and conditions of the GNU General Public
49 + * License. See the file "COPYING" in the main directory of this archive
52 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
55 +#include <linux/init.h>
56 +#include <linux/kernel.h>
57 +#include <linux/platform_device.h>
58 +#include <bcm63xx_cpu.h>
59 +#include <bcm63xx_dev_usb_ehci.h>
61 +static struct resource ehci_resources[] = {
63 + .start = -1, /* filled at runtime */
64 + .end = -1, /* filled at runtime */
65 + .flags = IORESOURCE_MEM,
68 + .start = -1, /* filled at runtime */
69 + .flags = IORESOURCE_IRQ,
73 +static u64 ehci_dmamask = ~(u32)0;
75 +static struct platform_device bcm63xx_ehci_device = {
76 + .name = "bcm63xx_ehci",
78 + .num_resources = ARRAY_SIZE(ehci_resources),
79 + .resource = ehci_resources,
81 + .dma_mask = &ehci_dmamask,
82 + .coherent_dma_mask = 0xffffffff,
86 +int __init bcm63xx_ehci_register(void)
88 + if (!BCMCPU_IS_6358())
91 + ehci_resources[0].start = bcm63xx_regset_address(RSET_EHCI0);
92 + ehci_resources[0].end = ehci_resources[0].start;
93 + ehci_resources[0].end += RSET_EHCI_SIZE - 1;
94 + ehci_resources[1].start = bcm63xx_get_irq_number(IRQ_EHCI0);
95 + return platform_device_register(&bcm63xx_ehci_device);
97 diff --git a/drivers/usb/host/ehci-bcm63xx.c b/drivers/usb/host/ehci-bcm63xx.c
99 index 0000000..2fef571
101 +++ b/drivers/usb/host/ehci-bcm63xx.c
104 + * This file is subject to the terms and conditions of the GNU General Public
105 + * License. See the file "COPYING" in the main directory of this archive
106 + * for more details.
108 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
111 +#include <linux/init.h>
112 +#include <linux/platform_device.h>
113 +#include <bcm63xx_cpu.h>
114 +#include <bcm63xx_regs.h>
115 +#include <bcm63xx_io.h>
117 +static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
119 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
122 + retval = ehci_halt(ehci);
126 + retval = ehci_init(hcd);
132 + ehci_port_power(ehci, 0);
138 +static const struct hc_driver ehci_bcm63xx_hc_driver = {
139 + .description = hcd_name,
140 + .product_desc = "BCM63XX integrated EHCI controller",
141 + .hcd_priv_size = sizeof(struct ehci_hcd),
144 + .flags = HCD_MEMORY | HCD_USB2,
146 + .reset = ehci_bcm63xx_setup,
149 + .shutdown = ehci_shutdown,
151 + .urb_enqueue = ehci_urb_enqueue,
152 + .urb_dequeue = ehci_urb_dequeue,
153 + .endpoint_disable = ehci_endpoint_disable,
155 + .get_frame_number = ehci_get_frame,
157 + .hub_status_data = ehci_hub_status_data,
158 + .hub_control = ehci_hub_control,
159 + .bus_suspend = ehci_bus_suspend,
160 + .bus_resume = ehci_bus_resume,
161 + .relinquish_port = ehci_relinquish_port,
162 + .port_handed_over = ehci_port_handed_over,
165 +static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
167 + struct resource *res_mem, *res_irq;
168 + struct usb_hcd *hcd;
169 + struct ehci_hcd *ehci;
173 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
174 + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
175 + if (!res_mem || !res_irq)
178 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_REG);
179 + reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
180 + reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
181 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_REG);
184 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
186 + hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
189 + hcd->rsrc_start = res_mem->start;
190 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
192 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
193 + pr_debug("request_mem_region failed\n");
198 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
200 + pr_debug("ioremap failed\n");
205 + ehci = hcd_to_ehci(hcd);
206 + ehci->big_endian_mmio = 1;
207 + ehci->big_endian_desc = 0;
208 + ehci->caps = hcd->regs;
209 + ehci->regs = hcd->regs +
210 + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
211 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
214 + ret = usb_add_hcd(hcd, res_irq->start, IRQF_DISABLED);
218 + platform_set_drvdata(pdev, hcd);
222 + iounmap(hcd->regs);
224 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
230 +static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
232 + struct usb_hcd *hcd;
234 + hcd = platform_get_drvdata(pdev);
235 + usb_remove_hcd(hcd);
236 + iounmap(hcd->regs);
238 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
239 + platform_set_drvdata(pdev, NULL);
243 +static struct platform_driver ehci_hcd_bcm63xx_driver = {
244 + .probe = ehci_hcd_bcm63xx_drv_probe,
245 + .remove = __devexit_p(ehci_hcd_bcm63xx_drv_remove),
246 + .shutdown = usb_hcd_platform_shutdown,
248 + .name = "bcm63xx_ehci",
249 + .owner = THIS_MODULE,
250 + .bus = &platform_bus_type
254 +MODULE_ALIAS("platform:bcm63xx_ehci");
255 diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
256 index 8409e07..3230ba3 100644
257 --- a/drivers/usb/host/ehci-hcd.c
258 +++ b/drivers/usb/host/ehci-hcd.c
259 @@ -1040,6 +1040,11 @@ MODULE_LICENSE ("GPL");
260 #define PLATFORM_DRIVER ixp4xx_ehci_driver
263 +#ifdef CONFIG_BCM63XX
264 +#include "ehci-bcm63xx.c"
265 +#define PLATFORM_DRIVER ehci_hcd_bcm63xx_driver
268 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
269 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
270 #error "missing bus glue for ehci-hcd"
271 diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
272 index 5799298..71d0eca 100644
273 --- a/drivers/usb/host/ehci.h
274 +++ b/drivers/usb/host/ehci.h
275 @@ -755,6 +755,11 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
276 #define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
279 +#if defined(CONFIG_MIPS) && defined(CONFIG_BCM63XX)
280 +#define readl_be(addr) __raw_readl((__force unsigned *)addr)
281 +#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
284 static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
285 __u32 __iomem * regs)
287 diff --git a/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ehci.h b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ehci.h
289 index 0000000..17fb519
291 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ehci.h
293 +#ifndef BCM63XX_DEV_USB_EHCI_H_
294 +#define BCM63XX_DEV_USB_EHCI_H_
296 +int bcm63xx_ehci_register(void);
298 +#endif /* BCM63XX_DEV_USB_EHCI_H_ */