summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s3c2440/sd-s3c2440.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s3c2440/sd-s3c2440.c')
-rw-r--r--firmware/target/arm/s3c2440/sd-s3c2440.c100
1 files changed, 35 insertions, 65 deletions
diff --git a/firmware/target/arm/s3c2440/sd-s3c2440.c b/firmware/target/arm/s3c2440/sd-s3c2440.c
index e8de3ac78d..2ff68aa4ee 100644
--- a/firmware/target/arm/s3c2440/sd-s3c2440.c
+++ b/firmware/target/arm/s3c2440/sd-s3c2440.c
@@ -21,11 +21,9 @@
21 21
22//#define SD_DEBUG 22//#define SD_DEBUG
23 23
24#include "sd.h"
25#include "system.h" 24#include "system.h"
26#include <string.h> 25#include <string.h>
27#include "gcc_extensions.h" 26#include "gcc_extensions.h"
28#include "thread.h"
29#include "panic.h" 27#include "panic.h"
30 28
31#ifdef SD_DEBUG 29#ifdef SD_DEBUG
@@ -33,8 +31,8 @@
33#endif 31#endif
34#ifdef HAVE_HOTSWAP 32#ifdef HAVE_HOTSWAP
35#include "sdmmc.h" 33#include "sdmmc.h"
36#include "disk.h"
37#endif 34#endif
35#include "storage.h"
38#include "dma-target.h" 36#include "dma-target.h"
39#include "system-target.h" 37#include "system-target.h"
40#include "led-mini2440.h" 38#include "led-mini2440.h"
@@ -90,6 +88,12 @@ struct sd_card_status
90/* for compatibility */ 88/* for compatibility */
91static long last_disk_activity = -1; 89static long last_disk_activity = -1;
92 90
91#ifdef CONFIG_STORAGE_MULTI
92static int sd_first_drive = 0;
93#else
94#define sd_first_drive 0
95#endif
96
93static bool initialized = false; 97static bool initialized = false;
94static bool sd_enabled = false; 98static bool sd_enabled = false;
95static long next_yield = 0; 99static long next_yield = 0;
@@ -109,11 +113,7 @@ static struct sd_card_status sd_status[NUM_CARDS] =
109#endif 113#endif
110#endif 114#endif
111 115
112/* Shoot for around 75% usage */
113static long sd_stack [(DEFAULT_STACK_SIZE*2 + 0x1c0)/sizeof(long)];
114static const char sd_thread_name[] = "sd";
115static struct mutex sd_mtx SHAREDBSS_ATTR; 116static struct mutex sd_mtx SHAREDBSS_ATTR;
116static struct event_queue sd_queue;
117static struct semaphore transfer_completion_signal; 117static struct semaphore transfer_completion_signal;
118static volatile unsigned int transfer_error[NUM_DRIVES]; 118static volatile unsigned int transfer_error[NUM_DRIVES];
119/* align on cache line size */ 119/* align on cache line size */
@@ -511,17 +511,13 @@ static inline bool card_detect_target(void)
511 511
512static int sd1_oneshot_callback(struct timeout *tmo) 512static int sd1_oneshot_callback(struct timeout *tmo)
513{ 513{
514 (void)tmo;
515
516 /* This is called only if the state was stable for 300ms - check state 514 /* This is called only if the state was stable for 300ms - check state
517 * and post appropriate event. */ 515 * and post appropriate event. */
518 if (card_detect_target()) 516 queue_broadcast(card_detect_target() ? SYS_HOTSWAP_INSERTED :
519 { 517 SYS_HOTSWAP_EXTRACTED,
520 queue_broadcast(SYS_HOTSWAP_INSERTED, 0); 518 sd_first_drive + CARD_NUM_SLOT);
521 }
522 else
523 queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0);
524 return 0; 519 return 0;
520 (void)tmo;
525} 521}
526 522
527void EINT8_23(void) 523void EINT8_23(void)
@@ -571,46 +567,6 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
571#endif /* HAVE_HOTSWAP */ 567#endif /* HAVE_HOTSWAP */
572/*****************************************************************************/ 568/*****************************************************************************/
573 569
574static void sd_thread(void) NORETURN_ATTR;
575static void sd_thread(void)
576{
577 struct queue_event ev;
578
579 /* TODO */
580 while (1)
581 {
582 queue_wait_w_tmo(&sd_queue, &ev, HZ);
583 switch ( ev.id )
584 {
585#ifdef HAVE_HOTSWAP
586 case SYS_HOTSWAP_INSERTED:
587 case SYS_HOTSWAP_EXTRACTED:;
588 int success = 1;
589
590 disk_unmount(0); /* release "by force" */
591
592 mutex_lock(&sd_mtx); /* lock-out card activity */
593
594 /* Force card init for new card, re-init for re-inserted one or
595 * clear if the last attempt to init failed with an error. */
596 card_info[0].initialized = 0;
597
598 /* Access is now safe */
599 mutex_unlock(&sd_mtx);
600
601 if (ev.id == SYS_HOTSWAP_INSERTED)
602 success = disk_mount(0); /* 0 if fail */
603
604 /* notify the system about the changed filesystems
605 */
606 if (success)
607 queue_broadcast(SYS_FS_CHANGED, 0);
608 break;
609#endif /* HAVE_HOTSWAP */
610 }
611 }
612}
613
614static int sd_wait_for_state(const int card_no, unsigned int state) 570static int sd_wait_for_state(const int card_no, unsigned int state)
615{ 571{
616 unsigned long response = 0; 572 unsigned long response = 0;
@@ -907,9 +863,6 @@ int sd_init(void)
907 semaphore_init(&transfer_completion_signal, 1, 0); 863 semaphore_init(&transfer_completion_signal, 1, 0);
908 /* init mutex */ 864 /* init mutex */
909 mutex_init(&sd_mtx); 865 mutex_init(&sd_mtx);
910 queue_init(&sd_queue, true);
911 create_thread(sd_thread, sd_stack, sizeof(sd_stack), 0,
912 sd_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE) IF_COP(, CPU));
913 866
914 uncached_buffer = UNCACHED_ADDR(&aligned_buffer[0]); 867 uncached_buffer = UNCACHED_ADDR(&aligned_buffer[0]);
915 868
@@ -950,18 +903,11 @@ tCardInfo *card_get_info_target(int card_no)
950int sd_num_drives(int first_drive) 903int sd_num_drives(int first_drive)
951{ 904{
952 dbgprintf ("sd_num_drv"); 905 dbgprintf ("sd_num_drv");
953#if 0
954 /* Store which logical drive number(s) we have been assigned */ 906 /* Store which logical drive number(s) we have been assigned */
955 sd_first_drive = first_drive; 907 sd_first_drive = first_drive;
956#endif
957
958 return NUM_CARDS; 908 return NUM_CARDS;
959} 909}
960 910
961void sd_sleepnow(void)
962{
963}
964
965bool sd_disk_is_active(void) 911bool sd_disk_is_active(void)
966{ 912{
967 return false; 913 return false;
@@ -980,3 +926,27 @@ int sd_spinup_time(void)
980#endif /* CONFIG_STORAGE_MULTI */ 926#endif /* CONFIG_STORAGE_MULTI */
981/*****************************************************************************/ 927/*****************************************************************************/
982 928
929int sd_event(long id, intptr_t data)
930{
931 int rc = 0;
932
933 switch (id)
934 {
935#ifdef HAVE_HOTSWAP
936 case SYS_HOTSWAP_INSERTED:
937 case SYS_HOTSWAP_EXTRACTED:
938 mutex_lock(&sd_mtx);
939 /* Force card init for new card, re-init for re-inserted one or
940 * clear if the last attempt to init failed with an error. */
941 card_info[data].initialized = 0;
942 mutex_unlock(&sd_mtx);
943 break;
944#endif /* HAVE_HOTSWAP */
945 default:
946 rc = storage_event_default_handler(id, data, last_disk_activity,
947 STORAGE_SD);
948 break;
949 }
950
951 return rc;
952}