Merge branches 'release', 'asus', 'sony-laptop' and 'thinkpad' into release
[pandora-kernel.git] / drivers / ide / pci / it8213.c
index 52e403f..e3427ea 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
 
-#include <asm/io.h>
-
 /**
  *     it8213_set_pio_mode     -       set host controller for PIO mode
  *     @drive: drive
@@ -28,7 +25,7 @@
 static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
        ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = hwif->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(hwif->dev);
        int is_slave            = drive->dn & 1;
        int master_port         = 0x40;
        int slave_port          = 0x44;
@@ -85,7 +82,7 @@ static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
 static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = hwif->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(hwif->dev);
        u8 maslave              = 0x40;
        int a_speed             = 3 << (drive->dn * 4);
        int u_flag              = 1 << drive->dn;
@@ -101,24 +98,11 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
        pci_read_config_byte(dev, 0x54, &reg54);
        pci_read_config_byte(dev, 0x55, &reg55);
 
-       switch(speed) {
-               case XFER_UDMA_6:
-               case XFER_UDMA_4:
-               case XFER_UDMA_2:       u_speed = 2 << (drive->dn * 4); break;
-               case XFER_UDMA_5:
-               case XFER_UDMA_3:
-               case XFER_UDMA_1:       u_speed = 1 << (drive->dn * 4); break;
-               case XFER_UDMA_0:       u_speed = 0 << (drive->dn * 4); break;
-                       break;
-               case XFER_MW_DMA_2:
-               case XFER_MW_DMA_1:
-               case XFER_SW_DMA_2:
-                       break;
-               default:
-                       return;
-       }
-
        if (speed >= XFER_UDMA_0) {
+               u8 udma = speed - XFER_UDMA_0;
+
+               u_speed = min_t(u8, 2 - (udma & 1), udma) << (drive->dn * 4);
+
                if (!(reg48 & u_flag))
                        pci_write_config_byte(dev, 0x48, reg48 | u_flag);
                if (speed >= XFER_UDMA_5) {
@@ -156,6 +140,16 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
        }
 }
 
+static u8 __devinit it8213_cable_detect(ide_hwif_t *hwif)
+{
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       u8 reg42h = 0;
+
+       pci_read_config_byte(dev, 0x42, &reg42h);
+
+       return (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+}
+
 /**
  *     init_hwif_it8213        -       set up hwif structs
  *     @hwif: interface to set up
@@ -165,18 +159,10 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
 static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
 {
-       u8 reg42h = 0;
-
        hwif->set_dma_mode = &it8213_set_dma_mode;
        hwif->set_pio_mode = &it8213_set_pio_mode;
 
-       if (!hwif->dma_base)
-               return;
-
-       pci_read_config_byte(hwif->pci_dev, 0x42, &reg42h);
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
+       hwif->cable_detect = it8213_cable_detect;
 }
 
 
@@ -193,7 +179,7 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
                .udma_mask      = ATA_UDMA6,            \
        }
 
-static struct ide_port_info it8213_chipsets[] __devinitdata = {
+static const struct ide_port_info it8213_chipsets[] __devinitdata = {
        /* 0 */ DECLARE_ITE_DEV("IT8213"),
 };