From patchwork Sat Jan 26 16:32:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10782511 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 573BE1399 for ; Sat, 26 Jan 2019 16:32:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 432602E387 for ; Sat, 26 Jan 2019 16:32:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 374FD2E38A; Sat, 26 Jan 2019 16:32:31 +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 9AB292E387 for ; Sat, 26 Jan 2019 16:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726295AbfAZQc3 (ORCPT ); Sat, 26 Jan 2019 11:32:29 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37184 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbfAZQc2 (ORCPT ); Sat, 26 Jan 2019 11:32:28 -0500 Received: by mail-lf1-f66.google.com with SMTP id y11so9030573lfj.4 for ; Sat, 26 Jan 2019 08:32:26 -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=PsBSv2w17w6lFrPapCk73CTS8LZT3j2+sF5Y7dWKzLc=; b=VN86UBu8NBXSChaiDHPIstNyAefKEC644yIFDOL81BghZ99qWqiGI4VWBaPrtVo+1S K2hAmpRAt7//vves1VSuPUaUdz4yAnsjEQPYdukgaHSVgxxgJ6rCJdgaB78Q7/nGNum7 2nWXt14pDtC3/z57oLpwMD8LoHhcJxMu1ZiAhQeASDKqJzmeTogsRbkMHpxh3eY17+fd eqW9vCKXIxQOqQGE+hwH+fWGjy0+g8d+AUVUOa7mS8ShT3t/OjFr075jfkO3LR4BlCP6 j58ehEqZ3rOK/s1teXBzJWt55x4rd7OWdBsfxpgVe/ZFQ2IIcOGtbKlYibtpppGcfRog 6+jQ== 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=PsBSv2w17w6lFrPapCk73CTS8LZT3j2+sF5Y7dWKzLc=; b=ChfKy0BP0YAfsflmP0bEaFpE8pYnHX+EWslmzQIuguNOlZYpM6rrGNcd6S7NmX28Hp g08OKHUuIRP8TcFf6ZsMRRQz35dFnDf5yWDOkwQxZncvBA4ycu8a539pfmTyE/GPpSwB 8K9p20QjfFgMjKC87P7AjT2MaSTeui2vvrlS8fbT8xzxzj0Ji2IiDBDO/uBzpU9l468U IPrvCJem87fRUSxmWDjvEtpRWCMB4TTo5yMSbuFVqtM37nm3sptyv2h8jt4jU79BidhU uiZHY/dUxtYW6XeVKauAUuX4cQzP23q+raq6bCx7aWMl3XbH7X8RN0zP4yBSKPmaR1yo V49g== X-Gm-Message-State: AJcUukckSDcajRUR6qySuB9jt7+F0B2/W/HHQIcghTTu1ezkWqq90v7M 0NXX+c8cvMj30qQl5Dl/HPmyOQ== X-Google-Smtp-Source: ALg8bN7LcYWaZVZJURFcXQFktVTSS0vQsLo6bWUgWp5pDrNVMQnth9Xh5ER9AATWYrc84v+OnUyDwQ== X-Received: by 2002:a19:c954:: with SMTP id z81mr11943281lff.150.1548520345708; Sat, 26 Jan 2019 08:32:25 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id e94sm2170532lfi.23.2019.01.26.08.32.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 08:32:25 -0800 (PST) From: Jonas Bonn To: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Cc: Jonas Bonn , Mark Brown , Rob Herring , Mark Rutland , devicetree@vger.kernel.org Subject: [PATCH v3 1/2] spi: support inter-word delay requirement for devices Date: Sat, 26 Jan 2019 17:32:19 +0100 Message-Id: <20190126163220.26421-2-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190126163220.26421-1-jonas@norrbonn.se> References: <20190126163220.26421-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. 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 --- include/linux/spi/spi.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 314d922ca607..8e410de02af4 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -118,6 +118,8 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, * for driver coldplugging, and in uevents used for hotplugging * @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when * not using a GPIO line) + * @word_delay: microsecond delay to be inserted between consecutive words + * of a transfer * * @statistics: statistics for the spi_device * @@ -164,6 +166,7 @@ struct spi_device { char modalias[SPI_NAME_SIZE]; const char *driver_override; int cs_gpio; /* chip select gpio */ + uint16_t word_delay; /* inter-word delay (us) */ /* the statistics */ struct spi_statistics statistics; From patchwork Sat Jan 26 16:32:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10782515 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 E383B91E for ; Sat, 26 Jan 2019 16:36:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D272929E46 for ; Sat, 26 Jan 2019 16:36:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6F6D2A51E; Sat, 26 Jan 2019 16:36:25 +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 6946E29E46 for ; Sat, 26 Jan 2019 16:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726215AbfAZQgU (ORCPT ); Sat, 26 Jan 2019 11:36:20 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45547 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbfAZQc3 (ORCPT ); Sat, 26 Jan 2019 11:32:29 -0500 Received: by mail-lf1-f65.google.com with SMTP id b20so9008987lfa.12 for ; Sat, 26 Jan 2019 08:32:27 -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=H4asA/HrfRTCLZ9s+7ODb9ujqrC02barVnHHP3w4OeE=; b=1Dw3YGg8xJI9+QrCu/LPqQ7Tr/GpytlL6Sj9JOqPWV3qR7JsVOZvTwcLkBmBXK2uSZ TFcurMiTzkCaWD95yVxh4ISXWz4SAVqgOKY1IaZeYUf/9QFNcV5k7bFGLvIHyADk5vWy +YN52P1zK5m6I6mEfnSzjP8VWEep9DACZXPu6VHTUPEnrcK28uoeDKgzsfU/E8PH800R HaXLsnx/buy6A5AdzNPoivt2pFHTu4B9tUtKGGpSKXpY9ygCjl8VdKWo/P9tOtBlfeyL shX85Yq4wrOuH5UporbikUTEjIY4YqXfIDN1Ar/apyBE8ldFeEmDCvW4015QH3UkobIS lhhQ== 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=H4asA/HrfRTCLZ9s+7ODb9ujqrC02barVnHHP3w4OeE=; b=emSOcGpguZ+peYT0T5b879T0+Jrc29AAbVMK/l+GzY7jzZfHUkKLvn+4BSE2DdNbpd buJsYTrBmpbo6wsKAcUtRk40hpWJWuN7Yp2cebut5BRZYf3PX6TzoRYDSDV06dz/jDRC hr44ONsw3TCe41zXoLTikZAjOSEo7weJCZKZAk8kFfUeyt0++YA1IlAvh1ZD62wo1RCW vwDM61PSOQxjEuEdglVu/FnBqXgaMIwvARRWSx4rGxnpv8FjJR/s4kdp0tkpy1NgIwcW YATg+FalOZQsw9r0dlHvxiIFDY1sLT1F+SuZrm4aqvhPOiWXwpUHBFBwEHMVI8wzO9gH cpvg== X-Gm-Message-State: AJcUukfS0e50m8hyXChkZ/4/oM83X5OkVZaXKV01NoOfYxzIahS0UTYb uI7R0PmyQ80fsitrvk48uWdM3g== X-Google-Smtp-Source: ALg8bN7ixO5jynANWXsRXQCc6pion+WBh06LKAJNIlpvS/JPjjM6Ib4nje2yFpEoX9h2Cy6IwOzaeA== X-Received: by 2002:a19:c4cc:: with SMTP id u195mr12471052lff.141.1548520346833; Sat, 26 Jan 2019 08:32:26 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id e94sm2170532lfi.23.2019.01.26.08.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 08:32:26 -0800 (PST) From: Jonas Bonn To: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Cc: Jonas Bonn , Nicolas Ferre , Mark Brown , Alexandre Belloni , Ludovic Desroches , linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/2] spi-atmel: support inter-word delay Date: Sat, 26 Jan 2019 17:32:20 +0100 Message-Id: <20190126163220.26421-3-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190126163220.26421-1-jonas@norrbonn.se> References: <20190126163220.26421-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 --- drivers/spi/spi-atmel.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 74fddcd3282b..24445bfbd74e 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -1209,13 +1209,21 @@ 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. + */ + if (spi->word_delay) { + csr |= SPI_BF(DLYBCT, + clamp_t(u8, + (as->spi_clk/1000000*spi->word_delay)>>5, + 1, 255)); + } else { + csr |= SPI_BF(DLYBCT, 0); + } + /* chipselect must have been muxed as GPIO (e.g. in board setup) */ npcs_pin = (unsigned long)spi->controller_data;