17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/pci.h>
26 #define DRV_NAME "pata_amd"
27 #define DRV_VERSION "0.4.1"
45 static const unsigned char amd_cyc2udma[] = {
46 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7
54 const int amd_clock = 33333;
57 T = 1000000000 / amd_clock;
63 dev_err(&pdev->
dev,
"unknown mode %d\n", speed);
85 pci_read_config_byte(pdev, offset + 0x0C, &t);
86 t = (t & ~(3 << ((3 -
dn) << 1))) | ((
clamp_val(at.
setup, 1, 4) - 1) << ((3 - dn) << 1));
87 pci_write_config_byte(pdev, offset + 0x0C , t);
90 pci_write_config_byte(pdev, offset + 0x0E + (1 - (dn >> 1)),
94 pci_write_config_byte(pdev, offset + 0x08 + (3 - dn),
120 pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
132 static int amd_pre_reset(
struct ata_link *
link,
unsigned long deadline)
134 static const struct pci_bits amd_enable_bits[] = {
135 { 0x40, 1, 0x02, 0x02 },
136 { 0x40, 1, 0x01, 0x01 }
142 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->
port_no]))
155 static int amd_cable_detect(
struct ata_port *ap)
161 pci_read_config_byte(pdev, 0x42, &ata66);
162 if (ata66 & bitmask[ap->
port_no])
178 static void amd_fifo_setup(
struct ata_port *ap)
182 static const u8 fifobit[2] = { 0xC0, 0x30};
195 pci_read_config_byte(pdev, 0x41, &r);
198 pci_write_config_byte(pdev, 0x41, r);
212 timing_setup(ap, adev, 0x40, adev->
pio_mode, 1);
218 timing_setup(ap, adev, 0x40, adev->
pio_mode, 2);
224 timing_setup(ap, adev, 0x40, adev->
pio_mode, 3);
230 timing_setup(ap, adev, 0x40, adev->
pio_mode, 4);
244 timing_setup(ap, adev, 0x40, adev->
dma_mode, 1);
249 timing_setup(ap, adev, 0x40, adev->
dma_mode, 2);
254 timing_setup(ap, adev, 0x40, adev->
dma_mode, 3);
259 timing_setup(ap, adev, 0x40, adev->
dma_mode, 4);
269 unsigned long xfer_mask)
271 static const unsigned int udma_mask_map[] =
275 char acpi_str[32] =
"";
276 u32 saved_udma, udma;
278 unsigned long bios_limit = 0, acpi_limit = 0,
limit;
281 udma = saved_udma = (
unsigned long)ap->
host->private_data;
288 if ((udma & 0xc0) == 0xc0)
292 gtm = ata_acpi_init_gtm(ap);
296 snprintf(acpi_str,
sizeof(acpi_str),
" (%u:%u:0x%x)",
301 limit = bios_limit | acpi_limit;
315 "BIOS=0x%lx (0x%x) ACPI=0x%lx%s\n",
316 xfer_mask,
limit, xfer_mask &
limit, bios_limit,
317 saved_udma, acpi_limit, acpi_str);
319 return xfer_mask &
limit;
330 static int nv_pre_reset(
struct ata_link *link,
unsigned long deadline)
332 static const struct pci_bits nv_enable_bits[] = {
333 { 0x50, 1, 0x02, 0x02 },
334 { 0x50, 1, 0x01, 0x01 }
340 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->
port_no]))
356 timing_setup(ap, adev, 0x50, adev->
pio_mode, 3);
361 timing_setup(ap, adev, 0x50, adev->
pio_mode, 4);
375 timing_setup(ap, adev, 0x50, adev->
dma_mode, 3);
380 timing_setup(ap, adev, 0x50, adev->
dma_mode, 4);
396 .inherits = &ata_bmdma32_port_ops,
397 .prereset = amd_pre_reset,
401 .inherits = &amd_base_port_ops,
403 .set_piomode = amd33_set_piomode,
404 .set_dmamode = amd33_set_dmamode,
408 .inherits = &amd_base_port_ops,
410 .set_piomode = amd66_set_piomode,
411 .set_dmamode = amd66_set_dmamode,
415 .inherits = &amd_base_port_ops,
417 .set_piomode = amd100_set_piomode,
418 .set_dmamode = amd100_set_dmamode,
422 .inherits = &amd_base_port_ops,
424 .set_piomode = amd133_set_piomode,
425 .set_dmamode = amd133_set_dmamode,
429 .inherits = &ata_bmdma_port_ops,
431 .mode_filter = nv_mode_filter,
432 .prereset = nv_pre_reset,
433 .host_stop = nv_host_stop,
437 .inherits = &nv_base_port_ops,
439 .set_dmamode = nv100_set_dmamode,
443 .inherits = &nv_base_port_ops,
445 .set_dmamode = nv133_set_dmamode,
448 static void amd_clear_fifo(
struct pci_dev *pdev)
453 pci_read_config_byte(pdev, 0x41, &fifo);
455 pci_write_config_byte(pdev, 0x41, fifo);
466 .port_ops = &amd33_port_ops
473 .port_ops = &amd66_port_ops
480 .port_ops = &amd66_port_ops
487 .port_ops = &amd100_port_ops
494 .port_ops = &amd100_port_ops
501 .port_ops = &amd133_port_ops
508 .port_ops = &amd133_port_ops
515 .port_ops = &nv100_port_ops
522 .port_ops = &nv133_port_ops
529 .port_ops = &amd100_port_ops
533 int type =
id->driver_data;
544 pci_read_config_byte(pdev, 0x41, &fifo);
547 if (type == 1 && pdev->
revision > 0x7)
558 ppi[0] = &info[
type];
561 ata_pci_bmdma_clear_simplex(pdev);
563 amd_clear_fifo(pdev);
567 if (type == 7 || type == 8) {
570 pci_read_config_dword(pdev, 0x60, &udma);
571 hpriv = (
void *)(
unsigned long)udma;
575 return ata_pci_bmdma_init_one(pdev, ppi, &amd_sht, hpriv, 0);
579 static int amd_reinit_one(
struct pci_dev *pdev)
584 rc = ata_pci_device_do_resume(pdev);
589 amd_clear_fifo(pdev);
592 ata_pci_bmdma_clear_simplex(pdev);
594 ata_host_resume(host);
627 .probe = amd_init_one,
628 .remove = ata_pci_remove_one,
630 .suspend = ata_pci_device_suspend,
631 .resume = amd_reinit_one,