summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorJun Lin <CHLin56@nuvoton.com>2023-02-16 10:51:08 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-02 19:51:03 +0000
commit267cec2b2e75609047469e6e351355f9e100fb14 (patch)
treedff3974dfbce23ccc8cbaba6cf1485d2f673e38b /chip
parentfb7cccc422e68c375ef8477cb05d12cd21047247 (diff)
downloadchrome-ec-267cec2b2e75609047469e6e351355f9e100fb14.tar.gz
npcx: driver: SPI: extend driver to support concurrent mode
This CL extends the SPI controller driver to support the concurrent transaction: - if the parameter "rxlen" is set to SPI_READBACK_ALL when spi_transaction() is called, the received data during the transmission phase should be stored in the "rxdata" buffer. BRANCH=none BUG=b:268286582 TEST=Loopback test on the npcx9 EVB, make sure the received data in the rxdata buffer is the same as that in the txdata buffer. Change-Id: Ia5ae17fefb69ce18709ded87693b34ed861f4997 Signed-off-by: Jun Lin <CHLin56@nuvoton.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4259466 Tested-by: CH Lin <chlin56@nuvoton.com> Reviewed-by: CH Lin <chlin56@nuvoton.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: David Cross <davidmcross@google.com> Commit-Queue: David Cross <davidmcross@google.com> Reviewed-by: Bobby Casey <bobbycasey@google.com>
Diffstat (limited to 'chip')
-rw-r--r--chip/npcx/spi.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/chip/npcx/spi.c b/chip/npcx/spi.c
index bbe6b33a9d..f152869bc5 100644
--- a/chip/npcx/spi.c
+++ b/chip/npcx/spi.c
@@ -148,9 +148,19 @@ int spi_transaction(const struct spi_device_t *spi_device,
/* Waiting till reading is finished */
while (!IS_BIT_SET(NPCX_SPI_STAT, NPCX_SPI_STAT_RBF))
;
- /* Reading the (unused) data */
- clear_databuf();
+
+ if (rxlen == SPI_READBACK_ALL) {
+ rxdata[i] = (uint8_t)NPCX_SPI_DATA;
+ CPRINTS("rxdata[i]=%x", rxdata[i]);
+ } else {
+ /* Reading the (unused) data to empty the read buffer */
+ clear_databuf();
+ }
}
+
+ if (rxlen == SPI_READBACK_ALL)
+ goto terminate;
+
CPRINTS("write end");
/* Reading the data */
for (i = 0; i < rxlen; ++i) {
@@ -166,6 +176,8 @@ int spi_transaction(const struct spi_device_t *spi_device,
rxdata[i] = (uint8_t)NPCX_SPI_DATA;
CPRINTS("rxdata[i]=%x", rxdata[i]);
}
+
+terminate:
/* Deassert CS# (high) to end transaction */
gpio_set_level(gpio, 1);
mutex_unlock(&spi_lock);