Merge branch 'master' of git://git.denx.de/u-boot-arm
[platform/kernel/u-boot.git] / common / cmd_ide.c
index b23db3f..1fc0377 100644 (file)
 #include <mpc5xxx.h>
 #endif
 
-#ifdef CONFIG_ORION5X
-#include <asm/arch/orion5x.h>
-#endif
-
 #include <ide.h>
 #include <ata.h>
 
@@ -158,7 +154,7 @@ static uchar ide_wait  (int dev, ulong t);
 #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
 
 static void input_data(int dev, ulong *sect_buf, int words);
-static void output_data(int dev, ulong *sect_buf, int words);
+static void output_data(int dev, const ulong *sect_buf, int words);
 static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
 
 #ifndef CONFIG_SYS_ATA_PORT_ADDR
@@ -354,7 +350,6 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        ulong addr, cnt;
        disk_partition_t info;
        image_header_t *hdr;
-       int rcode = 0;
 #if defined(CONFIG_FIT)
        const void *fit_hdr = NULL;
 #endif
@@ -493,20 +488,7 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        load_addr = addr;
 
-       /* Check if we should attempt an auto-start */
-       if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
-               char *local_args[2];
-               extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
-
-               local_args[0] = argv[0];
-               local_args[1] = NULL;
-
-               printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
-
-               do_bootm (cmdtp, 0, 1, local_args);
-               rcode = 1;
-       }
-       return rcode;
+       return bootm_maybe_autostart(cmdtp, argv[0]);
 }
 
 /* ------------------------------------------------------------------------- */
@@ -516,8 +498,20 @@ __ide_outb(int dev, int port, unsigned char val)
 {
        debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
                dev, port, val, (ATA_CURR_BASE(dev)+CONFIG_SYS_ATA_PORT_ADDR(port)));
+
+#if defined(CONFIG_IDE_AHB)
+       if (port) {
+               /* write command */
+               ide_write_register(dev, port, val);
+       } else {
+               /* write data */
+               outb(val, (ATA_CURR_BASE(dev)));
+       }
+#else
        outb(val, (ATA_CURR_BASE(dev)+CONFIG_SYS_ATA_PORT_ADDR(port)));
+#endif
 }
+
 void ide_outb (int dev, int port, unsigned char val)
                __attribute__((weak, alias("__ide_outb")));
 
@@ -525,7 +519,13 @@ unsigned char inline
 __ide_inb(int dev, int port)
 {
        uchar val;
+
+#if defined(CONFIG_IDE_AHB)
+       val = ide_read_register(dev, port);
+#else
        val = inb((ATA_CURR_BASE(dev)+CONFIG_SYS_ATA_PORT_ADDR(port)));
+#endif
+
        debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
                dev, port, (ATA_CURR_BASE(dev)+CONFIG_SYS_ATA_PORT_ADDR(port)), val);
        return val;
@@ -694,6 +694,7 @@ void ide_init (void)
                ide_dev_desc[i].blksz=0;
                ide_dev_desc[i].lba=0;
                ide_dev_desc[i].block_read=ide_read;
+               ide_dev_desc[i].block_write = ide_write;
                if (!ide_bus_ok[IDE_BUS(i)])
                        continue;
                ide_led (led, 1);               /* LED on       */
@@ -712,10 +713,12 @@ void ide_init (void)
 
 /* ------------------------------------------------------------------------- */
 
+#ifdef CONFIG_PARTITIONS
 block_dev_desc_t * ide_get_dev(int dev)
 {
        return (dev < CONFIG_SYS_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL;
 }
+#endif
 
 
 #ifdef CONFIG_IDE_8xx_DIRECT
@@ -810,13 +813,14 @@ set_pcmcia_timing (int pmode)
 
 /* We only need to swap data if we are running on a big endian cpu. */
 /* But Au1x00 cpu:s already swaps data in big endian mode! */
-#if defined(__LITTLE_ENDIAN) || ( defined(CONFIG_AU1X00) && !defined(CONFIG_GTH2) )
+#if defined(__LITTLE_ENDIAN) || \
+   (defined(CONFIG_SOC_AU1X00) && !defined(CONFIG_GTH2))
 #define input_swap_data(x,y,z) input_data(x,y,z)
 #else
 static void
 input_swap_data(int dev, ulong *sect_buf, int words)
 {
-#if defined(CONFIG_HMI10) || defined(CONFIG_CPC45)
+#if defined(CONFIG_CPC45)
        uchar i;
        volatile uchar *pbuf_even = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_EVEN);
        volatile uchar *pbuf_odd  = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD);
@@ -854,9 +858,9 @@ input_swap_data(int dev, ulong *sect_buf, int words)
 
 #if defined(CONFIG_IDE_SWAP_IO)
 static void
-output_data(int dev, ulong *sect_buf, int words)
+output_data(int dev, const ulong *sect_buf, int words)
 {
-#if defined(CONFIG_HMI10) || defined(CONFIG_CPC45)
+#if defined(CONFIG_CPC45)
        uchar   *dbuf;
        volatile uchar  *pbuf_even;
        volatile uchar  *pbuf_odd;
@@ -898,9 +902,13 @@ output_data(int dev, ulong *sect_buf, int words)
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
 static void
-output_data(int dev, ulong *sect_buf, int words)
+output_data(int dev, const ulong *sect_buf, int words)
 {
-       outsw(ATA_CURR_BASE(dev)+ATA_DATA_REG, sect_buf, words<<1);
+#if defined(CONFIG_IDE_AHB)
+       ide_write_data(dev, sect_buf, words);
+#else
+       outsw(ATA_CURR_BASE(dev)+ATA_DATA_REG, sect_buf, words << 1);
+#endif
 }
 #endif /* CONFIG_IDE_SWAP_IO */
 
@@ -908,7 +916,7 @@ output_data(int dev, ulong *sect_buf, int words)
 static void
 input_data(int dev, ulong *sect_buf, int words)
 {
-#if defined(CONFIG_HMI10) || defined(CONFIG_CPC45)
+#if defined(CONFIG_CPC45)
        uchar   *dbuf;
        volatile uchar  *pbuf_even;
        volatile uchar  *pbuf_odd;
@@ -958,7 +966,11 @@ input_data(int dev, ulong *sect_buf, int words)
 static void
 input_data(int dev, ulong *sect_buf, int words)
 {
+#if defined(CONFIG_IDE_AHB)
+       ide_read_data(dev, sect_buf, words);
+#else
        insw(ATA_CURR_BASE(dev)+ATA_DATA_REG, sect_buf, words << 1);
+#endif
 }
 
 #endif /* CONFIG_IDE_SWAP_IO */
@@ -967,9 +979,8 @@ input_data(int dev, ulong *sect_buf, int words)
  */
 static void ide_ident (block_dev_desc_t *dev_desc)
 {
-       ulong iobuf[ATA_SECTORWORDS];
        unsigned char c;
-       hd_driveid_t *iop = (hd_driveid_t *)iobuf;
+       hd_driveid_t iop;
 
 #ifdef CONFIG_ATAPI
        int retries = 0;
@@ -1055,11 +1066,11 @@ static void ide_ident (block_dev_desc_t *dev_desc)
                return;
 #endif
 
-       input_swap_data (device, iobuf, ATA_SECTORWORDS);
+       input_swap_data (device, (ulong *)&iop, ATA_SECTORWORDS);
 
-       ident_cpy ((unsigned char*)dev_desc->revision, iop->fw_rev, sizeof(dev_desc->revision));
-       ident_cpy ((unsigned char*)dev_desc->vendor, iop->model, sizeof(dev_desc->vendor));
-       ident_cpy ((unsigned char*)dev_desc->product, iop->serial_no, sizeof(dev_desc->product));
+       ident_cpy ((unsigned char*)dev_desc->revision, iop.fw_rev, sizeof(dev_desc->revision));
+       ident_cpy ((unsigned char*)dev_desc->vendor, iop.model, sizeof(dev_desc->vendor));
+       ident_cpy ((unsigned char*)dev_desc->product, iop.serial_no, sizeof(dev_desc->product));
 #ifdef __LITTLE_ENDIAN
        /*
         * firmware revision, model, and serial number have Big Endian Byte
@@ -1074,14 +1085,14 @@ static void ide_ident (block_dev_desc_t *dev_desc)
        strswab (dev_desc->product);
 #endif /* __LITTLE_ENDIAN */
 
-       if ((iop->config & 0x0080)==0x0080)
+       if ((iop.config & 0x0080) == 0x0080)
                dev_desc->removable = 1;
        else
                dev_desc->removable = 0;
 
 #ifdef CONFIG_TUNE_PIO
        /* Mode 0 - 2 only, are directly determined by word 51. */
-       pio_mode = iop->tPIO;
+       pio_mode = iop.tPIO;
        if (pio_mode > 2) {
                printf("WARNING: Invalid PIO (word 51 = %d).\n", pio_mode);
                pio_mode = 0; /* Force it to dead slow, and hope for the best... */
@@ -1091,18 +1102,18 @@ static void ide_ident (block_dev_desc_t *dev_desc)
         * shall set bit 1 of word 53 to one and support the fields contained
         * in words 64 through 70.
         */
-       if (iop->field_valid & 0x02) {
+       if (iop.field_valid & 0x02) {
                /* Mode 3 and above are possible.  Check in order from slow
                 * to fast, so we wind up with the highest mode allowed.
                 */
-               if (iop->eide_pio_modes & 0x01)
+               if (iop.eide_pio_modes & 0x01)
                        pio_mode = 3;
-               if (iop->eide_pio_modes & 0x02)
+               if (iop.eide_pio_modes & 0x02)
                        pio_mode = 4;
-               if (ata_id_is_cfa((u16 *)iop)) {
-                       if ((iop->cf_advanced_caps & 0x07) == 0x01)
+               if (ata_id_is_cfa((u16 *)&iop)) {
+                       if ((iop.cf_advanced_caps & 0x07) == 0x01)
                                pio_mode = 5;
-                       if ((iop->cf_advanced_caps & 0x07) == 0x02)
+                       if ((iop.cf_advanced_caps & 0x07) == 0x02)
                                pio_mode = 6;
                }
        }
@@ -1115,19 +1126,19 @@ static void ide_ident (block_dev_desc_t *dev_desc)
        /*
         * Drive PIO mode autoselection
         */
-       mode = iop->tPIO;
+       mode = iop.tPIO;
 
        printf ("tPIO = 0x%02x = %d\n",mode, mode);
        if (mode > 2) {         /* 2 is maximum allowed tPIO value */
                mode = 2;
                debug ("Override tPIO -> 2\n");
        }
-       if (iop->field_valid & 2) {     /* drive implements ATA2? */
+       if (iop.field_valid & 2) {      /* drive implements ATA2? */
                debug ("Drive implements ATA2\n");
-               if (iop->capability & 8) {      /* drive supports use_iordy? */
-                       cycle_time = iop->eide_pio_iordy;
+               if (iop.capability & 8) {       /* drive supports use_iordy? */
+                       cycle_time = iop.eide_pio_iordy;
                } else {
-                       cycle_time = iop->eide_pio;
+                       cycle_time = iop.eide_pio;
                }
                debug ("cycle time = %d\n", cycle_time);
                mode = 4;
@@ -1148,7 +1159,7 @@ static void ide_ident (block_dev_desc_t *dev_desc)
 
 #ifdef __BIG_ENDIAN
        /* swap shorts */
-       dev_desc->lba = (iop->lba_capacity << 16) | (iop->lba_capacity >> 16);
+       dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16);
 #else  /* ! __BIG_ENDIAN */
        /*
         * do not swap shorts on little endian
@@ -1156,16 +1167,16 @@ static void ide_ident (block_dev_desc_t *dev_desc)
         * See CF+ and CompactFlash Specification Revision 2.0:
         * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details.
         */
-       dev_desc->lba = iop->lba_capacity;
+       dev_desc->lba = iop.lba_capacity;
 #endif /* __BIG_ENDIAN */
 
 #ifdef CONFIG_LBA48
-       if (iop->command_set_2 & 0x0400) { /* LBA 48 support */
+       if (iop.command_set_2 & 0x0400) { /* LBA 48 support */
                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);
+               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->lba48 = 0;
        }
@@ -1207,7 +1218,7 @@ ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
                lba48 = 1;
        }
 #endif
-       debug ("ide_read dev %d start %LX, blocks %lX buffer at %lX\n",
+       debug("ide_read dev %d start %lX, blocks %lX buffer at %lX\n",
                device, blknr, blkcnt, (ulong)buffer);
 
        ide_led (DEVICE_LED(device), 1);        /* LED on       */
@@ -1319,7 +1330,7 @@ IDE_READ_E:
 /* ------------------------------------------------------------------------- */
 
 
-ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
+ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, const void *buffer)
 {
        ulong n = 0;
        unsigned char c;
@@ -1542,7 +1553,6 @@ static void ide_reset (void)
 
 #if defined(CONFIG_IDE_LED)    && \
    !defined(CONFIG_CPC45)      && \
-   !defined(CONFIG_HMI10)      && \
    !defined(CONFIG_KUP4K)      && \
    !defined(CONFIG_KUP4X)
 
@@ -1584,7 +1594,7 @@ int ide_device_present(int dev)
 static void
 output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
-#if defined(CONFIG_HMI10) || defined(CONFIG_CPC45)
+#if defined(CONFIG_CPC45)
        uchar   *dbuf;
        volatile uchar  *pbuf_even;
        volatile uchar  *pbuf_odd;
@@ -1616,7 +1626,7 @@ output_data_shorts(int dev, ushort *sect_buf, int shorts)
 static void
 input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
-#if defined(CONFIG_HMI10) || defined(CONFIG_CPC45)
+#if defined(CONFIG_CPC45)
        uchar   *dbuf;
        volatile uchar  *pbuf_even;
        volatile uchar  *pbuf_odd;