From patchwork Thu Aug 5 13:54:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 1513911 X-Patchwork-Delegate: chunkeey@googlemail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=gc25l2UA; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=pcrgjt6f; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GgVbD0rbfz9sWc for ; Thu, 5 Aug 2021 23:59:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=tq5r3t+YxzPUx+8xySXP2dQ8mHPzv3lV/17o0SCYPwA=; b=gc25l2UAWoY3Up Bok8yqqXrA1r0eT5m16aHU28jaqA2/BrMYjFmgXKVfLNP9bxGJdWKa/HyfiaWu5WDk4Q5+IG+uQSk YN7ExP3xPf/IPD/VbzVH5GJ1yRjv6R9dbwzHor1+pywvVi8ywnLbuNqZ70GOxd9AA6i0g7FswZLBO BlHIZNa5AB0KwvgUGzjj8t1p8PaYxp2jY01WXGnSM3q985/6KpgRFOqcl4nDqAI+GRJEUpyIIifNS JxaR3Gmu1ZVL7iykVjsaBA7rIMf6BDp1a1Vi/fm7Iyn3yDn0DWqZpClkXTRthBmh90Plrctmm9wG7 Bin5TLI48fRpRct245vQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBdp6-009kVv-TL; Thu, 05 Aug 2021 13:54:13 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBdp1-009kUd-0q for openwrt-devel@lists.openwrt.org; Thu, 05 Aug 2021 13:54:09 +0000 Received: by mail-wm1-x335.google.com with SMTP id e25-20020a05600c4b99b0290253418ba0fbso3778549wmp.1 for ; Thu, 05 Aug 2021 06:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Zfy2asFn5zjRYC/eIIBCjhY9u++hz7QoWZp+TED1rmY=; b=pcrgjt6fmdcxbZyJJQiKihpNAgyZM6jXRv6OWKvCbKBxR1ypIL+Q4oHDfJSh5vKm50 xkswpeolcKANfoZfPh2nQDE5bRASnK+5JZQT6H6xdU57OX/fC6y3SSGtO3fTU3qt4bsn 9TUNayQAZvqs3O/3l+c0ZwSQgHm2ykFIBcXl7EeEyrDs8/asmR5Qw1bL8hOJ6Qyyu7aO bKL0pNngkt4W+7hdHYxOCS+Paq8UU6/bxJlyx/9XWZ17st8OWEQgNNiChyNzkNfnCw9v 2epuwc6uVbeq8b82p2dOL2ybRXFBp9Ro7D+70VhJLZS4gr5w8oY4H2bhNUrz01MoA8sp cSig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Zfy2asFn5zjRYC/eIIBCjhY9u++hz7QoWZp+TED1rmY=; b=i1lbWdahd6CfZ8TeE60JU3o+o4nLFLD9pL/uWpoJSDlqVV7vK6cKHYFYah6o0lchiN xuov/OuywlFKUeFv/HIjP9XCEufDd9+sBp1hUwRJbsWtcoXTwmJMF99W/L7rFbfWBjVP Bs9ESGxFqr3S2+uJN3yca2Ozwcb/RDm4TmXGyCBP44345V0iWkrOhIfSY2FFTdw4dkWt wYq3eSC7kGuI9aLi2jsP0AcUlCJYCxyzcbxEBQdHh1aZkmcEKYlFu2sKehXq/dToMmkJ TL27mh6u80lofWBwUPdSZjUtD9AX/7OLFUB+FOWP4kw3B7svsoEsBtZmJyg71d3Ajbae M5lw== X-Gm-Message-State: AOAM530LPGL4OF/hc3+9mYIvxKHCrVuug1YppEi/LUHP9428njEXY01c vwuaQht+vRyg4gDw60bn+hZqiqLAVQY= X-Google-Smtp-Source: ABdhPJxirqG/7OBCIEgcIFWHIBKG3eRmScF96Po1m+aAGuWqae0DE5rvCg9W5qO5O54CrI1BGjkHtQ== X-Received: by 2002:a1c:a510:: with SMTP id o16mr5093496wme.176.1628171644456; Thu, 05 Aug 2021 06:54:04 -0700 (PDT) Received: from debian64.daheim (p5b0d7a6c.dip0.t-ipconnect.de. [91.13.122.108]) by smtp.gmail.com with ESMTPSA id n30sm7382428wra.1.2021.08.05.06.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 06:54:04 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.94.2) (envelope-from ) id 1mBdox-001AM1-8A; Thu, 05 Aug 2021 15:54:03 +0200 From: Christian Lamparter To: openwrt-devel@lists.openwrt.org Cc: linus.walleij@linaro.org, chrisrblake93@gmail.com Subject: [RFC PATCH] gpio-button-hotplug: gpio descriptor API update Date: Thu, 5 Aug 2021 15:54:03 +0200 Message-Id: <20210805135403.278083-1-chunkeey@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210805_065407_115401_EC63BCFA X-CRM114-Status: GOOD ( 17.87 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This driver still uses the Legacy GPIO Subsystem gpio_ API. While it does work fine, it won't supports the new GPIO LOOKUP tables that have been popping up upstream since v5.0. For APU2 users > linux 5.4: Please test if this fixes your reset button. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:335 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [chunkeey[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This driver still uses the Legacy GPIO Subsystem gpio_ API. While it does work fine, it won't supports the new GPIO LOOKUP tables that have been popping up upstream since v5.0. For APU2 users > linux 5.4: Please test if this fixes your reset button. (DT devices needs to be re-tested as well) Reported-by: Chris Blake Signed-off-by: Christian Lamparter Reviewed-by: Linus Walleij --- .../src/gpio-button-hotplug.c | 83 ++++++++----------- 1 file changed, 35 insertions(+), 48 deletions(-) diff --git a/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c b/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c index 9575c6245b..bc151645e3 100644 --- a/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c +++ b/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c @@ -242,11 +242,11 @@ static int gpio_button_get_value(struct gpio_keys_button_data *bdata) int val; if (bdata->can_sleep) - val = !!gpio_get_value_cansleep(bdata->b->gpio); + val = !!gpiod_get_value_cansleep(bdata->gpiod); else - val = !!gpio_get_value(bdata->b->gpio); + val = !!gpiod_get_value(bdata->gpiod); - return val ^ bdata->b->active_low; + return val; } static void gpio_keys_handle_button(struct gpio_keys_button_data *bdata) @@ -391,35 +391,15 @@ gpio_keys_get_devtree_pdata(struct device *dev) of_property_read_u32(node, "poll-interval", &pdata->poll_interval); for_each_child_of_node(node, pp) { - enum of_gpio_flags flags; - - if (!of_find_property(pp, "gpios", NULL)) { - pdata->nbuttons--; - dev_warn(dev, "Found button without gpios\n"); - continue; - } - button = (struct gpio_keys_button *)(&pdata->buttons[i++]); - button->irq = irq_of_parse_and_map(pp, 0); + button->gpio = -ENOENT; /* gets filled in later */ - button->gpio = of_get_gpio_flags(pp, 0, &flags); - if (button->gpio < 0) { - error = button->gpio; - if (error != -ENOENT) { - if (error != -EPROBE_DEFER) - dev_err(dev, - "Failed to get gpio flags, error: %d\n", - error); - return ERR_PTR(error); - } - } else { - button->active_low = !!(flags & OF_GPIO_ACTIVE_LOW); - } + button->irq = irq_of_parse_and_map(pp, 0); if (of_property_read_u32(pp, "linux,code", &button->code)) { - dev_err(dev, "Button without keycode: 0x%x\n", - button->gpio); + dev_err(dev, "Button node '%s' without keycode\n", + pp->full_name); error = -EINVAL; goto err_out; } @@ -514,7 +494,6 @@ static int gpio_keys_button_probe(struct platform_device *pdev, for (i = 0; i < pdata->nbuttons; i++) { struct gpio_keys_button *button = &buttons[i]; struct gpio_keys_button_data *bdata = &bdev->data[i]; - unsigned int gpio = button->gpio; if (button->wakeup) { dev_err(dev, "does not support wakeup\n"); @@ -534,26 +513,37 @@ static int gpio_keys_button_probe(struct platform_device *pdev, continue; } - error = devm_gpio_request(dev, gpio, + bdata->gpiod = devm_gpiod_get_index(dev, + button->desc ? button->desc : DRV_NAME, i, GPIOD_IN); + if (IS_ERR(bdata->gpiod)) { + unsigned gpio; + + error = PTR_ERR(bdata->gpiod); + + /* + * In case of -ENOENT, there still hope that we might + * just be using legacy platform data, which has the + * button->gpio filled in. + */ + if (error != -ENOENT || !gpio_is_valid(button->gpio)) + return error; + + gpio = button->gpio; + error = devm_gpio_request_one(dev, gpio, GPIOF_IN | + (button->active_low ? GPIOF_ACTIVE_LOW : 0), button->desc ? button->desc : DRV_NAME); - if (error) { - dev_err(dev, "unable to claim gpio %u, err=%d\n", - gpio, error); - return error; - } - bdata->gpiod = gpio_to_desc(gpio); - if (!bdata->gpiod) - return -EINVAL; + if (error) { + dev_err(dev, "unable to claim gpio %u, err=%d\n", + gpio, error); + return error; + } - error = gpio_direction_input(gpio); - if (error) { - dev_err(dev, - "unable to set direction on gpio %u, err=%d\n", - gpio, error); - return error; + bdata->gpiod = gpio_to_desc(gpio); + if (!bdata->gpiod) + return -EINVAL; } - bdata->can_sleep = gpio_cansleep(gpio); + bdata->can_sleep = gpiod_cansleep(bdata->gpiod); bdata->last_state = -1; /* Unknown state on boot */ if (bdev->polled) { @@ -608,11 +598,8 @@ static int gpio_keys_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&bdata->work, gpio_keys_irq_work_func); - if (!bdata->gpiod) - continue; - if (!button->irq) { - bdata->irq = gpio_to_irq(button->gpio); + bdata->irq = gpiod_to_irq(bdata->gpiod); if (bdata->irq < 0) { dev_err(&pdev->dev, "failed to get irq for gpio:%d\n",