aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3
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
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')
-rw-r--r--drivers/usb/dwc3/core.c42
-rw-r--r--drivers/usb/dwc3/core.h3
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c45
3 files changed, 50 insertions, 40 deletions
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index d55d84db2be..83e382b4ae2 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -63,6 +63,48 @@ static char *maximum_speed = "super";
63module_param(maximum_speed, charp, 0); 63module_param(maximum_speed, charp, 0);
64MODULE_PARM_DESC(maximum_speed, "Maximum supported speed."); 64MODULE_PARM_DESC(maximum_speed, "Maximum supported speed.");
65 65
66/* -------------------------------------------------------------------------- */
67
68#define DWC3_DEVS_POSSIBLE 32
69
70static DECLARE_BITMAP(dwc3_devs, DWC3_DEVS_POSSIBLE);
71
72int dwc3_get_device_id(void)
73{
74 int id;
75
76again:
77 id = find_first_zero_bit(dwc3_devs, DWC3_DEVS_POSSIBLE);
78 if (id < DWC3_DEVS_POSSIBLE) {
79 int old;
80
81 old = test_and_set_bit(id, dwc3_devs);
82 if (old)
83 goto again;
84 } else {
85 pr_err("dwc3: no space for new device\n");
86 id = -ENOMEM;
87 }
88
89 return 0;
90}
91EXPORT_SYMBOL_GPL(dwc3_get_device_id);
92
93void dwc3_put_device_id(int id)
94{
95 int ret;
96
97 if (id < 0)
98 return;
99
100 ret = test_bit(id, dwc3_devs);
101 WARN(!ret, "dwc3: ID %d not in use\n", id);
102 clear_bit(id, dwc3_devs);
103}
104EXPORT_SYMBOL_GPL(dwc3_put_device_id);
105
106/* -------------------------------------------------------------------------- */
107
66/** 108/**
67 * dwc3_core_soft_reset - Issues core soft reset and PHY reset 109 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
68 * @dwc: pointer to our context structure 110 * @dwc: pointer to our context structure
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index bebb5e1530a..95d5a87b409 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -793,4 +793,7 @@ void dwc3_host_exit(struct dwc3 *dwc);
793int dwc3_gadget_init(struct dwc3 *dwc); 793int dwc3_gadget_init(struct dwc3 *dwc);
794void dwc3_gadget_exit(struct dwc3 *dwc); 794void dwc3_gadget_exit(struct dwc3 *dwc);
795 795
796extern int dwc3_get_device_id(void);
797extern void dwc3_put_device_id(int id);
798
796#endif /* __DRIVERS_USB_DWC3_CORE_H */ 799#endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 193f1bd90d5..cd1429f168c 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);