diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2015-05-06 13:51:20 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-05-07 23:39:06 +0000 |
commit | dbf027f2f78f696b909dd2d70c8bf5439171befd (patch) | |
tree | 496044963b9a23f173b8c48e7ab81fdfdc79abc5 /board/cr50 | |
parent | d3771ff35928d7c00882e382577841b78c68190d (diff) | |
download | chrome-ec-dbf027f2f78f696b909dd2d70c8bf5439171befd.tar.gz |
cr50: add SPI Slave driver
The CR50 device will have to have two different drivers, for SPI slave
and master modes. This patch adds the slave driver which is called
SPS.
CR50 SPS controller uses 2KB buffer split evenly between receive and
transmit directions as two FIFOs. RX write and TX read pointers are
maintained by hardware, RX read and TX write pointers are maintained
by software.
The FIFO area allows only 32 bit writes from the CPU core, which
complicates the function placing TX data into the FIFO. There is no
limit to read access size.
Another complication is that the hardware pointers in the FIFO in fact
have 11 bits (instead of 10 required to address 1K), so the software
needs to use 10 bits when accessing the FIFO, but 11 bits when writing
the pointers into the registers.
Driver API provides three functions:
- transmit a packet of a certain size, runs on the task context and can
exit before the entire packet is transmitted.,
- register a receive callback. The callback is running in interrupt
context. Registering the callback (re)initializes the interface.
- unregister receive callback.
A CLI command is added to help testing this driver. When invoked, it
installs the callback function to handle receive data. The data is
expected to be of the following format:
<size/256> <size%256> [<size> bytes of payload]
where size should not exceed 1098 bytes.
Received frames are saved in a buffer and once received are
transmitted back to the host.
BRANCH=none
BUG=none
TEST=used the enhanced 'spiraw' utility which sends frames of random
size in 10..1010 bytes, and then clocks the line to receive the
same amount of bytes back, syncs up in the returning stream of
bytes and compares received and transmitted data.
# run 'sps 100' on the target
$ src/examples/spiraw.py -l 100 -f 2000000
FT232H Future Technology Devices International, Ltd initialized at 2000000 hertz
$
which is an indication of the successful loop back of 100 frames.
The cli command on the target exits and reports the stats:
> sps 100
Processed 100 frames
rx count 108532, tx count 51366, tx_empty count 100, max rx batch 11
Change-Id: I62956753eb09086b5fca7504f2241605c0afe613
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/269794
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'board/cr50')
-rw-r--r-- | board/cr50/board.h | 2 | ||||
-rw-r--r-- | board/cr50/gpio.inc | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/board/cr50/board.h b/board/cr50/board.h index 9552fad650..ba922ca357 100644 --- a/board/cr50/board.h +++ b/board/cr50/board.h @@ -36,6 +36,8 @@ #define CONFIG_RSA #define CONFIG_SHA256 +#define CONFIG_SPS_TEST + #ifndef __ASSEMBLER__ #include "gpio_signal.h" diff --git a/board/cr50/gpio.inc b/board/cr50/gpio.inc index d5cf447cb1..8858d04bad 100644 --- a/board/cr50/gpio.inc +++ b/board/cr50/gpio.inc @@ -63,3 +63,9 @@ ALTERNATE(LED_4, DIO(A11), 0, MODULE_GPIO, DIO_INPUT) ALTERNATE(LED_5, DIO(A12), 0, MODULE_GPIO, DIO_INPUT) ALTERNATE(LED_6, DIO(A13), 0, MODULE_GPIO, DIO_INPUT) ALTERNATE(LED_7, DIO(A14), 0, MODULE_GPIO, DIO_INPUT) + +/* SPS IOs */ +ALTERNATE(FUNC(SPS0_SPICLK), DIO(A2), 0, MODULE_GPIO, DIO_INPUT) +ALTERNATE(FUNC(SPS0_SPIMOSI), DIO(A3), 0, MODULE_GPIO, DIO_INPUT) +ALTERNATE(FUNC(SPS0_SPICSB), DIO(A4), 0, MODULE_GPIO, DIO_INPUT) +ALTERNATE(FUNC(SPS0_SPIMISO), DIO(A5), 0, MODULE_GPIO, DIO_OUTPUT) |