diff options
author | Richard Zhao <richard.zhao@freescale.com> | 2012-07-07 10:56:42 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-07-09 12:53:44 -0400 |
commit | fe6e125e30fb9d93fdfc5e3e3702b9c7c3076194 (patch) | |
tree | e88ebed6c65ca251a5563a64c86e8d2b8e27916b /drivers/usb/chipidea | |
parent | cbc6dc2af39e1395564445fd71cfcc1c70a96277 (diff) |
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')
-rw-r--r-- | drivers/usb/chipidea/core.c | 21 |
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 @@ | |||
56 | #include <linux/init.h> | 56 | #include <linux/init.h> |
57 | #include <linux/platform_device.h> | 57 | #include <linux/platform_device.h> |
58 | #include <linux/module.h> | 58 | #include <linux/module.h> |
59 | #include <linux/idr.h> | ||
59 | #include <linux/interrupt.h> | 60 | #include <linux/interrupt.h> |
60 | #include <linux/io.h> | 61 | #include <linux/io.h> |
61 | #include <linux/irq.h> | 62 | #include <linux/irq.h> |
@@ -332,17 +333,24 @@ static irqreturn_t ci_irq(int irq, void *data) | |||
332 | return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci); | 333 | return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci); |
333 | } | 334 | } |
334 | 335 | ||
336 | static DEFINE_IDA(ci_ida); | ||
337 | |||
335 | struct platform_device *ci13xxx_add_device(struct device *dev, | 338 | struct platform_device *ci13xxx_add_device(struct device *dev, |
336 | struct resource *res, int nres, | 339 | struct resource *res, int nres, |
337 | struct ci13xxx_platform_data *platdata) | 340 | struct ci13xxx_platform_data *platdata) |
338 | { | 341 | { |
339 | struct platform_device *pdev; | 342 | struct platform_device *pdev; |
340 | int ret; | 343 | int id, ret; |
341 | 344 | ||
342 | /* FIXME: find a way to choose id */ | 345 | id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL); |
343 | pdev = platform_device_alloc("ci_hdrc", -1); | 346 | if (id < 0) |
344 | if (!pdev) | 347 | return ERR_PTR(id); |
345 | return ERR_PTR(-ENOMEM); | 348 | |
349 | pdev = platform_device_alloc("ci_hdrc", id); | ||
350 | if (!pdev) { | ||
351 | ret = -ENOMEM; | ||
352 | goto put_id; | ||
353 | } | ||
346 | 354 | ||
347 | pdev->dev.parent = dev; | 355 | pdev->dev.parent = dev; |
348 | pdev->dev.dma_mask = dev->dma_mask; | 356 | pdev->dev.dma_mask = dev->dma_mask; |
@@ -365,6 +373,8 @@ struct platform_device *ci13xxx_add_device(struct device *dev, | |||
365 | 373 | ||
366 | err: | 374 | err: |
367 | platform_device_put(pdev); | 375 | platform_device_put(pdev); |
376 | put_id: | ||
377 | ida_simple_remove(&ci_ida, id); | ||
368 | return ERR_PTR(ret); | 378 | return ERR_PTR(ret); |
369 | } | 379 | } |
370 | EXPORT_SYMBOL_GPL(ci13xxx_add_device); | 380 | EXPORT_SYMBOL_GPL(ci13xxx_add_device); |
@@ -372,6 +382,7 @@ EXPORT_SYMBOL_GPL(ci13xxx_add_device); | |||
372 | void ci13xxx_remove_device(struct platform_device *pdev) | 382 | void ci13xxx_remove_device(struct platform_device *pdev) |
373 | { | 383 | { |
374 | platform_device_unregister(pdev); | 384 | platform_device_unregister(pdev); |
385 | ida_simple_remove(&ci_ida, pdev->id); | ||
375 | } | 386 | } |
376 | EXPORT_SYMBOL_GPL(ci13xxx_remove_device); | 387 | EXPORT_SYMBOL_GPL(ci13xxx_remove_device); |
377 | 388 | ||