Re: [PATCH 4.19.y-cip 6/7] spi: spi-mem: Add a new API to support direct mapping

Pavel Machek


commit aa167f3fed0c37e0e4c707d4331d827661f46644 upstream.

Most modern SPI controllers can directly map a SPI memory (or a portion
of the SPI memory) in the CPU address space. Most of the time this
brings significant performance improvements as it automates the whole
process of sending SPI memory operations every time a new region is

This new API allows SPI memory drivers to create direct mappings and
then use them to access the memory instead of using
+ * Return: the amount of data read from the memory device or a negative error
+ * code. Note that the returned size might be smaller than @len, and the caller
+ * is responsible for calling spi_mem_dirmap_read() again when that happens.
+ */
+ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
+ u64 offs, size_t len, void *buf)
+ struct spi_controller *ctlr = desc->mem->spi->controller;
+ ssize_t ret;
+ if (desc-> != SPI_MEM_DATA_IN)
+ return -EINVAL;
+ if (!len)
+ return 0;
+ if (desc->nodirmap) {
+ ret = spi_mem_no_dirmap_read(desc, offs, len, buf);
I'd do return ... here.

+ } else if (ctlr->mem_ops && ctlr->mem_ops->dirmap_read) {
+ ret = spi_mem_access_start(desc->mem);
+ if (ret)
+ return ret;
+ ret = ctlr->mem_ops->dirmap_read(desc, offs, len, buf);
+ spi_mem_access_end(desc->mem);
and here.

+ } else {
+ ret = -ENOTSUPP;
+ }
To help with if/else nesting. spi_mem_dirmap_write could use same

Best regards,

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Join to automatically receive all group messages.