ide: move ide_rate_filter() calls to the upper layer (take 2)
[cascardo/linux.git] / drivers / ide / pci / sis5513.c
index 4457c9d..fed582b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * linux/drivers/ide/pci/sis5513.c     Version 0.20    Mar 4, 2007
+ * linux/drivers/ide/pci/sis5513.c     Version 0.26    Jul 7, 2007
  *
  * Copyright (C) 1999-2000     Andre Hedrick <andre@linux-ide.org>
  * Copyright (C) 2002          Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
@@ -521,7 +521,7 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
 
 static int sis5513_tune_drive(ide_drive_t *drive, u8 pio)
 {
-       pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
+       pio = ide_get_best_pio_mode(drive, pio, 4);
        config_art_rwp_pio(drive, pio);
        return ide_config_drive_speed(drive, XFER_PIO_0 + pio);
 }
@@ -531,15 +531,12 @@ static void sis5513_tuneproc(ide_drive_t *drive, u8 pio)
        (void)sis5513_tune_drive(drive, pio);
 }
 
-static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed)
+static int sis5513_tune_chipset(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = hwif->pci_dev;
-
-       u8 drive_pci, reg, speed;
        u32 regdw;
-
-       speed = ide_rate_filter(drive, xferspeed);
+       u8 drive_pci, reg;
 
        /* See config_art_rwp_pio for drive pci config registers */
        drive_pci = 0x40;
@@ -582,9 +579,6 @@ static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed)
                                        regdw |= (unsigned long)cycle_time_value[ATA_133][speed-XFER_UDMA_0] << 4;
                                        regdw |= (unsigned long)cvs_time_value[ATA_133][speed-XFER_UDMA_0] << 8;
                                } else {
-                               /* if ATA133 disable, we should not set speed above UDMA5 */
-                                       if (speed > XFER_UDMA_5)
-                                               speed = XFER_UDMA_5;
                                        regdw |= (unsigned long)cycle_time_value[ATA_100][speed-XFER_UDMA_0] << 4;
                                        regdw |= (unsigned long)cvs_time_value[ATA_100][speed-XFER_UDMA_0] << 8;
                                }
@@ -640,6 +634,20 @@ static int sis5513_config_xfer_rate(ide_drive_t *drive)
        return -1;
 }
 
+static u8 sis5513_ata133_udma_filter(ide_drive_t *drive)
+{
+       struct pci_dev *dev = drive->hwif->pci_dev;
+       int drive_pci;
+       u32 reg54 = 0, regdw = 0;
+
+       pci_read_config_dword(dev, 0x54, &reg54);
+       drive_pci = ((reg54 & 0x40000000) ? 0x70 : 0x40) + drive->dn * 4;
+       pci_read_config_dword(dev, drive_pci, &regdw);
+
+       /* if ATA133 disable, we should not set speed above UDMA5 */
+       return (regdw & 0x08) ? ATA_UDMA6 : ATA_UDMA5;
+}
+
 /* Chip detection and general config */
 static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
 {
@@ -659,9 +667,7 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
 
                /* Special case for SiS630 : 630S/ET is ATA_100a */
                if (SiSHostChipInfo[i].host_id == PCI_DEVICE_ID_SI_630) {
-                       u8 hostrev;
-                       pci_read_config_byte(host, PCI_REVISION_ID, &hostrev);
-                       if (hostrev >= 0x30)
+                       if (host->revision >= 0x30)
                                chipset_family = ATA_100a;
                }
                pci_dev_put(host);
@@ -702,7 +708,6 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
                        u16 trueid;
                        u8 prefctl;
                        u8 idecfg;
-                       u8 sbrev;
 
                        pci_read_config_byte(dev, 0x4a, &idecfg);
                        pci_write_config_byte(dev, 0x4a, idecfg | 0x10);
@@ -712,11 +717,10 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
                        if (trueid == 0x5517) { /* SiS 961/961B */
 
                                lpc_bridge = pci_get_slot(dev->bus, 0x10); /* Bus 0, Dev 2, Fn 0 */
-                               pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev);
                                pci_read_config_byte(dev, 0x49, &prefctl);
                                pci_dev_put(lpc_bridge);
 
-                               if (sbrev == 0x10 && (prefctl & 0x80)) {
+                               if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
                                        printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n");
                                        chipset_family = ATA_133a;
                                } else {
@@ -796,10 +800,34 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
        return 0;
 }
 
+struct sis_laptop {
+       u16 device;
+       u16 subvendor;
+       u16 subdevice;
+};
+
+static const struct sis_laptop sis_laptop[] = {
+       /* devid, subvendor, subdev */
+       { 0x5513, 0x1043, 0x1107 },     /* ASUS A6K */
+       { 0x5513, 0x1734, 0x105f },     /* FSC Amilo A1630 */
+       /* end marker */
+       { 0, }
+};
+
 static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
 {
+       struct pci_dev *pdev = hwif->pci_dev;
+       const struct sis_laptop *lap = &sis_laptop[0];
        u8 ata66 = 0;
 
+       while (lap->device) {
+               if (lap->device == pdev->device &&
+                   lap->subvendor == pdev->subsystem_vendor &&
+                   lap->subdevice == pdev->subsystem_device)
+                       return ATA_CBL_PATA40_SHORT;
+               lap++;
+       }
+
        if (chipset_family >= ATA_133) {
                u16 regw = 0;
                u16 reg_addr = hwif->channel ? 0x52: 0x50;
@@ -827,6 +855,9 @@ static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
        hwif->tuneproc = &sis5513_tuneproc;
        hwif->speedproc = &sis5513_tune_chipset;
 
+       if (chipset_family >= ATA_133)
+               hwif->udma_filter = sis5513_ata133_udma_filter;
+
        if (!(hwif->dma_base)) {
                hwif->drives[0].autotune = 1;
                hwif->drives[1].autotune = 1;
@@ -859,10 +890,10 @@ static ide_pci_device_t sis5513_chipset __devinitdata = {
        .name           = "SIS5513",
        .init_chipset   = init_chipset_sis5513,
        .init_hwif      = init_hwif_sis5513,
-       .channels       = 2,
        .autodma        = NOAUTODMA,
        .enablebits     = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
        .bootable       = ON_BOARD,
+       .pio_mask       = ATA_PIO4,
 };
 
 static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id)