Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-leds
[pandora-kernel.git] / drivers / ide / ide-atapi.c
index cf2b99c..e96c012 100644 (file)
@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(ide_retry_pc);
 
 int ide_cd_expiry(ide_drive_t *drive)
 {
-       struct request *rq = HWGROUP(drive)->rq;
+       struct request *rq = drive->hwif->rq;
        unsigned long wait = 0;
 
        debug_log("%s: rq->cmd[0]: 0x%x\n", __func__, rq->cmd[0]);
@@ -294,7 +294,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 {
        struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
-       struct request *rq = hwif->hwgroup->rq;
+       struct request *rq = hwif->rq;
        const struct ide_tp_ops *tp_ops = hwif->tp_ops;
        xfer_func_t *xferfunc;
        unsigned int timeout, temp;
@@ -489,9 +489,9 @@ static int ide_delayed_transfer_pc(ide_drive_t *drive)
 
 static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
 {
-       struct ide_atapi_pc *pc = drive->pc;
+       struct ide_atapi_pc *uninitialized_var(pc);
        ide_hwif_t *hwif = drive->hwif;
-       struct request *rq = hwif->hwgroup->rq;
+       struct request *rq = hwif->rq;
        ide_expiry_t *expiry;
        unsigned int timeout;
        int cmd_len;
@@ -509,17 +509,6 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
                        drive->waiting_for_dma = 1;
        }
 
-       ireason = ide_read_ireason(drive);
-       if (drive->media == ide_tape)
-               ireason = ide_wait_ireason(drive, ireason);
-
-       if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
-               printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
-                               "a packet command\n", drive->name);
-
-               return ide_do_reset(drive);
-       }
-
        if (dev_is_idecd(drive)) {
                /* ATAPI commands get padded out to 12 bytes minimum */
                cmd_len = COMMAND_SIZE(rq->cmd[0]);
@@ -529,6 +518,8 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
                timeout = rq->timeout;
                expiry  = ide_cd_expiry;
        } else {
+               pc = drive->pc;
+
                cmd_len = ATAPI_MIN_CDB_BYTES;
 
                /*
@@ -544,15 +535,34 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
                                                               : WAIT_TAPE_CMD;
                        expiry = NULL;
                }
+
+               ireason = ide_read_ireason(drive);
+               if (drive->media == ide_tape)
+                       ireason = ide_wait_ireason(drive, ireason);
+
+               if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
+                       printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
+                                       "a packet command\n", drive->name);
+
+                       return ide_do_reset(drive);
+               }
        }
 
        /* Set the interrupt routine */
-       ide_set_handler(drive, ide_pc_intr, timeout, expiry);
+       ide_set_handler(drive,
+                       (dev_is_idecd(drive) ? drive->irq_handler
+                                            : ide_pc_intr),
+                       timeout, expiry);
 
        /* Begin DMA, if necessary */
-       if (pc->flags & PC_FLAG_DMA_OK) {
-               pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
-               hwif->dma_ops->dma_start(drive);
+       if (dev_is_idecd(drive)) {
+               if (drive->dma)
+                       hwif->dma_ops->dma_start(drive);
+       } else {
+               if (pc->flags & PC_FLAG_DMA_OK) {
+                       pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
+                       hwif->dma_ops->dma_start(drive);
+               }
        }
 
        /* Send the actual packet */
@@ -562,41 +572,50 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
        return ide_started;
 }
 
-ide_startstop_t ide_issue_pc(ide_drive_t *drive, unsigned int timeout)
+ide_startstop_t ide_issue_pc(ide_drive_t *drive)
 {
-       struct ide_atapi_pc *pc = drive->pc;
+       struct ide_atapi_pc *pc;
        ide_hwif_t *hwif = drive->hwif;
        ide_expiry_t *expiry = NULL;
+       unsigned int timeout;
        u32 tf_flags;
        u16 bcount;
 
-       /* We haven't transferred any data yet */
-       pc->xferred = 0;
-       pc->cur_pos = pc->buf;
-
        if (dev_is_idecd(drive)) {
                tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
-               bcount = ide_cd_get_xferlen(hwif->hwgroup->rq);
+               bcount = ide_cd_get_xferlen(hwif->rq);
                expiry = ide_cd_expiry;
+               timeout = ATAPI_WAIT_PC;
+
+               if (drive->dma)
+                       drive->dma = !hwif->dma_ops->dma_setup(drive);
        } else {
+               pc = drive->pc;
+
+               /* We haven't transferred any data yet */
+               pc->xferred = 0;
+               pc->cur_pos = pc->buf;
+
                tf_flags = IDE_TFLAG_OUT_DEVICE;
                bcount = ((drive->media == ide_tape) ?
                                pc->req_xfer :
                                min(pc->req_xfer, 63 * 1024));
-       }
 
-       if (pc->flags & PC_FLAG_DMA_ERROR) {
-               pc->flags &= ~PC_FLAG_DMA_ERROR;
-               ide_dma_off(drive);
-       }
+               if (pc->flags & PC_FLAG_DMA_ERROR) {
+                       pc->flags &= ~PC_FLAG_DMA_ERROR;
+                       ide_dma_off(drive);
+               }
+
+               if ((pc->flags & PC_FLAG_DMA_OK) &&
+                    (drive->dev_flags & IDE_DFLAG_USING_DMA))
+                       drive->dma = !hwif->dma_ops->dma_setup(drive);
 
-       if (((pc->flags & PC_FLAG_DMA_OK) &&
-               (drive->dev_flags & IDE_DFLAG_USING_DMA)) ||
-           drive->dma)
-               drive->dma = !hwif->dma_ops->dma_setup(drive);
+               if (!drive->dma)
+                       pc->flags &= ~PC_FLAG_DMA_OK;
 
-       if (!drive->dma)
-               pc->flags &= ~PC_FLAG_DMA_OK;
+               timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
+                                                      : WAIT_TAPE_CMD;
+       }
 
        ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);