86 #include <linux/kernel.h>
87 #include <linux/module.h>
88 #include <linux/pci.h>
92 #include <linux/device.h>
98 #define DRV_NAME "ata_piix"
99 #define DRV_VERSION "2.13"
167 static int piix_init_one(
struct pci_dev *pdev,
169 static void piix_remove_one(
struct pci_dev *pdev);
170 static int piix_pata_prereset(
struct ata_link *
link,
unsigned long deadline);
174 static int ich_pata_cable_detect(
struct ata_port *ap);
175 static u8 piix_vmw_bmdma_status(
struct ata_port *ap);
182 static bool piix_irq_check(
struct ata_port *ap);
183 static int piix_port_start(
struct ata_port *ap);
186 static int piix_pci_device_resume(
struct pci_dev *pdev);
189 static unsigned int in_module_init = 1;
347 .id_table = piix_pci_tbl,
348 .probe = piix_init_one,
349 .remove = piix_remove_one,
351 .suspend = piix_pci_device_suspend,
352 .resume = piix_pci_device_resume,
361 .inherits = &ata_bmdma32_port_ops,
362 .sff_irq_check = piix_irq_check,
363 .port_start = piix_port_start,
367 .inherits = &piix_sata_ops,
369 .set_piomode = piix_set_piomode,
370 .set_dmamode = piix_set_dmamode,
371 .prereset = piix_pata_prereset,
375 .inherits = &piix_pata_ops,
376 .bmdma_status = piix_vmw_bmdma_status,
380 .inherits = &piix_pata_ops,
382 .set_dmamode = ich_set_dmamode,
392 .shost_attrs = piix_sidpr_shost_attrs,
396 .inherits = &piix_sata_ops,
398 .scr_read = piix_sidpr_scr_read,
399 .scr_write = piix_sidpr_scr_write,
400 .set_lpm = piix_sidpr_set_lpm,
460 static const struct piix_map_db ich8_2port_map_db = {
472 static const struct piix_map_db ich8m_apple_map_db = {
496 static const struct piix_map_db *piix_map_db_table[] = {
513 .port_ops = &piix_pata_ops,
522 .port_ops = &piix_pata_ops,
531 .port_ops = &ich_pata_ops,
540 .port_ops = &ich_pata_ops,
549 .port_ops = &ich_pata_ops,
558 .port_ops = &ich_pata_ops,
567 .port_ops = &piix_sata_ops,
576 .port_ops = &piix_sata_ops,
585 .port_ops = &piix_sata_ops,
594 .port_ops = &piix_sata_ops,
603 .port_ops = &piix_sata_ops,
612 .port_ops = &piix_sata_ops,
621 .port_ops = &piix_sata_ops,
630 .port_ops = &piix_vmw_ops,
643 .port_ops = &piix_sata_ops,
648 static struct pci_bits piix_enable_bits[] = {
649 { 0x41
U, 1
U, 0x80
UL, 0x80UL },
650 { 0x43
U, 1
U, 0x80
UL, 0x80UL },
653 MODULE_AUTHOR(
"Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
671 { 0x27DF, 0x0005, 0x0280 },
672 { 0x27DF, 0x1025, 0x0102 },
673 { 0x27DF, 0x1025, 0x0110 },
674 { 0x27DF, 0x1028, 0x02b0 },
675 { 0x27DF, 0x1043, 0x1267 },
676 { 0x27DF, 0x103C, 0x30A1 },
677 { 0x27DF, 0x103C, 0x361a },
678 { 0x27DF, 0x1071, 0xD221 },
679 { 0x27DF, 0x152D, 0x0778 },
680 { 0x24CA, 0x1025, 0x0061 },
681 { 0x24CA, 0x1025, 0x003d },
682 { 0x266F, 0x1025, 0x0066 },
683 { 0x2653, 0x1043, 0x82D8 },
684 { 0x27df, 0x104d, 0x900e },
689 static int piix_port_start(
struct ata_port *ap)
694 return ata_bmdma_port_start(ap);
708 static int ich_pata_cable_detect(
struct ata_port *ap)
712 const struct ich_laptop *lap = &ich_laptop[0];
740 static int piix_pata_prereset(
struct ata_link *
link,
unsigned long deadline)
745 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->
port_no]))
757 unsigned int is_slave = (adev->
devno != 0);
758 unsigned int master_port= ap->
port_no ? 0x42 : 0x40;
759 unsigned int slave_port = 0x44;
798 pci_read_config_word(dev, master_port, &master_data);
801 master_data &= 0xff0f;
803 master_data |= (control << 4);
804 pci_read_config_byte(dev, slave_port, &slave_data);
805 slave_data &= (ap->
port_no ? 0x0f : 0xf0);
807 slave_data |= ((timings[
pio][0] << 2) | timings[pio][1])
811 master_data &= 0xccf0;
816 (timings[
pio][0] << 12) |
817 (timings[pio][1] << 8);
821 master_data |= 0x4000;
822 pci_write_config_word(dev, master_port, master_data);
824 pci_write_config_byte(dev, slave_port, slave_data);
830 pci_read_config_byte(dev, 0x48, &udma_enable);
832 pci_write_config_byte(dev, 0x48, udma_enable);
835 spin_unlock_irqrestore(&piix_lock, flags);
866 static void do_pata_set_dmamode(
struct ata_port *ap,
struct ata_device *adev,
int isich)
878 int u_clock, u_speed;
882 pci_read_config_byte(dev, 0x48, &udma_enable);
891 u_speed =
min(2 - (udma & 1), udma);
899 udma_enable |= (1 <<
devid);
902 pci_read_config_word(dev, 0x4A, &udma_timing);
903 udma_timing &= ~(3 << (4 *
devid));
904 udma_timing |= u_speed << (4 *
devid);
905 pci_write_config_word(dev, 0x4A, udma_timing);
909 pci_read_config_word(dev, 0x54, &ideconf);
910 ideconf &= ~(0x1001 <<
devid);
911 ideconf |= u_clock <<
devid;
914 pci_write_config_word(dev, 0x54, ideconf);
917 pci_write_config_byte(dev, 0x48, udma_enable);
919 spin_unlock_irqrestore(&piix_lock, flags);
923 const unsigned int needed_pio[3] = {
929 piix_set_timings(ap, adev, pio);
946 do_pata_set_dmamode(ap, adev, 0);
962 do_pata_set_dmamode(ap, adev, 1);
973 static const int piix_sidx_map[] = {
979 static void piix_sidpr_sel(
struct ata_link *link,
unsigned int reg)
988 static int piix_sidpr_scr_read(
struct ata_link *link,
989 unsigned int reg,
u32 *
val)
996 piix_sidpr_sel(link, reg);
1001 static int piix_sidpr_scr_write(
struct ata_link *link,
1002 unsigned int reg,
u32 val)
1009 piix_sidpr_sel(link, reg);
1020 static bool piix_irq_check(
struct ata_port *ap)
1022 if (
unlikely(!ap->ioaddr.bmdma_addr))
1029 static int piix_broken_suspend(
void)
1033 .
ident =
"TECRA M3",
1040 .ident =
"TECRA M3",
1047 .ident =
"TECRA M4",
1054 .ident =
"TECRA M4",
1061 .ident =
"TECRA M5",
1068 .ident =
"TECRA M6",
1075 .ident =
"TECRA M7",
1082 .ident =
"TECRA A8",
1089 .ident =
"Satellite R20",
1096 .ident =
"Satellite R25",
1103 .ident =
"Satellite U200",
1110 .ident =
"Satellite U200",
1117 .ident =
"Satellite Pro U200",
1124 .ident =
"Satellite U205",
1131 .ident =
"SATELLITE U205",
1138 .ident =
"Satellite Pro A120",
1145 .ident =
"Portege M500",
1152 .ident =
"VGN-BX297XP",
1161 static const char *oemstrs[] = {
1194 unsigned long flags;
1197 rc = ata_host_suspend(host, mesg);
1219 spin_unlock_irqrestore(&host->
lock, flags);
1221 ata_pci_device_do_suspend(pdev, mesg);
1226 static int piix_pci_device_resume(
struct pci_dev *pdev)
1229 unsigned long flags;
1235 spin_unlock_irqrestore(&host->
lock, flags);
1247 "failed to enable device after resume (%d)\n",
1250 rc = ata_pci_device_do_resume(pdev);
1253 ata_host_resume(host);
1259 static u8 piix_vmw_bmdma_status(
struct ata_port *ap)
1264 #define AHCI_PCI_BAR 5
1265 #define AHCI_GLOBAL_CTL 0x04
1266 #define AHCI_ENABLE (1 << 31)
1267 static int piix_disable_ahci(
struct pci_dev *pdev)
1287 tmp &= ~AHCI_ENABLE;
1291 if (tmp & AHCI_ENABLE)
1311 int no_piix_dma = 0;
1316 pci_read_config_word(pdev, 0x41, &cfg);
1321 else if (cfg & (1<<14) && pdev->
revision < 5)
1326 "450NX errata present, disabling IDE DMA%s\n",
1327 no_piix_dma == 2 ?
" - a BIOS update may resolve this"
1339 pci_read_config_word(pdev,
ICH5_PCS, &pcs);
1343 if (new_pcs != pcs) {
1344 DPRINTK(
"updating PCS from 0x%x to 0x%x\n", pcs, new_pcs);
1345 pci_write_config_word(pdev,
ICH5_PCS, new_pcs);
1355 int i, invalid_map = 0;
1358 pci_read_config_byte(pdev,
ICH5_PMR, &map_value);
1360 map = map_db->
map[map_value & map_db->
mask];
1363 for (i = 0; i < 4; i++) {
1391 dev_err(&pdev->
dev,
"invalid MAP value %u\n", map_value);
1396 static bool piix_no_sidpr(
struct ata_host *host)
1422 "Samsung DB-P70 detected, disabling SIDPR\n");
1438 for (i = 0; i < 4; i++)
1439 if (hpriv->
map[i] ==
IDE)
1443 if (piix_no_sidpr(host))
1462 piix_sidpr_scr_read(link0,
SCR_CONTROL, &scontrol);
1468 if ((scontrol & 0xf00) != 0x300) {
1470 piix_sidpr_scr_write(link0,
SCR_CONTROL, scontrol);
1471 piix_sidpr_scr_read(link0,
SCR_CONTROL, &scontrol);
1473 if ((scontrol & 0xf00) != 0x300) {
1475 "SCR access via SIDPR is available but doesn't work\n");
1481 for (i = 0; i < 2; i++) {
1484 ap->
ops = &piix_sidpr_sata_ops;
1496 static void piix_iocfg_bit18_quirk(
struct ata_host *host)
1524 dev_info(&pdev->
dev,
"applying IOCFG bit18 quirk\n");
1530 static bool piix_broken_system_poweroff(
struct pci_dev *pdev)
1534 .
ident =
"HP Compaq 2510p",
1540 .driver_data = (
void *)0x1FUL,
1543 .ident =
"HP Compaq nc6000",
1549 .driver_data = (
void *)0x1FUL,
1557 unsigned long slot = (
unsigned long)dmi->driver_data;
1565 static int prefer_ms_hyperv = 1;
1568 static void piix_ignore_devices_quirk(
struct ata_host *host)
1570 #if IS_ENABLED(CONFIG_HYPERV_STORAGE)
1579 .
ident =
"Hyper-V Virtual Machine",
1582 "Microsoft Corporation"),
1590 if (dmi && prefer_ms_hyperv) {
1592 dev_info(host->
dev,
"%s detected, ATA device ignore set\n",
1620 unsigned long port_flags;
1631 if (piix_broken_system_poweroff(pdev)) {
1635 dev_info(&pdev->
dev,
"quirky BIOS, skipping spindown "
1636 "on poweroff and hibernation\n");
1665 rc = piix_disable_ahci(pdev);
1675 rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
1681 if (port_flags & ATA_FLAG_SATA) {
1682 piix_init_pcs(host, piix_map_db_table[ent->
driver_data]);
1683 rc = piix_init_sidpr(host);
1686 if (host->
ports[0]->ops == &piix_sidpr_sata_ops)
1687 sht = &piix_sidpr_sht;
1691 piix_iocfg_bit18_quirk(host);
1702 if (piix_check_450nx_errata(pdev)) {
1706 host->
ports[0]->mwdma_mask = 0;
1707 host->
ports[0]->udma_mask = 0;
1708 host->
ports[1]->mwdma_mask = 0;
1709 host->
ports[1]->udma_mask = 0;
1714 piix_ignore_devices_quirk(host);
1717 return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
1720 static void piix_remove_one(
struct pci_dev *pdev)
1727 ata_pci_remove_one(pdev);
1730 static int __init piix_init(
void)
1734 DPRINTK(
"pci_register_driver\n");
1735 rc = pci_register_driver(&piix_pci_driver);
1745 static void __exit piix_exit(
void)