Lines Matching full:mtd
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
24 #include <linux/mtd/map.h>
31 * Data structure to hold the pointer to the mtd device as well
35 struct mtd_info *mtd; member
42 return fixed_size_llseek(file, offset, orig, mfi->mtd->size); in mtdchar_lseek()
50 struct mtd_info *mtd; in mtdchar_open() local
59 mtd = get_mtd_device(NULL, devnum); in mtdchar_open()
61 if (IS_ERR(mtd)) in mtdchar_open()
62 return PTR_ERR(mtd); in mtdchar_open()
64 if (mtd->type == MTD_ABSENT) { in mtdchar_open()
70 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { in mtdchar_open()
80 mfi->mtd = mtd; in mtdchar_open()
85 put_mtd_device(mtd); in mtdchar_open()
94 struct mtd_info *mtd = mfi->mtd; in mtdchar_close() local
100 mtd_sync(mtd); in mtdchar_close()
102 put_mtd_device(mtd); in mtdchar_close()
131 struct mtd_info *mtd = mfi->mtd; in mtdchar_read() local
141 if (*ppos + count > mtd->size) { in mtdchar_read()
142 if (*ppos < mtd->size) in mtdchar_read()
143 count = mtd->size - *ppos; in mtdchar_read()
151 kbuf = mtd_kmalloc_up_to(mtd, &size); in mtdchar_read()
160 ret = mtd_read_fact_prot_reg(mtd, *ppos, len, in mtdchar_read()
164 ret = mtd_read_user_prot_reg(mtd, *ppos, len, in mtdchar_read()
176 ret = mtd_read_oob(mtd, *ppos, &ops); in mtdchar_read()
181 ret = mtd_read(mtd, *ppos, len, &retlen, kbuf); in mtdchar_read()
221 struct mtd_info *mtd = mfi->mtd; in mtdchar_write() local
231 if (*ppos >= mtd->size) in mtdchar_write()
234 if (*ppos + count > mtd->size) in mtdchar_write()
235 count = mtd->size - *ppos; in mtdchar_write()
240 kbuf = mtd_kmalloc_up_to(mtd, &size); in mtdchar_write()
257 ret = mtd_write_user_prot_reg(mtd, *ppos, len, in mtdchar_write()
271 ret = mtd_write_oob(mtd, *ppos, &ops); in mtdchar_write()
277 ret = mtd_write(mtd, *ppos, len, &retlen, kbuf); in mtdchar_write()
312 struct mtd_info *mtd = mfi->mtd; in otp_select_filemode() local
317 if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) == in otp_select_filemode()
324 if (mtd_read_user_prot_reg(mtd, -1, 0, &retlen, NULL) == in otp_select_filemode()
340 static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd, in mtdchar_writeoob() argument
344 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_writeoob()
357 ops.ooboffs = start & (mtd->writesize - 1); in mtdchar_writeoob()
362 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) in mtdchar_writeoob()
369 start &= ~((uint64_t)mtd->writesize - 1); in mtdchar_writeoob()
370 ret = mtd_write_oob(mtd, start, &ops); in mtdchar_writeoob()
382 static int mtdchar_readoob(struct file *file, struct mtd_info *mtd, in mtdchar_readoob() argument
394 ops.ooboffs = start & (mtd->writesize - 1); in mtdchar_readoob()
399 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) in mtdchar_readoob()
406 start &= ~((uint64_t)mtd->writesize - 1); in mtdchar_readoob()
407 ret = mtd_read_oob(mtd, start, &ops); in mtdchar_readoob()
443 static int shrink_ecclayout(struct mtd_info *mtd, in shrink_ecclayout() argument
449 if (!mtd || !to) in shrink_ecclayout()
458 ret = mtd_ooblayout_ecc(mtd, section++, &oobregion); in shrink_ecclayout()
475 ret = mtd_ooblayout_free(mtd, i, &oobregion); in shrink_ecclayout()
491 static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to) in get_oobinfo() argument
496 if (!mtd || !to) in get_oobinfo()
505 ret = mtd_ooblayout_ecc(mtd, section++, &oobregion); in get_oobinfo()
524 ret = mtd_ooblayout_free(mtd, i, &oobregion); in get_oobinfo()
541 static int mtdchar_blkpg_ioctl(struct mtd_info *mtd, in mtdchar_blkpg_ioctl() argument
555 /* Only master mtd device must be used to add partitions */ in mtdchar_blkpg_ioctl()
556 if (mtd_is_partition(mtd)) in mtdchar_blkpg_ioctl()
562 return mtd_add_partition(mtd, p.devname, p.start, p.length); in mtdchar_blkpg_ioctl()
569 return mtd_del_partition(mtd, p.pno); in mtdchar_blkpg_ioctl()
576 static void adjust_oob_length(struct mtd_info *mtd, uint64_t start, in adjust_oob_length() argument
585 start_page = mtd_div_by_ws(start, mtd); in adjust_oob_length()
586 end_page = mtd_div_by_ws(start + ops->len - 1, mtd); in adjust_oob_length()
587 oob_per_page = mtd_oobavail(mtd, ops); in adjust_oob_length()
594 mtdchar_write_ioctl(struct mtd_info *mtd, struct mtd_write_req __user *argp) in mtdchar_write_ioctl() argument
596 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_write_ioctl()
621 if (req.start + req.len > mtd->size) in mtdchar_write_ioctl()
624 datbuf_len = min_t(size_t, req.len, mtd->erasesize); in mtdchar_write_ioctl()
631 oobbuf_len = min_t(size_t, req.ooblen, mtd->erasesize); in mtdchar_write_ioctl()
655 if (ops.len == mtd->erasesize) in mtdchar_write_ioctl()
656 ops.len -= mtd_mod_by_ws(req.start + ops.len, mtd); in mtdchar_write_ioctl()
665 adjust_oob_length(mtd, req.start, &ops); in mtdchar_write_ioctl()
673 ret = mtd_write_oob(mtd, req.start, &ops); in mtdchar_write_ioctl()
692 mtdchar_read_ioctl(struct mtd_info *mtd, struct mtd_read_req __user *argp) in mtdchar_read_ioctl() argument
694 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_read_ioctl()
727 if (req.start + req.len > mtd->size) { in mtdchar_read_ioctl()
732 datbuf_len = min_t(size_t, req.len, mtd->erasesize); in mtdchar_read_ioctl()
741 oobbuf_len = min_t(size_t, req.ooblen, mtd->erasesize); in mtdchar_read_ioctl()
768 if (ops.len == mtd->erasesize) in mtdchar_read_ioctl()
769 ops.len -= mtd_mod_by_ws(req.start + ops.len, mtd); in mtdchar_read_ioctl()
771 ret = mtd_read_oob(mtd, (loff_t)req.start, &ops); in mtdchar_read_ioctl()
825 struct mtd_info *mtd = mfi->mtd; in mtdchar_ioctl() local
826 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_ioctl()
879 if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int))) in mtdchar_ioctl()
892 if (ur_idx >= mtd->numeraseregions) in mtdchar_ioctl()
895 kr = &(mtd->eraseregions[ur_idx]); in mtdchar_ioctl()
907 info.type = mtd->type; in mtdchar_ioctl()
908 info.flags = mtd->flags; in mtdchar_ioctl()
909 info.size = mtd->size; in mtdchar_ioctl()
910 info.erasesize = mtd->erasesize; in mtdchar_ioctl()
911 info.writesize = mtd->writesize; in mtdchar_ioctl()
912 info.oobsize = mtd->oobsize; in mtdchar_ioctl()
950 ret = mtd_erase(mtd, erase); in mtdchar_ioctl()
965 ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
979 ret = mtdchar_readoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
992 ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
1006 ret = mtdchar_readoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
1014 ret = mtdchar_write_ioctl(mtd, in mtdchar_ioctl()
1021 ret = mtdchar_read_ioctl(mtd, in mtdchar_ioctl()
1033 ret = mtd_lock(mtd, einfo.start, einfo.length); in mtdchar_ioctl()
1044 ret = mtd_unlock(mtd, einfo.start, einfo.length); in mtdchar_ioctl()
1055 ret = mtd_is_locked(mtd, einfo.start, einfo.length); in mtdchar_ioctl()
1067 ret = get_oobinfo(mtd, &oi); in mtdchar_ioctl()
1082 return mtd_block_isbad(mtd, offs); in mtdchar_ioctl()
1091 return mtd_block_markbad(mtd, offs); in mtdchar_ioctl()
1117 ret = mtd_get_fact_prot_info(mtd, 4096, &retlen, buf); in mtdchar_ioctl()
1120 ret = mtd_get_user_prot_info(mtd, 4096, &retlen, buf); in mtdchar_ioctl()
1149 ret = mtd_lock_user_prot_reg(mtd, oinfo.start, oinfo.length); in mtdchar_ioctl()
1151 ret = mtd_erase_user_prot_reg(mtd, oinfo.start, oinfo.length); in mtdchar_ioctl()
1167 shrink_ecclayout(mtd, usrlay); in mtdchar_ioctl()
1177 if (copy_to_user(argp, &mtd->ecc_stats, in mtdchar_ioctl()
1194 if (!mtd_has_oob(mtd)) in mtdchar_ioctl()
1216 ret = mtdchar_blkpg_ioctl(mtd, &a); in mtdchar_ioctl()
1234 struct mtd_info *mtd = mfi->mtd; in mtdchar_unlocked_ioctl() local
1235 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_unlocked_ioctl()
1260 struct mtd_info *mtd = mfi->mtd; in mtdchar_compat_ioctl() local
1261 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_compat_ioctl()
1281 ret = mtdchar_writeoob(file, mtd, buf.start, in mtdchar_compat_ioctl()
1296 ret = mtdchar_readoob(file, mtd, buf.start, in mtdchar_compat_ioctl()
1320 ret = mtdchar_blkpg_ioctl(mtd, &a); in mtdchar_compat_ioctl()
1348 struct mtd_info *mtd = mfi->mtd; in mtdchar_get_unmapped_area() local
1355 if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT)) in mtdchar_get_unmapped_area()
1359 if (offset > mtd->size - len) in mtdchar_get_unmapped_area()
1362 ret = mtd_get_unmapped_area(mtd, len, offset, flags); in mtdchar_get_unmapped_area()
1370 return mtd_mmap_capabilities(mfi->mtd); in mtdchar_mmap_capabilities()
1381 struct mtd_info *mtd = mfi->mtd; in mtdchar_mmap() local
1382 struct map_info *map = mtd->priv; in mtdchar_mmap()
1384 /* This is broken because it assumes the MTD device is map-based in mtdchar_mmap()
1385 and that mtd->priv is a valid struct map_info. It should be in mtdchar_mmap()
1388 if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { in mtdchar_mmap()
1424 "mtd", &mtd_fops); in init_mtdchar()
1426 pr_err("Can't allocate major number %d for MTD\n", in init_mtdchar()
1436 __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); in cleanup_mtdchar()