From 36b81af9e8ecea2bf58aae9a421720ed10f61b82 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Thu, 1 Dec 2016 01:02:44 -0800 Subject: spi: Pass pointer to spi_slave structure in spi_setup_slave For spi_setup_slave, instead of making the platform driver return a pointer to spi_slave structure, pass in a structure pointer that can be filled in by the driver as required. This removes the need for platform drivers to maintain a slave structure in data/CAR section. BUG=chrome-os-partner:59832 BRANCH=None TEST=Compiles successfully Change-Id: Ia15a4f88ef4dcfdf616bb1c22261e7cb642a7573 Signed-off-by: Furquan Shaikh Reviewed-on: https://review.coreboot.org/17683 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/drivers/spi/tpm/tis.c | 10 ++++++++-- src/drivers/spi/tpm/tpm.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src/drivers/spi/tpm') diff --git a/src/drivers/spi/tpm/tis.c b/src/drivers/spi/tpm/tis.c index 055525b1c6..d3c727cb27 100644 --- a/src/drivers/spi/tpm/tis.c +++ b/src/drivers/spi/tpm/tis.c @@ -58,10 +58,16 @@ int tis_close(void) int tis_init(void) { + struct spi_slave spi; struct tpm2_info info; - if (tpm2_init(spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS, - CONFIG_DRIVER_TPM_SPI_CHIP))) { + if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS, + CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) { + printk(BIOS_ERR, "Failed to setup TPM SPI slave\n"); + return -1; + } + + if (tpm2_init(&spi)) { printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n"); return -1; } diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c index d364cb958a..5abfc4558f 100644 --- a/src/drivers/spi/tpm/tpm.c +++ b/src/drivers/spi/tpm/tpm.c @@ -36,7 +36,7 @@ /* SPI Interface descriptor used by the driver. */ struct tpm_spi_if { - struct spi_slave *slave; + struct spi_slave slave; int (*cs_assert)(const struct spi_slave *slave); void (*cs_deassert)(const struct spi_slave *slave); int (*xfer)(const struct spi_slave *slave, const void *dout, @@ -130,7 +130,7 @@ static void start_transaction(int read_write, size_t bytes, unsigned addr) header.body[i + 1] = (addr >> (8 * (2 - i))) & 0xff; /* CS assert wakes up the slave. */ - tpm_if.cs_assert(tpm_if.slave); + tpm_if.cs_assert(&tpm_if.slave); /* * The TCG TPM over SPI specification introduces the notion of SPI @@ -157,11 +157,11 @@ static void start_transaction(int read_write, size_t bytes, unsigned addr) * to require to stall the master, this would present an issue. * crosbug.com/p/52132 has been opened to track this. */ - tpm_if.xfer(tpm_if.slave, header.body, sizeof(header.body), NULL, 0); + tpm_if.xfer(&tpm_if.slave, header.body, sizeof(header.body), NULL, 0); /* Now poll the bus until TPM removes the stall bit. */ do { - tpm_if.xfer(tpm_if.slave, NULL, 0, &byte, 1); + tpm_if.xfer(&tpm_if.slave, NULL, 0, &byte, 1); } while (!(byte & 1)); } @@ -227,7 +227,7 @@ static void trace_dump(const char *prefix, uint32_t reg, */ static void write_bytes(const void *buffer, size_t bytes) { - tpm_if.xfer(tpm_if.slave, buffer, bytes, NULL, 0); + tpm_if.xfer(&tpm_if.slave, buffer, bytes, NULL, 0); } /* @@ -236,7 +236,7 @@ static void write_bytes(const void *buffer, size_t bytes) */ static void read_bytes(void *buffer, size_t bytes) { - tpm_if.xfer(tpm_if.slave, NULL, 0, buffer, bytes); + tpm_if.xfer(&tpm_if.slave, NULL, 0, buffer, bytes); } /* @@ -251,7 +251,7 @@ static int tpm2_write_reg(unsigned reg_number, const void *buffer, size_t bytes) trace_dump("W", reg_number, bytes, buffer, 0); start_transaction(false, bytes, reg_number); write_bytes(buffer, bytes); - tpm_if.cs_deassert(tpm_if.slave); + tpm_if.cs_deassert(&tpm_if.slave); return 1; } @@ -266,7 +266,7 @@ static int tpm2_read_reg(unsigned reg_number, void *buffer, size_t bytes) { start_transaction(true, bytes, reg_number); read_bytes(buffer, bytes); - tpm_if.cs_deassert(tpm_if.slave); + tpm_if.cs_deassert(&tpm_if.slave); trace_dump("R", reg_number, bytes, buffer, 0); return 1; } @@ -303,7 +303,7 @@ int tpm2_init(struct spi_slave *spi_if) uint32_t did_vid, status; uint8_t cmd; - tpm_if.slave = spi_if; + memcpy(&tpm_if.slave, spi_if, sizeof(*spi_if)); tpm2_read_reg(TPM_DID_VID_REG, &did_vid, sizeof(did_vid)); -- cgit v1.2.3