ide: ide_get_best_pio_mode() returns incorrect IORDY setting (take 2)

The function ide_get_best_pio_mode() fails to return the correct IORDY setting
for the explicitly specified modes -- fix this along with the heading comment,
and also remove the long commented out code.

Also, while at it, correct the misliading comment about the PIO cycle time in
<linux/ide.h> -- it actually consists of only the active and recovery periods,
with only some chips also including the address setup time into equation...

[ bart: sl82c105 seems to be currently the only driver affected by this fix ]

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

authored by Sergei Shtylyov and committed by Bartlomiej Zolnierkiewicz 81d368e0 07af4276

+8 -13
+6 -12
drivers/ide/ide-lib.c
··· 345 346 /** 347 * ide_get_best_pio_mode - get PIO mode from drive 348 - * @driver: drive to consider 349 * @mode_wanted: preferred mode 350 - * @max_mode: highest allowed 351 - * @d: pio data 352 * 353 * This routine returns the recommended PIO settings for a given drive, 354 * based on the drive->id information and the ide_pio_blacklist[]. 355 - * This is used by most chipset support modules when "auto-tuning". 356 * 357 - * Drive PIO mode auto selection 358 */ 359 360 u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d) ··· 367 368 if (mode_wanted != 255) { 369 pio_mode = mode_wanted; 370 } else if (!drive->id) { 371 pio_mode = 0; 372 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { ··· 397 } 398 } 399 400 - #if 0 401 - if (drive->id->major_rev_num & 0x0004) printk("ATA-2 "); 402 - #endif 403 - 404 /* 405 * Conservative "downgrade" for all pre-ATA2 drives 406 */ 407 if (pio_mode && pio_mode < 4) { 408 pio_mode--; 409 overridden = 1; 410 - #if 0 411 - use_iordy = (pio_mode > 2); 412 - #endif 413 if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time) 414 cycle_time = 0; /* use standard timing */ 415 }
··· 345 346 /** 347 * ide_get_best_pio_mode - get PIO mode from drive 348 + * @drive: drive to consider 349 * @mode_wanted: preferred mode 350 + * @max_mode: highest allowed mode 351 + * @d: PIO data 352 * 353 * This routine returns the recommended PIO settings for a given drive, 354 * based on the drive->id information and the ide_pio_blacklist[]. 355 * 356 + * Drive PIO mode is auto-selected if 255 is passed as mode_wanted. 357 + * This is used by most chipset support modules when "auto-tuning". 358 */ 359 360 u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d) ··· 367 368 if (mode_wanted != 255) { 369 pio_mode = mode_wanted; 370 + use_iordy = (pio_mode > 2); 371 } else if (!drive->id) { 372 pio_mode = 0; 373 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { ··· 396 } 397 } 398 399 /* 400 * Conservative "downgrade" for all pre-ATA2 drives 401 */ 402 if (pio_mode && pio_mode < 4) { 403 pio_mode--; 404 overridden = 1; 405 if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time) 406 cycle_time = 0; /* use standard timing */ 407 }
+2 -1
include/linux/ide.h
··· 1359 typedef struct ide_pio_timings_s { 1360 int setup_time; /* Address setup (ns) minimum */ 1361 int active_time; /* Active pulse (ns) minimum */ 1362 - int cycle_time; /* Cycle time (ns) minimum = (setup + active + recovery) */ 1363 } ide_pio_timings_t; 1364 1365 typedef struct ide_pio_data_s {
··· 1359 typedef struct ide_pio_timings_s { 1360 int setup_time; /* Address setup (ns) minimum */ 1361 int active_time; /* Active pulse (ns) minimum */ 1362 + int cycle_time; /* Cycle time (ns) minimum = */ 1363 + /* active + recovery (+ setup for some chips) */ 1364 } ide_pio_timings_t; 1365 1366 typedef struct ide_pio_data_s {