mailbox.h 2.3 KB

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