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: 992083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="hkPS6ldZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42mJBx4xRfzB4Z3 for ; Fri, 2 Nov 2018 08:25:13 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbeKBG3x (ORCPT ); Fri, 2 Nov 2018 02:29:53 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37964 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727338AbeKBG3x (ORCPT ); Fri, 2 Nov 2018 02:29:53 -0400 Received: by mail-lj1-f193.google.com with SMTP id q186-v6so6036105ljb.5 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=Phx8JD6y6v7p8lMV0MVDKbwuVHZEPryTmoNqkw2XeF4RZoZXW4ExTIaB8NqH5Cna4S 7ou4V68QOZ3oEq02Y7zQYwavb7qgpW/AoPUL7cd71GcGA7VAsimd50LWySRhZ6KtZaVQ h/CJWKpwNGTzkHWVd+C2s2s1/Ob8x4F2uhkI/DLTa0//3ttXWspgRuthau2QV9e+2XNC DVoyqX6/0Y9w208CaErkFdphvnB5GtzMoZBN5vO15PtyrZzdK5qYlE8mK7MOoIkhotSC 3RS5qcViapJss1KbReo9NhQcqBnIqBKiUosLcQ/q6aE4UOt+I9e+Yln3whQIPxSSNPPg 567A== X-Gm-Message-State: AGRZ1gLK5oahlpOcTcg107nPAzQ0gCY3eexauh5tQjudzalfAli+6lGV SzePBaUrKY1FmWdr+xJp3l7LMw== 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 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;