mailbox.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Mailbox reservation modules for DSP
  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/kernel.h>
  12. #include <linux/resource.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <mach/mailbox.h>
  17. #include <mach/irqs.h>
  18. #define MAILBOX_ARM2DSP1 0x00
  19. #define MAILBOX_ARM2DSP1b 0x04
  20. #define MAILBOX_DSP2ARM1 0x08
  21. #define MAILBOX_DSP2ARM1b 0x0c
  22. #define MAILBOX_DSP2ARM2 0x10
  23. #define MAILBOX_DSP2ARM2b 0x14
  24. #define MAILBOX_ARM2DSP1_Flag 0x18
  25. #define MAILBOX_DSP2ARM1_Flag 0x1c
  26. #define MAILBOX_DSP2ARM2_Flag 0x20
  27. static void __iomem *mbox_base;
  28. struct omap_mbox1_fifo {
  29. unsigned long cmd;
  30. unsigned long data;
  31. unsigned long flag;
  32. };
  33. struct omap_mbox1_priv {
  34. struct omap_mbox1_fifo tx_fifo;
  35. struct omap_mbox1_fifo rx_fifo;
  36. };
  37. static inline int mbox_read_reg(size_t ofs)
  38. {
  39. return __raw_readw(mbox_base + ofs);
  40. }
  41. static inline void mbox_write_reg(u32 val, size_t ofs)
  42. {
  43. __raw_writew(val, mbox_base + ofs);
  44. }
  45. /* msg */
  46. static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
  47. {
  48. struct omap_mbox1_fifo *fifo =
  49. &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
  50. mbox_msg_t msg;
  51. msg = mbox_read_reg(fifo->data);
  52. msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
  53. return msg;
  54. }
  55. static void
  56. omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
  57. {
  58. struct omap_mbox1_fifo *fifo =
  59. &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;
  60. mbox_write_reg(msg & 0xffff, fifo->data);
  61. mbox_write_reg(msg >> 16, fifo->cmd);
  62. }
  63. static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
  64. {
  65. return 0;
  66. }
  67. static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
  68. {
  69. struct omap_mbox1_fifo *fifo =
  70. &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
  71. return (mbox_read_reg(fifo->flag));
  72. }
  73. /* irq */
  74. static void
  75. omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
  76. {
  77. if (irq == IRQ_RX)
  78. enable_irq(mbox->irq);
  79. }
  80. static void
  81. omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
  82. {
  83. if (irq == IRQ_RX)
  84. disable_irq(mbox->irq);
  85. }
  86. static int
  87. omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
  88. {
  89. if (irq == IRQ_TX)
  90. return 0;
  91. return 1;
  92. }
  93. static struct omap_mbox_ops omap1_mbox_ops = {
  94. .type = OMAP_MBOX_TYPE1,
  95. .fifo_read = omap1_mbox_fifo_read,
  96. .fifo_write = omap1_mbox_fifo_write,
  97. .fifo_empty = omap1_mbox_fifo_empty,
  98. .fifo_full = omap1_mbox_fifo_full,
  99. .enable_irq = omap1_mbox_enable_irq,
  100. .disable_irq = omap1_mbox_disable_irq,
  101. .is_irq = omap1_mbox_is_irq,
  102. };
  103. /* FIXME: the following struct should be created automatically by the user id */
  104. /* DSP */
  105. static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
  106. .tx_fifo = {
  107. .cmd = MAILBOX_ARM2DSP1b,
  108. .data = MAILBOX_ARM2DSP1,
  109. .flag = MAILBOX_ARM2DSP1_Flag,
  110. },
  111. .rx_fifo = {
  112. .cmd = MAILBOX_DSP2ARM1b,
  113. .data = MAILBOX_DSP2ARM1,
  114. .flag = MAILBOX_DSP2ARM1_Flag,
  115. },
  116. };
  117. struct omap_mbox mbox_dsp_info = {
  118. .name = "dsp",
  119. .ops = &omap1_mbox_ops,
  120. .priv = &omap1_mbox_dsp_priv,
  121. };
  122. EXPORT_SYMBOL(mbox_dsp_info);
  123. static int __devinit omap1_mbox_probe(struct platform_device *pdev)
  124. {
  125. struct resource *res;
  126. int ret = 0;
  127. if (pdev->num_resources != 2) {
  128. dev_err(&pdev->dev, "invalid number of resources: %d\n",
  129. pdev->num_resources);
  130. return -ENODEV;
  131. }
  132. /* MBOX base */
  133. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  134. if (unlikely(!res)) {
  135. dev_err(&pdev->dev, "invalid mem resource\n");
  136. return -ENODEV;
  137. }
  138. mbox_base = res->start;
  139. /* DSP IRQ */
  140. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  141. if (unlikely(!res)) {
  142. dev_err(&pdev->dev, "invalid irq resource\n");
  143. return -ENODEV;
  144. }
  145. mbox_dsp_info.irq = res->start;
  146. return omap_mbox_register(&pdev->dev, &mbox_dsp_info);
  147. }
  148. static int __devexit omap1_mbox_remove(struct platform_device *pdev)
  149. {
  150. omap_mbox_unregister(&mbox_dsp_info);
  151. return 0;
  152. }
  153. static struct platform_driver omap1_mbox_driver = {
  154. .probe = omap1_mbox_probe,
  155. .remove = __devexit_p(omap1_mbox_remove),
  156. .driver = {
  157. .name = "omap1-mailbox",
  158. },
  159. };
  160. static int __init omap1_mbox_init(void)
  161. {
  162. return platform_driver_register(&omap1_mbox_driver);
  163. }
  164. static void __exit omap1_mbox_exit(void)
  165. {
  166. platform_driver_unregister(&omap1_mbox_driver);
  167. }
  168. module_init(omap1_mbox_init);
  169. module_exit(omap1_mbox_exit);
  170. MODULE_LICENSE("GPL v2");
  171. MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
  172. MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
  173. MODULE_ALIAS("platform:omap1-mailbox");