27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
37 #define DRV_NAME "pata_ali"
38 #define DRV_VERSION "0.7.8"
40 static int ali_atapi_dma = 0;
44 static struct pci_dev *ali_isa_bridge;
52 .ident =
"HP Pavilion N5430",
59 .ident =
"Toshiba Satellite S1800-814",
68 static int ali_cable_override(
struct pci_dev *pdev)
89 static int ali_c2_cable_detect(
struct ata_port *ap)
97 if (ali_cable_override(pdev))
102 pci_read_config_byte(pdev, 0x4A, &ata66);
103 if (ata66 & (1 << ap->
port_no))
118 static unsigned long ali_20_filter(
struct ata_device *adev,
unsigned long mask)
125 if (
strstr(model_num,
"WDC"))
144 int pio_fifo = 0x54 + ap->
port_no;
146 int shift = 4 * adev->
devno;
152 pci_read_config_byte(pdev, pio_fifo, &fifo);
153 fifo &= ~(0x0F << shift);
154 fifo |= (on << shift);
155 pci_write_config_byte(pdev, pio_fifo, fifo);
174 int cbt = 0x59 + 4 * ap->
port_no;
176 int udmat = 0x56 + ap->
port_no;
177 int shift = 4 * adev->
devno;
187 pci_write_config_byte(pdev, cas, t->
setup);
188 pci_write_config_byte(pdev, cbt, (t->
act8b << 4) | t->
rec8b);
189 pci_write_config_byte(pdev, drwt, (t->
active << 4) | t->
recover);
193 pci_read_config_byte(pdev, udmat, &udma);
194 udma &= ~(0x0F << shift);
195 udma |= ultra << shift;
196 pci_write_config_byte(pdev, udmat, udma);
211 unsigned long T = 1000000000 / 33333;
226 ali_fifo_control(ap, adev, 0x00);
227 ali_program_modes(ap, adev, &t, 0);
229 ali_fifo_control(ap, adev, 0x05);
243 static u8 udma_timing[7] = { 0xC, 0xB, 0xA, 0x9, 0x8, 0xF, 0xD };
246 unsigned long T = 1000000000 / 33333;
251 ali_fifo_control(ap, adev, 0x08);
257 pci_read_config_byte(pdev, 0x4B, ®4b);
259 pci_write_config_byte(pdev, 0x4B, reg4b);
272 ali_program_modes(ap, adev, &t, 0);
284 static void ali_warn_atapi_dma(
struct ata_device *adev)
291 "WARNING: ATAPI DMA disabled for reliability issues. It can be enabled\n");
293 "WARNING: via pata_ali.atapi_dma modparam or corresponding sysfs node.\n");
308 static void ali_lock_sectors(
struct ata_device *adev)
311 ali_warn_atapi_dma(adev);
323 if (!ali_atapi_dma) {
344 int port_bit = 4 << link->
ap->port_no;
347 if (ali_isa_bridge) {
349 pci_read_config_byte(ali_isa_bridge, 0x58, &r);
351 pci_write_config_byte(ali_isa_bridge, 0x58, r);
353 pci_write_config_byte(ali_isa_bridge, 0x58, r);
369 .set_piomode = ali_set_piomode,
374 .inherits = &ata_bmdma32_port_ops,
375 .set_piomode = ali_set_piomode,
376 .set_dmamode = ali_set_dmamode,
384 .inherits = &ali_dma_base_ops,
386 .mode_filter = ali_20_filter,
387 .check_atapi_dma = ali_check_atapi_dma,
388 .dev_config = ali_lock_sectors,
395 .inherits = &ali_dma_base_ops,
397 .cable_detect = ali_c2_cable_detect,
398 .dev_config = ali_lock_sectors,
399 .postreset = ali_c2_c3_postreset,
406 .inherits = &ali_dma_base_ops,
408 .cable_detect = ali_c2_cable_detect,
409 .dev_config = ali_lock_sectors,
416 .inherits = &ali_dma_base_ops,
418 .dev_config = ali_warn_atapi_dma,
419 .cable_detect = ali_c2_cable_detect,
431 static void ali_init_chipset(
struct pci_dev *pdev)
442 pci_read_config_byte(pdev, 0x53, &tmp);
444 pci_write_config_byte(pdev, 0x53, tmp);
446 pci_read_config_byte(pdev, 0x4a, &tmp);
447 pci_write_config_byte(pdev, 0x4a, tmp | 0x20);
448 pci_read_config_byte(pdev, 0x4B, &tmp);
456 pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
462 pci_read_config_byte(pdev, 0x53, &tmp);
467 pci_write_config_byte(pdev, 0x53, tmp);
473 pci_read_config_byte(ali_isa_bridge, 0x79, &tmp);
475 pci_write_config_byte(ali_isa_bridge, 0x79, tmp | 0x04);
477 pci_write_config_byte(ali_isa_bridge, 0x79, tmp | 0x02);
480 ata_pci_bmdma_clear_simplex(pdev);
496 .port_ops = &ali_early_port_ops
504 .port_ops = &ali_20_port_ops
513 .port_ops = &ali_20_port_ops
522 .port_ops = &ali_c2_port_ops
531 .port_ops = &ali_c2_port_ops
540 .port_ops = &ali_c4_port_ops
548 .port_ops = &ali_c5_port_ops
565 ppi[0] = &info_early;
568 }
else if (pdev->
revision == 0xC2) {
570 }
else if (pdev->
revision == 0xC3) {
572 }
else if (pdev->
revision == 0xC4) {
577 ali_init_chipset(pdev);
581 pci_read_config_byte(ali_isa_bridge, 0x5E, &tmp);
582 if ((tmp & 0x1E) == 0x12)
583 ppi[0] = &info_20_udma;
587 return ata_pci_sff_init_one(pdev, ppi, &ali_sht,
NULL, 0);
589 return ata_pci_bmdma_init_one(pdev, ppi, &ali_sht,
NULL, 0);
593 static int ali_reinit_one(
struct pci_dev *pdev)
598 rc = ata_pci_device_do_resume(pdev);
601 ali_init_chipset(pdev);
602 ata_host_resume(host);
617 .probe = ali_init_one,
618 .remove = ata_pci_remove_one,
620 .suspend = ata_pci_device_suspend,
621 .resume = ali_reinit_one,
625 static int __init ali_init(
void)
630 ret = pci_register_driver(&ali_pci_driver);
637 static void __exit ali_exit(
void)