From nobody Fri Dec 19 15:20:44 2025 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 6139522069E for ; Mon, 17 Feb 2025 14:28:44 +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=1739802526; cv=none; b=eqatYFcmeOFmx3BL7uofKN6HjdqD9Fo0lSKSGA0w74UMUj1OkntmpiRqLiDiUIDf18mmkRddreI8akh+PtyRgQmD7ruvOiJztpABbzrm/P8sftB8eNFa7ERYplwJSjOxenAvns5l9s5JHQnd7INllxvGCvuC6FTKYHjTNyBkafE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739802526; c=relaxed/simple; bh=QAOA908gNel3y1R7ETsRu2jzdhf2WxIWOfoFCHcP9qo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ErFCr4rlCRQL8ybGlVbNyPhbwOR/M8gcJ7zQ8F6I/BKqfv33iBIWpkFYW6b2JfJQn24by612zbl3a2FcvSlAbou0iAmPaAEpFrX6R/+hU2M/QBiEoCjE+beVO96AcI2bD6Mu4BcY3ZAXsORF5EzOZXfo3HmtryAeAfQd7x+uZaI= 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=vqpNbX0E; 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="vqpNbX0E" 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 4FCA63F87A for ; Mon, 17 Feb 2025 14:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1739802516; bh=N0Kj1d8MdTe6Cku6k8Y4hSRN1wAEicDaX3HkzkoJuyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vqpNbX0EXF3dfHvlUf6RHWbVQokG1i9p5dJJNybC4tcmSyJFGUzMe2CxQPM+cFZ9A n5Uv7KSt/EJ3i1FTGYtqoRYquE41OHrOX+YrWhwWFxg1QVMw+OcCGdNkSim+3SQ2I9 FloTz/JEsCxSy6tEWAumKSZKjLlk0Z3qsaK1Zf9usOfF4zqEoW3UxM6kitebWhYtZq RDClP1mUe0/0K4zd/e7/rhUmXWaahp+pu1TNTO86UM/tiMf9g1gYRQhItH4Vvy3HbU MtnbRxMR1yWDV3PvQTLRChFlGQtJ4fQtuRh0jP2/OAIch87yqnL1VcQ/fupOIPkjW0 V06Kt9j1Q7AVg== Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-22119b07d52so22046715ad.1 for ; Mon, 17 Feb 2025 06:28:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739802515; x=1740407315; 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=N0Kj1d8MdTe6Cku6k8Y4hSRN1wAEicDaX3HkzkoJuyo=; b=Hb4PYde9hWOzAwgkkF4VwrwbecONmRWOBX+fGeUHxiNhU5L1f+8wxR/W7lUZYMdmb8 25HQP2WL9dAEO9B5d1bOBnPzDXv/cz8dNfNhCDgDxzt2QgupStK3Fv306XJvUmHu5eEz EZLNOoLxI9KoMgg218cMY664kVIRK06x6Du2dHhTm/u7fkxLEe81XKQK9mmJJhks90cd hZHQKhLBAKvW7uWdCc2AL7o5LUf7EdNJlUMbSIoFDO8HZN2gxxAIKig3KVD8PR4y5h+y z8HHOjdypgw4Us41tLEK4AoNy6VG2wLwFajS4Ez3jliMkxKGXADOGO1ZlFC6xru595Vw iHaQ== X-Forwarded-Encrypted: i=1; AJvYcCV2qB9P/VZWN9KyZx3c8PBaRx6azIG5Ur3oyimG7wM0OCTcgF0TJprVTpzUS6aVVF4CXHRCLNtUZQupNBE=@vger.kernel.org X-Gm-Message-State: AOJu0YyW3KB1OCW+B05+RUZoaTG9w41JqyxpMReowdEkzEb3uMz3eTcA Pf5NV3K6DJ6AXNOEe3Zl1oJoLcCx0a+3JUezRfpwvsAuAghmcGDuDbVbaO/98QvHH2iMrxNnMPx y9o8yK/JZOA+DZvjeOJNHUzN5JmDukkV6Opq4qtRsHMGPx4TbE/JdVsYnw0ymxmcCNMxe3jY3FD 0hZw== X-Gm-Gg: ASbGncuWOepjypSoovrFAUXlDVrvsqrDOqRwMhGrkqs9SFhdZ/E1MVSRy/NQ/H+w7Vd WddvMqZ6ML0Y2sTuEulc/ebZoSDhR7MmRFQ9vwhYLp6St18/CQ5qF4BgbSU1/90IUILtoUUowUW 73RdxrqzsRy//flnd/bNZ3FSNRC/HL2GMQ9zEbS/s1ZSIKBCwszaRMtsAl+gBPqo841IcgFwgV6 zmui1sWxXcqgzvhTd5QsIIeNkLBM4RkNl+BrSGfv8mYSZUzC7kn3NV5nYzXBwhFQB6kpEGfsxr2 yWP7fHA/FFQRhOyCO71KG9k= X-Received: by 2002:a17:902:db0c:b0:215:9bc2:42ec with SMTP id d9443c01a7336-221040cf223mr132238855ad.47.1739802514816; Mon, 17 Feb 2025 06:28:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5xd3Qyn15GPhq2F9COyGUha2ugih5t2tEudHBsZMRrSSf0N606HwzeDlINRsrUnYXl5l86A== X-Received: by 2002:a17:902:db0c:b0:215:9bc2:42ec with SMTP id d9443c01a7336-221040cf223mr132238595ad.47.1739802514474; Mon, 17 Feb 2025 06:28:34 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:a6da:1fd8:6ba3:4cf3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d55916c7sm72237735ad.243.2025.02.17.06.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 06:28:34 -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 2/3] gpio: sim: convert to use gpio-pseudo utilities Date: Mon, 17 Feb 2025 23:27:57 +0900 Message-ID: <20250217142758.540601-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250217142758.540601-1-koichiro.den@canonical.com> References: <20250217142758.540601-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update gpio-sim to use the new gpio-pseudo helper functions for synchronized platform device creation, reducing code duplication. No functional change. Signed-off-by: Koichiro Den --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-sim.c | 84 ++++++----------------------------------- 2 files changed, 13 insertions(+), 72 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 1e2c95e03a95..c482e3494bac 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1913,6 +1913,7 @@ config GPIO_SIM tristate "GPIO Simulator Module" select IRQ_SIM select CONFIGFS_FS + select GPIO_PSEUDO 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..45dbf16bee12 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 =20 +#include "gpio-pseudo.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 =3D { }; =20 struct gpio_sim_device { + struct pseudo_gpio_common common; struct config_group group; =20 - /* - * 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; =20 /* @@ -562,46 +558,11 @@ struct gpio_sim_device { */ struct mutex lock; =20 - /* - * 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; =20 struct list_head bank_list; }; =20 -/* 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 =3D container_of(nb, - struct gpio_sim_device, - bus_notifier); - struct device *dev =3D data; - char devname[32]; - - snprintf(devname, sizeof(devname), "gpio-sim.%u", simdev->id); - - if (!device_match_name(dev, devname)) - return NOTIFY_DONE; - - if (action =3D=3D BUS_NOTIFY_BOUND_DRIVER) - simdev->driver_bound =3D true; - else if (action =3D=3D BUS_NOTIFY_DRIVER_NOT_BOUND) - simdev->driver_bound =3D 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 =3D to_config_group(item); @@ -708,7 +669,7 @@ static bool gpio_sim_device_is_live(struct gpio_sim_dev= ice *dev) { lockdep_assert_held(&dev->lock); =20 - return !!dev->pdev; + return !!dev->common.pdev; } =20 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(str= uct config_item *item, =20 guard(mutex)(&dev->lock); =20 - pdev =3D dev->pdev; + pdev =3D dev->common.pdev; if (pdev) return sprintf(page, "%s\n", dev_name(&pdev->dev)); =20 @@ -939,7 +900,6 @@ static int gpio_sim_device_activate(struct gpio_sim_dev= ice *dev) { struct platform_device_info pdevinfo; struct fwnode_handle *swnode; - struct platform_device *pdev; struct gpio_sim_bank *bank; int ret; =20 @@ -981,31 +941,13 @@ static int gpio_sim_device_activate(struct gpio_sim_d= evice *dev) pdevinfo.fwnode =3D swnode; pdevinfo.id =3D dev->id; =20 - reinit_completion(&dev->probe_completion); - dev->driver_bound =3D false; - bus_register_notifier(&platform_bus_type, &dev->bus_notifier); - - pdev =3D 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 =3D pseudo_gpio_register(&dev->common, &pdevinfo); + if (ret) { gpio_sim_remove_hogs(dev); gpio_sim_remove_swnode_recursive(swnode); - return -ENXIO; + return ret; } =20 - dev->pdev =3D pdev; - return 0; } =20 @@ -1015,11 +957,10 @@ static void gpio_sim_device_deactivate(struct gpio_s= im_device *dev) =20 lockdep_assert_held(&dev->lock); =20 - swnode =3D dev_fwnode(&dev->pdev->dev); - platform_device_unregister(dev->pdev); + swnode =3D dev_fwnode(&dev->common.pdev->dev); + pseudo_gpio_unregister(&dev->common); gpio_sim_remove_hogs(dev); gpio_sim_remove_swnode_recursive(swnode); - dev->pdev =3D NULL; } =20 static void @@ -1117,7 +1058,7 @@ static ssize_t gpio_sim_bank_config_chip_name_show(st= ruct config_item *item, guard(mutex)(&dev->lock); =20 if (gpio_sim_device_is_live(dev)) - return device_for_each_child(&dev->pdev->dev, &ctx, + return device_for_each_child(&dev->common.pdev->dev, &ctx, gpio_sim_emit_chip_name); =20 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); =20 - dev->bus_notifier.notifier_call =3D gpio_sim_bus_notifier_call; - init_completion(&dev->probe_completion); + pseudo_gpio_init(&dev->common); =20 return &no_free_ptr(dev)->group; } --=20 2.45.2