2 * linux/drivers/ide/pci/aec62xx.c Version 0.11 March 27, 2002
4 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
8 #include <linux/module.h>
9 #include <linux/config.h>
10 #include <linux/types.h>
11 #include <linux/pci.h>
12 #include <linux/delay.h>
13 #include <linux/hdreg.h>
14 #include <linux/ide.h>
15 #include <linux/init.h>
19 #include "ide_modes.h"
22 #if defined(DISPLAY_AEC62XX_TIMINGS) && defined(CONFIG_PROC_FS)
23 #include <linux/stat.h>
24 #include <linux/proc_fs.h>
26 static u8 aec62xx_proc = 0;
28 #define AEC_MAX_DEVS 5
30 static struct pci_dev *aec_devs[AEC_MAX_DEVS];
31 static int n_aec_devs;
35 static int aec62xx_get_info (char *buffer, char **addr, off_t offset, int count)
38 char *chipset_nums[] = {"error", "error", "error", "error",
39 "error", "error", "850UF", "860",
40 "860R", "865", "865R", "error" };
44 for (i = 0; i < n_aec_devs; i++) {
45 struct pci_dev *dev = aec_devs[i];
46 unsigned long iobase = pci_resource_start(dev, 4);
47 u8 c0 = 0, c1 = 0, art = 0;
50 #endif /* DEBUG_AEC_REGS */
52 c0 = inb(iobase + 0x02);
53 c1 = inb(iobase + 0x0a);
55 p += sprintf(p, "\nController: %d\n", i);
56 p += sprintf(p, "Chipset: AEC%s\n", chipset_nums[dev->device]);
58 p += sprintf(p, "--------------- Primary Channel "
59 "---------------- Secondary Channel "
61 (void) pci_read_config_byte(dev, 0x4a, &art);
62 p += sprintf(p, " %sabled ",
63 (art&0x02)?" en":"dis");
64 p += sprintf(p, " %sabled\n",
65 (art&0x04)?" en":"dis");
66 p += sprintf(p, "--------------- drive0 --------- drive1 "
67 "-------- drive0 ---------- drive1 ------\n");
68 p += sprintf(p, "DMA enabled: %s %s ",
69 (c0&0x20)?"yes":"no ",(c0&0x40)?"yes":"no ");
70 p += sprintf(p, " %s %s\n",
71 (c1&0x20)?"yes":"no ",(c1&0x40)?"yes":"no ");
73 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
74 (void) pci_read_config_byte(dev, 0x54, &art);
75 p += sprintf(p, "DMA Mode: %s(%s)",
76 (c0&0x20)?((art&0x03)?"UDMA":" DMA"):" PIO",
77 (art&0x02)?"2":(art&0x01)?"1":"0");
78 p += sprintf(p, " %s(%s)",
79 (c0&0x40)?((art&0x0c)?"UDMA":" DMA"):" PIO",
80 (art&0x08)?"2":(art&0x04)?"1":"0");
81 p += sprintf(p, " %s(%s)",
82 (c1&0x20)?((art&0x30)?"UDMA":" DMA"):" PIO",
83 (art&0x20)?"2":(art&0x10)?"1":"0");
84 p += sprintf(p, " %s(%s)\n",
85 (c1&0x40)?((art&0xc0)?"UDMA":" DMA"):" PIO",
86 (art&0x80)?"2":(art&0x40)?"1":"0");
88 (void) pci_read_config_byte(dev, 0x40, &art);
89 p += sprintf(p, "Active: 0x%02x", art);
90 (void) pci_read_config_byte(dev, 0x42, &art);
91 p += sprintf(p, " 0x%02x", art);
92 (void) pci_read_config_byte(dev, 0x44, &art);
93 p += sprintf(p, " 0x%02x", art);
94 (void) pci_read_config_byte(dev, 0x46, &art);
95 p += sprintf(p, " 0x%02x\n", art);
96 (void) pci_read_config_byte(dev, 0x41, &art);
97 p += sprintf(p, "Recovery: 0x%02x", art);
98 (void) pci_read_config_byte(dev, 0x43, &art);
99 p += sprintf(p, " 0x%02x", art);
100 (void) pci_read_config_byte(dev, 0x45, &art);
101 p += sprintf(p, " 0x%02x", art);
102 (void) pci_read_config_byte(dev, 0x47, &art);
103 p += sprintf(p, " 0x%02x\n", art);
104 #endif /* DEBUG_AEC_REGS */
107 * case PCI_DEVICE_ID_ARTOP_ATP860:
108 * case PCI_DEVICE_ID_ARTOP_ATP860R:
109 * case PCI_DEVICE_ID_ARTOP_ATP865:
110 * case PCI_DEVICE_ID_ARTOP_ATP865R:
112 (void) pci_read_config_byte(dev, 0x44, &art);
113 p += sprintf(p, "DMA Mode: %s(%s)",
114 (c0&0x20)?((art&0x07)?"UDMA":" DMA"):" PIO",
115 ((art&0x07)==0x07)?"6":
116 ((art&0x06)==0x06)?"5":
117 ((art&0x05)==0x05)?"4":
118 ((art&0x04)==0x04)?"3":
119 ((art&0x03)==0x03)?"2":
120 ((art&0x02)==0x02)?"1":
121 ((art&0x01)==0x01)?"0":"?");
122 p += sprintf(p, " %s(%s)",
123 (c0&0x40)?((art&0x70)?"UDMA":" DMA"):" PIO",
124 ((art&0x70)==0x70)?"6":
125 ((art&0x60)==0x60)?"5":
126 ((art&0x50)==0x50)?"4":
127 ((art&0x40)==0x40)?"3":
128 ((art&0x30)==0x30)?"2":
129 ((art&0x20)==0x20)?"1":
130 ((art&0x10)==0x10)?"0":"?");
131 (void) pci_read_config_byte(dev, 0x45, &art);
132 p += sprintf(p, " %s(%s)",
133 (c1&0x20)?((art&0x07)?"UDMA":" DMA"):" PIO",
134 ((art&0x07)==0x07)?"6":
135 ((art&0x06)==0x06)?"5":
136 ((art&0x05)==0x05)?"4":
137 ((art&0x04)==0x04)?"3":
138 ((art&0x03)==0x03)?"2":
139 ((art&0x02)==0x02)?"1":
140 ((art&0x01)==0x01)?"0":"?");
141 p += sprintf(p, " %s(%s)\n",
142 (c1&0x40)?((art&0x70)?"UDMA":" DMA"):" PIO",
143 ((art&0x70)==0x70)?"6":
144 ((art&0x60)==0x60)?"5":
145 ((art&0x50)==0x50)?"4":
146 ((art&0x40)==0x40)?"3":
147 ((art&0x30)==0x30)?"2":
148 ((art&0x20)==0x20)?"1":
149 ((art&0x10)==0x10)?"0":"?");
150 #ifdef DEBUG_AEC_REGS
151 (void) pci_read_config_byte(dev, 0x40, &art);
152 p += sprintf(p, "Active: 0x%02x", HIGH_4(art));
153 (void) pci_read_config_byte(dev, 0x41, &art);
154 p += sprintf(p, " 0x%02x", HIGH_4(art));
155 (void) pci_read_config_byte(dev, 0x42, &art);
156 p += sprintf(p, " 0x%02x", HIGH_4(art));
157 (void) pci_read_config_byte(dev, 0x43, &art);
158 p += sprintf(p, " 0x%02x\n", HIGH_4(art));
159 (void) pci_read_config_byte(dev, 0x40, &art);
160 p += sprintf(p, "Recovery: 0x%02x", LOW_4(art));
161 (void) pci_read_config_byte(dev, 0x41, &art);
162 p += sprintf(p, " 0x%02x", LOW_4(art));
163 (void) pci_read_config_byte(dev, 0x42, &art);
164 p += sprintf(p, " 0x%02x", LOW_4(art));
165 (void) pci_read_config_byte(dev, 0x43, &art);
166 p += sprintf(p, " 0x%02x\n", LOW_4(art));
167 (void) pci_read_config_byte(dev, 0x49, &uart);
168 p += sprintf(p, "reg49h = 0x%02x ", uart);
169 (void) pci_read_config_byte(dev, 0x4a, &uart);
170 p += sprintf(p, "reg4ah = 0x%02x\n", uart);
171 #endif /* DEBUG_AEC_REGS */
174 /* p - buffer must be less than 4k! */
175 len = (p - buffer) - offset;
176 *addr = buffer + offset;
178 return len > count ? count : len;
180 #endif /* defined(DISPLAY_AEC62xx_TIMINGS) && defined(CONFIG_PROC_FS) */
183 * TO DO: active tuning and correction of cards without a bios.
185 static u8 pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
187 for ( ; chipset_table->xfer_speed ; chipset_table++)
188 if (chipset_table->xfer_speed == speed) {
189 return chipset_table->chipset_settings;
191 return chipset_table->chipset_settings;
194 static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
196 for ( ; chipset_table->xfer_speed ; chipset_table++)
197 if (chipset_table->xfer_speed == speed) {
198 return chipset_table->ultra_settings;
200 return chipset_table->ultra_settings;
203 static u8 aec62xx_ratemask (ide_drive_t *drive)
205 ide_hwif_t *hwif = HWIF(drive);
208 switch(hwif->pci_dev->device) {
209 case PCI_DEVICE_ID_ARTOP_ATP865:
210 case PCI_DEVICE_ID_ARTOP_ATP865R:
212 mode = (hwif->INB(hwif->dma_master) & 0x10) ? 4 : 3;
214 mode = (hwif->INB(((hwif->channel) ?
215 hwif->mate->dma_status :
216 hwif->dma_status)) & 0x10) ? 4 : 3;
219 case PCI_DEVICE_ID_ARTOP_ATP860:
220 case PCI_DEVICE_ID_ARTOP_ATP860R:
223 case PCI_DEVICE_ID_ARTOP_ATP850UF:
228 if (!eighty_ninty_three(drive))
229 mode = min(mode, (u8)1);
233 static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed)
235 ide_hwif_t *hwif = HWIF(drive);
236 struct pci_dev *dev = hwif->pci_dev;
238 u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed);
239 u8 ultra = 0, ultra_conf = 0;
240 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0;
243 local_irq_save(flags);
244 pci_read_config_word(dev, 0x40|(2*drive->dn), &d_conf);
245 tmp0 = pci_bus_clock_list(speed, BUSCLOCK(dev));
246 SPLIT_BYTE(tmp0,tmp1,tmp2);
247 MAKE_WORD(d_conf,tmp1,tmp2);
248 pci_write_config_word(dev, 0x40|(2*drive->dn), d_conf);
252 pci_read_config_byte(dev, 0x54, &ultra);
253 tmp1 = ((0x00 << (2*drive->dn)) | (ultra & ~(3 << (2*drive->dn))));
254 ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev));
255 tmp2 = ((ultra_conf << (2*drive->dn)) | (tmp1 & ~(3 << (2*drive->dn))));
256 pci_write_config_byte(dev, 0x54, tmp2);
257 local_irq_restore(flags);
258 return(ide_config_drive_speed(drive, speed));
261 static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed)
263 ide_hwif_t *hwif = HWIF(drive);
264 struct pci_dev *dev = hwif->pci_dev;
265 u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed);
266 u8 unit = (drive->select.b.unit & 0x01);
267 u8 tmp1 = 0, tmp2 = 0;
268 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
271 local_irq_save(flags);
272 pci_read_config_byte(dev, 0x40|drive->dn, &drive_conf);
273 drive_conf = pci_bus_clock_list(speed, BUSCLOCK(dev));
274 pci_write_config_byte(dev, 0x40|drive->dn, drive_conf);
276 pci_read_config_byte(dev, (0x44|hwif->channel), &ultra);
277 tmp1 = ((0x00 << (4*unit)) | (ultra & ~(7 << (4*unit))));
278 ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev));
279 tmp2 = ((ultra_conf << (4*unit)) | (tmp1 & ~(7 << (4*unit))));
280 pci_write_config_byte(dev, (0x44|hwif->channel), tmp2);
281 local_irq_restore(flags);
282 return(ide_config_drive_speed(drive, speed));
285 static int aec62xx_tune_chipset (ide_drive_t *drive, u8 speed)
287 switch (HWIF(drive)->pci_dev->device) {
288 case PCI_DEVICE_ID_ARTOP_ATP865:
289 case PCI_DEVICE_ID_ARTOP_ATP865R:
290 case PCI_DEVICE_ID_ARTOP_ATP860:
291 case PCI_DEVICE_ID_ARTOP_ATP860R:
292 return ((int) aec6260_tune_chipset(drive, speed));
293 case PCI_DEVICE_ID_ARTOP_ATP850UF:
294 return ((int) aec6210_tune_chipset(drive, speed));
300 static int config_chipset_for_dma (ide_drive_t *drive)
302 u8 speed = ide_dma_speed(drive, aec62xx_ratemask(drive));
307 (void) aec62xx_tune_chipset(drive, speed);
308 return ide_dma_enable(drive);
311 static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
314 u8 new_pio = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
317 case 5: speed = new_pio; break;
318 case 4: speed = XFER_PIO_4; break;
319 case 3: speed = XFER_PIO_3; break;
320 case 2: speed = XFER_PIO_2; break;
321 case 1: speed = XFER_PIO_1; break;
322 default: speed = XFER_PIO_0; break;
324 (void) aec62xx_tune_chipset(drive, speed);
327 static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
329 ide_hwif_t *hwif = HWIF(drive);
330 struct hd_driveid *id = drive->id;
332 if ((id->capability & 1) && drive->autodma) {
333 /* Consult the list of known "bad" drives */
334 if (hwif->ide_dma_bad_drive(drive))
336 if (id->field_valid & 4) {
337 if (id->dma_ultra & hwif->ultra_mask) {
338 /* Force if Capable UltraDMA */
339 int dma = config_chipset_for_dma(drive);
340 if ((id->field_valid & 2) && !dma)
343 } else if (id->field_valid & 2) {
345 if ((id->dma_mword & hwif->mwdma_mask) ||
346 (id->dma_1word & hwif->swdma_mask)) {
347 /* Force if Capable regular DMA modes */
348 if (!config_chipset_for_dma(drive))
351 } else if (hwif->ide_dma_good_drive(drive) &&
352 (id->eide_dma_time < 150)) {
353 /* Consult the list of known "good" drives */
354 if (!config_chipset_for_dma(drive))
359 return hwif->ide_dma_on(drive);
360 } else if ((id->capability & 8) || (id->field_valid & 2)) {
363 aec62xx_tune_drive(drive, 5);
364 return hwif->ide_dma_off_quietly(drive);
366 /* IORDY not supported */
370 static int aec62xx_irq_timeout (ide_drive_t *drive)
372 ide_hwif_t *hwif = HWIF(drive);
373 struct pci_dev *dev = hwif->pci_dev;
375 switch(dev->device) {
376 case PCI_DEVICE_ID_ARTOP_ATP860:
377 case PCI_DEVICE_ID_ARTOP_ATP860R:
378 case PCI_DEVICE_ID_ARTOP_ATP865:
379 case PCI_DEVICE_ID_ARTOP_ATP865R:
380 printk(" AEC62XX time out ");
385 pci_read_config_byte(HWIF(drive)->pci_dev, 0x49, ®49h);
387 pci_write_config_byte(HWIF(drive)->pci_dev, 0x49, reg49h|0x10);
388 pci_write_config_byte(HWIF(drive)->pci_dev, 0x49, reg49h & ~0x10);
397 ide_hwif_t *hwif = HWIF(drive);
398 struct pci_dev *dev = hwif->pci_dev;
399 u8 tmp1 = 0, tmp2 = 0, mode6 = 0;
401 pci_read_config_byte(dev, 0x44, &tmp1);
402 pci_read_config_byte(dev, 0x45, &tmp2);
403 printk(" AEC6280 r44=%x r45=%x ",tmp1,tmp2);
404 mode6 = HWIF(drive)->INB(((hwif->channel) ?
405 hwif->mate->dma_status :
407 printk(" AEC6280 133=%x ", (mode6 & 0x10));
413 static unsigned int __init init_chipset_aec62xx (struct pci_dev *dev, const char *name)
415 int bus_speed = system_bus_clock();
417 if (dev->resource[PCI_ROM_RESOURCE].start) {
418 pci_write_config_dword(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
419 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, dev->resource[PCI_ROM_RESOURCE].start);
422 #if defined(DISPLAY_AEC62XX_TIMINGS) && defined(CONFIG_PROC_FS)
423 aec_devs[n_aec_devs++] = dev;
427 ide_pci_register_host_proc(&aec62xx_procs[0]);
429 #endif /* DISPLAY_AEC62XX_TIMINGS && CONFIG_PROC_FS */
432 pci_set_drvdata(dev, (void *) aec6xxx_33_base);
434 pci_set_drvdata(dev, (void *) aec6xxx_34_base);
439 static void __init init_hwif_aec62xx (ide_hwif_t *hwif)
442 hwif->tuneproc = &aec62xx_tune_drive;
443 hwif->speedproc = &aec62xx_tune_chipset;
445 if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
446 hwif->serialized = hwif->channel;
451 hwif->mate->serialized = hwif->serialized;
453 if (!hwif->dma_base) {
454 hwif->drives[0].autotune = 1;
455 hwif->drives[1].autotune = 1;
459 hwif->ultra_mask = 0x7f;
460 hwif->mwdma_mask = 0x07;
461 hwif->swdma_mask = 0x07;
463 hwif->ide_dma_check = &aec62xx_config_drive_xfer_rate;
464 hwif->ide_dma_lostirq = &aec62xx_irq_timeout;
465 hwif->ide_dma_timeout = &aec62xx_irq_timeout;
468 hwif->drives[0].autodma = hwif->autodma;
469 hwif->drives[1].autodma = hwif->autodma;
472 static void __init init_dma_aec62xx (ide_hwif_t *hwif, unsigned long dmabase)
474 struct pci_dev *dev = hwif->pci_dev;
476 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
480 spin_lock_irqsave(&ide_lock, flags);
481 pci_read_config_byte(dev, 0x54, ®54h);
482 pci_write_config_byte(dev, 0x54, reg54h & ~(hwif->channel ? 0xF0 : 0x0F));
483 spin_unlock_irqrestore(&ide_lock, flags);
486 pci_read_config_byte(hwif->pci_dev, 0x49, &ata66);
487 if (!(hwif->udma_four))
488 hwif->udma_four = (ata66&(hwif->channel?0x02:0x01))?0:1;
491 ide_setup_dma(hwif, dmabase, 8);
494 extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);
496 static void __init init_setup_aec62xx (struct pci_dev *dev, ide_pci_device_t *d)
498 ide_setup_pci_device(dev, d);
501 static void __init init_setup_aec6x80 (struct pci_dev *dev, ide_pci_device_t *d)
503 unsigned long bar4reg = pci_resource_start(dev, 4);
505 if (inb(bar4reg+2) & 0x10) {
506 strcpy(d->name, "AEC6880");
507 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R)
508 strcpy(d->name, "AEC6880R");
510 strcpy(d->name, "AEC6280");
511 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R)
512 strcpy(d->name, "AEC6280R");
515 ide_setup_pci_device(dev, d);
519 * aec62xx_init_one - called when a AEC is found
520 * @dev: the aec62xx device
521 * @id: the matching pci id
523 * Called when the PCI registration layer (or the IDE initialization)
524 * finds a device matching our IDE device tables.
527 static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
529 ide_pci_device_t *d = &aec62xx_chipsets[id->driver_data];
531 if (dev->device != d->device)
533 d->init_setup(dev, d);
538 static struct pci_device_id aec62xx_pci_tbl[] __devinitdata = {
539 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
540 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
541 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
542 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
543 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
547 static struct pci_driver driver = {
548 .name = "AEC62xx IDE",
549 .id_table = aec62xx_pci_tbl,
550 .probe = aec62xx_init_one,
553 static int aec62xx_ide_init(void)
555 return ide_pci_register_driver(&driver);
558 static void aec62xx_ide_exit(void)
560 ide_pci_unregister_driver(&driver);
563 module_init(aec62xx_ide_init);
564 module_exit(aec62xx_ide_exit);
566 MODULE_AUTHOR("Andre Hedrick");
567 MODULE_DESCRIPTION("PCI driver module for ARTOP AEC62xx IDE");
568 MODULE_LICENSE("GPL");