Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4994090imm; Tue, 18 Sep 2018 02:35:34 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaNXR67TZx0dVZYfrLOyk3pD3tE4piEnYSBQAHdYtL9sC56VJydT3+joU2MpUmbK0Gbdcun X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr27565516pgv.52.1537263334710; Tue, 18 Sep 2018 02:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537263334; cv=none; d=google.com; s=arc-20160816; b=k6TDkkcDFeVSwMGQtaeibtvf0HLjz83txb6VG83gkrwvdqxd8gFyisnNEaLOPHbSwp 3LPCwG/oDA6BLWuz6R8ayzuTnp8JCzatN+BWg5hIcnvomBv3Ysdkdaqm6TpFAEP6lu07 h/KXAOWGX0ZEwd4XqQIvFouFb9XQn/XMTYmxIc/uEjflJrho1l7rGTxfQHIfnFjc8OAU W/JOIAWEvaUZfQ1CmucVGo9/U38OqY1/rtaueQrByoK+eafj67UKpjUozHF9w0jmw+cW R/jrMb28n1TMtDkIgKrjW5hpOKI232NaPpx1uzDpfoVJy6O8l8CknxpTb0/Slx3tQpWS AtDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=NTqIUP9AfS8TXD+18iVtxDLQSL6RWJiZEp9YLh4KH7w=; b=dJvXbk3XOvA0gNeZVIEGPZ1d7ky/Kw5yAac3K3x3e+TjItLMczXRGEjeGHIo2FSoSA 368p1K6No6Uw9sw1xZkuiezMvmkgV/DT+KYeA9eQ+tEJeA1WIuRxcwSDynfEmVrkFj0Y SW0T2mMH0ifuzT4NTmRp2rD+Me3scExRui8a9yXeuUQAs7R+P/Tp+QDcH2JR2OwaC04O dg1ngRgC49TS9D19A6W8SYgihTWg5b2q88T1mL5ytGfhesqSM8CDZovkd7ck4uuNH7WW 5JSXNZrNlLd0ir73rNRmHQe6lUWVHcQHpnnkI3s39+u5nlVzsoG06lQU977DXMMMIOEJ wNzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4-v6si16924468pfn.340.2018.09.18.02.35.19; Tue, 18 Sep 2018 02:35:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729723AbeIRPGv (ORCPT + 99 others); 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.11.0