25 #include <linux/module.h>
26 #include <linux/types.h>
28 #include <linux/kernel.h>
29 #include <linux/string.h>
33 #include <linux/slab.h>
46 #define FCM_TIMEOUT_MSECS 500
87 .oobfree = { {0, 5}, {9, 7} },
94 .oobfree = { {0, 5}, {6, 2}, {11, 5} },
100 .eccpos = {6, 7, 8, 22, 23, 24, 38, 39, 40, 54, 55, 56},
101 .oobfree = { {1, 5}, {9, 13}, {25, 13}, {41, 13}, {57, 7} },
107 .eccpos = {8, 9, 10, 24, 25, 26, 40, 41, 42, 56, 57, 58},
108 .oobfree = { {1, 7}, {11, 13}, {27, 13}, {43, 13}, {59, 5} },
116 static u8 scan_ff_pattern[] = { 0xff, };
122 .pattern = scan_ff_pattern,
130 static u8 bbt_pattern[] = {
'B',
'b',
't',
'0' };
131 static u8 mirror_pattern[] = {
'1',
't',
'b',
'B' };
140 .pattern = bbt_pattern,
150 .pattern = mirror_pattern,
159 static void set_addr(
struct mtd_info *mtd,
int column,
int page_addr,
int oob)
168 elbc_fcm_ctrl->
page = page_addr;
179 buf_num = (page_addr & 1) << 2;
189 buf_num = page_addr & 7;
192 elbc_fcm_ctrl->
addr = priv->
vbase + buf_num * 1024;
200 "elbc_fcm_ctrl->addr=0x%p (0x%p), "
201 "index %x, pes %d ps %d\n",
202 buf_num, elbc_fcm_ctrl->
addr, priv->
vbase,
203 elbc_fcm_ctrl->
index,
210 static int fsl_elbc_run_command(
struct mtd_info *mtd)
224 "fsl_elbc_run_command: fmr=%08x fir=%08x fcr=%08x\n",
227 "fsl_elbc_run_command: fbar=%08x fpar=%08x "
228 "fbcr=%08x bank=%d\n",
248 "command failed: fir %x fcr %x status %x mdr %x\n",
250 elbc_fcm_ctrl->
status, elbc_fcm_ctrl->
mdr);
272 if (lteccr & 0x000F000F)
274 if (lteccr & 0x000F0000) {
283 static void fsl_elbc_do_read(
struct nand_chip *chip,
int oob)
314 static void fsl_elbc_cmdfunc(
struct mtd_info *mtd,
unsigned int command,
315 int column,
int page_addr)
328 elbc_fcm_ctrl->
index = 0;
338 "fsl_elbc_cmdfunc: NAND_CMD_READ0, page_addr:"
339 " 0x%x, column: 0x%x.\n", page_addr, column);
343 set_addr(mtd, 0, page_addr, 0);
346 elbc_fcm_ctrl->
index += column;
348 fsl_elbc_do_read(chip, 0);
349 fsl_elbc_run_command(mtd);
355 "fsl_elbc_cmdfunc: NAND_CMD_READOOB, page_addr:"
356 " 0x%x, column: 0x%x.\n", page_addr, column);
359 set_addr(mtd, column, page_addr, 1);
363 fsl_elbc_do_read(chip, 1);
364 fsl_elbc_run_command(mtd);
369 dev_vdbg(priv->
dev,
"fsl_elbc_cmdfunc: NAND_CMD %x\n", command);
382 elbc_fcm_ctrl->
mdr = column;
383 set_addr(mtd, 0, 0, 0);
384 fsl_elbc_run_command(mtd);
390 "fsl_elbc_cmdfunc: NAND_CMD_ERASE1, "
391 "page_addr: 0x%x.\n", page_addr);
392 set_addr(mtd, 0, page_addr, 0);
397 dev_vdbg(priv->
dev,
"fsl_elbc_cmdfunc: NAND_CMD_ERASE2.\n");
415 fsl_elbc_run_command(mtd);
422 "fsl_elbc_cmdfunc: NAND_CMD_SEQIN/PAGE_PROG, "
423 "page_addr: 0x%x, column: 0x%x.\n",
426 elbc_fcm_ctrl->
column = column;
432 elbc_fcm_ctrl->
oob = 1;
435 elbc_fcm_ctrl->
oob = 0;
462 if (elbc_fcm_ctrl->
oob)
471 set_addr(mtd, column, page_addr, elbc_fcm_ctrl->
oob);
478 "fsl_elbc_cmdfunc: NAND_CMD_PAGEPROG "
479 "writing %d bytes.\n", elbc_fcm_ctrl->
index);
485 if (elbc_fcm_ctrl->
oob || elbc_fcm_ctrl->
column != 0 ||
492 fsl_elbc_run_command(mtd);
504 set_addr(mtd, 0, 0, 0);
507 fsl_elbc_run_command(mtd);
517 dev_dbg(priv->
dev,
"fsl_elbc_cmdfunc: NAND_CMD_RESET.\n");
520 fsl_elbc_run_command(mtd);
525 "fsl_elbc_cmdfunc: error, unsupported command 0x%x.\n",
530 static void fsl_elbc_select_chip(
struct mtd_info *mtd,
int chip)
540 static void fsl_elbc_write_buf(
struct mtd_info *mtd,
const u8 *
buf,
int len)
548 dev_err(priv->
dev,
"write_buf of %d bytes", len);
549 elbc_fcm_ctrl->
status = 0;
553 if ((
unsigned int)len > bufsize - elbc_fcm_ctrl->
index) {
555 "write_buf beyond end of buffer "
556 "(%d requested, %u available)\n",
557 len, bufsize - elbc_fcm_ctrl->
index);
558 len = bufsize - elbc_fcm_ctrl->
index;
571 elbc_fcm_ctrl->
index += len;
578 static u8 fsl_elbc_read_byte(
struct mtd_info *mtd)
588 dev_err(priv->
dev,
"read_byte beyond end of buffer\n");
595 static void fsl_elbc_read_buf(
struct mtd_info *mtd,
u8 *buf,
int len)
605 avail =
min((
unsigned int)len,
612 "read_buf beyond end of buffer "
613 "(%d requested, %d available)\n",
634 static int fsl_elbc_chip_init_tail(
struct mtd_info *mtd)
651 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->numchips = %d\n",
653 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->chipsize = %lld\n",
655 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->pagemask = %8x\n",
657 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->chip_delay = %d\n",
659 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->badblockpos = %d\n",
661 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->chip_shift = %d\n",
663 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->page_shift = %d\n",
665 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->phys_erase_shift = %d\n",
667 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->ecclayout = %p\n",
669 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->ecc.mode = %d\n",
671 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->ecc.steps = %d\n",
673 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->ecc.bytes = %d\n",
675 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->ecc.total = %d\n",
677 dev_dbg(priv->
dev,
"fsl_elbc_init: nand->ecc.layout = %p\n",
680 dev_dbg(priv->
dev,
"fsl_elbc_init: mtd->size = %lld\n", mtd->
size);
681 dev_dbg(priv->
dev,
"fsl_elbc_init: mtd->erasesize = %d\n",
683 dev_dbg(priv->
dev,
"fsl_elbc_init: mtd->writesize = %d\n",
685 dev_dbg(priv->
dev,
"fsl_elbc_init: mtd->oobsize = %d\n",
698 chip->
ecc.size = 512;
700 &fsl_elbc_oob_lp_eccm1 :
701 &fsl_elbc_oob_lp_eccm0;
706 "fsl_elbc_init: page size %d is not supported\n",
721 fsl_elbc_read_buf(mtd, buf, mtd->
writesize);
735 const uint8_t *buf,
int oob_required)
737 fsl_elbc_write_buf(mtd, buf, mtd->
writesize);
743 static int fsl_elbc_chip_init(
struct fsl_elbc_mtd *priv)
750 dev_dbg(priv->
dev,
"eLBC Set Information for bank %d\n", priv->
bank);
767 chip->
cmdfunc = fsl_elbc_cmdfunc;
770 chip->
bbt_td = &bbt_main_descr;
771 chip->
bbt_md = &bbt_mirror_descr;
779 chip->
ecc.read_page = fsl_elbc_read_page;
780 chip->
ecc.write_page = fsl_elbc_write_page;
788 &fsl_elbc_oob_sp_eccm1 : &fsl_elbc_oob_sp_eccm0;
789 chip->
ecc.size = 512;
791 chip->
ecc.strength = 1;
800 static int fsl_elbc_chip_remove(
struct fsl_elbc_mtd *priv)
823 static const char *part_probe_types[]
824 = {
"cmdlinepart",
"RedBoot",
"ofpart",
NULL };
840 dev_err(dev,
"failed to get resource\n");
853 if (bank >= MAX_BANKS) {
854 dev_err(dev,
"address did not match any chip selects\n");
864 elbc_fcm_ctrl = kzalloc(
sizeof(*elbc_fcm_ctrl),
GFP_KERNEL);
865 if (!elbc_fcm_ctrl) {
866 dev_err(dev,
"failed to allocate memory\n");
889 dev_err(dev,
"failed to map chip region\n");
895 if (!priv->
mtd.name) {
900 ret = fsl_elbc_chip_init(priv);
908 ret = fsl_elbc_chip_init_tail(&priv->
mtd);
922 (
unsigned long long)
res.start, priv->
bank);
926 fsl_elbc_chip_remove(priv);
935 fsl_elbc_chip_remove(priv);
941 kfree(elbc_fcm_ctrl);
949 static const struct of_device_id fsl_elbc_nand_match[] = {
950 { .compatible =
"fsl,elbc-fcm-nand", },
956 .name =
"fsl,elbc-fcm-nand",
958 .of_match_table = fsl_elbc_nand_match,
960 .probe = fsl_elbc_nand_probe,
961 .remove = fsl_elbc_nand_remove,