Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * pata_triflex.c - Compaq PATA for new ATA layer |
| 3 | * (C) 2005 Red Hat Inc |
Alan Cox | ab77163 | 2008-10-27 15:09:10 +0000 | [diff] [blame] | 4 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 5 | * |
| 6 | * based upon |
| 7 | * |
| 8 | * triflex.c |
| 9 | * |
| 10 | * IDE Chipset driver for the Compaq TriFlex IDE controller. |
| 11 | * |
| 12 | * Known to work with the Compaq Workstation 5x00 series. |
| 13 | * |
| 14 | * Copyright (C) 2002 Hewlett-Packard Development Group, L.P. |
| 15 | * Author: Torben Mathiasen <torben.mathiasen@hp.com> |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License version 2 as |
| 19 | * published by the Free Software Foundation. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | * |
| 30 | * Loosely based on the piix & svwks drivers. |
| 31 | * |
| 32 | * Documentation: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 33 | * Not publicly available. |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/pci.h> |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 39 | #include <linux/blkdev.h> |
| 40 | #include <linux/delay.h> |
| 41 | #include <scsi/scsi_host.h> |
| 42 | #include <linux/libata.h> |
| 43 | |
| 44 | #define DRV_NAME "pata_triflex" |
Jeff Garzik | a0fcdc0 | 2007-03-09 07:24:15 -0500 | [diff] [blame] | 45 | #define DRV_VERSION "0.2.8" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 46 | |
| 47 | /** |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 48 | * triflex_prereset - probe begin |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 49 | * @link: ATA link |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 50 | * @deadline: deadline jiffies for the operation |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 51 | * |
| 52 | * Set up cable type and use generic probe init |
| 53 | */ |
| 54 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 55 | static int triflex_prereset(struct ata_link *link, unsigned long deadline) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 56 | { |
| 57 | static const struct pci_bits triflex_enable_bits[] = { |
| 58 | { 0x80, 1, 0x01, 0x01 }, |
| 59 | { 0x80, 1, 0x02, 0x02 } |
| 60 | }; |
| 61 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 62 | struct ata_port *ap = link->ap; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 63 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 64 | |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 65 | if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no])) |
| 66 | return -ENOENT; |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 67 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 68 | return ata_sff_prereset(link, deadline); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | |
| 72 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 73 | /** |
| 74 | * triflex_load_timing - timing configuration |
| 75 | * @ap: ATA interface |
| 76 | * @adev: Device on the bus |
| 77 | * @speed: speed to configure |
| 78 | * |
| 79 | * The Triflex has one set of timings per device per channel. This |
| 80 | * means we must do some switching. As the PIO and DMA timings don't |
| 81 | * match we have to do some reloading unlike PIIX devices where tuning |
| 82 | * tricks can avoid it. |
| 83 | */ |
| 84 | |
| 85 | static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed) |
| 86 | { |
| 87 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 88 | u32 timing = 0; |
| 89 | u32 triflex_timing, old_triflex_timing; |
| 90 | int channel_offset = ap->port_no ? 0x74: 0x70; |
| 91 | unsigned int is_slave = (adev->devno != 0); |
| 92 | |
| 93 | |
| 94 | pci_read_config_dword(pdev, channel_offset, &old_triflex_timing); |
| 95 | triflex_timing = old_triflex_timing; |
| 96 | |
| 97 | switch(speed) |
| 98 | { |
| 99 | case XFER_MW_DMA_2: |
| 100 | timing = 0x0103;break; |
| 101 | case XFER_MW_DMA_1: |
| 102 | timing = 0x0203;break; |
| 103 | case XFER_MW_DMA_0: |
| 104 | timing = 0x0808;break; |
| 105 | case XFER_SW_DMA_2: |
| 106 | case XFER_SW_DMA_1: |
| 107 | case XFER_SW_DMA_0: |
| 108 | timing = 0x0F0F;break; |
| 109 | case XFER_PIO_4: |
| 110 | timing = 0x0202;break; |
| 111 | case XFER_PIO_3: |
| 112 | timing = 0x0204;break; |
| 113 | case XFER_PIO_2: |
| 114 | timing = 0x0404;break; |
| 115 | case XFER_PIO_1: |
| 116 | timing = 0x0508;break; |
| 117 | case XFER_PIO_0: |
| 118 | timing = 0x0808;break; |
| 119 | default: |
| 120 | BUG(); |
| 121 | } |
| 122 | triflex_timing &= ~ (0xFFFF << (16 * is_slave)); |
| 123 | triflex_timing |= (timing << (16 * is_slave)); |
| 124 | |
| 125 | if (triflex_timing != old_triflex_timing) |
| 126 | pci_write_config_dword(pdev, channel_offset, triflex_timing); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * triflex_set_piomode - set initial PIO mode data |
| 131 | * @ap: ATA interface |
| 132 | * @adev: ATA device |
| 133 | * |
| 134 | * Use the timing loader to set up the PIO mode. We have to do this |
| 135 | * because DMA start/stop will only be called once DMA occurs. If there |
| 136 | * has been no DMA then the PIO timings are still needed. |
| 137 | */ |
| 138 | static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev) |
| 139 | { |
| 140 | triflex_load_timing(ap, adev, adev->pio_mode); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * triflex_dma_start - DMA start callback |
| 145 | * @qc: Command in progress |
| 146 | * |
| 147 | * Usually drivers set the DMA timing at the point the set_dmamode call |
| 148 | * is made. Triflex however requires we load new timings on the |
| 149 | * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc). |
| 150 | * We load the DMA timings just before starting DMA and then restore |
| 151 | * the PIO timing when the DMA is finished. |
| 152 | */ |
| 153 | |
| 154 | static void triflex_bmdma_start(struct ata_queued_cmd *qc) |
| 155 | { |
| 156 | triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode); |
| 157 | ata_bmdma_start(qc); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * triflex_dma_stop - DMA stop callback |
| 162 | * @ap: ATA interface |
| 163 | * @adev: ATA device |
| 164 | * |
| 165 | * We loaded new timings in dma_start, as a result we need to restore |
| 166 | * the PIO timings in dma_stop so that the next command issue gets the |
| 167 | * right clock values. |
| 168 | */ |
| 169 | |
| 170 | static void triflex_bmdma_stop(struct ata_queued_cmd *qc) |
| 171 | { |
| 172 | ata_bmdma_stop(qc); |
| 173 | triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode); |
| 174 | } |
| 175 | |
| 176 | static struct scsi_host_template triflex_sht = { |
Tejun Heo | 68d1d07 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 177 | ATA_BMDMA_SHT(DRV_NAME), |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | static struct ata_port_operations triflex_port_ops = { |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 181 | .inherits = &ata_bmdma_port_ops, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 182 | .bmdma_start = triflex_bmdma_start, |
| 183 | .bmdma_stop = triflex_bmdma_stop, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 184 | .cable_detect = ata_cable_40wire, |
| 185 | .set_piomode = triflex_set_piomode, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 186 | .prereset = triflex_prereset, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
| 190 | { |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 191 | static const struct ata_port_info info = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 192 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 193 | .pio_mask = ATA_PIO4, |
| 194 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 195 | .port_ops = &triflex_port_ops |
| 196 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 197 | const struct ata_port_info *ppi[] = { &info, NULL }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 198 | |
Joe Perches | 06296a1 | 2011-04-15 15:52:00 -0700 | [diff] [blame] | 199 | ata_print_version_once(&dev->dev, DRV_VERSION); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 200 | |
Tejun Heo | 1c5afdf | 2010-05-19 22:10:22 +0200 | [diff] [blame] | 201 | return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static const struct pci_device_id triflex[] = { |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 205 | { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), }, |
| 206 | |
| 207 | { }, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 208 | }; |
| 209 | |
Bartlomiej Zolnierkiewicz | 58eb8cd | 2014-05-07 17:17:44 +0200 | [diff] [blame] | 210 | #ifdef CONFIG_PM_SLEEP |
Mikulas Patocka | bfeec8c | 2011-05-15 22:33:19 +0200 | [diff] [blame] | 211 | static int triflex_ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) |
| 212 | { |
Jingoo Han | 0a86e1c | 2013-06-03 14:05:36 +0900 | [diff] [blame] | 213 | struct ata_host *host = pci_get_drvdata(pdev); |
Mikulas Patocka | bfeec8c | 2011-05-15 22:33:19 +0200 | [diff] [blame] | 214 | int rc = 0; |
| 215 | |
| 216 | rc = ata_host_suspend(host, mesg); |
| 217 | if (rc) |
| 218 | return rc; |
| 219 | |
| 220 | /* |
| 221 | * We must not disable or powerdown the device. |
| 222 | * APM bios refuses to suspend if IDE is not accessible. |
| 223 | */ |
| 224 | pci_save_state(pdev); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | #endif |
| 230 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 231 | static struct pci_driver triflex_pci_driver = { |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 232 | .name = DRV_NAME, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 233 | .id_table = triflex, |
| 234 | .probe = triflex_init_one, |
Alan | 30ced0f | 2006-11-22 16:57:36 +0000 | [diff] [blame] | 235 | .remove = ata_pci_remove_one, |
Bartlomiej Zolnierkiewicz | 58eb8cd | 2014-05-07 17:17:44 +0200 | [diff] [blame] | 236 | #ifdef CONFIG_PM_SLEEP |
Mikulas Patocka | bfeec8c | 2011-05-15 22:33:19 +0200 | [diff] [blame] | 237 | .suspend = triflex_ata_pci_device_suspend, |
Alan | 30ced0f | 2006-11-22 16:57:36 +0000 | [diff] [blame] | 238 | .resume = ata_pci_device_resume, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 239 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 240 | }; |
| 241 | |
Axel Lin | 2fc75da | 2012-04-19 13:43:05 +0800 | [diff] [blame] | 242 | module_pci_driver(triflex_pci_driver); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 243 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 244 | MODULE_AUTHOR("Alan Cox"); |
| 245 | MODULE_DESCRIPTION("low-level driver for Compaq Triflex"); |
| 246 | MODULE_LICENSE("GPL"); |
| 247 | MODULE_DEVICE_TABLE(pci, triflex); |
| 248 | MODULE_VERSION(DRV_VERSION); |