summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2005-01-26 12:53:48 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2005-01-26 12:53:48 +0000
commit4058b79c70f5ec5c97fa7aa7c361098155c7e96c (patch)
tree503e0565e8b34d3103d595ae416f723fafc51811 /firmware/drivers/ata.c
parentf07ddacb7d3d7939043d017dbca9fb4fbb2d93b1 (diff)
downloadrockbox-4058b79c70f5ec5c97fa7aa7c361098155c7e96c.tar.gz
rockbox-4058b79c70f5ec5c97fa7aa7c361098155c7e96c.zip
Ported ATA driver to iRiver, minor code policing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5663 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/ata.c')
-rw-r--r--firmware/drivers/ata.c277
1 files changed, 181 insertions, 96 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 0983fb52ee..2385e74b4c 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -37,24 +37,84 @@
37#define PREFER_C_WRITING 37#define PREFER_C_WRITING
38 38
39#define ATA_IOBASE 0x20000000 39#define ATA_IOBASE 0x20000000
40#define ATA_DATA (*((volatile unsigned short*)ATA_IOBASE)) 40#define ATA_DATA (*((volatile unsigned short*)(ATA_IOBASE + 0x20)))
41#define ATA_CONTROL (*((volatile unsigned short*)ATA_IOBASE + 0xe)) 41#define ATA_CONTROL (*((volatile unsigned short*)(ATA_IOBASE + 0xe)))
42
43#define ATA_ERROR (*((volatile unsigned short*)(ATA_IOBASE + 0x22)))
44#define ATA_NSECTOR (*((volatile unsigned short*)(ATA_IOBASE + 0x24)))
45#define ATA_SECTOR (*((volatile unsigned short*)(ATA_IOBASE + 0x26)))
46#define ATA_LCYL (*((volatile unsigned short*)(ATA_IOBASE + 0x28)))
47#define ATA_HCYL (*((volatile unsigned short*)(ATA_IOBASE + 0x2a)))
48#define ATA_SELECT (*((volatile unsigned short*)(ATA_IOBASE + 0x2c)))
49#define ATA_COMMAND (*((volatile unsigned short*)(ATA_IOBASE + 0x2e)))
50
51#define STATUS_BSY 0x8000
52#define STATUS_RDY 0x4000
53#define STATUS_DF 0x2000
54#define STATUS_DRQ 0x0800
55#define STATUS_ERR 0x0100
56
57#define ERROR_ABRT 0x0400
58
59#define WRITE_PATTERN1 0xa5
60#define WRITE_PATTERN2 0x5a
61#define WRITE_PATTERN3 0xaa
62#define WRITE_PATTERN4 0x55
63
64#define READ_PATTERN1 0xa500
65#define READ_PATTERN2 0x5a00
66#define READ_PATTERN3 0xaa00
67#define READ_PATTERN4 0x5500
68
69#define SET_REG(reg,val) reg = ((val) << 8)
70#define SET_16BITREG(reg,val) reg = (val)
42 71
43#elif CONFIG_CPU == SH7034 72#elif CONFIG_CPU == SH7034
44 73
74#define SWAP_WORDS
75
45#define ATA_IOBASE 0x06100100 76#define ATA_IOBASE 0x06100100
46#define ATA_DATA (*((volatile unsigned short*)0x06104100)) 77#define ATA_DATA (*((volatile unsigned short*)0x06104100))
47#define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) 78#define ATA_CONTROL1 ((volatile unsigned char*)0x06200206)
48#define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) 79#define ATA_CONTROL2 ((volatile unsigned char*)0x06200306)
49#define ATA_CONTROL (*ata_control) 80#define ATA_CONTROL (*ata_control)
50 81
51#endif 82#define ATA_ERROR (*((volatile unsigned char*)ATA_IOBASE + 1))
83#define ATA_NSECTOR (*((volatile unsigned char*)ATA_IOBASE + 2))
84#define ATA_SECTOR (*((volatile unsigned char*)ATA_IOBASE + 3))
85#define ATA_LCYL (*((volatile unsigned char*)ATA_IOBASE + 4))
86#define ATA_HCYL (*((volatile unsigned char*)ATA_IOBASE + 5))
87#define ATA_SELECT (*((volatile unsigned char*)ATA_IOBASE + 6))
88#define ATA_COMMAND (*((volatile unsigned char*)ATA_IOBASE + 7))
52 89
53#if CONFIG_CPU == TCC730 90#define STATUS_BSY 0x80
91#define STATUS_RDY 0x40
92#define STATUS_DF 0x20
93#define STATUS_DRQ 0x08
94#define STATUS_ERR 0x01
95
96#define ERROR_ABRT 0x04
97
98#define WRITE_PATTERN1 0xa5
99#define WRITE_PATTERN2 0x5a
100#define WRITE_PATTERN3 0xaa
101#define WRITE_PATTERN4 0x55
102
103#define READ_PATTERN1 0xa5
104#define READ_PATTERN2 0x5a
105#define READ_PATTERN3 0xaa
106#define READ_PATTERN4 0x55
107
108#define SET_REG(reg,val) reg = (val)
109#define SET_16BITREG(reg,val) reg = (val)
110
111#elif CONFIG_CPU == TCC730
54 112
55#define PREFER_C_READING 113#define PREFER_C_READING
56#define PREFER_C_WRITING 114#define PREFER_C_WRITING
57 115
116#define SWAP_WORDS
117
58#define ATA_DATA_IDX (0xD0) 118#define ATA_DATA_IDX (0xD0)
59#define ATA_ERROR_IDX (0xD2) 119#define ATA_ERROR_IDX (0xD2)
60#define ATA_NSECTOR_IDX (0xD4) 120#define ATA_NSECTOR_IDX (0xD4)
@@ -70,6 +130,7 @@
70#define ATA_ALT_STATUS_IDX ATA_CONTROL_IDX 130#define ATA_ALT_STATUS_IDX ATA_CONTROL_IDX
71 131
72#define SET_REG(reg, value) (ide_write_register(reg ## _IDX, value)) 132#define SET_REG(reg, value) (ide_write_register(reg ## _IDX, value))
133#define SET_16BITREG(reg, value) (ide_write_register(reg ## _IDX, value))
73#define GET_REG(reg) (ide_read_register(reg)) 134#define GET_REG(reg) (ide_read_register(reg))
74 135
75#define ATA_DATA (GET_REG(ATA_DATA_IDX)) 136#define ATA_DATA (GET_REG(ATA_DATA_IDX))
@@ -85,6 +146,23 @@
85#define ATA_ALT_STATUS (GET_REG(ATA_ALT_STATUS_IDX)) 146#define ATA_ALT_STATUS (GET_REG(ATA_ALT_STATUS_IDX))
86#define ATA_FEATURE (GET_REG(ATA_FEATURE_IDX)) 147#define ATA_FEATURE (GET_REG(ATA_FEATURE_IDX))
87 148
149#define STATUS_BSY 0x80
150#define STATUS_RDY 0x40
151#define STATUS_DF 0x20
152#define STATUS_DRQ 0x08
153#define STATUS_ERR 0x01
154
155#define ERROR_ABRT 0x04
156
157#define WRITE_PATTERN1 0xa5
158#define WRITE_PATTERN2 0x5a
159#define WRITE_PATTERN3 0xaa
160#define WRITE_PATTERN4 0x55
161
162#define READ_PATTERN1 0xa5
163#define READ_PATTERN2 0x5a
164#define READ_PATTERN3 0xaa
165#define READ_PATTERN4 0x55
88 166
89extern int idatastart __attribute__ ((section(".idata"))); 167extern int idatastart __attribute__ ((section(".idata")));
90 168
@@ -125,47 +203,15 @@ int ide_read_register(int reg) {
125 return ide_reg_temp; 203 return ide_reg_temp;
126} 204}
127 205
206#endif
128 207
129#else
130
131/* generic registers */
132#define ATA_ERROR (*((volatile unsigned char*)ATA_IOBASE + 1))
133#define ATA_NSECTOR (*((volatile unsigned char*)ATA_IOBASE + 2))
134#define ATA_SECTOR (*((volatile unsigned char*)ATA_IOBASE + 3))
135#define ATA_LCYL (*((volatile unsigned char*)ATA_IOBASE + 4))
136#define ATA_HCYL (*((volatile unsigned char*)ATA_IOBASE + 5))
137#define ATA_SELECT (*((volatile unsigned char*)ATA_IOBASE + 6))
138#define ATA_COMMAND (*((volatile unsigned char*)ATA_IOBASE + 7))
139#define ATA_FEATURE ATA_ERROR 208#define ATA_FEATURE ATA_ERROR
140#define ATA_STATUS ATA_COMMAND 209#define ATA_STATUS ATA_COMMAND
141#define ATA_ALT_STATUS ATA_CONTROL 210#define ATA_ALT_STATUS ATA_CONTROL
142 211
143#define SET_REG(reg, value) ((reg) = (value))
144
145#endif
146
147#define SET_ATA_DATA(v) (SET_REG(ATA_DATA,v))
148#define SET_ATA_SELECT(v) (SET_REG(ATA_SELECT,v))
149#define SET_ATA_NSECTOR(v) (SET_REG(ATA_NSECTOR,v))
150#define SET_ATA_SECTOR(v) (SET_REG(ATA_SECTOR,v))
151#define SET_ATA_LCYL(v) (SET_REG(ATA_LCYL,v))
152#define SET_ATA_HCYL(v) (SET_REG(ATA_HCYL,v))
153#define SET_ATA_COMMAND(v) (SET_REG(ATA_COMMAND,v))
154#define SET_ATA_CONTROL(v) (SET_REG(ATA_CONTROL,v))
155#define SET_ATA_FEATURE(v) (SET_REG(ATA_FEATURE, v))
156
157
158#define SELECT_DEVICE1 0x10 212#define SELECT_DEVICE1 0x10
159#define SELECT_LBA 0x40 213#define SELECT_LBA 0x40
160 214
161#define STATUS_BSY 0x80
162#define STATUS_RDY 0x40
163#define STATUS_DF 0x20
164#define STATUS_DRQ 0x08
165#define STATUS_ERR 0x01
166
167#define ERROR_ABRT 0x04
168
169#define CONTROL_nIEN 0x02 215#define CONTROL_nIEN 0x02
170#define CONTROL_SRST 0x04 216#define CONTROL_SRST 0x04
171 217
@@ -190,7 +236,9 @@ int ide_read_register(int reg) {
190static struct mutex ata_mtx; 236static struct mutex ata_mtx;
191char ata_device; /* device 0 (master) or 1 (slave) */ 237char ata_device; /* device 0 (master) or 1 (slave) */
192int ata_io_address; /* 0x300 or 0x200, only valid on recorder */ 238int ata_io_address; /* 0x300 or 0x200, only valid on recorder */
239#if CONFIG_CPU == SH7034
193static volatile unsigned char* ata_control; 240static volatile unsigned char* ata_control;
241#endif
194 242
195bool old_recorder = false; 243bool old_recorder = false;
196int ata_spinup_time = 0; 244int ata_spinup_time = 0;
@@ -294,8 +342,13 @@ static void copy_read_sectors(unsigned char* buf, int wordcount)
294 { /* loop compiles to 9 assembler instructions */ 342 { /* loop compiles to 9 assembler instructions */
295 /* takes 14 clock cycles (2 pipeline stalls, 1 wait) */ 343 /* takes 14 clock cycles (2 pipeline stalls, 1 wait) */
296 tmp = ATA_DATA; 344 tmp = ATA_DATA;
345#ifdef SWAP_WORDS
297 *buf++ = tmp & 0xff; /* I assume big endian */ 346 *buf++ = tmp & 0xff; /* I assume big endian */
298 *buf++ = tmp >> 8; /* and don't use the SWAB16 macro */ 347 *buf++ = tmp >> 8; /* and don't use the SWAB16 macro */
348#else
349 *buf++ = tmp >> 8;
350 *buf++ = tmp & 0xff;
351#endif
299 } while (buf < bufend); /* tail loop is faster */ 352 } while (buf < bufend); /* tail loop is faster */
300 } 353 }
301 else 354 else
@@ -305,7 +358,11 @@ static void copy_read_sectors(unsigned char* buf, int wordcount)
305 do 358 do
306 { /* loop compiles to 7 assembler instructions */ 359 { /* loop compiles to 7 assembler instructions */
307 /* takes 12 clock cycles (2 pipeline stalls, 1 wait) */ 360 /* takes 12 clock cycles (2 pipeline stalls, 1 wait) */
361#ifdef SWAP_WORDS
308 *wbuf = SWAB16(ATA_DATA); 362 *wbuf = SWAB16(ATA_DATA);
363#else
364 *wbuf = ATA_DATA;
365#endif
309 } while (++wbuf < wbufend); /* tail loop is faster */ 366 } while (++wbuf < wbufend); /* tail loop is faster */
310 } 367 }
311#else 368#else
@@ -415,7 +472,7 @@ int ata_read_sectors(IF_MV2(int drive,)
415 int timeout; 472 int timeout;
416 int count; 473 int count;
417 void* buf; 474 void* buf;
418 int spinup_start; 475 long spinup_start;
419 476
420#ifdef HAVE_MULTIVOLUME 477#ifdef HAVE_MULTIVOLUME
421 (void)drive; /* unused for now */ 478 (void)drive; /* unused for now */
@@ -447,7 +504,7 @@ int ata_read_sectors(IF_MV2(int drive,)
447 504
448 timeout = current_tick + READ_TIMEOUT; 505 timeout = current_tick + READ_TIMEOUT;
449 506
450 SET_ATA_SELECT(ata_device); 507 SET_REG(ATA_SELECT, ata_device);
451 if (!wait_for_rdy()) 508 if (!wait_for_rdy())
452 { 509 {
453 mutex_unlock(&ata_mtx); 510 mutex_unlock(&ata_mtx);
@@ -463,15 +520,15 @@ int ata_read_sectors(IF_MV2(int drive,)
463 last_disk_activity = current_tick; 520 last_disk_activity = current_tick;
464 521
465 if ( count == 256 ) 522 if ( count == 256 )
466 SET_ATA_NSECTOR(0); /* 0 means 256 sectors */ 523 SET_REG(ATA_NSECTOR, 0); /* 0 means 256 sectors */
467 else 524 else
468 SET_ATA_NSECTOR((unsigned char)count); 525 SET_REG(ATA_NSECTOR, (unsigned char)count);
469 526
470 SET_ATA_SECTOR(start & 0xff); 527 SET_REG(ATA_SECTOR, start & 0xff);
471 SET_ATA_LCYL((start >> 8) & 0xff); 528 SET_REG(ATA_LCYL, (start >> 8) & 0xff);
472 SET_ATA_HCYL((start >> 16) & 0xff); 529 SET_REG(ATA_HCYL, (start >> 16) & 0xff);
473 SET_ATA_SELECT(((start >> 24) & 0xf) | SELECT_LBA | ata_device); 530 SET_REG(ATA_SELECT, ((start >> 24) & 0xf) | SELECT_LBA | ata_device);
474 SET_ATA_COMMAND(CMD_READ_MULTIPLE); 531 SET_REG(ATA_COMMAND, CMD_READ_MULTIPLE);
475 532
476 /* wait at least 400ns between writing command and reading status */ 533 /* wait at least 400ns between writing command and reading status */
477 __asm__ volatile ("nop"); 534 __asm__ volatile ("nop");
@@ -572,11 +629,18 @@ static void copy_write_sectors(const unsigned char* buf, int wordcount)
572 unsigned short tmp = 0; 629 unsigned short tmp = 0;
573 const unsigned char* bufend = buf + wordcount*2; 630 const unsigned char* bufend = buf + wordcount*2;
574 do 631 do
575 { /* loop compiles to 9 assembler instructions */ 632 {
633#ifdef SWAP_WORDS
634 /* SH1: loop compiles to 9 assembler instructions */
576 /* takes 13 clock cycles (2 pipeline stalls) */ 635 /* takes 13 clock cycles (2 pipeline stalls) */
577 tmp = (unsigned short) *buf++; 636 tmp = (unsigned short) *buf++;
578 tmp |= (unsigned short) *buf++ << 8; /* I assume big endian */ 637 tmp |= (unsigned short) *buf++ << 8; /* I assume big endian */
579 SET_ATA_DATA(tmp); /* and don't use the SWAB16 macro */ 638 SET_16BITREG(ATA_DATA, tmp); /* and don't use the SWAB16 macro */
639#else
640 tmp = (unsigned short) *buf++ << 8;
641 tmp |= (unsigned short) *buf++;
642 SET_16BITREG(ATA_DATA, tmp);
643#endif
580 } while (buf < bufend); /* tail loop is faster */ 644 } while (buf < bufend); /* tail loop is faster */
581 } 645 }
582 else 646 else
@@ -584,9 +648,14 @@ static void copy_write_sectors(const unsigned char* buf, int wordcount)
584 unsigned short* wbuf = (unsigned short*)buf; 648 unsigned short* wbuf = (unsigned short*)buf;
585 unsigned short* wbufend = wbuf + wordcount; 649 unsigned short* wbufend = wbuf + wordcount;
586 do 650 do
587 { /* loop compiles to 6 assembler instructions */ 651 {
652#ifdef SWAP_WORDS
653 /* loop compiles to 6 assembler instructions */
588 /* takes 10 clock cycles (2 pipeline stalls) */ 654 /* takes 10 clock cycles (2 pipeline stalls) */
589 SET_ATA_DATA(SWAB16(*wbuf)); 655 SET_16BITREG(ATA_DATA, SWAB16(*wbuf));
656#else
657 SET_16BITREG(ATA_DATA, *wbuf);
658#endif
590 } while (++wbuf < wbufend); /* tail loop is faster */ 659 } while (++wbuf < wbufend); /* tail loop is faster */
591 } 660 }
592#else 661#else
@@ -716,7 +785,7 @@ int ata_write_sectors(IF_MV2(int drive,)
716 } 785 }
717 } 786 }
718 787
719 SET_ATA_SELECT(ata_device); 788 SET_REG(ATA_SELECT, ata_device);
720 if (!wait_for_rdy()) 789 if (!wait_for_rdy())
721 { 790 {
722 mutex_unlock(&ata_mtx); 791 mutex_unlock(&ata_mtx);
@@ -725,14 +794,14 @@ int ata_write_sectors(IF_MV2(int drive,)
725 } 794 }
726 795
727 if ( count == 256 ) 796 if ( count == 256 )
728 SET_ATA_NSECTOR(0); /* 0 means 256 sectors */ 797 SET_REG(ATA_NSECTOR, 0); /* 0 means 256 sectors */
729 else 798 else
730 SET_ATA_NSECTOR((unsigned char)count); 799 SET_REG(ATA_NSECTOR, (unsigned char)count);
731 SET_ATA_SECTOR(start & 0xff); 800 SET_REG(ATA_SECTOR, start & 0xff);
732 SET_ATA_LCYL((start >> 8) & 0xff); 801 SET_REG(ATA_LCYL, (start >> 8) & 0xff);
733 SET_ATA_HCYL((start >> 16) & 0xff); 802 SET_REG(ATA_HCYL, (start >> 16) & 0xff);
734 SET_ATA_SELECT(((start >> 24) & 0xf) | SELECT_LBA | ata_device); 803 SET_REG(ATA_SELECT, ((start >> 24) & 0xf) | SELECT_LBA | ata_device);
735 SET_ATA_COMMAND(CMD_WRITE_SECTORS); 804 SET_REG(ATA_COMMAND, CMD_WRITE_SECTORS);
736 805
737 for (i=0; i<count; i++) { 806 for (i=0; i<count; i++) {
738 807
@@ -803,15 +872,15 @@ static int check_registers(void)
803 return -1; 872 return -1;
804 873
805 for (i = 0; i<64; i++) { 874 for (i = 0; i<64; i++) {
806 SET_ATA_NSECTOR ( 0xa5); 875 SET_REG(ATA_NSECTOR, WRITE_PATTERN1);
807 SET_ATA_SECTOR ( 0x5a); 876 SET_REG(ATA_SECTOR, WRITE_PATTERN2);
808 SET_ATA_LCYL ( 0xaa); 877 SET_REG(ATA_LCYL, WRITE_PATTERN3);
809 SET_ATA_HCYL ( 0x55); 878 SET_REG(ATA_HCYL, WRITE_PATTERN4);
810 879
811 if ((ATA_NSECTOR == 0xa5) && 880 if ((ATA_NSECTOR == READ_PATTERN1) &&
812 (ATA_SECTOR == 0x5a) && 881 (ATA_SECTOR == READ_PATTERN2) &&
813 (ATA_LCYL == 0xaa) && 882 (ATA_LCYL == READ_PATTERN3) &&
814 (ATA_HCYL == 0x55)) 883 (ATA_HCYL == READ_PATTERN4))
815 return 0; 884 return 0;
816 } 885 }
817 886
@@ -823,12 +892,12 @@ static int freeze_lock(void)
823 /* does the disk support Security Mode feature set? */ 892 /* does the disk support Security Mode feature set? */
824 if (identify_info[82] & 2) 893 if (identify_info[82] & 2)
825 { 894 {
826 SET_ATA_SELECT (ata_device); 895 SET_REG(ATA_SELECT, ata_device);
827 896
828 if (!wait_for_rdy()) 897 if (!wait_for_rdy())
829 return -1; 898 return -1;
830 899
831 SET_ATA_COMMAND(CMD_SECURITY_FREEZE_LOCK); 900 SET_REG(ATA_COMMAND, CMD_SECURITY_FREEZE_LOCK);
832 901
833 if (!wait_for_rdy()) 902 if (!wait_for_rdy())
834 return -2; 903 return -2;
@@ -863,7 +932,7 @@ static int ata_perform_sleep(void)
863 932
864 mutex_lock(&ata_mtx); 933 mutex_lock(&ata_mtx);
865 934
866 SET_ATA_SELECT(ata_device); 935 SET_REG(ATA_SELECT, ata_device);
867 936
868 if(!wait_for_rdy()) { 937 if(!wait_for_rdy()) {
869 DEBUGF("ata_perform_sleep() - not RDY\n"); 938 DEBUGF("ata_perform_sleep() - not RDY\n");
@@ -871,7 +940,7 @@ static int ata_perform_sleep(void)
871 return -1; 940 return -1;
872 } 941 }
873 942
874 SET_ATA_COMMAND(CMD_SLEEP); 943 SET_REG(ATA_COMMAND, CMD_SLEEP);
875 944
876 if (!wait_for_rdy()) 945 if (!wait_for_rdy())
877 { 946 {
@@ -890,7 +959,7 @@ int ata_standby(int time)
890 959
891 mutex_lock(&ata_mtx); 960 mutex_lock(&ata_mtx);
892 961
893 SET_ATA_SELECT(ata_device); 962 SET_REG(ATA_SELECT, ata_device);
894 963
895 if(!wait_for_rdy()) { 964 if(!wait_for_rdy()) {
896 DEBUGF("ata_standby() - not RDY\n"); 965 DEBUGF("ata_standby() - not RDY\n");
@@ -899,11 +968,12 @@ int ata_standby(int time)
899 } 968 }
900 969
901 if(time) 970 if(time)
902 SET_ATA_NSECTOR ( ((time + 5) / 5) & 0xff); /* Round up to nearest 5 secs */ 971 /* Round up to nearest 5 secs */
972 SET_REG(ATA_NSECTOR, ((time + 5) / 5) & 0xff);
903 else 973 else
904 SET_ATA_NSECTOR ( 0); /* Disable standby */ 974 SET_REG(ATA_NSECTOR, 0); /* Disable standby */
905 975
906 SET_ATA_COMMAND(CMD_STANDBY); 976 SET_REG(ATA_COMMAND, CMD_STANDBY);
907 977
908 if (!wait_for_rdy()) 978 if (!wait_for_rdy())
909 { 979 {
@@ -996,11 +1066,16 @@ int ata_hard_reset(void)
996 /* state HRR1 */ 1066 /* state HRR1 */
997 or_b(0x02, &PADRH); /* negate _RESET */ 1067 or_b(0x02, &PADRH); /* negate _RESET */
998 sleep(1); /* > 2ms */ 1068 sleep(1); /* > 2ms */
999#elif defined HAVE_SCF5249 1069#elif defined HAVE_MCF5249
1070 GPIO_OUT &= ~0x00080000;
1071 sleep(1); /* > 25us */
1072
1073 GPIO_OUT |= 0x00080000;
1074 sleep(1); /* > 25us */
1000#endif 1075#endif
1001 1076
1002 /* state HRR2 */ 1077 /* state HRR2 */
1003 SET_ATA_SELECT(ata_device); /* select the right device */ 1078 SET_REG(ATA_SELECT, ata_device); /* select the right device */
1004 ret = wait_for_bsy(); 1079 ret = wait_for_bsy();
1005 1080
1006 /* Massage the return code so it is 0 on success and -1 on failure */ 1081 /* Massage the return code so it is 0 on success and -1 on failure */
@@ -1014,11 +1089,11 @@ static int perform_soft_reset(void)
1014 int ret; 1089 int ret;
1015 int retry_count; 1090 int retry_count;
1016 1091
1017 SET_ATA_SELECT ( SELECT_LBA | ata_device ); 1092 SET_REG(ATA_SELECT, SELECT_LBA | ata_device );
1018 SET_ATA_CONTROL ( CONTROL_nIEN|CONTROL_SRST ); 1093 SET_REG(ATA_CONTROL, CONTROL_nIEN|CONTROL_SRST );
1019 sleep(1); /* >= 5us */ 1094 sleep(1); /* >= 5us */
1020 1095
1021 SET_ATA_CONTROL (CONTROL_nIEN); 1096 SET_REG(ATA_CONTROL, CONTROL_nIEN);
1022 sleep(1); /* >2ms */ 1097 sleep(1); /* >2ms */
1023 1098
1024 /* This little sucker can take up to 30 seconds */ 1099 /* This little sucker can take up to 30 seconds */
@@ -1070,14 +1145,14 @@ static int ata_power_on(void)
1070static int master_slave_detect(void) 1145static int master_slave_detect(void)
1071{ 1146{
1072 /* master? */ 1147 /* master? */
1073 SET_ATA_SELECT( 0 ); 1148 SET_REG(ATA_SELECT, 0);
1074 if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) { 1149 if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) {
1075 ata_device = 0; 1150 ata_device = 0;
1076 DEBUGF("Found master harddisk\n"); 1151 DEBUGF("Found master harddisk\n");
1077 } 1152 }
1078 else { 1153 else {
1079 /* slave? */ 1154 /* slave? */
1080 SET_ATA_SELECT( SELECT_DEVICE1 ); 1155 SET_REG(ATA_SELECT, SELECT_DEVICE1);
1081 if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) { 1156 if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) {
1082 ata_device = SELECT_DEVICE1; 1157 ata_device = SELECT_DEVICE1;
1083 DEBUGF("Found slave harddisk\n"); 1158 DEBUGF("Found slave harddisk\n");
@@ -1115,7 +1190,8 @@ void ata_enable(bool on)
1115 or_b(0x80, &PADRL); /* disable ATA */ 1190 or_b(0x80, &PADRL); /* disable ATA */
1116 1191
1117 or_b(0x80, &PAIORL); 1192 or_b(0x80, &PAIORL);
1118#elif defined HAVE_SCF5249 1193#elif CONFIG_CPU == MCF5249
1194 (void)on; /* FIXME */
1119#endif 1195#endif
1120} 1196}
1121 1197
@@ -1123,15 +1199,14 @@ static int identify(void)
1123{ 1199{
1124 int i; 1200 int i;
1125 1201
1126 SET_ATA_SELECT ( ata_device ); 1202 SET_REG(ATA_SELECT, ata_device);
1127 1203
1128 if(!wait_for_rdy()) { 1204 if(!wait_for_rdy()) {
1129 DEBUGF("identify() - not RDY\n"); 1205 DEBUGF("identify() - not RDY\n");
1130 return -1; 1206 return -1;
1131 } 1207 }
1132 1208
1133 1209 SET_REG(ATA_COMMAND, CMD_IDENTIFY);
1134 SET_ATA_COMMAND ( CMD_IDENTIFY );
1135 1210
1136 if (!wait_for_start_of_transfer()) 1211 if (!wait_for_start_of_transfer())
1137 { 1212 {
@@ -1139,25 +1214,30 @@ static int identify(void)
1139 return -2; 1214 return -2;
1140 } 1215 }
1141 1216
1142 1217 for (i=0; i<SECTOR_SIZE/2; i++) {
1143 for (i=0; i<SECTOR_SIZE/2; i++) 1218 /* the IDENTIFY words are already swapped, so we need to treat
1144 /* the IDENTIFY words are already swapped */ 1219 this info differently that normal sector data */
1220#ifdef SWAP_WORDS
1145 identify_info[i] = ATA_DATA; 1221 identify_info[i] = ATA_DATA;
1222#else
1223 identify_info[i] = SWAB16(ATA_DATA);
1224#endif
1225 }
1146 1226
1147 return 0; 1227 return 0;
1148} 1228}
1149 1229
1150static int set_multiple_mode(int sectors) 1230static int set_multiple_mode(int sectors)
1151{ 1231{
1152 SET_ATA_SELECT ( ata_device ); 1232 SET_REG(ATA_SELECT, ata_device);
1153 1233
1154 if(!wait_for_rdy()) { 1234 if(!wait_for_rdy()) {
1155 DEBUGF("set_multiple_mode() - not RDY\n"); 1235 DEBUGF("set_multiple_mode() - not RDY\n");
1156 return -1; 1236 return -1;
1157 } 1237 }
1158 1238
1159 SET_ATA_NSECTOR ( sectors ); 1239 SET_REG(ATA_NSECTOR, sectors);
1160 SET_ATA_COMMAND ( CMD_SET_MULTIPLE_MODE ); 1240 SET_REG(ATA_COMMAND, CMD_SET_MULTIPLE_MODE);
1161 1241
1162 if (!wait_for_rdy()) 1242 if (!wait_for_rdy())
1163 { 1243 {
@@ -1195,7 +1275,7 @@ static int set_features(void)
1195 /* Update the table */ 1275 /* Update the table */
1196 features[3].parameter = 8 + pio_mode; 1276 features[3].parameter = 8 + pio_mode;
1197 1277
1198 SET_ATA_SELECT( ata_device ); 1278 SET_REG(ATA_SELECT, ata_device);
1199 1279
1200 if (!wait_for_rdy()) { 1280 if (!wait_for_rdy()) {
1201 DEBUGF("set_features() - not RDY\n"); 1281 DEBUGF("set_features() - not RDY\n");
@@ -1204,9 +1284,9 @@ static int set_features(void)
1204 1284
1205 for (i=0; features[i].id_word; i++) { 1285 for (i=0; features[i].id_word; i++) {
1206 if (identify_info[features[i].id_word] & (1 << features[i].id_bit)) { 1286 if (identify_info[features[i].id_word] & (1 << features[i].id_bit)) {
1207 SET_ATA_FEATURE ( features[i].subcommand ); 1287 SET_REG(ATA_FEATURE, features[i].subcommand);
1208 SET_ATA_NSECTOR ( features[i].parameter ); 1288 SET_REG(ATA_NSECTOR, features[i].parameter);
1209 SET_ATA_COMMAND ( CMD_SET_FEATURES ); 1289 SET_REG(ATA_COMMAND, CMD_SET_FEATURES);
1210 1290
1211 if (!wait_for_rdy()) { 1291 if (!wait_for_rdy()) {
1212 DEBUGF("set_features() - CMD failed\n"); 1292 DEBUGF("set_features() - CMD failed\n");
@@ -1262,6 +1342,8 @@ int ata_init(void)
1262#if CONFIG_CPU == TCC730 1342#if CONFIG_CPU == TCC730
1263 /* TODO: check for cold start (never happenning now) */ 1343 /* TODO: check for cold start (never happenning now) */
1264 bool coldstart = false; 1344 bool coldstart = false;
1345#elif CONFIG_CPU == MCF5249
1346 bool coldstart = true; /* FIXME */
1265#else 1347#else
1266 bool coldstart = (PACR2 & 0x4000) != 0; 1348 bool coldstart = (PACR2 & 0x4000) != 0;
1267#endif 1349#endif
@@ -1275,7 +1357,10 @@ int ata_init(void)
1275 or_b(0x02, &PAIORH); /* output for ATA reset */ 1357 or_b(0x02, &PAIORH); /* output for ATA reset */
1276 or_b(0x02, &PADRH); /* release ATA reset */ 1358 or_b(0x02, &PADRH); /* release ATA reset */
1277 PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */ 1359 PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */
1278#elif defined HAVE_SCF5249 1360#elif defined HAVE_MCF5249
1361 GPIO_OUT |= 0x00080000;
1362 GPIO_ENABLE |= 0x00080000;
1363 GPIO_FUNCTION |= 0x00080000;
1279#endif 1364#endif
1280 1365
1281 sleeping = false; 1366 sleeping = false;