mailbox.h 2.3 KB

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