blob: 9001b7633f107f4c0f29c61d56e999a5aebec81c [file] [log] [blame]
Hiroshi DOYU340a6142006-12-07 15:43:59 -08001/*
Felipe Contrerasd7427092010-06-11 15:51:48 +00002 * Mailbox reservation modules for OMAP1
Hiroshi DOYU340a6142006-12-07 15:43:59 -08003 *
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -07004 * Copyright (C) 2006-2009 Nokia Corporation
Hiroshi DOYU340a6142006-12-07 15:43:59 -08005 * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
Paul Gortmaker73017a52011-07-31 16:14:14 -040012#include <linux/module.h>
Hiroshi DOYU340a6142006-12-07 15:43:59 -080013#include <linux/interrupt.h>
14#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010015#include <linux/io.h>
Suman Annac869c752013-03-12 17:55:29 -050016
17#include "omap-mbox.h"
Hiroshi DOYU340a6142006-12-07 15:43:59 -080018
19#define MAILBOX_ARM2DSP1 0x00
20#define MAILBOX_ARM2DSP1b 0x04
21#define MAILBOX_DSP2ARM1 0x08
22#define MAILBOX_DSP2ARM1b 0x0c
23#define MAILBOX_DSP2ARM2 0x10
24#define MAILBOX_DSP2ARM2b 0x14
25#define MAILBOX_ARM2DSP1_Flag 0x18
26#define MAILBOX_DSP2ARM1_Flag 0x1c
27#define MAILBOX_DSP2ARM2_Flag 0x20
28
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070029static void __iomem *mbox_base;
Hiroshi DOYU340a6142006-12-07 15:43:59 -080030
31struct omap_mbox1_fifo {
32 unsigned long cmd;
33 unsigned long data;
34 unsigned long flag;
35};
36
37struct omap_mbox1_priv {
38 struct omap_mbox1_fifo tx_fifo;
39 struct omap_mbox1_fifo rx_fifo;
40};
41
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070042static inline int mbox_read_reg(size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080043{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070044 return __raw_readw(mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080045}
46
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070047static inline void mbox_write_reg(u32 val, size_t ofs)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080048{
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -070049 __raw_writew(val, mbox_base + ofs);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080050}
51
52/* msg */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080053static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080054{
55 struct omap_mbox1_fifo *fifo =
56 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
57 mbox_msg_t msg;
58
59 msg = mbox_read_reg(fifo->data);
60 msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;
61
62 return msg;
63}
64
Tony Lindgrene27a93a2007-12-18 20:58:32 -080065static void
Hiroshi DOYU340a6142006-12-07 15:43:59 -080066omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
67{
68 struct omap_mbox1_fifo *fifo =
69 &((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;
70
71 mbox_write_reg(msg & 0xffff, fifo->data);
72 mbox_write_reg(msg >> 16, fifo->cmd);
73}
74
Tony Lindgrene27a93a2007-12-18 20:58:32 -080075static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080076{
77 return 0;
78}
79
Tony Lindgrene27a93a2007-12-18 20:58:32 -080080static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080081{
82 struct omap_mbox1_fifo *fifo =
83 &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
84
Felipe Contreras909f9dc2010-06-11 15:51:37 +000085 return mbox_read_reg(fifo->flag);
Hiroshi DOYU340a6142006-12-07 15:43:59 -080086}
87
88/* irq */
Tony Lindgrene27a93a2007-12-18 20:58:32 -080089static void
Suman Annaf91ca052013-06-07 16:27:45 -050090omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080091{
92 if (irq == IRQ_RX)
93 enable_irq(mbox->irq);
94}
95
Tony Lindgrene27a93a2007-12-18 20:58:32 -080096static void
Suman Annaf91ca052013-06-07 16:27:45 -050097omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -080098{
99 if (irq == IRQ_RX)
100 disable_irq(mbox->irq);
101}
102
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800103static int
Suman Annaf91ca052013-06-07 16:27:45 -0500104omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800105{
106 if (irq == IRQ_TX)
107 return 0;
108 return 1;
109}
110
111static struct omap_mbox_ops omap1_mbox_ops = {
112 .type = OMAP_MBOX_TYPE1,
113 .fifo_read = omap1_mbox_fifo_read,
114 .fifo_write = omap1_mbox_fifo_write,
115 .fifo_empty = omap1_mbox_fifo_empty,
116 .fifo_full = omap1_mbox_fifo_full,
117 .enable_irq = omap1_mbox_enable_irq,
118 .disable_irq = omap1_mbox_disable_irq,
119 .is_irq = omap1_mbox_is_irq,
120};
121
122/* FIXME: the following struct should be created automatically by the user id */
123
124/* DSP */
125static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
126 .tx_fifo = {
127 .cmd = MAILBOX_ARM2DSP1b,
128 .data = MAILBOX_ARM2DSP1,
129 .flag = MAILBOX_ARM2DSP1_Flag,
130 },
131 .rx_fifo = {
132 .cmd = MAILBOX_DSP2ARM1b,
133 .data = MAILBOX_DSP2ARM1,
134 .flag = MAILBOX_DSP2ARM1_Flag,
135 },
136};
137
Aaro Koskinendba5e192010-11-18 19:59:48 +0200138static struct omap_mbox mbox_dsp_info = {
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800139 .name = "dsp",
140 .ops = &omap1_mbox_ops,
141 .priv = &omap1_mbox_dsp_priv,
142};
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800143
Aaro Koskinendba5e192010-11-18 19:59:48 +0200144static struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
Felipe Contreras898ee752010-06-11 15:51:45 +0000145
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800146static int omap1_mbox_probe(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800147{
Felipe Contreras898ee752010-06-11 15:51:45 +0000148 struct resource *mem;
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000149 int ret;
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000150 struct omap_mbox **list;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800151
Felipe Contreras898ee752010-06-11 15:51:45 +0000152 list = omap1_mboxes;
Felipe Contreras898ee752010-06-11 15:51:45 +0000153 list[0]->irq = platform_get_irq_byname(pdev, "dsp");
154
155 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Suman Annaa41677c2013-02-01 20:24:51 -0600156 if (!mem)
157 return -ENOENT;
158
Felipe Contreras898ee752010-06-11 15:51:45 +0000159 mbox_base = ioremap(mem->start, resource_size(mem));
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000160 if (!mbox_base)
161 return -ENOMEM;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800162
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000163 ret = omap_mbox_register(&pdev->dev, list);
164 if (ret) {
165 iounmap(mbox_base);
166 return ret;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800167 }
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000168
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000169 return 0;
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800170}
171
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800172static int omap1_mbox_remove(struct platform_device *pdev)
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800173{
Felipe Contreras9c80c8c2010-06-11 15:51:46 +0000174 omap_mbox_unregister();
Felipe Contreras5f1af5c2010-06-11 15:51:41 +0000175 iounmap(mbox_base);
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800176 return 0;
177}
178
179static struct platform_driver omap1_mbox_driver = {
180 .probe = omap1_mbox_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800181 .remove = omap1_mbox_remove,
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800182 .driver = {
Felipe Contrerasd7427092010-06-11 15:51:48 +0000183 .name = "omap-mailbox",
Hiroshi DOYU340a6142006-12-07 15:43:59 -0800184 },
185};
186
187static int __init omap1_mbox_init(void)
188{
189 return platform_driver_register(&omap1_mbox_driver);
190}
191
192static void __exit omap1_mbox_exit(void)
193{
194 platform_driver_unregister(&omap1_mbox_driver);
195}
196
197module_init(omap1_mbox_init);
198module_exit(omap1_mbox_exit);
199
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700200MODULE_LICENSE("GPL v2");
201MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
Jonathan McDowell0c405b32009-06-23 13:30:21 +0300202MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
Hiroshi DOYUf98d67a2009-03-23 18:07:25 -0700203MODULE_ALIAS("platform:omap1-mailbox");