summaryrefslogtreecommitdiffstats
path: root/drivers/nor/cfi_flash_amd.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-11-27 01:01:41 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-12-03 01:53:13 +0800
commit6bc05afea58bd1b8e98e8ad01755f5b644786552 (patch)
tree9191b44412ece24ea8909ca098f3ae3b2f1c81f4 /drivers/nor/cfi_flash_amd.c
parent8b41ca208e108ba49267ceb1b2ff880022f7c1bb (diff)
downloadbarebox-6bc05afea58bd1b8e98e8ad01755f5b644786552.tar.gz
barebox-6bc05afea58bd1b8e98e8ad01755f5b644786552.tar.xz
cfi_flash: Introduce read and write accessors
Introduce flash_read{8,16,32,64) and flash_write{8,16,32,64} and use them to access the flash memory. This makes it clearer when the flash is actually being accessed; merely dereferencing a volatile pointer looks just like any other kind of access. based on U-Boot Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'drivers/nor/cfi_flash_amd.c')
-rw-r--r--drivers/nor/cfi_flash_amd.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/drivers/nor/cfi_flash_amd.c b/drivers/nor/cfi_flash_amd.c
index 54e764db59..738389cce5 100644
--- a/drivers/nor/cfi_flash_amd.c
+++ b/drivers/nor/cfi_flash_amd.c
@@ -59,21 +59,21 @@ static void amd_read_jedec_ids (struct flash_info *info)
static int flash_toggle (struct flash_info *info, flash_sect_t sect, uint offset, uchar cmd)
{
- cfiptr_t cptr;
+ void *addr;
cfiword_t cword;
int retval;
- cptr.cp = flash_make_addr (info, sect, offset);
+ addr = flash_make_addr (info, sect, offset);
flash_make_cmd (info, cmd, &cword);
if (bankwidth_is_1(info)) {
- retval = ((cptr.cp[0] & cword.c) != (cptr.cp[0] & cword.c));
+ retval = flash_read8(addr) != flash_read8(addr);
} else if (bankwidth_is_2(info)) {
- retval = ((cptr.wp[0] & cword.w) != (cptr.wp[0] & cword.w));
+ retval = flash_read16(addr) != flash_read16(addr);
} else if (bankwidth_is_4(info)) {
- retval = ((cptr.lp[0] & cword.l) != (cptr.lp[0] & cword.l));
+ retval = flash_read32(addr) != flash_read32(addr);
} else if (bankwidth_is_8(info)) {
- retval = ((cptr.llp[0] & cword.ll) !=
- (cptr.llp[0] & cword.ll));
+ retval = ( (flash_read32( addr ) != flash_read32( addr )) ||
+ (flash_read32(addr+4) != flash_read32(addr+4)) );
} else
retval = 0;
@@ -112,12 +112,10 @@ static int amd_flash_write_cfibuffer (struct flash_info *info, ulong dest, const
flash_sect_t sector;
int cnt;
int retcode;
- volatile cfiptr_t src;
- volatile cfiptr_t dst;
+ void *src = (void*)cp;
+ void *dst = (void *)dest;
cfiword_t cword;
- src.cp = (uchar *)cp;
- dst.cp = (uchar *) dest;
sector = find_sector (info, dest);
flash_unlock_seq(info);
@@ -127,19 +125,31 @@ static int amd_flash_write_cfibuffer (struct flash_info *info, ulong dest, const
if (bankwidth_is_1(info)) {
cnt = len;
flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
- while (cnt-- > 0) *dst.cp++ = *src.cp++;
+ while (cnt-- > 0) {
+ flash_write8(flash_read8(src), dst);
+ src += 1, dst += 1;
+ }
} else if (bankwidth_is_2(info)) {
cnt = len >> 1;
flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
- while (cnt-- > 0) *dst.wp++ = *src.wp++;
+ while (cnt-- > 0) {
+ flash_write16(flash_read16(src), dst);
+ src += 2, dst += 2;
+ }
} else if (bankwidth_is_4(info)) {
cnt = len >> 2;
flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
- while (cnt-- > 0) *dst.lp++ = *src.lp++;
+ while (cnt-- > 0) {
+ flash_write32(flash_read32(src), dst);
+ src += 4, dst += 4;
+ }
} else if (bankwidth_is_8(info)) {
cnt = len >> 3;
flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
- while (cnt-- > 0) *dst.llp++ = *src.llp++;
+ while (cnt-- > 0) {
+ flash_write64(flash_read64(src), dst);
+ src += 8, dst += 8;
+ }
}
flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);