From patchwork Tue Sep 25 14:32:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 147461 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp803457lji; Tue, 25 Sep 2018 07:32:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV63RCNEZKIY0BBBe3UoX8jjklt/C/fk0rxnhsdAuHL5kFXRbprIXTwP4jPxi/TDccdT7KeIb X-Received: by 2002:a17:902:8a97:: with SMTP id p23-v6mr1506442plo.21.1537885950255; Tue, 25 Sep 2018 07:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537885950; cv=none; d=google.com; s=arc-20160816; b=ObHplQSmRKT2zYHNqEf+zCye/q4reFhIoPLMoENfCYo8ruES4ebjGG+o86K+skOMkE VZ2DNTV2Id/ruGv6mPquQcd2w11jZCKDgWBTkMJ2xDVpz8ElXMdXzQh1eYeNdQEj/vcc Anb8OaGhmNSOdnWP2SUWNr57TOlon6MpZxcKc4vLRzRLAK7Ro/QLD+VOaHE+cJwhTHxQ P6rcy4UyimLcY2p0XQVG/fCjcZCtge+O8vOwRH4uPflxGqY+pfV7RE37XnkxhmkyJLZt fJscHW77xmxgCsOmEXye5t/o8N7lU/hTASORXctphweDZ+uTjKWKhiUlARU0uTzcw+IW sPNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=U4y6ZtputpXJXWyhFUlFmPRAtoxRofEKwhSqArkgoLA=; b=y+usTobObD5GMnxKRcQI5D9zfdlqLaJnmlgtFMTJnUQ9gRkFAuvC6zjZL6XCyqJX2E 4yQJteGPH/g53lbxDInGlCLEyxjLE30urI8kIQznocewmKm3X6b0AMCxuJQ6Rz9hVNe0 ZCAFkInByeM8NwttUVGbZvpAKbO4l4jWhkFOKJMwCDKkrABYTCGG+hYDYoDSorrjGuv+ aU4WzHgVDhtwHLrevTVDe2pGv6UdnrgG2Nx5Ia3fYSC5Pd433MHnMobNx3xPBnLs/0QZ EGZzfvcYjE6zgoQAAiraDHpw4rVatHDRGCpRR3mJM8lBFX1xmgbfefuQVnQnNFjfH4Qu V+cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLm9bszr; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3-v6si2505600pgo.542.2018.09.25.07.32.30; Tue, 25 Sep 2018 07:32:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLm9bszr; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729306AbeIYUkQ (ORCPT + 1 other); Tue, 25 Sep 2018 16:40:16 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:35846 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729199AbeIYUkP (ORCPT ); Tue, 25 Sep 2018 16:40:15 -0400 Received: by mail-lj1-f196.google.com with SMTP id p89-v6so5804365ljb.3 for ; Tue, 25 Sep 2018 07:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=U4y6ZtputpXJXWyhFUlFmPRAtoxRofEKwhSqArkgoLA=; b=WLm9bszrOwvsEjfs/3m34sOYZNZVbZyp2pnRx+zS1orGMnW3lV7JxktGgi0xrsDG+0 JpiDlwjK+/O4Ihh0+tZhMPU2YqIngeUBKSMzp7ywDLm2KeYRz1SRSD4BTZHmPAMj6v7l phEKWDI/T9578E8KlP+13sXTtJDvUcxuR10Kc= 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; bh=U4y6ZtputpXJXWyhFUlFmPRAtoxRofEKwhSqArkgoLA=; b=cDP+zurUAMEFZiDH6Tnl0PChkAigVeOfHsqJ8gjHaCt/R+kznyzs8UNXY4jzKwCO9E tMvaL+Zb71CPPuNnFMnihHiv4tXgtWq3rxDa3xdpr0QWZLxMbv5LNDuR6mAWddoI/Fm+ TPI3MnlSUsfRGiftJvg2hvqEP/9bMc7u+csjbd9K6MgcB8Q0Q60hJqcfhH6r3yqZXoGa 7oFn2KANUbBkBIiJlxHrezRcKhA18afn1ENNre+jHWEfcQZKWam8B/TB6kz1WhLizgGG eSmjuLkeBrJobc5WyzWqgVCgeUycxzREtOIPSaFM35LNCJzS1LP6aL2OpKAifluMODkO cwQQ== X-Gm-Message-State: ABuFfohmhVPN2mAQBIp9edGZ9hv05r1nP4M4QNqYHLGkUFkbtjDQlH9L FAZa1+IW+MapXSFN2IUp2+y5ww== X-Received: by 2002:a2e:900a:: with SMTP id h10-v6mr1090723ljg.121.1537885947316; Tue, 25 Sep 2018 07:32:27 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id d13-v6sm441020lfi.74.2018.09.25.07.32.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Sep 2018 07:32:25 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org, Andrzej Hajda , Lorenzo Bianconi Cc: linux-gpio@vger.kernel.org, Linus Walleij , devicetree@vger.kernel.org Subject: [PATCH 1/2] spi: Add a DT binding for high-impedance turn-around Date: Tue, 25 Sep 2018 16:32:19 +0200 Message-Id: <20180925143220.19007-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Some 3WIRE SPI devices require the host to insert a "high-impedance turn-around" essentially a clock pulse after switching the one line from output to input. This is needed to support the TPO TPG110 panel to use the 3WIRE SPI bindings. Cc: devicetree@vger.kernel.org Cc: Andrzej Hajda Cc: Lorenzo Bianconi Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Change some spelling, instert dash in high-impedance use turn-around instead of turnaround. --- Documentation/devicetree/bindings/spi/spi-bus.txt | 4 ++++ 1 file changed, 4 insertions(+) -- 2.17.1 diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt index 1f6e86f787ef..d0b2d88a20ee 100644 --- a/Documentation/devicetree/bindings/spi/spi-bus.txt +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt @@ -70,6 +70,10 @@ All slave nodes can contain the following optional properties: - spi-cs-high - Empty property indicating device requires chip select active high. - spi-3wire - Empty property indicating device requires 3-wire mode. +- spi-3wire-high-impedance-turn-around - Empty property indicating that a + 3wire host need to insert a high-impedance turn-around + clock cycle after turning the one output line into an + input line. - spi-lsb-first - Empty property indicating device requires LSB first mode. - spi-tx-bus-width - The bus width (number of data wires) that is used for MOSI. Defaults to 1 if not present. From patchwork Tue Sep 25 14:32:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 147462 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp803577lji; Tue, 25 Sep 2018 07:32:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV624nUKSrvHkgCW3ipbOUwjeHkZrtgLK9EAhDSOIAICL7HTbt2/PvoudNTpgefhq0Giryxbb X-Received: by 2002:a17:902:d704:: with SMTP id w4-v6mr1571310ply.230.1537885955537; Tue, 25 Sep 2018 07:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537885955; cv=none; d=google.com; s=arc-20160816; b=CCEgXYcLFNLUje6Jd/0IcIX05PR9CGRNM8OHHeE6x99mXk5eZGfi9W8hP7eYEH3abE rpAtoh+ivepsVqikSt1fwInIIglb8EGk5+Yn5oSitvBHikpK3X1vHe/RGyURRXe8INwR GUz/65RoNsVFaoiCWxz2R4aqJmW/29YrDSrgW3TF009mlAa3RB8Ubbrf5okiO76Tndrh w3y0YALrB5UbnIw9Aawy3w2visXcbT6DT+pvDKHdo5umGoCbupslampzsjBsYyd0mh9y wuFILvF+GQ0mj93SRhuGcwebu0XDNfGVfEe38x3Ewcbt0HglyLDjzcGpIA9bp2re0ndP IkTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=mxW7yLXqPZ3VPTOvLFtQkakf4lGzxlbRO7mPl8cZ6qg=; b=Cz/wnkROWWueQ+ygiANHzE4wdpCoi1EJCI8sTBDdki/l8nVzPelxTs7AJLYgzZBLin Ty+5pAqcfab2pMgqv9q6u3JFG5J4Le/qKz4s8D49pZuG1FylXMRd2k04PsB/3x9F2XQg 61Ksq6f3OepnN9Or/6psQvvJdK8EENDcuNXCWbmTCtEqwfys+maXnAWghD/TyJvXXsrY h7k7FE7x/tGT5kmu4Q4+Tqdx/px6SxoE+T6oetODiRGMO8XcUztXcixtd5QtPvn6KRZ7 OWYZdoBzG2gzSkdn9n1XumEpSCJ34KxFRzKsAexnXymOJUEeWDNJ/1Dk5zgw59+NDGZE N5SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ks4siOZk; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3-v6si2505600pgo.542.2018.09.25.07.32.35; Tue, 25 Sep 2018 07:32:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ks4siOZk; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729289AbeIYUkV (ORCPT + 1 other); Tue, 25 Sep 2018 16:40:21 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:45171 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729188AbeIYUkV (ORCPT ); Tue, 25 Sep 2018 16:40:21 -0400 Received: by mail-lf1-f68.google.com with SMTP id m80-v6so9659061lfi.12 for ; Tue, 25 Sep 2018 07:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mxW7yLXqPZ3VPTOvLFtQkakf4lGzxlbRO7mPl8cZ6qg=; b=ks4siOZkuuPpYts5jW4vNkaqWxOqln/hFfKmdo6uqNQqY/UGUrMzmEfXGQBb56cWfE c4o2a1YUe+fdhiT3tpGVOQBpXCDJrGjnYp0jFr7AIhthmD2IdKWVz/vMnKYXOyhqeXPq vozh5Yd1Z4+3AfM9h6dYMjEm8YDq7P0myH4fY= 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; bh=mxW7yLXqPZ3VPTOvLFtQkakf4lGzxlbRO7mPl8cZ6qg=; b=DG9GD4a7qWIjUFennJWsAUIEyJ6sAXrazT1zCRy6ecT6+tze1Gm0Ye/rMNiYl+G4sx ny/NXFsBmZx6toX9fb4udpkVVRlncgDt3KDD0f2ptOAoBwShbng1SUZU2Q86NZ9k7by3 bS23W30sugjooE6lIe0weTAT1XKbL2LMOxFV1EMO/6vv2JWKtHwRkdTTtQqnDLbXT5YQ KDTJKtVd0dZIbB4dvbnFiQip7hitCFltcocHOv7I6ApC9NgTi5PTBzpgryOM7uqs012n l5Kn1wNnX35gfqjmJNuJ0tLNVIf1Q4RzRrHnzW8BS7fF8eUXinQh0xuEou6NY/PcK7Hd tfMA== X-Gm-Message-State: ABuFfoi8bVB/9fKYWQSTT+jhGwJzomfeZRyCgAlyaAXo1OvOHQB0PFOp +9bL+ES+mR88qFn+dpjvdK1zcg== X-Received: by 2002:a19:dd0e:: with SMTP id u14-v6mr1043743lfg.109.1537885952901; Tue, 25 Sep 2018 07:32:32 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id d13-v6sm441020lfi.74.2018.09.25.07.32.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Sep 2018 07:32:28 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org, Andrzej Hajda , Lorenzo Bianconi Cc: linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH 2/2] spi: gpio: Support 3WIRE high-impedance turn-around Date: Tue, 25 Sep 2018 16:32:20 +0200 Message-Id: <20180925143220.19007-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925143220.19007-1-linus.walleij@linaro.org> References: <20180925143220.19007-1-linus.walleij@linaro.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Some devices such as the TPO TPG110 display panel require a "high-impedance turn-around", in effect a clock cycle after switching the line from output to input mode. Support this in the GPIO driver to begin with. Other driver may implement it if they can, it is unclear if this can be achieved with anything else than GPIO bit-banging. Cc: Andrzej Hajda Acked-by: Lorenzo Bianconi Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Change some spelling to use dashes, high-impedance turn-around. - Collect Lorenzo's ACK. --- drivers/spi/spi-gpio.c | 24 +++++++++++++++++++++--- drivers/spi/spi.c | 2 ++ include/linux/spi/spi.h | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 088772ebef9b..899527a060f2 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -256,11 +256,29 @@ static int spi_gpio_setup(struct spi_device *spi) static int spi_gpio_set_direction(struct spi_device *spi, bool output) { struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); + int ret; if (output) return gpiod_direction_output(spi_gpio->mosi, 1); - else - return gpiod_direction_input(spi_gpio->mosi); + + ret = gpiod_direction_input(spi_gpio->mosi); + if (ret) + return ret; + /* + * Send a turnaround high impedance cycle when switching + * from output to input. Theoretically there should be + * a clock delay here, but as has been noted above, the + * nsec delay function for bit-banged GPIO is simply + * {} because bit-banging just doesn't get fast enough + * anyway. + */ + if (spi->mode & SPI_3WIRE_HIZ) { + gpiod_set_value_cansleep(spi_gpio->sck, + !(spi->mode & SPI_CPOL)); + gpiod_set_value_cansleep(spi_gpio->sck, + !!(spi->mode & SPI_CPOL)); + } + return 0; } static void spi_gpio_cleanup(struct spi_device *spi) @@ -410,7 +428,7 @@ static int spi_gpio_probe(struct platform_device *pdev) return status; master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); - master->mode_bits = SPI_3WIRE | SPI_CPHA | SPI_CPOL; + master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL; master->flags = master_flags; master->bus_num = pdev->id; /* The master needs to think there is a chipselect even if not connected */ diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ec395a6baf9c..a816fa05fa02 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1559,6 +1559,8 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, spi->mode |= SPI_CS_HIGH; if (of_property_read_bool(nc, "spi-3wire")) spi->mode |= SPI_3WIRE; + if (of_property_read_bool(nc, "spi-3wire-high-impedance-turn-around")) + spi->mode |= SPI_3WIRE_HIZ; if (of_property_read_bool(nc, "spi-lsb-first")) spi->mode |= SPI_LSB_FIRST; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index a64235e05321..b58aaf4a4e4b 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -163,6 +163,7 @@ struct spi_device { #define SPI_TX_QUAD 0x200 /* transmit with 4 wires */ #define SPI_RX_DUAL 0x400 /* receive with 2 wires */ #define SPI_RX_QUAD 0x800 /* receive with 4 wires */ +#define SPI_3WIRE_HIZ 0x1000 /* high impedance turnaround */ int irq; void *controller_state; void *controller_data;