summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2011-09-11 20:26:21 -0700
committerVadim Bendebury <vbendeb@chromium.org>2011-09-12 10:57:07 -0700
commite82ef9a5caec018af0a9bd2aea9870358b1f1313 (patch)
tree854c6ffd37b2908c371616fbe08d72cd7e044c54 /drivers
parent9f73d3dd20e1eac2e27d56992d94dc3d4bdbb883 (diff)
Allow smaller write units in SPI flash drivers.
There is a problem with x86 systems using Intel ICH chips as the SPI controller: whereas the SPI chips allow for 256 byte pages for write transactions, the controllers allow for only 64 bytes per transaction. This causes failures when the chip driver invokes the controller driver write() function passing a 256 byte page: only 64 bytes get written. This problem is not easy to fix in u-boot, this change suggests a scheme to allow the size override for certain SPI controllers. BUG=chromium-os:20105 TEST=manual . this change was tested combined with other modification, the ability to read and save the 16KB environment in a maconix SPI flash was demonstrated. Change-Id: Ic42f294da0e6abd554107d6189cabd7269370b96 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: http://gerrit.chromium.org/gerrit/7522 Reviewed-by: Stefan Reinauer <reinauer@google.com> Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/spi/macronix.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index ca0003ebc7..6f920d3da2 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -118,7 +118,6 @@ static int macronix_write(struct spi_flash *flash,
u32 offset, size_t len, const void *buf)
{
struct macronix_spi_flash *mcx = to_macronix_spi_flash(flash);
- unsigned long page_addr;
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -126,8 +125,7 @@ static int macronix_write(struct spi_flash *flash,
int ret;
u8 cmd[4];
- page_size = mcx->params->page_size;
- page_addr = offset / page_size;
+ page_size = min(mcx->params->page_size, CONTROLLER_PAGE_LIMIT);
byte_addr = offset % page_size;
ret = spi_claim_bus(flash->spi);
@@ -141,9 +139,9 @@ static int macronix_write(struct spi_flash *flash,
chunk_len = min(len - actual, page_size - byte_addr);
cmd[0] = CMD_MX25XX_PP;
- cmd[1] = page_addr >> 8;
- cmd[2] = page_addr;
- cmd[3] = byte_addr;
+ cmd[1] = (offset >> 16) & 0xff;
+ cmd[2] = (offset >> 8) & 0xff;
+ cmd[3] = offset & 0xff;
debug
("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %d\n",
@@ -166,12 +164,12 @@ static int macronix_write(struct spi_flash *flash,
if (ret)
break;
- page_addr++;
+ offset += chunk_len;
byte_addr = 0;
}
debug("SF: Macronix: Successfully programmed %u bytes @ 0x%x\n",
- len, offset);
+ len, offset - len);
spi_release_bus(flash->spi);
return ret;