aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 19:31:22 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 19:31:22 -0400
commit64fb98fc40738ae1a98bcea9ca3145b89fb71524 (patch)
tree24130f9c56b04638e91969d216db199652470a17
parent5f47c7eac65a45e33d7fe390effe75ec5c74f8bf (diff)
parent89636af25d75d8672aea05d258be357d0dc4bd70 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/bart/ide-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/bart/ide-2.6: (23 commits) ide: add support for SCSI ioctls to ide-floppy ide: remove stale changelog from setup-pci.c ide: remove stale changelog/comments/TODO from ide.c ide-cris: handle PIO auto-tuning in tune_cris_ide() ide: add PIO masks ide: remove ide_find_best_pio_mode() ide: drop "PIO data" argument from ide_get_best_pio_mode() ide: ide_find_best_pio_mode() fixes (take 2) ide: add ide_pio_cycle_time() helper (take 2) sc1200: remove stale Power Management code ide: ide_start_power_step() fix WRT disabling DMA serverworks: fix DMA serverworks: always tune PIO ide: add ide_pci_device_t.host_flags (take 2) ide: add ide_dev_has_iordy() helper (take 4) ide: make ide_get_best_pio_mode() print info if overriding PIO mode siimage: PIO mode setup fixes (take 2) atiixp: PIO mode setup fixes ide: Stop mapping ROMs IDE: Remove references to dead ETRAX-related variables. ...
-rw-r--r--drivers/ata/pata_pcmcia.c1
-rw-r--r--drivers/ide/cris/ide-cris.c9
-rw-r--r--drivers/ide/ide-floppy.c18
-rw-r--r--drivers/ide/ide-io.c5
-rw-r--r--drivers/ide/ide-lib.c72
-rw-r--r--drivers/ide/ide-timing.h20
-rw-r--r--drivers/ide/ide.c86
-rw-r--r--drivers/ide/legacy/ali14xx.c7
-rw-r--r--drivers/ide/legacy/dtc2278.c3
-rw-r--r--drivers/ide/legacy/ht6560b.c12
-rw-r--r--drivers/ide/legacy/ide-cs.c1
-rw-r--r--drivers/ide/legacy/qd65xx.c21
-rw-r--r--drivers/ide/legacy/umc8672.c4
-rw-r--r--drivers/ide/mips/au1xxx-ide.c4
-rw-r--r--drivers/ide/pci/aec62xx.c18
-rw-r--r--drivers/ide/pci/alim15x3.c5
-rw-r--r--drivers/ide/pci/amd74xx.c24
-rw-r--r--drivers/ide/pci/atiixp.c37
-rw-r--r--drivers/ide/pci/cmd640.c19
-rw-r--r--drivers/ide/pci/cmd64x.c21
-rw-r--r--drivers/ide/pci/cs5520.c6
-rw-r--r--drivers/ide/pci/cs5530.c4
-rw-r--r--drivers/ide/pci/cs5535.c9
-rw-r--r--drivers/ide/pci/cy82c693.c5
-rw-r--r--drivers/ide/pci/generic.c15
-rw-r--r--drivers/ide/pci/hpt34x.c17
-rw-r--r--drivers/ide/pci/hpt366.c36
-rw-r--r--drivers/ide/pci/it8213.c7
-rw-r--r--drivers/ide/pci/it821x.c8
-rw-r--r--drivers/ide/pci/jmicron.c4
-rw-r--r--drivers/ide/pci/ns87415.c1
-rw-r--r--drivers/ide/pci/opti621.c8
-rw-r--r--drivers/ide/pci/pdc202xx_new.c23
-rw-r--r--drivers/ide/pci/pdc202xx_old.c20
-rw-r--r--drivers/ide/pci/piix.c8
-rw-r--r--drivers/ide/pci/rz1000.c1
-rw-r--r--drivers/ide/pci/sc1200.c43
-rw-r--r--drivers/ide/pci/scc_pata.c76
-rw-r--r--drivers/ide/pci/serverworks.c105
-rw-r--r--drivers/ide/pci/sgiioc4.c3
-rw-r--r--drivers/ide/pci/siimage.c139
-rw-r--r--drivers/ide/pci/sis5513.c4
-rw-r--r--drivers/ide/pci/sl82c105.c22
-rw-r--r--drivers/ide/pci/slc90e66.c4
-rw-r--r--drivers/ide/pci/tc86c001.c7
-rw-r--r--drivers/ide/pci/triflex.c4
-rw-r--r--drivers/ide/pci/trm290.c1
-rw-r--r--drivers/ide/pci/via82cxxx.c26
-rw-r--r--drivers/ide/ppc/mpc8xx.c5
-rw-r--r--drivers/ide/ppc/pmac.c16
-rw-r--r--drivers/ide/setup-pci.c18
-rw-r--r--include/linux/ata.h9
-rw-r--r--include/linux/ide.h31
53 files changed, 473 insertions, 599 deletions
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index a56257c98fe5..6da23feed039 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -382,6 +382,7 @@ static struct pcmcia_device_id pcmcia_devices[] = {
382 PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), 382 PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
383 PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), 383 PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
384 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), 384 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
385 PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
385 PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), 386 PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b),
386 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), 387 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
387 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), 388 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 886091bc7db0..fbfea46a34f2 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -414,12 +414,6 @@ cris_ide_reset(unsigned val)
414#ifdef CONFIG_ETRAX_IDE_G27_RESET 414#ifdef CONFIG_ETRAX_IDE_G27_RESET
415 REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, val); 415 REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, val);
416#endif 416#endif
417#ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET
418 REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, val);
419#endif
420#ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET
421 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, val);
422#endif
423#ifdef CONFIG_ETRAX_IDE_PB7_RESET 417#ifdef CONFIG_ETRAX_IDE_PB7_RESET
424 port_pb_dir_shadow = port_pb_dir_shadow | 418 port_pb_dir_shadow = port_pb_dir_shadow |
425 IO_STATE(R_PORT_PB_DIR, dir7, output); 419 IO_STATE(R_PORT_PB_DIR, dir7, output);
@@ -690,6 +684,8 @@ static void tune_cris_ide(ide_drive_t *drive, u8 pio)
690{ 684{
691 int setup, strobe, hold; 685 int setup, strobe, hold;
692 686
687 pio = ide_get_best_pio_mode(drive, pio, 4);
688
693 switch(pio) 689 switch(pio)
694 { 690 {
695 case 0: 691 case 0:
@@ -820,6 +816,7 @@ init_e100_ide (void)
820 hwif->dma_host_on = &cris_dma_on; 816 hwif->dma_host_on = &cris_dma_on;
821 hwif->dma_off_quietly = &cris_dma_off; 817 hwif->dma_off_quietly = &cris_dma_off;
822 hwif->cbl = ATA_CBL_PATA40; 818 hwif->cbl = ATA_CBL_PATA40;
819 hwif->pio_mask = ATA_PIO4,
823 hwif->ultra_mask = cris_ultra_mask; 820 hwif->ultra_mask = cris_ultra_mask;
824 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */ 821 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */
825 hwif->autodma = 1; 822 hwif->autodma = 1;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index a21f585b1caa..ae8e1a64b8ad 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -99,6 +99,8 @@
99#include <linux/bitops.h> 99#include <linux/bitops.h>
100#include <linux/mutex.h> 100#include <linux/mutex.h>
101 101
102#include <scsi/scsi_ioctl.h>
103
102#include <asm/byteorder.h> 104#include <asm/byteorder.h>
103#include <asm/irq.h> 105#include <asm/irq.h>
104#include <asm/uaccess.h> 106#include <asm/uaccess.h>
@@ -2099,7 +2101,21 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
2099 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: 2101 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
2100 return idefloppy_get_format_progress(drive, argp); 2102 return idefloppy_get_format_progress(drive, argp);
2101 } 2103 }
2102 return generic_ide_ioctl(drive, file, bdev, cmd, arg); 2104
2105 /*
2106 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
2107 * and CDROM_SEND_PACKET (legacy) ioctls
2108 */
2109 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
2110 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
2111 bdev->bd_disk, cmd, argp);
2112 else
2113 err = -ENOTTY;
2114
2115 if (err == -ENOTTY)
2116 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
2117
2118 return err;
2103} 2119}
2104 2120
2105static int idefloppy_media_changed(struct gendisk *disk) 2121static int idefloppy_media_changed(struct gendisk *disk)
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index f9de79844418..484c50e71446 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -224,11 +224,12 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
224 * we could be smarter and check for current xfer_speed 224 * we could be smarter and check for current xfer_speed
225 * in struct drive etc... 225 * in struct drive etc...
226 */ 226 */
227 if ((drive->id->capability & 1) == 0)
228 break;
229 if (drive->hwif->ide_dma_check == NULL) 227 if (drive->hwif->ide_dma_check == NULL)
230 break; 228 break;
231 drive->hwif->dma_off_quietly(drive); 229 drive->hwif->dma_off_quietly(drive);
230 /*
231 * TODO: respect ->using_dma setting
232 */
232 ide_set_dma(drive); 233 ide_set_dma(drive);
233 break; 234 break;
234 } 235 }
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 074bb32a4a40..92a6c7bcf527 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -249,12 +249,34 @@ static int ide_scan_pio_blacklist (char *model)
249 return -1; 249 return -1;
250} 250}
251 251
252unsigned int ide_pio_cycle_time(ide_drive_t *drive, u8 pio)
253{
254 struct hd_driveid *id = drive->id;
255 int cycle_time = 0;
256
257 if (id->field_valid & 2) {
258 if (id->capability & 8)
259 cycle_time = id->eide_pio_iordy;
260 else
261 cycle_time = id->eide_pio;
262 }
263
264 /* conservative "downgrade" for all pre-ATA2 drives */
265 if (pio < 3) {
266 if (cycle_time && cycle_time < ide_pio_timings[pio].cycle_time)
267 cycle_time = 0; /* use standard timing */
268 }
269
270 return cycle_time ? cycle_time : ide_pio_timings[pio].cycle_time;
271}
272
273EXPORT_SYMBOL_GPL(ide_pio_cycle_time);
274
252/** 275/**
253 * ide_get_best_pio_mode - get PIO mode from drive 276 * ide_get_best_pio_mode - get PIO mode from drive
254 * @drive: drive to consider 277 * @drive: drive to consider
255 * @mode_wanted: preferred mode 278 * @mode_wanted: preferred mode
256 * @max_mode: highest allowed mode 279 * @max_mode: highest allowed mode
257 * @d: PIO data
258 * 280 *
259 * This routine returns the recommended PIO settings for a given drive, 281 * This routine returns the recommended PIO settings for a given drive,
260 * based on the drive->id information and the ide_pio_blacklist[]. 282 * based on the drive->id information and the ide_pio_blacklist[].
@@ -263,22 +285,18 @@ static int ide_scan_pio_blacklist (char *model)
263 * This is used by most chipset support modules when "auto-tuning". 285 * This is used by most chipset support modules when "auto-tuning".
264 */ 286 */
265 287
266u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d) 288u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
267{ 289{
268 int pio_mode; 290 int pio_mode;
269 int cycle_time = 0;
270 int use_iordy = 0;
271 struct hd_driveid* id = drive->id; 291 struct hd_driveid* id = drive->id;
272 int overridden = 0; 292 int overridden = 0;
273 293
274 if (mode_wanted != 255) { 294 if (mode_wanted != 255)
275 pio_mode = mode_wanted; 295 return min_t(u8, mode_wanted, max_mode);
276 use_iordy = (pio_mode > 2); 296
277 } else if (!drive->id) { 297 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0 &&
278 pio_mode = 0; 298 (pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
279 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { 299 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
280 overridden = 1;
281 use_iordy = (pio_mode > 2);
282 } else { 300 } else {
283 pio_mode = id->tPIO; 301 pio_mode = id->tPIO;
284 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */ 302 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
@@ -286,9 +304,7 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
286 overridden = 1; 304 overridden = 1;
287 } 305 }
288 if (id->field_valid & 2) { /* drive implements ATA2? */ 306 if (id->field_valid & 2) { /* drive implements ATA2? */
289 if (id->capability & 8) { /* drive supports use_iordy? */ 307 if (id->capability & 8) { /* IORDY supported? */
290 use_iordy = 1;
291 cycle_time = id->eide_pio_iordy;
292 if (id->eide_pio_modes & 7) { 308 if (id->eide_pio_modes & 7) {
293 overridden = 0; 309 overridden = 0;
294 if (id->eide_pio_modes & 4) 310 if (id->eide_pio_modes & 4)
@@ -298,31 +314,27 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
298 else 314 else
299 pio_mode = 3; 315 pio_mode = 3;
300 } 316 }
301 } else {
302 cycle_time = id->eide_pio;
303 } 317 }
304 } 318 }
305 319
320 if (overridden)
321 printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n",
322 drive->name);
323
306 /* 324 /*
307 * Conservative "downgrade" for all pre-ATA2 drives 325 * Conservative "downgrade" for all pre-ATA2 drives
308 */ 326 */
309 if (pio_mode && pio_mode < 4) { 327 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_DOWNGRADE) == 0 &&
328 pio_mode && pio_mode < 4) {
310 pio_mode--; 329 pio_mode--;
311 overridden = 1; 330 printk(KERN_INFO "%s: applying conservative "
312 if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time) 331 "PIO \"downgrade\"\n", drive->name);
313 cycle_time = 0; /* use standard timing */
314 } 332 }
315 } 333 }
316 if (pio_mode > max_mode) { 334
335 if (pio_mode > max_mode)
317 pio_mode = max_mode; 336 pio_mode = max_mode;
318 cycle_time = 0; 337
319 }
320 if (d) {
321 d->pio_mode = pio_mode;
322 d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time;
323 d->use_iordy = use_iordy;
324 d->overridden = overridden;
325 }
326 return pio_mode; 338 return pio_mode;
327} 339}
328 340
diff --git a/drivers/ide/ide-timing.h b/drivers/ide/ide-timing.h
index e6cb8593b5ba..daffbb9797e1 100644
--- a/drivers/ide/ide-timing.h
+++ b/drivers/ide/ide-timing.h
@@ -106,23 +106,6 @@ static struct ide_timing ide_timing[] = {
106#define XFER_EPIO 0x01 106#define XFER_EPIO 0x01
107#define XFER_PIO 0x00 107#define XFER_PIO 0x00
108 108
109static short ide_find_best_pio_mode(ide_drive_t *drive)
110{
111 struct hd_driveid *id = drive->id;
112 short best = 0;
113
114 if (id->field_valid & 2) { /* EIDE PIO modes */
115
116 if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 :
117 (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 :
118 (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best;
119 }
120
121 return (drive->id->tPIO == 2) ? XFER_PIO_2 :
122 (drive->id->tPIO == 1) ? XFER_PIO_1 :
123 (drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW;
124}
125
126static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT) 109static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT)
127{ 110{
128 q->setup = EZ(t->setup * 1000, T); 111 q->setup = EZ(t->setup * 1000, T);
@@ -212,7 +195,8 @@ static int ide_timing_compute(ide_drive_t *drive, short speed, struct ide_timing
212 */ 195 */
213 196
214 if ((speed & XFER_MODE) != XFER_PIO) { 197 if ((speed & XFER_MODE) != XFER_PIO) {
215 ide_timing_compute(drive, ide_find_best_pio_mode(drive), &p, T, UT); 198 u8 pio = ide_get_best_pio_mode(drive, 255, 5);
199 ide_timing_compute(drive, XFER_PIO_0 + pio, &p, T, UT);
216 ide_timing_merge(&p, t, t, IDE_TIMING_ALL); 200 ide_timing_merge(&p, t, t, IDE_TIMING_ALL);
217 } 201 }
218 202
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 077fb674a96d..5e88a060df06 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -16,10 +16,6 @@
16 * (usually 14 & 15). 16 * (usually 14 & 15).
17 * There can be up to two drives per interface, as per the ATA-2 spec. 17 * There can be up to two drives per interface, as per the ATA-2 spec.
18 * 18 *
19 * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64
20 * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64
21 * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64
22 * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64
23 * ... 19 * ...
24 * 20 *
25 * From hd.c: 21 * From hd.c:
@@ -47,80 +43,6 @@
47 * This was a rewrite of just about everything from hd.c, though some original 43 * This was a rewrite of just about everything from hd.c, though some original
48 * code is still sprinkled about. Think of it as a major evolution, with 44 * code is still sprinkled about. Think of it as a major evolution, with
49 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au 45 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
50 *
51 * Version 1.0 ALPHA initial code, primary i/f working okay
52 * Version 1.3 BETA dual i/f on shared irq tested & working!
53 * Version 1.4 BETA added auto probing for irq(s)
54 * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms,
55 * ...
56 * Version 5.50 allow values as small as 20 for idebus=
57 * Version 5.51 force non io_32bit in drive_cmd_intr()
58 * change delay_10ms() to delay_50ms() to fix problems
59 * Version 5.52 fix incorrect invalidation of removable devices
60 * add "hdx=slow" command line option
61 * Version 5.60 start to modularize the driver; the disk and ATAPI
62 * drivers can be compiled as loadable modules.
63 * move IDE probe code to ide-probe.c
64 * move IDE disk code to ide-disk.c
65 * add support for generic IDE device subdrivers
66 * add m68k code from Geert Uytterhoeven
67 * probe all interfaces by default
68 * add ioctl to (re)probe an interface
69 * Version 6.00 use per device request queues
70 * attempt to optimize shared hwgroup performance
71 * add ioctl to manually adjust bandwidth algorithms
72 * add kerneld support for the probe module
73 * fix bug in ide_error()
74 * fix bug in the first ide_get_lock() call for Atari
75 * don't flush leftover data for ATAPI devices
76 * Version 6.01 clear hwgroup->active while the hwgroup sleeps
77 * support HDIO_GETGEO for floppies
78 * Version 6.02 fix ide_ack_intr() call
79 * check partition table on floppies
80 * Version 6.03 handle bad status bit sequencing in ide_wait_stat()
81 * Version 6.10 deleted old entries from this list of updates
82 * replaced triton.c with ide-dma.c generic PCI DMA
83 * added support for BIOS-enabled UltraDMA
84 * rename all "promise" things to "pdc4030"
85 * fix EZ-DRIVE handling on small disks
86 * Version 6.11 fix probe error in ide_scan_devices()
87 * fix ancient "jiffies" polling bugs
88 * mask all hwgroup interrupts on each irq entry
89 * Version 6.12 integrate ioctl and proc interfaces
90 * fix parsing of "idex=" command line parameter
91 * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com
92 * Version 6.14 fixed IRQ sharing among PCI devices
93 * Version 6.15 added SMP awareness to IDE drivers
94 * Version 6.16 fixed various bugs; even more SMP friendly
95 * Version 6.17 fix for newest EZ-Drive problem
96 * Version 6.18 default unpartitioned-disk translation now "BIOS LBA"
97 * Version 6.19 Re-design for a UNIFORM driver for all platforms,
98 * model based on suggestions from Russell King and
99 * Geert Uytterhoeven
100 * Promise DC4030VL now supported.
101 * add support for ide6/ide7
102 * delay_50ms() changed to ide_delay_50ms() and exported.
103 * Version 6.20 Added/Fixed Generic ATA-66 support and hwif detection.
104 * Added hdx=flash to allow for second flash disk
105 * detection w/o the hang loop.
106 * Added support for ide8/ide9
107 * Added idex=ata66 for the quirky chipsets that are
108 * ATA-66 compliant, but have yet to determine a method
109 * of verification of the 80c cable presence.
110 * Specifically Promise's PDC20262 chipset.
111 * Version 6.21 Fixing/Fixed SMP spinlock issue with insight from an old
112 * hat that clarified original low level driver design.
113 * Version 6.30 Added SMP support; fixed multmode issues. -ml
114 * Version 6.31 Debug Share INTR's and request queue streaming
115 * Native ATA-100 support
116 * Prep for Cascades Project
117 * Version 7.00alpha First named revision of ide rearrange
118 *
119 * Some additional driver compile-time options are in ./include/linux/ide.h
120 *
121 * To do, in likely order of completion:
122 * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
123 *
124 */ 46 */
125 47
126#define REVISION "Revision: 7.00alpha2" 48#define REVISION "Revision: 7.00alpha2"
@@ -455,6 +377,10 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
455 hwif->straight8 = tmp_hwif->straight8; 377 hwif->straight8 = tmp_hwif->straight8;
456 hwif->bus_state = tmp_hwif->bus_state; 378 hwif->bus_state = tmp_hwif->bus_state;
457 379
380 hwif->host_flags = tmp_hwif->host_flags;
381
382 hwif->pio_mask = tmp_hwif->pio_mask;
383
458 hwif->atapi_dma = tmp_hwif->atapi_dma; 384 hwif->atapi_dma = tmp_hwif->atapi_dma;
459 hwif->ultra_mask = tmp_hwif->ultra_mask; 385 hwif->ultra_mask = tmp_hwif->ultra_mask;
460 hwif->mwdma_mask = tmp_hwif->mwdma_mask; 386 hwif->mwdma_mask = tmp_hwif->mwdma_mask;
@@ -1171,10 +1097,6 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
1171 return 0; 1097 return 0;
1172 } 1098 }
1173 1099
1174 case CDROMEJECT:
1175 case CDROMCLOSETRAY:
1176 return scsi_cmd_ioctl(file, bdev->bd_disk->queue, bdev->bd_disk, cmd, p);
1177
1178 case HDIO_GET_BUSSTATE: 1100 case HDIO_GET_BUSSTATE:
1179 if (!capable(CAP_SYS_ADMIN)) 1101 if (!capable(CAP_SYS_ADMIN))
1180 return -EACCES; 1102 return -EACCES;
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index df17ed68c0bc..9b9c4761cb7d 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -115,13 +115,12 @@ static void ali14xx_tune_drive (ide_drive_t *drive, u8 pio)
115 int time1, time2; 115 int time1, time2;
116 u8 param1, param2, param3, param4; 116 u8 param1, param2, param3, param4;
117 unsigned long flags; 117 unsigned long flags;
118 ide_pio_data_t d;
119 int bus_speed = system_bus_clock(); 118 int bus_speed = system_bus_clock();
120 119
121 pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO, &d); 120 pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO);
122 121
123 /* calculate timing, according to PIO mode */ 122 /* calculate timing, according to PIO mode */
124 time1 = d.cycle_time; 123 time1 = ide_pio_cycle_time(drive, pio);
125 time2 = ide_pio_timings[pio].active_time; 124 time2 = ide_pio_timings[pio].active_time;
126 param3 = param1 = (time2 * bus_speed + 999) / 1000; 125 param3 = param1 = (time2 * bus_speed + 999) / 1000;
127 param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1; 126 param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1;
@@ -212,10 +211,12 @@ static int __init ali14xx_probe(void)
212 mate = &ide_hwifs[1]; 211 mate = &ide_hwifs[1];
213 212
214 hwif->chipset = ide_ali14xx; 213 hwif->chipset = ide_ali14xx;
214 hwif->pio_mask = ATA_PIO4;
215 hwif->tuneproc = &ali14xx_tune_drive; 215 hwif->tuneproc = &ali14xx_tune_drive;
216 hwif->mate = mate; 216 hwif->mate = mate;
217 217
218 mate->chipset = ide_ali14xx; 218 mate->chipset = ide_ali14xx;
219 mate->pio_mask = ATA_PIO4;
219 mate->tuneproc = &ali14xx_tune_drive; 220 mate->tuneproc = &ali14xx_tune_drive;
220 mate->mate = hwif; 221 mate->mate = hwif;
221 mate->channel = 1; 222 mate->channel = 1;
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index 36a3f0ac6162..6c01d951d074 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/dtc2278.c
@@ -71,7 +71,7 @@ static void tune_dtc2278 (ide_drive_t *drive, u8 pio)
71{ 71{
72 unsigned long flags; 72 unsigned long flags;
73 73
74 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 74 pio = ide_get_best_pio_mode(drive, pio, 4);
75 75
76 if (pio >= 3) { 76 if (pio >= 3) {
77 spin_lock_irqsave(&ide_lock, flags); 77 spin_lock_irqsave(&ide_lock, flags);
@@ -123,6 +123,7 @@ static int __init dtc2278_probe(void)
123 123
124 hwif->serialized = 1; 124 hwif->serialized = 1;
125 hwif->chipset = ide_dtc2278; 125 hwif->chipset = ide_dtc2278;
126 hwif->pio_mask = ATA_PIO4;
126 hwif->tuneproc = &tune_dtc2278; 127 hwif->tuneproc = &tune_dtc2278;
127 hwif->drives[0].no_unmask = 1; 128 hwif->drives[0].no_unmask = 1;
128 hwif->drives[1].no_unmask = 1; 129 hwif->drives[1].no_unmask = 1;
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index c8f353b1296f..bfaa2025173b 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -203,19 +203,21 @@ static u8 ht_pio2timings(ide_drive_t *drive, 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;
206 ide_pio_data_t d;
207 int bus_speed = system_bus_clock(); 206 int bus_speed = system_bus_clock();
208 207
209 if (pio) { 208 if (pio) {
210 pio = ide_get_best_pio_mode(drive, pio, 5, &d); 209 unsigned int cycle_time;
211 210
211 pio = ide_get_best_pio_mode(drive, pio, 5);
212 cycle_time = ide_pio_cycle_time(drive, pio);
213
212 /* 214 /*
213 * Just like opti621.c we try to calculate the 215 * Just like opti621.c we try to calculate the
214 * actual cycle time for recovery and activity 216 * actual cycle time for recovery and activity
215 * according system bus speed. 217 * according system bus speed.
216 */ 218 */
217 active_time = ide_pio_timings[pio].active_time; 219 active_time = ide_pio_timings[pio].active_time;
218 recovery_time = d.cycle_time 220 recovery_time = cycle_time
219 - active_time 221 - active_time
220 - ide_pio_timings[pio].setup_time; 222 - ide_pio_timings[pio].setup_time;
221 /* 223 /*
@@ -331,12 +333,14 @@ int __init ht6560b_init(void)
331 333
332 hwif->chipset = ide_ht6560b; 334 hwif->chipset = ide_ht6560b;
333 hwif->selectproc = &ht6560b_selectproc; 335 hwif->selectproc = &ht6560b_selectproc;
336 hwif->pio_mask = ATA_PIO5;
334 hwif->tuneproc = &tune_ht6560b; 337 hwif->tuneproc = &tune_ht6560b;
335 hwif->serialized = 1; /* is this needed? */ 338 hwif->serialized = 1; /* is this needed? */
336 hwif->mate = mate; 339 hwif->mate = mate;
337 340
338 mate->chipset = ide_ht6560b; 341 mate->chipset = ide_ht6560b;
339 mate->selectproc = &ht6560b_selectproc; 342 mate->selectproc = &ht6560b_selectproc;
343 mate->pio_mask = ATA_PIO5;
340 mate->tuneproc = &tune_ht6560b; 344 mate->tuneproc = &tune_ht6560b;
341 mate->serialized = 1; /* is this needed? */ 345 mate->serialized = 1; /* is this needed? */
342 mate->mate = hwif; 346 mate->mate = hwif;
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index 2f3977f195b7..4cdb519f9832 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -386,6 +386,7 @@ static struct pcmcia_device_id ide_ids[] = {
386 PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), 386 PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
387 PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), 387 PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
388 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), 388 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
389 PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
389 PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), 390 PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b),
390 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), 391 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
391 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), 392 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index 7783745dd167..8b87a424094a 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -252,38 +252,38 @@ static void qd6500_tune_drive (ide_drive_t *drive, u8 pio)
252 252
253static void qd6580_tune_drive (ide_drive_t *drive, u8 pio) 253static void qd6580_tune_drive (ide_drive_t *drive, u8 pio)
254{ 254{
255 ide_pio_data_t d;
256 int base = HWIF(drive)->select_data; 255 int base = HWIF(drive)->select_data;
256 unsigned int cycle_time;
257 int active_time = 175; 257 int active_time = 175;
258 int recovery_time = 415; /* worst case values from the dos driver */ 258 int recovery_time = 415; /* worst case values from the dos driver */
259 259
260 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) { 260 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) {
261 pio = ide_get_best_pio_mode(drive, pio, 4, &d); 261 pio = ide_get_best_pio_mode(drive, pio, 4);
262 cycle_time = ide_pio_cycle_time(drive, pio);
262 263
263 switch (pio) { 264 switch (pio) {
264 case 0: break; 265 case 0: break;
265 case 3: 266 case 3:
266 if (d.cycle_time >= 110) { 267 if (cycle_time >= 110) {
267 active_time = 86; 268 active_time = 86;
268 recovery_time = d.cycle_time - 102; 269 recovery_time = cycle_time - 102;
269 } else 270 } else
270 printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); 271 printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name);
271 break; 272 break;
272 case 4: 273 case 4:
273 if (d.cycle_time >= 69) { 274 if (cycle_time >= 69) {
274 active_time = 70; 275 active_time = 70;
275 recovery_time = d.cycle_time - 61; 276 recovery_time = cycle_time - 61;
276 } else 277 } else
277 printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); 278 printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name);
278 break; 279 break;
279 default: 280 default:
280 if (d.cycle_time >= 180) { 281 if (cycle_time >= 180) {
281 active_time = 110; 282 active_time = 110;
282 recovery_time = d.cycle_time - 120; 283 recovery_time = cycle_time - 120;
283 } else { 284 } else {
284 active_time = ide_pio_timings[pio].active_time; 285 active_time = ide_pio_timings[pio].active_time;
285 recovery_time = d.cycle_time 286 recovery_time = cycle_time - active_time;
286 -active_time;
287 } 287 }
288 } 288 }
289 printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio); 289 printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio);
@@ -346,6 +346,7 @@ static void __init qd_setup(ide_hwif_t *hwif, int base, int config,
346 hwif->drives[1].drive_data = data1; 346 hwif->drives[1].drive_data = data1;
347 hwif->drives[0].io_32bit = 347 hwif->drives[0].io_32bit =
348 hwif->drives[1].io_32bit = 1; 348 hwif->drives[1].io_32bit = 1;
349 hwif->pio_mask = ATA_PIO4;
349 hwif->tuneproc = tuneproc; 350 hwif->tuneproc = tuneproc;
350 probe_hwif_init(hwif); 351 probe_hwif_init(hwif);
351} 352}
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index ddc403a0bd82..d2862e638bc5 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/umc8672.c
@@ -110,7 +110,7 @@ static void tune_umc (ide_drive_t *drive, u8 pio)
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, NULL); 113 pio = ide_get_best_pio_mode(drive, pio, 4);
114 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", 114 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n",
115 drive->name, pio, pio_to_umc[pio]); 115 drive->name, pio, pio_to_umc[pio]);
116 spin_lock_irqsave(&ide_lock, flags); 116 spin_lock_irqsave(&ide_lock, flags);
@@ -149,10 +149,12 @@ static int __init umc8672_probe(void)
149 mate = &ide_hwifs[1]; 149 mate = &ide_hwifs[1];
150 150
151 hwif->chipset = ide_umc8672; 151 hwif->chipset = ide_umc8672;
152 hwif->pio_mask = ATA_PIO4;
152 hwif->tuneproc = &tune_umc; 153 hwif->tuneproc = &tune_umc;
153 hwif->mate = mate; 154 hwif->mate = mate;
154 155
155 mate->chipset = ide_umc8672; 156 mate->chipset = ide_umc8672;
157 mate->pio_mask = ATA_PIO4;
156 mate->tuneproc = &tune_umc; 158 mate->tuneproc = &tune_umc;
157 mate->mate = hwif; 159 mate->mate = hwif;
158 mate->channel = 1; 160 mate->channel = 1;
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 2e7013a2a7f6..2ba6a054b861 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -106,7 +106,7 @@ static void auide_tune_drive(ide_drive_t *drive, byte pio)
106 u8 speed; 106 u8 speed;
107 107
108 /* get the best pio mode for the drive */ 108 /* get the best pio mode for the drive */
109 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 109 pio = ide_get_best_pio_mode(drive, pio, 4);
110 110
111 printk(KERN_INFO "%s: setting Au1XXX IDE to PIO mode%d\n", 111 printk(KERN_INFO "%s: setting Au1XXX IDE to PIO mode%d\n",
112 drive->name, pio); 112 drive->name, pio);
@@ -692,6 +692,8 @@ static int au_ide_probe(struct device *dev)
692 hwif->swdma_mask = 0x0; 692 hwif->swdma_mask = 0x0;
693#endif 693#endif
694 694
695 hwif->pio_mask = ATA_PIO4;
696
695 hwif->noprobe = 0; 697 hwif->noprobe = 0;
696 hwif->drives[0].unmask = 1; 698 hwif->drives[0].unmask = 1;
697 hwif->drives[1].unmask = 1; 699 hwif->drives[1].unmask = 1;
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index e5d09367627e..74432830abf7 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -142,7 +142,7 @@ static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed)
142 142
143static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio) 143static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
144{ 144{
145 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 145 pio = ide_get_best_pio_mode(drive, pio, 4);
146 (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0); 146 (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0);
147} 147}
148 148
@@ -174,12 +174,6 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch
174{ 174{
175 int bus_speed = system_bus_clock(); 175 int bus_speed = system_bus_clock();
176 176
177 if (dev->resource[PCI_ROM_RESOURCE].start) {
178 pci_write_config_dword(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
179 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name,
180 (unsigned long)dev->resource[PCI_ROM_RESOURCE].start);
181 }
182
183 if (bus_speed <= 33) 177 if (bus_speed <= 33)
184 pci_set_drvdata(dev, (void *) aec6xxx_33_base); 178 pci_set_drvdata(dev, (void *) aec6xxx_33_base);
185 else 179 else
@@ -271,48 +265,48 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
271 .init_setup = init_setup_aec62xx, 265 .init_setup = init_setup_aec62xx,
272 .init_chipset = init_chipset_aec62xx, 266 .init_chipset = init_chipset_aec62xx,
273 .init_hwif = init_hwif_aec62xx, 267 .init_hwif = init_hwif_aec62xx,
274 .channels = 2,
275 .autodma = AUTODMA, 268 .autodma = AUTODMA,
276 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 269 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
277 .bootable = OFF_BOARD, 270 .bootable = OFF_BOARD,
271 .pio_mask = ATA_PIO4,
278 .udma_mask = 0x07, /* udma0-2 */ 272 .udma_mask = 0x07, /* udma0-2 */
279 },{ /* 1 */ 273 },{ /* 1 */
280 .name = "AEC6260", 274 .name = "AEC6260",
281 .init_setup = init_setup_aec62xx, 275 .init_setup = init_setup_aec62xx,
282 .init_chipset = init_chipset_aec62xx, 276 .init_chipset = init_chipset_aec62xx,
283 .init_hwif = init_hwif_aec62xx, 277 .init_hwif = init_hwif_aec62xx,
284 .channels = 2,
285 .autodma = NOAUTODMA, 278 .autodma = NOAUTODMA,
286 .bootable = OFF_BOARD, 279 .bootable = OFF_BOARD,
280 .pio_mask = ATA_PIO4,
287 .udma_mask = 0x1f, /* udma0-4 */ 281 .udma_mask = 0x1f, /* udma0-4 */
288 },{ /* 2 */ 282 },{ /* 2 */
289 .name = "AEC6260R", 283 .name = "AEC6260R",
290 .init_setup = init_setup_aec62xx, 284 .init_setup = init_setup_aec62xx,
291 .init_chipset = init_chipset_aec62xx, 285 .init_chipset = init_chipset_aec62xx,
292 .init_hwif = init_hwif_aec62xx, 286 .init_hwif = init_hwif_aec62xx,
293 .channels = 2,
294 .autodma = AUTODMA, 287 .autodma = AUTODMA,
295 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 288 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
296 .bootable = NEVER_BOARD, 289 .bootable = NEVER_BOARD,
290 .pio_mask = ATA_PIO4,
297 .udma_mask = 0x1f, /* udma0-4 */ 291 .udma_mask = 0x1f, /* udma0-4 */
298 },{ /* 3 */ 292 },{ /* 3 */
299 .name = "AEC6280", 293 .name = "AEC6280",
300 .init_setup = init_setup_aec6x80, 294 .init_setup = init_setup_aec6x80,
301 .init_chipset = init_chipset_aec62xx, 295 .init_chipset = init_chipset_aec62xx,
302 .init_hwif = init_hwif_aec62xx, 296 .init_hwif = init_hwif_aec62xx,
303 .channels = 2,
304 .autodma = AUTODMA, 297 .autodma = AUTODMA,
305 .bootable = OFF_BOARD, 298 .bootable = OFF_BOARD,
299 .pio_mask = ATA_PIO4,
306 .udma_mask = 0x3f, /* udma0-5 */ 300 .udma_mask = 0x3f, /* udma0-5 */
307 },{ /* 4 */ 301 },{ /* 4 */
308 .name = "AEC6280R", 302 .name = "AEC6280R",
309 .init_setup = init_setup_aec6x80, 303 .init_setup = init_setup_aec6x80,
310 .init_chipset = init_chipset_aec62xx, 304 .init_chipset = init_chipset_aec62xx,
311 .init_hwif = init_hwif_aec62xx, 305 .init_hwif = init_hwif_aec62xx,
312 .channels = 2,
313 .autodma = AUTODMA, 306 .autodma = AUTODMA,
314 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 307 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
315 .bootable = OFF_BOARD, 308 .bootable = OFF_BOARD,
309 .pio_mask = ATA_PIO4,
316 .udma_mask = 0x3f, /* udma0-5 */ 310 .udma_mask = 0x3f, /* udma0-5 */
317 } 311 }
318}; 312};
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index ba0fb92b0417..5511c86733dc 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -295,7 +295,6 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
295 295
296static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio) 296static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio)
297{ 297{
298 ide_pio_data_t d;
299 ide_hwif_t *hwif = HWIF(drive); 298 ide_hwif_t *hwif = HWIF(drive);
300 struct pci_dev *dev = hwif->pci_dev; 299 struct pci_dev *dev = hwif->pci_dev;
301 int s_time, a_time, c_time; 300 int s_time, a_time, c_time;
@@ -307,7 +306,7 @@ static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio)
307 u8 cd_dma_fifo = 0; 306 u8 cd_dma_fifo = 0;
308 int unit = drive->select.b.unit & 1; 307 int unit = drive->select.b.unit & 1;
309 308
310 pio = ide_get_best_pio_mode(drive, pio, 5, &d); 309 pio = ide_get_best_pio_mode(drive, pio, 5);
311 s_time = ide_pio_timings[pio].setup_time; 310 s_time = ide_pio_timings[pio].setup_time;
312 a_time = ide_pio_timings[pio].active_time; 311 a_time = ide_pio_timings[pio].active_time;
313 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) 312 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
@@ -817,9 +816,9 @@ static ide_pci_device_t ali15x3_chipset __devinitdata = {
817 .init_chipset = init_chipset_ali15x3, 816 .init_chipset = init_chipset_ali15x3,
818 .init_hwif = init_hwif_ali15x3, 817 .init_hwif = init_hwif_ali15x3,
819 .init_dma = init_dma_ali15x3, 818 .init_dma = init_dma_ali15x3,
820 .channels = 2,
821 .autodma = AUTODMA, 819 .autodma = AUTODMA,
822 .bootable = ON_BOARD, 820 .bootable = ON_BOARD,
821 .pio_mask = ATA_PIO5,
823}; 822};
824 823
825/** 824/**
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 8d30b99a54d8..06c15a6a3e7d 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Version 2.20 2 * Version 2.21
3 * 3 *
4 * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04 4 * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04
5 * IDE driver for Linux. 5 * IDE driver for Linux.
@@ -272,10 +272,8 @@ static int amd_set_drive(ide_drive_t *drive, u8 speed)
272 272
273static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio) 273static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio)
274{ 274{
275 if (pio == 255) { 275 if (pio == 255)
276 amd_set_drive(drive, ide_find_best_pio_mode(drive)); 276 pio = ide_get_best_pio_mode(drive, 255, 5);
277 return;
278 }
279 277
280 amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5)); 278 amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5));
281} 279}
@@ -284,12 +282,14 @@ static int amd74xx_ide_dma_check(ide_drive_t *drive)
284{ 282{
285 u8 speed = ide_max_dma_mode(drive); 283 u8 speed = ide_max_dma_mode(drive);
286 284
287 if (speed == 0) 285 if (speed == 0) {
288 speed = ide_find_best_pio_mode(drive); 286 amd74xx_tune_drive(drive, 255);
287 return -1;
288 }
289 289
290 amd_set_drive(drive, speed); 290 amd_set_drive(drive, speed);
291 291
292 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 292 if (drive->autodma)
293 return 0; 293 return 0;
294 294
295 return -1; 295 return -1;
@@ -448,10 +448,12 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
448 .name = name_str, \ 448 .name = name_str, \
449 .init_chipset = init_chipset_amd74xx, \ 449 .init_chipset = init_chipset_amd74xx, \
450 .init_hwif = init_hwif_amd74xx, \ 450 .init_hwif = init_hwif_amd74xx, \
451 .channels = 2, \
452 .autodma = AUTODMA, \ 451 .autodma = AUTODMA, \
453 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ 452 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \
454 .bootable = ON_BOARD, \ 453 .bootable = ON_BOARD, \
454 .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST \
455 | IDE_HFLAG_PIO_NO_DOWNGRADE, \
456 .pio_mask = ATA_PIO5, \
455 } 457 }
456 458
457#define DECLARE_NV_DEV(name_str) \ 459#define DECLARE_NV_DEV(name_str) \
@@ -459,10 +461,12 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
459 .name = name_str, \ 461 .name = name_str, \
460 .init_chipset = init_chipset_amd74xx, \ 462 .init_chipset = init_chipset_amd74xx, \
461 .init_hwif = init_hwif_amd74xx, \ 463 .init_hwif = init_hwif_amd74xx, \
462 .channels = 2, \
463 .autodma = AUTODMA, \ 464 .autodma = AUTODMA, \
464 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ 465 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \
465 .bootable = ON_BOARD, \ 466 .bootable = ON_BOARD, \
467 .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST \
468 | IDE_HFLAG_PIO_NO_DOWNGRADE, \
469 .pio_mask = ATA_PIO5, \
466 } 470 }
467 471
468static ide_pci_device_t amd74xx_chipsets[] __devinitdata = { 472static ide_pci_device_t amd74xx_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 2761510309b3..1725aa402d98 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -1,9 +1,8 @@
1/* 1/*
2 * linux/drivers/ide/pci/atiixp.c Version 0.01-bart2 Feb. 26, 2004 2 * linux/drivers/ide/pci/atiixp.c Version 0.02 Jun 16 2007
3 * 3 *
4 * Copyright (C) 2003 ATI Inc. <hyu@ati.com> 4 * Copyright (C) 2003 ATI Inc. <hyu@ati.com>
5 * Copyright (C) 2004 Bartlomiej Zolnierkiewicz 5 * Copyright (C) 2004,2007 Bartlomiej Zolnierkiewicz
6 *
7 */ 6 */
8 7
9#include <linux/types.h> 8#include <linux/types.h>
@@ -123,14 +122,14 @@ static void atiixp_dma_host_off(ide_drive_t *drive)
123} 122}
124 123
125/** 124/**
126 * atiixp_tune_drive - tune a drive attached to a ATIIXP 125 * atiixp_tune_pio - tune a drive attached to a ATIIXP
127 * @drive: drive to tune 126 * @drive: drive to tune
128 * @pio: desired PIO mode 127 * @pio: desired PIO mode
129 * 128 *
130 * Set the interface PIO mode. 129 * Set the interface PIO mode.
131 */ 130 */
132 131
133static void atiixp_tuneproc(ide_drive_t *drive, u8 pio) 132static void atiixp_tune_pio(ide_drive_t *drive, u8 pio)
134{ 133{
135 struct pci_dev *dev = drive->hwif->pci_dev; 134 struct pci_dev *dev = drive->hwif->pci_dev;
136 unsigned long flags; 135 unsigned long flags;
@@ -154,6 +153,13 @@ static void atiixp_tuneproc(ide_drive_t *drive, u8 pio)
154 spin_unlock_irqrestore(&atiixp_lock, flags); 153 spin_unlock_irqrestore(&atiixp_lock, flags);
155} 154}
156 155
156static void atiixp_tuneproc(ide_drive_t *drive, u8 pio)
157{
158 pio = ide_get_best_pio_mode(drive, pio, 4);
159 atiixp_tune_pio(drive, pio);
160 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio);
161}
162
157/** 163/**
158 * atiixp_tune_chipset - tune a ATIIXP interface 164 * atiixp_tune_chipset - tune a ATIIXP interface
159 * @drive: IDE drive to tune 165 * @drive: IDE drive to tune
@@ -175,6 +181,11 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
175 181
176 speed = ide_rate_filter(drive, xferspeed); 182 speed = ide_rate_filter(drive, xferspeed);
177 183
184 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
185 atiixp_tune_pio(drive, speed - XFER_PIO_0);
186 return ide_config_drive_speed(drive, speed);
187 }
188
178 spin_lock_irqsave(&atiixp_lock, flags); 189 spin_lock_irqsave(&atiixp_lock, flags);
179 190
180 save_mdma_mode[drive->dn] = 0; 191 save_mdma_mode[drive->dn] = 0;
@@ -201,7 +212,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
201 else 212 else
202 pio = speed - XFER_PIO_0; 213 pio = speed - XFER_PIO_0;
203 214
204 atiixp_tuneproc(drive, pio); 215 atiixp_tune_pio(drive, pio);
205 216
206 return ide_config_drive_speed(drive, speed); 217 return ide_config_drive_speed(drive, speed);
207} 218}
@@ -216,18 +227,13 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
216 227
217static int atiixp_dma_check(ide_drive_t *drive) 228static int atiixp_dma_check(ide_drive_t *drive)
218{ 229{
219 u8 tspeed, speed;
220
221 drive->init_speed = 0; 230 drive->init_speed = 0;
222 231
223 if (ide_tune_dma(drive)) 232 if (ide_tune_dma(drive))
224 return 0; 233 return 0;
225 234
226 if (ide_use_fast_pio(drive)) { 235 if (ide_use_fast_pio(drive))
227 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 236 atiixp_tuneproc(drive, 255);
228 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0;
229 atiixp_speedproc(drive, speed);
230 }
231 237
232 return -1; 238 return -1;
233} 239}
@@ -285,17 +291,18 @@ static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
285 { /* 0 */ 291 { /* 0 */
286 .name = "ATIIXP", 292 .name = "ATIIXP",
287 .init_hwif = init_hwif_atiixp, 293 .init_hwif = init_hwif_atiixp,
288 .channels = 2,
289 .autodma = AUTODMA, 294 .autodma = AUTODMA,
290 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 295 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
291 .bootable = ON_BOARD, 296 .bootable = ON_BOARD,
297 .pio_mask = ATA_PIO4,
292 },{ /* 1 */ 298 },{ /* 1 */
293 .name = "SB600_PATA", 299 .name = "SB600_PATA",
294 .init_hwif = init_hwif_atiixp, 300 .init_hwif = init_hwif_atiixp,
295 .channels = 1,
296 .autodma = AUTODMA, 301 .autodma = AUTODMA,
297 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, 302 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
298 .bootable = ON_BOARD, 303 .bootable = ON_BOARD,
304 .host_flags = IDE_HFLAG_SINGLE,
305 .pio_mask = ATA_PIO4,
299 }, 306 },
300}; 307};
301 308
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index dc43f009acab..9689494efa24 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -633,9 +633,8 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle
633 */ 633 */
634static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted) 634static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted)
635{ 635{
636 unsigned int index = 0, cycle_time;
636 u8 b; 637 u8 b;
637 ide_pio_data_t d;
638 unsigned int index = 0;
639 638
640 while (drive != cmd_drives[index]) { 639 while (drive != cmd_drives[index]) {
641 if (++index > 3) { 640 if (++index > 3) {
@@ -662,16 +661,14 @@ static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted)
662 return; 661 return;
663 } 662 }
664 663
665 (void) ide_get_best_pio_mode (drive, mode_wanted, 5, &d); 664 mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 5);
666 cmd640_set_mode (index, d.pio_mode, d.cycle_time); 665 cycle_time = ide_pio_cycle_time(drive, mode_wanted);
666 cmd640_set_mode(index, mode_wanted, cycle_time);
667
668 printk("%s: selected cmd640 PIO mode%d (%dns)",
669 drive->name, mode_wanted, cycle_time);
667 670
668 printk ("%s: selected cmd640 PIO mode%d (%dns)%s",
669 drive->name,
670 d.pio_mode,
671 d.cycle_time,
672 d.overridden ? " (overriding vendor mode)" : "");
673 display_clocks(index); 671 display_clocks(index);
674 return;
675} 672}
676 673
677#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 674#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
@@ -769,6 +766,7 @@ int __init ide_probe_for_cmd640x (void)
769 cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr); 766 cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr);
770 cmd_hwif0->chipset = ide_cmd640; 767 cmd_hwif0->chipset = ide_cmd640;
771#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 768#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
769 cmd_hwif0->pio_mask = ATA_PIO5;
772 cmd_hwif0->tuneproc = &cmd640_tune_drive; 770 cmd_hwif0->tuneproc = &cmd640_tune_drive;
773#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 771#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
774 772
@@ -824,6 +822,7 @@ int __init ide_probe_for_cmd640x (void)
824 cmd_hwif1->mate = cmd_hwif0; 822 cmd_hwif1->mate = cmd_hwif0;
825 cmd_hwif1->channel = 1; 823 cmd_hwif1->channel = 1;
826#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 824#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
825 cmd_hwif1->pio_mask = ATA_PIO5;
827 cmd_hwif1->tuneproc = &cmd640_tune_drive; 826 cmd_hwif1->tuneproc = &cmd640_tune_drive;
828#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 827#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
829 } 828 }
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 1e89dd6e5bbf..19633c5aba15 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -221,17 +221,18 @@ static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted)
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 ide_pio_data_t pio; 224 unsigned int cycle_time;
225 u8 pio_mode, setup_count, arttim = 0; 225 u8 pio_mode, setup_count, arttim = 0;
226 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; 226 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0};
227 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; 227 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23};
228 pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &pio);
229 228
230 cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)%s\n", 229 pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5);
231 drive->name, mode_wanted, pio_mode, pio.cycle_time, 230 cycle_time = ide_pio_cycle_time(drive, pio_mode);
232 pio.overridden ? " (overriding vendor mode)" : "");
233 231
234 program_cycle_times(drive, pio.cycle_time, 232 cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)\n",
233 drive->name, mode_wanted, pio_mode, cycle_time);
234
235 program_cycle_times(drive, cycle_time,
235 ide_pio_timings[pio_mode].active_time); 236 ide_pio_timings[pio_mode].active_time);
236 237
237 setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time, 238 setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time,
@@ -618,40 +619,40 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
618 .init_setup = init_setup_cmd64x, 619 .init_setup = init_setup_cmd64x,
619 .init_chipset = init_chipset_cmd64x, 620 .init_chipset = init_chipset_cmd64x,
620 .init_hwif = init_hwif_cmd64x, 621 .init_hwif = init_hwif_cmd64x,
621 .channels = 2,
622 .autodma = AUTODMA, 622 .autodma = AUTODMA,
623 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 623 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
624 .bootable = ON_BOARD, 624 .bootable = ON_BOARD,
625 .pio_mask = ATA_PIO5,
625 .udma_mask = 0x00, /* no udma */ 626 .udma_mask = 0x00, /* no udma */
626 },{ /* 1 */ 627 },{ /* 1 */
627 .name = "CMD646", 628 .name = "CMD646",
628 .init_setup = init_setup_cmd646, 629 .init_setup = init_setup_cmd646,
629 .init_chipset = init_chipset_cmd64x, 630 .init_chipset = init_chipset_cmd64x,
630 .init_hwif = init_hwif_cmd64x, 631 .init_hwif = init_hwif_cmd64x,
631 .channels = 2,
632 .autodma = AUTODMA, 632 .autodma = AUTODMA,
633 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 633 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
634 .bootable = ON_BOARD, 634 .bootable = ON_BOARD,
635 .pio_mask = ATA_PIO5,
635 .udma_mask = 0x07, /* udma0-2 */ 636 .udma_mask = 0x07, /* udma0-2 */
636 },{ /* 2 */ 637 },{ /* 2 */
637 .name = "CMD648", 638 .name = "CMD648",
638 .init_setup = init_setup_cmd64x, 639 .init_setup = init_setup_cmd64x,
639 .init_chipset = init_chipset_cmd64x, 640 .init_chipset = init_chipset_cmd64x,
640 .init_hwif = init_hwif_cmd64x, 641 .init_hwif = init_hwif_cmd64x,
641 .channels = 2,
642 .autodma = AUTODMA, 642 .autodma = AUTODMA,
643 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 643 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
644 .bootable = ON_BOARD, 644 .bootable = ON_BOARD,
645 .pio_mask = ATA_PIO5,
645 .udma_mask = 0x1f, /* udma0-4 */ 646 .udma_mask = 0x1f, /* udma0-4 */
646 },{ /* 3 */ 647 },{ /* 3 */
647 .name = "CMD649", 648 .name = "CMD649",
648 .init_setup = init_setup_cmd64x, 649 .init_setup = init_setup_cmd64x,
649 .init_chipset = init_chipset_cmd64x, 650 .init_chipset = init_chipset_cmd64x,
650 .init_hwif = init_hwif_cmd64x, 651 .init_hwif = init_hwif_cmd64x,
651 .channels = 2,
652 .autodma = AUTODMA, 652 .autodma = AUTODMA,
653 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 653 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
654 .bootable = ON_BOARD, 654 .bootable = ON_BOARD,
655 .pio_mask = ATA_PIO5,
655 .udma_mask = 0x3f, /* udma0-5 */ 656 .udma_mask = 0x3f, /* udma0-5 */
656 } 657 }
657}; 658};
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index 3b88a3a56116..bccedf9b8b28 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -126,7 +126,7 @@ static int cs5520_tune_chipset(ide_drive_t *drive, u8 xferspeed)
126 126
127static void cs5520_tune_drive(ide_drive_t *drive, u8 pio) 127static void cs5520_tune_drive(ide_drive_t *drive, u8 pio)
128{ 128{
129 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 129 pio = ide_get_best_pio_mode(drive, pio, 4);
130 cs5520_tune_chipset(drive, (XFER_PIO_0 + pio)); 130 cs5520_tune_chipset(drive, (XFER_PIO_0 + pio));
131} 131}
132 132
@@ -194,10 +194,10 @@ static void __devinit init_hwif_cs5520(ide_hwif_t *hwif)
194 .name = name_str, \ 194 .name = name_str, \
195 .init_setup_dma = cs5520_init_setup_dma, \ 195 .init_setup_dma = cs5520_init_setup_dma, \
196 .init_hwif = init_hwif_cs5520, \ 196 .init_hwif = init_hwif_cs5520, \
197 .channels = 2, \
198 .autodma = AUTODMA, \ 197 .autodma = AUTODMA, \
199 .bootable = ON_BOARD, \ 198 .bootable = ON_BOARD, \
200 .flags = IDEPCI_FLAG_ISA_PORTS, \ 199 .host_flags = IDE_HFLAG_ISA_PORTS, \
200 .pio_mask = ATA_PIO4, \
201 } 201 }
202 202
203static ide_pci_device_t cyrix_chipsets[] __devinitdata = { 203static ide_pci_device_t cyrix_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index b5c00d15a704..acaf71fd4c09 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -82,7 +82,7 @@ static void cs5530_tunepio(ide_drive_t *drive, u8 pio)
82 82
83static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */ 83static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */
84{ 84{
85 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 85 pio = ide_get_best_pio_mode(drive, pio, 4);
86 86
87 if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) 87 if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0)
88 cs5530_tunepio(drive, pio); 88 cs5530_tunepio(drive, pio);
@@ -341,9 +341,9 @@ static ide_pci_device_t cs5530_chipset __devinitdata = {
341 .name = "CS5530", 341 .name = "CS5530",
342 .init_chipset = init_chipset_cs5530, 342 .init_chipset = init_chipset_cs5530,
343 .init_hwif = init_hwif_cs5530, 343 .init_hwif = init_hwif_cs5530,
344 .channels = 2,
345 .autodma = AUTODMA, 344 .autodma = AUTODMA,
346 .bootable = ON_BOARD, 345 .bootable = ON_BOARD,
346 .pio_mask = ATA_PIO4,
347}; 347};
348 348
349static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id) 349static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 10f61f38243c..ce44e38390aa 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -89,7 +89,7 @@ static void cs5535_set_speed(ide_drive_t *drive, u8 speed)
89 89
90 pioa = speed - XFER_PIO_0; 90 pioa = speed - XFER_PIO_0;
91 piob = ide_get_best_pio_mode(&(drive->hwif->drives[!unit]), 91 piob = ide_get_best_pio_mode(&(drive->hwif->drives[!unit]),
92 255, 4, NULL); 92 255, 4);
93 cmd = pioa < piob ? pioa : piob; 93 cmd = pioa < piob ? pioa : piob;
94 94
95 /* Write the speed of the current drive */ 95 /* Write the speed of the current drive */
@@ -159,7 +159,7 @@ static void cs5535_tuneproc(ide_drive_t *drive, u8 xferspeed)
159 /* cs5535 max pio is pio 4, best_pio will check the blacklist. 159 /* cs5535 max pio is pio 4, best_pio will check the blacklist.
160 i think we don't need to rate_filter the incoming xferspeed 160 i think we don't need to rate_filter the incoming xferspeed
161 since we know we're only going to choose pio */ 161 since we know we're only going to choose pio */
162 xferspeed = ide_get_best_pio_mode(drive, xferspeed, 4, NULL); 162 xferspeed = ide_get_best_pio_mode(drive, xferspeed, 4);
163 ide_config_drive_speed(drive, modes[xferspeed]); 163 ide_config_drive_speed(drive, modes[xferspeed]);
164 cs5535_set_speed(drive, xferspeed); 164 cs5535_set_speed(drive, xferspeed);
165} 165}
@@ -174,7 +174,7 @@ static int cs5535_dma_check(ide_drive_t *drive)
174 return 0; 174 return 0;
175 175
176 if (ide_use_fast_pio(drive)) { 176 if (ide_use_fast_pio(drive)) {
177 speed = ide_get_best_pio_mode(drive, 255, 4, NULL); 177 speed = ide_get_best_pio_mode(drive, 255, 4);
178 cs5535_set_drive(drive, speed); 178 cs5535_set_drive(drive, speed);
179 } 179 }
180 180
@@ -228,9 +228,10 @@ static void __devinit init_hwif_cs5535(ide_hwif_t *hwif)
228static ide_pci_device_t cs5535_chipset __devinitdata = { 228static ide_pci_device_t cs5535_chipset __devinitdata = {
229 .name = "CS5535", 229 .name = "CS5535",
230 .init_hwif = init_hwif_cs5535, 230 .init_hwif = init_hwif_cs5535,
231 .channels = 1,
232 .autodma = AUTODMA, 231 .autodma = AUTODMA,
233 .bootable = ON_BOARD, 232 .bootable = ON_BOARD,
233 .host_flags = IDE_HFLAG_SINGLE,
234 .pio_mask = ATA_PIO4,
234}; 235};
235 236
236static int __devinit cs5535_init_one(struct pci_dev *dev, 237static int __devinit cs5535_init_one(struct pci_dev *dev,
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 103b9db97853..daa36fcbc8ef 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -330,7 +330,7 @@ static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio)
330#endif /* CY82C693_DEBUG_LOGS */ 330#endif /* CY82C693_DEBUG_LOGS */
331 331
332 /* first let's calc the pio modes */ 332 /* first let's calc the pio modes */
333 pio = ide_get_best_pio_mode(drive, pio, CY82C693_MAX_PIO, NULL); 333 pio = ide_get_best_pio_mode(drive, pio, CY82C693_MAX_PIO);
334 334
335#if CY82C693_DEBUG_INFO 335#if CY82C693_DEBUG_INFO
336 printk (KERN_INFO "%s: Selected PIO mode %d\n", drive->name, pio); 336 printk (KERN_INFO "%s: Selected PIO mode %d\n", drive->name, pio);
@@ -483,9 +483,10 @@ static ide_pci_device_t cy82c693_chipset __devinitdata = {
483 .init_chipset = init_chipset_cy82c693, 483 .init_chipset = init_chipset_cy82c693,
484 .init_iops = init_iops_cy82c693, 484 .init_iops = init_iops_cy82c693,
485 .init_hwif = init_hwif_cy82c693, 485 .init_hwif = init_hwif_cy82c693,
486 .channels = 1,
487 .autodma = AUTODMA, 486 .autodma = AUTODMA,
488 .bootable = ON_BOARD, 487 .bootable = ON_BOARD,
488 .host_flags = IDE_HFLAG_SINGLE,
489 .pio_mask = ATA_PIO4,
489}; 490};
490 491
491static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id) 492static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 0d51a11e81da..48caa468b762 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -95,92 +95,77 @@ static ide_pci_device_t generic_chipsets[] __devinitdata = {
95 { /* 0 */ 95 { /* 0 */
96 .name = "Unknown", 96 .name = "Unknown",
97 .init_hwif = init_hwif_generic, 97 .init_hwif = init_hwif_generic,
98 .channels = 2,
99 .autodma = AUTODMA, 98 .autodma = AUTODMA,
100 .bootable = ON_BOARD, 99 .bootable = ON_BOARD,
101 },{ /* 1 */ 100 },{ /* 1 */
102 .name = "NS87410", 101 .name = "NS87410",
103 .init_hwif = init_hwif_generic, 102 .init_hwif = init_hwif_generic,
104 .channels = 2,
105 .autodma = AUTODMA, 103 .autodma = AUTODMA,
106 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, 104 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}},
107 .bootable = ON_BOARD, 105 .bootable = ON_BOARD,
108 },{ /* 2 */ 106 },{ /* 2 */
109 .name = "SAMURAI", 107 .name = "SAMURAI",
110 .init_hwif = init_hwif_generic, 108 .init_hwif = init_hwif_generic,
111 .channels = 2,
112 .autodma = AUTODMA, 109 .autodma = AUTODMA,
113 .bootable = ON_BOARD, 110 .bootable = ON_BOARD,
114 },{ /* 3 */ 111 },{ /* 3 */
115 .name = "HT6565", 112 .name = "HT6565",
116 .init_hwif = init_hwif_generic, 113 .init_hwif = init_hwif_generic,
117 .channels = 2,
118 .autodma = AUTODMA, 114 .autodma = AUTODMA,
119 .bootable = ON_BOARD, 115 .bootable = ON_BOARD,
120 },{ /* 4 */ 116 },{ /* 4 */
121 .name = "UM8673F", 117 .name = "UM8673F",
122 .init_hwif = init_hwif_generic, 118 .init_hwif = init_hwif_generic,
123 .channels = 2,
124 .autodma = NODMA, 119 .autodma = NODMA,
125 .bootable = ON_BOARD, 120 .bootable = ON_BOARD,
126 },{ /* 5 */ 121 },{ /* 5 */
127 .name = "UM8886A", 122 .name = "UM8886A",
128 .init_hwif = init_hwif_generic, 123 .init_hwif = init_hwif_generic,
129 .channels = 2,
130 .autodma = NODMA, 124 .autodma = NODMA,
131 .bootable = ON_BOARD, 125 .bootable = ON_BOARD,
132 },{ /* 6 */ 126 },{ /* 6 */
133 .name = "UM8886BF", 127 .name = "UM8886BF",
134 .init_hwif = init_hwif_generic, 128 .init_hwif = init_hwif_generic,
135 .channels = 2,
136 .autodma = NODMA, 129 .autodma = NODMA,
137 .bootable = ON_BOARD, 130 .bootable = ON_BOARD,
138 },{ /* 7 */ 131 },{ /* 7 */
139 .name = "HINT_IDE", 132 .name = "HINT_IDE",
140 .init_hwif = init_hwif_generic, 133 .init_hwif = init_hwif_generic,
141 .channels = 2,
142 .autodma = AUTODMA, 134 .autodma = AUTODMA,
143 .bootable = ON_BOARD, 135 .bootable = ON_BOARD,
144 },{ /* 8 */ 136 },{ /* 8 */
145 .name = "VIA_IDE", 137 .name = "VIA_IDE",
146 .init_hwif = init_hwif_generic, 138 .init_hwif = init_hwif_generic,
147 .channels = 2,
148 .autodma = NOAUTODMA, 139 .autodma = NOAUTODMA,
149 .bootable = ON_BOARD, 140 .bootable = ON_BOARD,
150 },{ /* 9 */ 141 },{ /* 9 */
151 .name = "OPTI621V", 142 .name = "OPTI621V",
152 .init_hwif = init_hwif_generic, 143 .init_hwif = init_hwif_generic,
153 .channels = 2,
154 .autodma = NOAUTODMA, 144 .autodma = NOAUTODMA,
155 .bootable = ON_BOARD, 145 .bootable = ON_BOARD,
156 },{ /* 10 */ 146 },{ /* 10 */
157 .name = "VIA8237SATA", 147 .name = "VIA8237SATA",
158 .init_hwif = init_hwif_generic, 148 .init_hwif = init_hwif_generic,
159 .channels = 2,
160 .autodma = AUTODMA, 149 .autodma = AUTODMA,
161 .bootable = OFF_BOARD, 150 .bootable = OFF_BOARD,
162 },{ /* 11 */ 151 },{ /* 11 */
163 .name = "Piccolo0102", 152 .name = "Piccolo0102",
164 .init_hwif = init_hwif_generic, 153 .init_hwif = init_hwif_generic,
165 .channels = 2,
166 .autodma = NOAUTODMA, 154 .autodma = NOAUTODMA,
167 .bootable = ON_BOARD, 155 .bootable = ON_BOARD,
168 },{ /* 12 */ 156 },{ /* 12 */
169 .name = "Piccolo0103", 157 .name = "Piccolo0103",
170 .init_hwif = init_hwif_generic, 158 .init_hwif = init_hwif_generic,
171 .channels = 2,
172 .autodma = NOAUTODMA, 159 .autodma = NOAUTODMA,
173 .bootable = ON_BOARD, 160 .bootable = ON_BOARD,
174 },{ /* 13 */ 161 },{ /* 13 */
175 .name = "Piccolo0105", 162 .name = "Piccolo0105",
176 .init_hwif = init_hwif_generic, 163 .init_hwif = init_hwif_generic,
177 .channels = 2,
178 .autodma = NOAUTODMA, 164 .autodma = NOAUTODMA,
179 .bootable = ON_BOARD, 165 .bootable = ON_BOARD,
180 },{ /* 14 */ 166 },{ /* 14 */
181 .name = "Revolution", 167 .name = "Revolution",
182 .init_hwif = init_hwif_generic, 168 .init_hwif = init_hwif_generic,
183 .channels = 2,
184 .autodma = AUTODMA, 169 .autodma = AUTODMA,
185 .bootable = OFF_BOARD, 170 .bootable = OFF_BOARD,
186 } 171 }
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 2c24c3de8846..19778c5fe711 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -80,7 +80,7 @@ static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
80 80
81static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) 81static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio)
82{ 82{
83 pio = ide_get_best_pio_mode(drive, pio, 5, NULL); 83 pio = ide_get_best_pio_mode(drive, pio, 5);
84 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); 84 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio));
85} 85}
86 86
@@ -120,17 +120,10 @@ static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev, const cha
120 pci_write_config_byte(dev, HPT34X_PCI_INIT_REG, 0x00); 120 pci_write_config_byte(dev, HPT34X_PCI_INIT_REG, 0x00);
121 pci_read_config_word(dev, PCI_COMMAND, &cmd); 121 pci_read_config_word(dev, PCI_COMMAND, &cmd);
122 122
123 if (cmd & PCI_COMMAND_MEMORY) { 123 if (cmd & PCI_COMMAND_MEMORY)
124 if (pci_resource_start(dev, PCI_ROM_RESOURCE)) {
125 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
126 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
127 printk(KERN_INFO "HPT345: ROM enabled at 0x%08lx\n",
128 (unsigned long)dev->resource[PCI_ROM_RESOURCE].start);
129 }
130 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0); 124 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0);
131 } else { 125 else
132 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 126 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
133 }
134 127
135 /* 128 /*
136 * Since 20-23 can be assigned and are R/W, we correct them. 129 * Since 20-23 can be assigned and are R/W, we correct them.
@@ -182,10 +175,10 @@ static ide_pci_device_t hpt34x_chipset __devinitdata = {
182 .name = "HPT34X", 175 .name = "HPT34X",
183 .init_chipset = init_chipset_hpt34x, 176 .init_chipset = init_chipset_hpt34x,
184 .init_hwif = init_hwif_hpt34x, 177 .init_hwif = init_hwif_hpt34x,
185 .channels = 2,
186 .autodma = NOAUTODMA, 178 .autodma = NOAUTODMA,
187 .bootable = NEVER_BOARD, 179 .bootable = NEVER_BOARD,
188 .extra = 16 180 .extra = 16,
181 .pio_mask = ATA_PIO5,
189}; 182};
190 183
191static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 184static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index e9b07a97c340..2cd74c345a6c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -652,7 +652,7 @@ static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed)
652 652
653static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio) 653static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio)
654{ 654{
655 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 655 pio = ide_get_best_pio_mode(drive, pio, 4);
656 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio); 656 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio);
657} 657}
658 658
@@ -994,14 +994,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
994 */ 994 */
995 *info = *(struct hpt_info *)pci_get_drvdata(dev); 995 *info = *(struct hpt_info *)pci_get_drvdata(dev);
996 996
997 /*
998 * FIXME: Not portable. Also, why do we enable the ROM in the first place?
999 * We don't seem to be using it.
1000 */
1001 if (dev->resource[PCI_ROM_RESOURCE].start)
1002 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
1003 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
1004
1005 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); 997 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
1006 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); 998 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1007 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); 999 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
@@ -1491,7 +1483,7 @@ static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d)
1491 * to both functions -- really stupid design decision... :-( 1483 * to both functions -- really stupid design decision... :-(
1492 * Bit 4 is for the primary channel, bit 5 for the secondary. 1484 * Bit 4 is for the primary channel, bit 5 for the secondary.
1493 */ 1485 */
1494 d->channels = 1; 1486 d->host_flags |= IDE_HFLAG_SINGLE;
1495 d->enablebits[0].mask = d->enablebits[0].val = 0x10; 1487 d->enablebits[0].mask = d->enablebits[0].val = 0x10;
1496 1488
1497 d->udma_mask = HPT366_ALLOW_ATA66_3 ? 1489 d->udma_mask = HPT366_ALLOW_ATA66_3 ?
@@ -1554,71 +1546,71 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1554 .init_chipset = init_chipset_hpt366, 1546 .init_chipset = init_chipset_hpt366,
1555 .init_hwif = init_hwif_hpt366, 1547 .init_hwif = init_hwif_hpt366,
1556 .init_dma = init_dma_hpt366, 1548 .init_dma = init_dma_hpt366,
1557 .channels = 2,
1558 .autodma = AUTODMA, 1549 .autodma = AUTODMA,
1559 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, 1550 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1560 .bootable = OFF_BOARD, 1551 .bootable = OFF_BOARD,
1561 .extra = 240 1552 .extra = 240,
1553 .pio_mask = ATA_PIO4,
1562 },{ /* 1 */ 1554 },{ /* 1 */
1563 .name = "HPT372A", 1555 .name = "HPT372A",
1564 .init_setup = init_setup_hpt372a, 1556 .init_setup = init_setup_hpt372a,
1565 .init_chipset = init_chipset_hpt366, 1557 .init_chipset = init_chipset_hpt366,
1566 .init_hwif = init_hwif_hpt366, 1558 .init_hwif = init_hwif_hpt366,
1567 .init_dma = init_dma_hpt366, 1559 .init_dma = init_dma_hpt366,
1568 .channels = 2,
1569 .autodma = AUTODMA, 1560 .autodma = AUTODMA,
1570 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, 1561 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1571 .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f, 1562 .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f,
1572 .bootable = OFF_BOARD, 1563 .bootable = OFF_BOARD,
1573 .extra = 240 1564 .extra = 240,
1565 .pio_mask = ATA_PIO4,
1574 },{ /* 2 */ 1566 },{ /* 2 */
1575 .name = "HPT302", 1567 .name = "HPT302",
1576 .init_setup = init_setup_hpt302, 1568 .init_setup = init_setup_hpt302,
1577 .init_chipset = init_chipset_hpt366, 1569 .init_chipset = init_chipset_hpt366,
1578 .init_hwif = init_hwif_hpt366, 1570 .init_hwif = init_hwif_hpt366,
1579 .init_dma = init_dma_hpt366, 1571 .init_dma = init_dma_hpt366,
1580 .channels = 2,
1581 .autodma = AUTODMA, 1572 .autodma = AUTODMA,
1582 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, 1573 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1583 .udma_mask = HPT302_ALLOW_ATA133_6 ? 0x7f : 0x3f, 1574 .udma_mask = HPT302_ALLOW_ATA133_6 ? 0x7f : 0x3f,
1584 .bootable = OFF_BOARD, 1575 .bootable = OFF_BOARD,
1585 .extra = 240 1576 .extra = 240,
1577 .pio_mask = ATA_PIO4,
1586 },{ /* 3 */ 1578 },{ /* 3 */
1587 .name = "HPT371", 1579 .name = "HPT371",
1588 .init_setup = init_setup_hpt371, 1580 .init_setup = init_setup_hpt371,
1589 .init_chipset = init_chipset_hpt366, 1581 .init_chipset = init_chipset_hpt366,
1590 .init_hwif = init_hwif_hpt366, 1582 .init_hwif = init_hwif_hpt366,
1591 .init_dma = init_dma_hpt366, 1583 .init_dma = init_dma_hpt366,
1592 .channels = 2,
1593 .autodma = AUTODMA, 1584 .autodma = AUTODMA,
1594 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, 1585 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1595 .udma_mask = HPT371_ALLOW_ATA133_6 ? 0x7f : 0x3f, 1586 .udma_mask = HPT371_ALLOW_ATA133_6 ? 0x7f : 0x3f,
1596 .bootable = OFF_BOARD, 1587 .bootable = OFF_BOARD,
1597 .extra = 240 1588 .extra = 240,
1589 .pio_mask = ATA_PIO4,
1598 },{ /* 4 */ 1590 },{ /* 4 */
1599 .name = "HPT374", 1591 .name = "HPT374",
1600 .init_setup = init_setup_hpt374, 1592 .init_setup = init_setup_hpt374,
1601 .init_chipset = init_chipset_hpt366, 1593 .init_chipset = init_chipset_hpt366,
1602 .init_hwif = init_hwif_hpt366, 1594 .init_hwif = init_hwif_hpt366,
1603 .init_dma = init_dma_hpt366, 1595 .init_dma = init_dma_hpt366,
1604 .channels = 2, /* 4 */
1605 .autodma = AUTODMA, 1596 .autodma = AUTODMA,
1606 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, 1597 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1607 .udma_mask = 0x3f, 1598 .udma_mask = 0x3f,
1608 .bootable = OFF_BOARD, 1599 .bootable = OFF_BOARD,
1609 .extra = 240 1600 .extra = 240,
1601 .pio_mask = ATA_PIO4,
1610 },{ /* 5 */ 1602 },{ /* 5 */
1611 .name = "HPT372N", 1603 .name = "HPT372N",
1612 .init_setup = init_setup_hpt372n, 1604 .init_setup = init_setup_hpt372n,
1613 .init_chipset = init_chipset_hpt366, 1605 .init_chipset = init_chipset_hpt366,
1614 .init_hwif = init_hwif_hpt366, 1606 .init_hwif = init_hwif_hpt366,
1615 .init_dma = init_dma_hpt366, 1607 .init_dma = init_dma_hpt366,
1616 .channels = 2, /* 4 */
1617 .autodma = AUTODMA, 1608 .autodma = AUTODMA,
1618 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, 1609 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1619 .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f, 1610 .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f,
1620 .bootable = OFF_BOARD, 1611 .bootable = OFF_BOARD,
1621 .extra = 240 1612 .extra = 240,
1613 .pio_mask = ATA_PIO4,
1622 } 1614 }
1623}; 1615};
1624 1616
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index ff48c23e571e..95dbed7e6022 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -82,7 +82,7 @@ static void it8213_tuneproc (ide_drive_t *drive, u8 pio)
82 { 2, 1 }, 82 { 2, 1 },
83 { 2, 3 }, }; 83 { 2, 3 }, };
84 84
85 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 85 pio = ide_get_best_pio_mode(drive, pio, 4);
86 86
87 spin_lock_irqsave(&tune_lock, flags); 87 spin_lock_irqsave(&tune_lock, flags);
88 pci_read_config_word(dev, master_port, &master_data); 88 pci_read_config_word(dev, master_port, &master_data);
@@ -214,7 +214,7 @@ static int it8213_config_drive_for_dma (ide_drive_t *drive)
214 if (ide_tune_dma(drive)) 214 if (ide_tune_dma(drive))
215 return 0; 215 return 0;
216 216
217 pio = ide_get_best_pio_mode(drive, 255, 4, NULL); 217 pio = ide_get_best_pio_mode(drive, 255, 4);
218 it8213_tune_chipset(drive, XFER_PIO_0 + pio); 218 it8213_tune_chipset(drive, XFER_PIO_0 + pio);
219 219
220 return -1; 220 return -1;
@@ -272,10 +272,11 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
272 { \ 272 { \
273 .name = name_str, \ 273 .name = name_str, \
274 .init_hwif = init_hwif_it8213, \ 274 .init_hwif = init_hwif_it8213, \
275 .channels = 1, \
276 .autodma = AUTODMA, \ 275 .autodma = AUTODMA, \
277 .enablebits = {{0x41,0x80,0x80}}, \ 276 .enablebits = {{0x41,0x80,0x80}}, \
278 .bootable = ON_BOARD, \ 277 .bootable = ON_BOARD, \
278 .host_flags = IDE_HFLAG_SINGLE, \
279 .pio_mask = ATA_PIO4, \
279 } 280 }
280 281
281static ide_pci_device_t it8213_chipsets[] __devinitdata = { 282static ide_pci_device_t it8213_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 8197b653ba1e..9286c99e2ff0 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -255,7 +255,7 @@ static int it821x_tunepio(ide_drive_t *drive, u8 set_pio)
255 * on the cable. 255 * on the cable.
256 */ 256 */
257 if (pair) { 257 if (pair) {
258 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4, NULL); 258 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4);
259 /* trim PIO to the slowest of the master/slave */ 259 /* trim PIO to the slowest of the master/slave */
260 if (pair_pio < set_pio) 260 if (pair_pio < set_pio)
261 set_pio = pair_pio; 261 set_pio = pair_pio;
@@ -276,7 +276,7 @@ static int it821x_tunepio(ide_drive_t *drive, u8 set_pio)
276 276
277static void it821x_tuneproc(ide_drive_t *drive, u8 pio) 277static void it821x_tuneproc(ide_drive_t *drive, u8 pio)
278{ 278{
279 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 279 pio = ide_get_best_pio_mode(drive, pio, 4);
280 (void)it821x_tunepio(drive, pio); 280 (void)it821x_tunepio(drive, pio);
281} 281}
282 282
@@ -718,10 +718,10 @@ static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const cha
718 .name = name_str, \ 718 .name = name_str, \
719 .init_chipset = init_chipset_it821x, \ 719 .init_chipset = init_chipset_it821x, \
720 .init_hwif = init_hwif_it821x, \ 720 .init_hwif = init_hwif_it821x, \
721 .channels = 2, \
722 .autodma = AUTODMA, \ 721 .autodma = AUTODMA, \
723 .bootable = ON_BOARD, \ 722 .bootable = ON_BOARD, \
724 .fixup = it821x_fixups \ 723 .fixup = it821x_fixups, \
724 .pio_mask = ATA_PIO4, \
725 } 725 }
726 726
727static ide_pci_device_t it821x_chipsets[] __devinitdata = { 727static ide_pci_device_t it821x_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index a6008f63e71e..d7ce9dd8de16 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -97,7 +97,7 @@ static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted)
97 97
98static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed) 98static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed)
99{ 99{
100 u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL); 100 u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5);
101 if (set_speed) 101 if (set_speed)
102 (void) ide_config_drive_speed(drive, speed); 102 (void) ide_config_drive_speed(drive, speed);
103} 103}
@@ -177,10 +177,10 @@ fallback:
177 { \ 177 { \
178 .name = name_str, \ 178 .name = name_str, \
179 .init_hwif = init_hwif_jmicron, \ 179 .init_hwif = init_hwif_jmicron, \
180 .channels = 2, \
181 .autodma = AUTODMA, \ 180 .autodma = AUTODMA, \
182 .bootable = ON_BOARD, \ 181 .bootable = ON_BOARD, \
183 .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \ 182 .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \
183 .pio_mask = ATA_PIO5, \
184 } 184 }
185 185
186static ide_pci_device_t jmicron_chipsets[] __devinitdata = { 186static ide_pci_device_t jmicron_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index b310c4f51077..09941f37d635 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -281,7 +281,6 @@ static ide_pci_device_t ns87415_chipset __devinitdata = {
281 .init_iops = init_iops_ns87415, 281 .init_iops = init_iops_ns87415,
282#endif 282#endif
283 .init_hwif = init_hwif_ns87415, 283 .init_hwif = init_hwif_ns87415,
284 .channels = 2,
285 .autodma = AUTODMA, 284 .autodma = AUTODMA,
286 .bootable = ON_BOARD, 285 .bootable = ON_BOARD,
287}; 286};
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index aede7eee9246..3a2bb2723515 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -147,12 +147,12 @@ 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, NULL); 150 drive->drive_data = ide_get_best_pio_mode(drive, pio, OPTI621_MAX_PIO);
151 for (d = 0; d < 2; ++d) { 151 for (d = 0; d < 2; ++d) {
152 drive = &hwif->drives[d]; 152 drive = &hwif->drives[d];
153 if (drive->present) { 153 if (drive->present) {
154 if (drive->drive_data == PIO_DONT_KNOW) 154 if (drive->drive_data == PIO_DONT_KNOW)
155 drive->drive_data = ide_get_best_pio_mode(drive, 255, OPTI621_MAX_PIO, NULL); 155 drive->drive_data = ide_get_best_pio_mode(drive, 255, OPTI621_MAX_PIO);
156#ifdef OPTI621_DEBUG 156#ifdef OPTI621_DEBUG
157 printk("%s: Selected PIO mode %d\n", 157 printk("%s: Selected PIO mode %d\n",
158 drive->name, drive->drive_data); 158 drive->name, drive->drive_data);
@@ -350,17 +350,17 @@ static ide_pci_device_t opti621_chipsets[] __devinitdata = {
350 { /* 0 */ 350 { /* 0 */
351 .name = "OPTI621", 351 .name = "OPTI621",
352 .init_hwif = init_hwif_opti621, 352 .init_hwif = init_hwif_opti621,
353 .channels = 2,
354 .autodma = AUTODMA, 353 .autodma = AUTODMA,
355 .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, 354 .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}},
356 .bootable = ON_BOARD, 355 .bootable = ON_BOARD,
356 .pio_mask = ATA_PIO3,
357 },{ /* 1 */ 357 },{ /* 1 */
358 .name = "OPTI621X", 358 .name = "OPTI621X",
359 .init_hwif = init_hwif_opti621, 359 .init_hwif = init_hwif_opti621,
360 .channels = 2,
361 .autodma = AUTODMA, 360 .autodma = AUTODMA,
362 .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, 361 .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}},
363 .bootable = ON_BOARD, 362 .bootable = ON_BOARD,
363 .pio_mask = ATA_PIO3,
364 } 364 }
365}; 365};
366 366
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index ee5020df005d..8a66a2871b3a 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -219,7 +219,7 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed)
219 219
220static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio) 220static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio)
221{ 221{
222 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 222 pio = ide_get_best_pio_mode(drive, pio, 4);
223 (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio); 223 (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio);
224} 224}
225 225
@@ -378,13 +378,6 @@ static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const cha
378 int f, r; 378 int f, r;
379 u8 pll_ctl0, pll_ctl1; 379 u8 pll_ctl0, pll_ctl1;
380 380
381 if (dev->resource[PCI_ROM_RESOURCE].start) {
382 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
383 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
384 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name,
385 (unsigned long)dev->resource[PCI_ROM_RESOURCE].start);
386 }
387
388#ifdef CONFIG_PPC_PMAC 381#ifdef CONFIG_PPC_PMAC
389 apple_kiwi_init(dev); 382 apple_kiwi_init(dev);
390#endif 383#endif
@@ -573,63 +566,63 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
573 .init_setup = init_setup_pdcnew, 566 .init_setup = init_setup_pdcnew,
574 .init_chipset = init_chipset_pdcnew, 567 .init_chipset = init_chipset_pdcnew,
575 .init_hwif = init_hwif_pdc202new, 568 .init_hwif = init_hwif_pdc202new,
576 .channels = 2,
577 .autodma = AUTODMA, 569 .autodma = AUTODMA,
578 .bootable = OFF_BOARD, 570 .bootable = OFF_BOARD,
571 .pio_mask = ATA_PIO4,
579 .udma_mask = 0x3f, /* udma0-5 */ 572 .udma_mask = 0x3f, /* udma0-5 */
580 },{ /* 1 */ 573 },{ /* 1 */
581 .name = "PDC20269", 574 .name = "PDC20269",
582 .init_setup = init_setup_pdcnew, 575 .init_setup = init_setup_pdcnew,
583 .init_chipset = init_chipset_pdcnew, 576 .init_chipset = init_chipset_pdcnew,
584 .init_hwif = init_hwif_pdc202new, 577 .init_hwif = init_hwif_pdc202new,
585 .channels = 2,
586 .autodma = AUTODMA, 578 .autodma = AUTODMA,
587 .bootable = OFF_BOARD, 579 .bootable = OFF_BOARD,
580 .pio_mask = ATA_PIO4,
588 .udma_mask = 0x7f, /* udma0-6*/ 581 .udma_mask = 0x7f, /* udma0-6*/
589 },{ /* 2 */ 582 },{ /* 2 */
590 .name = "PDC20270", 583 .name = "PDC20270",
591 .init_setup = init_setup_pdc20270, 584 .init_setup = init_setup_pdc20270,
592 .init_chipset = init_chipset_pdcnew, 585 .init_chipset = init_chipset_pdcnew,
593 .init_hwif = init_hwif_pdc202new, 586 .init_hwif = init_hwif_pdc202new,
594 .channels = 2,
595 .autodma = AUTODMA, 587 .autodma = AUTODMA,
596 .bootable = OFF_BOARD, 588 .bootable = OFF_BOARD,
589 .pio_mask = ATA_PIO4,
597 .udma_mask = 0x3f, /* udma0-5 */ 590 .udma_mask = 0x3f, /* udma0-5 */
598 },{ /* 3 */ 591 },{ /* 3 */
599 .name = "PDC20271", 592 .name = "PDC20271",
600 .init_setup = init_setup_pdcnew, 593 .init_setup = init_setup_pdcnew,
601 .init_chipset = init_chipset_pdcnew, 594 .init_chipset = init_chipset_pdcnew,
602 .init_hwif = init_hwif_pdc202new, 595 .init_hwif = init_hwif_pdc202new,
603 .channels = 2,
604 .autodma = AUTODMA, 596 .autodma = AUTODMA,
605 .bootable = OFF_BOARD, 597 .bootable = OFF_BOARD,
598 .pio_mask = ATA_PIO4,
606 .udma_mask = 0x7f, /* udma0-6*/ 599 .udma_mask = 0x7f, /* udma0-6*/
607 },{ /* 4 */ 600 },{ /* 4 */
608 .name = "PDC20275", 601 .name = "PDC20275",
609 .init_setup = init_setup_pdcnew, 602 .init_setup = init_setup_pdcnew,
610 .init_chipset = init_chipset_pdcnew, 603 .init_chipset = init_chipset_pdcnew,
611 .init_hwif = init_hwif_pdc202new, 604 .init_hwif = init_hwif_pdc202new,
612 .channels = 2,
613 .autodma = AUTODMA, 605 .autodma = AUTODMA,
614 .bootable = OFF_BOARD, 606 .bootable = OFF_BOARD,
607 .pio_mask = ATA_PIO4,
615 .udma_mask = 0x7f, /* udma0-6*/ 608 .udma_mask = 0x7f, /* udma0-6*/
616 },{ /* 5 */ 609 },{ /* 5 */
617 .name = "PDC20276", 610 .name = "PDC20276",
618 .init_setup = init_setup_pdc20276, 611 .init_setup = init_setup_pdc20276,
619 .init_chipset = init_chipset_pdcnew, 612 .init_chipset = init_chipset_pdcnew,
620 .init_hwif = init_hwif_pdc202new, 613 .init_hwif = init_hwif_pdc202new,
621 .channels = 2,
622 .autodma = AUTODMA, 614 .autodma = AUTODMA,
623 .bootable = OFF_BOARD, 615 .bootable = OFF_BOARD,
616 .pio_mask = ATA_PIO4,
624 .udma_mask = 0x7f, /* udma0-6*/ 617 .udma_mask = 0x7f, /* udma0-6*/
625 },{ /* 6 */ 618 },{ /* 6 */
626 .name = "PDC20277", 619 .name = "PDC20277",
627 .init_setup = init_setup_pdcnew, 620 .init_setup = init_setup_pdcnew,
628 .init_chipset = init_chipset_pdcnew, 621 .init_chipset = init_chipset_pdcnew,
629 .init_hwif = init_hwif_pdc202new, 622 .init_hwif = init_hwif_pdc202new,
630 .channels = 2,
631 .autodma = AUTODMA, 623 .autodma = AUTODMA,
632 .bootable = OFF_BOARD, 624 .bootable = OFF_BOARD,
625 .pio_mask = ATA_PIO4,
633 .udma_mask = 0x7f, /* udma0-6*/ 626 .udma_mask = 0x7f, /* udma0-6*/
634 } 627 }
635}; 628};
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 41ac4a94959f..fbcb0bb9c956 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -145,7 +145,7 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
145 145
146static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio) 146static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio)
147{ 147{
148 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 148 pio = ide_get_best_pio_mode(drive, pio, 4);
149 pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio); 149 pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio);
150} 150}
151 151
@@ -316,14 +316,6 @@ static void pdc202xx_reset (ide_drive_t *drive)
316static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, 316static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
317 const char *name) 317 const char *name)
318{ 318{
319 /* This doesn't appear needed */
320 if (dev->resource[PCI_ROM_RESOURCE].start) {
321 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
322 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
323 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name,
324 (unsigned long)dev->resource[PCI_ROM_RESOURCE].start);
325 }
326
327 return dev->irq; 319 return dev->irq;
328} 320}
329 321
@@ -449,10 +441,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
449 .init_chipset = init_chipset_pdc202xx, 441 .init_chipset = init_chipset_pdc202xx,
450 .init_hwif = init_hwif_pdc202xx, 442 .init_hwif = init_hwif_pdc202xx,
451 .init_dma = init_dma_pdc202xx, 443 .init_dma = init_dma_pdc202xx,
452 .channels = 2,
453 .autodma = AUTODMA, 444 .autodma = AUTODMA,
454 .bootable = OFF_BOARD, 445 .bootable = OFF_BOARD,
455 .extra = 16, 446 .extra = 16,
447 .pio_mask = ATA_PIO4,
456 .udma_mask = 0x07, /* udma0-2 */ 448 .udma_mask = 0x07, /* udma0-2 */
457 },{ /* 1 */ 449 },{ /* 1 */
458 .name = "PDC20262", 450 .name = "PDC20262",
@@ -460,10 +452,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
460 .init_chipset = init_chipset_pdc202xx, 452 .init_chipset = init_chipset_pdc202xx,
461 .init_hwif = init_hwif_pdc202xx, 453 .init_hwif = init_hwif_pdc202xx,
462 .init_dma = init_dma_pdc202xx, 454 .init_dma = init_dma_pdc202xx,
463 .channels = 2,
464 .autodma = AUTODMA, 455 .autodma = AUTODMA,
465 .bootable = OFF_BOARD, 456 .bootable = OFF_BOARD,
466 .extra = 48, 457 .extra = 48,
458 .pio_mask = ATA_PIO4,
467 .udma_mask = 0x1f, /* udma0-4 */ 459 .udma_mask = 0x1f, /* udma0-4 */
468 },{ /* 2 */ 460 },{ /* 2 */
469 .name = "PDC20263", 461 .name = "PDC20263",
@@ -471,10 +463,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
471 .init_chipset = init_chipset_pdc202xx, 463 .init_chipset = init_chipset_pdc202xx,
472 .init_hwif = init_hwif_pdc202xx, 464 .init_hwif = init_hwif_pdc202xx,
473 .init_dma = init_dma_pdc202xx, 465 .init_dma = init_dma_pdc202xx,
474 .channels = 2,
475 .autodma = AUTODMA, 466 .autodma = AUTODMA,
476 .bootable = OFF_BOARD, 467 .bootable = OFF_BOARD,
477 .extra = 48, 468 .extra = 48,
469 .pio_mask = ATA_PIO4,
478 .udma_mask = 0x1f, /* udma0-4 */ 470 .udma_mask = 0x1f, /* udma0-4 */
479 },{ /* 3 */ 471 },{ /* 3 */
480 .name = "PDC20265", 472 .name = "PDC20265",
@@ -482,10 +474,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
482 .init_chipset = init_chipset_pdc202xx, 474 .init_chipset = init_chipset_pdc202xx,
483 .init_hwif = init_hwif_pdc202xx, 475 .init_hwif = init_hwif_pdc202xx,
484 .init_dma = init_dma_pdc202xx, 476 .init_dma = init_dma_pdc202xx,
485 .channels = 2,
486 .autodma = AUTODMA, 477 .autodma = AUTODMA,
487 .bootable = OFF_BOARD, 478 .bootable = OFF_BOARD,
488 .extra = 48, 479 .extra = 48,
480 .pio_mask = ATA_PIO4,
489 .udma_mask = 0x3f, /* udma0-5 */ 481 .udma_mask = 0x3f, /* udma0-5 */
490 },{ /* 4 */ 482 },{ /* 4 */
491 .name = "PDC20267", 483 .name = "PDC20267",
@@ -493,10 +485,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
493 .init_chipset = init_chipset_pdc202xx, 485 .init_chipset = init_chipset_pdc202xx,
494 .init_hwif = init_hwif_pdc202xx, 486 .init_hwif = init_hwif_pdc202xx,
495 .init_dma = init_dma_pdc202xx, 487 .init_dma = init_dma_pdc202xx,
496 .channels = 2,
497 .autodma = AUTODMA, 488 .autodma = AUTODMA,
498 .bootable = OFF_BOARD, 489 .bootable = OFF_BOARD,
499 .extra = 48, 490 .extra = 48,
491 .pio_mask = ATA_PIO4,
500 .udma_mask = 0x3f, /* udma0-5 */ 492 .udma_mask = 0x3f, /* udma0-5 */
501 } 493 }
502}; 494};
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 1372c35be035..4f69cd067e5e 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -219,7 +219,7 @@ static void piix_tune_pio (ide_drive_t *drive, u8 pio)
219 */ 219 */
220static void piix_tune_drive (ide_drive_t *drive, u8 pio) 220static void piix_tune_drive (ide_drive_t *drive, u8 pio)
221{ 221{
222 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 222 pio = ide_get_best_pio_mode(drive, pio, 4);
223 piix_tune_pio(drive, pio); 223 piix_tune_pio(drive, pio);
224 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 224 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
225} 225}
@@ -495,10 +495,10 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
495 .name = name_str, \ 495 .name = name_str, \
496 .init_chipset = init_chipset_piix, \ 496 .init_chipset = init_chipset_piix, \
497 .init_hwif = init_hwif_piix, \ 497 .init_hwif = init_hwif_piix, \
498 .channels = 2, \
499 .autodma = AUTODMA, \ 498 .autodma = AUTODMA, \
500 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 499 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
501 .bootable = ON_BOARD, \ 500 .bootable = ON_BOARD, \
501 .pio_mask = ATA_PIO4, \
502 .udma_mask = udma, \ 502 .udma_mask = udma, \
503 } 503 }
504 504
@@ -514,11 +514,11 @@ static ide_pci_device_t piix_pci_info[] __devinitdata = {
514 */ 514 */
515 .name = "MPIIX", 515 .name = "MPIIX",
516 .init_hwif = init_hwif_piix, 516 .init_hwif = init_hwif_piix,
517 .channels = 2,
518 .autodma = NODMA, 517 .autodma = NODMA,
519 .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}}, 518 .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}},
520 .bootable = ON_BOARD, 519 .bootable = ON_BOARD,
521 .flags = IDEPCI_FLAG_ISA_PORTS 520 .host_flags = IDE_HFLAG_ISA_PORTS,
521 .pio_mask = ATA_PIO4,
522 }, 522 },
523 523
524 /* 3 */ DECLARE_PIIX_DEV("PIIX3", 0x00), /* no udma */ 524 /* 3 */ DECLARE_PIIX_DEV("PIIX3", 0x00), /* no udma */
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index f8c954690142..10e1ae7a4a02 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -52,7 +52,6 @@ static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif)
52static ide_pci_device_t rz1000_chipset __devinitdata = { 52static ide_pci_device_t rz1000_chipset __devinitdata = {
53 .name = "RZ100x", 53 .name = "RZ100x",
54 .init_hwif = init_hwif_rz1000, 54 .init_hwif = init_hwif_rz1000,
55 .channels = 2,
56 .autodma = NODMA, 55 .autodma = NODMA,
57 .bootable = ON_BOARD, 56 .bootable = ON_BOARD,
58}; 57};
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 523363c93794..9bdc9694d50d 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/pci/sc1200.c Version 0.94 Mar 10 2007 2 * linux/drivers/ide/pci/sc1200.c Version 0.95 Jun 16 2007
3 * 3 *
4 * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> 4 * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com>
5 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 5 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
@@ -304,7 +304,7 @@ static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "au
304 return; 304 return;
305 } 305 }
306 306
307 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 307 pio = ide_get_best_pio_mode(drive, pio, 4);
308 printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio); 308 printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio);
309 309
310 if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) 310 if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0)
@@ -390,7 +390,7 @@ static int sc1200_resume (struct pci_dev *dev)
390 // loop over all interfaces that are part of this pci device: 390 // loop over all interfaces that are part of this pci device:
391 // 391 //
392 while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { 392 while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) {
393 unsigned int basereg, r, d, format; 393 unsigned int basereg, r;
394 sc1200_saved_state_t *ss = (sc1200_saved_state_t *)hwif->config_data; 394 sc1200_saved_state_t *ss = (sc1200_saved_state_t *)hwif->config_data;
395 395
396 // 396 //
@@ -402,41 +402,6 @@ static int sc1200_resume (struct pci_dev *dev)
402 pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]); 402 pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]);
403 } 403 }
404 } 404 }
405 //
406 // Re-program drive PIO modes
407 //
408 pci_read_config_dword(hwif->pci_dev, basereg+4, &format);
409 format = (format >> 31) & 1;
410 if (format)
411 format += sc1200_get_pci_clock();
412 for (d = 0; d < 2; ++d) {
413 ide_drive_t *drive = &(hwif->drives[d]);
414 if (drive->present) {
415 unsigned int pio, timings;
416 pci_read_config_dword(hwif->pci_dev, basereg+(drive->select.b.unit << 3), &timings);
417 for (pio = 0; pio <= 4; ++pio) {
418 if (sc1200_pio_timings[format][pio] == timings)
419 break;
420 }
421 if (pio > 4)
422 pio = 255; /* autotune */
423 (void)sc1200_tuneproc(drive, pio);
424 }
425 }
426 //
427 // Re-program drive DMA modes
428 //
429 for (d = 0; d < MAX_DRIVES; ++d) {
430 ide_drive_t *drive = &(hwif->drives[d]);
431 if (drive->present && !__ide_dma_bad_drive(drive)) {
432 int enable_dma = drive->using_dma;
433 hwif->dma_off_quietly(drive);
434 if (sc1200_config_dma(drive))
435 enable_dma = 0;
436 if (enable_dma)
437 hwif->dma_host_on(drive);
438 }
439 }
440 } 405 }
441 return 0; 406 return 0;
442} 407}
@@ -471,9 +436,9 @@ static void __devinit init_hwif_sc1200 (ide_hwif_t *hwif)
471static ide_pci_device_t sc1200_chipset __devinitdata = { 436static ide_pci_device_t sc1200_chipset __devinitdata = {
472 .name = "SC1200", 437 .name = "SC1200",
473 .init_hwif = init_hwif_sc1200, 438 .init_hwif = init_hwif_sc1200,
474 .channels = 2,
475 .autodma = AUTODMA, 439 .autodma = AUTODMA,
476 .bootable = ON_BOARD, 440 .bootable = ON_BOARD,
441 .pio_mask = ATA_PIO4,
477}; 442};
478 443
479static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) 444static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index 7b87488e3daa..f668d235e6be 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -165,9 +165,9 @@ scc_ide_outbsync(ide_drive_t * drive, u8 addr, unsigned long port)
165 ide_hwif_t *hwif = HWIF(drive); 165 ide_hwif_t *hwif = HWIF(drive);
166 166
167 out_be32((void*)port, addr); 167 out_be32((void*)port, addr);
168 __asm__ __volatile__("eieio":::"memory"); 168 eieio();
169 in_be32((void*)(hwif->dma_base + 0x01c)); 169 in_be32((void*)(hwif->dma_base + 0x01c));
170 __asm__ __volatile__("eieio":::"memory"); 170 eieio();
171} 171}
172 172
173static void 173static void
@@ -210,7 +210,7 @@ static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted)
210 unsigned char speed = XFER_PIO_0; 210 unsigned char speed = XFER_PIO_0;
211 int offset; 211 int offset;
212 212
213 mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4, NULL); 213 mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4);
214 switch (mode_wanted) { 214 switch (mode_wanted) {
215 case 4: 215 case 4:
216 speed = XFER_PIO_4; 216 speed = XFER_PIO_4;
@@ -401,6 +401,33 @@ static int scc_ide_dma_end(ide_drive_t * drive)
401 ide_hwif_t *hwif = HWIF(drive); 401 ide_hwif_t *hwif = HWIF(drive);
402 unsigned long intsts_port = hwif->dma_base + 0x014; 402 unsigned long intsts_port = hwif->dma_base + 0x014;
403 u32 reg; 403 u32 reg;
404 int dma_stat, data_loss = 0;
405 static int retry = 0;
406
407 /* errata A308 workaround: Step5 (check data loss) */
408 /* We don't check non ide_disk because it is limited to UDMA4 */
409 if (!(in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT) &&
410 drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) {
411 reg = in_be32((void __iomem *)intsts_port);
412 if (!(reg & INTSTS_ACTEINT)) {
413 printk(KERN_WARNING "%s: operation failed (transfer data loss)\n",
414 drive->name);
415 data_loss = 1;
416 if (retry++) {
417 struct request *rq = HWGROUP(drive)->rq;
418 int unit;
419 /* ERROR_RESET and drive->crc_count are needed
420 * to reduce DMA transfer mode in retry process.
421 */
422 if (rq)
423 rq->errors |= ERROR_RESET;
424 for (unit = 0; unit < MAX_DRIVES; unit++) {
425 ide_drive_t *drive = &hwif->drives[unit];
426 drive->crc_count++;
427 }
428 }
429 }
430 }
404 431
405 while (1) { 432 while (1) {
406 reg = in_be32((void __iomem *)intsts_port); 433 reg = in_be32((void __iomem *)intsts_port);
@@ -469,27 +496,25 @@ static int scc_ide_dma_end(ide_drive_t * drive)
469 break; 496 break;
470 } 497 }
471 498
472 return __ide_dma_end(drive); 499 dma_stat = __ide_dma_end(drive);
500 if (data_loss)
501 dma_stat |= 2; /* emulate DMA error (to retry command) */
502 return dma_stat;
473} 503}
474 504
475/* returns 1 if dma irq issued, 0 otherwise */ 505/* returns 1 if dma irq issued, 0 otherwise */
476static int scc_dma_test_irq(ide_drive_t *drive) 506static int scc_dma_test_irq(ide_drive_t *drive)
477{ 507{
478 ide_hwif_t *hwif = HWIF(drive); 508 ide_hwif_t *hwif = HWIF(drive);
479 u8 dma_stat = hwif->INB(hwif->dma_status); 509 u32 int_stat = in_be32((void __iomem *)hwif->dma_base + 0x014);
480 510
481 /* return 1 if INTR asserted */ 511 /* SCC errata A252,A308 workaround: Step4 */
482 if ((dma_stat & 4) == 4) 512 if ((in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT) &&
513 (int_stat & INTSTS_INTRQ))
483 return 1; 514 return 1;
484 515
485 /* Workaround for PTERADD: emulate DMA_INTR when 516 /* SCC errata A308 workaround: Step5 (polling IOIRQS) */
486 * - IDE_STATUS[ERR] = 1 517 if (int_stat & INTSTS_IOIRQS)
487 * - INT_STATUS[INTRQ] = 1
488 * - DMA_STATUS[IORACTA] = 1
489 */
490 if (in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT &&
491 in_be32((void __iomem *)(hwif->dma_base + 0x014)) & INTSTS_INTRQ &&
492 dma_stat & 1)
493 return 1; 518 return 1;
494 519
495 if (!drive->waiting_for_dma) 520 if (!drive->waiting_for_dma)
@@ -498,6 +523,21 @@ static int scc_dma_test_irq(ide_drive_t *drive)
498 return 0; 523 return 0;
499} 524}
500 525
526static u8 scc_udma_filter(ide_drive_t *drive)
527{
528 ide_hwif_t *hwif = drive->hwif;
529 u8 mask = hwif->ultra_mask;
530
531 /* errata A308 workaround: limit non ide_disk drive to UDMA4 */
532 if ((drive->media != ide_disk) && (mask & 0xE0)) {
533 printk(KERN_INFO "%s: limit %s to UDMA4\n",
534 SCC_PATA_NAME, drive->name);
535 mask = 0x1F;
536 }
537
538 return mask;
539}
540
501/** 541/**
502 * setup_mmio_scc - map CTRL/BMID region 542 * setup_mmio_scc - map CTRL/BMID region
503 * @dev: PCI device we are configuring 543 * @dev: PCI device we are configuring
@@ -702,6 +742,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
702 hwif->tuneproc = scc_tuneproc; 742 hwif->tuneproc = scc_tuneproc;
703 hwif->ide_dma_check = scc_config_drive_for_dma; 743 hwif->ide_dma_check = scc_config_drive_for_dma;
704 hwif->ide_dma_test_irq = scc_dma_test_irq; 744 hwif->ide_dma_test_irq = scc_dma_test_irq;
745 hwif->udma_filter = scc_udma_filter;
705 746
706 hwif->drives[0].autotune = IDE_TUNE_AUTO; 747 hwif->drives[0].autotune = IDE_TUNE_AUTO;
707 hwif->drives[1].autotune = IDE_TUNE_AUTO; 748 hwif->drives[1].autotune = IDE_TUNE_AUTO;
@@ -731,9 +772,10 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
731 .init_setup = init_setup_scc, \ 772 .init_setup = init_setup_scc, \
732 .init_iops = init_iops_scc, \ 773 .init_iops = init_iops_scc, \
733 .init_hwif = init_hwif_scc, \ 774 .init_hwif = init_hwif_scc, \
734 .channels = 1, \
735 .autodma = AUTODMA, \ 775 .autodma = AUTODMA, \
736 .bootable = ON_BOARD, \ 776 .bootable = ON_BOARD, \
777 .host_flags = IDE_HFLAG_SINGLE, \
778 .pio_mask = ATA_PIO4, \
737 } 779 }
738 780
739static ide_pci_device_t scc_chipsets[] __devinitdata = { 781static ide_pci_device_t scc_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index ed04e0c8dd4c..9fead2e7d4c8 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/pci/serverworks.c Version 0.20 Jun 3 2007 2 * linux/drivers/ide/pci/serverworks.c Version 0.22 Jun 27 2007
3 * 3 *
4 * Copyright (C) 1998-2000 Michel Aubry 4 * Copyright (C) 1998-2000 Michel Aubry
5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz 5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
@@ -123,23 +123,45 @@ static u8 svwks_csb_check (struct pci_dev *dev)
123 } 123 }
124 return 0; 124 return 0;
125} 125}
126
127static void svwks_tune_pio(ide_drive_t *drive, const u8 pio)
128{
129 static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
130 static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
131
132 struct pci_dev *dev = drive->hwif->pci_dev;
133
134 pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]);
135
136 if (svwks_csb_check(dev)) {
137 u16 csb_pio = 0;
138
139 pci_read_config_word(dev, 0x4a, &csb_pio);
140
141 csb_pio &= ~(0x0f << (4 * drive->dn));
142 csb_pio |= (pio << (4 * drive->dn));
143
144 pci_write_config_word(dev, 0x4a, csb_pio);
145 }
146}
147
126static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) 148static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
127{ 149{
128 static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; 150 static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
129 static const u8 dma_modes[] = { 0x77, 0x21, 0x20 }; 151 static const u8 dma_modes[] = { 0x77, 0x21, 0x20 };
130 static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
131 static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
132 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; 152 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
133 153
134 ide_hwif_t *hwif = HWIF(drive); 154 ide_hwif_t *hwif = HWIF(drive);
135 struct pci_dev *dev = hwif->pci_dev; 155 struct pci_dev *dev = hwif->pci_dev;
136 u8 speed = ide_rate_filter(drive, xferspeed); 156 u8 speed = ide_rate_filter(drive, xferspeed);
137 u8 pio = ide_get_best_pio_mode(drive, 255, 4, NULL);
138 u8 unit = (drive->select.b.unit & 0x01); 157 u8 unit = (drive->select.b.unit & 0x01);
139 u8 csb5 = svwks_csb_check(dev); 158
140 u8 ultra_enable = 0, ultra_timing = 0; 159 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0;
141 u8 dma_timing = 0, pio_timing = 0; 160
142 u16 csb5_pio = 0; 161 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
162 svwks_tune_pio(drive, speed - XFER_PIO_0);
163 return ide_config_drive_speed(drive, speed);
164 }
143 165
144 /* If we are about to put a disk into UDMA mode we screwed up. 166 /* If we are about to put a disk into UDMA mode we screwed up.
145 Our code assumes we never _ever_ do this on an OSB4 */ 167 Our code assumes we never _ever_ do this on an OSB4 */
@@ -149,31 +171,15 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
149 BUG(); 171 BUG();
150 172
151 pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); 173 pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
152 pci_read_config_word(dev, 0x4A, &csb5_pio);
153 pci_read_config_byte(dev, 0x54, &ultra_enable); 174 pci_read_config_byte(dev, 0x54, &ultra_enable);
154 175
155 ultra_timing &= ~(0x0F << (4*unit)); 176 ultra_timing &= ~(0x0F << (4*unit));
156 ultra_enable &= ~(0x01 << drive->dn); 177 ultra_enable &= ~(0x01 << drive->dn);
157 csb5_pio &= ~(0x0F << (4*drive->dn));
158 178
159 switch(speed) { 179 switch(speed) {
160 case XFER_PIO_4:
161 case XFER_PIO_3:
162 case XFER_PIO_2:
163 case XFER_PIO_1:
164 case XFER_PIO_0:
165 pio_timing |= pio_modes[speed - XFER_PIO_0];
166 csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn));
167 break;
168
169 case XFER_MW_DMA_2: 180 case XFER_MW_DMA_2:
170 case XFER_MW_DMA_1: 181 case XFER_MW_DMA_1:
171 case XFER_MW_DMA_0: 182 case XFER_MW_DMA_0:
172 /*
173 * TODO: always setup PIO mode so this won't be needed
174 */
175 pio_timing |= pio_modes[pio];
176 csb5_pio |= (pio << (4*drive->dn));
177 dma_timing |= dma_modes[speed - XFER_MW_DMA_0]; 183 dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
178 break; 184 break;
179 185
@@ -183,11 +189,6 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
183 case XFER_UDMA_2: 189 case XFER_UDMA_2:
184 case XFER_UDMA_1: 190 case XFER_UDMA_1:
185 case XFER_UDMA_0: 191 case XFER_UDMA_0:
186 /*
187 * TODO: always setup PIO mode so this won't be needed
188 */
189 pio_timing |= pio_modes[pio];
190 csb5_pio |= (pio << (4*drive->dn));
191 dma_timing |= dma_modes[2]; 192 dma_timing |= dma_modes[2];
192 ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit)); 193 ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
193 ultra_enable |= (0x01 << drive->dn); 194 ultra_enable |= (0x01 << drive->dn);
@@ -195,10 +196,6 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
195 break; 196 break;
196 } 197 }
197 198
198 pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing);
199 if (csb5)
200 pci_write_config_word(dev, 0x4A, csb5_pio);
201
202 pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing); 199 pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
203 pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing); 200 pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
204 pci_write_config_byte(dev, 0x54, ultra_enable); 201 pci_write_config_byte(dev, 0x54, ultra_enable);
@@ -208,8 +205,9 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
208 205
209static void svwks_tune_drive (ide_drive_t *drive, u8 pio) 206static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
210{ 207{
211 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 208 pio = ide_get_best_pio_mode(drive, pio, 4);
212 (void)svwks_tune_chipset(drive, XFER_PIO_0 + pio); 209 svwks_tune_pio(drive, pio);
210 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio);
213} 211}
214 212
215static int svwks_config_drive_xfer_rate (ide_drive_t *drive) 213static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
@@ -389,8 +387,6 @@ static u8 __devinit ata66_svwks(ide_hwif_t *hwif)
389 387
390static void __devinit init_hwif_svwks (ide_hwif_t *hwif) 388static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
391{ 389{
392 u8 dma_stat = 0;
393
394 if (!hwif->irq) 390 if (!hwif->irq)
395 hwif->irq = hwif->channel ? 15 : 14; 391 hwif->irq = hwif->channel ? 15 : 14;
396 392
@@ -407,11 +403,11 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
407 403
408 hwif->autodma = 0; 404 hwif->autodma = 0;
409 405
410 if (!hwif->dma_base) { 406 hwif->drives[0].autotune = 1;
411 hwif->drives[0].autotune = 1; 407 hwif->drives[1].autotune = 1;
412 hwif->drives[1].autotune = 1; 408
409 if (!hwif->dma_base)
413 return; 410 return;
414 }
415 411
416 hwif->ide_dma_check = &svwks_config_drive_xfer_rate; 412 hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
417 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 413 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
@@ -421,11 +417,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
421 if (!noautodma) 417 if (!noautodma)
422 hwif->autodma = 1; 418 hwif->autodma = 1;
423 419
424 dma_stat = inb(hwif->dma_status); 420 hwif->drives[0].autodma = hwif->drives[1].autodma = 1;
425 hwif->drives[0].autodma = (dma_stat & 0x20);
426 hwif->drives[1].autodma = (dma_stat & 0x40);
427 hwif->drives[0].autotune = (!(dma_stat & 0x20));
428 hwif->drives[1].autotune = (!(dma_stat & 0x40));
429} 421}
430 422
431static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d) 423static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
@@ -441,9 +433,12 @@ static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
441 d->bootable = ON_BOARD; 433 d->bootable = ON_BOARD;
442 } 434 }
443 435
444 d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE || 436 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
445 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) && 437 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
446 (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2; 438 (!(PCI_FUNC(dev->devfn) & 1)))
439 d->host_flags |= IDE_HFLAG_SINGLE;
440 else
441 d->host_flags &= ~IDE_HFLAG_SINGLE;
447 442
448 return ide_setup_pci_device(dev, d); 443 return ide_setup_pci_device(dev, d);
449} 444}
@@ -454,41 +449,43 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
454 .init_setup = init_setup_svwks, 449 .init_setup = init_setup_svwks,
455 .init_chipset = init_chipset_svwks, 450 .init_chipset = init_chipset_svwks,
456 .init_hwif = init_hwif_svwks, 451 .init_hwif = init_hwif_svwks,
457 .channels = 2,
458 .autodma = AUTODMA, 452 .autodma = AUTODMA,
459 .bootable = ON_BOARD, 453 .bootable = ON_BOARD,
454 .pio_mask = ATA_PIO4,
460 },{ /* 1 */ 455 },{ /* 1 */
461 .name = "SvrWks CSB5", 456 .name = "SvrWks CSB5",
462 .init_setup = init_setup_svwks, 457 .init_setup = init_setup_svwks,
463 .init_chipset = init_chipset_svwks, 458 .init_chipset = init_chipset_svwks,
464 .init_hwif = init_hwif_svwks, 459 .init_hwif = init_hwif_svwks,
465 .channels = 2,
466 .autodma = AUTODMA, 460 .autodma = AUTODMA,
467 .bootable = ON_BOARD, 461 .bootable = ON_BOARD,
462 .pio_mask = ATA_PIO4,
468 },{ /* 2 */ 463 },{ /* 2 */
469 .name = "SvrWks CSB6", 464 .name = "SvrWks CSB6",
470 .init_setup = init_setup_csb6, 465 .init_setup = init_setup_csb6,
471 .init_chipset = init_chipset_svwks, 466 .init_chipset = init_chipset_svwks,
472 .init_hwif = init_hwif_svwks, 467 .init_hwif = init_hwif_svwks,
473 .channels = 2,
474 .autodma = AUTODMA, 468 .autodma = AUTODMA,
475 .bootable = ON_BOARD, 469 .bootable = ON_BOARD,
470 .pio_mask = ATA_PIO4,
476 },{ /* 3 */ 471 },{ /* 3 */
477 .name = "SvrWks CSB6", 472 .name = "SvrWks CSB6",
478 .init_setup = init_setup_csb6, 473 .init_setup = init_setup_csb6,
479 .init_chipset = init_chipset_svwks, 474 .init_chipset = init_chipset_svwks,
480 .init_hwif = init_hwif_svwks, 475 .init_hwif = init_hwif_svwks,
481 .channels = 1, /* 2 */
482 .autodma = AUTODMA, 476 .autodma = AUTODMA,
483 .bootable = ON_BOARD, 477 .bootable = ON_BOARD,
478 .host_flags = IDE_HFLAG_SINGLE,
479 .pio_mask = ATA_PIO4,
484 },{ /* 4 */ 480 },{ /* 4 */
485 .name = "SvrWks HT1000", 481 .name = "SvrWks HT1000",
486 .init_setup = init_setup_svwks, 482 .init_setup = init_setup_svwks,
487 .init_chipset = init_chipset_svwks, 483 .init_chipset = init_chipset_svwks,
488 .init_hwif = init_hwif_svwks, 484 .init_hwif = init_hwif_svwks,
489 .channels = 1, /* 2 */
490 .autodma = AUTODMA, 485 .autodma = AUTODMA,
491 .bootable = ON_BOARD, 486 .bootable = ON_BOARD,
487 .host_flags = IDE_HFLAG_SINGLE,
488 .pio_mask = ATA_PIO4,
492 } 489 }
493}; 490};
494 491
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index d396b2929ed8..57145767c3df 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -586,6 +586,7 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
586 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ 586 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
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->tuneproc = NULL; /* Sets timing for PIO mode */ 590 hwif->tuneproc = NULL; /* Sets timing for PIO mode */
590 hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */ 591 hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */
591 hwif->selectproc = NULL;/* Use the default routine to select drive */ 592 hwif->selectproc = NULL;/* Use the default routine to select drive */
@@ -724,10 +725,10 @@ static ide_pci_device_t sgiioc4_chipset __devinitdata = {
724 .name = "SGIIOC4", 725 .name = "SGIIOC4",
725 .init_hwif = ide_init_sgiioc4, 726 .init_hwif = ide_init_sgiioc4,
726 .init_dma = ide_dma_sgiioc4, 727 .init_dma = ide_dma_sgiioc4,
727 .channels = 1,
728 .autodma = AUTODMA, 728 .autodma = AUTODMA,
729 /* SGI IOC4 doesn't have enablebits. */ 729 /* SGI IOC4 doesn't have enablebits. */
730 .bootable = ON_BOARD, 730 .bootable = ON_BOARD,
731 .host_flags = IDE_HFLAG_SINGLE,
731}; 732};
732 733
733int 734int
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 1c3e35487893..50f6d172ef77 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * linux/drivers/ide/pci/siimage.c Version 1.12 Mar 10 2007 2 * linux/drivers/ide/pci/siimage.c Version 1.15 Jun 29 2007
3 * 3 *
4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * Copyright (C) 2007 MontaVista Software, Inc. 6 * Copyright (C) 2007 MontaVista Software, Inc.
7 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
7 * 8 *
8 * May be copied or modified under the terms of the GNU General Public License 9 * May be copied or modified under the terms of the GNU General Public License
9 * 10 *
@@ -31,6 +32,10 @@
31 * unplugging/replugging the virtual CD interface when the DRAC is reset. 32 * unplugging/replugging the virtual CD interface when the DRAC is reset.
32 * This often causes drivers/ide/siimage to panic but is ok with the rather 33 * This often causes drivers/ide/siimage to panic but is ok with the rather
33 * smarter code in libata. 34 * smarter code in libata.
35 *
36 * TODO:
37 * - IORDY fixes
38 * - VDMA support
34 */ 39 */
35 40
36#include <linux/types.h> 41#include <linux/types.h>
@@ -160,82 +165,45 @@ out:
160} 165}
161 166
162/** 167/**
163 * siimage_taskfile_timing - turn timing data to a mode 168 * sil_tune_pio - tune a drive
164 * @hwif: interface to query
165 *
166 * Read the timing data for the interface and return the
167 * mode that is being used.
168 */
169
170static byte siimage_taskfile_timing (ide_hwif_t *hwif)
171{
172 u16 timing = 0x328a;
173 unsigned long addr = siimage_selreg(hwif, 2);
174
175 if (hwif->mmio)
176 timing = hwif->INW(addr);
177 else
178 pci_read_config_word(hwif->pci_dev, addr, &timing);
179
180 switch (timing) {
181 case 0x10c1: return 4;
182 case 0x10c3: return 3;
183 case 0x1104:
184 case 0x1281: return 2;
185 case 0x2283: return 1;
186 case 0x328a:
187 default: return 0;
188 }
189}
190
191/**
192 * simmage_tuneproc - tune a drive
193 * @drive: drive to tune 169 * @drive: drive to tune
194 * @mode_wanted: the target operating mode 170 * @pio: the desired PIO mode
195 * 171 *
196 * Load the timing settings for this device mode into the 172 * Load the timing settings for this device mode into the
197 * controller. If we are in PIO mode 3 or 4 turn on IORDY 173 * controller. If we are in PIO mode 3 or 4 turn on IORDY
198 * monitoring (bit 9). The TF timing is bits 31:16 174 * monitoring (bit 9). The TF timing is bits 31:16
199 */ 175 */
200 176
201static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted) 177static void sil_tune_pio(ide_drive_t *drive, u8 pio)
202{ 178{
179 const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 };
180 const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 };
181
203 ide_hwif_t *hwif = HWIF(drive); 182 ide_hwif_t *hwif = HWIF(drive);
183 ide_drive_t *pair = &hwif->drives[drive->dn ^ 1];
204 u32 speedt = 0; 184 u32 speedt = 0;
205 u16 speedp = 0; 185 u16 speedp = 0;
206 unsigned long addr = siimage_seldev(drive, 0x04); 186 unsigned long addr = siimage_seldev(drive, 0x04);
207 unsigned long tfaddr = siimage_selreg(hwif, 0x02); 187 unsigned long tfaddr = siimage_selreg(hwif, 0x02);
208 188 u8 tf_pio = pio;
209 /* cheat for now and use the docs */ 189
210 switch (mode_wanted) { 190 /* trim *taskfile* PIO to the slowest of the master/slave */
211 case 4: 191 if (pair->present) {
212 speedp = 0x10c1; 192 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4);
213 speedt = 0x10c1; 193
214 break; 194 if (pair_pio < tf_pio)
215 case 3: 195 tf_pio = pair_pio;
216 speedp = 0x10c3;
217 speedt = 0x10c3;
218 break;
219 case 2:
220 speedp = 0x1104;
221 speedt = 0x1281;
222 break;
223 case 1:
224 speedp = 0x2283;
225 speedt = 0x2283;
226 break;
227 case 0:
228 default:
229 speedp = 0x328a;
230 speedt = 0x328a;
231 break;
232 } 196 }
233 197
198 /* cheat for now and use the docs */
199 speedp = data_speed[pio];
200 speedt = tf_speed[tf_pio];
201
234 if (hwif->mmio) { 202 if (hwif->mmio) {
235 hwif->OUTW(speedp, addr); 203 hwif->OUTW(speedp, addr);
236 hwif->OUTW(speedt, tfaddr); 204 hwif->OUTW(speedt, tfaddr);
237 /* Now set up IORDY */ 205 /* Now set up IORDY */
238 if(mode_wanted == 3 || mode_wanted == 4) 206 if (pio > 2)
239 hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); 207 hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2);
240 else 208 else
241 hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); 209 hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2);
@@ -245,42 +213,17 @@ static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted)
245 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); 213 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp);
246 speedp &= ~0x200; 214 speedp &= ~0x200;
247 /* Set IORDY for mode 3 or 4 */ 215 /* Set IORDY for mode 3 or 4 */
248 if(mode_wanted == 3 || mode_wanted == 4) 216 if (pio > 2)
249 speedp |= 0x200; 217 speedp |= 0x200;
250 pci_write_config_word(hwif->pci_dev, tfaddr-2, speedp); 218 pci_write_config_word(hwif->pci_dev, tfaddr-2, speedp);
251 } 219 }
252} 220}
253 221
254/** 222static void sil_tuneproc(ide_drive_t *drive, u8 pio)
255 * config_siimage_chipset_for_pio - set drive timings
256 * @drive: drive to tune
257 * @speed we want
258 *
259 * Compute the best pio mode we can for a given device. Also honour
260 * the timings for the driver when dealing with mixed devices. Some
261 * of this is ugly but its all wrapped up here
262 *
263 * The SI680 can also do VDMA - we need to start using that
264 *
265 * FIXME: we use the BIOS channel timings to avoid driving the task
266 * files too fast at the disk. We need to compute the master/slave
267 * drive PIO mode properly so that we can up the speed on a hotplug
268 * system.
269 */
270
271static void config_siimage_chipset_for_pio (ide_drive_t *drive, byte set_speed)
272{ 223{
273 u8 channel_timings = siimage_taskfile_timing(HWIF(drive)); 224 pio = ide_get_best_pio_mode(drive, pio, 4);
274 u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 4, 5, NULL); 225 sil_tune_pio(drive, pio);
275 226 (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio);
276 /* WARNING PIO timing mess is going to happen b/w devices, argh */
277 if ((channel_timings != set_pio) && (set_pio > channel_timings))
278 set_pio = channel_timings;
279
280 siimage_tuneproc(drive, set_pio);
281 speed = XFER_PIO_0 + set_pio;
282 if (set_speed)
283 (void) ide_config_drive_speed(drive, speed);
284} 227}
285 228
286/** 229/**
@@ -335,7 +278,7 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
335 case XFER_PIO_2: 278 case XFER_PIO_2:
336 case XFER_PIO_1: 279 case XFER_PIO_1:
337 case XFER_PIO_0: 280 case XFER_PIO_0:
338 siimage_tuneproc(drive, (speed - XFER_PIO_0)); 281 sil_tune_pio(drive, speed - XFER_PIO_0);
339 mode |= ((unit) ? 0x10 : 0x01); 282 mode |= ((unit) ? 0x10 : 0x01);
340 break; 283 break;
341 case XFER_MW_DMA_2: 284 case XFER_MW_DMA_2:
@@ -343,7 +286,6 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
343 case XFER_MW_DMA_0: 286 case XFER_MW_DMA_0:
344 multi = dma[speed - XFER_MW_DMA_0]; 287 multi = dma[speed - XFER_MW_DMA_0];
345 mode |= ((unit) ? 0x20 : 0x02); 288 mode |= ((unit) ? 0x20 : 0x02);
346 config_siimage_chipset_for_pio(drive, 0);
347 break; 289 break;
348 case XFER_UDMA_6: 290 case XFER_UDMA_6:
349 case XFER_UDMA_5: 291 case XFER_UDMA_5:
@@ -356,7 +298,6 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
356 ultra |= ((scsc) ? (ultra6[speed - XFER_UDMA_0]) : 298 ultra |= ((scsc) ? (ultra6[speed - XFER_UDMA_0]) :
357 (ultra5[speed - XFER_UDMA_0])); 299 (ultra5[speed - XFER_UDMA_0]));
358 mode |= ((unit) ? 0x30 : 0x03); 300 mode |= ((unit) ? 0x30 : 0x03);
359 config_siimage_chipset_for_pio(drive, 0);
360 break; 301 break;
361 default: 302 default:
362 return 1; 303 return 1;
@@ -390,7 +331,7 @@ static int siimage_config_drive_for_dma (ide_drive_t *drive)
390 return 0; 331 return 0;
391 332
392 if (ide_use_fast_pio(drive)) 333 if (ide_use_fast_pio(drive))
393 config_siimage_chipset_for_pio(drive, 1); 334 sil_tuneproc(drive, 255);
394 335
395 return -1; 336 return -1;
396} 337}
@@ -961,7 +902,7 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
961 902
962 hwif->resetproc = &siimage_reset; 903 hwif->resetproc = &siimage_reset;
963 hwif->speedproc = &siimage_tune_chipset; 904 hwif->speedproc = &siimage_tune_chipset;
964 hwif->tuneproc = &siimage_tuneproc; 905 hwif->tuneproc = &sil_tuneproc;
965 hwif->reset_poll = &siimage_reset_poll; 906 hwif->reset_poll = &siimage_reset_poll;
966 hwif->pre_reset = &siimage_pre_reset; 907 hwif->pre_reset = &siimage_pre_reset;
967 hwif->udma_filter = &sil_udma_filter; 908 hwif->udma_filter = &sil_udma_filter;
@@ -976,11 +917,11 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
976 first = 0; 917 first = 0;
977 } 918 }
978 } 919 }
979 if (!hwif->dma_base) { 920
980 hwif->drives[0].autotune = 1; 921 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
981 hwif->drives[1].autotune = 1; 922
923 if (hwif->dma_base == 0)
982 return; 924 return;
983 }
984 925
985 hwif->ultra_mask = 0x7f; 926 hwif->ultra_mask = 0x7f;
986 hwif->mwdma_mask = 0x07; 927 hwif->mwdma_mask = 0x07;
@@ -1016,9 +957,9 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
1016 .init_iops = init_iops_siimage, \ 957 .init_iops = init_iops_siimage, \
1017 .init_hwif = init_hwif_siimage, \ 958 .init_hwif = init_hwif_siimage, \
1018 .fixup = siimage_fixup, \ 959 .fixup = siimage_fixup, \
1019 .channels = 2, \
1020 .autodma = AUTODMA, \ 960 .autodma = AUTODMA, \
1021 .bootable = ON_BOARD, \ 961 .bootable = ON_BOARD, \
962 .pio_mask = ATA_PIO4, \
1022 } 963 }
1023 964
1024static ide_pci_device_t siimage_chipsets[] __devinitdata = { 965static ide_pci_device_t siimage_chipsets[] __devinitdata = {
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 756a9b6eb462..63fbb79e8178 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -521,7 +521,7 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
521 521
522static int sis5513_tune_drive(ide_drive_t *drive, u8 pio) 522static int sis5513_tune_drive(ide_drive_t *drive, u8 pio)
523{ 523{
524 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 524 pio = ide_get_best_pio_mode(drive, pio, 4);
525 config_art_rwp_pio(drive, pio); 525 config_art_rwp_pio(drive, pio);
526 return ide_config_drive_speed(drive, XFER_PIO_0 + pio); 526 return ide_config_drive_speed(drive, XFER_PIO_0 + pio);
527} 527}
@@ -878,10 +878,10 @@ static ide_pci_device_t sis5513_chipset __devinitdata = {
878 .name = "SIS5513", 878 .name = "SIS5513",
879 .init_chipset = init_chipset_sis5513, 879 .init_chipset = init_chipset_sis5513,
880 .init_hwif = init_hwif_sis5513, 880 .init_hwif = init_hwif_sis5513,
881 .channels = 2,
882 .autodma = NOAUTODMA, 881 .autodma = NOAUTODMA,
883 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 882 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
884 .bootable = ON_BOARD, 883 .bootable = ON_BOARD,
884 .pio_mask = ATA_PIO4,
885}; 885};
886 886
887static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id) 887static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index a7323d278c49..0947cab00595 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -52,12 +52,13 @@
52 * Convert a PIO mode and cycle time to the required on/off times 52 * Convert a PIO mode and cycle time to the required on/off times
53 * for the interface. This has protection against runaway timings. 53 * for the interface. This has protection against runaway timings.
54 */ 54 */
55static unsigned int get_pio_timings(ide_pio_data_t *p) 55static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
56{ 56{
57 unsigned int cmd_on, cmd_off; 57 unsigned int cmd_on, cmd_off;
58 u8 iordy = 0;
58 59
59 cmd_on = (ide_pio_timings[p->pio_mode].active_time + 29) / 30; 60 cmd_on = (ide_pio_timings[pio].active_time + 29) / 30;
60 cmd_off = (p->cycle_time - 30 * cmd_on + 29) / 30; 61 cmd_off = (ide_pio_cycle_time(drive, pio) - 30 * cmd_on + 29) / 30;
61 62
62 if (cmd_on == 0) 63 if (cmd_on == 0)
63 cmd_on = 1; 64 cmd_on = 1;
@@ -65,7 +66,10 @@ static unsigned int get_pio_timings(ide_pio_data_t *p)
65 if (cmd_off == 0) 66 if (cmd_off == 0)
66 cmd_off = 1; 67 cmd_off = 1;
67 68
68 return (cmd_on - 1) << 8 | (cmd_off - 1) | (p->use_iordy ? 0x40 : 0x00); 69 if (pio > 2 || ide_dev_has_iordy(drive->id))
70 iordy = 0x40;
71
72 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy;
69} 73}
70 74
71/* 75/*
@@ -75,14 +79,13 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio)
75{ 79{
76 struct pci_dev *dev = HWIF(drive)->pci_dev; 80 struct pci_dev *dev = HWIF(drive)->pci_dev;
77 int reg = 0x44 + drive->dn * 4; 81 int reg = 0x44 + drive->dn * 4;
78 ide_pio_data_t p;
79 u16 drv_ctrl; 82 u16 drv_ctrl;
80 83
81 DBG(("sl82c105_tune_pio(drive:%s, pio:%u)\n", drive->name, pio)); 84 DBG(("sl82c105_tune_pio(drive:%s, pio:%u)\n", drive->name, pio));
82 85
83 pio = ide_get_best_pio_mode(drive, pio, 5, &p); 86 pio = ide_get_best_pio_mode(drive, pio, 5);
84 87
85 drv_ctrl = get_pio_timings(&p); 88 drv_ctrl = get_pio_timings(drive, pio);
86 89
87 /* 90 /*
88 * Store the PIO timings so that we can restore them 91 * Store the PIO timings so that we can restore them
@@ -101,7 +104,8 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio)
101 } 104 }
102 105
103 printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name, 106 printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name,
104 ide_xfer_verbose(pio + XFER_PIO_0), p.cycle_time, drv_ctrl); 107 ide_xfer_verbose(pio + XFER_PIO_0),
108 ide_pio_cycle_time(drive, pio), drv_ctrl);
105 109
106 return pio; 110 return pio;
107} 111}
@@ -449,10 +453,10 @@ static ide_pci_device_t sl82c105_chipset __devinitdata = {
449 .name = "W82C105", 453 .name = "W82C105",
450 .init_chipset = init_chipset_sl82c105, 454 .init_chipset = init_chipset_sl82c105,
451 .init_hwif = init_hwif_sl82c105, 455 .init_hwif = init_hwif_sl82c105,
452 .channels = 2,
453 .autodma = NOAUTODMA, 456 .autodma = NOAUTODMA,
454 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}}, 457 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
455 .bootable = ON_BOARD, 458 .bootable = ON_BOARD,
459 .pio_mask = ATA_PIO5,
456}; 460};
457 461
458static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id) 462static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 575dbbd8b482..8e655f2db5cb 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -103,7 +103,7 @@ static void slc90e66_tune_pio (ide_drive_t *drive, u8 pio)
103 103
104static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio) 104static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio)
105{ 105{
106 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 106 pio = ide_get_best_pio_mode(drive, pio, 4);
107 slc90e66_tune_pio(drive, pio); 107 slc90e66_tune_pio(drive, pio);
108 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 108 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
109} 109}
@@ -214,10 +214,10 @@ static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
214static ide_pci_device_t slc90e66_chipset __devinitdata = { 214static ide_pci_device_t slc90e66_chipset __devinitdata = {
215 .name = "SLC90E66", 215 .name = "SLC90E66",
216 .init_hwif = init_hwif_slc90e66, 216 .init_hwif = init_hwif_slc90e66,
217 .channels = 2,
218 .autodma = AUTODMA, 217 .autodma = AUTODMA,
219 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, 218 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}},
220 .bootable = ON_BOARD, 219 .bootable = ON_BOARD,
220 .pio_mask = ATA_PIO4,
221}; 221};
222 222
223static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id) 223static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 8de1f8e22494..ec79bacc30c2 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -47,7 +47,7 @@ static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed)
47 47
48static void tc86c001_tune_drive(ide_drive_t *drive, u8 pio) 48static void tc86c001_tune_drive(ide_drive_t *drive, u8 pio)
49{ 49{
50 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 50 pio = ide_get_best_pio_mode(drive, pio, 4);
51 (void) tc86c001_tune_chipset(drive, XFER_PIO_0 + pio); 51 (void) tc86c001_tune_chipset(drive, XFER_PIO_0 + pio);
52} 52}
53 53
@@ -248,9 +248,10 @@ static ide_pci_device_t tc86c001_chipset __devinitdata = {
248 .name = "TC86C001", 248 .name = "TC86C001",
249 .init_chipset = init_chipset_tc86c001, 249 .init_chipset = init_chipset_tc86c001,
250 .init_hwif = init_hwif_tc86c001, 250 .init_hwif = init_hwif_tc86c001,
251 .channels = 1,
252 .autodma = AUTODMA, 251 .autodma = AUTODMA,
253 .bootable = OFF_BOARD 252 .bootable = OFF_BOARD,
253 .host_flags = IDE_HFLAG_SINGLE,
254 .pio_mask = ATA_PIO4,
254}; 255};
255 256
256static int __devinit tc86c001_init_one(struct pci_dev *dev, 257static int __devinit tc86c001_init_one(struct pci_dev *dev,
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index 35e8c612638f..024bbfae0429 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -96,7 +96,7 @@ static int triflex_tune_chipset(ide_drive_t *drive, u8 xferspeed)
96 96
97static void triflex_tune_drive(ide_drive_t *drive, u8 pio) 97static void triflex_tune_drive(ide_drive_t *drive, u8 pio)
98{ 98{
99 int use_pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 99 int use_pio = ide_get_best_pio_mode(drive, pio, 4);
100 (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio)); 100 (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio));
101} 101}
102 102
@@ -129,10 +129,10 @@ static void __devinit init_hwif_triflex(ide_hwif_t *hwif)
129static ide_pci_device_t triflex_device __devinitdata = { 129static ide_pci_device_t triflex_device __devinitdata = {
130 .name = "TRIFLEX", 130 .name = "TRIFLEX",
131 .init_hwif = init_hwif_triflex, 131 .init_hwif = init_hwif_triflex,
132 .channels = 2,
133 .autodma = AUTODMA, 132 .autodma = AUTODMA,
134 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, 133 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
135 .bootable = ON_BOARD, 134 .bootable = ON_BOARD,
135 .pio_mask = ATA_PIO4,
136}; 136};
137 137
138static int __devinit triflex_init_one(struct pci_dev *dev, 138static int __devinit triflex_init_one(struct pci_dev *dev,
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index cbb1b11119a5..dc4f4e298e00 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -327,7 +327,6 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
327static ide_pci_device_t trm290_chipset __devinitdata = { 327static ide_pci_device_t trm290_chipset __devinitdata = {
328 .name = "TRM290", 328 .name = "TRM290",
329 .init_hwif = init_hwif_trm290, 329 .init_hwif = init_hwif_trm290,
330 .channels = 2,
331 .autodma = NOAUTODMA, 330 .autodma = NOAUTODMA,
332 .bootable = ON_BOARD, 331 .bootable = ON_BOARD,
333}; 332};
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 27e92fb9f95e..581316f9581d 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * 2 *
3 * Version 3.45 3 * Version 3.46
4 * 4 *
5 * VIA IDE driver for Linux. Supported southbridges: 5 * VIA IDE driver for Linux. Supported southbridges:
6 * 6 *
@@ -203,10 +203,8 @@ static int via_set_drive(ide_drive_t *drive, u8 speed)
203 203
204static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio) 204static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio)
205{ 205{
206 if (pio == 255) { 206 if (pio == 255)
207 via_set_drive(drive, ide_find_best_pio_mode(drive)); 207 pio = ide_get_best_pio_mode(drive, 255, 5);
208 return;
209 }
210 208
211 via_set_drive(drive, XFER_PIO_0 + min_t(u8, pio, 5)); 209 via_set_drive(drive, XFER_PIO_0 + min_t(u8, pio, 5));
212} 210}
@@ -223,12 +221,14 @@ static int via82cxxx_ide_dma_check (ide_drive_t *drive)
223{ 221{
224 u8 speed = ide_max_dma_mode(drive); 222 u8 speed = ide_max_dma_mode(drive);
225 223
226 if (speed == 0) 224 if (speed == 0) {
227 speed = ide_find_best_pio_mode(drive); 225 via82cxxx_tune_drive(drive, 255);
226 return -1;
227 }
228 228
229 via_set_drive(drive, speed); 229 via_set_drive(drive, speed);
230 230
231 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 231 if (drive->autodma)
232 return 0; 232 return 0;
233 233
234 return -1; 234 return -1;
@@ -498,18 +498,22 @@ static ide_pci_device_t via82cxxx_chipsets[] __devinitdata = {
498 .name = "VP_IDE", 498 .name = "VP_IDE",
499 .init_chipset = init_chipset_via82cxxx, 499 .init_chipset = init_chipset_via82cxxx,
500 .init_hwif = init_hwif_via82cxxx, 500 .init_hwif = init_hwif_via82cxxx,
501 .channels = 2,
502 .autodma = NOAUTODMA, 501 .autodma = NOAUTODMA,
503 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, 502 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}},
504 .bootable = ON_BOARD 503 .bootable = ON_BOARD,
504 .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST
505 | IDE_HFLAG_PIO_NO_DOWNGRADE,
506 .pio_mask = ATA_PIO5,
505 },{ /* 1 */ 507 },{ /* 1 */
506 .name = "VP_IDE", 508 .name = "VP_IDE",
507 .init_chipset = init_chipset_via82cxxx, 509 .init_chipset = init_chipset_via82cxxx,
508 .init_hwif = init_hwif_via82cxxx, 510 .init_hwif = init_hwif_via82cxxx,
509 .channels = 2,
510 .autodma = AUTODMA, 511 .autodma = AUTODMA,
511 .enablebits = {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, 512 .enablebits = {{0x00,0x00,0x00}, {0x00,0x00,0x00}},
512 .bootable = ON_BOARD, 513 .bootable = ON_BOARD,
514 .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST
515 | IDE_HFLAG_PIO_NO_DOWNGRADE,
516 .pio_mask = ATA_PIO5,
513 } 517 }
514}; 518};
515 519
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c
index 82de2d781f2e..8859fe2f5ac2 100644
--- a/drivers/ide/ppc/mpc8xx.c
+++ b/drivers/ide/ppc/mpc8xx.c
@@ -316,6 +316,7 @@ m8xx_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port,
316 } 316 }
317 317
318 /* register routine to tune PIO mode */ 318 /* register routine to tune PIO mode */
319 ide_hwifs[data_port].pio_mask = ATA_PIO4;
319 ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; 320 ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc;
320 321
321 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; 322 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack;
@@ -402,6 +403,7 @@ void m8xx_ide_init_hwif_ports (hw_regs_t *hw,
402 } 403 }
403 404
404 /* register routine to tune PIO mode */ 405 /* register routine to tune PIO mode */
406 ide_hwifs[data_port].pio_mask = ATA_PIO4;
405 ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; 407 ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc;
406 408
407 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; 409 hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack;
@@ -431,13 +433,12 @@ void m8xx_ide_init_hwif_ports (hw_regs_t *hw,
431static void 433static void
432m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio) 434m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio)
433{ 435{
434 ide_pio_data_t d;
435#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) 436#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
436 volatile pcmconf8xx_t *pcmp; 437 volatile pcmconf8xx_t *pcmp;
437 ulong timing, mask, reg; 438 ulong timing, mask, reg;
438#endif 439#endif
439 440
440 pio = ide_get_best_pio_mode(drive, pio, 4, &d); 441 pio = ide_get_best_pio_mode(drive, pio, 4);
441 442
442#if 1 443#if 1
443 printk("%s[%d] %s: best PIO mode: %d\n", 444 printk("%s[%d] %s: best PIO mode: %d\n",
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index e46f47206542..33630ad3e794 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -615,24 +615,25 @@ out:
615static void 615static void
616pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) 616pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
617{ 617{
618 ide_pio_data_t d;
619 u32 *timings; 618 u32 *timings;
620 unsigned accessTicks, recTicks; 619 unsigned accessTicks, recTicks;
621 unsigned accessTime, recTime; 620 unsigned accessTime, recTime;
622 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; 621 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
623 622 unsigned int cycle_time;
623
624 if (pmif == NULL) 624 if (pmif == NULL)
625 return; 625 return;
626 626
627 /* which drive is it ? */ 627 /* which drive is it ? */
628 timings = &pmif->timings[drive->select.b.unit & 0x01]; 628 timings = &pmif->timings[drive->select.b.unit & 0x01];
629 629
630 pio = ide_get_best_pio_mode(drive, pio, 4, &d); 630 pio = ide_get_best_pio_mode(drive, pio, 4);
631 cycle_time = ide_pio_cycle_time(drive, pio);
631 632
632 switch (pmif->kind) { 633 switch (pmif->kind) {
633 case controller_sh_ata6: { 634 case controller_sh_ata6: {
634 /* 133Mhz cell */ 635 /* 133Mhz cell */
635 u32 tr = kauai_lookup_timing(shasta_pio_timings, d.cycle_time); 636 u32 tr = kauai_lookup_timing(shasta_pio_timings, cycle_time);
636 if (tr == 0) 637 if (tr == 0)
637 return; 638 return;
638 *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr; 639 *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr;
@@ -641,7 +642,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
641 case controller_un_ata6: 642 case controller_un_ata6:
642 case controller_k2_ata6: { 643 case controller_k2_ata6: {
643 /* 100Mhz cell */ 644 /* 100Mhz cell */
644 u32 tr = kauai_lookup_timing(kauai_pio_timings, d.cycle_time); 645 u32 tr = kauai_lookup_timing(kauai_pio_timings, cycle_time);
645 if (tr == 0) 646 if (tr == 0)
646 return; 647 return;
647 *timings = ((*timings) & ~TR_100_PIOREG_PIO_MASK) | tr; 648 *timings = ((*timings) & ~TR_100_PIOREG_PIO_MASK) | tr;
@@ -649,7 +650,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
649 } 650 }
650 case controller_kl_ata4: 651 case controller_kl_ata4:
651 /* 66Mhz cell */ 652 /* 66Mhz cell */
652 recTime = d.cycle_time - ide_pio_timings[pio].active_time 653 recTime = cycle_time - ide_pio_timings[pio].active_time
653 - ide_pio_timings[pio].setup_time; 654 - ide_pio_timings[pio].setup_time;
654 recTime = max(recTime, 150U); 655 recTime = max(recTime, 150U);
655 accessTime = ide_pio_timings[pio].active_time; 656 accessTime = ide_pio_timings[pio].active_time;
@@ -665,7 +666,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
665 default: { 666 default: {
666 /* 33Mhz cell */ 667 /* 33Mhz cell */
667 int ebit = 0; 668 int ebit = 0;
668 recTime = d.cycle_time - ide_pio_timings[pio].active_time 669 recTime = cycle_time - ide_pio_timings[pio].active_time
669 - ide_pio_timings[pio].setup_time; 670 - ide_pio_timings[pio].setup_time;
670 recTime = max(recTime, 150U); 671 recTime = max(recTime, 150U);
671 accessTime = ide_pio_timings[pio].active_time; 672 accessTime = ide_pio_timings[pio].active_time;
@@ -1247,6 +1248,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1247 hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40; 1248 hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
1248 hwif->drives[0].unmask = 1; 1249 hwif->drives[0].unmask = 1;
1249 hwif->drives[1].unmask = 1; 1250 hwif->drives[1].unmask = 1;
1251 hwif->pio_mask = ATA_PIO4;
1250 hwif->tuneproc = pmac_ide_tuneproc; 1252 hwif->tuneproc = pmac_ide_tuneproc;
1251 if (pmif->kind == controller_un_ata6 1253 if (pmif->kind == controller_un_ata6
1252 || pmif->kind == controller_k2_ata6 1254 || pmif->kind == controller_k2_ata6
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index c88d33225cf9..30e596c0f120 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -5,12 +5,6 @@
5 * 5 *
6 * Copyright (c) 1995-1998 Mark Lord 6 * Copyright (c) 1995-1998 Mark Lord
7 * May be copied or modified under the terms of the GNU General Public License 7 * May be copied or modified under the terms of the GNU General Public License
8 *
9 * Recent Changes
10 * Split the set up function into multiple functions
11 * Use pci_set_master
12 * Fix misreporting of I/O v MMIO problems
13 * Initial fixups for simplex devices
14 */ 8 */
15 9
16/* 10/*
@@ -407,7 +401,7 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d,
407 unsigned long ctl = 0, base = 0; 401 unsigned long ctl = 0, base = 0;
408 ide_hwif_t *hwif; 402 ide_hwif_t *hwif;
409 403
410 if ((d->flags & IDEPCI_FLAG_ISA_PORTS) == 0) { 404 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
411 /* Possibly we should fail if these checks report true */ 405 /* Possibly we should fail if these checks report true */
412 ide_pci_check_iomem(dev, d, 2*port); 406 ide_pci_check_iomem(dev, d, 2*port);
413 ide_pci_check_iomem(dev, d, 2*port+1); 407 ide_pci_check_iomem(dev, d, 2*port+1);
@@ -571,7 +565,7 @@ out:
571 565
572void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index) 566void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index)
573{ 567{
574 int port; 568 int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
575 int at_least_one_hwif_enabled = 0; 569 int at_least_one_hwif_enabled = 0;
576 ide_hwif_t *hwif, *mate = NULL; 570 ide_hwif_t *hwif, *mate = NULL;
577 u8 tmp; 571 u8 tmp;
@@ -582,16 +576,13 @@ void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, a
582 * Set up the IDE ports 576 * Set up the IDE ports
583 */ 577 */
584 578
585 for (port = 0; port <= 1; ++port) { 579 for (port = 0; port < channels; ++port) {
586 ide_pci_enablebit_t *e = &(d->enablebits[port]); 580 ide_pci_enablebit_t *e = &(d->enablebits[port]);
587 581
588 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || 582 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
589 (tmp & e->mask) != e->val)) 583 (tmp & e->mask) != e->val))
590 continue; /* port not enabled */ 584 continue; /* port not enabled */
591 585
592 if (d->channels <= port)
593 break;
594
595 if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL) 586 if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL)
596 continue; 587 continue;
597 588
@@ -616,6 +607,9 @@ void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, a
616 else 607 else
617 ide_hwif_setup_dma(dev, d, hwif); 608 ide_hwif_setup_dma(dev, d, hwif);
618bypass_legacy_dma: 609bypass_legacy_dma:
610 hwif->host_flags = d->host_flags;
611 hwif->pio_mask = d->pio_mask;
612
619 if (d->init_hwif) 613 if (d->init_hwif)
620 /* Call chipset-specific routine 614 /* Call chipset-specific routine
621 * for each enabled hwif 615 * for each enabled hwif
diff --git a/include/linux/ata.h b/include/linux/ata.h
index b5a20162af32..23a22df039d8 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -64,6 +64,15 @@ enum {
64 ATA_ID_PROD_LEN = 40, 64 ATA_ID_PROD_LEN = 40,
65 65
66 ATA_PCI_CTL_OFS = 2, 66 ATA_PCI_CTL_OFS = 2,
67
68 ATA_PIO0 = (1 << 0),
69 ATA_PIO1 = ATA_PIO0 | (1 << 1),
70 ATA_PIO2 = ATA_PIO1 | (1 << 2),
71 ATA_PIO3 = ATA_PIO2 | (1 << 3),
72 ATA_PIO4 = ATA_PIO3 | (1 << 4),
73 ATA_PIO5 = ATA_PIO4 | (1 << 5),
74 ATA_PIO6 = ATA_PIO5 | (1 << 6),
75
67 ATA_UDMA0 = (1 << 0), 76 ATA_UDMA0 = (1 << 0),
68 ATA_UDMA1 = ATA_UDMA0 | (1 << 1), 77 ATA_UDMA1 = ATA_UDMA0 | (1 << 1),
69 ATA_UDMA2 = ATA_UDMA1 | (1 << 2), 78 ATA_UDMA2 = ATA_UDMA1 | (1 << 2),
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 19ab25804056..5f5daad8bc54 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -681,6 +681,10 @@ typedef struct hwif_s {
681 u8 straight8; /* Alan's straight 8 check */ 681 u8 straight8; /* Alan's straight 8 check */
682 u8 bus_state; /* power state of the IDE bus */ 682 u8 bus_state; /* power state of the IDE bus */
683 683
684 u8 host_flags;
685
686 u8 pio_mask;
687
684 u8 atapi_dma; /* host supports atapi_dma */ 688 u8 atapi_dma; /* host supports atapi_dma */
685 u8 ultra_mask; 689 u8 ultra_mask;
686 u8 mwdma_mask; 690 u8 mwdma_mask;
@@ -1244,7 +1248,13 @@ typedef struct ide_pci_enablebit_s {
1244 1248
1245enum { 1249enum {
1246 /* Uses ISA control ports not PCI ones. */ 1250 /* Uses ISA control ports not PCI ones. */
1247 IDEPCI_FLAG_ISA_PORTS = (1 << 0), 1251 IDE_HFLAG_ISA_PORTS = (1 << 0),
1252 /* single port device */
1253 IDE_HFLAG_SINGLE = (1 << 1),
1254 /* don't use legacy PIO blacklist */
1255 IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2),
1256 /* don't use conservative PIO "downgrade" */
1257 IDE_HFLAG_PIO_NO_DOWNGRADE = (1 << 3),
1248}; 1258};
1249 1259
1250typedef struct ide_pci_device_s { 1260typedef struct ide_pci_device_s {
@@ -1256,13 +1266,13 @@ typedef struct ide_pci_device_s {
1256 void (*init_hwif)(ide_hwif_t *); 1266 void (*init_hwif)(ide_hwif_t *);
1257 void (*init_dma)(ide_hwif_t *, unsigned long); 1267 void (*init_dma)(ide_hwif_t *, unsigned long);
1258 void (*fixup)(ide_hwif_t *); 1268 void (*fixup)(ide_hwif_t *);
1259 u8 channels;
1260 u8 autodma; 1269 u8 autodma;
1261 ide_pci_enablebit_t enablebits[2]; 1270 ide_pci_enablebit_t enablebits[2];
1262 u8 bootable; 1271 u8 bootable;
1263 unsigned int extra; 1272 unsigned int extra;
1264 struct ide_pci_device_s *next; 1273 struct ide_pci_device_s *next;
1265 u8 flags; 1274 u8 host_flags;
1275 u8 pio_mask;
1266 u8 udma_mask; 1276 u8 udma_mask;
1267} ide_pci_device_t; 1277} ide_pci_device_t;
1268 1278
@@ -1363,6 +1373,11 @@ extern void ide_toggle_bounce(ide_drive_t *drive, int on);
1363extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate); 1373extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate);
1364int ide_use_fast_pio(ide_drive_t *); 1374int ide_use_fast_pio(ide_drive_t *);
1365 1375
1376static inline int ide_dev_has_iordy(struct hd_driveid *id)
1377{
1378 return ((id->field_valid & 2) && (id->capability & 8)) ? 1 : 0;
1379}
1380
1366u8 ide_dump_status(ide_drive_t *, const char *, u8); 1381u8 ide_dump_status(ide_drive_t *, const char *, u8);
1367 1382
1368typedef struct ide_pio_timings_s { 1383typedef struct ide_pio_timings_s {
@@ -1372,14 +1387,8 @@ typedef struct ide_pio_timings_s {
1372 /* active + recovery (+ setup for some chips) */ 1387 /* active + recovery (+ setup for some chips) */
1373} ide_pio_timings_t; 1388} ide_pio_timings_t;
1374 1389
1375typedef struct ide_pio_data_s { 1390unsigned int ide_pio_cycle_time(ide_drive_t *, u8);
1376 u8 pio_mode; 1391u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8);
1377 u8 use_iordy;
1378 u8 overridden;
1379 unsigned int cycle_time;
1380} ide_pio_data_t;
1381
1382extern u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d);
1383extern const ide_pio_timings_t ide_pio_timings[6]; 1392extern const ide_pio_timings_t ide_pio_timings[6];
1384 1393
1385 1394