Lines Matching refs:ns
203 #define NS_IS_INITIALIZED(ns) ((ns)->geom.totsz != 0) argument
206 #define NS_STATUS_OK(ns) (NAND_STATUS_READY | (NAND_STATUS_WP * ((ns)->lines.wp == 0))) argument
209 #define NS_STATUS_FAILED(ns) (NAND_STATUS_FAIL | NS_STATUS_OK(ns)) argument
212 #define NS_RAW_OFFSET(ns) \ argument
213 (((ns)->regs.row * (ns)->geom.pgszoob) + (ns)->regs.column)
216 #define NS_RAW_OFFSET_OOB(ns) (NS_RAW_OFFSET(ns) + ns->geom.pgsz) argument
560 static void nandsim_debugfs_remove(struct nandsim *ns) in nandsim_debugfs_remove() argument
563 debugfs_remove_recursive(ns->dbg.dfs_root); in nandsim_debugfs_remove()
572 static int alloc_device(struct nandsim *ns) in alloc_device() argument
591 ns->pages_written = vzalloc(BITS_TO_LONGS(ns->geom.pgnum) * in alloc_device()
593 if (!ns->pages_written) { in alloc_device()
598 ns->file_buf = kmalloc(ns->geom.pgszoob, GFP_KERNEL); in alloc_device()
599 if (!ns->file_buf) { in alloc_device()
604 ns->cfile = cfile; in alloc_device()
608 ns->pages = vmalloc(ns->geom.pgnum * sizeof(union ns_mem)); in alloc_device()
609 if (!ns->pages) { in alloc_device()
613 for (i = 0; i < ns->geom.pgnum; i++) { in alloc_device()
614 ns->pages[i].byte = NULL; in alloc_device()
616 ns->nand_pages_slab = kmem_cache_create("nandsim", in alloc_device()
617 ns->geom.pgszoob, 0, 0, NULL); in alloc_device()
618 if (!ns->nand_pages_slab) { in alloc_device()
626 vfree(ns->pages_written); in alloc_device()
635 static void free_device(struct nandsim *ns) in free_device() argument
639 if (ns->cfile) { in free_device()
640 kfree(ns->file_buf); in free_device()
641 vfree(ns->pages_written); in free_device()
642 filp_close(ns->cfile, NULL); in free_device()
646 if (ns->pages) { in free_device()
647 for (i = 0; i < ns->geom.pgnum; i++) { in free_device()
648 if (ns->pages[i].byte) in free_device()
649 kmem_cache_free(ns->nand_pages_slab, in free_device()
650 ns->pages[i].byte); in free_device()
652 kmem_cache_destroy(ns->nand_pages_slab); in free_device()
653 vfree(ns->pages); in free_device()
670 struct nandsim *ns = chip->priv; in init_nandsim() local
675 if (NS_IS_INITIALIZED(ns)) { in init_nandsim()
684 ns->busw = chip->options & NAND_BUSWIDTH_16 ? 16 : 8; in init_nandsim()
685 ns->geom.totsz = mtd->size; in init_nandsim()
686 ns->geom.pgsz = mtd->writesize; in init_nandsim()
687 ns->geom.oobsz = mtd->oobsize; in init_nandsim()
688 ns->geom.secsz = mtd->erasesize; in init_nandsim()
689 ns->geom.pgszoob = ns->geom.pgsz + ns->geom.oobsz; in init_nandsim()
690 ns->geom.pgnum = div_u64(ns->geom.totsz, ns->geom.pgsz); in init_nandsim()
691 ns->geom.totszoob = ns->geom.totsz + (uint64_t)ns->geom.pgnum * ns->geom.oobsz; in init_nandsim()
692 ns->geom.secshift = ffs(ns->geom.secsz) - 1; in init_nandsim()
693 ns->geom.pgshift = chip->page_shift; in init_nandsim()
694 ns->geom.pgsec = ns->geom.secsz / ns->geom.pgsz; in init_nandsim()
695 ns->geom.secszoob = ns->geom.secsz + ns->geom.oobsz * ns->geom.pgsec; in init_nandsim()
696 ns->options = 0; in init_nandsim()
698 if (ns->geom.pgsz == 512) { in init_nandsim()
699 ns->options |= OPT_PAGE512; in init_nandsim()
700 if (ns->busw == 8) in init_nandsim()
701 ns->options |= OPT_PAGE512_8BIT; in init_nandsim()
702 } else if (ns->geom.pgsz == 2048) { in init_nandsim()
703 ns->options |= OPT_PAGE2048; in init_nandsim()
704 } else if (ns->geom.pgsz == 4096) { in init_nandsim()
705 ns->options |= OPT_PAGE4096; in init_nandsim()
707 NS_ERR("init_nandsim: unknown page size %u\n", ns->geom.pgsz); in init_nandsim()
711 if (ns->options & OPT_SMALLPAGE) { in init_nandsim()
712 if (ns->geom.totsz <= (32 << 20)) { in init_nandsim()
713 ns->geom.pgaddrbytes = 3; in init_nandsim()
714 ns->geom.secaddrbytes = 2; in init_nandsim()
716 ns->geom.pgaddrbytes = 4; in init_nandsim()
717 ns->geom.secaddrbytes = 3; in init_nandsim()
720 if (ns->geom.totsz <= (128 << 20)) { in init_nandsim()
721 ns->geom.pgaddrbytes = 4; in init_nandsim()
722 ns->geom.secaddrbytes = 2; in init_nandsim()
724 ns->geom.pgaddrbytes = 5; in init_nandsim()
725 ns->geom.secaddrbytes = 3; in init_nandsim()
730 if (parts_num > ARRAY_SIZE(ns->partitions)) { in init_nandsim()
735 remains = ns->geom.totsz; in init_nandsim()
738 uint64_t part_sz = (uint64_t)parts[i] * ns->geom.secsz; in init_nandsim()
745 ns->partitions[i].name = get_partition_name(i); in init_nandsim()
746 ns->partitions[i].offset = next_offset; in init_nandsim()
747 ns->partitions[i].size = part_sz; in init_nandsim()
748 next_offset += ns->partitions[i].size; in init_nandsim()
749 remains -= ns->partitions[i].size; in init_nandsim()
751 ns->nbparts = parts_num; in init_nandsim()
753 if (parts_num + 1 > ARRAY_SIZE(ns->partitions)) { in init_nandsim()
758 ns->partitions[i].name = get_partition_name(i); in init_nandsim()
759 ns->partitions[i].offset = next_offset; in init_nandsim()
760 ns->partitions[i].size = remains; in init_nandsim()
761 ns->nbparts += 1; in init_nandsim()
764 if (ns->busw == 16) in init_nandsim()
768 (unsigned long long)ns->geom.totsz >> 20); in init_nandsim()
769 printk("page size: %u bytes\n", ns->geom.pgsz); in init_nandsim()
770 printk("OOB area size: %u bytes\n", ns->geom.oobsz); in init_nandsim()
771 printk("sector size: %u KiB\n", ns->geom.secsz >> 10); in init_nandsim()
772 printk("pages number: %u\n", ns->geom.pgnum); in init_nandsim()
773 printk("pages per sector: %u\n", ns->geom.pgsec); in init_nandsim()
774 printk("bus width: %u\n", ns->busw); in init_nandsim()
775 printk("bits in sector size: %u\n", ns->geom.secshift); in init_nandsim()
776 printk("bits in page size: %u\n", ns->geom.pgshift); in init_nandsim()
777 printk("bits in OOB size: %u\n", ffs(ns->geom.oobsz) - 1); in init_nandsim()
779 (unsigned long long)ns->geom.totszoob >> 10); in init_nandsim()
780 printk("page address bytes: %u\n", ns->geom.pgaddrbytes); in init_nandsim()
781 printk("sector address bytes: %u\n", ns->geom.secaddrbytes); in init_nandsim()
782 printk("options: %#x\n", ns->options); in init_nandsim()
784 if ((ret = alloc_device(ns)) != 0) in init_nandsim()
788 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL); in init_nandsim()
789 if (!ns->buf.byte) { in init_nandsim()
791 ns->geom.pgszoob); in init_nandsim()
795 memset(ns->buf.byte, 0xFF, ns->geom.pgszoob); in init_nandsim()
800 free_device(ns); in init_nandsim()
808 static void free_nandsim(struct nandsim *ns) in free_nandsim() argument
810 kfree(ns->buf.byte); in free_nandsim()
811 free_device(ns); in free_nandsim()
816 static int parse_badblocks(struct nandsim *ns, struct mtd_info *mtd) in parse_badblocks() argument
833 offset = (loff_t)erase_block_no * ns->geom.secsz; in parse_badblocks()
1177 static inline void accept_addr_byte(struct nandsim *ns, u_char bt) in accept_addr_byte() argument
1181 if (ns->regs.count < (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) in accept_addr_byte()
1182 ns->regs.column |= (byte << 8 * ns->regs.count); in accept_addr_byte()
1184 ns->regs.row |= (byte << 8 * (ns->regs.count - in accept_addr_byte()
1185 ns->geom.pgaddrbytes + in accept_addr_byte()
1186 ns->geom.secaddrbytes)); in accept_addr_byte()
1195 static inline void switch_to_ready_state(struct nandsim *ns, u_char status) in switch_to_ready_state() argument
1199 ns->state = STATE_READY; in switch_to_ready_state()
1200 ns->nxstate = STATE_UNKNOWN; in switch_to_ready_state()
1201 ns->op = NULL; in switch_to_ready_state()
1202 ns->npstates = 0; in switch_to_ready_state()
1203 ns->stateidx = 0; in switch_to_ready_state()
1204 ns->regs.num = 0; in switch_to_ready_state()
1205 ns->regs.count = 0; in switch_to_ready_state()
1206 ns->regs.off = 0; in switch_to_ready_state()
1207 ns->regs.row = 0; in switch_to_ready_state()
1208 ns->regs.column = 0; in switch_to_ready_state()
1209 ns->regs.status = status; in switch_to_ready_state()
1254 static int find_operation(struct nandsim *ns, uint32_t flag) in find_operation() argument
1263 if (!(ns->options & ops[i].reqopts)) in find_operation()
1268 if (!(ops[i].states[ns->npstates] & STATE_ADDR_MASK)) in find_operation()
1271 if (NS_STATE(ns->state) != NS_STATE(ops[i].states[ns->npstates])) in find_operation()
1275 for (j = 0; j < ns->npstates; j++) in find_operation()
1276 if (NS_STATE(ops[i].states[j]) != NS_STATE(ns->pstates[j]) in find_operation()
1277 && (ns->options & ops[idx].reqopts)) { in find_operation()
1290 ns->op = &ops[idx].states[0]; in find_operation()
1299 ns->stateidx = ns->npstates - 1; in find_operation()
1301 ns->stateidx = ns->npstates; in find_operation()
1303 ns->npstates = 0; in find_operation()
1304 ns->state = ns->op[ns->stateidx]; in find_operation()
1305 ns->nxstate = ns->op[ns->stateidx + 1]; in find_operation()
1307 idx, get_state_name(ns->state), get_state_name(ns->nxstate)); in find_operation()
1313 if (ns->npstates != 0) { in find_operation()
1315 get_state_name(ns->state)); in find_operation()
1316 ns->npstates = 0; in find_operation()
1317 return find_operation(ns, 0); in find_operation()
1321 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in find_operation()
1333 ns->pstates[ns->npstates++] = ns->state; in find_operation()
1338 static void put_pages(struct nandsim *ns) in put_pages() argument
1342 for (i = 0; i < ns->held_cnt; i++) in put_pages()
1343 page_cache_release(ns->held_pages[i]); in put_pages()
1347 static int get_pages(struct nandsim *ns, struct file *file, size_t count, loff_t pos) in get_pages() argument
1357 ns->held_cnt = 0; in get_pages()
1367 put_pages(ns); in get_pages()
1372 ns->held_pages[ns->held_cnt++] = page; in get_pages()
1391 static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) in read_file() argument
1396 err = get_pages(ns, file, count, pos); in read_file()
1402 put_pages(ns); in read_file()
1406 static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t po… in write_file() argument
1411 err = get_pages(ns, file, count, pos); in write_file()
1417 put_pages(ns); in write_file()
1424 static inline union ns_mem *NS_GET_PAGE(struct nandsim *ns) in NS_GET_PAGE() argument
1426 return &(ns->pages[ns->regs.row]); in NS_GET_PAGE()
1432 static inline u_char *NS_PAGE_BYTE_OFF(struct nandsim *ns) in NS_PAGE_BYTE_OFF() argument
1434 return NS_GET_PAGE(ns)->byte + ns->regs.column + ns->regs.off; in NS_PAGE_BYTE_OFF()
1437 static int do_read_error(struct nandsim *ns, int num) in do_read_error() argument
1439 unsigned int page_no = ns->regs.row; in do_read_error()
1442 prandom_bytes(ns->buf.byte, num); in do_read_error()
1449 static void do_bit_flips(struct nandsim *ns, int num) in do_bit_flips() argument
1457 ns->buf.byte[pos / 8] ^= (1 << (pos % 8)); in do_bit_flips()
1460 pos, ns->regs.row, ns->regs.column + ns->regs.off, in do_bit_flips()
1469 static void read_page(struct nandsim *ns, int num) in read_page() argument
1473 if (ns->cfile) { in read_page()
1474 if (!test_bit(ns->regs.row, ns->pages_written)) { in read_page()
1475 NS_DBG("read_page: page %d not written\n", ns->regs.row); in read_page()
1476 memset(ns->buf.byte, 0xFF, num); in read_page()
1482 ns->regs.row, ns->regs.column + ns->regs.off); in read_page()
1483 if (do_read_error(ns, num)) in read_page()
1485 pos = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; in read_page()
1486 tx = read_file(ns, ns->cfile, ns->buf.byte, num, pos); in read_page()
1488 NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); in read_page()
1491 do_bit_flips(ns, num); in read_page()
1496 mypage = NS_GET_PAGE(ns); in read_page()
1498 NS_DBG("read_page: page %d not allocated\n", ns->regs.row); in read_page()
1499 memset(ns->buf.byte, 0xFF, num); in read_page()
1502 ns->regs.row, ns->regs.column + ns->regs.off); in read_page()
1503 if (do_read_error(ns, num)) in read_page()
1505 memcpy(ns->buf.byte, NS_PAGE_BYTE_OFF(ns), num); in read_page()
1506 do_bit_flips(ns, num); in read_page()
1513 static void erase_sector(struct nandsim *ns) in erase_sector() argument
1518 if (ns->cfile) { in erase_sector()
1519 for (i = 0; i < ns->geom.pgsec; i++) in erase_sector()
1520 if (__test_and_clear_bit(ns->regs.row + i, in erase_sector()
1521 ns->pages_written)) { in erase_sector()
1522 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row + i); in erase_sector()
1527 mypage = NS_GET_PAGE(ns); in erase_sector()
1528 for (i = 0; i < ns->geom.pgsec; i++) { in erase_sector()
1530 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row+i); in erase_sector()
1531 kmem_cache_free(ns->nand_pages_slab, mypage->byte); in erase_sector()
1541 static int prog_page(struct nandsim *ns, int num) in prog_page() argument
1547 if (ns->cfile) { in prog_page()
1552 NS_DBG("prog_page: writing page %d\n", ns->regs.row); in prog_page()
1553 pg_off = ns->file_buf + ns->regs.column + ns->regs.off; in prog_page()
1554 off = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; in prog_page()
1555 if (!test_bit(ns->regs.row, ns->pages_written)) { in prog_page()
1557 memset(ns->file_buf, 0xff, ns->geom.pgszoob); in prog_page()
1560 tx = read_file(ns, ns->cfile, pg_off, num, off); in prog_page()
1562 NS_ERR("prog_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1567 pg_off[i] &= ns->buf.byte[i]; in prog_page()
1569 loff_t pos = (loff_t)ns->regs.row * ns->geom.pgszoob; in prog_page()
1570 tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, pos); in prog_page()
1571 if (tx != ns->geom.pgszoob) { in prog_page()
1572 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1575 __set_bit(ns->regs.row, ns->pages_written); in prog_page()
1577 tx = write_file(ns, ns->cfile, pg_off, num, off); in prog_page()
1579 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1586 mypage = NS_GET_PAGE(ns); in prog_page()
1588 NS_DBG("prog_page: allocating page %d\n", ns->regs.row); in prog_page()
1595 mypage->byte = kmem_cache_alloc(ns->nand_pages_slab, GFP_NOFS); in prog_page()
1597 NS_ERR("prog_page: error allocating memory for page %d\n", ns->regs.row); in prog_page()
1600 memset(mypage->byte, 0xFF, ns->geom.pgszoob); in prog_page()
1603 pg_off = NS_PAGE_BYTE_OFF(ns); in prog_page()
1605 pg_off[i] &= ns->buf.byte[i]; in prog_page()
1615 static int do_state_action(struct nandsim *ns, uint32_t action) in do_state_action() argument
1618 int busdiv = ns->busw == 8 ? 1 : 2; in do_state_action()
1624 if (action != ACTION_SECERASE && ns->regs.row >= ns->geom.pgnum) { in do_state_action()
1625 NS_WARN("do_state_action: wrong page number (%#x)\n", ns->regs.row); in do_state_action()
1637 if (ns->regs.column >= (ns->geom.pgszoob - ns->regs.off)) { in do_state_action()
1641 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in do_state_action()
1642 read_page(ns, num); in do_state_action()
1645 num, NS_RAW_OFFSET(ns) + ns->regs.off); in do_state_action()
1647 if (ns->regs.off == 0) in do_state_action()
1648 NS_LOG("read page %d\n", ns->regs.row); in do_state_action()
1649 else if (ns->regs.off < ns->geom.pgsz) in do_state_action()
1650 NS_LOG("read page %d (second half)\n", ns->regs.row); in do_state_action()
1652 NS_LOG("read OOB of page %d\n", ns->regs.row); in do_state_action()
1655 NS_UDELAY(input_cycle * ns->geom.pgsz / 1000 / busdiv); in do_state_action()
1664 if (ns->lines.wp) { in do_state_action()
1669 if (ns->regs.row >= ns->geom.pgnum - ns->geom.pgsec in do_state_action()
1670 || (ns->regs.row & ~(ns->geom.secsz - 1))) { in do_state_action()
1671 NS_ERR("do_state_action: wrong sector address (%#x)\n", ns->regs.row); in do_state_action()
1675 ns->regs.row = (ns->regs.row << in do_state_action()
1676 8 * (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) | ns->regs.column; in do_state_action()
1677 ns->regs.column = 0; in do_state_action()
1679 erase_block_no = ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift); in do_state_action()
1682 ns->regs.row, NS_RAW_OFFSET(ns)); in do_state_action()
1685 erase_sector(ns); in do_state_action()
1704 if (ns->lines.wp) { in do_state_action()
1709 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in do_state_action()
1710 if (num != ns->regs.count) { in do_state_action()
1712 ns->regs.count, num); in do_state_action()
1716 if (prog_page(ns, num) == -1) in do_state_action()
1719 page_no = ns->regs.row; in do_state_action()
1722 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off); in do_state_action()
1723 NS_LOG("programm page %d\n", ns->regs.row); in do_state_action()
1726 NS_UDELAY(output_cycle * ns->geom.pgsz / 1000 / busdiv); in do_state_action()
1737 ns->regs.off = 0; in do_state_action()
1741 if (!(ns->options & OPT_PAGE512_8BIT)) { in do_state_action()
1746 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz/2); in do_state_action()
1747 ns->regs.off = ns->geom.pgsz/2; in do_state_action()
1751 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz); in do_state_action()
1752 ns->regs.off = ns->geom.pgsz; in do_state_action()
1765 static void switch_state(struct nandsim *ns) in switch_state() argument
1767 if (ns->op) { in switch_state()
1773 ns->stateidx += 1; in switch_state()
1774 ns->state = ns->nxstate; in switch_state()
1775 ns->nxstate = ns->op[ns->stateidx + 1]; in switch_state()
1779 get_state_name(ns->state), get_state_name(ns->nxstate)); in switch_state()
1782 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in switch_state()
1783 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in switch_state()
1797 ns->state = get_state_by_command(ns->regs.command); in switch_state()
1801 if (find_operation(ns, 0) != 0) in switch_state()
1804 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in switch_state()
1805 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in switch_state()
1811 if ((ns->nxstate & STATE_ADDR_MASK) && ns->busw == 16) { in switch_state()
1813 ns->regs.column <<= 1; in switch_state()
1816 if (NS_STATE(ns->nxstate) == STATE_READY) { in switch_state()
1821 u_char status = NS_STATUS_OK(ns); in switch_state()
1824 if ((ns->state & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) in switch_state()
1825 && ns->regs.count != ns->regs.num) { in switch_state()
1827 ns->regs.num - ns->regs.count); in switch_state()
1828 status = NS_STATUS_FAILED(ns); in switch_state()
1833 switch_to_ready_state(ns, status); in switch_state()
1836 } else if (ns->nxstate & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) { in switch_state()
1841 ns->state = ns->nxstate; in switch_state()
1842 ns->nxstate = ns->op[++ns->stateidx + 1]; in switch_state()
1843 ns->regs.num = ns->regs.count = 0; in switch_state()
1847 get_state_name(ns->state), get_state_name(ns->nxstate)); in switch_state()
1853 switch (NS_STATE(ns->state)) { in switch_state()
1856 ns->regs.num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in switch_state()
1860 ns->regs.num = ns->geom.idbytes; in switch_state()
1864 ns->regs.count = ns->regs.num = 0; in switch_state()
1871 } else if (ns->nxstate & STATE_ADDR_MASK) { in switch_state()
1877 ns->regs.count = 0; in switch_state()
1879 switch (NS_STATE(ns->nxstate)) { in switch_state()
1881 ns->regs.num = ns->geom.pgaddrbytes; in switch_state()
1885 ns->regs.num = ns->geom.secaddrbytes; in switch_state()
1889 ns->regs.num = 1; in switch_state()
1894 ns->regs.num = ns->geom.pgaddrbytes - ns->geom.secaddrbytes; in switch_state()
1905 ns->regs.num = 0; in switch_state()
1906 ns->regs.count = 0; in switch_state()
1912 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_read_byte() local
1916 if (!ns->lines.ce) { in ns_nand_read_byte()
1920 if (ns->lines.ale || ns->lines.cle) { in ns_nand_read_byte()
1924 if (!(ns->state & STATE_DATAOUT_MASK)) { in ns_nand_read_byte()
1926 "return %#x\n", get_state_name(ns->state), (uint)outb); in ns_nand_read_byte()
1931 if (NS_STATE(ns->state) == STATE_DATAOUT_STATUS) { in ns_nand_read_byte()
1932 NS_DBG("read_byte: return %#x status\n", ns->regs.status); in ns_nand_read_byte()
1933 return ns->regs.status; in ns_nand_read_byte()
1937 if (ns->regs.count == ns->regs.num) { in ns_nand_read_byte()
1942 switch (NS_STATE(ns->state)) { in ns_nand_read_byte()
1944 if (ns->busw == 8) { in ns_nand_read_byte()
1945 outb = ns->buf.byte[ns->regs.count]; in ns_nand_read_byte()
1946 ns->regs.count += 1; in ns_nand_read_byte()
1948 outb = (u_char)cpu_to_le16(ns->buf.word[ns->regs.count >> 1]); in ns_nand_read_byte()
1949 ns->regs.count += 2; in ns_nand_read_byte()
1953 NS_DBG("read_byte: read ID byte %d, total = %d\n", ns->regs.count, ns->regs.num); in ns_nand_read_byte()
1954 outb = ns->ids[ns->regs.count]; in ns_nand_read_byte()
1955 ns->regs.count += 1; in ns_nand_read_byte()
1961 if (ns->regs.count == ns->regs.num) { in ns_nand_read_byte()
1964 if (NS_STATE(ns->nxstate) == STATE_READY) in ns_nand_read_byte()
1965 switch_state(ns); in ns_nand_read_byte()
1973 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_write_byte() local
1976 if (!ns->lines.ce) { in ns_nand_write_byte()
1980 if (ns->lines.ale && ns->lines.cle) { in ns_nand_write_byte()
1985 if (ns->lines.cle == 1) { in ns_nand_write_byte()
1992 switch_to_ready_state(ns, NS_STATUS_OK(ns)); in ns_nand_write_byte()
2002 if (NS_STATE(ns->state) == STATE_DATAOUT_STATUS in ns_nand_write_byte()
2003 || NS_STATE(ns->state) == STATE_DATAOUT) { in ns_nand_write_byte()
2004 int row = ns->regs.row; in ns_nand_write_byte()
2006 switch_state(ns); in ns_nand_write_byte()
2008 ns->regs.row = row; in ns_nand_write_byte()
2012 if (NS_STATE(ns->nxstate) != STATE_UNKNOWN && !(ns->nxstate & STATE_CMD_MASK)) { in ns_nand_write_byte()
2014 if (!(ns->regs.command == NAND_CMD_READID && in ns_nand_write_byte()
2015 NS_STATE(ns->state) == STATE_DATAOUT_ID && ns->regs.count == 2)) { in ns_nand_write_byte()
2022 "ignore previous states\n", (uint)byte, get_state_name(ns->nxstate)); in ns_nand_write_byte()
2024 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2029 ns->regs.command = byte; in ns_nand_write_byte()
2030 switch_state(ns); in ns_nand_write_byte()
2032 } else if (ns->lines.ale == 1) { in ns_nand_write_byte()
2037 if (NS_STATE(ns->nxstate) == STATE_UNKNOWN) { in ns_nand_write_byte()
2041 if (find_operation(ns, 1) < 0) in ns_nand_write_byte()
2044 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in ns_nand_write_byte()
2045 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2049 ns->regs.count = 0; in ns_nand_write_byte()
2050 switch (NS_STATE(ns->nxstate)) { in ns_nand_write_byte()
2052 ns->regs.num = ns->geom.pgaddrbytes; in ns_nand_write_byte()
2055 ns->regs.num = ns->geom.secaddrbytes; in ns_nand_write_byte()
2058 ns->regs.num = 1; in ns_nand_write_byte()
2066 if (!(ns->nxstate & STATE_ADDR_MASK)) { in ns_nand_write_byte()
2068 "switch to STATE_READY\n", (uint)byte, get_state_name(ns->nxstate)); in ns_nand_write_byte()
2069 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2074 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2076 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2080 accept_addr_byte(ns, byte); in ns_nand_write_byte()
2082 ns->regs.count += 1; in ns_nand_write_byte()
2085 (uint)byte, ns->regs.count, ns->regs.num); in ns_nand_write_byte()
2087 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2088 NS_DBG("address (%#x, %#x) is accepted\n", ns->regs.row, ns->regs.column); in ns_nand_write_byte()
2089 switch_state(ns); in ns_nand_write_byte()
2098 if (!(ns->state & STATE_DATAIN_MASK)) { in ns_nand_write_byte()
2101 get_state_name(ns->state), get_state_name(STATE_READY)); in ns_nand_write_byte()
2102 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2107 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2109 ns->regs.num); in ns_nand_write_byte()
2113 if (ns->busw == 8) { in ns_nand_write_byte()
2114 ns->buf.byte[ns->regs.count] = byte; in ns_nand_write_byte()
2115 ns->regs.count += 1; in ns_nand_write_byte()
2117 ns->buf.word[ns->regs.count >> 1] = cpu_to_le16((uint16_t)byte); in ns_nand_write_byte()
2118 ns->regs.count += 2; in ns_nand_write_byte()
2127 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_hwcontrol() local
2129 ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; in ns_hwcontrol()
2130 ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; in ns_hwcontrol()
2131 ns->lines.ce = bitmask & NAND_NCE ? 1 : 0; in ns_hwcontrol()
2154 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_write_buf() local
2157 if (!(ns->state & STATE_DATAIN_MASK)) { in ns_nand_write_buf()
2159 "switch to STATE_READY\n", get_state_name(ns->state)); in ns_nand_write_buf()
2160 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_buf()
2165 if (ns->regs.count + len > ns->regs.num) { in ns_nand_write_buf()
2167 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_buf()
2171 memcpy(ns->buf.byte + ns->regs.count, buf, len); in ns_nand_write_buf()
2172 ns->regs.count += len; in ns_nand_write_buf()
2174 if (ns->regs.count == ns->regs.num) { in ns_nand_write_buf()
2175 NS_DBG("write_buf: %d bytes were written\n", ns->regs.count); in ns_nand_write_buf()
2181 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_read_buf() local
2184 if (!ns->lines.ce) { in ns_nand_read_buf()
2188 if (ns->lines.ale || ns->lines.cle) { in ns_nand_read_buf()
2192 if (!(ns->state & STATE_DATAOUT_MASK)) { in ns_nand_read_buf()
2194 get_state_name(ns->state)); in ns_nand_read_buf()
2198 if (NS_STATE(ns->state) != STATE_DATAOUT) { in ns_nand_read_buf()
2208 if (ns->regs.count + len > ns->regs.num) { in ns_nand_read_buf()
2210 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_read_buf()
2214 memcpy(buf, ns->buf.byte + ns->regs.count, len); in ns_nand_read_buf()
2215 ns->regs.count += len; in ns_nand_read_buf()
2217 if (ns->regs.count == ns->regs.num) { in ns_nand_read_buf()
2218 if (NS_STATE(ns->nxstate) == STATE_READY) in ns_nand_read_buf()
2219 switch_state(ns); in ns_nand_read_buf()
2409 struct nandsim *ns = ((struct nand_chip *)nsmtd->priv)->priv; in ns_cleanup_module() local
2412 nandsim_debugfs_remove(ns); in ns_cleanup_module()
2413 free_nandsim(ns); /* Free nandsim private resources */ in ns_cleanup_module()
2415 for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) in ns_cleanup_module()
2416 kfree(ns->partitions[i].name); in ns_cleanup_module()