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