Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[sfrench/cifs-2.6.git] / drivers / ide / pci / amd74xx.c
index a4336995a4108675d4a2f73a9af6dcde1838be04..84ed30cdb324de5d4928700807f8db1198140228 100644 (file)
@@ -1,10 +1,11 @@
 /*
- * Version 2.13
+ * Version 2.20
  *
  * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04
  * IDE driver for Linux.
  *
  * Copyright (c) 2000-2002 Vojtech Pavlik
+ * Copyright (c) 2007 Bartlomiej Zolnierkiewicz
  *
  * Based on the work of:
  *      Andre Hedrick
 #define AMD_ADDRESS_SETUP      (0x0c + amd_config->base)
 #define AMD_UDMA_TIMING                (0x10 + amd_config->base)
 
-#define AMD_UDMA               0x07
-#define AMD_UDMA_33            0x01
-#define AMD_UDMA_66            0x02
-#define AMD_UDMA_100           0x03
-#define AMD_UDMA_133           0x04
 #define AMD_CHECK_SWDMA                0x08
 #define AMD_BAD_SWDMA          0x10
 #define AMD_BAD_FIFO           0x20
 
 static struct amd_ide_chip {
        unsigned short id;
-       unsigned long base;
-       unsigned char flags;
+       u8 base;
+       u8 udma_mask;
+       u8 flags;
 } amd_ide_chips[] = {
-       { PCI_DEVICE_ID_AMD_COBRA_7401,         0x40, AMD_UDMA_33 | AMD_BAD_SWDMA },
-       { PCI_DEVICE_ID_AMD_VIPER_7409,         0x40, AMD_UDMA_66 | AMD_CHECK_SWDMA },
-       { PCI_DEVICE_ID_AMD_VIPER_7411,         0x40, AMD_UDMA_100 | AMD_BAD_FIFO },
-       { PCI_DEVICE_ID_AMD_OPUS_7441,          0x40, AMD_UDMA_100 },
-       { PCI_DEVICE_ID_AMD_8111_IDE,           0x40, AMD_UDMA_133 | AMD_CHECK_SERENADE },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_IDE,      0x50, AMD_UDMA_100 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE,     0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE,    0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,   0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE,     0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE,    0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,   0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,  0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE,        0x50, AMD_UDMA_133 },
-       { PCI_DEVICE_ID_AMD_CS5536_IDE,                 0x40, AMD_UDMA_100 },
+       { PCI_DEVICE_ID_AMD_COBRA_7401,          0x40, ATA_UDMA2, AMD_BAD_SWDMA },
+       { PCI_DEVICE_ID_AMD_VIPER_7409,          0x40, ATA_UDMA4, AMD_CHECK_SWDMA },
+       { PCI_DEVICE_ID_AMD_VIPER_7411,          0x40, ATA_UDMA5, AMD_BAD_FIFO },
+       { PCI_DEVICE_ID_AMD_OPUS_7441,           0x40, ATA_UDMA5, },
+       { PCI_DEVICE_ID_AMD_8111_IDE,            0x40, ATA_UDMA6, AMD_CHECK_SERENADE },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_IDE,       0x50, ATA_UDMA5, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE,      0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE,     0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,    0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE,      0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE,     0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,    0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,   0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE, 0x50, ATA_UDMA6, },
+       { PCI_DEVICE_ID_AMD_CS5536_IDE,          0x40, ATA_UDMA5, },
        { 0 }
 };
 
@@ -85,14 +84,14 @@ static ide_pci_device_t *amd_chipset;
 static unsigned int amd_80w;
 static unsigned int amd_clock;
 
-static char *amd_dma[] = { "MWDMA16", "UDMA33", "UDMA66", "UDMA100", "UDMA133" };
+static char *amd_dma[] = { "16", "25", "33", "44", "66", "100", "133" };
 static unsigned char amd_cyc2udma[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7 };
 
 /*
  * AMD /proc entry.
  */
 
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_IDE_PROC_FS
 
 #include <linux/stat.h>
 #include <linux/proc_fs.h>
@@ -126,7 +125,7 @@ static int amd74xx_get_info(char *buffer, char **addr, off_t offset, int count)
 
        pci_read_config_byte(dev, PCI_REVISION_ID, &t);
        amd_print("Revision:                           IDE %#x", t);
-       amd_print("Highest DMA rate:                   %s", amd_dma[amd_config->flags & AMD_UDMA]);
+       amd_print("Highest DMA rate:                   UDMA%s", amd_dma[fls(amd_config->udma_mask) - 1]);
 
        amd_print("BM-DMA base:                        %#lx", amd_base);
        amd_print("PCI clock:                          %d.%dMHz", amd_clock / 1000, amd_clock / 100 % 10);
@@ -219,12 +218,12 @@ static void amd_set_speed(struct pci_dev *dev, unsigned char dn, struct ide_timi
        pci_write_config_byte(dev, AMD_DRIVE_TIMING + (3 - dn),
                ((FIT(timing->active, 1, 16) - 1) << 4) | (FIT(timing->recover, 1, 16) - 1));
 
-       switch (amd_config->flags & AMD_UDMA) {
-               case AMD_UDMA_33:  t = timing->udma ? (0xc0 | (FIT(timing->udma, 2, 5) - 2)) : 0x03; break;
-               case AMD_UDMA_66:  t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 2, 10)]) : 0x03; break;
-               case AMD_UDMA_100: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 10)]) : 0x03; break;
-               case AMD_UDMA_133: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 15)]) : 0x03; break;
-               default: return;
+       switch (amd_config->udma_mask) {
+       case ATA_UDMA2: t = timing->udma ? (0xc0 | (FIT(timing->udma, 2, 5) - 2)) : 0x03; break;
+       case ATA_UDMA4: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 2, 10)]) : 0x03; break;
+       case ATA_UDMA5: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 10)]) : 0x03; break;
+       case ATA_UDMA6: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 15)]) : 0x03; break;
+       default: return;
        }
 
        pci_write_config_byte(dev, AMD_UDMA_TIMING + (3 - dn), t);
@@ -242,13 +241,11 @@ static int amd_set_drive(ide_drive_t *drive, u8 speed)
        struct ide_timing t, p;
        int T, UT;
 
-       if (speed != XFER_PIO_SLOW && speed != drive->current_speed)
-               if (ide_config_drive_speed(drive, speed))
-                       printk(KERN_WARNING "ide%d: Drive %d didn't accept speed setting. Oh, well.\n",
-                               drive->dn >> 1, drive->dn & 1);
+       if (speed != XFER_PIO_SLOW)
+               ide_config_drive_speed(drive, speed);
 
        T = 1000000000 / amd_clock;
-       UT = T / min_t(int, max_t(int, amd_config->flags & AMD_UDMA, 1), 2);
+       UT = (amd_config->udma_mask == ATA_UDMA2) ? T : (T / 2);
 
        ide_timing_compute(drive, speed, &t, T, UT);
 
@@ -277,35 +274,26 @@ static int amd_set_drive(ide_drive_t *drive, u8 speed)
 static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio)
 {
        if (pio == 255) {
-               amd_set_drive(drive, ide_find_best_mode(drive, XFER_PIO | XFER_EPIO));
+               amd_set_drive(drive, ide_find_best_pio_mode(drive));
                return;
        }
 
        amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5));
 }
 
-/*
- * amd74xx_dmaproc() is a callback from upper layers that can do
- * a lot, but we use it for DMA/PIO tuning only, delegating everything
- * else to the default ide_dmaproc().
- */
-
 static int amd74xx_ide_dma_check(ide_drive_t *drive)
 {
-       int w80 = HWIF(drive)->udma_four;
+       u8 speed = ide_max_dma_mode(drive);
 
-       u8 speed = ide_find_best_mode(drive,
-               XFER_PIO | XFER_EPIO | XFER_MWDMA | XFER_UDMA |
-               ((amd_config->flags & AMD_BAD_SWDMA) ? 0 : XFER_SWDMA) |
-               (w80 && (amd_config->flags & AMD_UDMA) >= AMD_UDMA_66 ? XFER_UDMA_66 : 0) |
-               (w80 && (amd_config->flags & AMD_UDMA) >= AMD_UDMA_100 ? XFER_UDMA_100 : 0) |
-               (w80 && (amd_config->flags & AMD_UDMA) >= AMD_UDMA_133 ? XFER_UDMA_133 : 0));
+       if (speed == 0)
+               speed = ide_find_best_pio_mode(drive);
 
        amd_set_drive(drive, speed);
 
        if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
-               return HWIF(drive)->ide_dma_on(drive);
-       return HWIF(drive)->ide_dma_off_quietly(drive);
+               return 0;
+
+       return -1;
 }
 
 /*
@@ -333,10 +321,10 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
  * Check 80-wire cable presence.
  */
 
-       switch (amd_config->flags & AMD_UDMA) {
+       switch (amd_config->udma_mask) {
 
-               case AMD_UDMA_133:
-               case AMD_UDMA_100:
+               case ATA_UDMA6:
+               case ATA_UDMA5:
                        pci_read_config_byte(dev, AMD_CABLE_DETECT, &t);
                        pci_read_config_dword(dev, AMD_UDMA_TIMING, &u);
                        amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0);
@@ -348,7 +336,7 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
                                }
                        break;
 
-               case AMD_UDMA_66:
+               case ATA_UDMA4:
                        /* no host side cable detection */
                        amd_80w = 0x03;
                        break;
@@ -369,7 +357,7 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
        if ((amd_config->flags & AMD_CHECK_SERENADE) &&
                dev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
                dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
-                       amd_config->flags = AMD_UDMA_100;
+                       amd_config->udma_mask = ATA_UDMA5;
 
 /*
  * Determine the system bus clock.
@@ -394,21 +382,22 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
  */
 
        pci_read_config_byte(dev, PCI_REVISION_ID, &t);
-       printk(KERN_INFO "%s: %s (rev %02x) %s controller\n",
-               amd_chipset->name, pci_name(dev), t, amd_dma[amd_config->flags & AMD_UDMA]);
+       printk(KERN_INFO "%s: %s (rev %02x) UDMA%s controller\n",
+               amd_chipset->name, pci_name(dev), t,
+               amd_dma[fls(amd_config->udma_mask) - 1]);
 
 /*
  * Register /proc/ide/amd74xx entry
  */
 
-#if defined(DISPLAY_AMD_TIMINGS) && defined(CONFIG_PROC_FS)
+#if defined(DISPLAY_AMD_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
         if (!amd74xx_proc) {
                 amd_base = pci_resource_start(dev, 4);
                 bmide_dev = dev;
                ide_pci_create_host_proc("amd74xx", amd74xx_get_info);
                 amd74xx_proc = 1;
         }
-#endif /* DISPLAY_AMD_TIMINGS && CONFIG_PROC_FS */
+#endif /* DISPLAY_AMD_TIMINGS && CONFIG_IDE_PROC_FS */
 
        return dev->irq;
 }
@@ -436,12 +425,19 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
                return;
 
         hwif->atapi_dma = 1;
-        hwif->ultra_mask = 0x7f;
-        hwif->mwdma_mask = 0x07;
-        hwif->swdma_mask = 0x07;
 
-       if (!hwif->udma_four)
-               hwif->udma_four = (amd_80w >> hwif->channel) & 1;
+       hwif->ultra_mask = amd_config->udma_mask;
+       hwif->mwdma_mask = 0x07;
+       if ((amd_config->flags & AMD_BAD_SWDMA) == 0)
+               hwif->swdma_mask = 0x07;
+
+       if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
+               if ((amd_80w >> hwif->channel) & 1)
+                       hwif->cbl = ATA_CBL_PATA80;
+               else
+                       hwif->cbl = ATA_CBL_PATA40;
+       }
+
         hwif->ide_dma_check = &amd74xx_ide_dma_check;
         if (!noautodma)
                 hwif->autodma = 1;
@@ -493,7 +489,9 @@ static ide_pci_device_t amd74xx_chipsets[] __devinitdata = {
        /* 17 */ DECLARE_NV_DEV("NFORCE-MCP61"),
        /* 18 */ DECLARE_NV_DEV("NFORCE-MCP65"),
        /* 19 */ DECLARE_NV_DEV("NFORCE-MCP67"),
-       /* 20 */ DECLARE_AMD_DEV("AMD5536"),
+       /* 20 */ DECLARE_NV_DEV("NFORCE-MCP73"),
+       /* 21 */ DECLARE_NV_DEV("NFORCE-MCP77"),
+       /* 22 */ DECLARE_AMD_DEV("AMD5536"),
 };
 
 static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id)
@@ -533,7 +531,9 @@ static struct pci_device_id amd74xx_pci_tbl[] = {
        { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 17 },
        { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 18 },
        { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 19 },
-       { PCI_VENDOR_ID_AMD,    PCI_DEVICE_ID_AMD_CS5536_IDE,           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 20 },
+       { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 20 },
+       { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 21 },
+       { PCI_VENDOR_ID_AMD,    PCI_DEVICE_ID_AMD_CS5536_IDE,           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 22 },
        { 0, },
 };
 MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);