From patchwork Fri Jan 25 11:44:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10781235 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 16E29139A for ; Fri, 25 Jan 2019 11:44:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03A722EEE9 for ; Fri, 25 Jan 2019 11:44:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBE512EF09; Fri, 25 Jan 2019 11:44:37 +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 886712EF41 for ; Fri, 25 Jan 2019 11:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727955AbfAYLof (ORCPT ); Fri, 25 Jan 2019 06:44:35 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:47052 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbfAYLof (ORCPT ); Fri, 25 Jan 2019 06:44:35 -0500 Received: by mail-lf1-f65.google.com with SMTP id f5so6681837lfc.13 for ; Fri, 25 Jan 2019 03:44:34 -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=t213Fky0dlXC3LPSWsEKGnyugEHm5O3iqscObb9Pu/w=; b=1xYk19Kg544xWRSp+fgR6kC0YIM8F3jCjUq0+6joWIOq7QV/glm/vE+RGsKAHHVwJb rRxTuKotg8Ypz59HaO4dudfIJPU4iclpVgxhUUTwHnmGakWc8FFxVpHiIRTw0moO4EbZ p1Ibcb7FbSEdyav9ImSloKTh5hKDIpwLMdL1S3Bj76vv1g+pbzxP9YDH30UIUrSKtgEB NLL2Pq5Deb5Ds7akktjfKP5nO03xYopR5or3hUfrws4eEJ9pgLYYIGoqiNk7uQ3zgxwe ztefr/BN8pgSwJ+L8o6yL6C5Q1Aj7eMP+HG3jljdJhqj95rDvuQW+sbOste04lMhSQEO aghg== 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=t213Fky0dlXC3LPSWsEKGnyugEHm5O3iqscObb9Pu/w=; b=F9xwlKZSn2+LdWR0zVw2BV4oxJn7OQu9mQtzoMXG+RsQuJz8n37X7NsA4bB3S6yVJ2 usB/1pd57mmLdAJXcd7ZQJghi7oCV9sjoDfzPtiehRr6Sa0s9AOT+ZxkoD6vuN0lMgt1 M9DI/1q0UMWdnq+jWqxsxXp3tl10Hf06O5bqESAfXeBvMfYW6P5UAIWwhy+GonbidtYd ucdUPs+IBeRGO6YGIKIaeSirZmpkJWjSIVLUWLppto8pSjWQ8S+E8faqZZR/IMdtGCDe WiYzxTsQA2TgQ5y7XJcLD6ETix1vfvsiOgiHOyfyapmzInbzXnZNCKiHFi1INlkQSr+t UUog== X-Gm-Message-State: AJcUukdo5tiXAGsjZ8ZvP/gW2lxCjOykqcPiDiYrSsYeFmk178mZ1qz8 gt3RHKA3vxmyU3y92rqPGOd0hg== X-Google-Smtp-Source: ALg8bN4CGxebTCla8p8UY9zrtvRPivH2niOoBxryVUcWJMAUoaYMc65fTANBaUiBnLj7cosKJSXv+g== X-Received: by 2002:a19:a86:: with SMTP id 128mr8627485lfk.139.1548416673365; Fri, 25 Jan 2019 03:44:33 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id l3-v6sm1490962ljg.21.2019.01.25.03.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 03:44:32 -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 1/2] spi: support inter-word delay requirement for devices Date: Fri, 25 Jan 2019 12:44:28 +0100 Message-Id: <20190125114429.20066-2-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190125114429.20066-1-jonas@norrbonn.se> References: <20190125114429.20066-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 --- Documentation/devicetree/bindings/spi/spi-bus.txt | 1 + drivers/spi/spi.c | 4 ++++ include/linux/spi/spi.h | 1 + 3 files changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt index 1f6e86f787ef..a5f20060676d 100644 --- a/Documentation/devicetree/bindings/spi/spi-bus.txt +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt @@ -77,6 +77,7 @@ All slave nodes can contain the following optional properties: Defaults to 1 if not present. - spi-rx-delay-us - Microsecond delay after a read transfer. - spi-tx-delay-us - Microsecond delay after a write transfer. +- spi-word-delay-us - Microsecond delay between individual words of a transfer Some SPI controllers and devices support Dual and Quad SPI transfer mode. It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9a7def7c3237..cd4d4065eca2 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1692,6 +1692,10 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, } spi->max_speed_hz = value; + if (!of_property_read_u32(nc, "spi-word-delay-us", &value)) { + spi->word_delay = value; + } + return 0; } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 314d922ca607..e5200dd9d750 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -164,6 +164,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 Fri Jan 25 11:44:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10781237 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 9D38B17F0 for ; Fri, 25 Jan 2019 11:44:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C6082EEE2 for ; Fri, 25 Jan 2019 11:44:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8015A2EF09; Fri, 25 Jan 2019 11:44:38 +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 1CB6F2EEE9 for ; Fri, 25 Jan 2019 11:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726108AbfAYLoh (ORCPT ); Fri, 25 Jan 2019 06:44:37 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:42593 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726095AbfAYLog (ORCPT ); Fri, 25 Jan 2019 06:44:36 -0500 Received: by mail-lj1-f195.google.com with SMTP id l15-v6so8124257lja.9 for ; Fri, 25 Jan 2019 03:44:35 -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=Uu+GXREpN4UO7hWlKWeYJkb2H2GuTbzfegM7LkbZ/S8=; b=GEUhvkW0Aw6GHc3vSCXnmV8GTX+YAf3myHFSu3fzEAnbXvX5jP4hXHpfVi7RFjWnja elrrK7YvfIRcN9CgC/dZF3gn1rPhSfenaHc44zUrV1dK5Gl2X73Qp2C4YRSEWiyrJXYl ZErLRdaCPITbBF5zegxKL9TEv1aW3ySw7OiCPhQKLLJPLuw3ncrhK3VapBNZABn2IFKZ VEWtlB1mF61toNnCH8oEtzitthO/MpcHWX5gIyJyfqcLOEZpkLTVqrrrgL4rjQe962m8 /VKS6rDm++8Wdg1694dCdU/BOaExp+AHisTiVIFzbC8BBmVLmh0fD8k/4qNxrb2NNgeQ 3RIw== 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=Uu+GXREpN4UO7hWlKWeYJkb2H2GuTbzfegM7LkbZ/S8=; b=URvfdXc/tMebAebV7qqn+vTLpKqsSpNHjKPFdr4eJegtpd4aiaaWh07NG7L+xBleKm LKJXAEgXm318lI7u1SX/X7ruYFkHMO1rvuD+mniDhfXyYNzh3C4wWk2XDgHmAknTh94D 15L3rWnhg9u4R6AlbHOhGiLQnCmaMC+O/cSbx2v302TKhwKdy8wzfLvTTFBYYzJ1QtTv Y5A87gQ/YBdgNQPlTFWqH1mPmVkMg95gS4dicrH+hPfMP65h9bnrF1WC6LvjTjQMJBfZ jBu8M5sOmDzZi6mRqHysPr9Qq1fCF0yhJThLAtPmm/XCwyk+/qn2J91vcpqj3brMT95v WiRw== X-Gm-Message-State: AJcUukcj5ZjJ/RRm3OJZAoRbc9fr6mReJp8xnPf+uedYFthbmzU7p5Mj lPp7pz49X55jgOfaUz9gTst5hQ== X-Google-Smtp-Source: ALg8bN6XRXLKpFi04wXl+PQPSrzZMHYzuhRqTgfnNVEGIcDJwLrq8NNqXEeEDxsjqRcBDXesy2Gkrg== X-Received: by 2002:a2e:4a19:: with SMTP id x25-v6mr7678933lja.19.1548416674512; Fri, 25 Jan 2019 03:44:34 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id l3-v6sm1490962ljg.21.2019.01.25.03.44.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 03:44:34 -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 2/2] spi-atmel: support inter-word delay Date: Fri, 25 Jan 2019 12:44:29 +0100 Message-Id: <20190125114429.20066-3-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190125114429.20066-1-jonas@norrbonn.se> References: <20190125114429.20066-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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 74fddcd3282b..88ff3fef56e9 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -1209,13 +1209,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, + clamp_t(u8, (as->spi_clk/1000000*spi->word_delay)>>5, 1, 255)); /* chipselect must have been muxed as GPIO (e.g. in board setup) */ npcs_pin = (unsigned long)spi->controller_data;