o Disable the debug output that Kanoj disabled that I enabled
[linux-2.6/linux-mips.git] / drivers / block / via82cxxx.c
blobc2ec24d391d6420acdec9a7b19960c32276cb99a
1 /*
2 * linux/drivers/block/via82cxxx.c Version 0.07 Feb. 10, 2000
4 * Copyright (C) 1998-99 Michel Aubry, Maintainer
5 * Copyright (C) 1999 Jeff Garzik, MVP4 Support
6 * (jgarzik@mandrakesoft.com)
7 * Copyright (C) 1998-2000 Andre Hedrick (andre@suse.com)
8 * May be copied or modified under the terms of the GNU General Public License
10 * The VIA MVP-4 is reported OK with UDMA.
11 * The VIA MVP-3 is reported OK with UDMA.
12 * The TX Pro III is also reported OK with UDMA.
14 * VIA chips also have a single FIFO, with the same 64 bytes deep
15 * buffer (16 levels of 4 bytes each).
17 * However, VIA chips can have the buffer split either 8:8 levels,
18 * 16:0 levels or 0:16 levels between both channels. One could think
19 * of using this feature, as even if no level of FIFO is given to a
20 * given channel, one can for instance always reach ATAPI drives through
21 * it, or, if one channel is unused, configuration defaults to
22 * an even split FIFO levels.
24 * This feature is available only through a kernel command line :
25 * "splitfifo=Chan,Thr0,Thr1" or "splitfifo=Chan".
26 * where: Chan =1,2,3 or 4 and Thrx = 1,2,3,or 4.
28 * If Chan == 1:
29 * gives all the fifo to channel 0,
30 * sets its threshold to Thr0/4,
31 * and disables any dma access to channel 1.
33 * If chan == 2:
34 * gives all the fifo to channel 1,
35 * sets its threshold to Thr1/4,
36 * and disables any dma access to channel 0.
38 * If chan == 3 or 4:
39 * shares evenly fifo between channels,
40 * gives channel 0 a threshold of Thr0/4,
41 * and channel 1 a threshold of Thr1/4.
43 * Note that by default (if no command line is provided) and if a channel
44 * has been disabled in Bios, all the fifo is given to the active channel,
45 * and its threshold is set to 3/4.
47 * VT82c586B
49 * Offset 4B-48 - Drive Timing Control
50 * | pio0 | pio1 | pio2 | pio3 | pio4
51 * 25.0 MHz | 0xA8 | 0x65 | 0x65 | 0x31 | 0x20
52 * 33.0 MHz | 0xA8 | 0x65 | 0x65 | 0x31 | 0x20
53 * 37.5 MHz | 0xA9 | 0x76 | 0x76 | 0x32 | 0x21
55 * Offset 53-50 - UltraDMA Extended Timing Control
56 * UDMA | NO | 0 | 1 | 2
57 * | 0x03 | 0x62 | 0x61 | 0x60
59 * VT82c596B & VT82c686A
61 * Offset 4B-48 - Drive Timing Control
62 * | pio0 | pio1 | pio2 | pio3 | pio4
63 * 25.0 MHz | 0xA8 | 0x65 | 0x65 | 0x31 | 0x20
64 * 33.0 MHz | 0xA8 | 0x65 | 0x65 | 0x31 | 0x20
65 * 37.5 MHz | 0xDB | 0x87 | 0x87 | 0x42 | 0x31
66 * 41.5 MHz | 0xFE | 0xA8 | 0xA8 | 0x53 | 0x32
68 * Offset 53-50 - UltraDMA Extended Timing Control
69 * UDMA | NO | 0 | 1 | 2
70 * 33.0 MHz | 0x03 | 0xE2 | 0xE1 | 0xE0
71 * 37.5 MHz | 0x03 | 0xE2 | 0xE2 | 0xE1 (1)
73 * Offset 53-50 - UltraDMA Extended Timing Control
74 * UDMA | NO | 0 | 1 | 2 | 3 | 4
75 * 33.0 MHz | (2) | 0xE6 | 0xE4 | 0xE2 | 0xE1 | 0xE0
76 * 37.5 MHz | (2) | 0xE6 | 0xE6 | 0xE4 | 0xE2 | 0xE1 (1)
80 #include <linux/config.h>
81 #include <linux/types.h>
82 #include <linux/kernel.h>
83 #include <linux/timer.h>
84 #include <linux/mm.h>
85 #include <linux/ioport.h>
86 #include <linux/interrupt.h>
87 #include <linux/blkdev.h>
88 #include <linux/hdreg.h>
89 #include <linux/pci.h>
90 #include <linux/init.h>
91 #include <linux/delay.h>
92 #include <linux/ide.h>
94 #include <asm/io.h>
96 static struct pci_dev *host_dev = NULL;
97 static struct pci_dev *isa_dev = NULL;
99 static const struct {
100 const char *name;
101 unsigned short host_id;
102 } ApolloHostChipInfo[] = {
103 { "VT 82C585 Apollo VP1/VPX", PCI_DEVICE_ID_VIA_82C585, },
104 { "VT 82C595 Apollo VP2", PCI_DEVICE_ID_VIA_82C595, },
105 { "VT 82C597 Apollo VP3", PCI_DEVICE_ID_VIA_82C597_0, },
106 { "VT 82C598 Apollo MVP3", PCI_DEVICE_ID_VIA_82C598_0, },
107 { "VT 82C680 Apollo P6", PCI_DEVICE_ID_VIA_82C680, },
108 { "VT 82C691 Apollo Pro", PCI_DEVICE_ID_VIA_82C691, },
109 { "VT 82C693 Apollo Pro Plus", PCI_DEVICE_ID_VIA_82C693, },
110 { "Apollo MVP4", PCI_DEVICE_ID_VIA_8501_0, },
111 { "VT 8371", PCI_DEVICE_ID_VIA_8371_0, },
112 { "VT 8601", PCI_DEVICE_ID_VIA_8601_0, },
115 #define NUM_APOLLO_ISA_CHIP_DEVICES 2
116 #define VIA_FLAG_CHECK_REV 0x00000001
117 #define VIA_FLAG_ATA_66 0x00000002
119 static const struct {
120 unsigned short host_id;
121 unsigned short isa_id;
122 unsigned int flags;
123 } ApolloISAChipInfo[] = {
124 { PCI_DEVICE_ID_VIA_82C585, PCI_DEVICE_ID_VIA_82C586_1, VIA_FLAG_CHECK_REV },
125 { PCI_DEVICE_ID_VIA_82C595, PCI_DEVICE_ID_VIA_82C586_1, VIA_FLAG_CHECK_REV },
126 { PCI_DEVICE_ID_VIA_82C597_0, PCI_DEVICE_ID_VIA_82C586_1, VIA_FLAG_CHECK_REV },
127 { PCI_DEVICE_ID_VIA_82C598_0, PCI_DEVICE_ID_VIA_82C586_1, VIA_FLAG_CHECK_REV },
128 { PCI_DEVICE_ID_VIA_82C598_0, PCI_DEVICE_ID_VIA_82C596, 0 },
129 { PCI_DEVICE_ID_VIA_82C680, PCI_DEVICE_ID_VIA_82C586_1, VIA_FLAG_CHECK_REV },
130 { PCI_DEVICE_ID_VIA_82C691, PCI_DEVICE_ID_VIA_82C596, 0 },
131 { PCI_DEVICE_ID_VIA_82C693, PCI_DEVICE_ID_VIA_82C596, 0 },
132 { PCI_DEVICE_ID_VIA_8501_0, PCI_DEVICE_ID_VIA_82C686, VIA_FLAG_ATA_66 },
133 { PCI_DEVICE_ID_VIA_8371_0, PCI_DEVICE_ID_VIA_82C686, VIA_FLAG_ATA_66 },
134 { PCI_DEVICE_ID_VIA_8601_0, PCI_DEVICE_ID_VIA_8231, VIA_FLAG_ATA_66 },
137 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
139 #define DISPLAY_VIA_TIMINGS
141 #if defined(DISPLAY_VIA_TIMINGS) && defined(CONFIG_PROC_FS)
142 #include <linux/stat.h>
143 #include <linux/proc_fs.h>
145 static char *FIFO_str[] = {
146 " 1 ",
147 "3/4",
148 "1/2",
149 "1/4"
152 static char *control3_str[] = {
153 "No limitation",
154 "64",
155 "128",
156 "192"
159 static int via_get_info(char *, char **, off_t, int);
160 extern int (*via_display_info)(char *, char **, off_t, int); /* ide-proc.c */
161 static struct pci_dev *bmide_dev;
163 static char * print_apollo_drive_config (char *buf, struct pci_dev *dev)
165 int rc;
166 unsigned int time;
167 byte tm;
168 char *p = buf;
170 /* Drive Timing Control */
171 rc = pci_read_config_dword(dev, 0x48, &time);
172 p += sprintf(p, "Act Pls Width: %02d %02d %02d %02d\n",
173 ((time & 0xf0000000)>>28) + 1,
174 ((time & 0xf00000)>>20) + 1,
175 ((time & 0xf000)>>12) + 1,
176 ((time & 0xf0)>>4) + 1 );
177 p += sprintf(p, "Recovery Time: %02d %02d %02d %02d\n",
178 ((time & 0x0f000000)>>24) + 1,
179 ((time & 0x0f0000)>>16) + 1,
180 ((time & 0x0f00)>>8) + 1,
181 (time & 0x0f) + 1 );
183 /* Address Setup Time */
184 rc = pci_read_config_byte(dev, 0x4C, &tm);
185 p += sprintf(p, "Add. Setup T.: %01dT %01dT %01dT %01dT\n",
186 ((tm & 0xc0)>>6) + 1,
187 ((tm & 0x30)>>4) + 1,
188 ((tm & 0x0c)>>2) + 1,
189 (tm & 0x03) + 1 );
191 /* UltraDMA33 Extended Timing Control */
192 rc = pci_read_config_dword(dev, 0x50, &time);
193 p += sprintf(p, "------------------UDMA-Timing-Control------------------------\n");
194 p += sprintf(p, "Enable Meth.: %01d %01d %01d %01d\n",
195 (time & 0x80000000) ? 1 : 0,
196 (time & 0x800000) ? 1 : 0,
197 (time & 0x8000) ? 1 : 0,
198 (time & 0x80) ? 1 : 0 );
199 p += sprintf(p, "Enable: %s %s %s %s\n",
200 (time & 0x40000000) ? "yes" : "no ",
201 (time & 0x400000) ? "yes" : "no ",
202 (time & 0x4000) ? "yes" : "no ",
203 (time & 0x40) ? "yes" : "no " );
204 p += sprintf(p, "Transfer Mode: %s %s %s %s\n",
205 (time & 0x20000000) ? "PIO" : "DMA",
206 (time & 0x200000) ? "PIO" : "DMA",
207 (time & 0x2000) ? "PIO" : "DMA",
208 (time & 0x20) ? "PIO" : "DMA" );
209 p += sprintf(p, "Cycle Time: %01dT %01dT %01dT %01dT\n",
210 ((time & 0x03000000)>>24) + 2,
211 ((time & 0x030000)>>16) + 2,
212 ((time & 0x0300)>>8) + 2,
213 (time & 0x03) + 2 );
215 return (char *)p;
218 static char * print_apollo_ide_config (char *buf, struct pci_dev *dev)
220 byte time, tmp;
221 unsigned short size0, size1;
222 int rc;
223 char *p = buf;
225 rc = pci_read_config_byte(dev, 0x41, &time);
226 p += sprintf(p, "Prefetch Buffer : %s %s\n",
227 (time & 128) ? "on " : "off",
228 (time & 32) ? "on " : "off" );
229 p += sprintf(p, "Post Write Buffer: %s %s\n",
230 (time & 64) ? "on " : "off",
231 (time & 16) ? "on " : "off" );
233 /* FIFO configuration */
234 rc = pci_read_config_byte(dev, 0x43, &time);
235 tmp = ((time & 0x20)>>2) + ((time & 0x40)>>3);
236 p += sprintf(p, "FIFO Conf/Chan. : %02d %02d\n",
237 16 - tmp, tmp);
238 tmp = (time & 0x0F)>>2;
239 p += sprintf(p, "Threshold Prim. : %s %s\n",
240 FIFO_str[tmp],
241 FIFO_str[time & 0x03] );
243 /* chipset Control3 */
244 rc = pci_read_config_byte(dev, 0x46, &time);
245 p += sprintf(p, "Read DMA FIFO flush: %s %s\n",
246 (time & 0x80) ? "on " : "off",
247 (time & 0x40) ? "on " : "off" );
248 p += sprintf(p, "End Sect. FIFO flush: %s %s\n",
249 (time & 0x20) ? "on " : "off",
250 (time & 0x10) ? "on " : "off" );
251 p += sprintf(p, "Max DRDY Pulse Width: %s %s\n",
252 control3_str[(time & 0x03)],
253 (time & 0x03) ? "PCI clocks" : "" );
255 /* Primary and Secondary sector sizes */
256 rc = pci_read_config_word(dev, 0x60, &size0);
257 rc = pci_read_config_word(dev, 0x68, &size1);
258 p += sprintf(p, "Bytes Per Sector: %03d %03d\n",
259 size0 & 0xfff,
260 size1 & 0xfff );
262 return (char *)p;
265 static char * print_apollo_chipset_control1 (char *buf, struct pci_dev *dev)
267 byte t;
268 int rc;
269 char *p = buf;
270 unsigned short c;
271 byte l, l_max;
273 rc = pci_read_config_word(dev, 0x04, &c);
274 rc = pci_read_config_byte(dev, 0x44, &t);
275 rc = pci_read_config_byte(dev, 0x0d, &l);
276 rc = pci_read_config_byte(dev, 0x3f, &l_max);
278 p += sprintf(p, "Command register = 0x%x\n", c);
279 p += sprintf(p, "Master Read Cycle IRDY %d Wait State\n",
280 (t & 64) >>6 );
281 p += sprintf(p, "Master Write Cycle IRDY %d Wait State\n",
282 (t & 32) >> 5 );
283 p += sprintf(p, "FIFO Output Data 1/2 Clock Advance: %s\n",
284 (t & 16) ? "on " : "off" );
285 p += sprintf(p, "Bus Master IDE Status Register Read Retry: %s\n",
286 (t & 8) ? "on " : "off" );
287 p += sprintf(p, "Latency timer = %d (max. = %d)\n",
288 l, l_max);
290 return (char *)p;
293 static char * print_apollo_chipset_control2 (char *buf, struct pci_dev *dev)
295 byte t;
296 int rc;
297 char *p = buf;
298 rc = pci_read_config_byte(dev, 0x45, &t);
299 p += sprintf(p, "Interrupt Steering Swap: %s\n",
300 (t & 64) ? "on ":"off" );
302 return (char *)p;
305 static char * print_apollo_chipset_control3 (char *buf, struct pci_dev *dev,
306 unsigned short n)
309 * at that point we can be sure that register 0x20 of the
310 * chipset contains the right address...
312 unsigned int bibma;
313 int rc;
314 byte c0, c1;
315 char *p = buf;
317 rc = pci_read_config_dword(dev, 0x20, &bibma);
318 bibma = (bibma & 0xfff0) ;
321 * at that point bibma+0x2 et bibma+0xa are byte registers
322 * to investigate:
324 c0 = inb((unsigned short)bibma + 0x02);
325 c1 = inb((unsigned short)bibma + 0x0a);
327 if (n == 0) {
328 /*p = sprintf(p,"--------------------Primary IDE------------Secondary IDE-----");*/
329 p += sprintf(p, "both channels togth: %s %s\n",
330 (c0&0x80) ? "no" : "yes",
331 (c1&0x80) ? "no" : "yes" );
332 } else {
333 /*p = sprintf(p,"--------------drive0------drive1-------drive0------drive1----");*/
334 p += sprintf(p, "DMA enabled: %s %s %s %s\n",
335 (c0&0x20) ? "yes" : "no ",
336 (c0&0x40) ? "yes" : "no ",
337 (c1&0x20) ? "yes" : "no ",
338 (c1&0x40) ? "yes" : "no " );
341 return (char *)p;
344 static int via_get_info (char *buffer, char **addr, off_t offset, int count)
347 * print what /proc/via displays,
348 * if required from DISPLAY_APOLLO_TIMINGS
350 char *p = buffer;
351 /* Parameter of chipset : */
353 /* Miscellaneous control 1 */
354 p = print_apollo_chipset_control1(buffer, bmide_dev);
356 /* Miscellaneous control 2 */
357 p = print_apollo_chipset_control2(p, bmide_dev);
358 /* Parameters of drives: */
360 /* Header */
361 p += sprintf(p, "------------------Primary IDE------------Secondary IDE-----\n");
362 p = print_apollo_chipset_control3(p, bmide_dev, 0);
363 p = print_apollo_ide_config(p, bmide_dev);
364 p += sprintf(p, "--------------drive0------drive1-------drive0------drive1----\n");
365 p = print_apollo_chipset_control3(p, bmide_dev, 1);
366 p = print_apollo_drive_config(p, bmide_dev);
368 return p-buffer; /* hoping it is less than 4K... */
371 #endif /* defined(DISPLAY_VIA_TIMINGS) && defined(CONFIG_PROC_FS) */
374 * Used to set Fifo configuration via kernel command line:
377 byte via_proc = 0;
378 byte fifoconfig = 0;
379 static byte newfifo = 0;
381 /* Used to just intialize once Fifo configuration */
382 static short int done = 0;
385 * Set VIA Chipset Timings for (U)DMA modes enabled.
387 * VIA Apollo chipset has complete support for
388 * setting up the timing parameters.
390 static void set_via_timings (ide_hwif_t *hwif)
392 struct pci_dev *dev = hwif->pci_dev;
393 byte post = hwif->channel ? 0x30 : 0xc0;
394 byte flush = hwif->channel ? 0x50 : 0xa0;
395 int mask = hwif->channel ? ((newfifo & 0x60) ? 0 : 1) :
396 (((newfifo & 0x60) == 0x60) ? 1 : 0);
397 byte via_config = 0;
398 int rc = 0, errors = 0;
400 printk("%s: VIA Bus-Master ", hwif->name);
403 * setting IDE read prefetch buffer and IDE post write buffer.
404 * (This feature allows prefetched reads and post writes).
406 if ((rc = pci_read_config_byte(dev, 0x41, &via_config)))
407 errors++;
409 if (mask) {
410 if ((rc = pci_write_config_byte(dev, 0x41, via_config & ~post)))
411 errors++;
412 } else {
413 if ((rc = pci_write_config_byte(dev, 0x41, via_config | post)))
414 errors++;
418 * setting Channel read and End-of-sector FIFO flush.
419 * (This feature ensures that FIFO flush is enabled:
420 * - for read DMA when interrupt asserts the given channel.
421 * - at the end of each sector for the given channel.)
423 if ((rc = pci_read_config_byte(dev, 0x46, &via_config)))
424 errors++;
426 if (mask) {
427 if ((rc = pci_write_config_byte(dev, 0x46, via_config & ~flush)))
428 errors++;
429 } else {
430 if ((rc = pci_write_config_byte(dev, 0x46, via_config | flush)))
431 errors++;
434 if (!hwif->dma_base)
435 printk("Config %s. No DMA Enabled\n",
436 errors ? "ERROR":"Success");
437 else
438 printk("(U)DMA Timing Config %s\n",
439 errors ? "ERROR" : "Success");
443 * Sets VIA 82cxxx FIFO configuration:
444 * This chipsets gets a splitable fifo. This can be driven either by command
445 * line option (eg "splitfifo=2,2,3" which asks this driver to switch all the
446 * 16 fifo levels to the second drive, and give it a threshold of 3 for (u)dma
447 * triggering.
450 static int via_set_fifoconfig(ide_hwif_t *hwif)
452 byte fifo;
453 unsigned int timings;
454 struct pci_dev *dev = hwif->pci_dev;
456 /* read port configuration */
457 if (pci_read_config_dword(dev, 0x40, &timings))
458 return 1;
460 /* first read actual fifo config: */
461 if (pci_read_config_byte(dev, 0x43, &fifo))
462 return 1;
464 /* keep 4 and 7 bit as they seem to differ between chipsets flavors... */
465 newfifo = fifo & 0x90;
467 if (fifoconfig) {
468 /* we received a config request from kernel command line: */
469 newfifo |= fifoconfig & 0x6f;
470 } else {
471 /* If ever just one channel is unused, allocate all fifo levels to it
472 * and give it a 3/4 threshold for (u)dma transfers.
473 * Otherwise, share it evenly between channels:
475 if ((timings & 3) == 2) {
476 /* only primary channel is enabled
477 * 16 buf. to prim. chan. thresh=3/4
479 newfifo |= 0x06;
480 } else if ((timings & 3) == 1) {
481 /* only secondary channel is enabled!
482 * 16 buffers to sec. ch. thresh=3/4
484 newfifo |= 0x69;
485 } else {
486 /* fifo evenly distributed: */
487 newfifo |= 0x2a;
491 /* write resulting configuration to chipset: */
492 if (pci_write_config_byte(dev, 0x43, newfifo))
493 return 1;
495 /* and then reread it to get the actual one */
496 if (pci_read_config_byte(dev, 0x43, &newfifo))
497 return 1;
499 /* print a kernel report: */
500 printk("Split FIFO Configuration: %s Primary buffers, threshold = %s\n",
501 ((newfifo & 0x60) == 0x60) ? " 0" :
502 ((newfifo & 0x60) ? " 8" : "16"),
503 !(newfifo & 0x0c) ? "1" :
504 (!(newfifo & 0x08) ? "3/4" :
505 (newfifo & 0x04) ? "1/4" : "1/2"));
507 printk(" %s Second. buffers, threshold = %s\n",
508 ((newfifo & 0x60) == 0x60) ? "16" :
509 ((newfifo & 0x60) ? " 8" : " 0"),
510 !(newfifo & 0x03) ? "1" :
511 (!(newfifo & 0x02) ? "3/4" :
512 (newfifo & 0x01) ? "1/4" : "1/2"));
513 return 0;
516 #ifdef CONFIG_VIA82CXXX_TUNING
518 static int via82cxxx_tune_chipset (ide_drive_t *drive, byte speed)
520 struct hd_driveid *id = drive->id;
521 ide_hwif_t *hwif = HWIF(drive);
522 struct pci_dev *dev = hwif->pci_dev;
523 unsigned long dma_base = hwif->dma_base;
524 byte unit = (drive->select.b.unit & 0x01);
525 int drive_number = ((hwif->channel ? 2 : 0) + unit);
527 byte ata2_pci = 0x00;
528 byte ata3_pci = 0x00;
529 byte timing = 0x00;
530 byte ultra = 0x00;
531 int err;
533 int bus_speed = ide_system_bus_speed();
535 switch(drive_number) {
536 case 0: ata2_pci = 0x48; ata3_pci = 0x50; break;
537 case 1: ata2_pci = 0x49; ata3_pci = 0x51; break;
538 case 2: ata2_pci = 0x4a; ata3_pci = 0x52; break;
539 case 3: ata2_pci = 0x4b; ata3_pci = 0x53; break;
540 default:
541 return err;
544 pci_read_config_byte(dev, ata2_pci, &timing);
545 pci_read_config_byte(dev, ata3_pci, &ultra);
547 switch(speed) {
548 case XFER_UDMA_4:
549 case XFER_UDMA_3:
550 case XFER_UDMA_2:
551 case XFER_UDMA_1:
552 case XFER_UDMA_0:
553 case XFER_MW_DMA_2:
554 case XFER_MW_DMA_1:
555 case XFER_MW_DMA_0:
556 case XFER_SW_DMA_2:
557 case XFER_SW_DMA_1:
558 case XFER_SW_DMA_0:
559 case XFER_PIO_4:
560 case XFER_PIO_3:
561 case XFER_PIO_2:
562 case XFER_PIO_1:
563 case XFER_PIO_0:
564 case XFER_PIO_SLOW:
565 default:
566 break;
569 pci_write_config_byte(dev, ata2_pci, timing);
570 pci_write_config_byte(dev, ata3_pci, ultra);
572 err = ide_config_drive_speed(drive, speed);
574 return(err);
577 static int config_chipset_for_dma (ide_drive_t *drive)
579 struct hd_driveid *id = drive->id;
580 byte speed = 0x00;
581 int rval;
583 if ((id->dma_ultra & 0x0010) && (HWIF(drive)->udma_four)) {
584 speed = XFER_UDMA_4;
585 } else if ((id->dma_ultra & 0x0008) && (HWIF(drive)->udma_four)) {
586 speed = XFER_UDMA_3;
587 } else if (id->dma_ultra & 0x0004) {
588 speed = XFER_UDMA_2;
589 } else if (id->dma_ultra & 0x0002) {
590 speed = XFER_UDMA_1;
591 } else if (id->dma_ultra & 0x0001) {
592 speed = XFER_UDMA_0;
593 } else if (id->dma_mword & 0x0004) {
594 speed = XFER_MW_DMA_2;
595 } else if (id->dma_mword & 0x0002) {
596 speed = XFER_MW_DMA_1;
597 } else if (id->dma_mword & 0x0001) {
598 speed = XFER_MW_DMA_0;
599 } else if (id->dma_1word & 0x0004) {
600 speed = XFER_SW_DMA_2;
601 } else if (id->dma_1word & 0x0002) {
602 speed = XFER_SW_DMA_1;
603 } else if (id->dma_1word & 0x0001) {
604 speed = XFER_SW_DMA_0;
605 } else {
606 return ((int) ide_dma_off_quietly);
609 (void) via82cxxx_tune_chipset(drive, speed);
611 rval = (int)( ((id->dma_ultra >> 11) & 3) ? ide_dma_on :
612 ((id->dma_ultra >> 8) & 7) ? ide_dma_on :
613 ((id->dma_mword >> 8) & 7) ? ide_dma_on :
614 ((id->dma_1word >> 8) & 7) ? ide_dma_on :
615 ide_dma_off_quietly);
616 return rval;
619 static void config_chipset_for_pio (ide_drive_t *drive)
621 unsigned short eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
622 unsigned short xfer_pio = drive->id->eide_pio_modes;
623 byte timing, speed, pio;
625 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
627 if (xfer_pio> 4)
628 xfer_pio = 0;
630 if (drive->id->eide_pio_iordy > 0) {
631 for (xfer_pio = 5;
632 xfer_pio>0 &&
633 drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
634 xfer_pio--);
635 } else {
636 xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
637 (drive->id->eide_pio_modes & 2) ? 0x04 :
638 (drive->id->eide_pio_modes & 1) ? 0x03 :
639 (drive->id->tPIO & 2) ? 0x02 :
640 (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
643 timing = (xfer_pio >= pio) ? xfer_pio : pio;
645 switch(timing) {
646 case 4: speed = XFER_PIO_4;break;
647 case 3: speed = XFER_PIO_3;break;
648 case 2: speed = XFER_PIO_2;break;
649 case 1: speed = XFER_PIO_1;break;
650 default:
651 speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW; break;
653 (void) via82cxxx_tune_chipset(drive, speed);
656 static void via82cxxx_tune_drive (ide_drive_t *drive, byte pio)
658 byte speed;
659 switch(pio) {
660 case 4: speed = XFER_PIO_4;break;
661 case 3: speed = XFER_PIO_3;break;
662 case 2: speed = XFER_PIO_2;break;
663 case 1: speed = XFER_PIO_1;break;
664 default: speed = XFER_PIO_0;break;
666 (void) via82cxxx_tune_chipset(drive, speed);
669 static int config_drive_xfer_rate (ide_drive_t *drive)
671 struct hd_driveid *id = drive->id;
672 ide_dma_action_t dma_func = ide_dma_on;
674 if (id && (id->capability & 1) && HWIF(drive)->autodma) {
675 /* Consult the list of known "bad" drives */
676 if (ide_dmaproc(ide_dma_bad_drive, drive)) {
677 dma_func = ide_dma_off;
678 goto fast_ata_pio;
680 dma_func = ide_dma_off_quietly;
681 if (id->field_valid & 4) {
682 if (id->dma_ultra & 0x001F) {
683 /* Force if Capable UltraDMA */
684 dma_func = config_chipset_for_dma(drive);
685 if ((id->field_valid & 2) &&
686 (dma_func != ide_dma_on))
687 goto try_dma_modes;
689 } else if (id->field_valid & 2) {
690 try_dma_modes:
691 if ((id->dma_mword & 0x0007) ||
692 (id->dma_1word & 0x0007)) {
693 /* Force if Capable regular DMA modes */
694 dma_func = config_chipset_for_dma(drive);
695 if (dma_func != ide_dma_on)
696 goto no_dma_set;
698 } else if (ide_dmaproc(ide_dma_good_drive, drive)) {
699 if (id->eide_dma_time > 150) {
700 goto no_dma_set;
702 /* Consult the list of known "good" drives */
703 dma_func = config_chipset_for_dma(drive);
704 if (dma_func != ide_dma_on)
705 goto no_dma_set;
706 } else {
707 goto fast_ata_pio;
709 } else if ((id->capability & 8) || (id->field_valid & 2)) {
710 fast_ata_pio:
711 dma_func = ide_dma_off_quietly;
712 no_dma_set:
713 config_chipset_for_pio(drive);
715 return HWIF(drive)->dmaproc(dma_func, drive);
718 int via82cxxx_dmaproc (ide_dma_action_t func, ide_drive_t *drive)
720 switch (func) {
721 case ide_dma_check:
722 return config_drive_xfer_rate(drive);
723 default:
724 break;
726 return ide_dmaproc(func, drive); /* use standard DMA stuff */
728 #endif /* CONFIG_VIA82CXXX_TUNING */
730 unsigned int __init pci_init_via82cxxx (struct pci_dev *dev, const char *name)
732 struct pci_dev *host;
733 struct pci_dev *isa;
734 int i, j, ata33, ata66;
736 byte revision = 0;
738 for (i = 0; i < arraysize (ApolloHostChipInfo) && !host_dev; i++) {
739 host = pci_find_device (PCI_VENDOR_ID_VIA,
740 ApolloHostChipInfo[i].host_id,
741 NULL);
742 if (!host)
743 continue;
745 host_dev = host;
746 printk(ApolloHostChipInfo[i].name);
748 for (j = 0; j < arraysize (ApolloISAChipInfo) && !isa_dev; j++) {
749 if (ApolloISAChipInfo[j].host_id !=
750 ApolloHostChipInfo[i].host_id)
751 continue;
753 isa = pci_find_device (PCI_VENDOR_ID_VIA,
754 ApolloISAChipInfo[j].isa_id,
755 NULL);
756 if (!isa)
757 continue;
759 isa_dev = isa;
761 ata33 = 1;
762 ata66 = 0;
764 if (ApolloISAChipInfo[j].flags & VIA_FLAG_CHECK_REV) {
765 pci_read_config_byte(isa_dev, 0x0d, &revision);
766 ata33 = (revision >= 0x20) ? 1 : 0;
767 } else if (ApolloISAChipInfo[j].flags & VIA_FLAG_ATA_66) {
768 ata33 = 0;
769 ata66 = 1;
772 if (ata33 | ata66)
773 printk(" Chipset Core ATA-%s", ata66 ? "66" : "33");
775 printk("\n");
778 #if defined(DISPLAY_VIA_TIMINGS) && defined(CONFIG_PROC_FS)
779 via_proc = 1;
780 bmide_dev = dev;
781 via_display_info = &via_get_info;
782 #endif /* DISPLAY_VIA_TIMINGS && CONFIG_PROC_FS*/
784 return 0;
787 unsigned int __init ata66_via82cxxx (ide_hwif_t *hwif)
789 /* (Jeff Garzik) FIXME!!! for MVP4 */
790 return 0;
793 void __init ide_init_via82cxxx (ide_hwif_t *hwif)
795 set_via_timings(hwif);
797 #ifdef CONFIG_VIA82CXXX_TUNING
798 hwif->tuneproc = &via82cxxx_tune_drive;
799 if (hwif->dma_base) {
800 hwif->dmaproc = &via82cxxx_dmaproc;
801 } else {
802 hwif->autodma = 0;
803 hwif->drives[0].autotune = 1;
804 hwif->drives[1].autotune = 1;
806 #endif /* CONFIG_VIA82CXXX_TUNING */
810 * ide_dmacapable_via82cxxx(ide_hwif_t *, unsigned long)
811 * checks if channel "channel" of if hwif is dma
812 * capable or not, according to kernel command line,
813 * and the new fifo settings.
814 * It calls "ide_setup_dma" on capable mainboards, and
815 * bypasses the setup if not capable.
818 void ide_dmacapable_via82cxxx (ide_hwif_t *hwif, unsigned long dmabase)
820 if (!done) {
821 via_set_fifoconfig(hwif);
822 done = 1;
826 * check if any fifo is available for requested port:
828 if (((hwif->channel == 0) && ((newfifo & 0x60) == 0x60)) ||
829 ((hwif->channel == 1) && ((newfifo & 0x60) == 0x00))) {
830 printk(" %s: VP_IDE Bus-Master DMA disabled (FIFO setting)\n", hwif->name);
831 } else {
832 ide_setup_dma(hwif, dmabase, 8);