From patchwork Tue Jan 29 20:55:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10787243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD66591E for ; Tue, 29 Jan 2019 20:55:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF8672D2C8 for ; Tue, 29 Jan 2019 20:55:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A34262D2CA; Tue, 29 Jan 2019 20:55:18 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,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 8D8802D2D1 for ; Tue, 29 Jan 2019 20:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbfA2UzK (ORCPT ); Tue, 29 Jan 2019 15:55:10 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40547 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729466AbfA2UzJ (ORCPT ); Tue, 29 Jan 2019 15:55:09 -0500 Received: by mail-lf1-f68.google.com with SMTP id v5so15699980lfe.7 for ; Tue, 29 Jan 2019 12:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KVn7rJu2HIS1t/pLrBEM9tglmF08bUzUVQnXDkx+btM=; b=mXjC6LeG56EHotJrntbS8szRPxBKea+HEGVLKE7ysgXPWRe4+i7Q2Pv3DXNmA4B2/2 px/a8gNzBglenLmMSek6T4K5e/91wpt6cm0MI1UvHeVbWkXDAwrwH9X1V7nPF7a0AmI6 Nu+ZEvahl53MLzha1tEjkAhTH5ffsEwX19E4c09spc3AUIQgj/09j2QEaTrfzKWLT0kM qyTUorrdzUZzKYxEVZe/JXfDc6pkqOVlyerBhL7q4sjiUTZ60+GaVobWlahqkE8eqJIJ QYlGMkwKTAulJHHMpVXoSK29zQt2uQmkBFf3uPc4uy9May5SHsybjq8+seBaDQjwKcZe SwkA== 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=KVn7rJu2HIS1t/pLrBEM9tglmF08bUzUVQnXDkx+btM=; b=HjE6n859PVGLh7H8/YyvbotiZPCxfNS3bWLN2NJAnZwH5niib8VCzZiMPTtu4u0bqW rUaMlKY7kuRa2vf0HmOdvF0KkaWyStm6uNqm7l3InLtW9EXmCc0BvnyZKB3nas9pTzXu dQg0+HON4uoMbfIDXgNCrzXeVp6xDGMC4QnGugWFHxUiZkAdev8/oIAtec7m2TKaQoXB o+3Q/zXi1qmygUnthAoHWlN+YQlRTgD17SSFoNRiBt9xG1thsUg79jTdW0WOGN9a6H47 Pcf0TWiBched8JRKZcK13OpJJU1Bl9PJDX6FtcXb6qWDv8SROFYY/qUqlDUCjcEe0D9Z qFsA== X-Gm-Message-State: AJcUukfYQxY5NbxOKVTnsXs8XJYaiVKyo3r8xNOdpx45PIZUqld56acW fiQ290mXn3KGZBHH3DknA1Zo8A== X-Google-Smtp-Source: ALg8bN6LrDYkgwzG24sPDTX/FjfgqfnSeLwlkmP/0rz21oVbSnkdrlOzizeIx75wrfLpfxyJZN7KPQ== X-Received: by 2002:a19:3fcf:: with SMTP id m198mr19527973lfa.106.1548795306270; Tue, 29 Jan 2019 12:55:06 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id o17sm3677287lff.77.2019.01.29.12.55.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 12:55:05 -0800 (PST) From: Jonas Bonn To: linux-kernel@vger.kernel.org Cc: Jonas Bonn , Mark Brown , Rob Herring , Mark Rutland , linux-spi@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v5 1/2] spi: support inter-word delay requirement for devices Date: Tue, 29 Jan 2019 21:55:01 +0100 Message-Id: <20190129205502.7741-2-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129205502.7741-1-jonas@norrbonn.se> References: <20190129205502.7741-1-jonas@norrbonn.se> 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 Some devices are slow and cannot keep up with the SPI bus and therefore require a short delay between words of the SPI transfer. The example of this that I'm looking at is a SAMA5D2 with a minimum SPI clock of 400kHz talking to an AVR-based SPI slave. The AVR cannot put bytes on the bus fast enough to keep up with the SoC's SPI controller even at the lowest bus speed. This patch introduces the ability to specify a required inter-word delay for SPI devices. It is up to the controller driver to configure itself accordingly in order to introduce the requested delay. Note that, for spi_transfer, there is already a field word_delay that provides similar functionality. This field, however, is specified in clock cycles (and worse, SPI controller cycles, not SCK cycles); that makes this value dependent on the master clock instead of the device clock for which the delay is intended to provide some relief. This patch leaves this old word_delay in place and provides a time-based word_delay_us alongside it; the new field fits in the struct padding so struct size is constant. There is only one in-kernel user of the word_delay field and presumably that driver could be reworked to use the time-based value instead. The time-based delay is limited to 8 bits as these delays are intended to be short. The SAMA5D2 that I've tested this on limits delays to a maximum of ~100us, which is already many word-transfer periods even at the minimum transfer speed supported by the controller. Signed-off-by: Jonas Bonn CC: Mark Brown CC: Rob Herring CC: Mark Rutland CC: linux-spi@vger.kernel.org CC: devicetree@vger.kernel.org --- drivers/spi/spi.c | 5 +++++ include/linux/spi/spi.h | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 0e0f2c62973c..448443adee3a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3050,6 +3050,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) * it is not set for this transfer. * Set transfer tx_nbits and rx_nbits as single transfer default * (SPI_NBITS_SINGLE) if it is not set for this transfer. + * Ensure transfer word_delay is at least as long as that required by + * device itself. */ message->frame_length = 0; list_for_each_entry(xfer, &message->transfers, transfer_list) { @@ -3120,6 +3122,9 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) !(spi->mode & SPI_RX_QUAD)) return -EINVAL; } + + if (xfer->word_delay_us < spi->word_delay_us) + xfer->word_delay_us = spi->word_delay_us; } message->status = -EINPROGRESS; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 916bba47d156..555ba125bb89 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -122,6 +122,8 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, * the spi_master. * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when * not using a GPIO line) + * @word_delay_us: microsecond delay to be inserted between consecutive + * words of a transfer * * @statistics: statistics for the spi_device * @@ -169,6 +171,7 @@ struct spi_device { const char *driver_override; int cs_gpio; /* LEGACY: chip select gpio */ struct gpio_desc *cs_gpiod; /* chip select gpio desc */ + uint8_t word_delay_us; /* inter-word delay */ /* the statistics */ struct spi_statistics statistics; @@ -721,6 +724,8 @@ extern void spi_res_release(struct spi_controller *ctlr, * @delay_usecs: microseconds to delay after this transfer before * (optionally) changing the chipselect status, then starting * the next transfer or completing this @spi_message. + * @word_delay_us: microseconds to inter word delay after each word size + * (set by bits_per_word) transmission. * @word_delay: clock cycles to inter word delay after each word size * (set by bits_per_word) transmission. * @transfer_list: transfers are sequenced through @spi_message.transfers @@ -803,6 +808,7 @@ struct spi_transfer { #define SPI_NBITS_DUAL 0x02 /* 2bits transfer */ #define SPI_NBITS_QUAD 0x04 /* 4bits transfer */ u8 bits_per_word; + u8 word_delay_us; u16 delay_usecs; u32 speed_hz; u16 word_delay; From patchwork Tue Jan 29 20:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10787241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CDF191E for ; Tue, 29 Jan 2019 20:55:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CABD2D2C8 for ; Tue, 29 Jan 2019 20:55:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80BF32D2D5; Tue, 29 Jan 2019 20:55:17 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,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 6CFEB2D2C8 for ; Tue, 29 Jan 2019 20:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727686AbfA2UzP (ORCPT ); Tue, 29 Jan 2019 15:55:15 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33774 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729496AbfA2UzK (ORCPT ); Tue, 29 Jan 2019 15:55:10 -0500 Received: by mail-lf1-f65.google.com with SMTP id i26so15765386lfc.0 for ; Tue, 29 Jan 2019 12:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Adu7r7feIgD220eJhrZ8nREsuxr7WzIV5vIaaUUOmX8=; b=R2s3ESfnLLcxPKelxgl+NXEG8xnvOoijCdQhE07518wuxwwp0VMih0qBEWxulr+AsV q6sFN/bNB/N+ZAoRy5S/+rJDQOR4bMFDOVunBdWem8tPCRvchZt0Gk9QMyS6vRV6+9vU HFnDNPmjjWj/revgDQRb9LK2xRBiPB8dFhr2T1VEVB/1xEBB9s42JNyRyrozyTwy5bqI 6nDwfnhs1c8RofkvOYeGxPAnrs+yMnif1a1pSa0R19GVUL/oi7YgREisDqDUa7wbUUYH pKdL2rxbl/m6EYvYhVaZpAh6YmM3SkDS1TBXXYXDi2tWQ7jjP+Yv/6QKPr4SRiG6g1gO 38pQ== 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=Adu7r7feIgD220eJhrZ8nREsuxr7WzIV5vIaaUUOmX8=; b=rcj3jVlGo8WapMSP5Us2W0Ca+8BKJGafQMswa/has+3rNEekbTMU/93MEnTd0cyzO7 bZDfM3J58nF+3NC0FoilkVrOVA4v/gFW29swwSFcKJ6ge0/oCKcB7VktAey4AtM7DkHq Ee8BTiXH6cJbgeXOWPL4AAtWdpqp82BHCyippb54S1NH/BlQ5It/X3l4ubDKvu/UjFp5 anadzskSNZYzc7FzLT+b1Ad/qreCkqgfgJ/jhz41L8ke2aQg7ecvYcMNfY6cPkF0l/a1 QfpthvJfNiYg2Ezu2nWvYWVB53zdUVsK8Lfkj53ebyjlBxf6pw9doS3zlSmVu8VZiu4w z9hw== X-Gm-Message-State: AJcUukdUl81EClWOqkBHIYTsMkJnMXXx7VDrseCAS9x63iIUr/WaApGD 38+t3S9vAlU2sAVPHon3KWTGwg== X-Google-Smtp-Source: ALg8bN4tEAq/wKoIVj0YK0yHNk+mhqAeMD87gXVK3Y26fyShCMUnlSClIx4Kj+/8zfro6UrYIRvSZA== X-Received: by 2002:a19:980f:: with SMTP id a15mr21220369lfe.103.1548795307852; Tue, 29 Jan 2019 12:55:07 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id o17sm3677287lff.77.2019.01.29.12.55.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 12:55:07 -0800 (PST) From: Jonas Bonn To: linux-kernel@vger.kernel.org Cc: Jonas Bonn , Nicolas Ferre , Mark Brown , Alexandre Belloni , Ludovic Desroches , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 2/2] spi-atmel: support inter-word delay Date: Tue, 29 Jan 2019 21:55:02 +0100 Message-Id: <20190129205502.7741-3-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129205502.7741-1-jonas@norrbonn.se> References: <20190129205502.7741-1-jonas@norrbonn.se> 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 If the SPI slave requires an inter-word delay, configure the DLYBCT register accordingly. Tested on a SAMA5D2 board (derived from SAMA5D2-Xplained reference board). Signed-off-by: Jonas Bonn CC: Nicolas Ferre CC: Mark Brown CC: Alexandre Belloni CC: Ludovic Desroches CC: linux-spi@vger.kernel.org CC: linux-arm-kernel@lists.infradead.org Acked-by: Nicolas Ferre --- drivers/spi/spi-atmel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index f53f0c5e63da..57cc7110f9e8 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -1201,13 +1201,14 @@ static int atmel_spi_setup(struct spi_device *spi) csr |= SPI_BIT(CSAAT); /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs. - * - * DLYBCT would add delays between words, slowing down transfers. - * It could potentially be useful to cope with DMA bottlenecks, but - * in those cases it's probably best to just use a lower bitrate. */ csr |= SPI_BF(DLYBS, 0); - csr |= SPI_BF(DLYBCT, 0); + + /* DLYBCT adds delays between words. This is useful for slow devices + * that need a bit of time to setup the next transfer. + */ + csr |= SPI_BF(DLYBCT, + (as->spi_clk / 1000000 * spi->word_delay_us) >> 5); asd = spi->controller_state; if (!asd) {