2 * linux/drivers/ide/pci/siimage.c Version 1.12 Mar 10 2007
4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * Copyright (C) 2007 MontaVista Software, Inc.
8 * May be copied or modified under the terms of the GNU General Public License
10 * Documentation for CMD680:
11 * http://gkernel.sourceforge.net/specs/sii/sii-0680a-v1.31.pdf.bz2
13 * Documentation for SiI 3112:
14 * http://gkernel.sourceforge.net/specs/sii/3112A_SiI-DS-0095-B2.pdf.bz2
16 * Errata and other documentation only available under NDA.
20 * If you are using Marvell SATA-IDE adapters with Maxtor drives
21 * ensure the system is set up for ATA100/UDMA5 not UDMA6.
23 * If you are using WD drives with SATA bridges you must set the
24 * drive to "Single". "Master" will hang
26 * If you have strange problems with nVidia chipset systems please
27 * see the SI support documentation and update your system BIOS
30 * The Dell DRAC4 has some interesting features including effectively hot
31 * unplugging/replugging the virtual CD interface when the DRAC is reset.
32 * This often causes drivers/ide/siimage to panic but is ok with the rather
33 * smarter code in libata.
36 #include <linux/types.h>
37 #include <linux/module.h>
38 #include <linux/pci.h>
39 #include <linux/delay.h>
40 #include <linux/hdreg.h>
41 #include <linux/ide.h>
42 #include <linux/init.h>
47 * pdev_is_sata - check if device is SATA
48 * @pdev: PCI device to check
50 * Returns true if this is a SATA controller
53 static int pdev_is_sata(struct pci_dev
*pdev
)
57 case PCI_DEVICE_ID_SII_3112
:
58 case PCI_DEVICE_ID_SII_1210SA
:
60 case PCI_DEVICE_ID_SII_680
:
68 * is_sata - check if hwif is SATA
69 * @hwif: interface to check
71 * Returns true if this is a SATA controller
74 static inline int is_sata(ide_hwif_t
*hwif
)
76 return pdev_is_sata(hwif
->pci_dev
);
80 * siimage_selreg - return register base
84 * Turn a config register offset into the right address in either
85 * PCI space or MMIO space to access the control register in question
86 * Thankfully this is a configuration operation so isnt performance
90 static unsigned long siimage_selreg(ide_hwif_t
*hwif
, int r
)
92 unsigned long base
= (unsigned long)hwif
->hwif_data
;
95 base
+= (hwif
->channel
<< 6);
97 base
+= (hwif
->channel
<< 4);
102 * siimage_seldev - return register base
106 * Turn a config register offset into the right address in either
107 * PCI space or MMIO space to access the control register in question
108 * including accounting for the unit shift.
111 static inline unsigned long siimage_seldev(ide_drive_t
*drive
, int r
)
113 ide_hwif_t
*hwif
= HWIF(drive
);
114 unsigned long base
= (unsigned long)hwif
->hwif_data
;
117 base
+= (hwif
->channel
<< 6);
119 base
+= (hwif
->channel
<< 4);
120 base
|= drive
->select
.b
.unit
<< drive
->select
.b
.unit
;
125 * sil_udma_filter - compute UDMA mask
128 * Compute the available UDMA speeds for the device on the interface.
130 * For the CMD680 this depends on the clocking mode (scsc), for the
131 * SI3112 SATA controller life is a bit simpler.
134 static u8
sil_udma_filter(ide_drive_t
*drive
)
136 ide_hwif_t
*hwif
= drive
->hwif
;
137 unsigned long base
= (unsigned long) hwif
->hwif_data
;
138 u8 mask
= 0, scsc
= 0;
141 scsc
= hwif
->INB(base
+ 0x4A);
143 pci_read_config_byte(hwif
->pci_dev
, 0x8A, &scsc
);
146 mask
= strstr(drive
->id
->model
, "Maxtor") ? 0x3f : 0x7f;
150 if ((scsc
& 0x30) == 0x10) /* 133 */
152 else if ((scsc
& 0x30) == 0x20) /* 2xPCI */
154 else if ((scsc
& 0x30) == 0x00) /* 100 */
156 else /* Disabled ? */
163 * siimage_taskfile_timing - turn timing data to a mode
164 * @hwif: interface to query
166 * Read the timing data for the interface and return the
167 * mode that is being used.
170 static byte
siimage_taskfile_timing (ide_hwif_t
*hwif
)
173 unsigned long addr
= siimage_selreg(hwif
, 2);
176 timing
= hwif
->INW(addr
);
178 pci_read_config_word(hwif
->pci_dev
, addr
, &timing
);
181 case 0x10c1: return 4;
182 case 0x10c3: return 3;
184 case 0x1281: return 2;
185 case 0x2283: return 1;
192 * simmage_tuneproc - tune a drive
193 * @drive: drive to tune
194 * @mode_wanted: the target operating mode
196 * Load the timing settings for this device mode into the
197 * controller. If we are in PIO mode 3 or 4 turn on IORDY
198 * monitoring (bit 9). The TF timing is bits 31:16
201 static void siimage_tuneproc (ide_drive_t
*drive
, byte mode_wanted
)
203 ide_hwif_t
*hwif
= HWIF(drive
);
206 unsigned long addr
= siimage_seldev(drive
, 0x04);
207 unsigned long tfaddr
= siimage_selreg(hwif
, 0x02);
209 /* cheat for now and use the docs */
210 switch (mode_wanted
) {
235 hwif
->OUTW(speedp
, addr
);
236 hwif
->OUTW(speedt
, tfaddr
);
237 /* Now set up IORDY */
238 if(mode_wanted
== 3 || mode_wanted
== 4)
239 hwif
->OUTW(hwif
->INW(tfaddr
-2)|0x200, tfaddr
-2);
241 hwif
->OUTW(hwif
->INW(tfaddr
-2)&~0x200, tfaddr
-2);
243 pci_write_config_word(hwif
->pci_dev
, addr
, speedp
);
244 pci_write_config_word(hwif
->pci_dev
, tfaddr
, speedt
);
245 pci_read_config_word(hwif
->pci_dev
, tfaddr
-2, &speedp
);
247 /* Set IORDY for mode 3 or 4 */
248 if(mode_wanted
== 3 || mode_wanted
== 4)
250 pci_write_config_word(hwif
->pci_dev
, tfaddr
-2, speedp
);
255 * config_siimage_chipset_for_pio - set drive timings
256 * @drive: drive to tune
259 * Compute the best pio mode we can for a given device. Also honour
260 * the timings for the driver when dealing with mixed devices. Some
261 * of this is ugly but its all wrapped up here
263 * The SI680 can also do VDMA - we need to start using that
265 * FIXME: we use the BIOS channel timings to avoid driving the task
266 * files too fast at the disk. We need to compute the master/slave
267 * drive PIO mode properly so that we can up the speed on a hotplug
271 static void config_siimage_chipset_for_pio (ide_drive_t
*drive
, byte set_speed
)
273 u8 channel_timings
= siimage_taskfile_timing(HWIF(drive
));
274 u8 speed
= 0, set_pio
= ide_get_best_pio_mode(drive
, 4, 5, NULL
);
276 /* WARNING PIO timing mess is going to happen b/w devices, argh */
277 if ((channel_timings
!= set_pio
) && (set_pio
> channel_timings
))
278 set_pio
= channel_timings
;
280 siimage_tuneproc(drive
, set_pio
);
281 speed
= XFER_PIO_0
+ set_pio
;
283 (void) ide_config_drive_speed(drive
, speed
);
287 * siimage_tune_chipset - set controller timings
288 * @drive: Drive to set up
289 * @xferspeed: speed we want to achieve
291 * Tune the SII chipset for the desired mode. If we can't achieve
292 * the desired mode then tune for a lower one, but ultimately
293 * make the thing work.
296 static int siimage_tune_chipset (ide_drive_t
*drive
, byte xferspeed
)
298 u8 ultra6
[] = { 0x0F, 0x0B, 0x07, 0x05, 0x03, 0x02, 0x01 };
299 u8 ultra5
[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 };
300 u16 dma
[] = { 0x2208, 0x10C2, 0x10C1 };
302 ide_hwif_t
*hwif
= HWIF(drive
);
303 u16 ultra
= 0, multi
= 0;
304 u8 mode
= 0, unit
= drive
->select
.b
.unit
;
305 u8 speed
= ide_rate_filter(drive
, xferspeed
);
306 unsigned long base
= (unsigned long)hwif
->hwif_data
;
307 u8 scsc
= 0, addr_mask
= ((hwif
->channel
) ?
308 ((hwif
->mmio
) ? 0xF4 : 0x84) :
309 ((hwif
->mmio
) ? 0xB4 : 0x80));
311 unsigned long ma
= siimage_seldev(drive
, 0x08);
312 unsigned long ua
= siimage_seldev(drive
, 0x0C);
315 scsc
= hwif
->INB(base
+ 0x4A);
316 mode
= hwif
->INB(base
+ addr_mask
);
317 multi
= hwif
->INW(ma
);
318 ultra
= hwif
->INW(ua
);
320 pci_read_config_byte(hwif
->pci_dev
, 0x8A, &scsc
);
321 pci_read_config_byte(hwif
->pci_dev
, addr_mask
, &mode
);
322 pci_read_config_word(hwif
->pci_dev
, ma
, &multi
);
323 pci_read_config_word(hwif
->pci_dev
, ua
, &ultra
);
326 mode
&= ~((unit
) ? 0x30 : 0x03);
328 scsc
= ((scsc
& 0x30) == 0x00) ? 0 : 1;
330 scsc
= is_sata(hwif
) ? 1 : scsc
;
338 siimage_tuneproc(drive
, (speed
- XFER_PIO_0
));
339 mode
|= ((unit
) ? 0x10 : 0x01);
344 multi
= dma
[speed
- XFER_MW_DMA_0
];
345 mode
|= ((unit
) ? 0x20 : 0x02);
346 config_siimage_chipset_for_pio(drive
, 0);
356 ultra
|= ((scsc
) ? (ultra6
[speed
- XFER_UDMA_0
]) :
357 (ultra5
[speed
- XFER_UDMA_0
]));
358 mode
|= ((unit
) ? 0x30 : 0x03);
359 config_siimage_chipset_for_pio(drive
, 0);
366 hwif
->OUTB(mode
, base
+ addr_mask
);
367 hwif
->OUTW(multi
, ma
);
368 hwif
->OUTW(ultra
, ua
);
370 pci_write_config_byte(hwif
->pci_dev
, addr_mask
, mode
);
371 pci_write_config_word(hwif
->pci_dev
, ma
, multi
);
372 pci_write_config_word(hwif
->pci_dev
, ua
, ultra
);
374 return (ide_config_drive_speed(drive
, speed
));
378 * siimage_configure_drive_for_dma - set up for DMA transfers
379 * @drive: drive we are going to set up
381 * Set up the drive for DMA, tune the controller and drive as
382 * required. If the drive isn't suitable for DMA or we hit
383 * other problems then we will drop down to PIO and set up
387 static int siimage_config_drive_for_dma (ide_drive_t
*drive
)
389 if (ide_tune_dma(drive
))
392 if (ide_use_fast_pio(drive
))
393 config_siimage_chipset_for_pio(drive
, 1);
398 /* returns 1 if dma irq issued, 0 otherwise */
399 static int siimage_io_ide_dma_test_irq (ide_drive_t
*drive
)
401 ide_hwif_t
*hwif
= HWIF(drive
);
403 unsigned long addr
= siimage_selreg(hwif
, 1);
405 /* return 1 if INTR asserted */
406 if ((hwif
->INB(hwif
->dma_status
) & 4) == 4)
409 /* return 1 if Device INTR asserted */
410 pci_read_config_byte(hwif
->pci_dev
, addr
, &dma_altstat
);
412 return 0; //return 1;
417 * siimage_mmio_ide_dma_test_irq - check we caused an IRQ
418 * @drive: drive we are testing
420 * Check if we caused an IDE DMA interrupt. We may also have caused
421 * SATA status interrupts, if so we clean them up and continue.
424 static int siimage_mmio_ide_dma_test_irq (ide_drive_t
*drive
)
426 ide_hwif_t
*hwif
= HWIF(drive
);
427 unsigned long base
= (unsigned long)hwif
->hwif_data
;
428 unsigned long addr
= siimage_selreg(hwif
, 0x1);
430 if (SATA_ERROR_REG
) {
431 u32 ext_stat
= readl((void __iomem
*)(base
+ 0x10));
433 if (ext_stat
& ((hwif
->channel
) ? 0x40 : 0x10)) {
434 u32 sata_error
= readl((void __iomem
*)SATA_ERROR_REG
);
435 writel(sata_error
, (void __iomem
*)SATA_ERROR_REG
);
436 watchdog
= (sata_error
& 0x00680000) ? 1 : 0;
437 printk(KERN_WARNING
"%s: sata_error = 0x%08x, "
438 "watchdog = %d, %s\n",
439 drive
->name
, sata_error
, watchdog
,
443 watchdog
= (ext_stat
& 0x8000) ? 1 : 0;
447 if (!(ext_stat
& 0x0404) && !watchdog
)
451 /* return 1 if INTR asserted */
452 if ((readb((void __iomem
*)hwif
->dma_status
) & 0x04) == 0x04)
455 /* return 1 if Device INTR asserted */
456 if ((readb((void __iomem
*)addr
) & 8) == 8)
457 return 0; //return 1;
463 * siimage_busproc - bus isolation ioctl
464 * @drive: drive to isolate/restore
465 * @state: bus state to set
467 * Used by the SII3112 to handle bus isolation. As this is a
468 * SATA controller the work required is quite limited, we
469 * just have to clean up the statistics
472 static int siimage_busproc (ide_drive_t
* drive
, int state
)
474 ide_hwif_t
*hwif
= HWIF(drive
);
476 unsigned long addr
= siimage_selreg(hwif
, 0);
479 stat_config
= readl((void __iomem
*)addr
);
481 pci_read_config_dword(hwif
->pci_dev
, addr
, &stat_config
);
485 hwif
->drives
[0].failures
= 0;
486 hwif
->drives
[1].failures
= 0;
489 hwif
->drives
[0].failures
= hwif
->drives
[0].max_failures
+ 1;
490 hwif
->drives
[1].failures
= hwif
->drives
[1].max_failures
+ 1;
492 case BUSSTATE_TRISTATE
:
493 hwif
->drives
[0].failures
= hwif
->drives
[0].max_failures
+ 1;
494 hwif
->drives
[1].failures
= hwif
->drives
[1].max_failures
+ 1;
499 hwif
->bus_state
= state
;
504 * siimage_reset_poll - wait for sata reset
505 * @drive: drive we are resetting
507 * Poll the SATA phy and see whether it has come back from the dead
511 static int siimage_reset_poll (ide_drive_t
*drive
)
513 if (SATA_STATUS_REG
) {
514 ide_hwif_t
*hwif
= HWIF(drive
);
516 /* SATA_STATUS_REG is valid only when in MMIO mode */
517 if ((readl((void __iomem
*)SATA_STATUS_REG
) & 0x03) != 0x03) {
518 printk(KERN_WARNING
"%s: reset phy dead, status=0x%08x\n",
519 hwif
->name
, readl((void __iomem
*)SATA_STATUS_REG
));
520 HWGROUP(drive
)->polling
= 0;
530 * siimage_pre_reset - reset hook
531 * @drive: IDE device being reset
533 * For the SATA devices we need to handle recalibration/geometry
537 static void siimage_pre_reset (ide_drive_t
*drive
)
539 if (drive
->media
!= ide_disk
)
542 if (is_sata(HWIF(drive
)))
544 drive
->special
.b
.set_geometry
= 0;
545 drive
->special
.b
.recalibrate
= 0;
550 * siimage_reset - reset a device on an siimage controller
551 * @drive: drive to reset
553 * Perform a controller level reset fo the device. For
554 * SATA we must also check the PHY.
557 static void siimage_reset (ide_drive_t
*drive
)
559 ide_hwif_t
*hwif
= HWIF(drive
);
561 unsigned long addr
= siimage_selreg(hwif
, 0);
564 reset
= hwif
->INB(addr
);
565 hwif
->OUTB((reset
|0x03), addr
);
568 hwif
->OUTB(reset
, addr
);
569 (void) hwif
->INB(addr
);
571 pci_read_config_byte(hwif
->pci_dev
, addr
, &reset
);
572 pci_write_config_byte(hwif
->pci_dev
, addr
, reset
|0x03);
574 pci_write_config_byte(hwif
->pci_dev
, addr
, reset
);
575 pci_read_config_byte(hwif
->pci_dev
, addr
, &reset
);
578 if (SATA_STATUS_REG
) {
579 /* SATA_STATUS_REG is valid only when in MMIO mode */
580 u32 sata_stat
= readl((void __iomem
*)SATA_STATUS_REG
);
581 printk(KERN_WARNING
"%s: reset phy, status=0x%08x, %s\n",
582 hwif
->name
, sata_stat
, __FUNCTION__
);
584 printk(KERN_WARNING
"%s: reset phy dead, status=0x%08x\n",
585 hwif
->name
, sata_stat
);
593 * proc_reports_siimage - add siimage controller to proc
595 * @clocking: SCSC value
596 * @name: controller name
598 * Report the clocking mode of the controller and add it to
599 * the /proc interface layer
602 static void proc_reports_siimage (struct pci_dev
*dev
, u8 clocking
, const char *name
)
604 if (!pdev_is_sata(dev
)) {
605 printk(KERN_INFO
"%s: BASE CLOCK ", name
);
608 case 0x03: printk("DISABLED!\n"); break;
609 case 0x02: printk("== 2X PCI\n"); break;
610 case 0x01: printk("== 133\n"); break;
611 case 0x00: printk("== 100\n"); break;
617 * setup_mmio_siimage - switch an SI controller into MMIO
618 * @dev: PCI device we are configuring
621 * Attempt to put the device into mmio mode. There are some slight
622 * complications here with certain systems where the mmio bar isnt
623 * mapped so we have to be sure we can fall back to I/O.
626 static unsigned int setup_mmio_siimage (struct pci_dev
*dev
, const char *name
)
628 unsigned long bar5
= pci_resource_start(dev
, 5);
629 unsigned long barsize
= pci_resource_len(dev
, 5);
631 void __iomem
*ioaddr
;
635 * Drop back to PIO if we can't map the mmio. Some
636 * systems seem to get terminally confused in the PCI
640 if(!request_mem_region(bar5
, barsize
, name
))
642 printk(KERN_WARNING
"siimage: IDE controller MMIO ports not available.\n");
646 ioaddr
= ioremap(bar5
, barsize
);
650 release_mem_region(bar5
, barsize
);
655 pci_set_drvdata(dev
, (void *) ioaddr
);
657 if (pdev_is_sata(dev
)) {
658 /* make sure IDE0/1 interrupts are not masked */
659 irq_mask
= (1 << 22) | (1 << 23);
660 tmp
= readl(ioaddr
+ 0x48);
661 if (tmp
& irq_mask
) {
663 writel(tmp
, ioaddr
+ 0x48);
664 readl(ioaddr
+ 0x48); /* flush */
666 writel(0, ioaddr
+ 0x148);
667 writel(0, ioaddr
+ 0x1C8);
670 writeb(0, ioaddr
+ 0xB4);
671 writeb(0, ioaddr
+ 0xF4);
672 tmpbyte
= readb(ioaddr
+ 0x4A);
674 switch(tmpbyte
& 0x30) {
676 /* In 100 MHz clocking, try and switch to 133 */
677 writeb(tmpbyte
|0x10, ioaddr
+ 0x4A);
680 /* On 133Mhz clocking */
683 /* On PCIx2 clocking */
686 /* Clocking is disabled */
687 /* 133 clock attempt to force it on */
688 writeb(tmpbyte
& ~0x20, ioaddr
+ 0x4A);
692 writeb( 0x72, ioaddr
+ 0xA1);
693 writew( 0x328A, ioaddr
+ 0xA2);
694 writel(0x62DD62DD, ioaddr
+ 0xA4);
695 writel(0x43924392, ioaddr
+ 0xA8);
696 writel(0x40094009, ioaddr
+ 0xAC);
697 writeb( 0x72, ioaddr
+ 0xE1);
698 writew( 0x328A, ioaddr
+ 0xE2);
699 writel(0x62DD62DD, ioaddr
+ 0xE4);
700 writel(0x43924392, ioaddr
+ 0xE8);
701 writel(0x40094009, ioaddr
+ 0xEC);
703 if (pdev_is_sata(dev
)) {
704 writel(0xFFFF0000, ioaddr
+ 0x108);
705 writel(0xFFFF0000, ioaddr
+ 0x188);
706 writel(0x00680000, ioaddr
+ 0x148);
707 writel(0x00680000, ioaddr
+ 0x1C8);
710 tmpbyte
= readb(ioaddr
+ 0x4A);
712 proc_reports_siimage(dev
, (tmpbyte
>>4), name
);
717 * init_chipset_siimage - set up an SI device
721 * Perform the initial PCI set up for this device. Attempt to switch
722 * to 133MHz clocking if the system isn't already set up to do it.
725 static unsigned int __devinit
init_chipset_siimage(struct pci_dev
*dev
, const char *name
)
731 pci_read_config_dword(dev
, PCI_CLASS_REVISION
, &class_rev
);
733 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
, (class_rev
) ? 1 : 255);
735 pci_read_config_byte(dev
, 0x8A, &BA5_EN
);
736 if ((BA5_EN
& 0x01) || (pci_resource_start(dev
, 5))) {
737 if (setup_mmio_siimage(dev
, name
)) {
742 pci_write_config_byte(dev
, 0x80, 0x00);
743 pci_write_config_byte(dev
, 0x84, 0x00);
744 pci_read_config_byte(dev
, 0x8A, &tmpbyte
);
745 switch(tmpbyte
& 0x30) {
747 /* 133 clock attempt to force it on */
748 pci_write_config_byte(dev
, 0x8A, tmpbyte
|0x10);
750 /* if clocking is disabled */
751 /* 133 clock attempt to force it on */
752 pci_write_config_byte(dev
, 0x8A, tmpbyte
& ~0x20);
757 /* BIOS set PCI x2 clocking */
761 pci_read_config_byte(dev
, 0x8A, &tmpbyte
);
763 pci_write_config_byte(dev
, 0xA1, 0x72);
764 pci_write_config_word(dev
, 0xA2, 0x328A);
765 pci_write_config_dword(dev
, 0xA4, 0x62DD62DD);
766 pci_write_config_dword(dev
, 0xA8, 0x43924392);
767 pci_write_config_dword(dev
, 0xAC, 0x40094009);
768 pci_write_config_byte(dev
, 0xB1, 0x72);
769 pci_write_config_word(dev
, 0xB2, 0x328A);
770 pci_write_config_dword(dev
, 0xB4, 0x62DD62DD);
771 pci_write_config_dword(dev
, 0xB8, 0x43924392);
772 pci_write_config_dword(dev
, 0xBC, 0x40094009);
774 proc_reports_siimage(dev
, (tmpbyte
>>4), name
);
779 * init_mmio_iops_siimage - set up the iops for MMIO
780 * @hwif: interface to set up
782 * The basic setup here is fairly simple, we can use standard MMIO
783 * operations. However we do have to set the taskfile register offsets
784 * by hand as there isnt a standard defined layout for them this
787 * The hardware supports buffered taskfiles and also some rather nice
788 * extended PRD tables. For better SI3112 support use the libata driver
791 static void __devinit
init_mmio_iops_siimage(ide_hwif_t
*hwif
)
793 struct pci_dev
*dev
= hwif
->pci_dev
;
794 void *addr
= pci_get_drvdata(dev
);
795 u8 ch
= hwif
->channel
;
800 * Fill in the basic HWIF bits
803 default_hwif_mmiops(hwif
);
804 hwif
->hwif_data
= addr
;
807 * Now set up the hw. We have to do this ourselves as
808 * the MMIO layout isnt the same as the standard port
812 memset(&hw
, 0, sizeof(hw_regs_t
));
814 base
= (unsigned long)addr
;
821 * The buffered task file doesn't have status/control
822 * so we can't currently use it sanely since we want to
825 hw
.io_ports
[IDE_DATA_OFFSET
] = base
;
826 hw
.io_ports
[IDE_ERROR_OFFSET
] = base
+ 1;
827 hw
.io_ports
[IDE_NSECTOR_OFFSET
] = base
+ 2;
828 hw
.io_ports
[IDE_SECTOR_OFFSET
] = base
+ 3;
829 hw
.io_ports
[IDE_LCYL_OFFSET
] = base
+ 4;
830 hw
.io_ports
[IDE_HCYL_OFFSET
] = base
+ 5;
831 hw
.io_ports
[IDE_SELECT_OFFSET
] = base
+ 6;
832 hw
.io_ports
[IDE_STATUS_OFFSET
] = base
+ 7;
833 hw
.io_ports
[IDE_CONTROL_OFFSET
] = base
+ 10;
835 hw
.io_ports
[IDE_IRQ_OFFSET
] = 0;
837 if (pdev_is_sata(dev
)) {
838 base
= (unsigned long)addr
;
841 hwif
->sata_scr
[SATA_STATUS_OFFSET
] = base
+ 0x104;
842 hwif
->sata_scr
[SATA_ERROR_OFFSET
] = base
+ 0x108;
843 hwif
->sata_scr
[SATA_CONTROL_OFFSET
] = base
+ 0x100;
844 hwif
->sata_misc
[SATA_MISC_OFFSET
] = base
+ 0x140;
845 hwif
->sata_misc
[SATA_PHY_OFFSET
] = base
+ 0x144;
846 hwif
->sata_misc
[SATA_IEN_OFFSET
] = base
+ 0x148;
849 hw
.irq
= hwif
->pci_dev
->irq
;
851 memcpy(&hwif
->hw
, &hw
, sizeof(hw
));
852 memcpy(hwif
->io_ports
, hwif
->hw
.io_ports
, sizeof(hwif
->hw
.io_ports
));
856 base
= (unsigned long) addr
;
858 hwif
->dma_base
= base
+ (ch
? 0x08 : 0x00);
863 static int is_dev_seagate_sata(ide_drive_t
*drive
)
865 const char *s
= &drive
->id
->model
[0];
871 len
= strnlen(s
, sizeof(drive
->id
->model
));
873 if ((len
> 4) && (!memcmp(s
, "ST", 2))) {
874 if ((!memcmp(s
+ len
- 2, "AS", 2)) ||
875 (!memcmp(s
+ len
- 3, "ASL", 3))) {
876 printk(KERN_INFO
"%s: applying pessimistic Seagate "
877 "errata fix\n", drive
->name
);
885 * siimage_fixup - post probe fixups
886 * @hwif: interface to fix up
888 * Called after drive probe we use this to decide whether the
889 * Seagate fixup must be applied. This used to be in init_iops but
890 * that can occur before we know what drives are present.
893 static void __devinit
siimage_fixup(ide_hwif_t
*hwif
)
895 /* Try and raise the rqsize */
896 if (!is_sata(hwif
) || !is_dev_seagate_sata(&hwif
->drives
[0]))
901 * init_iops_siimage - set up iops
902 * @hwif: interface to set up
904 * Do the basic setup for the SIIMAGE hardware interface
905 * and then do the MMIO setup if we can. This is the first
906 * look in we get for setting up the hwif so that we
907 * can get the iops right before using them.
910 static void __devinit
init_iops_siimage(ide_hwif_t
*hwif
)
912 struct pci_dev
*dev
= hwif
->pci_dev
;
915 pci_read_config_dword(dev
, PCI_CLASS_REVISION
, &class_rev
);
918 hwif
->hwif_data
= NULL
;
920 /* Pessimal until we finish probing */
923 if (pci_get_drvdata(dev
) == NULL
)
925 init_mmio_iops_siimage(hwif
);
929 * ata66_siimage - check for 80 pin cable
930 * @hwif: interface to check
932 * Check for the presence of an ATA66 capable cable on the
936 static unsigned int __devinit
ata66_siimage(ide_hwif_t
*hwif
)
938 unsigned long addr
= siimage_selreg(hwif
, 0);
939 if (pci_get_drvdata(hwif
->pci_dev
) == NULL
) {
941 pci_read_config_byte(hwif
->pci_dev
, addr
, &ata66
);
942 return (ata66
& 0x01) ? 1 : 0;
945 return (hwif
->INB(addr
) & 0x01) ? 1 : 0;
949 * init_hwif_siimage - set up hwif structs
950 * @hwif: interface to set up
952 * We do the basic set up of the interface structure. The SIIMAGE
953 * requires several custom handlers so we override the default
954 * ide DMA handlers appropriately
957 static void __devinit
init_hwif_siimage(ide_hwif_t
*hwif
)
961 hwif
->resetproc
= &siimage_reset
;
962 hwif
->speedproc
= &siimage_tune_chipset
;
963 hwif
->tuneproc
= &siimage_tuneproc
;
964 hwif
->reset_poll
= &siimage_reset_poll
;
965 hwif
->pre_reset
= &siimage_pre_reset
;
966 hwif
->udma_filter
= &sil_udma_filter
;
969 static int first
= 1;
971 hwif
->busproc
= &siimage_busproc
;
974 printk(KERN_INFO
"siimage: For full SATA support you should use the libata sata_sil module.\n");
978 if (!hwif
->dma_base
) {
979 hwif
->drives
[0].autotune
= 1;
980 hwif
->drives
[1].autotune
= 1;
984 hwif
->ultra_mask
= 0x7f;
985 hwif
->mwdma_mask
= 0x07;
990 hwif
->ide_dma_check
= &siimage_config_drive_for_dma
;
991 if (!(hwif
->udma_four
))
992 hwif
->udma_four
= ata66_siimage(hwif
);
995 hwif
->ide_dma_test_irq
= &siimage_mmio_ide_dma_test_irq
;
997 hwif
->ide_dma_test_irq
= & siimage_io_ide_dma_test_irq
;
1001 * The BIOS often doesn't set up DMA on this controller
1002 * so we always do it.
1006 hwif
->drives
[0].autodma
= hwif
->autodma
;
1007 hwif
->drives
[1].autodma
= hwif
->autodma
;
1010 #define DECLARE_SII_DEV(name_str) \
1013 .init_chipset = init_chipset_siimage, \
1014 .init_iops = init_iops_siimage, \
1015 .init_hwif = init_hwif_siimage, \
1016 .fixup = siimage_fixup, \
1018 .autodma = AUTODMA, \
1019 .bootable = ON_BOARD, \
1022 static ide_pci_device_t siimage_chipsets
[] __devinitdata
= {
1023 /* 0 */ DECLARE_SII_DEV("SiI680"),
1024 /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA"),
1025 /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA")
1029 * siimage_init_one - pci layer discovery entry
1031 * @id: ident table entry
1033 * Called by the PCI code when it finds an SI680 or SI3112 controller.
1034 * We then use the IDE PCI generic helper to do most of the work.
1037 static int __devinit
siimage_init_one(struct pci_dev
*dev
, const struct pci_device_id
*id
)
1039 return ide_setup_pci_device(dev
, &siimage_chipsets
[id
->driver_data
]);
1042 static struct pci_device_id siimage_pci_tbl
[] = {
1043 { PCI_VENDOR_ID_CMD
, PCI_DEVICE_ID_SII_680
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
1044 #ifdef CONFIG_BLK_DEV_IDE_SATA
1045 { PCI_VENDOR_ID_CMD
, PCI_DEVICE_ID_SII_3112
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1},
1046 { PCI_VENDOR_ID_CMD
, PCI_DEVICE_ID_SII_1210SA
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2},
1050 MODULE_DEVICE_TABLE(pci
, siimage_pci_tbl
);
1052 static struct pci_driver driver
= {
1054 .id_table
= siimage_pci_tbl
,
1055 .probe
= siimage_init_one
,
1058 static int __init
siimage_ide_init(void)
1060 return ide_pci_register_driver(&driver
);
1063 module_init(siimage_ide_init
);
1065 MODULE_AUTHOR("Andre Hedrick, Alan Cox");
1066 MODULE_DESCRIPTION("PCI driver module for SiI IDE");
1067 MODULE_LICENSE("GPL");