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#include <linux/kernel.h>
42#include <linux/module.h>
43#include <linux/moduleparam.h>
44#include <linux/spinlock.h>
45#include <linux/interrupt.h>
46#include <linux/io.h>
47#include <linux/slab.h>
48#include <linux/pci.h>
49#include <linux/usb.h>
50
51#include <linux/usb/hcd.h>
52#include <linux/usb/ch11.h>
53#include <linux/platform_device.h>
54#include <linux/usb/usb_phy_generic.h>
55
56#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
57
58static const char dwc2_driver_name[] = "dwc2-pci";
59
60struct dwc2_pci_glue {
61 struct platform_device *dwc2;
62 struct platform_device *phy;
63};
64
65static void dwc2_pci_remove(struct pci_dev *pci)
66{
67 struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
68
69 platform_device_unregister(glue->dwc2);
70 usb_phy_generic_unregister(glue->phy);
71 kfree(glue);
72 pci_set_drvdata(pci, NULL);
73}
74
75static int dwc2_pci_probe(struct pci_dev *pci,
76 const struct pci_device_id *id)
77{
78 struct resource res[2];
79 struct platform_device *dwc2;
80 struct platform_device *phy;
81 int ret;
82 struct device *dev = &pci->dev;
83 struct dwc2_pci_glue *glue;
84
85 ret = pcim_enable_device(pci);
86 if (ret) {
87 dev_err(dev, "failed to enable pci device\n");
88 return -ENODEV;
89 }
90
91 pci_set_master(pci);
92
93 dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
94 if (!dwc2) {
95 dev_err(dev, "couldn't allocate dwc2 device\n");
96 return -ENOMEM;
97 }
98
99 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
100
101 res[0].start = pci_resource_start(pci, 0);
102 res[0].end = pci_resource_end(pci, 0);
103 res[0].name = "dwc2";
104 res[0].flags = IORESOURCE_MEM;
105
106 res[1].start = pci->irq;
107 res[1].name = "dwc2";
108 res[1].flags = IORESOURCE_IRQ;
109
110 ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
111 if (ret) {
112 dev_err(dev, "couldn't add resources to dwc2 device\n");
113 return ret;
114 }
115
116 dwc2->dev.parent = dev;
117
118 phy = usb_phy_generic_register();
119 if (IS_ERR(phy)) {
120 dev_err(dev, "error registering generic PHY (%ld)\n",
121 PTR_ERR(phy));
122 return PTR_ERR(phy);
123 }
124
125 ret = platform_device_add(dwc2);
126 if (ret) {
127 dev_err(dev, "failed to register dwc2 device\n");
128 goto err;
129 }
130
131 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
132 if (!glue)
133 return -ENOMEM;
134
135 glue->phy = phy;
136 glue->dwc2 = dwc2;
137 pci_set_drvdata(pci, glue);
138
139 return 0;
140err:
141 usb_phy_generic_unregister(phy);
142 platform_device_put(dwc2);
143 return ret;
144}
145
146static const struct pci_device_id dwc2_pci_ids[] = {
147 {
148 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
149 },
150 {
151 PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
152 PCI_DEVICE_ID_STMICRO_USB_OTG),
153 },
154 { }
155};
156MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
157
158static struct pci_driver dwc2_pci_driver = {
159 .name = dwc2_driver_name,
160 .id_table = dwc2_pci_ids,
161 .probe = dwc2_pci_probe,
162 .remove = dwc2_pci_remove,
163};
164
165module_pci_driver(dwc2_pci_driver);
166
167MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
168MODULE_AUTHOR("Synopsys, Inc.");
169MODULE_LICENSE("Dual BSD/GPL");
170