]> err.no Git - linux-2.6/blobdiff - drivers/ata/pata_bf54x.c
V4L/DVB (7858): video: build fix for drivers/media/video/mt9v022.c
[linux-2.6] / drivers / ata / pata_bf54x.c
index c854e882d4a99fdcd4f07aee84c8504fbe0e3129..9ab89732cf9474f1fa34458717bb9bd7da755d88 100644 (file)
@@ -1103,11 +1103,6 @@ static int bfin_softreset(struct ata_link *link, unsigned int *classes,
        unsigned int devmask = 0, err_mask;
        u8 err;
 
-       if (ata_link_offline(link)) {
-               classes[0] = ATA_DEV_NONE;
-               goto out;
-       }
-
        /* determine if device 0/1 are present */
        if (bfin_devchk(ap, 0))
                devmask |= (1 << 0);
@@ -1132,7 +1127,6 @@ static int bfin_softreset(struct ata_link *link, unsigned int *classes,
                classes[1] = ata_sff_dev_classify(&ap->link.device[1],
                                        devmask & (1 << 1), &err);
 
- out:
        return 0;
 }
 
@@ -1264,7 +1258,7 @@ static void bfin_freeze(struct ata_port *ap)
         * ATA_NIEN manipulation.  Also, many controllers fail to mask
         * previously pending IRQ on ATA_NIEN assertion.  Clear it.
         */
-       ap->ops->check_status(ap);
+       ap->ops->sff_check_status(ap);
 
        bfin_irq_clear(ap);
 }
@@ -1278,8 +1272,8 @@ static void bfin_freeze(struct ata_port *ap)
 
 void bfin_thaw(struct ata_port *ap)
 {
+       dev_dbg(ap->dev, "in atapi dma thaw\n");
        bfin_check_status(ap);
-       bfin_irq_clear(ap);
        bfin_irq_on(ap);
 }
 
@@ -1345,30 +1339,147 @@ static int bfin_port_start(struct ata_port *ap)
        return 0;
 }
 
+static unsigned int bfin_ata_host_intr(struct ata_port *ap,
+                                  struct ata_queued_cmd *qc)
+{
+       struct ata_eh_info *ehi = &ap->link.eh_info;
+       u8 status, host_stat = 0;
+
+       VPRINTK("ata%u: protocol %d task_state %d\n",
+               ap->print_id, qc->tf.protocol, ap->hsm_task_state);
+
+       /* Check whether we are expecting interrupt in this state */
+       switch (ap->hsm_task_state) {
+       case HSM_ST_FIRST:
+               /* Some pre-ATAPI-4 devices assert INTRQ
+                * at this state when ready to receive CDB.
+                */
+
+               /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
+                * The flag was turned on only for atapi devices.
+                * No need to check is_atapi_taskfile(&qc->tf) again.
+                */
+               if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
+                       goto idle_irq;
+               break;
+       case HSM_ST_LAST:
+               if (qc->tf.protocol == ATA_PROT_DMA ||
+                   qc->tf.protocol == ATAPI_PROT_DMA) {
+                       /* check status of DMA engine */
+                       host_stat = ap->ops->bmdma_status(ap);
+                       VPRINTK("ata%u: host_stat 0x%X\n",
+                               ap->print_id, host_stat);
+
+                       /* if it's not our irq... */
+                       if (!(host_stat & ATA_DMA_INTR))
+                               goto idle_irq;
+
+                       /* before we do anything else, clear DMA-Start bit */
+                       ap->ops->bmdma_stop(qc);
+
+                       if (unlikely(host_stat & ATA_DMA_ERR)) {
+                               /* error when transfering data to/from memory */
+                               qc->err_mask |= AC_ERR_HOST_BUS;
+                               ap->hsm_task_state = HSM_ST_ERR;
+                       }
+               }
+               break;
+       case HSM_ST:
+               break;
+       default:
+               goto idle_irq;
+       }
+
+       /* check altstatus */
+       status = ap->ops->sff_check_altstatus(ap);
+       if (status & ATA_BUSY)
+               goto busy_ata;
+
+       /* check main status, clearing INTRQ */
+       status = ap->ops->sff_check_status(ap);
+       if (unlikely(status & ATA_BUSY))
+               goto busy_ata;
+
+       /* ack bmdma irq events */
+       ap->ops->sff_irq_clear(ap);
+
+       ata_sff_hsm_move(ap, qc, status, 0);
+
+       if (unlikely(qc->err_mask) && (qc->tf.protocol == ATA_PROT_DMA ||
+                                      qc->tf.protocol == ATAPI_PROT_DMA))
+               ata_ehi_push_desc(ehi, "BMDMA stat 0x%x", host_stat);
+
+busy_ata:
+       return 1;       /* irq handled */
+
+idle_irq:
+       ap->stats.idle_irq++;
+
+#ifdef ATA_IRQ_TRAP
+       if ((ap->stats.idle_irq % 1000) == 0) {
+               ap->ops->irq_ack(ap, 0); /* debug trap */
+               ata_port_printk(ap, KERN_WARNING, "irq trap\n");
+               return 1;
+       }
+#endif
+       return 0;       /* irq not handled */
+}
+
+static irqreturn_t bfin_ata_interrupt(int irq, void *dev_instance)
+{
+       struct ata_host *host = dev_instance;
+       unsigned int i;
+       unsigned int handled = 0;
+       unsigned long flags;
+
+       /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */
+       spin_lock_irqsave(&host->lock, flags);
+
+       for (i = 0; i < host->n_ports; i++) {
+               struct ata_port *ap;
+
+               ap = host->ports[i];
+               if (ap &&
+                   !(ap->flags & ATA_FLAG_DISABLED)) {
+                       struct ata_queued_cmd *qc;
+
+                       qc = ata_qc_from_tag(ap, ap->link.active_tag);
+                       if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
+                           (qc->flags & ATA_QCFLAG_ACTIVE))
+                               handled |= bfin_ata_host_intr(ap, qc);
+               }
+       }
+
+       spin_unlock_irqrestore(&host->lock, flags);
+
+       return IRQ_RETVAL(handled);
+}
+
+
 static struct scsi_host_template bfin_sht = {
        ATA_BASE_SHT(DRV_NAME),
        .sg_tablesize           = SG_NONE,
        .dma_boundary           = ATA_DMA_BOUNDARY,
 };
 
-static const struct ata_port_operations bfin_pata_ops = {
+static struct ata_port_operations bfin_pata_ops = {
        .inherits               = &ata_sff_port_ops,
 
        .set_piomode            = bfin_set_piomode,
        .set_dmamode            = bfin_set_dmamode,
 
-       .tf_load                = bfin_tf_load,
-       .tf_read                = bfin_tf_read,
-       .exec_command           = bfin_exec_command,
-       .check_status           = bfin_check_status,
-       .check_altstatus        = bfin_check_altstatus,
-       .dev_select             = bfin_dev_select,
+       .sff_tf_load            = bfin_tf_load,
+       .sff_tf_read            = bfin_tf_read,
+       .sff_exec_command       = bfin_exec_command,
+       .sff_check_status       = bfin_check_status,
+       .sff_check_altstatus    = bfin_check_altstatus,
+       .sff_dev_select         = bfin_dev_select,
 
        .bmdma_setup            = bfin_bmdma_setup,
        .bmdma_start            = bfin_bmdma_start,
        .bmdma_stop             = bfin_bmdma_stop,
        .bmdma_status           = bfin_bmdma_status,
-       .data_xfer              = bfin_data_xfer,
+       .sff_data_xfer          = bfin_data_xfer,
 
        .qc_prep                = ata_noop_qc_prep,
 
@@ -1376,10 +1487,9 @@ static const struct ata_port_operations bfin_pata_ops = {
        .thaw                   = bfin_thaw,
        .softreset              = bfin_softreset,
        .postreset              = bfin_postreset,
-       .post_internal_cmd      = bfin_bmdma_stop,
 
-       .irq_clear              = bfin_irq_clear,
-       .irq_on                 = bfin_irq_on,
+       .sff_irq_clear          = bfin_irq_clear,
+       .sff_irq_on             = bfin_irq_on,
 
        .port_start             = bfin_port_start,
        .port_stop              = bfin_port_stop,
@@ -1423,7 +1533,7 @@ static int bfin_reset_controller(struct ata_host *host)
        count = 10000000;
        do {
                status = read_atapi_register(base, ATA_REG_STATUS);
-       } while (count-- && (status & ATA_BUSY));
+       } while (--count && (status & ATA_BUSY));
 
        /* Enable only ATAPI Device interrupt */
        ATAPI_SET_INT_MASK(base, 1);
@@ -1513,7 +1623,7 @@ static int __devinit bfin_atapi_probe(struct platform_device *pdev)
        }
 
        if (ata_host_activate(host, platform_get_irq(pdev, 0),
-               ata_sff_interrupt, IRQF_SHARED, &bfin_sht) != 0) {
+               bfin_ata_interrupt, IRQF_SHARED, &bfin_sht) != 0) {
                peripheral_free_list(atapi_io_port);
                dev_err(&pdev->dev, "Fail to attach ATAPI device\n");
                return -ENODEV;
@@ -1607,3 +1717,4 @@ MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
 MODULE_DESCRIPTION("PATA driver for blackfin 54x ATAPI controller");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
+MODULE_ALIAS("platform:" DRV_NAME);