aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3/dwc3-pci.c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2011-10-18 06:54:01 -0400
committerFelipe Balbi <balbi@ti.com>2011-12-12 04:48:21 -0500
commit8300dd236e957429acfb36be0ce8fe276dbe823c (patch)
treea8ed42c6ed57f396b49f807eb6bef4abbcfc8c3f /drivers/usb/dwc3/dwc3-pci.c
parent8ee6270c7f0aeba07355eee82d687efcd8ca9d39 (diff)
usb: dwc3: move dwc3 device ID bitmap to core.c
if we want to support situations where we have both SoC and PCIe versions of the IP on the same platform, we need to have sequential numbers between them, otherwise we will still have name collisions. Because of that, we need to move dwc3_get/put_device_id() to core.c and export that symbol to be used by glue layers. Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3/dwc3-pci.c')
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c45
1 files changed, 5 insertions, 40 deletions
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 193f1bd90d59..cd1429f168c2 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -42,52 +42,17 @@
42#include <linux/pci.h> 42#include <linux/pci.h>
43#include <linux/platform_device.h> 43#include <linux/platform_device.h>
44 44
45#include "core.h"
46
45/* FIXME define these in <linux/pci_ids.h> */ 47/* FIXME define these in <linux/pci_ids.h> */
46#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 48#define PCI_VENDOR_ID_SYNOPSYS 0x16c3
47#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 49#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
48 50
49#define DWC3_PCI_DEVS_POSSIBLE 32
50
51struct dwc3_pci { 51struct dwc3_pci {
52 struct device *dev; 52 struct device *dev;
53 struct platform_device *dwc3; 53 struct platform_device *dwc3;
54}; 54};
55 55
56static DECLARE_BITMAP(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE);
57
58static int dwc3_pci_get_device_id(struct dwc3_pci *glue)
59{
60 int id;
61
62again:
63 id = find_first_zero_bit(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE);
64 if (id < DWC3_PCI_DEVS_POSSIBLE) {
65 int old;
66
67 old = test_and_set_bit(id, dwc3_pci_devs);
68 if (old)
69 goto again;
70 } else {
71 dev_err(glue->dev, "no space for new device\n");
72 id = -ENOMEM;
73 }
74
75 return 0;
76}
77
78static void dwc3_pci_put_device_id(struct dwc3_pci *glue, int id)
79{
80 int ret;
81
82 if (id < 0)
83 return;
84
85 ret = test_bit(id, dwc3_pci_devs);
86 WARN(!ret, "Device: %s\nID %d not in use\n",
87 dev_driver_string(glue->dev), id);
88 clear_bit(id, dwc3_pci_devs);
89}
90
91static int __devinit dwc3_pci_probe(struct pci_dev *pci, 56static int __devinit dwc3_pci_probe(struct pci_dev *pci,
92 const struct pci_device_id *id) 57 const struct pci_device_id *id)
93{ 58{
@@ -114,7 +79,7 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
114 pci_set_power_state(pci, PCI_D0); 79 pci_set_power_state(pci, PCI_D0);
115 pci_set_master(pci); 80 pci_set_master(pci);
116 81
117 devid = dwc3_pci_get_device_id(glue); 82 devid = dwc3_get_device_id();
118 if (devid < 0) 83 if (devid < 0)
119 goto err2; 84 goto err2;
120 85
@@ -163,7 +128,7 @@ err4:
163 platform_device_put(dwc3); 128 platform_device_put(dwc3);
164 129
165err3: 130err3:
166 dwc3_pci_put_device_id(glue, devid); 131 dwc3_put_device_id(devid);
167 132
168err2: 133err2:
169 pci_disable_device(pci); 134 pci_disable_device(pci);
@@ -179,7 +144,7 @@ static void __devexit dwc3_pci_remove(struct pci_dev *pci)
179{ 144{
180 struct dwc3_pci *glue = pci_get_drvdata(pci); 145 struct dwc3_pci *glue = pci_get_drvdata(pci);
181 146
182 dwc3_pci_put_device_id(glue, glue->dwc3->id); 147 dwc3_put_device_id(glue->dwc3->id);
183 platform_device_unregister(glue->dwc3); 148 platform_device_unregister(glue->dwc3);
184 pci_set_drvdata(pci, NULL); 149 pci_set_drvdata(pci, NULL);
185 pci_disable_device(pci); 150 pci_disable_device(pci);