]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/ata/ata_piix.c
pata_sis: add mode_filter method for certain sis5513 chipsets
[linux-2.6.git] / drivers / ata / ata_piix.c
index 3aadded05a05233252b61ec7d904a3cbf38cc735..cc431d6bc97fd4c2e91880b553d6a0f9c28753b2 100644 (file)
  *  Hardware documentation available at http://developer.intel.com/
  *
  * Documentation
- *     Publically available from Intel web site. Errata documentation
- * is also publically available. As an aide to anyone hacking on this
+ *     Publicly available from Intel web site. Errata documentation
+ * is also publicly available. As an aide to anyone hacking on this
  * driver the list of errata that are relevant is below, going back to
  * PIIX4. Older device documentation is now a bit tricky to find.
  *
- * The chipsets all follow very much the same design. The orginal Triton
- * series chipsets do _not_ support independant device timings, but this
+ * The chipsets all follow very much the same design. The original Triton
+ * series chipsets do _not_ support independent device timings, but this
  * is fixed in Triton II. With the odd mobile exception the chips then
  * change little except in gaining more modes until SATA arrives. This
- * driver supports only the chips with independant timing (that is those
+ * driver supports only the chips with independent timing (that is those
  * with SITRE and the 0x44 timing register). See pata_oldpiix and pata_mpiix
  * for the early chip drivers.
  *
@@ -90,6 +90,7 @@
 #include <linux/blkdev.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/gfp.h>
 #include <scsi/scsi_host.h>
 #include <linux/libata.h>
 #include <linux/dmi.h>
@@ -112,6 +113,8 @@ enum {
        PIIX_PATA_FLAGS         = ATA_FLAG_SLAVE_POSS,
        PIIX_SATA_FLAGS         = ATA_FLAG_SATA | PIIX_FLAG_CHECKINTR,
 
+       PIIX_FLAG_PIO16         = (1 << 30), /*support 16bit PIO only*/
+
        PIIX_80C_PRI            = (1 << 5) | (1 << 4),
        PIIX_80C_SEC            = (1 << 7) | (1 << 6),
 
@@ -121,7 +124,7 @@ enum {
        P2                      = 2,  /* port 2 */
        P3                      = 3,  /* port 3 */
        IDE                     = -1, /* IDE */
-       NA                      = -2, /* not avaliable */
+       NA                      = -2, /* not available */
        RV                      = -3, /* reserved */
 
        PIIX_AHCI_DEVICE        = 6,
@@ -146,6 +149,7 @@ enum piix_controller_ids {
        ich8m_apple_sata,       /* locks up on second port enable */
        tolapai_sata,
        piix_pata_vmw,                  /* PIIX4 for VMware, spurious DMA_ERR */
+       ich8_sata_snb,
 };
 
 struct piix_map_db {
@@ -173,6 +177,10 @@ static int piix_sidpr_scr_read(struct ata_link *link,
                               unsigned int reg, u32 *val);
 static int piix_sidpr_scr_write(struct ata_link *link,
                                unsigned int reg, u32 val);
+static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
+                             unsigned hints);
+static bool piix_irq_check(struct ata_port *ap);
+static int piix_port_start(struct ata_port *ap);
 #ifdef CONFIG_PM
 static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
 static int piix_pci_device_resume(struct pci_dev *pdev);
@@ -206,6 +214,8 @@ static const struct pci_device_id piix_pci_tbl[] = {
        { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
        /* Intel ICH3 (E7500/1) UDMA 100 */
        { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
+       /* Intel ICH4-L */
+       { 0x8086, 0x24C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
        /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */
        { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
        { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
@@ -224,7 +234,7 @@ static const struct pci_device_id piix_pci_tbl[] = {
        { 0x8086, 0x2850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
 
        /* SATA ports */
-       
+
        /* 82801EB (ICH5) */
        { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
        /* 82801EB (ICH5) */
@@ -291,6 +301,26 @@ static const struct pci_device_id piix_pci_tbl[] = {
        { 0x8086, 0x3b2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
        /* SATA Controller IDE (PCH) */
        { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
+       /* SATA Controller IDE (CPT) */
+       { 0x8086, 0x1c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
+       /* SATA Controller IDE (CPT) */
+       { 0x8086, 0x1c01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
+       /* SATA Controller IDE (CPT) */
+       { 0x8086, 0x1c08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
+       /* SATA Controller IDE (CPT) */
+       { 0x8086, 0x1c09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
+       /* SATA Controller IDE (PBG) */
+       { 0x8086, 0x1d00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
+       /* SATA Controller IDE (PBG) */
+       { 0x8086, 0x1d08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
+       /* SATA Controller IDE (Panther Point) */
+       { 0x8086, 0x1e00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
+       /* SATA Controller IDE (Panther Point) */
+       { 0x8086, 0x1e01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
+       /* SATA Controller IDE (Panther Point) */
+       { 0x8086, 0x1e08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
+       /* SATA Controller IDE (Panther Point) */
+       { 0x8086, 0x1e09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
        { }     /* terminate list */
 };
 
@@ -309,8 +339,14 @@ static struct scsi_host_template piix_sht = {
        ATA_BMDMA_SHT(DRV_NAME),
 };
 
-static struct ata_port_operations piix_pata_ops = {
+static struct ata_port_operations piix_sata_ops = {
        .inherits               = &ata_bmdma32_port_ops,
+       .sff_irq_check          = piix_irq_check,
+       .port_start             = piix_port_start,
+};
+
+static struct ata_port_operations piix_pata_ops = {
+       .inherits               = &piix_sata_ops,
        .cable_detect           = ata_cable_40wire,
        .set_piomode            = piix_set_piomode,
        .set_dmamode            = piix_set_dmamode,
@@ -328,8 +364,14 @@ static struct ata_port_operations ich_pata_ops = {
        .set_dmamode            = ich_set_dmamode,
 };
 
-static struct ata_port_operations piix_sata_ops = {
-       .inherits               = &ata_bmdma_port_ops,
+static struct device_attribute *piix_sidpr_shost_attrs[] = {
+       &dev_attr_link_power_management_policy,
+       NULL
+};
+
+static struct scsi_host_template piix_sidpr_sht = {
+       ATA_BMDMA_SHT(DRV_NAME),
+       .shost_attrs            = piix_sidpr_shost_attrs,
 };
 
 static struct ata_port_operations piix_sidpr_sata_ops = {
@@ -337,6 +379,7 @@ static struct ata_port_operations piix_sidpr_sata_ops = {
        .hardreset              = sata_std_hardreset,
        .scr_read               = piix_sidpr_scr_read,
        .scr_write              = piix_sidpr_scr_write,
+       .set_lpm                = piix_sidpr_set_lpm,
 };
 
 static const struct piix_map_db ich5_map_db = {
@@ -440,6 +483,7 @@ static const struct piix_map_db *piix_map_db_table[] = {
        [ich8_2port_sata]       = &ich8_2port_map_db,
        [ich8m_apple_sata]      = &ich8m_apple_map_db,
        [tolapai_sata]          = &tolapai_map_db,
+       [ich8_sata_snb]         = &ich8_map_db,
 };
 
 static struct ata_port_info piix_port_info[] = {
@@ -568,6 +612,19 @@ static struct ata_port_info piix_port_info[] = {
                .port_ops       = &piix_vmw_ops,
        },
 
+       /*
+        * some Sandybridge chipsets have broken 32 mode up to now,
+        * see https://bugzilla.kernel.org/show_bug.cgi?id=40592
+        */
+       [ich8_sata_snb] =
+       {
+               .flags          = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR | PIIX_FLAG_PIO16,
+               .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA6,
+               .port_ops       = &piix_sata_ops,
+       },
+
 };
 
 static struct pci_bits piix_enable_bits[] = {
@@ -611,6 +668,14 @@ static const struct ich_laptop ich_laptop[] = {
        { 0, }
 };
 
+static int piix_port_start(struct ata_port *ap)
+{
+       if (!(ap->flags & PIIX_FLAG_PIO16))
+               ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
+
+       return ata_bmdma_port_start(ap);
+}
+
 /**
  *     ich_pata_cable_detect - Probe host controller cable detect info
  *     @ap: Port for which cable detect info is desired
@@ -869,10 +934,10 @@ static void do_pata_set_dmamode(struct ata_port *ap, struct ata_device *adev, in
                                (timings[pio][1] << 8);
                }
 
-               if (ap->udma_mask) {
+               if (ap->udma_mask)
                        udma_enable &= ~(1 << devid);
-                       pci_write_config_word(dev, master_port, master_data);
-               }
+
+               pci_write_config_word(dev, master_port, master_data);
        }
        /* Don't scribble on 0x48 if the controller does not support UDMA */
        if (ap->udma_mask)
@@ -962,6 +1027,20 @@ static int piix_sidpr_scr_write(struct ata_link *link,
        return 0;
 }
 
+static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
+                             unsigned hints)
+{
+       return sata_link_scr_lpm(link, policy, false);
+}
+
+static bool piix_irq_check(struct ata_port *ap)
+{
+       if (unlikely(!ap->ioaddr.bmdma_addr))
+               return false;
+
+       return ap->ops->bmdma_status(ap) & ATA_DMA_INTR;
+}
+
 #ifdef CONFIG_PM
 static int piix_broken_suspend(void)
 {
@@ -1173,8 +1252,9 @@ static int piix_pci_device_resume(struct pci_dev *pdev)
                 */
                rc = pci_reenable_device(pdev);
                if (rc)
-                       dev_printk(KERN_ERR, &pdev->dev, "failed to enable "
-                                  "device after resume (%d)\n", rc);
+                       dev_err(&pdev->dev,
+                               "failed to enable device after resume (%d)\n",
+                               rc);
        } else
                rc = ata_pci_device_do_resume(pdev);
 
@@ -1251,9 +1331,11 @@ static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
                        no_piix_dma = 2;
        }
        if (no_piix_dma)
-               dev_printk(KERN_WARNING, &ata_dev->dev, "450NX errata present, disabling IDE DMA.\n");
-       if (no_piix_dma == 2)
-               dev_printk(KERN_WARNING, &ata_dev->dev, "A BIOS update may resolve this.\n");
+               dev_warn(&ata_dev->dev,
+                        "450NX errata present, disabling IDE DMA%s\n",
+                        no_piix_dma == 2 ? " - a BIOS update may resolve this"
+                        : "");
+
        return no_piix_dma;
 }
 
@@ -1286,37 +1368,36 @@ static const int *__devinit piix_init_sata_map(struct pci_dev *pdev,
 
        map = map_db->map[map_value & map_db->mask];
 
-       dev_printk(KERN_INFO, &pdev->dev, "MAP [");
+       dev_info(&pdev->dev, "MAP [");
        for (i = 0; i < 4; i++) {
                switch (map[i]) {
                case RV:
                        invalid_map = 1;
-                       printk(" XX");
+                       pr_cont(" XX");
                        break;
 
                case NA:
-                       printk(" --");
+                       pr_cont(" --");
                        break;
 
                case IDE:
                        WARN_ON((i & 1) || map[i + 1] != IDE);
                        pinfo[i / 2] = piix_port_info[ich_pata_100];
                        i++;
-                       printk(" IDE IDE");
+                       pr_cont(" IDE IDE");
                        break;
 
                default:
-                       printk(" P%d", map[i]);
+                       pr_cont(" P%d", map[i]);
                        if (i & 1)
                                pinfo[i / 2].flags |= ATA_FLAG_SLAVE_POSS;
                        break;
                }
        }
-       printk(" ]\n");
+       pr_cont(" ]\n");
 
        if (invalid_map)
-               dev_printk(KERN_ERR, &pdev->dev,
-                          "invalid MAP value %u\n", map_value);
+               dev_err(&pdev->dev, "invalid MAP value %u\n", map_value);
 
        return map;
 }
@@ -1346,8 +1427,8 @@ static bool piix_no_sidpr(struct ata_host *host)
        if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2920 &&
            pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG &&
            pdev->subsystem_device == 0xb049) {
-               dev_printk(KERN_WARNING, host->dev,
-                          "Samsung DB-P70 detected, disabling SIDPR\n");
+               dev_warn(host->dev,
+                        "Samsung DB-P70 detected, disabling SIDPR\n");
                return true;
        }
 
@@ -1399,8 +1480,8 @@ static int __devinit piix_init_sidpr(struct ata_host *host)
                piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
 
                if ((scontrol & 0xf00) != 0x300) {
-                       dev_printk(KERN_INFO, host->dev, "SCR access via "
-                                  "SIDPR is available but doesn't work\n");
+                       dev_info(host->dev,
+                                "SCR access via SIDPR is available but doesn't work\n");
                        return 0;
                }
        }
@@ -1449,8 +1530,7 @@ static void piix_iocfg_bit18_quirk(struct ata_host *host)
         * affected systems.
         */
        if (hpriv->saved_iocfg & (1 << 18)) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "applying IOCFG bit18 quirk\n");
+               dev_info(&pdev->dev, "applying IOCFG bit18 quirk\n");
                pci_write_config_dword(pdev, PIIX_IOCFG,
                                       hpriv->saved_iocfg & ~(1 << 18));
        }
@@ -1509,18 +1589,16 @@ static bool piix_broken_system_poweroff(struct pci_dev *pdev)
 static int __devinit piix_init_one(struct pci_dev *pdev,
                                   const struct pci_device_id *ent)
 {
-       static int printed_version;
        struct device *dev = &pdev->dev;
        struct ata_port_info port_info[2];
        const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
+       struct scsi_host_template *sht = &piix_sht;
        unsigned long port_flags;
        struct ata_host *host;
        struct piix_host_priv *hpriv;
        int rc;
 
-       if (!printed_version++)
-               dev_printk(KERN_DEBUG, &pdev->dev,
-                          "version " DRV_VERSION "\n");
+       ata_print_version_once(&pdev->dev, DRV_VERSION);
 
        /* no hotplugging support for later devices (FIXME) */
        if (!in_module_init && ent->driver_data >= ich5_sata)
@@ -1570,7 +1648,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
                hpriv->map = piix_init_sata_map(pdev, port_info,
                                        piix_map_db_table[ent->driver_data]);
 
-       rc = ata_pci_sff_prepare_host(pdev, ppi, &host);
+       rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
        if (rc)
                return rc;
        host->private_data = hpriv;
@@ -1581,6 +1659,8 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
                rc = piix_init_sidpr(host);
                if (rc)
                        return rc;
+               if (host->ports[0]->ops == &piix_sidpr_sata_ops)
+                       sht = &piix_sidpr_sht;
        }
 
        /* apply IOCFG bit18 quirk */
@@ -1607,7 +1687,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
        host->flags |= ATA_HOST_PARALLEL_SCAN;
 
        pci_set_master(pdev);
-       return ata_pci_sff_activate_host(host, ata_sff_interrupt, &piix_sht);
+       return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
 }
 
 static void piix_remove_one(struct pci_dev *pdev)