diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-07-18 15:07:42 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-07-22 16:14:16 +0200 |
commit | 69f3d6c93b814c3464dea57538b90552de14caf4 (patch) | |
tree | bc31e20986dd63a7e7fc9c29ee89fa07e16e2624 /drivers | |
parent | d15561082121015724734c9eecf7f7f25d7c95b1 (diff) | |
download | barebox-69f3d6c93b814c3464dea57538b90552de14caf4.tar.gz barebox-69f3d6c93b814c3464dea57538b90552de14caf4.tar.xz |
mtd: introduce mtd_read_oob and mtd_write_oob
Directly copied from the Kernel as of 3.11-rc1
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/core.c | 21 | ||||
-rw-r--r-- | drivers/mtd/mtdoob.c | 2 | ||||
-rw-r--r-- | drivers/mtd/mtdraw.c | 6 |
3 files changed, 25 insertions, 4 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 37f4428dc3..fc345470f2 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -327,6 +327,27 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) return mtd->erase(mtd, instr); } +int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) +{ + int ret_code; + + ops->retlen = ops->oobretlen = 0; + if (!mtd->read_oob) + return -EOPNOTSUPP; + /* + * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics + * similar to mtd->_read(), returning a non-negative integer + * representing max bitflips. In other cases, mtd->_read_oob() may + * return -EUCLEAN. In all cases, perform similar logic to mtd_read(). + */ + ret_code = mtd->read_oob(mtd, from, ops); + if (unlikely(ret_code < 0)) + return ret_code; + if (mtd->ecc_strength == 0) + return 0; /* device lacks ecc */ + return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0; +} + static struct file_operations mtd_ops = { .read = mtd_op_read, #ifdef CONFIG_MTD_WRITE diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c index 6023302b76..1e88b534ff 100644 --- a/drivers/mtd/mtdoob.c +++ b/drivers/mtd/mtdoob.c @@ -56,7 +56,7 @@ static ssize_t mtd_op_read_oob(struct cdev *cdev, void *buf, size_t count, ops.len = mtd->oobsize; offset /= mtd->oobsize; - ret = mtd->read_oob(mtd, offset * mtd->writesize, &ops); + ret = mtd_read_oob(mtd, offset * mtd->writesize, &ops); if (ret) return ret; diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c index 9948e7cb7a..1a4711e7dd 100644 --- a/drivers/mtd/mtdraw.c +++ b/drivers/mtd/mtdraw.c @@ -58,7 +58,7 @@ * - no actual mtd->write if done * A second write of 512 bytes triggers: * - copy of the 16 first bytes into writebuf - * - a mtd->write_oob() from writebuf + * - a mtd_write_oob() from writebuf * - empty writebuf * - copy the remaining 496 bytes into writebuf * => write_fill = 496, write_ofs = offset + 528 @@ -103,7 +103,7 @@ static ssize_t mtdraw_read_unaligned(struct mtd_info *mtd, void *dst, ops.len = mtd->writesize; ops.oobbuf = tmp + mtd->writesize; ops.ooblen = mtd->oobsize; - ret = mtd->read_oob(mtd, offset, &ops); + ret = mtd_read_oob(mtd, offset, &ops); if (ret) goto err; if (partial) @@ -158,7 +158,7 @@ static ssize_t mtdraw_blkwrite(struct mtd_info *mtd, const void *buf, ops.len = mtd->writesize; ops.oobbuf = (void *)buf + mtd->writesize; ops.ooblen = mtd->oobsize; - ret = mtd->write_oob(mtd, offset, &ops); + ret = mtd_write_oob(mtd, offset, &ops); if (!ret) ret = ops.retlen + ops.oobretlen; return ret; |