From patchwork Fri Nov 25 22:59:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9448191 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 39D2360235 for ; Fri, 25 Nov 2016 23:00:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29CD927CEA for ; Fri, 25 Nov 2016 23:00:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EB7827F88; Fri, 25 Nov 2016 23:00:54 +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 A728027CEA for ; Fri, 25 Nov 2016 23:00:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751056AbcKYXAx (ORCPT ); Fri, 25 Nov 2016 18:00:53 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:33486 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751126AbcKYXAw (ORCPT ); Fri, 25 Nov 2016 18:00:52 -0500 Received: by mail-wj0-f193.google.com with SMTP id kp2so7096801wjc.0 for ; Fri, 25 Nov 2016 15:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=M3SUJ4TCBEz8DNV6Zcz0hsa+77lhqRASUQwbwjcDWxQ=; b=iFRZAxTytRlSbsisDJrcvvpzYEZBAX32SMYVarGvJcQslUvIqVnxUMnW0TuuzKPEvb SqmbpYTGo6xbf5lCHI5Pt9G0L81RmHioP/40y6FTjuc9s6jnL7VhTObDd+3ajAlkO6U7 FhxAEO3i7GgGDlXL89aycUzePqVrnaAbIzyPC4oclbSfA7Mrv0VxQA0YX1XtPMlw53RW yzpOeRK2GbDx4rn2g4BOJU42O5ot0vyMzqTlly7HplqnVEc+vJ+yK3i0UTkVd+UAT9K5 gNqG0iAXPLv+waB0pD816SI1xRUcex1I0Pdu6RdZdCgqTVRYlXScQ9De9s+PhmzEJlOs bk9Q== 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:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=M3SUJ4TCBEz8DNV6Zcz0hsa+77lhqRASUQwbwjcDWxQ=; b=UEKhr0Hdo1F44Ny99jOHK+bCU5y0aNs0h/3RbAOsZGNZwDMZSOsOhYu8ZdFT/a/c7r E79O3dBDMe7nkfksoDLAnGiBFVkgeULOPcMobShaSuf/pZvGDtKqiNuXfuknpzlIH+7i r030S3HcRbNZLY6spkjgGUAwr5Rr9R++PByhiFwudGoJMgoyHFFl1VCx6jASz0tsCrDr fffBRmuGDP4ukMb3/caQ+QqHfdQ/8TcLS+zBdnsnNzKqNauLdtMF1/LIdFpzFS9gHURg Cv0OtFJDh9QlcMcaSVh3AcMkUG5btEaZJC8PtOyuExhe9pka/xDQlnJ0DHq802fRW89/ DIRA== X-Gm-Message-State: AKaTC00g4rAQd34yeQSaKn3Ij0162gaZ4bJdCFIDhoyNRTddPOz/TlwchIS36rp1Ej0yXA== X-Received: by 10.194.91.148 with SMTP id ce20mr10744757wjb.59.1480114851067; Fri, 25 Nov 2016 15:00:51 -0800 (PST) Received: from ?IPv6:2003:62:5f58:9d00:6166:92fb:e75e:7735? (p200300625F589D00616692FBE75E7735.dip0.t-ipconnect.de. [2003:62:5f58:9d00:6166:92fb:e75e:7735]) by smtp.googlemail.com with ESMTPSA id y4sm49283280wjp.0.2016.11.25.15.00.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Nov 2016 15:00:50 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 3/4] spi: fsl-espi: eliminate need for linearization when reading from hardware To: Mark Brown References: <2424ba57-be1a-d32d-0c14-1662c2d02409@gmail.com> Cc: "linux-spi@vger.kernel.org" Message-ID: <80a5a858-dc54-ea9d-3c6e-34fdedc516d7@gmail.com> Date: Fri, 25 Nov 2016 23:59:57 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <2424ba57-be1a-d32d-0c14-1662c2d02409@gmail.com> 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 Eliminate need for linearization when reading from the hardware and write to the transfer buffers directly. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 77 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 14 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 189ab36..e93892d 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -102,6 +102,9 @@ struct fsl_espi { struct spi_transfer *tx_t; unsigned int tx_pos; bool tx_done; + struct spi_transfer *rx_t; + unsigned int rx_pos; + bool rx_done; bool swab; unsigned int rx_len; @@ -125,6 +128,11 @@ static inline u32 fsl_espi_read_reg(struct fsl_espi *espi, int offset) return ioread32be(espi->reg_base + offset); } +static inline u16 fsl_espi_read_reg16(struct fsl_espi *espi, int offset) +{ + return ioread16(espi->reg_base + offset); +} + static inline u8 fsl_espi_read_reg8(struct fsl_espi *espi, int offset) { return ioread8(espi->reg_base + offset); @@ -328,19 +336,53 @@ static void fsl_espi_fill_tx_fifo(struct fsl_espi *espi, u32 events) static void fsl_espi_read_rx_fifo(struct fsl_espi *espi, u32 events) { u32 rx_fifo_avail = SPIE_RXCNT(events); + unsigned int rx_left; + void *rx_buf; - while (rx_fifo_avail >= min(4U, espi->rx_len) && espi->rx_len) - if (espi->rx_len >= 4) { - *(u32 *)espi->rx = fsl_espi_read_reg(espi, ESPI_SPIRF); - espi->rx += 4; - espi->rx_len -= 4; +start: + rx_left = espi->rx_t->len - espi->rx_pos; + rx_buf = espi->rx_t->rx_buf; + while (rx_fifo_avail >= min(4U, rx_left) && rx_left) { + if (rx_left >= 4) { + u32 val = fsl_espi_read_reg(espi, ESPI_SPIRF); + + if (rx_buf && espi->swab) + *(u32 *)(rx_buf + espi->rx_pos) = swahb32(val); + else if (rx_buf) + *(u32 *)(rx_buf + espi->rx_pos) = val; + espi->rx_pos += 4; + rx_left -= 4; rx_fifo_avail -= 4; + } else if (rx_left >= 2 && rx_buf && espi->swab) { + u16 val = fsl_espi_read_reg16(espi, ESPI_SPIRF); + + *(u16 *)(rx_buf + espi->rx_pos) = swab16(val); + espi->rx_pos += 2; + rx_left -= 2; + rx_fifo_avail -= 2; } else { - *(u8 *)espi->rx = fsl_espi_read_reg8(espi, ESPI_SPIRF); - espi->rx += 1; - espi->rx_len -= 1; + u8 val = fsl_espi_read_reg8(espi, ESPI_SPIRF); + + if (rx_buf) + *(u8 *)(rx_buf + espi->rx_pos) = val; + espi->rx_pos += 1; + rx_left -= 1; rx_fifo_avail -= 1; } + } + + if (!rx_left) { + if (list_is_last(&espi->rx_t->transfer_list, + espi->m_transfers)) { + espi->rx_done = true; + return; + } + espi->rx_t = list_next_entry(espi->rx_t, transfer_list); + espi->rx_pos = 0; + /* continue with next transfer if rx fifo is not empty */ + if (rx_fifo_avail) + goto start; + } } static void fsl_espi_setup_transfer(struct spi_device *spi, @@ -375,6 +417,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 fsl_espi *espi = spi_master_get_devdata(spi->master); + unsigned int rx_len = t->len; u32 mask, spcom; int ret; @@ -395,6 +438,7 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) spcom |= SPCOM_RXSKIP(espi->rxskip); espi->tx_len = espi->rxskip; espi->rx_len = t->len - espi->rxskip; + rx_len = t->len - espi->rxskip; espi->rx = t->rx_buf + espi->rxskip; if (t->rx_nbits == SPI_NBITS_DUAL) spcom |= SPCOM_DO; @@ -404,7 +448,7 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) /* enable interrupts */ mask = SPIM_DON; - if (espi->rx_len > FSL_ESPI_FIFO_SIZE) + if (rx_len > FSL_ESPI_FIFO_SIZE) mask |= SPIM_RXT; fsl_espi_write_reg(espi, ESPI_SPIM, mask); @@ -438,6 +482,10 @@ static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans) transfer_list); espi->tx_pos = 0; espi->tx_done = false; + espi->rx_t = list_first_entry(&m->transfers, struct spi_transfer, + transfer_list); + espi->rx_pos = 0; + espi->rx_done = false; espi->rxskip = fsl_espi_check_rxskip_mode(m); if (trans->rx_nbits == SPI_NBITS_DUAL && !espi->rxskip) { @@ -445,6 +493,10 @@ static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans) return -EINVAL; } + /* In RXSKIP mode skip first transfer for reads */ + if (espi->rxskip) + espi->rx_t = list_next_entry(espi->rx_t, transfer_list); + fsl_espi_copy_to_buf(m, espi); fsl_espi_setup_transfer(spi, trans); @@ -453,9 +505,6 @@ static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans) if (trans->delay_usecs) udelay(trans->delay_usecs); - if (!ret) - fsl_espi_copy_from_buf(m, espi); - return ret; } @@ -556,13 +605,13 @@ static void fsl_espi_cleanup(struct spi_device *spi) static void fsl_espi_cpu_irq(struct fsl_espi *espi, u32 events) { - if (espi->rx_len) + if (!espi->rx_done) fsl_espi_read_rx_fifo(espi, events); if (!espi->tx_done) fsl_espi_fill_tx_fifo(espi, events); - if (!espi->tx_done || espi->rx_len) + if (!espi->tx_done || !espi->rx_done) return; /* we're done, but check for errors before returning */