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 /include | |
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 'include')
-rw-r--r-- | include/spi.h | 19 | ||||
-rw-r--r-- | include/sps.h | 47 |
2 files changed, 66 insertions, 0 deletions
diff --git a/include/spi.h b/include/spi.h index f8f916213b..d62c1420ca 100644 --- a/include/spi.h +++ b/include/spi.h @@ -8,6 +8,25 @@ #ifndef __CROS_EC_SPI_H #define __CROS_EC_SPI_H +/* + * SPI Clock polarity and phase mode (0 - 3) + * @code + * clk mode | POL PHA + * ---------+-------- + * 0 | 0 0 + * 1 | 0 1 + * 2 | 1 0 + * 3 | 1 1 + * ---------+-------- + * @endcode + */ +enum spi_clock_mode { + SPI_CLOCK_MODE0 = 0, + SPI_CLOCK_MODE1 = 1, + SPI_CLOCK_MODE2 = 2, + SPI_CLOCK_MODE3 = 3 +}; + /* Enable / disable the SPI port. When the port is disabled, all its I/O lines * are high-Z so the EC won't interfere with other devices on the SPI bus. */ int spi_enable(int enable); diff --git a/include/sps.h b/include/sps.h new file mode 100644 index 0000000000..93be326b15 --- /dev/null +++ b/include/sps.h @@ -0,0 +1,47 @@ +/* + * Copyright 2015 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_INCLUDE_SPS_H +#define __CROS_EC_INCLUDE_SPS_H + +#include "spi.h" +#include "util.h" + +/* SPS Control Mode */ +enum sps_mode { + SPS_GENERIC_MODE = 0, + SPS_SWETLAND_MODE = 1, + SPS_ROM_MODE = 2, + SPS_UNDEF_MODE = 3, +}; + +/* + * Tx interrupt callback function prototype. This function returns a portion + * of the received SPI data and current status of the CS line. When CS is + * deasserted, this function is called with data_size of zero and a non-zero + * cs_status. This allows the recipient to delineate the SPS frames. + */ +typedef void (*rx_handler_f)(uint32_t inst, uint8_t *data, + size_t data_size, int cs_status); + +/* + * Push data to the SPS TX FIFO + * @param inst Interface number + * @param data Pointer to 8-bit data + * @param data_size Number of bytes to transmit + * @return : actual number of bytes placed into tx fifo + */ +int sps_transmit(uint32_t inst, uint8_t *data, size_t data_size); + +/* + * These functions return zero on success or non-zero on failure (attempt to + * register a callback on top of existing one, or attempt to unregister + * non-exitisng callback. + */ +int sps_register_rx_handler(enum sps_mode mode, rx_handler_f rx_handler); +int sps_unregister_rx_handler(void); + +#endif |