aboutsummaryrefslogtreecommitdiff
path: root/libstb
diff options
context:
space:
mode:
authorClaudio Carvalho <cclaudio@linux.vnet.ibm.com>2016-11-28 01:08:02 -0200
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-11-29 18:17:02 +1100
commit830717695a8bf4114cdffab3d40a3508c5b129b1 (patch)
tree9dfc1d50acb4617cca155a691802b37043a1c0e6 /libstb
parent1fdb77cc7dc9695a6d7bb1781a1514855a95a6ea (diff)
downloadskiboot-830717695a8bf4114cdffab3d40a3508c5b129b1.zip
skiboot-830717695a8bf4114cdffab3d40a3508c5b129b1.tar.gz
skiboot-830717695a8bf4114cdffab3d40a3508c5b129b1.tar.bz2
tpm_i2c_nuvoton: add tpm_check_status()
This adds the tpm_check_status(), which makes the code more easy to read and also allows the use of a mask to check status. 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.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c
index 755bb16..b6a9202 100644
--- a/libstb/drivers/tpm_i2c_nuvoton.c
+++ b/libstb/drivers/tpm_i2c_nuvoton.c
@@ -65,6 +65,11 @@ static int tpm_status_write_byte(uint8_t byte)
sizeof(value));
}
+static bool tpm_check_status(uint8_t status, uint8_t mask, uint8_t expected)
+{
+ return ((status & mask) == expected);
+}
+
static int tpm_read_sts_reg_valid(uint8_t* value)
{
int polls, rc;
@@ -75,8 +80,7 @@ static int tpm_read_sts_reg_valid(uint8_t* value)
TPM_STS, 1, value, sizeof(uint8_t));
if (rc < 0)
return rc;
- if (rc == 0 &&
- ((*value & TPM_STS_VALID) == TPM_STS_VALID))
+ if (tpm_check_status(*value, TPM_STS_VALID, TPM_STS_VALID))
return 0;
/* Wait TPM STS register be settled */
time_wait_ms(5);
@@ -98,8 +102,10 @@ static bool tpm_is_command_ready(int* rc)
*rc = tpm_i2c_request_send(tpm_device->bus_id, tpm_device->xscom_base,
SMBUS_READ, TPM_STS, 1, &value,
sizeof(value));
- if (*rc == 0 &&
- ((value & TPM_STS_COMMAND_READY) == TPM_STS_COMMAND_READY)){
+ if (*rc < 0)
+ false;
+ if (tpm_check_status(value, TPM_STS_COMMAND_READY,
+ TPM_STS_COMMAND_READY)) {
DBG("---- TPM is command ready\n");
return true;
}
@@ -141,8 +147,9 @@ static bool tpm_is_expecting(int* rc)
{
uint8_t value = 0;
*rc = tpm_read_sts_reg_valid(&value);
- if (*rc == 0 &&
- (( value & TPM_STS_EXPECT) == TPM_STS_EXPECT))
+ if (*rc < 0)
+ return false;
+ if (tpm_check_status(value, TPM_STS_EXPECT, TPM_STS_EXPECT))
return true;
return false;
}
@@ -152,11 +159,10 @@ static bool tpm_is_data_avail(int* rc)
uint8_t value = 0;
*rc = tpm_read_sts_reg_valid(&value);
-
- if (*rc == 0 && (( value &
- TPM_STS_DATA_AVAIL) == TPM_STS_DATA_AVAIL))
+ if (*rc < 0)
+ return false;
+ if (tpm_check_status(value, TPM_STS_DATA_AVAIL, TPM_STS_DATA_AVAIL))
return true;
-
return false;
}