From patchwork Fri Oct 4 14:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1992770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=WVd4Tw54; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-gpio+bounces-10857-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XKrsc6zCSz1xt7 for ; Sat, 5 Oct 2024 00:44:20 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3DD531C208E5 for ; Fri, 4 Oct 2024 14:44:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1776B21B442; Fri, 4 Oct 2024 14:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="WVd4Tw54" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4238821B422 for ; Fri, 4 Oct 2024 14:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053018; cv=none; b=PAFz1cJGAAFwo2kdJV24A3MMFv4FAm8bfhK1SWYy4q1yISKVnzpPcz0XnjxjiqnRbkxfJVtzQsSYULsqpHHywGA1+2I8i6AJvQCHj2f0UjiVnYU28ivf6XiAB8fMyzd/TizTtUGJfOjsuVzhCPu9VenecWQ9Y5go6RNBVAnL1us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053018; c=relaxed/simple; bh=mTbxUxfH/W1IhTrQ77MjGIe1i70HdR5QpW2zw30Atk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R4toJs4XHJx2PMt5JGH3/04cOjGqeGyZlqcMViN4gDg51egrkRI+he9aiwj5teS+0Q8pDB/EwxVoQowcZXIBT8BRYVeiGWr208hsz3pJFCOAez+R6toGnu4Xr0or6Vw0lsEtNllSKQjZXjfhoZVj+Kpphmzs/LaHC6V37kWC3ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=WVd4Tw54; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42cbc22e1c4so17884045e9.2 for ; Fri, 04 Oct 2024 07:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1728053015; x=1728657815; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=H9HtJhv2OgjVrkOPzzQfXaqIVpBHmCwwecKLw+BCJgo=; b=WVd4Tw54rnxHr9ul1e9wHHu0ZIyQkKTyF05t7oMu4DmyF3k1Df4KTOQQluXTpRLMrm iH7KEWDa6PEchbBTk3iyxhMP7jOdcpMc3IYap7uUjcVY+DfKEFFINv6F+eZV0cH1sgwz GGVwy2qrzncR1w7sTsBZUM7qU/45M7rB0RuZ9Dt2CVGh2nEIksrVG+LRYxnSMXHAiysL 63cUUoxAQ7pvQ6WaFvuBhqCvfd/vMmBpQbCPrV6uH3IPrP4QDPVXB1bps8YgGmT3o/jJ rOcjTgmTrWE4oTyxsoMSA9uCfgW04B0hqEKasCGt7iT8UqbeaCN5R1D7pm2tZ2GAcLht 8gow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053015; x=1728657815; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H9HtJhv2OgjVrkOPzzQfXaqIVpBHmCwwecKLw+BCJgo=; b=YkdtD+mN2nmpOeWW3+8wFAD8eSc2Ws7wpLKIJFH9tw6S13HLLMJsm5CQxW7+QEeb68 PVQLH2LMWHSe2+feedUUPnGDKWbryu8CPwoMsFxPvAq9B9nf3FOZ/uP3IF8X5zYmuf1m 7Pb4pQDHxU83zwJ8Pt65mjUbye4Q3pFZQfmEi6tMud7nw/5vK61S3+PDwH9/8RFJdRPQ 3mT3qx47mkl7Y0yVkMh0va5s7PXC1VFWWO0a40ItWPpP83hW/5Fx3446pYT/jDHkmni6 uIaCEGSZssM/I/Bh+qhSzKsws5ajA9g64+W8kzarMf3krBPCyA/66QS+xB1tY4wOflY5 Jj4g== X-Gm-Message-State: AOJu0Yy8WeNwFVM4jiq5aMdY8aLsRE700p69lNmuNgUSFnVnLYePmgEk a6kw1AXycQsc+ODiwe2aQysipmJYPpcVyM5iYXTXc0Ub/AouF0wYqNl5v2oRWaaNc8vbyFwbgeA y X-Google-Smtp-Source: AGHT+IFm1vI2G+l7T6P3prtOY6eLRKhJJSDE0Bi64Yrs+Vw1dbkHWJHdthPe2RMFv/gUgvZjkgdSZg== X-Received: by 2002:a05:6000:1f11:b0:374:c847:85c with SMTP id ffacd0b85a97d-37d0e74d1a9mr1775876f8f.24.1728053015231; Fri, 04 Oct 2024 07:43:35 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:80ea:d045:eb77:2d3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082d20bcsm3361370f8f.100.2024.10.04.07.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:43:34 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Oct 2024 16:43:22 +0200 Subject: [PATCH 1/5] gpiolib: use v2 defines for line state change events Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-gpio-notify-in-kernel-events-v1-1-8ac29e1df4fe@linaro.org> References: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> In-Reply-To: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1145; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=GV9UbQrF97SgoHpvOQBfdX3GKi4ST9w/X7XOWpTaA0U=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBm//8U7avLQBDR+Jk16XDKwbBZucLe8em4mqFCg xIOM7R8TR6JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZv//FAAKCRARpy6gFHHX cpX6D/9krtQVe7uAEsAQ9QkLe5k4mu/RKjXoceGhMIgvZ9Nzkeihm8fJs+YFjsVX+EA83aKVeMX vPqtplrZU9E16y5otu0ERAZckZlyGGx8vuhUhPzWYPBBgnJKsnmGc9v95mLe0gBLBHJ8y/Jqo+d H9y9s0ScWo461RMxa5VadZRZqxWaS9+6Rx+24zlEAQ5vzCbEPVjMgyq1heo9uE57nbXb4gUKcXf m11S+Jl1YVJb5YUgWGSHS4xOA67ffgQV5MgDABhcZMhxbJ0IhRmaSBXlX1JeyDJ+u+qHLc7KcAG LTfcpJh5x7TJuZ5U2gXANEvgTaKi9Pl/zqzCty5WFGYPYBimod3DRSqwBysOXwzC0HXUkKJXlcH mBc3U3w29FlEhaOFzjfOgZXZndXcWf0Q3+PQsKvA+bod6fvKtxhohuJLIm3LMSoVIPDNPEoHwuW BuagJHTusdCCANPzD30cNpbNvOakFVa91sJJw6tWN15FLvvQKTgm9WqMknF4ujhei77sjtxiNZ/ uV86UFXXRKk+gg3emEnx+RmeNM7F/4pxgB0I2XOgHtvyME0evUprYRPGD6gIWbPhgvzAn9HEQQh TGBWutuvSJW8l+qX4H7RRTfSbGm0sxYQAD2cWe5KXdpNL3tckKySLkNbDKlAHpe8pwJ/0wfFNM1 BS6dCHl5LgBZGLA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We should only use v2 defines for line state change events. They will get tranlated to v1 if needed by gpio_v2_line_info_changed_to_v1(). This isn't really a functional change as they have the same values but let's do it for consistency. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6a5c28babf35..c1051d77fb88 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2434,7 +2434,7 @@ static void gpiod_free_commit(struct gpio_desc *desc) desc_set_label(desc, NULL); WRITE_ONCE(desc->flags, flags); - gpiod_line_state_notify(desc, GPIOLINE_CHANGED_RELEASED); + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_RELEASED); } } @@ -4366,7 +4366,7 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer, return ERR_PTR(ret); } - gpiod_line_state_notify(desc, GPIOLINE_CHANGED_REQUESTED); + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); return desc; } From patchwork Fri Oct 4 14:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1992771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=OrB2OOTB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-gpio+bounces-10858-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XKrt438YYz1xt7 for ; Sat, 5 Oct 2024 00:44:44 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 70BD81C20D50 for ; Fri, 4 Oct 2024 14:44:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 568B921BAEF; Fri, 4 Oct 2024 14:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="OrB2OOTB" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6160921B430 for ; Fri, 4 Oct 2024 14:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053020; cv=none; b=HNjlLrDgVwCEpTNvG54tajJ0hZMIgQLbmslj31Ir4vIUthQQfH89cttHUVwATaGSYaGVdodT5cmkhszmgAkpC0bKaXpJDUA2j9tlQWcWEt+pFgyQt32MyN/vCZrHUPgC9mZNO3DiwOpaRyeWkRTP7bmIHTo9jEu3rUIRa+qTVOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053020; c=relaxed/simple; bh=LvSUVHCEYa75B76/06/pgPDfGMpyB/pmvNoZX5DqpsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ss1d3DUA+LKjbkbVHyIrWmZwxAeP0GUAQOBSeCupcYbfIqRSEm5ae8E9B+XKNfG5lZzPBOgQAxb6+rMbNXD5wzR9Mmhpk7gbnb2bZfaOeB37Z2jmt5m5ujVhEcpfiTK4GX8Gdny+Kf+3xS+lVpmNC2FFtge3S8jiNugKYq+wngk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=OrB2OOTB; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-37ccf0c0376so1451917f8f.3 for ; Fri, 04 Oct 2024 07:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1728053016; x=1728657816; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1Ee5xWEeq7S4uSTcaRJnj1WAmTtYVkRiu3mWNu5ZDDk=; b=OrB2OOTBbNyh5g6l+EoRLPHnwLFEJfW/RI91dAkkXnSPjEcV29hwlrGicE1+K37xqd NnabvnC3IuYjXETKrbmKw10Z7jPsgokSuMk89u+kheZYttn5VdkyOFAumRrBYHlJUP2K sezrNzVUyVG77F0z12WAtFNzeKkSwdM+QUG5i9G8u7vP85auHFjCvH4F9NCKvMR/3p1e kYZuiqcagxehmOZ4232upMH605CKTgPZ0VAoizOcfzAzxoLoySxwdNnt+1og352jxPTR jXfMFLp2pkqE/N7S7d0sv1jR7ZNCEJHMSRhjC0qBssS1g/2U0fRsvFOCLbZ3eIXBaWxn oOyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053016; x=1728657816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Ee5xWEeq7S4uSTcaRJnj1WAmTtYVkRiu3mWNu5ZDDk=; b=FpuTonnfSdG8u7i3n8PTOclncFmAg/jpVPO5qlr8HarGRJ7R71IpV3+QGZF4Ujs2uR 1/4WyZLs7+Qb0YoyqcUZfGu9/HPo+hzTeagMJ4dqivWG4zvn4BjnWR3Ks2eplc1lGjjo 293eXlDyuQ2Nly/LDKWyHoK8C5xcml7FlmTrnJoQSH+x0kQgC/ABV5ei8N2uv5G7Rv0i 3vojGKYVQis1LnXL3ifZJtddyZbQi6ybmtXP8E+JrmalZGCxJ5X58Y1CsWOURRGSTaQG X4/VakJesWoGXSlC5ZYajaRXiEtWHGA5KeD980gYCMReehG9uMTWyLAidDZuopX5Ljpt kvLg== X-Gm-Message-State: AOJu0YzoeFRthD7Xukt8yqpV/9CJrmmAMfOpUl/tW2qbw/WIk5wEqn9Q 08U3pgEhqgt6lno+HCG5njnfLycJaNcutx5RFU5eJFkVv9Wrll7vyFEVNod32xsOd3mmGbRy+Ca e X-Google-Smtp-Source: AGHT+IH4ieDJNPwdvgv8ZCcUJ8Tih8/86uatD7Q7cdXsunzkfCocXl7DsElBA37H6akaQbNlgbRBqA== X-Received: by 2002:a5d:67cd:0:b0:37c:cd7e:6638 with SMTP id ffacd0b85a97d-37d0e6f2717mr1848046f8f.19.1728053016315; Fri, 04 Oct 2024 07:43:36 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:80ea:d045:eb77:2d3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082d20bcsm3361370f8f.100.2024.10.04.07.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:43:35 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Oct 2024 16:43:23 +0200 Subject: [PATCH 2/5] gpiolib: unify two loops initializing GPIO descriptors Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-gpio-notify-in-kernel-events-v1-2-8ac29e1df4fe@linaro.org> References: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> In-Reply-To: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1327; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ZDhG5KXyIkg99fKOqS3EbGyFcZRvR3MZeXd4yD4FiSk=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBm//8VwLw9BPyfaJK7F1XyQuwU0v+1yL8kdJkRI df+Jf7Q3nyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZv//FQAKCRARpy6gFHHX ciXfD/9gDhzfHmJyWP9oWZ2apaHgQM6rVNByAOpE/kriCMCLAG3KBOntI4oZgxzz6QUpiuh3mdB 2V6Qhos9yBVcKz+mSU1PCzeEQRe7SFHHw0N8KypvgwuegMFOvbKd16AYJj5x6lXLn4IMs7N/Apw /He4PoSl1jIYrrC3CmcY+2nRWo5Lf4qOc02TZkuUr7WCMaxFURxpb56XUizXYsLYsOwc9WAz8dj dn42OAih1Iop40J2FZbwaqP0MXPO8ASYwsibcirI5HF2WVvObQdAS9JMd6o1Ge8bVS3Kb4FdVL2 FM9XNzQMYChBOefgeFfjbdyyjT0axb/RE1Ze1S/a4XMkZzmJXwjwxJgoP6wZyGu5s+ZTV5cBeev jD5CsjiOKwbAz8k7HyqwbHhMHNW9bT/hqaYag9hn07MJ6cm6Ke3rqvOwgZyG9xkwjywYPLcnyo+ ASePfDY3VAxu0RD8hjCG7cpsbQGMidmUMOMuMs/lBzemL5Mvhsp46kT2qqx6yhTeM6/IPZviZbl 15WHdpXXilU9DxVISpsCgqMwea5uefZd3gHV8bZ/5SSxrat/xblUzmQ5VWeO2boLFJV5HgxjhFw jwyjASE4azh+fBOMVxPuu7B6r+sHezH/kzf2ifgXI25PlCCvR/S8+8IZnSALifTlVuqWn18yqrU 6yr2M0NNvsfGjog== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We currently iterate over the descriptors owned by the GPIO device we're adding twice with the first loop just setting the gdev pointer. It's not used anywhere between this and the second loop so just drop the first one and move the assignment to the second. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c1051d77fb88..97346b746ef5 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1026,9 +1026,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, } } - for (desc_index = 0; desc_index < gc->ngpio; desc_index++) - gdev->descs[desc_index].gdev = gdev; - BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); @@ -1058,6 +1055,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, for (desc_index = 0; desc_index < gc->ngpio; desc_index++) { struct gpio_desc *desc = &gdev->descs[desc_index]; + desc->gdev = gdev; + if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) { assign_bit(FLAG_IS_OUT, &desc->flags, !gc->get_direction(gc, desc_index)); From patchwork Fri Oct 4 14:43:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1992772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=EItN/f4B; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-10859-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XKrtP2v9jz1xt7 for ; Sat, 5 Oct 2024 00:45:01 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DBF1E1F2105A for ; Fri, 4 Oct 2024 14:44:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BE7C21BB19; Fri, 4 Oct 2024 14:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="EItN/f4B" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8023121B44D for ; Fri, 4 Oct 2024 14:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053021; cv=none; b=FZ2bTIbO6uVlxo5ndiMwRAivKDu42G8dw0JZA76WTtJDDPWZxhI63KZqdDWt+e3DxODyWRM7HuoRb0PdGnU2fel1TtL1tc6Ty/tLNAHgdtVB+aD8JbRNjI2KMxXmtP7jen5b3HPIVj1BC48SfCWPriDWy61wmafSJbZZ62cm7cA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053021; c=relaxed/simple; bh=nILLEVrSRUMuX39lz3JI49M+Jl9a8uMyMqPKy0crlCE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ECE+5pYEicZeBgpdyCSzf/YlFHiNqnj22xrX7fnan+ftzYhSljw+BnmAc8ZtB/SHLrO11bK9aVZpy8yMKimYKasV5FeLn/0A/SfltJApdyAkxVPXIepNkVb2yCYY7de4TSgRaGVsY5566wi0I1NDdRL0UKkOIMa2w9Az/B1cFVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=EItN/f4B; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-37cdb42b29dso1458821f8f.0 for ; Fri, 04 Oct 2024 07:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1728053017; x=1728657817; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7vd/1ALFEEqvJdDJR8cRrUppctjGlEDDTBM1Pkd8mDw=; b=EItN/f4BbjUFjWx0V+78y3vY59KMvFPWzPr+qKXhzXKH9+LlFmXX7y3S5bnObewRlv vw242fLULvAlHWZ3OhoQHUEfyO8MogUdw1p6X+7J5Yi00VC3Syu/PngG7po/1Xm3ueC/ KyfjsMdLap1cpOIykTzOW4r5GHCETwSS9ejvGjGsxBGRT1iDNAR5bv6LaPj1a48BY3v/ r1FhjscJPIf2xoWwqY/ZxLfjSdmof2ifWpnWSbk8tpRPIWb9PZCXjSXVVKhfj6tzoVpz PSMnHWxT4FBqqH9QPnQ73xCDBRsL4AVePdVyywhGjish80/WzWnIVY1N+CnLj7KGCpt2 c6Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053017; x=1728657817; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7vd/1ALFEEqvJdDJR8cRrUppctjGlEDDTBM1Pkd8mDw=; b=HKiWpK/wdvvqPH44dJ221up+tfaeRiVz6gAvJFRlQvyxB3NEwJRx4xWaBSIVK6xKNX e6pD1Ub/F07KTtvleLrdwPYrjaG3n6SuvqLLPMXubl3vvkRigzGLhJ20itlaV7rt5fQA +HMZUwz49fmWkJG78BxudAEDGZ3JL49sHYpa0E16WVCHdqn0tMONZ1U3nktEe+uxQUUX D1kbIUvxwjhrjdh26TyZNO9/HpcaH11xSnocYUBdDcUtVzu/m5bL37ZG8V5VnmGfuxI0 ugEZvz2v3nkgYFJyZQ+u6OM8WoGQiKAC53m8dQoupBnXA0QnFOTCGpc7300IeU0YUQ84 kBDQ== X-Gm-Message-State: AOJu0YzD0EHwBSX4wtMcywwHd8DEum2mWijWYrWWd5sHcHHKGgGVzPZ6 cUR/I3XXaY2d/rjh48nLN5DlxRG5uR8DQ76PxhYgEPsVgDz0MwujPo3+EtCiDGgLeFjhJbfuVng 5 X-Google-Smtp-Source: AGHT+IFOlwf1L/29DI0sE6sorIwM4sUuGpUATmRbKu+GBttC3o9DZIPg8ltKyasMoo4j0Kx5Yx9quQ== X-Received: by 2002:adf:f00a:0:b0:374:c3a3:1f4f with SMTP id ffacd0b85a97d-37d0e76fdf2mr2048119f8f.24.1728053017382; Fri, 04 Oct 2024 07:43:37 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:80ea:d045:eb77:2d3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082d20bcsm3361370f8f.100.2024.10.04.07.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:43:36 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Oct 2024 16:43:24 +0200 Subject: [PATCH 3/5] gpio: cdev: update flags at once when reconfiguring from user-space Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-gpio-notify-in-kernel-events-v1-3-8ac29e1df4fe@linaro.org> References: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> In-Reply-To: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4291; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ki9bnqoP0GYF3msoNU816SMbodAflXGpvokYWavz7z0=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBm//8VT5dAQQkkclXy52MS05gZoxyh4AYz3vXS/ UATzlpaS5CJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZv//FQAKCRARpy6gFHHX cjdGD/4+BHr0wq0zQIbMTrE1Eou3YpR0GQ6BZUcqFZERUcQuTYuRFR1kPDR5Cu3MkzhsZzM0Zlj gNqVo7YLSOSnxigxPMLM/xreqSkPdQymbxDIFGw6xnbd34+tNAlj3a9L0dagOAcJsS1d8heMnF4 dbEz1ZcDjgoEV+xJMzI5uIIrqxEOV6lJfnLSSUzvDFKPDJ0VjTl65H3zidrTzHS+Emob0YdH7QP kWL3GgRuM9YEh8W859HGLYaEYV/HaI++C9h8rFb4Sk5+B2iPgFKRCXwoUGd5LBJxh2Ju7G46faF TemMrKEId23sslmQKBrE1idevshk5kIbufaZHvT/EnUa+NOEupeQ8GdfkdXnNrfz2yKHmuVjYIX dGoO5+x11gX4S7KXmS2WQugAK2hQjBWhBzaTl+5r55kDT24m5qFfHTvIduByU7hOJS2wgOy7g8d +yIwGfkpCxD6GoM1X1yU0YnuysWe/U1ps8ew+eJGvffBSRVwVHx5N+LF/DogBjq9xwr+k5wyCLn 3vlRZQofvmJwWKBZK/K7MbwXRSzJkkoY/MGBgVKqZRib9QPr86vZ9OQSUbCnMNMqj9iz+xE10Sj XI3o6mNb+x4GMzEv4Fjp56Vjh5epTPmMTwyMZseibo+AWTPhtVIbpMuH1UjPMn26GrQIN7DFBhJ 6ph4KijIn6hF9Og== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Make updating the descriptor flags when reconfiguring from user-space consistent with the rest of the codebase: read the current state atomically, update it according to user's instructions and write it back atomically as well. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 70 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 6113a283c34a..b0050250ac3a 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -143,18 +143,22 @@ static int linehandle_validate_flags(u32 flags) static void linehandle_flags_to_desc_flags(u32 lflags, unsigned long *flagsp) { - assign_bit(FLAG_ACTIVE_LOW, flagsp, + unsigned long flags = READ_ONCE(*flagsp); + + assign_bit(FLAG_ACTIVE_LOW, &flags, lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW); - assign_bit(FLAG_OPEN_DRAIN, flagsp, + assign_bit(FLAG_OPEN_DRAIN, &flags, lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN); - assign_bit(FLAG_OPEN_SOURCE, flagsp, + assign_bit(FLAG_OPEN_SOURCE, &flags, lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE); - assign_bit(FLAG_PULL_UP, flagsp, + assign_bit(FLAG_PULL_UP, &flags, lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP); - assign_bit(FLAG_PULL_DOWN, flagsp, + assign_bit(FLAG_PULL_DOWN, &flags, lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN); - assign_bit(FLAG_BIAS_DISABLE, flagsp, + assign_bit(FLAG_BIAS_DISABLE, &flags, lflags & GPIOHANDLE_REQUEST_BIAS_DISABLE); + + WRITE_ONCE(*flagsp, flags); } static long linehandle_set_config(struct linehandle_state *lh, @@ -1348,38 +1352,42 @@ static int gpio_v2_line_config_validate(struct gpio_v2_line_config *lc, return 0; } -static void gpio_v2_line_config_flags_to_desc_flags(u64 flags, +static void gpio_v2_line_config_flags_to_desc_flags(u64 lflags, unsigned long *flagsp) { - assign_bit(FLAG_ACTIVE_LOW, flagsp, - flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW); + unsigned long flags = READ_ONCE(*flagsp); - if (flags & GPIO_V2_LINE_FLAG_OUTPUT) - set_bit(FLAG_IS_OUT, flagsp); - else if (flags & GPIO_V2_LINE_FLAG_INPUT) - clear_bit(FLAG_IS_OUT, flagsp); + assign_bit(FLAG_ACTIVE_LOW, &flags, + lflags & GPIO_V2_LINE_FLAG_ACTIVE_LOW); - assign_bit(FLAG_EDGE_RISING, flagsp, - flags & GPIO_V2_LINE_FLAG_EDGE_RISING); - assign_bit(FLAG_EDGE_FALLING, flagsp, - flags & GPIO_V2_LINE_FLAG_EDGE_FALLING); + if (lflags & GPIO_V2_LINE_FLAG_OUTPUT) + set_bit(FLAG_IS_OUT, &flags); + else if (lflags & GPIO_V2_LINE_FLAG_INPUT) + clear_bit(FLAG_IS_OUT, &flags); - assign_bit(FLAG_OPEN_DRAIN, flagsp, - flags & GPIO_V2_LINE_FLAG_OPEN_DRAIN); - assign_bit(FLAG_OPEN_SOURCE, flagsp, - flags & GPIO_V2_LINE_FLAG_OPEN_SOURCE); + assign_bit(FLAG_EDGE_RISING, &flags, + lflags & GPIO_V2_LINE_FLAG_EDGE_RISING); + assign_bit(FLAG_EDGE_FALLING, &flags, + lflags & GPIO_V2_LINE_FLAG_EDGE_FALLING); - assign_bit(FLAG_PULL_UP, flagsp, - flags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP); - assign_bit(FLAG_PULL_DOWN, flagsp, - flags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN); - assign_bit(FLAG_BIAS_DISABLE, flagsp, - flags & GPIO_V2_LINE_FLAG_BIAS_DISABLED); + assign_bit(FLAG_OPEN_DRAIN, &flags, + lflags & GPIO_V2_LINE_FLAG_OPEN_DRAIN); + assign_bit(FLAG_OPEN_SOURCE, &flags, + lflags & GPIO_V2_LINE_FLAG_OPEN_SOURCE); - assign_bit(FLAG_EVENT_CLOCK_REALTIME, flagsp, - flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME); - assign_bit(FLAG_EVENT_CLOCK_HTE, flagsp, - flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE); + assign_bit(FLAG_PULL_UP, &flags, + lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP); + assign_bit(FLAG_PULL_DOWN, &flags, + lflags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN); + assign_bit(FLAG_BIAS_DISABLE, &flags, + lflags & GPIO_V2_LINE_FLAG_BIAS_DISABLED); + + assign_bit(FLAG_EVENT_CLOCK_REALTIME, &flags, + lflags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME); + assign_bit(FLAG_EVENT_CLOCK_HTE, &flags, + lflags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE); + + WRITE_ONCE(*flagsp, flags); } static long linereq_get_values(struct linereq *lr, void __user *ip) From patchwork Fri Oct 4 14:43:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1992773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=KLeHX49V; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-gpio+bounces-10860-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XKrtl1fKQz1xtH for ; Sat, 5 Oct 2024 00:45:19 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 428F31C21681 for ; Fri, 4 Oct 2024 14:45:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C63922194BE; Fri, 4 Oct 2024 14:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="KLeHX49V" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDFBD21BB03 for ; Fri, 4 Oct 2024 14:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053022; cv=none; b=tD9x3sKEW/IWfi6IVXdwGyzDbMyiutyIDn9x6glL7LkCkDVTTph5AmhTDoMlENR0lePMNNcRMArnMaoVPjezSneZAuQvxYPezZvlOPnwOP/ZEX/kV0qzdv3aWRmE0whbjuJvYrV3Ftf3BYz3kS2sVbZCr0EXtv43D+UquPxR6Fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053022; c=relaxed/simple; bh=vCyqKCwfy1nt5e7v08lKAFzg/0ovYPR6Dgie6Fnihdo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kQW+DGMTKB9iDNhOZi+xImOKUKG3EM06NtDtqrpDbQZhUtv0Y5hhULUFaQOfBgcr/xvB/fa1aqEVIiDTbQjcF+voNk3lNujUitckUldlxhDTOBjb0w1V8aslRWM2uv8nf9uGyHU3FGRwhmVBYTy9tP5giiCnaHUTWKYUlTvXWDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=KLeHX49V; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-37cdac05af9so2096874f8f.0 for ; Fri, 04 Oct 2024 07:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1728053019; x=1728657819; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BKjMW5FAvExn1X1rKYf/xNSPWWy6xqM+i06DErztFe8=; b=KLeHX49VYxPGZnOBc51S5XTNH55kfQ4UlquGMx8FykucQq9p67ye6zYRG0b1BTFO4j g7sYFItwBLhadqf4AsN+Btuv1QfoTBYdl7nqH/GDCLD3w9zm0ndlDI6kNTP2WQChaInR Ti7HxRRQYCil1/f5UWGunMMJ0vHf3YTZl16xv9YJ1tQr1CSJFgvuBprkPwCvtCD7Ucet yeXGpaPFZNLScJ0Uhktd/yxFzfA8nzU/jSmNvs6GM0wM0QbAK+NmeVOArIFkMH21EUGu ia9ItckXXYbl4Yj5UFI4zJTy01wyBLZ7hxf4fR5+T260My6PSvAVKihfrmu+1PJX8yQZ Lolg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053019; x=1728657819; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BKjMW5FAvExn1X1rKYf/xNSPWWy6xqM+i06DErztFe8=; b=JfIwtfN2ZvYwWWFTuu6f+0QEduaBbWltD8VsILMEp07H4aUFrhcdbL4rWkU7JA0ur+ D6Ce5XalbwVly+gVLXhQcR48VF7q2wLzTCx5ooN7stXyzAUJFR7EjpoqGs1cnud1ERm4 GSO2rbN+6T0nMJKKpFAjbmSFL0V0GLRUQHWUBo9uE71wlvswnXjQyuRXLhWiqzJRo4lG /p5OUiWILHaX/pfLRSZBPmbDGYSTGs6ot4vgSqkU0LGJQm2TzYMc4HCYP17h4U4Aq9qP 3fN009EkCWqMGlPq/Dq42ZSBeE2uH+g0/nDOMOJcR69mTXqF5jXo0gkJb6ifMHcNqo7R yfbA== X-Gm-Message-State: AOJu0YyzPFNDe7YKOYnFkrcvBcHrqmHsUTaRp8IGTin1tLlv/G7pALjI PP916xTg+DIA52yscn4gKAEj9w3LWBbYxXNvSo6m/pT+kdG9+bttPAkU1QkMVr5QY7/6fjXE16U n X-Google-Smtp-Source: AGHT+IFm4b6vsKZfWNFphHza3MvykaI1856ZzfmQ9nuQoS0XnuGTmf8heUYonTjvbrf710Vr568WzA== X-Received: by 2002:adf:f58c:0:b0:37c:d507:aacd with SMTP id ffacd0b85a97d-37d0e724b97mr2745035f8f.14.1728053018674; Fri, 04 Oct 2024 07:43:38 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:80ea:d045:eb77:2d3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082d20bcsm3361370f8f.100.2024.10.04.07.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:43:37 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Oct 2024 16:43:25 +0200 Subject: [PATCH 4/5] gpiolib: simplify notifying user-space about line requests Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-gpio-notify-in-kernel-events-v1-4-8ac29e1df4fe@linaro.org> References: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> In-Reply-To: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2017; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=Rj60/yZ4gwl7HOw1XZWCqUwfUu0FrUco9KYhnC3+nbs=; b=owEBbAKT/ZANAwAKARGnLqAUcddyAcsmYgBm//8VC6Tw0qUqhumeXIZLVVKV/gzX6Jg6TeoDf Cv8Tb91hT2JAjIEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZv//FQAKCRARpy6gFHHX cokHD/Y1dTlGBuGjnh34+xOD4dNiEXGgmW/phkq5Z2CArTeC4p1OQWmdBvyMPgvU4oEQJFle+0h 35dvy4nvSwVJRILKHkR5O3mZGrJUx71JsoOIhrrW5Y5ojDRVEC11KBe5Z9FCdpeLaprJ4K/P9XY /NEoE0/rZISjQHStAPGr6Eugqs15fpAiftfMjIIJQQH40Y4WC6KB+CBxJp3vCjBUsfNCBw6BMcB YWv7DzDxqDZPYoxA+O9XLt95I4/YteHThJzvdh1iNhabb6fR1YN6DSHdA8f42EI2DA41p/FcHsV qv7n92zA3CKx0BXaP7/WNiVu2m4xJ7vLRyxzmItodwR4XGfNkMXqVfJIYcOztB4CHXHNyUQihMa lRX++daLYWtAkHdnu0eM8kEth6wK7czDqvCfE8AiuQNZVK2u6AbMX0t2ZLtOuPmD4xmmWNQdxh3 qT90mBvuwtzv05nclkF35Upb3TqjItNrnwHxsofRBowzxolC4a0TnpemdFeCyv4mqGKlWg8HB4a tSQlWdYkoWcRVoRLYOCv7xok+6OhCVOfXeVWwxGAnDtPPjkWqHTXc0j6FZYjKcqdWPzsvw/tAVD NyaLyh0zhPx8GCbo1lcncH7x6Y0N/ielIXePHIvCFhj8S0csekaCDHZjiLQWfb9/pRbbGEA0k5W RmEWk5AehbEgk X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Instead of emitting the line state change event on request in three different places, just do it once, closer to the source: in gpiod_request_commit(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 6 ------ drivers/gpio/gpiolib.c | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index b0050250ac3a..f614a981253d 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -372,8 +372,6 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) goto out_free_lh; } - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); - dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", offset); } @@ -1842,8 +1840,6 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) lr->lines[i].edflags = edflags; - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); - dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", offset); } @@ -2234,8 +2230,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) if (ret) goto out_free_le; - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); - irq = gpiod_to_irq(desc); if (irq <= 0) { ret = -ENODEV; diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 97346b746ef5..190ece4d6850 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2345,6 +2345,8 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) if (ret) goto out_clear_bit; + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); + return 0; out_clear_bit: @@ -4365,8 +4367,6 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer, return ERR_PTR(ret); } - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); - return desc; } From patchwork Fri Oct 4 14:43:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1992774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=K+wwARGH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-10861-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XKrvN5wmKz1xtH for ; Sat, 5 Oct 2024 00:45:52 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BFB62B242C1 for ; Fri, 4 Oct 2024 14:45:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61D4721D2BD; Fri, 4 Oct 2024 14:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="K+wwARGH" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43EEA21C16D for ; Fri, 4 Oct 2024 14:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053024; cv=none; b=C/gXTkrjKCRetZX33teeT3M+14WXj9Go19BNgyaBzitSI/Ro4aDgHEcYH0wFzqedO/I928q3ZPZdw6rS4cf5+J+W06sPsI8AmXJ4kFWusMGM9DZ0eLAK1a1YqfeJH5dQKmvjGL6VD4md8xfpBkK/2Gu8G/HNJhkSLmdiDKRRRT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728053024; c=relaxed/simple; bh=/Zd1cgX1HwVAzft6FhAsQIQ8nKeMY7GUJrxKl5LGOLA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iZhMwFqtqBQ581dBA4ZcROm5YVkv2jHx8i67GW+wdE2okGyHj/iRI72HBOnpT4Gby9L5xizplOMUZKlnVJR2fK6+5i3p3J/FLddd9wkKSveOyHrp5df20jARj6wmJeCYAcl9dF8vrjyClXpfGPareuYKl2S2FkmKtOkTwkGHUUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=K+wwARGH; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-37ccd81de57so1390211f8f.0 for ; Fri, 04 Oct 2024 07:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1728053020; x=1728657820; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Jfb6YI80rw3zHCFbKnEyH1U6ooQ/9EXSdd+jltWULAY=; b=K+wwARGHfaxcKVQ1iOI8WE2FvVEnnPcg1b8S8kSf9t3xMFwDh0Xr+kHYCcf89sttpt +E0bijh6CXVeYDhFFrJlCCYj0anuaEqoeOWxWt1Oesh1oFh7MxkBCVEA2Ipnj2PfTeuL iO2PCEQhypTyTk5KCIrD6Wi8UbkIgP4zM6bZQnzyV3Q/y0rXzfYt6Uh4t2gm7XbnPqiQ fZZttrJlE+EaheJGudf56dKkK3qP1GTbhbJkCopHZP6Uy5VEMoPiD7mA3x0lXswYjFfj P8LVlZLXwlHK45u/FU1s5vudlHMLv5Sk/yPgPD1iKal9UfAkT69chFXv0qtrJym5gkxU 4YQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053020; x=1728657820; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jfb6YI80rw3zHCFbKnEyH1U6ooQ/9EXSdd+jltWULAY=; b=tXSzrqBCaJAB10FxnO096uo7jWupZeHyj0/FsJqtgRrJN7ZD3LyTeqsvEP43co0iBp tC/2bC9NNDghU2ykpUmPzjq0fifLxHir0mEF1eovKbarn0Wb3M3tgsh9Fep0REoqAZM/ +JYBjYMxUKN1N+eOD3meLSd7v0xQrp4Kd1wmSIFIfTpKw5pcZyZbX3700+gTE9HSgafX JtmVvQCNvary04fesU+11FxcHKMT7pKaAlTD0UMZfzLr6ojXGQpwWG0cxrgxxWkZcgzw CeKuaxjANgjEOUD0vH9H1r25BofX8W/eRDjQj+ksDigssxy+qwL7ikbcrY8EnAchlCpN pr6w== X-Gm-Message-State: AOJu0YwirELT0cN8pP1WmL+40/PaSXdYbSa1RCJBNZcDKz9PqKaF4l7x wtbOh9rjC/FukVlWHr6zcULLyBVievDqiEbcDzf3gPM0QnZiNWOMut9OjLQlGKW/kIviXdu3a4o X X-Google-Smtp-Source: AGHT+IHl5Rwr13sP+gPr8mcUXq2K80wxzjjVKpp/yJWkdKYWjp/EW/nqphwrAkXEN5+Ks3owEwlDdg== X-Received: by 2002:a5d:4152:0:b0:374:b6e4:16a7 with SMTP id ffacd0b85a97d-37d049e12d3mr4362850f8f.8.1728053019938; Fri, 04 Oct 2024 07:43:39 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:80ea:d045:eb77:2d3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082d20bcsm3361370f8f.100.2024.10.04.07.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:43:39 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Oct 2024 16:43:26 +0200 Subject: [PATCH 5/5] gpiolib: notify user-space about in-kernel line state changes Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-gpio-notify-in-kernel-events-v1-5-8ac29e1df4fe@linaro.org> References: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> In-Reply-To: <20241004-gpio-notify-in-kernel-events-v1-0-8ac29e1df4fe@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=10719; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=wknoPtX1dNfD1bs2G/w2vi/UQ2Iy2lVZXz1DzFv12YE=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBm//8Vlfd4WUuwSf0BjR/U8tazYo87l9su6YW2p NW7KwuqMoWJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZv//FQAKCRARpy6gFHHX cutBEAC50WpKefyDXfPMvn6fvV1iP5lOHB9x2nNdV2B3GmZI2AeIOVlb8SORSs6hkP8c9UYuMI/ uxLf1GEztlkepIRDVBEqCOlStrKjyxRq8xZZcoIAujPjag6JRnLj6SzunBoMk4Py2sN/gJdUpOE UAW7bzupBlA+v++1gKA5/uOG+aPfqJYkXddwzunpsKplqDFYs8hL10xeqq5B7UO7mXqNn+BDnoU BgBiCIG6T4rAgAVJmv2CcJtQEmzKH0BKnyVJvYTvddA7jXieOIa8YVtPpSuRPvPOsKaull/jSIz +2YzdxoCEFSN3Ns/XX7MXUDCsX56Zcltupck3HPYyHfT6sW3lnCnUx8gO+GYznX7DEl92SbR8mc 3zn4PGe4iB9kTvk3i39J2D829mu2iC0fVo/9q7BDbpreGrY4Fn6p5CMGkehaKmVJjIvGZBeHZiW 90dpQS8bmYqc4Lu+WNsouEXHkJDh738GBkK79ZaVdMCfjzf4xIUkyDLwSLfD68xPM0y615kdTDy iCKlc7xsd2v+qarIzVsAvR75IjHfvUk0rG9Mq1tEAmnHPbEM23EuztMV0hVx/zNvQRm7nFDdv30 LK4mddKfJWvtYFcIVltn0xDrOd/p9sfkckl8bUiaZCk+nI+W0aj34f9ctmLyK8cNanTRZLUCym1 H4SO+QUru36IXOQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We currently only notify user-space about line config changes that are made from user-space. Any kernel config changes are not signalled. Let's improve the situation by emitting the events closer to the source. To that end let's call the relevant notifier chain from the functions setting direction, gpiod_set_config(), gpiod_set_consumer_name() and gpiod_toggle_active_low(). This covers all the options that we can inform the user-space about. There is a problem with gpiod_direction_output/input(), namely the fact that they can be called both from sleeping as well as atomic context. We cannot call the blocking notifier from atomic and we cannot switch to atomic notifier because the pinctrl functions we call higher up the stack take a mutex. Let's instead use a workqueue and schedule a task to emit the event from process context on the unbound system queue for minimal latencies. In tests, I typically get around 5 microseconds between scheduling the work and it being executed. That could of course differ during heavy system load but in general it should be enough to not miss direction change events which typically are not in hot paths. Let's also add non-notifying wrappers around the direction setters in order to not emit superfluous reconfigure events when requesting the lines. We can also now make gpiod_line_state_notify() static. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 12 ++---- drivers/gpio/gpiolib.c | 99 +++++++++++++++++++++++++++++++++++++++------ drivers/gpio/gpiolib.h | 9 ++++- 3 files changed, 97 insertions(+), 23 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index f614a981253d..bb00c9c29613 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -196,8 +196,6 @@ static long linehandle_set_config(struct linehandle_state *lh, if (ret) return ret; } - - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); } return 0; } @@ -363,11 +361,11 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) if (lflags & GPIOHANDLE_REQUEST_OUTPUT) { int val = !!handlereq.default_values[i]; - ret = gpiod_direction_output(desc, val); + ret = gpiod_direction_output_nonotify(desc, val); if (ret) goto out_free_lh; } else if (lflags & GPIOHANDLE_REQUEST_INPUT) { - ret = gpiod_direction_input(desc); + ret = gpiod_direction_input_nonotify(desc); if (ret) goto out_free_lh; } @@ -1566,8 +1564,6 @@ static long linereq_set_config(struct linereq *lr, void __user *ip) } WRITE_ONCE(line->edflags, edflags); - - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); } return 0; } @@ -1824,11 +1820,11 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) if (flags & GPIO_V2_LINE_FLAG_OUTPUT) { int val = gpio_v2_line_config_output_value(lc, i); - ret = gpiod_direction_output(desc, val); + ret = gpiod_direction_output_nonotify(desc, val); if (ret) goto out_free_linereq; } else if (flags & GPIO_V2_LINE_FLAG_INPUT) { - ret = gpiod_direction_input(desc); + ret = gpiod_direction_input_nonotify(desc); if (ret) goto out_free_linereq; diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 190ece4d6850..281502923482 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -870,6 +870,26 @@ static void gpiochip_set_data(struct gpio_chip *gc, void *data) gc->gpiodev->data = data; } +static void gpiod_line_state_notify(struct gpio_desc *desc, + unsigned long action) +{ + blocking_notifier_call_chain(&desc->gdev->line_state_notifier, + action, desc); +} + +static void gpiod_config_change_func(struct work_struct *work) +{ + struct gpio_desc *desc = container_of(work, struct gpio_desc, + line_state_work); + + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); +} + +static void gpiod_line_config_change_notify(struct gpio_desc *desc) +{ + queue_work(system_unbound_wq, &desc->line_state_work); +} + /** * gpiochip_get_data() - get per-subdriver data for the chip * @gc: GPIO chip @@ -1064,6 +1084,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, assign_bit(FLAG_IS_OUT, &desc->flags, !gc->direction_input); } + + INIT_WORK(&desc->line_state_work, gpiod_config_change_func); } ret = of_gpiochip_add(gc); @@ -2673,6 +2695,18 @@ int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) * 0 on success, or negative errno on failure. */ int gpiod_direction_input(struct gpio_desc *desc) +{ + int ret; + + ret = gpiod_direction_input_nonotify(desc); + if (ret == 0) + gpiod_line_config_change_notify(desc); + + return ret; +} +EXPORT_SYMBOL_GPL(gpiod_direction_input); + +int gpiod_direction_input_nonotify(struct gpio_desc *desc) { int ret = 0; @@ -2720,7 +2754,6 @@ int gpiod_direction_input(struct gpio_desc *desc) return ret; } -EXPORT_SYMBOL_GPL(gpiod_direction_input); static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) { @@ -2782,8 +2815,15 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) */ int gpiod_direction_output_raw(struct gpio_desc *desc, int value) { + int ret; + VALIDATE_DESC(desc); - return gpiod_direction_output_raw_commit(desc, value); + + ret = gpiod_direction_output_raw_commit(desc, value); + if (ret == 0) + gpiod_line_config_change_notify(desc); + + return ret; } EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); @@ -2801,6 +2841,18 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); * 0 on success, or negative errno on failure. */ int gpiod_direction_output(struct gpio_desc *desc, int value) +{ + int ret; + + ret = gpiod_direction_output_nonotify(desc, value); + if (ret == 0) + gpiod_line_config_change_notify(desc); + + return ret; +} +EXPORT_SYMBOL_GPL(gpiod_direction_output); + +int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value) { unsigned long flags; int ret; @@ -2863,7 +2915,6 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) set_bit(FLAG_IS_OUT, &desc->flags); return ret; } -EXPORT_SYMBOL_GPL(gpiod_direction_output); /** * gpiod_enable_hw_timestamp_ns - Enable hardware timestamp in nanoseconds. @@ -2942,13 +2993,34 @@ EXPORT_SYMBOL_GPL(gpiod_disable_hw_timestamp_ns); */ int gpiod_set_config(struct gpio_desc *desc, unsigned long config) { + int ret; + VALIDATE_DESC(desc); CLASS(gpio_chip_guard, guard)(desc); if (!guard.gc) return -ENODEV; - return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); + ret = gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); + if (ret == 0) { + /* These are the only options we notify the userspace about. */ + switch (pinconf_to_config_param(config)) { + case PIN_CONFIG_BIAS_DISABLE: + case PIN_CONFIG_BIAS_PULL_DOWN: + case PIN_CONFIG_BIAS_PULL_UP: + case PIN_CONFIG_DRIVE_OPEN_DRAIN: + case PIN_CONFIG_DRIVE_OPEN_SOURCE: + case PIN_CONFIG_DRIVE_PUSH_PULL: + case PIN_CONFIG_INPUT_DEBOUNCE: + gpiod_line_state_notify(desc, + GPIO_V2_LINE_CHANGED_CONFIG); + break; + default: + break; + } + } + + return ret; } EXPORT_SYMBOL_GPL(gpiod_set_config); @@ -3015,6 +3087,7 @@ void gpiod_toggle_active_low(struct gpio_desc *desc) { VALIDATE_DESC_VOID(desc); change_bit(FLAG_ACTIVE_LOW, &desc->flags); + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); } EXPORT_SYMBOL_GPL(gpiod_toggle_active_low); @@ -3659,9 +3732,15 @@ EXPORT_SYMBOL_GPL(gpiod_cansleep); */ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) { + int ret; + VALIDATE_DESC(desc); - return desc_set_label(desc, name); + ret = desc_set_label(desc, name); + if (ret == 0) + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + + return ret; } EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); @@ -4087,12 +4166,6 @@ int gpiod_set_array_value_cansleep(unsigned int array_size, } EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep); -void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action) -{ - blocking_notifier_call_chain(&desc->gdev->line_state_notifier, - action, desc); -} - /** * gpiod_add_lookup_table() - register GPIO device consumers * @table: table of consumers to register @@ -4537,10 +4610,10 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, /* Process flags */ if (dflags & GPIOD_FLAGS_BIT_DIR_OUT) - ret = gpiod_direction_output(desc, + ret = gpiod_direction_output_nonotify(desc, !!(dflags & GPIOD_FLAGS_BIT_DIR_VAL)); else - ret = gpiod_direction_input(desc); + ret = gpiod_direction_input_nonotify(desc); return ret; } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 067197d61d57..e07e053c7860 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -17,6 +17,7 @@ #include #include #include +#include #define GPIOCHIP_NAME "gpiochip" @@ -137,6 +138,9 @@ struct gpio_array { for_each_gpio_desc(gc, desc) \ if (!test_bit(flag, &desc->flags)) {} else +int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value); +int gpiod_direction_input_nonotify(struct gpio_desc *desc); + int gpiod_get_array_value_complex(bool raw, bool can_sleep, unsigned int array_size, struct gpio_desc **desc_array, @@ -150,8 +154,6 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); -void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action); - struct gpio_desc_label { struct rcu_head rh; char str[]; @@ -165,6 +167,8 @@ struct gpio_desc_label { * @label: Name of the consumer * @name: Line name * @hog: Pointer to the device node that hogs this line (if any) + * @line_state_work: Used to schedule line state updates to user-space from + * atomic context. * * These are obtained using gpiod_get() and are preferable to the old * integer-based handles. @@ -202,6 +206,7 @@ struct gpio_desc { #ifdef CONFIG_OF_DYNAMIC struct device_node *hog; #endif + struct work_struct line_state_work; }; #define gpiod_not_found(desc) (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)