summaryrefslogtreecommitdiff
path: root/firmware/target/arm/sandisk/ata-c200_e200.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/sandisk/ata-c200_e200.c')
-rw-r--r--firmware/target/arm/sandisk/ata-c200_e200.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/firmware/target/arm/sandisk/ata-c200_e200.c b/firmware/target/arm/sandisk/ata-c200_e200.c
index 150b08fd92..99a00358ff 100644
--- a/firmware/target/arm/sandisk/ata-c200_e200.c
+++ b/firmware/target/arm/sandisk/ata-c200_e200.c
@@ -16,7 +16,7 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include "ata.h" 19#include "fat.h"
20#include "hotswap-target.h" 20#include "hotswap-target.h"
21#include "ata-target.h" 21#include "ata-target.h"
22#include "ata_idle_notify.h" 22#include "ata_idle_notify.h"
@@ -29,8 +29,8 @@
29#include "panic.h" 29#include "panic.h"
30#include "usb.h" 30#include "usb.h"
31 31
32#define BLOCK_SIZE (512) 32#define BLOCK_SIZE 512
33#define SECTOR_SIZE (512) 33#define SECTOR_SIZE 512
34#define BLOCKS_PER_BANK 0x7a7800 34#define BLOCKS_PER_BANK 0x7a7800
35 35
36#define STATUS_REG (*(volatile unsigned int *)(0x70008204)) 36#define STATUS_REG (*(volatile unsigned int *)(0x70008204))
@@ -1045,22 +1045,33 @@ static void sd_thread(void)
1045 { 1045 {
1046#ifdef HAVE_HOTSWAP 1046#ifdef HAVE_HOTSWAP
1047 case SYS_HOTSWAP_INSERTED: 1047 case SYS_HOTSWAP_INSERTED:
1048 mutex_lock(&sd_mtx); /* Lock-out card activity */
1049 card_info[1].initialized = 0;
1050 sd_status[1].retry = 0;
1051 disk_unmount(1); /* Force remount */
1052 disk_mount(1); /* mount microSD card */
1053 queue_broadcast(SYS_FS_CHANGED, 0);
1054 mutex_unlock(&sd_mtx);
1055 break;
1056
1057 case SYS_HOTSWAP_EXTRACTED: 1048 case SYS_HOTSWAP_EXTRACTED:
1058 mutex_lock(&sd_mtx); /* Lock-out card activity */ 1049 fat_lock(); /* lock-out FAT activity first -
1059 card_info[1].initialized = 0; 1050 prevent deadlocking via disk_mount that
1051 would cause a reverse-order attempt with
1052 another thread */
1053 mutex_lock(&sd_mtx); /* lock-out card activity - direct calls
1054 into driver that bypass the fat cache */
1055
1056 /* We now have exclusive control of fat cache and ata */
1057
1058 disk_unmount(1); /* release "by force", ensure file
1059 descriptors aren't leaked and any busy
1060 ones are invalid if mounting */
1061
1062 /* Force card init for new card, re-init for re-inserted one or
1063 * clear if the last attempt to init failed with an error. */
1064 card_info[1].initialized = 0;
1060 sd_status[1].retry = 0; 1065 sd_status[1].retry = 0;
1061 disk_unmount(1); /* release "by force" */ 1066
1067 if (ev.id == SYS_HOTSWAP_INSERTED)
1068 disk_mount(1);
1069
1062 queue_broadcast(SYS_FS_CHANGED, 0); 1070 queue_broadcast(SYS_FS_CHANGED, 0);
1071
1072 /* Access is now safe */
1063 mutex_unlock(&sd_mtx); 1073 mutex_unlock(&sd_mtx);
1074 fat_unlock();
1064 break; 1075 break;
1065#endif 1076#endif
1066 case SYS_TIMEOUT: 1077 case SYS_TIMEOUT:
@@ -1135,6 +1146,28 @@ void ata_enable(bool on)
1135 } 1146 }
1136} 1147}
1137 1148
1149#ifdef HAVE_HOTSWAP
1150void card_enable_monitoring(bool on)
1151{
1152 if (on)
1153 {
1154#ifdef SANSA_E200
1155 GPIO_SET_BITWISE(GPIOA_INT_EN, 0x80);
1156#elif defined(SANSA_C200)
1157 GPIO_SET_BITWISE(GPIOL_INT_EN, 0x08);
1158#endif
1159 }
1160 else
1161 {
1162#ifdef SANSA_E200
1163 GPIO_CLEAR_BITWISE(GPIOA_INT_EN, 0x80);
1164#elif defined(SANSA_C200)
1165 GPIO_CLEAR_BITWISE(GPIOL_INT_EN, 0x08);
1166#endif
1167 }
1168}
1169#endif
1170
1138int ata_init(void) 1171int ata_init(void)
1139{ 1172{
1140 int ret = 0; 1173 int ret = 0;
@@ -1193,7 +1226,6 @@ int ata_init(void)
1193 GPIOA_INT_LEV = (0x80 << 8) | (~GPIOA_INPUT_VAL & 0x80); 1226 GPIOA_INT_LEV = (0x80 << 8) | (~GPIOA_INPUT_VAL & 0x80);
1194 1227
1195 GPIOA_INT_CLR = 0x80; 1228 GPIOA_INT_CLR = 0x80;
1196 GPIO_SET_BITWISE(GPIOA_INT_EN, 0x80);
1197#elif defined SANSA_C200 1229#elif defined SANSA_C200
1198 CPU_INT_EN = HI_MASK; 1230 CPU_INT_EN = HI_MASK;
1199 CPU_HI_INT_EN = GPIO2_MASK; 1231 CPU_HI_INT_EN = GPIO2_MASK;
@@ -1201,7 +1233,6 @@ int ata_init(void)
1201 GPIOL_INT_LEV = (0x08 << 8) | (~GPIOL_INPUT_VAL & 0x08); 1233 GPIOL_INT_LEV = (0x08 << 8) | (~GPIOL_INPUT_VAL & 0x08);
1202 1234
1203 GPIOL_INT_CLR = 0x08; 1235 GPIOL_INT_CLR = 0x08;
1204 GPIO_SET_BITWISE(GPIOL_INT_EN, 0x08);
1205#endif 1236#endif
1206#endif 1237#endif
1207 } 1238 }