The 23LCV1024 is a 1 Mbit serial SRAM with battery backup on an SPI
bus, used as non volatile scratch storage. This adds a driver for it,
plus a sandbox emulation and a unit test.

The driver sits in UCLASS_MTD, the way the SPI NAND driver does, so
the device is reached through the mtd command. v1 put it in
UCLASS_SPI_FLASH to borrow the sf command, which meant shimming
struct spi_nor fields for a device with no flash semantics.

Reworked this now in v2 (comments from Simon)

Add patch "mtd: refuse an erase on a device that cannot erase" in v2
which prepares the MTD core for devices which have no erase function.

Patch 2 does the same for partitions on such a device, which are
aligned on the write size instead of the erase size the device does
not have. Without it "mtd list" divides by zero as soon as the device
tree gives the RAM partitions.

Patch 3 is the driver itself, now in drivers/mtd/spi_ram.c without erase
function.

patch 4 teaches the sandbox SPI emulation to bind something other than
the flash emulator

patch 5 is the emulation and the test.

Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=218&view=results

Changes in v2:
- New patch. The SRAM driver of patch 3 has no erase, which the old
  mtd_erase() would have turned into a NULL pointer jump
- New patch mtd: align a partition on the write size if the device cannot erase
  Testing on the board dropped for "mtd list" command:
  ### ERROR ### Please RESET the board ###
  This is because division by erase_size, which the SPI RAM driver
  sets to 0. Added for this case also sandbox test.
Added comments from Simon:
- Moved from UCLASS_SPI_FLASH to UCLASS_MTD, the way the SPI NAND
  driver sits. The struct spi_nor shim and the dm_spi_flash_ops are
  gone with it, and the device is reached through the mtd command
  rather than sf.
- Moved from drivers/mtd/spi/ to drivers/mtd/, where the other
  standalone MTD drivers live.
- Dropped the erase operation. v1 filled the range with 0xff from a
  malloc'd buffer and claimed the bus once per 1 KB chunk. A RAM needs
  no erase, and patch 1 makes mtd_erase() answer -EOPNOTSUPP.
- Dropped the linux/mtd/spi-nor.h include, spi_flash.h pulled it in
  anyway and it advertised a NOR driver.
- sprintf() into a fixed field replaced by snprintf() into a buffer the
  driver owns.
- Copyright: dropped the trailing full stop and added Stefan Bigler's
  address.
fixed checkpatch warning:
- Added a MAINTAINERS entry, as the move out of drivers/mtd/spi/
  dropped a checkpatch warning.
Added comments from Simon:
- sandbox,emul is a phandle to an emulation node whose compatible
  selects the driver, instead of a string naming a U-Boot driver. That
  property is already a phandle for I2C and PCI, and dtoc treats it as
  one, so v1 would have given the same name two meanings.
- Renamed sandbox_sf_unbind_emul() to sandbox_spi_unbind_emul(), it is
  no longer specific to SPI NOR.
- The error paths name the driver or the node that could not be bound.
Added comments from Simon:
- The test drives the device through the MTD layer instead of the
  spi_flash uclass.
- Uses sandbox_spi_get_emul() rather than reaching into state->spi[][].
- Added a spi1 alias so that dev_seq() of the bus does not depend on
  probe order.
- The erase part checks for -EOPNOTSUPP now. The v1 comment about
  covering more than one staging step went with the erase loop.
- The emulation lives in its own node with its own compatible, which is
  what patch 4 resolves the phandle to.
- Added the emulation and the test to the MAINTAINERS entry.
Found while Stefan Bigler tested the series on hardware:
- Added partitions to the device in the test device tree and a second
  test that writes through one of them, which is what "mtd list" on his
  board fell over.

Heiko Schocher (5):
  mtd: refuse an erase on a device that cannot erase
  mtd: align a partition on the write size if the device cannot erase
  mtd: add driver for the Microchip 23LCV1024 SPI SRAM
  sandbox: spi: let a slave point at the emulation it needs
  test: dm: add a test for the Microchip 23LCV1024 SPI SRAM

 MAINTAINERS                     |   7 +
 arch/sandbox/dts/test.dts       |  37 ++++++
 arch/sandbox/include/asm/test.h |   8 ++
 configs/sandbox_defconfig       |   2 +
 drivers/mtd/Kconfig             |  23 ++++
 drivers/mtd/Makefile            |   2 +
 drivers/mtd/mtdcore.c           |   3 +
 drivers/mtd/mtdpart.c           |  38 ++++--
 drivers/mtd/spi/sandbox.c       |  65 ++++++++--
 drivers/mtd/spi_ram.c           | 222 ++++++++++++++++++++++++++++++++
 drivers/mtd/spi_ram_sandbox.c   | 190 +++++++++++++++++++++++++++
 drivers/spi/Kconfig             |   2 +-
 include/spi_flash.h             |   2 +-
 test/dm/Makefile                |   1 +
 test/dm/sf.c                    |   4 +-
 test/dm/spi.c                   |  10 +-
 test/dm/spi_ram.c               | 167 ++++++++++++++++++++++++
 17 files changed, 752 insertions(+), 31 deletions(-)
 create mode 100644 drivers/mtd/spi_ram.c
 create mode 100644 drivers/mtd/spi_ram_sandbox.c
 create mode 100644 test/dm/spi_ram.c

---
base-commit: 75df64103873fac09642860cedadaffb8cf6b2c7
branch: spi-ram-v2

-- 
2.55.0

Reply via email to