sata_mv: fix loop with last port
[safe/jmp/linux-2.6] / drivers / ata / pata_qdi.c
index c2f87da..9f308ed 100644 (file)
@@ -26,7 +26,7 @@
 #include <linux/platform_device.h>
 
 #define DRV_NAME "pata_qdi"
-#define DRV_VERSION "0.3.0"
+#define DRV_VERSION "0.3.1"
 
 #define NR_HOST 4      /* Two 6580s */
 
@@ -124,31 +124,33 @@ static unsigned int qdi_qc_issue_prot(struct ata_queued_cmd *qc)
        return ata_qc_issue_prot(qc);
 }
 
-static void qdi_data_xfer(struct ata_device *adev, unsigned char *buf, unsigned int buflen, int write_data)
+static unsigned int qdi_data_xfer(struct ata_device *dev, unsigned char *buf,
+                                 unsigned int buflen, int rw)
 {
-       struct ata_port *ap = adev->ap;
-       int slop = buflen & 3;
+       if (ata_id_has_dword_io(dev->id)) {
+               struct ata_port *ap = dev->link->ap;
+               int slop = buflen & 3;
 
-       if (ata_id_has_dword_io(adev->id)) {
-               if (write_data)
-                       iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
-               else
+               if (rw == READ)
                        ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
+               else
+                       iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
 
                if (unlikely(slop)) {
                        u32 pad;
-                       if (write_data) {
-                               memcpy(&pad, buf + buflen - slop, slop);
-                               pad = le32_to_cpu(pad);
-                               iowrite32(pad, ap->ioaddr.data_addr);
-                       } else {
-                               pad = ioread32(ap->ioaddr.data_addr);
-                               pad = cpu_to_le32(pad);
+                       if (rw == READ) {
+                               pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
                                memcpy(buf + buflen - slop, &pad, slop);
+                       } else {
+                               memcpy(&pad, buf + buflen - slop, slop);
+                               iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
                        }
+                       buflen += 4 - slop;
                }
        } else
-               ata_data_xfer(adev, buf, buflen, write_data);
+               buflen = ata_data_xfer(dev, buf, buflen, rw);
+
+       return buflen;
 }
 
 static struct scsi_host_template qdi_sht = {
@@ -170,7 +172,6 @@ static struct scsi_host_template qdi_sht = {
 };
 
 static struct ata_port_operations qdi6500_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = qdi6500_set_piomode,
 
        .tf_load        = ata_tf_load,
@@ -183,22 +184,20 @@ static struct ata_port_operations qdi6500_port_ops = {
        .thaw           = ata_bmdma_thaw,
        .error_handler  = ata_bmdma_error_handler,
        .post_internal_cmd = ata_bmdma_post_internal_cmd,
+       .cable_detect   = ata_cable_40wire,
 
        .qc_prep        = ata_qc_prep,
        .qc_issue       = qdi_qc_issue_prot,
 
        .data_xfer      = qdi_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_start     = ata_sff_port_start,
 };
 
 static struct ata_port_operations qdi6580_port_ops = {
-       .port_disable   = ata_port_disable,
        .set_piomode    = qdi6580_set_piomode,
 
        .tf_load        = ata_tf_load,
@@ -211,18 +210,17 @@ static struct ata_port_operations qdi6580_port_ops = {
        .thaw           = ata_bmdma_thaw,
        .error_handler  = ata_bmdma_error_handler,
        .post_internal_cmd = ata_bmdma_post_internal_cmd,
+       .cable_detect   = ata_cable_40wire,
 
        .qc_prep        = ata_qc_prep,
        .qc_issue       = qdi_qc_issue_prot,
 
        .data_xfer      = qdi_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_start     = ata_sff_port_start,
 };
 
 /**
@@ -238,8 +236,10 @@ static struct ata_port_operations qdi6580_port_ops = {
 
 static __init int qdi_init_one(unsigned long port, int type, unsigned long io, int irq, int fast)
 {
-       struct ata_probe_ent ae;
+       unsigned long ctl = io + 0x206;
        struct platform_device *pdev;
+       struct ata_host *host;
+       struct ata_port *ap;
        void __iomem *io_addr, *ctl_addr;
        int ret;
 
@@ -253,38 +253,37 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
 
        ret = -ENOMEM;
        io_addr = devm_ioport_map(&pdev->dev, io, 8);
-       ctl_addr = devm_ioport_map(&pdev->dev, io + 0x206, 1);
+       ctl_addr = devm_ioport_map(&pdev->dev, ctl, 1);
        if (!io_addr || !ctl_addr)
                goto fail;
 
-       memset(&ae, 0, sizeof(struct ata_probe_ent));
-       INIT_LIST_HEAD(&ae.node);
-       ae.dev = &pdev->dev;
+       ret = -ENOMEM;
+       host = ata_host_alloc(&pdev->dev, 1);
+       if (!host)
+               goto fail;
+       ap = host->ports[0];
 
        if (type == 6580) {
-               ae.port_ops = &qdi6580_port_ops;
-               ae.pio_mask = 0x1F;
-               ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
+               ap->ops = &qdi6580_port_ops;
+               ap->pio_mask = 0x1F;
+               ap->flags |= ATA_FLAG_SLAVE_POSS;
        } else {
-               ae.port_ops = &qdi6500_port_ops;
-               ae.pio_mask = 0x07;     /* Actually PIO3 !IORDY is possible */
-               ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
-                               ATA_FLAG_NO_IORDY;
+               ap->ops = &qdi6500_port_ops;
+               ap->pio_mask = 0x07;    /* Actually PIO3 !IORDY is possible */
+               ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
        }
 
-       ae.sht = &qdi_sht;
-       ae.n_ports = 1;
-       ae.irq = irq;
-       ae.irq_flags = 0;
-       ae.port[0].cmd_addr = io_addr;
-       ae.port[0].altstatus_addr = ctl_addr;
-       ae.port[0].ctl_addr = ctl_addr;
-       ata_std_ports(&ae.port[0]);
+       ap->ioaddr.cmd_addr = io_addr;
+       ap->ioaddr.altstatus_addr = ctl_addr;
+       ap->ioaddr.ctl_addr = ctl_addr;
+       ata_std_ports(&ap->ioaddr);
+
+       ata_port_desc(ap, "cmd %lx ctl %lx", io, ctl);
 
        /*
         *      Hook in a private data structure per channel
         */
-       ae.private_data = &qdi_data[nr_qdi_host];
+       ap->private_data = &qdi_data[nr_qdi_host];
 
        qdi_data[nr_qdi_host].timing = port;
        qdi_data[nr_qdi_host].fast = fast;
@@ -292,8 +291,9 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
 
        printk(KERN_INFO DRV_NAME": qd%d at 0x%lx.\n", type, io);
 
-       ret = -ENODEV;
-       if (!ata_device_add(&ae))
+       /* activate */
+       ret = ata_host_activate(host, irq, ata_interrupt, 0, &qdi_sht);
+       if (ret)
                goto fail;
 
        qdi_host[nr_qdi_host++] = dev_get_drvdata(&pdev->dev);
@@ -363,7 +363,8 @@ static __init int qdi_init(void)
                                        release_region(port, 2);
                                        continue;
                                }
-                               ct += qdi_init_one(port, 6500, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04);
+                               if (qdi_init_one(port, 6500, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04) == 0)
+                                       ct++;
                        }
                        if (((r & 0xF0) == 0xA0) || (r & 0xF0) == 0x50) {
                                /* QD6580: dual channel */
@@ -375,11 +376,14 @@ static __init int qdi_init(void)
                                res = inb(port + 3);
                                if (res & 1) {
                                        /* Single channel mode */
-                                       ct += qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04);
+                                       if (qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04) == 0)
+                                               ct++;
                                } else {
                                        /* Dual channel mode */
-                                       ct += qdi_init_one(port, 6580, 0x1F0, 14, r & 0x04);
-                                       ct += qdi_init_one(port + 2, 6580, 0x170, 15, r & 0x04);
+                                       if (qdi_init_one(port, 6580, 0x1F0, 14, r & 0x04) == 0)
+                                               ct++;
+                                       if (qdi_init_one(port + 2, 6580, 0x170, 15, r & 0x04) == 0)
+                                               ct++;
                                }
                        }
                }