From patchwork Wed Nov 9 21:58:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9420211 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 D53956048E for ; Wed, 9 Nov 2016 21:58:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B983F29346 for ; Wed, 9 Nov 2016 21:58:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA8D9293B0; Wed, 9 Nov 2016 21:58:47 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 32C8429346 for ; Wed, 9 Nov 2016 21:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754106AbcKIV6q (ORCPT ); Wed, 9 Nov 2016 16:58:46 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33164 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754104AbcKIV6p (ORCPT ); Wed, 9 Nov 2016 16:58:45 -0500 Received: by mail-wm0-f66.google.com with SMTP id u144so31912559wmu.0 for ; Wed, 09 Nov 2016 13:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=A0c9b8XhOYGzuquR08Kdb5PLX2zs8J62YilOWQo7gAk=; b=0FN4P6k3+imDjm7Yqwp/wwY22zWiaXamDudgh9Nj8OHbx1BTzJCdeSdtf+VYTGPHj1 BF8qzHbku2RTj4IiOLiVBuEdevnfHjVLK6n/4tq9N34r+laS9uOYagTlzv5RUzwd+tTR x9SC2mYP0iTx9I1n0Le8pRWI2TsXrAG0SuV5+DrZV33Oj2xbA4jjy1RQBsUFy1ZkSWWd nuNDdRiCQj2xKRtHfHxPR1tQ+nfw9wF2DQxyCGiYsuGY3vmmBtnCGzIcHLRVHX1aD/Z7 Gn10e5WtYP2OAenoHekluwAjvMHcUe/zQ80knKm80/JGR0Dj+cNp/KPIwdUx8sJ9OMBD Yq1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=A0c9b8XhOYGzuquR08Kdb5PLX2zs8J62YilOWQo7gAk=; b=ky0IRA6Zpvo8ieyUYq8g/mIqc5QEn/KkijboubZl8ud3PQWm0bGGL+E6pdKF58Json +TaVWoZ3NSR4jXzRS/VGdOtgIVXAaqk3wDD/8dOhSWiCAk1YVl6B1CFSub+pQgZVKtvu 5Qq+NqV7Ea+rZJemUTRdb94e1M1aMO4Vgxym0ZZB5bVEE88UWouLMdCF/Me1m9S6p64s tW0y6rtY+OQ2FgFCkYKedOIyJN6DNUxTxQ491pqQzQeBndHGOY+qm4ILM2gnBKGn+aA4 Eb5Qnxgf8xMdb8kx8sKS2QYZ0hLbAHqx6COCTBsFWc1UOxDfOA92TecPzHm0R0Z0oLK1 QCig== X-Gm-Message-State: ABUngvfV4Mvz5r1uRJo1xVWlZ2bRNfksTP/FZrJIAw4cxgpahFkUHOIHq3PAtW9Fci6usA== X-Received: by 10.28.161.67 with SMTP id k64mr21135667wme.69.1478728724011; Wed, 09 Nov 2016 13:58:44 -0800 (PST) Received: from ?IPv6:2003:62:5f43:4700:28ed:b39a:a22f:1a25? (p200300625F43470028EDB39AA22F1A25.dip0.t-ipconnect.de. [2003:62:5f43:4700:28ed:b39a:a22f:1a25]) by smtp.googlemail.com with ESMTPSA id k74sm2539386wmd.18.2016.11.09.13.58.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 13:58:43 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 1/2] spi: fsl-espi: add support for ESPI RXSKIP mode To: Mark Brown Cc: "linux-spi@vger.kernel.org" Message-ID: <0e96f53c-5e83-77bd-a57a-2e576ca20019@gmail.com> Date: Wed, 9 Nov 2016 22:58:01 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 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 patch adds support for ESPI RXSKIP mode. This mode is optimized for flash reads: - sends a number of bytes and then reads a number of bytes - shifts out zeros automatically when reading Supporting RXSKIP mode is a prerequisite for supporting dual output read mode. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 51 ++++++++++++++++++++++++++++++++++++++++++---- drivers/spi/spi-fsl-lib.h | 1 + 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index edb524f..e147fa7 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -150,7 +150,8 @@ static void fsl_espi_copy_to_buf(struct spi_message *m, list_for_each_entry(t, &m->transfers, transfer_list) { if (t->tx_buf) fsl_espi_memcpy_swab(buf, t->tx_buf, m, t); - else + /* In RXSKIP mode controller shifts out zeros internally */ + else if (!mspi->rxskip) memset(buf, 0, t->len); buf += t->len; } @@ -203,6 +204,37 @@ static int fsl_espi_check_message(struct spi_message *m) return 0; } +static unsigned int fsl_espi_check_rxskip_mode(struct spi_message *m) +{ + struct spi_transfer *t; + unsigned int i = 0, rxskip = 0; + + /* + * prerequisites for ESPI rxskip mode: + * - message has two transfers + * - first transfer is a write and second is a read + * + * In addition the current low-level transfer mechanism requires + * that the rxskip bytes fit into the TX FIFO. Else the transfer + * would hang because after the first FSL_ESPI_FIFO_SIZE bytes + * the TX FIFO isn't re-filled. + */ + list_for_each_entry(t, &m->transfers, transfer_list) { + if (i == 0) { + if (!t->tx_buf || t->rx_buf || + t->len > FSL_ESPI_FIFO_SIZE) + return 0; + rxskip = t->len; + } else if (i == 1) { + if (t->tx_buf || !t->rx_buf) + return 0; + } + i++; + } + + return i == 2 ? rxskip : 0; +} + static void fsl_espi_fill_tx_fifo(struct mpc8xxx_spi *mspi, u32 events) { u32 tx_fifo_avail; @@ -281,7 +313,7 @@ static void fsl_espi_setup_transfer(struct spi_device *spi, static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) { struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); - u32 mask; + u32 mask, spcom; int ret; mpc8xxx_spi->rx_len = t->len; @@ -293,8 +325,18 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) reinit_completion(&mpc8xxx_spi->done); /* Set SPCOM[CS] and SPCOM[TRANLEN] field */ - fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM, - (SPCOM_CS(spi->chip_select) | SPCOM_TRANLEN(t->len - 1))); + spcom = SPCOM_CS(spi->chip_select); + spcom |= SPCOM_TRANLEN(t->len - 1); + + /* configure RXSKIP mode */ + if (mpc8xxx_spi->rxskip) { + spcom |= SPCOM_RXSKIP(mpc8xxx_spi->rxskip); + mpc8xxx_spi->tx_len = mpc8xxx_spi->rxskip; + mpc8xxx_spi->rx_len = t->len - mpc8xxx_spi->rxskip; + mpc8xxx_spi->rx = t->rx_buf + mpc8xxx_spi->rxskip; + } + + fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM, spcom); /* enable interrupts */ mask = SPIM_DON; @@ -326,6 +368,7 @@ static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans) struct spi_device *spi = m->spi; int ret; + mspi->rxskip = fsl_espi_check_rxskip_mode(m); fsl_espi_copy_to_buf(m, mspi); fsl_espi_setup_transfer(spi, trans); diff --git a/drivers/spi/spi-fsl-lib.h b/drivers/spi/spi-fsl-lib.h index 35a7a17..3951322 100644 --- a/drivers/spi/spi-fsl-lib.h +++ b/drivers/spi/spi-fsl-lib.h @@ -31,6 +31,7 @@ struct mpc8xxx_spi { #if IS_ENABLED(CONFIG_SPI_FSL_ESPI) unsigned int rx_len; unsigned int tx_len; + unsigned int rxskip; u8 *local_buf; spinlock_t lock; #endif