norflash: Clear status register before sending commands
authorRoberto Vargas <roberto.vargas@arm.com>
Wed, 26 Jul 2017 14:17:24 +0000 (15:17 +0100)
committerRoberto Vargas <roberto.vargas@arm.com>
Tue, 22 Aug 2017 08:41:59 +0000 (09:41 +0100)
The status register bits remain until explicitly cleared, which means
that a command can be incorrectly considered to have generated an error -
for example, after reset the status register contents may be unknown or
if a previous command had failed.

This patch clears the status register before beginning any command to
be sure that the status register only represents information about the
current operation.

Change-Id: I9e98110ee24179937215461c00b6543a3467b350
Signed-off-by: Roberto Vargas <roberto.vargas@arm.com>
plat/arm/board/common/drivers/norflash/norflash.c

index 18dad7b6548ffbb09843e1dc63faa71ad4202ef8..ee9eca7e1763d6c63fc4a1a998efddcb86a8a327 100644 (file)
@@ -68,6 +68,8 @@ int nor_word_program(uintptr_t base_addr, unsigned long data)
        uint32_t status;
        int ret;
 
+       nor_send_cmd(base_addr, NOR_CMD_CLEAR_STATUS_REG);
+
        /* Set the device in write word mode */
        nor_send_cmd(base_addr, NOR_CMD_WORD_PROGRAM);
        mmio_write_32(base_addr, data);
@@ -98,8 +100,10 @@ int nor_lock(uintptr_t base_addr)
 {
        int ret;
 
+       nor_send_cmd(base_addr, NOR_CMD_CLEAR_STATUS_REG);
+
        nor_send_cmd(base_addr, NOR_CMD_LOCK_UNLOCK);
-       mmio_write_32(base_addr, NOR_2X16(NOR_LOCK_BLOCK));
+       nor_send_cmd(base_addr, NOR_LOCK_BLOCK);
 
        ret = nor_poll_dws(base_addr, DWS_WORD_LOCK_RETRIES);
        nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY);
@@ -117,8 +121,10 @@ int nor_unlock(uintptr_t base_addr)
 {
        int ret;
 
+       nor_send_cmd(base_addr, NOR_CMD_CLEAR_STATUS_REG);
+
        nor_send_cmd(base_addr, NOR_CMD_LOCK_UNLOCK);
-       mmio_write_32(base_addr, NOR_2X16(NOR_UNLOCK_BLOCK));
+       nor_send_cmd(base_addr, NOR_UNLOCK_BLOCK);
 
        ret = nor_poll_dws(base_addr, DWS_WORD_LOCK_RETRIES);
        nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY);