diff options
Diffstat (limited to 'drivers/usb/dwc3/dwc3-pci.c')
-rw-r--r-- | drivers/usb/dwc3/dwc3-pci.c | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index f77c00042685..64e1f7c67b08 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 | |||
51 | struct dwc3_pci { | 51 | struct dwc3_pci { |
52 | struct device *dev; | 52 | struct device *dev; |
53 | struct platform_device *dwc3; | 53 | struct platform_device *dwc3; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | static DECLARE_BITMAP(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE); | ||
57 | |||
58 | static int dwc3_pci_get_device_id(struct dwc3_pci *glue) | ||
59 | { | ||
60 | int id; | ||
61 | |||
62 | again: | ||
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 | |||
78 | static 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 | |||
91 | static int __devinit dwc3_pci_probe(struct pci_dev *pci, | 56 | static 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,11 +79,11 @@ 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 | ||
121 | dwc3 = platform_device_alloc("dwc3-pci", devid); | 86 | dwc3 = platform_device_alloc("dwc3", devid); |
122 | if (!dwc3) { | 87 | if (!dwc3) { |
123 | dev_err(&pci->dev, "couldn't allocate dwc3 device\n"); | 88 | dev_err(&pci->dev, "couldn't allocate dwc3 device\n"); |
124 | goto err3; | 89 | goto err3; |
@@ -163,13 +128,13 @@ err4: | |||
163 | platform_device_put(dwc3); | 128 | platform_device_put(dwc3); |
164 | 129 | ||
165 | err3: | 130 | err3: |
166 | dwc3_pci_put_device_id(glue, devid); | 131 | dwc3_put_device_id(devid); |
167 | 132 | ||
168 | err2: | 133 | err2: |
169 | pci_disable_device(pci); | 134 | pci_disable_device(pci); |
170 | 135 | ||
171 | err1: | 136 | err1: |
172 | kfree(pci); | 137 | kfree(glue); |
173 | 138 | ||
174 | err0: | 139 | err0: |
175 | return ret; | 140 | return ret; |
@@ -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); |
@@ -196,7 +161,7 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = { | |||
196 | MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); | 161 | MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); |
197 | 162 | ||
198 | static struct pci_driver dwc3_pci_driver = { | 163 | static struct pci_driver dwc3_pci_driver = { |
199 | .name = "pci-dwc3", | 164 | .name = "dwc3-pci", |
200 | .id_table = dwc3_pci_id_table, | 165 | .id_table = dwc3_pci_id_table, |
201 | .probe = dwc3_pci_probe, | 166 | .probe = dwc3_pci_probe, |
202 | .remove = __devexit_p(dwc3_pci_remove), | 167 | .remove = __devexit_p(dwc3_pci_remove), |