diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-04-19 20:12:56 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-02-14 10:44:41 +0100 |
commit | 1bd90ff5a11fdb79eb865173d2bf4b5e25d95679 (patch) | |
tree | 1c4cf6f095e368d0971ccb6b9bf00c3924707449 /drivers | |
parent | bdd58b17ebabf2df364f67592cda994dd932b6e6 (diff) | |
download | barebox-1bd90ff5a11fdb79eb865173d2bf4b5e25d95679.tar.gz barebox-1bd90ff5a11fdb79eb865173d2bf4b5e25d95679.tar.xz |
mtd: implement mtd_lock and mtd_unlock
Needed for NOR flashes.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/core.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index e852fb6b49..4ddf9d1bcf 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -95,6 +95,20 @@ static int mtd_op_erase(struct cdev *cdev, size_t count, loff_t offset) return 0; } + +static ssize_t mtd_op_protect(struct cdev *cdev, size_t count, loff_t offset, int prot) +{ + struct mtd_info *mtd = cdev->priv; + + if (!mtd->unlock || !mtd->lock) + return -ENOSYS; + + if (prot) + return mtd_lock(mtd, offset, count); + else + return mtd_unlock(mtd, offset, count); +} + #endif /* CONFIG_MTD_WRITE */ int mtd_ioctl(struct cdev *cdev, int request, void *buf) @@ -161,6 +175,28 @@ int mtd_ioctl(struct cdev *cdev, int request, void *buf) return ret; } +int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + if (!mtd->lock) + return -EOPNOTSUPP; + if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) + return -EINVAL; + if (!len) + return 0; + return mtd->lock(mtd, ofs, len); +} + +int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + if (!mtd->unlock) + return -EOPNOTSUPP; + if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) + return -EINVAL; + if (!len) + return 0; + return mtd->unlock(mtd, ofs, len); +} + int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) { if (!mtd->block_isbad) @@ -206,6 +242,7 @@ static struct file_operations mtd_ops = { #ifdef CONFIG_MTD_WRITE .write = mtd_op_write, .erase = mtd_op_erase, + .protect = mtd_op_protect, #endif .ioctl = mtd_ioctl, .lseek = dev_lseek_default, |