Commit 9390bd0d authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'mailbox-for-next' of git://git.linaro.org/landing-teams/working/fujitsu/integration

Pull mailbox updates from Jassi Brar.

* 'mailbox-for-next' of git://git.linaro.org/landing-teams/working/fujitsu/integration:
  mailbox/bcm2835: Fix mailbox full detection.
  dt: mailbox: Remove 'mbox-names property is discouraged' message from binding
  mailbox: Add ability for clients to request channels by name
  mailbox: Enable BCM2835 mailbox support
  dt/bindings: Add binding for the BCM2835 mailbox driver
  mailbox: Fix up error handling in mbox_request_channel()
  mailbox: Make mbox_chan_ops const
  mailbox: altera: Add dependency on HAS_IOMEM
parents da996f73 7d641938
Broadcom BCM2835 VideoCore mailbox IPC
Required properties:
- compatible: Should be "brcm,bcm2835-mbox"
- reg: Specifies base physical address and size of the registers
- interrupts: The interrupt number
See bindings/interrupt-controller/brcm,bcm2835-armctrl-ic.txt
- #mbox-cells: Specifies the number of cells needed to encode a mailbox
channel. The value shall be 0, since there is only one
mailbox channel implemented by the device.
Example:
mailbox: mailbox@7e00b800 {
compatible = "brcm,bcm2835-mbox";
reg = <0x7e00b880 0x40>;
interrupts = <0 1>;
#mbox-cells = <0>;
};
firmware: firmware {
compatible = "raspberrypi,firmware";
mboxes = <&mailbox>;
#power-domain-cells = <1>;
};
...@@ -22,17 +22,11 @@ Required property: ...@@ -22,17 +22,11 @@ Required property:
- mboxes: List of phandle and mailbox channel specifiers. - mboxes: List of phandle and mailbox channel specifiers.
Optional property: Optional property:
- mbox-names: List of identifier strings for each mailbox channel - mbox-names: List of identifier strings for each mailbox channel.
required by the client. The use of this property
is discouraged in favor of using index in list of
'mboxes' while requesting a mailbox. Instead the
platforms may define channel indices, in DT headers,
to something legible.
Example: Example:
pwr_cntrl: power { pwr_cntrl: power {
... ...
mbox-names = "pwr-ctrl", "rpc"; mbox-names = "pwr-ctrl", "rpc";
mboxes = <&mailbox 0 mboxes = <&mailbox 0 &mailbox 1>;
&mailbox 1>;
}; };
...@@ -56,8 +56,18 @@ config PCC ...@@ -56,8 +56,18 @@ config PCC
config ALTERA_MBOX config ALTERA_MBOX
tristate "Altera Mailbox" tristate "Altera Mailbox"
depends on HAS_IOMEM
help help
An implementation of the Altera Mailbox soft core. It is used An implementation of the Altera Mailbox soft core. It is used
to send message between processors. Say Y here if you want to use the to send message between processors. Say Y here if you want to use the
Altera mailbox support. Altera mailbox support.
config BCM2835_MBOX
tristate "BCM2835 Mailbox"
depends on ARCH_BCM2835
help
An implementation of the BCM2385 Mailbox. It is used to invoke
the services of the Videocore. Say Y here if you want to use the
BCM2835 Mailbox.
endif endif
...@@ -11,3 +11,5 @@ obj-$(CONFIG_OMAP2PLUS_MBOX) += omap-mailbox.o ...@@ -11,3 +11,5 @@ obj-$(CONFIG_OMAP2PLUS_MBOX) += omap-mailbox.o
obj-$(CONFIG_PCC) += pcc.o obj-$(CONFIG_PCC) += pcc.o
obj-$(CONFIG_ALTERA_MBOX) += mailbox-altera.o obj-$(CONFIG_ALTERA_MBOX) += mailbox-altera.o
obj-$(CONFIG_BCM2835_MBOX) += bcm2835-mailbox.o
...@@ -110,7 +110,7 @@ static void mhu_shutdown(struct mbox_chan *chan) ...@@ -110,7 +110,7 @@ static void mhu_shutdown(struct mbox_chan *chan)
free_irq(mlink->irq, chan); free_irq(mlink->irq, chan);
} }
static struct mbox_chan_ops mhu_ops = { static const struct mbox_chan_ops mhu_ops = {
.send_data = mhu_send_data, .send_data = mhu_send_data,
.startup = mhu_startup, .startup = mhu_startup,
.shutdown = mhu_shutdown, .shutdown = mhu_shutdown,
......
/*
* Copyright (C) 2010,2015 Broadcom
* Copyright (C) 2013-2014 Lubomir Rintel
* Copyright (C) 2013 Craig McGeachie
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This device provides a mechanism for writing to the mailboxes,
* that are shared between the ARM and the VideoCore processor
*
* Parts of the driver are based on:
* - arch/arm/mach-bcm2708/vcio.c file written by Gray Girling that was
* obtained from branch "rpi-3.6.y" of git://github.com/raspberrypi/
* linux.git
* - drivers/mailbox/bcm2835-ipc.c by Lubomir Rintel at
* https://github.com/hackerspace/rpi-linux/blob/lr-raspberry-pi/drivers/
* mailbox/bcm2835-ipc.c
* - documentation available on the following web site:
* https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
*/
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/mailbox_controller.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
/* Mailboxes */
#define ARM_0_MAIL0 0x00
#define ARM_0_MAIL1 0x20
/*
* Mailbox registers. We basically only support mailbox 0 & 1. We
* deliver to the VC in mailbox 1, it delivers to us in mailbox 0. See
* BCM2835-ARM-Peripherals.pdf section 1.3 for an explanation about
* the placement of memory barriers.
*/
#define MAIL0_RD (ARM_0_MAIL0 + 0x00)
#define MAIL0_POL (ARM_0_MAIL0 + 0x10)
#define MAIL0_STA (ARM_0_MAIL0 + 0x18)
#define MAIL0_CNF (ARM_0_MAIL0 + 0x1C)
#define MAIL1_WRT (ARM_0_MAIL1 + 0x00)
#define MAIL1_STA (ARM_0_MAIL1 + 0x18)
/* Status register: FIFO state. */
#define ARM_MS_FULL BIT(31)
#define ARM_MS_EMPTY BIT(30)
/* Configuration register: Enable interrupts. */
#define ARM_MC_IHAVEDATAIRQEN BIT(0)
struct bcm2835_mbox {
void __iomem *regs;
spinlock_t lock;
struct mbox_controller controller;
};
static struct bcm2835_mbox *bcm2835_link_mbox(struct mbox_chan *link)
{
return container_of(link->mbox, struct bcm2835_mbox, controller);
}
static irqreturn_t bcm2835_mbox_irq(int irq, void *dev_id)
{
struct bcm2835_mbox *mbox = dev_id;
struct device *dev = mbox->controller.dev;
struct mbox_chan *link = &mbox->controller.chans[0];
while (!(readl(mbox->regs + MAIL0_STA) & ARM_MS_EMPTY)) {
u32 msg = readl(mbox->regs + MAIL0_RD);
dev_dbg(dev, "Reply 0x%08X\n", msg);
mbox_chan_received_data(link, &msg);
}
return IRQ_HANDLED;
}
static int bcm2835_send_data(struct mbox_chan *link, void *data)
{
struct bcm2835_mbox *mbox = bcm2835_link_mbox(link);
u32 msg = *(u32 *)data;
spin_lock(&mbox->lock);
writel(msg, mbox->regs + MAIL1_WRT);
dev_dbg(mbox->controller.dev, "Request 0x%08X\n", msg);
spin_unlock(&mbox->lock);
return 0;
}
static int bcm2835_startup(struct mbox_chan *link)
{
struct bcm2835_mbox *mbox = bcm2835_link_mbox(link);
/* Enable the interrupt on data reception */
writel(ARM_MC_IHAVEDATAIRQEN, mbox->regs + MAIL0_CNF);
return 0;
}
static void bcm2835_shutdown(struct mbox_chan *link)
{
struct bcm2835_mbox *mbox = bcm2835_link_mbox(link);
writel(0, mbox->regs + MAIL0_CNF);
}
static bool bcm2835_last_tx_done(struct mbox_chan *link)
{
struct bcm2835_mbox *mbox = bcm2835_link_mbox(link);
bool ret;
spin_lock(&mbox->lock);
ret = !(readl(mbox->regs + MAIL1_STA) & ARM_MS_FULL);
spin_unlock(&mbox->lock);
return ret;
}
static const struct mbox_chan_ops bcm2835_mbox_chan_ops = {
.send_data = bcm2835_send_data,
.startup = bcm2835_startup,
.shutdown = bcm2835_shutdown,
.last_tx_done = bcm2835_last_tx_done
};
static struct mbox_chan *bcm2835_mbox_index_xlate(struct mbox_controller *mbox,
const struct of_phandle_args *sp)
{
if (sp->args_count != 0)
return NULL;
return &mbox->chans[0];
}
static int bcm2835_mbox_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
int ret = 0;
struct resource *iomem;
struct bcm2835_mbox *mbox;
mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL);
if (mbox == NULL)
return -ENOMEM;
spin_lock_init(&mbox->lock);
ret = devm_request_irq(dev, irq_of_parse_and_map(dev->of_node, 0),
bcm2835_mbox_irq, 0, dev_name(dev), mbox);
if (ret) {
dev_err(dev, "Failed to register a mailbox IRQ handler: %d\n",
ret);
return -ENODEV;
}
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mbox->regs = devm_ioremap_resource(&pdev->dev, iomem);
if (IS_ERR(mbox->regs)) {
ret = PTR_ERR(mbox->regs);
dev_err(&pdev->dev, "Failed to remap mailbox regs: %d\n", ret);
return ret;
}
mbox->controller.txdone_poll = true;
mbox->controller.txpoll_period = 5;
mbox->controller.ops = &bcm2835_mbox_chan_ops;
mbox->controller.of_xlate = &bcm2835_mbox_index_xlate;
mbox->controller.dev = dev;
mbox->controller.num_chans = 1;
mbox->controller.chans = devm_kzalloc(dev,
sizeof(*mbox->controller.chans), GFP_KERNEL);
if (!mbox->controller.chans)
return -ENOMEM;
ret = mbox_controller_register(&mbox->controller);
if (ret)
return ret;
platform_set_drvdata(pdev, mbox);
dev_info(dev, "mailbox enabled\n");
return ret;
}
static int bcm2835_mbox_remove(struct platform_device *pdev)
{
struct bcm2835_mbox *mbox = platform_get_drvdata(pdev);
mbox_controller_unregister(&mbox->controller);
return 0;
}
static const struct of_device_id bcm2835_mbox_of_match[] = {
{ .compatible = "brcm,bcm2835-mbox", },
{},
};
MODULE_DEVICE_TABLE(of, bcm2835_mbox_of_match);
static struct platform_driver bcm2835_mbox_driver = {
.driver = {
.name = "bcm2835-mbox",
.owner = THIS_MODULE,
.of_match_table = bcm2835_mbox_of_match,
},
.probe = bcm2835_mbox_probe,
.remove = bcm2835_mbox_remove,
};
module_platform_driver(bcm2835_mbox_driver);
MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
MODULE_DESCRIPTION("BCM2835 mailbox IPC driver");
MODULE_LICENSE("GPL v2");
...@@ -285,7 +285,7 @@ static void altera_mbox_shutdown(struct mbox_chan *chan) ...@@ -285,7 +285,7 @@ static void altera_mbox_shutdown(struct mbox_chan *chan)
} }
} }
static struct mbox_chan_ops altera_mbox_ops = { static const struct mbox_chan_ops altera_mbox_ops = {
.send_data = altera_mbox_send_data, .send_data = altera_mbox_send_data,
.startup = altera_mbox_startup, .startup = altera_mbox_startup,
.shutdown = altera_mbox_shutdown, .shutdown = altera_mbox_shutdown,
......
...@@ -318,7 +318,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) ...@@ -318,7 +318,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
} }
chan = NULL; chan = ERR_PTR(-EPROBE_DEFER);
list_for_each_entry(mbox, &mbox_cons, node) list_for_each_entry(mbox, &mbox_cons, node)
if (mbox->dev->of_node == spec.np) { if (mbox->dev->of_node == spec.np) {
chan = mbox->of_xlate(mbox, &spec); chan = mbox->of_xlate(mbox, &spec);
...@@ -327,7 +327,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) ...@@ -327,7 +327,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
of_node_put(spec.np); of_node_put(spec.np);
if (!chan || chan->cl || !try_module_get(mbox->dev->driver->owner)) { if (IS_ERR(chan)) {
mutex_unlock(&con_mutex);
return chan;
}
if (chan->cl || !try_module_get(mbox->dev->driver->owner)) {
dev_dbg(dev, "%s: mailbox not free\n", __func__); dev_dbg(dev, "%s: mailbox not free\n", __func__);
mutex_unlock(&con_mutex); mutex_unlock(&con_mutex);
return ERR_PTR(-EBUSY); return ERR_PTR(-EBUSY);
...@@ -357,6 +362,35 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) ...@@ -357,6 +362,35 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
} }
EXPORT_SYMBOL_GPL(mbox_request_channel); EXPORT_SYMBOL_GPL(mbox_request_channel);
struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
const char *name)
{
struct device_node *np = cl->dev->of_node;
struct property *prop;
const char *mbox_name;
int index = 0;
if (!np) {
dev_err(cl->dev, "%s() currently only supports DT\n", __func__);
return ERR_PTR(-ENOSYS);
}
if (!of_get_property(np, "mbox-names", NULL)) {
dev_err(cl->dev,
"%s() requires an \"mbox-names\" property\n", __func__);
return ERR_PTR(-ENOSYS);
}
of_property_for_each_string(np, "mbox-names", prop, mbox_name) {
if (!strncmp(name, mbox_name, strlen(name)))
break;
index++;
}
return mbox_request_channel(cl, index);
}
EXPORT_SYMBOL_GPL(mbox_request_channel_byname);
/** /**
* mbox_free_channel - The client relinquishes control of a mailbox * mbox_free_channel - The client relinquishes control of a mailbox
* channel by this call. * channel by this call.
...@@ -390,7 +424,7 @@ of_mbox_index_xlate(struct mbox_controller *mbox, ...@@ -390,7 +424,7 @@ of_mbox_index_xlate(struct mbox_controller *mbox,
int ind = sp->args[0]; int ind = sp->args[0];
if (ind >= mbox->num_chans) if (ind >= mbox->num_chans)
return NULL; return ERR_PTR(-EINVAL);
return &mbox->chans[ind]; return &mbox->chans[ind];
} }
......
...@@ -604,7 +604,7 @@ static int omap_mbox_chan_send_data(struct mbox_chan *chan, void *data) ...@@ -604,7 +604,7 @@ static int omap_mbox_chan_send_data(struct mbox_chan *chan, void *data)
return ret; return ret;
} }
static struct mbox_chan_ops omap_mbox_chan_ops = { static const struct mbox_chan_ops omap_mbox_chan_ops = {
.startup = omap_mbox_chan_startup, .startup = omap_mbox_chan_startup,
.send_data = omap_mbox_chan_send_data, .send_data = omap_mbox_chan_send_data,
.shutdown = omap_mbox_chan_shutdown, .shutdown = omap_mbox_chan_shutdown,
...@@ -639,18 +639,18 @@ static struct mbox_chan *omap_mbox_of_xlate(struct mbox_controller *controller, ...@@ -639,18 +639,18 @@ static struct mbox_chan *omap_mbox_of_xlate(struct mbox_controller *controller,
mdev = container_of(controller, struct omap_mbox_device, controller); mdev = container_of(controller, struct omap_mbox_device, controller);
if (WARN_ON(!mdev)) if (WARN_ON(!mdev))
return NULL; return ERR_PTR(-EINVAL);
node = of_find_node_by_phandle(phandle); node = of_find_node_by_phandle(phandle);
if (!node) { if (!node) {
pr_err("%s: could not find node phandle 0x%x\n", pr_err("%s: could not find node phandle 0x%x\n",
__func__, phandle); __func__, phandle);
return NULL; return ERR_PTR(-ENODEV);
} }
mbox = omap_mbox_device_find(mdev, node->name); mbox = omap_mbox_device_find(mdev, node->name);
of_node_put(node); of_node_put(node);
return mbox ? mbox->chan : NULL; return mbox ? mbox->chan : ERR_PTR(-ENOENT);
} }
static int omap_mbox_probe(struct platform_device *pdev) static int omap_mbox_probe(struct platform_device *pdev)
......
...@@ -198,7 +198,7 @@ static int pcc_send_data(struct mbox_chan *chan, void *data) ...@@ -198,7 +198,7 @@ static int pcc_send_data(struct mbox_chan *chan, void *data)
return 0; return 0;
} }
static struct mbox_chan_ops pcc_chan_ops = { static const struct mbox_chan_ops pcc_chan_ops = {
.send_data = pcc_send_data, .send_data = pcc_send_data,
}; };
......
...@@ -40,6 +40,8 @@ struct mbox_client { ...@@ -40,6 +40,8 @@ struct mbox_client {
void (*tx_done)(struct mbox_client *cl, void *mssg, int r); void (*tx_done)(struct mbox_client *cl, void *mssg, int r);
}; };
struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
const char *name);
struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index);
int mbox_send_message(struct mbox_chan *chan, void *mssg); int mbox_send_message(struct mbox_chan *chan, void *mssg);
void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */ void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */
......
...@@ -72,7 +72,7 @@ struct mbox_chan_ops { ...@@ -72,7 +72,7 @@ struct mbox_chan_ops {
*/ */
struct mbox_controller { struct mbox_controller {
struct device *dev; struct device *dev;
struct mbox_chan_ops *ops; const struct mbox_chan_ops *ops;
struct mbox_chan *chans; struct mbox_chan *chans;
int num_chans; int num_chans;
bool txdone_irq; bool txdone_irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment