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) */
53 #if defined(CONFIG_CMD_FDC) || defined(CONFIG_CMD_FDOS)
56 int flags
; /* connected drives ect */
57 unsigned long blnr
; /* Logical block nr */
58 uchar drive
; /* drive no */
59 uchar cmdlen
; /* cmd length */
60 uchar cmd
[16]; /* cmd desc */
61 uchar dma
; /* if > 0 dma enabled */
62 uchar result
[11]; /* status information */
63 uchar resultlen
; /* lenght of result */
66 /* flags: only the lower 8bit used:
67 * bit 0 if set drive 0 is present
68 * bit 1 if set drive 1 is present
69 * bit 2 if set drive 2 is present
70 * bit 3 if set drive 3 is present
71 * bit 4 if set disk in drive 0 is inserted
72 * bit 5 if set disk in drive 1 is inserted
73 * bit 6 if set disk in drive 2 is inserted
74 * bit 7 if set disk in drive 4 is inserted
97 #define STATUS_TRACK 3
100 #define STATUS_SECT_SIZE 6
103 /* Register addresses */
104 #define FDC_BASE 0x3F0
105 #define FDC_SRA FDC_BASE + 0 /* Status Register A */
106 #define FDC_SRB FDC_BASE + 1 /* Status Register B */
107 #define FDC_DOR FDC_BASE + 2 /* Digital Output Register */
108 #define FDC_TDR FDC_BASE + 3 /* Tape Drive Register */
109 #define FDC_DSR FDC_BASE + 4 /* Data rate Register */
110 #define FDC_MSR FDC_BASE + 4 /* Main Status Register */
111 #define FDC_FIFO FDC_BASE + 5 /* FIFO */
112 #define FDC_DIR FDC_BASE + 6 /* Digital Input Register */
113 #define FDC_CCR FDC_BASE + 7 /* Configuration Control */
115 #define FDC_CMD_SENSE_INT 0x08
116 #define FDC_CMD_CONFIGURE 0x13
117 #define FDC_CMD_SPECIFY 0x03
118 #define FDC_CMD_RECALIBRATE 0x07
119 #define FDC_CMD_READ 0x06
120 #define FDC_CMD_READ_TRACK 0x02
121 #define FDC_CMD_READ_ID 0x0A
122 #define FDC_CMD_DUMP_REG 0x0E
123 #define FDC_CMD_SEEK 0x0F
125 #define FDC_CMD_SENSE_INT_LEN 0x01
126 #define FDC_CMD_CONFIGURE_LEN 0x04
127 #define FDC_CMD_SPECIFY_LEN 0x03
128 #define FDC_CMD_RECALIBRATE_LEN 0x02
129 #define FDC_CMD_READ_LEN 0x09
130 #define FDC_CMD_READ_TRACK_LEN 0x09
131 #define FDC_CMD_READ_ID_LEN 0x02
132 #define FDC_CMD_DUMP_REG_LEN 0x01
133 #define FDC_CMD_SEEK_LEN 0x03
135 #define FDC_FIFO_THR 0x0C
136 #define FDC_FIFO_DIS 0x00
137 #define FDC_IMPLIED_SEEK 0x01
138 #define FDC_POLL_DIS 0x00
139 #define FDC_PRE_TRK 0x00
140 #define FDC_CONFIGURE FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
141 #define FDC_MFM_MODE 0x01 /* MFM enable */
142 #define FDC_SKIP_MODE 0x00 /* skip enable */
144 #define FDC_TIME_OUT 100000 /* time out */
145 #define FDC_RW_RETRIES 3 /* read write retries */
146 #define FDC_CAL_RETRIES 3 /* calibration and seek retries */
151 unsigned int size
; /* nr of sectors total */
152 unsigned int sect
; /* sectors per track */
153 unsigned int head
; /* nr of heads */
154 unsigned int track
; /* nr of tracks */
155 unsigned int stretch
; /* !=0 means double track steps */
156 unsigned char gap
; /* gap1 size */
157 unsigned char rate
; /* data rate. |= 0x40 for perpendicular */
158 unsigned char spec1
; /* stepping rate, head unload time */
159 unsigned char fmt_gap
;/* gap2 size */
160 unsigned char hlt
; /* head load time */
161 unsigned char sect_code
;/* Sector Size code */
162 const char * name
; /* used only for predefined formats */
166 /* supported Floppy types (currently only one) */
167 const static FD_GEO_STRUCT floppy_type
[2] = {
168 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" }, /* 7 1.44MB 3.5" */
169 { 0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL
}, /* end of table */
172 static FDC_COMMAND_STRUCT cmd
; /* global command struct */
174 /* If the boot drive number is undefined, we assume it's drive 0 */
175 #ifndef CFG_FDC_DRIVE_NUMBER
176 #define CFG_FDC_DRIVE_NUMBER 0
179 /* Hardware access */
180 #ifndef CFG_ISA_IO_STRIDE
181 #define CFG_ISA_IO_STRIDE 1
184 #ifndef CFG_ISA_IO_OFFSET
185 #define CFG_ISA_IO_OFFSET 0
189 #ifdef CONFIG_AMIGAONEG3SE
190 unsigned char INT6_Status
;
192 void fdc_interrupt(void)
197 /* waits for an interrupt (polling) */
198 int wait_for_fdc_int(void)
200 unsigned long timeout
;
201 timeout
= FDC_TIME_OUT
;
202 while(((volatile)INT6_Status
& 0x80) == 0) {
205 if(timeout
== 0) /* timeout occured */
213 /* Supporting Functions */
214 /* reads a Register of the FDC */
215 unsigned char read_fdc_reg(unsigned int addr
)
217 volatile unsigned char *val
=
218 (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS
+
219 (addr
* CFG_ISA_IO_STRIDE
) +
225 /* writes a Register of the FDC */
226 void write_fdc_reg(unsigned int addr
, unsigned char val
)
228 volatile unsigned char *tmp
=
229 (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS
+
230 (addr
* CFG_ISA_IO_STRIDE
) +
235 #ifndef CONFIG_AMIGAONEG3SE
236 /* waits for an interrupt (polling) */
237 int wait_for_fdc_int(void)
239 unsigned long timeout
;
240 timeout
= FDC_TIME_OUT
;
241 while((read_fdc_reg(FDC_SRA
)&0x80)==0) {
244 if(timeout
==0) /* timeout occured */
252 /* reads a byte from the FIFO of the FDC and checks direction and RQM bit
253 of the MSR. returns -1 if timeout, or byte if ok */
254 int read_fdc_byte(void)
256 unsigned long timeout
;
257 timeout
= FDC_TIME_OUT
;
258 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0xC0) {
259 /* direction out and ready */
262 if(timeout
==0) /* timeout occured */
265 return read_fdc_reg(FDC_FIFO
);
268 /* if the direction of the FIFO is wrong, this routine is used to
269 empty the FIFO. Should _not_ be used */
270 int fdc_need_more_output(void)
273 while((read_fdc_reg(FDC_MSR
)&0xC0)==0xC0) {
274 c
=(unsigned char)read_fdc_byte();
275 printf("Error: more output: %x\n",c
);
281 /* writes a byte to the FIFO of the FDC and checks direction and RQM bit
283 int write_fdc_byte(unsigned char val
)
285 unsigned long timeout
;
286 timeout
= FDC_TIME_OUT
;
287 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0x80) {
288 /* direction in and ready for byte */
291 fdc_need_more_output();
292 if(timeout
==0) /* timeout occured */
295 write_fdc_reg(FDC_FIFO
,val
);
299 /* sets up all FDC commands and issues it to the FDC. If
300 the command causes direct results (no Execution Phase)
301 the result is be read as well. */
303 int fdc_issue_cmd(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
306 unsigned long head
,track
,sect
,timeout
;
307 track
= pCMD
->blnr
/ (pFG
->sect
* pFG
->head
); /* track nr */
308 sect
= pCMD
->blnr
% (pFG
->sect
* pFG
->head
); /* remaining blocks */
309 head
= sect
/ pFG
->sect
; /* head nr */
310 sect
= sect
% pFG
->sect
; /* remaining blocks */
311 sect
++; /* sectors are 1 based */
312 PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
313 pCMD
->cmd
[0],track
,head
,sect
,pCMD
->drive
,pCMD
->blnr
);
315 if(head
|=0) { /* max heads = 2 */
316 pCMD
->cmd
[DRIVE
]=pCMD
->drive
| 0x04; /* head 1 */
317 pCMD
->cmd
[HEAD
]=(unsigned char) head
; /* head register */
320 pCMD
->cmd
[DRIVE
]=pCMD
->drive
; /* head 0 */
321 pCMD
->cmd
[HEAD
]=(unsigned char) head
; /* head register */
323 pCMD
->cmd
[TRACK
]=(unsigned char) track
; /* track */
324 switch (pCMD
->cmd
[COMMAND
]) {
326 pCMD
->cmd
[SECTOR
]=(unsigned char) sect
; /* sector */
327 pCMD
->cmd
[SECTOR_SIZE
]=pFG
->sect_code
; /* sector size code */
328 pCMD
->cmd
[LAST_TRACK
]=pFG
->sect
; /* End of track */
329 pCMD
->cmd
[GAP
]=pFG
->gap
; /* gap */
330 pCMD
->cmd
[DTL
]=0xFF; /* DTL */
331 pCMD
->cmdlen
=FDC_CMD_READ_LEN
;
332 pCMD
->cmd
[COMMAND
]|=(FDC_MFM_MODE
<<6); /* set MFM bit */
333 pCMD
->cmd
[COMMAND
]|=(FDC_SKIP_MODE
<<5); /* set Skip bit */
334 pCMD
->resultlen
=0; /* result only after execution */
337 pCMD
->cmdlen
=FDC_CMD_SEEK_LEN
;
338 pCMD
->resultlen
=0; /* no result */
340 case FDC_CMD_CONFIGURE
:
341 pCMD
->cmd
[CONFIG0
]=0;
342 pCMD
->cmd
[CONFIG1
]=FDC_CONFIGURE
; /* FIFO Threshold, Poll, Enable FIFO */
343 pCMD
->cmd
[CONFIG2
]=FDC_PRE_TRK
; /* Precompensation Track */
344 pCMD
->cmdlen
=FDC_CMD_CONFIGURE_LEN
;
345 pCMD
->resultlen
=0; /* no result */
347 case FDC_CMD_SPECIFY
:
348 pCMD
->cmd
[SPEC_HUTSRT
]=pFG
->spec1
;
349 pCMD
->cmd
[SPEC_HLT
]=(pFG
->hlt
)<<1; /* head load time */
351 pCMD
->cmd
[SPEC_HLT
]|=0x1; /* no dma */
352 pCMD
->cmdlen
=FDC_CMD_SPECIFY_LEN
;
353 pCMD
->resultlen
=0; /* no result */
355 case FDC_CMD_DUMP_REG
:
356 pCMD
->cmdlen
=FDC_CMD_DUMP_REG_LEN
;
357 pCMD
->resultlen
=10; /* 10 byte result */
359 case FDC_CMD_READ_ID
:
360 pCMD
->cmd
[COMMAND
]|=(FDC_MFM_MODE
<<6); /* set MFM bit */
361 pCMD
->cmdlen
=FDC_CMD_READ_ID_LEN
;
362 pCMD
->resultlen
=7; /* 7 byte result */
364 case FDC_CMD_RECALIBRATE
:
365 pCMD
->cmd
[DRIVE
]&=0x03; /* don't set the head bit */
366 pCMD
->cmdlen
=FDC_CMD_RECALIBRATE_LEN
;
367 pCMD
->resultlen
=0; /* no result */
370 case FDC_CMD_SENSE_INT
:
371 pCMD
->cmdlen
=FDC_CMD_SENSE_INT_LEN
;
375 for(i
=0;i
<pCMD
->cmdlen
;i
++) {
376 /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
377 if(write_fdc_byte(pCMD
->cmd
[i
])==FALSE
) {
378 PRINTF("Error: timeout while issue cmd%d\n",i
);
382 timeout
=FDC_TIME_OUT
;
383 for(i
=0;i
<pCMD
->resultlen
;i
++) {
384 while((read_fdc_reg(FDC_MSR
)&0xC0)!=0xC0) {
387 PRINTF(" timeout while reading result%d MSR=0x%02X\n",i
,read_fdc_reg(FDC_MSR
));
391 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
396 /* selects the drive assigned in the cmd structur and
397 switches on the Motor */
398 void select_fdc_drive(FDC_COMMAND_STRUCT
*pCMD
)
402 val
=(1<<(4+pCMD
->drive
))|pCMD
->drive
|0xC; /* set reset, dma gate and motor bits */
403 if((read_fdc_reg(FDC_DOR
)&val
)!=val
) {
404 write_fdc_reg(FDC_DOR
,val
);
405 for(val
=0;val
<255;val
++)
406 udelay(500); /* wait some time to start motor */
410 /* switches off the Motor of the specified drive */
411 void stop_fdc_drive(FDC_COMMAND_STRUCT
*pCMD
)
415 val
=(1<<(4+pCMD
->drive
))|pCMD
->drive
; /* sets motor bits */
416 write_fdc_reg(FDC_DOR
,(read_fdc_reg(FDC_DOR
)&~val
));
419 /* issues a recalibrate command, waits for interrupt and
420 * issues a sense_interrupt */
421 int fdc_recalibrate(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
423 pCMD
->cmd
[COMMAND
]=FDC_CMD_RECALIBRATE
;
424 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
426 while(wait_for_fdc_int()!=TRUE
);
427 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
428 return(fdc_issue_cmd(pCMD
,pFG
));
431 /* issues a recalibrate command, waits for interrupt and
432 * issues a sense_interrupt */
433 int fdc_seek(FDC_COMMAND_STRUCT
*pCMD
,FD_GEO_STRUCT
*pFG
)
435 pCMD
->cmd
[COMMAND
]=FDC_CMD_SEEK
;
436 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
438 while(wait_for_fdc_int()!=TRUE
);
439 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
440 return(fdc_issue_cmd(pCMD
,pFG
));
443 #ifndef CONFIG_AMIGAONEG3SE
444 /* terminates current command, by not servicing the FIFO
445 * waits for interrupt and fills in the result bytes */
446 int fdc_terminate(FDC_COMMAND_STRUCT
*pCMD
)
450 udelay(500); /* wait 500usec for fifo overrun */
451 while((read_fdc_reg(FDC_SRA
)&0x80)==0x00); /* wait as long as no int has occured */
453 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
458 #ifdef CONFIG_AMIGAONEG3SE
459 int fdc_terminate(FDC_COMMAND_STRUCT
*pCMD
)
463 udelay(500); /* wait 500usec for fifo overrun */
464 while((INT6_Status
&0x80)==0x00); /* wait as long as no int has occured */
466 pCMD
->result
[i
]=(unsigned char)read_fdc_byte();
474 #ifdef CONFIG_AMIGAONEG3SE
475 #define disable_interrupts() 0
476 #define enable_interrupts() (void)0
479 /* reads data from FDC, seek commands are issued automatic */
480 int fdc_read_data(unsigned char *buffer
, unsigned long blocks
,FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
482 /* first seek to start address */
483 unsigned long len
,lastblk
,readblk
,i
,timeout
,ii
,offset
;
484 unsigned char pcn
,c
,retriesrw
,retriescal
;
485 unsigned char *bufferw
; /* working buffer */
489 flags
=disable_interrupts(); /* switch off all Interrupts */
490 select_fdc_drive(pCMD
); /* switch on drive */
491 sect_size
=0x080<<pFG
->sect_code
;
495 if(fdc_seek(pCMD
,pFG
)==FALSE
) {
496 stop_fdc_drive(pCMD
);
500 if((pCMD
->result
[STATUS_0
]&0x20)!=0x20) {
501 printf("Seek error Status: %02X\n",pCMD
->result
[STATUS_0
]);
502 stop_fdc_drive(pCMD
);
506 pcn
=pCMD
->result
[STATUS_PCN
]; /* current track */
507 /* now determine the next seek point */
508 lastblk
=pCMD
->blnr
+ blocks
;
509 /* readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
510 readblk
=pFG
->sect
-(pCMD
->blnr
%pFG
->sect
);
511 PRINTF("1st nr of block possible read %ld start %ld\n",readblk
,pCMD
->blnr
);
512 if(readblk
>blocks
) /* is end within 1st track */
513 readblk
=blocks
; /* yes, correct it */
514 PRINTF("we read %ld blocks start %ld\n",readblk
,pCMD
->blnr
);
515 bufferw
= &buffer
[0]; /* setup working buffer */
518 len
=sect_size
* readblk
;
519 pCMD
->cmd
[COMMAND
]=FDC_CMD_READ
;
520 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
521 stop_fdc_drive(pCMD
);
525 for (i
=0;i
<len
;i
++) {
526 timeout
=FDC_TIME_OUT
;
528 c
=read_fdc_reg(FDC_MSR
);
530 bufferw
[i
]=read_fdc_reg(FDC_FIFO
);
533 if((c
&0xC0)==0x80) { /* output */
534 PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i
,c
);
536 for(ii
=0;ii
<7;ii
++) {
537 pCMD
->result
[ii
]=bufferw
[(i
-7+ii
)];
540 if(retriesrw
++>FDC_RW_RETRIES
) {
541 if (retriescal
++>FDC_CAL_RETRIES
) {
542 stop_fdc_drive(pCMD
);
547 PRINTF(" trying to recalibrate Try %d\n",retriescal
);
548 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
) {
549 stop_fdc_drive(pCMD
);
555 } /* else >FDC_CAL_RETRIES */
558 PRINTF("Read retry %d\n",retriesrw
);
560 } /* else >FDC_RW_RETRIES */
565 /* the last sector of a track or all data has been read,
566 * we need to get the results */
568 offset
+=(sect_size
*readblk
); /* set up buffer pointer */
569 bufferw
= &buffer
[offset
];
570 pCMD
->blnr
+=readblk
; /* update current block nr */
571 blocks
-=readblk
; /* update blocks */
573 break; /* we are finish */
574 /* setup new read blocks */
575 /* readblk=pFG->head*pFG->sect; */
580 /* a seek is necessary */
581 if(fdc_seek(pCMD
,pFG
)==FALSE
) {
582 stop_fdc_drive(pCMD
);
586 if((pCMD
->result
[STATUS_0
]&0x20)!=0x20) {
587 PRINTF("Seek error Status: %02X\n",pCMD
->result
[STATUS_0
]);
588 stop_fdc_drive(pCMD
);
591 pcn
=pCMD
->result
[STATUS_PCN
]; /* current track */
592 }while(TRUE
); /* start over */
593 stop_fdc_drive(pCMD
); /* switch off drive */
598 #ifdef CONFIG_AMIGAONEG3SE
599 #undef disable_interrupts()
600 #undef enable_interrupts()
603 /* Scan all drives and check if drive is present and disk is inserted */
604 int fdc_check_drive(FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
607 /* OK procedure of data book is satisfied.
608 * trying to get some information over the drives */
609 state
=0; /* no drives, no disks */
610 for(drives
=0;drives
<4;drives
++) {
612 select_fdc_drive(pCMD
);
613 pCMD
->blnr
=0; /* set to the 1st block */
614 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
)
616 if((pCMD
->result
[STATUS_0
]&0x10)==0x10)
618 /* ok drive connected check for disk */
620 pCMD
->blnr
=pFG
->size
; /* set to the last block */
621 if(fdc_seek(pCMD
,pFG
)==FALSE
)
623 pCMD
->blnr
=0; /* set to the 1st block */
624 if(fdc_recalibrate(pCMD
,pFG
)==FALSE
)
626 pCMD
->cmd
[COMMAND
]=FDC_CMD_READ_ID
;
627 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
)
629 state
|=(0x10<<drives
);
631 stop_fdc_drive(pCMD
);
633 PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i
,
634 ((state
&(1<<i
))==(1<<i
)) ? "":"not ",
635 ((state
&(0x10<<i
))==(0x10<<i
)) ? "":"no ",
636 ((state
&(0x10<<i
))==(0x10<<i
)) ? pFG
->name
: "");
643 /**************************************************************************
645 * setup the fdc according the datasheet
646 * assuming in PS2 Mode
648 int fdc_setup(int drive
, FDC_COMMAND_STRUCT
*pCMD
, FD_GEO_STRUCT
*pFG
)
652 #ifdef CONFIG_AMIGAONEG3SE
653 irq_install_handler(6, (interrupt_handler_t
*)fdc_interrupt
, NULL
);
657 #ifdef CFG_FDC_HW_INIT
660 /* first, we reset the FDC via the DOR */
661 write_fdc_reg(FDC_DOR
,0x00);
662 for(i
=0; i
<255; i
++) /* then we wait some time */
664 /* then, we clear the reset in the DOR */
666 select_fdc_drive(pCMD
);
667 /* initialize the CCR */
668 write_fdc_reg(FDC_CCR
,pFG
->rate
);
669 /* then initialize the DSR */
670 write_fdc_reg(FDC_DSR
,pFG
->rate
);
671 if(wait_for_fdc_int()==FALSE
) {
672 PRINTF("Time Out after writing CCR\n");
675 /* now issue sense Interrupt and status command
676 * assuming only one drive present (drive 0) */
677 pCMD
->dma
=0; /* we don't use any dma at all */
679 /* issue sense interrupt for all 4 possible drives */
680 pCMD
->cmd
[COMMAND
]=FDC_CMD_SENSE_INT
;
681 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
682 PRINTF("Sense Interrupt for drive %d failed\n",i
);
685 /* issue the configure command */
687 select_fdc_drive(pCMD
);
688 pCMD
->cmd
[COMMAND
]=FDC_CMD_CONFIGURE
;
689 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
690 PRINTF(" configure timeout\n");
691 stop_fdc_drive(pCMD
);
694 /* issue specify command */
695 pCMD
->cmd
[COMMAND
]=FDC_CMD_SPECIFY
;
696 if(fdc_issue_cmd(pCMD
,pFG
)==FALSE
) {
697 PRINTF(" specify timeout\n");
698 stop_fdc_drive(pCMD
);
702 /* then, we clear the reset in the DOR */
703 /* fdc_check_drive(pCMD,pFG); */
704 /* write_fdc_reg(FDC_DOR,0x04); */
710 #if defined(CONFIG_CMD_FDOS)
712 /* Low level functions for the Floppy-DOS layer */
714 /**************************************************************************
716 * initialize the FDC layer
719 int fdc_fdos_init (int drive
)
721 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
722 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
724 /* setup FDC and scan for drives */
725 if(fdc_setup(drive
,pCMD
,pFG
)==FALSE
) {
726 printf("\n** Error in setup FDC **\n");
729 if(fdc_check_drive(pCMD
,pFG
)==FALSE
) {
730 printf("\n** Error in check_drives **\n");
733 if((pCMD
->flags
&(1<<drive
))==0) {
734 /* drive not available */
735 printf("\n** Drive %d not available **\n",drive
);
738 if((pCMD
->flags
&(0x10<<drive
))==0) {
739 /* no disk inserted */
740 printf("\n** No disk inserted in drive %d **\n",drive
);
743 /* ok, we have a valid source */
746 /* read first block */
750 /**************************************************************************
752 * parameter is a block number
754 int fdc_fdos_seek (int where
)
756 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
757 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
759 pCMD
-> blnr
= where
;
760 return (fdc_seek (pCMD
, pFG
));
762 /**************************************************************************
764 * the length is in block number
766 int fdc_fdos_read (void *buffer
, int len
)
768 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
769 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
771 return (fdc_read_data (buffer
, len
, pCMD
, pFG
));
775 #if defined(CONFIG_CMD_FDC)
776 /****************************************************************************
777 * main routine do_fdcboot
779 int do_fdcboot (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
781 FD_GEO_STRUCT
*pFG
= (FD_GEO_STRUCT
*)floppy_type
;
782 FDC_COMMAND_STRUCT
*pCMD
= &cmd
;
783 unsigned long addr
,imsize
;
784 image_header_t
*hdr
; /* used for fdc boot */
785 unsigned char boot_drive
;
789 #if defined(CONFIG_FIT)
790 const void *fit_hdr
= NULL
;
795 addr
= CFG_LOAD_ADDR
;
796 boot_drive
=CFG_FDC_DRIVE_NUMBER
;
799 addr
= simple_strtoul(argv
[1], NULL
, 16);
800 boot_drive
=CFG_FDC_DRIVE_NUMBER
;
803 addr
= simple_strtoul(argv
[1], NULL
, 16);
804 boot_drive
=simple_strtoul(argv
[2], NULL
, 10);
807 printf ("Usage:\n%s\n", cmdtp
->usage
);
810 /* setup FDC and scan for drives */
811 if(fdc_setup(boot_drive
,pCMD
,pFG
)==FALSE
) {
812 printf("\n** Error in setup FDC **\n");
815 if(fdc_check_drive(pCMD
,pFG
)==FALSE
) {
816 printf("\n** Error in check_drives **\n");
819 if((pCMD
->flags
&(1<<boot_drive
))==0) {
820 /* drive not available */
821 printf("\n** Drive %d not availabe **\n",boot_drive
);
824 if((pCMD
->flags
&(0x10<<boot_drive
))==0) {
825 /* no disk inserted */
826 printf("\n** No disk inserted in drive %d **\n",boot_drive
);
829 /* ok, we have a valid source */
830 pCMD
->drive
=boot_drive
;
831 /* read first block */
833 if(fdc_read_data((unsigned char *)addr
,1,pCMD
,pFG
)==FALSE
) {
834 printf("\nRead error:");
836 printf("result%d: 0x%02X\n",i
,pCMD
->result
[i
]);
840 switch (genimg_get_format ((void *)addr
)) {
841 case IMAGE_FORMAT_LEGACY
:
842 hdr
= (image_header_t
*)addr
;
843 image_print_contents (hdr
);
845 imsize
= image_get_image_size (hdr
);
847 #if defined(CONFIG_FIT)
848 case IMAGE_FORMAT_FIT
:
849 fit_hdr
= (const void *)addr
;
850 puts ("Fit image detected...\n");
852 imsize
= fit_get_size (fit_hdr
);
856 puts ("** Unknown image type\n");
863 printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize
,nrofblk
,addr
);
865 if(fdc_read_data((unsigned char *)addr
,nrofblk
,pCMD
,pFG
)==FALSE
) {
866 /* read image block */
867 printf("\nRead error:");
869 printf("result%d: 0x%02X\n",i
,pCMD
->result
[i
]);
872 printf("OK %ld Bytes loaded.\n",imsize
);
874 flush_cache (addr
, imsize
);
876 #if defined(CONFIG_FIT)
877 /* This cannot be done earlier, we need complete FIT image in RAM first */
878 if (genimg_get_format ((void *)addr
) == IMAGE_FORMAT_FIT
) {
879 if (!fit_check_format (fit_hdr
)) {
880 puts ("** Bad FIT image format\n");
883 fit_print_contents (fit_hdr
);
887 /* Loading ok, update default load address */
890 /* Check if we should attempt an auto-start */
891 if (((ep
= getenv("autostart")) != NULL
) && (strcmp(ep
,"yes") == 0)) {
893 extern int do_bootm (cmd_tbl_t
*, int, int, char *[]);
895 local_args
[0] = argv
[0];
896 local_args
[1] = NULL
;
898 printf ("Automatic boot of image at addr 0x%08lX ...\n", addr
);
900 do_bootm (cmdtp
, 0, 1, local_args
);
910 /***************************************************/
913 #if defined(CONFIG_CMD_FDC)
916 fdcboot
, 3, 1, do_fdcboot
,
917 "fdcboot - boot from floppy device\n",