pata_cs5520: remove dead VDMA support
[safe/jmp/linux-2.6] / drivers / ata / sata_sx4.c
index 9f9f7b3..bbcf970 100644 (file)
                submit ATA packet to hardware
                hardware executes ATA WRITE command, w/ data in DIMM
                hardware raises interrupt
-       
+
        and each READ looks like this:
 
                submit ATA packet to hardware
                hardware executes ATA READ command, w/ data in DIMM
                hardware raises interrupt
-       
+
                submit HDMA packet to hardware
                hardware copies data from DIMM to system memory
                hardware raises interrupt
@@ -193,6 +193,7 @@ enum {
                                          PDC_TIMER_MASK_INT,
 };
 
+#define ECC_ERASE_BUF_SZ (128 * 1024)
 
 struct pdc_port_priv {
        u8                      dimm_buf[(ATA_PRD_SZ * ATA_MAX_PRD) + 512];
@@ -212,9 +213,10 @@ struct pdc_host_priv {
 };
 
 
-static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
-static void pdc_eng_timeout(struct ata_port *ap);
-static void pdc_20621_phy_reset (struct ata_port *ap);
+static int pdc_sata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
+static void pdc_error_handler(struct ata_port *ap);
+static void pdc_freeze(struct ata_port *ap);
+static void pdc_thaw(struct ata_port *ap);
 static int pdc_port_start(struct ata_port *ap);
 static void pdc20621_qc_prep(struct ata_queued_cmd *qc);
 static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
@@ -232,41 +234,39 @@ static void pdc20621_get_from_dimm(struct ata_host *host,
 static void pdc20621_put_to_dimm(struct ata_host *host,
                                 void *psource, u32 offset, u32 size);
 static void pdc20621_irq_clear(struct ata_port *ap);
-static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
+static unsigned int pdc20621_qc_issue(struct ata_queued_cmd *qc);
+static int pdc_softreset(struct ata_link *link, unsigned int *class,
+                        unsigned long deadline);
+static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
+static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
 
 
 static struct scsi_host_template pdc_sata_sht = {
-       .module                 = THIS_MODULE,
-       .name                   = DRV_NAME,
-       .ioctl                  = ata_scsi_ioctl,
-       .queuecommand           = ata_scsi_queuecmd,
-       .can_queue              = ATA_DEF_QUEUE,
-       .this_id                = ATA_SHT_THIS_ID,
+       ATA_BASE_SHT(DRV_NAME),
        .sg_tablesize           = LIBATA_MAX_PRD,
-       .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
-       .emulated               = ATA_SHT_EMULATED,
-       .use_clustering         = ATA_SHT_USE_CLUSTERING,
-       .proc_name              = DRV_NAME,
        .dma_boundary           = ATA_DMA_BOUNDARY,
-       .slave_configure        = ata_scsi_slave_config,
-       .slave_destroy          = ata_scsi_slave_destroy,
-       .bios_param             = ata_std_bios_param,
 };
 
-static const struct ata_port_operations pdc_20621_ops = {
-       .tf_load                = pdc_tf_load_mmio,
-       .tf_read                = ata_tf_read,
-       .check_status           = ata_check_status,
-       .exec_command           = pdc_exec_command_mmio,
-       .dev_select             = ata_std_dev_select,
-       .phy_reset              = pdc_20621_phy_reset,
+/* TODO: inherit from base port_ops after converting to new EH */
+static struct ata_port_operations pdc_20621_ops = {
+       .inherits               = &ata_sff_port_ops,
+
+       .check_atapi_dma        = pdc_check_atapi_dma,
        .qc_prep                = pdc20621_qc_prep,
-       .qc_issue               = pdc20621_qc_issue_prot,
-       .data_xfer              = ata_data_xfer,
-       .eng_timeout            = pdc_eng_timeout,
-       .irq_clear              = pdc20621_irq_clear,
-       .irq_on                 = ata_irq_on,
+       .qc_issue               = pdc20621_qc_issue,
+
+       .freeze                 = pdc_freeze,
+       .thaw                   = pdc_thaw,
+       .softreset              = pdc_softreset,
+       .error_handler          = pdc_error_handler,
+       .lost_interrupt         = ATA_OP_NULL,
+       .post_internal_cmd      = pdc_post_internal_cmd,
+
        .port_start             = pdc_port_start,
+
+       .sff_tf_load            = pdc_tf_load_mmio,
+       .sff_exec_command       = pdc_exec_command_mmio,
+       .sff_irq_clear          = pdc20621_irq_clear,
 };
 
 static const struct ata_port_info pdc_port_info[] = {
@@ -275,8 +275,8 @@ static const struct ata_port_info pdc_port_info[] = {
                .flags          = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
                                  ATA_FLAG_SRST | ATA_FLAG_MMIO |
                                  ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING,
-               .pio_mask       = 0x1f, /* pio0-4 */
-               .mwdma_mask     = 0x07, /* mwdma0-2 */
+               .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
                .udma_mask      = ATA_UDMA6,
                .port_ops       = &pdc_20621_ops,
        },
@@ -320,21 +320,13 @@ static int pdc_port_start(struct ata_port *ap)
        return 0;
 }
 
-static void pdc_20621_phy_reset (struct ata_port *ap)
-{
-       VPRINTK("ENTER\n");
-        ap->cbl = ATA_CBL_SATA;
-        ata_port_probe(ap);
-        ata_bus_reset(ap);
-}
-
 static inline void pdc20621_ata_sg(struct ata_taskfile *tf, u8 *buf,
-                                          unsigned int portno,
+                                  unsigned int portno,
                                           unsigned int total_len)
 {
        u32 addr;
        unsigned int dw = PDC_DIMM_APKT_PRD >> 2;
-       u32 *buf32 = (u32 *) buf;
+       __le32 *buf32 = (__le32 *) buf;
 
        /* output ATA packet S/G table */
        addr = PDC_20621_DIMM_BASE + PDC_20621_DIMM_DATA +
@@ -351,12 +343,12 @@ static inline void pdc20621_ata_sg(struct ata_taskfile *tf, u8 *buf,
 }
 
 static inline void pdc20621_host_sg(struct ata_taskfile *tf, u8 *buf,
-                                           unsigned int portno,
+                                   unsigned int portno,
                                            unsigned int total_len)
 {
        u32 addr;
        unsigned int dw = PDC_DIMM_HPKT_PRD >> 2;
-       u32 *buf32 = (u32 *) buf;
+       __le32 *buf32 = (__le32 *) buf;
 
        /* output Host DMA packet S/G table */
        addr = PDC_20621_DIMM_BASE + PDC_20621_DIMM_DATA +
@@ -377,7 +369,7 @@ static inline unsigned int pdc20621_ata_pkt(struct ata_taskfile *tf,
                                            unsigned int portno)
 {
        unsigned int i, dw;
-       u32 *buf32 = (u32 *) buf;
+       __le32 *buf32 = (__le32 *) buf;
        u8 dev_reg;
 
        unsigned int dimm_sg = PDC_20621_DIMM_BASE +
@@ -429,7 +421,8 @@ static inline void pdc20621_host_pkt(struct ata_taskfile *tf, u8 *buf,
                                     unsigned int portno)
 {
        unsigned int dw;
-       u32 tmp, *buf32 = (u32 *) buf;
+       u32 tmp;
+       __le32 *buf32 = (__le32 *) buf;
 
        unsigned int host_sg = PDC_20621_DIMM_BASE +
                               (PDC_DIMM_WINDOW_STEP * portno) +
@@ -473,8 +466,8 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
        void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
        void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
        unsigned int portno = ap->port_no;
-       unsigned int i, idx, total_len = 0, sgt_len;
-       u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
+       unsigned int i, si, idx, total_len = 0, sgt_len;
+       __le32 *buf = (__le32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
 
        WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP));
 
@@ -487,7 +480,7 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
         * Build S/G table
         */
        idx = 0;
-       ata_for_each_sg(sg, qc) {
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
                buf[idx++] = cpu_to_le32(sg_dma_address(sg));
                buf[idx++] = cpu_to_le32(sg_dma_len(sg));
                total_len += sg_dma_len(sg);
@@ -692,15 +685,18 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
        }
 }
 
-static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
+static unsigned int pdc20621_qc_issue(struct ata_queued_cmd *qc)
 {
        switch (qc->tf.protocol) {
-       case ATA_PROT_DMA:
        case ATA_PROT_NODATA:
+               if (qc->tf.flags & ATA_TFLAG_POLLING)
+                       break;
+               /*FALLTHROUGH*/
+       case ATA_PROT_DMA:
                pdc20621_packet_start(qc);
                return 0;
 
-       case ATA_PROT_ATAPI_DMA:
+       case ATAPI_PROT_DMA:
                BUG();
                break;
 
@@ -708,11 +704,11 @@ static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
                break;
        }
 
-       return ata_qc_issue_prot(qc);
+       return ata_sff_qc_issue(qc);
 }
 
-static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
-                                          struct ata_queued_cmd *qc,
+static inline unsigned int pdc20621_host_intr(struct ata_port *ap,
+                                         struct ata_queued_cmd *qc,
                                          unsigned int doing_hdma,
                                          void __iomem *mmio)
 {
@@ -780,7 +776,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
        /* command completion, but no data xfer */
        } else if (qc->tf.protocol == ATA_PROT_NODATA) {
 
-               status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
+               status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
                DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status);
                qc->err_mask |= ac_err_mask(status);
                ata_qc_complete(qc);
@@ -795,15 +791,10 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
 
 static void pdc20621_irq_clear(struct ata_port *ap)
 {
-       struct ata_host *host = ap->host;
-       void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
-
-       mmio += PDC_CHIP0_OFS;
-
-       readl(mmio + PDC_20621_SEQMASK);
+       ioread8(ap->ioaddr.status_addr);
 }
 
-static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance)
+static irqreturn_t pdc20621_interrupt(int irq, void *dev_instance)
 {
        struct ata_host *host = dev_instance;
        struct ata_port *ap;
@@ -836,9 +827,9 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance)
                return IRQ_NONE;
        }
 
-        spin_lock(&host->lock);
+       spin_lock(&host->lock);
 
-        for (i = 1; i < 9; i++) {
+       for (i = 1; i < 9; i++) {
                port_no = i - 1;
                if (port_no > 3)
                        port_no -= 4;
@@ -859,7 +850,7 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance)
                }
        }
 
-        spin_unlock(&host->lock);
+       spin_unlock(&host->lock);
 
        VPRINTK("mask == 0x%x\n", mask);
 
@@ -868,55 +859,128 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance)
        return IRQ_RETVAL(handled);
 }
 
-static void pdc_eng_timeout(struct ata_port *ap)
+static void pdc_freeze(struct ata_port *ap)
 {
-       u8 drv_stat;
-       struct ata_host *host = ap->host;
-       struct ata_queued_cmd *qc;
-       unsigned long flags;
+       void __iomem *mmio = ap->ioaddr.cmd_addr;
+       u32 tmp;
 
-       DPRINTK("ENTER\n");
+       /* FIXME: if all 4 ATA engines are stopped, also stop HDMA engine */
 
-       spin_lock_irqsave(&host->lock, flags);
+       tmp = readl(mmio + PDC_CTLSTAT);
+       tmp |= PDC_MASK_INT;
+       tmp &= ~PDC_DMA_ENABLE;
+       writel(tmp, mmio + PDC_CTLSTAT);
+       readl(mmio + PDC_CTLSTAT); /* flush */
+}
 
-       qc = ata_qc_from_tag(ap, ap->link.active_tag);
+static void pdc_thaw(struct ata_port *ap)
+{
+       void __iomem *mmio = ap->ioaddr.cmd_addr;
+       u32 tmp;
 
-       switch (qc->tf.protocol) {
-       case ATA_PROT_DMA:
-       case ATA_PROT_NODATA:
-               ata_port_printk(ap, KERN_ERR, "command timeout\n");
-               qc->err_mask |= __ac_err_mask(ata_wait_idle(ap));
-               break;
+       /* FIXME: start HDMA engine, if zero ATA engines running */
 
-       default:
-               drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
+       /* clear IRQ */
+       ioread8(ap->ioaddr.status_addr);
 
-               ata_port_printk(ap, KERN_ERR,
-                               "unknown timeout, cmd 0x%x stat 0x%x\n",
-                               qc->tf.command, drv_stat);
+       /* turn IRQ back on */
+       tmp = readl(mmio + PDC_CTLSTAT);
+       tmp &= ~PDC_MASK_INT;
+       writel(tmp, mmio + PDC_CTLSTAT);
+       readl(mmio + PDC_CTLSTAT); /* flush */
+}
 
-               qc->err_mask |= ac_err_mask(drv_stat);
-               break;
+static void pdc_reset_port(struct ata_port *ap)
+{
+       void __iomem *mmio = ap->ioaddr.cmd_addr + PDC_CTLSTAT;
+       unsigned int i;
+       u32 tmp;
+
+       /* FIXME: handle HDMA copy engine */
+
+       for (i = 11; i > 0; i--) {
+               tmp = readl(mmio);
+               if (tmp & PDC_RESET)
+                       break;
+
+               udelay(100);
+
+               tmp |= PDC_RESET;
+               writel(tmp, mmio);
        }
 
-       spin_unlock_irqrestore(&host->lock, flags);
-       ata_eh_qc_complete(qc);
-       DPRINTK("EXIT\n");
+       tmp &= ~PDC_RESET;
+       writel(tmp, mmio);
+       readl(mmio);    /* flush */
+}
+
+static int pdc_softreset(struct ata_link *link, unsigned int *class,
+                        unsigned long deadline)
+{
+       pdc_reset_port(link->ap);
+       return ata_sff_softreset(link, class, deadline);
+}
+
+static void pdc_error_handler(struct ata_port *ap)
+{
+       if (!(ap->pflags & ATA_PFLAG_FROZEN))
+               pdc_reset_port(ap);
+
+       ata_std_error_handler(ap);
+}
+
+static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+
+       /* make DMA engine forget about the failed command */
+       if (qc->flags & ATA_QCFLAG_FAILED)
+               pdc_reset_port(ap);
+}
+
+static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
+{
+       u8 *scsicmd = qc->scsicmd->cmnd;
+       int pio = 1; /* atapi dma off by default */
+
+       /* Whitelist commands that may use DMA. */
+       switch (scsicmd[0]) {
+       case WRITE_12:
+       case WRITE_10:
+       case WRITE_6:
+       case READ_12:
+       case READ_10:
+       case READ_6:
+       case 0xad: /* READ_DVD_STRUCTURE */
+       case 0xbe: /* READ_CD */
+               pio = 0;
+       }
+       /* -45150 (FFFF4FA2) to -1 (FFFFFFFF) shall use PIO mode */
+       if (scsicmd[0] == WRITE_10) {
+               unsigned int lba =
+                       (scsicmd[2] << 24) |
+                       (scsicmd[3] << 16) |
+                       (scsicmd[4] << 8) |
+                       scsicmd[5];
+               if (lba >= 0xFFFF4FA2)
+                       pio = 1;
+       }
+       return pio;
 }
 
 static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
 {
-       WARN_ON (tf->protocol == ATA_PROT_DMA ||
-                tf->protocol == ATA_PROT_NODATA);
-       ata_tf_load(ap, tf);
+       WARN_ON(tf->protocol == ATA_PROT_DMA ||
+               tf->protocol == ATAPI_PROT_DMA);
+       ata_sff_tf_load(ap, tf);
 }
 
 
 static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
 {
-       WARN_ON (tf->protocol == ATA_PROT_DMA ||
-                tf->protocol == ATA_PROT_NODATA);
-       ata_exec_command(ap, tf);
+       WARN_ON(tf->protocol == ATA_PROT_DMA ||
+               tf->protocol == ATAPI_PROT_DMA);
+       ata_sff_exec_command(ap, tf);
 }
 
 
@@ -953,7 +1017,7 @@ static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
        mmio += PDC_CHIP0_OFS;
 
        page_mask = 0x00;
-       window_size = 0x2000 * 4; /* 32K byte uchar size */
+       window_size = 0x2000 * 4; /* 32K byte uchar size */
        idx = (u16) (offset / window_size);
 
        writel(0x01, mmio + PDC_GENERAL_CTLR);
@@ -979,7 +1043,7 @@ static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
                              window_size / 4);
                psource += window_size;
                size -= window_size;
-               idx ++;
+               idx++;
        }
 
        if (size) {
@@ -1008,7 +1072,7 @@ static void pdc20621_put_to_dimm(struct ata_host *host, void *psource,
        mmio += PDC_CHIP0_OFS;
 
        page_mask = 0x00;
-       window_size = 0x2000 * 4;       /* 32K byte uchar size */
+       window_size = 0x2000 * 4;       /* 32K byte uchar size */
        idx = (u16) (offset / window_size);
 
        writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
@@ -1031,7 +1095,7 @@ static void pdc20621_put_to_dimm(struct ata_host *host, void *psource,
                readl(mmio + PDC_GENERAL_CTLR);
                psource += window_size;
                size -= window_size;
-               idx ++;
+               idx++;
        }
 
        if (size) {
@@ -1050,7 +1114,7 @@ static unsigned int pdc20621_i2c_read(struct ata_host *host, u32 device,
        void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
        u32 i2creg  = 0;
        u32 status;
-       u32 count =0;
+       u32 count = 0;
 
        /* hard-code chip #0 */
        mmio += PDC_CHIP0_OFS;
@@ -1082,21 +1146,21 @@ static unsigned int pdc20621_i2c_read(struct ata_host *host, u32 device,
 
 static int pdc20621_detect_dimm(struct ata_host *host)
 {
-       u32 data=0 ;
+       u32 data = 0;
        if (pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
                             PDC_DIMM_SPD_SYSTEM_FREQ, &data)) {
-               if (data == 100)
+               if (data == 100)
                        return 100;
-       } else
+       } else
                return 0;
 
        if (pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS, 9, &data)) {
-               if(data <= 0x75)
+               if (data <= 0x75)
                        return 133;
-       } else
+       } else
                return 0;
 
-       return 0;
+       return 0;
 }
 
 
@@ -1104,8 +1168,8 @@ static int pdc20621_prog_dimm0(struct ata_host *host)
 {
        u32 spd0[50];
        u32 data = 0;
-       int size, i;
-       u8 bdimmsize;
+       int size, i;
+       u8 bdimmsize;
        void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
        static const struct {
                unsigned int reg;
@@ -1128,40 +1192,40 @@ static int pdc20621_prog_dimm0(struct ata_host *host)
        /* hard-code chip #0 */
        mmio += PDC_CHIP0_OFS;
 
-       for(i=0; i<ARRAY_SIZE(pdc_i2c_read_data); i++)
+       for (i = 0; i < ARRAY_SIZE(pdc_i2c_read_data); i++)
                pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
                                  pdc_i2c_read_data[i].reg,
                                  &spd0[pdc_i2c_read_data[i].ofs]);
 
-       data |= (spd0[4] - 8) | ((spd0[21] != 0) << 3) | ((spd0[3]-11) << 4);
-       data |= ((spd0[17] / 4) << 6) | ((spd0[5] / 2) << 7) |
+       data |= (spd0[4] - 8) | ((spd0[21] != 0) << 3) | ((spd0[3]-11) << 4);
+       data |= ((spd0[17] / 4) << 6) | ((spd0[5] / 2) << 7) |
                ((((spd0[27] + 9) / 10) - 1) << 8) ;
-       data |= (((((spd0[29] > spd0[28])
+       data |= (((((spd0[29] > spd0[28])
                    ? spd0[29] : spd0[28]) + 9) / 10) - 1) << 10;
-       data |= ((spd0[30] - spd0[29] + 9) / 10 - 2) << 12;
+       data |= ((spd0[30] - spd0[29] + 9) / 10 - 2) << 12;
 
-       if (spd0[18] & 0x08)
+       if (spd0[18] & 0x08)
                data |= ((0x03) << 14);
-       else if (spd0[18] & 0x04)
+       else if (spd0[18] & 0x04)
                data |= ((0x02) << 14);
-       else if (spd0[18] & 0x01)
+       else if (spd0[18] & 0x01)
                data |= ((0x01) << 14);
-       else
+       else
                data |= (0 << 14);
 
-       /*
+       /*
           Calculate the size of bDIMMSize (power of 2) and
           merge the DIMM size by program start/end address.
        */
 
-       bdimmsize = spd0[4] + (spd0[5] / 2) + spd0[3] + (spd0[17] / 2) + 3;
-       size = (1 << bdimmsize) >> 20;  /* size = xxx(MB) */
-       data |= (((size / 16) - 1) << 16);
-       data |= (0 << 23);
+       bdimmsize = spd0[4] + (spd0[5] / 2) + spd0[3] + (spd0[17] / 2) + 3;
+       size = (1 << bdimmsize) >> 20;  /* size = xxx(MB) */
+       data |= (((size / 16) - 1) << 16);
+       data |= (0 << 23);
        data |= 8;
-       writel(data, mmio + PDC_DIMM0_CONTROL);
+       writel(data, mmio + PDC_DIMM0_CONTROL);
        readl(mmio + PDC_DIMM0_CONTROL);
-       return size;
+       return size;
 }
 
 
@@ -1172,9 +1236,9 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_host *host)
        void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
 
        /* hard-code chip #0 */
-       mmio += PDC_CHIP0_OFS;
+       mmio += PDC_CHIP0_OFS;
 
-       /*
+       /*
          Set To Default : DIMM Module Global Control Register (0x022259F1)
          DIMM Arbitration Disable (bit 20)
          DIMM Data/Control Output Driving Selection (bit12 - bit15)
@@ -1193,40 +1257,39 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_host *host)
                writel(data, mmio + PDC_SDRAM_CONTROL);
                readl(mmio + PDC_SDRAM_CONTROL);
                printk(KERN_ERR "Local DIMM ECC Enabled\n");
-       }
+       }
 
-       /* DIMM Initialization Select/Enable (bit 18/19) */
-       data &= (~(1<<18));
-       data |= (1<<19);
-       writel(data, mmio + PDC_SDRAM_CONTROL);
+       /* DIMM Initialization Select/Enable (bit 18/19) */
+       data &= (~(1<<18));
+       data |= (1<<19);
+       writel(data, mmio + PDC_SDRAM_CONTROL);
 
-       error = 1;
-       for (i = 1; i <= 10; i++) {   /* polling ~5 secs */
+       error = 1;
+       for (i = 1; i <= 10; i++) {   /* polling ~5 secs */
                data = readl(mmio + PDC_SDRAM_CONTROL);
                if (!(data & (1<<19))) {
-                       error = 0;
-                       break;
+                       error = 0;
+                       break;
                }
                msleep(i*100);
-       }
-       return error;
+       }
+       return error;
 }
 
 
 static unsigned int pdc20621_dimm_init(struct ata_host *host)
 {
        int speed, size, length;
-       u32 addr,spd0,pci_status;
-       u32 tmp=0;
-       u32 time_period=0;
-       u32 tcount=0;
-       u32 ticks=0;
-       u32 clock=0;
-       u32 fparam=0;
+       u32 addr, spd0, pci_status;
+       u32 time_period = 0;
+       u32 tcount = 0;
+       u32 ticks = 0;
+       u32 clock = 0;
+       u32 fparam = 0;
        void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
 
        /* hard-code chip #0 */
-       mmio += PDC_CHIP0_OFS;
+       mmio += PDC_CHIP0_OFS;
 
        /* Initialize PLL based upon PCI Bus Frequency */
 
@@ -1254,7 +1317,7 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
           If SX4 is on PCI-X bus, after 3 seconds, the timer counter
           register should be >= (0xffffffff - 3x10^8).
        */
-       if(tcount >= PCI_X_TCOUNT) {
+       if (tcount >= PCI_X_TCOUNT) {
                ticks = (time_period - tcount);
                VPRINTK("Num counters 0x%x (%d)\n", ticks, ticks);
 
@@ -1285,41 +1348,43 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
        if (!(speed = pdc20621_detect_dimm(host))) {
                printk(KERN_ERR "Detect Local DIMM Fail\n");
                return 1;       /* DIMM error */
-       }
-       VPRINTK("Local DIMM Speed = %d\n", speed);
+       }
+       VPRINTK("Local DIMM Speed = %d\n", speed);
 
-       /* Programming DIMM0 Module Control Register (index_CID0:80h) */
+       /* Programming DIMM0 Module Control Register (index_CID0:80h) */
        size = pdc20621_prog_dimm0(host);
-       VPRINTK("Local DIMM Size = %dMB\n",size);
+       VPRINTK("Local DIMM Size = %dMB\n", size);
 
-       /* Programming DIMM Module Global Control Register (index_CID0:88h) */
+       /* Programming DIMM Module Global Control Register (index_CID0:88h) */
        if (pdc20621_prog_dimm_global(host)) {
                printk(KERN_ERR "Programming DIMM Module Global Control Register Fail\n");
                return 1;
-       }
+       }
 
 #ifdef ATA_VERBOSE_DEBUG
        {
-               u8 test_parttern1[40] = {0x55,0xAA,'P','r','o','m','i','s','e',' ',
-                               'N','o','t',' ','Y','e','t',' ','D','e','f','i','n','e','d',' ',
-                                '1','.','1','0',
-                               '9','8','0','3','1','6','1','2',0,0};
+               u8 test_parttern1[40] =
+                       {0x55,0xAA,'P','r','o','m','i','s','e',' ',
+                       'N','o','t',' ','Y','e','t',' ',
+                       'D','e','f','i','n','e','d',' ',
+                       '1','.','1','0',
+                       '9','8','0','3','1','6','1','2',0,0};
                u8 test_parttern2[40] = {0};
 
-               pdc20621_put_to_dimm(host, (void *) test_parttern2, 0x10040, 40);
-               pdc20621_put_to_dimm(host, (void *) test_parttern2, 0x40, 40);
+               pdc20621_put_to_dimm(host, test_parttern2, 0x10040, 40);
+               pdc20621_put_to_dimm(host, test_parttern2, 0x40, 40);
 
-               pdc20621_put_to_dimm(host, (void *) test_parttern1, 0x10040, 40);
-               pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x40, 40);
+               pdc20621_put_to_dimm(host, test_parttern1, 0x10040, 40);
+               pdc20621_get_from_dimm(host, test_parttern2, 0x40, 40);
                printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
                       test_parttern2[1], &(test_parttern2[2]));
-               pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x10040,
+               pdc20621_get_from_dimm(host, test_parttern2, 0x10040,
                                       40);
                printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
                       test_parttern2[1], &(test_parttern2[2]));
 
-               pdc20621_put_to_dimm(host, (void *) test_parttern1, 0x40, 40);
-               pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x40, 40);
+               pdc20621_put_to_dimm(host, test_parttern1, 0x40, 40);
+               pdc20621_get_from_dimm(host, test_parttern2, 0x40, 40);
                printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
                       test_parttern2[1], &(test_parttern2[2]));
        }
@@ -1330,14 +1395,17 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
        pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
                          PDC_DIMM_SPD_TYPE, &spd0);
        if (spd0 == 0x02) {
+               void *buf;
                VPRINTK("Start ECC initialization\n");
                addr = 0;
                length = size * 1024 * 1024;
+               buf = kzalloc(ECC_ERASE_BUF_SZ, GFP_KERNEL);
                while (addr < length) {
-                       pdc20621_put_to_dimm(host, (void *) &tmp, addr,
-                                            sizeof(u32));
-                       addr += sizeof(u32);
+                       pdc20621_put_to_dimm(host, buf, addr,
+                                            ECC_ERASE_BUF_SZ);
+                       addr += ECC_ERASE_BUF_SZ;
                }
+               kfree(buf);
                VPRINTK("Finish ECC initialization\n");
        }
        return 0;
@@ -1375,7 +1443,8 @@ static void pdc_20621_init(struct ata_host *host)
        readl(mmio + PDC_HDMA_CTLSTAT);         /* flush */
 }
 
-static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
+static int pdc_sata_init_one(struct pci_dev *pdev,
+                            const struct pci_device_id *ent)
 {
        static int printed_version;
        const struct ata_port_info *ppi[] =