3 * Denis Peter, MPL AG, d.peter@mpl.ch.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 #define PRINTF(fmt,args...) printf (fmt ,##args)
39 #define PRINTF(fmt,args...)
49 /*#if defined(CONFIG_CMD_DATE) */
54 int flags
; /* connected drives ect */
55 unsigned long blnr
; /* Logical block nr */
56 uchar drive
; /* drive no */
57 uchar cmdlen
; /* cmd length */
58 uchar cmd
[16]; /* cmd desc */
59 uchar dma
; /* if > 0 dma enabled */
60 uchar result
[11]; /* status information */
61 uchar resultlen
; /* lenght of result */
64 /* flags: only the lower 8bit used:
65 * bit 0 if set drive 0 is present
66 * bit 1 if set drive 1 is present
67 * bit 2 if set drive 2 is present
68 * bit 3 if set drive 3 is present
69 * bit 4 if set disk in drive 0 is inserted
70 * bit 5 if set disk in drive 1 is inserted
71 * bit 6 if set disk in drive 2 is inserted
72 * bit 7 if set disk in drive 4 is inserted
95 #define STATUS_TRACK 3
98 #define STATUS_SECT_SIZE 6
101 /* Register addresses */
102 #define FDC_BASE 0x3F0
103 #define FDC_SRA FDC_BASE + 0 /* Status Register A */
104 #define FDC_SRB FDC_BASE + 1 /* Status Register B */
105 #define FDC_DOR FDC_BASE + 2 /* Digital Output Register */
106 #define FDC_TDR FDC_BASE + 3 /* Tape Drive Register */
107 #define FDC_DSR FDC_BASE + 4 /* Data rate Register */
108 #define FDC_MSR FDC_BASE + 4 /* Main Status Register */
109 #define FDC_FIFO FDC_BASE + 5 /* FIFO */
110 #define FDC_DIR FDC_BASE + 6 /* Digital Input Register */
111 #define FDC_CCR FDC_BASE + 7 /* Configuration Control */
113 #define FDC_CMD_SENSE_INT 0x08
114 #define FDC_CMD_CONFIGURE 0x13
115 #define FDC_CMD_SPECIFY 0x03
116 #define FDC_CMD_RECALIBRATE 0x07
117 #define FDC_CMD_READ 0x06
118 #define FDC_CMD_READ_TRACK 0x02
119 #define FDC_CMD_READ_ID 0x0A
120 #define FDC_CMD_DUMP_REG 0x0E
121 #define FDC_CMD_SEEK 0x0F
123 #define FDC_CMD_SENSE_INT_LEN 0x01
124 #define FDC_CMD_CONFIGURE_LEN 0x04
125 #define FDC_CMD_SPECIFY_LEN 0x03
126 #define FDC_CMD_RECALIBRATE_LEN 0x02
127 #define FDC_CMD_READ_LEN 0x09
128 #define FDC_CMD_READ_TRACK_LEN 0x09
129 #define FDC_CMD_READ_ID_LEN 0x02
130 #define FDC_CMD_DUMP_REG_LEN 0x01
131 #define FDC_CMD_SEEK_LEN 0x03
133 #define FDC_FIFO_THR 0x0C
134 #define FDC_FIFO_DIS 0x00
135 #define FDC_IMPLIED_SEEK 0x01
136 #define FDC_POLL_DIS 0x00
137 #define FDC_PRE_TRK 0x00
138 #define FDC_CONFIGURE FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
139 #define FDC_MFM_MODE 0x01 /* MFM enable */
140 #define FDC_SKIP_MODE 0x00 /* skip enable */
142 #define FDC_TIME_OUT 100000 /* time out */
143 #define FDC_RW_RETRIES 3 /* read write retries */
144 #define FDC_CAL_RETRIES 3 /* calibration and seek retries */
149 unsigned int size
; /* nr of sectors total */
150 unsigned int sect
; /* sectors per track */
151 unsigned int head
; /* nr of heads */
152 unsigned int track
; /* nr of tracks */
153 unsigned int stretch
; /* !=0 means double track steps */
154 unsigned char gap
; /* gap1 size */
155 unsigned char rate
; /* data rate. |= 0x40 for perpendicular */
156 unsigned char spec1
; /* stepping rate, head unload time */
157 unsigned char fmt_gap
;/* gap2 size */
158 unsigned char hlt
; /* head load time */
159 unsigned char sect_code
;/* Sector Size code */
160 const char * name
; /* used only for predefined formats */
164 /* supported Floppy types (currently only one) */
165 const static FD_GEO_STRUCT floppy_type
[2] = {
166 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" }, /* 7 1.44MB 3.5" */
167 { 0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL
}, /* end of table */
170 static FDC_COMMAND_STRUCT cmd
; /* global command struct */
172 /* If the boot drive number is undefined, we assume it's drive 0 */
173 #ifndef CONFIG_SYS_FDC_DRIVE_NUMBER
174 #define CONFIG_SYS_FDC_DRIVE_NUMBER 0
177 /* Hardware access */
178 #ifndef CONFIG_SYS_ISA_IO_STRIDE
179 #define CONFIG_SYS_ISA_IO_STRIDE 1
182 #ifndef CONFIG_SYS_ISA_IO_OFFSET
183 #define CONFIG_SYS_ISA_IO_OFFSET 0
187 #ifdef CONFIG_AMIGAONEG3SE
188 unsigned char INT6_Status
;
190 void fdc_interrupt(void)
195 /* waits for an interrupt (polling) */
196 int wait_for_fdc_int(void)
198 unsigned long timeout
;
199 timeout
= FDC_TIME_OUT
;
200 while(((volatile)INT6_Status
& 0x80) == 0) {
203 if(timeout
== 0) /* timeout occured */
211 /* Supporting Functions */
212 /* reads a Register of the FDC */
213 unsigned char read_fdc_reg(unsigned int addr
)
215 volatile unsigned char *val
=
216 (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS
+
217 (addr
* CONFIG_SYS_ISA_IO_STRIDE
) +
218 CONFIG_SYS_ISA_IO_OFFSET
);
223 /* writes a Register of the FDC */
224 void write_fdc_reg(unsigned int addr
, unsigned char val
)
226 volatile unsigned char *tmp
=
227 (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS
+
228 (addr
* CONFIG_SYS_ISA_IO_STRIDE
) +
229 CONFIG_SYS_ISA_IO_OFFSET
);
233 #ifndef CONFIG_AMIGAONEG3SE
234 /* waits for an interrupt (polling) */
235 int wait_for_fdc_int(void)
237 unsigned long timeout
;
238 timeout
= FDC_TIME_OUT
;
239 while((read_fdc_reg(FDC_SRA
)&0x80)==0) {
242 if(timeout
==0) /* timeout occured */
250 /* reads a byte from the FIFO of the FDC and checks direction and RQM bit
251 of the MSR. returns -1 if timeout, or byte if ok */
252 int read_fdc_byte(void)
254 unsigned long timeout
;
255 timeout
= FDC_TIME_OUT
;
256 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0xC0) {
257 /* direction out and ready */
260 if(timeout
==0) /* timeout occured */
263 return read_fdc_reg(FDC_FIFO
);
266 /* if the direction of the FIFO is wrong, this routine is used to
267 empty the FIFO. Should _not_ be used */
268 int fdc_need_more_output(void)
271 while((read_fdc_reg(FDC_MSR
)&0xC0)==0xC0) {
272 c
=(unsigned char)read_fdc_byte();
273 printf("Error: more output: %x\n",c
);
279 /* writes a byte to the FIFO of the FDC and checks direction and RQM bit
281 int write_fdc_byte(unsigned char val
)
283 unsigned long timeout
;
284 timeout
= FDC_TIME_OUT
;
285 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0x80) {
286 /* direction in and ready for byte */
289 fdc_need_more_output();
290 if(timeout
==0) /* timeout occured */
293 write_fdc_reg(FDC_FIFO
,val
);
297 /* sets up all FDC commands and issues it to the FDC. If
298 the command causes direct results (no Execution Phase)
299 the result is be read as well. */
301 int fdc_issue_cmd(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
304 unsigned long head
,track
,sect
,timeout
;
305 track
= pCMD
->blnr
/ (pFG
->sect
* pFG
->head
); /* track nr */
306 sect
= pCMD
->blnr
% (pFG
->sect
* pFG
->head
); /* remaining blocks */
307 head
= sect
/ pFG
->sect
; /* head nr */
308 sect
= sect
% pFG
->sect
; /* remaining blocks */
309 sect
++; /* sectors are 1 based */
310 PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
311 pCMD
->cmd
[0],track
,head
,sect
,pCMD
->drive
,pCMD
->blnr
);
313 if(head
|=0) { /* max heads = 2 */
314 pCMD
->cmd
[DRIVE
]=pCMD
->drive
| 0x04; /* head 1 */
315 pCMD
->cmd
[HEAD
]=(unsigned char) head
; /* head register */
318 pCMD
->cmd
[DRIVE
]=pCMD
->drive
; /* head 0 */
319 pCMD
->cmd
[HEAD
]=(unsigned char) head
; /* head register */
321 pCMD
->cmd
[TRACK
]=(unsigned char) track
; /* track */
322 switch (pCMD
->cmd
[COMMAND
]) {
324 pCMD
->cmd
[SECTOR
]=(unsigned char) sect
; /* sector */
325 pCMD
->cmd
[SECTOR_SIZE
]=pFG
->sect_code
; /* sector size code */
326 pCMD
->cmd
[LAST_TRACK
]=pFG
->sect
; /* End of track */
327 pCMD
->cmd
[GAP
]=pFG
->gap
; /* gap */
328 pCMD
->cmd
[DTL
]=0xFF; /* DTL */
329 pCMD
->cmdlen
=FDC_CMD_READ_LEN
;
330 pCMD
->cmd
[COMMAND
]|=(FDC_MFM_MODE
<<6); /* set MFM bit */
331 pCMD
->cmd
[COMMAND
]|=(FDC_SKIP_MODE
<<5); /* set Skip bit */
332 pCMD
->resultlen
=0; /* result only after execution */
335 pCMD
->cmdlen
=FDC_CMD_SEEK_LEN
;
336 pCMD
->resultlen
=0; /* no result */
338 case FDC_CMD_CONFIGURE
:
339 pCMD
->cmd
[CONFIG0
]=0;
340 pCMD
->cmd
[CONFIG1
]=FDC_CONFIGURE
; /* FIFO Threshold, Poll, Enable FIFO */
341 pCMD
->cmd
[CONFIG2
]=FDC_PRE_TRK
; /* Precompensation Track */
342 pCMD
->cmdlen
=FDC_CMD_CONFIGURE_LEN
;
343 pCMD
->resultlen
=0; /* no result */
345 case FDC_CMD_SPECIFY
:
346 pCMD
->cmd
[SPEC_HUTSRT
]=pFG
->spec1
;
347 pCMD
->cmd
[SPEC_HLT
]=(pFG
->hlt
)<<1; /* head load time */
349 pCMD
->cmd
[SPEC_HLT
]|=0x1; /* no dma */
350 pCMD
->cmdlen
=FDC_CMD_SPECIFY_LEN
;
351 pCMD
->resultlen
=0; /* no result */
353 case FDC_CMD_DUMP_REG
:
354 pCMD
->cmdlen
=FDC_CMD_DUMP_REG_LEN
;
355 pCMD
->resultlen
=10; /* 10 byte result */
357 case FDC_CMD_READ_ID
:
358 pCMD
->cmd
[COMMAND
]|=(FDC_MFM_MODE
<<6); /* set MFM bit */
359 pCMD
->cmdlen
=FDC_CMD_READ_ID_LEN
;
360 pCMD
->resultlen
=7; /* 7 byte result */
362 case FDC_CMD_RECALIBRATE
:
363 pCMD
->cmd
[DRIVE
]&=0x03; /* don't set the head bit */
364 pCMD
->cmdlen
=FDC_CMD_RECALIBRATE_LEN
;
365 pCMD
->resultlen
=0; /* no result */
368 case FDC_CMD_SENSE_INT
:
369 pCMD
->cmdlen
=FDC_CMD_SENSE_INT_LEN
;
373 for(i
=0;i
<pCMD
->cmdlen
;i
++) {
374 /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
375 if(write_fdc_byte(pCMD
->cmd
[i
])==FALSE
) {
376 PRINTF("Error: timeout while issue cmd%d\n",i
);
380 timeout
=FDC_TIME_OUT
;
381 for(i
=0;i
<pCMD
->resultlen
;i
++) {
382 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0xC0) {
385 PRINTF(" timeout while reading result%d MSR=0x%02X\n",i
,read_fdc_reg(FDC_MSR
));
389 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
394 /* selects the drive assigned in the cmd structur and
395 switches on the Motor */
396 void select_fdc_drive(FDC_COMMAND_STRUCT
*pCMD
)
400 val
=(1<<(4+pCMD
->drive
))|pCMD
->drive
|0xC; /* set reset, dma gate and motor bits */
401 if((read_fdc_reg(FDC_DOR
)&val
)!=val
) {
402 write_fdc_reg(FDC_DOR
,val
);
403 for(val
=0;val
<255;val
++)
404 udelay(500); /* wait some time to start motor */
408 /* switches off the Motor of the specified drive */
409 void stop_fdc_drive(FDC_COMMAND_STRUCT
*pCMD
)
413 val
=(1<<(4+pCMD
->drive
))|pCMD
->drive
; /* sets motor bits */
414 write_fdc_reg(FDC_DOR
,(read_fdc_reg(FDC_DOR
)&~val
));
417 /* issues a recalibrate command, waits for interrupt and
418 * issues a sense_interrupt */
419 int fdc_recalibrate(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
421 pCMD
->cmd
[COMMAND
]=FDC_CMD_RECALIBRATE
;
422 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
424 while(wait_for_fdc_int()!=TRUE
);
425 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
426 return(fdc_issue_cmd(pCMD
,pFG
));
429 /* issues a recalibrate command, waits for interrupt and
430 * issues a sense_interrupt */
431 int fdc_seek(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
433 pCMD
->cmd
[COMMAND
]=FDC_CMD_SEEK
;
434 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
436 while(wait_for_fdc_int()!=TRUE
);
437 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
438 return(fdc_issue_cmd(pCMD
,pFG
));
441 #ifndef CONFIG_AMIGAONEG3SE
442 /* terminates current command, by not servicing the FIFO
443 * waits for interrupt and fills in the result bytes */
444 int fdc_terminate(FDC_COMMAND_STRUCT
*pCMD
)
448 udelay(500); /* wait 500usec for fifo overrun */
449 while((read_fdc_reg(FDC_SRA
)&0x80)==0x00); /* wait as long as no int has occured */
451 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
456 #ifdef CONFIG_AMIGAONEG3SE
457 int fdc_terminate(FDC_COMMAND_STRUCT
*pCMD
)
461 udelay(500); /* wait 500usec for fifo overrun */
462 while((INT6_Status
&0x80)==0x00); /* wait as long as no int has occured */
464 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
472 #ifdef CONFIG_AMIGAONEG3SE
473 #define disable_interrupts() 0
474 #define enable_interrupts() (void)0
477 /* reads data from FDC, seek commands are issued automatic */
478 int fdc_read_data(unsigned char *buffer
, unsigned long blocks
,FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
480 /* first seek to start address */
481 unsigned long len
,lastblk
,readblk
,i
,timeout
,ii
,offset
;
482 unsigned char pcn
,c
,retriesrw
,retriescal
;
483 unsigned char *bufferw
; /* working buffer */
487 flags
=disable_interrupts(); /* switch off all Interrupts */
488 select_fdc_drive(pCMD
); /* switch on drive */
489 sect_size
=0x080<<pFG
->sect_code
;
493 if(fdc_seek(pCMD
,pFG
)==FALSE
) {
494 stop_fdc_drive(pCMD
);
498 if((pCMD
->result
[STATUS_0
]&0x20)!=0x20) {
499 printf("Seek error Status: %02X\n",pCMD
->result
[STATUS_0
]);
500 stop_fdc_drive(pCMD
);
504 pcn
=pCMD
->result
[STATUS_PCN
]; /* current track */
505 /* now determine the next seek point */
506 lastblk
=pCMD
->blnr
+ blocks
;
507 /* readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
508 readblk
=pFG
->sect
-(pCMD
->blnr
%pFG
->sect
);
509 PRINTF("1st nr of block possible read %ld start %ld\n",readblk
,pCMD
->blnr
);
510 if(readblk
>blocks
) /* is end within 1st track */
511 readblk
=blocks
; /* yes, correct it */
512 PRINTF("we read %ld blocks start %ld\n",readblk
,pCMD
->blnr
);
513 bufferw
= &buffer
[0]; /* setup working buffer */
516 len
=sect_size
* readblk
;
517 pCMD
->cmd
[COMMAND
]=FDC_CMD_READ
;
518 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
519 stop_fdc_drive(pCMD
);
523 for (i
=0;i
<len
;i
++) {
524 timeout
=FDC_TIME_OUT
;
526 c
=read_fdc_reg(FDC_MSR
);
528 bufferw
[i
]=read_fdc_reg(FDC_FIFO
);
531 if((c
&0xC0)==0x80) { /* output */
532 PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i
,c
);
534 for(ii
=0;ii
<7;ii
++) {
535 pCMD
->result
[ii
]=bufferw
[(i
-7+ii
)];
538 if(retriesrw
++>FDC_RW_RETRIES
) {
539 if (retriescal
++>FDC_CAL_RETRIES
) {
540 stop_fdc_drive(pCMD
);
545 PRINTF(" trying to recalibrate Try %d\n",retriescal
);
546 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
) {
547 stop_fdc_drive(pCMD
);
553 } /* else >FDC_CAL_RETRIES */
556 PRINTF("Read retry %d\n",retriesrw
);
558 } /* else >FDC_RW_RETRIES */
563 /* the last sector of a track or all data has been read,
564 * we need to get the results */
566 offset
+=(sect_size
*readblk
); /* set up buffer pointer */
567 bufferw
= &buffer
[offset
];
568 pCMD
->blnr
+=readblk
; /* update current block nr */
569 blocks
-=readblk
; /* update blocks */
571 break; /* we are finish */
572 /* setup new read blocks */
573 /* readblk=pFG->head*pFG->sect; */
578 /* a seek is necessary */
579 if(fdc_seek(pCMD
,pFG
)==FALSE
) {
580 stop_fdc_drive(pCMD
);
584 if((pCMD
->result
[STATUS_0
]&0x20)!=0x20) {
585 PRINTF("Seek error Status: %02X\n",pCMD
->result
[STATUS_0
]);
586 stop_fdc_drive(pCMD
);
589 pcn
=pCMD
->result
[STATUS_PCN
]; /* current track */
590 }while(TRUE
); /* start over */
591 stop_fdc_drive(pCMD
); /* switch off drive */
596 #ifdef CONFIG_AMIGAONEG3SE
597 #undef disable_interrupts()
598 #undef enable_interrupts()
601 /* Scan all drives and check if drive is present and disk is inserted */
602 int fdc_check_drive(FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
605 /* OK procedure of data book is satisfied.
606 * trying to get some information over the drives */
607 state
=0; /* no drives, no disks */
608 for(drives
=0;drives
<4;drives
++) {
610 select_fdc_drive(pCMD
);
611 pCMD
->blnr
=0; /* set to the 1st block */
612 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
)
614 if((pCMD
->result
[STATUS_0
]&0x10)==0x10)
616 /* ok drive connected check for disk */
618 pCMD
->blnr
=pFG
->size
; /* set to the last block */
619 if(fdc_seek(pCMD
,pFG
)==FALSE
)
621 pCMD
->blnr
=0; /* set to the 1st block */
622 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
)
624 pCMD
->cmd
[COMMAND
]=FDC_CMD_READ_ID
;
625 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
627 state
|=(0x10<<drives
);
629 stop_fdc_drive(pCMD
);
631 PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i
,
632 ((state
&(1<<i
))==(1<<i
)) ? "":"not ",
633 ((state
&(0x10<<i
))==(0x10<<i
)) ? "":"no ",
634 ((state
&(0x10<<i
))==(0x10<<i
)) ? pFG
->name
: "");
641 /**************************************************************************
643 * setup the fdc according the datasheet
644 * assuming in PS2 Mode
646 int fdc_setup(int drive
, FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
650 #ifdef CONFIG_AMIGAONEG3SE
651 irq_install_handler(6, (interrupt_handler_t
*)fdc_interrupt
, NULL
);
655 #ifdef CONFIG_SYS_FDC_HW_INIT
658 /* first, we reset the FDC via the DOR */
659 write_fdc_reg(FDC_DOR
,0x00);
660 for(i
=0; i
<255; i
++) /* then we wait some time */
662 /* then, we clear the reset in the DOR */
664 select_fdc_drive(pCMD
);
665 /* initialize the CCR */
666 write_fdc_reg(FDC_CCR
,pFG
->rate
);
667 /* then initialize the DSR */
668 write_fdc_reg(FDC_DSR
,pFG
->rate
);
669 if(wait_for_fdc_int()==FALSE
) {
670 PRINTF("Time Out after writing CCR\n");
673 /* now issue sense Interrupt and status command
674 * assuming only one drive present (drive 0) */
675 pCMD
->dma
=0; /* we don't use any dma at all */
677 /* issue sense interrupt for all 4 possible drives */
678 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
679 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
680 PRINTF("Sense Interrupt for drive %d failed\n",i
);
683 /* issue the configure command */
685 select_fdc_drive(pCMD
);
686 pCMD
->cmd
[COMMAND
]=FDC_CMD_CONFIGURE
;
687 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
688 PRINTF(" configure timeout\n");
689 stop_fdc_drive(pCMD
);
692 /* issue specify command */
693 pCMD
->cmd
[COMMAND
]=FDC_CMD_SPECIFY
;
694 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
695 PRINTF(" specify timeout\n");
696 stop_fdc_drive(pCMD
);
700 /* then, we clear the reset in the DOR */
701 /* fdc_check_drive(pCMD,pFG); */
702 /* write_fdc_reg(FDC_DOR,0x04); */
707 #if defined(CONFIG_CMD_FDOS)
709 /* Low level functions for the Floppy-DOS layer */
711 /**************************************************************************
713 * initialize the FDC layer
716 int fdc_fdos_init (int drive
)
718 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
719 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
721 /* setup FDC and scan for drives */
722 if(fdc_setup(drive
,pCMD
,pFG
)==FALSE
) {
723 printf("\n** Error in setup FDC **\n");
726 if(fdc_check_drive(pCMD
,pFG
)==FALSE
) {
727 printf("\n** Error in check_drives **\n");
730 if((pCMD
->flags
&(1<<drive
))==0) {
731 /* drive not available */
732 printf("\n** Drive %d not available **\n",drive
);
735 if((pCMD
->flags
&(0x10<<drive
))==0) {
736 /* no disk inserted */
737 printf("\n** No disk inserted in drive %d **\n",drive
);
740 /* ok, we have a valid source */
743 /* read first block */
747 /**************************************************************************
749 * parameter is a block number
751 int fdc_fdos_seek (int where
)
753 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
754 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
756 pCMD
-> blnr
= where
;
757 return (fdc_seek (pCMD
, pFG
));
759 /**************************************************************************
761 * the length is in block number
763 int fdc_fdos_read (void *buffer
, int len
)
765 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
766 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
768 return (fdc_read_data (buffer
, len
, pCMD
, pFG
));
772 #if defined(CONFIG_CMD_FDC)
773 /****************************************************************************
774 * main routine do_fdcboot
776 int do_fdcboot (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
778 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
779 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
780 unsigned long addr
,imsize
;
781 image_header_t
*hdr
; /* used for fdc boot */
782 unsigned char boot_drive
;
786 #if defined(CONFIG_FIT)
787 const void *fit_hdr
= NULL
;
792 addr
= CONFIG_SYS_LOAD_ADDR
;
793 boot_drive
=CONFIG_SYS_FDC_DRIVE_NUMBER
;
796 addr
= simple_strtoul(argv
[1], NULL
, 16);
797 boot_drive
=CONFIG_SYS_FDC_DRIVE_NUMBER
;
800 addr
= simple_strtoul(argv
[1], NULL
, 16);
801 boot_drive
=simple_strtoul(argv
[2], NULL
, 10);
807 /* setup FDC and scan for drives */
808 if(fdc_setup(boot_drive
,pCMD
,pFG
)==FALSE
) {
809 printf("\n** Error in setup FDC **\n");
812 if(fdc_check_drive(pCMD
,pFG
)==FALSE
) {
813 printf("\n** Error in check_drives **\n");
816 if((pCMD
->flags
&(1<<boot_drive
))==0) {
817 /* drive not available */
818 printf("\n** Drive %d not availabe **\n",boot_drive
);
821 if((pCMD
->flags
&(0x10<<boot_drive
))==0) {
822 /* no disk inserted */
823 printf("\n** No disk inserted in drive %d **\n",boot_drive
);
826 /* ok, we have a valid source */
827 pCMD
->drive
=boot_drive
;
828 /* read first block */
830 if(fdc_read_data((unsigned char *)addr
,1,pCMD
,pFG
)==FALSE
) {
831 printf("\nRead error:");
833 printf("result%d: 0x%02X\n",i
,pCMD
->result
[i
]);
837 switch (genimg_get_format ((void *)addr
)) {
838 case IMAGE_FORMAT_LEGACY
:
839 hdr
= (image_header_t
*)addr
;
840 image_print_contents (hdr
);
842 imsize
= image_get_image_size (hdr
);
844 #if defined(CONFIG_FIT)
845 case IMAGE_FORMAT_FIT
:
846 fit_hdr
= (const void *)addr
;
847 puts ("Fit image detected...\n");
849 imsize
= fit_get_size (fit_hdr
);
853 puts ("** Unknown image type\n");
860 printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize
,nrofblk
,addr
);
862 if(fdc_read_data((unsigned char *)addr
,nrofblk
,pCMD
,pFG
)==FALSE
) {
863 /* read image block */
864 printf("\nRead error:");
866 printf("result%d: 0x%02X\n",i
,pCMD
->result
[i
]);
869 printf("OK %ld Bytes loaded.\n",imsize
);
871 flush_cache (addr
, imsize
);
873 #if defined(CONFIG_FIT)
874 /* This cannot be done earlier, we need complete FIT image in RAM first */
875 if (genimg_get_format ((void *)addr
) == IMAGE_FORMAT_FIT
) {
876 if (!fit_check_format (fit_hdr
)) {
877 puts ("** Bad FIT image format\n");
880 fit_print_contents (fit_hdr
);
884 /* Loading ok, update default load address */
887 /* Check if we should attempt an auto-start */
888 if (((ep
= getenv("autostart")) != NULL
) && (strcmp(ep
,"yes") == 0)) {
890 extern int do_bootm (cmd_tbl_t
*, int, int, char *[]);
892 local_args
[0] = argv
[0];
893 local_args
[1] = NULL
;
895 printf ("Automatic boot of image at addr 0x%08lX ...\n", addr
);
897 do_bootm (cmdtp
, 0, 1, local_args
);
904 fdcboot
, 3, 1, do_fdcboot
,
905 "boot from floppy device",