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
549 static int __init alloc_device(struct nandsim *ns) in alloc_device() argument
568 ns->pages_written = in alloc_device()
570 BITS_TO_LONGS(ns->geom.pgnum))); in alloc_device()
571 if (!ns->pages_written) { in alloc_device()
576 ns->file_buf = kmalloc(ns->geom.pgszoob, GFP_KERNEL); in alloc_device()
577 if (!ns->file_buf) { in alloc_device()
582 ns->cfile = cfile; in alloc_device()
586 ns->pages = vmalloc(array_size(sizeof(union ns_mem), ns->geom.pgnum)); in alloc_device()
587 if (!ns->pages) { in alloc_device()
591 for (i = 0; i < ns->geom.pgnum; i++) { in alloc_device()
592 ns->pages[i].byte = NULL; in alloc_device()
594 ns->nand_pages_slab = kmem_cache_create("nandsim", in alloc_device()
595 ns->geom.pgszoob, 0, 0, NULL); in alloc_device()
596 if (!ns->nand_pages_slab) { in alloc_device()
604 vfree(ns->pages_written); in alloc_device()
613 static void free_device(struct nandsim *ns) in free_device() argument
617 if (ns->cfile) { in free_device()
618 kfree(ns->file_buf); in free_device()
619 vfree(ns->pages_written); in free_device()
620 filp_close(ns->cfile, NULL); in free_device()
624 if (ns->pages) { in free_device()
625 for (i = 0; i < ns->geom.pgnum; i++) { in free_device()
626 if (ns->pages[i].byte) in free_device()
627 kmem_cache_free(ns->nand_pages_slab, in free_device()
628 ns->pages[i].byte); in free_device()
630 kmem_cache_destroy(ns->nand_pages_slab); in free_device()
631 vfree(ns->pages); in free_device()
648 struct nandsim *ns = nand_get_controller_data(chip); in init_nandsim() local
653 if (NS_IS_INITIALIZED(ns)) { in init_nandsim()
662 ns->busw = chip->options & NAND_BUSWIDTH_16 ? 16 : 8; in init_nandsim()
663 ns->geom.totsz = mtd->size; in init_nandsim()
664 ns->geom.pgsz = mtd->writesize; in init_nandsim()
665 ns->geom.oobsz = mtd->oobsize; in init_nandsim()
666 ns->geom.secsz = mtd->erasesize; in init_nandsim()
667 ns->geom.pgszoob = ns->geom.pgsz + ns->geom.oobsz; in init_nandsim()
668 ns->geom.pgnum = div_u64(ns->geom.totsz, ns->geom.pgsz); in init_nandsim()
669 ns->geom.totszoob = ns->geom.totsz + (uint64_t)ns->geom.pgnum * ns->geom.oobsz; in init_nandsim()
670 ns->geom.secshift = ffs(ns->geom.secsz) - 1; in init_nandsim()
671 ns->geom.pgshift = chip->page_shift; in init_nandsim()
672 ns->geom.pgsec = ns->geom.secsz / ns->geom.pgsz; in init_nandsim()
673 ns->geom.secszoob = ns->geom.secsz + ns->geom.oobsz * ns->geom.pgsec; in init_nandsim()
674 ns->options = 0; in init_nandsim()
676 if (ns->geom.pgsz == 512) { in init_nandsim()
677 ns->options |= OPT_PAGE512; in init_nandsim()
678 if (ns->busw == 8) in init_nandsim()
679 ns->options |= OPT_PAGE512_8BIT; in init_nandsim()
680 } else if (ns->geom.pgsz == 2048) { in init_nandsim()
681 ns->options |= OPT_PAGE2048; in init_nandsim()
682 } else if (ns->geom.pgsz == 4096) { in init_nandsim()
683 ns->options |= OPT_PAGE4096; in init_nandsim()
685 NS_ERR("init_nandsim: unknown page size %u\n", ns->geom.pgsz); in init_nandsim()
689 if (ns->options & OPT_SMALLPAGE) { in init_nandsim()
690 if (ns->geom.totsz <= (32 << 20)) { in init_nandsim()
691 ns->geom.pgaddrbytes = 3; in init_nandsim()
692 ns->geom.secaddrbytes = 2; in init_nandsim()
694 ns->geom.pgaddrbytes = 4; in init_nandsim()
695 ns->geom.secaddrbytes = 3; in init_nandsim()
698 if (ns->geom.totsz <= (128 << 20)) { in init_nandsim()
699 ns->geom.pgaddrbytes = 4; in init_nandsim()
700 ns->geom.secaddrbytes = 2; in init_nandsim()
702 ns->geom.pgaddrbytes = 5; in init_nandsim()
703 ns->geom.secaddrbytes = 3; in init_nandsim()
708 if (parts_num > ARRAY_SIZE(ns->partitions)) { in init_nandsim()
712 remains = ns->geom.totsz; in init_nandsim()
715 uint64_t part_sz = (uint64_t)parts[i] * ns->geom.secsz; in init_nandsim()
721 ns->partitions[i].name = get_partition_name(i); in init_nandsim()
722 if (!ns->partitions[i].name) { in init_nandsim()
726 ns->partitions[i].offset = next_offset; in init_nandsim()
727 ns->partitions[i].size = part_sz; in init_nandsim()
728 next_offset += ns->partitions[i].size; in init_nandsim()
729 remains -= ns->partitions[i].size; in init_nandsim()
731 ns->nbparts = parts_num; in init_nandsim()
733 if (parts_num + 1 > ARRAY_SIZE(ns->partitions)) { in init_nandsim()
737 ns->partitions[i].name = get_partition_name(i); in init_nandsim()
738 if (!ns->partitions[i].name) { in init_nandsim()
742 ns->partitions[i].offset = next_offset; in init_nandsim()
743 ns->partitions[i].size = remains; in init_nandsim()
744 ns->nbparts += 1; in init_nandsim()
747 if (ns->busw == 16) in init_nandsim()
751 (unsigned long long)ns->geom.totsz >> 20); in init_nandsim()
752 printk("page size: %u bytes\n", ns->geom.pgsz); in init_nandsim()
753 printk("OOB area size: %u bytes\n", ns->geom.oobsz); in init_nandsim()
754 printk("sector size: %u KiB\n", ns->geom.secsz >> 10); in init_nandsim()
755 printk("pages number: %u\n", ns->geom.pgnum); in init_nandsim()
756 printk("pages per sector: %u\n", ns->geom.pgsec); in init_nandsim()
757 printk("bus width: %u\n", ns->busw); in init_nandsim()
758 printk("bits in sector size: %u\n", ns->geom.secshift); in init_nandsim()
759 printk("bits in page size: %u\n", ns->geom.pgshift); in init_nandsim()
760 printk("bits in OOB size: %u\n", ffs(ns->geom.oobsz) - 1); in init_nandsim()
762 (unsigned long long)ns->geom.totszoob >> 10); in init_nandsim()
763 printk("page address bytes: %u\n", ns->geom.pgaddrbytes); in init_nandsim()
764 printk("sector address bytes: %u\n", ns->geom.secaddrbytes); in init_nandsim()
765 printk("options: %#x\n", ns->options); in init_nandsim()
767 if ((ret = alloc_device(ns)) != 0) in init_nandsim()
771 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL); in init_nandsim()
772 if (!ns->buf.byte) { in init_nandsim()
774 ns->geom.pgszoob); in init_nandsim()
777 memset(ns->buf.byte, 0xFF, ns->geom.pgszoob); in init_nandsim()
785 static void free_nandsim(struct nandsim *ns) in free_nandsim() argument
787 kfree(ns->buf.byte); in free_nandsim()
788 free_device(ns); in free_nandsim()
793 static int parse_badblocks(struct nandsim *ns, struct mtd_info *mtd) in parse_badblocks() argument
810 offset = (loff_t)erase_block_no * ns->geom.secsz; in parse_badblocks()
1154 static inline void accept_addr_byte(struct nandsim *ns, u_char bt) in accept_addr_byte() argument
1158 if (ns->regs.count < (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) in accept_addr_byte()
1159 ns->regs.column |= (byte << 8 * ns->regs.count); in accept_addr_byte()
1161 ns->regs.row |= (byte << 8 * (ns->regs.count - in accept_addr_byte()
1162 ns->geom.pgaddrbytes + in accept_addr_byte()
1163 ns->geom.secaddrbytes)); in accept_addr_byte()
1172 static inline void switch_to_ready_state(struct nandsim *ns, u_char status) in switch_to_ready_state() argument
1176 ns->state = STATE_READY; in switch_to_ready_state()
1177 ns->nxstate = STATE_UNKNOWN; in switch_to_ready_state()
1178 ns->op = NULL; in switch_to_ready_state()
1179 ns->npstates = 0; in switch_to_ready_state()
1180 ns->stateidx = 0; in switch_to_ready_state()
1181 ns->regs.num = 0; in switch_to_ready_state()
1182 ns->regs.count = 0; in switch_to_ready_state()
1183 ns->regs.off = 0; in switch_to_ready_state()
1184 ns->regs.row = 0; in switch_to_ready_state()
1185 ns->regs.column = 0; in switch_to_ready_state()
1186 ns->regs.status = status; in switch_to_ready_state()
1231 static int find_operation(struct nandsim *ns, uint32_t flag) in find_operation() argument
1240 if (!(ns->options & ops[i].reqopts)) in find_operation()
1245 if (!(ops[i].states[ns->npstates] & STATE_ADDR_MASK)) in find_operation()
1248 if (NS_STATE(ns->state) != NS_STATE(ops[i].states[ns->npstates])) in find_operation()
1252 for (j = 0; j < ns->npstates; j++) in find_operation()
1253 if (NS_STATE(ops[i].states[j]) != NS_STATE(ns->pstates[j]) in find_operation()
1254 && (ns->options & ops[idx].reqopts)) { in find_operation()
1267 ns->op = &ops[idx].states[0]; in find_operation()
1276 ns->stateidx = ns->npstates - 1; in find_operation()
1278 ns->stateidx = ns->npstates; in find_operation()
1280 ns->npstates = 0; in find_operation()
1281 ns->state = ns->op[ns->stateidx]; in find_operation()
1282 ns->nxstate = ns->op[ns->stateidx + 1]; in find_operation()
1284 idx, get_state_name(ns->state), get_state_name(ns->nxstate)); in find_operation()
1290 if (ns->npstates != 0) { in find_operation()
1292 get_state_name(ns->state)); in find_operation()
1293 ns->npstates = 0; in find_operation()
1294 return find_operation(ns, 0); in find_operation()
1298 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in find_operation()
1310 ns->pstates[ns->npstates++] = ns->state; in find_operation()
1315 static void put_pages(struct nandsim *ns) in put_pages() argument
1319 for (i = 0; i < ns->held_cnt; i++) in put_pages()
1320 put_page(ns->held_pages[i]); in put_pages()
1324 static int get_pages(struct nandsim *ns, struct file *file, size_t count, loff_t pos) in get_pages() argument
1334 ns->held_cnt = 0; in get_pages()
1344 put_pages(ns); in get_pages()
1349 ns->held_pages[ns->held_cnt++] = page; in get_pages()
1354 static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) in read_file() argument
1360 err = get_pages(ns, file, count, pos); in read_file()
1366 put_pages(ns); in read_file()
1370 static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t po… in write_file() argument
1376 err = get_pages(ns, file, count, pos); in write_file()
1382 put_pages(ns); in write_file()
1389 static inline union ns_mem *NS_GET_PAGE(struct nandsim *ns) in NS_GET_PAGE() argument
1391 return &(ns->pages[ns->regs.row]); in NS_GET_PAGE()
1397 static inline u_char *NS_PAGE_BYTE_OFF(struct nandsim *ns) in NS_PAGE_BYTE_OFF() argument
1399 return NS_GET_PAGE(ns)->byte + ns->regs.column + ns->regs.off; in NS_PAGE_BYTE_OFF()
1402 static int do_read_error(struct nandsim *ns, int num) in do_read_error() argument
1404 unsigned int page_no = ns->regs.row; in do_read_error()
1407 prandom_bytes(ns->buf.byte, num); in do_read_error()
1414 static void do_bit_flips(struct nandsim *ns, int num) in do_bit_flips() argument
1422 ns->buf.byte[pos / 8] ^= (1 << (pos % 8)); in do_bit_flips()
1425 pos, ns->regs.row, ns->regs.column + ns->regs.off, in do_bit_flips()
1434 static void read_page(struct nandsim *ns, int num) in read_page() argument
1438 if (ns->cfile) { in read_page()
1439 if (!test_bit(ns->regs.row, ns->pages_written)) { in read_page()
1440 NS_DBG("read_page: page %d not written\n", ns->regs.row); in read_page()
1441 memset(ns->buf.byte, 0xFF, num); in read_page()
1447 ns->regs.row, ns->regs.column + ns->regs.off); in read_page()
1448 if (do_read_error(ns, num)) in read_page()
1450 pos = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; in read_page()
1451 tx = read_file(ns, ns->cfile, ns->buf.byte, num, pos); in read_page()
1453 NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); in read_page()
1456 do_bit_flips(ns, num); in read_page()
1461 mypage = NS_GET_PAGE(ns); in read_page()
1463 NS_DBG("read_page: page %d not allocated\n", ns->regs.row); in read_page()
1464 memset(ns->buf.byte, 0xFF, num); in read_page()
1467 ns->regs.row, ns->regs.column + ns->regs.off); in read_page()
1468 if (do_read_error(ns, num)) in read_page()
1470 memcpy(ns->buf.byte, NS_PAGE_BYTE_OFF(ns), num); in read_page()
1471 do_bit_flips(ns, num); in read_page()
1478 static void erase_sector(struct nandsim *ns) in erase_sector() argument
1483 if (ns->cfile) { in erase_sector()
1484 for (i = 0; i < ns->geom.pgsec; i++) in erase_sector()
1485 if (__test_and_clear_bit(ns->regs.row + i, in erase_sector()
1486 ns->pages_written)) { in erase_sector()
1487 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row + i); in erase_sector()
1492 mypage = NS_GET_PAGE(ns); in erase_sector()
1493 for (i = 0; i < ns->geom.pgsec; i++) { in erase_sector()
1495 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row+i); in erase_sector()
1496 kmem_cache_free(ns->nand_pages_slab, mypage->byte); in erase_sector()
1506 static int prog_page(struct nandsim *ns, int num) in prog_page() argument
1512 if (ns->cfile) { in prog_page()
1517 NS_DBG("prog_page: writing page %d\n", ns->regs.row); in prog_page()
1518 pg_off = ns->file_buf + ns->regs.column + ns->regs.off; in prog_page()
1519 off = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; in prog_page()
1520 if (!test_bit(ns->regs.row, ns->pages_written)) { in prog_page()
1522 memset(ns->file_buf, 0xff, ns->geom.pgszoob); in prog_page()
1525 tx = read_file(ns, ns->cfile, pg_off, num, off); in prog_page()
1527 NS_ERR("prog_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1532 pg_off[i] &= ns->buf.byte[i]; in prog_page()
1534 loff_t pos = (loff_t)ns->regs.row * ns->geom.pgszoob; in prog_page()
1535 tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, pos); in prog_page()
1536 if (tx != ns->geom.pgszoob) { in prog_page()
1537 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1540 __set_bit(ns->regs.row, ns->pages_written); in prog_page()
1542 tx = write_file(ns, ns->cfile, pg_off, num, off); in prog_page()
1544 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); in prog_page()
1551 mypage = NS_GET_PAGE(ns); in prog_page()
1553 NS_DBG("prog_page: allocating page %d\n", ns->regs.row); in prog_page()
1560 mypage->byte = kmem_cache_alloc(ns->nand_pages_slab, GFP_NOFS); in prog_page()
1562 NS_ERR("prog_page: error allocating memory for page %d\n", ns->regs.row); in prog_page()
1565 memset(mypage->byte, 0xFF, ns->geom.pgszoob); in prog_page()
1568 pg_off = NS_PAGE_BYTE_OFF(ns); in prog_page()
1570 pg_off[i] &= ns->buf.byte[i]; in prog_page()
1580 static int do_state_action(struct nandsim *ns, uint32_t action) in do_state_action() argument
1583 int busdiv = ns->busw == 8 ? 1 : 2; in do_state_action()
1589 if (action != ACTION_SECERASE && ns->regs.row >= ns->geom.pgnum) { in do_state_action()
1590 NS_WARN("do_state_action: wrong page number (%#x)\n", ns->regs.row); in do_state_action()
1602 if (ns->regs.column >= (ns->geom.pgszoob - ns->regs.off)) { in do_state_action()
1606 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in do_state_action()
1607 read_page(ns, num); in do_state_action()
1610 num, NS_RAW_OFFSET(ns) + ns->regs.off); in do_state_action()
1612 if (ns->regs.off == 0) in do_state_action()
1613 NS_LOG("read page %d\n", ns->regs.row); in do_state_action()
1614 else if (ns->regs.off < ns->geom.pgsz) in do_state_action()
1615 NS_LOG("read page %d (second half)\n", ns->regs.row); in do_state_action()
1617 NS_LOG("read OOB of page %d\n", ns->regs.row); in do_state_action()
1620 NS_UDELAY(input_cycle * ns->geom.pgsz / 1000 / busdiv); in do_state_action()
1629 if (ns->lines.wp) { in do_state_action()
1634 if (ns->regs.row >= ns->geom.pgnum - ns->geom.pgsec in do_state_action()
1635 || (ns->regs.row & ~(ns->geom.secsz - 1))) { in do_state_action()
1636 NS_ERR("do_state_action: wrong sector address (%#x)\n", ns->regs.row); in do_state_action()
1640 ns->regs.row = (ns->regs.row << in do_state_action()
1641 8 * (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) | ns->regs.column; in do_state_action()
1642 ns->regs.column = 0; in do_state_action()
1644 erase_block_no = ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift); in do_state_action()
1647 ns->regs.row, NS_RAW_OFFSET(ns)); in do_state_action()
1650 erase_sector(ns); in do_state_action()
1669 if (ns->lines.wp) { in do_state_action()
1674 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in do_state_action()
1675 if (num != ns->regs.count) { in do_state_action()
1677 ns->regs.count, num); in do_state_action()
1681 if (prog_page(ns, num) == -1) in do_state_action()
1684 page_no = ns->regs.row; in do_state_action()
1687 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off); in do_state_action()
1688 NS_LOG("programm page %d\n", ns->regs.row); in do_state_action()
1691 NS_UDELAY(output_cycle * ns->geom.pgsz / 1000 / busdiv); in do_state_action()
1702 ns->regs.off = 0; in do_state_action()
1706 if (!(ns->options & OPT_PAGE512_8BIT)) { in do_state_action()
1711 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz/2); in do_state_action()
1712 ns->regs.off = ns->geom.pgsz/2; in do_state_action()
1716 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz); in do_state_action()
1717 ns->regs.off = ns->geom.pgsz; in do_state_action()
1730 static void switch_state(struct nandsim *ns) in switch_state() argument
1732 if (ns->op) { in switch_state()
1738 ns->stateidx += 1; in switch_state()
1739 ns->state = ns->nxstate; in switch_state()
1740 ns->nxstate = ns->op[ns->stateidx + 1]; in switch_state()
1744 get_state_name(ns->state), get_state_name(ns->nxstate)); in switch_state()
1747 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in switch_state()
1748 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in switch_state()
1762 ns->state = get_state_by_command(ns->regs.command); in switch_state()
1766 if (find_operation(ns, 0) != 0) in switch_state()
1769 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in switch_state()
1770 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in switch_state()
1776 if ((ns->nxstate & STATE_ADDR_MASK) && ns->busw == 16) { in switch_state()
1778 ns->regs.column <<= 1; in switch_state()
1781 if (NS_STATE(ns->nxstate) == STATE_READY) { in switch_state()
1786 u_char status = NS_STATUS_OK(ns); in switch_state()
1789 if ((ns->state & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) in switch_state()
1790 && ns->regs.count != ns->regs.num) { in switch_state()
1792 ns->regs.num - ns->regs.count); in switch_state()
1793 status = NS_STATUS_FAILED(ns); in switch_state()
1798 switch_to_ready_state(ns, status); in switch_state()
1801 } else if (ns->nxstate & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) { in switch_state()
1806 ns->state = ns->nxstate; in switch_state()
1807 ns->nxstate = ns->op[++ns->stateidx + 1]; in switch_state()
1808 ns->regs.num = ns->regs.count = 0; in switch_state()
1812 get_state_name(ns->state), get_state_name(ns->nxstate)); in switch_state()
1818 switch (NS_STATE(ns->state)) { in switch_state()
1821 ns->regs.num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; in switch_state()
1825 ns->regs.num = ns->geom.idbytes; in switch_state()
1829 ns->regs.count = ns->regs.num = 0; in switch_state()
1836 } else if (ns->nxstate & STATE_ADDR_MASK) { in switch_state()
1842 ns->regs.count = 0; in switch_state()
1844 switch (NS_STATE(ns->nxstate)) { in switch_state()
1846 ns->regs.num = ns->geom.pgaddrbytes; in switch_state()
1850 ns->regs.num = ns->geom.secaddrbytes; in switch_state()
1854 ns->regs.num = 1; in switch_state()
1859 ns->regs.num = ns->geom.pgaddrbytes - ns->geom.secaddrbytes; in switch_state()
1870 ns->regs.num = 0; in switch_state()
1871 ns->regs.count = 0; in switch_state()
1878 struct nandsim *ns = nand_get_controller_data(chip); in ns_nand_read_byte() local
1882 if (!ns->lines.ce) { in ns_nand_read_byte()
1886 if (ns->lines.ale || ns->lines.cle) { in ns_nand_read_byte()
1890 if (!(ns->state & STATE_DATAOUT_MASK)) { in ns_nand_read_byte()
1892 "return %#x\n", get_state_name(ns->state), (uint)outb); in ns_nand_read_byte()
1897 if (NS_STATE(ns->state) == STATE_DATAOUT_STATUS) { in ns_nand_read_byte()
1898 NS_DBG("read_byte: return %#x status\n", ns->regs.status); in ns_nand_read_byte()
1899 return ns->regs.status; in ns_nand_read_byte()
1903 if (ns->regs.count == ns->regs.num) { in ns_nand_read_byte()
1908 switch (NS_STATE(ns->state)) { in ns_nand_read_byte()
1910 if (ns->busw == 8) { in ns_nand_read_byte()
1911 outb = ns->buf.byte[ns->regs.count]; in ns_nand_read_byte()
1912 ns->regs.count += 1; in ns_nand_read_byte()
1914 outb = (u_char)cpu_to_le16(ns->buf.word[ns->regs.count >> 1]); in ns_nand_read_byte()
1915 ns->regs.count += 2; in ns_nand_read_byte()
1919 NS_DBG("read_byte: read ID byte %d, total = %d\n", ns->regs.count, ns->regs.num); in ns_nand_read_byte()
1920 outb = ns->ids[ns->regs.count]; in ns_nand_read_byte()
1921 ns->regs.count += 1; in ns_nand_read_byte()
1927 if (ns->regs.count == ns->regs.num) { in ns_nand_read_byte()
1930 if (NS_STATE(ns->nxstate) == STATE_READY) in ns_nand_read_byte()
1931 switch_state(ns); in ns_nand_read_byte()
1940 struct nandsim *ns = nand_get_controller_data(chip); in ns_nand_write_byte() local
1943 if (!ns->lines.ce) { in ns_nand_write_byte()
1947 if (ns->lines.ale && ns->lines.cle) { in ns_nand_write_byte()
1952 if (ns->lines.cle == 1) { in ns_nand_write_byte()
1959 switch_to_ready_state(ns, NS_STATUS_OK(ns)); in ns_nand_write_byte()
1969 if (NS_STATE(ns->state) == STATE_DATAOUT_STATUS in ns_nand_write_byte()
1970 || NS_STATE(ns->state) == STATE_DATAOUT) { in ns_nand_write_byte()
1971 int row = ns->regs.row; in ns_nand_write_byte()
1973 switch_state(ns); in ns_nand_write_byte()
1975 ns->regs.row = row; in ns_nand_write_byte()
1979 if (NS_STATE(ns->nxstate) != STATE_UNKNOWN && !(ns->nxstate & STATE_CMD_MASK)) { in ns_nand_write_byte()
1981 if (!(ns->regs.command == NAND_CMD_READID && in ns_nand_write_byte()
1982 NS_STATE(ns->state) == STATE_DATAOUT_ID && ns->regs.count == 2)) { in ns_nand_write_byte()
1989 "ignore previous states\n", (uint)byte, get_state_name(ns->nxstate)); in ns_nand_write_byte()
1991 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
1996 ns->regs.command = byte; in ns_nand_write_byte()
1997 switch_state(ns); in ns_nand_write_byte()
1999 } else if (ns->lines.ale == 1) { in ns_nand_write_byte()
2004 if (NS_STATE(ns->nxstate) == STATE_UNKNOWN) { in ns_nand_write_byte()
2008 if (find_operation(ns, 1) < 0) in ns_nand_write_byte()
2011 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { in ns_nand_write_byte()
2012 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2016 ns->regs.count = 0; in ns_nand_write_byte()
2017 switch (NS_STATE(ns->nxstate)) { in ns_nand_write_byte()
2019 ns->regs.num = ns->geom.pgaddrbytes; in ns_nand_write_byte()
2022 ns->regs.num = ns->geom.secaddrbytes; in ns_nand_write_byte()
2025 ns->regs.num = 1; in ns_nand_write_byte()
2033 if (!(ns->nxstate & STATE_ADDR_MASK)) { in ns_nand_write_byte()
2035 "switch to STATE_READY\n", (uint)byte, get_state_name(ns->nxstate)); in ns_nand_write_byte()
2036 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2041 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2043 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_byte()
2047 accept_addr_byte(ns, byte); in ns_nand_write_byte()
2049 ns->regs.count += 1; in ns_nand_write_byte()
2052 (uint)byte, ns->regs.count, ns->regs.num); in ns_nand_write_byte()
2054 if (ns->regs.count == ns->regs.num) { in ns_nand_write_byte()
2055 NS_DBG("address (%#x, %#x) is accepted\n", ns->regs.row, ns->regs.column); in ns_nand_write_byte()
2056 switch_state(ns); in ns_nand_write_byte()
2065 if (!(ns->state & STATE_DATAIN_MASK)) { in ns_nand_write_byte()
2068 get_state_name(ns->state), get_state_name(STATE_READY)); 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 ns->regs.num); in ns_nand_write_byte()
2080 if (ns->busw == 8) { in ns_nand_write_byte()
2081 ns->buf.byte[ns->regs.count] = byte; in ns_nand_write_byte()
2082 ns->regs.count += 1; in ns_nand_write_byte()
2084 ns->buf.word[ns->regs.count >> 1] = cpu_to_le16((uint16_t)byte); in ns_nand_write_byte()
2085 ns->regs.count += 2; in ns_nand_write_byte()
2095 struct nandsim *ns = nand_get_controller_data(chip); in ns_hwcontrol() local
2097 ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; in ns_hwcontrol()
2098 ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; in ns_hwcontrol()
2099 ns->lines.ce = bitmask & NAND_NCE ? 1 : 0; in ns_hwcontrol()
2123 struct nandsim *ns = nand_get_controller_data(chip); in ns_nand_write_buf() local
2126 if (!(ns->state & STATE_DATAIN_MASK)) { in ns_nand_write_buf()
2128 "switch to STATE_READY\n", get_state_name(ns->state)); in ns_nand_write_buf()
2129 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_buf()
2134 if (ns->regs.count + len > ns->regs.num) { in ns_nand_write_buf()
2136 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_write_buf()
2140 memcpy(ns->buf.byte + ns->regs.count, buf, len); in ns_nand_write_buf()
2141 ns->regs.count += len; in ns_nand_write_buf()
2143 if (ns->regs.count == ns->regs.num) { in ns_nand_write_buf()
2144 NS_DBG("write_buf: %d bytes were written\n", ns->regs.count); in ns_nand_write_buf()
2151 struct nandsim *ns = nand_get_controller_data(chip); in ns_nand_read_buf() local
2154 if (!ns->lines.ce) { in ns_nand_read_buf()
2158 if (ns->lines.ale || ns->lines.cle) { in ns_nand_read_buf()
2162 if (!(ns->state & STATE_DATAOUT_MASK)) { in ns_nand_read_buf()
2164 get_state_name(ns->state)); in ns_nand_read_buf()
2168 if (NS_STATE(ns->state) != STATE_DATAOUT) { in ns_nand_read_buf()
2178 if (ns->regs.count + len > ns->regs.num) { in ns_nand_read_buf()
2180 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); in ns_nand_read_buf()
2184 memcpy(buf, ns->buf.byte + ns->regs.count, len); in ns_nand_read_buf()
2185 ns->regs.count += len; in ns_nand_read_buf()
2187 if (ns->regs.count == ns->regs.num) { in ns_nand_read_buf()
2188 if (NS_STATE(ns->nxstate) == STATE_READY) in ns_nand_read_buf()
2189 switch_state(ns); in ns_nand_read_buf()
2385 struct nandsim *ns = nand_get_controller_data(chip); in ns_cleanup_module() local
2388 free_nandsim(ns); /* Free nandsim private resources */ in ns_cleanup_module()
2390 for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) in ns_cleanup_module()
2391 kfree(ns->partitions[i].name); in ns_cleanup_module()