From patchwork Tue Feb 18 16:03:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 866274 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05C5C26E645 for ; Tue, 18 Feb 2025 16:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894662; cv=none; b=sCZgqqcZ6HiH467oXFMvYMdFJGJj4uNQputD8QkZBrzgMV/oNMlMRYoWBBRdBbZ74pbi1l57JxXivB5EhVuH6MGeecRhKEgSlBb2AgJIqMQYrzJSwLtzt01aex6eTMVIa7Z/6D258qZdX0UX2Bcu5tjPFJ7SpTO1m+/dTLrubAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894662; c=relaxed/simple; bh=hC2PNDnSvlx8tVpCvUE09c63PWr8yW9nO5xzmsySDoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BuxAgWMCNxb2HDxSRXGKt3dREjgSgqEOFFtspwlWLKu9iPNI6czc6k3UCVFKMQaZE5bFt2cKj3ViQ7IKsnEaP/johWnwaRZyafsNRmxHAKdAEXBeq4OCfdnbHUpl4GsT751oCTUlKFsTINLRkv2LEYRxK1wUC6Gy56/1n8lUD4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=jfKJ4vHr; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="jfKJ4vHr" Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 002823FE71 for ; Tue, 18 Feb 2025 16:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739894651; bh=AHMqJnxK4/Dnt8c9QVgTRTY4Zs2e90yXoYYPy4GoEkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jfKJ4vHrNLwIu9IxT2I2f8KDtFye1Nztd+pxYWxPCEzuVB/GpIW9cqIq1eq9t7mY7 cpCyhn7dSlgY/8hVVUQ29CrigHN3deh1XJpJK7gF47aoLM7ppMf1Us+QikRx1WZ49V zk5Hu+42raJ0fPEG7Rqh3tBhyo7OceBHVtOu+GpvpgY6wupkhup+WiVhBp0TylibM1 TftQkiaJyDdjTC9OQIBDFftYCh4IBYm3xKBiHTb5JEtf4HjeAi4X7YdA4Rg8LTF30o 7YZBjjrDVwE2QsQR9JEZIJIOrEDasCrhYg8iSjs+Z7iaqcgXf+vrVyag6LKUr/bn+n 6BUV/5Sk9O2WA== Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-22103ae73f9so69977855ad.2 for ; Tue, 18 Feb 2025 08:04:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739894648; x=1740499448; 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=AHMqJnxK4/Dnt8c9QVgTRTY4Zs2e90yXoYYPy4GoEkA=; b=HXP2WwudL/UEtTwxZ2q8ozikdnDSL+Sx0HTybnnoD+16To496ZrfaYwf4138EL6bGY F7v4W0ygVeVlhcToSJyY48QjUdaSUVnDWtvU5efvzMY/Dlf/LXlnq67Un+1BTo13loiW +GkAPGu4jL4AyL0T2nQpbcwQViCXl5mGydSY/+A/Pb3/Ym+NLZdIai/CAKj1KLAIv934 dPkxpHuQd9xEeqRGUgGLvG8SGoxz8p5SAQDVX5A/Oqcc9tZq+51MdRfwW0NAmJsOg0xU WfDn2joxInL+ZOVj8RAWmNmQgTajy6pUeE+bHqymYJ200g2luTmwSMBQVhW7nN++whqH jP8g== X-Gm-Message-State: AOJu0YwnqXQvSj7o2mY4toWS7QBlIcMcfnnD0Vgbc/CZkRO9Y425nKc3 GUOhMENj0iOpoIkhto6jGnKq9uveAOBPaDht4QRdfcXpX+/0pn5rOK3jR97rp6L6aCrrUda/iW1 7Bm5mxoW0ibRpWyBGToZkBa3QPThslP/CV1hBzqUw12pKBKpnywnWaqdPShveOLRybmRDtK7VpZ klEdE9NIo= X-Gm-Gg: ASbGncsW5SPaIj4svLuBwKyc2cJ4NOHU+IIbQacXjvf0IhZXZjSL5GGCGGUWkb06y4O ofaXN+74ULDY5blzPzseZS49jMY7h3LTFfm2bLPdSm9mRcHwFq1jTc0IR4Oa0BTRUsmCfz/UsfM xfiBMSRZv5IbWeH0gD884+XfLbojmKlMy/4NVxaKnLWRoZ8b/XZrCp+u9JHAyUERYl3IDZBxgZn vX+MgA1UqizqVVQTEgwOqiXlbH8XvOQAG/NR0ODEdpN6Af5zlXPrf6IjZ6tvzp1tEbssG6nxa6d e+eRdqBxZH9WmTVAOHH8vKY= X-Received: by 2002:a05:6a21:3995:b0:1ee:c390:58ad with SMTP id adf61e73a8af0-1eec3905cf2mr9166247637.34.1739894647613; Tue, 18 Feb 2025 08:04:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWmjYTvj6cKvC3gQEh96rnDqB1rMAwKafJdc7LFPp9QKU7MUBHctRmJpmMjmoPftsnIJh8sg== X-Received: by 2002:a05:6a21:3995:b0:1ee:c390:58ad with SMTP id adf61e73a8af0-1eec3905cf2mr9166188637.34.1739894647261; Tue, 18 Feb 2025 08:04:07 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:ad3a:e902:d78b:b8fa]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ae01c768020sm3662177a12.73.2025.02.18.08.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 08:04:06 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: brgl@bgdev.pl, geert+renesas@glider.be, linus.walleij@linaro.org, maciej.borzecki@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] gpio: introduce utilities for synchronous fake device creation Date: Wed, 19 Feb 2025 01:03:31 +0900 Message-ID: <20250218160333.605829-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250218160333.605829-1-koichiro.den@canonical.com> References: <20250218160333.605829-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both gpio-sim and gpio-virtuser share a mechanism to instantiate a platform device, wait for probe completion, and retrieve the probe success or error status synchronously. With gpio-aggregator planned to adopt this approach for its configfs interface, it's time to factor out the common code. Add dev-sync-probe.[ch] to house helper functions used by all such implementations. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 7 +++ drivers/gpio/Makefile | 3 ++ drivers/gpio/dev-sync-probe.c | 96 +++++++++++++++++++++++++++++++++++ drivers/gpio/dev-sync-probe.h | 25 +++++++++ 4 files changed, 131 insertions(+) create mode 100644 drivers/gpio/dev-sync-probe.c create mode 100644 drivers/gpio/dev-sync-probe.h diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 56c1f30ac195..2e4c5f0a94f7 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1863,6 +1863,13 @@ config GPIO_MPSSE endmenu +# This symbol is selected by drivers that need synchronous fake device creation +config DEV_SYNC_PROBE + tristate "Utilities for synchronous fake device creation" + help + Common helper functions for drivers that need synchronous fake + device creation. + menu "Virtual GPIO drivers" config GPIO_AGGREGATOR diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index af3ba4d81b58..af130882ffee 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -19,6 +19,9 @@ obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o # directly supported by gpio-generic gpio-generic-$(CONFIG_GPIO_GENERIC) += gpio-mmio.o +# Utilities for drivers that need synchronous fake device creation +obj-$(CONFIG_DEV_SYNC_PROBE) += dev-sync-probe.o + obj-$(CONFIG_GPIO_104_DIO_48E) += gpio-104-dio-48e.o obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o diff --git a/drivers/gpio/dev-sync-probe.c b/drivers/gpio/dev-sync-probe.c new file mode 100644 index 000000000000..82c8d7ae9fa7 --- /dev/null +++ b/drivers/gpio/dev-sync-probe.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Common code for drivers creating fake platform devices. + * + * Provides synchronous device creation: waits for probe completion and + * returns the probe success or error status to the device creator. + * + * Copyright (C) 2025 Bartosz Golaszewski + */ + +#include +#include + +#include "dev-sync-probe.h" + +static int dev_sync_probe_notifier_call(struct notifier_block *nb, + unsigned long action, + void *data) +{ + struct dev_sync_probe_data *pdata; + struct device *dev = data; + + pdata = container_of(nb, struct dev_sync_probe_data, bus_notifier); + if (!device_match_name(dev, pdata->name)) + return NOTIFY_DONE; + + switch (action) { + case BUS_NOTIFY_BOUND_DRIVER: + pdata->driver_bound = true; + break; + case BUS_NOTIFY_DRIVER_NOT_BOUND: + pdata->driver_bound = false; + break; + default: + return NOTIFY_DONE; + } + + complete(&pdata->probe_completion); + return NOTIFY_OK; +} + +void dev_sync_probe_init(struct dev_sync_probe_data *data) +{ + memset(data, 0, sizeof(*data)); + init_completion(&data->probe_completion); + data->bus_notifier.notifier_call = dev_sync_probe_notifier_call; +} +EXPORT_SYMBOL_GPL(dev_sync_probe_init); + +int dev_sync_probe_register(struct dev_sync_probe_data *data, + struct platform_device_info *pdevinfo) +{ + struct platform_device *pdev; + char *name; + + name = kasprintf(GFP_KERNEL, "%s.%u", pdevinfo->name, pdevinfo->id); + if (!name) + return -ENOMEM; + + data->driver_bound = false; + data->name = name; + reinit_completion(&data->probe_completion); + bus_register_notifier(&platform_bus_type, &data->bus_notifier); + + pdev = platform_device_register_full(pdevinfo); + if (IS_ERR(pdev)) { + bus_unregister_notifier(&platform_bus_type, &data->bus_notifier); + kfree(data->name); + return PTR_ERR(pdev); + } + + wait_for_completion(&data->probe_completion); + bus_unregister_notifier(&platform_bus_type, &data->bus_notifier); + + if (!data->driver_bound) { + platform_device_unregister(pdev); + kfree(data->name); + return -ENXIO; + } + + data->pdev = pdev; + return 0; +} +EXPORT_SYMBOL_GPL(dev_sync_probe_register); + +void dev_sync_probe_unregister(struct dev_sync_probe_data *data) +{ + platform_device_unregister(data->pdev); + kfree(data->name); + data->pdev = NULL; +} +EXPORT_SYMBOL_GPL(dev_sync_probe_unregister); + +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_DESCRIPTION("Utilities for synchronous fake device creation"); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpio/dev-sync-probe.h b/drivers/gpio/dev-sync-probe.h new file mode 100644 index 000000000000..4b3d52b70519 --- /dev/null +++ b/drivers/gpio/dev-sync-probe.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef DEV_SYNC_PROBE_H +#define DEV_SYNC_PROBE_H + +#include +#include +#include + +struct dev_sync_probe_data { + struct platform_device *pdev; + const char *name; + + /* Synchronize with probe */ + struct notifier_block bus_notifier; + struct completion probe_completion; + bool driver_bound; +}; + +void dev_sync_probe_init(struct dev_sync_probe_data *data); +int dev_sync_probe_register(struct dev_sync_probe_data *data, + struct platform_device_info *pdevinfo); +void dev_sync_probe_unregister(struct dev_sync_probe_data *data); + +#endif /* DEV_SYNC_PROBE_H */ From patchwork Tue Feb 18 16:03:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 866919 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80D8623536B for ; Tue, 18 Feb 2025 16:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894657; cv=none; b=iwow+Z0WZBVo4lhRLPO+Pi8FLk6oMvRAjNW+qh+wtAf2/JuqxJj5xP4ysOYDMwUrxrqU06Xj3C7I15t8+x/Eniat45TiVZcKGzFBylQUTIf35wFbW6Y0aIrd6L0kiYGBSAhnWXhygO+YgXq91u2hobN3+DeUZqu1L6axWHZJbfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894657; c=relaxed/simple; bh=sdZ6VzRRB5ZPauONLm1Y6ciUkGYRdBApYYUeFYnndrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YPKr+hZxMwmz8ucFD9zehelD42rBTHWZHOfEmElmS/WLx3EKJKAxc/yXXbR1G+w/+pCqhaD8z1dJFUBYUHqFoVD7R6djn6X56afiyhWswgQbV7EGJFWOamcFn6TkcJ5j0fGTLUrT0sto5oyzOc4UWEWaebkNoi8Mx15XL0nFkvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=mfsA4PEy; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="mfsA4PEy" Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id ABF523F296 for ; Tue, 18 Feb 2025 16:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739894652; bh=RjN5AreZarUYbQVP0Uc0k3mb1KoxJf6GB7t5AILSk3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mfsA4PEyvTH8tEAkzjOjKopK7o4sjBQtF9IP0tUTrqAhDLzNMRD0YPCmTmlX5yiZU jeMiP+J3rt/Qw/Bn86ZySJdf2ww990rerXOUMDmsnat5ezD1OsZq3lWmuZmkU82wih bLaod7STdkv2vwSN3f9yX4fzm683ZkqfKkDTcGQxrs9W0p0Mjmjg3rT9K+OG7ivCnk 7ITLHF4smm6d3++t+GegJfM6UPALKjVY7ft6urxxzeltZRG6LqXwPQ8HewtszLNQA/ Bd6W/6falHXIXqXaRl+uHObct9FHoBS2/RA2AY7Aui54M0zBGIKIhCVG6Rg9lCbGZs KirfT5opfhu4w== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-220c86b3ef3so123644295ad.1 for ; Tue, 18 Feb 2025 08:04:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739894651; x=1740499451; 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=RjN5AreZarUYbQVP0Uc0k3mb1KoxJf6GB7t5AILSk3M=; b=uN2Na5az4HsYEjNQF8uZFyQ4bmZbxRCfadRUlw0Wf+qH8u8D382WtH7r/7Le7o26i8 d0opjvlyFky/E5YmmOXyLO/PTKRmO4S9ucdNvhaLEj1dUzyGW8adpcbMbTQcOgBCLKBJ WuBT/4y38w9SFD546zaNjJDksyM1RfaokRBhuHNsJl2xbxz0eIEu0rkTvO4+iaxcY7EN I2cM47IefAqr73uw6TbWmdweNqkciuJ5w6x6jmtPIcG3UnpXwkivHOiG9w8qWSBcTdof CkYO6wu72nYL6NdKq3hsgzuOY9H8lBTddoxAE00tM/j0+galFmJcIxlpYibQZJcAJ1+d d9WQ== X-Gm-Message-State: AOJu0YzlYhTiqlajxGmFwBnySco1IU2MWZF37R7HnCFk/i9+bDcKYtct I2T6k71P4sFAh7UO5zk/Py+QMW391DZi5bRp9Ob1IHCI1E6jG6ILLCRPevP1v4SNXWhmaZ+JSU2 h8r6m/rHpyq/p0MY/DonIIqcWp8G3HQYcNe3jlV9ICRtHBxtl2XDgkkfBSG46TFSvqB05J9Tc42 DS125palo= X-Gm-Gg: ASbGncu1K8AFi8hBbg44U+8lMHHT7HZlveM28fIWEP3avNM7WDsr28pHlCHNeSlna2i 86TC/sAzgCXDKhvl+iKUqs1OcSpwE+btKSXFE7ohIWj4JBhLEb5wWhs36xPNb1cYGdAoLPDfpjR 1e1X3b0cmtXymkX7/D2x0RGvSzaLb5OoMs2jjE8MPsyJamTzgxHhJIJ2dsLRuaK2BW92s5F409i ER7RFpuGEKMZ2D5/kL1uUwCMOEzepQTYfJbTAzikhYB/vcbs9KBXJKy+LgEbM/C4A4VWb++UkwV 2rb2ltp9J+LbeWzbz1NOFu8= X-Received: by 2002:a05:6a21:6daa:b0:1e0:cc01:43da with SMTP id adf61e73a8af0-1eed3795347mr546837637.0.1739894650614; Tue, 18 Feb 2025 08:04:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlr8j/FIMrYjFZKCpEiD3ian13qv9GhgmhOTyegL8NA0OLFd302bU08nHMhlRVPDaC/ZBWew== X-Received: by 2002:a05:6a21:6daa:b0:1e0:cc01:43da with SMTP id adf61e73a8af0-1eed3795347mr546798637.0.1739894650131; Tue, 18 Feb 2025 08:04:10 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:ad3a:e902:d78b:b8fa]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ae01c768020sm3662177a12.73.2025.02.18.08.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 08:04:09 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: brgl@bgdev.pl, geert+renesas@glider.be, linus.walleij@linaro.org, maciej.borzecki@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] gpio: sim: convert to use dev-sync-probe utilities Date: Wed, 19 Feb 2025 01:03:32 +0900 Message-ID: <20250218160333.605829-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250218160333.605829-1-koichiro.den@canonical.com> References: <20250218160333.605829-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update gpio-sim to use the new dev-sync-probe helper functions for synchronized platform device creation, reducing code duplication. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 2 + drivers/gpio/gpio-sim.c | 84 ++++++----------------------------------- 2 files changed, 14 insertions(+), 72 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 2e4c5f0a94f7..ba06f052b9ea 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1866,6 +1866,7 @@ endmenu # This symbol is selected by drivers that need synchronous fake device creation config DEV_SYNC_PROBE tristate "Utilities for synchronous fake device creation" + depends on GPIO_SIM help Common helper functions for drivers that need synchronous fake device creation. @@ -1916,6 +1917,7 @@ config GPIO_SIM tristate "GPIO Simulator Module" select IRQ_SIM select CONFIGFS_FS + select DEV_SYNC_PROBE help This enables the GPIO simulator - a configfs-based GPIO testing driver. diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index a086087ada17..d1cdea450937 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,8 @@ #include #include +#include "dev-sync-probe.h" + #define GPIO_SIM_NGPIO_MAX 1024 #define GPIO_SIM_PROP_MAX 4 /* Max 3 properties + sentinel. */ #define GPIO_SIM_NUM_ATTRS 3 /* value, pull and sentinel */ @@ -541,14 +542,9 @@ static struct platform_driver gpio_sim_driver = { }; struct gpio_sim_device { + struct dev_sync_probe_data data; struct config_group group; - /* - * If pdev is NULL, the device is 'pending' (waiting for configuration). - * Once the pointer is assigned, the device has been created and the - * item is 'live'. - */ - struct platform_device *pdev; int id; /* @@ -562,46 +558,11 @@ struct gpio_sim_device { */ struct mutex lock; - /* - * This is used to synchronously wait for the driver's probe to complete - * and notify the user-space about any errors. - */ - struct notifier_block bus_notifier; - struct completion probe_completion; - bool driver_bound; - struct gpiod_hog *hogs; struct list_head bank_list; }; -/* This is called with dev->lock already taken. */ -static int gpio_sim_bus_notifier_call(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct gpio_sim_device *simdev = container_of(nb, - struct gpio_sim_device, - bus_notifier); - struct device *dev = data; - char devname[32]; - - snprintf(devname, sizeof(devname), "gpio-sim.%u", simdev->id); - - if (!device_match_name(dev, devname)) - return NOTIFY_DONE; - - if (action == BUS_NOTIFY_BOUND_DRIVER) - simdev->driver_bound = true; - else if (action == BUS_NOTIFY_DRIVER_NOT_BOUND) - simdev->driver_bound = false; - else - return NOTIFY_DONE; - - complete(&simdev->probe_completion); - - return NOTIFY_OK; -} - static struct gpio_sim_device *to_gpio_sim_device(struct config_item *item) { struct config_group *group = to_config_group(item); @@ -708,7 +669,7 @@ static bool gpio_sim_device_is_live(struct gpio_sim_device *dev) { lockdep_assert_held(&dev->lock); - return !!dev->pdev; + return !!dev->data.pdev; } static char *gpio_sim_strdup_trimmed(const char *str, size_t count) @@ -730,7 +691,7 @@ static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item, guard(mutex)(&dev->lock); - pdev = dev->pdev; + pdev = dev->data.pdev; if (pdev) return sprintf(page, "%s\n", dev_name(&pdev->dev)); @@ -939,7 +900,6 @@ static int gpio_sim_device_activate(struct gpio_sim_device *dev) { struct platform_device_info pdevinfo; struct fwnode_handle *swnode; - struct platform_device *pdev; struct gpio_sim_bank *bank; int ret; @@ -981,31 +941,13 @@ static int gpio_sim_device_activate(struct gpio_sim_device *dev) pdevinfo.fwnode = swnode; pdevinfo.id = dev->id; - reinit_completion(&dev->probe_completion); - dev->driver_bound = false; - bus_register_notifier(&platform_bus_type, &dev->bus_notifier); - - pdev = platform_device_register_full(&pdevinfo); - if (IS_ERR(pdev)) { - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - gpio_sim_remove_hogs(dev); - gpio_sim_remove_swnode_recursive(swnode); - return PTR_ERR(pdev); - } - - wait_for_completion(&dev->probe_completion); - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - - if (!dev->driver_bound) { - /* Probe failed, check kernel log. */ - platform_device_unregister(pdev); + ret = dev_sync_probe_register(&dev->data, &pdevinfo); + if (ret) { gpio_sim_remove_hogs(dev); gpio_sim_remove_swnode_recursive(swnode); - return -ENXIO; + return ret; } - dev->pdev = pdev; - return 0; } @@ -1015,11 +957,10 @@ static void gpio_sim_device_deactivate(struct gpio_sim_device *dev) lockdep_assert_held(&dev->lock); - swnode = dev_fwnode(&dev->pdev->dev); - platform_device_unregister(dev->pdev); + swnode = dev_fwnode(&dev->data.pdev->dev); + dev_sync_probe_unregister(&dev->data); gpio_sim_remove_hogs(dev); gpio_sim_remove_swnode_recursive(swnode); - dev->pdev = NULL; } static void @@ -1117,7 +1058,7 @@ static ssize_t gpio_sim_bank_config_chip_name_show(struct config_item *item, guard(mutex)(&dev->lock); if (gpio_sim_device_is_live(dev)) - return device_for_each_child(&dev->pdev->dev, &ctx, + return device_for_each_child(&dev->data.pdev->dev, &ctx, gpio_sim_emit_chip_name); return sprintf(page, "none\n"); @@ -1558,8 +1499,7 @@ gpio_sim_config_make_device_group(struct config_group *group, const char *name) mutex_init(&dev->lock); INIT_LIST_HEAD(&dev->bank_list); - dev->bus_notifier.notifier_call = gpio_sim_bus_notifier_call; - init_completion(&dev->probe_completion); + dev_sync_probe_init(&dev->data); return &no_free_ptr(dev)->group; } From patchwork Tue Feb 18 16:03:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 866918 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A68F26B95A for ; Tue, 18 Feb 2025 16:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894658; cv=none; b=eRipSkE6jdEgOuBYdYx8q5GuhMl/ZEXCvTbjuSGjE3wZKk9u8pMdI1VFLiXL26fX0SRFBpRfUuKiwPyq69g7vNhNxd9H3FPDcUKOheCQ6isDG608sWivoaCglmU19Ywi/v8MaV17NRFT6+k/VMrurjyD3qJth1XCEe8+AzNmSkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739894658; c=relaxed/simple; bh=4eJWuiu8iMylG68gF/vH9qt791ZdSmlwPSbKjxx5PNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=avItXwS1JLi0X1hrwKnbWAmYO8djF10D3wfN23MQoLNOzWHFtFERrKooYXmPcfDaqawikfoKV+wNxoD8u0wx6KQt5RWDNmOMuhGZTGvpTzr6iG5SufKS2aUX6dFnq0pRlXQrV0BXr4tWv1IHzD9762Lqh4jQyffUYO4ovB+LBY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=HQUCZWR/; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="HQUCZWR/" Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 75A363F868 for ; Tue, 18 Feb 2025 16:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739894655; bh=hXMs8HBNi/hnowMwXyt+GhCst9ecZCs2bYJfUqZe+sI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQUCZWR/Fl7J2/I18HW+5W3IXf/RVPNX+tYHfrOqv+YUHNF7WYjPStQ5lukOrNEq+ gNubeYim3xXcf771oQl22IcsaW3APp1RFfOMtuIV5r2C4tgUSezND/FPc3ThwqPgmT y5dKTZIOMnk1sZR8DcK9sBIN9aobdFJ9yeSjRsp1+enlAdrA6QJN00cPuuEPgG95IK XwhXYcqPNPhDqpJG/lxlwU7Z+kr3Shw4F6vcLyOJPozao/DqAptEl2qiLqeJS4XVEP U9QXIjR4CKfCN07Pgq+S7d8uBhiKn2DxIpukFVmJ0bk1BHyQvA4mjraHbOP/yYJ2XX oKEnvLH/bAy7g== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-220ec5c16e9so90767955ad.1 for ; Tue, 18 Feb 2025 08:04:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739894653; x=1740499453; 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=hXMs8HBNi/hnowMwXyt+GhCst9ecZCs2bYJfUqZe+sI=; b=OOPuTg1PTfpc5CQ02MAHnRpcKupr3fYFUxu3xQ3Xa0JBvVVSXNJnI2U1iV+uR5OdWo wK5HmvqPc3sOEB+o8IcjxVqTpbOxkXQe5CgESk/gjqiQxyCddY06SS/ALg4pBGcNNOhp KfKgWvcTMeC6ogY4OetE9uWhRPJ9WrMFAVVyO8D8Tcx9loIzqMq8vLBIwVuqhSknB2rr 1E0mCuyLXNcpDF6/Dm9Cjc1BTHjAgBdarF3UfPXC8/gu3yoa5v873vsW4LzEfRrqxUA1 C8wVdWXmFCkOWmVXjVDF14sKclmPUlEEMAr43eLfqTG9n9UD8B6/O/S/5K5T6OLGGnIl KDLA== X-Gm-Message-State: AOJu0YwyN9yGEy6i2O82887D5pOMoQyxnNDtDKvD+d5NJguecB/X71VS UeuHOfc4TLJ+mieKw88KgM97l2HBXY2xrY799k1K42C3o/jVAbkezpibVqaMYrXXB+HSBDOGLXA 7cxoujTd0w7QXNMaRcMbencj8lX///IFLCgYkgEB4OJWo6NoVsI5xKx26oDBc5GDxvMfReya7/X DzVIIxK/s= X-Gm-Gg: ASbGncubdoz7Irssm1ry+a/+WJgIfDsQiOusTAwslqitCnpjHfzKe8f8cx1cerHeciQ VbTa8UbLhWNiHqAn4fcTjPax50L4bLZoMjSkacRwStI6qcONbTVdHkjHeMTGi9+FwZLzHcGG9eu UIBlHuEf/cqW2D4CkPjWi4sdVFPM1HVqLs+Sw8F9bUaFq2V2/Nz5d9mbm1mLsZXUXoT3cmRAkP6 h1lV/ZpxGZjQ6wkaXErHRGPosIcZizsB7TCJStrqdqKj2FD+4OTZiSNF8+VBho0yfsZQZT7K+Uy AdaqpJ/rX50kY9f38NWNYRs= X-Received: by 2002:a17:902:f612:b0:21f:9c7:2d2e with SMTP id d9443c01a7336-221040bdb68mr245123175ad.40.1739894653514; Tue, 18 Feb 2025 08:04:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2TbTWW3u0CYVTQ9OQPM/nQJvb6h3vq+eHaom1mbDtD51GpaWKMh3d5FIgowV2tRA1OUtNOw== X-Received: by 2002:a17:902:f612:b0:21f:9c7:2d2e with SMTP id d9443c01a7336-221040bdb68mr245122685ad.40.1739894652947; Tue, 18 Feb 2025 08:04:12 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:ad3a:e902:d78b:b8fa]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ae01c768020sm3662177a12.73.2025.02.18.08.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 08:04:12 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: brgl@bgdev.pl, geert+renesas@glider.be, linus.walleij@linaro.org, maciej.borzecki@canonical.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] gpio: virtuser: convert to use dev-sync-probe utilities Date: Wed, 19 Feb 2025 01:03:33 +0900 Message-ID: <20250218160333.605829-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250218160333.605829-1-koichiro.den@canonical.com> References: <20250218160333.605829-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update gpio-virtuser to use the new dev-sync-probe helper functions for synchronized platform device creation, reducing code duplication. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 3 +- drivers/gpio/gpio-virtuser.c | 73 +++++------------------------------- 2 files changed, 12 insertions(+), 64 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index ba06f052b9ea..b3049993a449 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1866,7 +1866,7 @@ endmenu # This symbol is selected by drivers that need synchronous fake device creation config DEV_SYNC_PROBE tristate "Utilities for synchronous fake device creation" - depends on GPIO_SIM + depends on GPIO_SIM || GPIO_VIRTUSER help Common helper functions for drivers that need synchronous fake device creation. @@ -1946,6 +1946,7 @@ config GPIO_VIRTUSER select DEBUG_FS select CONFIGFS_FS select IRQ_WORK + select DEV_SYNC_PROBE help Say Y here to enable the configurable, configfs-based virtual GPIO consumer testing driver. diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index e89f299f2140..a48627352337 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,8 @@ #include #include +#include "dev-sync-probe.h" + #define GPIO_VIRTUSER_NAME_BUF_LEN 32 static DEFINE_IDA(gpio_virtuser_ida); @@ -973,49 +974,17 @@ static struct platform_driver gpio_virtuser_driver = { }; struct gpio_virtuser_device { + struct dev_sync_probe_data data; struct config_group group; - struct platform_device *pdev; int id; struct mutex lock; - struct notifier_block bus_notifier; - struct completion probe_completion; - bool driver_bound; - struct gpiod_lookup_table *lookup_table; struct list_head lookup_list; }; -static int gpio_virtuser_bus_notifier_call(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct gpio_virtuser_device *vdev; - struct device *dev = data; - char devname[32]; - - vdev = container_of(nb, struct gpio_virtuser_device, bus_notifier); - snprintf(devname, sizeof(devname), "gpio-virtuser.%d", vdev->id); - - if (!device_match_name(dev, devname)) - return NOTIFY_DONE; - - switch (action) { - case BUS_NOTIFY_BOUND_DRIVER: - vdev->driver_bound = true; - break; - case BUS_NOTIFY_DRIVER_NOT_BOUND: - vdev->driver_bound = false; - break; - default: - return NOTIFY_DONE; - } - - complete(&vdev->probe_completion); - return NOTIFY_OK; -} - static struct gpio_virtuser_device * to_gpio_virtuser_device(struct config_item *item) { @@ -1029,7 +998,7 @@ gpio_virtuser_device_is_live(struct gpio_virtuser_device *dev) { lockdep_assert_held(&dev->lock); - return !!dev->pdev; + return !!dev->data.pdev; } struct gpio_virtuser_lookup { @@ -1369,7 +1338,7 @@ gpio_virtuser_device_config_dev_name_show(struct config_item *item, guard(mutex)(&dev->lock); - pdev = dev->pdev; + pdev = dev->data.pdev; if (pdev) return sprintf(page, "%s\n", dev_name(&pdev->dev)); @@ -1478,7 +1447,6 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev) { struct platform_device_info pdevinfo; struct fwnode_handle *swnode; - struct platform_device *pdev; int ret; lockdep_assert_held(&dev->lock); @@ -1499,31 +1467,12 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev) if (ret) goto err_remove_swnode; - reinit_completion(&dev->probe_completion); - dev->driver_bound = false; - bus_register_notifier(&platform_bus_type, &dev->bus_notifier); - - pdev = platform_device_register_full(&pdevinfo); - if (IS_ERR(pdev)) { - ret = PTR_ERR(pdev); - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); + ret = dev_sync_probe_register(&dev->data, &pdevinfo); + if (ret) goto err_remove_lookup_table; - } - - wait_for_completion(&dev->probe_completion); - bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); - - if (!dev->driver_bound) { - ret = -ENXIO; - goto err_unregister_pdev; - } - - dev->pdev = pdev; return 0; -err_unregister_pdev: - platform_device_unregister(pdev); err_remove_lookup_table: gpio_virtuser_remove_lookup_table(dev); err_remove_swnode: @@ -1539,11 +1488,10 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser_device *dev) lockdep_assert_held(&dev->lock); - swnode = dev_fwnode(&dev->pdev->dev); - platform_device_unregister(dev->pdev); + swnode = dev_fwnode(&dev->data.pdev->dev); + dev_sync_probe_unregister(&dev->data); gpio_virtuser_remove_lookup_table(dev); fwnode_remove_software_node(swnode); - dev->pdev = NULL; } static void @@ -1772,8 +1720,7 @@ gpio_virtuser_config_make_device_group(struct config_group *group, &gpio_virtuser_device_config_group_type); mutex_init(&dev->lock); INIT_LIST_HEAD(&dev->lookup_list); - dev->bus_notifier.notifier_call = gpio_virtuser_bus_notifier_call; - init_completion(&dev->probe_completion); + dev_sync_probe_init(&dev->data); return &no_free_ptr(dev)->group; }