From patchwork Sat Apr 20 11:14:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10910217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 750161390 for ; Sat, 20 Apr 2019 11:16:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A1CB28D94 for ; Sat, 20 Apr 2019 11:16:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C23228D95; Sat, 20 Apr 2019 11:16:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAE77288AF for ; Sat, 20 Apr 2019 11:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbfDTLQY (ORCPT ); Sat, 20 Apr 2019 07:16:24 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46064 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbfDTLQY (ORCPT ); Sat, 20 Apr 2019 07:16:24 -0400 Received: by mail-lj1-f194.google.com with SMTP id y6so6535057ljd.12 for ; Sat, 20 Apr 2019 04:16: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:mime-version :content-transfer-encoding; bh=TSQYFWpzJQZwVuVCAnz5lxpQmD59owFtWJ0qEyX3T6o=; b=ccznE1bBqSCeXVPQxH4UY3XD13jOfE0rkBofV3SGw344I/rdqhxcX/CJWAsCNqBKAc o0/IaM9IABRSaUhrVT51sk9b+aECMnisaplwK+RoALs6nMLw6jABjhOW1snWfhS6S4+M PozsW7kysH6Ja/CHbrE4+gNtok/HtoWfdhd3Q51o+wqb8iQlHqpq5BXIJSiz6+CF7g2c LZ+MWq4yskn8kAI8ucmVpN8YWVt0VhF5p41slB4UiyZUDwtfCnByqRq6i1PENHxPJLE/ y3ZLg3RR6tRfyW3IZmGg11dDtc6xHttT2qM06ibqlKKP1ZnqKaSSVSNnpnr2uxNAU8Yh HWig== 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=TSQYFWpzJQZwVuVCAnz5lxpQmD59owFtWJ0qEyX3T6o=; b=akFc2dZXbg32Uo7tRztzY2kr49B/HWZHJuTM5VQGPDLxB51gzhLlAFDvj4374xQ9rn MXtdnom40sreY0gL0b+rchGo28st38q/nQah9fs3N3OSeKiTBirUmiKcQ8hP8HhsAi6Y fN0x5IFWRfUstvAqHjCkxff0YxpN6oT7Dhh+aS7jRZARwns2S5cG+giBKrnG5BaZ+KGh lmTzxAGgE2+fq4KXOMiU5wX6/aCFro0SscYhCUX2i2U3hbamd+uNBv+8GoAZWeST+tD0 ZU/ox5BX7lDhjaQjMYehgGkdMwOUbiBsSkHeKgamN7bbjccDymLt+6HPAfvYsVpJLQF7 KuzQ== X-Gm-Message-State: APjAAAXEA7+bHO7AyyWasY6S68eajiZ2bcpkV9SdHvVakQgB8ErGh5Ve q5V8wSBru/73uF1mQ/K8fkLFAg== X-Google-Smtp-Source: APXvYqyj2lfg7Ov79uby7r7aPsrK+p8jnRZVWR9ZYDpGN1bCTDPRoV+alfj2bsMwWLhxgbXOiBEpEg== X-Received: by 2002:a2e:204e:: with SMTP id g75mr4974880ljg.92.1555758982299; Sat, 20 Apr 2019 04:16:22 -0700 (PDT) Received: from localhost.localdomain (c-c5d3225c.014-348-6c756e10.bbcust.telenor.se. [92.34.211.197]) by smtp.gmail.com with ESMTPSA id u2sm1649376lje.74.2019.04.20.04.16.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Apr 2019 04:16:21 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org, Fabio Estevam Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski , Linus Walleij Subject: [PATCH 1/2] gpio: of: Handle the Freescale SPI CS Date: Sat, 20 Apr 2019 13:14:03 +0200 Message-Id: <20190420111404.6225-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Freescale SPI chipselects are special: while everyone else is using "cs-gpios" the Freescale platforms just use "gpios". Fix this by responding with "gpios" when asking for "cs-gpios" in a freescale device node, so we hide this pecularity from the SPI core. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased on v5.1-rc1 This is a prerequisite for the Freescale patch to work and should be merged to the SPI tree along with the rest. --- drivers/gpio/gpiolib-of.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 8b9c3ab70f6e..a46ae1248501 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -254,6 +254,37 @@ static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id return desc; } +/* + * The old Freescale bindings use simply "gpios" as name for the chip select + * lines rather than "cs-gpios" like all other SPI hardware. Account for this + * with a special quirk. + */ +static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev, + const char *con_id, + unsigned int idx, + enum gpio_lookup_flags *flags) +{ + struct device_node *np = dev->of_node; + + if (!IS_ENABLED(CONFIG_SPI_MASTER)) + return ERR_PTR(-ENOENT); + + /* Allow this specifically for Freescale devices */ + if (!of_device_is_compatible(np, "fsl,spi") && + !of_device_is_compatible(np, "aeroflexgaisler,spictrl")) + return ERR_PTR(-ENOENT); + /* Allow only if asking for "cs-gpios" */ + if (!con_id || strcmp(con_id, "cs")) + return ERR_PTR(-ENOENT); + + /* + * While all other SPI controllers use "cs-gpios" the Freescale + * uses just "gpios" so translate to that when "cs-gpios" is + * requested. + */ + return of_find_gpio(dev, NULL, idx, flags); +} + /* * Some regulator bindings happened before we managed to establish that GPIO * properties should be named "foo-gpios" so we have this special kludge for @@ -326,6 +357,12 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, /* 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)) { + /* This quirk looks up flags and all */ + desc = of_find_spi_cs_gpio(dev, con_id, idx, flags); + if (!IS_ERR(desc)) + return desc; + } /* Special handling for regulator GPIOs if used */ if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)