From patchwork Wed Nov 27 13:54:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 180297 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp6150442ilf; Wed, 27 Nov 2019 05:54:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyhbLNE/2EzSh9+J/PL9sZNkEze7sRYFu8HEi5aRwmhH90D0LTFoD0st8PLqGnIxdP5a3zi X-Received: by 2002:a50:ec82:: with SMTP id e2mr32387637edr.68.1574862867212; Wed, 27 Nov 2019 05:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574862867; cv=none; d=google.com; s=arc-20160816; b=VJDdqbHDwjQYm40OlSnYaIO/8MSiNQVnlxu3uF/5USkFoc+th+0GXDta0cAjs5E+l6 4Y9jYj8Ue1et+coiWTPU65YlC72Vr4Big03qXrK6tv/YSKpSr9Hv1Qy8VGZutYs0FGt2 EMdjG38OXGlP3f87cgm+5Y39XmF4TR6hdsbiHzISIJpUFQLCv4MV74fOJG32ZSUIww89 bEAhsCIbGrzSOcIgTzqg873vgsp/XZe3XoPLJh9rhlqskEccwIK1uM2s42+1HPaVU0MS 9HVsBIAeSXWehE+uTZM7Dhg0gDjmQMUaoQkwIkycy1mVWaLWWEmRwtUwqsOosH2RqJ/I 4etA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ze5hvXCplepJyWjwgkySScV2FO5TtWlZUcDiUJMYMsA=; b=FRSwp0mpBFOQAToM0Xn3bpOpyHaIKQVS5v9CvRBRhVDi4/11CACu6OrDS5N+sRBYW/ a164T4v6F8h7Nq2Er+8MWllmZLjIkIwCColZdNXC1RlEa4oMmzmsNxT1GDzpFuCAyqgQ /ilFB3xNtGWCcrkeK6DdSffgxFPfr2JgPHkZu2gZTm3q3EfzIjIGW9ff5j8sfrD6XOF9 iDhSvQzplWFR6f1am5rd0ZzMdvHpcZzDpgQ8b7E/ecBGTnifkKBFwVMpVxhgSoB+8LzE vI67wMxqt7xcp2Xd0TQQwcUaMMMcXqI/lEwLOMTs51vuMpCbdWlwn6ScCgOKby4A1BhD uzpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZCGKYWsi; 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 x17si9267291ejs.178.2019.11.27.05.54.27; Wed, 27 Nov 2019 05:54:27 -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=pass header.i=@linaro.org header.s=google header.b=ZCGKYWsi; 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 S1727073AbfK0NyZ (ORCPT + 2 others); Wed, 27 Nov 2019 08:54:25 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:35663 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbfK0NyZ (ORCPT ); Wed, 27 Nov 2019 08:54:25 -0500 Received: by mail-lj1-f193.google.com with SMTP id j6so15571638lja.2 for ; Wed, 27 Nov 2019 05:54:23 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ze5hvXCplepJyWjwgkySScV2FO5TtWlZUcDiUJMYMsA=; b=ZCGKYWsiinnFBhR/ovPRoqpJ/8qXeVhMLeaVJqOoLLtY27y18Jgl9k7T/cKKtZMB4a VrbOK7iw0tueIbg5MRQAWVKXQEHoc/CofCoQmbIRpV9+oI09ZpN/zddGl/kCYDF4R7hG JxYdioLqxcYKl2UxjQrDA41oSTHVobiWPAHokFH3/ARoiRk6fdfsO0mcT87r0dVKcKyT r6S03KPMvdgLhfFOC3Dp66wvZJOeKhsNycoN6YEpKMxKKDqnoe8Hw5uS81bTr1hhN6SH hSpvUqo6o0aWplpDR2yzWKEQQkigJUXULDvnl2YxMhxF6nslImbWIawkYG4bL2snPPod ql9A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ze5hvXCplepJyWjwgkySScV2FO5TtWlZUcDiUJMYMsA=; b=UEV7AdppGJOueGJkxvbQmg4yYYDkWOCBVxEcb79BqUDLpt6xnm/at9zeyj2dJkTwI3 F3QWneCNOnDKfl2g/cJArAXZ1MGEL0vpVwAD0T5xzEvcGdjEWqHw1iOP1NYux0MMq5De Kyy1i/BaqDPLhh6HBo9PYE5t02y/+wBlAioTjFe9DffAcxyZMl8xW+XI3ZrK5B8j3T4d YSQIUsIPeGOCFbMVS+ARVj7VGZwG1E/NXhjE6Y9ffa2mYxgswzE3WOfKtxrz8jmhGHXG WFkRSYeaTM7u3EuyF7PYjMV3JQEwi98WGOTnEf2enRvAdc1gImMofaAZHvwTK0Xp7J0U ptag== X-Gm-Message-State: APjAAAVoIB4/ITfcI3dIHhu9IXz0JLECFpPZ4j0zDXP0DhzPjch0RZ4Y q3L65K8Lda+uXcosLsVsG98C4w== X-Received: by 2002:a2e:2201:: with SMTP id i1mr17841502lji.110.1574862862903; Wed, 27 Nov 2019 05:54:22 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j18sm2343561lfh.6.2019.11.27.05.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 05:54:21 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: Linus Walleij , Christophe Leroy Subject: [PATCH 2/3 v2] gpio: Handle counting of Freescale chipselects Date: Wed, 27 Nov 2019 14:54:09 +0100 Message-Id: <20191127135410.156430-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191127135410.156430-1-linus.walleij@linaro.org> References: <20191127135410.156430-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org We have a special quirk to handle the Freescale nonstandard SPI chipselect GPIOs in the gpiolib-of.c file, but it currently only handles the case where the GPIOs are actually requested (gpiod_*get()). We also need to handle that the SPI core attempts to count the GPIOs before use, and that needs a similar quirk in the OF part of the library. Cc: Christophe Leroy Reported-by: Christophe Leroy Fixes: 0f0581b24bd0 ("spi: fsl: Convert to use CS GPIO descriptors") Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Hardcode the quirk to look for "gpios" as this is all we support and else the call would just recurse back and fail again. - Provide a proper NULL check so we don't upset strcmp(). Mark: I change my mind, better to keep the patches together, once Christophe has it working with my patch stack let's just merge all of it. --- drivers/gpio/gpiolib-of.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.23.0 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 80ea49f570f4..ae8b296160bf 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -23,6 +23,29 @@ #include "gpiolib.h" #include "gpiolib-of.h" +/** + * of_gpio_spi_cs_get_count() - special GPIO counting for SPI + * Some elder GPIO controllers need special quirks. Currently we handle + * the Freescale GPIO controller with bindings that doesn't use the + * established "cs-gpios" for chip selects but instead rely on + * "gpios" for the chip select lines. If we detect this, we redirect + * the counting of "cs-gpios" to count "gpios" transparent to the + * driver. + */ +int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id) +{ + struct device_node *np = dev->of_node; + + if (!IS_ENABLED(CONFIG_SPI_MASTER)) + return 0; + if (!con_id || strcmp(con_id, "cs")) + return 0; + if (!of_device_is_compatible(np, "fsl,spi") && + !of_device_is_compatible(np, "aeroflexgaisler,spictrl")) + return 0; + return of_gpio_get_count(dev, "gpios"); +} + /* * This is used by external users of of_gpio_count() from * @@ -35,6 +58,10 @@ int of_gpio_get_count(struct device *dev, const char *con_id) char propname[32]; unsigned int i; + ret = of_gpio_spi_cs_get_count(dev, con_id); + if (ret > 0) + return ret; + for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { if (con_id) snprintf(propname, sizeof(propname), "%s-%s",