Skip to content

Commit e4fe4d2

Browse files
Bichao Zhengtobetter
authored andcommitted
nand: fix nand bugs [1/1]
PD#SWPL-120491 PD#SWPL-129754 PD#SWPL-155674 PD#SWPL-183416 Problem: 1.wrong select onfi mode 2.erase flash error during OTA upgrade 3.strncmp can't match full id 01h,DCh,00h,05h,04h(S34ML04G300BHI00) and 01h,DCh,00h,1Ah,00h(S34ML04G300TFI000) 4.mtd_device_parse_register panic when parse_mtd_partitions return -EPROBE_DEFER Solution: 1.get onfi mode from id table 2.change the check way of badblock 3.use memcmp to compare ID memory instead strncmp 4.nvmem_unregister otp_user_nvmem/otp_factory_nvmem if them existing Verify: 1-2:s4 3:AT301_T962D4-K35E(1.5G) #256 4:BR309-T950D5_SOCKET #48 Change-Id: Ie747ceb95f1045c2acaaf2afb6862c9b05d36d8b Signed-off-by: Bichao Zheng <[email protected]> Signed-off-by: zhikui.cui <[email protected]>
1 parent 146c08e commit e4fe4d2

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

drivers/mtd/mtdcore.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,15 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
10081008

10091009
out:
10101010
if (ret) {
1011+
#if (IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND) || IS_ENABLED(CONFIG_AMLOGIC_MTD_SPI_NAND))
1012+
if (mtd->otp_user_nvmem)
1013+
nvmem_unregister(mtd->otp_user_nvmem);
1014+
if (mtd->otp_factory_nvmem)
1015+
nvmem_unregister(mtd->otp_factory_nvmem);
1016+
#else
10111017
nvmem_unregister(mtd->otp_user_nvmem);
10121018
nvmem_unregister(mtd->otp_factory_nvmem);
1019+
#endif
10131020
}
10141021

10151022
if (ret && device_is_registered(&mtd->dev))

drivers/mtd/nand/raw/nand_base.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,10 @@ int nand_choose_best_sdr_timings(struct nand_chip *chip,
963963
return ret;
964964
}
965965

966+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
967+
EXPORT_SYMBOL_GPL(nand_choose_best_sdr_timings);
968+
#endif
969+
966970
/**
967971
* nand_choose_best_nvddr_timings - Pick up the best NVDDR timings that both the
968972
* NAND controller and the NAND chip support
@@ -4891,7 +4895,12 @@ static bool find_full_id_nand(struct nand_chip *chip,
48914895

48924896
memorg = nanddev_get_memorg(&chip->base);
48934897

4898+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
4899+
if (!memcmp(type->id, id_data, type->id_len)) {
4900+
#else
48944901
if (!strncmp(type->id, id_data, type->id_len)) {
4902+
#endif
4903+
48954904
memorg->pagesize = type->pagesize;
48964905
mtd->writesize = memorg->pagesize;
48974906
memorg->pages_per_eraseblock = type->erasesize /
@@ -5151,7 +5160,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
51515160
chip->options |= NAND_ROW_ADDR_3;
51525161

51535162
chip->badblockbits = 8;
5154-
5163+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
5164+
chip->type = type;
5165+
#endif
51555166
nand_legacy_adjust_cmdfunc(chip);
51565167

51575168
pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n",

drivers/mtd/nand/raw/nand_bbt.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@
7575

7676
static inline uint8_t bbt_get_entry(struct nand_chip *chip, int block)
7777
{
78+
#if !IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
7879
uint8_t entry = chip->bbt[block >> BBT_ENTRY_SHIFT];
7980
entry >>= (block & BBT_ENTRY_MASK) * 2;
8081
return entry & BBT_ENTRY_MASK;
82+
#else
83+
if (chip->bbt)
84+
return chip->bbt[block];
85+
86+
return 1;
87+
#endif
8188
}
8289

8390
static inline void bbt_mark_entry(struct nand_chip *chip, int block,
@@ -1454,7 +1461,7 @@ int nand_isbad_bbt(struct nand_chip *this, loff_t offs, int allowbbt)
14541461

14551462
pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
14561463
(unsigned int)offs, block, res);
1457-
1464+
#if !IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
14581465
switch (res) {
14591466
case BBT_BLOCK_GOOD:
14601467
return 0;
@@ -1464,6 +1471,9 @@ int nand_isbad_bbt(struct nand_chip *this, loff_t offs, int allowbbt)
14641471
return allowbbt ? 0 : 1;
14651472
}
14661473
return 1;
1474+
#else
1475+
return res ? 1 : 0;
1476+
#endif
14671477
}
14681478

14691479
/**

drivers/mtd/nand/raw/nand_timings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,7 @@ void onfi_fill_interface_config(struct nand_chip *chip,
735735
else
736736
return onfi_fill_nvddr_interface_config(chip, iface, timing_mode);
737737
}
738+
739+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
740+
EXPORT_SYMBOL_GPL(onfi_fill_interface_config);
741+
#endif

include/linux/mtd/rawnand.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,9 @@ struct nand_chip {
13041304
/* Externals */
13051305
struct nand_controller *controller;
13061306
struct nand_ecc_ctrl ecc;
1307+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
1308+
struct nand_flash_dev *type;
1309+
#endif
13071310
void *priv;
13081311
};
13091312

@@ -1432,6 +1435,9 @@ struct nand_flash_dev {
14321435
uint16_t strength_ds;
14331436
uint16_t step_ds;
14341437
} ecc;
1438+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
1439+
int onfi_timing_mode_default;
1440+
#endif
14351441
};
14361442

14371443
int nand_create_bbt(struct nand_chip *chip);
@@ -1548,6 +1554,17 @@ int nand_read_page_hwecc_oob_first(struct nand_chip *chip, uint8_t *buf,
15481554
int nand_scan_with_ids(struct nand_chip *chip, unsigned int max_chips,
15491555
struct nand_flash_dev *ids);
15501556

1557+
#if IS_ENABLED(CONFIG_AMLOGIC_MTD_NAND)
1558+
void onfi_fill_interface_config(struct nand_chip *chip,
1559+
struct nand_interface_config *iface,
1560+
enum nand_interface_type type,
1561+
unsigned int timing_mode);
1562+
1563+
int nand_choose_best_sdr_timings(struct nand_chip *chip,
1564+
struct nand_interface_config *iface,
1565+
struct nand_sdr_timings *spec_timings);
1566+
#endif
1567+
15511568
static inline int nand_scan(struct nand_chip *chip, unsigned int max_chips)
15521569
{
15531570
return nand_scan_with_ids(chip, max_chips, NULL);

0 commit comments

Comments
 (0)