summaryrefslogtreecommitdiffstats
path: root/ichspi.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-06-13 12:04:03 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-06-13 12:04:03 +0000
commit38a059d6ef1ebb7145a04825fec0ebef1d8a66a7 (patch)
tree66c9108eda2f0f7129f2ba55b9cb757414d9466a /ichspi.c
parent8b2f46b878a952a0ea0869624636cb4d6f5fa8c1 (diff)
downloadast2050-flashrom-38a059d6ef1ebb7145a04825fec0ebef1d8a66a7.zip
ast2050-flashrom-38a059d6ef1ebb7145a04825fec0ebef1d8a66a7.tar.gz
Every SPI host controller implemented its own way to read flash chips
This was partly due to a design problem in the abstraction layer. There should be exactly two different functions for reading SPI chips: - memory mapped reads - SPI command reads. Each of them should be contained in a separate function, optionally taking parameters where needed. This patch solves the problems mentioned above, shortens the code and makes the code logic a lot more obvious. Since open-coding the min() function leads to errors, include it in this patch as well. Corresponding to flashrom svn r589. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'ichspi.c')
-rw-r--r--ichspi.c47
1 files changed, 2 insertions, 45 deletions
diff --git a/ichspi.c b/ichspi.c
index 4f83908..e3fb740 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -148,8 +148,6 @@ static int generate_opcodes(OPCODES * op);
static int program_opcodes(OPCODES * op);
static int run_opcode(OPCODE op, uint32_t offset,
uint8_t datalength, uint8_t * data);
-static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf,
- int offset, int maxdata);
static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes,
int offset, int maxdata);
@@ -614,38 +612,6 @@ static int run_opcode(OPCODE op, uint32_t offset,
return -1;
}
-static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, int offset,
- int maxdata)
-{
- int page_size = flash->page_size;
- uint32_t remaining = flash->page_size;
- int a;
-
- printf_debug("ich_spi_read_page: offset=%d, number=%d, buf=%p\n",
- offset, page_size, buf);
-
- for (a = 0; a < page_size; a += maxdata) {
- if (remaining < maxdata) {
-
- if (spi_nbyte_read(offset + (page_size - remaining),
- &buf[page_size - remaining], remaining)) {
- printf_debug("Error reading");
- return 1;
- }
- remaining = 0;
- } else {
- if (spi_nbyte_read(offset + (page_size - remaining),
- &buf[page_size - remaining], maxdata)) {
- printf_debug("Error reading");
- return 1;
- }
- remaining -= maxdata;
- }
- }
-
- return 0;
-}
-
static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes,
int offset, int maxdata)
{
@@ -683,21 +649,12 @@ static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes,
int ich_spi_read(struct flashchip *flash, uint8_t * buf)
{
- int i, rc = 0;
- int total_size = flash->total_size * 1024;
- int page_size = flash->page_size;
int maxdata = 64;
- if (spi_controller == SPI_CONTROLLER_VIA) {
+ if (spi_controller == SPI_CONTROLLER_VIA)
maxdata = 16;
- }
- for (i = 0; (i < total_size / page_size) && (rc == 0); i++) {
- rc = ich_spi_read_page(flash, (void *)(buf + i * page_size),
- i * page_size, maxdata);
- }
-
- return rc;
+ return spi_read_chunked(flash, buf, maxdata);
}
int ich_spi_write_256(struct flashchip *flash, uint8_t * buf)
OpenPOWER on IntegriCloud