This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / ide / pci / it8212.c
similarity index 66%
rename from drivers/ide/pci/it821x.c
rename to drivers/ide/pci/it8212.c
index 41d8acb..5c83a7a 100644 (file)
@@ -1,6 +1,5 @@
-
 /*
- * linux/drivers/ide/pci/it821x.c              Version 0.09    December 2004
+ * linux/drivers/ide/pci/it8212.c              Version 0.07    November 2004
  *
  * Copyright (C) 2004          Red Hat <alan@redhat.com>
  *
@@ -15,8 +14,7 @@
  *  modes. In pass through mode then it is an IDE controller. In its smart
  *  mode its actually quite a capable hardware raid controller disguised
  *  as an IDE controller. Smart mode only understands DMA read/write and
- *  identify, none of the fancier commands apply. The IT8211 is identical
- *  in other respects but lacks the raid mode.
+ *  identify, none of the fancier commands apply.
  *
  *  Errata:
  *  o  Rev 0x10 also requires master/slave hold the same DMA timings and
@@ -59,7 +57,6 @@
  *  TODO
  *     -       ATAPI UDMA is ok but not MWDMA it seems
  *     -       RAID configuration ioctls
- *     -       Move to libata once it grows up
  */
 
 #include <linux/config.h>
@@ -73,7 +70,7 @@
 
 #include <asm/io.h>
 
-struct it821x_dev
+struct it8212_dev
 {
        unsigned int smart:1,           /* Are we in smart raid mode */
                timing10:1;             /* Rev 0x10 */
@@ -103,17 +100,17 @@ struct it821x_dev
 static int it8212_noraid;
 
 /**
- *     it821x_program  -       program the PIO/MWDMA registers
+ *     it8212_program  -       program the PIO/MWDMA registers
  *     @drive: drive to tune
  *
  *     Program the PIO/MWDMA timing for this channel according to the
  *     current clock.
  */
 
-static void it821x_program(ide_drive_t *drive, u16 timing)
+static void it8212_program(ide_drive_t *drive, u16 timing)
 {
-       ide_hwif_t *hwif        = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int channel = hwif->channel;
        u8 conf;
 
@@ -126,17 +123,17 @@ static void it821x_program(ide_drive_t *drive, u16 timing)
 }
 
 /**
- *     it821x_program_udma     -       program the UDMA registers
+ *     it8212_program_udma     -       program the UDMA registers
  *     @drive: drive to tune
  *
  *     Program the UDMA timing for this drive according to the
  *     current clock.
  */
 
-static void it821x_program_udma(ide_drive_t *drive, u16 timing)
+static void it8212_program_udma(ide_drive_t *drive, u16 timing)
 {
-       ide_hwif_t *hwif        = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int channel = hwif->channel;
        int unit = drive->select.b.unit;
        u8 conf;
@@ -156,17 +153,17 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
 
 
 /**
- *     it821x_clock_strategy
+ *     it8212_clock_strategy
  *     @hwif: hardware interface
  *
  *     Select between the 50 and 66Mhz base clocks to get the best
  *     results for this interface.
  */
 
-static void it821x_clock_strategy(ide_drive_t *drive)
+static void it8212_clock_strategy(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
 
        u8 unit = drive->select.b.unit;
        ide_drive_t *pair = &hwif->drives[1-unit];
@@ -211,28 +208,28 @@ static void it821x_clock_strategy(ide_drive_t *drive)
         *      MWDMA will be dealt with by the dma switcher
         */
        if(pair && itdev->udma[1-unit] != UDMA_OFF) {
-               it821x_program_udma(pair, itdev->udma[1-unit]);
-               it821x_program(pair, itdev->pio[1-unit]);
+               it8212_program_udma(pair, itdev->udma[1-unit]);
+               it8212_program(pair, itdev->pio[1-unit]);
        }
        /*
         *      Reprogram the UDMA/PIO of our drive for the switch.
         *      MWDMA will be dealt with by the dma switcher
         */
        if(itdev->udma[unit] != UDMA_OFF) {
-               it821x_program_udma(drive, itdev->udma[unit]);
-               it821x_program(drive, itdev->pio[unit]);
+               it8212_program_udma(drive, itdev->udma[unit]);
+               it8212_program(drive, itdev->pio[unit]);
        }
 }
 
 /**
- *     it821x_ratemask -       Compute available modes
+ *     it8212_ratemask -       Compute available modes
  *     @drive: IDE drive
  *
  *     Compute the available speeds for the devices on the interface. This
  *     is all modes to ATA133 clipped by drive cable setup.
  */
 
-static u8 it821x_ratemask (ide_drive_t *drive)
+static byte it8212_ratemask (ide_drive_t *drive)
 {
        u8 mode = 4;
        if (!eighty_ninty_three(drive))
@@ -241,7 +238,7 @@ static u8 it821x_ratemask (ide_drive_t *drive)
 }
 
 /**
- *     it821x_tuneproc -       tune a drive
+ *     it8212_tuneproc -       tune a drive
  *     @drive: drive to tune
  *     @mode_wanted: the target operating mode
  *
@@ -253,10 +250,10 @@ static u8 it821x_ratemask (ide_drive_t *drive)
  *     This code is only used in pass through mode.
  */
 
-static void it821x_tuneproc (ide_drive_t *drive, byte mode_wanted)
+static void it8212_tuneproc (ide_drive_t *drive, byte mode_wanted)
 {
-       ide_hwif_t *hwif        = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int unit = drive->select.b.unit;
        
        /* Spec says 89 ref driver uses 88 */
@@ -270,12 +267,12 @@ static void it821x_tuneproc (ide_drive_t *drive, byte mode_wanted)
        itdev->want[unit][1] = pio_want[mode_wanted];
        itdev->want[unit][0] = 1;       /* PIO is lowest priority */
        itdev->pio[unit] = pio[mode_wanted];
-       it821x_clock_strategy(drive);
-       it821x_program(drive, itdev->pio[unit]);
+       it8212_clock_strategy(drive);
+       it8212_program(drive, itdev->pio[unit]);
 }
 
 /**
- *     it821x_tune_mwdma       -       tune a channel for MWDMA
+ *     it8212_tune_mwdma       -       tune a channel for MWDMA
  *     @drive: drive to set up
  *     @mode_wanted: the target operating mode
  *
@@ -285,10 +282,10 @@ static void it821x_tuneproc (ide_drive_t *drive, byte mode_wanted)
  *     the shared MWDMA/PIO timing register.
  */
 
-static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
+static void it8212_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
 {
-       ide_hwif_t *hwif        = drive->hwif;
-       struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct it8212_dev *itdev = (void *)ide_get_hwifdata(hwif);
        int unit = drive->select.b.unit;
        int channel = hwif->channel;
        u8 conf;
@@ -309,13 +306,13 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
                conf |= 1 << (3 + 2 * channel + unit);
        pci_write_config_byte(hwif->pci_dev, 0x50, conf);
 
-       it821x_clock_strategy(drive);
+       it8212_clock_strategy(drive);
        /* FIXME: do we need to program this ? */
-       /* it821x_program(drive, itdev->mwdma[unit]); */
+       /* it8212_program(drive, itdev->mwdma[unit]); */
 }
 
 /**
- *     it821x_tune_udma        -       tune a channel for UDMA
+ *     it8212_tune_udma        -       tune a channel for UDMA
  *     @drive: drive to set up
  *     @mode_wanted: the target operating mode
  *
@@ -323,10 +320,10 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
  *     controller when doing UDMA modes in pass through.
  */
 
-static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
+static void it8212_tune_udma (ide_drive_t *drive, byte mode_wanted)
 {
-       ide_hwif_t *hwif        = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int unit = drive->select.b.unit;
        int channel = hwif->channel;
        u8 conf;
@@ -349,13 +346,13 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
                conf &= ~ (1 << (3 + 2 * channel + unit));
        pci_write_config_byte(hwif->pci_dev, 0x50, conf);
 
-       it821x_clock_strategy(drive);
-       it821x_program_udma(drive, itdev->udma[unit]);
+       it8212_clock_strategy(drive);
+       it8212_program_udma(drive, itdev->udma[unit]);
        
 }
 
 /**
- *     config_it821x_chipset_for_pio   -       set drive timings
+ *     config_it8212_chipset_for_pio   -       set drive timings
  *     @drive: drive to tune
  *     @speed we want
  *
@@ -364,22 +361,22 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
  *     on the cable.
  */
 
-static void config_it821x_chipset_for_pio (ide_drive_t *drive, byte set_speed)
+static void config_it8212_chipset_for_pio (ide_drive_t *drive, byte set_speed)
 {
        u8 unit = drive->select.b.unit;
-       ide_hwif_t *hwif = drive->hwif;
+       ide_hwif_t *hwif = HWIF(drive);
        ide_drive_t *pair = &hwif->drives[1-unit];
-       u8 speed = 0, set_pio   = ide_get_best_pio_mode(drive, 255, 5, NULL);
+       u8 speed = 0, set_pio   = ide_get_best_pio_mode(drive, 4, 5, NULL);
        u8 pair_pio;
        
        /* We have to deal with this mess in pairs */
        if(pair != NULL) {
-               pair_pio = ide_get_best_pio_mode(pair, 255, 5, NULL);
+               pair_pio = ide_get_best_pio_mode(pair, 4, 5, NULL);
                /* Trim PIO to the slowest of the master/slave */
                if(pair_pio < set_pio)
                        set_pio = pair_pio;
        }
-       it821x_tuneproc(drive, set_pio);
+       it8212_tuneproc(drive, set_pio);
        speed = XFER_PIO_0 + set_pio;
        /* XXX - We trim to the lowest of the pair so the other drive
           will always be fine at this point until we do hotplug passthru */
@@ -388,11 +385,16 @@ static void config_it821x_chipset_for_pio (ide_drive_t *drive, byte set_speed)
                (void) ide_config_drive_speed(drive, speed);
 }
 
+static void config_chipset_for_pio (ide_drive_t *drive, byte set_speed)
+{
+       config_it8212_chipset_for_pio(drive, set_speed);
+}
+
 /**
- *     it821x_dma_read -       DMA hook
+ *     it8212_dma_read -       DMA hook
  *     @drive: drive for DMA
  *
- *     The IT821x has a single timing register for MWDMA and for PIO
+ *     The IT8212 has a single timing register for MWDMA and for PIO
  *     operations. As we flip back and forth we have to reload the
  *     clock. In addition the rev 0x10 device only works if the same
  *     timing value is loaded into the master and slave UDMA clock
@@ -401,41 +403,41 @@ static void config_it821x_chipset_for_pio (ide_drive_t *drive, byte set_speed)
  *     FIXME: we could figure out in advance if we need to do reloads
  */
 
-static void it821x_dma_start(ide_drive_t *drive)
+static int it8212_dma_begin(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_hwif_t *hwif = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int unit = drive->select.b.unit;
        if(itdev->mwdma[unit] != MWDMA_OFF)
-               it821x_program(drive, itdev->mwdma[unit]);
+               it8212_program(drive, itdev->mwdma[unit]);
        else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
-               it821x_program_udma(drive, itdev->udma[unit]);
-       ide_dma_start(drive);
+               it8212_program_udma(drive, itdev->udma[unit]);
+       return __ide_dma_begin(drive);
 }
 
 /**
- *     it821x_dma_write        -       DMA hook
+ *     it8212_dma_write        -       DMA hook
  *     @drive: drive for DMA stop
  *
- *     The IT821x has a single timing register for MWDMA and for PIO
+ *     The IT8212 has a single timing register for MWDMA and for PIO
  *     operations. As we flip back and forth we have to reload the
  *     clock.
  */
 
-static int it821x_dma_end(ide_drive_t *drive)
+static int it8212_dma_end(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = drive->hwif;
+       ide_hwif_t *hwif = HWIF(drive);
        int unit = drive->select.b.unit;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int ret = __ide_dma_end(drive);
        if(itdev->mwdma[unit] != MWDMA_OFF)
-               it821x_program(drive, itdev->pio[unit]);
+               it8212_program(drive, itdev->pio[unit]);
        return ret;
 }
 
        
 /**
- *     it821x_tune_chipset     -       set controller timings
+ *     it8212_tune_chipset     -       set controller timings
  *     @drive: Drive to set up
  *     @xferspeed: speed we want to achieve
  *
@@ -444,48 +446,48 @@ static int it821x_dma_end(ide_drive_t *drive)
  *     make the thing work.
  */
 
-static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
+static int it8212_tune_chipset (ide_drive_t *drive, byte xferspeed)
 {
 
-       ide_hwif_t *hwif        = drive->hwif;
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
-       u8 speed                = ide_rate_filter(it821x_ratemask(drive), xferspeed);
-
-       if(!itdev->smart) {
-               switch(speed) {
-                       case XFER_PIO_4:
-                       case XFER_PIO_3:
-                       case XFER_PIO_2:
-                       case XFER_PIO_1:
-                       case XFER_PIO_0:
-                               it821x_tuneproc(drive, (speed - XFER_PIO_0));
-                               break;
-                       /* MWDMA tuning is really hard because our MWDMA and PIO
-                          timings are kept in the same place. We can switch in the
-                          host dma on/off callbacks */
-                       case XFER_MW_DMA_2:
-                       case XFER_MW_DMA_1:
-                       case XFER_MW_DMA_0:
-                               it821x_tune_mwdma(drive, (speed - XFER_MW_DMA_0));
-                               break;
-                       case XFER_UDMA_6:
-                       case XFER_UDMA_5:
-                       case XFER_UDMA_4:
-                       case XFER_UDMA_3:
-                       case XFER_UDMA_2:
-                       case XFER_UDMA_1:
-                       case XFER_UDMA_0:
-                               it821x_tune_udma(drive, (speed - XFER_UDMA_0));
-                               break;
-                       default:
-                               return 1;
-               }
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
+       u8 speed                = ide_rate_filter(it8212_ratemask(drive), xferspeed);
+
+       switch(speed) {
+               case XFER_PIO_4:
+               case XFER_PIO_3:
+               case XFER_PIO_2:
+               case XFER_PIO_1:
+               case XFER_PIO_0:
+                       it8212_tuneproc(drive, (speed - XFER_PIO_0));
+                       break;
+               /* MWDMA tuning is really hard because our MWDMA and PIO
+                  timings are kept in the same place. We can switch in the
+                  host dma on/off callbacks */
+               case XFER_MW_DMA_2:
+               case XFER_MW_DMA_1:
+               case XFER_MW_DMA_0:
+                       if(!itdev->smart)
+                               it8212_tune_mwdma(drive, (speed - XFER_MW_DMA_0));
+                       break;
+               case XFER_UDMA_6:
+               case XFER_UDMA_5:
+               case XFER_UDMA_4:
+               case XFER_UDMA_3:
+               case XFER_UDMA_2:
+               case XFER_UDMA_1:
+               case XFER_UDMA_0:
+                       if(!itdev->smart)
+                               it8212_tune_udma(drive, (speed - XFER_UDMA_0));
+                       break;
+               default:
+                       return 1;
        }
        /*
         *      In smart mode the clocking is done by the host controller
         *      snooping the mode we picked. The rest of it is not our problem
         */
-       return ide_config_drive_speed(drive, speed);
+       return (ide_config_drive_speed(drive, speed));
 }
 
 /**
@@ -497,15 +499,24 @@ static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
 
 static int config_chipset_for_dma (ide_drive_t *drive)
 {
-       u8 speed        = ide_dma_speed(drive, it821x_ratemask(drive));
+       u8 speed        = ide_dma_speed(drive, it8212_ratemask(drive));
+
+       config_chipset_for_pio(drive, !speed);
+
+       if (!speed)
+               return 0;
+
+       if (ide_set_xfer_rate(drive, speed))
+               return 0;
+
+       if (!drive->init_speed)
+               drive->init_speed = speed;
 
-       config_it821x_chipset_for_pio(drive, !speed);
-       it821x_tune_chipset(drive, speed);
        return ide_dma_enable(drive);
 }
 
 /**
- *     it821x_configure_drive_for_dma  -       set up for DMA transfers
+ *     it8212_configure_drive_for_dma  -       set up for DMA transfers
  *     @drive: drive we are going to set up
  *
  *     Set up the drive for DMA, tune the controller and drive as
@@ -514,20 +525,65 @@ static int config_chipset_for_dma (ide_drive_t *drive)
  *     PIO appropriately
  */
 
-static int it821x_config_drive_for_dma (ide_drive_t *drive)
+static int it8212_config_drive_for_dma (ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = drive->hwif;
-
-       if (ide_use_dma(drive)) {
-               if (config_chipset_for_dma(drive))
-                       return hwif->ide_dma_on(drive);
+       ide_hwif_t *hwif        = HWIF(drive);
+       struct hd_driveid *id   = drive->id;
+
+       if ((id->capability & 1) != 0 && drive->autodma) {
+               /* Consult the list of known "bad" drives */
+               if (__ide_dma_bad_drive(drive))
+                       goto fast_ata_pio;
+
+               if ((id->field_valid & 4) && it8212_ratemask(drive)) {
+                       if (id->dma_ultra & hwif->ultra_mask) {
+                               /* Force if Capable UltraDMA */
+                               int dma = config_chipset_for_dma(drive);
+                               if ((id->field_valid & 2) && !dma)
+                                       goto try_dma_modes;
+                       }
+               } else if (id->field_valid & 2) {
+try_dma_modes:
+                       if ((id->dma_mword & hwif->mwdma_mask) ||
+                           (id->dma_1word & hwif->swdma_mask)) {
+                               /* Force if Capable regular DMA modes */
+                               if (!config_chipset_for_dma(drive))
+                                       goto no_dma_set;
+                       }
+               } else if (__ide_dma_good_drive(drive) &&
+                          (id->eide_dma_time < 150)) {
+                       /* Consult the list of known "good" drives */
+                       if (!config_chipset_for_dma(drive))
+                               goto no_dma_set;
+               } else {
+                       goto fast_ata_pio;
+               }
+               return hwif->ide_dma_on(drive);
+       } else if ((id->capability & 8) || (id->field_valid & 2)) {
+fast_ata_pio:
+no_dma_set:
+               config_chipset_for_pio(drive, 1);
+               return hwif->ide_dma_off_quietly(drive);
        }
-       config_it821x_chipset_for_pio(drive, 1);
-       return hwif->ide_dma_off_quietly(drive);
+       /* IORDY not supported */
+       return 0;
 }
 
 /**
- *     ata66_it821x    -       check for 80 pin cable
+ *     init_chipset_it8212     -       set up an ITE device
+ *     @dev: PCI device
+ *     @name: device name
+ *
+ *     PCI chipset level initialize. Nothing to do.
+ */
+
+static unsigned int __devinit init_chipset_it8212(struct pci_dev *dev, const char *name)
+{
+       return 0;
+}
+
+/**
+ *     ata66_it8212    -       check for 80 pin cable
  *     @hwif: interface to check
  *
  *     Check for the presence of an ATA66 capable cable on the
@@ -535,14 +591,14 @@ static int it821x_config_drive_for_dma (ide_drive_t *drive)
  *     the needed logic onboard.
  */
 
-static unsigned int __devinit ata66_it821x(ide_hwif_t *hwif)
+static unsigned int __devinit ata66_it8212(ide_hwif_t *hwif)
 {
        /* The reference driver also only does disk side */
        return 1;
 }
 
 /**
- *     it821x_fixup    -       post init callback
+ *     it8212_fixup    -       post init callback
  *     @hwif: interface
  *
  *     This callback is run after the drives have been probed but
@@ -550,17 +606,17 @@ static unsigned int __devinit ata66_it821x(ide_hwif_t *hwif)
  *     final tuning that is needed, or fixups to work around bugs.
  */
 
-static void __devinit it821x_fixups(ide_hwif_t *hwif)
+static void __devinit it8212_fixups(ide_hwif_t *hwif)
 {
-       struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       struct it8212_dev *itdev = ide_get_hwifdata(hwif);
        int i;
 
        if(!itdev->smart) {
                /*
                 *      If we are in pass through mode then not much
                 *      needs to be done, but we do bother to clear the
-                *      IRQ mask as we may well be in PIO (eg rev 0x10)
-                *      for now and we know unmasking is safe on this chipset.
+                *      IRQ mask in case the drives are PIO (eg rev 0x10)
+                *      for now.
                 */
                for (i = 0; i < 2; i++) {
                        ide_drive_t *drive = &hwif->drives[i];
@@ -588,9 +644,7 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
                
                /* Check for RAID v native */
                if(strstr(id->model, "Integrated Technology Express")) {
-                       /* In raid mode the ident block is slightly buggy
-                          We need to set the bits so that the IDE layer knows
-                          LBA28. LBA48 and DMA ar valid */
+                       /* In raid mode the ident block is slightly buggy */
                        id->capability |= 3;            /* LBA28, DMA */
                        id->command_set_2 |= 0x0400;    /* LBA48 valid */
                        id->cfs_enable_2 |= 0x0400;     /* LBA48 on */
@@ -602,13 +656,6 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
                                if(idbits[129] != 1)
                                        printk("(%dK stripe)", idbits[146]);
                                printk(".\n");
-                       /* Now the core code will have wrongly decided no DMA 
-                          so we need to fix this */
-                       hwif->ide_dma_off_quietly(drive);
-#ifdef CONFIG_IDEDMA_ONLYDISK
-                       if (drive->media == ide_disk)
-#endif
-                               hwif->ide_dma_check(drive);
                } else {
                        /* Non RAID volume. Fixups to stop the core code 
                           doing unsupported things */
@@ -632,7 +679,7 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
 }
 
 /**
- *     init_hwif_it821x        -       set up hwif structs
+ *     init_hwif_it8212        -       set up hwif structs
  *     @hwif: interface to set up
  *
  *     We do the basic set up of the interface structure. The IT8212
@@ -640,18 +687,40 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
  *     ide DMA handlers appropriately
  */
 
-static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
+static void __devinit init_hwif_it8212(ide_hwif_t *hwif)
 {
-       struct it821x_dev *idev = kmalloc(sizeof(struct it821x_dev), GFP_KERNEL);
+       struct it8212_dev *idev = kmalloc(sizeof(struct it8212_dev), GFP_KERNEL);
        u8 conf;
+       static char *mode[2] = { "pass through", "smart" };
 
        if(idev == NULL) {
-               printk(KERN_ERR "it821x: out of memory, falling back to legacy behaviour.\n");
+               printk(KERN_ERR "it8212: out of memory, falling back to legacy behaviour.\n");
                goto fallback;
        }
-       memset(idev, 0, sizeof(struct it821x_dev));
+       memset(idev, 0, sizeof(struct it8212_dev));
        ide_set_hwifdata(hwif, idev);
 
+       /* Force the card into bypass mode if so requested */
+       if (it8212_noraid) {
+               printk(KERN_INFO "it8212: forcing bypass mode.\n");
+
+               /* Reset local CPU, and set BIOS not ready */
+               pci_write_config_byte(hwif->pci_dev, 0x5E, 0x01);
+
+               /* Set to bypass mode, and reset PCI bus */
+               pci_write_config_byte(hwif->pci_dev, 0x50, 0x00);
+
+               pci_write_config_word(hwif->pci_dev, PCI_COMMAND,
+                                     PCI_COMMAND_PARITY | PCI_COMMAND_IO |
+                                     PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
+
+               pci_write_config_word(hwif->pci_dev, 0x40, 0xA0F3);
+
+               pci_write_config_dword(hwif->pci_dev,0x4C, 0x02040204);
+               pci_write_config_byte(hwif->pci_dev, 0x42, 0x36);
+               pci_write_config_byte(hwif->pci_dev, PCI_LATENCY_TIMER, 0);
+       }
+
        pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
        if(conf & 1) {
                idev->smart = 1;
@@ -661,7 +730,11 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
                hwif->rqsize = 256;
        }
 
-       /* Pull the current clocks from 0x50 also */
+       if(hwif->channel == 0)
+               printk(KERN_INFO "it8212: controller in %s mode.\n",
+                       mode[idev->smart]);
+               
+       pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
        if (conf & (1 << (1 + hwif->channel)))
                idev->clock_mode = ATA_50;
        else
@@ -680,21 +753,18 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
                idev->timing10 = 1;
                hwif->atapi_dma = 0;
                if(!idev->smart)
-                       printk(KERN_WARNING "it821x: Revision 0x10, workarounds activated.\n");
+                       printk(KERN_WARNING "it8212: Revision 0x10, workarounds activated.\n");
        }
                
-       hwif->speedproc = &it821x_tune_chipset;
-       hwif->tuneproc  = &it821x_tuneproc;
+       hwif->speedproc = &it8212_tune_chipset;
+       hwif->tuneproc  = &it8212_tuneproc;
        
        /* MWDMA/PIO clock switching for pass through mode */
        if(!idev->smart) {
-               hwif->ide_dma_start = &it821x_dma_start;
-               hwif->ide_dma_end = &it821x_dma_end;
+               hwif->ide_dma_begin = &it8212_dma_begin;
+               hwif->ide_dma_end = &it8212_dma_end;
        }
 
-       hwif->drives[0].autotune = 1;
-       hwif->drives[1].autotune = 1;
-
        if (!hwif->dma_base)
                goto fallback;
 
@@ -702,9 +772,9 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
        hwif->mwdma_mask = 0x07;
        hwif->swdma_mask = 0x07;
 
-       hwif->ide_dma_check = &it821x_config_drive_for_dma;
+       hwif->ide_dma_check = &it8212_config_drive_for_dma;
        if (!(hwif->udma_four))
-               hwif->udma_four = ata66_it821x(hwif);
+               hwif->udma_four = ata66_it8212(hwif);
 
        /*
         *      The BIOS often doesn't set up DMA on this controller
@@ -715,98 +785,67 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
        hwif->drives[0].autodma = hwif->autodma;
        hwif->drives[1].autodma = hwif->autodma;
        return;
+
 fallback:
        hwif->autodma = 0;
+       hwif->drives[0].autotune = 1;
+       hwif->drives[1].autotune = 1;
        return;
 }
 
-static void __devinit it8212_disable_raid(struct pci_dev *dev)
-{
-       /* Reset local CPU, and set BIOS not ready */
-       pci_write_config_byte(dev, 0x5E, 0x01);
-
-       /* Set to bypass mode, and reset PCI bus */
-       pci_write_config_byte(dev, 0x50, 0x00);
-       pci_write_config_word(dev, PCI_COMMAND,
-                             PCI_COMMAND_PARITY | PCI_COMMAND_IO |
-                             PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
-       pci_write_config_word(dev, 0x40, 0xA0F3);
-
-       pci_write_config_dword(dev,0x4C, 0x02040204);
-       pci_write_config_byte(dev, 0x42, 0x36);
-       pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0);
-}
-
-static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const char *name)
-{
-       u8 conf;
-       static char *mode[2] = { "pass through", "smart" };
-
-       /* Force the card into bypass mode if so requested */
-       if (it8212_noraid) {
-               printk(KERN_INFO "it8212: forcing bypass mode.\n");
-               it8212_disable_raid(dev);
-       }
-       pci_read_config_byte(dev, 0x50, &conf);
-       printk(KERN_INFO "it821x: controller in %s mode.\n", mode[conf & 1]);
-       return 0;
-}
-
-
 #define DECLARE_ITE_DEV(name_str)                      \
        {                                               \
                .name           = name_str,             \
-               .init_chipset   = init_chipset_it821x,  \
-               .init_hwif      = init_hwif_it821x,     \
+               .init_chipset   = init_chipset_it8212,  \
+               .init_hwif      = init_hwif_it8212,     \
                .channels       = 2,                    \
                .autodma        = AUTODMA,              \
                .bootable       = ON_BOARD,             \
-               .fixup          = it821x_fixups         \
+               .fixup          = it8212_fixups         \
        }
 
-static ide_pci_device_t it821x_chipsets[] __devinitdata = {
+static ide_pci_device_t it8212_chipsets[] __devinitdata = {
        /* 0 */ DECLARE_ITE_DEV("IT8212"),
 };
 
 /**
- *     it821x_init_one -       pci layer discovery entry
+ *     it8212_init_one -       pci layer discovery entry
  *     @dev: PCI device
  *     @id: ident table entry
  *
- *     Called by the PCI code when it finds an ITE821x controller.
+ *     Called by the PCI code when it finds an ITE8212 controller.
  *     We then use the IDE PCI generic helper to do most of the work.
  */
 
-static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
+static int __devinit it8212_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
-       ide_setup_pci_device(dev, &it821x_chipsets[id->driver_data]);
+       ide_setup_pci_device(dev, &it8212_chipsets[id->driver_data]);
        return 0;
 }
 
-static struct pci_device_id it821x_pci_tbl[] = {
-       { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8211,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+static struct pci_device_id it8212_pci_tbl[] = {
        { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8212,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
        { 0, },
 };
 
-MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
+MODULE_DEVICE_TABLE(pci, it8212_pci_tbl);
 
 static struct pci_driver driver = {
-       .name           = "ITE821x IDE",
-       .id_table       = it821x_pci_tbl,
-       .probe          = it821x_init_one,
+       .name           = "ITE8212 IDE",
+       .id_table       = it8212_pci_tbl,
+       .probe          = it8212_init_one,
 };
 
-static int __init it821x_ide_init(void)
+static int __init it8212_ide_init(void)
 {
        return ide_pci_register_driver(&driver);
 }
 
-module_init(it821x_ide_init);
+module_init(it8212_ide_init);
 
 module_param_named(noraid, it8212_noraid, int, S_IRUGO);
 MODULE_PARM_DESC(it8212_noraid, "Force card into bypass mode");
 
 MODULE_AUTHOR("Alan Cox");
-MODULE_DESCRIPTION("PCI driver module for the ITE 821x");
+MODULE_DESCRIPTION("PCI driver module for the ITE 8212");
 MODULE_LICENSE("GPL");