Hi Heiko,
On 2026-09-22T06:09:29, Heiko Schocher <[email protected]> wrote:
> sandbox: spi: let a slave name the driver that emulates it
>
> sandbox_sf_bind_emul() binds the SPI NOR flash emulator for every slave
> on the sandbox SPI bus, whatever that slave is. There is no way to
> emulate a different kind of SPI device, and a test for such a device
> therefore cannot be written.
>
> Take the name of the emulation driver from a "sandbox,emul" property on
> the node of the slave, and fall back to the flash emulator when the
> property is absent, so that every node in the test device tree today
> keeps the emulation it has.
>
> Signed-off-by: Heiko Schocher <[email protected]>
>
> drivers/mtd/spi/sandbox.c | 25 +++++++++++++++++++++++--
> 1 file changed, 23 insertions(+), 2 deletions(-)
> diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
> @@ -518,6 +518,27 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops
> = {
> +static struct driver *sandbox_spi_emul_lookup(ofnode node)
> +{
> + const char *name;
> +
> + name = ofnode_read_string(node, "sandbox,emul");
> + if (!name)
> + name = "sandbox_sf_emul";
> +
> + return lists_driver_lookup_name(name);
> +}
The property name sandbox,emul is already in use - see
arch/sandbox/dts/sandbox.dtsi for i2c-eeprom, sandbox-rtc, the PMIC
and the swap-case device, and drivers/i2c/i2c-emul-uclass.c /
drivers/pci/pci-emul-uclass.c on the consumer side. Everywhere else it
is a phandle pointing at an emulation node whose compatible selects
the driver, and dtoc even hard-codes #emul-cells for it in
tools/dtoc/dtb_platdata.py. Reusing the same name for a string that
happens to be a U-Boot driver name will confuse anyone reading a
sandbox DT, and it bakes an implementation detail (the C symbol of the
driver) into the device tree. Please follow the I2C and PCI pattern:
put the emulation in its own node with the appropriate compatible, and
reference it here with sandbox,emul = <&spi_ram_emul>. Then
sandbox_spi_emul_lookup() resolves the phandle, binds the driver named
by its compatible, and there is no new schema to invent.
> diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
> @@ -530,9 +551,9 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int
> busnum, int cs,
> drv = lists_driver_lookup_name("sandbox_sf_emul");
> if (!drv) {
> - puts("Cannot find sandbox_sf_emul driver\n");
> + puts("Cannot find SPI emulation driver\n");
> return -ENOENT;
> }
Now that the name can come from the DT, the message should say which
driver was not found - otherwise a typo in sandbox,emul gives the
reader nothing to go on. Something like printf("Cannot find SPI
emulation driver '%s'\n", name) would help, which means passing the
resolved name back from the lookup helper.
Regards,
Simon