From patchwork Tue Jun 26 13:23:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 10489047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 766C360386 for ; Tue, 26 Jun 2018 13:23:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6570F283CF for ; Tue, 26 Jun 2018 13:23:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59525286D5; Tue, 26 Jun 2018 13:23:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC1F62842E for ; Tue, 26 Jun 2018 13:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934791AbeFZNXi (ORCPT ); Tue, 26 Jun 2018 09:23:38 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:33537 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935343AbeFZNX2 (ORCPT ); Tue, 26 Jun 2018 09:23:28 -0400 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXnwG-0004p4-Ot; Tue, 26 Jun 2018 15:23:20 +0200 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fXnwG-0003o8-2W; Tue, 26 Jun 2018 15:23:20 +0200 Date: Tue, 26 Jun 2018 15:23:20 +0200 From: Sascha Hauer To: "A.s. Dong" Cc: Oleksij Rempel , Shawn Guo , Fabio Estevam , Rob Herring , Mark Rutland , "devicetree@vger.kernel.org" , dl-linux-imx , "linux-arm-kernel@lists.infradead.org" , "kernel@pengutronix.de" , "linux-clk@vger.kernel.org" Subject: Re: [PATCH v2 4/4] mailbox: Add support for i.MX7D messaging unit Message-ID: <20180626132320.uvgfxff32p32ke6f@pengutronix.de> References: <20180615095107.24610-1-o.rempel@pengutronix.de> <20180615095107.24610-5-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 15:14:14 up 13 days, 22:23, 59 users, load average: 0.01, 0.14, 0.18 User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-clk@vger.kernel.org Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Jun 26, 2018 at 10:09:14AM +0000, A.s. Dong wrote: > Since Sascha is requesting to write a generic MU mailbox driver for both > SCU MU and M4 case, the current way using virtual channels in this patch > only send one word a time obviously can't fit for SCU MU clients well. > Do you think if we can refer to TI case to design a generic data transfer > protocol to allow send multi words which is more close to SCU? > include/linux/soc/ti/ti-msgmgr.h > struct ti_msgmgr_message { > size_t len; > u8 *buf; > }; > > Or we try to support both type transfer protocols in this driver? > That may introduce much complexities, personally I'm not quite > like that. To give you an idea what I am suggesting see the following patch. It implements SCU mode ontop of Oleksijs patch. Untested of course and as said, the mailbox framework lacks some way of synchronous receive, that would still have to be implemented and Jassi might have his own ideas how this could be done, but it doesn't add much complexity. Sascha ------------------------------8<-------------------------------- From fad77078a1f1b5719fcc3c1ab789ce9cca4c9212 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 26 Jun 2018 15:07:04 +0200 Subject: [PATCH] mailbox: imx-mu: Implement SCU mode Signed-off-by: Sascha Hauer --- drivers/mailbox/imx-mailbox.c | 89 +++++++++++++++++++++++++++- include/dt-bindings/mailbox/imx-mu.h | 10 ++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 include/dt-bindings/mailbox/imx-mu.h diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c index e3f621cb1d30..a4803d1eae1d 100644 --- a/drivers/mailbox/imx-mailbox.c +++ b/drivers/mailbox/imx-mailbox.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include /* Transmit Register */ #define IMX_MU_xTRn(x) (0x00 + 4 * (x)) @@ -28,7 +30,7 @@ /* Receive Interrupt Enable */ #define IMX_MU_xCR_RIEn(x) BIT(24 + (x)) -#define IMX_MU_MAX_CHANS 4u +#define IMX_MU_MAX_CHANS 5u struct imx_mu_priv; @@ -119,12 +121,80 @@ static bool imx_mu_last_tx_done(struct mbox_chan *chan) return (!!(val & IMX_MU_xSR_TEn(cp->bidx))); } +// Take from some include file +struct sc_rpc_msg { + uint8_t version; + uint8_t size; + uint8_t svc; + uint8_t func; +}; + +#define MU_DATA_TIME_OUT_US (100 * USEC_PER_MSEC) + +static int imx_mu_scu_send_data(struct imx_mu_priv *priv, void *data) +{ + struct sc_rpc_msg *msg = data; + uint32_t *msg_raw = data; + int i, ret; + + for (i = 0; i < msg->size + 1; i++) { + int index = i % 4; + uint32_t asr; + + /* Wait TX register to be empty. */ + ret = readl_poll_timeout_atomic(priv->base + IMX_MU_xSR, asr, + asr & IMX_MU_xSR_TEn(4 - index), + 0, MU_DATA_TIME_OUT_US); + if (ret) + goto out; + + writel(msg_raw[i], priv->base + IMX_MU_xTRn(4 - index)); + } + + ret = 0; +out: + mbox_chan_txdone(chan, ret); + return ret; +} + +static int imx_mu_scu_receive_data(struct imx_mu_priv *priv, void *data) +{ + struct sc_rpc_msg *msg = data; + uint32_t *msg_raw = data; + int i, ret, size = 8; + + for (i = 0; i < size; i++) { + int index = i % 4; + uint32_t asr; + + /* Wait TX register to be empty. */ + ret = readl_poll_timeout_atomic(priv->base + IMX_MU_xSR, asr, + asr & IMX_MU_xSR_RFn(4 - index), + 0, MU_DATA_TIME_OUT_US); + if (ret) + return ret; + + msg_raw[i] = readl(priv->base + IMX_MU_xRRn(4 - index)); + + if (i == 0) { + size = msg->size; + if (size > 7) + return -EINVAL; + } + } + + return 0; +} + static int imx_mu_send_data(struct mbox_chan *chan, void *data) { struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); struct imx_mu_con_priv *cp = chan->con_priv; u32 *arg = data; + if (cp->idx == IMX_MU_CHANNEL_IMX8_SCU) + return imx_mu_scu_send_data(priv, data); + if (!imx_mu_last_tx_done(chan)) return -EBUSY; @@ -134,6 +204,17 @@ static int imx_mu_send_data(struct mbox_chan *chan, void *data) return 0; } +static int imx_mu_receive_data(struct mbox_chan *chan, void *data) +{ + struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); + struct imx_mu_con_priv *cp = chan->con_priv; + + if (cp->idx == IMX_MU_CHANNEL_IMX8_SCU) + return imx_mu_scu_receive_data(priv, data); + + return -EINVAL; +} + static int imx_mu_startup(struct mbox_chan *chan) { struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox); @@ -166,6 +247,12 @@ static void imx_mu_shutdown(struct mbox_chan *chan) static const struct mbox_chan_ops imx_mu_ops = { .send_data = imx_mu_send_data, + /* + * FIXME: This has to be implemented in the mailbox framework. + * Currently there is only support for asynchronous read using + * callbacks which is not suitable for the SCU usecase. + */ +// .synchronous_read = imx_mu_receive_data, .startup = imx_mu_startup, .shutdown = imx_mu_shutdown, }; diff --git a/include/dt-bindings/mailbox/imx-mu.h b/include/dt-bindings/mailbox/imx-mu.h new file mode 100644 index 000000000000..4836266a7e57 --- /dev/null +++ b/include/dt-bindings/mailbox/imx-mu.h @@ -0,0 +1,10 @@ +#ifndef __DT_BINDINGS_MAILBOX_IMX_MU_H +#define __DT_BINDINGS_MAILBOX_IMX_MU_H + +#define IMX_MU_CHANNEL0 0 +#define IMX_MU_CHANNEL1 1 +#define IMX_MU_CHANNEL2 2 +#define IMX_MU_CHANNEL3 3 +#define IMX_MU_CHANNEL_IMX8_SCU 4 + +#endif /* __DT_BINDINGS_MAILBOX_IMX_MU_H */