From patchwork Tue Sep 18 09:34:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 10603917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BF305A4 for ; Tue, 18 Sep 2018 09:35:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C3AA2A116 for ; Tue, 18 Sep 2018 09:35:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 400BC2A126; Tue, 18 Sep 2018 09:35:04 +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 DB7DD2A116 for ; Tue, 18 Sep 2018 09:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729697AbeIRPGt (ORCPT ); Tue, 18 Sep 2018 11:06:49 -0400 Received: from mail-out.m-online.net ([212.18.0.10]:53143 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729650AbeIRPGs (ORCPT ); Tue, 18 Sep 2018 11:06:48 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42DyWl63Znz1qwwF; Tue, 18 Sep 2018 11:34:59 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42DyWl57VHz1qr2Y; Tue, 18 Sep 2018 11:34:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id hZq7Dylz8JCJ; Tue, 18 Sep 2018 11:34:58 +0200 (CEST) X-Auth-Info: rsVpbuj/3Npz3LsVjZx+PJVvQVZeitB3ryYtOsO6s7Y= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 18 Sep 2018 11:34:58 +0200 (CEST) From: Lukasz Majewski To: Mark Brown Cc: Rob Herring , Mark Rutland , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH 1/3] dt-bindings: spi: Provide bindings for fsl dspi working in slave mode Date: Tue, 18 Sep 2018 11:34:35 +0200 Message-Id: <20180918093437.26799-2-lukma@denx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180918093437.26799-1-lukma@denx.de> References: <20180918093437.26799-1-lukma@denx.de> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit provides the description of new property: "fsl,spi-slave-mode" which enables support for DSPI driver working in slave mode. As the new compatible shall be used with SPI bus equipped with master device a new "spidev" based node has been introduced to avoid confusion. Signed-off-by: Lukasz Majewski --- Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt index 18eeafe359d8..b30af19a2bc5 100644 --- a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +++ b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt @@ -26,6 +26,7 @@ Optional SPI properties for slave nodes: - fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping the clock signal and deactivating chip select, at the end of a transfer. - bus-num : the slave chip chipselect signal number. +- fsl,spi-slave-mode: if present, controller runs in slave mode. Example: @@ -56,6 +57,13 @@ dspi0@4002c000 { fsl,spi-cs-sck-delay = <100>; fsl,spi-sck-cs-delay = <50>; }; + + spidev3@1 { + compatible = "fsl,vf610-dspi"; + spi-max-frequency = <30000000>; + reg = <1>; + fsl,spi-slave-mode; + }; }; From patchwork Tue Sep 18 09:34:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 10603921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40172157B for ; Tue, 18 Sep 2018 09:35:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 311152A116 for ; Tue, 18 Sep 2018 09:35:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 257412A126; Tue, 18 Sep 2018 09:35:20 +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 B34D02A116 for ; Tue, 18 Sep 2018 09:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728912AbeIRPHA (ORCPT ); Tue, 18 Sep 2018 11:07:00 -0400 Received: from mail-out.m-online.net ([212.18.0.9]:34816 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729487AbeIRPGt (ORCPT ); Tue, 18 Sep 2018 11:06:49 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42DyWn0PFdz1qx9G; Tue, 18 Sep 2018 11:35:01 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42DyWm6xbCz1qr2Y; Tue, 18 Sep 2018 11:35:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 4K95DQEcQN31; Tue, 18 Sep 2018 11:34:59 +0200 (CEST) X-Auth-Info: eZ77StSqVjRfIIwiZI9ofVWvB6mYtalXWjjjK4bANnw= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 18 Sep 2018 11:34:59 +0200 (CEST) From: Lukasz Majewski To: Mark Brown Cc: Rob Herring , Mark Rutland , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH 2/3] ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE mode) Date: Tue, 18 Sep 2018 11:34:36 +0200 Message-Id: <20180918093437.26799-3-lukma@denx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180918093437.26799-1-lukma@denx.de> References: <20180918093437.26799-1-lukma@denx.de> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The vf610 Vybryd can work in two DSPI modes - namely master and slave. Already we do support master mode. This commit serves as a prerequisite to add support for slave mode. For slave mode we do need to preserve the MCR register value to change its "mode" bit (31) according to the supported state. Signed-off-by: Lukasz Majewski --- drivers/spi/spi-fsl-dspi.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 7cb3ab0a35a0..472385f0a842 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -126,6 +126,7 @@ #define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000) struct chip_data { + u32 mcr_val; u32 ctar_val; u16 void_write_data; }; @@ -696,9 +697,9 @@ static int dspi_transfer_one_message(struct spi_master *master, else dspi->bytes_per_word = 4; - regmap_update_bits(dspi->regmap, SPI_MCR, - SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF, - SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF); + regmap_write(dspi->regmap, SPI_MCR, dspi->cur_chip->mcr_val | + SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF); + regmap_write(dspi->regmap, SPI_CTAR(0), dspi->cur_chip->ctar_val | SPI_FRAME_BITS(transfer->bits_per_word)); @@ -767,6 +768,11 @@ static int dspi_setup(struct spi_device *spi) return -ENOMEM; } + chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS; + + if (dspi->devtype_data->xspi_mode) + chip->mcr_val |= SPI_MCR_XSPI; + pdata = dev_get_platdata(&dspi->pdev->dev); if (!pdata) { @@ -964,8 +970,6 @@ static const struct regmap_config dspi_xspi_regmap_config[] = { static void dspi_init(struct fsl_dspi *dspi) { - regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS | - (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0)); regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR); if (dspi->devtype_data->xspi_mode) regmap_write(dspi->regmap, SPI_CTARE(0), From patchwork Tue Sep 18 09:34:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 10603919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBA3C157B for ; Tue, 18 Sep 2018 09:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABE332A116 for ; Tue, 18 Sep 2018 09:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A00B32A126; Tue, 18 Sep 2018 09:35:09 +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 442D02A116 for ; Tue, 18 Sep 2018 09:35:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729719AbeIRPGv (ORCPT ); Tue, 18 Sep 2018 11:06:51 -0400 Received: from mail-out.m-online.net ([212.18.0.9]:47813 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729695AbeIRPGv (ORCPT ); Tue, 18 Sep 2018 11:06:51 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42DyWp2Y6Hz1qx96; Tue, 18 Sep 2018 11:35:02 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42DyWp2JmKz1qr2Y; Tue, 18 Sep 2018 11:35:02 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 6M0bvvb4N8vZ; Tue, 18 Sep 2018 11:35:01 +0200 (CEST) X-Auth-Info: pwsWq3Jq9rnTc4tuFv1rUu8vI7rUrM3SDAzcPtLNq74= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 18 Sep 2018 11:35:01 +0200 (CEST) From: Lukasz Majewski To: Mark Brown Cc: Rob Herring , Mark Rutland , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH 3/3] ARM: dspi: Provide support for DSPI slave more operation (Vybryd vf610) Date: Tue, 18 Sep 2018 11:34:37 +0200 Message-Id: <20180918093437.26799-4-lukma@denx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180918093437.26799-1-lukma@denx.de> References: <20180918093437.26799-1-lukma@denx.de> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The NXP's Vybryd vf610 can work as a SPI slave device (the CS and clock signal are provided by master). It is possible to specify a single device to work in that mode. As we do use DMA for transferring data, the RX channel must be prepared for incoming data. Moreover, in slave mode we just set a subset of control fields in configuration registers (CTAR0, PUSHR). Signed-off-by: Lukasz Majewski --- drivers/spi/spi-fsl-dspi.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 472385f0a842..1d71f6fd2e0b 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -209,6 +209,14 @@ struct fsl_dspi { struct fsl_dspi_dma *dma; }; +static inline bool dspi_slave_mode(struct fsl_dspi *dspi) +{ + if (!(dspi->cur_chip->mcr_val & SPI_MCR_MASTER)) + return true; + + return false; +} + static u32 dspi_pop_tx(struct fsl_dspi *dspi) { u32 txdata = 0; @@ -230,6 +238,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) { u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi); + if (dspi_slave_mode(dspi)) + return data; + if (dspi->len > 0) cmd |= SPI_PUSHR_CMD_CONT; return cmd << 16 | data; @@ -326,6 +337,11 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) dma_async_issue_pending(dma->chan_rx); dma_async_issue_pending(dma->chan_tx); + if (dspi_slave_mode(dspi)) { + wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete); + return 0; + } + time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete, DMA_COMPLETION_TIMEOUT); if (time_left == 0) { @@ -781,6 +797,10 @@ static int dspi_setup(struct spi_device *spi) of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay", &sck_cs_delay); + + if (of_property_read_bool(spi->dev.of_node, + "fsl,spi-slave-mode")) + chip->mcr_val &= ~SPI_MCR_MASTER; } else { cs_sck_delay = pdata->cs_sck_delay; sck_cs_delay = pdata->sck_cs_delay; @@ -798,14 +818,18 @@ static int dspi_setup(struct spi_device *spi) ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate); chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) - | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0) - | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0) - | SPI_CTAR_PCSSCK(pcssck) - | SPI_CTAR_CSSCK(cssck) - | SPI_CTAR_PASC(pasc) - | SPI_CTAR_ASC(asc) - | SPI_CTAR_PBR(pbr) - | SPI_CTAR_BR(br); + | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0); + + if (chip->mcr_val & SPI_MCR_MASTER) { + chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode & + SPI_LSB_FIRST ? 1 : 0) + | SPI_CTAR_PCSSCK(pcssck) + | SPI_CTAR_CSSCK(cssck) + | SPI_CTAR_PASC(pasc) + | SPI_CTAR_ASC(asc) + | SPI_CTAR_PBR(pbr) + | SPI_CTAR_BR(br); + } spi_set_ctldata(spi, chip);