ata: printk warning fixes
[powerpc.git] / drivers / ata / pata_sil680.c
index 11942fd..6770820 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/libata.h>
 
 #define DRV_NAME "pata_sil680"
-#define DRV_VERSION "0.3.2"
+#define DRV_VERSION "0.4.6"
 
 /**
  *     sil680_selreg           -       return register base
@@ -91,12 +91,6 @@ static int sil680_cable_detect(struct ata_port *ap) {
                return ATA_CBL_PATA40;
 }
 
-static int sil680_pre_reset(struct ata_port *ap)
-{
-       ap->cbl = sil680_cable_detect(ap);
-       return ata_std_prereset(ap);
-}
-
 /**
  *     sil680_bus_reset        -       reset the SIL680 bus
  *     @ap: ATA port to reset
@@ -119,7 +113,7 @@ static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes)
 
 static void sil680_error_handler(struct ata_port *ap)
 {
-       ata_bmdma_drive_eh(ap, sil680_pre_reset, sil680_bus_reset, NULL, ata_std_postreset);
+       ata_bmdma_drive_eh(ap, ata_std_prereset, sil680_bus_reset, NULL, ata_std_postreset);
 }
 
 /**
@@ -135,14 +129,17 @@ static void sil680_error_handler(struct ata_port *ap)
 static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev)
 {
        static u16 speed_p[5] = { 0x328A, 0x2283, 0x1104, 0x10C3, 0x10C1 };
-       static u16 speed_t[5] = { 0x328A, 0x1281, 0x1281, 0x10C3, 0x10C1 };
+       static u16 speed_t[5] = { 0x328A, 0x2283, 0x1281, 0x10C3, 0x10C1 };
 
        unsigned long tfaddr = sil680_selreg(ap, 0x02);
        unsigned long addr = sil680_seldev(ap, adev, 0x04);
+       unsigned long addr_mask = 0x80 + 4 * ap->port_no;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
        int pio = adev->pio_mode - XFER_PIO_0;
        int lowest_pio = pio;
+       int port_shift = 4 * adev->devno;
        u16 reg;
+       u8 mode;
 
        struct ata_device *pair = ata_dev_pair(adev);
 
@@ -153,10 +150,17 @@ static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev)
        pci_write_config_word(pdev, tfaddr, speed_t[lowest_pio]);
 
        pci_read_config_word(pdev, tfaddr-2, &reg);
+       pci_read_config_byte(pdev, addr_mask, &mode);
+
        reg &= ~0x0200;                 /* Clear IORDY */
-       if (ata_pio_need_iordy(adev))
+       mode &= ~(3 << port_shift);     /* Clear IORDY and DMA bits */
+
+       if (ata_pio_need_iordy(adev)) {
                reg |= 0x0200;          /* Enable IORDY */
+               mode |= 1 << port_shift;
+       }
        pci_write_config_word(pdev, tfaddr-2, reg);
+       pci_write_config_byte(pdev, addr_mask, mode);
 }
 
 /**
@@ -218,7 +222,6 @@ static struct scsi_host_template sil680_sht = {
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
        .sg_tablesize           = LIBATA_MAX_PRD,
-       .max_sectors            = ATA_MAX_SECTORS,
        .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
        .emulated               = ATA_SHT_EMULATED,
        .use_clustering         = ATA_SHT_USE_CLUSTERING,
@@ -227,6 +230,10 @@ static struct scsi_host_template sil680_sht = {
        .slave_configure        = ata_scsi_slave_config,
        .slave_destroy          = ata_scsi_slave_destroy,
        .bios_param             = ata_std_bios_param,
+#ifdef CONFIG_PM
+       .suspend                = ata_scsi_device_suspend,
+       .resume                 = ata_scsi_device_resume,
+#endif
 };
 
 static struct ata_port_operations sil680_port_ops = {
@@ -244,6 +251,7 @@ static struct ata_port_operations sil680_port_ops = {
        .thaw           = ata_bmdma_thaw,
        .error_handler  = sil680_error_handler,
        .post_internal_cmd = ata_bmdma_post_internal_cmd,
+       .cable_detect   = sil680_cable_detect,
 
        .bmdma_setup    = ata_bmdma_setup,
        .bmdma_start    = ata_bmdma_start,
@@ -253,42 +261,30 @@ static struct ata_port_operations sil680_port_ops = {
        .qc_prep        = ata_qc_prep,
        .qc_issue       = ata_qc_issue_prot,
 
-       .data_xfer      = ata_pio_data_xfer,
+       .data_xfer      = ata_data_xfer,
 
        .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_stop      = ata_port_stop,
-       .host_stop      = ata_host_stop
 };
 
-static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
+/**
+ *     sil680_init_chip                -       chip setup
+ *     @pdev: PCI device
+ *
+ *     Perform all the chip setup which must be done both when the device
+ *     is powered up on boot and when we resume in case we resumed from RAM.
+ *     Returns the final clock settings.
+ */
+
+static u8 sil680_init_chip(struct pci_dev *pdev)
 {
-       static struct ata_port_info info = {
-               .sht = &sil680_sht,
-               .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
-               .udma_mask = 0x7f,
-               .port_ops = &sil680_port_ops
-       };
-       static struct ata_port_info info_slow = {
-               .sht = &sil680_sht,
-               .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
-               .udma_mask = 0x3f,
-               .port_ops = &sil680_port_ops
-       };
-       static struct ata_port_info *port_info[2] = {&info, &info};
-       static int printed_version;
        u32 class_rev   = 0;
        u8 tmpbyte      = 0;
 
-       if (!printed_version++)
-               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
-
         pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev);
         class_rev &= 0xff;
         /* FIXME: double check */
@@ -323,8 +319,6 @@ static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
        pci_read_config_byte(pdev,   0x8A, &tmpbyte);
        printk(KERN_INFO "sil680: BA5_EN = %d clock = %02X\n",
                        tmpbyte & 1, tmpbyte & 0x30);
-       if ((tmpbyte & 0x30) == 0)
-               port_info[0] = port_info[1] = &info_slow;
 
        pci_write_config_byte(pdev,  0xA1, 0x72);
        pci_write_config_word(pdev,  0xA2, 0x328A);
@@ -343,11 +337,53 @@ static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
                case 0x20: printk(KERN_INFO "sil680: Using PCI clock.\n");break;
                /* This last case is _NOT_ ok */
                case 0x30: printk(KERN_ERR "sil680: Clock disabled ?\n");
-                       return -EIO;
+       }
+       return tmpbyte & 0x30;
+}
+
+static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+       static struct ata_port_info info = {
+               .sht = &sil680_sht,
+               .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
+               .pio_mask = 0x1f,
+               .mwdma_mask = 0x07,
+               .udma_mask = 0x7f,
+               .port_ops = &sil680_port_ops
+       };
+       static struct ata_port_info info_slow = {
+               .sht = &sil680_sht,
+               .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
+               .pio_mask = 0x1f,
+               .mwdma_mask = 0x07,
+               .udma_mask = 0x3f,
+               .port_ops = &sil680_port_ops
+       };
+       static struct ata_port_info *port_info[2] = {&info, &info};
+       static int printed_version;
+
+       if (!printed_version++)
+               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
+
+       switch(sil680_init_chip(pdev))
+       {
+               case 0:
+                       port_info[0] = port_info[1] = &info_slow;
+                       break;
+               case 0x30:
+                       return -ENODEV;
        }
        return ata_pci_init_one(pdev, port_info, 2);
 }
 
+#ifdef CONFIG_PM
+static int sil680_reinit_one(struct pci_dev *pdev)
+{
+       sil680_init_chip(pdev);
+       return ata_pci_device_resume(pdev);
+}
+#endif
+
 static const struct pci_device_id sil680[] = {
        { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), },
 
@@ -358,7 +394,11 @@ static struct pci_driver sil680_pci_driver = {
        .name           = DRV_NAME,
        .id_table       = sil680,
        .probe          = sil680_init_one,
-       .remove         = ata_pci_remove_one
+       .remove         = ata_pci_remove_one,
+#ifdef CONFIG_PM
+       .suspend        = ata_pci_device_suspend,
+       .resume         = sil680_reinit_one,
+#endif
 };
 
 static int __init sil680_init(void)