diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2006-11-08 01:55:26 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2006-11-08 01:55:26 +0000 |
commit | f184152c0501a80e95ad871927d766fdee50281b (patch) | |
tree | ecfa4b6cdf24065b32467d6d7274a2659c3ec9b0 /firmware/drivers | |
parent | 5dd07759248fec1407f6b3d4d1fb177554e45a13 (diff) | |
download | rockbox-f184152c0501a80e95ad871927d766fdee50281b.tar.gz rockbox-f184152c0501a80e95ad871927d766fdee50281b.zip |
* changes to ata.c - idle callbacks are called after 2 sec of real idle,
and shutdown and usb (it makes sense here). ata_sleep doesnt get broken
by callbacks.
* allow ata_sleep() at the end of buffering again
* config block uses ata_idle instead of delayed sector when saving
* remove delayed sector code from ata_mmc.c (idle callbacks are not yet
implemented for ata_mmc.c tho)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11461 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/ata.c | 65 | ||||
-rw-r--r-- | firmware/drivers/ata_mmc.c | 31 |
2 files changed, 20 insertions, 76 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 0a03fd2a25..9e20bfb87d 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -239,9 +239,6 @@ static long ata_stack[DEFAULT_STACK_SIZE/sizeof(long)]; | |||
239 | static const char ata_thread_name[] = "ata"; | 239 | static const char ata_thread_name[] = "ata"; |
240 | static struct event_queue ata_queue; | 240 | static struct event_queue ata_queue; |
241 | static bool initialized = false; | 241 | static bool initialized = false; |
242 | static bool delayed_write = false; | ||
243 | static unsigned char delayed_sector[SECTOR_SIZE]; | ||
244 | static int delayed_sector_num; | ||
245 | 242 | ||
246 | static long last_user_activity = -1; | 243 | static long last_user_activity = -1; |
247 | long last_disk_activity = -1; | 244 | long last_disk_activity = -1; |
@@ -804,10 +801,6 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
804 | 801 | ||
805 | mutex_unlock(&ata_mtx); | 802 | mutex_unlock(&ata_mtx); |
806 | 803 | ||
807 | /* only flush if reading went ok */ | ||
808 | if ( (ret == 0) && delayed_write ) | ||
809 | ata_flush(); | ||
810 | |||
811 | return ret; | 804 | return ret; |
812 | } | 805 | } |
813 | 806 | ||
@@ -1229,34 +1222,9 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
1229 | 1222 | ||
1230 | mutex_unlock(&ata_mtx); | 1223 | mutex_unlock(&ata_mtx); |
1231 | 1224 | ||
1232 | /* only flush if writing went ok */ | ||
1233 | if ( (ret == 0) && delayed_write ) | ||
1234 | ata_flush(); | ||
1235 | |||
1236 | return ret; | 1225 | return ret; |
1237 | } | 1226 | } |
1238 | 1227 | ||
1239 | /* schedule a single sector write, executed with the the next spinup | ||
1240 | (volume 0 only, used for config sector) */ | ||
1241 | extern void ata_delayed_write(unsigned long sector, const void* buf) | ||
1242 | { | ||
1243 | memcpy(delayed_sector, buf, SECTOR_SIZE); | ||
1244 | delayed_sector_num = sector; | ||
1245 | delayed_write = true; | ||
1246 | } | ||
1247 | |||
1248 | /* write the delayed sector to volume 0 */ | ||
1249 | extern void ata_flush(void) | ||
1250 | { | ||
1251 | if ( delayed_write ) { | ||
1252 | DEBUGF("ata_flush()\n"); | ||
1253 | delayed_write = false; | ||
1254 | ata_write_sectors(IF_MV2(0,) delayed_sector_num, 1, delayed_sector); | ||
1255 | } | ||
1256 | } | ||
1257 | |||
1258 | |||
1259 | |||
1260 | static int check_registers(void) | 1228 | static int check_registers(void) |
1261 | { | 1229 | { |
1262 | #if (CONFIG_CPU == PP5002) | 1230 | #if (CONFIG_CPU == PP5002) |
@@ -1364,28 +1332,31 @@ static void ata_thread(void) | |||
1364 | { | 1332 | { |
1365 | static long last_sleep = 0; | 1333 | static long last_sleep = 0; |
1366 | struct event ev; | 1334 | struct event ev; |
1367 | static long last_callback_run = 0; | 1335 | static long last_seen_mtx_unlock = 0; |
1368 | 1336 | ||
1369 | while (1) { | 1337 | while (1) { |
1370 | while ( queue_empty( &ata_queue ) ) { | 1338 | while ( queue_empty( &ata_queue ) ) { |
1371 | if (!spinup && !sleeping) | 1339 | if (!spinup && !sleeping) |
1372 | { | 1340 | { |
1341 | if (!ata_mtx.locked) | ||
1342 | { | ||
1343 | if (!last_seen_mtx_unlock) | ||
1344 | last_seen_mtx_unlock = current_tick; | ||
1345 | if (TIME_AFTER(current_tick, last_seen_mtx_unlock+(HZ*2))) | ||
1346 | { | ||
1347 | call_ata_idle_notifys(false); | ||
1348 | last_seen_mtx_unlock = 0; | ||
1349 | } | ||
1350 | } | ||
1373 | if ( sleep_timeout && | 1351 | if ( sleep_timeout && |
1374 | TIME_AFTER( current_tick, | 1352 | TIME_AFTER( current_tick, |
1375 | last_user_activity + sleep_timeout ) && | 1353 | last_user_activity + sleep_timeout ) && |
1376 | TIME_AFTER( current_tick, | 1354 | TIME_AFTER( current_tick, |
1377 | last_disk_activity + sleep_timeout ) ) | 1355 | last_disk_activity + sleep_timeout ) ) |
1378 | { | 1356 | { |
1379 | if (!call_ata_idle_notifys()) | 1357 | call_ata_idle_notifys(false); |
1380 | { | 1358 | ata_perform_sleep(); |
1381 | ata_perform_sleep(); | 1359 | last_sleep = current_tick; |
1382 | last_sleep = current_tick; | ||
1383 | } | ||
1384 | } | ||
1385 | else if (TIME_AFTER(current_tick, last_callback_run+(HZ*5))) | ||
1386 | { | ||
1387 | last_callback_run = current_tick; | ||
1388 | call_ata_idle_notifys(); | ||
1389 | } | 1360 | } |
1390 | } | 1361 | } |
1391 | #ifdef HAVE_ATA_POWER_OFF | 1362 | #ifdef HAVE_ATA_POWER_OFF |
@@ -1403,8 +1374,10 @@ static void ata_thread(void) | |||
1403 | } | 1374 | } |
1404 | queue_wait(&ata_queue, &ev); | 1375 | queue_wait(&ata_queue, &ev); |
1405 | switch ( ev.id ) { | 1376 | switch ( ev.id ) { |
1406 | #ifndef USB_NONE | 1377 | case SYS_POWEROFF: |
1407 | case SYS_USB_CONNECTED: | 1378 | case SYS_USB_CONNECTED: |
1379 | call_ata_idle_notifys(false); | ||
1380 | #ifndef USB_NONE | ||
1408 | if (poweroff) { | 1381 | if (poweroff) { |
1409 | mutex_lock(&ata_mtx); | 1382 | mutex_lock(&ata_mtx); |
1410 | ata_led(true); | 1383 | ata_led(true); |
@@ -1419,11 +1392,13 @@ static void ata_thread(void) | |||
1419 | 1392 | ||
1420 | /* Wait until the USB cable is extracted again */ | 1393 | /* Wait until the USB cable is extracted again */ |
1421 | usb_wait_for_disconnect(&ata_queue); | 1394 | usb_wait_for_disconnect(&ata_queue); |
1422 | break; | ||
1423 | #endif | 1395 | #endif |
1396 | break; | ||
1424 | case Q_SLEEP: | 1397 | case Q_SLEEP: |
1398 | call_ata_idle_notifys(true); | ||
1425 | last_disk_activity = current_tick - sleep_timeout + (HZ/2); | 1399 | last_disk_activity = current_tick - sleep_timeout + (HZ/2); |
1426 | break; | 1400 | break; |
1401 | |||
1427 | } | 1402 | } |
1428 | } | 1403 | } |
1429 | } | 1404 | } |
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 6303ca2851..64a7ba4bfd 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c | |||
@@ -98,9 +98,6 @@ static bool mmc_monitor_enabled = true; | |||
98 | #endif | 98 | #endif |
99 | static bool initialized = false; | 99 | static bool initialized = false; |
100 | static bool new_mmc_circuit; | 100 | static bool new_mmc_circuit; |
101 | static bool delayed_write = false; | ||
102 | static unsigned char delayed_sector[SECTOR_SIZE]; | ||
103 | static int delayed_sector_num; | ||
104 | 101 | ||
105 | static enum { | 102 | static enum { |
106 | MMC_UNKNOWN, | 103 | MMC_UNKNOWN, |
@@ -805,10 +802,6 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
805 | 802 | ||
806 | deselect_card(); | 803 | deselect_card(); |
807 | 804 | ||
808 | /* only flush if reading went ok */ | ||
809 | if ( (rc == 0) && delayed_write ) | ||
810 | ata_flush(); | ||
811 | |||
812 | return rc; | 805 | return rc; |
813 | } | 806 | } |
814 | 807 | ||
@@ -960,33 +953,9 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
960 | 953 | ||
961 | deselect_card(); | 954 | deselect_card(); |
962 | 955 | ||
963 | /* only flush if writing went ok */ | ||
964 | if ( (rc == 0) && delayed_write ) | ||
965 | ata_flush(); | ||
966 | |||
967 | return rc; | 956 | return rc; |
968 | } | 957 | } |
969 | 958 | ||
970 | /* While there is no spinup, the delayed write is still here to avoid | ||
971 | wearing the flash unnecessarily */ | ||
972 | extern void ata_delayed_write(unsigned long sector, const void* buf) | ||
973 | { | ||
974 | memcpy(delayed_sector, buf, SECTOR_SIZE); | ||
975 | delayed_sector_num = sector; | ||
976 | delayed_write = true; | ||
977 | } | ||
978 | |||
979 | /* write the delayed sector to volume 0 */ | ||
980 | extern void ata_flush(void) | ||
981 | { | ||
982 | if ( delayed_write ) | ||
983 | { | ||
984 | DEBUGF("ata_flush()\n"); | ||
985 | delayed_write = false; | ||
986 | ata_write_sectors(IF_MV2(0,) delayed_sector_num, 1, delayed_sector); | ||
987 | } | ||
988 | } | ||
989 | |||
990 | void ata_spindown(int seconds) | 959 | void ata_spindown(int seconds) |
991 | { | 960 | { |
992 | (void)seconds; | 961 | (void)seconds; |