diff options
Diffstat (limited to 'firmware/target/arm/rk27xx/sd-rk27xx.c')
-rw-r--r-- | firmware/target/arm/rk27xx/sd-rk27xx.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/firmware/target/arm/rk27xx/sd-rk27xx.c b/firmware/target/arm/rk27xx/sd-rk27xx.c index deca8a1fa7..9d6821ee38 100644 --- a/firmware/target/arm/rk27xx/sd-rk27xx.c +++ b/firmware/target/arm/rk27xx/sd-rk27xx.c @@ -22,7 +22,6 @@ ****************************************************************************/ #include "config.h" /* for HAVE_MULTIVOLUME */ -#include "fat.h" #include "thread.h" #include "gcc_extensions.h" #include "led.h" @@ -331,50 +330,45 @@ static void sd_thread(void) { #ifdef HAVE_HOTSWAP case SYS_HOTSWAP_INSERTED: - case SYS_HOTSWAP_EXTRACTED: - { - int microsd_init = 1; - fat_lock(); /* lock-out FAT activity first - - prevent deadlocking via disk_mount that - would cause a reverse-order attempt with - another thread */ - mutex_lock(&sd_mtx); /* lock-out card activity - direct calls - into driver that bypass the fat cache */ - - /* We now have exclusive control of fat cache and ata */ - - disk_unmount(sd_first_drive); /* release "by force", ensure file - descriptors aren't leaked and any busy - ones are invalid if mounting */ + case SYS_HOTSWAP_EXTRACTED:; + int success = 1; + + disk_unmount(sd_first_drive); /* release "by force" */ + + mutex_lock(&sd_mtx); /* lock-out card activity */ + /* Force card init for new card, re-init for re-inserted one or * clear if the last attempt to init failed with an error. */ card_info.initialized = 0; if (ev.id == SYS_HOTSWAP_INSERTED) { + success = 0; sd_enable(true); - microsd_init = sd_init_card(sd_first_drive); - if (microsd_init < 0) /* initialisation failed */ - panicf("microSD init failed : %d", microsd_init); - - microsd_init = disk_mount(sd_first_drive); /* 0 if fail */ + int rc = sd_init_card(sd_first_drive); + sd_enable(false); + if (rc >= 0) + success = 2; + else /* initialisation failed */ + panicf("microSD init failed : %d", rc); } + /* Access is now safe */ + mutex_unlock(&sd_mtx); + + if (success > 1) + success = disk_mount(sd_first_drive); /* 0 if fail */ + /* * Mount succeeded, or this was an EXTRACTED event, * in both cases notify the system about the changed filesystems */ - if (microsd_init) + if (success) queue_broadcast(SYS_FS_CHANGED, 0); - sd_enable(false); - - /* Access is now safe */ - mutex_unlock(&sd_mtx); - fat_unlock(); - } break; -#endif +#endif /* HAVE_HOTSWAP */ + case SYS_TIMEOUT: if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) { |