18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer 38c2ecf20Sopenharmony_ci * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 48c2ecf20Sopenharmony_ci * Copyright (C) 2003 Red Hat 58c2ecf20Sopenharmony_ci * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * May be copied or modified under the terms of the GNU General Public License 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Documentation: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Publicly available from Intel web site. Errata documentation 128c2ecf20Sopenharmony_ci * is also publicly available. As an aide to anyone hacking on this 138c2ecf20Sopenharmony_ci * driver the list of errata that are relevant is below.going back to 148c2ecf20Sopenharmony_ci * PIIX4. Older device documentation is now a bit tricky to find. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * Errata of note: 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * Unfixable 198c2ecf20Sopenharmony_ci * PIIX4 errata #9 - Only on ultra obscure hw 208c2ecf20Sopenharmony_ci * ICH3 errata #13 - Not observed to affect real hw 218c2ecf20Sopenharmony_ci * by Intel 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Things we must deal with 248c2ecf20Sopenharmony_ci * PIIX4 errata #10 - BM IDE hang with non UDMA 258c2ecf20Sopenharmony_ci * (must stop/start dma to recover) 268c2ecf20Sopenharmony_ci * 440MX errata #15 - As PIIX4 errata #10 278c2ecf20Sopenharmony_ci * PIIX4 errata #15 - Must not read control registers 288c2ecf20Sopenharmony_ci * during a PIO transfer 298c2ecf20Sopenharmony_ci * 440MX errata #13 - As PIIX4 errata #15 308c2ecf20Sopenharmony_ci * ICH2 errata #21 - DMA mode 0 doesn't work right 318c2ecf20Sopenharmony_ci * ICH0/1 errata #55 - As ICH2 errata #21 328c2ecf20Sopenharmony_ci * ICH2 spec c #9 - Extra operations needed to handle 338c2ecf20Sopenharmony_ci * drive hotswap [NOT YET SUPPORTED] 348c2ecf20Sopenharmony_ci * ICH2 spec c #20 - IDE PRD must not cross a 64K boundary 358c2ecf20Sopenharmony_ci * and must be dword aligned 368c2ecf20Sopenharmony_ci * ICH2 spec c #24 - UDMA mode 4,5 t85/86 should be 6ns not 3.3 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * Should have been BIOS fixed: 398c2ecf20Sopenharmony_ci * 450NX: errata #19 - DMA hangs on old 450NX 408c2ecf20Sopenharmony_ci * 450NX: errata #20 - DMA hangs on old 450NX 418c2ecf20Sopenharmony_ci * 450NX: errata #25 - Corruption with DMA on old 450NX 428c2ecf20Sopenharmony_ci * ICH3 errata #15 - IDE deadlock under high load 438c2ecf20Sopenharmony_ci * (BIOS must set dev 31 fn 0 bit 23) 448c2ecf20Sopenharmony_ci * ICH3 errata #18 - Don't use native mode 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#include <linux/types.h> 488c2ecf20Sopenharmony_ci#include <linux/module.h> 498c2ecf20Sopenharmony_ci#include <linux/kernel.h> 508c2ecf20Sopenharmony_ci#include <linux/pci.h> 518c2ecf20Sopenharmony_ci#include <linux/ide.h> 528c2ecf20Sopenharmony_ci#include <linux/init.h> 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#include <asm/io.h> 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define DRV_NAME "piix" 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic int no_piix_dma; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/** 618c2ecf20Sopenharmony_ci * piix_set_pio_mode - set host controller for PIO mode 628c2ecf20Sopenharmony_ci * @port: port 638c2ecf20Sopenharmony_ci * @drive: drive 648c2ecf20Sopenharmony_ci * 658c2ecf20Sopenharmony_ci * Set the interface PIO mode based upon the settings done by AMI BIOS. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic void piix_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 718c2ecf20Sopenharmony_ci int is_slave = drive->dn & 1; 728c2ecf20Sopenharmony_ci int master_port = hwif->channel ? 0x42 : 0x40; 738c2ecf20Sopenharmony_ci int slave_port = 0x44; 748c2ecf20Sopenharmony_ci unsigned long flags; 758c2ecf20Sopenharmony_ci u16 master_data; 768c2ecf20Sopenharmony_ci u8 slave_data; 778c2ecf20Sopenharmony_ci static DEFINE_SPINLOCK(tune_lock); 788c2ecf20Sopenharmony_ci int control = 0; 798c2ecf20Sopenharmony_ci const u8 pio = drive->pio_mode - XFER_PIO_0; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci /* ISP RTC */ 828c2ecf20Sopenharmony_ci static const u8 timings[][2]= { 838c2ecf20Sopenharmony_ci { 0, 0 }, 848c2ecf20Sopenharmony_ci { 0, 0 }, 858c2ecf20Sopenharmony_ci { 1, 0 }, 868c2ecf20Sopenharmony_ci { 2, 1 }, 878c2ecf20Sopenharmony_ci { 2, 3 }, }; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci /* 908c2ecf20Sopenharmony_ci * Master vs slave is synchronized above us but the slave register is 918c2ecf20Sopenharmony_ci * shared by the two hwifs so the corner case of two slave timeouts in 928c2ecf20Sopenharmony_ci * parallel must be locked. 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_ci spin_lock_irqsave(&tune_lock, flags); 958c2ecf20Sopenharmony_ci pci_read_config_word(dev, master_port, &master_data); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci if (pio > 1) 988c2ecf20Sopenharmony_ci control |= 1; /* Programmable timing on */ 998c2ecf20Sopenharmony_ci if (drive->media == ide_disk) 1008c2ecf20Sopenharmony_ci control |= 4; /* Prefetch, post write */ 1018c2ecf20Sopenharmony_ci if (ide_pio_need_iordy(drive, pio)) 1028c2ecf20Sopenharmony_ci control |= 2; /* IORDY */ 1038c2ecf20Sopenharmony_ci if (is_slave) { 1048c2ecf20Sopenharmony_ci master_data |= 0x4000; 1058c2ecf20Sopenharmony_ci master_data &= ~0x0070; 1068c2ecf20Sopenharmony_ci if (pio > 1) { 1078c2ecf20Sopenharmony_ci /* Set PPE, IE and TIME */ 1088c2ecf20Sopenharmony_ci master_data |= control << 4; 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci pci_read_config_byte(dev, slave_port, &slave_data); 1118c2ecf20Sopenharmony_ci slave_data &= hwif->channel ? 0x0f : 0xf0; 1128c2ecf20Sopenharmony_ci slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << 1138c2ecf20Sopenharmony_ci (hwif->channel ? 4 : 0); 1148c2ecf20Sopenharmony_ci } else { 1158c2ecf20Sopenharmony_ci master_data &= ~0x3307; 1168c2ecf20Sopenharmony_ci if (pio > 1) { 1178c2ecf20Sopenharmony_ci /* enable PPE, IE and TIME */ 1188c2ecf20Sopenharmony_ci master_data |= control; 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci master_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8); 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci pci_write_config_word(dev, master_port, master_data); 1238c2ecf20Sopenharmony_ci if (is_slave) 1248c2ecf20Sopenharmony_ci pci_write_config_byte(dev, slave_port, slave_data); 1258c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&tune_lock, flags); 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/** 1298c2ecf20Sopenharmony_ci * piix_set_dma_mode - set host controller for DMA mode 1308c2ecf20Sopenharmony_ci * @hwif: port 1318c2ecf20Sopenharmony_ci * @drive: drive 1328c2ecf20Sopenharmony_ci * 1338c2ecf20Sopenharmony_ci * Set a PIIX host controller to the desired DMA mode. This involves 1348c2ecf20Sopenharmony_ci * programming the right timing data into the PCI configuration space. 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic void piix_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1408c2ecf20Sopenharmony_ci u8 maslave = hwif->channel ? 0x42 : 0x40; 1418c2ecf20Sopenharmony_ci int a_speed = 3 << (drive->dn * 4); 1428c2ecf20Sopenharmony_ci int u_flag = 1 << drive->dn; 1438c2ecf20Sopenharmony_ci int v_flag = 0x01 << drive->dn; 1448c2ecf20Sopenharmony_ci int w_flag = 0x10 << drive->dn; 1458c2ecf20Sopenharmony_ci int u_speed = 0; 1468c2ecf20Sopenharmony_ci int sitre; 1478c2ecf20Sopenharmony_ci u16 reg4042, reg4a; 1488c2ecf20Sopenharmony_ci u8 reg48, reg54, reg55; 1498c2ecf20Sopenharmony_ci const u8 speed = drive->dma_mode; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci pci_read_config_word(dev, maslave, ®4042); 1528c2ecf20Sopenharmony_ci sitre = (reg4042 & 0x4000) ? 1 : 0; 1538c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x48, ®48); 1548c2ecf20Sopenharmony_ci pci_read_config_word(dev, 0x4a, ®4a); 1558c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x54, ®54); 1568c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x55, ®55); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci if (speed >= XFER_UDMA_0) { 1598c2ecf20Sopenharmony_ci u8 udma = speed - XFER_UDMA_0; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci u_speed = min_t(u8, 2 - (udma & 1), udma) << (drive->dn * 4); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci if (!(reg48 & u_flag)) 1648c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x48, reg48 | u_flag); 1658c2ecf20Sopenharmony_ci if (speed == XFER_UDMA_5) { 1668c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag); 1678c2ecf20Sopenharmony_ci } else { 1688c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 1698c2ecf20Sopenharmony_ci } 1708c2ecf20Sopenharmony_ci if ((reg4a & a_speed) != u_speed) 1718c2ecf20Sopenharmony_ci pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed); 1728c2ecf20Sopenharmony_ci if (speed > XFER_UDMA_2) { 1738c2ecf20Sopenharmony_ci if (!(reg54 & v_flag)) 1748c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x54, reg54 | v_flag); 1758c2ecf20Sopenharmony_ci } else 1768c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); 1778c2ecf20Sopenharmony_ci } else { 1788c2ecf20Sopenharmony_ci const u8 mwdma_to_pio[] = { 0, 3, 4 }; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci if (reg48 & u_flag) 1818c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x48, reg48 & ~u_flag); 1828c2ecf20Sopenharmony_ci if (reg4a & a_speed) 1838c2ecf20Sopenharmony_ci pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); 1848c2ecf20Sopenharmony_ci if (reg54 & v_flag) 1858c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); 1868c2ecf20Sopenharmony_ci if (reg55 & w_flag) 1878c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci if (speed >= XFER_MW_DMA_0) 1908c2ecf20Sopenharmony_ci drive->pio_mode = 1918c2ecf20Sopenharmony_ci mwdma_to_pio[speed - XFER_MW_DMA_0] + XFER_PIO_0; 1928c2ecf20Sopenharmony_ci else 1938c2ecf20Sopenharmony_ci drive->pio_mode = XFER_PIO_2; /* for SWDMA2 */ 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci piix_set_pio_mode(hwif, drive); 1968c2ecf20Sopenharmony_ci } 1978c2ecf20Sopenharmony_ci} 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/** 2008c2ecf20Sopenharmony_ci * init_chipset_ich - set up the ICH chipset 2018c2ecf20Sopenharmony_ci * @dev: PCI device to set up 2028c2ecf20Sopenharmony_ci * 2038c2ecf20Sopenharmony_ci * Initialize the PCI device as required. For the ICH this turns 2048c2ecf20Sopenharmony_ci * out to be nice and simple. 2058c2ecf20Sopenharmony_ci */ 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cistatic int init_chipset_ich(struct pci_dev *dev) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci u32 extra = 0; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci pci_read_config_dword(dev, 0x54, &extra); 2128c2ecf20Sopenharmony_ci pci_write_config_dword(dev, 0x54, extra | 0x400); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci return 0; 2158c2ecf20Sopenharmony_ci} 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci/** 2188c2ecf20Sopenharmony_ci * ich_clear_irq - clear BMDMA status 2198c2ecf20Sopenharmony_ci * @drive: IDE drive 2208c2ecf20Sopenharmony_ci * 2218c2ecf20Sopenharmony_ci * ICHx contollers set DMA INTR no matter DMA or PIO. 2228c2ecf20Sopenharmony_ci * BMDMA status might need to be cleared even for 2238c2ecf20Sopenharmony_ci * PIO interrupts to prevent spurious/lost IRQ. 2248c2ecf20Sopenharmony_ci */ 2258c2ecf20Sopenharmony_cistatic void ich_clear_irq(ide_drive_t *drive) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 2288c2ecf20Sopenharmony_ci u8 dma_stat; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci /* 2318c2ecf20Sopenharmony_ci * ide_dma_end() needs BMDMA status for error checking. 2328c2ecf20Sopenharmony_ci * So, skip clearing BMDMA status here and leave it 2338c2ecf20Sopenharmony_ci * to ide_dma_end() if this is DMA interrupt. 2348c2ecf20Sopenharmony_ci */ 2358c2ecf20Sopenharmony_ci if (drive->waiting_for_dma || hwif->dma_base == 0) 2368c2ecf20Sopenharmony_ci return; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci /* clear the INTR & ERROR bits */ 2398c2ecf20Sopenharmony_ci dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 2408c2ecf20Sopenharmony_ci /* Should we force the bit as well ? */ 2418c2ecf20Sopenharmony_ci outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS); 2428c2ecf20Sopenharmony_ci} 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cistruct ich_laptop { 2458c2ecf20Sopenharmony_ci u16 device; 2468c2ecf20Sopenharmony_ci u16 subvendor; 2478c2ecf20Sopenharmony_ci u16 subdevice; 2488c2ecf20Sopenharmony_ci}; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/* 2518c2ecf20Sopenharmony_ci * List of laptops that use short cables rather than 80 wire 2528c2ecf20Sopenharmony_ci */ 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_cistatic const struct ich_laptop ich_laptop[] = { 2558c2ecf20Sopenharmony_ci /* devid, subvendor, subdev */ 2568c2ecf20Sopenharmony_ci { 0x27DF, 0x1025, 0x0102 }, /* ICH7 on Acer 5602aWLMi */ 2578c2ecf20Sopenharmony_ci { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */ 2588c2ecf20Sopenharmony_ci { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 2598c2ecf20Sopenharmony_ci { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 2608c2ecf20Sopenharmony_ci { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 2618c2ecf20Sopenharmony_ci { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */ 2628c2ecf20Sopenharmony_ci { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */ 2638c2ecf20Sopenharmony_ci { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */ 2648c2ecf20Sopenharmony_ci { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */ 2658c2ecf20Sopenharmony_ci { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 2668c2ecf20Sopenharmony_ci { 0x27df, 0x104d, 0x900e }, /* ICH7 on Sony TZ-90 */ 2678c2ecf20Sopenharmony_ci /* end marker */ 2688c2ecf20Sopenharmony_ci { 0, } 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic u8 piix_cable_detect(ide_hwif_t *hwif) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci struct pci_dev *pdev = to_pci_dev(hwif->dev); 2748c2ecf20Sopenharmony_ci const struct ich_laptop *lap = &ich_laptop[0]; 2758c2ecf20Sopenharmony_ci u8 reg54h = 0, mask = hwif->channel ? 0xc0 : 0x30; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci /* check for specials */ 2788c2ecf20Sopenharmony_ci while (lap->device) { 2798c2ecf20Sopenharmony_ci if (lap->device == pdev->device && 2808c2ecf20Sopenharmony_ci lap->subvendor == pdev->subsystem_vendor && 2818c2ecf20Sopenharmony_ci lap->subdevice == pdev->subsystem_device) { 2828c2ecf20Sopenharmony_ci return ATA_CBL_PATA40_SHORT; 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci lap++; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci pci_read_config_byte(pdev, 0x54, ®54h); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci return (reg54h & mask) ? ATA_CBL_PATA80 : ATA_CBL_PATA40; 2908c2ecf20Sopenharmony_ci} 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/** 2938c2ecf20Sopenharmony_ci * init_hwif_piix - fill in the hwif for the PIIX 2948c2ecf20Sopenharmony_ci * @hwif: IDE interface 2958c2ecf20Sopenharmony_ci * 2968c2ecf20Sopenharmony_ci * Set up the ide_hwif_t for the PIIX interface according to the 2978c2ecf20Sopenharmony_ci * capabilities of the hardware. 2988c2ecf20Sopenharmony_ci */ 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_cistatic void init_hwif_piix(ide_hwif_t *hwif) 3018c2ecf20Sopenharmony_ci{ 3028c2ecf20Sopenharmony_ci if (!hwif->dma_base) 3038c2ecf20Sopenharmony_ci return; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci if (no_piix_dma) 3068c2ecf20Sopenharmony_ci hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0; 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic const struct ide_port_ops piix_port_ops = { 3108c2ecf20Sopenharmony_ci .set_pio_mode = piix_set_pio_mode, 3118c2ecf20Sopenharmony_ci .set_dma_mode = piix_set_dma_mode, 3128c2ecf20Sopenharmony_ci .cable_detect = piix_cable_detect, 3138c2ecf20Sopenharmony_ci}; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_cistatic const struct ide_port_ops ich_port_ops = { 3168c2ecf20Sopenharmony_ci .set_pio_mode = piix_set_pio_mode, 3178c2ecf20Sopenharmony_ci .set_dma_mode = piix_set_dma_mode, 3188c2ecf20Sopenharmony_ci .clear_irq = ich_clear_irq, 3198c2ecf20Sopenharmony_ci .cable_detect = piix_cable_detect, 3208c2ecf20Sopenharmony_ci}; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci#define DECLARE_PIIX_DEV(udma) \ 3238c2ecf20Sopenharmony_ci { \ 3248c2ecf20Sopenharmony_ci .name = DRV_NAME, \ 3258c2ecf20Sopenharmony_ci .init_hwif = init_hwif_piix, \ 3268c2ecf20Sopenharmony_ci .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 3278c2ecf20Sopenharmony_ci .port_ops = &piix_port_ops, \ 3288c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, \ 3298c2ecf20Sopenharmony_ci .swdma_mask = ATA_SWDMA2_ONLY, \ 3308c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA12_ONLY, \ 3318c2ecf20Sopenharmony_ci .udma_mask = udma, \ 3328c2ecf20Sopenharmony_ci } 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci#define DECLARE_ICH_DEV(mwdma, udma) \ 3358c2ecf20Sopenharmony_ci { \ 3368c2ecf20Sopenharmony_ci .name = DRV_NAME, \ 3378c2ecf20Sopenharmony_ci .init_chipset = init_chipset_ich, \ 3388c2ecf20Sopenharmony_ci .init_hwif = init_hwif_piix, \ 3398c2ecf20Sopenharmony_ci .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 3408c2ecf20Sopenharmony_ci .port_ops = &ich_port_ops, \ 3418c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, \ 3428c2ecf20Sopenharmony_ci .swdma_mask = ATA_SWDMA2_ONLY, \ 3438c2ecf20Sopenharmony_ci .mwdma_mask = mwdma, \ 3448c2ecf20Sopenharmony_ci .udma_mask = udma, \ 3458c2ecf20Sopenharmony_ci } 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistatic const struct ide_port_info piix_pci_info[] = { 3488c2ecf20Sopenharmony_ci /* 0: MPIIX */ 3498c2ecf20Sopenharmony_ci { /* 3508c2ecf20Sopenharmony_ci * MPIIX actually has only a single IDE channel mapped to 3518c2ecf20Sopenharmony_ci * the primary or secondary ports depending on the value 3528c2ecf20Sopenharmony_ci * of the bit 14 of the IDETIM register at offset 0x6c 3538c2ecf20Sopenharmony_ci */ 3548c2ecf20Sopenharmony_ci .name = DRV_NAME, 3558c2ecf20Sopenharmony_ci .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}}, 3568c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_NO_DMA, 3578c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 3588c2ecf20Sopenharmony_ci /* This is a painful system best to let it self tune for now */ 3598c2ecf20Sopenharmony_ci }, 3608c2ecf20Sopenharmony_ci /* 1: PIIXa/PIIXb/PIIX3 */ 3618c2ecf20Sopenharmony_ci DECLARE_PIIX_DEV(0x00), /* no udma */ 3628c2ecf20Sopenharmony_ci /* 2: PIIX4 */ 3638c2ecf20Sopenharmony_ci DECLARE_PIIX_DEV(ATA_UDMA2), 3648c2ecf20Sopenharmony_ci /* 3: ICH0 */ 3658c2ecf20Sopenharmony_ci DECLARE_ICH_DEV(ATA_MWDMA12_ONLY, ATA_UDMA2), 3668c2ecf20Sopenharmony_ci /* 4: ICH */ 3678c2ecf20Sopenharmony_ci DECLARE_ICH_DEV(ATA_MWDMA12_ONLY, ATA_UDMA4), 3688c2ecf20Sopenharmony_ci /* 5: PIIX4 */ 3698c2ecf20Sopenharmony_ci DECLARE_PIIX_DEV(ATA_UDMA4), 3708c2ecf20Sopenharmony_ci /* 6: ICH[2-6]/ICH[2-3]M/C-ICH/ICH5-SATA/ESB2/ICH8M */ 3718c2ecf20Sopenharmony_ci DECLARE_ICH_DEV(ATA_MWDMA12_ONLY, ATA_UDMA5), 3728c2ecf20Sopenharmony_ci /* 7: ICH7/7-R, no MWDMA1 */ 3738c2ecf20Sopenharmony_ci DECLARE_ICH_DEV(ATA_MWDMA2_ONLY, ATA_UDMA5), 3748c2ecf20Sopenharmony_ci}; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci/** 3778c2ecf20Sopenharmony_ci * piix_init_one - called when a PIIX is found 3788c2ecf20Sopenharmony_ci * @dev: the piix device 3798c2ecf20Sopenharmony_ci * @id: the matching pci id 3808c2ecf20Sopenharmony_ci * 3818c2ecf20Sopenharmony_ci * Called when the PCI registration layer (or the IDE initialization) 3828c2ecf20Sopenharmony_ci * finds a device matching our IDE device tables. 3838c2ecf20Sopenharmony_ci */ 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_cistatic int piix_init_one(struct pci_dev *dev, const struct pci_device_id *id) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci return ide_pci_init_one(dev, &piix_pci_info[id->driver_data], NULL); 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci/** 3918c2ecf20Sopenharmony_ci * piix_check_450nx - Check for problem 450NX setup 3928c2ecf20Sopenharmony_ci * 3938c2ecf20Sopenharmony_ci * Check for the present of 450NX errata #19 and errata #25. If 3948c2ecf20Sopenharmony_ci * they are found, disable use of DMA IDE 3958c2ecf20Sopenharmony_ci */ 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_cistatic void piix_check_450nx(void) 3988c2ecf20Sopenharmony_ci{ 3998c2ecf20Sopenharmony_ci struct pci_dev *pdev = NULL; 4008c2ecf20Sopenharmony_ci u16 cfg; 4018c2ecf20Sopenharmony_ci while((pdev=pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev))!=NULL) 4028c2ecf20Sopenharmony_ci { 4038c2ecf20Sopenharmony_ci /* Look for 450NX PXB. Check for problem configurations 4048c2ecf20Sopenharmony_ci A PCI quirk checks bit 6 already */ 4058c2ecf20Sopenharmony_ci pci_read_config_word(pdev, 0x41, &cfg); 4068c2ecf20Sopenharmony_ci /* Only on the original revision: IDE DMA can hang */ 4078c2ecf20Sopenharmony_ci if (pdev->revision == 0x00) 4088c2ecf20Sopenharmony_ci no_piix_dma = 1; 4098c2ecf20Sopenharmony_ci /* On all revisions below 5 PXB bus lock must be disabled for IDE */ 4108c2ecf20Sopenharmony_ci else if (cfg & (1<<14) && pdev->revision < 5) 4118c2ecf20Sopenharmony_ci no_piix_dma = 2; 4128c2ecf20Sopenharmony_ci } 4138c2ecf20Sopenharmony_ci if(no_piix_dma) 4148c2ecf20Sopenharmony_ci printk(KERN_WARNING DRV_NAME ": 450NX errata present, disabling IDE DMA.\n"); 4158c2ecf20Sopenharmony_ci if(no_piix_dma == 2) 4168c2ecf20Sopenharmony_ci printk(KERN_WARNING DRV_NAME ": A BIOS update may resolve this.\n"); 4178c2ecf20Sopenharmony_ci} 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_cistatic const struct pci_device_id piix_pci_tbl[] = { 4208c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371FB_0), 1 }, 4218c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371FB_1), 1 }, 4228c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371MX), 0 }, 4238c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371SB_1), 1 }, 4248c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371AB), 2 }, 4258c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801AB_1), 3 }, 4268c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82443MX_1), 2 }, 4278c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801AA_1), 4 }, 4288c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82372FB_1), 5 }, 4298c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82451NX), 2 }, 4308c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801BA_9), 6 }, 4318c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801BA_8), 6 }, 4328c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801CA_10), 6 }, 4338c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801CA_11), 6 }, 4348c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_11), 6 }, 4358c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801EB_11), 6 }, 4368c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801E_11), 6 }, 4378c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_10), 6 }, 4388c2ecf20Sopenharmony_ci#ifdef CONFIG_BLK_DEV_IDE_SATA 4398c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801EB_1), 6 }, 4408c2ecf20Sopenharmony_ci#endif 4418c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB_2), 6 }, 4428c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH6_19), 6 }, 4438c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH7_21), 7 }, 4448c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_1), 6 }, 4458c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB2_18), 7 }, 4468c2ecf20Sopenharmony_ci { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH8_6), 6 }, 4478c2ecf20Sopenharmony_ci { 0, }, 4488c2ecf20Sopenharmony_ci}; 4498c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, piix_pci_tbl); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_cistatic struct pci_driver piix_pci_driver = { 4528c2ecf20Sopenharmony_ci .name = "PIIX_IDE", 4538c2ecf20Sopenharmony_ci .id_table = piix_pci_tbl, 4548c2ecf20Sopenharmony_ci .probe = piix_init_one, 4558c2ecf20Sopenharmony_ci .remove = ide_pci_remove, 4568c2ecf20Sopenharmony_ci .suspend = ide_pci_suspend, 4578c2ecf20Sopenharmony_ci .resume = ide_pci_resume, 4588c2ecf20Sopenharmony_ci}; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_cistatic int __init piix_ide_init(void) 4618c2ecf20Sopenharmony_ci{ 4628c2ecf20Sopenharmony_ci piix_check_450nx(); 4638c2ecf20Sopenharmony_ci return ide_pci_register_driver(&piix_pci_driver); 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_cistatic void __exit piix_ide_exit(void) 4678c2ecf20Sopenharmony_ci{ 4688c2ecf20Sopenharmony_ci pci_unregister_driver(&piix_pci_driver); 4698c2ecf20Sopenharmony_ci} 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_cimodule_init(piix_ide_init); 4728c2ecf20Sopenharmony_cimodule_exit(piix_ide_exit); 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andre Hedrick, Andrzej Krzysztofowicz"); 4758c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PCI driver module for Intel PIIX IDE"); 4768c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 477