1 From: Michael Buesch <mb@bu3sch.de>
2 Date: Wed, 10 Oct 2007 06:47:17 +0000 (-0700)
3 Subject: USB: ohci SSB bus glue
4 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fralf%2Flinux.git;a=commitdiff_plain;h=c604e851486eabcbeb73e984279d436ce121fd5d
8 This adds SSB bus glue for the USB OHCI HCD.
10 Signed-off-by: Michael Buesch <mb@bu3sch.de>
11 Signed-off-by: John W. Linville <linville@tuxdriver.com>
12 Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
16 diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
17 index 565d6ef..c978d62 100644
18 --- a/drivers/usb/host/Kconfig
19 +++ b/drivers/usb/host/Kconfig
20 @@ -154,6 +154,19 @@ config USB_OHCI_HCD_PCI
21 Enables support for PCI-bus plug-in USB controller cards.
24 +config USB_OHCI_HCD_SSB
25 + bool "OHCI support for Broadcom SSB OHCI core"
26 + depends on USB_OHCI_HCD && SSB && EXPERIMENTAL
29 + Support for the Sonics Silicon Backplane (SSB) attached
30 + Broadcom USB OHCI core.
32 + This device is present in some embedded devices with
33 + Broadcom based SSB bus.
37 config USB_OHCI_BIG_ENDIAN_DESC
39 depends on USB_OHCI_HCD
40 diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
41 index f7c6ced..240c7f5 100644
42 --- a/drivers/usb/host/ohci-hcd.c
43 +++ b/drivers/usb/host/ohci-hcd.c
44 @@ -1033,11 +1033,17 @@ MODULE_LICENSE ("GPL");
45 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
48 +#ifdef CONFIG_USB_OHCI_HCD_SSB
49 +#include "ohci-ssb.c"
50 +#define SSB_OHCI_DRIVER ssb_ohci_driver
53 #if !defined(PCI_DRIVER) && \
54 !defined(PLATFORM_DRIVER) && \
55 !defined(OF_PLATFORM_DRIVER) && \
56 !defined(SA1111_DRIVER) && \
57 - !defined(PS3_SYSTEM_BUS_DRIVER)
58 + !defined(PS3_SYSTEM_BUS_DRIVER) && \
59 + !defined(SSB_OHCI_DRIVER)
60 #error "missing bus glue for ohci-hcd"
63 @@ -1082,10 +1088,20 @@ static int __init ohci_hcd_mod_init(void)
67 +#ifdef SSB_OHCI_DRIVER
68 + retval = ssb_driver_register(&SSB_OHCI_DRIVER);
76 +#ifdef SSB_OHCI_DRIVER
80 + pci_unregister_driver(&PCI_DRIVER);
84 @@ -1110,6 +1126,9 @@ module_init(ohci_hcd_mod_init);
86 static void __exit ohci_hcd_mod_exit(void)
88 +#ifdef SSB_OHCI_DRIVER
89 + ssb_driver_unregister(&SSB_OHCI_DRIVER);
92 pci_unregister_driver(&PCI_DRIVER);
94 diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
96 index 0000000..bc3e785
98 +++ b/drivers/usb/host/ohci-ssb.c
101 + * Sonics Silicon Backplane
102 + * Broadcom USB-core OHCI driver
104 + * Copyright 2007 Michael Buesch <mb@bu3sch.de>
106 + * Derived from the OHCI-PCI driver
107 + * Copyright 1999 Roman Weissgaerber
108 + * Copyright 2000-2002 David Brownell
109 + * Copyright 1999 Linus Torvalds
110 + * Copyright 1999 Gregory P. Smith
112 + * Derived from the USBcore related parts of Broadcom-SB
113 + * Copyright 2005 Broadcom Corporation
115 + * Licensed under the GNU/GPL. See COPYING for details.
117 +#include <linux/ssb/ssb.h>
120 +#define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
122 +struct ssb_ohci_device {
123 + struct ohci_hcd ohci; /* _must_ be at the beginning. */
129 +struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
131 + return (struct ssb_ohci_device *)(hcd->hcd_priv);
135 +static int ssb_ohci_reset(struct usb_hcd *hcd)
137 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
138 + struct ohci_hcd *ohci = &ohcidev->ohci;
141 + ohci_hcd_init(ohci);
142 + err = ohci_init(ohci);
147 +static int ssb_ohci_start(struct usb_hcd *hcd)
149 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
150 + struct ohci_hcd *ohci = &ohcidev->ohci;
153 + err = ohci_run(ohci);
155 + ohci_err(ohci, "can't start\n");
163 +static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
165 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
166 + struct ohci_hcd *ohci = &ohcidev->ohci;
167 + unsigned long flags;
169 + spin_lock_irqsave(&ohci->lock, flags);
171 + ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
172 + ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
174 + /* make sure snapshot being resumed re-enumerates everything */
175 + if (message.event == PM_EVENT_PRETHAW)
176 + ohci_usb_reset(ohci);
178 + clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
180 + spin_unlock_irqrestore(&ohci->lock, flags);
184 +static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
186 + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
187 + usb_hcd_resume_root_hub(hcd);
190 +#endif /* CONFIG_PM */
192 +static const struct hc_driver ssb_ohci_hc_driver = {
193 + .description = "ssb-usb-ohci",
194 + .product_desc = "SSB OHCI Controller",
195 + .hcd_priv_size = sizeof(struct ssb_ohci_device),
198 + .flags = HCD_MEMORY | HCD_USB11,
200 + .reset = ssb_ohci_reset,
201 + .start = ssb_ohci_start,
203 + .shutdown = ohci_shutdown,
206 + .suspend = ssb_ohci_hcd_suspend,
207 + .resume = ssb_ohci_hcd_resume,
210 + .urb_enqueue = ohci_urb_enqueue,
211 + .urb_dequeue = ohci_urb_dequeue,
212 + .endpoint_disable = ohci_endpoint_disable,
214 + .get_frame_number = ohci_get_frame,
216 + .hub_status_data = ohci_hub_status_data,
217 + .hub_control = ohci_hub_control,
218 + .hub_irq_enable = ohci_rhsc_enable,
219 + .bus_suspend = ohci_bus_suspend,
220 + .bus_resume = ohci_bus_resume,
222 + .start_port_reset = ohci_start_port_reset,
225 +static void ssb_ohci_detach(struct ssb_device *dev)
227 + struct usb_hcd *hcd = ssb_get_drvdata(dev);
229 + usb_remove_hcd(hcd);
230 + iounmap(hcd->regs);
232 + ssb_device_disable(dev, 0);
235 +static int ssb_ohci_attach(struct ssb_device *dev)
237 + struct ssb_ohci_device *ohcidev;
238 + struct usb_hcd *hcd;
240 + u32 tmp, flags = 0;
242 + if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
243 + flags |= SSB_OHCI_TMSLOW_HOSTMODE;
245 + ssb_device_enable(dev, flags);
247 + hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
250 + goto err_dev_disable;
251 + ohcidev = hcd_to_ssb_ohci(hcd);
252 + ohcidev->enable_flags = flags;
254 + tmp = ssb_read32(dev, SSB_ADMATCH0);
255 + hcd->rsrc_start = ssb_admatch_base(tmp);
256 + hcd->rsrc_len = ssb_admatch_size(tmp);
257 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
260 + err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
264 + ssb_set_drvdata(dev, hcd);
269 + iounmap(hcd->regs);
273 + ssb_device_disable(dev, flags);
277 +static int ssb_ohci_probe(struct ssb_device *dev,
278 + const struct ssb_device_id *id)
283 + /* USBcores are only connected on embedded devices. */
284 + chipid_top = (dev->bus->chip_id & 0xFF00);
285 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
288 + /* TODO: Probably need checks here; is the core connected? */
290 + if (usb_disabled())
293 + /* We currently always attach SSB_DEV_USB11_HOSTDEV
294 + * as HOST OHCI. If we want to attach it as Client device,
295 + * we must branch here and call into the (yet to
296 + * be written) Client mode driver. Same for remove(). */
298 + err = ssb_ohci_attach(dev);
303 +static void ssb_ohci_remove(struct ssb_device *dev)
305 + ssb_ohci_detach(dev);
310 +static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
312 + ssb_device_disable(dev, 0);
317 +static int ssb_ohci_resume(struct ssb_device *dev)
319 + struct usb_hcd *hcd = ssb_get_drvdata(dev);
320 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
322 + ssb_device_enable(dev, ohcidev->enable_flags);
327 +#else /* !CONFIG_PM */
328 +#define ssb_ohci_suspend NULL
329 +#define ssb_ohci_resume NULL
330 +#endif /* CONFIG_PM */
332 +static const struct ssb_device_id ssb_ohci_table[] = {
333 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
334 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
337 +MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
339 +static struct ssb_driver ssb_ohci_driver = {
340 + .name = KBUILD_MODNAME,
341 + .id_table = ssb_ohci_table,
342 + .probe = ssb_ohci_probe,
343 + .remove = ssb_ohci_remove,
344 + .suspend = ssb_ohci_suspend,
345 + .resume = ssb_ohci_resume,