1 From 7b510c5754d3c46e1287803f51e8ecb177414438 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Fri, 10 Jun 2011 19:14:30 +0200
4 Subject: [PATCH 23/63] ohci: add driver for bcm63xx integrated controller.
7 drivers/usb/host/Kconfig | 9 ++
8 drivers/usb/host/ohci-bcm63xx.c | 175 +++++++++++++++++++++++++++++++++++++++
9 drivers/usb/host/ohci-hcd.c | 5 +
10 drivers/usb/host/ohci.h | 2 +-
11 4 files changed, 190 insertions(+), 1 deletions(-)
12 create mode 100644 drivers/usb/host/ohci-bcm63xx.c
14 --- a/drivers/usb/host/Kconfig
15 +++ b/drivers/usb/host/Kconfig
16 @@ -306,6 +306,15 @@ config USB_OHCI_HCD
17 To compile this driver as a module, choose M here: the
18 module will be called ohci-hcd.
20 +config USB_OHCI_BCM63XX
21 + bool "Support for Broadcom 63xx on-chip OHCI USB controller"
22 + depends on USB_OHCI_HCD && BCM63XX
23 + select USB_OHCI_BIG_ENDIAN_DESC
24 + select USB_OHCI_BIG_ENDIAN_MMIO
26 + Enables support for the on-chip OHCI controller on
29 config USB_OHCI_HCD_OMAP1
30 bool "OHCI support for OMAP1/2 chips"
31 depends on USB_OHCI_HCD && ARCH_OMAP1
33 +++ b/drivers/usb/host/ohci-bcm63xx.c
36 + * This file is subject to the terms and conditions of the GNU General Public
37 + * License. See the file "COPYING" in the main directory of this archive
40 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
43 +#include <linux/init.h>
44 +#include <linux/clk.h>
45 +#include <linux/platform_device.h>
46 +#include <bcm63xx_cpu.h>
47 +#include <bcm63xx_regs.h>
48 +#include <bcm63xx_io.h>
50 +static struct clk *usb_host_clock;
52 +static int __devinit ohci_bcm63xx_start(struct usb_hcd *hcd)
54 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
57 + ohci->num_ports = 1;
59 + ret = ohci_init(ohci);
63 + /* FIXME: autodetected port 2 is shared with USB slave */
65 + ret = ohci_run(ohci);
67 + dev_err(hcd->self.controller, "can't start %s\n",
68 + hcd->self.bus_name);
75 +static const struct hc_driver ohci_bcm63xx_hc_driver = {
76 + .description = hcd_name,
77 + .product_desc = "BCM63XX integrated OHCI controller",
78 + .hcd_priv_size = sizeof(struct ohci_hcd),
81 + .flags = HCD_USB11 | HCD_MEMORY,
82 + .start = ohci_bcm63xx_start,
84 + .shutdown = ohci_shutdown,
85 + .urb_enqueue = ohci_urb_enqueue,
86 + .urb_dequeue = ohci_urb_dequeue,
87 + .endpoint_disable = ohci_endpoint_disable,
88 + .get_frame_number = ohci_get_frame,
89 + .hub_status_data = ohci_hub_status_data,
90 + .hub_control = ohci_hub_control,
91 + .start_port_reset = ohci_start_port_reset,
94 +static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
96 + struct resource *res_mem;
97 + struct usb_hcd *hcd;
98 + struct ohci_hcd *ohci;
103 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
104 + irq = platform_get_irq(pdev, 0);
105 + if (!res_mem || irq < 0)
108 + /* enable USB host clock */
109 + clk = clk_get(&pdev->dev, "usbh");
114 + usb_host_clock = clk;
117 + if (BCMCPU_IS_6348())
118 + bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
119 + else if (BCMCPU_IS_6358()) {
120 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6358_REG);
121 + reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
122 + reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
123 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6358_REG);
125 + * The magic value comes for the original vendor BSP
126 + * and is needed for USB to work. Datasheet does not
127 + * help, so the magic value is used as-is.
129 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020,
130 + USBH_PRIV_TEST_6358_REG);
132 + } else if (BCMCPU_IS_6368()) {
133 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6368_REG);
134 + reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
135 + reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
136 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6368_REG);
138 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SETUP_6368_REG);
139 + reg |= USBH_PRIV_SETUP_IOC_MASK;
140 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SETUP_6368_REG);
143 + hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
146 + hcd->rsrc_start = res_mem->start;
147 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
149 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
150 + pr_debug("request_mem_region failed\n");
155 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
157 + pr_debug("ioremap failed\n");
162 + ohci = hcd_to_ohci(hcd);
163 + ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC |
164 + OHCI_QUIRK_FRAME_NO;
165 + ohci_hcd_init(ohci);
167 + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
171 + platform_set_drvdata(pdev, hcd);
175 + iounmap(hcd->regs);
177 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
183 +static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
185 + struct usb_hcd *hcd;
187 + hcd = platform_get_drvdata(pdev);
188 + usb_remove_hcd(hcd);
189 + iounmap(hcd->regs);
191 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
192 + if (usb_host_clock) {
193 + clk_disable(usb_host_clock);
194 + clk_put(usb_host_clock);
196 + platform_set_drvdata(pdev, NULL);
200 +static struct platform_driver ohci_hcd_bcm63xx_driver = {
201 + .probe = ohci_hcd_bcm63xx_drv_probe,
202 + .remove = __devexit_p(ohci_hcd_bcm63xx_drv_remove),
203 + .shutdown = usb_hcd_platform_shutdown,
205 + .name = "bcm63xx_ohci",
206 + .owner = THIS_MODULE,
210 +MODULE_ALIAS("platform:bcm63xx_ohci");
211 --- a/drivers/usb/host/ohci-hcd.c
212 +++ b/drivers/usb/host/ohci-hcd.c
213 @@ -1120,6 +1120,11 @@ MODULE_LICENSE ("GPL");
214 #define OHCI_PLATFORM_DRIVER ohci_platform_driver
217 +#ifdef CONFIG_USB_OHCI_BCM63XX
218 +#include "ohci-bcm63xx.c"
219 +#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
222 #if !defined(PCI_DRIVER) && \
223 !defined(PLATFORM_DRIVER) && \
224 !defined(OMAP1_PLATFORM_DRIVER) && \
225 --- a/drivers/usb/host/ohci.h
226 +++ b/drivers/usb/host/ohci.h
227 @@ -647,7 +647,7 @@ static inline u32 hc32_to_cpup (const st
228 * some big-endian SOC implementations. Same thing happens with PSW access.
231 -#ifdef CONFIG_PPC_MPC52xx
232 +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_BCM63XX)
233 #define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
235 #define big_endian_frame_no_quirk(ohci) 0