1 /* Freescale Enhanced Local Bus Controller FCM NAND driver
3 * Copyright (c) 2006-2008 Freescale Semiconductor
5 * Authors: Nick Spence <nick.spence@freescale.com>,
6 * Scott Wood <scottwood@freescale.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/nand.h>
28 #include <linux/mtd/nand_ecc.h>
31 #include <asm/errno.h>
35 #define vdbg(format, arg...) printf("DEBUG: " format, ##arg)
37 #define vdbg(format, arg...) do {} while (0)
40 /* Can't use plain old DEBUG because the linux mtd
41 * headers define it as a macro.
44 #define dbg(format, arg...) printf("DEBUG: " format, ##arg)
46 #define dbg(format, arg...) do {} while (0)
50 #define ERR_BYTE 0xFF /* Value returned for read bytes when read failed */
51 #define FCM_TIMEOUT_MSECS 10 /* Maximum number of mSecs to wait for FCM */
53 #define LTESR_NAND_MASK (LTESR_FCT | LTESR_PAR | LTESR_CC)
57 /* mtd information per set */
61 struct nand_chip chip;
62 struct fsl_elbc_ctrl *ctrl;
65 int bank; /* Chip select bank number */
66 u8 __iomem *vbase; /* Chip select base virtual address */
67 int page_size; /* NAND page size (0=512, 1=2048) */
68 unsigned int fmr; /* FCM Flash Mode Register value */
71 /* overview of the fsl elbc controller */
73 struct fsl_elbc_ctrl {
74 struct nand_hw_control controller;
75 struct fsl_elbc_mtd *chips[MAX_BANKS];
79 u8 __iomem *addr; /* Address of assigned FCM buffer */
80 unsigned int page; /* Last page written to / read from */
81 unsigned int read_bytes; /* Number of bytes read during command */
82 unsigned int column; /* Saved column from SEQIN */
83 unsigned int index; /* Pointer to next byte to 'read' */
84 unsigned int status; /* status read from LTESR after last op */
85 unsigned int mdr; /* UPM/FCM Data Register value */
86 unsigned int use_mdr; /* Non zero if the MDR is to be set */
87 unsigned int oob; /* Non zero if operating on OOB data */
88 uint8_t *oob_poi; /* Place to write ECC after read back */
91 /* These map to the positions used by the FCM hardware ECC generator */
93 /* Small Page FLASH with FMR[ECCM] = 0 */
94 static struct nand_ecclayout fsl_elbc_oob_sp_eccm0 = {
97 .oobfree = { {0, 5}, {9, 7} },
101 /* Small Page FLASH with FMR[ECCM] = 1 */
102 static struct nand_ecclayout fsl_elbc_oob_sp_eccm1 = {
104 .eccpos = {8, 9, 10},
105 .oobfree = { {0, 5}, {6, 2}, {11, 5} },
109 /* Large Page FLASH with FMR[ECCM] = 0 */
110 static struct nand_ecclayout fsl_elbc_oob_lp_eccm0 = {
112 .eccpos = {6, 7, 8, 22, 23, 24, 38, 39, 40, 54, 55, 56},
113 .oobfree = { {1, 5}, {9, 13}, {25, 13}, {41, 13}, {57, 7} },
117 /* Large Page FLASH with FMR[ECCM] = 1 */
118 static struct nand_ecclayout fsl_elbc_oob_lp_eccm1 = {
120 .eccpos = {8, 9, 10, 24, 25, 26, 40, 41, 42, 56, 57, 58},
121 .oobfree = { {1, 7}, {11, 13}, {27, 13}, {43, 13}, {59, 5} },
125 /*=================================*/
128 * Set up the FCM hardware block and page address fields, and the fcm
129 * structure addr field to point to the correct FCM buffer in memory
131 static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
133 struct nand_chip *chip = mtd->priv;
134 struct fsl_elbc_mtd *priv = chip->priv;
135 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
136 lbus83xx_t *lbc = ctrl->regs;
139 ctrl->page = page_addr;
141 if (priv->page_size) {
142 out_be32(&lbc->fbar, page_addr >> 6);
144 ((page_addr << FPAR_LP_PI_SHIFT) & FPAR_LP_PI) |
145 (oob ? FPAR_LP_MS : 0) | column);
146 buf_num = (page_addr & 1) << 2;
148 out_be32(&lbc->fbar, page_addr >> 5);
150 ((page_addr << FPAR_SP_PI_SHIFT) & FPAR_SP_PI) |
151 (oob ? FPAR_SP_MS : 0) | column);
152 buf_num = page_addr & 7;
155 ctrl->addr = priv->vbase + buf_num * 1024;
156 ctrl->index = column;
158 /* for OOB data point to the second half of the buffer */
160 ctrl->index += priv->page_size ? 2048 : 512;
162 vdbg("set_addr: bank=%d, ctrl->addr=0x%p (0x%p), "
163 "index %x, pes %d ps %d\n",
164 buf_num, ctrl->addr, priv->vbase, ctrl->index,
165 chip->phys_erase_shift, chip->page_shift);
169 * execute FCM command and wait for it to complete
171 static int fsl_elbc_run_command(struct mtd_info *mtd)
173 struct nand_chip *chip = mtd->priv;
174 struct fsl_elbc_mtd *priv = chip->priv;
175 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
176 lbus83xx_t *lbc = ctrl->regs;
180 /* Setup the FMR[OP] to execute without write protection */
181 out_be32(&lbc->fmr, priv->fmr | 3);
183 out_be32(&lbc->mdr, ctrl->mdr);
185 vdbg("fsl_elbc_run_command: fmr=%08x fir=%08x fcr=%08x\n",
186 in_be32(&lbc->fmr), in_be32(&lbc->fir), in_be32(&lbc->fcr));
187 vdbg("fsl_elbc_run_command: fbar=%08x fpar=%08x "
188 "fbcr=%08x bank=%d\n",
189 in_be32(&lbc->fbar), in_be32(&lbc->fpar),
190 in_be32(&lbc->fbcr), priv->bank);
192 /* execute special operation */
193 out_be32(&lbc->lsor, priv->bank);
195 /* wait for FCM complete flag or timeout */
196 end_tick = usec2ticks(FCM_TIMEOUT_MSECS * 1000) + get_ticks();
199 while (end_tick > get_ticks()) {
200 ltesr = in_be32(&lbc->ltesr);
201 if (ltesr & LTESR_CC)
205 ctrl->status = ltesr & LTESR_NAND_MASK;
206 out_be32(&lbc->ltesr, ctrl->status);
207 out_be32(&lbc->lteatr, 0);
209 /* store mdr value in case it was needed */
211 ctrl->mdr = in_be32(&lbc->mdr);
215 vdbg("fsl_elbc_run_command: stat=%08x mdr=%08x fmr=%08x\n",
216 ctrl->status, ctrl->mdr, in_be32(&lbc->fmr));
218 /* returns 0 on success otherwise non-zero) */
219 return ctrl->status == LTESR_CC ? 0 : -EIO;
222 static void fsl_elbc_do_read(struct nand_chip *chip, int oob)
224 struct fsl_elbc_mtd *priv = chip->priv;
225 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
226 lbus83xx_t *lbc = ctrl->regs;
228 if (priv->page_size) {
230 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
231 (FIR_OP_CA << FIR_OP1_SHIFT) |
232 (FIR_OP_PA << FIR_OP2_SHIFT) |
233 (FIR_OP_CW1 << FIR_OP3_SHIFT) |
234 (FIR_OP_RBW << FIR_OP4_SHIFT));
236 out_be32(&lbc->fcr, (NAND_CMD_READ0 << FCR_CMD0_SHIFT) |
237 (NAND_CMD_READSTART << FCR_CMD1_SHIFT));
240 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
241 (FIR_OP_CA << FIR_OP1_SHIFT) |
242 (FIR_OP_PA << FIR_OP2_SHIFT) |
243 (FIR_OP_RBW << FIR_OP3_SHIFT));
247 NAND_CMD_READOOB << FCR_CMD0_SHIFT);
249 out_be32(&lbc->fcr, NAND_CMD_READ0 << FCR_CMD0_SHIFT);
253 /* cmdfunc send commands to the FCM */
254 static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command,
255 int column, int page_addr)
257 struct nand_chip *chip = mtd->priv;
258 struct fsl_elbc_mtd *priv = chip->priv;
259 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
260 lbus83xx_t *lbc = ctrl->regs;
264 /* clear the read buffer */
265 ctrl->read_bytes = 0;
266 if (command != NAND_CMD_PAGEPROG)
270 /* READ0 and READ1 read the entire buffer to use hardware ECC. */
276 vdbg("fsl_elbc_cmdfunc: NAND_CMD_READ0, page_addr:"
277 " 0x%x, column: 0x%x.\n", page_addr, column);
279 out_be32(&lbc->fbcr, 0); /* read entire page to enable ECC */
280 set_addr(mtd, 0, page_addr, 0);
282 ctrl->read_bytes = mtd->writesize + mtd->oobsize;
283 ctrl->index += column;
285 fsl_elbc_do_read(chip, 0);
286 fsl_elbc_run_command(mtd);
289 /* READOOB reads only the OOB because no ECC is performed. */
290 case NAND_CMD_READOOB:
291 vdbg("fsl_elbc_cmdfunc: NAND_CMD_READOOB, page_addr:"
292 " 0x%x, column: 0x%x.\n", page_addr, column);
294 out_be32(&lbc->fbcr, mtd->oobsize - column);
295 set_addr(mtd, column, page_addr, 1);
297 ctrl->read_bytes = mtd->writesize + mtd->oobsize;
299 fsl_elbc_do_read(chip, 1);
300 fsl_elbc_run_command(mtd);
304 /* READID must read all 5 possible bytes while CEB is active */
305 case NAND_CMD_READID:
306 vdbg("fsl_elbc_cmdfunc: NAND_CMD_READID.\n");
308 out_be32(&lbc->fir, (FIR_OP_CW0 << FIR_OP0_SHIFT) |
309 (FIR_OP_UA << FIR_OP1_SHIFT) |
310 (FIR_OP_RBW << FIR_OP2_SHIFT));
311 out_be32(&lbc->fcr, NAND_CMD_READID << FCR_CMD0_SHIFT);
312 /* 5 bytes for manuf, device and exts */
313 out_be32(&lbc->fbcr, 5);
314 ctrl->read_bytes = 5;
318 set_addr(mtd, 0, 0, 0);
319 fsl_elbc_run_command(mtd);
322 /* ERASE1 stores the block and page address */
323 case NAND_CMD_ERASE1:
324 vdbg("fsl_elbc_cmdfunc: NAND_CMD_ERASE1, "
325 "page_addr: 0x%x.\n", page_addr);
326 set_addr(mtd, 0, page_addr, 0);
329 /* ERASE2 uses the block and page address from ERASE1 */
330 case NAND_CMD_ERASE2:
331 vdbg("fsl_elbc_cmdfunc: NAND_CMD_ERASE2.\n");
334 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
335 (FIR_OP_PA << FIR_OP1_SHIFT) |
336 (FIR_OP_CM1 << FIR_OP2_SHIFT));
339 (NAND_CMD_ERASE1 << FCR_CMD0_SHIFT) |
340 (NAND_CMD_ERASE2 << FCR_CMD1_SHIFT));
342 out_be32(&lbc->fbcr, 0);
343 ctrl->read_bytes = 0;
345 fsl_elbc_run_command(mtd);
348 /* SEQIN sets up the addr buffer and all registers except the length */
349 case NAND_CMD_SEQIN: {
351 vdbg("fsl_elbc_cmdfunc: NAND_CMD_SEQIN/PAGE_PROG, "
352 "page_addr: 0x%x, column: 0x%x.\n",
355 ctrl->column = column;
358 if (priv->page_size) {
359 fcr = (NAND_CMD_SEQIN << FCR_CMD0_SHIFT) |
360 (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT);
363 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
364 (FIR_OP_CA << FIR_OP1_SHIFT) |
365 (FIR_OP_PA << FIR_OP2_SHIFT) |
366 (FIR_OP_WB << FIR_OP3_SHIFT) |
367 (FIR_OP_CW1 << FIR_OP4_SHIFT));
369 fcr = (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT) |
370 (NAND_CMD_SEQIN << FCR_CMD2_SHIFT);
373 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
374 (FIR_OP_CM2 << FIR_OP1_SHIFT) |
375 (FIR_OP_CA << FIR_OP2_SHIFT) |
376 (FIR_OP_PA << FIR_OP3_SHIFT) |
377 (FIR_OP_WB << FIR_OP4_SHIFT) |
378 (FIR_OP_CW1 << FIR_OP5_SHIFT));
380 if (column >= mtd->writesize) {
381 /* OOB area --> READOOB */
382 column -= mtd->writesize;
383 fcr |= NAND_CMD_READOOB << FCR_CMD0_SHIFT;
385 } else if (column < 256) {
386 /* First 256 bytes --> READ0 */
387 fcr |= NAND_CMD_READ0 << FCR_CMD0_SHIFT;
389 /* Second 256 bytes --> READ1 */
390 fcr |= NAND_CMD_READ1 << FCR_CMD0_SHIFT;
394 out_be32(&lbc->fcr, fcr);
395 set_addr(mtd, column, page_addr, ctrl->oob);
399 /* PAGEPROG reuses all of the setup from SEQIN and adds the length */
400 case NAND_CMD_PAGEPROG: {
402 vdbg("fsl_elbc_cmdfunc: NAND_CMD_PAGEPROG "
403 "writing %d bytes.\n", ctrl->index);
405 /* if the write did not start at 0 or is not a full page
406 * then set the exact length, otherwise use a full page
407 * write so the HW generates the ECC.
409 if (ctrl->oob || ctrl->column != 0 ||
410 ctrl->index != mtd->writesize + mtd->oobsize) {
411 out_be32(&lbc->fbcr, ctrl->index);
414 out_be32(&lbc->fbcr, 0);
418 fsl_elbc_run_command(mtd);
420 /* Read back the page in order to fill in the ECC for the
421 * caller. Is this really needed?
423 if (full_page && ctrl->oob_poi) {
424 out_be32(&lbc->fbcr, 3);
425 set_addr(mtd, 6, page_addr, 1);
427 ctrl->read_bytes = mtd->writesize + 9;
429 fsl_elbc_do_read(chip, 1);
430 fsl_elbc_run_command(mtd);
432 memcpy_fromio(ctrl->oob_poi + 6,
433 &ctrl->addr[ctrl->index], 3);
437 ctrl->oob_poi = NULL;
441 /* CMD_STATUS must read the status byte while CEB is active */
442 /* Note - it does not wait for the ready line */
443 case NAND_CMD_STATUS:
445 (FIR_OP_CM0 << FIR_OP0_SHIFT) |
446 (FIR_OP_RBW << FIR_OP1_SHIFT));
447 out_be32(&lbc->fcr, NAND_CMD_STATUS << FCR_CMD0_SHIFT);
448 out_be32(&lbc->fbcr, 1);
449 set_addr(mtd, 0, 0, 0);
450 ctrl->read_bytes = 1;
452 fsl_elbc_run_command(mtd);
454 /* The chip always seems to report that it is
455 * write-protected, even when it is not.
457 out_8(ctrl->addr, in_8(ctrl->addr) | NAND_STATUS_WP);
460 /* RESET without waiting for the ready line */
462 dbg("fsl_elbc_cmdfunc: NAND_CMD_RESET.\n");
463 out_be32(&lbc->fir, FIR_OP_CM0 << FIR_OP0_SHIFT);
464 out_be32(&lbc->fcr, NAND_CMD_RESET << FCR_CMD0_SHIFT);
465 fsl_elbc_run_command(mtd);
469 printf("fsl_elbc_cmdfunc: error, unsupported command 0x%x.\n",
474 static void fsl_elbc_select_chip(struct mtd_info *mtd, int chip)
476 /* The hardware does not seem to support multiple
482 * Write buf to the FCM Controller Data Buffer
484 static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
486 struct nand_chip *chip = mtd->priv;
487 struct fsl_elbc_mtd *priv = chip->priv;
488 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
489 unsigned int bufsize = mtd->writesize + mtd->oobsize;
492 printf("write_buf of %d bytes", len);
497 if ((unsigned int)len > bufsize - ctrl->index) {
498 printf("write_buf beyond end of buffer "
499 "(%d requested, %u available)\n",
500 len, bufsize - ctrl->index);
501 len = bufsize - ctrl->index;
504 memcpy_toio(&ctrl->addr[ctrl->index], buf, len);
506 * This is workaround for the weird elbc hangs during nand write,
507 * Scott Wood says: "...perhaps difference in how long it takes a
508 * write to make it through the localbus compared to a write to IMMR
509 * is causing problems, and sync isn't helping for some reason."
510 * Reading back the last byte helps though.
512 in_8(&ctrl->addr[ctrl->index] + len - 1);
518 * read a byte from either the FCM hardware buffer if it has any data left
519 * otherwise issue a command to read a single byte.
521 static u8 fsl_elbc_read_byte(struct mtd_info *mtd)
523 struct nand_chip *chip = mtd->priv;
524 struct fsl_elbc_mtd *priv = chip->priv;
525 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
527 /* If there are still bytes in the FCM, then use the next byte. */
528 if (ctrl->index < ctrl->read_bytes)
529 return in_8(&ctrl->addr[ctrl->index++]);
531 printf("read_byte beyond end of buffer\n");
536 * Read from the FCM Controller Data Buffer
538 static void fsl_elbc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
540 struct nand_chip *chip = mtd->priv;
541 struct fsl_elbc_mtd *priv = chip->priv;
542 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
548 avail = min((unsigned int)len, ctrl->read_bytes - ctrl->index);
549 memcpy_fromio(buf, &ctrl->addr[ctrl->index], avail);
550 ctrl->index += avail;
553 printf("read_buf beyond end of buffer "
554 "(%d requested, %d available)\n",
559 * Verify buffer against the FCM Controller Data Buffer
561 static int fsl_elbc_verify_buf(struct mtd_info *mtd,
562 const u_char *buf, int len)
564 struct nand_chip *chip = mtd->priv;
565 struct fsl_elbc_mtd *priv = chip->priv;
566 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
570 printf("write_buf of %d bytes", len);
574 if ((unsigned int)len > ctrl->read_bytes - ctrl->index) {
575 printf("verify_buf beyond end of buffer "
576 "(%d requested, %u available)\n",
577 len, ctrl->read_bytes - ctrl->index);
579 ctrl->index = ctrl->read_bytes;
583 for (i = 0; i < len; i++)
584 if (in_8(&ctrl->addr[ctrl->index + i]) != buf[i])
588 return i == len && ctrl->status == LTESR_CC ? 0 : -EIO;
591 /* This function is called after Program and Erase Operations to
592 * check for success or failure.
594 static int fsl_elbc_wait(struct mtd_info *mtd, struct nand_chip *chip)
596 struct fsl_elbc_mtd *priv = chip->priv;
597 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
598 lbus83xx_t *lbc = ctrl->regs;
600 if (ctrl->status != LTESR_CC)
601 return NAND_STATUS_FAIL;
603 /* Use READ_STATUS command, but wait for the device to be ready */
606 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
607 (FIR_OP_RBW << FIR_OP1_SHIFT));
608 out_be32(&lbc->fcr, NAND_CMD_STATUS << FCR_CMD0_SHIFT);
609 out_be32(&lbc->fbcr, 1);
610 set_addr(mtd, 0, 0, 0);
611 ctrl->read_bytes = 1;
613 fsl_elbc_run_command(mtd);
615 if (ctrl->status != LTESR_CC)
616 return NAND_STATUS_FAIL;
618 /* The chip always seems to report that it is
619 * write-protected, even when it is not.
621 out_8(ctrl->addr, in_8(ctrl->addr) | NAND_STATUS_WP);
622 return fsl_elbc_read_byte(mtd);
625 static int fsl_elbc_read_page(struct mtd_info *mtd,
626 struct nand_chip *chip,
629 fsl_elbc_read_buf(mtd, buf, mtd->writesize);
630 fsl_elbc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
632 if (fsl_elbc_wait(mtd, chip) & NAND_STATUS_FAIL)
633 mtd->ecc_stats.failed++;
638 /* ECC will be calculated automatically, and errors will be detected in
641 static void fsl_elbc_write_page(struct mtd_info *mtd,
642 struct nand_chip *chip,
645 struct fsl_elbc_mtd *priv = chip->priv;
646 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
648 fsl_elbc_write_buf(mtd, buf, mtd->writesize);
649 fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
651 ctrl->oob_poi = chip->oob_poi;
654 static struct fsl_elbc_ctrl *elbc_ctrl;
656 static void fsl_elbc_ctrl_init(void)
658 immap_t *im = (immap_t *)CFG_IMMR;
660 elbc_ctrl = kzalloc(sizeof(*elbc_ctrl), GFP_KERNEL);
664 elbc_ctrl->regs = &im->lbus;
666 /* clear event registers */
667 out_be32(&elbc_ctrl->regs->ltesr, LTESR_NAND_MASK);
668 out_be32(&elbc_ctrl->regs->lteatr, 0);
670 /* Enable interrupts for any detected events */
671 out_be32(&elbc_ctrl->regs->lteir, LTESR_NAND_MASK);
673 elbc_ctrl->read_bytes = 0;
674 elbc_ctrl->index = 0;
675 elbc_ctrl->addr = NULL;
678 int board_nand_init(struct nand_chip *nand)
680 struct fsl_elbc_mtd *priv;
684 fsl_elbc_ctrl_init();
689 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
693 priv->ctrl = elbc_ctrl;
694 priv->vbase = nand->IO_ADDR_R;
696 /* Find which chip select it is connected to. It'd be nice
697 * if we could pass more than one datum to the NAND driver...
699 for (priv->bank = 0; priv->bank < MAX_BANKS; priv->bank++) {
700 br = in_be32(&elbc_ctrl->regs->bank[priv->bank].br);
701 or = in_be32(&elbc_ctrl->regs->bank[priv->bank].or);
703 if ((br & BR_V) && (br & BR_MSEL) == BR_MS_FCM &&
704 (br & or & BR_BA) == (phys_addr_t)nand->IO_ADDR_R)
708 if (priv->bank >= MAX_BANKS) {
709 printf("fsl_elbc_nand: address did not match any "
714 elbc_ctrl->chips[priv->bank] = priv;
716 /* fill in nand_chip structure */
717 /* set up function call table */
718 nand->read_byte = fsl_elbc_read_byte;
719 nand->write_buf = fsl_elbc_write_buf;
720 nand->read_buf = fsl_elbc_read_buf;
721 nand->verify_buf = fsl_elbc_verify_buf;
722 nand->select_chip = fsl_elbc_select_chip;
723 nand->cmdfunc = fsl_elbc_cmdfunc;
724 nand->waitfunc = fsl_elbc_wait;
726 /* set up nand options */
727 nand->options = NAND_NO_READRDY | NAND_NO_AUTOINCR;
729 nand->controller = &elbc_ctrl->controller;
732 nand->ecc.read_page = fsl_elbc_read_page;
733 nand->ecc.write_page = fsl_elbc_write_page;
735 /* If CS Base Register selects full hardware ECC then use it */
736 if ((br & BR_DECC) == BR_DECC_CHK_GEN) {
737 nand->ecc.mode = NAND_ECC_HW;
739 nand->ecc.layout = (priv->fmr & FMR_ECCM) ?
740 &fsl_elbc_oob_sp_eccm1 :
741 &fsl_elbc_oob_sp_eccm0;
743 nand->ecc.size = 512;
747 /* otherwise fall back to default software ECC */
748 nand->ecc.mode = NAND_ECC_SOFT;
751 priv->fmr = (15 << FMR_CWTO_SHIFT) | (2 << FMR_AL_SHIFT);
753 /* adjust Option Register and ECC to match Flash page size */
754 if (or & OR_FCM_PGS) {
757 /* adjust ecc setup if needed */
758 if ((br & BR_DECC) == BR_DECC_CHK_GEN) {
760 nand->ecc.layout = (priv->fmr & FMR_ECCM) ?
761 &fsl_elbc_oob_lp_eccm1 :
762 &fsl_elbc_oob_lp_eccm0;