aboutsummaryrefslogtreecommitdiffstats
path: root/mstarddc_spi.c
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-03-23 16:34:07 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2021-04-01 01:17:48 +0000
commite704583ad53b24e1b39aa7a2e5077fa95d5f9244 (patch)
treed30504f5ac4310850372b124c33447b8f8ce3176 /mstarddc_spi.c
parent6d79a6ab808463f6895a9665858ff8b220d5118b (diff)
downloadflashrom-e704583ad53b24e1b39aa7a2e5077fa95d5f9244.tar.gz
flashrom-e704583ad53b24e1b39aa7a2e5077fa95d5f9244.tar.bz2
flashrom-e704583ad53b24e1b39aa7a2e5077fa95d5f9244.zip
tree: Remove forward-declarations of structs for spi masters
Reorder functions to avoid forward-declarations of structs. Similar thing was done earlier for functions declarations, this patch takes care of structs declarations. BUG=b:140394053 TEST=builds objdump -d is identical objdump -s only difference is version number Change-Id: I256bd7c763efc010fc1f29f7c5853f150ac10739 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/51731 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'mstarddc_spi.c')
-rw-r--r--mstarddc_spi.c156
1 files changed, 77 insertions, 79 deletions
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index 48d62045..c041bd33 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -31,8 +31,6 @@
#include "programmer.h"
#include "spi.h"
-static const struct spi_master spi_master_mstarddc;
-
static int mstarddc_fd;
static int mstarddc_addr;
static int mstarddc_doreset = 1;
@@ -68,6 +66,83 @@ static int mstarddc_spi_shutdown(void *data)
}
/* Returns 0 upon success, a negative number upon errors. */
+static int mstarddc_spi_send_command(const struct flashctx *flash,
+ unsigned int writecnt,
+ unsigned int readcnt,
+ const unsigned char *writearr,
+ unsigned char *readarr)
+{
+ int ret = 0;
+ uint8_t *cmd = malloc((writecnt + 1) * sizeof(uint8_t));
+ if (cmd == NULL) {
+ msg_perr("Error allocating memory: errno %d.\n", errno);
+ ret = -1;
+ }
+
+ if (!ret && writecnt) {
+ cmd[0] = MSTARDDC_SPI_WRITE;
+ memcpy(cmd + 1, writearr, writecnt);
+ if (write(mstarddc_fd, cmd, writecnt + 1) < 0) {
+ msg_perr("Error sending write command: errno %d.\n",
+ errno);
+ ret = -1;
+ }
+ }
+
+ if (!ret && readcnt) {
+ struct i2c_rdwr_ioctl_data i2c_data;
+ struct i2c_msg msg[2];
+
+ cmd[0] = MSTARDDC_SPI_READ;
+ i2c_data.nmsgs = 2;
+ i2c_data.msgs = msg;
+ i2c_data.msgs[0].addr = mstarddc_addr;
+ i2c_data.msgs[0].len = 1;
+ i2c_data.msgs[0].flags = 0;
+ i2c_data.msgs[0].buf = cmd;
+ i2c_data.msgs[1].addr = mstarddc_addr;
+ i2c_data.msgs[1].len = readcnt;
+ i2c_data.msgs[1].flags = I2C_M_RD;
+ i2c_data.msgs[1].buf = readarr;
+
+ if (ioctl(mstarddc_fd, I2C_RDWR, &i2c_data) < 0) {
+ msg_perr("Error sending read command: errno %d.\n",
+ errno);
+ ret = -1;
+ }
+ }
+
+ if (!ret && (writecnt || readcnt)) {
+ cmd[0] = MSTARDDC_SPI_END;
+ if (write(mstarddc_fd, cmd, 1) < 0) {
+ msg_perr("Error sending end command: errno %d.\n",
+ errno);
+ ret = -1;
+ }
+ }
+
+ /* Do not reset if something went wrong, as it might prevent from
+ * retrying flashing. */
+ if (ret != 0)
+ mstarddc_doreset = 0;
+
+ if (cmd)
+ free(cmd);
+
+ return ret;
+}
+
+static const struct spi_master spi_master_mstarddc = {
+ .max_data_read = 256,
+ .max_data_write = 256,
+ .command = mstarddc_spi_send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
+};
+
+/* Returns 0 upon success, a negative number upon errors. */
int mstarddc_spi_init(void)
{
int ret = 0;
@@ -152,81 +227,4 @@ out:
return ret;
}
-/* Returns 0 upon success, a negative number upon errors. */
-static int mstarddc_spi_send_command(const struct flashctx *flash,
- unsigned int writecnt,
- unsigned int readcnt,
- const unsigned char *writearr,
- unsigned char *readarr)
-{
- int ret = 0;
- uint8_t *cmd = malloc((writecnt + 1) * sizeof(uint8_t));
- if (cmd == NULL) {
- msg_perr("Error allocating memory: errno %d.\n", errno);
- ret = -1;
- }
-
- if (!ret && writecnt) {
- cmd[0] = MSTARDDC_SPI_WRITE;
- memcpy(cmd + 1, writearr, writecnt);
- if (write(mstarddc_fd, cmd, writecnt + 1) < 0) {
- msg_perr("Error sending write command: errno %d.\n",
- errno);
- ret = -1;
- }
- }
-
- if (!ret && readcnt) {
- struct i2c_rdwr_ioctl_data i2c_data;
- struct i2c_msg msg[2];
-
- cmd[0] = MSTARDDC_SPI_READ;
- i2c_data.nmsgs = 2;
- i2c_data.msgs = msg;
- i2c_data.msgs[0].addr = mstarddc_addr;
- i2c_data.msgs[0].len = 1;
- i2c_data.msgs[0].flags = 0;
- i2c_data.msgs[0].buf = cmd;
- i2c_data.msgs[1].addr = mstarddc_addr;
- i2c_data.msgs[1].len = readcnt;
- i2c_data.msgs[1].flags = I2C_M_RD;
- i2c_data.msgs[1].buf = readarr;
-
- if (ioctl(mstarddc_fd, I2C_RDWR, &i2c_data) < 0) {
- msg_perr("Error sending read command: errno %d.\n",
- errno);
- ret = -1;
- }
- }
-
- if (!ret && (writecnt || readcnt)) {
- cmd[0] = MSTARDDC_SPI_END;
- if (write(mstarddc_fd, cmd, 1) < 0) {
- msg_perr("Error sending end command: errno %d.\n",
- errno);
- ret = -1;
- }
- }
-
- /* Do not reset if something went wrong, as it might prevent from
- * retrying flashing. */
- if (ret != 0)
- mstarddc_doreset = 0;
-
- if (cmd)
- free(cmd);
-
- return ret;
-}
-
-static const struct spi_master spi_master_mstarddc = {
- .max_data_read = 256,
- .max_data_write = 256,
- .command = mstarddc_spi_send_command,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
-};
-
#endif