mailbox.c 4.31 KB
Newer Older
1
/*
2
 * Mailbox reservation modules for OMAP1
3
 *
4
 * Copyright (C) 2006-2009 Nokia Corporation
5 6 7 8 9 10 11
 * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

12
#include <linux/module.h>
13 14
#include <linux/interrupt.h>
#include <linux/platform_device.h>
15
#include <linux/io.h>
16
#include <plat/mailbox.h>
17 18 19 20 21 22 23 24 25 26 27

#define MAILBOX_ARM2DSP1		0x00
#define MAILBOX_ARM2DSP1b		0x04
#define MAILBOX_DSP2ARM1		0x08
#define MAILBOX_DSP2ARM1b		0x0c
#define MAILBOX_DSP2ARM2		0x10
#define MAILBOX_DSP2ARM2b		0x14
#define MAILBOX_ARM2DSP1_Flag		0x18
#define MAILBOX_DSP2ARM1_Flag		0x1c
#define MAILBOX_DSP2ARM2_Flag		0x20

28
static void __iomem *mbox_base;
29 30 31 32 33 34 35 36 37 38 39 40

struct omap_mbox1_fifo {
	unsigned long cmd;
	unsigned long data;
	unsigned long flag;
};

struct omap_mbox1_priv {
	struct omap_mbox1_fifo tx_fifo;
	struct omap_mbox1_fifo rx_fifo;
};

41
static inline int mbox_read_reg(size_t ofs)
42
{
43
	return __raw_readw(mbox_base + ofs);
44 45
}

46
static inline void mbox_write_reg(u32 val, size_t ofs)
47
{
48
	__raw_writew(val, mbox_base + ofs);
49 50 51
}

/* msg */
Tony Lindgren's avatar
Tony Lindgren committed
52
static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
53 54 55 56 57 58 59 60 61 62 63
{
	struct omap_mbox1_fifo *fifo =
		&((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
	mbox_msg_t msg;

	msg = mbox_read_reg(fifo->data);
	msg |= ((mbox_msg_t) mbox_read_reg(fifo->cmd)) << 16;

	return msg;
}

Tony Lindgren's avatar
Tony Lindgren committed
64
static void
65 66 67 68 69 70 71 72 73
omap1_mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
{
	struct omap_mbox1_fifo *fifo =
		&((struct omap_mbox1_priv *)mbox->priv)->tx_fifo;

	mbox_write_reg(msg & 0xffff, fifo->data);
	mbox_write_reg(msg >> 16, fifo->cmd);
}

Tony Lindgren's avatar
Tony Lindgren committed
74
static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
75 76 77 78
{
	return 0;
}

Tony Lindgren's avatar
Tony Lindgren committed
79
static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
80 81 82 83
{
	struct omap_mbox1_fifo *fifo =
		&((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;

84
	return mbox_read_reg(fifo->flag);
85 86 87
}

/* irq */
Tony Lindgren's avatar
Tony Lindgren committed
88
static void
89 90 91 92 93 94
omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
{
	if (irq == IRQ_RX)
		enable_irq(mbox->irq);
}

Tony Lindgren's avatar
Tony Lindgren committed
95
static void
96 97 98 99 100 101
omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
{
	if (irq == IRQ_RX)
		disable_irq(mbox->irq);
}

Tony Lindgren's avatar
Tony Lindgren committed
102
static int
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
{
	if (irq == IRQ_TX)
		return 0;
	return 1;
}

static struct omap_mbox_ops omap1_mbox_ops = {
	.type		= OMAP_MBOX_TYPE1,
	.fifo_read	= omap1_mbox_fifo_read,
	.fifo_write	= omap1_mbox_fifo_write,
	.fifo_empty	= omap1_mbox_fifo_empty,
	.fifo_full	= omap1_mbox_fifo_full,
	.enable_irq	= omap1_mbox_enable_irq,
	.disable_irq	= omap1_mbox_disable_irq,
	.is_irq		= omap1_mbox_is_irq,
};

/* FIXME: the following struct should be created automatically by the user id */

/* DSP */
static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
	.tx_fifo = {
		.cmd	= MAILBOX_ARM2DSP1b,
		.data	= MAILBOX_ARM2DSP1,
		.flag	= MAILBOX_ARM2DSP1_Flag,
	},
	.rx_fifo = {
		.cmd	= MAILBOX_DSP2ARM1b,
		.data	= MAILBOX_DSP2ARM1,
		.flag	= MAILBOX_DSP2ARM1_Flag,
	},
};

137
static struct omap_mbox mbox_dsp_info = {
138 139 140 141 142
	.name	= "dsp",
	.ops	= &omap1_mbox_ops,
	.priv	= &omap1_mbox_dsp_priv,
};

143
static struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
144

145
static int omap1_mbox_probe(struct platform_device *pdev)
146
{
147
	struct resource *mem;
148
	int ret;
149
	struct omap_mbox **list;
150

151 152
	list = omap1_mboxes;
	list[0]->irq = platform_get_irq_byname(pdev, "dsp");
153

154 155
	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	mbox_base = ioremap(mem->start, resource_size(mem));
156 157
	if (!mbox_base)
		return -ENOMEM;
158

159 160 161 162
	ret = omap_mbox_register(&pdev->dev, list);
	if (ret) {
		iounmap(mbox_base);
		return ret;
163
	}
164

165
	return 0;
166 167
}

168
static int omap1_mbox_remove(struct platform_device *pdev)
169
{
170
	omap_mbox_unregister();
171
	iounmap(mbox_base);
172 173 174 175 176
	return 0;
}

static struct platform_driver omap1_mbox_driver = {
	.probe	= omap1_mbox_probe,
177
	.remove	= omap1_mbox_remove,
178
	.driver	= {
179
		.name	= "omap-mailbox",
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
	},
};

static int __init omap1_mbox_init(void)
{
	return platform_driver_register(&omap1_mbox_driver);
}

static void __exit omap1_mbox_exit(void)
{
	platform_driver_unregister(&omap1_mbox_driver);
}

module_init(omap1_mbox_init);
module_exit(omap1_mbox_exit);

196 197
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
198
MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
199
MODULE_ALIAS("platform:omap1-mailbox");