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