Skip to content

Commit 480139d

Browse files
miquelraynalBoris Brezillon
authored andcommitted
mtd: rawnand: get rid of the JEDEC parameter page in nand_chip
The NAND chip parameter page is statically allocated within the nand_chip structure, which reserves a lot of space. Even not ONFI nor JEDEC chips have it embedded. Also, only a few parameters are actually read from the parameter page after the detection. Now that there is a small nand_parameters structure that can held generic parameters, remove the JEDEC page from the nand_chip structure by just allocating it during the identification phase and removing it right after. Signed-off-by: Miquel Raynal <[email protected]> Signed-off-by: Boris Brezillon <[email protected]>
1 parent 34c5c01 commit 480139d

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

drivers/mtd/nand/raw/nand_base.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,8 +5226,9 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
52265226
static int nand_flash_detect_jedec(struct nand_chip *chip)
52275227
{
52285228
struct mtd_info *mtd = nand_to_mtd(chip);
5229-
struct nand_jedec_params *p = &chip->jedec_params;
5229+
struct nand_jedec_params *p;
52305230
struct jedec_ecc_info *ecc;
5231+
int jedec_version = 0;
52315232
char id[5];
52325233
int i, val, ret;
52335234

@@ -5236,14 +5237,23 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
52365237
if (ret || strncmp(id, "JEDEC", sizeof(id)))
52375238
return 0;
52385239

5240+
/* JEDEC chip: allocate a buffer to hold its parameter page */
5241+
p = kzalloc(sizeof(*p), GFP_KERNEL);
5242+
if (!p)
5243+
return -ENOMEM;
5244+
52395245
ret = nand_read_param_page_op(chip, 0x40, NULL, 0);
5240-
if (ret)
5241-
return 0;
5246+
if (ret) {
5247+
ret = 0;
5248+
goto free_jedec_param_page;
5249+
}
52425250

52435251
for (i = 0; i < 3; i++) {
52445252
ret = nand_read_data_op(chip, p, sizeof(*p), true);
5245-
if (ret)
5246-
return 0;
5253+
if (ret) {
5254+
ret = 0;
5255+
goto free_jedec_param_page;
5256+
}
52475257

52485258
if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 510) ==
52495259
le16_to_cpu(p->crc))
@@ -5252,19 +5262,19 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
52525262

52535263
if (i == 3) {
52545264
pr_err("Could not find valid JEDEC parameter page; aborting\n");
5255-
return 0;
5265+
goto free_jedec_param_page;
52565266
}
52575267

52585268
/* Check version */
52595269
val = le16_to_cpu(p->revision);
52605270
if (val & (1 << 2))
5261-
chip->jedec_version = 10;
5271+
jedec_version = 10;
52625272
else if (val & (1 << 1))
5263-
chip->jedec_version = 1; /* vendor specific version */
5273+
jedec_version = 1; /* vendor specific version */
52645274

5265-
if (!chip->jedec_version) {
5275+
if (!jedec_version) {
52665276
pr_info("unsupported JEDEC version: %d\n", val);
5267-
return 0;
5277+
goto free_jedec_param_page;
52685278
}
52695279

52705280
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
@@ -5285,7 +5295,7 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
52855295
chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
52865296
chip->bits_per_cell = p->bits_per_cell;
52875297

5288-
if (jedec_feature(chip) & JEDEC_FEATURE_16_BIT_BUS)
5298+
if (le16_to_cpu(p->features) & JEDEC_FEATURE_16_BIT_BUS)
52895299
chip->options |= NAND_BUSWIDTH_16;
52905300

52915301
/* ECC info */
@@ -5298,7 +5308,9 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
52985308
pr_warn("Invalid codeword size\n");
52995309
}
53005310

5301-
return 1;
5311+
free_jedec_param_page:
5312+
kfree(p);
5313+
return ret;
53025314
}
53035315

53045316
/*
@@ -5604,7 +5616,10 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
56045616
goto ident_done;
56055617

56065618
/* Check if the chip is JEDEC compliant */
5607-
if (nand_flash_detect_jedec(chip))
5619+
ret = nand_flash_detect_jedec(chip);
5620+
if (ret < 0)
5621+
return ret;
5622+
else if (ret)
56085623
goto ident_done;
56095624
}
56105625

include/linux/mtd/rawnand.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,12 +1200,8 @@ int nand_op_parser_exec_op(struct nand_chip *chip,
12001200
* currently in data_buf.
12011201
* @subpagesize: [INTERN] holds the subpagesize
12021202
* @id: [INTERN] holds NAND ID
1203-
* @jedec_version: [INTERN] holds the chip JEDEC version (BCD encoded),
1204-
* non 0 if JEDEC supported.
12051203
* @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is
12061204
* supported, 0 otherwise.
1207-
* @jedec_params: [INTERN] holds the JEDEC parameter page when JEDEC is
1208-
* supported, 0 otherwise.
12091205
* @parameters: [INTERN] holds generic parameters under an easily
12101206
* readable form.
12111207
* @max_bb_per_die: [INTERN] the max number of bad blocks each die of a
@@ -1286,11 +1282,7 @@ struct nand_chip {
12861282
int badblockbits;
12871283

12881284
struct nand_id id;
1289-
int jedec_version;
1290-
union {
1291-
struct nand_onfi_params onfi_params;
1292-
struct nand_jedec_params jedec_params;
1293-
};
1285+
struct nand_onfi_params onfi_params;
12941286
struct nand_parameters parameters;
12951287
u16 max_bb_per_die;
12961288
u32 blocks_per_die;
@@ -1621,13 +1613,6 @@ static inline int nand_opcode_8bits(unsigned int command)
16211613
return 0;
16221614
}
16231615

1624-
/* return the supported JEDEC features. */
1625-
static inline int jedec_feature(struct nand_chip *chip)
1626-
{
1627-
return chip->jedec_version ? le16_to_cpu(chip->jedec_params.features)
1628-
: 0;
1629-
}
1630-
16311616
/* get timing characteristics from ONFI timing mode. */
16321617
const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode);
16331618

0 commit comments

Comments
 (0)