2006-12-08 00:43:59 +01:00
|
|
|
/*
|
|
|
|
* Mailbox reservation modules for DSP
|
|
|
|
*
|
2009-03-24 02:07:25 +01:00
|
|
|
* Copyright (C) 2006-2009 Nokia Corporation
|
2006-12-08 00:43:59 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/resource.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
2008-09-06 13:10:45 +02:00
|
|
|
#include <linux/io.h>
|
2009-10-20 18:40:47 +02:00
|
|
|
#include <plat/mailbox.h>
|
2008-08-05 17:14:15 +02:00
|
|
|
#include <mach/irqs.h>
|
2006-12-08 00:43:59 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
static void __iomem *mbox_base;
|
2006-12-08 00:43:59 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
static inline int mbox_read_reg(size_t ofs)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
2009-03-24 02:07:25 +01:00
|
|
|
return __raw_readw(mbox_base + ofs);
|
2006-12-08 00:43:59 +01:00
|
|
|
}
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
static inline void mbox_write_reg(u32 val, size_t ofs)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
2009-03-24 02:07:25 +01:00
|
|
|
__raw_writew(val, mbox_base + ofs);
|
2006-12-08 00:43:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* msg */
|
2007-12-19 05:58:32 +01:00
|
|
|
static mbox_msg_t omap1_mbox_fifo_read(struct omap_mbox *mbox)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-12-19 05:58:32 +01:00
|
|
|
static void
|
2006-12-08 00:43:59 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-12-19 05:58:32 +01:00
|
|
|
static int omap1_mbox_fifo_empty(struct omap_mbox *mbox)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-19 05:58:32 +01:00
|
|
|
static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
|
|
|
struct omap_mbox1_fifo *fifo =
|
|
|
|
&((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
|
|
|
|
|
|
|
|
return (mbox_read_reg(fifo->flag));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* irq */
|
2007-12-19 05:58:32 +01:00
|
|
|
static void
|
2006-12-08 00:43:59 +01:00
|
|
|
omap1_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
|
|
|
|
{
|
|
|
|
if (irq == IRQ_RX)
|
|
|
|
enable_irq(mbox->irq);
|
|
|
|
}
|
|
|
|
|
2007-12-19 05:58:32 +01:00
|
|
|
static void
|
2006-12-08 00:43:59 +01:00
|
|
|
omap1_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
|
|
|
|
{
|
|
|
|
if (irq == IRQ_RX)
|
|
|
|
disable_irq(mbox->irq);
|
|
|
|
}
|
|
|
|
|
2007-12-19 05:58:32 +01:00
|
|
|
static int
|
2006-12-08 00:43:59 +01:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
struct omap_mbox mbox_dsp_info = {
|
|
|
|
.name = "dsp",
|
|
|
|
.ops = &omap1_mbox_ops,
|
|
|
|
.priv = &omap1_mbox_dsp_priv,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL(mbox_dsp_info);
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
static int __devinit omap1_mbox_probe(struct platform_device *pdev)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
if (pdev->num_resources != 2) {
|
|
|
|
dev_err(&pdev->dev, "invalid number of resources: %d\n",
|
|
|
|
pdev->num_resources);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MBOX base */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (unlikely(!res)) {
|
|
|
|
dev_err(&pdev->dev, "invalid mem resource\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2010-02-15 19:03:33 +01:00
|
|
|
|
|
|
|
mbox_base = ioremap(res->start, resource_size(res));
|
|
|
|
if (!mbox_base) {
|
|
|
|
dev_err(&pdev->dev, "ioremap failed\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2006-12-08 00:43:59 +01:00
|
|
|
|
|
|
|
/* DSP IRQ */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (unlikely(!res)) {
|
|
|
|
dev_err(&pdev->dev, "invalid irq resource\n");
|
2010-02-15 19:03:33 +01:00
|
|
|
iounmap(mbox_base);
|
2006-12-08 00:43:59 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
mbox_dsp_info.irq = res->start;
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
return omap_mbox_register(&pdev->dev, &mbox_dsp_info);
|
2006-12-08 00:43:59 +01:00
|
|
|
}
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
static int __devexit omap1_mbox_remove(struct platform_device *pdev)
|
2006-12-08 00:43:59 +01:00
|
|
|
{
|
|
|
|
omap_mbox_unregister(&mbox_dsp_info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver omap1_mbox_driver = {
|
|
|
|
.probe = omap1_mbox_probe,
|
2009-03-24 02:07:25 +01:00
|
|
|
.remove = __devexit_p(omap1_mbox_remove),
|
2006-12-08 00:43:59 +01:00
|
|
|
.driver = {
|
2009-03-24 02:07:25 +01:00
|
|
|
.name = "omap1-mailbox",
|
2006-12-08 00:43:59 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-03-24 02:07:25 +01:00
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
|
2009-06-23 12:30:21 +02:00
|
|
|
MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
|
2009-03-24 02:07:25 +01:00
|
|
|
MODULE_ALIAS("platform:omap1-mailbox");
|