Change order of module startup to force USB2 before USB1.1
[openwrt.git] / target / linux / brcm63xx / patches-2.6.27 / 007-usb_ohci_support.patch
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.
5
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
7 ---
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
19
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"
27 select HW_HAS_PCI
28 + select USB_ARCH_HAS_OHCI
29 + select USB_OHCI_BIG_ENDIAN_DESC
30 + select USB_OHCI_BIG_ENDIAN_MMIO
31
32 config BCM63XX_CPU_6358
33 bool "support 6358 CPU"
34 select HW_HAS_PCI
35 + select USB_ARCH_HAS_OHCI
36 + select USB_OHCI_BIG_ENDIAN_DESC
37 + select USB_OHCI_BIG_ENDIAN_MMIO
38 endmenu
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
43 @@ -1,4 +1,5 @@
44 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o
45 obj-y += dev-uart.o
46 obj-y += dev-pcmcia.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
50 new file mode 100644
51 index 0000000..377e67c
52 --- /dev/null
53 +++ b/arch/mips/bcm63xx/dev-usb-ohci.c
54 @@ -0,0 +1,50 @@
55 +/*
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
58 + * for more details.
59 + *
60 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
61 + */
62 +
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>
68 +
69 +static struct resource ohci_resources[] = {
70 + {
71 + .start = -1, /* filled at runtime */
72 + .end = -1, /* filled at runtime */
73 + .flags = IORESOURCE_MEM,
74 + },
75 + {
76 + .start = -1, /* filled at runtime */
77 + .flags = IORESOURCE_IRQ,
78 + },
79 +};
80 +
81 +static u64 ohci_dmamask = ~(u32)0;
82 +
83 +static struct platform_device bcm63xx_ohci_device = {
84 + .name = "bcm63xx_ohci",
85 + .id = 0,
86 + .num_resources = ARRAY_SIZE(ohci_resources),
87 + .resource = ohci_resources,
88 + .dev = {
89 + .dma_mask = &ohci_dmamask,
90 + .coherent_dma_mask = 0xffffffff,
91 + },
92 +};
93 +
94 +int __init bcm63xx_ohci_register(void)
95 +{
96 + if (!BCMCPU_IS_6348() && !BCMCPU_IS_6358())
97 + return 0;
98 +
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);
104 +}
105 diff --git a/drivers/usb/host/ohci-bcm63xx.c b/drivers/usb/host/ohci-bcm63xx.c
106 new file mode 100644
107 index 0000000..08807d9
108 --- /dev/null
109 +++ b/drivers/usb/host/ohci-bcm63xx.c
110 @@ -0,0 +1,159 @@
111 +/*
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.
115 + *
116 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
117 + */
118 +
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>
125 +
126 +static struct clk *usb_host_clock;
127 +
128 +static int __devinit ohci_bcm63xx_start(struct usb_hcd *hcd)
129 +{
130 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
131 + int ret;
132 +
133 + ret = ohci_init(ohci);
134 + if (ret < 0)
135 + return ret;
136 +
137 + /* FIXME: autodetected port 2 is shared with USB slave */
138 +
139 + ret = ohci_run(ohci);
140 + if (ret < 0) {
141 + err("can't start %s", hcd->self.bus_name);
142 + ohci_stop(hcd);
143 + return ret;
144 + }
145 + return 0;
146 +}
147 +
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),
152 +
153 + .irq = ohci_irq,
154 + .flags = HCD_USB11 | HCD_MEMORY,
155 + .start = ohci_bcm63xx_start,
156 + .stop = ohci_stop,
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,
165 +};
166 +
167 +static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
168 +{
169 + struct resource *res_mem, *res_irq;
170 + struct usb_hcd *hcd;
171 + struct ohci_hcd *ohci;
172 + u32 reg;
173 + int ret;
174 +
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)
178 + return -ENODEV;
179 +
180 + if (BCMCPU_IS_6348()) {
181 + struct clk *clk;
182 + /* enable USB host clock */
183 + clk = clk_get(&pdev->dev, "usbh");
184 + if (IS_ERR(clk))
185 + return -ENODEV;
186 +
187 + clk_enable(clk);
188 + usb_host_clock = clk;
189 + bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
190 +
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);
196 + /* don't ask... */
197 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
198 + } else
199 + return 0;
200 +
201 + hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
202 + if (!hcd)
203 + return -ENOMEM;
204 + hcd->rsrc_start = res_mem->start;
205 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
206 +
207 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
208 + pr_debug("request_mem_region failed\n");
209 + ret = -EBUSY;
210 + goto out;
211 + }
212 +
213 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
214 + if (!hcd->regs) {
215 + pr_debug("ioremap failed\n");
216 + ret = -EIO;
217 + goto out1;
218 + }
219 +
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);
224 +
225 + ret = usb_add_hcd(hcd, res_irq->start, IRQF_DISABLED);
226 + if (ret)
227 + goto out2;
228 +
229 + platform_set_drvdata(pdev, hcd);
230 + return 0;
231 +
232 +out2:
233 + iounmap(hcd->regs);
234 +out1:
235 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
236 +out:
237 + usb_put_hcd(hcd);
238 + return ret;
239 +}
240 +
241 +static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
242 +{
243 + struct usb_hcd *hcd;
244 +
245 + hcd = platform_get_drvdata(pdev);
246 + usb_remove_hcd(hcd);
247 + iounmap(hcd->regs);
248 + usb_put_hcd(hcd);
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);
253 + }
254 + platform_set_drvdata(pdev, NULL);
255 + return 0;
256 +}
257 +
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,
262 + .driver = {
263 + .name = "bcm63xx_ohci",
264 + .owner = THIS_MODULE,
265 + .bus = &platform_bus_type
266 + },
267 +};
268 +
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
276 #endif
277
278 +#ifdef CONFIG_BCM63XX
279 +#include "ohci-bcm63xx.c"
280 +#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
281 +#endif
282 +
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)
292 #endif
293
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)
297 +#endif
298 +
299 static inline unsigned int _ohci_readl (const struct ohci_hcd *ohci,
300 __hc32 __iomem * regs)
301 {
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.
304 */
305
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)
309 #else
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
312 new file mode 100644
313 index 0000000..518a04d
314 --- /dev/null
315 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
316 @@ -0,0 +1,6 @@
317 +#ifndef BCM63XX_DEV_USB_OHCI_H_
318 +#define BCM63XX_DEV_USB_OHCI_H_
319 +
320 +int bcm63xx_ohci_register(void);
321 +
322 +#endif /* BCM63XX_DEV_USB_OHCI_H_ */
323 --
324 1.5.4.3
325
This page took 0.061343 seconds and 5 git commands to generate.