ahci: add HFLAG_YES_FBS and apply it to 88SE9128
[linux-2.6.git] / drivers / ata / pata_serverworks.c
index df68806..86dd714 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * pata_serverworks.c  - Serverworks PATA for new ATA layer
  *                       (C) 2005 Red Hat Inc
- *                       Alan Cox <alan@redhat.com>
+ *                       (C) 2010 Bartlomiej Zolnierkiewicz
  *
  * based upon
  *
@@ -41,7 +41,7 @@
 #include <linux/libata.h>
 
 #define DRV_NAME "pata_serverworks"
-#define DRV_VERSION "0.4.2"
+#define DRV_VERSION "0.4.3"
 
 #define SVWKS_CSB5_REVISION_NEW        0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
 #define SVWKS_CSB6_REVISION    0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
@@ -102,7 +102,7 @@ static int osb4_cable(struct ata_port *ap) {
 }
 
 /**
- *     csb4_cable      -       CSB5/6 cable detect
+ *     csb_cable       -       CSB5/6 cable detect
  *     @ap: ATA port to check
  *
  *     Serverworks default arrangement is to use the drive side detection
@@ -110,7 +110,7 @@ static int osb4_cable(struct ata_port *ap) {
  */
 
 static int csb_cable(struct ata_port *ap) {
-       return ATA_CBL_PATA80;
+       return ATA_CBL_PATA_UNK;
 }
 
 struct sv_cable_table {
@@ -139,7 +139,6 @@ static struct sv_cable_table cable_detect[] = {
 /**
  *     serverworks_cable_detect        -       cable detection
  *     @ap: ATA port
- *     @deadline: deadline jiffies for the operation
  *
  *     Perform cable detection according to the device and subvendor
  *     identifications
@@ -199,7 +198,7 @@ static unsigned long serverworks_osb4_filter(struct ata_device *adev, unsigned l
 {
        if (adev->class == ATA_DEV_ATA)
                mask &= ~ATA_MASK_UDMA;
-       return ata_pci_default_filter(adev, mask);
+       return mask;
 }
 
 
@@ -219,19 +218,18 @@ static unsigned long serverworks_csb_filter(struct ata_device *adev, unsigned lo
 
        /* Disk, UDMA */
        if (adev->class != ATA_DEV_ATA)
-               return ata_pci_default_filter(adev, mask);
+               return mask;
 
        /* Actually do need to check */
        ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
 
        for (i = 0; (p = csb_bad_ata100[i]) != NULL; i++) {
                if (!strcmp(p, model_num))
-                       mask &= ~(0x1F << ATA_SHIFT_UDMA);
+                       mask &= ~(0xE0 << ATA_SHIFT_UDMA);
        }
-       return ata_pci_default_filter(adev, mask);
+       return mask;
 }
 
-
 /**
  *     serverworks_set_piomode -       set initial PIO mode data
  *     @ap: ATA interface
@@ -243,7 +241,7 @@ static unsigned long serverworks_csb_filter(struct ata_device *adev, unsigned lo
 static void serverworks_set_piomode(struct ata_port *ap, struct ata_device *adev)
 {
        static const u8 pio_mode[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
-       int offset = 1 + (2 * ap->port_no) - adev->devno;
+       int offset = 1 + 2 * ap->port_no - adev->devno;
        int devbits = (2 * ap->port_no + adev->devno) * 4;
        u16 csb5_pio;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -256,7 +254,7 @@ static void serverworks_set_piomode(struct ata_port *ap, struct ata_device *adev
        if (serverworks_is_csb(pdev)) {
                pci_read_config_word(pdev, 0x4A, &csb5_pio);
                csb5_pio &= ~(0x0F << devbits);
-               pci_write_config_byte(pdev, 0x4A, csb5_pio | (pio << devbits));
+               pci_write_config_word(pdev, 0x4A, csb5_pio | (pio << devbits));
        }
 }
 
@@ -274,115 +272,45 @@ static void serverworks_set_dmamode(struct ata_port *ap, struct ata_device *adev
 {
        static const u8 dma_mode[] = { 0x77, 0x21, 0x20 };
        int offset = 1 + 2 * ap->port_no - adev->devno;
-       int devbits = (2 * ap->port_no + adev->devno);
+       int devbits = 2 * ap->port_no + adev->devno;
        u8 ultra;
        u8 ultra_cfg;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 
        pci_read_config_byte(pdev, 0x54, &ultra_cfg);
+       pci_read_config_byte(pdev, 0x56 + ap->port_no, &ultra);
+       ultra &= ~(0x0F << (adev->devno * 4));
 
        if (adev->dma_mode >= XFER_UDMA_0) {
                pci_write_config_byte(pdev, 0x44 + offset,  0x20);
 
-               pci_read_config_byte(pdev, 0x56 + ap->port_no, &ultra);
-               ultra &= ~(0x0F << (ap->port_no * 4));
                ultra |= (adev->dma_mode - XFER_UDMA_0)
-                                       << (ap->port_no * 4);
-               pci_write_config_byte(pdev, 0x56 + ap->port_no, ultra);
-
+                                       << (adev->devno * 4);
                ultra_cfg |=  (1 << devbits);
        } else {
                pci_write_config_byte(pdev, 0x44 + offset,
                        dma_mode[adev->dma_mode - XFER_MW_DMA_0]);
                ultra_cfg &= ~(1 << devbits);
        }
+       pci_write_config_byte(pdev, 0x56 + ap->port_no, ultra);
        pci_write_config_byte(pdev, 0x54, ultra_cfg);
 }
 
 static struct scsi_host_template serverworks_sht = {
-       .module                 = THIS_MODULE,
-       .name                   = DRV_NAME,
-       .ioctl                  = ata_scsi_ioctl,
-       .queuecommand           = ata_scsi_queuecmd,
-       .can_queue              = ATA_DEF_QUEUE,
-       .this_id                = ATA_SHT_THIS_ID,
-       .sg_tablesize           = LIBATA_MAX_PRD,
-       .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
-       .emulated               = ATA_SHT_EMULATED,
-       .use_clustering         = ATA_SHT_USE_CLUSTERING,
-       .proc_name              = DRV_NAME,
-       .dma_boundary           = ATA_DMA_BOUNDARY,
-       .slave_configure        = ata_scsi_slave_config,
-       .slave_destroy          = ata_scsi_slave_destroy,
-       .bios_param             = ata_std_bios_param,
+       ATA_BMDMA_SHT(DRV_NAME),
 };
 
 static struct ata_port_operations serverworks_osb4_port_ops = {
+       .inherits       = &ata_bmdma_port_ops,
+       .cable_detect   = serverworks_cable_detect,
+       .mode_filter    = serverworks_osb4_filter,
        .set_piomode    = serverworks_set_piomode,
        .set_dmamode    = serverworks_set_dmamode,
-       .mode_filter    = serverworks_osb4_filter,
-
-       .tf_load        = ata_tf_load,
-       .tf_read        = ata_tf_read,
-       .check_status   = ata_check_status,
-       .exec_command   = ata_exec_command,
-       .dev_select     = ata_std_dev_select,
-
-       .freeze         = ata_bmdma_freeze,
-       .thaw           = ata_bmdma_thaw,
-       .error_handler  = ata_bmdma_error_handler,
-       .post_internal_cmd = ata_bmdma_post_internal_cmd,
-       .cable_detect   = serverworks_cable_detect,
-
-       .bmdma_setup    = ata_bmdma_setup,
-       .bmdma_start    = ata_bmdma_start,
-       .bmdma_stop     = ata_bmdma_stop,
-       .bmdma_status   = ata_bmdma_status,
-
-       .qc_prep        = ata_qc_prep,
-       .qc_issue       = ata_qc_issue_prot,
-
-       .data_xfer      = ata_data_xfer,
-
-       .irq_handler    = ata_interrupt,
-       .irq_clear      = ata_bmdma_irq_clear,
-       .irq_on         = ata_irq_on,
-
-       .port_start     = ata_sff_port_start,
 };
 
 static struct ata_port_operations serverworks_csb_port_ops = {
-       .set_piomode    = serverworks_set_piomode,
-       .set_dmamode    = serverworks_set_dmamode,
+       .inherits       = &serverworks_osb4_port_ops,
        .mode_filter    = serverworks_csb_filter,
-
-       .tf_load        = ata_tf_load,
-       .tf_read        = ata_tf_read,
-       .check_status   = ata_check_status,
-       .exec_command   = ata_exec_command,
-       .dev_select     = ata_std_dev_select,
-
-       .freeze         = ata_bmdma_freeze,
-       .thaw           = ata_bmdma_thaw,
-       .error_handler  = ata_bmdma_error_handler,
-       .post_internal_cmd = ata_bmdma_post_internal_cmd,
-       .cable_detect   = serverworks_cable_detect,
-
-       .bmdma_setup    = ata_bmdma_setup,
-       .bmdma_start    = ata_bmdma_start,
-       .bmdma_stop     = ata_bmdma_stop,
-       .bmdma_status   = ata_bmdma_status,
-
-       .qc_prep        = ata_qc_prep,
-       .qc_issue       = ata_qc_issue_prot,
-
-       .data_xfer      = ata_data_xfer,
-
-       .irq_handler    = ata_interrupt,
-       .irq_clear      = ata_bmdma_irq_clear,
-       .irq_on         = ata_irq_on,
-
-       .port_start     = ata_sff_port_start,
 };
 
 static int serverworks_fixup_osb4(struct pci_dev *pdev)
@@ -400,7 +328,7 @@ static int serverworks_fixup_osb4(struct pci_dev *pdev)
                pci_dev_put(isa_dev);
                return 0;
        }
-       printk(KERN_WARNING "ata_serverworks: Unable to find bridge.\n");
+       printk(KERN_WARNING DRV_NAME ": Unable to find bridge.\n");
        return -ENODEV;
 }
 
@@ -470,36 +398,37 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
 {
        static const struct ata_port_info info[4] = {
                { /* OSB4 */
-                       .sht = &serverworks_sht,
                        .flags = ATA_FLAG_SLAVE_POSS,
-                       .pio_mask = 0x1f,
-                       .mwdma_mask = 0x07,
-                       .udma_mask = 0x07,
+                       .pio_mask = ATA_PIO4,
+                       .mwdma_mask = ATA_MWDMA2,
+                       .udma_mask = ATA_UDMA2,
                        .port_ops = &serverworks_osb4_port_ops
                }, { /* OSB4 no UDMA */
-                       .sht = &serverworks_sht,
                        .flags = ATA_FLAG_SLAVE_POSS,
-                       .pio_mask = 0x1f,
-                       .mwdma_mask = 0x07,
-                       .udma_mask = 0x00,
+                       .pio_mask = ATA_PIO4,
+                       .mwdma_mask = ATA_MWDMA2,
+                       /* No UDMA */
                        .port_ops = &serverworks_osb4_port_ops
                }, { /* CSB5 */
-                       .sht = &serverworks_sht,
                        .flags = ATA_FLAG_SLAVE_POSS,
-                       .pio_mask = 0x1f,
-                       .mwdma_mask = 0x07,
+                       .pio_mask = ATA_PIO4,
+                       .mwdma_mask = ATA_MWDMA2,
                        .udma_mask = ATA_UDMA4,
                        .port_ops = &serverworks_csb_port_ops
                }, { /* CSB5 - later revisions*/
-                       .sht = &serverworks_sht,
                        .flags = ATA_FLAG_SLAVE_POSS,
-                       .pio_mask = 0x1f,
-                       .mwdma_mask = 0x07,
+                       .pio_mask = ATA_PIO4,
+                       .mwdma_mask = ATA_MWDMA2,
                        .udma_mask = ATA_UDMA5,
                        .port_ops = &serverworks_csb_port_ops
                }
        };
        const struct ata_port_info *ppi[] = { &info[id->driver_data], NULL };
+       int rc;
+
+       rc = pcim_enable_device(pdev);
+       if (rc)
+               return rc;
 
        /* Force master latency timer to 64 PCI clocks */
        pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40);
@@ -529,24 +458,30 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
                serverworks_fixup_ht1000(pdev);
 
        if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
-               ata_pci_clear_simplex(pdev);
+               ata_pci_bmdma_clear_simplex(pdev);
 
-       return ata_pci_init_one(pdev, ppi);
+       return ata_pci_bmdma_init_one(pdev, ppi, &serverworks_sht, NULL, 0);
 }
 
 #ifdef CONFIG_PM
 static int serverworks_reinit_one(struct pci_dev *pdev)
 {
+       struct ata_host *host = dev_get_drvdata(&pdev->dev);
+       int rc;
+
+       rc = ata_pci_device_do_resume(pdev);
+       if (rc)
+               return rc;
+
        /* Force master latency timer to 64 PCI clocks */
        pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40);
 
-       switch (pdev->device)
-       {
+       switch (pdev->device) {
                case PCI_DEVICE_ID_SERVERWORKS_OSB4IDE:
                        serverworks_fixup_osb4(pdev);
                        break;
                case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
-                       ata_pci_clear_simplex(pdev);
+                       ata_pci_bmdma_clear_simplex(pdev);
                        /* fall through */
                case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
                case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
@@ -556,7 +491,9 @@ static int serverworks_reinit_one(struct pci_dev *pdev)
                        serverworks_fixup_ht1000(pdev);
                        break;
        }
-       return ata_pci_device_resume(pdev);
+
+       ata_host_resume(host);
+       return 0;
 }
 #endif