This series adds a UCLASS_SPI_EEPROM uclass, a driver for AT25-style
parts, a sandbox emulator and a DM test.

Simon, thank you for the detailed review of v4 - it was a genuinely
useful read. The point about the hard-coded 16-bit address in
particular sent this somewhere better than where I had it, and chasing
your comment about the non-standard 'size' and 'pagesize' properties is
what turned up the atmel,at25 binding already sitting in the tree,
which now drives the whole geometry.

v5 addresses that review. The main change is that the driver
is no longer hard-wired to a single 16-bit-addressed part: the address
length now comes from driver data and can be overridden from the device
tree, so 8-, 16- and 24-bit addressed devices all work.

It also fixes a crash that v3 and v4 both had, and that I only spotted
while re-testing this round. Adding the EEPROM emulator to test.dts
makes "ut dm" segfault in dm_test_spi_flash: that test picks up its
emulator with uclass_first_device_err(UCLASS_SPI_EMUL), assuming the
sandbox SPI flash emulator is the only one. The flash emulator is bound
lazily on first transfer, so a second emulator described in the device
tree is bound during the devicetree scan and lands first in the uclass.
sandbox_sf_set_block_protect() then casts a struct sandbox_spi_eeprom
to struct sandbox_spi_flash and writes past the end of it, which trips
the dlmalloc heap check. Sorry for shipping that in v3/v4 - my testing
had been running "ut dm spi_eeprom" rather than the whole suite. New
patch 1 fixes the test; with it, "ut dm" on sandbox reports the same 28
failures as an unpatched v2026.10-rc3 tree here (all fixture-related),
plus the new spi_eeprom test passing.

Changes in v5:

- New patch 1: test/dm/sf.c now asks for the emulator attached to its
  own slave rather than the first one in UCLASS_SPI_EMUL, fixing the
  segfault described above.

- Commit message on patch 2 reworded: imperative mood, "driver model"
  rather than "driver mode", and it now explains the motivation - what
  these EEPROMs are used for and why the uclass is wanted.

- SPI_EEPROM_CMD_SIZE is gone. Address length is an addr_len field in
  driver data, overridable from the device tree, so parts larger than
  64 KiB are handled and adding one later does not need an API change.

- The AT25_CMD_* opcodes have moved out of include/spi_eeprom.h into a
  new private header, drivers/misc/spi_eeprom_priv.h, shared by the
  driver and the emulator.

- The read path no longer computes "offset + size", which could
  overflow; the two ranges are checked independently as suggested.
  probe() additionally rejects a "size" that does not fit the
  configured address width, so an offset can no longer be silently
  truncated.

- of_to_plat() dropped; the geometry is read in probe() instead.

- "size" and "pagesize" are kept, and "address-width" added, because
  they are documented -- and in fact required for non-FRAM parts -- by
  the atmel,at25 binding in dts/upstream/Bindings/eeprom/at25.yaml,
  which is already in tree. The commit message and Kconfig help now
  point at it.

- Compatible list expanded, taking the strings from that binding rather
  than inventing them: microchip,25aa010a, microchip,at25160bn,
  atmel,at25256B, st,m95640, st,m95256 and st,m95m02, plus the generic
  "atmel,at25" fallback the binding requires every node to carry. A
  node matching only the fallback is fully described by its device
  tree. The at25010b/020b/040b/080b/640b strings suggested in review
  are not part of the binding so I left them out, and microchip,25lc040
  is in the binding but uses 9-bit addressing, which this driver does
  not implement yet.

- Kconfig: "depends on MISC" dropped -- the misc uclass really is not
  used here. (For the record, I2C_EEPROM in tree does still carry it.)
  The help text now describes the uclass, the AT25 driver, the
  supported address widths and the read-only limitation.

- include/spi_eeprom.h converted to kerneldoc, and the outer #endif is
  now commented.

- The sandbox EEPROM node in test.dts follows the binding: it carries
  the "atmel,at25" fallback compatible and the required size, pagesize
  and address-width properties.

- Added my own copyright line alongside the existing Philips one on the
  new files. The first version of this series was posted while I worked
  at Philips; the rework since is my own.

Patch 3 (the emulator and test) is otherwise unchanged, and I have kept
Simon's Reviewed-by and Tested-by on it.

Simon - please do re-test rather than let those tags stand. The tree
you tested for v4 segfaulted on a full "ut dm"; only "ut dm spi_eeprom"
on its own passes, which I assume is what we both ran. New patch 1 is
what makes the full suite pass again. Patch 3 has also changed since
v4: its DT node now follows the atmel,at25 binding, and the emulator
includes the new private header instead of the uclass one. Happy to
drop the tags if you would rather re-review from scratch.

Changes in v4:
- Emulator frees its backing store in a remove() method.
- Full kerneldoc for sandbox_spi_emul_get().

Changes in v3:
- Reindented with tabs; the series is now checkpatch-clean.
- Dropped the no-op write stub in favour of returning -ENOSYS.
- Removed dead code, fixed the read bounds check, corrected the
  AT25160 geometry, switched to u8 types and added a MAINTAINERS entry.
- Added the sandbox emulator and the DM test (patch 2).

João Loureiro (3):
  test: dm: sf: Get the emulator attached to the flash slave
  spi: Introduce initial driver-model support for SPI EEPROMs
  sandbox: spi: Add SPI EEPROM emulator and DM test

 MAINTAINERS                    |   9 ++
 arch/sandbox/dts/test.dts      |  16 +-
 configs/sandbox_defconfig      |   1 +
 drivers/misc/Kconfig           |  15 ++
 drivers/misc/Makefile          |   2 +
 drivers/misc/spi_eeprom.c      | 267 +++++++++++++++++++++++++++++++++
 drivers/misc/spi_eeprom_emul.c | 130 ++++++++++++++++
 drivers/misc/spi_eeprom_priv.h |  18 +++
 drivers/spi/sandbox_spi.c      |  37 ++++-
 include/dm/uclass-id.h         |   1 +
 include/spi_eeprom.h           |  95 ++++++++++++
 test/dm/Makefile               |   1 +
 test/dm/sf.c                   |   9 +-
 test/dm/spi_eeprom.c           |  46 ++++++
 14 files changed, 643 insertions(+), 4 deletions(-)
 create mode 100644 drivers/misc/spi_eeprom.c
 create mode 100644 drivers/misc/spi_eeprom_emul.c
 create mode 100644 drivers/misc/spi_eeprom_priv.h
 create mode 100644 include/spi_eeprom.h
 create mode 100644 test/dm/spi_eeprom.c

-- 
2.55.0

Reply via email to