From patchwork Tue Jan 14 12:41:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 11332103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B63B014B4 for ; Tue, 14 Jan 2020 12:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94D252467C for ; Tue, 14 Jan 2020 12:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=newoldbits-com.20150623.gappssmtp.com header.i=@newoldbits-com.20150623.gappssmtp.com header.b="P/9NID94" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726106AbgANMlp (ORCPT ); Tue, 14 Jan 2020 07:41:45 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36171 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbgANMlo (ORCPT ); Tue, 14 Jan 2020 07:41:44 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so13562511wma.1 for ; Tue, 14 Jan 2020 04:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newoldbits-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RuFcvURIwl3QEskF2/O6O3xS34vena8ygMjl8ypgEHw=; b=P/9NID945fj+tW2UHMVnT3ozdvK2MzX6RDZJWoGW/ef3oxygVKB0rhf9IH2tpkG/tD J1NpL8DdhBEGPGhVlh6XBrtOx12B0aIGuikoUKUgvePAvztiK0AB9+cgQIDycBdlYgrW Np/eTUdbmsO6q3ju5kjPxFgN5YhhjDDIZeoFbbl4TJQ/eQtPyy9YAw9TLqSLG9VnjZwA gxUG9b3kg/kSug+Q1nq/quSe58QI/+XBycrL/Jkptpx3huukjy/IaPn8iCDFvftz/20U cZuQwzapdRI3mzzR7PZ1M9OKlovGodHmoo9jznr6vt5G0URAXoWzOjsvDXf1snqHlGBK 5zlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RuFcvURIwl3QEskF2/O6O3xS34vena8ygMjl8ypgEHw=; b=eO5/Ij3KWjpOPdVgIf/90uCi4y/aWMDtH/x1Zu39yr9hc2FCHTraBG4iG7dkFM2Pj3 AJJaSbIuycl3PA2a1VIX2gJ26KzGhg7IwqkSKx9U+LfqmStJSmZyc0kcN4+k0wBmLHPC CP+FD6YwAYOGmEnFOQVqYM9oorBEbk2cDSAJ2aMY3vHGb5jG8ke85aB7JPNq1sN3lJeP 20tg+kTH80Kyc6/KN+NnQgJQaWVNC6OlIysM3wco43nIe5Te8cdcUGPm30C3W7ixYsQk OGkZX23CtfCkQiWiWSHtxmhEP+cRn8ctw9nomCmvD0bQtYCtIpVCx+8rw8exz6fbjc14 eu3w== X-Gm-Message-State: APjAAAUmugKsPs93oKlILY2fDrTpn6YvQhZ4KZjYKE7899KBDB45oGdW y37CjBpIMmnLKfmRS3m83jGtDQ== X-Google-Smtp-Source: APXvYqyz9OBeckCVBa1MPx1CpVOp9iXJMMupsGydT1vzHC77j7stWudOPiXkh82lnDgkCPBhBesxew== X-Received: by 2002:a1c:f20c:: with SMTP id s12mr27616650wmc.173.1579005702690; Tue, 14 Jan 2020 04:41:42 -0800 (PST) Received: from msilabo.lan (241.33-200-80.adsl-dyn.isp.belgacom.be. [80.200.33.241]) by smtp.gmail.com with ESMTPSA id i5sm18260185wml.31.2020.01.14.04.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 04:41:42 -0800 (PST) From: Jean Pihet To: Mark Brown , Tony Lindgren , Vignesh Raghavendra Cc: linux-omap@vger.kernel.org, linux-spi@vger.kernel.org, Ryan Barnett , Conrad Ratschan , Arnout Vandecappelle , Jean Pihet Subject: [PATCH 2/2] spi: spi-ti-qspi: optimize byte-transfers Date: Tue, 14 Jan 2020 13:41:25 +0100 Message-Id: <20200114124125.361429-3-jean.pihet@newoldbits.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114124125.361429-1-jean.pihet@newoldbits.com> References: <20200114124125.361429-1-jean.pihet@newoldbits.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Optimize the 8-bit based transfers, as used by the SPI flash devices, by reading the data registers by 32 and 128 bits when possible and copy the contents to the receive buffer. The speed improvement is 4.9x using quad read. Signed-off-by: Jean Pihet Cc: Ryan Barnett Cc: Conrad Ratschan Cc: Arnout Vandecappelle --- drivers/spi/spi-ti-qspi.c | 54 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c index 0334e2926998..858fda8ac73e 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c @@ -314,6 +314,8 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t, { int wlen; unsigned int cmd; + u32 rx; + u8 rxlen, rx_wlen; u8 *rxbuf; rxbuf = t->rx_buf; @@ -336,14 +338,60 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t, if (qspi_is_busy(qspi)) return -EBUSY; + switch (wlen) { + case 1: + /* + * Optimize the 8-bit words transfers, as used by + * the SPI flash devices. + */ + if (count >= QSPI_WLEN_MAX_BYTES) { + rxlen = QSPI_WLEN_MAX_BYTES; + } else { + rxlen = min(count, 4); + } + rx_wlen = rxlen << 3; + cmd &= ~QSPI_WLEN_MASK; + cmd |= QSPI_WLEN(rx_wlen); + break; + default: + rxlen = wlen; + break; + } + ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG); if (ti_qspi_poll_wc(qspi)) { dev_err(qspi->dev, "read timed out\n"); return -ETIMEDOUT; } + switch (wlen) { case 1: - *rxbuf = readb(qspi->base + QSPI_SPI_DATA_REG); + /* + * Optimize the 8-bit words transfers, as used by + * the SPI flash devices. + */ + if (count >= QSPI_WLEN_MAX_BYTES) { + u32 *rxp = (u32 *) rxbuf; + rx = readl(qspi->base + QSPI_SPI_DATA_REG_3); + *rxp++ = be32_to_cpu(rx); + rx = readl(qspi->base + QSPI_SPI_DATA_REG_2); + *rxp++ = be32_to_cpu(rx); + rx = readl(qspi->base + QSPI_SPI_DATA_REG_1); + *rxp++ = be32_to_cpu(rx); + rx = readl(qspi->base + QSPI_SPI_DATA_REG); + *rxp++ = be32_to_cpu(rx); + } else { + u8 *rxp = rxbuf; + rx = readl(qspi->base + QSPI_SPI_DATA_REG); + if (rx_wlen >= 8) + *rxp++ = rx >> (rx_wlen - 8); + if (rx_wlen >= 16) + *rxp++ = rx >> (rx_wlen - 16); + if (rx_wlen >= 24) + *rxp++ = rx >> (rx_wlen - 24); + if (rx_wlen >= 32) + *rxp++ = rx; + } break; case 2: *((u16 *)rxbuf) = readw(qspi->base + QSPI_SPI_DATA_REG); @@ -352,8 +400,8 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t, *((u32 *)rxbuf) = readl(qspi->base + QSPI_SPI_DATA_REG); break; } - rxbuf += wlen; - count -= wlen; + rxbuf += rxlen; + count -= rxlen; } return 0;