From patchwork Thu May 6 03:00:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Fang X-Patchwork-Id: 12241535 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 B8034C43460 for ; Thu, 6 May 2021 03:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B00C600D4 for ; Thu, 6 May 2021 03:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbhEFDBZ (ORCPT ); Wed, 5 May 2021 23:01:25 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17469 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231745AbhEFDBY (ORCPT ); Wed, 5 May 2021 23:01:24 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FbJCy2qdWzkWqK; Thu, 6 May 2021 10:57:50 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Thu, 6 May 2021 11:00:16 +0800 From: Jay Fang To: , CC: , , , , Subject: [PATCH 1/2] spi: Correct CS GPIOs polarity when using GPIO descriptors Date: Thu, 6 May 2021 11:00:16 +0800 Message-ID: <1620270017-52643-2-git-send-email-f.fangjian@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620270017-52643-1-git-send-email-f.fangjian@huawei.com> References: <1620270017-52643-1-git-send-email-f.fangjian@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org When using GPIO descriptors for CS GPIOs we need to inspect the child node to determine if the 'cs-gpios' active flags should have inverted semantics. Previously, commit 6953c57ab172 ("gpio: of: Handle SPI chipselect legacy bindings") introduced a special quirk to solve the conflict between the 'cs-gpios' flags and the optional SPI slaves flags. The principle is that the SPI slave flag will take precedence when we get a conflict. For more details, see Documentation/devicetree/bindings/spi/spi-controller.yaml. If following the previous commit, we need to add a new quirk to deal with this in ACPI. Instead, this patch introduces a generic implementation to solve this conflict by SPI core. The 'cs-gpios' active rules are as follows: 1) DT (SPI device have active low chip selects by default): device node | cs-gpio | CS pin state active ================+===============+===================== spi-cs-high | - | H - | - | L spi-cs-high | ACTIVE_HIGH | H - | ACTIVE_HIGH | L spi-cs-high | ACTIVE_LOW | H - | ACTIVE_LOW | L 2) ACPI: device node | cs-gpio | CS pin state active ================+===============+===================== PolarityLow | ACTIVE_LOW | L PolarityLow | ACTIVE_HIGH | L PolarityHigh | ACTIVE_LOW | H PolarityHigh | ACTIVE_HIGH | H Signed-off-by: Jay Fang Signed-off-by: Zihao Tang --- drivers/spi/spi.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index b08efe8..2c0324d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -33,6 +33,7 @@ #include #include #include +#include <../gpio/gpiolib.h> #define CREATE_TRACE_POINTS #include @@ -604,9 +605,26 @@ int spi_add_device(struct spi_device *spi) } /* Descriptors take precedence */ - if (ctlr->cs_gpiods) + if (ctlr->cs_gpiods) { spi->cs_gpiod = ctlr->cs_gpiods[spi->chip_select]; - else if (ctlr->cs_gpios) + + /* We need to handle the active flag conflict between + * the cs-gpio and the SPI slave. The SPI slave active + * flag will determine the active state of cs-gpio. + */ + if (spi->mode & SPI_CS_HIGH) { + if (test_bit(FLAG_ACTIVE_LOW, &spi->cs_gpiod->flags)) { + dev_warn(&spi->dev, "GPIO handle specifies " + "active low - ignored\n"); + clear_bit(FLAG_ACTIVE_LOW, &spi->cs_gpiod->flags); + } + } else { + if (!test_bit(FLAG_ACTIVE_LOW, &spi->cs_gpiod->flags)) + dev_warn(&spi->dev, "enforce active low on " + "chipselect handle\n"); + set_bit(FLAG_ACTIVE_LOW, &spi->cs_gpiod->flags); + } + } else if (ctlr->cs_gpios) spi->cs_gpio = ctlr->cs_gpios[spi->chip_select]; /* Drivers may modify this initial i/o setup, but will From patchwork Thu May 6 03:00:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Fang X-Patchwork-Id: 12241533 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 6445AC43461 for ; Thu, 6 May 2021 03:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34B94613BA for ; Thu, 6 May 2021 03:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231473AbhEFDBY (ORCPT ); Wed, 5 May 2021 23:01:24 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17468 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbhEFDBY (ORCPT ); Wed, 5 May 2021 23:01:24 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FbJCy2bXCzkWqJ; Thu, 6 May 2021 10:57:50 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Thu, 6 May 2021 11:00:17 +0800 From: Jay Fang To: , CC: , , , , Subject: [PATCH 2/2] Revert "gpio: of: Handle SPI chipselect legacy bindings" Date: Thu, 6 May 2021 11:00:17 +0800 Message-ID: <1620270017-52643-3-git-send-email-f.fangjian@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620270017-52643-1-git-send-email-f.fangjian@huawei.com> References: <1620270017-52643-1-git-send-email-f.fangjian@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org This reverts commit 6953c57ab1721ce57914fc5741d0ce0568756bb0. The latter introduced a generic implementation to resolve it by SPI core and is not needed anymore after the previous commit. Signed-off-by: Jay Fang --- drivers/gpio/gpiolib-of.c | 51 ++--------------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index baf0153..b8337f8b 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -132,8 +132,7 @@ bool of_gpio_need_valid_mask(const struct gpio_chip *gc) static void of_gpio_flags_quirks(struct device_node *np, const char *propname, - enum of_gpio_flags *flags, - int index) + enum of_gpio_flags *flags) { /* * Some GPIO fixed regulator quirks. @@ -172,52 +171,6 @@ static void of_gpio_flags_quirks(struct device_node *np, of_node_full_name(np)); } - /* - * Legacy handling of SPI active high chip select. If we have a - * property named "cs-gpios" we need to inspect the child node - * to determine if the flags should have inverted semantics. - */ - if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && - of_property_read_bool(np, "cs-gpios")) { - struct device_node *child; - u32 cs; - int ret; - - for_each_child_of_node(np, child) { - ret = of_property_read_u32(child, "reg", &cs); - if (ret) - continue; - if (cs == index) { - /* - * SPI children have active low chip selects - * by default. This can be specified negatively - * by just omitting "spi-cs-high" in the - * device node, or actively by tagging on - * GPIO_ACTIVE_LOW as flag in the device - * tree. If the line is simultaneously - * tagged as active low in the device tree - * and has the "spi-cs-high" set, we get a - * conflict and the "spi-cs-high" flag will - * take precedence. - */ - if (of_property_read_bool(child, "spi-cs-high")) { - if (*flags & OF_GPIO_ACTIVE_LOW) { - pr_warn("%s GPIO handle specifies active low - ignored\n", - of_node_full_name(child)); - *flags &= ~OF_GPIO_ACTIVE_LOW; - } - } else { - if (!(*flags & OF_GPIO_ACTIVE_LOW)) - pr_info("%s enforce active low on chipselect handle\n", - of_node_full_name(child)); - *flags |= OF_GPIO_ACTIVE_LOW; - } - of_node_put(child); - break; - } - } - } - /* Legacy handling of stmmac's active-low PHY reset line */ if (IS_ENABLED(CONFIG_STMMAC_ETH) && !strcmp(propname, "snps,reset-gpio") && @@ -263,7 +216,7 @@ static struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, goto out; if (flags) - of_gpio_flags_quirks(np, propname, flags, index); + of_gpio_flags_quirks(np, propname, flags); pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", __func__, propname, np, index,