26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/pci.h>
32 #include <linux/device.h>
38 #define DRV_NAME "pata_sis"
39 #define DRV_VERSION "0.5.2"
56 { 0x5513, 0x1043, 0x1107 },
57 { 0x5513, 0x1734, 0x105F },
58 { 0x5513, 0x1071, 0x8640 },
63 static int sis_short_ata40(
struct pci_dev *
dev)
65 const struct sis_laptop *lap = &sis_laptop[0];
86 static int sis_old_port_base(
struct ata_device *adev)
88 return 0x40 + (4 * adev->
link->ap->port_no) + (2 * adev->
devno);
99 static int sis_port_base(
struct ata_device *adev)
107 pci_read_config_dword(pdev, 0x54, ®54);
108 if (reg54 & 0x40000000)
123 static int sis_133_cable_detect(
struct ata_port *ap)
129 pci_read_config_word(pdev, 0x50 + 2 * ap->
port_no, &tmp);
130 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
143 static int sis_66_cable_detect(
struct ata_port *ap)
149 pci_read_config_byte(pdev, 0x48, &tmp);
151 if ((tmp & 0x10) && !sis_short_ata40(pdev))
165 static int sis_pre_reset(
struct ata_link *
link,
unsigned long deadline)
167 static const struct pci_bits sis_enable_bits[] = {
168 { 0x4a
U, 1
U, 0x02
UL, 0x02UL },
169 { 0x4a
U, 1
U, 0x04
UL, 0x04UL },
175 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->
port_no]))
180 pci_write_config_byte(pdev, 0x4B, 0);
202 mask <<= adev->
devno;
205 pci_read_config_byte(pdev, 0x4B, &fifoctrl);
211 pci_write_config_byte(pdev, 0x4B, fifoctrl);
230 int port = sis_old_port_base(adev);
234 static const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
235 static const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
237 sis_set_fifo(ap, adev);
239 pci_read_config_byte(pdev, port, &t1);
240 pci_read_config_byte(pdev, port + 1, &t2);
246 t2 |= recovery[speed];
248 pci_write_config_byte(pdev, port, t1);
249 pci_write_config_byte(pdev, port + 1, t2);
267 int port = sis_old_port_base(adev);
270 static const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
272 sis_set_fifo(ap, adev);
274 pci_write_config_byte(pdev, port, actrec[speed]);
296 static const u32 timing133[] = {
303 static const u32 timing100[] = {
311 sis_set_fifo(ap, adev);
313 port = sis_port_base(adev);
314 pci_read_config_dword(pdev, port, &t1);
318 t1 |= timing133[speed];
320 t1 |= timing100[speed];
321 pci_write_config_byte(pdev, port, t1);
341 int drive_pci = sis_old_port_base(adev);
344 static const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
345 static const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
347 pci_read_config_word(pdev, drive_pci, &timing);
353 timing |= mwdma_bits[speed];
358 timing |= udma_bits[speed];
360 pci_write_config_word(pdev, drive_pci, timing);
380 int drive_pci = sis_old_port_base(adev);
384 static const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
385 static const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 };
387 pci_read_config_word(pdev, drive_pci, &timing);
393 timing |= mwdma_bits[speed];
398 timing |= udma_bits[speed];
400 pci_write_config_word(pdev, drive_pci, timing);
419 int drive_pci = sis_old_port_base(adev);
422 static const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
424 pci_read_config_byte(pdev, drive_pci + 1, &timing);
432 timing |= udma_bits[speed];
434 pci_write_config_byte(pdev, drive_pci + 1, timing);
453 int drive_pci = sis_old_port_base(adev);
456 static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
458 pci_read_config_byte(pdev, drive_pci + 1, &timing);
466 timing |= udma_bits[speed];
468 pci_write_config_byte(pdev, drive_pci + 1, timing);
488 port = sis_port_base(adev);
489 pci_read_config_dword(pdev, port, &t1);
493 static const u32 timing_u100[] = { 0x19154000, 0x06072000, 0x04062000 };
494 static const u32 timing_u133[] = { 0x221C6000, 0x0C0A3000, 0x05093000 };
501 t1 |= timing_u133[speed];
503 t1 |= timing_u100[speed];
506 static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
507 static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
514 t1 |= timing_u133[speed];
516 t1 |= timing_u100[speed];
518 pci_write_config_dword(pdev, port, t1);
528 static unsigned long sis_133_mode_filter(
struct ata_device *adev,
unsigned long mask)
532 int port = sis_port_base(adev);
535 pci_read_config_dword(pdev, port, &t1);
547 .inherits = &ata_bmdma_port_ops,
548 .set_piomode = sis_133_set_piomode,
549 .set_dmamode = sis_133_set_dmamode,
550 .cable_detect = sis_133_cable_detect,
554 .inherits = &ata_bmdma_port_ops,
555 .prereset = sis_pre_reset,
559 .inherits = &sis_base_ops,
561 .set_dmamode = sis_133_set_dmamode,
562 .cable_detect = sis_133_cable_detect,
563 .mode_filter = sis_133_mode_filter,
567 .inherits = &sis_base_ops,
569 .set_dmamode = sis_133_early_set_dmamode,
570 .cable_detect = sis_66_cable_detect,
574 .inherits = &sis_base_ops,
576 .set_dmamode = sis_100_set_dmamode,
577 .cable_detect = sis_66_cable_detect,
581 .inherits = &sis_base_ops,
583 .set_dmamode = sis_66_set_dmamode,
584 .cable_detect = sis_66_cable_detect,
588 .inherits = &sis_base_ops,
590 .set_dmamode = sis_old_set_dmamode,
599 .port_ops = &sis_old_ops,
606 .port_ops = &sis_old_ops,
613 .port_ops = &sis_66_ops,
620 .port_ops = &sis_100_ops,
627 .port_ops = &sis_66_ops,
634 .port_ops = &sis_133_ops,
641 .port_ops = &sis_133_for_sata_ops,
648 .port_ops = &sis_133_early_ops,
659 if (sis->
info == &sis_info133) {
660 pci_read_config_word(pdev, 0x50, ®w);
662 pci_write_config_word(pdev, 0x50, regw & ~0x08);
663 pci_read_config_word(pdev, 0x52, ®w);
665 pci_write_config_word(pdev, 0x52, regw & ~0x08);
669 if (sis->
info == &sis_info133_early || sis->
info == &sis_info100) {
673 pci_read_config_byte(pdev, 0x49, ®);
675 pci_write_config_byte(pdev, 0x49, reg | 0x01);
679 if (sis->
info == &sis_info66 || sis->
info == &sis_info100_early) {
683 pci_read_config_byte(pdev, 0x52, ®);
685 pci_write_config_byte(pdev, 0x52, reg | 0x04);
689 if (sis->
info == &sis_info33) {
691 if (( reg & 0x0F ) != 0x00)
696 if (sis->
info == &sis_info || sis->
info == &sis_info33) {
699 pci_read_config_byte(pdev, 0x52, ®);
701 pci_write_config_byte(pdev, 0x52, reg|0x08);
733 { 0x0968, &sis_info133 },
734 { 0x0966, &sis_info133 },
735 { 0x0965, &sis_info133 },
736 { 0x0745, &sis_info100 },
737 { 0x0735, &sis_info100 },
738 { 0x0733, &sis_info100 },
739 { 0x0635, &sis_info100 },
740 { 0x0633, &sis_info100 },
742 { 0x0730, &sis_info100_early },
743 { 0x0550, &sis_info100_early },
745 { 0x0640, &sis_info66 },
746 { 0x0630, &sis_info66 },
747 { 0x0620, &sis_info66 },
748 { 0x0540, &sis_info66 },
749 { 0x0530, &sis_info66 },
751 { 0x5600, &sis_info33 },
752 { 0x5598, &sis_info33 },
753 { 0x5597, &sis_info33 },
754 { 0x5591, &sis_info33 },
755 { 0x5582, &sis_info33 },
756 { 0x5581, &sis_info33 },
758 { 0x5596, &sis_info },
759 { 0x5571, &sis_info },
760 { 0x5517, &sis_info },
761 { 0x5511, &sis_info },
766 0x0, &sis_info133_early
772 0x0, &sis_info100_early
785 for (sets = &sis_chipsets[0]; sets->
device; sets++) {
789 if (sets->
device == 0x630) {
791 chipset = &sis100_early;
798 if (chipset ==
NULL) {
806 pci_read_config_dword(pdev, 0x54, &idemisc);
807 pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
809 pci_write_config_dword(pdev, 0x54, idemisc);
814 "SiS 962/963 MuTIOL IDE UDMA133 controller\n");
816 if ((idemisc & 0x40000000) == 0) {
817 pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
819 "Switching to 5513 register mapping\n");
832 if (chipset ==
NULL) {
839 pci_read_config_byte(pdev, 0x4a, &idecfg);
840 pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
842 pci_write_config_byte(pdev, 0x4a, idecfg);
847 if (lpc_bridge ==
NULL)
849 pci_read_config_byte(pdev, 0x49, &prefctl);
852 if (lpc_bridge->
revision == 0x10 && (prefctl & 0x80)) {
853 chipset = &sis133_early;
866 ppi[0] = chipset->
info;
868 sis_fixup(pdev, chipset);
870 return ata_pci_bmdma_init_one(pdev, ppi, &sis_sht, chipset, 0);
874 static int sis_reinit_one(
struct pci_dev *pdev)
879 rc = ata_pci_device_do_resume(pdev);
885 ata_host_resume(host);
900 .id_table = sis_pci_tbl,
901 .probe = sis_init_one,
902 .remove = ata_pci_remove_one,
904 .suspend = ata_pci_device_suspend,
905 .resume = sis_reinit_one,