blob: 8a033598e7e17519a8e18dfd0aaf6a6ebc465e08 [file] [log] [blame]
Thomas Gleixner45051532019-05-29 16:57:47 -07001// SPDX-License-Identifier: GPL-2.0-only
Jeff Garzik669a5db2006-08-29 18:12:40 -04002/*
3 * pata_triflex.c - Compaq PATA for new ATA layer
4 * (C) 2005 Red Hat Inc
Alan Coxab771632008-10-27 15:09:10 +00005 * Alan Cox <alan@lxorguk.ukuu.org.uk>
Jeff Garzik669a5db2006-08-29 18:12:40 -04006 *
7 * based upon
8 *
9 * triflex.c
10 *
11 * IDE Chipset driver for the Compaq TriFlex IDE controller.
12 *
13 * Known to work with the Compaq Workstation 5x00 series.
14 *
15 * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
16 * Author: Torben Mathiasen <torben.mathiasen@hp.com>
17 *
Jeff Garzik669a5db2006-08-29 18:12:40 -040018 * Loosely based on the piix & svwks drivers.
19 *
20 * Documentation:
Lucas De Marchi25985ed2011-03-30 22:57:33 -030021 * Not publicly available.
Jeff Garzik669a5db2006-08-29 18:12:40 -040022 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/pci.h>
Jeff Garzik669a5db2006-08-29 18:12:40 -040027#include <linux/blkdev.h>
28#include <linux/delay.h>
29#include <scsi/scsi_host.h>
30#include <linux/libata.h>
31
32#define DRV_NAME "pata_triflex"
Jeff Garzika0fcdc02007-03-09 07:24:15 -050033#define DRV_VERSION "0.2.8"
Jeff Garzik669a5db2006-08-29 18:12:40 -040034
35/**
Alan Coxc9619222006-09-26 17:53:38 +010036 * triflex_prereset - probe begin
Tejun Heocc0680a2007-08-06 18:36:23 +090037 * @link: ATA link
Tejun Heod4b2bab2007-02-02 16:50:52 +090038 * @deadline: deadline jiffies for the operation
Jeff Garzik669a5db2006-08-29 18:12:40 -040039 *
40 * Set up cable type and use generic probe init
41 */
42
Tejun Heocc0680a2007-08-06 18:36:23 +090043static int triflex_prereset(struct ata_link *link, unsigned long deadline)
Jeff Garzik669a5db2006-08-29 18:12:40 -040044{
45 static const struct pci_bits triflex_enable_bits[] = {
46 { 0x80, 1, 0x01, 0x01 },
47 { 0x80, 1, 0x02, 0x02 }
48 };
49
Tejun Heocc0680a2007-08-06 18:36:23 +090050 struct ata_port *ap = link->ap;
Jeff Garzik669a5db2006-08-29 18:12:40 -040051 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Jeff Garzik85cd7252006-08-31 00:03:49 -040052
Alan Coxc9619222006-09-26 17:53:38 +010053 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
54 return -ENOENT;
Tejun Heod4b2bab2007-02-02 16:50:52 +090055
Tejun Heo9363c382008-04-07 22:47:16 +090056 return ata_sff_prereset(link, deadline);
Jeff Garzik669a5db2006-08-29 18:12:40 -040057}
58
59
60
Jeff Garzik669a5db2006-08-29 18:12:40 -040061/**
62 * triflex_load_timing - timing configuration
63 * @ap: ATA interface
64 * @adev: Device on the bus
65 * @speed: speed to configure
66 *
67 * The Triflex has one set of timings per device per channel. This
68 * means we must do some switching. As the PIO and DMA timings don't
69 * match we have to do some reloading unlike PIIX devices where tuning
70 * tricks can avoid it.
71 */
72
73static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
74{
75 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
76 u32 timing = 0;
77 u32 triflex_timing, old_triflex_timing;
78 int channel_offset = ap->port_no ? 0x74: 0x70;
79 unsigned int is_slave = (adev->devno != 0);
80
81
82 pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
83 triflex_timing = old_triflex_timing;
84
85 switch(speed)
86 {
87 case XFER_MW_DMA_2:
88 timing = 0x0103;break;
89 case XFER_MW_DMA_1:
90 timing = 0x0203;break;
91 case XFER_MW_DMA_0:
92 timing = 0x0808;break;
93 case XFER_SW_DMA_2:
94 case XFER_SW_DMA_1:
95 case XFER_SW_DMA_0:
96 timing = 0x0F0F;break;
97 case XFER_PIO_4:
98 timing = 0x0202;break;
99 case XFER_PIO_3:
100 timing = 0x0204;break;
101 case XFER_PIO_2:
102 timing = 0x0404;break;
103 case XFER_PIO_1:
104 timing = 0x0508;break;
105 case XFER_PIO_0:
106 timing = 0x0808;break;
107 default:
108 BUG();
109 }
110 triflex_timing &= ~ (0xFFFF << (16 * is_slave));
111 triflex_timing |= (timing << (16 * is_slave));
112
113 if (triflex_timing != old_triflex_timing)
114 pci_write_config_dword(pdev, channel_offset, triflex_timing);
115}
116
117/**
118 * triflex_set_piomode - set initial PIO mode data
119 * @ap: ATA interface
120 * @adev: ATA device
121 *
122 * Use the timing loader to set up the PIO mode. We have to do this
123 * because DMA start/stop will only be called once DMA occurs. If there
124 * has been no DMA then the PIO timings are still needed.
125 */
126static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
127{
128 triflex_load_timing(ap, adev, adev->pio_mode);
129}
130
131/**
Lee Jones2ee628f2021-03-18 08:51:39 +0000132 * triflex_bmdma_start - DMA start callback
Jeff Garzik669a5db2006-08-29 18:12:40 -0400133 * @qc: Command in progress
134 *
135 * Usually drivers set the DMA timing at the point the set_dmamode call
136 * is made. Triflex however requires we load new timings on the
137 * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
138 * We load the DMA timings just before starting DMA and then restore
139 * the PIO timing when the DMA is finished.
140 */
141
142static void triflex_bmdma_start(struct ata_queued_cmd *qc)
143{
144 triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
145 ata_bmdma_start(qc);
146}
147
148/**
Lee Jones2ee628f2021-03-18 08:51:39 +0000149 * triflex_bmdma_stop - DMA stop callback
150 * @qc: ATA command
Jeff Garzik669a5db2006-08-29 18:12:40 -0400151 *
152 * We loaded new timings in dma_start, as a result we need to restore
153 * the PIO timings in dma_stop so that the next command issue gets the
154 * right clock values.
155 */
156
157static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
158{
159 ata_bmdma_stop(qc);
160 triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
161}
162
163static struct scsi_host_template triflex_sht = {
Tejun Heo68d1d072008-03-25 12:22:49 +0900164 ATA_BMDMA_SHT(DRV_NAME),
Jeff Garzik669a5db2006-08-29 18:12:40 -0400165};
166
167static struct ata_port_operations triflex_port_ops = {
Tejun Heo029cfd62008-03-25 12:22:49 +0900168 .inherits = &ata_bmdma_port_ops,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400169 .bmdma_start = triflex_bmdma_start,
170 .bmdma_stop = triflex_bmdma_stop,
Tejun Heo029cfd62008-03-25 12:22:49 +0900171 .cable_detect = ata_cable_40wire,
172 .set_piomode = triflex_set_piomode,
Tejun Heoa1efdab2008-03-25 12:22:50 +0900173 .prereset = triflex_prereset,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400174};
175
176static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
177{
Tejun Heo1626aeb2007-05-04 12:43:58 +0200178 static const struct ata_port_info info = {
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400179 .flags = ATA_FLAG_SLAVE_POSS,
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +0100180 .pio_mask = ATA_PIO4,
181 .mwdma_mask = ATA_MWDMA2,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400182 .port_ops = &triflex_port_ops
183 };
Tejun Heo1626aeb2007-05-04 12:43:58 +0200184 const struct ata_port_info *ppi[] = { &info, NULL };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400185
Joe Perches06296a12011-04-15 15:52:00 -0700186 ata_print_version_once(&dev->dev, DRV_VERSION);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400187
Tejun Heo1c5afdf2010-05-19 22:10:22 +0200188 return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400189}
190
191static const struct pci_device_id triflex[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400192 { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
193
194 { },
Jeff Garzik669a5db2006-08-29 18:12:40 -0400195};
196
Bartlomiej Zolnierkiewicz58eb8cd2014-05-07 17:17:44 +0200197#ifdef CONFIG_PM_SLEEP
Mikulas Patockabfeec8c2011-05-15 22:33:19 +0200198static int triflex_ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
199{
Jingoo Han0a86e1c2013-06-03 14:05:36 +0900200 struct ata_host *host = pci_get_drvdata(pdev);
Mikulas Patockabfeec8c2011-05-15 22:33:19 +0200201 int rc = 0;
202
203 rc = ata_host_suspend(host, mesg);
204 if (rc)
205 return rc;
206
207 /*
208 * We must not disable or powerdown the device.
209 * APM bios refuses to suspend if IDE is not accessible.
210 */
211 pci_save_state(pdev);
212
213 return 0;
214}
215
216#endif
217
Jeff Garzik669a5db2006-08-29 18:12:40 -0400218static struct pci_driver triflex_pci_driver = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400219 .name = DRV_NAME,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400220 .id_table = triflex,
221 .probe = triflex_init_one,
Alan30ced0f2006-11-22 16:57:36 +0000222 .remove = ata_pci_remove_one,
Bartlomiej Zolnierkiewicz58eb8cd2014-05-07 17:17:44 +0200223#ifdef CONFIG_PM_SLEEP
Mikulas Patockabfeec8c2011-05-15 22:33:19 +0200224 .suspend = triflex_ata_pci_device_suspend,
Alan30ced0f2006-11-22 16:57:36 +0000225 .resume = ata_pci_device_resume,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900226#endif
Jeff Garzik669a5db2006-08-29 18:12:40 -0400227};
228
Axel Lin2fc75da2012-04-19 13:43:05 +0800229module_pci_driver(triflex_pci_driver);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400230
Jeff Garzik669a5db2006-08-29 18:12:40 -0400231MODULE_AUTHOR("Alan Cox");
232MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
233MODULE_LICENSE("GPL");
234MODULE_DEVICE_TABLE(pci, triflex);
235MODULE_VERSION(DRV_VERSION);