<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>[PATCH] (Resubmit) Added support to flash_real_protect for Atmelflash devices (tested with AT49BV6416)</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Some of the flash memories produced by ATMEL start in read-only mode. We<BR>
need to unprotect it.<BR>
This patch allows the AT49BV6416 to work with cfi_flash memories. Tested<BR>
in the at91rm9200ek board.<BR>
<BR>
<BR>
Signed-off-by: Rafael Campos Las Heras <rafael.campos@hanscan.com><BR>
---<BR>
drivers/mtd/cfi_flash.c | 40 ++++++++++++++++++++++++++++++++++------<BR>
1 files changed, 34 insertions(+), 6 deletions(-)<BR>
<BR>
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c<BR>
index 4340b1b..8d12eb8 100644<BR>
--- a/drivers/mtd/cfi_flash.c<BR>
+++ b/drivers/mtd/cfi_flash.c<BR>
@@ -103,6 +103,10 @@<BR>
#define AMD_STATUS_TOGGLE 0x40<BR>
#define AMD_STATUS_ERROR 0x20<BR>
<BR>
+#define ATM_CMD_UNLOCK_SECT 0x70<BR>
+#define ATM_CMD_SOFTLOCK_START 0x80<BR>
+#define ATM_CMD_LOCK_SECT 0x40<BR>
+<BR>
#define FLASH_OFFSET_MANUFACTURER_ID 0x00<BR>
#define FLASH_OFFSET_DEVICE_ID 0x01<BR>
#define FLASH_OFFSET_DEVICE_ID2 0x0E<BR>
@@ -1348,12 +1352,36 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)<BR>
{<BR>
int retcode = 0;<BR>
<BR>
- flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);<BR>
- flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);<BR>
- if (prot)<BR>
- flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);<BR>
- else<BR>
- flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);<BR>
+ switch (info->vendor) {<BR>
+ case CFI_CMDSET_INTEL_PROG_REGIONS:<BR>
+ case CFI_CMDSET_INTEL_STANDARD:<BR>
+ flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);<BR>
+ flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);<BR>
+ if (prot)<BR>
+ flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);<BR>
+ else<BR>
+ flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);<BR>
+ break;<BR>
+ case CFI_CMDSET_AMD_EXTENDED:<BR>
+ case CFI_CMDSET_AMD_STANDARD:<BR>
+#ifdef CONFIG_FLASH_CFI_LEGACY<BR>
+ case CFI_CMDSET_AMD_LEGACY:<BR>
+#endif<BR>
+ /* U-Boot only checks the first byte */<BR>
+ if (info->manufacturer_id == (uchar)ATM_MANUFACT ) {<BR>
+ if (prot) {<BR>
+ flash_unlock_seq(info, 0);<BR>
+ flash_write_cmd (info, 0, info->addr_unlock1, ATM_CMD_SOFTLOCK_START);<BR>
+ flash_unlock_seq(info, 0);<BR>
+ flash_write_cmd (info, sector, 0, ATM_CMD_LOCK_SECT);<BR>
+ } else {<BR>
+ flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_UNLOCK_START);<BR>
+ if (info->device_id == ATM_ID_BV6416)<BR>
+ flash_write_cmd (info, sector, 0, ATM_CMD_UNLOCK_SECT);<BR>
+ }<BR>
+ }<BR>
+ break;<BR>
+ }<BR>
<BR>
if ((retcode =<BR>
flash_full_status_check (info, sector, info->erase_blk_tout,<BR>
--<BR>
1.5.6.2<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>