]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_ide.c
Fix IDE stability problems on CPC45 board.
[u-boot] / common / cmd_ide.c
index baab8715c94f4211d2a5e7e90c68304104be8e25..b8e0bef574289e6fd112fff5ba1e27519bb6f618 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2000-2002
+ * (C) Copyright 2000-2004
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
  * See file CREDITS for list of people who contributed to this
@@ -60,6 +60,11 @@ static unsigned long mips_io_port_base = 0;
 # define SHOW_BOOT_PROGRESS(arg)
 #endif
 
+#ifdef __PPC__
+# define EIEIO         __asm__ volatile ("eieio")
+#else
+# define EIEIO         /* nothing */
+#endif
 
 #undef IDE_DEBUG
 
@@ -135,11 +140,11 @@ static int            ide_bus_ok[CFG_IDE_MAXBUS];
 static int         ide_bus_ok[CFG_IDE_MAXBUS] = {0,};
 #endif
 
-static  block_dev_desc_t ide_dev_desc[CFG_IDE_MAXDEVICE];
+block_dev_desc_t ide_dev_desc[CFG_IDE_MAXDEVICE];
 /* ------------------------------------------------------------------------- */
 
 #ifdef CONFIG_IDE_LED
-#if !defined(CONFIG_KUP4K) &&  !defined(CONFIG_KUP4X) &&!defined(CONFIG_BMS2003)
+#if !defined(CONFIG_KUP4K) &&  !defined(CONFIG_KUP4X) &&!defined(CONFIG_BMS2003) &&!defined(CONFIG_CPC45)
 static void  ide_led   (uchar led, uchar status);
 #else
 extern void  ide_led   (uchar led, uchar status);
@@ -790,9 +795,7 @@ ide_outb(int dev, int port, unsigned char val)
                dev, port, val, (ATA_CURR_BASE(dev)+port));
 
        /* Ensure I/O operations complete */
-#ifdef __PPC__
-       __asm__ volatile("eieio");
-#endif
+       EIEIO;
        *((uchar *)(ATA_CURR_BASE(dev)+port)) = val;
 }
 #else  /* ! __PPC__ */
@@ -810,9 +813,7 @@ ide_inb(int dev, int port)
 {
        uchar val;
        /* Ensure I/O operations complete */
-#ifdef __PPC__
-       __asm__ volatile("eieio");
-#endif
+       EIEIO;
        val = *((uchar *)(ATA_CURR_BASE(dev)+port));
        PRINTF ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
                dev, port, (ATA_CURR_BASE(dev)+port), val);
@@ -837,9 +838,9 @@ output_data_short(int dev, ulong *sect_buf, int words)
        pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG);
        dbuf = (ushort *)sect_buf;
        while (words--) {
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf = *dbuf++;
-               __asm__ volatile ("eieio");
+               EIEIO;
        }
 
        if (words&1)
@@ -895,13 +896,9 @@ output_data(int dev, ulong *sect_buf, int words)
        pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG);
        dbuf = (ushort *)sect_buf;
        while (words--) {
-#ifdef __PPC__
-               __asm__ volatile ("eieio");
-#endif
+               EIEIO;
                *pbuf = *dbuf++;
-#ifdef __PPC__
-               __asm__ volatile ("eieio");
-#endif
+               EIEIO;
                *pbuf = *dbuf++;
        }
 #else  /* CONFIG_HMI10 */
@@ -913,13 +910,13 @@ output_data(int dev, ulong *sect_buf, int words)
        pbuf_odd  = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD);
        dbuf = (uchar *)sect_buf;
        while (words--) {
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf_even = *dbuf++;
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf_odd = *dbuf++;
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf_even = *dbuf++;
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf_odd = *dbuf++;
        }
 #endif /* CONFIG_HMI10 */
@@ -946,13 +943,9 @@ input_data(int dev, ulong *sect_buf, int words)
        PRINTF("in input data base for read is %lx\n", (unsigned long) pbuf);
 
        while (words--) {
-#ifdef __PPC__
-               __asm__ volatile ("eieio");
-#endif
+               EIEIO;
                *dbuf++ = *pbuf;
-#ifdef __PPC__
-               __asm__ volatile ("eieio");
-#endif
+               EIEIO;
                *dbuf++ = *pbuf;
        }
 #else  /* CONFIG_HMI10 */
@@ -964,13 +957,17 @@ input_data(int dev, ulong *sect_buf, int words)
        pbuf_odd  = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD);
        dbuf = (uchar *)sect_buf;
        while (words--) {
-               __asm__ volatile ("eieio");
+               EIEIO;
+               EIEIO;
                *dbuf++ = *pbuf_even;
-               __asm__ volatile ("eieio");
+               EIEIO;
+               EIEIO;
                *dbuf++ = *pbuf_odd;
-               __asm__ volatile ("eieio");
+               EIEIO;
+               EIEIO;
                *dbuf++ = *pbuf_even;
-               __asm__ volatile ("eieio");
+               EIEIO;
+               EIEIO;
                *dbuf++ = *pbuf_odd;
        }
 #endif /* CONFIG_HMI10 */
@@ -994,9 +991,9 @@ input_data_short(int dev, ulong *sect_buf, int words)
        pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG);
        dbuf = (ushort *)sect_buf;
        while (words--) {
-               __asm__ volatile ("eieio");
+               EIEIO;
                *dbuf++ = *pbuf;
-               __asm__ volatile ("eieio");
+               EIEIO;
        }
 
        if (words&1) {
@@ -1016,8 +1013,10 @@ static void ide_ident (block_dev_desc_t *dev_desc)
 
 #ifdef CONFIG_AMIGAONEG3SE
        int max_bus_scan;
-       int retries = 0;
        char *s;
+#endif
+#ifdef CONFIG_ATAPI
+       int retries = 0;
        int do_retry = 0;
 #endif
 
@@ -1048,14 +1047,11 @@ static void ide_ident (block_dev_desc_t *dev_desc)
        dev_desc->if_type=IF_TYPE_IDE;
 #ifdef CONFIG_ATAPI
 
-#ifdef CONFIG_AMIGAONEG3SE
     do_retry = 0;
     retries = 0;
 
     /* Warning: This will be tricky to read */
     while (retries <= 1) {
-#endif /* CONFIG_AMIGAONEG3SE */
-
        /* check signature */
        if ((ide_inb(device,ATA_SECT_CNT) == 0x01) &&
                 (ide_inb(device,ATA_SECT_NUM) == 0x01) &&
@@ -1086,32 +1082,35 @@ static void ide_ident (block_dev_desc_t *dev_desc)
 
        if (((c & ATA_STAT_DRQ) == 0) ||
            ((c & (ATA_STAT_FAULT|ATA_STAT_ERR)) != 0) ) {
+#ifdef CONFIG_ATAPI
 #ifdef CONFIG_AMIGAONEG3SE
-               if (retries == 0) {
-                       do_retry = 1;
-               } else {
-                       return;
-               }
-#else
-               return;
-#endif /* CONFIG_AMIGAONEG3SE */
-       }
-
-#ifdef CONFIG_AMIGAONEG3SE
-       s = getenv("ide_doreset");
-       if (s && strcmp(s, "on") == 0 && 1 == do_retry) {
-               /* Need to soft reset the device in case it's an ATAPI...  */
-               PRINTF("Retrying...\n");
+               s = getenv("ide_doreset");
+               if (s && strcmp(s, "on") == 0)
+#endif
+                       {
+                               /* Need to soft reset the device in case it's an ATAPI...  */
+                               PRINTF("Retrying...\n");
+                               ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+                               udelay(100000);
+                               ide_outb (device, ATA_COMMAND, 0x08);
+                               udelay (500000);        /* 500 ms */
+                       }
+               /* Select device
+                */
                ide_outb (device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-               udelay(100000);
-               ide_outb (device, ATA_COMMAND, 0x08);
-               udelay (100000);        /* 100 ms */
                retries++;
-       } else {
-               retries = 100;
+#else
+               return;
+#endif
        }
+#ifdef CONFIG_ATAPI
+       else
+               break;
     }  /* see above - ugly to read */
-#endif /* CONFIG_AMIGAONEG3SE */
+
+       if (retries == 2) /* Not found */
+               return;
+#endif
 
        input_swap_data (device, iobuf, ATA_SECTORWORDS);
 
@@ -1186,13 +1185,12 @@ static void ide_ident (block_dev_desc_t *dev_desc)
 
 #ifdef CONFIG_LBA48
        if (iop->command_set_2 & 0x0400) { /* LBA 48 support */
-               dev_desc->lba48support = 1;
-               dev_desc->lba48 = (unsigned long long)iop->lba48_capacity[0] |
+               dev_desc->lba48 = 1;
+               dev_desc->lba = (unsigned long long)iop->lba48_capacity[0] |
                                                  ((unsigned long long)iop->lba48_capacity[1] << 16) |
                                                  ((unsigned long long)iop->lba48_capacity[2] << 32) |
                                                  ((unsigned long long)iop->lba48_capacity[3] << 48);
        } else {
-               dev_desc->lba48support = 0;
                dev_desc->lba48 = 0;
        }
 #endif /* CONFIG_LBA48 */
@@ -1554,11 +1552,12 @@ static void ide_reset (void)
 
 /* ------------------------------------------------------------------------- */
 
-#if defined(CONFIG_IDE_LED) && \
-   !defined(CONFIG_AMIGAONEG3SE) && \
-   !defined(CONFIG_KUP4K) && \
-   !defined(CONFIG_KUP4X) && \
-   !defined(CONFIG_HMI10)
+#if defined(CONFIG_IDE_LED)    && \
+   !defined(CONFIG_AMIGAONEG3SE)&& \
+   !defined(CONFIG_CPC45)      && \
+   !defined(CONFIG_HMI10)      && \
+   !defined(CONFIG_KUP4K)      && \
+   !defined(CONFIG_KUP4X)
 
 static uchar   led_buffer = 0;         /* Buffer for current LED status        */
 
@@ -1584,7 +1583,6 @@ static void ide_led (uchar led, uchar status)
  * ATAPI Support
  */
 
-
 #undef ATAPI_DEBUG
 
 #ifdef ATAPI_DEBUG
@@ -1609,9 +1607,7 @@ output_data_shorts(int dev, ushort *sect_buf, int shorts)
        PRINTF("in output data shorts base for read is %lx\n", (unsigned long) pbuf);
 
        while (shorts--) {
-#ifdef __PPC__
-               __asm__ volatile ("eieio");
-#endif
+               EIEIO;
                *pbuf = *dbuf++;
        }
 #else  /* CONFIG_HMI10 */
@@ -1622,9 +1618,9 @@ output_data_shorts(int dev, ushort *sect_buf, int shorts)
        pbuf_even = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_EVEN);
        pbuf_odd  = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD);
        while (shorts--) {
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf_even = *dbuf++;
-               __asm__ volatile ("eieio");
+               EIEIO;
                *pbuf_odd = *dbuf++;
        }
 #endif /* CONFIG_HMI10 */
@@ -1643,9 +1639,7 @@ input_data_shorts(int dev, ushort *sect_buf, int shorts)
        PRINTF("in input data shorts base for read is %lx\n", (unsigned long) pbuf);
 
        while (shorts--) {
-#ifdef __PPC__
-               __asm__ volatile ("eieio");
-#endif
+               EIEIO;
                *dbuf++ = *pbuf;
        }
 #else  /* CONFIG_HMI10 */
@@ -1656,9 +1650,9 @@ input_data_shorts(int dev, ushort *sect_buf, int shorts)
        pbuf_even = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_EVEN);
        pbuf_odd  = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD);
        while (shorts--) {
-               __asm__ volatile ("eieio");
+               EIEIO;
                *dbuf++ = *pbuf_even;
-               __asm__ volatile ("eieio");
+               EIEIO;
                *dbuf++ = *pbuf_odd;
        }
 #endif /* CONFIG_HMI10 */
@@ -1671,7 +1665,6 @@ output_data_shorts(int dev, ushort *sect_buf, int shorts)
        outsw(ATA_CURR_BASE(dev)+ATA_DATA_REG, sect_buf, shorts);
 }
 
-
 static void
 input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {