mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-01 22:21:16 +02:00
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>
This commit is contained in:

committed by
Edward O'Callaghan

parent
d784d484c9
commit
f1391c756f
122
linux_spi.c
122
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
|
||||
|
Reference in New Issue
Block a user