From patchwork Tue Oct 11 22:19:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 614934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5FE9C433FE for ; Tue, 11 Oct 2022 22:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbiJKWUG (ORCPT ); Tue, 11 Oct 2022 18:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbiJKWTy (ORCPT ); Tue, 11 Oct 2022 18:19:54 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8884813F20; Tue, 11 Oct 2022 15:19:50 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o9-20020a17090a0a0900b0020ad4e758b3so279836pjo.4; Tue, 11 Oct 2022 15:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fh3v3yhN+2E5ygCgfV0BTHYUwG2aM97Wp0EcHi2gxlg=; b=O51pSS8/2qIEK3GhD0my1EHHUGlySin6EdmCRqCNr0sJOYKtpeXbjdAguScQCm9F8L jCBKghQYusOrqscaGpmphibwIrx9cSaxtm86FOg9U9kfLOD2Vy0YTSCPZEE59X/cPviB wJiYxhqtnfbBe3gzk02/jGzcdReijX3pm28iLyy8rHd/R3MLL94GhL/KnVvIFeDDYKac JOssavR2Xi7QXNbTVDX4txQNWE+xr4C/jRnEkXblJYAL85yTIeNPt9C1NE4PHJI/EvBq mpVB/W4kGp4erxK4iWcOWwNeEFK5jJZ0mEBVhuvchBKLhUDD9F15AfDX/Q+zRQdWSXkG 6abA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fh3v3yhN+2E5ygCgfV0BTHYUwG2aM97Wp0EcHi2gxlg=; b=z2+g495PL1atm25EIc0uKH66iZT42c7zI97fSFG2vU8bWnkvpPiTqMaB6sh3xzhtL4 qBPXdylRt6XKEKH0F3UuBzSVdacyTQmIDE64lBtpcAEtXNZ3sYTvPJ16w6DFOvEDG8K1 izwYZ85h7iVTu4Pl8KpLYR4R4+W0BJk/3jPamzjY+6mcHTiY3itmJHmnFNFRvfJ7ASLh rSPS4gM7oEU2fQQ52X4j+LLXkSe5ATg6eibBGBnSFvQafY8e7syr2wIKBUWLeWRNsbQc caMFFq4FI1zLd1SGZDW8UrNUTxBtxBu2nRDz8g8UEotU9L7kdUPta1O0kCR4K2hxRFoy 8Rpg== X-Gm-Message-State: ACrzQf1ofgXKt3jf56lmje3z5UL0rJsHcsla2s2/Duyx/mN4m3TIOgpQ BtupQgeJ4QNCOzBu+ECdoQPazA05d4Y= X-Google-Smtp-Source: AMsMyM5MwcBpgl/QmYTxnPgIwc8Ka6MfCq+pFUcwBI+LjlTQ/Qeb+hLI8u+4VZU7BazFQ98PYUkatw== X-Received: by 2002:a17:902:f689:b0:179:fdac:c4e2 with SMTP id l9-20020a170902f68900b00179fdacc4e2mr26995320plg.119.1665526789337; Tue, 11 Oct 2022 15:19:49 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:becc:db10:eb45:dc35]) by smtp.gmail.com with ESMTPSA id l6-20020a17090ab70600b0020d39ffe987sm60151pjr.50.2022.10.11.15.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 15:19:48 -0700 (PDT) From: Dmitry Torokhov To: Linus Walleij , Bartosz Golaszewski Cc: Daniel Thompson , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Andy Shevchenko , linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org Subject: [PATCH 6/7] gpiolib: of: factor out code overriding gpio line polarity Date: Tue, 11 Oct 2022 15:19:34 -0700 Message-Id: <20221011-gpiolib-quirks-v1-6-e01d9d3e7b29@gmail.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221011-gpiolib-quirks-v1-0-e01d9d3e7b29@gmail.com> References: <20221011-gpiolib-quirks-v1-0-e01d9d3e7b29@gmail.com> MIME-Version: 1.0 X-Mailer: b4 0.11.0-dev-5166b Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org There are several instances where we use a separate property to override polarity specified in gpio property. Factor it out into a separate function. Signed-off-by: Dmitry Torokhov --- drivers/gpio/gpiolib-of.c | 48 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 953d1c23950a..3200d705fbe3 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -130,6 +130,28 @@ bool of_gpio_need_valid_mask(const struct gpio_chip *gc) return false; } +/* + * Overrides stated polarity of a gpio line and warns when there is a + * discrepancy. + */ +static void of_gpio_quirk_polarity(const struct device_node *np, + bool active_high, + enum of_gpio_flags *flags) +{ + if (active_high) { + if (*flags & OF_GPIO_ACTIVE_LOW) { + pr_warn("%s GPIO handle specifies active low - ignored\n", + of_node_full_name(np)); + *flags &= ~OF_GPIO_ACTIVE_LOW; + } + } else { + if (!(*flags & OF_GPIO_ACTIVE_LOW)) + pr_info("%s enforce active low on GPIO handle\n", + of_node_full_name(np)); + *flags |= OF_GPIO_ACTIVE_LOW; + } +} + static void of_gpio_flags_quirks(const struct device_node *np, const char *propname, enum of_gpio_flags *flags, @@ -145,7 +167,7 @@ static void of_gpio_flags_quirks(const struct device_node *np, (!(strcmp(propname, "enable-gpio") && strcmp(propname, "enable-gpios")) && of_device_is_compatible(np, "regulator-gpio")))) { - bool active_low = !of_property_read_bool(np, + bool active_high = of_property_read_bool(np, "enable-active-high"); /* * The regulator GPIO handles are specified such that the @@ -153,13 +175,7 @@ static void of_gpio_flags_quirks(const struct device_node *np, * the polarity of the GPIO line. Any phandle flags must * be actively ignored. */ - if ((*flags & OF_GPIO_ACTIVE_LOW) && !active_low) { - pr_warn("%s GPIO handle specifies active low - ignored\n", - of_node_full_name(np)); - *flags &= ~OF_GPIO_ACTIVE_LOW; - } - if (active_low) - *flags |= OF_GPIO_ACTIVE_LOW; + of_gpio_quirk_polarity(np, active_high, flags); } /* * Legacy open drain handling for fixed voltage regulators. @@ -200,18 +216,10 @@ static void of_gpio_flags_quirks(const struct device_node *np, * 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; - } + bool active_high = of_property_read_bool(child, + "spi-cs-high"); + of_gpio_quirk_polarity(child, active_high, + flags); of_node_put(child); break; }