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