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()
734 remains = ns->geom.totsz; in init_nandsim()
737 uint64_t part_sz = (uint64_t)parts[i] * ns->geom.secsz; in init_nandsim()
743 ns->partitions[i].name = get_partition_name(i); in init_nandsim()
744 if (!ns->partitions[i].name) { in init_nandsim()
748 ns->partitions[i].offset = next_offset; in init_nandsim()
749 ns->partitions[i].size = part_sz; in init_nandsim()
750 next_offset += ns->partitions[i].size; in init_nandsim()
751 remains -= ns->partitions[i].size; in init_nandsim()
753 ns->nbparts = parts_num; in init_nandsim()
755 if (parts_num + 1 > ARRAY_SIZE(ns->partitions)) { in init_nandsim()
759 ns->partitions[i].name = get_partition_name(i); in init_nandsim()
760 if (!ns->partitions[i].name) { in init_nandsim()
764 ns->partitions[i].offset = next_offset; in init_nandsim()
765 ns->partitions[i].size = remains; in init_nandsim()
766 ns->nbparts += 1; in init_nandsim()
769 if (ns->busw == 16) in init_nandsim()
773 (unsigned long long)ns->geom.totsz >> 20); in init_nandsim()
774 printk("page size: %u bytes\n", ns->geom.pgsz); in init_nandsim()
775 printk("OOB area size: %u bytes\n", ns->geom.oobsz); in init_nandsim()
776 printk("sector size: %u KiB\n", ns->geom.secsz >> 10); in init_nandsim()
777 printk("pages number: %u\n", ns->geom.pgnum); in init_nandsim()
778 printk("pages per sector: %u\n", ns->geom.pgsec); in init_nandsim()
779 printk("bus width: %u\n", ns->busw); in init_nandsim()
780 printk("bits in sector size: %u\n", ns->geom.secshift); in init_nandsim()
781 printk("bits in page size: %u\n", ns->geom.pgshift); in init_nandsim()
782 printk("bits in OOB size: %u\n", ffs(ns->geom.oobsz) - 1); in init_nandsim()
784 (unsigned long long)ns->geom.totszoob >> 10); in init_nandsim()
785 printk("page address bytes: %u\n", ns->geom.pgaddrbytes); in init_nandsim()
786 printk("sector address bytes: %u\n", ns->geom.secaddrbytes); in init_nandsim()
787 printk("options: %#x\n", ns->options); in init_nandsim()
789 if ((ret = alloc_device(ns)) != 0) in init_nandsim()
793 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL); in init_nandsim()
794 if (!ns->buf.byte) { in init_nandsim()
796 ns->geom.pgszoob); in init_nandsim()
799 memset(ns->buf.byte, 0xFF, ns->geom.pgszoob); in init_nandsim()
807 static void free_nandsim(struct nandsim *ns) in free_nandsim() argument
809 kfree(ns->buf.byte); in free_nandsim()
810 free_device(ns); in free_nandsim()
815 static int parse_badblocks(struct nandsim *ns, struct mtd_info *mtd) in parse_badblocks() argument
832 offset = (loff_t)erase_block_no * ns->geom.secsz; in parse_badblocks()
1176 static inline void accept_addr_byte(struct nandsim *ns, u_char bt) in accept_addr_byte() argument
1180 if (ns->regs.count < (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) in accept_addr_byte()
1181 ns->regs.column |= (byte << 8 * ns->regs.count); in accept_addr_byte()
1183 ns->regs.row |= (byte << 8 * (ns->regs.count - in accept_addr_byte()
1184 ns->geom.pgaddrbytes + in accept_addr_byte()
1185 ns->geom.secaddrbytes)); in accept_addr_byte()
1194 static inline void switch_to_ready_state(struct nandsim *ns, u_char status) in switch_to_ready_state() argument
1198 ns->state = STATE_READY; in switch_to_ready_state()
1199 ns->nxstate = STATE_UNKNOWN; in switch_to_ready_state()
1200 ns->op = NULL; in switch_to_ready_state()
1201 ns->npstates = 0; in switch_to_ready_state()
1202 ns->stateidx = 0; in switch_to_ready_state()
1203 ns->regs.num = 0; in switch_to_ready_state()
1204 ns->regs.count = 0; in switch_to_ready_state()
1205 ns->regs.off = 0; in switch_to_ready_state()
1206 ns->regs.row = 0; in switch_to_ready_state()
1207 ns->regs.column = 0; in switch_to_ready_state()
1208 ns->regs.status = status; in switch_to_ready_state()
1253 static int find_operation(struct nandsim *ns, uint32_t flag) in find_operation() argument
1262 if (!(ns->options & ops[i].reqopts)) in find_operation()
1267 if (!(ops[i].states[ns->npstates] & STATE_ADDR_MASK)) in find_operation()
1270 if (NS_STATE(ns->state) != NS_STATE(ops[i].states[ns->npstates])) in find_operation()
1274 for (j = 0; j < ns->npstates; j++) in find_operation()
1275 if (NS_STATE(ops[i].states[j]) != NS_STATE(ns->pstates[j]) in find_operation()
1276 && (ns->options & ops[idx].reqopts)) { in find_operation()
1289 ns->op = &ops[idx].states[0]; in find_operation()
1298 ns->stateidx = ns->npstates - 1; in find_operation()
1300 ns->stateidx = ns->npstates; in find_operation()
1302 ns->npstates = 0; in find_operation()
1303 ns->state = ns->op[ns->stateidx]; in find_operation()
1304 ns->nxstate = ns->op[ns->stateidx + 1]; in find_operation()
1306 idx, get_state_name(ns->state), get_state_name(ns->nxstate)); in find_operation()
1312 if (ns->npstates != 0) { in find_operation()
1314 get_state_name(ns->state)); in find_operation()
1315 ns->npstates = 0; in find_operation()
1316 return find_operation(ns, 0); in find_operation()
1320 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in find_operation()
1332 ns->pstates[ns->npstates++] = ns->state; in find_operation()
1337 static void put_pages(struct nandsim *ns) in put_pages() argument
1341 for (i = 0; i < ns->held_cnt; i++) in put_pages()
1342 page_cache_release(ns->held_pages[i]); in put_pages()
1346 static int get_pages(struct nandsim *ns, struct file *file, size_t count, loff_t pos) in get_pages() argument
1356 ns->held_cnt = 0; in get_pages()
1366 put_pages(ns); in get_pages()
1371 ns->held_pages[ns->held_cnt++] = page; in get_pages()
1390 static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) in read_file() argument
1395 err = get_pages(ns, file, count, pos); in read_file()
1401 put_pages(ns); in read_file()
1405 static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t po… in write_file() argument
1410 err = get_pages(ns, file, count, pos); in write_file()
1416 put_pages(ns); in write_file()
1423 static inline union ns_mem *NS_GET_PAGE(struct nandsim *ns) in NS_GET_PAGE() argument
1425 return &(ns->pages[ns->regs.row]); in NS_GET_PAGE()
1431 static inline u_char *NS_PAGE_BYTE_OFF(struct nandsim *ns) in NS_PAGE_BYTE_OFF() argument
1433 return NS_GET_PAGE(ns)->byte + ns->regs.column + ns->regs.off; in NS_PAGE_BYTE_OFF()
1436 static int do_read_error(struct nandsim *ns, int num) in do_read_error() argument
1438 unsigned int page_no = ns->regs.row; in do_read_error()
1441 prandom_bytes(ns->buf.byte, num); in do_read_error()
1448 static void do_bit_flips(struct nandsim *ns, int num) in do_bit_flips() argument
1456 ns->buf.byte[pos / 8] ^= (1 << (pos % 8)); in do_bit_flips()
1459 pos, ns->regs.row, ns->regs.column + ns->regs.off, in do_bit_flips()
1468 static void read_page(struct nandsim *ns, int num) in read_page() argument
1472 if (ns->cfile) { in read_page()
1473 if (!test_bit(ns->regs.row, ns->pages_written)) { in read_page()
1474 NS_DBG("read_page: page %d not written\n", ns->regs.row); in read_page()
1475 memset(ns->buf.byte, 0xFF, num); in read_page()
1481 ns->regs.row, ns->regs.column + ns->regs.off); in read_page()
1482 if (do_read_error(ns, num)) in read_page()
1484 pos = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; in read_page()
1485 tx = read_file(ns, ns->cfile, ns->buf.byte, num, pos); in read_page()
1487 NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); in read_page()
1490 do_bit_flips(ns, num); in read_page()
1495 mypage = NS_GET_PAGE(ns); in read_page()
1497 NS_DBG("read_page: page %d not allocated\n", ns->regs.row); in read_page()
1498 memset(ns->buf.byte, 0xFF, num); in read_page()
1501 ns->regs.row, ns->regs.column + ns->regs.off); in read_page()
1502 if (do_read_error(ns, num)) in read_page()
1504 memcpy(ns->buf.byte, NS_PAGE_BYTE_OFF(ns), num); in read_page()
1505 do_bit_flips(ns, num); in read_page()
1512 static void erase_sector(struct nandsim *ns) in erase_sector() argument
1517 if (ns->cfile) { in erase_sector()
1518 for (i = 0; i < ns->geom.pgsec; i++) in erase_sector()
1519 if (__test_and_clear_bit(ns->regs.row + i, in erase_sector()
1520 ns->pages_written)) { in erase_sector()
1521 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row + i); in erase_sector()
1526 mypage = NS_GET_PAGE(ns); in erase_sector()
1527 for (i = 0; i < ns->geom.pgsec; i++) { in erase_sector()
1529 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row+i); in erase_sector()
1530 kmem_cache_free(ns->nand_pages_slab, mypage->byte); in erase_sector()
1540 static int prog_page(struct nandsim *ns, int num) in prog_page() argument
1546 if (ns->cfile) { in prog_page()
1551 NS_DBG("prog_page: writing page %d\n", ns->regs.row); in prog_page()
1552 pg_off = ns->file_buf + ns->regs.column + ns->regs.off; in prog_page()
1553 off = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; in prog_page()
1554 if (!test_bit(ns->regs.row, ns->pages_written)) { in prog_page()
1556 memset(ns->file_buf, 0xff, ns->geom.pgszoob); in prog_page()
1559 tx = read_file(ns, ns->cfile, pg_off, num, off); in prog_page()
1561 NS_ERR("prog_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1566 pg_off[i] &= ns->buf.byte[i]; in prog_page()
1568 loff_t pos = (loff_t)ns->regs.row * ns->geom.pgszoob; in prog_page()
1569 tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, pos); in prog_page()
1570 if (tx != ns->geom.pgszoob) { in prog_page()
1571 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1574 __set_bit(ns->regs.row, ns->pages_written); in prog_page()
1576 tx = write_file(ns, ns->cfile, pg_off, num, off); in prog_page()
1578 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1585 mypage = NS_GET_PAGE(ns); in prog_page()
1587 NS_DBG("prog_page: allocating page %d\n", ns->regs.row); in prog_page()
1594 mypage->byte = kmem_cache_alloc(ns->nand_pages_slab, GFP_NOFS); in prog_page()
1596 NS_ERR("prog_page: error allocating memory for page %d\n", ns->regs.row); in prog_page()
1599 memset(mypage->byte, 0xFF, ns->geom.pgszoob); in prog_page()
1602 pg_off = NS_PAGE_BYTE_OFF(ns); in prog_page()
1604 pg_off[i] &= ns->buf.byte[i]; in prog_page()
1614 static int do_state_action(struct nandsim *ns, uint32_t action) in do_state_action() argument
1617 int busdiv = ns->busw == 8 ? 1 : 2; in do_state_action()
1623 if (action != ACTION_SECERASE && ns->regs.row >= ns->geom.pgnum) { in do_state_action()
1624 NS_WARN("do_state_action: wrong page number (%#x)\n", ns->regs.row); in do_state_action()
1636 if (ns->regs.column >= (ns->geom.pgszoob - ns->regs.off)) { in do_state_action()
1640 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in do_state_action()
1641 read_page(ns, num); in do_state_action()
1644 num, NS_RAW_OFFSET(ns) + ns->regs.off); in do_state_action()
1646 if (ns->regs.off == 0) in do_state_action()
1647 NS_LOG("read page %d\n", ns->regs.row); in do_state_action()
1648 else if (ns->regs.off < ns->geom.pgsz) in do_state_action()
1649 NS_LOG("read page %d (second half)\n", ns->regs.row); in do_state_action()
1651 NS_LOG("read OOB of page %d\n", ns->regs.row); in do_state_action()
1654 NS_UDELAY(input_cycle * ns->geom.pgsz / 1000 / busdiv); in do_state_action()
1663 if (ns->lines.wp) { in do_state_action()
1668 if (ns->regs.row >= ns->geom.pgnum - ns->geom.pgsec in do_state_action()
1669 || (ns->regs.row & ~(ns->geom.secsz - 1))) { in do_state_action()
1670 NS_ERR("do_state_action: wrong sector address (%#x)\n", ns->regs.row); in do_state_action()
1674 ns->regs.row = (ns->regs.row << in do_state_action()
1675 8 * (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) | ns->regs.column; in do_state_action()
1676 ns->regs.column = 0; in do_state_action()
1678 erase_block_no = ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift); in do_state_action()
1681 ns->regs.row, NS_RAW_OFFSET(ns)); in do_state_action()
1684 erase_sector(ns); in do_state_action()
1703 if (ns->lines.wp) { in do_state_action()
1708 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in do_state_action()
1709 if (num != ns->regs.count) { in do_state_action()
1711 ns->regs.count, num); in do_state_action()
1715 if (prog_page(ns, num) == -1) in do_state_action()
1718 page_no = ns->regs.row; in do_state_action()
1721 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off); in do_state_action()
1722 NS_LOG("programm page %d\n", ns->regs.row); in do_state_action()
1725 NS_UDELAY(output_cycle * ns->geom.pgsz / 1000 / busdiv); in do_state_action()
1736 ns->regs.off = 0; in do_state_action()
1740 if (!(ns->options & OPT_PAGE512_8BIT)) { in do_state_action()
1745 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz/2); in do_state_action()
1746 ns->regs.off = ns->geom.pgsz/2; in do_state_action()
1750 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz); in do_state_action()
1751 ns->regs.off = ns->geom.pgsz; in do_state_action()
1764 static void switch_state(struct nandsim *ns) in switch_state() argument
1766 if (ns->op) { in switch_state()
1772 ns->stateidx += 1; in switch_state()
1773 ns->state = ns->nxstate; in switch_state()
1774 ns->nxstate = ns->op[ns->stateidx + 1]; in switch_state()
1778 get_state_name(ns->state), get_state_name(ns->nxstate)); in switch_state()
1781 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in switch_state()
1782 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in switch_state()
1796 ns->state = get_state_by_command(ns->regs.command); in switch_state()
1800 if (find_operation(ns, 0) != 0) in switch_state()
1803 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in switch_state()
1804 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in switch_state()
1810 if ((ns->nxstate & STATE_ADDR_MASK) && ns->busw == 16) { in switch_state()
1812 ns->regs.column <<= 1; in switch_state()
1815 if (NS_STATE(ns->nxstate) == STATE_READY) { in switch_state()
1820 u_char status = NS_STATUS_OK(ns); in switch_state()
1823 if ((ns->state & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) in switch_state()
1824 && ns->regs.count != ns->regs.num) { in switch_state()
1826 ns->regs.num - ns->regs.count); in switch_state()
1827 status = NS_STATUS_FAILED(ns); in switch_state()
1832 switch_to_ready_state(ns, status); in switch_state()
1835 } else if (ns->nxstate & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) { in switch_state()
1840 ns->state = ns->nxstate; in switch_state()
1841 ns->nxstate = ns->op[++ns->stateidx + 1]; in switch_state()
1842 ns->regs.num = ns->regs.count = 0; in switch_state()
1846 get_state_name(ns->state), get_state_name(ns->nxstate)); in switch_state()
1852 switch (NS_STATE(ns->state)) { in switch_state()
1855 ns->regs.num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in switch_state()
1859 ns->regs.num = ns->geom.idbytes; in switch_state()
1863 ns->regs.count = ns->regs.num = 0; in switch_state()
1870 } else if (ns->nxstate & STATE_ADDR_MASK) { in switch_state()
1876 ns->regs.count = 0; in switch_state()
1878 switch (NS_STATE(ns->nxstate)) { in switch_state()
1880 ns->regs.num = ns->geom.pgaddrbytes; in switch_state()
1884 ns->regs.num = ns->geom.secaddrbytes; in switch_state()
1888 ns->regs.num = 1; in switch_state()
1893 ns->regs.num = ns->geom.pgaddrbytes - ns->geom.secaddrbytes; in switch_state()
1904 ns->regs.num = 0; in switch_state()
1905 ns->regs.count = 0; in switch_state()
1911 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_read_byte() local
1915 if (!ns->lines.ce) { in ns_nand_read_byte()
1919 if (ns->lines.ale || ns->lines.cle) { in ns_nand_read_byte()
1923 if (!(ns->state & STATE_DATAOUT_MASK)) { in ns_nand_read_byte()
1925 "return %#x\n", get_state_name(ns->state), (uint)outb); in ns_nand_read_byte()
1930 if (NS_STATE(ns->state) == STATE_DATAOUT_STATUS) { in ns_nand_read_byte()
1931 NS_DBG("read_byte: return %#x status\n", ns->regs.status); in ns_nand_read_byte()
1932 return ns->regs.status; in ns_nand_read_byte()
1936 if (ns->regs.count == ns->regs.num) { in ns_nand_read_byte()
1941 switch (NS_STATE(ns->state)) { in ns_nand_read_byte()
1943 if (ns->busw == 8) { in ns_nand_read_byte()
1944 outb = ns->buf.byte[ns->regs.count]; in ns_nand_read_byte()
1945 ns->regs.count += 1; in ns_nand_read_byte()
1947 outb = (u_char)cpu_to_le16(ns->buf.word[ns->regs.count >> 1]); in ns_nand_read_byte()
1948 ns->regs.count += 2; in ns_nand_read_byte()
1952 NS_DBG("read_byte: read ID byte %d, total = %d\n", ns->regs.count, ns->regs.num); in ns_nand_read_byte()
1953 outb = ns->ids[ns->regs.count]; in ns_nand_read_byte()
1954 ns->regs.count += 1; in ns_nand_read_byte()
1960 if (ns->regs.count == ns->regs.num) { in ns_nand_read_byte()
1963 if (NS_STATE(ns->nxstate) == STATE_READY) in ns_nand_read_byte()
1964 switch_state(ns); in ns_nand_read_byte()
1972 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_write_byte() local
1975 if (!ns->lines.ce) { in ns_nand_write_byte()
1979 if (ns->lines.ale && ns->lines.cle) { in ns_nand_write_byte()
1984 if (ns->lines.cle == 1) { in ns_nand_write_byte()
1991 switch_to_ready_state(ns, NS_STATUS_OK(ns)); in ns_nand_write_byte()
2001 if (NS_STATE(ns->state) == STATE_DATAOUT_STATUS in ns_nand_write_byte()
2002 || NS_STATE(ns->state) == STATE_DATAOUT) { in ns_nand_write_byte()
2003 int row = ns->regs.row; in ns_nand_write_byte()
2005 switch_state(ns); in ns_nand_write_byte()
2007 ns->regs.row = row; in ns_nand_write_byte()
2011 if (NS_STATE(ns->nxstate) != STATE_UNKNOWN && !(ns->nxstate & STATE_CMD_MASK)) { in ns_nand_write_byte()
2013 if (!(ns->regs.command == NAND_CMD_READID && in ns_nand_write_byte()
2014 NS_STATE(ns->state) == STATE_DATAOUT_ID && ns->regs.count == 2)) { in ns_nand_write_byte()
2021 "ignore previous states\n", (uint)byte, get_state_name(ns->nxstate)); in ns_nand_write_byte()
2023 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2028 ns->regs.command = byte; in ns_nand_write_byte()
2029 switch_state(ns); in ns_nand_write_byte()
2031 } else if (ns->lines.ale == 1) { in ns_nand_write_byte()
2036 if (NS_STATE(ns->nxstate) == STATE_UNKNOWN) { in ns_nand_write_byte()
2040 if (find_operation(ns, 1) < 0) in ns_nand_write_byte()
2043 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in ns_nand_write_byte()
2044 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2048 ns->regs.count = 0; in ns_nand_write_byte()
2049 switch (NS_STATE(ns->nxstate)) { in ns_nand_write_byte()
2051 ns->regs.num = ns->geom.pgaddrbytes; in ns_nand_write_byte()
2054 ns->regs.num = ns->geom.secaddrbytes; in ns_nand_write_byte()
2057 ns->regs.num = 1; in ns_nand_write_byte()
2065 if (!(ns->nxstate & STATE_ADDR_MASK)) { in ns_nand_write_byte()
2067 "switch to STATE_READY\n", (uint)byte, get_state_name(ns->nxstate)); in ns_nand_write_byte()
2068 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2073 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2075 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2079 accept_addr_byte(ns, byte); in ns_nand_write_byte()
2081 ns->regs.count += 1; in ns_nand_write_byte()
2084 (uint)byte, ns->regs.count, ns->regs.num); in ns_nand_write_byte()
2086 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2087 NS_DBG("address (%#x, %#x) is accepted\n", ns->regs.row, ns->regs.column); in ns_nand_write_byte()
2088 switch_state(ns); in ns_nand_write_byte()
2097 if (!(ns->state & STATE_DATAIN_MASK)) { in ns_nand_write_byte()
2100 get_state_name(ns->state), get_state_name(STATE_READY)); in ns_nand_write_byte()
2101 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2106 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2108 ns->regs.num); in ns_nand_write_byte()
2112 if (ns->busw == 8) { in ns_nand_write_byte()
2113 ns->buf.byte[ns->regs.count] = byte; in ns_nand_write_byte()
2114 ns->regs.count += 1; in ns_nand_write_byte()
2116 ns->buf.word[ns->regs.count >> 1] = cpu_to_le16((uint16_t)byte); in ns_nand_write_byte()
2117 ns->regs.count += 2; in ns_nand_write_byte()
2126 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_hwcontrol() local
2128 ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; in ns_hwcontrol()
2129 ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; in ns_hwcontrol()
2130 ns->lines.ce = bitmask & NAND_NCE ? 1 : 0; in ns_hwcontrol()
2153 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_write_buf() local
2156 if (!(ns->state & STATE_DATAIN_MASK)) { in ns_nand_write_buf()
2158 "switch to STATE_READY\n", get_state_name(ns->state)); in ns_nand_write_buf()
2159 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_buf()
2164 if (ns->regs.count + len > ns->regs.num) { in ns_nand_write_buf()
2166 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_buf()
2170 memcpy(ns->buf.byte + ns->regs.count, buf, len); in ns_nand_write_buf()
2171 ns->regs.count += len; in ns_nand_write_buf()
2173 if (ns->regs.count == ns->regs.num) { in ns_nand_write_buf()
2174 NS_DBG("write_buf: %d bytes were written\n", ns->regs.count); in ns_nand_write_buf()
2180 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; in ns_nand_read_buf() local
2183 if (!ns->lines.ce) { in ns_nand_read_buf()
2187 if (ns->lines.ale || ns->lines.cle) { in ns_nand_read_buf()
2191 if (!(ns->state & STATE_DATAOUT_MASK)) { in ns_nand_read_buf()
2193 get_state_name(ns->state)); in ns_nand_read_buf()
2197 if (NS_STATE(ns->state) != STATE_DATAOUT) { in ns_nand_read_buf()
2207 if (ns->regs.count + len > ns->regs.num) { in ns_nand_read_buf()
2209 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_read_buf()
2213 memcpy(buf, ns->buf.byte + ns->regs.count, len); in ns_nand_read_buf()
2214 ns->regs.count += len; in ns_nand_read_buf()
2216 if (ns->regs.count == ns->regs.num) { in ns_nand_read_buf()
2217 if (NS_STATE(ns->nxstate) == STATE_READY) in ns_nand_read_buf()
2218 switch_state(ns); in ns_nand_read_buf()
2408 struct nandsim *ns = ((struct nand_chip *)nsmtd->priv)->priv; in ns_cleanup_module() local
2411 nandsim_debugfs_remove(ns); in ns_cleanup_module()
2412 free_nandsim(ns); /* Free nandsim private resources */ in ns_cleanup_module()
2414 for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) in ns_cleanup_module()
2415 kfree(ns->partitions[i].name); in ns_cleanup_module()