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 */
397 static inline struct mtd_info *mtd_get_master(struct mtd_info *mtd) in mtd_get_master() argument
399 while (mtd->parent) in mtd_get_master()
400 mtd = mtd->parent; in mtd_get_master()
402 return mtd; in mtd_get_master()
405 static inline u64 mtd_get_master_ofs(struct mtd_info *mtd, u64 ofs) in mtd_get_master_ofs() argument
407 while (mtd->parent) { in mtd_get_master_ofs()
408 ofs += mtd->part.offset; in mtd_get_master_ofs()
409 mtd = mtd->parent; in mtd_get_master_ofs()
415 static inline bool mtd_is_partition(const struct mtd_info *mtd) in mtd_is_partition() argument
417 return mtd->parent; in mtd_is_partition()
420 static inline bool mtd_has_partitions(const struct mtd_info *mtd) in mtd_has_partitions() argument
422 return !list_empty(&mtd->partitions); in mtd_has_partitions()
425 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
427 int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
430 int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
432 int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
434 int mtd_ooblayout_free(struct mtd_info *mtd, int section,
436 int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
438 int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
440 int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
441 int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
443 static inline void mtd_set_ooblayout(struct mtd_info *mtd, in mtd_set_ooblayout() argument
446 mtd->ooblayout = ooblayout; in mtd_set_ooblayout()
449 static inline void mtd_set_pairing_scheme(struct mtd_info *mtd, in mtd_set_pairing_scheme() argument
452 mtd->pairing = pairing; in mtd_set_pairing_scheme()
455 static inline void mtd_set_of_node(struct mtd_info *mtd, in mtd_set_of_node() argument
458 mtd->dev.of_node = np; in mtd_set_of_node()
459 if (!mtd->name) in mtd_set_of_node()
460 of_property_read_string(np, "label", &mtd->name); in mtd_set_of_node()
463 static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd) in mtd_get_of_node() argument
465 return dev_of_node(&mtd->dev); in mtd_get_of_node()
468 static inline u32 mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops) in mtd_oobavail() argument
470 return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize; in mtd_oobavail()
473 static inline int mtd_max_bad_blocks(struct mtd_info *mtd, in mtd_max_bad_blocks() argument
476 struct mtd_info *master = mtd_get_master(mtd); in mtd_max_bad_blocks()
481 if (mtd->size < (len + ofs) || ofs < 0) in mtd_max_bad_blocks()
484 return master->_max_bad_blocks(master, mtd_get_master_ofs(mtd, ofs), in mtd_max_bad_blocks()
488 int mtd_wunit_to_pairing_info(struct mtd_info *mtd, int wunit,
490 int mtd_pairing_info_to_wunit(struct mtd_info *mtd,
492 int mtd_pairing_groups(struct mtd_info *mtd);
493 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
494 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
496 int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
497 unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
499 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
501 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
503 int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
506 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
507 int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
509 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
511 int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
513 int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
515 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
517 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
519 int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
521 int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
524 static inline void mtd_sync(struct mtd_info *mtd) in mtd_sync() argument
526 struct mtd_info *master = mtd_get_master(mtd); in mtd_sync()
532 int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
533 int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
534 int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
535 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
536 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
537 int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
539 static inline int mtd_suspend(struct mtd_info *mtd) in mtd_suspend() argument
541 struct mtd_info *master = mtd_get_master(mtd); in mtd_suspend()
555 static inline void mtd_resume(struct mtd_info *mtd) in mtd_resume() argument
557 struct mtd_info *master = mtd_get_master(mtd); in mtd_resume()
568 static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd) in mtd_div_by_eb() argument
570 if (mtd->erasesize_shift) in mtd_div_by_eb()
571 return sz >> mtd->erasesize_shift; in mtd_div_by_eb()
572 do_div(sz, mtd->erasesize); in mtd_div_by_eb()
576 static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd) in mtd_mod_by_eb() argument
578 if (mtd->erasesize_shift) in mtd_mod_by_eb()
579 return sz & mtd->erasesize_mask; in mtd_mod_by_eb()
580 return do_div(sz, mtd->erasesize); in mtd_mod_by_eb()
586 * @mtd: the MTD device this erase request applies on
590 * @mtd->erasesize. Of course we expect @mtd->erasesize to be != 0.
592 static inline void mtd_align_erase_req(struct mtd_info *mtd, in mtd_align_erase_req() argument
597 if (WARN_ON(!mtd->erasesize)) in mtd_align_erase_req()
600 mod = mtd_mod_by_eb(req->addr, mtd); in mtd_align_erase_req()
606 mod = mtd_mod_by_eb(req->addr + req->len, mtd); in mtd_align_erase_req()
608 req->len += mtd->erasesize - mod; in mtd_align_erase_req()
611 static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd) in mtd_div_by_ws() argument
613 if (mtd->writesize_shift) in mtd_div_by_ws()
614 return sz >> mtd->writesize_shift; in mtd_div_by_ws()
615 do_div(sz, mtd->writesize); in mtd_div_by_ws()
619 static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd) in mtd_mod_by_ws() argument
621 if (mtd->writesize_shift) in mtd_mod_by_ws()
622 return sz & mtd->writesize_mask; in mtd_mod_by_ws()
623 return do_div(sz, mtd->writesize); in mtd_mod_by_ws()
626 static inline int mtd_wunit_per_eb(struct mtd_info *mtd) in mtd_wunit_per_eb() argument
628 struct mtd_info *master = mtd_get_master(mtd); in mtd_wunit_per_eb()
630 return master->erasesize / mtd->writesize; in mtd_wunit_per_eb()
633 static inline int mtd_offset_to_wunit(struct mtd_info *mtd, loff_t offs) in mtd_offset_to_wunit() argument
635 return mtd_div_by_ws(mtd_mod_by_eb(offs, mtd), mtd); in mtd_offset_to_wunit()
638 static inline loff_t mtd_wunit_to_offset(struct mtd_info *mtd, loff_t base, in mtd_wunit_to_offset() argument
641 return base + (wunit * mtd->writesize); in mtd_wunit_to_offset()
645 static inline int mtd_has_oob(const struct mtd_info *mtd) in mtd_has_oob() argument
647 struct mtd_info *master = mtd_get_master((struct mtd_info *)mtd); in mtd_has_oob()
652 static inline int mtd_type_is_nand(const struct mtd_info *mtd) in mtd_type_is_nand() argument
654 return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH; in mtd_type_is_nand()
657 static inline int mtd_can_have_bb(const struct mtd_info *mtd) in mtd_can_have_bb() argument
659 struct mtd_info *master = mtd_get_master((struct mtd_info *)mtd); in mtd_can_have_bb()
669 extern int mtd_device_parse_register(struct mtd_info *mtd,
677 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
678 extern int __get_mtd_device(struct mtd_info *mtd);
679 extern void __put_mtd_device(struct mtd_info *mtd);
681 extern void put_mtd_device(struct mtd_info *mtd);
685 void (*add)(struct mtd_info *mtd);
686 void (*remove)(struct mtd_info *mtd);
693 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
707 unsigned mtd_mmap_capabilities(struct mtd_info *mtd);