1 From f7416412febd7efc1d33c7506c81265719368667 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Mon, 21 Jul 2008 14:58:19 +0200
4 Subject: [PATCH] [MIPS] BCM63XX: Add USB OHCI support.
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
8 arch/mips/bcm63xx/Kconfig | 6 +
9 arch/mips/bcm63xx/Makefile | 1 +
10 arch/mips/bcm63xx/dev-usb-ohci.c | 50 ++++++
11 drivers/usb/host/ohci-bcm63xx.c | 159 ++++++++++++++++++++
12 drivers/usb/host/ohci-hcd.c | 5 +
13 drivers/usb/host/ohci.h | 7 +-
14 .../asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h | 6 +
15 7 files changed, 233 insertions(+), 1 deletions(-)
16 create mode 100644 arch/mips/bcm63xx/dev-usb-ohci.c
17 create mode 100644 drivers/usb/host/ohci-bcm63xx.c
18 create mode 100644 include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
20 diff --git a/arch/mips/bcm63xx/Kconfig b/arch/mips/bcm63xx/Kconfig
21 index 7ca370a..f2ddb87 100644
22 --- a/arch/mips/bcm63xx/Kconfig
23 +++ b/arch/mips/bcm63xx/Kconfig
24 @@ -4,8 +4,14 @@ menu "CPU support"
25 config BCM63XX_CPU_6348
26 bool "support 6348 CPU"
28 + select USB_ARCH_HAS_OHCI
29 + select USB_OHCI_BIG_ENDIAN_DESC
30 + select USB_OHCI_BIG_ENDIAN_MMIO
32 config BCM63XX_CPU_6358
33 bool "support 6358 CPU"
35 + select USB_ARCH_HAS_OHCI
36 + select USB_OHCI_BIG_ENDIAN_DESC
37 + select USB_OHCI_BIG_ENDIAN_MMIO
39 diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
40 index 456e915..75f0d54 100644
41 --- a/arch/mips/bcm63xx/Makefile
42 +++ b/arch/mips/bcm63xx/Makefile
44 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o
47 +obj-y += dev-usb-ohci.o
48 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
49 diff --git a/arch/mips/bcm63xx/dev-usb-ohci.c b/arch/mips/bcm63xx/dev-usb-ohci.c
51 index 0000000..377e67c
53 +++ b/arch/mips/bcm63xx/dev-usb-ohci.c
56 + * This file is subject to the terms and conditions of the GNU General Public
57 + * License. See the file "COPYING" in the main directory of this archive
60 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
63 +#include <linux/init.h>
64 +#include <linux/kernel.h>
65 +#include <linux/platform_device.h>
66 +#include <bcm63xx_cpu.h>
67 +#include <bcm63xx_dev_usb_ohci.h>
69 +static struct resource ohci_resources[] = {
71 + .start = -1, /* filled at runtime */
72 + .end = -1, /* filled at runtime */
73 + .flags = IORESOURCE_MEM,
76 + .start = -1, /* filled at runtime */
77 + .flags = IORESOURCE_IRQ,
81 +static u64 ohci_dmamask = ~(u32)0;
83 +static struct platform_device bcm63xx_ohci_device = {
84 + .name = "bcm63xx_ohci",
86 + .num_resources = ARRAY_SIZE(ohci_resources),
87 + .resource = ohci_resources,
89 + .dma_mask = &ohci_dmamask,
90 + .coherent_dma_mask = 0xffffffff,
94 +int __init bcm63xx_ohci_register(void)
96 + if (!BCMCPU_IS_6348() && !BCMCPU_IS_6358())
99 + ohci_resources[0].start = bcm63xx_regset_address(RSET_OHCI0);
100 + ohci_resources[0].end = ohci_resources[0].start;
101 + ohci_resources[0].end += RSET_OHCI_SIZE - 1;
102 + ohci_resources[1].start = bcm63xx_get_irq_number(IRQ_OHCI0);
103 + return platform_device_register(&bcm63xx_ohci_device);
105 diff --git a/drivers/usb/host/ohci-bcm63xx.c b/drivers/usb/host/ohci-bcm63xx.c
107 index 0000000..08807d9
109 +++ b/drivers/usb/host/ohci-bcm63xx.c
112 + * This file is subject to the terms and conditions of the GNU General Public
113 + * License. See the file "COPYING" in the main directory of this archive
114 + * for more details.
116 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
119 +#include <linux/init.h>
120 +#include <linux/clk.h>
121 +#include <linux/platform_device.h>
122 +#include <bcm63xx_cpu.h>
123 +#include <bcm63xx_regs.h>
124 +#include <bcm63xx_io.h>
126 +static struct clk *usb_host_clock;
128 +static int __devinit ohci_bcm63xx_start(struct usb_hcd *hcd)
130 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
133 + ret = ohci_init(ohci);
137 + /* FIXME: autodetected port 2 is shared with USB slave */
139 + ret = ohci_run(ohci);
141 + err("can't start %s", hcd->self.bus_name);
148 +static const struct hc_driver ohci_bcm63xx_hc_driver = {
149 + .description = hcd_name,
150 + .product_desc = "BCM63XX integrated OHCI controller",
151 + .hcd_priv_size = sizeof(struct ohci_hcd),
154 + .flags = HCD_USB11 | HCD_MEMORY,
155 + .start = ohci_bcm63xx_start,
157 + .shutdown = ohci_shutdown,
158 + .urb_enqueue = ohci_urb_enqueue,
159 + .urb_dequeue = ohci_urb_dequeue,
160 + .endpoint_disable = ohci_endpoint_disable,
161 + .get_frame_number = ohci_get_frame,
162 + .hub_status_data = ohci_hub_status_data,
163 + .hub_control = ohci_hub_control,
164 + .start_port_reset = ohci_start_port_reset,
167 +static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
169 + struct resource *res_mem, *res_irq;
170 + struct usb_hcd *hcd;
171 + struct ohci_hcd *ohci;
175 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
176 + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
177 + if (!res_mem || !res_irq)
180 + if (BCMCPU_IS_6348()) {
182 + /* enable USB host clock */
183 + clk = clk_get(&pdev->dev, "usbh");
188 + usb_host_clock = clk;
189 + bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
191 + } else if (BCMCPU_IS_6358()) {
192 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_REG);
193 + reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
194 + reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
195 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_REG);
197 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
201 + hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
204 + hcd->rsrc_start = res_mem->start;
205 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
207 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
208 + pr_debug("request_mem_region failed\n");
213 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
215 + pr_debug("ioremap failed\n");
220 + ohci = hcd_to_ohci(hcd);
221 + ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC |
222 + OHCI_QUIRK_FRAME_NO;
223 + ohci_hcd_init(ohci);
225 + ret = usb_add_hcd(hcd, res_irq->start, IRQF_DISABLED);
229 + platform_set_drvdata(pdev, hcd);
233 + iounmap(hcd->regs);
235 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
241 +static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
243 + struct usb_hcd *hcd;
245 + hcd = platform_get_drvdata(pdev);
246 + usb_remove_hcd(hcd);
247 + iounmap(hcd->regs);
249 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
250 + if (usb_host_clock) {
251 + clk_disable(usb_host_clock);
252 + clk_put(usb_host_clock);
254 + platform_set_drvdata(pdev, NULL);
258 +static struct platform_driver ohci_hcd_bcm63xx_driver = {
259 + .probe = ohci_hcd_bcm63xx_drv_probe,
260 + .remove = __devexit_p(ohci_hcd_bcm63xx_drv_remove),
261 + .shutdown = usb_hcd_platform_shutdown,
263 + .name = "bcm63xx_ohci",
264 + .owner = THIS_MODULE,
265 + .bus = &platform_bus_type
269 +MODULE_ALIAS("platform:bcm63xx_ohci");
270 diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
271 index 8990196..7e360ef 100644
272 --- a/drivers/usb/host/ohci-hcd.c
273 +++ b/drivers/usb/host/ohci-hcd.c
274 @@ -1050,6 +1050,11 @@ MODULE_LICENSE ("GPL");
275 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
278 +#ifdef CONFIG_BCM63XX
279 +#include "ohci-bcm63xx.c"
280 +#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
283 #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
284 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
285 defined(CONFIG_CPU_SUBTYPE_SH7763)
286 diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
287 index faf622e..947e240 100644
288 --- a/drivers/usb/host/ohci.h
289 +++ b/drivers/usb/host/ohci.h
290 @@ -549,6 +549,11 @@ static inline struct usb_hcd *ohci_to_hcd (const struct ohci_hcd *ohci)
291 #define writel_be(val, addr) out_be32((__force unsigned *)addr, val)
294 +#if defined(CONFIG_MIPS) && defined(CONFIG_BCM63XX)
295 +#define readl_be(addr) __raw_readl((__force unsigned *)addr)
296 +#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
299 static inline unsigned int _ohci_readl (const struct ohci_hcd *ohci,
300 __hc32 __iomem * regs)
302 @@ -654,7 +659,7 @@ static inline u32 hc32_to_cpup (const struct ohci_hcd *ohci, const __hc32 *x)
303 * some big-endian SOC implementations. Same thing happens with PSW access.
306 -#ifdef CONFIG_PPC_MPC52xx
307 +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_BCM63XX)
308 #define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
310 #define big_endian_frame_no_quirk(ohci) 0
311 diff --git a/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
313 index 0000000..518a04d
315 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
317 +#ifndef BCM63XX_DEV_USB_OHCI_H_
318 +#define BCM63XX_DEV_USB_OHCI_H_
320 +int bcm63xx_ohci_register(void);
322 +#endif /* BCM63XX_DEV_USB_OHCI_H_ */