82fbec305a66a2663462fd941f8968c5fcfe31c8
[firefly-linux-kernel-4.4.55.git] / drivers / usb / host / ohci-pci.c
1 /*
2  * OHCI HCD (Host Controller Driver) for USB.
3  *
4  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6  *
7  * [ Initialisation is based on Linus'  ]
8  * [ uhci code and gregs ohci fragments ]
9  * [ (C) Copyright 1999 Linus Torvalds  ]
10  * [ (C) Copyright 1999 Gregory P. Smith]
11  *
12  * PCI Bus Glue
13  *
14  * This file is licenced under the GPL.
15  */
16
17 #ifndef CONFIG_PCI
18 #error "This file is PCI bus glue.  CONFIG_PCI must be defined."
19 #endif
20
21 /*-------------------------------------------------------------------------*/
22
23 /* AMD 756, for most chips (early revs), corrupts register
24  * values on read ... so enable the vendor workaround.
25  */
26 static int __devinit ohci_quirk_amd756(struct usb_hcd *hcd)
27 {
28         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
29
30         ohci->flags = OHCI_QUIRK_AMD756;
31         ohci_dbg (ohci, "AMD756 erratum 4 workaround\n");
32
33         /* also erratum 10 (suspend/resume issues) */
34         device_init_wakeup(&hcd->self.root_hub->dev, 0);
35
36         return 0;
37 }
38
39 /* Apple's OHCI driver has a lot of bizarre workarounds
40  * for this chip.  Evidently control and bulk lists
41  * can get confused.  (B&W G3 models, and ...)
42  */
43 static int __devinit ohci_quirk_opti(struct usb_hcd *hcd)
44 {
45         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
46
47         ohci_dbg (ohci, "WARNING: OPTi workarounds unavailable\n");
48
49         return 0;
50 }
51
52 /* Check for NSC87560. We have to look at the bridge (fn1) to
53  * identify the USB (fn2). This quirk might apply to more or
54  * even all NSC stuff.
55  */
56 static int __devinit ohci_quirk_ns(struct usb_hcd *hcd)
57 {
58         struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
59         struct pci_dev  *b;
60
61         b  = pci_get_slot (pdev->bus, PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
62         if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
63             && b->vendor == PCI_VENDOR_ID_NS) {
64                 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
65
66                 ohci->flags |= OHCI_QUIRK_SUPERIO;
67                 ohci_dbg (ohci, "Using NSC SuperIO setup\n");
68         }
69         pci_dev_put(b);
70
71         return 0;
72 }
73
74 /* Check for Compaq's ZFMicro chipset, which needs short
75  * delays before control or bulk queues get re-activated
76  * in finish_unlinks()
77  */
78 static int __devinit ohci_quirk_zfmicro(struct usb_hcd *hcd)
79 {
80         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
81
82         ohci->flags |= OHCI_QUIRK_ZFMICRO;
83         ohci_dbg (ohci, "enabled Compaq ZFMicro chipset quirk\n");
84
85         return 0;
86 }
87
88
89 /* List of quirks for OHCI */
90 static const struct pci_device_id ohci_pci_quirks[] = {
91         {
92                 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c),
93                 .driver_data = (unsigned long)ohci_quirk_amd756,
94         },
95         {
96                 PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861),
97                 .driver_data = (unsigned long)ohci_quirk_opti,
98         },
99         {
100                 PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID),
101                 .driver_data = (unsigned long)ohci_quirk_ns,
102         },
103         {
104                 PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8),
105                 .driver_data = (unsigned long)ohci_quirk_zfmicro,
106         },
107         /* FIXME for some of the early AMD 760 southbridges, OHCI
108          * won't work at all.  blacklist them.
109          */
110         {},
111 };
112
113 static int ohci_pci_reset (struct usb_hcd *hcd)
114 {
115         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
116         int ret = 0;
117
118         if (hcd->self.controller) {
119                 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
120                 const struct pci_device_id *quirk_id;
121
122                 quirk_id = pci_match_id(ohci_pci_quirks, pdev);
123                 if (quirk_id != NULL) {
124                         int (*quirk)(struct usb_hcd *ohci);
125                         quirk = (void *)quirk_id->driver_data;
126                         ret = quirk(hcd);
127                 }
128         }
129         if (ret == 0) {
130                 ohci_hcd_init (ohci);
131                 return ohci_init (ohci);
132         }
133         return ret;
134 }
135
136
137 static int __devinit ohci_pci_start (struct usb_hcd *hcd)
138 {
139         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
140         int             ret;
141
142 #ifdef CONFIG_PM /* avoid warnings about unused pdev */
143         if (hcd->self.controller) {
144                 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
145
146                 /* RWC may not be set for add-in PCI cards, since boot
147                  * firmware probably ignored them.  This transfers PCI
148                  * PM wakeup capabilities (once the PCI layer is fixed).
149                  */
150                 if (device_may_wakeup(&pdev->dev))
151                         ohci->hc_control |= OHCI_CTRL_RWC;
152         }
153 #endif /* CONFIG_PM */
154
155         ret = ohci_run (ohci);
156         if (ret < 0) {
157                 ohci_err (ohci, "can't start\n");
158                 ohci_stop (hcd);
159         }
160         return ret;
161 }
162
163 #ifdef  CONFIG_PM
164
165 static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
166 {
167         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
168         unsigned long   flags;
169         int             rc = 0;
170
171         /* Root hub was already suspended. Disable irq emission and
172          * mark HW unaccessible, bail out if RH has been resumed. Use
173          * the spinlock to properly synchronize with possible pending
174          * RH suspend or resume activity.
175          *
176          * This is still racy as hcd->state is manipulated outside of
177          * any locks =P But that will be a different fix.
178          */
179         spin_lock_irqsave (&ohci->lock, flags);
180         if (hcd->state != HC_STATE_SUSPENDED) {
181                 rc = -EINVAL;
182                 goto bail;
183         }
184         ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
185         (void)ohci_readl(ohci, &ohci->regs->intrdisable);
186
187         /* make sure snapshot being resumed re-enumerates everything */
188         if (message.event == PM_EVENT_PRETHAW)
189                 ohci_usb_reset(ohci);
190
191         clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
192  bail:
193         spin_unlock_irqrestore (&ohci->lock, flags);
194
195         return rc;
196 }
197
198
199 static int ohci_pci_resume (struct usb_hcd *hcd)
200 {
201         set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
202         usb_hcd_resume_root_hub(hcd);
203         return 0;
204 }
205
206 #endif  /* CONFIG_PM */
207
208
209 /*-------------------------------------------------------------------------*/
210
211 static const struct hc_driver ohci_pci_hc_driver = {
212         .description =          hcd_name,
213         .product_desc =         "OHCI Host Controller",
214         .hcd_priv_size =        sizeof(struct ohci_hcd),
215
216         /*
217          * generic hardware linkage
218          */
219         .irq =                  ohci_irq,
220         .flags =                HCD_MEMORY | HCD_USB11,
221
222         /*
223          * basic lifecycle operations
224          */
225         .reset =                ohci_pci_reset,
226         .start =                ohci_pci_start,
227         .stop =                 ohci_stop,
228         .shutdown =             ohci_shutdown,
229
230 #ifdef  CONFIG_PM
231         /* these suspend/resume entries are for upstream PCI glue ONLY */
232         .suspend =              ohci_pci_suspend,
233         .resume =               ohci_pci_resume,
234 #endif
235
236         /*
237          * managing i/o requests and associated device resources
238          */
239         .urb_enqueue =          ohci_urb_enqueue,
240         .urb_dequeue =          ohci_urb_dequeue,
241         .endpoint_disable =     ohci_endpoint_disable,
242
243         /*
244          * scheduling support
245          */
246         .get_frame_number =     ohci_get_frame,
247
248         /*
249          * root hub support
250          */
251         .hub_status_data =      ohci_hub_status_data,
252         .hub_control =          ohci_hub_control,
253         .hub_irq_enable =       ohci_rhsc_enable,
254 #ifdef  CONFIG_PM
255         .bus_suspend =          ohci_bus_suspend,
256         .bus_resume =           ohci_bus_resume,
257 #endif
258         .start_port_reset =     ohci_start_port_reset,
259 };
260
261 /*-------------------------------------------------------------------------*/
262
263
264 static const struct pci_device_id pci_ids [] = { {
265         /* handle any USB OHCI controller */
266         PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0),
267         .driver_data =  (unsigned long) &ohci_pci_hc_driver,
268         }, { /* end: all zeroes */ }
269 };
270 MODULE_DEVICE_TABLE (pci, pci_ids);
271
272 /* pci driver glue; this is a "new style" PCI driver module */
273 static struct pci_driver ohci_pci_driver = {
274         .name =         (char *) hcd_name,
275         .id_table =     pci_ids,
276
277         .probe =        usb_hcd_pci_probe,
278         .remove =       usb_hcd_pci_remove,
279
280 #ifdef  CONFIG_PM
281         .suspend =      usb_hcd_pci_suspend,
282         .resume =       usb_hcd_pci_resume,
283 #endif
284
285         .shutdown =     usb_hcd_pci_shutdown,
286 };
287
288
289 static int __init ohci_hcd_pci_init (void)
290 {
291         printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name);
292         if (usb_disabled())
293                 return -ENODEV;
294
295         pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
296                 sizeof (struct ed), sizeof (struct td));
297         return pci_register_driver (&ohci_pci_driver);
298 }
299 module_init (ohci_hcd_pci_init);
300
301 /*-------------------------------------------------------------------------*/
302
303 static void __exit ohci_hcd_pci_cleanup (void)
304 {
305         pci_unregister_driver (&ohci_pci_driver);
306 }
307 module_exit (ohci_hcd_pci_cleanup);