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;