]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ata/pata_amd.c
dz.h: remove useless unused module junk
[linux-2.6-omap-h63xx.git] / drivers / ata / pata_amd.c
index b9c44c575ce3f42c5bddf10cf994e788a7432b13..761a66608d7bd9ce7478a7daf4db6e02f8bd3e7a 100644 (file)
@@ -25,7 +25,7 @@
 #include <linux/libata.h>
 
 #define DRV_NAME "pata_amd"
-#define DRV_VERSION "0.3.8"
+#define DRV_VERSION "0.3.10"
 
 /**
  *     timing_setup            -       shared timing computation and load
@@ -115,31 +115,33 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
        }
 
        /* UDMA timing */
-       pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
+       if (at.udma)
+               pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
 }
 
 /**
- *     amd_probe_init          -       perform reset handling
- *     @ap: ATA port
+ *     amd_pre_reset           -       perform reset handling
+ *     @link: ATA link
  *     @deadline: deadline jiffies for the operation
  *
  *     Reset sequence checking enable bits to see which ports are
  *     active.
  */
 
-static int amd_pre_reset(struct ata_port *ap, unsigned long deadline)
+static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
 {
        static const struct pci_bits amd_enable_bits[] = {
                { 0x40, 1, 0x02, 0x02 },
                { 0x40, 1, 0x01, 0x01 }
        };
 
+       struct ata_port *ap = link->ap;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 
        if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
                return -ENOENT;
 
-       return ata_std_prereset(ap, deadline);
+       return ata_std_prereset(link, deadline);
 }
 
 static void amd_error_handler(struct ata_port *ap)
@@ -218,28 +220,85 @@ static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
        timing_setup(ap, adev, 0x40, adev->dma_mode, 4);
 }
 
+/* Both host-side and drive-side detection results are worthless on NV
+ * PATAs.  Ignore them and just follow what BIOS configured.  Both the
+ * current configuration in PCI config reg and ACPI GTM result are
+ * cached during driver attach and are consulted to select transfer
+ * mode.
+ */
+static unsigned long nv_mode_filter(struct ata_device *dev,
+                                   unsigned long xfer_mask)
+{
+       static const unsigned int udma_mask_map[] =
+               { ATA_UDMA2, ATA_UDMA1, ATA_UDMA0, 0,
+                 ATA_UDMA3, ATA_UDMA4, ATA_UDMA5, ATA_UDMA6 };
+       struct ata_port *ap = dev->link->ap;
+       char acpi_str[32] = "";
+       u32 saved_udma, udma;
+       const struct ata_acpi_gtm *gtm;
+       unsigned long bios_limit = 0, acpi_limit = 0, limit;
+
+       /* find out what BIOS configured */
+       udma = saved_udma = (unsigned long)ap->host->private_data;
+
+       if (ap->port_no == 0)
+               udma >>= 16;
+       if (dev->devno == 0)
+               udma >>= 8;
+
+       if ((udma & 0xc0) == 0xc0)
+               bios_limit = ata_pack_xfermask(0, 0, udma_mask_map[udma & 0x7]);
+
+       /* consult ACPI GTM too */
+       gtm = ata_acpi_init_gtm(ap);
+       if (gtm) {
+               acpi_limit = ata_acpi_gtm_xfermask(dev, gtm);
+
+               snprintf(acpi_str, sizeof(acpi_str), " (%u:%u:0x%x)",
+                        gtm->drive[0].dma, gtm->drive[1].dma, gtm->flags);
+       }
+
+       /* be optimistic, EH can take care of things if something goes wrong */
+       limit = bios_limit | acpi_limit;
+
+       /* If PIO or DMA isn't configured at all, don't limit.  Let EH
+        * handle it.
+        */
+       if (!(limit & ATA_MASK_PIO))
+               limit |= ATA_MASK_PIO;
+       if (!(limit & (ATA_MASK_MWDMA | ATA_MASK_UDMA)))
+               limit |= ATA_MASK_MWDMA | ATA_MASK_UDMA;
+
+       ata_port_printk(ap, KERN_DEBUG, "nv_mode_filter: 0x%lx&0x%lx->0x%lx, "
+                       "BIOS=0x%lx (0x%x) ACPI=0x%lx%s\n",
+                       xfer_mask, limit, xfer_mask & limit, bios_limit,
+                       saved_udma, acpi_limit, acpi_str);
+
+       return xfer_mask & limit;
+}
 
 /**
  *     nv_probe_init   -       cable detection
- *     @ap: ATA port
+ *     @lin: ATA link
  *
  *     Perform cable detection. The BIOS stores this in PCI config
  *     space for us.
  */
 
-static int nv_pre_reset(struct ata_port *ap, unsigned long deadline)
+static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
 {
        static const struct pci_bits nv_enable_bits[] = {
                { 0x50, 1, 0x02, 0x02 },
                { 0x50, 1, 0x01, 0x01 }
        };
 
+       struct ata_port *ap = link->ap;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 
        if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
                return -ENOENT;
 
-       return ata_std_prereset(ap, deadline);
+       return ata_std_prereset(link, deadline);
 }
 
 static void nv_error_handler(struct ata_port *ap)
@@ -249,28 +308,6 @@ static void nv_error_handler(struct ata_port *ap)
                               ata_std_postreset);
 }
 
-static int nv_cable_detect(struct ata_port *ap)
-{
-       static const u8 bitmask[2] = {0x03, 0x0C};
-       struct pci_dev *pdev = to_pci_dev(ap->host->dev);
-       u8 ata66;
-       u16 udma;
-       int cbl;
-
-       pci_read_config_byte(pdev, 0x52, &ata66);
-       if (ata66 & bitmask[ap->port_no])
-               cbl = ATA_CBL_PATA80;
-       else
-               cbl = ATA_CBL_PATA40;
-
-       /* We now have to double check because the Nvidia boxes BIOS
-          doesn't always set the cable bits but does set mode bits */
-       pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
-       if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
-               cbl = ATA_CBL_PATA80;
-       return cbl;
-}
-
 /**
  *     nv100_set_piomode       -       set initial PIO mode data
  *     @ap: ATA interface
@@ -308,6 +345,14 @@ static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
        timing_setup(ap, adev, 0x50, adev->dma_mode, 4);
 }
 
+static void nv_host_stop(struct ata_host *host)
+{
+       u32 udma = (unsigned long)host->private_data;
+
+       /* restore PCI config register 0x60 */
+       pci_write_config_dword(to_pci_dev(host->dev), 0x60, udma);
+}
+
 static struct scsi_host_template amd_sht = {
        .module                 = THIS_MODULE,
        .name                   = DRV_NAME,
@@ -327,7 +372,6 @@ static struct scsi_host_template amd_sht = {
 };
 
 static struct ata_port_operations amd33_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = amd33_set_piomode,
        .set_dmamode    = amd33_set_dmamode,
        .mode_filter    = ata_pci_default_filter,
@@ -356,13 +400,11 @@ static struct ata_port_operations amd33_port_ops = {
        .irq_handler    = ata_interrupt,
        .irq_clear      = ata_bmdma_irq_clear,
        .irq_on         = ata_irq_on,
-       .irq_ack        = ata_irq_ack,
 
-       .port_start     = ata_port_start,
+       .port_start     = ata_sff_port_start,
 };
 
 static struct ata_port_operations amd66_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = amd66_set_piomode,
        .set_dmamode    = amd66_set_dmamode,
        .mode_filter    = ata_pci_default_filter,
@@ -391,13 +433,11 @@ static struct ata_port_operations amd66_port_ops = {
        .irq_handler    = ata_interrupt,
        .irq_clear      = ata_bmdma_irq_clear,
        .irq_on         = ata_irq_on,
-       .irq_ack        = ata_irq_ack,
 
-       .port_start     = ata_port_start,
+       .port_start     = ata_sff_port_start,
 };
 
 static struct ata_port_operations amd100_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = amd100_set_piomode,
        .set_dmamode    = amd100_set_dmamode,
        .mode_filter    = ata_pci_default_filter,
@@ -426,13 +466,11 @@ static struct ata_port_operations amd100_port_ops = {
        .irq_handler    = ata_interrupt,
        .irq_clear      = ata_bmdma_irq_clear,
        .irq_on         = ata_irq_on,
-       .irq_ack        = ata_irq_ack,
 
-       .port_start     = ata_port_start,
+       .port_start     = ata_sff_port_start,
 };
 
 static struct ata_port_operations amd133_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = amd133_set_piomode,
        .set_dmamode    = amd133_set_dmamode,
        .mode_filter    = ata_pci_default_filter,
@@ -461,13 +499,11 @@ static struct ata_port_operations amd133_port_ops = {
        .irq_handler    = ata_interrupt,
        .irq_clear      = ata_bmdma_irq_clear,
        .irq_on         = ata_irq_on,
-       .irq_ack        = ata_irq_ack,
 
-       .port_start     = ata_port_start,
+       .port_start     = ata_sff_port_start,
 };
 
 static struct ata_port_operations nv100_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = nv100_set_piomode,
        .set_dmamode    = nv100_set_dmamode,
        .mode_filter    = ata_pci_default_filter,
@@ -481,7 +517,8 @@ static struct ata_port_operations nv100_port_ops = {
        .thaw           = ata_bmdma_thaw,
        .error_handler  = nv_error_handler,
        .post_internal_cmd = ata_bmdma_post_internal_cmd,
-       .cable_detect   = nv_cable_detect,
+       .cable_detect   = ata_cable_ignore,
+       .mode_filter    = nv_mode_filter,
 
        .bmdma_setup    = ata_bmdma_setup,
        .bmdma_start    = ata_bmdma_start,
@@ -496,13 +533,12 @@ static struct ata_port_operations nv100_port_ops = {
        .irq_handler    = ata_interrupt,
        .irq_clear      = ata_bmdma_irq_clear,
        .irq_on         = ata_irq_on,
-       .irq_ack        = ata_irq_ack,
 
-       .port_start     = ata_port_start,
+       .port_start     = ata_sff_port_start,
+       .host_stop      = nv_host_stop,
 };
 
 static struct ata_port_operations nv133_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = nv133_set_piomode,
        .set_dmamode    = nv133_set_dmamode,
        .mode_filter    = ata_pci_default_filter,
@@ -516,7 +552,8 @@ static struct ata_port_operations nv133_port_ops = {
        .thaw           = ata_bmdma_thaw,
        .error_handler  = nv_error_handler,
        .post_internal_cmd = ata_bmdma_post_internal_cmd,
-       .cable_detect   = nv_cable_detect,
+       .cable_detect   = ata_cable_ignore,
+       .mode_filter    = nv_mode_filter,
 
        .bmdma_setup    = ata_bmdma_setup,
        .bmdma_start    = ata_bmdma_start,
@@ -531,9 +568,9 @@ static struct ata_port_operations nv133_port_ops = {
        .irq_handler    = ata_interrupt,
        .irq_clear      = ata_bmdma_irq_clear,
        .irq_on         = ata_irq_on,
-       .irq_ack        = ata_irq_ack,
 
-       .port_start     = ata_port_start,
+       .port_start     = ata_sff_port_start,
+       .host_stop      = nv_host_stop,
 };
 
 static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -620,22 +657,34 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
                        .port_ops = &amd100_port_ops
                }
        };
-       const struct ata_port_info *ppi[] = { NULL, NULL };
+       struct ata_port_info pi;
+       const struct ata_port_info *ppi[] = { &pi, NULL };
        static int printed_version;
        int type = id->driver_data;
-       u8 rev;
        u8 fifo;
 
        if (!printed_version++)
                dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
 
-       pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
        pci_read_config_byte(pdev, 0x41, &fifo);
 
        /* Check for AMD7409 without swdma errata and if found adjust type */
-       if (type == 1 && rev > 0x7)
+       if (type == 1 && pdev->revision > 0x7)
                type = 2;
 
+       /* Serenade ? */
+       if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
+                        pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
+               type = 6;       /* UDMA 100 only */
+
+       /*
+        * Okay, type is determined now.  Apply type-specific workarounds.
+        */
+       pi = info[type];
+
+       if (type < 3)
+               ata_pci_clear_simplex(pdev);
+
        /* Check for AMD7411 */
        if (type == 3)
                /* FIFO is broken */
@@ -643,16 +692,17 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
        else
                pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
 
-       /* Serenade ? */
-       if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
-                        pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
-               type = 6;       /* UDMA 100 only */
+       /* Cable detection on Nvidia chips doesn't work too well,
+        * cache BIOS programmed UDMA mode.
+        */
+       if (type == 7 || type == 8) {
+               u32 udma;
 
-       if (type < 3)
-               ata_pci_clear_simplex(pdev);
+               pci_read_config_dword(pdev, 0x60, &udma);
+               pi.private_data = (void *)(unsigned long)udma;
+       }
 
        /* And fire it up */
-       ppi[0] = &info[type];
        return ata_pci_init_one(pdev, ppi);
 }