ide: add proper PCI PM support (v2)
[safe/jmp/linux-2.6] / drivers / ide / pci / cs5530.c
index 0324a8a..da42fa7 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * linux/drivers/ide/pci/cs5530.c              Version 0.76    Aug 3 2007
- *
  * Copyright (C) 2000                  Andre Hedrick <andre@linux-ide.org>
  * Copyright (C) 2000                  Mark Lord <mlord@pobox.com>
  * Copyright (C) 2007                  Bartlomiej Zolnierkiewicz
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
-#include <linux/hdreg.h>
-#include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
+
 #include <asm/io.h>
-#include <asm/irq.h>
+
+#define DRV_NAME "cs5530"
 
 /*
  * Here are the standard PIO mode 0-4 timings for each "format".
@@ -87,17 +80,19 @@ static void cs5530_set_pio_mode(ide_drive_t *drive, const u8 pio)
 static u8 cs5530_udma_filter(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1];
-       struct hd_driveid *mateid = mate->id;
+       ide_drive_t *mate = ide_get_pair_dev(drive);
+       u16 *mateid = mate->id;
        u8 mask = hwif->ultra_mask;
 
-       if (mate->present == 0)
+       if (mate == NULL)
                goto out;
 
-       if ((mateid->capability & 1) && __ide_dma_bad_drive(mate) == 0) {
-               if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7))
+       if (ata_id_has_dma(mateid) && __ide_dma_bad_drive(mate) == 0) {
+               if ((mateid[ATA_ID_FIELD_VALID] & 4) &&
+                   (mateid[ATA_ID_UDMA_MODES] & 7))
                        goto out;
-               if ((mateid->field_valid & 2) && (mateid->dma_mword & 7))
+               if ((mateid[ATA_ID_FIELD_VALID] & 2) &&
+                   (mateid[ATA_ID_MWDMA_MODES] & 7))
                        mask = 0;
        }
 out:
@@ -116,9 +111,6 @@ static void cs5530_set_dma_mode(ide_drive_t *drive, const u8 mode)
                case XFER_MW_DMA_0:     timings = 0x00077771; break;
                case XFER_MW_DMA_1:     timings = 0x00012121; break;
                case XFER_MW_DMA_2:     timings = 0x00002020; break;
-               default:
-                       BUG();
-                       break;
        }
        basereg = CS5530_BASEREG(drive->hwif);
        reg = inl(basereg + 4);                 /* get drive0 config register */
@@ -138,15 +130,13 @@ static void cs5530_set_dma_mode(ide_drive_t *drive, const u8 mode)
 /**
  *     init_chipset_5530       -       set up 5530 bridge
  *     @dev: PCI device
- *     @name: device name
  *
  *     Initialize the cs5530 bridge for reliable IDE DMA operation.
  */
 
-static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const char *name)
+static unsigned int init_chipset_cs5530(struct pci_dev *dev)
 {
        struct pci_dev *master_0 = NULL, *cs5530_0 = NULL;
-       unsigned long flags;
 
        if (pci_resource_start(dev, 4) == 0)
                return -EFAULT;
@@ -163,17 +153,14 @@ static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const ch
                }
        }
        if (!master_0) {
-               printk(KERN_ERR "%s: unable to locate PCI MASTER function\n", name);
+               printk(KERN_ERR DRV_NAME ": unable to locate PCI MASTER function\n");
                goto out;
        }
        if (!cs5530_0) {
-               printk(KERN_ERR "%s: unable to locate CS5530 LEGACY function\n", name);
+               printk(KERN_ERR DRV_NAME ": unable to locate CS5530 LEGACY function\n");
                goto out;
        }
 
-       spin_lock_irqsave(&ide_lock, flags);
-               /* all CPUs (there should only be one CPU with this chipset) */
-
        /*
         * Enable BusMaster and MemoryWriteAndInvalidate for the cs5530:
         * -->  OR 0x14 into 16-bit PCI COMMAND reg of function 0 of the cs5530
@@ -224,8 +211,6 @@ static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const ch
        pci_write_config_byte(master_0, 0x42, 0x00);
        pci_write_config_byte(master_0, 0x43, 0xc1);
 
-       spin_unlock_irqrestore(&ide_lock, flags);
-
 out:
        pci_dev_put(master_0);
        pci_dev_put(cs5530_0);
@@ -245,32 +230,27 @@ static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
        unsigned long basereg;
        u32 d0_timings;
 
-       hwif->set_pio_mode = &cs5530_set_pio_mode;
-       hwif->set_dma_mode = &cs5530_set_dma_mode;
-
        basereg = CS5530_BASEREG(hwif);
        d0_timings = inl(basereg + 0);
        if (CS5530_BAD_PIO(d0_timings))
                outl(cs5530_pio_timings[(d0_timings >> 31) & 1][0], basereg + 0);
        if (CS5530_BAD_PIO(inl(basereg + 8)))
                outl(cs5530_pio_timings[(d0_timings >> 31) & 1][0], basereg + 8);
-
-       hwif->drives[0].autotune = 1;
-       hwif->drives[1].autotune = 1;
-
-       if (hwif->dma_base == 0)
-               return;
-
-       hwif->udma_filter = cs5530_udma_filter;
 }
 
-static ide_pci_device_t cs5530_chipset __devinitdata = {
-       .name           = "CS5530",
+static const struct ide_port_ops cs5530_port_ops = {
+       .set_pio_mode           = cs5530_set_pio_mode,
+       .set_dma_mode           = cs5530_set_dma_mode,
+       .udma_filter            = cs5530_udma_filter,
+};
+
+static const struct ide_port_info cs5530_chipset __devinitdata = {
+       .name           = DRV_NAME,
        .init_chipset   = init_chipset_cs5530,
        .init_hwif      = init_hwif_cs5530,
+       .port_ops       = &cs5530_port_ops,
        .host_flags     = IDE_HFLAG_SERIALIZE |
-                         IDE_HFLAG_POST_SET_MODE |
-                         IDE_HFLAG_BOOTABLE,
+                         IDE_HFLAG_POST_SET_MODE,
        .pio_mask       = ATA_PIO4,
        .mwdma_mask     = ATA_MWDMA2,
        .udma_mask      = ATA_UDMA2,
@@ -278,7 +258,7 @@ static ide_pci_device_t cs5530_chipset __devinitdata = {
 
 static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
-       return ide_setup_pci_device(dev, &cs5530_chipset);
+       return ide_pci_init_one(dev, &cs5530_chipset, NULL);
 }
 
 static const struct pci_device_id cs5530_pci_tbl[] = {
@@ -291,6 +271,9 @@ static struct pci_driver driver = {
        .name           = "CS5530 IDE",
        .id_table       = cs5530_pci_tbl,
        .probe          = cs5530_init_one,
+       .remove         = ide_pci_remove,
+       .suspend        = ide_pci_suspend,
+       .resume         = ide_pci_resume,
 };
 
 static int __init cs5530_ide_init(void)
@@ -298,7 +281,13 @@ static int __init cs5530_ide_init(void)
        return ide_pci_register_driver(&driver);
 }
 
+static void __exit cs5530_ide_exit(void)
+{
+       pci_unregister_driver(&driver);
+}
+
 module_init(cs5530_ide_init);
+module_exit(cs5530_ide_exit);
 
 MODULE_AUTHOR("Mark Lord");
 MODULE_DESCRIPTION("PCI driver module for Cyrix/NS 5530 IDE");