diff options
Diffstat (limited to 'drivers/tpm/tpm_tis_lpc.c')
-rw-r--r-- | drivers/tpm/tpm_tis_lpc.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c index e993fd9f833..30194bce078 100644 --- a/drivers/tpm/tpm_tis_lpc.c +++ b/drivers/tpm/tpm_tis_lpc.c @@ -388,6 +388,27 @@ static int tis_readresponse(struct udevice *dev, u8 *buffer, size_t len) return offset; } +static int tpm_tis_lpc_close(struct udevice *dev) +{ + struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); + struct tpm_locality *regs = priv->regs; + u8 locality = 0; + + if (tpm_read_word(priv, ®s[locality].access) & + TIS_ACCESS_ACTIVE_LOCALITY) { + tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY, + ®s[locality].access); + + if (tis_wait_reg(priv, ®s[locality].access, + TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) { + printf("%s:%d - failed to release locality %d\n", + __FILE__, __LINE__, locality); + return -ETIMEDOUT; + } + } + return 0; +} + static int tpm_tis_lpc_open(struct udevice *dev) { struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); @@ -395,6 +416,12 @@ static int tpm_tis_lpc_open(struct udevice *dev) u8 locality = 0; /* we use locality zero for everything. */ int ret; + ret = tpm_tis_lpc_close(dev); + if (ret) { + printf("%s: Failed to close TPM\n", __func__); + return ret; + } + /* now request access to locality. */ tpm_write_word(priv, TIS_ACCESS_REQUEST_USE, ®s[locality].access); @@ -410,27 +437,7 @@ static int tpm_tis_lpc_open(struct udevice *dev) tpm_write_word(priv, TIS_STS_COMMAND_READY, ®s[locality].tpm_status); - return 0; -} - -static int tpm_tis_lpc_close(struct udevice *dev) -{ - struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); - struct tpm_locality *regs = priv->regs; - u8 locality = 0; - - if (tpm_read_word(priv, ®s[locality].access) & - TIS_ACCESS_ACTIVE_LOCALITY) { - tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY, - ®s[locality].access); - if (tis_wait_reg(priv, ®s[locality].access, - TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) { - printf("%s:%d - failed to release locality %d\n", - __FILE__, __LINE__, locality); - return -ETIMEDOUT; - } - } return 0; } |