summaryrefslogtreecommitdiffstats
path: root/drivers/usb/chipidea/core.c
diff options
context:
space:
mode:
authorRichard Zhao <richard.zhao@freescale.com>2012-07-07 22:56:42 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-09 09:53:44 -0700
commitfe6e125e30fb9d93fdfc5e3e3702b9c7c3076194 (patch)
treee88ebed6c65ca251a5563a64c86e8d2b8e27916b /drivers/usb/chipidea/core.c
parentcbc6dc2af39e1395564445fd71cfcc1c70a96277 (diff)
downloadblackbird-obmc-linux-fe6e125e30fb9d93fdfc5e3e3702b9c7c3076194.tar.gz
blackbird-obmc-linux-fe6e125e30fb9d93fdfc5e3e3702b9c7c3076194.zip
USB: Chipidea: add ci13xxx device id management
We use ida_simple_get and ida_simple_remove to manage the ids. Signed-off-by: Richard Zhao <richard.zhao@freescale.com> Reviewed-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/chipidea/core.c')
-rw-r--r--drivers/usb/chipidea/core.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 8b9d06fd0325..39603d7b7916 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -56,6 +56,7 @@
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/module.h>
+#include <linux/idr.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/irq.h>
@@ -332,17 +333,24 @@ static irqreturn_t ci_irq(int irq, void *data)
return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci);
}
+static DEFINE_IDA(ci_ida);
+
struct platform_device *ci13xxx_add_device(struct device *dev,
struct resource *res, int nres,
struct ci13xxx_platform_data *platdata)
{
struct platform_device *pdev;
- int ret;
+ int id, ret;
- /* FIXME: find a way to choose id */
- pdev = platform_device_alloc("ci_hdrc", -1);
- if (!pdev)
- return ERR_PTR(-ENOMEM);
+ id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
+ if (id < 0)
+ return ERR_PTR(id);
+
+ pdev = platform_device_alloc("ci_hdrc", id);
+ if (!pdev) {
+ ret = -ENOMEM;
+ goto put_id;
+ }
pdev->dev.parent = dev;
pdev->dev.dma_mask = dev->dma_mask;
@@ -365,6 +373,8 @@ struct platform_device *ci13xxx_add_device(struct device *dev,
err:
platform_device_put(pdev);
+put_id:
+ ida_simple_remove(&ci_ida, id);
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(ci13xxx_add_device);
@@ -372,6 +382,7 @@ EXPORT_SYMBOL_GPL(ci13xxx_add_device);
void ci13xxx_remove_device(struct platform_device *pdev)
{
platform_device_unregister(pdev);
+ ida_simple_remove(&ci_ida, pdev->id);
}
EXPORT_SYMBOL_GPL(ci13xxx_remove_device);
OpenPOWER on IntegriCloud