Index: apps/plugin.c =================================================================== --- apps/plugin.c (revision 18065) +++ apps/plugin.c (working copy) @@ -607,6 +607,9 @@ #endif gui_syncyesno_run, +#ifndef SIMULATOR + ata_wakeup, +#endif }; int plugin_load(const char* plugin, const void* parameter) Index: apps/plugin.h =================================================================== --- apps/plugin.h (revision 18065) +++ apps/plugin.h (working copy) @@ -763,6 +763,9 @@ const struct text_message * yes_message, const struct text_message * no_message); +#ifndef SIMULATOR + void (*ata_wakeup)(void); +#endif }; /* plugin header */ Index: firmware/export/ata.h =================================================================== --- firmware/export/ata.h (revision 18065) +++ firmware/export/ata.h (working copy) @@ -46,6 +46,7 @@ If you are waiting for the disk to become active before doing something use ata_idle_notify.h */ +extern void ata_wakeup(void); extern bool ata_disk_is_active(void); extern int ata_hard_reset(void); extern int ata_soft_reset(void); Index: firmware/target/arm/ata-sd-pp.c =================================================================== --- firmware/target/arm/ata-sd-pp.c (revision 18065) +++ firmware/target/arm/ata-sd-pp.c (working copy) @@ -1121,6 +1121,10 @@ { } +void ata_wakeup(void) +{ +} + void ata_spin(void) { } Index: firmware/drivers/ata.c =================================================================== --- firmware/drivers/ata.c (revision 18065) +++ firmware/drivers/ata.c (working copy) @@ -62,6 +62,7 @@ #define Q_SLEEP 0 #define Q_CLOSE 1 +#define Q_WAKEUP 1 #define READ_TIMEOUT 5*HZ @@ -182,6 +183,7 @@ #endif static int ata_power_on(void); +static int ata_perform_wakeup(void); static int perform_soft_reset(void); static int set_multiple_mode(int sectors); static int set_features(void); @@ -300,7 +302,6 @@ long timeout; int count; void* buf; - long spinup_start; #ifndef MAX_PHYS_SECTOR_SIZE #ifdef HAVE_MULTIVOLUME @@ -315,35 +316,18 @@ } last_disk_activity = current_tick; - spinup_start = current_tick; ata_led(true); - if ( sleeping ) { - spinup = true; - if (poweroff) { - if (ata_power_on()) { - ret = -2; - goto error; - } - } - else { - if (perform_soft_reset()) { - ret = -2; - goto error; - } - } - } - - timeout = current_tick + READ_TIMEOUT; - - SET_REG(ATA_SELECT, ata_device); - if (!wait_for_rdy()) + ret = ata_perform_wakeup(); + if (ret) { ret = -3; goto error; } + timeout = current_tick + READ_TIMEOUT; + retry: buf = inbuf; count = incount; @@ -402,13 +386,6 @@ goto retry; } - if (spinup) { - ata_spinup_time = current_tick - spinup_start; - spinup = false; - sleeping = false; - poweroff = false; - } - /* read the status register exactly once per loop */ status = ATA_STATUS; @@ -507,7 +484,6 @@ { int i; int ret = 0; - long spinup_start; #ifndef MAX_PHYS_SECTOR_SIZE #ifdef HAVE_MULTIVOLUME @@ -520,28 +496,11 @@ panicf("Writing past end of disk"); last_disk_activity = current_tick; - spinup_start = current_tick; ata_led(true); - if ( sleeping ) { - spinup = true; - if (poweroff) { - if (ata_power_on()) { - ret = -1; - goto error; - } - } - else { - if (perform_soft_reset()) { - ret = -1; - goto error; - } - } - } - - SET_REG(ATA_SELECT, ata_device); - if (!wait_for_rdy()) + ret = ata_perform_wakeup(); + if (ret) { ret = -2; goto error; @@ -579,13 +538,6 @@ break; } - if (spinup) { - ata_spinup_time = current_tick - spinup_start; - spinup = false; - sleeping = false; - poweroff = false; - } - copy_write_sectors(buf, SECTOR_SIZE/2); #ifdef USE_INTERRUPT @@ -834,6 +786,33 @@ return !sleeping; } +static int ata_perform_wakeup(void) +{ + long spinup_start = current_tick; + + if ( sleeping ) { + spinup = true; + if (poweroff) { + if (ata_power_on()) + return -1; + } + else { + if (perform_soft_reset()) + return -1; + } + } + + SET_REG(ATA_SELECT, ata_device); + if (!wait_for_rdy()) + return -2; + + ata_spinup_time = current_tick - spinup_start; + spinup = false; + sleeping = false; + poweroff = false; + return 0; +} + static int ata_perform_sleep(void) { mutex_lock(&ata_mtx); @@ -874,6 +853,11 @@ } } +void ata_wakeup(void) +{ + queue_post(&ata_queue, Q_WAKEUP, 0); +} + void ata_spin(void) { last_user_activity = current_tick; @@ -949,6 +933,13 @@ last_disk_activity = current_tick - sleep_timeout + (HZ/2); break; + case Q_WAKEUP: + mutex_lock(&ata_mtx); + ata_led(true); + ata_perform_wakeup(); + ata_led(false); + mutex_unlock(&ata_mtx); + #ifdef ATA_DRIVER_CLOSE case Q_CLOSE: return; Index: firmware/drivers/ata_mmc.c =================================================================== --- firmware/drivers/ata_mmc.c (revision 18065) +++ firmware/drivers/ata_mmc.c (working copy) @@ -952,6 +952,10 @@ { } +void ata_wakeup(void) +{ +} + void ata_spin(void) { } Index: firmware/drivers/ata_flash.c =================================================================== --- firmware/drivers/ata_flash.c (revision 18065) +++ firmware/drivers/ata_flash.c (working copy) @@ -442,6 +442,10 @@ { } +void ata_wakeup(void) +{ +} + void ata_spin(void) { }