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