Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[safe/jmp/linux-2.6] / drivers / ata / sata_via.c
index 62367fe..08f6549 100644 (file)
 #include <linux/blkdev.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_host.h>
 #include <linux/libata.h>
 
 #define DRV_NAME       "sata_via"
-#define DRV_VERSION    "2.4"
+#define DRV_VERSION    "2.6"
 
 /*
  * vt8251 is different from other sata controllers of VIA.  It has two
@@ -80,6 +82,7 @@ static int vt8251_scr_write(struct ata_link *link, unsigned int scr, u32 val);
 static void svia_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
 static void svia_noop_freeze(struct ata_port *ap);
 static int vt6420_prereset(struct ata_link *link, unsigned long deadline);
+static void vt6420_bmdma_start(struct ata_queued_cmd *qc);
 static int vt6421_pata_cable_detect(struct ata_port *ap);
 static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
 static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
@@ -92,6 +95,7 @@ static const struct pci_device_id svia_pci_tbl[] = {
        { PCI_VDEVICE(VIA, 0x5372), vt6420 },
        { PCI_VDEVICE(VIA, 0x7372), vt6420 },
        { PCI_VDEVICE(VIA, 0x5287), vt8251 }, /* 2 sata chnls (Master/Slave) */
+       { PCI_VDEVICE(VIA, 0x9000), vt8251 },
 
        { }     /* terminate list */
 };
@@ -120,6 +124,7 @@ static struct ata_port_operations vt6420_sata_ops = {
        .inherits               = &svia_base_ops,
        .freeze                 = svia_noop_freeze,
        .prereset               = vt6420_prereset,
+       .bmdma_start            = vt6420_bmdma_start,
 };
 
 static struct ata_port_operations vt6421_pata_ops = {
@@ -144,24 +149,24 @@ static struct ata_port_operations vt8251_ops = {
 
 static const struct ata_port_info vt6420_port_info = {
        .flags          = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
-       .pio_mask       = 0x1f,
-       .mwdma_mask     = 0x07,
+       .pio_mask       = ATA_PIO4,
+       .mwdma_mask     = ATA_MWDMA2,
        .udma_mask      = ATA_UDMA6,
        .port_ops       = &vt6420_sata_ops,
 };
 
 static struct ata_port_info vt6421_sport_info = {
        .flags          = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
-       .pio_mask       = 0x1f,
-       .mwdma_mask     = 0x07,
+       .pio_mask       = ATA_PIO4,
+       .mwdma_mask     = ATA_MWDMA2,
        .udma_mask      = ATA_UDMA6,
        .port_ops       = &vt6421_sata_ops,
 };
 
 static struct ata_port_info vt6421_pport_info = {
        .flags          = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY,
-       .pio_mask       = 0x1f,
-       .mwdma_mask     = 0,
+       .pio_mask       = ATA_PIO4,
+       /* No MWDMA */
        .udma_mask      = ATA_UDMA6,
        .port_ops       = &vt6421_pata_ops,
 };
@@ -169,8 +174,8 @@ static struct ata_port_info vt6421_pport_info = {
 static struct ata_port_info vt8251_port_info = {
        .flags          = ATA_FLAG_SATA | ATA_FLAG_SLAVE_POSS |
                          ATA_FLAG_NO_LEGACY,
-       .pio_mask       = 0x1f,
-       .mwdma_mask     = 0x07,
+       .pio_mask       = ATA_PIO4,
+       .mwdma_mask     = ATA_MWDMA2,
        .udma_mask      = ATA_UDMA6,
        .port_ops       = &vt8251_ops,
 };
@@ -376,6 +381,17 @@ static int vt6420_prereset(struct ata_link *link, unsigned long deadline)
        return 0;
 }
 
+static void vt6420_bmdma_start(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       if ((qc->tf.command == ATA_CMD_PACKET) &&
+           (qc->scsicmd->sc_data_direction == DMA_TO_DEVICE)) {
+               /* Prevents corruption on some ATAPI burners */
+               ata_sff_pause(ap);
+       }
+       ata_bmdma_start(qc);
+}
+
 static int vt6421_pata_cable_detect(struct ata_port *ap)
 {
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -391,14 +407,16 @@ static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
 {
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
        static const u8 pio_bits[] = { 0xA8, 0x65, 0x65, 0x31, 0x20 };
-       pci_write_config_byte(pdev, PATA_PIO_TIMING, pio_bits[adev->pio_mode - XFER_PIO_0]);
+       pci_write_config_byte(pdev, PATA_PIO_TIMING - adev->devno,
+                             pio_bits[adev->pio_mode - XFER_PIO_0]);
 }
 
 static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
 {
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
        static const u8 udma_bits[] = { 0xEE, 0xE8, 0xE6, 0xE4, 0xE2, 0xE1, 0xE0, 0xE0 };
-       pci_write_config_byte(pdev, PATA_UDMA_TIMING, udma_bits[adev->dma_mode - XFER_UDMA_0]);
+       pci_write_config_byte(pdev, PATA_UDMA_TIMING - adev->devno,
+                             udma_bits[adev->dma_mode - XFER_UDMA_0]);
 }
 
 static const unsigned int svia_bar_sizes[] = {
@@ -564,7 +582,7 @@ static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        static int printed_version;
        unsigned int i;
        int rc;
-       struct ata_host *host;
+       struct ata_host *host = NULL;
        int board_id = (int) ent->driver_data;
        const unsigned *bar_sizes;
 
@@ -602,8 +620,10 @@ static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                rc = vt8251_prepare_host(pdev, &host);
                break;
        default:
-               return -EINVAL;
+               rc = -EINVAL;
        }
+       if (rc)
+               return rc;
 
        svia_configure(pdev);