blob: fdeb8c7bf30a8f790348eb9f01df24f16db47d63 [file] [log] [blame]
Paul Zimmerman99882e32013-03-11 17:48:01 -07001/*
2 * pci.c - DesignWare HS OTG Controller PCI driver
3 *
4 * Copyright (C) 2004-2013 Synopsys, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the above-listed copyright holders may not be used
16 * to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * ALTERNATIVELY, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") as published by the Free Software
21 * Foundation; either version 2 of the License, or (at your option) any
22 * later version.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37/*
38 * Provides the initialization and cleanup entry points for the DWC_otg PCI
39 * driver
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>
John Youn9024c492015-03-03 17:17:49 -080053#include <linux/platform_device.h>
54#include <linux/usb/usb_phy_generic.h>
Paul Zimmerman99882e32013-03-11 17:48:01 -070055
Paul Zimmerman99882e32013-03-11 17:48:01 -070056#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
57
John Youn9024c492015-03-03 17:17:49 -080058static const char dwc2_driver_name[] = "dwc2-pci";
Paul Zimmerman99882e32013-03-11 17:48:01 -070059
John Youn9024c492015-03-03 17:17:49 -080060struct dwc2_pci_glue {
61 struct platform_device *dwc2;
62 struct platform_device *phy;
Paul Zimmerman99882e32013-03-11 17:48:01 -070063};
64
Vahram Aharonyanced8a032016-11-03 17:56:15 -070065static 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[] = {
Vahram Aharonyanced8a032016-11-03 17:56:15 -070070 { },
71 };
72
73 return platform_device_add_properties(dwc2, properties);
74 }
75
76 return 0;
77}
78
John Youn9024c492015-03-03 17:17:49 -080079static void dwc2_pci_remove(struct pci_dev *pci)
Paul Zimmerman99882e32013-03-11 17:48:01 -070080{
John Youn9024c492015-03-03 17:17:49 -080081 struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
Paul Zimmerman99882e32013-03-11 17:48:01 -070082
John Youn9024c492015-03-03 17:17:49 -080083 platform_device_unregister(glue->dwc2);
84 usb_phy_generic_unregister(glue->phy);
85 kfree(glue);
86 pci_set_drvdata(pci, NULL);
Paul Zimmerman99882e32013-03-11 17:48:01 -070087}
88
John Youn9024c492015-03-03 17:17:49 -080089static int dwc2_pci_probe(struct pci_dev *pci,
John Youn9da51972017-01-17 20:30:27 -080090 const struct pci_device_id *id)
Paul Zimmerman99882e32013-03-11 17:48:01 -070091{
John Youn9024c492015-03-03 17:17:49 -080092 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;
Paul Zimmerman99882e32013-03-11 17:48:01 -070098
John Youn9024c492015-03-03 17:17:49 -080099 ret = pcim_enable_device(pci);
100 if (ret) {
101 dev_err(dev, "failed to enable pci device\n");
Paul Zimmerman99882e32013-03-11 17:48:01 -0700102 return -ENODEV;
Paul Zimmerman99882e32013-03-11 17:48:01 -0700103 }
104
John Youn9024c492015-03-03 17:17:49 -0800105 pci_set_master(pci);
Paul Zimmerman99882e32013-03-11 17:48:01 -0700106
John Youn9024c492015-03-03 17:17:49 -0800107 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
Vahram Aharonyanced8a032016-11-03 17:56:15 -0700139 ret = dwc2_pci_quirks(pci, dwc2);
140 if (ret)
141 goto err;
142
John Youn9024c492015-03-03 17:17:49 -0800143 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;
Paul Zimmerman99882e32013-03-11 17:48:01 -0700162}
163
Jingoo Han41e043f2013-12-03 08:26:00 +0900164static const struct pci_device_id dwc2_pci_ids[] = {
Paul Zimmerman99882e32013-03-11 17:48:01 -0700165 {
166 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
167 },
Federico Vaga25f73e62013-05-13 19:54:12 +0200168 {
169 PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
170 PCI_DEVICE_ID_STMICRO_USB_OTG),
171 },
Paul Zimmerman99882e32013-03-11 17:48:01 -0700172 { /* end: all zeroes */ }
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,
John Youn9024c492015-03-03 17:17:49 -0800179 .probe = dwc2_pci_probe,
180 .remove = dwc2_pci_remove,
Paul Zimmerman99882e32013-03-11 17:48:01 -0700181};
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");