summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-05-17 22:10:51 +0000
committerJens Arnold <amiconn@rockbox.org>2005-05-17 22:10:51 +0000
commit27abc2a6411ac6f864529ff3783c8009e43074d0 (patch)
tree84dda92347a7a7b671a547e2e75851ca3d3a99e0
parent32be590e6db3e2c2bcdcc16d89bad22135bd9058 (diff)
downloadrockbox-27abc2a6411ac6f864529ff3783c8009e43074d0.tar.gz
rockbox-27abc2a6411ac6f864529ff3783c8009e43074d0.zip
(1) Early USB detection on boot, before trying to mount the partitions. Cleaner & quicker; removes the need for the extra USB check at the top of ask_resume() which caused a deadlock in screenshot mode (see patch #1110332). On Ondio, this allows to leave an MMC in the slot when booting with USB connected for instant access. (2) Ondio: Track MMC status, only ask to remove the card if required. Probe MMC status if unknown.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6488 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/main.c38
-rw-r--r--apps/misc.c2
-rw-r--r--apps/screens.c1
-rw-r--r--apps/tree.c5
-rw-r--r--firmware/drivers/ata_mmc.c32
-rw-r--r--firmware/export/ata_mmc.h1
6 files changed, 61 insertions, 18 deletions
diff --git a/apps/main.c b/apps/main.c
index 25bc9296e5..537c3da4dc 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -127,6 +127,7 @@ void init(void)
127void init(void) 127void init(void)
128{ 128{
129 int rc; 129 int rc;
130 bool mounted = false;
130#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) 131#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
131 /* if nobody initialized ATA before, I consider this a cold start */ 132 /* if nobody initialized ATA before, I consider this a cold start */
132 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ 133 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
@@ -216,22 +217,35 @@ void init(void)
216 } 217 }
217 218
218 usb_start_monitoring(); 219 usb_start_monitoring();
220 while (usb_detect())
221 { /* enter USB mode early, before trying to mount */
222 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
223#ifdef HAVE_MMC
224 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
225#endif
226 {
227 usb_screen();
228 mounted = true; /* mounting done @ end of USB mode */
229 }
230 }
219 231
220 /* FixMe: the same kind of mounting happens in usb.c, share the code. */ 232 if (!mounted)
221 rc = disk_mount_all();
222 if (rc<=0)
223 { 233 {
224 lcd_clear_display(); 234 rc = disk_mount_all();
225 lcd_puts(0, 0, "No partition"); 235 if (rc<=0)
226 lcd_puts(0, 1, "found."); 236 {
237 lcd_clear_display();
238 lcd_puts(0, 0, "No partition");
239 lcd_puts(0, 1, "found.");
227#ifdef HAVE_LCD_BITMAP 240#ifdef HAVE_LCD_BITMAP
228 lcd_puts(0, 2, "Insert USB cable"); 241 lcd_puts(0, 2, "Insert USB cable");
229 lcd_puts(0, 3, "and fix it."); 242 lcd_puts(0, 3, "and fix it.");
230 lcd_update(); 243 lcd_update();
231#endif 244#endif
232 while(button_get(true) != SYS_USB_CONNECTED) {}; 245 while(button_get(true) != SYS_USB_CONNECTED) {};
233 usb_screen(); 246 usb_screen();
234 system_reboot(); 247 system_reboot();
248 }
235 } 249 }
236 250
237 settings_calc_config_sector(); 251 settings_calc_config_sector();
diff --git a/apps/misc.c b/apps/misc.c
index e7438d673e..bc2df3ab5a 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -353,7 +353,7 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
353 if (callback != NULL) 353 if (callback != NULL)
354 callback(parameter); 354 callback(parameter);
355#ifdef HAVE_MMC 355#ifdef HAVE_MMC
356 if (!mmc_detect() || (mmc_remove_request() == SYS_MMC_EXTRACTED)) 356 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
357#endif 357#endif
358 usb_screen(); 358 usb_screen();
359 return SYS_USB_CONNECTED; 359 return SYS_USB_CONNECTED;
diff --git a/apps/screens.c b/apps/screens.c
index b725f0a6ae..7c00e9481d 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -97,6 +97,7 @@ void usb_display_info(void)
97 status_draw(true); 97 status_draw(true);
98 lcd_update(); 98 lcd_update();
99#else 99#else
100 lcd_double_height(false);
100 lcd_puts(0, 0, "[USB Mode]"); 101 lcd_puts(0, 0, "[USB Mode]");
101 status_set_param(false); 102 status_set_param(false);
102 status_set_audio(false); 103 status_set_audio(false);
diff --git a/apps/tree.c b/apps/tree.c
index c7ff7326fb..a49fb9b3ab 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -434,11 +434,6 @@ static bool ask_resume(bool ask_once)
434 lcd_double_height(false); 434 lcd_double_height(false);
435#endif 435#endif
436 436
437 if (usb_detect()) {
438 default_event_handler(SYS_USB_CONNECTED);
439 return false;
440 }
441
442#ifdef HAVE_ALARM_MOD 437#ifdef HAVE_ALARM_MOD
443 if ( rtc_check_alarm_started(true) ) { 438 if ( rtc_check_alarm_started(true) ) {
444 rtc_enable_alarm(false); 439 rtc_enable_alarm(false);
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index 9c2e5817f9..6876ce0ec9 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -103,6 +103,12 @@ static unsigned char delayed_sector[SECTOR_SIZE];
103static int delayed_sector_num; 103static int delayed_sector_num;
104 104
105static enum { 105static enum {
106 MMC_UNKNOWN,
107 MMC_UNTOUCHED,
108 MMC_TOUCHED
109} mmc_status = MMC_UNKNOWN;
110
111static enum {
106 SER_POLL_WRITE, 112 SER_POLL_WRITE,
107 SER_POLL_READ, 113 SER_POLL_READ,
108 SER_DISABLED 114 SER_DISABLED
@@ -429,6 +435,8 @@ static int initialize_card(int card_no)
429 10000000, 100000000, 1000000000 435 10000000, 100000000, 1000000000
430 }; 436 };
431 437
438 if (card_no == 1)
439 mmc_status = MMC_TOUCHED;
432 /* switch to SPI mode */ 440 /* switch to SPI mode */
433 send_cmd(CMD_GO_IDLE_STATE, 0, response); 441 send_cmd(CMD_GO_IDLE_STATE, 0, response);
434 if (response[0] != 0x01) 442 if (response[0] != 0x01)
@@ -1046,6 +1054,27 @@ bool mmc_detect(void)
1046 return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false; 1054 return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false;
1047} 1055}
1048 1056
1057bool mmc_touched(void)
1058{
1059 if (mmc_status == MMC_UNKNOWN) /* try to detect */
1060 {
1061 unsigned char response;
1062
1063 mutex_lock(&mmc_mutex);
1064 mmc_select_clock(1);
1065 setup_sci1(7); /* safe value */
1066 and_b(~0x02, &PADRH); /* assert CS */
1067 send_cmd(CMD_SEND_OP_COND, 0, &response);
1068 if (response == 0xFF)
1069 mmc_status = MMC_UNTOUCHED;
1070 else
1071 mmc_status = MMC_TOUCHED;
1072
1073 deselect_card();
1074 }
1075 return mmc_status == MMC_TOUCHED;
1076}
1077
1049bool mmc_usb_active(int delayticks) 1078bool mmc_usb_active(int delayticks)
1050{ 1079{
1051 /* reading "inactive" is delayed by user-supplied monoflop value */ 1080 /* reading "inactive" is delayed by user-supplied monoflop value */
@@ -1094,6 +1123,7 @@ static void mmc_tick(void)
1094 else 1123 else
1095 { 1124 {
1096 queue_broadcast(SYS_MMC_EXTRACTED, NULL); 1125 queue_broadcast(SYS_MMC_EXTRACTED, NULL);
1126 mmc_status = MMC_UNTOUCHED;
1097 card_info[1].initialized = false; 1127 card_info[1].initialized = false;
1098 } 1128 }
1099 } 1129 }
@@ -1157,6 +1187,8 @@ int ata_init(void)
1157 1187
1158 if ( !initialized ) 1188 if ( !initialized )
1159 { 1189 {
1190 if (!last_mmc_status)
1191 mmc_status = MMC_UNTOUCHED;
1160 new_mmc_circuit = ((read_hw_mask() & MMC_CLOCK_POLARITY) != 0); 1192 new_mmc_circuit = ((read_hw_mask() & MMC_CLOCK_POLARITY) != 0);
1161#ifdef HAVE_HOTSWAP 1193#ifdef HAVE_HOTSWAP
1162 queue_init(&mmc_queue); 1194 queue_init(&mmc_queue);
diff --git a/firmware/export/ata_mmc.h b/firmware/export/ata_mmc.h
index 6f7fb2bdb5..9da93906ad 100644
--- a/firmware/export/ata_mmc.h
+++ b/firmware/export/ata_mmc.h
@@ -44,6 +44,7 @@ bool mmc_detect(void);
44unsigned long mmc_extract_bits(const unsigned long *p, unsigned int start, 44unsigned long mmc_extract_bits(const unsigned long *p, unsigned int start,
45 unsigned int size); 45 unsigned int size);
46tCardInfo *mmc_card_info(int card_no); 46tCardInfo *mmc_card_info(int card_no);
47bool mmc_touched(void);
47bool mmc_usb_active(int delayticks); 48bool mmc_usb_active(int delayticks);
48#ifdef HAVE_HOTSWAP 49#ifdef HAVE_HOTSWAP
49void mmc_enable_monitoring(bool on); 50void mmc_enable_monitoring(bool on);