1 // SPDX-License-Identifier: GPL-2.0
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>
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 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
19 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
20 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
23 * struct dwc3_haps - Driver private structure
24 * @dwc3: child dwc3 platform_device
25 * @pci: our link to PCI bus
28 struct platform_device
*dwc3
;
32 static const struct property_entry initial_properties
[] = {
33 PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
34 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
35 PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
36 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
40 static int dwc3_haps_probe(struct pci_dev
*pci
,
41 const struct pci_device_id
*id
)
43 struct dwc3_haps
*dwc
;
44 struct device
*dev
= &pci
->dev
;
45 struct resource res
[2];
48 ret
= pcim_enable_device(pci
);
50 dev_err(dev
, "failed to enable pci device\n");
56 dwc
= devm_kzalloc(dev
, sizeof(*dwc
), GFP_KERNEL
);
60 dwc
->dwc3
= platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO
);
64 memset(res
, 0x00, sizeof(struct resource
) * ARRAY_SIZE(res
));
66 res
[0].start
= pci_resource_start(pci
, 0);
67 res
[0].end
= pci_resource_end(pci
, 0);
68 res
[0].name
= "dwc_usb3";
69 res
[0].flags
= IORESOURCE_MEM
;
71 res
[1].start
= pci
->irq
;
72 res
[1].name
= "dwc_usb3";
73 res
[1].flags
= IORESOURCE_IRQ
;
75 ret
= platform_device_add_resources(dwc
->dwc3
, res
, ARRAY_SIZE(res
));
77 dev_err(dev
, "couldn't add resources to dwc3 device\n");
82 dwc
->dwc3
->dev
.parent
= dev
;
84 ret
= platform_device_add_properties(dwc
->dwc3
, initial_properties
);
88 ret
= platform_device_add(dwc
->dwc3
);
90 dev_err(dev
, "failed to register dwc3 device\n");
94 pci_set_drvdata(pci
, dwc
);
98 platform_device_put(dwc
->dwc3
);
102 static void dwc3_haps_remove(struct pci_dev
*pci
)
104 struct dwc3_haps
*dwc
= pci_get_drvdata(pci
);
106 platform_device_unregister(dwc
->dwc3
);
109 static const struct pci_device_id dwc3_haps_id_table
[] = {
111 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS
,
112 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3
),
115 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS
,
116 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI
),
119 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS
,
120 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31
),
122 { } /* Terminating Entry */
124 MODULE_DEVICE_TABLE(pci
, dwc3_haps_id_table
);
126 static struct pci_driver dwc3_haps_driver
= {
128 .id_table
= dwc3_haps_id_table
,
129 .probe
= dwc3_haps_probe
,
130 .remove
= dwc3_haps_remove
,
133 MODULE_AUTHOR("Thinh Nguyen <thinhn@synopsys.com>");
134 MODULE_LICENSE("GPL v2");
135 MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer");
137 module_pci_driver(dwc3_haps_driver
);