From patchwork Tue Oct 18 05:41:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1691345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Nj7SpUxq; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Ms2mr1Z7tz23jk for ; Tue, 18 Oct 2022 16:42:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbiJRFmB (ORCPT ); Tue, 18 Oct 2022 01:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbiJRFlo (ORCPT ); Tue, 18 Oct 2022 01:41:44 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8446A3F60; Mon, 17 Oct 2022 22:41:31 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id a6-20020a17090abe0600b0020d7c0c6650so16363802pjs.0; Mon, 17 Oct 2022 22:41:31 -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=aAo5oGxoQQ9M35JSkjwS/M3VaYU6KO6LohL0MAi6tfs=; b=Nj7SpUxqGWO/g5w8qtXKXYOgpeXvQWI0giRLoUtM/08fFN1XpvrQ0O30qHx6FrIfIb C/CR50B74wIm07MrIzIj6cC9kLGf2G/5cp/sHdMQMrdazlroSc+Biv2BC5VqQWqP8915 yTXE3pSWpXjhjKFf/yZTiJxImEV4wPYpJPLZAa9RAarPTxWVoo9PbZ6oyL8zH3jeSHOX XmTTLNZMCJ01LDAHOhv+hgMcaboEyicpyUtz9Ro8apyzA9Uy5JwauG/RDI/aCe94GHvv PpVjGTBmJmx+n+35E9c5u4KL4j2/nut1WZu7AKFv4Gdyfrbkopv6yiB/4Md5dVvGf/vT CwQQ== 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=aAo5oGxoQQ9M35JSkjwS/M3VaYU6KO6LohL0MAi6tfs=; b=Mvb2EvusChTSlW02SEXCVuOs2gpQmiX0Myw/NGIpxX1mhdEX9QHzyVKs3gD6z4PpZ2 vk3ieNtQDMeJXPtdo3kVMvRyWdLKT5KeJFOSDQ5BtPU1Fdh5b5T3IZZuM/lrSEU1rD9F FVn31FWc7wtbBDTdz8r8q3XtPI2ppbHxDh63kR4p61Uxdd7LIA5bPgaKSkIXqtR1xMGf 7el66ZNgz8b7Dwadk58eHz9/UclWmpACLLj5MwE+pFPnX4ZT/4H+yPyKyKUry15o1eE7 E5uwvRX9z1rBqWXe/EPSGdgShrntVpeLRWp5XgYmnNtewu2e7vc1Be/urXUbCa95AbEF 6nPA== X-Gm-Message-State: ACrzQf3dXVuFw26hEouLhYAhYTcjL3IVUOONwbLcRmbg1bhWkl2a9fcW Xul5A7CgVBMhxmh0Z5Baj11FhjwD14J2XA== X-Google-Smtp-Source: AMsMyM5psfIakJgMDw/HEqJqCW2SWqB/Y1AAF5bTHufNONjzn9g2OVeIPLHFUev+XHc/9EEpIwa20A== X-Received: by 2002:a17:902:b606:b0:184:1183:5f9f with SMTP id b6-20020a170902b60600b0018411835f9fmr1431169pls.84.1666071690510; Mon, 17 Oct 2022 22:41:30 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:f7bc:1bb5:e0b1:92cb]) by smtp.gmail.com with ESMTPSA id z7-20020a1709027e8700b00172f4835f53sm7597435pla.192.2022.10.17.22.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 22:41:29 -0700 (PDT) From: Dmitry Torokhov To: Bartosz Golaszewski , Linus Walleij Cc: Alexander Stein , linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, Andy Shevchenko , Daniel Thompson , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v3 08/10] gpiolib: of: factor out code overriding gpio line polarity Date: Mon, 17 Oct 2022 22:41:09 -0700 Message-Id: <20221011-gpiolib-quirks-v3-8-eae9cc2ed0a1@gmail.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221011-gpiolib-quirks-v3-0-eae9cc2ed0a1@gmail.com> References: <20221011-gpiolib-quirks-v3-0-eae9cc2ed0a1@gmail.com> MIME-Version: 1.0 X-Mailer: b4 0.11.0-dev-5166b X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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. Reviewed-by: Linus Walleij 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 d22498c72a67..6faf0dc7bc31 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; }