From patchwork Mon Jan 8 15:02:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 123728 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2835225qgn; Mon, 8 Jan 2018 07:04:42 -0800 (PST) X-Google-Smtp-Source: ACJfBovVga32TdpdIb4yGeU+Ce7bd+Qe9kLrxv9zWxTGDx+v5o38NmfQHZXxv55zhYizt2HxM0Df X-Received: by 10.101.102.7 with SMTP id w7mr9551514pgv.366.1515423882446; Mon, 08 Jan 2018 07:04:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515423882; cv=none; d=google.com; s=arc-20160816; b=qfasYkJBrrmafnKwFjNPR0tj8WL9wnUGPcXGa0eAwfPkmcVZkORFOyr5MnpRoxFDHm aFxkj+iFQyNf5sUkDRLr31W4/hnqVAvwBXeOgAMemFLnqEerfJBU32MQA0qehX2brD8h a4zbYQDyH8jvyxwuf6er2hMEYHIoEK8eLo9Af3NSN8swIw89cZFcM+EbENqwuCffFOAo FsvZjRwErSlcbDfgWau/tWXSApqYCwdAJHrKB1pbP9IL5vbHVYQqvybb2HhuarF5g7GS KyOWfdXBC5xqaG8uamHVC7UFOeWCjxG7dymfbVSGCHD5wbbYd8w2eEnfRsxFunVCDtH9 n8SQ== 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=2fc8CuH+qP/ITI356IG5EBEa/dxlUKyHX5uHxOVLWpM=; b=IQtFn6dxAWvWlo9lPpbqyFWct7uta01gxaNOix+CtvNr8n9vL8nkagvlxsMl2/wkZ4 xVcJUku/edTYFpkGbrt/KpAJqqndRYg0ItgT0glgGJnFWLk/Gty9uIRbAW1VHl9LjGEv FQlH4KaDTb19MAh5oMroRDFJOb0s91IvyOo7vPvRstgGDofu/wdW36MQMwI8YLZhhZpZ N4m8JQzWsBMf26If/oymCo1YFjvXldGFPkygwyRVRTNxnSYYM/wiRpI31nKBSEcNtmx+ hfK9gRGyQqSv2XJxkCRBmb6FPdwsQ0R3pSZubsUZQj0wquQ1ZfaRG+muIFDw/CcLQhwT 1l0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dYFzOt5C; 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=fail (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 r130si3621992pgr.700.2018.01.08.07.04.42; Mon, 08 Jan 2018 07:04:42 -0800 (PST) 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=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dYFzOt5C; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934055AbeAHPEc (ORCPT + 1 other); Mon, 8 Jan 2018 10:04:32 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:40784 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934054AbeAHPEa (ORCPT ); Mon, 8 Jan 2018 10:04:30 -0500 Received: by mail-lf0-f65.google.com with SMTP id u84so12424632lff.7 for ; Mon, 08 Jan 2018 07:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qh/cE4WukJhnpoRUCa1JhrmTy5sTI8ZOKwSeis7EVcM=; b=dYFzOt5CBM428LdNwYIsuDbEIyM3UTxzZA/+AGbiUsUZMCaitSb4VNpZWAjFIF+NVI GKw7Pp1iSVV7hSC1AMMjvVwnKloGogMw9tWen+GpPe8VQ2qrrRLBr2zzLzWq849XOm81 We/GokQahG+dksVkvDTcao5ptsWiRz7O+emGs= 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=qh/cE4WukJhnpoRUCa1JhrmTy5sTI8ZOKwSeis7EVcM=; b=i8Z0a5II+C4uVSOhjc8Qz7R92hdUk/ZraJdP5MkRYSrbd1Isu6v4mxjGZbRIyaEaEi x2jPSylgNxwUMsNStX2dNIl5u4KYAC3Yl/Zh6qyU5FhQL2u7iCaDOEZtUPMQkwhwkLUw IQi/Z3IdYMBeIyDhyY6gDLvW1Vo5nploKiObDrmbBph2C54ZgbtjJgxBDDskrduSuTAL wBd63HHr5UtfhLjBKHYIgdrmDRtxU11L+W5EfqnDu6GWBie1zaO+CZ4+vpxtZte0nMTA BSK+YReOmivcDexa7AMEXAaXiD3dlND7cWYyYCbfK4qD87USiO3LqRyGPcaP5X3n8sAU GsFw== X-Gm-Message-State: AKGB3mKt4x5ldsrBL5Itj/nrwp+GyVDw+I7+t1wifEiNi2P+lXJdjDMh 0bLPGVeoJZghoI1yHBOr5VYlTQ== X-Received: by 10.46.60.23 with SMTP id j23mr6687084lja.107.1515423869296; Mon, 08 Jan 2018 07:04:29 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id j34sm203870lfi.80.2018.01.08.07.04.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 07:04:27 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Linus Walleij , Rob Herring Subject: [PATCH v3] gpio: of: Support SPI nonstandard GPIO properties Date: Mon, 8 Jan 2018 16:02:21 +0100 Message-Id: <20180108150221.14193-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Before it was clearly established that all GPIO properties in the device tree shall be named "foo-gpios" (with the deprecated variant "foo-gpio" for single lines) we unfortunately merged a few bindings which named the lines "gpio-foo" instead. This is most prominent in the GPIO SPI driver in Linux which names the lines "gpio-sck", "gpio-mosi" and "gpio-miso". As we want to switch the GPIO SPI driver to using descriptors, we need devm_gpiod_get() to return something reasonable when looking up these in the device tree. Put in a special #ifdef:ed kludge to do this special lookup only for the SPI case and gets compiled out if we're not enabling SPI. If we have more oddly defined legacy GPIOs like this, they can be handled in a similar manner. Cc: Rob Herring Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Put the if(!IS_ENABLED()) inside the SPI GPIO retrieveal function and rely on the compiler to stub out unused code. ChangeLog v1->v2: - Us if IS_ENABLED(CONFIG_SPI_MASTER) instead of #ifdef CONFIG_SPI_MASTER --- drivers/gpio/gpiolib-of.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index e0d59e61b52f..317e54f95035 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -117,6 +117,36 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name, } EXPORT_SYMBOL(of_get_named_gpio_flags); +/* + * The SPI GPIO bindings happened before we managed to establish that GPIO + * properties should be named "foo-gpios" so we have this special kludge for + * them. + */ +static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id, + enum of_gpio_flags *of_flags) +{ + char prop_name[32]; /* 32 is max size of property name */ + struct device_node *np = dev->of_node; + struct gpio_desc *desc; + + /* + * Hopefully the compiler stubs the rest of the function if this + * is false. + */ + if (!IS_ENABLED(CONFIG_SPI_MASTER)) + return ERR_PTR(-ENOENT); + + /* Allow this specifically for "spi-gpio" devices */ + if (!of_device_is_compatible(np, "spi-gpio") || !con_id) + return ERR_PTR(-ENOENT); + + /* Will be "gpio-sck", "gpio-mosi" or "gpio-miso" */ + snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id); + + desc = of_get_named_gpiod_flags(np, prop_name, 0, of_flags); + return desc; +} + struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, unsigned int idx, enum gpio_lookup_flags *flags) @@ -126,6 +156,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, struct gpio_desc *desc; unsigned int i; + /* Try GPIO property "foo-gpios" and "foo-gpio" */ for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { if (con_id) snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, @@ -140,6 +171,10 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, break; } + /* Special handling for SPI GPIOs if used */ + if (IS_ERR(desc)) + desc = of_find_spi_gpio(dev, con_id, &of_flags); + if (IS_ERR(desc)) return desc;