mailbox.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Mailbox reservation modules for OMAP1
  3. *
  4. * Copyright (C) 2006-2009 Nokia Corporation
  5. * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/io.h>
  14. #include <plat/mailbox.h>
  15. #define MAILBOX_ARM2DSP1 0x00
  16. #define MAILBOX_ARM2DSP1b 0x04
  17. #define MAILBOX_DSP2ARM1 0x08
  18. #define MAILBOX_DSP2ARM1b 0x0c
  19. #define MAILBOX_DSP2ARM2 0x10
  20. #define MAILBOX_DSP2ARM2b 0x14
  21. #define MAILBOX_ARM2DSP1_Flag 0x18
  22. #define MAILBOX_DSP2ARM1_Flag 0x1c
  23. #define MAILBOX_DSP2ARM2_Flag 0x20
  24. static void __iomem *mbox_base;
  25. struct omap_mbox1_fifo {
  26. unsigned long cmd;
  27. unsigned long data;
  28. unsigned long flag;
  29. };
  30. struct omap_mbox1_priv {
  31. struct omap_mbox1_fifo tx_fifo;
  32. struct omap_mbox1_fifo rx_fifo;
  33. };
  34. static inline int mbox_read_reg(size_t ofs)
  35. {
  36. return __raw_readw(mbox_base + ofs);
  37. }
  38. static inline void mbox_write_reg(u32 val, size_t ofs)
  39. {
  40. __raw_writew(val, mbox_base + ofs);
  41. }
  42. /* msg */
  43. static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
  44. {
  45. struct omap_mbox1_fifo *fifo =
  46. &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
  47. mbox_msg_t msg;
  48. msg = mbox_read_reg(fifo->data);
  49. msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
  50. return msg;
  51. }
  52. static void
  53. omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
  54. {
  55. struct omap_mbox1_fifo *fifo =
  56. &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;
  57. mbox_write_reg(msg & 0xffff, fifo->data);
  58. mbox_write_reg(msg >> 16, fifo->cmd);
  59. }
  60. static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
  61. {
  62. return 0;
  63. }
  64. static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
  65. {
  66. struct omap_mbox1_fifo *fifo =
  67. &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
  68. return mbox_read_reg(fifo->flag);
  69. }
  70. /* irq */
  71. static void
  72. omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
  73. {
  74. if (irq == IRQ_RX)
  75. enable_irq(mbox->irq);
  76. }
  77. static void
  78. omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
  79. {
  80. if (irq == IRQ_RX)
  81. disable_irq(mbox->irq);
  82. }
  83. static int
  84. omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
  85. {
  86. if (irq == IRQ_TX)
  87. return 0;
  88. return 1;
  89. }
  90. static struct omap_mbox_ops omap1_mbox_ops = {
  91. .type = OMAP_MBOX_TYPE1,
  92. .fifo_read = omap1_mbox_fifo_read,
  93. .fifo_write = omap1_mbox_fifo_write,
  94. .fifo_empty = omap1_mbox_fifo_empty,
  95. .fifo_full = omap1_mbox_fifo_full,
  96. .enable_irq = omap1_mbox_enable_irq,
  97. .disable_irq = omap1_mbox_disable_irq,
  98. .is_irq = omap1_mbox_is_irq,
  99. };
  100. /* FIXME: the following struct should be created automatically by the user id */
  101. /* DSP */
  102. static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
  103. .tx_fifo = {
  104. .cmd = MAILBOX_ARM2DSP1b,
  105. .data = MAILBOX_ARM2DSP1,
  106. .flag = MAILBOX_ARM2DSP1_Flag,
  107. },
  108. .rx_fifo = {
  109. .cmd = MAILBOX_DSP2ARM1b,
  110. .data = MAILBOX_DSP2ARM1,
  111. .flag = MAILBOX_DSP2ARM1_Flag,
  112. },
  113. };
  114. static struct omap_mbox mbox_dsp_info = {
  115. .name = "dsp",
  116. .ops = &omap1_mbox_ops,
  117. .priv = &omap1_mbox_dsp_priv,
  118. };
  119. static struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
  120. static int __devinit omap1_mbox_probe(struct platform_device *pdev)
  121. {
  122. struct resource *mem;
  123. int ret;
  124. struct omap_mbox **list;
  125. list = omap1_mboxes;
  126. list[0]->irq = platform_get_irq_byname(pdev, "dsp");
  127. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  128. mbox_base = ioremap(mem->start, resource_size(mem));
  129. if (!mbox_base)
  130. return -ENOMEM;
  131. ret = omap_mbox_register(&pdev->dev, list);
  132. if (ret) {
  133. iounmap(mbox_base);
  134. return ret;
  135. }
  136. return 0;
  137. }
  138. static int __devexit omap1_mbox_remove(struct platform_device *pdev)
  139. {
  140. omap_mbox_unregister();
  141. iounmap(mbox_base);
  142. return 0;
  143. }
  144. static struct platform_driver omap1_mbox_driver = {
  145. .probe = omap1_mbox_probe,
  146. .remove = __devexit_p(omap1_mbox_remove),
  147. .driver = {
  148. .name = "omap-mailbox",
  149. },
  150. };
  151. static int __init omap1_mbox_init(void)
  152. {
  153. return platform_driver_register(&omap1_mbox_driver);
  154. }
  155. static void __exit omap1_mbox_exit(void)
  156. {
  157. platform_driver_unregister(&omap1_mbox_driver);
  158. }
  159. module_init(omap1_mbox_init);
  160. module_exit(omap1_mbox_exit);
  161. MODULE_LICENSE("GPL v2");
  162. MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
  163. MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
  164. MODULE_ALIAS("platform:omap1-mailbox");