All of lore.kernel.org
 help / color / mirror / Atom feed
From: christophe.ricard <christophe.ricard@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 14/25] tpm: tpm_tis_i2c: Tidy up delays
Date: Tue, 11 Aug 2015 23:44:17 +0200	[thread overview]
Message-ID: <55CA6CB1.3060109@gmail.com> (raw)
In-Reply-To: <1439304497-10081-15-git-send-email-sjg@chromium.org>

Hi Simon,

Acked-by: Christophe Ricard <christophe-h.ricard@st.com>

Best Regards
Christophe

On 11/08/2015 16:48, Simon Glass wrote:
> 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>
> ---
>
>   drivers/tpm/tpm_tis_i2c.c | 43 ++++++++++++++++++++++---------------------
>   drivers/tpm/tpm_tis_i2c.h | 16 ++++++----------
>   2 files changed, 28 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_tis_i2c.c
> index f3d615c..f1ad596 100644
> --- a/drivers/tpm/tpm_tis_i2c.c
> +++ b/drivers/tpm/tpm_tis_i2c.c
> @@ -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);
>   			if (rc == 0)
>   				break;  /* Success, break to skip sleep */
> -			udelay(SLEEP_DURATION);
> +			udelay(SLEEP_DURATION_US);
>   		}
>   		if (rc)
>   			return -rc;
> @@ -78,7 +78,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
>   		 * retrieving the data
>   		 */
>   		for (count = 0; count < MAX_COUNT; count++) {
> -			udelay(SLEEP_DURATION);
> +			udelay(SLEEP_DURATION_US);
>   			rc = dm_i2c_read(g_chip.dev, 0, buffer, len);
>   			if (rc == 0)
>   				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);
>   			if (rc == 0)
>   				break;  /* break here to skip sleep */
> -			udelay(SLEEP_DURATION);
> +			udelay(SLEEP_DURATION_US);
>   		}
>   	}
>   
>   	/* Take care of 'guard time' */
> -	udelay(SLEEP_DURATION);
> +	udelay(SLEEP_DURATION_US);
>   	if (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,
> -				     unsigned int sleep_time, u8 max_count)
> +				     unsigned int sleep_time_us, u8 max_count)
>   {
>   	int rc = 0;
>   	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);
>   		if (rc == 0)
>   			break;  /* Success, break to skip sleep */
> -		udelay(sleep_time);
> +		udelay(sleep_time_us);
>   	}
>   
>   	/* take care of 'guard time' */
> -	udelay(sleep_time);
> +	udelay(sleep_time_us);
>   	if (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)
>   {
> -	return tpm_tis_i2c_write_generic(addr, buffer, len, SLEEP_DURATION,
> -			MAX_COUNT);
> +	return tpm_tis_i2c_write_generic(addr, buffer, len, SLEEP_DURATION_US,
> +					 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)
>   {
> -	return tpm_tis_i2c_write_generic(addr, buffer, len, SLEEP_DURATION_LONG,
> -			MAX_COUNT_LONG);
> +	return tpm_tis_i2c_write_generic(addr, buffer, len,
> +					 SLEEP_DURATION_LONG_US,
> +					 MAX_COUNT_LONG);
>   }
>   
>   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 {
>   		if (tpm_tis_i2c_check_locality(chip, loc) >= 0)
>   			return loc;
> -		udelay(TPM_TIMEOUT * 1000);
> +		mdelay(TPM_TIMEOUT_MS);
>   	} while (get_timer(start) < stop);
>   
>   	return -1;
> @@ -262,7 +263,7 @@ static ssize_t tpm_tis_i2c_get_burstcount(struct tpm_chip *chip)
>   
>   		if (burstcnt)
>   			return burstcnt;
> -		udelay(TPM_TIMEOUT * 1000);
> +		mdelay(TPM_TIMEOUT_MS);
>   	} while (get_timer(start) < stop);
>   
>   	return -EBUSY;
> @@ -281,7 +282,7 @@ static int tpm_tis_i2c_wait_for_stat(struct tpm_chip *chip, u8 mask,
>   	start = get_timer(0);
>   	stop = timeout;
>   	do {
> -		udelay(TPM_TIMEOUT * 1000);
> +		mdelay(TPM_TIMEOUT_MS);
>   		*status = tpm_tis_i2c_status(chip);
>   		if ((*status & mask) == mask)
>   			return 0;
> @@ -363,7 +364,7 @@ out:
>   	 * The TPM needs some time to clean up here,
>   	 * so we sleep rather than keeping the bus busy
>   	 */
> -	udelay(2000);
> +	mdelay(2);
>   	tpm_tis_i2c_release_locality(chip, chip->locality, 0);
>   
>   	return size;
> @@ -446,7 +447,7 @@ out_err:
>   	 * The TPM needs some time to clean up here,
>   	 * so we sleep rather than keeping the bus busy
>   	 */
> -	udelay(2000);
> +	mdelay(2);
>   	tpm_tis_i2c_release_locality(chip, chip->locality, 0);
>   
>   	return rc;
> @@ -480,10 +481,10 @@ static int tpm_tis_i2c_init(struct udevice *dev)
>   	chip->irq = 0;
>   
>   	/* Default timeouts - these could move to the device tree */
> -	chip->timeout_a = TIS_SHORT_TIMEOUT;
> -	chip->timeout_b = TIS_LONG_TIMEOUT;
> -	chip->timeout_c = TIS_SHORT_TIMEOUT;
> -	chip->timeout_d = TIS_SHORT_TIMEOUT;
> +	chip->timeout_a = TIS_SHORT_TIMEOUT_MS;
> +	chip->timeout_b = TIS_LONG_TIMEOUT_MS;
> +	chip->timeout_c = TIS_SHORT_TIMEOUT_MS;
> +	chip->timeout_d = TIS_SHORT_TIMEOUT_MS;
>   	chip->req_complete_mask = 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;
> @@ -593,7 +594,7 @@ static ssize_t tpm_tis_i2c_transmit(const unsigned char *buf, size_t bufsiz)
>   			rc = -ECANCELED;
>   			goto out;
>   		}
> -		udelay(TPM_TIMEOUT * 1000);
> +		mdelay(TPM_TIMEOUT_MS);
>   	} while (get_timer(start) < stop);
>   
>   	tpm_tis_i2c_ready(chip);
> diff --git a/drivers/tpm/tpm_tis_i2c.h b/drivers/tpm/tpm_tis_i2c.h
> index db99200..ecdaf0c 100644
> --- a/drivers/tpm/tpm_tis_i2c.h
> +++ b/drivers/tpm/tpm_tis_i2c.h
> @@ -23,7 +23,11 @@
>   #include <linux/types.h>
>   
>   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)*/
> @@ -125,9 +129,6 @@ struct tpm_cmd_t {
>    */
>   #define MAX_COUNT_LONG		50
>   
> -#define SLEEP_DURATION		60	/* in usec */
> -#define SLEEP_DURATION_LONG	210	/* in usec */
> -
>   #define TPM_HEADER_SIZE		10
>   
>   enum tis_access {
> @@ -145,11 +146,6 @@ enum tis_status {
>   	TPM_STS_DATA_EXPECT		= 0x08,
>   };
>   
> -enum tis_defaults {
> -	TIS_SHORT_TIMEOUT		= 750,	/* ms */
> -	TIS_LONG_TIMEOUT		= 2000,	/* ms */
> -};
> -
>   /* expected value for DIDVID register */
>   #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
>   #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
> @@ -169,7 +165,7 @@ enum tpm_duration {
>   /* Extended error numbers from linux (see errno.h) */
>   #define ECANCELED	125	/* Operation Canceled */
>   
> -/* Timer frequency. Corresponds to msec timer resolution*/
> +/* Timer frequency. Corresponds to msec timer resolution */
>   #define HZ		1000
>   
>   #define TPM_MAX_ORDINAL			243

  reply	other threads:[~2015-08-11 21:44 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11 14:47 [U-Boot] [PATCH 00/25] dm: Convert TPM drivers to driver model Simon Glass
2015-08-11 14:47 ` [U-Boot] [PATCH 01/25] tpm: Remove old pre-driver-model I2C code Simon Glass
2015-08-11 21:41   ` christophe.ricard
2015-08-13  1:30     ` Simon Glass
2015-08-11 14:47 ` [U-Boot] [PATCH 02/25] tpm: Drop two unused options Simon Glass
2015-08-11 21:44   ` christophe.ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 03/25] tpm: Add Kconfig options for TPMs Simon Glass
2015-08-11 21:45   ` christophe.ricard
2015-08-13  1:30     ` Simon Glass
2015-08-11 14:47 ` [U-Boot] [PATCH 04/25] tpm: Convert board config TPM options to Kconfig Simon Glass
2015-08-11 21:45   ` christophe.ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 05/25] tpm: Convert drivers to use SPDX Simon Glass
2015-08-11 21:41   ` christophe.ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 06/25] tpm: Move the I2C TPM code into one file Simon Glass
2015-08-11 21:42   ` christophe.ricard
2015-08-13  1:30     ` Simon Glass
2015-08-13 20:26       ` Christophe Ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 07/25] tpm: tpm_tis_i2c: Drop unnecessary methods Simon Glass
2015-08-11 21:47   ` christophe.ricard
2015-08-13  1:30     ` Simon Glass
2015-08-13 20:28       ` Christophe Ricard
2015-08-13 22:53         ` Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 08/25] tpm: tpm_tis_i2c: Drop struct tpm_vendor_specific Simon Glass
2015-08-11 21:47   ` christophe.ricard
2015-08-13  1:30     ` Simon Glass
2015-08-13 20:32       ` Christophe Ricard
2015-08-13 22:53         ` Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 09/25] tpm: tpm_tis_i2c: Merge struct tpm_dev into tpm_chip Simon Glass
2015-08-11 21:46   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 10/25] tpm: tpm_tis_i2c: Merge struct tpm " Simon Glass
2015-08-11 21:46   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 11/25] tpm: tpm_tis_i2c: Move definitions into the header file Simon Glass
2015-08-11 21:45   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 12/25] tpm: tpm_tis_i2c: Simplify init code Simon Glass
2015-08-11 21:45   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 13/25] tpm: tpm_tis_i2c: Use a consistent tpm_tis_i2c_ prefix Simon Glass
2015-08-11 21:44   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 14/25] tpm: tpm_tis_i2c: Tidy up delays Simon Glass
2015-08-11 21:44   ` christophe.ricard [this message]
2015-08-11 14:48 ` [U-Boot] [PATCH 15/25] dm: tpm: Add a uclass for Trusted Platform Modules Simon Glass
2015-08-11 21:44   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 16/25] dm: tpm: Convert the TPM command and library to driver model Simon Glass
2015-08-11 21:43   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 17/25] dm: i2c: Add a command to adjust the offset length Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 18/25] tpm: Report tpm errors on the command line Simon Glass
2015-08-11 21:43   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 19/25] dm: tpm: sandbox: Convert TPM driver to driver model Simon Glass
2015-08-11 21:42   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 20/25] tpm: Check that parse_byte_string() has data to parse Simon Glass
2015-08-11 21:42   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 21/25] exynos: x86: dts: Add tpm nodes to the device tree for Chrome OS devices Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 22/25] dm: tpm: Convert I2C driver to driver model Simon Glass
2015-08-11 21:41   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 23/25] dm: tpm: Convert LPC " Simon Glass
2015-08-11 21:41   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 24/25] tpm: Add a 'tpm info' command Simon Glass
2015-08-11 21:40   ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 25/25] tegra: nyan: Enable TPM command and driver Simon Glass
2015-08-11 21:40   ` christophe.ricard
2015-08-11 21:50 ` [U-Boot] [PATCH 00/25] dm: Convert TPM drivers to driver model christophe.ricard
2015-08-13  1:30   ` Simon Glass
2015-08-13 20:22     ` Christophe Ricard
2015-08-13 22:52       ` Simon Glass
2015-08-20 21:39         ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55CA6CB1.3060109@gmail.com \
    --to=christophe.ricard@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.