1669a5db4SJeff Garzik /* 2669a5db4SJeff Garzik * ata-serverworks.c - Serverworks PATA for new ATA layer 3669a5db4SJeff Garzik * (C) 2005 Red Hat Inc 4669a5db4SJeff Garzik * Alan Cox <alan@redhat.com> 5669a5db4SJeff Garzik * 6669a5db4SJeff Garzik * based upon 7669a5db4SJeff Garzik * 8669a5db4SJeff Garzik * serverworks.c 9669a5db4SJeff Garzik * 10669a5db4SJeff Garzik * Copyright (C) 1998-2000 Michel Aubry 11669a5db4SJeff Garzik * Copyright (C) 1998-2000 Andrzej Krzysztofowicz 12669a5db4SJeff Garzik * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 13669a5db4SJeff Garzik * Portions copyright (c) 2001 Sun Microsystems 14669a5db4SJeff Garzik * 15669a5db4SJeff Garzik * 16669a5db4SJeff Garzik * RCC/ServerWorks IDE driver for Linux 17669a5db4SJeff Garzik * 18669a5db4SJeff Garzik * OSB4: `Open South Bridge' IDE Interface (fn 1) 19669a5db4SJeff Garzik * supports UDMA mode 2 (33 MB/s) 20669a5db4SJeff Garzik * 21669a5db4SJeff Garzik * CSB5: `Champion South Bridge' IDE Interface (fn 1) 22669a5db4SJeff Garzik * all revisions support UDMA mode 4 (66 MB/s) 23669a5db4SJeff Garzik * revision A2.0 and up support UDMA mode 5 (100 MB/s) 24669a5db4SJeff Garzik * 25669a5db4SJeff Garzik * *** The CSB5 does not provide ANY register *** 26669a5db4SJeff Garzik * *** to detect 80-conductor cable presence. *** 27669a5db4SJeff Garzik * 28669a5db4SJeff Garzik * CSB6: `Champion South Bridge' IDE Interface (optional: third channel) 29669a5db4SJeff Garzik * 30669a5db4SJeff Garzik * Documentation: 31669a5db4SJeff Garzik * Available under NDA only. Errata info very hard to get. 32669a5db4SJeff Garzik */ 33669a5db4SJeff Garzik 34669a5db4SJeff Garzik #include <linux/kernel.h> 35669a5db4SJeff Garzik #include <linux/module.h> 36669a5db4SJeff Garzik #include <linux/pci.h> 37669a5db4SJeff Garzik #include <linux/init.h> 38669a5db4SJeff Garzik #include <linux/blkdev.h> 39669a5db4SJeff Garzik #include <linux/delay.h> 40669a5db4SJeff Garzik #include <scsi/scsi_host.h> 41669a5db4SJeff Garzik #include <linux/libata.h> 42669a5db4SJeff Garzik 43669a5db4SJeff Garzik #define DRV_NAME "pata_serverworks" 4468d0d7abSAlan Cox #define DRV_VERSION "0.3.7" 45669a5db4SJeff Garzik 46669a5db4SJeff Garzik #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */ 47669a5db4SJeff Garzik #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */ 48669a5db4SJeff Garzik 49669a5db4SJeff Garzik /* Seagate Barracuda ATA IV Family drives in UDMA mode 5 50669a5db4SJeff Garzik * can overrun their FIFOs when used with the CSB5 */ 51669a5db4SJeff Garzik 52669a5db4SJeff Garzik static const char *csb_bad_ata100[] = { 53669a5db4SJeff Garzik "ST320011A", 54669a5db4SJeff Garzik "ST340016A", 55669a5db4SJeff Garzik "ST360021A", 56669a5db4SJeff Garzik "ST380021A", 57669a5db4SJeff Garzik NULL 58669a5db4SJeff Garzik }; 59669a5db4SJeff Garzik 60669a5db4SJeff Garzik /** 61669a5db4SJeff Garzik * dell_cable - Dell serverworks cable detection 62669a5db4SJeff Garzik * @ap: ATA port to do cable detect 63669a5db4SJeff Garzik * 64669a5db4SJeff Garzik * Dell hide the 40/80 pin select for their interfaces in the top two 65669a5db4SJeff Garzik * bits of the subsystem ID. 66669a5db4SJeff Garzik */ 67669a5db4SJeff Garzik 68669a5db4SJeff Garzik static int dell_cable(struct ata_port *ap) { 69669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 70669a5db4SJeff Garzik 71669a5db4SJeff Garzik if (pdev->subsystem_device & (1 << (ap->port_no + 14))) 72669a5db4SJeff Garzik return ATA_CBL_PATA80; 73669a5db4SJeff Garzik return ATA_CBL_PATA40; 74669a5db4SJeff Garzik } 75669a5db4SJeff Garzik 76669a5db4SJeff Garzik /** 77669a5db4SJeff Garzik * sun_cable - Sun Cobalt 'Alpine' cable detection 78669a5db4SJeff Garzik * @ap: ATA port to do cable select 79669a5db4SJeff Garzik * 80669a5db4SJeff Garzik * Cobalt CSB5 IDE hides the 40/80pin in the top two bits of the 81669a5db4SJeff Garzik * subsystem ID the same as dell. We could use one function but we may 82669a5db4SJeff Garzik * need to extend the Dell one in future 83669a5db4SJeff Garzik */ 84669a5db4SJeff Garzik 85669a5db4SJeff Garzik static int sun_cable(struct ata_port *ap) { 86669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 87669a5db4SJeff Garzik 88669a5db4SJeff Garzik if (pdev->subsystem_device & (1 << (ap->port_no + 14))) 89669a5db4SJeff Garzik return ATA_CBL_PATA80; 90669a5db4SJeff Garzik return ATA_CBL_PATA40; 91669a5db4SJeff Garzik } 92669a5db4SJeff Garzik 93669a5db4SJeff Garzik /** 94669a5db4SJeff Garzik * osb4_cable - OSB4 cable detect 95669a5db4SJeff Garzik * @ap: ATA port to check 96669a5db4SJeff Garzik * 97669a5db4SJeff Garzik * The OSB4 isn't UDMA66 capable so this is easy 98669a5db4SJeff Garzik */ 99669a5db4SJeff Garzik 100669a5db4SJeff Garzik static int osb4_cable(struct ata_port *ap) { 101669a5db4SJeff Garzik return ATA_CBL_PATA40; 102669a5db4SJeff Garzik } 103669a5db4SJeff Garzik 104669a5db4SJeff Garzik /** 105669a5db4SJeff Garzik * csb4_cable - CSB5/6 cable detect 106669a5db4SJeff Garzik * @ap: ATA port to check 107669a5db4SJeff Garzik * 108669a5db4SJeff Garzik * Serverworks default arrangement is to use the drive side detection 109669a5db4SJeff Garzik * only. 110669a5db4SJeff Garzik */ 111669a5db4SJeff Garzik 112669a5db4SJeff Garzik static int csb_cable(struct ata_port *ap) { 113669a5db4SJeff Garzik return ATA_CBL_PATA80; 114669a5db4SJeff Garzik } 115669a5db4SJeff Garzik 116669a5db4SJeff Garzik struct sv_cable_table { 117669a5db4SJeff Garzik int device; 118669a5db4SJeff Garzik int subvendor; 119669a5db4SJeff Garzik int (*cable_detect)(struct ata_port *ap); 120669a5db4SJeff Garzik }; 121669a5db4SJeff Garzik 122669a5db4SJeff Garzik /* 123669a5db4SJeff Garzik * Note that we don't copy the old serverworks code because the old 124669a5db4SJeff Garzik * code contains obvious mistakes 125669a5db4SJeff Garzik */ 126669a5db4SJeff Garzik 127669a5db4SJeff Garzik static struct sv_cable_table cable_detect[] = { 128669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_DELL, dell_cable }, 129669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_VENDOR_ID_DELL, dell_cable }, 130669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_SUN, sun_cable }, 13168d0d7abSAlan Cox { PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, osb4_cable }, 132669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, csb_cable }, 133669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, csb_cable }, 134669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, csb_cable }, 135669a5db4SJeff Garzik { PCI_DEVICE_ID_SERVERWORKS_HT1000IDE, PCI_ANY_ID, csb_cable }, 136669a5db4SJeff Garzik { } 137669a5db4SJeff Garzik }; 138669a5db4SJeff Garzik 139669a5db4SJeff Garzik /** 140669a5db4SJeff Garzik * serverworks_pre_reset - cable detection 141669a5db4SJeff Garzik * @ap: ATA port 142669a5db4SJeff Garzik * 143669a5db4SJeff Garzik * Perform cable detection according to the device and subvendor 144669a5db4SJeff Garzik * identifications 145669a5db4SJeff Garzik */ 146669a5db4SJeff Garzik 147669a5db4SJeff Garzik static int serverworks_pre_reset(struct ata_port *ap) { 148669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 149669a5db4SJeff Garzik struct sv_cable_table *cb = cable_detect; 150669a5db4SJeff Garzik 151669a5db4SJeff Garzik while(cb->device) { 152669a5db4SJeff Garzik if (cb->device == pdev->device && 153669a5db4SJeff Garzik (cb->subvendor == pdev->subsystem_vendor || 154669a5db4SJeff Garzik cb->subvendor == PCI_ANY_ID)) { 155669a5db4SJeff Garzik ap->cbl = cb->cable_detect(ap); 156669a5db4SJeff Garzik return ata_std_prereset(ap); 157669a5db4SJeff Garzik } 158669a5db4SJeff Garzik cb++; 159669a5db4SJeff Garzik } 160669a5db4SJeff Garzik 161669a5db4SJeff Garzik BUG(); 162669a5db4SJeff Garzik return -1; /* kill compiler warning */ 163669a5db4SJeff Garzik } 164669a5db4SJeff Garzik 165669a5db4SJeff Garzik static void serverworks_error_handler(struct ata_port *ap) 166669a5db4SJeff Garzik { 167669a5db4SJeff Garzik return ata_bmdma_drive_eh(ap, serverworks_pre_reset, ata_std_softreset, NULL, ata_std_postreset); 168669a5db4SJeff Garzik } 169669a5db4SJeff Garzik 170669a5db4SJeff Garzik /** 171669a5db4SJeff Garzik * serverworks_is_csb - Check for CSB or OSB 172669a5db4SJeff Garzik * @pdev: PCI device to check 173669a5db4SJeff Garzik * 174669a5db4SJeff Garzik * Returns true if the device being checked is known to be a CSB 175669a5db4SJeff Garzik * series device. 176669a5db4SJeff Garzik */ 177669a5db4SJeff Garzik 178669a5db4SJeff Garzik static u8 serverworks_is_csb(struct pci_dev *pdev) 179669a5db4SJeff Garzik { 180669a5db4SJeff Garzik switch (pdev->device) { 181669a5db4SJeff Garzik case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: 182669a5db4SJeff Garzik case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE: 183669a5db4SJeff Garzik case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2: 184669a5db4SJeff Garzik case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE: 185669a5db4SJeff Garzik return 1; 186669a5db4SJeff Garzik default: 187669a5db4SJeff Garzik break; 188669a5db4SJeff Garzik } 189669a5db4SJeff Garzik return 0; 190669a5db4SJeff Garzik } 191669a5db4SJeff Garzik 192669a5db4SJeff Garzik /** 193669a5db4SJeff Garzik * serverworks_osb4_filter - mode selection filter 194669a5db4SJeff Garzik * @ap: ATA interface 195669a5db4SJeff Garzik * @adev: ATA device 196669a5db4SJeff Garzik * 197669a5db4SJeff Garzik * Filter the offered modes for the device to apply controller 198669a5db4SJeff Garzik * specific rules. OSB4 requires no UDMA for disks due to a FIFO 199669a5db4SJeff Garzik * bug we hit. 200669a5db4SJeff Garzik */ 201669a5db4SJeff Garzik 202669a5db4SJeff Garzik static unsigned long serverworks_osb4_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 203669a5db4SJeff Garzik { 204669a5db4SJeff Garzik if (adev->class == ATA_DEV_ATA) 205669a5db4SJeff Garzik mask &= ~ATA_MASK_UDMA; 206669a5db4SJeff Garzik return ata_pci_default_filter(ap, adev, mask); 207669a5db4SJeff Garzik } 208669a5db4SJeff Garzik 209669a5db4SJeff Garzik 210669a5db4SJeff Garzik /** 211669a5db4SJeff Garzik * serverworks_csb_filter - mode selection filter 212669a5db4SJeff Garzik * @ap: ATA interface 213669a5db4SJeff Garzik * @adev: ATA device 214669a5db4SJeff Garzik * 215669a5db4SJeff Garzik * Check the blacklist and disable UDMA5 if matched 216669a5db4SJeff Garzik */ 217669a5db4SJeff Garzik 218669a5db4SJeff Garzik static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 219669a5db4SJeff Garzik { 220669a5db4SJeff Garzik const char *p; 221669a5db4SJeff Garzik char model_num[40]; 222669a5db4SJeff Garzik int len, i; 223669a5db4SJeff Garzik 224669a5db4SJeff Garzik /* Disk, UDMA */ 225669a5db4SJeff Garzik if (adev->class != ATA_DEV_ATA) 226669a5db4SJeff Garzik return ata_pci_default_filter(ap, adev, mask); 227669a5db4SJeff Garzik 228669a5db4SJeff Garzik /* Actually do need to check */ 229669a5db4SJeff Garzik ata_id_string(adev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num)); 230669a5db4SJeff Garzik /* Precuationary - why not do this in the libata core ?? */ 231669a5db4SJeff Garzik 232669a5db4SJeff Garzik len = strlen(model_num); 233669a5db4SJeff Garzik while ((len > 0) && (model_num[len - 1] == ' ')) { 234669a5db4SJeff Garzik len--; 235669a5db4SJeff Garzik model_num[len] = 0; 236669a5db4SJeff Garzik } 237669a5db4SJeff Garzik 238669a5db4SJeff Garzik for(i = 0; (p = csb_bad_ata100[i]) != NULL; i++) { 239669a5db4SJeff Garzik if (!strncmp(p, model_num, len)) 240669a5db4SJeff Garzik mask &= ~(0x1F << ATA_SHIFT_UDMA); 241669a5db4SJeff Garzik } 242669a5db4SJeff Garzik return ata_pci_default_filter(ap, adev, mask); 243669a5db4SJeff Garzik } 244669a5db4SJeff Garzik 245669a5db4SJeff Garzik 246669a5db4SJeff Garzik /** 247669a5db4SJeff Garzik * serverworks_set_piomode - set initial PIO mode data 248669a5db4SJeff Garzik * @ap: ATA interface 249669a5db4SJeff Garzik * @adev: ATA device 250669a5db4SJeff Garzik * 251669a5db4SJeff Garzik * Program the OSB4/CSB5 timing registers for PIO. The PIO register 252669a5db4SJeff Garzik * load is done as a simple lookup. 253669a5db4SJeff Garzik */ 254669a5db4SJeff Garzik static void serverworks_set_piomode(struct ata_port *ap, struct ata_device *adev) 255669a5db4SJeff Garzik { 256669a5db4SJeff Garzik static const u8 pio_mode[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 }; 257669a5db4SJeff Garzik int offset = 1 + (2 * ap->port_no) - adev->devno; 258669a5db4SJeff Garzik int devbits = (2 * ap->port_no + adev->devno) * 4; 259669a5db4SJeff Garzik u16 csb5_pio; 260669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 261669a5db4SJeff Garzik int pio = adev->pio_mode - XFER_PIO_0; 262669a5db4SJeff Garzik 263669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x40 + offset, pio_mode[pio]); 264669a5db4SJeff Garzik 265669a5db4SJeff Garzik /* The OSB4 just requires the timing but the CSB series want the 266669a5db4SJeff Garzik mode number as well */ 267669a5db4SJeff Garzik if (serverworks_is_csb(pdev)) { 268669a5db4SJeff Garzik pci_read_config_word(pdev, 0x4A, &csb5_pio); 269669a5db4SJeff Garzik csb5_pio &= ~(0x0F << devbits); 270669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x4A, csb5_pio | (pio << devbits)); 271669a5db4SJeff Garzik } 272669a5db4SJeff Garzik } 273669a5db4SJeff Garzik 274669a5db4SJeff Garzik /** 275669a5db4SJeff Garzik * serverworks_set_dmamode - set initial DMA mode data 276669a5db4SJeff Garzik * @ap: ATA interface 277669a5db4SJeff Garzik * @adev: ATA device 278669a5db4SJeff Garzik * 279669a5db4SJeff Garzik * Program the MWDMA/UDMA modes for the serverworks OSB4/CSB5 280669a5db4SJeff Garzik * chipset. The MWDMA mode values are pulled from a lookup table 281669a5db4SJeff Garzik * while the chipset uses mode number for UDMA. 282669a5db4SJeff Garzik */ 283669a5db4SJeff Garzik 284669a5db4SJeff Garzik static void serverworks_set_dmamode(struct ata_port *ap, struct ata_device *adev) 285669a5db4SJeff Garzik { 286669a5db4SJeff Garzik static const u8 dma_mode[] = { 0x77, 0x21, 0x20 }; 287669a5db4SJeff Garzik int offset = 1 + 2 * ap->port_no - adev->devno; 288669a5db4SJeff Garzik int devbits = (2 * ap->port_no + adev->devno); 289669a5db4SJeff Garzik u8 ultra; 290669a5db4SJeff Garzik u8 ultra_cfg; 291669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 292669a5db4SJeff Garzik 293669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x54, &ultra_cfg); 294669a5db4SJeff Garzik 295669a5db4SJeff Garzik if (adev->dma_mode >= XFER_UDMA_0) { 296669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x44 + offset, 0x20); 297669a5db4SJeff Garzik 298669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x56 + ap->port_no, &ultra); 299669a5db4SJeff Garzik ultra &= ~(0x0F << (ap->port_no * 4)); 300669a5db4SJeff Garzik ultra |= (adev->dma_mode - XFER_UDMA_0) 301669a5db4SJeff Garzik << (ap->port_no * 4); 302669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x56 + ap->port_no, ultra); 303669a5db4SJeff Garzik 304669a5db4SJeff Garzik ultra_cfg |= (1 << devbits); 305669a5db4SJeff Garzik } else { 306669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x44 + offset, 307669a5db4SJeff Garzik dma_mode[adev->dma_mode - XFER_MW_DMA_0]); 308669a5db4SJeff Garzik ultra_cfg &= ~(1 << devbits); 309669a5db4SJeff Garzik } 310669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x54, ultra_cfg); 311669a5db4SJeff Garzik } 312669a5db4SJeff Garzik 313669a5db4SJeff Garzik static struct scsi_host_template serverworks_sht = { 314669a5db4SJeff Garzik .module = THIS_MODULE, 315669a5db4SJeff Garzik .name = DRV_NAME, 316669a5db4SJeff Garzik .ioctl = ata_scsi_ioctl, 317669a5db4SJeff Garzik .queuecommand = ata_scsi_queuecmd, 318669a5db4SJeff Garzik .can_queue = ATA_DEF_QUEUE, 319669a5db4SJeff Garzik .this_id = ATA_SHT_THIS_ID, 320669a5db4SJeff Garzik .sg_tablesize = LIBATA_MAX_PRD, 321669a5db4SJeff Garzik .max_sectors = ATA_MAX_SECTORS, 322669a5db4SJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 323669a5db4SJeff Garzik .emulated = ATA_SHT_EMULATED, 324669a5db4SJeff Garzik .use_clustering = ATA_SHT_USE_CLUSTERING, 325669a5db4SJeff Garzik .proc_name = DRV_NAME, 326669a5db4SJeff Garzik .dma_boundary = ATA_DMA_BOUNDARY, 327669a5db4SJeff Garzik .slave_configure = ata_scsi_slave_config, 328669a5db4SJeff Garzik .bios_param = ata_std_bios_param, 329669a5db4SJeff Garzik }; 330669a5db4SJeff Garzik 331669a5db4SJeff Garzik static struct ata_port_operations serverworks_osb4_port_ops = { 332669a5db4SJeff Garzik .port_disable = ata_port_disable, 333669a5db4SJeff Garzik .set_piomode = serverworks_set_piomode, 334669a5db4SJeff Garzik .set_dmamode = serverworks_set_dmamode, 335669a5db4SJeff Garzik .mode_filter = serverworks_osb4_filter, 336669a5db4SJeff Garzik 337669a5db4SJeff Garzik .tf_load = ata_tf_load, 338669a5db4SJeff Garzik .tf_read = ata_tf_read, 339669a5db4SJeff Garzik .check_status = ata_check_status, 340669a5db4SJeff Garzik .exec_command = ata_exec_command, 341669a5db4SJeff Garzik .dev_select = ata_std_dev_select, 342669a5db4SJeff Garzik 343669a5db4SJeff Garzik .freeze = ata_bmdma_freeze, 344669a5db4SJeff Garzik .thaw = ata_bmdma_thaw, 345669a5db4SJeff Garzik .error_handler = serverworks_error_handler, 346669a5db4SJeff Garzik .post_internal_cmd = ata_bmdma_post_internal_cmd, 347669a5db4SJeff Garzik 348669a5db4SJeff Garzik .bmdma_setup = ata_bmdma_setup, 349669a5db4SJeff Garzik .bmdma_start = ata_bmdma_start, 350669a5db4SJeff Garzik .bmdma_stop = ata_bmdma_stop, 351669a5db4SJeff Garzik .bmdma_status = ata_bmdma_status, 352669a5db4SJeff Garzik 353669a5db4SJeff Garzik .qc_prep = ata_qc_prep, 354669a5db4SJeff Garzik .qc_issue = ata_qc_issue_prot, 355669a5db4SJeff Garzik .eng_timeout = ata_eng_timeout, 356669a5db4SJeff Garzik .data_xfer = ata_pio_data_xfer, 357669a5db4SJeff Garzik 358669a5db4SJeff Garzik .irq_handler = ata_interrupt, 359*efbf3f14SJeff Garzik .irq_clear = ata_bmdma_irq_clear, 360*efbf3f14SJeff Garzik 361669a5db4SJeff Garzik .port_start = ata_port_start, 362669a5db4SJeff Garzik .port_stop = ata_port_stop, 363669a5db4SJeff Garzik .host_stop = ata_host_stop 364669a5db4SJeff Garzik }; 365669a5db4SJeff Garzik 366669a5db4SJeff Garzik static struct ata_port_operations serverworks_csb_port_ops = { 367669a5db4SJeff Garzik .port_disable = ata_port_disable, 368669a5db4SJeff Garzik .set_piomode = serverworks_set_piomode, 369669a5db4SJeff Garzik .set_dmamode = serverworks_set_dmamode, 370669a5db4SJeff Garzik .mode_filter = serverworks_csb_filter, 371669a5db4SJeff Garzik 372669a5db4SJeff Garzik .tf_load = ata_tf_load, 373669a5db4SJeff Garzik .tf_read = ata_tf_read, 374669a5db4SJeff Garzik .check_status = ata_check_status, 375669a5db4SJeff Garzik .exec_command = ata_exec_command, 376669a5db4SJeff Garzik .dev_select = ata_std_dev_select, 377669a5db4SJeff Garzik 378669a5db4SJeff Garzik .freeze = ata_bmdma_freeze, 379669a5db4SJeff Garzik .thaw = ata_bmdma_thaw, 380669a5db4SJeff Garzik .error_handler = serverworks_error_handler, 381669a5db4SJeff Garzik .post_internal_cmd = ata_bmdma_post_internal_cmd, 382669a5db4SJeff Garzik 383669a5db4SJeff Garzik .bmdma_setup = ata_bmdma_setup, 384669a5db4SJeff Garzik .bmdma_start = ata_bmdma_start, 385669a5db4SJeff Garzik .bmdma_stop = ata_bmdma_stop, 386669a5db4SJeff Garzik .bmdma_status = ata_bmdma_status, 387669a5db4SJeff Garzik 388669a5db4SJeff Garzik .qc_prep = ata_qc_prep, 389669a5db4SJeff Garzik .qc_issue = ata_qc_issue_prot, 390669a5db4SJeff Garzik .eng_timeout = ata_eng_timeout, 391669a5db4SJeff Garzik .data_xfer = ata_pio_data_xfer, 392669a5db4SJeff Garzik 393669a5db4SJeff Garzik .irq_handler = ata_interrupt, 394*efbf3f14SJeff Garzik .irq_clear = ata_bmdma_irq_clear, 395*efbf3f14SJeff Garzik 396669a5db4SJeff Garzik .port_start = ata_port_start, 397669a5db4SJeff Garzik .port_stop = ata_port_stop, 398669a5db4SJeff Garzik .host_stop = ata_host_stop 399669a5db4SJeff Garzik }; 400669a5db4SJeff Garzik 401669a5db4SJeff Garzik static int serverworks_fixup_osb4(struct pci_dev *pdev) 402669a5db4SJeff Garzik { 403669a5db4SJeff Garzik u32 reg; 404669a5db4SJeff Garzik struct pci_dev *isa_dev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, 405669a5db4SJeff Garzik PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL); 406669a5db4SJeff Garzik if (isa_dev) { 407669a5db4SJeff Garzik pci_read_config_dword(isa_dev, 0x64, ®); 408669a5db4SJeff Garzik reg &= ~0x00002000; /* disable 600ns interrupt mask */ 409669a5db4SJeff Garzik if (!(reg & 0x00004000)) 410669a5db4SJeff Garzik printk(KERN_DEBUG DRV_NAME ": UDMA not BIOS enabled.\n"); 411669a5db4SJeff Garzik reg |= 0x00004000; /* enable UDMA/33 support */ 412669a5db4SJeff Garzik pci_write_config_dword(isa_dev, 0x64, reg); 413669a5db4SJeff Garzik pci_dev_put(isa_dev); 414669a5db4SJeff Garzik return 0; 415669a5db4SJeff Garzik } 416669a5db4SJeff Garzik printk(KERN_WARNING "ata_serverworks: Unable to find bridge.\n"); 417669a5db4SJeff Garzik return -ENODEV; 418669a5db4SJeff Garzik } 419669a5db4SJeff Garzik 420669a5db4SJeff Garzik static int serverworks_fixup_csb(struct pci_dev *pdev) 421669a5db4SJeff Garzik { 422669a5db4SJeff Garzik u8 rev; 423669a5db4SJeff Garzik u8 btr; 424669a5db4SJeff Garzik 425669a5db4SJeff Garzik pci_read_config_byte(pdev, PCI_REVISION_ID, &rev); 426669a5db4SJeff Garzik 427669a5db4SJeff Garzik /* Third Channel Test */ 428669a5db4SJeff Garzik if (!(PCI_FUNC(pdev->devfn) & 1)) { 429669a5db4SJeff Garzik struct pci_dev * findev = NULL; 430669a5db4SJeff Garzik u32 reg4c = 0; 431669a5db4SJeff Garzik findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, 432669a5db4SJeff Garzik PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL); 433669a5db4SJeff Garzik if (findev) { 434669a5db4SJeff Garzik pci_read_config_dword(findev, 0x4C, ®4c); 435669a5db4SJeff Garzik reg4c &= ~0x000007FF; 436669a5db4SJeff Garzik reg4c |= 0x00000040; 437669a5db4SJeff Garzik reg4c |= 0x00000020; 438669a5db4SJeff Garzik pci_write_config_dword(findev, 0x4C, reg4c); 439669a5db4SJeff Garzik pci_dev_put(findev); 440669a5db4SJeff Garzik } 441669a5db4SJeff Garzik } else { 442669a5db4SJeff Garzik struct pci_dev * findev = NULL; 443669a5db4SJeff Garzik u8 reg41 = 0; 444669a5db4SJeff Garzik 445669a5db4SJeff Garzik findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, 446669a5db4SJeff Garzik PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL); 447669a5db4SJeff Garzik if (findev) { 448669a5db4SJeff Garzik pci_read_config_byte(findev, 0x41, ®41); 449669a5db4SJeff Garzik reg41 &= ~0x40; 450669a5db4SJeff Garzik pci_write_config_byte(findev, 0x41, reg41); 451669a5db4SJeff Garzik pci_dev_put(findev); 452669a5db4SJeff Garzik } 453669a5db4SJeff Garzik } 454669a5db4SJeff Garzik /* setup the UDMA Control register 455669a5db4SJeff Garzik * 456669a5db4SJeff Garzik * 1. clear bit 6 to enable DMA 457669a5db4SJeff Garzik * 2. enable DMA modes with bits 0-1 458669a5db4SJeff Garzik * 00 : legacy 459669a5db4SJeff Garzik * 01 : udma2 460669a5db4SJeff Garzik * 10 : udma2/udma4 461669a5db4SJeff Garzik * 11 : udma2/udma4/udma5 462669a5db4SJeff Garzik */ 463669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x5A, &btr); 464669a5db4SJeff Garzik btr &= ~0x40; 465669a5db4SJeff Garzik if (!(PCI_FUNC(pdev->devfn) & 1)) 466669a5db4SJeff Garzik btr |= 0x2; 467669a5db4SJeff Garzik else 468669a5db4SJeff Garzik btr |= (rev >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2; 469669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x5A, btr); 470669a5db4SJeff Garzik 471669a5db4SJeff Garzik return btr; 472669a5db4SJeff Garzik } 473669a5db4SJeff Garzik 474669a5db4SJeff Garzik static void serverworks_fixup_ht1000(struct pci_dev *pdev) 475669a5db4SJeff Garzik { 476669a5db4SJeff Garzik u8 btr; 477669a5db4SJeff Garzik /* Setup HT1000 SouthBridge Controller - Single Channel Only */ 478669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x5A, &btr); 479669a5db4SJeff Garzik btr &= ~0x40; 480669a5db4SJeff Garzik btr |= 0x3; 481669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x5A, btr); 482669a5db4SJeff Garzik } 483669a5db4SJeff Garzik 484669a5db4SJeff Garzik 485669a5db4SJeff Garzik static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 486669a5db4SJeff Garzik { 487669a5db4SJeff Garzik int ports = 2; 488669a5db4SJeff Garzik static struct ata_port_info info[4] = { 489669a5db4SJeff Garzik { /* OSB4 */ 490669a5db4SJeff Garzik .sht = &serverworks_sht, 491669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 492669a5db4SJeff Garzik .pio_mask = 0x1f, 493669a5db4SJeff Garzik .mwdma_mask = 0x07, 494669a5db4SJeff Garzik .udma_mask = 0x07, 495669a5db4SJeff Garzik .port_ops = &serverworks_osb4_port_ops 496669a5db4SJeff Garzik }, { /* OSB4 no UDMA */ 497669a5db4SJeff Garzik .sht = &serverworks_sht, 498669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 499669a5db4SJeff Garzik .pio_mask = 0x1f, 500669a5db4SJeff Garzik .mwdma_mask = 0x07, 501669a5db4SJeff Garzik .udma_mask = 0x00, 502669a5db4SJeff Garzik .port_ops = &serverworks_osb4_port_ops 503669a5db4SJeff Garzik }, { /* CSB5 */ 504669a5db4SJeff Garzik .sht = &serverworks_sht, 505669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 506669a5db4SJeff Garzik .pio_mask = 0x1f, 507669a5db4SJeff Garzik .mwdma_mask = 0x07, 508669a5db4SJeff Garzik .udma_mask = 0x1f, 509669a5db4SJeff Garzik .port_ops = &serverworks_csb_port_ops 510669a5db4SJeff Garzik }, { /* CSB5 - later revisions*/ 511669a5db4SJeff Garzik .sht = &serverworks_sht, 512669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 513669a5db4SJeff Garzik .pio_mask = 0x1f, 514669a5db4SJeff Garzik .mwdma_mask = 0x07, 515669a5db4SJeff Garzik .udma_mask = 0x3f, 516669a5db4SJeff Garzik .port_ops = &serverworks_csb_port_ops 517669a5db4SJeff Garzik } 518669a5db4SJeff Garzik }; 519669a5db4SJeff Garzik static struct ata_port_info *port_info[2]; 520669a5db4SJeff Garzik struct ata_port_info *devinfo = &info[id->driver_data]; 521669a5db4SJeff Garzik 522669a5db4SJeff Garzik /* Force master latency timer to 64 PCI clocks */ 523669a5db4SJeff Garzik pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40); 524669a5db4SJeff Garzik 525669a5db4SJeff Garzik /* OSB4 : South Bridge and IDE */ 526669a5db4SJeff Garzik if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 527669a5db4SJeff Garzik /* Select non UDMA capable OSB4 if we can't do fixups */ 528669a5db4SJeff Garzik if ( serverworks_fixup_osb4(pdev) < 0) 529669a5db4SJeff Garzik devinfo = &info[1]; 530669a5db4SJeff Garzik } 531669a5db4SJeff Garzik /* setup CSB5/CSB6 : South Bridge and IDE option RAID */ 532669a5db4SJeff Garzik else if ((pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) || 533669a5db4SJeff Garzik (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 534669a5db4SJeff Garzik (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) { 535669a5db4SJeff Garzik 536669a5db4SJeff Garzik /* If the returned btr is the newer revision then 537669a5db4SJeff Garzik select the right info block */ 538669a5db4SJeff Garzik if (serverworks_fixup_csb(pdev) == 3) 539669a5db4SJeff Garzik devinfo = &info[3]; 540669a5db4SJeff Garzik 541669a5db4SJeff Garzik /* Is this the 3rd channel CSB6 IDE ? */ 542669a5db4SJeff Garzik if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) 543669a5db4SJeff Garzik ports = 1; 544669a5db4SJeff Garzik } 545669a5db4SJeff Garzik /* setup HT1000E */ 546669a5db4SJeff Garzik else if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) 547669a5db4SJeff Garzik serverworks_fixup_ht1000(pdev); 548669a5db4SJeff Garzik 549669a5db4SJeff Garzik if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) 550669a5db4SJeff Garzik ata_pci_clear_simplex(pdev); 551669a5db4SJeff Garzik 552669a5db4SJeff Garzik port_info[0] = port_info[1] = devinfo; 553669a5db4SJeff Garzik return ata_pci_init_one(pdev, port_info, ports); 554669a5db4SJeff Garzik } 555669a5db4SJeff Garzik 556669a5db4SJeff Garzik static struct pci_device_id serverworks[] = { 557669a5db4SJeff Garzik { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0}, 558669a5db4SJeff Garzik { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE), 2}, 559669a5db4SJeff Garzik { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE), 2}, 560669a5db4SJeff Garzik { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2), 2}, 561669a5db4SJeff Garzik { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 2}, 562669a5db4SJeff Garzik { 0, }, 563669a5db4SJeff Garzik }; 564669a5db4SJeff Garzik 565669a5db4SJeff Garzik static struct pci_driver serverworks_pci_driver = { 566669a5db4SJeff Garzik .name = DRV_NAME, 567669a5db4SJeff Garzik .id_table = serverworks, 568669a5db4SJeff Garzik .probe = serverworks_init_one, 569669a5db4SJeff Garzik .remove = ata_pci_remove_one 570669a5db4SJeff Garzik }; 571669a5db4SJeff Garzik 572669a5db4SJeff Garzik static int __init serverworks_init(void) 573669a5db4SJeff Garzik { 574669a5db4SJeff Garzik return pci_register_driver(&serverworks_pci_driver); 575669a5db4SJeff Garzik } 576669a5db4SJeff Garzik 577669a5db4SJeff Garzik 578669a5db4SJeff Garzik static void __exit serverworks_exit(void) 579669a5db4SJeff Garzik { 580669a5db4SJeff Garzik pci_unregister_driver(&serverworks_pci_driver); 581669a5db4SJeff Garzik } 582669a5db4SJeff Garzik 583669a5db4SJeff Garzik 584669a5db4SJeff Garzik MODULE_AUTHOR("Alan Cox"); 585669a5db4SJeff Garzik MODULE_DESCRIPTION("low-level driver for Serverworks OSB4/CSB5/CSB6"); 586669a5db4SJeff Garzik MODULE_LICENSE("GPL"); 587669a5db4SJeff Garzik MODULE_DEVICE_TABLE(pci, serverworks); 588669a5db4SJeff Garzik MODULE_VERSION(DRV_VERSION); 589669a5db4SJeff Garzik 590669a5db4SJeff Garzik module_init(serverworks_init); 591669a5db4SJeff Garzik module_exit(serverworks_exit); 592