diff options
author | Felipe Balbi <balbi@ti.com> | 2011-10-18 13:54:01 +0300 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2011-12-12 11:48:21 +0200 |
commit | 8300dd236e957429acfb36be0ce8fe276dbe823c (patch) | |
tree | a8ed42c6ed57f396b49f807eb6bef4abbcfc8c3f /drivers/usb/dwc3/core.c | |
parent | 8ee6270c7f0aeba07355eee82d687efcd8ca9d39 (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/core.c')
-rw-r--r-- | drivers/usb/dwc3/core.c | 42 |
1 files changed, 42 insertions, 0 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"; module_param(maximum_speed, charp, 0); MODULE_PARM_DESC(maximum_speed, "Maximum supported speed."); +/* -------------------------------------------------------------------------- */ + +#define DWC3_DEVS_POSSIBLE 32 + +static DECLARE_BITMAP(dwc3_devs, DWC3_DEVS_POSSIBLE); + +int dwc3_get_device_id(void) +{ + int id; + +again: + id = find_first_zero_bit(dwc3_devs, DWC3_DEVS_POSSIBLE); + if (id < DWC3_DEVS_POSSIBLE) { + int old; + + old = test_and_set_bit(id, dwc3_devs); + if (old) + goto again; + } else { + pr_err("dwc3: no space for new device\n"); + id = -ENOMEM; + } + + return 0; +} +EXPORT_SYMBOL_GPL(dwc3_get_device_id); + +void dwc3_put_device_id(int id) +{ + int ret; + + if (id < 0) + return; + + ret = test_bit(id, dwc3_devs); + WARN(!ret, "dwc3: ID %d not in use\n", id); + clear_bit(id, dwc3_devs); +} +EXPORT_SYMBOL_GPL(dwc3_put_device_id); + +/* -------------------------------------------------------------------------- */ + /** * dwc3_core_soft_reset - Issues core soft reset and PHY reset * @dwc: pointer to our context structure |