Back when the TPM subsystem was refactored tpm_tis_wait_init() ended up

being called after tpm_tis_init() which initializes values the former needs.
 
 Since we added more TPM chipsets since then sitting on an i2c bus, this patch
 folds in tpm_tis_wait_init into tpm_tis_init and makes sure it's called in the
 right order regardless of the bus the TPM sits on.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEgWII69YpahbL5iK5gS8AYozs+qIFAma18twACgkQgS8AYozs
 +qKUxQ/+N15BctMTOVyrZ/wtYMle/ulox/drtrNKmDtSxKtaz1prfk/b1Z9YX9jD
 oXU6DBku6gsSLwQlUOPQoOkWIeKxta5v8GLIn1BgMP12GCLLf+0stZ0haYPpig0p
 zZCyLFQIa82on655xopIc9MdRW3s0m3AlepoPcjh5LoK/IauodQntBknrc2H93El
 AArwDIMhTV0D5zevbUQpVr98G2GsSsJ9P44YTG97+s7mjFq/2/qqNL2N692UvAlm
 B54FhgnqDzamSGpZsLGTQCDpwDm6WXVErA4Ta4Zd3FnTAMOGivB0+WxBR1fi/RSr
 mcm0Rq+OMCLvzHZJITpe21R9xadmZ4pdOlPRLeiAw90htJ65981j+mdXW7XI/ZEc
 fcGDyUS8+RrO+u+5T2AxhTcuJ4HcH9/vbn/ADyrcZ3wR89bRqAOj71v7utDL2JT1
 OSYYGfWLJYQ850HMdap6zv4Fh0FBuZ1dnp3Z/GDfiLQgDYLD+oO/CY/R72al+U65
 HjaAzSp3SbBDbEjRmlyopa0Vc5jGzPN7jXPuA/0YN20gLxcb819NnhbGmxTplaHp
 38LFlheflYLXizGpK0Lq9a4D3fCgFE7gSM7RTBB/G6cN+ADz49SLPkLYKv8O5fRl
 X/f991nrDw+pBtSECa3TdtoVnY9TZdPNHUkuAfSgKqoC9l/OW/k=
 =aq79
 -----END PGP SIGNATURE-----

Merge tag 'tpm-master-09082024' of https://source.denx.de/u-boot/custodians/u-boot-tpm.git

Back when the TPM subsystem was refactored tpm_tis_wait_init() ended up
being called after tpm_tis_init() which initializes values the former needs.

Since we added more TPM chipsets since then sitting on an i2c bus, this patch
folds in tpm_tis_wait_init into tpm_tis_init and makes sure it's called in the
right order regardless of the bus the TPM sits on.
This commit is contained in:
Tom Rini 2024-08-09 14:00:04 -06:00
commit 7bd2559cb3
2 changed files with 28 additions and 30 deletions

View File

@ -419,6 +419,28 @@ static bool tis_check_ops(struct tpm_tis_phy_ops *phy_ops)
return true;
}
static int tpm_tis_wait_init(struct udevice *dev, int loc)
{
struct tpm_chip *chip = dev_get_priv(dev);
unsigned long start, stop;
u8 status;
int ret;
start = get_timer(0);
stop = chip->timeout_b;
do {
mdelay(TPM_TIMEOUT_MS);
ret = chip->phy_ops->read_bytes(dev, TPM_ACCESS(loc), 1, &status);
if (ret)
break;
if (status & TPM_ACCESS_VALID)
return 0;
} while (get_timer(start) < stop);
return -EIO;
}
int tpm_tis_init(struct udevice *dev)
{
struct tpm_chip *chip = dev_get_priv(dev);
@ -436,6 +458,12 @@ int tpm_tis_init(struct udevice *dev)
chip->timeout_c = TIS_SHORT_TIMEOUT_MS;
chip->timeout_d = TIS_SHORT_TIMEOUT_MS;
ret = tpm_tis_wait_init(dev, chip->locality);
if (ret) {
log(LOGC_DM, LOGL_ERR, "%s: no device found\n", __func__);
return ret;
}
ret = tpm_tis_request_locality(dev, 0);
if (ret)
return ret;

View File

@ -187,29 +187,6 @@ static int tpm_tis_spi_write32(struct udevice *dev, u32 addr, u32 value)
return tpm_tis_spi_write(dev, addr, sizeof(value), (u8 *)&value_le);
}
static int tpm_tis_wait_init(struct udevice *dev, int loc)
{
struct tpm_chip *chip = dev_get_priv(dev);
unsigned long start, stop;
u8 status;
int ret;
start = get_timer(0);
stop = chip->timeout_b;
do {
mdelay(TPM_TIMEOUT_MS);
ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), 1, &status);
if (ret)
break;
if (status & TPM_ACCESS_VALID)
return 0;
} while (get_timer(start) < stop);
return -EIO;
}
static struct tpm_tis_phy_ops phy_ops = {
.read_bytes = tpm_tis_spi_read,
.write_bytes = tpm_tis_spi_write,
@ -221,7 +198,6 @@ static int tpm_tis_spi_probe(struct udevice *dev)
{
struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
struct tpm_chip *chip = dev_get_priv(dev);
int ret;
/* Use the TPM v2 stack */
@ -255,12 +231,6 @@ static int tpm_tis_spi_probe(struct udevice *dev)
/* Ensure a minimum amount of time elapsed since reset of the TPM */
mdelay(drv_data->time_before_first_cmd_ms);
ret = tpm_tis_wait_init(dev, chip->locality);
if (ret) {
log(LOGC_DM, LOGL_ERR, "%s: no device found\n", __func__);
return ret;
}
tpm_tis_ops_register(dev, &phy_ops);
ret = tpm_tis_init(dev);
if (ret)