969c3b78a4f5cb729abffe60fe836eb4c699ef54
[openwrt.git] / target / linux / brcm63xx / patches-3.3 / 011-add_bcm63xx_ehci_controller.patch
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.
5
6 ---
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
12
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)
21 default y
22
23 config USB_EHCI_BIG_ENDIAN_DESC
24 @@ -129,6 +129,14 @@ config XPS_USB_HCD_XILINX
25 config USB_FSL_MPH_DR_OF
26 tristate
27
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
32 + ---help---
33 + Enables support for the on-chip EHCI controller on
34 + BCM6358 and later chips.
35 +
36 config USB_EHCI_FSL
37 bool "Support for Freescale PPC on-chip EHCI USB controller"
38 depends on USB_EHCI_HCD && FSL_SOC
39 --- /dev/null
40 +++ b/drivers/usb/host/ehci-bcm63xx.c
41 @@ -0,0 +1,185 @@
42 +/*
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
45 + * for more details.
46 + *
47 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
48 + */
49 +
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>
56 +
57 +static struct clk *usb_host_clock;
58 +
59 +static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
60 +{
61 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
62 + int retval;
63 +
64 + retval = ehci_halt(ehci);
65 + if (retval)
66 + return retval;
67 +
68 + retval = ehci_init(hcd);
69 + if (retval)
70 + return retval;
71 +
72 + ehci_reset(ehci);
73 + ehci_port_power(ehci, 0);
74 +
75 + return retval;
76 +}
77 +
78 +
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),
83 +
84 + .irq = ehci_irq,
85 + .flags = HCD_MEMORY | HCD_USB2,
86 +
87 + .reset = ehci_bcm63xx_setup,
88 + .start = ehci_run,
89 + .stop = ehci_stop,
90 + .shutdown = ehci_shutdown,
91 +
92 + .urb_enqueue = ehci_urb_enqueue,
93 + .urb_dequeue = ehci_urb_dequeue,
94 + .endpoint_disable = ehci_endpoint_disable,
95 +
96 + .get_frame_number = ehci_get_frame,
97 +
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,
104 +};
105 +
106 +static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
107 +{
108 + struct resource *res_mem;
109 + struct usb_hcd *hcd;
110 + struct ehci_hcd *ehci;
111 + struct clk *clk;
112 + u32 reg;
113 + int ret, irq;
114 +
115 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
116 + irq = platform_get_irq(pdev, 0);;
117 + if (!res_mem || irq < 0)
118 + return -ENODEV;
119 +
120 + /* enable USB host clock */
121 + clk = clk_get(&pdev->dev, "usbh");
122 + if (IS_ERR(clk))
123 + return -ENODEV;
124 +
125 + clk_enable(clk);
126 + usb_host_clock = clk;
127 + msleep(100);
128 +
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);
134 +
135 + /*
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.
139 + */
140 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020,
141 + USBH_PRIV_TEST_6358_REG);
142 +
143 + } else if (BCMCPU_IS_6368()) {
144 +
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);
149 +
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);
153 + }
154 +
155 + hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
156 + if (!hcd)
157 + return -ENOMEM;
158 + hcd->rsrc_start = res_mem->start;
159 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
160 +
161 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
162 + pr_debug("request_mem_region failed\n");
163 + ret = -EBUSY;
164 + goto out;
165 + }
166 +
167 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
168 + if (!hcd->regs) {
169 + pr_debug("ioremap failed\n");
170 + ret = -EIO;
171 + goto out1;
172 + }
173 +
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);
181 + ehci->sbrn = 0x20;
182 +
183 + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
184 + if (ret)
185 + goto out2;
186 +
187 + platform_set_drvdata(pdev, hcd);
188 + return 0;
189 +
190 +out2:
191 + iounmap(hcd->regs);
192 +out1:
193 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194 +out:
195 + usb_put_hcd(hcd);
196 + return ret;
197 +}
198 +
199 +static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
200 +{
201 + struct usb_hcd *hcd;
202 +
203 + hcd = platform_get_drvdata(pdev);
204 + usb_remove_hcd(hcd);
205 + iounmap(hcd->regs);
206 + usb_put_hcd(hcd);
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);
211 + }
212 + platform_set_drvdata(pdev, NULL);
213 + return 0;
214 +}
215 +
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,
220 + .driver = {
221 + .name = "bcm63xx_ehci",
222 + .owner = THIS_MODULE,
223 + },
224 +};
225 +
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
231 #endif
232
233 +#ifdef CONFIG_USB_EHCI_BCM63XX
234 +#include "ehci-bcm63xx.c"
235 +#define PLATFORM_DRIVER ehci_hcd_bcm63xx_driver
236 +#endif
237 +
238 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
239 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
240 !defined(XILINX_OF_PLATFORM_DRIVER)
This page took 0.051101 seconds and 3 git commands to generate.