Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * OMAP mailbox driver |
| 3 | * |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 4 | * Copyright (C) 2006-2009 Nokia Corporation. All rights reserved. |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 5 | * Copyright (C) 2013-2014 Texas Instruments Inc. |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 6 | * |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 7 | * Contact: Hiroshi DOYU <Hiroshi.DOYU@nokia.com> |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 8 | * Suman Anna <s-anna@ti.com> |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * version 2 as published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 22 | * 02110-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Felipe Contreras | b3e6914 | 2010-06-11 15:51:49 +0000 | [diff] [blame] | 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 30 | #include <linux/kfifo.h> |
| 31 | #include <linux/err.h> |
Paul Gortmaker | 73017a5 | 2011-07-31 16:14:14 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 33 | #include <linux/of_device.h> |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/pm_runtime.h> |
| 36 | #include <linux/platform_data/mailbox-omap.h> |
| 37 | #include <linux/omap-mailbox.h> |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 38 | #include <linux/mailbox_controller.h> |
| 39 | #include <linux/mailbox_client.h> |
Hiroshi DOYU | 8dff0fa | 2009-03-23 18:07:32 -0700 | [diff] [blame] | 40 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 41 | #define MAILBOX_REVISION 0x000 |
| 42 | #define MAILBOX_MESSAGE(m) (0x040 + 4 * (m)) |
| 43 | #define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m)) |
| 44 | #define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m)) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 45 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 46 | #define OMAP2_MAILBOX_IRQSTATUS(u) (0x100 + 8 * (u)) |
| 47 | #define OMAP2_MAILBOX_IRQENABLE(u) (0x104 + 8 * (u)) |
| 48 | |
| 49 | #define OMAP4_MAILBOX_IRQSTATUS(u) (0x104 + 0x10 * (u)) |
| 50 | #define OMAP4_MAILBOX_IRQENABLE(u) (0x108 + 0x10 * (u)) |
| 51 | #define OMAP4_MAILBOX_IRQENABLE_CLR(u) (0x10c + 0x10 * (u)) |
| 52 | |
| 53 | #define MAILBOX_IRQSTATUS(type, u) (type ? OMAP4_MAILBOX_IRQSTATUS(u) : \ |
| 54 | OMAP2_MAILBOX_IRQSTATUS(u)) |
| 55 | #define MAILBOX_IRQENABLE(type, u) (type ? OMAP4_MAILBOX_IRQENABLE(u) : \ |
| 56 | OMAP2_MAILBOX_IRQENABLE(u)) |
| 57 | #define MAILBOX_IRQDISABLE(type, u) (type ? OMAP4_MAILBOX_IRQENABLE_CLR(u) \ |
| 58 | : OMAP2_MAILBOX_IRQENABLE(u)) |
| 59 | |
| 60 | #define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m))) |
| 61 | #define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1)) |
| 62 | |
| 63 | #define MBOX_REG_SIZE 0x120 |
| 64 | |
| 65 | #define OMAP4_MBOX_REG_SIZE 0x130 |
| 66 | |
| 67 | #define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32)) |
| 68 | #define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32)) |
| 69 | |
| 70 | struct omap_mbox_fifo { |
| 71 | unsigned long msg; |
| 72 | unsigned long fifo_stat; |
| 73 | unsigned long msg_stat; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 74 | unsigned long irqenable; |
| 75 | unsigned long irqstatus; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 76 | unsigned long irqdisable; |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 77 | u32 intr_bit; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct omap_mbox_queue { |
| 81 | spinlock_t lock; |
| 82 | struct kfifo fifo; |
| 83 | struct work_struct work; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 84 | struct omap_mbox *mbox; |
| 85 | bool full; |
| 86 | }; |
| 87 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 88 | struct omap_mbox_device { |
| 89 | struct device *dev; |
| 90 | struct mutex cfg_lock; |
| 91 | void __iomem *mbox_base; |
| 92 | u32 num_users; |
| 93 | u32 num_fifos; |
| 94 | struct omap_mbox **mboxes; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 95 | struct mbox_controller controller; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 96 | struct list_head elem; |
| 97 | }; |
| 98 | |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 99 | struct omap_mbox_fifo_info { |
| 100 | int tx_id; |
| 101 | int tx_usr; |
| 102 | int tx_irq; |
| 103 | |
| 104 | int rx_id; |
| 105 | int rx_usr; |
| 106 | int rx_irq; |
| 107 | |
| 108 | const char *name; |
| 109 | }; |
| 110 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 111 | struct omap_mbox { |
| 112 | const char *name; |
| 113 | int irq; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 114 | struct omap_mbox_queue *rxq; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 115 | struct device *dev; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 116 | struct omap_mbox_device *parent; |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 117 | struct omap_mbox_fifo tx_fifo; |
| 118 | struct omap_mbox_fifo rx_fifo; |
| 119 | u32 ctx[OMAP4_MBOX_NR_REGS]; |
| 120 | u32 intr_type; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 121 | struct mbox_chan *chan; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 124 | /* global variables for the mailbox devices */ |
| 125 | static DEFINE_MUTEX(omap_mbox_devices_lock); |
| 126 | static LIST_HEAD(omap_mbox_devices); |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 127 | |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 128 | static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE; |
| 129 | module_param(mbox_kfifo_size, uint, S_IRUGO); |
| 130 | MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)"); |
| 131 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 132 | static struct omap_mbox *mbox_chan_to_omap_mbox(struct mbox_chan *chan) |
| 133 | { |
| 134 | if (!chan || !chan->con_priv) |
| 135 | return NULL; |
| 136 | |
| 137 | return (struct omap_mbox *)chan->con_priv; |
| 138 | } |
| 139 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 140 | static inline |
| 141 | unsigned int mbox_read_reg(struct omap_mbox_device *mdev, size_t ofs) |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 142 | { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 143 | return __raw_readl(mdev->mbox_base + ofs); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 146 | static inline |
| 147 | void mbox_write_reg(struct omap_mbox_device *mdev, u32 val, size_t ofs) |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 148 | { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 149 | __raw_writel(val, mdev->mbox_base + ofs); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 152 | /* Mailbox FIFO handle functions */ |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 153 | static mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox) |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 154 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 155 | struct omap_mbox_fifo *fifo = &mbox->rx_fifo; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 156 | return (mbox_msg_t) mbox_read_reg(mbox->parent, fifo->msg); |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 157 | } |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 158 | |
| 159 | static void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg) |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 160 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 161 | struct omap_mbox_fifo *fifo = &mbox->tx_fifo; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 162 | mbox_write_reg(mbox->parent, msg, fifo->msg); |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 163 | } |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 164 | |
| 165 | static int mbox_fifo_empty(struct omap_mbox *mbox) |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 166 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 167 | struct omap_mbox_fifo *fifo = &mbox->rx_fifo; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 168 | return (mbox_read_reg(mbox->parent, fifo->msg_stat) == 0); |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 169 | } |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 170 | |
| 171 | static int mbox_fifo_full(struct omap_mbox *mbox) |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 172 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 173 | struct omap_mbox_fifo *fifo = &mbox->tx_fifo; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 174 | return mbox_read_reg(mbox->parent, fifo->fifo_stat); |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /* Mailbox IRQ handle functions */ |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 178 | static void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 179 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 180 | struct omap_mbox_fifo *fifo = (irq == IRQ_TX) ? |
| 181 | &mbox->tx_fifo : &mbox->rx_fifo; |
| 182 | u32 bit = fifo->intr_bit; |
| 183 | u32 irqstatus = fifo->irqstatus; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 184 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 185 | mbox_write_reg(mbox->parent, bit, irqstatus); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 186 | |
| 187 | /* Flush posted write for irq status to avoid spurious interrupts */ |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 188 | mbox_read_reg(mbox->parent, irqstatus); |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 189 | } |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 190 | |
| 191 | static int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 192 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 193 | struct omap_mbox_fifo *fifo = (irq == IRQ_TX) ? |
| 194 | &mbox->tx_fifo : &mbox->rx_fifo; |
| 195 | u32 bit = fifo->intr_bit; |
| 196 | u32 irqenable = fifo->irqenable; |
| 197 | u32 irqstatus = fifo->irqstatus; |
| 198 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 199 | u32 enable = mbox_read_reg(mbox->parent, irqenable); |
| 200 | u32 status = mbox_read_reg(mbox->parent, irqstatus); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 201 | |
| 202 | return (int)(enable & status & bit); |
Hiroshi DOYU | 9ae0ee0 | 2009-03-23 18:07:26 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 205 | void omap_mbox_save_ctx(struct mbox_chan *chan) |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 206 | { |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 207 | int i; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 208 | int nr_regs; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 209 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 210 | |
| 211 | if (WARN_ON(!mbox)) |
| 212 | return; |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 213 | |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 214 | if (mbox->intr_type) |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 215 | nr_regs = OMAP4_MBOX_NR_REGS; |
| 216 | else |
| 217 | nr_regs = MBOX_NR_REGS; |
| 218 | for (i = 0; i < nr_regs; i++) { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 219 | mbox->ctx[i] = mbox_read_reg(mbox->parent, i * sizeof(u32)); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 220 | |
| 221 | dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 222 | i, mbox->ctx[i]); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 223 | } |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 224 | } |
| 225 | EXPORT_SYMBOL(omap_mbox_save_ctx); |
| 226 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 227 | void omap_mbox_restore_ctx(struct mbox_chan *chan) |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 228 | { |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 229 | int i; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 230 | int nr_regs; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 231 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 232 | |
| 233 | if (WARN_ON(!mbox)) |
| 234 | return; |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 235 | |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 236 | if (mbox->intr_type) |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 237 | nr_regs = OMAP4_MBOX_NR_REGS; |
| 238 | else |
| 239 | nr_regs = MBOX_NR_REGS; |
| 240 | for (i = 0; i < nr_regs; i++) { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 241 | mbox_write_reg(mbox->parent, mbox->ctx[i], i * sizeof(u32)); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 242 | dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 243 | i, mbox->ctx[i]); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 244 | } |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 245 | } |
| 246 | EXPORT_SYMBOL(omap_mbox_restore_ctx); |
| 247 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 248 | static void _omap_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 249 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 250 | u32 l; |
| 251 | struct omap_mbox_fifo *fifo = (irq == IRQ_TX) ? |
| 252 | &mbox->tx_fifo : &mbox->rx_fifo; |
| 253 | u32 bit = fifo->intr_bit; |
| 254 | u32 irqenable = fifo->irqenable; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 255 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 256 | l = mbox_read_reg(mbox->parent, irqenable); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 257 | l |= bit; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 258 | mbox_write_reg(mbox->parent, l, irqenable); |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 259 | } |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 260 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 261 | static void _omap_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 262 | { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 263 | struct omap_mbox_fifo *fifo = (irq == IRQ_TX) ? |
| 264 | &mbox->tx_fifo : &mbox->rx_fifo; |
| 265 | u32 bit = fifo->intr_bit; |
| 266 | u32 irqdisable = fifo->irqdisable; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * Read and update the interrupt configuration register for pre-OMAP4. |
| 270 | * OMAP4 and later SoCs have a dedicated interrupt disabling register. |
| 271 | */ |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 272 | if (!mbox->intr_type) |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 273 | bit = mbox_read_reg(mbox->parent, irqdisable) & ~bit; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 274 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 275 | mbox_write_reg(mbox->parent, bit, irqdisable); |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 276 | } |
Suman Anna | c869c75 | 2013-03-12 17:55:29 -0500 | [diff] [blame] | 277 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 278 | void omap_mbox_enable_irq(struct mbox_chan *chan, omap_mbox_irq_t irq) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 279 | { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 280 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 281 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 282 | if (WARN_ON(!mbox)) |
| 283 | return; |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 284 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 285 | _omap_mbox_enable_irq(mbox, irq); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 286 | } |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 287 | EXPORT_SYMBOL(omap_mbox_enable_irq); |
| 288 | |
| 289 | void omap_mbox_disable_irq(struct mbox_chan *chan, omap_mbox_irq_t irq) |
| 290 | { |
| 291 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 292 | |
| 293 | if (WARN_ON(!mbox)) |
| 294 | return; |
| 295 | |
| 296 | _omap_mbox_disable_irq(mbox, irq); |
| 297 | } |
| 298 | EXPORT_SYMBOL(omap_mbox_disable_irq); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 299 | |
| 300 | /* |
| 301 | * Message receiver(workqueue) |
| 302 | */ |
| 303 | static void mbox_rx_work(struct work_struct *work) |
| 304 | { |
| 305 | struct omap_mbox_queue *mq = |
| 306 | container_of(work, struct omap_mbox_queue, work); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 307 | mbox_msg_t msg; |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 308 | int len; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 309 | |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 310 | while (kfifo_len(&mq->fifo) >= sizeof(msg)) { |
| 311 | len = kfifo_out(&mq->fifo, (unsigned char *)&msg, sizeof(msg)); |
| 312 | WARN_ON(len != sizeof(msg)); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 313 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 314 | mbox_chan_received_data(mq->mbox->chan, (void *)msg); |
Fernando Guzman Lugo | d229504 | 2010-11-29 20:24:11 +0000 | [diff] [blame] | 315 | spin_lock_irq(&mq->lock); |
| 316 | if (mq->full) { |
| 317 | mq->full = false; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 318 | _omap_mbox_enable_irq(mq->mbox, IRQ_RX); |
Fernando Guzman Lugo | d229504 | 2010-11-29 20:24:11 +0000 | [diff] [blame] | 319 | } |
| 320 | spin_unlock_irq(&mq->lock); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Mailbox interrupt handler |
| 326 | */ |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 327 | static void __mbox_tx_interrupt(struct omap_mbox *mbox) |
| 328 | { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 329 | _omap_mbox_disable_irq(mbox, IRQ_TX); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 330 | ack_mbox_irq(mbox, IRQ_TX); |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 331 | mbox_chan_txdone(mbox->chan, 0); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static void __mbox_rx_interrupt(struct omap_mbox *mbox) |
| 335 | { |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 336 | struct omap_mbox_queue *mq = mbox->rxq; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 337 | mbox_msg_t msg; |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 338 | int len; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 339 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 340 | while (!mbox_fifo_empty(mbox)) { |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 341 | if (unlikely(kfifo_avail(&mq->fifo) < sizeof(msg))) { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 342 | _omap_mbox_disable_irq(mbox, IRQ_RX); |
Fernando Guzman Lugo | d229504 | 2010-11-29 20:24:11 +0000 | [diff] [blame] | 343 | mq->full = true; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 344 | goto nomem; |
Fernando Guzman Lugo | 1ea5d6d | 2010-02-08 13:35:40 -0600 | [diff] [blame] | 345 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 346 | |
| 347 | msg = mbox_fifo_read(mbox); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 348 | |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 349 | len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg)); |
| 350 | WARN_ON(len != sizeof(msg)); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* no more messages in the fifo. clear IRQ source. */ |
| 354 | ack_mbox_irq(mbox, IRQ_RX); |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 355 | nomem: |
Tejun Heo | c487300 | 2011-01-26 12:12:50 +0100 | [diff] [blame] | 356 | schedule_work(&mbox->rxq->work); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static irqreturn_t mbox_interrupt(int irq, void *p) |
| 360 | { |
Jeff Garzik | 2a7057e | 2007-10-26 05:40:22 -0400 | [diff] [blame] | 361 | struct omap_mbox *mbox = p; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 362 | |
| 363 | if (is_mbox_irq(mbox, IRQ_TX)) |
| 364 | __mbox_tx_interrupt(mbox); |
| 365 | |
| 366 | if (is_mbox_irq(mbox, IRQ_RX)) |
| 367 | __mbox_rx_interrupt(mbox); |
| 368 | |
| 369 | return IRQ_HANDLED; |
| 370 | } |
| 371 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 372 | static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox, |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 373 | void (*work)(struct work_struct *)) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 374 | { |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 375 | struct omap_mbox_queue *mq; |
| 376 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 377 | if (!work) |
| 378 | return NULL; |
| 379 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 380 | mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL); |
| 381 | if (!mq) |
| 382 | return NULL; |
| 383 | |
| 384 | spin_lock_init(&mq->lock); |
| 385 | |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 386 | if (kfifo_alloc(&mq->fifo, mbox_kfifo_size, GFP_KERNEL)) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 387 | goto error; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 388 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 389 | INIT_WORK(&mq->work, work); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 390 | return mq; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 391 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 392 | error: |
| 393 | kfree(mq); |
| 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | static void mbox_queue_free(struct omap_mbox_queue *q) |
| 398 | { |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 399 | kfifo_free(&q->fifo); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 400 | kfree(q); |
| 401 | } |
| 402 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 403 | static int omap_mbox_startup(struct omap_mbox *mbox) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 404 | { |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 405 | int ret = 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 406 | struct omap_mbox_queue *mq; |
| 407 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 408 | mq = mbox_queue_alloc(mbox, mbox_rx_work); |
| 409 | if (!mq) |
| 410 | return -ENOMEM; |
| 411 | mbox->rxq = mq; |
| 412 | mq->mbox = mbox; |
C A Subramaniam | 5f00ec6 | 2009-11-22 10:11:22 -0800 | [diff] [blame] | 413 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 414 | ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, |
| 415 | mbox->name, mbox); |
| 416 | if (unlikely(ret)) { |
| 417 | pr_err("failed to register mailbox interrupt:%d\n", ret); |
| 418 | goto fail_request_irq; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 419 | } |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 420 | |
| 421 | _omap_mbox_enable_irq(mbox, IRQ_RX); |
| 422 | |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 423 | return 0; |
| 424 | |
Suman Anna | ecf305c | 2013-02-01 20:37:06 -0600 | [diff] [blame] | 425 | fail_request_irq: |
| 426 | mbox_queue_free(mbox->rxq); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | static void omap_mbox_fini(struct omap_mbox *mbox) |
| 431 | { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 432 | _omap_mbox_disable_irq(mbox, IRQ_RX); |
| 433 | free_irq(mbox->irq, mbox); |
| 434 | flush_work(&mbox->rxq->work); |
| 435 | mbox_queue_free(mbox->rxq); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 438 | static struct omap_mbox *omap_mbox_device_find(struct omap_mbox_device *mdev, |
| 439 | const char *mbox_name) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 440 | { |
Kevin Hilman | c037732 | 2011-02-11 19:56:43 +0000 | [diff] [blame] | 441 | struct omap_mbox *_mbox, *mbox = NULL; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 442 | struct omap_mbox **mboxes = mdev->mboxes; |
| 443 | int i; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 444 | |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 445 | if (!mboxes) |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 446 | return NULL; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 447 | |
Kevin Hilman | c037732 | 2011-02-11 19:56:43 +0000 | [diff] [blame] | 448 | for (i = 0; (_mbox = mboxes[i]); i++) { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 449 | if (!strcmp(_mbox->name, mbox_name)) { |
Kevin Hilman | c037732 | 2011-02-11 19:56:43 +0000 | [diff] [blame] | 450 | mbox = _mbox; |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 451 | break; |
Kevin Hilman | c037732 | 2011-02-11 19:56:43 +0000 | [diff] [blame] | 452 | } |
| 453 | } |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 454 | return mbox; |
| 455 | } |
| 456 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 457 | struct mbox_chan *omap_mbox_request_channel(struct mbox_client *cl, |
| 458 | const char *chan_name) |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 459 | { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 460 | struct device *dev = cl->dev; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 461 | struct omap_mbox *mbox = NULL; |
| 462 | struct omap_mbox_device *mdev; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 463 | struct mbox_chan *chan; |
| 464 | unsigned long flags; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 465 | int ret; |
| 466 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 467 | if (!dev) |
| 468 | return ERR_PTR(-ENODEV); |
| 469 | |
| 470 | if (dev->of_node) { |
| 471 | pr_err("%s: please use mbox_request_channel(), this API is supported only for OMAP non-DT usage\n", |
| 472 | __func__); |
| 473 | return ERR_PTR(-ENODEV); |
| 474 | } |
| 475 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 476 | mutex_lock(&omap_mbox_devices_lock); |
| 477 | list_for_each_entry(mdev, &omap_mbox_devices, elem) { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 478 | mbox = omap_mbox_device_find(mdev, chan_name); |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 479 | if (mbox) |
| 480 | break; |
| 481 | } |
| 482 | mutex_unlock(&omap_mbox_devices_lock); |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 483 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 484 | if (!mbox || !mbox->chan) |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 485 | return ERR_PTR(-ENOENT); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 486 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 487 | chan = mbox->chan; |
| 488 | spin_lock_irqsave(&chan->lock, flags); |
| 489 | chan->msg_free = 0; |
| 490 | chan->msg_count = 0; |
| 491 | chan->active_req = NULL; |
| 492 | chan->cl = cl; |
| 493 | init_completion(&chan->tx_complete); |
| 494 | spin_unlock_irqrestore(&chan->lock, flags); |
Kanigeri, Hari | 5825630 | 2010-11-29 20:24:14 +0000 | [diff] [blame] | 495 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 496 | ret = chan->mbox->ops->startup(chan); |
Juan Gutierrez | 1d8a0e9 | 2012-05-13 15:33:04 +0300 | [diff] [blame] | 497 | if (ret) { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 498 | pr_err("Unable to startup the chan (%d)\n", ret); |
| 499 | mbox_free_channel(chan); |
| 500 | chan = ERR_PTR(ret); |
Juan Gutierrez | 1d8a0e9 | 2012-05-13 15:33:04 +0300 | [diff] [blame] | 501 | } |
| 502 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 503 | return chan; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 504 | } |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 505 | EXPORT_SYMBOL(omap_mbox_request_channel); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 506 | |
Hiroshi DOYU | 6b23398 | 2010-05-18 16:15:32 +0300 | [diff] [blame] | 507 | static struct class omap_mbox_class = { .name = "mbox", }; |
| 508 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 509 | static int omap_mbox_register(struct omap_mbox_device *mdev) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 510 | { |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 511 | int ret; |
| 512 | int i; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 513 | struct omap_mbox **mboxes; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 514 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 515 | if (!mdev || !mdev->mboxes) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 516 | return -EINVAL; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 517 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 518 | mboxes = mdev->mboxes; |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 519 | for (i = 0; mboxes[i]; i++) { |
| 520 | struct omap_mbox *mbox = mboxes[i]; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 521 | mbox->dev = device_create(&omap_mbox_class, mdev->dev, |
| 522 | 0, mbox, "%s", mbox->name); |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 523 | if (IS_ERR(mbox->dev)) { |
| 524 | ret = PTR_ERR(mbox->dev); |
| 525 | goto err_out; |
| 526 | } |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 527 | } |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 528 | |
| 529 | mutex_lock(&omap_mbox_devices_lock); |
| 530 | list_add(&mdev->elem, &omap_mbox_devices); |
| 531 | mutex_unlock(&omap_mbox_devices_lock); |
| 532 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 533 | ret = mbox_controller_register(&mdev->controller); |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 534 | |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 535 | err_out: |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 536 | if (ret) { |
| 537 | while (i--) |
| 538 | device_unregister(mboxes[i]->dev); |
| 539 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 540 | return ret; |
| 541 | } |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 542 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 543 | static int omap_mbox_unregister(struct omap_mbox_device *mdev) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 544 | { |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 545 | int i; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 546 | struct omap_mbox **mboxes; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 547 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 548 | if (!mdev || !mdev->mboxes) |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 549 | return -EINVAL; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 550 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 551 | mutex_lock(&omap_mbox_devices_lock); |
| 552 | list_del(&mdev->elem); |
| 553 | mutex_unlock(&omap_mbox_devices_lock); |
| 554 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 555 | mbox_controller_unregister(&mdev->controller); |
| 556 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 557 | mboxes = mdev->mboxes; |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 558 | for (i = 0; mboxes[i]; i++) |
| 559 | device_unregister(mboxes[i]->dev); |
Felipe Contreras | 9c80c8c | 2010-06-11 15:51:46 +0000 | [diff] [blame] | 560 | return 0; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 561 | } |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 562 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 563 | static int omap_mbox_chan_startup(struct mbox_chan *chan) |
| 564 | { |
| 565 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 566 | struct omap_mbox_device *mdev = mbox->parent; |
| 567 | int ret = 0; |
| 568 | |
| 569 | mutex_lock(&mdev->cfg_lock); |
| 570 | pm_runtime_get_sync(mdev->dev); |
| 571 | ret = omap_mbox_startup(mbox); |
| 572 | if (ret) |
| 573 | pm_runtime_put_sync(mdev->dev); |
| 574 | mutex_unlock(&mdev->cfg_lock); |
| 575 | return ret; |
| 576 | } |
| 577 | |
| 578 | static void omap_mbox_chan_shutdown(struct mbox_chan *chan) |
| 579 | { |
| 580 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 581 | struct omap_mbox_device *mdev = mbox->parent; |
| 582 | |
| 583 | mutex_lock(&mdev->cfg_lock); |
| 584 | omap_mbox_fini(mbox); |
| 585 | pm_runtime_put_sync(mdev->dev); |
| 586 | mutex_unlock(&mdev->cfg_lock); |
| 587 | } |
| 588 | |
| 589 | static int omap_mbox_chan_send_data(struct mbox_chan *chan, void *data) |
| 590 | { |
| 591 | struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 592 | int ret = -EBUSY; |
| 593 | |
| 594 | if (!mbox) |
| 595 | return -EINVAL; |
| 596 | |
| 597 | if (!mbox_fifo_full(mbox)) { |
| 598 | mbox_fifo_write(mbox, (mbox_msg_t)data); |
| 599 | ret = 0; |
| 600 | } |
| 601 | |
| 602 | /* always enable the interrupt */ |
| 603 | _omap_mbox_enable_irq(mbox, IRQ_TX); |
| 604 | return ret; |
| 605 | } |
| 606 | |
Andrew Bresticker | 05ae797 | 2015-05-04 10:36:35 -0700 | [diff] [blame] | 607 | static const struct mbox_chan_ops omap_mbox_chan_ops = { |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 608 | .startup = omap_mbox_chan_startup, |
| 609 | .send_data = omap_mbox_chan_send_data, |
| 610 | .shutdown = omap_mbox_chan_shutdown, |
| 611 | }; |
| 612 | |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 613 | static const struct of_device_id omap_mailbox_of_match[] = { |
| 614 | { |
| 615 | .compatible = "ti,omap2-mailbox", |
| 616 | .data = (void *)MBOX_INTR_CFG_TYPE1, |
| 617 | }, |
| 618 | { |
| 619 | .compatible = "ti,omap3-mailbox", |
| 620 | .data = (void *)MBOX_INTR_CFG_TYPE1, |
| 621 | }, |
| 622 | { |
| 623 | .compatible = "ti,omap4-mailbox", |
| 624 | .data = (void *)MBOX_INTR_CFG_TYPE2, |
| 625 | }, |
| 626 | { |
| 627 | /* end */ |
| 628 | }, |
| 629 | }; |
| 630 | MODULE_DEVICE_TABLE(of, omap_mailbox_of_match); |
| 631 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 632 | static struct mbox_chan *omap_mbox_of_xlate(struct mbox_controller *controller, |
| 633 | const struct of_phandle_args *sp) |
| 634 | { |
| 635 | phandle phandle = sp->args[0]; |
| 636 | struct device_node *node; |
| 637 | struct omap_mbox_device *mdev; |
| 638 | struct omap_mbox *mbox; |
| 639 | |
| 640 | mdev = container_of(controller, struct omap_mbox_device, controller); |
| 641 | if (WARN_ON(!mdev)) |
Benson Leung | 2d805fc | 2015-05-04 10:36:36 -0700 | [diff] [blame] | 642 | return ERR_PTR(-EINVAL); |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 643 | |
| 644 | node = of_find_node_by_phandle(phandle); |
| 645 | if (!node) { |
| 646 | pr_err("%s: could not find node phandle 0x%x\n", |
| 647 | __func__, phandle); |
Benson Leung | 2d805fc | 2015-05-04 10:36:36 -0700 | [diff] [blame] | 648 | return ERR_PTR(-ENODEV); |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | mbox = omap_mbox_device_find(mdev, node->name); |
| 652 | of_node_put(node); |
Benson Leung | 2d805fc | 2015-05-04 10:36:36 -0700 | [diff] [blame] | 653 | return mbox ? mbox->chan : ERR_PTR(-ENOENT); |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 654 | } |
| 655 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 656 | static int omap_mbox_probe(struct platform_device *pdev) |
| 657 | { |
| 658 | struct resource *mem; |
| 659 | int ret; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 660 | struct mbox_chan *chnls; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 661 | struct omap_mbox **list, *mbox, *mboxblk; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 662 | struct omap_mbox_pdata *pdata = pdev->dev.platform_data; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 663 | struct omap_mbox_dev_info *info = NULL; |
| 664 | struct omap_mbox_fifo_info *finfo, *finfoblk; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 665 | struct omap_mbox_device *mdev; |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 666 | struct omap_mbox_fifo *fifo; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 667 | struct device_node *node = pdev->dev.of_node; |
| 668 | struct device_node *child; |
| 669 | const struct of_device_id *match; |
| 670 | u32 intr_type, info_count; |
| 671 | u32 num_users, num_fifos; |
| 672 | u32 tmp[3]; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 673 | u32 l; |
| 674 | int i; |
| 675 | |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 676 | if (!node && (!pdata || !pdata->info_cnt || !pdata->info)) { |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 677 | pr_err("%s: platform not supported\n", __func__); |
| 678 | return -ENODEV; |
| 679 | } |
| 680 | |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 681 | if (node) { |
| 682 | match = of_match_device(omap_mailbox_of_match, &pdev->dev); |
| 683 | if (!match) |
| 684 | return -ENODEV; |
| 685 | intr_type = (u32)match->data; |
| 686 | |
| 687 | if (of_property_read_u32(node, "ti,mbox-num-users", |
| 688 | &num_users)) |
| 689 | return -ENODEV; |
| 690 | |
| 691 | if (of_property_read_u32(node, "ti,mbox-num-fifos", |
| 692 | &num_fifos)) |
| 693 | return -ENODEV; |
| 694 | |
| 695 | info_count = of_get_available_child_count(node); |
| 696 | if (!info_count) { |
| 697 | dev_err(&pdev->dev, "no available mbox devices found\n"); |
| 698 | return -ENODEV; |
| 699 | } |
| 700 | } else { /* non-DT device creation */ |
| 701 | info_count = pdata->info_cnt; |
| 702 | info = pdata->info; |
| 703 | intr_type = pdata->intr_type; |
| 704 | num_users = pdata->num_users; |
| 705 | num_fifos = pdata->num_fifos; |
| 706 | } |
| 707 | |
| 708 | finfoblk = devm_kzalloc(&pdev->dev, info_count * sizeof(*finfoblk), |
| 709 | GFP_KERNEL); |
| 710 | if (!finfoblk) |
| 711 | return -ENOMEM; |
| 712 | |
| 713 | finfo = finfoblk; |
| 714 | child = NULL; |
| 715 | for (i = 0; i < info_count; i++, finfo++) { |
| 716 | if (node) { |
| 717 | child = of_get_next_available_child(node, child); |
| 718 | ret = of_property_read_u32_array(child, "ti,mbox-tx", |
| 719 | tmp, ARRAY_SIZE(tmp)); |
| 720 | if (ret) |
| 721 | return ret; |
| 722 | finfo->tx_id = tmp[0]; |
| 723 | finfo->tx_irq = tmp[1]; |
| 724 | finfo->tx_usr = tmp[2]; |
| 725 | |
| 726 | ret = of_property_read_u32_array(child, "ti,mbox-rx", |
| 727 | tmp, ARRAY_SIZE(tmp)); |
| 728 | if (ret) |
| 729 | return ret; |
| 730 | finfo->rx_id = tmp[0]; |
| 731 | finfo->rx_irq = tmp[1]; |
| 732 | finfo->rx_usr = tmp[2]; |
| 733 | |
| 734 | finfo->name = child->name; |
| 735 | } else { |
| 736 | finfo->tx_id = info->tx_id; |
| 737 | finfo->rx_id = info->rx_id; |
| 738 | finfo->tx_usr = info->usr_id; |
| 739 | finfo->tx_irq = info->irq_id; |
| 740 | finfo->rx_usr = info->usr_id; |
| 741 | finfo->rx_irq = info->irq_id; |
| 742 | finfo->name = info->name; |
| 743 | info++; |
| 744 | } |
| 745 | if (finfo->tx_id >= num_fifos || finfo->rx_id >= num_fifos || |
| 746 | finfo->tx_usr >= num_users || finfo->rx_usr >= num_users) |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 750 | mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL); |
| 751 | if (!mdev) |
| 752 | return -ENOMEM; |
| 753 | |
| 754 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 755 | mdev->mbox_base = devm_ioremap_resource(&pdev->dev, mem); |
| 756 | if (IS_ERR(mdev->mbox_base)) |
| 757 | return PTR_ERR(mdev->mbox_base); |
| 758 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 759 | /* allocate one extra for marking end of list */ |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 760 | list = devm_kzalloc(&pdev->dev, (info_count + 1) * sizeof(*list), |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 761 | GFP_KERNEL); |
| 762 | if (!list) |
| 763 | return -ENOMEM; |
| 764 | |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 765 | chnls = devm_kzalloc(&pdev->dev, (info_count + 1) * sizeof(*chnls), |
| 766 | GFP_KERNEL); |
| 767 | if (!chnls) |
| 768 | return -ENOMEM; |
| 769 | |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 770 | mboxblk = devm_kzalloc(&pdev->dev, info_count * sizeof(*mbox), |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 771 | GFP_KERNEL); |
| 772 | if (!mboxblk) |
| 773 | return -ENOMEM; |
| 774 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 775 | mbox = mboxblk; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 776 | finfo = finfoblk; |
| 777 | for (i = 0; i < info_count; i++, finfo++) { |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 778 | fifo = &mbox->tx_fifo; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 779 | fifo->msg = MAILBOX_MESSAGE(finfo->tx_id); |
| 780 | fifo->fifo_stat = MAILBOX_FIFOSTATUS(finfo->tx_id); |
| 781 | fifo->intr_bit = MAILBOX_IRQ_NOTFULL(finfo->tx_id); |
| 782 | fifo->irqenable = MAILBOX_IRQENABLE(intr_type, finfo->tx_usr); |
| 783 | fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, finfo->tx_usr); |
| 784 | fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, finfo->tx_usr); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 785 | |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 786 | fifo = &mbox->rx_fifo; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 787 | fifo->msg = MAILBOX_MESSAGE(finfo->rx_id); |
| 788 | fifo->msg_stat = MAILBOX_MSGSTATUS(finfo->rx_id); |
| 789 | fifo->intr_bit = MAILBOX_IRQ_NEWMSG(finfo->rx_id); |
| 790 | fifo->irqenable = MAILBOX_IRQENABLE(intr_type, finfo->rx_usr); |
| 791 | fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, finfo->rx_usr); |
| 792 | fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, finfo->rx_usr); |
Suman Anna | be3322e | 2014-06-24 19:43:42 -0500 | [diff] [blame] | 793 | |
| 794 | mbox->intr_type = intr_type; |
| 795 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 796 | mbox->parent = mdev; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 797 | mbox->name = finfo->name; |
| 798 | mbox->irq = platform_get_irq(pdev, finfo->tx_irq); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 799 | if (mbox->irq < 0) |
| 800 | return mbox->irq; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 801 | mbox->chan = &chnls[i]; |
| 802 | chnls[i].con_priv = mbox; |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 803 | list[i] = mbox++; |
| 804 | } |
| 805 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 806 | mutex_init(&mdev->cfg_lock); |
| 807 | mdev->dev = &pdev->dev; |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 808 | mdev->num_users = num_users; |
| 809 | mdev->num_fifos = num_fifos; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 810 | mdev->mboxes = list; |
Suman Anna | 8841a66 | 2014-11-03 17:05:50 -0600 | [diff] [blame] | 811 | |
| 812 | /* OMAP does not have a Tx-Done IRQ, but rather a Tx-Ready IRQ */ |
| 813 | mdev->controller.txdone_irq = true; |
| 814 | mdev->controller.dev = mdev->dev; |
| 815 | mdev->controller.ops = &omap_mbox_chan_ops; |
| 816 | mdev->controller.chans = chnls; |
| 817 | mdev->controller.num_chans = info_count; |
| 818 | mdev->controller.of_xlate = omap_mbox_of_xlate; |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 819 | ret = omap_mbox_register(mdev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 820 | if (ret) |
| 821 | return ret; |
| 822 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 823 | platform_set_drvdata(pdev, mdev); |
| 824 | pm_runtime_enable(mdev->dev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 825 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 826 | ret = pm_runtime_get_sync(mdev->dev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 827 | if (ret < 0) { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 828 | pm_runtime_put_noidle(mdev->dev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 829 | goto unregister; |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | * just print the raw revision register, the format is not |
| 834 | * uniform across all SoCs |
| 835 | */ |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 836 | l = mbox_read_reg(mdev, MAILBOX_REVISION); |
| 837 | dev_info(mdev->dev, "omap mailbox rev 0x%x\n", l); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 838 | |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 839 | ret = pm_runtime_put_sync(mdev->dev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 840 | if (ret < 0) |
| 841 | goto unregister; |
| 842 | |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 843 | devm_kfree(&pdev->dev, finfoblk); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 844 | return 0; |
| 845 | |
| 846 | unregister: |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 847 | pm_runtime_disable(mdev->dev); |
| 848 | omap_mbox_unregister(mdev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | static int omap_mbox_remove(struct platform_device *pdev) |
| 853 | { |
Suman Anna | 72c1c81 | 2014-06-24 19:43:43 -0500 | [diff] [blame] | 854 | struct omap_mbox_device *mdev = platform_get_drvdata(pdev); |
| 855 | |
| 856 | pm_runtime_disable(mdev->dev); |
| 857 | omap_mbox_unregister(mdev); |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | static struct platform_driver omap_mbox_driver = { |
| 863 | .probe = omap_mbox_probe, |
| 864 | .remove = omap_mbox_remove, |
| 865 | .driver = { |
| 866 | .name = "omap-mailbox", |
Suman Anna | 75288cc | 2014-09-10 14:20:59 -0500 | [diff] [blame] | 867 | .of_match_table = of_match_ptr(omap_mailbox_of_match), |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 868 | }, |
| 869 | }; |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 870 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 871 | static int __init omap_mbox_init(void) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 872 | { |
Hiroshi DOYU | 6b23398 | 2010-05-18 16:15:32 +0300 | [diff] [blame] | 873 | int err; |
| 874 | |
| 875 | err = class_register(&omap_mbox_class); |
| 876 | if (err) |
| 877 | return err; |
| 878 | |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 879 | /* kfifo size sanity check: alignment and minimal size */ |
| 880 | mbox_kfifo_size = ALIGN(mbox_kfifo_size, sizeof(mbox_msg_t)); |
Kanigeri, Hari | ab66ac3 | 2010-11-29 20:24:12 +0000 | [diff] [blame] | 881 | mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size, |
| 882 | sizeof(mbox_msg_t)); |
Ohad Ben-Cohen | b5bebe4 | 2010-05-05 15:33:09 +0000 | [diff] [blame] | 883 | |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 884 | return platform_driver_register(&omap_mbox_driver); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 885 | } |
Hiroshi DOYU | 6b23398 | 2010-05-18 16:15:32 +0300 | [diff] [blame] | 886 | subsys_initcall(omap_mbox_init); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 887 | |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 888 | static void __exit omap_mbox_exit(void) |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 889 | { |
Suman Anna | 5040f53 | 2014-06-24 19:43:41 -0500 | [diff] [blame] | 890 | platform_driver_unregister(&omap_mbox_driver); |
Hiroshi DOYU | 6b23398 | 2010-05-18 16:15:32 +0300 | [diff] [blame] | 891 | class_unregister(&omap_mbox_class); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 892 | } |
Hiroshi DOYU | c7c158e | 2009-11-22 10:11:19 -0800 | [diff] [blame] | 893 | module_exit(omap_mbox_exit); |
Hiroshi DOYU | 340a614 | 2006-12-07 15:43:59 -0800 | [diff] [blame] | 894 | |
Hiroshi DOYU | f48cca8 | 2009-03-23 18:07:24 -0700 | [diff] [blame] | 895 | MODULE_LICENSE("GPL v2"); |
| 896 | MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging"); |
Ohad Ben-Cohen | f375325 | 2010-05-05 15:33:07 +0000 | [diff] [blame] | 897 | MODULE_AUTHOR("Toshihiro Kobayashi"); |
| 898 | MODULE_AUTHOR("Hiroshi DOYU"); |