mtd: Microchip 23LCV1024 SPI SRAM
Subsystems (2)
v2 cover mtd: Microchip 23LCV1024 SPI SRAM
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
Signature · 1 line
2.55.0
PATCH v2 1/5 mtd: refuse an erase on a device that cannot erase
mtd_erase() calls mtd->_erase() without checking that the driver has one, so a device which does not provide one will end in accessing NULL pointer.
MTD_NO_ERASE flag exists, but nobody reads it yet.
Linux guards mtd_erase() with
if (!mtd->erasesize || !master->_erase) return -ENOTSUPP;
so do the same in U-Boot, but with EOPNOTSUPP as the error code, as checkpatch asks for ("ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP").
---
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
drivers/mtd/mtdcore.c | 3 +++ drivers/mtd/mtdpart.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/mtdcore.c +3 -0
@@ -906,6 +906,9 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);int mtd_erase (struct mtd_info *mtd,struct erase_info *instr) { +if (!mtd->erasesize || !mtd->_erase) +return -EOPNOTSUPP ; +if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)return -EINVAL ;if (!(mtd->flags &MTD_WRITEABLE ))
drivers/mtd/mtdpart.c +2 -1
@@ -654,7 +654,8 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, slave->_block_isbad = part_block_isbad;if (master->_block_markbad) slave->_block_markbad = part_block_markbad; - slave->_erase = part_erase; +if (master->_erase) + slave->_erase = part_erase; slave->parent = master; slave->offset = part->offset;INIT_LIST_HEAD (&slave->partitions);
Signature · 1 line
2.55.0
Re: [PATCH v2 1/5] mtd: refuse an erase on a device that cannot erase
Hi Heiko,
Quoted 7 lines · Heiko Schocher
mtd: refuse an erase on a device that cannot erase
mtd_erase()callsmtd->_erase()without checking that the driver has one, so a device which does not provide one will end in accessing NULL pointer.
MTD_NO_ERASEflag exists, but nobody reads it yet.
This sentence is confusing. spi-nor-core.c already sets MTD_NO_ERASE for SPI_NOR_NO_ERASE parts, which still have an _erase and a non-zero erasesize. This patch doesn't read the flag either, so it would be clearer to drop the sentence or to say why the check uses erasesize and _erase rather than the flag. Also, how about 'jumps to a NULL pointer' instead of 'will end in accessing NULL pointer'?
Quoted 18 lines
Linux guards
mtd_erase()withif (!mtd->erasesize || !master->_erase) return -ENOTSUPP;so do the same in U-Boot, but with EOPNOTSUPP as the error code, as checkpatch asks for ("ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP").
Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/mtdcore.c| 3 +++drivers/mtd/mtdpart.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/mtdcore.c EXPORT_SYMBOL_GPL(__put_mtd_device); · line 935
Quoted 6 lines
drivers/mtd/mtdcore.c +3
-0@@ -930,6 +930,9 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);int mtd_erase (struct mtd_info *mtd,struct erase_info *instr) { +if (!mtd->erasesize || !mtd->_erase) +return -EOPNOTSUPP ; +
From what I can see, but 'mtd erase' never gets this far. do_mtd_erase() first calls mtd_is_aligned_with_block_size(), which does do_div(size, mtd->erasesize), then mtd_div_by_eb(). With erasesize == 0 both divide by zero.
do_mtd_io() also calls mtd_is_aligned_with_block_size(mtd, off) for every page, so I think 'mtd read' and 'mtd write' hit it too. The test in patch 5 calls mtd_read() and mtd_write() directly, so it doesn't catch this.
Please can you make mtd_is_aligned_with_block_size() cope with erasesize == 0 (e.g. treating it as 'no blocks'), and have do_mtd_erase() bail out early with a message for such a device? A small test that runs 'mtd read', 'mtd write' and 'mtd erase' against the SRAM would cover it.
drivers/mtd/mtdpart.c static struct mtd_info *allocate_partition(struct mtd_info *master, · line 655
Quoted 5 lines
drivers/mtd/mtdpart.c +2
-1@@ -654,7 +654,8 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, - slave->_erase = part_erase; +if (master->_erase) + slave->_erase = part_erase;
This is fine, but please mention it in the commit message: a partition only gets part_erase() when its master has an _erase, so part_erase() can't call through a NULL master->_erase either.
With the above:
Regards,
Simon
Re: [PATCH v2 1/5] mtd: refuse an erase on a device that cannot erase
Hello Simon,
Quoted 9 lines · Simon Glass
Hi Heiko,
Quoted 6 lines · Heiko Schocher
mtd: refuse an erase on a device that cannot erase
mtd_erase()callsmtd->_erase()without checking that the driver has one, so a device which does not provide one will end in accessing NULL pointer.
Quoted 8 lines
Quoted 1 line
MTD_NO_ERASEflag exists, but nobody reads it yet.This sentence is confusing.
spi-nor-core.calready setsMTD_NO_ERASEforSPI_NOR_NO_ERASEparts, which still have an_eraseand a non-zero erasesize. This patch doesn't read the flag either, so it would be clearer to drop the sentence or to say why the check uses erasesize and_eraserather than the flag. Also, how about 'jumps to a NULL pointer' instead of 'will end in accessing NULL pointer'?
I drop the sentence which is wrong. Also reword to "jumps to a NULL pointer"
Quoted 36 lines
Quoted 19 lines
Linux guards
mtd_erase()withif (!mtd->erasesize || !master->_erase) return -ENOTSUPP;so do the same in U-Boot, but with EOPNOTSUPP as the error code, as checkpatch asks for ("ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP").
Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/mtdcore.c| 3 +++drivers/mtd/mtdpart.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)drivers/mtd/mtdcore.c EXPORT_SYMBOL_GPL(__put_mtd_device); · line 935
Quoted 6 lines
drivers/mtd/mtdcore.c +3
-0@@ -930,6 +930,9 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);int mtd_erase (struct mtd_info *mtd,struct erase_info *instr) { +if (!mtd->erasesize || !mtd->_erase) +return -EOPNOTSUPP ; +From what I can see, but 'mtd erase' never gets this far.
do_mtd_erase()first callsmtd_is_aligned_with_block_size(), which doesdo_div(size, mtd->erasesize), thenmtd_div_by_eb(). With erasesize == 0 both divide by zero.
do_mtd_io()also callsmtd_is_aligned_with_block_size(mtd, off)for every page, so I think 'mtd read' and 'mtd write' hit it too. The test in patch 5 callsmtd_read()andmtd_write()directly, so it doesn't catch this.
Quoted 5 lines
Please can you make
mtd_is_aligned_with_block_size()cope with erasesize == 0 (e.g. treating it as 'no blocks'), and havedo_mtd_erase()bail out early with a message for such a device? A small test that runs 'mtd read', 'mtd write' and 'mtd erase' against the SRAM would cover it.
Of course! I think I start with a test/cmd/mtd.c
Quoted 10 lines
drivers/mtd/mtdpart.c static struct mtd_info *allocate_partition(struct mtd_info *master, · line 655
Quoted 6 lines
drivers/mtd/mtdpart.c +2
-1@@ -654,7 +654,8 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, - slave->_erase = part_erase; +if (master->_erase) + slave->_erase = part_erase;This is fine, but please mention it in the commit message: a partition only gets
part_erase()when its master has an_erase, sopart_erase()can't call through a NULLmaster->_eraseeither.
Will add this.
Quoted 4 lines
With the above:
Reviewed-by Simon Glass <[email protected]>
Will add this too, thanks for your review!
bye,
Heiko
Quoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
PATCH v2 2/5 mtd: align a partition on the write size if the device cannot erase
In reply to Heiko Schocherallocate_partition() aligns a partition on the erase size of its master and checks the offset and the size against it with mtd_mod_by_eb(). A device which cannot erase has no erase size, so that check divides by zero, "mtd list" shows
### ERROR ### Please RESET the board ###
Linux aligns the partition of such a device on the write size instead, see wr_alignment in allocate_partition() in drivers/mtd/mtdpart.c. Do the same here, and take the alignment for the MTDPART_OFS_NXTBLK rounding from the same place, which divided by the erase size as well.
---
checkpatch reports two warnings and four checks on the two printk(KERN_WARNING"mtd: partition ... force read-only\n") lines. This patch only changes s|erase block|erase/write block in the string of the print, so ignoring the warnings.
Changes in v2:
- 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.
drivers/mtd/mtdpart.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/mtd/mtdpart.c +26 -9
@@ -563,8 +563,12 @@ static struct mtd_info *allocate_partition(struct mtd_info *master,const struct mtd_partition *part, int partno, uint64_t cur_offset) { + u32 wr_alignment = (master->flags & MTD_NO_ERASE) ? master->writesize : + master->erasesize;struct mtd_info *slave; +u32 remainder;char *name; +u64 tmp;/* allocate the partition structure */ slave =kzalloc (sizeof (*slave),GFP_KERNEL );
@@ -665,9 +669,11 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, slave->offset = cur_offset;if (slave->offset ==MTDPART_OFS_NXTBLK ) { slave->offset = cur_offset; -if (mtd_mod_by_eb (cur_offset, master) !=0 ) { -/* Round up to next erasesize */ - slave->offset = (mtd_div_by_eb (cur_offset, master) +1 ) * master->erasesize; + tmp = cur_offset; + remainder =do_div (tmp, wr_alignment); +if (remainder) { +/* Round up to the next alignment boundary */ + slave->offset += wr_alignment - remainder;debug ("Moving partition %d: " "0x%012llx -> 0x%012llx\n" , partno, (unsigned long long )cur_offset, (unsigned long long )slave->offset);
@@ -731,19 +737,30 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, slave->erasesize = master->erasesize; } -if ((slave->flags &MTD_WRITEABLE ) && -mtd_mod_by_eb (slave->offset, slave)) { +/* +* The erase size of the partition may differ from the one of the +* master if the master exposes several erase regions. Align to the +* one the partition ended up with. +*/ +if (!(slave->flags &MTD_NO_ERASE )) + wr_alignment = slave->erasesize; + + tmp = slave->offset; + remainder =do_div (tmp, wr_alignment); +if ((slave->flags &MTD_WRITEABLE ) && remainder) {/* Doesn't start on a boundary of major erase size */ /* FIXME: Let it be writable if it is on a boundary of * _minor_ erase size though */ slave->flags &= ~MTD_WRITEABLE ; -printk (KERN_WARNING "mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n" , +printk (KERN_WARNING "mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n" , part->name); } -if ((slave->flags &MTD_WRITEABLE ) && -mtd_mod_by_eb (slave->size, slave)) { + + tmp = slave->size; + remainder =do_div (tmp, wr_alignment); +if ((slave->flags &MTD_WRITEABLE ) && remainder) { slave->flags &= ~MTD_WRITEABLE ; -printk (KERN_WARNING "mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n" , +printk (KERN_WARNING "mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n" , part->name); }
Signature · 1 line
2.55.0
Re: [PATCH v2 2/5] mtd: align a partition on the write size if the device cannot erase
Hi Heiko,
Quoted 22 lines · Heiko Schocher
mtd: align a partition on the write size if the device cannot erase
allocate_partition()aligns a partition on the erase size of its master and checks the offset and the size against it withmtd_mod_by_eb(). A device which cannot erase has no erase size, so that check divides by zero, "mtd list" shows### ERROR ### Please RESET the board ###
Linux aligns the partition of such a device on the write size instead, see
wr_alignmentinallocate_partition()indrivers/mtd/mtdpart.c. Do the same here, and take the alignment for theMTDPART_OFS_NXTBLKrounding from the same place, which divided by the erase size as well.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/mtdpart.c| 35 ++++++++++++++++++++++++++---------1 file changed, 26 insertions(+), 9 deletions(-)
drivers/mtd/mtdpart.c static struct mtd_info *allocate_partition(struct mtd_info *master, · line 564
Quoted 2 lines
drivers/mtd/mtdpart.c +2
-0@@ -563,8 +563,12 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, +u32 wr_alignment = (master->flags &MTD_NO_ERASE ) ? master->writesize : + master->erasesize;
Patch 1 decides that a device cannot erase with !mtd->erasesize || !mtd->_erase, but this patch checks MTD_NO_ERASE, and the two don't always agree. A driver that leaves erasesize at 0 without setting MTD_NO_ERASE still divides by zero here, as does an MTD_NO_ERASE driver that leaves writesize at 0. Since the point is to stop 'mtd list' crashing, I suggest skipping the alignment checks, or adding a WARN_ON(), when wr_alignment is 0, rather than relying on every driver setting the flags correctly. What do you think?
drivers/mtd/mtdpart.c static struct mtd_info *allocate_partition(struct mtd_info *master, · line 740
Quoted 6 lines
drivers/mtd/mtdpart.c +3
-0@@ -731,19 +737,30 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, + tmp = slave->offset; + remainder =do_div (tmp, wr_alignment); +if ((slave->flags &MTD_WRITEABLE ) && remainder) {/* Doesn't start on a boundary of major erase size */
This comment is now out of date.
In any case:
Regards,
Simon
Re: [PATCH v2 2/5] mtd: align a partition on the write size if the device cannot erase
Hello Simon,
Quoted 23 lines · Simon Glass
Hi Heiko,
Quoted 19 lines · Heiko Schocher
mtd: align a partition on the write size if the device cannot erase
allocate_partition()aligns a partition on the erase size of its master and checks the offset and the size against it withmtd_mod_by_eb(). A device which cannot erase has no erase size, so that check divides by zero, "mtd list" shows### ERROR ### Please RESET the board ###
Linux aligns the partition of such a device on the write size instead, see
wr_alignmentinallocate_partition()indrivers/mtd/mtdpart.c. Do the same here, and take the alignment for theMTDPART_OFS_NXTBLKrounding from the same place, which divided by the erase size as well.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/mtdpart.c| 35 ++++++++++++++++++++++++++---------1 file changed, 26 insertions(+), 9 deletions(-)
Quoted 13 lines
drivers/mtd/mtdpart.c static struct mtd_info *allocate_partition(struct mtd_info *master, · line 564
Quoted 4 lines
drivers/mtd/mtdpart.c +2
-0@@ -563,8 +563,12 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, +u32 wr_alignment = (master->flags &MTD_NO_ERASE ) ? master->writesize : + master->erasesize;Patch 1 decides that a device cannot erase with !mtd->erasesize || !mtd->_erase, but this patch checks
MTD_NO_ERASE, and the two don't always agree. A driver that leaves erasesize at 0 without settingMTD_NO_ERASEstill divides by zero here, as does anMTD_NO_ERASEdriver that leaves writesize at 0. Since the point is to stop 'mtd list' crashing, I suggest skipping the alignment checks, or adding aWARN_ON(), whenwr_alignmentis 0, rather than relying on every driver setting the flags correctly. What do you think?
Makes sense, I think I remove the alignment checks and add a WARN_ON()
Quoted 9 lines
drivers/mtd/mtdpart.c static struct mtd_info *allocate_partition(struct mtd_info *master, · line 740
Quoted 7 lines
drivers/mtd/mtdpart.c +3
-0@@ -731,19 +737,30 @@ static struct mtd_info *allocate_partition(struct mtd_info *master, + tmp = slave->offset; + remainder =do_div (tmp, wr_alignment); +if ((slave->flags &MTD_WRITEABLE ) && remainder) {/* Doesn't start on a boundary of major erase size */ This comment is now out of date.
Will fix this in v3.
Quoted 4 lines
In any case:
Reviewed-by Simon Glass <[email protected]>
Thanks!
bye,
HEiko
Quoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
PATCH v2 3/5 mtd: add driver for the Microchip 23LCV1024 SPI SRAM
In reply to Heiko SchocherThe 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type MTD_RAM, so the mtd command reaches it.
The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe, so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says MTD_NO_ERASE in the MTD flags.
---
Changes in v2:
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.
MAINTAINERS | 5 + configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 drivers/mtd/spi_ram.c
MAINTAINERS +5 -0
@@ -1649,6 +1649,11 @@ S: Maintained T: git https://git.u-boot-project.org/u-boot/custodians/u-boot-nand-flash.git F: drivers/mtd/nand/spi/ +SPI RAM +M: Heiko Schocher <[email protected]> +S: Maintained +F: drivers/mtd/spi_ram.c + SPI-NOR M: Vignesh R <[email protected]> R: Takahiro Kuwano <[email protected]>
configs/sandbox_defconfig +1 -0
@@ -260,6 +260,7 @@ CONFIG_MMC_PCI=y CONFIG_MMC_SANDBOX=y CONFIG_MMC_SDHCI=y CONFIG_DM_MTD=y +CONFIG_SPI_RAM=y CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 CONFIG_SYS_NAND_USE_FLASH_BBT=y
drivers/mtd/Kconfig +14 -0
@@ -194,6 +194,20 @@ config ALTERA_QSPI NOR flash to parallel flash interface. Please find details on the "Embedded Peripherals IP User Guide" of Altera. +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD + help + Enable support for the Microchip 23LCV1024 serial SRAM, a 1 Mbit + SRAM with battery backup on an SPI bus. The device is registered + as an MTD device of type MTD_RAM, so the mtd command reaches it. + + Writing needs no erase, so the driver implements none and the MTD + flags say MTD_NO_ERASE. An erase request is answered with + -EOPNOTSUPP rather than silently doing nothing. + + If unsure, say N + config RENESAS_RPC_HF bool "Renesas R-Car Gen3 RPC HyperFlash driver" depends on RCAR_64 && DM_MTD
drivers/mtd/Makefile +1 -0
@@ -13,6 +13,7 @@ mtd-$(CONFIG_FLASH_CFI_MTD) += cfi_mtd.o mtd-$(CONFIG_FLASH_CFI_LEGACY) += jedec_flash.o mtd-$(CONFIG_STM32_FLASH) += stm32_flash.o mtd-$(CONFIG_RENESAS_RPC_HF) += renesas_rpc_hf.o +mtd-$(CONFIG_SPI_RAM) += spi_ram.o mtd-$(CONFIG_HBMC_AM654) += hbmc-am654.o # U-Boot build
drivers/mtd/spi_ram.c new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in spi_ram_probe() to match?
Quoted 18 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 3 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM, spi_ram.c and the spi_ram driver name are very generic for a driver that handles one Microchip part. Linux already supports this chip in drivers/mtd/devices/mchp23k256.c (CONFIG_MTD_MCHP23K256), and the binding in dts/upstream/Bindings/mtd/microchip,mchp23k256.yaml lists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and in MAINTAINERS?
drivers/mtd/spi_ram.c line 8
Quoted 10 lines
drivers/mtd/spi_ram.c +8
-0@@ -0,0 +1,222 @@ +static int spi_ram_xfer (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, +const void *data_out,void *data_in,size_t data_len) +{ +unsigned long flags =SPI_XFER_BEGIN ; +int ret; + +if (!data_len) + flags |=SPI_XFER_END ;
This duplicates spi_write_then_read() in drivers/spi/spi-uclass.c, which has the same flag handling and debug messages. You could drop this function and use that one instead?
drivers/mtd/spi_ram.c line 7
Quoted 9 lines
drivers/mtd/spi_ram.c +7
-0@@ -0,0 +1,222 @@ + ret =spi_claim_bus (spi); +if (ret) { +dev_dbg (dev,"failed to claim SPI bus: %d\n" , ret); +return ret; + } + + ret =spi_ram_xfer (spi, cmd,sizeof (cmd), data_out, data_in, len);
A read or write of the whole 128KB goes out as a single spi_xfer(). This fails on controllers that only implement spi-mem ops or that limit the transfer size, where the SPI NAND driver you are modelling this on would work. Using spi_mem_exec_op() with spi_mem_adjust_op_size() in a loop would cover both cases. I'm not sure how much that matters for your boards, so I'm just mentioning it.
In any case:
Regards,
Simon
RE: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)
Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?
I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Thanks,
Takahiro
Quoted 32 lines
drivers/mtd/spi_ram.c line 8
Quoted 10 lines
drivers/mtd/spi_ram.c +8
-0@@ -0,0 +1,222 @@ +static int spi_ram_xfer (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, +const void *data_out,void *data_in,size_t data_len) +{ +unsigned long flags =SPI_XFER_BEGIN ; +int ret; + +if (!data_len) + flags |=SPI_XFER_END ;This duplicates
spi_write_then_read()indrivers/spi/spi-uclass.c, which has the same flag handling and debug messages. You could drop this function and use that one instead?drivers/mtd/spi_ram.c line 7
Quoted 9 lines
drivers/mtd/spi_ram.c +7
-0@@ -0,0 +1,222 @@ + ret =spi_claim_bus (spi); +if (ret) { +dev_dbg (dev,"failed to claim SPI bus: %d\n" , ret); +return ret; + } + + ret =spi_ram_xfer (spi, cmd,sizeof (cmd), data_out, data_in, len);A read or write of the whole 128KB goes out as a single
spi_xfer(). This fails on controllers that only implement spi-mem ops or that limit the transfer size, where the SPI NAND driver you are modelling this on would work. Usingspi_mem_exec_op()withspi_mem_adjust_op_size()in a loop would cover both cases. I'm not sure how much that matters for your boards, so I'm just mentioning it.
Quoted 5 lines
In any case:
Reviewed-by Simon Glass <[email protected]>Regards,
Simon
[1] https://lore.kernel.org/u-boot/20261008-everspin_mr24h40_mram_support-v1-0-d8f14da1a997@gmail.com/
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 53 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?
Quoted 7 lines
I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Seems like a valid argument to me. Simon? What do you think?
Thanks!
bye,
Heiko
Quoted 44 lines
Thanks,
TakahiroQuoted 32 lines
drivers/mtd/spi_ram.c line 8
Quoted 10 lines
drivers/mtd/spi_ram.c +8
-0@@ -0,0 +1,222 @@ +static int spi_ram_xfer (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, +const void *data_out,void *data_in,size_t data_len) +{ +unsigned long flags =SPI_XFER_BEGIN ; +int ret; + +if (!data_len) + flags |=SPI_XFER_END ;This duplicates
spi_write_then_read()indrivers/spi/spi-uclass.c, which has the same flag handling and debug messages. You could drop this function and use that one instead?drivers/mtd/spi_ram.c line 7
Quoted 9 lines
drivers/mtd/spi_ram.c +7
-0@@ -0,0 +1,222 @@ + ret =spi_claim_bus (spi); +if (ret) { +dev_dbg (dev,"failed to claim SPI bus: %d\n" , ret); +return ret; + } + + ret =spi_ram_xfer (spi, cmd,sizeof (cmd), data_out, data_in, len);A read or write of the whole 128KB goes out as a single
spi_xfer(). This fails on controllers that only implement spi-mem ops or that limit the transfer size, where the SPI NAND driver you are modelling this on would work. Usingspi_mem_exec_op()withspi_mem_adjust_op_size()in a loop would cover both cases. I'm not sure how much that matters for your boards, so I'm just mentioning it.Quoted 5 lines
In any case:
Reviewed-by Simon Glass <[email protected]>Regards,
Simon[1] https://lore.kernel.org/u-boot/20261008-everspin_mr24h40_mram_support-v1-0-d8f14da1a997@gmail.com/
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hi Takahiro.Kuwano,
Quoted 61 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 56 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>MAINTAINERS | 5 ++
configs/sandbox_defconfig | 1 +
drivers/mtd/Kconfig | 14 +++
drivers/mtd/Makefile | 1 +
drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Quoted 6 lines
Quoted 4 lines
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Seems like a valid argument to me. Simon? What do you think?
After looking into patches from Yasir (added to cc). the FRAM case is different. The FRAM (at least the one Yasir adds) has a JEDEC interface, the 23LCV1024 has not! So 23LCV1024 is really special, and I currently tend to say, that Simon is correct, that we should name the 23LCV1024 driver drivers/mtd/devices/mchp23k256.c.
So I prepare a v3 for my patchset with:
CONFIG_SPI_RAM -> CONFIG_MTD_MCHP23K256 drivers/mtd/spi_ram.c -> drivers/mtd/devices/mchp23k256.c driver name "spi_ram" -> "mchp23k256"
Thanks!
bye,
Heiko
Quoted 50 lines
Thanks!
bye,
HeikoQuoted 44 lines
Thanks,
TakahiroQuoted 32 lines
drivers/mtd/spi_ram.c line 8
Quoted 10 lines
drivers/mtd/spi_ram.c +8
-0@@ -0,0 +1,222 @@ +static int spi_ram_xfer (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, + const void *data_out, void *data_in, size_t data_len) +{ + unsigned long flags = SPI_XFER_BEGIN; + int ret; + + if (!data_len) + flags |= SPI_XFER_END;This duplicates
spi_write_then_read()indrivers/spi/spi-uclass.c, which has the same flag handling and debug messages. You could drop this function and use that one instead?drivers/mtd/spi_ram.c line 7
Quoted 9 lines
drivers/mtd/spi_ram.c +7
-0@@ -0,0 +1,222 @@ + ret = spi_claim_bus(spi); + if (ret) { + dev_dbg(dev, "failed to claim SPI bus: %d\n", ret); + return ret; + } + + ret = spi_ram_xfer(spi, cmd, sizeof(cmd), data_out, data_in, len);A read or write of the whole 128KB goes out as a single
spi_xfer(). This fails on controllers that only implement spi-mem ops or that limit the transfer size, where the SPI NAND driver you are modelling this on would work. Usingspi_mem_exec_op()withspi_mem_adjust_op_size()in a loop would cover both cases. I'm not sure how much that matters for your boards, so I'm just mentioning it.Quoted 5 lines
In any case:
Reviewed-by Simon Glass <[email protected]>Regards,
Simon[1] https://lore.kernel.org/u-boot/20261008-everspin_mr24h40_mram_support-v1-0-d8f14da1a997@gmail.com/
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
RE: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hi Heiko,
Quoted 69 lines
Hi Takahiro.Kuwano,
Quoted 66 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 60 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Quoted 7 lines
Quoted 1 line
Seems like a valid argument to me. Simon? What do you think?
After looking into patches from Yasir (added to cc). the FRAM case is different. The FRAM (at least the one Yasir adds) has a JEDEC interface, the 23LCV1024 has not! So 23LCV1024 is really special, and I currently tend to say, that Simon is correct, that we should name the 23LCV1024 driver
drivers/mtd/devices/mchp23k256.c.
The MRAM (not FRAM) part doesn't support Read ID (JEDEC ID) command. Yasir mentions that in the commit description and I checked datasheet [1]. Why did you get it has a JEDEC interface?
Thanks,
Takahiro
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hi Takahiro.Kuwano,
Quoted 79 lines · On 13.10.26 03:20, [email protected] wrote:
Hi Heiko,
Quoted 69 lines
Hi Takahiro.Kuwano,
Quoted 66 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 60 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Quoted 7 lines
Quoted 1 line
Seems like a valid argument to me. Simon? What do you think?
After looking into patches from Yasir (added to cc). the FRAM case is different. The FRAM (at least the one Yasir adds) has a JEDEC interface, the 23LCV1024 has not! So 23LCV1024 is really special, and I currently tend to say, that Simon is correct, that we should name the 23LCV1024 driver
drivers/mtd/devices/mchp23k256.c.
Quoted 3 lines
The MRAM (not FRAM) part doesn't support Read ID (JEDEC ID) command. Yasir mentions that in the commit description and I checked datasheet [1]. Why did you get it has a JEDEC interface?
Seems I looked into the wrong datasheet! Maybe it is too early for me here... I need a coffee now.
Thanks!
In linux the MRAM Yasir adds, is also handled in spi nor driver.
the register 5/1 (read/write status register) and 3/2 (read/write data) seems the same for both chips and for spi-nor subsystem.
But, spi-nor and MRAM expect a "status register" and the 23LCV1024 [2] has there a mode register, with different bit meanings!
Seems to me, that is why the 23LCV1024 got his own driver in linux... even if this is the only obvious difference (not checked deeper now).
I tend to be in sync with linux here, and still add the MRAM Yasir adds to the spi-nor driver, and have an own driver for the 23LCV1024 in drivers/mtd/devices.
If not I see 2 options:
a) Yasir adds the MR25H40 to the "spi-ram" driver in this thread in a follow up series. I tend to say, I first go with driver place and name Simon proposed.
b) add 23LCV1024 to spi-nor subsystem and find a way to work out mode/status register differences
other options?
b) seems ugly, a) doable... but all options differ to linux approach.
bye,
Heiko
[2] https://ww1.microchip.com/downloads/en/DeviceDoc/25156A.pdf
Quoted 6 lines
Thanks,
Takahiro
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
RE: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hi Heiko,
Quoted 86 lines
Hi Takahiro.Kuwano,
Quoted 79 lines · On 13.10.26 03:20, [email protected] wrote:
Hi Heiko,
Quoted 69 lines
Hi Takahiro.Kuwano,
Quoted 66 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 60 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Quoted 7 lines
Quoted 1 line
Seems like a valid argument to me. Simon? What do you think?
After looking into patches from Yasir (added to cc). the FRAM case is different. The FRAM (at least the one Yasir adds) has a JEDEC interface, the 23LCV1024 has not! So 23LCV1024 is really special, and I currently tend to say, that Simon is correct, that we should name the 23LCV1024 driver
drivers/mtd/devices/mchp23k256.c.Quoted 3 lines
The MRAM (not FRAM) part doesn't support Read ID (JEDEC ID) command. Yasir mentions that in the commit description and I checked datasheet [1]. Why did you get it has a JEDEC interface?
Quoted 7 lines
Seems I looked into the wrong datasheet! Maybe it is too early for me here... I need a coffee now.
Thanks!
In linux the MRAM Yasir adds, is also handled in spi nor driver.
Yes, it was added quite some time ago. We no longer add new xRAM (non-erase) devices to spi-nor.
Quoted 6 lines
the register 5/1 (read/write status register) and 3/2 (read/write data) seems the same for both chips and for spi-nor subsystem.
But, spi-nor and MRAM expect a "status register" and the 23LCV1024 [2] has there a mode register, with different bit meanings!
I still think we can handle this difference using compatibles and device specific fixup hooks, but...
Quoted 6 lines
Seems to me, that is why the 23LCV1024 got his own driver in linux... even if this is the only obvious difference (not checked deeper now).
I tend to be in sync with linux here, and still add the MRAM Yasir adds to the spi-nor driver, and have an own driver for the 23LCV1024 in
drivers/mtd/devices.
keeping in sync with Linux is generally right thing to do😊
Quoted 8 lines
If not I see 2 options:
a) Yasir adds the MR25H40 to the "spi-ram" driver in this thread in a follow up series. I tend to say, I first go with driver place and name Simon proposed.
b) add 23LCV1024 to spi-nor subsystem and find a way to work out mode/status register differences
Quoted 4 lines
other options?
b) seems ugly, a) doable... but all options differ to linux approach.
At some point, I plan to propose generic spi-ram driver. I have a few Infineon FRAM devices that would benefit from it.
Quoted 3 lines
bye,
Heiko
Anyway, thanks for taking the time to think about this! Takahiro
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Hello Takahiro,
Quoted 91 lines · On 14.10.26 04:54, [email protected] wrote:
Hi Heiko,
Quoted 89 lines
Hi Takahiro.Kuwano,
Quoted 79 lines · On 13.10.26 03:20, [email protected] wrote:
Hi Heiko,
Quoted 69 lines
Hi Takahiro.Kuwano,
Quoted 66 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 60 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Quoted 7 lines
Quoted 1 line
Seems like a valid argument to me. Simon? What do you think?
After looking into patches from Yasir (added to cc). the FRAM case is different. The FRAM (at least the one Yasir adds) has a JEDEC interface, the 23LCV1024 has not! So 23LCV1024 is really special, and I currently tend to say, that Simon is correct, that we should name the 23LCV1024 driver
drivers/mtd/devices/mchp23k256.c.Quoted 3 lines
The MRAM (not FRAM) part doesn't support Read ID (JEDEC ID) command. Yasir mentions that in the commit description and I checked datasheet [1]. Why did you get it has a JEDEC interface?
Seems I looked into the wrong datasheet! Maybe it is too early for me here... I need a coffee now.
Quoted 6 lines
Quoted 4 lines
Thanks!
In linux the MRAM Yasir adds, is also handled in spi nor driver.
Yes, it was added quite some time ago. We no longer add new xRAM (non-erase) devices to spi-nor.
Ah!
For the ones who "share" spi nor interface, we may should extract that part from spi nor to share the code... but as said, I am not to deep in the code...
Quoted 8 lines
Quoted 6 lines
the register 5/1 (read/write status register) and 3/2 (read/write data) seems the same for both chips and for spi-nor subsystem.
But, spi-nor and MRAM expect a "status register" and the 23LCV1024 [2] has there a mode register, with different bit meanings!
I still think we can handle this difference using compatibles and device specific fixup hooks, but...
It is not only the status register, 23LCV1024 has no WREN (write enable), nor polll a status register... It is much more simpler... but yes doable.
Quoted 8 lines
Quoted 7 lines
Seems to me, that is why the 23LCV1024 got his own driver in linux... even if this is the only obvious difference (not checked deeper now).
I tend to be in sync with linux here, and still add the MRAM Yasir adds to the spi-nor driver, and have an own driver for the 23LCV1024 in
drivers/mtd/devices.keeping in sync with Linux is generally right thing to do😊
:-D
Quoted 9 lines
Quoted 9 lines
If not I see 2 options:
a) Yasir adds the MR25H40 to the "spi-ram" driver in this thread in a follow up series. I tend to say, I first go with driver place and name Simon proposed.
b) add 23LCV1024 to spi-nor subsystem and find a way to work out mode/status register differences
Quoted 6 lines
Quoted 4 lines
other options?
b) seems ugly, a) doable... but all options differ to linux approach.
At some point, I plan to propose generic spi-ram driver. I have a few Infineon FRAM devices that would benefit from it.
Good to hear... for linux and/or u-boot?
so for the series... should I try a more common spi-ram approach, or go with linux like drivers/mtd/devices/mchp23k256.c ?
Quoted 5 lines
Quoted 4 lines
bye,
HeikoAnyway, thanks for taking the time to think about this!
You are welcome! Thanks for your time to review my patch.
bye,
Heiko
Quoted 2 lines
Takahiro
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
RE: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
Quoted 139 lines
Hello Takahiro,
Quoted 91 lines · On 14.10.26 04:54, [email protected] wrote:
Hi Heiko,
Quoted 89 lines
Hi Takahiro.Kuwano,
Quoted 79 lines · On 13.10.26 03:20, [email protected] wrote:
Hi Heiko,
Quoted 69 lines
Hi Takahiro.Kuwano,
Quoted 66 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 60 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Quoted 7 lines
Quoted 1 line
Seems like a valid argument to me. Simon? What do you think?
After looking into patches from Yasir (added to cc). the FRAM case is different. The FRAM (at least the one Yasir adds) has a JEDEC interface, the 23LCV1024 has not! So 23LCV1024 is really special, and I currently tend to say, that Simon is correct, that we should name the 23LCV1024 driver
drivers/mtd/devices/mchp23k256.c.Quoted 3 lines
The MRAM (not FRAM) part doesn't support Read ID (JEDEC ID) command. Yasir mentions that in the commit description and I checked datasheet [1]. Why did you get it has a JEDEC interface?
Seems I looked into the wrong datasheet! Maybe it is too early for me here... I need a coffee now.
Quoted 6 lines
Quoted 4 lines
Thanks!
In linux the MRAM Yasir adds, is also handled in spi nor driver.
Yes, it was added quite some time ago. We no longer add new xRAM (non-erase) devices to spi-nor.
Ah!
For the ones who "share" spi nor interface, we may should extract that part from spi nor to share the code... but as said, I am not to deep in the code...
Quoted 8 lines
Quoted 6 lines
the register 5/1 (read/write status register) and 3/2 (read/write data) seems the same for both chips and for spi-nor subsystem.
But, spi-nor and MRAM expect a "status register" and the 23LCV1024 [2] has there a mode register, with different bit meanings!
I still think we can handle this difference using compatibles and device specific fixup hooks, but...
It is not only the status register, 23LCV1024 has no WREN (write enable), nor polll a status register... It is much more simpler... but yes doable.
Quoted 8 lines
Quoted 7 lines
Seems to me, that is why the 23LCV1024 got his own driver in linux... even if this is the only obvious difference (not checked deeper now).
I tend to be in sync with linux here, and still add the MRAM Yasir adds to the spi-nor driver, and have an own driver for the 23LCV1024 in
drivers/mtd/devices.keeping in sync with Linux is generally right thing to do😊
:-D
Quoted 9 lines
Quoted 9 lines
If not I see 2 options:
a) Yasir adds the MR25H40 to the "spi-ram" driver in this thread in a follow up series. I tend to say, I first go with driver place and name Simon proposed.
b) add 23LCV1024 to spi-nor subsystem and find a way to work out mode/status register differences
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
other options?
b) seems ugly, a) doable... but all options differ to linux approach.
At some point, I plan to propose generic spi-ram driver. I have a few Infineon FRAM devices that would benefit from it.
Good to hear... for linux and/or u-boot?
For u-boot. In Linux, FRAM is handled by drivers/nvmem/at25.c as SPI EEPROM compatible devices. If we also want to cover EEPROM in u-boot, then spi-ram may not be the right name...
Quoted 3 lines
so for the series... should I try a more common spi-ram approach, or go with linux like
drivers/mtd/devices/mchp23k256.c?
So, please go with linux like one.
Thanks again,
Takahiro
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
In reply to Heiko SchocherHI Heiko,
Quoted 62 lines · Heiko Schocher
Hello Takahiro.Kuwano,
just answer here, before I looked into the comments from Simon...
Quoted 56 lines · On 09.10.26 10:29, [email protected] wrote:
Hi Heiko and Simon,
Quoted 37 lines
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?Quoted 15 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)Quoted 13 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?I would rather have a generic SPI-RAM driver that also supports MRAM [1] and FRAM devices using the common opcode set without erase.
Quoted 6 lines
Quoted 4 lines
Currently, some FRAM chips are handled by SPI-NOR, but new devices should be added to the SPI-RAM driver if it exists.
What are your thoughts on this?
Seems like a valid argument to me. Simon? What do you think?
Seems reasonable to me, but I have not dug into how these chips actually work.
Regards,
Simon
Quoted 56 lines
Thanks!
bye,
HeikoQuoted 36 lines
Thanks,
TakahiroQuoted 32 lines
drivers/mtd/spi_ram.c line 8
Quoted 10 lines
drivers/mtd/spi_ram.c +8
-0@@ -0,0 +1,222 @@ +static int spi_ram_xfer (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, +const void *data_out,void *data_in,size_t data_len) +{ +unsigned long flags =SPI_XFER_BEGIN ; +int ret; + +if (!data_len) + flags |=SPI_XFER_END ;This duplicates
spi_write_then_read()indrivers/spi/spi-uclass.c, which has the same flag handling and debug messages. You could drop this function and use that one instead?drivers/mtd/spi_ram.c line 7
Quoted 9 lines
drivers/mtd/spi_ram.c +7
-0@@ -0,0 +1,222 @@ + ret =spi_claim_bus (spi); +if (ret) { +dev_dbg (dev,"failed to claim SPI bus: %d\n" , ret); +return ret; + } + + ret =spi_ram_xfer (spi, cmd,sizeof (cmd), data_out, data_in, len);A read or write of the whole 128KB goes out as a single
spi_xfer(). This fails on controllers that only implement spi-mem ops or that limit the transfer size, where the SPI NAND driver you are modelling this on would work. Usingspi_mem_exec_op()withspi_mem_adjust_op_size()in a loop would cover both cases. I'm not sure how much that matters for your boards, so I'm just mentioning it.Quoted 8 lines
Quoted 5 lines
In any case:
Reviewed-by Simon Glass <[email protected]>Regards,
Simon[1] https://lore.kernel.org/u-boot/20261008-everspin_mr24h40_mram_support-v1-0-d8f14da1a997@gmail.com/
--
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic
Re: [PATCH v2 3/5] mtd: add driver for the Microchip 23LCV1024 SPI SRAM
In reply to Simon GlassHello Simon,
Quoted 12 lines · Simon Glass
Hi Heiko,
Quoted 8 lines · Heiko Schocher
mtd: add driver for the Microchip 23LCV1024 SPI SRAM
The 23LCV1024 is a 1 Mbit serial SRAM with battery backup, sitting on an SPI bus and used as non volatile scratch storage. Register it as an MTD device of type
MTD_RAM, so the mtd command reaches it.The device powers up in byte operation, where every command carries exactly one data byte. Select sequential operation once during probe,
Quoted 8 lines
Just to check, is this right? My understanding is that the 23LC1024/23LCV1024 data sheet gives sequential mode (01) as the MODE register default; byte mode is the default only on the older 23K256. The Linux mchp23k256 driver never writes the MODE register. Setting it explicitly is still a fine defensive step, since something else could have changed the mode and the part keeps it while on battery. Please can you reword the commit message and the comment in
spi_ram_probe()to match?
Indeed, my comment is wrong, fix that in v3.
But the linux driver drivers/mtd/devices/mchp23k256.c
base * 24a19b953e2a - (HEAD -> master, tag: v7.3-rc7, origin/master, origin/HEAD) Linux 7.3-rc7)
171 static int mchp23k256_probe(struct spi_device *spi) [...]
185 err = mchp23k256_set_mode(spi);
186 if (err)
187 return err;
with
143 static int mchp23k256_set_mode(struct spi_device *spi) [...]
151 command[0] = MCHP23K256_CMD_WRITE_STATUS;
152 command[1] = MCHP23K256_MODE_SEQ;
so the same as my patch does...
Quoted 17 lines
Quoted 16 lines
so that a read or a write of any length is served by a single command and the bus is claimed once per transfer.
Writing needs no erase. The driver therefore implements no erase operation and says
MTD_NO_ERASEin the MTD flags.Signed-off-by Stefan Bigler <[email protected]>Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 5 ++configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 14 +++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+)
Quoted 12 lines
drivers/mtd/Kconfig config ALTERA_QSPI · line 196
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -194,6 +194,20 @@ config ALTERA_QSPI +config SPI_RAM + bool "Microchip 23LCV1024 SPI SRAM" + depends on DM_SPI && DM_MTD
SPI_RAM,spi_ram.cand thespi_ramdriver name are very generic for a driver that handles one Microchip part. Linux already supports this chip indrivers/mtd/devices/mchp23k256.c(CONFIG_MTD_MCHP23K256), and the binding indts/upstream/Bindings/mtd/microchip,mchp23k256.yamllists both microchip,mchp23k256 and microchip,mchp23lcv1024. How about using the Linux names, here and inMAINTAINERS?
Yep, as in an earlier reply to Takahire Kuwano, I will make this renaming in a v3.
And while looking through the linux driver, I will add mchp23k256 compatible too in v3, and add a sandbox emulation for this (I cannot test it).
Quoted 15 lines
drivers/mtd/spi_ram.c line 8
Quoted 11 lines
drivers/mtd/spi_ram.c +8
-0@@ -0,0 +1,222 @@ +static int spi_ram_xfer (struct spi_slave *spi,const u8 *cmd,size_t cmd_len, +const void *data_out,void *data_in,size_t data_len) +{ +unsigned long flags =SPI_XFER_BEGIN ; +int ret; + +if (!data_len) + flags |=SPI_XFER_END ;This duplicates
spi_write_then_read()indrivers/spi/spi-uclass.c, which has the same flag handling and debug messages. You could drop this function and use that one instead?
Will drop it, thanks!
Quoted 17 lines
drivers/mtd/spi_ram.c line 7
Quoted 10 lines
drivers/mtd/spi_ram.c +7
-0@@ -0,0 +1,222 @@ + ret =spi_claim_bus (spi); +if (ret) { +dev_dbg (dev,"failed to claim SPI bus: %d\n" , ret); +return ret; + } + + ret =spi_ram_xfer (spi, cmd,sizeof (cmd), data_out, data_in, len);A read or write of the whole 128KB goes out as a single
spi_xfer(). This fails on controllers that only implement spi-mem ops or that limit the transfer size, where the SPI NAND driver you are modelling this on would work. Usingspi_mem_exec_op()withspi_mem_adjust_op_size()in a loop would cover both cases. I'm not sure how much that matters for your boards, so I'm just mentioning it.
I will look into it.
Quoted 2 lines
In any case:
Reviewed-by Simon Glass <[email protected]>
Thanks!
bye,
Heiko
Quoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
PATCH v2 4/5 sandbox: spi: let a slave point at the emulation it needs
In reply to Heiko Schochersandbox_sf_bind_emul() binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.
As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename sandbox_sf_unbind_emul() to sandbox_spi_unbind_emul() while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.
---
checkpatch warns "strlcpy is preferred over strncpy" on drivers/mtd/spi/sandbox.c:562. That line is not new, it is there since since commit b6c2956defb4 ("dm: sf: sandbox: Convert SPI flash driver to driver model"). So ignoring this warning.
Changes in v2:
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.
drivers/mtd/spi/sandbox.c | 65 +++++++++++++++++++++++++++++++-------- include/spi_flash.h | 2 +- test/dm/sf.c | 4 +-- test/dm/spi.c | 10 +++--- 4 files changed, 61 insertions(+), 20 deletions(-)
drivers/mtd/spi/sandbox.c +53 -12
@@ -26,6 +26,8 @@#include <dm/lists.h> #include <dm/uclass-internal.h> +#define SANDBOX_SF_EMUL "sandbox_sf_emul" +/* * The different states that our SPI flash transitions between. * We need to keep track of this across multiple xfer calls since
@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { };#ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, -struct udevice *bus,ofnode node,const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave +* +* A slave points at its emulation with a "sandbox,emul" phandle, the way +* the I2C and PCI emulations do, and the compatible of that node selects +* the driver. Without the property the SPI NOR flash emulator is bound on +* the slave's own node, which is what every existing node relies on. +* +* @bus: SPI bus the emulator becomes a child of +* @node: device tree node of the slave +* @spec: name of the slave, used to name the flash emulator +* @emulp: returns the bound emulator +* Return: 0 on success, negative on error +*/ +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, +const char *spec,struct udevice **emulp) { -struct udevice *emul; +struct ofnode_phandle_args args;char name[20 ], *str;struct driver *drv;int ret; -/* now the emulator */ -strncpy (name, spec,sizeof (name) -6 ); - name[sizeof (name) -6 ] ='\0' ; -strcat (name,"-emul" ); - drv =lists_driver_lookup_name ("sandbox_sf_emul" ); +if (!ofnode_parse_phandle_with_args (node,"sandbox,emul" ,NULL ,0 ,0 , + &args)) { + ret =lists_bind_fdt (bus, args.node, emulp,NULL , false); +if (ret) +printf ("Cannot bind emulator from node '%s' (err=%d)\n" , +ofnode_get_name (args.node), ret); + +return ret; + } + + drv =lists_driver_lookup_name (SANDBOX_SF_EMUL );if (!drv) { -puts ("Cannot find sandbox_sf_emul driver\n" ); +printf ("Cannot find SPI emulation driver '%s'\n" , +SANDBOX_SF_EMUL );return -ENOENT ; } + +strncpy (name, spec,sizeof (name) -6 ); + name[sizeof (name) -6 ] ='\0' ; +strcat (name,"-emul" ); str =strdup (name);if (!str)return -ENOMEM ; - ret =device_bind (bus, drv, str,NULL , node, &emul); + + ret =device_bind (bus, drv, str,NULL , node, emulp);if (ret) {free (str);printf ("Cannot create emul device for spec '%s' (err=%d)\n" , spec, ret); -return ret; } + +return ret; +} + +int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, +struct udevice *bus,ofnode node,const char *spec) +{ +struct udevice *emul; +int ret; + + ret =sandbox_spi_emul_lookup (bus, node, spec, &emul); +if (ret) +return ret; + state->spi[busnum][cs].emul = emul;return 0 ; } -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs) +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs) {struct udevice *dev;
include/spi_flash.h +1 -1
@@ -136,7 +136,7 @@ struct sandbox_state;int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs,struct udevice *bus,ofnode node,const char *spec); -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs); +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs);#else /* Compatibility functions for when DM_SPI_FLASH is disabled */
test/dm/sf.c +2 -2
@@ -68,7 +68,7 @@ static int dm_test_spi_flash(struct unit_test_state *uts)* Since we are about to destroy all devices, we must tell sandbox * to forget the emulation device */ -sandbox_sf_unbind_emul (state_get_current (),0 ,0 ); +sandbox_spi_unbind_emul (state_get_current (),0 ,0 );return 0 ; }
@@ -96,7 +96,7 @@ static int dm_test_spi_flash_func(struct unit_test_state *uts)* Since we are about to destroy all devices, we must tell sandbox * to forget the emulation device */ -sandbox_sf_unbind_emul (state_get_current (),0 ,0 ); +sandbox_spi_unbind_emul (state_get_current (),0 ,0 );return 0 ; }
test/dm/spi.c +5 -5
@@ -57,7 +57,7 @@ static int dm_test_spi_find(struct unit_test_state *uts)ut_asserteq (-ENOENT ,_spi_get_bus_and_cs (busnum, cs, speed, mode,"jedec_spi_nor" ,"name" , &bus, &slave)); -sandbox_sf_unbind_emul (state_get_current (), busnum, cs); +sandbox_spi_unbind_emul (state_get_current (), busnum, cs);ut_assertok (spi_cs_info (bus, cs, &info));ut_asserteq_ptr (NULL , info.dev);
@@ -84,8 +84,8 @@ static int dm_test_spi_find(struct unit_test_state *uts)* Since we are about to destroy all devices, we must tell sandbox * to forget the emulation device */ -sandbox_sf_unbind_emul (state_get_current (), busnum, cs); -sandbox_sf_unbind_emul (state_get_current (), busnum, cs_b); +sandbox_spi_unbind_emul (state_get_current (), busnum, cs); +sandbox_spi_unbind_emul (state_get_current (), busnum, cs_b);return 0 ; }
@@ -210,7 +210,7 @@ static int dm_test_spi_xfer(struct unit_test_state *uts)* to forget the emulation device */ #if CONFIG_IS_ENABLED (DM_SPI_FLASH ) -sandbox_sf_unbind_emul (state_get_current (), busnum, cs); +sandbox_spi_unbind_emul (state_get_current (), busnum, cs);#endif return 0 ;
@@ -249,7 +249,7 @@ static int dm_test_spi_xfer_no_rx_tx(struct unit_test_state *uts)* to forget the emulation device */ #if CONFIG_IS_ENABLED (DM_SPI_FLASH ) -sandbox_sf_unbind_emul (state_get_current (), busnum, cs); +sandbox_spi_unbind_emul (state_get_current (), busnum, cs);#endif return 0 ;
Signature · 1 line
2.55.0
Re: [PATCH v2 4/5] sandbox: spi: let a slave point at the emulation it needs
Hi Heiko,
Quoted 24 lines · Heiko Schocher
sandbox: spi: let a slave point at the emulation it needs
sandbox_sf_bind_emul()binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename
sandbox_sf_unbind_emul()tosandbox_spi_unbind_emul()while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/spi/sandbox.c| 65 ++++++++++++++++++++++++++++++++++++++---------include/spi_flash.h | 2 +- test/dm/sf.c | 4 +-- test/dm/spi.c | 10 ++++---- 4 files changed, 61 insertions(+), 20 deletions(-)
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 522
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-2@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = {#ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, -struct udevice *bus,ofnode node,const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave
The generic part (following the sandbox,emul phandle) now lives in the SPI NOR emulator, inside #ifdef CONFIG_SPI_FLASH, as does the only non-weak sandbox_spi_get_emul(). So emulating an SRAM, or anything else that is not flash, needs SPI_FLASH and SPI_FLASH_SANDBOX enabled. Please can you move the phandle lookup and sandbox_spi_get_emul() into drivers/spi/sandbox_spi.c, replacing the __weak version? The flash emulator can then supply just the fallback for nodes with no sandbox,emul property.
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 528
Quoted 11 lines
drivers/mtd/spi/sandbox.c +9
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +if (!ofnode_parse_phandle_with_args (node,"sandbox,emul" ,NULL ,0 ,0 , + &args)) { + ret =lists_bind_fdt (bus, args.node, emulp,NULL , false); +if (ret) +printf ("Cannot bind emulator from node '%s' (err=%d)\n" , +ofnode_get_name (args.node), ret); + +return ret; + }
lists_bind_fdt() returns 0 and sets *emulp to NULL when no driver matches the compatible, e.g. with CONFIG_SPI_RAM_SANDBOX off. NULL is then stored in state->spi[][].emul, sandbox_spi_get_emul() succeeds, and sandbox_spi_xfer() gets -EINVAL from device_probe(NULL) with no hint about the cause. sandbox_spi_unbind_emul() would also pass NULL to device_remove(). Please check for a NULL device and return -ENOENT with a message naming the node.
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 4 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, +const char *spec,struct udevice **emulp)
This binds a device rather than looking one up, so the name is misleading. Also, I2C and PCI do not bind on demand: their emulators are bound by the normal DT scan under an emulation parent node, then found with uclass_get_device_by_phandle(..., "sandbox,emul", ...). If SPI did the same, you could drop the lists_bind_fdt() call, and tests would no longer need to unbind the emulator by hand before devices are destroyed. Here the emulator node is a child of the slave, so it would also be bound twice if the SRAM driver (or the MTD uclass) ever scanned its children. What do you think?
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 4 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, +struct udevice *bus,ofnode node,const char *spec)
The unbind function is renamed because it is no longer specific to SPI NOR, but this one, which now binds any emulator too, keeps the 'sf' name. Please rename it to sandbox_spi_bind_emul() so the two stay consistent.
include/spi_flash.h struct sandbox_state; · line 136
Quoted 4 lines
include/spi_flash.h +1
-1@@ -136,7 +136,7 @@ struct sandbox_state; -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs); +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs);
If this is now a generic SPI helper, it should be declared in include/spi.h next to sandbox_spi_get_emul(), not in spi_flash.h under DM_SPI_FLASH.
Regards,
Simon
Re: [PATCH v2 4/5] sandbox: spi: let a slave point at the emulation it needs
Hello Simon,
Quoted 25 lines · Simon Glass
Hi Heiko,
Quoted 21 lines · Heiko Schocher
sandbox: spi: let a slave point at the emulation it needs
sandbox_sf_bind_emul()binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename
sandbox_sf_unbind_emul()tosandbox_spi_unbind_emul()while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/spi/sandbox.c| 65 ++++++++++++++++++++++++++++++++++++++---------include/spi_flash.h | 2 +- test/dm/sf.c | 4 +-- test/dm/spi.c | 10 ++++---- 4 files changed, 61 insertions(+), 20 deletions(-)
Quoted 16 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 522
Quoted 7 lines
drivers/mtd/spi/sandbox.c +2
-2@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = {#ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, -struct udevice *bus,ofnode node,const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave The generic part (following the sandbox,emul phandle) now lives in the SPI NOR emulator, inside #ifdef
CONFIG_SPI_FLASH, as does the only non-weaksandbox_spi_get_emul(). So emulating an SRAM, or anything else that is not flash, needsSPI_FLASHandSPI_FLASH_SANDBOXenabled. Please can you move the phandle lookup andsandbox_spi_get_emul()intodrivers/spi/sandbox_spi.c, replacing the__weakversion? The flash emulator can then supply just the fallback for nodes with no sandbox,emul property.
I add this in a v3.
Quoted 12 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 528
Quoted 11 lines
drivers/mtd/spi/sandbox.c +9
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +if (!ofnode_parse_phandle_with_args (node,"sandbox,emul" ,NULL ,0 ,0 , + &args)) { + ret =lists_bind_fdt (bus, args.node, emulp,NULL , false); +if (ret) +printf ("Cannot bind emulator from node '%s' (err=%d)\n" , +ofnode_get_name (args.node), ret); + +return ret; + }
Quoted 7 lines
lists_bind_fdt()returns 0 and sets *emulp to NULL when no driver matches the compatible, e.g. withCONFIG_SPI_RAM_SANDBOXoff. NULL is then stored in state->spi[][].emul,sandbox_spi_get_emul()succeeds, andsandbox_spi_xfer()gets-EINVALfromdevice_probe(NULL)with no hint about the cause.sandbox_spi_unbind_emul()would also pass NULL todevice_remove(). Please check for a NULL device and return-ENOENTwith a message naming the node.
I add this in v3.
Quoted 15 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, +const char *spec,struct udevice **emulp)This binds a device rather than looking one up, so the name is misleading. Also, I2C and PCI do not bind on demand: their emulators are bound by the normal DT scan under an emulation parent node, then found with
uclass_get_device_by_phandle(..., "sandbox,emul", ...). If SPI did the same, you could drop thelists_bind_fdt()call, and tests would no longer need to unbind the emulator by hand before devices are destroyed. Here the emulator node is a child of the slave, so it would also be bound twice if the SRAM driver (or the MTD uclass) ever scanned its children. What do you think?
I take a look into it, but sounds correct.
Quoted 10 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, +struct udevice *bus,ofnode node,const char *spec)The unbind function is renamed because it is no longer specific to SPI NOR, but this one, which now binds any emulator too, keeps the 'sf' name. Please rename it to
sandbox_spi_bind_emul()so the two stay consistent.
Of course.
Quoted 9 lines
include/spi_flash.h struct sandbox_state; · line 136
Quoted 5 lines
include/spi_flash.h +1
-1@@ -136,7 +136,7 @@ struct sandbox_state; -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs); +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs);If this is now a generic SPI helper, it should be declared in
include/spi.hnext tosandbox_spi_get_emul(), not inspi_flash.hunderDM_SPI_FLASH.
Indeed, move this in v3
Thanks!
bye,
Heiko
Quoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v2 4/5] sandbox: spi: let a slave point at the emulation it needs
Hi Simon,
Quoted 85 lines · Heiko Schocher
Hello Simon,
Quoted 25 lines · Simon Glass
Hi Heiko,
Quoted 21 lines · Heiko Schocher
sandbox: spi: let a slave point at the emulation it needs
sandbox_sf_bind_emul()binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename
sandbox_sf_unbind_emul()tosandbox_spi_unbind_emul()while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/spi/sandbox.c| 65 ++++++++++++++++++++++++++++++++++++++--------- include/spi_flash.h | 2 +-
test/dm/sf.c | 4 +--
test/dm/spi.c | 10 ++++----4 files changed, 61 insertions(+), 20 deletions(-)Quoted 16 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 522
Quoted 7 lines
drivers/mtd/spi/sandbox.c +2
-2@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { #ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, - struct udevice *bus, ofnode node, const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave The generic part (following the sandbox,emul phandle) now lives in the SPI NOR emulator, inside #ifdef
CONFIG_SPI_FLASH, as does the only non-weaksandbox_spi_get_emul(). So emulating an SRAM, or anything else that is not flash, needsSPI_FLASHandSPI_FLASH_SANDBOXenabled. Please can you move the phandle lookup andsandbox_spi_get_emul()intodrivers/spi/sandbox_spi.c, replacing the__weakversion? The flash emulator can then supply just the fallback for nodes with no sandbox,emul property.I add this in a v3.
Quoted 12 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 528
Quoted 11 lines
drivers/mtd/spi/sandbox.c +9
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { + if (!ofnode_parse_phandle_with_args(node, "sandbox,emul", NULL, 0, 0, + &args)) { + ret = lists_bind_fdt(bus, args.node, emulp, NULL, false); + if (ret) + printf("Cannot bind emulator from node '%s' (err=%d)\n", + ofnode_get_name(args.node), ret); + + return ret; + }Quoted 7 lines
lists_bind_fdt()returns 0 and sets *emulp to NULL when no driver matches the compatible, e.g. withCONFIG_SPI_RAM_SANDBOXoff. NULL is then stored in state->spi[][].emul,sandbox_spi_get_emul()succeeds, andsandbox_spi_xfer()gets-EINVALfromdevice_probe(NULL)with no hint about the cause.sandbox_spi_unbind_emul()would also pass NULL todevice_remove(). Please check for a NULL device and return-ENOENTwith a message naming the node.I add this in v3.
Quoted 15 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, + const char *spec, struct udevice **emulp)This binds a device rather than looking one up, so the name is misleading. Also, I2C and PCI do not bind on demand: their emulators are bound by the normal DT scan under an emulation parent node, then found with
uclass_get_device_by_phandle(..., "sandbox,emul", ...). If SPI did the same, you could drop thelists_bind_fdt()call, and tests would no longer need to unbind the emulator by hand before devices are destroyed. Here the emulator node is a child of the slave, so it would also be bound twice if the SRAM driver (or the MTD uclass) ever scanned its children. What do you think?
Quoted 1 line
I take a look into it, but sounds correct.
I think you are right about the shape.
I will implement in v3 your other comments, and I think, that is a series of its own about the sandbox SPI infrastructure, and none of it is about the SRAM.
I would send it after this one, with the SRAM as the second user, and drop the manual unbind from the tests there, where the change can be seen for what it is.
If this is okay for you?
Thanks!
bye,
Heiko
Quoted 35 lines
Quoted 11 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 6 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, + struct udevice *bus, ofnode node, const char *spec)The unbind function is renamed because it is no longer specific to SPI NOR, but this one, which now binds any emulator too, keeps the 'sf' name. Please rename it to
sandbox_spi_bind_emul()so the two stay consistent.Of course.
Quoted 9 lines
include/spi_flash.h struct sandbox_state; · line 136
Quoted 5 lines
include/spi_flash.h +1
-1@@ -136,7 +136,7 @@ struct sandbox_state; -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs); +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs);If this is now a generic SPI helper, it should be declared in
include/spi.hnext tosandbox_spi_get_emul(), not inspi_flash.hunderDM_SPI_FLASH.Indeed, move this in v3
Thanks!
bye,
HeikoQuoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v2 4/5] sandbox: spi: let a slave point at the emulation it needs
Hello Simon,
Quoted 96 lines · Heiko Schocher
Hi Simon,
Quoted 85 lines · Heiko Schocher
Hello Simon,
Quoted 25 lines · Simon Glass
Hi Heiko,
Quoted 21 lines · Heiko Schocher
sandbox: spi: let a slave point at the emulation it needs
sandbox_sf_bind_emul()binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename
sandbox_sf_unbind_emul()tosandbox_spi_unbind_emul()while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/spi/sandbox.c| 65 ++++++++++++++++++++++++++++++++++++++--------- include/spi_flash.h | 2 +-
test/dm/sf.c | 4 +--
test/dm/spi.c | 10 ++++----4 files changed, 61 insertions(+), 20 deletions(-)Quoted 16 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 522
Quoted 7 lines
drivers/mtd/spi/sandbox.c +2
-2@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { #ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, - struct udevice *bus, ofnode node, const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave The generic part (following the sandbox,emul phandle) now lives in the SPI NOR emulator, inside #ifdef
CONFIG_SPI_FLASH, as does the only non-weaksandbox_spi_get_emul(). So emulating an SRAM, or anything else that is not flash, needsSPI_FLASHandSPI_FLASH_SANDBOXenabled. Please can you move the phandle lookup andsandbox_spi_get_emul()intodrivers/spi/sandbox_spi.c, replacing the__weakversion? The flash emulator can then supply just the fallback for nodes with no sandbox,emul property.I add this in a v3.
Quoted 12 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 528
Quoted 11 lines
drivers/mtd/spi/sandbox.c +9
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { + if (!ofnode_parse_phandle_with_args(node, "sandbox,emul", NULL, 0, 0, + &args)) { + ret = lists_bind_fdt(bus, args.node, emulp, NULL, false); + if (ret) + printf("Cannot bind emulator from node '%s' (err=%d)\n", + ofnode_get_name(args.node), ret); + + return ret; + }Quoted 7 lines
lists_bind_fdt()returns 0 and sets *emulp to NULL when no driver matches the compatible, e.g. withCONFIG_SPI_RAM_SANDBOXoff. NULL is then stored in state->spi[][].emul,sandbox_spi_get_emul()succeeds, andsandbox_spi_xfer()gets-EINVALfromdevice_probe(NULL)with no hint about the cause.sandbox_spi_unbind_emul()would also pass NULL todevice_remove(). Please check for a NULL device and return-ENOENTwith a message naming the node.I add this in v3.
Quoted 15 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, + const char *spec, struct udevice **emulp)This binds a device rather than looking one up, so the name is misleading. Also, I2C and PCI do not bind on demand: their emulators are bound by the normal DT scan under an emulation parent node, then found with
uclass_get_device_by_phandle(..., "sandbox,emul", ...). If SPI did the same, you could drop thelists_bind_fdt()call, and tests would no longer need to unbind the emulator by hand before devices are destroyed. Here the emulator node is a child of the slave, so it would also be bound twice if the SRAM driver (or the MTD uclass) ever scanned its children. What do you think?Quoted 1 line
I take a look into it, but sounds correct.
I think you are right about the shape.
I will implement in v3 your other comments, and I think, that is a series of its own about the sandbox SPI infrastructure, and none of it is about the SRAM.
Quoted 5 lines
I would send it after this one, with the SRAM as the second user, and drop the manual unbind from the tests there, where the change can be seen for what it is.
If this is okay for you?
Gentle ping?
I wait with v3 because Stefan was on holiday (added to cc), as Stefan can test v3. If all work fine, I can send v3 ... currently state is without your above comment...
Thanks!
bye,
Heiko
Quoted 41 lines
Thanks!
bye,
HeikoQuoted 35 lines
Quoted 11 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 6 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, + struct udevice *bus, ofnode node, const char *spec)The unbind function is renamed because it is no longer specific to SPI NOR, but this one, which now binds any emulator too, keeps the 'sf' name. Please rename it to
sandbox_spi_bind_emul()so the two stay consistent.Of course.
Quoted 9 lines
include/spi_flash.h struct sandbox_state; · line 136
Quoted 5 lines
include/spi_flash.h +1
-1@@ -136,7 +136,7 @@ struct sandbox_state; -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs); +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs);If this is now a generic SPI helper, it should be declared in
include/spi.hnext tosandbox_spi_get_emul(), not inspi_flash.hunderDM_SPI_FLASH.Indeed, move this in v3
Thanks!
bye,
HeikoQuoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v2 4/5] sandbox: spi: let a slave point at the emulation it needs
Hi Simon,
Quoted 105 lines · Heiko Schocher
Hello Simon,
Quoted 96 lines · Heiko Schocher
Hi Simon,
Quoted 85 lines · Heiko Schocher
Hello Simon,
Quoted 25 lines · Simon Glass
Hi Heiko,
Quoted 21 lines · Heiko Schocher
sandbox: spi: let a slave point at the emulation it needs
sandbox_sf_bind_emul()binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename
sandbox_sf_unbind_emul()tosandbox_spi_unbind_emul()while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/spi/sandbox.c| 65 ++++++++++++++++++++++++++++++++++++++--------- include/spi_flash.h | 2 +-
test/dm/sf.c | 4 +--
test/dm/spi.c | 10 ++++----4 files changed, 61 insertions(+), 20 deletions(-)Quoted 16 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 522
Quoted 7 lines
drivers/mtd/spi/sandbox.c +2
-2@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { #ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, - struct udevice *bus, ofnode node, const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave The generic part (following the sandbox,emul phandle) now lives in the SPI NOR emulator, inside #ifdef
CONFIG_SPI_FLASH, as does the only non-weaksandbox_spi_get_emul(). So emulating an SRAM, or anything else that is not flash, needsSPI_FLASHandSPI_FLASH_SANDBOXenabled. Please can you move the phandle lookup andsandbox_spi_get_emul()intodrivers/spi/sandbox_spi.c, replacing the__weakversion? The flash emulator can then supply just the fallback for nodes with no sandbox,emul property.I add this in a v3.
Quoted 12 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 528
Quoted 11 lines
drivers/mtd/spi/sandbox.c +9
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { + if (!ofnode_parse_phandle_with_args(node, "sandbox,emul", NULL, 0, 0, + &args)) { + ret = lists_bind_fdt(bus, args.node, emulp, NULL, false); + if (ret) + printf("Cannot bind emulator from node '%s' (err=%d)\n", + ofnode_get_name(args.node), ret); + + return ret; + }Quoted 7 lines
lists_bind_fdt()returns 0 and sets *emulp to NULL when no driver matches the compatible, e.g. withCONFIG_SPI_RAM_SANDBOXoff. NULL is then stored in state->spi[][].emul,sandbox_spi_get_emul()succeeds, andsandbox_spi_xfer()gets-EINVALfromdevice_probe(NULL)with no hint about the cause.sandbox_spi_unbind_emul()would also pass NULL todevice_remove(). Please check for a NULL device and return-ENOENTwith a message naming the node.I add this in v3.
Quoted 15 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, + const char *spec, struct udevice **emulp)This binds a device rather than looking one up, so the name is misleading. Also, I2C and PCI do not bind on demand: their emulators are bound by the normal DT scan under an emulation parent node, then found with
uclass_get_device_by_phandle(..., "sandbox,emul", ...). If SPI did the same, you could drop thelists_bind_fdt()call, and tests would no longer need to unbind the emulator by hand before devices are destroyed. Here the emulator node is a child of the slave, so it would also be bound twice if the SRAM driver (or the MTD uclass) ever scanned its children. What do you think?Quoted 1 line
I take a look into it, but sounds correct.
I think you are right about the shape.
I will implement in v3 your other comments, and I think, that is a series of its own about the sandbox SPI infrastructure, and none of it is about the SRAM.
Quoted 5 lines
I would send it after this one, with the SRAM as the second user, and drop the manual unbind from the tests there, where the change can be seen for what it is.
If this is okay for you?
Quoted 7 lines
Gentle ping?
I wait with v3 because Stefan was on holiday (added to cc), as Stefan can test v3. If all work fine, I can send v3 ... currently state is without your above comment...
Thanks!
Sorry for the email flood... just made a rebase of the patchset to current HEAD, and I found
commit 3b748d780a37 ("sandbox: spi: Add SPI EEPROM emulator and DM test")
and it seems to me, I do not need this patch anymore, am I correct?
I try to make a rework of the patchset without this patch...
bye,
Heiko
Quoted 45 lines
bye,
HeikoQuoted 41 lines
Thanks!
bye,
HeikoQuoted 35 lines
Quoted 11 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 6 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, + struct udevice *bus, ofnode node, const char *spec)The unbind function is renamed because it is no longer specific to SPI NOR, but this one, which now binds any emulator too, keeps the 'sf' name. Please rename it to
sandbox_spi_bind_emul()so the two stay consistent.Of course.
Quoted 9 lines
include/spi_flash.h struct sandbox_state; · line 136
Quoted 5 lines
include/spi_flash.h +1
-1@@ -136,7 +136,7 @@ struct sandbox_state; -void sandbox_sf_unbind_emul (struct sandbox_state *state,int busnum,int cs); +void sandbox_spi_unbind_emul (struct sandbox_state *state,int busnum,int cs);If this is now a generic SPI helper, it should be declared in
include/spi.hnext tosandbox_spi_get_emul(), not inspi_flash.hunderDM_SPI_FLASH.Indeed, move this in v3
Thanks!
bye,
HeikoQuoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v2 4/5] sandbox: spi: let a slave point at the emulation it needs
In reply to Heiko SchocherHi Heiko,
Quoted 105 lines · Heiko Schocher
Hello Simon,
Quoted 101 lines · Heiko Schocher
Hi Simon,
Quoted 85 lines · Heiko Schocher
Hello Simon,
Quoted 25 lines · Simon Glass
Hi Heiko,
Quoted 21 lines · Heiko Schocher
sandbox: spi: let a slave point at the emulation it needs
sandbox_sf_bind_emul()binds the SPI NOR flash emulator for every slave on the sandbox SPI bus, whatever that slave is, so a device of another kind cannot be emulated and cannot be tested.As with I2C and PCI, a slave can point to an emulation node via a sandbox,emul phandle. Its compatible selects the driver. Without the property, the flash emulator remains bound to the slave node as before.
Rename
sandbox_sf_unbind_emul()tosandbox_spi_unbind_emul()while here. It is no longer specific to SPI NOR, and the old name would mislead every new caller.Signed-off-by Heiko Schocher <[email protected]>
drivers/mtd/spi/sandbox.c| 65 ++++++++++++++++++++++++++++++++++++++---------include/spi_flash.h | 2 +- test/dm/sf.c | 4 +-- test/dm/spi.c | 10 ++++---- 4 files changed, 61 insertions(+), 20 deletions(-)Quoted 16 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 522
Quoted 7 lines
drivers/mtd/spi/sandbox.c +2
-2@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = {#ifdef CONFIG_SPI_FLASH -int sandbox_sf_bind_emul (struct sandbox_state *state,int busnum,int cs, -struct udevice *bus,ofnode node,const char *spec) +/** +* sandbox_spi_emul_lookup() - bind the emulator standing in for a slave The generic part (following the sandbox,emul phandle) now lives in the SPI NOR emulator, inside #ifdef
CONFIG_SPI_FLASH, as does the only non-weaksandbox_spi_get_emul(). So emulating an SRAM, or anything else that is not flash, needsSPI_FLASHandSPI_FLASH_SANDBOXenabled. Please can you move the phandle lookup andsandbox_spi_get_emul()intodrivers/spi/sandbox_spi.c, replacing the__weakversion? The flash emulator can then supply just the fallback for nodes with no sandbox,emul property.I add this in a v3.
Quoted 12 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 528
Quoted 11 lines
drivers/mtd/spi/sandbox.c +9
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +if (!ofnode_parse_phandle_with_args (node,"sandbox,emul" ,NULL ,0 ,0 , + &args)) { + ret =lists_bind_fdt (bus, args.node, emulp,NULL , false); +if (ret) +printf ("Cannot bind emulator from node '%s' (err=%d)\n" , +ofnode_get_name (args.node), ret); + +return ret; + }Quoted 7 lines
lists_bind_fdt()returns 0 and sets *emulp to NULL when no driver matches the compatible, e.g. withCONFIG_SPI_RAM_SANDBOXoff. NULL is then stored in state->spi[][].emul,sandbox_spi_get_emul()succeeds, andsandbox_spi_xfer()gets-EINVALfromdevice_probe(NULL)with no hint about the cause.sandbox_spi_unbind_emul()would also pass NULL todevice_remove(). Please check for a NULL device and return-ENOENTwith a message naming the node.I add this in v3.
Quoted 15 lines
drivers/mtd/spi/sandbox.c static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { · line 521
Quoted 5 lines
drivers/mtd/spi/sandbox.c +2
-0@@ -518,39 +520,78 @@ static const struct dm_spi_emul_ops sandbox_sf_emul_ops = { +static int sandbox_spi_emul_lookup (struct udevice *bus,ofnode node, +const char *spec,struct udevice **emulp)This binds a device rather than looking one up, so the name is misleading. Also, I2C and PCI do not bind on demand: their emulators are bound by the normal DT scan under an emulation parent node, then found with
uclass_get_device_by_phandle(..., "sandbox,emul", ...). If SPI did the same, you could drop thelists_bind_fdt()call, and tests would no longer need to unbind the emulator by hand before devices are destroyed. Here the emulator node is a child of the slave, so it would also be bound twice if the SRAM driver (or the MTD uclass) ever scanned its children. What do you think?Quoted 1 line
I take a look into it, but sounds correct.
I think you are right about the shape.
I will implement in v3 your other comments, and I think, that is a series of its own about the sandbox SPI infrastructure, and none of it is about the SRAM.
I would send it after this one, with the SRAM as the second user, and drop the manual unbind from the tests there, where the change can be seen for what it is.
If this is okay for you?
Yes that sounds good, sorry for the late reply.
Quoted 7 lines
Gentle ping?
I wait with v3 because Stefan was on holiday (added to cc), as Stefan can test v3. If all work fine, I can send v3 ... currently state is without your above comment...
[..]
Regards,
Simon
PATCH v2 5/5 test: dm: add a test for the Microchip 23LCV1024 SPI SRAM
In reply to Heiko SchocherEmulate the device on a second sandbox SPI bus and exercise the driver through the MTD layer.
The emulation implements byte, page and sequential operation and advances the internal address counter the way the data sheet describes for each of them. A transfer running past the 32 byte page of the device therefore only comes back unharmed once the driver has selected sequential operation, which is what its probe is for. The test asserts that mode directly as well, so a failure says which of the two went wrong.
Test also if erase returns -EOPNOTSUPP and data is not touched.
A second test gives the device two partitions in the test device tree and writes through the one whose offset is on no erase block boundary, which a device without an erase size does not have to care about.
---
checkpatch asks for a blank line after the two test functions, before the DM_TEST() that registers them. But in test/dm/ all over is without a blank line, so ignore this warning.
Changes in v2:
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.
MAINTAINERS | 2 + arch/sandbox/dts/test.dts | 37 +++++++ arch/sandbox/include/asm/test.h | 8 ++ configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 9 ++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram_sandbox.c | 190 ++++++++++++++++++++++++++++++++ drivers/spi/Kconfig | 2 +- test/dm/Makefile | 1 + test/dm/spi_ram.c | 167 ++++++++++++++++++++++++++++ 10 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/spi_ram_sandbox.c create mode 100644 test/dm/spi_ram.c
MAINTAINERS +2 -0
@@ -1653,6 +1653,8 @@ SPI RAM M: Heiko Schocher <[email protected]> S: Maintained F: drivers/mtd/spi_ram.c +F: drivers/mtd/spi_ram_sandbox.c +F: test/dm/spi_ram.c SPI-NOR M: Vignesh R <[email protected]>
arch/sandbox/dts/test.dts +37 -0
@@ -57,6 +57,7 @@ rtc0 = &rtc_0; rtc1 = &rtc_1; spi0 = "/spi@0"; + spi1 = "/spi@1"; testfdt6 = "/e-test"; testbus3 = "/some-bus"; testfdt0 = "/some-bus/c-test@0";
@@ -1644,6 +1645,42 @@ }; }; + spi@1 { + #address-cells = <1>; + #size-cells = <0>; + reg = <1 1>; + compatible = "sandbox,spi"; + + sram@0 { + #address-cells = <1>; + #size-cells = <1>; + reg = <0>; + compatible = "microchip,mchp23lcv1024"; + spi-max-frequency = <20000000>; + sandbox,emul = <&spi_ram_emul>; + + spi_ram_emul: emul { + compatible = "sandbox,spi-ram-emul"; + }; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "spi-ram-part0"; + reg = <0x0 0xa000>; + }; + + partition@a000 { + label = "spi-ram-part1"; + reg = <0xa000 0x1000>; + }; + }; + }; + }; + syscon0: syscon@0 { compatible = "sandbox,syscon0"; reg = <0x10 16>;
arch/sandbox/include/asm/test.h +8 -0
@@ -251,6 +251,14 @@ uint sandbox_spi_get_mode(struct udevice *dev);*/ uint sandbox_spi_get_wordlen (struct udevice *dev); +/** +* sandbox_spi_ram_is_sequential() - check the mode of the emulated SPI SRAM +* +* @dev: the emulation device +* Return: true if the MODE register selects sequential operation +*/ +bool sandbox_spi_ram_is_sequential (struct udevice *dev); +/** * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status *
configs/sandbox_defconfig +1 -0
@@ -261,6 +261,7 @@ CONFIG_MMC_SANDBOX=y CONFIG_MMC_SDHCI=y CONFIG_DM_MTD=y CONFIG_SPI_RAM=y +CONFIG_SPI_RAM_SANDBOX=y CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 CONFIG_SYS_NAND_USE_FLASH_BBT=y
drivers/mtd/Kconfig +9 -0
@@ -208,6 +208,15 @@ config SPI_RAM If unsure, say N +config SPI_RAM_SANDBOX + bool "Sandbox emulation of the Microchip 23LCV1024" + depends on SANDBOX && SPI_RAM + help + Emulate a 23LCV1024 on the sandbox SPI bus, so that the driver can + be exercised by the unit tests. The emulation implements all three + operating modes of the device, which is what makes it able to tell + whether the driver selects the right one. + config RENESAS_RPC_HF bool "Renesas R-Car Gen3 RPC HyperFlash driver" depends on RCAR_64 && DM_MTD
drivers/mtd/Makefile +1 -0
@@ -14,6 +14,7 @@ mtd-$(CONFIG_FLASH_CFI_LEGACY) += jedec_flash.o mtd-$(CONFIG_STM32_FLASH) += stm32_flash.o mtd-$(CONFIG_RENESAS_RPC_HF) += renesas_rpc_hf.o mtd-$(CONFIG_SPI_RAM) += spi_ram.o +mtd-$(CONFIG_SPI_RAM_SANDBOX) += spi_ram_sandbox.o mtd-$(CONFIG_HBMC_AM654) += hbmc-am654.o # U-Boot build
drivers/mtd/spi_ram_sandbox.c new file +190 -0
190 lines not on this page · raw message
drivers/spi/Kconfig +1 -1
@@ -518,7 +518,7 @@ config SANDBOX_SPI config SANDBOX_SPI_MAX_BUS int depends on SANDBOX - default 1 + default 2 config SANDBOX_SPI_MAX_CS int
test/dm/Makefile +1 -0
@@ -119,6 +119,7 @@ obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o obj-$(CONFIG_SOC_DEVICE) += soc.o obj-$(CONFIG_SOUND) += sound.o obj-$(CONFIG_DM_SPI) += spi.o +obj-$(CONFIG_SPI_RAM) += spi_ram.o obj-$(CONFIG_SPMI) += spmi.o obj-y += syscon.o obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o
test/dm/spi_ram.c new file +167 -0
167 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v2 5/5] test: dm: add a test for the Microchip 23LCV1024 SPI SRAM
Hi Heiko,
Quoted 35 lines · Heiko Schocher
test: dm: add a test for the Microchip 23LCV1024 SPI SRAM
Emulate the device on a second sandbox SPI bus and exercise the driver through the MTD layer.
The emulation implements byte, page and sequential operation and advances the internal address counter the way the data sheet describes for each of them. A transfer running past the 32 byte page of the device therefore only comes back unharmed once the driver has selected sequential operation, which is what its probe is for. The test asserts that mode directly as well, so a failure says which of the two went wrong.
Test also if erase returns
-EOPNOTSUPPand data is not touched.A second test gives the device two partitions in the test device tree and writes through the one whose offset is on no erase block boundary, which a device without an erase size does not have to care about.
Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 2 +arch/sandbox/dts/test.dts | 37 ++++++++ arch/sandbox/include/asm/test.h | 8 ++ configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 9 ++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram_sandbox.c | 190 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/Kconfig | 2 +- test/dm/Makefile | 1 + test/dm/spi_ram.c | 167 +++++++++++++++++++++++++++++++++++ 10 files changed, 417 insertions(+), 1 deletion(-)
test/dm/Makefile obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o · line 120
Quoted 1 line
test/dm/Makefile +1
-0@@ -120,6 +120,7 @@ obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o +obj-$(CONFIG_SPI_RAM) += spi_ram.o
I'm assuming that CONFIG_SPI_RAM_SANDBOX is always set for sanebox builds.
test/dm/spi_ram.c line 3
Quoted 5 lines
test/dm/spi_ram.c +3
-0@@ -0,0 +1,167 @@ + bus =dev_get_parent (dev); +ut_assertok (spi_get_bus_and_cs (dev_seq (bus),SPI_RAM_CS , &bus, &slave)); +ut_assertok (sandbox_spi_get_emul (state, bus, slave->dev, &emul));
slave->dev is just 'dev', so you can drop spi_get_bus_and_cs() and 'slave' and call sandbox_spi_get_emul(state, bus, dev, &emul) directly.
test/dm/spi_ram.c line 7
Quoted 9 lines
test/dm/spi_ram.c +7
-0@@ -0,0 +1,167 @@ +ut_assert (mtd->flags &MTD_NO_ERASE ); + instr.addr =0 ; + instr.len =SPI_RAM_OFFSET ; +ut_asserteq (-EOPNOTSUPP ,mtd_erase (mtd, &instr)); + +ut_assertok (mtd_read (mtd,SPI_RAM_OFFSET ,SPI_RAM_LEN , &retlen, dst)); +ut_asserteq_mem (src, dst,SPI_RAM_LEN );
The erase covers [0, 0x1f) but the read-back covers [0x1f, 0x83), so if the erase did touch the data, this check would not see it. Please can you erase over the written data instead, i.e. addr = SPI_RAM_OFFSET and len = SPI_RAM_LEN?
test/dm/spi_ram.c line 7
Quoted 9 lines
test/dm/spi_ram.c +7
-0@@ -0,0 +1,167 @@ +/* +* The second partition of the device in the test device tree. Its offset is +* on no erase block boundary, which a device that cannot erase does not have +* to care about. +*/ +#define SPI_RAM_PART "spi-ram-part1" +#define SPI_RAM_PART_OFFSET 0xa000
0xa000 is 8K-aligned, so contrary to the comment it does sit on a typical erase-block boundary. The test catches the divide-by-zero from patch 2 but does not show that an unaligned offset still gives a writeable partition. How about an odd offset such as 0xa001 (in test.dts too), and rewording the comment to say the device has no erase size, so the write size of 1 is the only alignment that applies?
drivers/mtd/spi_ram_sandbox.c line 4
Quoted 6 lines
drivers/mtd/spi_ram_sandbox.c +4
-0@@ -0,0 +1,190 @@ +/* +* The command and the data it carries arrive as two transfers, the first +* one holding the opcode and, for a read or a write, the address. +*/
This ties the emulation to how the driver currently splits its
transfers: a driver that sends command and data in a single BEGIN|END transfer would have its data silently dropped. The real device just sees a byte stream while CS is asserted. You could treat any bytes after the address in the first transfer as data (n starting at 0 from there), as the SPI flash emulator does, so the emulation follows the data sheet rather than the driver. What do you think?
Regards,
Simon
Re: [PATCH v2 5/5] test: dm: add a test for the Microchip 23LCV1024 SPI SRAM
Hello Simon,
Quoted 36 lines · Simon Glass
Hi Heiko,
Quoted 32 lines · Heiko Schocher
test: dm: add a test for the Microchip 23LCV1024 SPI SRAM
Emulate the device on a second sandbox SPI bus and exercise the driver through the MTD layer.
The emulation implements byte, page and sequential operation and advances the internal address counter the way the data sheet describes for each of them. A transfer running past the 32 byte page of the device therefore only comes back unharmed once the driver has selected sequential operation, which is what its probe is for. The test asserts that mode directly as well, so a failure says which of the two went wrong.
Test also if erase returns
-EOPNOTSUPPand data is not touched.A second test gives the device two partitions in the test device tree and writes through the one whose offset is on no erase block boundary, which a device without an erase size does not have to care about.
Signed-off-by Heiko Schocher <[email protected]>
MAINTAINERS| 2 +arch/sandbox/dts/test.dts | 37 ++++++++ arch/sandbox/include/asm/test.h | 8 ++ configs/sandbox_defconfig | 1 + drivers/mtd/Kconfig | 9 ++ drivers/mtd/Makefile | 1 + drivers/mtd/spi_ram_sandbox.c | 190 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/Kconfig | 2 +- test/dm/Makefile | 1 + test/dm/spi_ram.c | 167 +++++++++++++++++++++++++++++++++++ 10 files changed, 417 insertions(+), 1 deletion(-)
Quoted 5 lines
test/dm/Makefile obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o · line 120
Quoted 3 lines
test/dm/Makefile +1
-0@@ -120,6 +120,7 @@ obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o +obj-$(CONFIG_SPI_RAM) += spi_ram.oI'm assuming that
CONFIG_SPI_RAM_SANDBOXis always set for sanebox builds.
It is in sandbox_defconfig.
Quoted 10 lines
test/dm/spi_ram.c line 3
Quoted 6 lines
test/dm/spi_ram.c +3
-0@@ -0,0 +1,167 @@ + bus =dev_get_parent (dev); +ut_assertok (spi_get_bus_and_cs (dev_seq (bus),SPI_RAM_CS , &bus, &slave)); +ut_assertok (sandbox_spi_get_emul (state, bus, slave->dev, &emul));
slave->devis just 'dev', so you can dropspi_get_bus_and_cs()and 'slave' and callsandbox_spi_get_emul(state, bus, dev, &emul)directly.
will do.
Quoted 15 lines
test/dm/spi_ram.c line 7
Quoted 10 lines
test/dm/spi_ram.c +7
-0@@ -0,0 +1,167 @@ +ut_assert (mtd->flags &MTD_NO_ERASE ); + instr.addr =0 ; + instr.len =SPI_RAM_OFFSET ; +ut_asserteq (-EOPNOTSUPP ,mtd_erase (mtd, &instr)); + +ut_assertok (mtd_read (mtd,SPI_RAM_OFFSET ,SPI_RAM_LEN , &retlen, dst)); +ut_asserteq_mem (src, dst,SPI_RAM_LEN );The erase covers [0,
0x1f) but the read-back covers [0x1f,0x83), so if the erase did touch the data, this check would not see it. Please can you erase over the written data instead, i.e. addr =SPI_RAM_OFFSETand len =SPI_RAM_LEN?
Yep, will change this.
Quoted 17 lines
test/dm/spi_ram.c line 7
Quoted 10 lines
test/dm/spi_ram.c +7
-0@@ -0,0 +1,167 @@ +/* +* The second partition of the device in the test device tree. Its offset is +* on no erase block boundary, which a device that cannot erase does not have +* to care about. +*/ +#define SPI_RAM_PART "spi-ram-part1" +#define SPI_RAM_PART_OFFSET 0xa000
0xa000is 8K-aligned, so contrary to the comment it does sit on a typical erase-block boundary. The test catches the divide-by-zero from patch 2 but does not show that an unaligned offset still gives a writeable partition. How about an odd offset such as0xa001(intest.dtstoo), and rewording the comment to say the device has no erase size, so the write size of 1 is the only alignment that applies?
Yep, good idea, will add this in v3.
Quoted 15 lines
drivers/mtd/spi_ram_sandbox.c line 4
Quoted 7 lines
drivers/mtd/spi_ram_sandbox.c +4
-0@@ -0,0 +1,190 @@ +/* +* The command and the data it carries arrive as two transfers, the first +* one holding the opcode and, for a read or a write, the address. +*/ This ties the emulation to how the driver currently splits its
transfers: a driver that sends command and data in a single BEGIN|END transfer would have its data silently dropped. The real device just sees a byte stream while CS is asserted. You could treat any bytes after the address in the first transfer as data (n starting at 0 from there), as the SPI flash emulator does, so the emulation follows the data sheet rather than the driver. What do you think?
Heh, indeed.
bye,
Heiko
Quoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
A message that is not in the archive (sent off-list or not yet received): CAFLszTj+VejVp7CmsBedH6TmT9PC59H1b1CnxWyfN6is4yz=_w@mail.gmail.com
Hi Simon,
Quoted 9 lines · Simon Glass
Hi Heiko,
Quoted 2 lines · Heiko Schocher
The driver sits in
UCLASS_MTD, the way the SPI NAND driver does, so the device is reached through the mtd command.Thanks for reworking this. Moving to
UCLASS_MTDand dropping the erase makes the series much cleaner.
Thanks!
I will take a look on all your comments soon. Many thanks for your time!
bye,
Heiko
Quoted 4 lines
Regards,
Simon
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic