diff options
-rw-r--r-- | firmware/drivers/ata.c | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index af6955b2b0..1e889a3339 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -33,29 +33,39 @@ | |||
33 | /* skip whole file for an MMC-based system, FIXME in makefile */ | 33 | /* skip whole file for an MMC-based system, FIXME in makefile */ |
34 | #ifndef HAVE_MMC | 34 | #ifndef HAVE_MMC |
35 | 35 | ||
36 | /* Uncomment the matching #define to use plain C code instead if the tweaked | 36 | #ifdef HAVE_SCF5249 |
37 | * assembler code for disk reading or writing should cause problems. */ | ||
38 | /* #define PREFER_C_READING */ | ||
39 | /* #define PREFER_C_WRITING */ | ||
40 | 37 | ||
41 | #define SECTOR_SIZE 512 | 38 | /* don't use sh7034 assembler routines */ |
42 | #define ATA_DATA (*((volatile unsigned short*)0x06104100)) | 39 | #define PREFER_C_READING |
43 | #define ATA_ERROR (*((volatile unsigned char*)0x06100101)) | 40 | #define PREFER_C_WRITING |
44 | #define ATA_FEATURE ATA_ERROR | 41 | |
45 | #define ATA_NSECTOR (*((volatile unsigned char*)0x06100102)) | 42 | #define ATA_IOBASE 0x20000000 |
46 | #define ATA_SECTOR (*((volatile unsigned char*)0x06100103)) | 43 | #define ATA_DATA (*((volatile unsigned short*)ATA_IOBASE)) |
47 | #define ATA_LCYL (*((volatile unsigned char*)0x06100104)) | 44 | #define ATA_CONTROL (*((volatile unsigned short*)ATA_IOBASE + 0xe)) |
48 | #define ATA_HCYL (*((volatile unsigned char*)0x06100105)) | 45 | |
49 | #define ATA_SELECT (*((volatile unsigned char*)0x06100106)) | 46 | #elif defined HAVE_SH7034 |
50 | #define ATA_COMMAND (*((volatile unsigned char*)0x06100107)) | ||
51 | #define ATA_STATUS (*((volatile unsigned char*)0x06100107)) | ||
52 | 47 | ||
48 | #define ATA_IOBASE 0x06100100 | ||
49 | #define ATA_DATA (*((volatile unsigned short*)0x06104100)) | ||
53 | #define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) | 50 | #define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) |
54 | #define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) | 51 | #define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) |
55 | |||
56 | #define ATA_CONTROL (*ata_control) | 52 | #define ATA_CONTROL (*ata_control) |
53 | #endif | ||
54 | |||
55 | /* generic registers */ | ||
56 | #define ATA_ERROR (*((volatile unsigned char*)ATA_IOBASE + 1)) | ||
57 | #define ATA_NSECTOR (*((volatile unsigned char*)ATA_IOBASE + 2)) | ||
58 | #define ATA_SECTOR (*((volatile unsigned char*)ATA_IOBASE + 3)) | ||
59 | #define ATA_LCYL (*((volatile unsigned char*)ATA_IOBASE + 4)) | ||
60 | #define ATA_HCYL (*((volatile unsigned char*)ATA_IOBASE + 5)) | ||
61 | #define ATA_SELECT (*((volatile unsigned char*)ATA_IOBASE + 6)) | ||
62 | #define ATA_COMMAND (*((volatile unsigned char*)ATA_IOBASE + 7)) | ||
63 | #define ATA_FEATURE ATA_ERROR | ||
64 | #define ATA_STATUS ATA_COMMAND | ||
57 | #define ATA_ALT_STATUS ATA_CONTROL | 65 | #define ATA_ALT_STATUS ATA_CONTROL |
58 | 66 | ||
67 | |||
68 | |||
59 | #define SELECT_DEVICE1 0x10 | 69 | #define SELECT_DEVICE1 0x10 |
60 | #define SELECT_LBA 0x40 | 70 | #define SELECT_LBA 0x40 |
61 | 71 | ||
@@ -86,6 +96,8 @@ | |||
86 | 96 | ||
87 | #define READ_TIMEOUT 5*HZ | 97 | #define READ_TIMEOUT 5*HZ |
88 | 98 | ||
99 | #define SECTOR_SIZE 512 | ||
100 | |||
89 | static struct mutex ata_mtx; | 101 | static struct mutex ata_mtx; |
90 | char ata_device; /* device 0 (master) or 1 (slave) */ | 102 | char ata_device; /* device 0 (master) or 1 (slave) */ |
91 | int ata_io_address; /* 0x300 or 0x200, only valid on recorder */ | 103 | int ata_io_address; /* 0x300 or 0x200, only valid on recorder */ |
@@ -699,15 +711,19 @@ static int check_registers(void) | |||
699 | 711 | ||
700 | static int freeze_lock(void) | 712 | static int freeze_lock(void) |
701 | { | 713 | { |
702 | ATA_SELECT = ata_device; | 714 | /* does the disk support Security Mode feature set? */ |
715 | if (identify_info[82] & 2) | ||
716 | { | ||
717 | ATA_SELECT = ata_device; | ||
703 | 718 | ||
704 | if (!wait_for_rdy()) | 719 | if (!wait_for_rdy()) |
705 | return -1; | 720 | return -1; |
706 | 721 | ||
707 | ATA_COMMAND = CMD_SECURITY_FREEZE_LOCK; | 722 | ATA_COMMAND = CMD_SECURITY_FREEZE_LOCK; |
708 | 723 | ||
709 | if (!wait_for_rdy()) | 724 | if (!wait_for_rdy()) |
710 | return -2; | 725 | return -2; |
726 | } | ||
711 | 727 | ||
712 | return 0; | 728 | return 0; |
713 | } | 729 | } |
@@ -862,7 +878,8 @@ static void ata_thread(void) | |||
862 | int ata_hard_reset(void) | 878 | int ata_hard_reset(void) |
863 | { | 879 | { |
864 | int ret; | 880 | int ret; |
865 | 881 | ||
882 | #ifdef HAVE_SH7034 | ||
866 | /* state HRR0 */ | 883 | /* state HRR0 */ |
867 | and_b(~0x02, &PADRH); /* assert _RESET */ | 884 | and_b(~0x02, &PADRH); /* assert _RESET */ |
868 | sleep(1); /* > 25us */ | 885 | sleep(1); /* > 25us */ |
@@ -870,6 +887,8 @@ int ata_hard_reset(void) | |||
870 | /* state HRR1 */ | 887 | /* state HRR1 */ |
871 | or_b(0x02, &PADRH); /* negate _RESET */ | 888 | or_b(0x02, &PADRH); /* negate _RESET */ |
872 | sleep(1); /* > 2ms */ | 889 | sleep(1); /* > 2ms */ |
890 | #elif defined HAVE_SCF5249 | ||
891 | #endif | ||
873 | 892 | ||
874 | /* state HRR2 */ | 893 | /* state HRR2 */ |
875 | ATA_SELECT = ata_device; /* select the right device */ | 894 | ATA_SELECT = ata_device; /* select the right device */ |
@@ -960,6 +979,7 @@ static int master_slave_detect(void) | |||
960 | return 0; | 979 | return 0; |
961 | } | 980 | } |
962 | 981 | ||
982 | #ifdef HAVE_SH7034 /* special archos quirk */ | ||
963 | static int io_address_detect(void) | 983 | static int io_address_detect(void) |
964 | { /* now, use the HW mask instead of probing */ | 984 | { /* now, use the HW mask instead of probing */ |
965 | if (read_hw_mask() & ATA_ADDRESS_200) | 985 | if (read_hw_mask() & ATA_ADDRESS_200) |
@@ -977,15 +997,19 @@ static int io_address_detect(void) | |||
977 | 997 | ||
978 | return 0; | 998 | return 0; |
979 | } | 999 | } |
1000 | #endif | ||
980 | 1001 | ||
981 | void ata_enable(bool on) | 1002 | void ata_enable(bool on) |
982 | { | 1003 | { |
1004 | #ifdef HAVE_SH7034 | ||
983 | if(on) | 1005 | if(on) |
984 | and_b(~0x80, &PADRL); /* enable ATA */ | 1006 | and_b(~0x80, &PADRL); /* enable ATA */ |
985 | else | 1007 | else |
986 | or_b(0x80, &PADRL); /* disable ATA */ | 1008 | or_b(0x80, &PADRL); /* disable ATA */ |
987 | 1009 | ||
988 | or_b(0x80, &PAIORL); | 1010 | or_b(0x80, &PAIORL); |
1011 | #elif defined HAVE_SCF5249 | ||
1012 | #endif | ||
989 | } | 1013 | } |
990 | 1014 | ||
991 | static int identify(void) | 1015 | static int identify(void) |
@@ -1105,10 +1129,13 @@ int ata_init(void) | |||
1105 | 1129 | ||
1106 | led(false); | 1130 | led(false); |
1107 | 1131 | ||
1132 | #ifdef HAVE_SH7034 | ||
1108 | /* Port A setup */ | 1133 | /* Port A setup */ |
1109 | or_b(0x02, &PAIORH); /* output for ATA reset */ | 1134 | or_b(0x02, &PAIORH); /* output for ATA reset */ |
1110 | or_b(0x02, &PADRH); /* release ATA reset */ | 1135 | or_b(0x02, &PADRH); /* release ATA reset */ |
1111 | PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */ | 1136 | PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */ |
1137 | #elif defined HAVE_SCF5249 | ||
1138 | #endif | ||
1112 | 1139 | ||
1113 | sleeping = false; | 1140 | sleeping = false; |
1114 | ata_enable(true); | 1141 | ata_enable(true); |
@@ -1132,9 +1159,11 @@ int ata_init(void) | |||
1132 | if (rc) | 1159 | if (rc) |
1133 | return -10 + rc; | 1160 | return -10 + rc; |
1134 | 1161 | ||
1162 | #ifdef HAVE_SH7034 | ||
1135 | rc = io_address_detect(); | 1163 | rc = io_address_detect(); |
1136 | if (rc) | 1164 | if (rc) |
1137 | return -20 + rc; | 1165 | return -20 + rc; |
1166 | #endif | ||
1138 | 1167 | ||
1139 | /* symptom fix: else check_registers() below may fail */ | 1168 | /* symptom fix: else check_registers() below may fail */ |
1140 | if (coldstart && !wait_for_bsy()) | 1169 | if (coldstart && !wait_for_bsy()) |
@@ -1146,16 +1175,16 @@ int ata_init(void) | |||
1146 | if (rc) | 1175 | if (rc) |
1147 | return -30 + rc; | 1176 | return -30 + rc; |
1148 | 1177 | ||
1149 | rc = freeze_lock(); | ||
1150 | if (rc) | ||
1151 | return -40 + rc; | ||
1152 | |||
1153 | rc = identify(); | 1178 | rc = identify(); |
1154 | if (rc) | 1179 | if (rc) |
1155 | return -50 + rc; | 1180 | return -40 + rc; |
1156 | multisectors = identify_info[47] & 0xff; | 1181 | multisectors = identify_info[47] & 0xff; |
1157 | DEBUGF("ata: %d sectors per ata request\n",multisectors); | 1182 | DEBUGF("ata: %d sectors per ata request\n",multisectors); |
1158 | 1183 | ||
1184 | rc = freeze_lock(); | ||
1185 | if (rc) | ||
1186 | return -50 + rc; | ||
1187 | |||
1159 | rc = set_features(); | 1188 | rc = set_features(); |
1160 | if (rc) | 1189 | if (rc) |
1161 | return -60 + rc; | 1190 | return -60 + rc; |