summaryrefslogtreecommitdiffstats
path: root/ch341a_spi.c
diff options
context:
space:
mode:
authorMarc Schink <flashrom-dev@marcschink.de>2016-03-17 16:07:23 +0100
committerNico Huber <nico.h@gmx.de>2018-08-30 09:55:57 +0000
commit7ecfe48b19c3e97341a3f2b0d85e7367ab92f2b6 (patch)
tree8114881424b47ca6c3044e39da8e16615001887b /ch341a_spi.c
parentaf499198a49fe342a0bb3dbbfa362b8788a8fb4e (diff)
downloadflashrom-7ecfe48b19c3e97341a3f2b0d85e7367ab92f2b6.tar.gz
flashrom-7ecfe48b19c3e97341a3f2b0d85e7367ab92f2b6.tar.bz2
flashrom-7ecfe48b19c3e97341a3f2b0d85e7367ab92f2b6.zip
helpers: Add reverse_byte() and reverse_bytes()
Change-Id: I9d2e1e2856c835d22eed3b3a34bc0379773dd831 Signed-off-by: Marc Schink <flashrom-dev@marcschink.de> Reviewed-on: https://review.coreboot.org/28086 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'ch341a_spi.c')
-rw-r--r--ch341a_spi.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 9ebda0d3a..83d5ccf35 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -274,15 +274,6 @@ static int32_t config_stream(uint32_t speed)
return ret;
}
-/* ch341 requires LSB first, swap the bit order before send and after receive */
-static uint8_t swap_byte(uint8_t x)
-{
- x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
- x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
- x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
- return x;
-}
-
/* The assumed map between UIO command bits, pins on CH341A chip and pins on SPI chip:
* UIO CH341A SPI CH341A SPI name
* 0 D0/15 CS/1 (CS0)
@@ -372,7 +363,7 @@ static int ch341a_spi_spi_send_command(struct flashctx *flash, unsigned int writ
*ptr++ = CH341A_CMD_SPI_STREAM;
unsigned int i;
for (i = 0; i < write_now; ++i)
- *ptr++ = swap_byte(*writearr++);
+ *ptr++ = reverse_byte(*writearr++);
if (read_now) {
memset(ptr, 0xFF, read_now);
read_left -= read_now;
@@ -387,7 +378,7 @@ static int ch341a_spi_spi_send_command(struct flashctx *flash, unsigned int writ
unsigned int i;
for (i = 0; i < readcnt; i++) {
- *readarr++ = swap_byte(rbuf[writecnt + i]);
+ *readarr++ = reverse_byte(rbuf[writecnt + i]);
}
return 0;