summaryrefslogtreecommitdiffstats
path: root/linux_spi.c
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-02-15 15:04:20 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2021-02-16 23:36:15 +0000
commitf1391c756f315af7acc2494f9524b78f14d62bef (patch)
tree1ce2020c6e2d35423b27c0d33bd50d3ba4637dd9 /linux_spi.c
parentd784d484c92f31ea46fd1fa649812ecc1c6a36d8 (diff)
downloadflashrom-f1391c756f315af7acc2494f9524b78f14d62bef.tar.gz
flashrom-f1391c756f315af7acc2494f9524b78f14d62bef.tar.bz2
flashrom-f1391c756f315af7acc2494f9524b78f14d62bef.zip
tree: Remove forward-declarations for spi masters
Reorder functions to avoid forward-declarations. It looks like for most of the spi masters this has already been done before, I covered remaining small ones in one patch. BUG=b:140394053 TEST=builds Change-Id: I23ff6b79d794876f73b327f18784ca7c04c32c84 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/50711 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Sam McNally <sammc@google.com> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Diffstat (limited to 'linux_spi.c')
-rw-r--r--linux_spi.c122
1 files changed, 56 insertions, 66 deletions
diff --git a/linux_spi.c b/linux_spi.c
index 1ef8f2b72..bbd45f3b5 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -48,15 +48,65 @@ static int fd = -1;
#define BUF_SIZE_FROM_SYSFS "/sys/module/spidev/parameters/bufsiz"
static size_t max_kernel_buf_size;
-static int linux_spi_shutdown(void *data);
+static int linux_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
+{
+ /* Older kernels use a single buffer for combined input and output
+ data. So account for longest possible command + address, too. */
+ return spi_read_chunked(flash, buf, start, len, max_kernel_buf_size - 5);
+}
+
+static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
+{
+ /* 5 bytes must be reserved for longest possible command + address. */
+ return spi_write_chunked(flash, buf, start, len, max_kernel_buf_size - 5);
+}
+
+static int linux_spi_shutdown(void *data)
+{
+ if (fd != -1) {
+ close(fd);
+ fd = -1;
+ }
+ return 0;
+}
+
static int linux_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
const unsigned char *txbuf,
- unsigned char *rxbuf);
-static int linux_spi_read(struct flashctx *flash, uint8_t *buf,
- unsigned int start, unsigned int len);
-static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf,
- unsigned int start, unsigned int len);
+ unsigned char *rxbuf)
+{
+ int iocontrol_code;
+ struct spi_ioc_transfer msg[2] = {
+ {
+ .tx_buf = (uint64_t)(uintptr_t)txbuf,
+ .len = writecnt,
+ },
+ {
+ .rx_buf = (uint64_t)(uintptr_t)rxbuf,
+ .len = readcnt,
+ },
+ };
+
+ if (fd == -1)
+ return -1;
+ /* The implementation currently does not support requests that
+ don't start with sending a command. */
+ if (writecnt == 0)
+ return SPI_INVALID_LENGTH;
+
+ /* Just submit the first (write) request in case there is nothing
+ to read. Otherwise submit both requests. */
+ if (readcnt == 0)
+ iocontrol_code = SPI_IOC_MESSAGE(1);
+ else
+ iocontrol_code = SPI_IOC_MESSAGE(2);
+
+ if (ioctl(fd, iocontrol_code, msg) == -1) {
+ msg_cerr("%s: ioctl: %s\n", __func__, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
static const struct spi_master spi_master_linux = {
.features = SPI_MASTER_4BA,
@@ -174,64 +224,4 @@ out:
return 0;
}
-static int linux_spi_shutdown(void *data)
-{
- if (fd != -1) {
- close(fd);
- fd = -1;
- }
- return 0;
-}
-
-static int linux_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
- unsigned int readcnt,
- const unsigned char *txbuf,
- unsigned char *rxbuf)
-{
- int iocontrol_code;
- struct spi_ioc_transfer msg[2] = {
- {
- .tx_buf = (uint64_t)(uintptr_t)txbuf,
- .len = writecnt,
- },
- {
- .rx_buf = (uint64_t)(uintptr_t)rxbuf,
- .len = readcnt,
- },
- };
-
- if (fd == -1)
- return -1;
- /* The implementation currently does not support requests that
- don't start with sending a command. */
- if (writecnt == 0)
- return SPI_INVALID_LENGTH;
-
- /* Just submit the first (write) request in case there is nothing
- to read. Otherwise submit both requests. */
- if (readcnt == 0)
- iocontrol_code = SPI_IOC_MESSAGE(1);
- else
- iocontrol_code = SPI_IOC_MESSAGE(2);
-
- if (ioctl(fd, iocontrol_code, msg) == -1) {
- msg_cerr("%s: ioctl: %s\n", __func__, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int linux_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
-{
- /* Older kernels use a single buffer for combined input and output
- data. So account for longest possible command + address, too. */
- return spi_read_chunked(flash, buf, start, len, max_kernel_buf_size - 5);
-}
-
-static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
-{
- /* 5 bytes must be reserved for longest possible command + address. */
- return spi_write_chunked(flash, buf, start, len, max_kernel_buf_size - 5);
-}
-
#endif // CONFIG_LINUX_SPI == 1