diff options
Diffstat (limited to 'firmware/drivers/ata.c')
-rw-r--r-- | firmware/drivers/ata.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index edef507e0d..5f5829736f 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -61,8 +61,9 @@ | |||
61 | #define CMD_SET_FEATURES 0xEF | 61 | #define CMD_SET_FEATURES 0xEF |
62 | #define CMD_SECURITY_FREEZE_LOCK 0xF5 | 62 | #define CMD_SECURITY_FREEZE_LOCK 0xF5 |
63 | 63 | ||
64 | #define Q_SLEEP 0 | 64 | /* Should all be < 0x100 (which are reserved for control messages) */ |
65 | #define Q_CLOSE 1 | 65 | #define Q_SLEEP 0 |
66 | #define Q_CLOSE 1 | ||
66 | 67 | ||
67 | #define READ_TIMEOUT 5*HZ | 68 | #define READ_TIMEOUT 5*HZ |
68 | 69 | ||
@@ -143,7 +144,7 @@ static void ata_lock_unlock(struct ata_lock *l) | |||
143 | #define mutex_unlock ata_lock_unlock | 144 | #define mutex_unlock ata_lock_unlock |
144 | #endif /* MAX_PHYS_SECTOR_SIZE */ | 145 | #endif /* MAX_PHYS_SECTOR_SIZE */ |
145 | 146 | ||
146 | #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) && !defined(BOOTLOADER) | 147 | #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) |
147 | #define ALLOW_USB_SPINDOWN | 148 | #define ALLOW_USB_SPINDOWN |
148 | #endif | 149 | #endif |
149 | 150 | ||
@@ -164,7 +165,7 @@ static bool lba48 = false; /* set for 48 bit addressing */ | |||
164 | #endif | 165 | #endif |
165 | static long ata_stack[(DEFAULT_STACK_SIZE*3)/sizeof(long)]; | 166 | static long ata_stack[(DEFAULT_STACK_SIZE*3)/sizeof(long)]; |
166 | static const char ata_thread_name[] = "ata"; | 167 | static const char ata_thread_name[] = "ata"; |
167 | static struct event_queue ata_queue; | 168 | static struct event_queue ata_queue SHAREDBSS_ATTR; |
168 | static bool initialized = false; | 169 | static bool initialized = false; |
169 | 170 | ||
170 | static long last_user_activity = -1; | 171 | static long last_user_activity = -1; |
@@ -910,7 +911,9 @@ static void ata_thread(void) | |||
910 | #ifdef ALLOW_USB_SPINDOWN | 911 | #ifdef ALLOW_USB_SPINDOWN |
911 | if(!usb_mode) | 912 | if(!usb_mode) |
912 | #endif | 913 | #endif |
914 | { | ||
913 | call_storage_idle_notifys(false); | 915 | call_storage_idle_notifys(false); |
916 | } | ||
914 | last_seen_mtx_unlock = 0; | 917 | last_seen_mtx_unlock = 0; |
915 | } | 918 | } |
916 | } | 919 | } |
@@ -923,7 +926,9 @@ static void ata_thread(void) | |||
923 | #ifdef ALLOW_USB_SPINDOWN | 926 | #ifdef ALLOW_USB_SPINDOWN |
924 | if(!usb_mode) | 927 | if(!usb_mode) |
925 | #endif | 928 | #endif |
929 | { | ||
926 | call_storage_idle_notifys(true); | 930 | call_storage_idle_notifys(true); |
931 | } | ||
927 | ata_perform_sleep(); | 932 | ata_perform_sleep(); |
928 | last_sleep = current_tick; | 933 | last_sleep = current_tick; |
929 | } | 934 | } |
@@ -935,14 +940,21 @@ static void ata_thread(void) | |||
935 | { | 940 | { |
936 | mutex_lock(&ata_mtx); | 941 | mutex_lock(&ata_mtx); |
937 | ide_power_enable(false); | 942 | ide_power_enable(false); |
938 | mutex_unlock(&ata_mtx); | ||
939 | poweroff = true; | 943 | poweroff = true; |
944 | mutex_unlock(&ata_mtx); | ||
940 | } | 945 | } |
941 | #endif | 946 | #endif |
942 | break; | 947 | break; |
943 | 948 | ||
944 | #ifndef USB_NONE | 949 | #ifndef USB_NONE |
945 | case SYS_USB_CONNECTED: | 950 | case SYS_USB_CONNECTED: |
951 | /* Tell the USB thread that we are safe */ | ||
952 | DEBUGF("ata_thread got SYS_USB_CONNECTED\n"); | ||
953 | #ifdef ALLOW_USB_SPINDOWN | ||
954 | usb_mode = true; | ||
955 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
956 | /* There is no need to force ATA power on */ | ||
957 | #else | ||
946 | if (poweroff) { | 958 | if (poweroff) { |
947 | mutex_lock(&ata_mtx); | 959 | mutex_lock(&ata_mtx); |
948 | ata_led(true); | 960 | ata_led(true); |
@@ -951,14 +963,8 @@ static void ata_thread(void) | |||
951 | mutex_unlock(&ata_mtx); | 963 | mutex_unlock(&ata_mtx); |
952 | } | 964 | } |
953 | 965 | ||
954 | /* Tell the USB thread that we are safe */ | ||
955 | DEBUGF("ata_thread got SYS_USB_CONNECTED\n"); | ||
956 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
957 | |||
958 | #ifdef ALLOW_USB_SPINDOWN | ||
959 | usb_mode = true; | ||
960 | #else | ||
961 | /* Wait until the USB cable is extracted again */ | 966 | /* Wait until the USB cable is extracted again */ |
967 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
962 | usb_wait_for_disconnect(&ata_queue); | 968 | usb_wait_for_disconnect(&ata_queue); |
963 | #endif | 969 | #endif |
964 | break; | 970 | break; |
@@ -971,12 +977,15 @@ static void ata_thread(void) | |||
971 | usb_mode = false; | 977 | usb_mode = false; |
972 | break; | 978 | break; |
973 | #endif | 979 | #endif |
974 | #endif | 980 | #endif /* USB_NONE */ |
981 | |||
975 | case Q_SLEEP: | 982 | case Q_SLEEP: |
976 | #ifdef ALLOW_USB_SPINDOWN | 983 | #ifdef ALLOW_USB_SPINDOWN |
977 | if(!usb_mode) | 984 | if(!usb_mode) |
978 | #endif | 985 | #endif |
986 | { | ||
979 | call_storage_idle_notifys(false); | 987 | call_storage_idle_notifys(false); |
988 | } | ||
980 | last_disk_activity = current_tick - sleep_timeout + (HZ/2); | 989 | last_disk_activity = current_tick - sleep_timeout + (HZ/2); |
981 | break; | 990 | break; |
982 | 991 | ||