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>
21 #if defined(DISPLAY_AEC62XX_TIMINGS) && defined(CONFIG_PROC_FS)
22 #include <linux/stat.h>
23 #include <linux/proc_fs.h>
25 static u8 aec62xx_proc
= 0;
27 #define AEC_MAX_DEVS 5
29 static struct pci_dev
*aec_devs
[AEC_MAX_DEVS
];
30 static int n_aec_devs
;
32 static int aec62xx_get_info (char *buffer
, char **addr
, off_t offset
, int count
)
35 char *chipset_nums
[] = {"error", "error", "error", "error",
36 "error", "error", "850UF", "860",
37 "860R", "865", "865R", "error" };
41 for (i
= 0; i
< n_aec_devs
; i
++) {
42 struct pci_dev
*dev
= aec_devs
[i
];
43 unsigned long iobase
= pci_resource_start(dev
, 4);
44 u8 c0
= 0, c1
= 0, art
= 0;
46 c0
= inb(iobase
+ 0x02);
47 c1
= inb(iobase
+ 0x0a);
49 p
+= sprintf(p
, "\nController: %d\n", i
);
50 p
+= sprintf(p
, "Chipset: AEC%s\n", chipset_nums
[dev
->device
]);
52 p
+= sprintf(p
, "--------------- Primary Channel "
53 "---------------- Secondary Channel "
55 (void) pci_read_config_byte(dev
, 0x4a, &art
);
56 p
+= sprintf(p
, " %sabled ",
57 (art
&0x02)?" en":"dis");
58 p
+= sprintf(p
, " %sabled\n",
59 (art
&0x04)?" en":"dis");
60 p
+= sprintf(p
, "--------------- drive0 --------- drive1 "
61 "-------- drive0 ---------- drive1 ------\n");
62 p
+= sprintf(p
, "DMA enabled: %s %s ",
63 (c0
&0x20)?"yes":"no ",(c0
&0x40)?"yes":"no ");
64 p
+= sprintf(p
, " %s %s\n",
65 (c1
&0x20)?"yes":"no ",(c1
&0x40)?"yes":"no ");
67 if (dev
->device
== PCI_DEVICE_ID_ARTOP_ATP850UF
) {
68 (void) pci_read_config_byte(dev
, 0x54, &art
);
69 p
+= sprintf(p
, "DMA Mode: %s(%s)",
70 (c0
&0x20)?((art
&0x03)?"UDMA":" DMA"):" PIO",
71 (art
&0x02)?"2":(art
&0x01)?"1":"0");
72 p
+= sprintf(p
, " %s(%s)",
73 (c0
&0x40)?((art
&0x0c)?"UDMA":" DMA"):" PIO",
74 (art
&0x08)?"2":(art
&0x04)?"1":"0");
75 p
+= sprintf(p
, " %s(%s)",
76 (c1
&0x20)?((art
&0x30)?"UDMA":" DMA"):" PIO",
77 (art
&0x20)?"2":(art
&0x10)?"1":"0");
78 p
+= sprintf(p
, " %s(%s)\n",
79 (c1
&0x40)?((art
&0xc0)?"UDMA":" DMA"):" PIO",
80 (art
&0x80)?"2":(art
&0x40)?"1":"0");
83 * case PCI_DEVICE_ID_ARTOP_ATP860:
84 * case PCI_DEVICE_ID_ARTOP_ATP860R:
85 * case PCI_DEVICE_ID_ARTOP_ATP865:
86 * case PCI_DEVICE_ID_ARTOP_ATP865R:
88 (void) pci_read_config_byte(dev
, 0x44, &art
);
89 p
+= sprintf(p
, "DMA Mode: %s(%s)",
90 (c0
&0x20)?((art
&0x07)?"UDMA":" DMA"):" PIO",
91 ((art
&0x07)==0x07)?"6":
92 ((art
&0x06)==0x06)?"5":
93 ((art
&0x05)==0x05)?"4":
94 ((art
&0x04)==0x04)?"3":
95 ((art
&0x03)==0x03)?"2":
96 ((art
&0x02)==0x02)?"1":
97 ((art
&0x01)==0x01)?"0":"?");
98 p
+= sprintf(p
, " %s(%s)",
99 (c0
&0x40)?((art
&0x70)?"UDMA":" DMA"):" PIO",
100 ((art
&0x70)==0x70)?"6":
101 ((art
&0x60)==0x60)?"5":
102 ((art
&0x50)==0x50)?"4":
103 ((art
&0x40)==0x40)?"3":
104 ((art
&0x30)==0x30)?"2":
105 ((art
&0x20)==0x20)?"1":
106 ((art
&0x10)==0x10)?"0":"?");
107 (void) pci_read_config_byte(dev
, 0x45, &art
);
108 p
+= sprintf(p
, " %s(%s)",
109 (c1
&0x20)?((art
&0x07)?"UDMA":" DMA"):" PIO",
110 ((art
&0x07)==0x07)?"6":
111 ((art
&0x06)==0x06)?"5":
112 ((art
&0x05)==0x05)?"4":
113 ((art
&0x04)==0x04)?"3":
114 ((art
&0x03)==0x03)?"2":
115 ((art
&0x02)==0x02)?"1":
116 ((art
&0x01)==0x01)?"0":"?");
117 p
+= sprintf(p
, " %s(%s)\n",
118 (c1
&0x40)?((art
&0x70)?"UDMA":" DMA"):" PIO",
119 ((art
&0x70)==0x70)?"6":
120 ((art
&0x60)==0x60)?"5":
121 ((art
&0x50)==0x50)?"4":
122 ((art
&0x40)==0x40)?"3":
123 ((art
&0x30)==0x30)?"2":
124 ((art
&0x20)==0x20)?"1":
125 ((art
&0x10)==0x10)?"0":"?");
128 /* p - buffer must be less than 4k! */
129 len
= (p
- buffer
) - offset
;
130 *addr
= buffer
+ offset
;
132 return len
> count
? count
: len
;
134 #endif /* defined(DISPLAY_AEC62xx_TIMINGS) && defined(CONFIG_PROC_FS) */
137 * TO DO: active tuning and correction of cards without a bios.
139 static u8
pci_bus_clock_list (u8 speed
, struct chipset_bus_clock_list_entry
* chipset_table
)
141 for ( ; chipset_table
->xfer_speed
; chipset_table
++)
142 if (chipset_table
->xfer_speed
== speed
) {
143 return chipset_table
->chipset_settings
;
145 return chipset_table
->chipset_settings
;
148 static u8
pci_bus_clock_list_ultra (u8 speed
, struct chipset_bus_clock_list_entry
* chipset_table
)
150 for ( ; chipset_table
->xfer_speed
; chipset_table
++)
151 if (chipset_table
->xfer_speed
== speed
) {
152 return chipset_table
->ultra_settings
;
154 return chipset_table
->ultra_settings
;
157 static u8
aec62xx_ratemask (ide_drive_t
*drive
)
159 ide_hwif_t
*hwif
= HWIF(drive
);
162 switch(hwif
->pci_dev
->device
) {
163 case PCI_DEVICE_ID_ARTOP_ATP865
:
164 case PCI_DEVICE_ID_ARTOP_ATP865R
:
166 mode
= (hwif
->INB(hwif
->dma_master
) & 0x10) ? 4 : 3;
168 mode
= (hwif
->INB(((hwif
->channel
) ?
169 hwif
->mate
->dma_status
:
170 hwif
->dma_status
)) & 0x10) ? 4 : 3;
173 case PCI_DEVICE_ID_ARTOP_ATP860
:
174 case PCI_DEVICE_ID_ARTOP_ATP860R
:
177 case PCI_DEVICE_ID_ARTOP_ATP850UF
:
182 if (!eighty_ninty_three(drive
))
183 mode
= min(mode
, (u8
)1);
187 static int aec6210_tune_chipset (ide_drive_t
*drive
, u8 xferspeed
)
189 ide_hwif_t
*hwif
= HWIF(drive
);
190 struct pci_dev
*dev
= hwif
->pci_dev
;
192 u8 speed
= ide_rate_filter(aec62xx_ratemask(drive
), xferspeed
);
193 u8 ultra
= 0, ultra_conf
= 0;
194 u8 tmp0
= 0, tmp1
= 0, tmp2
= 0;
197 local_irq_save(flags
);
198 /* 0x40|(2*drive->dn): Active, 0x41|(2*drive->dn): Recovery */
199 pci_read_config_word(dev
, 0x40|(2*drive
->dn
), &d_conf
);
200 tmp0
= pci_bus_clock_list(speed
, BUSCLOCK(dev
));
201 SPLIT_BYTE(tmp0
,tmp1
,tmp2
);
202 MAKE_WORD(d_conf
,tmp1
,tmp2
);
203 pci_write_config_word(dev
, 0x40|(2*drive
->dn
), d_conf
);
207 pci_read_config_byte(dev
, 0x54, &ultra
);
208 tmp1
= ((0x00 << (2*drive
->dn
)) | (ultra
& ~(3 << (2*drive
->dn
))));
209 ultra_conf
= pci_bus_clock_list_ultra(speed
, BUSCLOCK(dev
));
210 tmp2
= ((ultra_conf
<< (2*drive
->dn
)) | (tmp1
& ~(3 << (2*drive
->dn
))));
211 pci_write_config_byte(dev
, 0x54, tmp2
);
212 local_irq_restore(flags
);
213 return(ide_config_drive_speed(drive
, speed
));
216 static int aec6260_tune_chipset (ide_drive_t
*drive
, u8 xferspeed
)
218 ide_hwif_t
*hwif
= HWIF(drive
);
219 struct pci_dev
*dev
= hwif
->pci_dev
;
220 u8 speed
= ide_rate_filter(aec62xx_ratemask(drive
), xferspeed
);
221 u8 unit
= (drive
->select
.b
.unit
& 0x01);
222 u8 tmp1
= 0, tmp2
= 0;
223 u8 ultra
= 0, drive_conf
= 0, ultra_conf
= 0;
226 local_irq_save(flags
);
227 /* high 4-bits: Active, low 4-bits: Recovery */
228 pci_read_config_byte(dev
, 0x40|drive
->dn
, &drive_conf
);
229 drive_conf
= pci_bus_clock_list(speed
, BUSCLOCK(dev
));
230 pci_write_config_byte(dev
, 0x40|drive
->dn
, drive_conf
);
232 pci_read_config_byte(dev
, (0x44|hwif
->channel
), &ultra
);
233 tmp1
= ((0x00 << (4*unit
)) | (ultra
& ~(7 << (4*unit
))));
234 ultra_conf
= pci_bus_clock_list_ultra(speed
, BUSCLOCK(dev
));
235 tmp2
= ((ultra_conf
<< (4*unit
)) | (tmp1
& ~(7 << (4*unit
))));
236 pci_write_config_byte(dev
, (0x44|hwif
->channel
), tmp2
);
237 local_irq_restore(flags
);
238 return(ide_config_drive_speed(drive
, speed
));
241 static int aec62xx_tune_chipset (ide_drive_t
*drive
, u8 speed
)
243 switch (HWIF(drive
)->pci_dev
->device
) {
244 case PCI_DEVICE_ID_ARTOP_ATP865
:
245 case PCI_DEVICE_ID_ARTOP_ATP865R
:
246 case PCI_DEVICE_ID_ARTOP_ATP860
:
247 case PCI_DEVICE_ID_ARTOP_ATP860R
:
248 return ((int) aec6260_tune_chipset(drive
, speed
));
249 case PCI_DEVICE_ID_ARTOP_ATP850UF
:
250 return ((int) aec6210_tune_chipset(drive
, speed
));
256 static int config_chipset_for_dma (ide_drive_t
*drive
)
258 u8 speed
= ide_dma_speed(drive
, aec62xx_ratemask(drive
));
263 (void) aec62xx_tune_chipset(drive
, speed
);
264 return ide_dma_enable(drive
);
267 static void aec62xx_tune_drive (ide_drive_t
*drive
, u8 pio
)
270 u8 new_pio
= XFER_PIO_0
+ ide_get_best_pio_mode(drive
, 255, 5, NULL
);
273 case 5: speed
= new_pio
; break;
274 case 4: speed
= XFER_PIO_4
; break;
275 case 3: speed
= XFER_PIO_3
; break;
276 case 2: speed
= XFER_PIO_2
; break;
277 case 1: speed
= XFER_PIO_1
; break;
278 default: speed
= XFER_PIO_0
; break;
280 (void) aec62xx_tune_chipset(drive
, speed
);
283 static int aec62xx_config_drive_xfer_rate (ide_drive_t
*drive
)
285 ide_hwif_t
*hwif
= HWIF(drive
);
286 struct hd_driveid
*id
= drive
->id
;
288 if ((id
->capability
& 1) && drive
->autodma
) {
289 /* Consult the list of known "bad" drives */
290 if (__ide_dma_bad_drive(drive
))
292 if (id
->field_valid
& 4) {
293 if (id
->dma_ultra
& hwif
->ultra_mask
) {
294 /* Force if Capable UltraDMA */
295 int dma
= config_chipset_for_dma(drive
);
296 if ((id
->field_valid
& 2) && !dma
)
299 } else if (id
->field_valid
& 2) {
301 if ((id
->dma_mword
& hwif
->mwdma_mask
) ||
302 (id
->dma_1word
& hwif
->swdma_mask
)) {
303 /* Force if Capable regular DMA modes */
304 if (!config_chipset_for_dma(drive
))
307 } else if (__ide_dma_good_drive(drive
) &&
308 (id
->eide_dma_time
< 150)) {
309 /* Consult the list of known "good" drives */
310 if (!config_chipset_for_dma(drive
))
315 return hwif
->ide_dma_on(drive
);
316 } else if ((id
->capability
& 8) || (id
->field_valid
& 2)) {
319 aec62xx_tune_drive(drive
, 5);
320 return hwif
->ide_dma_off_quietly(drive
);
322 /* IORDY not supported */
326 static int aec62xx_irq_timeout (ide_drive_t
*drive
)
328 ide_hwif_t
*hwif
= HWIF(drive
);
329 struct pci_dev
*dev
= hwif
->pci_dev
;
331 switch(dev
->device
) {
332 case PCI_DEVICE_ID_ARTOP_ATP860
:
333 case PCI_DEVICE_ID_ARTOP_ATP860R
:
334 case PCI_DEVICE_ID_ARTOP_ATP865
:
335 case PCI_DEVICE_ID_ARTOP_ATP865R
:
336 printk(" AEC62XX time out ");
341 pci_read_config_byte(HWIF(drive
)->pci_dev
, 0x49, ®49h
);
343 pci_write_config_byte(HWIF(drive
)->pci_dev
, 0x49, reg49h
|0x10);
344 pci_write_config_byte(HWIF(drive
)->pci_dev
, 0x49, reg49h
& ~0x10);
353 ide_hwif_t
*hwif
= HWIF(drive
);
354 struct pci_dev
*dev
= hwif
->pci_dev
;
355 u8 tmp1
= 0, tmp2
= 0, mode6
= 0;
357 pci_read_config_byte(dev
, 0x44, &tmp1
);
358 pci_read_config_byte(dev
, 0x45, &tmp2
);
359 printk(" AEC6280 r44=%x r45=%x ",tmp1
,tmp2
);
360 mode6
= HWIF(drive
)->INB(((hwif
->channel
) ?
361 hwif
->mate
->dma_status
:
363 printk(" AEC6280 133=%x ", (mode6
& 0x10));
369 static unsigned int __devinit
init_chipset_aec62xx(struct pci_dev
*dev
, const char *name
)
371 int bus_speed
= system_bus_clock();
373 if (dev
->resource
[PCI_ROM_RESOURCE
].start
) {
374 pci_write_config_dword(dev
, PCI_ROM_ADDRESS
, dev
->resource
[PCI_ROM_RESOURCE
].start
| PCI_ROM_ADDRESS_ENABLE
);
375 printk(KERN_INFO
"%s: ROM enabled at 0x%08lx\n", name
, dev
->resource
[PCI_ROM_RESOURCE
].start
);
378 #if defined(DISPLAY_AEC62XX_TIMINGS) && defined(CONFIG_PROC_FS)
379 aec_devs
[n_aec_devs
++] = dev
;
383 ide_pci_create_host_proc("aec62xx", aec62xx_get_info
);
385 #endif /* DISPLAY_AEC62XX_TIMINGS && CONFIG_PROC_FS */
388 pci_set_drvdata(dev
, (void *) aec6xxx_33_base
);
390 pci_set_drvdata(dev
, (void *) aec6xxx_34_base
);
395 static void __devinit
init_hwif_aec62xx(ide_hwif_t
*hwif
)
398 hwif
->tuneproc
= &aec62xx_tune_drive
;
399 hwif
->speedproc
= &aec62xx_tune_chipset
;
401 if (hwif
->pci_dev
->device
== PCI_DEVICE_ID_ARTOP_ATP850UF
) {
402 hwif
->serialized
= hwif
->channel
;
407 hwif
->mate
->serialized
= hwif
->serialized
;
409 if (!hwif
->dma_base
) {
410 hwif
->drives
[0].autotune
= 1;
411 hwif
->drives
[1].autotune
= 1;
415 hwif
->ultra_mask
= 0x7f;
416 hwif
->mwdma_mask
= 0x07;
417 hwif
->swdma_mask
= 0x07;
419 hwif
->ide_dma_check
= &aec62xx_config_drive_xfer_rate
;
420 hwif
->ide_dma_lostirq
= &aec62xx_irq_timeout
;
421 hwif
->ide_dma_timeout
= &aec62xx_irq_timeout
;
424 hwif
->drives
[0].autodma
= hwif
->autodma
;
425 hwif
->drives
[1].autodma
= hwif
->autodma
;
428 static void __devinit
init_dma_aec62xx(ide_hwif_t
*hwif
, unsigned long dmabase
)
430 struct pci_dev
*dev
= hwif
->pci_dev
;
432 if (dev
->device
== PCI_DEVICE_ID_ARTOP_ATP850UF
) {
436 spin_lock_irqsave(&ide_lock
, flags
);
437 pci_read_config_byte(dev
, 0x54, ®54h
);
438 pci_write_config_byte(dev
, 0x54, reg54h
& ~(hwif
->channel
? 0xF0 : 0x0F));
439 spin_unlock_irqrestore(&ide_lock
, flags
);
442 pci_read_config_byte(hwif
->pci_dev
, 0x49, &ata66
);
443 if (!(hwif
->udma_four
))
444 hwif
->udma_four
= (ata66
&(hwif
->channel
?0x02:0x01))?0:1;
447 ide_setup_dma(hwif
, dmabase
, 8);
450 static void __devinit
init_setup_aec62xx(struct pci_dev
*dev
, ide_pci_device_t
*d
)
452 ide_setup_pci_device(dev
, d
);
455 static void __devinit
init_setup_aec6x80(struct pci_dev
*dev
, ide_pci_device_t
*d
)
457 unsigned long bar4reg
= pci_resource_start(dev
, 4);
459 if (inb(bar4reg
+2) & 0x10) {
460 strcpy(d
->name
, "AEC6880");
461 if (dev
->device
== PCI_DEVICE_ID_ARTOP_ATP865R
)
462 strcpy(d
->name
, "AEC6880R");
464 strcpy(d
->name
, "AEC6280");
465 if (dev
->device
== PCI_DEVICE_ID_ARTOP_ATP865R
)
466 strcpy(d
->name
, "AEC6280R");
469 ide_setup_pci_device(dev
, d
);
473 * aec62xx_init_one - called when a AEC is found
474 * @dev: the aec62xx device
475 * @id: the matching pci id
477 * Called when the PCI registration layer (or the IDE initialization)
478 * finds a device matching our IDE device tables.
481 static int __devinit
aec62xx_init_one(struct pci_dev
*dev
, const struct pci_device_id
*id
)
483 ide_pci_device_t
*d
= &aec62xx_chipsets
[id
->driver_data
];
485 d
->init_setup(dev
, d
);
489 static struct pci_device_id aec62xx_pci_tbl
[] = {
490 { PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_ATP850UF
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
491 { PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_ATP860
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
492 { PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_ATP860R
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2 },
493 { PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_ATP865
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 3 },
494 { PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_ATP865R
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 4 },
497 MODULE_DEVICE_TABLE(pci
, aec62xx_pci_tbl
);
499 static struct pci_driver driver
= {
500 .name
= "AEC62xx_IDE",
501 .id_table
= aec62xx_pci_tbl
,
502 .probe
= aec62xx_init_one
,
505 static int aec62xx_ide_init(void)
507 return ide_pci_register_driver(&driver
);
510 module_init(aec62xx_ide_init
);
512 MODULE_AUTHOR("Andre Hedrick");
513 MODULE_DESCRIPTION("PCI driver module for ARTOP AEC62xx IDE");
514 MODULE_LICENSE("GPL");