Add support for Broadcom iProc mailbox controller
Subsystems (3)
cover Add support for Broadcom iProc mailbox controller
This patch set contains mailbox support for Broadcom iProc based SoC's. The mailbox controller handles all communication with a Cortex-M0 MCU processor that provides support for power, clock, and reset management.
The patch set enables the mailbox controller for Cygnus and also interrupt support for the Cygnus CRMU GPIO driver which requires use of the M0 processor.
Jonathan Richardson (4):
dt-bindings: Document Broadcom iProc mailbox controller driver
mailbox: Add iProc mailbox controller driver
ARM: dts: Enable Broadcom iProc mailbox controller
ARM: dts: Enable interrupt support for cygnus crmu gpio driver
.../bindings/mailbox/brcm,iproc-mailbox.txt | 20 + arch/arm/boot/dts/bcm-cygnus.dtsi | 12 + drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/bcm-iproc-mailbox.c | 422 +++++++++++++++++++++ include/linux/bcm_iproc_mailbox.h | 32 ++ 6 files changed, 498 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/brcm,iproc-mailbox.txt create mode 100644 drivers/mailbox/bcm-iproc-mailbox.c create mode 100644 include/linux/bcm_iproc_mailbox.h
Signature · 1 line
1.9.1
PATCH 1/4 dt-bindings: Document Broadcom iProc mailbox controller driver
--- .../bindings/mailbox/brcm,iproc-mailbox.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/brcm,iproc-mailbox.txt
Documentation/devicetree/bindings/mailbox/brcm,iproc-mailbox.txt new file +20 -0
@@ -0,0 +1,20 @@ +* Broadcom's iProc Mailbox Controller + +Required properties: +- compatible: Must be "brcm,iproc-mailbox" +- reg: Defines the base address of the mailbox controller. +- interrupts: The mailbox controller's interrupt. +- #interrupt-cells: Must be 1. +- interrupt-controller: Sets device as an interrupt controller. +- #mbox-cells: Must be 1. + +Example: + + mailbox: mailbox at 3024024 { + compatible = "brcm,iproc-mailbox"; + reg = <0x03024024 0x40>; + interrupts = <GIC_SPI 138 IRQ_TYPE_LEVEL_HIGH>; + #interrupt-cells = <1>; + interrupt-controller; + #mbox-cells = <1>; + };
Signature · 1 line
1.9.1
PATCH 2/4 mailbox: Add iProc mailbox controller driver
In reply to Jonathan RichardsonThe Broadcom iProc mailbox controller handles all communication with a Cortex-M0 MCU processor that provides support for power, clock, and reset management.
--- drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/bcm-iproc-mailbox.c | 422 ++++++++++++++++++++++++++++++++++++ include/linux/bcm_iproc_mailbox.h | 32 +++ 4 files changed, 466 insertions(+) create mode 100644 drivers/mailbox/bcm-iproc-mailbox.c create mode 100644 include/linux/bcm_iproc_mailbox.h
drivers/mailbox/Kconfig +10 -0
@@ -143,4 +143,14 @@ config BCM_PDC_MBOX Mailbox implementation for the Broadcom PDC ring manager, which provides access to various offload engines on Broadcom SoCs. Say Y here if you want to use the Broadcom PDC. + +config BCM_IPROC_MBOX + bool "Broadcom iProc Mailbox" + depends on ARCH_BCM_IPROC || COMPILE_TEST + default ARCH_BCM_IPROC + help + Broadcom iProc architected SoC's have an always on Cortex-M0 MCU processor + that handles support for power, clock, and reset management. The iProc + mailbox controller handles all communication with this processor. + endif
drivers/mailbox/Makefile +2 -0
@@ -29,3 +29,5 @@ obj-$(CONFIG_XGENE_SLIMPRO_MBOX) += mailbox-xgene-slimpro.o obj-$(CONFIG_HI6220_MBOX) += hi6220-mailbox.o obj-$(CONFIG_BCM_PDC_MBOX) += bcm-pdc-mailbox.o + +obj-$(CONFIG_BCM_IPROC_MBOX) += bcm-iproc-mailbox.o
drivers/mailbox/bcm-iproc-mailbox.c new file +422 -0
422 lines not on this page · raw message
include/linux/bcm_iproc_mailbox.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2016 Broadcom. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation version 2. +* +* This program is distributed "as is" WITHOUT ANY WARRANTY of any +* kind, whether express or implied; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#ifndef _BCM_IPROC_MAILBOX_H_ +#define _BCM_IPROC_MAILBOX_H_ + +/* +* A message to send to the M0 processor. +* @cmd Command to send. +* @param Parameter corresponding to command. +* @wait_ack true if mbox_send_message() should wait for a reply from the M0, +* false if the M0 doesn't reply. This depends on the message being sent. +* @reply_code The response code from the M0 for the command sent (wait_ack was +* set to true). +*/ +struct iproc_mbox_msg { +u32 cmd; +u32 param; +bool wait_ack; +u32 reply_code; +}; + +#endif
Signature · 1 line
1.9.1
PATCH 3/4 ARM: dts: Enable Broadcom iProc mailbox controller
In reply to Jonathan Richardson--- arch/arm/boot/dts/bcm-cygnus.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/boot/dts/bcm-cygnus.dtsi +9 -0
@@ -114,6 +114,15 @@ <0x0301d24c 0x2c>; }; + mailbox: mailbox at 03024024 { + compatible = "brcm,iproc-mailbox"; + reg = <0x03024024 0x40>; + interrupts = <GIC_SPI 138 IRQ_TYPE_LEVEL_HIGH>; + #interrupt-cells = <1>; + interrupt-controller; + #mbox-cells = <1>; + }; + gpio_crmu: gpio at 03024800 { compatible = "brcm,cygnus-crmu-gpio"; reg = <0x03024800 0x50>,
Signature · 1 line
1.9.1
PATCH 4/4 ARM: dts: Enable interrupt support for cygnus crmu gpio driver
In reply to Jonathan RichardsonThe M0 processor handles interrupts for the always-on CRMU GPIO controller. Setting the CRMU GPIO driver with the mailbox controller as the interrupt parent allows the mailbox controller to forward interrupts from the M0 to the GPIO driver for processing.
--- arch/arm/boot/dts/bcm-cygnus.dtsi | 3 +++ 1 file changed, 3 insertions(+)
arch/arm/boot/dts/bcm-cygnus.dtsi +3 -0
@@ -130,6 +130,9 @@ ngpios = <6>; #gpio-cells = <2>; gpio-controller; + interrupt-controller; + interrupt-parent = <&mailbox>; + interrupts = <0>; }; i2c0: i2c at 18008000 {
Signature · 1 line
1.9.1
Rob Herring
maintainerPATCH 1/4 dt-bindings: Document Broadcom iProc mailbox controller driver
In reply to Jonathan RichardsonQuoted 11 lines · Jonathan Richardson
Reviewed-by Jonathan Richardson <[email protected]>Tested-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Ray Jui <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>--- .../bindings/mailbox/brcm,iproc-mailbox.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/brcm,iproc-mailbox.txt
Florian Fainelli
AppliedPATCH 3/4 ARM: dts: Enable Broadcom iProc mailbox controller
In reply to Jonathan RichardsonQuoted 7 lines · Jonathan Richardson
Reviewed-by Jonathan Richardson <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Ray Jui <[email protected]>Tested-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>
Applied, thanks
Signature · 1 line
Florian
Florian Fainelli
AppliedPATCH 4/4 ARM: dts: Enable interrupt support for cygnus crmu gpio driver
In reply to Jonathan RichardsonQuoted 5 lines · Jonathan Richardson
The M0 processor handles interrupts for the always-on CRMU GPIO controller. Setting the CRMU GPIO driver with the mailbox controller as the interrupt parent allows the mailbox controller to forward interrupts from the M0 to the GPIO driver for processing.
Quoted 7 lines
Reviewed-by Jonathan Richardson <[email protected]>Tested-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Ray Jui <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>
Applied, thanks
Signature · 1 line
Florian
Jassi Brar
maintainerPATCH 1/4 dt-bindings: Document Broadcom iProc mailbox controller driver
In reply to Jonathan RichardsonQuoted 8 lines · Jonathan Richardson
Reviewed-by Jonathan Richardson <[email protected]>Tested-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Ray Jui <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>---
Wow, heavily endorsed! :) Some log explaining the node, would have
been nice. Especially how mailbox acts as an interrupt controller.
Thanks.
Jassi Brar
maintainerPATCH 2/4 mailbox: Add iProc mailbox controller driver
In reply to Jonathan RichardsonHi Jonathan,
Quoted 11 lines · Jonathan Richardson
The Broadcom iProc mailbox controller handles all communication with a Cortex-M0 MCU processor that provides support for power, clock, and reset management.
Tested-by Jonathan Richardson <[email protected]>Reviewed-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Ray Jui <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>
Quoted 6 lines
--- drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/bcm-iproc-mailbox.c | 422 ++++++++++++++++++++++++++++++++++++ include/linux/bcm_iproc_mailbox.h | 32 +++
This should be include/linux/mailbox/bcm_iproc_mailbox.h
Quoted 20 lines
+++
b/drivers/mailbox/bcm-iproc-mailbox.cdrivers/mailbox/bcm-iproc-mailbox.c new file +17
-0@@ -0,0 +1,422 @@ +/* +* Copyright (C) 2016 Broadcom. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation version 2. +* +* This program is distributed "as is" WITHOUT ANY WARRANTY of any +* kind, whether express or implied; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/irq.h> +#include <linux/interrupt.h>
drivers/mailbox/bcm-iproc-mailbox.c line 27
Quoted 10 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +10
-0+#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/of_device.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/notifier.h> +#include <linux/reboot.h> +#include <linux/mailbox_controller.h> +#include <linux/mailbox_client.h>
Need of mailbox_controller.h & client.h is a bad sign.
Quoted 31 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +31
-0+ +static int iproc_mbox_send_data_m0_imp (struct iproc_mbox *mbox, +struct iproc_mbox_msg *msg,int max_retries,int poll_period_us) +{ +unsigned long flags; +u32 val; +int err =0 ; +int retries; + +spin_lock_irqsave (&mbox->lock, flags); + +dev_dbg (mbox->dev,"Send msg to M0: cmd=0x%x, param=0x%x, wait_ack=%d\n" , + msg->cmd, msg->param, msg->wait_ack); + +writel (msg->cmd, mbox->base +IPROC_CRMU_MAILBOX0_OFFSET ); +writel (msg->param, mbox->base +IPROC_CRMU_MAILBOX1_OFFSET ); + +if (msg->wait_ack) { + err = msg->reply_code = -ETIMEDOUT ; +for (retries =0 ; retries < max_retries; retries++) { + val =readl (mbox->base +IPROC_CRMU_MAILBOX0_OFFSET ); +if (val &M0_IPC_CMD_DONE_MASK ) { +/* +* M0 replied - save reply code and +* clear error. +*/ + msg->reply_code = (val & +M0_IPC_CMD_REPLY_MASK ) >> +M0_IPC_CMD_REPLY_SHIFT ; + err =0 ; +break ;
drivers/mailbox/bcm-iproc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +10
-0+ } +udelay (poll_period_us); + } + } + +spin_unlock_irqrestore (&mbox->lock, flags); + +return err; +} +
OK, so this is the real message passing voodoo.
Quoted 27 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +27
-0+static void iproc_mbox_aon_gpio_forwarding_enable (struct iproc_mbox *mbox, +bool en) +{ +struct iproc_mbox_msg msg; +const int max_retries =5 ; +const int poll_period_us =200 ; + + msg.cmd =M0_IPC_M0_CMD_AON_GPIO_FORWARDING_ENABLE ; + msg.param = en ?1 :0 ; + msg.wait_ack = true; + +iproc_mbox_send_data_m0_imp (mbox, &msg, max_retries, poll_period_us); +} + +static void iproc_mbox_irq_unmask (struct irq_data *d) +{ +struct iproc_mbox *iproc_mbox =irq_data_get_irq_chip_data (d); + +iproc_mbox_aon_gpio_forwarding_enable (iproc_mbox, true); +} + +static void iproc_mbox_irq_mask (struct irq_data *d) +{ +/* Do nothing - Mask callback is not required, since upon GPIO event, +* M0 disables GPIO forwarding to A9. Hence, GPIO forwarding is already +* disabled when in mbox irq handler, and no other mbox events from M0 +* to A9 are expected until GPIO forwarding is enabled following
drivers/mailbox/bcm-iproc-mailbox.c line 194
Quoted 10 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +10
-0+* iproc_mbox_irq_unmask() +*/ +} + +static struct irq_chip iproc_mbox_irq_chip = { + .name ="bcm-iproc-mbox" , + .irq_mask = iproc_mbox_irq_mask, + .irq_unmask = iproc_mbox_irq_unmask, +}; +
.... these are simply using the mailbox controllers directly. So you are actually clubbing a mailbox client (interrupt controller) with the provider (mailbox) here.
I think you need move the IRQ controller part under drivers/irqchip/ that uses the mailbox api to manage its 'irq lines'.
Thanks.
PATCH 2/4 mailbox: Add iProc mailbox controller driver
Quoted 1 line · Jassi Brar
Hi Jonathan,
Hi Jassi. Thanks for the review. I was away so sorry for the slow reply.
Quoted 20 lines
Quoted 11 lines · Jonathan Richardson
The Broadcom iProc mailbox controller handles all communication with a Cortex-M0 MCU processor that provides support for power, clock, and reset management.
Tested-by Jonathan Richardson <[email protected]>Reviewed-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Ray Jui <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>Quoted 6 lines
--- drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/bcm-iproc-mailbox.c | 422 ++++++++++++++++++++++++++++++++++++ include/linux/bcm_iproc_mailbox.h | 32 +++
Quoted 1 line
This should be
include/linux/mailbox/bcm_iproc_mailbox.h
I'll move it.
Quoted 25 lines
Quoted 25 lines
+++
b/drivers/mailbox/bcm-iproc-mailbox.cdrivers/mailbox/bcm-iproc-mailbox.c new file +21
-0@@ -0,0 +1,422 @@ +/* +* Copyright (C) 2016 Broadcom. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation version 2. +* +* This program is distributed "as is" WITHOUT ANY WARRANTY of any +* kind, whether express or implied; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/irq.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/of_device.h> +#include <linux/of.h>
Quoted 8 lines
drivers/mailbox/bcm-iproc-mailbox.c line 27
Quoted 7 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +6
-0+#include <linux/of_irq.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/notifier.h> +#include <linux/reboot.h> +#include <linux/mailbox_controller.h> +#include <linux/mailbox_client.h> Need of
mailbox_controller.h&client.his a bad sign.
The controller is using this only for the tx_tout value from the client to determine a reasonable timeout period. We could use a fixed value in the controller instead.
Quoted 85 lines
Quoted 32 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +31
-0+ +static int iproc_mbox_send_data_m0_imp (struct iproc_mbox *mbox, +struct iproc_mbox_msg *msg,int max_retries,int poll_period_us) +{ +unsigned long flags; +u32 val; +int err =0 ; +int retries; + +spin_lock_irqsave (&mbox->lock, flags); + +dev_dbg (mbox->dev,"Send msg to M0: cmd=0x%x, param=0x%x, wait_ack=%d\n" , + msg->cmd, msg->param, msg->wait_ack); + +writel (msg->cmd, mbox->base +IPROC_CRMU_MAILBOX0_OFFSET ); +writel (msg->param, mbox->base +IPROC_CRMU_MAILBOX1_OFFSET ); + +if (msg->wait_ack) { + err = msg->reply_code = -ETIMEDOUT ; +for (retries =0 ; retries < max_retries; retries++) { + val =readl (mbox->base +IPROC_CRMU_MAILBOX0_OFFSET ); +if (val &M0_IPC_CMD_DONE_MASK ) { +/* +* M0 replied - save reply code and +* clear error. +*/ + msg->reply_code = (val & +M0_IPC_CMD_REPLY_MASK ) >> +M0_IPC_CMD_REPLY_SHIFT ; + err =0 ; +break ;drivers/mailbox/bcm-iproc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +10
-0+ } +udelay (poll_period_us); + } + } + +spin_unlock_irqrestore (&mbox->lock, flags); + +return err; +} +OK, so this is the real message passing voodoo.
Quoted 27 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +27
-0+static void iproc_mbox_aon_gpio_forwarding_enable (struct iproc_mbox *mbox, +bool en) +{ +struct iproc_mbox_msg msg; +const int max_retries =5 ; +const int poll_period_us =200 ; + + msg.cmd =M0_IPC_M0_CMD_AON_GPIO_FORWARDING_ENABLE ; + msg.param = en ?1 :0 ; + msg.wait_ack = true; + +iproc_mbox_send_data_m0_imp (mbox, &msg, max_retries, poll_period_us); +} + +static void iproc_mbox_irq_unmask (struct irq_data *d) +{ +struct iproc_mbox *iproc_mbox =irq_data_get_irq_chip_data (d); + +iproc_mbox_aon_gpio_forwarding_enable (iproc_mbox, true); +} + +static void iproc_mbox_irq_mask (struct irq_data *d) +{ +/* Do nothing - Mask callback is not required, since upon GPIO event, +* M0 disables GPIO forwarding to A9. Hence, GPIO forwarding is already +* disabled when in mbox irq handler, and no other mbox events from M0 +* to A9 are expected until GPIO forwarding is enabled following drivers/mailbox/bcm-iproc-mailbox.c line 194
Quoted 10 lines
drivers/mailbox/bcm-iproc-mailbox.c new file +10
-0+* iproc_mbox_irq_unmask() +*/ +} + +static struct irq_chip iproc_mbox_irq_chip = { + .name ="bcm-iproc-mbox" , + .irq_mask = iproc_mbox_irq_mask, + .irq_unmask = iproc_mbox_irq_unmask, +}; +.... these are simply using the mailbox controllers directly. So you are actually clubbing a mailbox client (interrupt controller) with the provider (mailbox) here.
Quoted 3 lines
I think you need move the IRQ controller part under
drivers/irqchip/that uses the mailbox api to manage its 'irq lines'.
Should be straight forward to change.
Thanks.
Quoted 2 lines
Thanks.
PATCH 1/4 dt-bindings: Document Broadcom iProc mailbox controller driver
In reply to Jassi BrarQuoted 11 lines · Jassi Brar
Quoted 8 lines · Jonathan Richardson
Reviewed-by Jonathan Richardson <[email protected]>Tested-by Jonathan Richardson <[email protected]>Reviewed-by Vikram Prakash <[email protected]>Reviewed-by Ray Jui <[email protected]>Reviewed-by Shreesha Rajashekar <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Jonathan Richardson <[email protected]>---
Quoted 3 lines
Wow, heavily endorsed! :) Some log explaining the node, would have
been nice. Especially how mailbox acts as an interrupt controller.
I agree. I'll add it to the binding for the suggested new mailbox irq controller driver.
Quoted 2 lines
Thanks.