1669a5db4SJeff Garzik /* 2669a5db4SJeff Garzik * pata_triflex.c - Compaq PATA for new ATA layer 3669a5db4SJeff Garzik * (C) 2005 Red Hat Inc 4ab771630SAlan Cox * Alan Cox <alan@lxorguk.ukuu.org.uk> 5669a5db4SJeff Garzik * 6669a5db4SJeff Garzik * based upon 7669a5db4SJeff Garzik * 8669a5db4SJeff Garzik * triflex.c 9669a5db4SJeff Garzik * 10669a5db4SJeff Garzik * IDE Chipset driver for the Compaq TriFlex IDE controller. 11669a5db4SJeff Garzik * 12669a5db4SJeff Garzik * Known to work with the Compaq Workstation 5x00 series. 13669a5db4SJeff Garzik * 14669a5db4SJeff Garzik * Copyright (C) 2002 Hewlett-Packard Development Group, L.P. 15669a5db4SJeff Garzik * Author: Torben Mathiasen <torben.mathiasen@hp.com> 16669a5db4SJeff Garzik * 17669a5db4SJeff Garzik * This program is free software; you can redistribute it and/or modify 18669a5db4SJeff Garzik * it under the terms of the GNU General Public License version 2 as 19669a5db4SJeff Garzik * published by the Free Software Foundation. 20669a5db4SJeff Garzik * 21669a5db4SJeff Garzik * This program is distributed in the hope that it will be useful, 22669a5db4SJeff Garzik * but WITHOUT ANY WARRANTY; without even the implied warranty of 23669a5db4SJeff Garzik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24669a5db4SJeff Garzik * GNU General Public License for more details. 25669a5db4SJeff Garzik * 26669a5db4SJeff Garzik * You should have received a copy of the GNU General Public License 27669a5db4SJeff Garzik * along with this program; if not, write to the Free Software 28669a5db4SJeff Garzik * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29669a5db4SJeff Garzik * 30669a5db4SJeff Garzik * Loosely based on the piix & svwks drivers. 31669a5db4SJeff Garzik * 32669a5db4SJeff Garzik * Documentation: 33669a5db4SJeff Garzik * Not publically available. 34669a5db4SJeff Garzik */ 35669a5db4SJeff Garzik 36669a5db4SJeff Garzik #include <linux/kernel.h> 37669a5db4SJeff Garzik #include <linux/module.h> 38669a5db4SJeff Garzik #include <linux/pci.h> 39669a5db4SJeff Garzik #include <linux/init.h> 40669a5db4SJeff Garzik #include <linux/blkdev.h> 41669a5db4SJeff Garzik #include <linux/delay.h> 42669a5db4SJeff Garzik #include <scsi/scsi_host.h> 43669a5db4SJeff Garzik #include <linux/libata.h> 44669a5db4SJeff Garzik 45669a5db4SJeff Garzik #define DRV_NAME "pata_triflex" 46a0fcdc02SJeff Garzik #define DRV_VERSION "0.2.8" 47669a5db4SJeff Garzik 48669a5db4SJeff Garzik /** 49c961922bSAlan Cox * triflex_prereset - probe begin 50cc0680a5STejun Heo * @link: ATA link 51d4b2bab4STejun Heo * @deadline: deadline jiffies for the operation 52669a5db4SJeff Garzik * 53669a5db4SJeff Garzik * Set up cable type and use generic probe init 54669a5db4SJeff Garzik */ 55669a5db4SJeff Garzik 56cc0680a5STejun Heo static int triflex_prereset(struct ata_link *link, unsigned long deadline) 57669a5db4SJeff Garzik { 58669a5db4SJeff Garzik static const struct pci_bits triflex_enable_bits[] = { 59669a5db4SJeff Garzik { 0x80, 1, 0x01, 0x01 }, 60669a5db4SJeff Garzik { 0x80, 1, 0x02, 0x02 } 61669a5db4SJeff Garzik }; 62669a5db4SJeff Garzik 63cc0680a5STejun Heo struct ata_port *ap = link->ap; 64669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 65669a5db4SJeff Garzik 66c961922bSAlan Cox if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no])) 67c961922bSAlan Cox return -ENOENT; 68d4b2bab4STejun Heo 699363c382STejun Heo return ata_sff_prereset(link, deadline); 70669a5db4SJeff Garzik } 71669a5db4SJeff Garzik 72669a5db4SJeff Garzik 73669a5db4SJeff Garzik 74669a5db4SJeff Garzik /** 75669a5db4SJeff Garzik * triflex_load_timing - timing configuration 76669a5db4SJeff Garzik * @ap: ATA interface 77669a5db4SJeff Garzik * @adev: Device on the bus 78669a5db4SJeff Garzik * @speed: speed to configure 79669a5db4SJeff Garzik * 80669a5db4SJeff Garzik * The Triflex has one set of timings per device per channel. This 81669a5db4SJeff Garzik * means we must do some switching. As the PIO and DMA timings don't 82669a5db4SJeff Garzik * match we have to do some reloading unlike PIIX devices where tuning 83669a5db4SJeff Garzik * tricks can avoid it. 84669a5db4SJeff Garzik */ 85669a5db4SJeff Garzik 86669a5db4SJeff Garzik static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed) 87669a5db4SJeff Garzik { 88669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 89669a5db4SJeff Garzik u32 timing = 0; 90669a5db4SJeff Garzik u32 triflex_timing, old_triflex_timing; 91669a5db4SJeff Garzik int channel_offset = ap->port_no ? 0x74: 0x70; 92669a5db4SJeff Garzik unsigned int is_slave = (adev->devno != 0); 93669a5db4SJeff Garzik 94669a5db4SJeff Garzik 95669a5db4SJeff Garzik pci_read_config_dword(pdev, channel_offset, &old_triflex_timing); 96669a5db4SJeff Garzik triflex_timing = old_triflex_timing; 97669a5db4SJeff Garzik 98669a5db4SJeff Garzik switch(speed) 99669a5db4SJeff Garzik { 100669a5db4SJeff Garzik case XFER_MW_DMA_2: 101669a5db4SJeff Garzik timing = 0x0103;break; 102669a5db4SJeff Garzik case XFER_MW_DMA_1: 103669a5db4SJeff Garzik timing = 0x0203;break; 104669a5db4SJeff Garzik case XFER_MW_DMA_0: 105669a5db4SJeff Garzik timing = 0x0808;break; 106669a5db4SJeff Garzik case XFER_SW_DMA_2: 107669a5db4SJeff Garzik case XFER_SW_DMA_1: 108669a5db4SJeff Garzik case XFER_SW_DMA_0: 109669a5db4SJeff Garzik timing = 0x0F0F;break; 110669a5db4SJeff Garzik case XFER_PIO_4: 111669a5db4SJeff Garzik timing = 0x0202;break; 112669a5db4SJeff Garzik case XFER_PIO_3: 113669a5db4SJeff Garzik timing = 0x0204;break; 114669a5db4SJeff Garzik case XFER_PIO_2: 115669a5db4SJeff Garzik timing = 0x0404;break; 116669a5db4SJeff Garzik case XFER_PIO_1: 117669a5db4SJeff Garzik timing = 0x0508;break; 118669a5db4SJeff Garzik case XFER_PIO_0: 119669a5db4SJeff Garzik timing = 0x0808;break; 120669a5db4SJeff Garzik default: 121669a5db4SJeff Garzik BUG(); 122669a5db4SJeff Garzik } 123669a5db4SJeff Garzik triflex_timing &= ~ (0xFFFF << (16 * is_slave)); 124669a5db4SJeff Garzik triflex_timing |= (timing << (16 * is_slave)); 125669a5db4SJeff Garzik 126669a5db4SJeff Garzik if (triflex_timing != old_triflex_timing) 127669a5db4SJeff Garzik pci_write_config_dword(pdev, channel_offset, triflex_timing); 128669a5db4SJeff Garzik } 129669a5db4SJeff Garzik 130669a5db4SJeff Garzik /** 131669a5db4SJeff Garzik * triflex_set_piomode - set initial PIO mode data 132669a5db4SJeff Garzik * @ap: ATA interface 133669a5db4SJeff Garzik * @adev: ATA device 134669a5db4SJeff Garzik * 135669a5db4SJeff Garzik * Use the timing loader to set up the PIO mode. We have to do this 136669a5db4SJeff Garzik * because DMA start/stop will only be called once DMA occurs. If there 137669a5db4SJeff Garzik * has been no DMA then the PIO timings are still needed. 138669a5db4SJeff Garzik */ 139669a5db4SJeff Garzik static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev) 140669a5db4SJeff Garzik { 141669a5db4SJeff Garzik triflex_load_timing(ap, adev, adev->pio_mode); 142669a5db4SJeff Garzik } 143669a5db4SJeff Garzik 144669a5db4SJeff Garzik /** 145669a5db4SJeff Garzik * triflex_dma_start - DMA start callback 146669a5db4SJeff Garzik * @qc: Command in progress 147669a5db4SJeff Garzik * 148669a5db4SJeff Garzik * Usually drivers set the DMA timing at the point the set_dmamode call 149669a5db4SJeff Garzik * is made. Triflex however requires we load new timings on the 150669a5db4SJeff Garzik * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc). 151669a5db4SJeff Garzik * We load the DMA timings just before starting DMA and then restore 152669a5db4SJeff Garzik * the PIO timing when the DMA is finished. 153669a5db4SJeff Garzik */ 154669a5db4SJeff Garzik 155669a5db4SJeff Garzik static void triflex_bmdma_start(struct ata_queued_cmd *qc) 156669a5db4SJeff Garzik { 157669a5db4SJeff Garzik triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode); 158669a5db4SJeff Garzik ata_bmdma_start(qc); 159669a5db4SJeff Garzik } 160669a5db4SJeff Garzik 161669a5db4SJeff Garzik /** 162669a5db4SJeff Garzik * triflex_dma_stop - DMA stop callback 163669a5db4SJeff Garzik * @ap: ATA interface 164669a5db4SJeff Garzik * @adev: ATA device 165669a5db4SJeff Garzik * 166669a5db4SJeff Garzik * We loaded new timings in dma_start, as a result we need to restore 167669a5db4SJeff Garzik * the PIO timings in dma_stop so that the next command issue gets the 168669a5db4SJeff Garzik * right clock values. 169669a5db4SJeff Garzik */ 170669a5db4SJeff Garzik 171669a5db4SJeff Garzik static void triflex_bmdma_stop(struct ata_queued_cmd *qc) 172669a5db4SJeff Garzik { 173669a5db4SJeff Garzik ata_bmdma_stop(qc); 174669a5db4SJeff Garzik triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode); 175669a5db4SJeff Garzik } 176669a5db4SJeff Garzik 177669a5db4SJeff Garzik static struct scsi_host_template triflex_sht = { 17868d1d07bSTejun Heo ATA_BMDMA_SHT(DRV_NAME), 179669a5db4SJeff Garzik }; 180669a5db4SJeff Garzik 181669a5db4SJeff Garzik static struct ata_port_operations triflex_port_ops = { 182029cfd6bSTejun Heo .inherits = &ata_bmdma_port_ops, 183669a5db4SJeff Garzik .bmdma_start = triflex_bmdma_start, 184669a5db4SJeff Garzik .bmdma_stop = triflex_bmdma_stop, 185029cfd6bSTejun Heo .cable_detect = ata_cable_40wire, 186029cfd6bSTejun Heo .set_piomode = triflex_set_piomode, 187a1efdabaSTejun Heo .prereset = triflex_prereset, 188669a5db4SJeff Garzik }; 189669a5db4SJeff Garzik 190669a5db4SJeff Garzik static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id) 191669a5db4SJeff Garzik { 1921626aeb8STejun Heo static const struct ata_port_info info = { 1931d2808fdSJeff Garzik .flags = ATA_FLAG_SLAVE_POSS, 19414bdef98SErik Inge Bolsø .pio_mask = ATA_PIO4, 19514bdef98SErik Inge Bolsø .mwdma_mask = ATA_MWDMA2, 196669a5db4SJeff Garzik .port_ops = &triflex_port_ops 197669a5db4SJeff Garzik }; 1981626aeb8STejun Heo const struct ata_port_info *ppi[] = { &info, NULL }; 199669a5db4SJeff Garzik static int printed_version; 200669a5db4SJeff Garzik 201669a5db4SJeff Garzik if (!printed_version++) 202669a5db4SJeff Garzik dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n"); 203669a5db4SJeff Garzik 204*1c5afdf7STejun Heo return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0); 205669a5db4SJeff Garzik } 206669a5db4SJeff Garzik 207669a5db4SJeff Garzik static const struct pci_device_id triflex[] = { 2082d2744fcSJeff Garzik { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), }, 2092d2744fcSJeff Garzik 2102d2744fcSJeff Garzik { }, 211669a5db4SJeff Garzik }; 212669a5db4SJeff Garzik 213669a5db4SJeff Garzik static struct pci_driver triflex_pci_driver = { 214669a5db4SJeff Garzik .name = DRV_NAME, 215669a5db4SJeff Garzik .id_table = triflex, 216669a5db4SJeff Garzik .probe = triflex_init_one, 21730ced0f0SAlan .remove = ata_pci_remove_one, 218438ac6d5STejun Heo #ifdef CONFIG_PM 21930ced0f0SAlan .suspend = ata_pci_device_suspend, 22030ced0f0SAlan .resume = ata_pci_device_resume, 221438ac6d5STejun Heo #endif 222669a5db4SJeff Garzik }; 223669a5db4SJeff Garzik 224669a5db4SJeff Garzik static int __init triflex_init(void) 225669a5db4SJeff Garzik { 226669a5db4SJeff Garzik return pci_register_driver(&triflex_pci_driver); 227669a5db4SJeff Garzik } 228669a5db4SJeff Garzik 229669a5db4SJeff Garzik static void __exit triflex_exit(void) 230669a5db4SJeff Garzik { 231669a5db4SJeff Garzik pci_unregister_driver(&triflex_pci_driver); 232669a5db4SJeff Garzik } 233669a5db4SJeff Garzik 234669a5db4SJeff Garzik MODULE_AUTHOR("Alan Cox"); 235669a5db4SJeff Garzik MODULE_DESCRIPTION("low-level driver for Compaq Triflex"); 236669a5db4SJeff Garzik MODULE_LICENSE("GPL"); 237669a5db4SJeff Garzik MODULE_DEVICE_TABLE(pci, triflex); 238669a5db4SJeff Garzik MODULE_VERSION(DRV_VERSION); 239669a5db4SJeff Garzik 240669a5db4SJeff Garzik module_init(triflex_init); 241669a5db4SJeff Garzik module_exit(triflex_exit); 242