Lines Matching full:mtd
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
24 #include <linux/mtd/map.h>
33 * Data structure to hold the pointer to the mtd device as well
37 struct mtd_info *mtd; member
44 return fixed_size_llseek(file, offset, orig, mfi->mtd->size); in mtdchar_lseek()
52 struct mtd_info *mtd; in mtdchar_open() local
62 mtd = get_mtd_device(NULL, devnum); in mtdchar_open()
64 if (IS_ERR(mtd)) { in mtdchar_open()
65 ret = PTR_ERR(mtd); in mtdchar_open()
69 if (mtd->type == MTD_ABSENT) { in mtdchar_open()
75 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { in mtdchar_open()
85 mfi->mtd = mtd; in mtdchar_open()
91 put_mtd_device(mtd); in mtdchar_open()
102 struct mtd_info *mtd = mfi->mtd; in mtdchar_close() local
108 mtd_sync(mtd); in mtdchar_close()
110 put_mtd_device(mtd); in mtdchar_close()
139 struct mtd_info *mtd = mfi->mtd; in mtdchar_read() local
149 if (*ppos + count > mtd->size) { in mtdchar_read()
150 if (*ppos < mtd->size) in mtdchar_read()
151 count = mtd->size - *ppos; in mtdchar_read()
159 kbuf = mtd_kmalloc_up_to(mtd, &size); in mtdchar_read()
168 ret = mtd_read_fact_prot_reg(mtd, *ppos, len, in mtdchar_read()
172 ret = mtd_read_user_prot_reg(mtd, *ppos, len, in mtdchar_read()
184 ret = mtd_read_oob(mtd, *ppos, &ops); in mtdchar_read()
189 ret = mtd_read(mtd, *ppos, len, &retlen, kbuf); in mtdchar_read()
229 struct mtd_info *mtd = mfi->mtd; in mtdchar_write() local
239 if (*ppos >= mtd->size) in mtdchar_write()
242 if (*ppos + count > mtd->size) in mtdchar_write()
243 count = mtd->size - *ppos; in mtdchar_write()
248 kbuf = mtd_kmalloc_up_to(mtd, &size); in mtdchar_write()
265 ret = mtd_write_user_prot_reg(mtd, *ppos, len, in mtdchar_write()
279 ret = mtd_write_oob(mtd, *ppos, &ops); in mtdchar_write()
285 ret = mtd_write(mtd, *ppos, len, &retlen, kbuf); in mtdchar_write()
320 struct mtd_info *mtd = mfi->mtd; in otp_select_filemode() local
325 if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) == in otp_select_filemode()
332 if (mtd_read_user_prot_reg(mtd, -1, 0, &retlen, NULL) == in otp_select_filemode()
348 static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd, in mtdchar_writeoob() argument
352 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_writeoob()
365 ops.ooboffs = start & (mtd->writesize - 1); in mtdchar_writeoob()
370 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) in mtdchar_writeoob()
377 start &= ~((uint64_t)mtd->writesize - 1); in mtdchar_writeoob()
378 ret = mtd_write_oob(mtd, start, &ops); in mtdchar_writeoob()
390 static int mtdchar_readoob(struct file *file, struct mtd_info *mtd, in mtdchar_readoob() argument
402 ops.ooboffs = start & (mtd->writesize - 1); in mtdchar_readoob()
407 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) in mtdchar_readoob()
414 start &= ~((uint64_t)mtd->writesize - 1); in mtdchar_readoob()
415 ret = mtd_read_oob(mtd, start, &ops); in mtdchar_readoob()
451 static int shrink_ecclayout(struct mtd_info *mtd, in shrink_ecclayout() argument
457 if (!mtd || !to) in shrink_ecclayout()
466 ret = mtd_ooblayout_ecc(mtd, section++, &oobregion); in shrink_ecclayout()
483 ret = mtd_ooblayout_free(mtd, i, &oobregion); in shrink_ecclayout()
499 static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to) in get_oobinfo() argument
504 if (!mtd || !to) in get_oobinfo()
513 ret = mtd_ooblayout_ecc(mtd, section++, &oobregion); in get_oobinfo()
532 ret = mtd_ooblayout_free(mtd, i, &oobregion); in get_oobinfo()
549 static int mtdchar_blkpg_ioctl(struct mtd_info *mtd, in mtdchar_blkpg_ioctl() argument
563 /* Only master mtd device must be used to add partitions */ in mtdchar_blkpg_ioctl()
564 if (mtd_is_partition(mtd)) in mtdchar_blkpg_ioctl()
570 return mtd_add_partition(mtd, p.devname, p.start, p.length); in mtdchar_blkpg_ioctl()
577 return mtd_del_partition(mtd, p.pno); in mtdchar_blkpg_ioctl()
584 static int mtdchar_write_ioctl(struct mtd_info *mtd, in mtdchar_write_ioctl() argument
587 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_write_ioctl()
624 ret = mtd_write_oob(mtd, (loff_t)req.start, &ops); in mtdchar_write_ioctl()
635 struct mtd_info *mtd = mfi->mtd; in mtdchar_ioctl() local
636 struct mtd_info *master = mtd_get_master(mtd); in mtdchar_ioctl()
687 if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int))) in mtdchar_ioctl()
700 if (ur_idx >= mtd->numeraseregions) in mtdchar_ioctl()
703 kr = &(mtd->eraseregions[ur_idx]); in mtdchar_ioctl()
715 info.type = mtd->type; in mtdchar_ioctl()
716 info.flags = mtd->flags; in mtdchar_ioctl()
717 info.size = mtd->size; in mtdchar_ioctl()
718 info.erasesize = mtd->erasesize; in mtdchar_ioctl()
719 info.writesize = mtd->writesize; in mtdchar_ioctl()
720 info.oobsize = mtd->oobsize; in mtdchar_ioctl()
758 ret = mtd_erase(mtd, erase); in mtdchar_ioctl()
773 ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
787 ret = mtdchar_readoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
800 ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
814 ret = mtdchar_readoob(file, mtd, buf.start, buf.length, in mtdchar_ioctl()
822 ret = mtdchar_write_ioctl(mtd, in mtdchar_ioctl()
834 ret = mtd_lock(mtd, einfo.start, einfo.length); in mtdchar_ioctl()
845 ret = mtd_unlock(mtd, einfo.start, einfo.length); in mtdchar_ioctl()
856 ret = mtd_is_locked(mtd, einfo.start, einfo.length); in mtdchar_ioctl()
868 ret = get_oobinfo(mtd, &oi); in mtdchar_ioctl()
883 return mtd_block_isbad(mtd, offs); in mtdchar_ioctl()
893 return mtd_block_markbad(mtd, offs); in mtdchar_ioctl()
920 ret = mtd_get_fact_prot_info(mtd, 4096, &retlen, buf); in mtdchar_ioctl()
923 ret = mtd_get_user_prot_info(mtd, 4096, &retlen, buf); in mtdchar_ioctl()
950 ret = mtd_lock_user_prot_reg(mtd, oinfo.start, oinfo.length); in mtdchar_ioctl()
966 shrink_ecclayout(mtd, usrlay); in mtdchar_ioctl()
976 if (copy_to_user(argp, &mtd->ecc_stats, in mtdchar_ioctl()
993 if (!mtd_has_oob(mtd)) in mtdchar_ioctl()
1014 ret = mtdchar_blkpg_ioctl(mtd, &a); in mtdchar_ioctl()
1055 struct mtd_info *mtd = mfi->mtd; in mtdchar_compat_ioctl() local
1075 ret = mtdchar_writeoob(file, mtd, buf.start, in mtdchar_compat_ioctl()
1090 ret = mtdchar_readoob(file, mtd, buf.start, in mtdchar_compat_ioctl()
1114 ret = mtdchar_blkpg_ioctl(mtd, &a); in mtdchar_compat_ioctl()
1142 struct mtd_info *mtd = mfi->mtd; in mtdchar_get_unmapped_area() local
1149 if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT)) in mtdchar_get_unmapped_area()
1153 if (offset > mtd->size - len) in mtdchar_get_unmapped_area()
1156 ret = mtd_get_unmapped_area(mtd, len, offset, flags); in mtdchar_get_unmapped_area()
1164 return mtd_mmap_capabilities(mfi->mtd); in mtdchar_mmap_capabilities()
1175 struct mtd_info *mtd = mfi->mtd; in mtdchar_mmap() local
1176 struct map_info *map = mtd->priv; in mtdchar_mmap()
1178 /* This is broken because it assumes the MTD device is map-based in mtdchar_mmap()
1179 and that mtd->priv is a valid struct map_info. It should be in mtdchar_mmap()
1182 if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { in mtdchar_mmap()
1218 "mtd", &mtd_fops); in init_mtdchar()
1220 pr_err("Can't allocate major number %d for MTD\n", in init_mtdchar()
1230 __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); in cleanup_mtdchar()