From patchwork Mon Jan 8 12:49:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 123703 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2683377qgn; Mon, 8 Jan 2018 04:51:19 -0800 (PST) X-Google-Smtp-Source: ACJfBouXpfGPUhs2jWI+ljdjmgPPBnv8WAPR5M7jUpqMufF59fce0quUZUB3yVqpbyLBzdjU8mMc X-Received: by 10.98.103.129 with SMTP id t1mr10692886pfj.53.1515415879106; Mon, 08 Jan 2018 04:51:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515415879; cv=none; d=google.com; s=arc-20160816; b=xadU5Ex6gmWDKy4Feldun8kp734vUwKwkHdsfPrUdpsvEFu/K9BrPv/wkeejE1DQGc JTBpCZ09PtZikdl1JbBIM342LTfH75ewBFInoTh85j69DOcldWynkf8KFhe7AVjO0dOu 6scoBtTzuI8AWW4/CEmJHU74mS1Gt1yCO0Dh41M2yU1P9uTotbyPFAuRXLsSV5cG1m8s gO59S6KDT5o+hEDdgVJnQlJ4ajI22faYdcDxncJ39PXcXprDRok2wXDQysRvncM1KdNY nZlYn9WVRF8Vq7WimTen8UOfBif4EwV4LOMxKsvgaK3JHKoaSF2Xywp3Jg2vMETTKJoB j79A== 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=LNPaXS0QKaeDkvpP6C1d1tnfc1owbFehgjifjXVynXQ=; b=CwToc+zl9mabZDz1ZwIAXvOeTjcE0Fb1ylfZD/yVVv+GMFq8D/FM8NpP4wRv1fiMNi 9zXiCP+kA+ULSAntbmTSsRM80pVlsx+Ze0AK86p0jtv8lCmjfWJZ2v4Zklo8kb1iHOSZ NSu0TrPt9c26YlcrEZBw5vYKOADvX8m+RaOnQ625eK8yc0zNKTWoP2VFKXxi5BXX47KY i5StaMMu7cAyzedMiXJnKPlfeCG/Eii64Km7LnD3+8LdcJD8X+9EKQ7WkCPfccbrPCaH Z9hiaPEMrguwf48ckccY6VUtspGb5sW4pJly0X4eRsXLeZlsyEYRQ5mIdeaOTaHE7/K1 WdIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dq491gl0; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 t9si2057227pgc.468.2018.01.08.04.51.18; Mon, 08 Jan 2018 04:51:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=dq491gl0; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 S932466AbeAHMvR (ORCPT + 6 others); Mon, 8 Jan 2018 07:51:17 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:38220 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932413AbeAHMvR (ORCPT ); Mon, 8 Jan 2018 07:51:17 -0500 Received: by mail-lf0-f65.google.com with SMTP id d19so3667805lfj.5 for ; Mon, 08 Jan 2018 04:51:16 -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=0y83lDsSUwSSWZmhNquK1DOCDPjSEMZkl9+NMnrihH0=; b=dq491gl06VYVmz/nhq9+TDY4IjsQue8RcrSD6kBxQc3xSntXgYKYqUMmsz6Dtt05TI iWoesCSUtbNlgpuwy4KW0SrGJsdQxs5RFx85hlrv+tLP8mwCazgGgWmFvJP5pUfKw0yL LAY+ftmuocggsJXnbh4yJwaOiaF5kKFMTN6fM= 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=0y83lDsSUwSSWZmhNquK1DOCDPjSEMZkl9+NMnrihH0=; b=n7c4EpuFfAS1ksIj2ORhrh7UNHszdTJ8+kRfGLzoTg/IJq9vrpt9VoH9W9u+G6QlvW 69Xb4sXNnLId5Fkk7JXt9VSz/o4kLk53oBLu+KUes1CiDtKtVb4Lt8PNEe7PYy8t13HU M0SbYlN/SJBQnQSUw1ETiF6Aa1DGDdDA0/m+44LHame5gf29YjP63EdLqcaFN8B4o8FQ yTjl68oFfH4XG5KW97YG5uKd2QmVG+0wbv9ORDUG6oS4be69Gtn44oFIG51PruSn2cQu mTnNoK+vNxVhjQgc7RdF4/6fuvtFBYhnyYx+bPJuRvXrBWwr4GqrOlRYO+XL6dd+yKg1 GkZg== X-Gm-Message-State: AKGB3mKI3kqAHL533Up+bfrcZmuQlNKqK1U1rp0YnjKEjVLOb/TACnfI TTkQfYz51fBKFioSgD1SYP9yfw== X-Received: by 10.46.16.1 with SMTP id j1mr6292432lje.139.1515415875655; Mon, 08 Jan 2018 04:51:15 -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 t11sm2317757ljd.53.2018.01.08.04.51.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 04:51:14 -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 v2] gpio: of: Support SPI nonstandard GPIO properties Date: Mon, 8 Jan 2018 13:49:09 +0100 Message-Id: <20180108124909.32334-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 --- I will merge this into the GPIO tree as a preparation for the next (v4.17) kernel cycle so that we avoid cross-tree dependencies. I estimate that it is too late to merge the bulk of the patches for v4.16, but this can go in. ChangeLog v1->v2: - Us if IS_ENABLED(CONFIG_SPI_MASTER) instead of #ifdef CONFIG_SPI_MASTER --- drivers/gpio/gpiolib-of.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" 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..3ae9876e8c44 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -117,6 +117,37 @@ 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. + */ +#if IS_ENABLED(CONFIG_SPI_MASTER) +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; + + /* 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; +} +#else +static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id, + enum of_gpio_flags *of_flags) +{ + return ERR_PTR(-ENOENT); +} +#endif + struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, unsigned int idx, enum gpio_lookup_flags *flags) @@ -126,6 +157,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 +172,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;