@@ -169,6 +169,18 @@ static int onenand_buffer_address(int dataram1, int sectors, int count)
169169 return ((bsa << ONENAND_BSA_SHIFT ) | bsc );
170170}
171171
172+ /**
173+ * onenand_get_density - [DEFAULT] Get OneNAND density
174+ * @param dev_id OneNAND device ID
175+ *
176+ * Get OneNAND density from device ID
177+ */
178+ static inline int onenand_get_density (int dev_id )
179+ {
180+ int density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT ;
181+ return (density & ONENAND_DEVICE_DENSITY_MASK );
182+ }
183+
172184/**
173185 * onenand_command - [DEFAULT] Send command to OneNAND device
174186 * @param mtd MTD device structure
@@ -182,8 +194,7 @@ static int onenand_buffer_address(int dataram1, int sectors, int count)
182194static int onenand_command (struct mtd_info * mtd , int cmd , loff_t addr , size_t len )
183195{
184196 struct onenand_chip * this = mtd -> priv ;
185- int value , readcmd = 0 , block_cmd = 0 ;
186- int block , page ;
197+ int value , block , page ;
187198
188199 /* Address translation */
189200 switch (cmd ) {
@@ -198,7 +209,6 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
198209 case ONENAND_CMD_ERASE :
199210 case ONENAND_CMD_BUFFERRAM :
200211 case ONENAND_CMD_OTP_ACCESS :
201- block_cmd = 1 ;
202212 block = (int ) (addr >> this -> erase_shift );
203213 page = -1 ;
204214 break ;
@@ -240,11 +250,9 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
240250 value = onenand_block_address (this , block );
241251 this -> write_word (value , this -> base + ONENAND_REG_START_ADDRESS1 );
242252
243- if (block_cmd ) {
244- /* Select DataRAM for DDP */
245- value = onenand_bufferram_address (this , block );
246- this -> write_word (value , this -> base + ONENAND_REG_START_ADDRESS2 );
247- }
253+ /* Select DataRAM for DDP */
254+ value = onenand_bufferram_address (this , block );
255+ this -> write_word (value , this -> base + ONENAND_REG_START_ADDRESS2 );
248256 }
249257
250258 if (page != -1 ) {
@@ -256,7 +264,6 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
256264 case ONENAND_CMD_READ :
257265 case ONENAND_CMD_READOOB :
258266 dataram = ONENAND_SET_NEXT_BUFFERRAM (this );
259- readcmd = 1 ;
260267 break ;
261268
262269 default :
@@ -273,12 +280,6 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
273280 /* Write 'BSA, BSC' of DataRAM */
274281 value = onenand_buffer_address (dataram , sectors , count );
275282 this -> write_word (value , this -> base + ONENAND_REG_START_BUFFER );
276-
277- if (readcmd ) {
278- /* Select DataRAM for DDP */
279- value = onenand_bufferram_address (this , block );
280- this -> write_word (value , this -> base + ONENAND_REG_START_ADDRESS2 );
281- }
282283 }
283284
284285 /* Interrupt clear */
@@ -1118,12 +1119,10 @@ static int onenand_bbt_wait(struct mtd_info *mtd, int state)
11181119 interrupt = this -> read_word (this -> base + ONENAND_REG_INTERRUPT );
11191120 ctrl = this -> read_word (this -> base + ONENAND_REG_CTRL_STATUS );
11201121
1122+ /* Initial bad block case: 0x2400 or 0x0400 */
11211123 if (ctrl & ONENAND_CTRL_ERROR ) {
11221124 printk (KERN_DEBUG "onenand_bbt_wait: controller error = 0x%04x\n" , ctrl );
1123- /* Initial bad block case */
1124- if (ctrl & ONENAND_CTRL_LOAD )
1125- return ONENAND_BBT_READ_ERROR ;
1126- return ONENAND_BBT_READ_FATAL_ERROR ;
1125+ return ONENAND_BBT_READ_ERROR ;
11271126 }
11281127
11291128 if (interrupt & ONENAND_INT_READ ) {
@@ -1218,7 +1217,7 @@ int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
12181217static int onenand_verify_oob (struct mtd_info * mtd , const u_char * buf , loff_t to )
12191218{
12201219 struct onenand_chip * this = mtd -> priv ;
1221- char oobbuf [ 64 ] ;
1220+ u_char * oob_buf = this -> oob_buf ;
12221221 int status , i ;
12231222
12241223 this -> command (mtd , ONENAND_CMD_READOOB , to , mtd -> oobsize );
@@ -1227,9 +1226,9 @@ static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to
12271226 if (status )
12281227 return status ;
12291228
1230- this -> read_bufferram (mtd , ONENAND_SPARERAM , oobbuf , 0 , mtd -> oobsize );
1229+ this -> read_bufferram (mtd , ONENAND_SPARERAM , oob_buf , 0 , mtd -> oobsize );
12311230 for (i = 0 ; i < mtd -> oobsize ; i ++ )
1232- if (buf [i ] != 0xFF && buf [i ] != oobbuf [i ])
1231+ if (buf [i ] != 0xFF && buf [i ] != oob_buf [i ])
12331232 return - EBADMSG ;
12341233
12351234 return 0 ;
@@ -1431,7 +1430,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
14311430 }
14321431
14331432 /* Only check verify write turn on */
1434- ret = onenand_verify (mtd , ( u_char * ) wbuf , to , thislen );
1433+ ret = onenand_verify (mtd , buf , to , thislen );
14351434 if (ret ) {
14361435 printk (KERN_ERR "onenand_write_ops_nolock: verify failed %d\n" , ret );
14371436 break ;
@@ -1447,9 +1446,6 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
14471446 buf += thislen ;
14481447 }
14491448
1450- /* Deselect and wake up anyone waiting on the device */
1451- onenand_release_device (mtd );
1452-
14531449 ops -> retlen = written ;
14541450
14551451 return ret ;
@@ -2160,7 +2156,7 @@ static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,
21602156
21612157 * retlen = 0 ;
21622158
2163- density = this -> device_id >> ONENAND_DEVICE_DENSITY_SHIFT ;
2159+ density = onenand_get_density ( this -> device_id ) ;
21642160 if (density < ONENAND_DEVICE_DENSITY_512Mb )
21652161 otp_pages = 20 ;
21662162 else
@@ -2311,7 +2307,8 @@ static int onenand_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
23112307static int onenand_lock_user_prot_reg (struct mtd_info * mtd , loff_t from ,
23122308 size_t len )
23132309{
2314- unsigned char oob_buf [64 ];
2310+ struct onenand_chip * this = mtd -> priv ;
2311+ u_char * oob_buf = this -> oob_buf ;
23152312 size_t retlen ;
23162313 int ret ;
23172314
@@ -2351,7 +2348,7 @@ static void onenand_check_features(struct mtd_info *mtd)
23512348 unsigned int density , process ;
23522349
23532350 /* Lock scheme depends on density and process */
2354- density = this -> device_id >> ONENAND_DEVICE_DENSITY_SHIFT ;
2351+ density = onenand_get_density ( this -> device_id ) ;
23552352 process = this -> version_id >> ONENAND_VERSION_PROCESS_SHIFT ;
23562353
23572354 /* Lock scheme */
@@ -2400,7 +2397,7 @@ static void onenand_print_device_info(int device, int version)
24002397 vcc = device & ONENAND_DEVICE_VCC_MASK ;
24012398 demuxed = device & ONENAND_DEVICE_IS_DEMUX ;
24022399 ddp = device & ONENAND_DEVICE_IS_DDP ;
2403- density = device >> ONENAND_DEVICE_DENSITY_SHIFT ;
2400+ density = onenand_get_density ( device ) ;
24042401 printk (KERN_INFO "%sOneNAND%s %dMB %sV 16-bit (0x%02x)\n" ,
24052402 demuxed ? "" : "Muxed " ,
24062403 ddp ? "(DDP)" : "" ,
@@ -2492,7 +2489,7 @@ static int onenand_probe(struct mtd_info *mtd)
24922489 this -> device_id = dev_id ;
24932490 this -> version_id = ver_id ;
24942491
2495- density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT ;
2492+ density = onenand_get_density ( dev_id ) ;
24962493 this -> chipsize = (16 << density ) << 20 ;
24972494 /* Set density mask. it is used for DDP */
24982495 if (ONENAND_IS_DDP (this ))
0 commit comments