New Broadcom BCM63xx codebase, huge thanks to Maxime ;)
[openwrt.git] / target / linux / brcm63xx / patches-2.6.27 / 008-usb_ehci_support.patch
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.
5
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
7 ---
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
19
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
30 endmenu
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
36 obj-y += dev-uart.o
37 obj-y += dev-pcmcia.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
42 new file mode 100644
43 index 0000000..7885405
44 --- /dev/null
45 +++ b/arch/mips/bcm63xx/dev-usb-ehci.c
46 @@ -0,0 +1,50 @@
47 +/*
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
50 + * for more details.
51 + *
52 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
53 + */
54 +
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>
60 +
61 +static struct resource ehci_resources[] = {
62 + {
63 + .start = -1, /* filled at runtime */
64 + .end = -1, /* filled at runtime */
65 + .flags = IORESOURCE_MEM,
66 + },
67 + {
68 + .start = -1, /* filled at runtime */
69 + .flags = IORESOURCE_IRQ,
70 + },
71 +};
72 +
73 +static u64 ehci_dmamask = ~(u32)0;
74 +
75 +static struct platform_device bcm63xx_ehci_device = {
76 + .name = "bcm63xx_ehci",
77 + .id = 0,
78 + .num_resources = ARRAY_SIZE(ehci_resources),
79 + .resource = ehci_resources,
80 + .dev = {
81 + .dma_mask = &ehci_dmamask,
82 + .coherent_dma_mask = 0xffffffff,
83 + },
84 +};
85 +
86 +int __init bcm63xx_ehci_register(void)
87 +{
88 + if (!BCMCPU_IS_6358())
89 + return 0;
90 +
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);
96 +}
97 diff --git a/drivers/usb/host/ehci-bcm63xx.c b/drivers/usb/host/ehci-bcm63xx.c
98 new file mode 100644
99 index 0000000..2fef571
100 --- /dev/null
101 +++ b/drivers/usb/host/ehci-bcm63xx.c
102 @@ -0,0 +1,152 @@
103 +/*
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.
107 + *
108 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
109 + */
110 +
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>
116 +
117 +static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
118 +{
119 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
120 + int retval;
121 +
122 + retval = ehci_halt(ehci);
123 + if (retval)
124 + return retval;
125 +
126 + retval = ehci_init(hcd);
127 + if (retval)
128 + return retval;
129 +
130 + hcd->has_tt = 1;
131 + ehci_reset(ehci);
132 + ehci_port_power(ehci, 0);
133 +
134 + return retval;
135 +}
136 +
137 +
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),
142 +
143 + .irq = ehci_irq,
144 + .flags = HCD_MEMORY | HCD_USB2,
145 +
146 + .reset = ehci_bcm63xx_setup,
147 + .start = ehci_run,
148 + .stop = ehci_stop,
149 + .shutdown = ehci_shutdown,
150 +
151 + .urb_enqueue = ehci_urb_enqueue,
152 + .urb_dequeue = ehci_urb_dequeue,
153 + .endpoint_disable = ehci_endpoint_disable,
154 +
155 + .get_frame_number = ehci_get_frame,
156 +
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,
163 +};
164 +
165 +static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
166 +{
167 + struct resource *res_mem, *res_irq;
168 + struct usb_hcd *hcd;
169 + struct ehci_hcd *ehci;
170 + u32 reg;
171 + int ret;
172 +
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)
176 + return -ENODEV;
177 +
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);
182 +
183 + /* don't ask... */
184 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
185 +
186 + hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
187 + if (!hcd)
188 + return -ENOMEM;
189 + hcd->rsrc_start = res_mem->start;
190 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
191 +
192 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
193 + pr_debug("request_mem_region failed\n");
194 + ret = -EBUSY;
195 + goto out;
196 + }
197 +
198 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
199 + if (!hcd->regs) {
200 + pr_debug("ioremap failed\n");
201 + ret = -EIO;
202 + goto out1;
203 + }
204 +
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);
212 + ehci->sbrn = 0x20;
213 +
214 + ret = usb_add_hcd(hcd, res_irq->start, IRQF_DISABLED);
215 + if (ret)
216 + goto out2;
217 +
218 + platform_set_drvdata(pdev, hcd);
219 + return 0;
220 +
221 +out2:
222 + iounmap(hcd->regs);
223 +out1:
224 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
225 +out:
226 + usb_put_hcd(hcd);
227 + return ret;
228 +}
229 +
230 +static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
231 +{
232 + struct usb_hcd *hcd;
233 +
234 + hcd = platform_get_drvdata(pdev);
235 + usb_remove_hcd(hcd);
236 + iounmap(hcd->regs);
237 + usb_put_hcd(hcd);
238 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
239 + platform_set_drvdata(pdev, NULL);
240 + return 0;
241 +}
242 +
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,
247 + .driver = {
248 + .name = "bcm63xx_ehci",
249 + .owner = THIS_MODULE,
250 + .bus = &platform_bus_type
251 + },
252 +};
253 +
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
261 #endif
262
263 +#ifdef CONFIG_BCM63XX
264 +#include "ehci-bcm63xx.c"
265 +#define PLATFORM_DRIVER ehci_hcd_bcm63xx_driver
266 +#endif
267 +
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)
277 #endif
278
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)
282 +#endif
283 +
284 static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
285 __u32 __iomem * regs)
286 {
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
288 new file mode 100644
289 index 0000000..17fb519
290 --- /dev/null
291 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ehci.h
292 @@ -0,0 +1,6 @@
293 +#ifndef BCM63XX_DEV_USB_EHCI_H_
294 +#define BCM63XX_DEV_USB_EHCI_H_
295 +
296 +int bcm63xx_ehci_register(void);
297 +
298 +#endif /* BCM63XX_DEV_USB_EHCI_H_ */
299 --
300 1.5.4.3
301
This page took 0.061603 seconds and 5 git commands to generate.