Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 1 | /* |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 2 | * Mailbox reservation modules for OMAP2/3 |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 3 | * |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 4 | * Copyright (C) 2006-2009 Nokia Corporation |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 5 | * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com> |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 6 | * and Paul Mundt |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file "COPYING" in the main directory of this archive |
| 10 | * for more details. |
| 11 | */ |
| 12 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 13 | #include <linux/clk.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/platform_device.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 16 | #include <linux/io.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 17 | #include <plat/mailbox.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 18 | #include <mach/irqs.h> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 19 | |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 20 | #define MAILBOX_REVISION 0x000 |
| 21 | #define MAILBOX_SYSCONFIG 0x010 |
| 22 | #define MAILBOX_SYSSTATUS 0x014 |
| 23 | #define MAILBOX_MESSAGE(m) (0x040 + 4 * (m)) |
| 24 | #define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m)) |
| 25 | #define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m)) |
| 26 | #define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u)) |
| 27 | #define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u)) |
| 28 | |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 29 | #define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 10 * (u)) |
| 30 | #define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 10 * (u)) |
| 31 | #define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 10 * (u)) |
| 32 | |
| 33 | #define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m))) |
| 34 | #define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1)) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 35 | |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 36 | /* SYSCONFIG: register bit definition */ |
| 37 | #define AUTOIDLE (1 << 0) |
| 38 | #define SOFTRESET (1 << 1) |
| 39 | #define SMARTIDLE (2 << 3) |
Suman Anna | a6a6022 | 2010-01-26 16:55:29 -0600 | [diff] [blame] | 40 | #define OMAP4_SOFTRESET (1 << 0) |
Suman Anna | 4499ce4 | 2010-02-05 17:20:26 -0600 | [diff] [blame] | 41 | #define OMAP4_NOIDLE (1 << 2) |
| 42 | #define OMAP4_SMARTIDLE (2 << 2) |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 43 | |
| 44 | /* SYSSTATUS: register bit definition */ |
| 45 | #define RESETDONE (1 << 0) |
| 46 | |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 47 | #define MBOX_REG_SIZE 0x120 |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 48 | |
| 49 | #define OMAP4_MBOX_REG_SIZE 0x130 |
| 50 | |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 51 | #define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32)) |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 52 | #define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32)) |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 53 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 54 | static void __iomem *mbox_base; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 55 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 56 | struct omap_mbox2_fifo { |
| 57 | unsigned long msg; |
| 58 | unsigned long fifo_stat; |
| 59 | unsigned long msg_stat; |
| 60 | }; |
| 61 | |
| 62 | struct omap_mbox2_priv { |
| 63 | struct omap_mbox2_fifo tx_fifo; |
| 64 | struct omap_mbox2_fifo rx_fifo; |
| 65 | unsigned long irqenable; |
| 66 | unsigned long irqstatus; |
| 67 | u32 newmsg_bit; |
| 68 | u32 notfull_bit; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 69 | u32 ctx[OMAP4_MBOX_NR_REGS]; |
| 70 | unsigned long irqdisable; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static struct clk *mbox_ick_handle; |
| 74 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 75 | static void omap2_mbox_enable_irq(struct omap_mbox *mbox, |
| 76 | omap_mbox_type_t irq); |
| 77 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 78 | static inline unsigned int mbox_read_reg(size_t ofs) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 79 | { |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 80 | return __raw_readl(mbox_base + ofs); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 83 | static inline void mbox_write_reg(u32 val, size_t ofs) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 84 | { |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 85 | __raw_writel(val, mbox_base + ofs); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* Mailbox H/W preparations */ |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 89 | static int omap2_mbox_startup(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 90 | { |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 91 | u32 l; |
| 92 | unsigned long timeout; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 93 | |
| 94 | mbox_ick_handle = clk_get(NULL, "mailboxes_ick"); |
| 95 | if (IS_ERR(mbox_ick_handle)) { |
Felipe Balbi | 0cd7e1c | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 96 | printk(KERN_ERR "Could not get mailboxes_ick: %ld\n", |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 97 | PTR_ERR(mbox_ick_handle)); |
| 98 | return PTR_ERR(mbox_ick_handle); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 99 | } |
| 100 | clk_enable(mbox_ick_handle); |
| 101 | |
Suman Anna | a6a6022 | 2010-01-26 16:55:29 -0600 | [diff] [blame] | 102 | if (cpu_is_omap44xx()) { |
| 103 | mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG); |
| 104 | timeout = jiffies + msecs_to_jiffies(20); |
| 105 | do { |
| 106 | l = mbox_read_reg(MAILBOX_SYSCONFIG); |
| 107 | if (!(l & OMAP4_SOFTRESET)) |
| 108 | break; |
| 109 | } while (!time_after(jiffies, timeout)); |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 110 | |
Suman Anna | a6a6022 | 2010-01-26 16:55:29 -0600 | [diff] [blame] | 111 | if (l & OMAP4_SOFTRESET) { |
| 112 | pr_err("Can't take mailbox out of reset\n"); |
| 113 | return -ENODEV; |
| 114 | } |
| 115 | } else { |
| 116 | mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG); |
| 117 | timeout = jiffies + msecs_to_jiffies(20); |
| 118 | do { |
| 119 | l = mbox_read_reg(MAILBOX_SYSSTATUS); |
| 120 | if (l & RESETDONE) |
| 121 | break; |
| 122 | } while (!time_after(jiffies, timeout)); |
| 123 | |
| 124 | if (!(l & RESETDONE)) { |
| 125 | pr_err("Can't take mailbox out of reset\n"); |
| 126 | return -ENODEV; |
| 127 | } |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Hiroshi DOYU | 94fc58c | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 130 | l = mbox_read_reg(MAILBOX_REVISION); |
Felipe Contreras | 909f9dc | 2010-06-11 15:51:37 +0000 | [diff] [blame] | 131 | pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f)); |
Hiroshi DOYU | 94fc58c | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 132 | |
Suman Anna | 4499ce4 | 2010-02-05 17:20:26 -0600 | [diff] [blame] | 133 | if (cpu_is_omap44xx()) |
| 134 | l = OMAP4_SMARTIDLE; |
| 135 | else |
| 136 | l = SMARTIDLE | AUTOIDLE; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 137 | mbox_write_reg(l, MAILBOX_SYSCONFIG); |
| 138 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 139 | omap2_mbox_enable_irq(mbox, IRQ_RX); |
| 140 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 144 | static void omap2_mbox_shutdown(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 145 | { |
| 146 | clk_disable(mbox_ick_handle); |
| 147 | clk_put(mbox_ick_handle); |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 148 | mbox_ick_handle = NULL; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* Mailbox FIFO handle functions */ |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 152 | static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 153 | { |
| 154 | struct omap_mbox2_fifo *fifo = |
| 155 | &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo; |
| 156 | return (mbox_msg_t) mbox_read_reg(fifo->msg); |
| 157 | } |
| 158 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 159 | static void omap2_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 160 | { |
| 161 | struct omap_mbox2_fifo *fifo = |
| 162 | &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo; |
| 163 | mbox_write_reg(msg, fifo->msg); |
| 164 | } |
| 165 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 166 | static int omap2_mbox_fifo_empty(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 167 | { |
| 168 | struct omap_mbox2_fifo *fifo = |
| 169 | &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo; |
| 170 | return (mbox_read_reg(fifo->msg_stat) == 0); |
| 171 | } |
| 172 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 173 | static int omap2_mbox_fifo_full(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 174 | { |
| 175 | struct omap_mbox2_fifo *fifo = |
| 176 | &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 177 | return mbox_read_reg(fifo->fifo_stat); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* Mailbox IRQ handle functions */ |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 181 | static void omap2_mbox_enable_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 182 | omap_mbox_type_t irq) |
| 183 | { |
matt mooney | b45b501 | 2010-09-27 19:04:32 -0700 | [diff] [blame] | 184 | struct omap_mbox2_priv *p = mbox->priv; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 185 | u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 186 | |
| 187 | l = mbox_read_reg(p->irqenable); |
| 188 | l |= bit; |
| 189 | mbox_write_reg(l, p->irqenable); |
| 190 | } |
| 191 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 192 | static void omap2_mbox_disable_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 193 | omap_mbox_type_t irq) |
| 194 | { |
matt mooney | b45b501 | 2010-09-27 19:04:32 -0700 | [diff] [blame] | 195 | struct omap_mbox2_priv *p = mbox->priv; |
Hari Kanigeri | 525a113 | 2011-03-02 22:14:18 +0000 | [diff] [blame^] | 196 | u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 197 | |
| 198 | if (!cpu_is_omap44xx()) |
| 199 | bit = mbox_read_reg(p->irqdisable) & ~bit; |
| 200 | |
| 201 | mbox_write_reg(bit, p->irqdisable); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 204 | static void omap2_mbox_ack_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 205 | omap_mbox_type_t irq) |
| 206 | { |
matt mooney | b45b501 | 2010-09-27 19:04:32 -0700 | [diff] [blame] | 207 | struct omap_mbox2_priv *p = mbox->priv; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 208 | u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 209 | |
| 210 | mbox_write_reg(bit, p->irqstatus); |
Hiroshi DOYU | 8828880 | 2009-09-24 16:23:10 -0700 | [diff] [blame] | 211 | |
| 212 | /* Flush posted write for irq status to avoid spurious interrupts */ |
| 213 | mbox_read_reg(p->irqstatus); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 216 | static int omap2_mbox_is_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 217 | omap_mbox_type_t irq) |
| 218 | { |
matt mooney | b45b501 | 2010-09-27 19:04:32 -0700 | [diff] [blame] | 219 | struct omap_mbox2_priv *p = mbox->priv; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 220 | u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 221 | u32 enable = mbox_read_reg(p->irqenable); |
| 222 | u32 status = mbox_read_reg(p->irqstatus); |
| 223 | |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 224 | return (int)(enable & status & bit); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 227 | static void omap2_mbox_save_ctx(struct omap_mbox *mbox) |
| 228 | { |
| 229 | int i; |
| 230 | struct omap_mbox2_priv *p = mbox->priv; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 231 | int nr_regs; |
| 232 | if (cpu_is_omap44xx()) |
| 233 | nr_regs = OMAP4_MBOX_NR_REGS; |
| 234 | else |
| 235 | nr_regs = MBOX_NR_REGS; |
| 236 | for (i = 0; i < nr_regs; i++) { |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 237 | p->ctx[i] = mbox_read_reg(i * sizeof(u32)); |
| 238 | |
| 239 | dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
| 240 | i, p->ctx[i]); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static void omap2_mbox_restore_ctx(struct omap_mbox *mbox) |
| 245 | { |
| 246 | int i; |
| 247 | struct omap_mbox2_priv *p = mbox->priv; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 248 | int nr_regs; |
| 249 | if (cpu_is_omap44xx()) |
| 250 | nr_regs = OMAP4_MBOX_NR_REGS; |
| 251 | else |
| 252 | nr_regs = MBOX_NR_REGS; |
| 253 | for (i = 0; i < nr_regs; i++) { |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 254 | mbox_write_reg(p->ctx[i], i * sizeof(u32)); |
| 255 | |
| 256 | dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
| 257 | i, p->ctx[i]); |
| 258 | } |
| 259 | } |
| 260 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 261 | static struct omap_mbox_ops omap2_mbox_ops = { |
| 262 | .type = OMAP_MBOX_TYPE2, |
| 263 | .startup = omap2_mbox_startup, |
| 264 | .shutdown = omap2_mbox_shutdown, |
| 265 | .fifo_read = omap2_mbox_fifo_read, |
| 266 | .fifo_write = omap2_mbox_fifo_write, |
| 267 | .fifo_empty = omap2_mbox_fifo_empty, |
| 268 | .fifo_full = omap2_mbox_fifo_full, |
| 269 | .enable_irq = omap2_mbox_enable_irq, |
| 270 | .disable_irq = omap2_mbox_disable_irq, |
| 271 | .ack_irq = omap2_mbox_ack_irq, |
| 272 | .is_irq = omap2_mbox_is_irq, |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 273 | .save_ctx = omap2_mbox_save_ctx, |
| 274 | .restore_ctx = omap2_mbox_restore_ctx, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | /* |
| 278 | * MAILBOX 0: ARM -> DSP, |
| 279 | * MAILBOX 1: ARM <- DSP. |
| 280 | * MAILBOX 2: ARM -> IVA, |
| 281 | * MAILBOX 3: ARM <- IVA. |
| 282 | */ |
| 283 | |
| 284 | /* FIXME: the following structs should be filled automatically by the user id */ |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 285 | |
Omar Ramirez Luna | ff0fba0 | 2010-10-22 20:10:58 -0500 | [diff] [blame] | 286 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP2) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 287 | /* DSP */ |
| 288 | static struct omap_mbox2_priv omap2_mbox_dsp_priv = { |
| 289 | .tx_fifo = { |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 290 | .msg = MAILBOX_MESSAGE(0), |
| 291 | .fifo_stat = MAILBOX_FIFOSTATUS(0), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 292 | }, |
| 293 | .rx_fifo = { |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 294 | .msg = MAILBOX_MESSAGE(1), |
| 295 | .msg_stat = MAILBOX_MSGSTATUS(1), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 296 | }, |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 297 | .irqenable = MAILBOX_IRQENABLE(0), |
| 298 | .irqstatus = MAILBOX_IRQSTATUS(0), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 299 | .notfull_bit = MAILBOX_IRQ_NOTFULL(0), |
| 300 | .newmsg_bit = MAILBOX_IRQ_NEWMSG(1), |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 301 | .irqdisable = MAILBOX_IRQENABLE(0), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 302 | }; |
| 303 | |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 304 | struct omap_mbox mbox_dsp_info = { |
| 305 | .name = "dsp", |
| 306 | .ops = &omap2_mbox_ops, |
| 307 | .priv = &omap2_mbox_dsp_priv, |
| 308 | }; |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 309 | #endif |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 310 | |
Omar Ramirez Luna | ff0fba0 | 2010-10-22 20:10:58 -0500 | [diff] [blame] | 311 | #if defined(CONFIG_ARCH_OMAP3) |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 312 | struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL }; |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 313 | #endif |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 314 | |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 315 | #if defined(CONFIG_ARCH_OMAP2420) |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 316 | /* IVA */ |
| 317 | static struct omap_mbox2_priv omap2_mbox_iva_priv = { |
| 318 | .tx_fifo = { |
| 319 | .msg = MAILBOX_MESSAGE(2), |
| 320 | .fifo_stat = MAILBOX_FIFOSTATUS(2), |
| 321 | }, |
| 322 | .rx_fifo = { |
| 323 | .msg = MAILBOX_MESSAGE(3), |
| 324 | .msg_stat = MAILBOX_MSGSTATUS(3), |
| 325 | }, |
| 326 | .irqenable = MAILBOX_IRQENABLE(3), |
| 327 | .irqstatus = MAILBOX_IRQSTATUS(3), |
| 328 | .notfull_bit = MAILBOX_IRQ_NOTFULL(2), |
| 329 | .newmsg_bit = MAILBOX_IRQ_NEWMSG(3), |
| 330 | .irqdisable = MAILBOX_IRQENABLE(3), |
| 331 | }; |
| 332 | |
| 333 | static struct omap_mbox mbox_iva_info = { |
| 334 | .name = "iva", |
| 335 | .ops = &omap2_mbox_ops, |
| 336 | .priv = &omap2_mbox_iva_priv, |
| 337 | }; |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 338 | |
Kevin Hilman | eca8325 | 2011-02-11 19:56:42 +0000 | [diff] [blame] | 339 | struct omap_mbox *omap2_mboxes[] = { &mbox_dsp_info, &mbox_iva_info, NULL }; |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 340 | #endif |
| 341 | |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 342 | #if defined(CONFIG_ARCH_OMAP4) |
Felipe Contreras | 07d65d8 | 2010-06-11 15:51:38 +0000 | [diff] [blame] | 343 | /* OMAP4 */ |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 344 | static struct omap_mbox2_priv omap2_mbox_1_priv = { |
| 345 | .tx_fifo = { |
| 346 | .msg = MAILBOX_MESSAGE(0), |
| 347 | .fifo_stat = MAILBOX_FIFOSTATUS(0), |
| 348 | }, |
| 349 | .rx_fifo = { |
| 350 | .msg = MAILBOX_MESSAGE(1), |
| 351 | .msg_stat = MAILBOX_MSGSTATUS(1), |
| 352 | }, |
| 353 | .irqenable = OMAP4_MAILBOX_IRQENABLE(0), |
| 354 | .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0), |
| 355 | .notfull_bit = MAILBOX_IRQ_NOTFULL(0), |
| 356 | .newmsg_bit = MAILBOX_IRQ_NEWMSG(1), |
| 357 | .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0), |
| 358 | }; |
| 359 | |
| 360 | struct omap_mbox mbox_1_info = { |
| 361 | .name = "mailbox-1", |
| 362 | .ops = &omap2_mbox_ops, |
| 363 | .priv = &omap2_mbox_1_priv, |
| 364 | }; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 365 | |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 366 | static struct omap_mbox2_priv omap2_mbox_2_priv = { |
| 367 | .tx_fifo = { |
| 368 | .msg = MAILBOX_MESSAGE(3), |
| 369 | .fifo_stat = MAILBOX_FIFOSTATUS(3), |
| 370 | }, |
| 371 | .rx_fifo = { |
| 372 | .msg = MAILBOX_MESSAGE(2), |
| 373 | .msg_stat = MAILBOX_MSGSTATUS(2), |
| 374 | }, |
| 375 | .irqenable = OMAP4_MAILBOX_IRQENABLE(0), |
| 376 | .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0), |
| 377 | .notfull_bit = MAILBOX_IRQ_NOTFULL(3), |
| 378 | .newmsg_bit = MAILBOX_IRQ_NEWMSG(2), |
| 379 | .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0), |
| 380 | }; |
| 381 | |
| 382 | struct omap_mbox mbox_2_info = { |
| 383 | .name = "mailbox-2", |
| 384 | .ops = &omap2_mbox_ops, |
| 385 | .priv = &omap2_mbox_2_priv, |
| 386 | }; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 387 | |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 388 | struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL }; |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 389 | #endif |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 390 | |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 391 | static int __devinit omap2_mbox_probe(struct platform_device *pdev) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 392 | { |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 393 | struct resource *mem; |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 394 | int ret; |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 395 | struct omap_mbox **list; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 396 | |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 397 | if (false) |
| 398 | ; |
Omar Ramirez Luna | ff0fba0 | 2010-10-22 20:10:58 -0500 | [diff] [blame] | 399 | #if defined(CONFIG_ARCH_OMAP3) |
| 400 | else if (cpu_is_omap34xx()) { |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 401 | list = omap3_mboxes; |
| 402 | |
| 403 | list[0]->irq = platform_get_irq_byname(pdev, "dsp"); |
| 404 | } |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 405 | #endif |
Omar Ramirez Luna | ff0fba0 | 2010-10-22 20:10:58 -0500 | [diff] [blame] | 406 | #if defined(CONFIG_ARCH_OMAP2) |
| 407 | else if (cpu_is_omap2430()) { |
| 408 | list = omap2_mboxes; |
| 409 | |
| 410 | list[0]->irq = platform_get_irq_byname(pdev, "dsp"); |
| 411 | } else if (cpu_is_omap2420()) { |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 412 | list = omap2_mboxes; |
| 413 | |
| 414 | list[0]->irq = platform_get_irq_byname(pdev, "dsp"); |
| 415 | list[1]->irq = platform_get_irq_byname(pdev, "iva"); |
| 416 | } |
| 417 | #endif |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 418 | #if defined(CONFIG_ARCH_OMAP4) |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 419 | else if (cpu_is_omap44xx()) { |
| 420 | list = omap4_mboxes; |
| 421 | |
| 422 | list[0]->irq = list[1]->irq = |
| 423 | platform_get_irq_byname(pdev, "mbox"); |
| 424 | } |
Felipe Contreras | 14476bd | 2010-06-11 15:51:47 +0000 | [diff] [blame] | 425 | #endif |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 426 | else { |
| 427 | pr_err("%s: platform not supported\n", __func__); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 428 | return -ENODEV; |
| 429 | } |
Felipe Contreras | 898ee75 | 2010-06-11 15:51:45 +0000 | [diff] [blame] | 430 | |
| 431 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 432 | mbox_base = ioremap(mem->start, resource_size(mem)); |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 433 | if (!mbox_base) |
| 434 | return -ENOMEM; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 435 | |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 436 | ret = omap_mbox_register(&pdev->dev, list); |
| 437 | if (ret) { |
| 438 | iounmap(mbox_base); |
| 439 | return ret; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 440 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 441 | |
Omar Ramirez Luna | 5d78373 | 2010-12-01 14:15:08 -0600 | [diff] [blame] | 442 | return 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 445 | static int __devexit omap2_mbox_remove(struct platform_device *pdev) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 446 | { |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 447 | omap_mbox_unregister(); |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 448 | iounmap(mbox_base); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static struct platform_driver omap2_mbox_driver = { |
| 453 | .probe = omap2_mbox_probe, |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 454 | .remove = __devexit_p(omap2_mbox_remove), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 455 | .driver = { |
Felipe Contreras | d742709 | 2010-06-11 15:51:48 +0000 | [diff] [blame] | 456 | .name = "omap-mailbox", |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 457 | }, |
| 458 | }; |
| 459 | |
| 460 | static int __init omap2_mbox_init(void) |
| 461 | { |
| 462 | return platform_driver_register(&omap2_mbox_driver); |
| 463 | } |
| 464 | |
| 465 | static void __exit omap2_mbox_exit(void) |
| 466 | { |
| 467 | platform_driver_unregister(&omap2_mbox_driver); |
| 468 | } |
| 469 | |
| 470 | module_init(omap2_mbox_init); |
| 471 | module_exit(omap2_mbox_exit); |
| 472 | |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 473 | MODULE_LICENSE("GPL v2"); |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 474 | MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions"); |
Ohad Ben-Cohen | f375325 | 2010-05-05 15:33:07 +0000 | [diff] [blame] | 475 | MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>"); |
| 476 | MODULE_AUTHOR("Paul Mundt"); |
Felipe Contreras | d742709 | 2010-06-11 15:51:48 +0000 | [diff] [blame] | 477 | MODULE_ALIAS("platform:omap2-mailbox"); |