NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/61012: spi(4): add ca_rescan so children attach on runtime modload / drvctl -r
>Number: 61012
>Category: kern
>Synopsis: spi(4): add ca_rescan so children attach on runtime modload / drvctl -r
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Nov 15 17:40:00 +0000 2026
>Originator: Thorsten Grassmann
>Release: 11.1, NetBSD-current
>Organization:
ZAE Bayern
>Environment:
NetBSD netbsdrpi 11.1 NetBSD 11.1 (GENERIC64) #4: Sun Nov 15 02:19:15 CET 2026 grass@mirrorbox:/tmp/nbsd/obj/sys/arch/evbarm/compile/GENERIC64 evbarm
>Description:
I wrote a small SNES-gamepad driver as an LKM that attaches with "snespad* at spi? slave N" (for a Raspberry Pi 3 via the SPI0 header; the driver is pure spi(4) and machine-independent; https://github.com/thgrass/NetBSD_snespad_spi ).
On NetBSD 11.1 evbarm GENERIC64 with bcmspi(4)/spi(4):
# modload snespad
modload: rc=0 // module loads fine
// dmesg: nothing. no snespad0 at spi0, no /dev/snespad*.
# drvctl -r -a spi spi0 -> also nothing.
Tracing config_cfdata_attach() -> rescan_with_cfdata() showed the rescan is dispatched to ca_rescan of each attached bus. But spi's cfattach is ca_rescan = NULL (CFATTACH_DECL_NEW).
The same driver works when built into the kernel directly.
Is this by design? As SPI devices usually are "built-in" and there is rarely the need for loadable modules in production.
Adding proposed patch (see below) would at least make SPI driver development more convenient...
>How-To-Repeat:
On any system with an spi(4) bus attached:
# drvctl -l // shows spi0
# drvctl -r -a spi spi0
drvctl: DRVRESCANBUS: No such device or address
>Fix:
Patch spi-rescan-trunk.patch:
adds spi_rescan() to spi(4) and registers it as ca_rescan via CFATTACH_DECL2_NEW. (Boot-time attach is unchanged).
spi-rescan-trunk.patch:
--- a/sys/dev/spi/spi.c
+++ b/sys/dev/spi/spi.c
@@ -298,6 +298,22 @@
* We provide wrapper routines to decouple the ABI for the SPI
* device drivers from the ABI for the SPI bus drivers.
*/
+/*
+ * Rescan the bus for children, e.g. when a driver module with
+ * "at spi?" cfdata is loaded at runtime (config_cfdata_attach() ->
+ * rescan_with_cfdata()) or via "drvctl -r -a spi <bus>".
+ */
+static int
+spi_rescan(device_t self, const char *ifattr, const int *ldesc)
+{
+
+ KASSERT(ifattr && !strcmp(ifattr, "spi"));
+
+ config_search(self, NULL,
+ CFARGS(.search = spi_search));
+ return 0;
+}
+
static void
spi_attach(device_t parent, device_t self, void *aux)
{
@@ -375,8 +391,7 @@
device_call(self, SPI_ENUMERATE_DEVICES(&enumargs));
/* Then do any other devices the user may have manually wired */
- config_search(self, NULL,
- CFARGS(.search = spi_search));
+ spi_rescan(self, "spi", NULL);
}
static int
@@ -488,8 +503,8 @@
return error;
}
-CFATTACH_DECL_NEW(spi, sizeof(struct spi_softc),
- spi_match, spi_attach, spi_detach, NULL);
+CFATTACH_DECL2_NEW(spi, sizeof(struct spi_softc),
+ spi_match, spi_attach, spi_detach, NULL, spi_rescan, NULL);
/*
* Configure. This should be the first thing that the SPI driver
Home |
Main Index |
Thread Index |
Old Index