memoryCall.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Mailbox reservation modules for OMAP2/3
  3. *
  4. * Copyright (C) 2006-2009 Nokia Corporation
  5. * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
  6. * and Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/clk.h>
  14. #include <linux/err.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/io.h>
  17. #include <linux/pm_runtime.h>
  18. #include <plat/mailbox.h>
  19. #include "soc.h"
  20. #define MAILBOX_REVISION 0x000
  21. #define MAILBOX_MESSAGE(m) (0x040 + 4 * (m))
  22. #define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m))
  23. #define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m))
  24. #define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u))
  25. #define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u))
  26. #define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 0x10 * (u))
  27. #define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 0x10 * (u))
  28. #define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 0x10 * (u))
  29. #define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m)))
  30. #define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1))
  31. #define MBOX_REG_SIZE 0x120
  32. #define OMAP4_MBOX_REG_SIZE 0x130
  33. #define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32))
  34. #define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32))
  35. static void __iomem *mbox_base;
  36. struct omap_mbox2_fifo {
  37. unsigned long msg;
  38. unsigned long fifo_stat;
  39. unsigned long msg_stat;
  40. };
  41. struct omap_mbox2_priv {
  42. struct omap_mbox2_fifo tx_fifo;
  43. struct omap_mbox2_fifo rx_fifo;
  44. unsigned long irqenable;
  45. unsigned long irqstatus;
  46. u32 newmsg_bit;
  47. u32 notfull_bit;
  48. u32 ctx[OMAP4_MBOX_NR_REGS];
  49. unsigned long irqdisable;
  50. };
  51. static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
  52. omap_mbox_type_t irq);
  53. static inline unsigned int mbox_read_reg(size_t ofs)
  54. {
  55. return __raw_readl(mbox_base + ofs);
  56. }
  57. static inline void mbox_write_reg(u32 val, size_t ofs)
  58. {
  59. __raw_writel(val, mbox_base + ofs);
  60. }
  61. /* Mailbox H/W preparations */
  62. static int omap2_mbox_startup(struct omap_mbox *mbox)
  63. {
  64. u32 l;
  65. pm_runtime_enable(mbox->dev->parent);
  66. pm_runtime_get_sync(mbox->dev->parent);
  67. l = mbox_read_reg(MAILBOX_REVISION);
  68. pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
  69. return 0;
  70. }
  71. static void omap2_mbox_shutdown(struct omap_mbox *mbox)
  72. {
  73. pm_runtime_put_sync(mbox->dev->parent);
  74. pm_runtime_disable(mbox->dev->parent);
  75. }
  76. /* Mailbox FIFO handle functions */
  77. static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox)
  78. {
  79. struct omap_mbox2_fifo *fifo =
  80. &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo;
  81. return (mbox_msg_t) mbox_read_reg(fifo->msg);
  82. }
  83. static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
  84. {
  85. struct omap_mbox2_fifo *fifo =
  86. &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo;
  87. mbox_write_reg(msg, fifo->msg);
  88. }