Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 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" |
Bartlomiej Zolnierkiewicz | 943547a | 2007-12-02 03:47:01 +0100 | [diff] [blame] | 28 | #define DRV_VERSION "0.3.10" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 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 */ |
Bartlomiej Zolnierkiewicz | 943547a | 2007-12-02 03:47:01 +0100 | [diff] [blame] | 118 | if (at.udma) |
| 119 | pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 123 | * amd_pre_reset - perform reset handling |
| 124 | * @link: ATA link |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 125 | * @deadline: deadline jiffies for the operation |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 126 | * |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 127 | * Reset sequence checking enable bits to see which ports are |
| 128 | * active. |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 129 | */ |
| 130 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 131 | static int amd_pre_reset(struct ata_link *link, unsigned long deadline) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 132 | { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 133 | static const struct pci_bits amd_enable_bits[] = { |
| 134 | { 0x40, 1, 0x02, 0x02 }, |
| 135 | { 0x40, 1, 0x01, 0x01 } |
| 136 | }; |
| 137 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 138 | struct ata_port *ap = link->ap; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 139 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 140 | |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 141 | if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) |
| 142 | return -ENOENT; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 143 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 144 | return ata_std_prereset(link, deadline); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void amd_error_handler(struct ata_port *ap) |
| 148 | { |
Harvey Harrison | d98f88c | 2008-02-13 21:14:20 -0800 | [diff] [blame] | 149 | ata_bmdma_drive_eh(ap, amd_pre_reset, ata_std_softreset, NULL, |
| 150 | ata_std_postreset); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 153 | static int amd_cable_detect(struct ata_port *ap) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 154 | { |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 155 | static const u32 bitmask[2] = {0x03, 0x0C}; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 156 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 157 | u8 ata66; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 158 | |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 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; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 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 | |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 222 | /* Both host-side and drive-side detection results are worthless on NV |
| 223 | * PATAs. Ignore them and just follow what BIOS configured. Both the |
| 224 | * current configuration in PCI config reg and ACPI GTM result are |
| 225 | * cached during driver attach and are consulted to select transfer |
| 226 | * mode. |
| 227 | */ |
| 228 | static unsigned long nv_mode_filter(struct ata_device *dev, |
| 229 | unsigned long xfer_mask) |
| 230 | { |
| 231 | static const unsigned int udma_mask_map[] = |
| 232 | { ATA_UDMA2, ATA_UDMA1, ATA_UDMA0, 0, |
| 233 | ATA_UDMA3, ATA_UDMA4, ATA_UDMA5, ATA_UDMA6 }; |
| 234 | struct ata_port *ap = dev->link->ap; |
| 235 | char acpi_str[32] = ""; |
| 236 | u32 saved_udma, udma; |
| 237 | const struct ata_acpi_gtm *gtm; |
| 238 | unsigned long bios_limit = 0, acpi_limit = 0, limit; |
| 239 | |
| 240 | /* find out what BIOS configured */ |
| 241 | udma = saved_udma = (unsigned long)ap->host->private_data; |
| 242 | |
| 243 | if (ap->port_no == 0) |
| 244 | udma >>= 16; |
| 245 | if (dev->devno == 0) |
| 246 | udma >>= 8; |
| 247 | |
| 248 | if ((udma & 0xc0) == 0xc0) |
| 249 | bios_limit = ata_pack_xfermask(0, 0, udma_mask_map[udma & 0x7]); |
| 250 | |
| 251 | /* consult ACPI GTM too */ |
| 252 | gtm = ata_acpi_init_gtm(ap); |
| 253 | if (gtm) { |
| 254 | acpi_limit = ata_acpi_gtm_xfermask(dev, gtm); |
| 255 | |
| 256 | snprintf(acpi_str, sizeof(acpi_str), " (%u:%u:0x%x)", |
| 257 | gtm->drive[0].dma, gtm->drive[1].dma, gtm->flags); |
| 258 | } |
| 259 | |
| 260 | /* be optimistic, EH can take care of things if something goes wrong */ |
| 261 | limit = bios_limit | acpi_limit; |
| 262 | |
| 263 | /* If PIO or DMA isn't configured at all, don't limit. Let EH |
| 264 | * handle it. |
| 265 | */ |
| 266 | if (!(limit & ATA_MASK_PIO)) |
| 267 | limit |= ATA_MASK_PIO; |
| 268 | if (!(limit & (ATA_MASK_MWDMA | ATA_MASK_UDMA))) |
| 269 | limit |= ATA_MASK_MWDMA | ATA_MASK_UDMA; |
| 270 | |
| 271 | ata_port_printk(ap, KERN_DEBUG, "nv_mode_filter: 0x%lx&0x%lx->0x%lx, " |
| 272 | "BIOS=0x%lx (0x%x) ACPI=0x%lx%s\n", |
| 273 | xfer_mask, limit, xfer_mask & limit, bios_limit, |
| 274 | saved_udma, acpi_limit, acpi_str); |
| 275 | |
| 276 | return xfer_mask & limit; |
| 277 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * nv_probe_init - cable detection |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 281 | * @lin: ATA link |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 282 | * |
| 283 | * Perform cable detection. The BIOS stores this in PCI config |
| 284 | * space for us. |
| 285 | */ |
| 286 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 287 | static int nv_pre_reset(struct ata_link *link, unsigned long deadline) |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 288 | { |
Alan Cox | 76ff3c6 | 2006-09-12 17:14:03 +0100 | [diff] [blame] | 289 | static const struct pci_bits nv_enable_bits[] = { |
| 290 | { 0x50, 1, 0x02, 0x02 }, |
| 291 | { 0x50, 1, 0x01, 0x01 } |
| 292 | }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 293 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 294 | struct ata_port *ap = link->ap; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 295 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 296 | |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 297 | if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no])) |
| 298 | return -ENOENT; |
Alan Cox | 76ff3c6 | 2006-09-12 17:14:03 +0100 | [diff] [blame] | 299 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 300 | return ata_std_prereset(link, deadline); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void nv_error_handler(struct ata_port *ap) |
| 304 | { |
| 305 | ata_bmdma_drive_eh(ap, nv_pre_reset, |
| 306 | ata_std_softreset, NULL, |
| 307 | ata_std_postreset); |
| 308 | } |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 309 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 310 | /** |
| 311 | * nv100_set_piomode - set initial PIO mode data |
| 312 | * @ap: ATA interface |
| 313 | * @adev: ATA device |
| 314 | * |
| 315 | * Program the AMD registers for PIO mode. |
| 316 | */ |
| 317 | |
| 318 | static void nv100_set_piomode(struct ata_port *ap, struct ata_device *adev) |
| 319 | { |
| 320 | timing_setup(ap, adev, 0x50, adev->pio_mode, 3); |
| 321 | } |
| 322 | |
| 323 | static void nv133_set_piomode(struct ata_port *ap, struct ata_device *adev) |
| 324 | { |
| 325 | timing_setup(ap, adev, 0x50, adev->pio_mode, 4); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * nv100_set_dmamode - set initial DMA mode data |
| 330 | * @ap: ATA interface |
| 331 | * @adev: ATA device |
| 332 | * |
| 333 | * Program the MWDMA/UDMA modes for the AMD and Nvidia |
| 334 | * chipset. |
| 335 | */ |
| 336 | |
| 337 | static void nv100_set_dmamode(struct ata_port *ap, struct ata_device *adev) |
| 338 | { |
| 339 | timing_setup(ap, adev, 0x50, adev->dma_mode, 3); |
| 340 | } |
| 341 | |
| 342 | static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev) |
| 343 | { |
| 344 | timing_setup(ap, adev, 0x50, adev->dma_mode, 4); |
| 345 | } |
| 346 | |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 347 | static void nv_host_stop(struct ata_host *host) |
| 348 | { |
| 349 | u32 udma = (unsigned long)host->private_data; |
| 350 | |
| 351 | /* restore PCI config register 0x60 */ |
| 352 | pci_write_config_dword(to_pci_dev(host->dev), 0x60, udma); |
| 353 | } |
| 354 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 355 | static struct scsi_host_template amd_sht = { |
Tejun Heo | 68d1d07 | 2008-03-25 12:22:49 +0900 | [diff] [blame^] | 356 | ATA_BMDMA_SHT(DRV_NAME), |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | static struct ata_port_operations amd33_port_ops = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 360 | .set_piomode = amd33_set_piomode, |
| 361 | .set_dmamode = amd33_set_dmamode, |
| 362 | .mode_filter = ata_pci_default_filter, |
| 363 | .tf_load = ata_tf_load, |
| 364 | .tf_read = ata_tf_read, |
| 365 | .check_status = ata_check_status, |
| 366 | .exec_command = ata_exec_command, |
| 367 | .dev_select = ata_std_dev_select, |
| 368 | |
| 369 | .freeze = ata_bmdma_freeze, |
| 370 | .thaw = ata_bmdma_thaw, |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 371 | .error_handler = amd_error_handler, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 372 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 373 | .cable_detect = ata_cable_40wire, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 374 | |
| 375 | .bmdma_setup = ata_bmdma_setup, |
| 376 | .bmdma_start = ata_bmdma_start, |
| 377 | .bmdma_stop = ata_bmdma_stop, |
| 378 | .bmdma_status = ata_bmdma_status, |
| 379 | |
| 380 | .qc_prep = ata_qc_prep, |
| 381 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 382 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 383 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 384 | |
| 385 | .irq_handler = ata_interrupt, |
| 386 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 387 | .irq_on = ata_irq_on, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 388 | |
Alan Cox | 81ad183 | 2007-08-22 22:55:41 +0100 | [diff] [blame] | 389 | .port_start = ata_sff_port_start, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | static struct ata_port_operations amd66_port_ops = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 393 | .set_piomode = amd66_set_piomode, |
| 394 | .set_dmamode = amd66_set_dmamode, |
| 395 | .mode_filter = ata_pci_default_filter, |
| 396 | .tf_load = ata_tf_load, |
| 397 | .tf_read = ata_tf_read, |
| 398 | .check_status = ata_check_status, |
| 399 | .exec_command = ata_exec_command, |
| 400 | .dev_select = ata_std_dev_select, |
| 401 | |
| 402 | .freeze = ata_bmdma_freeze, |
| 403 | .thaw = ata_bmdma_thaw, |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 404 | .error_handler = amd_error_handler, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 405 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 406 | .cable_detect = ata_cable_unknown, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 407 | |
| 408 | .bmdma_setup = ata_bmdma_setup, |
| 409 | .bmdma_start = ata_bmdma_start, |
| 410 | .bmdma_stop = ata_bmdma_stop, |
| 411 | .bmdma_status = ata_bmdma_status, |
| 412 | |
| 413 | .qc_prep = ata_qc_prep, |
| 414 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 415 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 416 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 417 | |
| 418 | .irq_handler = ata_interrupt, |
| 419 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 420 | .irq_on = ata_irq_on, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 421 | |
Alan Cox | 81ad183 | 2007-08-22 22:55:41 +0100 | [diff] [blame] | 422 | .port_start = ata_sff_port_start, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | static struct ata_port_operations amd100_port_ops = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 426 | .set_piomode = amd100_set_piomode, |
| 427 | .set_dmamode = amd100_set_dmamode, |
| 428 | .mode_filter = ata_pci_default_filter, |
| 429 | .tf_load = ata_tf_load, |
| 430 | .tf_read = ata_tf_read, |
| 431 | .check_status = ata_check_status, |
| 432 | .exec_command = ata_exec_command, |
| 433 | .dev_select = ata_std_dev_select, |
| 434 | |
| 435 | .freeze = ata_bmdma_freeze, |
| 436 | .thaw = ata_bmdma_thaw, |
| 437 | .error_handler = amd_error_handler, |
| 438 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 439 | .cable_detect = ata_cable_unknown, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 440 | |
| 441 | .bmdma_setup = ata_bmdma_setup, |
| 442 | .bmdma_start = ata_bmdma_start, |
| 443 | .bmdma_stop = ata_bmdma_stop, |
| 444 | .bmdma_status = ata_bmdma_status, |
| 445 | |
| 446 | .qc_prep = ata_qc_prep, |
| 447 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 448 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 449 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 450 | |
| 451 | .irq_handler = ata_interrupt, |
| 452 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 453 | .irq_on = ata_irq_on, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 454 | |
Alan Cox | 81ad183 | 2007-08-22 22:55:41 +0100 | [diff] [blame] | 455 | .port_start = ata_sff_port_start, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | static struct ata_port_operations amd133_port_ops = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 459 | .set_piomode = amd133_set_piomode, |
| 460 | .set_dmamode = amd133_set_dmamode, |
| 461 | .mode_filter = ata_pci_default_filter, |
| 462 | .tf_load = ata_tf_load, |
| 463 | .tf_read = ata_tf_read, |
| 464 | .check_status = ata_check_status, |
| 465 | .exec_command = ata_exec_command, |
| 466 | .dev_select = ata_std_dev_select, |
| 467 | |
| 468 | .freeze = ata_bmdma_freeze, |
| 469 | .thaw = ata_bmdma_thaw, |
| 470 | .error_handler = amd_error_handler, |
| 471 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | eb4a2c7 | 2007-04-11 00:04:20 +0100 | [diff] [blame] | 472 | .cable_detect = amd_cable_detect, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 473 | |
| 474 | .bmdma_setup = ata_bmdma_setup, |
| 475 | .bmdma_start = ata_bmdma_start, |
| 476 | .bmdma_stop = ata_bmdma_stop, |
| 477 | .bmdma_status = ata_bmdma_status, |
| 478 | |
| 479 | .qc_prep = ata_qc_prep, |
| 480 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 481 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 482 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 483 | |
| 484 | .irq_handler = ata_interrupt, |
| 485 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 486 | .irq_on = ata_irq_on, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 487 | |
Alan Cox | 81ad183 | 2007-08-22 22:55:41 +0100 | [diff] [blame] | 488 | .port_start = ata_sff_port_start, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 489 | }; |
| 490 | |
| 491 | static struct ata_port_operations nv100_port_ops = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 492 | .set_piomode = nv100_set_piomode, |
| 493 | .set_dmamode = nv100_set_dmamode, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 494 | .tf_load = ata_tf_load, |
| 495 | .tf_read = ata_tf_read, |
| 496 | .check_status = ata_check_status, |
| 497 | .exec_command = ata_exec_command, |
| 498 | .dev_select = ata_std_dev_select, |
| 499 | |
| 500 | .freeze = ata_bmdma_freeze, |
| 501 | .thaw = ata_bmdma_thaw, |
| 502 | .error_handler = nv_error_handler, |
| 503 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 504 | .cable_detect = ata_cable_ignore, |
| 505 | .mode_filter = nv_mode_filter, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 506 | |
| 507 | .bmdma_setup = ata_bmdma_setup, |
| 508 | .bmdma_start = ata_bmdma_start, |
| 509 | .bmdma_stop = ata_bmdma_stop, |
| 510 | .bmdma_status = ata_bmdma_status, |
| 511 | |
| 512 | .qc_prep = ata_qc_prep, |
| 513 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 514 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 515 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 516 | |
| 517 | .irq_handler = ata_interrupt, |
| 518 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 519 | .irq_on = ata_irq_on, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 520 | |
Alan Cox | 81ad183 | 2007-08-22 22:55:41 +0100 | [diff] [blame] | 521 | .port_start = ata_sff_port_start, |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 522 | .host_stop = nv_host_stop, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 523 | }; |
| 524 | |
| 525 | static struct ata_port_operations nv133_port_ops = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 526 | .set_piomode = nv133_set_piomode, |
| 527 | .set_dmamode = nv133_set_dmamode, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 528 | .tf_load = ata_tf_load, |
| 529 | .tf_read = ata_tf_read, |
| 530 | .check_status = ata_check_status, |
| 531 | .exec_command = ata_exec_command, |
| 532 | .dev_select = ata_std_dev_select, |
| 533 | |
| 534 | .freeze = ata_bmdma_freeze, |
| 535 | .thaw = ata_bmdma_thaw, |
| 536 | .error_handler = nv_error_handler, |
| 537 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 538 | .cable_detect = ata_cable_ignore, |
| 539 | .mode_filter = nv_mode_filter, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 540 | |
| 541 | .bmdma_setup = ata_bmdma_setup, |
| 542 | .bmdma_start = ata_bmdma_start, |
| 543 | .bmdma_stop = ata_bmdma_stop, |
| 544 | .bmdma_status = ata_bmdma_status, |
| 545 | |
| 546 | .qc_prep = ata_qc_prep, |
| 547 | .qc_issue = ata_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 548 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 549 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 550 | |
| 551 | .irq_handler = ata_interrupt, |
| 552 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 553 | .irq_on = ata_irq_on, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 554 | |
Alan Cox | 81ad183 | 2007-08-22 22:55:41 +0100 | [diff] [blame] | 555 | .port_start = ata_sff_port_start, |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 556 | .host_stop = nv_host_stop, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 557 | }; |
| 558 | |
| 559 | static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id) |
| 560 | { |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 561 | static const struct ata_port_info info[10] = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 562 | { /* 0: AMD 7401 */ |
| 563 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 564 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 565 | .pio_mask = 0x1f, |
| 566 | .mwdma_mask = 0x07, /* No SWDMA */ |
| 567 | .udma_mask = 0x07, /* UDMA 33 */ |
| 568 | .port_ops = &amd33_port_ops |
| 569 | }, |
| 570 | { /* 1: Early AMD7409 - no swdma */ |
| 571 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 572 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 573 | .pio_mask = 0x1f, |
| 574 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 575 | .udma_mask = ATA_UDMA4, /* UDMA 66 */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 576 | .port_ops = &amd66_port_ops |
| 577 | }, |
| 578 | { /* 2: AMD 7409, no swdma errata */ |
| 579 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 580 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 581 | .pio_mask = 0x1f, |
| 582 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 583 | .udma_mask = ATA_UDMA4, /* UDMA 66 */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 584 | .port_ops = &amd66_port_ops |
| 585 | }, |
| 586 | { /* 3: AMD 7411 */ |
| 587 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 588 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 589 | .pio_mask = 0x1f, |
| 590 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 591 | .udma_mask = ATA_UDMA5, /* UDMA 100 */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 592 | .port_ops = &amd100_port_ops |
| 593 | }, |
| 594 | { /* 4: AMD 7441 */ |
| 595 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 596 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 597 | .pio_mask = 0x1f, |
| 598 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 599 | .udma_mask = ATA_UDMA5, /* UDMA 100 */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 600 | .port_ops = &amd100_port_ops |
| 601 | }, |
| 602 | { /* 5: AMD 8111*/ |
| 603 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 604 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 605 | .pio_mask = 0x1f, |
| 606 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 607 | .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 608 | .port_ops = &amd133_port_ops |
| 609 | }, |
| 610 | { /* 6: AMD 8111 UDMA 100 (Serenade) */ |
| 611 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 612 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 613 | .pio_mask = 0x1f, |
| 614 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 615 | .udma_mask = ATA_UDMA5, /* UDMA 100, no swdma */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 616 | .port_ops = &amd133_port_ops |
| 617 | }, |
| 618 | { /* 7: Nvidia Nforce */ |
| 619 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 620 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 621 | .pio_mask = 0x1f, |
| 622 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 623 | .udma_mask = ATA_UDMA5, /* UDMA 100 */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 624 | .port_ops = &nv100_port_ops |
| 625 | }, |
| 626 | { /* 8: Nvidia Nforce2 and later */ |
| 627 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 628 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 629 | .pio_mask = 0x1f, |
| 630 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 631 | .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 632 | .port_ops = &nv133_port_ops |
| 633 | }, |
| 634 | { /* 9: AMD CS5536 (Geode companion) */ |
| 635 | .sht = &amd_sht, |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 636 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 637 | .pio_mask = 0x1f, |
| 638 | .mwdma_mask = 0x07, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 639 | .udma_mask = ATA_UDMA5, /* UDMA 100 */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 640 | .port_ops = &amd100_port_ops |
| 641 | } |
| 642 | }; |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 643 | struct ata_port_info pi; |
| 644 | const struct ata_port_info *ppi[] = { &pi, NULL }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 645 | static int printed_version; |
| 646 | int type = id->driver_data; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 647 | u8 fifo; |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 648 | int rc; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 649 | |
| 650 | if (!printed_version++) |
| 651 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); |
| 652 | |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 653 | rc = pcim_enable_device(pdev); |
| 654 | if (rc) |
| 655 | return rc; |
| 656 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 657 | pci_read_config_byte(pdev, 0x41, &fifo); |
| 658 | |
| 659 | /* Check for AMD7409 without swdma errata and if found adjust type */ |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 660 | if (type == 1 && pdev->revision > 0x7) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 661 | type = 2; |
| 662 | |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 663 | /* Serenade ? */ |
| 664 | if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD && |
| 665 | pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE) |
| 666 | type = 6; /* UDMA 100 only */ |
| 667 | |
| 668 | /* |
| 669 | * Okay, type is determined now. Apply type-specific workarounds. |
| 670 | */ |
| 671 | pi = info[type]; |
| 672 | |
| 673 | if (type < 3) |
| 674 | ata_pci_clear_simplex(pdev); |
| 675 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 676 | /* Check for AMD7411 */ |
| 677 | if (type == 3) |
| 678 | /* FIFO is broken */ |
| 679 | pci_write_config_byte(pdev, 0x41, fifo & 0x0F); |
| 680 | else |
| 681 | pci_write_config_byte(pdev, 0x41, fifo | 0xF0); |
| 682 | |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 683 | /* Cable detection on Nvidia chips doesn't work too well, |
| 684 | * cache BIOS programmed UDMA mode. |
| 685 | */ |
| 686 | if (type == 7 || type == 8) { |
| 687 | u32 udma; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 688 | |
Tejun Heo | ce54d16 | 2007-12-18 16:33:07 +0900 | [diff] [blame] | 689 | pci_read_config_dword(pdev, 0x60, &udma); |
| 690 | pi.private_data = (void *)(unsigned long)udma; |
| 691 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 692 | |
| 693 | /* And fire it up */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 694 | return ata_pci_init_one(pdev, ppi); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 695 | } |
| 696 | |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 697 | #ifdef CONFIG_PM |
Alan | c304193 | 2006-11-27 16:21:24 +0000 | [diff] [blame] | 698 | static int amd_reinit_one(struct pci_dev *pdev) |
| 699 | { |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 700 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
| 701 | int rc; |
| 702 | |
| 703 | rc = ata_pci_device_do_resume(pdev); |
| 704 | if (rc) |
| 705 | return rc; |
| 706 | |
Alan | c304193 | 2006-11-27 16:21:24 +0000 | [diff] [blame] | 707 | if (pdev->vendor == PCI_VENDOR_ID_AMD) { |
| 708 | u8 fifo; |
| 709 | pci_read_config_byte(pdev, 0x41, &fifo); |
| 710 | if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411) |
| 711 | /* FIFO is broken */ |
| 712 | pci_write_config_byte(pdev, 0x41, fifo & 0x0F); |
| 713 | else |
| 714 | pci_write_config_byte(pdev, 0x41, fifo | 0xF0); |
| 715 | if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 || |
| 716 | pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401) |
| 717 | ata_pci_clear_simplex(pdev); |
| 718 | } |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 719 | |
| 720 | ata_host_resume(host); |
| 721 | return 0; |
Alan | c304193 | 2006-11-27 16:21:24 +0000 | [diff] [blame] | 722 | } |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 723 | #endif |
Alan | c304193 | 2006-11-27 16:21:24 +0000 | [diff] [blame] | 724 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 725 | static const struct pci_device_id amd[] = { |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 726 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 }, |
| 727 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 }, |
| 728 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 3 }, |
| 729 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 4 }, |
| 730 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 5 }, |
| 731 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 7 }, |
| 732 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 8 }, |
| 733 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 8 }, |
| 734 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 8 }, |
| 735 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 8 }, |
| 736 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 }, |
| 737 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 }, |
| 738 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 }, |
| 739 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 }, |
| 740 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 }, |
Peer Chen | 05e2867 | 2006-11-02 17:58:21 -0500 | [diff] [blame] | 741 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 }, |
| 742 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 }, |
Peer Chen | 9f78975 | 2007-06-07 18:23:12 +0800 | [diff] [blame] | 743 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 8 }, |
| 744 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 8 }, |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 745 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 9 }, |
| 746 | |
| 747 | { }, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 748 | }; |
| 749 | |
| 750 | static struct pci_driver amd_pci_driver = { |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 751 | .name = DRV_NAME, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 752 | .id_table = amd, |
| 753 | .probe = amd_init_one, |
Alan | c304193 | 2006-11-27 16:21:24 +0000 | [diff] [blame] | 754 | .remove = ata_pci_remove_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 755 | #ifdef CONFIG_PM |
Alan | c304193 | 2006-11-27 16:21:24 +0000 | [diff] [blame] | 756 | .suspend = ata_pci_device_suspend, |
| 757 | .resume = amd_reinit_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 758 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 759 | }; |
| 760 | |
| 761 | static int __init amd_init(void) |
| 762 | { |
| 763 | return pci_register_driver(&amd_pci_driver); |
| 764 | } |
| 765 | |
| 766 | static void __exit amd_exit(void) |
| 767 | { |
| 768 | pci_unregister_driver(&amd_pci_driver); |
| 769 | } |
| 770 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 771 | MODULE_AUTHOR("Alan Cox"); |
Alan Cox | c9544bc | 2008-02-08 15:22:39 +0000 | [diff] [blame] | 772 | MODULE_DESCRIPTION("low-level driver for AMD and Nvidia PATA IDE"); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 773 | MODULE_LICENSE("GPL"); |
| 774 | MODULE_DEVICE_TABLE(pci, amd); |
| 775 | MODULE_VERSION(DRV_VERSION); |
| 776 | |
| 777 | module_init(amd_init); |
| 778 | module_exit(amd_exit); |