diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-11-29 11:16:40 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-12-07 09:22:15 +0100 |
commit | 3139c3e9a61e70846be8c4f95bb9cffd4465d88a (patch) | |
tree | 013bdd3ba06c976020a0df6c5f856225b903d77f | |
parent | 381fd6f56e7c07369e9dd11e649eeb3e21964935 (diff) | |
download | barebox-3139c3e9a61e70846be8c4f95bb9cffd4465d88a.tar.gz barebox-3139c3e9a61e70846be8c4f95bb9cffd4465d88a.tar.xz |
mtd core: call driver write function with complete buffer
mtd->write is supposed to loop around pages internally, no need
to do this in mtd_write. This fixes a huge write performance drop
with the m25p80 driver when it was converted to a mtd driver recently.
Since mtd->writesize is 1 for this driver mtd_write ended up doing
single byte writes on the flash.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/mtd/core.c | 56 |
1 files changed, 3 insertions, 53 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 8601787286..b5916dab02 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -62,65 +62,15 @@ static ssize_t mtd_read(struct cdev *cdev, void* buf, size_t count, #define MTDPGALG(x) ((x) & ~(mtd->writesize - 1)) #ifdef CONFIG_MTD_WRITE -static int all_ff(const void *buf, int len) -{ - int i; - const uint8_t *p = buf; - - for (i = 0; i < len; i++) - if (p[i] != 0xFF) - return 0; - return 1; -} - static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count, loff_t _offset, ulong flags) { struct mtd_info *mtd = cdev->priv; - size_t retlen, now; - int ret = 0; - void *wrbuf = NULL; - size_t count = _count; - unsigned long offset = _offset; - - if (NOTALIGNED(offset)) { - printf("offset 0x%0lx not page aligned\n", offset); - return -EINVAL; - } - - dev_dbg(cdev->dev, "write: offset: 0x%08lx count: 0x%zx\n", offset, count); - while (count) { - now = count > mtd->writesize ? mtd->writesize : count; - - if (NOTALIGNED(now)) { - dev_dbg(cdev->dev, "not aligned: %d %ld\n", - mtd->writesize, - (offset % mtd->writesize)); - wrbuf = xmalloc(mtd->writesize); - memset(wrbuf, 0xff, mtd->writesize); - memcpy(wrbuf + (offset % mtd->writesize), buf, now); - if (!all_ff(wrbuf, mtd->writesize)) - ret = mtd->write(mtd, MTDPGALG(offset), - mtd->writesize, &retlen, - wrbuf); - free(wrbuf); - } else { - if (!all_ff(buf, mtd->writesize)) - ret = mtd->write(mtd, offset, now, &retlen, - buf); - dev_dbg(cdev->dev, - "offset: 0x%08lx now: 0x%zx retlen: 0x%zx\n", - offset, now, retlen); - } - if (ret) - goto out; + size_t retlen; + int ret; - offset += now; - count -= now; - buf += now; - } + ret = mtd->write(mtd, _offset, _count, &retlen, buf); -out: return ret ? ret : _count; } #endif |