18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. 48c2ecf20Sopenharmony_ci * Due to massive hardware bugs, UltraDMA is only supported 58c2ecf20Sopenharmony_ci * on the 646U2 and not on the 646U. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) 88c2ecf20Sopenharmony_ci * Copyright (C) 1998 David S. Miller (davem@redhat.com) 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org> 118c2ecf20Sopenharmony_ci * Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz 128c2ecf20Sopenharmony_ci * Copyright (C) 2007,2009 MontaVista Software, Inc. <source@mvista.com> 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/module.h> 168c2ecf20Sopenharmony_ci#include <linux/types.h> 178c2ecf20Sopenharmony_ci#include <linux/pci.h> 188c2ecf20Sopenharmony_ci#include <linux/ide.h> 198c2ecf20Sopenharmony_ci#include <linux/init.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include <asm/io.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define DRV_NAME "cmd64x" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * CMD64x specific registers definition. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci#define CFR 0x50 298c2ecf20Sopenharmony_ci#define CFR_INTR_CH0 0x04 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define CMDTIM 0x52 328c2ecf20Sopenharmony_ci#define ARTTIM0 0x53 338c2ecf20Sopenharmony_ci#define DRWTIM0 0x54 348c2ecf20Sopenharmony_ci#define ARTTIM1 0x55 358c2ecf20Sopenharmony_ci#define DRWTIM1 0x56 368c2ecf20Sopenharmony_ci#define ARTTIM23 0x57 378c2ecf20Sopenharmony_ci#define ARTTIM23_DIS_RA2 0x04 388c2ecf20Sopenharmony_ci#define ARTTIM23_DIS_RA3 0x08 398c2ecf20Sopenharmony_ci#define ARTTIM23_INTR_CH1 0x10 408c2ecf20Sopenharmony_ci#define DRWTIM2 0x58 418c2ecf20Sopenharmony_ci#define BRST 0x59 428c2ecf20Sopenharmony_ci#define DRWTIM3 0x5b 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define BMIDECR0 0x70 458c2ecf20Sopenharmony_ci#define MRDMODE 0x71 468c2ecf20Sopenharmony_ci#define MRDMODE_INTR_CH0 0x04 478c2ecf20Sopenharmony_ci#define MRDMODE_INTR_CH1 0x08 488c2ecf20Sopenharmony_ci#define UDIDETCR0 0x73 498c2ecf20Sopenharmony_ci#define DTPR0 0x74 508c2ecf20Sopenharmony_ci#define BMIDECR1 0x78 518c2ecf20Sopenharmony_ci#define BMIDECSR 0x79 528c2ecf20Sopenharmony_ci#define UDIDETCR1 0x7B 538c2ecf20Sopenharmony_ci#define DTPR1 0x7C 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic void cmd64x_program_timings(ide_drive_t *drive, u8 mode) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 588c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 598c2ecf20Sopenharmony_ci int bus_speed = ide_pci_clk ? ide_pci_clk : 33; 608c2ecf20Sopenharmony_ci const unsigned long T = 1000000 / bus_speed; 618c2ecf20Sopenharmony_ci static const u8 recovery_values[] = 628c2ecf20Sopenharmony_ci {15, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0}; 638c2ecf20Sopenharmony_ci static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; 648c2ecf20Sopenharmony_ci static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; 658c2ecf20Sopenharmony_ci static const u8 drwtim_regs[4] = {DRWTIM0, DRWTIM1, DRWTIM2, DRWTIM3}; 668c2ecf20Sopenharmony_ci struct ide_timing t; 678c2ecf20Sopenharmony_ci u8 arttim = 0; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (drive->dn >= ARRAY_SIZE(drwtim_regs)) 708c2ecf20Sopenharmony_ci return; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci ide_timing_compute(drive, mode, &t, T, 0); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci /* 758c2ecf20Sopenharmony_ci * In case we've got too long recovery phase, try to lengthen 768c2ecf20Sopenharmony_ci * the active phase 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_ci if (t.recover > 16) { 798c2ecf20Sopenharmony_ci t.active += t.recover - 16; 808c2ecf20Sopenharmony_ci t.recover = 16; 818c2ecf20Sopenharmony_ci } 828c2ecf20Sopenharmony_ci if (t.active > 16) /* shouldn't actually happen... */ 838c2ecf20Sopenharmony_ci t.active = 16; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci /* 868c2ecf20Sopenharmony_ci * Convert values to internal chipset representation 878c2ecf20Sopenharmony_ci */ 888c2ecf20Sopenharmony_ci t.recover = recovery_values[t.recover]; 898c2ecf20Sopenharmony_ci t.active &= 0x0f; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* Program the active/recovery counts into the DRWTIM register */ 928c2ecf20Sopenharmony_ci pci_write_config_byte(dev, drwtim_regs[drive->dn], 938c2ecf20Sopenharmony_ci (t.active << 4) | t.recover); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci /* 968c2ecf20Sopenharmony_ci * The primary channel has individual address setup timing registers 978c2ecf20Sopenharmony_ci * for each drive and the hardware selects the slowest timing itself. 988c2ecf20Sopenharmony_ci * The secondary channel has one common register and we have to select 998c2ecf20Sopenharmony_ci * the slowest address setup timing ourselves. 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci if (hwif->channel) { 1028c2ecf20Sopenharmony_ci ide_drive_t *pair = ide_get_pair_dev(drive); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci if (pair) { 1058c2ecf20Sopenharmony_ci struct ide_timing tp; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci ide_timing_compute(pair, pair->pio_mode, &tp, T, 0); 1088c2ecf20Sopenharmony_ci ide_timing_merge(&t, &tp, &t, IDE_TIMING_SETUP); 1098c2ecf20Sopenharmony_ci if (pair->dma_mode) { 1108c2ecf20Sopenharmony_ci ide_timing_compute(pair, pair->dma_mode, 1118c2ecf20Sopenharmony_ci &tp, T, 0); 1128c2ecf20Sopenharmony_ci ide_timing_merge(&tp, &t, &t, IDE_TIMING_SETUP); 1138c2ecf20Sopenharmony_ci } 1148c2ecf20Sopenharmony_ci } 1158c2ecf20Sopenharmony_ci } 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci if (t.setup > 5) /* shouldn't actually happen... */ 1188c2ecf20Sopenharmony_ci t.setup = 5; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci /* 1218c2ecf20Sopenharmony_ci * Program the address setup clocks into the ARTTIM registers. 1228c2ecf20Sopenharmony_ci * Avoid clearing the secondary channel's interrupt bit. 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci (void) pci_read_config_byte (dev, arttim_regs[drive->dn], &arttim); 1258c2ecf20Sopenharmony_ci if (hwif->channel) 1268c2ecf20Sopenharmony_ci arttim &= ~ARTTIM23_INTR_CH1; 1278c2ecf20Sopenharmony_ci arttim &= ~0xc0; 1288c2ecf20Sopenharmony_ci arttim |= setup_values[t.setup]; 1298c2ecf20Sopenharmony_ci (void) pci_write_config_byte(dev, arttim_regs[drive->dn], arttim); 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/* 1338c2ecf20Sopenharmony_ci * Attempts to set drive's PIO mode. 1348c2ecf20Sopenharmony_ci * Special cases are 8: prefetch off, 9: prefetch on (both never worked) 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic void cmd64x_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci const u8 pio = drive->pio_mode - XFER_PIO_0; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci /* 1428c2ecf20Sopenharmony_ci * Filter out the prefetch control values 1438c2ecf20Sopenharmony_ci * to prevent PIO5 from being programmed 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_ci if (pio == 8 || pio == 9) 1468c2ecf20Sopenharmony_ci return; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci cmd64x_program_timings(drive, XFER_PIO_0 + pio); 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic void cmd64x_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1548c2ecf20Sopenharmony_ci u8 unit = drive->dn & 0x01; 1558c2ecf20Sopenharmony_ci u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0; 1568c2ecf20Sopenharmony_ci const u8 speed = drive->dma_mode; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci pci_read_config_byte(dev, pciU, ®U); 1598c2ecf20Sopenharmony_ci regU &= ~(unit ? 0xCA : 0x35); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci switch(speed) { 1628c2ecf20Sopenharmony_ci case XFER_UDMA_5: 1638c2ecf20Sopenharmony_ci regU |= unit ? 0x0A : 0x05; 1648c2ecf20Sopenharmony_ci break; 1658c2ecf20Sopenharmony_ci case XFER_UDMA_4: 1668c2ecf20Sopenharmony_ci regU |= unit ? 0x4A : 0x15; 1678c2ecf20Sopenharmony_ci break; 1688c2ecf20Sopenharmony_ci case XFER_UDMA_3: 1698c2ecf20Sopenharmony_ci regU |= unit ? 0x8A : 0x25; 1708c2ecf20Sopenharmony_ci break; 1718c2ecf20Sopenharmony_ci case XFER_UDMA_2: 1728c2ecf20Sopenharmony_ci regU |= unit ? 0x42 : 0x11; 1738c2ecf20Sopenharmony_ci break; 1748c2ecf20Sopenharmony_ci case XFER_UDMA_1: 1758c2ecf20Sopenharmony_ci regU |= unit ? 0x82 : 0x21; 1768c2ecf20Sopenharmony_ci break; 1778c2ecf20Sopenharmony_ci case XFER_UDMA_0: 1788c2ecf20Sopenharmony_ci regU |= unit ? 0xC2 : 0x31; 1798c2ecf20Sopenharmony_ci break; 1808c2ecf20Sopenharmony_ci case XFER_MW_DMA_2: 1818c2ecf20Sopenharmony_ci case XFER_MW_DMA_1: 1828c2ecf20Sopenharmony_ci case XFER_MW_DMA_0: 1838c2ecf20Sopenharmony_ci cmd64x_program_timings(drive, speed); 1848c2ecf20Sopenharmony_ci break; 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci pci_write_config_byte(dev, pciU, regU); 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_cistatic void cmd648_clear_irq(ide_drive_t *drive) 1918c2ecf20Sopenharmony_ci{ 1928c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 1938c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1948c2ecf20Sopenharmony_ci unsigned long base = pci_resource_start(dev, 4); 1958c2ecf20Sopenharmony_ci u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 1968c2ecf20Sopenharmony_ci MRDMODE_INTR_CH0; 1978c2ecf20Sopenharmony_ci u8 mrdmode = inb(base + 1); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* clear the interrupt bit */ 2008c2ecf20Sopenharmony_ci outb((mrdmode & ~(MRDMODE_INTR_CH0 | MRDMODE_INTR_CH1)) | irq_mask, 2018c2ecf20Sopenharmony_ci base + 1); 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic void cmd64x_clear_irq(ide_drive_t *drive) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 2078c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 2088c2ecf20Sopenharmony_ci int irq_reg = hwif->channel ? ARTTIM23 : CFR; 2098c2ecf20Sopenharmony_ci u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 2108c2ecf20Sopenharmony_ci CFR_INTR_CH0; 2118c2ecf20Sopenharmony_ci u8 irq_stat = 0; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 2148c2ecf20Sopenharmony_ci /* clear the interrupt bit */ 2158c2ecf20Sopenharmony_ci (void) pci_write_config_byte(dev, irq_reg, irq_stat | irq_mask); 2168c2ecf20Sopenharmony_ci} 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistatic int cmd648_test_irq(ide_hwif_t *hwif) 2198c2ecf20Sopenharmony_ci{ 2208c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 2218c2ecf20Sopenharmony_ci unsigned long base = pci_resource_start(dev, 4); 2228c2ecf20Sopenharmony_ci u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 2238c2ecf20Sopenharmony_ci MRDMODE_INTR_CH0; 2248c2ecf20Sopenharmony_ci u8 mrdmode = inb(base + 1); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci pr_debug("%s: mrdmode: 0x%02x irq_mask: 0x%02x\n", 2278c2ecf20Sopenharmony_ci hwif->name, mrdmode, irq_mask); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci return (mrdmode & irq_mask) ? 1 : 0; 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic int cmd64x_test_irq(ide_hwif_t *hwif) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 2358c2ecf20Sopenharmony_ci int irq_reg = hwif->channel ? ARTTIM23 : CFR; 2368c2ecf20Sopenharmony_ci u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 2378c2ecf20Sopenharmony_ci CFR_INTR_CH0; 2388c2ecf20Sopenharmony_ci u8 irq_stat = 0; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci pr_debug("%s: irq_stat: 0x%02x irq_mask: 0x%02x\n", 2438c2ecf20Sopenharmony_ci hwif->name, irq_stat, irq_mask); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci return (irq_stat & irq_mask) ? 1 : 0; 2468c2ecf20Sopenharmony_ci} 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci/* 2498c2ecf20Sopenharmony_ci * ASUS P55T2P4D with CMD646 chipset revision 0x01 requires the old 2508c2ecf20Sopenharmony_ci * event order for DMA transfers. 2518c2ecf20Sopenharmony_ci */ 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_cistatic int cmd646_1_dma_end(ide_drive_t *drive) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci ide_hwif_t *hwif = drive->hwif; 2568c2ecf20Sopenharmony_ci u8 dma_stat = 0, dma_cmd = 0; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* get DMA status */ 2598c2ecf20Sopenharmony_ci dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 2608c2ecf20Sopenharmony_ci /* read DMA command state */ 2618c2ecf20Sopenharmony_ci dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); 2628c2ecf20Sopenharmony_ci /* stop DMA */ 2638c2ecf20Sopenharmony_ci outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD); 2648c2ecf20Sopenharmony_ci /* clear the INTR & ERROR bits */ 2658c2ecf20Sopenharmony_ci outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS); 2668c2ecf20Sopenharmony_ci /* verify good DMA status */ 2678c2ecf20Sopenharmony_ci return (dma_stat & 7) != 4; 2688c2ecf20Sopenharmony_ci} 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_cistatic int init_chipset_cmd64x(struct pci_dev *dev) 2718c2ecf20Sopenharmony_ci{ 2728c2ecf20Sopenharmony_ci u8 mrdmode = 0; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci /* Set a good latency timer and cache line size value. */ 2758c2ecf20Sopenharmony_ci (void) pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 2768c2ecf20Sopenharmony_ci /* FIXME: pci_set_master() to ensure a good latency timer value */ 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci /* 2798c2ecf20Sopenharmony_ci * Enable interrupts, select MEMORY READ LINE for reads. 2808c2ecf20Sopenharmony_ci * 2818c2ecf20Sopenharmony_ci * NOTE: although not mentioned in the PCI0646U specs, 2828c2ecf20Sopenharmony_ci * bits 0-1 are write only and won't be read back as 2838c2ecf20Sopenharmony_ci * set or not -- PCI0646U2 specs clarify this point. 2848c2ecf20Sopenharmony_ci */ 2858c2ecf20Sopenharmony_ci (void) pci_read_config_byte (dev, MRDMODE, &mrdmode); 2868c2ecf20Sopenharmony_ci mrdmode &= ~0x30; 2878c2ecf20Sopenharmony_ci (void) pci_write_config_byte(dev, MRDMODE, (mrdmode | 0x02)); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci return 0; 2908c2ecf20Sopenharmony_ci} 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_cistatic u8 cmd64x_cable_detect(ide_hwif_t *hwif) 2938c2ecf20Sopenharmony_ci{ 2948c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 2958c2ecf20Sopenharmony_ci u8 bmidecsr = 0, mask = hwif->channel ? 0x02 : 0x01; 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci switch (dev->device) { 2988c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_CMD_648: 2998c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_CMD_649: 3008c2ecf20Sopenharmony_ci pci_read_config_byte(dev, BMIDECSR, &bmidecsr); 3018c2ecf20Sopenharmony_ci return (bmidecsr & mask) ? ATA_CBL_PATA80 : ATA_CBL_PATA40; 3028c2ecf20Sopenharmony_ci default: 3038c2ecf20Sopenharmony_ci return ATA_CBL_PATA40; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci} 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_cistatic const struct ide_port_ops cmd64x_port_ops = { 3088c2ecf20Sopenharmony_ci .set_pio_mode = cmd64x_set_pio_mode, 3098c2ecf20Sopenharmony_ci .set_dma_mode = cmd64x_set_dma_mode, 3108c2ecf20Sopenharmony_ci .clear_irq = cmd64x_clear_irq, 3118c2ecf20Sopenharmony_ci .test_irq = cmd64x_test_irq, 3128c2ecf20Sopenharmony_ci .cable_detect = cmd64x_cable_detect, 3138c2ecf20Sopenharmony_ci}; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_cistatic const struct ide_port_ops cmd648_port_ops = { 3168c2ecf20Sopenharmony_ci .set_pio_mode = cmd64x_set_pio_mode, 3178c2ecf20Sopenharmony_ci .set_dma_mode = cmd64x_set_dma_mode, 3188c2ecf20Sopenharmony_ci .clear_irq = cmd648_clear_irq, 3198c2ecf20Sopenharmony_ci .test_irq = cmd648_test_irq, 3208c2ecf20Sopenharmony_ci .cable_detect = cmd64x_cable_detect, 3218c2ecf20Sopenharmony_ci}; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistatic const struct ide_dma_ops cmd646_rev1_dma_ops = { 3248c2ecf20Sopenharmony_ci .dma_host_set = ide_dma_host_set, 3258c2ecf20Sopenharmony_ci .dma_setup = ide_dma_setup, 3268c2ecf20Sopenharmony_ci .dma_start = ide_dma_start, 3278c2ecf20Sopenharmony_ci .dma_end = cmd646_1_dma_end, 3288c2ecf20Sopenharmony_ci .dma_test_irq = ide_dma_test_irq, 3298c2ecf20Sopenharmony_ci .dma_lost_irq = ide_dma_lost_irq, 3308c2ecf20Sopenharmony_ci .dma_timer_expiry = ide_dma_sff_timer_expiry, 3318c2ecf20Sopenharmony_ci .dma_sff_read_status = ide_dma_sff_read_status, 3328c2ecf20Sopenharmony_ci}; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_cistatic const struct ide_port_info cmd64x_chipsets[] = { 3358c2ecf20Sopenharmony_ci { /* 0: CMD643 */ 3368c2ecf20Sopenharmony_ci .name = DRV_NAME, 3378c2ecf20Sopenharmony_ci .init_chipset = init_chipset_cmd64x, 3388c2ecf20Sopenharmony_ci .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 3398c2ecf20Sopenharmony_ci .port_ops = &cmd64x_port_ops, 3408c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | 3418c2ecf20Sopenharmony_ci IDE_HFLAG_ABUSE_PREFETCH | 3428c2ecf20Sopenharmony_ci IDE_HFLAG_SERIALIZE, 3438c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO5, 3448c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3458c2ecf20Sopenharmony_ci .udma_mask = 0x00, /* no udma */ 3468c2ecf20Sopenharmony_ci }, 3478c2ecf20Sopenharmony_ci { /* 1: CMD646 */ 3488c2ecf20Sopenharmony_ci .name = DRV_NAME, 3498c2ecf20Sopenharmony_ci .init_chipset = init_chipset_cmd64x, 3508c2ecf20Sopenharmony_ci .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 3518c2ecf20Sopenharmony_ci .port_ops = &cmd648_port_ops, 3528c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_ABUSE_PREFETCH | 3538c2ecf20Sopenharmony_ci IDE_HFLAG_SERIALIZE, 3548c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO5, 3558c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3568c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA2, 3578c2ecf20Sopenharmony_ci }, 3588c2ecf20Sopenharmony_ci { /* 2: CMD648 */ 3598c2ecf20Sopenharmony_ci .name = DRV_NAME, 3608c2ecf20Sopenharmony_ci .init_chipset = init_chipset_cmd64x, 3618c2ecf20Sopenharmony_ci .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 3628c2ecf20Sopenharmony_ci .port_ops = &cmd648_port_ops, 3638c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_ABUSE_PREFETCH, 3648c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO5, 3658c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3668c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA4, 3678c2ecf20Sopenharmony_ci }, 3688c2ecf20Sopenharmony_ci { /* 3: CMD649 */ 3698c2ecf20Sopenharmony_ci .name = DRV_NAME, 3708c2ecf20Sopenharmony_ci .init_chipset = init_chipset_cmd64x, 3718c2ecf20Sopenharmony_ci .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 3728c2ecf20Sopenharmony_ci .port_ops = &cmd648_port_ops, 3738c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_ABUSE_PREFETCH, 3748c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO5, 3758c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3768c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA5, 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci}; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_cistatic int cmd64x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci struct ide_port_info d; 3838c2ecf20Sopenharmony_ci u8 idx = id->driver_data; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci d = cmd64x_chipsets[idx]; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci if (idx == 1) { 3888c2ecf20Sopenharmony_ci /* 3898c2ecf20Sopenharmony_ci * UltraDMA only supported on PCI646U and PCI646U2, which 3908c2ecf20Sopenharmony_ci * correspond to revisions 0x03, 0x05 and 0x07 respectively. 3918c2ecf20Sopenharmony_ci * Actually, although the CMD tech support people won't 3928c2ecf20Sopenharmony_ci * tell me the details, the 0x03 revision cannot support 3938c2ecf20Sopenharmony_ci * UDMA correctly without hardware modifications, and even 3948c2ecf20Sopenharmony_ci * then it only works with Quantum disks due to some 3958c2ecf20Sopenharmony_ci * hold time assumptions in the 646U part which are fixed 3968c2ecf20Sopenharmony_ci * in the 646U2. 3978c2ecf20Sopenharmony_ci * 3988c2ecf20Sopenharmony_ci * So we only do UltraDMA on revision 0x05 and 0x07 chipsets. 3998c2ecf20Sopenharmony_ci */ 4008c2ecf20Sopenharmony_ci if (dev->revision < 5) { 4018c2ecf20Sopenharmony_ci d.udma_mask = 0x00; 4028c2ecf20Sopenharmony_ci /* 4038c2ecf20Sopenharmony_ci * The original PCI0646 didn't have the primary 4048c2ecf20Sopenharmony_ci * channel enable bit, it appeared starting with 4058c2ecf20Sopenharmony_ci * PCI0646U (i.e. revision ID 3). 4068c2ecf20Sopenharmony_ci */ 4078c2ecf20Sopenharmony_ci if (dev->revision < 3) { 4088c2ecf20Sopenharmony_ci d.enablebits[0].reg = 0; 4098c2ecf20Sopenharmony_ci d.port_ops = &cmd64x_port_ops; 4108c2ecf20Sopenharmony_ci if (dev->revision == 1) 4118c2ecf20Sopenharmony_ci d.dma_ops = &cmd646_rev1_dma_ops; 4128c2ecf20Sopenharmony_ci } 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci } 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci return ide_pci_init_one(dev, &d, NULL); 4178c2ecf20Sopenharmony_ci} 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_cistatic const struct pci_device_id cmd64x_pci_tbl[] = { 4208c2ecf20Sopenharmony_ci { PCI_VDEVICE(CMD, PCI_DEVICE_ID_CMD_643), 0 }, 4218c2ecf20Sopenharmony_ci { PCI_VDEVICE(CMD, PCI_DEVICE_ID_CMD_646), 1 }, 4228c2ecf20Sopenharmony_ci { PCI_VDEVICE(CMD, PCI_DEVICE_ID_CMD_648), 2 }, 4238c2ecf20Sopenharmony_ci { PCI_VDEVICE(CMD, PCI_DEVICE_ID_CMD_649), 3 }, 4248c2ecf20Sopenharmony_ci { 0, }, 4258c2ecf20Sopenharmony_ci}; 4268c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl); 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_cistatic struct pci_driver cmd64x_pci_driver = { 4298c2ecf20Sopenharmony_ci .name = "CMD64x_IDE", 4308c2ecf20Sopenharmony_ci .id_table = cmd64x_pci_tbl, 4318c2ecf20Sopenharmony_ci .probe = cmd64x_init_one, 4328c2ecf20Sopenharmony_ci .remove = ide_pci_remove, 4338c2ecf20Sopenharmony_ci .suspend = ide_pci_suspend, 4348c2ecf20Sopenharmony_ci .resume = ide_pci_resume, 4358c2ecf20Sopenharmony_ci}; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_cistatic int __init cmd64x_ide_init(void) 4388c2ecf20Sopenharmony_ci{ 4398c2ecf20Sopenharmony_ci return ide_pci_register_driver(&cmd64x_pci_driver); 4408c2ecf20Sopenharmony_ci} 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_cistatic void __exit cmd64x_ide_exit(void) 4438c2ecf20Sopenharmony_ci{ 4448c2ecf20Sopenharmony_ci pci_unregister_driver(&cmd64x_pci_driver); 4458c2ecf20Sopenharmony_ci} 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_cimodule_init(cmd64x_ide_init); 4488c2ecf20Sopenharmony_cimodule_exit(cmd64x_ide_exit); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ciMODULE_AUTHOR("Eddie Dost, David Miller, Andre Hedrick, Bartlomiej Zolnierkiewicz"); 4518c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PCI driver module for CMD64x IDE"); 4528c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 453