Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/sh64-2.6
[sfrench/cifs-2.6.git] / drivers / ide / pci / serverworks.c
index 057548d072056dfe70e63667d21d483d402be317..6234f806c6b5caa6d264d52371dbc69fa2405f8d 100644 (file)
@@ -1,9 +1,10 @@
 /*
- * linux/drivers/ide/pci/serverworks.c         Version 0.8      25 Ebr 2003
+ * linux/drivers/ide/pci/serverworks.c         Version 0.9     Mar 4 2007
  *
  * Copyright (C) 1998-2000 Michel Aubry
  * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
  * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
+ * Copyright (C)      2007 Bartlomiej Zolnierkiewicz
  * Portions copyright (c) 2001 Sun Microsystems
  *
  *
@@ -65,16 +66,16 @@ static int check_in_drive_lists (ide_drive_t *drive, const char **list)
        return 0;
 }
 
-static u8 svwks_ratemask (ide_drive_t *drive)
+static u8 svwks_udma_filter(ide_drive_t *drive)
 {
        struct pci_dev *dev     = HWIF(drive)->pci_dev;
-       u8 mode = 0;
+       u8 mask = 0;
 
        if (!svwks_revision)
                pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
 
        if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
-               return 2;
+               return 0x1f;
        if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
                u32 reg = 0;
                if (isa_dev)
@@ -86,25 +87,31 @@ static u8 svwks_ratemask (ide_drive_t *drive)
                if(drive->media == ide_disk)
                        return 0;
                /* Check the OSB4 DMA33 enable bit */
-               return ((reg & 0x00004000) == 0x00004000) ? 1 : 0;
+               return ((reg & 0x00004000) == 0x00004000) ? 0x07 : 0;
        } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
-               return 1;
+               return 0x07;
        } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
-               u8 btr = 0;
+               u8 btr = 0, mode;
                pci_read_config_byte(dev, 0x5A, &btr);
                mode = btr & 0x3;
-               if (!eighty_ninty_three(drive))
-                       mode = min(mode, (u8)1);
+
                /* If someone decides to do UDMA133 on CSB5 the same
                   issue will bite so be inclusive */
                if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
                        mode = 2;
+
+               switch(mode) {
+               case 2:  mask = 0x1f; break;
+               case 1:  mask = 0x07; break;
+               default: mask = 0x00; break;
+               }
        }
        if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
             (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
            (!(PCI_FUNC(dev->devfn) & 1)))
-               mode = 2;
-       return mode;
+               mask = 0x1f;
+
+       return mask;
 }
 
 static u8 svwks_csb_check (struct pci_dev *dev)
@@ -130,19 +137,14 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
 
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = hwif->pci_dev;
-       u8 speed;
-       u8 pio                  = ide_get_best_pio_mode(drive, 255, 5, NULL);
+       u8 speed                = ide_rate_filter(drive, xferspeed);
+       u8 pio                  = ide_get_best_pio_mode(drive, 255, 4, NULL);
        u8 unit                 = (drive->select.b.unit & 0x01);
        u8 csb5                 = svwks_csb_check(dev);
        u8 ultra_enable         = 0, ultra_timing = 0;
        u8 dma_timing           = 0, pio_timing = 0;
        u16 csb5_pio            = 0;
 
-       if (xferspeed == 255)   /* PIO auto-tuning */
-               speed = XFER_PIO_0 + pio;
-       else
-               speed = ide_rate_filter(svwks_ratemask(drive), xferspeed);
-
        /* If we are about to put a disk into UDMA mode we screwed up.
           Our code assumes we never _ever_ do this on an OSB4 */
           
@@ -160,7 +162,7 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
        if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
            (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
                if (!drive->init_speed) {
-                       u8 dma_stat = hwif->INB(hwif->dma_status);
+                       u8 dma_stat = inb(hwif->dma_status);
 
 dma_pio:
                        if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
@@ -225,6 +227,9 @@ oem_setup_failed:
                case XFER_MW_DMA_2:
                case XFER_MW_DMA_1:
                case XFER_MW_DMA_0:
+                       /*
+                        * TODO: always setup PIO mode so this won't be needed
+                        */
                        pio_timing |= pio_modes[pio];
                        csb5_pio   |= (pio << (4*drive->dn));
                        dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
@@ -236,6 +241,9 @@ oem_setup_failed:
                case XFER_UDMA_2:
                case XFER_UDMA_1:
                case XFER_UDMA_0:
+                       /*
+                        * TODO: always setup PIO mode so this won't be needed
+                        */
                        pio_timing   |= pio_modes[pio];
                        csb5_pio     |= (pio << (4*drive->dn));
                        dma_timing   |= dma_modes[2];
@@ -256,94 +264,23 @@ oem_setup_failed:
        return (ide_config_drive_speed(drive, speed));
 }
 
-static void config_chipset_for_pio (ide_drive_t *drive)
-{
-       u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
-       u16 xfer_pio = drive->id->eide_pio_modes;
-       u8 timing, speed, pio;
-
-       pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
-
-       if (xfer_pio > 4)
-               xfer_pio = 0;
-
-       if (drive->id->eide_pio_iordy > 0)
-               for (xfer_pio = 5;
-                       xfer_pio>0 &&
-                       drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
-                       xfer_pio--);
-       else
-               xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
-                          (drive->id->eide_pio_modes & 2) ? 0x04 :
-                          (drive->id->eide_pio_modes & 1) ? 0x03 :
-                          (drive->id->tPIO & 2) ? 0x02 :
-                          (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
-
-       timing = (xfer_pio >= pio) ? xfer_pio : pio;
-
-       switch(timing) {
-               case 4: speed = XFER_PIO_4;break;
-               case 3: speed = XFER_PIO_3;break;
-               case 2: speed = XFER_PIO_2;break;
-               case 1: speed = XFER_PIO_1;break;
-               default:
-                       speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
-                       break;
-       }
-       (void) svwks_tune_chipset(drive, speed);
-       drive->current_speed = speed;
-}
-
 static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
 {
-       if(pio == 255)
-               (void) svwks_tune_chipset(drive, 255);
-       else
-               (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio));
-}
-
-static int config_chipset_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_dma_speed(drive, svwks_ratemask(drive));
-
-       if (!(speed))
-               speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
-
-       (void) svwks_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
+       pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
+       (void)svwks_tune_chipset(drive, XFER_PIO_0 + pio);
 }
 
 static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = HWIF(drive);
-       struct hd_driveid *id   = drive->id;
-
        drive->init_speed = 0;
 
-       if ((id->capability & 1) && drive->autodma) {
-
-               if (ide_use_dma(drive)) {
-                       if (config_chipset_for_dma(drive))
-                               return hwif->ide_dma_on(drive);
-               }
+       if (ide_tune_dma(drive))
+               return 0;
 
-               goto fast_ata_pio;
+       if (ide_use_fast_pio(drive))
+               svwks_tune_drive(drive, 255);
 
-       } else if ((id->capability & 8) || (id->field_valid & 2)) {
-fast_ata_pio:
-               config_chipset_for_pio(drive);
-               //      hwif->tuneproc(drive, 5);
-               return hwif->ide_dma_off_quietly(drive);
-       }
-       /* IORDY not supported */
-       return 0;
-}
-
-/* This can go soon */
-
-static int svwks_ide_dma_end (ide_drive_t *drive)
-{
-       return __ide_dma_end(drive);
+       return -1;
 }
 
 static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
@@ -520,6 +457,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
 
        hwif->tuneproc = &svwks_tune_drive;
        hwif->speedproc = &svwks_tune_chipset;
+       hwif->udma_filter = &svwks_udma_filter;
 
        hwif->atapi_dma = 1;
 
@@ -537,35 +475,20 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
        }
 
        hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
-       if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
-               hwif->ide_dma_end = &svwks_ide_dma_end;
-       else if (!(hwif->udma_four))
-               hwif->udma_four = ata66_svwks(hwif);
+       if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
+               if (!hwif->udma_four)
+                       hwif->udma_four = ata66_svwks(hwif);
+       }
        if (!noautodma)
                hwif->autodma = 1;
 
-       dma_stat = hwif->INB(hwif->dma_status);
+       dma_stat = inb(hwif->dma_status);
        hwif->drives[0].autodma = (dma_stat & 0x20);
        hwif->drives[1].autodma = (dma_stat & 0x40);
        hwif->drives[0].autotune = (!(dma_stat & 0x20));
        hwif->drives[1].autotune = (!(dma_stat & 0x40));
 }
 
-/*
- * We allow the BM-DMA driver to only work on enabled interfaces.
- */
-static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase)
-{
-       struct pci_dev *dev = hwif->pci_dev;
-
-       if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
-            (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
-           (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel))
-               return;
-
-       ide_setup_dma(hwif, dmabase, 8);
-}
-
 static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
 {
        return ide_setup_pci_device(dev, d);
@@ -600,7 +523,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
                .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .init_dma       = init_dma_svwks,
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = ON_BOARD,
@@ -609,7 +531,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
                .init_setup     = init_setup_csb6,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .init_dma       = init_dma_svwks,
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = ON_BOARD,
@@ -618,7 +539,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
                .init_setup     = init_setup_csb6,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .init_dma       = init_dma_svwks,
                .channels       = 1,    /* 2 */
                .autodma        = AUTODMA,
                .bootable       = ON_BOARD,
@@ -627,7 +547,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
                .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .init_dma       = init_dma_svwks,
                .channels       = 1,    /* 2 */
                .autodma        = AUTODMA,
                .bootable       = ON_BOARD,
@@ -666,7 +585,7 @@ static struct pci_driver driver = {
        .probe          = svwks_init_one,
 };
 
-static int svwks_ide_init(void)
+static int __init svwks_ide_init(void)
 {
        return ide_pci_register_driver(&driver);
 }