blob: aad8bf80c2247112a21e35cbfbca55c0ad8c4e22 [file] [log] [blame]
Hiroshi DOYU340a6142006-12-07 15:43:59 -08001/* mailbox.h */
2
3#ifndef MAILBOX_H
4#define MAILBOX_H
5
6#include <linux/wait.h>
7#include <linux/workqueue.h>
C A Subramaniam5ed8d322009-11-22 10:11:24 -08008#include <linux/interrupt.h>
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +00009#include <linux/kfifo.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080010
11typedef u32 mbox_msg_t;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080012struct omap_mbox;
13
14typedef int __bitwise omap_mbox_irq_t;
15#define IRQ_TX ((__force omap_mbox_irq_t) 1)
16#define IRQ_RX ((__force omap_mbox_irq_t) 2)
17
18typedef int __bitwise omap_mbox_type_t;
19#define OMAP_MBOX_TYPE1 ((__force omap_mbox_type_t) 1)
20#define OMAP_MBOX_TYPE2 ((__force omap_mbox_type_t) 2)
21
22struct omap_mbox_ops {
23 omap_mbox_type_t type;
24 int (*startup)(struct omap_mbox *mbox);
25 void (*shutdown)(struct omap_mbox *mbox);
26 /* fifo */
27 mbox_msg_t (*fifo_read)(struct omap_mbox *mbox);
28 void (*fifo_write)(struct omap_mbox *mbox, mbox_msg_t msg);
29 int (*fifo_empty)(struct omap_mbox *mbox);
30 int (*fifo_full)(struct omap_mbox *mbox);
31 /* irq */
C A Subramaniam5ed8d322009-11-22 10:11:24 -080032 void (*enable_irq)(struct omap_mbox *mbox,
33 omap_mbox_irq_t irq);
34 void (*disable_irq)(struct omap_mbox *mbox,
35 omap_mbox_irq_t irq);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080036 void (*ack_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
37 int (*is_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070038 /* ctx */
39 void (*save_ctx)(struct omap_mbox *mbox);
40 void (*restore_ctx)(struct omap_mbox *mbox);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080041};
42
43struct omap_mbox_queue {
44 spinlock_t lock;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000045 struct kfifo fifo;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080046 struct work_struct work;
C A Subramaniam5ed8d322009-11-22 10:11:24 -080047 struct tasklet_struct tasklet;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080048 int (*callback)(void *);
49 struct omap_mbox *mbox;
50};
51
52struct omap_mbox {
53 char *name;
54 unsigned int irq;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080055 struct omap_mbox_queue *txq, *rxq;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080056 struct omap_mbox_ops *ops;
Hiroshi DOYUf48cca82009-03-23 18:07:24 -070057 struct device *dev;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080058 struct omap_mbox *next;
59 void *priv;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080060};
61
C A Subramaniamb2b63622009-11-22 10:11:20 -080062int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080063void omap_mbox_init_seq(struct omap_mbox *);
64
65struct omap_mbox *omap_mbox_get(const char *);
66void omap_mbox_put(struct omap_mbox *);
67
Hiroshi DOYUf48cca82009-03-23 18:07:24 -070068int omap_mbox_register(struct device *parent, struct omap_mbox *);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080069int omap_mbox_unregister(struct omap_mbox *);
70
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070071static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
72{
73 if (!mbox->ops->save_ctx) {
74 dev_err(mbox->dev, "%s:\tno save\n", __func__);
75 return;
76 }
77
78 mbox->ops->save_ctx(mbox);
79}
80
81static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
82{
83 if (!mbox->ops->restore_ctx) {
84 dev_err(mbox->dev, "%s:\tno restore\n", __func__);
85 return;
86 }
87
88 mbox->ops->restore_ctx(mbox);
89}
90
Hiroshi DOYUeb188582009-11-22 10:11:22 -080091static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
92 omap_mbox_irq_t irq)
93{
94 mbox->ops->enable_irq(mbox, irq);
95}
96
97static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
98 omap_mbox_irq_t irq)
99{
100 mbox->ops->disable_irq(mbox, irq);
101}
102
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800103#endif /* MAILBOX_H */