summaryrefslogtreecommitdiff
path: root/bitbang_spi.c
diff options
context:
space:
mode:
authormkarcher <mkarcher@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2010-07-17 10:42:34 +0000
committermkarcher <mkarcher@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2010-07-17 10:42:34 +0000
commit6b862f39cbd5b82f9cf903fdc9d67d908ea61187 (patch)
treefff028326e73a84a6fa375ae43436042ddb174ad /bitbang_spi.c
parenta7ec4ffcde835926f1024a0ecd61cf20259c53fb (diff)
downloadflashrom-6b862f39cbd5b82f9cf903fdc9d67d908ea61187.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. Signed-off-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1084 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
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;
}