blob: bf0695310bde31871f44448e369efe58771159e7 [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>
8#include <linux/blkdev.h>
9
10typedef u32 mbox_msg_t;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080011struct omap_mbox;
12
13typedef int __bitwise omap_mbox_irq_t;
14#define IRQ_TX ((__force omap_mbox_irq_t) 1)
15#define IRQ_RX ((__force omap_mbox_irq_t) 2)
16
17typedef int __bitwise omap_mbox_type_t;
18#define OMAP_MBOX_TYPE1 ((__force omap_mbox_type_t) 1)
19#define OMAP_MBOX_TYPE2 ((__force omap_mbox_type_t) 2)
20
21struct omap_mbox_ops {
22 omap_mbox_type_t type;
23 int (*startup)(struct omap_mbox *mbox);
24 void (*shutdown)(struct omap_mbox *mbox);
25 /* fifo */
26 mbox_msg_t (*fifo_read)(struct omap_mbox *mbox);
27 void (*fifo_write)(struct omap_mbox *mbox, mbox_msg_t msg);
28 int (*fifo_empty)(struct omap_mbox *mbox);
29 int (*fifo_full)(struct omap_mbox *mbox);
30 /* irq */
31 void (*enable_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
32 void (*disable_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
33 void (*ack_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
34 int (*is_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070035 /* ctx */
36 void (*save_ctx)(struct omap_mbox *mbox);
37 void (*restore_ctx)(struct omap_mbox *mbox);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080038};
39
40struct omap_mbox_queue {
41 spinlock_t lock;
Jens Axboe165125e2007-07-24 09:28:11 +020042 struct request_queue *queue;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080043 struct work_struct work;
44 int (*callback)(void *);
45 struct omap_mbox *mbox;
46};
47
48struct omap_mbox {
49 char *name;
50 unsigned int irq;
51
52 struct omap_mbox_queue *txq, *rxq;
53
54 struct omap_mbox_ops *ops;
55
56 mbox_msg_t seq_snd, seq_rcv;
57
Hiroshi DOYUf48cca82009-03-23 18:07:24 -070058 struct device *dev;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080059
60 struct omap_mbox *next;
61 void *priv;
62
63 void (*err_notify)(void);
64};
65
C A Subramaniamb2b63622009-11-22 10:11:20 -080066int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080067void omap_mbox_init_seq(struct omap_mbox *);
68
69struct omap_mbox *omap_mbox_get(const char *);
70void omap_mbox_put(struct omap_mbox *);
71
Hiroshi DOYUf48cca82009-03-23 18:07:24 -070072int omap_mbox_register(struct device *parent, struct omap_mbox *);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080073int omap_mbox_unregister(struct omap_mbox *);
74
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070075static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
76{
77 if (!mbox->ops->save_ctx) {
78 dev_err(mbox->dev, "%s:\tno save\n", __func__);
79 return;
80 }
81
82 mbox->ops->save_ctx(mbox);
83}
84
85static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
86{
87 if (!mbox->ops->restore_ctx) {
88 dev_err(mbox->dev, "%s:\tno restore\n", __func__);
89 return;
90 }
91
92 mbox->ops->restore_ctx(mbox);
93}
94
Hiroshi DOYUeb188582009-11-22 10:11:22 -080095static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
96 omap_mbox_irq_t irq)
97{
98 mbox->ops->enable_irq(mbox, irq);
99}
100
101static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
102 omap_mbox_irq_t irq)
103{
104 mbox->ops->disable_irq(mbox, irq);
105}
106
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800107#endif /* MAILBOX_H */