ide: use ->tf_read in ide_read_error()
[firefly-linux-kernel-4.4.55.git] / drivers / ide / ide-iops.c
index 086eceaeeafdc8cf8cb7faa82457c5968a1e8292..113db87447364b6c97146709a5c3b3f1e3b14232 100644 (file)
@@ -88,11 +88,15 @@ void SELECT_DRIVE (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        const struct ide_port_ops *port_ops = hwif->port_ops;
+       ide_task_t task;
 
        if (port_ops && port_ops->selectproc)
                port_ops->selectproc(drive);
 
-       hwif->OUTB(drive->select.all, hwif->io_ports.device_addr);
+       memset(&task, 0, sizeof(task));
+       task.tf_flags = IDE_TFLAG_OUT_DEVICE;
+
+       drive->hwif->tf_load(drive, &task);
 }
 
 void SELECT_MASK(ide_drive_t *drive, int mask)
@@ -119,6 +123,14 @@ static u8 ide_read_status(ide_hwif_t *hwif)
                return inb(hwif->io_ports.status_addr);
 }
 
+static u8 ide_read_altstatus(ide_hwif_t *hwif)
+{
+       if (hwif->host_flags & IDE_HFLAG_MMIO)
+               return readb((void __iomem *)hwif->io_ports.ctl_addr);
+       else
+               return inb(hwif->io_ports.ctl_addr);
+}
+
 static u8 ide_read_sff_dma_status(ide_hwif_t *hwif)
 {
        if (hwif->host_flags & IDE_HFLAG_MMIO)
@@ -127,6 +139,23 @@ static u8 ide_read_sff_dma_status(ide_hwif_t *hwif)
                return inb(hwif->dma_base + ATA_DMA_STATUS);
 }
 
+static void ide_set_irq(ide_hwif_t *hwif, int on)
+{
+       u8 ctl = ATA_DEVCTL_OBS;
+
+       if (on == 4) { /* hack for SRST */
+               ctl |= 4;
+               on &= ~4;
+       }
+
+       ctl |= on ? 0 : 2;
+
+       if (hwif->host_flags & IDE_HFLAG_MMIO)
+               writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
+       else
+               outb(ctl, hwif->io_ports.ctl_addr);
+}
+
 static void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
 {
        ide_hwif_t *hwif = drive->hwif;
@@ -212,6 +241,8 @@ static void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
        /* be sure we're looking at the low order bits */
        tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
 
+       if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
+               tf->feature = tf_inb(io_ports->feature_addr);
        if (task->tf_flags & IDE_TFLAG_IN_NSECT)
                tf->nsect  = tf_inb(io_ports->nsect_addr);
        if (task->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -349,8 +380,11 @@ void default_hwif_transport(ide_hwif_t *hwif)
 {
        hwif->exec_command        = ide_exec_command;
        hwif->read_status         = ide_read_status;
+       hwif->read_altstatus      = ide_read_altstatus;
        hwif->read_sff_dma_status = ide_read_sff_dma_status;
 
+       hwif->set_irq     = ide_set_irq;
+
        hwif->tf_load     = ide_tf_load;
        hwif->tf_read     = ide_tf_read;
 
@@ -358,6 +392,19 @@ void default_hwif_transport(ide_hwif_t *hwif)
        hwif->output_data = ata_output_data;
 }
 
+u8 ide_read_error(ide_drive_t *drive)
+{
+       ide_task_t task;
+
+       memset(&task, 0, sizeof(task));
+       task.tf_flags = IDE_TFLAG_IN_FEATURE;
+
+       drive->hwif->tf_read(drive, &task);
+
+       return task.tf.error;
+}
+EXPORT_SYMBOL_GPL(ide_read_error);
+
 void ide_fix_driveid (struct hd_driveid *id)
 {
 #ifndef __LITTLE_ENDIAN
@@ -511,7 +558,7 @@ int drive_is_ready (ide_drive_t *drive)
         * about possible isa-pnp and pci-pnp issues yet.
         */
        if (hwif->io_ports.ctl_addr)
-               stat = ide_read_altstatus(drive);
+               stat = hwif->read_altstatus(hwif);
        else
                /* Note: this may clear a pending IRQ!! */
                stat = hwif->read_status(hwif);
@@ -713,7 +760,7 @@ int ide_driveid_update(ide_drive_t *drive)
         */
 
        SELECT_MASK(drive, 1);
-       ide_set_irq(drive, 0);
+       hwif->set_irq(hwif, 0);
        msleep(50);
        hwif->exec_command(hwif, WIN_IDENTIFY);
        timeout = jiffies + WAIT_WORSTCASE;
@@ -724,7 +771,7 @@ int ide_driveid_update(ide_drive_t *drive)
                }
 
                msleep(50);     /* give drive a breather */
-               stat = ide_read_altstatus(drive);
+               stat = hwif->read_altstatus(hwif);
        } while (stat & BUSY_STAT);
 
        msleep(50);     /* wait for IRQ and DRQ_STAT */
@@ -764,9 +811,9 @@ int ide_driveid_update(ide_drive_t *drive)
 int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
 {
        ide_hwif_t *hwif = drive->hwif;
-       struct ide_io_ports *io_ports = &hwif->io_ports;
        int error = 0;
        u8 stat;
+       ide_task_t task;
 
 #ifdef CONFIG_BLK_DEV_IDEDMA
        if (hwif->dma_ops)      /* check if host supports DMA */
@@ -799,12 +846,19 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
        SELECT_DRIVE(drive);
        SELECT_MASK(drive, 0);
        udelay(1);
-       ide_set_irq(drive, 0);
-       hwif->OUTB(speed, io_ports->nsect_addr);
-       hwif->OUTB(SETFEATURES_XFER, io_ports->feature_addr);
+       hwif->set_irq(hwif, 0);
+
+       memset(&task, 0, sizeof(task));
+       task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT;
+       task.tf.feature = SETFEATURES_XFER;
+       task.tf.nsect   = speed;
+
+       hwif->tf_load(drive, &task);
+
        hwif->exec_command(hwif, WIN_SETFEATURES);
+
        if (drive->quirk_list == 2)
-               ide_set_irq(drive, 1);
+               hwif->set_irq(hwif, 1);
 
        error = __ide_wait_stat(drive, drive->ready_stat,
                                BUSY_STAT|DRQ_STAT|ERR_STAT,
@@ -1120,7 +1174,6 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
        ide_hwgroup_t *hwgroup;
        struct ide_io_ports *io_ports;
        const struct ide_port_ops *port_ops;
-       u8 ctl;
 
        spin_lock_irqsave(&ide_lock, flags);
        hwif = HWIF(drive);
@@ -1165,16 +1218,15 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
         * immediate interrupt due to the edge transition it produces.
         * This single interrupt gives us a "fast poll" for drives that
         * recover from reset very quickly, saving us the first 50ms wait time.
+        *
+        * TODO: add ->softreset method and stop abusing ->set_irq
         */
        /* set SRST and nIEN */
-       hwif->OUTBSYNC(hwif, ATA_DEVCTL_OBS | 6, io_ports->ctl_addr);
+       hwif->set_irq(hwif, 4);
        /* more than enough time */
        udelay(10);
-       if (drive->quirk_list == 2)
-               ctl = ATA_DEVCTL_OBS;           /* clear SRST and nIEN */
-       else
-               ctl = ATA_DEVCTL_OBS | 2;       /* clear SRST, leave nIEN */
-       hwif->OUTBSYNC(hwif, ctl, io_ports->ctl_addr);
+       /* clear SRST, leave nIEN (unless device is on the quirk list) */
+       hwif->set_irq(hwif, drive->quirk_list == 2);
        /* more than enough time */
        udelay(10);
        hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;