@@ -3819,7 +3819,7 @@ static int nand_get_bits_per_cell(u8 cellinfo)
38193819 * chip. The rest of the parameters must be decoded according to generic or
38203820 * manufacturer-specific "extended ID" decoding patterns.
38213821 */
3822- static void nand_decode_ext_id (struct nand_chip * chip )
3822+ void nand_decode_ext_id (struct nand_chip * chip )
38233823{
38243824 struct mtd_info * mtd = nand_to_mtd (chip );
38253825 int extid , id_len = chip -> id .len ;
@@ -3944,6 +3944,7 @@ static void nand_decode_ext_id(struct nand_chip *chip)
39443944
39453945 }
39463946}
3947+ EXPORT_SYMBOL_GPL (nand_decode_ext_id );
39473948
39483949/*
39493950 * Old devices have chip data hardcoded in the device ID table. nand_decode_id
@@ -4047,6 +4048,53 @@ static bool find_full_id_nand(struct nand_chip *chip,
40474048 return false;
40484049}
40494050
4051+ /*
4052+ * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC
4053+ * compliant and does not have a full-id or legacy-id entry in the nand_ids
4054+ * table.
4055+ */
4056+ static void nand_manufacturer_detect (struct nand_chip * chip )
4057+ {
4058+ /*
4059+ * Try manufacturer detection if available and use
4060+ * nand_decode_ext_id() otherwise.
4061+ */
4062+ if (chip -> manufacturer .desc && chip -> manufacturer .desc -> ops &&
4063+ chip -> manufacturer .desc -> ops -> detect )
4064+ chip -> manufacturer .desc -> ops -> detect (chip );
4065+ else
4066+ nand_decode_ext_id (chip );
4067+ }
4068+
4069+ /*
4070+ * Manufacturer initialization. This function is called for all NANDs including
4071+ * ONFI and JEDEC compliant ones.
4072+ * Manufacturer drivers should put all their specific initialization code in
4073+ * their ->init() hook.
4074+ */
4075+ static int nand_manufacturer_init (struct nand_chip * chip )
4076+ {
4077+ if (!chip -> manufacturer .desc || !chip -> manufacturer .desc -> ops ||
4078+ !chip -> manufacturer .desc -> ops -> init )
4079+ return 0 ;
4080+
4081+ return chip -> manufacturer .desc -> ops -> init (chip );
4082+ }
4083+
4084+ /*
4085+ * Manufacturer cleanup. This function is called for all NANDs including
4086+ * ONFI and JEDEC compliant ones.
4087+ * Manufacturer drivers should put all their specific cleanup code in their
4088+ * ->cleanup() hook.
4089+ */
4090+ static void nand_manufacturer_cleanup (struct nand_chip * chip )
4091+ {
4092+ /* Release manufacturer private data */
4093+ if (chip -> manufacturer .desc && chip -> manufacturer .desc -> ops &&
4094+ chip -> manufacturer .desc -> ops -> cleanup )
4095+ chip -> manufacturer .desc -> ops -> cleanup (chip );
4096+ }
4097+
40504098/*
40514099 * Get the flash and manufacturer id and lookup if the type is supported.
40524100 */
@@ -4055,7 +4103,7 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
40554103 const struct nand_manufacturer * manufacturer ;
40564104 struct mtd_info * mtd = nand_to_mtd (chip );
40574105 int busw ;
4058- int i ;
4106+ int i , ret ;
40594107 u8 * id_data = chip -> id .data ;
40604108 u8 maf_id , dev_id ;
40614109
@@ -4096,6 +4144,10 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
40964144
40974145 chip -> id .len = nand_id_len (id_data , 8 );
40984146
4147+ /* Try to identify manufacturer */
4148+ manufacturer = nand_get_manufacturer (maf_id );
4149+ chip -> manufacturer .desc = manufacturer ;
4150+
40994151 if (!type )
41004152 type = nand_flash_ids ;
41014153
@@ -4142,12 +4194,11 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
41424194
41434195 chip -> chipsize = (uint64_t )type -> chipsize << 20 ;
41444196
4145- if (!type -> pagesize ) {
4146- /* Decode parameters from extended ID */
4147- nand_decode_ext_id (chip );
4148- } else {
4197+ if (!type -> pagesize )
4198+ nand_manufacturer_detect (chip );
4199+ else
41494200 nand_decode_id (chip , type );
4150- }
4201+
41514202 /* Get chip options */
41524203 chip -> options |= type -> options ;
41534204
@@ -4159,9 +4210,6 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
41594210 chip -> options &= ~NAND_SAMSUNG_LP_OPTIONS ;
41604211ident_done :
41614212
4162- /* Try to identify manufacturer */
4163- manufacturer = nand_get_manufacturer (maf_id );
4164-
41654213 if (chip -> options & NAND_BUSWIDTH_AUTO ) {
41664214 WARN_ON (busw & NAND_BUSWIDTH_16 );
41674215 nand_set_defaults (chip );
@@ -4202,6 +4250,10 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
42024250 if (mtd -> writesize > 512 && chip -> cmdfunc == nand_command )
42034251 chip -> cmdfunc = nand_command_lp ;
42044252
4253+ ret = nand_manufacturer_init (chip );
4254+ if (ret )
4255+ return ret ;
4256+
42054257 pr_info ("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n" ,
42064258 maf_id , dev_id );
42074259
@@ -4947,6 +4999,9 @@ void nand_cleanup(struct nand_chip *chip)
49474999 if (chip -> badblock_pattern && chip -> badblock_pattern -> options
49485000 & NAND_BBT_DYNAMICSTRUCT )
49495001 kfree (chip -> badblock_pattern );
5002+
5003+ /* Free manufacturer priv data. */
5004+ nand_manufacturer_cleanup (chip );
49505005}
49515006EXPORT_SYMBOL_GPL (nand_cleanup );
49525007
0 commit comments