diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c index e993fd9f83..30194bce07 100644 --- a/drivers/tpm/tpm_tis_lpc.c +++ b/drivers/tpm/tpm_tis_lpc.c @@ -388,31 +388,6 @@ static int tis_readresponse(struct udevice *dev, u8 *buffer, size_t len) return offset; } -static int tpm_tis_lpc_open(struct udevice *dev) -{ - struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); - struct tpm_locality *regs = priv->regs; - u8 locality = 0; /* we use locality zero for everything. */ - int ret; - - /* now request access to locality. */ - tpm_write_word(priv, TIS_ACCESS_REQUEST_USE, ®s[locality].access); - - /* did we get a lock? */ - ret = tis_wait_reg(priv, ®s[locality].access, - TIS_ACCESS_ACTIVE_LOCALITY, - TIS_ACCESS_ACTIVE_LOCALITY); - if (ret == -ETIMEDOUT) { - printf("%s:%d - failed to lock locality %d\n", - __FILE__, __LINE__, locality); - return ret; - } - - 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); @@ -434,6 +409,38 @@ static int tpm_tis_lpc_close(struct udevice *dev) return 0; } +static int tpm_tis_lpc_open(struct udevice *dev) +{ + struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); + struct tpm_locality *regs = priv->regs; + 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); + + /* did we get a lock? */ + ret = tis_wait_reg(priv, ®s[locality].access, + TIS_ACCESS_ACTIVE_LOCALITY, + TIS_ACCESS_ACTIVE_LOCALITY); + if (ret == -ETIMEDOUT) { + printf("%s:%d - failed to lock locality %d\n", + __FILE__, __LINE__, locality); + return ret; + } + + tpm_write_word(priv, TIS_STS_COMMAND_READY, + ®s[locality].tpm_status); + + return 0; +} + static int tpm_tis_get_desc(struct udevice *dev, char *buf, int size) { ulong chip_type = dev_get_driver_data(dev); diff --git a/include/tpm-common.h b/include/tpm-common.h index 449ad4c96e..f8c5569003 100644 --- a/include/tpm-common.h +++ b/include/tpm-common.h @@ -181,6 +181,24 @@ int do_##cmd(cmd_tbl_t *cmdtp, int flag, \ return report_return_code(cmd()); \ } +/** + * tpm_open() - Request access to locality 0 for the caller + * + * After all commands have been completed the caller is supposed to + * call tpm_close(). + * + * Returns 0 on success, -ve on failure. + */ +int tpm_open(struct udevice *dev); + +/** + * tpm_close() - Close the current session + * + * Releasing the locked locality. Returns 0 on success, -ve 1 on + * failure (in case lock removal did not succeed). + */ +int tpm_close(struct udevice *dev); + /** * tpm_get_desc() - Get a text description of the TPM * diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h index a9cb7dc7ee..ac95f262f5 100644 --- a/lib/tpm-utils.h +++ b/lib/tpm-utils.h @@ -18,24 +18,6 @@ #define tpm_u16(x) __MSB(x), __LSB(x) #define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF) -/** - * tpm_open() - Request access to locality 0 for the caller - * - * After all commands have been completed the caller is supposed to - * call tpm_close(). - * - * Returns 0 on success, -ve on failure. - */ -int tpm_open(struct udevice *dev); - -/** - * tpm_close() - Close the current session - * - * Releasing the locked locality. Returns 0 on success, -ve 1 on - * failure (in case lock removal did not succeed). - */ -int tpm_close(struct udevice *dev); - /** * Pack data into a byte string. The data types are specified in * the format string: 'b' means unsigned byte, 'w' unsigned word,