diff options
Diffstat (limited to 'firmware/target/arm/rk27xx')
-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 @@ | |||
22 | ****************************************************************************/ | 22 | ****************************************************************************/ |
23 | 23 | ||
24 | #include "config.h" /* for HAVE_MULTIVOLUME */ | 24 | #include "config.h" /* for HAVE_MULTIVOLUME */ |
25 | #include "fat.h" | ||
26 | #include "thread.h" | 25 | #include "thread.h" |
27 | #include "gcc_extensions.h" | 26 | #include "gcc_extensions.h" |
28 | #include "led.h" | 27 | #include "led.h" |
@@ -331,50 +330,45 @@ static void sd_thread(void) | |||
331 | { | 330 | { |
332 | #ifdef HAVE_HOTSWAP | 331 | #ifdef HAVE_HOTSWAP |
333 | case SYS_HOTSWAP_INSERTED: | 332 | case SYS_HOTSWAP_INSERTED: |
334 | case SYS_HOTSWAP_EXTRACTED: | 333 | case SYS_HOTSWAP_EXTRACTED:; |
335 | { | 334 | int success = 1; |
336 | int microsd_init = 1; | 335 | |
337 | fat_lock(); /* lock-out FAT activity first - | 336 | disk_unmount(sd_first_drive); /* release "by force" */ |
338 | prevent deadlocking via disk_mount that | 337 | |
339 | would cause a reverse-order attempt with | 338 | mutex_lock(&sd_mtx); /* lock-out card activity */ |
340 | another thread */ | 339 | |
341 | mutex_lock(&sd_mtx); /* lock-out card activity - direct calls | ||
342 | into driver that bypass the fat cache */ | ||
343 | |||
344 | /* We now have exclusive control of fat cache and ata */ | ||
345 | |||
346 | disk_unmount(sd_first_drive); /* release "by force", ensure file | ||
347 | descriptors aren't leaked and any busy | ||
348 | ones are invalid if mounting */ | ||
349 | /* Force card init for new card, re-init for re-inserted one or | 340 | /* Force card init for new card, re-init for re-inserted one or |
350 | * clear if the last attempt to init failed with an error. */ | 341 | * clear if the last attempt to init failed with an error. */ |
351 | card_info.initialized = 0; | 342 | card_info.initialized = 0; |
352 | 343 | ||
353 | if (ev.id == SYS_HOTSWAP_INSERTED) | 344 | if (ev.id == SYS_HOTSWAP_INSERTED) |
354 | { | 345 | { |
346 | success = 0; | ||
355 | sd_enable(true); | 347 | sd_enable(true); |
356 | microsd_init = sd_init_card(sd_first_drive); | 348 | int rc = sd_init_card(sd_first_drive); |
357 | if (microsd_init < 0) /* initialisation failed */ | 349 | sd_enable(false); |
358 | panicf("microSD init failed : %d", microsd_init); | 350 | if (rc >= 0) |
359 | 351 | success = 2; | |
360 | microsd_init = disk_mount(sd_first_drive); /* 0 if fail */ | 352 | else /* initialisation failed */ |
353 | panicf("microSD init failed : %d", rc); | ||
361 | } | 354 | } |
362 | 355 | ||
356 | /* Access is now safe */ | ||
357 | mutex_unlock(&sd_mtx); | ||
358 | |||
359 | if (success > 1) | ||
360 | success = disk_mount(sd_first_drive); /* 0 if fail */ | ||
361 | |||
363 | /* | 362 | /* |
364 | * Mount succeeded, or this was an EXTRACTED event, | 363 | * Mount succeeded, or this was an EXTRACTED event, |
365 | * in both cases notify the system about the changed filesystems | 364 | * in both cases notify the system about the changed filesystems |
366 | */ | 365 | */ |
367 | if (microsd_init) | 366 | if (success) |
368 | queue_broadcast(SYS_FS_CHANGED, 0); | 367 | queue_broadcast(SYS_FS_CHANGED, 0); |
369 | 368 | ||
370 | sd_enable(false); | ||
371 | |||
372 | /* Access is now safe */ | ||
373 | mutex_unlock(&sd_mtx); | ||
374 | fat_unlock(); | ||
375 | } | ||
376 | break; | 369 | break; |
377 | #endif | 370 | #endif /* HAVE_HOTSWAP */ |
371 | |||
378 | case SYS_TIMEOUT: | 372 | case SYS_TIMEOUT: |
379 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) | 373 | if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) |
380 | { | 374 | { |