UPSTREAM: 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
BRANCH=none
TEST=builds
Original-Change-Id: I23ff6b79d794876f73b327f18784ca7c04c32c84
Original-Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/50711
Original-Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Sam McNally <sammc@google.com>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
(cherry picked from commit f1391c756f315af7acc2494f9524b78f14d62bef)
Change-Id: I34fd94d55285bb0993af8c0de3252e88ffa4bba5
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/2711149
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Commit-Queue: Nikolai Artemiev <nartemiev@google.com>
diff --git a/linux_spi.c b/linux_spi.c
index 7701f50..2dd1782 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -55,15 +55,65 @@
#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,
@@ -251,64 +301,4 @@
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