Commit 784502ae authored by Roberto Vargas's avatar Roberto Vargas
Browse files

norflash: Add nor_erase() to NOR driver



NOR memory only supports setting bits to 1. To clear a bit, set to zero,
the NOR memory needs to be erased.

Change-Id: Ia82eb15a5af9a6d4fc7e5ea2b58e6db87226b351
Signed-off-by: default avatarRoberto Vargas <roberto.vargas@arm.com>
parent b4b09ca5
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define NOR_CMD_WORD_PROGRAM 0x40 #define NOR_CMD_WORD_PROGRAM 0x40
#define NOR_CMD_BLOCK_ERASE 0x20 #define NOR_CMD_BLOCK_ERASE 0x20
#define NOR_CMD_LOCK_UNLOCK 0x60 #define NOR_CMD_LOCK_UNLOCK 0x60
#define NOR_CMD_BLOCK_ERASE_ACK 0xD0
/* Second bus cycle */ /* Second bus cycle */
#define NOR_LOCK_BLOCK 0x01 #define NOR_LOCK_BLOCK 0x01
...@@ -39,6 +40,7 @@ void nor_send_cmd(uintptr_t base_addr, unsigned long cmd); ...@@ -39,6 +40,7 @@ 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);
int nor_lock(uintptr_t base_addr); int nor_lock(uintptr_t base_addr);
int nor_unlock(uintptr_t base_addr); int nor_unlock(uintptr_t base_addr);
int nor_erase(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_ERASE_RETRIES 3000000
#define DWS_WORD_LOCK_RETRIES 1000 #define DWS_WORD_LOCK_RETRIES 1000
/* Helper macro to detect end of command */ /* Helper macro to detect end of command */
...@@ -35,7 +36,7 @@ ...@@ -35,7 +36,7 @@
* 0 = WSM ready * 0 = WSM ready
* -EBUSY = WSM busy after the number of retries * -EBUSY = WSM busy after the number of retries
*/ */
static int nor_poll_dws(uintptr_t base_addr, unsigned int retries) static int nor_poll_dws(uintptr_t base_addr, unsigned long int retries)
{ {
unsigned long status; unsigned long status;
...@@ -90,6 +91,27 @@ int nor_word_program(uintptr_t base_addr, unsigned long data) ...@@ -90,6 +91,27 @@ int nor_word_program(uintptr_t base_addr, unsigned long data)
return ret; return ret;
} }
/*
* Erase a full 256K block
* Return values:
* 0 = success
* -EBUSY = WSM not ready
*/
int nor_erase(uintptr_t base_addr)
{
int ret;
nor_send_cmd(base_addr, NOR_CMD_CLEAR_STATUS_REG);
nor_send_cmd(base_addr, NOR_CMD_BLOCK_ERASE);
nor_send_cmd(base_addr, NOR_CMD_BLOCK_ERASE_ACK);
ret = nor_poll_dws(base_addr, DWS_WORD_ERASE_RETRIES);
nor_send_cmd(base_addr, NOR_CMD_READ_ARRAY);
return ret;
}
/* /*
* Lock a full 256 block * Lock a full 256 block
* Return values: * Return values:
......
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