Re: [U-Boot] [PATCH v2 22/28] dm: tpm: Convert I2C driver to driver model

2015-08-30 Thread Simon Glass
On 24 August 2015 at 14:22, Christophe Ricard
christophe.ric...@gmail.com wrote:
 Hi Simon,

 This one looks good to me.

 Acked-by: Christophe Ricardchristophe-h.ric...@st.com

Applied to u-boot-dm.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 22/28] dm: tpm: Convert I2C driver to driver model

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me.

Acked-by: Christophe Ricardchristophe-h.ric...@st.com

Best Regards
Christophe


On 23/08/2015 02:31, Simon Glass wrote:

Convert the tpm_tis_i2c driver to use driver model and update boards which
use it.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2:
- Update driver for v2 TPM uclass which supports timeouts

  configs/peach-pi_defconfig  |   1 +
  configs/peach-pit_defconfig |   1 +
  configs/snow_defconfig  |   1 +
  configs/spring_defconfig|   1 +
  drivers/tpm/tpm_tis_i2c.c   | 529 +---
  drivers/tpm/tpm_tis_i2c.h   |  20 +-
  include/fdtdec.h|   2 -
  lib/fdtdec.c|   2 -
  8 files changed, 207 insertions(+), 350 deletions(-)

diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index 2be74fd..6416f16 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -13,6 +13,7 @@ CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
  CONFIG_CROS_EC_SPI=y
  CONFIG_CROS_EC_KEYB=y
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_I2C=y
  CONFIG_DM_I2C=y
  CONFIG_DM_I2C_COMPAT=y
diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig
index 875ddd1..d0646ab 100644
--- a/configs/peach-pit_defconfig
+++ b/configs/peach-pit_defconfig
@@ -13,6 +13,7 @@ CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
  CONFIG_CROS_EC_SPI=y
  CONFIG_CROS_EC_KEYB=y
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_I2C=y
  CONFIG_DM_I2C=y
  CONFIG_DM_I2C_COMPAT=y
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index f59aa3f..7624ad2 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -18,6 +18,7 @@ CONFIG_DEBUG_UART=y
  CONFIG_DEBUG_UART_S5P=y
  CONFIG_DEBUG_UART_BASE=0x12c3
  CONFIG_DEBUG_UART_CLOCK=1
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_I2C=y
  CONFIG_DM_I2C=y
  CONFIG_DM_I2C_COMPAT=y
diff --git a/configs/spring_defconfig b/configs/spring_defconfig
index 6144f03..3b109fa 100644
--- a/configs/spring_defconfig
+++ b/configs/spring_defconfig
@@ -18,6 +18,7 @@ CONFIG_DEBUG_UART=y
  CONFIG_DEBUG_UART_S5P=y
  CONFIG_DEBUG_UART_BASE=0x12c3
  CONFIG_DEBUG_UART_CLOCK=1
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_I2C=y
  CONFIG_DM_I2C=y
  CONFIG_DM_I2C_COMPAT=y
diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_tis_i2c.c
index 645f702..9afe46c 100644
--- a/drivers/tpm/tpm_tis_i2c.c
+++ b/drivers/tpm/tpm_tis_i2c.c
@@ -23,11 +23,11 @@
  #include common.h
  #include dm.h
  #include fdtdec.h
-#include linux/compiler.h
  #include i2c.h
  #include tis.h
  #include tpm.h
  #include asm-generic/errno.h
+#include linux/compiler.h
  #include linux/types.h
  #include linux/unaligned/be_byteshift.h
  
@@ -42,8 +42,6 @@ static const char * const chip_name[] = {

[UNKNOWN] = unknown/fallback to slb9635,
  };
  
-static struct tpm_chip g_chip;

-
  /*
   * tpm_tis_i2c_read() - read from TPM register
   * @addr: register address to read from
@@ -58,22 +56,24 @@ static struct tpm_chip g_chip;
   *
   * Return -EIO on error, 0 on success.
   */
-static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
+static int tpm_tis_i2c_read(struct udevice *dev, u8 addr, u8 *buffer,
+   size_t len)
  {
+   struct tpm_chip *chip = dev_get_priv(dev);
int rc;
int count;
uint32_t addrbuf = addr;
  
-	if ((g_chip.chip_type == SLB9635) || (g_chip.chip_type == UNKNOWN)) {

+   if ((chip-chip_type == SLB9635) || (chip-chip_type == UNKNOWN)) {
/* slb9635 protocol should work in both cases */
for (count = 0; count  MAX_COUNT; count++) {
-   rc = dm_i2c_write(g_chip.dev, 0, (uchar *)addrbuf, 1);
+   rc = dm_i2c_write(dev, 0, (uchar *)addrbuf, 1);
if (rc == 0)
break;  /* Success, break to skip sleep */
udelay(SLEEP_DURATION_US);
}
if (rc)
-   return -rc;
+   return rc;
  
  		/* After the TPM has successfully received the register address

 * it needs some time, thus we're sleeping here again, before
@@ -81,7 +81,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
 */
for (count = 0; count  MAX_COUNT; count++) {
udelay(SLEEP_DURATION_US);
-   rc = dm_i2c_read(g_chip.dev, 0, buffer, len);
+   rc = dm_i2c_read(dev, 0, buffer, len);
if (rc == 0)
break;  /* success, break to skip sleep */
}
@@ -94,7 +94,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
 * be safe on the safe side.
 */
for (count = 0; count  MAX_COUNT; count++) {
-   rc = dm_i2c_read(g_chip.dev, addr, buffer, len);
+   rc = dm_i2c_read(dev, addr, buffer, len);
 

[U-Boot] [PATCH v2 22/28] dm: tpm: Convert I2C driver to driver model

2015-08-22 Thread Simon Glass
Convert the tpm_tis_i2c driver to use driver model and update boards which
use it.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2:
- Update driver for v2 TPM uclass which supports timeouts

 configs/peach-pi_defconfig  |   1 +
 configs/peach-pit_defconfig |   1 +
 configs/snow_defconfig  |   1 +
 configs/spring_defconfig|   1 +
 drivers/tpm/tpm_tis_i2c.c   | 529 +---
 drivers/tpm/tpm_tis_i2c.h   |  20 +-
 include/fdtdec.h|   2 -
 lib/fdtdec.c|   2 -
 8 files changed, 207 insertions(+), 350 deletions(-)

diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index 2be74fd..6416f16 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -13,6 +13,7 @@ CONFIG_CMD_CROS_EC=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
+CONFIG_DM_TPM=y
 CONFIG_TPM_TIS_I2C=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig
index 875ddd1..d0646ab 100644
--- a/configs/peach-pit_defconfig
+++ b/configs/peach-pit_defconfig
@@ -13,6 +13,7 @@ CONFIG_CMD_CROS_EC=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
+CONFIG_DM_TPM=y
 CONFIG_TPM_TIS_I2C=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index f59aa3f..7624ad2 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -18,6 +18,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_DEBUG_UART_S5P=y
 CONFIG_DEBUG_UART_BASE=0x12c3
 CONFIG_DEBUG_UART_CLOCK=1
+CONFIG_DM_TPM=y
 CONFIG_TPM_TIS_I2C=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
diff --git a/configs/spring_defconfig b/configs/spring_defconfig
index 6144f03..3b109fa 100644
--- a/configs/spring_defconfig
+++ b/configs/spring_defconfig
@@ -18,6 +18,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_DEBUG_UART_S5P=y
 CONFIG_DEBUG_UART_BASE=0x12c3
 CONFIG_DEBUG_UART_CLOCK=1
+CONFIG_DM_TPM=y
 CONFIG_TPM_TIS_I2C=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_tis_i2c.c
index 645f702..9afe46c 100644
--- a/drivers/tpm/tpm_tis_i2c.c
+++ b/drivers/tpm/tpm_tis_i2c.c
@@ -23,11 +23,11 @@
 #include common.h
 #include dm.h
 #include fdtdec.h
-#include linux/compiler.h
 #include i2c.h
 #include tis.h
 #include tpm.h
 #include asm-generic/errno.h
+#include linux/compiler.h
 #include linux/types.h
 #include linux/unaligned/be_byteshift.h
 
@@ -42,8 +42,6 @@ static const char * const chip_name[] = {
[UNKNOWN] = unknown/fallback to slb9635,
 };
 
-static struct tpm_chip g_chip;
-
 /*
  * tpm_tis_i2c_read() - read from TPM register
  * @addr: register address to read from
@@ -58,22 +56,24 @@ static struct tpm_chip g_chip;
  *
  * Return -EIO on error, 0 on success.
  */
-static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
+static int tpm_tis_i2c_read(struct udevice *dev, u8 addr, u8 *buffer,
+   size_t len)
 {
+   struct tpm_chip *chip = dev_get_priv(dev);
int rc;
int count;
uint32_t addrbuf = addr;
 
-   if ((g_chip.chip_type == SLB9635) || (g_chip.chip_type == UNKNOWN)) {
+   if ((chip-chip_type == SLB9635) || (chip-chip_type == UNKNOWN)) {
/* slb9635 protocol should work in both cases */
for (count = 0; count  MAX_COUNT; count++) {
-   rc = dm_i2c_write(g_chip.dev, 0, (uchar *)addrbuf, 1);
+   rc = dm_i2c_write(dev, 0, (uchar *)addrbuf, 1);
if (rc == 0)
break;  /* Success, break to skip sleep */
udelay(SLEEP_DURATION_US);
}
if (rc)
-   return -rc;
+   return rc;
 
/* After the TPM has successfully received the register address
 * it needs some time, thus we're sleeping here again, before
@@ -81,7 +81,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
 */
for (count = 0; count  MAX_COUNT; count++) {
udelay(SLEEP_DURATION_US);
-   rc = dm_i2c_read(g_chip.dev, 0, buffer, len);
+   rc = dm_i2c_read(dev, 0, buffer, len);
if (rc == 0)
break;  /* success, break to skip sleep */
}
@@ -94,7 +94,7 @@ static int tpm_tis_i2c_read(u8 addr, u8 *buffer, size_t len)
 * be safe on the safe side.
 */
for (count = 0; count  MAX_COUNT; count++) {
-   rc = dm_i2c_read(g_chip.dev, addr, buffer, len);
+   rc = dm_i2c_read(dev, addr, buffer, len);
if (rc == 0)
break;  /* break here to skip sleep */
udelay(SLEEP_DURATION_US);
@@ -104,19 +104,31 @@ static int