mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>,
	Patrice Vilchez <patrice.vilchez@atmel.com>
Subject: [PATCH 05/12] cfi_flash: synchronize command offsets with Linux CFI driver
Date: Fri, 26 Nov 2010 20:52:34 +0100	[thread overview]
Message-ID: <1290801161-2417-5-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20101126194353.GH26540@game.jcrosoft.org>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/nor/cfi_flash.h     |    7 +++----
 drivers/nor/cfi_flash_amd.c |   32 +++++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/drivers/nor/cfi_flash.h b/drivers/nor/cfi_flash.h
index 9a299db..4094b02 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 dffd6f0..c64377b 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,
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-11-26 19:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-26 19:43 [PATCH 0/12] cfi_flash: improvment Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 01/12] cfi_flash: move intel real protect flash support to cfi_flash_intel.c Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 02/12] cfi_flash: add Atmel real protect flash support Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 03/12] cfi_flash: move flash_read_uchar from inline to noinline Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 04/12] cfi_flash: use amd and standard reset flash command at probing Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2010-11-26 19:52 ` [PATCH 06/12] cfi_flash: update manufacturer id flash support Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 07/12] cfi_flash: Introduce read and write accessors Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 08/12] cfi_flash: Read whole QRY structure in one go Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 09/12] cfi_flash: do not reset flash when probe fails Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 10/12] cfi_flash: move reset command assigment to specific chipset init function Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 11/12] cfi_flash: introduce flash cmdset fixup Jean-Christophe PLAGNIOL-VILLARD
2010-11-26 19:52 ` [PATCH 12/12] cfi_flash_amd: Add manufacturer-specific fixups Jean-Christophe PLAGNIOL-VILLARD
2010-11-29 20:53 ` [PATCH 0/12] cfi_flash: improvment Sascha Hauer
2010-11-30 13:44   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-02 17:52   ` Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1290801161-2417-5-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    --cc=nicolas.ferre@atmel.com \
    --cc=patrice.vilchez@atmel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox