38 #include <linux/types.h>
39 #include <linux/module.h>
40 #include <linux/pci.h>
45 #define DRV_NAME "siimage"
54 static int pdev_is_sata(
struct pci_dev *pdev)
56 #ifdef CONFIG_BLK_DEV_IDE_SATA
92 static unsigned long siimage_selreg(
ide_hwif_t *hwif,
int r)
114 static inline unsigned long siimage_seldev(
ide_drive_t *drive,
int r)
137 pci_read_config_byte(dev, addr, &tmp);
142 static u16 sil_ioread16(
struct pci_dev *dev,
unsigned long addr)
144 struct ide_host *host = pci_get_drvdata(dev);
150 pci_read_config_word(dev, addr, &tmp);
155 static void sil_iowrite8(
struct pci_dev *dev,
u8 val,
unsigned long addr)
157 struct ide_host *host = pci_get_drvdata(dev);
162 pci_write_config_byte(dev, addr, val);
165 static void sil_iowrite16(
struct pci_dev *dev,
u16 val,
unsigned long addr)
167 struct ide_host *host = pci_get_drvdata(dev);
172 pci_write_config_word(dev, addr, val);
175 static void sil_iowrite32(
struct pci_dev *dev,
u32 val,
unsigned long addr)
177 struct ide_host *host = pci_get_drvdata(dev);
182 pci_write_config_dword(dev, addr, val);
204 scsc = sil_ioread8(dev, base);
206 switch (scsc & 0x30) {
241 static const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 };
242 static const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 };
248 unsigned long addr = siimage_seldev(drive, 0x04);
249 unsigned long tfaddr = siimage_selreg(hwif, 0x02);
254 u8 addr_mask = hwif->
channel ? (mmio ? 0xF4 : 0x84)
255 : (mmio ? 0xB4 : 0x80);
263 if (pair_pio < tf_pio)
268 speedp = data_speed[
pio];
269 speedt = tf_speed[tf_pio];
271 sil_iowrite16(dev, speedp, addr);
272 sil_iowrite16(dev, speedt, tfaddr);
275 speedp = sil_ioread16(dev, tfaddr - 2);
278 mode = sil_ioread8(dev, base + addr_mask);
279 mode &= ~(unit ? 0x30 : 0x03);
283 mode |= unit ? 0x10 : 0x01;
286 sil_iowrite16(dev, speedp, tfaddr - 2);
287 sil_iowrite8(dev, mode, base + addr_mask);
300 static const u8 ultra6[] = { 0x0F, 0x0B, 0x07, 0x05, 0x03, 0x02, 0x01 };
301 static const u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 };
302 static const u16 dma[] = { 0x2208, 0x10C2, 0x10C1 };
307 u8 mode = 0, unit = drive->
dn & 1;
309 u8 scsc = 0, addr_mask = hwif->
channel ? (mmio ? 0xF4 : 0x84)
310 : (mmio ? 0xB4 : 0x80);
311 unsigned long ma = siimage_seldev(drive, 0x08);
312 unsigned long ua = siimage_seldev(drive, 0x0C);
315 scsc = sil_ioread8 (dev, base + (mmio ? 0x4A : 0x8A));
316 mode = sil_ioread8 (dev, base + addr_mask);
317 multi = sil_ioread16(dev, ma);
318 ultra = sil_ioread16(dev, ua);
320 mode &= ~(unit ? 0x30 : 0x03);
322 scsc = ((scsc & 0x30) == 0x00) ? 0 : 1;
324 scsc = is_sata(hwif) ? 1 : scsc;
330 mode |= unit ? 0x30 : 0x03;
333 mode |= unit ? 0x20 : 0x02;
336 sil_iowrite8 (dev, mode, base + addr_mask);
337 sil_iowrite16(dev,
multi, ma);
338 sil_iowrite16(dev,
ultra, ua);
344 unsigned long addr = siimage_selreg(hwif, 1);
345 u8 val = sil_ioread8(dev, addr);
348 return (val & 8) ? 1 : 0;
359 static int siimage_mmio_dma_test_irq(
ide_drive_t *drive)
365 if (sata_error_addr) {
370 if (ext_stat & ((hwif->
channel) ? 0x40 : 0x10)) {
371 u32 sata_error =
readl(sata_error_addr);
373 writel(sata_error, sata_error_addr);
374 watchdog = (sata_error & 0x00680000) ? 1 : 0;
376 "watchdog = %d, %s\n",
377 drive->
name, sata_error, watchdog, __func__);
379 watchdog = (ext_stat & 0x8000) ? 1 : 0;
382 if (!(ext_stat & 0x0404) && !watchdog)
393 static int siimage_dma_test_irq(
ide_drive_t *drive)
396 return siimage_mmio_dma_test_irq(drive);
415 if (sata_status_addr) {
417 u32 sata_stat =
readl(sata_status_addr);
419 if ((sata_stat & 0x03) != 0x03) {
421 hwif->
name, sata_stat);
453 static int init_chipset_siimage(
struct pci_dev *dev)
455 struct ide_host *host = pci_get_drvdata(dev);
457 unsigned long base, scsc_addr;
465 base = (
unsigned long)ioaddr;
467 if (ioaddr && pdev_is_sata(dev)) {
471 irq_mask = (1 << 22) | (1 << 23);
472 tmp32 =
readl(ioaddr + 0x48);
473 if (tmp32 & irq_mask) {
475 writel(tmp32, ioaddr + 0x48);
476 readl(ioaddr + 0x48);
478 writel(0, ioaddr + 0x148);
479 writel(0, ioaddr + 0x1C8);
482 sil_iowrite8(dev, 0, base ? (base + 0xB4) : 0x80);
483 sil_iowrite8(dev, 0, base ? (base + 0xF4) : 0x84);
485 scsc_addr = base ? (base + 0x4A) : 0x8A;
486 tmp = sil_ioread8(dev, scsc_addr);
488 switch (tmp & 0x30) {
491 sil_iowrite8(dev, tmp | 0x10, scsc_addr);
495 sil_iowrite8(dev, tmp & ~0x20, scsc_addr);
504 tmp = sil_ioread8(dev, scsc_addr);
506 sil_iowrite8 (dev, 0x72, base + 0xA1);
507 sil_iowrite16(dev, 0x328A, base + 0xA2);
508 sil_iowrite32(dev, 0x62DD62DD, base + 0xA4);
509 sil_iowrite32(dev, 0x43924392, base + 0xA8);
510 sil_iowrite32(dev, 0x40094009, base + 0xAC);
511 sil_iowrite8 (dev, 0x72, base ? (base + 0xE1) : 0xB1);
512 sil_iowrite16(dev, 0x328A, base ? (base + 0xE2) : 0xB2);
513 sil_iowrite32(dev, 0x62DD62DD, base ? (base + 0xE4) : 0xB4);
514 sil_iowrite32(dev, 0x43924392, base ? (base + 0xE8) : 0xB8);
515 sil_iowrite32(dev, 0x40094009, base ? (base + 0xEC) : 0xBC);
517 if (base && pdev_is_sata(dev)) {
518 writel(0xFFFF0000, ioaddr + 0x108);
519 writel(0xFFFF0000, ioaddr + 0x188);
520 writel(0x00680000, ioaddr + 0x148);
521 writel(0x00680000, ioaddr + 0x1C8);
525 if (!pdev_is_sata(dev)) {
526 static const char *clk_str[] =
527 {
"== 100",
"== 133",
"== 2X PCI",
"DISABLED!" };
531 pci_name(dev), clk_str[tmp & 3]);
552 struct ide_host *host = pci_get_drvdata(dev);
569 memset(io_ports, 0,
sizeof(*io_ports));
571 base = (
unsigned long)addr;
591 if (pdev_is_sata(dev)) {
592 base = (
unsigned long)addr;
602 hwif->
dma_base = (
unsigned long)addr + (ch ? 0x08 : 0x00);
610 if ((len > 4) && (!
memcmp(s,
"ST", 2)))
611 if ((!
memcmp(s + len - 2,
"AS", 2)) ||
612 (!
memcmp(s + len - 3,
"ASL", 3))) {
614 "errata fix\n", drive->
name);
635 if (!is_sata(hwif) || !is_dev_seagate_sata(drive))
652 struct ide_host *host = pci_get_drvdata(dev);
660 init_mmio_iops_siimage(hwif);
673 unsigned long addr = siimage_selreg(hwif, 0);
674 u8 ata66 = sil_ioread8(dev, addr);
680 .set_pio_mode = sil_set_pio_mode,
681 .set_dma_mode = sil_set_dma_mode,
682 .quirkproc = sil_quirkproc,
683 .test_irq = sil_test_irq,
684 .udma_filter = sil_pata_udma_filter,
685 .cable_detect = sil_cable_detect,
689 .set_pio_mode = sil_set_pio_mode,
690 .set_dma_mode = sil_set_dma_mode,
691 .reset_poll = sil_sata_reset_poll,
692 .pre_reset = sil_sata_pre_reset,
693 .quirkproc = sil_quirkproc,
694 .test_irq = sil_test_irq,
695 .udma_filter = sil_sata_udma_filter,
696 .cable_detect = sil_cable_detect,
704 .dma_test_irq = siimage_dma_test_irq,
710 #define DECLARE_SII_DEV(p_ops) \
713 .init_chipset = init_chipset_siimage, \
714 .init_iops = init_iops_siimage, \
716 .dma_ops = &sil_dma_ops, \
717 .pio_mask = ATA_PIO4, \
718 .mwdma_mask = ATA_MWDMA2, \
719 .udma_mask = ATA_UDMA6, \
744 u8 idx =
id->driver_data;
747 d = siimage_chipsets[
idx];
750 static int first = 1;
754 "should use the libata sata_sil module.\n");
765 pci_read_config_byte(dev, 0x8A, &BA5_EN);
766 if ((BA5_EN & 0x01) || bar5) {
773 "available\n", pci_name(dev));
795 struct ide_host *host = pci_get_drvdata(dev);
813 #ifdef CONFIG_BLK_DEV_IDE_SATA
821 static struct pci_driver siimage_pci_driver = {
823 .id_table = siimage_pci_tbl,
824 .probe = siimage_init_one,
830 static int __init siimage_ide_init(
void)
835 static void __exit siimage_ide_exit(
void)