18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
29 #define DRV_NAME "pata_hpt3x2n"
30 #define DRV_VERSION "0.3.15"
72 static struct hpt_clock hpt3x2n_clocks[] = {
104 static u32 hpt3x2n_find_mode(
struct ata_port *ap,
int speed)
106 struct hpt_clock *clocks = hpt3x2n_clocks;
125 static unsigned long hpt372n_filter(
struct ata_device *adev,
unsigned long mask)
127 if (ata_id_is_sata(adev->
id))
140 static int hpt3x2n_cable_detect(
struct ata_port *ap)
145 pci_read_config_byte(pdev, 0x5B, &scr2);
146 pci_write_config_byte(pdev, 0x5B, scr2 & ~0x01);
151 pci_read_config_byte(pdev, 0x5A, &ata66);
153 pci_write_config_byte(pdev, 0x5B, scr2);
155 if (ata66 & (2 >> ap->
port_no))
170 static int hpt3x2n_pre_reset(
struct ata_link *
link,
unsigned long deadline)
176 pci_write_config_byte(pdev, 0x50 + 4 * ap->
port_no, 0x37);
191 addr2 = 0x51 + 4 * ap->
port_no;
194 pci_read_config_byte(pdev, addr2, &fast);
196 pci_write_config_byte(pdev, addr2, fast);
206 timing = hpt3x2n_find_mode(ap, mode);
208 pci_read_config_dword(pdev, addr1, ®);
209 reg = (reg & ~mask) | (timing & mask);
210 pci_write_config_dword(pdev, addr1, reg);
223 hpt3x2n_set_mode(ap, adev, adev->
pio_mode);
236 hpt3x2n_set_mode(ap, adev, adev->
dma_mode);
250 int mscreg = 0x50 + 2 * ap->
port_no;
251 u8 bwsr_stat, msc_stat;
253 pci_read_config_byte(pdev, 0x6A, &bwsr_stat);
254 pci_read_config_byte(pdev, mscreg, &msc_stat);
255 if (bwsr_stat & (1 << ap->
port_no))
256 pci_write_config_byte(pdev, mscreg, msc_stat | 0x30);
300 static int hpt3x2n_use_dpll(
struct ata_port *ap,
int writing)
332 int flags = (
long)ap->
host->private_data;
338 ap->
host->private_data = (
void *)(
long)
flags;
340 hpt3x2n_set_clock(ap, dpll ? 0x21 : 0x23);
342 return ata_bmdma_qc_issue(qc);
354 .inherits = &ata_bmdma_port_ops,
356 .bmdma_stop = hpt3x2n_bmdma_stop,
358 .qc_defer = hpt3x2n_qc_defer,
359 .qc_issue = hpt3x2n_qc_issue,
361 .cable_detect = hpt3x2n_cable_detect,
362 .set_piomode = hpt3x2n_set_piomode,
363 .set_dmamode = hpt3x2n_set_dmamode,
364 .prereset = hpt3x2n_pre_reset,
372 .inherits = &hpt3xxn_port_ops,
384 static int hpt3xn_calibrate_dpll(
struct pci_dev *
dev)
390 for (tries = 0; tries < 0x5000; tries++) {
392 pci_read_config_byte(dev, 0x5b, ®5b);
395 for (tries = 0; tries < 0x1000; tries++) {
396 pci_read_config_byte(dev, 0x5b, ®5b);
398 if ((reg5b & 0x80) == 0)
402 pci_read_config_dword(dev, 0x5c, ®5c);
403 pci_write_config_dword(dev, 0x5c, reg5c & ~0x100);
411 static int hpt3x2n_pci_clock(
struct pci_dev *pdev)
417 fcnt =
inl(iobase + 0x90);
418 if ((fcnt >> 12) != 0xABCDE) {
423 pr_warn(
"BIOS clock data not set\n");
426 for (i = 0; i < 128; i++) {
427 pci_read_config_word(pdev, 0x78, &sr);
435 freq = (fcnt * 77) / 192;
483 .port_ops = &hpt372n_port_ops
491 .port_ops = &hpt3xxn_port_ops
496 unsigned int pci_mhz;
497 unsigned int f_low, f_high;
500 void *hpriv = (
void *)USE_DPLL;
530 ppi[0] = &info_hpt372n;
533 pr_err(
"PCI table is bogus, please report (%d)\n", dev->
device);
544 pci_read_config_byte(dev, 0x5A, &irqmask);
546 pci_write_config_byte(dev, 0x5a, irqmask);
556 pci_read_config_byte(dev, 0x50, &mcr1);
558 pci_write_config_byte(dev, 0x50, mcr1);
566 pci_mhz = hpt3x2n_pci_clock(dev);
568 f_low = (pci_mhz * 48) / 66;
571 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low | 0x100);
573 pci_write_config_byte(dev, 0x5B, 0x21);
576 for (adjust = 0; adjust < 8; adjust++) {
577 if (hpt3xn_calibrate_dpll(dev))
579 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low);
582 pr_err(
"DPLL did not stabilize!\n");
586 pr_info(
"bus clock %dMHz, using 66MHz DPLL\n", pci_mhz);
593 hpriv = (
void *)(
PCI66 | USE_DPLL);
601 outb(
inb(iobase + 0x9c) | 0x04, iobase + 0x9c);
604 return ata_pci_bmdma_init_one(dev, ppi, &hpt3x2n_sht, hpriv, 0);
617 static struct pci_driver hpt3x2n_pci_driver = {
620 .probe = hpt3x2n_init_one,
621 .remove = ata_pci_remove_one