mailbox.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* mailbox.h */
  2. #ifndef MAILBOX_H
  3. #define MAILBOX_H
  4. #include <linux/spinlock.h>
  5. #include <linux/workqueue.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/device.h>
  8. #include <linux/kfifo.h>
  9. typedef u32 mbox_msg_t;
  10. struct omap_mbox;
  11. typedef int __bitwise omap_mbox_irq_t;
  12. #define IRQ_TX ((__force omap_mbox_irq_t) 1)
  13. #define IRQ_RX ((__force omap_mbox_irq_t) 2)
  14. typedef int __bitwise omap_mbox_type_t;
  15. #define OMAP_MBOX_TYPE1 ((__force omap_mbox_type_t) 1)
  16. #define OMAP_MBOX_TYPE2 ((__force omap_mbox_type_t) 2)
  17. struct omap_mbox_ops {
  18. omap_mbox_type_t type;
  19. int (*startup)(struct omap_mbox *mbox);
  20. void (*shutdown)(struct omap_mbox *mbox);
  21. /* fifo */
  22. mbox_msg_t (*fifo_read)(struct omap_mbox *mbox);
  23. void (*fifo_write)(struct omap_mbox *mbox, mbox_msg_t msg);
  24. int (*fifo_empty)(struct omap_mbox *mbox);
  25. int (*fifo_full)(struct omap_mbox *mbox);
  26. /* irq */
  27. void (*enable_irq)(struct omap_mbox *mbox,
  28. omap_mbox_irq_t irq);
  29. void (*disable_irq)(struct omap_mbox *mbox,
  30. omap_mbox_irq_t irq);
  31. void (*ack_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
  32. int (*is_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
  33. /* ctx */
  34. void (*save_ctx)(struct omap_mbox *mbox);
  35. void (*restore_ctx)(struct omap_mbox *mbox);
  36. };
  37. struct omap_mbox_queue {
  38. spinlock_t lock;
  39. struct kfifo fifo;
  40. struct work_struct work;
  41. struct tasklet_struct tasklet;
  42. int (*callback)(void *);
  43. struct omap_mbox *mbox;
  44. };
  45. struct omap_mbox {
  46. char *name;
  47. unsigned int irq;
  48. struct omap_mbox_queue *txq, *rxq;
  49. struct omap_mbox_ops *ops;
  50. struct device *dev;
  51. void *priv;
  52. };
  53. int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
  54. void omap_mbox_init_seq(struct omap_mbox *);
  55. struct omap_mbox *omap_mbox_get(const char *);
  56. void omap_mbox_put(struct omap_mbox *);
  57. int omap_mbox_register(struct device *parent, struct omap_mbox **);
  58. int omap_mbox_unregister(void);
  59. static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
  60. {
  61. if (!mbox->ops->save_ctx) {
  62. dev_err(mbox->dev, "%s:\tno save\n", __func__);
  63. return;
  64. }
  65. mbox->ops->save_ctx(mbox);
  66. }
  67. static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
  68. {
  69. if (!mbox->ops->restore_ctx) {
  70. dev_err(mbox->dev, "%s:\tno restore\n", __func__);
  71. return;
  72. }
  73. mbox->ops->restore_ctx(mbox);
  74. }
  75. static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
  76. omap_mbox_irq_t irq)
  77. {
  78. mbox->ops->enable_irq(mbox, irq);
  79. }
  80. static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
  81. omap_mbox_irq_t irq)
  82. {
  83. mbox->ops->disable_irq(mbox, irq);
  84. }
  85. #endif /* MAILBOX_H */