add mailbox support for i.MX7D
Subsystems (3)
v6 cover add mailbox support for i.MX7D
20180622 changes v6:
- include one more patch provided by Aisheng
- DT: add fall back compatible fsl,imx6sx-mu
- imx-mailbox: for now, use only fsl,imx6sx-mu
20180621 changes v5:
- DT: revert most of the changes from previous version
- imx-mailbox: remove struct imx_mu_cfg
- imx-mailbox: remove !! from imx_mu_last_tx_done()
20180618 changes v4:
- DT: change fsl,mu-side-a to fsl,mu-side-b
- DT: split the patches.
- DT: add all currently known SoCs.
- imx-mailbox: free allocated irq name on channel shutdown
- imx-mailbox: rename *_imx7 functions to *_generic
20180615 changes v3:
- DT: remove prosaic part of documentation. It describes software or firmware specific usage and not relevant for HW description.
- DT: use <soc>-mu instead of <soc>-mu-<mu side> and add fsl,mu-side-a parameter.
- DT: add most of know i.MX variants with MU
- imx-mailbox: use macros instead of precalculated bit index.
- imx-mailbox: remove warning message for clk.
- imx-mailbox: use imx_mu_chan[%idx] for devm_request_irq.
- imx-mailbox: depend on ARCH_MXC instead of SOX_IMX7
20180615 changes v2:
- DT: use mailbox@ instead of mu@
- DT: change interrupts description
- clk: use imx_clk_gate4 instead of imx_clk_gate2
- imx-mailbox: remove last_tx_done support
- imx-mailbox: fix module description
This patches are providing support for mailbox (Messaging Unit) for i.MX7D.
Functionality was tested on PHYTEC phyBOARD-Zeta i.MX7D with Linux running on all cores: ARM Cortex-A7 and ARM Cortex-M4.
Both parts of i.MX messaging Unit are visible for all CPUs available on i.MX7D. Communication worked independent of MU side in combination with CPU. For example MU-A used on ARM Cortex-A7 and MU-B used on ARM Cortex-M4 or other ways around.
Dong Aisheng (2):
dt-bindings: mailbox: allow mbox-cells to be equal to 0
dt-bindings: arm: fsl: add mu binding doc
Oleksij Rempel (3):
dt-bindings: mailbox: imx-mu: add generic MU channel support
ARM: dts: imx7s: add i.MX7 messaging unit support
mailbox: Add support for i.MX7D messaging unit
.../devicetree/bindings/mailbox/fsl,mu.txt | 41 +++ .../devicetree/bindings/mailbox/mailbox.txt | 3 +- arch/arm/boot/dts/imx7s.dtsi | 19 ++ drivers/mailbox/Kconfig | 6 + drivers/mailbox/Makefile | 2 + drivers/mailbox/imx-mailbox.c | 273 ++++++++++++++++++ 6 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/mailbox/fsl,mu.txt create mode 100644 drivers/mailbox/imx-mailbox.c
Signature · 1 line
2.18.0
PATCH v6 1/5 dt-bindings: mailbox: allow mbox-cells to be equal to 0
From: Dong Aisheng <[email protected]>
Mailbox devices may have only one channel which means the mbox-cells at least 1 does not make sense for this type devices. Let's remove that limitation to allow the mbox-cells to be equal to 0.
--- Documentation/devicetree/bindings/mailbox/mailbox.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/mailbox/mailbox.txt +1 -2
@@ -6,8 +6,7 @@ assign appropriate mailbox channel to client drivers. * Mailbox Controller Required property: -- #mbox-cells: Must be at least 1. Number of cells in a mailbox - specifier. +- #mbox-cells: Number of cells in a mailbox specifier. Example: mailbox: mailbox {
Signature · 1 line
2.18.0
PATCH v6 2/5 dt-bindings: arm: fsl: add mu binding doc
In reply to Oleksij RempelFrom: Dong Aisheng <[email protected]>
The Messaging Unit module enables two processors within the SoC to communicate and coordinate by passing messages (e.g. data, status and control) through the MU interface.
--- .../devicetree/bindings/mailbox/fsl,mu.txt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/fsl,mu.txt
Documentation/devicetree/bindings/mailbox/fsl,mu.txt new file +34 -0
@@ -0,0 +1,34 @@ +NXP i.MX Messaging Unit (MU) +-------------------------------------------------------------------- + +The Messaging Unit module enables two processors within the SoC to +communicate and coordinate by passing messages (e.g. data, status +and control) through the MU interface. The MU also provides the ability +for one processor to signal the other processor using interrupts. + +Because the MU manages the messaging between processors, the MU uses +different clocks (from each side of the different peripheral buses). +Therefore, the MU must synchronize the accesses from one side to the +other. The MU accomplishes synchronization using two sets of matching +registers (Processor A-facing, Processor B-facing). + +Messaging Unit Device Node: +============================= + +Required properties: +------------------- +- compatible : should be "fsl,<chip>-mu", the supported chips include + imx8qxp, imx8qm. +- reg : Should contain the registers location and length +- interrupts : Interrupt number. The interrupt specifier format depends + on the interrupt controller parent. +- #mbox-cells: Must be 0. Number of cells in a mailbox + +Examples: +-------- +lsio_mu0: mailbox at 5d1b0000 { + compatible = "fsl,imx8qxp-mu"; + reg = <0x0 0x5d1b0000 0x0 0x10000>; + interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>; + #mbox-cells = <0>; +};
Signature · 1 line
2.18.0
PATCH v6 3/5 dt-bindings: mailbox: imx-mu: add generic MU channel support
In reply to Oleksij RempelEach MU has four pairs of rx/tx data register with four rx/tx interrupts which can also be used as a separate channel.
--- Documentation/devicetree/bindings/mailbox/fsl,mu.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mailbox/fsl,mu.txt +8 -1
@@ -22,7 +22,14 @@ Required properties: - reg : Should contain the registers location and length - interrupts : Interrupt number. The interrupt specifier format depends on the interrupt controller parent. -- #mbox-cells: Must be 0. Number of cells in a mailbox +- #mbox-cells: Must be: + 0 - for single channel mode. i.MX8* SCU protocol specific. + 1 - for multichannel (generic) mode. + +Optional properties: +------------------- +- clocks : phandle to the input clock. +- fsl,mu-side-b : Should be set for side B MU. Examples: --------
Signature · 1 line
2.18.0
Rob Herring
maintainerPATCH v6 3/5 dt-bindings: mailbox: imx-mu: add generic MU channel support
Quoted 8 lines · Oleksij Rempel
Each MU has four pairs of rx/tx data register with four rx/tx interrupts which can also be used as a separate channel.
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>--- Documentation/devicetree/bindings/mailbox/fsl,mu.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
PATCH v6 4/5 ARM: dts: imx7s: add i.MX7 messaging unit support
In reply to Oleksij RempelDefine the Messaging Unit (MU) for i.MX7 in the processor's dtsi. The respective driver is added in the next commit.
--- arch/arm/boot/dts/imx7s.dtsi | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/arm/boot/dts/imx7s.dtsi +19 -0
@@ -1001,6 +1001,25 @@ status = "disabled"; }; + mu0a: mailbox at 30aa0000 { + compatible = "fsl,imx7s-mu", "fsl,imx6sx-mu"; + reg = <0x30aa0000 0x10000>; + interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks IMX7D_MU_ROOT_CLK>; + #mbox-cells = <1>; + status = "disabled"; + }; + + mu0b: mailbox at 30ab0000 { + compatible = "fsl,imx7s-mu", "fsl,imx6sx-mu"; + reg = <0x30ab0000 0x10000>; + interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks IMX7D_MU_ROOT_CLK>; + #mbox-cells = <1>; + fsl,mu-side-b; + status = "disabled"; + }; + usbotg1: usb at 30b10000 { compatible = "fsl,imx7d-usb", "fsl,imx27-usb"; reg = <0x30b10000 0x200>;
Signature · 1 line
2.18.0
PATCH v6 4/5 ARM: dts: imx7s: add i.MX7 messaging unit support
Am Sonntag, den 22.07.2018, 08:39 +0200 schrieb Oleksij Rempel:
Quoted 18 lines
Define the Messaging Unit (MU) for i.MX7 in the processor's dtsi. The respective driver is added in the next commit.
Quoted 2 lines
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>---
?arch/arm/boot/dts/imx7s.dtsi | 19 +++++++++++++++++++ ?1 file changed, 19 insertions(+)arch/arm/boot/dts/imx7s.dtsi +0
-0@@ -1001,6 +1001,25 @@ > ? status = "disabled"; > ? };?
Quoted 1 line
Quoted 1 line
arch/arm/boot/dts/imx7s.dtsi +1
-0+ mu0a: mailbox at 30aa0000 {
arch/arm/boot/dts/imx7s.dtsi
Quoted 1 line
arch/arm/boot/dts/imx7s.dtsi +1
-0+ compatible = "fsl,imx7s-mu", "fsl,imx6sx-mu";
Those compatibles are missing documentation in the binding.
Quoted 20 lines
arch/arm/boot/dts/imx7s.dtsi +1
-0+ reg = <0x30aa0000 0x10000>;arch/arm/boot/dts/imx7s.dtsi line 1011
Quoted 5 lines
arch/arm/boot/dts/imx7s.dtsi +5
-0+ interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks IMX7D_MU_ROOT_CLK>; + #mbox-cells = <1>; + status = "disabled"; + };+
arch/arm/boot/dts/imx7s.dtsi line 1021
Quoted 9 lines
Quoted 1 line
arch/arm/boot/dts/imx7s.dtsi +1
-0+ mu0b: mailbox at 30ab0000 {arch/arm/boot/dts/imx7s.dtsi +8
-0+ compatible = "fsl,imx7s-mu", "fsl,imx6sx-mu"; + reg = <0x30ab0000 0x10000>; + interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks IMX7D_MU_ROOT_CLK>; + #mbox-cells = <1>; + fsl,mu-side-b; + status = "disabled"; + };+
Quoted 3 lines
Quoted 1 line
? usbotg1: usb at
30b10000{? compatible = "fsl,imx7d-usb", "fsl,imx27-usb";
? reg = <0x30b100000x200>;
PATCH v6 4/5 ARM: dts: imx7s: add i.MX7 messaging unit support
Quoted 28 lines
-----Original Message-----
From: Lucas Stach [mailto:l.stach at pengutronix.de]
Sent: Tuesday, July 24, 2018 12:57 AM
To: Oleksij Rempel <[email protected]>; Shawn Guo <[email protected]>; Fabio Estevam <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; A.s. Dong <[email protected]>; Vladimir Zapolskiy <[email protected]>
Cc: dl-linux-imx <[email protected]>; linux-arm-kernel at lists.infradead.org; kernel at pengutronix.de; devicetree at vger.kernel.org
Subject: Re: [PATCH v6 4/5] ARM: dts: imx7s: add i.MX7 messaging unit supportAm Sonntag, den 22.07.2018, 08:39 +0200 schrieb Oleksij Rempel:
Quoted 14 lines
Define the Messaging Unit (MU) for i.MX7 in the processor's dtsi. The respective driver is added in the next commit.
Quoted 2 lines
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>---
?arch/arm/boot/dts/imx7s.dtsi | 19 +++++++++++++++++++ ?1 file changed, 19 insertions(+)(quoted diff) +0
-0
b/arch/arm/boot/dts/imx7s.dtsiindexce85b3ca1a55..191a0286fa3b100644arch/arm/boot/dts/imx7s.dtsi +0
-0@@ -1001,6 +1001,25 @@
Quoted 8 lines
arch/arm/boot/dts/imx7s.dtsi line 1005
Quoted 5 lines
arch/arm/boot/dts/imx7s.dtsi +1
-0> ? status = "disabled"; > ? }; > > + mu0a: mailbox at 30aa0000 { + compatible = "fsl,imx7s-mu", "fsl,imx6sx-mu";Those compatibles are missing documentation in the binding.
Sorry for the overlooking.
They seem to be got missed during a updated binding doc review.
Oleksij,
Would you add them back and resend the patch series?
Regards
Dong Aisheng
Quoted 22 lines
Quoted 2 lines
arch/arm/boot/dts/imx7s.dtsi +1
-0+ reg = <0x30aa0000 0x10000>;Review
Quoted 1 line
(quoted diff) +1
-0+ interrupts = <GIC_SPI 88
IRQ_TYPE_LEVEL_HIGH>;Quoted 9 lines
arch/arm/boot/dts/imx7s.dtsi line 1011
Quoted 4 lines
arch/arm/boot/dts/imx7s.dtsi +4
-0+ clocks = <&clks IMX7D_MU_ROOT_CLK>; + #mbox-cells = <1>; + status = "disabled"; + };+
arch/arm/boot/dts/imx7s.dtsi
Quoted 4 lines
Quoted 1 line
arch/arm/boot/dts/imx7s.dtsi +1
-0+ mu0b: mailbox at 30ab0000 {arch/arm/boot/dts/imx7s.dtsi +3
-0+ compatible = "fsl,imx7s-mu", "fsl,imx6sx-mu"; + reg = <0x30ab0000 0x10000>; + interrupts = <GIC_SPI 97
IRQ_TYPE_LEVEL_HIGH>;Quoted 9 lines
arch/arm/boot/dts/imx7s.dtsi line 1021
Quoted 5 lines
arch/arm/boot/dts/imx7s.dtsi +5
-0+ clocks = <&clks IMX7D_MU_ROOT_CLK>; + #mbox-cells = <1>; + fsl,mu-side-b; + status = "disabled"; + };+
Quoted 3 lines
Quoted 1 line
? usbotg1: usb at
30b10000{? compatible = "fsl,imx7d-usb", "fsl,imx27-usb";
? reg = <0x30b100000x200>;
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
In reply to Oleksij RempelThe Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
--- drivers/mailbox/Kconfig | 6 + drivers/mailbox/Makefile | 2 + drivers/mailbox/imx-mailbox.c | 273 ++++++++++++++++++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 drivers/mailbox/imx-mailbox.c
drivers/mailbox/Kconfig +6 -0
@@ -15,6 +15,12 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config IMX_MBOX + tristate "i.MX Mailbox" + depends on ARCH_MXC || COMPILE_TEST + help + Mailbox implementation for i.MX Messaging Unit (MU). + config PLATFORM_MHU tristate "Platform MHU Mailbox" depends on OF
drivers/mailbox/Makefile +2 -0
@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o + obj-$(CONFIG_PLATFORM_MHU) += platform_mhu.o obj-$(CONFIG_PL320_MBOX) += pl320-ipc.o
drivers/mailbox/imx-mailbox.c new file +273 -0
273 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
Am Sonntag, den 22.07.2018, 08:39 +0200 schrieb Oleksij Rempel:
Quoted 105 lines
The Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
Quoted 2 lines
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>---
?drivers/mailbox/Kconfig???????|???6 + ?drivers/mailbox/Makefile??????|???2 + ?drivers/mailbox/imx-mailbox.c | 273 ++++++++++++++++++++++++++++++++++?3 files changed, 281 insertions(+)
?create mode 100644drivers/mailbox/imx-mailbox.cdrivers/mailbox/Kconfig +0
-0@@ -15,6 +15,12 @@ config ARM_MHUQuoted 2 lines
? ??The controller has 3 mailbox channels, the last of which can be
? ??used in Secure mode only.?
+configIMX_MBOXdrivers/mailbox/Kconfig config ARM_MHU
Quoted 4 lines
drivers/mailbox/Kconfig +4
-0+ tristate "i.MX Mailbox" + depends on ARCH_MXC || COMPILE_TEST + help + ??Mailbox implementation for i.MX Messaging Unit (MU).+
?configPLATFORM_MHUQuoted 2 lines
? tristate "Platform MHU Mailbox"
? depends on OFdrivers/mailbox/Makefile +0
-0Review obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o
Quoted 1 line
(quoted diff) +0
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o?
Quoted 1 line
?obj-$(CONFIG_ARM_MHU) += arm_mhu.o
?
Quoted 1 line
+obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o
+
Quoted 1 line
?obj-$(CONFIG_PLATFORM_MHU) += platform_mhu.o
?
Quoted 1 line
?obj-$(CONFIG_PL320_MBOX) += pl320-ipc.o
drivers/mailbox/imx-mailbox.c new file +14
-0@@ -0,0 +1,273 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018 Pengutronix, Oleksij Rempel <[email protected]> +*/ + +#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> + +/* Transmit Register */ Quoted 1 line
+#define
IMX_MU_xTRn(x)(0x00+ 4 * (x))+/* Receive Register */
Quoted 1 line
+#define
IMX_MU_xRRn(x)(0x10+ 4 * (x))+/* Status Register */
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+#define IMX_MU_xSR 0x20 +#define IMX_MU_xSR_TEn (x) BIT(20 + (3 - (x))) +#define IMX_MU_xSR_RFn (x) BIT(24 + (3 - (x))) +#define IMX_MU_xSR_BRDIP BIT(9)drivers/mailbox/imx-mailbox.c new file +2
-0+ +/* Control Register */ Quoted 1 line
+#define
IMX_MU_xCR0x24+/* Transmit Interrupt Enable */
Quoted 1 line
+#define
IMX_MU_xCR_TIEn(x)BIT(20 + (3 - (x)))+/* Receive Interrupt Enable */
Quoted 1 line
+#define
IMX_MU_xCR_RIEn(x)BIT(24 + (3 - (x)))+
Quoted 1 line
+#define
IMX_MU_CHANS4udrivers/mailbox/imx-mailbox.c new file +2
-0+ +struct imx_mu_con_priv {Quoted 3 lines
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+int irq; +unsigned int idx; +char *irq_desc;drivers/mailbox/imx-mailbox.c new file +3
-0+}; + +struct imx_mu_priv {Quoted 2 lines
drivers/mailbox/imx-mailbox.c line 41
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+struct device *dev; +void __iomem *base;+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c line 44
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+struct mbox_controller mbox; +struct mbox_chan mbox_chans[IMX_MU_CHANS ];+
Quoted 2 lines
(quoted diff) +1
-0+ struct imx_mu_con_priv??con_priv[IMX_MU_CHANS];drivers/mailbox/imx-mailbox.c line 47
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+struct clk *clk;+
Quoted 1 line
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+bool side_b;drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static struct imx_mu_priv *to_imx_mu_priv (struct mbox_controller *mbox) +{Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ return container_of(mbox, struct imx_mu_priv, mbox);
drivers/mailbox/imx-mailbox.c line 59
Quoted 5 lines
drivers/mailbox/imx-mailbox.c new file +5
-0+} + +static void imx_mu_write (struct imx_mu_priv *priv,u32 val,u32 offs) +{ +iowrite32 (val, priv->base + offs);
This driver is never going to be used on a device with port based IO, so iowrite doesn't make much sense here, just use writel. Same comment applies to the below read function.
Also, given that those functions are not really shortening the code in the user they may also be removed completely IMHO.
Quoted 54 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static u32 imx_mu_read (struct imx_mu_priv *priv,u32 offs) +{Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return ioread32 (priv->base + offs);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static u32 imx_mu_rmw (struct imx_mu_priv *priv,u32 offs,u32 set,u32 clr) +{Review
Quoted 1 line
(quoted diff) +1
-0+ u32 val;+
drivers/mailbox/imx-mailbox.c line 74
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ val =imx_mu_read (priv, offs); + val &= ~clr; + val |= set; +imx_mu_write (priv, val, offs);+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return val;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static irqreturn_t imx_mu_isr (int irq,void *p) +{drivers/mailbox/imx-mailbox.c line 84
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+struct mbox_chan *chan = p; +struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 val, ctrl, dat;+
drivers/mailbox/imx-mailbox.c line 91
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+ ctrl =imx_mu_read (priv, IMX_MU_xCR); + val =imx_mu_read (priv, IMX_MU_xSR); + val &=IMX_MU_xSR_TEn (cp->idx) |IMX_MU_xSR_RFn (cp->idx); + val &= ctrl & (IMX_MU_xCR_TIEn (cp->idx) |IMX_MU_xCR_RIEn (cp->idx)); +if (!val) +return IRQ_NONE ;+
drivers/mailbox/imx-mailbox.c line 96
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+if (val &IMX_MU_xSR_TEn (cp->idx)) { +imx_mu_rmw (priv, IMX_MU_xCR,0 ,IMX_MU_xCR_TIEn (cp->idx)); +mbox_chan_txdone (chan,0 ); + }+
drivers/mailbox/imx-mailbox.c line 101
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+if (val &IMX_MU_xSR_RFn (cp->idx)) { + dat =imx_mu_read (priv,IMX_MU_xRRn (cp->idx)); +mbox_chan_received_data (chan, (void *)&dat); + }+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return IRQ_HANDLED ;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static bool imx_mu_last_tx_done (struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 110
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 val;+
Quoted 2 lines
(quoted diff) +2
-0+ val = imx_mu_read(priv, IMX_MU_xSR); + /* test if transmit register is empty */
drivers/mailbox/imx-mailbox.c line 114
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return val &IMX_MU_xSR_TEn (cp->idx);
I guess
"return imx_mu_read(priv, IMX_MU_xSR) & IMX_MU_xSR_TEn(cp->idx);" is shorter and equally well understood.
drivers/mailbox/imx-mailbox.c line 127
Quoted 13 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_send_data (struct mbox_chan *chan,void *data) +{drivers/mailbox/imx-mailbox.c line 121
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 *arg = data;+
drivers/mailbox/imx-mailbox.c line 124
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (!imx_mu_last_tx_done (chan)) +return -EBUSY ;+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_write (priv, *arg,IMX_MU_xTRn (cp->idx));drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xSR_TEn (cp->idx),0 );
In multi-channel mode this RMW cycle needs some kind of locking. As this register is also changed from the irq handler, this probably needs to be a irqsave spinlock.
Quoted 16 lines
+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_startup (struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 136
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +int ret;+
drivers/mailbox/imx-mailbox.c line 141
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->irq_desc =devm_kasprintf (priv->dev,GFP_KERNEL ,"imx_mu_chan[%i]" , + ??????cp->idx); +if (!cp->irq_desc) +return -ENOMEM ;+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ ret = devm_request_irq(priv->dev, cp->irq, imx_mu_isr,
drivers/mailbox/imx-mailbox.c
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ ???????IRQF_SHARED, cp->irq_desc, chan);
Using the devm_ variants of those functions doesn't make sense when the resources aren't tied to the device lifetime. As you are tearing them down manually in imx_mu_shutdown anyways, just use the raw variants of those functions.
Quoted 85 lines
drivers/mailbox/imx-mailbox.c new file +1
-0+if (ret) {drivers/mailbox/imx-mailbox.c line 149
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+dev_err (priv->dev, +"Unable to acquire IRQ %d\n" , cp->irq); +return ret; + }+
drivers/mailbox/imx-mailbox.c line 151
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xCR_RIEn (cp->idx),0 );+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static void imx_mu_shutdown (struct mbox_chan *chan) +{Review
Quoted 2 lines
(quoted diff) +2
-0+ struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); + struct imx_mu_con_priv *cp = chan->con_priv;+
Review
Quoted 2 lines
(quoted diff) +2
-0+ imx_mu_rmw(priv, IMX_MU_xCR, 0, + ???IMX_MU_xCR_TIEn(cp->idx) | IMX_MU_xCR_RIEn(cp->idx));+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+devm_free_irq (priv->dev, cp->irq, chan); +devm_kfree (priv->dev, cp->irq_desc);drivers/mailbox/imx-mailbox.c new file +3
-0+} + +static const struct mbox_chan_ops imx_mu_ops = {Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ .send_data = imx_mu_send_data, + .startup = imx_mu_startup, + .shutdown = imx_mu_shutdown,drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static void imx_mu_init_generic (struct imx_mu_priv *priv) +{drivers/mailbox/imx-mailbox.c line 177
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (priv->side_b) +return ;+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+/* Set default MU configuration */ +imx_mu_write (priv,0 , IMX_MU_xCR);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_probe (struct platform_device *pdev) +{drivers/mailbox/imx-mailbox.c line 190
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct resource *iomem; +struct imx_mu_priv *priv; +unsigned int i; +int irq, ret;+
drivers/mailbox/imx-mailbox.c line 194
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ;+
drivers/mailbox/imx-mailbox.c line 196
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ priv->dev = dev;+
drivers/mailbox/imx-mailbox.c line 201
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ iomem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->base =devm_ioremap_resource (&pdev->dev, iomem); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base);+
drivers/mailbox/imx-mailbox.c line 205
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq;+
drivers/mailbox/imx-mailbox.c line 210
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) { +if (PTR_ERR (priv->clk) != -ENOENT ) +return PTR_ERR (priv->clk);+
Review
Quoted 2 lines
(quoted diff) +2
-0+ priv->clk = NULL; + }+
drivers/mailbox/imx-mailbox.c line 219
Quoted 5 lines
drivers/mailbox/imx-mailbox.c new file +5
-0+ ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + }+
drivers/mailbox/imx-mailbox.c line 222
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+for (i =0 ; i <IMX_MU_CHANS ; i++) { +struct imx_mu_con_priv *cp = &priv->con_priv[i];+
drivers/mailbox/imx-mailbox.c line 227
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->idx = i; + cp->irq = irq; + priv->mbox_chans[i].con_priv = cp; + }+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+if (of_property_read_bool (np,"fsl,mu-side-b" ))
drivers/mailbox/imx-mailbox.c line 230
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ priv->side_b = true;
No need for the if clause here. Just assign the return value from of_property_read_bool to priv->side_b.
Quoted 43 lines
+
drivers/mailbox/imx-mailbox.c line 236
Quoted 5 lines
drivers/mailbox/imx-mailbox.c new file +5
-0+ priv->mbox.dev = dev; + priv->mbox.ops = &imx_mu_ops; + priv->mbox.chans = priv->mbox_chans; + priv->mbox.num_chans =IMX_MU_CHANS ; + priv->mbox.txdone_irq = true;+
drivers/mailbox/imx-mailbox.c line 238
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+platform_set_drvdata (pdev, priv);+
drivers/mailbox/imx-mailbox.c line 240
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_init_generic (priv);+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return mbox_controller_register (&priv->mbox);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_remove (struct platform_device *pdev) +{drivers/mailbox/imx-mailbox.c line 247
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+struct imx_mu_priv *priv =platform_get_drvdata (pdev);+
drivers/mailbox/imx-mailbox.c line 250
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+mbox_controller_unregister (&priv->mbox); +clk_disable_unprepare (priv->clk);+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +3
-0+} + +static const struct of_device_id imx_mu_dt_ids[] = {Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+ { .compatible = "fsl,imx6sx-mu" }, + { },drivers/mailbox/imx-mailbox.c new file +4
-0+}; +MODULE_DEVICE_TABLE (of, imx_mu_dt_ids); + +static struct platform_driver imx_mu_driver = {Quoted 6 lines
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+ .probe = imx_mu_probe, + .remove = imx_mu_remove,drivers/mailbox/imx-mailbox.c new file +1
-0+ .driver = {Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ .name = "imx_mu",drivers/mailbox/imx-mailbox.c new file +2
-0+ .of_match_table = imx_mu_dt_ids, + },drivers/mailbox/imx-mailbox.c new file +3
-0+}; +module_platform_driver (imx_mu_driver); +Quoted 1 line
+MODULE_AUTHOR("Oleksij Rempel <[email protected]>");
drivers/mailbox/imx-mailbox.c new file +2
-0+MODULE_DESCRIPTION ("Message Unit driver for i.MX" ); +MODULE_LICENSE ("GPL v2" );
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
Quoted 105 lines · Lucas Stach
Am Sonntag, den 22.07.2018, 08:39 +0200 schrieb Oleksij Rempel:
Quoted 104 lines
The Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
Quoted 2 lines
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>---
?drivers/mailbox/Kconfig???????|???6 + ?drivers/mailbox/Makefile??????|???2 + ?drivers/mailbox/imx-mailbox.c | 273 ++++++++++++++++++++++++++++++++++?3 files changed, 281 insertions(+)
?create mode 100644drivers/mailbox/imx-mailbox.cdrivers/mailbox/Kconfig +0
-0@@ -15,6 +15,12 @@ config ARM_MHUQuoted 2 lines
? ??The controller has 3 mailbox channels, the last of which can be
? ??used in Secure mode only.?
+configIMX_MBOXdrivers/mailbox/Kconfig config ARM_MHU
Quoted 4 lines
drivers/mailbox/Kconfig +4
-0+ tristate "i.MX Mailbox" + depends on ARCH_MXC || COMPILE_TEST + help + ??Mailbox implementation for i.MX Messaging Unit (MU).+
?configPLATFORM_MHUQuoted 2 lines
? tristate "Platform MHU Mailbox"
? depends on OFdrivers/mailbox/Makefile +0
-0Review obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o
Quoted 1 line
(quoted diff) +0
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o?
Quoted 1 line
?obj-$(CONFIG_ARM_MHU) += arm_mhu.o
?
Quoted 1 line
+obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o
+
Quoted 1 line
?obj-$(CONFIG_PLATFORM_MHU) += platform_mhu.o
?
Quoted 1 line
?obj-$(CONFIG_PL320_MBOX) += pl320-ipc.o
drivers/mailbox/imx-mailbox.c new file +14
-0@@ -0,0 +1,273 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018 Pengutronix, Oleksij Rempel <[email protected]> +*/ + +#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> + +/* Transmit Register */ Quoted 1 line
+#define
IMX_MU_xTRn(x)(0x00+ 4 * (x))+/* Receive Register */
Quoted 1 line
+#define
IMX_MU_xRRn(x)(0x10+ 4 * (x))+/* Status Register */
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+#define IMX_MU_xSR 0x20 +#define IMX_MU_xSR_TEn (x) BIT(20 + (3 - (x))) +#define IMX_MU_xSR_RFn (x) BIT(24 + (3 - (x))) +#define IMX_MU_xSR_BRDIP BIT(9)drivers/mailbox/imx-mailbox.c new file +2
-0+ +/* Control Register */ Quoted 1 line
+#define
IMX_MU_xCR0x24+/* Transmit Interrupt Enable */
Quoted 1 line
+#define
IMX_MU_xCR_TIEn(x)BIT(20 + (3 - (x)))+/* Receive Interrupt Enable */
Quoted 1 line
+#define
IMX_MU_xCR_RIEn(x)BIT(24 + (3 - (x)))+
Quoted 1 line
+#define
IMX_MU_CHANS4udrivers/mailbox/imx-mailbox.c new file +2
-0+ +struct imx_mu_con_priv {Quoted 3 lines
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+int irq; +unsigned int idx; +char *irq_desc;drivers/mailbox/imx-mailbox.c new file +3
-0+}; + +struct imx_mu_priv {Quoted 2 lines
drivers/mailbox/imx-mailbox.c line 41
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+struct device *dev; +void __iomem *base;+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c line 44
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+struct mbox_controller mbox; +struct mbox_chan mbox_chans[IMX_MU_CHANS ];+
Quoted 2 lines
(quoted diff) +1
-0+ struct imx_mu_con_priv??con_priv[IMX_MU_CHANS];drivers/mailbox/imx-mailbox.c line 47
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+struct clk *clk;+
Quoted 1 line
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+bool side_b;drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static struct imx_mu_priv *to_imx_mu_priv (struct mbox_controller *mbox) +{
Quoted 10 lines
drivers/mailbox/imx-mailbox.c line 59
Quoted 6 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ return container_of(mbox, struct imx_mu_priv, mbox);drivers/mailbox/imx-mailbox.c new file +5
-0+} + +static void imx_mu_write (struct imx_mu_priv *priv,u32 val,u32 offs) +{ +iowrite32 (val, priv->base + offs);This driver is never going to be used on a device with port based IO, so iowrite doesn't make much sense here, just use writel. Same comment applies to the below read function.
I read this and do not understand what is actual problem:
https://lwn.net/Articles/102232/
"By default, these functions are simply wrappers around readb() and friends. The explicit pointer type for the argument will generate warnings, however, if a driver passes in an integer type."
So, is it wrong or not? If yes, why?
Quoted 2 lines
Also, given that those functions are not really shortening the code in the user they may also be removed completely IMHO.
Is it subjective or technical issue?
Quoted 52 lines
Quoted 52 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static u32 imx_mu_read (struct imx_mu_priv *priv,u32 offs) +{Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return ioread32 (priv->base + offs);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static u32 imx_mu_rmw (struct imx_mu_priv *priv,u32 offs,u32 set,u32 clr) +{Review
Quoted 1 line
(quoted diff) +1
-0+ u32 val;+
drivers/mailbox/imx-mailbox.c line 74
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ val =imx_mu_read (priv, offs); + val &= ~clr; + val |= set; +imx_mu_write (priv, val, offs);+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return val;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static irqreturn_t imx_mu_isr (int irq,void *p) +{drivers/mailbox/imx-mailbox.c line 84
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+struct mbox_chan *chan = p; +struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 val, ctrl, dat;+
drivers/mailbox/imx-mailbox.c line 91
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+ ctrl =imx_mu_read (priv, IMX_MU_xCR); + val =imx_mu_read (priv, IMX_MU_xSR); + val &=IMX_MU_xSR_TEn (cp->idx) |IMX_MU_xSR_RFn (cp->idx); + val &= ctrl & (IMX_MU_xCR_TIEn (cp->idx) |IMX_MU_xCR_RIEn (cp->idx)); +if (!val) +return IRQ_NONE ;+
drivers/mailbox/imx-mailbox.c line 96
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+if (val &IMX_MU_xSR_TEn (cp->idx)) { +imx_mu_rmw (priv, IMX_MU_xCR,0 ,IMX_MU_xCR_TIEn (cp->idx)); +mbox_chan_txdone (chan,0 ); + }+
drivers/mailbox/imx-mailbox.c line 101
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+if (val &IMX_MU_xSR_RFn (cp->idx)) { + dat =imx_mu_read (priv,IMX_MU_xRRn (cp->idx)); +mbox_chan_received_data (chan, (void *)&dat); + }+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return IRQ_HANDLED ;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static bool imx_mu_last_tx_done (struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 110
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 val;+
Quoted 7 lines
drivers/mailbox/imx-mailbox.c line 114
Quoted 3 lines
Quoted 2 lines
(quoted diff) +2
-0+ val = imx_mu_read(priv, IMX_MU_xSR); + /* test if transmit register is empty */drivers/mailbox/imx-mailbox.c new file +1
-0+return val &IMX_MU_xSR_TEn (cp->idx);I guess
"returnimx_mu_read(priv, IMX_MU_xSR)&IMX_MU_xSR_TEn(cp->idx);" is shorter and equally well understood.
Same as before:
Is it subjective or technical issue?
Quoted 11 lines
Quoted 11 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_send_data (struct mbox_chan *chan,void *data) +{drivers/mailbox/imx-mailbox.c line 121
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 *arg = data;+
drivers/mailbox/imx-mailbox.c line 124
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (!imx_mu_last_tx_done (chan)) +return -EBUSY ;+
Quoted 6 lines
drivers/mailbox/imx-mailbox.c line 127
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_write (priv, *arg,IMX_MU_xTRn (cp->idx));drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xSR_TEn (cp->idx),0 );In multi-channel mode this RMW cycle needs some kind of locking. As this register is also changed from the irq handler, this probably needs to be a irqsave spinlock.
ok.
Quoted 15 lines
Quoted 15 lines
+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_startup (struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 136
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +int ret;+
drivers/mailbox/imx-mailbox.c line 141
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->irq_desc =devm_kasprintf (priv->dev,GFP_KERNEL ,"imx_mu_chan[%i]" , + ??????cp->idx); +if (!cp->irq_desc) +return -ENOMEM ;+
Quoted 7 lines
drivers/mailbox/imx-mailbox.c
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ ret = devm_request_irq(priv->dev, cp->irq, imx_mu_isr,drivers/mailbox/imx-mailbox.c new file +1
-0+ ???????IRQF_SHARED, cp->irq_desc, chan);Using the
devm_variants of those functions doesn't make sense when the resources aren't tied to the device lifetime. As you are tearing them down manually inimx_mu_shutdownanyways, just use the raw variants of those functions.
So, it is not a problem and there is no advantage. Right?
Quoted 84 lines
Quoted 84 lines
drivers/mailbox/imx-mailbox.c new file +1
-0+if (ret) {drivers/mailbox/imx-mailbox.c line 149
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+dev_err (priv->dev, +"Unable to acquire IRQ %d\n" , cp->irq); +return ret; + }+
drivers/mailbox/imx-mailbox.c line 151
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xCR_RIEn (cp->idx),0 );+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static void imx_mu_shutdown (struct mbox_chan *chan) +{Review
Quoted 2 lines
(quoted diff) +2
-0+ struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); + struct imx_mu_con_priv *cp = chan->con_priv;+
Review
Quoted 2 lines
(quoted diff) +2
-0+ imx_mu_rmw(priv, IMX_MU_xCR, 0, + ???IMX_MU_xCR_TIEn(cp->idx) | IMX_MU_xCR_RIEn(cp->idx));+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+devm_free_irq (priv->dev, cp->irq, chan); +devm_kfree (priv->dev, cp->irq_desc);drivers/mailbox/imx-mailbox.c new file +3
-0+} + +static const struct mbox_chan_ops imx_mu_ops = {Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ .send_data = imx_mu_send_data, + .startup = imx_mu_startup, + .shutdown = imx_mu_shutdown,drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static void imx_mu_init_generic (struct imx_mu_priv *priv) +{drivers/mailbox/imx-mailbox.c line 177
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (priv->side_b) +return ;+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+/* Set default MU configuration */ +imx_mu_write (priv,0 , IMX_MU_xCR);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_probe (struct platform_device *pdev) +{drivers/mailbox/imx-mailbox.c line 190
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct resource *iomem; +struct imx_mu_priv *priv; +unsigned int i; +int irq, ret;+
drivers/mailbox/imx-mailbox.c line 194
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ;+
drivers/mailbox/imx-mailbox.c line 196
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ priv->dev = dev;+
drivers/mailbox/imx-mailbox.c line 201
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ iomem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->base =devm_ioremap_resource (&pdev->dev, iomem); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base);+
drivers/mailbox/imx-mailbox.c line 205
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq;+
drivers/mailbox/imx-mailbox.c line 210
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) { +if (PTR_ERR (priv->clk) != -ENOENT ) +return PTR_ERR (priv->clk);+
Review
Quoted 2 lines
(quoted diff) +2
-0+ priv->clk = NULL; + }+
drivers/mailbox/imx-mailbox.c line 219
Quoted 5 lines
drivers/mailbox/imx-mailbox.c new file +5
-0+ ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + }+
drivers/mailbox/imx-mailbox.c line 222
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+for (i =0 ; i <IMX_MU_CHANS ; i++) { +struct imx_mu_con_priv *cp = &priv->con_priv[i];+
drivers/mailbox/imx-mailbox.c line 227
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->idx = i; + cp->irq = irq; + priv->mbox_chans[i].con_priv = cp; + }+
Quoted 5 lines
drivers/mailbox/imx-mailbox.c line 230
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+if (of_property_read_bool (np,"fsl,mu-side-b" ))drivers/mailbox/imx-mailbox.c new file +1
-0+ priv->side_b = true;No need for the if clause here. Just assign the return value from
of_property_read_booltopriv->side_b.
Not against kernel style and not broken.
Is it subjective or technical issue? I assume I like more red color...
Quoted 44 lines
Quoted 43 lines
+
drivers/mailbox/imx-mailbox.c line 236
Quoted 5 lines
drivers/mailbox/imx-mailbox.c new file +5
-0+ priv->mbox.dev = dev; + priv->mbox.ops = &imx_mu_ops; + priv->mbox.chans = priv->mbox_chans; + priv->mbox.num_chans =IMX_MU_CHANS ; + priv->mbox.txdone_irq = true;+
drivers/mailbox/imx-mailbox.c line 238
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+platform_set_drvdata (pdev, priv);+
drivers/mailbox/imx-mailbox.c line 240
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_init_generic (priv);+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return mbox_controller_register (&priv->mbox);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_remove (struct platform_device *pdev) +{drivers/mailbox/imx-mailbox.c line 247
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+struct imx_mu_priv *priv =platform_get_drvdata (pdev);+
drivers/mailbox/imx-mailbox.c line 250
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+mbox_controller_unregister (&priv->mbox); +clk_disable_unprepare (priv->clk);+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +3
-0+} + +static const struct of_device_id imx_mu_dt_ids[] = {Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+ { .compatible = "fsl,imx6sx-mu" }, + { },drivers/mailbox/imx-mailbox.c new file +4
-0+}; +MODULE_DEVICE_TABLE (of, imx_mu_dt_ids); + +static struct platform_driver imx_mu_driver = {Quoted 6 lines
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+ .probe = imx_mu_probe, + .remove = imx_mu_remove,drivers/mailbox/imx-mailbox.c new file +1
-0+ .driver = {Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ .name = "imx_mu",drivers/mailbox/imx-mailbox.c new file +2
-0+ .of_match_table = imx_mu_dt_ids, + },drivers/mailbox/imx-mailbox.c new file +3
-0+}; +module_platform_driver (imx_mu_driver); +Quoted 1 line
+MODULE_AUTHOR("Oleksij Rempel <[email protected]>");
drivers/mailbox/imx-mailbox.c new file +2
-0+MODULE_DESCRIPTION ("Message Unit driver for i.MX" ); +MODULE_LICENSE ("GPL v2" );
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180723/06b2537f/attachment.sig>
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
In reply to Lucas StachQuoted 12 lines
-----Original Message-----
From: Lucas Stach [mailto:l.stach at pengutronix.de]
Sent: Tuesday, July 24, 2018 1:20 AM
To: Oleksij Rempel <[email protected]>; Shawn Guo <[email protected]>; Fabio Estevam <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; A.s. Dong <[email protected]>; Vladimir Zapolskiy <[email protected]>
Cc: dl-linux-imx <[email protected]>; linux-arm-kernel at lists.infradead.org; kernel at pengutronix.de; devicetree at vger.kernel.org
Subject: Re: [PATCH v6 5/5] mailbox: Add support for i.MX7D messaging unit
[...]
Quoted 10 lines
Quoted 10 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+} + +static int imx_mu_send_data (struct mbox_chan *chan,void *data) {drivers/mailbox/imx-mailbox.c line 121
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 *arg = data;+
drivers/mailbox/imx-mailbox.c line 124
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (!imx_mu_last_tx_done (chan)) +return -EBUSY ;+
Quoted 7 lines
drivers/mailbox/imx-mailbox.c line 127
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_write (priv, *arg,IMX_MU_xTRn (cp->idx));drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xSR_TEn (cp->idx),0 );In multi-channel mode this RMW cycle needs some kind of locking. As this register is also changed from the irq handler, this probably needs to be a irqsave spinlock.
Good catch!
They do need to be protected.
Regards
Dong Aisheng
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
In reply to Lucas StachHi Lucas,
here is more detailed response:
Quoted 105 lines · Lucas Stach
Am Sonntag, den 22.07.2018, 08:39 +0200 schrieb Oleksij Rempel:
Quoted 104 lines
The Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
Quoted 2 lines
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>---
?drivers/mailbox/Kconfig???????|???6 + ?drivers/mailbox/Makefile??????|???2 + ?drivers/mailbox/imx-mailbox.c | 273 ++++++++++++++++++++++++++++++++++?3 files changed, 281 insertions(+)
?create mode 100644drivers/mailbox/imx-mailbox.cdrivers/mailbox/Kconfig +0
-0@@ -15,6 +15,12 @@ config ARM_MHUQuoted 2 lines
? ??The controller has 3 mailbox channels, the last of which can be
? ??used in Secure mode only.?
+configIMX_MBOXdrivers/mailbox/Kconfig config ARM_MHU
Quoted 4 lines
drivers/mailbox/Kconfig +4
-0+ tristate "i.MX Mailbox" + depends on ARCH_MXC || COMPILE_TEST + help + ??Mailbox implementation for i.MX Messaging Unit (MU).+
?configPLATFORM_MHUQuoted 2 lines
? tristate "Platform MHU Mailbox"
? depends on OFdrivers/mailbox/Makefile +0
-0Review obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o
Quoted 1 line
(quoted diff) +0
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o?
Quoted 1 line
?obj-$(CONFIG_ARM_MHU) += arm_mhu.o
?
Quoted 1 line
+obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o
+
Quoted 1 line
?obj-$(CONFIG_PLATFORM_MHU) += platform_mhu.o
?
Quoted 1 line
?obj-$(CONFIG_PL320_MBOX) += pl320-ipc.o
drivers/mailbox/imx-mailbox.c new file +14
-0@@ -0,0 +1,273 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018 Pengutronix, Oleksij Rempel <[email protected]> +*/ + +#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> + +/* Transmit Register */ Quoted 1 line
+#define
IMX_MU_xTRn(x)(0x00+ 4 * (x))+/* Receive Register */
Quoted 1 line
+#define
IMX_MU_xRRn(x)(0x10+ 4 * (x))+/* Status Register */
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+#define IMX_MU_xSR 0x20 +#define IMX_MU_xSR_TEn (x) BIT(20 + (3 - (x))) +#define IMX_MU_xSR_RFn (x) BIT(24 + (3 - (x))) +#define IMX_MU_xSR_BRDIP BIT(9)drivers/mailbox/imx-mailbox.c new file +2
-0+ +/* Control Register */ Quoted 1 line
+#define
IMX_MU_xCR0x24+/* Transmit Interrupt Enable */
Quoted 1 line
+#define
IMX_MU_xCR_TIEn(x)BIT(20 + (3 - (x)))+/* Receive Interrupt Enable */
Quoted 1 line
+#define
IMX_MU_xCR_RIEn(x)BIT(24 + (3 - (x)))+
Quoted 1 line
+#define
IMX_MU_CHANS4udrivers/mailbox/imx-mailbox.c new file +2
-0+ +struct imx_mu_con_priv {Quoted 3 lines
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+int irq; +unsigned int idx; +char *irq_desc;drivers/mailbox/imx-mailbox.c new file +3
-0+}; + +struct imx_mu_priv {Quoted 2 lines
drivers/mailbox/imx-mailbox.c line 41
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+struct device *dev; +void __iomem *base;+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c line 44
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+struct mbox_controller mbox; +struct mbox_chan mbox_chans[IMX_MU_CHANS ];+
Quoted 2 lines
(quoted diff) +1
-0+ struct imx_mu_con_priv??con_priv[IMX_MU_CHANS];drivers/mailbox/imx-mailbox.c line 47
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+struct clk *clk;+
Quoted 1 line
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+bool side_b;drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static struct imx_mu_priv *to_imx_mu_priv (struct mbox_controller *mbox) +{
Quoted 10 lines
drivers/mailbox/imx-mailbox.c line 59
Quoted 6 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ return container_of(mbox, struct imx_mu_priv, mbox);drivers/mailbox/imx-mailbox.c new file +5
-0+} + +static void imx_mu_write (struct imx_mu_priv *priv,u32 val,u32 offs) +{ +iowrite32 (val, priv->base + offs);This driver is never going to be used on a device with port based IO, so iowrite doesn't make much sense here, just use writel. Same comment applies to the below read function.
As before I don't really understand the difference. I took some time for learning and here are my findings:
- historical background of ioread/iowrite functions. What I can find is this LWN article: https://lwn.net/Articles/102232/ . The main point seems to be "The first of these is a new __iomem annotation used to mark pointers to I/O memory" ... " As with __user, the __iomem marker serves a documentation role in the kernel code;"
In modern kernel the difference between ioread32 and readl seems to be completely disappeared.
with this LWN article (2016):
https://lwn.net/Articles/698014/
the readl and reade32 are always in the same group..
If there is some documentation which will say why I should use readl() instead of ioread32() i would really love to read it.
Quoted 2 lines
Also, given that those functions are not really shortening the code in the user they may also be removed completely IMHO.
Wrong assumption.. I use this functions for tracing. It is just to easy to add two trace points... From technical perspective I don't see any advantage or disadvantage of having this functions.
If it is my personal preference, then I decide to keep it.
Quoted 52 lines
Quoted 52 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static u32 imx_mu_read (struct imx_mu_priv *priv,u32 offs) +{Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return ioread32 (priv->base + offs);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static u32 imx_mu_rmw (struct imx_mu_priv *priv,u32 offs,u32 set,u32 clr) +{Review
Quoted 1 line
(quoted diff) +1
-0+ u32 val;+
drivers/mailbox/imx-mailbox.c line 74
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ val =imx_mu_read (priv, offs); + val &= ~clr; + val |= set; +imx_mu_write (priv, val, offs);+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return val;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static irqreturn_t imx_mu_isr (int irq,void *p) +{drivers/mailbox/imx-mailbox.c line 84
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+struct mbox_chan *chan = p; +struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 val, ctrl, dat;+
drivers/mailbox/imx-mailbox.c line 91
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+ ctrl =imx_mu_read (priv, IMX_MU_xCR); + val =imx_mu_read (priv, IMX_MU_xSR); + val &=IMX_MU_xSR_TEn (cp->idx) |IMX_MU_xSR_RFn (cp->idx); + val &= ctrl & (IMX_MU_xCR_TIEn (cp->idx) |IMX_MU_xCR_RIEn (cp->idx)); +if (!val) +return IRQ_NONE ;+
drivers/mailbox/imx-mailbox.c line 96
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+if (val &IMX_MU_xSR_TEn (cp->idx)) { +imx_mu_rmw (priv, IMX_MU_xCR,0 ,IMX_MU_xCR_TIEn (cp->idx)); +mbox_chan_txdone (chan,0 ); + }+
drivers/mailbox/imx-mailbox.c line 101
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+if (val &IMX_MU_xSR_RFn (cp->idx)) { + dat =imx_mu_read (priv,IMX_MU_xRRn (cp->idx)); +mbox_chan_received_data (chan, (void *)&dat); + }+
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+return IRQ_HANDLED ;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static bool imx_mu_last_tx_done (struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 110
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 val;+
Quoted 7 lines
drivers/mailbox/imx-mailbox.c line 114
Quoted 3 lines
Quoted 2 lines
(quoted diff) +2
-0+ val = imx_mu_read(priv, IMX_MU_xSR); + /* test if transmit register is empty */drivers/mailbox/imx-mailbox.c new file +1
-0+return val &IMX_MU_xSR_TEn (cp->idx);I guess
"returnimx_mu_read(priv, IMX_MU_xSR)&IMX_MU_xSR_TEn(cp->idx);" is shorter and equally well understood.
So, previous comment was saying, "those functions are not really shortening the code"
I would apply same comment: "those .. are not really shortening the code".
Do we really need to make review of "personal coding style preferences".. which are not against kernel coding style in 6. review round...?!
For example:
kernel coding style is pink... in this case we are talking about difference between lavender pink and carnation pink.
Quoted 11 lines
Quoted 11 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_send_data (struct mbox_chan *chan,void *data) +{drivers/mailbox/imx-mailbox.c line 121
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +u32 *arg = data;+
drivers/mailbox/imx-mailbox.c line 124
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (!imx_mu_last_tx_done (chan)) +return -EBUSY ;+
Quoted 6 lines
drivers/mailbox/imx-mailbox.c line 127
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_write (priv, *arg,IMX_MU_xTRn (cp->idx));drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xSR_TEn (cp->idx),0 );In multi-channel mode this RMW cycle needs some kind of locking. As this register is also changed from the irq handler, this probably needs to be a irqsave spinlock.
Thank you, i need to fix it.
Quoted 15 lines
Quoted 15 lines
+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_startup (struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 136
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +int ret;+
drivers/mailbox/imx-mailbox.c line 141
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->irq_desc =devm_kasprintf (priv->dev,GFP_KERNEL ,"imx_mu_chan[%i]" , + ??????cp->idx); +if (!cp->irq_desc) +return -ENOMEM ;+
Quoted 7 lines
drivers/mailbox/imx-mailbox.c
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ ret = devm_request_irq(priv->dev, cp->irq, imx_mu_isr,drivers/mailbox/imx-mailbox.c new file +1
-0+ ???????IRQF_SHARED, cp->irq_desc, chan);Using the
devm_variants of those functions doesn't make sense when the resources aren't tied to the device lifetime. As you are tearing them down manually inimx_mu_shutdownanyways, just use the raw variants of those functions.
I have nothing against it.
Quoted 84 lines
Quoted 84 lines
drivers/mailbox/imx-mailbox.c new file +1
-0+if (ret) {drivers/mailbox/imx-mailbox.c line 149
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+dev_err (priv->dev, +"Unable to acquire IRQ %d\n" , cp->irq); +return ret; + }+
drivers/mailbox/imx-mailbox.c line 151
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+imx_mu_rmw (priv, IMX_MU_xCR,IMX_MU_xCR_RIEn (cp->idx),0 );+
Quoted 1 line
(quoted diff) +1
-0+ return 0;drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static void imx_mu_shutdown (struct mbox_chan *chan) +{Review
Quoted 2 lines
(quoted diff) +2
-0+ struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); + struct imx_mu_con_priv *cp = chan->con_priv;+
Review
Quoted 2 lines
(quoted diff) +2
-0+ imx_mu_rmw(priv, IMX_MU_xCR, 0, + ???IMX_MU_xCR_TIEn(cp->idx) | IMX_MU_xCR_RIEn(cp->idx));+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+devm_free_irq (priv->dev, cp->irq, chan); +devm_kfree (priv->dev, cp->irq_desc);drivers/mailbox/imx-mailbox.c new file +3
-0+} + +static const struct mbox_chan_ops imx_mu_ops = {Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ .send_data = imx_mu_send_data, + .startup = imx_mu_startup, + .shutdown = imx_mu_shutdown,drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static void imx_mu_init_generic (struct imx_mu_priv *priv) +{drivers/mailbox/imx-mailbox.c line 177
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+if (priv->side_b) +return ;+
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+/* Set default MU configuration */ +imx_mu_write (priv,0 , IMX_MU_xCR);drivers/mailbox/imx-mailbox.c new file +4
-0+} + +static int imx_mu_probe (struct platform_device *pdev) +{drivers/mailbox/imx-mailbox.c line 190
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct resource *iomem; +struct imx_mu_priv *priv; +unsigned int i; +int irq, ret;+
drivers/mailbox/imx-mailbox.c line 194
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ;+
drivers/mailbox/imx-mailbox.c line 196
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ priv->dev = dev;+
drivers/mailbox/imx-mailbox.c line 201
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ iomem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->base =devm_ioremap_resource (&pdev->dev, iomem); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base);+
drivers/mailbox/imx-mailbox.c line 205
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq;+
drivers/mailbox/imx-mailbox.c line 210
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) { +if (PTR_ERR (priv->clk) != -ENOENT ) +return PTR_ERR (priv->clk);+
Review
Quoted 2 lines
(quoted diff) +2
-0+ priv->clk = NULL; + }+
drivers/mailbox/imx-mailbox.c line 219
Quoted 5 lines
drivers/mailbox/imx-mailbox.c new file +5
-0+ ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + }+
drivers/mailbox/imx-mailbox.c line 222
Quoted 2 lines
drivers/mailbox/imx-mailbox.c new file +2
-0+for (i =0 ; i <IMX_MU_CHANS ; i++) { +struct imx_mu_con_priv *cp = &priv->con_priv[i];+
drivers/mailbox/imx-mailbox.c line 227
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->idx = i; + cp->irq = irq; + priv->mbox_chans[i].con_priv = cp; + }+
Quoted 5 lines
drivers/mailbox/imx-mailbox.c line 230
Quoted 2 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+if (of_property_read_bool (np,"fsl,mu-side-b" ))drivers/mailbox/imx-mailbox.c new file +1
-0+ priv->side_b = true;No need for the if clause here. Just assign the return value from
of_property_read_booltopriv->side_b.
ok.
Thank you for a review!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180724/8a7ff5f5/attachment-0001.sig>
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
Am Dienstag, den 24.07.2018, 07:14 +0200 schrieb Oleksij Rempel:
Quoted 5 lines
Hi Lucas,
here is more detailed response:
On 23.07.2018 19:19, Lucas Stach wrote:
[...]
Quoted 24 lines
Quoted 4 lines
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+}; + +static struct imx_mu_priv *to_imx_mu_priv (struct mbox_controller *mbox) +{Quoted 11 lines
drivers/mailbox/imx-mailbox.c line 59
Quoted 7 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ return container_of(mbox, struct imx_mu_priv, mbox);drivers/mailbox/imx-mailbox.c new file +5
-0+} + +static void imx_mu_write (struct imx_mu_priv *priv,u32 val,u32 offs) +{ +iowrite32 (val, priv->base + offs);This driver is never going to be used on a device with port based IO, so iowrite doesn't make much sense here, just use writel. Same comment applies to the below read function.
As before I don't really understand the difference. I took some time for learning and here are my findings:
- historical background of ioread/iowrite functions. What I can find isQuoted 1 line
this LWN article: https://lwn.net/Articles/102232/ . The main point
seems to be "The first of these is a new
__iomemannotation used to mark pointers to I/O memory" ... " As with__user, the__iomemmarker serves a documentation role in the kernel code;"
Quoted 5 lines
In modern kernel the difference between ioread32 and readl seems to be completely disappeared.
with this LWN article (2016):
https://lwn.net/Articles/698014/
the readl and reade32 are always in the same group..
Okay, as discussed offline this is more a thing of personal preference, since this maps to the same thing internally when used on a architecture without IO ports. I slightly dislike those as they don't have a _relaxed counterpart, but other than that there should be no difference. As we don't use any of the relaxed stuff in this driver it's really about the color of the bikeshed, so feel free to keep it your way.
Quoted 10 lines
If there is some documentation which will say why I should use
readl()instead ofioread32()i would really love to read it.Quoted 2 lines
Also, given that those functions are not really shortening the code in the user they may also be removed completely IMHO.
Wrong assumption..??I use this functions for tracing. It is just to easy to add two trace points...??From technical perspective I don't see any advantage or disadvantage of having this functions.
If it is my personal preference, then I decide to keep it.
That IMHO implies that I'm perfectly fine with you ignoring this comment. :)
[...]
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +2
-0+static int imx_mu_startup(struct mbox_chan *chan) +{drivers/mailbox/imx-mailbox.c line 136
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2
-0+ struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); + struct imx_mu_con_priv *cp = chan->con_priv;drivers/mailbox/imx-mailbox.c new file +1
-0+int ret;+
Review
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ cp->irq_desc =devm_kasprintf (priv->dev,GFP_KERNEL ,"imx_mu_chan[%i]" , + ??????cp->idx); +if (!cp->irq_desc)(quoted diff) +1
-0+ return -ENOMEM;+
Quoted 8 lines
Review
Quoted 3 lines
Quoted 1 line
drivers/mailbox/imx-mailbox.c new file +1
-0+ ret = devm_request_irq(priv->dev, cp->irq, imx_mu_isr,(quoted diff) +1
-0+ ???????IRQF_SHARED, cp->irq_desc, chan);Using the
devm_variants of those functions doesn't make sense when the resources aren't tied to the device lifetime. As you are tearing them down manually inimx_mu_shutdownanyways, just use the raw variants of those functions.
Quoted 1 line
I have nothing against it.
Thanks, as this is something I feel more strongly about. As the devm_ stuff is meant to tie the lifetime of an object to the device/driver lifetime using them in a context where there is no relation at all is kind of an API abuse to me.
Regards,
Lucas
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
In reply to Oleksij RempelHi Oleksij,
Quoted 8 lines · Oleksij Rempel
The Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>
[snip]
drivers/mailbox/imx-mailbox.c line 142
Quoted 11 lines
drivers/mailbox/imx-mailbox.c new file +11
-0+static int imx_mu_startup (struct mbox_chan *chan) +{ +struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +int ret; + + cp->irq_desc =devm_kasprintf (priv->dev,GFP_KERNEL ,"imx_mu_chan[%i]" , + cp->idx); +if (!cp->irq_desc) +return -ENOMEM ; +
Again I would suggest to move this allocation to the loop in .probe function.
[snip]
drivers/mailbox/imx-mailbox.c line 225
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+ +for (i =0 ; i <IMX_MU_CHANS ; i++) { +struct imx_mu_con_priv *cp = &priv->con_priv[i]; + + cp->idx = i; + cp->irq = irq;
^^^^ right over here.
drivers/mailbox/imx-mailbox.c line 228
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ priv->mbox_chans[i].con_priv = cp; + } +
please feel free to add my technical side review tag to the next version:
FWIW I find that review comments from Lucas are pretty valid, I would recommend to incorporate them.
--
Best wishes,
Vladimir
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
Quoted 33 lines
-----Original Message-----
From: Vladimir Zapolskiy [mailto:vz at mleia.com]
Sent: Tuesday, July 24, 2018 7:31 AM
To: Oleksij Rempel <[email protected]>; Shawn Guo <[email protected]>; Fabio Estevam <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; A.s. Dong <[email protected]>; Vladimir Zapolskiy <[email protected]>
Cc: kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org; devicetree at vger.kernel.org; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v6 5/5] mailbox: Add support for i.MX7D messaging unitHi Oleksij,
Quoted 8 lines · Oleksij Rempel
The Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>[snip]
drivers/mailbox/imx-mailbox.c
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+static int imx_mu_startup (struct mbox_chan *chan) { +struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +int ret; + + cp->irq_desc = devm_kasprintf(priv->dev, GFP_KERNEL,"imx_mu_chan[%i]",
Quoted 9 lines
drivers/mailbox/imx-mailbox.c line 142
Quoted 4 lines
drivers/mailbox/imx-mailbox.c new file +4
-0+ cp->idx); +if (!cp->irq_desc) +return -ENOMEM ; +Again I would suggest to move this allocation to the loop in .probe function.
[snip]
+1
Good point.
Quoted 15 lines
drivers/mailbox/imx-mailbox.c line 225
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+ +for (i =0 ; i <IMX_MU_CHANS ; i++) { +struct imx_mu_con_priv *cp = &priv->con_priv[i]; + + cp->idx = i; + cp->irq = irq;^^^^ right over here.
drivers/mailbox/imx-mailbox.c line 228
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ priv->mbox_chans[i].con_priv = cp; + } +please feel free to add my technical side review tag to the next version:
Quoted 4 lines
Reviewed-by Vladimir Zapolskiy <[email protected]>FWIW I find that review comments from Lucas are pretty valid, I would recommend to incorporate them.
+1
Regards
Dong Aisheng
Quoted 4 lines
--
Best wishes,
Vladimir
PATCH v6 5/5 mailbox: Add support for i.MX7D messaging unit
In reply to Vladimir ZapolskiyQuoted 14 lines · Vladimir Zapolskiy
Hi Oleksij,
Quoted 8 lines · Oleksij Rempel
The Mailbox controller is able to send messages (up to 4 32 bit words) between the endpoints.
This driver was tested using the mailbox-test driver sending messages between the Cortex-A7 and the Cortex-M4.
Reviewed-by Dong Aisheng <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>[snip]
Quoted 13 lines
drivers/mailbox/imx-mailbox.c line 142
Quoted 11 lines
drivers/mailbox/imx-mailbox.c new file +11
-0+static int imx_mu_startup (struct mbox_chan *chan) +{ +struct imx_mu_priv *priv =to_imx_mu_priv (chan->mbox); +struct imx_mu_con_priv *cp = chan->con_priv; +int ret; + + cp->irq_desc =devm_kasprintf (priv->dev,GFP_KERNEL ,"imx_mu_chan[%i]" , + cp->idx); +if (!cp->irq_desc) +return -ENOMEM ; +Again I would suggest to move this allocation to the loop in .probe function.
Why? In my case I use 2 channels. Why should I allocate 4 descriptors for using only 2 of them?
The SCU driver will use only one channel...
Quoted 17 lines
[snip]
drivers/mailbox/imx-mailbox.c line 225
Quoted 6 lines
drivers/mailbox/imx-mailbox.c new file +6
-0+ +for (i =0 ; i <IMX_MU_CHANS ; i++) { +struct imx_mu_con_priv *cp = &priv->con_priv[i]; + + cp->idx = i; + cp->irq = irq;^^^^ right over here.
drivers/mailbox/imx-mailbox.c line 228
Quoted 3 lines
drivers/mailbox/imx-mailbox.c new file +3
-0+ priv->mbox_chans[i].con_priv = cp; + } +please feel free to add my technical side review tag to the next version:
Quoted 4 lines
Reviewed-by Vladimir Zapolskiy <[email protected]>FWIW I find that review comments from Lucas are pretty valid, I would recommend to incorporate them.
Ok
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180724/e1b3ccac/attachment.sig>
v6 cover add mailbox support for i.MX7D
In reply to Oleksij RempelHi Oleksij,
Thanks for the work.
Hi Jassi,
Do you think if we can have your tag and let those patches go through Shawn's tree as the later QXP support patches depends on them?
Regards
Dong Aisheng
Quoted 77 lines
-----Original Message-----
From: Oleksij Rempel [mailto:o.rempel at pengutronix.de]
Sent: Sunday, July 22, 2018 2:39 PM
To: Shawn Guo <[email protected]>; Fabio Estevam <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; A.s. Dong <[email protected]>; Vladimir Zapolskiy <[email protected]>
Cc: Oleksij Rempel <[email protected]>; kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org; devicetree at vger.kernel.org; dl-linux- imx <[email protected]>
Subject: [PATCH v6 0/5] add mailbox support for i.MX7D20180622 changes v6:
- include one more patch provided by Aisheng
- DT: add fall back compatible fsl,imx6sx-mu
- imx-mailbox: for now, use only fsl,imx6sx-mu20180621 changes v5:
- DT: revert most of the changes from previous version
- imx-mailbox: remove structimx_mu_cfg
- imx-mailbox: remove !! fromimx_mu_last_tx_done()20180618 changes v4:
- DT: change fsl,mu-side-a to fsl,mu-side-b
- DT: split the patches.
- DT: add all currently known SoCs.
- imx-mailbox: free allocated irq name on channel shutdown
- imx-mailbox: rename*_imx7functions to*_generic20180615 changes v3:
- DT: remove prosaic part of documentation. It describes software or firmware specific usage and not relevant for HW description.
- DT: use <soc>-mu instead of <soc>-mu-<mu side> and add fsl,mu-side-a parameter.
- DT: add most of know i.MX variants with MU
- imx-mailbox: use macros instead of precalculated bit index.
- imx-mailbox: remove warning message for clk.
- imx-mailbox: use imx_mu_chan[%idx] fordevm_request_irq.
- imx-mailbox: depend onARCH_MXCinstead ofSOX_IMX720180615 changes v2:
- DT: use mailbox@ instead of mu@
- DT: change interrupts description
- clk: useimx_clk_gate4instead ofimx_clk_gate2
- imx-mailbox: removelast_tx_donesupport
- imx-mailbox: fix module descriptionThis patches are providing support for mailbox (Messaging Unit) for i.MX7D. Functionality was tested on PHYTEC phyBOARD-Zeta i.MX7D with Linux running on all cores: ARM Cortex-A7 and ARM Cortex-M4.
Both parts of i.MX messaging Unit are visible for all CPUs available on i.MX7D. Communication worked independent of MU side in combination with CPU. For example MU-A used on ARM Cortex-A7 and MU-B used on ARM Cortex- M4 or other ways around.
Dong Aisheng (2):
dt-bindings: mailbox: allow mbox-cells to be equal to 0
dt-bindings: arm: fsl: add mu binding docOleksij Rempel (3):
dt-bindings: mailbox: imx-mu: add generic MU channel support
ARM: dts: imx7s: add i.MX7 messaging unit support
mailbox: Add support for i.MX7D messaging unit.../devicetree/bindings/mailbox/fsl,mu.txt | 41 +++ .../devicetree/bindings/mailbox/mailbox.txt | 3 +- arch/arm/boot/dts/imx7s.dtsi | 19 ++ drivers/mailbox/Kconfig | 6 + drivers/mailbox/Makefile | 2 + drivers/mailbox/imx-mailbox.c | 273 ++++++++++++++++++ 6 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/mailbox/fsl,mu.txt create mode 100644 drivers/mailbox/imx-mailbox.c--
2.18.0
Jassi Brar
maintainerv6 cover add mailbox support for i.MX7D
Quoted 8 lines · A.s. Dong
Hi Oleksij,
Thanks for the work.
Hi Jassi,
Do you think if we can have your tag and let those patches go through Shawn's tree as the later QXP support patches depends on them?
Hmm... I don't find the 5 patches in my mailbox. Are you sure I was CC'ed?
Dong Aisheng (2):
dt-bindings: mailbox: allow mbox-cells to be equal to 0
dt-bindings: arm: fsl: add mu binding doc
Oleksij Rempel (3):
dt-bindings: mailbox: imx-mu: add generic MU channel support
ARM: dts: imx7s: add i.MX7 messaging unit support
mailbox: Add support for i.MX7D messaging unit
v6 cover add mailbox support for i.MX7D
Quoted 15 lines
-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Monday, July 23, 2018 11:33 PM
To: A.s. Dong <[email protected]>
Cc: Oleksij Rempel <[email protected]>; kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org; devicetree at vger.kernel.org; dl-linux- imx <[email protected]>; Shawn Guo <[email protected]>; Fabio Estevam <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Vladimir Zapolskiy <[email protected]>
Subject: Re: [PATCH v6 0/5] add mailbox support for i.MX7DQuoted 2 lines · A.s. Dong
Hi Oleksij,
Quoted 7 lines
Quoted 6 lines
Thanks for the work.
Hi Jassi,
Do you think if we can have your tag and let those patches go through Shawn's tree as the later QXP support patches depends on them?Hmm... I don't find the 5 patches in my mailbox. Are you sure I was CC'ed?
I guess you are missed to be CC'ed.
Oleksij,
As there're some new review comments and may need a small change, please do not miss to CC Jassi (Mailbox Maintainer) in the next version of your patch series.
Regards
Dong Aisheng
Quoted 9 lines
Dong Aisheng (2):
dt-bindings: mailbox: allow mbox-cells to be equal to 0
dt-bindings: arm: fsl: add mu binding docOleksij Rempel (3):
dt-bindings: mailbox: imx-mu: add generic MU channel support
ARM: dts: imx7s: add i.MX7 messaging unit support
mailbox: Add support for i.MX7D messaging unit