Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-1.0+
0002 /*
0003  * OHCI HCD (Host Controller Driver) for USB.
0004  *
0005  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
0006  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
0007  *
0008  * [ Initialisation is based on Linus'  ]
0009  * [ uhci code and gregs ohci fragments ]
0010  * [ (C) Copyright 1999 Linus Torvalds  ]
0011  * [ (C) Copyright 1999 Gregory P. Smith]
0012  *
0013  * PCI Bus Glue
0014  *
0015  * This file is licenced under the GPL.
0016  */
0017 
0018 #include <linux/io.h>
0019 #include <linux/kernel.h>
0020 #include <linux/module.h>
0021 #include <linux/pci.h>
0022 #include <linux/usb.h>
0023 #include <linux/usb/hcd.h>
0024 
0025 #include "ohci.h"
0026 #include "pci-quirks.h"
0027 
0028 #define DRIVER_DESC "OHCI PCI platform driver"
0029 
0030 static const char hcd_name[] = "ohci-pci";
0031 
0032 
0033 /*-------------------------------------------------------------------------*/
0034 
0035 static int broken_suspend(struct usb_hcd *hcd)
0036 {
0037     device_init_wakeup(&hcd->self.root_hub->dev, 0);
0038     return 0;
0039 }
0040 
0041 /* AMD 756, for most chips (early revs), corrupts register
0042  * values on read ... so enable the vendor workaround.
0043  */
0044 static int ohci_quirk_amd756(struct usb_hcd *hcd)
0045 {
0046     struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0047 
0048     ohci->flags = OHCI_QUIRK_AMD756;
0049     ohci_dbg (ohci, "AMD756 erratum 4 workaround\n");
0050 
0051     /* also erratum 10 (suspend/resume issues) */
0052     return broken_suspend(hcd);
0053 }
0054 
0055 /* Apple's OHCI driver has a lot of bizarre workarounds
0056  * for this chip.  Evidently control and bulk lists
0057  * can get confused.  (B&W G3 models, and ...)
0058  */
0059 static int ohci_quirk_opti(struct usb_hcd *hcd)
0060 {
0061     struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0062 
0063     ohci_dbg (ohci, "WARNING: OPTi workarounds unavailable\n");
0064 
0065     return 0;
0066 }
0067 
0068 /* Check for NSC87560. We have to look at the bridge (fn1) to
0069  * identify the USB (fn2). This quirk might apply to more or
0070  * even all NSC stuff.
0071  */
0072 static int ohci_quirk_ns(struct usb_hcd *hcd)
0073 {
0074     struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
0075     struct pci_dev  *b;
0076 
0077     b  = pci_get_slot (pdev->bus, PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
0078     if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
0079         && b->vendor == PCI_VENDOR_ID_NS) {
0080         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0081 
0082         ohci->flags |= OHCI_QUIRK_SUPERIO;
0083         ohci_dbg (ohci, "Using NSC SuperIO setup\n");
0084     }
0085     pci_dev_put(b);
0086 
0087     return 0;
0088 }
0089 
0090 /* Check for Compaq's ZFMicro chipset, which needs short
0091  * delays before control or bulk queues get re-activated
0092  * in finish_unlinks()
0093  */
0094 static int ohci_quirk_zfmicro(struct usb_hcd *hcd)
0095 {
0096     struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0097 
0098     ohci->flags |= OHCI_QUIRK_ZFMICRO;
0099     ohci_dbg(ohci, "enabled Compaq ZFMicro chipset quirks\n");
0100 
0101     return 0;
0102 }
0103 
0104 /* Check for Toshiba SCC OHCI which has big endian registers
0105  * and little endian in memory data structures
0106  */
0107 static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd)
0108 {
0109     struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0110 
0111     /* That chip is only present in the southbridge of some
0112      * cell based platforms which are supposed to select
0113      * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO. We verify here if
0114      * that was the case though.
0115      */
0116 #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
0117     ohci->flags |= OHCI_QUIRK_BE_MMIO;
0118     ohci_dbg (ohci, "enabled big endian Toshiba quirk\n");
0119     return 0;
0120 #else
0121     ohci_err (ohci, "unsupported big endian Toshiba quirk\n");
0122     return -ENXIO;
0123 #endif
0124 }
0125 
0126 /* Check for NEC chip and apply quirk for allegedly lost interrupts.
0127  */
0128 
0129 static void ohci_quirk_nec_worker(struct work_struct *work)
0130 {
0131     struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
0132     int status;
0133 
0134     status = ohci_restart(ohci);
0135     if (status != 0)
0136         ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
0137              "ohci_restart", status);
0138 }
0139 
0140 static int ohci_quirk_nec(struct usb_hcd *hcd)
0141 {
0142     struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0143 
0144     ohci->flags |= OHCI_QUIRK_NEC;
0145     INIT_WORK(&ohci->nec_work, ohci_quirk_nec_worker);
0146     ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n");
0147 
0148     return 0;
0149 }
0150 
0151 static int ohci_quirk_amd700(struct usb_hcd *hcd)
0152 {
0153     struct ohci_hcd *ohci = hcd_to_ohci(hcd);
0154 
0155     if (usb_amd_quirk_pll_check())
0156         ohci->flags |= OHCI_QUIRK_AMD_PLL;
0157 
0158     /* SB800 needs pre-fetch fix */
0159     if (usb_amd_prefetch_quirk()) {
0160         ohci->flags |= OHCI_QUIRK_AMD_PREFETCH;
0161         ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
0162     }
0163 
0164     ohci->flags |= OHCI_QUIRK_GLOBAL_SUSPEND;
0165     return 0;
0166 }
0167 
0168 static int ohci_quirk_qemu(struct usb_hcd *hcd)
0169 {
0170     struct ohci_hcd *ohci = hcd_to_ohci(hcd);
0171 
0172     ohci->flags |= OHCI_QUIRK_QEMU;
0173     ohci_dbg(ohci, "enabled qemu quirk\n");
0174     return 0;
0175 }
0176 
0177 /* List of quirks for OHCI */
0178 static const struct pci_device_id ohci_pci_quirks[] = {
0179     {
0180         PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c),
0181         .driver_data = (unsigned long)ohci_quirk_amd756,
0182     },
0183     {
0184         PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861),
0185         .driver_data = (unsigned long)ohci_quirk_opti,
0186     },
0187     {
0188         PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID),
0189         .driver_data = (unsigned long)ohci_quirk_ns,
0190     },
0191     {
0192         PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8),
0193         .driver_data = (unsigned long)ohci_quirk_zfmicro,
0194     },
0195     {
0196         PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6),
0197         .driver_data = (unsigned long)ohci_quirk_toshiba_scc,
0198     },
0199     {
0200         PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB),
0201         .driver_data = (unsigned long)ohci_quirk_nec,
0202     },
0203     {
0204         /* Toshiba portege 4000 */
0205         .vendor     = PCI_VENDOR_ID_AL,
0206         .device     = 0x5237,
0207         .subvendor  = PCI_VENDOR_ID_TOSHIBA,
0208         .subdevice  = 0x0004,
0209         .driver_data    = (unsigned long) broken_suspend,
0210     },
0211     {
0212         PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152),
0213         .driver_data = (unsigned long) broken_suspend,
0214     },
0215     {
0216         PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4397),
0217         .driver_data = (unsigned long)ohci_quirk_amd700,
0218     },
0219     {
0220         PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4398),
0221         .driver_data = (unsigned long)ohci_quirk_amd700,
0222     },
0223     {
0224         PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
0225         .driver_data = (unsigned long)ohci_quirk_amd700,
0226     },
0227     {
0228         .vendor     = PCI_VENDOR_ID_APPLE,
0229         .device     = 0x003f,
0230         .subvendor  = PCI_SUBVENDOR_ID_REDHAT_QUMRANET,
0231         .subdevice  = PCI_SUBDEVICE_ID_QEMU,
0232         .driver_data    = (unsigned long)ohci_quirk_qemu,
0233     },
0234 
0235     {},
0236 };
0237 
0238 static int ohci_pci_reset (struct usb_hcd *hcd)
0239 {
0240     struct ohci_hcd *ohci = hcd_to_ohci (hcd);
0241     struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
0242     int ret = 0;
0243 
0244     if (hcd->self.controller) {
0245         const struct pci_device_id *quirk_id;
0246 
0247         quirk_id = pci_match_id(ohci_pci_quirks, pdev);
0248         if (quirk_id != NULL) {
0249             int (*quirk)(struct usb_hcd *ohci);
0250             quirk = (void *)quirk_id->driver_data;
0251             ret = quirk(hcd);
0252         }
0253     }
0254 
0255     if (ret == 0)
0256         ret = ohci_setup(hcd);
0257     /*
0258     * After ohci setup RWC may not be set for add-in PCI cards.
0259     * This transfers PCI PM wakeup capabilities.
0260     */
0261     if (device_can_wakeup(&pdev->dev))
0262         ohci->hc_control |= OHCI_CTRL_RWC;
0263     return ret;
0264 }
0265 
0266 static struct hc_driver __read_mostly ohci_pci_hc_driver;
0267 
0268 static const struct ohci_driver_overrides pci_overrides __initconst = {
0269     .product_desc =     "OHCI PCI host controller",
0270     .reset =        ohci_pci_reset,
0271 };
0272 
0273 static const struct pci_device_id pci_ids[] = { {
0274     /* handle any USB OHCI controller */
0275     PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0),
0276     }, {
0277     /* The device in the ConneXT I/O hub has no class reg */
0278     PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_OHCI),
0279     }, { /* end: all zeroes */ }
0280 };
0281 MODULE_DEVICE_TABLE (pci, pci_ids);
0282 
0283 static int ohci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
0284 {
0285     return usb_hcd_pci_probe(dev, id, &ohci_pci_hc_driver);
0286 }
0287 
0288 /* pci driver glue; this is a "new style" PCI driver module */
0289 static struct pci_driver ohci_pci_driver = {
0290     .name =     hcd_name,
0291     .id_table = pci_ids,
0292 
0293     .probe =    ohci_pci_probe,
0294     .remove =   usb_hcd_pci_remove,
0295     .shutdown = usb_hcd_pci_shutdown,
0296 
0297 #ifdef CONFIG_PM
0298     .driver =   {
0299         .pm =   &usb_hcd_pci_pm_ops
0300     },
0301 #endif
0302 };
0303 
0304 static int __init ohci_pci_init(void)
0305 {
0306     if (usb_disabled())
0307         return -ENODEV;
0308 
0309     pr_info("%s: " DRIVER_DESC "\n", hcd_name);
0310 
0311     ohci_init_driver(&ohci_pci_hc_driver, &pci_overrides);
0312 
0313 #ifdef  CONFIG_PM
0314     /* Entries for the PCI suspend/resume callbacks are special */
0315     ohci_pci_hc_driver.pci_suspend = ohci_suspend;
0316     ohci_pci_hc_driver.pci_resume = ohci_resume;
0317 #endif
0318 
0319     return pci_register_driver(&ohci_pci_driver);
0320 }
0321 module_init(ohci_pci_init);
0322 
0323 static void __exit ohci_pci_cleanup(void)
0324 {
0325     pci_unregister_driver(&ohci_pci_driver);
0326 }
0327 module_exit(ohci_pci_cleanup);
0328 
0329 MODULE_DESCRIPTION(DRIVER_DESC);
0330 MODULE_LICENSE("GPL");
0331 MODULE_SOFTDEP("pre: ehci_pci");