This source file includes following definitions.
- dwc2_pci_quirks
- dwc2_pci_remove
- dwc2_pci_probe
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 
  27 
  28 
  29 
  30 
  31 
  32 
  33 
  34 
  35 
  36 
  37 
  38 
  39 
  40 
  41 
  42 #include <linux/kernel.h>
  43 #include <linux/module.h>
  44 #include <linux/moduleparam.h>
  45 #include <linux/spinlock.h>
  46 #include <linux/interrupt.h>
  47 #include <linux/io.h>
  48 #include <linux/slab.h>
  49 #include <linux/pci.h>
  50 #include <linux/usb.h>
  51 
  52 #include <linux/usb/hcd.h>
  53 #include <linux/usb/ch11.h>
  54 #include <linux/platform_device.h>
  55 #include <linux/usb/usb_phy_generic.h>
  56 
  57 #define PCI_PRODUCT_ID_HAPS_HSOTG       0xabc0
  58 
  59 static const char dwc2_driver_name[] = "dwc2-pci";
  60 
  61 struct dwc2_pci_glue {
  62         struct platform_device *dwc2;
  63         struct platform_device *phy;
  64 };
  65 
  66 static int dwc2_pci_quirks(struct pci_dev *pdev, struct platform_device *dwc2)
  67 {
  68         if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
  69             pdev->device == PCI_PRODUCT_ID_HAPS_HSOTG) {
  70                 struct property_entry properties[] = {
  71                         { },
  72                 };
  73 
  74                 return platform_device_add_properties(dwc2, properties);
  75         }
  76 
  77         return 0;
  78 }
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 static void dwc2_pci_remove(struct pci_dev *pci)
  87 {
  88         struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
  89 
  90         platform_device_unregister(glue->dwc2);
  91         usb_phy_generic_unregister(glue->phy);
  92         pci_set_drvdata(pci, NULL);
  93 }
  94 
  95 static int dwc2_pci_probe(struct pci_dev *pci,
  96                           const struct pci_device_id *id)
  97 {
  98         struct resource         res[2];
  99         struct platform_device  *dwc2;
 100         struct platform_device  *phy;
 101         int                     ret;
 102         struct device           *dev = &pci->dev;
 103         struct dwc2_pci_glue    *glue;
 104 
 105         ret = pcim_enable_device(pci);
 106         if (ret) {
 107                 dev_err(dev, "failed to enable pci device\n");
 108                 return -ENODEV;
 109         }
 110 
 111         pci_set_master(pci);
 112 
 113         phy = usb_phy_generic_register();
 114         if (IS_ERR(phy)) {
 115                 dev_err(dev, "error registering generic PHY (%ld)\n",
 116                         PTR_ERR(phy));
 117                 return PTR_ERR(phy);
 118         }
 119 
 120         dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
 121         if (!dwc2) {
 122                 dev_err(dev, "couldn't allocate dwc2 device\n");
 123                 ret = -ENOMEM;
 124                 goto err;
 125         }
 126 
 127         memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
 128 
 129         res[0].start    = pci_resource_start(pci, 0);
 130         res[0].end      = pci_resource_end(pci, 0);
 131         res[0].name     = "dwc2";
 132         res[0].flags    = IORESOURCE_MEM;
 133 
 134         res[1].start    = pci->irq;
 135         res[1].name     = "dwc2";
 136         res[1].flags    = IORESOURCE_IRQ;
 137 
 138         ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
 139         if (ret) {
 140                 dev_err(dev, "couldn't add resources to dwc2 device\n");
 141                 goto err;
 142         }
 143 
 144         dwc2->dev.parent = dev;
 145 
 146         ret = dwc2_pci_quirks(pci, dwc2);
 147         if (ret)
 148                 goto err;
 149 
 150         glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
 151         if (!glue) {
 152                 ret = -ENOMEM;
 153                 goto err;
 154         }
 155 
 156         ret = platform_device_add(dwc2);
 157         if (ret) {
 158                 dev_err(dev, "failed to register dwc2 device\n");
 159                 goto err;
 160         }
 161 
 162         glue->phy = phy;
 163         glue->dwc2 = dwc2;
 164         pci_set_drvdata(pci, glue);
 165 
 166         return 0;
 167 err:
 168         usb_phy_generic_unregister(phy);
 169         platform_device_put(dwc2);
 170         return ret;
 171 }
 172 
 173 static const struct pci_device_id dwc2_pci_ids[] = {
 174         {
 175                 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
 176         },
 177         {
 178                 PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
 179                            PCI_DEVICE_ID_STMICRO_USB_OTG),
 180         },
 181         {  }
 182 };
 183 MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
 184 
 185 static struct pci_driver dwc2_pci_driver = {
 186         .name = dwc2_driver_name,
 187         .id_table = dwc2_pci_ids,
 188         .probe = dwc2_pci_probe,
 189         .remove = dwc2_pci_remove,
 190 };
 191 
 192 module_pci_driver(dwc2_pci_driver);
 193 
 194 MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
 195 MODULE_AUTHOR("Synopsys, Inc.");
 196 MODULE_LICENSE("Dual BSD/GPL");