From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6476EC2D0DA for ; Fri, 27 Dec 2019 17:59:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4160E206F4 for ; Fri, 27 Dec 2019 17:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577469546; bh=Ls5eP08dXgIKhQU5IUZfcznzPTY9R0mvtRrX9FJWQTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KceM1kaPkgN3WbdbCd0tUDjpDEe/rNEI4zdJ1ZtK9ij6pAxgMt4so1S7vHF7wu1mM IMbIo9HpaR97HmLpUet8CUAymOTAsgCgHd9aGcd5rodEIe/f2oiknFv1ZvH/zR1M6o Xbh1rKzVrEJ1qMmNntYn6CxobwZuvQIz+VtIMrS0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbfL0R7F (ORCPT ); Fri, 27 Dec 2019 12:59:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:37192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbfL0RlK (ORCPT ); Fri, 27 Dec 2019 12:41:10 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0655D2173E; Fri, 27 Dec 2019 17:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577468469; bh=Ls5eP08dXgIKhQU5IUZfcznzPTY9R0mvtRrX9FJWQTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SvLeGofDAeEaVQJ8RZz8vxmt45M2I1YA7FxXtWG4tN1JPpSr9ndDDy2NDv3K/cQVw axKSZUvRlCthgJLH0F+72GgFeNWnY+wwJcWGQEedwuh0IikgFy9w6CDhzake8ZOtit VUL/607gmjlJAZSOWsS/HA4ZAZlNj7P+z4+8pDe0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Walleij , Christophe Leroy , Mark Brown , Sasha Levin , linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 011/187] gpio: Handle counting of Freescale chipselects Date: Fri, 27 Dec 2019 12:37:59 -0500 Message-Id: <20191227174055.4923-11-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191227174055.4923-1-sashal@kernel.org> References: <20191227174055.4923-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Linus Walleij [ Upstream commit 71b8f600b034c7f5780f6fb311dabfe331c64feb ] 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 Tested-by: Christophe Leroy Link: https://lore.kernel.org/r/20191128083718.39177-2-linus.walleij@linaro.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib-of.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 80ea49f570f4..43ffec3a6fbb 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_named_count(np, "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", -- 2.20.1