blob: cc3921e9059c8995d55334dba80ee64cba8d9aff [file] [log] [blame]
Hiroshi DOYU340a614a2006-12-07 15:43:59 -08001/* mailbox.h */
2
3#ifndef MAILBOX_H
4#define MAILBOX_H
5
Felipe Contrerasb3e69142010-06-11 15:51:49 +00006#include <linux/spinlock.h>
Hiroshi DOYU340a614a2006-12-07 15:43:59 -08007#include <linux/workqueue.h>
C A Subramaniam5ed8d322009-11-22 10:11:24 -08008#include <linux/interrupt.h>
Felipe Contrerasb3e69142010-06-11 15:51:49 +00009#include <linux/device.h>
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000010#include <linux/kfifo.h>
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080011
12typedef u32 mbox_msg_t;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080013struct omap_mbox;
14
15typedef int __bitwise omap_mbox_irq_t;
16#define IRQ_TX ((__force omap_mbox_irq_t) 1)
17#define IRQ_RX ((__force omap_mbox_irq_t) 2)
18
19typedef int __bitwise omap_mbox_type_t;
20#define OMAP_MBOX_TYPE1 ((__force omap_mbox_type_t) 1)
21#define OMAP_MBOX_TYPE2 ((__force omap_mbox_type_t) 2)
22
23struct omap_mbox_ops {
24 omap_mbox_type_t type;
25 int (*startup)(struct omap_mbox *mbox);
26 void (*shutdown)(struct omap_mbox *mbox);
27 /* fifo */
28 mbox_msg_t (*fifo_read)(struct omap_mbox *mbox);
29 void (*fifo_write)(struct omap_mbox *mbox, mbox_msg_t msg);
30 int (*fifo_empty)(struct omap_mbox *mbox);
31 int (*fifo_full)(struct omap_mbox *mbox);
32 /* irq */
C A Subramaniam5ed8d322009-11-22 10:11:24 -080033 void (*enable_irq)(struct omap_mbox *mbox,
34 omap_mbox_irq_t irq);
35 void (*disable_irq)(struct omap_mbox *mbox,
36 omap_mbox_irq_t irq);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080037 void (*ack_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
38 int (*is_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070039 /* ctx */
40 void (*save_ctx)(struct omap_mbox *mbox);
41 void (*restore_ctx)(struct omap_mbox *mbox);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080042};
43
44struct omap_mbox_queue {
45 spinlock_t lock;
Ohad Ben-Cohenb5bebe42010-05-05 15:33:09 +000046 struct kfifo fifo;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080047 struct work_struct work;
C A Subramaniam5ed8d322009-11-22 10:11:24 -080048 struct tasklet_struct tasklet;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080049 struct omap_mbox *mbox;
Fernando Guzman Lugod2295042010-11-29 20:24:11 +000050 bool full;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080051};
52
53struct omap_mbox {
54 char *name;
55 unsigned int irq;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080056 struct omap_mbox_queue *txq, *rxq;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080057 struct omap_mbox_ops *ops;
Hiroshi DOYUf48cca82009-03-23 18:07:24 -070058 struct device *dev;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080059 void *priv;
Kanigeri, Hari58256302010-11-29 20:24:14 +000060 int use_count;
61 struct blocking_notifier_head notifier;
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080062};
63
C A Subramaniamb2b63622009-11-22 10:11:20 -080064int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080065void omap_mbox_init_seq(struct omap_mbox *);
66
Kanigeri, Hari58256302010-11-29 20:24:14 +000067struct omap_mbox *omap_mbox_get(const char *, struct notifier_block *nb);
68void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080069
Felipe Contreras9c80c8c2010-06-11 15:51:46 +000070int omap_mbox_register(struct device *parent, struct omap_mbox **);
71int omap_mbox_unregister(void);
Hiroshi DOYU340a614a2006-12-07 15:43:59 -080072
Hiroshi DOYUc75ee752009-03-23 18:07:26 -070073static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
74{
75 if (!mbox->ops->save_ctx) {
76 dev_err(mbox->dev, "%s:\tno save\n", __func__);
77 return;
78 }
79
80 mbox->ops->save_ctx(mbox);
81}
82
83static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
84{
85 if (!mbox->ops->restore_ctx) {
86 dev_err(mbox->dev, "%s:\tno restore\n", __func__);
87 return;
88 }
89
90 mbox->ops->restore_ctx(mbox);
91}
92
Hiroshi DOYUeb188582009-11-22 10:11:22 -080093static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
94 omap_mbox_irq_t irq)
95{
96 mbox->ops->enable_irq(mbox, irq);
97}
98
99static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
100 omap_mbox_irq_t irq)
101{
102 mbox->ops->disable_irq(mbox, irq);
103}
104
Hiroshi DOYU340a614a2006-12-07 15:43:59 -0800105#endif /* MAILBOX_H */