From patchwork Fri Aug 18 19:09:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 715069 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 01844EE498D for ; Fri, 18 Aug 2023 19:10:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245313AbjHRTKV (ORCPT ); Fri, 18 Aug 2023 15:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379566AbjHRTJw (ORCPT ); Fri, 18 Aug 2023 15:09:52 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A6EB3A9A for ; Fri, 18 Aug 2023 12:09:50 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3197b461bb5so1050726f8f.3 for ; Fri, 18 Aug 2023 12:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1692385789; x=1692990589; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=amkvA6oVV+l1eNsM2AWwmHoLgXyiDp9eihxuhp7cWNc=; b=3mIHXGgU/eI83YuHIPw3zwbwQTJNCeegwalUbfzmwqPus1IF6TO+/9fouBkFV3uRg7 HXKpZ9Dum1GCYwkE+BpbGhEEfME9xE6jT2HCakTssRn36cfog2hTN3p9kD/IvbSF3Q2g qx8+4mom7REdxk9eM0HDojVBpSD1Vt1cjORzQGbjUK8dcxuHxHx09E4VELHSSmuaN/LJ ohxzRbWImIyKG6BtDjJWwhjXTXceVxxbp0rhbCNa0jv38yMI5vnAZKIpYx37iTOeb/od OOwiqjAU6VhYvMVtAyvsdVOVZ2wpM796HT2jd0S9tbXLwrOu5YLF3ND0vjS1FPMBftd8 H+kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692385789; x=1692990589; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=amkvA6oVV+l1eNsM2AWwmHoLgXyiDp9eihxuhp7cWNc=; b=ERfmS05NBumjgxXWl3bjnrAk4z8pCUEdMiaXlhOzNoHtTNvkh4Ucw0ph6fAY1+weuY 3R+tIT1wBiajV8ftZ2fKeRnSSlfH4rSK/qc2jUZfMS06MP0AMDzjE++PSt6OapCrjnIA y0JjGT8svqCh9NNAun687R450ThCS/M9WHEW1AemP2vOJu4qIwwhrXHiKTvV86lL7FjH 0n6J9k8qVAMmFgE7/dAU+QXz27ZanNa6LQmnrF82j4PV32ZSwCz9HUiPXcJRnHUXdMKt ugHykNYxt+0juwR9Mt/wNNrvpyyYf0VjxanWqOZW7ePYfSQF7W+MPCWsU8BSXA/6WNVy ymvg== X-Gm-Message-State: AOJu0Yxl2KbMUTyjnrmtZai9ngcz7NQig/hj9tN+HPT4QaLNQ0HrqLRl CtaIdPEhcp8Kb0HmZ5yq3ta04A== X-Google-Smtp-Source: AGHT+IESWKOC22E20uRDQDPy12DpszS869olMVnEFhVi1k3xxTPABCit6DasW/5yeaTfK+91OxnqNQ== X-Received: by 2002:a05:6000:87:b0:317:69d2:35c2 with SMTP id m7-20020a056000008700b0031769d235c2mr88663wrx.2.1692385788947; Fri, 18 Aug 2023 12:09:48 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d1c5:9f1f:6f05:38a3]) by smtp.gmail.com with ESMTPSA id i14-20020a5d630e000000b0031980783d78sm3669191wru.54.2023.08.18.12.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 12:09:48 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] gpiolib: notify user-space about line state changes triggered by kernel Date: Fri, 18 Aug 2023 21:09:44 +0200 Message-Id: <20230818190944.22177-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We currently only emit CHANGED_CONFIG events when the user-space changes GPIO config. We won't be notified if changes come from in-kernel. Let's call the notifier chain whenever kernel users change direction or any of the active-low, debounce or consumer name settings. We don't notify the user-space about the persistence as the uAPI has no notion of it. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 76e0c38026c3..77e0d0afa2b5 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2421,6 +2421,9 @@ int gpiod_direction_input(struct gpio_desc *desc) } if (ret == 0) { clear_bit(FLAG_IS_OUT, &desc->flags); + blocking_notifier_call_chain(&desc->gdev->notifier, + GPIO_V2_LINE_CHANGED_CONFIG, + desc); ret = gpio_set_bias(desc); } @@ -2466,8 +2469,12 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) gc->set(gc, gpio_chip_hwgpio(desc), val); } - if (!ret) + if (!ret) { set_bit(FLAG_IS_OUT, &desc->flags); + blocking_notifier_call_chain(&desc->gdev->notifier, + GPIO_V2_LINE_CHANGED_CONFIG, + desc); + } trace_gpio_value(desc_to_gpio(desc), 0, val); trace_gpio_direction(desc_to_gpio(desc), 0, ret); return ret; @@ -2654,9 +2661,15 @@ EXPORT_SYMBOL_GPL(gpiod_set_config); int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce) { unsigned long config; + int ret; config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce); - return gpiod_set_config(desc, config); + ret = gpiod_set_config(desc, config); + if (!ret) + blocking_notifier_call_chain(&desc->gdev->notifier, + GPIO_V2_LINE_CHANGED_CONFIG, + desc); + return ret; } EXPORT_SYMBOL_GPL(gpiod_set_debounce); @@ -2705,6 +2718,8 @@ void gpiod_toggle_active_low(struct gpio_desc *desc) { VALIDATE_DESC_VOID(desc); change_bit(FLAG_ACTIVE_LOW, &desc->flags); + blocking_notifier_call_chain(&desc->gdev->notifier, + GPIO_V2_LINE_CHANGED_CONFIG, desc); } EXPORT_SYMBOL_GPL(gpiod_toggle_active_low); @@ -3312,6 +3327,8 @@ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) kfree_const(desc->label); desc_set_label(desc, name); + blocking_notifier_call_chain(&desc->gdev->notifier, + GPIO_V2_LINE_CHANGED_CONFIG, desc); return 0; }