• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiona1286a1fc41633f45a4fa9dbf0be5eba3deadc09 (tree)
Time2022-07-22 20:29:06
AuthorMichael Trimarchi <michael@amar...>
CommiterMichael Trimarchi

Log Message

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>

Change Summary

Incremental Difference

--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
1414 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
1515 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
1616 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
1818 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
1919 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
2020 ifeq ($(CONFIG_SPL_ENV_SUPPORT),y)
@@ -31,6 +31,7 @@ obj-y += nand_ids.o
3131 obj-y += nand_util.o
3232 obj-y += nand_ecc.o
3333 obj-y += nand_base.o
34+obj-y += nand_samsung.o
3435 obj-y += nand_timings.o
3536
3637 endif # not spl
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4173,48 +4173,13 @@ void nand_decode_ext_id(struct nand_chip *chip)
41734173 /*
41744174 * Field definitions are in the following datasheets:
41754175 * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32)
4176- * New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44)
41774176 * Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22)
41784177 *
41794178 * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung
41804179 * ID to decide what to do.
41814180 */
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)) {
42184183 unsigned int tmp;
42194184
42204185 /* Calc pagesize */
@@ -4374,13 +4339,10 @@ static void nand_decode_bbm_options(struct mtd_info *mtd,
43744339 * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
43754340 * AMD/Spansion, and Macronix. All others scan only the first page.
43764341 */
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)
43804343 chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
43814344 else if ((nand_is_slc(chip) &&
4382- (maf_id == NAND_MFR_SAMSUNG ||
4383- maf_id == NAND_MFR_HYNIX ||
4345+ (maf_id == NAND_MFR_HYNIX ||
43844346 maf_id == NAND_MFR_TOSHIBA ||
43854347 maf_id == NAND_MFR_AMD ||
43864348 maf_id == NAND_MFR_MACRONIX)) ||
@@ -4549,12 +4511,6 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
45494511 /* Get chip options */
45504512 chip->options |= type->options;
45514513
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;
45584514 ident_done:
45594515
45604516 if (chip->options & NAND_BUSWIDTH_AUTO) {
--- a/drivers/mtd/nand/raw/nand_ids.c
+++ b/drivers/mtd/nand/raw/nand_ids.c
@@ -10,7 +10,7 @@
1010 #include <linux/mtd/rawnand.h>
1111 #include <linux/sizes.h>
1212
13-#define LP_OPTIONS NAND_SAMSUNG_LP_OPTIONS
13+#define LP_OPTIONS 0
1414 #define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16)
1515
1616 #define SP_OPTIONS NAND_NEED_READRDY
@@ -189,7 +189,7 @@ struct nand_flash_dev nand_flash_ids[] = {
189189 /* Manufacturer IDs */
190190 struct nand_manufacturers nand_manuf_ids[] = {
191191 {NAND_MFR_TOSHIBA, "Toshiba"},
192- {NAND_MFR_SAMSUNG, "Samsung"},
192+ {NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops},
193193 {NAND_MFR_FUJITSU, "Fujitsu"},
194194 {NAND_MFR_NATIONAL, "National"},
195195 {NAND_MFR_RENESAS, "Renesas"},
--- /dev/null
+++ b/drivers/mtd/nand/raw/nand_samsung.c
@@ -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+};
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1158,6 +1158,8 @@ struct nand_manufacturers {
11581158 extern struct nand_flash_dev nand_flash_ids[];
11591159 extern struct nand_manufacturers nand_manuf_ids[];
11601160
1161+extern const struct nand_manufacturer_ops samsung_nand_manuf_ops;
1162+
11611163 int nand_default_bbt(struct mtd_info *mtd);
11621164 int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);
11631165 int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs);