Commit 9753cb5b authored by Roberto Vargas's avatar Roberto Vargas
Browse files

norflash: Wait for WSM bit in lock/unlock



lock/unlock operation must wait until WSM bit
is set. Since we do not allow to loop forever then these functions
must return an error if WSM bit isn't enabled after a number of tries.

Change-Id: I21c9e292b514b28786ff4a225128bcd8c1bfa999
Signed-off-by: default avatarRoberto Vargas <roberto.vargas@arm.com>
parent f4953e76
/* /*
* Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
/* Public API */ /* Public API */
void nor_send_cmd(uintptr_t base_addr, unsigned long cmd); void nor_send_cmd(uintptr_t base_addr, unsigned long cmd);
int nor_word_program(uintptr_t base_addr, unsigned long data); int nor_word_program(uintptr_t base_addr, unsigned long data);
void nor_lock(uintptr_t base_addr); int nor_lock(uintptr_t base_addr);
void nor_unlock(uintptr_t base_addr); int nor_unlock(uintptr_t base_addr);
#endif /* __NORFLASH_H_ */ #endif /* __NORFLASH_H_ */
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
* model * model
*/ */
#define DWS_WORD_PROGRAM_RETRIES 1000 #define DWS_WORD_PROGRAM_RETRIES 1000
#define DWS_WORD_LOCK_RETRIES 1000
/* Helper macro to detect end of command */ /* Helper macro to detect end of command */
#define NOR_CMD_END (NOR_DWS | NOR_DWS << 16l) #define NOR_CMD_END (NOR_DWS | NOR_DWS << 16l)
...@@ -89,20 +90,38 @@ int nor_word_program(uintptr_t base_addr, unsigned long data) ...@@ -89,20 +90,38 @@ int nor_word_program(uintptr_t base_addr, unsigned long data)
/* /*
* Lock a full 256 block * Lock a full 256 block
* Return values:
* 0 = success
* otherwise it returns a negative value
*/ */
void nor_lock(uintptr_t base_addr) int nor_lock(uintptr_t base_addr)
{ {
int ret;
nor_send_cmd(base_addr, NOR_CMD_LOCK_UNLOCK); nor_send_cmd(base_addr, NOR_CMD_LOCK_UNLOCK);
mmio_write_32(base_addr, NOR_2X16(NOR_LOCK_BLOCK)); mmio_write_32(base_addr, NOR_2X16(NOR_LOCK_BLOCK));
ret = nor_poll_dws(base_addr, DWS_WORD_LOCK_RETRIES);
nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY); nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY);
return ret;
} }
/* /*
* unlock a full 256 block * unlock a full 256 block
* Return values:
* 0 = success
* otherwise it returns a negative value
*/ */
void nor_unlock(uintptr_t base_addr) int nor_unlock(uintptr_t base_addr)
{ {
int ret;
nor_send_cmd(base_addr, NOR_CMD_LOCK_UNLOCK); nor_send_cmd(base_addr, NOR_CMD_LOCK_UNLOCK);
mmio_write_32(base_addr, NOR_2X16(NOR_UNLOCK_BLOCK)); mmio_write_32(base_addr, NOR_2X16(NOR_UNLOCK_BLOCK));
ret = nor_poll_dws(base_addr, DWS_WORD_LOCK_RETRIES);
nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY); nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY);
return ret;
} }
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