tpm: tpm_tis_i2c: Tidy up delays
Use a _US suffix for microseconds and a _MS suffic for milliseconds. Move all timeouts and delays into one place. Use mdelay() instead of udelay() where appropriate. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Christophe Ricard <christophe-h.ricard@st.com> Reviewed-by: Heiko Schocher <hs@denx.de>
This commit is contained in:
parent
e56e20eb86
commit
42c8ec56c5
@ -68,7 +68,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
|
|||||||
rc = dm_i2c_write(g_chip.dev, 0, (uchar *)&addrbuf, 1);
|
rc = dm_i2c_write(g_chip.dev, 0, (uchar *)&addrbuf, 1);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
break; /* Success, break to skip sleep */
|
break; /* Success, break to skip sleep */
|
||||||
udelay(SLEEP_DURATION);
|
udelay(SLEEP_DURATION_US);
|
||||||
}
|
}
|
||||||
if (rc)
|
if (rc)
|
||||||
return -rc;
|
return -rc;
|
||||||
@ -78,7 +78,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
|
|||||||
* retrieving the data
|
* retrieving the data
|
||||||
*/
|
*/
|
||||||
for (count = 0; count < MAX_COUNT; count++) {
|
for (count = 0; count < MAX_COUNT; count++) {
|
||||||
udelay(SLEEP_DURATION);
|
udelay(SLEEP_DURATION_US);
|
||||||
rc = dm_i2c_read(g_chip.dev, 0, buffer, len);
|
rc = dm_i2c_read(g_chip.dev, 0, buffer, len);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
break; /* success, break to skip sleep */
|
break; /* success, break to skip sleep */
|
||||||
@ -95,12 +95,12 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
|
|||||||
rc = dm_i2c_read(g_chip.dev, addr, buffer, len);
|
rc = dm_i2c_read(g_chip.dev, addr, buffer, len);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
break; /* break here to skip sleep */
|
break; /* break here to skip sleep */
|
||||||
udelay(SLEEP_DURATION);
|
udelay(SLEEP_DURATION_US);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Take care of 'guard time' */
|
/* Take care of 'guard time' */
|
||||||
udelay(SLEEP_DURATION);
|
udelay(SLEEP_DURATION_US);
|
||||||
if (rc)
|
if (rc)
|
||||||
return -rc;
|
return -rc;
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int tpm_tis_i2c_write_generic(u8 addr, u8 *buffer, size_t len,
|
static int tpm_tis_i2c_write_generic(u8 addr, u8 *buffer, size_t len,
|
||||||
unsigned int sleep_time, u8 max_count)
|
unsigned int sleep_time_us, u8 max_count)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int count;
|
int count;
|
||||||
@ -117,11 +117,11 @@ static int tpm_tis_i2c_write_generic(u8 addr, u8 *buffer, size_t len,
|
|||||||
rc = dm_i2c_write(g_chip.dev, addr, buffer, len);
|
rc = dm_i2c_write(g_chip.dev, addr, buffer, len);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
break; /* Success, break to skip sleep */
|
break; /* Success, break to skip sleep */
|
||||||
udelay(sleep_time);
|
udelay(sleep_time_us);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* take care of 'guard time' */
|
/* take care of 'guard time' */
|
||||||
udelay(sleep_time);
|
udelay(sleep_time_us);
|
||||||
if (rc)
|
if (rc)
|
||||||
return -rc;
|
return -rc;
|
||||||
|
|
||||||
@ -146,8 +146,8 @@ static int tpm_tis_i2c_write_generic(u8 addr, u8 *buffer, size_t len,
|
|||||||
*/
|
*/
|
||||||
static int tpm_tis_i2c_write(u8 addr, u8 *buffer, size_t len)
|
static int tpm_tis_i2c_write(u8 addr, u8 *buffer, size_t len)
|
||||||
{
|
{
|
||||||
return tpm_tis_i2c_write_generic(addr, buffer, len, SLEEP_DURATION,
|
return tpm_tis_i2c_write_generic(addr, buffer, len, SLEEP_DURATION_US,
|
||||||
MAX_COUNT);
|
MAX_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -156,8 +156,9 @@ static int tpm_tis_i2c_write(u8 addr, u8 *buffer, size_t len)
|
|||||||
*/
|
*/
|
||||||
static int tpm_tis_i2c_write_long(u8 addr, u8 *buffer, size_t len)
|
static int tpm_tis_i2c_write_long(u8 addr, u8 *buffer, size_t len)
|
||||||
{
|
{
|
||||||
return tpm_tis_i2c_write_generic(addr, buffer, len, SLEEP_DURATION_LONG,
|
return tpm_tis_i2c_write_generic(addr, buffer, len,
|
||||||
MAX_COUNT_LONG);
|
SLEEP_DURATION_LONG_US,
|
||||||
|
MAX_COUNT_LONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tpm_tis_i2c_check_locality(struct tpm_chip *chip, int loc)
|
static int tpm_tis_i2c_check_locality(struct tpm_chip *chip, int loc)
|
||||||
@ -212,7 +213,7 @@ static int tpm_tis_i2c_request_locality(struct tpm_chip *chip, int loc)
|
|||||||
do {
|
do {
|
||||||
if (tpm_tis_i2c_check_locality(chip, loc) >= 0)
|
if (tpm_tis_i2c_check_locality(chip, loc) >= 0)
|
||||||
return loc;
|
return loc;
|
||||||
udelay(TPM_TIMEOUT * 1000);
|
mdelay(TPM_TIMEOUT_MS);
|
||||||
} while (get_timer(start) < stop);
|
} while (get_timer(start) < stop);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -262,7 +263,7 @@ static ssize_t tpm_tis_i2c_get_burstcount(struct tpm_chip *chip)
|
|||||||
|
|
||||||
if (burstcnt)
|
if (burstcnt)
|
||||||
return burstcnt;
|
return burstcnt;
|
||||||
udelay(TPM_TIMEOUT * 1000);
|
mdelay(TPM_TIMEOUT_MS);
|
||||||
} while (get_timer(start) < stop);
|
} while (get_timer(start) < stop);
|
||||||
|
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
@ -281,7 +282,7 @@ static int tpm_tis_i2c_wait_for_stat(struct tpm_chip *chip, u8 mask,
|
|||||||
start = get_timer(0);
|
start = get_timer(0);
|
||||||
stop = timeout;
|
stop = timeout;
|
||||||
do {
|
do {
|
||||||
udelay(TPM_TIMEOUT * 1000);
|
mdelay(TPM_TIMEOUT_MS);
|
||||||
*status = tpm_tis_i2c_status(chip);
|
*status = tpm_tis_i2c_status(chip);
|
||||||
if ((*status & mask) == mask)
|
if ((*status & mask) == mask)
|
||||||
return 0;
|
return 0;
|
||||||
@ -363,7 +364,7 @@ out:
|
|||||||
* The TPM needs some time to clean up here,
|
* The TPM needs some time to clean up here,
|
||||||
* so we sleep rather than keeping the bus busy
|
* so we sleep rather than keeping the bus busy
|
||||||
*/
|
*/
|
||||||
udelay(2000);
|
mdelay(2);
|
||||||
tpm_tis_i2c_release_locality(chip, chip->locality, 0);
|
tpm_tis_i2c_release_locality(chip, chip->locality, 0);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
@ -446,7 +447,7 @@ out_err:
|
|||||||
* The TPM needs some time to clean up here,
|
* The TPM needs some time to clean up here,
|
||||||
* so we sleep rather than keeping the bus busy
|
* so we sleep rather than keeping the bus busy
|
||||||
*/
|
*/
|
||||||
udelay(2000);
|
mdelay(2);
|
||||||
tpm_tis_i2c_release_locality(chip, chip->locality, 0);
|
tpm_tis_i2c_release_locality(chip, chip->locality, 0);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -480,10 +481,10 @@ static int tpm_tis_i2c_init(struct udevice *dev)
|
|||||||
chip->irq = 0;
|
chip->irq = 0;
|
||||||
|
|
||||||
/* Default timeouts - these could move to the device tree */
|
/* Default timeouts - these could move to the device tree */
|
||||||
chip->timeout_a = TIS_SHORT_TIMEOUT;
|
chip->timeout_a = TIS_SHORT_TIMEOUT_MS;
|
||||||
chip->timeout_b = TIS_LONG_TIMEOUT;
|
chip->timeout_b = TIS_LONG_TIMEOUT_MS;
|
||||||
chip->timeout_c = TIS_SHORT_TIMEOUT;
|
chip->timeout_c = TIS_SHORT_TIMEOUT_MS;
|
||||||
chip->timeout_d = TIS_SHORT_TIMEOUT;
|
chip->timeout_d = TIS_SHORT_TIMEOUT_MS;
|
||||||
chip->req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID;
|
chip->req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID;
|
||||||
chip->req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID;
|
chip->req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID;
|
||||||
chip->req_canceled = TPM_STS_COMMAND_READY;
|
chip->req_canceled = TPM_STS_COMMAND_READY;
|
||||||
@ -593,7 +594,7 @@ static ssize_t tpm_tis_i2c_transmit(const unsigned char *buf, size_t bufsiz)
|
|||||||
rc = -ECANCELED;
|
rc = -ECANCELED;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
udelay(TPM_TIMEOUT * 1000);
|
mdelay(TPM_TIMEOUT_MS);
|
||||||
} while (get_timer(start) < stop);
|
} while (get_timer(start) < stop);
|
||||||
|
|
||||||
tpm_tis_i2c_ready(chip);
|
tpm_tis_i2c_ready(chip);
|
||||||
|
@ -23,7 +23,11 @@
|
|||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
|
||||||
enum tpm_timeout {
|
enum tpm_timeout {
|
||||||
TPM_TIMEOUT = 5, /* msecs */
|
TPM_TIMEOUT_MS = 5,
|
||||||
|
TIS_SHORT_TIMEOUT_MS = 750,
|
||||||
|
TIS_LONG_TIMEOUT_MS = 2000,
|
||||||
|
SLEEP_DURATION_US = 60,
|
||||||
|
SLEEP_DURATION_LONG_US = 210,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Size of external transmit buffer (used in tpm_transmit)*/
|
/* Size of external transmit buffer (used in tpm_transmit)*/
|
||||||
@ -125,9 +129,6 @@ struct tpm_cmd_t {
|
|||||||
*/
|
*/
|
||||||
#define MAX_COUNT_LONG 50
|
#define MAX_COUNT_LONG 50
|
||||||
|
|
||||||
#define SLEEP_DURATION 60 /* in usec */
|
|
||||||
#define SLEEP_DURATION_LONG 210 /* in usec */
|
|
||||||
|
|
||||||
#define TPM_HEADER_SIZE 10
|
#define TPM_HEADER_SIZE 10
|
||||||
|
|
||||||
enum tis_access {
|
enum tis_access {
|
||||||
@ -145,11 +146,6 @@ enum tis_status {
|
|||||||
TPM_STS_DATA_EXPECT = 0x08,
|
TPM_STS_DATA_EXPECT = 0x08,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum tis_defaults {
|
|
||||||
TIS_SHORT_TIMEOUT = 750, /* ms */
|
|
||||||
TIS_LONG_TIMEOUT = 2000, /* ms */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* expected value for DIDVID register */
|
/* expected value for DIDVID register */
|
||||||
#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
|
#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
|
||||||
#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
|
#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
|
||||||
@ -169,7 +165,7 @@ enum tpm_duration {
|
|||||||
/* Extended error numbers from linux (see errno.h) */
|
/* Extended error numbers from linux (see errno.h) */
|
||||||
#define ECANCELED 125 /* Operation Canceled */
|
#define ECANCELED 125 /* Operation Canceled */
|
||||||
|
|
||||||
/* Timer frequency. Corresponds to msec timer resolution*/
|
/* Timer frequency. Corresponds to msec timer resolution */
|
||||||
#define HZ 1000
|
#define HZ 1000
|
||||||
|
|
||||||
#define TPM_MAX_ORDINAL 243
|
#define TPM_MAX_ORDINAL 243
|
||||||
|
Loading…
Reference in New Issue
Block a user