From patchwork Fri Jan 25 12:24:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10781321 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 1C33C13B5 for ; Fri, 25 Jan 2019 12:24:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0974D2EE5E for ; Fri, 25 Jan 2019 12:24:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1F3D2EE71; Fri, 25 Jan 2019 12:24:44 +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 BFCF62EE23 for ; Fri, 25 Jan 2019 12:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726108AbfAYMYb (ORCPT ); Fri, 25 Jan 2019 07:24:31 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33211 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbfAYMYb (ORCPT ); Fri, 25 Jan 2019 07:24:31 -0500 Received: by mail-lj1-f194.google.com with SMTP id v1-v6so8245022ljd.0 for ; Fri, 25 Jan 2019 04:24:30 -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=ux28+rkiGYdzx/BIIXR9Dt412sbQF9EfCE0/FXheXQuGmB2DzBvMMITxFxJWwOE22h 3yQmuz01wfISkJwgcJdXynWm+L+7Z/d7L1eMsJRyoObFIp62Hg3q387btvSi3Pa//NXU pm16WLR9Xi8poduFYMCrD8dEK5OZvRCl+uQ/Ic6MvhaLXIX4AF052d9ZYleMWdoeIfbj ACfe+s++MiRS7G/8OW3C4IfxX6+MRsNJtzPAvmshP4Asx6VOG97wCcOdgcJXYpmRXYgU 8/1aL4GWaGu8n8eTFHmIyuDlXniAOSK9VwrmuOIyIVCRJWtr3/F+uMnkvgOm3T80jCFP xPSw== 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=mzqKrXYZJoQvSZB4mu6oePsCv4uFkOd3RNzC89sNTseTvnEjpDP+ldnqhfAzh17NFH gN5gWFoFWdar79SjZ0rjrLFcV1oTPTdhurgYOyk0E2EzN8ekph8T5Ey4HrhN9y1eXQf4 od+8xcf2YX6XSOf/MNaPEmuNGR5YmJ6YZfuF0QnvCdVz7zEvBuOja6zI5Grk2DHHIV9A F+0/v3oOS7FTuZKysPGhD6nZUoORBmn6cRRGuhocuy5OBIzVD90DohKVBftMTpwWjXv5 C85bBiseb5b6rv+/3IHY6oqN/NK4enX6gvSyLW4VGu7Gyd4ZIUkIL99jseaERg16I77E eD9Q== X-Gm-Message-State: AJcUukcVAuFimglyYzCxUbulmdLw6ofJJ2bRCNSuROcVWISkPjp4tjH4 ahPO9efONXhQOULoZwKf038zdA== X-Google-Smtp-Source: ALg8bN6ETeWG1r6djfeHOB2AkscgnzjCeqWd1IFZk+1jbAwo6p8CArdmPo5QVMe7Mr11r3mPkFXm1w== X-Received: by 2002:a2e:8087:: with SMTP id i7-v6mr8747843ljg.179.1548419069469; Fri, 25 Jan 2019 04:24:29 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id y81-v6sm1508376lje.30.2019.01.25.04.24.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 04:24:29 -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 v2 1/2] spi: support inter-word delay requirement for devices Date: Fri, 25 Jan 2019 13:24:24 +0100 Message-Id: <20190125122425.30676-2-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190125122425.30676-1-jonas@norrbonn.se> References: <20190125122425.30676-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 12:24:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 10781323 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 3E31113BF for ; Fri, 25 Jan 2019 12:24:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BB032EE23 for ; Fri, 25 Jan 2019 12:24:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D5E72EE34; Fri, 25 Jan 2019 12:24:45 +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 A8D782EE34 for ; Fri, 25 Jan 2019 12:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726630AbfAYMYn (ORCPT ); Fri, 25 Jan 2019 07:24:43 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:42382 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbfAYMYc (ORCPT ); Fri, 25 Jan 2019 07:24:32 -0500 Received: by mail-lj1-f196.google.com with SMTP id l15-v6so8217831lja.9 for ; Fri, 25 Jan 2019 04:24:31 -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=Be58ebP2NyXkKjVLpYKmbQRZZfz3qxFpZX7JJYIlPVc6kI0GGagVOkjSCFTr14Ep+t FlIUuKrIHL8l2PmaM4wewKSzvatj23DhHsfnun9xWLo0OS/geLz2KKMzWndKvVEz+Oy1 DTlyM6cACpHEwEssEelAj/7ctskzid88crHwIz36ABtIHF9JUT04DkyWk5t5Pp8KsKWa FeagTCAQNkJMnmDdG1TOui7yuBE4MZlzJCRRo8pN7L+2sbT3QFFCLKKieVOikawdEH/1 /KTwz+u9RAwyEOcAfFs72Rocd5M1PIxQVf8Qa/Inbule02RoAPGYLaKSh0eZJGq0qKtf JiWQ== 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=hGDWzorwI2aEmyZ99jNV2IOHqKRsIwx/yQn5KYqMggAcJlhaH64pwvHmvjCIebE37+ Snm6W1HP+k4RIvPXdNjxoINo90mwwx5PRU2K858WBPMp6uniOVTaSAbMjtjn7n/4AYaa T+kMFtJExbWwTETtWi6MnuftYtly69n9Eot/prPG0sSy5XmibWKcSn0i3Mr2zZvlXsGp kl2hC2y6eSqmSwu+t9waP2xxS+rV1RdR0/z/XUXlRJi1fcoi2h45i0GweYM3bA/9dDtL 5ZCnCqBc4LcORJzv6eMl2o7ejXoF3dIIagyxzyodt8qiQ2BHmGabDKmAO06Zpyaikz/A +Kdg== X-Gm-Message-State: AJcUukeAw7EEMKdulvpQ6WFfINGY0unUilcEKLIweAt+GPlyzQCWap30 l2rTd5gsh9J+cSEVZHT04+tEFQ== X-Google-Smtp-Source: ALg8bN4X4/JA2vr3rvz97Rl0G1OZlJYP7AKI1v1U8VIF8CdEcalqNEa9fD/7XSaILMfEB9KpjufNBQ== X-Received: by 2002:a2e:7d15:: with SMTP id y21-v6mr8583036ljc.77.1548419070963; Fri, 25 Jan 2019 04:24:30 -0800 (PST) Received: from mimer.lan (h-29-16.A159.priv.bahnhof.se. [79.136.29.16]) by smtp.gmail.com with ESMTPSA id y81-v6sm1508376lje.30.2019.01.25.04.24.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 04:24:30 -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 v2 2/2] spi-atmel: support inter-word delay Date: Fri, 25 Jan 2019 13:24:25 +0100 Message-Id: <20190125122425.30676-3-jonas@norrbonn.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190125122425.30676-1-jonas@norrbonn.se> References: <20190125122425.30676-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;