From: "João Loureiro" <joaofl@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: "Tom Rini" <trini@konsulko.com>, "Simon Glass" <sjg@chromium.org>,
"João Loureiro" <joaofl@gmail.com>
Subject: [PATCH v5 0/3] spi: Introduce driver-model support for SPI EEPROMs
Date: Sat, 5 Sep 2026 12:24:28 +0200 [thread overview]
Message-ID: <20260905102431.426747-1-joaofl@gmail.com> (raw)
In-Reply-To: <20260615175118.53720-1-joaofl@gmail.com>
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
next prev parent reply other threads:[~2026-09-05 13:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 11:38 [PATCH] SPI: Introduce initial EEPROM driver mode support Loureiro, Joao
2025-02-24 11:43 ` [PATCH] spi: Introduce initial eeprom " Loureiro, Joao
2025-03-04 17:47 ` Tom Rini
2025-03-05 12:26 ` [PATCH v2] spi: Introduce initial EEPROM " Loureiro, Joao
2026-06-10 22:11 ` [PATCH v3 0/2] " João Loureiro
2026-06-10 22:11 ` [PATCH v3 1/2] " João Loureiro
2026-06-10 22:12 ` [PATCH v3 2/2] sandbox: spi: Add SPI EEPROM emulator and DM test João Loureiro
2026-06-14 12:18 ` Simon Glass
2026-06-15 17:51 ` [PATCH v4 0/2] spi: Introduce initial EEPROM driver mode support João Loureiro
2026-06-15 17:51 ` [PATCH v4 1/2] " João Loureiro
2026-07-13 13:03 ` Simon Glass
2026-09-05 10:14 ` João Loureiro
2026-06-15 17:51 ` [PATCH v4 2/2] sandbox: spi: Add SPI EEPROM emulator and DM test João Loureiro
2026-09-05 10:24 ` João Loureiro [this message]
2026-09-10 14:30 ` [PATCH v5 0/3] spi: Introduce driver-model support for SPI EEPROMs Simon Glass
2026-09-05 10:24 ` [PATCH v5 1/3] test: dm: sf: Get the emulator attached to the flash slave João Loureiro
2026-09-05 10:24 ` [PATCH v5 2/3] spi: Introduce initial driver-model support for SPI EEPROMs João Loureiro
2026-09-05 10:24 ` [PATCH v5 3/3] sandbox: spi: Add SPI EEPROM emulator and DM test João Loureiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260905102431.426747-1-joaofl@gmail.com \
--to=joaofl@gmail.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox