• Home
  • Raw
  • Download

Lines Matching +full:odd +full:- +full:numbered

4  * mtd nand driver for M-Systems DiskOnChip G4
17 * Mechanism for management of password-protected areas
21 * According to the M-Sys documentation, this device is also available in a
22 * "dual-die" configuration having a 256MB capacity, but no mechanism for
52 * even-numbered pages in the normal manner; odd-numbered pages will appear to
55 * program loader (IPL, stored in the docg4's 2k NOR-like region that is mapped
59 * manner, and the starting offset must be within an even-numbered 2k region;
183 * On read operations (page and oob-only), the first byte read from I/O reg is a
201 #define DOCG4_BCH_SIZE (DOCG4_PAGE_SIZE + DOCG4_OOB_SIZE - 1)
215 #define DOCG4_FACTORY_BBT_PAGE 16 /* page where read-only factory bbt lives */
220 * Bytes 2 - 6 are available to the user.
222 * Bytes 8 - 14 are hw-generated ecc covering entire page + oob bytes 0 - 14.
229 return -ERANGE; in docg4_ooblayout_ecc()
231 oobregion->offset = 7; in docg4_ooblayout_ecc()
232 oobregion->length = 9; in docg4_ooblayout_ecc()
241 return -ERANGE; in docg4_ooblayout_free()
243 oobregion->offset = 2; in docg4_ooblayout_free()
244 oobregion->length = 5; in docg4_ooblayout_free()
255 * The device has a nop register which M-Sys claims is for the purpose of
272 p[i] = readw(nand->IO_ADDR_R); in docg4_read_buf()
283 writew(p[i], nand->IO_ADDR_W); in docg4_write_buf16()
289 * Busy-wait for the FLASHREADY bit to be set in the FLASHCONTROL in poll_status()
296 void __iomem *docptr = doc->virtadr; in poll_status()
298 dev_dbg(doc->dev, "%s...\n", __func__); in poll_status()
311 dev_err(doc->dev, "%s: timed out!\n", __func__); in poll_status()
324 dev_dbg(doc->dev, "%s...\n", __func__); in docg4_wait()
327 if (doc->status) { in docg4_wait()
328 status |= doc->status; in docg4_wait()
329 doc->status = 0; in docg4_wait()
341 * not yet supported, so the only valid non-negative value is 0. in docg4_select_chip()
345 void __iomem *docptr = doc->virtadr; in docg4_select_chip()
347 dev_dbg(doc->dev, "%s: chip %d\n", __func__, chip); in docg4_select_chip()
353 dev_warn(doc->dev, "multiple floors currently unsupported\n"); in docg4_select_chip()
364 void __iomem *docptr = doc->virtadr; in reset()
384 /* read the 7 hw-generated ecc bytes */ in read_hw_ecc()
402 void __iomem *docptr = doc->virtadr; in correct_data()
407 read_hw_ecc(docptr, doc->ecc_buf); /* read 7 hw-generated ecc bytes */ in correct_data()
410 if (!memcmp(doc->ecc_buf, blank_read_hwecc, 7)) in correct_data()
425 if (nand->oob_poi[15]) { in correct_data()
427 unsigned long written_flag = nand->oob_poi[15]; in correct_data()
431 dev_warn(doc->dev, in correct_data()
448 doc->ecc_buf[i] = bitrev8(doc->ecc_buf[i]); in correct_data()
450 numerrs = decode_bch(doc->bch, NULL, DOCG4_USERDATA_LEN, NULL, in correct_data()
451 doc->ecc_buf, NULL, errpos); in correct_data()
453 if (numerrs == -EBADMSG) { in correct_data()
454 dev_warn(doc->dev, "uncorrectable errors at offset %08x\n", in correct_data()
456 return -EBADMSG; in correct_data()
459 BUG_ON(numerrs < 0); /* -EINVAL, or anything other than -EBADMSG */ in correct_data()
463 errpos[i] = (errpos[i] & ~7)|(7-(errpos[i] & 7)); in correct_data()
474 change_bit(errpos[i] - DOCG4_PAGE_SIZE * 8, in correct_data()
475 (unsigned long *)nand->oob_poi); in correct_data()
481 dev_notice(doc->dev, "%d error(s) corrected at offset %08x\n", in correct_data()
492 dev_dbg(doc->dev, "%s\n", __func__); in docg4_read_byte()
494 if (doc->last_command.command == NAND_CMD_STATUS) { in docg4_read_byte()
502 doc->last_command.command = 0; in docg4_read_byte()
504 if (doc->status) { in docg4_read_byte()
505 status = doc->status; in docg4_read_byte()
506 doc->status = 0; in docg4_read_byte()
516 dev_warn(doc->dev, "unexpected call to read_byte()\n"); in docg4_read_byte()
525 void __iomem *docptr = doc->virtadr; in write_addr()
542 void __iomem *docptr = doc->virtadr; in read_progstatus()
549 dev_dbg(doc->dev, "docg4: %s: %02x %02x %02x\n", in read_progstatus()
555 doc->status = NAND_STATUS_FAIL; in read_progstatus()
556 dev_warn(doc->dev, "read_progstatus failed: " in read_progstatus()
558 return -EIO; in read_progstatus()
572 void __iomem *docptr = doc->virtadr; in pageprog()
575 dev_dbg(doc->dev, "docg4: %s\n", __func__); in pageprog()
582 /* Just busy-wait; usleep_range() slows things down noticeably. */ in pageprog()
609 void __iomem *docptr = doc->virtadr; in sequence_reset()
626 void __iomem *docptr = doc->virtadr; in read_page_prologue()
628 dev_dbg(doc->dev, in read_page_prologue()
653 void __iomem *docptr = doc->virtadr; in write_page_prologue()
655 dev_dbg(doc->dev, in write_page_prologue()
680 * Some notes on G4 addressing... The M-Sys documentation on this device in mtd_to_docg4_address()
683 * four 512 byte "sub-pages", each with its own oob data that is in mtd_to_docg4_address()
688 * with four sub-pages each, we engage in a little subterfuge and tell in mtd_to_docg4_address()
690 * done because during the course of reverse-engineering the device, I in mtd_to_docg4_address()
692 * written as a unit. Each "sub-page" is always addressed individually, in mtd_to_docg4_address()
693 * its data read/written, and ecc handled before the next "sub-page" is in mtd_to_docg4_address()
701 * the page. The index is in terms of 16-bit half-words and includes in mtd_to_docg4_address()
703 * "sub-page" is 0x108, and the full device address of the start of mtd in mtd_to_docg4_address()
720 dev_dbg(doc->dev, "%s %x, page_addr=%x, column=%x\n", in docg4_command()
727 doc->last_command.command = command; in docg4_command()
728 doc->last_command.column = column; in docg4_command()
729 doc->last_command.page = page_addr; in docg4_command()
749 /* writes to odd-numbered 2k pages are invalid */ in docg4_command()
751 dev_warn(doc->dev, in docg4_command()
758 if (doc->oob_page == page_addr) in docg4_command()
759 memcpy(nand->oob_poi, doc->oob_buf, 16); in docg4_command()
771 dev_warn(doc->dev, "docg4_command: " in docg4_command()
782 void __iomem *docptr = doc->virtadr; in read_page()
786 dev_dbg(doc->dev, "%s: page %08x\n", __func__, page); in read_page()
804 dev_err(doc->dev, in read_page()
807 return -EIO; in read_page()
810 dev_dbg(doc->dev, "%s: status = 0x%x\n", __func__, status); in read_page()
816 docg4_read_buf(mtd, nand->oob_poi, 14); in read_page()
819 buf16 = (uint16_t *)(nand->oob_poi + 14); in read_page()
829 dev_dbg(doc->dev, "%s: edc_err = 0x%02x\n", __func__, edc_err); in read_page()
834 if (bits_corrected == -EBADMSG) in read_page()
835 mtd->ecc_stats.failed++; in read_page()
837 mtd->ecc_stats.corrected += bits_corrected; in read_page()
842 if (bits_corrected == -EBADMSG) /* uncorrectable errors */ in read_page()
864 void __iomem *docptr = doc->virtadr; in docg4_read_oob()
867 dev_dbg(doc->dev, "%s: page %x\n", __func__, page); in docg4_read_oob()
869 nand_read_page_op(nand, page, nand->ecc.size, NULL, 0); in docg4_read_oob()
881 dev_warn(doc->dev, in docg4_read_oob()
883 return -EIO; in docg4_read_oob()
886 dev_dbg(doc->dev, "%s: status = 0x%x\n", __func__, status); in docg4_read_oob()
888 docg4_read_buf(mtd, nand->oob_poi, 16); in docg4_read_oob()
903 void __iomem *docptr = doc->virtadr; in docg4_erase_block()
907 dev_dbg(doc->dev, "%s: page %04x\n", __func__, page); in docg4_erase_block()
945 status = nand->waitfunc(mtd, nand); in docg4_erase_block()
949 return status & NAND_STATUS_FAIL ? -EIO : 0; in docg4_erase_block()
956 void __iomem *docptr = doc->virtadr; in write_page()
959 dev_dbg(doc->dev, "%s...\n", __func__); in write_page()
973 docg4_write_buf16(mtd, nand->oob_poi, 6); in write_page()
976 writew(nand->oob_poi[6], docptr + DOCG4_OOB_6_7); in write_page()
981 /* write hw-generated ecc bytes to oob */ in write_page()
994 /* write user-supplied bytes to oob */ in write_page()
996 writew(nand->oob_poi[7], docptr + DOCG4_OOB_6_7); in write_page()
998 memcpy(ecc_buf, &nand->oob_poi[8], 8); in write_page()
1026 * Writing oob-only is not really supported, because MLC nand must write in docg4_write_oob()
1038 doc->oob_page = page; in docg4_write_oob()
1039 memcpy(doc->oob_buf, nand->oob_poi, 16); in docg4_write_oob()
1046 * The device contains a read-only factory bad block table. Read it and in read_factory_bbt()
1047 * update the memory-based bbt accordingly. in read_factory_bbt()
1055 __u32 eccfailed_stats = mtd->ecc_stats.failed; in read_factory_bbt()
1059 return -ENOMEM; in read_factory_bbt()
1065 * If no memory-based bbt was created, exit. This will happen if module in read_factory_bbt()
1068 * operation after device power-up. The above read ensures it never is. in read_factory_bbt()
1071 if (nand->bbt == NULL) /* no memory-based bbt */ in read_factory_bbt()
1074 if (mtd->ecc_stats.failed > eccfailed_stats) { in read_factory_bbt()
1079 eccfailed_stats = mtd->ecc_stats.failed; in read_factory_bbt()
1081 if (mtd->ecc_stats.failed > eccfailed_stats) { in read_factory_bbt()
1082 dev_warn(doc->dev, in read_factory_bbt()
1089 * Parse factory bbt and update memory-based bbt. Factory bbt format is in read_factory_bbt()
1097 int badblock = block + 7 - bitnum; in read_factory_bbt()
1098 nand->bbt[badblock / 4] |= in read_factory_bbt()
1100 mtd->ecc_stats.badblocks++; in read_factory_bbt()
1101 dev_notice(doc->dev, "factory-marked bad block: %d\n", in read_factory_bbt()
1115 * infrastructure code works fine for building the memory-based bbt in docg4_block_markbad()
1118 * the nand default because writes to oob-only are not supported. in docg4_block_markbad()
1125 struct nand_bbt_descr *bbtd = nand->badblock_pattern; in docg4_block_markbad()
1126 int page = (int)(ofs >> nand->page_shift); in docg4_block_markbad()
1129 dev_dbg(doc->dev, "%s: %08llx\n", __func__, ofs); in docg4_block_markbad()
1131 if (unlikely(ofs & (DOCG4_BLOCK_SIZE - 1))) in docg4_block_markbad()
1132 dev_warn(doc->dev, "%s: ofs %llx not start of block!\n", in docg4_block_markbad()
1138 return -ENOMEM; in docg4_block_markbad()
1140 /* write bit-wise negation of pattern to oob buffer */ in docg4_block_markbad()
1141 memset(nand->oob_poi, 0xff, mtd->oobsize); in docg4_block_markbad()
1142 for (i = 0; i < bbtd->len; i++) in docg4_block_markbad()
1143 nand->oob_poi[bbtd->offs + i] = ~bbtd->pattern[i]; in docg4_block_markbad()
1164 * Put the device into "deep power-down" mode. Note that CE# must be in docg4_suspend()
1166 * configured to float this signal when the processor enters power-down, in docg4_suspend()
1167 * and a suitable pull-up ensures its deassertion. in docg4_suspend()
1173 void __iomem *docptr = doc->virtadr; in docg4_suspend()
1175 dev_dbg(doc->dev, "%s...\n", __func__); in docg4_suspend()
1186 dev_err(doc->dev, "suspend failed; " in docg4_suspend()
1188 return -EIO; in docg4_suspend()
1205 * Exit power-down. Twelve consecutive reads of the address below in docg4_resume()
1210 void __iomem *docptr = doc->virtadr; in docg4_resume()
1213 dev_dbg(doc->dev, "%s...\n", __func__); in docg4_resume()
1238 mtd->size = DOCG4_CHIP_SIZE; in init_mtd_structs()
1239 mtd->name = "Msys_Diskonchip_G4"; in init_mtd_structs()
1240 mtd->writesize = DOCG4_PAGE_SIZE; in init_mtd_structs()
1241 mtd->erasesize = DOCG4_BLOCK_SIZE; in init_mtd_structs()
1242 mtd->oobsize = DOCG4_OOB_SIZE; in init_mtd_structs()
1244 nand->chipsize = DOCG4_CHIP_SIZE; in init_mtd_structs()
1245 nand->chip_shift = DOCG4_CHIP_SHIFT; in init_mtd_structs()
1246 nand->bbt_erase_shift = nand->phys_erase_shift = DOCG4_ERASE_SHIFT; in init_mtd_structs()
1247 nand->chip_delay = 20; in init_mtd_structs()
1248 nand->page_shift = DOCG4_PAGE_SHIFT; in init_mtd_structs()
1249 nand->pagemask = 0x3ffff; in init_mtd_structs()
1250 nand->badblockpos = NAND_LARGE_BADBLOCK_POS; in init_mtd_structs()
1251 nand->badblockbits = 8; in init_mtd_structs()
1252 nand->ecc.mode = NAND_ECC_HW_SYNDROME; in init_mtd_structs()
1253 nand->ecc.size = DOCG4_PAGE_SIZE; in init_mtd_structs()
1254 nand->ecc.prepad = 8; in init_mtd_structs()
1255 nand->ecc.bytes = 8; in init_mtd_structs()
1256 nand->ecc.strength = DOCG4_T; in init_mtd_structs()
1257 nand->options = NAND_BUSWIDTH_16 | NAND_NO_SUBPAGE_WRITE; in init_mtd_structs()
1258 nand->IO_ADDR_R = nand->IO_ADDR_W = doc->virtadr + DOC_IOSPACE_DATA; in init_mtd_structs()
1259 nand->controller = &nand->dummy_controller; in init_mtd_structs()
1260 nand_controller_init(nand->controller); in init_mtd_structs()
1263 nand->cmdfunc = docg4_command; in init_mtd_structs()
1264 nand->waitfunc = docg4_wait; in init_mtd_structs()
1265 nand->select_chip = docg4_select_chip; in init_mtd_structs()
1266 nand->read_byte = docg4_read_byte; in init_mtd_structs()
1267 nand->block_markbad = docg4_block_markbad; in init_mtd_structs()
1268 nand->read_buf = docg4_read_buf; in init_mtd_structs()
1269 nand->write_buf = docg4_write_buf16; in init_mtd_structs()
1270 nand->erase = docg4_erase_block; in init_mtd_structs()
1271 nand->set_features = nand_get_set_features_notsupp; in init_mtd_structs()
1272 nand->get_features = nand_get_set_features_notsupp; in init_mtd_structs()
1273 nand->ecc.read_page = docg4_read_page; in init_mtd_structs()
1274 nand->ecc.write_page = docg4_write_page; in init_mtd_structs()
1275 nand->ecc.read_page_raw = docg4_read_page_raw; in init_mtd_structs()
1276 nand->ecc.write_page_raw = docg4_write_page_raw; in init_mtd_structs()
1277 nand->ecc.read_oob = docg4_read_oob; in init_mtd_structs()
1278 nand->ecc.write_oob = docg4_write_oob; in init_mtd_structs()
1281 * The way the nand infrastructure code is written, a memory-based bbt in init_mtd_structs()
1283 * nand->block_bad() is used. So when ignoring bad blocks, we skip the in init_mtd_structs()
1287 nand->options |= NAND_SKIP_BBTSCAN; in init_mtd_structs()
1288 nand->block_bad = docg4_block_neverbad; in init_mtd_structs()
1297 void __iomem *docptr = doc->virtadr; in read_id_reg()
1307 dev_info(doc->dev, in read_id_reg()
1312 return -ENODEV; in read_id_reg()
1326 doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY); in docg4_attach_chip()
1327 if (!doc->bch) in docg4_attach_chip()
1328 return -EINVAL; in docg4_attach_chip()
1334 free_bch(doc->bch); in docg4_attach_chip()
1343 free_bch(doc->bch); in docg4_detach_chip()
1359 struct device *dev = &pdev->dev; in probe_docg4()
1364 return -ENODEV; in probe_docg4()
1367 virtadr = ioremap(r->start, resource_size(r)); in probe_docg4()
1370 return -EIO; in probe_docg4()
1376 retval = -ENOMEM; in probe_docg4()
1383 mtd->dev.parent = &pdev->dev; in probe_docg4()
1384 doc->virtadr = virtadr; in probe_docg4()
1385 doc->dev = dev; in probe_docg4()
1391 * ->attach_chip callback. in probe_docg4()
1393 nand->dummy_controller.ops = &docg4_controller_ops; in probe_docg4()
1406 doc->mtd = mtd; in probe_docg4()
1423 nand_release(mtd_to_nand(doc->mtd)); in cleanup_docg4()
1424 kfree(mtd_to_nand(doc->mtd)); in cleanup_docg4()
1425 iounmap(doc->virtadr); in cleanup_docg4()
1442 MODULE_DESCRIPTION("M-Systems DiskOnChip G4 device driver");