summaryrefslogtreecommitdiffstats
path: root/bitbang_spi.c
diff options
context:
space:
mode:
authorMichael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>2010-07-17 10:42:34 +0000
committerMichael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>2010-07-17 10:42:34 +0000
commit1a854fc98ca68dae574a836ead8a6d3e6321fb18 (patch)
treefff028326e73a84a6fa375ae43436042ddb174ad /bitbang_spi.c
parent420cf6f633f7697a8a709326c47b3cf0e6ea229d (diff)
downloadast2050-flashrom-1a854fc98ca68dae574a836ead8a6d3e6321fb18.zip
ast2050-flashrom-1a854fc98ca68dae574a836ead8a6d3e6321fb18.tar.gz
Remove temporary buffers from bitbanging
This removes the need of allocating an extra buffer, but also removes the possibility of having the data read back during the initial write phase for debugging purposes. Compile tested, no functional testing. Corresponding to flashrom svn r1084. Signed-off-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Diffstat (limited to 'bitbang_spi.c')
-rw-r--r--bitbang_spi.c43
1 files changed, 5 insertions, 38 deletions
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 446be11..6316a55 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -85,50 +85,17 @@ uint8_t bitbang_spi_readwrite_byte(uint8_t val)
int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
- static unsigned char *bufout = NULL;
- static unsigned char *bufin = NULL;
- static int oldbufsize = 0;
- int bufsize;
int i;
- /* Arbitrary size limitation here. We're only constrained by memory. */
- if (writecnt > 65536 || readcnt > 65536)
- return SPI_INVALID_LENGTH;
-
- bufsize = max(writecnt + readcnt, 260);
- /* Never shrink. realloc() calls are expensive. */
- if (bufsize > oldbufsize) {
- bufout = realloc(bufout, bufsize);
- if (!bufout) {
- msg_perr("Out of memory!\n");
- if (bufin)
- free(bufin);
- exit(1);
- }
- bufin = realloc(bufout, bufsize);
- if (!bufin) {
- msg_perr("Out of memory!\n");
- if (bufout)
- free(bufout);
- exit(1);
- }
- oldbufsize = bufsize;
- }
-
- memcpy(bufout, writearr, writecnt);
- /* Shift out 0x00 while reading data. */
- memset(bufout + writecnt, 0x00, readcnt);
- /* Make sure any non-read data is 0xff. */
- memset(bufin + writecnt, 0xff, readcnt);
-
bitbang_spi_set_cs(0);
- for (i = 0; i < readcnt + writecnt; i++) {
- bufin[i] = bitbang_spi_readwrite_byte(bufout[i]);
- }
+ for (i = 0; i < writecnt; i++)
+ bitbang_spi_readwrite_byte(writearr[i]);
+ for (i = 0; i < readcnt; i++)
+ readarr[i] = bitbang_spi_readwrite_byte(0);
+
programmer_delay(bitbang_spi_half_period);
bitbang_spi_set_cs(1);
programmer_delay(bitbang_spi_half_period);
- memcpy(readarr, bufin + writecnt, readcnt);
return 0;
}
OpenPOWER on IntegriCloud