From patchwork Tue Sep 4 12:49:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 145927 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3623659ljw; Tue, 4 Sep 2018 05:49:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYlLRaVIwfCp58HzJCEHtizURBHoDNdkHIsvmcmEW40EYyyOLbBv0MulT45LmaOh5XY3Tu1 X-Received: by 2002:a17:902:82c9:: with SMTP id u9-v6mr33271830plz.138.1536065399440; Tue, 04 Sep 2018 05:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536065399; cv=none; d=google.com; s=arc-20160816; b=UKv3Z+xbDZWrGK5YSq6rmJCiDUiwEqcUt6WXg2C5KRTQe0o7i4WzirvZJBXbZXvSS0 j6UEGlSCyyRMfn/bAZKuIRWoZk071LRIsrJUxuJwtiwnnAA31zF7T5cJrmfjJDuZ49kW 6db3U5Nlz+0xljIAjxBnlk/TGNgMjqLBU/DgFJ0tjjM+TIY85aBBHPQjLUr72tha18bV /l48EYdWoqbJcq10hPelM4tl4v0g+xA22diC5zGZyJxgBfLdnN155FLXUBddi1YyqYeR 0jxeJ4DMo7GcEfHKci5i/KET/1KFqYuW7dApquAYUo3KxWMJASzIJKTfEkniyGiwimOh 82GA== 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:arc-authentication-results; bh=PzkREg4x2j8VIqbWyGPLG5KoNntQS7JTW2P3pbkbkyo=; b=tF8Q2gD4SduChSLJXZ+rYk4vwUPk+oiZ2gRvw84BgTnJ/W1R2syuzqEIh+Tz786JQu hxvSf76rnimS93h+38UCOPv/eYwyZoC0RO05Ia6Wk8lPbRyHBccEAA13htbnlk3Kx0kX Nr5EzdkTm1kx2i1qvAF2AOqOOWmOhTVYwFzA5UD2kUJkb8DO3Gvh3awfQZcbDbPpnmYq OdLb5BE5GIWlg4ArgiICgZDm+ec8pvU/pUzM3XH2JomsVl8WX7LdoDeIcw5BFrrxa3UF AQq2uux3PAc7vwV7ZkrMflPtGWo97uSa9jEi+Yvy4+QbIQ1mji+XewffQQBXqranXVxc nlGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jZzoac3g; 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 f76-v6si22923245pfh.33.2018.09.04.05.49.59; Tue, 04 Sep 2018 05:49:59 -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=jZzoac3g; 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 S1726956AbeIDRO6 (ORCPT + 1 other); Tue, 4 Sep 2018 13:14:58 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:43058 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbeIDRO6 (ORCPT ); Tue, 4 Sep 2018 13:14:58 -0400 Received: by mail-lf1-f65.google.com with SMTP id h64-v6so2826859lfi.10 for ; Tue, 04 Sep 2018 05:49:56 -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=PzkREg4x2j8VIqbWyGPLG5KoNntQS7JTW2P3pbkbkyo=; b=jZzoac3gX8ZWPfQP1+ql7Ie6PvWG8Ngcx24D1SqbOeIVBZW+ccZ72h3INXnCt6r3dJ dj+JzG6AI/pPbRQfjyiTzRJWPHNVODY5DBayEQxvcAhnWGZW8st5g408ouRNE5CNHeBB e/Kp7w3I5t0NCHrLo1zYiSbqt435ckHI6d0s8= 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=PzkREg4x2j8VIqbWyGPLG5KoNntQS7JTW2P3pbkbkyo=; b=s1asi8MP+oGimTjFAw9jeOL85UqWmnN3MgAnBIRdBckIKEC+XGoIpZ4RSJmi7XdxH6 CUZG3J7rO5NOw76Q9vn1eQ51jS1xPaQZiCyOf8kY4W4h3XeCszqv9kJeuAvS9PYovtdx TBIJVuY+el/6NsFneoa6f0a2gO2sYK+eiExkHBGKh4RhVxR4A4vR7O6T0qH/vVgKYGD2 5luDuKt9kevrCNm9qR3LI9NZWT0w3pbDFaSd8xd2uwMkXf+SpK9wQPRx3Kj+oq1LGIq2 9pWJHVh/012CZ4G9/0rJnmLydogKAjCcD2igY+zFgzP7emG+ynRnJKxFpaKgmGk5+X7b bgBg== X-Gm-Message-State: APzg51AWKPrc7kX9LhoKk6wzUcYf36GGa4tWM0xvh93RbPDuOAApKSYf BC+x100E7nRl6FvFd1iu6lsqSA== X-Received: by 2002:a19:17e6:: with SMTP id 99-v6mr21435878lfx.48.1536065396039; Tue, 04 Sep 2018 05:49:56 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k4-v6sm4019782ljc.6.2018.09.04.05.49.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Sep 2018 05:49:54 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Mark Brown , linux-spi@vger.kernel.org Subject: [PATCH] gpio: of: Handle SPI chipselect legacy bindings Date: Tue, 4 Sep 2018 14:49:50 +0200 Message-Id: <20180904124950.17067-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 chipselect 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 "cs-active-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 "cs-active-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 "cs-active-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 "cs-active-high" the SPI active high property takes precedence and we print a warning. Cc: Mark Brown Cc: linux-spi@vger.kernel.org Signed-off-by: Linus Walleij --- 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 | 47 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index a4f1157d6aa0..cec8351909ce 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,48 @@ 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 { + *flags |= OF_GPIO_ACTIVE_LOW; + } + break; + } + } + } } /** @@ -131,7 +174,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,