From patchwork Mon Sep 3 21:50:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10586403 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 E907E17DE for ; Mon, 3 Sep 2018 21:50:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D950C29183 for ; Mon, 3 Sep 2018 21:50:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDAC2291B6; Mon, 3 Sep 2018 21:50:58 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 676E5291A9 for ; Mon, 3 Sep 2018 21:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbeIDCND (ORCPT ); Mon, 3 Sep 2018 22:13:03 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41273 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727273AbeIDCND (ORCPT ); Mon, 3 Sep 2018 22:13:03 -0400 Received: by mail-lj1-f194.google.com with SMTP id y17-v6so1425076ljy.8 for ; Mon, 03 Sep 2018 14:50:56 -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=QEhK/bpHHaAsfxxk6O25rXl0lAg0t9abRQKrc8xEIyg=; b=Bw+666OSNRIHss2oQX32tD7grRfhkeSfP4TR5QYjYG+BUYs+qeJYFBP336Lb5cgD38 hEyBUbnqYkezvOkXfKm4kzoV56abrmtccXiK4tD9FFeqGZ0jCmKutGJ5+YMfE3cu5ztQ GbBwzgqz30H6V6P2d0u294RbA9k9QehVYfi5U= 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=QEhK/bpHHaAsfxxk6O25rXl0lAg0t9abRQKrc8xEIyg=; b=sOf2xoa2vTJH1/GUEF20VBEtmcMSYf3ICUseAuaKcxnZR3znbp0BWUHou6r/7k1z4E gH/UkH8Ul0aTOy+/nv/UGihJLKygB+Wa8Bc2Sw5HLHo8o77xgqH+jjzd6K4H4liSqZVA lF3kaSnciRzMjgyBC9aiv+xoUzMnvIZdkn6rMPYSMxMlC1fp19A9HblmUASmQw5MhSST uFIPHhtq1e8gNEIZAgNgpG1NYs+h8GMXJjgNITmbWUjfSnZuv3d8qu7wTsS4xs8O3N6S kUpG9h3cQ4/kpoN1HmM9bqONLufRbx7ie5l+Smvpa8eRGAOyKQf7Ag5Dhd+NVSSVZ+76 nG+Q== X-Gm-Message-State: APzg51BOXhjNjllKiZ+xgSLUsRBfuoOL0MySvM1Ay5Io9JAZk9SL+Qts 6DH3CRCrhSIJoswNgOqheJJQyOZ/3jDptg== X-Google-Smtp-Source: ANB0VdahBGTn8VryAJZJ+CYtJ+bsf5aILo7cxwYo6CDCD3WHJdgPDqmvjsJfIvv5i1SrUuq73DZ2LQ== X-Received: by 2002:a2e:8743:: with SMTP id q3-v6mr18557430ljj.139.1536011455531; Mon, 03 Sep 2018 14:50:55 -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 q128-v6sm3665503ljq.72.2018.09.03.14.50.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 14:50:54 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org, Andrzej Hajda , Lorenzo Bianconi Cc: linux-gpio@vger.kernel.org, Rob Herring , Linus Walleij Subject: [PATCH 4/4] spi: gpio: Support 3WIRE high impedance turn-around Date: Mon, 3 Sep 2018 23:50:35 +0200 Message-Id: <20180903215035.17265-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903215035.17265-1-linus.walleij@linaro.org> References: <20180903215035.17265-1-linus.walleij@linaro.org> 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 such as the TPO TPG110 display panel require a "high impedance turnaround", 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 Cc: Lorenzo Bianconi Signed-off-by: Linus Walleij Acked-by: Lorenzo Bianconi --- drivers/spi/spi-gpio.c | 24 +++++++++++++++++++++--- drivers/spi/spi.c | 2 ++ include/linux/spi/spi.h | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 6bd692304b92..36e481ad38f7 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -265,11 +265,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) @@ -417,7 +435,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 f6f9314e9a18..97159cedd6dd 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-turnaround")) + 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;