From patchwork Thu Nov 1 21:25:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10664529 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 CC70C17D5 for ; Thu, 1 Nov 2018 21:25:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBEE2B6AC for ; Thu, 1 Nov 2018 21:25:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0CAF2C3BD; Thu, 1 Nov 2018 21:25:13 +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 177AF2B6AC for ; Thu, 1 Nov 2018 21:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727497AbeKBG3x (ORCPT ); Fri, 2 Nov 2018 02:29:53 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46434 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbeKBG3x (ORCPT ); Fri, 2 Nov 2018 02:29:53 -0400 Received: by mail-lj1-f195.google.com with SMTP id x3-v6so19376278lji.13 for ; Thu, 01 Nov 2018 14:25:11 -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:mime-version :content-transfer-encoding; bh=oDJATwhfz+ZO38J53/GF00yxZydN0xRjeOn1iLw9bD0=; b=hkPS6ldZQe0HRSGZEVgUDgq2NaYawC5FOfAfpZt/I6w7biWdv3QFssP7wuSLxaM2QM EaVDlKPK/mEPJO5vMX88JDBHhY7qp3oUNrkz++YPM7JFdawtT0xTPjH+j5Prl1OXyL3H yML7bU3f8tABDswMyMxjeFoDQ84XoOveZ5ueo= 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:mime-version :content-transfer-encoding; bh=oDJATwhfz+ZO38J53/GF00yxZydN0xRjeOn1iLw9bD0=; b=n59PJHihrrBgeIkb4EHSTQHHpbea4KG1zESfurU4HDLa0dmXzx04H7bqswUD/Ma0Ci nhMBXpLXnhXyhh8itCjJuIpsl8kN6bU6Ekdrizjj0yidI45/sls8/2el7ha/asJRImZ8 3v6y6/T1x1W4i9KM7EnM7hYcSrzdJ0770cfJ3W1+hcWjnpwkubWlhFDqAq+wxMgxQKhA eHa0F6HfQU67iUEiVcLz73GSFwrMdJjdbNCb8tYESyHsZu8Jn9QvLxXmO+R15798p4ph A0YRHWAGbaTRG7WnvICosE3Sq57tUPJEcoxJG0hqBNmBlKo4S5fdSM3EuKm+RRzf1CIk GK7Q== X-Gm-Message-State: AGRZ1gIBLn6xYS+2D2UHQ5+jccCmQHBDS6stMhW4SamXY4kzk197nLy5 /w7lvhQUIEE2T2dhsKdJKRKW1cYqgOG6oQ== X-Google-Smtp-Source: AJdET5cjtde8FCcCXGPMkaZqYnqyyzSUGL4+skdOaCFIvlWCU69W7E2oy/r7xLcCWakcneHrhnfCDQ== X-Received: by 2002:a2e:1b47:: with SMTP id b68-v6mr5121708ljb.104.1541107510393; Thu, 01 Nov 2018 14:25:10 -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 b25sm4809544lfa.96.2018.11.01.14.25.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 14:25:08 -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 v3] spi: gpio: Support 3WIRE high-impedance turn-around Date: Thu, 1 Nov 2018 22:25:04 +0100 Message-Id: <20181101212504.11723-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 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 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 v2->v3: - Drop the device tree parsing (and the device tree bindings) for high-impedance turn-around. This is a client property, so let the drivers using it simply set the flag. ChangeLog v1->v2: - Change some spelling to use dashes, high-impedance turn-around. - Collect Lorenzo's ACK. --- drivers/spi/spi-gpio.c | 24 +++++++++++++++++++++--- include/linux/spi/spi.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 45973ee3ae11..a4aee26028cd 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/include/linux/spi/spi.h b/include/linux/spi/spi.h index 6be77fa5ab90..3ced58eebe1b 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -155,6 +155,7 @@ struct spi_device { #define SPI_RX_DUAL 0x400 /* receive with 2 wires */ #define SPI_RX_QUAD 0x800 /* receive with 4 wires */ #define SPI_CS_WORD 0x1000 /* toggle cs after each word */ +#define SPI_3WIRE_HIZ 0x2000 /* high impedance turnaround */ int irq; void *controller_state; void *controller_data;