4 * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04
5 * IDE driver for Linux.
7 * Copyright (c) 2000-2002 Vojtech Pavlik
8 * Copyright (c) 2007 Bartlomiej Zolnierkiewicz
10 * Based on the work of:
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License version 2 as published by
17 * the Free Software Foundation.
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/ioport.h>
23 #include <linux/blkdev.h>
24 #include <linux/pci.h>
25 #include <linux/init.h>
26 #include <linux/ide.h>
29 #include "ide-timing.h"
32 AMD_IDE_CONFIG
= 0x41,
33 AMD_CABLE_DETECT
= 0x42,
34 AMD_DRIVE_TIMING
= 0x48,
35 AMD_8BIT_TIMING
= 0x4e,
36 AMD_ADDRESS_SETUP
= 0x4c,
37 AMD_UDMA_TIMING
= 0x50,
40 static unsigned int amd_80w
;
41 static unsigned int amd_clock
;
43 static char *amd_dma
[] = { "16", "25", "33", "44", "66", "100", "133" };
44 static unsigned char amd_cyc2udma
[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7 };
46 static inline u8
amd_offset(struct pci_dev
*dev
)
48 return (dev
->vendor
== PCI_VENDOR_ID_NVIDIA
) ? 0x10 : 0;
52 * amd_set_speed() writes timing values to the chipset registers
55 static void amd_set_speed(struct pci_dev
*dev
, u8 dn
, u8 udma_mask
,
56 struct ide_timing
*timing
)
58 u8 t
= 0, offset
= amd_offset(dev
);
60 pci_read_config_byte(dev
, AMD_ADDRESS_SETUP
+ offset
, &t
);
61 t
= (t
& ~(3 << ((3 - dn
) << 1))) | ((FIT(timing
->setup
, 1, 4) - 1) << ((3 - dn
) << 1));
62 pci_write_config_byte(dev
, AMD_ADDRESS_SETUP
+ offset
, t
);
64 pci_write_config_byte(dev
, AMD_8BIT_TIMING
+ offset
+ (1 - (dn
>> 1)),
65 ((FIT(timing
->act8b
, 1, 16) - 1) << 4) | (FIT(timing
->rec8b
, 1, 16) - 1));
67 pci_write_config_byte(dev
, AMD_DRIVE_TIMING
+ offset
+ (3 - dn
),
68 ((FIT(timing
->active
, 1, 16) - 1) << 4) | (FIT(timing
->recover
, 1, 16) - 1));
71 case ATA_UDMA2
: t
= timing
->udma
? (0xc0 | (FIT(timing
->udma
, 2, 5) - 2)) : 0x03; break;
72 case ATA_UDMA4
: t
= timing
->udma
? (0xc0 | amd_cyc2udma
[FIT(timing
->udma
, 2, 10)]) : 0x03; break;
73 case ATA_UDMA5
: t
= timing
->udma
? (0xc0 | amd_cyc2udma
[FIT(timing
->udma
, 1, 10)]) : 0x03; break;
74 case ATA_UDMA6
: t
= timing
->udma
? (0xc0 | amd_cyc2udma
[FIT(timing
->udma
, 1, 15)]) : 0x03; break;
78 pci_write_config_byte(dev
, AMD_UDMA_TIMING
+ offset
+ (3 - dn
), t
);
82 * amd_set_drive() computes timing values and configures the chipset
83 * to a desired transfer mode. It also can be called by upper layers.
86 static void amd_set_drive(ide_drive_t
*drive
, const u8 speed
)
88 ide_hwif_t
*hwif
= drive
->hwif
;
89 ide_drive_t
*peer
= hwif
->drives
+ (~drive
->dn
& 1);
90 struct ide_timing t
, p
;
92 u8 udma_mask
= hwif
->ultra_mask
;
94 T
= 1000000000 / amd_clock
;
95 UT
= (udma_mask
== ATA_UDMA2
) ? T
: (T
/ 2);
97 ide_timing_compute(drive
, speed
, &t
, T
, UT
);
100 ide_timing_compute(peer
, peer
->current_speed
, &p
, T
, UT
);
101 ide_timing_merge(&p
, &t
, &t
, IDE_TIMING_8BIT
);
104 if (speed
== XFER_UDMA_5
&& amd_clock
<= 33333) t
.udma
= 1;
105 if (speed
== XFER_UDMA_6
&& amd_clock
<= 33333) t
.udma
= 15;
107 amd_set_speed(hwif
->pci_dev
, drive
->dn
, udma_mask
, &t
);
111 * amd_set_pio_mode() is a callback from upper layers for PIO-only tuning.
114 static void amd_set_pio_mode(ide_drive_t
*drive
, const u8 pio
)
116 amd_set_drive(drive
, XFER_PIO_0
+ pio
);
119 static void __devinit
amd7409_cable_detect(struct pci_dev
*dev
,
122 /* no host side cable detection */
126 static void __devinit
amd7411_cable_detect(struct pci_dev
*dev
,
131 u8 t
= 0, offset
= amd_offset(dev
);
133 pci_read_config_byte(dev
, AMD_CABLE_DETECT
+ offset
, &t
);
134 pci_read_config_dword(dev
, AMD_UDMA_TIMING
+ offset
, &u
);
135 amd_80w
= ((t
& 0x3) ? 1 : 0) | ((t
& 0xc) ? 2 : 0);
136 for (i
= 24; i
>= 0; i
-= 8)
137 if (((u
>> i
) & 4) && !(amd_80w
& (1 << (1 - (i
>> 4))))) {
138 printk(KERN_WARNING
"%s: BIOS didn't set cable bits "
139 "correctly. Enabling workaround.\n",
141 amd_80w
|= (1 << (1 - (i
>> 4)));
146 * The initialization callback. Initialize drive independent registers.
149 static unsigned int __devinit
init_chipset_amd74xx(struct pci_dev
*dev
,
152 u8 t
= 0, offset
= amd_offset(dev
);
155 * Check 80-wire cable presence.
158 if (dev
->vendor
== PCI_VENDOR_ID_AMD
&&
159 dev
->device
== PCI_DEVICE_ID_AMD_COBRA_7401
)
161 else if (dev
->vendor
== PCI_VENDOR_ID_AMD
&&
162 dev
->device
== PCI_DEVICE_ID_AMD_VIPER_7409
)
163 amd7409_cable_detect(dev
, name
);
165 amd7411_cable_detect(dev
, name
);
168 * Take care of prefetch & postwrite.
171 pci_read_config_byte(dev
, AMD_IDE_CONFIG
+ offset
, &t
);
173 * Check for broken FIFO support.
175 if (dev
->vendor
== PCI_VENDOR_ID_AMD
&&
176 dev
->vendor
== PCI_DEVICE_ID_AMD_VIPER_7411
)
180 pci_write_config_byte(dev
, AMD_IDE_CONFIG
+ offset
, t
);
183 * Determine the system bus clock.
186 amd_clock
= system_bus_clock() * 1000;
189 case 33000: amd_clock
= 33333; break;
190 case 37000: amd_clock
= 37500; break;
191 case 41000: amd_clock
= 41666; break;
194 if (amd_clock
< 20000 || amd_clock
> 50000) {
195 printk(KERN_WARNING
"%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n",
203 static void __devinit
init_hwif_amd74xx(ide_hwif_t
*hwif
)
205 if (hwif
->irq
== 0) /* 0 is bogus but will do for now */
206 hwif
->irq
= pci_get_legacy_ide_irq(hwif
->pci_dev
, hwif
->channel
);
208 hwif
->set_pio_mode
= &amd_set_pio_mode
;
209 hwif
->set_dma_mode
= &amd_set_drive
;
214 if (hwif
->cbl
!= ATA_CBL_PATA40_SHORT
) {
215 if ((amd_80w
>> hwif
->channel
) & 1)
216 hwif
->cbl
= ATA_CBL_PATA80
;
218 hwif
->cbl
= ATA_CBL_PATA40
;
222 #define IDE_HFLAGS_AMD \
223 (IDE_HFLAG_PIO_NO_BLACKLIST | \
224 IDE_HFLAG_PIO_NO_DOWNGRADE | \
225 IDE_HFLAG_ABUSE_SET_DMA_MODE | \
226 IDE_HFLAG_POST_SET_MODE | \
227 IDE_HFLAG_IO_32BIT | \
228 IDE_HFLAG_UNMASK_IRQS | \
231 #define DECLARE_AMD_DEV(name_str, swdma, udma) \
234 .init_chipset = init_chipset_amd74xx, \
235 .init_hwif = init_hwif_amd74xx, \
236 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \
237 .host_flags = IDE_HFLAGS_AMD, \
238 .pio_mask = ATA_PIO5, \
239 .swdma_mask = swdma, \
240 .mwdma_mask = ATA_MWDMA2, \
244 #define DECLARE_NV_DEV(name_str, udma) \
247 .init_chipset = init_chipset_amd74xx, \
248 .init_hwif = init_hwif_amd74xx, \
249 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \
250 .host_flags = IDE_HFLAGS_AMD, \
251 .pio_mask = ATA_PIO5, \
252 .swdma_mask = ATA_SWDMA2, \
253 .mwdma_mask = ATA_MWDMA2, \
257 static const struct ide_port_info amd74xx_chipsets
[] __devinitdata
= {
258 /* 0 */ DECLARE_AMD_DEV("AMD7401", 0x00, ATA_UDMA2
),
259 /* 1 */ DECLARE_AMD_DEV("AMD7409", ATA_SWDMA2
, ATA_UDMA4
),
260 /* 2 */ DECLARE_AMD_DEV("AMD7411", ATA_SWDMA2
, ATA_UDMA5
),
261 /* 3 */ DECLARE_AMD_DEV("AMD7441", ATA_SWDMA2
, ATA_UDMA5
),
262 /* 4 */ DECLARE_AMD_DEV("AMD8111", ATA_SWDMA2
, ATA_UDMA6
),
264 /* 5 */ DECLARE_NV_DEV("NFORCE", ATA_UDMA5
),
265 /* 6 */ DECLARE_NV_DEV("NFORCE2", ATA_UDMA6
),
266 /* 7 */ DECLARE_NV_DEV("NFORCE2-U400R", ATA_UDMA6
),
267 /* 8 */ DECLARE_NV_DEV("NFORCE2-U400R-SATA", ATA_UDMA6
),
268 /* 9 */ DECLARE_NV_DEV("NFORCE3-150", ATA_UDMA6
),
269 /* 10 */ DECLARE_NV_DEV("NFORCE3-250", ATA_UDMA6
),
270 /* 11 */ DECLARE_NV_DEV("NFORCE3-250-SATA", ATA_UDMA6
),
271 /* 12 */ DECLARE_NV_DEV("NFORCE3-250-SATA2", ATA_UDMA6
),
272 /* 13 */ DECLARE_NV_DEV("NFORCE-CK804", ATA_UDMA6
),
273 /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04", ATA_UDMA6
),
274 /* 15 */ DECLARE_NV_DEV("NFORCE-MCP51", ATA_UDMA6
),
275 /* 16 */ DECLARE_NV_DEV("NFORCE-MCP55", ATA_UDMA6
),
276 /* 17 */ DECLARE_NV_DEV("NFORCE-MCP61", ATA_UDMA6
),
277 /* 18 */ DECLARE_NV_DEV("NFORCE-MCP65", ATA_UDMA6
),
278 /* 19 */ DECLARE_NV_DEV("NFORCE-MCP67", ATA_UDMA6
),
279 /* 20 */ DECLARE_NV_DEV("NFORCE-MCP73", ATA_UDMA6
),
280 /* 21 */ DECLARE_NV_DEV("NFORCE-MCP77", ATA_UDMA6
),
282 /* 22 */ DECLARE_AMD_DEV("AMD5536", ATA_SWDMA2
, ATA_UDMA5
),
285 static int __devinit
amd74xx_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
287 struct ide_port_info d
;
288 u8 idx
= id
->driver_data
;
290 d
= amd74xx_chipsets
[idx
];
293 * Check for bad SWDMA and incorrectly wired Serenade mainboards.
296 if (dev
->revision
<= 7)
298 d
.host_flags
|= IDE_HFLAG_CLEAR_SIMPLEX
;
299 } else if (idx
== 4) {
300 if (dev
->subsystem_vendor
== PCI_VENDOR_ID_AMD
&&
301 dev
->subsystem_device
== PCI_DEVICE_ID_AMD_SERENADE
)
302 d
.udma_mask
= ATA_UDMA5
;
305 printk(KERN_INFO
"%s: %s (rev %02x) UDMA%s controller\n",
306 d
.name
, pci_name(dev
), dev
->revision
,
307 amd_dma
[fls(d
.udma_mask
) - 1]);
309 return ide_setup_pci_device(dev
, &d
);
312 static const struct pci_device_id amd74xx_pci_tbl
[] = {
313 { PCI_VDEVICE(AMD
, PCI_DEVICE_ID_AMD_COBRA_7401
), 0 },
314 { PCI_VDEVICE(AMD
, PCI_DEVICE_ID_AMD_VIPER_7409
), 1 },
315 { PCI_VDEVICE(AMD
, PCI_DEVICE_ID_AMD_VIPER_7411
), 2 },
316 { PCI_VDEVICE(AMD
, PCI_DEVICE_ID_AMD_OPUS_7441
), 3 },
317 { PCI_VDEVICE(AMD
, PCI_DEVICE_ID_AMD_8111_IDE
), 4 },
318 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE
), 5 },
319 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE
), 6 },
320 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE
), 7 },
321 #ifdef CONFIG_BLK_DEV_IDE_SATA
322 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA
), 8 },
324 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE
), 9 },
325 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE
), 10 },
326 #ifdef CONFIG_BLK_DEV_IDE_SATA
327 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA
), 11 },
328 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2
), 12 },
330 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE
), 13 },
331 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE
), 14 },
332 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE
), 15 },
333 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE
), 16 },
334 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE
), 17 },
335 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE
), 18 },
336 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE
), 19 },
337 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE
), 20 },
338 { PCI_VDEVICE(NVIDIA
, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE
), 21 },
339 { PCI_VDEVICE(AMD
, PCI_DEVICE_ID_AMD_CS5536_IDE
), 22 },
342 MODULE_DEVICE_TABLE(pci
, amd74xx_pci_tbl
);
344 static struct pci_driver driver
= {
346 .id_table
= amd74xx_pci_tbl
,
347 .probe
= amd74xx_probe
,
350 static int __init
amd74xx_ide_init(void)
352 return ide_pci_register_driver(&driver
);
355 module_init(amd74xx_ide_init
);
357 MODULE_AUTHOR("Vojtech Pavlik");
358 MODULE_DESCRIPTION("AMD PCI IDE driver");
359 MODULE_LICENSE("GPL");