Lines Matching full:nand

17  * @bits_per_cell: number of bits per NAND cell
25 * @ntargets: total number of targets exposed by the NAND device
65 * struct nand_pos - NAND position object
66 * @target: the NAND target/die
84 * struct nand_page_io_req - NAND I/O request object
94 * This object is used to pass per-page I/O requests to NAND sub-layers. This
96 * specific NAND layers can focus on translating these information into
117 * struct nand_ecc_req - NAND ECC requirements
139 * struct nand_ops - NAND operations
141 * erasing, this has been taken care of by the generic NAND layer
144 * NAND layer. This method should just write the BBM (Bad Block
152 * NAND layers (SPI NAND, raw NAND, ...).
155 int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
156 int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
157 bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
161 * struct nand_device - NAND device
162 * @mtd: MTD instance attached to the NAND device
167 * @ops: NAND operations attached to the NAND device
169 * Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
170 * should declare their own NAND object embedding a nand_device struct (that's
173 * at device detection time to reflect the NAND device
175 * It will take care of converting NAND information into MTD ones, which means
176 * the specialized NAND layers should never manually tweak
189 * struct nand_io_iter - NAND I/O iterator
195 * Can be used by specialized NAND layers to iterate over all pages covered
197 * code needed to read/write data from/to a NAND device.
207 * mtd_to_nanddev() - Get the NAND device attached to the MTD instance
210 * Return: the NAND device embedding @mtd.
218 * nanddev_to_mtd() - Get the MTD device attached to a NAND device
219 * @nand: NAND device
221 * Return: the MTD device embedded in @nand.
223 static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand) in nanddev_to_mtd() argument
225 return &nand->mtd; in nanddev_to_mtd()
230 * @nand: NAND device
234 static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand) in nanddev_bits_per_cell() argument
236 return nand->memorg.bits_per_cell; in nanddev_bits_per_cell()
240 * nanddev_page_size() - Get NAND page size
241 * @nand: NAND device
245 static inline size_t nanddev_page_size(const struct nand_device *nand) in nanddev_page_size() argument
247 return nand->memorg.pagesize; in nanddev_page_size()
251 * nanddev_per_page_oobsize() - Get NAND OOB size
252 * @nand: NAND device
257 nanddev_per_page_oobsize(const struct nand_device *nand) in nanddev_per_page_oobsize() argument
259 return nand->memorg.oobsize; in nanddev_per_page_oobsize()
264 * @nand: NAND device
269 nanddev_pages_per_eraseblock(const struct nand_device *nand) in nanddev_pages_per_eraseblock() argument
271 return nand->memorg.pages_per_eraseblock; in nanddev_pages_per_eraseblock()
276 * @nand: NAND device
281 nanddev_pages_per_target(const struct nand_device *nand) in nanddev_pages_per_target() argument
283 return nand->memorg.pages_per_eraseblock * in nanddev_pages_per_target()
284 nand->memorg.eraseblocks_per_lun * in nanddev_pages_per_target()
285 nand->memorg.luns_per_target; in nanddev_pages_per_target()
289 * nanddev_per_page_oobsize() - Get NAND erase block size
290 * @nand: NAND device
294 static inline size_t nanddev_eraseblock_size(const struct nand_device *nand) in nanddev_eraseblock_size() argument
296 return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock; in nanddev_eraseblock_size()
301 * @nand: NAND device
306 nanddev_eraseblocks_per_lun(const struct nand_device *nand) in nanddev_eraseblocks_per_lun() argument
308 return nand->memorg.eraseblocks_per_lun; in nanddev_eraseblocks_per_lun()
313 * @nand: NAND device
318 nanddev_eraseblocks_per_target(const struct nand_device *nand) in nanddev_eraseblocks_per_target() argument
320 return nand->memorg.eraseblocks_per_lun * nand->memorg.luns_per_target; in nanddev_eraseblocks_per_target()
325 * @nand: NAND device
329 static inline u64 nanddev_target_size(const struct nand_device *nand) in nanddev_target_size() argument
331 return (u64)nand->memorg.luns_per_target * in nanddev_target_size()
332 nand->memorg.eraseblocks_per_lun * in nanddev_target_size()
333 nand->memorg.pages_per_eraseblock * in nanddev_target_size()
334 nand->memorg.pagesize; in nanddev_target_size()
339 * @nand: NAND device
341 * Return: the number of targets/dies exposed by @nand.
343 static inline unsigned int nanddev_ntargets(const struct nand_device *nand) in nanddev_ntargets() argument
345 return nand->memorg.ntargets; in nanddev_ntargets()
350 * @nand: NAND device
352 * Return: the total number of eraseblocks exposed by @nand.
354 static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand) in nanddev_neraseblocks() argument
356 return nand->memorg.ntargets * nand->memorg.luns_per_target * in nanddev_neraseblocks()
357 nand->memorg.eraseblocks_per_lun; in nanddev_neraseblocks()
361 * nanddev_size() - Get NAND size
362 * @nand: NAND device
364 * Return: the total size (in bytes) exposed by @nand.
366 static inline u64 nanddev_size(const struct nand_device *nand) in nanddev_size() argument
368 return nanddev_target_size(nand) * nanddev_ntargets(nand); in nanddev_size()
372 * nanddev_get_memorg() - Extract memory organization info from a NAND device
373 * @nand: NAND device
378 * Return: the memorg object embedded in the NAND device.
381 nanddev_get_memorg(struct nand_device *nand) in nanddev_get_memorg() argument
383 return &nand->memorg; in nanddev_get_memorg()
386 int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
388 void nanddev_cleanup(struct nand_device *nand);
391 * nanddev_register() - Register a NAND device
392 * @nand: NAND device
394 * Register a NAND device.
396 * registering the MTD device embedded in @nand.
400 static inline int nanddev_register(struct nand_device *nand) in nanddev_register() argument
402 return mtd_device_register(&nand->mtd, NULL, 0); in nanddev_register()
406 * nanddev_unregister() - Unregister a NAND device
407 * @nand: NAND device
409 * Unregister a NAND device.
411 * unregistering the MTD device embedded in @nand.
415 static inline int nanddev_unregister(struct nand_device *nand) in nanddev_unregister() argument
417 return mtd_device_unregister(&nand->mtd); in nanddev_unregister()
421 * nanddev_set_of_node() - Attach a DT node to a NAND device
422 * @nand: NAND device
425 * Attach a DT node to a NAND device.
427 static inline void nanddev_set_of_node(struct nand_device *nand, in nanddev_set_of_node() argument
430 mtd_set_of_node(&nand->mtd, np); in nanddev_set_of_node()
434 * nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
435 * @nand: NAND device
437 * Return: the DT node attached to @nand.
439 static inline struct device_node *nanddev_get_of_node(struct nand_device *nand) in nanddev_get_of_node() argument
441 return mtd_get_of_node(&nand->mtd); in nanddev_get_of_node()
445 * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
446 * @nand: NAND device
447 * @offs: absolute NAND offset (usually passed by the MTD layer)
448 * @pos: a NAND position object to fill in
452 * Return: the offset within the NAND page pointed by @pos.
454 static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand, in nanddev_offs_to_pos() argument
461 pageoffs = do_div(tmp, nand->memorg.pagesize); in nanddev_offs_to_pos()
462 pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock); in nanddev_offs_to_pos()
463 pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun); in nanddev_offs_to_pos()
464 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_offs_to_pos()
465 pos->lun = do_div(tmp, nand->memorg.luns_per_target); in nanddev_offs_to_pos()
472 * nanddev_pos_cmp() - Compare two NAND positions
473 * @a: First NAND position
474 * @b: Second NAND position
476 * Compares two NAND positions.
499 * nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
500 * @nand: NAND device
501 * @pos: the NAND position to convert
503 * Converts @pos NAND position into an absolute offset.
509 static inline loff_t nanddev_pos_to_offs(struct nand_device *nand, in nanddev_pos_to_offs() argument
517 (pos->target * nand->memorg.luns_per_target)) * in nanddev_pos_to_offs()
518 nand->memorg.eraseblocks_per_lun) * in nanddev_pos_to_offs()
519 nand->memorg.pages_per_eraseblock); in nanddev_pos_to_offs()
521 return (loff_t)npages * nand->memorg.pagesize; in nanddev_pos_to_offs()
525 * nanddev_pos_to_row() - Extract a row address from a NAND position
526 * @nand: NAND device
529 * Converts a NAND position into a row address that can then be passed to the
534 static inline unsigned int nanddev_pos_to_row(struct nand_device *nand, in nanddev_pos_to_row() argument
537 return (pos->lun << nand->rowconv.lun_addr_shift) | in nanddev_pos_to_row()
538 (pos->eraseblock << nand->rowconv.eraseblock_addr_shift) | in nanddev_pos_to_row()
544 * @nand: NAND device
548 * want to iterate over all targets/dies of a NAND device.
550 static inline void nanddev_pos_next_target(struct nand_device *nand, in nanddev_pos_next_target() argument
562 * @nand: NAND device
566 * iterate over all LUNs of a NAND device.
568 static inline void nanddev_pos_next_lun(struct nand_device *nand, in nanddev_pos_next_lun() argument
571 if (pos->lun >= nand->memorg.luns_per_target - 1) in nanddev_pos_next_lun()
572 return nanddev_pos_next_target(nand, pos); in nanddev_pos_next_lun()
582 * @nand: NAND device
586 * want to iterate over all eraseblocks of a NAND device.
588 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand, in nanddev_pos_next_eraseblock() argument
591 if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1) in nanddev_pos_next_eraseblock()
592 return nanddev_pos_next_lun(nand, pos); in nanddev_pos_next_eraseblock()
596 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_pos_next_eraseblock()
601 * @nand: NAND device
605 * iterate over all pages of a NAND device.
607 static inline void nanddev_pos_next_page(struct nand_device *nand, in nanddev_pos_next_page() argument
610 if (pos->page >= nand->memorg.pages_per_eraseblock - 1) in nanddev_pos_next_page()
611 return nanddev_pos_next_eraseblock(nand, pos); in nanddev_pos_next_page()
617 * nand_io_iter_init - Initialize a NAND I/O iterator
618 * @nand: NAND device
621 * @iter: NAND I/O iterator
623 * Initializes a NAND iterator based on the information passed by the MTD
626 static inline void nanddev_io_iter_init(struct nand_device *nand, in nanddev_io_iter_init() argument
630 struct mtd_info *mtd = nanddev_to_mtd(nand); in nanddev_io_iter_init()
633 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos); in nanddev_io_iter_init()
640 nand->memorg.pagesize - iter->req.dataoffs, in nanddev_io_iter_init()
650 * @nand: NAND device
651 * @iter: NAND I/O iterator
655 static inline void nanddev_io_iter_next_page(struct nand_device *nand, in nanddev_io_iter_next_page() argument
658 nanddev_pos_next_page(nand, &iter->req.pos); in nanddev_io_iter_next_page()
665 iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize, in nanddev_io_iter_next_page()
673 * @nand: NAND device
674 * @iter: NAND I/O iterator
676 * Check whether @iter has reached the end of the NAND portion it was asked to
682 static inline bool nanddev_io_iter_end(struct nand_device *nand, in nanddev_io_iter_end() argument
692 * nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
694 * @nand: NAND device
697 * @iter: NAND I/O iterator
701 #define nanddev_io_for_each_page(nand, start, req, iter) \ argument
702 for (nanddev_io_iter_init(nand, start, req, iter); \
703 !nanddev_io_iter_end(nand, iter); \
704 nanddev_io_iter_next_page(nand, iter))
706 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
707 bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
708 int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos);
709 int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
721 int nanddev_bbt_init(struct nand_device *nand);
722 void nanddev_bbt_cleanup(struct nand_device *nand);
723 int nanddev_bbt_update(struct nand_device *nand);
724 int nanddev_bbt_get_block_status(const struct nand_device *nand,
726 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
728 int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
731 * nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
732 * @nand: NAND device
733 * @pos: the NAND position we want to get BBT entry for
740 static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand, in nanddev_bbt_pos_to_entry() argument
744 ((pos->lun + (pos->target * nand->memorg.luns_per_target)) * in nanddev_bbt_pos_to_entry()
745 nand->memorg.eraseblocks_per_lun); in nanddev_bbt_pos_to_entry()
750 * @nand: NAND device
754 static inline bool nanddev_bbt_is_initialized(struct nand_device *nand) in nanddev_bbt_is_initialized() argument
756 return !!nand->bbt.cache; in nanddev_bbt_is_initialized()
759 /* MTD -> NAND helper functions. */