diff options
author | Felipe Contreras <felipe.contreras@gmail.com> | 2010-06-11 11:51:46 -0400 |
---|---|---|
committer | Hiroshi DOYU <Hiroshi.DOYU@nokia.com> | 2010-08-04 08:50:19 -0400 |
commit | 9c80c8cd740f802eed27ed1c1334262b205bb8f5 (patch) | |
tree | d1cff1b65ad4bf7d79a059eefffd19e3d9343979 | |
parent | 898ee75623d5a151157e3f0dca12b0148051e2d6 (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>
-rw-r--r-- | arch/arm/mach-omap1/mailbox.c | 25 | ||||
-rw-r--r-- | arch/arm/mach-omap2/mailbox.c | 22 | ||||
-rw-r--r-- | arch/arm/plat-omap/include/plat/mailbox.h | 5 | ||||
-rw-r--r-- | arch/arm/plat-omap/mailbox.c | 95 |
4 files changed, 50 insertions, 97 deletions
diff --git a/arch/arm/mach-omap1/mailbox.c b/arch/arm/mach-omap1/mailbox.c index 0318754e850..9ca0d58fead 100644 --- a/arch/arm/mach-omap1/mailbox.c +++ b/arch/arm/mach-omap1/mailbox.c | |||
@@ -29,8 +29,6 @@ | |||
29 | 29 | ||
30 | static void __iomem *mbox_base; | 30 | static void __iomem *mbox_base; |
31 | 31 | ||
32 | static struct omap_mbox **list; | ||
33 | |||
34 | struct omap_mbox1_fifo { | 32 | struct omap_mbox1_fifo { |
35 | unsigned long cmd; | 33 | unsigned long cmd; |
36 | unsigned long data; | 34 | unsigned long data; |
@@ -151,9 +149,9 @@ static int __devinit omap1_mbox_probe(struct platform_device *pdev) | |||
151 | struct resource *mem; | 149 | struct resource *mem; |
152 | int ret; | 150 | int ret; |
153 | int i; | 151 | int i; |
152 | struct omap_mbox **list; | ||
154 | 153 | ||
155 | list = omap1_mboxes; | 154 | list = omap1_mboxes; |
156 | |||
157 | list[0]->irq = platform_get_irq_byname(pdev, "dsp"); | 155 | list[0]->irq = platform_get_irq_byname(pdev, "dsp"); |
158 | 156 | ||
159 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 157 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -161,27 +159,18 @@ static int __devinit omap1_mbox_probe(struct platform_device *pdev) | |||
161 | if (!mbox_base) | 159 | if (!mbox_base) |
162 | return -ENOMEM; | 160 | return -ENOMEM; |
163 | 161 | ||
164 | for (i = 0; list[i]; i++) { | 162 | ret = omap_mbox_register(&pdev->dev, list); |
165 | ret = omap_mbox_register(&pdev->dev, list[i]); | 163 | if (ret) { |
166 | if (ret) | 164 | iounmap(mbox_base); |
167 | goto err_out; | 165 | return ret; |
168 | } | 166 | } |
169 | return 0; | ||
170 | 167 | ||
171 | err_out: | 168 | return 0; |
172 | while (i--) | ||
173 | omap_mbox_unregister(list[i]); | ||
174 | iounmap(mbox_base); | ||
175 | return ret; | ||
176 | } | 169 | } |
177 | 170 | ||
178 | static int __devexit omap1_mbox_remove(struct platform_device *pdev) | 171 | static int __devexit omap1_mbox_remove(struct platform_device *pdev) |
179 | { | 172 | { |
180 | int i; | 173 | omap_mbox_unregister(); |
181 | |||
182 | for (i = 0; list[i]; i++) | ||
183 | omap_mbox_unregister(list[i]); | ||
184 | |||
185 | iounmap(mbox_base); | 174 | iounmap(mbox_base); |
186 | return 0; | 175 | return 0; |
187 | } | 176 | } |
diff --git a/arch/arm/mach-omap2/mailbox.c b/arch/arm/mach-omap2/mailbox.c index e5abc8e42f5..55d8b77f0fc 100644 --- a/arch/arm/mach-omap2/mailbox.c +++ b/arch/arm/mach-omap2/mailbox.c | |||
@@ -56,8 +56,6 @@ | |||
56 | 56 | ||
57 | static void __iomem *mbox_base; | 57 | static void __iomem *mbox_base; |
58 | 58 | ||
59 | static struct omap_mbox **list; | ||
60 | |||
61 | struct omap_mbox2_fifo { | 59 | struct omap_mbox2_fifo { |
62 | unsigned long msg; | 60 | unsigned long msg; |
63 | unsigned long fifo_stat; | 61 | unsigned long fifo_stat; |
@@ -390,7 +388,7 @@ static int __devinit omap2_mbox_probe(struct platform_device *pdev) | |||
390 | { | 388 | { |
391 | struct resource *mem; | 389 | struct resource *mem; |
392 | int ret; | 390 | int ret; |
393 | int i; | 391 | struct omap_mbox **list; |
394 | 392 | ||
395 | if (cpu_is_omap3430()) { | 393 | if (cpu_is_omap3430()) { |
396 | list = omap3_mboxes; | 394 | list = omap3_mboxes; |
@@ -421,27 +419,19 @@ static int __devinit omap2_mbox_probe(struct platform_device *pdev) | |||
421 | if (!mbox_base) | 419 | if (!mbox_base) |
422 | return -ENOMEM; | 420 | return -ENOMEM; |
423 | 421 | ||
424 | for (i = 0; list[i]; i++) { | 422 | ret = omap_mbox_register(&pdev->dev, list); |
425 | ret = omap_mbox_register(&pdev->dev, list[i]); | 423 | if (ret) { |
426 | if (ret) | 424 | iounmap(mbox_base); |
427 | goto err_out; | 425 | return ret; |
428 | } | 426 | } |
429 | return 0; | 427 | return 0; |
430 | 428 | ||
431 | err_out: | ||
432 | while (i--) | ||
433 | omap_mbox_unregister(list[i]); | ||
434 | iounmap(mbox_base); | ||
435 | return ret; | 429 | return ret; |
436 | } | 430 | } |
437 | 431 | ||
438 | static int __devexit omap2_mbox_remove(struct platform_device *pdev) | 432 | static int __devexit omap2_mbox_remove(struct platform_device *pdev) |
439 | { | 433 | { |
440 | int i; | 434 | omap_mbox_unregister(); |
441 | |||
442 | for (i = 0; list[i]; i++) | ||
443 | omap_mbox_unregister(list[i]); | ||
444 | |||
445 | iounmap(mbox_base); | 435 | iounmap(mbox_base); |
446 | return 0; | 436 | return 0; |
447 | } | 437 | } |
diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index aad8bf80c22..c44fde30c7c 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h | |||
@@ -55,7 +55,6 @@ struct omap_mbox { | |||
55 | struct omap_mbox_queue *txq, *rxq; | 55 | struct omap_mbox_queue *txq, *rxq; |
56 | struct omap_mbox_ops *ops; | 56 | struct omap_mbox_ops *ops; |
57 | struct device *dev; | 57 | struct device *dev; |
58 | struct omap_mbox *next; | ||
59 | void *priv; | 58 | void *priv; |
60 | }; | 59 | }; |
61 | 60 | ||
@@ -65,8 +64,8 @@ void omap_mbox_init_seq(struct omap_mbox *); | |||
65 | struct omap_mbox *omap_mbox_get(const char *); | 64 | struct omap_mbox *omap_mbox_get(const char *); |
66 | void omap_mbox_put(struct omap_mbox *); | 65 | void omap_mbox_put(struct omap_mbox *); |
67 | 66 | ||
68 | int omap_mbox_register(struct device *parent, struct omap_mbox *); | 67 | int omap_mbox_register(struct device *parent, struct omap_mbox **); |
69 | int omap_mbox_unregister(struct omap_mbox *); | 68 | int omap_mbox_unregister(void); |
70 | 69 | ||
71 | static inline void omap_mbox_save_ctx(struct omap_mbox *mbox) | 70 | static inline void omap_mbox_save_ctx(struct omap_mbox *mbox) |
72 | { | 71 | { |
diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 87e0cde8d0d..fe088213085 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 | ||
35 | static struct workqueue_struct *mboxd; | 35 | static struct workqueue_struct *mboxd; |
36 | static struct omap_mbox *mboxes; | 36 | static struct omap_mbox **mboxes; |
37 | static DEFINE_SPINLOCK(mboxes_lock); | ||
38 | static bool rq_full; | 37 | static bool rq_full; |
39 | 38 | ||
40 | static int mbox_configured; | 39 | static int mbox_configured; |
@@ -307,31 +306,20 @@ static void omap_mbox_fini(struct omap_mbox *mbox) | |||
307 | } | 306 | } |
308 | } | 307 | } |
309 | 308 | ||
310 | static 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 | |||
322 | struct omap_mbox *omap_mbox_get(const char *name) | 309 | struct 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 | ||
350 | static struct class omap_mbox_class = { .name = "mbox", }; | 338 | static struct class omap_mbox_class = { .name = "mbox", }; |
351 | 339 | ||
352 | int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) | 340 | int 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 | ||
379 | err_find: | 360 | err_out: |
361 | while (i--) | ||
362 | device_unregister(mboxes[i]->dev); | ||
380 | return ret; | 363 | return ret; |
381 | } | 364 | } |
382 | EXPORT_SYMBOL(omap_mbox_register); | 365 | EXPORT_SYMBOL(omap_mbox_register); |
383 | 366 | ||
384 | int omap_mbox_unregister(struct omap_mbox *mbox) | 367 | int 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 | } |
404 | EXPORT_SYMBOL(omap_mbox_unregister); | 379 | EXPORT_SYMBOL(omap_mbox_unregister); |
405 | 380 | ||