17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
28 #define DRV_NAME "pata_hpt37x"
29 #define DRV_VERSION "0.6.23"
64 static struct hpt_clock hpt37x_timings_33[] = {
84 static struct hpt_clock hpt37x_timings_50[] = {
104 static struct hpt_clock hpt37x_timings_66[] = {
125 static const struct hpt_chip hpt370 = {
136 static const struct hpt_chip hpt370a = {
147 static const struct hpt_chip hpt372 = {
158 static const struct hpt_chip hpt302 = {
169 static const struct hpt_chip hpt371 = {
180 static const struct hpt_chip hpt372a = {
191 static const struct hpt_chip hpt374 = {
211 static u32 hpt37x_find_mode(
struct ata_port *ap,
int speed)
224 static int hpt_dma_blacklisted(
const struct ata_device *
dev,
char *modestr,
225 const char *
const list[])
232 while (list[i] !=
NULL) {
233 if (!
strcmp(list[i], model_num)) {
234 pr_warn(
"%s is not supported for %s\n",
243 static const char *
const bad_ata33[] = {
244 "Maxtor 92720U8",
"Maxtor 92040U6",
"Maxtor 91360U4",
"Maxtor 91020U3",
245 "Maxtor 90845U3",
"Maxtor 90650U2",
246 "Maxtor 91360D8",
"Maxtor 91190D7",
"Maxtor 91020D6",
"Maxtor 90845D5",
247 "Maxtor 90680D4",
"Maxtor 90510D3",
"Maxtor 90340D2",
248 "Maxtor 91152D8",
"Maxtor 91008D7",
"Maxtor 90845D6",
"Maxtor 90840D6",
249 "Maxtor 90720D5",
"Maxtor 90648D5",
"Maxtor 90576D4",
251 "Maxtor 90432D3",
"Maxtor 90288D2",
"Maxtor 90256D2",
252 "Maxtor 91000D8",
"Maxtor 90910D8",
"Maxtor 90875D7",
"Maxtor 90840D7",
253 "Maxtor 90750D6",
"Maxtor 90625D5",
"Maxtor 90500D4",
254 "Maxtor 91728D8",
"Maxtor 91512D7",
"Maxtor 91303D6",
"Maxtor 91080D5",
255 "Maxtor 90845D4",
"Maxtor 90680D4",
"Maxtor 90648D3",
"Maxtor 90432D2",
259 static const char *
const bad_ata100_5[] = {
285 static unsigned long hpt370_filter(
struct ata_device *adev,
unsigned long mask)
288 if (hpt_dma_blacklisted(adev,
"UDMA", bad_ata33))
290 if (hpt_dma_blacklisted(adev,
"UDMA100", bad_ata100_5))
303 static unsigned long hpt370a_filter(
struct ata_device *adev,
unsigned long mask)
306 if (hpt_dma_blacklisted(adev,
"UDMA100", bad_ata100_5))
320 static unsigned long hpt372_filter(
struct ata_device *adev,
unsigned long mask)
322 if (ata_id_is_sata(adev->
id))
335 static int hpt37x_cable_detect(
struct ata_port *ap)
340 pci_read_config_byte(pdev, 0x5B, &scr2);
341 pci_write_config_byte(pdev, 0x5B, scr2 & ~0x01);
346 pci_read_config_byte(pdev, 0x5A, &ata66);
348 pci_write_config_byte(pdev, 0x5B, scr2);
350 if (ata66 & (2 >> ap->
port_no))
363 static int hpt374_fn1_cable_detect(
struct ata_port *ap)
366 unsigned int mcrbase = 0x50 + 4 * ap->
port_no;
371 pci_read_config_word(pdev, mcrbase + 2, &mcr3);
373 pci_write_config_word(pdev, mcrbase + 2, mcr3 | 0x8000);
374 pci_read_config_byte(pdev, 0x5A, &ata66);
376 pci_write_config_word(pdev, mcrbase + 2, mcr3);
378 if (ata66 & (2 >> ap->
port_no))
392 static int hpt37x_pre_reset(
struct ata_link *
link,
unsigned long deadline)
396 static const struct pci_bits hpt37x_enable_bits[] = {
397 { 0x50, 1, 0x04, 0x04 },
398 { 0x54, 1, 0x04, 0x04 }
401 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->
port_no]))
405 pci_write_config_byte(pdev, 0x50 + 4 * ap->
port_no, 0x37);
420 addr2 = 0x51 + 4 * ap->
port_no;
423 pci_read_config_byte(pdev, addr2, &fast);
426 pci_write_config_byte(pdev, addr2, fast);
436 timing = hpt37x_find_mode(ap, mode);
438 pci_read_config_dword(pdev, addr1, ®);
439 reg = (reg & ~mask) | (timing & mask);
440 pci_write_config_dword(pdev, addr1, reg);
452 hpt370_set_mode(ap, adev, adev->
pio_mode);
465 hpt370_set_mode(ap, adev, adev->
dma_mode);
487 if (dma_stat & ATA_DMA_ACTIVE) {
489 pci_write_config_byte(pdev, 0x50 + 4 * ap->
port_no, 0x37);
499 pci_write_config_byte(pdev, 0x50 + 4 * ap->
port_no, 0x37);
514 addr2 = 0x51 + 4 * ap->
port_no;
517 pci_read_config_byte(pdev, addr2, &fast);
519 pci_write_config_byte(pdev, addr2, fast);
529 timing = hpt37x_find_mode(ap, mode);
531 pci_read_config_dword(pdev, addr1, ®);
532 reg = (reg & ~mask) | (timing & mask);
533 pci_write_config_dword(pdev, addr1, reg);
546 hpt372_set_mode(ap, adev, adev->
pio_mode);
559 hpt372_set_mode(ap, adev, adev->
dma_mode);
573 int mscreg = 0x50 + 4 * ap->
port_no;
574 u8 bwsr_stat, msc_stat;
576 pci_read_config_byte(pdev, 0x6A, &bwsr_stat);
577 pci_read_config_byte(pdev, mscreg, &msc_stat);
578 if (bwsr_stat & (1 << ap->
port_no))
579 pci_write_config_byte(pdev, mscreg, msc_stat | 0x30);
593 .inherits = &ata_bmdma_port_ops,
595 .bmdma_stop = hpt370_bmdma_stop,
597 .mode_filter = hpt370_filter,
598 .cable_detect = hpt37x_cable_detect,
599 .set_piomode = hpt370_set_piomode,
600 .set_dmamode = hpt370_set_dmamode,
601 .prereset = hpt37x_pre_reset,
609 .inherits = &hpt370_port_ops,
619 .inherits = &ata_bmdma_port_ops,
621 .bmdma_stop = hpt37x_bmdma_stop,
623 .cable_detect = hpt37x_cable_detect,
624 .set_piomode = hpt372_set_piomode,
625 .set_dmamode = hpt372_set_dmamode,
626 .prereset = hpt37x_pre_reset,
635 .inherits = &hpt302_port_ops,
645 .inherits = &hpt372_port_ops,
658 static int hpt37x_clock_slot(
unsigned int freq,
unsigned int base)
660 unsigned int f = (base *
freq) / 192;
678 static int hpt37x_calibrate_dpll(
struct pci_dev *dev)
684 for (tries = 0; tries < 0x5000; tries++) {
686 pci_read_config_byte(dev, 0x5b, ®5b);
689 for (tries = 0; tries < 0x1000; tries++) {
690 pci_read_config_byte(dev, 0x5b, ®5b);
692 if ((reg5b & 0x80) == 0)
696 pci_read_config_dword(dev, 0x5c, ®5c);
697 pci_write_config_dword(dev, 0x5c, reg5c & ~0x100);
705 static u32 hpt374_read_freq(
struct pci_dev *pdev)
718 freq =
inl(io_base + 0x90);
721 freq =
inl(io_base + 0x90);
765 .port_ops = &hpt370_port_ops
773 .port_ops = &hpt370a_port_ops
781 .port_ops = &hpt370_port_ops
789 .port_ops = &hpt370a_port_ops
797 .port_ops = &hpt372_port_ops
805 .port_ops = &hpt302_port_ops
813 .port_ops = &hpt372_port_ops
820 .port_ops = &hpt374_fn1_port_ops
823 static const int MHz[4] = { 33, 40, 50, 66 };
854 ppi[0] = &info_hpt370;
855 chip_table = &hpt370;
859 ppi[0] = &info_hpt370a;
860 chip_table = &hpt370a;
864 ppi[0] = &info_hpt372;
865 chip_table = &hpt372;
868 pr_err(
"Unknown HPT366 subtype, please report (%d)\n",
877 ppi[0] = &info_hpt372;
878 chip_table = &hpt372a;
884 ppi[0] = &info_hpt302;
886 chip_table = &hpt302;
891 ppi[0] = &info_hpt302;
892 chip_table = &hpt371;
897 pci_read_config_byte(dev, 0x50, &mcr1);
899 pci_write_config_byte(dev, 0x50, mcr1);
902 chip_table = &hpt374;
904 *ppi = &info_hpt374_fn0;
906 *ppi = &info_hpt374_fn1;
909 pr_err(
"PCI table is bogus, please report (%d)\n", dev->
device);
919 pci_read_config_byte(dev, 0x5A, &irqmask);
921 pci_write_config_byte(dev, 0x5a, irqmask);
930 pci_write_config_byte(dev, 0x5b, 0x23);
936 if (chip_table == &hpt372a)
937 outb(0x0e, iobase + 0x9c);
945 if (chip_table == &hpt374) {
946 freq = hpt374_read_freq(dev);
950 freq =
inl(iobase + 0x90);
952 if ((freq >> 12) != 0xABCDE) {
957 pr_warn(
"BIOS has not set timing clocks\n");
960 for (i = 0; i < 128; i++) {
961 pci_read_config_byte(dev, 0x78, &sr);
974 clock_slot = hpt37x_clock_slot(freq, chip_table->
base);
975 if (chip_table->
clocks[clock_slot] ==
NULL || prefer_dpll) {
982 unsigned int f_low, f_high;
986 dpll = (ppi[0]->
udma_mask & 0xC0) ? 3 : 2;
988 f_low = (MHz[clock_slot] * 48) / MHz[dpll];
994 pci_write_config_byte(dev, 0x5b, 0x21);
995 pci_write_config_dword(dev, 0x5C,
996 (f_high << 16) | f_low | 0x100);
998 for (adjust = 0; adjust < 8; adjust++) {
999 if (hpt37x_calibrate_dpll(dev))
1006 f_low -= adjust >> 1;
1008 f_high += adjust >> 1;
1009 pci_write_config_dword(dev, 0x5C,
1010 (f_high << 16) | f_low | 0x100);
1013 pr_err(
"DPLL did not stabilize!\n");
1017 private_data = (
void *)hpt37x_timings_66;
1019 private_data = (
void *)hpt37x_timings_50;
1021 pr_info(
"bus clock %dMHz, using %dMHz DPLL\n",
1022 MHz[clock_slot], MHz[dpll]);
1024 private_data = (
void *)chip_table->
clocks[clock_slot];
1031 if (clock_slot < 2 && ppi[0] == &info_hpt370)
1032 ppi[0] = &info_hpt370_33;
1033 if (clock_slot < 2 && ppi[0] == &info_hpt370a)
1034 ppi[0] = &info_hpt370a_33;
1036 pr_info(
"%s using %dMHz bus clock\n",
1037 chip_table->
name, MHz[clock_slot]);
1041 return ata_pci_bmdma_init_one(dev, ppi, &hpt37x_sht, private_data, 0);
1054 static struct pci_driver hpt37x_pci_driver = {
1057 .probe = hpt37x_init_one,
1058 .remove = ata_pci_remove_one