Lines Matching full:nand
17 * @bits_per_cell: number of bits per NAND cell
24 * @ntargets: total number of targets exposed by the NAND device
62 * struct nand_pos - NAND position object
63 * @target: the NAND target/die
81 * struct nand_page_io_req - NAND I/O request object
91 * This object is used to pass per-page I/O requests to NAND sub-layers. This
93 * specific NAND layers can focus on translating these information into
114 * struct nand_ecc_req - NAND ECC requirements
136 * struct nand_ops - NAND operations
138 * erasing, this has been taken care of by the generic NAND layer
141 * NAND layer. This method should just write the BBM (Bad Block
149 * NAND layers (SPI NAND, raw NAND, ...).
152 int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
153 int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
154 bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
158 * struct nand_device - NAND device
159 * @mtd: MTD instance attached to the NAND device
164 * @ops: NAND operations attached to the NAND device
166 * Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
167 * should declare their own NAND object embedding a nand_device struct (that's
170 * at device detection time to reflect the NAND device
172 * It will take care of converting NAND information into MTD ones, which means
173 * the specialized NAND layers should never manually tweak
186 * struct nand_io_iter - NAND I/O iterator
192 * Can be used by specialized NAND layers to iterate over all pages covered
194 * code needed to read/write data from/to a NAND device.
204 * mtd_to_nanddev() - Get the NAND device attached to the MTD instance
207 * Return: the NAND device embedding @mtd.
215 * nanddev_to_mtd() - Get the MTD device attached to a NAND device
216 * @nand: NAND device
218 * Return: the MTD device embedded in @nand.
220 static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand) in nanddev_to_mtd() argument
222 return nand->mtd; in nanddev_to_mtd()
227 * @nand: NAND device
231 static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand) in nanddev_bits_per_cell() argument
233 return nand->memorg.bits_per_cell; in nanddev_bits_per_cell()
237 * nanddev_page_size() - Get NAND page size
238 * @nand: NAND device
242 static inline size_t nanddev_page_size(const struct nand_device *nand) in nanddev_page_size() argument
244 return nand->memorg.pagesize; in nanddev_page_size()
248 * nanddev_per_page_oobsize() - Get NAND OOB size
249 * @nand: NAND device
254 nanddev_per_page_oobsize(const struct nand_device *nand) in nanddev_per_page_oobsize() argument
256 return nand->memorg.oobsize; in nanddev_per_page_oobsize()
261 * @nand: NAND device
266 nanddev_pages_per_eraseblock(const struct nand_device *nand) in nanddev_pages_per_eraseblock() argument
268 return nand->memorg.pages_per_eraseblock; in nanddev_pages_per_eraseblock()
272 * nanddev_per_page_oobsize() - Get NAND erase block size
273 * @nand: NAND device
277 static inline size_t nanddev_eraseblock_size(const struct nand_device *nand) in nanddev_eraseblock_size() argument
279 return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock; in nanddev_eraseblock_size()
284 * @nand: NAND device
289 nanddev_eraseblocks_per_lun(const struct nand_device *nand) in nanddev_eraseblocks_per_lun() argument
291 return nand->memorg.eraseblocks_per_lun; in nanddev_eraseblocks_per_lun()
296 * @nand: NAND device
300 static inline u64 nanddev_target_size(const struct nand_device *nand) in nanddev_target_size() argument
302 return (u64)nand->memorg.luns_per_target * in nanddev_target_size()
303 nand->memorg.eraseblocks_per_lun * in nanddev_target_size()
304 nand->memorg.pages_per_eraseblock * in nanddev_target_size()
305 nand->memorg.pagesize; in nanddev_target_size()
310 * @nand: NAND device
312 * Return: the number of targets/dies exposed by @nand.
314 static inline unsigned int nanddev_ntargets(const struct nand_device *nand) in nanddev_ntargets() argument
316 return nand->memorg.ntargets; in nanddev_ntargets()
321 * @nand: NAND device
323 * Return: the total number of eraseblocks exposed by @nand.
325 static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand) in nanddev_neraseblocks() argument
327 return (u64)nand->memorg.luns_per_target * in nanddev_neraseblocks()
328 nand->memorg.eraseblocks_per_lun * in nanddev_neraseblocks()
329 nand->memorg.pages_per_eraseblock; in nanddev_neraseblocks()
333 * nanddev_size() - Get NAND size
334 * @nand: NAND device
336 * Return: the total size (in bytes) exposed by @nand.
338 static inline u64 nanddev_size(const struct nand_device *nand) in nanddev_size() argument
340 return nanddev_target_size(nand) * nanddev_ntargets(nand); in nanddev_size()
344 * nanddev_get_memorg() - Extract memory organization info from a NAND device
345 * @nand: NAND device
350 * Return: the memorg object embedded in the NAND device.
353 nanddev_get_memorg(struct nand_device *nand) in nanddev_get_memorg() argument
355 return &nand->memorg; in nanddev_get_memorg()
358 int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
360 void nanddev_cleanup(struct nand_device *nand);
363 * nanddev_register() - Register a NAND device
364 * @nand: NAND device
366 * Register a NAND device.
368 * registering the MTD device embedded in @nand.
372 static inline int nanddev_register(struct nand_device *nand) in nanddev_register() argument
374 return mtd_device_register(nand->mtd, NULL, 0); in nanddev_register()
378 * nanddev_unregister() - Unregister a NAND device
379 * @nand: NAND device
381 * Unregister a NAND device.
383 * unregistering the MTD device embedded in @nand.
387 static inline int nanddev_unregister(struct nand_device *nand) in nanddev_unregister() argument
389 return mtd_device_unregister(nand->mtd); in nanddev_unregister()
393 * nanddev_set_of_node() - Attach a DT node to a NAND device
394 * @nand: NAND device
397 * Attach a DT node to a NAND device.
399 static inline void nanddev_set_of_node(struct nand_device *nand, in nanddev_set_of_node() argument
402 mtd_set_of_node(nand->mtd, np); in nanddev_set_of_node()
406 * nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
407 * @nand: NAND device
409 * Return: the DT node attached to @nand.
411 static inline const struct device_node *nanddev_get_of_node(struct nand_device *nand) in nanddev_get_of_node() argument
413 return mtd_get_of_node(nand->mtd); in nanddev_get_of_node()
417 * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
418 * @nand: NAND device
419 * @offs: absolute NAND offset (usually passed by the MTD layer)
420 * @pos: a NAND position object to fill in
424 * Return: the offset within the NAND page pointed by @pos.
426 static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand, in nanddev_offs_to_pos() argument
433 pageoffs = do_div(tmp, nand->memorg.pagesize); in nanddev_offs_to_pos()
434 pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock); in nanddev_offs_to_pos()
435 pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun); in nanddev_offs_to_pos()
436 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_offs_to_pos()
437 pos->lun = do_div(tmp, nand->memorg.luns_per_target); in nanddev_offs_to_pos()
444 * nanddev_pos_cmp() - Compare two NAND positions
445 * @a: First NAND position
446 * @b: Second NAND position
448 * Compares two NAND positions.
471 * nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
472 * @nand: NAND device
473 * @pos: the NAND position to convert
475 * Converts @pos NAND position into an absolute offset.
481 static inline loff_t nanddev_pos_to_offs(struct nand_device *nand, in nanddev_pos_to_offs() argument
489 (pos->target * nand->memorg.luns_per_target)) * in nanddev_pos_to_offs()
490 nand->memorg.eraseblocks_per_lun) * in nanddev_pos_to_offs()
491 nand->memorg.pages_per_eraseblock); in nanddev_pos_to_offs()
493 return (loff_t)npages * nand->memorg.pagesize; in nanddev_pos_to_offs()
497 * nanddev_pos_to_row() - Extract a row address from a NAND position
498 * @nand: NAND device
501 * Converts a NAND position into a row address that can then be passed to the
506 static inline unsigned int nanddev_pos_to_row(struct nand_device *nand, in nanddev_pos_to_row() argument
509 return (pos->lun << nand->rowconv.lun_addr_shift) | in nanddev_pos_to_row()
510 (pos->eraseblock << nand->rowconv.eraseblock_addr_shift) | in nanddev_pos_to_row()
516 * @nand: NAND device
520 * want to iterate over all targets/dies of a NAND device.
522 static inline void nanddev_pos_next_target(struct nand_device *nand, in nanddev_pos_next_target() argument
534 * @nand: NAND device
538 * iterate over all LUNs of a NAND device.
540 static inline void nanddev_pos_next_lun(struct nand_device *nand, in nanddev_pos_next_lun() argument
543 if (pos->lun >= nand->memorg.luns_per_target - 1) in nanddev_pos_next_lun()
544 return nanddev_pos_next_target(nand, pos); in nanddev_pos_next_lun()
554 * @nand: NAND device
558 * want to iterate over all eraseblocks of a NAND device.
560 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand, in nanddev_pos_next_eraseblock() argument
563 if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1) in nanddev_pos_next_eraseblock()
564 return nanddev_pos_next_lun(nand, pos); in nanddev_pos_next_eraseblock()
568 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun; in nanddev_pos_next_eraseblock()
573 * @nand: NAND device
577 * iterate over all pages of a NAND device.
579 static inline void nanddev_pos_next_page(struct nand_device *nand, in nanddev_pos_next_page() argument
582 if (pos->page >= nand->memorg.pages_per_eraseblock - 1) in nanddev_pos_next_page()
583 return nanddev_pos_next_eraseblock(nand, pos); in nanddev_pos_next_page()
589 * nand_io_iter_init - Initialize a NAND I/O iterator
590 * @nand: NAND device
593 * @iter: NAND I/O iterator
595 * Initializes a NAND iterator based on the information passed by the MTD
598 static inline void nanddev_io_iter_init(struct nand_device *nand, in nanddev_io_iter_init() argument
602 struct mtd_info *mtd = nanddev_to_mtd(nand); in nanddev_io_iter_init()
605 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos); in nanddev_io_iter_init()
612 nand->memorg.pagesize - iter->req.dataoffs, in nanddev_io_iter_init()
622 * @nand: NAND device
623 * @iter: NAND I/O iterator
627 static inline void nanddev_io_iter_next_page(struct nand_device *nand, in nanddev_io_iter_next_page() argument
630 nanddev_pos_next_page(nand, &iter->req.pos); in nanddev_io_iter_next_page()
637 iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize, in nanddev_io_iter_next_page()
645 * @nand: NAND device
646 * @iter: NAND I/O iterator
648 * Check whether @iter has reached the end of the NAND portion it was asked to
654 static inline bool nanddev_io_iter_end(struct nand_device *nand, in nanddev_io_iter_end() argument
664 * nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
666 * @nand: NAND device
669 * @iter: NAND I/O iterator
673 #define nanddev_io_for_each_page(nand, start, req, iter) \ argument
674 for (nanddev_io_iter_init(nand, start, req, iter); \
675 !nanddev_io_iter_end(nand, iter); \
676 nanddev_io_iter_next_page(nand, iter))
678 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
679 bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
680 int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos);
681 int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
693 int nanddev_bbt_init(struct nand_device *nand);
694 void nanddev_bbt_cleanup(struct nand_device *nand);
695 int nanddev_bbt_update(struct nand_device *nand);
696 int nanddev_bbt_get_block_status(const struct nand_device *nand,
698 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
700 int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
703 * nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
704 * @nand: NAND device
705 * @pos: the NAND position we want to get BBT entry for
712 static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand, in nanddev_bbt_pos_to_entry() argument
716 ((pos->lun + (pos->target * nand->memorg.luns_per_target)) * in nanddev_bbt_pos_to_entry()
717 nand->memorg.eraseblocks_per_lun); in nanddev_bbt_pos_to_entry()
722 * @nand: NAND device
726 static inline bool nanddev_bbt_is_initialized(struct nand_device *nand) in nanddev_bbt_is_initialized() argument
728 return !!nand->bbt.cache; in nanddev_bbt_is_initialized()
731 /* MTD -> NAND helper functions. */