]> Pileus Git - ~andy/linux/blobdiff - drivers/ide/ide-lib.c
ide: fix PCI refcounting
[~andy/linux] / drivers / ide / ide-lib.c
index d45bbad9ffe7602a8a46726be10a8cf943571a13..92a6c7bcf5278dc8594eb7a73113c9d648647f63 100644 (file)
@@ -249,12 +249,34 @@ static int ide_scan_pio_blacklist (char *model)
        return -1;
 }
 
+unsigned int ide_pio_cycle_time(ide_drive_t *drive, u8 pio)
+{
+       struct hd_driveid *id = drive->id;
+       int cycle_time = 0;
+
+       if (id->field_valid & 2) {
+               if (id->capability & 8)
+                       cycle_time = id->eide_pio_iordy;
+               else
+                       cycle_time = id->eide_pio;
+       }
+
+       /* conservative "downgrade" for all pre-ATA2 drives */
+       if (pio < 3) {
+               if (cycle_time && cycle_time < ide_pio_timings[pio].cycle_time)
+                       cycle_time = 0; /* use standard timing */
+       }
+
+       return cycle_time ? cycle_time : ide_pio_timings[pio].cycle_time;
+}
+
+EXPORT_SYMBOL_GPL(ide_pio_cycle_time);
+
 /**
  *     ide_get_best_pio_mode   -       get PIO mode from drive
  *     @drive: drive to consider
  *     @mode_wanted: preferred mode
  *     @max_mode: highest allowed mode
- *     @d: PIO data
  *
  *     This routine returns the recommended PIO settings for a given drive,
  *     based on the drive->id information and the ide_pio_blacklist[].
@@ -263,22 +285,18 @@ static int ide_scan_pio_blacklist (char *model)
  *     This is used by most chipset support modules when "auto-tuning".
  */
 
-u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d)
+u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
 {
        int pio_mode;
-       int cycle_time = 0;
-       int use_iordy = 0;
        struct hd_driveid* id = drive->id;
        int overridden  = 0;
 
-       if (mode_wanted != 255) {
-               pio_mode = mode_wanted;
-               use_iordy = (pio_mode > 2);
-       } else if (!drive->id) {
-               pio_mode = 0;
-       } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
+       if (mode_wanted != 255)
+               return min_t(u8, mode_wanted, max_mode);
+
+       if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0 &&
+           (pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
                printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
-               use_iordy = (pio_mode > 2);
        } else {
                pio_mode = id->tPIO;
                if (pio_mode > 2) {     /* 2 is maximum allowed tPIO value */
@@ -286,9 +304,7 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
                        overridden = 1;
                }
                if (id->field_valid & 2) {        /* drive implements ATA2? */
-                       if (id->capability & 8) { /* drive supports use_iordy? */
-                               use_iordy = 1;
-                               cycle_time = id->eide_pio_iordy;
+                       if (id->capability & 8) { /* IORDY supported? */
                                if (id->eide_pio_modes & 7) {
                                        overridden = 0;
                                        if (id->eide_pio_modes & 4)
@@ -298,8 +314,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
                                        else
                                                pio_mode = 3;
                                }
-                       } else {
-                               cycle_time = id->eide_pio;
                        }
                }
 
@@ -310,23 +324,17 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
                /*
                 * Conservative "downgrade" for all pre-ATA2 drives
                 */
-               if (pio_mode && pio_mode < 4) {
+               if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_DOWNGRADE) == 0 &&
+                   pio_mode && pio_mode < 4) {
                        pio_mode--;
                        printk(KERN_INFO "%s: applying conservative "
                                         "PIO \"downgrade\"\n", drive->name);
-                       if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time)
-                               cycle_time = 0; /* use standard timing */
                }
        }
-       if (pio_mode > max_mode) {
+
+       if (pio_mode > max_mode)
                pio_mode = max_mode;
-               cycle_time = 0;
-       }
-       if (d) {
-               d->pio_mode = pio_mode;
-               d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time;
-               d->use_iordy = use_iordy;
-       }
+
        return pio_mode;
 }