Enable SSB ohci driver (#2828)
[oweals/openwrt.git] / target / linux / brcm47xx / patches-2.6.23 / 230-ohci-ssb.patch
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
5
6 USB: ohci SSB bus glue
7
8 This adds SSB bus glue for the USB OHCI HCD.
9
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>
14 ---
15
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.
22           If unsure, say Y.
23  
24 +config USB_OHCI_HCD_SSB
25 +       bool "OHCI support for Broadcom SSB OHCI core"
26 +       depends on USB_OHCI_HCD && SSB && EXPERIMENTAL
27 +       default n
28 +       ---help---
29 +         Support for the Sonics Silicon Backplane (SSB) attached
30 +         Broadcom USB OHCI core.
31 +
32 +         This device is present in some embedded devices with
33 +         Broadcom based SSB bus.
34 +
35 +         If unsure, say N.
36 +
37  config USB_OHCI_BIG_ENDIAN_DESC
38         bool
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
46  #endif
47  
48 +#ifdef CONFIG_USB_OHCI_HCD_SSB
49 +#include "ohci-ssb.c"
50 +#define SSB_OHCI_DRIVER                ssb_ohci_driver
51 +#endif
52 +
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"
61  #endif
62  
63 @@ -1082,10 +1088,20 @@ static int __init ohci_hcd_mod_init(void)
64                 goto error_pci;
65  #endif
66  
67 +#ifdef SSB_OHCI_DRIVER
68 +       retval = ssb_driver_register(&SSB_OHCI_DRIVER);
69 +       if (retval)
70 +               goto error_ssb;
71 +#endif
72 +
73         return retval;
74  
75         /* Error path */
76 +#ifdef SSB_OHCI_DRIVER
77 + error_ssb:
78 +#endif
79  #ifdef PCI_DRIVER
80 +       pci_unregister_driver(&PCI_DRIVER);
81   error_pci:
82  #endif
83  #ifdef SA1111_DRIVER
84 @@ -1110,6 +1126,9 @@ module_init(ohci_hcd_mod_init);
85  
86  static void __exit ohci_hcd_mod_exit(void)
87  {
88 +#ifdef SSB_OHCI_DRIVER
89 +       ssb_driver_unregister(&SSB_OHCI_DRIVER);
90 +#endif
91  #ifdef PCI_DRIVER
92         pci_unregister_driver(&PCI_DRIVER);
93  #endif
94 diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
95 new file mode 100644
96 index 0000000..bc3e785
97 --- /dev/null
98 +++ b/drivers/usb/host/ohci-ssb.c
99 @@ -0,0 +1,247 @@
100 +/*
101 + * Sonics Silicon Backplane
102 + * Broadcom USB-core OHCI driver
103 + *
104 + * Copyright 2007 Michael Buesch <mb@bu3sch.de>
105 + *
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
111 + *
112 + * Derived from the USBcore related parts of Broadcom-SB
113 + * Copyright 2005 Broadcom Corporation
114 + *
115 + * Licensed under the GNU/GPL. See COPYING for details.
116 + */
117 +#include <linux/ssb/ssb.h>
118 +
119 +
120 +#define SSB_OHCI_TMSLOW_HOSTMODE       (1 << 29)
121 +
122 +struct ssb_ohci_device {
123 +       struct ohci_hcd ohci; /* _must_ be at the beginning. */
124 +
125 +       u32 enable_flags;
126 +};
127 +
128 +static inline
129 +struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
130 +{
131 +       return (struct ssb_ohci_device *)(hcd->hcd_priv);
132 +}
133 +
134 +
135 +static int ssb_ohci_reset(struct usb_hcd *hcd)
136 +{
137 +       struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
138 +       struct ohci_hcd *ohci = &ohcidev->ohci;
139 +       int err;
140 +
141 +       ohci_hcd_init(ohci);
142 +       err = ohci_init(ohci);
143 +
144 +       return err;
145 +}
146 +
147 +static int ssb_ohci_start(struct usb_hcd *hcd)
148 +{
149 +       struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
150 +       struct ohci_hcd *ohci = &ohcidev->ohci;
151 +       int err;
152 +
153 +       err = ohci_run(ohci);
154 +       if (err < 0) {
155 +               ohci_err(ohci, "can't start\n");
156 +               ohci_stop(hcd);
157 +       }
158 +
159 +       return err;
160 +}
161 +
162 +#ifdef CONFIG_PM
163 +static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
164 +{
165 +       struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
166 +       struct ohci_hcd *ohci = &ohcidev->ohci;
167 +       unsigned long flags;
168 +
169 +       spin_lock_irqsave(&ohci->lock, flags);
170 +
171 +       ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
172 +       ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
173 +
174 +       /* make sure snapshot being resumed re-enumerates everything */
175 +       if (message.event == PM_EVENT_PRETHAW)
176 +               ohci_usb_reset(ohci);
177 +
178 +       clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
179 +
180 +       spin_unlock_irqrestore(&ohci->lock, flags);
181 +       return 0;
182 +}
183 +
184 +static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
185 +{
186 +       set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
187 +       usb_hcd_resume_root_hub(hcd);
188 +       return 0;
189 +}
190 +#endif /* CONFIG_PM */
191 +
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),
196 +
197 +       .irq                    = ohci_irq,
198 +       .flags                  = HCD_MEMORY | HCD_USB11,
199 +
200 +       .reset                  = ssb_ohci_reset,
201 +       .start                  = ssb_ohci_start,
202 +       .stop                   = ohci_stop,
203 +       .shutdown               = ohci_shutdown,
204 +
205 +#ifdef CONFIG_PM
206 +       .suspend                = ssb_ohci_hcd_suspend,
207 +       .resume                 = ssb_ohci_hcd_resume,
208 +#endif
209 +
210 +       .urb_enqueue            = ohci_urb_enqueue,
211 +       .urb_dequeue            = ohci_urb_dequeue,
212 +       .endpoint_disable       = ohci_endpoint_disable,
213 +
214 +       .get_frame_number       = ohci_get_frame,
215 +
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,
221 +
222 +       .start_port_reset       = ohci_start_port_reset,
223 +};
224 +
225 +static void ssb_ohci_detach(struct ssb_device *dev)
226 +{
227 +       struct usb_hcd *hcd = ssb_get_drvdata(dev);
228 +
229 +       usb_remove_hcd(hcd);
230 +       iounmap(hcd->regs);
231 +       usb_put_hcd(hcd);
232 +       ssb_device_disable(dev, 0);
233 +}
234 +
235 +static int ssb_ohci_attach(struct ssb_device *dev)
236 +{
237 +       struct ssb_ohci_device *ohcidev;
238 +       struct usb_hcd *hcd;
239 +       int err = -ENOMEM;
240 +       u32 tmp, flags = 0;
241 +
242 +       if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
243 +               flags |= SSB_OHCI_TMSLOW_HOSTMODE;
244 +
245 +       ssb_device_enable(dev, flags);
246 +
247 +       hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
248 +                       dev->dev->bus_id);
249 +       if (!hcd)
250 +               goto err_dev_disable;
251 +       ohcidev = hcd_to_ssb_ohci(hcd);
252 +       ohcidev->enable_flags = flags;
253 +
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);
258 +       if (!hcd->regs)
259 +               goto err_put_hcd;
260 +       err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
261 +       if (err)
262 +               goto err_iounmap;
263 +
264 +       ssb_set_drvdata(dev, hcd);
265 +
266 +       return err;
267 +
268 +err_iounmap:
269 +       iounmap(hcd->regs);
270 +err_put_hcd:
271 +       usb_put_hcd(hcd);
272 +err_dev_disable:
273 +       ssb_device_disable(dev, flags);
274 +       return err;
275 +}
276 +
277 +static int ssb_ohci_probe(struct ssb_device *dev,
278 +               const struct ssb_device_id *id)
279 +{
280 +       int err;
281 +       u16 chipid_top;
282 +
283 +       /* USBcores are only connected on embedded devices. */
284 +       chipid_top = (dev->bus->chip_id & 0xFF00);
285 +       if (chipid_top != 0x4700 && chipid_top != 0x5300)
286 +               return -ENODEV;
287 +
288 +       /* TODO: Probably need checks here; is the core connected? */
289 +
290 +       if (usb_disabled())
291 +               return -ENODEV;
292 +
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(). */
297 +
298 +       err = ssb_ohci_attach(dev);
299 +
300 +       return err;
301 +}
302 +
303 +static void ssb_ohci_remove(struct ssb_device *dev)
304 +{
305 +       ssb_ohci_detach(dev);
306 +}
307 +
308 +#ifdef CONFIG_PM
309 +
310 +static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
311 +{
312 +       ssb_device_disable(dev, 0);
313 +
314 +       return 0;
315 +}
316 +
317 +static int ssb_ohci_resume(struct ssb_device *dev)
318 +{
319 +       struct usb_hcd *hcd = ssb_get_drvdata(dev);
320 +       struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
321 +
322 +       ssb_device_enable(dev, ohcidev->enable_flags);
323 +
324 +       return 0;
325 +}
326 +
327 +#else /* !CONFIG_PM */
328 +#define ssb_ohci_suspend       NULL
329 +#define ssb_ohci_resume        NULL
330 +#endif /* CONFIG_PM */
331 +
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),
335 +       SSB_DEVTABLE_END
336 +};
337 +MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
338 +
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,
346 +};
347