From patchwork Tue Jul 2 19:39:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 168345 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4651603ilk; Tue, 2 Jul 2019 12:40:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9qi9CfmOQcIJPI4zkmwNOuXlT2H2h6KOiwbY4mmh5HxDehBXSlXZUP9PJXbYw8xGOhyPA X-Received: by 2002:a17:90a:1d8:: with SMTP id 24mr7648425pjd.70.1562096436667; Tue, 02 Jul 2019 12:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562096436; cv=none; d=google.com; s=arc-20160816; b=u92w+Qgufme862sm7JCuJpB377s6Lywfx17c3/rkWDczPScZs2DOvKb45InuLaSKzT ZmmUrz4DGl4+q/kxhJR2FKf9SAWnkMOieY5yk51+jntddwXOQNLegR9a4/qhVIcYRHFY 3oUuyb0jCZYeXe2cWhiyYkLkknwBeADJsYcWSZ/ULY/V6bgl2YPft10FALyyvHLHowaQ 7h7HxAMdC89OWQw7x16MUJZ8BlOJZwiYPKN24cl6FQIGnB0sjezvy1B2zFgnnJjPvqGd kIesjeBn+F+yUryG4vuqJAHNDbQYa1bCupj7IYN4d6CKoolnO/1w1aV3qro76MvwdOm1 DX8Q== 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=82eMZxwOWHVRAy4QkqHiIVsrvrrm4gUfEQ6ASMxsICw=; b=lmQeW19I5QjrmyI8NYqS1LtQLqFV04yz9CiAk+Z2Vc0Wps3TIpCK/8I6P7Cifrz4ej QUNMDvCQ0bj6ohhYYefZAjsrLIHyjfPk3E2yCg4rgKeHWs08WfaviB4IHbB0PFK7mf1m WnOh/wF894SPmxjRLLy0DBFpmdF9I3sxM44l6oBsDt1LjtE+RmcnzggwlpJlSPzw8HxL EDmj/zu2YCkK7g7rM7cf/NT0af3AIMQsv7+lMsGW18Ls08VTF8TUPyPc9nSiKVmV1sLV yWvDD4euXY6/yGeH62m4kSlAzkpOYf0QhUnfm3+7mIEG7FW5z89pWRmF6XIp8zWZsw5H K4Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MCr5IZ0r; 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 x13si13373092pgh.116.2019.07.02.12.40.35; Tue, 02 Jul 2019 12:40:36 -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=MCr5IZ0r; 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 S1726977AbfGBTkf (ORCPT + 1 other); Tue, 2 Jul 2019 15:40:35 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:42215 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbfGBTkf (ORCPT ); Tue, 2 Jul 2019 15:40:35 -0400 Received: by mail-lf1-f67.google.com with SMTP id x144so12261795lfa.9 for ; Tue, 02 Jul 2019 12:40:34 -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=82eMZxwOWHVRAy4QkqHiIVsrvrrm4gUfEQ6ASMxsICw=; b=MCr5IZ0rUq1B5TKNFO9MkSvECBmHEYoIJNyi3podRvKIzh3AU3AWTZtq05JaS0bNFK N/kS2gwX4xoaEf+2qqGoYrg2UgoNEZwcCeMod91Kq6yUzcbbDwp4ekgnluSEq2x4yVJ+ 265Sb0TbSx+dAqMW7ux628lcOWb3XmbY2+RKHmJf79jZ8lhG9DHrBrrC58h3YZbnMNiC 9RmxUSzRIfyf3aYeRY65PMWMURmynG803JuEAFedrc4sKU7lXz/WuMHLnUZ3X+7rvJQC Jh+P27YVl9XOuyNVJxkS39QA75Jdnhdpr9hlgU6x2eC6SFsEV9XdPeB88ybZttqA0/EX n5Dg== 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=82eMZxwOWHVRAy4QkqHiIVsrvrrm4gUfEQ6ASMxsICw=; b=g44aU2wFiZJkACYKPN07pr0j1HohE0hlq7+k7q3do65WpuuN6Ro6x9yq0SnkQOBsSa SbYmzcSd5u72kIvvi6y1FLPGKoUJQoY6gwt8rHvvsTLUo/yWdHUgppwXpXwrgUlZafia rc39TjvGl0t1i6ivwGZOFXHJKSGqLMMfexMWEAT+OqQt/5t/nXpWIQ+LaccASUvW4E+k LDnpUyOEeHOoUaDMPleqBJjSu+t8EU2WB2gm+CMOwD4SZnndyE5tlBhWnGrYjezTLuVI U2QRXLCnFshYCXDAA2ym7Dus7ErB+6f6Mi4nmWITWgbG8kNB0he9utpqZtA3Ten9Znnn f4/A== X-Gm-Message-State: APjAAAVEqk1ah1S6ERb2yrABP/aHtJLAR2EDMewcSqLfkFkKNW0w66Uo Cz5xReC+7vYzrYvNOd95euUaRw== X-Received: by 2002:ac2:42c7:: with SMTP id n7mr9960246lfl.65.1562096433408; Tue, 02 Jul 2019 12:40:33 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-22cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.34]) by smtp.gmail.com with ESMTPSA id z83sm3970798ljb.73.2019.07.02.12.40.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 12:40:32 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Linus Walleij , Andrey Smirnov Subject: [PATCH] gpio/spi: Fix spi-gpio regression on active high CS Date: Tue, 2 Jul 2019 21:39:59 +0200 Message-Id: <20190702193959.11150-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org I ran into an intriguing bug caused by commit ""spi: gpio: Don't request CS GPIO in DT use-case" affecting all SPI GPIO devices with an active high chip select line. The commit switches the CS gpio handling over to the GPIO core, which will parse and handle "cs-gpios" from the OF node without even calling down to the driver to get the job done. However the GPIO core handles the standard bindings in Documentation/devicetree/bindings/spi/spi-controller.yaml that specifies that active high CS needs to be specified using "spi-cs-high" in the DT node. The code in drivers/spi/spi-gpio.c never respected this and never tried to inspect subnodes to see if they contained "spi-cs-high" like the gpiolib OF quirks does. Instead the only way to get an active high CS was to tag it in the device tree using the flags cell such as cs-gpios = <&gpio 4 GPIO_ACTIVE_HIGH>; This alters the quirks to not inspect the subnodes of SPI masters on "spi-gpio" for the standard attribute "spi-cs-high", making old device trees work as expected. This semantic is a bit ambigous, but just allowing the flags on the GPIO descriptor to modify polarity is what the kernel at large mostly uses so let's encourage that. Fixes: 249e2632dcd0 ("spi: gpio: Don't request CS GPIO in DT use-case") Cc: Andrey Smirnov Cc: linux-gpio@vger.kernel.org Cc: linux-spi@vger.kernel.org Signed-off-by: Linus Walleij --- Mark: I will apply this to the GPIO tree, so I think it is safe for you to drop my revert of Andrey's patch once this hits mainline. I will try to expediate it, I feel a bit responsible. --- drivers/gpio/gpiolib-of.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.21.0 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index aec7bd86ae7e..9c9b965d7d6d 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -118,8 +118,15 @@ static void of_gpio_flags_quirks(struct device_node *np, * Legacy handling of SPI active high chip select. If we have a * property named "cs-gpios" we need to inspect the child node * to determine if the flags should have inverted semantics. + * + * This does not apply to an SPI device named "spi-gpio", because + * these have traditionally obtained their own GPIOs by parsing + * the device tree directly and did not respect any "spi-cs-high" + * property on the SPI bus children. */ - if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && + if (IS_ENABLED(CONFIG_SPI_MASTER) && + !strcmp(propname, "cs-gpios") && + !of_device_is_compatible(np, "spi-gpio") && of_property_read_bool(np, "cs-gpios")) { struct device_node *child; u32 cs;