ide: use ide_build_sglist() and ide_destroy_dmatable() in non-PCI host drivers
[cascardo/linux.git] / drivers / ide / mips / au1xxx-ide.c
index aebde49..ed1a285 100644 (file)
@@ -198,8 +198,6 @@ static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
                break;
 #endif
-       default:
-               return;
        }
 
        au_writel(mem_sttime,MEM_STTIME2);
@@ -211,24 +209,6 @@ static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
  */
 
 #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
-
-static int auide_build_sglist(ide_drive_t *drive,  struct request *rq)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
-       struct scatterlist *sg = hwif->sg_table;
-
-       ide_map_sg(drive, rq);
-
-       if (rq_data_dir(rq) == READ)
-               hwif->sg_dma_direction = DMA_FROM_DEVICE;
-       else
-               hwif->sg_dma_direction = DMA_TO_DEVICE;
-
-       return dma_map_sg(ahwif->dev, sg, hwif->sg_nents,
-                         hwif->sg_dma_direction);
-}
-
 static int auide_build_dmatable(ide_drive_t *drive)
 {
        int i, iswrite, count = 0;
@@ -243,8 +223,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
        /* Save for interrupt context */
        ahwif->drive = drive;
 
-       /* Build sglist */
-       hwif->sg_nents = i = auide_build_sglist(drive, rq);
+       hwif->sg_nents = i = ide_build_sglist(drive, rq);
 
        if (!i)
                return 0;
@@ -276,8 +255,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
 
                        if (iswrite) {
                                if(!put_source_flags(ahwif->tx_chan, 
-                                                    (void*)(page_address(sg->page) 
-                                                            + sg->offset), 
+                                                    (void*) sg_virt(sg),
                                                     tc, flags)) { 
                                        printk(KERN_ERR "%s failed %d\n", 
                                               __FUNCTION__, __LINE__);
@@ -285,8 +263,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
                        } else 
                        {
                                if(!put_dest_flags(ahwif->rx_chan, 
-                                                  (void*)(page_address(sg->page) 
-                                                          + sg->offset), 
+                                                  (void*) sg_virt(sg),
                                                   tc, flags)) { 
                                        printk(KERN_ERR "%s failed %d\n", 
                                               __FUNCTION__, __LINE__);
@@ -296,7 +273,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
                        cur_addr += tc;
                        cur_len -= tc;
                }
-               sg++;
+               sg = sg_next(sg);
                i--;
        }
 
@@ -304,10 +281,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
                return 1;
 
  use_pio_instead:
-       dma_unmap_sg(ahwif->dev,
-                    hwif->sg_table,
-                    hwif->sg_nents,
-                    hwif->sg_dma_direction);
+       ide_destroy_dmatable(drive);
 
        return 0; /* revert to PIO for this request */
 }
@@ -315,11 +289,9 @@ static int auide_build_dmatable(ide_drive_t *drive)
 static int auide_dma_end(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = HWIF(drive);
-       _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
 
        if (hwif->sg_nents) {
-               dma_unmap_sg(ahwif->dev, hwif->sg_table, hwif->sg_nents,
-                            hwif->sg_dma_direction);
+               ide_destroy_dmatable(drive);
                hwif->sg_nents = 0;
        }
 
@@ -351,11 +323,18 @@ static int auide_dma_setup(ide_drive_t *drive)
        return 0;
 }
 
-static int auide_dma_check(ide_drive_t *drive)
+static u8 auide_mdma_filter(ide_drive_t *drive)
 {
-       u8 speed = ide_max_dma_mode(drive);
+       /*
+        * FIXME: ->white_list and ->black_list are based on completely bogus
+        * ->ide_dma_check implementation which didn't set neither the host
+        * controller timings nor the device for the desired transfer mode.
+        *
+        * They should be either removed or 0x00 MWDMA mask should be
+        * returned for devices on the ->black_list.
+        */
 
-       if( dbdma_init_done == 0 ){
+       if (dbdma_init_done == 0) {
                auide_hwif.white_list = ide_in_drive_list(drive->id,
                                                          dma_white_list);
                auide_hwif.black_list = ide_in_drive_list(drive->id,
@@ -366,22 +345,11 @@ static int auide_dma_check(ide_drive_t *drive)
        }
 
        /* Is the drive in our DMA black list? */
-
-       if ( auide_hwif.black_list ) {
-               drive->using_dma = 0;
-
-               /* Borrowed the warning message from ide-dma.c */
-
+       if (auide_hwif.black_list)
                printk(KERN_WARNING "%s: Disabling DMA for %s (blacklisted)\n",
-                      drive->name, drive->id->model);         
-       }
-       else
-               drive->using_dma = 1;
+                                   drive->name, drive->id->model);
 
-       if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
-               return 0;
-
-       return -1;
+       return drive->hwif->mwdma_mask;
 }
 
 static int auide_dma_test_irq(ide_drive_t *drive)
@@ -403,26 +371,10 @@ static int auide_dma_test_irq(ide_drive_t *drive)
        return 0;
 }
 
-static void auide_dma_host_on(ide_drive_t *drive)
-{
-}
-
-static int auide_dma_on(ide_drive_t *drive)
-{
-       drive->using_dma = 1;
-
-       return 0;
-}
-
-static void auide_dma_host_off(ide_drive_t *drive)
+static void auide_dma_host_set(ide_drive_t *drive, int on)
 {
 }
 
-static void auide_dma_off_quietly(ide_drive_t *drive)
-{
-       drive->using_dma = 0;
-}
-
 static void auide_dma_lost_irq(ide_drive_t *drive)
 {
        printk(KERN_ERR "%s: IRQ lost\n", drive->name);
@@ -528,7 +480,7 @@ static int auide_ddma_init(_auide_hwif *auide) {
        auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
                                                             NUM_DESCRIPTORS);
  
-       hwif->dmatable_cpu = dma_alloc_coherent(auide->dev,
+       hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev,
                                                PRD_ENTRIES * PRD_BYTES,        /* 1 Page */
                                                &hwif->dmatable_dma, GFP_KERNEL);
        
@@ -605,8 +557,9 @@ static int au_ide_probe(struct device *dev)
        _auide_hwif *ahwif = &auide_hwif;
        ide_hwif_t *hwif;
        struct resource *res;
-       hw_regs_t *hw;
        int ret = 0;
+       u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
+       hw_regs_t hw;
 
 #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
        char *mode = "MWDMA2";
@@ -615,9 +568,6 @@ static int au_ide_probe(struct device *dev)
 #endif
 
        memset(&auide_hwif, 0, sizeof(_auide_hwif));
-       auide_hwif.dev                  = 0;
-
-       ahwif->dev = dev;
        ahwif->irq = platform_get_irq(pdev, 0);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -648,12 +598,15 @@ static int au_ide_probe(struct device *dev)
        /* FIXME:  This might possibly break PCMCIA IDE devices */
 
        hwif                            = &ide_hwifs[pdev->id];
-       hw                              = &hwif->hw;
-       hwif->irq = hw->irq             = ahwif->irq;
-       hwif->chipset                   = ide_au1xxx;
 
-       auide_setup_ports(hw, ahwif);
-       memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
+       memset(&hw, 0, sizeof(hw));
+       auide_setup_ports(&hw, ahwif);
+       hw.irq = ahwif->irq;
+       hw.chipset = ide_au1xxx;
+
+       ide_init_port_hw(hwif, &hw);
+
+       hwif->dev = dev;
 
        hwif->ultra_mask                = 0x0;  /* Disable Ultra DMA */
 #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
@@ -667,7 +620,6 @@ static int au_ide_probe(struct device *dev)
        hwif->pio_mask = ATA_PIO4;
        hwif->host_flags = IDE_HFLAG_POST_SET_MODE;
 
-       hwif->noprobe = 0;
        hwif->drives[0].unmask          = 1;
        hwif->drives[1].unmask          = 1;
 
@@ -689,36 +641,27 @@ static int au_ide_probe(struct device *dev)
        hwif->set_dma_mode              = &auide_set_dma_mode;
 
 #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
-       hwif->dma_off_quietly           = &auide_dma_off_quietly;
        hwif->dma_timeout               = &auide_dma_timeout;
 
-       hwif->ide_dma_check             = &auide_dma_check;
+       hwif->mdma_filter               = &auide_mdma_filter;
+
+       hwif->dma_host_set              = &auide_dma_host_set;
        hwif->dma_exec_cmd              = &auide_dma_exec_cmd;
        hwif->dma_start                 = &auide_dma_start;
        hwif->ide_dma_end               = &auide_dma_end;
        hwif->dma_setup                 = &auide_dma_setup;
        hwif->ide_dma_test_irq          = &auide_dma_test_irq;
-       hwif->dma_host_off              = &auide_dma_host_off;
-       hwif->dma_host_on               = &auide_dma_host_on;
        hwif->dma_lost_irq              = &auide_dma_lost_irq;
-       hwif->ide_dma_on                = &auide_dma_on;
-
-       hwif->autodma                   = 1;
-       hwif->drives[0].autodma         = hwif->autodma;
-       hwif->drives[1].autodma         = hwif->autodma;
-       hwif->atapi_dma                 = 1;
-
-#else /* !CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
-       hwif->autodma                   = 0;
+#endif
        hwif->channel                   = 0;
-       hwif->hold                      = 1;
        hwif->select_data               = 0;    /* no chipset-specific code */
        hwif->config_data               = 0;    /* no chipset-specific code */
 
-       hwif->drives[0].autodma         = 0;
        hwif->drives[0].autotune        = 1;    /* 1=autotune, 2=noautotune, 0=default */
-#endif
-       hwif->drives[0].no_io_32bit     = 1;   
+       hwif->drives[1].autotune        = 1;
+
+       hwif->drives[0].no_io_32bit     = 1;
+       hwif->drives[1].no_io_32bit     = 1;
 
        auide_hwif.hwif                 = hwif;
        hwif->hwif_data                 = &auide_hwif;
@@ -728,9 +671,9 @@ static int au_ide_probe(struct device *dev)
        dbdma_init_done = 1;
 #endif
 
-       probe_hwif_init(hwif);
+       idx[0] = hwif->index;
 
-       ide_proc_register_port(hwif);
+       ide_device_add(idx);
 
        dev_set_drvdata(dev, hwif);