it821x: use ->pio_mode value to determine pair device speed
[safe/jmp/linux-2.6] / drivers / ide / slc90e66.c
index 9aec78d..864ffe0 100644 (file)
@@ -18,9 +18,8 @@
 
 static DEFINE_SPINLOCK(slc90e66_lock);
 
-static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
+static void slc90e66_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = drive->hwif;
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
        int is_slave            = drive->dn & 1;
        int master_port         = hwif->channel ? 0x42 : 0x40;
@@ -29,6 +28,8 @@ static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
        u16 master_data;
        u8 slave_data;
        int control = 0;
+       const u8 pio = drive->pio_mode - XFER_PIO_0;
+
                                     /* ISP  RTC */
        static const u8 timings[][2] = {
                                        { 0, 0 },
@@ -71,14 +72,14 @@ static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
        spin_unlock_irqrestore(&slc90e66_lock, flags);
 }
 
-static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
+static void slc90e66_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = drive->hwif;
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
        u8 maslave              = hwif->channel ? 0x42 : 0x40;
        int sitre = 0, a_speed  = 7 << (drive->dn * 4);
        int u_speed = 0, u_flag = 1 << drive->dn;
        u16                     reg4042, reg44, reg48, reg4a;
+       const u8 speed          = drive->dma_mode;
 
        pci_read_config_word(dev, maslave, &reg4042);
        sitre = (reg4042 & 0x4000) ? 1 : 0;
@@ -91,15 +92,13 @@ static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
                if (!(reg48 & u_flag))
                        pci_write_config_word(dev, 0x48, reg48|u_flag);
-               /* FIXME: (reg4a & a_speed) ? */
-               if ((reg4a & u_speed) != u_speed) {
+               if ((reg4a & a_speed) != u_speed) {
                        pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
                        pci_read_config_word(dev, 0x4a, &reg4a);
                        pci_write_config_word(dev, 0x4a, reg4a|u_speed);
                }
        } else {
                const u8 mwdma_to_pio[] = { 0, 3, 4 };
-               u8 pio;
 
                if (reg48 & u_flag)
                        pci_write_config_word(dev, 0x48, reg48 & ~u_flag);
@@ -107,11 +106,12 @@ static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
                        pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
 
                if (speed >= XFER_MW_DMA_0)
-                       pio = mwdma_to_pio[speed - XFER_MW_DMA_0];
+                       drive->pio_mode =
+                               mwdma_to_pio[speed - XFER_MW_DMA_0] + XFER_PIO_0;
                else
-                       pio = 2; /* only SWDMA2 is allowed */
+                       drive->pio_mode = XFER_PIO_2; /* for SWDMA2 */
 
-               slc90e66_set_pio_mode(drive, pio);
+               slc90e66_set_pio_mode(hwif, drive);
        }
 }