summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-16 20:48:46 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-17 00:29:24 +0200
commit8ed8a79f5cd596f1941a9720450518ae6a093f3d (patch)
tree9c92fc6bb8c6b5eb44a2ee7ea65c0f448db02f99 /firmware/target/arm
parentfbee03e0f0522abf9071a5762b50f2822f83c645 (diff)
downloadrockbox-8ed8a79f5cd596f1941a9720450518ae6a093f3d.tar.gz
rockbox-8ed8a79f5cd596f1941a9720450518ae6a093f3d.zip
imx233: various sdmmc fixes
Change-Id: I261d0bdea1e7c5bc9139b10bf42e7ce7ce6b6dd8
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/imx233/sdmmc-imx233.c62
1 files changed, 46 insertions, 16 deletions
diff --git a/firmware/target/arm/imx233/sdmmc-imx233.c b/firmware/target/arm/imx233/sdmmc-imx233.c
index 8c18b284fd..b74c21c08c 100644
--- a/firmware/target/arm/imx233/sdmmc-imx233.c
+++ b/firmware/target/arm/imx233/sdmmc-imx233.c
@@ -181,6 +181,19 @@ static int init_drive(int drive);
181 * refer to sd/mmc drive indexes. We keep two maps sd->sdmmc and mmc->sdmmc 181 * refer to sd/mmc drive indexes. We keep two maps sd->sdmmc and mmc->sdmmc
182 * to find the sdmmc index from the sd or mmc one */ 182 * to find the sdmmc index from the sd or mmc one */
183 183
184static int sdmmc_present(int drive)
185{
186 if(SDMMC_FLAGS(drive) & REMOVABLE)
187 return imx233_ssp_sdmmc_detect(SDMMC_SSP(drive));
188 else
189 return true;
190}
191
192static inline int sdmmc_removable(int drive)
193{
194 return SDMMC_FLAGS(drive) & REMOVABLE;
195}
196
184static void sdmmc_detect_callback(int ssp) 197static void sdmmc_detect_callback(int ssp)
185{ 198{
186 /* This is called only if the state was stable for 300ms - check state 199 /* This is called only if the state was stable for 300ms - check state
@@ -291,7 +304,6 @@ static int init_sd_card(int drive)
291 /* SSPCLK @ 96MHz 304 /* SSPCLK @ 96MHz
292 * gives bitrate of 96000 / 240 / 1 = 400kHz */ 305 * gives bitrate of 96000 / 240 / 1 = 400kHz */
293 imx233_ssp_set_timings(ssp, 240, 0, 0xffff); 306 imx233_ssp_set_timings(ssp, 240, 0, 0xffff);
294
295 imx233_ssp_sd_mmc_power_up_sequence(ssp); 307 imx233_ssp_sd_mmc_power_up_sequence(ssp);
296 imx233_ssp_set_bus_width(ssp, 1); 308 imx233_ssp_set_bus_width(ssp, 1);
297 imx233_ssp_set_block_size(ssp, 9); 309 imx233_ssp_set_block_size(ssp, 9);
@@ -671,7 +683,9 @@ static void sdmmc_thread(void)
671 * prevent deadlocking via disk_mount that 683 * prevent deadlocking via disk_mount that
672 * would cause a reverse-order attempt with 684 * would cause a reverse-order attempt with
673 * another thread */ 685 * another thread */
686#ifdef HAVE_HOTSWAP
674 fat_lock(); 687 fat_lock();
688#endif
675 689
676 /* We now have exclusive control of fat cache and sd. 690 /* We now have exclusive control of fat cache and sd.
677 * Release "by force", ensure file 691 * Release "by force", ensure file
@@ -681,7 +695,7 @@ static void sdmmc_thread(void)
681 { 695 {
682 int drive = sd_map[sd_drive]; 696 int drive = sd_map[sd_drive];
683 /* Skip non-removable drivers */ 697 /* Skip non-removable drivers */
684 if(!sd_removable(sd_drive)) 698 if(!sdmmc_removable(drive))
685 continue; 699 continue;
686 /* lock-out card activity - direct calls 700 /* lock-out card activity - direct calls
687 * into driver that bypass the fat cache */ 701 * into driver that bypass the fat cache */
@@ -709,7 +723,9 @@ static void sdmmc_thread(void)
709 mutex_unlock(&mutex[drive]); 723 mutex_unlock(&mutex[drive]);
710 } 724 }
711 /* Access is now safe */ 725 /* Access is now safe */
726#ifdef HAVE_HOTSWAP
712 fat_unlock(); 727 fat_unlock();
728#endif
713 break; 729 break;
714 } 730 }
715#endif 731#endif
@@ -764,21 +780,8 @@ static int sdmmc_init(void)
764 imx233_ssp_sdmmc_setup_detect(SDMMC_SSP(drive), true, sdmmc_detect_callback, 780 imx233_ssp_sdmmc_setup_detect(SDMMC_SSP(drive), true, sdmmc_detect_callback,
765 false, SDMMC_FLAGS(drive) & DETECT_INVERTED); 781 false, SDMMC_FLAGS(drive) & DETECT_INVERTED);
766 } 782 }
767
768 return 0;
769}
770
771static int sdmmc_present(int drive)
772{
773 if(SDMMC_FLAGS(drive) & REMOVABLE)
774 return imx233_ssp_sdmmc_detect(SDMMC_SSP(drive));
775 else
776 return true;
777}
778 783
779static inline int sdmmc_removable(int drive) 784 return 0;
780{
781 return SDMMC_FLAGS(drive) & REMOVABLE;
782} 785}
783 786
784#if CONFIG_STORAGE & STORAGE_SD 787#if CONFIG_STORAGE & STORAGE_SD
@@ -807,11 +810,17 @@ int sd_num_drives(int first_drive)
807 810
808bool sd_present(IF_MV_NONVOID(int sd_drive)) 811bool sd_present(IF_MV_NONVOID(int sd_drive))
809{ 812{
813#ifndef HAVE_MULTIVOLUME
814 int sd_drive = 0;
815#endif
810 return sdmmc_present(sd_map[sd_drive]); 816 return sdmmc_present(sd_map[sd_drive]);
811} 817}
812 818
813bool sd_removable(IF_MV_NONVOID(int sd_drive)) 819bool sd_removable(IF_MV_NONVOID(int sd_drive))
814{ 820{
821#ifndef HAVE_MULTIVOLUME
822 int sd_drive = 0;
823#endif
815 return sdmmc_removable(sd_map[sd_drive]); 824 return sdmmc_removable(sd_map[sd_drive]);
816} 825}
817 826
@@ -830,11 +839,17 @@ void sd_enable(bool on)
830 839
831int sd_read_sectors(IF_MD2(int sd_drive,) unsigned long start, int count, void *buf) 840int sd_read_sectors(IF_MD2(int sd_drive,) unsigned long start, int count, void *buf)
832{ 841{
842#ifndef HAVE_MULTIDRIVE
843 int sd_drive = 0;
844#endif
833 return transfer_sectors(sd_map[sd_drive], start, count, buf, true); 845 return transfer_sectors(sd_map[sd_drive], start, count, buf, true);
834} 846}
835 847
836int sd_write_sectors(IF_MD2(int sd_drive,) unsigned long start, int count, const void* buf) 848int sd_write_sectors(IF_MD2(int sd_drive,) unsigned long start, int count, const void* buf)
837{ 849{
850#ifndef HAVE_MULTIDRIVE
851 int sd_drive = 0;
852#endif
838 return transfer_sectors(sd_map[sd_drive], start, count, (void *)buf, false); 853 return transfer_sectors(sd_map[sd_drive], start, count, (void *)buf, false);
839} 854}
840#endif 855#endif
@@ -857,6 +872,9 @@ int mmc_init(void)
857 872
858void mmc_get_info(IF_MD2(int mmc_drive,) struct storage_info *info) 873void mmc_get_info(IF_MD2(int mmc_drive,) struct storage_info *info)
859{ 874{
875#ifndef HAVE_MULTIDRIVE
876 int mmc_drive = 0;
877#endif
860 int drive = mmc_map[mmc_drive]; 878 int drive = mmc_map[mmc_drive];
861 info->sector_size = 512; 879 info->sector_size = 512;
862 info->num_sectors = window_end[drive] - window_start[drive]; 880 info->num_sectors = window_end[drive] - window_start[drive];
@@ -873,11 +891,17 @@ int mmc_num_drives(int first_drive)
873 891
874bool mmc_present(IF_MV_NONVOID(int mmc_drive)) 892bool mmc_present(IF_MV_NONVOID(int mmc_drive))
875{ 893{
894#ifndef HAVE_MULTIVOLUME
895 int mmc_drive = 0;
896#endif
876 return sdmmc_present(mmc_map[mmc_drive]); 897 return sdmmc_present(mmc_map[mmc_drive]);
877} 898}
878 899
879bool mmc_removable(IF_MV_NONVOID(int mmc_drive)) 900bool mmc_removable(IF_MV_NONVOID(int mmc_drive))
880{ 901{
902#ifndef HAVE_MULTIVOLUME
903 int mmc_drive = 0;
904#endif
881 return sdmmc_removable(mmc_map[mmc_drive]); 905 return sdmmc_removable(mmc_map[mmc_drive]);
882} 906}
883 907
@@ -938,11 +962,17 @@ int mmc_spinup_time(void)
938 962
939int mmc_read_sectors(IF_MD2(int mmc_drive,) unsigned long start, int count, void *buf) 963int mmc_read_sectors(IF_MD2(int mmc_drive,) unsigned long start, int count, void *buf)
940{ 964{
965#ifndef HAVE_MULTIDRIVE
966 int mmc_drive = 0;
967#endif
941 return transfer_sectors(mmc_map[mmc_drive], start, count, buf, true); 968 return transfer_sectors(mmc_map[mmc_drive], start, count, buf, true);
942} 969}
943 970
944int mmc_write_sectors(IF_MD2(int mmc_drive,) unsigned long start, int count, const void* buf) 971int mmc_write_sectors(IF_MD2(int mmc_drive,) unsigned long start, int count, const void* buf)
945{ 972{
973#ifndef HAVE_MULTIDRIVE
974 int mmc_drive = 0;
975#endif
946 return transfer_sectors(mmc_map[mmc_drive], start, count, (void *)buf, false); 976 return transfer_sectors(mmc_map[mmc_drive], start, count, (void *)buf, false);
947} 977}
948 978