linux-gbmc: everspin: Add Linux < 5.11 compatibility for spi_nor_read_sr Prior to Linux 5.11, spi_nor_read_sr() was a static function defined internally in drivers/mtd/spi-nor/core.c and was not declared in core.h. When compiling everspin.c against Linux 5.10 (such as for Nuvoton platforms), calls to spi_nor_read_sr() fail due to implicit function declaration warnings treated as errors. Add a compatibility fallback implementation of spi_nor_read_sr() for LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0) using spi_mem_exec_op() when nor->spimem is valid, or nor->controller_ops->read_reg() otherwise, matching upstream 5.10 core.c behavior. Tested: Built a 5.10 platform image and ran on the platform. Verified that erase commands use nearly no CPU time even though they wait. Fusion-Link: fusion2 N/A Google-Bug-Id: 565629335 Change-Id: I13159c0c11c3c6ad4df9e5605d463bbc3649e66e Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/recipes-kernel/linux/files/linux-gbmc/drivers/mtd/spi-nor/everspin.c b/recipes-kernel/linux/files/linux-gbmc/drivers/mtd/spi-nor/everspin.c index 58afbbd..58ee9eb 100644 --- a/recipes-kernel/linux/files/linux-gbmc/drivers/mtd/spi-nor/everspin.c +++ b/recipes-kernel/linux/files/linux-gbmc/drivers/mtd/spi-nor/everspin.c
@@ -8,6 +8,25 @@ #include <linux/version.h> #include "core.h" +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0) +#include <linux/spi/spi-mem.h> + +static int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) +{ + if (nor->spimem) { + struct spi_mem_op op = + SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDSR, 1), + SPI_MEM_OP_NO_ADDR, + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_IN(1, sr, 1)); + + return spi_mem_exec_op(nor->spimem, &op); + } + + return nor->controller_ops->read_reg(nor, SPINOR_OP_RDSR, sr, 1); +} +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(5,17,0) #define SNOR_ID(a, b, c) (((a) << 16) | ((b) << 8) | (c)) #define GINFO(name, id, sec) { (name), INFO((id), 0, 64 * 1024, (sec), SECT_4K) }