Commit df467899 authored by Miquel Raynal's avatar Miquel Raynal Committed by Boris Brezillon

mtd: nand: fix interpretation of NAND_CMD_NONE in nand_command[_lp]()

Some drivers (like nand_hynix.c) call ->cmdfunc() with NAND_CMD_NONE
and a column address and expect the controller to only send address
cycles. Right now, the default ->cmdfunc() implementations provided by
the core do not filter out the command cycle in this case and forwards
the request to the controller driver through the ->cmd_ctrl() method.
The thing is, NAND controller drivers can get this wrong and send a
command cycle with a NAND_CMD_NONE opcode and since NAND_CMD_NONE is
-1, and the command field is usually casted to an u8, we end up sending
the 0xFF command which is actually a RESET operation.

Add conditions in nand_command[_lp]() functions to sending the initial
command cycle when command == NAND_CMD_NONE.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@free-electrons.com>
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
parent b13a9735
...@@ -710,6 +710,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, ...@@ -710,6 +710,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
chip->cmd_ctrl(mtd, readcmd, ctrl); chip->cmd_ctrl(mtd, readcmd, ctrl);
ctrl &= ~NAND_CTRL_CHANGE; ctrl &= ~NAND_CTRL_CHANGE;
} }
if (command != NAND_CMD_NONE)
chip->cmd_ctrl(mtd, command, ctrl); chip->cmd_ctrl(mtd, command, ctrl);
/* Address cycle, when necessary */ /* Address cycle, when necessary */
...@@ -738,6 +739,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, ...@@ -738,6 +739,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
*/ */
switch (command) { switch (command) {
case NAND_CMD_NONE:
case NAND_CMD_PAGEPROG: case NAND_CMD_PAGEPROG:
case NAND_CMD_ERASE1: case NAND_CMD_ERASE1:
case NAND_CMD_ERASE2: case NAND_CMD_ERASE2:
...@@ -831,7 +833,9 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, ...@@ -831,7 +833,9 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
} }
/* Command latch cycle */ /* Command latch cycle */
chip->cmd_ctrl(mtd, command, NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); if (command != NAND_CMD_NONE)
chip->cmd_ctrl(mtd, command,
NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
if (column != -1 || page_addr != -1) { if (column != -1 || page_addr != -1) {
int ctrl = NAND_CTRL_CHANGE | NAND_NCE | NAND_ALE; int ctrl = NAND_CTRL_CHANGE | NAND_NCE | NAND_ALE;
...@@ -866,6 +870,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, ...@@ -866,6 +870,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
*/ */
switch (command) { switch (command) {
case NAND_CMD_NONE:
case NAND_CMD_CACHEDPROG: case NAND_CMD_CACHEDPROG:
case NAND_CMD_PAGEPROG: case NAND_CMD_PAGEPROG:
case NAND_CMD_ERASE1: case NAND_CMD_ERASE1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment