1 From 0f7d8ff44dc9e7048c141e6589bb590438cfc656 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Fri, 10 Jun 2011 19:15:47 +0200
4 Subject: [PATCH 22/57] ehci: add driver for bcm63xx integrated controller.
7 drivers/usb/host/Kconfig | 10 ++-
8 drivers/usb/host/ehci-bcm63xx.c | 185 +++++++++++++++++++++++++++++++++++++++
9 drivers/usb/host/ehci-hcd.c | 5 +
10 3 files changed, 199 insertions(+), 1 deletions(-)
11 create mode 100644 drivers/usb/host/ehci-bcm63xx.c
13 --- a/drivers/usb/host/Kconfig
14 +++ b/drivers/usb/host/Kconfig
15 @@ -106,7 +106,7 @@ config USB_EHCI_BIG_ENDIAN_MMIO
16 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \
17 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
18 PPC_MPC512x || CPU_CAVIUM_OCTEON || \
19 - PMC_MSP || SPARC_LEON)
20 + PMC_MSP || SPARC_LEON || BCM63XX)
23 config USB_EHCI_BIG_ENDIAN_DESC
24 @@ -129,6 +129,14 @@ config XPS_USB_HCD_XILINX
25 config USB_FSL_MPH_DR_OF
28 +config USB_EHCI_BCM63XX
29 + bool "Support for Broadcom 63xx on-chip EHCI USB controller"
30 + depends on USB_EHCI_HCD && BCM63XX
31 + select USB_EHCI_BIG_ENDIAN_MMIO
33 + Enables support for the on-chip EHCI controller on
34 + BCM6358 and later chips.
37 bool "Support for Freescale on-chip EHCI USB controller"
38 depends on USB_EHCI_HCD && FSL_SOC
40 +++ b/drivers/usb/host/ehci-bcm63xx.c
43 + * This file is subject to the terms and conditions of the GNU General Public
44 + * License. See the file "COPYING" in the main directory of this archive
47 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
50 +#include <linux/init.h>
51 +#include <linux/clk.h>
52 +#include <linux/platform_device.h>
53 +#include <bcm63xx_cpu.h>
54 +#include <bcm63xx_regs.h>
55 +#include <bcm63xx_io.h>
57 +static struct clk *usb_host_clock;
59 +static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
61 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
64 + retval = ehci_halt(ehci);
68 + retval = ehci_init(hcd);
73 + ehci_port_power(ehci, 0);
79 +static const struct hc_driver ehci_bcm63xx_hc_driver = {
80 + .description = hcd_name,
81 + .product_desc = "BCM63XX integrated EHCI controller",
82 + .hcd_priv_size = sizeof(struct ehci_hcd),
85 + .flags = HCD_MEMORY | HCD_USB2,
87 + .reset = ehci_bcm63xx_setup,
90 + .shutdown = ehci_shutdown,
92 + .urb_enqueue = ehci_urb_enqueue,
93 + .urb_dequeue = ehci_urb_dequeue,
94 + .endpoint_disable = ehci_endpoint_disable,
96 + .get_frame_number = ehci_get_frame,
98 + .hub_status_data = ehci_hub_status_data,
99 + .hub_control = ehci_hub_control,
100 + .bus_suspend = ehci_bus_suspend,
101 + .bus_resume = ehci_bus_resume,
102 + .relinquish_port = ehci_relinquish_port,
103 + .port_handed_over = ehci_port_handed_over,
106 +static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
108 + struct resource *res_mem;
109 + struct usb_hcd *hcd;
110 + struct ehci_hcd *ehci;
115 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
116 + irq = platform_get_irq(pdev, 0);;
117 + if (!res_mem || irq < 0)
120 + /* enable USB host clock */
121 + clk = clk_get(&pdev->dev, "usbh");
126 + usb_host_clock = clk;
129 + if (BCMCPU_IS_6358()) {
130 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6358_REG);
131 + reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
132 + reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
133 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6358_REG);
136 + * The magic value comes for the original vendor BSP
137 + * and is needed for USB to work. Datasheet does not
138 + * help, so the magic value is used as-is.
140 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020,
141 + USBH_PRIV_TEST_6358_REG);
143 + } else if (BCMCPU_IS_6368()) {
145 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6368_REG);
146 + reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
147 + reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
148 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6368_REG);
150 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SETUP_6368_REG);
151 + reg |= USBH_PRIV_SETUP_IOC_MASK;
152 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SETUP_6368_REG);
155 + hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
158 + hcd->rsrc_start = res_mem->start;
159 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
161 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
162 + pr_debug("request_mem_region failed\n");
167 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
169 + pr_debug("ioremap failed\n");
174 + ehci = hcd_to_ehci(hcd);
175 + ehci->big_endian_mmio = 1;
176 + ehci->big_endian_desc = 0;
177 + ehci->caps = hcd->regs;
178 + ehci->regs = hcd->regs +
179 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
180 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
183 + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
187 + platform_set_drvdata(pdev, hcd);
191 + iounmap(hcd->regs);
193 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
199 +static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
201 + struct usb_hcd *hcd;
203 + hcd = platform_get_drvdata(pdev);
204 + usb_remove_hcd(hcd);
205 + iounmap(hcd->regs);
207 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
208 + if (usb_host_clock) {
209 + clk_disable(usb_host_clock);
210 + clk_put(usb_host_clock);
212 + platform_set_drvdata(pdev, NULL);
216 +static struct platform_driver ehci_hcd_bcm63xx_driver = {
217 + .probe = ehci_hcd_bcm63xx_drv_probe,
218 + .remove = __devexit_p(ehci_hcd_bcm63xx_drv_remove),
219 + .shutdown = usb_hcd_platform_shutdown,
221 + .name = "bcm63xx_ehci",
222 + .owner = THIS_MODULE,
226 +MODULE_ALIAS("platform:bcm63xx_ehci");
227 --- a/drivers/usb/host/ehci-hcd.c
228 +++ b/drivers/usb/host/ehci-hcd.c
229 @@ -1376,6 +1376,11 @@ MODULE_LICENSE ("GPL");
230 #define PLATFORM_DRIVER ehci_mv_driver
233 +#ifdef CONFIG_USB_EHCI_BCM63XX
234 +#include "ehci-bcm63xx.c"
235 +#define PLATFORM_DRIVER ehci_hcd_bcm63xx_driver
238 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
239 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
240 !defined(XILINX_OF_PLATFORM_DRIVER)