blob: d0cebe16a8ee2baf9a3178f01fa5d67d4a96afc4 [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001/*
2 * pata_amd.c - AMD PATA for new ATA layer
3 * (C) 2005-2006 Red Hat Inc
4 * Alan Cox <alan@redhat.com>
5 *
6 * Based on pata-sil680. Errata information is taken from data sheets
7 * and the amd74xx.c driver by Vojtech Pavlik. Nvidia SATA devices are
8 * claimed by sata-nv.c.
9 *
10 * TODO:
11 * Variable system clock when/if it makes sense
12 * Power management on ports
13 *
14 *
15 * Documentation publically available.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/init.h>
22#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <scsi/scsi_host.h>
25#include <linux/libata.h>
26
27#define DRV_NAME "pata_amd"
Jeff Garzik2a3103c2007-08-31 04:54:06 -040028#define DRV_VERSION "0.3.9"
Jeff Garzik669a5db2006-08-29 18:12:40 -040029
30/**
31 * timing_setup - shared timing computation and load
32 * @ap: ATA port being set up
33 * @adev: drive being configured
34 * @offset: port offset
35 * @speed: target speed
36 * @clock: clock multiplier (number of times 33MHz for this part)
37 *
38 * Perform the actual timing set up for Nvidia or AMD PATA devices.
39 * The actual devices vary so they all call into this helper function
40 * providing the clock multipler and offset (because AMD and Nvidia put
41 * the ports at different locations).
42 */
43
44static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offset, int speed, int clock)
45{
46 static const unsigned char amd_cyc2udma[] = {
47 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7
48 };
49
50 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
51 struct ata_device *peer = ata_dev_pair(adev);
52 int dn = ap->port_no * 2 + adev->devno;
53 struct ata_timing at, apeer;
54 int T, UT;
55 const int amd_clock = 33333; /* KHz. */
56 u8 t;
57
58 T = 1000000000 / amd_clock;
59 UT = T / min_t(int, max_t(int, clock, 1), 2);
60
61 if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {
62 dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed);
63 return;
64 }
65
66 if (peer) {
67 /* This may be over conservative */
68 if (peer->dma_mode) {
69 ata_timing_compute(peer, peer->dma_mode, &apeer, T, UT);
70 ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT);
71 }
72 ata_timing_compute(peer, peer->pio_mode, &apeer, T, UT);
73 ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT);
74 }
75
76 if (speed == XFER_UDMA_5 && amd_clock <= 33333) at.udma = 1;
77 if (speed == XFER_UDMA_6 && amd_clock <= 33333) at.udma = 15;
78
79 /*
80 * Now do the setup work
81 */
82
83 /* Configure the address set up timing */
84 pci_read_config_byte(pdev, offset + 0x0C, &t);
85 t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(at.setup, 1, 4) - 1) << ((3 - dn) << 1));
86 pci_write_config_byte(pdev, offset + 0x0C , t);
87
88 /* Configure the 8bit I/O timing */
89 pci_write_config_byte(pdev, offset + 0x0E + (1 - (dn >> 1)),
90 ((FIT(at.act8b, 1, 16) - 1) << 4) | (FIT(at.rec8b, 1, 16) - 1));
91
92 /* Drive timing */
93 pci_write_config_byte(pdev, offset + 0x08 + (3 - dn),
94 ((FIT(at.active, 1, 16) - 1) << 4) | (FIT(at.recover, 1, 16) - 1));
95
96 switch (clock) {
97 case 1:
98 t = at.udma ? (0xc0 | (FIT(at.udma, 2, 5) - 2)) : 0x03;
99 break;
100
101 case 2:
102 t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 2, 10)]) : 0x03;
103 break;
104
105 case 3:
106 t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 10)]) : 0x03;
107 break;
108
109 case 4:
110 t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 15)]) : 0x03;
111 break;
112
113 default:
114 return;
115 }
116
117 /* UDMA timing */
118 pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
119}
120
121/**
Tejun Heocc0680a2007-08-06 18:36:23 +0900122 * amd_pre_reset - perform reset handling
123 * @link: ATA link
Tejun Heod4b2bab2007-02-02 16:50:52 +0900124 * @deadline: deadline jiffies for the operation
Jeff Garzik669a5db2006-08-29 18:12:40 -0400125 *
Alan Coxeb4a2c72007-04-11 00:04:20 +0100126 * Reset sequence checking enable bits to see which ports are
127 * active.
Jeff Garzik669a5db2006-08-29 18:12:40 -0400128 */
129
Tejun Heocc0680a2007-08-06 18:36:23 +0900130static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
Jeff Garzik669a5db2006-08-29 18:12:40 -0400131{
Jeff Garzik669a5db2006-08-29 18:12:40 -0400132 static const struct pci_bits amd_enable_bits[] = {
133 { 0x40, 1, 0x02, 0x02 },
134 { 0x40, 1, 0x01, 0x01 }
135 };
136
Tejun Heocc0680a2007-08-06 18:36:23 +0900137 struct ata_port *ap = link->ap;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400138 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Jeff Garzik85cd7252006-08-31 00:03:49 -0400139
Alan Coxc9619222006-09-26 17:53:38 +0100140 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
141 return -ENOENT;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400142
Tejun Heocc0680a2007-08-06 18:36:23 +0900143 return ata_std_prereset(link, deadline);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400144}
145
146static void amd_error_handler(struct ata_port *ap)
147{
148 return ata_bmdma_drive_eh(ap, amd_pre_reset,
149 ata_std_softreset, NULL,
150 ata_std_postreset);
151}
152
Alan Coxeb4a2c72007-04-11 00:04:20 +0100153static int amd_cable_detect(struct ata_port *ap)
Jeff Garzik669a5db2006-08-29 18:12:40 -0400154{
Alan Coxeb4a2c72007-04-11 00:04:20 +0100155 static const u32 bitmask[2] = {0x03, 0x0C};
Jeff Garzik669a5db2006-08-29 18:12:40 -0400156 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Alan Coxeb4a2c72007-04-11 00:04:20 +0100157 u8 ata66;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400158
Alan Coxeb4a2c72007-04-11 00:04:20 +0100159 pci_read_config_byte(pdev, 0x42, &ata66);
160 if (ata66 & bitmask[ap->port_no])
161 return ATA_CBL_PATA80;
162 return ATA_CBL_PATA40;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400163}
164
165/**
166 * amd33_set_piomode - set initial PIO mode data
167 * @ap: ATA interface
168 * @adev: ATA device
169 *
170 * Program the AMD registers for PIO mode.
171 */
172
173static void amd33_set_piomode(struct ata_port *ap, struct ata_device *adev)
174{
175 timing_setup(ap, adev, 0x40, adev->pio_mode, 1);
176}
177
178static void amd66_set_piomode(struct ata_port *ap, struct ata_device *adev)
179{
180 timing_setup(ap, adev, 0x40, adev->pio_mode, 2);
181}
182
183static void amd100_set_piomode(struct ata_port *ap, struct ata_device *adev)
184{
185 timing_setup(ap, adev, 0x40, adev->pio_mode, 3);
186}
187
188static void amd133_set_piomode(struct ata_port *ap, struct ata_device *adev)
189{
190 timing_setup(ap, adev, 0x40, adev->pio_mode, 4);
191}
192
193/**
194 * amd33_set_dmamode - set initial DMA mode data
195 * @ap: ATA interface
196 * @adev: ATA device
197 *
198 * Program the MWDMA/UDMA modes for the AMD and Nvidia
199 * chipset.
200 */
201
202static void amd33_set_dmamode(struct ata_port *ap, struct ata_device *adev)
203{
204 timing_setup(ap, adev, 0x40, adev->dma_mode, 1);
205}
206
207static void amd66_set_dmamode(struct ata_port *ap, struct ata_device *adev)
208{
209 timing_setup(ap, adev, 0x40, adev->dma_mode, 2);
210}
211
212static void amd100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
213{
214 timing_setup(ap, adev, 0x40, adev->dma_mode, 3);
215}
216
217static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
218{
219 timing_setup(ap, adev, 0x40, adev->dma_mode, 4);
220}
221
222
223/**
224 * nv_probe_init - cable detection
Tejun Heocc0680a2007-08-06 18:36:23 +0900225 * @lin: ATA link
Jeff Garzik669a5db2006-08-29 18:12:40 -0400226 *
227 * Perform cable detection. The BIOS stores this in PCI config
228 * space for us.
229 */
230
Tejun Heocc0680a2007-08-06 18:36:23 +0900231static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
Tejun Heod4b2bab2007-02-02 16:50:52 +0900232{
Alan Cox76ff3c62006-09-12 17:14:03 +0100233 static const struct pci_bits nv_enable_bits[] = {
234 { 0x50, 1, 0x02, 0x02 },
235 { 0x50, 1, 0x01, 0x01 }
236 };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400237
Tejun Heocc0680a2007-08-06 18:36:23 +0900238 struct ata_port *ap = link->ap;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400239 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400240
Alan Coxc9619222006-09-26 17:53:38 +0100241 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
242 return -ENOENT;
Alan Cox76ff3c62006-09-12 17:14:03 +0100243
Tejun Heocc0680a2007-08-06 18:36:23 +0900244 return ata_std_prereset(link, deadline);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400245}
246
247static void nv_error_handler(struct ata_port *ap)
248{
249 ata_bmdma_drive_eh(ap, nv_pre_reset,
250 ata_std_softreset, NULL,
251 ata_std_postreset);
252}
Alan Coxeb4a2c72007-04-11 00:04:20 +0100253
254static int nv_cable_detect(struct ata_port *ap)
255{
256 static const u8 bitmask[2] = {0x03, 0x0C};
257 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
258 u8 ata66;
259 u16 udma;
260 int cbl;
261
262 pci_read_config_byte(pdev, 0x52, &ata66);
263 if (ata66 & bitmask[ap->port_no])
264 cbl = ATA_CBL_PATA80;
265 else
266 cbl = ATA_CBL_PATA40;
267
268 /* We now have to double check because the Nvidia boxes BIOS
269 doesn't always set the cable bits but does set mode bits */
270 pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
271 if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
272 cbl = ATA_CBL_PATA80;
273 return cbl;
274}
275
Jeff Garzik669a5db2006-08-29 18:12:40 -0400276/**
277 * nv100_set_piomode - set initial PIO mode data
278 * @ap: ATA interface
279 * @adev: ATA device
280 *
281 * Program the AMD registers for PIO mode.
282 */
283
284static void nv100_set_piomode(struct ata_port *ap, struct ata_device *adev)
285{
286 timing_setup(ap, adev, 0x50, adev->pio_mode, 3);
287}
288
289static void nv133_set_piomode(struct ata_port *ap, struct ata_device *adev)
290{
291 timing_setup(ap, adev, 0x50, adev->pio_mode, 4);
292}
293
294/**
295 * nv100_set_dmamode - set initial DMA mode data
296 * @ap: ATA interface
297 * @adev: ATA device
298 *
299 * Program the MWDMA/UDMA modes for the AMD and Nvidia
300 * chipset.
301 */
302
303static void nv100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
304{
305 timing_setup(ap, adev, 0x50, adev->dma_mode, 3);
306}
307
308static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
309{
310 timing_setup(ap, adev, 0x50, adev->dma_mode, 4);
311}
312
313static struct scsi_host_template amd_sht = {
314 .module = THIS_MODULE,
315 .name = DRV_NAME,
316 .ioctl = ata_scsi_ioctl,
317 .queuecommand = ata_scsi_queuecmd,
318 .can_queue = ATA_DEF_QUEUE,
319 .this_id = ATA_SHT_THIS_ID,
320 .sg_tablesize = LIBATA_MAX_PRD,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400321 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
322 .emulated = ATA_SHT_EMULATED,
323 .use_clustering = ATA_SHT_USE_CLUSTERING,
324 .proc_name = DRV_NAME,
325 .dma_boundary = ATA_DMA_BOUNDARY,
326 .slave_configure = ata_scsi_slave_config,
Tejun Heoafdfe892006-11-29 11:26:47 +0900327 .slave_destroy = ata_scsi_slave_destroy,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400328 .bios_param = ata_std_bios_param,
329};
330
331static struct ata_port_operations amd33_port_ops = {
332 .port_disable = ata_port_disable,
333 .set_piomode = amd33_set_piomode,
334 .set_dmamode = amd33_set_dmamode,
335 .mode_filter = ata_pci_default_filter,
336 .tf_load = ata_tf_load,
337 .tf_read = ata_tf_read,
338 .check_status = ata_check_status,
339 .exec_command = ata_exec_command,
340 .dev_select = ata_std_dev_select,
341
342 .freeze = ata_bmdma_freeze,
343 .thaw = ata_bmdma_thaw,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100344 .error_handler = amd_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400345 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100346 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400347
348 .bmdma_setup = ata_bmdma_setup,
349 .bmdma_start = ata_bmdma_start,
350 .bmdma_stop = ata_bmdma_stop,
351 .bmdma_status = ata_bmdma_status,
352
353 .qc_prep = ata_qc_prep,
354 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400355
Tejun Heo0d5ff562007-02-01 15:06:36 +0900356 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400357
358 .irq_handler = ata_interrupt,
359 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900360 .irq_on = ata_irq_on,
361 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400362
363 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400364};
365
366static struct ata_port_operations amd66_port_ops = {
367 .port_disable = ata_port_disable,
368 .set_piomode = amd66_set_piomode,
369 .set_dmamode = amd66_set_dmamode,
370 .mode_filter = ata_pci_default_filter,
371 .tf_load = ata_tf_load,
372 .tf_read = ata_tf_read,
373 .check_status = ata_check_status,
374 .exec_command = ata_exec_command,
375 .dev_select = ata_std_dev_select,
376
377 .freeze = ata_bmdma_freeze,
378 .thaw = ata_bmdma_thaw,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100379 .error_handler = amd_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400380 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100381 .cable_detect = ata_cable_unknown,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400382
383 .bmdma_setup = ata_bmdma_setup,
384 .bmdma_start = ata_bmdma_start,
385 .bmdma_stop = ata_bmdma_stop,
386 .bmdma_status = ata_bmdma_status,
387
388 .qc_prep = ata_qc_prep,
389 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400390
Tejun Heo0d5ff562007-02-01 15:06:36 +0900391 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400392
393 .irq_handler = ata_interrupt,
394 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900395 .irq_on = ata_irq_on,
396 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400397
398 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400399};
400
401static struct ata_port_operations amd100_port_ops = {
402 .port_disable = ata_port_disable,
403 .set_piomode = amd100_set_piomode,
404 .set_dmamode = amd100_set_dmamode,
405 .mode_filter = ata_pci_default_filter,
406 .tf_load = ata_tf_load,
407 .tf_read = ata_tf_read,
408 .check_status = ata_check_status,
409 .exec_command = ata_exec_command,
410 .dev_select = ata_std_dev_select,
411
412 .freeze = ata_bmdma_freeze,
413 .thaw = ata_bmdma_thaw,
414 .error_handler = amd_error_handler,
415 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100416 .cable_detect = ata_cable_unknown,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400417
418 .bmdma_setup = ata_bmdma_setup,
419 .bmdma_start = ata_bmdma_start,
420 .bmdma_stop = ata_bmdma_stop,
421 .bmdma_status = ata_bmdma_status,
422
423 .qc_prep = ata_qc_prep,
424 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400425
Tejun Heo0d5ff562007-02-01 15:06:36 +0900426 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400427
428 .irq_handler = ata_interrupt,
429 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900430 .irq_on = ata_irq_on,
431 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400432
433 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400434};
435
436static struct ata_port_operations amd133_port_ops = {
437 .port_disable = ata_port_disable,
438 .set_piomode = amd133_set_piomode,
439 .set_dmamode = amd133_set_dmamode,
440 .mode_filter = ata_pci_default_filter,
441 .tf_load = ata_tf_load,
442 .tf_read = ata_tf_read,
443 .check_status = ata_check_status,
444 .exec_command = ata_exec_command,
445 .dev_select = ata_std_dev_select,
446
447 .freeze = ata_bmdma_freeze,
448 .thaw = ata_bmdma_thaw,
449 .error_handler = amd_error_handler,
450 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100451 .cable_detect = amd_cable_detect,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400452
453 .bmdma_setup = ata_bmdma_setup,
454 .bmdma_start = ata_bmdma_start,
455 .bmdma_stop = ata_bmdma_stop,
456 .bmdma_status = ata_bmdma_status,
457
458 .qc_prep = ata_qc_prep,
459 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400460
Tejun Heo0d5ff562007-02-01 15:06:36 +0900461 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400462
463 .irq_handler = ata_interrupt,
464 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900465 .irq_on = ata_irq_on,
466 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400467
468 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400469};
470
471static struct ata_port_operations nv100_port_ops = {
472 .port_disable = ata_port_disable,
473 .set_piomode = nv100_set_piomode,
474 .set_dmamode = nv100_set_dmamode,
475 .mode_filter = ata_pci_default_filter,
476 .tf_load = ata_tf_load,
477 .tf_read = ata_tf_read,
478 .check_status = ata_check_status,
479 .exec_command = ata_exec_command,
480 .dev_select = ata_std_dev_select,
481
482 .freeze = ata_bmdma_freeze,
483 .thaw = ata_bmdma_thaw,
484 .error_handler = nv_error_handler,
485 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100486 .cable_detect = nv_cable_detect,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400487
488 .bmdma_setup = ata_bmdma_setup,
489 .bmdma_start = ata_bmdma_start,
490 .bmdma_stop = ata_bmdma_stop,
491 .bmdma_status = ata_bmdma_status,
492
493 .qc_prep = ata_qc_prep,
494 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400495
Tejun Heo0d5ff562007-02-01 15:06:36 +0900496 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400497
498 .irq_handler = ata_interrupt,
499 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900500 .irq_on = ata_irq_on,
501 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400502
503 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400504};
505
506static struct ata_port_operations nv133_port_ops = {
507 .port_disable = ata_port_disable,
508 .set_piomode = nv133_set_piomode,
509 .set_dmamode = nv133_set_dmamode,
510 .mode_filter = ata_pci_default_filter,
511 .tf_load = ata_tf_load,
512 .tf_read = ata_tf_read,
513 .check_status = ata_check_status,
514 .exec_command = ata_exec_command,
515 .dev_select = ata_std_dev_select,
516
517 .freeze = ata_bmdma_freeze,
518 .thaw = ata_bmdma_thaw,
519 .error_handler = nv_error_handler,
520 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Coxeb4a2c72007-04-11 00:04:20 +0100521 .cable_detect = nv_cable_detect,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400522
523 .bmdma_setup = ata_bmdma_setup,
524 .bmdma_start = ata_bmdma_start,
525 .bmdma_stop = ata_bmdma_stop,
526 .bmdma_status = ata_bmdma_status,
527
528 .qc_prep = ata_qc_prep,
529 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400530
Tejun Heo0d5ff562007-02-01 15:06:36 +0900531 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400532
533 .irq_handler = ata_interrupt,
534 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900535 .irq_on = ata_irq_on,
536 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400537
538 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400539};
540
541static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
542{
Tejun Heo1626aeb2007-05-04 12:43:58 +0200543 static const struct ata_port_info info[10] = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400544 { /* 0: AMD 7401 */
545 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400546 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400547 .pio_mask = 0x1f,
548 .mwdma_mask = 0x07, /* No SWDMA */
549 .udma_mask = 0x07, /* UDMA 33 */
550 .port_ops = &amd33_port_ops
551 },
552 { /* 1: Early AMD7409 - no swdma */
553 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400554 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400555 .pio_mask = 0x1f,
556 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400557 .udma_mask = ATA_UDMA4, /* UDMA 66 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400558 .port_ops = &amd66_port_ops
559 },
560 { /* 2: AMD 7409, no swdma errata */
561 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400562 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400563 .pio_mask = 0x1f,
564 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400565 .udma_mask = ATA_UDMA4, /* UDMA 66 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400566 .port_ops = &amd66_port_ops
567 },
568 { /* 3: AMD 7411 */
569 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400570 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400571 .pio_mask = 0x1f,
572 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400573 .udma_mask = ATA_UDMA5, /* UDMA 100 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400574 .port_ops = &amd100_port_ops
575 },
576 { /* 4: AMD 7441 */
577 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400578 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400579 .pio_mask = 0x1f,
580 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400581 .udma_mask = ATA_UDMA5, /* UDMA 100 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400582 .port_ops = &amd100_port_ops
583 },
584 { /* 5: AMD 8111*/
585 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400586 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400587 .pio_mask = 0x1f,
588 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400589 .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400590 .port_ops = &amd133_port_ops
591 },
592 { /* 6: AMD 8111 UDMA 100 (Serenade) */
593 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400594 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400595 .pio_mask = 0x1f,
596 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400597 .udma_mask = ATA_UDMA5, /* UDMA 100, no swdma */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400598 .port_ops = &amd133_port_ops
599 },
600 { /* 7: Nvidia Nforce */
601 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400602 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400603 .pio_mask = 0x1f,
604 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400605 .udma_mask = ATA_UDMA5, /* UDMA 100 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400606 .port_ops = &nv100_port_ops
607 },
608 { /* 8: Nvidia Nforce2 and later */
609 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400610 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400611 .pio_mask = 0x1f,
612 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400613 .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400614 .port_ops = &nv133_port_ops
615 },
616 { /* 9: AMD CS5536 (Geode companion) */
617 .sht = &amd_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400618 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400619 .pio_mask = 0x1f,
620 .mwdma_mask = 0x07,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400621 .udma_mask = ATA_UDMA5, /* UDMA 100 */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400622 .port_ops = &amd100_port_ops
623 }
624 };
Tejun Heo1626aeb2007-05-04 12:43:58 +0200625 const struct ata_port_info *ppi[] = { NULL, NULL };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400626 static int printed_version;
627 int type = id->driver_data;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400628 u8 fifo;
629
630 if (!printed_version++)
631 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
632
Jeff Garzik669a5db2006-08-29 18:12:40 -0400633 pci_read_config_byte(pdev, 0x41, &fifo);
634
635 /* Check for AMD7409 without swdma errata and if found adjust type */
Auke Kok44c10132007-06-08 15:46:36 -0700636 if (type == 1 && pdev->revision > 0x7)
Jeff Garzik669a5db2006-08-29 18:12:40 -0400637 type = 2;
638
639 /* Check for AMD7411 */
640 if (type == 3)
641 /* FIFO is broken */
642 pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
643 else
644 pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
645
646 /* Serenade ? */
647 if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
648 pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
649 type = 6; /* UDMA 100 only */
650
651 if (type < 3)
652 ata_pci_clear_simplex(pdev);
653
654 /* And fire it up */
Tejun Heo1626aeb2007-05-04 12:43:58 +0200655 ppi[0] = &info[type];
656 return ata_pci_init_one(pdev, ppi);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400657}
658
Tejun Heo438ac6d2007-03-02 17:31:26 +0900659#ifdef CONFIG_PM
Alanc3041932006-11-27 16:21:24 +0000660static int amd_reinit_one(struct pci_dev *pdev)
661{
662 if (pdev->vendor == PCI_VENDOR_ID_AMD) {
663 u8 fifo;
664 pci_read_config_byte(pdev, 0x41, &fifo);
665 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411)
666 /* FIFO is broken */
667 pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
668 else
669 pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
670 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
671 pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
672 ata_pci_clear_simplex(pdev);
673 }
674 return ata_pci_device_resume(pdev);
675}
Tejun Heo438ac6d2007-03-02 17:31:26 +0900676#endif
Alanc3041932006-11-27 16:21:24 +0000677
Jeff Garzik669a5db2006-08-29 18:12:40 -0400678static const struct pci_device_id amd[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400679 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
680 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 },
681 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 3 },
682 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 4 },
683 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 5 },
684 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 7 },
685 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 8 },
686 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 8 },
687 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 8 },
688 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 8 },
689 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 },
690 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 },
691 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 },
692 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 },
693 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 },
Peer Chen05e28672006-11-02 17:58:21 -0500694 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 },
695 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 },
Peer Chen9f789752007-06-07 18:23:12 +0800696 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 8 },
697 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 8 },
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400698 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 9 },
699
700 { },
Jeff Garzik669a5db2006-08-29 18:12:40 -0400701};
702
703static struct pci_driver amd_pci_driver = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400704 .name = DRV_NAME,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400705 .id_table = amd,
706 .probe = amd_init_one,
Alanc3041932006-11-27 16:21:24 +0000707 .remove = ata_pci_remove_one,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900708#ifdef CONFIG_PM
Alanc3041932006-11-27 16:21:24 +0000709 .suspend = ata_pci_device_suspend,
710 .resume = amd_reinit_one,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900711#endif
Jeff Garzik669a5db2006-08-29 18:12:40 -0400712};
713
714static int __init amd_init(void)
715{
716 return pci_register_driver(&amd_pci_driver);
717}
718
719static void __exit amd_exit(void)
720{
721 pci_unregister_driver(&amd_pci_driver);
722}
723
Jeff Garzik669a5db2006-08-29 18:12:40 -0400724MODULE_AUTHOR("Alan Cox");
725MODULE_DESCRIPTION("low-level driver for AMD PATA IDE");
726MODULE_LICENSE("GPL");
727MODULE_DEVICE_TABLE(pci, amd);
728MODULE_VERSION(DRV_VERSION);
729
730module_init(amd_init);
731module_exit(amd_exit);