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> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 18 | #include <mach/mailbox.h> |
| 19 | #include <mach/irqs.h> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 20 | |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 21 | #define MAILBOX_REVISION 0x000 |
| 22 | #define MAILBOX_SYSCONFIG 0x010 |
| 23 | #define MAILBOX_SYSSTATUS 0x014 |
| 24 | #define MAILBOX_MESSAGE(m) (0x040 + 4 * (m)) |
| 25 | #define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m)) |
| 26 | #define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m)) |
| 27 | #define MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u)) |
| 28 | #define MAILBOX_IRQENABLE(u) (0x104 + 8 * (u)) |
| 29 | |
| 30 | #define MAILBOX_IRQ_NEWMSG(u) (1 << (2 * (u))) |
| 31 | #define MAILBOX_IRQ_NOTFULL(u) (1 << (2 * (u) + 1)) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 32 | |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 33 | /* SYSCONFIG: register bit definition */ |
| 34 | #define AUTOIDLE (1 << 0) |
| 35 | #define SOFTRESET (1 << 1) |
| 36 | #define SMARTIDLE (2 << 3) |
| 37 | |
| 38 | /* SYSSTATUS: register bit definition */ |
| 39 | #define RESETDONE (1 << 0) |
| 40 | |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 41 | #define MBOX_REG_SIZE 0x120 |
| 42 | #define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32)) |
| 43 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 44 | static void __iomem *mbox_base; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 45 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 46 | struct omap_mbox2_fifo { |
| 47 | unsigned long msg; |
| 48 | unsigned long fifo_stat; |
| 49 | unsigned long msg_stat; |
| 50 | }; |
| 51 | |
| 52 | struct omap_mbox2_priv { |
| 53 | struct omap_mbox2_fifo tx_fifo; |
| 54 | struct omap_mbox2_fifo rx_fifo; |
| 55 | unsigned long irqenable; |
| 56 | unsigned long irqstatus; |
| 57 | u32 newmsg_bit; |
| 58 | u32 notfull_bit; |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 59 | u32 ctx[MBOX_NR_REGS]; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static struct clk *mbox_ick_handle; |
| 63 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 64 | static void omap2_mbox_enable_irq(struct omap_mbox *mbox, |
| 65 | omap_mbox_type_t irq); |
| 66 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 67 | static inline unsigned int mbox_read_reg(size_t ofs) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 68 | { |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 69 | return __raw_readl(mbox_base + ofs); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 72 | static inline void mbox_write_reg(u32 val, size_t ofs) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 73 | { |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 74 | __raw_writel(val, mbox_base + ofs); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* Mailbox H/W preparations */ |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 78 | static int omap2_mbox_startup(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 79 | { |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 80 | u32 l; |
| 81 | unsigned long timeout; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 82 | |
| 83 | mbox_ick_handle = clk_get(NULL, "mailboxes_ick"); |
| 84 | if (IS_ERR(mbox_ick_handle)) { |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 85 | pr_err("Can't get mailboxes_ick\n"); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 86 | return -ENODEV; |
| 87 | } |
| 88 | clk_enable(mbox_ick_handle); |
| 89 | |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 90 | mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG); |
| 91 | timeout = jiffies + msecs_to_jiffies(20); |
| 92 | do { |
| 93 | l = mbox_read_reg(MAILBOX_SYSSTATUS); |
| 94 | if (l & RESETDONE) |
| 95 | break; |
Hiroshi DOYU | 055c49d | 2009-09-28 09:21:26 -0700 | [diff] [blame] | 96 | } while (!time_after(jiffies, timeout)); |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 97 | |
| 98 | if (!(l & RESETDONE)) { |
| 99 | pr_err("Can't take mmu out of reset\n"); |
| 100 | return -ENODEV; |
| 101 | } |
| 102 | |
Hiroshi DOYU | 94fc58c | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 103 | l = mbox_read_reg(MAILBOX_REVISION); |
| 104 | pr_info("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f)); |
| 105 | |
Hiroshi DOYU | 1ffe627 | 2009-09-24 16:23:09 -0700 | [diff] [blame] | 106 | l = SMARTIDLE | AUTOIDLE; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 107 | mbox_write_reg(l, MAILBOX_SYSCONFIG); |
| 108 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 109 | omap2_mbox_enable_irq(mbox, IRQ_RX); |
| 110 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 114 | static void omap2_mbox_shutdown(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 115 | { |
| 116 | clk_disable(mbox_ick_handle); |
| 117 | clk_put(mbox_ick_handle); |
| 118 | } |
| 119 | |
| 120 | /* Mailbox FIFO handle functions */ |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 121 | static mbox_msg_t omap2_mbox_fifo_read(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 122 | { |
| 123 | struct omap_mbox2_fifo *fifo = |
| 124 | &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo; |
| 125 | return (mbox_msg_t) mbox_read_reg(fifo->msg); |
| 126 | } |
| 127 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 128 | 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] | 129 | { |
| 130 | struct omap_mbox2_fifo *fifo = |
| 131 | &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo; |
| 132 | mbox_write_reg(msg, fifo->msg); |
| 133 | } |
| 134 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 135 | static int omap2_mbox_fifo_empty(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 136 | { |
| 137 | struct omap_mbox2_fifo *fifo = |
| 138 | &((struct omap_mbox2_priv *)mbox->priv)->rx_fifo; |
| 139 | return (mbox_read_reg(fifo->msg_stat) == 0); |
| 140 | } |
| 141 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 142 | static int omap2_mbox_fifo_full(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 143 | { |
| 144 | struct omap_mbox2_fifo *fifo = |
| 145 | &((struct omap_mbox2_priv *)mbox->priv)->tx_fifo; |
| 146 | return (mbox_read_reg(fifo->fifo_stat)); |
| 147 | } |
| 148 | |
| 149 | /* Mailbox IRQ handle functions */ |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 150 | static void omap2_mbox_enable_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 151 | omap_mbox_type_t irq) |
| 152 | { |
| 153 | struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv; |
| 154 | u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 155 | |
| 156 | l = mbox_read_reg(p->irqenable); |
| 157 | l |= bit; |
| 158 | mbox_write_reg(l, p->irqenable); |
| 159 | } |
| 160 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 161 | static void omap2_mbox_disable_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 162 | omap_mbox_type_t irq) |
| 163 | { |
| 164 | struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv; |
| 165 | u32 l, bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 166 | |
| 167 | l = mbox_read_reg(p->irqenable); |
| 168 | l &= ~bit; |
| 169 | mbox_write_reg(l, p->irqenable); |
| 170 | } |
| 171 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 172 | static void omap2_mbox_ack_irq(struct omap_mbox *mbox, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 173 | omap_mbox_type_t irq) |
| 174 | { |
| 175 | struct omap_mbox2_priv *p = (struct omap_mbox2_priv *)mbox->priv; |
| 176 | u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 177 | |
| 178 | mbox_write_reg(bit, p->irqstatus); |
Hiroshi DOYU | 8828880 | 2009-09-24 16:23:10 -0700 | [diff] [blame] | 179 | |
| 180 | /* Flush posted write for irq status to avoid spurious interrupts */ |
| 181 | mbox_read_reg(p->irqstatus); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Hiroshi DOYU | bfbdcf8 | 2007-07-30 14:04:04 +0300 | [diff] [blame] | 184 | static int omap2_mbox_is_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 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; |
| 189 | u32 enable = mbox_read_reg(p->irqenable); |
| 190 | u32 status = mbox_read_reg(p->irqstatus); |
| 191 | |
| 192 | return (enable & status & bit); |
| 193 | } |
| 194 | |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 195 | static void omap2_mbox_save_ctx(struct omap_mbox *mbox) |
| 196 | { |
| 197 | int i; |
| 198 | struct omap_mbox2_priv *p = mbox->priv; |
| 199 | |
| 200 | for (i = 0; i < MBOX_NR_REGS; i++) { |
| 201 | p->ctx[i] = mbox_read_reg(i * sizeof(u32)); |
| 202 | |
| 203 | dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
| 204 | i, p->ctx[i]); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | static void omap2_mbox_restore_ctx(struct omap_mbox *mbox) |
| 209 | { |
| 210 | int i; |
| 211 | struct omap_mbox2_priv *p = mbox->priv; |
| 212 | |
| 213 | for (i = 0; i < MBOX_NR_REGS; i++) { |
| 214 | mbox_write_reg(p->ctx[i], i * sizeof(u32)); |
| 215 | |
| 216 | dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
| 217 | i, p->ctx[i]); |
| 218 | } |
| 219 | } |
| 220 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 221 | static struct omap_mbox_ops omap2_mbox_ops = { |
| 222 | .type = OMAP_MBOX_TYPE2, |
| 223 | .startup = omap2_mbox_startup, |
| 224 | .shutdown = omap2_mbox_shutdown, |
| 225 | .fifo_read = omap2_mbox_fifo_read, |
| 226 | .fifo_write = omap2_mbox_fifo_write, |
| 227 | .fifo_empty = omap2_mbox_fifo_empty, |
| 228 | .fifo_full = omap2_mbox_fifo_full, |
| 229 | .enable_irq = omap2_mbox_enable_irq, |
| 230 | .disable_irq = omap2_mbox_disable_irq, |
| 231 | .ack_irq = omap2_mbox_ack_irq, |
| 232 | .is_irq = omap2_mbox_is_irq, |
Hiroshi DOYU | c75ee75 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 233 | .save_ctx = omap2_mbox_save_ctx, |
| 234 | .restore_ctx = omap2_mbox_restore_ctx, |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | /* |
| 238 | * MAILBOX 0: ARM -> DSP, |
| 239 | * MAILBOX 1: ARM <- DSP. |
| 240 | * MAILBOX 2: ARM -> IVA, |
| 241 | * MAILBOX 3: ARM <- IVA. |
| 242 | */ |
| 243 | |
| 244 | /* FIXME: the following structs should be filled automatically by the user id */ |
| 245 | |
| 246 | /* DSP */ |
| 247 | static struct omap_mbox2_priv omap2_mbox_dsp_priv = { |
| 248 | .tx_fifo = { |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 249 | .msg = MAILBOX_MESSAGE(0), |
| 250 | .fifo_stat = MAILBOX_FIFOSTATUS(0), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 251 | }, |
| 252 | .rx_fifo = { |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 253 | .msg = MAILBOX_MESSAGE(1), |
| 254 | .msg_stat = MAILBOX_MSGSTATUS(1), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 255 | }, |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 256 | .irqenable = MAILBOX_IRQENABLE(0), |
| 257 | .irqstatus = MAILBOX_IRQSTATUS(0), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 258 | .notfull_bit = MAILBOX_IRQ_NOTFULL(0), |
| 259 | .newmsg_bit = MAILBOX_IRQ_NEWMSG(1), |
| 260 | }; |
| 261 | |
| 262 | struct omap_mbox mbox_dsp_info = { |
| 263 | .name = "dsp", |
| 264 | .ops = &omap2_mbox_ops, |
| 265 | .priv = &omap2_mbox_dsp_priv, |
| 266 | }; |
| 267 | EXPORT_SYMBOL(mbox_dsp_info); |
| 268 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 269 | #if defined(CONFIG_ARCH_OMAP2420) /* IVA */ |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 270 | static struct omap_mbox2_priv omap2_mbox_iva_priv = { |
| 271 | .tx_fifo = { |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 272 | .msg = MAILBOX_MESSAGE(2), |
| 273 | .fifo_stat = MAILBOX_FIFOSTATUS(2), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 274 | }, |
| 275 | .rx_fifo = { |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 276 | .msg = MAILBOX_MESSAGE(3), |
| 277 | .msg_stat = MAILBOX_MSGSTATUS(3), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 278 | }, |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 279 | .irqenable = MAILBOX_IRQENABLE(3), |
| 280 | .irqstatus = MAILBOX_IRQSTATUS(3), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 281 | .notfull_bit = MAILBOX_IRQ_NOTFULL(2), |
| 282 | .newmsg_bit = MAILBOX_IRQ_NEWMSG(3), |
| 283 | }; |
| 284 | |
| 285 | static struct omap_mbox mbox_iva_info = { |
| 286 | .name = "iva", |
| 287 | .ops = &omap2_mbox_ops, |
| 288 | .priv = &omap2_mbox_iva_priv, |
| 289 | }; |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 290 | #endif |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 291 | |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 292 | static int __devinit omap2_mbox_probe(struct platform_device *pdev) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 293 | { |
| 294 | struct resource *res; |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 295 | int ret; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 296 | |
| 297 | /* MBOX base */ |
| 298 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 299 | if (unlikely(!res)) { |
| 300 | dev_err(&pdev->dev, "invalid mem resource\n"); |
| 301 | return -ENODEV; |
| 302 | } |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 303 | mbox_base = ioremap(res->start, res->end - res->start); |
| 304 | if (!mbox_base) |
| 305 | return -ENOMEM; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 306 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 307 | /* DSP or IVA2 IRQ */ |
Roel Kluin | 091a58a | 2009-06-23 13:30:22 +0300 | [diff] [blame] | 308 | ret = platform_get_irq(pdev, 0); |
| 309 | if (ret < 0) { |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 310 | dev_err(&pdev->dev, "invalid irq resource\n"); |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 311 | goto err_dsp; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 312 | } |
Roel Kluin | 091a58a | 2009-06-23 13:30:22 +0300 | [diff] [blame] | 313 | mbox_dsp_info.irq = ret; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 314 | |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 315 | ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info); |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 316 | if (ret) |
| 317 | goto err_dsp; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 318 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 319 | #if defined(CONFIG_ARCH_OMAP2420) /* IVA */ |
| 320 | if (cpu_is_omap2420()) { |
| 321 | /* IVA IRQ */ |
| 322 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); |
| 323 | if (unlikely(!res)) { |
| 324 | dev_err(&pdev->dev, "invalid irq resource\n"); |
| 325 | ret = -ENODEV; |
| 326 | goto err_iva1; |
| 327 | } |
| 328 | mbox_iva_info.irq = res->start; |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 329 | ret = omap_mbox_register(&pdev->dev, &mbox_iva_info); |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 330 | if (ret) |
| 331 | goto err_iva1; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 332 | } |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 333 | #endif |
| 334 | return 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 335 | |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 336 | err_iva1: |
| 337 | omap_mbox_unregister(&mbox_dsp_info); |
| 338 | err_dsp: |
| 339 | iounmap(mbox_base); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 340 | return ret; |
| 341 | } |
| 342 | |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 343 | static int __devexit omap2_mbox_remove(struct platform_device *pdev) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 344 | { |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 345 | #if defined(CONFIG_ARCH_OMAP2420) |
| 346 | omap_mbox_unregister(&mbox_iva_info); |
| 347 | #endif |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 348 | omap_mbox_unregister(&mbox_dsp_info); |
Hiroshi DOYU | 6c20a68 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 349 | iounmap(mbox_base); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static struct platform_driver omap2_mbox_driver = { |
| 354 | .probe = omap2_mbox_probe, |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 355 | .remove = __devexit_p(omap2_mbox_remove), |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 356 | .driver = { |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 357 | .name = "omap2-mailbox", |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 358 | }, |
| 359 | }; |
| 360 | |
| 361 | static int __init omap2_mbox_init(void) |
| 362 | { |
| 363 | return platform_driver_register(&omap2_mbox_driver); |
| 364 | } |
| 365 | |
| 366 | static void __exit omap2_mbox_exit(void) |
| 367 | { |
| 368 | platform_driver_unregister(&omap2_mbox_driver); |
| 369 | } |
| 370 | |
| 371 | module_init(omap2_mbox_init); |
| 372 | module_exit(omap2_mbox_exit); |
| 373 | |
Hiroshi DOYU | 733ecc5 | 2009-03-23 18:07:23 -0700 | [diff] [blame] | 374 | MODULE_LICENSE("GPL v2"); |
| 375 | MODULE_DESCRIPTION("omap mailbox: omap2/3 architecture specific functions"); |
| 376 | MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>, Paul Mundt"); |
Hiroshi DOYU | da8cfe0 | 2009-03-23 18:07:25 -0700 | [diff] [blame] | 377 | MODULE_ALIAS("platform:omap2-mailbox"); |