]>
Commit | Line | Data |
---|---|---|
5fd54ace | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
99882e3f PZ |
2 | /* |
3 | * pci.c - DesignWare HS OTG Controller PCI driver | |
4 | * | |
5 | * Copyright (C) 2004-2013 Synopsys, Inc. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions, and the following disclaimer, | |
12 | * without modification. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. The names of the above-listed copyright holders may not be used | |
17 | * to endorse or promote products derived from this software without | |
18 | * specific prior written permission. | |
19 | * | |
20 | * ALTERNATIVELY, this software may be distributed under the terms of the | |
21 | * GNU General Public License ("GPL") as published by the Free Software | |
22 | * Foundation; either version 2 of the License, or (at your option) any | |
23 | * later version. | |
24 | * | |
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
26 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
27 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
29 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
30 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
31 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
32 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | /* | |
39 | * Provides the initialization and cleanup entry points for the DWC_otg PCI | |
40 | * driver | |
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> | |
9024c495 JY |
54 | #include <linux/platform_device.h> |
55 | #include <linux/usb/usb_phy_generic.h> | |
99882e3f | 56 | |
99882e3f PZ |
57 | #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 |
58 | ||
9024c495 JY |
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; | |
99882e3f PZ |
64 | }; |
65 | ||
ced8a03c VA |
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[] = { | |
ced8a03c VA |
71 | { }, |
72 | }; | |
73 | ||
74 | return platform_device_add_properties(dwc2, properties); | |
75 | } | |
76 | ||
77 | return 0; | |
78 | } | |
79 | ||
9024c495 | 80 | static void dwc2_pci_remove(struct pci_dev *pci) |
99882e3f | 81 | { |
9024c495 | 82 | struct dwc2_pci_glue *glue = pci_get_drvdata(pci); |
99882e3f | 83 | |
9024c495 JY |
84 | platform_device_unregister(glue->dwc2); |
85 | usb_phy_generic_unregister(glue->phy); | |
86 | kfree(glue); | |
87 | pci_set_drvdata(pci, NULL); | |
99882e3f PZ |
88 | } |
89 | ||
9024c495 | 90 | static int dwc2_pci_probe(struct pci_dev *pci, |
9da51974 | 91 | const struct pci_device_id *id) |
99882e3f | 92 | { |
9024c495 JY |
93 | struct resource res[2]; |
94 | struct platform_device *dwc2; | |
95 | struct platform_device *phy; | |
96 | int ret; | |
97 | struct device *dev = &pci->dev; | |
98 | struct dwc2_pci_glue *glue; | |
99 | ||
100 | ret = pcim_enable_device(pci); | |
101 | if (ret) { | |
102 | dev_err(dev, "failed to enable pci device\n"); | |
103 | return -ENODEV; | |
104 | } | |
105 | ||
106 | pci_set_master(pci); | |
99882e3f | 107 | |
9024c495 JY |
108 | dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO); |
109 | if (!dwc2) { | |
110 | dev_err(dev, "couldn't allocate dwc2 device\n"); | |
99882e3f | 111 | return -ENOMEM; |
9024c495 | 112 | } |
99882e3f | 113 | |
9024c495 | 114 | memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); |
99882e3f | 115 | |
9024c495 JY |
116 | res[0].start = pci_resource_start(pci, 0); |
117 | res[0].end = pci_resource_end(pci, 0); | |
118 | res[0].name = "dwc2"; | |
119 | res[0].flags = IORESOURCE_MEM; | |
99882e3f | 120 | |
9024c495 JY |
121 | res[1].start = pci->irq; |
122 | res[1].name = "dwc2"; | |
123 | res[1].flags = IORESOURCE_IRQ; | |
99882e3f | 124 | |
9024c495 JY |
125 | ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res)); |
126 | if (ret) { | |
127 | dev_err(dev, "couldn't add resources to dwc2 device\n"); | |
128 | return ret; | |
129 | } | |
99882e3f | 130 | |
9024c495 | 131 | dwc2->dev.parent = dev; |
db8178c3 | 132 | |
9024c495 JY |
133 | phy = usb_phy_generic_register(); |
134 | if (IS_ERR(phy)) { | |
135 | dev_err(dev, "error registering generic PHY (%ld)\n", | |
136 | PTR_ERR(phy)); | |
137 | return PTR_ERR(phy); | |
99882e3f PZ |
138 | } |
139 | ||
ced8a03c VA |
140 | ret = dwc2_pci_quirks(pci, dwc2); |
141 | if (ret) | |
142 | goto err; | |
143 | ||
9024c495 JY |
144 | ret = platform_device_add(dwc2); |
145 | if (ret) { | |
146 | dev_err(dev, "failed to register dwc2 device\n"); | |
147 | goto err; | |
148 | } | |
149 | ||
150 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | |
151 | if (!glue) | |
152 | return -ENOMEM; | |
153 | ||
154 | glue->phy = phy; | |
155 | glue->dwc2 = dwc2; | |
156 | pci_set_drvdata(pci, glue); | |
99882e3f | 157 | |
9024c495 JY |
158 | return 0; |
159 | err: | |
160 | usb_phy_generic_unregister(phy); | |
161 | platform_device_put(dwc2); | |
162 | return ret; | |
99882e3f PZ |
163 | } |
164 | ||
41e043fc | 165 | static const struct pci_device_id dwc2_pci_ids[] = { |
99882e3f PZ |
166 | { |
167 | PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), | |
168 | }, | |
25f73e62 FV |
169 | { |
170 | PCI_DEVICE(PCI_VENDOR_ID_STMICRO, | |
171 | PCI_DEVICE_ID_STMICRO_USB_OTG), | |
172 | }, | |
99882e3f PZ |
173 | { /* end: all zeroes */ } |
174 | }; | |
175 | MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); | |
176 | ||
177 | static struct pci_driver dwc2_pci_driver = { | |
178 | .name = dwc2_driver_name, | |
179 | .id_table = dwc2_pci_ids, | |
9024c495 JY |
180 | .probe = dwc2_pci_probe, |
181 | .remove = dwc2_pci_remove, | |
99882e3f PZ |
182 | }; |
183 | ||
184 | module_pci_driver(dwc2_pci_driver); | |
185 | ||
186 | MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); | |
187 | MODULE_AUTHOR("Synopsys, Inc."); | |
188 | MODULE_LICENSE("Dual BSD/GPL"); |