Browse Source

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: Roberto Vargas <roberto.vargas@arm.com>
pull/1061/head
Roberto Vargas 7 years ago
parent
commit
9753cb5b51
  1. 6
      include/plat/arm/board/common/drivers/norflash.h
  2. 23
      plat/arm/board/common/drivers/norflash/norflash.c

6
include/plat/arm/board/common/drivers/norflash.h

@ -1,5 +1,5 @@
/*
* 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
*/
@ -37,8 +37,8 @@
/* Public API */
void nor_send_cmd(uintptr_t base_addr, unsigned long cmd);
int nor_word_program(uintptr_t base_addr, unsigned long data);
void nor_lock(uintptr_t base_addr);
void nor_unlock(uintptr_t base_addr);
int nor_lock(uintptr_t base_addr);
int nor_unlock(uintptr_t base_addr);
#endif /* __NORFLASH_H_ */

23
plat/arm/board/common/drivers/norflash/norflash.c

@ -25,6 +25,7 @@
* model
*/
#define DWS_WORD_PROGRAM_RETRIES 1000
#define DWS_WORD_LOCK_RETRIES 1000
/* Helper macro to detect end of command */
#define NOR_CMD_END (NOR_DWS | NOR_DWS << 16l)
@ -89,20 +90,38 @@ int nor_word_program(uintptr_t base_addr, unsigned long data)
/*
* 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);
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);
return ret;
}
/*
* 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);
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);
return ret;
}

Loading…
Cancel
Save