blob: df64f24430018674f527bfe1bb26d49a73b3ea05 [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001/*
2 * pata_oldpiix.c - Intel PATA/SATA controllers
3 *
4 * (C) 2005 Red Hat <alan@redhat.com>
5 *
6 * Some parts based on ata_piix.c by Jeff Garzik and others.
7 *
8 * Early PIIX differs significantly from the later PIIX as it lacks
9 * SITRE and the slave timing registers. This means that you have to
10 * set timing per channel, or be clever. Libata tells us whenever it
11 * does drive selection and we use this to reload the timings.
12 *
13 * Because of these behaviour differences PIIX gets its own driver module.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/pci.h>
19#include <linux/init.h>
20#include <linux/blkdev.h>
21#include <linux/delay.h>
22#include <linux/device.h>
23#include <scsi/scsi_host.h>
24#include <linux/libata.h>
25#include <linux/ata.h>
26
27#define DRV_NAME "pata_oldpiix"
Jeff Garzika0fcdc02007-03-09 07:24:15 -050028#define DRV_VERSION "0.5.5"
Jeff Garzik669a5db2006-08-29 18:12:40 -040029
30/**
31 * oldpiix_pre_reset - probe begin
Tejun Heocc0680a2007-08-06 18:36:23 +090032 * @link: ATA link
Tejun Heod4b2bab2007-02-02 16:50:52 +090033 * @deadline: deadline jiffies for the operation
Jeff Garzik669a5db2006-08-29 18:12:40 -040034 *
35 * Set up cable type and use generic probe init
36 */
37
Tejun Heocc0680a2007-08-06 18:36:23 +090038static int oldpiix_pre_reset(struct ata_link *link, unsigned long deadline)
Jeff Garzik669a5db2006-08-29 18:12:40 -040039{
Tejun Heocc0680a2007-08-06 18:36:23 +090040 struct ata_port *ap = link->ap;
Jeff Garzik669a5db2006-08-29 18:12:40 -040041 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
42 static const struct pci_bits oldpiix_enable_bits[] = {
43 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
44 { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
45 };
46
Alan Coxc9619222006-09-26 17:53:38 +010047 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
48 return -ENOENT;
Tejun Heod4b2bab2007-02-02 16:50:52 +090049
Tejun Heo9363c382008-04-07 22:47:16 +090050 return ata_sff_prereset(link, deadline);
Jeff Garzik669a5db2006-08-29 18:12:40 -040051}
52
53/**
Jeff Garzik669a5db2006-08-29 18:12:40 -040054 * oldpiix_set_piomode - Initialize host controller PATA PIO timings
55 * @ap: Port whose timings we are configuring
Jeff Garzika0fcdc02007-03-09 07:24:15 -050056 * @adev: Device whose timings we are configuring
Jeff Garzik669a5db2006-08-29 18:12:40 -040057 *
58 * Set PIO mode for device, in host controller PCI config space.
59 *
60 * LOCKING:
61 * None (inherited from caller).
62 */
63
64static void oldpiix_set_piomode (struct ata_port *ap, struct ata_device *adev)
65{
66 unsigned int pio = adev->pio_mode - XFER_PIO_0;
67 struct pci_dev *dev = to_pci_dev(ap->host->dev);
68 unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
69 u16 idetm_data;
70 int control = 0;
71
72 /*
73 * See Intel Document 298600-004 for the timing programing rules
74 * for PIIX/ICH. Note that the early PIIX does not have the slave
75 * timing port at 0x44.
76 */
77
78 static const /* ISP RTC */
79 u8 timings[][2] = { { 0, 0 },
80 { 0, 0 },
81 { 1, 0 },
82 { 2, 1 },
83 { 2, 3 }, };
84
Sergei Shtylyov409ba472007-02-05 19:45:38 +030085 if (pio > 1)
86 control |= 1; /* TIME */
Jeff Garzik669a5db2006-08-29 18:12:40 -040087 if (ata_pio_need_iordy(adev))
Sergei Shtylyov409ba472007-02-05 19:45:38 +030088 control |= 2; /* IE */
Jeff Garzik669a5db2006-08-29 18:12:40 -040089
Sergei Shtylyov409ba472007-02-05 19:45:38 +030090 /* Intel specifies that the prefetch/posting is for disk only */
Jeff Garzik669a5db2006-08-29 18:12:40 -040091 if (adev->class == ATA_DEV_ATA)
Sergei Shtylyov409ba472007-02-05 19:45:38 +030092 control |= 4; /* PPE */
Jeff Garzik669a5db2006-08-29 18:12:40 -040093
94 pci_read_config_word(dev, idetm_port, &idetm_data);
95
Sergei Shtylyov409ba472007-02-05 19:45:38 +030096 /*
97 * Set PPE, IE and TIME as appropriate.
98 * Clear the other drive's timing bits.
99 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400100 if (adev->devno == 0) {
101 idetm_data &= 0xCCE0;
102 idetm_data |= control;
103 } else {
104 idetm_data &= 0xCC0E;
105 idetm_data |= (control << 4);
106 }
107 idetm_data |= (timings[pio][0] << 12) |
108 (timings[pio][1] << 8);
109 pci_write_config_word(dev, idetm_port, idetm_data);
110
111 /* Track which port is configured */
112 ap->private_data = adev;
113}
114
115/**
116 * oldpiix_set_dmamode - Initialize host controller PATA DMA timings
117 * @ap: Port whose timings we are configuring
118 * @adev: Device to program
119 * @isich: True if the device is an ICH and has IOCFG registers
120 *
121 * Set MWDMA mode for device, in host controller PCI config space.
122 *
123 * LOCKING:
124 * None (inherited from caller).
125 */
126
127static void oldpiix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
128{
129 struct pci_dev *dev = to_pci_dev(ap->host->dev);
130 u8 idetm_port = ap->port_no ? 0x42 : 0x40;
131 u16 idetm_data;
132
133 static const /* ISP RTC */
134 u8 timings[][2] = { { 0, 0 },
135 { 0, 0 },
136 { 1, 0 },
137 { 2, 1 },
138 { 2, 3 }, };
139
140 /*
141 * MWDMA is driven by the PIO timings. We must also enable
142 * IORDY unconditionally along with TIME1. PPE has already
143 * been set when the PIO timing was set.
144 */
145
146 unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
147 unsigned int control;
148 const unsigned int needed_pio[3] = {
149 XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
150 };
151 int pio = needed_pio[mwdma] - XFER_PIO_0;
152
153 pci_read_config_word(dev, idetm_port, &idetm_data);
154
155 control = 3; /* IORDY|TIME0 */
156 /* Intel specifies that the PPE functionality is for disk only */
157 if (adev->class == ATA_DEV_ATA)
158 control |= 4; /* PPE enable */
159
160 /* If the drive MWDMA is faster than it can do PIO then
161 we must force PIO into PIO0 */
162
163 if (adev->pio_mode < needed_pio[mwdma])
164 /* Enable DMA timing only */
165 control |= 8; /* PIO cycles in PIO0 */
166
167 /* Mask out the relevant control and timing bits we will load. Also
168 clear the other drive TIME register as a precaution */
169 if (adev->devno == 0) {
170 idetm_data &= 0xCCE0;
171 idetm_data |= control;
172 } else {
173 idetm_data &= 0xCC0E;
174 idetm_data |= (control << 4);
175 }
176 idetm_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
177 pci_write_config_word(dev, idetm_port, idetm_data);
178
179 /* Track which port is configured */
180 ap->private_data = adev;
181}
182
183/**
Tejun Heo9363c382008-04-07 22:47:16 +0900184 * oldpiix_qc_issue - command issue
Jeff Garzik669a5db2006-08-29 18:12:40 -0400185 * @qc: command pending
186 *
187 * Called when the libata layer is about to issue a command. We wrap
188 * this interface so that we can load the correct ATA timings if
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200189 * necessary. Our logic also clears TIME0/TIME1 for the other device so
Jeff Garzik669a5db2006-08-29 18:12:40 -0400190 * that, even if we get this wrong, cycles to the other device will
191 * be made PIO0.
192 */
193
Tejun Heo9363c382008-04-07 22:47:16 +0900194static unsigned int oldpiix_qc_issue(struct ata_queued_cmd *qc)
Jeff Garzik669a5db2006-08-29 18:12:40 -0400195{
196 struct ata_port *ap = qc->ap;
197 struct ata_device *adev = qc->dev;
198
199 if (adev != ap->private_data) {
Alanb7939b12007-02-20 17:47:37 +0000200 oldpiix_set_piomode(ap, adev);
Alan Coxb15b3eb2008-08-01 09:18:34 +0100201 if (ata_dma_enabled(adev))
Jeff Garzik669a5db2006-08-29 18:12:40 -0400202 oldpiix_set_dmamode(ap, adev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400203 }
Tejun Heo9363c382008-04-07 22:47:16 +0900204 return ata_sff_qc_issue(qc);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400205}
206
207
208static struct scsi_host_template oldpiix_sht = {
Tejun Heo68d1d072008-03-25 12:22:49 +0900209 ATA_BMDMA_SHT(DRV_NAME),
Jeff Garzik669a5db2006-08-29 18:12:40 -0400210};
211
Tejun Heo029cfd62008-03-25 12:22:49 +0900212static struct ata_port_operations oldpiix_pata_ops = {
213 .inherits = &ata_bmdma_port_ops,
Tejun Heo9363c382008-04-07 22:47:16 +0900214 .qc_issue = oldpiix_qc_issue,
Tejun Heo029cfd62008-03-25 12:22:49 +0900215 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400216 .set_piomode = oldpiix_set_piomode,
217 .set_dmamode = oldpiix_set_dmamode,
Tejun Heoa1efdab2008-03-25 12:22:50 +0900218 .prereset = oldpiix_pre_reset,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400219};
220
221
222/**
223 * oldpiix_init_one - Register PIIX ATA PCI device with kernel services
224 * @pdev: PCI device to register
225 * @ent: Entry in oldpiix_pci_tbl matching with @pdev
226 *
227 * Called from kernel PCI layer. We probe for combined mode (sigh),
228 * and then hand over control to libata, for it to do the rest.
229 *
230 * LOCKING:
231 * Inherited from PCI layer (may sleep).
232 *
233 * RETURNS:
234 * Zero on success, or -ERRNO value.
235 */
236
237static int oldpiix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
238{
239 static int printed_version;
Tejun Heo1626aeb2007-05-04 12:43:58 +0200240 static const struct ata_port_info info = {
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400241 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400242 .pio_mask = 0x1f, /* pio0-4 */
243 .mwdma_mask = 0x07, /* mwdma1-2 */
244 .port_ops = &oldpiix_pata_ops,
245 };
Tejun Heo1626aeb2007-05-04 12:43:58 +0200246 const struct ata_port_info *ppi[] = { &info, NULL };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400247
248 if (!printed_version++)
249 dev_printk(KERN_DEBUG, &pdev->dev,
250 "version " DRV_VERSION "\n");
251
Tejun Heo9363c382008-04-07 22:47:16 +0900252 return ata_pci_sff_init_one(pdev, ppi, &oldpiix_sht, NULL);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400253}
254
255static const struct pci_device_id oldpiix_pci_tbl[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400256 { PCI_VDEVICE(INTEL, 0x1230), },
257
Jeff Garzik669a5db2006-08-29 18:12:40 -0400258 { } /* terminate list */
259};
260
261static struct pci_driver oldpiix_pci_driver = {
262 .name = DRV_NAME,
263 .id_table = oldpiix_pci_tbl,
264 .probe = oldpiix_init_one,
265 .remove = ata_pci_remove_one,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900266#ifdef CONFIG_PM
Alan30ced0f2006-11-22 16:57:36 +0000267 .suspend = ata_pci_device_suspend,
268 .resume = ata_pci_device_resume,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900269#endif
Jeff Garzik669a5db2006-08-29 18:12:40 -0400270};
271
272static int __init oldpiix_init(void)
273{
274 return pci_register_driver(&oldpiix_pci_driver);
275}
276
277static void __exit oldpiix_exit(void)
278{
279 pci_unregister_driver(&oldpiix_pci_driver);
280}
281
Jeff Garzik669a5db2006-08-29 18:12:40 -0400282module_init(oldpiix_init);
283module_exit(oldpiix_exit);
284
285MODULE_AUTHOR("Alan Cox");
286MODULE_DESCRIPTION("SCSI low-level driver for early PIIX series controllers");
287MODULE_LICENSE("GPL");
288MODULE_DEVICE_TABLE(pci, oldpiix_pci_tbl);
289MODULE_VERSION(DRV_VERSION);
290