aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/nandsim.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/nand/nandsim.c')
-rw-r--r--drivers/mtd/nand/nandsim.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index a6a73aab1253..a5aa99f014ba 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -210,12 +210,12 @@ MODULE_PARM_DESC(bbt, "0 OOB, 1 BBT with marker in OOB, 2 BBT with marker in d
210#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */ 210#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */
211#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */ 211#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */
212#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */ 212#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */
213#define STATE_CMD_PAGEPROG 0x00000004 /* start page programm */ 213#define STATE_CMD_PAGEPROG 0x00000004 /* start page program */
214#define STATE_CMD_READOOB 0x00000005 /* read OOB area */ 214#define STATE_CMD_READOOB 0x00000005 /* read OOB area */
215#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */ 215#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */
216#define STATE_CMD_STATUS 0x00000007 /* read status */ 216#define STATE_CMD_STATUS 0x00000007 /* read status */
217#define STATE_CMD_STATUS_M 0x00000008 /* read multi-plane status (isn't implemented) */ 217#define STATE_CMD_STATUS_M 0x00000008 /* read multi-plane status (isn't implemented) */
218#define STATE_CMD_SEQIN 0x00000009 /* sequential data imput */ 218#define STATE_CMD_SEQIN 0x00000009 /* sequential data input */
219#define STATE_CMD_READID 0x0000000A /* read ID */ 219#define STATE_CMD_READID 0x0000000A /* read ID */
220#define STATE_CMD_ERASE2 0x0000000B /* sector erase second command */ 220#define STATE_CMD_ERASE2 0x0000000B /* sector erase second command */
221#define STATE_CMD_RESET 0x0000000C /* reset */ 221#define STATE_CMD_RESET 0x0000000C /* reset */
@@ -230,7 +230,7 @@ MODULE_PARM_DESC(bbt, "0 OOB, 1 BBT with marker in OOB, 2 BBT with marker in d
230#define STATE_ADDR_ZERO 0x00000040 /* one byte zero address was accepted */ 230#define STATE_ADDR_ZERO 0x00000040 /* one byte zero address was accepted */
231#define STATE_ADDR_MASK 0x00000070 /* address states mask */ 231#define STATE_ADDR_MASK 0x00000070 /* address states mask */
232 232
233/* Durind data input/output the simulator is in these states */ 233/* During data input/output the simulator is in these states */
234#define STATE_DATAIN 0x00000100 /* waiting for data input */ 234#define STATE_DATAIN 0x00000100 /* waiting for data input */
235#define STATE_DATAIN_MASK 0x00000100 /* data input states mask */ 235#define STATE_DATAIN_MASK 0x00000100 /* data input states mask */
236 236
@@ -248,7 +248,7 @@ MODULE_PARM_DESC(bbt, "0 OOB, 1 BBT with marker in OOB, 2 BBT with marker in d
248 248
249/* Simulator's actions bit masks */ 249/* Simulator's actions bit masks */
250#define ACTION_CPY 0x00100000 /* copy page/OOB to the internal buffer */ 250#define ACTION_CPY 0x00100000 /* copy page/OOB to the internal buffer */
251#define ACTION_PRGPAGE 0x00200000 /* programm the internal buffer to flash */ 251#define ACTION_PRGPAGE 0x00200000 /* program the internal buffer to flash */
252#define ACTION_SECERASE 0x00300000 /* erase sector */ 252#define ACTION_SECERASE 0x00300000 /* erase sector */
253#define ACTION_ZEROOFF 0x00400000 /* don't add any offset to address */ 253#define ACTION_ZEROOFF 0x00400000 /* don't add any offset to address */
254#define ACTION_HALFOFF 0x00500000 /* add to address half of page */ 254#define ACTION_HALFOFF 0x00500000 /* add to address half of page */
@@ -263,18 +263,18 @@ MODULE_PARM_DESC(bbt, "0 OOB, 1 BBT with marker in OOB, 2 BBT with marker in d
263#define OPT_PAGE512 0x00000002 /* 512-byte page chips */ 263#define OPT_PAGE512 0x00000002 /* 512-byte page chips */
264#define OPT_PAGE2048 0x00000008 /* 2048-byte page chips */ 264#define OPT_PAGE2048 0x00000008 /* 2048-byte page chips */
265#define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */ 265#define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */
266#define OPT_AUTOINCR 0x00000020 /* page number auto inctimentation is possible */ 266#define OPT_AUTOINCR 0x00000020 /* page number auto incrementation is possible */
267#define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ 267#define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */
268#define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */ 268#define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */
269#define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */ 269#define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */
270#define OPT_SMALLPAGE (OPT_PAGE256 | OPT_PAGE512) /* 256 and 512-byte page chips */ 270#define OPT_SMALLPAGE (OPT_PAGE256 | OPT_PAGE512) /* 256 and 512-byte page chips */
271 271
272/* Remove action bits ftom state */ 272/* Remove action bits from state */
273#define NS_STATE(x) ((x) & ~ACTION_MASK) 273#define NS_STATE(x) ((x) & ~ACTION_MASK)
274 274
275/* 275/*
276 * Maximum previous states which need to be saved. Currently saving is 276 * Maximum previous states which need to be saved. Currently saving is
277 * only needed for page programm operation with preceeded read command 277 * only needed for page program operation with preceded read command
278 * (which is only valid for 512-byte pages). 278 * (which is only valid for 512-byte pages).
279 */ 279 */
280#define NS_MAX_PREVSTATES 1 280#define NS_MAX_PREVSTATES 1
@@ -380,16 +380,16 @@ static struct nandsim_operations {
380 /* Read OOB */ 380 /* Read OOB */
381 {OPT_SMALLPAGE, {STATE_CMD_READOOB | ACTION_OOBOFF, STATE_ADDR_PAGE | ACTION_CPY, 381 {OPT_SMALLPAGE, {STATE_CMD_READOOB | ACTION_OOBOFF, STATE_ADDR_PAGE | ACTION_CPY,
382 STATE_DATAOUT, STATE_READY}}, 382 STATE_DATAOUT, STATE_READY}},
383 /* Programm page starting from the beginning */ 383 /* Program page starting from the beginning */
384 {OPT_ANY, {STATE_CMD_SEQIN, STATE_ADDR_PAGE, STATE_DATAIN, 384 {OPT_ANY, {STATE_CMD_SEQIN, STATE_ADDR_PAGE, STATE_DATAIN,
385 STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}}, 385 STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}},
386 /* Programm page starting from the beginning */ 386 /* Program page starting from the beginning */
387 {OPT_SMALLPAGE, {STATE_CMD_READ0, STATE_CMD_SEQIN | ACTION_ZEROOFF, STATE_ADDR_PAGE, 387 {OPT_SMALLPAGE, {STATE_CMD_READ0, STATE_CMD_SEQIN | ACTION_ZEROOFF, STATE_ADDR_PAGE,
388 STATE_DATAIN, STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}}, 388 STATE_DATAIN, STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}},
389 /* Programm page starting from the second half */ 389 /* Program page starting from the second half */
390 {OPT_PAGE512, {STATE_CMD_READ1, STATE_CMD_SEQIN | ACTION_HALFOFF, STATE_ADDR_PAGE, 390 {OPT_PAGE512, {STATE_CMD_READ1, STATE_CMD_SEQIN | ACTION_HALFOFF, STATE_ADDR_PAGE,
391 STATE_DATAIN, STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}}, 391 STATE_DATAIN, STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}},
392 /* Programm OOB */ 392 /* Program OOB */
393 {OPT_SMALLPAGE, {STATE_CMD_READOOB, STATE_CMD_SEQIN | ACTION_OOBOFF, STATE_ADDR_PAGE, 393 {OPT_SMALLPAGE, {STATE_CMD_READOOB, STATE_CMD_SEQIN | ACTION_OOBOFF, STATE_ADDR_PAGE,
394 STATE_DATAIN, STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}}, 394 STATE_DATAIN, STATE_CMD_PAGEPROG | ACTION_PRGPAGE, STATE_READY}},
395 /* Erase sector */ 395 /* Erase sector */
@@ -470,7 +470,7 @@ static int alloc_device(struct nandsim *ns)
470 err = -EINVAL; 470 err = -EINVAL;
471 goto err_close; 471 goto err_close;
472 } 472 }
473 ns->pages_written = vmalloc(ns->geom.pgnum); 473 ns->pages_written = vzalloc(ns->geom.pgnum);
474 if (!ns->pages_written) { 474 if (!ns->pages_written) {
475 NS_ERR("alloc_device: unable to allocate pages written array\n"); 475 NS_ERR("alloc_device: unable to allocate pages written array\n");
476 err = -ENOMEM; 476 err = -ENOMEM;
@@ -483,7 +483,6 @@ static int alloc_device(struct nandsim *ns)
483 goto err_free; 483 goto err_free;
484 } 484 }
485 ns->cfile = cfile; 485 ns->cfile = cfile;
486 memset(ns->pages_written, 0, ns->geom.pgnum);
487 return 0; 486 return 0;
488 } 487 }
489 488
@@ -1171,9 +1170,9 @@ static inline void switch_to_ready_state(struct nandsim *ns, u_char status)
1171 * of supported operations. 1170 * of supported operations.
1172 * 1171 *
1173 * Operation can be unknown because of the following. 1172 * Operation can be unknown because of the following.
1174 * 1. New command was accepted and this is the firs call to find the 1173 * 1. New command was accepted and this is the first call to find the
1175 * correspondent states chain. In this case ns->npstates = 0; 1174 * correspondent states chain. In this case ns->npstates = 0;
1176 * 2. There is several operations which begin with the same command(s) 1175 * 2. There are several operations which begin with the same command(s)
1177 * (for example program from the second half and read from the 1176 * (for example program from the second half and read from the
1178 * second half operations both begin with the READ1 command). In this 1177 * second half operations both begin with the READ1 command). In this
1179 * case the ns->pstates[] array contains previous states. 1178 * case the ns->pstates[] array contains previous states.
@@ -1186,7 +1185,7 @@ static inline void switch_to_ready_state(struct nandsim *ns, u_char status)
1186 * ns->ops, ns->state, ns->nxstate are initialized, ns->npstate is 1185 * ns->ops, ns->state, ns->nxstate are initialized, ns->npstate is
1187 * zeroed). 1186 * zeroed).
1188 * 1187 *
1189 * If there are several maches, the current state is pushed to the 1188 * If there are several matches, the current state is pushed to the
1190 * ns->pstates. 1189 * ns->pstates.
1191 * 1190 *
1192 * The operation can be unknown only while commands are input to the chip. 1191 * The operation can be unknown only while commands are input to the chip.
@@ -1195,10 +1194,10 @@ static inline void switch_to_ready_state(struct nandsim *ns, u_char status)
1195 * operation is searched using the following pattern: 1194 * operation is searched using the following pattern:
1196 * ns->pstates[0], ... ns->pstates[ns->npstates], <address input> 1195 * ns->pstates[0], ... ns->pstates[ns->npstates], <address input>
1197 * 1196 *
1198 * It is supposed that this pattern must either match one operation on 1197 * It is supposed that this pattern must either match one operation or
1199 * none. There can't be ambiguity in that case. 1198 * none. There can't be ambiguity in that case.
1200 * 1199 *
1201 * If no matches found, the functions does the following: 1200 * If no matches found, the function does the following:
1202 * 1. if there are saved states present, try to ignore them and search 1201 * 1. if there are saved states present, try to ignore them and search
1203 * again only using the last command. If nothing was found, switch 1202 * again only using the last command. If nothing was found, switch
1204 * to the STATE_READY state. 1203 * to the STATE_READY state.
@@ -1668,7 +1667,7 @@ static int do_state_action(struct nandsim *ns, uint32_t action)
1668 1667
1669 case ACTION_PRGPAGE: 1668 case ACTION_PRGPAGE:
1670 /* 1669 /*
1671 * Programm page - move internal buffer data to the page. 1670 * Program page - move internal buffer data to the page.
1672 */ 1671 */
1673 1672
1674 if (ns->lines.wp) { 1673 if (ns->lines.wp) {
@@ -1933,7 +1932,7 @@ static u_char ns_nand_read_byte(struct mtd_info *mtd)
1933 NS_DBG("read_byte: all bytes were read\n"); 1932 NS_DBG("read_byte: all bytes were read\n");
1934 1933
1935 /* 1934 /*
1936 * The OPT_AUTOINCR allows to read next conseqitive pages without 1935 * The OPT_AUTOINCR allows to read next consecutive pages without
1937 * new read operation cycle. 1936 * new read operation cycle.
1938 */ 1937 */
1939 if ((ns->options & OPT_AUTOINCR) && NS_STATE(ns->state) == STATE_DATAOUT) { 1938 if ((ns->options & OPT_AUTOINCR) && NS_STATE(ns->state) == STATE_DATAOUT) {