Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5573890ima; Tue, 5 Feb 2019 14:15:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IajpUCm/SC/L1IOXrnrXICezyZr9GePIgXJkGp2A0L3V6dIG/ghfjOGX70PsOjJLRtZO2zr X-Received: by 2002:a63:9c1a:: with SMTP id f26mr6601696pge.381.1549404932277; Tue, 05 Feb 2019 14:15:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549404932; cv=none; d=google.com; s=arc-20160816; b=OOjqOw2ZBI6XYWRNkbDkvvw5RQARRWSaZdMOnP+cuZnnWa7c5TSGful0zRUY7fkuhR ubg/pRdD7XKO0yxyfEApSvrDAOgLFCmXrxr5TzwTQ54EiUXnBUnmifswj/H4Au38K6vc 8XYeamIW480Syvhtp7oc6RGOHxuslcc8Sq8QHz1otQYnEjwDS/qmRenck6p8NW7NmjN6 d/Xs28mVnKQw42ueiEU+o3O2iTfoFtPIwH6Y4STecgZr7iMurJ2OWP1siq7ffXSQBbfA nQK3CnKH6VHHLULT+eY6gqc8Z89vY2KUCCsUfSToauJFSBUYoCcvzt5oDtiMmYTzdlfj ux9A== 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=d7ByiLu3/erTTyxKL4mbtjPdjkzAxrgD2KUZ1F5MVe4=; b=Twxe0RLczNxxYRSSTRCmg9sSNftz4VcVid9qeYuso+Y/awJS34InyhrasVnR2j9QXW wrJccqfcSDrUb7ZzI9jO8LvSbhoEwBv/g55nKG8lzTfIRs9KjwbovSy3CFj2Jys3+XC9 ADLdv/4YlgQd5cIqw5kYz+KDpk1SlfPRLS08Z3X1I2P3aiTmWF/CZ/WVcZWudRZRJ1Co ogVNy/umlW5gg+WxQ6sRVQ7gUb5iWKQhxMq7mUea08mYqhBTsSGuGy+07vxeDo+m9Bzo VxRnevDMzc5bD34rj98G2LRsA970k2/66Ib+kmllpOhRnOY3A+UaMKGKtyj2D+ffUOsl sffQ== 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 q14si4051512pgq.197.2019.02.05.14.15.16; Tue, 05 Feb 2019 14:15:32 -0800 (PST) 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 S1730670AbfBEWO1 (ORCPT + 99 others); Tue, 5 Feb 2019 17:14:27 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:59714 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728300AbfBEWOR (ORCPT ); Tue, 5 Feb 2019 17:14:17 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43vJl96j9Vz1rNbn; Tue, 5 Feb 2019 23:14:13 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43vJl95CQjz1qqkX; Tue, 5 Feb 2019 23:14:13 +0100 (CET) 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 NvldWWKmQw75; Tue, 5 Feb 2019 23:14:11 +0100 (CET) X-Auth-Info: bEpiIsN9etJ3ZScjMB6s5jCf6flR6ck5wETZmHRlKuE= 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, 5 Feb 2019 23:14:11 +0100 (CET) From: Lukasz Majewski To: Mark Brown Cc: Mark Rutland , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Esben Haabendal , =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= , Andrey Smirnov , Shawn Guo , Stefan Agner , Sascha Hauer , Lukasz Majewski Subject: [PATCH v6] spi: spi-fsl-dspi: Provide support for DSPI slave mode operation (Vybryd vf610) Date: Tue, 5 Feb 2019 23:13:49 +0100 Message-Id: <20190205221349.16321-1-lukma@denx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180927150709.17010-1-lukma@denx.de> References: <20180927150709.17010-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 signals 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). For testing the spidev_test program has been used. Test script for this patch can be found here: https://github.com/lmajewski/tests-spi/blob/master/tests/spi/spi_tests.sh Signed-off-by: Lukasz Majewski --- Changes for v6: - Rebase to v5.0-rc4 (no code changes needed) - Change the patch topic from ARM: dspi: to spi: spi-fsl-dspi: Changes for v5: - Rebase to v5.0-rc1 (no code changes needed) Changes for v4: - Rebase to v4.20-rc5 (no code changes needed) Changes for v3: - Rebase to v4.20-rc2 (no code changes needed) Changes for v2: - Remove patch which adds extra NXP specific DTS property to support slave mode and reuse the generic one (spi-slave) - Remove patch which brings back the mcr_register local copy. It is not needed as generic SPI slave infrastructure is used. - Rewrite the code to use spi_controller_is_slave() helper functions --- drivers/spi/spi-fsl-dspi.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 5e10dc5c93a5..348682be9dd5 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -233,6 +233,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) { u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi); + if (spi_controller_is_slave(dspi->master)) + return data; + if (dspi->len > 0) cmd |= SPI_PUSHR_CMD_CONT; return cmd << 16 | data; @@ -329,6 +332,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 (spi_controller_is_slave(dspi->master)) { + 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) { @@ -798,14 +806,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 (!spi_controller_is_slave(dspi->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); @@ -970,8 +982,13 @@ 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)); + unsigned int mcr = SPI_MCR_PCSIS | + (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0); + + if (!spi_controller_is_slave(dspi->master)) + mcr |= SPI_MCR_MASTER; + + regmap_write(dspi->regmap, SPI_MCR, mcr); regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR); if (dspi->devtype_data->xspi_mode) regmap_write(dspi->regmap, SPI_CTARE(0), @@ -1027,6 +1044,9 @@ static int dspi_probe(struct platform_device *pdev) } master->bus_num = bus_num; + if (of_property_read_bool(np, "spi-slave")) + master->slave = true; + dspi->devtype_data = of_device_get_match_data(&pdev->dev); if (!dspi->devtype_data) { dev_err(&pdev->dev, "can't get devtype_data\n"); -- 2.11.0