summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-11-27 00:28:39 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-12-03 01:53:12 +0800
commitce35b3c09ad8a6f6c52627e969ea7c0a394300ef (patch)
tree452a37b9081418c0574454ba3be95cc7e27058e5
parent64e70cd0508e36e76ae69f1a9eedacd6be7e18be (diff)
downloadbarebox-ce35b3c09ad8a6f6c52627e969ea7c0a394300ef.tar.gz
barebox-ce35b3c09ad8a6f6c52627e969ea7c0a394300ef.tar.xz
cfi_flash: synchronize command offsets with Linux CFI driver
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
-rw-r--r--drivers/nor/cfi_flash.h7
-rw-r--r--drivers/nor/cfi_flash_amd.c32
2 files changed, 28 insertions, 11 deletions
diff --git a/drivers/nor/cfi_flash.h b/drivers/nor/cfi_flash.h
index 9a299db1ee..4094b02f21 100644
--- a/drivers/nor/cfi_flash.h
+++ b/drivers/nor/cfi_flash.h
@@ -59,6 +59,8 @@ struct flash_info {
ushort ext_addr; /* extended query table address */
ushort cfi_version; /* cfi version */
ushort cfi_offset; /* offset for cfi query */
+ ulong addr_unlock1; /* unlock address 1 for AMD flash roms */
+ ulong addr_unlock2; /* unlock address 2 for AMD flash roms */
struct cfi_cmd_set *cfi_cmd_set;
struct cdev cdev;
#ifdef CONFIG_PARTITION_NEED_MTD
@@ -117,10 +119,6 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;
#define AMD_STATUS_TOGGLE 0x40
#define AMD_STATUS_ERROR 0x20
-#define AMD_ADDR_ERASE_START ((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
-#define AMD_ADDR_START ((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
-#define AMD_ADDR_ACK ((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
-
#define ATM_CMD_UNLOCK_SECT 0x70
#define ATM_CMD_SOFTLOCK_START 0x80
#define ATM_CMD_LOCK_SECT 0x40
@@ -187,6 +185,7 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;
#define FLASH_CFI_X8 0x00
#define FLASH_CFI_X16 0x01
#define FLASH_CFI_X8X16 0x02
+#define FLASH_CFI_X16X32 0x05
/* convert between bit value and numeric value */
#define CFI_FLASH_SHIFT_WIDTH 3
diff --git a/drivers/nor/cfi_flash_amd.c b/drivers/nor/cfi_flash_amd.c
index dffd6f0208..c64377b550 100644
--- a/drivers/nor/cfi_flash_amd.c
+++ b/drivers/nor/cfi_flash_amd.c
@@ -4,8 +4,8 @@
static void flash_unlock_seq (struct flash_info *info)
{
- flash_write_cmd (info, 0, AMD_ADDR_START, AMD_CMD_UNLOCK_START);
- flash_write_cmd (info, 0, AMD_ADDR_ACK, AMD_CMD_UNLOCK_ACK);
+ flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_UNLOCK_START);
+ flash_write_cmd (info, 0, info->addr_unlock2, AMD_CMD_UNLOCK_ACK);
}
/*
@@ -20,9 +20,27 @@ static void amd_read_jedec_ids (struct flash_info *info)
info->device_id = 0;
info->device_id2 = 0;
+ /* calculate command offsets as in the Linux driver */
+ info->addr_unlock1 = 0x555;
+ info->addr_unlock2 = 0x2AA;
+
+ /*
+ * modify the unlock address if we are in compatibility mode
+ */
+ if ( /* x8/x16 in x8 mode */
+ ((info->chipwidth == FLASH_CFI_BY8) &&
+ (info->interface == FLASH_CFI_X8X16)) ||
+ /* x16/x32 in x16 mode */
+ ((info->chipwidth == FLASH_CFI_BY16) &&
+ (info->interface == FLASH_CFI_X16X32)))
+ {
+ info->addr_unlock1 = 0xaaa;
+ info->addr_unlock2 = 0x555;
+ }
+
flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
flash_unlock_seq(info);
- flash_write_cmd(info, 0, AMD_ADDR_START, FLASH_CMD_READ_ID);
+ flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID);
udelay(1000); /* some flash are slow to respond */
info->manufacturer_id = flash_read_uchar (info,
FLASH_OFFSET_MANUFACTURER_ID);
@@ -74,7 +92,7 @@ static int amd_flash_is_busy (struct flash_info *info, flash_sect_t sect)
static int amd_flash_erase_one (struct flash_info *info, long sect)
{
flash_unlock_seq(info);
- flash_write_cmd (info, 0, AMD_ADDR_ERASE_START, AMD_CMD_ERASE_START);
+ flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_ERASE_START);
flash_unlock_seq(info);
flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
@@ -84,7 +102,7 @@ static int amd_flash_erase_one (struct flash_info *info, long sect)
static void amd_flash_prepare_write(struct flash_info *info)
{
flash_unlock_seq(info);
- flash_write_cmd (info, 0, AMD_ADDR_START, AMD_CMD_WRITE);
+ flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_WRITE);
}
#ifdef CONFIG_CFI_BUFFER_WRITE
@@ -140,12 +158,12 @@ static int amd_flash_real_protect (struct flash_info *info, long sector, int pro
if (prot) {
flash_unlock_seq (info);
- flash_write_cmd (info, 0, AMD_ADDR_START,
+ flash_write_cmd (info, 0, info->addr_unlock1,
ATM_CMD_SOFTLOCK_START);
flash_unlock_seq (info);
flash_write_cmd (info, sector, 0, ATM_CMD_LOCK_SECT);
} else {
- flash_write_cmd (info, 0, AMD_ADDR_START,
+ 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,