From 9753cb5b51794dac43fc9c4eb474207ebf369b59 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Wed, 26 Jul 2017 14:37:56 +0100 Subject: [PATCH] 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 --- .../plat/arm/board/common/drivers/norflash.h | 6 ++--- .../board/common/drivers/norflash/norflash.c | 23 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/plat/arm/board/common/drivers/norflash.h b/include/plat/arm/board/common/drivers/norflash.h index e74635ecc..4b66e4251 100644 --- a/include/plat/arm/board/common/drivers/norflash.h +++ b/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_ */ diff --git a/plat/arm/board/common/drivers/norflash/norflash.c b/plat/arm/board/common/drivers/norflash/norflash.c index 053696eed..18dad7b65 100644 --- a/plat/arm/board/common/drivers/norflash/norflash.c +++ b/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; }