mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
The old spi driver has atrophied in various ways. It doesn't support
the new protocol and does not build either.
Rewrite the driver to:
- Use dma for reception (rather than just reception)
- This makes message reception more robust and allows us to process
the new multi-byte commands
- Add timeouts for rx and tx so that we don't wait forever
- Increase buffer sizes to deal with new larger messages
- Always send a preamble byte regardless of SPI clock speed
(previously above 10MHz we sometimes miss this)
- Use the NSS line to delineate transactions. When it drops, a
transaction is starting. When it rises the transaction is immediately
terminates regardless of state. This keeps the AP and EC in sync even
in the event of timeouts, bus errors and other oddities.
- Implement the new protocol which has a checksum, version byte, etc
- Set up tx dma in advance and kick it when ready, thus ensuring that
a message body is always attached immediately after the preamble
- Use the new host_cmd_handle_args structure, which makes things much
easier for us, since we don't need globals, and can use the
send_response handler to know when a slow command is complete.
- Handle the new type of 'slow' commands properly
BUG=chrome-os-partner:10533
TEST=manual
build and boot to kernel on snow
Change-Id: I11767d1a6f045a86f6c9a0b4b1e943b660e4da33
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/32076
Reviewed-by: Randall Spangler <rspangler@chromium.org>
39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
/* Copyright (c) 2012 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.
|
|
*/
|
|
|
|
/* SPI interface for Chrome EC */
|
|
|
|
#ifndef __CROS_EC_SPI_H
|
|
#define __CROS_EC_SPI_H
|
|
|
|
/* 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);
|
|
|
|
/* Issue a SPI transaction. Assumes SPI port has already been enabled.
|
|
* Transmits <txlen> bytes from <txdata>, throwing away the corresponding
|
|
* received data, then transmits <rxlen> dummy bytes, saving the received data
|
|
* in <rxdata>. */
|
|
int spi_transaction(const uint8_t *txdata, int txlen,
|
|
uint8_t *rxdata, int rxlen);
|
|
|
|
#ifdef CONFIG_SPI
|
|
/**
|
|
* Called when the NSS level changes, signalling the start or end of a SPI
|
|
* transaction.
|
|
*
|
|
* @param signal GPIO signal that changed
|
|
*/
|
|
void spi_event(enum gpio_signal signal);
|
|
|
|
#else
|
|
static inline void spi_event(enum gpio_signal signal)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* __CROS_EC_SPI_H */
|