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 int dwc2_pci_quirks(struct pci_dev *pdev, struct platform_device *dwc2)
66{
67 if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
68 pdev->device == PCI_PRODUCT_ID_HAPS_HSOTG) {
69 struct property_entry properties[] = {
70 { },
71 };
72
73 return platform_device_add_properties(dwc2, properties);
74 }
75
76 return 0;
77}
78
79static void dwc2_pci_remove(struct pci_dev *pci)
80{
81 struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
82
83 platform_device_unregister(glue->dwc2);
84 usb_phy_generic_unregister(glue->phy);
85 kfree(glue);
86 pci_set_drvdata(pci, NULL);
87}
88
89static int dwc2_pci_probe(struct pci_dev *pci,
90 const struct pci_device_id *id)
91{
92 struct resource res[2];
93 struct platform_device *dwc2;
94 struct platform_device *phy;
95 int ret;
96 struct device *dev = &pci->dev;
97 struct dwc2_pci_glue *glue;
98
99 ret = pcim_enable_device(pci);
100 if (ret) {
101 dev_err(dev, "failed to enable pci device\n");
102 return -ENODEV;
103 }
104
105 pci_set_master(pci);
106
107 dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
108 if (!dwc2) {
109 dev_err(dev, "couldn't allocate dwc2 device\n");
110 return -ENOMEM;
111 }
112
113 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
114
115 res[0].start = pci_resource_start(pci, 0);
116 res[0].end = pci_resource_end(pci, 0);
117 res[0].name = "dwc2";
118 res[0].flags = IORESOURCE_MEM;
119
120 res[1].start = pci->irq;
121 res[1].name = "dwc2";
122 res[1].flags = IORESOURCE_IRQ;
123
124 ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
125 if (ret) {
126 dev_err(dev, "couldn't add resources to dwc2 device\n");
127 return ret;
128 }
129
130 dwc2->dev.parent = dev;
131
132 phy = usb_phy_generic_register();
133 if (IS_ERR(phy)) {
134 dev_err(dev, "error registering generic PHY (%ld)\n",
135 PTR_ERR(phy));
136 return PTR_ERR(phy);
137 }
138
139 ret = dwc2_pci_quirks(pci, dwc2);
140 if (ret)
141 goto err;
142
143 ret = platform_device_add(dwc2);
144 if (ret) {
145 dev_err(dev, "failed to register dwc2 device\n");
146 goto err;
147 }
148
149 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
150 if (!glue)
151 return -ENOMEM;
152
153 glue->phy = phy;
154 glue->dwc2 = dwc2;
155 pci_set_drvdata(pci, glue);
156
157 return 0;
158err:
159 usb_phy_generic_unregister(phy);
160 platform_device_put(dwc2);
161 return ret;
162}
163
164static const struct pci_device_id dwc2_pci_ids[] = {
165 {
166 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
167 },
168 {
169 PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
170 PCI_DEVICE_ID_STMICRO_USB_OTG),
171 },
172 { }
173};
174MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
175
176static struct pci_driver dwc2_pci_driver = {
177 .name = dwc2_driver_name,
178 .id_table = dwc2_pci_ids,
179 .probe = dwc2_pci_probe,
180 .remove = dwc2_pci_remove,
181};
182
183module_pci_driver(dwc2_pci_driver);
184
185MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
186MODULE_AUTHOR("Synopsys, Inc.");
187MODULE_LICENSE("Dual BSD/GPL");
188