aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/lpddr/lpddr_cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/lpddr/lpddr_cmds.c')
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c79
1 files changed, 39 insertions, 40 deletions
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index a73ee12aad81..fece5be58715 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -107,8 +107,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
107 /* those should be reset too since 107 /* those should be reset too since
108 they create memory references. */ 108 they create memory references. */
109 init_waitqueue_head(&chip->wq); 109 init_waitqueue_head(&chip->wq);
110 spin_lock_init(&chip->_spinlock); 110 mutex_init(&chip->mutex);
111 chip->mutex = &chip->_spinlock;
112 chip++; 111 chip++;
113 } 112 }
114 } 113 }
@@ -144,7 +143,7 @@ static int wait_for_ready(struct map_info *map, struct flchip *chip,
144 } 143 }
145 144
146 /* OK Still waiting. Drop the lock, wait a while and retry. */ 145 /* OK Still waiting. Drop the lock, wait a while and retry. */
147 spin_unlock(chip->mutex); 146 mutex_unlock(&chip->mutex);
148 if (sleep_time >= 1000000/HZ) { 147 if (sleep_time >= 1000000/HZ) {
149 /* 148 /*
150 * Half of the normal delay still remaining 149 * Half of the normal delay still remaining
@@ -159,17 +158,17 @@ static int wait_for_ready(struct map_info *map, struct flchip *chip,
159 cond_resched(); 158 cond_resched();
160 timeo--; 159 timeo--;
161 } 160 }
162 spin_lock(chip->mutex); 161 mutex_lock(&chip->mutex);
163 162
164 while (chip->state != chip_state) { 163 while (chip->state != chip_state) {
165 /* Someone's suspended the operation: sleep */ 164 /* Someone's suspended the operation: sleep */
166 DECLARE_WAITQUEUE(wait, current); 165 DECLARE_WAITQUEUE(wait, current);
167 set_current_state(TASK_UNINTERRUPTIBLE); 166 set_current_state(TASK_UNINTERRUPTIBLE);
168 add_wait_queue(&chip->wq, &wait); 167 add_wait_queue(&chip->wq, &wait);
169 spin_unlock(chip->mutex); 168 mutex_unlock(&chip->mutex);
170 schedule(); 169 schedule();
171 remove_wait_queue(&chip->wq, &wait); 170 remove_wait_queue(&chip->wq, &wait);
172 spin_lock(chip->mutex); 171 mutex_lock(&chip->mutex);
173 } 172 }
174 if (chip->erase_suspended || chip->write_suspended) { 173 if (chip->erase_suspended || chip->write_suspended) {
175 /* Suspend has occured while sleep: reset timeout */ 174 /* Suspend has occured while sleep: reset timeout */
@@ -230,20 +229,20 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
230 * it'll happily send us to sleep. In any case, when 229 * it'll happily send us to sleep. In any case, when
231 * get_chip returns success we're clear to go ahead. 230 * get_chip returns success we're clear to go ahead.
232 */ 231 */
233 ret = spin_trylock(contender->mutex); 232 ret = mutex_trylock(&contender->mutex);
234 spin_unlock(&shared->lock); 233 spin_unlock(&shared->lock);
235 if (!ret) 234 if (!ret)
236 goto retry; 235 goto retry;
237 spin_unlock(chip->mutex); 236 mutex_unlock(&chip->mutex);
238 ret = chip_ready(map, contender, mode); 237 ret = chip_ready(map, contender, mode);
239 spin_lock(chip->mutex); 238 mutex_lock(&chip->mutex);
240 239
241 if (ret == -EAGAIN) { 240 if (ret == -EAGAIN) {
242 spin_unlock(contender->mutex); 241 mutex_unlock(&contender->mutex);
243 goto retry; 242 goto retry;
244 } 243 }
245 if (ret) { 244 if (ret) {
246 spin_unlock(contender->mutex); 245 mutex_unlock(&contender->mutex);
247 return ret; 246 return ret;
248 } 247 }
249 spin_lock(&shared->lock); 248 spin_lock(&shared->lock);
@@ -252,10 +251,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
252 * state. Put contender and retry. */ 251 * state. Put contender and retry. */
253 if (chip->state == FL_SYNCING) { 252 if (chip->state == FL_SYNCING) {
254 put_chip(map, contender); 253 put_chip(map, contender);
255 spin_unlock(contender->mutex); 254 mutex_unlock(&contender->mutex);
256 goto retry; 255 goto retry;
257 } 256 }
258 spin_unlock(contender->mutex); 257 mutex_unlock(&contender->mutex);
259 } 258 }
260 259
261 /* Check if we have suspended erase on this chip. 260 /* Check if we have suspended erase on this chip.
@@ -265,10 +264,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
265 spin_unlock(&shared->lock); 264 spin_unlock(&shared->lock);
266 set_current_state(TASK_UNINTERRUPTIBLE); 265 set_current_state(TASK_UNINTERRUPTIBLE);
267 add_wait_queue(&chip->wq, &wait); 266 add_wait_queue(&chip->wq, &wait);
268 spin_unlock(chip->mutex); 267 mutex_unlock(&chip->mutex);
269 schedule(); 268 schedule();
270 remove_wait_queue(&chip->wq, &wait); 269 remove_wait_queue(&chip->wq, &wait);
271 spin_lock(chip->mutex); 270 mutex_lock(&chip->mutex);
272 goto retry; 271 goto retry;
273 } 272 }
274 273
@@ -337,10 +336,10 @@ static int chip_ready(struct map_info *map, struct flchip *chip, int mode)
337sleep: 336sleep:
338 set_current_state(TASK_UNINTERRUPTIBLE); 337 set_current_state(TASK_UNINTERRUPTIBLE);
339 add_wait_queue(&chip->wq, &wait); 338 add_wait_queue(&chip->wq, &wait);
340 spin_unlock(chip->mutex); 339 mutex_unlock(&chip->mutex);
341 schedule(); 340 schedule();
342 remove_wait_queue(&chip->wq, &wait); 341 remove_wait_queue(&chip->wq, &wait);
343 spin_lock(chip->mutex); 342 mutex_lock(&chip->mutex);
344 return -EAGAIN; 343 return -EAGAIN;
345 } 344 }
346} 345}
@@ -356,12 +355,12 @@ static void put_chip(struct map_info *map, struct flchip *chip)
356 if (shared->writing && shared->writing != chip) { 355 if (shared->writing && shared->writing != chip) {
357 /* give back the ownership */ 356 /* give back the ownership */
358 struct flchip *loaner = shared->writing; 357 struct flchip *loaner = shared->writing;
359 spin_lock(loaner->mutex); 358 mutex_lock(&loaner->mutex);
360 spin_unlock(&shared->lock); 359 spin_unlock(&shared->lock);
361 spin_unlock(chip->mutex); 360 mutex_unlock(&chip->mutex);
362 put_chip(map, loaner); 361 put_chip(map, loaner);
363 spin_lock(chip->mutex); 362 mutex_lock(&chip->mutex);
364 spin_unlock(loaner->mutex); 363 mutex_unlock(&loaner->mutex);
365 wake_up(&chip->wq); 364 wake_up(&chip->wq);
366 return; 365 return;
367 } 366 }
@@ -414,10 +413,10 @@ int do_write_buffer(struct map_info *map, struct flchip *chip,
414 413
415 wbufsize = 1 << lpddr->qinfo->BufSizeShift; 414 wbufsize = 1 << lpddr->qinfo->BufSizeShift;
416 415
417 spin_lock(chip->mutex); 416 mutex_lock(&chip->mutex);
418 ret = get_chip(map, chip, FL_WRITING); 417 ret = get_chip(map, chip, FL_WRITING);
419 if (ret) { 418 if (ret) {
420 spin_unlock(chip->mutex); 419 mutex_unlock(&chip->mutex);
421 return ret; 420 return ret;
422 } 421 }
423 /* Figure out the number of words to write */ 422 /* Figure out the number of words to write */
@@ -478,7 +477,7 @@ int do_write_buffer(struct map_info *map, struct flchip *chip,
478 } 477 }
479 478
480 out: put_chip(map, chip); 479 out: put_chip(map, chip);
481 spin_unlock(chip->mutex); 480 mutex_unlock(&chip->mutex);
482 return ret; 481 return ret;
483} 482}
484 483
@@ -490,10 +489,10 @@ int do_erase_oneblock(struct mtd_info *mtd, loff_t adr)
490 struct flchip *chip = &lpddr->chips[chipnum]; 489 struct flchip *chip = &lpddr->chips[chipnum];
491 int ret; 490 int ret;
492 491
493 spin_lock(chip->mutex); 492 mutex_lock(&chip->mutex);
494 ret = get_chip(map, chip, FL_ERASING); 493 ret = get_chip(map, chip, FL_ERASING);
495 if (ret) { 494 if (ret) {
496 spin_unlock(chip->mutex); 495 mutex_unlock(&chip->mutex);
497 return ret; 496 return ret;
498 } 497 }
499 send_pfow_command(map, LPDDR_BLOCK_ERASE, adr, 0, NULL); 498 send_pfow_command(map, LPDDR_BLOCK_ERASE, adr, 0, NULL);
@@ -505,7 +504,7 @@ int do_erase_oneblock(struct mtd_info *mtd, loff_t adr)
505 goto out; 504 goto out;
506 } 505 }
507 out: put_chip(map, chip); 506 out: put_chip(map, chip);
508 spin_unlock(chip->mutex); 507 mutex_unlock(&chip->mutex);
509 return ret; 508 return ret;
510} 509}
511 510
@@ -518,10 +517,10 @@ static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len,
518 struct flchip *chip = &lpddr->chips[chipnum]; 517 struct flchip *chip = &lpddr->chips[chipnum];
519 int ret = 0; 518 int ret = 0;
520 519
521 spin_lock(chip->mutex); 520 mutex_lock(&chip->mutex);
522 ret = get_chip(map, chip, FL_READY); 521 ret = get_chip(map, chip, FL_READY);
523 if (ret) { 522 if (ret) {
524 spin_unlock(chip->mutex); 523 mutex_unlock(&chip->mutex);
525 return ret; 524 return ret;
526 } 525 }
527 526
@@ -529,7 +528,7 @@ static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len,
529 *retlen = len; 528 *retlen = len;
530 529
531 put_chip(map, chip); 530 put_chip(map, chip);
532 spin_unlock(chip->mutex); 531 mutex_unlock(&chip->mutex);
533 return ret; 532 return ret;
534} 533}
535 534
@@ -569,9 +568,9 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
569 else 568 else
570 thislen = len; 569 thislen = len;
571 /* get the chip */ 570 /* get the chip */
572 spin_lock(chip->mutex); 571 mutex_lock(&chip->mutex);
573 ret = get_chip(map, chip, FL_POINT); 572 ret = get_chip(map, chip, FL_POINT);
574 spin_unlock(chip->mutex); 573 mutex_unlock(&chip->mutex);
575 if (ret) 574 if (ret)
576 break; 575 break;
577 576
@@ -611,7 +610,7 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
611 else 610 else
612 thislen = len; 611 thislen = len;
613 612
614 spin_lock(chip->mutex); 613 mutex_lock(&chip->mutex);
615 if (chip->state == FL_POINT) { 614 if (chip->state == FL_POINT) {
616 chip->ref_point_counter--; 615 chip->ref_point_counter--;
617 if (chip->ref_point_counter == 0) 616 if (chip->ref_point_counter == 0)
@@ -621,7 +620,7 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
621 "pointed region\n", map->name); 620 "pointed region\n", map->name);
622 621
623 put_chip(map, chip); 622 put_chip(map, chip);
624 spin_unlock(chip->mutex); 623 mutex_unlock(&chip->mutex);
625 624
626 len -= thislen; 625 len -= thislen;
627 ofs = 0; 626 ofs = 0;
@@ -727,10 +726,10 @@ int do_xxlock(struct mtd_info *mtd, loff_t adr, uint32_t len, int thunk)
727 int chipnum = adr >> lpddr->chipshift; 726 int chipnum = adr >> lpddr->chipshift;
728 struct flchip *chip = &lpddr->chips[chipnum]; 727 struct flchip *chip = &lpddr->chips[chipnum];
729 728
730 spin_lock(chip->mutex); 729 mutex_lock(&chip->mutex);
731 ret = get_chip(map, chip, FL_LOCKING); 730 ret = get_chip(map, chip, FL_LOCKING);
732 if (ret) { 731 if (ret) {
733 spin_unlock(chip->mutex); 732 mutex_unlock(&chip->mutex);
734 return ret; 733 return ret;
735 } 734 }
736 735
@@ -750,7 +749,7 @@ int do_xxlock(struct mtd_info *mtd, loff_t adr, uint32_t len, int thunk)
750 goto out; 749 goto out;
751 } 750 }
752out: put_chip(map, chip); 751out: put_chip(map, chip);
753 spin_unlock(chip->mutex); 752 mutex_unlock(&chip->mutex);
754 return ret; 753 return ret;
755} 754}
756 755
@@ -771,10 +770,10 @@ int word_program(struct map_info *map, loff_t adr, uint32_t curval)
771 int chipnum = adr >> lpddr->chipshift; 770 int chipnum = adr >> lpddr->chipshift;
772 struct flchip *chip = &lpddr->chips[chipnum]; 771 struct flchip *chip = &lpddr->chips[chipnum];
773 772
774 spin_lock(chip->mutex); 773 mutex_lock(&chip->mutex);
775 ret = get_chip(map, chip, FL_WRITING); 774 ret = get_chip(map, chip, FL_WRITING);
776 if (ret) { 775 if (ret) {
777 spin_unlock(chip->mutex); 776 mutex_unlock(&chip->mutex);
778 return ret; 777 return ret;
779 } 778 }
780 779
@@ -788,7 +787,7 @@ int word_program(struct map_info *map, loff_t adr, uint32_t curval)
788 } 787 }
789 788
790out: put_chip(map, chip); 789out: put_chip(map, chip);
791 spin_unlock(chip->mutex); 790 mutex_unlock(&chip->mutex);
792 return ret; 791 return ret;
793} 792}
794 793