From patchwork Wed Dec 11 19:39:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 11286169 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 7DA6B1593 for ; Wed, 11 Dec 2019 19:40:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D70F2173E for ; Wed, 11 Dec 2019 19:40:15 +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="FgQpTSTB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727002AbfLKTkO (ORCPT ); Wed, 11 Dec 2019 14:40:14 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37865 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbfLKTkO (ORCPT ); Wed, 11 Dec 2019 14:40:14 -0500 Received: by mail-wr1-f66.google.com with SMTP id w15so25487418wru.4 for ; Wed, 11 Dec 2019 11:40:13 -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=BQmYkzxzuJFcEZEM1zZf6dMLQjogmuzV839YGrPJbCo=; b=FgQpTSTBkhSXGcl296Oqs66MZgJoxfXx7Bim02LCDBoV7hEBFTLWI7bTz4hncSbefv lPVjZGYITyVCPQzLPRwXln6FD2KEbfRZkTpUXTRXFvP86ZhrLMy5hbo9NvMDf72ZGUd7 0JzLoK4gmfnCQRT2aBXzLp68Q12G5FaCUTe6D/xfL/Q0L+K/91iHLMeDVeqJrAUnufzh 9gAGPUAU/VaYe6R3mYA4UzwGcxzh3JEhKE4Pwr7+398B7E/WwFJmZlS5SQvi8BT0bqKL yv6UMqrAK4CU4v+rDUjseSDCBgYYxci6pUdcDvPc2MJDVnC4Iv+qU05zpM4d4M/y8TFT /QMA== 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=BQmYkzxzuJFcEZEM1zZf6dMLQjogmuzV839YGrPJbCo=; b=WsnQODrctmHhuZnDAdsFPeq/9iLb2HysUi1J2SO5t7x0k4pkKkUIlBkcBCAlNHmfXB RhAWs3WWlY8Z0W5OVgXL/6FYqWcqdOK9W5IX2ciiIDge2BTDiLg9mpqm0H4hzAqEzsM2 mLf58iaTJqczqIctArqjLUVRPv0x68rTBpd1imA8Vy8NW0z5gP5WSo2bqzWSoBQkStzW Lap2VogsuTc+RFjA6551FVnrhyIGtOKPKIv91gsbk8GLgmOKeMER6V3VYbY053kVnKtj iS5dJDWiBJThjO21J9hLs3vaFpsdifluTU3hVcGnqSGJS8Nd+dNFYJuuzbPRiWHbE5dP Cu/w== X-Gm-Message-State: APjAAAWgTcw+vhnFACxU+8xOyKwSCds6aK0QcjKiFH6+rueKD2kT0iff sbErqycugO8DqBvtK0dNq4X+YA== X-Google-Smtp-Source: APXvYqxmrSljC7te1sBWtHOqGTVoBhPFhWAFPbU/E5oMvQVdyvKXT3hPX1LRSHLiBq6+Lk7IBkvLeQ== X-Received: by 2002:a5d:6a52:: with SMTP id t18mr1514397wrw.391.1576093212580; Wed, 11 Dec 2019 11:40:12 -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 x1sm3309964wru.50.2019.12.11.11.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 11:40:12 -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 1/3] spi: spi-ti-qspi: Remove unused macro for fclk frequency Date: Wed, 11 Dec 2019 20:39:52 +0100 Message-Id: <20191211193954.747745-2-jean.pihet@newoldbits.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191211193954.747745-1-jean.pihet@newoldbits.com> References: <20191211193954.747745-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 The fclk and its rate are retrieved from DT. Signed-off-by: Jean Pihet Cc: Ryan Barnett Cc: Conrad Ratschan Cc: Arnout Vandecappelle --- drivers/spi/spi-ti-qspi.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c index 3cb65371ae3b..a18835128ad0 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c @@ -79,8 +79,6 @@ struct ti_qspi { #define QSPI_COMPLETION_TIMEOUT msecs_to_jiffies(2000) -#define QSPI_FCLK 192000000 - /* Clock Control */ #define QSPI_CLK_EN (1 << 31) #define QSPI_CLK_DIV_MAX 0xffff From patchwork Wed Dec 11 19:39:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 11286173 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 E3AF9138D for ; Wed, 11 Dec 2019 19:40:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C411D22527 for ; Wed, 11 Dec 2019 19:40:16 +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="uQ6wD3OK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727119AbfLKTkQ (ORCPT ); Wed, 11 Dec 2019 14:40:16 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33807 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfLKTkQ (ORCPT ); Wed, 11 Dec 2019 14:40:16 -0500 Received: by mail-wr1-f65.google.com with SMTP id t2so25423651wrr.1 for ; Wed, 11 Dec 2019 11:40:14 -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=7tf7mfSQc2XBRyA6iBQyomQJYKh8y7vhPXY0uorTcMM=; b=uQ6wD3OKdk7vxkX1YUJRFpvmQlFFK1HQpVfMGmCNrc83oZBzhcoIfmZdGhS9As/G3b v4cpUOelehu7V+pQjYeZEj7084Ifsw0eOgV+gR+/9lvXQlWzkIPN2qSid/PBHcqzLDM4 X5Li9ttNqigmRwNCxQbI7RVEbKaJEhFQ/RZU/hkhhpZULALuyz3x6JCbovNBg1wdZo6l bcycDWM08t9++jK03xssoksDOILaXK+/CkZEU6SI/RFqJgV1mQTSga8qj9/06qh5Cm3K cltAK/XGcj0tG58/NRwNilcRM61ghwLKGx0gaXRVDYLXSIMss7k5llnvuupxuvcdbu/Z BvqQ== 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=7tf7mfSQc2XBRyA6iBQyomQJYKh8y7vhPXY0uorTcMM=; b=qiHIv0ZVWPBbovtxwoTxSI8bFd6OmQCX+m5aBkX2eaSc5j3vpaHGxnq8irzv0JRHNf XykBW2s/jXUHYn+kZaCxsrWcsRS+dkOoub2YZBZZQj70w4++UNW8F9FUV87jRlBYfCLe 4UjlgI8NARm/NtccroGwsUq6DNL+FrftkqbDb8OqWp5VT479yps1ANnz/sWY6JX/P9TR xT4lkeb0oRvZ7CtzwKFwc9bDZQi+L3bOFXd075Ofy/H5XWaEnMPRUCsmJZlZbg5uJiOS 0J/W+47Vreow72jTixI6VJgDUAHjoOjk2Y5i/hi9l0RaEnCW0drK5d86ixnPndhhA1RV aHOg== X-Gm-Message-State: APjAAAWDV4hhyH9qfT0cCG87CYQ6wiC06YO+FJrUWpMoSQ43l/4puty0 IJFpWKhT8R452X0PamPpd/92ICJwfdkKmw== X-Google-Smtp-Source: APXvYqwTHxnTVeomZ2NSfFHU0dVTZi5uxzaetWzqGEAhbZKAnrZs5h/Xj90zSu6iW5xPTyxwQHjGgw== X-Received: by 2002:adf:f288:: with SMTP id k8mr1685347wro.301.1576093213862; Wed, 11 Dec 2019 11:40:13 -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 x1sm3309964wru.50.2019.12.11.11.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 11:40:13 -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/3] spi: spi-ti-qspi: support large flash devices Date: Wed, 11 Dec 2019 20:39:53 +0100 Message-Id: <20191211193954.747745-3-jean.pihet@newoldbits.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191211193954.747745-1-jean.pihet@newoldbits.com> References: <20191211193954.747745-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 The TI QSPI IP has limitations: - the MMIO region is 64MB in size - in non-MMIO mode, the transfer can handle 4096 words max. Add support for bigger devices. Use MMIO and DMA transfers below the 64MB boundary, use software generated transfers above. Signed-off-by: Jean Pihet Cc: Ryan Barnett Cc: Conrad Ratschan Cc: Arnout Vandecappelle --- drivers/spi/spi-ti-qspi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c index a18835128ad0..aee4709d105e 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c @@ -522,6 +522,33 @@ static void ti_qspi_setup_mmap_read(struct spi_device *spi, u8 opcode, QSPI_SPI_SETUP_REG(spi->chip_select)); } +static int ti_qspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) +{ + struct ti_qspi *qspi = spi_controller_get_devdata(mem->spi->master); + size_t max_len; + + if (op->data.dir == SPI_MEM_DATA_IN) { + if (op->addr.val < qspi->mmap_size) { + /* Limit MMIO to the mmaped region */ + if (op->addr.val + op->data.nbytes > qspi->mmap_size) { + max_len = qspi->mmap_size - op->addr.val; + op->data.nbytes = min(op->data.nbytes, max_len); + } + } else { + /* + * Use fallback mode (SW generated transfers) above the + * mmaped region. + * Adjust size to comply with the QSPI max frame length. + */ + max_len = QSPI_FRAME; + max_len -= 1 + op->addr.nbytes + op->dummy.nbytes; + op->data.nbytes = min(op->data.nbytes, max_len); + } + } + + return 0; +} + static int ti_qspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) { @@ -572,6 +599,7 @@ static int ti_qspi_exec_mem_op(struct spi_mem *mem, static const struct spi_controller_mem_ops ti_qspi_mem_ops = { .exec_op = ti_qspi_exec_mem_op, + .adjust_op_size = ti_qspi_adjust_op_size, }; static int ti_qspi_start_transfer_one(struct spi_master *master, From patchwork Wed Dec 11 19:39:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 11286177 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 EA1C91593 for ; Wed, 11 Dec 2019 19:40:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C99362173E for ; Wed, 11 Dec 2019 19:40:17 +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="kujCsLCY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726986AbfLKTkR (ORCPT ); Wed, 11 Dec 2019 14:40:17 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55159 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727185AbfLKTkR (ORCPT ); Wed, 11 Dec 2019 14:40:17 -0500 Received: by mail-wm1-f68.google.com with SMTP id b11so8522627wmj.4 for ; Wed, 11 Dec 2019 11:40:15 -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=h6aD3ZwnsdG7TKWm0dgTcaqxnRc3IcXouy4MGbRCkRU=; b=kujCsLCY1yor+FFFDqrEFqahY0s7rgN8LbecSpHECQVcTOTGtWjkUKa6pt+r2us32M AkwZ7QR7aHetXsHPnC38l+eEf0dZ7YTi11We+jSvuGUUuaUs4xx2IB/7OJ8xKiLNhgp6 DnoRSbNzsGJO+S/1kui4C4dnq1f4l9Y7TJz5AMN6tB8wk8/KWlsLPaT2hb+5g4MFaQ06 dzAOuSWcx1/4noCq/3Mfem7hjyHbjFNpMVH9OjHRWnSmU2pnArKAYOH8ycQSkJvkILcj aQ586rLsiAb7Vb/0c9i1np7i6eQ+wg+K571bWAGJO/x3n9T78S6QB34g0xrxmvmvRm1X YOcA== 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=h6aD3ZwnsdG7TKWm0dgTcaqxnRc3IcXouy4MGbRCkRU=; b=iH4jZ6sGq71KGE8j8qs9+AWrJMR3tB/QOcgCHMW5zpTVQPaZqfVxVo/+HU/kP4oJzi vrayBq1jFaLKfc7nmP2JQ74t3HPAHznF/ZYYaNUC+IjXTdn20ir5f+80MIm37QRlBlGT 8NdmPOkRhHkRy4C5r0fhsyRPp/eI2B//jpIOVo7x6E+gOb1uP1lVI/YqsusRLeUePVpe U+4gGyqBppUIhJ/4VBNP+guHfA+Mimld+mTHtcrRwV0vj1opPk7nFSEGeOlBPInaL38f 6tBtU7+WMErWPJPfeYXi+ClRFdX97YMluYOoq+UT61XFvXInkXRVPZ4UtZ0Lz1oN+bqC lCPQ== X-Gm-Message-State: APjAAAWL0WG4JYDDruplFbsiSzikXl6SdwWMiMwUZvdrpyIwbdLyxVgS 3ymhiNDIFGprf2cFnLQe+Q8s4g== X-Google-Smtp-Source: APXvYqyg62SDpqGnNqjiXv5hgkclclMtPjpRCK5K6TEYzFRcIhPUEoIj181s3viZTu+oR0ZQSuzYuw== X-Received: by 2002:a1c:5419:: with SMTP id i25mr1749923wmb.150.1576093215057; Wed, 11 Dec 2019 11:40:15 -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 x1sm3309964wru.50.2019.12.11.11.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 11:40:14 -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 3/3] spi: spi-ti-qspi: optimize byte-transfers Date: Wed, 11 Dec 2019 20:39:54 +0100 Message-Id: <20191211193954.747745-4-jean.pihet@newoldbits.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191211193954.747745-1-jean.pihet@newoldbits.com> References: <20191211193954.747745-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 aee4709d105e..d37306cafd8b 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c @@ -313,6 +313,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; @@ -335,14 +337,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); @@ -351,8 +399,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;