18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 1998-2000 Michel Aubry 48c2ecf20Sopenharmony_ci * Copyright (C) 1998-2000 Andrzej Krzysztofowicz 58c2ecf20Sopenharmony_ci * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 68c2ecf20Sopenharmony_ci * Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz 78c2ecf20Sopenharmony_ci * Portions copyright (c) 2001 Sun Microsystems 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * RCC/ServerWorks IDE driver for Linux 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * OSB4: `Open South Bridge' IDE Interface (fn 1) 138c2ecf20Sopenharmony_ci * supports UDMA mode 2 (33 MB/s) 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * CSB5: `Champion South Bridge' IDE Interface (fn 1) 168c2ecf20Sopenharmony_ci * all revisions support UDMA mode 4 (66 MB/s) 178c2ecf20Sopenharmony_ci * revision A2.0 and up support UDMA mode 5 (100 MB/s) 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * *** The CSB5 does not provide ANY register *** 208c2ecf20Sopenharmony_ci * *** to detect 80-conductor cable presence. *** 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * CSB6: `Champion South Bridge' IDE Interface (optional: third channel) 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * HT1000: AKA BCM5785 - Hypertransport Southbridge for Opteron systems. IDE 258c2ecf20Sopenharmony_ci * controller same as the CSB6. Single channel ATA100 only. 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * Documentation: 288c2ecf20Sopenharmony_ci * Available under NDA only. Errata info very hard to get. 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <linux/types.h> 338c2ecf20Sopenharmony_ci#include <linux/module.h> 348c2ecf20Sopenharmony_ci#include <linux/kernel.h> 358c2ecf20Sopenharmony_ci#include <linux/pci.h> 368c2ecf20Sopenharmony_ci#include <linux/ide.h> 378c2ecf20Sopenharmony_ci#include <linux/init.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <asm/io.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define DRV_NAME "serverworks" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */ 448c2ecf20Sopenharmony_ci#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* Seagate Barracuda ATA IV Family drives in UDMA mode 5 478c2ecf20Sopenharmony_ci * can overrun their FIFOs when used with the CSB5 */ 488c2ecf20Sopenharmony_cistatic const char *svwks_bad_ata100[] = { 498c2ecf20Sopenharmony_ci "ST320011A", 508c2ecf20Sopenharmony_ci "ST340016A", 518c2ecf20Sopenharmony_ci "ST360021A", 528c2ecf20Sopenharmony_ci "ST380021A", 538c2ecf20Sopenharmony_ci NULL 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic int check_in_drive_lists (ide_drive_t *drive, const char **list) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci char *m = (char *)&drive->id[ATA_ID_PROD]; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci while (*list) 618c2ecf20Sopenharmony_ci if (!strcmp(*list++, m)) 628c2ecf20Sopenharmony_ci return 1; 638c2ecf20Sopenharmony_ci return 0; 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic u8 svwks_udma_filter(ide_drive_t *drive) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) { 718c2ecf20Sopenharmony_ci return 0x1f; 728c2ecf20Sopenharmony_ci } else if (dev->revision < SVWKS_CSB5_REVISION_NEW) { 738c2ecf20Sopenharmony_ci return 0x07; 748c2ecf20Sopenharmony_ci } else { 758c2ecf20Sopenharmony_ci u8 btr = 0, mode, mask; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x5A, &btr); 788c2ecf20Sopenharmony_ci mode = btr & 0x3; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci /* If someone decides to do UDMA133 on CSB5 the same 818c2ecf20Sopenharmony_ci issue will bite so be inclusive */ 828c2ecf20Sopenharmony_ci if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100)) 838c2ecf20Sopenharmony_ci mode = 2; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci switch(mode) { 868c2ecf20Sopenharmony_ci case 3: mask = 0x3f; break; 878c2ecf20Sopenharmony_ci case 2: mask = 0x1f; break; 888c2ecf20Sopenharmony_ci case 1: mask = 0x07; break; 898c2ecf20Sopenharmony_ci default: mask = 0x00; break; 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci return mask; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic u8 svwks_csb_check (struct pci_dev *dev) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci switch (dev->device) { 998c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: 1008c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE: 1018c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2: 1028c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE: 1038c2ecf20Sopenharmony_ci return 1; 1048c2ecf20Sopenharmony_ci default: 1058c2ecf20Sopenharmony_ci break; 1068c2ecf20Sopenharmony_ci } 1078c2ecf20Sopenharmony_ci return 0; 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistatic void svwks_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 }; 1138c2ecf20Sopenharmony_ci static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 }; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1168c2ecf20Sopenharmony_ci const u8 pio = drive->pio_mode - XFER_PIO_0; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci if (drive->dn >= ARRAY_SIZE(drive_pci)) 1198c2ecf20Sopenharmony_ci return; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci if (svwks_csb_check(dev)) { 1248c2ecf20Sopenharmony_ci u16 csb_pio = 0; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci pci_read_config_word(dev, 0x4a, &csb_pio); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci csb_pio &= ~(0x0f << (4 * drive->dn)); 1298c2ecf20Sopenharmony_ci csb_pio |= (pio << (4 * drive->dn)); 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci pci_write_config_word(dev, 0x4a, csb_pio); 1328c2ecf20Sopenharmony_ci } 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic void svwks_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; 1388c2ecf20Sopenharmony_ci static const u8 dma_modes[] = { 0x77, 0x21, 0x20 }; 1398c2ecf20Sopenharmony_ci static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 1428c2ecf20Sopenharmony_ci const u8 speed = drive->dma_mode; 1438c2ecf20Sopenharmony_ci u8 unit = drive->dn & 1; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci if (drive->dn >= ARRAY_SIZE(drive_pci2)) 1488c2ecf20Sopenharmony_ci return; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); 1518c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x54, &ultra_enable); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci ultra_timing &= ~(0x0F << (4*unit)); 1548c2ecf20Sopenharmony_ci ultra_enable &= ~(0x01 << drive->dn); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci if (speed >= XFER_UDMA_0) { 1578c2ecf20Sopenharmony_ci dma_timing |= dma_modes[2]; 1588c2ecf20Sopenharmony_ci ultra_timing |= (udma_modes[speed - XFER_UDMA_0] << (4 * unit)); 1598c2ecf20Sopenharmony_ci ultra_enable |= (0x01 << drive->dn); 1608c2ecf20Sopenharmony_ci } else if (speed >= XFER_MW_DMA_0) 1618c2ecf20Sopenharmony_ci dma_timing |= dma_modes[speed - XFER_MW_DMA_0]; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing); 1648c2ecf20Sopenharmony_ci pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing); 1658c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x54, ultra_enable); 1668c2ecf20Sopenharmony_ci} 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistatic int init_chipset_svwks(struct pci_dev *dev) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci unsigned int reg; 1718c2ecf20Sopenharmony_ci u8 btr; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci /* force Master Latency Timer value to 64 PCICLKs */ 1748c2ecf20Sopenharmony_ci pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci /* OSB4 : South Bridge and IDE */ 1778c2ecf20Sopenharmony_ci if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 1788c2ecf20Sopenharmony_ci struct pci_dev *isa_dev = 1798c2ecf20Sopenharmony_ci pci_get_device(PCI_VENDOR_ID_SERVERWORKS, 1808c2ecf20Sopenharmony_ci PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL); 1818c2ecf20Sopenharmony_ci if (isa_dev) { 1828c2ecf20Sopenharmony_ci pci_read_config_dword(isa_dev, 0x64, ®); 1838c2ecf20Sopenharmony_ci reg &= ~0x00002000; /* disable 600ns interrupt mask */ 1848c2ecf20Sopenharmony_ci if(!(reg & 0x00004000)) 1858c2ecf20Sopenharmony_ci printk(KERN_DEBUG DRV_NAME " %s: UDMA not BIOS " 1868c2ecf20Sopenharmony_ci "enabled.\n", pci_name(dev)); 1878c2ecf20Sopenharmony_ci reg |= 0x00004000; /* enable UDMA/33 support */ 1888c2ecf20Sopenharmony_ci pci_write_config_dword(isa_dev, 0x64, reg); 1898c2ecf20Sopenharmony_ci pci_dev_put(isa_dev); 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci } 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci /* setup CSB5/CSB6 : South Bridge and IDE option RAID */ 1948c2ecf20Sopenharmony_ci else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) || 1958c2ecf20Sopenharmony_ci (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 1968c2ecf20Sopenharmony_ci (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) { 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci /* Third Channel Test */ 1998c2ecf20Sopenharmony_ci if (!(PCI_FUNC(dev->devfn) & 1)) { 2008c2ecf20Sopenharmony_ci struct pci_dev * findev = NULL; 2018c2ecf20Sopenharmony_ci u32 reg4c = 0; 2028c2ecf20Sopenharmony_ci findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, 2038c2ecf20Sopenharmony_ci PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL); 2048c2ecf20Sopenharmony_ci if (findev) { 2058c2ecf20Sopenharmony_ci pci_read_config_dword(findev, 0x4C, ®4c); 2068c2ecf20Sopenharmony_ci reg4c &= ~0x000007FF; 2078c2ecf20Sopenharmony_ci reg4c |= 0x00000040; 2088c2ecf20Sopenharmony_ci reg4c |= 0x00000020; 2098c2ecf20Sopenharmony_ci pci_write_config_dword(findev, 0x4C, reg4c); 2108c2ecf20Sopenharmony_ci pci_dev_put(findev); 2118c2ecf20Sopenharmony_ci } 2128c2ecf20Sopenharmony_ci outb_p(0x06, 0x0c00); 2138c2ecf20Sopenharmony_ci dev->irq = inb_p(0x0c01); 2148c2ecf20Sopenharmony_ci } else { 2158c2ecf20Sopenharmony_ci struct pci_dev * findev = NULL; 2168c2ecf20Sopenharmony_ci u8 reg41 = 0; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, 2198c2ecf20Sopenharmony_ci PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL); 2208c2ecf20Sopenharmony_ci if (findev) { 2218c2ecf20Sopenharmony_ci pci_read_config_byte(findev, 0x41, ®41); 2228c2ecf20Sopenharmony_ci reg41 &= ~0x40; 2238c2ecf20Sopenharmony_ci pci_write_config_byte(findev, 0x41, reg41); 2248c2ecf20Sopenharmony_ci pci_dev_put(findev); 2258c2ecf20Sopenharmony_ci } 2268c2ecf20Sopenharmony_ci /* 2278c2ecf20Sopenharmony_ci * This is a device pin issue on CSB6. 2288c2ecf20Sopenharmony_ci * Since there will be a future raid mode, 2298c2ecf20Sopenharmony_ci * early versions of the chipset require the 2308c2ecf20Sopenharmony_ci * interrupt pin to be set, and it is a compatibility 2318c2ecf20Sopenharmony_ci * mode issue. 2328c2ecf20Sopenharmony_ci */ 2338c2ecf20Sopenharmony_ci if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) 2348c2ecf20Sopenharmony_ci dev->irq = 0; 2358c2ecf20Sopenharmony_ci } 2368c2ecf20Sopenharmony_ci// pci_read_config_dword(dev, 0x40, &pioreg) 2378c2ecf20Sopenharmony_ci// pci_write_config_dword(dev, 0x40, 0x99999999); 2388c2ecf20Sopenharmony_ci// pci_read_config_dword(dev, 0x44, &dmareg); 2398c2ecf20Sopenharmony_ci// pci_write_config_dword(dev, 0x44, 0xFFFFFFFF); 2408c2ecf20Sopenharmony_ci /* setup the UDMA Control register 2418c2ecf20Sopenharmony_ci * 2428c2ecf20Sopenharmony_ci * 1. clear bit 6 to enable DMA 2438c2ecf20Sopenharmony_ci * 2. enable DMA modes with bits 0-1 2448c2ecf20Sopenharmony_ci * 00 : legacy 2458c2ecf20Sopenharmony_ci * 01 : udma2 2468c2ecf20Sopenharmony_ci * 10 : udma2/udma4 2478c2ecf20Sopenharmony_ci * 11 : udma2/udma4/udma5 2488c2ecf20Sopenharmony_ci */ 2498c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x5A, &btr); 2508c2ecf20Sopenharmony_ci btr &= ~0x40; 2518c2ecf20Sopenharmony_ci if (!(PCI_FUNC(dev->devfn) & 1)) 2528c2ecf20Sopenharmony_ci btr |= 0x2; 2538c2ecf20Sopenharmony_ci else 2548c2ecf20Sopenharmony_ci btr |= (dev->revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2; 2558c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x5A, btr); 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci /* Setup HT1000 SouthBridge Controller - Single Channel Only */ 2588c2ecf20Sopenharmony_ci else if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) { 2598c2ecf20Sopenharmony_ci pci_read_config_byte(dev, 0x5A, &btr); 2608c2ecf20Sopenharmony_ci btr &= ~0x40; 2618c2ecf20Sopenharmony_ci btr |= 0x3; 2628c2ecf20Sopenharmony_ci pci_write_config_byte(dev, 0x5A, btr); 2638c2ecf20Sopenharmony_ci } 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci return 0; 2668c2ecf20Sopenharmony_ci} 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_cistatic u8 ata66_svwks_svwks(ide_hwif_t *hwif) 2698c2ecf20Sopenharmony_ci{ 2708c2ecf20Sopenharmony_ci return ATA_CBL_PATA80; 2718c2ecf20Sopenharmony_ci} 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci/* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits 2748c2ecf20Sopenharmony_ci * of the subsystem device ID indicate presence of an 80-pin cable. 2758c2ecf20Sopenharmony_ci * Bit 15 clear = secondary IDE channel does not have 80-pin cable. 2768c2ecf20Sopenharmony_ci * Bit 15 set = secondary IDE channel has 80-pin cable. 2778c2ecf20Sopenharmony_ci * Bit 14 clear = primary IDE channel does not have 80-pin cable. 2788c2ecf20Sopenharmony_ci * Bit 14 set = primary IDE channel has 80-pin cable. 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_cistatic u8 ata66_svwks_dell(ide_hwif_t *hwif) 2818c2ecf20Sopenharmony_ci{ 2828c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL && 2858c2ecf20Sopenharmony_ci dev->vendor == PCI_VENDOR_ID_SERVERWORKS && 2868c2ecf20Sopenharmony_ci (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE || 2878c2ecf20Sopenharmony_ci dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE)) 2888c2ecf20Sopenharmony_ci return ((1 << (hwif->channel + 14)) & 2898c2ecf20Sopenharmony_ci dev->subsystem_device) ? ATA_CBL_PATA80 : ATA_CBL_PATA40; 2908c2ecf20Sopenharmony_ci return ATA_CBL_PATA40; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/* Sun Cobalt Alpine hardware avoids the 80-pin cable 2948c2ecf20Sopenharmony_ci * detect issue by attaching the drives directly to the board. 2958c2ecf20Sopenharmony_ci * This check follows the Dell precedent (how scary is that?!) 2968c2ecf20Sopenharmony_ci * 2978c2ecf20Sopenharmony_ci * WARNING: this only works on Alpine hardware! 2988c2ecf20Sopenharmony_ci */ 2998c2ecf20Sopenharmony_cistatic u8 ata66_svwks_cobalt(ide_hwif_t *hwif) 3008c2ecf20Sopenharmony_ci{ 3018c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN && 3048c2ecf20Sopenharmony_ci dev->vendor == PCI_VENDOR_ID_SERVERWORKS && 3058c2ecf20Sopenharmony_ci dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) 3068c2ecf20Sopenharmony_ci return ((1 << (hwif->channel + 14)) & 3078c2ecf20Sopenharmony_ci dev->subsystem_device) ? ATA_CBL_PATA80 : ATA_CBL_PATA40; 3088c2ecf20Sopenharmony_ci return ATA_CBL_PATA40; 3098c2ecf20Sopenharmony_ci} 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_cistatic u8 svwks_cable_detect(ide_hwif_t *hwif) 3128c2ecf20Sopenharmony_ci{ 3138c2ecf20Sopenharmony_ci struct pci_dev *dev = to_pci_dev(hwif->dev); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci /* Server Works */ 3168c2ecf20Sopenharmony_ci if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS) 3178c2ecf20Sopenharmony_ci return ata66_svwks_svwks (hwif); 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci /* Dell PowerEdge */ 3208c2ecf20Sopenharmony_ci if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL) 3218c2ecf20Sopenharmony_ci return ata66_svwks_dell (hwif); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci /* Cobalt Alpine */ 3248c2ecf20Sopenharmony_ci if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN) 3258c2ecf20Sopenharmony_ci return ata66_svwks_cobalt (hwif); 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci /* Per Specified Design by OEM, and ASIC Architect */ 3288c2ecf20Sopenharmony_ci if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 3298c2ecf20Sopenharmony_ci (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) 3308c2ecf20Sopenharmony_ci return ATA_CBL_PATA80; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci return ATA_CBL_PATA40; 3338c2ecf20Sopenharmony_ci} 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_cistatic const struct ide_port_ops osb4_port_ops = { 3368c2ecf20Sopenharmony_ci .set_pio_mode = svwks_set_pio_mode, 3378c2ecf20Sopenharmony_ci .set_dma_mode = svwks_set_dma_mode, 3388c2ecf20Sopenharmony_ci}; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_cistatic const struct ide_port_ops svwks_port_ops = { 3418c2ecf20Sopenharmony_ci .set_pio_mode = svwks_set_pio_mode, 3428c2ecf20Sopenharmony_ci .set_dma_mode = svwks_set_dma_mode, 3438c2ecf20Sopenharmony_ci .udma_filter = svwks_udma_filter, 3448c2ecf20Sopenharmony_ci .cable_detect = svwks_cable_detect, 3458c2ecf20Sopenharmony_ci}; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistatic const struct ide_port_info serverworks_chipsets[] = { 3488c2ecf20Sopenharmony_ci { /* 0: OSB4 */ 3498c2ecf20Sopenharmony_ci .name = DRV_NAME, 3508c2ecf20Sopenharmony_ci .init_chipset = init_chipset_svwks, 3518c2ecf20Sopenharmony_ci .port_ops = &osb4_port_ops, 3528c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 3538c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3548c2ecf20Sopenharmony_ci .udma_mask = 0x00, /* UDMA is problematic on OSB4 */ 3558c2ecf20Sopenharmony_ci }, 3568c2ecf20Sopenharmony_ci { /* 1: CSB5 */ 3578c2ecf20Sopenharmony_ci .name = DRV_NAME, 3588c2ecf20Sopenharmony_ci .init_chipset = init_chipset_svwks, 3598c2ecf20Sopenharmony_ci .port_ops = &svwks_port_ops, 3608c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 3618c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3628c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA5, 3638c2ecf20Sopenharmony_ci }, 3648c2ecf20Sopenharmony_ci { /* 2: CSB6 */ 3658c2ecf20Sopenharmony_ci .name = DRV_NAME, 3668c2ecf20Sopenharmony_ci .init_chipset = init_chipset_svwks, 3678c2ecf20Sopenharmony_ci .port_ops = &svwks_port_ops, 3688c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 3698c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3708c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA5, 3718c2ecf20Sopenharmony_ci }, 3728c2ecf20Sopenharmony_ci { /* 3: CSB6-2 */ 3738c2ecf20Sopenharmony_ci .name = DRV_NAME, 3748c2ecf20Sopenharmony_ci .init_chipset = init_chipset_svwks, 3758c2ecf20Sopenharmony_ci .port_ops = &svwks_port_ops, 3768c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_SINGLE, 3778c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 3788c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3798c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA5, 3808c2ecf20Sopenharmony_ci }, 3818c2ecf20Sopenharmony_ci { /* 4: HT1000 */ 3828c2ecf20Sopenharmony_ci .name = DRV_NAME, 3838c2ecf20Sopenharmony_ci .init_chipset = init_chipset_svwks, 3848c2ecf20Sopenharmony_ci .port_ops = &svwks_port_ops, 3858c2ecf20Sopenharmony_ci .host_flags = IDE_HFLAG_SINGLE, 3868c2ecf20Sopenharmony_ci .pio_mask = ATA_PIO4, 3878c2ecf20Sopenharmony_ci .mwdma_mask = ATA_MWDMA2, 3888c2ecf20Sopenharmony_ci .udma_mask = ATA_UDMA5, 3898c2ecf20Sopenharmony_ci } 3908c2ecf20Sopenharmony_ci}; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci/** 3938c2ecf20Sopenharmony_ci * svwks_init_one - called when a OSB/CSB is found 3948c2ecf20Sopenharmony_ci * @dev: the svwks device 3958c2ecf20Sopenharmony_ci * @id: the matching pci id 3968c2ecf20Sopenharmony_ci * 3978c2ecf20Sopenharmony_ci * Called when the PCI registration layer (or the IDE initialization) 3988c2ecf20Sopenharmony_ci * finds a device matching our IDE device tables. 3998c2ecf20Sopenharmony_ci */ 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_cistatic int svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci struct ide_port_info d; 4048c2ecf20Sopenharmony_ci u8 idx = id->driver_data; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci d = serverworks_chipsets[idx]; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci if (idx == 1) 4098c2ecf20Sopenharmony_ci d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX; 4108c2ecf20Sopenharmony_ci else if (idx == 2 || idx == 3) { 4118c2ecf20Sopenharmony_ci if ((PCI_FUNC(dev->devfn) & 1) == 0) { 4128c2ecf20Sopenharmony_ci if (pci_resource_start(dev, 0) != 0x01f1) 4138c2ecf20Sopenharmony_ci d.host_flags |= IDE_HFLAG_NON_BOOTABLE; 4148c2ecf20Sopenharmony_ci d.host_flags |= IDE_HFLAG_SINGLE; 4158c2ecf20Sopenharmony_ci } else 4168c2ecf20Sopenharmony_ci d.host_flags &= ~IDE_HFLAG_SINGLE; 4178c2ecf20Sopenharmony_ci } 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci return ide_pci_init_one(dev, &d, NULL); 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic const struct pci_device_id svwks_pci_tbl[] = { 4238c2ecf20Sopenharmony_ci { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0 }, 4248c2ecf20Sopenharmony_ci { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE), 1 }, 4258c2ecf20Sopenharmony_ci { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE), 2 }, 4268c2ecf20Sopenharmony_ci { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2), 3 }, 4278c2ecf20Sopenharmony_ci { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 4 }, 4288c2ecf20Sopenharmony_ci { 0, }, 4298c2ecf20Sopenharmony_ci}; 4308c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, svwks_pci_tbl); 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_cistatic struct pci_driver svwks_pci_driver = { 4338c2ecf20Sopenharmony_ci .name = "Serverworks_IDE", 4348c2ecf20Sopenharmony_ci .id_table = svwks_pci_tbl, 4358c2ecf20Sopenharmony_ci .probe = svwks_init_one, 4368c2ecf20Sopenharmony_ci .remove = ide_pci_remove, 4378c2ecf20Sopenharmony_ci .suspend = ide_pci_suspend, 4388c2ecf20Sopenharmony_ci .resume = ide_pci_resume, 4398c2ecf20Sopenharmony_ci}; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_cistatic int __init svwks_ide_init(void) 4428c2ecf20Sopenharmony_ci{ 4438c2ecf20Sopenharmony_ci return ide_pci_register_driver(&svwks_pci_driver); 4448c2ecf20Sopenharmony_ci} 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_cistatic void __exit svwks_ide_exit(void) 4478c2ecf20Sopenharmony_ci{ 4488c2ecf20Sopenharmony_ci pci_unregister_driver(&svwks_pci_driver); 4498c2ecf20Sopenharmony_ci} 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_cimodule_init(svwks_ide_init); 4528c2ecf20Sopenharmony_cimodule_exit(svwks_ide_exit); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ciMODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick, Bartlomiej Zolnierkiewicz"); 4558c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE"); 4568c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 457