Lines Matching full:mtd

17 #include <mtd/mtd-abi.h>
37 uint64_t offset; /* At which this region starts, from the beginning of the MTD */
58 * Note, some MTD drivers do not allow you to write more than one OOB area at
59 * one go. If you try to do that on such an MTD device, -EINVAL will be
60 * returned. If you want to make your implementation portable on all kind of MTD
102 int (*ecc)(struct mtd_info *mtd, int section,
104 int (*free)(struct mtd_info *mtd, int section,
163 * write-unit <-> (pair + group) conversions, we ask the MTD drivers to
166 * MTD users will then be able to query these information by using the
169 * @ngroups is here to help MTD users iterating over all the pages in a
170 * given pair. This value can be retrieved by MTD users using the
178 int (*get_info)(struct mtd_info *mtd, int wunit,
180 int (*get_wunit)(struct mtd_info *mtd,
187 * struct mtd_debug_info - debugging information for an MTD device.
189 * @dfs_dir: direntry object of the MTD device debugfs directory
199 * struct mtd_part - MTD partition specific fields
201 * @node: list node used to add an MTD partition to the parent partition list
203 * @size: partition size. Should be equal to mtd->size unless
219 * struct mtd_master - MTD master specific fields
227 * properties/fields. The master is the root MTD device from the MTD partition
238 uint64_t size; // Total size of the MTD
255 * Size of the write buffer used by the MTD. MTD devices having a write
258 * buffer the MTD driver can (but doesn't have to) do 2 writesize
283 * see Documentation/ABI/testing/sysfs-class-mtd for more detail.
313 int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
314 int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
316 int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
317 int (*_read) (struct mtd_info *mtd, loff_t from, size_t len,
319 int (*_write) (struct mtd_info *mtd, loff_t to, size_t len,
321 int (*_panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
323 int (*_read_oob) (struct mtd_info *mtd, loff_t from,
325 int (*_write_oob) (struct mtd_info *mtd, loff_t to,
327 int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
329 int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
331 int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
333 int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
335 int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
337 int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
339 int (*_writev) (struct mtd_info *mtd, const struct kvec *vecs,
341 void (*_sync) (struct mtd_info *mtd);
342 int (*_lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
343 int (*_unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
344 int (*_is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
345 int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
346 int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
347 int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
348 int (*_max_bad_blocks) (struct mtd_info *mtd, loff_t ofs, size_t len);
349 int (*_suspend) (struct mtd_info *mtd);
350 void (*_resume) (struct mtd_info *mtd);
351 void (*_reboot) (struct mtd_info *mtd);
356 int (*_get_device) (struct mtd_info *mtd);
357 void (*_put_device) (struct mtd_info *mtd);
381 * Parent device from the MTD partition point of view.
383 * MTD masters do not have any parent, MTD partitions do. The parent
384 * MTD device can itself be a partition.
388 /* List of partitions attached to this MTD device */
395 static inline struct mtd_info *mtd_get_master(struct mtd_info *mtd) in mtd_get_master() argument
397 while (mtd->parent) in mtd_get_master()
398 mtd = mtd->parent; in mtd_get_master()
400 return mtd; in mtd_get_master()
403 static inline u64 mtd_get_master_ofs(struct mtd_info *mtd, u64 ofs) in mtd_get_master_ofs() argument
405 while (mtd->parent) { in mtd_get_master_ofs()
406 ofs += mtd->part.offset; in mtd_get_master_ofs()
407 mtd = mtd->parent; in mtd_get_master_ofs()
413 static inline bool mtd_is_partition(const struct mtd_info *mtd) in mtd_is_partition() argument
415 return mtd->parent; in mtd_is_partition()
418 static inline bool mtd_has_partitions(const struct mtd_info *mtd) in mtd_has_partitions() argument
420 return !list_empty(&mtd->partitions); in mtd_has_partitions()
423 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
425 int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
428 int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
430 int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
432 int mtd_ooblayout_free(struct mtd_info *mtd, int section,
434 int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
436 int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
438 int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
439 int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
441 static inline void mtd_set_ooblayout(struct mtd_info *mtd, in mtd_set_ooblayout() argument
444 mtd->ooblayout = ooblayout; in mtd_set_ooblayout()
447 static inline void mtd_set_pairing_scheme(struct mtd_info *mtd, in mtd_set_pairing_scheme() argument
450 mtd->pairing = pairing; in mtd_set_pairing_scheme()
453 static inline void mtd_set_of_node(struct mtd_info *mtd, in mtd_set_of_node() argument
456 mtd->dev.of_node = np; in mtd_set_of_node()
457 if (!mtd->name) in mtd_set_of_node()
458 of_property_read_string(np, "label", &mtd->name); in mtd_set_of_node()
461 static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd) in mtd_get_of_node() argument
463 return dev_of_node(&mtd->dev); in mtd_get_of_node()
466 static inline u32 mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops) in mtd_oobavail() argument
468 return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize; in mtd_oobavail()
471 static inline int mtd_max_bad_blocks(struct mtd_info *mtd, in mtd_max_bad_blocks() argument
474 struct mtd_info *master = mtd_get_master(mtd); in mtd_max_bad_blocks()
479 if (mtd->size < (len + ofs) || ofs < 0) in mtd_max_bad_blocks()
482 return master->_max_bad_blocks(master, mtd_get_master_ofs(mtd, ofs), in mtd_max_bad_blocks()
486 int mtd_wunit_to_pairing_info(struct mtd_info *mtd, int wunit,
488 int mtd_pairing_info_to_wunit(struct mtd_info *mtd,
490 int mtd_pairing_groups(struct mtd_info *mtd);
491 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
492 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
494 int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
495 unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
497 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
499 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
501 int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
504 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
505 int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
507 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
509 int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
511 int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
513 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
515 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
517 int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
519 int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
522 static inline void mtd_sync(struct mtd_info *mtd) in mtd_sync() argument
524 struct mtd_info *master = mtd_get_master(mtd); in mtd_sync()
530 int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
531 int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
532 int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
533 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
534 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
535 int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
537 static inline int mtd_suspend(struct mtd_info *mtd) in mtd_suspend() argument
539 struct mtd_info *master = mtd_get_master(mtd); in mtd_suspend()
553 static inline void mtd_resume(struct mtd_info *mtd) in mtd_resume() argument
555 struct mtd_info *master = mtd_get_master(mtd); in mtd_resume()
566 static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd) in mtd_div_by_eb() argument
568 if (mtd->erasesize_shift) in mtd_div_by_eb()
569 return sz >> mtd->erasesize_shift; in mtd_div_by_eb()
570 do_div(sz, mtd->erasesize); in mtd_div_by_eb()
574 static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd) in mtd_mod_by_eb() argument
576 if (mtd->erasesize_shift) in mtd_mod_by_eb()
577 return sz & mtd->erasesize_mask; in mtd_mod_by_eb()
578 return do_div(sz, mtd->erasesize); in mtd_mod_by_eb()
584 * @mtd: the MTD device this erase request applies on
588 * @mtd->erasesize. Of course we expect @mtd->erasesize to be != 0.
590 static inline void mtd_align_erase_req(struct mtd_info *mtd, in mtd_align_erase_req() argument
595 if (WARN_ON(!mtd->erasesize)) in mtd_align_erase_req()
598 mod = mtd_mod_by_eb(req->addr, mtd); in mtd_align_erase_req()
604 mod = mtd_mod_by_eb(req->addr + req->len, mtd); in mtd_align_erase_req()
606 req->len += mtd->erasesize - mod; in mtd_align_erase_req()
609 static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd) in mtd_div_by_ws() argument
611 if (mtd->writesize_shift) in mtd_div_by_ws()
612 return sz >> mtd->writesize_shift; in mtd_div_by_ws()
613 do_div(sz, mtd->writesize); in mtd_div_by_ws()
617 static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd) in mtd_mod_by_ws() argument
619 if (mtd->writesize_shift) in mtd_mod_by_ws()
620 return sz & mtd->writesize_mask; in mtd_mod_by_ws()
621 return do_div(sz, mtd->writesize); in mtd_mod_by_ws()
624 static inline int mtd_wunit_per_eb(struct mtd_info *mtd) in mtd_wunit_per_eb() argument
626 struct mtd_info *master = mtd_get_master(mtd); in mtd_wunit_per_eb()
628 return master->erasesize / mtd->writesize; in mtd_wunit_per_eb()
631 static inline int mtd_offset_to_wunit(struct mtd_info *mtd, loff_t offs) in mtd_offset_to_wunit() argument
633 return mtd_div_by_ws(mtd_mod_by_eb(offs, mtd), mtd); in mtd_offset_to_wunit()
636 static inline loff_t mtd_wunit_to_offset(struct mtd_info *mtd, loff_t base, in mtd_wunit_to_offset() argument
639 return base + (wunit * mtd->writesize); in mtd_wunit_to_offset()
643 static inline int mtd_has_oob(const struct mtd_info *mtd) in mtd_has_oob() argument
645 struct mtd_info *master = mtd_get_master((struct mtd_info *)mtd); in mtd_has_oob()
650 static inline int mtd_type_is_nand(const struct mtd_info *mtd) in mtd_type_is_nand() argument
652 return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH; in mtd_type_is_nand()
655 static inline int mtd_can_have_bb(const struct mtd_info *mtd) in mtd_can_have_bb() argument
657 struct mtd_info *master = mtd_get_master((struct mtd_info *)mtd); in mtd_can_have_bb()
667 extern int mtd_device_parse_register(struct mtd_info *mtd,
675 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
676 extern int __get_mtd_device(struct mtd_info *mtd);
677 extern void __put_mtd_device(struct mtd_info *mtd);
679 extern void put_mtd_device(struct mtd_info *mtd);
683 void (*add)(struct mtd_info *mtd);
684 void (*remove)(struct mtd_info *mtd);
691 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
705 unsigned mtd_mmap_capabilities(struct mtd_info *mtd);