Lines Matching full:nand
19 * @bits_per_cell: number of bits per NAND cell
27 * @ntargets: total number of targets exposed by the NAND device
67 * struct nand_pos - NAND position object
68 * @target: the NAND target/die
96 * struct nand_page_io_req - NAND I/O request object
107 * This object is used to pass per-page I/O requests to NAND sub-layers. This
109 * specific NAND layers can focus on translating these information into
135 * enum nand_ecc_engine_type - NAND ECC engine type
151 * enum nand_ecc_placement - NAND ECC bytes placement
165 * enum nand_ecc_algo - NAND ECC algorithm
179 * struct nand_ecc_props - NAND ECC properties
198 /* NAND ECC misc flags */
222 * struct nand_ops - NAND operations
224 * erasing, this has been taken care of by the generic NAND layer
227 * NAND layer. This method should just write the BBM (Bad Block
235 * NAND layers (SPI NAND, raw NAND, ...).
238 int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
239 int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
240 bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
258 * @init_ctx: given a desired user configuration for the pointed NAND device,
268 int (*init_ctx)(struct nand_device *nand);
269 void (*cleanup_ctx)(struct nand_device *nand);
270 int (*prepare_io_req)(struct nand_device *nand,
272 int (*finish_io_req)(struct nand_device *nand,
277 * struct nand_ecc_engine - ECC engine abstraction for NAND devices
284 void of_get_nand_ecc_user_config(struct nand_device *nand);
285 int nand_ecc_init_ctx(struct nand_device *nand);
286 void nand_ecc_cleanup_ctx(struct nand_device *nand);
287 int nand_ecc_prepare_io_req(struct nand_device *nand,
289 int nand_ecc_finish_io_req(struct nand_device *nand,
291 bool nand_ecc_is_strong_enough(struct nand_device *nand);
296 * @requirements: ECC requirements from the NAND chip perspective
313 * struct nand_device - NAND device
314 * @mtd: MTD instance attached to the NAND device
316 * @ecc: NAND ECC object attached to the NAND device
319 * @ops: NAND operations attached to the NAND device
321 * Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
322 * should declare their own NAND object embedding a nand_device struct (that's
325 * be filled at device detection time to reflect the NAND device
327 * It will take care of converting NAND information into MTD ones, which means
328 * the specialized NAND layers should never manually tweak
341 * struct nand_io_iter - NAND I/O iterator
347 * Can be used by specialized NAND layers to iterate over all pages covered
349 * code needed to read/write data from/to a NAND device.
359 * mtd_to_nanddev() - Get the NAND device attached to the MTD instance
362 * Return: the NAND device embedding @mtd.
370 * nanddev_to_mtd() - Get the MTD device attached to a NAND device
371 * @nand: NAND device
373 * Return: the MTD device embedded in @nand.
375 static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand) in nanddev_to_mtd() argument
377 return &nand->mtd; in nanddev_to_mtd()
382 * @nand: NAND device
386 static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand) in nanddev_bits_per_cell() argument
388 return nand->memorg.bits_per_cell; in nanddev_bits_per_cell()
392 * nanddev_page_size() - Get NAND page size
393 * @nand: NAND device
397 static inline size_t nanddev_page_size(const struct nand_device *nand) in nanddev_page_size() argument
399 return nand->memorg.pagesize; in nanddev_page_size()
403 * nanddev_per_page_oobsize() - Get NAND OOB size
404 * @nand: NAND device
409 nanddev_per_page_oobsize(const struct nand_device *nand) in nanddev_per_page_oobsize() argument
411 return nand->memorg.oobsize; in nanddev_per_page_oobsize()
416 * @nand: NAND device
421 nanddev_pages_per_eraseblock(const struct nand_device *nand) in nanddev_pages_per_eraseblock() argument
423 return nand->memorg.pages_per_eraseblock; in nanddev_pages_per_eraseblock()
428 * @nand: NAND device
433 nanddev_pages_per_target(const struct nand_device *nand) in nanddev_pages_per_target() argument
435 return nand->memorg.pages_per_eraseblock * in nanddev_pages_per_target()
436 nand->memorg.eraseblocks_per_lun * in nanddev_pages_per_target()
437 nand->memorg.luns_per_target; in nanddev_pages_per_target()
441 * nanddev_per_page_oobsize() - Get NAND erase block size
442 * @nand: NAND device
446 static inline size_t nanddev_eraseblock_size(const struct nand_device *nand) in nanddev_eraseblock_size() argument
448 return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock; in nanddev_eraseblock_size()
453 * @nand: NAND device
458 nanddev_eraseblocks_per_lun(const struct nand_device *nand) in nanddev_eraseblocks_per_lun() argument
460 return nand->memorg.eraseblocks_per_lun; in nanddev_eraseblocks_per_lun()
465 * @nand: NAND device
470 nanddev_eraseblocks_per_target(const struct nand_device *nand) in nanddev_eraseblocks_per_target() argument
472 return nand->memorg.eraseblocks_per_lun * nand->memorg.luns_per_target; in nanddev_eraseblocks_per_target()
477 * @nand: NAND device
481 static inline u64 nanddev_target_size(const struct nand_device *nand) in nanddev_target_size() argument
483 return (u64)nand->memorg.luns_per_target * in nanddev_target_size()
484 nand->memorg.eraseblocks_per_lun * in nanddev_target_size()
485 nand->memorg.pages_per_eraseblock * in nanddev_target_size()
486 nand->memorg.pagesize; in nanddev_target_size()
491 * @nand: NAND device
493 * Return: the number of targets/dies exposed by @nand.
495 static inline unsigned int nanddev_ntargets(const struct nand_device *nand) in nanddev_ntargets() argument
497 return nand->memorg.ntargets; in nanddev_ntargets()
502 * @nand: NAND device
504 * Return: the total number of eraseblocks exposed by @nand.
506 static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand) in nanddev_neraseblocks() argument
508 return nand->memorg.ntargets * nand->memorg.luns_per_target * in nanddev_neraseblocks()
509 nand->memorg.eraseblocks_per_lun; in nanddev_neraseblocks()
513 * nanddev_size() - Get NAND size
514 * @nand: NAND device
516 * Return: the total size (in bytes) exposed by @nand.
518 static inline u64 nanddev_size(const struct nand_device *nand) in nanddev_size() argument
520 return nanddev_target_size(nand) * nanddev_ntargets(nand); in nanddev_size()
524 * nanddev_get_memorg() - Extract memory organization info from a NAND device
525 * @nand: NAND device
530 * Return: the memorg object embedded in the NAND device.
533 nanddev_get_memorg(struct nand_device *nand) in nanddev_get_memorg() argument
535 return &nand->memorg; in nanddev_get_memorg()
539 * nanddev_get_ecc_conf() - Extract the ECC configuration from a NAND device
540 * @nand: NAND device
543 nanddev_get_ecc_conf(struct nand_device *nand) in nanddev_get_ecc_conf() argument
545 return &nand->ecc.ctx.conf; in nanddev_get_ecc_conf()
549 * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
551 * @nand: NAND device
554 nanddev_get_ecc_requirements(struct nand_device *nand) in nanddev_get_ecc_requirements() argument
556 return &nand->ecc.requirements; in nanddev_get_ecc_requirements()
560 * nanddev_set_ecc_requirements() - Assign the ECC requirements of a NAND
562 * @nand: NAND device
566 nanddev_set_ecc_requirements(struct nand_device *nand, in nanddev_set_ecc_requirements() argument
569 nand->ecc.requirements = *reqs; in nanddev_set_ecc_requirements()
572 int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
574 void nanddev_cleanup(struct nand_device *nand);
577 * nanddev_register() - Register a NAND device
578 * @nand: NAND device
580 * Register a NAND device.
582 * registering the MTD device embedded in @nand.
586 static inline int nanddev_register(struct nand_device *nand) in nanddev_register() argument
588 return mtd_device_register(&nand->mtd, NULL, 0); in nanddev_register()
592 * nanddev_unregister() - Unregister a NAND device
593 * @nand: NAND device
595 * Unregister a NAND device.
597 * unregistering the MTD device embedded in @nand.
601 static inline int nanddev_unregister(struct nand_device *nand) in nanddev_unregister() argument
603 return mtd_device_unregister(&nand->mtd); in nanddev_unregister()
607 * nanddev_set_of_node() - Attach a DT node to a NAND device
608 * @nand: NAND device
611 * Attach a DT node to a NAND device.
613 static inline void nanddev_set_of_node(struct nand_device *nand, in nanddev_set_of_node() argument
616 mtd_set_of_node(&nand->mtd, np); in nanddev_set_of_node()
620 * nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
621 * @nand: NAND device
623 * Return: the DT node attached to @nand.
625 static inline struct device_node *nanddev_get_of_node(struct nand_device *nand) in nanddev_get_of_node() argument
627 return mtd_get_of_node(&nand->mtd); in nanddev_get_of_node()
631 * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
632 * @nand: NAND device
633 * @offs: absolute NAND offset (usually passed by the MTD layer)
634 * @pos: a NAND position object to fill in
638 * Return: the offset within the NAND page pointed by @pos.
640 static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand, in nanddev_offs_to_pos() argument
647 pageoffs = do_div(tmp, nand->memorg.pagesize); in nanddev_offs_to_pos()
648 pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock); in nanddev_offs_to_pos()
649 pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun); in nanddev_offs_to_pos()
650 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_offs_to_pos()
651 pos->lun = do_div(tmp, nand->memorg.luns_per_target); in nanddev_offs_to_pos()
658 * nanddev_pos_cmp() - Compare two NAND positions
659 * @a: First NAND position
660 * @b: Second NAND position
662 * Compares two NAND positions.
685 * nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
686 * @nand: NAND device
687 * @pos: the NAND position to convert
689 * Converts @pos NAND position into an absolute offset.
695 static inline loff_t nanddev_pos_to_offs(struct nand_device *nand, in nanddev_pos_to_offs() argument
703 (pos->target * nand->memorg.luns_per_target)) * in nanddev_pos_to_offs()
704 nand->memorg.eraseblocks_per_lun) * in nanddev_pos_to_offs()
705 nand->memorg.pages_per_eraseblock); in nanddev_pos_to_offs()
707 return (loff_t)npages * nand->memorg.pagesize; in nanddev_pos_to_offs()
711 * nanddev_pos_to_row() - Extract a row address from a NAND position
712 * @nand: NAND device
715 * Converts a NAND position into a row address that can then be passed to the
720 static inline unsigned int nanddev_pos_to_row(struct nand_device *nand, in nanddev_pos_to_row() argument
723 return (pos->lun << nand->rowconv.lun_addr_shift) | in nanddev_pos_to_row()
724 (pos->eraseblock << nand->rowconv.eraseblock_addr_shift) | in nanddev_pos_to_row()
730 * @nand: NAND device
734 * want to iterate over all targets/dies of a NAND device.
736 static inline void nanddev_pos_next_target(struct nand_device *nand, in nanddev_pos_next_target() argument
748 * @nand: NAND device
752 * iterate over all LUNs of a NAND device.
754 static inline void nanddev_pos_next_lun(struct nand_device *nand, in nanddev_pos_next_lun() argument
757 if (pos->lun >= nand->memorg.luns_per_target - 1) in nanddev_pos_next_lun()
758 return nanddev_pos_next_target(nand, pos); in nanddev_pos_next_lun()
768 * @nand: NAND device
772 * want to iterate over all eraseblocks of a NAND device.
774 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand, in nanddev_pos_next_eraseblock() argument
777 if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1) in nanddev_pos_next_eraseblock()
778 return nanddev_pos_next_lun(nand, pos); in nanddev_pos_next_eraseblock()
782 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_pos_next_eraseblock()
787 * @nand: NAND device
791 * iterate over all pages of a NAND device.
793 static inline void nanddev_pos_next_page(struct nand_device *nand, in nanddev_pos_next_page() argument
796 if (pos->page >= nand->memorg.pages_per_eraseblock - 1) in nanddev_pos_next_page()
797 return nanddev_pos_next_eraseblock(nand, pos); in nanddev_pos_next_page()
803 * nand_io_iter_init - Initialize a NAND I/O iterator
804 * @nand: NAND device
807 * @iter: NAND I/O iterator
809 * Initializes a NAND iterator based on the information passed by the MTD
812 static inline void nanddev_io_iter_init(struct nand_device *nand, in nanddev_io_iter_init() argument
817 struct mtd_info *mtd = nanddev_to_mtd(nand); in nanddev_io_iter_init()
821 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos); in nanddev_io_iter_init()
828 nand->memorg.pagesize - iter->req.dataoffs, in nanddev_io_iter_init()
838 * @nand: NAND device
839 * @iter: NAND I/O iterator
843 static inline void nanddev_io_iter_next_page(struct nand_device *nand, in nanddev_io_iter_next_page() argument
846 nanddev_pos_next_page(nand, &iter->req.pos); in nanddev_io_iter_next_page()
853 iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize, in nanddev_io_iter_next_page()
861 * @nand: NAND device
862 * @iter: NAND I/O iterator
864 * Check whether @iter has reached the end of the NAND portion it was asked to
870 static inline bool nanddev_io_iter_end(struct nand_device *nand, in nanddev_io_iter_end() argument
880 * nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
882 * @nand: NAND device
885 * @iter: NAND I/O iterator
889 #define nanddev_io_for_each_page(nand, type, start, req, iter) \ argument
890 for (nanddev_io_iter_init(nand, type, start, req, iter); \
891 !nanddev_io_iter_end(nand, iter); \
892 nanddev_io_iter_next_page(nand, iter))
894 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
895 bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
896 int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos);
897 int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
909 int nanddev_bbt_init(struct nand_device *nand);
910 void nanddev_bbt_cleanup(struct nand_device *nand);
911 int nanddev_bbt_update(struct nand_device *nand);
912 int nanddev_bbt_get_block_status(const struct nand_device *nand,
914 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
916 int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
919 * nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
920 * @nand: NAND device
921 * @pos: the NAND position we want to get BBT entry for
928 static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand, in nanddev_bbt_pos_to_entry() argument
932 ((pos->lun + (pos->target * nand->memorg.luns_per_target)) * in nanddev_bbt_pos_to_entry()
933 nand->memorg.eraseblocks_per_lun); in nanddev_bbt_pos_to_entry()
938 * @nand: NAND device
942 static inline bool nanddev_bbt_is_initialized(struct nand_device *nand) in nanddev_bbt_is_initialized() argument
944 return !!nand->bbt.cache; in nanddev_bbt_is_initialized()
947 /* MTD -> NAND helper functions. */