Lines Matching +full:nand +full:- +full:on +full:- +full:flash +full:- +full:bbt

1 // SPDX-License-Identifier: GPL-2.0
6 * Boris Brezillon <boris.brezillon@free-electrons.com>
10 #define pr_fmt(fmt) "nand-bbt: " fmt
12 #include <linux/mtd/nand.h>
18 * nanddev_bbt_init() - Initialize the BBT (Bad Block Table)
19 * @nand: NAND device
21 * Initialize the in-memory BBT.
25 int nanddev_bbt_init(struct nand_device *nand) in nanddev_bbt_init() argument
28 unsigned int nblocks = nanddev_neraseblocks(nand); in nanddev_bbt_init()
32 nand->bbt.cache = kzalloc(nwords, GFP_KERNEL); in nanddev_bbt_init()
33 if (!nand->bbt.cache) in nanddev_bbt_init()
34 return -ENOMEM; in nanddev_bbt_init()
41 * nanddev_bbt_cleanup() - Cleanup the BBT (Bad Block Table)
42 * @nand: NAND device
46 void nanddev_bbt_cleanup(struct nand_device *nand) in nanddev_bbt_cleanup() argument
48 kfree(nand->bbt.cache); in nanddev_bbt_cleanup()
53 * nanddev_bbt_update() - Update a BBT
54 * @nand: nand device
56 * Update the BBT. Currently a NOP function since on-flash bbt is not yet
61 int nanddev_bbt_update(struct nand_device *nand) in nanddev_bbt_update() argument
68 * nanddev_bbt_get_block_status() - Return the status of an eraseblock
69 * @nand: nand device
70 * @entry: the BBT entry
72 * Return: a positive number nand_bbt_block_status status or -%ERANGE if @entry
73 * is bigger than the BBT size.
75 int nanddev_bbt_get_block_status(const struct nand_device *nand, in nanddev_bbt_get_block_status() argument
79 unsigned long *pos = nand->bbt.cache + in nanddev_bbt_get_block_status()
84 if (entry >= nanddev_neraseblocks(nand)) in nanddev_bbt_get_block_status()
85 return -ERANGE; in nanddev_bbt_get_block_status()
89 status |= pos[1] << (BITS_PER_LONG - offs); in nanddev_bbt_get_block_status()
91 return status & GENMASK(bits_per_block - 1, 0); in nanddev_bbt_get_block_status()
96 * nanddev_bbt_set_block_status() - Update the status of an eraseblock in the
97 * in-memory BBT
98 * @nand: nand device
99 * @entry: the BBT entry to update
102 * Update an entry of the in-memory BBT. If you want to push the updated BBT
103 * the NAND you should call nanddev_bbt_update().
105 * Return: 0 in case of success or -%ERANGE if @entry is bigger than the BBT
108 int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry, in nanddev_bbt_set_block_status() argument
112 unsigned long *pos = nand->bbt.cache + in nanddev_bbt_set_block_status()
115 unsigned long val = status & GENMASK(bits_per_block - 1, 0); in nanddev_bbt_set_block_status()
117 if (entry >= nanddev_neraseblocks(nand)) in nanddev_bbt_set_block_status()
118 return -ERANGE; in nanddev_bbt_set_block_status()
120 pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs); in nanddev_bbt_set_block_status()
124 unsigned int rbits = bits_per_block + offs - BITS_PER_LONG; in nanddev_bbt_set_block_status()
126 pos[1] &= ~GENMASK(rbits - 1, 0); in nanddev_bbt_set_block_status()