diff options
Diffstat (limited to 'firmware/target/arm/as3525')
-rw-r--r-- | firmware/target/arm/as3525/sd-as3525.c | 44 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sd-as3525v2.c | 41 |
2 files changed, 36 insertions, 49 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c index c80c7f7491..ead40eac3c 100644 --- a/firmware/target/arm/as3525/sd-as3525.c +++ b/firmware/target/arm/as3525/sd-as3525.c | |||
@@ -449,21 +449,12 @@ static void sd_thread(void) | |||
449 | { | 449 | { |
450 | #ifdef HAVE_HOTSWAP | 450 | #ifdef HAVE_HOTSWAP |
451 | case SYS_HOTSWAP_INSERTED: | 451 | case SYS_HOTSWAP_INSERTED: |
452 | case SYS_HOTSWAP_EXTRACTED: | 452 | case SYS_HOTSWAP_EXTRACTED:; |
453 | { | 453 | int success = 1; |
454 | int microsd_init = 1; | ||
455 | fat_lock(); /* lock-out FAT activity first - | ||
456 | prevent deadlocking via disk_mount that | ||
457 | would cause a reverse-order attempt with | ||
458 | another thread */ | ||
459 | mutex_lock(&sd_mtx); /* lock-out card activity - direct calls | ||
460 | into driver that bypass the fat cache */ | ||
461 | 454 | ||
462 | /* We now have exclusive control of fat cache and ata */ | 455 | disk_unmount(SD_SLOT_AS3525); /* release "by force" */ |
463 | 456 | ||
464 | disk_unmount(SD_SLOT_AS3525); /* release "by force", ensure file | 457 | mutex_lock(&sd_mtx); /* lock-out card activity */ |
465 | descriptors aren't leaked and any busy | ||
466 | ones are invalid if mounting */ | ||
467 | 458 | ||
468 | /* Force card init for new card, re-init for re-inserted one or | 459 | /* Force card init for new card, re-init for re-inserted one or |
469 | * clear if the last attempt to init failed with an error. */ | 460 | * clear if the last attempt to init failed with an error. */ |
@@ -471,29 +462,32 @@ static void sd_thread(void) | |||
471 | 462 | ||
472 | if (ev.id == SYS_HOTSWAP_INSERTED) | 463 | if (ev.id == SYS_HOTSWAP_INSERTED) |
473 | { | 464 | { |
465 | success = 0; | ||
474 | sd_enable(true); | 466 | sd_enable(true); |
475 | init_pl180_controller(SD_SLOT_AS3525); | 467 | init_pl180_controller(SD_SLOT_AS3525); |
476 | microsd_init = sd_init_card(SD_SLOT_AS3525); | 468 | int rc = sd_init_card(SD_SLOT_AS3525); |
477 | if (microsd_init < 0) /* initialisation failed */ | 469 | sd_enable(false); |
478 | panicf("microSD init failed : %d", microsd_init); | 470 | if (rc >= 0) |
479 | 471 | success = 2; | |
480 | microsd_init = disk_mount(SD_SLOT_AS3525); /* 0 if fail */ | 472 | else /* initialisation failed */ |
473 | panicf("microSD init failed : %d", rc); | ||
481 | } | 474 | } |
482 | 475 | ||
476 | mutex_unlock(&sd_mtx); | ||
477 | |||
478 | if (success > 1) | ||
479 | success = disk_mount(SD_SLOT_AS3525); /* 0 if fail */ | ||
480 | |||
483 | /* | 481 | /* |
484 | * Mount succeeded, or this was an EXTRACTED event, | 482 | * Mount succeeded, or this was an EXTRACTED event, |
485 | * in both cases notify the system about the changed filesystems | 483 | * in both cases notify the system about the changed filesystems |
486 | */ | 484 | */ |
487 | if (microsd_init) | 485 | if (success) |
488 | queue_broadcast(SYS_FS_CHANGED, 0); | 486 | queue_broadcast(SYS_FS_CHANGED, 0); |
489 | 487 | ||
490 | /* Access is now safe */ | ||
491 | mutex_unlock(&sd_mtx); | ||
492 | fat_unlock(); | ||
493 | sd_enable(false); | ||
494 | } | ||
495 | break; | 488 | break; |
496 | #endif | 489 | #endif /* HAVE_HOTSWAP */ |
490 | |||
497 | case SYS_TIMEOUT: | 491 | case SYS_TIMEOUT: |
498 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) | 492 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) |
499 | { | 493 | { |
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c index ae3dde4495..b4ac40152b 100644 --- a/firmware/target/arm/as3525/sd-as3525v2.c +++ b/firmware/target/arm/as3525/sd-as3525v2.c | |||
@@ -598,21 +598,13 @@ static void sd_thread(void) | |||
598 | { | 598 | { |
599 | #ifdef HAVE_HOTSWAP | 599 | #ifdef HAVE_HOTSWAP |
600 | case SYS_HOTSWAP_INSERTED: | 600 | case SYS_HOTSWAP_INSERTED: |
601 | case SYS_HOTSWAP_EXTRACTED: | 601 | case SYS_HOTSWAP_EXTRACTED:; |
602 | { | 602 | int success = 1; |
603 | int changed = 1; | 603 | |
604 | fat_lock(); /* lock-out FAT activity first - | 604 | disk_unmount(SD_SLOT_AS3525); /* release "by force" */ |
605 | prevent deadlocking via disk_mount that | 605 | |
606 | would cause a reverse-order attempt with | 606 | mutex_lock(&sd_mtx); /* lock-out card activity */ |
607 | another thread */ | 607 | |
608 | mutex_lock(&sd_mtx); /* lock-out card activity - direct calls | ||
609 | into driver that bypass the fat cache */ | ||
610 | |||
611 | /* We now have exclusive control of fat cache and ata */ | ||
612 | |||
613 | disk_unmount(SD_SLOT_AS3525); /* release "by force", ensure file | ||
614 | descriptors aren't leaked and any busy | ||
615 | ones are invalid if mounting */ | ||
616 | /* Force card init for new card, re-init for re-inserted one or | 608 | /* Force card init for new card, re-init for re-inserted one or |
617 | * clear if the last attempt to init failed with an error. */ | 609 | * clear if the last attempt to init failed with an error. */ |
618 | card_info[SD_SLOT_AS3525].initialized = 0; | 610 | card_info[SD_SLOT_AS3525].initialized = 0; |
@@ -620,24 +612,25 @@ static void sd_thread(void) | |||
620 | if (ev.id == SYS_HOTSWAP_INSERTED) | 612 | if (ev.id == SYS_HOTSWAP_INSERTED) |
621 | { | 613 | { |
622 | sd_enable(true); | 614 | sd_enable(true); |
623 | changed = (sd_init_card(SD_SLOT_AS3525) == 0) && disk_mount(SD_SLOT_AS3525); /* 0 if fail */ | 615 | success = sd_init_card(SD_SLOT_AS3525) == 0 ? 2 : 0; |
616 | sd_enable(false); | ||
624 | } | 617 | } |
625 | 618 | ||
619 | mutex_unlock(&sd_mtx); | ||
620 | |||
621 | if (success > 1) | ||
622 | success = disk_mount(SD_SLOT_AS3525); /* 0 if fail */ | ||
623 | |||
626 | /* | 624 | /* |
627 | * Mount succeeded, or this was an EXTRACTED event, | 625 | * Mount succeeded, or this was an EXTRACTED event, |
628 | * in both cases notify the system about the changed filesystems | 626 | * in both cases notify the system about the changed filesystems |
629 | */ | 627 | */ |
630 | if (changed) | 628 | if (success) |
631 | queue_broadcast(SYS_FS_CHANGED, 0); | 629 | queue_broadcast(SYS_FS_CHANGED, 0); |
632 | 630 | ||
633 | sd_enable(false); | ||
634 | |||
635 | /* Access is now safe */ | ||
636 | mutex_unlock(&sd_mtx); | ||
637 | fat_unlock(); | ||
638 | } | ||
639 | break; | 631 | break; |
640 | #endif | 632 | #endif /* HAVE_HOTSWAP */ |
633 | |||
641 | case SYS_TIMEOUT: | 634 | case SYS_TIMEOUT: |
642 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) | 635 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) |
643 | { | 636 | { |