ar71xx: remove __dev{init,exit} annotations from kernel files
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / drivers / mtd / nand / ar934x_nfc.c
index 86899fd720c65c601dc4fc1e2a0963484a3dd6b2..e932491b922803fbdbb97e65992fb43c6ca41345 100644 (file)
 #define AR934X_NFC_DEV_READY_TIMEOUT   25 /* msecs */
 #define AR934X_NFC_DMA_READY_TIMEOUT   25 /* msecs */
 #define AR934X_NFC_DONE_TIMEOUT                1000
+#define AR934X_NFC_DMA_RETRIES         20
 
 #define AR934X_NFC_USE_IRQ             true
 #define AR934X_NFC_IRQ_MASK            AR934X_NFC_INT_DEV_RDY(0)
@@ -173,6 +174,7 @@ struct ar934x_nfc {
        struct device *parent;
        void __iomem *base;
        void (*select_chip)(int chip_no);
+       bool swap_dma;
        int irq;
        wait_queue_head_t irq_waitq;
 
@@ -189,6 +191,8 @@ struct ar934x_nfc {
        unsigned int buf_size;
        int buf_index;
 
+       bool read_id;
+
        int erase1_page_addr;
 
        int rndout_page_addr;
@@ -465,7 +469,7 @@ retry:
                        (write) ? "write" : "read", page_addr);
 
                ar934x_nfc_restart(nfc);
-               if (retries++ < 5)
+               if (retries++ < AR934X_NFC_DMA_RETRIES)
                        goto retry;
 
                dev_err(nfc->parent, "%s operation failed on page %d\n",
@@ -491,12 +495,12 @@ ar934x_nfc_send_readid(struct ar934x_nfc *nfc, unsigned command)
 
 static void
 ar934x_nfc_send_read(struct ar934x_nfc *nfc, unsigned command, int column,
-                    int page_addr, int len, bool oob)
+                    int page_addr, int len)
 {
        u32 cmd_reg;
 
-       nfc_dbg(nfc, "read, column=%d page=%d len=%d oob:%d\n",
-               column, page_addr, len, oob);
+       nfc_dbg(nfc, "read, column=%d page=%d len=%d\n",
+               column, page_addr, len);
 
        cmd_reg = (command & AR934X_NFC_CMD_CMD0_M) << AR934X_NFC_CMD_CMD0_S;
 
@@ -590,7 +594,10 @@ ar934x_nfc_read_status(struct ar934x_nfc *nfc)
        nfc_dbg(nfc, "read status, cmd:%08x status:%02x\n",
                cmd_reg, (status & 0xff));
 
-       nfc->buf[0 ^ 3] = status;
+       if (nfc->swap_dma)
+               nfc->buf[0 ^ 3] = status;
+       else
+               nfc->buf[0] = status;
 }
 
 static void
@@ -599,6 +606,7 @@ ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
 {
        struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
 
+       nfc->read_id = false;
        if (command != NAND_CMD_PAGEPROG)
                nfc->buf_index = 0;
 
@@ -608,6 +616,7 @@ ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
                break;
 
        case NAND_CMD_READID:
+               nfc->read_id = true;
                ar934x_nfc_send_readid(nfc, command);
                break;
 
@@ -615,12 +624,10 @@ ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
        case NAND_CMD_READ1:
                if (nfc->small_page) {
                        ar934x_nfc_send_read(nfc, command, column, page_addr,
-                                            mtd->writesize + mtd->oobsize,
-                                            false);
+                                            mtd->writesize + mtd->oobsize);
                } else {
                        ar934x_nfc_send_read(nfc, command, 0, page_addr,
-                                            mtd->writesize + mtd->oobsize,
-                                            false);
+                                            mtd->writesize + mtd->oobsize);
                        nfc->buf_index = column;
                        nfc->rndout_page_addr = page_addr;
                        nfc->rndout_read_cmd = command;
@@ -628,25 +635,25 @@ ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
                break;
 
        case NAND_CMD_READOOB:
-               if (nfc->small_page) {
+               if (nfc->small_page)
                        ar934x_nfc_send_read(nfc, NAND_CMD_READOOB,
                                             column, page_addr,
-                                            mtd->oobsize,
-                                            true);
-               } else {
+                                            mtd->oobsize);
+               else
                        ar934x_nfc_send_read(nfc, NAND_CMD_READ0,
-                                            column, page_addr,
-                                            mtd->writesize + mtd->oobsize,
-                                            true);
-                       nfc->buf_index = mtd->writesize;
-               }
+                                            mtd->writesize, page_addr,
+                                            mtd->oobsize);
                break;
 
        case NAND_CMD_RNDOUT:
+               if (WARN_ON(nfc->small_page))
+                       break;
+
                /* emulate subpage read */
-               ar934x_nfc_send_read(nfc, nfc->rndout_read_cmd, column,
+               ar934x_nfc_send_read(nfc, nfc->rndout_read_cmd, 0,
                                     nfc->rndout_page_addr,
-                                    mtd->writesize, false);
+                                    mtd->writesize + mtd->oobsize);
+               nfc->buf_index = column;
                break;
 
        case NAND_CMD_ERASE1:
@@ -718,13 +725,15 @@ static u8
 ar934x_nfc_read_byte(struct mtd_info *mtd)
 {
        struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
-       unsigned int buf_index;
        u8 data;
 
        WARN_ON(nfc->buf_index >= nfc->buf_size);
 
-       buf_index = nfc->buf_index ^ 3;
-       data = nfc->buf[buf_index];
+       if (nfc->swap_dma || nfc->read_id)
+               data = nfc->buf[nfc->buf_index ^ 3];
+       else
+               data = nfc->buf[nfc->buf_index];
+
        nfc->buf_index++;
 
        return data;
@@ -738,9 +747,16 @@ ar934x_nfc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 
        WARN_ON(nfc->buf_index + len > nfc->buf_size);
 
-       for (i = 0; i < len; i++) {
-               nfc->buf[nfc->buf_index ^ 3] = buf[i];
-               nfc->buf_index++;
+       if (nfc->swap_dma) {
+               for (i = 0; i < len; i++) {
+                       nfc->buf[nfc->buf_index ^ 3] = buf[i];
+                       nfc->buf_index++;
+               }
+       } else {
+               for (i = 0; i < len; i++) {
+                       nfc->buf[nfc->buf_index] = buf[i];
+                       nfc->buf_index++;
+               }
        }
 }
 
@@ -755,26 +771,21 @@ ar934x_nfc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 
        buf_index = nfc->buf_index;
 
-       for (i = 0; i < len; i++) {
-               buf[i] = nfc->buf[buf_index ^ 3];
-               buf_index++;
+       if (nfc->swap_dma || nfc->read_id) {
+               for (i = 0; i < len; i++) {
+                       buf[i] = nfc->buf[buf_index ^ 3];
+                       buf_index++;
+               }
+       } else {
+               for (i = 0; i < len; i++) {
+                       buf[i] = nfc->buf[buf_index];
+                       buf_index++;
+               }
        }
 
        nfc->buf_index = buf_index;
 }
 
-static int
-ar934x_nfc_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
-{
-       int i;
-
-       for (i = 0; i < len; i++)
-               if (buf[i] != ar934x_nfc_read_byte(mtd))
-                       return -EFAULT;
-
-       return 0;
-}
-
 static void
 ar934x_nfc_hw_init(struct ar934x_nfc *nfc)
 {
@@ -861,7 +872,7 @@ ar934x_nfc_irq_handler(int irq, void *data)
        return IRQ_HANDLED;
 }
 
-static int __devinit
+static int
 ar934x_nfc_init_tail(struct mtd_info *mtd)
 {
        struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
@@ -987,7 +998,7 @@ ar934x_nfc_init_tail(struct mtd_info *mtd)
        return err;
 }
 
-static int __devinit
+static int
 ar934x_nfc_probe(struct platform_device *pdev)
 {
        static const char *part_probes[] = { "cmdlinepart", NULL, };
@@ -1041,6 +1052,7 @@ ar934x_nfc_probe(struct platform_device *pdev)
 
        nfc->parent = &pdev->dev;
        nfc->select_chip = pdata->select_chip;
+       nfc->swap_dma = pdata->swap_dma;
 
        nand = &nfc->nand_chip;
        mtd = &nfc->mtd;
@@ -1052,7 +1064,6 @@ ar934x_nfc_probe(struct platform_device *pdev)
        else
                mtd->name = dev_name(&pdev->dev);
 
-       nand->options = NAND_NO_AUTOINCR;
        nand->chip_delay = 25;
        nand->ecc.mode = NAND_ECC_SOFT;
 
@@ -1061,7 +1072,6 @@ ar934x_nfc_probe(struct platform_device *pdev)
        nand->read_byte = ar934x_nfc_read_byte;
        nand->write_buf = ar934x_nfc_write_buf;
        nand->read_buf = ar934x_nfc_read_buf;
-       nand->verify_buf = ar934x_nfc_verify_buf;
        nand->select_chip = ar934x_nfc_select_chip;
 
        ret = ar934x_nfc_alloc_buf(nfc, AR934X_NFC_ID_BUF_SIZE);
@@ -1118,7 +1128,7 @@ err_free_nand:
        return ret;
 }
 
-static int __devexit
+static int
 ar934x_nfc_remove(struct platform_device *pdev)
 {
        struct ar934x_nfc *nfc;
@@ -1137,7 +1147,7 @@ ar934x_nfc_remove(struct platform_device *pdev)
 
 static struct platform_driver ar934x_nfc_driver = {
        .probe          = ar934x_nfc_probe,
-       .remove         = __devexit_p(ar934x_nfc_remove),
+       .remove         = ar934x_nfc_remove,
        .driver = {
                .name   = AR934X_NFC_DRIVER_NAME,
                .owner  = THIS_MODULE,