hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/mtd/nand/raw/nand_amd.c
....@@ -1,25 +1,19 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2017 Free Electrons
34 * Copyright (C) 2017 NextThing Co
45 *
56 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
167 */
178
18
-#include <linux/mtd/rawnand.h>
9
+#include "internals.h"
1910
2011 static void amd_nand_decode_id(struct nand_chip *chip)
2112 {
2213 struct mtd_info *mtd = nand_to_mtd(chip);
14
+ struct nand_memory_organization *memorg;
15
+
16
+ memorg = nanddev_get_memorg(&chip->base);
2317
2418 nand_decode_ext_id(chip);
2519
....@@ -31,16 +25,24 @@
3125 */
3226 if (chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 &&
3327 chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 &&
34
- mtd->writesize == 512) {
35
- mtd->erasesize = 128 * 1024;
36
- mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1);
28
+ memorg->pagesize == 512) {
29
+ memorg->pages_per_eraseblock = 256;
30
+ memorg->pages_per_eraseblock <<= ((chip->id.data[3] & 0x03) << 1);
31
+ mtd->erasesize = memorg->pages_per_eraseblock *
32
+ memorg->pagesize;
3733 }
3834 }
3935
4036 static int amd_nand_init(struct nand_chip *chip)
4137 {
4238 if (nand_is_slc(chip))
43
- chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
39
+ /*
40
+ * According to the datasheet of some Cypress SLC NANDs,
41
+ * the bad block markers can be in the first, second or last
42
+ * page of a block. So let's check all three locations.
43
+ */
44
+ chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE |
45
+ NAND_BBM_LASTPAGE;
4446
4547 return 0;
4648 }