ide: delete filenames/versions from comments
[pandora-kernel.git] / drivers / ide / pci / sl82c105.c
index f492318..da13a12 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * linux/drivers/ide/pci/sl82c105.c
- *
  * SL82C105/Winbond 553 IDE driver
  *
  * Maintainer unknown.
@@ -13,6 +11,7 @@
  *  -- Benjamin Herrenschmidt (01/11/03) benh@kernel.crashing.org
  *
  * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com>
+ * Copyright (C)      2007 Bartlomiej Zolnierkiewicz
  */
 
 #include <linux/types.h>
@@ -75,9 +74,9 @@ static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
 /*
  * Configure the chipset for PIO mode.
  */
-static void sl82c105_tune_pio(ide_drive_t *drive, const u8 pio)
+static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
-       struct pci_dev *dev     = HWIF(drive)->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(drive->hwif->dev);
        int reg                 = 0x44 + drive->dn * 4;
        u16 drv_ctrl;
 
@@ -90,14 +89,8 @@ static void sl82c105_tune_pio(ide_drive_t *drive, const u8 pio)
        drive->drive_data &= 0xffff0000;
        drive->drive_data |= drv_ctrl;
 
-       if (!drive->using_dma) {
-               /*
-                * If we are actually using MW DMA, then we can not
-                * reprogram the interface drive control register.
-                */
-               pci_write_config_word(dev, reg,  drv_ctrl);
-               pci_read_config_word (dev, reg, &drv_ctrl);
-       }
+       pci_write_config_word(dev, reg,  drv_ctrl);
+       pci_read_config_word (dev, reg, &drv_ctrl);
 
        printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name,
                          ide_xfer_verbose(pio + XFER_PIO_0),
@@ -105,9 +98,9 @@ static void sl82c105_tune_pio(ide_drive_t *drive, const u8 pio)
 }
 
 /*
- * Configure the drive and chipset for a new transfer speed.
+ * Configure the chipset for DMA mode.
  */
-static int sl82c105_tune_chipset(ide_drive_t *drive, const u8 speed)
+static void sl82c105_set_dma_mode(ide_drive_t *drive, const u8 speed)
 {
        static u16 mwdma_timings[] = {0x0707, 0x0201, 0x0200};
        u16 drv_ctrl;
@@ -115,48 +108,14 @@ static int sl82c105_tune_chipset(ide_drive_t *drive, const u8 speed)
        DBG(("sl82c105_tune_chipset(drive:%s, speed:%s)\n",
             drive->name, ide_xfer_verbose(speed)));
 
-       switch (speed) {
-       case XFER_MW_DMA_2:
-       case XFER_MW_DMA_1:
-       case XFER_MW_DMA_0:
-               drv_ctrl = mwdma_timings[speed - XFER_MW_DMA_0];
-
-               /*
-                * Store the DMA timings so that we can actually program
-                * them when DMA will be turned on...
-                */
-               drive->drive_data &= 0x0000ffff;
-               drive->drive_data |= (unsigned long)drv_ctrl << 16;
-
-               /*
-                * If we are already using DMA, we just reprogram
-                * the drive control register.
-                */
-               if (drive->using_dma) {
-                       struct pci_dev *dev     = HWIF(drive)->pci_dev;
-                       int reg                 = 0x44 + drive->dn * 4;
-
-                       pci_write_config_word(dev, reg, drv_ctrl);
-               }
-               break;
-       default:
-               return -1;
-       }
-
-       return ide_config_drive_speed(drive, speed);
-}
+       drv_ctrl = mwdma_timings[speed - XFER_MW_DMA_0];
 
-/*
- * Check to see if the drive and chipset are capable of DMA mode.
- */
-static int sl82c105_ide_dma_check(ide_drive_t *drive)
-{
-       DBG(("sl82c105_ide_dma_check(drive:%s)\n", drive->name));
-
-       if (ide_tune_dma(drive))
-               return 0;
-
-       return -1;
+       /*
+        * Store the DMA timings so that we can actually program
+        * them when DMA will be turned on...
+        */
+       drive->drive_data &= 0x0000ffff;
+       drive->drive_data |= (unsigned long)drv_ctrl << 16;
 }
 
 /*
@@ -186,7 +145,7 @@ static inline void sl82c105_reset_host(struct pci_dev *dev)
 static void sl82c105_dma_lost_irq(ide_drive_t *drive)
 {
        ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = hwif->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(hwif->dev);
        u32 val, mask           = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA;
        u8 dma_cmd;
 
@@ -223,7 +182,12 @@ static void sl82c105_dma_lost_irq(ide_drive_t *drive)
 static void sl82c105_dma_start(ide_drive_t *drive)
 {
        ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = hwif->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(hwif->dev);
+       int reg                 = 0x44 + drive->dn * 4;
+
+       DBG(("%s(drive:%s)\n", __FUNCTION__, drive->name));
+
+       pci_write_config_word(dev, reg, drive->drive_data >> 16);
 
        sl82c105_reset_host(dev);
        ide_dma_start(drive);
@@ -231,91 +195,43 @@ static void sl82c105_dma_start(ide_drive_t *drive)
 
 static void sl82c105_dma_timeout(ide_drive_t *drive)
 {
+       struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
+
        DBG(("sl82c105_dma_timeout(drive:%s)\n", drive->name));
 
-       sl82c105_reset_host(HWIF(drive)->pci_dev);
+       sl82c105_reset_host(dev);
        ide_dma_timeout(drive);
 }
 
-static int sl82c105_ide_dma_on(ide_drive_t *drive)
-{
-       struct pci_dev *dev     = HWIF(drive)->pci_dev;
-       int rc, reg             = 0x44 + drive->dn * 4;
-
-       DBG(("sl82c105_ide_dma_on(drive:%s)\n", drive->name));
-
-       rc = __ide_dma_on(drive);
-       if (rc == 0) {
-               pci_write_config_word(dev, reg, drive->drive_data >> 16);
-
-               printk(KERN_INFO "%s: DMA enabled\n", drive->name);
-       }
-       return rc;
-}
-
-static void sl82c105_dma_off_quietly(ide_drive_t *drive)
+static int sl82c105_dma_end(ide_drive_t *drive)
 {
-       struct pci_dev *dev     = HWIF(drive)->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(drive->hwif->dev);
        int reg                 = 0x44 + drive->dn * 4;
+       int ret;
 
-       DBG(("sl82c105_dma_off_quietly(drive:%s)\n", drive->name));
+       DBG(("%s(drive:%s)\n", __FUNCTION__, drive->name));
 
-       pci_write_config_word(dev, reg, drive->drive_data);
+       ret = __ide_dma_end(drive);
 
-       ide_dma_off_quietly(drive);
-}
+       pci_write_config_word(dev, reg, drive->drive_data);
 
-/*
- * Ok, that is nasty, but we must make sure the DMA timings
- * won't be used for a PIO access. The solution here is
- * to make sure the 16 bits mode is diabled on the channel
- * when DMA is enabled, thus causing the chip to use PIO0
- * timings for those operations.
- */
-static void sl82c105_selectproc(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = hwif->pci_dev;
-       u32 val, old, mask;
-
-       //DBG(("sl82c105_selectproc(drive:%s)\n", drive->name));
-
-       mask = hwif->channel ? CTRL_P1F16 : CTRL_P0F16;
-       old = val = (u32)pci_get_drvdata(dev);
-       if (drive->using_dma)
-               val &= ~mask;
-       else
-               val |= mask;
-       if (old != val) {
-               pci_write_config_dword(dev, 0x40, val); 
-               pci_set_drvdata(dev, (void *)val);
-       }
+       return ret;
 }
 
 /*
  * ATA reset will clear the 16 bits mode in the control
- * register, we need to update our cache
+ * register, we need to reprogram it
  */
 static void sl82c105_resetproc(ide_drive_t *drive)
 {
-       struct pci_dev *dev = HWIF(drive)->pci_dev;
+       struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
        u32 val;
 
        DBG(("sl82c105_resetproc(drive:%s)\n", drive->name));
 
        pci_read_config_dword(dev, 0x40, &val);
-       pci_set_drvdata(dev, (void *)val);
-}
-       
-/*
- * We only deal with PIO mode here - DMA mode 'using_dma' is not
- * initialised at the point that this function is called.
- */
-static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
-{
-       sl82c105_tune_pio(drive, pio);
-
-       (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
+       val |= (CTRL_P1F16 | CTRL_P0F16);
+       pci_write_config_dword(dev, 0x40, val);
 }
 
 /*
@@ -368,7 +284,6 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
        pci_read_config_dword(dev, 0x40, &val);
        val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16;
        pci_write_config_dword(dev, 0x40, val);
-       pci_set_drvdata(dev, (void *)val);
 
        return dev->irq;
 }
@@ -378,32 +293,19 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
  */
 static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
 {
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        unsigned int rev;
 
        DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
 
        hwif->set_pio_mode      = &sl82c105_set_pio_mode;
-       hwif->speedproc         = &sl82c105_tune_chipset;
-       hwif->selectproc        = &sl82c105_selectproc;
+       hwif->set_dma_mode      = &sl82c105_set_dma_mode;
        hwif->resetproc         = &sl82c105_resetproc;
 
-       /*
-        * We support 32-bit I/O on this interface, and
-        * it doesn't have problems with interrupts.
-        */
-       hwif->drives[0].io_32bit = hwif->drives[1].io_32bit = 1;
-       hwif->drives[0].unmask   = hwif->drives[1].unmask   = 1;
-
-       /*
-        * We always autotune PIO,  this is done before DMA is checked,
-        * so there's no risk of accidentally disabling DMA
-        */
-       hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
-
        if (!hwif->dma_base)
                return;
 
-       rev = sl82c105_bridge_revision(hwif->pci_dev);
+       rev = sl82c105_bridge_revision(dev);
        if (rev <= 5) {
                /*
                 * Never ever EVER under any circumstances enable
@@ -414,31 +316,26 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
                return;
        }
 
-       hwif->atapi_dma  = 1;
-       hwif->mwdma_mask = 0x07;
+       hwif->mwdma_mask = ATA_MWDMA2;
 
-       hwif->ide_dma_check             = &sl82c105_ide_dma_check;
-       hwif->ide_dma_on                = &sl82c105_ide_dma_on;
-       hwif->dma_off_quietly           = &sl82c105_dma_off_quietly;
        hwif->dma_lost_irq              = &sl82c105_dma_lost_irq;
        hwif->dma_start                 = &sl82c105_dma_start;
+       hwif->ide_dma_end               = &sl82c105_dma_end;
        hwif->dma_timeout               = &sl82c105_dma_timeout;
 
-       if (!noautodma)
-               hwif->autodma = 1;
-       hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
-
        if (hwif->mate)
                hwif->serialized = hwif->mate->serialized = 1;
 }
 
-static ide_pci_device_t sl82c105_chipset __devinitdata = {
+static const struct ide_port_info sl82c105_chipset __devinitdata = {
        .name           = "W82C105",
        .init_chipset   = init_chipset_sl82c105,
        .init_hwif      = init_hwif_sl82c105,
-       .autodma        = NOAUTODMA,
        .enablebits     = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
-       .bootable       = ON_BOARD,
+       .host_flags     = IDE_HFLAG_IO_32BIT |
+                         IDE_HFLAG_UNMASK_IRQS |
+                         IDE_HFLAG_NO_AUTODMA |
+                         IDE_HFLAG_BOOTABLE,
        .pio_mask       = ATA_PIO5,
 };
 
@@ -447,8 +344,8 @@ static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_dev
        return ide_setup_pci_device(dev, &sl82c105_chipset);
 }
 
-static struct pci_device_id sl82c105_pci_tbl[] = {
-       { PCI_DEVICE(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105), 0},
+static const struct pci_device_id sl82c105_pci_tbl[] = {
+       { PCI_VDEVICE(WINBOND, PCI_DEVICE_ID_WINBOND_82C105), 0 },
        { 0, },
 };
 MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl);