Skip to contentSkip to conversation

mailbox: rockchip: Add mailbox driver for Rockchip platform

PATCH In review Caesar Wang 4 participants 12 messages Sep 14, 2015 – Oct 27, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover mailbox: rockchip: Add mailbox driver for Rockchip platform

Mailbox is used by the Rockchip CPU cores to communicate requests to MCU processorm.

This driver is found on RK3368 SoCs.

The Mailbox module is a simple APB peripheral that allows both the Cortex-A53 MCU system to communicate by writing operation to generate interrupt.
The registers are accessible by both CPU via APB interface.

Tested on RK3368 SDK board.

Caesar Wang (3):
dt-bindings: Add document of Rockchip mailbox
mailbox: rockchip: Add Rockchip mailbox driver
ARM64: dts: rk3368: Add mailbox device nodes

 .../bindings/mailbox/rockchip-mailbox.txt          |  33 +++
 arch/arm64/boot/dts/rockchip/rk3368.dtsi           |  13 +
 drivers/mailbox/Kconfig                            |   9 +
 drivers/mailbox/Makefile                           |   2 +
 drivers/mailbox/rockchip-mailbox.c                 | 317 +++++++++++++++++++++
 5 files changed, 374 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt
 create mode 100644 drivers/mailbox/rockchip-mailbox.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/3 dt-bindings: Add document of Rockchip mailbox

This add the necessary binding documentation for mailbox found on RK3368 SoC.

---

 .../bindings/mailbox/rockchip-mailbox.txt          | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +33 -0
new file mode 100644
index 0000000..b9b4768
@@ -0,0 +1,33 @@
+Rockchip mailbox
+
+The Rockchip mailbox is used by the Rockchip CPU cores to communicate
+requests to MCU processor.
+
+Refer to ./mailbox.txt for generic information about mailbox device-tree
+bindings.
+
+Required properties:
+
+ - compatible: should be one of the following.
+   - "rockchip,rk3368-mbox" for rk3368
+ - reg: physical base address of the controller and length of memory mapped
+	region.
+	physical base address of the share buffer and length of memory mapped
+	region.
+ - interrupts: The interrupt number to the cpu. The interrupt specifier format
+	depends on the interrupt controller.
+
+Example:
+--------
+
+/* RK3368 */
+mbox: mbox at ff6b0000 {
+	compatible = "rockchip,rk3368-mailbox";
+	reg = <0x0 0xff6b0000 0x0 0x1000>,
+	      <0x0 0xff8cf000 0x0 0x1000>; /* the end 4k of sram */
+	interrupts = <GIC_SPI 146 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+	#mbox-cells = <1>;
+};
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH 1/3] dt-bindings: Add document of Rockchip mailbox

Quoted 22 lines · Caesar Wang

This add the necessary binding documentation for mailbox found on RK3368 SoC.

---

 .../bindings/mailbox/rockchip-mailbox.txt          | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +6 -0
new file mode 100644
index 0000000..b9b4768
@@ -0,0 +1,33 @@
+Rockchip mailbox
+
+The Rockchip mailbox is used by the Rockchip CPU cores to communicate
+requests to MCU processor.
+
+Refer to ./mailbox.txt for generic information about mailbox device-tree

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 16

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +10 -0
+bindings.
+
+Required properties:
+
+ - compatible: should be one of the following.
+   - "rockchip,rk3368-mbox" for rk3368
+ - reg: physical base address of the controller and length of memory mapped
+       region.
+       physical base address of the share buffer and length of memory mapped
+       region.

Please make shared-sram a property of user drivers.

Location and size of shared-memory is a platform property, mailbox controller doesn't need sram to function.
For example, protocol on some platform, with this controller, may be
trivial enough to not need a shared sram... say only 32-bits wide requests and responses which can be passed via mailbox registers
directly. mbox_client.tx_prepare() is where the user driver sets up
the shared-memory.

#3 lore raw

Re: [PATCH 1/3] dt-bindings: Add document of Rockchip mailbox

Hello Jassi,

Sorry for delay reply.
? 2015?10?06? 18:34, Jassi Brar ??:

Quoted 26 lines · Caesar Wang
Quoted 25 lines

This add the necessary binding documentation for mailbox found on RK3368 SoC.

---

  .../bindings/mailbox/rockchip-mailbox.txt          | 33 ++++++++++++++++++++++
  1 file changed, 33 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +9 -0
new file mode 100644
index 0000000..b9b4768
@@ -0,0 +1,33 @@
+Rockchip mailbox
+
+The Rockchip mailbox is used by the Rockchip CPU cores to communicate
+requests to MCU processor.
+
+Refer to ./mailbox.txt for generic information about mailbox device-tree
+bindings.
+
+Required properties:
Quoted 8 lines

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 16

Quoted 7 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +7 -0
+
+ - compatible: should be one of the following.
+   - "rockchip,rk3368-mbox" for rk3368
+ - reg: physical base address of the controller and length of memory mapped
+       region.
+       physical base address of the share buffer and length of memory mapped
+       region.

Please make shared-sram a property of user drivers.

As Rob points out,
maybe, don't we need also define it in user drivers. As the SRAM binding (misc/sram.txt) had defined.

I just make the SCPI protocol client driver to work for mailbox.

Quoted 13 lines

Location and size of shared-memory is a platform property, mailbox controller doesn't need sram to function.
For example, protocol on some platform, with this controller, may be
trivial enough to not need a shared sram... say only 32-bits wide requests and responses which can be passed via mailbox registers
directly. mbox_client.tx_prepare() is where the user driver sets up
the shared-memory.

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

Signature · 2 lines
Thanks,
Caesar
maintainer
#4 lore raw

Re: [PATCH 1/3] dt-bindings: Add document of Rockchip mailbox

In reply to Caesar Wang
Quoted 21 lines · Caesar Wang

This add the necessary binding documentation for mailbox found on RK3368 SoC.

---

 .../bindings/mailbox/rockchip-mailbox.txt          | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +5 -0
new file mode 100644
index 0000000..b9b4768
@@ -0,0 +1,33 @@
+Rockchip mailbox
+
+The Rockchip mailbox is used by the Rockchip CPU cores to communicate
+requests to MCU processor.
+

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 15

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +10 -0
+Refer to ./mailbox.txt for generic information about mailbox device-tree
+bindings.
+
+Required properties:
+
+ - compatible: should be one of the following.
+   - "rockchip,rk3368-mbox" for rk3368
+ - reg: physical base address of the controller and length of memory mapped
+       region.
+       physical base address of the share buffer and length of memory mapped

s/share/shared/

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 18

Quoted 3 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +3 -0
+       region.
+ - interrupts: The interrupt number to the cpu. The interrupt specifier format
+       depends on the interrupt controller.

Need to specify the value of #mbox-cells.

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 27

Quoted 9 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +9 -0
+
+Example:
+--------
+
+/* RK3368 */
+mbox: mbox at ff6b0000 {
+       compatible = "rockchip,rk3368-mailbox";
+       reg = <0x0 0xff6b0000 0x0 0x1000>,
+             <0x0 0xff8cf000 0x0 0x1000>; /* the end 4k of sram */

If this is just onchip SRAM usable for anything, then use the SRAM binding (misc/sram.txt). It has provisions for defining the use.

Quoted 9 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +6 -1
+       interrupts = <GIC_SPI 146 IRQ_TYPE_LEVEL_HIGH>,
+                    <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
+                    <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+                    <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+       #mbox-cells = <1>;
+};
--

1.9.1

#5 lore raw

Re: [PATCH 1/3] dt-bindings: Add document of Rockchip mailbox

I'm missing this patch for long time.

? 2015?10?06? 22:50, Rob Herring ??:

Quoted 25 lines · Caesar Wang
Quoted 24 lines

This add the necessary binding documentation for mailbox found on RK3368 SoC.

---

  .../bindings/mailbox/rockchip-mailbox.txt          | 33 ++++++++++++++++++++++
  1 file changed, 33 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +8 -0
new file mode 100644
index 0000000..b9b4768
@@ -0,0 +1,33 @@
+Rockchip mailbox
+
+The Rockchip mailbox is used by the Rockchip CPU cores to communicate
+requests to MCU processor.
+
+Refer to ./mailbox.txt for generic information about mailbox device-tree
+bindings.
+
Quoted 8 lines

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 15

Quoted 7 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +7 -0
+Required properties:
+
+ - compatible: should be one of the following.
+   - "rockchip,rk3368-mbox" for rk3368
+ - reg: physical base address of the controller and length of memory mapped
+       region.
+       physical base address of the share buffer and length of memory mapped

s/share/shared/

Done.

Quoted 5 lines

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 18

Quoted 4 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +3 -0
+       region.
+ - interrupts: The interrupt number to the cpu. The interrupt specifier format
+       depends on the interrupt controller.

Need to specify the value of #mbox-cells.

Done.

Quoted 11 lines

Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt line 27

Quoted 9 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +9 -0
+
+Example:
+--------
+
+/* RK3368 */
+mbox: mbox at ff6b0000 {
+       compatible = "rockchip,rk3368-mailbox";
+       reg = <0x0 0xff6b0000 0x0 0x1000>,
+             <0x0 0xff8cf000 0x0 0x1000>; /* the end 4k of sram */

If this is just onchip SRAM usable for anything, then use the SRAM binding (misc/sram.txt). It has provisions for defining the use.

Okay, we don't need define the shared-sram in this document.

Quoted 13 lines
Quoted 9 lines
Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt new file +6 -1
+       interrupts = <GIC_SPI 146 IRQ_TYPE_LEVEL_HIGH>,
+                    <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
+                    <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+                    <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+       #mbox-cells = <1>;
+};
--

1.9.1

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

Signature · 2 lines
Thanks,
Caesar
#6 lore raw

PATCH 2/3 mailbox: rockchip: Add Rockchip mailbox driver

In reply to Caesar Wang

This driver is found on RK3368 SoCs.

The Mailbox module is a simple APB peripheral that allows both the Cortex-A53 MCU system to communicate by writing operation to generate interrupt.
The registers are accessible by both CPU via APB interface.

The Mailbox has the following main features:

@ Support dual-core system: Cortex-A53 and MCU.
@ Support APB interface.
@ Support four mailbox elements, each element includes one data word, one
command word register and one flag bit that can represent one interrupt.
@ Four interrupts to Cortex-A53.
@ Four interrupts to MCU.
@ Provide 32 lock registers for software to use to indicate whether mailbox
is occupied.

---

 drivers/mailbox/Kconfig            |   9 ++
 drivers/mailbox/Makefile           |   2 +
 drivers/mailbox/rockchip-mailbox.c | 317 +++++++++++++++++++++++++++++++++++++
 3 files changed, 328 insertions(+)
 create mode 100644 drivers/mailbox/rockchip-mailbox.c
drivers/mailbox/Kconfig +9 -0
index bbec500..a548d700 100644
@@ -43,6 +43,15 @@ config OMAP_MBOX_KFIFO_SIZE
 	  This can also be changed at runtime (via the mbox_kfifo_size
 	  module parameter).
 
+config ROCKCHIP_MBOX
+	bool "Rockchip Soc Intergrated Mailbox Support"
+	depends on ARCH_ROCKCHIP
+	help
+	  This driver provides support for inter-processor communication
+	  between CPU cores and MCU processor on Some Rockchip SOCs.
+	  Please check it that the Soc you use have Mailbox hardware.
+	  Say Y here if you want to use the Rockchip Mailbox support.
+
 config PCC
 	bool "Platform Communication Channel Driver"
 	depends on ACPI
drivers/mailbox/Makefile +2 -0
index 8e6d822..730cb5d 100644
@@ -8,6 +8,8 @@ obj-$(CONFIG_PL320_MBOX)	+= pl320-ipc.o
 
 obj-$(CONFIG_OMAP2PLUS_MBOX)	+= omap-mailbox.o
 
+obj-$(CONFIG_ROCKCHIP_MBOX)	+= rockchip-mailbox.o
+
 obj-$(CONFIG_PCC)		+= pcc.o
 
 obj-$(CONFIG_ALTERA_MBOX)	+= mailbox-altera.o
drivers/mailbox/rockchip-mailbox.c new file +317 -0

317 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#7 lore raw

Re: [PATCH 2/3] mailbox: rockchip: Add Rockchip mailbox driver

Quoted 138 lines · Caesar Wang

This driver is found on RK3368 SoCs.

The Mailbox module is a simple APB peripheral that allows both the Cortex-A53 MCU system to communicate by writing operation to generate interrupt.
The registers are accessible by both CPU via APB interface.

The Mailbox has the following main features:

@ Support dual-core system: Cortex-A53 and MCU.
@ Support APB interface.
@ Support four mailbox elements, each element includes one data word, one
command word register and one flag bit that can represent one interrupt.
@ Four interrupts to Cortex-A53.
@ Four interrupts to MCU.
@ Provide 32 lock registers for software to use to indicate whether mailbox
is occupied.

---

 drivers/mailbox/Kconfig            |   9 ++
 drivers/mailbox/Makefile           |   2 +
 drivers/mailbox/rockchip-mailbox.c | 317 +++++++++++++++++++++++++++++++++++++
 3 files changed, 328 insertions(+)
 create mode 100644 drivers/mailbox/rockchip-mailbox.c
drivers/mailbox/Kconfig +9 -0
index bbec500..a548d700 100644
@@ -43,6 +43,15 @@ config OMAP_MBOX_KFIFO_SIZE
          This can also be changed at runtime (via the mbox_kfifo_size
          module parameter).
 
+config ROCKCHIP_MBOX
+       bool "Rockchip Soc Intergrated Mailbox Support"
+       depends on ARCH_ROCKCHIP
+       help
+         This driver provides support for inter-processor communication
+         between CPU cores and MCU processor on Some Rockchip SOCs.
+         Please check it that the Soc you use have Mailbox hardware.
+         Say Y here if you want to use the Rockchip Mailbox support.
+
 config PCC
        bool "Platform Communication Channel Driver"
        depends on ACPI
drivers/mailbox/Makefile +2 -0
index 8e6d822..730cb5d 100644
@@ -8,6 +8,8 @@ obj-$(CONFIG_PL320_MBOX)        += pl320-ipc.o
 
 obj-$(CONFIG_OMAP2PLUS_MBOX)   += omap-mailbox.o
 
+obj-$(CONFIG_ROCKCHIP_MBOX)    += rockchip-mailbox.o
+
 obj-$(CONFIG_PCC)              += pcc.o
 
 obj-$(CONFIG_ALTERA_MBOX)      += mailbox-altera.o
drivers/mailbox/rockchip-mailbox.c new file +72 -0
new file mode 100644
index 0000000..715ab96
@@ -0,0 +1,317 @@
+/*
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Authors:    Addy Ke <[email protected]>
+ *             Caesar Wang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mailbox_controller.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#define MAILBOX_A2B_INTEN              0x00
+#define MAILBOX_A2B_STATUS             0x04
+#define MAILBOX_A2B_CMD(x)             (0x08 + (x) * 8)
+#define MAILBOX_A2B_DAT(x)             (0x0c + (x) * 8)
+
+#define MAILBOX_B2A_INTEN              0x28
+#define MAILBOX_B2A_STATUS             0x2C
+#define MAILBOX_B2A_CMD(x)             (0x30 + (x) * 8)
+#define MAILBOX_B2A_DAT(x)             (0x34 + (x) * 8)
+
+#define MAILBOX_ATOMIC_LOCK(x)         (0x100 + (x) * 8)
+
+/* A2B: 0 - 2k */
+#define A2B_BUF(size, idx)             ((idx) * (size))
+
+/* B2A: 2k - 4k */
+#define B2A_BUF(size, idx)             (((idx) + 4) * (size))
+
+struct rockchip_mbox_msg {
+       u32 cmd;
+       int tx_size;
+       void *tx_buf;
+       int rx_size;
+       void *rx_buf;
+       void *cl_data;
+};
+
+struct rockchip_mbox_data {
+       int num_chans;
+};
+
+struct rockchip_mbox_chan {
+       int idx;
+       int irq;
+       struct rockchip_mbox_msg *msg;
+       struct rockchip_mbox *mb;
+};
+
+struct rockchip_mbox {
+       struct mbox_controller mbox;
+       struct clk *pclk;
+       void __iomem *mbox_base;
+
+       /* The base address of share memory to transfer data */
+       void __iomem *buf_base;
+
+       /* The maximum size of buf for each channel */

drivers/mailbox/rockchip-mailbox.c line 82

Quoted 10 lines
drivers/mailbox/rockchip-mailbox.c new file +10 -0
+       u32 buf_size;
+
+       struct rockchip_mbox_chan *chans;
+};
+
+static inline int chan_to_idx(struct rockchip_mbox *mb,
+                             struct mbox_chan *chan)
+{
+       return (chan - mb->mbox.chans);
+}

perhaps you intended rockchip_mbox_chan.idx for this purpose?

Quoted 15 lines
drivers/mailbox/rockchip-mailbox.c new file +15 -0
+static int rockchip_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+       struct rockchip_mbox *mb = dev_get_drvdata(chan->mbox->dev);
+       struct rockchip_mbox_msg *msg = data;
+       int idx = chan_to_idx(mb, chan);
+
+       if (!msg)
+               return -EINVAL;
+
+       if ((msg->tx_size > mb->buf_size) ||
+           (msg->rx_size > mb->buf_size)) {
+               dev_err(mb->mbox.dev, "Transmit size over buf size(%d)\n",
+                       mb->buf_size);
+               return -EINVAL;
+       }

drivers/mailbox/rockchip-mailbox.c line 108

Quoted 10 lines
drivers/mailbox/rockchip-mailbox.c new file +10 -0
+
+       dev_dbg(mb->mbox.dev, "Chan[%d]: A2B message, cmd 0x%08x\n",
+               idx, msg->cmd);
+
+       mb->chans[idx].msg = msg;
+
+       if (msg->tx_buf)
+               memcpy(mb->buf_base + A2B_BUF(mb->buf_size, idx),
+                      msg->tx_buf, msg->tx_size);
+

as I said on the bindings patch, this should be done by client driver in tx_prepare() callback.

drivers/mailbox/rockchip-mailbox.c line 111

Quoted 3 lines
drivers/mailbox/rockchip-mailbox.c new file +3 -0
+       writel_relaxed(msg->cmd, mb->mbox_base + MAILBOX_A2B_CMD(idx));
+       writel_relaxed(msg->rx_size, mb->mbox_base + MAILBOX_A2B_DAT(idx));
+

Usually length of payload is not specified via mailbox registers but we have to live with what your protocol does... so maybe keep rx_size in rockchip_mbox_msg but remove tx_size, tx_buf, void *rx_buf, and cl_data

drivers/mailbox/rockchip-mailbox.c line 118

Quoted 7 lines
drivers/mailbox/rockchip-mailbox.c new file +7 -0
+       return 0;
+}
+
+static int rockchip_mbox_startup(struct mbox_chan *chan)
+{
+       return 0;
+}

maybe request the channel irq in startup and release in shutdown ?

#8 lore raw

Re: [PATCH 2/3] mailbox: rockchip: Add Rockchip mailbox driver

Hi Jassi,

Thanks for your comments.

Quoted 142 lines · Jassi Brar
Quoted 141 lines · Caesar Wang

This driver is found on RK3368 SoCs.

The Mailbox module is a simple APB peripheral that allows both the Cortex-A53 MCU system to communicate by writing operation to generate interrupt.
The registers are accessible by both CPU via APB interface.

The Mailbox has the following main features:

@ Support dual-core system: Cortex-A53 and MCU.
@ Support APB interface.
@ Support four mailbox elements, each element includes one data word, one
command word register and one flag bit that can represent one interrupt.
@ Four interrupts to Cortex-A53.
@ Four interrupts to MCU.
@ Provide 32 lock registers for software to use to indicate whether mailbox
is occupied.

---

  drivers/mailbox/Kconfig            |   9 ++
  drivers/mailbox/Makefile           |   2 +
  drivers/mailbox/rockchip-mailbox.c | 317 +++++++++++++++++++++++++++++++++++++
  3 files changed, 328 insertions(+)

create mode 100644 drivers/mailbox/rockchip-mailbox.c

drivers/mailbox/Kconfig +9 -0
index bbec500..a548d700 100644
@@ -43,6 +43,15 @@ config OMAP_MBOX_KFIFO_SIZE
           This can also be changed at runtime (via the mbox_kfifo_size
           module parameter).
 
+config ROCKCHIP_MBOX
+       bool "Rockchip Soc Intergrated Mailbox Support"
+       depends on ARCH_ROCKCHIP
+       help
+         This driver provides support for inter-processor communication
+         between CPU cores and MCU processor on Some Rockchip SOCs.
+         Please check it that the Soc you use have Mailbox hardware.
+         Say Y here if you want to use the Rockchip Mailbox support.
+
  config PCC
         bool "Platform Communication Channel Driver"
         depends on ACPI
drivers/mailbox/Makefile +2 -0
index 8e6d822..730cb5d 100644
@@ -8,6 +8,8 @@ obj-$(CONFIG_PL320_MBOX)        += pl320-ipc.o
 
  obj-$(CONFIG_OMAP2PLUS_MBOX)   += omap-mailbox.o
 
+obj-$(CONFIG_ROCKCHIP_MBOX)    += rockchip-mailbox.o
+
  obj-$(CONFIG_PCC)              += pcc.o
 
  obj-$(CONFIG_ALTERA_MBOX)      += mailbox-altera.o
drivers/mailbox/rockchip-mailbox.c new file +75 -0
new file mode 100644
index 0000000..715ab96
@@ -0,0 +1,317 @@
+/*
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Authors:    Addy Ke <[email protected]>
+ *             Caesar Wang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mailbox_controller.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#define MAILBOX_A2B_INTEN              0x00
+#define MAILBOX_A2B_STATUS             0x04
+#define MAILBOX_A2B_CMD(x)             (0x08 + (x) * 8)
+#define MAILBOX_A2B_DAT(x)             (0x0c + (x) * 8)
+
+#define MAILBOX_B2A_INTEN              0x28
+#define MAILBOX_B2A_STATUS             0x2C
+#define MAILBOX_B2A_CMD(x)             (0x30 + (x) * 8)
+#define MAILBOX_B2A_DAT(x)             (0x34 + (x) * 8)
+
+#define MAILBOX_ATOMIC_LOCK(x)         (0x100 + (x) * 8)
+
+/* A2B: 0 - 2k */
+#define A2B_BUF(size, idx)             ((idx) * (size))
+
+/* B2A: 2k - 4k */
+#define B2A_BUF(size, idx)             (((idx) + 4) * (size))
+
+struct rockchip_mbox_msg {
+       u32 cmd;
+       int tx_size;
+       void *tx_buf;
+       int rx_size;
+       void *rx_buf;
+       void *cl_data;
+};
+
+struct rockchip_mbox_data {
+       int num_chans;
+};
+
+struct rockchip_mbox_chan {
+       int idx;
+       int irq;
+       struct rockchip_mbox_msg *msg;
+       struct rockchip_mbox *mb;
+};
+
+struct rockchip_mbox {
+       struct mbox_controller mbox;
+       struct clk *pclk;
+       void __iomem *mbox_base;
+
+       /* The base address of share memory to transfer data */
+       void __iomem *buf_base;
+
+       /* The maximum size of buf for each channel */
+       u32 buf_size;
+
+       struct rockchip_mbox_chan *chans;
Quoted 9 lines

drivers/mailbox/rockchip-mailbox.c line 82

Quoted 7 lines
drivers/mailbox/rockchip-mailbox.c new file +7 -0
+};
+
+static inline int chan_to_idx(struct rockchip_mbox *mb,
+                             struct mbox_chan *chan)
+{
+       return (chan - mb->mbox.chans);
+}

perhaps you intended rockchip_mbox_chan.idx for this purpose?

Done,
Fixed in next version v1.

Quoted 19 lines
Quoted 19 lines
drivers/mailbox/rockchip-mailbox.c new file +19 -0
+static int rockchip_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+       struct rockchip_mbox *mb = dev_get_drvdata(chan->mbox->dev);
+       struct rockchip_mbox_msg *msg = data;
+       int idx = chan_to_idx(mb, chan);
+
+       if (!msg)
+               return -EINVAL;
+
+       if ((msg->tx_size > mb->buf_size) ||
+           (msg->rx_size > mb->buf_size)) {
+               dev_err(mb->mbox.dev, "Transmit size over buf size(%d)\n",
+                       mb->buf_size);
+               return -EINVAL;
+       }
+
+       dev_dbg(mb->mbox.dev, "Chan[%d]: A2B message, cmd 0x%08x\n",
+               idx, msg->cmd);
+
Quoted 8 lines

drivers/mailbox/rockchip-mailbox.c line 108

Quoted 6 lines
drivers/mailbox/rockchip-mailbox.c new file +6 -0
+       mb->chans[idx].msg = msg;
+
+       if (msg->tx_buf)
+               memcpy(mb->buf_base + A2B_BUF(mb->buf_size, idx),
+                      msg->tx_buf, msg->tx_size);
+

as I said on the bindings patch, this should be done by client driver in tx_prepare() callback.

Okay, so I should do that in client driver since I'm ready sent the client driver with scpi protocol, I found the similar driver in LKML.

mailbox: add support for System Control and Power Interface(SCPI) protocol
https://patchwork.kernel.org/patch/6279371/

I will pick up this driver with my client driver for later or another patchs.

Quoted 7 lines

drivers/mailbox/rockchip-mailbox.c line 111

Quoted 3 lines
drivers/mailbox/rockchip-mailbox.c new file +3 -0
+       writel_relaxed(msg->cmd, mb->mbox_base + MAILBOX_A2B_CMD(idx));
+       writel_relaxed(msg->rx_size, mb->mbox_base + MAILBOX_A2B_DAT(idx));
+

Usually length of payload is not specified via mailbox registers but we have to live with what your protocol does... so maybe keep rx_size in rockchip_mbox_msg but remove tx_size, tx_buf, void *rx_buf, and cl_data

Done.

Quoted 9 lines

drivers/mailbox/rockchip-mailbox.c line 118

Quoted 8 lines
drivers/mailbox/rockchip-mailbox.c new file +7 -0
+       return 0;
+}
+
+static int rockchip_mbox_startup(struct mbox_chan *chan)
+{
+       return 0;
+}

maybe request the channel irq in startup and release in shutdown ?

Here, I think the devm_request_threaded_irq() can also put in probe(), And I change the enable/disable interrupts for startup/shundown.

Quoted 4 lines

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

Signature · 2 lines
Thanks,
Caesar
#9 lore raw

PATCH 3/3 ARM64: dts: rk3368: Add mailbox device nodes

In reply to Caesar Wang

This adds mailbox device nodes in dts.

mailbox is used by the Rockchip CPU cores to communicate requests to MCU processormZ

---

 arch/arm64/boot/dts/rockchip/rk3368.dtsi | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/arm64/boot/dts/rockchip/rk3368.dtsi +13 -0
index a712bea..9ac5cca 100644
@@ -484,6 +484,19 @@
 		status = "disabled";
 	};
 
+	mbox: mbox at ff6b0000 {
+		compatible = "rockchip,rk3368-mailbox";
+		reg = <0x0 0xff6b0000 0x0 0x1000>,
+		      <0x0 0xff8cf000 0x0 0x1000>; /* the end 4k of sram */
+		interrupts = <GIC_SPI 146 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru PCLK_MAILBOX>;
+		clock-names = "pclk_mailbox";
+		#mbox-cells = <1>;
+	};
+
 	pmugrf: syscon at ff738000 {
 		compatible = "rockchip,rk3368-pmugrf", "syscon";
 		reg = <0x0 0xff738000 0x0 0x1000>;
Signature · 1 line
1.9.1
#10 lore raw
In reply to Caesar Wang

Hello Jassi,

Friendly Ping!

Could you review this series patchs if you have free time?

? 2015?09?14? 19:06, Caesar Wang ??:

Quoted 28 lines

Mailbox is used by the Rockchip CPU cores to communicate requests to MCU processorm.

This driver is found on RK3368 SoCs.

The Mailbox module is a simple APB peripheral that allows both the Cortex-A53 MCU system to communicate by writing operation to generate interrupt.
The registers are accessible by both CPU via APB interface.

Tested on RK3368 SDK board.

Caesar Wang (3):
dt-bindings: Add document of Rockchip mailbox
mailbox: rockchip: Add Rockchip mailbox driver
ARM64: dts: rk3368: Add mailbox device nodes

  .../bindings/mailbox/rockchip-mailbox.txt          |  33 +++
  arch/arm64/boot/dts/rockchip/rk3368.dtsi           |  13 +
  drivers/mailbox/Kconfig                            |   9 +
  drivers/mailbox/Makefile                           |   2 +
  drivers/mailbox/rockchip-mailbox.c                 | 317 +++++++++++++++++++++
  5 files changed, 374 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mailbox/rockchip-mailbox.txt create mode 100644 drivers/mailbox/rockchip-mailbox.c

Signature · 2 lines
Thanks,
Caesar
maintainer
#11 lore raw
Quoted 6 lines · Caesar Wang

Hello Jassi,

Friendly Ping!

Could you review this series patchs if you have free time?

It's been only 2 weeks since you posted the driver and I have been busy with stuff that missed the last release. I did not miss your patchset.

-Jassi