aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ide/cris/ide-cris.c8
-rw-r--r--drivers/ide/ide-io.c39
-rw-r--r--drivers/ide/ide-iops.c6
-rw-r--r--drivers/ide/ide-lib.c29
-rw-r--r--drivers/ide/ide-probe.c6
-rw-r--r--drivers/ide/ide.c5
-rw-r--r--drivers/ide/legacy/ali14xx.c10
-rw-r--r--drivers/ide/legacy/dtc2278.c6
-rw-r--r--drivers/ide/legacy/ht6560b.c11
-rw-r--r--drivers/ide/legacy/qd65xx.c60
-rw-r--r--drivers/ide/legacy/umc8672.c7
-rw-r--r--drivers/ide/mips/au1xxx-ide.c12
-rw-r--r--drivers/ide/pci/aec62xx.c7
-rw-r--r--drivers/ide/pci/alim15x3.c32
-rw-r--r--drivers/ide/pci/amd74xx.c14
-rw-r--r--drivers/ide/pci/atiixp.c7
-rw-r--r--drivers/ide/pci/cmd640.c35
-rw-r--r--drivers/ide/pci/cmd64x.c39
-rw-r--r--drivers/ide/pci/cs5520.c11
-rw-r--r--drivers/ide/pci/cs5530.c15
-rw-r--r--drivers/ide/pci/cs5535.c16
-rw-r--r--drivers/ide/pci/cy82c693.c20
-rw-r--r--drivers/ide/pci/hpt34x.c7
-rw-r--r--drivers/ide/pci/hpt366.c7
-rw-r--r--drivers/ide/pci/it8213.c7
-rw-r--r--drivers/ide/pci/it821x.c7
-rw-r--r--drivers/ide/pci/jmicron.c7
-rw-r--r--drivers/ide/pci/opti621.c19
-rw-r--r--drivers/ide/pci/pdc202xx_new.c8
-rw-r--r--drivers/ide/pci/pdc202xx_old.c14
-rw-r--r--drivers/ide/pci/piix.c21
-rw-r--r--drivers/ide/pci/sc1200.c14
-rw-r--r--drivers/ide/pci/scc_pata.c7
-rw-r--r--drivers/ide/pci/serverworks.c7
-rw-r--r--drivers/ide/pci/sgiioc4.c2
-rw-r--r--drivers/ide/pci/siimage.c7
-rw-r--r--drivers/ide/pci/sis5513.c11
-rw-r--r--drivers/ide/pci/sl82c105.c17
-rw-r--r--drivers/ide/pci/slc90e66.c7
-rw-r--r--drivers/ide/pci/tc86c001.c7
-rw-r--r--drivers/ide/pci/triflex.c9
-rw-r--r--drivers/ide/pci/via82cxxx.c17
-rw-r--r--drivers/ide/ppc/mpc8xx.c21
-rw-r--r--drivers/ide/ppc/pmac.c8
-rw-r--r--include/linux/ide.h18
45 files changed, 318 insertions, 326 deletions
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 67cec8916fcd..7c90218e9319 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -680,12 +680,10 @@ static void cris_dma_off(ide_drive_t *drive)
680{ 680{
681} 681}
682 682
683static void tune_cris_ide(ide_drive_t *drive, u8 pio) 683static void cris_set_pio_mode(ide_drive_t *drive, const u8 pio)
684{ 684{
685 int setup, strobe, hold; 685 int setup, strobe, hold;
686 686
687 pio = ide_get_best_pio_mode(drive, pio, 4);
688
689 switch(pio) 687 switch(pio)
690 { 688 {
691 case 0: 689 case 0:
@@ -727,7 +725,7 @@ static int speed_cris_ide(ide_drive_t *drive, const u8 speed)
727 int cyc = 0, dvs = 0, strobe = 0, hold = 0; 725 int cyc = 0, dvs = 0, strobe = 0, hold = 0;
728 726
729 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) { 727 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
730 tune_cris_ide(drive, speed - XFER_PIO_0); 728 cris_set_pio_mode(drive, speed - XFER_PIO_0);
731 return ide_config_drive_speed(drive, speed); 729 return ide_config_drive_speed(drive, speed);
732 } 730 }
733 731
@@ -797,7 +795,7 @@ init_e100_ide (void)
797 ide_register_hw(&hw, 1, &hwif); 795 ide_register_hw(&hw, 1, &hwif);
798 hwif->mmio = 1; 796 hwif->mmio = 1;
799 hwif->chipset = ide_etrax100; 797 hwif->chipset = ide_etrax100;
800 hwif->tuneproc = &tune_cris_ide; 798 hwif->set_pio_mode = &cris_set_pio_mode;
801 hwif->speedproc = &speed_cris_ide; 799 hwif->speedproc = &speed_cris_ide;
802 hwif->ata_input_data = &cris_ide_input_data; 800 hwif->ata_input_data = &cris_ide_input_data;
803 hwif->ata_output_data = &cris_ide_output_data; 801 hwif->ata_output_data = &cris_ide_output_data;
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index aa9f5f0b1e67..9560a8f4a86c 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -201,8 +201,7 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
201 return do_rw_taskfile(drive, args); 201 return do_rw_taskfile(drive, args);
202 202
203 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */ 203 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
204 if (drive->hwif->tuneproc != NULL) 204 ide_set_max_pio(drive);
205 drive->hwif->tuneproc(drive, 255);
206 /* 205 /*
207 * skip idedisk_pm_idle for ATAPI devices 206 * skip idedisk_pm_idle for ATAPI devices
208 */ 207 */
@@ -788,6 +787,30 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
788 return ide_started; 787 return ide_started;
789} 788}
790 789
790/*
791 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
792 */
793static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
794{
795 switch (req_pio) {
796 case 202:
797 case 201:
798 case 200:
799 case 102:
800 case 101:
801 case 100:
802 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
803 case 9:
804 case 8:
805 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
806 case 7:
807 case 6:
808 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
809 default:
810 return 0;
811 }
812}
813
791/** 814/**
792 * do_special - issue some special commands 815 * do_special - issue some special commands
793 * @drive: drive the command is for 816 * @drive: drive the command is for
@@ -805,9 +828,17 @@ static ide_startstop_t do_special (ide_drive_t *drive)
805 printk("%s: do_special: 0x%02x\n", drive->name, s->all); 828 printk("%s: do_special: 0x%02x\n", drive->name, s->all);
806#endif 829#endif
807 if (s->b.set_tune) { 830 if (s->b.set_tune) {
831 ide_hwif_t *hwif = drive->hwif;
832 u8 req_pio = drive->tune_req;
833
808 s->b.set_tune = 0; 834 s->b.set_tune = 0;
809 if (HWIF(drive)->tuneproc != NULL) 835
810 HWIF(drive)->tuneproc(drive, drive->tune_req); 836 if (set_pio_mode_abuse(drive->hwif, req_pio)) {
837 if (hwif->set_pio_mode)
838 hwif->set_pio_mode(drive, req_pio);
839 } else
840 ide_set_pio(drive, req_pio);
841
811 return ide_stopped; 842 return ide_stopped;
812 } else { 843 } else {
813 if (drive->media == ide_disk) 844 if (drive->media == ide_disk)
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 646a54e233d3..cf0678b61161 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -780,12 +780,6 @@ int ide_driveid_update (ide_drive_t *drive)
780 780
781/* 781/*
782 * Similar to ide_wait_stat(), except it never calls ide_error internally. 782 * Similar to ide_wait_stat(), except it never calls ide_error internally.
783 * This is a kludge to handle the new ide_config_drive_speed() function,
784 * and should not otherwise be used anywhere. Eventually, the tuneproc's
785 * should be updated to return ide_startstop_t, in which case we can get
786 * rid of this abomination again. :) -ml
787 *
788 * It is gone..........
789 * 783 *
790 * const char *msg == consider adding for verbose errors. 784 * const char *msg == consider adding for verbose errors.
791 */ 785 */
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 957618849540..8400b1b4aa1b 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -325,6 +325,35 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
325 325
326EXPORT_SYMBOL_GPL(ide_get_best_pio_mode); 326EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
327 327
328/* req_pio == "255" for auto-tune */
329void ide_set_pio(ide_drive_t *drive, u8 req_pio)
330{
331 ide_hwif_t *hwif = drive->hwif;
332 u8 host_pio, pio;
333
334 if (hwif->set_pio_mode == NULL)
335 return;
336
337 BUG_ON(hwif->pio_mask == 0x00);
338
339 host_pio = fls(hwif->pio_mask) - 1;
340
341 pio = ide_get_best_pio_mode(drive, req_pio, host_pio);
342
343 /*
344 * TODO:
345 * - report device max PIO mode
346 * - check req_pio != 255 against device max PIO mode
347 */
348 printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n",
349 drive->name, host_pio, req_pio,
350 req_pio == 255 ? "(auto-tune)" : "", pio);
351
352 hwif->set_pio_mode(drive, pio);
353}
354
355EXPORT_SYMBOL_GPL(ide_set_pio);
356
328/** 357/**
329 * ide_toggle_bounce - handle bounce buffering 358 * ide_toggle_bounce - handle bounce buffering
330 * @drive: drive to update 359 * @drive: drive to update
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 3a2a9a338fd9..b4c9f63a3854 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -827,10 +827,8 @@ static void probe_hwif(ide_hwif_t *hwif, void (*fixup)(ide_hwif_t *hwif))
827 ide_drive_t *drive = &hwif->drives[unit]; 827 ide_drive_t *drive = &hwif->drives[unit];
828 828
829 if (drive->present) { 829 if (drive->present) {
830 if (hwif->tuneproc != NULL && 830 if (drive->autotune == IDE_TUNE_AUTO)
831 drive->autotune == IDE_TUNE_AUTO) 831 ide_set_max_pio(drive);
832 /* auto-tune PIO mode */
833 hwif->tuneproc(drive, 255);
834 832
835 if (drive->autotune != IDE_TUNE_DEFAULT && 833 if (drive->autotune != IDE_TUNE_DEFAULT &&
836 drive->autotune != IDE_TUNE_AUTO) 834 drive->autotune != IDE_TUNE_AUTO)
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 9fdc1fe1b299..e96212ce5729 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -396,7 +396,7 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
396 hwif->cds = tmp_hwif->cds; 396 hwif->cds = tmp_hwif->cds;
397#endif 397#endif
398 398
399 hwif->tuneproc = tmp_hwif->tuneproc; 399 hwif->set_pio_mode = tmp_hwif->set_pio_mode;
400 hwif->speedproc = tmp_hwif->speedproc; 400 hwif->speedproc = tmp_hwif->speedproc;
401 hwif->mdma_filter = tmp_hwif->mdma_filter; 401 hwif->mdma_filter = tmp_hwif->mdma_filter;
402 hwif->udma_filter = tmp_hwif->udma_filter; 402 hwif->udma_filter = tmp_hwif->udma_filter;
@@ -867,8 +867,9 @@ int set_pio_mode(ide_drive_t *drive, int arg)
867 if (arg < 0 || arg > 255) 867 if (arg < 0 || arg > 255)
868 return -EINVAL; 868 return -EINVAL;
869 869
870 if (!HWIF(drive)->tuneproc) 870 if (drive->hwif->set_pio_mode == NULL)
871 return -ENOSYS; 871 return -ENOSYS;
872
872 if (drive->special.b.set_tune) 873 if (drive->special.b.set_tune)
873 return -EBUSY; 874 return -EBUSY;
874 ide_init_drive_cmd(&rq); 875 ide_init_drive_cmd(&rq);
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 9b9c4761cb7d..2f0ef9b44033 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -68,8 +68,6 @@ static RegInitializer initData[] __initdata = {
68 {0x35, 0x03}, {0x00, 0x00} 68 {0x35, 0x03}, {0x00, 0x00}
69}; 69};
70 70
71#define ALI_MAX_PIO 4
72
73/* timing parameter registers for each drive */ 71/* timing parameter registers for each drive */
74static struct { u8 reg1, reg2, reg3, reg4; } regTab[4] = { 72static struct { u8 reg1, reg2, reg3, reg4; } regTab[4] = {
75 {0x03, 0x26, 0x04, 0x27}, /* drive 0 */ 73 {0x03, 0x26, 0x04, 0x27}, /* drive 0 */
@@ -109,7 +107,7 @@ static void outReg (u8 data, u8 reg)
109 * This function computes timing parameters 107 * This function computes timing parameters
110 * and sets controller registers accordingly. 108 * and sets controller registers accordingly.
111 */ 109 */
112static void ali14xx_tune_drive (ide_drive_t *drive, u8 pio) 110static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
113{ 111{
114 int driveNum; 112 int driveNum;
115 int time1, time2; 113 int time1, time2;
@@ -117,8 +115,6 @@ static void ali14xx_tune_drive (ide_drive_t *drive, u8 pio)
117 unsigned long flags; 115 unsigned long flags;
118 int bus_speed = system_bus_clock(); 116 int bus_speed = system_bus_clock();
119 117
120 pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO);
121
122 /* calculate timing, according to PIO mode */ 118 /* calculate timing, according to PIO mode */
123 time1 = ide_pio_cycle_time(drive, pio); 119 time1 = ide_pio_cycle_time(drive, pio);
124 time2 = ide_pio_timings[pio].active_time; 120 time2 = ide_pio_timings[pio].active_time;
@@ -212,12 +208,12 @@ static int __init ali14xx_probe(void)
212 208
213 hwif->chipset = ide_ali14xx; 209 hwif->chipset = ide_ali14xx;
214 hwif->pio_mask = ATA_PIO4; 210 hwif->pio_mask = ATA_PIO4;
215 hwif->tuneproc = &ali14xx_tune_drive; 211 hwif->set_pio_mode = &ali14xx_set_pio_mode;
216 hwif->mate = mate; 212 hwif->mate = mate;
217 213
218 mate->chipset = ide_ali14xx; 214 mate->chipset = ide_ali14xx;
219 mate->pio_mask = ATA_PIO4; 215 mate->pio_mask = ATA_PIO4;
220 mate->tuneproc = &ali14xx_tune_drive; 216 mate->set_pio_mode = &ali14xx_set_pio_mode;
221 mate->mate = hwif; 217 mate->mate = hwif;
222 mate->channel = 1; 218 mate->channel = 1;
223 219
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index 6c01d951d074..f16521254867 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/dtc2278.c
@@ -67,12 +67,10 @@ static void sub22 (char b, char c)
67 } 67 }
68} 68}
69 69
70static void tune_dtc2278 (ide_drive_t *drive, u8 pio) 70static void dtc2278_set_pio_mode(ide_drive_t *drive, const u8 pio)
71{ 71{
72 unsigned long flags; 72 unsigned long flags;
73 73
74 pio = ide_get_best_pio_mode(drive, pio, 4);
75
76 if (pio >= 3) { 74 if (pio >= 3) {
77 spin_lock_irqsave(&ide_lock, flags); 75 spin_lock_irqsave(&ide_lock, flags);
78 /* 76 /*
@@ -124,7 +122,7 @@ static int __init dtc2278_probe(void)
124 hwif->serialized = 1; 122 hwif->serialized = 1;
125 hwif->chipset = ide_dtc2278; 123 hwif->chipset = ide_dtc2278;
126 hwif->pio_mask = ATA_PIO4; 124 hwif->pio_mask = ATA_PIO4;
127 hwif->tuneproc = &tune_dtc2278; 125 hwif->set_pio_mode = &dtc2278_set_pio_mode;
128 hwif->drives[0].no_unmask = 1; 126 hwif->drives[0].no_unmask = 1;
129 hwif->drives[1].no_unmask = 1; 127 hwif->drives[1].no_unmask = 1;
130 hwif->mate = mate; 128 hwif->mate = mate;
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index bfaa2025173b..2e5a9cc5c0f7 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -199,7 +199,7 @@ static int __init try_to_init_ht6560b(void)
199 return 1; 199 return 1;
200} 200}
201 201
202static u8 ht_pio2timings(ide_drive_t *drive, u8 pio) 202static u8 ht_pio2timings(ide_drive_t *drive, const u8 pio)
203{ 203{
204 int active_time, recovery_time; 204 int active_time, recovery_time;
205 int active_cycles, recovery_cycles; 205 int active_cycles, recovery_cycles;
@@ -208,7 +208,6 @@ static u8 ht_pio2timings(ide_drive_t *drive, u8 pio)
208 if (pio) { 208 if (pio) {
209 unsigned int cycle_time; 209 unsigned int cycle_time;
210 210
211 pio = ide_get_best_pio_mode(drive, pio, 5);
212 cycle_time = ide_pio_cycle_time(drive, pio); 211 cycle_time = ide_pio_cycle_time(drive, pio);
213 212
214 /* 213 /*
@@ -277,7 +276,7 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
277#endif 276#endif
278} 277}
279 278
280static void tune_ht6560b (ide_drive_t *drive, u8 pio) 279static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio)
281{ 280{
282 unsigned long flags; 281 unsigned long flags;
283 u8 timing; 282 u8 timing;
@@ -333,15 +332,17 @@ int __init ht6560b_init(void)
333 332
334 hwif->chipset = ide_ht6560b; 333 hwif->chipset = ide_ht6560b;
335 hwif->selectproc = &ht6560b_selectproc; 334 hwif->selectproc = &ht6560b_selectproc;
335 hwif->host_flags = IDE_HFLAG_ABUSE_PREFETCH;
336 hwif->pio_mask = ATA_PIO5; 336 hwif->pio_mask = ATA_PIO5;
337 hwif->tuneproc = &tune_ht6560b; 337 hwif->set_pio_mode = &ht6560b_set_pio_mode;
338 hwif->serialized = 1; /* is this needed? */ 338 hwif->serialized = 1; /* is this needed? */
339 hwif->mate = mate; 339 hwif->mate = mate;
340 340
341 mate->chipset = ide_ht6560b; 341 mate->chipset = ide_ht6560b;
342 mate->selectproc = &ht6560b_selectproc; 342 mate->selectproc = &ht6560b_selectproc;
343 mate->host_flags = IDE_HFLAG_ABUSE_PREFETCH;
343 mate->pio_mask = ATA_PIO5; 344 mate->pio_mask = ATA_PIO5;
344 mate->tuneproc = &tune_ht6560b; 345 mate->set_pio_mode = &ht6560b_set_pio_mode;
345 mate->serialized = 1; /* is this needed? */ 346 mate->serialized = 1; /* is this needed? */
346 mate->mate = hwif; 347 mate->mate = hwif;
347 mate->channel = 1; 348 mate->channel = 1;
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index 8b87a424094a..0c81d2d0b941 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -224,15 +224,14 @@ static void qd_set_timing (ide_drive_t *drive, u8 timing)
224 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing); 224 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing);
225} 225}
226 226
227/* 227static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio)
228 * qd6500_tune_drive
229 */
230
231static void qd6500_tune_drive (ide_drive_t *drive, u8 pio)
232{ 228{
233 int active_time = 175; 229 int active_time = 175;
234 int recovery_time = 415; /* worst case values from the dos driver */ 230 int recovery_time = 415; /* worst case values from the dos driver */
235 231
232 /*
233 * FIXME: use "pio" value
234 */
236 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time) 235 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)
237 && drive->id->tPIO && (drive->id->field_valid & 0x02) 236 && drive->id->tPIO && (drive->id->field_valid & 0x02)
238 && drive->id->eide_pio >= 240) { 237 && drive->id->eide_pio >= 240) {
@@ -246,11 +245,7 @@ static void qd6500_tune_drive (ide_drive_t *drive, u8 pio)
246 qd_set_timing(drive, qd6500_compute_timing(HWIF(drive), active_time, recovery_time)); 245 qd_set_timing(drive, qd6500_compute_timing(HWIF(drive), active_time, recovery_time));
247} 246}
248 247
249/* 248static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio)
250 * qd6580_tune_drive
251 */
252
253static void qd6580_tune_drive (ide_drive_t *drive, u8 pio)
254{ 249{
255 int base = HWIF(drive)->select_data; 250 int base = HWIF(drive)->select_data;
256 unsigned int cycle_time; 251 unsigned int cycle_time;
@@ -258,7 +253,6 @@ static void qd6580_tune_drive (ide_drive_t *drive, u8 pio)
258 int recovery_time = 415; /* worst case values from the dos driver */ 253 int recovery_time = 415; /* worst case values from the dos driver */
259 254
260 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) { 255 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) {
261 pio = ide_get_best_pio_mode(drive, pio, 4);
262 cycle_time = ide_pio_cycle_time(drive, pio); 256 cycle_time = ide_pio_cycle_time(drive, pio);
263 257
264 switch (pio) { 258 switch (pio) {
@@ -335,8 +329,7 @@ static int __init qd_testreg(int port)
335 */ 329 */
336 330
337static void __init qd_setup(ide_hwif_t *hwif, int base, int config, 331static void __init qd_setup(ide_hwif_t *hwif, int base, int config,
338 unsigned int data0, unsigned int data1, 332 unsigned int data0, unsigned int data1)
339 void (*tuneproc) (ide_drive_t *, u8 pio))
340{ 333{
341 hwif->chipset = ide_qd65xx; 334 hwif->chipset = ide_qd65xx;
342 hwif->channel = hwif->index; 335 hwif->channel = hwif->index;
@@ -347,8 +340,6 @@ static void __init qd_setup(ide_hwif_t *hwif, int base, int config,
347 hwif->drives[0].io_32bit = 340 hwif->drives[0].io_32bit =
348 hwif->drives[1].io_32bit = 1; 341 hwif->drives[1].io_32bit = 1;
349 hwif->pio_mask = ATA_PIO4; 342 hwif->pio_mask = ATA_PIO4;
350 hwif->tuneproc = tuneproc;
351 probe_hwif_init(hwif);
352} 343}
353 344
354/* 345/*
@@ -361,7 +352,7 @@ static void __exit qd_unsetup(ide_hwif_t *hwif)
361{ 352{
362 u8 config = hwif->config_data; 353 u8 config = hwif->config_data;
363 int base = hwif->select_data; 354 int base = hwif->select_data;
364 void *tuneproc = (void *) hwif->tuneproc; 355 void *set_pio_mode = (void *)hwif->set_pio_mode;
365 356
366 if (hwif->chipset != ide_qd65xx) 357 if (hwif->chipset != ide_qd65xx)
367 return; 358 return;
@@ -369,12 +360,12 @@ static void __exit qd_unsetup(ide_hwif_t *hwif)
369 printk(KERN_NOTICE "%s: back to defaults\n", hwif->name); 360 printk(KERN_NOTICE "%s: back to defaults\n", hwif->name);
370 361
371 hwif->selectproc = NULL; 362 hwif->selectproc = NULL;
372 hwif->tuneproc = NULL; 363 hwif->set_pio_mode = NULL;
373 364
374 if (tuneproc == (void *) qd6500_tune_drive) { 365 if (set_pio_mode == (void *)qd6500_set_pio_mode) {
375 // will do it for both 366 // will do it for both
376 qd_write_reg(QD6500_DEF_DATA, QD_TIMREG(&hwif->drives[0])); 367 qd_write_reg(QD6500_DEF_DATA, QD_TIMREG(&hwif->drives[0]));
377 } else if (tuneproc == (void *) qd6580_tune_drive) { 368 } else if (set_pio_mode == (void *)qd6580_set_pio_mode) {
378 if (QD_CONTROL(hwif) & QD_CONTR_SEC_DISABLED) { 369 if (QD_CONTROL(hwif) & QD_CONTR_SEC_DISABLED) {
379 qd_write_reg(QD6580_DEF_DATA, QD_TIMREG(&hwif->drives[0])); 370 qd_write_reg(QD6580_DEF_DATA, QD_TIMREG(&hwif->drives[0]));
380 qd_write_reg(QD6580_DEF_DATA2, QD_TIMREG(&hwif->drives[1])); 371 qd_write_reg(QD6580_DEF_DATA2, QD_TIMREG(&hwif->drives[1]));
@@ -424,8 +415,11 @@ static int __init qd_probe(int base)
424 return 1; 415 return 1;
425 } 416 }
426 417
427 qd_setup(hwif, base, config, QD6500_DEF_DATA, QD6500_DEF_DATA, 418 qd_setup(hwif, base, config, QD6500_DEF_DATA, QD6500_DEF_DATA);
428 &qd6500_tune_drive); 419
420 hwif->set_pio_mode = &qd6500_set_pio_mode;
421
422 probe_hwif_init(hwif);
429 423
430 ide_proc_register_port(hwif); 424 ide_proc_register_port(hwif);
431 425
@@ -455,8 +449,12 @@ static int __init qd_probe(int base)
455 printk(KERN_INFO "%s: qd6580: single IDE board\n", 449 printk(KERN_INFO "%s: qd6580: single IDE board\n",
456 hwif->name); 450 hwif->name);
457 qd_setup(hwif, base, config | (control << 8), 451 qd_setup(hwif, base, config | (control << 8),
458 QD6580_DEF_DATA, QD6580_DEF_DATA2, 452 QD6580_DEF_DATA, QD6580_DEF_DATA2);
459 &qd6580_tune_drive); 453
454 hwif->set_pio_mode = &qd6580_set_pio_mode;
455
456 probe_hwif_init(hwif);
457
460 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT); 458 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT);
461 459
462 ide_proc_register_port(hwif); 460 ide_proc_register_port(hwif);
@@ -472,11 +470,19 @@ static int __init qd_probe(int base)
472 hwif->name, mate->name); 470 hwif->name, mate->name);
473 471
474 qd_setup(hwif, base, config | (control << 8), 472 qd_setup(hwif, base, config | (control << 8),
475 QD6580_DEF_DATA, QD6580_DEF_DATA, 473 QD6580_DEF_DATA, QD6580_DEF_DATA);
476 &qd6580_tune_drive); 474
475 hwif->set_pio_mode = &qd6580_set_pio_mode;
476
477 probe_hwif_init(hwif);
478
477 qd_setup(mate, base, config | (control << 8), 479 qd_setup(mate, base, config | (control << 8),
478 QD6580_DEF_DATA2, QD6580_DEF_DATA2, 480 QD6580_DEF_DATA2, QD6580_DEF_DATA2);
479 &qd6580_tune_drive); 481
482 mate->set_pio_mode = &qd6580_set_pio_mode;
483
484 probe_hwif_init(mate);
485
480 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT); 486 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT);
481 487
482 ide_proc_register_port(hwif); 488 ide_proc_register_port(hwif);
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index d2862e638bc5..1151c92dd531 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/umc8672.c
@@ -105,12 +105,11 @@ static void umc_set_speeds (u8 speeds[])
105 speeds[0], speeds[1], speeds[2], speeds[3]); 105 speeds[0], speeds[1], speeds[2], speeds[3]);
106} 106}
107 107
108static void tune_umc (ide_drive_t *drive, u8 pio) 108static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio)
109{ 109{
110 unsigned long flags; 110 unsigned long flags;
111 ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup; 111 ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup;
112 112
113 pio = ide_get_best_pio_mode(drive, pio, 4);
114 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", 113 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n",
115 drive->name, pio, pio_to_umc[pio]); 114 drive->name, pio, pio_to_umc[pio]);
116 spin_lock_irqsave(&ide_lock, flags); 115 spin_lock_irqsave(&ide_lock, flags);
@@ -150,12 +149,12 @@ static int __init umc8672_probe(void)
150 149
151 hwif->chipset = ide_umc8672; 150 hwif->chipset = ide_umc8672;
152 hwif->pio_mask = ATA_PIO4; 151 hwif->pio_mask = ATA_PIO4;
153 hwif->tuneproc = &tune_umc; 152 hwif->set_pio_mode = &umc_set_pio_mode;
154 hwif->mate = mate; 153 hwif->mate = mate;
155 154
156 mate->chipset = ide_umc8672; 155 mate->chipset = ide_umc8672;
157 mate->pio_mask = ATA_PIO4; 156 mate->pio_mask = ATA_PIO4;
158 mate->tuneproc = &tune_umc; 157 mate->set_pio_mode = &umc_set_pio_mode;
159 mate->mate = hwif; 158 mate->mate = hwif;
160 mate->channel = 1; 159 mate->channel = 1;
161 160
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index b04db9ff1938..670cb748481f 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -99,18 +99,12 @@ void auide_outsw(unsigned long port, void *addr, u32 count)
99 99
100#endif 100#endif
101 101
102static void auide_tune_drive(ide_drive_t *drive, byte pio) 102static void au1xxx_set_pio_mode(ide_drive_t *drive, const u8 pio)
103{ 103{
104 int mem_sttime; 104 int mem_sttime;
105 int mem_stcfg; 105 int mem_stcfg;
106 u8 speed; 106 u8 speed;
107 107
108 /* get the best pio mode for the drive */
109 pio = ide_get_best_pio_mode(drive, pio, 4);
110
111 printk(KERN_INFO "%s: setting Au1XXX IDE to PIO mode%d\n",
112 drive->name, pio);
113
114 mem_sttime = 0; 108 mem_sttime = 0;
115 mem_stcfg = au_readl(MEM_STCFG2); 109 mem_stcfg = au_readl(MEM_STCFG2);
116 110
@@ -184,7 +178,7 @@ static int auide_tune_chipset(ide_drive_t *drive, const u8 speed)
184 mem_stcfg = au_readl(MEM_STCFG2); 178 mem_stcfg = au_readl(MEM_STCFG2);
185 179
186 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) { 180 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
187 auide_tune_drive(drive, speed - XFER_PIO_0); 181 au1xxx_set_pio_mode(drive, speed - XFER_PIO_0);
188 return 0; 182 return 0;
189 } 183 }
190 184
@@ -712,7 +706,7 @@ static int au_ide_probe(struct device *dev)
712 hwif->OUTSW = auide_outsw; 706 hwif->OUTSW = auide_outsw;
713#endif 707#endif
714 708
715 hwif->tuneproc = &auide_tune_drive; 709 hwif->set_pio_mode = &au1xxx_set_pio_mode;
716 hwif->speedproc = &auide_tune_chipset; 710 hwif->speedproc = &auide_tune_chipset;
717 711
718#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 712#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index a827ea2ab989..0d5f62c5dfae 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -138,9 +138,8 @@ static int aec6260_tune_chipset(ide_drive_t *drive, const u8 speed)
138 return(ide_config_drive_speed(drive, speed)); 138 return(ide_config_drive_speed(drive, speed));
139} 139}
140 140
141static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio) 141static void aec_set_pio_mode(ide_drive_t *drive, const u8 pio)
142{ 142{
143 pio = ide_get_best_pio_mode(drive, pio, 4);
144 (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0); 143 (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0);
145} 144}
146 145
@@ -150,7 +149,7 @@ static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
150 return 0; 149 return 0;
151 150
152 if (ide_use_fast_pio(drive)) 151 if (ide_use_fast_pio(drive))
153 aec62xx_tune_drive(drive, 255); 152 ide_set_max_pio(drive);
154 153
155 return -1; 154 return -1;
156} 155}
@@ -201,7 +200,7 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
201 u8 reg54 = 0, mask = hwif->channel ? 0xf0 : 0x0f; 200 u8 reg54 = 0, mask = hwif->channel ? 0xf0 : 0x0f;
202 unsigned long flags; 201 unsigned long flags;
203 202
204 hwif->tuneproc = &aec62xx_tune_drive; 203 hwif->set_pio_mode = &aec_set_pio_mode;
205 204
206 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) { 205 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
207 if(hwif->mate) 206 if(hwif->mate)
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 37ecd726aa40..005402ab748b 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -283,17 +283,14 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
283#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */ 283#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
284 284
285/** 285/**
286 * ali15x3_tune_pio - set up chipset for PIO mode 286 * ali_tune_pio - set host controller for PIO mode
287 * @drive: drive to tune 287 * @drive: drive
288 * @pio: desired mode 288 * @pio: PIO mode number
289 *
290 * Select the best PIO mode for the drive in question.
291 * Then program the controller for this mode.
292 * 289 *
293 * Returns the PIO mode programmed. 290 * Program the controller for the given PIO mode.
294 */ 291 */
295 292
296static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio) 293static void ali_tune_pio(ide_drive_t *drive, const u8 pio)
297{ 294{
298 ide_hwif_t *hwif = HWIF(drive); 295 ide_hwif_t *hwif = HWIF(drive);
299 struct pci_dev *dev = hwif->pci_dev; 296 struct pci_dev *dev = hwif->pci_dev;
@@ -306,7 +303,6 @@ static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio)
306 u8 cd_dma_fifo = 0; 303 u8 cd_dma_fifo = 0;
307 int unit = drive->select.b.unit & 1; 304 int unit = drive->select.b.unit & 1;
308 305
309 pio = ide_get_best_pio_mode(drive, pio, 5);
310 s_time = ide_pio_timings[pio].setup_time; 306 s_time = ide_pio_timings[pio].setup_time;
311 a_time = ide_pio_timings[pio].active_time; 307 a_time = ide_pio_timings[pio].active_time;
312 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) 308 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
@@ -359,22 +355,20 @@ static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio)
359 * { 25, 70, 25 }, PIO Mode 4 with IORDY ns 355 * { 25, 70, 25 }, PIO Mode 4 with IORDY ns
360 * { 20, 50, 30 } PIO Mode 5 with IORDY (nonstandard) 356 * { 20, 50, 30 } PIO Mode 5 with IORDY (nonstandard)
361 */ 357 */
362
363 return pio;
364} 358}
365 359
366/** 360/**
367 * ali15x3_tune_drive - set up drive for PIO mode 361 * ali_set_pio_mode - set up drive for PIO mode
368 * @drive: drive to tune 362 * @drive: drive to tune
369 * @pio: desired mode 363 * @pio: desired mode
370 * 364 *
371 * Program the controller with the best PIO timing for the given drive. 365 * Program the controller with the desired PIO timing for the given drive.
372 * Then set up the drive itself. 366 * Then set up the drive itself.
373 */ 367 */
374 368
375static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio) 369static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
376{ 370{
377 pio = ali15x3_tune_pio(drive, pio); 371 ali_tune_pio(drive, pio);
378 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 372 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
379} 373}
380 374
@@ -437,7 +431,7 @@ static int ali15x3_tune_chipset(ide_drive_t *drive, const u8 speed)
437 pci_write_config_byte(dev, m5229_udma, tmpbyte); 431 pci_write_config_byte(dev, m5229_udma, tmpbyte);
438 432
439 if (speed < XFER_SW_DMA_0) 433 if (speed < XFER_SW_DMA_0)
440 (void) ali15x3_tune_pio(drive, speed - XFER_PIO_0); 434 ali_tune_pio(drive, speed - XFER_PIO_0);
441 } else { 435 } else {
442 pci_read_config_byte(dev, m5229_udma, &tmpbyte); 436 pci_read_config_byte(dev, m5229_udma, &tmpbyte);
443 tmpbyte &= (0x0f << ((1-unit) << 2)); 437 tmpbyte &= (0x0f << ((1-unit) << 2));
@@ -470,7 +464,7 @@ static int ali15x3_config_drive_for_dma(ide_drive_t *drive)
470 if (ide_tune_dma(drive)) 464 if (ide_tune_dma(drive))
471 return 0; 465 return 0;
472 466
473 ali15x3_tune_drive(drive, 255); 467 ide_set_max_pio(drive);
474 468
475 return -1; 469 return -1;
476} 470}
@@ -700,7 +694,7 @@ static u8 __devinit ata66_ali15x3(ide_hwif_t *hwif)
700static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif) 694static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
701{ 695{
702 hwif->autodma = 0; 696 hwif->autodma = 0;
703 hwif->tuneproc = &ali15x3_tune_drive; 697 hwif->set_pio_mode = &ali_set_pio_mode;
704 hwif->speedproc = &ali15x3_tune_chipset; 698 hwif->speedproc = &ali15x3_tune_chipset;
705 hwif->udma_filter = &ali_udma_filter; 699 hwif->udma_filter = &ali_udma_filter;
706 700
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 9abbde3c7984..1088ba86cd1d 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -266,16 +266,12 @@ static int amd_set_drive(ide_drive_t *drive, const u8 speed)
266} 266}
267 267
268/* 268/*
269 * amd74xx_tune_drive() is a callback from upper layers for 269 * amd_set_pio_mode() is a callback from upper layers for PIO-only tuning.
270 * PIO-only tuning.
271 */ 270 */
272 271
273static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio) 272static void amd_set_pio_mode(ide_drive_t *drive, const u8 pio)
274{ 273{
275 if (pio == 255) 274 amd_set_drive(drive, XFER_PIO_0 + pio);
276 pio = ide_get_best_pio_mode(drive, 255, 5);
277
278 amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5));
279} 275}
280 276
281static int amd74xx_ide_dma_check(ide_drive_t *drive) 277static int amd74xx_ide_dma_check(ide_drive_t *drive)
@@ -283,7 +279,7 @@ static int amd74xx_ide_dma_check(ide_drive_t *drive)
283 u8 speed = ide_max_dma_mode(drive); 279 u8 speed = ide_max_dma_mode(drive);
284 280
285 if (speed == 0) { 281 if (speed == 0) {
286 amd74xx_tune_drive(drive, 255); 282 ide_set_max_pio(drive);
287 return -1; 283 return -1;
288 } 284 }
289 285
@@ -409,7 +405,7 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
409 405
410 hwif->autodma = 0; 406 hwif->autodma = 0;
411 407
412 hwif->tuneproc = &amd74xx_tune_drive; 408 hwif->set_pio_mode = &amd_set_pio_mode;
413 hwif->speedproc = &amd_set_drive; 409 hwif->speedproc = &amd_set_drive;
414 410
415 for (i = 0; i < 2; i++) { 411 for (i = 0; i < 2; i++) {
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index e05e88298500..b9f66f53f9a6 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -153,9 +153,8 @@ static void atiixp_tune_pio(ide_drive_t *drive, u8 pio)
153 spin_unlock_irqrestore(&atiixp_lock, flags); 153 spin_unlock_irqrestore(&atiixp_lock, flags);
154} 154}
155 155
156static void atiixp_tuneproc(ide_drive_t *drive, u8 pio) 156static void atiixp_set_pio_mode(ide_drive_t *drive, const u8 pio)
157{ 157{
158 pio = ide_get_best_pio_mode(drive, pio, 4);
159 atiixp_tune_pio(drive, pio); 158 atiixp_tune_pio(drive, pio);
160 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio); 159 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio);
161} 160}
@@ -231,7 +230,7 @@ static int atiixp_dma_check(ide_drive_t *drive)
231 return 0; 230 return 0;
232 231
233 if (ide_use_fast_pio(drive)) 232 if (ide_use_fast_pio(drive))
234 atiixp_tuneproc(drive, 255); 233 ide_set_max_pio(drive);
235 234
236 return -1; 235 return -1;
237} 236}
@@ -254,7 +253,7 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
254 hwif->irq = ch ? 15 : 14; 253 hwif->irq = ch ? 15 : 14;
255 254
256 hwif->autodma = 0; 255 hwif->autodma = 0;
257 hwif->tuneproc = &atiixp_tuneproc; 256 hwif->set_pio_mode = &atiixp_set_pio_mode;
258 hwif->speedproc = &atiixp_speedproc; 257 hwif->speedproc = &atiixp_speedproc;
259 hwif->drives[0].autotune = 1; 258 hwif->drives[0].autotune = 1;
260 hwif->drives[1].autotune = 1; 259 hwif->drives[1].autotune = 1;
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index 9689494efa24..f369645e4d16 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -628,45 +628,40 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle
628 program_drive_counts (index); 628 program_drive_counts (index);
629} 629}
630 630
631/* 631static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
632 * Drive PIO mode selection:
633 */
634static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted)
635{ 632{
636 unsigned int index = 0, cycle_time; 633 unsigned int index = 0, cycle_time;
637 u8 b; 634 u8 b;
638 635
639 while (drive != cmd_drives[index]) { 636 while (drive != cmd_drives[index]) {
640 if (++index > 3) { 637 if (++index > 3) {
641 printk("%s: bad news in cmd640_tune_drive\n", drive->name); 638 printk(KERN_ERR "%s: bad news in %s\n",
639 drive->name, __FUNCTION__);
642 return; 640 return;
643 } 641 }
644 } 642 }
645 switch (mode_wanted) { 643 switch (pio) {
646 case 6: /* set fast-devsel off */ 644 case 6: /* set fast-devsel off */
647 case 7: /* set fast-devsel on */ 645 case 7: /* set fast-devsel on */
648 mode_wanted &= 1;
649 b = get_cmd640_reg(CNTRL) & ~0x27; 646 b = get_cmd640_reg(CNTRL) & ~0x27;
650 if (mode_wanted) 647 if (pio & 1)
651 b |= 0x27; 648 b |= 0x27;
652 put_cmd640_reg(CNTRL, b); 649 put_cmd640_reg(CNTRL, b);
653 printk("%s: %sabled cmd640 fast host timing (devsel)\n", drive->name, mode_wanted ? "en" : "dis"); 650 printk("%s: %sabled cmd640 fast host timing (devsel)\n", drive->name, (pio & 1) ? "en" : "dis");
654 return; 651 return;
655 652
656 case 8: /* set prefetch off */ 653 case 8: /* set prefetch off */
657 case 9: /* set prefetch on */ 654 case 9: /* set prefetch on */
658 mode_wanted &= 1; 655 set_prefetch_mode(index, pio & 1);
659 set_prefetch_mode(index, mode_wanted); 656 printk("%s: %sabled cmd640 prefetch\n", drive->name, (pio & 1) ? "en" : "dis");
660 printk("%s: %sabled cmd640 prefetch\n", drive->name, mode_wanted ? "en" : "dis");
661 return; 657 return;
662 } 658 }
663 659
664 mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 5); 660 cycle_time = ide_pio_cycle_time(drive, pio);
665 cycle_time = ide_pio_cycle_time(drive, mode_wanted); 661 cmd640_set_mode(index, pio, cycle_time);
666 cmd640_set_mode(index, mode_wanted, cycle_time);
667 662
668 printk("%s: selected cmd640 PIO mode%d (%dns)", 663 printk("%s: selected cmd640 PIO mode%d (%dns)",
669 drive->name, mode_wanted, cycle_time); 664 drive->name, pio, cycle_time);
670 665
671 display_clocks(index); 666 display_clocks(index);
672} 667}
@@ -766,8 +761,10 @@ int __init ide_probe_for_cmd640x (void)
766 cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr); 761 cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr);
767 cmd_hwif0->chipset = ide_cmd640; 762 cmd_hwif0->chipset = ide_cmd640;
768#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 763#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
764 cmd_hwif0->host_flags = IDE_HFLAG_ABUSE_PREFETCH |
765 IDE_HFLAG_ABUSE_FAST_DEVSEL;
769 cmd_hwif0->pio_mask = ATA_PIO5; 766 cmd_hwif0->pio_mask = ATA_PIO5;
770 cmd_hwif0->tuneproc = &cmd640_tune_drive; 767 cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode;
771#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 768#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
772 769
773 /* 770 /*
@@ -822,8 +819,10 @@ int __init ide_probe_for_cmd640x (void)
822 cmd_hwif1->mate = cmd_hwif0; 819 cmd_hwif1->mate = cmd_hwif0;
823 cmd_hwif1->channel = 1; 820 cmd_hwif1->channel = 1;
824#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 821#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
822 cmd_hwif1->host_flags = IDE_HFLAG_ABUSE_PREFETCH |
823 IDE_HFLAG_ABUSE_FAST_DEVSEL;
825 cmd_hwif1->pio_mask = ATA_PIO5; 824 cmd_hwif1->pio_mask = ATA_PIO5;
826 cmd_hwif1->tuneproc = &cmd640_tune_drive; 825 cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode;
827#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 826#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
828 } 827 }
829 printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name, 828 printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name,
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 5fe50a234ce1..85f5e42eb831 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -214,28 +214,25 @@ static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_
214} 214}
215 215
216/* 216/*
217 * This routine selects drive's best PIO mode and writes into the chipset 217 * This routine writes into the chipset registers
218 * registers setup/active/recovery timings. 218 * PIO setup/active/recovery timings.
219 */ 219 */
220static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted) 220static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
221{ 221{
222 ide_hwif_t *hwif = HWIF(drive); 222 ide_hwif_t *hwif = HWIF(drive);
223 struct pci_dev *dev = hwif->pci_dev; 223 struct pci_dev *dev = hwif->pci_dev;
224 unsigned int cycle_time; 224 unsigned int cycle_time;
225 u8 pio_mode, setup_count, arttim = 0; 225 u8 setup_count, arttim = 0;
226
226 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; 227 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0};
227 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; 228 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23};
228 229
229 pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5); 230 cycle_time = ide_pio_cycle_time(drive, pio);
230 cycle_time = ide_pio_cycle_time(drive, pio_mode);
231
232 cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)\n",
233 drive->name, mode_wanted, pio_mode, cycle_time);
234 231
235 program_cycle_times(drive, cycle_time, 232 program_cycle_times(drive, cycle_time,
236 ide_pio_timings[pio_mode].active_time); 233 ide_pio_timings[pio].active_time);
237 234
238 setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time, 235 setup_count = quantize_timing(ide_pio_timings[pio].setup_time,
239 1000 / system_bus_clock()); 236 1000 / system_bus_clock());
240 237
241 /* 238 /*
@@ -266,16 +263,14 @@ static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted)
266 arttim |= setup_values[setup_count]; 263 arttim |= setup_values[setup_count];
267 (void) pci_write_config_byte(dev, arttim_regs[drive->dn], arttim); 264 (void) pci_write_config_byte(dev, arttim_regs[drive->dn], arttim);
268 cmdprintk("Write 0x%02x to reg 0x%x\n", arttim, arttim_regs[drive->dn]); 265 cmdprintk("Write 0x%02x to reg 0x%x\n", arttim, arttim_regs[drive->dn]);
269
270 return pio_mode;
271} 266}
272 267
273/* 268/*
274 * Attempts to set drive's PIO mode. 269 * Attempts to set drive's PIO mode.
275 * Special cases are 8: prefetch off, 9: prefetch on (both never worked), 270 * Special cases are 8: prefetch off, 9: prefetch on (both never worked)
276 * and 255: auto-select best mode (used at boot time).
277 */ 271 */
278static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio) 272
273static void cmd64x_set_pio_mode(ide_drive_t *drive, const u8 pio)
279{ 274{
280 /* 275 /*
281 * Filter out the prefetch control values 276 * Filter out the prefetch control values
@@ -284,7 +279,7 @@ static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio)
284 if (pio == 8 || pio == 9) 279 if (pio == 8 || pio == 9)
285 return; 280 return;
286 281
287 pio = cmd64x_tune_pio(drive, pio); 282 cmd64x_tune_pio(drive, pio);
288 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 283 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
289} 284}
290 285
@@ -334,7 +329,7 @@ static int cmd64x_tune_chipset(ide_drive_t *drive, const u8 speed)
334 case XFER_PIO_2: 329 case XFER_PIO_2:
335 case XFER_PIO_1: 330 case XFER_PIO_1:
336 case XFER_PIO_0: 331 case XFER_PIO_0:
337 (void) cmd64x_tune_pio(drive, speed - XFER_PIO_0); 332 cmd64x_tune_pio(drive, speed - XFER_PIO_0);
338 break; 333 break;
339 default: 334 default:
340 return 1; 335 return 1;
@@ -352,7 +347,7 @@ static int cmd64x_config_drive_for_dma (ide_drive_t *drive)
352 return 0; 347 return 0;
353 348
354 if (ide_use_fast_pio(drive)) 349 if (ide_use_fast_pio(drive))
355 cmd64x_tune_drive(drive, 255); 350 ide_set_max_pio(drive);
356 351
357 return -1; 352 return -1;
358} 353}
@@ -536,7 +531,7 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
536 531
537 pci_read_config_byte(dev, PCI_REVISION_ID, &rev); 532 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
538 533
539 hwif->tuneproc = &cmd64x_tune_drive; 534 hwif->set_pio_mode = &cmd64x_set_pio_mode;
540 hwif->speedproc = &cmd64x_tune_chipset; 535 hwif->speedproc = &cmd64x_tune_chipset;
541 536
542 hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 537 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
@@ -620,6 +615,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
620 .autodma = AUTODMA, 615 .autodma = AUTODMA,
621 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 616 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
622 .bootable = ON_BOARD, 617 .bootable = ON_BOARD,
618 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
623 .pio_mask = ATA_PIO5, 619 .pio_mask = ATA_PIO5,
624 .udma_mask = 0x00, /* no udma */ 620 .udma_mask = 0x00, /* no udma */
625 },{ /* 1 */ 621 },{ /* 1 */
@@ -630,6 +626,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
630 .autodma = AUTODMA, 626 .autodma = AUTODMA,
631 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 627 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
632 .bootable = ON_BOARD, 628 .bootable = ON_BOARD,
629 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
633 .pio_mask = ATA_PIO5, 630 .pio_mask = ATA_PIO5,
634 .udma_mask = 0x07, /* udma0-2 */ 631 .udma_mask = 0x07, /* udma0-2 */
635 },{ /* 2 */ 632 },{ /* 2 */
@@ -640,6 +637,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
640 .autodma = AUTODMA, 637 .autodma = AUTODMA,
641 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 638 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
642 .bootable = ON_BOARD, 639 .bootable = ON_BOARD,
640 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
643 .pio_mask = ATA_PIO5, 641 .pio_mask = ATA_PIO5,
644 .udma_mask = 0x1f, /* udma0-4 */ 642 .udma_mask = 0x1f, /* udma0-4 */
645 },{ /* 3 */ 643 },{ /* 3 */
@@ -650,6 +648,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
650 .autodma = AUTODMA, 648 .autodma = AUTODMA,
651 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 649 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
652 .bootable = ON_BOARD, 650 .bootable = ON_BOARD,
651 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
653 .pio_mask = ATA_PIO5, 652 .pio_mask = ATA_PIO5,
654 .udma_mask = 0x3f, /* udma0-5 */ 653 .udma_mask = 0x3f, /* udma0-5 */
655 } 654 }
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index af67438328a8..a73c318ff086 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -122,17 +122,16 @@ static int cs5520_tune_chipset(ide_drive_t *drive, const u8 speed)
122 122
123 return error; 123 return error;
124} 124}
125 125
126static void cs5520_tune_drive(ide_drive_t *drive, u8 pio) 126static void cs5520_set_pio_mode(ide_drive_t *drive, const u8 pio)
127{ 127{
128 pio = ide_get_best_pio_mode(drive, pio, 4); 128 cs5520_tune_chipset(drive, XFER_PIO_0 + pio);
129 cs5520_tune_chipset(drive, (XFER_PIO_0 + pio));
130} 129}
131 130
132static int cs5520_config_drive_xfer_rate(ide_drive_t *drive) 131static int cs5520_config_drive_xfer_rate(ide_drive_t *drive)
133{ 132{
134 /* Tune the drive for PIO modes up to PIO 4 */ 133 /* Tune the drive for PIO modes up to PIO 4 */
135 cs5520_tune_drive(drive, 255); 134 ide_set_max_pio(drive);
136 135
137 /* Then tell the core to use DMA operations */ 136 /* Then tell the core to use DMA operations */
138 return 0; 137 return 0;
@@ -164,7 +163,7 @@ static int cs5520_dma_on(ide_drive_t *drive)
164 163
165static void __devinit init_hwif_cs5520(ide_hwif_t *hwif) 164static void __devinit init_hwif_cs5520(ide_hwif_t *hwif)
166{ 165{
167 hwif->tuneproc = &cs5520_tune_drive; 166 hwif->set_pio_mode = &cs5520_set_pio_mode;
168 hwif->speedproc = &cs5520_tune_chipset; 167 hwif->speedproc = &cs5520_tune_chipset;
169 hwif->ide_dma_check = &cs5520_config_drive_xfer_rate; 168 hwif->ide_dma_check = &cs5520_config_drive_xfer_rate;
170 hwif->ide_dma_on = &cs5520_dma_on; 169 hwif->ide_dma_on = &cs5520_dma_on;
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index 518f430c1529..1588a323c5d0 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -71,19 +71,18 @@ static void cs5530_tunepio(ide_drive_t *drive, u8 pio)
71} 71}
72 72
73/** 73/**
74 * cs5530_tuneproc - select/set PIO modes 74 * cs5530_set_pio_mode - set PIO mode
75 * @drive: drive
76 * @pio: PIO mode number
75 * 77 *
76 * cs5530_tuneproc() handles selection/setting of PIO modes 78 * Handles setting of PIO mode for both the chipset and drive.
77 * for both the chipset and drive.
78 * 79 *
79 * The ide_init_cs5530() routine guarantees that all drives 80 * The init_hwif_cs5530() routine guarantees that all drives
80 * will have valid default PIO timings set up before we get here. 81 * will have valid default PIO timings set up before we get here.
81 */ 82 */
82 83
83static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */ 84static void cs5530_set_pio_mode(ide_drive_t *drive, const u8 pio)
84{ 85{
85 pio = ide_get_best_pio_mode(drive, pio, 4);
86
87 if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) 86 if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0)
88 cs5530_tunepio(drive, pio); 87 cs5530_tunepio(drive, pio);
89} 88}
@@ -306,7 +305,7 @@ static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
306 if (hwif->mate) 305 if (hwif->mate)
307 hwif->serialized = hwif->mate->serialized = 1; 306 hwif->serialized = hwif->mate->serialized = 1;
308 307
309 hwif->tuneproc = &cs5530_tuneproc; 308 hwif->set_pio_mode = &cs5530_set_pio_mode;
310 hwif->speedproc = &cs5530_tune_chipset; 309 hwif->speedproc = &cs5530_tune_chipset;
311 310
312 basereg = CS5530_BASEREG(hwif); 311 basereg = CS5530_BASEREG(hwif);
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index bc00e7b62151..383b7eccbcbb 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -147,16 +147,16 @@ static int cs5535_set_drive(ide_drive_t *drive, u8 speed)
147 return 0; 147 return 0;
148} 148}
149 149
150/**** 150/**
151 * cs5535_tuneproc - PIO setup 151 * cs5535_set_pio_mode - PIO setup
152 * @drive: drive to set up 152 * @drive: drive
153 * @pio: mode to use (255 for 'best possible') 153 * @pio: PIO mode number
154 * 154 *
155 * A callback from the upper layers for PIO-only tuning. 155 * A callback from the upper layers for PIO-only tuning.
156 */ 156 */
157static void cs5535_tuneproc(ide_drive_t *drive, u8 pio) 157
158static void cs5535_set_pio_mode(ide_drive_t *drive, const u8 pio)
158{ 159{
159 pio = ide_get_best_pio_mode(drive, pio, 4);
160 ide_config_drive_speed(drive, XFER_PIO_0 + pio); 160 ide_config_drive_speed(drive, XFER_PIO_0 + pio);
161 cs5535_set_speed(drive, XFER_PIO_0 + pio); 161 cs5535_set_speed(drive, XFER_PIO_0 + pio);
162} 162}
@@ -169,7 +169,7 @@ static int cs5535_dma_check(ide_drive_t *drive)
169 return 0; 169 return 0;
170 170
171 if (ide_use_fast_pio(drive)) 171 if (ide_use_fast_pio(drive))
172 cs5535_tuneproc(drive, 255); 172 ide_set_max_pio(drive);
173 173
174 return -1; 174 return -1;
175} 175}
@@ -198,7 +198,7 @@ static void __devinit init_hwif_cs5535(ide_hwif_t *hwif)
198 198
199 hwif->autodma = 0; 199 hwif->autodma = 0;
200 200
201 hwif->tuneproc = &cs5535_tuneproc; 201 hwif->set_pio_mode = &cs5535_set_pio_mode;
202 hwif->speedproc = &cs5535_set_drive; 202 hwif->speedproc = &cs5535_set_drive;
203 hwif->ide_dma_check = &cs5535_dma_check; 203 hwif->ide_dma_check = &cs5535_dma_check;
204 204
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index daa36fcbc8ef..dc278025d318 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -97,9 +97,6 @@
97#define CY82_INDEX_CHANNEL1 0x31 97#define CY82_INDEX_CHANNEL1 0x31
98#define CY82_INDEX_TIMEOUT 0x32 98#define CY82_INDEX_TIMEOUT 0x32
99 99
100/* the max PIO mode - from datasheet */
101#define CY82C693_MAX_PIO 4
102
103/* the min and max PCI bus speed in MHz - from datasheet */ 100/* the min and max PCI bus speed in MHz - from datasheet */
104#define CY82C963_MIN_BUS_SPEED 25 101#define CY82C963_MIN_BUS_SPEED 25
105#define CY82C963_MAX_BUS_SPEED 33 102#define CY82C963_MAX_BUS_SPEED 33
@@ -148,9 +145,6 @@ static void compute_clocks (u8 pio, pio_clocks_t *p_pclk)
148 * so you can play with the idebus=xx parameter 145 * so you can play with the idebus=xx parameter
149 */ 146 */
150 147
151 if (pio > CY82C693_MAX_PIO)
152 pio = CY82C693_MAX_PIO;
153
154 /* let's calc the address setup time clocks */ 148 /* let's calc the address setup time clocks */
155 p_pclk->address_time = (u8)calc_clk(ide_pio_timings[pio].setup_time, bus_speed); 149 p_pclk->address_time = (u8)calc_clk(ide_pio_timings[pio].setup_time, bus_speed);
156 150
@@ -269,10 +263,7 @@ static int cy82c693_ide_dma_on (ide_drive_t *drive)
269 return __ide_dma_on(drive); 263 return __ide_dma_on(drive);
270} 264}
271 265
272/* 266static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
273 * tune ide drive - set PIO mode
274 */
275static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio)
276{ 267{
277 ide_hwif_t *hwif = HWIF(drive); 268 ide_hwif_t *hwif = HWIF(drive);
278 struct pci_dev *dev = hwif->pci_dev; 269 struct pci_dev *dev = hwif->pci_dev;
@@ -329,13 +320,6 @@ static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio)
329 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8); 320 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
330#endif /* CY82C693_DEBUG_LOGS */ 321#endif /* CY82C693_DEBUG_LOGS */
331 322
332 /* first let's calc the pio modes */
333 pio = ide_get_best_pio_mode(drive, pio, CY82C693_MAX_PIO);
334
335#if CY82C693_DEBUG_INFO
336 printk (KERN_INFO "%s: Selected PIO mode %d\n", drive->name, pio);
337#endif /* CY82C693_DEBUG_INFO */
338
339 /* let's calc the values for this PIO mode */ 323 /* let's calc the values for this PIO mode */
340 compute_clocks(pio, &pclk); 324 compute_clocks(pio, &pclk);
341 325
@@ -447,7 +431,7 @@ static void __devinit init_hwif_cy82c693(ide_hwif_t *hwif)
447 hwif->autodma = 0; 431 hwif->autodma = 0;
448 432
449 hwif->chipset = ide_cy82c693; 433 hwif->chipset = ide_cy82c693;
450 hwif->tuneproc = &cy82c693_tune_drive; 434 hwif->set_pio_mode = &cy82c693_set_pio_mode;
451 435
452 if (!hwif->dma_base) { 436 if (!hwif->dma_base) {
453 hwif->drives[0].autotune = 1; 437 hwif->drives[0].autotune = 1;
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index ba982d66ff73..a1bb10188fe5 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -77,9 +77,8 @@ static int hpt34x_tune_chipset(ide_drive_t *drive, const u8 speed)
77 return(ide_config_drive_speed(drive, speed)); 77 return(ide_config_drive_speed(drive, speed));
78} 78}
79 79
80static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) 80static void hpt34x_set_pio_mode(ide_drive_t *drive, const u8 pio)
81{ 81{
82 pio = ide_get_best_pio_mode(drive, pio, 5);
83 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); 82 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio));
84} 83}
85 84
@@ -91,7 +90,7 @@ static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive)
91 return -1; 90 return -1;
92 91
93 if (ide_use_fast_pio(drive)) 92 if (ide_use_fast_pio(drive))
94 hpt34x_tune_drive(drive, 255); 93 ide_set_max_pio(drive);
95 94
96 return -1; 95 return -1;
97} 96}
@@ -145,7 +144,7 @@ static void __devinit init_hwif_hpt34x(ide_hwif_t *hwif)
145 144
146 hwif->autodma = 0; 145 hwif->autodma = 0;
147 146
148 hwif->tuneproc = &hpt34x_tune_drive; 147 hwif->set_pio_mode = &hpt34x_set_pio_mode;
149 hwif->speedproc = &hpt34x_tune_chipset; 148 hwif->speedproc = &hpt34x_tune_chipset;
150 hwif->drives[0].autotune = 1; 149 hwif->drives[0].autotune = 1;
151 hwif->drives[1].autotune = 1; 150 hwif->drives[1].autotune = 1;
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 67127ac3a14a..0e7d3b60d43c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -662,9 +662,8 @@ static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed)
662 return hpt36x_tune_chipset(drive, speed); 662 return hpt36x_tune_chipset(drive, speed);
663} 663}
664 664
665static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio) 665static void hpt3xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
666{ 666{
667 pio = ide_get_best_pio_mode(drive, pio, 4);
668 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio); 667 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio);
669} 668}
670 669
@@ -726,7 +725,7 @@ static int hpt366_config_drive_xfer_rate(ide_drive_t *drive)
726 return 0; 725 return 0;
727 726
728 if (ide_use_fast_pio(drive)) 727 if (ide_use_fast_pio(drive))
729 hpt3xx_tune_drive(drive, 255); 728 ide_set_max_pio(drive);
730 729
731 return -1; 730 return -1;
732} 731}
@@ -1257,7 +1256,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1257 /* Cache the channel's MISC. control registers' offset */ 1256 /* Cache the channel's MISC. control registers' offset */
1258 hwif->select_data = hwif->channel ? 0x54 : 0x50; 1257 hwif->select_data = hwif->channel ? 0x54 : 0x50;
1259 1258
1260 hwif->tuneproc = &hpt3xx_tune_drive; 1259 hwif->set_pio_mode = &hpt3xx_set_pio_mode;
1261 hwif->speedproc = &hpt3xx_tune_chipset; 1260 hwif->speedproc = &hpt3xx_tune_chipset;
1262 hwif->quirkproc = &hpt3xx_quirkproc; 1261 hwif->quirkproc = &hpt3xx_quirkproc;
1263 hwif->intrproc = &hpt3xx_intrproc; 1262 hwif->intrproc = &hpt3xx_intrproc;
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 6fa955749aec..d07771e06b2d 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -105,9 +105,8 @@ static void it8213_tune_pio(ide_drive_t *drive, const u8 pio)
105 spin_unlock_irqrestore(&tune_lock, flags); 105 spin_unlock_irqrestore(&tune_lock, flags);
106} 106}
107 107
108static void it8213_tuneproc(ide_drive_t *drive, u8 pio) 108static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
109{ 109{
110 pio = ide_get_best_pio_mode(drive, pio, 4);
111 it8213_tune_pio(drive, pio); 110 it8213_tune_pio(drive, pio);
112 ide_config_drive_speed(drive, XFER_PIO_0 + pio); 111 ide_config_drive_speed(drive, XFER_PIO_0 + pio);
113} 112}
@@ -212,7 +211,7 @@ static int it8213_config_drive_for_dma (ide_drive_t *drive)
212 if (ide_tune_dma(drive)) 211 if (ide_tune_dma(drive))
213 return 0; 212 return 0;
214 213
215 it8213_tuneproc(drive, 255); 214 ide_set_max_pio(drive);
216 215
217 return -1; 216 return -1;
218} 217}
@@ -231,7 +230,7 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
231 u8 reg42h = 0; 230 u8 reg42h = 0;
232 231
233 hwif->speedproc = &it8213_tune_chipset; 232 hwif->speedproc = &it8213_tune_chipset;
234 hwif->tuneproc = &it8213_tuneproc; 233 hwif->set_pio_mode = &it8213_set_pio_mode;
235 234
236 hwif->autodma = 0; 235 hwif->autodma = 0;
237 236
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index a756e61bcb32..0cce4a7f5e46 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -274,9 +274,8 @@ static int it821x_tunepio(ide_drive_t *drive, u8 set_pio)
274 return ide_config_drive_speed(drive, XFER_PIO_0 + set_pio); 274 return ide_config_drive_speed(drive, XFER_PIO_0 + set_pio);
275} 275}
276 276
277static void it821x_tuneproc(ide_drive_t *drive, u8 pio) 277static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
278{ 278{
279 pio = ide_get_best_pio_mode(drive, pio, 4);
280 (void)it821x_tunepio(drive, pio); 279 (void)it821x_tunepio(drive, pio);
281} 280}
282 281
@@ -473,7 +472,7 @@ static int it821x_config_drive_for_dma (ide_drive_t *drive)
473 if (ide_tune_dma(drive)) 472 if (ide_tune_dma(drive))
474 return 0; 473 return 0;
475 474
476 it821x_tuneproc(drive, 255); 475 ide_set_max_pio(drive);
477 476
478 return -1; 477 return -1;
479} 478}
@@ -640,7 +639,7 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
640 } 639 }
641 640
642 hwif->speedproc = &it821x_tune_chipset; 641 hwif->speedproc = &it821x_tune_chipset;
643 hwif->tuneproc = &it821x_tuneproc; 642 hwif->set_pio_mode = &it821x_set_pio_mode;
644 643
645 /* MWDMA/PIO clock switching for pass through mode */ 644 /* MWDMA/PIO clock switching for pass through mode */
646 if(!idev->smart) { 645 if(!idev->smart) {
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index 7bac87fb481a..d379fbaf6743 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -83,9 +83,8 @@ static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
83 return ATA_CBL_PATA80; 83 return ATA_CBL_PATA80;
84} 84}
85 85
86static void jmicron_tuneproc(ide_drive_t *drive, u8 pio) 86static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
87{ 87{
88 pio = ide_get_best_pio_mode(drive, pio, 5);
89 ide_config_drive_speed(drive, XFER_PIO_0 + pio); 88 ide_config_drive_speed(drive, XFER_PIO_0 + pio);
90} 89}
91 90
@@ -116,7 +115,7 @@ static int jmicron_config_drive_for_dma (ide_drive_t *drive)
116 if (ide_tune_dma(drive)) 115 if (ide_tune_dma(drive))
117 return 0; 116 return 0;
118 117
119 jmicron_tuneproc(drive, 255); 118 ide_set_max_pio(drive);
120 119
121 return -1; 120 return -1;
122} 121}
@@ -131,7 +130,7 @@ static int jmicron_config_drive_for_dma (ide_drive_t *drive)
131static void __devinit init_hwif_jmicron(ide_hwif_t *hwif) 130static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
132{ 131{
133 hwif->speedproc = &jmicron_tune_chipset; 132 hwif->speedproc = &jmicron_tune_chipset;
134 hwif->tuneproc = &jmicron_tuneproc; 133 hwif->set_pio_mode = &jmicron_set_pio_mode;
135 134
136 hwif->drives[0].autotune = 1; 135 hwif->drives[0].autotune = 1;
137 hwif->drives[1].autotune = 1; 136 hwif->drives[1].autotune = 1;
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 3a2bb2723515..9fa06393469a 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -47,7 +47,7 @@
47 * The main problem with OPTi is that some timings for master 47 * The main problem with OPTi is that some timings for master
48 * and slave must be the same. For example, if you have master 48 * and slave must be the same. For example, if you have master
49 * PIO 3 and slave PIO 0, driver have to set some timings of 49 * PIO 3 and slave PIO 0, driver have to set some timings of
50 * master for PIO 0. Second problem is that opti621_tune_drive 50 * master for PIO 0. Second problem is that opti621_set_pio_mode
51 * got only one drive to set, but have to set both drives. 51 * got only one drive to set, but have to set both drives.
52 * This is solved in compute_pios. If you don't set 52 * This is solved in compute_pios. If you don't set
53 * the second drive, compute_pios use ide_get_best_pio_mode 53 * the second drive, compute_pios use ide_get_best_pio_mode
@@ -103,7 +103,7 @@
103 103
104#include <asm/io.h> 104#include <asm/io.h>
105 105
106#define OPTI621_MAX_PIO 3 106//#define OPTI621_MAX_PIO 3
107/* In fact, I do not have any PIO 4 drive 107/* In fact, I do not have any PIO 4 drive
108 * (address: 25 ns, data: 70 ns, recovery: 35 ns), 108 * (address: 25 ns, data: 70 ns, recovery: 35 ns),
109 * but OPTi 82C621 is programmable and it can do (minimal values): 109 * but OPTi 82C621 is programmable and it can do (minimal values):
@@ -136,8 +136,8 @@ static int reg_base;
136#define PIO_NOT_EXIST 254 136#define PIO_NOT_EXIST 254
137#define PIO_DONT_KNOW 255 137#define PIO_DONT_KNOW 255
138 138
139/* there are stored pio numbers from other calls of opti621_tune_drive */ 139/* there are stored pio numbers from other calls of opti621_set_pio_mode */
140static void compute_pios(ide_drive_t *drive, u8 pio) 140static void compute_pios(ide_drive_t *drive, const u8 pio)
141/* Store values into drive->drive_data 141/* Store values into drive->drive_data
142 * second_contr - 0 for primary controller, 1 for secondary 142 * second_contr - 0 for primary controller, 1 for secondary
143 * slave_drive - 0 -> pio is for master, 1 -> pio is for slave 143 * slave_drive - 0 -> pio is for master, 1 -> pio is for slave
@@ -147,12 +147,13 @@ static void compute_pios(ide_drive_t *drive, u8 pio)
147 int d; 147 int d;
148 ide_hwif_t *hwif = HWIF(drive); 148 ide_hwif_t *hwif = HWIF(drive);
149 149
150 drive->drive_data = ide_get_best_pio_mode(drive, pio, OPTI621_MAX_PIO); 150 drive->drive_data = pio;
151
151 for (d = 0; d < 2; ++d) { 152 for (d = 0; d < 2; ++d) {
152 drive = &hwif->drives[d]; 153 drive = &hwif->drives[d];
153 if (drive->present) { 154 if (drive->present) {
154 if (drive->drive_data == PIO_DONT_KNOW) 155 if (drive->drive_data == PIO_DONT_KNOW)
155 drive->drive_data = ide_get_best_pio_mode(drive, 255, OPTI621_MAX_PIO); 156 drive->drive_data = ide_get_best_pio_mode(drive, 255, 3);
156#ifdef OPTI621_DEBUG 157#ifdef OPTI621_DEBUG
157 printk("%s: Selected PIO mode %d\n", 158 printk("%s: Selected PIO mode %d\n",
158 drive->name, drive->drive_data); 159 drive->name, drive->drive_data);
@@ -240,8 +241,7 @@ static void compute_clocks(int pio, pio_clocks_t *clks)
240 241
241} 242}
242 243
243/* Main tune procedure, called from tuneproc. */ 244static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
244static void opti621_tune_drive (ide_drive_t *drive, u8 pio)
245{ 245{
246 /* primary and secondary drives share some registers, 246 /* primary and secondary drives share some registers,
247 * so we have to program both drives 247 * so we have to program both drives
@@ -331,7 +331,8 @@ static void __devinit init_hwif_opti621 (ide_hwif_t *hwif)
331 hwif->autodma = 0; 331 hwif->autodma = 0;
332 hwif->drives[0].drive_data = PIO_DONT_KNOW; 332 hwif->drives[0].drive_data = PIO_DONT_KNOW;
333 hwif->drives[1].drive_data = PIO_DONT_KNOW; 333 hwif->drives[1].drive_data = PIO_DONT_KNOW;
334 hwif->tuneproc = &opti621_tune_drive; 334
335 hwif->set_pio_mode = &opti621_set_pio_mode;
335 336
336 if (!(hwif->dma_base)) 337 if (!(hwif->dma_base))
337 return; 338 return;
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 3787194a2249..5fb1eedc8194 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -215,9 +215,8 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, const u8 speed)
215 return err; 215 return err;
216} 216}
217 217
218static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio) 218static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio)
219{ 219{
220 pio = ide_get_best_pio_mode(drive, pio, 4);
221 (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio); 220 (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio);
222} 221}
223 222
@@ -237,7 +236,7 @@ static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive)
237 return 0; 236 return 0;
238 237
239 if (ide_use_fast_pio(drive)) 238 if (ide_use_fast_pio(drive))
240 pdcnew_tune_drive(drive, 255); 239 ide_set_max_pio(drive);
241 240
242 return -1; 241 return -1;
243} 242}
@@ -490,7 +489,8 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
490{ 489{
491 hwif->autodma = 0; 490 hwif->autodma = 0;
492 491
493 hwif->tuneproc = &pdcnew_tune_drive; 492 hwif->set_pio_mode = &pdcnew_set_pio_mode;
493
494 hwif->quirkproc = &pdcnew_quirkproc; 494 hwif->quirkproc = &pdcnew_quirkproc;
495 hwif->speedproc = &pdcnew_tune_chipset; 495 hwif->speedproc = &pdcnew_tune_chipset;
496 hwif->resetproc = &pdcnew_reset; 496 hwif->resetproc = &pdcnew_reset;
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index e7a5e3014c09..b578307fad51 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -142,9 +142,8 @@ static int pdc202xx_tune_chipset(ide_drive_t *drive, const u8 speed)
142 return ide_config_drive_speed(drive, speed); 142 return ide_config_drive_speed(drive, speed);
143} 143}
144 144
145static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio) 145static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
146{ 146{
147 pio = ide_get_best_pio_mode(drive, pio, 4);
148 pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio); 147 pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio);
149} 148}
150 149
@@ -190,7 +189,7 @@ static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
190 return 0; 189 return 0;
191 190
192 if (ide_use_fast_pio(drive)) 191 if (ide_use_fast_pio(drive))
193 pdc202xx_tune_drive(drive, 255); 192 ide_set_max_pio(drive);
194 193
195 return -1; 194 return -1;
196} 195}
@@ -306,10 +305,11 @@ static void pdc202xx_reset (ide_drive_t *drive)
306{ 305{
307 ide_hwif_t *hwif = HWIF(drive); 306 ide_hwif_t *hwif = HWIF(drive);
308 ide_hwif_t *mate = hwif->mate; 307 ide_hwif_t *mate = hwif->mate;
309 308
310 pdc202xx_reset_host(hwif); 309 pdc202xx_reset_host(hwif);
311 pdc202xx_reset_host(mate); 310 pdc202xx_reset_host(mate);
312 pdc202xx_tune_drive(drive, 255); 311
312 ide_set_max_pio(drive);
313} 313}
314 314
315static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, 315static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
@@ -328,7 +328,9 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
328 hwif->rqsize = 256; 328 hwif->rqsize = 256;
329 329
330 hwif->autodma = 0; 330 hwif->autodma = 0;
331 hwif->tuneproc = &pdc202xx_tune_drive; 331
332 hwif->set_pio_mode = &pdc202xx_set_pio_mode;
333
332 hwif->quirkproc = &pdc202xx_quirkproc; 334 hwif->quirkproc = &pdc202xx_quirkproc;
333 335
334 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) 336 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246)
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index b66f9d1411b3..07492d71c602 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -17,11 +17,11 @@
17 * 41 17 * 41
18 * 43 18 * 43
19 * 19 *
20 * | PIO 0 | c0 | 80 | 0 | piix_tune_drive(drive, 0); 20 * | PIO 0 | c0 | 80 | 0 |
21 * | PIO 2 | SW2 | d0 | 90 | 4 | piix_tune_drive(drive, 2); 21 * | PIO 2 | SW2 | d0 | 90 | 4 |
22 * | PIO 3 | MW1 | e1 | a1 | 9 | piix_tune_drive(drive, 3); 22 * | PIO 3 | MW1 | e1 | a1 | 9 |
23 * | PIO 4 | MW2 | e3 | a3 | b | piix_tune_drive(drive, 4); 23 * | PIO 4 | MW2 | e3 | a3 | b |
24 * 24 *
25 * sitre = word40 & 0x4000; primary 25 * sitre = word40 & 0x4000; primary
26 * sitre = word42 & 0x4000; secondary 26 * sitre = word42 & 0x4000; secondary
27 * 27 *
@@ -204,16 +204,16 @@ static void piix_tune_pio (ide_drive_t *drive, u8 pio)
204} 204}
205 205
206/** 206/**
207 * piix_tune_drive - tune a drive attached to PIIX 207 * piix_set_pio_mode - set PIO mode
208 * @drive: drive to tune 208 * @drive: drive to tune
209 * @pio: desired PIO mode 209 * @pio: desired PIO mode
210 * 210 *
211 * Set the drive's PIO mode (might be useful if drive is not registered 211 * Set the drive's PIO mode (might be useful if drive is not registered
212 * in CMOS for any reason). 212 * in CMOS for any reason).
213 */ 213 */
214static void piix_tune_drive (ide_drive_t *drive, u8 pio) 214
215static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio)
215{ 216{
216 pio = ide_get_best_pio_mode(drive, pio, 4);
217 piix_tune_pio(drive, pio); 217 piix_tune_pio(drive, pio);
218 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 218 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
219} 219}
@@ -317,7 +317,7 @@ static int piix_config_drive_xfer_rate (ide_drive_t *drive)
317 return 0; 317 return 0;
318 318
319 if (ide_use_fast_pio(drive)) 319 if (ide_use_fast_pio(drive))
320 piix_tune_drive(drive, 255); 320 ide_set_max_pio(drive);
321 321
322 return -1; 322 return -1;
323} 323}
@@ -454,7 +454,8 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
454 } 454 }
455 455
456 hwif->autodma = 0; 456 hwif->autodma = 0;
457 hwif->tuneproc = &piix_tune_drive; 457
458 hwif->set_pio_mode = &piix_set_pio_mode;
458 hwif->speedproc = &piix_tune_chipset; 459 hwif->speedproc = &piix_tune_chipset;
459 hwif->drives[0].autotune = 1; 460 hwif->drives[0].autotune = 1;
460 hwif->drives[1].autotune = 1; 461 hwif->drives[1].autotune = 1;
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 059071cd2d49..f9f5ed906577 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -272,19 +272,20 @@ static int sc1200_ide_dma_end (ide_drive_t *drive)
272} 272}
273 273
274/* 274/*
275 * sc1200_tuneproc() handles selection/setting of PIO modes 275 * sc1200_set_pio_mode() handles setting of PIO modes
276 * for both the chipset and drive. 276 * for both the chipset and drive.
277 * 277 *
278 * All existing BIOSs for this chipset guarantee that all drives 278 * All existing BIOSs for this chipset guarantee that all drives
279 * will have valid default PIO timings set up before we get here. 279 * will have valid default PIO timings set up before we get here.
280 */ 280 */
281static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "autotune" */ 281
282static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
282{ 283{
283 ide_hwif_t *hwif = HWIF(drive); 284 ide_hwif_t *hwif = HWIF(drive);
284 int mode = -1; 285 int mode = -1;
285 286
286 /* 287 /*
287 * bad abuse of ->tuneproc interface 288 * bad abuse of ->set_pio_mode interface
288 */ 289 */
289 switch (pio) { 290 switch (pio) {
290 case 200: mode = XFER_UDMA_0; break; 291 case 200: mode = XFER_UDMA_0; break;
@@ -302,9 +303,6 @@ static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "au
302 return; 303 return;
303 } 304 }
304 305
305 pio = ide_get_best_pio_mode(drive, pio, 4);
306 printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio);
307
308 if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) 306 if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0)
309 sc1200_tunepio(drive, pio); 307 sc1200_tunepio(drive, pio);
310} 308}
@@ -420,7 +418,8 @@ static void __devinit init_hwif_sc1200 (ide_hwif_t *hwif)
420 hwif->ide_dma_end = &sc1200_ide_dma_end; 418 hwif->ide_dma_end = &sc1200_ide_dma_end;
421 if (!noautodma) 419 if (!noautodma)
422 hwif->autodma = 1; 420 hwif->autodma = 1;
423 hwif->tuneproc = &sc1200_tuneproc; 421
422 hwif->set_pio_mode = &sc1200_set_pio_mode;
424 hwif->speedproc = &sc1200_tune_chipset; 423 hwif->speedproc = &sc1200_tune_chipset;
425 } 424 }
426 hwif->atapi_dma = 1; 425 hwif->atapi_dma = 1;
@@ -436,6 +435,7 @@ static ide_pci_device_t sc1200_chipset __devinitdata = {
436 .init_hwif = init_hwif_sc1200, 435 .init_hwif = init_hwif_sc1200,
437 .autodma = AUTODMA, 436 .autodma = AUTODMA,
438 .bootable = ON_BOARD, 437 .bootable = ON_BOARD,
438 .host_flags = IDE_HFLAG_ABUSE_DMA_MODES,
439 .pio_mask = ATA_PIO4, 439 .pio_mask = ATA_PIO4,
440}; 440};
441 441
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index a19687caf65a..3505d57eda18 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -221,9 +221,8 @@ static void scc_tune_pio(ide_drive_t *drive, const u8 pio)
221 out_be32((void __iomem *)pioct_port, reg); 221 out_be32((void __iomem *)pioct_port, reg);
222} 222}
223 223
224static void scc_tuneproc(ide_drive_t *drive, u8 pio) 224static void scc_set_pio_mode(ide_drive_t *drive, const u8 pio)
225{ 225{
226 pio = ide_get_best_pio_mode(drive, pio, 4);
227 scc_tune_pio(drive, pio); 226 scc_tune_pio(drive, pio);
228 ide_config_drive_speed(drive, XFER_PIO_0 + pio); 227 ide_config_drive_speed(drive, XFER_PIO_0 + pio);
229} 228}
@@ -316,7 +315,7 @@ static int scc_config_drive_for_dma(ide_drive_t *drive)
316 return 0; 315 return 0;
317 316
318 if (ide_use_fast_pio(drive)) 317 if (ide_use_fast_pio(drive))
319 scc_tuneproc(drive, 255); 318 ide_set_max_pio(drive);
320 319
321 return -1; 320 return -1;
322} 321}
@@ -717,7 +716,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
717 hwif->dma_setup = scc_dma_setup; 716 hwif->dma_setup = scc_dma_setup;
718 hwif->ide_dma_end = scc_ide_dma_end; 717 hwif->ide_dma_end = scc_ide_dma_end;
719 hwif->speedproc = scc_tune_chipset; 718 hwif->speedproc = scc_tune_chipset;
720 hwif->tuneproc = scc_tuneproc; 719 hwif->set_pio_mode = scc_set_pio_mode;
721 hwif->ide_dma_check = scc_config_drive_for_dma; 720 hwif->ide_dma_check = scc_config_drive_for_dma;
722 hwif->ide_dma_test_irq = scc_dma_test_irq; 721 hwif->ide_dma_test_irq = scc_dma_test_irq;
723 hwif->udma_filter = scc_udma_filter; 722 hwif->udma_filter = scc_udma_filter;
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index b51133bb58af..f4e08abf0fee 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -202,9 +202,8 @@ static int svwks_tune_chipset(ide_drive_t *drive, const u8 speed)
202 return (ide_config_drive_speed(drive, speed)); 202 return (ide_config_drive_speed(drive, speed));
203} 203}
204 204
205static void svwks_tune_drive (ide_drive_t *drive, u8 pio) 205static void svwks_set_pio_mode(ide_drive_t *drive, const u8 pio)
206{ 206{
207 pio = ide_get_best_pio_mode(drive, pio, 4);
208 svwks_tune_pio(drive, pio); 207 svwks_tune_pio(drive, pio);
209 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio); 208 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio);
210} 209}
@@ -217,7 +216,7 @@ static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
217 return 0; 216 return 0;
218 217
219 if (ide_use_fast_pio(drive)) 218 if (ide_use_fast_pio(drive))
220 svwks_tune_drive(drive, 255); 219 ide_set_max_pio(drive);
221 220
222 return -1; 221 return -1;
223} 222}
@@ -389,7 +388,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
389 if (!hwif->irq) 388 if (!hwif->irq)
390 hwif->irq = hwif->channel ? 15 : 14; 389 hwif->irq = hwif->channel ? 15 : 14;
391 390
392 hwif->tuneproc = &svwks_tune_drive; 391 hwif->set_pio_mode = &svwks_set_pio_mode;
393 hwif->speedproc = &svwks_tune_chipset; 392 hwif->speedproc = &svwks_tune_chipset;
394 hwif->udma_filter = &svwks_udma_filter; 393 hwif->udma_filter = &svwks_udma_filter;
395 394
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 57145767c3df..38f63d19c3b9 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -587,7 +587,7 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
587 hwif->mwdma_mask = 0x2; /* Multimode-2 DMA */ 587 hwif->mwdma_mask = 0x2; /* Multimode-2 DMA */
588 hwif->swdma_mask = 0x2; 588 hwif->swdma_mask = 0x2;
589 hwif->pio_mask = 0x00; 589 hwif->pio_mask = 0x00;
590 hwif->tuneproc = NULL; /* Sets timing for PIO mode */ 590 hwif->set_pio_mode = NULL; /* Sets timing for PIO mode */
591 hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */ 591 hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */
592 hwif->selectproc = NULL;/* Use the default routine to select drive */ 592 hwif->selectproc = NULL;/* Use the default routine to select drive */
593 hwif->reset_poll = NULL;/* No HBA specific reset_poll needed */ 593 hwif->reset_poll = NULL;/* No HBA specific reset_poll needed */
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 4c1f3bc7e179..e07c991d91b9 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -219,9 +219,8 @@ static void sil_tune_pio(ide_drive_t *drive, u8 pio)
219 } 219 }
220} 220}
221 221
222static void sil_tuneproc(ide_drive_t *drive, u8 pio) 222static void sil_set_pio_mode(ide_drive_t *drive, const u8 pio)
223{ 223{
224 pio = ide_get_best_pio_mode(drive, pio, 4);
225 sil_tune_pio(drive, pio); 224 sil_tune_pio(drive, pio);
226 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio); 225 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio);
227} 226}
@@ -328,7 +327,7 @@ static int siimage_config_drive_for_dma (ide_drive_t *drive)
328 return 0; 327 return 0;
329 328
330 if (ide_use_fast_pio(drive)) 329 if (ide_use_fast_pio(drive))
331 sil_tuneproc(drive, 255); 330 ide_set_max_pio(drive);
332 331
333 return -1; 332 return -1;
334} 333}
@@ -899,7 +898,7 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
899 898
900 hwif->resetproc = &siimage_reset; 899 hwif->resetproc = &siimage_reset;
901 hwif->speedproc = &siimage_tune_chipset; 900 hwif->speedproc = &siimage_tune_chipset;
902 hwif->tuneproc = &sil_tuneproc; 901 hwif->set_pio_mode = &sil_set_pio_mode;
903 hwif->reset_poll = &siimage_reset_poll; 902 hwif->reset_poll = &siimage_reset_poll;
904 hwif->pre_reset = &siimage_pre_reset; 903 hwif->pre_reset = &siimage_pre_reset;
905 hwif->udma_filter = &sil_udma_filter; 904 hwif->udma_filter = &sil_udma_filter;
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index fed582b4b32f..7455bf357ed9 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -519,14 +519,13 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
519 } 519 }
520} 520}
521 521
522static int sis5513_tune_drive(ide_drive_t *drive, u8 pio) 522static int sis5513_tune_drive(ide_drive_t *drive, const u8 pio)
523{ 523{
524 pio = ide_get_best_pio_mode(drive, pio, 4);
525 config_art_rwp_pio(drive, pio); 524 config_art_rwp_pio(drive, pio);
526 return ide_config_drive_speed(drive, XFER_PIO_0 + pio); 525 return ide_config_drive_speed(drive, XFER_PIO_0 + pio);
527} 526}
528 527
529static void sis5513_tuneproc(ide_drive_t *drive, u8 pio) 528static void sis_set_pio_mode(ide_drive_t *drive, const u8 pio)
530{ 529{
531 (void)sis5513_tune_drive(drive, pio); 530 (void)sis5513_tune_drive(drive, pio);
532} 531}
@@ -621,7 +620,7 @@ static int sis5513_config_xfer_rate(ide_drive_t *drive)
621 /* 620 /*
622 * TODO: always set PIO mode and remove this 621 * TODO: always set PIO mode and remove this
623 */ 622 */
624 sis5513_tuneproc(drive, 255); 623 ide_set_max_pio(drive);
625 624
626 drive->init_speed = 0; 625 drive->init_speed = 0;
627 626
@@ -629,7 +628,7 @@ static int sis5513_config_xfer_rate(ide_drive_t *drive)
629 return 0; 628 return 0;
630 629
631 if (ide_use_fast_pio(drive)) 630 if (ide_use_fast_pio(drive))
632 sis5513_tuneproc(drive, 255); 631 ide_set_max_pio(drive);
633 632
634 return -1; 633 return -1;
635} 634}
@@ -852,7 +851,7 @@ static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
852 if (!hwif->irq) 851 if (!hwif->irq)
853 hwif->irq = hwif->channel ? 15 : 14; 852 hwif->irq = hwif->channel ? 15 : 14;
854 853
855 hwif->tuneproc = &sis5513_tuneproc; 854 hwif->set_pio_mode = &sis_set_pio_mode;
856 hwif->speedproc = &sis5513_tune_chipset; 855 hwif->speedproc = &sis5513_tune_chipset;
857 856
858 if (chipset_family >= ATA_133) 857 if (chipset_family >= ATA_133)
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 9f425b0b5721..131e91ca1d82 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -75,16 +75,12 @@ static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
75/* 75/*
76 * Configure the chipset for PIO mode. 76 * Configure the chipset for PIO mode.
77 */ 77 */
78static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio) 78static void sl82c105_tune_pio(ide_drive_t *drive, const u8 pio)
79{ 79{
80 struct pci_dev *dev = HWIF(drive)->pci_dev; 80 struct pci_dev *dev = HWIF(drive)->pci_dev;
81 int reg = 0x44 + drive->dn * 4; 81 int reg = 0x44 + drive->dn * 4;
82 u16 drv_ctrl; 82 u16 drv_ctrl;
83 83
84 DBG(("sl82c105_tune_pio(drive:%s, pio:%u)\n", drive->name, pio));
85
86 pio = ide_get_best_pio_mode(drive, pio, 5);
87
88 drv_ctrl = get_pio_timings(drive, pio); 84 drv_ctrl = get_pio_timings(drive, pio);
89 85
90 /* 86 /*
@@ -106,8 +102,6 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio)
106 printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name, 102 printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name,
107 ide_xfer_verbose(pio + XFER_PIO_0), 103 ide_xfer_verbose(pio + XFER_PIO_0),
108 ide_pio_cycle_time(drive, pio), drv_ctrl); 104 ide_pio_cycle_time(drive, pio), drv_ctrl);
109
110 return pio;
111} 105}
112 106
113/* 107/*
@@ -151,7 +145,7 @@ static int sl82c105_tune_chipset(ide_drive_t *drive, const u8 speed)
151 case XFER_PIO_2: 145 case XFER_PIO_2:
152 case XFER_PIO_1: 146 case XFER_PIO_1:
153 case XFER_PIO_0: 147 case XFER_PIO_0:
154 (void) sl82c105_tune_pio(drive, speed - XFER_PIO_0); 148 sl82c105_tune_pio(drive, speed - XFER_PIO_0);
155 break; 149 break;
156 default: 150 default:
157 return -1; 151 return -1;
@@ -325,11 +319,10 @@ static void sl82c105_resetproc(ide_drive_t *drive)
325 * We only deal with PIO mode here - DMA mode 'using_dma' is not 319 * We only deal with PIO mode here - DMA mode 'using_dma' is not
326 * initialised at the point that this function is called. 320 * initialised at the point that this function is called.
327 */ 321 */
328static void sl82c105_tune_drive(ide_drive_t *drive, u8 pio) 322static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
329{ 323{
330 DBG(("sl82c105_tune_drive(drive:%s, pio:%u)\n", drive->name, pio)); 324 sl82c105_tune_pio(drive, pio);
331 325
332 pio = sl82c105_tune_pio(drive, pio);
333 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 326 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
334} 327}
335 328
@@ -397,7 +390,7 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
397 390
398 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); 391 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
399 392
400 hwif->tuneproc = &sl82c105_tune_drive; 393 hwif->set_pio_mode = &sl82c105_set_pio_mode;
401 hwif->speedproc = &sl82c105_tune_chipset; 394 hwif->speedproc = &sl82c105_tune_chipset;
402 hwif->selectproc = &sl82c105_selectproc; 395 hwif->selectproc = &sl82c105_selectproc;
403 hwif->resetproc = &sl82c105_resetproc; 396 hwif->resetproc = &sl82c105_resetproc;
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index cc9353565070..214d396fc31f 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -95,9 +95,8 @@ static void slc90e66_tune_pio (ide_drive_t *drive, u8 pio)
95 spin_unlock_irqrestore(&ide_lock, flags); 95 spin_unlock_irqrestore(&ide_lock, flags);
96} 96}
97 97
98static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio) 98static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
99{ 99{
100 pio = ide_get_best_pio_mode(drive, pio, 4);
101 slc90e66_tune_pio(drive, pio); 100 slc90e66_tune_pio(drive, pio);
102 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 101 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
103} 102}
@@ -166,7 +165,7 @@ static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
166 return 0; 165 return 0;
167 166
168 if (ide_use_fast_pio(drive)) 167 if (ide_use_fast_pio(drive))
169 slc90e66_tune_drive(drive, 255); 168 ide_set_max_pio(drive);
170 169
171 return -1; 170 return -1;
172} 171}
@@ -182,7 +181,7 @@ static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
182 hwif->irq = hwif->channel ? 15 : 14; 181 hwif->irq = hwif->channel ? 15 : 14;
183 182
184 hwif->speedproc = &slc90e66_tune_chipset; 183 hwif->speedproc = &slc90e66_tune_chipset;
185 hwif->tuneproc = &slc90e66_tune_drive; 184 hwif->set_pio_mode = &slc90e66_set_pio_mode;
186 185
187 pci_read_config_byte(hwif->pci_dev, 0x47, &reg47); 186 pci_read_config_byte(hwif->pci_dev, 0x47, &reg47);
188 187
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index e5425772622f..e23b9cfb6eb4 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -43,9 +43,8 @@ static int tc86c001_tune_chipset(ide_drive_t *drive, const u8 speed)
43 return ide_config_drive_speed(drive, speed); 43 return ide_config_drive_speed(drive, speed);
44} 44}
45 45
46static void tc86c001_tune_drive(ide_drive_t *drive, u8 pio) 46static void tc86c001_set_pio_mode(ide_drive_t *drive, const u8 pio)
47{ 47{
48 pio = ide_get_best_pio_mode(drive, pio, 4);
49 (void) tc86c001_tune_chipset(drive, XFER_PIO_0 + pio); 48 (void) tc86c001_tune_chipset(drive, XFER_PIO_0 + pio);
50} 49}
51 50
@@ -171,7 +170,7 @@ static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive)
171 return 0; 170 return 0;
172 171
173 if (ide_use_fast_pio(drive)) 172 if (ide_use_fast_pio(drive))
174 tc86c001_tune_drive(drive, 255); 173 ide_set_max_pio(drive);
175 174
176 return -1; 175 return -1;
177} 176}
@@ -193,7 +192,7 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
193 /* Store the system control register base for convenience... */ 192 /* Store the system control register base for convenience... */
194 hwif->config_data = sc_base; 193 hwif->config_data = sc_base;
195 194
196 hwif->tuneproc = &tc86c001_tune_drive; 195 hwif->set_pio_mode = &tc86c001_set_pio_mode;
197 hwif->speedproc = &tc86c001_tune_chipset; 196 hwif->speedproc = &tc86c001_tune_chipset;
198 hwif->busproc = &tc86c001_busproc; 197 hwif->busproc = &tc86c001_busproc;
199 198
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index 47cf89be4dfc..c3ff066eea5a 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -93,10 +93,9 @@ static int triflex_tune_chipset(ide_drive_t *drive, const u8 speed)
93 return (ide_config_drive_speed(drive, speed)); 93 return (ide_config_drive_speed(drive, speed));
94} 94}
95 95
96static void triflex_tune_drive(ide_drive_t *drive, u8 pio) 96static void triflex_set_pio_mode(ide_drive_t *drive, const u8 pio)
97{ 97{
98 int use_pio = ide_get_best_pio_mode(drive, pio, 4); 98 (void)triflex_tune_chipset(drive, XFER_PIO_0 + pio);
99 (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio));
100} 99}
101 100
102static int triflex_config_drive_xfer_rate(ide_drive_t *drive) 101static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
@@ -104,14 +103,14 @@ static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
104 if (ide_tune_dma(drive)) 103 if (ide_tune_dma(drive))
105 return 0; 104 return 0;
106 105
107 triflex_tune_drive(drive, 255); 106 ide_set_max_pio(drive);
108 107
109 return -1; 108 return -1;
110} 109}
111 110
112static void __devinit init_hwif_triflex(ide_hwif_t *hwif) 111static void __devinit init_hwif_triflex(ide_hwif_t *hwif)
113{ 112{
114 hwif->tuneproc = &triflex_tune_drive; 113 hwif->set_pio_mode = &triflex_set_pio_mode;
115 hwif->speedproc = &triflex_tune_chipset; 114 hwif->speedproc = &triflex_tune_chipset;
116 115
117 if (hwif->dma_base == 0) 116 if (hwif->dma_base == 0)
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index e3bf90736332..2fc4f8835f19 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -195,19 +195,16 @@ static int via_set_drive(ide_drive_t *drive, const u8 speed)
195} 195}
196 196
197/** 197/**
198 * via82cxxx_tune_drive - PIO setup 198 * via_set_pio_mode - PIO setup
199 * @drive: drive to set up 199 * @drive: drive
200 * @pio: mode to use (255 for 'best possible') 200 * @pio: PIO mode number
201 * 201 *
202 * A callback from the upper layers for PIO-only tuning. 202 * A callback from the upper layers for PIO-only tuning.
203 */ 203 */
204 204
205static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio) 205static void via_set_pio_mode(ide_drive_t *drive, const u8 pio)
206{ 206{
207 if (pio == 255) 207 via_set_drive(drive, XFER_PIO_0 + pio);
208 pio = ide_get_best_pio_mode(drive, 255, 5);
209
210 via_set_drive(drive, XFER_PIO_0 + min_t(u8, pio, 5));
211} 208}
212 209
213/** 210/**
@@ -223,7 +220,7 @@ static int via82cxxx_ide_dma_check (ide_drive_t *drive)
223 u8 speed = ide_max_dma_mode(drive); 220 u8 speed = ide_max_dma_mode(drive);
224 221
225 if (speed == 0) { 222 if (speed == 0) {
226 via82cxxx_tune_drive(drive, 255); 223 ide_set_max_pio(drive);
227 return -1; 224 return -1;
228 } 225 }
229 226
@@ -465,7 +462,7 @@ static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
465 462
466 hwif->autodma = 0; 463 hwif->autodma = 0;
467 464
468 hwif->tuneproc = &via82cxxx_tune_drive; 465 hwif->set_pio_mode = &via_set_pio_mode;
469 hwif->speedproc = &via_set_drive; 466 hwif->speedproc = &via_set_drive;
470 467
471 468
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c
index dab79afa9b22..df2e92034f5d 100644
--- a/drivers/ide/ppc/mpc8xx.c
+++ b/drivers/ide/ppc/mpc8xx.c
@@ -45,7 +45,7 @@ static void print_funcid (int func);
45static int check_ide_device (unsigned long base); 45static int check_ide_device (unsigned long base);
46 46
47static void ide_interrupt_ack (void *dev); 47static void ide_interrupt_ack (void *dev);
48static void m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio); 48static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio);
49 49
50typedef struct ide_ioport_desc { 50typedef struct ide_ioport_desc {
51 unsigned long base_off; /* Offset to PCMCIA memory */ 51 unsigned long base_off; /* Offset to PCMCIA memory */
@@ -314,9 +314,8 @@ m8xx_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port,
314#endif /* CONFIG_IDE_8xx_PCCARD */ 314#endif /* CONFIG_IDE_8xx_PCCARD */
315 } 315 }
316 316
317 /* register routine to tune PIO mode */
318 ide_hwifs[data_port].pio_mask = ATA_PIO4; 317 ide_hwifs[data_port].pio_mask = ATA_PIO4;
319 ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; 318 ide_hwifs[data_port].set_pio_mode = m8xx_ide_set_pio_mode;
320 319
321 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; 320 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack;
322 /* Enable Harddisk Interrupt, 321 /* Enable Harddisk Interrupt,
@@ -401,9 +400,8 @@ void m8xx_ide_init_hwif_ports (hw_regs_t *hw,
401 *irq = ioport_dsc[data_port].irq; 400 *irq = ioport_dsc[data_port].irq;
402 } 401 }
403 402
404 /* register routine to tune PIO mode */
405 ide_hwifs[data_port].pio_mask = ATA_PIO4; 403 ide_hwifs[data_port].pio_mask = ATA_PIO4;
406 ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; 404 ide_hwifs[data_port].set_pio_mode = m8xx_ide_set_pio_mode;
407 405
408 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; 406 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack;
409 /* Enable Harddisk Interrupt, 407 /* Enable Harddisk Interrupt,
@@ -427,24 +425,13 @@ void m8xx_ide_init_hwif_ports (hw_regs_t *hw,
427#define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */ 425#define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */
428#endif 426#endif
429 427
430
431/* Calculate PIO timings */ 428/* Calculate PIO timings */
432static void 429static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
433m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio)
434{ 430{
435#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) 431#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
436 volatile pcmconf8xx_t *pcmp; 432 volatile pcmconf8xx_t *pcmp;
437 ulong timing, mask, reg; 433 ulong timing, mask, reg;
438#endif
439
440 pio = ide_get_best_pio_mode(drive, pio, 4);
441 434
442#if 1
443 printk("%s[%d] %s: best PIO mode: %d\n",
444 __FILE__,__LINE__,__FUNCTION__, pio);
445#endif
446
447#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
448 pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); 435 pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia));
449 436
450 mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF)); 437 mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF));
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 284bb7c39b87..beafdf3c1124 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -411,7 +411,6 @@ kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
411 411
412static void pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif); 412static void pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
413static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq); 413static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
414static void pmac_ide_tuneproc(ide_drive_t *drive, u8 pio);
415static void pmac_ide_selectproc(ide_drive_t *drive); 414static void pmac_ide_selectproc(ide_drive_t *drive);
416static void pmac_ide_kauai_selectproc(ide_drive_t *drive); 415static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
417 416
@@ -615,7 +614,7 @@ out:
615 * Old tuning functions (called on hdparm -p), sets up drive PIO timings 614 * Old tuning functions (called on hdparm -p), sets up drive PIO timings
616 */ 615 */
617static void 616static void
618pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) 617pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
619{ 618{
620 u32 *timings; 619 u32 *timings;
621 unsigned accessTicks, recTicks; 620 unsigned accessTicks, recTicks;
@@ -629,7 +628,6 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
629 /* which drive is it ? */ 628 /* which drive is it ? */
630 timings = &pmif->timings[drive->select.b.unit & 0x01]; 629 timings = &pmif->timings[drive->select.b.unit & 0x01];
631 630
632 pio = ide_get_best_pio_mode(drive, pio, 4);
633 cycle_time = ide_pio_cycle_time(drive, pio); 631 cycle_time = ide_pio_cycle_time(drive, pio);
634 632
635 switch (pmif->kind) { 633 switch (pmif->kind) {
@@ -966,7 +964,7 @@ static int pmac_ide_tune_chipset(ide_drive_t *drive, const u8 speed)
966 case XFER_PIO_2: 964 case XFER_PIO_2:
967 case XFER_PIO_1: 965 case XFER_PIO_1:
968 case XFER_PIO_0: 966 case XFER_PIO_0:
969 pmac_ide_tuneproc(drive, speed & 0x07); 967 pmac_ide_set_pio_mode(drive, speed & 0x07);
970 break; 968 break;
971 default: 969 default:
972 ret = 1; 970 ret = 1;
@@ -1241,7 +1239,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1241 hwif->drives[0].unmask = 1; 1239 hwif->drives[0].unmask = 1;
1242 hwif->drives[1].unmask = 1; 1240 hwif->drives[1].unmask = 1;
1243 hwif->pio_mask = ATA_PIO4; 1241 hwif->pio_mask = ATA_PIO4;
1244 hwif->tuneproc = pmac_ide_tuneproc; 1242 hwif->set_pio_mode = pmac_ide_set_pio_mode;
1245 if (pmif->kind == controller_un_ata6 1243 if (pmif->kind == controller_un_ata6
1246 || pmif->kind == controller_k2_ata6 1244 || pmif->kind == controller_k2_ata6
1247 || pmif->kind == controller_sh_ata6) 1245 || pmif->kind == controller_sh_ata6)
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 81736cb7ef3d..85d448b4abec 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -634,7 +634,7 @@ typedef struct ide_drive_s {
634 634
635 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */ 635 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */
636 unsigned int cyl; /* "real" number of cyls */ 636 unsigned int cyl; /* "real" number of cyls */
637 unsigned int drive_data; /* use by tuneproc/selectproc */ 637 unsigned int drive_data; /* used by set_pio_mode/selectproc */
638 unsigned int failures; /* current failure count */ 638 unsigned int failures; /* current failure count */
639 unsigned int max_failures; /* maximum allowed failure count */ 639 unsigned int max_failures; /* maximum allowed failure count */
640 u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */ 640 u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */
@@ -702,8 +702,8 @@ typedef struct hwif_s {
702#if 0 702#if 0
703 ide_hwif_ops_t *hwifops; 703 ide_hwif_ops_t *hwifops;
704#else 704#else
705 /* routine to tune PIO mode for drives */ 705 /* routine to set PIO mode for drives */
706 void (*tuneproc)(ide_drive_t *, u8); 706 void (*set_pio_mode)(ide_drive_t *, const u8);
707 /* routine to retune DMA modes for drives */ 707 /* routine to retune DMA modes for drives */
708 int (*speedproc)(ide_drive_t *, const u8); 708 int (*speedproc)(ide_drive_t *, const u8);
709 /* tweaks hardware to select drive */ 709 /* tweaks hardware to select drive */
@@ -1256,6 +1256,12 @@ enum {
1256 IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2), 1256 IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2),
1257 /* don't use conservative PIO "downgrade" */ 1257 /* don't use conservative PIO "downgrade" */
1258 IDE_HFLAG_PIO_NO_DOWNGRADE = (1 << 3), 1258 IDE_HFLAG_PIO_NO_DOWNGRADE = (1 << 3),
1259 /* use PIO8/9 for prefetch off/on */
1260 IDE_HFLAG_ABUSE_PREFETCH = (1 << 4),
1261 /* use PIO6/7 for fast-devsel off/on */
1262 IDE_HFLAG_ABUSE_FAST_DEVSEL = (1 << 5),
1263 /* use 100-102 and 200-202 PIO values to set DMA modes */
1264 IDE_HFLAG_ABUSE_DMA_MODES = (1 << 6),
1259}; 1265};
1260 1266
1261typedef struct ide_pci_device_s { 1267typedef struct ide_pci_device_s {
@@ -1414,6 +1420,12 @@ unsigned int ide_pio_cycle_time(ide_drive_t *, u8);
1414u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8); 1420u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8);
1415extern const ide_pio_timings_t ide_pio_timings[6]; 1421extern const ide_pio_timings_t ide_pio_timings[6];
1416 1422
1423void ide_set_pio(ide_drive_t *, u8);
1424
1425static inline void ide_set_max_pio(ide_drive_t *drive)
1426{
1427 ide_set_pio(drive, 255);
1428}
1417 1429
1418extern spinlock_t ide_lock; 1430extern spinlock_t ide_lock;
1419extern struct mutex ide_cfg_mtx; 1431extern struct mutex ide_cfg_mtx;