pata_atiixp: update port enabledness test handling
[safe/jmp/linux-2.6] / drivers / ata / pata_amd.c
index 644702c..63719ab 100644 (file)
@@ -1,7 +1,6 @@
 /*
  * pata_amd.c  - AMD PATA for new ATA layer
  *                       (C) 2005-2006 Red Hat Inc
- *                       Alan Cox <alan@redhat.com>
  *
  *  Based on pata-sil680. Errata information is taken from data sheets
  *  and the amd74xx.c driver by Vojtech Pavlik. Nvidia SATA devices are
@@ -25,7 +24,7 @@
 #include <linux/libata.h>
 
 #define DRV_NAME "pata_amd"
-#define DRV_VERSION "0.3.10"
+#define DRV_VERSION "0.3.11"
 
 /**
  *     timing_setup            -       shared timing computation and load
@@ -56,7 +55,9 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
        u8 t;
 
        T = 1000000000 / amd_clock;
-       UT = T / min_t(int, max_t(int, clock, 1), 2);
+       UT = T;
+       if (clock >= 2)
+               UT = T / 2;
 
        if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {
                dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed);
@@ -82,32 +83,32 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
 
        /* Configure the address set up timing */
        pci_read_config_byte(pdev, offset + 0x0C, &t);
-       t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(at.setup, 1, 4) - 1) << ((3 - dn) << 1));
+       t = (t & ~(3 << ((3 - dn) << 1))) | ((clamp_val(at.setup, 1, 4) - 1) << ((3 - dn) << 1));
        pci_write_config_byte(pdev, offset + 0x0C , t);
 
        /* Configure the 8bit I/O timing */
        pci_write_config_byte(pdev, offset + 0x0E + (1 - (dn >> 1)),
-               ((FIT(at.act8b, 1, 16) - 1) << 4) | (FIT(at.rec8b, 1, 16) - 1));
+               ((clamp_val(at.act8b, 1, 16) - 1) << 4) | (clamp_val(at.rec8b, 1, 16) - 1));
 
        /* Drive timing */
        pci_write_config_byte(pdev, offset + 0x08 + (3 - dn),
-               ((FIT(at.active, 1, 16) - 1) << 4) | (FIT(at.recover, 1, 16) - 1));
+               ((clamp_val(at.active, 1, 16) - 1) << 4) | (clamp_val(at.recover, 1, 16) - 1));
 
        switch (clock) {
                case 1:
-               t = at.udma ? (0xc0 | (FIT(at.udma, 2, 5) - 2)) : 0x03;
+               t = at.udma ? (0xc0 | (clamp_val(at.udma, 2, 5) - 2)) : 0x03;
                break;
 
                case 2:
-               t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 2, 10)]) : 0x03;
+               t = at.udma ? (0xc0 | amd_cyc2udma[clamp_val(at.udma, 2, 10)]) : 0x03;
                break;
 
                case 3:
-               t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 10)]) : 0x03;
+               t = at.udma ? (0xc0 | amd_cyc2udma[clamp_val(at.udma, 1, 10)]) : 0x03;
                break;
 
                case 4:
-               t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 15)]) : 0x03;
+               t = at.udma ? (0xc0 | amd_cyc2udma[clamp_val(at.udma, 1, 15)]) : 0x03;
                break;
 
                default:
@@ -141,13 +142,7 @@ static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
        if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
                return -ENOENT;
 
-       return ata_std_prereset(link, deadline);
-}
-
-static void amd_error_handler(struct ata_port *ap)
-{
-       ata_bmdma_drive_eh(ap, amd_pre_reset, ata_std_softreset, NULL,
-                          ata_std_postreset);
+       return ata_sff_prereset(link, deadline);
 }
 
 static int amd_cable_detect(struct ata_port *ap)
@@ -297,14 +292,7 @@ static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
        if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
                return -ENOENT;
 
-       return ata_std_prereset(link, deadline);
-}
-
-static void nv_error_handler(struct ata_port *ap)
-{
-       ata_bmdma_drive_eh(ap, nv_pre_reset,
-                              ata_std_softreset, NULL,
-                              ata_std_postreset);
+       return ata_sff_prereset(link, deadline);
 }
 
 /**
@@ -357,8 +345,8 @@ static struct scsi_host_template amd_sht = {
 };
 
 static const struct ata_port_operations amd_base_port_ops = {
-       .inherits       = &ata_bmdma_port_ops,
-       .error_handler  = amd_error_handler,
+       .inherits       = &ata_bmdma32_port_ops,
+       .prereset       = amd_pre_reset,
 };
 
 static struct ata_port_operations amd33_port_ops = {
@@ -393,7 +381,7 @@ static const struct ata_port_operations nv_base_port_ops = {
        .inherits       = &ata_bmdma_port_ops,
        .cable_detect   = ata_cable_ignore,
        .mode_filter    = nv_mode_filter,
-       .error_handler  = nv_error_handler,
+       .prereset       = nv_pre_reset,
        .host_stop      = nv_host_stop,
 };
 
@@ -483,10 +471,10 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
                        .port_ops = &amd100_port_ops
                }
        };
-       struct ata_port_info pi;
-       const struct ata_port_info *ppi[] = { &pi, NULL };
+       const struct ata_port_info *ppi[] = { NULL, NULL };
        static int printed_version;
        int type = id->driver_data;
+       void *hpriv = NULL;
        u8 fifo;
        int rc;
 
@@ -511,10 +499,10 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
        /*
         * Okay, type is determined now.  Apply type-specific workarounds.
         */
-       pi = info[type];
+       ppi[0] = &info[type];
 
        if (type < 3)
-               ata_pci_clear_simplex(pdev);
+               ata_pci_bmdma_clear_simplex(pdev);
 
        /* Check for AMD7411 */
        if (type == 3)
@@ -530,11 +518,11 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
                u32 udma;
 
                pci_read_config_dword(pdev, 0x60, &udma);
-               pi.private_data = (void *)(unsigned long)udma;
+               hpriv = (void *)(unsigned long)udma;
        }
 
        /* And fire it up */
-       return ata_pci_init_one(pdev, ppi, &amd_sht);
+       return ata_pci_sff_init_one(pdev, ppi, &amd_sht, hpriv);
 }
 
 #ifdef CONFIG_PM
@@ -557,7 +545,7 @@ static int amd_reinit_one(struct pci_dev *pdev)
                        pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
                if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
                    pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
-                       ata_pci_clear_simplex(pdev);
+                       ata_pci_bmdma_clear_simplex(pdev);
        }
 
        ata_host_resume(host);