]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/ata/pata_amd.c
46f829c838b3b78901572f9a2ecae1ec996ad66d
[linux-2.6-omap-h63xx.git] / drivers / ata / pata_amd.c
1 /*
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"
28 #define DRV_VERSION "0.3.9"
29
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
44 static 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 /**
122  *      amd_pre_reset           -       perform reset handling
123  *      @link: ATA link
124  *      @deadline: deadline jiffies for the operation
125  *
126  *      Reset sequence checking enable bits to see which ports are
127  *      active.
128  */
129
130 static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
131 {
132         static const struct pci_bits amd_enable_bits[] = {
133                 { 0x40, 1, 0x02, 0x02 },
134                 { 0x40, 1, 0x01, 0x01 }
135         };
136
137         struct ata_port *ap = link->ap;
138         struct pci_dev *pdev = to_pci_dev(ap->host->dev);
139
140         if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
141                 return -ENOENT;
142
143         return ata_std_prereset(link, deadline);
144 }
145
146 static 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
153 static int amd_cable_detect(struct ata_port *ap)
154 {
155         static const u32 bitmask[2] = {0x03, 0x0C};
156         struct pci_dev *pdev = to_pci_dev(ap->host->dev);
157         u8 ata66;
158
159         pci_read_config_byte(pdev, 0x42, &ata66);
160         if (ata66 & bitmask[ap->port_no])
161                 return ATA_CBL_PATA80;
162         return ATA_CBL_PATA40;
163 }
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
173 static 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
178 static 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
183 static 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
188 static 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
202 static 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
207 static 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
212 static 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
217 static 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
225  *      @lin: ATA link
226  *
227  *      Perform cable detection. The BIOS stores this in PCI config
228  *      space for us.
229  */
230
231 static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
232 {
233         static const struct pci_bits nv_enable_bits[] = {
234                 { 0x50, 1, 0x02, 0x02 },
235                 { 0x50, 1, 0x01, 0x01 }
236         };
237
238         struct ata_port *ap = link->ap;
239         struct pci_dev *pdev = to_pci_dev(ap->host->dev);
240
241         if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
242                 return -ENOENT;
243
244         return ata_std_prereset(link, deadline);
245 }
246
247 static 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 }
253
254 static 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
276 /**
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
284 static 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
289 static 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
303 static 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
308 static 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
313 static 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,
321         .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,
327         .slave_destroy          = ata_scsi_slave_destroy,
328         .bios_param             = ata_std_bios_param,
329 };
330
331 static 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,
344         .error_handler  = amd_error_handler,
345         .post_internal_cmd = ata_bmdma_post_internal_cmd,
346         .cable_detect   = ata_cable_40wire,
347
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,
355
356         .data_xfer      = ata_data_xfer,
357
358         .irq_handler    = ata_interrupt,
359         .irq_clear      = ata_bmdma_irq_clear,
360         .irq_on         = ata_irq_on,
361
362         .port_start     = ata_port_start,
363 };
364
365 static struct ata_port_operations amd66_port_ops = {
366         .port_disable   = ata_port_disable,
367         .set_piomode    = amd66_set_piomode,
368         .set_dmamode    = amd66_set_dmamode,
369         .mode_filter    = ata_pci_default_filter,
370         .tf_load        = ata_tf_load,
371         .tf_read        = ata_tf_read,
372         .check_status   = ata_check_status,
373         .exec_command   = ata_exec_command,
374         .dev_select     = ata_std_dev_select,
375
376         .freeze         = ata_bmdma_freeze,
377         .thaw           = ata_bmdma_thaw,
378         .error_handler  = amd_error_handler,
379         .post_internal_cmd = ata_bmdma_post_internal_cmd,
380         .cable_detect   = ata_cable_unknown,
381
382         .bmdma_setup    = ata_bmdma_setup,
383         .bmdma_start    = ata_bmdma_start,
384         .bmdma_stop     = ata_bmdma_stop,
385         .bmdma_status   = ata_bmdma_status,
386
387         .qc_prep        = ata_qc_prep,
388         .qc_issue       = ata_qc_issue_prot,
389
390         .data_xfer      = ata_data_xfer,
391
392         .irq_handler    = ata_interrupt,
393         .irq_clear      = ata_bmdma_irq_clear,
394         .irq_on         = ata_irq_on,
395
396         .port_start     = ata_port_start,
397 };
398
399 static struct ata_port_operations amd100_port_ops = {
400         .port_disable   = ata_port_disable,
401         .set_piomode    = amd100_set_piomode,
402         .set_dmamode    = amd100_set_dmamode,
403         .mode_filter    = ata_pci_default_filter,
404         .tf_load        = ata_tf_load,
405         .tf_read        = ata_tf_read,
406         .check_status   = ata_check_status,
407         .exec_command   = ata_exec_command,
408         .dev_select     = ata_std_dev_select,
409
410         .freeze         = ata_bmdma_freeze,
411         .thaw           = ata_bmdma_thaw,
412         .error_handler  = amd_error_handler,
413         .post_internal_cmd = ata_bmdma_post_internal_cmd,
414         .cable_detect   = ata_cable_unknown,
415
416         .bmdma_setup    = ata_bmdma_setup,
417         .bmdma_start    = ata_bmdma_start,
418         .bmdma_stop     = ata_bmdma_stop,
419         .bmdma_status   = ata_bmdma_status,
420
421         .qc_prep        = ata_qc_prep,
422         .qc_issue       = ata_qc_issue_prot,
423
424         .data_xfer      = ata_data_xfer,
425
426         .irq_handler    = ata_interrupt,
427         .irq_clear      = ata_bmdma_irq_clear,
428         .irq_on         = ata_irq_on,
429
430         .port_start     = ata_port_start,
431 };
432
433 static struct ata_port_operations amd133_port_ops = {
434         .port_disable   = ata_port_disable,
435         .set_piomode    = amd133_set_piomode,
436         .set_dmamode    = amd133_set_dmamode,
437         .mode_filter    = ata_pci_default_filter,
438         .tf_load        = ata_tf_load,
439         .tf_read        = ata_tf_read,
440         .check_status   = ata_check_status,
441         .exec_command   = ata_exec_command,
442         .dev_select     = ata_std_dev_select,
443
444         .freeze         = ata_bmdma_freeze,
445         .thaw           = ata_bmdma_thaw,
446         .error_handler  = amd_error_handler,
447         .post_internal_cmd = ata_bmdma_post_internal_cmd,
448         .cable_detect   = amd_cable_detect,
449
450         .bmdma_setup    = ata_bmdma_setup,
451         .bmdma_start    = ata_bmdma_start,
452         .bmdma_stop     = ata_bmdma_stop,
453         .bmdma_status   = ata_bmdma_status,
454
455         .qc_prep        = ata_qc_prep,
456         .qc_issue       = ata_qc_issue_prot,
457
458         .data_xfer      = ata_data_xfer,
459
460         .irq_handler    = ata_interrupt,
461         .irq_clear      = ata_bmdma_irq_clear,
462         .irq_on         = ata_irq_on,
463
464         .port_start     = ata_port_start,
465 };
466
467 static struct ata_port_operations nv100_port_ops = {
468         .port_disable   = ata_port_disable,
469         .set_piomode    = nv100_set_piomode,
470         .set_dmamode    = nv100_set_dmamode,
471         .mode_filter    = ata_pci_default_filter,
472         .tf_load        = ata_tf_load,
473         .tf_read        = ata_tf_read,
474         .check_status   = ata_check_status,
475         .exec_command   = ata_exec_command,
476         .dev_select     = ata_std_dev_select,
477
478         .freeze         = ata_bmdma_freeze,
479         .thaw           = ata_bmdma_thaw,
480         .error_handler  = nv_error_handler,
481         .post_internal_cmd = ata_bmdma_post_internal_cmd,
482         .cable_detect   = nv_cable_detect,
483
484         .bmdma_setup    = ata_bmdma_setup,
485         .bmdma_start    = ata_bmdma_start,
486         .bmdma_stop     = ata_bmdma_stop,
487         .bmdma_status   = ata_bmdma_status,
488
489         .qc_prep        = ata_qc_prep,
490         .qc_issue       = ata_qc_issue_prot,
491
492         .data_xfer      = ata_data_xfer,
493
494         .irq_handler    = ata_interrupt,
495         .irq_clear      = ata_bmdma_irq_clear,
496         .irq_on         = ata_irq_on,
497
498         .port_start     = ata_port_start,
499 };
500
501 static struct ata_port_operations nv133_port_ops = {
502         .port_disable   = ata_port_disable,
503         .set_piomode    = nv133_set_piomode,
504         .set_dmamode    = nv133_set_dmamode,
505         .mode_filter    = ata_pci_default_filter,
506         .tf_load        = ata_tf_load,
507         .tf_read        = ata_tf_read,
508         .check_status   = ata_check_status,
509         .exec_command   = ata_exec_command,
510         .dev_select     = ata_std_dev_select,
511
512         .freeze         = ata_bmdma_freeze,
513         .thaw           = ata_bmdma_thaw,
514         .error_handler  = nv_error_handler,
515         .post_internal_cmd = ata_bmdma_post_internal_cmd,
516         .cable_detect   = nv_cable_detect,
517
518         .bmdma_setup    = ata_bmdma_setup,
519         .bmdma_start    = ata_bmdma_start,
520         .bmdma_stop     = ata_bmdma_stop,
521         .bmdma_status   = ata_bmdma_status,
522
523         .qc_prep        = ata_qc_prep,
524         .qc_issue       = ata_qc_issue_prot,
525
526         .data_xfer      = ata_data_xfer,
527
528         .irq_handler    = ata_interrupt,
529         .irq_clear      = ata_bmdma_irq_clear,
530         .irq_on         = ata_irq_on,
531
532         .port_start     = ata_port_start,
533 };
534
535 static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
536 {
537         static const struct ata_port_info info[10] = {
538                 {       /* 0: AMD 7401 */
539                         .sht = &amd_sht,
540                         .flags = ATA_FLAG_SLAVE_POSS,
541                         .pio_mask = 0x1f,
542                         .mwdma_mask = 0x07,     /* No SWDMA */
543                         .udma_mask = 0x07,      /* UDMA 33 */
544                         .port_ops = &amd33_port_ops
545                 },
546                 {       /* 1: Early AMD7409 - no swdma */
547                         .sht = &amd_sht,
548                         .flags = ATA_FLAG_SLAVE_POSS,
549                         .pio_mask = 0x1f,
550                         .mwdma_mask = 0x07,
551                         .udma_mask = ATA_UDMA4, /* UDMA 66 */
552                         .port_ops = &amd66_port_ops
553                 },
554                 {       /* 2: AMD 7409, no swdma errata */
555                         .sht = &amd_sht,
556                         .flags = ATA_FLAG_SLAVE_POSS,
557                         .pio_mask = 0x1f,
558                         .mwdma_mask = 0x07,
559                         .udma_mask = ATA_UDMA4, /* UDMA 66 */
560                         .port_ops = &amd66_port_ops
561                 },
562                 {       /* 3: AMD 7411 */
563                         .sht = &amd_sht,
564                         .flags = ATA_FLAG_SLAVE_POSS,
565                         .pio_mask = 0x1f,
566                         .mwdma_mask = 0x07,
567                         .udma_mask = ATA_UDMA5, /* UDMA 100 */
568                         .port_ops = &amd100_port_ops
569                 },
570                 {       /* 4: AMD 7441 */
571                         .sht = &amd_sht,
572                         .flags = ATA_FLAG_SLAVE_POSS,
573                         .pio_mask = 0x1f,
574                         .mwdma_mask = 0x07,
575                         .udma_mask = ATA_UDMA5, /* UDMA 100 */
576                         .port_ops = &amd100_port_ops
577                 },
578                 {       /* 5: AMD 8111*/
579                         .sht = &amd_sht,
580                         .flags = ATA_FLAG_SLAVE_POSS,
581                         .pio_mask = 0x1f,
582                         .mwdma_mask = 0x07,
583                         .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */
584                         .port_ops = &amd133_port_ops
585                 },
586                 {       /* 6: AMD 8111 UDMA 100 (Serenade) */
587                         .sht = &amd_sht,
588                         .flags = ATA_FLAG_SLAVE_POSS,
589                         .pio_mask = 0x1f,
590                         .mwdma_mask = 0x07,
591                         .udma_mask = ATA_UDMA5, /* UDMA 100, no swdma */
592                         .port_ops = &amd133_port_ops
593                 },
594                 {       /* 7: Nvidia Nforce */
595                         .sht = &amd_sht,
596                         .flags = ATA_FLAG_SLAVE_POSS,
597                         .pio_mask = 0x1f,
598                         .mwdma_mask = 0x07,
599                         .udma_mask = ATA_UDMA5, /* UDMA 100 */
600                         .port_ops = &nv100_port_ops
601                 },
602                 {       /* 8: Nvidia Nforce2 and later */
603                         .sht = &amd_sht,
604                         .flags = ATA_FLAG_SLAVE_POSS,
605                         .pio_mask = 0x1f,
606                         .mwdma_mask = 0x07,
607                         .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */
608                         .port_ops = &nv133_port_ops
609                 },
610                 {       /* 9: AMD CS5536 (Geode companion) */
611                         .sht = &amd_sht,
612                         .flags = ATA_FLAG_SLAVE_POSS,
613                         .pio_mask = 0x1f,
614                         .mwdma_mask = 0x07,
615                         .udma_mask = ATA_UDMA5, /* UDMA 100 */
616                         .port_ops = &amd100_port_ops
617                 }
618         };
619         const struct ata_port_info *ppi[] = { NULL, NULL };
620         static int printed_version;
621         int type = id->driver_data;
622         u8 fifo;
623
624         if (!printed_version++)
625                 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
626
627         pci_read_config_byte(pdev, 0x41, &fifo);
628
629         /* Check for AMD7409 without swdma errata and if found adjust type */
630         if (type == 1 && pdev->revision > 0x7)
631                 type = 2;
632
633         /* Check for AMD7411 */
634         if (type == 3)
635                 /* FIFO is broken */
636                 pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
637         else
638                 pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
639
640         /* Serenade ? */
641         if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
642                          pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
643                 type = 6;       /* UDMA 100 only */
644
645         if (type < 3)
646                 ata_pci_clear_simplex(pdev);
647
648         /* And fire it up */
649         ppi[0] = &info[type];
650         return ata_pci_init_one(pdev, ppi);
651 }
652
653 #ifdef CONFIG_PM
654 static int amd_reinit_one(struct pci_dev *pdev)
655 {
656         if (pdev->vendor == PCI_VENDOR_ID_AMD) {
657                 u8 fifo;
658                 pci_read_config_byte(pdev, 0x41, &fifo);
659                 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411)
660                         /* FIFO is broken */
661                         pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
662                 else
663                         pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
664                 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
665                     pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
666                         ata_pci_clear_simplex(pdev);
667         }
668         return ata_pci_device_resume(pdev);
669 }
670 #endif
671
672 static const struct pci_device_id amd[] = {
673         { PCI_VDEVICE(AMD,      PCI_DEVICE_ID_AMD_COBRA_7401),          0 },
674         { PCI_VDEVICE(AMD,      PCI_DEVICE_ID_AMD_VIPER_7409),          1 },
675         { PCI_VDEVICE(AMD,      PCI_DEVICE_ID_AMD_VIPER_7411),          3 },
676         { PCI_VDEVICE(AMD,      PCI_DEVICE_ID_AMD_OPUS_7441),           4 },
677         { PCI_VDEVICE(AMD,      PCI_DEVICE_ID_AMD_8111_IDE),            5 },
678         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_IDE),       7 },
679         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE),      8 },
680         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE),     8 },
681         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE),      8 },
682         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE),     8 },
683         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 },
684         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 },
685         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 },
686         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 },
687         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 },
688         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 },
689         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 },
690         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 8 },
691         { PCI_VDEVICE(NVIDIA,   PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 8 },
692         { PCI_VDEVICE(AMD,      PCI_DEVICE_ID_AMD_CS5536_IDE),          9 },
693
694         { },
695 };
696
697 static struct pci_driver amd_pci_driver = {
698         .name           = DRV_NAME,
699         .id_table       = amd,
700         .probe          = amd_init_one,
701         .remove         = ata_pci_remove_one,
702 #ifdef CONFIG_PM
703         .suspend        = ata_pci_device_suspend,
704         .resume         = amd_reinit_one,
705 #endif
706 };
707
708 static int __init amd_init(void)
709 {
710         return pci_register_driver(&amd_pci_driver);
711 }
712
713 static void __exit amd_exit(void)
714 {
715         pci_unregister_driver(&amd_pci_driver);
716 }
717
718 MODULE_AUTHOR("Alan Cox");
719 MODULE_DESCRIPTION("low-level driver for AMD PATA IDE");
720 MODULE_LICENSE("GPL");
721 MODULE_DEVICE_TABLE(pci, amd);
722 MODULE_VERSION(DRV_VERSION);
723
724 module_init(amd_init);
725 module_exit(amd_exit);