]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/arm/plat-omap/include/plat/mailbox.h
omap: mailbox: convert block api to kfifo
[net-next-2.6.git] / arch / arm / plat-omap / include / plat / mailbox.h
CommitLineData
340a614a
HD
1/* mailbox.h */
2
3#ifndef MAILBOX_H
4#define MAILBOX_H
5
6#include <linux/wait.h>
7#include <linux/workqueue.h>
5ed8d32e 8#include <linux/interrupt.h>
b5bebe41 9#include <linux/kfifo.h>
340a614a
HD
10
11typedef u32 mbox_msg_t;
340a614a
HD
12struct 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 */
5ed8d32e
S
32 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);
340a614a
HD
36 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);
c75ee752
HD
38 /* ctx */
39 void (*save_ctx)(struct omap_mbox *mbox);
40 void (*restore_ctx)(struct omap_mbox *mbox);
340a614a
HD
41};
42
43struct omap_mbox_queue {
44 spinlock_t lock;
b5bebe41 45 struct kfifo fifo;
340a614a 46 struct work_struct work;
5ed8d32e 47 struct tasklet_struct tasklet;
340a614a
HD
48 int (*callback)(void *);
49 struct omap_mbox *mbox;
50};
51
52struct omap_mbox {
53 char *name;
54 unsigned int irq;
55
56 struct omap_mbox_queue *txq, *rxq;
57
58 struct omap_mbox_ops *ops;
59
60 mbox_msg_t seq_snd, seq_rcv;
61
f48cca87 62 struct device *dev;
340a614a
HD
63
64 struct omap_mbox *next;
65 void *priv;
66
67 void (*err_notify)(void);
68};
69
b2b6362e 70int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
340a614a
HD
71void omap_mbox_init_seq(struct omap_mbox *);
72
73struct omap_mbox *omap_mbox_get(const char *);
74void omap_mbox_put(struct omap_mbox *);
75
f48cca87 76int omap_mbox_register(struct device *parent, struct omap_mbox *);
340a614a
HD
77int omap_mbox_unregister(struct omap_mbox *);
78
c75ee752
HD
79static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
80{
81 if (!mbox->ops->save_ctx) {
82 dev_err(mbox->dev, "%s:\tno save\n", __func__);
83 return;
84 }
85
86 mbox->ops->save_ctx(mbox);
87}
88
89static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
90{
91 if (!mbox->ops->restore_ctx) {
92 dev_err(mbox->dev, "%s:\tno restore\n", __func__);
93 return;
94 }
95
96 mbox->ops->restore_ctx(mbox);
97}
98
eb18858e
HD
99static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
100 omap_mbox_irq_t irq)
101{
102 mbox->ops->enable_irq(mbox, irq);
103}
104
105static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
106 omap_mbox_irq_t irq)
107{
108 mbox->ops->disable_irq(mbox, irq);
109}
110
340a614a 111#endif /* MAILBOX_H */