summaryrefslogtreecommitdiffstats
path: root/sst28sf040.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-03-05 19:24:22 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-03-05 19:24:22 +0000
commit61a8bd27fb5ff27db98e96b462957994e7cca946 (patch)
tree42326fb1bdeb491df1db567eacdec088bee46c7d /sst28sf040.c
parent0677dfffc67ad2d0e973f558be86e66f225b4ddc (diff)
downloadast2050-flashrom-61a8bd27fb5ff27db98e96b462957994e7cca946.zip
ast2050-flashrom-61a8bd27fb5ff27db98e96b462957994e7cca946.tar.gz
Use helper functions to access flash chips
Right now we perform direct pointer manipulation without any abstraction to read from and write to memory mapped flash chips. That makes it impossible to drive any flasher which does not mmap the whole chip. Using helper functions readb() and writeb() allows a driver for external flash programmers like Paraflasher to replace readb and writeb with calls to its own chip access routines. This patch has the additional advantage of removing lots of unnecessary casts to volatile uint8_t * and now-superfluous parentheses which caused poor readability. I used the semantic patcher Coccinelle to create this patch. The semantic patch follows: @@ expression a; typedef uint8_t; volatile uint8_t *b; @@ - *(b) = (a); + writeb(a, b); @@ volatile uint8_t *b; @@ - *(b) + readb(b) @@ type T; T b; @@ ( readb | writeb ) (..., - (T) - (b) + b ) In contrast to a sed script, the semantic patch performs type checking before converting anything. Tested-by: Joe Julian Corresponding to flashrom svn r418 and coreboot v2 svn r3971. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: FENG Yu Ning <fengyuning1984@gmail.com>
Diffstat (limited to 'sst28sf040.c')
-rw-r--r--sst28sf040.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/sst28sf040.c b/sst28sf040.c
index 89be9d8..ee8ee80 100644
--- a/sst28sf040.c
+++ b/sst28sf040.c
@@ -35,13 +35,13 @@ static __inline__ void protect_28sf040(volatile uint8_t *bios)
/* ask compiler not to optimize this */
volatile uint8_t tmp;
- tmp = *(volatile uint8_t *)(bios + 0x1823);
- tmp = *(volatile uint8_t *)(bios + 0x1820);
- tmp = *(volatile uint8_t *)(bios + 0x1822);
- tmp = *(volatile uint8_t *)(bios + 0x0418);
- tmp = *(volatile uint8_t *)(bios + 0x041B);
- tmp = *(volatile uint8_t *)(bios + 0x0419);
- tmp = *(volatile uint8_t *)(bios + 0x040A);
+ tmp = readb(bios + 0x1823);
+ tmp = readb(bios + 0x1820);
+ tmp = readb(bios + 0x1822);
+ tmp = readb(bios + 0x0418);
+ tmp = readb(bios + 0x041B);
+ tmp = readb(bios + 0x0419);
+ tmp = readb(bios + 0x040A);
}
static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
@@ -49,20 +49,20 @@ static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
/* ask compiler not to optimize this */
volatile uint8_t tmp;
- tmp = *(volatile uint8_t *)(bios + 0x1823);
- tmp = *(volatile uint8_t *)(bios + 0x1820);
- tmp = *(volatile uint8_t *)(bios + 0x1822);
- tmp = *(volatile uint8_t *)(bios + 0x0418);
- tmp = *(volatile uint8_t *)(bios + 0x041B);
- tmp = *(volatile uint8_t *)(bios + 0x0419);
- tmp = *(volatile uint8_t *)(bios + 0x041A);
+ tmp = readb(bios + 0x1823);
+ tmp = readb(bios + 0x1820);
+ tmp = readb(bios + 0x1822);
+ tmp = readb(bios + 0x0418);
+ tmp = readb(bios + 0x041B);
+ tmp = readb(bios + 0x0419);
+ tmp = readb(bios + 0x041A);
}
static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,
unsigned long address)
{
- *bios = AUTO_PG_ERASE1;
- *(bios + address) = AUTO_PG_ERASE2;
+ writeb(AUTO_PG_ERASE1, bios);
+ writeb(AUTO_PG_ERASE2, bios + address);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
@@ -85,8 +85,8 @@ static __inline__ int write_sector_28sf040(volatile uint8_t *bios,
continue;
}
/*issue AUTO PROGRAM command */
- *dst = AUTO_PGRM;
- *dst++ = *src++;
+ writeb(AUTO_PGRM, dst);
+ writeb(*src++, dst++);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
@@ -100,16 +100,16 @@ int probe_28sf040(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *bios = RESET;
+ writeb(RESET, bios);
myusec_delay(10);
- *bios = READ_ID;
+ writeb(READ_ID, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
+ id1 = readb(bios);
myusec_delay(10);
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id2 = readb(bios + 0x01);
- *bios = RESET;
+ writeb(RESET, bios);
myusec_delay(10);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
@@ -124,8 +124,8 @@ int erase_28sf040(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
unprotect_28sf040(bios);
- *bios = CHIP_ERASE;
- *bios = CHIP_ERASE;
+ writeb(CHIP_ERASE, bios);
+ writeb(CHIP_ERASE, bios);
protect_28sf040(bios);
myusec_delay(10);
OpenPOWER on IntegriCloud