Make 4-port LAN and 1 port wan configurations work
[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 --- a/arch/mips/bcm63xx/Kconfig
21 +++ b/arch/mips/bcm63xx/Kconfig
22 @@ -4,8 +4,14 @@ menu "CPU support"
23 config BCM63XX_CPU_6348
24 bool "support 6348 CPU"
25 select HW_HAS_PCI
26 + select USB_ARCH_HAS_OHCI
27 + select USB_OHCI_BIG_ENDIAN_DESC
28 + select USB_OHCI_BIG_ENDIAN_MMIO
29
30 config BCM63XX_CPU_6358
31 bool "support 6358 CPU"
32 select HW_HAS_PCI
33 + select USB_ARCH_HAS_OHCI
34 + select USB_OHCI_BIG_ENDIAN_DESC
35 + select USB_OHCI_BIG_ENDIAN_MMIO
36 endmenu
37 --- a/arch/mips/bcm63xx/Makefile
38 +++ b/arch/mips/bcm63xx/Makefile
39 @@ -1,4 +1,5 @@
40 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o
41 obj-y += dev-uart.o
42 obj-y += dev-pcmcia.o
43 +obj-y += dev-usb-ohci.o
44 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
45 --- /dev/null
46 +++ b/arch/mips/bcm63xx/dev-usb-ohci.c
47 @@ -0,0 +1,50 @@
48 +/*
49 + * This file is subject to the terms and conditions of the GNU General Public
50 + * License. See the file "COPYING" in the main directory of this archive
51 + * for more details.
52 + *
53 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
54 + */
55 +
56 +#include <linux/init.h>
57 +#include <linux/kernel.h>
58 +#include <linux/platform_device.h>
59 +#include <bcm63xx_cpu.h>
60 +#include <bcm63xx_dev_usb_ohci.h>
61 +
62 +static struct resource ohci_resources[] = {
63 + {
64 + .start = -1, /* filled at runtime */
65 + .end = -1, /* filled at runtime */
66 + .flags = IORESOURCE_MEM,
67 + },
68 + {
69 + .start = -1, /* filled at runtime */
70 + .flags = IORESOURCE_IRQ,
71 + },
72 +};
73 +
74 +static u64 ohci_dmamask = ~(u32)0;
75 +
76 +static struct platform_device bcm63xx_ohci_device = {
77 + .name = "bcm63xx_ohci",
78 + .id = 0,
79 + .num_resources = ARRAY_SIZE(ohci_resources),
80 + .resource = ohci_resources,
81 + .dev = {
82 + .dma_mask = &ohci_dmamask,
83 + .coherent_dma_mask = 0xffffffff,
84 + },
85 +};
86 +
87 +int __init bcm63xx_ohci_register(void)
88 +{
89 + if (!BCMCPU_IS_6348() && !BCMCPU_IS_6358())
90 + return 0;
91 +
92 + ohci_resources[0].start = bcm63xx_regset_address(RSET_OHCI0);
93 + ohci_resources[0].end = ohci_resources[0].start;
94 + ohci_resources[0].end += RSET_OHCI_SIZE - 1;
95 + ohci_resources[1].start = bcm63xx_get_irq_number(IRQ_OHCI0);
96 + return platform_device_register(&bcm63xx_ohci_device);
97 +}
98 --- /dev/null
99 +++ b/drivers/usb/host/ohci-bcm63xx.c
100 @@ -0,0 +1,159 @@
101 +/*
102 + * This file is subject to the terms and conditions of the GNU General Public
103 + * License. See the file "COPYING" in the main directory of this archive
104 + * for more details.
105 + *
106 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
107 + */
108 +
109 +#include <linux/init.h>
110 +#include <linux/clk.h>
111 +#include <linux/platform_device.h>
112 +#include <bcm63xx_cpu.h>
113 +#include <bcm63xx_regs.h>
114 +#include <bcm63xx_io.h>
115 +
116 +static struct clk *usb_host_clock;
117 +
118 +static int __devinit ohci_bcm63xx_start(struct usb_hcd *hcd)
119 +{
120 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
121 + int ret;
122 +
123 + ret = ohci_init(ohci);
124 + if (ret < 0)
125 + return ret;
126 +
127 + /* FIXME: autodetected port 2 is shared with USB slave */
128 +
129 + ret = ohci_run(ohci);
130 + if (ret < 0) {
131 + err("can't start %s", hcd->self.bus_name);
132 + ohci_stop(hcd);
133 + return ret;
134 + }
135 + return 0;
136 +}
137 +
138 +static const struct hc_driver ohci_bcm63xx_hc_driver = {
139 + .description = hcd_name,
140 + .product_desc = "BCM63XX integrated OHCI controller",
141 + .hcd_priv_size = sizeof(struct ohci_hcd),
142 +
143 + .irq = ohci_irq,
144 + .flags = HCD_USB11 | HCD_MEMORY,
145 + .start = ohci_bcm63xx_start,
146 + .stop = ohci_stop,
147 + .shutdown = ohci_shutdown,
148 + .urb_enqueue = ohci_urb_enqueue,
149 + .urb_dequeue = ohci_urb_dequeue,
150 + .endpoint_disable = ohci_endpoint_disable,
151 + .get_frame_number = ohci_get_frame,
152 + .hub_status_data = ohci_hub_status_data,
153 + .hub_control = ohci_hub_control,
154 + .start_port_reset = ohci_start_port_reset,
155 +};
156 +
157 +static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
158 +{
159 + struct resource *res_mem, *res_irq;
160 + struct usb_hcd *hcd;
161 + struct ohci_hcd *ohci;
162 + u32 reg;
163 + int ret;
164 +
165 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
166 + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
167 + if (!res_mem || !res_irq)
168 + return -ENODEV;
169 +
170 + if (BCMCPU_IS_6348()) {
171 + struct clk *clk;
172 + /* enable USB host clock */
173 + clk = clk_get(&pdev->dev, "usbh");
174 + if (IS_ERR(clk))
175 + return -ENODEV;
176 +
177 + clk_enable(clk);
178 + usb_host_clock = clk;
179 + bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
180 +
181 + } else if (BCMCPU_IS_6358()) {
182 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_REG);
183 + reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
184 + reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
185 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_REG);
186 + /* don't ask... */
187 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
188 + } else
189 + return 0;
190 +
191 + hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
192 + if (!hcd)
193 + return -ENOMEM;
194 + hcd->rsrc_start = res_mem->start;
195 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
196 +
197 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
198 + pr_debug("request_mem_region failed\n");
199 + ret = -EBUSY;
200 + goto out;
201 + }
202 +
203 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
204 + if (!hcd->regs) {
205 + pr_debug("ioremap failed\n");
206 + ret = -EIO;
207 + goto out1;
208 + }
209 +
210 + ohci = hcd_to_ohci(hcd);
211 + ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC |
212 + OHCI_QUIRK_FRAME_NO;
213 + ohci_hcd_init(ohci);
214 +
215 + ret = usb_add_hcd(hcd, res_irq->start, IRQF_DISABLED);
216 + if (ret)
217 + goto out2;
218 +
219 + platform_set_drvdata(pdev, hcd);
220 + return 0;
221 +
222 +out2:
223 + iounmap(hcd->regs);
224 +out1:
225 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
226 +out:
227 + usb_put_hcd(hcd);
228 + return ret;
229 +}
230 +
231 +static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
232 +{
233 + struct usb_hcd *hcd;
234 +
235 + hcd = platform_get_drvdata(pdev);
236 + usb_remove_hcd(hcd);
237 + iounmap(hcd->regs);
238 + usb_put_hcd(hcd);
239 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
240 + if (usb_host_clock) {
241 + clk_disable(usb_host_clock);
242 + clk_put(usb_host_clock);
243 + }
244 + platform_set_drvdata(pdev, NULL);
245 + return 0;
246 +}
247 +
248 +static struct platform_driver ohci_hcd_bcm63xx_driver = {
249 + .probe = ohci_hcd_bcm63xx_drv_probe,
250 + .remove = __devexit_p(ohci_hcd_bcm63xx_drv_remove),
251 + .shutdown = usb_hcd_platform_shutdown,
252 + .driver = {
253 + .name = "bcm63xx_ohci",
254 + .owner = THIS_MODULE,
255 + .bus = &platform_bus_type
256 + },
257 +};
258 +
259 +MODULE_ALIAS("platform:bcm63xx_ohci");
260 --- a/drivers/usb/host/ohci-hcd.c
261 +++ b/drivers/usb/host/ohci-hcd.c
262 @@ -1050,6 +1050,11 @@ MODULE_LICENSE ("GPL");
263 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
264 #endif
265
266 +#ifdef CONFIG_BCM63XX
267 +#include "ohci-bcm63xx.c"
268 +#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
269 +#endif
270 +
271 #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
272 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
273 defined(CONFIG_CPU_SUBTYPE_SH7763)
274 --- a/drivers/usb/host/ohci.h
275 +++ b/drivers/usb/host/ohci.h
276 @@ -549,6 +549,11 @@ static inline struct usb_hcd *ohci_to_hc
277 #define writel_be(val, addr) out_be32((__force unsigned *)addr, val)
278 #endif
279
280 +#if defined(CONFIG_MIPS) && defined(CONFIG_BCM63XX)
281 +#define readl_be(addr) __raw_readl((__force unsigned *)addr)
282 +#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
283 +#endif
284 +
285 static inline unsigned int _ohci_readl (const struct ohci_hcd *ohci,
286 __hc32 __iomem * regs)
287 {
288 @@ -654,7 +659,7 @@ static inline u32 hc32_to_cpup (const st
289 * some big-endian SOC implementations. Same thing happens with PSW access.
290 */
291
292 -#ifdef CONFIG_PPC_MPC52xx
293 +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_BCM63XX)
294 #define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
295 #else
296 #define big_endian_frame_no_quirk(ohci) 0
297 --- /dev/null
298 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
299 @@ -0,0 +1,6 @@
300 +#ifndef BCM63XX_DEV_USB_OHCI_H_
301 +#define BCM63XX_DEV_USB_OHCI_H_
302 +
303 +int bcm63xx_ohci_register(void);
304 +
305 +#endif /* BCM63XX_DEV_USB_OHCI_H_ */
This page took 0.05722 seconds and 5 git commands to generate.