From 9a4141880ccdb22a202e11cf30e2400b86025b3c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 2 Sep 2020 22:50:24 +0200 Subject: [PATCH] mtd: allow to use non-pagewise functions If the underlying driver implements 'plain' read/write/erase fucntions, don't convert them to pagewise functions and back. Just use the old direct functions. --- drivers/mtd/mtd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/mtd/mtd.c b/drivers/mtd/mtd.c index e19c233693..e6e3338371 100644 --- a/drivers/mtd/mtd.c +++ b/drivers/mtd/mtd.c @@ -46,6 +46,10 @@ int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count) return -ENODEV; } + if (mtd->driver->read) { + return mtd->driver->read(mtd, dest, addr, count); + } + /* page size is always a power of two */ const uint32_t page_shift = bitarithm_msb(mtd->page_size); const uint32_t page_mask = mtd->page_size - 1; @@ -110,6 +114,10 @@ int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count) return -ENODEV; } + if (mtd->driver->write) { + return mtd->driver->write(mtd, src, addr, count); + } + /* page size is always a power of two */ const uint32_t page_shift = bitarithm_msb(mtd->page_size); const uint32_t page_mask = mtd->page_size - 1; @@ -174,6 +182,10 @@ int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count) return -ENODEV; } + if (mtd->driver->erase) { + mtd->driver->erase(mtd, addr, count); + } + uint32_t sector_size = mtd->pages_per_sector * mtd->page_size; if (count % sector_size) {