Skip to content

Commit 776f265

Browse files
ezequielgarciacomputersforpeace
authored andcommitted
mtd: nand: pxa3xx: Add bad block handling
Add support for flash-based bad block table using Marvell's custom in-flash bad block table layout. The support is enabled a 'flash_bbt' platform data or device tree parameter. Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> Tested-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
1 parent 56704d8 commit 776f265

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Optional properties:
1515
- marvell,nand-keep-config: Set to keep the NAND controller config as set
1616
by the bootloader
1717
- num-cs: Number of chipselect lines to usw
18+
- nand-on-flash-bbt: boolean to enable on flash bbt option if
19+
not present false
1820

1921
Example:
2022

drivers/mtd/nand/pxa3xx_nand.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/slab.h>
2727
#include <linux/of.h>
2828
#include <linux/of_device.h>
29+
#include <linux/of_mtd.h>
2930

3031
#if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP)
3132
#define ARCH_HAS_DMA
@@ -241,6 +242,29 @@ static struct pxa3xx_nand_flash builtin_flash_types[] = {
241242
{ "256MiB 16-bit", 0xba20, 64, 2048, 16, 16, 2048, &timing[3] },
242243
};
243244

245+
static u8 bbt_pattern[] = {'M', 'V', 'B', 'b', 't', '0' };
246+
static u8 bbt_mirror_pattern[] = {'1', 't', 'b', 'B', 'V', 'M' };
247+
248+
static struct nand_bbt_descr bbt_main_descr = {
249+
.options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
250+
| NAND_BBT_2BIT | NAND_BBT_VERSION,
251+
.offs = 8,
252+
.len = 6,
253+
.veroffs = 14,
254+
.maxblocks = 8, /* Last 8 blocks in each chip */
255+
.pattern = bbt_pattern
256+
};
257+
258+
static struct nand_bbt_descr bbt_mirror_descr = {
259+
.options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
260+
| NAND_BBT_2BIT | NAND_BBT_VERSION,
261+
.offs = 8,
262+
.len = 6,
263+
.veroffs = 14,
264+
.maxblocks = 8, /* Last 8 blocks in each chip */
265+
.pattern = bbt_mirror_pattern
266+
};
267+
244268
/* Define a default flash type setting serve as flash detecting only */
245269
#define DEFAULT_FLASH_TYPE (&builtin_flash_types[0])
246270

@@ -1122,6 +1146,18 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
11221146

11231147
if (nand_scan_ident(mtd, 1, def))
11241148
return -ENODEV;
1149+
1150+
if (pdata->flash_bbt) {
1151+
/*
1152+
* We'll use a bad block table stored in-flash and don't
1153+
* allow writing the bad block marker to the flash.
1154+
*/
1155+
chip->bbt_options |= NAND_BBT_USE_FLASH |
1156+
NAND_BBT_NO_OOB_BBM;
1157+
chip->bbt_td = &bbt_main_descr;
1158+
chip->bbt_md = &bbt_mirror_descr;
1159+
}
1160+
11251161
/* calculate addressing information */
11261162
if (mtd->writesize >= 2048)
11271163
host->col_addr_cycles = 2;
@@ -1316,6 +1352,7 @@ static int pxa3xx_nand_probe_dt(struct platform_device *pdev)
13161352
if (of_get_property(np, "marvell,nand-keep-config", NULL))
13171353
pdata->keep_config = 1;
13181354
of_property_read_u32(np, "num-cs", &pdata->num_cs);
1355+
pdata->flash_bbt = of_get_nand_on_flash_bbt(np);
13191356

13201357
pdev->dev.platform_data = pdata;
13211358

include/linux/platform_data/mtd-nand-pxa3xx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ struct pxa3xx_nand_platform_data {
5555
/* indicate how many chip selects will be used */
5656
int num_cs;
5757

58+
/* use an flash-based bad block table */
59+
bool flash_bbt;
60+
5861
const struct mtd_partition *parts[NUM_CHIP_SELECT];
5962
unsigned int nr_parts[NUM_CHIP_SELECT];
6063

0 commit comments

Comments
 (0)