]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - sitara-epos/sitara-epos-kernel.git/blob - arch/arm/plat-omap/include/plat/mailbox.h
ARM: AM335X: Split hwmod data accessible only on GP devices
[sitara-epos/sitara-epos-kernel.git] / arch / arm / plat-omap / include / plat / mailbox.h
1 /* mailbox.h */
3 #ifndef MAILBOX_H
4 #define MAILBOX_H
6 #include <linux/spinlock.h>
7 #include <linux/workqueue.h>
8 #include <linux/interrupt.h>
9 #include <linux/device.h>
10 #include <linux/kfifo.h>
12 typedef u32 mbox_msg_t;
13 struct omap_mbox;
15 typedef 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)
19 typedef 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)
23 struct 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         int             (*fifo_needs_flush)(struct omap_mbox *mbox);
33         mbox_msg_t      (*fifo_readback)(struct omap_mbox *mbox);
34         /* irq */
35         void            (*enable_irq)(struct omap_mbox *mbox,
36                                                 omap_mbox_irq_t irq);
37         void            (*disable_irq)(struct omap_mbox *mbox,
38                                                 omap_mbox_irq_t irq);
39         void            (*ack_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
40         int             (*is_irq)(struct omap_mbox *mbox, omap_mbox_irq_t irq);
41         /* ctx */
42         void            (*save_ctx)(struct omap_mbox *mbox);
43         void            (*restore_ctx)(struct omap_mbox *mbox);
44 };
46 struct omap_mbox_queue {
47         spinlock_t              lock;
48         struct kfifo            fifo;
49         struct work_struct      work;
50         struct tasklet_struct   tasklet;
51         struct omap_mbox        *mbox;
52         bool full;
53 };
55 struct omap_mbox {
56         char                    *name;
57         unsigned int            irq;
58         struct omap_mbox_queue  *txq, *rxq;
59         struct omap_mbox_ops    *ops;
60         struct device           *dev;
61         void                    *priv;
62         int                     use_count;
63         struct blocking_notifier_head   notifier;
64 };
66 int omap_mbox_msg_rx_flush(struct omap_mbox *mbox);
67 int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
68 void omap_mbox_init_seq(struct omap_mbox *);
70 struct omap_mbox *omap_mbox_get(const char *, struct notifier_block *nb);
71 void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb);
73 int omap_mbox_register(struct device *parent, struct omap_mbox **);
74 int omap_mbox_unregister(void);
76 static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
77 {
78         if (!mbox->ops->save_ctx) {
79                 dev_err(mbox->dev, "%s:\tno save\n", __func__);
80                 return;
81         }
83         mbox->ops->save_ctx(mbox);
84 }
86 static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
87 {
88         if (!mbox->ops->restore_ctx) {
89                 dev_err(mbox->dev, "%s:\tno restore\n", __func__);
90                 return;
91         }
93         mbox->ops->restore_ctx(mbox);
94 }
96 static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
97                                         omap_mbox_irq_t irq)
98 {
99         mbox->ops->enable_irq(mbox, irq);
102 static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
103                                          omap_mbox_irq_t irq)
105         mbox->ops->disable_irq(mbox, irq);
108 #endif /* MAILBOX_H */