summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/sdmmc-imx233.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233/sdmmc-imx233.c')
-rw-r--r--firmware/target/arm/imx233/sdmmc-imx233.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/firmware/target/arm/imx233/sdmmc-imx233.c b/firmware/target/arm/imx233/sdmmc-imx233.c
index 8f293543ab..87548aef53 100644
--- a/firmware/target/arm/imx233/sdmmc-imx233.c
+++ b/firmware/target/arm/imx233/sdmmc-imx233.c
@@ -766,14 +766,7 @@ static void sdmmc_thread(void)
766 case SYS_HOTSWAP_INSERTED: 766 case SYS_HOTSWAP_INSERTED:
767 case SYS_HOTSWAP_EXTRACTED: 767 case SYS_HOTSWAP_EXTRACTED:
768 { 768 {
769 int microsd_init = 1; 769 int microsd_init = ev.id == SYS_HOTSWAP_INSERTED ? 0 : 1;
770 /* lock-out FAT activity first -
771 * prevent deadlocking via disk_mount that
772 * would cause a reverse-order attempt with
773 * another thread */
774#ifdef HAVE_HOTSWAP
775 fat_lock();
776#endif
777 770
778 /* We now have exclusive control of fat cache and sd. 771 /* We now have exclusive control of fat cache and sd.
779 * Release "by force", ensure file 772 * Release "by force", ensure file
@@ -785,35 +778,37 @@ static void sdmmc_thread(void)
785 /* Skip non-removable drivers */ 778 /* Skip non-removable drivers */
786 if(!sdmmc_removable(drive)) 779 if(!sdmmc_removable(drive))
787 continue; 780 continue;
788 /* lock-out card activity - direct calls 781
789 * into driver that bypass the fat cache */
790 mutex_lock(&mutex[drive]);
791 disk_unmount(sd_first_drive + sd_drive); 782 disk_unmount(sd_first_drive + sd_drive);
783
784 mutex_lock(&mutex[drive]); /* lock-out card activity */
785
792 /* Force card init for new card, re-init for re-inserted one or 786 /* Force card init for new card, re-init for re-inserted one or
793 * clear if the last attempt to init failed with an error. */ 787 * clear if the last attempt to init failed with an error. */
794 SDMMC_INFO(sd_map[sd_drive]).initialized = 0; 788 SDMMC_INFO(sd_map[sd_drive]).initialized = 0;
795 789
790 int rc = -1;
796 if(ev.id == SYS_HOTSWAP_INSERTED) 791 if(ev.id == SYS_HOTSWAP_INSERTED)
797 { 792 {
798 microsd_init = init_drive(drive); 793 rc = init_drive(drive);
799 if(microsd_init < 0) /* initialisation failed */ 794 if(rc < 0) /* initialisation failed */
800 panicf("%s init failed : %d", SDMMC_CONF(sd_map[sd_drive]).name, microsd_init); 795 panicf("%s init failed : %d", SDMMC_CONF(sd_map[sd_drive]).name, rc);
801
802 microsd_init = disk_mount(sd_first_drive + sd_drive); /* 0 if fail */
803 } 796 }
804 /* 797
805 * Mount succeeded, or this was an EXTRACTED event,
806 * in both cases notify the system about the changed filesystems
807 */
808 if(microsd_init)
809 queue_broadcast(SYS_FS_CHANGED, 0);
810 /* unlock card */ 798 /* unlock card */
811 mutex_unlock(&mutex[drive]); 799 mutex_unlock(&mutex[drive]);
800
801 if (rc >= 0)
802 microsd_init += disk_mount(sd_first_drive + sd_drive); /* 0 if fail */
812 } 803 }
813 /* Access is now safe */ 804 /* Access is now safe */
814#ifdef HAVE_HOTSWAP 805 /*
815 fat_unlock(); 806 * One or more mounts succeeded, or this was an EXTRACTED event,
816#endif 807 * in both cases notify the system about the changed filesystems
808 */
809 if(microsd_init)
810 queue_broadcast(SYS_FS_CHANGED, 0);
811
817 break; 812 break;
818 } 813 }
819#endif 814#endif