]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> |
3 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | |
075cb655 | 4 | * Copyright (C) 2007 MontaVista Software, Inc. |
328dcbb6 | 5 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz |
1da177e4 LT |
6 | * |
7 | * May be copied or modified under the terms of the GNU General Public License | |
8 | * | |
bf4c796d JG |
9 | * Documentation for CMD680: |
10 | * http://gkernel.sourceforge.net/specs/sii/sii-0680a-v1.31.pdf.bz2 | |
11 | * | |
12 | * Documentation for SiI 3112: | |
13 | * http://gkernel.sourceforge.net/specs/sii/3112A_SiI-DS-0095-B2.pdf.bz2 | |
14 | * | |
15 | * Errata and other documentation only available under NDA. | |
1da177e4 LT |
16 | * |
17 | * | |
18 | * FAQ Items: | |
19 | * If you are using Marvell SATA-IDE adapters with Maxtor drives | |
20 | * ensure the system is set up for ATA100/UDMA5 not UDMA6. | |
21 | * | |
22 | * If you are using WD drives with SATA bridges you must set the | |
23 | * drive to "Single". "Master" will hang | |
24 | * | |
25 | * If you have strange problems with nVidia chipset systems please | |
26 | * see the SI support documentation and update your system BIOS | |
3a4fa0a2 | 27 | * if necessary |
8693d3e4 AC |
28 | * |
29 | * The Dell DRAC4 has some interesting features including effectively hot | |
30 | * unplugging/replugging the virtual CD interface when the DRAC is reset. | |
31 | * This often causes drivers/ide/siimage to panic but is ok with the rather | |
32 | * smarter code in libata. | |
328dcbb6 BZ |
33 | * |
34 | * TODO: | |
35 | * - IORDY fixes | |
36 | * - VDMA support | |
1da177e4 LT |
37 | */ |
38 | ||
1da177e4 LT |
39 | #include <linux/types.h> |
40 | #include <linux/module.h> | |
41 | #include <linux/pci.h> | |
1da177e4 LT |
42 | #include <linux/hdreg.h> |
43 | #include <linux/ide.h> | |
44 | #include <linux/init.h> | |
45 | ||
46 | #include <asm/io.h> | |
47 | ||
1da177e4 LT |
48 | /** |
49 | * pdev_is_sata - check if device is SATA | |
50 | * @pdev: PCI device to check | |
51 | * | |
52 | * Returns true if this is a SATA controller | |
53 | */ | |
54 | ||
55 | static int pdev_is_sata(struct pci_dev *pdev) | |
56 | { | |
438c4702 BZ |
57 | #ifdef CONFIG_BLK_DEV_IDE_SATA |
58 | switch(pdev->device) { | |
1da177e4 LT |
59 | case PCI_DEVICE_ID_SII_3112: |
60 | case PCI_DEVICE_ID_SII_1210SA: | |
61 | return 1; | |
62 | case PCI_DEVICE_ID_SII_680: | |
63 | return 0; | |
64 | } | |
65 | BUG(); | |
438c4702 | 66 | #endif |
1da177e4 LT |
67 | return 0; |
68 | } | |
438c4702 | 69 | |
1da177e4 LT |
70 | /** |
71 | * is_sata - check if hwif is SATA | |
72 | * @hwif: interface to check | |
73 | * | |
74 | * Returns true if this is a SATA controller | |
75 | */ | |
76 | ||
77 | static inline int is_sata(ide_hwif_t *hwif) | |
78 | { | |
36501650 | 79 | return pdev_is_sata(to_pci_dev(hwif->dev)); |
1da177e4 LT |
80 | } |
81 | ||
82 | /** | |
83 | * siimage_selreg - return register base | |
84 | * @hwif: interface | |
85 | * @r: config offset | |
86 | * | |
87 | * Turn a config register offset into the right address in either | |
88 | * PCI space or MMIO space to access the control register in question | |
89 | * Thankfully this is a configuration operation so isnt performance | |
90 | * criticial. | |
91 | */ | |
92 | ||
93 | static unsigned long siimage_selreg(ide_hwif_t *hwif, int r) | |
94 | { | |
95 | unsigned long base = (unsigned long)hwif->hwif_data; | |
96 | base += 0xA0 + r; | |
97 | if(hwif->mmio) | |
98 | base += (hwif->channel << 6); | |
99 | else | |
100 | base += (hwif->channel << 4); | |
101 | return base; | |
102 | } | |
103 | ||
104 | /** | |
105 | * siimage_seldev - return register base | |
106 | * @hwif: interface | |
107 | * @r: config offset | |
108 | * | |
109 | * Turn a config register offset into the right address in either | |
110 | * PCI space or MMIO space to access the control register in question | |
111 | * including accounting for the unit shift. | |
112 | */ | |
113 | ||
114 | static inline unsigned long siimage_seldev(ide_drive_t *drive, int r) | |
115 | { | |
116 | ide_hwif_t *hwif = HWIF(drive); | |
117 | unsigned long base = (unsigned long)hwif->hwif_data; | |
118 | base += 0xA0 + r; | |
119 | if(hwif->mmio) | |
120 | base += (hwif->channel << 6); | |
121 | else | |
122 | base += (hwif->channel << 4); | |
123 | base |= drive->select.b.unit << drive->select.b.unit; | |
124 | return base; | |
125 | } | |
126 | ||
127 | /** | |
2d5eaa6d BZ |
128 | * sil_udma_filter - compute UDMA mask |
129 | * @drive: IDE device | |
130 | * | |
131 | * Compute the available UDMA speeds for the device on the interface. | |
1da177e4 | 132 | * |
1da177e4 | 133 | * For the CMD680 this depends on the clocking mode (scsc), for the |
2d5eaa6d | 134 | * SI3112 SATA controller life is a bit simpler. |
1da177e4 | 135 | */ |
2d5eaa6d | 136 | |
438c4702 | 137 | static u8 sil_pata_udma_filter(ide_drive_t *drive) |
1da177e4 | 138 | { |
2d5eaa6d | 139 | ide_hwif_t *hwif = drive->hwif; |
36501650 | 140 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1da177e4 | 141 | unsigned long base = (unsigned long) hwif->hwif_data; |
2d5eaa6d | 142 | u8 mask = 0, scsc = 0; |
1da177e4 LT |
143 | |
144 | if (hwif->mmio) | |
145 | scsc = hwif->INB(base + 0x4A); | |
146 | else | |
36501650 | 147 | pci_read_config_byte(dev, 0x8A, &scsc); |
1da177e4 | 148 | |
1da177e4 | 149 | if ((scsc & 0x30) == 0x10) /* 133 */ |
438c4702 | 150 | mask = ATA_UDMA6; |
1da177e4 | 151 | else if ((scsc & 0x30) == 0x20) /* 2xPCI */ |
438c4702 | 152 | mask = ATA_UDMA6; |
1da177e4 | 153 | else if ((scsc & 0x30) == 0x00) /* 100 */ |
438c4702 | 154 | mask = ATA_UDMA5; |
1da177e4 LT |
155 | else /* Disabled ? */ |
156 | BUG(); | |
438c4702 | 157 | |
2d5eaa6d | 158 | return mask; |
1da177e4 LT |
159 | } |
160 | ||
438c4702 BZ |
161 | static u8 sil_sata_udma_filter(ide_drive_t *drive) |
162 | { | |
163 | return strstr(drive->id->model, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6; | |
164 | } | |
165 | ||
1da177e4 | 166 | /** |
88b2b32b BZ |
167 | * sil_set_pio_mode - set host controller for PIO mode |
168 | * @drive: drive | |
169 | * @pio: PIO mode number | |
1da177e4 LT |
170 | * |
171 | * Load the timing settings for this device mode into the | |
172 | * controller. If we are in PIO mode 3 or 4 turn on IORDY | |
173 | * monitoring (bit 9). The TF timing is bits 31:16 | |
174 | */ | |
328dcbb6 | 175 | |
88b2b32b | 176 | static void sil_set_pio_mode(ide_drive_t *drive, u8 pio) |
1da177e4 | 177 | { |
328dcbb6 BZ |
178 | const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 }; |
179 | const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 }; | |
180 | ||
1da177e4 | 181 | ide_hwif_t *hwif = HWIF(drive); |
a87a87cc | 182 | ide_drive_t *pair = ide_get_paired_drive(drive); |
1da177e4 LT |
183 | u32 speedt = 0; |
184 | u16 speedp = 0; | |
185 | unsigned long addr = siimage_seldev(drive, 0x04); | |
186 | unsigned long tfaddr = siimage_selreg(hwif, 0x02); | |
ffe5415c | 187 | unsigned long base = (unsigned long)hwif->hwif_data; |
328dcbb6 | 188 | u8 tf_pio = pio; |
ffe5415c BZ |
189 | u8 addr_mask = hwif->channel ? (hwif->mmio ? 0xF4 : 0x84) |
190 | : (hwif->mmio ? 0xB4 : 0x80); | |
191 | u8 mode = 0; | |
192 | u8 unit = drive->select.b.unit; | |
328dcbb6 BZ |
193 | |
194 | /* trim *taskfile* PIO to the slowest of the master/slave */ | |
195 | if (pair->present) { | |
2134758d | 196 | u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4); |
328dcbb6 BZ |
197 | |
198 | if (pair_pio < tf_pio) | |
199 | tf_pio = pair_pio; | |
1da177e4 | 200 | } |
075cb655 | 201 | |
328dcbb6 BZ |
202 | /* cheat for now and use the docs */ |
203 | speedp = data_speed[pio]; | |
204 | speedt = tf_speed[tf_pio]; | |
205 | ||
075cb655 SS |
206 | if (hwif->mmio) { |
207 | hwif->OUTW(speedp, addr); | |
208 | hwif->OUTW(speedt, tfaddr); | |
1da177e4 | 209 | /* Now set up IORDY */ |
328dcbb6 | 210 | if (pio > 2) |
1da177e4 LT |
211 | hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); |
212 | else | |
213 | hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); | |
ffe5415c BZ |
214 | |
215 | mode = hwif->INB(base + addr_mask); | |
216 | mode &= ~(unit ? 0x30 : 0x03); | |
217 | mode |= (unit ? 0x10 : 0x01); | |
218 | hwif->OUTB(mode, base + addr_mask); | |
075cb655 | 219 | } else { |
36501650 BZ |
220 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
221 | ||
222 | pci_write_config_word(dev, addr, speedp); | |
223 | pci_write_config_word(dev, tfaddr, speedt); | |
224 | pci_read_config_word(dev, tfaddr - 2, &speedp); | |
1da177e4 LT |
225 | speedp &= ~0x200; |
226 | /* Set IORDY for mode 3 or 4 */ | |
328dcbb6 | 227 | if (pio > 2) |
1da177e4 | 228 | speedp |= 0x200; |
36501650 | 229 | pci_write_config_word(dev, tfaddr - 2, speedp); |
ffe5415c | 230 | |
36501650 | 231 | pci_read_config_byte(dev, addr_mask, &mode); |
ffe5415c BZ |
232 | mode &= ~(unit ? 0x30 : 0x03); |
233 | mode |= (unit ? 0x10 : 0x01); | |
36501650 | 234 | pci_write_config_byte(dev, addr_mask, mode); |
1da177e4 LT |
235 | } |
236 | } | |
237 | ||
1da177e4 | 238 | /** |
88b2b32b BZ |
239 | * sil_set_dma_mode - set host controller for DMA mode |
240 | * @drive: drive | |
241 | * @speed: DMA mode | |
1da177e4 | 242 | * |
88b2b32b | 243 | * Tune the SiI chipset for the desired DMA mode. |
1da177e4 | 244 | */ |
f212ff28 | 245 | |
88b2b32b | 246 | static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed) |
1da177e4 LT |
247 | { |
248 | u8 ultra6[] = { 0x0F, 0x0B, 0x07, 0x05, 0x03, 0x02, 0x01 }; | |
249 | u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 }; | |
250 | u16 dma[] = { 0x2208, 0x10C2, 0x10C1 }; | |
251 | ||
252 | ide_hwif_t *hwif = HWIF(drive); | |
36501650 | 253 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1da177e4 LT |
254 | u16 ultra = 0, multi = 0; |
255 | u8 mode = 0, unit = drive->select.b.unit; | |
1da177e4 LT |
256 | unsigned long base = (unsigned long)hwif->hwif_data; |
257 | u8 scsc = 0, addr_mask = ((hwif->channel) ? | |
258 | ((hwif->mmio) ? 0xF4 : 0x84) : | |
259 | ((hwif->mmio) ? 0xB4 : 0x80)); | |
260 | ||
261 | unsigned long ma = siimage_seldev(drive, 0x08); | |
262 | unsigned long ua = siimage_seldev(drive, 0x0C); | |
263 | ||
264 | if (hwif->mmio) { | |
265 | scsc = hwif->INB(base + 0x4A); | |
266 | mode = hwif->INB(base + addr_mask); | |
267 | multi = hwif->INW(ma); | |
268 | ultra = hwif->INW(ua); | |
269 | } else { | |
36501650 BZ |
270 | pci_read_config_byte(dev, 0x8A, &scsc); |
271 | pci_read_config_byte(dev, addr_mask, &mode); | |
272 | pci_read_config_word(dev, ma, &multi); | |
273 | pci_read_config_word(dev, ua, &ultra); | |
1da177e4 LT |
274 | } |
275 | ||
276 | mode &= ~((unit) ? 0x30 : 0x03); | |
277 | ultra &= ~0x3F; | |
278 | scsc = ((scsc & 0x30) == 0x00) ? 0 : 1; | |
279 | ||
280 | scsc = is_sata(hwif) ? 1 : scsc; | |
281 | ||
4db90a14 BZ |
282 | if (speed >= XFER_UDMA_0) { |
283 | multi = dma[2]; | |
284 | ultra |= (scsc ? ultra6[speed - XFER_UDMA_0] : | |
285 | ultra5[speed - XFER_UDMA_0]); | |
286 | mode |= (unit ? 0x30 : 0x03); | |
287 | } else { | |
288 | multi = dma[speed - XFER_MW_DMA_0]; | |
289 | mode |= (unit ? 0x20 : 0x02); | |
1da177e4 LT |
290 | } |
291 | ||
292 | if (hwif->mmio) { | |
293 | hwif->OUTB(mode, base + addr_mask); | |
294 | hwif->OUTW(multi, ma); | |
295 | hwif->OUTW(ultra, ua); | |
296 | } else { | |
36501650 BZ |
297 | pci_write_config_byte(dev, addr_mask, mode); |
298 | pci_write_config_word(dev, ma, multi); | |
299 | pci_write_config_word(dev, ua, ultra); | |
1da177e4 | 300 | } |
1da177e4 LT |
301 | } |
302 | ||
1da177e4 LT |
303 | /* returns 1 if dma irq issued, 0 otherwise */ |
304 | static int siimage_io_ide_dma_test_irq (ide_drive_t *drive) | |
305 | { | |
306 | ide_hwif_t *hwif = HWIF(drive); | |
36501650 | 307 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1da177e4 LT |
308 | u8 dma_altstat = 0; |
309 | unsigned long addr = siimage_selreg(hwif, 1); | |
310 | ||
311 | /* return 1 if INTR asserted */ | |
312 | if ((hwif->INB(hwif->dma_status) & 4) == 4) | |
313 | return 1; | |
314 | ||
315 | /* return 1 if Device INTR asserted */ | |
36501650 | 316 | pci_read_config_byte(dev, addr, &dma_altstat); |
1da177e4 LT |
317 | if (dma_altstat & 8) |
318 | return 0; //return 1; | |
319 | return 0; | |
320 | } | |
321 | ||
1da177e4 LT |
322 | /** |
323 | * siimage_mmio_ide_dma_test_irq - check we caused an IRQ | |
324 | * @drive: drive we are testing | |
325 | * | |
326 | * Check if we caused an IDE DMA interrupt. We may also have caused | |
327 | * SATA status interrupts, if so we clean them up and continue. | |
328 | */ | |
329 | ||
330 | static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive) | |
331 | { | |
332 | ide_hwif_t *hwif = HWIF(drive); | |
1da177e4 | 333 | unsigned long addr = siimage_selreg(hwif, 0x1); |
835457de BZ |
334 | void __iomem *sata_error_addr |
335 | = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET]; | |
1da177e4 | 336 | |
835457de | 337 | if (sata_error_addr) { |
438c4702 | 338 | unsigned long base = (unsigned long)hwif->hwif_data; |
0ecdca26 | 339 | u32 ext_stat = readl((void __iomem *)(base + 0x10)); |
1da177e4 | 340 | u8 watchdog = 0; |
835457de | 341 | |
1da177e4 | 342 | if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) { |
835457de BZ |
343 | u32 sata_error = readl(sata_error_addr); |
344 | ||
345 | writel(sata_error, sata_error_addr); | |
1da177e4 | 346 | watchdog = (sata_error & 0x00680000) ? 1 : 0; |
1da177e4 LT |
347 | printk(KERN_WARNING "%s: sata_error = 0x%08x, " |
348 | "watchdog = %d, %s\n", | |
349 | drive->name, sata_error, watchdog, | |
350 | __FUNCTION__); | |
1da177e4 LT |
351 | |
352 | } else { | |
353 | watchdog = (ext_stat & 0x8000) ? 1 : 0; | |
354 | } | |
355 | ext_stat >>= 16; | |
356 | ||
357 | if (!(ext_stat & 0x0404) && !watchdog) | |
358 | return 0; | |
359 | } | |
360 | ||
361 | /* return 1 if INTR asserted */ | |
0ecdca26 | 362 | if ((readb((void __iomem *)hwif->dma_status) & 0x04) == 0x04) |
1da177e4 LT |
363 | return 1; |
364 | ||
365 | /* return 1 if Device INTR asserted */ | |
0ecdca26 | 366 | if ((readb((void __iomem *)addr) & 8) == 8) |
1da177e4 LT |
367 | return 0; //return 1; |
368 | ||
369 | return 0; | |
370 | } | |
371 | ||
1da177e4 | 372 | /** |
438c4702 | 373 | * sil_sata_reset_poll - wait for SATA reset |
1da177e4 LT |
374 | * @drive: drive we are resetting |
375 | * | |
376 | * Poll the SATA phy and see whether it has come back from the dead | |
377 | * yet. | |
378 | */ | |
438c4702 BZ |
379 | |
380 | static int sil_sata_reset_poll(ide_drive_t *drive) | |
1da177e4 | 381 | { |
835457de BZ |
382 | ide_hwif_t *hwif = drive->hwif; |
383 | void __iomem *sata_status_addr | |
384 | = (void __iomem *)hwif->sata_scr[SATA_STATUS_OFFSET]; | |
385 | ||
386 | if (sata_status_addr) { | |
387 | /* SATA Status is available only when in MMIO mode */ | |
388 | u32 sata_stat = readl(sata_status_addr); | |
1da177e4 | 389 | |
835457de | 390 | if ((sata_stat & 0x03) != 0x03) { |
1da177e4 | 391 | printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", |
835457de | 392 | hwif->name, sata_stat); |
1da177e4 LT |
393 | HWGROUP(drive)->polling = 0; |
394 | return ide_started; | |
395 | } | |
1da177e4 | 396 | } |
438c4702 BZ |
397 | |
398 | return 0; | |
1da177e4 LT |
399 | } |
400 | ||
401 | /** | |
438c4702 | 402 | * sil_sata_pre_reset - reset hook |
1da177e4 LT |
403 | * @drive: IDE device being reset |
404 | * | |
405 | * For the SATA devices we need to handle recalibration/geometry | |
406 | * differently | |
407 | */ | |
1da177e4 | 408 | |
438c4702 BZ |
409 | static void sil_sata_pre_reset(ide_drive_t *drive) |
410 | { | |
411 | if (drive->media == ide_disk) { | |
1da177e4 LT |
412 | drive->special.b.set_geometry = 0; |
413 | drive->special.b.recalibrate = 0; | |
414 | } | |
415 | } | |
416 | ||
1da177e4 LT |
417 | /** |
418 | * proc_reports_siimage - add siimage controller to proc | |
419 | * @dev: PCI device | |
420 | * @clocking: SCSC value | |
421 | * @name: controller name | |
422 | * | |
423 | * Report the clocking mode of the controller and add it to | |
424 | * the /proc interface layer | |
425 | */ | |
426 | ||
427 | static void proc_reports_siimage (struct pci_dev *dev, u8 clocking, const char *name) | |
428 | { | |
429 | if (!pdev_is_sata(dev)) { | |
430 | printk(KERN_INFO "%s: BASE CLOCK ", name); | |
431 | clocking &= 0x03; | |
432 | switch (clocking) { | |
433 | case 0x03: printk("DISABLED!\n"); break; | |
434 | case 0x02: printk("== 2X PCI\n"); break; | |
435 | case 0x01: printk("== 133\n"); break; | |
436 | case 0x00: printk("== 100\n"); break; | |
437 | } | |
438 | } | |
439 | } | |
440 | ||
441 | /** | |
442 | * setup_mmio_siimage - switch an SI controller into MMIO | |
443 | * @dev: PCI device we are configuring | |
444 | * @name: device name | |
445 | * | |
446 | * Attempt to put the device into mmio mode. There are some slight | |
447 | * complications here with certain systems where the mmio bar isnt | |
448 | * mapped so we have to be sure we can fall back to I/O. | |
449 | */ | |
450 | ||
451 | static unsigned int setup_mmio_siimage (struct pci_dev *dev, const char *name) | |
452 | { | |
c976816b | 453 | resource_size_t bar5 = pci_resource_start(dev, 5); |
1da177e4 LT |
454 | unsigned long barsize = pci_resource_len(dev, 5); |
455 | u8 tmpbyte = 0; | |
456 | void __iomem *ioaddr; | |
d868dd19 | 457 | u32 tmp, irq_mask; |
1da177e4 LT |
458 | |
459 | /* | |
460 | * Drop back to PIO if we can't map the mmio. Some | |
461 | * systems seem to get terminally confused in the PCI | |
462 | * spaces. | |
463 | */ | |
464 | ||
465 | if(!request_mem_region(bar5, barsize, name)) | |
466 | { | |
467 | printk(KERN_WARNING "siimage: IDE controller MMIO ports not available.\n"); | |
468 | return 0; | |
469 | } | |
470 | ||
471 | ioaddr = ioremap(bar5, barsize); | |
472 | ||
473 | if (ioaddr == NULL) | |
474 | { | |
475 | release_mem_region(bar5, barsize); | |
476 | return 0; | |
477 | } | |
478 | ||
479 | pci_set_master(dev); | |
480 | pci_set_drvdata(dev, (void *) ioaddr); | |
481 | ||
482 | if (pdev_is_sata(dev)) { | |
d868dd19 JL |
483 | /* make sure IDE0/1 interrupts are not masked */ |
484 | irq_mask = (1 << 22) | (1 << 23); | |
485 | tmp = readl(ioaddr + 0x48); | |
486 | if (tmp & irq_mask) { | |
487 | tmp &= ~irq_mask; | |
488 | writel(tmp, ioaddr + 0x48); | |
489 | readl(ioaddr + 0x48); /* flush */ | |
490 | } | |
1da177e4 LT |
491 | writel(0, ioaddr + 0x148); |
492 | writel(0, ioaddr + 0x1C8); | |
493 | } | |
494 | ||
495 | writeb(0, ioaddr + 0xB4); | |
496 | writeb(0, ioaddr + 0xF4); | |
497 | tmpbyte = readb(ioaddr + 0x4A); | |
498 | ||
499 | switch(tmpbyte & 0x30) { | |
500 | case 0x00: | |
501 | /* In 100 MHz clocking, try and switch to 133 */ | |
502 | writeb(tmpbyte|0x10, ioaddr + 0x4A); | |
503 | break; | |
504 | case 0x10: | |
505 | /* On 133Mhz clocking */ | |
506 | break; | |
507 | case 0x20: | |
508 | /* On PCIx2 clocking */ | |
509 | break; | |
510 | case 0x30: | |
511 | /* Clocking is disabled */ | |
512 | /* 133 clock attempt to force it on */ | |
513 | writeb(tmpbyte & ~0x20, ioaddr + 0x4A); | |
514 | break; | |
515 | } | |
516 | ||
517 | writeb( 0x72, ioaddr + 0xA1); | |
518 | writew( 0x328A, ioaddr + 0xA2); | |
519 | writel(0x62DD62DD, ioaddr + 0xA4); | |
520 | writel(0x43924392, ioaddr + 0xA8); | |
521 | writel(0x40094009, ioaddr + 0xAC); | |
522 | writeb( 0x72, ioaddr + 0xE1); | |
523 | writew( 0x328A, ioaddr + 0xE2); | |
524 | writel(0x62DD62DD, ioaddr + 0xE4); | |
525 | writel(0x43924392, ioaddr + 0xE8); | |
526 | writel(0x40094009, ioaddr + 0xEC); | |
527 | ||
528 | if (pdev_is_sata(dev)) { | |
529 | writel(0xFFFF0000, ioaddr + 0x108); | |
530 | writel(0xFFFF0000, ioaddr + 0x188); | |
531 | writel(0x00680000, ioaddr + 0x148); | |
532 | writel(0x00680000, ioaddr + 0x1C8); | |
533 | } | |
534 | ||
535 | tmpbyte = readb(ioaddr + 0x4A); | |
536 | ||
537 | proc_reports_siimage(dev, (tmpbyte>>4), name); | |
538 | return 1; | |
539 | } | |
540 | ||
541 | /** | |
542 | * init_chipset_siimage - set up an SI device | |
543 | * @dev: PCI device | |
544 | * @name: device name | |
545 | * | |
546 | * Perform the initial PCI set up for this device. Attempt to switch | |
547 | * to 133MHz clocking if the system isn't already set up to do it. | |
548 | */ | |
549 | ||
550 | static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev, const char *name) | |
551 | { | |
fc212bb1 | 552 | u8 rev = dev->revision, tmpbyte = 0, BA5_EN = 0; |
1da177e4 | 553 | |
fc212bb1 | 554 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, rev ? 1 : 255); |
1da177e4 LT |
555 | |
556 | pci_read_config_byte(dev, 0x8A, &BA5_EN); | |
557 | if ((BA5_EN & 0x01) || (pci_resource_start(dev, 5))) { | |
558 | if (setup_mmio_siimage(dev, name)) { | |
559 | return 0; | |
560 | } | |
561 | } | |
562 | ||
563 | pci_write_config_byte(dev, 0x80, 0x00); | |
564 | pci_write_config_byte(dev, 0x84, 0x00); | |
565 | pci_read_config_byte(dev, 0x8A, &tmpbyte); | |
566 | switch(tmpbyte & 0x30) { | |
567 | case 0x00: | |
568 | /* 133 clock attempt to force it on */ | |
569 | pci_write_config_byte(dev, 0x8A, tmpbyte|0x10); | |
570 | case 0x30: | |
571 | /* if clocking is disabled */ | |
572 | /* 133 clock attempt to force it on */ | |
573 | pci_write_config_byte(dev, 0x8A, tmpbyte & ~0x20); | |
574 | case 0x10: | |
575 | /* 133 already */ | |
576 | break; | |
577 | case 0x20: | |
578 | /* BIOS set PCI x2 clocking */ | |
579 | break; | |
580 | } | |
581 | ||
582 | pci_read_config_byte(dev, 0x8A, &tmpbyte); | |
583 | ||
584 | pci_write_config_byte(dev, 0xA1, 0x72); | |
585 | pci_write_config_word(dev, 0xA2, 0x328A); | |
586 | pci_write_config_dword(dev, 0xA4, 0x62DD62DD); | |
587 | pci_write_config_dword(dev, 0xA8, 0x43924392); | |
588 | pci_write_config_dword(dev, 0xAC, 0x40094009); | |
589 | pci_write_config_byte(dev, 0xB1, 0x72); | |
590 | pci_write_config_word(dev, 0xB2, 0x328A); | |
591 | pci_write_config_dword(dev, 0xB4, 0x62DD62DD); | |
592 | pci_write_config_dword(dev, 0xB8, 0x43924392); | |
593 | pci_write_config_dword(dev, 0xBC, 0x40094009); | |
594 | ||
595 | proc_reports_siimage(dev, (tmpbyte>>4), name); | |
596 | return 0; | |
597 | } | |
598 | ||
599 | /** | |
600 | * init_mmio_iops_siimage - set up the iops for MMIO | |
601 | * @hwif: interface to set up | |
602 | * | |
603 | * The basic setup here is fairly simple, we can use standard MMIO | |
604 | * operations. However we do have to set the taskfile register offsets | |
605 | * by hand as there isnt a standard defined layout for them this | |
606 | * time. | |
607 | * | |
608 | * The hardware supports buffered taskfiles and also some rather nice | |
19c1ef5f | 609 | * extended PRD tables. For better SI3112 support use the libata driver |
1da177e4 LT |
610 | */ |
611 | ||
612 | static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif) | |
613 | { | |
36501650 | 614 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1da177e4 LT |
615 | void *addr = pci_get_drvdata(dev); |
616 | u8 ch = hwif->channel; | |
617 | hw_regs_t hw; | |
618 | unsigned long base; | |
619 | ||
620 | /* | |
621 | * Fill in the basic HWIF bits | |
622 | */ | |
623 | ||
624 | default_hwif_mmiops(hwif); | |
625 | hwif->hwif_data = addr; | |
626 | ||
627 | /* | |
628 | * Now set up the hw. We have to do this ourselves as | |
59c51591 | 629 | * the MMIO layout isnt the same as the standard port |
1da177e4 LT |
630 | * based I/O |
631 | */ | |
632 | ||
633 | memset(&hw, 0, sizeof(hw_regs_t)); | |
634 | ||
635 | base = (unsigned long)addr; | |
636 | if (ch) | |
637 | base += 0xC0; | |
638 | else | |
639 | base += 0x80; | |
640 | ||
641 | /* | |
642 | * The buffered task file doesn't have status/control | |
643 | * so we can't currently use it sanely since we want to | |
644 | * use LBA48 mode. | |
645 | */ | |
1da177e4 LT |
646 | hw.io_ports[IDE_DATA_OFFSET] = base; |
647 | hw.io_ports[IDE_ERROR_OFFSET] = base + 1; | |
648 | hw.io_ports[IDE_NSECTOR_OFFSET] = base + 2; | |
649 | hw.io_ports[IDE_SECTOR_OFFSET] = base + 3; | |
650 | hw.io_ports[IDE_LCYL_OFFSET] = base + 4; | |
651 | hw.io_ports[IDE_HCYL_OFFSET] = base + 5; | |
652 | hw.io_ports[IDE_SELECT_OFFSET] = base + 6; | |
653 | hw.io_ports[IDE_STATUS_OFFSET] = base + 7; | |
654 | hw.io_ports[IDE_CONTROL_OFFSET] = base + 10; | |
655 | ||
656 | hw.io_ports[IDE_IRQ_OFFSET] = 0; | |
657 | ||
658 | if (pdev_is_sata(dev)) { | |
659 | base = (unsigned long)addr; | |
660 | if (ch) | |
661 | base += 0x80; | |
662 | hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104; | |
663 | hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108; | |
664 | hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100; | |
1da177e4 LT |
665 | } |
666 | ||
9239b333 | 667 | memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports)); |
1da177e4 | 668 | |
9239b333 | 669 | hwif->irq = dev->irq; |
1da177e4 | 670 | |
9239b333 | 671 | hwif->dma_base = (unsigned long)addr + (ch ? 0x08 : 0x00); |
2ad1e558 BZ |
672 | |
673 | hwif->mmio = 1; | |
1da177e4 LT |
674 | } |
675 | ||
676 | static int is_dev_seagate_sata(ide_drive_t *drive) | |
677 | { | |
678 | const char *s = &drive->id->model[0]; | |
679 | unsigned len; | |
680 | ||
1da177e4 LT |
681 | len = strnlen(s, sizeof(drive->id->model)); |
682 | ||
683 | if ((len > 4) && (!memcmp(s, "ST", 2))) { | |
684 | if ((!memcmp(s + len - 2, "AS", 2)) || | |
685 | (!memcmp(s + len - 3, "ASL", 3))) { | |
686 | printk(KERN_INFO "%s: applying pessimistic Seagate " | |
687 | "errata fix\n", drive->name); | |
688 | return 1; | |
689 | } | |
690 | } | |
691 | return 0; | |
692 | } | |
693 | ||
694 | /** | |
f01393e4 BZ |
695 | * sil_quirkproc - post probe fixups |
696 | * @drive: drive | |
1da177e4 LT |
697 | * |
698 | * Called after drive probe we use this to decide whether the | |
699 | * Seagate fixup must be applied. This used to be in init_iops but | |
700 | * that can occur before we know what drives are present. | |
701 | */ | |
702 | ||
f01393e4 | 703 | static void __devinit sil_quirkproc(ide_drive_t *drive) |
1da177e4 | 704 | { |
f01393e4 BZ |
705 | ide_hwif_t *hwif = drive->hwif; |
706 | ||
1da177e4 | 707 | /* Try and raise the rqsize */ |
f01393e4 | 708 | if (!is_sata(hwif) || !is_dev_seagate_sata(drive)) |
1da177e4 LT |
709 | hwif->rqsize = 128; |
710 | } | |
711 | ||
712 | /** | |
713 | * init_iops_siimage - set up iops | |
714 | * @hwif: interface to set up | |
715 | * | |
716 | * Do the basic setup for the SIIMAGE hardware interface | |
717 | * and then do the MMIO setup if we can. This is the first | |
718 | * look in we get for setting up the hwif so that we | |
719 | * can get the iops right before using them. | |
720 | */ | |
721 | ||
722 | static void __devinit init_iops_siimage(ide_hwif_t *hwif) | |
723 | { | |
36501650 BZ |
724 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
725 | ||
1da177e4 LT |
726 | hwif->hwif_data = NULL; |
727 | ||
728 | /* Pessimal until we finish probing */ | |
729 | hwif->rqsize = 15; | |
730 | ||
36501650 | 731 | if (pci_get_drvdata(dev) == NULL) |
1da177e4 | 732 | return; |
fc212bb1 | 733 | |
1da177e4 LT |
734 | init_mmio_iops_siimage(hwif); |
735 | } | |
736 | ||
737 | /** | |
738 | * ata66_siimage - check for 80 pin cable | |
739 | * @hwif: interface to check | |
740 | * | |
741 | * Check for the presence of an ATA66 capable cable on the | |
742 | * interface. | |
743 | */ | |
744 | ||
49521f97 | 745 | static u8 __devinit ata66_siimage(ide_hwif_t *hwif) |
1da177e4 | 746 | { |
36501650 | 747 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1da177e4 | 748 | unsigned long addr = siimage_selreg(hwif, 0); |
49521f97 BZ |
749 | u8 ata66 = 0; |
750 | ||
36501650 BZ |
751 | if (pci_get_drvdata(dev) == NULL) |
752 | pci_read_config_byte(dev, addr, &ata66); | |
49521f97 BZ |
753 | else |
754 | ata66 = hwif->INB(addr); | |
1da177e4 | 755 | |
49521f97 | 756 | return (ata66 & 0x01) ? ATA_CBL_PATA80 : ATA_CBL_PATA40; |
1da177e4 LT |
757 | } |
758 | ||
759 | /** | |
760 | * init_hwif_siimage - set up hwif structs | |
761 | * @hwif: interface to set up | |
762 | * | |
763 | * We do the basic set up of the interface structure. The SIIMAGE | |
764 | * requires several custom handlers so we override the default | |
765 | * ide DMA handlers appropriately | |
766 | */ | |
767 | ||
768 | static void __devinit init_hwif_siimage(ide_hwif_t *hwif) | |
769 | { | |
438c4702 BZ |
770 | u8 sata = is_sata(hwif); |
771 | ||
26bcb879 | 772 | hwif->set_pio_mode = &sil_set_pio_mode; |
88b2b32b | 773 | hwif->set_dma_mode = &sil_set_dma_mode; |
f01393e4 | 774 | hwif->quirkproc = &sil_quirkproc; |
1da177e4 | 775 | |
438c4702 | 776 | if (sata) { |
19c1ef5f AC |
777 | static int first = 1; |
778 | ||
438c4702 BZ |
779 | hwif->reset_poll = &sil_sata_reset_poll; |
780 | hwif->pre_reset = &sil_sata_pre_reset; | |
781 | hwif->udma_filter = &sil_sata_udma_filter; | |
1da177e4 | 782 | |
19c1ef5f AC |
783 | if (first) { |
784 | printk(KERN_INFO "siimage: For full SATA support you should use the libata sata_sil module.\n"); | |
785 | first = 0; | |
786 | } | |
438c4702 BZ |
787 | } else |
788 | hwif->udma_filter = &sil_pata_udma_filter; | |
328dcbb6 | 789 | |
bfa14b42 BZ |
790 | hwif->cable_detect = ata66_siimage; |
791 | ||
328dcbb6 | 792 | if (hwif->dma_base == 0) |
1da177e4 | 793 | return; |
1da177e4 | 794 | |
438c4702 | 795 | if (sata) |
33c1002e | 796 | hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; |
1da177e4 | 797 | |
1da177e4 LT |
798 | if (hwif->mmio) { |
799 | hwif->ide_dma_test_irq = &siimage_mmio_ide_dma_test_irq; | |
800 | } else { | |
801 | hwif->ide_dma_test_irq = & siimage_io_ide_dma_test_irq; | |
802 | } | |
1da177e4 LT |
803 | } |
804 | ||
805 | #define DECLARE_SII_DEV(name_str) \ | |
806 | { \ | |
807 | .name = name_str, \ | |
808 | .init_chipset = init_chipset_siimage, \ | |
809 | .init_iops = init_iops_siimage, \ | |
810 | .init_hwif = init_hwif_siimage, \ | |
7cab14a7 | 811 | .host_flags = IDE_HFLAG_BOOTABLE, \ |
4099d143 | 812 | .pio_mask = ATA_PIO4, \ |
5f8b6c34 BZ |
813 | .mwdma_mask = ATA_MWDMA2, \ |
814 | .udma_mask = ATA_UDMA6, \ | |
1da177e4 LT |
815 | } |
816 | ||
85620436 | 817 | static const struct ide_port_info siimage_chipsets[] __devinitdata = { |
1da177e4 LT |
818 | /* 0 */ DECLARE_SII_DEV("SiI680"), |
819 | /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA"), | |
820 | /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA") | |
821 | }; | |
822 | ||
823 | /** | |
824 | * siimage_init_one - pci layer discovery entry | |
825 | * @dev: PCI device | |
826 | * @id: ident table entry | |
827 | * | |
828 | * Called by the PCI code when it finds an SI680 or SI3112 controller. | |
829 | * We then use the IDE PCI generic helper to do most of the work. | |
830 | */ | |
831 | ||
832 | static int __devinit siimage_init_one(struct pci_dev *dev, const struct pci_device_id *id) | |
833 | { | |
834 | return ide_setup_pci_device(dev, &siimage_chipsets[id->driver_data]); | |
835 | } | |
836 | ||
9cbcc5e3 BZ |
837 | static const struct pci_device_id siimage_pci_tbl[] = { |
838 | { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), 0 }, | |
1da177e4 | 839 | #ifdef CONFIG_BLK_DEV_IDE_SATA |
9cbcc5e3 BZ |
840 | { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_3112), 1 }, |
841 | { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_1210SA), 2 }, | |
1da177e4 LT |
842 | #endif |
843 | { 0, }, | |
844 | }; | |
845 | MODULE_DEVICE_TABLE(pci, siimage_pci_tbl); | |
846 | ||
847 | static struct pci_driver driver = { | |
848 | .name = "SiI_IDE", | |
849 | .id_table = siimage_pci_tbl, | |
850 | .probe = siimage_init_one, | |
851 | }; | |
852 | ||
82ab1eec | 853 | static int __init siimage_ide_init(void) |
1da177e4 LT |
854 | { |
855 | return ide_pci_register_driver(&driver); | |
856 | } | |
857 | ||
858 | module_init(siimage_ide_init); | |
859 | ||
860 | MODULE_AUTHOR("Andre Hedrick, Alan Cox"); | |
861 | MODULE_DESCRIPTION("PCI driver module for SiI IDE"); | |
862 | MODULE_LICENSE("GPL"); |