]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - common/cmd_ide.c
Merge with /home/wd/git/u-boot/custodian/u-boot-testing
[karo-tx-uboot.git] / common / cmd_ide.c
index a4155029a7b8ddb7755619056af7c5c29a1e0ef7..89fefed33d06fccdc535eefaad9a038d1626b621 100644 (file)
 #include <command.h>
 #include <image.h>
 #include <asm/byteorder.h>
+
 #if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
 # include <pcmcia.h>
 #endif
+
 #ifdef CONFIG_8xx
 # include <mpc8xx.h>
 #endif
+
 #ifdef CONFIG_MPC5xxx
 #include <mpc5xxx.h>
 #endif
+
 #include <ide.h>
 #include <ata.h>
+
 #ifdef CONFIG_STATUS_LED
 # include <status_led.h>
 #endif
+
 #ifndef __PPC__
 #include <asm/io.h>
 #ifdef __MIPS__
@@ -53,13 +59,6 @@ unsigned long mips_io_port_base = 0;
 #endif
 #endif
 
-#ifdef CONFIG_SHOW_BOOT_PROGRESS
-# include <status_led.h>
-# define SHOW_BOOT_PROGRESS(arg)       show_boot_progress(arg)
-#else
-# define SHOW_BOOT_PROGRESS(arg)
-#endif
-
 #ifdef CONFIG_IDE_8xx_DIRECT
 DECLARE_GLOBAL_DATA_PTR;
 #endif
@@ -72,7 +71,7 @@ DECLARE_GLOBAL_DATA_PTR;
 # define SYNC          /* nothing */
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_IDE)
+#if defined(CONFIG_CMD_IDE)
 
 #ifdef CONFIG_IDE_8xx_DIRECT
 /* Timings for IDE Interface
@@ -179,10 +178,13 @@ static void input_data(int dev, ulong *sect_buf, int words);
 static void output_data(int dev, ulong *sect_buf, int words);
 static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
 
+#ifndef CFG_ATA_PORT_ADDR
+#define CFG_ATA_PORT_ADDR(port) (port)
+#endif
 
 #ifdef CONFIG_ATAPI
 static void    atapi_inquiry(block_dev_desc_t *dev_desc);
-ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer);
+ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer);
 #endif
 
 
@@ -376,6 +378,7 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        image_header_t *hdr;
        int rcode = 0;
 
+       show_boot_progress (41);
        switch (argc) {
        case 1:
                addr = CFG_LOAD_ADDR;
@@ -391,44 +394,50 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                break;
        default:
                printf ("Usage:\n%s\n", cmdtp->usage);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-42);
                return 1;
        }
+       show_boot_progress (42);
 
        if (!boot_device) {
                puts ("\n** No boot device **\n");
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-43);
                return 1;
        }
+       show_boot_progress (43);
 
        dev = simple_strtoul(boot_device, &ep, 16);
 
        if (ide_dev_desc[dev].type==DEV_TYPE_UNKNOWN) {
                printf ("\n** Device %d not available\n", dev);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-44);
                return 1;
        }
+       show_boot_progress (44);
 
        if (*ep) {
                if (*ep != ':') {
                        puts ("\n** Invalid boot device, use `dev[:part]' **\n");
-                       SHOW_BOOT_PROGRESS (-1);
+                       show_boot_progress (-45);
                        return 1;
                }
                part = simple_strtoul(++ep, NULL, 16);
        }
-       if (get_partition_info (ide_dev_desc, part, &info)) {
-               SHOW_BOOT_PROGRESS (-1);
+       show_boot_progress (45);
+       if (get_partition_info (&ide_dev_desc[dev], part, &info)) {
+               show_boot_progress (-46);
                return 1;
        }
+       show_boot_progress (46);
        if ((strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) &&
            (strncmp((char *)info.type, BOOT_PART_COMP, sizeof(info.type)) != 0)) {
                printf ("\n** Invalid partition type \"%.32s\""
                        " (expect \"" BOOT_PART_TYPE "\")\n",
                        info.type);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-47);
                return 1;
        }
+       show_boot_progress (47);
 
        printf ("\nLoading from IDE device %d, partition %d: "
                "Name: %.32s  Type: %.32s\n",
@@ -439,26 +448,29 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        if (ide_dev_desc[dev].block_read (dev, info.start, 1, (ulong *)addr) != 1) {
                printf ("** Read error on %d:%d\n", dev, part);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-48);
                return 1;
        }
+       show_boot_progress (48);
 
        hdr = (image_header_t *)addr;
 
        if (ntohl(hdr->ih_magic) != IH_MAGIC) {
                printf("\n** Bad Magic Number **\n");
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-49);
                return 1;
        }
+       show_boot_progress (49);
 
        checksum = ntohl(hdr->ih_hcrc);
        hdr->ih_hcrc = 0;
 
        if (crc32 (0, (uchar *)hdr, sizeof(image_header_t)) != checksum) {
                puts ("\n** Bad Header Checksum **\n");
-               SHOW_BOOT_PROGRESS (-2);
+               show_boot_progress (-50);
                return 1;
        }
+       show_boot_progress (50);
        hdr->ih_hcrc = htonl(checksum); /* restore checksum for later use */
 
        print_image_hdr (hdr);
@@ -471,9 +483,10 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        if (ide_dev_desc[dev].block_read (dev, info.start+1, cnt,
                      (ulong *)(addr+info.blksz)) != cnt) {
                printf ("** Read error on %d:%d\n", dev, part);
-               SHOW_BOOT_PROGRESS (-1);
+               show_boot_progress (-51);
                return 1;
        }
+       show_boot_progress (51);
 
 
        /* Loading ok, update default load address */
@@ -507,10 +520,12 @@ void ide_init (void)
 #endif
        unsigned char c;
        int i, bus;
+#if defined(CONFIG_AMIGAONEG3SE) || defined(CONFIG_SC3)
+       unsigned int ata_reset_time = ATA_RESET_TIME;
+       char *s;
+#endif
 #ifdef CONFIG_AMIGAONEG3SE
        unsigned int max_bus_scan;
-       unsigned int ata_reset_time;
-       char *s;
 #endif
 #ifdef CONFIG_IDE_8xx_PCCARD
        extern int pcmcia_on (void);
@@ -611,10 +626,9 @@ void ide_init (void)
                udelay (100000);                /* 100 ms */
                ide_outb (dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
                udelay (100000);                /* 100 ms */
-#ifdef CONFIG_AMIGAONEG3SE
-               ata_reset_time = ATA_RESET_TIME;
-               s = getenv("ide_reset_timeout");
-               if (s) ata_reset_time = 2*simple_strtol(s, NULL, 10);
+#if defined(CONFIG_AMIGAONEG3SE) || defined(CONFIG_SC3)
+               if ((s = getenv("ide_reset_timeout")) != NULL)
+                       ata_reset_time = simple_strtol(s, NULL, 10);
 #endif
                i = 0;
                do {
@@ -622,7 +636,7 @@ void ide_init (void)
 
                        c = ide_inb (dev, ATA_STATUS);
                        i++;
-#ifdef CONFIG_AMIGAONEG3SE
+#if defined(CONFIG_AMIGAONEG3SE) || defined(CONFIG_SC3)
                        if (i > (ata_reset_time * 100)) {
 #else
                        if (i > (ATA_RESET_TIME * 100)) {
@@ -697,7 +711,7 @@ void ide_init (void)
 
 block_dev_desc_t * ide_get_dev(int dev)
 {
-       return ((block_dev_desc_t *)&ide_dev_desc[dev]);
+       return (dev < CFG_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL;
 }
 
 
@@ -800,13 +814,13 @@ ide_outb(int dev, int port, unsigned char val)
 
        /* Ensure I/O operations complete */
        EIEIO;
-       *((uchar *)(ATA_CURR_BASE(dev)+port)) = val;
+       *((u16 *)(ATA_CURR_BASE(dev)+CFG_ATA_PORT_ADDR(port))) = val;
 }
 #else  /* ! __PPC__ */
 static void __inline__
 ide_outb(int dev, int port, unsigned char val)
 {
-       outb(val, ATA_CURR_BASE(dev)+port);
+       outb(val, ATA_CURR_BASE(dev)+CFG_ATA_PORT_ADDR(port));
 }
 #endif /* __PPC__ */
 
@@ -818,7 +832,7 @@ ide_inb(int dev, int port)
        uchar val;
        /* Ensure I/O operations complete */
        EIEIO;
-       val = *((uchar *)(ATA_CURR_BASE(dev)+port));
+       val = *((u16 *)(ATA_CURR_BASE(dev)+CFG_ATA_PORT_ADDR(port)));
        debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
                dev, port, (ATA_CURR_BASE(dev)+port), val);
        return (val);
@@ -827,7 +841,7 @@ ide_inb(int dev, int port)
 static unsigned char __inline__
 ide_inb(int dev, int port)
 {
-  return inb(ATA_CURR_BASE(dev)+port);
+  return inb(ATA_CURR_BASE(dev)+CFG_ATA_PORT_ADDR(port));
 }
 #endif /* __PPC__ */
 
@@ -884,6 +898,9 @@ input_swap_data(int dev, ulong *sect_buf, int words)
 #ifdef __MIPS__
                *dbuf++ = swab16p((u16*)pbuf);
                *dbuf++ = swab16p((u16*)pbuf);
+#elif defined(CONFIG_PCS440EP)
+               *dbuf++ = *pbuf;
+               *dbuf++ = *pbuf;
 #else
                *dbuf++ = ld_le16(pbuf);
                *dbuf++ = ld_le16(pbuf);
@@ -923,10 +940,18 @@ output_data(int dev, ulong *sect_buf, int words)
        pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG);
        dbuf = (ushort *)sect_buf;
        while (words--) {
+#if defined(CONFIG_PCS440EP)
+               /* not tested, because CF was write protected */
+               EIEIO;
+               *pbuf = ld_le16(dbuf++);
+               EIEIO;
+               *pbuf = ld_le16(dbuf++);
+#else
                EIEIO;
                *pbuf = *dbuf++;
                EIEIO;
                *pbuf = *dbuf++;
+#endif
        }
 #endif
 }
@@ -974,10 +999,17 @@ input_data(int dev, ulong *sect_buf, int words)
        debug("in input data base for read is %lx\n", (unsigned long) pbuf);
 
        while (words--) {
+#if defined(CONFIG_PCS440EP)
+               EIEIO;
+               *dbuf++ = ld_le16(pbuf);
+               EIEIO;
+               *dbuf++ = ld_le16(pbuf);
+#else
                EIEIO;
                *dbuf++ = *pbuf;
                EIEIO;
                *dbuf++ = *pbuf;
+#endif
        }
 #endif
 }
@@ -1227,7 +1259,7 @@ static void ide_ident (block_dev_desc_t *dev_desc)
 
 /* ------------------------------------------------------------------------- */
 
-ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer)
+ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
 {
        ulong n = 0;
        unsigned char c;
@@ -1337,7 +1369,7 @@ ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer)
 
                ++n;
                ++blknr;
-               buffer += ATA_SECTORWORDS;
+               buffer += ATA_BLOCKSIZE;
        }
 IDE_READ_E:
        ide_led (DEVICE_LED(device), 0);        /* LED off      */
@@ -1347,7 +1379,7 @@ IDE_READ_E:
 /* ------------------------------------------------------------------------- */
 
 
-ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer)
+ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
 {
        ulong n = 0;
        unsigned char c;
@@ -1421,7 +1453,7 @@ ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer)
                c = ide_inb (device, ATA_STATUS);       /* clear IRQ */
                ++n;
                ++blknr;
-               buffer += ATA_SECTORWORDS;
+               buffer += ATA_BLOCKSIZE;
        }
 WR_OUT:
        ide_led (DEVICE_LED(device), 0);        /* LED off      */
@@ -2009,7 +2041,7 @@ static void       atapi_inquiry(block_dev_desc_t * dev_desc)
 #define ATAPI_READ_BLOCK_SIZE  2048    /* assuming CD part */
 #define ATAPI_READ_MAX_BLOCK ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE        /* max blocks */
 
-ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer)
+ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
 {
        ulong n = 0;
        unsigned char ccb[12]; /* Command descriptor block */
@@ -2045,7 +2077,7 @@ ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer)
                n+=cnt;
                blkcnt-=cnt;
                blknr+=cnt;
-               buffer+=cnt*(ATAPI_READ_BLOCK_SIZE/4); /* ulong blocksize in ulong */
+               buffer+=(cnt*ATAPI_READ_BLOCK_SIZE);
        } while (blkcnt > 0);
        return (n);
 }
@@ -2073,4 +2105,4 @@ U_BOOT_CMD(
        "loadAddr dev:part\n"
 );
 
-#endif /* CONFIG_COMMANDS & CFG_CMD_IDE */
+#endif