~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/mtd/nand/mxc_nand.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
#define NFC_V1_V2_WRPROT                (host->regs + 0x12)
57
57
#define NFC_V1_UNLOCKSTART_BLKADDR      (host->regs + 0x14)
58
58
#define NFC_V1_UNLOCKEND_BLKADDR        (host->regs + 0x16)
59
 
#define NFC_V21_UNLOCKSTART_BLKADDR     (host->regs + 0x20)
60
 
#define NFC_V21_UNLOCKEND_BLKADDR       (host->regs + 0x22)
 
59
#define NFC_V21_UNLOCKSTART_BLKADDR0    (host->regs + 0x20)
 
60
#define NFC_V21_UNLOCKSTART_BLKADDR1    (host->regs + 0x24)
 
61
#define NFC_V21_UNLOCKSTART_BLKADDR2    (host->regs + 0x28)
 
62
#define NFC_V21_UNLOCKSTART_BLKADDR3    (host->regs + 0x2c)
 
63
#define NFC_V21_UNLOCKEND_BLKADDR0      (host->regs + 0x22)
 
64
#define NFC_V21_UNLOCKEND_BLKADDR1      (host->regs + 0x26)
 
65
#define NFC_V21_UNLOCKEND_BLKADDR2      (host->regs + 0x2a)
 
66
#define NFC_V21_UNLOCKEND_BLKADDR3      (host->regs + 0x2e)
61
67
#define NFC_V1_V2_NF_WRPRST             (host->regs + 0x18)
62
68
#define NFC_V1_V2_CONFIG1               (host->regs + 0x1a)
63
69
#define NFC_V1_V2_CONFIG2               (host->regs + 0x1c)
152
158
        int                     clk_act;
153
159
        int                     irq;
154
160
        int                     eccsize;
 
161
        int                     active_cs;
155
162
 
156
163
        struct completion       op_completion;
157
164
 
211
218
        }
212
219
};
213
220
 
214
 
#ifdef CONFIG_MTD_PARTITIONS
 
221
/* OOB description for 4096 byte pages with 128 byte OOB */
 
222
static struct nand_ecclayout nandv2_hw_eccoob_4k = {
 
223
        .eccbytes = 8 * 9,
 
224
        .eccpos = {
 
225
                7,  8,  9, 10, 11, 12, 13, 14, 15,
 
226
                23, 24, 25, 26, 27, 28, 29, 30, 31,
 
227
                39, 40, 41, 42, 43, 44, 45, 46, 47,
 
228
                55, 56, 57, 58, 59, 60, 61, 62, 63,
 
229
                71, 72, 73, 74, 75, 76, 77, 78, 79,
 
230
                87, 88, 89, 90, 91, 92, 93, 94, 95,
 
231
                103, 104, 105, 106, 107, 108, 109, 110, 111,
 
232
                119, 120, 121, 122, 123, 124, 125, 126, 127,
 
233
        },
 
234
        .oobfree = {
 
235
                {.offset = 2, .length = 4},
 
236
                {.offset = 16, .length = 7},
 
237
                {.offset = 32, .length = 7},
 
238
                {.offset = 48, .length = 7},
 
239
                {.offset = 64, .length = 7},
 
240
                {.offset = 80, .length = 7},
 
241
                {.offset = 96, .length = 7},
 
242
                {.offset = 112, .length = 7},
 
243
        }
 
244
};
 
245
 
215
246
static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL };
216
 
#endif
217
247
 
218
248
static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
219
249
{
420
450
        for (i = 0; i < bufs; i++) {
421
451
 
422
452
                /* NANDFC buffer 0 is used for page read/write */
423
 
                writew(i, NFC_V1_V2_BUF_ADDR);
 
453
                writew((host->active_cs << 4) | i, NFC_V1_V2_BUF_ADDR);
424
454
 
425
455
                writew(ops, NFC_V1_V2_CONFIG2);
426
456
 
445
475
        struct nand_chip *this = &host->nand;
446
476
 
447
477
        /* NANDFC buffer 0 is used for device ID output */
448
 
        writew(0x0, NFC_V1_V2_BUF_ADDR);
 
478
        writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
449
479
 
450
480
        writew(NFC_ID, NFC_V1_V2_CONFIG2);
451
481
 
480
510
        uint32_t store;
481
511
        uint16_t ret;
482
512
 
483
 
        writew(0x0, NFC_V1_V2_BUF_ADDR);
 
513
        writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
484
514
 
485
515
        /*
486
516
         * The device status is stored in main_area0. To
641
671
 
642
672
        n = min(n, len);
643
673
 
644
 
        memcpy(buf, host->data_buf + col, len);
 
674
        memcpy(buf, host->data_buf + col, n);
645
675
 
646
 
        host->buf_start += len;
 
676
        host->buf_start += n;
647
677
}
648
678
 
649
679
/* Used by the upper layer to verify the data in NAND Flash
661
691
        struct nand_chip *nand_chip = mtd->priv;
662
692
        struct mxc_nand_host *host = nand_chip->priv;
663
693
 
664
 
        switch (chip) {
665
 
        case -1:
 
694
        if (chip == -1) {
666
695
                /* Disable the NFC clock */
667
696
                if (host->clk_act) {
668
697
                        clk_disable(host->clk);
669
698
                        host->clk_act = 0;
670
699
                }
671
 
                break;
672
 
        case 0:
 
700
                return;
 
701
        }
 
702
 
 
703
        if (!host->clk_act) {
673
704
                /* Enable the NFC clock */
674
 
                if (!host->clk_act) {
675
 
                        clk_enable(host->clk);
676
 
                        host->clk_act = 1;
677
 
                }
678
 
                break;
 
705
                clk_enable(host->clk);
 
706
                host->clk_act = 1;
 
707
        }
679
708
 
680
 
        default:
681
 
                break;
 
709
        if (nfc_is_v21()) {
 
710
                host->active_cs = chip;
 
711
                writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
682
712
        }
683
713
}
684
714
 
722
752
                /*
723
753
                 * MXC NANDFC can only perform full page+spare or
724
754
                 * spare-only read/write.  When the upper layers
725
 
                 * layers perform a read/write buf operation,
726
 
                 * we will used the saved column address to index into
727
 
                 * the full page.
 
755
                 * perform a read/write buf operation, the saved column
 
756
                  * address is used to index into the full page.
728
757
                 */
729
758
                host->send_addr(host, 0, page_addr == -1);
730
759
                if (mtd->writesize > 512)
810
839
 
811
840
        /* Blocks to be unlocked */
812
841
        if (nfc_is_v21()) {
813
 
                writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR);
814
 
                writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR);
 
842
                writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR0);
 
843
                writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR1);
 
844
                writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR2);
 
845
                writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR3);
 
846
                writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR0);
 
847
                writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR1);
 
848
                writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR2);
 
849
                writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3);
815
850
        } else if (nfc_is_v1()) {
816
851
                writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
817
852
                writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR);
1176
1211
                irq_control_v1_v2(host, 1);
1177
1212
 
1178
1213
        /* first scan to find the device and get the page size */
1179
 
        if (nand_scan_ident(mtd, 1, NULL)) {
 
1214
        if (nand_scan_ident(mtd, nfc_is_v21() ? 4 : 1, NULL)) {
1180
1215
                err = -ENXIO;
1181
1216
                goto escan;
1182
1217
        }
1186
1221
 
1187
1222
        if (mtd->writesize == 2048)
1188
1223
                this->ecc.layout = oob_largepage;
 
1224
        if (nfc_is_v21() && mtd->writesize == 4096)
 
1225
                this->ecc.layout = &nandv2_hw_eccoob_4k;
1189
1226
 
1190
1227
        /* second phase scan */
1191
1228
        if (nand_scan_tail(mtd)) {
1194
1231
        }
1195
1232
 
1196
1233
        /* Register the partitions */
1197
 
#ifdef CONFIG_MTD_PARTITIONS
1198
1234
        nr_parts =
1199
1235
            parse_mtd_partitions(mtd, part_probes, &host->parts, 0);
1200
1236
        if (nr_parts > 0)
1201
 
                add_mtd_partitions(mtd, host->parts, nr_parts);
 
1237
                mtd_device_register(mtd, host->parts, nr_parts);
1202
1238
        else if (pdata->parts)
1203
 
                add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
1204
 
        else
1205
 
#endif
1206
 
        {
 
1239
                mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
 
1240
        else {
1207
1241
                pr_info("Registering %s as whole device\n", mtd->name);
1208
 
                add_mtd_device(mtd);
 
1242
                mtd_device_register(mtd, NULL, 0);
1209
1243
        }
1210
1244
 
1211
1245
        platform_set_drvdata(pdev, host);