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