]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_fdc.c
ColdFire 54455: Fix correct boot location for atmel and intel
[u-boot] / common / cmd_fdc.c
index e45b3361ca1b72c9e0227ab02ac227a2716c2604..7349412c77a92af60fa8700f9f48e5a012fda8d5 100644 (file)
 #endif
 
 
-#if (CONFIG_COMMANDS & CFG_CMD_DATE)
-#include <rtc.h>
-#endif
+/*#if defined(CONFIG_CMD_DATE) */
+/*#include <rtc.h> */
+/*#endif */
 
-#if ((CONFIG_COMMANDS & CFG_CMD_FDC) || (CONFIG_COMMANDS & CFG_CMD_FDOS))
+#if defined(CONFIG_CMD_FDC) || defined(CONFIG_CMD_FDOS)
 
 
 typedef struct {
@@ -188,6 +188,30 @@ static FDC_COMMAND_STRUCT cmd; /* global command struct */
 #endif
 
 
+#ifdef CONFIG_AMIGAONEG3SE
+unsigned char INT6_Status;
+
+void fdc_interrupt(void)
+{
+    INT6_Status = 0x80;
+}
+
+/* waits for an interrupt (polling) */
+int wait_for_fdc_int(void)
+{
+       unsigned long timeout;
+       timeout = FDC_TIME_OUT;
+       while(((volatile)INT6_Status & 0x80) == 0) {
+               timeout--;
+               udelay(10);
+               if(timeout == 0) /* timeout occured */
+                       return FALSE;
+       }
+       INT6_Status = 0;
+       return TRUE;
+}
+#endif
+
 /* Supporting Functions */
 /* reads a Register of the FDC */
 unsigned char read_fdc_reg(unsigned int addr)
@@ -196,20 +220,21 @@ unsigned char read_fdc_reg(unsigned int addr)
                (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS +
                                           (addr * CFG_ISA_IO_STRIDE) +
                                           CFG_ISA_IO_OFFSET);
-        
+
        return val [0];
 }
 
 /* writes a Register of the FDC */
 void write_fdc_reg(unsigned int addr, unsigned char val)
 {
-        volatile unsigned char *tmp =
+       volatile unsigned char *tmp =
                (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS +
                                           (addr * CFG_ISA_IO_STRIDE) +
                                           CFG_ISA_IO_OFFSET);
        tmp[0]=val;
 }
 
+#ifndef CONFIG_AMIGAONEG3SE
 /* waits for an interrupt (polling) */
 int wait_for_fdc_int(void)
 {
@@ -224,6 +249,7 @@ int wait_for_fdc_int(void)
        return TRUE;
 }
 
+#endif
 
 /* reads a byte from the FIFO of the FDC and checks direction and RQM bit
    of the MSR. returns -1 if timeout, or byte if ok */
@@ -416,7 +442,7 @@ int fdc_seek(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
        return(fdc_issue_cmd(pCMD,pFG));
 }
 
-
+#ifndef CONFIG_AMIGAONEG3SE
 /* terminates current command, by not servicing the FIFO
  * waits for interrupt and fills in the result bytes */
 int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
@@ -430,6 +456,27 @@ int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
        }
        return TRUE;
 }
+#endif
+#ifdef CONFIG_AMIGAONEG3SE
+int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
+{
+       int i;
+       for(i=0;i<100;i++)
+               udelay(500); /* wait 500usec for fifo overrun */
+       while((INT6_Status&0x80)==0x00); /* wait as long as no int has occured */
+       for(i=0;i<7;i++) {
+               pCMD->result[i]=(unsigned char)read_fdc_byte();
+       }
+       INT6_Status = 0;
+       return TRUE;
+}
+
+#endif
+
+#ifdef CONFIG_AMIGAONEG3SE
+#define disable_interrupts() 0
+#define enable_interrupts() (void)0
+#endif
 
 /* reads data from FDC, seek commands are issued automatic */
 int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
@@ -550,6 +597,11 @@ retrycal:
        return TRUE;
 }
 
+#ifdef CONFIG_AMIGAONEG3SE
+#undef disable_interrupts()
+#undef enable_interrupts()
+#endif
+
 /* Scan all drives and check if drive is present and disk is inserted */
 int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
 {
@@ -597,11 +649,15 @@ int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
 */
 int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
 {
-
        int i;
 
+#ifdef CONFIG_AMIGAONEG3SE
+       irq_install_handler(6, (interrupt_handler_t *)fdc_interrupt, NULL);
+       i8259_unmask_irq(6);
+#endif
+
 #ifdef CFG_FDC_HW_INIT
-        fdc_hw_init ();
+       fdc_hw_init ();
 #endif
        /* first, we reset the FDC via the DOR */
        write_fdc_reg(FDC_DOR,0x00);
@@ -648,24 +704,25 @@ int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
        /* then, we clear the reset in the DOR */
        /* fdc_check_drive(pCMD,pFG);   */
        /*      write_fdc_reg(FDC_DOR,0x04); */
+
        return TRUE;
 }
-#endif /* ((CONFIG_COMMANDS & CFG_CMD_FDC)||(CONFIG_COMMANDS & CFG_CMD_FDOS))*/
+#endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_FDOS)
+#if defined(CONFIG_CMD_FDOS)
 
 /* Low level functions for the Floppy-DOS layer                              */
 
 /**************************************************************************
 * int fdc_fdos_init
-* initialize the FDC layer 
-* 
+* initialize the FDC layer
+*
 */
 int fdc_fdos_init (int drive)
 {
        FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
        FDC_COMMAND_STRUCT *pCMD = &cmd;
-    
+
        /* setup FDC and scan for drives  */
        if(fdc_setup(drive,pCMD,pFG)==FALSE) {
                printf("\n** Error in setup FDC **\n");
@@ -690,19 +747,19 @@ int fdc_fdos_init (int drive)
 
        /* read first block */
        pCMD->blnr=0;
-        return TRUE;
+       return TRUE;
 }
 /**************************************************************************
 * int fdc_fdos_seek
-* parameter is a block number 
+* parameter is a block number
 */
 int fdc_fdos_seek (int where)
 {
        FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
        FDC_COMMAND_STRUCT *pCMD = &cmd;
 
-        pCMD -> blnr = where ;
-        return (fdc_seek (pCMD, pFG));
+       pCMD -> blnr = where ;
+       return (fdc_seek (pCMD, pFG));
 }
 /**************************************************************************
 * int fdc_fdos_read
@@ -713,11 +770,11 @@ int fdc_fdos_read (void *buffer, int len)
        FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
        FDC_COMMAND_STRUCT *pCMD = &cmd;
 
-        return (fdc_read_data (buffer, len, pCMD, pFG));
+       return (fdc_read_data (buffer, len, pCMD, pFG));
 }
-#endif  /* (CONFIG_COMMANDS & CFG_CMD_FDOS)                                  */
+#endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_FDC)
+#if defined(CONFIG_CMD_FDC)
 /****************************************************************************
  * main routine do_fdcboot
  */
@@ -725,7 +782,7 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
        FDC_COMMAND_STRUCT *pCMD = &cmd;
-       unsigned long addr,imsize;
+       unsigned long addr,imsize;
        image_header_t *hdr;  /* used for fdc boot */
        unsigned char boot_drive;
        int i,nrofblk;
@@ -735,7 +792,7 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        switch (argc) {
        case 1:
                addr = CFG_LOAD_ADDR;
-               boot_drive=CFG_FDC_DRIVE_NUMBER; 
+               boot_drive=CFG_FDC_DRIVE_NUMBER;
                break;
        case 2:
                addr = simple_strtoul(argv[1], NULL, 16);
@@ -779,13 +836,13 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return 1;
        }
        hdr = (image_header_t *)addr;
-       if (hdr->ih_magic  != IH_MAGIC) {
+       if (ntohl(hdr->ih_magic)  != IH_MAGIC) {
                printf ("Bad Magic Number\n");
                return 1;
        }
        print_image_hdr(hdr);
 
-       imsize= hdr->ih_size+sizeof(image_header_t);
+       imsize= ntohl(hdr->ih_size)+sizeof(image_header_t);
        nrofblk=imsize/512;
        if((imsize%512)>0)
                nrofblk++;
@@ -823,7 +880,17 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 }
 
 
+#endif
+
+
+/***************************************************/
 
-#endif /* CONFIG_COMMANDS & CFG_CMD_FDC */
 
+#if defined(CONFIG_CMD_FDC)
 
+U_BOOT_CMD(
+       fdcboot,        3,      1,      do_fdcboot,
+       "fdcboot - boot from floppy device\n",
+       "loadAddr drive\n"
+);
+#endif