[U-Boot] [PATCH] Add code for spi half duplex operation for enc28j60
Asok Subramanian
asok at vyassoft.com
Tue Aug 13 04:45:04 CEST 2013
Add code for spi half duplex operation for enc28j60
The current code assumes full duplex spi operation. But there are processors like imx23 which
only permit half duplex operation. This fix does half duplex operation based on the definition
of CONFIG_SPI_HALF_DUPLEX
Signed-off-by: Asok Subramanian <asok at vyassoft.com>
---
drivers/net/enc28j60.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c
index ec33764..753fe26 100644
--- a/drivers/net/enc28j60.c
+++ b/drivers/net/enc28j60.c
@@ -157,9 +157,17 @@ static u8 enc_r8(enc_dev_t *enc, const u16 reg)
enc_set_bank(enc, reg);
dout[0] = CMD_RCR(reg);
+#ifndef CONFIG_SPI_HALF_DUPLEX
spi_xfer(enc->slave, nbytes * 8, dout, din,
SPI_XFER_BEGIN | SPI_XFER_END);
return din[nbytes-1];
+#else
+ spi_xfer(enc->slave, (nbytes -1) * 8, dout, NULL,
+ SPI_XFER_BEGIN );
+ spi_xfer(enc->slave, 8, NULL, din,
+ SPI_XFER_END );
+ return din[0];
+#endif
}
/*
@@ -175,6 +183,7 @@ static u16 enc_r16(enc_dev_t *enc, const u16 reg)
enc_set_bank(enc, reg);
dout[0] = CMD_RCR(reg);
+#ifndef CONFIG_SPI_HALF_DUPLEX
spi_xfer(enc->slave, nbytes * 8, dout, din,
SPI_XFER_BEGIN | SPI_XFER_END);
result = din[nbytes-1];
@@ -183,6 +192,20 @@ static u16 enc_r16(enc_dev_t *enc, const u16 reg)
SPI_XFER_BEGIN | SPI_XFER_END);
result |= din[nbytes-1] << 8;
return result;
+#else
+ spi_xfer(enc->slave, (nbytes -1) * 8, dout, NULL,
+ SPI_XFER_BEGIN );
+ spi_xfer(enc->slave, 8, NULL, din,
+ SPI_XFER_END );
+ result = din[0];
+ dout[0]++; /* next register */
+ spi_xfer(enc->slave, (nbytes -1) * 8, dout, NULL,
+ SPI_XFER_BEGIN );
+ spi_xfer(enc->slave, 8, NULL, din,
+ SPI_XFER_END );
+ result |= din[0] << 8;
+ return result;
+#endif
}
/*
--
1.7.9.5
More information about the U-Boot
mailing list