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: 149983 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1289348ljp; Thu, 1 Nov 2018 14:25:13 -0700 (PDT) X-Google-Smtp-Source: AJdET5cCFw/ORFX3zDyz09sW+jAnPrfjLbNVKp+m2Zqx8IjtcC2DoXeDa6nb3b7L8/yLcNDM9nxM X-Received: by 2002:a17:902:848f:: with SMTP id c15-v6mr8894924plo.119.1541107513871; Thu, 01 Nov 2018 14:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541107513; cv=none; d=google.com; s=arc-20160816; b=IGP+3kFTL06L4Pv01fDBJJyXJZ5EMFMEBmmJt46R1KcR2ckHR+Wf+K8sHUeOSLR3Og MAXsmgCBuiGP3u7cxHYy3FOjx8bz34MWOygETxbLEYnOZrISv2xGEm1UISNqV07fPpZF 3oOLHqPnTanIk4n1y3GOl18SFVeKR0uJeSMLG+6N6DqxFibk9PsT3UM+EMDRwHxceUhD X7u29OmftLdwOb0wQQv5q6lmLBzrw7x9+1ofMHVWxhM4cIhrroQdpSexNGukARTSNuXT HVeosraAFxQiIUgfcY7q1MW/0vg6MvJsfB5VhwAoKEjc8KGTJPcOca8156VlAZuz9ERv zrWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oDJATwhfz+ZO38J53/GF00yxZydN0xRjeOn1iLw9bD0=; b=HBS+/H6E086xEuboC6dSXZkuB6H8rwwRse885FBMlt6qbAw63mCx0AWZuMsEPZh2qQ 56Z9jITHm+Hc5kXbl1wYTGa6Fj4E9zfcM2R2v46l729/yby0297mG4OGJPDSLV+vpklE jztYUlQhx6sw1XYO6bawivP5DAf0oBk+x1mQNVAp2SO6LyeKoW/gS9ysPEzWpDqATpgA oh3qnN5o9IW80Lu7VRdQB72oVr12CTCDoKKV4lqnjSCTabD6nqL8Hc4Rl6n4+z1GtWpy 7YLGfrxmOEFUTQ63sDzZ3pYZLIpPnAJ8axKbk5JhbZ8sB7Be26Tyh8EfjBWC81wZYUW8 gAvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hkPS6ldZ; 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 r2-v6si6848844pgj.139.2018.11.01.14.25.12; Thu, 01 Nov 2018 14:25:13 -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=hkPS6ldZ; 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 S1727497AbeKBG3x (ORCPT + 1 other); 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-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 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(-) -- 2.19.1 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;