@@ -338,16 +338,19 @@ static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs)
338
338
*
339
339
* Return: -EBUSY if the chip has been suspended, 0 otherwise
340
340
*/
341
- static int nand_get_device (struct nand_chip * chip )
341
+ static void nand_get_device (struct nand_chip * chip )
342
342
{
343
- mutex_lock (& chip -> lock );
344
- if (chip -> suspended ) {
343
+ /* Wait until the device is resumed. */
344
+ while (1 ) {
345
+ mutex_lock (& chip -> lock );
346
+ if (!chip -> suspended ) {
347
+ mutex_lock (& chip -> controller -> lock );
348
+ return ;
349
+ }
345
350
mutex_unlock (& chip -> lock );
346
- return - EBUSY ;
347
- }
348
- mutex_lock (& chip -> controller -> lock );
349
351
350
- return 0 ;
352
+ wait_event (chip -> resume_wq , !chip -> suspended );
353
+ }
351
354
}
352
355
353
356
/**
@@ -576,9 +579,7 @@ static int nand_block_markbad_lowlevel(struct nand_chip *chip, loff_t ofs)
576
579
nand_erase_nand (chip , & einfo , 0 );
577
580
578
581
/* Write bad block marker to OOB */
579
- ret = nand_get_device (chip );
580
- if (ret )
581
- return ret ;
582
+ nand_get_device (chip );
582
583
583
584
ret = nand_markbad_bbm (chip , ofs );
584
585
nand_release_device (chip );
@@ -3826,9 +3827,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
3826
3827
ops -> mode != MTD_OPS_RAW )
3827
3828
return - ENOTSUPP ;
3828
3829
3829
- ret = nand_get_device (chip );
3830
- if (ret )
3831
- return ret ;
3830
+ nand_get_device (chip );
3832
3831
3833
3832
if (!ops -> datbuf )
3834
3833
ret = nand_do_read_oob (chip , from , ops );
@@ -4415,13 +4414,11 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
4415
4414
struct mtd_oob_ops * ops )
4416
4415
{
4417
4416
struct nand_chip * chip = mtd_to_nand (mtd );
4418
- int ret ;
4417
+ int ret = 0 ;
4419
4418
4420
4419
ops -> retlen = 0 ;
4421
4420
4422
- ret = nand_get_device (chip );
4423
- if (ret )
4424
- return ret ;
4421
+ nand_get_device (chip );
4425
4422
4426
4423
switch (ops -> mode ) {
4427
4424
case MTD_OPS_PLACE_OOB :
@@ -4481,9 +4478,7 @@ int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr,
4481
4478
return - EIO ;
4482
4479
4483
4480
/* Grab the lock and see if the device is available */
4484
- ret = nand_get_device (chip );
4485
- if (ret )
4486
- return ret ;
4481
+ nand_get_device (chip );
4487
4482
4488
4483
/* Shift to get first page */
4489
4484
page = (int )(instr -> addr >> chip -> page_shift );
@@ -4570,7 +4565,7 @@ static void nand_sync(struct mtd_info *mtd)
4570
4565
pr_debug ("%s: called\n" , __func__ );
4571
4566
4572
4567
/* Grab the lock and see if the device is available */
4573
- WARN_ON ( nand_get_device (chip ) );
4568
+ nand_get_device (chip );
4574
4569
/* Release it and go back */
4575
4570
nand_release_device (chip );
4576
4571
}
@@ -4587,9 +4582,7 @@ static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
4587
4582
int ret ;
4588
4583
4589
4584
/* Select the NAND device */
4590
- ret = nand_get_device (chip );
4591
- if (ret )
4592
- return ret ;
4585
+ nand_get_device (chip );
4593
4586
4594
4587
nand_select_target (chip , chipnr );
4595
4588
@@ -4660,6 +4653,8 @@ static void nand_resume(struct mtd_info *mtd)
4660
4653
__func__ );
4661
4654
}
4662
4655
mutex_unlock (& chip -> lock );
4656
+
4657
+ wake_up_all (& chip -> resume_wq );
4663
4658
}
4664
4659
4665
4660
/**
@@ -5438,6 +5433,7 @@ static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips,
5438
5433
chip -> cur_cs = -1 ;
5439
5434
5440
5435
mutex_init (& chip -> lock );
5436
+ init_waitqueue_head (& chip -> resume_wq );
5441
5437
5442
5438
/* Enforce the right timings for reset/detection */
5443
5439
chip -> current_interface_config = nand_get_reset_interface_config ();
0 commit comments