[flashrom] [PATCH 1/3] rayer_spi: add signal inversion support

Ondrej Zary linux at rainbow-software.org
Sat Mar 16 23:43:02 CET 2013


Add signal inversion support for all signals and remove the bit 7 hack
in rayer_bitbang_get_miso().

Signed-off-by: Ondrej Zary <linux at rainbow-software.org>

--- a/rayer_spi.c	2013-03-16 23:11:57.000000000 +0100
+++ b/rayer_spi.c	2013-03-16 23:12:06.000000000 +0100
@@ -54,6 +54,10 @@ struct rayer_pinout {
 	int sck_bit;
 	int mosi_bit;
 	int miso_bit;
+	int cs_inverted;
+	int sck_inverted;
+	int mosi_inverted;
+	int miso_inverted;
 	void (*preinit)(void *);
 	int (*shutdown)(void *);
 };
@@ -92,6 +96,7 @@ static struct rayer_pinout altera_bytebl
 	.sck_bit = 0,
 	.mosi_bit = 6,
 	.miso_bit = 7,
+	.miso_inverted = 1,
 	.preinit =  byteblaster_preinit,
 	.shutdown = byteblaster_shutdown,
 };
@@ -113,6 +118,7 @@ static struct rayer_pinout wiggler_lpt =
 	.sck_bit = 2,
 	.mosi_bit = 3,
 	.miso_bit = 7,
+	.miso_inverted = 1,
 };
 
 struct rayer_programmer rayer_spi_types[] = {
@@ -134,6 +140,8 @@ static uint8_t lpt_outbyte;
 
 static void rayer_bitbang_set_cs(int val)
 {
+	if (pinout->cs_inverted)
+		val = !val;
 	lpt_outbyte &= ~(1 << pinout->cs_bit);
 	lpt_outbyte |= (val << pinout->cs_bit);
 	OUTB(lpt_outbyte, lpt_iobase);
@@ -141,6 +149,8 @@ static void rayer_bitbang_set_cs(int val
 
 static void rayer_bitbang_set_sck(int val)
 {
+	if (pinout->sck_inverted)
+		val = !val;
 	lpt_outbyte &= ~(1 << pinout->sck_bit);
 	lpt_outbyte |= (val << pinout->sck_bit);
 	OUTB(lpt_outbyte, lpt_iobase);
@@ -148,6 +158,8 @@ static void rayer_bitbang_set_sck(int va
 
 static void rayer_bitbang_set_mosi(int val)
 {
+	if (pinout->mosi_inverted)
+		val = !val;
 	lpt_outbyte &= ~(1 << pinout->mosi_bit);
 	lpt_outbyte |= (val << pinout->mosi_bit);
 	OUTB(lpt_outbyte, lpt_iobase);
@@ -157,8 +169,10 @@ static int rayer_bitbang_get_miso(void)
 {
 	uint8_t tmp;
 
-	tmp = INB(lpt_iobase + 1) ^ 0x80; // bit.7 inverted
+	tmp = INB(lpt_iobase + 1);
 	tmp = (tmp >> pinout->miso_bit) & 0x1;
+	if (pinout->miso_inverted)
+		tmp = !tmp;
 	return tmp;
 }
 

-- 
Ondrej Zary




More information about the flashrom mailing list