aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/plat-omap/mailbox.c
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2010-06-11 11:51:46 -0400
committerHiroshi DOYU <Hiroshi.DOYU@nokia.com>2010-08-04 08:50:19 -0400
commit9c80c8cd740f802eed27ed1c1334262b205bb8f5 (patch)
treed1cff1b65ad4bf7d79a059eefffd19e3d9343979 /arch/arm/plat-omap/mailbox.c
parent898ee75623d5a151157e3f0dca12b0148051e2d6 (diff)
omap: mailbox: simplify omap_mbox_register()
No need to dynamically register mailboxes one by one. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Diffstat (limited to 'arch/arm/plat-omap/mailbox.c')
-rw-r--r--arch/arm/plat-omap/mailbox.c95
1 files changed, 35 insertions, 60 deletions
diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
index 87e0cde8d0db..fe0882130852 100644
--- a/arch/arm/plat-omap/mailbox.c
+++ b/arch/arm/plat-omap/mailbox.c
@@ -33,8 +33,7 @@
33#include <plat/mailbox.h> 33#include <plat/mailbox.h>
34 34
35static struct workqueue_struct *mboxd; 35static struct workqueue_struct *mboxd;
36static struct omap_mbox *mboxes; 36static struct omap_mbox **mboxes;
37static DEFINE_SPINLOCK(mboxes_lock);
38static bool rq_full; 37static bool rq_full;
39 38
40static int mbox_configured; 39static int mbox_configured;
@@ -307,31 +306,20 @@ static void omap_mbox_fini(struct omap_mbox *mbox)
307 } 306 }
308} 307}
309 308
310static struct omap_mbox **find_mboxes(const char *name)
311{
312 struct omap_mbox **p;
313
314 for (p = &mboxes; *p; p = &(*p)->next) {
315 if (strcmp((*p)->name, name) == 0)
316 break;
317 }
318
319 return p;
320}
321
322struct omap_mbox *omap_mbox_get(const char *name) 309struct omap_mbox *omap_mbox_get(const char *name)
323{ 310{
324 struct omap_mbox *mbox; 311 struct omap_mbox *mbox;
325 int ret; 312 int ret;
326 313
327 spin_lock(&mboxes_lock); 314 if (!mboxes)
328 mbox = *(find_mboxes(name)); 315 return ERR_PTR(-EINVAL);
329 if (mbox == NULL) {
330 spin_unlock(&mboxes_lock);
331 return ERR_PTR(-ENOENT);
332 }
333 316
334 spin_unlock(&mboxes_lock); 317 for (mbox = *mboxes; mbox; mbox++)
318 if (!strcmp(mbox->name, name))
319 break;
320
321 if (!mbox)
322 return ERR_PTR(-ENOENT);
335 323
336 ret = omap_mbox_startup(mbox); 324 ret = omap_mbox_startup(mbox);
337 if (ret) 325 if (ret)
@@ -349,57 +337,44 @@ EXPORT_SYMBOL(omap_mbox_put);
349 337
350static struct class omap_mbox_class = { .name = "mbox", }; 338static struct class omap_mbox_class = { .name = "mbox", };
351 339
352int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) 340int omap_mbox_register(struct device *parent, struct omap_mbox **list)
353{ 341{
354 int ret = 0; 342 int ret;
355 struct omap_mbox **tmp; 343 int i;
356 344
357 if (!mbox) 345 mboxes = list;
346 if (!mboxes)
358 return -EINVAL; 347 return -EINVAL;
359 if (mbox->next)
360 return -EBUSY;
361
362 mbox->dev = device_create(&omap_mbox_class,
363 parent, 0, mbox, "%s", mbox->name);
364 if (IS_ERR(mbox->dev))
365 return PTR_ERR(mbox->dev);
366
367 spin_lock(&mboxes_lock);
368 tmp = find_mboxes(mbox->name);
369 if (*tmp) {
370 ret = -EBUSY;
371 spin_unlock(&mboxes_lock);
372 goto err_find;
373 }
374 *tmp = mbox;
375 spin_unlock(&mboxes_lock);
376 348
349 for (i = 0; mboxes[i]; i++) {
350 struct omap_mbox *mbox = mboxes[i];
351 mbox->dev = device_create(&omap_mbox_class,
352 parent, 0, mbox, "%s", mbox->name);
353 if (IS_ERR(mbox->dev)) {
354 ret = PTR_ERR(mbox->dev);
355 goto err_out;
356 }
357 }
377 return 0; 358 return 0;
378 359
379err_find: 360err_out:
361 while (i--)
362 device_unregister(mboxes[i]->dev);
380 return ret; 363 return ret;
381} 364}
382EXPORT_SYMBOL(omap_mbox_register); 365EXPORT_SYMBOL(omap_mbox_register);
383 366
384int omap_mbox_unregister(struct omap_mbox *mbox) 367int omap_mbox_unregister(void)
385{ 368{
386 struct omap_mbox **tmp; 369 int i;
387
388 spin_lock(&mboxes_lock);
389 tmp = &mboxes;
390 while (*tmp) {
391 if (mbox == *tmp) {
392 *tmp = mbox->next;
393 mbox->next = NULL;
394 spin_unlock(&mboxes_lock);
395 device_unregister(mbox->dev);
396 return 0;
397 }
398 tmp = &(*tmp)->next;
399 }
400 spin_unlock(&mboxes_lock);
401 370
402 return -EINVAL; 371 if (!mboxes)
372 return -EINVAL;
373
374 for (i = 0; mboxes[i]; i++)
375 device_unregister(mboxes[i]->dev);
376 mboxes = NULL;
377 return 0;
403} 378}
404EXPORT_SYMBOL(omap_mbox_unregister); 379EXPORT_SYMBOL(omap_mbox_unregister);
405 380