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