Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04 |
| 3 | * IDE driver for Linux. |
| 4 | * |
| 5 | * Copyright (c) 2000-2002 Vojtech Pavlik |
Bartlomiej Zolnierkiewicz | 31bbb66 | 2010-01-18 07:18:17 +0000 | [diff] [blame] | 6 | * Copyright (c) 2007-2010 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Based on the work of: |
| 9 | * Andre Hedrick |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License version 2 as published by |
| 15 | * the Free Software Foundation. |
| 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/pci.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/ide.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 24 | #define DRV_NAME "amd74xx" |
| 25 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 26 | enum { |
| 27 | AMD_IDE_CONFIG = 0x41, |
| 28 | AMD_CABLE_DETECT = 0x42, |
| 29 | AMD_DRIVE_TIMING = 0x48, |
| 30 | AMD_8BIT_TIMING = 0x4e, |
| 31 | AMD_ADDRESS_SETUP = 0x4c, |
| 32 | AMD_UDMA_TIMING = 0x50, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static unsigned int amd_80w; |
| 36 | static unsigned int amd_clock; |
| 37 | |
Bartlomiej Zolnierkiewicz | 75b1d97 | 2007-07-09 23:17:57 +0200 | [diff] [blame] | 38 | static char *amd_dma[] = { "16", "25", "33", "44", "66", "100", "133" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static unsigned char amd_cyc2udma[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7 }; |
| 40 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 41 | static inline u8 amd_offset(struct pci_dev *dev) |
| 42 | { |
| 43 | return (dev->vendor == PCI_VENDOR_ID_NVIDIA) ? 0x10 : 0; |
| 44 | } |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * amd_set_speed() writes timing values to the chipset registers |
| 48 | */ |
| 49 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 50 | static void amd_set_speed(struct pci_dev *dev, u8 dn, u8 udma_mask, |
| 51 | struct ide_timing *timing) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 53 | u8 t = 0, offset = amd_offset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 55 | pci_read_config_byte(dev, AMD_ADDRESS_SETUP + offset, &t); |
Harvey Harrison | d6cddd3 | 2008-07-15 21:21:41 +0200 | [diff] [blame] | 56 | t = (t & ~(3 << ((3 - dn) << 1))) | ((clamp_val(timing->setup, 1, 4) - 1) << ((3 - dn) << 1)); |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 57 | pci_write_config_byte(dev, AMD_ADDRESS_SETUP + offset, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 59 | pci_write_config_byte(dev, AMD_8BIT_TIMING + offset + (1 - (dn >> 1)), |
Harvey Harrison | d6cddd3 | 2008-07-15 21:21:41 +0200 | [diff] [blame] | 60 | ((clamp_val(timing->act8b, 1, 16) - 1) << 4) | (clamp_val(timing->rec8b, 1, 16) - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 62 | pci_write_config_byte(dev, AMD_DRIVE_TIMING + offset + (3 - dn), |
Harvey Harrison | d6cddd3 | 2008-07-15 21:21:41 +0200 | [diff] [blame] | 63 | ((clamp_val(timing->active, 1, 16) - 1) << 4) | (clamp_val(timing->recover, 1, 16) - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 65 | switch (udma_mask) { |
Harvey Harrison | d6cddd3 | 2008-07-15 21:21:41 +0200 | [diff] [blame] | 66 | case ATA_UDMA2: t = timing->udma ? (0xc0 | (clamp_val(timing->udma, 2, 5) - 2)) : 0x03; break; |
| 67 | case ATA_UDMA4: t = timing->udma ? (0xc0 | amd_cyc2udma[clamp_val(timing->udma, 2, 10)]) : 0x03; break; |
| 68 | case ATA_UDMA5: t = timing->udma ? (0xc0 | amd_cyc2udma[clamp_val(timing->udma, 1, 10)]) : 0x03; break; |
| 69 | case ATA_UDMA6: t = timing->udma ? (0xc0 | amd_cyc2udma[clamp_val(timing->udma, 1, 15)]) : 0x03; break; |
Bartlomiej Zolnierkiewicz | 75b1d97 | 2007-07-09 23:17:57 +0200 | [diff] [blame] | 70 | default: return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Bartlomiej Zolnierkiewicz | 31bbb66 | 2010-01-18 07:18:17 +0000 | [diff] [blame] | 73 | if (timing->udma) |
| 74 | pci_write_config_byte(dev, AMD_UDMA_TIMING + offset + 3 - dn, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 78 | * amd_set_drive() computes timing values and configures the chipset |
| 79 | * to a desired transfer mode. It also can be called by upper layers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | */ |
| 81 | |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 82 | static void amd_set_drive(ide_hwif_t *hwif, ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 84 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Bartlomiej Zolnierkiewicz | bca4ff1 | 2009-01-06 17:20:54 +0100 | [diff] [blame] | 85 | ide_drive_t *peer = ide_get_pair_dev(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | struct ide_timing t, p; |
| 87 | int T, UT; |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 88 | u8 udma_mask = hwif->ultra_mask; |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 89 | const u8 speed = drive->dma_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | T = 1000000000 / amd_clock; |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 92 | UT = (udma_mask == ATA_UDMA2) ? T : (T / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | ide_timing_compute(drive, speed, &t, T, UT); |
| 95 | |
Bartlomiej Zolnierkiewicz | bca4ff1 | 2009-01-06 17:20:54 +0100 | [diff] [blame] | 96 | if (peer) { |
Bartlomiej Zolnierkiewicz | f6d23c2 | 2010-01-18 07:21:33 +0000 | [diff] [blame] | 97 | ide_timing_compute(peer, peer->pio_mode, &p, T, UT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); |
| 99 | } |
| 100 | |
| 101 | if (speed == XFER_UDMA_5 && amd_clock <= 33333) t.udma = 1; |
| 102 | if (speed == XFER_UDMA_6 && amd_clock <= 33333) t.udma = 15; |
| 103 | |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 104 | amd_set_speed(dev, drive->dn, udma_mask, &t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 108 | * amd_set_pio_mode() is a callback from upper layers for PIO-only tuning. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | */ |
| 110 | |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 111 | static void amd_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 113 | drive->dma_mode = drive->pio_mode; |
| 114 | amd_set_drive(hwif, drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 117 | static void amd7409_cable_detect(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 119 | /* no host side cable detection */ |
| 120 | amd_80w = 0x03; |
| 121 | } |
| 122 | |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 123 | static void amd7411_cable_detect(struct pci_dev *dev) |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 124 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | int i; |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 126 | u32 u = 0; |
| 127 | u8 t = 0, offset = amd_offset(dev); |
| 128 | |
| 129 | pci_read_config_byte(dev, AMD_CABLE_DETECT + offset, &t); |
| 130 | pci_read_config_dword(dev, AMD_UDMA_TIMING + offset, &u); |
| 131 | amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0); |
| 132 | for (i = 24; i >= 0; i -= 8) |
| 133 | if (((u >> i) & 4) && !(amd_80w & (1 << (1 - (i >> 4))))) { |
Bartlomiej Zolnierkiewicz | a326b02 | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 134 | printk(KERN_WARNING DRV_NAME " %s: BIOS didn't set " |
| 135 | "cable bits correctly. Enabling workaround.\n", |
| 136 | pci_name(dev)); |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 137 | amd_80w |= (1 << (1 - (i >> 4))); |
| 138 | } |
| 139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | /* |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 142 | * The initialization callback. Initialize drive independent registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | */ |
| 144 | |
Bartlomiej Zolnierkiewicz | 2ed0ef5 | 2009-03-24 23:22:53 +0100 | [diff] [blame] | 145 | static int init_chipset_amd74xx(struct pci_dev *dev) |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 146 | { |
| 147 | u8 t = 0, offset = amd_offset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * Check 80-wire cable presence. |
| 151 | */ |
| 152 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 153 | if (dev->vendor == PCI_VENDOR_ID_AMD && |
| 154 | dev->device == PCI_DEVICE_ID_AMD_COBRA_7401) |
| 155 | ; /* no UDMA > 2 */ |
| 156 | else if (dev->vendor == PCI_VENDOR_ID_AMD && |
| 157 | dev->device == PCI_DEVICE_ID_AMD_VIPER_7409) |
Bartlomiej Zolnierkiewicz | a326b02 | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 158 | amd7409_cable_detect(dev); |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 159 | else |
Bartlomiej Zolnierkiewicz | a326b02 | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 160 | amd7411_cable_detect(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | /* |
| 163 | * Take care of prefetch & postwrite. |
| 164 | */ |
| 165 | |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 166 | pci_read_config_byte(dev, AMD_IDE_CONFIG + offset, &t); |
| 167 | /* |
| 168 | * Check for broken FIFO support. |
| 169 | */ |
| 170 | if (dev->vendor == PCI_VENDOR_ID_AMD && |
Roel Kluin | 43a1221 | 2009-02-25 20:28:22 +0100 | [diff] [blame] | 171 | dev->device == PCI_DEVICE_ID_AMD_VIPER_7411) |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 172 | t &= 0x0f; |
| 173 | else |
| 174 | t |= 0xf0; |
| 175 | pci_write_config_byte(dev, AMD_IDE_CONFIG + offset, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Bartlomiej Zolnierkiewicz | 2ed0ef5 | 2009-03-24 23:22:53 +0100 | [diff] [blame] | 177 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Bartlomiej Zolnierkiewicz | f454cbe | 2008-08-05 18:17:04 +0200 | [diff] [blame] | 180 | static u8 amd_cable_detect(ide_hwif_t *hwif) |
Bartlomiej Zolnierkiewicz | bfa14b4 | 2008-02-02 19:56:31 +0100 | [diff] [blame] | 181 | { |
| 182 | if ((amd_80w >> hwif->channel) & 1) |
| 183 | return ATA_CBL_PATA80; |
| 184 | else |
| 185 | return ATA_CBL_PATA40; |
| 186 | } |
| 187 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 188 | static const struct ide_port_ops amd_port_ops = { |
| 189 | .set_pio_mode = amd_set_pio_mode, |
| 190 | .set_dma_mode = amd_set_drive, |
| 191 | .cable_detect = amd_cable_detect, |
| 192 | }; |
| 193 | |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 194 | #define IDE_HFLAGS_AMD \ |
| 195 | (IDE_HFLAG_PIO_NO_BLACKLIST | \ |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 196 | IDE_HFLAG_POST_SET_MODE | \ |
| 197 | IDE_HFLAG_IO_32BIT | \ |
Bartlomiej Zolnierkiewicz | 5e71d9c | 2008-04-26 17:36:35 +0200 | [diff] [blame] | 198 | IDE_HFLAG_UNMASK_IRQS) |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 199 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 200 | #define DECLARE_AMD_DEV(swdma, udma) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { \ |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 202 | .name = DRV_NAME, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | .init_chipset = init_chipset_amd74xx, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 205 | .port_ops = &amd_port_ops, \ |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 206 | .host_flags = IDE_HFLAGS_AMD, \ |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 207 | .pio_mask = ATA_PIO5, \ |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 208 | .swdma_mask = swdma, \ |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 209 | .mwdma_mask = ATA_MWDMA2, \ |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 210 | .udma_mask = udma, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 213 | #define DECLARE_NV_DEV(udma) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { \ |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 215 | .name = DRV_NAME, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | .init_chipset = init_chipset_amd74xx, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 218 | .port_ops = &amd_port_ops, \ |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 219 | .host_flags = IDE_HFLAGS_AMD, \ |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 220 | .pio_mask = ATA_PIO5, \ |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 221 | .swdma_mask = ATA_SWDMA2, \ |
| 222 | .mwdma_mask = ATA_MWDMA2, \ |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 223 | .udma_mask = udma, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame^] | 226 | static const struct ide_port_info amd74xx_chipsets[] = { |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 227 | /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2), |
| 228 | /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4), |
| 229 | /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5), |
| 230 | /* 3: AMD8111 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA6), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 232 | /* 4: NFORCE */ DECLARE_NV_DEV(ATA_UDMA5), |
| 233 | /* 5: >= NFORCE2 */ DECLARE_NV_DEV(ATA_UDMA6), |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 234 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 235 | /* 6: AMD5536 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | }; |
| 237 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame^] | 238 | static int amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 240 | struct ide_port_info d; |
| 241 | u8 idx = id->driver_data; |
| 242 | |
| 243 | d = amd74xx_chipsets[idx]; |
| 244 | |
| 245 | /* |
| 246 | * Check for bad SWDMA and incorrectly wired Serenade mainboards. |
| 247 | */ |
| 248 | if (idx == 1) { |
| 249 | if (dev->revision <= 7) |
| 250 | d.swdma_mask = 0; |
Bartlomiej Zolnierkiewicz | 8ac2b42a | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 251 | d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX; |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 252 | } else if (idx == 3) { |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 253 | if (dev->subsystem_vendor == PCI_VENDOR_ID_AMD && |
| 254 | dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE) |
| 255 | d.udma_mask = ATA_UDMA5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 257 | |
Bartlomiej Zolnierkiewicz | 6636487 | 2008-12-02 20:40:03 +0100 | [diff] [blame] | 258 | /* |
| 259 | * It seems that on some nVidia controllers using AltStatus |
| 260 | * register can be unreliable so default to Status register |
| 261 | * if the device is in Compatibility Mode. |
| 262 | */ |
| 263 | if (dev->vendor == PCI_VENDOR_ID_NVIDIA && |
| 264 | ide_pci_is_in_compatibility_mode(dev)) |
| 265 | d.host_flags |= IDE_HFLAG_BROKEN_ALTSTATUS; |
| 266 | |
Bartlomiej Zolnierkiewicz | 28cfd8a | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 267 | printk(KERN_INFO "%s %s: UDMA%s controller\n", |
| 268 | d.name, pci_name(dev), amd_dma[fls(d.udma_mask) - 1]); |
Bartlomiej Zolnierkiewicz | 993da8f | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 269 | |
Bartlomiej Zolnierkiewicz | d51f19c | 2008-07-24 22:53:17 +0200 | [diff] [blame] | 270 | /* |
| 271 | * Determine the system bus clock. |
| 272 | */ |
| 273 | amd_clock = (ide_pci_clk ? ide_pci_clk : 33) * 1000; |
| 274 | |
| 275 | switch (amd_clock) { |
| 276 | case 33000: amd_clock = 33333; break; |
| 277 | case 37000: amd_clock = 37500; break; |
| 278 | case 41000: amd_clock = 41666; break; |
| 279 | } |
| 280 | |
| 281 | if (amd_clock < 20000 || amd_clock > 50000) { |
| 282 | printk(KERN_WARNING "%s: User given PCI clock speed impossible" |
| 283 | " (%d), using 33 MHz instead.\n", |
| 284 | d.name, amd_clock); |
| 285 | amd_clock = 33333; |
| 286 | } |
| 287 | |
Bartlomiej Zolnierkiewicz | 6cdf6eb | 2008-07-24 22:53:14 +0200 | [diff] [blame] | 288 | return ide_pci_init_one(dev, &d, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 291 | static const struct pci_device_id amd74xx_pci_tbl[] = { |
| 292 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 }, |
| 293 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 }, |
| 294 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 2 }, |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 295 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 2 }, |
| 296 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 3 }, |
| 297 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 4 }, |
| 298 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 5 }, |
| 299 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 5 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | #ifdef CONFIG_BLK_DEV_IDE_SATA |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 301 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA), 5 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | #endif |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 303 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 5 }, |
| 304 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 5 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | #ifdef CONFIG_BLK_DEV_IDE_SATA |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 306 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA), 5 }, |
| 307 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2), 5 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | #endif |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 309 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 5 }, |
| 310 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 5 }, |
| 311 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 5 }, |
| 312 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 5 }, |
| 313 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 5 }, |
| 314 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 5 }, |
| 315 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 5 }, |
| 316 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 5 }, |
| 317 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 5 }, |
| 318 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 6 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { 0, }, |
| 320 | }; |
| 321 | MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); |
| 322 | |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 323 | static struct pci_driver amd74xx_pci_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | .name = "AMD_IDE", |
| 325 | .id_table = amd74xx_pci_tbl, |
| 326 | .probe = amd74xx_probe, |
Bartlomiej Zolnierkiewicz | b2509ac | 2008-07-24 22:53:19 +0200 | [diff] [blame] | 327 | .remove = ide_pci_remove, |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 328 | .suspend = ide_pci_suspend, |
| 329 | .resume = ide_pci_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | }; |
| 331 | |
Bartlomiej Zolnierkiewicz | 82ab1ee | 2007-01-27 13:46:56 +0100 | [diff] [blame] | 332 | static int __init amd74xx_ide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 334 | return ide_pci_register_driver(&amd74xx_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Bartlomiej Zolnierkiewicz | b2509ac | 2008-07-24 22:53:19 +0200 | [diff] [blame] | 337 | static void __exit amd74xx_ide_exit(void) |
| 338 | { |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 339 | pci_unregister_driver(&amd74xx_pci_driver); |
Bartlomiej Zolnierkiewicz | b2509ac | 2008-07-24 22:53:19 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | module_init(amd74xx_ide_init); |
Bartlomiej Zolnierkiewicz | b2509ac | 2008-07-24 22:53:19 +0200 | [diff] [blame] | 343 | module_exit(amd74xx_ide_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Bartlomiej Zolnierkiewicz | 31bbb66 | 2010-01-18 07:18:17 +0000 | [diff] [blame] | 345 | MODULE_AUTHOR("Vojtech Pavlik, Bartlomiej Zolnierkiewicz"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | MODULE_DESCRIPTION("AMD PCI IDE driver"); |
| 347 | MODULE_LICENSE("GPL"); |