summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/ata.c')
-rw-r--r--firmware/drivers/ata.c57
1 files changed, 49 insertions, 8 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index b80f615eb3..c2882a5b74 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -32,6 +32,7 @@
32#include "string.h" 32#include "string.h"
33#include "ata_idle_notify.h" 33#include "ata_idle_notify.h"
34#include "ata-target.h" 34#include "ata-target.h"
35#include "storage.h"
35 36
36#define SECTOR_SIZE (512) 37#define SECTOR_SIZE (512)
37 38
@@ -148,7 +149,7 @@ static void ata_lock_unlock(struct ata_lock *l)
148static struct mutex ata_mtx SHAREDBSS_ATTR; 149static struct mutex ata_mtx SHAREDBSS_ATTR;
149static int ata_device; /* device 0 (master) or 1 (slave) */ 150static int ata_device; /* device 0 (master) or 1 (slave) */
150 151
151int ata_spinup_time = 0; 152static int spinup_time = 0;
152#if (CONFIG_LED == LED_REAL) 153#if (CONFIG_LED == LED_REAL)
153static bool ata_led_enabled = true; 154static bool ata_led_enabled = true;
154static bool ata_led_on = false; 155static bool ata_led_on = false;
@@ -166,7 +167,7 @@ static struct event_queue ata_queue;
166static bool initialized = false; 167static bool initialized = false;
167 168
168static long last_user_activity = -1; 169static long last_user_activity = -1;
169long last_disk_activity = -1; 170static long last_disk_activity = -1;
170 171
171static unsigned long total_sectors; 172static unsigned long total_sectors;
172static int multisectors; /* number of supported multisectors */ 173static int multisectors; /* number of supported multisectors */
@@ -407,7 +408,7 @@ int ata_read_sectors(IF_MV2(int drive,)
407 } 408 }
408 409
409 if (spinup) { 410 if (spinup) {
410 ata_spinup_time = current_tick - spinup_start; 411 spinup_time = current_tick - spinup_start;
411 spinup = false; 412 spinup = false;
412 sleeping = false; 413 sleeping = false;
413 poweroff = false; 414 poweroff = false;
@@ -584,7 +585,7 @@ int ata_write_sectors(IF_MV2(int drive,)
584 } 585 }
585 586
586 if (spinup) { 587 if (spinup) {
587 ata_spinup_time = current_tick - spinup_start; 588 spinup_time = current_tick - spinup_start;
588 spinup = false; 589 spinup = false;
589 sleeping = false; 590 sleeping = false;
590 poweroff = false; 591 poweroff = false;
@@ -873,7 +874,7 @@ void ata_sleepnow(void)
873{ 874{
874 if (!spinup && !sleeping && !ata_mtx.locked && initialized) 875 if (!spinup && !sleeping && !ata_mtx.locked && initialized)
875 { 876 {
876 call_ata_idle_notifys(false); 877 call_storage_idle_notifys(false);
877 ata_perform_sleep(); 878 ata_perform_sleep();
878 } 879 }
879} 880}
@@ -908,7 +909,7 @@ static void ata_thread(void)
908#ifdef ALLOW_USB_SPINDOWN 909#ifdef ALLOW_USB_SPINDOWN
909 if(!usb_mode) 910 if(!usb_mode)
910#endif 911#endif
911 call_ata_idle_notifys(false); 912 call_storage_idle_notifys(false);
912 last_seen_mtx_unlock = 0; 913 last_seen_mtx_unlock = 0;
913 } 914 }
914 } 915 }
@@ -921,7 +922,7 @@ static void ata_thread(void)
921#ifdef ALLOW_USB_SPINDOWN 922#ifdef ALLOW_USB_SPINDOWN
922 if(!usb_mode) 923 if(!usb_mode)
923#endif 924#endif
924 call_ata_idle_notifys(true); 925 call_storage_idle_notifys(true);
925 ata_perform_sleep(); 926 ata_perform_sleep();
926 last_sleep = current_tick; 927 last_sleep = current_tick;
927 } 928 }
@@ -974,7 +975,7 @@ static void ata_thread(void)
974#ifdef ALLOW_USB_SPINDOWN 975#ifdef ALLOW_USB_SPINDOWN
975 if(!usb_mode) 976 if(!usb_mode)
976#endif 977#endif
977 call_ata_idle_notifys(false); 978 call_storage_idle_notifys(false);
978 last_disk_activity = current_tick - sleep_timeout + (HZ/2); 979 last_disk_activity = current_tick - sleep_timeout + (HZ/2);
979 break; 980 break;
980 981
@@ -1391,3 +1392,43 @@ void ata_set_led_enabled(bool enabled)
1391 led(false); 1392 led(false);
1392} 1393}
1393#endif 1394#endif
1395
1396long ata_last_disk_activity(void)
1397{
1398 return last_disk_activity;
1399}
1400
1401int ata_spinup_time(void)
1402{
1403 return spinup_time;
1404}
1405
1406void ata_get_info(struct storage_info *info)
1407{
1408 unsigned short *src,*dest;
1409 static char vendor[8];
1410 static char product[16];
1411 static char revision[4];
1412 int i;
1413 info->sector_size = SECTOR_SIZE;
1414 info->num_sectors= ((unsigned long)identify_info[61] << 16 | \
1415 (unsigned long)identify_info[60]);
1416
1417 src = (unsigned short*)&identify_info[27];
1418 dest = (unsigned short*)vendor;
1419 for (i=0;i<4;i++)
1420 dest[i] = htobe16(src[i]);
1421 info->vendor=vendor;
1422
1423 src = (unsigned short*)&identify_info[31];
1424 dest = (unsigned short*)product;
1425 for (i=0;i<8;i++)
1426 dest[i] = htobe16(src[i]);
1427 info->product=product;
1428
1429 src = (unsigned short*)&identify_info[23];
1430 dest = (unsigned short*)revision;
1431 for (i=0;i<2;i++)
1432 dest[i] = htobe16(src[i]);
1433 info->revision=revision;
1434}