2 * linux/drivers/ide/pci/hpt366.c Version 0.36 April 25, 2003
4 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
5 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
6 * Portions Copyright (C) 2003 Red Hat Inc
8 * Thanks to HighPoint Technologies for their assistance, and hardware.
9 * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his
10 * donation of an ABit BP6 mainboard, processor, and memory acellerated
11 * development and support.
14 * Highpoint have their own driver (source except for the raid part)
15 * available from http://www.highpoint-tech.com/hpt3xx-opensource-v131.tgz
16 * This may be useful to anyone wanting to work on the mainstream hpt IDE.
18 * Note that final HPT370 support was done by force extraction of GPL.
20 * - add function for getting/setting power status of drive
21 * - the HPT370's state machine can get confused. reset it before each dma
22 * xfer to prevent that from happening.
23 * - reset state engine whenever we get an error.
24 * - check for busmaster state at end of dma.
25 * - use new highpoint timings.
26 * - detect bus speed using highpoint register.
27 * - use pll if we don't have a clock table. added a 66MHz table that's
28 * just 2x the 33MHz table.
29 * - removed turnaround. NOTE: we never want to switch between pll and
30 * pci clocks as the chip can glitch in those cases. the highpoint
31 * approved workaround slows everything down too much to be useful. in
32 * addition, we would have to serialize access to each chip.
33 * Adrian Sun <a.sun@sun.com>
35 * add drive timings for 66MHz PCI bus,
36 * fix ATA Cable signal detection, fix incorrect /proc info
37 * add /proc display for per-drive PIO/DMA/UDMA mode and
38 * per-channel ATA-33/66 Cable detect.
39 * Duncan Laurie <void@sun.com>
41 * fixup /proc output for multiple controllers
42 * Tim Hockin <thockin@sun.com>
45 * Reset the hpt366 on error, reset on dma
46 * Fix disabling Fast Interrupt hpt366.
47 * Mike Waychison <crlf@sun.com>
49 * Added support for 372N clocking and clock switching. The 372N needs
50 * different clocks on read/write. This requires overloading rw_disk and
51 * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for
53 * Alan Cox <alan@redhat.com>
58 #include <linux/types.h>
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/delay.h>
62 #include <linux/timer.h>
64 #include <linux/ioport.h>
65 #include <linux/blkdev.h>
66 #include <linux/hdreg.h>
68 #include <linux/interrupt.h>
69 #include <linux/pci.h>
70 #include <linux/init.h>
71 #include <linux/ide.h>
73 #include <asm/uaccess.h>
77 /* various tuning parameters */
78 #define HPT_RESET_STATE_ENGINE
79 #undef HPT_DELAY_INTERRUPT
80 #undef HPT_SERIALIZE_IO
82 static const char *quirk_drives[] = {
83 "QUANTUM FIREBALLlct08 08",
84 "QUANTUM FIREBALLP KA6.4",
85 "QUANTUM FIREBALLP LM20.4",
86 "QUANTUM FIREBALLP LM20.5",
90 static const char *bad_ata100_5[] = {
109 static const char *bad_ata66_4[] = {
128 static const char *bad_ata66_3[] = {
133 static const char *bad_ata33[] = {
134 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2",
135 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
136 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
138 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
139 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
140 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
144 struct chipset_bus_clock_list_entry {
146 unsigned int chipset_settings;
149 /* key for bus clock timings
151 * 0:3 data_high_time. inactive time of DIOW_/DIOR_ for PIO and MW
152 * DMA. cycles = value + 1
153 * 4:8 data_low_time. active time of DIOW_/DIOR_ for PIO and MW
154 * DMA. cycles = value + 1
155 * 9:12 cmd_high_time. inactive time of DIOW_/DIOR_ during task file
157 * 13:17 cmd_low_time. active time of DIOW_/DIOR_ during task file
159 * 18:21 udma_cycle_time. clock freq and clock cycles for UDMA xfer.
160 * during task file register access.
161 * 22:24 pre_high_time. time to initialize 1st cycle for PIO and MW DMA
163 * 25:27 cmd_pre_high_time. time to initialize 1st PIO cycle for task
167 * 30 PIO_MST enable. if set, the chip is in bus master mode during
171 static struct chipset_bus_clock_list_entry forty_base_hpt366[] = {
172 { XFER_UDMA_4, 0x900fd943 },
173 { XFER_UDMA_3, 0x900ad943 },
174 { XFER_UDMA_2, 0x900bd943 },
175 { XFER_UDMA_1, 0x9008d943 },
176 { XFER_UDMA_0, 0x9008d943 },
178 { XFER_MW_DMA_2, 0xa008d943 },
179 { XFER_MW_DMA_1, 0xa010d955 },
180 { XFER_MW_DMA_0, 0xa010d9fc },
182 { XFER_PIO_4, 0xc008d963 },
183 { XFER_PIO_3, 0xc010d974 },
184 { XFER_PIO_2, 0xc010d997 },
185 { XFER_PIO_1, 0xc010d9c7 },
186 { XFER_PIO_0, 0xc018d9d9 },
190 static struct chipset_bus_clock_list_entry thirty_three_base_hpt366[] = {
191 { XFER_UDMA_4, 0x90c9a731 },
192 { XFER_UDMA_3, 0x90cfa731 },
193 { XFER_UDMA_2, 0x90caa731 },
194 { XFER_UDMA_1, 0x90cba731 },
195 { XFER_UDMA_0, 0x90c8a731 },
197 { XFER_MW_DMA_2, 0xa0c8a731 },
198 { XFER_MW_DMA_1, 0xa0c8a732 }, /* 0xa0c8a733 */
199 { XFER_MW_DMA_0, 0xa0c8a797 },
201 { XFER_PIO_4, 0xc0c8a731 },
202 { XFER_PIO_3, 0xc0c8a742 },
203 { XFER_PIO_2, 0xc0d0a753 },
204 { XFER_PIO_1, 0xc0d0a7a3 }, /* 0xc0d0a793 */
205 { XFER_PIO_0, 0xc0d0a7aa }, /* 0xc0d0a7a7 */
209 static struct chipset_bus_clock_list_entry twenty_five_base_hpt366[] = {
210 { XFER_UDMA_4, 0x90c98521 },
211 { XFER_UDMA_3, 0x90cf8521 },
212 { XFER_UDMA_2, 0x90cf8521 },
213 { XFER_UDMA_1, 0x90cb8521 },
214 { XFER_UDMA_0, 0x90cb8521 },
216 { XFER_MW_DMA_2, 0xa0ca8521 },
217 { XFER_MW_DMA_1, 0xa0ca8532 },
218 { XFER_MW_DMA_0, 0xa0ca8575 },
220 { XFER_PIO_4, 0xc0ca8521 },
221 { XFER_PIO_3, 0xc0ca8532 },
222 { XFER_PIO_2, 0xc0ca8542 },
223 { XFER_PIO_1, 0xc0d08572 },
224 { XFER_PIO_0, 0xc0d08585 },
228 /* from highpoint documentation. these are old values */
229 static struct chipset_bus_clock_list_entry thirty_three_base_hpt370[] = {
230 /* { XFER_UDMA_5, 0x1A85F442, 0x16454e31 }, */
231 { XFER_UDMA_5, 0x16454e31 },
232 { XFER_UDMA_4, 0x16454e31 },
233 { XFER_UDMA_3, 0x166d4e31 },
234 { XFER_UDMA_2, 0x16494e31 },
235 { XFER_UDMA_1, 0x164d4e31 },
236 { XFER_UDMA_0, 0x16514e31 },
238 { XFER_MW_DMA_2, 0x26514e21 },
239 { XFER_MW_DMA_1, 0x26514e33 },
240 { XFER_MW_DMA_0, 0x26514e97 },
242 { XFER_PIO_4, 0x06514e21 },
243 { XFER_PIO_3, 0x06514e22 },
244 { XFER_PIO_2, 0x06514e33 },
245 { XFER_PIO_1, 0x06914e43 },
246 { XFER_PIO_0, 0x06914e57 },
250 static struct chipset_bus_clock_list_entry sixty_six_base_hpt370[] = {
251 { XFER_UDMA_5, 0x14846231 },
252 { XFER_UDMA_4, 0x14886231 },
253 { XFER_UDMA_3, 0x148c6231 },
254 { XFER_UDMA_2, 0x148c6231 },
255 { XFER_UDMA_1, 0x14906231 },
256 { XFER_UDMA_0, 0x14986231 },
258 { XFER_MW_DMA_2, 0x26514e21 },
259 { XFER_MW_DMA_1, 0x26514e33 },
260 { XFER_MW_DMA_0, 0x26514e97 },
262 { XFER_PIO_4, 0x06514e21 },
263 { XFER_PIO_3, 0x06514e22 },
264 { XFER_PIO_2, 0x06514e33 },
265 { XFER_PIO_1, 0x06914e43 },
266 { XFER_PIO_0, 0x06914e57 },
270 /* these are the current (4 sep 2001) timings from highpoint */
271 static struct chipset_bus_clock_list_entry thirty_three_base_hpt370a[] = {
272 { XFER_UDMA_5, 0x12446231 },
273 { XFER_UDMA_4, 0x12446231 },
274 { XFER_UDMA_3, 0x126c6231 },
275 { XFER_UDMA_2, 0x12486231 },
276 { XFER_UDMA_1, 0x124c6233 },
277 { XFER_UDMA_0, 0x12506297 },
279 { XFER_MW_DMA_2, 0x22406c31 },
280 { XFER_MW_DMA_1, 0x22406c33 },
281 { XFER_MW_DMA_0, 0x22406c97 },
283 { XFER_PIO_4, 0x06414e31 },
284 { XFER_PIO_3, 0x06414e42 },
285 { XFER_PIO_2, 0x06414e53 },
286 { XFER_PIO_1, 0x06814e93 },
287 { XFER_PIO_0, 0x06814ea7 },
291 /* 2x 33MHz timings */
292 static struct chipset_bus_clock_list_entry sixty_six_base_hpt370a[] = {
293 { XFER_UDMA_5, 0x1488e673 },
294 { XFER_UDMA_4, 0x1488e673 },
295 { XFER_UDMA_3, 0x1498e673 },
296 { XFER_UDMA_2, 0x1490e673 },
297 { XFER_UDMA_1, 0x1498e677 },
298 { XFER_UDMA_0, 0x14a0e73f },
300 { XFER_MW_DMA_2, 0x2480fa73 },
301 { XFER_MW_DMA_1, 0x2480fa77 },
302 { XFER_MW_DMA_0, 0x2480fb3f },
304 { XFER_PIO_4, 0x0c82be73 },
305 { XFER_PIO_3, 0x0c82be95 },
306 { XFER_PIO_2, 0x0c82beb7 },
307 { XFER_PIO_1, 0x0d02bf37 },
308 { XFER_PIO_0, 0x0d02bf5f },
312 static struct chipset_bus_clock_list_entry fifty_base_hpt370a[] = {
313 { XFER_UDMA_5, 0x12848242 },
314 { XFER_UDMA_4, 0x12ac8242 },
315 { XFER_UDMA_3, 0x128c8242 },
316 { XFER_UDMA_2, 0x120c8242 },
317 { XFER_UDMA_1, 0x12148254 },
318 { XFER_UDMA_0, 0x121882ea },
320 { XFER_MW_DMA_2, 0x22808242 },
321 { XFER_MW_DMA_1, 0x22808254 },
322 { XFER_MW_DMA_0, 0x228082ea },
324 { XFER_PIO_4, 0x0a81f442 },
325 { XFER_PIO_3, 0x0a81f443 },
326 { XFER_PIO_2, 0x0a81f454 },
327 { XFER_PIO_1, 0x0ac1f465 },
328 { XFER_PIO_0, 0x0ac1f48a },
332 static struct chipset_bus_clock_list_entry thirty_three_base_hpt372[] = {
333 { XFER_UDMA_6, 0x1c81dc62 },
334 { XFER_UDMA_5, 0x1c6ddc62 },
335 { XFER_UDMA_4, 0x1c8ddc62 },
336 { XFER_UDMA_3, 0x1c8edc62 }, /* checkme */
337 { XFER_UDMA_2, 0x1c91dc62 },
338 { XFER_UDMA_1, 0x1c9adc62 }, /* checkme */
339 { XFER_UDMA_0, 0x1c82dc62 }, /* checkme */
341 { XFER_MW_DMA_2, 0x2c829262 },
342 { XFER_MW_DMA_1, 0x2c829266 }, /* checkme */
343 { XFER_MW_DMA_0, 0x2c82922e }, /* checkme */
345 { XFER_PIO_4, 0x0c829c62 },
346 { XFER_PIO_3, 0x0c829c84 },
347 { XFER_PIO_2, 0x0c829ca6 },
348 { XFER_PIO_1, 0x0d029d26 },
349 { XFER_PIO_0, 0x0d029d5e },
353 static struct chipset_bus_clock_list_entry fifty_base_hpt372[] = {
354 { XFER_UDMA_5, 0x12848242 },
355 { XFER_UDMA_4, 0x12ac8242 },
356 { XFER_UDMA_3, 0x128c8242 },
357 { XFER_UDMA_2, 0x120c8242 },
358 { XFER_UDMA_1, 0x12148254 },
359 { XFER_UDMA_0, 0x121882ea },
361 { XFER_MW_DMA_2, 0x22808242 },
362 { XFER_MW_DMA_1, 0x22808254 },
363 { XFER_MW_DMA_0, 0x228082ea },
365 { XFER_PIO_4, 0x0a81f442 },
366 { XFER_PIO_3, 0x0a81f443 },
367 { XFER_PIO_2, 0x0a81f454 },
368 { XFER_PIO_1, 0x0ac1f465 },
369 { XFER_PIO_0, 0x0ac1f48a },
373 static struct chipset_bus_clock_list_entry sixty_six_base_hpt372[] = {
374 { XFER_UDMA_6, 0x1c869c62 },
375 { XFER_UDMA_5, 0x1cae9c62 },
376 { XFER_UDMA_4, 0x1c8a9c62 },
377 { XFER_UDMA_3, 0x1c8e9c62 },
378 { XFER_UDMA_2, 0x1c929c62 },
379 { XFER_UDMA_1, 0x1c9a9c62 },
380 { XFER_UDMA_0, 0x1c829c62 },
382 { XFER_MW_DMA_2, 0x2c829c62 },
383 { XFER_MW_DMA_1, 0x2c829c66 },
384 { XFER_MW_DMA_0, 0x2c829d2e },
386 { XFER_PIO_4, 0x0c829c62 },
387 { XFER_PIO_3, 0x0c829c84 },
388 { XFER_PIO_2, 0x0c829ca6 },
389 { XFER_PIO_1, 0x0d029d26 },
390 { XFER_PIO_0, 0x0d029d5e },
394 static struct chipset_bus_clock_list_entry thirty_three_base_hpt374[] = {
395 { XFER_UDMA_6, 0x12808242 },
396 { XFER_UDMA_5, 0x12848242 },
397 { XFER_UDMA_4, 0x12ac8242 },
398 { XFER_UDMA_3, 0x128c8242 },
399 { XFER_UDMA_2, 0x120c8242 },
400 { XFER_UDMA_1, 0x12148254 },
401 { XFER_UDMA_0, 0x121882ea },
403 { XFER_MW_DMA_2, 0x22808242 },
404 { XFER_MW_DMA_1, 0x22808254 },
405 { XFER_MW_DMA_0, 0x228082ea },
407 { XFER_PIO_4, 0x0a81f442 },
408 { XFER_PIO_3, 0x0a81f443 },
409 { XFER_PIO_2, 0x0a81f454 },
410 { XFER_PIO_1, 0x0ac1f465 },
411 { XFER_PIO_0, 0x0ac1f48a },
415 /* FIXME: 50MHz timings for HPT374 */
418 static struct chipset_bus_clock_list_entry sixty_six_base_hpt374[] = {
419 { XFER_UDMA_6, 0x12406231 }, /* checkme */
420 { XFER_UDMA_5, 0x12446231 }, /* 0x14846231 */
421 { XFER_UDMA_4, 0x16814ea7 }, /* 0x14886231 */
422 { XFER_UDMA_3, 0x16814ea7 }, /* 0x148c6231 */
423 { XFER_UDMA_2, 0x16814ea7 }, /* 0x148c6231 */
424 { XFER_UDMA_1, 0x16814ea7 }, /* 0x14906231 */
425 { XFER_UDMA_0, 0x16814ea7 }, /* 0x14986231 */
426 { XFER_MW_DMA_2, 0x16814ea7 }, /* 0x26514e21 */
427 { XFER_MW_DMA_1, 0x16814ea7 }, /* 0x26514e97 */
428 { XFER_MW_DMA_0, 0x16814ea7 }, /* 0x26514e97 */
429 { XFER_PIO_4, 0x06814ea7 }, /* 0x06514e21 */
430 { XFER_PIO_3, 0x06814ea7 }, /* 0x06514e22 */
431 { XFER_PIO_2, 0x06814ea7 }, /* 0x06514e33 */
432 { XFER_PIO_1, 0x06814ea7 }, /* 0x06914e43 */
433 { XFER_PIO_0, 0x06814ea7 }, /* 0x06914e57 */
438 #define HPT366_DEBUG_DRIVE_INFO 0
439 #define HPT374_ALLOW_ATA133_6 0
440 #define HPT371_ALLOW_ATA133_6 0
441 #define HPT302_ALLOW_ATA133_6 0
442 #define HPT372_ALLOW_ATA133_6 1
443 #define HPT370_ALLOW_ATA100_5 1
444 #define HPT366_ALLOW_ATA66_4 1
445 #define HPT366_ALLOW_ATA66_3 1
446 #define HPT366_MAX_DEVS 8
448 #define F_LOW_PCI_33 0x23
449 #define F_LOW_PCI_40 0x29
450 #define F_LOW_PCI_50 0x2d
451 #define F_LOW_PCI_66 0x42
454 * Hold all the highpoint quirks and revision information in one
460 u8 max_mode; /* Speeds allowed */
461 int revision; /* Chipset revision */
462 int flags; /* Chipset properties */
466 struct chipset_bus_clock_list_entry *speed;
470 * This wants fixing so that we do everything not by classrev
471 * (which breaks on the newest chips) but by creating an
472 * enumeration of chip variants and using that
475 static __devinit u32 hpt_revision (struct pci_dev *dev)
478 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
481 switch(dev->device) {
482 /* Remap new 372N onto 372 */
483 case PCI_DEVICE_ID_TTI_HPT372N:
484 class_rev = PCI_DEVICE_ID_TTI_HPT372; break;
485 case PCI_DEVICE_ID_TTI_HPT374:
486 class_rev = PCI_DEVICE_ID_TTI_HPT374; break;
487 case PCI_DEVICE_ID_TTI_HPT371:
488 class_rev = PCI_DEVICE_ID_TTI_HPT371; break;
489 case PCI_DEVICE_ID_TTI_HPT302:
490 class_rev = PCI_DEVICE_ID_TTI_HPT302; break;
491 case PCI_DEVICE_ID_TTI_HPT372:
492 class_rev = PCI_DEVICE_ID_TTI_HPT372; break;
499 static int check_in_drive_lists(ide_drive_t *drive, const char **list);
501 static u8 hpt3xx_ratemask (ide_drive_t *drive)
503 ide_hwif_t *hwif = drive->hwif;
504 struct hpt_info *info = ide_get_hwifdata(hwif);
507 /* FIXME: TODO - move this to set info->mode once at boot */
509 if (info->revision >= 8) { /* HPT374 */
510 mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3;
511 } else if (info->revision >= 7) { /* HPT371 */
512 mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3;
513 } else if (info->revision >= 6) { /* HPT302 */
514 mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3;
515 } else if (info->revision >= 5) { /* HPT372 */
516 mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3;
517 } else if (info->revision >= 4) { /* HPT370A */
518 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
519 } else if (info->revision >= 3) { /* HPT370 */
520 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
521 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode;
522 } else { /* HPT366 and HPT368 */
523 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2;
525 if (!eighty_ninty_three(drive) && mode)
526 mode = min(mode, (u8)1);
531 * Note for the future; the SATA hpt37x we must set
532 * either PIO or UDMA modes 0,4,5
535 static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
537 ide_hwif_t *hwif = drive->hwif;
538 struct hpt_info *info = ide_get_hwifdata(hwif);
539 u8 mode = hpt3xx_ratemask(drive);
541 if (drive->media != ide_disk)
542 return min(speed, (u8)XFER_PIO_4);
546 speed = min(speed, (u8)XFER_UDMA_6);
549 speed = min(speed, (u8)XFER_UDMA_5);
550 if (info->revision >= 5)
552 if (check_in_drive_lists(drive, bad_ata100_5))
553 speed = min(speed, (u8)XFER_UDMA_4);
556 speed = min(speed, (u8)XFER_UDMA_4);
558 * CHECK ME, Does this need to be set to 5 ??
560 if (info->revision >= 3)
562 if ((check_in_drive_lists(drive, bad_ata66_4)) ||
563 (!(HPT366_ALLOW_ATA66_4)))
564 speed = min(speed, (u8)XFER_UDMA_3);
565 if ((check_in_drive_lists(drive, bad_ata66_3)) ||
566 (!(HPT366_ALLOW_ATA66_3)))
567 speed = min(speed, (u8)XFER_UDMA_2);
570 speed = min(speed, (u8)XFER_UDMA_2);
572 * CHECK ME, Does this need to be set to 5 ??
574 if (info->revision >= 3)
576 if (check_in_drive_lists(drive, bad_ata33))
577 speed = min(speed, (u8)XFER_MW_DMA_2);
581 speed = min(speed, (u8)XFER_MW_DMA_2);
587 static int check_in_drive_lists (ide_drive_t *drive, const char **list)
589 struct hd_driveid *id = drive->id;
591 if (quirk_drives == list) {
593 if (strstr(id->model, *list++))
597 if (!strcmp(*list++,id->model))
603 static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
605 for ( ; chipset_table->xfer_speed ; chipset_table++)
606 if (chipset_table->xfer_speed == speed)
607 return chipset_table->chipset_settings;
608 return chipset_table->chipset_settings;
611 static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
613 ide_hwif_t *hwif = drive->hwif;
614 struct pci_dev *dev = hwif->pci_dev;
615 struct hpt_info *info = ide_get_hwifdata(hwif);
616 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
617 u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40;
618 u8 regfast = (hwif->channel) ? 0x55 : 0x51;
620 u32 reg1 = 0, reg2 = 0;
623 * Disable the "fast interrupt" prediction.
625 pci_read_config_byte(dev, regfast, &drive_fast);
626 if (drive_fast & 0x80)
627 pci_write_config_byte(dev, regfast, drive_fast & ~0x80);
629 reg2 = pci_bus_clock_list(speed, info->speed);
632 * Disable on-chip PIO FIFO/buffer
633 * (to avoid problems handling I/O errors later)
635 pci_read_config_dword(dev, regtime, ®1);
636 if (speed >= XFER_MW_DMA_0) {
637 reg2 = (reg2 & ~0xc0000000) | (reg1 & 0xc0000000);
639 reg2 = (reg2 & ~0x30070000) | (reg1 & 0x30070000);
643 pci_write_config_dword(dev, regtime, reg2);
645 return ide_config_drive_speed(drive, speed);
648 static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
650 ide_hwif_t *hwif = drive->hwif;
651 struct pci_dev *dev = hwif->pci_dev;
652 struct hpt_info *info = ide_get_hwifdata(hwif);
653 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
654 u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
655 u8 drive_pci = 0x40 + (drive->dn * 4);
656 u8 new_fast = 0, drive_fast = 0;
657 u32 list_conf = 0, drive_conf = 0;
658 u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
661 * Disable the "fast interrupt" prediction.
662 * don't holdoff on interrupts. (== 0x01 despite what the docs say)
664 pci_read_config_byte(dev, regfast, &drive_fast);
665 new_fast = drive_fast;
669 #ifdef HPT_DELAY_INTERRUPT
673 if ((new_fast & 0x01) == 0)
676 if (new_fast != drive_fast)
677 pci_write_config_byte(dev, regfast, new_fast);
679 list_conf = pci_bus_clock_list(speed, info->speed);
681 pci_read_config_dword(dev, drive_pci, &drive_conf);
682 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
684 if (speed < XFER_MW_DMA_0)
685 list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
686 pci_write_config_dword(dev, drive_pci, list_conf);
688 return ide_config_drive_speed(drive, speed);
691 static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
693 ide_hwif_t *hwif = drive->hwif;
694 struct pci_dev *dev = hwif->pci_dev;
695 struct hpt_info *info = ide_get_hwifdata(hwif);
696 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
697 u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
698 u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4);
699 u32 list_conf = 0, drive_conf = 0;
700 u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
703 * Disable the "fast interrupt" prediction.
704 * don't holdoff on interrupts. (== 0x01 despite what the docs say)
706 pci_read_config_byte(dev, regfast, &drive_fast);
708 pci_write_config_byte(dev, regfast, drive_fast);
710 list_conf = pci_bus_clock_list(speed, info->speed);
711 pci_read_config_dword(dev, drive_pci, &drive_conf);
712 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
713 if (speed < XFER_MW_DMA_0)
714 list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
715 pci_write_config_dword(dev, drive_pci, list_conf);
717 return ide_config_drive_speed(drive, speed);
720 static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed)
722 ide_hwif_t *hwif = drive->hwif;
723 struct hpt_info *info = ide_get_hwifdata(hwif);
725 if (info->revision >= 8)
726 return hpt372_tune_chipset(drive, speed); /* not a typo */
727 else if (info->revision >= 5)
728 return hpt372_tune_chipset(drive, speed);
729 else if (info->revision >= 3)
730 return hpt370_tune_chipset(drive, speed);
731 else /* hpt368: hpt_minimum_revision(dev, 2) */
732 return hpt36x_tune_chipset(drive, speed);
735 static void hpt3xx_tune_drive (ide_drive_t *drive, u8 pio)
737 pio = ide_get_best_pio_mode(drive, 255, pio, NULL);
738 (void) hpt3xx_tune_chipset(drive, (XFER_PIO_0 + pio));
742 * This allows the configuration of ide_pci chipset registers
743 * for cards that learn about the drive's UDMA, DMA, PIO capabilities
744 * after the drive is reported by the OS. Initially for designed for
745 * HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc.
747 * check_in_drive_lists(drive, bad_ata66_4)
748 * check_in_drive_lists(drive, bad_ata66_3)
749 * check_in_drive_lists(drive, bad_ata33)
752 static int config_chipset_for_dma (ide_drive_t *drive)
754 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
755 ide_hwif_t *hwif = drive->hwif;
756 struct hpt_info *info = ide_get_hwifdata(hwif);
761 /* If we don't have any timings we can't do a lot */
762 if (info->speed == NULL)
765 (void) hpt3xx_tune_chipset(drive, speed);
766 return ide_dma_enable(drive);
769 static int hpt3xx_quirkproc (ide_drive_t *drive)
771 return ((int) check_in_drive_lists(drive, quirk_drives));
774 static void hpt3xx_intrproc (ide_drive_t *drive)
776 ide_hwif_t *hwif = drive->hwif;
778 if (drive->quirk_list)
780 /* drives in the quirk_list may not like intr setups/cleanups */
781 hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG);
784 static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
786 ide_hwif_t *hwif = drive->hwif;
787 struct hpt_info *info = ide_get_hwifdata(hwif);
788 struct pci_dev *dev = hwif->pci_dev;
790 if (drive->quirk_list) {
791 if (info->revision >= 3) {
793 pci_read_config_byte(dev, 0x5a, ®5a);
794 if (((reg5a & 0x10) >> 4) != mask)
795 pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10));
798 disable_irq(hwif->irq);
800 enable_irq(hwif->irq);
805 hwif->OUTB(mask ? (drive->ctl | 2) :
811 static int hpt366_config_drive_xfer_rate (ide_drive_t *drive)
813 ide_hwif_t *hwif = drive->hwif;
814 struct hd_driveid *id = drive->id;
816 drive->init_speed = 0;
818 if ((id->capability & 1) && drive->autodma) {
820 if (ide_use_dma(drive)) {
821 if (config_chipset_for_dma(drive))
822 return hwif->ide_dma_on(drive);
827 } else if ((id->capability & 8) || (id->field_valid & 2)) {
829 hpt3xx_tune_drive(drive, 5);
830 return hwif->ide_dma_off_quietly(drive);
832 /* IORDY not supported */
837 * This is specific to the HPT366 UDMA bios chipset
838 * by HighPoint|Triones Technologies, Inc.
840 static int hpt366_ide_dma_lostirq (ide_drive_t *drive)
842 struct pci_dev *dev = HWIF(drive)->pci_dev;
843 u8 reg50h = 0, reg52h = 0, reg5ah = 0;
845 pci_read_config_byte(dev, 0x50, ®50h);
846 pci_read_config_byte(dev, 0x52, ®52h);
847 pci_read_config_byte(dev, 0x5a, ®5ah);
848 printk("%s: (%s) reg50h=0x%02x, reg52h=0x%02x, reg5ah=0x%02x\n",
849 drive->name, __FUNCTION__, reg50h, reg52h, reg5ah);
851 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
852 return __ide_dma_lostirq(drive);
855 static void hpt370_clear_engine (ide_drive_t *drive)
857 u8 regstate = HWIF(drive)->channel ? 0x54 : 0x50;
858 pci_write_config_byte(HWIF(drive)->pci_dev, regstate, 0x37);
862 static void hpt370_ide_dma_start(ide_drive_t *drive)
864 #ifdef HPT_RESET_STATE_ENGINE
865 hpt370_clear_engine(drive);
867 ide_dma_start(drive);
870 static int hpt370_ide_dma_end (ide_drive_t *drive)
872 ide_hwif_t *hwif = HWIF(drive);
873 u8 dma_stat = hwif->INB(hwif->dma_status);
875 if (dma_stat & 0x01) {
878 dma_stat = hwif->INB(hwif->dma_status);
880 if ((dma_stat & 0x01) != 0)
882 (void) HWIF(drive)->ide_dma_timeout(drive);
884 return __ide_dma_end(drive);
887 static void hpt370_lostirq_timeout (ide_drive_t *drive)
889 ide_hwif_t *hwif = HWIF(drive);
890 u8 bfifo = 0, reginfo = hwif->channel ? 0x56 : 0x52;
891 u8 dma_stat = 0, dma_cmd = 0;
893 pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo);
894 printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo);
895 hpt370_clear_engine(drive);
896 /* get dma command mode */
897 dma_cmd = hwif->INB(hwif->dma_command);
899 hwif->OUTB(dma_cmd & ~0x1, hwif->dma_command);
900 dma_stat = hwif->INB(hwif->dma_status);
902 hwif->OUTB(dma_stat | 0x6, hwif->dma_status);
905 static int hpt370_ide_dma_timeout (ide_drive_t *drive)
907 hpt370_lostirq_timeout(drive);
908 hpt370_clear_engine(drive);
909 return __ide_dma_timeout(drive);
912 static int hpt370_ide_dma_lostirq (ide_drive_t *drive)
914 hpt370_lostirq_timeout(drive);
915 hpt370_clear_engine(drive);
916 return __ide_dma_lostirq(drive);
919 /* returns 1 if DMA IRQ issued, 0 otherwise */
920 static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
922 ide_hwif_t *hwif = HWIF(drive);
924 u8 reginfo = hwif->channel ? 0x56 : 0x52;
927 pci_read_config_word(hwif->pci_dev, reginfo, &bfifo);
929 // printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
933 dma_stat = hwif->INB(hwif->dma_status);
934 /* return 1 if INTR asserted */
935 if ((dma_stat & 4) == 4)
938 if (!drive->waiting_for_dma)
939 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
940 drive->name, __FUNCTION__);
944 static int hpt374_ide_dma_end (ide_drive_t *drive)
946 struct pci_dev *dev = HWIF(drive)->pci_dev;
947 ide_hwif_t *hwif = HWIF(drive);
948 u8 msc_stat = 0, mscreg = hwif->channel ? 0x54 : 0x50;
949 u8 bwsr_stat = 0, bwsr_mask = hwif->channel ? 0x02 : 0x01;
951 pci_read_config_byte(dev, 0x6a, &bwsr_stat);
952 pci_read_config_byte(dev, mscreg, &msc_stat);
953 if ((bwsr_stat & bwsr_mask) == bwsr_mask)
954 pci_write_config_byte(dev, mscreg, msc_stat|0x30);
955 return __ide_dma_end(drive);
959 * hpt372n_set_clock - perform clock switching dance
960 * @drive: Drive to switch
961 * @mode: Switching mode (0x21 for write, 0x23 otherwise)
963 * Switch the DPLL clock on the HPT372N devices. This is a
967 static void hpt372n_set_clock(ide_drive_t *drive, int mode)
969 ide_hwif_t *hwif = HWIF(drive);
971 /* FIXME: should we check for DMA active and BUG() */
972 /* Tristate the bus */
973 outb(0x80, hwif->dma_base+0x73);
974 outb(0x80, hwif->dma_base+0x77);
976 /* Switch clock and reset channels */
977 outb(mode, hwif->dma_base+0x7B);
978 outb(0xC0, hwif->dma_base+0x79);
980 /* Reset state machines */
981 outb(0x37, hwif->dma_base+0x70);
982 outb(0x37, hwif->dma_base+0x74);
985 outb(0x00, hwif->dma_base+0x79);
987 /* Reconnect channels to bus */
988 outb(0x00, hwif->dma_base+0x73);
989 outb(0x00, hwif->dma_base+0x77);
993 * hpt372n_rw_disk - prepare for I/O
994 * @drive: drive for command
995 * @rq: block request structure
997 * This is called when a disk I/O is issued to the 372N.
998 * We need it because of the clock switching.
1001 static void hpt372n_rw_disk(ide_drive_t *drive, struct request *rq)
1003 ide_hwif_t *hwif = drive->hwif;
1006 wantclock = rq_data_dir(rq) ? 0x23 : 0x21;
1008 if (hwif->config_data != wantclock) {
1009 hpt372n_set_clock(drive, wantclock);
1010 hwif->config_data = wantclock;
1015 * Since SUN Cobalt is attempting to do this operation, I should disclose
1016 * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date
1017 * HOTSWAP ATA Infrastructure.
1020 static void hpt3xx_reset (ide_drive_t *drive)
1024 static int hpt3xx_tristate (ide_drive_t * drive, int state)
1026 ide_hwif_t *hwif = HWIF(drive);
1027 struct pci_dev *dev = hwif->pci_dev;
1028 u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40;
1029 u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
1031 pci_read_config_byte(dev, 0x59, ®59h);
1032 pci_read_config_byte(dev, state_reg, ®XXh);
1035 (void) ide_do_reset(drive);
1036 pci_write_config_byte(dev, state_reg, regXXh|0x80);
1037 pci_write_config_byte(dev, 0x59, reg59h|reset);
1039 pci_write_config_byte(dev, 0x59, reg59h & ~(reset));
1040 pci_write_config_byte(dev, state_reg, regXXh & ~(0x80));
1041 (void) ide_do_reset(drive);
1047 * set/get power state for a drive.
1048 * turning the power off does the following things:
1049 * 1) soft-reset the drive
1050 * 2) tri-states the ide bus
1052 * when we turn things back on, we need to re-initialize things.
1054 #define TRISTATE_BIT 0x8000
1055 static int hpt370_busproc(ide_drive_t * drive, int state)
1057 ide_hwif_t *hwif = drive->hwif;
1058 struct pci_dev *dev = hwif->pci_dev;
1059 u8 tristate = 0, resetmask = 0, bus_reg = 0;
1062 hwif->bus_state = state;
1064 if (hwif->channel) {
1065 /* secondary channel */
1069 /* primary channel */
1075 pci_read_config_word(dev, tristate, &tri_reg);
1076 pci_read_config_byte(dev, 0x59, &bus_reg);
1078 /* set the state. we don't set it if we don't need to do so.
1079 * make sure that the drive knows that it has failed if it's off */
1082 hwif->drives[0].failures = 0;
1083 hwif->drives[1].failures = 0;
1084 if ((bus_reg & resetmask) == 0)
1086 tri_reg &= ~TRISTATE_BIT;
1087 bus_reg &= ~resetmask;
1090 hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
1091 hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
1092 if ((tri_reg & TRISTATE_BIT) == 0 && (bus_reg & resetmask))
1094 tri_reg &= ~TRISTATE_BIT;
1095 bus_reg |= resetmask;
1097 case BUSSTATE_TRISTATE:
1098 hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
1099 hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
1100 if ((tri_reg & TRISTATE_BIT) && (bus_reg & resetmask))
1102 tri_reg |= TRISTATE_BIT;
1103 bus_reg |= resetmask;
1106 pci_write_config_byte(dev, 0x59, bus_reg);
1107 pci_write_config_word(dev, tristate, tri_reg);
1112 static void __devinit hpt366_clocking(ide_hwif_t *hwif)
1115 struct hpt_info *info = ide_get_hwifdata(hwif);
1117 pci_read_config_dword(hwif->pci_dev, 0x40, ®1);
1119 /* detect bus speed by looking at control reg timing: */
1120 switch((reg1 >> 8) & 7) {
1122 info->speed = forty_base_hpt366;
1125 info->speed = twenty_five_base_hpt366;
1129 info->speed = thirty_three_base_hpt366;
1134 static void __devinit hpt37x_clocking(ide_hwif_t *hwif)
1136 struct hpt_info *info = ide_get_hwifdata(hwif);
1137 struct pci_dev *dev = hwif->pci_dev;
1144 * default to pci clock. make sure MA15/16 are set to output
1145 * to prevent drives having problems with 40-pin cables. Needed
1146 * for some drives such as IBM-DTLA which will not enter ready
1147 * state on reset when PDIAG is a input.
1149 * ToDo: should we set 0x21 when using PLL mode ?
1151 pci_write_config_byte(dev, 0x5b, 0x23);
1154 * set up the PLL. we need to adjust it so that it's stable.
1155 * freq = Tpll * 192 / Tpci
1157 * Todo. For non x86 should probably check the dword is
1158 * set to 0xABCDExxx indicating the BIOS saved f_CNT
1160 pci_read_config_word(dev, 0x78, &freq);
1164 * The 372N uses different PCI clock information and has
1165 * some other complications
1166 * On PCI33 timing we must clock switch
1167 * On PCI66 timing we must NOT use the PCI clock
1169 * Currently we always set up the PLL for the 372N
1172 if(info->flags & IS_372N)
1174 printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n");
1177 else if(freq < 0x70)
1179 else if(freq < 0x7F)
1184 printk(KERN_INFO "FREQ: %d PLL: %d\n", freq, pll);
1186 /* We always use the pll not the PCI clock on 372N */
1192 else if(freq < 0xb0)
1199 if (pll == F_LOW_PCI_33) {
1200 if (info->revision >= 8)
1201 info->speed = thirty_three_base_hpt374;
1202 else if (info->revision >= 5)
1203 info->speed = thirty_three_base_hpt372;
1204 else if (info->revision >= 4)
1205 info->speed = thirty_three_base_hpt370a;
1207 info->speed = thirty_three_base_hpt370;
1208 printk(KERN_DEBUG "HPT37X: using 33MHz PCI clock\n");
1209 } else if (pll == F_LOW_PCI_40) {
1211 } else if (pll == F_LOW_PCI_50) {
1212 if (info->revision >= 8)
1213 info->speed = fifty_base_hpt370a;
1214 else if (info->revision >= 5)
1215 info->speed = fifty_base_hpt372;
1216 else if (info->revision >= 4)
1217 info->speed = fifty_base_hpt370a;
1219 info->speed = fifty_base_hpt370a;
1220 printk(KERN_DEBUG "HPT37X: using 50MHz PCI clock\n");
1222 if (info->revision >= 8) {
1223 printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n");
1225 else if (info->revision >= 5)
1226 info->speed = sixty_six_base_hpt372;
1227 else if (info->revision >= 4)
1228 info->speed = sixty_six_base_hpt370a;
1230 info->speed = sixty_six_base_hpt370;
1231 printk(KERN_DEBUG "HPT37X: using 66MHz PCI clock\n");
1236 * only try the pll if we don't have a table for the clock
1237 * speed that we're running at. NOTE: the internal PLL will
1238 * result in slow reads when using a 33MHz PCI clock. we also
1239 * don't like to use the PLL because it will cause glitches
1240 * on PRST/SRST when the HPT state engine gets reset.
1242 * ToDo: Use 66MHz PLL when ATA133 devices are present on a
1243 * 372 device so we can get ATA133 support
1246 goto init_hpt37X_done;
1248 info->flags |= PLL_MODE;
1251 * FIXME: make this work correctly, esp with 372N as per
1252 * reference driver code.
1254 * adjust PLL based upon PCI clock, enable it, and wait for
1258 freq = (pll < F_LOW_PCI_50) ? 2 : 4;
1259 while (adjust++ < 6) {
1260 pci_write_config_dword(dev, 0x5c, (freq + pll) << 16 |
1263 /* wait for clock stabilization */
1264 for (i = 0; i < 0x50000; i++) {
1265 pci_read_config_byte(dev, 0x5b, ®5bh);
1266 if (reg5bh & 0x80) {
1267 /* spin looking for the clock to destabilize */
1268 for (i = 0; i < 0x1000; ++i) {
1269 pci_read_config_byte(dev, 0x5b,
1271 if ((reg5bh & 0x80) == 0)
1274 pci_read_config_dword(dev, 0x5c, &pll);
1275 pci_write_config_dword(dev, 0x5c,
1277 pci_write_config_byte(dev, 0x5b, 0x21);
1278 if (info->revision >= 8)
1279 info->speed = fifty_base_hpt370a;
1280 else if (info->revision >= 5)
1281 info->speed = fifty_base_hpt372;
1282 else if (info->revision >= 4)
1283 info->speed = fifty_base_hpt370a;
1285 info->speed = fifty_base_hpt370a;
1286 printk("HPT37X: using 50MHz internal PLL\n");
1287 goto init_hpt37X_done;
1290 if (!pci_get_drvdata(dev)) {
1291 printk("No Clock Stabilization!!!\n");
1296 pll -= (adjust >> 1);
1298 pll += (adjust >> 1);
1303 printk(KERN_ERR "HPT37X%s: unknown bus timing [%d %d].\n",
1304 (info->flags & IS_372N)?"N":"", pll, freq);
1305 /* reset state engine */
1306 pci_write_config_byte(dev, 0x50, 0x37);
1307 pci_write_config_byte(dev, 0x54, 0x37);
1311 static int __devinit init_hpt37x(struct pci_dev *dev)
1315 pci_read_config_byte(dev, 0x5a, ®5ah);
1316 /* interrupt force enable */
1317 pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
1321 static int __devinit init_hpt366(struct pci_dev *dev)
1327 * Disable the "fast interrupt" prediction.
1329 pci_read_config_byte(dev, 0x51, &drive_fast);
1330 if (drive_fast & 0x80)
1331 pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);
1332 pci_read_config_dword(dev, 0x40, ®1);
1337 static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
1342 * FIXME: Not portable. Also, why do we enable the ROM in the first place?
1343 * We don't seem to be using it.
1345 if (dev->resource[PCI_ROM_RESOURCE].start)
1346 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
1347 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
1349 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
1350 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1351 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
1352 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
1354 if (hpt_revision(dev) >= 3)
1355 ret = init_hpt37x(dev);
1357 ret = init_hpt366(dev);
1365 static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1367 struct pci_dev *dev = hwif->pci_dev;
1368 struct hpt_info *info = ide_get_hwifdata(hwif);
1369 u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02;
1371 hwif->tuneproc = &hpt3xx_tune_drive;
1372 hwif->speedproc = &hpt3xx_tune_chipset;
1373 hwif->quirkproc = &hpt3xx_quirkproc;
1374 hwif->intrproc = &hpt3xx_intrproc;
1375 hwif->maskproc = &hpt3xx_maskproc;
1377 if(info->flags & IS_372N)
1378 hwif->rw_disk = &hpt372n_rw_disk;
1381 * The HPT37x uses the CBLID pins as outputs for MA15/MA16
1382 * address lines to access an external eeprom. To read valid
1383 * cable detect state the pins must be enabled as inputs.
1385 if (info->revision >= 8 && (PCI_FUNC(dev->devfn) & 1)) {
1387 * HPT374 PCI function 1
1388 * - set bit 15 of reg 0x52 to enable TCBLID as input
1389 * - set bit 15 of reg 0x56 to enable FCBLID as input
1392 pci_read_config_word(dev, 0x52, &mcr3);
1393 pci_read_config_word(dev, 0x56, &mcr6);
1394 pci_write_config_word(dev, 0x52, mcr3 | 0x8000);
1395 pci_write_config_word(dev, 0x56, mcr6 | 0x8000);
1396 /* now read cable id register */
1397 pci_read_config_byte(dev, 0x5a, &ata66);
1398 pci_write_config_word(dev, 0x52, mcr3);
1399 pci_write_config_word(dev, 0x56, mcr6);
1400 } else if (info->revision >= 3) {
1402 * HPT370/372 and 374 pcifn 0
1403 * - clear bit 0 of 0x5b to enable P/SCBLID as inputs
1406 pci_read_config_byte(dev, 0x5b, &scr2);
1407 pci_write_config_byte(dev, 0x5b, scr2 & ~1);
1408 /* now read cable id register */
1409 pci_read_config_byte(dev, 0x5a, &ata66);
1410 pci_write_config_byte(dev, 0x5b, scr2);
1412 pci_read_config_byte(dev, 0x5a, &ata66);
1416 printk("HPT366: reg5ah=0x%02x ATA-%s Cable Port%d\n",
1417 ata66, (ata66 & regmask) ? "33" : "66",
1418 PCI_FUNC(hwif->pci_dev->devfn));
1421 #ifdef HPT_SERIALIZE_IO
1422 /* serialize access to this device */
1424 hwif->serialized = hwif->mate->serialized = 1;
1427 if (info->revision >= 3) {
1429 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
1431 * set up ioctl for power status.
1432 * note: power affects both
1433 * drives on each channel
1435 hwif->resetproc = &hpt3xx_reset;
1436 hwif->busproc = &hpt370_busproc;
1437 } else if (info->revision >= 2) {
1438 hwif->resetproc = &hpt3xx_reset;
1439 hwif->busproc = &hpt3xx_tristate;
1441 hwif->resetproc = &hpt3xx_reset;
1442 hwif->busproc = &hpt3xx_tristate;
1445 if (!hwif->dma_base) {
1446 hwif->drives[0].autotune = 1;
1447 hwif->drives[1].autotune = 1;
1451 hwif->ultra_mask = 0x7f;
1452 hwif->mwdma_mask = 0x07;
1454 if (!(hwif->udma_four))
1455 hwif->udma_four = ((ata66 & regmask) ? 0 : 1);
1456 hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;
1458 if (info->revision >= 8) {
1459 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1460 hwif->ide_dma_end = &hpt374_ide_dma_end;
1461 } else if (info->revision >= 5) {
1462 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1463 hwif->ide_dma_end = &hpt374_ide_dma_end;
1464 } else if (info->revision >= 3) {
1465 hwif->dma_start = &hpt370_ide_dma_start;
1466 hwif->ide_dma_end = &hpt370_ide_dma_end;
1467 hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;
1468 hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq;
1469 } else if (info->revision >= 2)
1470 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
1472 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
1476 hwif->drives[0].autodma = hwif->autodma;
1477 hwif->drives[1].autodma = hwif->autodma;
1480 static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1482 struct hpt_info *info = ide_get_hwifdata(hwif);
1483 u8 masterdma = 0, slavedma = 0;
1484 u8 dma_new = 0, dma_old = 0;
1485 u8 primary = hwif->channel ? 0x4b : 0x43;
1486 u8 secondary = hwif->channel ? 0x4f : 0x47;
1487 unsigned long flags;
1492 if(info->speed == NULL) {
1493 printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n");
1497 dma_old = hwif->INB(dmabase+2);
1499 local_irq_save(flags);
1502 pci_read_config_byte(hwif->pci_dev, primary, &masterdma);
1503 pci_read_config_byte(hwif->pci_dev, secondary, &slavedma);
1505 if (masterdma & 0x30) dma_new |= 0x20;
1506 if (slavedma & 0x30) dma_new |= 0x40;
1507 if (dma_new != dma_old)
1508 hwif->OUTB(dma_new, dmabase+2);
1510 local_irq_restore(flags);
1512 ide_setup_dma(hwif, dmabase, 8);
1516 * We "borrow" this hook in order to set the data structures
1517 * up early enough before dma or init_hwif calls are made.
1520 static void __devinit init_iops_hpt366(ide_hwif_t *hwif)
1522 struct hpt_info *info = kzalloc(sizeof(struct hpt_info), GFP_KERNEL);
1523 unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4);
1527 printk(KERN_WARNING "hpt366: out of memory.\n");
1530 ide_set_hwifdata(hwif, info);
1533 did = inb(dmabase + 0x22);
1534 rid = inb(dmabase + 0x28);
1536 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1537 info->flags |= IS_372N;
1540 info->revision = hpt_revision(hwif->pci_dev);
1542 if (info->revision >= 3)
1543 hpt37x_clocking(hwif);
1545 hpt366_clocking(hwif);
1548 static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d)
1550 struct pci_dev *findev = NULL;
1552 if (PCI_FUNC(dev->devfn) & 1)
1555 while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {
1556 if ((findev->vendor == dev->vendor) &&
1557 (findev->device == dev->device) &&
1558 ((findev->devfn - dev->devfn) == 1) &&
1559 (PCI_FUNC(findev->devfn) & 1)) {
1560 if (findev->irq != dev->irq) {
1561 /* FIXME: we need a core pci_set_interrupt() */
1562 findev->irq = dev->irq;
1563 printk(KERN_WARNING "%s: pci-config space interrupt "
1564 "fixed.\n", d->name);
1566 return ide_setup_pci_devices(dev, findev, d);
1569 return ide_setup_pci_device(dev, d);
1572 static int __devinit init_setup_hpt37x(struct pci_dev *dev, ide_pci_device_t *d)
1574 return ide_setup_pci_device(dev, d);
1577 static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d)
1579 struct pci_dev *findev = NULL;
1580 u8 pin1 = 0, pin2 = 0;
1581 unsigned int class_rev;
1582 char *chipset_names[] = {"HPT366", "HPT366", "HPT368",
1583 "HPT370", "HPT370A", "HPT372",
1586 if (PCI_FUNC(dev->devfn) & 1)
1589 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
1592 if(dev->device == PCI_DEVICE_ID_TTI_HPT372N)
1596 d->name = chipset_names[class_rev];
1610 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);
1611 while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {
1612 if ((findev->vendor == dev->vendor) &&
1613 (findev->device == dev->device) &&
1614 ((findev->devfn - dev->devfn) == 1) &&
1615 (PCI_FUNC(findev->devfn) & 1)) {
1616 pci_read_config_byte(findev, PCI_INTERRUPT_PIN, &pin2);
1617 if ((pin1 != pin2) && (dev->irq == findev->irq)) {
1618 d->bootable = ON_BOARD;
1619 printk("%s: onboard version of chipset, "
1620 "pin1=%d pin2=%d\n", d->name,
1623 return ide_setup_pci_devices(dev, findev, d);
1627 return ide_setup_pci_device(dev, d);
1630 static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1633 .init_setup = init_setup_hpt366,
1634 .init_chipset = init_chipset_hpt366,
1635 .init_iops = init_iops_hpt366,
1636 .init_hwif = init_hwif_hpt366,
1637 .init_dma = init_dma_hpt366,
1640 .bootable = OFF_BOARD,
1644 .init_setup = init_setup_hpt37x,
1645 .init_chipset = init_chipset_hpt366,
1646 .init_iops = init_iops_hpt366,
1647 .init_hwif = init_hwif_hpt366,
1648 .init_dma = init_dma_hpt366,
1651 .bootable = OFF_BOARD,
1654 .init_setup = init_setup_hpt37x,
1655 .init_chipset = init_chipset_hpt366,
1656 .init_iops = init_iops_hpt366,
1657 .init_hwif = init_hwif_hpt366,
1658 .init_dma = init_dma_hpt366,
1661 .bootable = OFF_BOARD,
1664 .init_setup = init_setup_hpt37x,
1665 .init_chipset = init_chipset_hpt366,
1666 .init_iops = init_iops_hpt366,
1667 .init_hwif = init_hwif_hpt366,
1668 .init_dma = init_dma_hpt366,
1671 .bootable = OFF_BOARD,
1674 .init_setup = init_setup_hpt374,
1675 .init_chipset = init_chipset_hpt366,
1676 .init_iops = init_iops_hpt366,
1677 .init_hwif = init_hwif_hpt366,
1678 .init_dma = init_dma_hpt366,
1679 .channels = 2, /* 4 */
1681 .bootable = OFF_BOARD,
1684 .init_setup = init_setup_hpt37x,
1685 .init_chipset = init_chipset_hpt366,
1686 .init_iops = init_iops_hpt366,
1687 .init_hwif = init_hwif_hpt366,
1688 .init_dma = init_dma_hpt366,
1689 .channels = 2, /* 4 */
1691 .bootable = OFF_BOARD,
1696 * hpt366_init_one - called when an HPT366 is found
1697 * @dev: the hpt366 device
1698 * @id: the matching pci id
1700 * Called when the PCI registration layer (or the IDE initialization)
1701 * finds a device matching our IDE device tables.
1704 static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1706 ide_pci_device_t *d = &hpt366_chipsets[id->driver_data];
1708 return d->init_setup(dev, d);
1711 static struct pci_device_id hpt366_pci_tbl[] = {
1712 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1713 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
1714 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
1715 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
1716 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
1717 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372N, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
1720 MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
1722 static struct pci_driver driver = {
1723 .name = "HPT366_IDE",
1724 .id_table = hpt366_pci_tbl,
1725 .probe = hpt366_init_one,
1728 static int hpt366_ide_init(void)
1730 return ide_pci_register_driver(&driver);
1733 module_init(hpt366_ide_init);
1735 MODULE_AUTHOR("Andre Hedrick");
1736 MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");
1737 MODULE_LICENSE("GPL");