Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 into for-linus
[pandora-kernel.git] / drivers / ide / ide-probe.c
index a4b65b3..655ec7e 100644 (file)
@@ -124,7 +124,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
 
        id = drive->id;
        /* read 512 bytes of id info */
-       hwif->ata_input_data(drive, id, SECTOR_WORDS);
+       hwif->input_data(drive, NULL, id, SECTOR_SIZE);
 
        drive->id_read = 1;
        local_irq_enable();
@@ -264,6 +264,7 @@ err_misc:
 static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
 {
        ide_hwif_t *hwif = HWIF(drive);
+       struct ide_io_ports *io_ports = &hwif->io_ports;
        int use_altstatus = 0, rc;
        unsigned long timeout;
        u8 s = 0, a = 0;
@@ -271,7 +272,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
        /* take a deep breath */
        msleep(50);
 
-       if (hwif->io_ports[IDE_CONTROL_OFFSET]) {
+       if (io_ports->ctl_addr) {
                a = ide_read_altstatus(drive);
                s = ide_read_status(drive);
                if ((a ^ s) & ~INDEX_STAT)
@@ -289,10 +290,10 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
         */
        if ((cmd == WIN_PIDENTIFY))
                /* disable dma & overlap */
-               hwif->OUTB(0, hwif->io_ports[IDE_FEATURE_OFFSET]);
+               hwif->OUTB(0, io_ports->feature_addr);
 
        /* ask drive for ID */
-       hwif->OUTB(cmd, hwif->io_ports[IDE_COMMAND_OFFSET]);
+       hwif->OUTBSYNC(drive, cmd, io_ports->command_addr);
 
        timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
        timeout += jiffies;
@@ -353,7 +354,7 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
         * interrupts during the identify-phase that
         * the irq handler isn't expecting.
         */
-       if (hwif->io_ports[IDE_CONTROL_OFFSET]) {
+       if (hwif->io_ports.ctl_addr) {
                if (!hwif->irq) {
                        autoprobe = 1;
                        cookie = probe_irq_on();
@@ -393,7 +394,7 @@ static int ide_busy_sleep(ide_hwif_t *hwif)
 
        do {
                msleep(50);
-               stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
+               stat = hwif->INB(hwif->io_ports.status_addr);
                if ((stat & BUSY_STAT) == 0)
                        return 0;
        } while (time_before(jiffies, timeout));
@@ -425,6 +426,7 @@ static int ide_busy_sleep(ide_hwif_t *hwif)
 static int do_probe (ide_drive_t *drive, u8 cmd)
 {
        ide_hwif_t *hwif = HWIF(drive);
+       struct ide_io_ports *io_ports = &hwif->io_ports;
        int rc;
        u8 stat;
 
@@ -445,7 +447,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
        msleep(50);
        SELECT_DRIVE(drive);
        msleep(50);
-       if (hwif->INB(hwif->io_ports[IDE_SELECT_OFFSET]) != drive->select.all &&
+       if (hwif->INB(io_ports->device_addr) != drive->select.all &&
            !drive->present) {
                if (drive->select.b.unit != 0) {
                        /* exit with drive0 selected */
@@ -472,17 +474,13 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
                if (stat == (BUSY_STAT | READY_STAT))
                        return 4;
 
-               if ((rc == 1 && cmd == WIN_PIDENTIFY) &&
-                       ((drive->autotune == IDE_TUNE_DEFAULT) ||
-                       (drive->autotune == IDE_TUNE_AUTO))) {
+               if (rc == 1 && cmd == WIN_PIDENTIFY) {
                        printk(KERN_ERR "%s: no response (status = 0x%02x), "
                                        "resetting drive\n", drive->name, stat);
                        msleep(50);
-                       hwif->OUTB(drive->select.all,
-                                  hwif->io_ports[IDE_SELECT_OFFSET]);
+                       hwif->OUTB(drive->select.all, io_ports->device_addr);
                        msleep(50);
-                       hwif->OUTB(WIN_SRST,
-                                  hwif->io_ports[IDE_COMMAND_OFFSET]);
+                       hwif->OUTBSYNC(drive, WIN_SRST, io_ports->command_addr);
                        (void)ide_busy_sleep(hwif);
                        rc = try_to_identify(drive, cmd);
                }
@@ -518,7 +516,7 @@ static void enable_nest (ide_drive_t *drive)
        printk("%s: enabling %s -- ", hwif->name, drive->id->model);
        SELECT_DRIVE(drive);
        msleep(50);
-       hwif->OUTB(EXABYTE_ENABLE_NEST, hwif->io_ports[IDE_COMMAND_OFFSET]);
+       hwif->OUTBSYNC(drive, EXABYTE_ENABLE_NEST, hwif->io_ports.command_addr);
 
        if (ide_busy_sleep(hwif)) {
                printk(KERN_CONT "failed (timeout)\n");
@@ -650,13 +648,12 @@ static int ide_register_port(ide_hwif_t *hwif)
 
        get_device(&hwif->gendev);
 
-       hwif->portdev = device_create(ide_port_class, &hwif->gendev,
-                                     MKDEV(0, 0), hwif->name);
+       hwif->portdev = device_create_drvdata(ide_port_class, &hwif->gendev,
+                                             MKDEV(0, 0), hwif, hwif->name);
        if (IS_ERR(hwif->portdev)) {
                ret = PTR_ERR(hwif->portdev);
                device_unregister(&hwif->gendev);
        }
-       dev_set_drvdata(hwif->portdev, hwif);
 out:
        return ret;
 }
@@ -800,14 +797,9 @@ static int ide_probe_port(ide_hwif_t *hwif)
                if (drive->present)
                        rc = 0;
        }
-       if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {
-               printk(KERN_WARNING "%s: reset\n", hwif->name);
-               hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
-               udelay(10);
-               hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
-               (void)ide_busy_sleep(hwif);
-       }
+
        local_irq_restore(flags);
+
        /*
         * Use cached IRQ number. It might be (and is...) changed by probe
         * code above
@@ -834,12 +826,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
                ide_drive_t *drive = &hwif->drives[unit];
 
                if (drive->present) {
-                       if (drive->autotune == IDE_TUNE_AUTO)
-                               ide_set_max_pio(drive);
-
-                       if (drive->autotune != IDE_TUNE_DEFAULT &&
-                           drive->autotune != IDE_TUNE_AUTO)
-                               continue;
+                       ide_set_max_pio(drive);
 
                        drive->nice1 = 1;
 
@@ -994,6 +981,7 @@ static void ide_port_setup_devices(ide_hwif_t *hwif)
  */
 static int init_irq (ide_hwif_t *hwif)
 {
+       struct ide_io_ports *io_ports = &hwif->io_ports;
        unsigned int index;
        ide_hwgroup_t *hwgroup;
        ide_hwif_t *match = NULL;
@@ -1077,9 +1065,9 @@ static int init_irq (ide_hwif_t *hwif)
                if (IDE_CHIPSET_IS_PCI(hwif->chipset))
                        sa = IRQF_SHARED;
 
-               if (hwif->io_ports[IDE_CONTROL_OFFSET])
+               if (io_ports->ctl_addr)
                        /* clear nIEN */
-                       hwif->OUTB(0x08, hwif->io_ports[IDE_CONTROL_OFFSET]);
+                       hwif->OUTB(0x08, io_ports->ctl_addr);
 
                if (request_irq(hwif->irq,&ide_intr,sa,hwif->name,hwgroup))
                        goto out_unlink;
@@ -1095,12 +1083,11 @@ static int init_irq (ide_hwif_t *hwif)
 
 #if !defined(__mc68000__)
        printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
-               hwif->io_ports[IDE_DATA_OFFSET],
-               hwif->io_ports[IDE_DATA_OFFSET]+7,
-               hwif->io_ports[IDE_CONTROL_OFFSET], hwif->irq);
+               io_ports->data_addr, io_ports->status_addr,
+               io_ports->ctl_addr, hwif->irq);
 #else
        printk("%s at 0x%08lx on irq %d", hwif->name,
-               hwif->io_ports[IDE_DATA_OFFSET], hwif->irq);
+               io_ports->data_addr, hwif->irq);
 #endif /* __mc68000__ */
        if (match)
                printk(" (%sed with %s)",
@@ -1242,8 +1229,8 @@ static int hwif_init(ide_hwif_t *hwif)
        int old_irq;
 
        if (!hwif->irq) {
-               if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
-               {
+               hwif->irq = ide_default_irq(hwif->io_ports.data_addr);
+               if (!hwif->irq) {
                        printk("%s: DISABLED, NO IRQ\n", hwif->name);
                        return 0;
                }
@@ -1272,7 +1259,8 @@ static int hwif_init(ide_hwif_t *hwif)
         *      It failed to initialise. Find the default IRQ for 
         *      this port and try that.
         */
-       if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) {
+       hwif->irq = ide_default_irq(hwif->io_ports.data_addr);
+       if (!hwif->irq) {
                printk("%s: Disabled unable to get IRQ %d.\n",
                        hwif->name, old_irq);
                goto out;
@@ -1336,8 +1324,6 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
                        drive->unmask = 1;
                if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
                        drive->no_unmask = 1;
-               if ((hwif->host_flags & IDE_HFLAG_NO_AUTOTUNE) == 0)
-                       drive->autotune = 1;
        }
 
        if (port_ops && port_ops->port_init_devs)
@@ -1360,19 +1346,14 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
            (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS))
                hwif->irq = port ? 15 : 14;
 
-       hwif->host_flags = d->host_flags;
+       /* ->host_flags may be set by ->init_iops (or even earlier...) */
+       hwif->host_flags |= d->host_flags;
        hwif->pio_mask = d->pio_mask;
 
        /* ->set_pio_mode for DTC2278 is currently limited to port 0 */
        if (hwif->chipset != ide_dtc2278 || hwif->channel == 0)
                hwif->port_ops = d->port_ops;
 
-       if ((d->host_flags & IDE_HFLAG_SERIALIZE) ||
-           ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base)) {
-               if (hwif->mate)
-                       hwif->mate->serialized = hwif->serialized = 1;
-       }
-
        hwif->swdma_mask = d->swdma_mask;
        hwif->mwdma_mask = d->mwdma_mask;
        hwif->ultra_mask = d->udma_mask;
@@ -1394,6 +1375,12 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
                        hwif->dma_ops = d->dma_ops;
        }
 
+       if ((d->host_flags & IDE_HFLAG_SERIALIZE) ||
+           ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base)) {
+               if (hwif->mate)
+                       hwif->mate->serialized = hwif->serialized = 1;
+       }
+
        if (d->host_flags & IDE_HFLAG_RQSIZE_256)
                hwif->rqsize = 256;
 
@@ -1518,13 +1505,20 @@ int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
        int i, rc = 0;
 
        for (i = 0; i < MAX_HWIFS; i++) {
-               if (d == NULL || idx[i] == 0xff) {
+               if (idx[i] == 0xff) {
                        mate = NULL;
                        continue;
                }
 
                hwif = &ide_hwifs[idx[i]];
 
+               ide_port_apply_params(hwif);
+
+               if (d == NULL) {
+                       mate = NULL;
+                       continue;
+               }
+
                if (d->chipset != ide_etrax100 && (i & 1) && mate) {
                        hwif->mate = mate;
                        mate->mate = hwif;
@@ -1621,6 +1615,7 @@ EXPORT_SYMBOL_GPL(ide_device_add);
 
 void ide_port_scan(ide_hwif_t *hwif)
 {
+       ide_port_apply_params(hwif);
        ide_port_cable_detect(hwif);
        ide_port_init_devices(hwif);