Revision | a1286a1fc41633f45a4fa9dbf0be5eba3deadc09 (tree) |
---|---|
Time | 2022-07-22 20:29:06 |
Author | Michael Trimarchi <michael@amar...> |
Commiter | Michael Trimarchi |
mtd: nand: Move Samsung specific init/detection logic in nand_samsung.c
Upstream linux commit c51d0ac59f2420.
Move Samsung specific initialization and detection logic into
nand_samsung.c. This is part of the "separate vendor specific code from
core" cleanup process.
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
@@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o | ||
14 | 14 | obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o |
15 | 15 | obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o |
16 | 16 | obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o |
17 | -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o | |
17 | +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_samsung.o | |
18 | 18 | obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o |
19 | 19 | obj-$(CONFIG_TPL_NAND_INIT) += nand.o |
20 | 20 | ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) |
@@ -31,6 +31,7 @@ obj-y += nand_ids.o | ||
31 | 31 | obj-y += nand_util.o |
32 | 32 | obj-y += nand_ecc.o |
33 | 33 | obj-y += nand_base.o |
34 | +obj-y += nand_samsung.o | |
34 | 35 | obj-y += nand_timings.o |
35 | 36 | |
36 | 37 | endif # not spl |
@@ -4173,48 +4173,13 @@ void nand_decode_ext_id(struct nand_chip *chip) | ||
4173 | 4173 | /* |
4174 | 4174 | * Field definitions are in the following datasheets: |
4175 | 4175 | * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32) |
4176 | - * New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) | |
4177 | 4176 | * Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) |
4178 | 4177 | * |
4179 | 4178 | * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung |
4180 | 4179 | * ID to decide what to do. |
4181 | 4180 | */ |
4182 | - if (id_len == 6 && chip->id.data[0] == NAND_MFR_SAMSUNG && | |
4183 | - !nand_is_slc(chip) && chip->id.data[5] != 0x00) { | |
4184 | - /* Calc pagesize */ | |
4185 | - mtd->writesize = 2048 << (extid & 0x03); | |
4186 | - extid >>= 2; | |
4187 | - /* Calc oobsize */ | |
4188 | - switch (((extid >> 2) & 0x04) | (extid & 0x03)) { | |
4189 | - case 1: | |
4190 | - mtd->oobsize = 128; | |
4191 | - break; | |
4192 | - case 2: | |
4193 | - mtd->oobsize = 218; | |
4194 | - break; | |
4195 | - case 3: | |
4196 | - mtd->oobsize = 400; | |
4197 | - break; | |
4198 | - case 4: | |
4199 | - mtd->oobsize = 436; | |
4200 | - break; | |
4201 | - case 5: | |
4202 | - mtd->oobsize = 512; | |
4203 | - break; | |
4204 | - case 6: | |
4205 | - mtd->oobsize = 640; | |
4206 | - break; | |
4207 | - case 7: | |
4208 | - default: /* Other cases are "reserved" (unknown) */ | |
4209 | - mtd->oobsize = 1024; | |
4210 | - break; | |
4211 | - } | |
4212 | - extid >>= 2; | |
4213 | - /* Calc blocksize */ | |
4214 | - mtd->erasesize = (128 * 1024) << | |
4215 | - (((extid >> 1) & 0x04) | (extid & 0x03)); | |
4216 | - } else if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && | |
4217 | - !nand_is_slc(chip)) { | |
4181 | + if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && | |
4182 | + !nand_is_slc(chip)) { | |
4218 | 4183 | unsigned int tmp; |
4219 | 4184 | |
4220 | 4185 | /* Calc pagesize */ |
@@ -4374,13 +4339,10 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, | ||
4374 | 4339 | * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, |
4375 | 4340 | * AMD/Spansion, and Macronix. All others scan only the first page. |
4376 | 4341 | */ |
4377 | - if (!nand_is_slc(chip) && | |
4378 | - (maf_id == NAND_MFR_SAMSUNG || | |
4379 | - maf_id == NAND_MFR_HYNIX)) | |
4342 | + if (!nand_is_slc(chip) && maf_id == NAND_MFR_HYNIX) | |
4380 | 4343 | chip->bbt_options |= NAND_BBT_SCANLASTPAGE; |
4381 | 4344 | else if ((nand_is_slc(chip) && |
4382 | - (maf_id == NAND_MFR_SAMSUNG || | |
4383 | - maf_id == NAND_MFR_HYNIX || | |
4345 | + (maf_id == NAND_MFR_HYNIX || | |
4384 | 4346 | maf_id == NAND_MFR_TOSHIBA || |
4385 | 4347 | maf_id == NAND_MFR_AMD || |
4386 | 4348 | maf_id == NAND_MFR_MACRONIX)) || |
@@ -4549,12 +4511,6 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id, | ||
4549 | 4511 | /* Get chip options */ |
4550 | 4512 | chip->options |= type->options; |
4551 | 4513 | |
4552 | - /* | |
4553 | - * Check if chip is not a Samsung device. Do not clear the | |
4554 | - * options for chips which do not have an extended id. | |
4555 | - */ | |
4556 | - if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize) | |
4557 | - chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; | |
4558 | 4514 | ident_done: |
4559 | 4515 | |
4560 | 4516 | if (chip->options & NAND_BUSWIDTH_AUTO) { |
@@ -10,7 +10,7 @@ | ||
10 | 10 | #include <linux/mtd/rawnand.h> |
11 | 11 | #include <linux/sizes.h> |
12 | 12 | |
13 | -#define LP_OPTIONS NAND_SAMSUNG_LP_OPTIONS | |
13 | +#define LP_OPTIONS 0 | |
14 | 14 | #define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16) |
15 | 15 | |
16 | 16 | #define SP_OPTIONS NAND_NEED_READRDY |
@@ -189,7 +189,7 @@ struct nand_flash_dev nand_flash_ids[] = { | ||
189 | 189 | /* Manufacturer IDs */ |
190 | 190 | struct nand_manufacturers nand_manuf_ids[] = { |
191 | 191 | {NAND_MFR_TOSHIBA, "Toshiba"}, |
192 | - {NAND_MFR_SAMSUNG, "Samsung"}, | |
192 | + {NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops}, | |
193 | 193 | {NAND_MFR_FUJITSU, "Fujitsu"}, |
194 | 194 | {NAND_MFR_NATIONAL, "National"}, |
195 | 195 | {NAND_MFR_RENESAS, "Renesas"}, |
@@ -0,0 +1,90 @@ | ||
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * Copyright (C) 2017 Free Electrons | |
4 | + * Copyright (C) 2017 NextThing Co | |
5 | + * | |
6 | + * Author: Boris Brezillon <boris.brezillon@free-electrons.com> | |
7 | + * | |
8 | + * This program is free software; you can redistribute it and/or modify | |
9 | + * it under the terms of the GNU General Public License as published by | |
10 | + * the Free Software Foundation; either version 2 of the License, or | |
11 | + * (at your option) any later version. | |
12 | + * | |
13 | + * This program is distributed in the hope that it will be useful, | |
14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | + * GNU General Public License for more details. | |
17 | + */ | |
18 | + | |
19 | +#include <linux/bug.h> | |
20 | +#include <linux/mtd/rawnand.h> | |
21 | + | |
22 | +static void samsung_nand_decode_id(struct nand_chip *chip) | |
23 | +{ | |
24 | + struct mtd_info *mtd = nand_to_mtd(chip); | |
25 | + | |
26 | + /* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */ | |
27 | + if (chip->id.len == 6 && !nand_is_slc(chip) && | |
28 | + chip->id.data[5] != 0x00) { | |
29 | + u8 extid = chip->id.data[3]; | |
30 | + | |
31 | + /* Get pagesize */ | |
32 | + mtd->writesize = 2048 << (extid & 0x03); | |
33 | + | |
34 | + extid >>= 2; | |
35 | + | |
36 | + /* Get oobsize */ | |
37 | + switch (((extid >> 2) & 0x4) | (extid & 0x3)) { | |
38 | + case 1: | |
39 | + mtd->oobsize = 128; | |
40 | + break; | |
41 | + case 2: | |
42 | + mtd->oobsize = 218; | |
43 | + break; | |
44 | + case 3: | |
45 | + mtd->oobsize = 400; | |
46 | + break; | |
47 | + case 4: | |
48 | + mtd->oobsize = 436; | |
49 | + break; | |
50 | + case 5: | |
51 | + mtd->oobsize = 512; | |
52 | + break; | |
53 | + case 6: | |
54 | + mtd->oobsize = 640; | |
55 | + break; | |
56 | + case 7: | |
57 | + default: /* Other cases are "reserved" (unknown) */ | |
58 | + WARN(1, "Invalid OOB size value"); | |
59 | + mtd->oobsize = 1024; | |
60 | + break; | |
61 | + } | |
62 | + | |
63 | + /* Get blocksize */ | |
64 | + extid >>= 2; | |
65 | + mtd->erasesize = (128 * 1024) << | |
66 | + (((extid >> 1) & 0x04) | (extid & 0x03)); | |
67 | + } else { | |
68 | + nand_decode_ext_id(chip); | |
69 | + } | |
70 | +} | |
71 | + | |
72 | +static int samsung_nand_init(struct nand_chip *chip) | |
73 | +{ | |
74 | + struct mtd_info *mtd = nand_to_mtd(chip); | |
75 | + | |
76 | + if (mtd->writesize > 512) | |
77 | + chip->options |= NAND_SAMSUNG_LP_OPTIONS; | |
78 | + | |
79 | + if (!nand_is_slc(chip)) | |
80 | + chip->bbt_options |= NAND_BBT_SCANLASTPAGE; | |
81 | + else | |
82 | + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; | |
83 | + | |
84 | + return 0; | |
85 | +} | |
86 | + | |
87 | +const struct nand_manufacturer_ops samsung_nand_manuf_ops = { | |
88 | + .detect = samsung_nand_decode_id, | |
89 | + .init = samsung_nand_init, | |
90 | +}; |
@@ -1158,6 +1158,8 @@ struct nand_manufacturers { | ||
1158 | 1158 | extern struct nand_flash_dev nand_flash_ids[]; |
1159 | 1159 | extern struct nand_manufacturers nand_manuf_ids[]; |
1160 | 1160 | |
1161 | +extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; | |
1162 | + | |
1161 | 1163 | int nand_default_bbt(struct mtd_info *mtd); |
1162 | 1164 | int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); |
1163 | 1165 | int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs); |