summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/ata.c44
-rw-r--r--firmware/export/ata.h1
2 files changed, 32 insertions, 13 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 10f5f20c7b..956f61dc89 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -241,6 +241,8 @@ static volatile unsigned char* ata_control;
241 241
242bool old_recorder = false; 242bool old_recorder = false;
243int ata_spinup_time = 0; 243int ata_spinup_time = 0;
244static bool ata_led_enabled = true;
245static bool ata_led_on = false;
244static bool spinup = false; 246static bool spinup = false;
245static bool sleeping = true; 247static bool sleeping = true;
246static long sleep_timeout = 5*HZ; 248static long sleep_timeout = 5*HZ;
@@ -473,6 +475,13 @@ static void copy_read_sectors(unsigned char* buf, int wordcount)
473#endif 475#endif
474} 476}
475 477
478static void ata_led(bool on) {
479 ata_led_on = on;
480 if (ata_led_enabled) {
481 led(ata_led_on);
482 }
483}
484
476int ata_read_sectors(IF_MV2(int drive,) 485int ata_read_sectors(IF_MV2(int drive,)
477 unsigned long start, 486 unsigned long start,
478 int incount, 487 int incount,
@@ -492,21 +501,21 @@ int ata_read_sectors(IF_MV2(int drive,)
492 last_disk_activity = current_tick; 501 last_disk_activity = current_tick;
493 spinup_start = current_tick; 502 spinup_start = current_tick;
494 503
495 led(true); 504 ata_led(true);
496 505
497 if ( sleeping ) { 506 if ( sleeping ) {
498 spinup = true; 507 spinup = true;
499 if (poweroff) { 508 if (poweroff) {
500 if (ata_power_on()) { 509 if (ata_power_on()) {
501 mutex_unlock(&ata_mtx); 510 mutex_unlock(&ata_mtx);
502 led(false); 511 ata_led(false);
503 return -1; 512 return -1;
504 } 513 }
505 } 514 }
506 else { 515 else {
507 if (perform_soft_reset()) { 516 if (perform_soft_reset()) {
508 mutex_unlock(&ata_mtx); 517 mutex_unlock(&ata_mtx);
509 led(false); 518 ata_led(false);
510 return -1; 519 return -1;
511 } 520 }
512 } 521 }
@@ -518,7 +527,7 @@ int ata_read_sectors(IF_MV2(int drive,)
518 if (!wait_for_rdy()) 527 if (!wait_for_rdy())
519 { 528 {
520 mutex_unlock(&ata_mtx); 529 mutex_unlock(&ata_mtx);
521 led(false); 530 ata_led(false);
522 return -2; 531 return -2;
523 } 532 }
524 533
@@ -614,7 +623,7 @@ int ata_read_sectors(IF_MV2(int drive,)
614 } 623 }
615 break; 624 break;
616 } 625 }
617 led(false); 626 ata_led(false);
618 627
619 mutex_unlock(&ata_mtx); 628 mutex_unlock(&ata_mtx);
620 629
@@ -775,21 +784,21 @@ int ata_write_sectors(IF_MV2(int drive,)
775 last_disk_activity = current_tick; 784 last_disk_activity = current_tick;
776 spinup_start = current_tick; 785 spinup_start = current_tick;
777 786
778 led(true); 787 ata_led(true);
779 788
780 if ( sleeping ) { 789 if ( sleeping ) {
781 spinup = true; 790 spinup = true;
782 if (poweroff) { 791 if (poweroff) {
783 if (ata_power_on()) { 792 if (ata_power_on()) {
784 mutex_unlock(&ata_mtx); 793 mutex_unlock(&ata_mtx);
785 led(false); 794 ata_led(false);
786 return -1; 795 return -1;
787 } 796 }
788 } 797 }
789 else { 798 else {
790 if (perform_soft_reset()) { 799 if (perform_soft_reset()) {
791 mutex_unlock(&ata_mtx); 800 mutex_unlock(&ata_mtx);
792 led(false); 801 ata_led(false);
793 return -1; 802 return -1;
794 } 803 }
795 } 804 }
@@ -799,7 +808,7 @@ int ata_write_sectors(IF_MV2(int drive,)
799 if (!wait_for_rdy()) 808 if (!wait_for_rdy())
800 { 809 {
801 mutex_unlock(&ata_mtx); 810 mutex_unlock(&ata_mtx);
802 led(false); 811 ata_led(false);
803 return -2; 812 return -2;
804 } 813 }
805 814
@@ -843,7 +852,7 @@ int ata_write_sectors(IF_MV2(int drive,)
843 ret = -4; 852 ret = -4;
844 } 853 }
845 854
846 led(false); 855 ata_led(false);
847 856
848 mutex_unlock(&ata_mtx); 857 mutex_unlock(&ata_mtx);
849 858
@@ -1042,9 +1051,9 @@ static void ata_thread(void)
1042 case SYS_USB_CONNECTED: 1051 case SYS_USB_CONNECTED:
1043 if (poweroff) { 1052 if (poweroff) {
1044 mutex_lock(&ata_mtx); 1053 mutex_lock(&ata_mtx);
1045 led(true); 1054 ata_led(true);
1046 ata_power_on(); 1055 ata_power_on();
1047 led(false); 1056 ata_led(false);
1048 mutex_unlock(&ata_mtx); 1057 mutex_unlock(&ata_mtx);
1049 } 1058 }
1050 1059
@@ -1384,7 +1393,7 @@ int ata_init(void)
1384 1393
1385 mutex_init(&ata_mtx); 1394 mutex_init(&ata_mtx);
1386 1395
1387 led(false); 1396 ata_led(false);
1388 1397
1389#if CONFIG_CPU == SH7034 1398#if CONFIG_CPU == SH7034
1390 /* Port A setup */ 1399 /* Port A setup */
@@ -1458,3 +1467,12 @@ int ata_init(void)
1458 1467
1459 return 0; 1468 return 0;
1460} 1469}
1470
1471void ata_set_led_enabled(bool enabled) {
1472 ata_led_enabled = enabled;
1473 if (ata_led_enabled) {
1474 led(ata_led_on);
1475 } else {
1476 led(false);
1477 }
1478}
diff --git a/firmware/export/ata.h b/firmware/export/ata.h
index fb604a120d..2043de915a 100644
--- a/firmware/export/ata.h
+++ b/firmware/export/ata.h
@@ -61,6 +61,7 @@ extern int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count,
61extern void ata_delayed_write(unsigned long sector, const void* buf); 61extern void ata_delayed_write(unsigned long sector, const void* buf);
62extern void ata_flush(void); 62extern void ata_flush(void);
63extern void ata_spin(void); 63extern void ata_spin(void);
64extern void ata_set_led_enabled(bool enabled);
64extern unsigned short* ata_get_identify(void); 65extern unsigned short* ata_get_identify(void);
65 66
66extern long last_disk_activity; 67extern long last_disk_activity;