]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
cfi-flash: Added support to flash_real_protect for Atmel flash devices
authorRafael Campos <rafael.campos@hanscan.com>
Thu, 31 Jul 2008 08:22:20 +0000 (10:22 +0200)
committerStefan Roese <sr@denx.de>
Wed, 6 Aug 2008 12:22:41 +0000 (14:22 +0200)
Some of the flash memories produced by ATMEL start in read-only mode.
We need to unprotect it. This patch allows the AT49BV6416 to work with
cfi_flash memories. Tested in the at91rm9200ek board.

Signed-off-by: Rafael Campos Las Heras <rafael.campos@hanscan.com>
Signed-off-by: Stefan Roese <sr@denx.de>
drivers/mtd/cfi_flash.c

index 12647ef98613ff818be19e53fd33e65eaf90c445..31ee75607d57ca17b979747ef54620747d215a10 100644 (file)
 #define AMD_STATUS_TOGGLE              0x40
 #define AMD_STATUS_ERROR               0x20
 
+#define ATM_CMD_UNLOCK_SECT            0x70
+#define ATM_CMD_SOFTLOCK_START         0x80
+#define ATM_CMD_LOCK_SECT              0x40
+
 #define FLASH_OFFSET_MANUFACTURER_ID   0x00
 #define FLASH_OFFSET_DEVICE_ID         0x01
 #define FLASH_OFFSET_DEVICE_ID2                0x0E
@@ -1351,12 +1355,45 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)
 {
        int retcode = 0;
 
-       flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
-       flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
-       if (prot)
-               flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);
-       else
-               flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
+       switch (info->vendor) {
+               case CFI_CMDSET_INTEL_PROG_REGIONS:
+               case CFI_CMDSET_INTEL_STANDARD:
+                       flash_write_cmd (info, sector, 0,
+                                        FLASH_CMD_CLEAR_STATUS);
+                       flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
+                       if (prot)
+                               flash_write_cmd (info, sector, 0,
+                                       FLASH_CMD_PROTECT_SET);
+                       else
+                               flash_write_cmd (info, sector, 0,
+                                       FLASH_CMD_PROTECT_CLEAR);
+                       break;
+               case CFI_CMDSET_AMD_EXTENDED:
+               case CFI_CMDSET_AMD_STANDARD:
+#ifdef CONFIG_FLASH_CFI_LEGACY
+               case CFI_CMDSET_AMD_LEGACY:
+#endif
+                       /* U-Boot only checks the first byte */
+                       if (info->manufacturer_id == (uchar)ATM_MANUFACT) {
+                               if (prot) {
+                                       flash_unlock_seq (info, 0);
+                                       flash_write_cmd (info, 0,
+                                                       info->addr_unlock1,
+                                                       ATM_CMD_SOFTLOCK_START);
+                                       flash_unlock_seq (info, 0);
+                                       flash_write_cmd (info, sector, 0,
+                                                       ATM_CMD_LOCK_SECT);
+                               } else {
+                                       flash_write_cmd (info, 0,
+                                                       info->addr_unlock1,
+                                                       AMD_CMD_UNLOCK_START);
+                                       if (info->device_id == ATM_ID_BV6416)
+                                               flash_write_cmd (info, sector,
+                                                       0, ATM_CMD_UNLOCK_SECT);
+                               }
+                       }
+                       break;
+       };
 
        if ((retcode =
             flash_full_status_check (info, sector, info->erase_blk_tout,