Add Broadcom / Netgear changes from RAXE 1.0.0.48
[project/bcm63xx/u-boot.git] / include / linux / mtd / nand.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright 2017 - Free Electrons
4 *
5 * Authors:
6 * Boris Brezillon <boris.brezillon@free-electrons.com>
7 * Peter Pan <peterpandong@micron.com>
8 */
9
10 #ifndef __LINUX_MTD_NAND_H
11 #define __LINUX_MTD_NAND_H
12
13 #include <linux/mtd/mtd.h>
14 #include <linux/bitops.h>
15
16 /**
17 * struct nand_memory_organization - Memory organization structure
18 * @bits_per_cell: number of bits per NAND cell
19 * @pagesize: page size
20 * @oobsize: OOB area size
21 * @pages_per_eraseblock: number of pages per eraseblock
22 * @eraseblocks_per_lun: number of eraseblocks per LUN (Logical Unit Number)
23 * @planes_per_lun: number of planes per LUN
24 * @luns_per_target: number of LUN per target (target is a synonym for die)
25 * @ntargets: total number of targets exposed by the NAND device
26 */
27 struct nand_memory_organization {
28 unsigned int bits_per_cell;
29 unsigned int pagesize;
30 unsigned int oobsize;
31 unsigned int pages_per_eraseblock;
32 unsigned int eraseblocks_per_lun;
33 unsigned int planes_per_lun;
34 unsigned int luns_per_target;
35 unsigned int ntargets;
36 };
37
38 #define NAND_MEMORG(bpc, ps, os, ppe, epl, ppl, lpt, nt) \
39 { \
40 .bits_per_cell = (bpc), \
41 .pagesize = (ps), \
42 .oobsize = (os), \
43 .pages_per_eraseblock = (ppe), \
44 .eraseblocks_per_lun = (epl), \
45 .planes_per_lun = (ppl), \
46 .luns_per_target = (lpt), \
47 .ntargets = (nt), \
48 }
49
50 /**
51 * struct nand_row_converter - Information needed to convert an absolute offset
52 * into a row address
53 * @lun_addr_shift: position of the LUN identifier in the row address
54 * @eraseblock_addr_shift: position of the eraseblock identifier in the row
55 * address
56 */
57 struct nand_row_converter {
58 unsigned int lun_addr_shift;
59 unsigned int eraseblock_addr_shift;
60 };
61
62 /**
63 * struct nand_pos - NAND position object
64 * @target: the NAND target/die
65 * @lun: the LUN identifier
66 * @plane: the plane within the LUN
67 * @eraseblock: the eraseblock within the LUN
68 * @page: the page within the LUN
69 *
70 * These information are usually used by specific sub-layers to select the
71 * appropriate target/die and generate a row address to pass to the device.
72 */
73 struct nand_pos {
74 unsigned int target;
75 unsigned int lun;
76 unsigned int plane;
77 unsigned int eraseblock;
78 unsigned int page;
79 };
80
81 /**
82 * struct nand_page_io_req - NAND I/O request object
83 * @pos: the position this I/O request is targeting
84 * @dataoffs: the offset within the page
85 * @datalen: number of data bytes to read from/write to this page
86 * @databuf: buffer to store data in or get data from
87 * @ooboffs: the OOB offset within the page
88 * @ooblen: the number of OOB bytes to read from/write to this page
89 * @oobbuf: buffer to store OOB data in or get OOB data from
90 * @mode: one of the %MTD_OPS_XXX mode
91 *
92 * This object is used to pass per-page I/O requests to NAND sub-layers. This
93 * way all useful information are already formatted in a useful way and
94 * specific NAND layers can focus on translating these information into
95 * specific commands/operations.
96 */
97 struct nand_page_io_req {
98 struct nand_pos pos;
99 unsigned int dataoffs;
100 unsigned int datalen;
101 union {
102 const void *out;
103 void *in;
104 } databuf;
105 unsigned int ooboffs;
106 unsigned int ooblen;
107 union {
108 const void *out;
109 void *in;
110 } oobbuf;
111 int mode;
112 };
113
114 /**
115 * struct nand_ecc_req - NAND ECC requirements
116 * @strength: ECC strength
117 * @step_size: ECC step/block size
118 */
119 struct nand_ecc_req {
120 unsigned int strength;
121 unsigned int step_size;
122 };
123
124 #define NAND_ECCREQ(str, stp) { .strength = (str), .step_size = (stp) }
125
126 /**
127 * struct nand_bbt - bad block table object
128 * @cache: in memory BBT cache
129 */
130 struct nand_bbt {
131 unsigned long *cache;
132 };
133
134 struct nand_device;
135
136 /**
137 * struct nand_ops - NAND operations
138 * @erase: erase a specific block. No need to check if the block is bad before
139 * erasing, this has been taken care of by the generic NAND layer
140 * @markbad: mark a specific block bad. No need to check if the block is
141 * already marked bad, this has been taken care of by the generic
142 * NAND layer. This method should just write the BBM (Bad Block
143 * Marker) so that future call to struct_nand_ops->isbad() return
144 * true
145 * @isbad: check whether a block is bad or not. This method should just read
146 * the BBM and return whether the block is bad or not based on what it
147 * reads
148 *
149 * These are all low level operations that should be implemented by specialized
150 * NAND layers (SPI NAND, raw NAND, ...).
151 */
152 struct nand_ops {
153 int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
154 int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
155 bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
156 };
157
158 /**
159 * struct nand_device - NAND device
160 * @mtd: MTD instance attached to the NAND device
161 * @memorg: memory layout
162 * @eccreq: ECC requirements
163 * @rowconv: position to row address converter
164 * @bbt: bad block table info
165 * @ops: NAND operations attached to the NAND device
166 *
167 * Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
168 * should declare their own NAND object embedding a nand_device struct (that's
169 * how inheritance is done).
170 * struct_nand_device->memorg and struct_nand_device->eccreq should be filled
171 * at device detection time to reflect the NAND device
172 * capabilities/requirements. Once this is done nanddev_init() can be called.
173 * It will take care of converting NAND information into MTD ones, which means
174 * the specialized NAND layers should never manually tweak
175 * struct_nand_device->mtd except for the ->_read/write() hooks.
176 */
177 struct nand_device {
178 struct mtd_info *mtd;
179 struct nand_memory_organization memorg;
180 struct nand_ecc_req eccreq;
181 struct nand_row_converter rowconv;
182 struct nand_bbt bbt;
183 const struct nand_ops *ops;
184 };
185
186 /**
187 * struct nand_io_iter - NAND I/O iterator
188 * @req: current I/O request
189 * @oobbytes_per_page: maximum number of OOB bytes per page
190 * @dataleft: remaining number of data bytes to read/write
191 * @oobleft: remaining number of OOB bytes to read/write
192 *
193 * Can be used by specialized NAND layers to iterate over all pages covered
194 * by an MTD I/O request, which should greatly simplifies the boiler-plate
195 * code needed to read/write data from/to a NAND device.
196 */
197 struct nand_io_iter {
198 struct nand_page_io_req req;
199 unsigned int oobbytes_per_page;
200 unsigned int dataleft;
201 unsigned int oobleft;
202 };
203
204 /**
205 * mtd_to_nanddev() - Get the NAND device attached to the MTD instance
206 * @mtd: MTD instance
207 *
208 * Return: the NAND device embedding @mtd.
209 */
210 static inline struct nand_device *mtd_to_nanddev(struct mtd_info *mtd)
211 {
212 return mtd->priv;
213 }
214
215 /**
216 * nanddev_to_mtd() - Get the MTD device attached to a NAND device
217 * @nand: NAND device
218 *
219 * Return: the MTD device embedded in @nand.
220 */
221 static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand)
222 {
223 return nand->mtd;
224 }
225
226 /*
227 * nanddev_bits_per_cell() - Get the number of bits per cell
228 * @nand: NAND device
229 *
230 * Return: the number of bits per cell.
231 */
232 static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand)
233 {
234 return nand->memorg.bits_per_cell;
235 }
236
237 /**
238 * nanddev_page_size() - Get NAND page size
239 * @nand: NAND device
240 *
241 * Return: the page size.
242 */
243 static inline size_t nanddev_page_size(const struct nand_device *nand)
244 {
245 return nand->memorg.pagesize;
246 }
247
248 /**
249 * nanddev_per_page_oobsize() - Get NAND OOB size
250 * @nand: NAND device
251 *
252 * Return: the OOB size.
253 */
254 static inline unsigned int
255 nanddev_per_page_oobsize(const struct nand_device *nand)
256 {
257 return nand->memorg.oobsize;
258 }
259
260 /**
261 * nanddev_pages_per_eraseblock() - Get the number of pages per eraseblock
262 * @nand: NAND device
263 *
264 * Return: the number of pages per eraseblock.
265 */
266 static inline unsigned int
267 nanddev_pages_per_eraseblock(const struct nand_device *nand)
268 {
269 return nand->memorg.pages_per_eraseblock;
270 }
271
272 /**
273 * nanddev_per_page_oobsize() - Get NAND erase block size
274 * @nand: NAND device
275 *
276 * Return: the eraseblock size.
277 */
278 static inline size_t nanddev_eraseblock_size(const struct nand_device *nand)
279 {
280 return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock;
281 }
282
283 /**
284 * nanddev_eraseblocks_per_lun() - Get the number of eraseblocks per LUN
285 * @nand: NAND device
286 *
287 * Return: the number of eraseblocks per LUN.
288 */
289 static inline unsigned int
290 nanddev_eraseblocks_per_lun(const struct nand_device *nand)
291 {
292 return nand->memorg.eraseblocks_per_lun;
293 }
294
295 /**
296 * nanddev_target_size() - Get the total size provided by a single target/die
297 * @nand: NAND device
298 *
299 * Return: the total size exposed by a single target/die in bytes.
300 */
301 static inline u64 nanddev_target_size(const struct nand_device *nand)
302 {
303 return (u64)nand->memorg.luns_per_target *
304 nand->memorg.eraseblocks_per_lun *
305 nand->memorg.pages_per_eraseblock *
306 nand->memorg.pagesize;
307 }
308
309 /**
310 * nanddev_ntarget() - Get the total of targets
311 * @nand: NAND device
312 *
313 * Return: the number of targets/dies exposed by @nand.
314 */
315 static inline unsigned int nanddev_ntargets(const struct nand_device *nand)
316 {
317 return nand->memorg.ntargets;
318 }
319
320 /**
321 * nanddev_neraseblocks() - Get the total number of erasablocks
322 * @nand: NAND device
323 *
324 * Return: the total number of eraseblocks exposed by @nand.
325 */
326 static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand)
327 {
328 return (u64)nand->memorg.luns_per_target *
329 nand->memorg.eraseblocks_per_lun *
330 nand->memorg.pages_per_eraseblock;
331 }
332
333 /**
334 * nanddev_size() - Get NAND size
335 * @nand: NAND device
336 *
337 * Return: the total size (in bytes) exposed by @nand.
338 */
339 static inline u64 nanddev_size(const struct nand_device *nand)
340 {
341 return nanddev_target_size(nand) * nanddev_ntargets(nand);
342 }
343
344 /**
345 * nanddev_get_memorg() - Extract memory organization info from a NAND device
346 * @nand: NAND device
347 *
348 * This can be used by the upper layer to fill the memorg info before calling
349 * nanddev_init().
350 *
351 * Return: the memorg object embedded in the NAND device.
352 */
353 static inline struct nand_memory_organization *
354 nanddev_get_memorg(struct nand_device *nand)
355 {
356 return &nand->memorg;
357 }
358
359 int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
360 struct module *owner);
361 void nanddev_cleanup(struct nand_device *nand);
362
363 /**
364 * nanddev_register() - Register a NAND device
365 * @nand: NAND device
366 *
367 * Register a NAND device.
368 * This function is just a wrapper around mtd_device_register()
369 * registering the MTD device embedded in @nand.
370 *
371 * Return: 0 in case of success, a negative error code otherwise.
372 */
373 static inline int nanddev_register(struct nand_device *nand)
374 {
375 return mtd_device_register(nand->mtd, NULL, 0);
376 }
377
378 /**
379 * nanddev_unregister() - Unregister a NAND device
380 * @nand: NAND device
381 *
382 * Unregister a NAND device.
383 * This function is just a wrapper around mtd_device_unregister()
384 * unregistering the MTD device embedded in @nand.
385 *
386 * Return: 0 in case of success, a negative error code otherwise.
387 */
388 static inline int nanddev_unregister(struct nand_device *nand)
389 {
390 return mtd_device_unregister(nand->mtd);
391 }
392
393 /**
394 * nanddev_set_of_node() - Attach a DT node to a NAND device
395 * @nand: NAND device
396 * @np: DT node
397 *
398 * Attach a DT node to a NAND device.
399 */
400 static inline void nanddev_set_of_node(struct nand_device *nand,
401 const struct device_node *np)
402 {
403 mtd_set_of_node(nand->mtd, np);
404 }
405
406 /**
407 * nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
408 * @nand: NAND device
409 *
410 * Return: the DT node attached to @nand.
411 */
412 static inline const struct device_node *nanddev_get_of_node(struct nand_device *nand)
413 {
414 return mtd_get_of_node(nand->mtd);
415 }
416
417 /**
418 * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
419 * @nand: NAND device
420 * @offs: absolute NAND offset (usually passed by the MTD layer)
421 * @pos: a NAND position object to fill in
422 *
423 * Converts @offs into a nand_pos representation.
424 *
425 * Return: the offset within the NAND page pointed by @pos.
426 */
427 static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand,
428 loff_t offs,
429 struct nand_pos *pos)
430 {
431 unsigned int pageoffs;
432 u64 tmp = offs;
433
434 pageoffs = do_div(tmp, nand->memorg.pagesize);
435 pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock);
436 pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun);
437 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun;
438 pos->lun = do_div(tmp, nand->memorg.luns_per_target);
439 pos->target = tmp;
440
441 return pageoffs;
442 }
443
444 /**
445 * nanddev_pos_cmp() - Compare two NAND positions
446 * @a: First NAND position
447 * @b: Second NAND position
448 *
449 * Compares two NAND positions.
450 *
451 * Return: -1 if @a < @b, 0 if @a == @b and 1 if @a > @b.
452 */
453 static inline int nanddev_pos_cmp(const struct nand_pos *a,
454 const struct nand_pos *b)
455 {
456 if (a->target != b->target)
457 return a->target < b->target ? -1 : 1;
458
459 if (a->lun != b->lun)
460 return a->lun < b->lun ? -1 : 1;
461
462 if (a->eraseblock != b->eraseblock)
463 return a->eraseblock < b->eraseblock ? -1 : 1;
464
465 if (a->page != b->page)
466 return a->page < b->page ? -1 : 1;
467
468 return 0;
469 }
470
471 /**
472 * nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
473 * @nand: NAND device
474 * @pos: the NAND position to convert
475 *
476 * Converts @pos NAND position into an absolute offset.
477 *
478 * Return: the absolute offset. Note that @pos points to the beginning of a
479 * page, if one wants to point to a specific offset within this page
480 * the returned offset has to be adjusted manually.
481 */
482 static inline loff_t nanddev_pos_to_offs(struct nand_device *nand,
483 const struct nand_pos *pos)
484 {
485 unsigned int npages;
486
487 npages = pos->page +
488 ((pos->eraseblock +
489 (pos->lun +
490 (pos->target * nand->memorg.luns_per_target)) *
491 nand->memorg.eraseblocks_per_lun) *
492 nand->memorg.pages_per_eraseblock);
493
494 return (loff_t)npages * nand->memorg.pagesize;
495 }
496
497 /**
498 * nanddev_pos_to_row() - Extract a row address from a NAND position
499 * @nand: NAND device
500 * @pos: the position to convert
501 *
502 * Converts a NAND position into a row address that can then be passed to the
503 * device.
504 *
505 * Return: the row address extracted from @pos.
506 */
507 static inline unsigned int nanddev_pos_to_row(struct nand_device *nand,
508 const struct nand_pos *pos)
509 {
510 return (pos->lun << nand->rowconv.lun_addr_shift) |
511 (pos->eraseblock << nand->rowconv.eraseblock_addr_shift) |
512 pos->page;
513 }
514
515 /**
516 * nanddev_pos_next_target() - Move a position to the next target/die
517 * @nand: NAND device
518 * @pos: the position to update
519 *
520 * Updates @pos to point to the start of the next target/die. Useful when you
521 * want to iterate over all targets/dies of a NAND device.
522 */
523 static inline void nanddev_pos_next_target(struct nand_device *nand,
524 struct nand_pos *pos)
525 {
526 pos->page = 0;
527 pos->plane = 0;
528 pos->eraseblock = 0;
529 pos->lun = 0;
530 pos->target++;
531 }
532
533 /**
534 * nanddev_pos_next_lun() - Move a position to the next LUN
535 * @nand: NAND device
536 * @pos: the position to update
537 *
538 * Updates @pos to point to the start of the next LUN. Useful when you want to
539 * iterate over all LUNs of a NAND device.
540 */
541 static inline void nanddev_pos_next_lun(struct nand_device *nand,
542 struct nand_pos *pos)
543 {
544 if (pos->lun >= nand->memorg.luns_per_target - 1)
545 return nanddev_pos_next_target(nand, pos);
546
547 pos->lun++;
548 pos->page = 0;
549 pos->plane = 0;
550 pos->eraseblock = 0;
551 }
552
553 /**
554 * nanddev_pos_next_eraseblock() - Move a position to the next eraseblock
555 * @nand: NAND device
556 * @pos: the position to update
557 *
558 * Updates @pos to point to the start of the next eraseblock. Useful when you
559 * want to iterate over all eraseblocks of a NAND device.
560 */
561 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand,
562 struct nand_pos *pos)
563 {
564 if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1)
565 return nanddev_pos_next_lun(nand, pos);
566
567 pos->eraseblock++;
568 pos->page = 0;
569 pos->plane = pos->eraseblock % nand->memorg.planes_per_lun;
570 }
571
572 /**
573 * nanddev_pos_next_eraseblock() - Move a position to the next page
574 * @nand: NAND device
575 * @pos: the position to update
576 *
577 * Updates @pos to point to the start of the next page. Useful when you want to
578 * iterate over all pages of a NAND device.
579 */
580 static inline void nanddev_pos_next_page(struct nand_device *nand,
581 struct nand_pos *pos)
582 {
583 if (pos->page >= nand->memorg.pages_per_eraseblock - 1)
584 return nanddev_pos_next_eraseblock(nand, pos);
585
586 pos->page++;
587 }
588
589 /**
590 * nand_io_iter_init - Initialize a NAND I/O iterator
591 * @nand: NAND device
592 * @offs: absolute offset
593 * @req: MTD request
594 * @iter: NAND I/O iterator
595 *
596 * Initializes a NAND iterator based on the information passed by the MTD
597 * layer.
598 */
599 static inline void nanddev_io_iter_init(struct nand_device *nand,
600 loff_t offs, struct mtd_oob_ops *req,
601 struct nand_io_iter *iter)
602 {
603 struct mtd_info *mtd = nanddev_to_mtd(nand);
604
605 iter->req.mode = req->mode;
606 iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos);
607 iter->req.ooboffs = req->ooboffs;
608 iter->oobbytes_per_page = mtd_oobavail(mtd, req);
609 iter->dataleft = req->len;
610 iter->oobleft = req->ooblen;
611 iter->req.databuf.in = req->datbuf;
612 iter->req.datalen = min_t(unsigned int,
613 nand->memorg.pagesize - iter->req.dataoffs,
614 iter->dataleft);
615 iter->req.oobbuf.in = req->oobbuf;
616 iter->req.ooblen = min_t(unsigned int,
617 iter->oobbytes_per_page - iter->req.ooboffs,
618 iter->oobleft);
619 }
620
621 /**
622 * nand_io_iter_next_page - Move to the next page
623 * @nand: NAND device
624 * @iter: NAND I/O iterator
625 *
626 * Updates the @iter to point to the next page.
627 */
628 static inline void nanddev_io_iter_next_page(struct nand_device *nand,
629 struct nand_io_iter *iter)
630 {
631 nanddev_pos_next_page(nand, &iter->req.pos);
632 iter->dataleft -= iter->req.datalen;
633 iter->req.databuf.in += iter->req.datalen;
634 iter->oobleft -= iter->req.ooblen;
635 iter->req.oobbuf.in += iter->req.ooblen;
636 iter->req.dataoffs = 0;
637 iter->req.ooboffs = 0;
638 iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize,
639 iter->dataleft);
640 iter->req.ooblen = min_t(unsigned int, iter->oobbytes_per_page,
641 iter->oobleft);
642 }
643
644 /**
645 * nand_io_iter_end - Should end iteration or not
646 * @nand: NAND device
647 * @iter: NAND I/O iterator
648 *
649 * Check whether @iter has reached the end of the NAND portion it was asked to
650 * iterate on or not.
651 *
652 * Return: true if @iter has reached the end of the iteration request, false
653 * otherwise.
654 */
655 static inline bool nanddev_io_iter_end(struct nand_device *nand,
656 const struct nand_io_iter *iter)
657 {
658 if (iter->dataleft || iter->oobleft)
659 return false;
660
661 return true;
662 }
663
664 /**
665 * nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
666 * request
667 * @nand: NAND device
668 * @start: start address to read/write from
669 * @req: MTD I/O request
670 * @iter: NAND I/O iterator
671 *
672 * Should be used for iterate over pages that are contained in an MTD request.
673 */
674 #define nanddev_io_for_each_page(nand, start, req, iter) \
675 for (nanddev_io_iter_init(nand, start, req, iter); \
676 !nanddev_io_iter_end(nand, iter); \
677 nanddev_io_iter_next_page(nand, iter))
678
679 bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
680 bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
681 int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos);
682 int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
683
684 /* BBT related functions */
685 enum nand_bbt_block_status {
686 NAND_BBT_BLOCK_STATUS_UNKNOWN,
687 NAND_BBT_BLOCK_GOOD,
688 NAND_BBT_BLOCK_WORN,
689 NAND_BBT_BLOCK_RESERVED,
690 NAND_BBT_BLOCK_FACTORY_BAD,
691 NAND_BBT_BLOCK_NUM_STATUS,
692 };
693
694 int nanddev_bbt_init(struct nand_device *nand);
695 void nanddev_bbt_cleanup(struct nand_device *nand);
696 int nanddev_bbt_update(struct nand_device *nand);
697 int nanddev_bbt_get_block_status(const struct nand_device *nand,
698 unsigned int entry);
699 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
700 enum nand_bbt_block_status status);
701 int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
702
703 /**
704 * nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
705 * @nand: NAND device
706 * @pos: the NAND position we want to get BBT entry for
707 *
708 * Return the BBT entry used to store information about the eraseblock pointed
709 * by @pos.
710 *
711 * Return: the BBT entry storing information about eraseblock pointed by @pos.
712 */
713 static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand,
714 const struct nand_pos *pos)
715 {
716 return pos->eraseblock +
717 ((pos->lun + (pos->target * nand->memorg.luns_per_target)) *
718 nand->memorg.eraseblocks_per_lun);
719 }
720
721 /**
722 * nanddev_bbt_is_initialized() - Check if the BBT has been initialized
723 * @nand: NAND device
724 *
725 * Return: true if the BBT has been initialized, false otherwise.
726 */
727 static inline bool nanddev_bbt_is_initialized(struct nand_device *nand)
728 {
729 return !!nand->bbt.cache;
730 }
731
732 /* MTD -> NAND helper functions. */
733 int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo);
734
735 #endif /* __LINUX_MTD_NAND_H */