Linux 4.19.133
[linux/fpc-iii.git] / drivers / usb / dwc3 / dwc3-haps.c
blob02d57d98ef9bd41190257a9d05ca028cb07c0fd1
1 // SPDX-License-Identifier: GPL-2.0
2 /**
3 * dwc3-haps.c - Synopsys HAPS PCI Specific glue layer
5 * Copyright (C) 2018 Synopsys, Inc.
7 * Authors: Thinh Nguyen <thinhn@synopsys.com>,
8 * John Youn <johnyoun@synopsys.com>
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/pci.h>
15 #include <linux/platform_device.h>
16 #include <linux/property.h>
18 /**
19 * struct dwc3_haps - Driver private structure
20 * @dwc3: child dwc3 platform_device
21 * @pci: our link to PCI bus
23 struct dwc3_haps {
24 struct platform_device *dwc3;
25 struct pci_dev *pci;
28 static const struct property_entry initial_properties[] = {
29 PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
30 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
31 PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
32 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
33 { },
36 static int dwc3_haps_probe(struct pci_dev *pci,
37 const struct pci_device_id *id)
39 struct dwc3_haps *dwc;
40 struct device *dev = &pci->dev;
41 struct resource res[2];
42 int ret;
44 ret = pcim_enable_device(pci);
45 if (ret) {
46 dev_err(dev, "failed to enable pci device\n");
47 return -ENODEV;
50 pci_set_master(pci);
52 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
53 if (!dwc)
54 return -ENOMEM;
56 dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
57 if (!dwc->dwc3)
58 return -ENOMEM;
60 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
62 res[0].start = pci_resource_start(pci, 0);
63 res[0].end = pci_resource_end(pci, 0);
64 res[0].name = "dwc_usb3";
65 res[0].flags = IORESOURCE_MEM;
67 res[1].start = pci->irq;
68 res[1].name = "dwc_usb3";
69 res[1].flags = IORESOURCE_IRQ;
71 ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
72 if (ret) {
73 dev_err(dev, "couldn't add resources to dwc3 device\n");
74 goto err;
77 dwc->pci = pci;
78 dwc->dwc3->dev.parent = dev;
80 ret = platform_device_add_properties(dwc->dwc3, initial_properties);
81 if (ret)
82 goto err;
84 ret = platform_device_add(dwc->dwc3);
85 if (ret) {
86 dev_err(dev, "failed to register dwc3 device\n");
87 goto err;
90 pci_set_drvdata(pci, dwc);
92 return 0;
93 err:
94 platform_device_put(dwc->dwc3);
95 return ret;
98 static void dwc3_haps_remove(struct pci_dev *pci)
100 struct dwc3_haps *dwc = pci_get_drvdata(pci);
102 platform_device_unregister(dwc->dwc3);
105 static const struct pci_device_id dwc3_haps_id_table[] = {
107 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
108 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
111 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
112 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
115 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
116 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
118 { } /* Terminating Entry */
120 MODULE_DEVICE_TABLE(pci, dwc3_haps_id_table);
122 static struct pci_driver dwc3_haps_driver = {
123 .name = "dwc3-haps",
124 .id_table = dwc3_haps_id_table,
125 .probe = dwc3_haps_probe,
126 .remove = dwc3_haps_remove,
129 MODULE_AUTHOR("Thinh Nguyen <thinhn@synopsys.com>");
130 MODULE_LICENSE("GPL v2");
131 MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer");
133 module_pci_driver(dwc3_haps_driver);