From patchwork Thu Sep 6 14:30:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 146097 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp588950ljw; Thu, 6 Sep 2018 07:30:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdadAfWa2rCDkP0++KtoXFdcV53E6LowA5+oNUJNzlKAJddmwHmRQfMIhv8uU+CWQB6dBJpG X-Received: by 2002:a63:e443:: with SMTP id i3-v6mr3050178pgk.381.1536244225701; Thu, 06 Sep 2018 07:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536244225; cv=none; d=google.com; s=arc-20160816; b=lIvOiByJzCUGTFFMm6bbdq4bwusl6iAkDU3pQYtT8ccWEpxyDAEUhUffUWtEN1lsAv 92OE4IkT5qpB5Mss5LgIhm44yHPvieNnAhaF50XzwKetyzNhx2gS4j50zTUeWC+B3VFQ ajy3OWitk8vnxGzIM6tyVFvXcTrgv1irRT3+mQsLPGyCXMw63ATBQz30gdnkRDDKJiaU 3ToJ6Se7kS01z19FhDeHuDMmEniwW3mINKgwNilH9b10x9TEpxoSGfB00d4tygLIb1Ri 2vfgtW6NV0qTmDCNik3MxUsip+nzEdlFWI/UIC5SzkJkLdnK6wPIjQE9CvXVMraCyDjO o46g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=pCi2sfPpQAFdJsUNAeTg0upNmPIaEwLCSaG66TQT1D4=; b=U3spLRm7H2t0iP1Ag0+X6IrlfkOqYuRCs96/BKWdVEOMCqCxwluh6Fy0c63etu2r6+ QCI6SjHEa3ltWSUUDikFa4XB9efEiar5k2ceagxPPBYz0c4aVCqO0YVTLN8Asv4EX9U3 /6DQ4rN6ASn5MLKVMCWjWvAaQyrV31j+OZhgjcheE52KXHKBBEEq/RnBlIB+utVOL0iy 8R+Uk9MmmU5D+k/4ldUO+mDkj49EHWn5vKjVPtyzMVnbJxoJCeqnGVfZd7LGFHG/7FKy k6aSllKfds+J6TE8psVatEqTaKNSZav1hn3cjNu7q7iKpYRBKbws0Tkaan6x7bRDLqpR j3UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XvT5uWAE; 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 u3-v6si5206288plb.401.2018.09.06.07.30.25; Thu, 06 Sep 2018 07:30:25 -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=XvT5uWAE; 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 S1729932AbeIFTGM (ORCPT + 1 other); Thu, 6 Sep 2018 15:06:12 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39106 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729401AbeIFTGM (ORCPT ); Thu, 6 Sep 2018 15:06:12 -0400 Received: by mail-lj1-f193.google.com with SMTP id l15-v6so9507550lji.6 for ; Thu, 06 Sep 2018 07:30:23 -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; bh=pCi2sfPpQAFdJsUNAeTg0upNmPIaEwLCSaG66TQT1D4=; b=XvT5uWAEgVZZst/O40GrD+6ul4ITdpor71Uwm47eJ+snaT9OQtNhJZO0nCcLh4tIOI BngjMof3sBoyYqyE7Ba/7lg/5cTTbZ387Zv/q6ByaoesH6+x8QXBWLQ21Sav4t+My0U7 0PdWHJ14ELy+qGuYaBf1Wusu4KLvZoRpqSmTI= 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; bh=pCi2sfPpQAFdJsUNAeTg0upNmPIaEwLCSaG66TQT1D4=; b=FqIbDZuvB0U0hbz42H1fq/iuNXBEnjHE0jwRx9QgWYPORaszPvJwnpdGE+V8UhDbCm 8hyUludRmHzoVNPNnsn9RQWbx/S7a6q+3rl0ps4dFcvX5mSRhfKDkABQrGm8aNh5GfTn 4sTvnNxZcq9pnFIp0iYSE5vRi0jh+eVMFa+lao67HLv7v8eZNu/M8fJEv4/Md2XCDPYx nbQSncq8sYf+M3CI/1Fjr49qLPatZGwdXYJXbkEo4dTfP5Rx/LnIlWy2pdCKD7iMCgLA E4koQ8VPegPb0rE/kMqJKC7ut2t8jlaMAU2QqqyUg53K9irZg0Pm/tn7es28deaZmVpL 528g== X-Gm-Message-State: APzg51CtVzwpPkEXc0HMvauLqIl5ZonrIqmVnvc4dWYYNa0MJ8ivRKo9 sY3q7fDPMZ71Cyy6DFRB2IotiQ== X-Received: by 2002:a2e:2d0a:: with SMTP id t10-v6mr2048067ljt.8.1536244222587; Thu, 06 Sep 2018 07:30:22 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id m10-v6sm830872lfl.38.2018.09.06.07.30.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 07:30:21 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Mark Brown , linux-spi@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2] gpio: of: Handle SPI chipselect legacy bindings Date: Thu, 6 Sep 2018 16:30:17 +0200 Message-Id: <20180906143017.11649-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The SPI chipselects are assumed to be active low in the current binding, so when we want to use GPIO descriptors and handle the active low/high semantics in gpiolib, we need a special parsing quirk to deal with this. We check for the property "spi-cs-high" and if that is NOT present we assume the CS line is active low. If the line is tagged as active low in the device tree and has no "spi-cs-high" property all is fine, the device tree and the SPI bindings are in agreement. If the line is tagged as active high in the device tree with the second cell flag and has no "spi-cs-high" property we enforce active low semantics (as this is the exception we can just tag on the flag). If the line is tagged as active low with the second cell flag AND tagged with "spi-cs-high" the SPI active high property takes precedence and we print a warning. Cc: Mark Brown Cc: linux-spi@vger.kernel.org Cc: Geert Uytterhoeven Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Fix the property name in the commit message. - Print an info that we enforce active low on CS This will be merged as a precursor to a series switching over to using GPIO descriptors for chip select handling in the SPI subsystem. Currently no descriptors are used for chip selects so the impact will be zero until we start switching drivers over. --- drivers/gpio/gpiolib-of.c | 49 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index a4f1157d6aa0..a4e07a2a2570 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -57,7 +57,8 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, } static void of_gpio_flags_quirks(struct device_node *np, - enum of_gpio_flags *flags) + enum of_gpio_flags *flags, + int index) { /* * Some GPIO fixed regulator quirks. @@ -91,6 +92,50 @@ static void of_gpio_flags_quirks(struct device_node *np, pr_info("%s uses legacy open drain flag - update the DTS if you can\n", of_node_full_name(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. + */ + if (IS_ENABLED(CONFIG_SPI_MASTER) && + of_property_read_bool(np, "cs-gpios")) { + struct device_node *child; + u32 cs; + int ret; + + for_each_child_of_node(np, child) { + ret = of_property_read_u32(child, "reg", &cs); + if (!ret) + continue; + if (cs == index) { + /* + * SPI children have active low chip selects + * by default. This can be specified negatively + * by just omitting "spi-cs-high" in the + * device node, or actively by tagging on + * GPIO_ACTIVE_LOW as flag in the device + * tree. If the line is simultaneously + * tagged as active low in the device tree + * and has the "spi-cs-high" set, we get a + * conflict and the "spi-cs-high" flag will + * take precedence. + */ + if (of_property_read_bool(np, "spi-cs-high")) { + if (*flags & OF_GPIO_ACTIVE_LOW) { + pr_warn("%s GPIO handle specifies active low - ignored\n", + of_node_full_name(np)); + *flags &= ~OF_GPIO_ACTIVE_LOW; + } + } else { + if (!(*flags & OF_GPIO_ACTIVE_LOW)) + pr_info("%s enforce active low on chipselect handle\n"); + *flags |= OF_GPIO_ACTIVE_LOW; + } + break; + } + } + } } /** @@ -131,7 +176,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, goto out; if (flags) - of_gpio_flags_quirks(np, flags); + of_gpio_flags_quirks(np, flags, index); pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", __func__, propname, np, index,