siimage: do clocking register posting earlier in setup_mmio_siimage()
[pandora-kernel.git] / drivers / ide / pci / siimage.c
index cc4be96..f0c4234 100644 (file)
@@ -301,7 +301,7 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
 }
 
 /* returns 1 if dma irq issued, 0 otherwise */
-static int siimage_io_ide_dma_test_irq (ide_drive_t *drive)
+static int siimage_io_dma_test_irq(ide_drive_t *drive)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
@@ -320,14 +320,14 @@ static int siimage_io_ide_dma_test_irq (ide_drive_t *drive)
 }
 
 /**
- *     siimage_mmio_ide_dma_test_irq   -       check we caused an IRQ
+ *     siimage_mmio_dma_test_irq       -       check we caused an IRQ
  *     @drive: drive we are testing
  *
  *     Check if we caused an IDE DMA interrupt. We may also have caused
  *     SATA status interrupts, if so we clean them up and continue.
  */
-static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
+
+static int siimage_mmio_dma_test_irq(ide_drive_t *drive)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        unsigned long addr      = siimage_selreg(hwif, 0x1);
@@ -347,7 +347,7 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
                        printk(KERN_WARNING "%s: sata_error = 0x%08x, "
                                "watchdog = %d, %s\n",
                                drive->name, sata_error, watchdog,
-                               __FUNCTION__);
+                               __func__);
 
                } else {
                        watchdog = (ext_stat & 0x8000) ? 1 : 0;
@@ -369,46 +369,12 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
        return 0;
 }
 
-/**
- *     sil_sata_busproc        -       bus isolation IOCTL
- *     @drive: drive to isolate/restore
- *     @state: bus state to set
- *
- *     Used by the SII3112 to handle bus isolation. As this is a 
- *     SATA controller the work required is quite limited, we 
- *     just have to clean up the statistics
- */
-
-static int sil_sata_busproc(ide_drive_t * drive, int state)
+static int siimage_dma_test_irq(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = to_pci_dev(hwif->dev);
-       u32 stat_config         = 0;
-       unsigned long addr      = siimage_selreg(hwif, 0);
-
-       if (hwif->mmio)
-               stat_config = readl((void __iomem *)addr);
+       if (drive->hwif->mmio)
+               return siimage_mmio_dma_test_irq(drive);
        else
-               pci_read_config_dword(dev, addr, &stat_config);
-
-       switch (state) {
-               case BUSSTATE_ON:
-                       hwif->drives[0].failures = 0;
-                       hwif->drives[1].failures = 0;
-                       break;
-               case BUSSTATE_OFF:
-                       hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
-                       hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
-                       break;
-               case BUSSTATE_TRISTATE:
-                       hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
-                       hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
-                       break;
-               default:
-                       return -EINVAL;
-       }
-       hwif->bus_state = state;
-       return 0;
+               return siimage_io_dma_test_irq(drive);
 }
 
 /**
@@ -492,7 +458,7 @@ static void proc_reports_siimage (struct pci_dev *dev, u8 clocking, const char *
  
 static unsigned int setup_mmio_siimage (struct pci_dev *dev, const char *name)
 {
-       unsigned long bar5      = pci_resource_start(dev, 5);
+       resource_size_t bar5    = pci_resource_start(dev, 5);
        unsigned long barsize   = pci_resource_len(dev, 5);
        u8 tmpbyte      = 0;
        void __iomem *ioaddr;
@@ -555,7 +521,9 @@ static unsigned int setup_mmio_siimage (struct pci_dev *dev, const char *name)
                        writeb(tmpbyte & ~0x20, ioaddr + 0x4A);
                        break;
        }
-       
+
+       tmpbyte = readb(ioaddr + 0x4A);
+
        writeb(      0x72, ioaddr + 0xA1);
        writew(    0x328A, ioaddr + 0xA2);
        writel(0x62DD62DD, ioaddr + 0xA4);
@@ -574,8 +542,6 @@ static unsigned int setup_mmio_siimage (struct pci_dev *dev, const char *name)
                writel(0x00680000, ioaddr + 0x1C8);
        }
 
-       tmpbyte = readb(ioaddr + 0x4A);
-
        proc_reports_siimage(dev, (tmpbyte>>4), name);
        return 1;
 }
@@ -656,13 +622,15 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
        void *addr              = pci_get_drvdata(dev);
        u8 ch                   = hwif->channel;
-       hw_regs_t               hw;
        unsigned long           base;
 
+       struct ide_io_ports *io_ports = &hwif->io_ports;
+
        /*
         *      Fill in the basic HWIF bits
         */
 
+       hwif->host_flags |= IDE_HFLAG_MMIO;
        default_hwif_mmiops(hwif);
        hwif->hwif_data                 = addr;
 
@@ -672,7 +640,7 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
         *      based I/O
         */
 
-       memset(&hw, 0, sizeof(hw_regs_t));
+       memset(io_ports, 0, sizeof(*io_ports));
 
        base = (unsigned long)addr;
        if (ch)
@@ -685,17 +653,15 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
         *      so we can't currently use it sanely since we want to
         *      use LBA48 mode.
         */     
-       hw.io_ports[IDE_DATA_OFFSET]    = base;
-       hw.io_ports[IDE_ERROR_OFFSET]   = base + 1;
-       hw.io_ports[IDE_NSECTOR_OFFSET] = base + 2;
-       hw.io_ports[IDE_SECTOR_OFFSET]  = base + 3;
-       hw.io_ports[IDE_LCYL_OFFSET]    = base + 4;
-       hw.io_ports[IDE_HCYL_OFFSET]    = base + 5;
-       hw.io_ports[IDE_SELECT_OFFSET]  = base + 6;
-       hw.io_ports[IDE_STATUS_OFFSET]  = base + 7;
-       hw.io_ports[IDE_CONTROL_OFFSET] = base + 10;
-
-       hw.io_ports[IDE_IRQ_OFFSET]     = 0;
+       io_ports->data_addr     = base;
+       io_ports->error_addr    = base + 1;
+       io_ports->nsect_addr    = base + 2;
+       io_ports->lbal_addr     = base + 3;
+       io_ports->lbam_addr     = base + 4;
+       io_ports->lbah_addr     = base + 5;
+       io_ports->device_addr   = base + 6;
+       io_ports->status_addr   = base + 7;
+       io_ports->ctl_addr      = base + 10;
 
        if (pdev_is_sata(dev)) {
                base = (unsigned long)addr;
@@ -706,8 +672,6 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
                hwif->sata_scr[SATA_CONTROL_OFFSET]     = base + 0x100;
        }
 
-       memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports));
-
        hwif->irq = dev->irq;
 
        hwif->dma_base = (unsigned long)addr + (ch ? 0x08 : 0x00);
@@ -777,14 +741,14 @@ static void __devinit init_iops_siimage(ide_hwif_t *hwif)
 }
 
 /**
- *     ata66_siimage   -       check for 80 pin cable
+ *     sil_cable_detect        -       cable detection
  *     @hwif: interface to check
  *
  *     Check for the presence of an ATA66 capable cable on the
  *     interface.
  */
 
-static u8 __devinit ata66_siimage(ide_hwif_t *hwif)
+static u8 __devinit sil_cable_detect(ide_hwif_t *hwif)
 {
        struct pci_dev *dev = to_pci_dev(hwif->dev);
        unsigned long addr = siimage_selreg(hwif, 0);
@@ -798,69 +762,44 @@ static u8 __devinit ata66_siimage(ide_hwif_t *hwif)
        return (ata66 & 0x01) ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
 }
 
-/**
- *     init_hwif_siimage       -       set up hwif structs
- *     @hwif: interface to set up
- *
- *     We do the basic set up of the interface structure. The SIIMAGE
- *     requires several custom handlers so we override the default
- *     ide DMA handlers appropriately
- */
-
-static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
-{
-       u8 sata = is_sata(hwif);
-
-       hwif->set_pio_mode = &sil_set_pio_mode;
-       hwif->set_dma_mode = &sil_set_dma_mode;
-       hwif->quirkproc = &sil_quirkproc;
-
-       if (sata) {
-               static int first = 1;
-
-               hwif->busproc = &sil_sata_busproc;
-               hwif->reset_poll = &sil_sata_reset_poll;
-               hwif->pre_reset = &sil_sata_pre_reset;
-               hwif->udma_filter = &sil_sata_udma_filter;
-
-               if (first) {
-                       printk(KERN_INFO "siimage: For full SATA support you should use the libata sata_sil module.\n");
-                       first = 0;
-               }
-       } else
-               hwif->udma_filter = &sil_pata_udma_filter;
-
-       hwif->cable_detect = ata66_siimage;
-
-       if (hwif->dma_base == 0)
-               return;
+static const struct ide_port_ops sil_pata_port_ops = {
+       .set_pio_mode           = sil_set_pio_mode,
+       .set_dma_mode           = sil_set_dma_mode,
+       .quirkproc              = sil_quirkproc,
+       .udma_filter            = sil_pata_udma_filter,
+       .cable_detect           = sil_cable_detect,
+};
 
-       if (sata)
-               hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
+static const struct ide_port_ops sil_sata_port_ops = {
+       .set_pio_mode           = sil_set_pio_mode,
+       .set_dma_mode           = sil_set_dma_mode,
+       .reset_poll             = sil_sata_reset_poll,
+       .pre_reset              = sil_sata_pre_reset,
+       .quirkproc              = sil_quirkproc,
+       .udma_filter            = sil_sata_udma_filter,
+       .cable_detect           = sil_cable_detect,
+};
 
-       if (hwif->mmio) {
-               hwif->ide_dma_test_irq = &siimage_mmio_ide_dma_test_irq;
-       } else {
-               hwif->ide_dma_test_irq = & siimage_io_ide_dma_test_irq;
-       }
-}
+static struct ide_dma_ops sil_dma_ops = {
+       .dma_test_irq           = siimage_dma_test_irq,
+};
 
-#define DECLARE_SII_DEV(name_str)                      \
+#define DECLARE_SII_DEV(name_str, p_ops)               \
        {                                               \
                .name           = name_str,             \
                .init_chipset   = init_chipset_siimage, \
                .init_iops      = init_iops_siimage,    \
-               .init_hwif      = init_hwif_siimage,    \
-               .host_flags     = IDE_HFLAG_BOOTABLE,   \
+               .port_ops       = p_ops,                \
+               .dma_ops        = &sil_dma_ops,         \
                .pio_mask       = ATA_PIO4,             \
                .mwdma_mask     = ATA_MWDMA2,           \
                .udma_mask      = ATA_UDMA6,            \
        }
 
 static const struct ide_port_info siimage_chipsets[] __devinitdata = {
-       /* 0 */ DECLARE_SII_DEV("SiI680"),
-       /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA"),
-       /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA")
+       /* 0 */ DECLARE_SII_DEV("SiI680",               &sil_pata_port_ops),
+       /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA",   &sil_sata_port_ops),
+       /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA",   &sil_sata_port_ops)
 };
 
 /**
@@ -874,7 +813,24 @@ static const struct ide_port_info siimage_chipsets[] __devinitdata = {
  
 static int __devinit siimage_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
-       return ide_setup_pci_device(dev, &siimage_chipsets[id->driver_data]);
+       struct ide_port_info d;
+       u8 idx = id->driver_data;
+
+       d = siimage_chipsets[idx];
+
+       if (idx) {
+               static int first = 1;
+
+               if (first) {
+                       printk(KERN_INFO "siimage: For full SATA support you "
+                               "should use the libata sata_sil module.\n");
+                       first = 0;
+               }
+
+               d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
+       }
+
+       return ide_setup_pci_device(dev, &d);
 }
 
 static const struct pci_device_id siimage_pci_tbl[] = {