Skip to content

Commit

Permalink
tpm_i2c_nuvoton: add tpm_check_status()
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit 8307176)
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Claudio Carvalho authored and stewartsmith committed Nov 29, 2016
1 parent 39d05f1 commit 52cf034
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions libstb/drivers/tpm_i2c_nuvoton.c
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 52cf034

Please sign in to comment.