Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1766229ybl; Sat, 11 Jan 2020 02:23:04 -0800 (PST) X-Google-Smtp-Source: APXvYqzAoWuBvmSQAbeUF6piBejNDWnpQwA1eRcRk12vwW8QSAzh4lYXtVUwWYW4cPMv3jVza2Y8 X-Received: by 2002:a9d:3e16:: with SMTP id a22mr6734310otd.259.1578738184654; Sat, 11 Jan 2020 02:23:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578738184; cv=none; d=google.com; s=arc-20160816; b=t8u2IExqulTCRy6s6EuSb8FsdGsdDggx72CzGS1k65xNj3ibIfp1e9CG6co/aozDWm bAOx64K/uDxUxfKuQk3S6oXQXE22lFh7TDoo0dWpG08wlaE4pIon0wC/srhA6eHrH411 pDkmtf4PgxKWr1QqHua8I+9W2iVTSUQuTcB6fl5NQxN6RhEEj1pl1L9zJVgOrLgsM2Jq uSIwmGFeT5Cuh6IQJd3VJ9Tx1YWl/NbJen1u6M91CKvq+u8CgSIvub+aUA1px69XZgfX 2WwYBsVPNJDOQJDpDNsbiR52zGQDB88Gz4ibsd5BhxCL4maYGCQRpVxR03bz8C3icj8+ r7QA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3AlCfm8I2YFe0n4hhzXmwaFM0JpL15yTv48KxGJBbnY=; b=ZCkuSnwOXwJsqcuCulZhhN4oEu7zT1hHLYbr9ckwbktQO4MOgnT02sCXltyQemYX+r mmP4QvoDIhjKCJnnS9Fw5pxNxhmCiBElB43Ang4Y8UuQo0HqemWP9DYrpxaO5hQQn165 WORSjM5DJ/HtW/Q7+NiCIDT7LtTGadpTpD+nWK4wZWvhOqAwhNQlakF2oa+HoO49FvLR ya/+3lEdGjEsbJOrMy7PrzoIl/bpyXsRsyfOU6Hc+V4UtoK8iP2uQDB2H6dc6ZzyDa7l f3XAu/3qvP3umtuDPEz7iJ8cgHZUYD8eBrvC8PJ+KI0ag3sVIAVn+9AXK8BU4zDdsWSK mn2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tAEW9qTJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si3085787oia.169.2020.01.11.02.22.53; Sat, 11 Jan 2020 02:23:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=tAEW9qTJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730590AbgAKKVA (ORCPT + 99 others); Sat, 11 Jan 2020 05:21:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:43308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730577AbgAKKU4 (ORCPT ); Sat, 11 Jan 2020 05:20:56 -0500 Received: from localhost (unknown [62.119.166.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC8C420848; Sat, 11 Jan 2020 10:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738055; bh=Ls5eP08dXgIKhQU5IUZfcznzPTY9R0mvtRrX9FJWQTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAEW9qTJRfWMhZo40h6uKHuGQCWTErlgIJz2HS8S8kOk32wc8qfEQoGdU7OHKoiDg qLS20meJ2FhdaNncNgCzV8NwohYpkDijsTbdeRBop8lWZ1pHkQFMNxxLv72bxowG8s U40qIXyaH93K7VxVDOR1FEcOF8l9iZL/Ror8YmmA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Linus Walleij , Mark Brown , Sasha Levin Subject: [PATCH 5.4 008/165] gpio: Handle counting of Freescale chipselects Date: Sat, 11 Jan 2020 10:48:47 +0100 Message-Id: <20200111094921.938767017@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094921.347491861@linuxfoundation.org> References: <20200111094921.347491861@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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