aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2018-03-19 09:47:26 -0400
committerBoris Brezillon <boris.brezillon@bootlin.com>2018-03-20 05:46:35 -0400
commitf4531b2b1929806d2bec1a2f19805031d8bc0806 (patch)
treeb566dde24cc7975cdd519efd35a69178bc6b2a4d
parent107b7d6a7ad4927e1b217cf5667ac94bab021e42 (diff)
mtd: rawnand: prepare the removal of ONFI/JEDEC parameter pages
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. To prepare to the removal of such huge structure, a small NAND parameter structure is allocated statically and contains only very few members that are generic to all chips and actually used elsewhere in the code. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
-rw-r--r--drivers/mtd/nand/raw/nand_base.c39
-rw-r--r--include/linux/mtd/rawnand.h13
2 files changed, 30 insertions, 22 deletions
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 4099d8a1e25e..0f1f45526c7f 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -1162,9 +1162,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
1162 1162
1163static bool nand_supports_set_get_features(struct nand_chip *chip) 1163static bool nand_supports_set_get_features(struct nand_chip *chip)
1164{ 1164{
1165 return (chip->onfi_version && 1165 return chip->parameters.supports_set_get_features;
1166 (le16_to_cpu(chip->onfi_params.opt_cmd) &
1167 ONFI_OPT_CMD_SET_GET_FEATURES));
1168} 1166}
1169 1167
1170/** 1168/**
@@ -5145,8 +5143,8 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
5145 5143
5146 sanitize_string(p->manufacturer, sizeof(p->manufacturer)); 5144 sanitize_string(p->manufacturer, sizeof(p->manufacturer));
5147 sanitize_string(p->model, sizeof(p->model)); 5145 sanitize_string(p->model, sizeof(p->model));
5148 if (!mtd->name) 5146 strncpy(chip->parameters.model, p->model,
5149 mtd->name = p->model; 5147 sizeof(chip->parameters.model) - 1);
5150 5148
5151 mtd->writesize = le32_to_cpu(p->byte_per_page); 5149 mtd->writesize = le32_to_cpu(p->byte_per_page);
5152 5150
@@ -5193,6 +5191,10 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
5193 pr_warn("Could not retrieve ONFI ECC requirements\n"); 5191 pr_warn("Could not retrieve ONFI ECC requirements\n");
5194 } 5192 }
5195 5193
5194 /* Save some parameters from the parameter page for future use */
5195 if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_SET_GET_FEATURES)
5196 chip->parameters.supports_set_get_features = true;
5197
5196 return 1; 5198 return 1;
5197} 5199}
5198 5200
@@ -5245,8 +5247,8 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
5245 5247
5246 sanitize_string(p->manufacturer, sizeof(p->manufacturer)); 5248 sanitize_string(p->manufacturer, sizeof(p->manufacturer));
5247 sanitize_string(p->model, sizeof(p->model)); 5249 sanitize_string(p->model, sizeof(p->model));
5248 if (!mtd->name) 5250 strncpy(chip->parameters.model, p->model,
5249 mtd->name = p->model; 5251 sizeof(chip->parameters.model) - 1);
5250 5252
5251 mtd->writesize = le32_to_cpu(p->byte_per_page); 5253 mtd->writesize = le32_to_cpu(p->byte_per_page);
5252 5254
@@ -5433,8 +5435,8 @@ static bool find_full_id_nand(struct nand_chip *chip,
5433 chip->onfi_timing_mode_default = 5435 chip->onfi_timing_mode_default =
5434 type->onfi_timing_mode_default; 5436 type->onfi_timing_mode_default;
5435 5437
5436 if (!mtd->name) 5438 strncpy(chip->parameters.model, type->name,
5437 mtd->name = type->name; 5439 sizeof(chip->parameters.model) - 1);
5438 5440
5439 return true; 5441 return true;
5440 } 5442 }
@@ -5587,8 +5589,8 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
5587 if (!type->name) 5589 if (!type->name)
5588 return -ENODEV; 5590 return -ENODEV;
5589 5591
5590 if (!mtd->name) 5592 strncpy(chip->parameters.model, type->name,
5591 mtd->name = type->name; 5593 sizeof(chip->parameters.model) - 1);
5592 5594
5593 chip->chipsize = (uint64_t)type->chipsize << 20; 5595 chip->chipsize = (uint64_t)type->chipsize << 20;
5594 5596
@@ -5601,6 +5603,8 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
5601 chip->options |= type->options; 5603 chip->options |= type->options;
5602 5604
5603ident_done: 5605ident_done:
5606 if (!mtd->name)
5607 mtd->name = chip->parameters.model;
5604 5608
5605 if (chip->options & NAND_BUSWIDTH_AUTO) { 5609 if (chip->options & NAND_BUSWIDTH_AUTO) {
5606 WARN_ON(busw & NAND_BUSWIDTH_16); 5610 WARN_ON(busw & NAND_BUSWIDTH_16);
@@ -5647,17 +5651,8 @@ ident_done:
5647 5651
5648 pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", 5652 pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n",
5649 maf_id, dev_id); 5653 maf_id, dev_id);
5650 5654 pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
5651 if (chip->onfi_version) 5655 chip->parameters.model);
5652 pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
5653 chip->onfi_params.model);
5654 else if (chip->jedec_version)
5655 pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
5656 chip->jedec_params.model);
5657 else
5658 pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
5659 type->name);
5660
5661 pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n", 5656 pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n",
5662 (int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", 5657 (int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
5663 mtd->erasesize >> 10, mtd->writesize, mtd->oobsize); 5658 mtd->erasesize >> 10, mtd->writesize, mtd->oobsize);
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index 3cc2a3435b20..a24591411d78 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -429,6 +429,16 @@ struct nand_jedec_params {
429 __le16 crc; 429 __le16 crc;
430} __packed; 430} __packed;
431 431
432/**
433 * struct nand_parameters - NAND generic parameters from the parameter page
434 * @model: Model name
435 * @supports_set_get_features: The NAND chip supports setting/getting features
436 */
437struct nand_parameters {
438 char model[100];
439 bool supports_set_get_features;
440};
441
432/* The maximum expected count of bytes in the NAND ID sequence */ 442/* The maximum expected count of bytes in the NAND ID sequence */
433#define NAND_MAX_ID_LEN 8 443#define NAND_MAX_ID_LEN 8
434 444
@@ -1165,6 +1175,8 @@ int nand_op_parser_exec_op(struct nand_chip *chip,
1165 * supported, 0 otherwise. 1175 * supported, 0 otherwise.
1166 * @jedec_params: [INTERN] holds the JEDEC parameter page when JEDEC is 1176 * @jedec_params: [INTERN] holds the JEDEC parameter page when JEDEC is
1167 * supported, 0 otherwise. 1177 * supported, 0 otherwise.
1178 * @parameters: [INTERN] holds generic parameters under an easily
1179 * readable form.
1168 * @max_bb_per_die: [INTERN] the max number of bad blocks each die of a 1180 * @max_bb_per_die: [INTERN] the max number of bad blocks each die of a
1169 * this nand device will encounter their life times. 1181 * this nand device will encounter their life times.
1170 * @blocks_per_die: [INTERN] The number of PEBs in a die 1182 * @blocks_per_die: [INTERN] The number of PEBs in a die
@@ -1249,6 +1261,7 @@ struct nand_chip {
1249 struct nand_onfi_params onfi_params; 1261 struct nand_onfi_params onfi_params;
1250 struct nand_jedec_params jedec_params; 1262 struct nand_jedec_params jedec_params;
1251 }; 1263 };
1264 struct nand_parameters parameters;
1252 u16 max_bb_per_die; 1265 u16 max_bb_per_die;
1253 u32 blocks_per_die; 1266 u32 blocks_per_die;
1254 1267