ide-floppy: allocate only toplevel packet commands
[safe/jmp/linux-2.6] / drivers / ide / tx4938ide.c
index 9c518e7..b4ef218 100644 (file)
@@ -26,12 +26,13 @@ static void tx4938ide_tune_ebusc(unsigned int ebus_ch,
        unsigned int sp = (cr >> 4) & 3;
        unsigned int clock = gbus_clock / (4 - sp);
        unsigned int cycle = 1000000000 / clock;
-       unsigned int wt, shwt;
+       unsigned int shwt;
+       int wt;
 
        /* Minimum DIOx- active time */
        wt = DIV_ROUND_UP(t->act8b, cycle) - 2;
        /* IORDY setup time: 35ns */
-       wt = max(wt, DIV_ROUND_UP(35, cycle));
+       wt = max_t(int, wt, DIV_ROUND_UP(35, cycle));
        /* actual wait-cycle is max(wt & ~1, 1) */
        if (wt > 2 && (wt & 1))
                wt++;
@@ -180,7 +181,7 @@ static void tx4938ide_input_data_swap(ide_drive_t *drive, struct request *rq,
 
        while (count--)
                *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port));
-       __ide_flush_dcache_range((unsigned long)buf, count * 2);
+       __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
 }
 
 static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq,
@@ -194,7 +195,7 @@ static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq,
                __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port);
                ptr++;
        }
-       __ide_flush_dcache_range((unsigned long)buf, count * 2);
+       __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
 }
 
 static const struct ide_tp_ops tx4938ide_tp_ops = {
@@ -215,16 +216,17 @@ static const struct ide_tp_ops tx4938ide_tp_ops = {
 #endif /* __BIG_ENDIAN */
 
 static const struct ide_port_ops tx4938ide_port_ops = {
-       .set_pio_mode = tx4938ide_set_pio_mode,
+       .set_pio_mode           = tx4938ide_set_pio_mode,
 };
 
 static const struct ide_port_info tx4938ide_port_info __initdata = {
-       .port_ops = &tx4938ide_port_ops,
+       .port_ops               = &tx4938ide_port_ops,
 #ifdef __BIG_ENDIAN
-       .tp_ops = &tx4938ide_tp_ops,
+       .tp_ops                 = &tx4938ide_tp_ops,
 #endif
-       .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
-       .pio_mask = ATA_PIO5,
+       .host_flags             = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
+       .pio_mask               = ATA_PIO5,
+       .chipset                = ide_generic,
 };
 
 static int __init tx4938ide_probe(struct platform_device *pdev)
@@ -235,7 +237,7 @@ static int __init tx4938ide_probe(struct platform_device *pdev)
        struct resource *res;
        struct tx4938ide_platform_info *pdata = pdev->dev.platform_data;
        int irq, ret, i;
-       unsigned long mapbase;
+       unsigned long mapbase, mapctl;
        struct ide_port_info d = tx4938ide_port_info;
 
        irq = platform_get_irq(pdev, 0);
@@ -249,38 +251,43 @@ static int __init tx4938ide_probe(struct platform_device *pdev)
                                     res->end - res->start + 1, "tx4938ide"))
                return -EBUSY;
        mapbase = (unsigned long)devm_ioremap(&pdev->dev, res->start,
-                                             res->end - res->start + 1);
-       if (!mapbase)
+                                             8 << pdata->ioport_shift);
+       mapctl = (unsigned long)devm_ioremap(&pdev->dev,
+                                            res->start + 0x10000 +
+                                            (6 << pdata->ioport_shift),
+                                            1 << pdata->ioport_shift);
+       if (!mapbase || !mapctl)
                return -EBUSY;
 
        memset(&hw, 0, sizeof(hw));
        if (pdata->ioport_shift) {
                unsigned long port = mapbase;
+               unsigned long ctl = mapctl;
 
                hw.io_ports_array[0] = port;
 #ifdef __BIG_ENDIAN
                port++;
+               ctl++;
 #endif
                for (i = 1; i <= 7; i++)
                        hw.io_ports_array[i] =
                                port + (i << pdata->ioport_shift);
-               hw.io_ports.ctl_addr =
-                       port + 0x10000 + (6 << pdata->ioport_shift);
+               hw.io_ports.ctl_addr = ctl;
        } else
-               ide_std_init_ports(&hw, mapbase, mapbase + 0x10006);
+               ide_std_init_ports(&hw, mapbase, mapctl);
        hw.irq = irq;
        hw.dev = &pdev->dev;
 
-       pr_info("TX4938 IDE interface (base %#lx, irq %d)\n", mapbase, hw.irq);
+       pr_info("TX4938 IDE interface (base %#lx, ctl %#lx, irq %d)\n",
+               mapbase, mapctl, hw.irq);
        if (pdata->gbus_clock)
                tx4938ide_tune_ebusc(pdata->ebus_ch, pdata->gbus_clock, 0);
        else
                d.port_ops = NULL;
        ret = ide_host_add(&d, hws, &host);
-       if (ret)
-               return ret;
-       platform_set_drvdata(pdev, host);
-       return 0;
+       if (!ret)
+               platform_set_drvdata(pdev, host);
+       return ret;
 }
 
 static int __exit tx4938ide_remove(struct platform_device *pdev)