aboutsummaryrefslogtreecommitdiff
path: root/libstb
diff options
context:
space:
mode:
authorClaudio Carvalho <cclaudio@linux.vnet.ibm.com>2016-11-28 01:08:03 -0200
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-11-29 18:17:02 +1100
commit5154ff3b67019ccc2abe7b505357a9d1db8172cb (patch)
tree3456b39b78dc36abc1bcd50d11710771e33a0d4d /libstb
parent830717695a8bf4114cdffab3d40a3508c5b129b1 (diff)
downloadskiboot-5154ff3b67019ccc2abe7b505357a9d1db8172cb.zip
skiboot-5154ff3b67019ccc2abe7b505357a9d1db8172cb.tar.gz
skiboot-5154ff3b67019ccc2abe7b505357a9d1db8172cb.tar.bz2
tpm_i2c_nuvoton: add tpm_status_read_byte()
The tpm status register is read from multiple places by calling the tpm-i2c-interface. This adds the tpm_status_read_byte() to be the only function that directly calls the tpm-i2c interface to read the tpm status register Signed-off-by: Claudio Carvalho <cclaudio@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libstb')
-rw-r--r--libstb/drivers/tpm_i2c_nuvoton.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c
index b6a9202..7413770 100644
--- a/libstb/drivers/tpm_i2c_nuvoton.c
+++ b/libstb/drivers/tpm_i2c_nuvoton.c
@@ -65,6 +65,13 @@ static int tpm_status_write_byte(uint8_t byte)
sizeof(value));
}
+static int tpm_status_read_byte(uint8_t offset, uint8_t *byte)
+{
+ return tpm_i2c_request_send(tpm_device->bus_id, tpm_device->xscom_base,
+ SMBUS_READ, offset, 1, byte,
+ sizeof(uint8_t));
+}
+
static bool tpm_check_status(uint8_t status, uint8_t mask, uint8_t expected)
{
return ((status & mask) == expected);
@@ -75,9 +82,7 @@ static int tpm_read_sts_reg_valid(uint8_t* value)
int polls, rc;
for(polls=0; polls<=MAX_STSVALID_POLLS; polls++) {
- rc = tpm_i2c_request_send(tpm_device->bus_id,
- tpm_device->xscom_base, SMBUS_READ,
- TPM_STS, 1, value, sizeof(uint8_t));
+ rc = tpm_status_read_byte(TPM_STS, value);
if (rc < 0)
return rc;
if (tpm_check_status(*value, TPM_STS_VALID, TPM_STS_VALID))
@@ -99,9 +104,7 @@ static int tpm_read_sts_reg_valid(uint8_t* value)
static bool tpm_is_command_ready(int* rc)
{
uint8_t value = 0;
- *rc = tpm_i2c_request_send(tpm_device->bus_id, tpm_device->xscom_base,
- SMBUS_READ, TPM_STS, 1, &value,
- sizeof(value));
+ *rc = tpm_status_read_byte(TPM_STS, &value);
if (*rc < 0)
false;
if (tpm_check_status(value, TPM_STS_COMMAND_READY,
@@ -194,9 +197,7 @@ static int tpm_read_burst_count(uint8_t* burst_count)
{
int rc = 0;
/* In i2C, burstCount is 1 byte */
- rc = tpm_i2c_request_send(tpm_device->bus_id, tpm_device->xscom_base,
- SMBUS_READ, TPM_BURST_COUNT, 1,
- burst_count, sizeof(uint8_t));
+ rc = tpm_status_read_byte(TPM_BURST_COUNT, burst_count);
DBG("---- burst_count=%d rc=%d\n", *burst_count, rc);
if (rc < 0)
*burst_count = 0;