forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/mtd/nand/raw/nand_samsung.c
....@@ -1,25 +1,21 @@
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 samsung_nand_decode_id(struct nand_chip *chip)
2112 {
13
+ struct nand_device *base = &chip->base;
14
+ struct nand_ecc_props requirements = {};
2215 struct mtd_info *mtd = nand_to_mtd(chip);
16
+ struct nand_memory_organization *memorg;
17
+
18
+ memorg = nanddev_get_memorg(&chip->base);
2319
2420 /* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */
2521 if (chip->id.len == 6 && !nand_is_slc(chip) &&
....@@ -27,29 +23,30 @@
2723 u8 extid = chip->id.data[3];
2824
2925 /* Get pagesize */
30
- mtd->writesize = 2048 << (extid & 0x03);
26
+ memorg->pagesize = 2048 << (extid & 0x03);
27
+ mtd->writesize = memorg->pagesize;
3128
3229 extid >>= 2;
3330
3431 /* Get oobsize */
3532 switch (((extid >> 2) & 0x4) | (extid & 0x3)) {
3633 case 1:
37
- mtd->oobsize = 128;
34
+ memorg->oobsize = 128;
3835 break;
3936 case 2:
40
- mtd->oobsize = 218;
37
+ memorg->oobsize = 218;
4138 break;
4239 case 3:
43
- mtd->oobsize = 400;
40
+ memorg->oobsize = 400;
4441 break;
4542 case 4:
46
- mtd->oobsize = 436;
43
+ memorg->oobsize = 436;
4744 break;
4845 case 5:
49
- mtd->oobsize = 512;
46
+ memorg->oobsize = 512;
5047 break;
5148 case 6:
52
- mtd->oobsize = 640;
49
+ memorg->oobsize = 640;
5350 break;
5451 default:
5552 /*
....@@ -62,31 +59,37 @@
6259 break;
6360 }
6461
62
+ mtd->oobsize = memorg->oobsize;
63
+
6564 /* Get blocksize */
6665 extid >>= 2;
66
+ memorg->pages_per_eraseblock = (128 * 1024) <<
67
+ (((extid >> 1) & 0x04) |
68
+ (extid & 0x03)) /
69
+ memorg->pagesize;
6770 mtd->erasesize = (128 * 1024) <<
6871 (((extid >> 1) & 0x04) | (extid & 0x03));
6972
7073 /* Extract ECC requirements from 5th id byte*/
7174 extid = (chip->id.data[4] >> 4) & 0x07;
7275 if (extid < 5) {
73
- chip->ecc_step_ds = 512;
74
- chip->ecc_strength_ds = 1 << extid;
76
+ requirements.step_size = 512;
77
+ requirements.strength = 1 << extid;
7578 } else {
76
- chip->ecc_step_ds = 1024;
79
+ requirements.step_size = 1024;
7780 switch (extid) {
7881 case 5:
79
- chip->ecc_strength_ds = 24;
82
+ requirements.strength = 24;
8083 break;
8184 case 6:
82
- chip->ecc_strength_ds = 40;
85
+ requirements.strength = 40;
8386 break;
8487 case 7:
85
- chip->ecc_strength_ds = 60;
88
+ requirements.strength = 60;
8689 break;
8790 default:
8891 WARN(1, "Could not decode ECC info");
89
- chip->ecc_step_ds = 0;
92
+ requirements.step_size = 0;
9093 }
9194 }
9295 } else {
....@@ -96,8 +99,8 @@
9699 switch (chip->id.data[1]) {
97100 /* K9F4G08U0D-S[I|C]B0(T00) */
98101 case 0xDC:
99
- chip->ecc_step_ds = 512;
100
- chip->ecc_strength_ds = 1;
102
+ requirements.step_size = 512;
103
+ requirements.strength = 1;
101104 break;
102105
103106 /* K9F1G08U0E 21nm chips do not support subpage write */
....@@ -111,6 +114,8 @@
111114 }
112115 }
113116 }
117
+
118
+ nanddev_set_ecc_requirements(base, &requirements);
114119 }
115120
116121 static int samsung_nand_init(struct nand_chip *chip)
....@@ -121,9 +126,9 @@
121126 chip->options |= NAND_SAMSUNG_LP_OPTIONS;
122127
123128 if (!nand_is_slc(chip))
124
- chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
129
+ chip->options |= NAND_BBM_LASTPAGE;
125130 else
126
- chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
131
+ chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;
127132
128133 return 0;
129134 }