Skip to content

Commit c51d0ac

Browse files
author
Boris Brezillon
committed
mtd: nand: Move Samsung specific init/detection logic in nand_samsung.c
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: Boris Brezillon <boris.brezillon@free-electrons.com> Acked-by: Richard Weinberger <richard@nod.at>
1 parent abbe26d commit c51d0ac

5 files changed

Lines changed: 101 additions & 50 deletions

File tree

‎drivers/mtd/nand/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ obj-$(CONFIG_MTD_NAND_QCOM) += qcom_nandc.o
6161
obj-$(CONFIG_MTD_NAND_MTK) += mtk_nand.o mtk_ecc.o
6262

6363
nand-objs := nand_base.o nand_bbt.o nand_timings.o nand_ids.o
64+
nand-objs += nand_samsung.o

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,48 +3832,13 @@ void nand_decode_ext_id(struct nand_chip *chip)
38323832
/*
38333833
* Field definitions are in the following datasheets:
38343834
* Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32)
3835-
* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44)
38363835
* Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22)
38373836
*
38383837
* Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung
38393838
* ID to decide what to do.
38403839
*/
3841-
if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG &&
3842-
!nand_is_slc(chip) && id_data[5] != 0x00) {
3843-
/* Calc pagesize */
3844-
mtd->writesize = 2048 << (extid & 0x03);
3845-
extid >>= 2;
3846-
/* Calc oobsize */
3847-
switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
3848-
case 1:
3849-
mtd->oobsize = 128;
3850-
break;
3851-
case 2:
3852-
mtd->oobsize = 218;
3853-
break;
3854-
case 3:
3855-
mtd->oobsize = 400;
3856-
break;
3857-
case 4:
3858-
mtd->oobsize = 436;
3859-
break;
3860-
case 5:
3861-
mtd->oobsize = 512;
3862-
break;
3863-
case 6:
3864-
mtd->oobsize = 640;
3865-
break;
3866-
case 7:
3867-
default: /* Other cases are "reserved" (unknown) */
3868-
mtd->oobsize = 1024;
3869-
break;
3870-
}
3871-
extid >>= 2;
3872-
/* Calc blocksize */
3873-
mtd->erasesize = (128 * 1024) <<
3874-
(((extid >> 1) & 0x04) | (extid & 0x03));
3875-
} else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
3876-
!nand_is_slc(chip)) {
3840+
if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
3841+
!nand_is_slc(chip)) {
38773842
unsigned int tmp;
38783843

38793844
/* Calc pagesize */
@@ -4001,13 +3966,10 @@ static void nand_decode_bbm_options(struct nand_chip *chip)
40013966
* Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
40023967
* AMD/Spansion, and Macronix. All others scan only the first page.
40033968
*/
4004-
if (!nand_is_slc(chip) &&
4005-
(maf_id == NAND_MFR_SAMSUNG ||
4006-
maf_id == NAND_MFR_HYNIX))
3969+
if (!nand_is_slc(chip) && maf_id == NAND_MFR_HYNIX)
40073970
chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
40083971
else if ((nand_is_slc(chip) &&
4009-
(maf_id == NAND_MFR_SAMSUNG ||
4010-
maf_id == NAND_MFR_HYNIX ||
3972+
(maf_id == NAND_MFR_HYNIX ||
40113973
maf_id == NAND_MFR_TOSHIBA ||
40123974
maf_id == NAND_MFR_AMD ||
40133975
maf_id == NAND_MFR_MACRONIX)) ||
@@ -4202,12 +4164,6 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
42024164
/* Get chip options */
42034165
chip->options |= type->options;
42044166

4205-
/*
4206-
* Check if chip is not a Samsung device. Do not clear the
4207-
* options for chips which do not have an extended id.
4208-
*/
4209-
if (maf_id != NAND_MFR_SAMSUNG && !type->pagesize)
4210-
chip->options &= ~NAND_SAMSUNG_LP_OPTIONS;
42114167
ident_done:
42124168

42134169
if (chip->options & NAND_BUSWIDTH_AUTO) {

‎drivers/mtd/nand/nand_ids.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <linux/mtd/nand.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
@@ -172,7 +172,7 @@ struct nand_flash_dev nand_flash_ids[] = {
172172
static const struct nand_manufacturer nand_manufacturers[] = {
173173
{NAND_MFR_TOSHIBA, "Toshiba"},
174174
{NAND_MFR_ESMT, "ESMT"},
175-
{NAND_MFR_SAMSUNG, "Samsung"},
175+
{NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops},
176176
{NAND_MFR_FUJITSU, "Fujitsu"},
177177
{NAND_MFR_NATIONAL, "National"},
178178
{NAND_MFR_RENESAS, "Renesas"},

‎drivers/mtd/nand/nand_samsung.c‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (C) 2017 Free Electrons
3+
* Copyright (C) 2017 NextThing Co
4+
*
5+
* 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.
16+
*/
17+
18+
#include <linux/mtd/nand.h>
19+
20+
static void samsung_nand_decode_id(struct nand_chip *chip)
21+
{
22+
struct mtd_info *mtd = nand_to_mtd(chip);
23+
24+
/* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */
25+
if (chip->id.len == 6 && !nand_is_slc(chip) &&
26+
chip->id.data[5] != 0x00) {
27+
u8 extid = chip->id.data[3];
28+
29+
/* Get pagesize */
30+
mtd->writesize = 2048 << (extid & 0x03);
31+
32+
extid >>= 2;
33+
34+
/* Get oobsize */
35+
switch (((extid >> 2) & 0x4) | (extid & 0x3)) {
36+
case 1:
37+
mtd->oobsize = 128;
38+
break;
39+
case 2:
40+
mtd->oobsize = 218;
41+
break;
42+
case 3:
43+
mtd->oobsize = 400;
44+
break;
45+
case 4:
46+
mtd->oobsize = 436;
47+
break;
48+
case 5:
49+
mtd->oobsize = 512;
50+
break;
51+
case 6:
52+
mtd->oobsize = 640;
53+
break;
54+
default:
55+
/*
56+
* We should never reach this case, but if that
57+
* happens, this probably means Samsung decided to use
58+
* a different extended ID format, and we should find
59+
* a way to support it.
60+
*/
61+
WARN(1, "Invalid OOB size value");
62+
break;
63+
}
64+
65+
/* Get blocksize */
66+
extid >>= 2;
67+
mtd->erasesize = (128 * 1024) <<
68+
(((extid >> 1) & 0x04) | (extid & 0x03));
69+
} else {
70+
nand_decode_ext_id(chip);
71+
}
72+
}
73+
74+
static int samsung_nand_init(struct nand_chip *chip)
75+
{
76+
struct mtd_info *mtd = nand_to_mtd(chip);
77+
78+
if (mtd->writesize > 512)
79+
chip->options |= NAND_SAMSUNG_LP_OPTIONS;
80+
81+
if (!nand_is_slc(chip))
82+
chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
83+
else
84+
chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
85+
86+
return 0;
87+
}
88+
89+
const struct nand_manufacturer_ops samsung_nand_manuf_ops = {
90+
.detect = samsung_nand_decode_id,
91+
.init = samsung_nand_init,
92+
};

‎include/linux/mtd/nand.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ nand_manufacturer_name(const struct nand_manufacturer *manufacturer)
11141114

11151115
extern struct nand_flash_dev nand_flash_ids[];
11161116

1117+
extern const struct nand_manufacturer_ops samsung_nand_manuf_ops;
1118+
11171119
int nand_default_bbt(struct mtd_info *mtd);
11181120
int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);
11191121
int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs);

0 commit comments

Comments
 (0)