From patchwork Wed Nov 30 18:07:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 9454669 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 4C3DB60585 for ; Wed, 30 Nov 2016 18:08:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 454AA28497 for ; Wed, 30 Nov 2016 18:08:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36ED328483; Wed, 30 Nov 2016 18:08:27 +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.9 required=2.0 tests=BAYES_00,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 9111E28483 for ; Wed, 30 Nov 2016 18:08:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758511AbcK3SIK (ORCPT ); Wed, 30 Nov 2016 13:08:10 -0500 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:36050 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758286AbcK3SIG (ORCPT ); Wed, 30 Nov 2016 13:08:06 -0500 Received: from [2001:470:1f1d:6b5::3] (helo=debutante) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cC9IX-0005l5-4r; Wed, 30 Nov 2016 18:08:03 +0000 Received: from broonie by debutante with local (Exim 4.87) (envelope-from ) id 1cC9IU-0008OK-EV; Wed, 30 Nov 2016 18:07:58 +0000 From: Mark Brown To: Heiner Kallweit Cc: Mark Brown , Mark Brown , "linux-spi@vger.kernel.org" In-Reply-To: <80a5a858-dc54-ea9d-3c6e-34fdedc516d7@gmail.com> Message-Id: Date: Wed, 30 Nov 2016 18:07:58 +0000 X-SA-Exim-Connect-IP: 2001:470:1f1d:6b5::3 X-SA-Exim-Mail-From: broonie@sirena.org.uk Subject: Applied "spi: fsl-espi: eliminate need for linearization when reading from hardware" to the spi tree X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: No (on mezzanine.sirena.org.uk); Unknown failure 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 patch spi: fsl-espi: eliminate need for linearization when reading from hardware has been applied to the spi tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From dcb425f3ba6ebee4269f68461420246ba9d4ec02 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Fri, 25 Nov 2016 23:59:57 +0100 Subject: [PATCH] spi: fsl-espi: eliminate need for linearization when reading from hardware Eliminate need for linearization when reading from the hardware and write to the transfer buffers directly. Signed-off-by: Heiner Kallweit Signed-off-by: Mark Brown --- 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 189ab36b787f..e93892dca90a 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 */