summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata_mmc.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/ata_mmc.c')
-rw-r--r--firmware/drivers/ata_mmc.c60
1 files changed, 24 insertions, 36 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index 5da0b44292..c27c3b5d05 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -93,7 +93,6 @@ static long last_disk_activity = -1;
93static struct mutex mmc_mutex; 93static struct mutex mmc_mutex;
94 94
95#ifdef HAVE_HOTSWAP 95#ifdef HAVE_HOTSWAP
96static bool mmc_monitor_enabled = true;
97static long mmc_stack[((DEFAULT_STACK_SIZE*2) + 0x800)/sizeof(long)]; 96static long mmc_stack[((DEFAULT_STACK_SIZE*2) + 0x800)/sizeof(long)];
98#else 97#else
99static long mmc_stack[(DEFAULT_STACK_SIZE*2)/sizeof(long)]; 98static long mmc_stack[(DEFAULT_STACK_SIZE*2)/sizeof(long)];
@@ -130,7 +129,9 @@ static tCardInfo card_info[2];
130static int current_card = 0; 129static int current_card = 0;
131#endif 130#endif
132static bool last_mmc_status = false; 131static bool last_mmc_status = false;
133static int countdown = HZ/3; /* for mmc switch debouncing */ 132static int countdown = -1; /* for mmc switch debouncing. -1 because the
133 countdown should not happen if the card
134 is inserted at boot */
134static bool usb_activity; /* monitoring the USB bridge */ 135static bool usb_activity; /* monitoring the USB bridge */
135static long last_usb_activity; 136static long last_usb_activity;
136 137
@@ -807,13 +808,6 @@ static void mmc_thread(void)
807 } 808 }
808} 809}
809 810
810#ifdef HAVE_HOTSWAP
811void mmc_enable_monitoring(bool on)
812{
813 mmc_monitor_enabled = on;
814}
815#endif
816
817bool mmc_detect(void) 811bool mmc_detect(void)
818{ 812{
819 return (adc_read(ADC_MMC_SWITCH) < 0x200); 813 return (adc_read(ADC_MMC_SWITCH) < 0x200);
@@ -846,9 +840,6 @@ bool mmc_usb_active(int delayticks)
846static void mmc_tick(void) 840static void mmc_tick(void)
847{ 841{
848 bool current_status; 842 bool current_status;
849#ifndef HAVE_HOTSWAP
850 const bool mmc_monitor_enabled = true;
851#endif
852 843
853 if (new_mmc_circuit) 844 if (new_mmc_circuit)
854 /* USB bridge activity is 0 on idle, ~527 on active */ 845 /* USB bridge activity is 0 on idle, ~527 on active */
@@ -860,33 +851,30 @@ static void mmc_tick(void)
860 last_usb_activity = current_tick; 851 last_usb_activity = current_tick;
861 usb_activity = current_status; 852 usb_activity = current_status;
862 853
863 if (mmc_monitor_enabled) 854 current_status = mmc_detect();
855 /* Only report when the status has changed */
856 if (current_status != last_mmc_status)
864 { 857 {
865 current_status = mmc_detect(); 858 last_mmc_status = current_status;
866 /* Only report when the status has changed */ 859 countdown = HZ/3;
867 if (current_status != last_mmc_status) 860 }
868 { 861 else
869 last_mmc_status = current_status; 862 {
870 countdown = HZ/3; 863 /* Count down until it gets negative */
871 } 864 if (countdown >= 0)
872 else 865 countdown--;
873 {
874 /* Count down until it gets negative */
875 if (countdown >= 0)
876 countdown--;
877 866
878 if (countdown == 0) 867 if (countdown == 0)
868 {
869 if (current_status)
879 { 870 {
880 if (current_status) 871 queue_broadcast(SYS_HOTSWAP_INSERTED, 0);
881 { 872 }
882 queue_broadcast(SYS_HOTSWAP_INSERTED, 0); 873 else
883 } 874 {
884 else 875 queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0);
885 { 876 mmc_status = MMC_UNTOUCHED;
886 queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0); 877 card_info[1].initialized = false;
887 mmc_status = MMC_UNTOUCHED;
888 card_info[1].initialized = false;
889 }
890 } 878 }
891 } 879 }
892 } 880 }