diff options
author | Sergei Shtylyov <sshtylyov@ru.mvista.com> | 2007-02-07 12:18:16 -0500 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2007-02-07 12:18:16 -0500 |
commit | 7b73ee05d0acb926923d43d78b61add776ea4bb1 (patch) | |
tree | f2ec45ca5343918502d5dc4b10b05632a20b847c /drivers/ide/pci/hpt366.c | |
parent | 4bf63de27e9fd9c0926ba3bb773de076b324a955 (diff) |
hpt366: init code rewrite
Finally, rework the driver init. code to correctly handle all the chip
variants HighPoint has created so far. This should cure the rest of the
timing issues in the driver (especially, on 66 MHz PCI) caused by the
HighPoint's habit of switching the base DPLL clock with every new revision
of the chips...
- switch to using the enumeration type to differ between the numerous chip
variants, matching PCI device/revision ID with the chip type early, at the
init_setup stage;
- extend the hpt_info structure to hold the DPLL and PCI clock frequencies,
stop duplicating it for each channel by storing the pointer in the pci_dev
structure: first, at the init_setup stage, point it to a static "template"
with only the chip type and its specific base DPLL frequency, the highest
supported DMA mode, and the chip settings table pointer filled, then, at
the init_chipset stage, allocate per-chip instance and fill it with the
rest of the necessary information;
- get rid of the constant thresholds in the HPT37x PCI clock detection code,
switch to calculating PCI clock frequency based on the chip's base DPLL
frequency;
- switch to using the DPLL clock and enable UltraATA/133 mode by default on
anything newer than HPT370/A;
- fold PCI clock detection and DPLL setup code into init_chipset_hpt366(),
unify the HPT36x/37x setup code and the speedproc handlers by joining the
register setting lists into the table indexed by the clock selected;
- add enablebits for all the chips to avoid touching disabled channels
(though the HighPoint BIOS seem to only disable the primary one on
HPT371/N);
- separate the UltraDMA and MWDMA masks there to avoid changing PIO timings
when setting an UltraDMA mode in hpt37x_tune_chipset().
This version has been tested on HPT370/302/371N.
Thanks to Alan for the inspiration. Hopefully, his libata driver will also
benefit from the work done on this "obsolete" driver...
Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/pci/hpt366.c')
-rw-r--r-- | drivers/ide/pci/hpt366.c | 851 |
1 files changed, 489 insertions, 362 deletions
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c index 9ad1531b6034..4350e3371360 100644 --- a/drivers/ide/pci/hpt366.c +++ b/drivers/ide/pci/hpt366.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/ide/pci/hpt366.c Version 0.52 Jun 07, 2006 | 2 | * linux/drivers/ide/pci/hpt366.c Version 1.00 Jun 25, 2006 |
3 | * | 3 | * |
4 | * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> | 4 | * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> |
5 | * Portions Copyright (C) 2001 Sun Microsystems, Inc. | 5 | * Portions Copyright (C) 2001 Sun Microsystems, Inc. |
@@ -60,13 +60,10 @@ | |||
60 | * channel caused the cached register value to get out of sync with the | 60 | * channel caused the cached register value to get out of sync with the |
61 | * actual one, the channels weren't serialized, the turnaround shouldn't | 61 | * actual one, the channels weren't serialized, the turnaround shouldn't |
62 | * be done on 66 MHz PCI bus | 62 | * be done on 66 MHz PCI bus |
63 | * - avoid calibrating PLL twice as the second time results in a wrong PCI | 63 | * - disable UltraATA/100 for HPT370 by default as the 33 MHz clock being used |
64 | * frequency and thus in the wrong timings for the secondary channel | 64 | * does not allow for this speed anyway |
65 | * - disable UltraATA/133 for HPT372 and UltraATA/100 for HPT370 by default | 65 | * - avoid touching disabled channels (e.g. HPT371/N are single channel chips, |
66 | * as the ATA clock being used does not allow for this speed anyway | 66 | * their primary channel is kind of virtual, it isn't tied to any pins) |
67 | * - add support for HPT302N and HPT371N clocking (the same as for HPT372N) | ||
68 | * - HPT371/N are single channel chips, so avoid touching the primary channel | ||
69 | * which exists only virtually (there's no pins for it) | ||
70 | * - fix/remove bad/unused timing tables and use one set of tables for the whole | 67 | * - fix/remove bad/unused timing tables and use one set of tables for the whole |
71 | * HPT37x chip family; save space by introducing the separate transfer mode | 68 | * HPT37x chip family; save space by introducing the separate transfer mode |
72 | * table in which the mode lookup is done | 69 | * table in which the mode lookup is done |
@@ -76,22 +73,44 @@ | |||
76 | * and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead | 73 | * and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead |
77 | * - pass to init_chipset() handlers a copy of the IDE PCI device structure as | 74 | * - pass to init_chipset() handlers a copy of the IDE PCI device structure as |
78 | * they tamper with its fields | 75 | * they tamper with its fields |
76 | * - pass to the init_setup handlers a copy of the ide_pci_device_t structure | ||
77 | * since they may tamper with its fields | ||
79 | * - prefix the driver startup messages with the real chip name | 78 | * - prefix the driver startup messages with the real chip name |
80 | * - claim the extra 240 bytes of I/O space for all chips | 79 | * - claim the extra 240 bytes of I/O space for all chips |
81 | * - optimize the rate masking/filtering and the drive list lookup code | 80 | * - optimize the rate masking/filtering and the drive list lookup code |
82 | * - use pci_get_slot() to get to the function 1 of HPT36x/374 | 81 | * - use pci_get_slot() to get to the function 1 of HPT36x/374 |
83 | * - cache the channel's MCRs' offset; only touch the relevant MCR when detecting | 82 | * - cache offset of the channel's misc. control registers (MCRs) being used |
84 | * the cable type on HPT374's function 1 | 83 | * throughout the driver |
84 | * - only touch the relevant MCR when detecting the cable type on HPT374's | ||
85 | * function 1 | ||
85 | * - rename all the register related variables consistently | 86 | * - rename all the register related variables consistently |
86 | * - move the interrupt twiddling code from the speedproc handlers into the | 87 | * - move all the interrupt twiddling code from the speedproc handlers into |
87 | * init_hwif handler, also grouping all the DMA related code together there; | 88 | * init_hwif_hpt366(), also grouping all the DMA related code together there |
88 | * simplify the init_chipset handler | 89 | * - merge two HPT37x speedproc handlers, fix the PIO timing register mask and |
89 | * - merge two HPT37x speedproc handlers and fix the PIO timing register mask | 90 | * separate the UltraDMA and MWDMA masks there to avoid changing PIO timings |
90 | * there; make HPT36x speedproc handler look the same way as the HPT37x one | 91 | * when setting an UltraDMA mode |
91 | * - fix the tuneproc handler to always set the PIO mode requested, not the | 92 | * - fix hpt3xx_tune_drive() to set the PIO mode requested, not always select |
92 | * best possible one | 93 | * the best possible one |
93 | * - clean up DMA timeout handling for HPT370 | 94 | * - clean up DMA timeout handling for HPT370 |
94 | * <source@mvista.com> | 95 | * - switch to using the enumeration type to differ between the numerous chip |
96 | * variants, matching PCI device/revision ID with the chip type early, at the | ||
97 | * init_setup stage | ||
98 | * - extend the hpt_info structure to hold the DPLL and PCI clock frequencies, | ||
99 | * stop duplicating it for each channel by storing the pointer in the pci_dev | ||
100 | * structure: first, at the init_setup stage, point it to a static "template" | ||
101 | * with only the chip type and its specific base DPLL frequency, the highest | ||
102 | * supported DMA mode, and the chip settings table pointer filled, then, at | ||
103 | * the init_chipset stage, allocate per-chip instance and fill it with the | ||
104 | * rest of the necessary information | ||
105 | * - get rid of the constant thresholds in the HPT37x PCI clock detection code, | ||
106 | * switch to calculating PCI clock frequency based on the chip's base DPLL | ||
107 | * frequency | ||
108 | * - switch to using the DPLL clock and enable UltraATA/133 mode by default on | ||
109 | * anything newer than HPT370/A | ||
110 | * - fold PCI clock detection and DPLL setup code into init_chipset_hpt366(); | ||
111 | * unify HPT36x/37x timing setup code and the speedproc handlers by joining | ||
112 | * the register setting lists into the table indexed by the clock selected | ||
113 | * Sergei Shtylyov, <sshtylyov@ru.mvista.com> or <source@mvista.com> | ||
95 | */ | 114 | */ |
96 | 115 | ||
97 | #include <linux/types.h> | 116 | #include <linux/types.h> |
@@ -345,71 +364,143 @@ static u32 sixty_six_base_hpt37x[] = { | |||
345 | }; | 364 | }; |
346 | 365 | ||
347 | #define HPT366_DEBUG_DRIVE_INFO 0 | 366 | #define HPT366_DEBUG_DRIVE_INFO 0 |
348 | #define HPT374_ALLOW_ATA133_6 0 | 367 | #define HPT374_ALLOW_ATA133_6 1 |
349 | #define HPT371_ALLOW_ATA133_6 0 | 368 | #define HPT371_ALLOW_ATA133_6 1 |
350 | #define HPT302_ALLOW_ATA133_6 0 | 369 | #define HPT302_ALLOW_ATA133_6 1 |
351 | #define HPT372_ALLOW_ATA133_6 0 | 370 | #define HPT372_ALLOW_ATA133_6 1 |
352 | #define HPT370_ALLOW_ATA100_5 0 | 371 | #define HPT370_ALLOW_ATA100_5 0 |
353 | #define HPT366_ALLOW_ATA66_4 1 | 372 | #define HPT366_ALLOW_ATA66_4 1 |
354 | #define HPT366_ALLOW_ATA66_3 1 | 373 | #define HPT366_ALLOW_ATA66_3 1 |
355 | #define HPT366_MAX_DEVS 8 | 374 | #define HPT366_MAX_DEVS 8 |
356 | 375 | ||
357 | #define F_LOW_PCI_33 0x23 | 376 | /* Supported ATA clock frequencies */ |
358 | #define F_LOW_PCI_40 0x29 | 377 | enum ata_clock { |
359 | #define F_LOW_PCI_50 0x2d | 378 | ATA_CLOCK_25MHZ, |
360 | #define F_LOW_PCI_66 0x42 | 379 | ATA_CLOCK_33MHZ, |
380 | ATA_CLOCK_40MHZ, | ||
381 | ATA_CLOCK_50MHZ, | ||
382 | ATA_CLOCK_66MHZ, | ||
383 | NUM_ATA_CLOCKS | ||
384 | }; | ||
361 | 385 | ||
362 | /* | 386 | /* |
363 | * Hold all the highpoint quirks and revision information in one | 387 | * Hold all the HighPoint chip information in one place. |
364 | * place. | ||
365 | */ | 388 | */ |
366 | 389 | ||
367 | struct hpt_info | 390 | struct hpt_info { |
368 | { | 391 | u8 chip_type; /* Chip type */ |
369 | u8 max_mode; /* Speeds allowed */ | 392 | u8 max_mode; /* Speeds allowed */ |
370 | u8 revision; /* Chipset revision */ | 393 | u8 dpll_clk; /* DPLL clock in MHz */ |
371 | u8 flags; /* Chipset properties */ | 394 | u8 pci_clk; /* PCI clock in MHz */ |
372 | #define PLL_MODE 1 | 395 | u32 **settings; /* Chipset settings table */ |
373 | #define IS_3xxN 2 | ||
374 | #define PCI_66MHZ 4 | ||
375 | /* Speed table */ | ||
376 | u32 *speed; | ||
377 | }; | 396 | }; |
378 | 397 | ||
379 | /* | 398 | /* Supported HighPoint chips */ |
380 | * This wants fixing so that we do everything not by revision | 399 | enum { |
381 | * (which breaks on the newest chips) but by creating an | 400 | HPT36x, |
382 | * enumeration of chip variants and using that | 401 | HPT370, |
383 | */ | 402 | HPT370A, |
403 | HPT374, | ||
404 | HPT372, | ||
405 | HPT372A, | ||
406 | HPT302, | ||
407 | HPT371, | ||
408 | HPT372N, | ||
409 | HPT302N, | ||
410 | HPT371N | ||
411 | }; | ||
384 | 412 | ||
385 | static __devinit u8 hpt_revision(struct pci_dev *dev) | 413 | static u32 *hpt36x_settings[NUM_ATA_CLOCKS] = { |
386 | { | 414 | twenty_five_base_hpt36x, |
387 | u8 rev = 0; | 415 | thirty_three_base_hpt36x, |
416 | forty_base_hpt36x, | ||
417 | NULL, | ||
418 | NULL | ||
419 | }; | ||
388 | 420 | ||
389 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); | 421 | static u32 *hpt37x_settings[NUM_ATA_CLOCKS] = { |
422 | NULL, | ||
423 | thirty_three_base_hpt37x, | ||
424 | NULL, | ||
425 | fifty_base_hpt37x, | ||
426 | sixty_six_base_hpt37x | ||
427 | }; | ||
390 | 428 | ||
391 | switch(dev->device) { | 429 | static struct hpt_info hpt36x __devinitdata = { |
392 | /* Remap new 372N onto 372 */ | 430 | .chip_type = HPT36x, |
393 | case PCI_DEVICE_ID_TTI_HPT372N: | 431 | .max_mode = (HPT366_ALLOW_ATA66_4 || HPT366_ALLOW_ATA66_3) ? 2 : 1, |
394 | rev = PCI_DEVICE_ID_TTI_HPT372; | 432 | .dpll_clk = 0, /* no DPLL */ |
395 | break; | 433 | .settings = hpt36x_settings |
396 | case PCI_DEVICE_ID_TTI_HPT374: | 434 | }; |
397 | rev = PCI_DEVICE_ID_TTI_HPT374; | 435 | |
398 | break; | 436 | static struct hpt_info hpt370 __devinitdata = { |
399 | case PCI_DEVICE_ID_TTI_HPT371: | 437 | .chip_type = HPT370, |
400 | rev = PCI_DEVICE_ID_TTI_HPT371; | 438 | .max_mode = HPT370_ALLOW_ATA100_5 ? 3 : 2, |
401 | break; | 439 | .dpll_clk = 48, |
402 | case PCI_DEVICE_ID_TTI_HPT302: | 440 | .settings = hpt37x_settings |
403 | rev = PCI_DEVICE_ID_TTI_HPT302; | 441 | }; |
404 | break; | 442 | |
405 | case PCI_DEVICE_ID_TTI_HPT372: | 443 | static struct hpt_info hpt370a __devinitdata = { |
406 | rev = PCI_DEVICE_ID_TTI_HPT372; | 444 | .chip_type = HPT370A, |
407 | break; | 445 | .max_mode = HPT370_ALLOW_ATA100_5 ? 3 : 2, |
408 | default: | 446 | .dpll_clk = 48, |
409 | break; | 447 | .settings = hpt37x_settings |
410 | } | 448 | }; |
411 | return rev; | 449 | |
412 | } | 450 | static struct hpt_info hpt374 __devinitdata = { |
451 | .chip_type = HPT374, | ||
452 | .max_mode = HPT374_ALLOW_ATA133_6 ? 4 : 3, | ||
453 | .dpll_clk = 48, | ||
454 | .settings = hpt37x_settings | ||
455 | }; | ||
456 | |||
457 | static struct hpt_info hpt372 __devinitdata = { | ||
458 | .chip_type = HPT372, | ||
459 | .max_mode = HPT372_ALLOW_ATA133_6 ? 4 : 3, | ||
460 | .dpll_clk = 55, | ||
461 | .settings = hpt37x_settings | ||
462 | }; | ||
463 | |||
464 | static struct hpt_info hpt372a __devinitdata = { | ||
465 | .chip_type = HPT372A, | ||
466 | .max_mode = HPT372_ALLOW_ATA133_6 ? 4 : 3, | ||
467 | .dpll_clk = 66, | ||
468 | .settings = hpt37x_settings | ||
469 | }; | ||
470 | |||
471 | static struct hpt_info hpt302 __devinitdata = { | ||
472 | .chip_type = HPT302, | ||
473 | .max_mode = HPT302_ALLOW_ATA133_6 ? 4 : 3, | ||
474 | .dpll_clk = 66, | ||
475 | .settings = hpt37x_settings | ||
476 | }; | ||
477 | |||
478 | static struct hpt_info hpt371 __devinitdata = { | ||
479 | .chip_type = HPT371, | ||
480 | .max_mode = HPT371_ALLOW_ATA133_6 ? 4 : 3, | ||
481 | .dpll_clk = 66, | ||
482 | .settings = hpt37x_settings | ||
483 | }; | ||
484 | |||
485 | static struct hpt_info hpt372n __devinitdata = { | ||
486 | .chip_type = HPT372N, | ||
487 | .max_mode = HPT372_ALLOW_ATA133_6 ? 4 : 3, | ||
488 | .dpll_clk = 77, | ||
489 | .settings = hpt37x_settings | ||
490 | }; | ||
491 | |||
492 | static struct hpt_info hpt302n __devinitdata = { | ||
493 | .chip_type = HPT302N, | ||
494 | .max_mode = HPT302_ALLOW_ATA133_6 ? 4 : 3, | ||
495 | .dpll_clk = 77, | ||
496 | }; | ||
497 | |||
498 | static struct hpt_info hpt371n __devinitdata = { | ||
499 | .chip_type = HPT371N, | ||
500 | .max_mode = HPT371_ALLOW_ATA133_6 ? 4 : 3, | ||
501 | .dpll_clk = 77, | ||
502 | .settings = hpt37x_settings | ||
503 | }; | ||
413 | 504 | ||
414 | static int check_in_drive_list(ide_drive_t *drive, const char **list) | 505 | static int check_in_drive_list(ide_drive_t *drive, const char **list) |
415 | { | 506 | { |
@@ -423,7 +514,7 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list) | |||
423 | 514 | ||
424 | static u8 hpt3xx_ratemask(ide_drive_t *drive) | 515 | static u8 hpt3xx_ratemask(ide_drive_t *drive) |
425 | { | 516 | { |
426 | struct hpt_info *info = ide_get_hwifdata(HWIF(drive)); | 517 | struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev); |
427 | u8 mode = info->max_mode; | 518 | u8 mode = info->max_mode; |
428 | 519 | ||
429 | if (!eighty_ninty_three(drive) && mode) | 520 | if (!eighty_ninty_three(drive) && mode) |
@@ -438,7 +529,8 @@ static u8 hpt3xx_ratemask(ide_drive_t *drive) | |||
438 | 529 | ||
439 | static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) | 530 | static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) |
440 | { | 531 | { |
441 | struct hpt_info *info = ide_get_hwifdata(HWIF(drive)); | 532 | struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev); |
533 | u8 chip_type = info->chip_type; | ||
442 | u8 mode = hpt3xx_ratemask(drive); | 534 | u8 mode = hpt3xx_ratemask(drive); |
443 | 535 | ||
444 | if (drive->media != ide_disk) | 536 | if (drive->media != ide_disk) |
@@ -446,21 +538,22 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) | |||
446 | 538 | ||
447 | switch (mode) { | 539 | switch (mode) { |
448 | case 0x04: | 540 | case 0x04: |
449 | speed = min(speed, (u8)XFER_UDMA_6); | 541 | speed = min_t(u8, speed, XFER_UDMA_6); |
450 | break; | 542 | break; |
451 | case 0x03: | 543 | case 0x03: |
452 | speed = min(speed, (u8)XFER_UDMA_5); | 544 | speed = min_t(u8, speed, XFER_UDMA_5); |
453 | if (info->revision >= 5) | 545 | if (chip_type >= HPT374) |
454 | break; | 546 | break; |
455 | if (!check_in_drive_list(drive, bad_ata100_5)) | 547 | if (!check_in_drive_list(drive, bad_ata100_5)) |
456 | goto check_bad_ata33; | 548 | goto check_bad_ata33; |
457 | /* fall thru */ | 549 | /* fall thru */ |
458 | case 0x02: | 550 | case 0x02: |
459 | speed = min_t(u8, speed, XFER_UDMA_4); | 551 | speed = min_t(u8, speed, XFER_UDMA_4); |
460 | /* | 552 | |
461 | * CHECK ME, Does this need to be set to 5 ?? | 553 | /* |
462 | */ | 554 | * CHECK ME, Does this need to be changed to HPT374 ?? |
463 | if (info->revision >= 3) | 555 | */ |
556 | if (chip_type >= HPT370) | ||
464 | goto check_bad_ata33; | 557 | goto check_bad_ata33; |
465 | if (HPT366_ALLOW_ATA66_4 && | 558 | if (HPT366_ALLOW_ATA66_4 && |
466 | !check_in_drive_list(drive, bad_ata66_4)) | 559 | !check_in_drive_list(drive, bad_ata66_4)) |
@@ -475,7 +568,7 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) | |||
475 | speed = min_t(u8, speed, XFER_UDMA_2); | 568 | speed = min_t(u8, speed, XFER_UDMA_2); |
476 | 569 | ||
477 | check_bad_ata33: | 570 | check_bad_ata33: |
478 | if (info->revision >= 4) | 571 | if (chip_type >= HPT370A) |
479 | break; | 572 | break; |
480 | if (!check_in_drive_list(drive, bad_ata33)) | 573 | if (!check_in_drive_list(drive, bad_ata33)) |
481 | break; | 574 | break; |
@@ -488,7 +581,7 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) | |||
488 | return speed; | 581 | return speed; |
489 | } | 582 | } |
490 | 583 | ||
491 | static u32 pci_bus_clock_list(u8 speed, u32 *chipset_table) | 584 | static u32 get_speed_setting(u8 speed, struct hpt_info *info) |
492 | { | 585 | { |
493 | int i; | 586 | int i; |
494 | 587 | ||
@@ -501,18 +594,23 @@ static u32 pci_bus_clock_list(u8 speed, u32 *chipset_table) | |||
501 | for (i = 0; i < ARRAY_SIZE(xfer_speeds) - 1; i++) | 594 | for (i = 0; i < ARRAY_SIZE(xfer_speeds) - 1; i++) |
502 | if (xfer_speeds[i] == speed) | 595 | if (xfer_speeds[i] == speed) |
503 | break; | 596 | break; |
504 | return chipset_table[i]; | 597 | /* |
598 | * NOTE: info->settings only points to the pointer | ||
599 | * to the list of the actual register values | ||
600 | */ | ||
601 | return (*info->settings)[i]; | ||
505 | } | 602 | } |
506 | 603 | ||
507 | static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed) | 604 | static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed) |
508 | { | 605 | { |
509 | ide_hwif_t *hwif = HWIF(drive); | 606 | ide_hwif_t *hwif = HWIF(drive); |
510 | struct pci_dev *dev = hwif->pci_dev; | 607 | struct pci_dev *dev = hwif->pci_dev; |
511 | struct hpt_info *info = ide_get_hwifdata (hwif); | 608 | struct hpt_info *info = pci_get_drvdata(dev); |
512 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); | 609 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); |
513 | u8 itr_addr = drive->dn ? 0x44 : 0x40; | 610 | u8 itr_addr = drive->dn ? 0x44 : 0x40; |
514 | u32 itr_mask = (speed < XFER_MW_DMA_0) ? 0x30070000 : 0xc0000000; | 611 | u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 : |
515 | u32 new_itr = pci_bus_clock_list(speed, info->speed); | 612 | (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff); |
613 | u32 new_itr = get_speed_setting(speed, info); | ||
516 | u32 old_itr = 0; | 614 | u32 old_itr = 0; |
517 | 615 | ||
518 | /* | 616 | /* |
@@ -532,11 +630,12 @@ static int hpt37x_tune_chipset(ide_drive_t *drive, u8 xferspeed) | |||
532 | { | 630 | { |
533 | ide_hwif_t *hwif = HWIF(drive); | 631 | ide_hwif_t *hwif = HWIF(drive); |
534 | struct pci_dev *dev = hwif->pci_dev; | 632 | struct pci_dev *dev = hwif->pci_dev; |
535 | struct hpt_info *info = ide_get_hwifdata (hwif); | 633 | struct hpt_info *info = pci_get_drvdata(dev); |
536 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); | 634 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); |
537 | u8 itr_addr = 0x40 + (drive->dn * 4); | 635 | u8 itr_addr = 0x40 + (drive->dn * 4); |
538 | u32 itr_mask = (speed < XFER_MW_DMA_0) ? 0x303c0000 : 0xc0000000; | 636 | u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 : |
539 | u32 new_itr = pci_bus_clock_list(speed, info->speed); | 637 | (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff); |
638 | u32 new_itr = get_speed_setting(speed, info); | ||
540 | u32 old_itr = 0; | 639 | u32 old_itr = 0; |
541 | 640 | ||
542 | pci_read_config_dword(dev, itr_addr, &old_itr); | 641 | pci_read_config_dword(dev, itr_addr, &old_itr); |
@@ -552,9 +651,9 @@ static int hpt37x_tune_chipset(ide_drive_t *drive, u8 xferspeed) | |||
552 | static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed) | 651 | static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed) |
553 | { | 652 | { |
554 | ide_hwif_t *hwif = HWIF(drive); | 653 | ide_hwif_t *hwif = HWIF(drive); |
555 | struct hpt_info *info = ide_get_hwifdata(hwif); | 654 | struct hpt_info *info = pci_get_drvdata(hwif->pci_dev); |
556 | 655 | ||
557 | if (info->revision >= 3) | 656 | if (info->chip_type >= HPT370) |
558 | return hpt37x_tune_chipset(drive, speed); | 657 | return hpt37x_tune_chipset(drive, speed); |
559 | else /* hpt368: hpt_minimum_revision(dev, 2) */ | 658 | else /* hpt368: hpt_minimum_revision(dev, 2) */ |
560 | return hpt36x_tune_chipset(drive, speed); | 659 | return hpt36x_tune_chipset(drive, speed); |
@@ -576,16 +675,10 @@ static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio) | |||
576 | static int config_chipset_for_dma(ide_drive_t *drive) | 675 | static int config_chipset_for_dma(ide_drive_t *drive) |
577 | { | 676 | { |
578 | u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive)); | 677 | u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive)); |
579 | ide_hwif_t *hwif = HWIF(drive); | ||
580 | struct hpt_info *info = ide_get_hwifdata(hwif); | ||
581 | 678 | ||
582 | if (!speed) | 679 | if (!speed) |
583 | return 0; | 680 | return 0; |
584 | 681 | ||
585 | /* If we don't have any timings we can't do a lot */ | ||
586 | if (info->speed == NULL) | ||
587 | return 0; | ||
588 | |||
589 | (void) hpt3xx_tune_chipset(drive, speed); | 682 | (void) hpt3xx_tune_chipset(drive, speed); |
590 | return ide_dma_enable(drive); | 683 | return ide_dma_enable(drive); |
591 | } | 684 | } |
@@ -615,10 +708,10 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask) | |||
615 | { | 708 | { |
616 | ide_hwif_t *hwif = HWIF(drive); | 709 | ide_hwif_t *hwif = HWIF(drive); |
617 | struct pci_dev *dev = hwif->pci_dev; | 710 | struct pci_dev *dev = hwif->pci_dev; |
618 | struct hpt_info *info = ide_get_hwifdata(hwif); | 711 | struct hpt_info *info = pci_get_drvdata(dev); |
619 | 712 | ||
620 | if (drive->quirk_list) { | 713 | if (drive->quirk_list) { |
621 | if (info->revision >= 3) { | 714 | if (info->chip_type >= HPT370) { |
622 | u8 scr1 = 0; | 715 | u8 scr1 = 0; |
623 | 716 | ||
624 | pci_read_config_byte(dev, 0x5a, &scr1); | 717 | pci_read_config_byte(dev, 0x5a, &scr1); |
@@ -778,40 +871,37 @@ static int hpt374_ide_dma_end(ide_drive_t *drive) | |||
778 | * @mode: clocking mode (0x21 for write, 0x23 otherwise) | 871 | * @mode: clocking mode (0x21 for write, 0x23 otherwise) |
779 | * | 872 | * |
780 | * Switch the DPLL clock on the HPT3xxN devices. This is a right mess. | 873 | * Switch the DPLL clock on the HPT3xxN devices. This is a right mess. |
781 | * NOTE: avoid touching the disabled primary channel on HPT371N -- it | ||
782 | * doesn't physically exist anyway... | ||
783 | */ | 874 | */ |
784 | 875 | ||
785 | static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode) | 876 | static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode) |
786 | { | 877 | { |
787 | u8 mcr1, scr2 = hwif->INB(hwif->dma_master + 0x7b); | 878 | u8 scr2 = hwif->INB(hwif->dma_master + 0x7b); |
788 | 879 | ||
789 | if ((scr2 & 0x7f) == mode) | 880 | if ((scr2 & 0x7f) == mode) |
790 | return; | 881 | return; |
791 | 882 | ||
792 | /* MISC. control register 1 has the channel enable bit... */ | ||
793 | mcr1 = hwif->INB(hwif->dma_master + 0x70); | ||
794 | |||
795 | /* Tristate the bus */ | 883 | /* Tristate the bus */ |
796 | if (mcr1 & 0x04) | 884 | hwif->OUTB(0x80, hwif->dma_master + 0x73); |
797 | hwif->OUTB(0x80, hwif->dma_master + 0x73); | ||
798 | hwif->OUTB(0x80, hwif->dma_master + 0x77); | 885 | hwif->OUTB(0x80, hwif->dma_master + 0x77); |
799 | 886 | ||
800 | /* Switch clock and reset channels */ | 887 | /* Switch clock and reset channels */ |
801 | hwif->OUTB(mode, hwif->dma_master + 0x7b); | 888 | hwif->OUTB(mode, hwif->dma_master + 0x7b); |
802 | hwif->OUTB(0xc0, hwif->dma_master + 0x79); | 889 | hwif->OUTB(0xc0, hwif->dma_master + 0x79); |
803 | 890 | ||
804 | /* Reset state machines */ | 891 | /* |
805 | if (mcr1 & 0x04) | 892 | * Reset the state machines. |
806 | hwif->OUTB(0x37, hwif->dma_master + 0x70); | 893 | * NOTE: avoid accidentally enabling the disabled channels. |
807 | hwif->OUTB(0x37, hwif->dma_master + 0x74); | 894 | */ |
895 | hwif->OUTB(hwif->INB(hwif->dma_master + 0x70) | 0x32, | ||
896 | hwif->dma_master + 0x70); | ||
897 | hwif->OUTB(hwif->INB(hwif->dma_master + 0x74) | 0x32, | ||
898 | hwif->dma_master + 0x74); | ||
808 | 899 | ||
809 | /* Complete reset */ | 900 | /* Complete reset */ |
810 | hwif->OUTB(0x00, hwif->dma_master + 0x79); | 901 | hwif->OUTB(0x00, hwif->dma_master + 0x79); |
811 | 902 | ||
812 | /* Reconnect channels to bus */ | 903 | /* Reconnect channels to bus */ |
813 | if (mcr1 & 0x04) | 904 | hwif->OUTB(0x00, hwif->dma_master + 0x73); |
814 | hwif->OUTB(0x00, hwif->dma_master + 0x73); | ||
815 | hwif->OUTB(0x00, hwif->dma_master + 0x77); | 905 | hwif->OUTB(0x00, hwif->dma_master + 0x77); |
816 | } | 906 | } |
817 | 907 | ||
@@ -826,10 +916,7 @@ static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode) | |||
826 | 916 | ||
827 | static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq) | 917 | static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq) |
828 | { | 918 | { |
829 | ide_hwif_t *hwif = HWIF(drive); | 919 | hpt3xxn_set_clock(HWIF(drive), rq_data_dir(rq) ? 0x23 : 0x21); |
830 | u8 wantclock = rq_data_dir(rq) ? 0x23 : 0x21; | ||
831 | |||
832 | hpt3xxn_set_clock(hwif, wantclock); | ||
833 | } | 920 | } |
834 | 921 | ||
835 | /* | 922 | /* |
@@ -890,223 +977,293 @@ static int hpt3xx_busproc(ide_drive_t *drive, int state) | |||
890 | return 0; | 977 | return 0; |
891 | } | 978 | } |
892 | 979 | ||
893 | static void __devinit hpt366_clocking(ide_hwif_t *hwif) | 980 | /** |
981 | * hpt37x_calibrate_dpll - calibrate the DPLL | ||
982 | * @dev: PCI device | ||
983 | * | ||
984 | * Perform a calibration cycle on the DPLL. | ||
985 | * Returns 1 if this succeeds | ||
986 | */ | ||
987 | static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high) | ||
894 | { | 988 | { |
895 | u32 itr1 = 0; | 989 | u32 dpll = (f_high << 16) | f_low | 0x100; |
896 | struct hpt_info *info = ide_get_hwifdata(hwif); | 990 | u8 scr2; |
991 | int i; | ||
897 | 992 | ||
898 | pci_read_config_dword(hwif->pci_dev, 0x40, &itr1); | 993 | pci_write_config_dword(dev, 0x5c, dpll); |
899 | 994 | ||
900 | /* detect bus speed by looking at control reg timing: */ | 995 | /* Wait for oscillator ready */ |
901 | switch((itr1 >> 8) & 7) { | 996 | for(i = 0; i < 0x5000; ++i) { |
902 | case 5: | 997 | udelay(50); |
903 | info->speed = forty_base_hpt36x; | 998 | pci_read_config_byte(dev, 0x5b, &scr2); |
904 | break; | 999 | if (scr2 & 0x80) |
905 | case 9: | ||
906 | info->speed = twenty_five_base_hpt36x; | ||
907 | break; | ||
908 | case 7: | ||
909 | default: | ||
910 | info->speed = thirty_three_base_hpt36x; | ||
911 | break; | 1000 | break; |
912 | } | 1001 | } |
1002 | /* See if it stays ready (we'll just bail out if it's not yet) */ | ||
1003 | for(i = 0; i < 0x1000; ++i) { | ||
1004 | pci_read_config_byte(dev, 0x5b, &scr2); | ||
1005 | /* DPLL destabilized? */ | ||
1006 | if(!(scr2 & 0x80)) | ||
1007 | return 0; | ||
1008 | } | ||
1009 | /* Turn off tuning, we have the DPLL set */ | ||
1010 | pci_read_config_dword (dev, 0x5c, &dpll); | ||
1011 | pci_write_config_dword(dev, 0x5c, (dpll & ~0x100)); | ||
1012 | return 1; | ||
913 | } | 1013 | } |
914 | 1014 | ||
915 | static void __devinit hpt37x_clocking(ide_hwif_t *hwif) | 1015 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) |
916 | { | 1016 | { |
917 | struct hpt_info *info = ide_get_hwifdata(hwif); | 1017 | struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL); |
918 | struct pci_dev *dev = hwif->pci_dev; | 1018 | unsigned long io_base = pci_resource_start(dev, 4); |
919 | char *name = hwif->cds->name; | 1019 | u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ |
920 | int adjust, i; | 1020 | enum ata_clock clock; |
921 | u16 freq = 0; | 1021 | |
922 | u32 pll, temp = 0; | 1022 | if (info == NULL) { |
923 | u8 scr2 = 0, mcr1 = 0; | 1023 | printk(KERN_ERR "%s: out of memory!\n", name); |
924 | 1024 | return -ENOMEM; | |
1025 | } | ||
1026 | |||
925 | /* | 1027 | /* |
926 | * default to pci clock. make sure MA15/16 are set to output | 1028 | * Copy everything from a static "template" structure |
927 | * to prevent drives having problems with 40-pin cables. Needed | 1029 | * to just allocated per-chip hpt_info structure. |
928 | * for some drives such as IBM-DTLA which will not enter ready | ||
929 | * state on reset when PDIAG is a input. | ||
930 | * | ||
931 | * ToDo: should we set 0x21 when using PLL mode ? | ||
932 | */ | 1030 | */ |
933 | pci_write_config_byte(dev, 0x5b, 0x23); | 1031 | *info = *(struct hpt_info *)pci_get_drvdata(dev); |
934 | 1032 | ||
935 | /* | 1033 | /* |
936 | * We'll have to read f_CNT value in order to determine | 1034 | * FIXME: Not portable. Also, why do we enable the ROM in the first place? |
937 | * the PCI clock frequency according to the following ratio: | 1035 | * We don't seem to be using it. |
938 | * | ||
939 | * f_CNT = Fpci * 192 / Fdpll | ||
940 | * | ||
941 | * First try reading the register in which the HighPoint BIOS | ||
942 | * saves f_CNT value before reprogramming the DPLL from its | ||
943 | * default setting (which differs for the various chips). | ||
944 | * NOTE: This register is only accessible via I/O space. | ||
945 | * | ||
946 | * In case the signature check fails, we'll have to resort to | ||
947 | * reading the f_CNT register itself in hopes that nobody has | ||
948 | * touched the DPLL yet... | ||
949 | */ | 1036 | */ |
950 | temp = inl(pci_resource_start(dev, 4) + 0x90); | 1037 | if (dev->resource[PCI_ROM_RESOURCE].start) |
951 | if ((temp & 0xFFFFF000) != 0xABCDE000) { | 1038 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, |
952 | printk(KERN_WARNING "%s: no clock data saved by BIOS\n", name); | 1039 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); |
953 | 1040 | ||
954 | /* Calculate the average value of f_CNT */ | 1041 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); |
955 | for (temp = i = 0; i < 128; i++) { | 1042 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); |
956 | pci_read_config_word(dev, 0x78, &freq); | 1043 | pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); |
957 | temp += freq & 0x1ff; | 1044 | pci_write_config_byte(dev, PCI_MAX_LAT, 0x08); |
958 | mdelay(1); | ||
959 | } | ||
960 | freq = temp / 128; | ||
961 | } else | ||
962 | freq = temp & 0x1ff; | ||
963 | 1045 | ||
964 | /* | 1046 | /* |
965 | * HPT3xxN chips use different PCI clock information. | 1047 | * First, try to estimate the PCI clock frequency... |
966 | * Currently we always set up the PLL for them. | ||
967 | */ | 1048 | */ |
1049 | if (info->chip_type >= HPT370) { | ||
1050 | u8 scr1 = 0; | ||
1051 | u16 f_cnt = 0; | ||
1052 | u32 temp = 0; | ||
1053 | |||
1054 | /* Interrupt force enable. */ | ||
1055 | pci_read_config_byte(dev, 0x5a, &scr1); | ||
1056 | if (scr1 & 0x10) | ||
1057 | pci_write_config_byte(dev, 0x5a, scr1 & ~0x10); | ||
1058 | |||
1059 | /* | ||
1060 | * HighPoint does this for HPT372A. | ||
1061 | * NOTE: This register is only writeable via I/O space. | ||
1062 | */ | ||
1063 | if (info->chip_type == HPT372A) | ||
1064 | outb(0x0e, io_base + 0x9c); | ||
1065 | |||
1066 | /* | ||
1067 | * Default to PCI clock. Make sure MA15/16 are set to output | ||
1068 | * to prevent drives having problems with 40-pin cables. | ||
1069 | */ | ||
1070 | pci_write_config_byte(dev, 0x5b, 0x23); | ||
968 | 1071 | ||
969 | if (info->flags & IS_3xxN) { | 1072 | /* |
970 | if(freq < 0x55) | 1073 | * We'll have to read f_CNT value in order to determine |
971 | pll = F_LOW_PCI_33; | 1074 | * the PCI clock frequency according to the following ratio: |
972 | else if(freq < 0x70) | 1075 | * |
973 | pll = F_LOW_PCI_40; | 1076 | * f_CNT = Fpci * 192 / Fdpll |
974 | else if(freq < 0x7F) | 1077 | * |
975 | pll = F_LOW_PCI_50; | 1078 | * First try reading the register in which the HighPoint BIOS |
1079 | * saves f_CNT value before reprogramming the DPLL from its | ||
1080 | * default setting (which differs for the various chips). | ||
1081 | * NOTE: This register is only accessible via I/O space. | ||
1082 | * | ||
1083 | * In case the signature check fails, we'll have to resort to | ||
1084 | * reading the f_CNT register itself in hopes that nobody has | ||
1085 | * touched the DPLL yet... | ||
1086 | */ | ||
1087 | temp = inl(io_base + 0x90); | ||
1088 | if ((temp & 0xFFFFF000) != 0xABCDE000) { | ||
1089 | int i; | ||
1090 | |||
1091 | printk(KERN_WARNING "%s: no clock data saved by BIOS\n", | ||
1092 | name); | ||
1093 | |||
1094 | /* Calculate the average value of f_CNT. */ | ||
1095 | for (temp = i = 0; i < 128; i++) { | ||
1096 | pci_read_config_word(dev, 0x78, &f_cnt); | ||
1097 | temp += f_cnt & 0x1ff; | ||
1098 | mdelay(1); | ||
1099 | } | ||
1100 | f_cnt = temp / 128; | ||
1101 | } else | ||
1102 | f_cnt = temp & 0x1ff; | ||
1103 | |||
1104 | dpll_clk = info->dpll_clk; | ||
1105 | pci_clk = (f_cnt * dpll_clk) / 192; | ||
1106 | |||
1107 | /* Clamp PCI clock to bands. */ | ||
1108 | if (pci_clk < 40) | ||
1109 | pci_clk = 33; | ||
1110 | else if(pci_clk < 45) | ||
1111 | pci_clk = 40; | ||
1112 | else if(pci_clk < 55) | ||
1113 | pci_clk = 50; | ||
976 | else | 1114 | else |
977 | pll = F_LOW_PCI_66; | 1115 | pci_clk = 66; |
978 | 1116 | ||
1117 | printk(KERN_INFO "%s: DPLL base: %d MHz, f_CNT: %d, " | ||
1118 | "assuming %d MHz PCI\n", name, dpll_clk, f_cnt, pci_clk); | ||
979 | } else { | 1119 | } else { |
980 | if(freq < 0x9C) | 1120 | u32 itr1 = 0; |
981 | pll = F_LOW_PCI_33; | 1121 | |
982 | else if(freq < 0xb0) | 1122 | pci_read_config_dword(dev, 0x40, &itr1); |
983 | pll = F_LOW_PCI_40; | 1123 | |
984 | else if(freq <0xc8) | 1124 | /* Detect PCI clock by looking at cmd_high_time. */ |
985 | pll = F_LOW_PCI_50; | 1125 | switch((itr1 >> 8) & 0x07) { |
986 | else | 1126 | case 0x09: |
987 | pll = F_LOW_PCI_66; | 1127 | pci_clk = 40; |
988 | } | 1128 | case 0x05: |
989 | printk(KERN_INFO "%s: FREQ: %d, PLL: %d\n", name, freq, pll); | 1129 | pci_clk = 25; |
990 | 1130 | case 0x07: | |
991 | if (!(info->flags & IS_3xxN)) { | 1131 | default: |
992 | if (pll == F_LOW_PCI_33) { | 1132 | pci_clk = 33; |
993 | info->speed = thirty_three_base_hpt37x; | ||
994 | printk(KERN_DEBUG "%s: using 33MHz PCI clock\n", name); | ||
995 | } else if (pll == F_LOW_PCI_40) { | ||
996 | /* Unsupported */ | ||
997 | } else if (pll == F_LOW_PCI_50) { | ||
998 | info->speed = fifty_base_hpt37x; | ||
999 | printk(KERN_DEBUG "%s: using 50MHz PCI clock\n", name); | ||
1000 | } else { | ||
1001 | info->speed = sixty_six_base_hpt37x; | ||
1002 | printk(KERN_DEBUG "%s: using 66MHz PCI clock\n", name); | ||
1003 | } | 1133 | } |
1004 | } | 1134 | } |
1005 | 1135 | ||
1006 | if (pll == F_LOW_PCI_66) | 1136 | /* Let's assume we'll use PCI clock for the ATA clock... */ |
1007 | info->flags |= PCI_66MHZ; | 1137 | switch (pci_clk) { |
1138 | case 25: | ||
1139 | clock = ATA_CLOCK_25MHZ; | ||
1140 | break; | ||
1141 | case 33: | ||
1142 | default: | ||
1143 | clock = ATA_CLOCK_33MHZ; | ||
1144 | break; | ||
1145 | case 40: | ||
1146 | clock = ATA_CLOCK_40MHZ; | ||
1147 | break; | ||
1148 | case 50: | ||
1149 | clock = ATA_CLOCK_50MHZ; | ||
1150 | break; | ||
1151 | case 66: | ||
1152 | clock = ATA_CLOCK_66MHZ; | ||
1153 | break; | ||
1154 | } | ||
1008 | 1155 | ||
1009 | /* | 1156 | /* |
1010 | * only try the pll if we don't have a table for the clock | 1157 | * Only try the DPLL if we don't have a table for the PCI clock that |
1011 | * speed that we're running at. NOTE: the internal PLL will | 1158 | * we are running at for HPT370/A, always use it for anything newer... |
1012 | * result in slow reads when using a 33MHz PCI clock. we also | ||
1013 | * don't like to use the PLL because it will cause glitches | ||
1014 | * on PRST/SRST when the HPT state engine gets reset. | ||
1015 | * | 1159 | * |
1016 | * ToDo: Use 66MHz PLL when ATA133 devices are present on a | 1160 | * NOTE: Using the internal DPLL results in slow reads on 33 MHz PCI. |
1017 | * 372 device so we can get ATA133 support | 1161 | * We also don't like using the DPLL because this causes glitches |
1162 | * on PRST-/SRST- when the state engine gets reset... | ||
1018 | */ | 1163 | */ |
1019 | if (info->speed) | 1164 | if (info->chip_type >= HPT374 || info->settings[clock] == NULL) { |
1020 | goto init_hpt37X_done; | 1165 | u16 f_low, delta = pci_clk < 50 ? 2 : 4; |
1166 | int adjust; | ||
1167 | |||
1168 | /* | ||
1169 | * Select 66 MHz DPLL clock only if UltraATA/133 mode is | ||
1170 | * supported/enabled, use 50 MHz DPLL clock otherwise... | ||
1171 | */ | ||
1172 | if (info->max_mode == 0x04) { | ||
1173 | dpll_clk = 66; | ||
1174 | clock = ATA_CLOCK_66MHZ; | ||
1175 | } else if (dpll_clk) { /* HPT36x chips don't have DPLL */ | ||
1176 | dpll_clk = 50; | ||
1177 | clock = ATA_CLOCK_50MHZ; | ||
1178 | } | ||
1021 | 1179 | ||
1022 | info->flags |= PLL_MODE; | 1180 | if (info->settings[clock] == NULL) { |
1023 | 1181 | printk(KERN_ERR "%s: unknown bus timing!\n", name); | |
1024 | /* | 1182 | kfree(info); |
1025 | * Adjust the PLL based upon the PCI clock, enable it, and | 1183 | return -EIO; |
1026 | * wait for stabilization... | ||
1027 | */ | ||
1028 | adjust = 0; | ||
1029 | freq = (pll < F_LOW_PCI_50) ? 2 : 4; | ||
1030 | while (adjust++ < 6) { | ||
1031 | pci_write_config_dword(dev, 0x5c, (freq + pll) << 16 | | ||
1032 | pll | 0x100); | ||
1033 | |||
1034 | /* wait for clock stabilization */ | ||
1035 | for (i = 0; i < 0x50000; i++) { | ||
1036 | pci_read_config_byte(dev, 0x5b, &scr2); | ||
1037 | if (scr2 & 0x80) { | ||
1038 | /* spin looking for the clock to destabilize */ | ||
1039 | for (i = 0; i < 0x1000; ++i) { | ||
1040 | pci_read_config_byte(dev, 0x5b, | ||
1041 | &scr2); | ||
1042 | if ((scr2 & 0x80) == 0) | ||
1043 | goto pll_recal; | ||
1044 | } | ||
1045 | pci_read_config_dword(dev, 0x5c, &pll); | ||
1046 | pci_write_config_dword(dev, 0x5c, | ||
1047 | pll & ~0x100); | ||
1048 | pci_write_config_byte(dev, 0x5b, 0x21); | ||
1049 | |||
1050 | info->speed = fifty_base_hpt37x; | ||
1051 | printk("%s: using 50MHz internal PLL\n", name); | ||
1052 | goto init_hpt37X_done; | ||
1053 | } | ||
1054 | } | 1184 | } |
1055 | pll_recal: | ||
1056 | if (adjust & 1) | ||
1057 | pll -= (adjust >> 1); | ||
1058 | else | ||
1059 | pll += (adjust >> 1); | ||
1060 | } | ||
1061 | 1185 | ||
1062 | init_hpt37X_done: | 1186 | /* Select the DPLL clock. */ |
1063 | if (!info->speed) | 1187 | pci_write_config_byte(dev, 0x5b, 0x21); |
1064 | printk(KERN_ERR "%s: unknown bus timing [%d %d].\n", | 1188 | |
1065 | name, pll, freq); | 1189 | /* |
1066 | /* | 1190 | * Adjust the DPLL based upon PCI clock, enable it, |
1067 | * Reset the state engines. | 1191 | * and wait for stabilization... |
1068 | * NOTE: avoid accidentally enabling the primary channel on HPT371N. | 1192 | */ |
1069 | */ | 1193 | f_low = (pci_clk * 48) / dpll_clk; |
1070 | pci_read_config_byte(dev, 0x50, &mcr1); | 1194 | |
1071 | if (mcr1 & 0x04) | 1195 | for (adjust = 0; adjust < 8; adjust++) { |
1072 | pci_write_config_byte(dev, 0x50, 0x37); | 1196 | if(hpt37x_calibrate_dpll(dev, f_low, f_low + delta)) |
1073 | pci_write_config_byte(dev, 0x54, 0x37); | 1197 | break; |
1074 | udelay(100); | 1198 | |
1075 | } | 1199 | /* |
1200 | * See if it'll settle at a fractionally different clock | ||
1201 | */ | ||
1202 | if (adjust & 1) | ||
1203 | f_low -= adjust >> 1; | ||
1204 | else | ||
1205 | f_low += adjust >> 1; | ||
1206 | } | ||
1207 | if (adjust == 8) { | ||
1208 | printk(KERN_ERR "%s: DPLL did not stabilize!\n", name); | ||
1209 | kfree(info); | ||
1210 | return -EIO; | ||
1211 | } | ||
1212 | |||
1213 | printk("%s: using %d MHz DPLL clock\n", name, dpll_clk); | ||
1214 | } else { | ||
1215 | /* Mark the fact that we're not using the DPLL. */ | ||
1216 | dpll_clk = 0; | ||
1217 | |||
1218 | printk("%s: using %d MHz PCI clock\n", name, pci_clk); | ||
1219 | } | ||
1076 | 1220 | ||
1077 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) | ||
1078 | { | ||
1079 | /* | 1221 | /* |
1080 | * FIXME: Not portable. Also, why do we enable the ROM in the first place? | 1222 | * Advance the table pointer to a slot which points to the list |
1081 | * We don't seem to be using it. | 1223 | * of the register values settings matching the clock being used. |
1082 | */ | 1224 | */ |
1083 | if (dev->resource[PCI_ROM_RESOURCE].start) | 1225 | info->settings += clock; |
1084 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
1085 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
1086 | 1226 | ||
1087 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); | 1227 | /* Store the clock frequencies. */ |
1088 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); | 1228 | info->dpll_clk = dpll_clk; |
1089 | pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); | 1229 | info->pci_clk = pci_clk; |
1090 | pci_write_config_byte(dev, PCI_MAX_LAT, 0x08); | ||
1091 | 1230 | ||
1092 | if (hpt_revision(dev) >= 3) { | 1231 | /* Point to this chip's own instance of the hpt_info structure. */ |
1093 | u8 scr1 = 0; | 1232 | pci_set_drvdata(dev, info); |
1094 | 1233 | ||
1095 | /* Interrupt force enable. */ | 1234 | if (info->chip_type >= HPT370) { |
1096 | pci_read_config_byte(dev, 0x5a, &scr1); | 1235 | u8 mcr1, mcr4; |
1097 | if (scr1 & 0x10) | 1236 | |
1098 | pci_write_config_byte(dev, 0x5a, scr1 & ~0x10); | 1237 | /* |
1238 | * Reset the state engines. | ||
1239 | * NOTE: Avoid accidentally enabling the disabled channels. | ||
1240 | */ | ||
1241 | pci_read_config_byte (dev, 0x50, &mcr1); | ||
1242 | pci_read_config_byte (dev, 0x54, &mcr4); | ||
1243 | pci_write_config_byte(dev, 0x50, (mcr1 | 0x32)); | ||
1244 | pci_write_config_byte(dev, 0x54, (mcr4 | 0x32)); | ||
1245 | udelay(100); | ||
1099 | } | 1246 | } |
1100 | 1247 | ||
1248 | /* | ||
1249 | * On HPT371N, if ATA clock is 66 MHz we must set bit 2 in | ||
1250 | * the MISC. register to stretch the UltraDMA Tss timing. | ||
1251 | * NOTE: This register is only writeable via I/O space. | ||
1252 | */ | ||
1253 | if (info->chip_type == HPT371N && clock == ATA_CLOCK_66MHZ) | ||
1254 | |||
1255 | outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c); | ||
1256 | |||
1101 | return dev->irq; | 1257 | return dev->irq; |
1102 | } | 1258 | } |
1103 | 1259 | ||
1104 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | 1260 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) |
1105 | { | 1261 | { |
1106 | struct pci_dev *dev = hwif->pci_dev; | 1262 | struct pci_dev *dev = hwif->pci_dev; |
1107 | struct hpt_info *info = ide_get_hwifdata(hwif); | 1263 | struct hpt_info *info = pci_get_drvdata(dev); |
1108 | int serialize = HPT_SERIALIZE_IO; | 1264 | int serialize = HPT_SERIALIZE_IO; |
1109 | u8 scr1 = 0, ata66 = (hwif->channel) ? 0x01 : 0x02; | 1265 | u8 scr1 = 0, ata66 = (hwif->channel) ? 0x01 : 0x02; |
1266 | u8 chip_type = info->chip_type; | ||
1110 | u8 new_mcr, old_mcr = 0; | 1267 | u8 new_mcr, old_mcr = 0; |
1111 | 1268 | ||
1112 | /* Cache the channel's MISC. control registers' offset */ | 1269 | /* Cache the channel's MISC. control registers' offset */ |
@@ -1125,7 +1282,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | |||
1125 | * - on 33 MHz PCI we must clock switch | 1282 | * - on 33 MHz PCI we must clock switch |
1126 | * - on 66 MHz PCI we must NOT use the PCI clock | 1283 | * - on 66 MHz PCI we must NOT use the PCI clock |
1127 | */ | 1284 | */ |
1128 | if ((info->flags & (IS_3xxN | PCI_66MHZ)) == IS_3xxN) { | 1285 | if (chip_type >= HPT372N && info->dpll_clk && info->pci_clk < 66) { |
1129 | /* | 1286 | /* |
1130 | * Clock is shared between the channels, | 1287 | * Clock is shared between the channels, |
1131 | * so we'll have to serialize them... :-( | 1288 | * so we'll have to serialize them... :-( |
@@ -1144,9 +1301,9 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | |||
1144 | */ | 1301 | */ |
1145 | pci_read_config_byte(dev, hwif->select_data + 1, &old_mcr); | 1302 | pci_read_config_byte(dev, hwif->select_data + 1, &old_mcr); |
1146 | 1303 | ||
1147 | if (info->revision >= 5) /* HPT372 and newer */ | 1304 | if (info->chip_type >= HPT374) |
1148 | new_mcr = old_mcr & ~0x07; | 1305 | new_mcr = old_mcr & ~0x07; |
1149 | else if (info->revision >= 3) { /* HPT370 and HPT370A */ | 1306 | else if (info->chip_type >= HPT370) { |
1150 | new_mcr = old_mcr; | 1307 | new_mcr = old_mcr; |
1151 | new_mcr &= ~0x02; | 1308 | new_mcr &= ~0x02; |
1152 | 1309 | ||
@@ -1174,7 +1331,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | |||
1174 | * address lines to access an external EEPROM. To read valid | 1331 | * address lines to access an external EEPROM. To read valid |
1175 | * cable detect state the pins must be enabled as inputs. | 1332 | * cable detect state the pins must be enabled as inputs. |
1176 | */ | 1333 | */ |
1177 | if (info->revision >= 8 && (PCI_FUNC(dev->devfn) & 1)) { | 1334 | if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) { |
1178 | /* | 1335 | /* |
1179 | * HPT374 PCI function 1 | 1336 | * HPT374 PCI function 1 |
1180 | * - set bit 15 of reg 0x52 to enable TCBLID as input | 1337 | * - set bit 15 of reg 0x52 to enable TCBLID as input |
@@ -1188,7 +1345,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | |||
1188 | /* now read cable id register */ | 1345 | /* now read cable id register */ |
1189 | pci_read_config_byte (dev, 0x5a, &scr1); | 1346 | pci_read_config_byte (dev, 0x5a, &scr1); |
1190 | pci_write_config_word(dev, mcr_addr, mcr); | 1347 | pci_write_config_word(dev, mcr_addr, mcr); |
1191 | } else if (info->revision >= 3) { | 1348 | } else if (chip_type >= HPT370) { |
1192 | /* | 1349 | /* |
1193 | * HPT370/372 and 374 pcifn 0 | 1350 | * HPT370/372 and 374 pcifn 0 |
1194 | * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs | 1351 | * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs |
@@ -1208,10 +1365,10 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | |||
1208 | 1365 | ||
1209 | hwif->ide_dma_check = &hpt366_config_drive_xfer_rate; | 1366 | hwif->ide_dma_check = &hpt366_config_drive_xfer_rate; |
1210 | 1367 | ||
1211 | if (info->revision >= 5) { | 1368 | if (chip_type >= HPT374) { |
1212 | hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; | 1369 | hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; |
1213 | hwif->ide_dma_end = &hpt374_ide_dma_end; | 1370 | hwif->ide_dma_end = &hpt374_ide_dma_end; |
1214 | } else if (info->revision >= 3) { | 1371 | } else if (chip_type >= HPT370) { |
1215 | hwif->dma_start = &hpt370_ide_dma_start; | 1372 | hwif->dma_start = &hpt370_ide_dma_start; |
1216 | hwif->ide_dma_end = &hpt370_ide_dma_end; | 1373 | hwif->ide_dma_end = &hpt370_ide_dma_end; |
1217 | hwif->ide_dma_timeout = &hpt370_ide_dma_timeout; | 1374 | hwif->ide_dma_timeout = &hpt370_ide_dma_timeout; |
@@ -1226,7 +1383,6 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | |||
1226 | static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) | 1383 | static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) |
1227 | { | 1384 | { |
1228 | struct pci_dev *dev = hwif->pci_dev; | 1385 | struct pci_dev *dev = hwif->pci_dev; |
1229 | struct hpt_info *info = ide_get_hwifdata(hwif); | ||
1230 | u8 masterdma = 0, slavedma = 0; | 1386 | u8 masterdma = 0, slavedma = 0; |
1231 | u8 dma_new = 0, dma_old = 0; | 1387 | u8 dma_new = 0, dma_old = 0; |
1232 | unsigned long flags; | 1388 | unsigned long flags; |
@@ -1234,12 +1390,6 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) | |||
1234 | if (!dmabase) | 1390 | if (!dmabase) |
1235 | return; | 1391 | return; |
1236 | 1392 | ||
1237 | if(info->speed == NULL) { | ||
1238 | printk(KERN_WARNING "%s: no known IDE timings, disabling DMA.\n", | ||
1239 | hwif->cds->name); | ||
1240 | return; | ||
1241 | } | ||
1242 | |||
1243 | dma_old = hwif->INB(dmabase + 2); | 1393 | dma_old = hwif->INB(dmabase + 2); |
1244 | 1394 | ||
1245 | local_irq_save(flags); | 1395 | local_irq_save(flags); |
@@ -1258,60 +1408,6 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) | |||
1258 | ide_setup_dma(hwif, dmabase, 8); | 1408 | ide_setup_dma(hwif, dmabase, 8); |
1259 | } | 1409 | } |
1260 | 1410 | ||
1261 | /* | ||
1262 | * We "borrow" this hook in order to set the data structures | ||
1263 | * up early enough before dma or init_hwif calls are made. | ||
1264 | */ | ||
1265 | |||
1266 | static void __devinit init_iops_hpt366(ide_hwif_t *hwif) | ||
1267 | { | ||
1268 | struct hpt_info *info = kzalloc(sizeof(struct hpt_info), GFP_KERNEL); | ||
1269 | struct pci_dev *dev = hwif->pci_dev; | ||
1270 | u16 did = dev->device; | ||
1271 | u8 mode, rid = 0; | ||
1272 | |||
1273 | if(info == NULL) { | ||
1274 | printk(KERN_WARNING "%s: out of memory.\n", hwif->cds->name); | ||
1275 | return; | ||
1276 | } | ||
1277 | ide_set_hwifdata(hwif, info); | ||
1278 | |||
1279 | /* Avoid doing the same thing twice. */ | ||
1280 | if (hwif->channel && hwif->mate) { | ||
1281 | memcpy(info, ide_get_hwifdata(hwif->mate), sizeof(struct hpt_info)); | ||
1282 | return; | ||
1283 | } | ||
1284 | |||
1285 | pci_read_config_byte(dev, PCI_REVISION_ID, &rid); | ||
1286 | |||
1287 | if (( did == PCI_DEVICE_ID_TTI_HPT366 && rid == 6) || | ||
1288 | ((did == PCI_DEVICE_ID_TTI_HPT372 || | ||
1289 | did == PCI_DEVICE_ID_TTI_HPT302 || | ||
1290 | did == PCI_DEVICE_ID_TTI_HPT371) && rid > 1) || | ||
1291 | did == PCI_DEVICE_ID_TTI_HPT372N) | ||
1292 | info->flags |= IS_3xxN; | ||
1293 | |||
1294 | rid = info->revision = hpt_revision(dev); | ||
1295 | if (rid >= 8) /* HPT374 */ | ||
1296 | mode = HPT374_ALLOW_ATA133_6 ? 4 : 3; | ||
1297 | else if (rid >= 7) /* HPT371 and HPT371N */ | ||
1298 | mode = HPT371_ALLOW_ATA133_6 ? 4 : 3; | ||
1299 | else if (rid >= 6) /* HPT302 and HPT302N */ | ||
1300 | mode = HPT302_ALLOW_ATA133_6 ? 4 : 3; | ||
1301 | else if (rid >= 5) /* HPT372, HPT372A, and HPT372N */ | ||
1302 | mode = HPT372_ALLOW_ATA133_6 ? 4 : 3; | ||
1303 | else if (rid >= 3) /* HPT370 and HPT370A */ | ||
1304 | mode = HPT370_ALLOW_ATA100_5 ? 3 : 2; | ||
1305 | else /* HPT366 and HPT368 */ | ||
1306 | mode = (HPT366_ALLOW_ATA66_4 || HPT366_ALLOW_ATA66_3) ? 2 : 1; | ||
1307 | info->max_mode = mode; | ||
1308 | |||
1309 | if (rid >= 3) | ||
1310 | hpt37x_clocking(hwif); | ||
1311 | else | ||
1312 | hpt366_clocking(hwif); | ||
1313 | } | ||
1314 | |||
1315 | static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) | 1411 | static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) |
1316 | { | 1412 | { |
1317 | struct pci_dev *dev2; | 1413 | struct pci_dev *dev2; |
@@ -1319,9 +1415,13 @@ static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) | |||
1319 | if (PCI_FUNC(dev->devfn) & 1) | 1415 | if (PCI_FUNC(dev->devfn) & 1) |
1320 | return -ENODEV; | 1416 | return -ENODEV; |
1321 | 1417 | ||
1418 | pci_set_drvdata(dev, &hpt374); | ||
1419 | |||
1322 | if ((dev2 = pci_get_slot(dev->bus, dev->devfn + 1)) != NULL) { | 1420 | if ((dev2 = pci_get_slot(dev->bus, dev->devfn + 1)) != NULL) { |
1323 | int ret; | 1421 | int ret; |
1324 | 1422 | ||
1423 | pci_set_drvdata(dev2, &hpt374); | ||
1424 | |||
1325 | if (dev2->irq != dev->irq) { | 1425 | if (dev2->irq != dev->irq) { |
1326 | /* FIXME: we need a core pci_set_interrupt() */ | 1426 | /* FIXME: we need a core pci_set_interrupt() */ |
1327 | dev2->irq = dev->irq; | 1427 | dev2->irq = dev->irq; |
@@ -1338,18 +1438,25 @@ static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) | |||
1338 | 1438 | ||
1339 | static int __devinit init_setup_hpt372n(struct pci_dev *dev, ide_pci_device_t *d) | 1439 | static int __devinit init_setup_hpt372n(struct pci_dev *dev, ide_pci_device_t *d) |
1340 | { | 1440 | { |
1441 | pci_set_drvdata(dev, &hpt372n); | ||
1442 | |||
1341 | return ide_setup_pci_device(dev, d); | 1443 | return ide_setup_pci_device(dev, d); |
1342 | } | 1444 | } |
1343 | 1445 | ||
1344 | static int __devinit init_setup_hpt371(struct pci_dev *dev, ide_pci_device_t *d) | 1446 | static int __devinit init_setup_hpt371(struct pci_dev *dev, ide_pci_device_t *d) |
1345 | { | 1447 | { |
1448 | struct hpt_info *info; | ||
1346 | u8 rev = 0, mcr1 = 0; | 1449 | u8 rev = 0, mcr1 = 0; |
1347 | 1450 | ||
1348 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); | 1451 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); |
1349 | 1452 | ||
1350 | if (rev > 1) | 1453 | if (rev > 1) { |
1351 | d->name = "HPT371N"; | 1454 | d->name = "HPT371N"; |
1352 | 1455 | ||
1456 | info = &hpt371n; | ||
1457 | } else | ||
1458 | info = &hpt371; | ||
1459 | |||
1353 | /* | 1460 | /* |
1354 | * HPT371 chips physically have only one channel, the secondary one, | 1461 | * HPT371 chips physically have only one channel, the secondary one, |
1355 | * but the primary channel registers do exist! Go figure... | 1462 | * but the primary channel registers do exist! Go figure... |
@@ -1360,30 +1467,44 @@ static int __devinit init_setup_hpt371(struct pci_dev *dev, ide_pci_device_t *d) | |||
1360 | if (mcr1 & 0x04) | 1467 | if (mcr1 & 0x04) |
1361 | pci_write_config_byte(dev, 0x50, mcr1 & ~0x04); | 1468 | pci_write_config_byte(dev, 0x50, mcr1 & ~0x04); |
1362 | 1469 | ||
1470 | pci_set_drvdata(dev, info); | ||
1471 | |||
1363 | return ide_setup_pci_device(dev, d); | 1472 | return ide_setup_pci_device(dev, d); |
1364 | } | 1473 | } |
1365 | 1474 | ||
1366 | static int __devinit init_setup_hpt372a(struct pci_dev *dev, ide_pci_device_t *d) | 1475 | static int __devinit init_setup_hpt372a(struct pci_dev *dev, ide_pci_device_t *d) |
1367 | { | 1476 | { |
1477 | struct hpt_info *info; | ||
1368 | u8 rev = 0; | 1478 | u8 rev = 0; |
1369 | 1479 | ||
1370 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); | 1480 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); |
1371 | 1481 | ||
1372 | if (rev > 1) | 1482 | if (rev > 1) { |
1373 | d->name = "HPT372N"; | 1483 | d->name = "HPT372N"; |
1374 | 1484 | ||
1485 | info = &hpt372n; | ||
1486 | } else | ||
1487 | info = &hpt372a; | ||
1488 | pci_set_drvdata(dev, info); | ||
1489 | |||
1375 | return ide_setup_pci_device(dev, d); | 1490 | return ide_setup_pci_device(dev, d); |
1376 | } | 1491 | } |
1377 | 1492 | ||
1378 | static int __devinit init_setup_hpt302(struct pci_dev *dev, ide_pci_device_t *d) | 1493 | static int __devinit init_setup_hpt302(struct pci_dev *dev, ide_pci_device_t *d) |
1379 | { | 1494 | { |
1495 | struct hpt_info *info; | ||
1380 | u8 rev = 0; | 1496 | u8 rev = 0; |
1381 | 1497 | ||
1382 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); | 1498 | pci_read_config_byte(dev, PCI_REVISION_ID, &rev); |
1383 | 1499 | ||
1384 | if (rev > 1) | 1500 | if (rev > 1) { |
1385 | d->name = "HPT302N"; | 1501 | d->name = "HPT302N"; |
1386 | 1502 | ||
1503 | info = &hpt302n; | ||
1504 | } else | ||
1505 | info = &hpt302; | ||
1506 | pci_set_drvdata(dev, info); | ||
1507 | |||
1387 | return ide_setup_pci_device(dev, d); | 1508 | return ide_setup_pci_device(dev, d); |
1388 | } | 1509 | } |
1389 | 1510 | ||
@@ -1394,6 +1515,9 @@ static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d) | |||
1394 | static char *chipset_names[] = { "HPT366", "HPT366", "HPT368", | 1515 | static char *chipset_names[] = { "HPT366", "HPT366", "HPT368", |
1395 | "HPT370", "HPT370A", "HPT372", | 1516 | "HPT370", "HPT370A", "HPT372", |
1396 | "HPT372N" }; | 1517 | "HPT372N" }; |
1518 | static struct hpt_info *info[] = { &hpt36x, &hpt36x, &hpt36x, | ||
1519 | &hpt370, &hpt370a, &hpt372, | ||
1520 | &hpt372n }; | ||
1397 | 1521 | ||
1398 | if (PCI_FUNC(dev->devfn) & 1) | 1522 | if (PCI_FUNC(dev->devfn) & 1) |
1399 | return -ENODEV; | 1523 | return -ENODEV; |
@@ -1405,6 +1529,8 @@ static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d) | |||
1405 | 1529 | ||
1406 | d->name = chipset_names[rev]; | 1530 | d->name = chipset_names[rev]; |
1407 | 1531 | ||
1532 | pci_set_drvdata(dev, info[rev]); | ||
1533 | |||
1408 | if (rev > 2) | 1534 | if (rev > 2) |
1409 | goto init_single; | 1535 | goto init_single; |
1410 | 1536 | ||
@@ -1414,6 +1540,8 @@ static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d) | |||
1414 | u8 pin1 = 0, pin2 = 0; | 1540 | u8 pin1 = 0, pin2 = 0; |
1415 | int ret; | 1541 | int ret; |
1416 | 1542 | ||
1543 | pci_set_drvdata(dev2, info[rev]); | ||
1544 | |||
1417 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1); | 1545 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1); |
1418 | pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2); | 1546 | pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2); |
1419 | if (pin1 != pin2 && dev->irq == dev2->irq) { | 1547 | if (pin1 != pin2 && dev->irq == dev2->irq) { |
@@ -1435,40 +1563,39 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = { | |||
1435 | .name = "HPT366", | 1563 | .name = "HPT366", |
1436 | .init_setup = init_setup_hpt366, | 1564 | .init_setup = init_setup_hpt366, |
1437 | .init_chipset = init_chipset_hpt366, | 1565 | .init_chipset = init_chipset_hpt366, |
1438 | .init_iops = init_iops_hpt366, | ||
1439 | .init_hwif = init_hwif_hpt366, | 1566 | .init_hwif = init_hwif_hpt366, |
1440 | .init_dma = init_dma_hpt366, | 1567 | .init_dma = init_dma_hpt366, |
1441 | .channels = 2, | 1568 | .channels = 2, |
1442 | .autodma = AUTODMA, | 1569 | .autodma = AUTODMA, |
1570 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | ||
1443 | .bootable = OFF_BOARD, | 1571 | .bootable = OFF_BOARD, |
1444 | .extra = 240 | 1572 | .extra = 240 |
1445 | },{ /* 1 */ | 1573 | },{ /* 1 */ |
1446 | .name = "HPT372A", | 1574 | .name = "HPT372A", |
1447 | .init_setup = init_setup_hpt372a, | 1575 | .init_setup = init_setup_hpt372a, |
1448 | .init_chipset = init_chipset_hpt366, | 1576 | .init_chipset = init_chipset_hpt366, |
1449 | .init_iops = init_iops_hpt366, | ||
1450 | .init_hwif = init_hwif_hpt366, | 1577 | .init_hwif = init_hwif_hpt366, |
1451 | .init_dma = init_dma_hpt366, | 1578 | .init_dma = init_dma_hpt366, |
1452 | .channels = 2, | 1579 | .channels = 2, |
1453 | .autodma = AUTODMA, | 1580 | .autodma = AUTODMA, |
1581 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | ||
1454 | .bootable = OFF_BOARD, | 1582 | .bootable = OFF_BOARD, |
1455 | .extra = 240 | 1583 | .extra = 240 |
1456 | },{ /* 2 */ | 1584 | },{ /* 2 */ |
1457 | .name = "HPT302", | 1585 | .name = "HPT302", |
1458 | .init_setup = init_setup_hpt302, | 1586 | .init_setup = init_setup_hpt302, |
1459 | .init_chipset = init_chipset_hpt366, | 1587 | .init_chipset = init_chipset_hpt366, |
1460 | .init_iops = init_iops_hpt366, | ||
1461 | .init_hwif = init_hwif_hpt366, | 1588 | .init_hwif = init_hwif_hpt366, |
1462 | .init_dma = init_dma_hpt366, | 1589 | .init_dma = init_dma_hpt366, |
1463 | .channels = 2, | 1590 | .channels = 2, |
1464 | .autodma = AUTODMA, | 1591 | .autodma = AUTODMA, |
1592 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | ||
1465 | .bootable = OFF_BOARD, | 1593 | .bootable = OFF_BOARD, |
1466 | .extra = 240 | 1594 | .extra = 240 |
1467 | },{ /* 3 */ | 1595 | },{ /* 3 */ |
1468 | .name = "HPT371", | 1596 | .name = "HPT371", |
1469 | .init_setup = init_setup_hpt371, | 1597 | .init_setup = init_setup_hpt371, |
1470 | .init_chipset = init_chipset_hpt366, | 1598 | .init_chipset = init_chipset_hpt366, |
1471 | .init_iops = init_iops_hpt366, | ||
1472 | .init_hwif = init_hwif_hpt366, | 1599 | .init_hwif = init_hwif_hpt366, |
1473 | .init_dma = init_dma_hpt366, | 1600 | .init_dma = init_dma_hpt366, |
1474 | .channels = 2, | 1601 | .channels = 2, |
@@ -1480,22 +1607,22 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = { | |||
1480 | .name = "HPT374", | 1607 | .name = "HPT374", |
1481 | .init_setup = init_setup_hpt374, | 1608 | .init_setup = init_setup_hpt374, |
1482 | .init_chipset = init_chipset_hpt366, | 1609 | .init_chipset = init_chipset_hpt366, |
1483 | .init_iops = init_iops_hpt366, | ||
1484 | .init_hwif = init_hwif_hpt366, | 1610 | .init_hwif = init_hwif_hpt366, |
1485 | .init_dma = init_dma_hpt366, | 1611 | .init_dma = init_dma_hpt366, |
1486 | .channels = 2, /* 4 */ | 1612 | .channels = 2, /* 4 */ |
1487 | .autodma = AUTODMA, | 1613 | .autodma = AUTODMA, |
1614 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | ||
1488 | .bootable = OFF_BOARD, | 1615 | .bootable = OFF_BOARD, |
1489 | .extra = 240 | 1616 | .extra = 240 |
1490 | },{ /* 5 */ | 1617 | },{ /* 5 */ |
1491 | .name = "HPT372N", | 1618 | .name = "HPT372N", |
1492 | .init_setup = init_setup_hpt372n, | 1619 | .init_setup = init_setup_hpt372n, |
1493 | .init_chipset = init_chipset_hpt366, | 1620 | .init_chipset = init_chipset_hpt366, |
1494 | .init_iops = init_iops_hpt366, | ||
1495 | .init_hwif = init_hwif_hpt366, | 1621 | .init_hwif = init_hwif_hpt366, |
1496 | .init_dma = init_dma_hpt366, | 1622 | .init_dma = init_dma_hpt366, |
1497 | .channels = 2, /* 4 */ | 1623 | .channels = 2, /* 4 */ |
1498 | .autodma = AUTODMA, | 1624 | .autodma = AUTODMA, |
1625 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | ||
1499 | .bootable = OFF_BOARD, | 1626 | .bootable = OFF_BOARD, |
1500 | .extra = 240 | 1627 | .extra = 240 |
1501 | } | 1628 | } |