Revision | 1ca6f9483e9ab56fa66b2e922b2df2c9ad609fbb (tree) |
---|---|
Time | 2022-07-22 15:30:16 |
Author | Michael Trimarchi <michael@amar...> |
Commiter | Michael Trimarchi |
mtd: nand: Get rid of busw parameter
Upstream linux commit 29a198a1592d83.
Auto-detection functions are passed a busw parameter to retrieve the actual
NAND bus width and eventually set the correct value in chip->options.
Rework the nand_get_flash_type() function to get rid of this extra
parameter and let detection code directly set the NAND_BUSWIDTH_16 flag in
chip->options if needed.
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
@@ -3898,8 +3898,7 @@ static void nand_onfi_detect_micron(struct nand_chip *chip, | ||
3898 | 3898 | /* |
3899 | 3899 | * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. |
3900 | 3900 | */ |
3901 | -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |
3902 | - int *busw) | |
3901 | +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) | |
3903 | 3902 | { |
3904 | 3903 | struct nand_onfi_params *p = &chip->onfi_params; |
3905 | 3904 | char id[4]; |
@@ -3971,9 +3970,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | ||
3971 | 3970 | chip->bits_per_cell = p->bits_per_cell; |
3972 | 3971 | |
3973 | 3972 | if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) |
3974 | - *busw = NAND_BUSWIDTH_16; | |
3975 | - else | |
3976 | - *busw = 0; | |
3973 | + chip->options |= NAND_BUSWIDTH_16; | |
3977 | 3974 | |
3978 | 3975 | if (p->ecc_bits != 0xff) { |
3979 | 3976 | chip->ecc_strength_ds = p->ecc_bits; |
@@ -4003,8 +4000,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | ||
4003 | 4000 | return 1; |
4004 | 4001 | } |
4005 | 4002 | #else |
4006 | -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |
4007 | - int *busw) | |
4003 | +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) | |
4008 | 4004 | { |
4009 | 4005 | return 0; |
4010 | 4006 | } |
@@ -4013,8 +4009,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | ||
4013 | 4009 | /* |
4014 | 4010 | * Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise. |
4015 | 4011 | */ |
4016 | -static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, | |
4017 | - int *busw) | |
4012 | +static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip) | |
4018 | 4013 | { |
4019 | 4014 | struct nand_jedec_params *p = &chip->jedec_params; |
4020 | 4015 | struct jedec_ecc_info *ecc; |
@@ -4076,9 +4071,7 @@ static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, | ||
4076 | 4071 | chip->bits_per_cell = p->bits_per_cell; |
4077 | 4072 | |
4078 | 4073 | if (jedec_feature(chip) & JEDEC_FEATURE_16_BIT_BUS) |
4079 | - *busw = NAND_BUSWIDTH_16; | |
4080 | - else | |
4081 | - *busw = 0; | |
4074 | + chip->options |= NAND_BUSWIDTH_16; | |
4082 | 4075 | |
4083 | 4076 | /* ECC info */ |
4084 | 4077 | ecc = &p->ecc_info[0]; |
@@ -4168,7 +4161,7 @@ static int nand_get_bits_per_cell(u8 cellinfo) | ||
4168 | 4161 | * manufacturer-specific "extended ID" decoding patterns. |
4169 | 4162 | */ |
4170 | 4163 | static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, |
4171 | - u8 id_data[8], int *busw) | |
4164 | + u8 id_data[8]) | |
4172 | 4165 | { |
4173 | 4166 | int extid, id_len; |
4174 | 4167 | /* The 3rd id byte holds MLC / multichip data */ |
@@ -4221,7 +4214,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | ||
4221 | 4214 | /* Calc blocksize */ |
4222 | 4215 | mtd->erasesize = (128 * 1024) << |
4223 | 4216 | (((extid >> 1) & 0x04) | (extid & 0x03)); |
4224 | - *busw = 0; | |
4225 | 4217 | } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && |
4226 | 4218 | !nand_is_slc(chip)) { |
4227 | 4219 | unsigned int tmp; |
@@ -4262,7 +4254,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | ||
4262 | 4254 | mtd->erasesize = 768 * 1024; |
4263 | 4255 | else |
4264 | 4256 | mtd->erasesize = (64 * 1024) << tmp; |
4265 | - *busw = 0; | |
4266 | 4257 | } else { |
4267 | 4258 | /* Calc pagesize */ |
4268 | 4259 | mtd->writesize = 1024 << (extid & 0x03); |
@@ -4275,7 +4266,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | ||
4275 | 4266 | mtd->erasesize = (64 * 1024) << (extid & 0x03); |
4276 | 4267 | extid >>= 2; |
4277 | 4268 | /* Get buswidth information */ |
4278 | - *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; | |
4269 | + /* Get buswidth information */ | |
4270 | + if (extid & 0x1) | |
4271 | + chip->options |= NAND_BUSWIDTH_16; | |
4279 | 4272 | |
4280 | 4273 | /* |
4281 | 4274 | * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per |
@@ -4301,15 +4294,13 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | ||
4301 | 4294 | * the chip. |
4302 | 4295 | */ |
4303 | 4296 | static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, |
4304 | - struct nand_flash_dev *type, u8 id_data[8], | |
4305 | - int *busw) | |
4297 | + struct nand_flash_dev *type, u8 id_data[8]) | |
4306 | 4298 | { |
4307 | 4299 | int maf_id = id_data[0]; |
4308 | 4300 | |
4309 | 4301 | mtd->erasesize = type->erasesize; |
4310 | 4302 | mtd->writesize = type->pagesize; |
4311 | 4303 | mtd->oobsize = mtd->writesize / 32; |
4312 | - *busw = type->options & NAND_BUSWIDTH_16; | |
4313 | 4304 | |
4314 | 4305 | /* All legacy ID NAND are small-page, SLC */ |
4315 | 4306 | chip->bits_per_cell = 1; |
@@ -4371,7 +4362,7 @@ static inline bool is_full_id_nand(struct nand_flash_dev *type) | ||
4371 | 4362 | } |
4372 | 4363 | |
4373 | 4364 | static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, |
4374 | - struct nand_flash_dev *type, u8 *id_data, int *busw) | |
4365 | + struct nand_flash_dev *type, u8 *id_data) | |
4375 | 4366 | { |
4376 | 4367 | if (!strncmp((char *)type->id, (char *)id_data, type->id_len)) { |
4377 | 4368 | mtd->writesize = type->pagesize; |
@@ -4386,8 +4377,6 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, | ||
4386 | 4377 | chip->onfi_timing_mode_default = |
4387 | 4378 | type->onfi_timing_mode_default; |
4388 | 4379 | |
4389 | - *busw = type->options & NAND_BUSWIDTH_16; | |
4390 | - | |
4391 | 4380 | if (!mtd->name) |
4392 | 4381 | mtd->name = type->name; |
4393 | 4382 |
@@ -4449,9 +4438,24 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | ||
4449 | 4438 | if (!type) |
4450 | 4439 | type = nand_flash_ids; |
4451 | 4440 | |
4441 | + /* | |
4442 | + * Save the NAND_BUSWIDTH_16 flag before letting auto-detection logic | |
4443 | + * override it. | |
4444 | + * This is required to make sure initial NAND bus width set by the | |
4445 | + * NAND controller driver is coherent with the real NAND bus width | |
4446 | + * (extracted by auto-detection code). | |
4447 | + */ | |
4448 | + busw = chip->options & NAND_BUSWIDTH_16; | |
4449 | + | |
4450 | + /* | |
4451 | + * The flag is only set (never cleared), reset it to its default value | |
4452 | + * before starting auto-detection. | |
4453 | + */ | |
4454 | + chip->options &= ~NAND_BUSWIDTH_16; | |
4455 | + | |
4452 | 4456 | for (; type->name != NULL; type++) { |
4453 | 4457 | if (is_full_id_nand(type)) { |
4454 | - if (find_full_id_nand(mtd, chip, type, id_data, &busw)) | |
4458 | + if (find_full_id_nand(mtd, chip, type, id_data)) | |
4455 | 4459 | goto ident_done; |
4456 | 4460 | } else if (*dev_id == type->dev_id) { |
4457 | 4461 | break; |
@@ -4461,11 +4465,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | ||
4461 | 4465 | chip->onfi_version = 0; |
4462 | 4466 | if (!type->name || !type->pagesize) { |
4463 | 4467 | /* Check if the chip is ONFI compliant */ |
4464 | - if (nand_flash_detect_onfi(mtd, chip, &busw)) | |
4468 | + if (nand_flash_detect_onfi(mtd, chip)) | |
4465 | 4469 | goto ident_done; |
4466 | 4470 | |
4467 | 4471 | /* Check if the chip is JEDEC compliant */ |
4468 | - if (nand_flash_detect_jedec(mtd, chip, &busw)) | |
4472 | + if (nand_flash_detect_jedec(mtd, chip)) | |
4469 | 4473 | goto ident_done; |
4470 | 4474 | } |
4471 | 4475 |
@@ -4479,10 +4483,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | ||
4479 | 4483 | |
4480 | 4484 | if (!type->pagesize) { |
4481 | 4485 | /* Decode parameters from extended ID */ |
4482 | - nand_decode_ext_id(mtd, chip, id_data, &busw); | |
4486 | + nand_decode_ext_id(mtd, chip, id_data); | |
4483 | 4487 | } else { |
4484 | - nand_decode_id(mtd, chip, type, id_data, &busw); | |
4488 | + nand_decode_id(mtd, chip, type, id_data); | |
4485 | 4489 | } |
4490 | + | |
4486 | 4491 | /* Get chip options */ |
4487 | 4492 | chip->options |= type->options; |
4488 | 4493 |