it821x: use ->pio_mode value to determine pair device speed
[safe/jmp/linux-2.6] / drivers / ide / au1xxx-ide.c
index 11f2c8f..e2fd378 100644 (file)
@@ -50,7 +50,7 @@ static _auide_hwif auide_hwif;
 
 #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
 
-void auide_insw(unsigned long port, void *addr, u32 count)
+static inline void auide_insw(unsigned long port, void *addr, u32 count)
 {
        _auide_hwif *ahwif = &auide_hwif;
        chan_tab_t *ctp;
@@ -68,7 +68,7 @@ void auide_insw(unsigned long port, void *addr, u32 count)
        ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
 }
 
-void auide_outsw(unsigned long port, void *addr, u32 count)
+static inline void auide_outsw(unsigned long port, void *addr, u32 count)
 {
        _auide_hwif *ahwif = &auide_hwif;
        chan_tab_t *ctp;
@@ -86,25 +86,24 @@ void auide_outsw(unsigned long port, void *addr, u32 count)
        ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
 }
 
-static void au1xxx_input_data(ide_drive_t *drive, struct request *rq,
+static void au1xxx_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
                              void *buf, unsigned int len)
 {
        auide_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
 }
 
-static void au1xxx_output_data(ide_drive_t *drive, struct request *rq,
+static void au1xxx_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
                               void *buf, unsigned int len)
 {
        auide_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
 }
 #endif
 
-static void au1xxx_set_pio_mode(ide_drive_t *drive, const u8 pio)
+static void au1xxx_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
 {
        int mem_sttime = 0, mem_stcfg = au_readl(MEM_STCFG2);
 
-       /* set pio mode! */
-       switch(pio) {
+       switch (drive->pio_mode - XFER_PIO_0) {
        case 0:
                mem_sttime = SBC_IDE_TIMING(PIO0);
 
@@ -161,11 +160,11 @@ static void au1xxx_set_pio_mode(ide_drive_t *drive, const u8 pio)
        au_writel(mem_stcfg,MEM_STCFG2);
 }
 
-static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
+static void auide_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
 {
        int mem_sttime = 0, mem_stcfg = au_readl(MEM_STCFG2);
 
-       switch(speed) {
+       switch (drive->dma_mode) {
 #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
        case XFER_MW_DMA_2:
                mem_sttime = SBC_IDE_TIMING(MDMA2);
@@ -209,23 +208,17 @@ 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_dmatable(ide_drive_t *drive)
+static int auide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
 {
-       int i, iswrite, count = 0;
        ide_hwif_t *hwif = drive->hwif;
-       struct request *rq = hwif->rq;
        _auide_hwif *ahwif = &auide_hwif;
        struct scatterlist *sg;
+       int i = cmd->sg_nents, count = 0;
+       int iswrite = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
 
-       iswrite = (rq_data_dir(rq) == WRITE);
        /* Save for interrupt context */
        ahwif->drive = drive;
 
-       hwif->sg_nents = i = ide_build_sglist(drive, rq);
-
-       if (!i)
-               return 0;
-
        /* fill the descriptors */
        sg = hwif->sg_table;
        while (i && sg_dma_len(sg)) {
@@ -242,7 +235,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
                        if (++count >= PRD_ENTRIES) {
                                printk(KERN_WARNING "%s: DMA table too small\n",
                                       drive->name);
-                               goto use_pio_instead;
+                               return 0;
                        }
 
                        /* Lets enable intr for the last descriptor only */
@@ -278,21 +271,11 @@ static int auide_build_dmatable(ide_drive_t *drive)
        if (count)
                return 1;
 
- use_pio_instead:
-       ide_destroy_dmatable(drive);
-
        return 0; /* revert to PIO for this request */
 }
 
 static int auide_dma_end(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = drive->hwif;
-
-       if (hwif->sg_nents) {
-               ide_destroy_dmatable(drive);
-               hwif->sg_nents = 0;
-       }
-
        return 0;
 }
 
@@ -301,23 +284,11 @@ static void auide_dma_start(ide_drive_t *drive )
 }
 
 
-static void auide_dma_exec_cmd(ide_drive_t *drive, u8 command)
+static int auide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
 {
-       /* issue cmd to drive */
-       ide_execute_command(drive, command, &ide_dma_intr,
-                           (2*WAIT_CMD), NULL);
-}
-
-static int auide_dma_setup(ide_drive_t *drive)
-{
-       struct request *rq = drive->hwif->rq;
-
-       if (!auide_build_dmatable(drive)) {
-               ide_map_sg(drive, rq);
+       if (auide_build_dmatable(drive, cmd) == 0)
                return 1;
-       }
 
-       drive->waiting_for_dma = 1;
        return 0;
 }
 
@@ -342,16 +313,11 @@ static void auide_dma_host_set(ide_drive_t *drive, int on)
 
 static void auide_ddma_tx_callback(int irq, void *param)
 {
-       _auide_hwif *ahwif = (_auide_hwif*)param;
-       ahwif->drive->waiting_for_dma = 0;
 }
 
 static void auide_ddma_rx_callback(int irq, void *param)
 {
-       _auide_hwif *ahwif = (_auide_hwif*)param;
-       ahwif->drive->waiting_for_dma = 0;
 }
-
 #endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
 
 static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 devwidth, u32 flags)
@@ -369,12 +335,10 @@ static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 de
 static const struct ide_dma_ops au1xxx_dma_ops = {
        .dma_host_set           = auide_dma_host_set,
        .dma_setup              = auide_dma_setup,
-       .dma_exec_cmd           = auide_dma_exec_cmd,
        .dma_start              = auide_dma_start,
        .dma_end                = auide_dma_end,
        .dma_test_irq           = auide_dma_test_irq,
        .dma_lost_irq           = ide_dma_lost_irq,
-       .dma_timeout            = ide_dma_timeout,
 };
 
 static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
@@ -484,7 +448,7 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
 }
 #endif
 
-static void auide_setup_ports(hw_regs_t *hw, _auide_hwif *ahwif)
+static void auide_setup_ports(struct ide_hw *hw, _auide_hwif *ahwif)
 {
        int i;
        unsigned long *ata_regs = hw->io_ports_array;
@@ -502,10 +466,9 @@ static const struct ide_tp_ops au1xxx_tp_ops = {
        .exec_command           = ide_exec_command,
        .read_status            = ide_read_status,
        .read_altstatus         = ide_read_altstatus,
-       .read_sff_dma_status    = ide_read_sff_dma_status,
-
-       .set_irq                = ide_set_irq,
+       .write_devctl           = ide_write_devctl,
 
+       .dev_select             = ide_dev_select,
        .tf_load                = ide_tf_load,
        .tf_read                = ide_tf_read,
 
@@ -535,16 +498,16 @@ static const struct ide_port_info au1xxx_port_info = {
 #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
        .mwdma_mask             = ATA_MWDMA2,
 #endif
+       .chipset                = ide_au1xxx,
 };
 
-static int au_ide_probe(struct device *dev)
+static int au_ide_probe(struct platform_device *dev)
 {
-       struct platform_device *pdev = to_platform_device(dev);
        _auide_hwif *ahwif = &auide_hwif;
        struct resource *res;
        struct ide_host *host;
        int ret = 0;
-       hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
+       struct ide_hw hw, *hws[] = { &hw };
 
 #if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
        char *mode = "MWDMA2";
@@ -553,29 +516,28 @@ static int au_ide_probe(struct device *dev)
 #endif
 
        memset(&auide_hwif, 0, sizeof(_auide_hwif));
-       ahwif->irq = platform_get_irq(pdev, 0);
+       ahwif->irq = platform_get_irq(dev, 0);
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 
        if (res == NULL) {
-               pr_debug("%s %d: no base address\n", DRV_NAME, pdev->id);
+               pr_debug("%s %d: no base address\n", DRV_NAME, dev->id);
                ret = -ENODEV;
                goto out;
        }
        if (ahwif->irq < 0) {
-               pr_debug("%s %d: no IRQ\n", DRV_NAME, pdev->id);
+               pr_debug("%s %d: no IRQ\n", DRV_NAME, dev->id);
                ret = -ENODEV;
                goto out;
        }
 
-       if (!request_mem_region(res->start, res->end - res->start + 1,
-                               pdev->name)) {
+       if (!request_mem_region(res->start, resource_size(res), dev->name)) {
                pr_debug("%s: request_mem_region failed\n", DRV_NAME);
                ret =  -EBUSY;
                goto out;
        }
 
-       ahwif->regbase = (u32)ioremap(res->start, res->end - res->start + 1);
+       ahwif->regbase = (u32)ioremap(res->start, resource_size(res));
        if (ahwif->regbase == 0) {
                ret = -ENOMEM;
                goto out;
@@ -584,16 +546,15 @@ static int au_ide_probe(struct device *dev)
        memset(&hw, 0, sizeof(hw));
        auide_setup_ports(&hw, ahwif);
        hw.irq = ahwif->irq;
-       hw.dev = dev;
-       hw.chipset = ide_au1xxx;
+       hw.dev = &dev->dev;
 
-       ret = ide_host_add(&au1xxx_port_info, hws, &host);
+       ret = ide_host_add(&au1xxx_port_info, hws, 1, &host);
        if (ret)
                goto out;
 
        auide_hwif.hwif = host->ports[0];
 
-       dev_set_drvdata(dev, host);
+       platform_set_drvdata(dev, host);
 
        printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
 
@@ -601,38 +562,39 @@ static int au_ide_probe(struct device *dev)
        return ret;
 }
 
-static int au_ide_remove(struct device *dev)
+static int au_ide_remove(struct platform_device *dev)
 {
-       struct platform_device *pdev = to_platform_device(dev);
        struct resource *res;
-       struct ide_host *host = dev_get_drvdata(dev);
+       struct ide_host *host = platform_get_drvdata(dev);
        _auide_hwif *ahwif = &auide_hwif;
 
        ide_host_remove(host);
 
        iounmap((void *)ahwif->regbase);
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       release_mem_region(res->start, res->end - res->start + 1);
+       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       release_mem_region(res->start, resource_size(res));
 
        return 0;
 }
 
-static struct device_driver au1200_ide_driver = {
-       .name           = "au1200-ide",
-       .bus            = &platform_bus_type,
+static struct platform_driver au1200_ide_driver = {
+       .driver = {
+               .name           = "au1200-ide",
+               .owner          = THIS_MODULE,
+       },
        .probe          = au_ide_probe,
        .remove         = au_ide_remove,
 };
 
 static int __init au_ide_init(void)
 {
-       return driver_register(&au1200_ide_driver);
+       return platform_driver_register(&au1200_ide_driver);
 }
 
 static void __exit au_ide_exit(void)
 {
-       driver_unregister(&au1200_ide_driver);
+       platform_driver_unregister(&au1200_ide_driver);
 }
 
 MODULE_LICENSE("GPL");