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...)
50 /*#if defined(CONFIG_CMD_DATE) */
54 #if defined(CONFIG_CMD_FDC) || defined(CONFIG_CMD_FDOS)
58 int flags
; /* connected drives ect */
59 unsigned long blnr
; /* Logical block nr */
60 uchar drive
; /* drive no */
61 uchar cmdlen
; /* cmd length */
62 uchar cmd
[16]; /* cmd desc */
63 uchar dma
; /* if > 0 dma enabled */
64 uchar result
[11];/* status information */
65 uchar resultlen
; /* lenght of result */
67 /* flags: only the lower 8bit used:
68 * bit 0 if set drive 0 is present
69 * bit 1 if set drive 1 is present
70 * bit 2 if set drive 2 is present
71 * bit 3 if set drive 3 is present
72 * bit 4 if set disk in drive 0 is inserted
73 * bit 5 if set disk in drive 1 is inserted
74 * bit 6 if set disk in drive 2 is inserted
75 * bit 7 if set disk in drive 4 is inserted
99 #define STATUS_TRACK 3
100 #define STATUS_HEAD 4
101 #define STATUS_SECT 5
102 #define STATUS_SECT_SIZE 6
105 /* Register addresses */
106 #define FDC_BASE 0x3F0
107 #define FDC_SRA FDC_BASE + 0 /* Status Register A */
108 #define FDC_SRB FDC_BASE + 1 /* Status Register B */
109 #define FDC_DOR FDC_BASE + 2 /* Digital Output Register */
110 #define FDC_TDR FDC_BASE + 3 /* Tape Drive Register */
111 #define FDC_DSR FDC_BASE + 4 /* Data rate Register */
112 #define FDC_MSR FDC_BASE + 4 /* Main Status Register */
113 #define FDC_FIFO FDC_BASE + 5 /* FIFO */
114 #define FDC_DIR FDC_BASE + 6 /* Digital Input Register */
115 #define FDC_CCR FDC_BASE + 7 /* Configuration Control */
117 #define FDC_CMD_SENSE_INT 0x08
118 #define FDC_CMD_CONFIGURE 0x13
119 #define FDC_CMD_SPECIFY 0x03
120 #define FDC_CMD_RECALIBRATE 0x07
121 #define FDC_CMD_READ 0x06
122 #define FDC_CMD_READ_TRACK 0x02
123 #define FDC_CMD_READ_ID 0x0A
124 #define FDC_CMD_DUMP_REG 0x0E
125 #define FDC_CMD_SEEK 0x0F
127 #define FDC_CMD_SENSE_INT_LEN 0x01
128 #define FDC_CMD_CONFIGURE_LEN 0x04
129 #define FDC_CMD_SPECIFY_LEN 0x03
130 #define FDC_CMD_RECALIBRATE_LEN 0x02
131 #define FDC_CMD_READ_LEN 0x09
132 #define FDC_CMD_READ_TRACK_LEN 0x09
133 #define FDC_CMD_READ_ID_LEN 0x02
134 #define FDC_CMD_DUMP_REG_LEN 0x01
135 #define FDC_CMD_SEEK_LEN 0x03
137 #define FDC_FIFO_THR 0x0C
138 #define FDC_FIFO_DIS 0x00
139 #define FDC_IMPLIED_SEEK 0x01
140 #define FDC_POLL_DIS 0x00
141 #define FDC_PRE_TRK 0x00
142 #define FDC_CONFIGURE FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
143 #define FDC_MFM_MODE 0x01 /* MFM enable */
144 #define FDC_SKIP_MODE 0x00 /* skip enable */
146 #define FDC_TIME_OUT 100000 /* time out */
147 #define FDC_RW_RETRIES 3 /* read write retries */
148 #define FDC_CAL_RETRIES 3 /* calibration and seek retries */
153 unsigned int size
; /* nr of sectors total */
154 unsigned int sect
; /* sectors per track */
155 unsigned int head
; /* nr of heads */
156 unsigned int track
; /* nr of tracks */
157 unsigned int stretch
; /* !=0 means double track steps */
158 unsigned char gap
; /* gap1 size */
159 unsigned char rate
; /* data rate. |= 0x40 for perpendicular */
160 unsigned char spec1
; /* stepping rate, head unload time */
161 unsigned char fmt_gap
; /* gap2 size */
162 unsigned char hlt
; /* head load time */
163 unsigned char sect_code
; /* Sector Size code */
164 const char * name
; /* used only for predefined formats */
168 /* supported Floppy types (currently only one) */
169 const static FD_GEO_STRUCT floppy_type
[2] = {
170 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" }, /* 7 1.44MB 3.5" */
171 { 0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL
}, /* end of table */
174 static FDC_COMMAND_STRUCT cmd
; /* global command struct */
176 /* If the boot drive number is undefined, we assume it's drive 0 */
177 #ifndef CFG_FDC_DRIVE_NUMBER
178 #define CFG_FDC_DRIVE_NUMBER 0
181 /* Hardware access */
182 #ifndef CFG_ISA_IO_STRIDE
183 #define CFG_ISA_IO_STRIDE 1
186 #ifndef CFG_ISA_IO_OFFSET
187 #define CFG_ISA_IO_OFFSET 0
191 #ifdef CONFIG_AMIGAONEG3SE
192 unsigned char INT6_Status
;
194 void fdc_interrupt(void)
199 /* waits for an interrupt (polling) */
200 int wait_for_fdc_int(void)
202 unsigned long timeout
;
203 timeout
= FDC_TIME_OUT
;
204 while(((volatile)INT6_Status
& 0x80) == 0) {
207 if(timeout
== 0) /* timeout occured */
215 /* Supporting Functions */
216 /* reads a Register of the FDC */
217 unsigned char read_fdc_reg(unsigned int addr
)
219 volatile unsigned char *val
=
220 (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS
+
221 (addr
* CFG_ISA_IO_STRIDE
) +
227 /* writes a Register of the FDC */
228 void write_fdc_reg(unsigned int addr
, unsigned char val
)
230 volatile unsigned char *tmp
=
231 (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS
+
232 (addr
* CFG_ISA_IO_STRIDE
) +
237 #ifndef CONFIG_AMIGAONEG3SE
238 /* waits for an interrupt (polling) */
239 int wait_for_fdc_int(void)
241 unsigned long timeout
;
242 timeout
= FDC_TIME_OUT
;
243 while((read_fdc_reg(FDC_SRA
)&0x80)==0) {
246 if(timeout
==0) /* timeout occured */
254 /* reads a byte from the FIFO of the FDC and checks direction and RQM bit
255 of the MSR. returns -1 if timeout, or byte if ok */
256 int read_fdc_byte(void)
258 unsigned long timeout
;
259 timeout
= FDC_TIME_OUT
;
260 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0xC0) {
261 /* direction out and ready */
264 if(timeout
==0) /* timeout occured */
267 return read_fdc_reg(FDC_FIFO
);
270 /* if the direction of the FIFO is wrong, this routine is used to
271 empty the FIFO. Should _not_ be used */
272 int fdc_need_more_output(void)
275 while((read_fdc_reg(FDC_MSR
)&0xC0)==0xC0) {
276 c
=(unsigned char)read_fdc_byte();
277 printf("Error: more output: %x\n",c
);
283 /* writes a byte to the FIFO of the FDC and checks direction and RQM bit
285 int write_fdc_byte(unsigned char val
)
287 unsigned long timeout
;
288 timeout
= FDC_TIME_OUT
;
289 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0x80) {
290 /* direction in and ready for byte */
293 fdc_need_more_output();
294 if(timeout
==0) /* timeout occured */
297 write_fdc_reg(FDC_FIFO
,val
);
301 /* sets up all FDC commands and issues it to the FDC. If
302 the command causes direct results (no Execution Phase)
303 the result is be read as well. */
305 int fdc_issue_cmd(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
308 unsigned long head
,track
,sect
,timeout
;
309 track
= pCMD
->blnr
/ (pFG
->sect
* pFG
->head
); /* track nr */
310 sect
= pCMD
->blnr
% (pFG
->sect
* pFG
->head
); /* remaining blocks */
311 head
= sect
/ pFG
->sect
; /* head nr */
312 sect
= sect
% pFG
->sect
; /* remaining blocks */
313 sect
++; /* sectors are 1 based */
314 PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
315 pCMD
->cmd
[0],track
,head
,sect
,pCMD
->drive
,pCMD
->blnr
);
317 if(head
|=0) { /* max heads = 2 */
318 pCMD
->cmd
[DRIVE
]=pCMD
->drive
| 0x04; /* head 1 */
319 pCMD
->cmd
[HEAD
]=(unsigned char) head
; /* head register */
322 pCMD
->cmd
[DRIVE
]=pCMD
->drive
; /* head 0 */
323 pCMD
->cmd
[HEAD
]=(unsigned char) head
; /* head register */
325 pCMD
->cmd
[TRACK
]=(unsigned char) track
; /* track */
326 switch (pCMD
->cmd
[COMMAND
]) {
328 pCMD
->cmd
[SECTOR
]=(unsigned char) sect
; /* sector */
329 pCMD
->cmd
[SECTOR_SIZE
]=pFG
->sect_code
; /* sector size code */
330 pCMD
->cmd
[LAST_TRACK
]=pFG
->sect
; /* End of track */
331 pCMD
->cmd
[GAP
]=pFG
->gap
; /* gap */
332 pCMD
->cmd
[DTL
]=0xFF; /* DTL */
333 pCMD
->cmdlen
=FDC_CMD_READ_LEN
;
334 pCMD
->cmd
[COMMAND
]|=(FDC_MFM_MODE
<<6); /* set MFM bit */
335 pCMD
->cmd
[COMMAND
]|=(FDC_SKIP_MODE
<<5); /* set Skip bit */
336 pCMD
->resultlen
=0; /* result only after execution */
339 pCMD
->cmdlen
=FDC_CMD_SEEK_LEN
;
340 pCMD
->resultlen
=0; /* no result */
342 case FDC_CMD_CONFIGURE
:
343 pCMD
->cmd
[CONFIG0
]=0;
344 pCMD
->cmd
[CONFIG1
]=FDC_CONFIGURE
; /* FIFO Threshold, Poll, Enable FIFO */
345 pCMD
->cmd
[CONFIG2
]=FDC_PRE_TRK
; /* Precompensation Track */
346 pCMD
->cmdlen
=FDC_CMD_CONFIGURE_LEN
;
347 pCMD
->resultlen
=0; /* no result */
349 case FDC_CMD_SPECIFY
:
350 pCMD
->cmd
[SPEC_HUTSRT
]=pFG
->spec1
;
351 pCMD
->cmd
[SPEC_HLT
]=(pFG
->hlt
)<<1; /* head load time */
353 pCMD
->cmd
[SPEC_HLT
]|=0x1; /* no dma */
354 pCMD
->cmdlen
=FDC_CMD_SPECIFY_LEN
;
355 pCMD
->resultlen
=0; /* no result */
357 case FDC_CMD_DUMP_REG
:
358 pCMD
->cmdlen
=FDC_CMD_DUMP_REG_LEN
;
359 pCMD
->resultlen
=10; /* 10 byte result */
361 case FDC_CMD_READ_ID
:
362 pCMD
->cmd
[COMMAND
]|=(FDC_MFM_MODE
<<6); /* set MFM bit */
363 pCMD
->cmdlen
=FDC_CMD_READ_ID_LEN
;
364 pCMD
->resultlen
=7; /* 7 byte result */
366 case FDC_CMD_RECALIBRATE
:
367 pCMD
->cmd
[DRIVE
]&=0x03; /* don't set the head bit */
368 pCMD
->cmdlen
=FDC_CMD_RECALIBRATE_LEN
;
369 pCMD
->resultlen
=0; /* no result */
372 case FDC_CMD_SENSE_INT
:
373 pCMD
->cmdlen
=FDC_CMD_SENSE_INT_LEN
;
377 for(i
=0;i
<pCMD
->cmdlen
;i
++) {
378 /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
379 if(write_fdc_byte(pCMD
->cmd
[i
])==FALSE
) {
380 PRINTF("Error: timeout while issue cmd%d\n",i
);
384 timeout
=FDC_TIME_OUT
;
385 for(i
=0;i
<pCMD
->resultlen
;i
++) {
386 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0xC0) {
389 PRINTF(" timeout while reading result%d MSR=0x%02X\n",i
,read_fdc_reg(FDC_MSR
));
393 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
398 /* selects the drive assigned in the cmd structur and
399 switches on the Motor */
400 void select_fdc_drive(FDC_COMMAND_STRUCT
*pCMD
)
404 val
=(1<<(4+pCMD
->drive
))|pCMD
->drive
|0xC; /* set reset, dma gate and motor bits */
405 if((read_fdc_reg(FDC_DOR
)&val
)!=val
) {
406 write_fdc_reg(FDC_DOR
,val
);
407 for(val
=0;val
<255;val
++)
408 udelay(500); /* wait some time to start motor */
412 /* switches off the Motor of the specified drive */
413 void stop_fdc_drive(FDC_COMMAND_STRUCT
*pCMD
)
417 val
=(1<<(4+pCMD
->drive
))|pCMD
->drive
; /* sets motor bits */
418 write_fdc_reg(FDC_DOR
,(read_fdc_reg(FDC_DOR
)&~val
));
421 /* issues a recalibrate command, waits for interrupt and
422 * issues a sense_interrupt */
423 int fdc_recalibrate(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
425 pCMD
->cmd
[COMMAND
]=FDC_CMD_RECALIBRATE
;
426 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
428 while(wait_for_fdc_int()!=TRUE
);
429 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
430 return(fdc_issue_cmd(pCMD
,pFG
));
433 /* issues a recalibrate command, waits for interrupt and
434 * issues a sense_interrupt */
435 int fdc_seek(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
437 pCMD
->cmd
[COMMAND
]=FDC_CMD_SEEK
;
438 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
440 while(wait_for_fdc_int()!=TRUE
);
441 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
442 return(fdc_issue_cmd(pCMD
,pFG
));
445 #ifndef CONFIG_AMIGAONEG3SE
446 /* terminates current command, by not servicing the FIFO
447 * waits for interrupt and fills in the result bytes */
448 int fdc_terminate(FDC_COMMAND_STRUCT
*pCMD
)
452 udelay(500); /* wait 500usec for fifo overrun */
453 while((read_fdc_reg(FDC_SRA
)&0x80)==0x00); /* wait as long as no int has occured */
455 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
460 #ifdef CONFIG_AMIGAONEG3SE
461 int fdc_terminate(FDC_COMMAND_STRUCT
*pCMD
)
465 udelay(500); /* wait 500usec for fifo overrun */
466 while((INT6_Status
&0x80)==0x00); /* wait as long as no int has occured */
468 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
476 #ifdef CONFIG_AMIGAONEG3SE
477 #define disable_interrupts() 0
478 #define enable_interrupts() (void)0
481 /* reads data from FDC, seek commands are issued automatic */
482 int fdc_read_data(unsigned char *buffer
, unsigned long blocks
,FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
484 /* first seek to start address */
485 unsigned long len
,lastblk
,readblk
,i
,timeout
,ii
,offset
;
486 unsigned char pcn
,c
,retriesrw
,retriescal
;
487 unsigned char *bufferw
; /* working buffer */
491 flags
=disable_interrupts(); /* switch off all Interrupts */
492 select_fdc_drive(pCMD
); /* switch on drive */
493 sect_size
=0x080<<pFG
->sect_code
;
497 if(fdc_seek(pCMD
,pFG
)==FALSE
) {
498 stop_fdc_drive(pCMD
);
502 if((pCMD
->result
[STATUS_0
]&0x20)!=0x20) {
503 printf("Seek error Status: %02X\n",pCMD
->result
[STATUS_0
]);
504 stop_fdc_drive(pCMD
);
508 pcn
=pCMD
->result
[STATUS_PCN
]; /* current track */
509 /* now determine the next seek point */
510 lastblk
=pCMD
->blnr
+ blocks
;
511 /* readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
512 readblk
=pFG
->sect
-(pCMD
->blnr
%pFG
->sect
);
513 PRINTF("1st nr of block possible read %ld start %ld\n",readblk
,pCMD
->blnr
);
514 if(readblk
>blocks
) /* is end within 1st track */
515 readblk
=blocks
; /* yes, correct it */
516 PRINTF("we read %ld blocks start %ld\n",readblk
,pCMD
->blnr
);
517 bufferw
=&buffer
[0]; /* setup working buffer */
520 len
=sect_size
* readblk
;
521 pCMD
->cmd
[COMMAND
]=FDC_CMD_READ
;
522 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
523 stop_fdc_drive(pCMD
);
527 for (i
=0;i
<len
;i
++) {
528 timeout
=FDC_TIME_OUT
;
530 c
=read_fdc_reg(FDC_MSR
);
532 bufferw
[i
]=read_fdc_reg(FDC_FIFO
);
535 if((c
&0xC0)==0x80) { /* output */
536 PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i
,c
);
538 for(ii
=0;ii
<7;ii
++) {
539 pCMD
->result
[ii
]=bufferw
[(i
-7+ii
)];
542 if(retriesrw
++>FDC_RW_RETRIES
) {
543 if (retriescal
++>FDC_CAL_RETRIES
) {
544 stop_fdc_drive(pCMD
);
549 PRINTF(" trying to recalibrate Try %d\n",retriescal
);
550 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
) {
551 stop_fdc_drive(pCMD
);
557 } /* else >FDC_CAL_RETRIES */
560 PRINTF("Read retry %d\n",retriesrw
);
562 } /* else >FDC_RW_RETRIES */
567 /* the last sector of a track or all data has been read,
568 * we need to get the results */
570 offset
+=(sect_size
*readblk
); /* set up buffer pointer */
571 bufferw
=&buffer
[offset
];
572 pCMD
->blnr
+=readblk
; /* update current block nr */
573 blocks
-=readblk
; /* update blocks */
575 break; /* we are finish */
576 /* setup new read blocks */
577 /* readblk=pFG->head*pFG->sect; */
582 /* a seek is necessary */
583 if(fdc_seek(pCMD
,pFG
)==FALSE
) {
584 stop_fdc_drive(pCMD
);
588 if((pCMD
->result
[STATUS_0
]&0x20)!=0x20) {
589 PRINTF("Seek error Status: %02X\n",pCMD
->result
[STATUS_0
]);
590 stop_fdc_drive(pCMD
);
593 pcn
=pCMD
->result
[STATUS_PCN
]; /* current track */
594 }while(TRUE
); /* start over */
595 stop_fdc_drive(pCMD
); /* switch off drive */
600 #ifdef CONFIG_AMIGAONEG3SE
601 #undef disable_interrupts()
602 #undef enable_interrupts()
605 /* Scan all drives and check if drive is present and disk is inserted */
606 int fdc_check_drive(FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
609 /* OK procedure of data book is satisfied.
610 * trying to get some information over the drives */
611 state
=0; /* no drives, no disks */
612 for(drives
=0;drives
<4;drives
++) {
614 select_fdc_drive(pCMD
);
615 pCMD
->blnr
=0; /* set to the 1st block */
616 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
)
618 if((pCMD
->result
[STATUS_0
]&0x10)==0x10)
620 /* ok drive connected check for disk */
622 pCMD
->blnr
=pFG
->size
; /* set to the last block */
623 if(fdc_seek(pCMD
,pFG
)==FALSE
)
625 pCMD
->blnr
=0; /* set to the 1st block */
626 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
)
628 pCMD
->cmd
[COMMAND
]=FDC_CMD_READ_ID
;
629 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
631 state
|=(0x10<<drives
);
633 stop_fdc_drive(pCMD
);
635 PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i
,
636 ((state
&(1<<i
))==(1<<i
)) ? "":"not ",
637 ((state
&(0x10<<i
))==(0x10<<i
)) ? "":"no ",
638 ((state
&(0x10<<i
))==(0x10<<i
)) ? pFG
->name
: "");
645 /**************************************************************************
647 * setup the fdc according the datasheet
648 * assuming in PS2 Mode
650 int fdc_setup(int drive
, FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
654 #ifdef CONFIG_AMIGAONEG3SE
655 irq_install_handler(6, (interrupt_handler_t
*)fdc_interrupt
, NULL
);
659 #ifdef CFG_FDC_HW_INIT
662 /* first, we reset the FDC via the DOR */
663 write_fdc_reg(FDC_DOR
,0x00);
664 for(i
=0; i
<255; i
++) /* then we wait some time */
666 /* then, we clear the reset in the DOR */
668 select_fdc_drive(pCMD
);
669 /* initialize the CCR */
670 write_fdc_reg(FDC_CCR
,pFG
->rate
);
671 /* then initialize the DSR */
672 write_fdc_reg(FDC_DSR
,pFG
->rate
);
673 if(wait_for_fdc_int()==FALSE
) {
674 PRINTF("Time Out after writing CCR\n");
677 /* now issue sense Interrupt and status command
678 * assuming only one drive present (drive 0) */
679 pCMD
->dma
=0; /* we don't use any dma at all */
681 /* issue sense interrupt for all 4 possible drives */
682 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
683 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
684 PRINTF("Sense Interrupt for drive %d failed\n",i
);
687 /* issue the configure command */
689 select_fdc_drive(pCMD
);
690 pCMD
->cmd
[COMMAND
]=FDC_CMD_CONFIGURE
;
691 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
692 PRINTF(" configure timeout\n");
693 stop_fdc_drive(pCMD
);
696 /* issue specify command */
697 pCMD
->cmd
[COMMAND
]=FDC_CMD_SPECIFY
;
698 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
699 PRINTF(" specify timeout\n");
700 stop_fdc_drive(pCMD
);
704 /* then, we clear the reset in the DOR */
705 /* fdc_check_drive(pCMD,pFG); */
706 /* write_fdc_reg(FDC_DOR,0x04); */
712 #if defined(CONFIG_CMD_FDOS)
714 /* Low level functions for the Floppy-DOS layer */
716 /**************************************************************************
718 * initialize the FDC layer
721 int fdc_fdos_init (int drive
)
723 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
724 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
726 /* setup FDC and scan for drives */
727 if(fdc_setup(drive
,pCMD
,pFG
)==FALSE
) {
728 printf("\n** Error in setup FDC **\n");
731 if(fdc_check_drive(pCMD
,pFG
)==FALSE
) {
732 printf("\n** Error in check_drives **\n");
735 if((pCMD
->flags
&(1<<drive
))==0) {
736 /* drive not available */
737 printf("\n** Drive %d not available **\n",drive
);
740 if((pCMD
->flags
&(0x10<<drive
))==0) {
741 /* no disk inserted */
742 printf("\n** No disk inserted in drive %d **\n",drive
);
745 /* ok, we have a valid source */
748 /* read first block */
752 /**************************************************************************
754 * parameter is a block number
756 int fdc_fdos_seek (int where
)
758 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
759 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
761 pCMD
-> blnr
= where
;
762 return (fdc_seek (pCMD
, pFG
));
764 /**************************************************************************
766 * the length is in block number
768 int fdc_fdos_read (void *buffer
, int len
)
770 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
771 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
773 return (fdc_read_data (buffer
, len
, pCMD
, pFG
));
777 #if defined(CONFIG_CMD_FDC)
778 /****************************************************************************
779 * main routine do_fdcboot
781 int do_fdcboot (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
783 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
784 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
785 unsigned long addr
,imsize
;
786 image_header_t
*hdr
; /* used for fdc boot */
787 unsigned char boot_drive
;
791 #if defined(CONFIG_FIT)
797 addr
= CFG_LOAD_ADDR
;
798 boot_drive
=CFG_FDC_DRIVE_NUMBER
;
801 addr
= simple_strtoul(argv
[1], NULL
, 16);
802 boot_drive
=CFG_FDC_DRIVE_NUMBER
;
805 addr
= simple_strtoul(argv
[1], NULL
, 16);
806 boot_drive
=simple_strtoul(argv
[2], NULL
, 10);
809 printf ("Usage:\n%s\n", cmdtp
->usage
);
812 /* setup FDC and scan for drives */
813 if(fdc_setup(boot_drive
,pCMD
,pFG
)==FALSE
) {
814 printf("\n** Error in setup FDC **\n");
817 if(fdc_check_drive(pCMD
,pFG
)==FALSE
) {
818 printf("\n** Error in check_drives **\n");
821 if((pCMD
->flags
&(1<<boot_drive
))==0) {
822 /* drive not available */
823 printf("\n** Drive %d not availabe **\n",boot_drive
);
826 if((pCMD
->flags
&(0x10<<boot_drive
))==0) {
827 /* no disk inserted */
828 printf("\n** No disk inserted in drive %d **\n",boot_drive
);
831 /* ok, we have a valid source */
832 pCMD
->drive
=boot_drive
;
833 /* read first block */
835 if(fdc_read_data((unsigned char *)addr
,1,pCMD
,pFG
)==FALSE
) {
836 printf("\nRead error:");
838 printf("result%d: 0x%02X\n",i
,pCMD
->result
[i
]);
842 switch (genimg_get_format ((void *)addr
)) {
843 case IMAGE_FORMAT_LEGACY
:
844 hdr
= (image_header_t
*)addr
;
845 image_print_contents (hdr
);
847 imsize
= image_get_image_size (hdr
);
849 #if defined(CONFIG_FIT)
850 case IMAGE_FORMAT_FIT
:
851 fit_hdr
= (const void *)addr
;
852 if (!fit_check_format (fit_hdr
)) {
853 puts ("** Bad FIT image format\n");
856 puts ("Fit image detected...\n");
858 imsize
= fit_get_size (fit_hdr
);
862 puts ("** Unknown image type\n");
869 printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize
,nrofblk
,addr
);
871 if(fdc_read_data((unsigned char *)addr
,nrofblk
,pCMD
,pFG
)==FALSE
) {
872 /* read image block */
873 printf("\nRead error:");
875 printf("result%d: 0x%02X\n",i
,pCMD
->result
[i
]);
878 printf("OK %ld Bytes loaded.\n",imsize
);
880 flush_cache (addr
, imsize
);
882 #if defined(CONFIG_FIT)
883 /* This cannot be done earlier, we need complete FIT image in RAM first */
884 if (genimg_get_format ((void *)addr
) == IMAGE_FORMAT_FIT
)
885 fit_print_contents ((const void *)addr
);
888 /* Loading ok, update default load address */
891 /* Check if we should attempt an auto-start */
892 if (((ep
= getenv("autostart")) != NULL
) && (strcmp(ep
,"yes") == 0)) {
894 extern int do_bootm (cmd_tbl_t
*, int, int, char *[]);
896 local_args
[0] = argv
[0];
897 local_args
[1] = NULL
;
899 printf ("Automatic boot of image at addr 0x%08lX ...\n", addr
);
901 do_bootm (cmdtp
, 0, 1, local_args
);
911 /***************************************************/
914 #if defined(CONFIG_CMD_FDC)
917 fdcboot
, 3, 1, do_fdcboot
,
918 "fdcboot - boot from floppy device\n",