Re: [U-Boot] [PATCH v2] dm: tpm: Drop CONFIG_DM_TPM

2015-10-04 Thread Christophe Ricard

Hi Simon,

Acked-by: Christophe Ricard

Best Regards
Christophe

On 03/10/2015 14:39, Simon Glass wrote:

Now that all TPM drivers use driver model, we can drop the special driver
model CONFIG option.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Fix missing 'depends on DM' left out of the v1 patch

  drivers/tpm/Kconfig  | 15 +++
  drivers/tpm/Makefile |  2 +-
  lib/Kconfig  |  1 +
  3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 3ab652c..31b35f7 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -4,15 +4,6 @@
  
  menu "TPM support"
  
-config DM_TPM

-   bool "Enable driver model for Trusted Platform Module drivers"
-   depends on DM && TPM
-   help
-  Enable driver model for TPMs. The TIS interface (tis_open(),
- tis_sendrecv(), etc.) is then implemented by the TPM uclass. Note
- that even with driver model only a single TPM is currently
- supported, since the tpm library assumes this.
-
  config TPM_TIS_SANDBOX
bool "Enable sandbox TPM driver"
depends on SANDBOX
@@ -24,7 +15,7 @@ config TPM_TIS_SANDBOX
  
  config TPM_ATMEL_TWI

bool "Enable Atmel TWI TPM device driver"
-   depends on DM_TPM && DM_I2C
+   depends on TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -33,7 +24,7 @@ config TPM_ATMEL_TWI
  
  config TPM_TIS_INFINEON

bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
-   depends on DM_TPM && DM_I2C
+   depends on TPM && DM_I2C
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -57,7 +48,7 @@ config TPM_TIS_I2C_BURST_LIMITATION_LEN
  
  config TPM_TIS_LPC

bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
-   depends on DM_TPM && X86
+   depends on TPM && X86
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 5748145..1d49e95 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -3,7 +3,7 @@
  # SPDX-License-Identifier:GPL-2.0+
  #
  
-obj-$(CONFIG_DM_TPM) += tpm-uclass.o

+obj-$(CONFIG_TPM) += tpm-uclass.o
  
  obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o

  obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
diff --git a/lib/Kconfig b/lib/Kconfig
index 0673072..70ed20d 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -56,6 +56,7 @@ source lib/rsa/Kconfig
  
  config TPM

bool "Trusted Platform Module (TPM) Support"
+   depends on DM
help
  This enables support for TPMs which can be used to provide security
  features for your board. The TPM can be connected via LPC or I2C


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


Re: [U-Boot] [PATCH v3 2/4] dm: tpm: Add Driver Model support for tpm_atmel_twi driver

2015-10-06 Thread Christophe Ricard
Hi Simon,

This error is coming from the fact that no driver model is available for
powerpc and the config file mention in the error log
(controlcenterd_36BIT_SDCARD, controlcenterd_36BIT_SDCARD_DEVELOP,
controlcenterd_TRAILBLAZER, controlcenterd_TRAILBLAZER_DEVELOP).

Do you think converting atmel driver to dm_tpm without dm_i2c dependency is
acceptable as a first step ? It would help to clean the TPM driver model.

Do you think it make sense to convert powerpc i2c driver to i2c_dm ?

Best Regards
Christophe

2015-10-04 18:25 GMT+02:00 Simon Glass :

> Hi Christophe,
>
> On 3 October 2015 at 15:27, Simon Glass  wrote:
> > On 20 September 2015 at 21:00, Christophe Ricard
> >  wrote:
> >> tpm_atmel_twi can fit perfectly to the new UCLASS_TPM class.
> >>
> >> Signed-off-by: Christophe Ricard 
> >> Reviewed-by: Tom Rini 
> >> ---
> >>
> >> Changes in v3: None
> >>
> >>  drivers/tpm/Kconfig |  2 +-
> >>  drivers/tpm/tpm_atmel_twi.c | 74
> -
> >>  2 files changed, 54 insertions(+), 22 deletions(-)
> >
> > Acked-by: Simon Glass 
>
> I get errors with this patch:
>
> 03: dm: tpm: Add Driver Model support for tpm_atmel_twi driver
>powerpc:  +   controlcenterd_36BIT_SDCARD
> controlcenterd_36BIT_SDCARD_DEVELOP controlcenterd_TRAILBLAZER
> controlcenterd_TRAILBLAZER_DEVELOP
> +common/built-in.o: In function `do_tpm_raw_transfer':
> +build/../common/cmd_tpm.c:504: undefined reference to `tis_sendrecv'
> +lib/built-in.o: In function `tpm_sendrecv_command':
> +build/../lib/tpm.c:253: undefined reference to `tis_sendrecv'
> +lib/built-in.o: In function `tpm_init':
> +build/../lib/tpm.c:276: undefined reference to `tis_init'
> +build/../lib/tpm.c:280: undefined reference to `tis_open'
>
> Regards,
> Simon
>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v4 4/4] dm: tpm: Every TPM drivers should depends on DM_TPM

2015-10-06 Thread Christophe Ricard
Every TPM drivers should now depends on DM_TPM and not only TPM.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/tpm/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index ff2cdbe..3ab652c 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
 
 config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
-   depends on TPM && DM_I2C
+   depends on DM_TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -33,7 +33,7 @@ config TPM_ATMEL_TWI
 
 config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
-   depends on TPM && DM_I2C
+   depends on DM_TPM && DM_I2C
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -57,7 +57,7 @@ config TPM_TIS_I2C_BURST_LIMITATION_LEN
 
 config TPM_TIS_LPC
bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
-   depends on TPM && X86
+   depends on DM_TPM && X86
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
-- 
2.1.4

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


[U-Boot] [PATCH v4 0/4] Move tpm_tis_i2c to tpm_tis_infineon and convert last tpm driver to use DM_TPM

2015-10-06 Thread Christophe Ricard
Hi Simon,

This patch serie move tpm_tis_i2c driver to tpm_tis_infineon.
It also convert the latest tpm driver tpm_atmel_twi to DM_TPM.

In v4, i am fixing compilation errors you reported on patch 2 and 3.
On patch 2 i chose to convert tpm_atmel_twi to DM_TPM without using DM_I2C
as a first step to complete the core DM_TPM conversion.
Hope this approach is acceptable.

Best Regards
Christophe

Changes in v4:
- Fix compilation issues reported by Simon Glass on
- patch 2: dm: tpm: Add Driver Model support for tpm_atmel_twi driver
- patch 3: dm: tpm: Remove every compilation switch for TPM driver model

Changes in v3:
- Adding mention to Tom Rini review

Changes in v2:
- Change existing users of config to use renamed Kconfig

Christophe Ricard (4):
  dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon
  dm: tpm: Add Driver Model support for tpm_atmel_twi driver
  dm: tpm: Remove every compilation switch for TPM driver model
  dm: tpm: Every TPM drivers should depends on DM_TPM

 README |  4 +-
 common/cmd_tpm.c   | 13 +
 .../controlcenterd_36BIT_SDCARD_DEVELOP_defconfig  |  2 +
 configs/controlcenterd_36BIT_SDCARD_defconfig  |  2 +
 .../controlcenterd_TRAILBLAZER_DEVELOP_defconfig   |  2 +
 configs/controlcenterd_TRAILBLAZER_defconfig   |  2 +
 configs/nyan-big_defconfig |  2 +-
 configs/peach-pi_defconfig |  2 +-
 configs/peach-pit_defconfig|  2 +-
 configs/snow_defconfig |  2 +-
 configs/spring_defconfig   |  2 +-
 drivers/tpm/Kconfig| 10 ++--
 drivers/tpm/Makefile   |  2 +-
 drivers/tpm/tpm_atmel_twi.c| 68 --
 drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c}  |  5 +-
 drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h}  |  0
 drivers/tpm/tpm_tis_lpc.c  |  1 -
 include/tis.h  | 60 ---
 include/tpm.h  |  6 --
 lib/tpm.c  | 20 +--
 20 files changed, 77 insertions(+), 130 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
 rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)
 delete mode 100644 include/tis.h

-- 
2.1.4

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


[U-Boot] [PATCH v4 3/4] dm: tpm: Remove every compilation switch for TPM driver model

2015-10-06 Thread Christophe Ricard
As every TPM drivers support UCLASS_TPM, we can only rely on DM_TPM
functions.

This simplify a bit the code.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/cmd_tpm.c   | 13 +
 drivers/tpm/tpm_tis_infineon.c |  1 -
 drivers/tpm/tpm_tis_lpc.c  |  1 -
 include/tis.h  | 60 --
 include/tpm.h  |  6 -
 lib/tpm.c  | 20 +++---
 6 files changed, 4 insertions(+), 97 deletions(-)
 delete mode 100644 include/tis.h

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 97501cc..add6bfb 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -443,7 +443,6 @@ TPM_COMMAND_NO_ARG(tpm_force_clear)
 TPM_COMMAND_NO_ARG(tpm_physical_enable)
 TPM_COMMAND_NO_ARG(tpm_physical_disable)
 
-#ifdef CONFIG_DM_TPM
 static int get_tpm(struct udevice **devp)
 {
int rc;
@@ -476,11 +475,11 @@ static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int 
argc,
 
return 0;
 }
-#endif
 
 static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
 {
+   struct udevice *dev;
void *command;
uint8_t response[1024];
size_t count, response_length = sizeof(response);
@@ -492,17 +491,11 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}
 
-#ifdef CONFIG_DM_TPM
-   struct udevice *dev;
-
rc = get_tpm(&dev);
if (rc)
return rc;
 
rc = tpm_xfer(dev, command, count, response, &response_length);
-#else
-   rc = tis_sendrecv(command, count, response, &response_length);
-#endif
free(command);
if (!rc) {
puts("tpm response:\n");
@@ -657,9 +650,7 @@ TPM_COMMAND_NO_ARG(tpm_end_oiap)
U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
 
 static cmd_tbl_t tpm_commands[] = {
-#ifdef CONFIG_DM_TPM
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
-#endif
U_BOOT_CMD_MKENT(init, 0, 1,
do_tpm_init, "", ""),
U_BOOT_CMD_MKENT(startup, 0, 1,
@@ -730,9 +721,7 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
 "cmd args...\n"
 "- Issue TPM command  with arguments .\n"
 "Admin Startup and State Commands:\n"
-#ifdef CONFIG_DM_TPM
 "  info - Show information about the TPM\n"
-#endif
 "  init\n"
 "- Put TPM into a state where it waits for 'startup' command.\n"
 "  startup mode\n"
diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c
index 88eb786..f57c328 100644
--- a/drivers/tpm/tpm_tis_infineon.c
+++ b/drivers/tpm/tpm_tis_infineon.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c
index b41c3ce..257d035 100644
--- a/drivers/tpm/tpm_tis_lpc.c
+++ b/drivers/tpm/tpm_tis_lpc.c
@@ -16,7 +16,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/include/tis.h b/include/tis.h
deleted file mode 100644
index 1985d9e..000
--- a/include/tis.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#ifndef __TIS_H
-#define __TIS_H
-
-#ifndef CONFIG_DM_TPM
-
-#include 
-
-/* Low-level interface to access TPM */
-
-/*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void);
-
-/*
- * tis_open()
- *
- * Requests access to locality 0 for the caller. After all commands have been
- * completed the caller is supposed to call tis_close().
- *
- * Returns 0 on success, -1 on failure.
- */
-int tis_open(void);
-
-/*
- * tis_close()
- *
- * terminate the currect session with the TPM by releasing the locked
- * locality. Returns 0 on success of -1 on failure (in case lock
- * removal did not succeed).
- */
-int tis_close(void);
-
-/*
- * tis_sendrecv()
- *
- * Send the requested data to the TPM and then try to get its response
- *
- * @sendbuf - buffer of the data to send
- * @send_size size of the data to send
- * @recvbuf - memory to save the response to
- * @recv_len - pointer to the size of the response buffer
- *
- * Returns 0 on success (and places the number of response bytes at recv_len)
- * or -1 on failure.
- */
-int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
-   size_t *recv_len);
-#endif
-
-#endif /* __TIS_H */
diff --git a/include/tpm.h b/include/tpm.h
index 086b672..9a6585d 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -8,8 +8,6 @@
 #ifndef __TPM_H
 #define __TPM_H
 
-#include 
-
 /*
  * Here is a partial imple

[U-Boot] [PATCH v4 1/4] dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon

2015-10-06 Thread Christophe Ricard
As there is no TCG specification or recommendation for i2c TPM 1.2,
move tpm_tis_i2c driver to tpm_i2c_infineon. Other tpm vendors like Atmel
or STMicroelectronics may have a different transport protocol for i2c.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v4:
- Fix compilation issues reported by Simon Glass on
- patch 2: dm: tpm: Add Driver Model support for tpm_atmel_twi driver
- patch 3: dm: tpm: Remove every compilation switch for TPM driver model

Changes in v3:
- Adding mention to Tom Rini review

Changes in v2:
- Change existing users of config to use renamed Kconfig

 README| 4 ++--
 configs/nyan-big_defconfig| 2 +-
 configs/peach-pi_defconfig| 2 +-
 configs/peach-pit_defconfig   | 2 +-
 configs/snow_defconfig| 2 +-
 configs/spring_defconfig  | 2 +-
 drivers/tpm/Kconfig   | 4 ++--
 drivers/tpm/Makefile  | 2 +-
 drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} | 4 ++--
 drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} | 0
 10 files changed, 12 insertions(+), 12 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
 rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)

diff --git a/README b/README
index c22b60b..48ea80d 100644
--- a/README
+++ b/README
@@ -1478,8 +1478,8 @@ The following options need to be configured:
CONFIG_TPM
Support TPM devices.
 
-   CONFIG_TPM_TIS_I2C
-   Support for i2c bus TPM devices. Only one device
+   CONFIG_TPM_TIS_INFINEON
+   Support for Infineon i2c bus TPM devices. Only one device
per system is supported at this time.
 
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
diff --git a/configs/nyan-big_defconfig b/configs/nyan-big_defconfig
index 2dd2930..4f31c1c 100644
--- a/configs/nyan-big_defconfig
+++ b/configs/nyan-big_defconfig
@@ -20,7 +20,7 @@ CONFIG_CROS_EC_SPI=y
 CONFIG_SPI_FLASH=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_DISPLAY_PORT=y
diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index dfdf61b..6eff072 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -30,7 +30,7 @@ CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
 CONFIG_SOUND_WM8994=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_VIDEO_BRIDGE=y
diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig
index 01c4f37..24bc161 100644
--- a/configs/peach-pit_defconfig
+++ b/configs/peach-pit_defconfig
@@ -30,7 +30,7 @@ CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
 CONFIG_SOUND_WM8994=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_VIDEO_BRIDGE=y
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index c4e2f61..0c9ca8b 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -39,7 +39,7 @@ CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
 CONFIG_SOUND_WM8994=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_VIDEO_BRIDGE=y
diff --git a/configs/spring_defconfig b/configs/spring_defconfig
index 4acadf3..47bc643 100644
--- a/configs/spring_defconfig
+++ b/configs/spring_defconfig
@@ -39,7 +39,7 @@ CONFIG_I2S_SAMSUNG=y
 CONFIG_SOUND_MAX98095=y
 CONFIG_SOUND_WM8994=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_VIDEO_BRIDGE=y
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 6bc8fdd..dacb847 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -31,7 +31,7 @@ config TPM_ATMEL_TWI
  to the device using the standard TPM Interface Specification (TIS)
  protocol
 
-config TPM_TIS_I2C
+config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
depends on TPM && DM_I2C
help
@@ -42,7 +42,7 @@ config TPM_TIS_I2C
 
 config TPM_TIS_I2C_BURST_LIMITATION
bool "Enable I2C burst length limitation"
-   depends on TPM_TIS_I2C
+   depends on TPM_TIS_INFINEON
help
  Some broken TPMs have a limitation on the number of bytes they can
  receive in one message. Enable this option to allow you to set this
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 0d328f8..5748145 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -6,6 +6,6 @@
 obj-$(CONFIG_DM_TPM) += tpm-uclass.o
 
 obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
-obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
+obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm

[U-Boot] [PATCH v4 2/4] dm: tpm: Add Driver Model support for tpm_atmel_twi driver

2015-10-06 Thread Christophe Ricard
tpm_atmel_twi can fit perfectly to the new UCLASS_TPM class.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 .../controlcenterd_36BIT_SDCARD_DEVELOP_defconfig  |  2 +
 configs/controlcenterd_36BIT_SDCARD_defconfig  |  2 +
 .../controlcenterd_TRAILBLAZER_DEVELOP_defconfig   |  2 +
 configs/controlcenterd_TRAILBLAZER_defconfig   |  2 +
 drivers/tpm/Kconfig|  2 +-
 drivers/tpm/tpm_atmel_twi.c| 68 --
 6 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig 
b/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig
index c8ab862..58566c1 100644
--- a/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig
+++ b/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig
@@ -6,6 +6,8 @@ CONFIG_SYS_EXTRA_OPTIONS="36BIT,SDCARD,DEVELOP"
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_TPM=y
 CONFIG_SPI_FLASH=y
+CONFIG_DM=y
+CONFIG_DM_TPM=y
 CONFIG_TPM_ATMEL_TWI=y
 CONFIG_TPM_AUTH_SESSIONS=y
 CONFIG_TPM=y
diff --git a/configs/controlcenterd_36BIT_SDCARD_defconfig 
b/configs/controlcenterd_36BIT_SDCARD_defconfig
index 21c0eab..56a4910 100644
--- a/configs/controlcenterd_36BIT_SDCARD_defconfig
+++ b/configs/controlcenterd_36BIT_SDCARD_defconfig
@@ -6,6 +6,8 @@ CONFIG_SYS_EXTRA_OPTIONS="36BIT,SDCARD"
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_TPM=y
 CONFIG_SPI_FLASH=y
+CONFIG_DM=y
+CONFIG_DM_TPM=y
 CONFIG_TPM_ATMEL_TWI=y
 CONFIG_TPM_AUTH_SESSIONS=y
 CONFIG_TPM=y
diff --git a/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig 
b/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig
index c3a0920..cbf43ef 100644
--- a/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig
+++ b/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig
@@ -7,6 +7,8 @@ CONFIG_SYS_EXTRA_OPTIONS="TRAILBLAZER,SPIFLASH,DEVELOP"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TPM=y
+CONFIG_DM=y
+CONFIG_DM_TPM=y
 CONFIG_TPM_ATMEL_TWI=y
 CONFIG_TPM_AUTH_SESSIONS=y
 CONFIG_TPM=y
diff --git a/configs/controlcenterd_TRAILBLAZER_defconfig 
b/configs/controlcenterd_TRAILBLAZER_defconfig
index 08aae9a..e897422 100644
--- a/configs/controlcenterd_TRAILBLAZER_defconfig
+++ b/configs/controlcenterd_TRAILBLAZER_defconfig
@@ -7,6 +7,8 @@ CONFIG_SYS_EXTRA_OPTIONS="TRAILBLAZER,SPIFLASH"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TPM=y
+CONFIG_DM=y
+CONFIG_DM_TPM=y
 CONFIG_TPM_ATMEL_TWI=y
 CONFIG_TPM_AUTH_SESSIONS=y
 CONFIG_TPM=y
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index dacb847..ff2cdbe 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
 
 config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
-   depends on TPM
+   depends on TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
diff --git a/drivers/tpm/tpm_atmel_twi.c b/drivers/tpm/tpm_atmel_twi.c
index 205d7a5..2aa9381 100644
--- a/drivers/tpm/tpm_atmel_twi.c
+++ b/drivers/tpm/tpm_atmel_twi.c
@@ -7,51 +7,56 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+#include "tpm_internal.h"
+
 #define ATMEL_TPM_TIMEOUT_MS 5000 /* sufficient for anything but
 generating/exporting keys */
 
 /*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void)
-{
-   return 0;
-}
-
-/*
- * tis_open()
+ * tpm_atmel_twi_open()
  *
  * Requests access to locality 0 for the caller. After all commands have been
  * completed the caller is supposed to call tis_close().
  *
  * Returns 0 on success, -1 on failure.
  */
-int tis_open(void)
+static int tpm_atmel_twi_open(struct udevice *dev)
 {
return 0;
 }
 
 /*
- * tis_close()
+ * tpm_atmel_twi_close()
  *
  * terminate the currect session with the TPM by releasing the locked
  * locality. Returns 0 on success of -1 on failure (in case lock
  * removal did not succeed).
  */
-int tis_close(void)
+static int tpm_atmel_twi_close(struct udevice *dev)
+{
+   return 0;
+}
+
+/*
+ * tpm_atmel_twi_get_desc()
+ *
+ * @dev:Device to check
+ * @buf:Buffer to put the string
+ * @size:   Maximum size of buffer
+ * @return length of string, or -ENOSPC it no space
+ */
+static int tpm_atmel_twi_get_desc(struct udevice *dev, char *buf, int size)
 {
return 0;
 }
 
 /*
- * tis_sendrecv()
+ * tpm_atmel_twi_xfer()
  *
  * Send the requested data to the TPM and then try to get its response
  *
@@ -63,8 +68,9 @@ int tis_close(void)
  * Returns 0 on success (and places the number of response bytes at recv_len)
  * or -1 on failure.
  *

[U-Boot] [PATCH 1/3] tpm: Move tpm_tis_i2c to tpm_i2c_infineon

2015-08-09 Thread Christophe Ricard
As there is no TCG specification or recommendation for i2c TPM 1.2, move
tpm_tis_i2c driver to tpm_i2c_infineon. Other tpm vendors like atmel or
stmicroelectronics may have a different transport protocol for i2c.

Signed-off-by: Christophe Ricard 
---

 README| 4 ++--
 drivers/tpm/Makefile  | 2 +-
 drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} | 0
 3 files changed, 3 insertions(+), 3 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} (100%)

diff --git a/README b/README
index 1bcb63c..a563aa1 100644
--- a/README
+++ b/README
@@ -1492,8 +1492,8 @@ The following options need to be configured:
CONFIG_TPM
Support TPM devices.
 
-   CONFIG_TPM_TIS_I2C
-   Support for i2c bus TPM devices. Only one device
+   CONFIG_TPM_I2C_INFINEON
+   Support for infineon i2c bus TPM devices. Only one device
per system is supported at this time.
 
CONFIG_TPM_TIS_I2C_BUS_NUMBER
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 150570e..fea246f 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -6,6 +6,6 @@
 # TODO: Merge tpm_tis_lpc.c with tpm.c
 obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
 obj-$(CONFIG_TPM_TIS_I2C) += tpm.o
-obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
+obj-$(CONFIG_TPM_INFINEON_I2C) += tpm_i2c_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_i2c_infineon.c
similarity index 100%
rename from drivers/tpm/tpm_tis_i2c.c
rename to drivers/tpm/tpm_i2c_infineon.c
-- 
2.1.4

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


[U-Boot] [PATCH 0/3] Introduce TPM driver model and STMicroelectronics ST33ZP24 TPMs

2015-08-09 Thread Christophe Ricard
Hi,

This patch serie introduce TPM driver model allowing to instantiate a TPM
using U_BOOT_DEVICE macro for platform_data or device tree.

As an information, there is no TCG transport protocol official specification
for i2c for TPM1.2. The TPM uclass allows to support different kind of bus
(LPC, I2C, SPI) keeping the TPM command duration in common.

Also, this serie introduce TPM1.2 from STMicroelectronics ST33ZP24 with
I2C and SPI support. It has been ported from existing Linux drivers.

This has been tested on Beagleboard xM.

Best Regards
Christophe


Christophe Ricard (3):
  tpm: Move tpm_tis_i2c to tpm_i2c_infineon
  tpm: Initial work to introduce TPM driver model
  tpm: Add st33zp24 tpm with i2c and spi phy

 README|  23 +-
 drivers/tpm/Makefile  |   5 +-
 drivers/tpm/st33zp24/Makefile |   7 +
 drivers/tpm/st33zp24/i2c.c| 226 +++
 drivers/tpm/st33zp24/spi.c| 286 ++
 drivers/tpm/st33zp24/st33zp24.c   | 454 ++
 drivers/tpm/st33zp24/st33zp24.h   |  29 ++
 drivers/tpm/tpm.c | 275 +++--
 drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} | 271 -
 drivers/tpm/tpm_private.h |  23 +-
 include/dm/platform_data/st33zp24_i2c.h   |  28 ++
 include/dm/platform_data/st33zp24_spi.h   |  30 ++
 include/dm/platform_data/tpm_i2c_infineon.h   |  23 ++
 include/dm/uclass-id.h|   1 +
 include/fdtdec.h  |   5 +-
 lib/fdtdec.c  |   2 +
 16 files changed, 1351 insertions(+), 337 deletions(-)
 create mode 100644 drivers/tpm/st33zp24/Makefile
 create mode 100644 drivers/tpm/st33zp24/i2c.c
 create mode 100644 drivers/tpm/st33zp24/spi.c
 create mode 100644 drivers/tpm/st33zp24/st33zp24.c
 create mode 100644 drivers/tpm/st33zp24/st33zp24.h
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} (70%)
 create mode 100644 include/dm/platform_data/st33zp24_i2c.h
 create mode 100644 include/dm/platform_data/st33zp24_spi.h
 create mode 100644 include/dm/platform_data/tpm_i2c_infineon.h

-- 
2.1.4

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


[U-Boot] [PATCH 2/3] tpm: Initial work to introduce TPM driver model

2015-08-09 Thread Christophe Ricard
drivers/tpm/tpm.c is a TPM core driver port from Linux.
So far in u-boot only infineon i2c driver is using it but it could fit
for others...

Introduce a new tpm uclass so that every TPM driver can register against it and
and take benefit of common functions and data such as tpm_transmit,
tpm_register_hardware & tpm_remove_hardware.
Finally tis_init, tis_open, tis_close, tis_sendrecv are using ops allowing
to introduce proprietary instructions.
Also this patch convert tpm_i2c_infineon for using this tpm uclass.

Signed-off-by: Christophe Ricard 
---

 README  |   8 +-
 drivers/tpm/Makefile|   2 +-
 drivers/tpm/tpm.c   | 275 +++-
 drivers/tpm/tpm_i2c_infineon.c  | 271 ---
 drivers/tpm/tpm_private.h   |  23 ++-
 include/dm/platform_data/tpm_i2c_infineon.h |  23 +++
 include/dm/uclass-id.h  |   1 +
 7 files changed, 270 insertions(+), 333 deletions(-)
 create mode 100644 include/dm/platform_data/tpm_i2c_infineon.h

diff --git a/README b/README
index a563aa1..506ff6c 100644
--- a/README
+++ b/README
@@ -1489,19 +1489,13 @@ The following options need to be configured:
Support for PWM modul on the imx6.
 
 - TPM Support:
-   CONFIG_TPM
+   CONFIG_DM_TPM
Support TPM devices.
 
CONFIG_TPM_I2C_INFINEON
Support for infineon i2c bus TPM devices. Only one device
per system is supported at this time.
 
-   CONFIG_TPM_TIS_I2C_BUS_NUMBER
-   Define the the i2c bus number for the TPM device
-
-   CONFIG_TPM_TIS_I2C_SLAVE_ADDRESS
-   Define the TPM's address on the i2c bus
-
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
Define the burst count bytes upper limit
 
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index fea246f..bd2cd6d 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -5,7 +5,7 @@
 
 # TODO: Merge tpm_tis_lpc.c with tpm.c
 obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
-obj-$(CONFIG_TPM_TIS_I2C) += tpm.o
+obj-$(CONFIG_DM_TPM) += tpm.o
 obj-$(CONFIG_TPM_INFINEON_I2C) += tpm_i2c_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
diff --git a/drivers/tpm/tpm.c b/drivers/tpm/tpm.c
index a650892..caf208d 100644
--- a/drivers/tpm/tpm.c
+++ b/drivers/tpm/tpm.c
@@ -36,8 +36,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -47,21 +45,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/* TPM configuration */
-struct tpm {
-#ifdef CONFIG_DM_I2C
-   struct udevice *dev;
-#else
-   int i2c_bus;
-   int slave_addr;
-   int old_bus;
-#endif
-   char inited;
-} tpm;
-
-/* Global structure for tpm chip data */
-static struct tpm_chip g_chip;
-
 enum tpm_duration {
TPM_SHORT = 0,
TPM_MEDIUM = 1,
@@ -375,14 +358,12 @@ static unsigned long tpm_calc_ordinal_duration(struct 
tpm_chip *chip,
return duration;
 }
 
-static ssize_t tpm_transmit(const unsigned char *buf, size_t bufsiz)
+static ssize_t tpm_transmit(struct tpm_chip *chip, const unsigned char *buf, 
size_t bufsiz)
 {
int rc;
u32 count, ordinal;
unsigned long start, stop;
 
-   struct tpm_chip *chip = &g_chip;
-
/* switch endianess: big->little */
count = get_unaligned_be32(buf + TPM_CMD_COUNT_BYTE);
ordinal = get_unaligned_be32(buf + TPM_CMD_ORDINAL_BYTE);
@@ -441,233 +422,102 @@ out:
return rc;
 }
 
-#ifdef CONFIG_DM_I2C
-static int tpm_open_dev(struct udevice *dev)
-{
-   int rc;
-
-   debug("%s: start\n", __func__);
-   if (g_chip.is_open)
-   return -EBUSY;
-   rc = tpm_vendor_init_dev(dev);
-   if (rc < 0)
-   g_chip.is_open = 0;
-   return rc;
-}
-#else
-static int tpm_open(uint32_t dev_addr)
-{
-   int rc;
-
-   if (g_chip.is_open)
-   return -EBUSY;
-   rc = tpm_vendor_init(dev_addr);
-   if (rc < 0)
-   g_chip.is_open = 0;
-   return rc;
-}
-#endif
-static void tpm_close(void)
-{
-   if (g_chip.is_open) {
-   tpm_vendor_cleanup(&g_chip);
-   g_chip.is_open = 0;
-   }
-}
-
-static int tpm_select(void)
-{
-#ifndef CONFIG_DM_I2C
-   int ret;
-
-   tpm.old_bus = i2c_get_bus_num();
-   if (tpm.old_bus != tpm.i2c_bus) {
-   ret = i2c_set_bus_num(tpm.i2c_bus);
-   if (ret) {
-   debug("%s: Fail to set i2c bus %d\n", __func__,
- tpm.i2c_bus);
-   return -1;
-   }
-   }
-#endif
-   return 0;
-}
-
-static int tpm_deselect(void)
+void tpm_remove_hardware(struct udevice *

[U-Boot] [PATCH 3/3] tpm: Add st33zp24 tpm with i2c and spi phy

2015-08-09 Thread Christophe Ricard
Add TPM st33zp24 tpm with i2c and spi phy. This is a port from Linux.
This driver relies on tpm uclass.

Signed-off-by: Christophe Ricard 
---

 README  |  11 +
 drivers/tpm/Makefile|   1 +
 drivers/tpm/st33zp24/Makefile   |   7 +
 drivers/tpm/st33zp24/i2c.c  | 226 
 drivers/tpm/st33zp24/spi.c  | 286 
 drivers/tpm/st33zp24/st33zp24.c | 454 
 drivers/tpm/st33zp24/st33zp24.h |  29 ++
 include/dm/platform_data/st33zp24_i2c.h |  28 ++
 include/dm/platform_data/st33zp24_spi.h |  30 +++
 include/fdtdec.h|   5 +-
 lib/fdtdec.c|   2 +
 11 files changed, 1078 insertions(+), 1 deletion(-)
 create mode 100644 drivers/tpm/st33zp24/Makefile
 create mode 100644 drivers/tpm/st33zp24/i2c.c
 create mode 100644 drivers/tpm/st33zp24/spi.c
 create mode 100644 drivers/tpm/st33zp24/st33zp24.c
 create mode 100644 drivers/tpm/st33zp24/st33zp24.h
 create mode 100644 include/dm/platform_data/st33zp24_i2c.h
 create mode 100644 include/dm/platform_data/st33zp24_spi.h

diff --git a/README b/README
index 506ff6c..d3f9590 100644
--- a/README
+++ b/README
@@ -1499,6 +1499,17 @@ The following options need to be configured:
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
Define the burst count bytes upper limit
 
+   CONFIG_TPM_ST33ZP24
+   Support for STMicroelectronics TPM devices. Requires DM_TPM 
support.
+
+   CONFIG_TPM_ST33ZP24_I2C
+   Support for STMicroelectronics ST33ZP24 I2C devices.
+   Requires TPM_ST33ZP24 and I2C.
+
+   CONFIG_TPM_ST33ZP24_SPI
+   Support for STMicroelectronics ST33ZP24 SPI devices.
+   Requires TPM_ST33ZP24 and SPI.
+
CONFIG_TPM_ATMEL_TWI
Support for Atmel TWI TPM device. Requires I2C support.
 
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index bd2cd6d..48bc5f3 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_DM_TPM) += tpm.o
 obj-$(CONFIG_TPM_INFINEON_I2C) += tpm_i2c_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
+obj-$(CONFIG_TPM_ST33ZP24) += st33zp24/
diff --git a/drivers/tpm/st33zp24/Makefile b/drivers/tpm/st33zp24/Makefile
new file mode 100644
index 000..ed28e8c
--- /dev/null
+++ b/drivers/tpm/st33zp24/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for ST33ZP24 TPM 1.2 driver
+#
+
+obj-$(CONFIG_TPM_ST33ZP24) += st33zp24.o
+obj-$(CONFIG_TPM_ST33ZP24_I2C) += i2c.o
+obj-$(CONFIG_TPM_ST33ZP24_SPI) += spi.o
diff --git a/drivers/tpm/st33zp24/i2c.c b/drivers/tpm/st33zp24/i2c.c
new file mode 100644
index 000..204021a
--- /dev/null
+++ b/drivers/tpm/st33zp24/i2c.c
@@ -0,0 +1,226 @@
+/*
+ * STMicroelectronics TPM ST33ZP24 I2C phy for UBOOT
+ * Copyright (C) 2015  STMicroelectronics
+ *
+ * Description: Device driver for ST33ZP24 I2C TPM TCG.
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
+ * STMicroelectronics I2C Protocol Stack Specification version 1.2.0.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../tpm_private.h"
+#include "st33zp24.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define TPM_DUMMY_BYTE 0xAA
+#define TPM_ST33ZP24_I2C_SLAVE_ADDR 0x13
+
+struct st33zp24_i2c_phy {
+   uint8_t slave_addr;
+   int i2c_bus;
+   int old_bus;
+   u8 buf[TPM_BUFSIZE + 1];
+} __packed;
+
+/*
+ * write8_reg
+ * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
+ * @param: tpm_register, the tpm tis register where the data should be written
+ * @param: tpm_data, the tpm_data to write inside the tpm_register
+ * @param: tpm_size, The length of the data
+ * @return: Number of byte written successfully else an error code.
+ */
+static int write8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, u16 
tpm_size)
+{
+   struct st33zp24_i2c_phy *phy = phy_id;
+   int ret;
+   phy->buf[0] = tpm_register;
+   memcpy(phy->buf + 1, tpm_data, tpm_size);
+   ret = i2c_write(phy->slave_addr, 0, 0, phy->buf, tpm_size + 1);
+   if (!ret)
+   return tpm_size + 1;
+   return ret;
+} /* write8_reg() */
+
+/*
+* read8_reg
+* Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
+* @param: tpm_register, the tpm tis register where the data should be read
+* @param: tpm_data, the TPM response
+* @param: tpm_size, tpm TPM response size to read.
+* @return: Number of byte read successfully else an error code.
+*/
+static int read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size)
+{

Re: [U-Boot] [PATCH 0/3] Introduce TPM driver model and STMicroelectronics ST33ZP24 TPMs

2015-08-09 Thread Christophe Ricard
Hi Simon,
Thanks for pointing me to the right tree and branch. I missed that :-(.

I will go and look at your on-going work and try to fit our STM drivers.

I will be happy to co-work on this.

Best regards
Christophe

Le dim. 9 août 2015 15:28, Simon Glass  a écrit :

> Hi Christophe,
>
> On 9 August 2015 at 07:19, Christophe Ricard
>  wrote:
> >
> > Hi,
> >
> > This patch serie introduce TPM driver model allowing to instantiate a TPM
> > using U_BOOT_DEVICE macro for platform_data or device tree.
> >
> > As an information, there is no TCG transport protocol official
> specification
> > for i2c for TPM1.2. The TPM uclass allows to support different kind of
> bus
> > (LPC, I2C, SPI) keeping the TPM command duration in common.
> >
> > Also, this serie introduce TPM1.2 from STMicroelectronics ST33ZP24 with
> > I2C and SPI support. It has been ported from existing Linux drivers.
> >
> > This has been tested on Beagleboard xM.
>
> As it happens I have just been trying to clean up the TPM drivers for
> Kconfig and driver model.
>
> Please see u-boot-dm branch tpm-working. I'll hurry up and try to send
> out some patches and update the wiki. I wonder if we can join our work
> somehow?
>
> Regards,
> Simon
>
> >
> > Best Regards
> > Christophe
> >
> >
> > Christophe Ricard (3):
> >   tpm: Move tpm_tis_i2c to tpm_i2c_infineon
> >   tpm: Initial work to introduce TPM driver model
> >   tpm: Add st33zp24 tpm with i2c and spi phy
> >
> >  README|  23 +-
> >  drivers/tpm/Makefile  |   5 +-
> >  drivers/tpm/st33zp24/Makefile |   7 +
> >  drivers/tpm/st33zp24/i2c.c| 226 +++
> >  drivers/tpm/st33zp24/spi.c| 286 ++
> >  drivers/tpm/st33zp24/st33zp24.c   | 454
> ++
> >  drivers/tpm/st33zp24/st33zp24.h   |  29 ++
> >  drivers/tpm/tpm.c | 275 +++--
> >  drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} | 271 -
> >  drivers/tpm/tpm_private.h |  23 +-
> >  include/dm/platform_data/st33zp24_i2c.h   |  28 ++
> >  include/dm/platform_data/st33zp24_spi.h   |  30 ++
> >  include/dm/platform_data/tpm_i2c_infineon.h   |  23 ++
> >  include/dm/uclass-id.h|   1 +
> >  include/fdtdec.h  |   5 +-
> >  lib/fdtdec.c  |   2 +
> >  16 files changed, 1351 insertions(+), 337 deletions(-)
> >  create mode 100644 drivers/tpm/st33zp24/Makefile
> >  create mode 100644 drivers/tpm/st33zp24/i2c.c
> >  create mode 100644 drivers/tpm/st33zp24/spi.c
> >  create mode 100644 drivers/tpm/st33zp24/st33zp24.c
> >  create mode 100644 drivers/tpm/st33zp24/st33zp24.h
> >  rename drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} (70%)
> >  create mode 100644 include/dm/platform_data/st33zp24_i2c.h
> >  create mode 100644 include/dm/platform_data/st33zp24_spi.h
> >  create mode 100644 include/dm/platform_data/tpm_i2c_infineon.h
> >
> > --
> > 2.1.4
> >
>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 06/25] tpm: Move the I2C TPM code into one file

2015-08-13 Thread Christophe Ricard

Hi Simon,

On 13/08/2015 03:30, Simon Glass wrote:

Hi Christophe,

On 11 August 2015 at 15:42, christophe.ricard
 wrote:

Hi Simon,

I would basically disagree with this one.
The code from tpm.c you are merging into tpm_tis_i2c may not only be used by
tpm_tis_i2c as it is using data from TPM standards (e.g: Trusted computing
group) that should be used by other TPM drivers.
You can find in chapter 17 how the table tpm_protected_ordinal_duration,
tpm_ordinal_duration were build.
(https://www.trustedcomputinggroup.org/files/resource_files/E14876A3-1A4B-B294-D086297A1ED38F96/mainP2Structrev103.pdf).

This come from a Linux port.

As a result, we can imagine tis_sendrecv as a generic function where
tpm_transmit manage the way tpm commands are sent following specification
giving the hand to drivers thanks to the tpm_vendor_specific field
{send,recv} for handling the communication over a specified or proprietary
transport protocol.
As an example in tpm_tis_lpc, a 1s command duration might be too short or
too long for some commands and might be really hard to debug in case someone
decide to had a new TPM command support in u-boot.
Also 1s might be enought for the current commands or for evaluated TPM but
it may require a longer duration for some other.
By reading the duration TPM capability, that will be just generic.

But this code is only used by the Infineon driver.

My idea is to standardize the way a tpm does a command transfer in u-boot.
The approach is applicable to all the existing u-boot tpm drivers.



Also tpm_tis_i2c is Infineon specific and does not fit to any TCG standard
for TPM1.2, i would recommand to rename this driver tpm_i2c_infineon to be
inline with Linux naming and not confuse a future user on what it support.

Yes we should do that.


At the end from my delivery tentative, a Linux port as well, you may see
that i also rely on those functions. However I am not doing any check on the
command duration. This is to be improved...

May you prefer an approach that would not lead to duplicated code ?

I wonder if the timing of each command can be attached to the uclass
and handled there. We might have a function like:

tpm_xfer()

which sends data to the TPM and receives a rseponse. This can be
implemented by the uclass.

Then the driver interface (which I currently have as xfer()) could be
send() and receive(). The time delay measurement could happen in the
uclass.

So in summary:

tpm-uclass.c:
tpm_xfer()
- calls driver->send()
- checks timeout based on data supplied by the driver
 -calls driver->receive()
- checks timeout based on data supplied by the driver
 - returns result

Then the drivers only need to implement simple send and receive functions.

I agree with this approach.

[...]

Best REgards
Christophe
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 07/25] tpm: tpm_tis_i2c: Drop unnecessary methods

2015-08-13 Thread Christophe Ricard

Hi Simon,

On 13/08/2015 03:30, Simon Glass wrote:

Hi Christophe,

On 11 August 2015 at 15:47, christophe.ricard
 wrote:

Hi Simon,

As per my comment on patch 6, i would disagree as well on this one.
It tpm_vendor_specific structure is convenient for ST33ZP24 for example.

Best Regards
Christophe


As things stand they are only used in one place. I think we should
work out the best uclass API for the TPM and then go with that.

I agree with that.
How do you want to proceed ? Do you agree to integrate the results of 
our exchanges for a new round ?


[...]

Best Regards
Christophe
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 08/25] tpm: tpm_tis_i2c: Drop struct tpm_vendor_specific

2015-08-13 Thread Christophe Ricard

Hi Simon,

On 13/08/2015 03:30, Simon Glass wrote:

Hi Christophe,

On 11 August 2015 at 15:47, christophe.ricard
 wrote:

Hi Simon,

Locality concept are valid almost on any chip assuming if no locality are
supported the default one is locality 0.
I would leave this change open for discussion.

However, as per patch 06 & 07, i would keep req_complete_mask,
req_complete_val, req_canceled, timeout_a, timeout_b, timeout_c, timeout_d
in tpm_vendor_specific structure as this is chip specific.

I really think tpm_vendor_specific is usefull for managing different kind of
TPM "the same way"/following standards.

That code belongs in the uclass I think. If there really are generic
settings that are needed for all TPMs then it should sit there. We
don't want to have an additional layer of stuff that doesn't relate to
driver model.
After reviewing your previous comments, i think we can drop this 
tpm_vendor_specific structure to simplify the code a bit.
However, the work we are doing may stick only to TPM1.2. I think it will 
be fine as we have only drivers for those kind of TPMs.
I believe a new uclass may be necessary when going to provide support 
TPM 2.0.


In short, may be we can anticipate that and make it explicit in the 
uclass name ? (UCLASS_TPM12 ?)


[...]

Best Regards
Christophe
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/3] tpm: Initial work to introduce TPM driver model

2015-08-13 Thread Christophe Ricard

Hi Simon,

On 13/08/2015 17:55, Simon Glass wrote:

Hi Christophe,

On 9 August 2015 at 07:19, Christophe Ricard
 wrote:

drivers/tpm/tpm.c is a TPM core driver port from Linux.
So far in u-boot only infineon i2c driver is using it but it could fit
for others...

Introduce a new tpm uclass so that every TPM driver can register against it and
and take benefit of common functions and data such as tpm_transmit,
tpm_register_hardware & tpm_remove_hardware.
Finally tis_init, tis_open, tis_close, tis_sendrecv are using ops allowing
to introduce proprietary instructions.
Also this patch convert tpm_i2c_infineon for using this tpm uclass.

Signed-off-by: Christophe Ricard 
---

  README  |   8 +-
  drivers/tpm/Makefile|   2 +-
  drivers/tpm/tpm.c   | 275 +++-
  drivers/tpm/tpm_i2c_infineon.c  | 271 ---
  drivers/tpm/tpm_private.h   |  23 ++-
  include/dm/platform_data/tpm_i2c_infineon.h |  23 +++
  include/dm/uclass-id.h  |   1 +
  7 files changed, 270 insertions(+), 333 deletions(-)
  create mode 100644 include/dm/platform_data/tpm_i2c_infineon.h

There is a lot going on in this patch - in general I think it is
better to split things up so that each patch does one thing.
I understand. I have basically seen in your work more or less the same 
approach as far as TPM class.
I believe, according to your plan, i can wait for you to update you tree 
integrating my first comments on tpm-working branch or

if you prefer i can send a merge between your work and my comments.

What's your prefered option ?

Best Regards
Christophe

Regards,
Simon


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


Re: [U-Boot] [PATCH 00/25] dm: Convert TPM drivers to driver model

2015-08-13 Thread Christophe Ricard

Hi Simon,

Thanks for the review and your comments.
Please see mine below:

On 13/08/2015 03:30, Simon Glass wrote:

Hi Christophe,

On 11 August 2015 at 15:50, christophe.ricard
 wrote:

Hi Simon,

I pretty much like the move to driver model for TPM.
However, i have some few remarks:

The current i2c driver stick to Infineon TPMs and will not support any other
vendors like ST(in my case).
The main reason for this is that there is no transport protocol over I2C
specification defined by the Trusted Computing Group for TPM1.2.
You can take a look at my release tentative here:
http://lists.denx.de/pipermail/u-boot/2015-August/222596.html

Yes I agree it's probably better to rename it. One more patch...


The tpm.c file was delivering a way to ajust best the waiting time for
command duration to receive a command answer from a TPM command. It was
ported from Linux to u-boot.
You can find in chapter 17 how the table tpm_protected_ordinal_duration,
tpm_ordinal_duration were build.
(https://www.trustedcomputinggroup.org/files/resource_files/E14876A3-1A4B-B294-D086297A1ED38F96/mainP2Structrev103.pdf)
This is defined by the TCG and followed by TPM vendors. In u-boot, this is
used only by Infineon i2c driver but it could/should(?) be used
by all other drivers (i2c and lpc).

In short, the idea is to keep  the way TPM commands are transfered giving
the hands to drivers for handling the communication over a specified or
proprietary transport protocol.

I fear the current approach would lead to duplicated codes on may TPM
drivers and 2 very differents kind of drivers (Linux/u-boot) very far from
each other.

In that case we should define what the interface is for the TPM. My
approach is to provide a low-level interface which takes care of
open/close, and sending and receiving bytes.

Since that interface doesn't understand the actual commands it can't
attach different timeouts to each. On the other hand as you say only
one driver uses it.

But since tpm_transmit() currently looks inside the packet, I don't
see why the new xfer() method could not do that also. It removes one
layer of itnerfaces.

I think your approach is acceptable and simplifies the code as well.
I would use the send/recv low level interfaces in tis_xfer reproducing 
the tpm_transmit behavior.


Do all TPMs use the same commands and timeouts?

My answer is yes with some few informations or highlights.

When it goes with TPM commands, the litteratures is using term "duration".
Term "timeout" is used for a lower level layer that may not be used by 
all TPMs (TIS).


Durations are classified into 3 categories: short, medium and long. 
Undefined is for non used Ordinals.
Each categories have a predefined value in the standard but TPM vendors 
are free to modified(greater or lower) them according to their 
implementation.
Those values can/may be updated using a tpm_getcapability command 
requiring at least a prior TPM_Startup.
I believe TPM_Startup and the tpm_getcapability(duration) could be 
executed in tis_open.


Just a nitpick, i believe prefix tis_ for the main TPM class functions 
may not be appropriate.

What about tcg_ or tpm_ ?

Also, we will have TPM 2.0 would it be acceptable to build a second TPM 
class to support additional features ?


In general Linux has ad-hoc interfaces for different things, but in
U-Boot we are trying to standardise on driver model, so normally
function pointers would end up implemented there.

[...]

Regards
Christophe
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 3/3] tpm: Add st33zp24 tpm with i2c and spi phy

2015-08-13 Thread Christophe Ricard

Hi Simon,

On 13/08/2015 17:55, Simon Glass wrote:

Hi Christophe,

On 9 August 2015 at 07:19, Christophe Ricard
 wrote:

Add TPM st33zp24 tpm with i2c and spi phy. This is a port from Linux.
This driver relies on tpm uclass.

Signed-off-by: Christophe Ricard 
---

  README  |  11 +
  drivers/tpm/Makefile|   1 +
  drivers/tpm/st33zp24/Makefile   |   7 +
  drivers/tpm/st33zp24/i2c.c  | 226 
  drivers/tpm/st33zp24/spi.c  | 286 
  drivers/tpm/st33zp24/st33zp24.c | 454 
  drivers/tpm/st33zp24/st33zp24.h |  29 ++
  include/dm/platform_data/st33zp24_i2c.h |  28 ++
  include/dm/platform_data/st33zp24_spi.h |  30 +++
  include/fdtdec.h|   5 +-
  lib/fdtdec.c|   2 +
  11 files changed, 1078 insertions(+), 1 deletion(-)
  create mode 100644 drivers/tpm/st33zp24/Makefile
  create mode 100644 drivers/tpm/st33zp24/i2c.c
  create mode 100644 drivers/tpm/st33zp24/spi.c
  create mode 100644 drivers/tpm/st33zp24/st33zp24.c
  create mode 100644 drivers/tpm/st33zp24/st33zp24.h
  create mode 100644 include/dm/platform_data/st33zp24_i2c.h
  create mode 100644 include/dm/platform_data/st33zp24_spi.h

diff --git a/README b/README
index 506ff6c..d3f9590 100644
--- a/README
+++ b/README
@@ -1499,6 +1499,17 @@ The following options need to be configured:
 CONFIG_TPM_TIS_I2C_BURST_LIMITATION
 Define the burst count bytes upper limit

+   CONFIG_TPM_ST33ZP24
+   Support for STMicroelectronics TPM devices. Requires DM_TPM 
support.
+
+   CONFIG_TPM_ST33ZP24_I2C
+   Support for STMicroelectronics ST33ZP24 I2C devices.
+   Requires TPM_ST33ZP24 and I2C.
+
+   CONFIG_TPM_ST33ZP24_SPI
+   Support for STMicroelectronics ST33ZP24 SPI devices.
+   Requires TPM_ST33ZP24 and SPI.
+

These can go in Kconfig

Ok, your are correct, i will update this in a future v2.

 CONFIG_TPM_ATMEL_TWI
 Support for Atmel TWI TPM device. Requires I2C support.

diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index bd2cd6d..48bc5f3 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_DM_TPM) += tpm.o
  obj-$(CONFIG_TPM_INFINEON_I2C) += tpm_i2c_infineon.o
  obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
  obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
+obj-$(CONFIG_TPM_ST33ZP24) += st33zp24/
diff --git a/drivers/tpm/st33zp24/Makefile b/drivers/tpm/st33zp24/Makefile
new file mode 100644
index 000..ed28e8c
--- /dev/null
+++ b/drivers/tpm/st33zp24/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for ST33ZP24 TPM 1.2 driver
+#
+
+obj-$(CONFIG_TPM_ST33ZP24) += st33zp24.o
+obj-$(CONFIG_TPM_ST33ZP24_I2C) += i2c.o
+obj-$(CONFIG_TPM_ST33ZP24_SPI) += spi.o
diff --git a/drivers/tpm/st33zp24/i2c.c b/drivers/tpm/st33zp24/i2c.c
new file mode 100644
index 000..204021a
--- /dev/null
+++ b/drivers/tpm/st33zp24/i2c.c
@@ -0,0 +1,226 @@
+/*
+ * STMicroelectronics TPM ST33ZP24 I2C phy for UBOOT
+ * Copyright (C) 2015  STMicroelectronics
+ *
+ * Description: Device driver for ST33ZP24 I2C TPM TCG.
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
+ * STMicroelectronics I2C Protocol Stack Specification version 1.2.0.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 

That may not be needed, but if so should go after the dm/platform_data...


+#include 
+#include 
+#include 

Should go up under common.h

ok.

+#include 
+#include 
+
+#include "../tpm_private.h"
+#include "st33zp24.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define TPM_DUMMY_BYTE 0xAA
+#define TPM_ST33ZP24_I2C_SLAVE_ADDR 0x13
+
+struct st33zp24_i2c_phy {
+   uint8_t slave_addr;
+   int i2c_bus;
+   int old_bus;
+   u8 buf[TPM_BUFSIZE + 1];
+} __packed;

Should not need address and bus - just use a struct udevice. Also, why __packed?
What if my board (beagleboard xm) does not support DM_I2C ? Should i 
concider a new one ? (Any recommendation ?)

How do you attach a I2C device using platform_data approach ?
I was doing this in board/ti/beagle/beagle.c:

static const struct st33zp24_i2c_platdata beagle_tpm_i2c = {
.i2c_bus = 1,
.slave_addr = 0x13,
};

U_BOOT_DEVICE(beagle_tpm_i2c) = {
.name = TPM_ST33ZP24_I2C,
.platdata = &beagle_tpm_i2c,
};


+
+/*
+ * write8_reg
+ * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
+ * @param: tpm_register, the tpm tis register where the data should be written
+ * @param: tpm_data, the tpm_data to write inside the tpm_register
+ * @param: tpm_size, The length of the data
+ * @return: Number of b

Re: [U-Boot] [PATCH v2 04/28] tpm: Convert board config TPM options to Kconfig

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

Convert all TPM options to Kconfig and tidy up.

Signed-off-by: Simon Glass 
Acked-by: Christophe Ricard 
---

Changes in v2: None

  configs/chromebook_link_defconfig | 2 ++
  configs/chromebox_panther_defconfig   | 2 ++
  configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig | 4 
  configs/controlcenterd_36BIT_SDCARD_defconfig | 4 
  configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig  | 4 
  configs/controlcenterd_TRAILBLAZER_defconfig  | 4 
  configs/coreboot-x86_defconfig| 2 ++
  configs/peach-pi_defconfig| 3 +++
  configs/peach-pit_defconfig   | 3 +++
  configs/sandbox_defconfig | 2 ++
  configs/snow_defconfig| 3 +++
  configs/spring_defconfig  | 3 +++
  include/configs/controlcenterd.h  | 7 ---
  include/configs/efi-x86.h | 2 --
  include/configs/exynos5-common.h  | 5 -
  include/configs/x86-common.h  | 2 --
  16 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/configs/chromebook_link_defconfig 
b/configs/chromebook_link_defconfig
index b987f3f..b0fc5ca 100644
--- a/configs/chromebook_link_defconfig
+++ b/configs/chromebook_link_defconfig
@@ -17,9 +17,11 @@ CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
  CONFIG_CROS_EC_LPC=y
+CONFIG_TPM_TIS_LPC=y
  CONFIG_VIDEO_VESA=y
  CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
  CONFIG_DM_RTC=y
  CONFIG_USE_PRIVATE_LIBGCC=y
  CONFIG_SYS_VSNPRINTF=y
+CONFIG_TPM=y
diff --git a/configs/chromebox_panther_defconfig 
b/configs/chromebox_panther_defconfig
index e82c8ec..e7ef8fe 100644
--- a/configs/chromebox_panther_defconfig
+++ b/configs/chromebox_panther_defconfig
@@ -17,9 +17,11 @@ CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
  CONFIG_CROS_EC_LPC=y
+CONFIG_TPM_TIS_LPC=y
  CONFIG_VIDEO_VESA=y
  CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
  CONFIG_DM_RTC=y
  CONFIG_USE_PRIVATE_LIBGCC=y
  CONFIG_SYS_VSNPRINTF=y
+CONFIG_TPM=y
diff --git a/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig 
b/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig
index 37ead03..c8ab862 100644
--- a/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig
+++ b/configs/controlcenterd_36BIT_SDCARD_DEVELOP_defconfig
@@ -4,4 +4,8 @@ CONFIG_TARGET_CONTROLCENTERD=y
  CONFIG_SYS_EXTRA_OPTIONS="36BIT,SDCARD,DEVELOP"
  # CONFIG_CMD_IMLS is not set
  # CONFIG_CMD_FLASH is not set
+CONFIG_CMD_TPM=y
  CONFIG_SPI_FLASH=y
+CONFIG_TPM_ATMEL_TWI=y
+CONFIG_TPM_AUTH_SESSIONS=y
+CONFIG_TPM=y
diff --git a/configs/controlcenterd_36BIT_SDCARD_defconfig 
b/configs/controlcenterd_36BIT_SDCARD_defconfig
index 7166edb..21c0eab 100644
--- a/configs/controlcenterd_36BIT_SDCARD_defconfig
+++ b/configs/controlcenterd_36BIT_SDCARD_defconfig
@@ -4,4 +4,8 @@ CONFIG_TARGET_CONTROLCENTERD=y
  CONFIG_SYS_EXTRA_OPTIONS="36BIT,SDCARD"
  # CONFIG_CMD_IMLS is not set
  # CONFIG_CMD_FLASH is not set
+CONFIG_CMD_TPM=y
  CONFIG_SPI_FLASH=y
+CONFIG_TPM_ATMEL_TWI=y
+CONFIG_TPM_AUTH_SESSIONS=y
+CONFIG_TPM=y
diff --git a/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig 
b/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig
index d99fcd4..c3a0920 100644
--- a/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig
+++ b/configs/controlcenterd_TRAILBLAZER_DEVELOP_defconfig
@@ -6,3 +6,7 @@ CONFIG_SYS_EXTRA_OPTIONS="TRAILBLAZER,SPIFLASH,DEVELOP"
  # CONFIG_CMD_IMLS is not set
  # CONFIG_CMD_FLASH is not set
  # CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_TPM=y
+CONFIG_TPM_ATMEL_TWI=y
+CONFIG_TPM_AUTH_SESSIONS=y
+CONFIG_TPM=y
diff --git a/configs/controlcenterd_TRAILBLAZER_defconfig 
b/configs/controlcenterd_TRAILBLAZER_defconfig
index 3557aea..08aae9a 100644
--- a/configs/controlcenterd_TRAILBLAZER_defconfig
+++ b/configs/controlcenterd_TRAILBLAZER_defconfig
@@ -6,3 +6,7 @@ CONFIG_SYS_EXTRA_OPTIONS="TRAILBLAZER,SPIFLASH"
  # CONFIG_CMD_IMLS is not set
  # CONFIG_CMD_FLASH is not set
  # CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_TPM=y
+CONFIG_TPM_ATMEL_TWI=y
+CONFIG_TPM_AUTH_SESSIONS=y
+CONFIG_TPM=y
diff --git a/configs/coreboot-x86_defconfig b/configs/coreboot-x86_defconfig
index df3a624..66b8caa 100644
--- a/configs/coreboot-x86_defconfig
+++ b/configs/coreboot-x86_defconfig
@@ -14,5 +14,7 @@ CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
  CONFIG_NETDEVICES=y
  CONFIG_E1000=y
+CONFIG_TPM_TIS_LPC=y
  CONFIG_USE_PRIVATE_LIBGCC=y
  CONFIG_SYS_VSNPRINTF=y
+CONFIG_TPM=y
diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index 323a2d3..2be74fd 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -7,11 +7,13 @@ CO

Re: [U-Boot] [PATCH v2 00/28] dm: Convert TPM drivers to driver model

2015-08-24 Thread Christophe Ricard

Hi Simon,

I like your updates but i have few comments:
- I believe tpm_tis_i2c should be renamed as tpm_tis_infineon to be 
aligned with Linux naming.
Also as there is no standard for i2c for tpm, every vendor does have 
their own low level transport protocol.

I believe this is confusing.

- I think atmel tpm driver can be easily move to driver model with this 
new tpm class. I would cleanup some few
#ifdef and make the code even clearer. May be i can try to send an 
update when sending ST33ZP24 TPM driver ?


Other than that, i looks pretty good.

Thanks a lot.
Christophe

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

This series adds driver model support for Trusted Platform Modules (TPMs).
These have a very simple interface and are configured via the device tree.

Two bus types are supported at present: I2C and LPC (Intel Low-Pin-Count).

Most drivers and users are converted over to driver model. The exception is
the Atmel TPM and its users.

The I2C driver has been cleaned up and simplified. It was ported from Linux
and was pretty hard to follow. This series includes patches to unify the
code, remove duplicated data structures and drop unnecessary indirection.

Also this series enables the TPM on all Chromebooks supported by upstream
U-Boot (snow, spring, nyan-big, pit, pi, link, panther) since some did not
have it fully enabled.

As before, the 'tpm' command can be used to implement TPM functionality. In
addition a 'tpmtest' command provides some basic TPM tests taken from
Chrome OS U-Boot. These are fairly rudimentary but are useful if you know
what you are doing.

Changes in v2:
- Add a 'TPM' menu in Kconfig
- Add new patch with a 'tpmtest' command
- Add new patch with functions to access flags and permissions
- Add tpm device tree node for panther also
- Correct error checking code in tpm_sendrecv_command()
- Correct error-checking code in report_return_code()
- Enable 'tpmtest' command for nyan
- Enhance uclass to support timeouts with new send()/recv() methods
- Implement the get_desc() method
- Include tpm.h header file instead of tis.h
- Move the timeout definitions into a new tpm_internal.h header
- Update cover letter to mention panther and the tpmtest command.
- Update driver for the new uclass interface
- Update driver for v2 TPM uclass which supports timeouts
- Use tpm_ prefix instead of tis_ for TPM functions

Simon Glass (28):
   tpm: Remove old pre-driver-model I2C code
   tpm: Drop two unused options
   tpm: Add Kconfig options for TPMs
   tpm: Convert board config TPM options to Kconfig
   tpm: Convert drivers to use SPDX
   tpm: Move the I2C TPM code into one file
   tpm: tpm_tis_i2c: Drop unnecessary methods
   tpm: tpm_tis_i2c: Drop struct tpm_vendor_specific
   tpm: tpm_tis_i2c: Merge struct tpm_dev into tpm_chip
   tpm: tpm_tis_i2c: Merge struct tpm into tpm_chip
   tpm: tpm_tis_i2c: Move definitions into the header file
   tpm: tpm_tis_i2c: Simplify init code
   tpm: tpm_tis_i2c: Use a consistent tpm_tis_i2c_ prefix
   tpm: tpm_tis_i2c: Tidy up delays
   dm: tpm: Add a uclass for Trusted Platform Modules
   dm: tpm: Convert the TPM command and library to driver model
   dm: i2c: Add a command to adjust the offset length
   tpm: Report tpm errors on the command line
   dm: tpm: sandbox: Convert TPM driver to driver model
   tpm: Check that parse_byte_string() has data to parse
   exynos: x86: dts: Add tpm nodes to the device tree for Chrome OS
 devices
   dm: tpm: Convert I2C driver to driver model
   dm: tpm: Convert LPC driver to driver model
   tpm: Add a 'tpm info' command
   tpm: Add functions to access flags and permissions
   dm: tpm: Add a 'tpmtest' command
   tpm: Enable 'tpmtest' command for Chrome OS boards with TPMs
   tegra: nyan: Enable TPM command and driver

  README |   6 -
  arch/arm/dts/exynos5250-snow.dts   |   9 +
  arch/arm/dts/exynos5250-spring.dts |   8 +
  arch/arm/dts/exynos5420-peach-pit.dts  |   6 +-
  arch/arm/dts/exynos5800-peach-pi.dts   |   6 +-
  arch/sandbox/dts/sandbox.dts   |   4 +
  arch/x86/dts/chromebook_link.dts   |   5 +
  arch/x86/dts/chromebox_panther.dts |   5 +
  common/Kconfig |  22 +
  common/Makefile|   1 +
  common/cmd_i2c.c   |  33 +
  common/cmd_tpm.c   | 100 ++-
  common/cmd_tpm_test.c  | 565 +
  configs/chromebook_link_defconfig  |   5 +
  configs/chromebox_panther_defconfig|   5 +
  .../controlcenterd_36BIT_SDCARD_DEVELOP_defconfig  |   4 +
  configs/controlcenterd_36BIT_SDCARD_defconfig  |   4 +
  .../controlcenterd_TRAILBLAZER_DEVELOP_defconfig   |   4 +
  configs/controlcenterd_TRAILBLAZER_defconfig   |   4 +
  configs/coreboot-x86_defconfig

Re: [U-Boot] [PATCH v2 12/28] tpm: tpm_tis_i2c: Simplify init code

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

Move all the init and uninit code into one place.

Signed-off-by: Simon Glass 
---

Changes in v2: None

  drivers/tpm/tpm_tis_i2c.c | 33 ++---
  1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_tis_i2c.c
index 39652a9..9dd40dd 100644
--- a/drivers/tpm/tpm_tis_i2c.c
+++ b/drivers/tpm/tpm_tis_i2c.c
@@ -608,27 +608,6 @@ out:
return rc;
  }
  
-static int tpm_open_dev(struct udevice *dev)

-{
-   int rc;
-
-   debug("%s: start\n", __func__);
-   if (g_chip.is_open)
-   return -EBUSY;
-   rc = tpm_tis_i2c_init(dev);
-   if (rc < 0)
-   g_chip.is_open = 0;
-   return rc;
-}
-
-static void tpm_close(void)
-{
-   if (g_chip.is_open) {
-   release_locality(&g_chip, g_chip.locality, 1);
-   g_chip.is_open = 0;
-   }
-}
-
  /**
   * Decode TPM configuration.
   *
@@ -712,7 +691,12 @@ int tis_open(void)
if (!g_chip.inited)
return -1;
  
-	rc = tpm_open_dev(g_chip.dev);

+   debug("%s: start\n", __func__);
+   if (g_chip.is_open)
+   return -EBUSY;
+   rc = tpm_tis_i2c_init(g_chip.dev);
+   if (rc < 0)
+   g_chip.is_open = 0;
  
  	return rc;

  }
@@ -722,7 +706,10 @@ int tis_close(void)
if (!g_chip.inited)
return -1;
  
-	tpm_close();

+   if (g_chip.is_open) {
+   release_locality(&g_chip, g_chip.locality, 1);
+   g_chip.is_open = 0;
+   }
  
  	return 0;

  }


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


Re: [U-Boot] [PATCH v2 16/28] dm: tpm: Convert the TPM command and library to driver model

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me. Actually, i think atmel driver is trivial to move to 
driver model following the current TPM class.
I would assume this will be changed very soon.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

Add driver model support to the TPM command and the TPM library. Both
support only a single TPM at present.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Correct error checking code in tpm_sendrecv_command()
- Use tpm_ prefix instead of tis_ for TPM functions

  common/cmd_tpm.c | 26 ++
  include/tpm.h|  2 +-
  lib/tpm.c| 31 ++-
  3 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 0294952..bad2006 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -6,6 +6,7 @@
  
  #include 

  #include 
+#include 
  #include 
  #include 
  #include 
@@ -438,6 +439,21 @@ TPM_COMMAND_NO_ARG(tpm_force_clear)
  TPM_COMMAND_NO_ARG(tpm_physical_enable)
  TPM_COMMAND_NO_ARG(tpm_physical_disable)
  
+#ifdef CONFIG_DM_TPM

+static int get_tpm(struct udevice **devp)
+{
+   int rc;
+
+   rc = uclass_first_device(UCLASS_TPM, devp);
+   if (rc) {
+   printf("Could not find TPM (ret=%d)\n", rc);
+   return CMD_RET_FAILURE;
+   }
+
+   return 0;
+}
+#endif
+
  static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
  {
@@ -452,7 +468,17 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}
  
+#ifdef CONFIG_DM_TPM

+   struct udevice *dev;
+
+   rc = get_tpm(&dev);
+   if (rc)
+   return rc;
+
+   rc = tpm_xfer(dev, command, count, response, &response_length);
+#else
rc = tis_sendrecv(command, count, response, &response_length);
+#endif
free(command);
if (!rc) {
puts("tpm response:\n");
diff --git a/include/tpm.h b/include/tpm.h
index e4472d3..445952b 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -349,7 +349,7 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, 
size_t send_size,
   *
   * @return 0 on success, non-0 on error.
   */
-uint32_t tpm_init(void);
+int tpm_init(void);
  
  /**

   * Issue a TPM_Startup command.
diff --git a/lib/tpm.c b/lib/tpm.c
index d9789b0..19bf0b5 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -6,10 +6,11 @@
   */
  
  #include 

-#include 
-#include 
+#include 
+#include 
  #include 
  #include 
+#include 
  
  /* Internal error of TPM command library */

  #define TPM_LIB_ERROR ((uint32_t)~0u)
@@ -240,9 +241,20 @@ static uint32_t tpm_sendrecv_command(const void *command,
response = response_buffer;
response_length = sizeof(response_buffer);
}
+#ifdef CONFIG_DM_TPM
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_first_device(UCLASS_TPM, &dev);
+   if (ret)
+   return ret;
+   err = tpm_xfer(dev, command, tpm_command_size(command),
+  response, &response_length);
+#else
err = tis_sendrecv(command, tpm_command_size(command),
response, &response_length);
-   if (err)
+#endif
+   if (err < 0)
return TPM_LIB_ERROR;
if (size_ptr)
*size_ptr = response_length;
@@ -250,15 +262,24 @@ static uint32_t tpm_sendrecv_command(const void *command,
return tpm_return_code(response);
  }
  
-uint32_t tpm_init(void)

+int tpm_init(void)
  {
-   uint32_t err;
+   int err;
  
+#ifdef CONFIG_DM_TPM

+   struct udevice *dev;
+
+   err = uclass_first_device(UCLASS_TPM, &dev);
+   if (err)
+   return err;
+   return tpm_open(dev);
+#else
err = tis_init();
if (err)
return err;
  
  	return tis_open();

+#endif
  }
  
  uint32_t tpm_startup(enum tpm_startup_type mode)


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


Re: [U-Boot] [PATCH v2 15/28] dm: tpm: Add a uclass for Trusted Platform Modules

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me as well.
 
Acked-by: Christophe Ricard


Best Regards
Christophe

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

Add a new uclass for TPMs which uses almost the same TIS (TPM Interface
Specification) as is currently implemented. Since init() is handled by the
normal driver model probe() method, we don't need to implement that. Also
rename the transfer method to xfer() which is a less clumbsy name.

Once all drivers and users are converted to driver model we can remove the
old code.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Enhance uclass to support timeouts with new send()/recv() methods
- Move the timeout definitions into a new tpm_internal.h header
- Use tpm_ prefix instead of tis_ for TPM functions

  drivers/tpm/Kconfig|   9 ++
  drivers/tpm/Makefile   |   2 +
  drivers/tpm/tpm-uclass.c   | 133 +
  drivers/tpm/tpm_internal.h | 287 +
  drivers/tpm/tpm_tis_i2c.c  |   2 +
  drivers/tpm/tpm_tis_i2c.h  | 283 
  drivers/tpm/tpm_tis_lpc.c  |   4 +-
  include/dm/uclass-id.h |   1 +
  include/tis.h  |   3 +
  include/tpm.h  | 192 ++
  10 files changed, 630 insertions(+), 286 deletions(-)
  create mode 100644 drivers/tpm/tpm-uclass.c
  create mode 100644 drivers/tpm/tpm_internal.h

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 9101fc2..6bc8fdd 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -4,6 +4,15 @@
  
  menu "TPM support"
  
+config DM_TPM

+   bool "Enable driver model for Trusted Platform Module drivers"
+   depends on DM && TPM
+   help
+  Enable driver model for TPMs. The TIS interface (tis_open(),
+ tis_sendrecv(), etc.) is then implemented by the TPM uclass. Note
+ that even with driver model only a single TPM is currently
+ supported, since the tpm library assumes this.
+
  config TPM_TIS_SANDBOX
bool "Enable sandbox TPM driver"
depends on SANDBOX
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 597966c..0d328f8 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -3,6 +3,8 @@
  # SPDX-License-Identifier:GPL-2.0+
  #
  
+obj-$(CONFIG_DM_TPM) += tpm-uclass.o

+
  obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
  obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
  obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
new file mode 100644
index 000..b6e1fc5
--- /dev/null
+++ b/drivers/tpm/tpm-uclass.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass 
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "tpm_internal.h"
+
+int tpm_open(struct udevice *dev)
+{
+   struct tpm_ops *ops = tpm_get_ops(dev);
+
+   if (!ops->open)
+   return -ENOSYS;
+
+   return ops->open(dev);
+}
+
+int tpm_close(struct udevice *dev)
+{
+   struct tpm_ops *ops = tpm_get_ops(dev);
+
+   if (!ops->close)
+   return -ENOSYS;
+
+   return ops->close(dev);
+}
+
+int tpm_get_desc(struct udevice *dev, char *buf, int size)
+{
+   struct tpm_ops *ops = tpm_get_ops(dev);
+
+   if (!ops->get_desc)
+   return -ENOSYS;
+
+   return ops->get_desc(dev, buf, size);
+}
+
+/* Returns max number of milliseconds to wait */
+static ulong tpm_tis_i2c_calc_ordinal_duration(struct tpm_chip_priv *priv,
+  u32 ordinal)
+{
+   int duration_idx = TPM_UNDEFINED;
+   int duration = 0;
+
+   if (ordinal < TPM_MAX_ORDINAL) {
+   duration_idx = tpm_ordinal_duration[ordinal];
+   } else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
+   TPM_MAX_PROTECTED_ORDINAL) {
+   duration_idx = tpm_protected_ordinal_duration[
+   ordinal & TPM_PROTECTED_ORDINAL_MASK];
+   }
+
+   if (duration_idx != TPM_UNDEFINED)
+   duration = priv->duration_ms[duration_idx];
+
+   if (duration <= 0)
+   return 2 * 60 * 1000; /* Two minutes timeout */
+   else
+   return duration;
+}
+
+int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
+   uint8_t *recvbuf, size_t *recv_size)
+{
+   struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+   struct tpm_ops *ops = tpm_get_ops(dev);
+   ulong start, stop;
+   uint count, ordinal;
+   int ret, ret2;
+
+   if (ops->xfer)
+   return ops->xfer(dev, sendbuf, send_size, recvbuf, recv_size);
+
+   if (!ops->send || !ops->recv)
+   return -ENOSYS;
+
+   /* switch endianess: big->little */
+   count = get_unaligned_be32(sendbuf + TPM_CMD_C

Re: [U-Boot] [PATCH v2 17/28] dm: i2c: Add a command to adjust the offset length

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one is fine with me.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

I2C chips can support a register offset, with registers accessible by
sending this offset as the first part of any read or write transaction.
Most I2C chips have a single byte offset, thus the offset length is 1.
This provides access for up 256 registers.

However other offset lengths are supported, including 0.

Add a command to provide access to the offset length from the command
line. This allows the offset length to be read or written.

Signed-off-by: Simon Glass 
---

Changes in v2: None

  common/cmd_i2c.c | 33 +
  1 file changed, 33 insertions(+)

diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index 1bc0db8..864b259 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -453,6 +453,37 @@ static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int 
argc,
  
  	return 0;

  }
+
+static int do_i2c_olen(cmd_tbl_t *cmdtp, int flag, int argc, char *const 
argv[])
+{
+   struct udevice *dev;
+   uint olen;
+   int chip;
+   int ret;
+
+   if (argc < 2)
+   return CMD_RET_USAGE;
+
+   chip = simple_strtoul(argv[1], NULL, 16);
+   ret = i2c_get_cur_bus_chip(chip, &dev);
+   if (ret)
+   return i2c_report_err(ret, I2C_ERR_READ);
+
+   if (argc > 2) {
+   olen = simple_strtoul(argv[2], NULL, 16);
+   ret = i2c_set_chip_offset_len(dev, olen);
+   } else  {
+   ret = i2c_get_chip_offset_len(dev);
+   if (ret >= 0) {
+   printf("%x\n", ret);
+   ret = 0;
+   }
+   }
+   if (ret)
+   return i2c_report_err(ret, I2C_ERR_READ);
+
+   return 0;
+}
  #endif
  
  /**

@@ -1903,6 +1934,7 @@ static cmd_tbl_t cmd_i2c_sub[] = {
U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
  #ifdef CONFIG_DM_I2C
U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
+   U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""),
  #endif
U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
  #if defined(CONFIG_CMD_SDRAM)
@@ -1971,6 +2003,7 @@ static char i2c_help_text[] =
"  to I2C; the -s option selects bulk write in a single 
transaction\n"
  #ifdef CONFIG_DM_I2C
"i2c flags chip [flags] - set or get chip flags\n"
+   "i2c olen chip [offset_length] - set or get chip offset length\n"
  #endif
"i2c reset - re-init the I2C Controller\n"
  #if defined(CONFIG_CMD_SDRAM)


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


Re: [U-Boot] [PATCH v2 18/28] tpm: Report tpm errors on the command line

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

When a 'tpm' command fails, we set the return code but give no indication
of failure. This can be confusing.

Add an error message when any tpm command fails.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Correct error-checking code in report_return_code()

  common/cmd_tpm.c | 46 --
  1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index bad2006..65e7371 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -80,17 +80,19 @@ static void *parse_byte_string(char *bytes, uint8_t *data, 
size_t *count_ptr)
  }
  
  /**

- * Convert TPM command return code to U-Boot command error codes.
+ * report_return_code() - Report any error and return failure or success
   *
   * @param return_code TPM command return code
   * @return value of enum command_ret_t
   */
-static int convert_return_code(uint32_t return_code)
+static int report_return_code(int return_code)
  {
-   if (return_code)
+   if (return_code) {
+   printf("Error: %d\n", return_code);
return CMD_RET_FAILURE;
-   else
+   } else {
return CMD_RET_SUCCESS;
+   }
  }
  
  /**

@@ -252,7 +254,7 @@ static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}
  
-	return convert_return_code(tpm_startup(mode));

+   return report_return_code(tpm_startup(mode));
  }
  
  static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,

@@ -266,7 +268,7 @@ static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int 
flag,
perm = simple_strtoul(argv[2], NULL, 0);
size = simple_strtoul(argv[3], NULL, 0);
  
-	return convert_return_code(tpm_nv_define_space(index, perm, size));

+   return report_return_code(tpm_nv_define_space(index, perm, size));
  }
  
  static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,

@@ -287,7 +289,7 @@ static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
print_byte_string(data, count);
}
  
-	return convert_return_code(rc);

+   return report_return_code(rc);
  }
  
  static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,

@@ -309,7 +311,7 @@ static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
rc = tpm_nv_write_value(index, data, count);
free(data);
  
-	return convert_return_code(rc);

+   return report_return_code(rc);
  }
  
  static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,

@@ -332,7 +334,7 @@ static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
print_byte_string(out_digest, sizeof(out_digest));
}
  
-	return convert_return_code(rc);

+   return report_return_code(rc);
  }
  
  static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,

@@ -353,7 +355,7 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
print_byte_string(data, count);
}
  
-	return convert_return_code(rc);

+   return report_return_code(rc);
  }
  
  static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,

@@ -365,7 +367,7 @@ static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, 
int flag,
return CMD_RET_USAGE;
presence = (uint16_t)simple_strtoul(argv[1], NULL, 0);
  
-	return convert_return_code(tpm_tsc_physical_presence(presence));

+   return report_return_code(tpm_tsc_physical_presence(presence));
  }
  
  static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,

@@ -385,7 +387,7 @@ static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
print_byte_string(data, count);
}
  
-	return convert_return_code(rc);

+   return report_return_code(rc);
  }
  
  static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,

@@ -397,7 +399,7 @@ static int do_tpm_physical_set_deactivated(cmd_tbl_t 
*cmdtp, int flag,
return CMD_RET_USAGE;
state = (uint8_t)simple_strtoul(argv[1], NULL, 0);
  
-	return convert_return_code(tpm_physical_set_deactivated(state));

+   return report_return_code(tpm_physical_set_deactivated(state));
  }
  
  static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,

@@ -420,7 +422,7 @@ static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
print_byte_string(cap, count);
}
  
-	return convert_return_code(rc);

+   return report_return_code(rc);
  }
  
  #define TPM_COMMAND_NO_ARG(cmd)\

@@ -429,7 +431,7 @@ static int do_##cmd(cmd_tbl_t *cmdtp, int flag, 
\
  { \
if (argc != 1)  \
return CMD_RET_USAGE;   \
-   return convert_return_code(cmd());  \
+   return report_return_code(cmd());   \
  }
  
  TPM_COMMAND_NO_ARG(tpm_ini

Re: [U-Boot] [PATCH v2 21/28] exynos: x86: dts: Add tpm nodes to the device tree for Chrome OS devices

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

Add a TPM node to the various Chromebooks so that driver can be converted to
driver model.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add tpm device tree node for panther also

  arch/arm/dts/exynos5250-snow.dts  | 9 +
  arch/arm/dts/exynos5250-spring.dts| 8 
  arch/arm/dts/exynos5420-peach-pit.dts | 6 +++---
  arch/arm/dts/exynos5800-peach-pi.dts  | 6 +++---
  arch/x86/dts/chromebook_link.dts  | 5 +
  arch/x86/dts/chromebox_panther.dts| 5 +
  6 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/exynos5250-snow.dts b/arch/arm/dts/exynos5250-snow.dts
index 32c0098..bda5499 100644
--- a/arch/arm/dts/exynos5250-snow.dts
+++ b/arch/arm/dts/exynos5250-snow.dts
@@ -206,6 +206,15 @@
};
};
  
+	i2c@12C9 {

+   clock-frequency = <10>;
+   tpm@20 {
+   reg = <0x20>;
+   u-boot,i2c-offset-len = <0>;
+   compatible = "infineon,slb9635tt";
+   };
+   };
+
spi@12d3 {
spi-max-frequency = <5000>;
firmware_storage_spi: flash@0 {
diff --git a/arch/arm/dts/exynos5250-spring.dts 
b/arch/arm/dts/exynos5250-spring.dts
index 76d5323..81b3d29 100644
--- a/arch/arm/dts/exynos5250-spring.dts
+++ b/arch/arm/dts/exynos5250-spring.dts
@@ -59,6 +59,14 @@
 <&gpy4 2 0>;
};
  
+	i2c@12C9 {

+   clock-frequency = <10>;
+   tpm@20 {
+   reg = <0x20>;
+   compatible = "infineon,slb9645tt";
+   };
+   };
+
mmc@1220 {
samsung,bus-width = <8>;
samsung,timing = <1 3 3>;
diff --git a/arch/arm/dts/exynos5420-peach-pit.dts 
b/arch/arm/dts/exynos5420-peach-pit.dts
index 2d2b7c9..16d52f4 100644
--- a/arch/arm/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/dts/exynos5420-peach-pit.dts
@@ -197,9 +197,9 @@
  
  	i2c@12E1 { /* i2c9 */

clock-frequency = <40>;
-tpm@20 {
-compatible = "infineon,slb9645tt";
-reg = <0x20>;
+   tpm@20 {
+   compatible = "infineon,slb9645tt";
+   reg = <0x20>;
};
};
  
diff --git a/arch/arm/dts/exynos5800-peach-pi.dts b/arch/arm/dts/exynos5800-peach-pi.dts

index 600c294..1d7ff23 100644
--- a/arch/arm/dts/exynos5800-peach-pi.dts
+++ b/arch/arm/dts/exynos5800-peach-pi.dts
@@ -72,9 +72,9 @@
  
  	i2c@12E1 { /* i2c9 */

clock-frequency = <40>;
-tpm@20 {
-compatible = "infineon,slb9645tt";
-reg = <0x20>;
+   tpm@20 {
+   compatible = "infineon,slb9645tt";
+   reg = <0x20>;
};
};
  
diff --git a/arch/x86/dts/chromebook_link.dts b/arch/x86/dts/chromebook_link.dts

index ad390bf..4291141 100644
--- a/arch/x86/dts/chromebook_link.dts
+++ b/arch/x86/dts/chromebook_link.dts
@@ -237,6 +237,11 @@
};
};
  
+	tpm {

+   reg = <0xfed4 0x5000>;
+   compatible = "infineon,slb9635lpc";
+   };
+
microcode {
update@0 {
  #include "microcode/m12306a9_001b.dtsi"
diff --git a/arch/x86/dts/chromebox_panther.dts 
b/arch/x86/dts/chromebox_panther.dts
index 84eae3a..36feb96 100644
--- a/arch/x86/dts/chromebox_panther.dts
+++ b/arch/x86/dts/chromebox_panther.dts
@@ -62,4 +62,9 @@
};
};
  
+	tpm {

+   reg = <0xfed4 0x5000>;
+   compatible = "infineon,slb9635lpc";
+   };
+
  };


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


Re: [U-Boot] [PATCH v2 20/28] tpm: Check that parse_byte_string() has data to parse

2015-08-24 Thread Christophe Ricard

Hi Simon,

Print an error ? Are you sure ? I guess the comment is not accurate ;).

Best Regards
Christophe

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

Rather then crashing when there is no data, print an error.

Acked-by: Christophe Ricard 
Signed-off-by: Simon Glass 
---

Changes in v2: None

  common/cmd_tpm.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 65e7371..e9c6618 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -58,6 +58,8 @@ static void *parse_byte_string(char *bytes, uint8_t *data, 
size_t *count_ptr)
size_t count, length;
int i;
  
+	if (!bytes)

+   return NULL;
length = strlen(bytes);
count = length / 2;
  


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


Re: [U-Boot] [PATCH v2 25/28] tpm: Add functions to access flags and permissions

2015-08-24 Thread Christophe Ricard

Acked-by: Christophe Ricard


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

Add a few new functions which will be used by the test command in a future
patch.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch with functions to access flags and permissions

  include/tpm.h | 49 +
  lib/tpm.c | 51 ++-
  2 files changed, 99 insertions(+), 1 deletion(-)

diff --git a/include/tpm.h b/include/tpm.h
index 445952b..086b672 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -49,6 +49,15 @@ enum tpm_nv_index {
TPM_NV_INDEX_DIR= 0x1001,
  };
  
+#define TPM_NV_PER_GLOBALLOCK		(1U << 15)

+#define TPM_NV_PER_PPWRITE (1U << 0)
+#define TPM_NV_PER_READ_STCLEAR(1U << 31)
+#define TPM_NV_PER_WRITE_STCLEAR   (1U << 14)
+
+enum {
+   TPM_PUBEK_SIZE  = 256,
+};
+
  /**
   * TPM return codes as defined in the TCG Main specification
   * (TPM Main Part 2 Structures; Specification version 1.2)
@@ -163,6 +172,30 @@ enum tpm_return_code {
TPM_DEFEND_LOCK_RUNNING = TPM_BASE + TPM_NON_FATAL + 3,
  };
  
+struct tpm_permanent_flags {

+   __be16  tag;
+   u8  disable;
+   u8  ownership;
+   u8  deactivated;
+   u8  read_pubek;
+   u8  disable_owner_clear;
+   u8  allow_maintenance;
+   u8  physical_presence_lifetime_lock;
+   u8  physical_presence_hw_enable;
+   u8  physical_presence_cmd_enable;
+   u8  cekp_used;
+   u8  tpm_post;
+   u8  tpm_post_lock;
+   u8  fips;
+   u8  operator;
+   u8  enable_revoke_ek;
+   u8  nv_locked;
+   u8  read_srk_pub;
+   u8  tpm_established;
+   u8  maintenance_done;
+   u8  disable_full_da_logic_info;
+} __packed;
+
  #ifdef CONFIG_DM_TPM
  
  /* Max buffer size supported by our tpm */

@@ -551,4 +584,20 @@ uint32_t tpm_load_key2_oiap(uint32_t parent_handle,
  uint32_t tpm_get_pub_key_oiap(uint32_t key_handle, const void *usage_auth,
void *pubkey, size_t *pubkey_len);
  
+/**

+ * Get the TPM permanent flags value
+ *
+ * @param pflags   Place to put permanent flags
+ * @return return code of the operation
+ */
+uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags);
+
+/**
+ * Get the TPM permissions
+ *
+ * @param perm Returns permissions value
+ * @return return code of the operation
+ */
+uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm);
+
  #endif /* __TPM_H */
diff --git a/lib/tpm.c b/lib/tpm.c
index 19bf0b5..5d5f707 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -18,7 +18,6 @@
  /* Useful constants */
  enum {
COMMAND_BUFFER_SIZE = 256,
-   TPM_PUBEK_SIZE  = 256,
TPM_REQUEST_HEADER_LENGTH   = 10,
TPM_RESPONSE_HEADER_LENGTH  = 10,
PCR_DIGEST_LENGTH   = 20,
@@ -610,6 +609,56 @@ uint32_t tpm_get_capability(uint32_t cap_area, uint32_t 
sub_cap,
return 0;
  }
  
+uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags)

+{
+   const uint8_t command[22] = {
+   0x0, 0xc1,  /* TPM_TAG */
+   0x0, 0x0, 0x0, 0x16,/* parameter size */
+   0x0, 0x0, 0x0, 0x65,/* TPM_COMMAND_CODE */
+   0x0, 0x0, 0x0, 0x4, /* TPM_CAP_FLAG_PERM */
+   0x0, 0x0, 0x0, 0x4, /* subcap size */
+   0x0, 0x0, 0x1, 0x8, /* subcap value */
+   };
+   uint8_t response[COMMAND_BUFFER_SIZE];
+   size_t response_length = sizeof(response);
+   uint32_t err;
+
+   err = tpm_sendrecv_command(command, response, &response_length);
+   if (err)
+   return err;
+   memcpy(pflags, response + TPM_HEADER_SIZE, sizeof(*pflags));
+
+   return 0;
+}
+
+uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm)
+{
+   const uint8_t command[22] = {
+   0x0, 0xc1,  /* TPM_TAG */
+   0x0, 0x0, 0x0, 0x16,/* parameter size */
+   0x0, 0x0, 0x0, 0x65,/* TPM_COMMAND_CODE */
+   0x0, 0x0, 0x0, 0x11,
+   0x0, 0x0, 0x0, 0x4,
+   };
+   const size_t index_offset = 18;
+   const size_t perm_offset = 60;
+   uint8_t buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE];
+   size_t response_length = sizeof(response);
+   uint32_t err;
+
+   if (pack_byte_string(buf, sizeof(buf), "d", 0, command, sizeof(command),
+index_offset, index))
+   return TPM_LIB_ERROR;
+   err = tpm_sendrecv_command(buf, response, &response_length);
+   if (err)
+   return err;
+   if (unpack_byte_string(response, response_length, "d",
+  perm_offset, perm))
+   ret

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 Ricard

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 
---

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 
  #include 
  #include 
-#include 
  #include 
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  
@@ -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 */
   

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

2015-08-24 Thread Christophe Ricard

Hi Simon,

Acked-by: Christophe Ricard

Best Regards
Christophe

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

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

Signed-off-by: Simon Glass 
---

Changes in v2:
- Update driver for the new uclass interface

  configs/chromebook_link_defconfig   |   2 +
  configs/chromebox_panther_defconfig |   2 +
  configs/coreboot-x86_defconfig  |   2 +
  drivers/tpm/tpm_tis_lpc.c   | 286 +---
  4 files changed, 137 insertions(+), 155 deletions(-)

diff --git a/configs/chromebook_link_defconfig 
b/configs/chromebook_link_defconfig
index b0fc5ca..85752e4 100644
--- a/configs/chromebook_link_defconfig
+++ b/configs/chromebook_link_defconfig
@@ -11,12 +11,14 @@ CONFIG_HAVE_VGA_BIOS=y
  CONFIG_BOOTSTAGE=y
  CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_BOOTSTAGE=y
+CONFIG_CMD_TPM=y
  CONFIG_OF_CONTROL=y
  CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
  CONFIG_CROS_EC_LPC=y
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_LPC=y
  CONFIG_VIDEO_VESA=y
  CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
diff --git a/configs/chromebox_panther_defconfig 
b/configs/chromebox_panther_defconfig
index e7ef8fe..a6bafe3 100644
--- a/configs/chromebox_panther_defconfig
+++ b/configs/chromebox_panther_defconfig
@@ -11,12 +11,14 @@ CONFIG_HAVE_VGA_BIOS=y
  CONFIG_BOOTSTAGE=y
  CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_BOOTSTAGE=y
+CONFIG_CMD_TPM=y
  CONFIG_OF_CONTROL=y
  CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
  CONFIG_CROS_EC_LPC=y
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_LPC=y
  CONFIG_VIDEO_VESA=y
  CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
diff --git a/configs/coreboot-x86_defconfig b/configs/coreboot-x86_defconfig
index 66b8caa..fda2b7e 100644
--- a/configs/coreboot-x86_defconfig
+++ b/configs/coreboot-x86_defconfig
@@ -9,11 +9,13 @@ CONFIG_TSC_CALIBRATION_BYPASS=y
  CONFIG_BOOTSTAGE=y
  CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_BOOTSTAGE=y
+CONFIG_CMD_TPM=y
  CONFIG_OF_CONTROL=y
  CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
  CONFIG_NETDEVICES=y
  CONFIG_E1000=y
+CONFIG_DM_TPM=y
  CONFIG_TPM_TIS_LPC=y
  CONFIG_USE_PRIVATE_LIBGCC=y
  CONFIG_SYS_VSNPRINTF=y
diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c
index 3109c50..b41c3ce 100644
--- a/drivers/tpm/tpm_tis_lpc.c
+++ b/drivers/tpm/tpm_tis_lpc.c
@@ -14,9 +14,11 @@
   */
  
  #include 

-#include 
+#include 
+#include 
  #include 
  #include 
+#include 
  
  #define PREFIX "lpc_tpm: "
  
@@ -37,13 +39,15 @@ struct tpm_locality {

u8 padding4[251];
  };
  
+struct tpm_tis_lpc_priv {

+   struct tpm_locality *regs;
+};
+
  /*
   * This pointer refers to the TPM chip, 5 of its localities are mapped as an
   * array.
   */
  #define TPM_TOTAL_LOCALITIES  5
-static struct tpm_locality *lpc_tpm_dev =
-   (struct tpm_locality *)CONFIG_TPM_TIS_BASE_ADDRESS;
  
  /* Some registers' bit field definitions */

  #define TIS_STS_VALID  (1 << 7) /* 0x80 */
@@ -64,85 +68,45 @@ static struct tpm_locality *lpc_tpm_dev =
  #define TIS_STS_BURST_COUNT_MASK   (0x)
  #define TIS_STS_BURST_COUNT_SHIFT  (8)
  
-/*

- * Error value returned if a tpm register does not enter the expected state
- * after continuous polling. No actual TPM register reading ever returns -1,
- * so this value is a safe error indication to be mixed with possible status
- * register values.
- */
-#define TPM_TIMEOUT_ERR(-1)
-
-/* Error value returned on various TPM driver errors. */
-#define TPM_DRIVER_ERR (1)
-
   /* 1 second is plenty for anything TPM does. */
  #define MAX_DELAY_US  (1000 * 1000)
  
  /* Retrieve burst count value out of the status register contents. */

  static u16 burst_count(u32 status)
  {
-   return (status >> TIS_STS_BURST_COUNT_SHIFT) & TIS_STS_BURST_COUNT_MASK;
+   return (status >> TIS_STS_BURST_COUNT_SHIFT) &
+   TIS_STS_BURST_COUNT_MASK;
  }
  
-/*

- * Structures defined below allow creating descriptions of TPM vendor/device
- * ID information for run time discovery. The only device the system knows
- * about at this time is Infineon slb9635.
- */
-struct device_name {
-   u16 dev_id;
-   const char * const dev_name;
-};
-
-struct vendor_name {
-   u16 vendor_id;
-   const char *vendor_name;
-   const struct device_name *dev_names;
-};
-
-static const struct device_name infineon_devices[] = {
-   {0xb, "SLB9635 TT 1.2"},
-   {0}
-};
-
-static const struct vendor_name vendor_names[] = {
-   {0x15d1, "Infineon", infineon_devices},
-};
-
-/*
- * Cached vendor/device ID pair to indicate that the device has been already
- * discovered.
- */
-static u32 vendor_dev_id;
-
  /* TPM access wrappers to support tracing */
-static u8 tpm_read_byte(const u8 *ptr)
+static u8 tpm_read_byte(struct tpm_tis_lpc_priv *priv, const u8 *ptr)
  {
u8  ret = readb(p

Re: [U-Boot] [PATCH v2 26/28] dm: tpm: Add a 'tpmtest' command

2015-08-24 Thread Christophe Ricard

Hi Simon,

Acked-by: Christophe Ricard

I will try those tpm tests.

Best Regards
Christophe

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

These tests come from Chrome OS code. They are not particularly tidy but can
be useful for checking that the TPM is behaving correctly. Some knowledge of
TPM operation is required to use these.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch with a 'tpmtest' command

  common/Kconfig|  10 +
  common/Makefile   |   1 +
  common/cmd_tpm_test.c | 565 ++
  3 files changed, 576 insertions(+)
  create mode 100644 common/cmd_tpm_test.c

diff --git a/common/Kconfig b/common/Kconfig
index bacc4e0..2c42b8e 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -635,6 +635,16 @@ config CMD_TPM
  command requires a suitable TPM on your board and the correct driver
  must be enabled.
  
+config CMD_TPM_TEST

+   bool "Enable the 'tpm test' command"
+   depends on CMD_TPM
+   help
+ This provides a a series of tests to confirm that the TPM is working
+ correctly. The tests cover initialisation, non-volatile RAM, extend,
+ global lock and checking that timing is within expectations. The
+ tests pass correctly on Infineon TPMs but may need to be adjusted
+ for other devices.
+
  endmenu
  
  endmenu

diff --git a/common/Makefile b/common/Makefile
index dc82433..f4ba878 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_TIME) += cmd_time.o
  obj-$(CONFIG_CMD_TRACE) += cmd_trace.o
  obj-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
  obj-$(CONFIG_CMD_TPM) += cmd_tpm.o
+obj-$(CONFIG_CMD_TPM_TEST) += cmd_tpm_test.o
  obj-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
  obj-$(CONFIG_CMD_UBI) += cmd_ubi.o
  obj-$(CONFIG_CMD_UBIFS) += cmd_ubifs.o
diff --git a/common/cmd_tpm_test.c b/common/cmd_tpm_test.c
new file mode 100644
index 000..2bef5a1
--- /dev/null
+++ b/common/cmd_tpm_test.c
@@ -0,0 +1,565 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* Prints error and returns on failure */
+#define TPM_CHECK(tpm_command) do { \
+   uint32_t result; \
+   \
+   result = (tpm_command); \
+   if (result != TPM_SUCCESS) { \
+   printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \
+   __LINE__, result); \
+   return result; \
+   } \
+} while (0)
+
+#define INDEX0 0xda70
+#define INDEX1 0xda71
+#define INDEX2 0xda72
+#define INDEX3 0xda73
+#define INDEX_INITIALISED  0xda80
+#define PHYS_PRESENCE  4
+#define PRESENCE   8
+
+static uint32_t TlclStartupIfNeeded(void)
+{
+   uint32_t result = tpm_startup(TPM_ST_CLEAR);
+
+   return result == TPM_INVALID_POSTINIT ? TPM_SUCCESS : result;
+}
+
+static int test_timer(void)
+{
+   printf("get_timer(0) = %lu\n", get_timer(0));
+   return 0;
+}
+
+static uint32_t tpm_get_flags(uint8_t *disable, uint8_t *deactivated,
+ uint8_t *nvlocked)
+{
+   struct tpm_permanent_flags pflags;
+   uint32_t result;
+
+   result = tpm_get_permanent_flags(&pflags);
+   if (result)
+   return result;
+   if (disable)
+   *disable = pflags.disable;
+   if (deactivated)
+   *deactivated = pflags.deactivated;
+   if (nvlocked)
+   *nvlocked = pflags.nv_locked;
+   debug("TPM: Got flags disable=%d, deactivated=%d, nvlocked=%d\n",
+ pflags.disable, pflags.deactivated, pflags.nv_locked);
+
+   return 0;
+}
+
+static uint32_t tpm_set_global_lock(void)
+{
+   uint32_t x;
+
+   debug("TPM: Set global lock\n");
+   return tpm_nv_write_value(INDEX0, (uint8_t *)&x, 0);
+}
+
+static uint32_t tpm_nv_write_value_lock(uint32_t index)
+{
+   debug("TPM: Write lock 0x%x\n", index);
+
+   return tpm_nv_write_value(index, NULL, 0);
+}
+
+static uint32_t tpm_nv_set_locked(void)
+{
+   debug("TPM: Set NV locked\n");
+
+   return tpm_nv_define_space(TPM_NV_INDEX_LOCK, 0, 0);
+}
+
+static int tpm_is_owned(void)
+{
+   uint8_t response[TPM_PUBEK_SIZE];
+   uint32_t result;
+
+   result = tpm_read_pubek(response, sizeof(response));
+
+   return result != TPM_SUCCESS;
+}
+
+static int test_early_extend(void)
+{
+   uint8_t value_in[20];
+   uint8_t value_out[20];
+
+   printf("Testing earlyextend ...");
+   tpm_init();
+   TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
+   TPM_CHECK(tpm_continue_self_test());
+   TPM_CHECK(tpm_extend(1, value_in, value_out));
+   printf("done\n");
+   return 0;
+}
+
+static int test_early_nvram(void)
+{
+   uint32_t x;

Re: [U-Boot] [PATCH v2 27/28] tpm: Enable 'tpmtest' command for Chrome OS boards with TPMs

2015-08-24 Thread Christophe Ricard

Acked-by: Christophe Ricard


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

This command provides a few useful tests so enable it for common boards.

Signed-off-by: Simon Glass 
---

Changes in v2: None

  configs/chromebook_link_defconfig   | 1 +
  configs/chromebox_panther_defconfig | 1 +
  configs/coreboot-x86_defconfig  | 1 +
  configs/peach-pi_defconfig  | 1 +
  configs/peach-pit_defconfig | 1 +
  configs/sandbox_defconfig   | 1 +
  configs/snow_defconfig  | 1 +
  configs/spring_defconfig| 1 +
  8 files changed, 8 insertions(+)

diff --git a/configs/chromebook_link_defconfig 
b/configs/chromebook_link_defconfig
index 85752e4..9855736 100644
--- a/configs/chromebook_link_defconfig
+++ b/configs/chromebook_link_defconfig
@@ -12,6 +12,7 @@ CONFIG_BOOTSTAGE=y
  CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_BOOTSTAGE=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_OF_CONTROL=y
  CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
diff --git a/configs/chromebox_panther_defconfig 
b/configs/chromebox_panther_defconfig
index a6bafe3..c75b20d 100644
--- a/configs/chromebox_panther_defconfig
+++ b/configs/chromebox_panther_defconfig
@@ -12,6 +12,7 @@ CONFIG_BOOTSTAGE=y
  CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_BOOTSTAGE=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_OF_CONTROL=y
  CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
diff --git a/configs/coreboot-x86_defconfig b/configs/coreboot-x86_defconfig
index fda2b7e..ebaf86b 100644
--- a/configs/coreboot-x86_defconfig
+++ b/configs/coreboot-x86_defconfig
@@ -10,6 +10,7 @@ CONFIG_BOOTSTAGE=y
  CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_BOOTSTAGE=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_OF_CONTROL=y
  CONFIG_DM_PCI=y
  CONFIG_SPI_FLASH=y
diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index 6416f16..56a5185 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -8,6 +8,7 @@ CONFIG_SPL=y
  CONFIG_CMD_PMIC=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig
index d0646ab..1934bf3 100644
--- a/configs/peach-pit_defconfig
+++ b/configs/peach-pit_defconfig
@@ -8,6 +8,7 @@ CONFIG_SPL=y
  CONFIG_CMD_PMIC=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 2600bf7..4034a2e 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -12,6 +12,7 @@ CONFIG_BOOTSTAGE_REPORT=y
  CONFIG_CMD_PMIC=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_OF_CONTROL=y
  CONFIG_OF_HOSTFILE=y
  CONFIG_CLK=y
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index 7624ad2..32c7c5d 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -9,6 +9,7 @@ CONFIG_CMD_SOUND=y
  CONFIG_CMD_PMIC=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y
diff --git a/configs/spring_defconfig b/configs/spring_defconfig
index 3b109fa..b20bfed 100644
--- a/configs/spring_defconfig
+++ b/configs/spring_defconfig
@@ -9,6 +9,7 @@ CONFIG_CMD_SOUND=y
  CONFIG_CMD_PMIC=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_CMD_TPM=y
+CONFIG_CMD_TPM_TEST=y
  CONFIG_SPI_FLASH=y
  CONFIG_CMD_CROS_EC=y
  CONFIG_CROS_EC=y


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


Re: [U-Boot] [PATCH v2 06/28] tpm: Move the I2C TPM code into one file

2015-08-24 Thread Christophe Ricard

Hi Simon,

I don't disagree with this patch (from patch 6 to patch 12).
However, i believe it would be better to have this driver renamed 
tpm_i2c_infineon as shown in my previous patch:

http://lists.denx.de/pipermail/u-boot/2015-August/223582.html

Could you update this ?

Best Regards
Christophe

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

The current Infineon I2C TPM driver is written in two parts, intended to
support use with other I2C devices. However we don't have any users and the
Atmel I2C TPM device does not use this file.

We should simplify this and remove the unused abstration. As a first step,
move the code into one file.

Also the name tpm_private.h suggests that the header file is generic to all
TPMs but it is not. Rename it indicate that it relates only to this driver

Signed-off-by: Simon Glass 
---

Changes in v2: None

  drivers/tpm/Makefile |   2 -
  drivers/tpm/tpm.c| 594 ---
  drivers/tpm/tpm_tis_i2c.c| 548 +++-
  drivers/tpm/{tpm_private.h => tpm_tis_i2c.h} |  24 +-
  4 files changed, 550 insertions(+), 618 deletions(-)
  delete mode 100644 drivers/tpm/tpm.c
  rename drivers/tpm/{tpm_private.h => tpm_tis_i2c.h} (73%)

diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 150570e..597966c 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -3,9 +3,7 @@
  # SPDX-License-Identifier:GPL-2.0+
  #
  
-# TODO: Merge tpm_tis_lpc.c with tpm.c

  obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
-obj-$(CONFIG_TPM_TIS_I2C) += tpm.o
  obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
  obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
  obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
diff --git a/drivers/tpm/tpm.c b/drivers/tpm/tpm.c
deleted file mode 100644
index 24997f6..000
--- a/drivers/tpm/tpm.c
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * Copyright (C) 2011 Infineon Technologies
- *
- * Authors:
- * Peter Huewe 
- *
- * Description:
- * Device driver for TCG/TCPA TPM (trusted platform module).
- * Specifications at www.trustedcomputinggroup.org
- *
- * It is based on the Linux kernel driver tpm.c from Leendert van
- * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
- *
- * Version: 2.1.1
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, version 2 of the
- * License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "tpm_private.h"
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/* TPM configuration */
-struct tpm {
-   struct udevice *dev;
-   char inited;
-} tpm;
-
-/* Global structure for tpm chip data */
-static struct tpm_chip g_chip;
-
-enum tpm_duration {
-   TPM_SHORT = 0,
-   TPM_MEDIUM = 1,
-   TPM_LONG = 2,
-   TPM_UNDEFINED,
-};
-
-/* Extended error numbers from linux (see errno.h) */
-#define ECANCELED  125 /* Operation Canceled */
-
-/* Timer frequency. Corresponds to msec timer resolution*/
-#define HZ 1000
-
-#define TPM_MAX_ORDINAL243
-#define TPM_MAX_PROTECTED_ORDINAL  12
-#define TPM_PROTECTED_ORDINAL_MASK 0xFF
-
-#define TPM_CMD_COUNT_BYTE 2
-#define TPM_CMD_ORDINAL_BYTE   6
-
-/*
- * Array with one entry per ordinal defining the maximum amount
- * of time the chip could take to return the result.  The ordinal
- * designation of short, medium or long is defined in a table in
- * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
- * values of the SHORT, MEDIUM, and LONG durations are retrieved
- * from the chip during initialization with a call to tpm_get_timeouts.
- */
-static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = {
-   TPM_UNDEFINED,  /* 0 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,  /* 5 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_SHORT,  /* 10 */
-   TPM_SHORT,
-};
-
-static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
-   TPM_UNDEFINED,  /* 0 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,  /* 5 */
-   TPM_UNDEFINE

Re: [U-Boot] [PATCH v2 03/28] tpm: Add Kconfig options for TPMs

2015-08-24 Thread Christophe Ricard

Hi Simon,

This one looks good to me.

Acked-by: Christophe Ricard

Best Regards
Christophe

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

Add new Kconfig options for TPMs in preparation for moving boards to use
Kconfig for TPM configuration.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add a 'TPM' menu in Kconfig

  common/Kconfig  | 12 +++
  drivers/tpm/Kconfig | 60 +
  lib/Kconfig | 10 +
  3 files changed, 82 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index 88dc016..bacc4e0 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -625,4 +625,16 @@ config CMD_REGULATOR
  
  endmenu
  
+menu "Security commands"

+config CMD_TPM
+   bool "Enable the 'tpm' command"
+   depends on TPM
+   help
+ This provides a means to talk to a TPM from the command line. A wide
+ range of commands if provided - see 'tpm help' for details. The
+ command requires a suitable TPM on your board and the correct driver
+ must be enabled.
+
+endmenu
+
  endmenu
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index f408b8a..9101fc2 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -1,7 +1,67 @@
+#
+# TPM subsystem configuration
+#
+
+menu "TPM support"
+
  config TPM_TIS_SANDBOX
bool "Enable sandbox TPM driver"
+   depends on SANDBOX
help
  This driver emulates a TPM, providing access to base functions
  such as reading and writing TPM private data. This is enough to
  support Chrome OS verified boot. Extend functionality is not
  implemented.
+
+config TPM_ATMEL_TWI
+   bool "Enable Atmel TWI TPM device driver"
+   depends on TPM
+   help
+ This driver supports an Atmel TPM device connected on the I2C bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
+config TPM_TIS_I2C
+   bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
+   depends on TPM && DM_I2C
+   help
+ This driver supports Infineon TPM devices connected on the I2C bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
+config TPM_TIS_I2C_BURST_LIMITATION
+   bool "Enable I2C burst length limitation"
+   depends on TPM_TIS_I2C
+   help
+ Some broken TPMs have a limitation on the number of bytes they can
+ receive in one message. Enable this option to allow you to set this
+ option. The can allow a broken TPM to be used by splitting messages
+ into separate pieces.
+
+config TPM_TIS_I2C_BURST_LIMITATION_LEN
+   int "Length"
+   depends on TPM_TIS_I2C_BURST_LIMITATION
+   help
+ Use this to set the burst limitation length
+
+config TPM_TIS_LPC
+   bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
+   depends on TPM && X86
+   help
+ This driver supports Infineon TPM devices connected on the I2C bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
+config TPM_AUTH_SESSIONS
+   bool "Enable TPM authentication session support"
+   depends on TPM
+   help
+ Enable support for authorised (AUTH1) commands as specified in the
+ TCG Main Specification 1.2. OIAP-authorised versions of the commands
+ TPM_LoadKey2 and TPM_GetPubKey are provided. Both features are
+ available using the 'tpm' command, too.
+
+endmenu
diff --git a/lib/Kconfig b/lib/Kconfig
index 884218a..0673072 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -54,6 +54,16 @@ source lib/dhry/Kconfig
  
  source lib/rsa/Kconfig
  
+config TPM

+   bool "Trusted Platform Module (TPM) Support"
+   help
+ This enables support for TPMs which can be used to provide security
+ features for your board. The TPM can be connected via LPC or I2C
+ and a sandbox TPM is provided for testing purposes. Use the 'tpm'
+ command to interactive the TPM. Driver model support is provided
+ for the low-level TPM interface, but only one TPM is supported at
+ a time by the TPM library.
+
  menu "Hashing Support"
  
  config SHA1


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


Re: [U-Boot] [PATCH v2 06/28] tpm: Move the I2C TPM code into one file

2015-08-25 Thread Christophe Ricard

Hi Simon,

Le 25/08/2015 06:13, Simon Glass a écrit :

Hi Christophe,

On 24 August 2015 at 14:24, Christophe Ricard
 wrote:

Hi Simon,

I don't disagree with this patch (from patch 6 to patch 12).
However, i believe it would be better to have this driver renamed
tpm_i2c_infineon as shown in my previous patch:
http://lists.denx.de/pipermail/u-boot/2015-August/223582.html

Could you update this ?

Yes, although I think this can be a separate patch. I was going to use yours...

Then ok. This is fine for me :)

Best Regards
Christophe

[snip]

Best Regards
Christophe
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 20/28] tpm: Check that parse_byte_string() has data to parse

2015-08-25 Thread Christophe Ricard

Hi Simon,
Le 25/08/2015 06:13, Simon Glass a écrit :

Hi Christophe,

On 24 August 2015 at 14:22, Christophe Ricard
 wrote:

Hi Simon,

Print an error ? Are you sure ? I guess the comment is not accurate ;).


Well returning NULL from parse_byte_string() will cause an error to be
printed by the caller...


This is just a comment nitpick. I think it is clear enough but from the 
patch the printing is may be not so obvious.

It is just fine like that.


Regards,
Simon

Best Regards
Christophe

Best Regards
Christophe


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

Rather then crashing when there is no data, print an error.

Acked-by: Christophe Ricard 
Signed-off-by: Simon Glass 
---

Changes in v2: None

   common/cmd_tpm.c | 2 ++
   1 file changed, 2 insertions(+)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 65e7371..e9c6618 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -58,6 +58,8 @@ static void *parse_byte_string(char *bytes, uint8_t
*data, size_t *count_ptr)
 size_t count, length;
 int i;
   + if (!bytes)
+   return NULL;
 length = strlen(bytes);
 count = length / 2;





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


Re: [U-Boot] [PATCH 3/4] spi: omap3: Convert to DM

2016-02-06 Thread Christophe Ricard

Hi Simon, Tom,

I assume the approach you are taking is also valuable for the i2c: 
omap24xx patch serie:

http://lists.denx.de/pipermail/u-boot/2016-January/241676.html

What are your recommendation about the pending patches ?
Should i send back only the one not taking care of the DM conversion and 
send another serie later ?


I have seen some work ongoing on this topic on the u-boot-fdt tree on 
the spl-working branch.

Is there a more accurate place to follow this work ?

Best Regards
Christophe

On 26/01/2016 02:55, Peng Fan wrote:

Hi Simon,

On Mon, Jan 25, 2016 at 06:11:24PM -0700, Simon Glass wrote:

+Hans

Hi Tom,

On 21 January 2016 at 05:24, Tom Rini  wrote:

On Wed, Jan 20, 2016 at 07:46:15PM -0700, Simon Glass wrote:

+Mugunthan, Tom

On 17 January 2016 at 03:56, Christophe Ricard
 wrote:

Convert omap3_spi driver to DM and keep compatibility with previous
mode.

Signed-off-by: Christophe Ricard 
---

  drivers/spi/Kconfig |   6 +
  drivers/spi/omap3_spi.c | 439 ++--
  drivers/spi/omap3_spi.h |  14 +-
  3 files changed, 402 insertions(+), 57 deletions(-)

This is a pretty painful conversion, with lots of #ifdefs. I think it
would be possible to use a common pointer type and reduce this.

But perhaps it does not matter - how long must we be in the state of
supporting legacy SPI? Can we convert all TI boards to driver model?

We _really_ need some way to support more than one board per binary
before we can move everything to DM only.

I think we can kind of do this today if we stick to using platform data
for everything that's board-specific rather than SoC-defined.  What we
talked about at ELCE was auto-generating the pdata from the device tree,
I think.

We discussed this on IRC but since that doesn't exist as far as the
mailing list is concerned...

The current plan is:

- Adjust build system to optionally build a u-boot.img in FIT format
that includes the U-Boot binary and >1 device tree files
- Adjust SPL to load this
- Add a way for SPL to determine which device tree to select (by
calling a board-specific function)
- Have SPL pass this selected device tree to U-Boot when it starts

Can dtb be sperated from the final u-boot.img, if using SPL?
I mean let SPL load the u-boot.img and the dtb to correct DRAM address.
And the dtb is shared with linux kernel.

Regards,
Peng.

Thus we should be able to support more than one board with a single
U-Boot image. Of course this is not a perfect solution (e.g. it is
inefficient since the DTs are likely to be largely the same) but it
should be a good first step.

I'm going to try this out with sunxi initially and plan to get some
patches out by the end of the week.

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


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


Re: [U-Boot] [PATCH 3/4] spi: omap3: Convert to DM

2016-02-10 Thread Christophe Ricard

Hi Jagan,

My understanding is that some work are ongoing around spl in order to 
support correctly DM for all spi/i2c bus drivers.

As a consequence patch 4 got differed.

Hopefully Simon or Tom can comment.

Are you ok in applying patch 1 and 2 only ? or should i send a new serie 
with only patch 1 and 2 ?


Best Regards
Christophe

On 10/02/2016 20:16, Jagan Teki wrote:

On 8 February 2016 at 23:26, Jagan Teki  wrote:

On 8 February 2016 at 23:10, Tom Rini  wrote:

On Sat, Feb 06, 2016 at 11:27:21PM +0100, Christophe Ricard wrote:

Hi Simon, Tom,

I assume the approach you are taking is also valuable for the i2c:
omap24xx patch serie:
http://lists.denx.de/pipermail/u-boot/2016-January/241676.html

What are your recommendation about the pending patches ?
Should i send back only the one not taking care of the DM conversion
and send another serie later ?

I have seen some work ongoing on this topic on the u-boot-fdt tree
on the spl-working branch.
Is there a more accurate place to follow this work ?

For i2c, aside from needing to defer removing the non-DM code for a
while yet, there were some review comments to address in a v2 or answer
as intentional.  For SPI, it's all looking good and I'm assuming Jagan
will have a SPI PR soon.  Thanks!

Yes, by this week-end.

Any idea 4/4 got differed in patchwork [1], do we have next version
patches for these?

[1] https://patchwork.ozlabs.org/patch/569241/


On 26/01/2016 02:55, Peng Fan wrote:

Hi Simon,

On Mon, Jan 25, 2016 at 06:11:24PM -0700, Simon Glass wrote:

+Hans

Hi Tom,

On 21 January 2016 at 05:24, Tom Rini  wrote:

On Wed, Jan 20, 2016 at 07:46:15PM -0700, Simon Glass wrote:

+Mugunthan, Tom

On 17 January 2016 at 03:56, Christophe Ricard
 wrote:

Convert omap3_spi driver to DM and keep compatibility with previous
mode.

Signed-off-by: Christophe Ricard 
---

  drivers/spi/Kconfig |   6 +
  drivers/spi/omap3_spi.c | 439 ++--
  drivers/spi/omap3_spi.h |  14 +-
  3 files changed, 402 insertions(+), 57 deletions(-)

This is a pretty painful conversion, with lots of #ifdefs. I think it
would be possible to use a common pointer type and reduce this.

But perhaps it does not matter - how long must we be in the state of
supporting legacy SPI? Can we convert all TI boards to driver model?

We _really_ need some way to support more than one board per binary
before we can move everything to DM only.

I think we can kind of do this today if we stick to using platform data
for everything that's board-specific rather than SoC-defined.  What we
talked about at ELCE was auto-generating the pdata from the device tree,
I think.

We discussed this on IRC but since that doesn't exist as far as the
mailing list is concerned...

The current plan is:

- Adjust build system to optionally build a u-boot.img in FIT format
that includes the U-Boot binary and >1 device tree files
- Adjust SPL to load this
- Add a way for SPL to determine which device tree to select (by
calling a board-specific function)
- Have SPL pass this selected device tree to U-Boot when it starts

Can dtb be sperated from the final u-boot.img, if using SPL?
I mean let SPL load the u-boot.img and the dtb to correct DRAM address.
And the dtb is shared with linux kernel.

Regards,
Peng.

Thus we should be able to support more than one board with a single
U-Boot image. Of course this is not a perfect solution (e.g. it is
inefficient since the DTs are likely to be largely the same) but it
should be a good first step.

I'm going to try this out with sunxi initially and plan to get some
patches out by the end of the week.


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


[U-Boot] [PATCH v5 0/3] omap3_spi update after testing Jagan Teki v4 series.

2016-03-01 Thread Christophe Ricard

Hi Jagan, Simon,

Please find an updated series based on Jagan Teki work.

I have updated this series after validation on a Beagleboard xM
and a TPM ST33ZP24 spi slave.

Overall, priv->wordlen was not set and i got several code style issue
when using patman.

Best Regards
Christophe

Changes in v5:
- Few code style fixes reported by patman
- Remove omap3_spi_txrx, omap3_spi_write, omap3_spi_read header in C file
to avoid "externs should be avoided in .c files" patman warnings.
- Adding Christophe Ricard credit on omap3_spi driver dm conversion
- Set priv->wordlen in omap3_spi_probe
- Add OMAP3_SPI in drivers/spi/Kconfig

Changes in v4:
- rebase to master

Changes in v3:
- Add DECLARE_GLOBAL_DATA_PTR

Changes in v2:
- Added dm pindir-d0-out-d1-in logic
- Updated comment about 4-wire master mode as per Linux.

Christophe Ricard (3):
  spi: omap3: Move headers code inside the driver
  spi: omap3: Make local functions as static
  spi: omap3: Convert to driver model

 drivers/spi/Kconfig |   7 +
 drivers/spi/omap3_spi.c | 755 +++-
 drivers/spi/omap3_spi.h | 109 ---
 3 files changed, 495 insertions(+), 376 deletions(-)
 delete mode 100644 drivers/spi/omap3_spi.h

-- 
2.5.0

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


[U-Boot] [PATCH v5 1/3] spi: omap3: Move headers code inside the driver

2016-03-01 Thread Christophe Ricard
Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini 
Cc: Simon Glass 
Cc: Christophe Ricard 
Signed-off-by: Jagan Teki 
Signed-off-by: Christophe Ricard 
---

Changes in v5:
- Few code style fixes reported by patman
- Remove omap3_spi_txrx, omap3_spi_write, omap3_spi_read header in C file
to avoid "externs should be avoided in .c files" patman warnings.

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/spi/omap3_spi.c |  86 +-
 drivers/spi/omap3_spi.h | 109 
 2 files changed, 84 insertions(+), 111 deletions(-)
 delete mode 100644 drivers/spi/omap3_spi.h

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 95cdfa3..e2cfbac 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -18,9 +18,91 @@
 #include 
 #include 
 #include 
-#include "omap3_spi.h"
 
-#define SPI_WAIT_TIMEOUT 10
+#if defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX)
+#define OMAP3_MCSPI1_BASE  0x48030100
+#define OMAP3_MCSPI2_BASE  0x481A0100
+#else
+#define OMAP3_MCSPI1_BASE  0x48098000
+#define OMAP3_MCSPI2_BASE  0x4809A000
+#define OMAP3_MCSPI3_BASE  0x480B8000
+#define OMAP3_MCSPI4_BASE  0x480BA000
+#endif
+
+/* per-register bitmasks */
+#define OMAP3_MCSPI_SYSCONFIG_SMARTIDLE (2 << 3)
+#define OMAP3_MCSPI_SYSCONFIG_ENAWAKEUP BIT(2)
+#define OMAP3_MCSPI_SYSCONFIG_AUTOIDLE BIT(0)
+#define OMAP3_MCSPI_SYSCONFIG_SOFTRESET BIT(1)
+
+#define OMAP3_MCSPI_SYSSTATUS_RESETDONE BIT(0)
+
+#define OMAP3_MCSPI_MODULCTRL_SINGLE   BIT(0)
+#define OMAP3_MCSPI_MODULCTRL_MS   BIT(2)
+#define OMAP3_MCSPI_MODULCTRL_STESTBIT(3)
+
+#define OMAP3_MCSPI_CHCONF_PHA BIT(0)
+#define OMAP3_MCSPI_CHCONF_POL BIT(1)
+#define OMAP3_MCSPI_CHCONF_CLKD_MASK   GENMASK(5, 2)
+#define OMAP3_MCSPI_CHCONF_EPOLBIT(6)
+#define OMAP3_MCSPI_CHCONF_WL_MASK GENMASK(11, 7)
+#define OMAP3_MCSPI_CHCONF_TRM_RX_ONLY BIT(12)
+#define OMAP3_MCSPI_CHCONF_TRM_TX_ONLY BIT(13)
+#define OMAP3_MCSPI_CHCONF_TRM_MASKGENMASK(13, 12)
+#define OMAP3_MCSPI_CHCONF_DMAWBIT(14)
+#define OMAP3_MCSPI_CHCONF_DMARBIT(15)
+#define OMAP3_MCSPI_CHCONF_DPE0BIT(16)
+#define OMAP3_MCSPI_CHCONF_DPE1BIT(17)
+#define OMAP3_MCSPI_CHCONF_IS  BIT(18)
+#define OMAP3_MCSPI_CHCONF_TURBO   BIT(19)
+#define OMAP3_MCSPI_CHCONF_FORCE   BIT(20)
+
+#define OMAP3_MCSPI_CHSTAT_RXS BIT(0)
+#define OMAP3_MCSPI_CHSTAT_TXS BIT(1)
+#define OMAP3_MCSPI_CHSTAT_EOT BIT(2)
+
+#define OMAP3_MCSPI_CHCTRL_EN  BIT(0)
+#define OMAP3_MCSPI_CHCTRL_DIS (0 << 0)
+
+#define OMAP3_MCSPI_WAKEUPENABLE_WKEN  BIT(0)
+
+#define OMAP3_MCSPI_MAX_FREQ   4800
+#define SPI_WAIT_TIMEOUT   10
+
+/* OMAP3 McSPI registers */
+struct mcspi_channel {
+   unsigned int chconf;/* 0x2C, 0x40, 0x54, 0x68 */
+   unsigned int chstat;/* 0x30, 0x44, 0x58, 0x6C */
+   unsigned int chctrl;/* 0x34, 0x48, 0x5C, 0x70 */
+   unsigned int tx;/* 0x38, 0x4C, 0x60, 0x74 */
+   unsigned int rx;/* 0x3C, 0x50, 0x64, 0x78 */
+};
+
+struct mcspi {
+   unsigned char res1[0x10];
+   unsigned int sysconfig; /* 0x10 */
+   unsigned int sysstatus; /* 0x14 */
+   unsigned int irqstatus; /* 0x18 */
+   unsigned int irqenable; /* 0x1C */
+   unsigned int wakeupenable;  /* 0x20 */
+   unsigned int syst;  /* 0x24 */
+   unsigned int modulctrl; /* 0x28 */
+   struct mcspi_channel channel[4];
+   /* channel0: 0x2C - 0x3C, bus 0 & 1 & 2 & 3 */
+   /* channel1: 0x40 - 0x50, bus 0 & 1 */
+   /* channel2: 0x54 - 0x64, bus 0 & 1 */
+   /* channel3: 0x68 - 0x78, bus 0 */
+};
+
+struct omap3_spi_slave {
+   struct spi_slave slave;
+   struct mcspi *regs;
+   unsigned int freq;
+   unsigned int mode;
+};
+
+static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave)
+{ return container_of(slave, struct omap3_spi_slave, slave); }
 
 static void spi_reset(struct omap3_spi_slave *ds)
 {
diff --git a/drivers/spi/omap3_spi.h b/drivers/spi/omap3_spi.h
deleted file mode 100644
index 6a07c6d..000
--- a/drivers/spi/omap3_spi.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Register definitions for the OMAP3 McSPI Controller
- *
- * Copyright (C) 2010 Dirk Behme 
- *
- * Parts taken from linux/drivers/spi/omap2_mcspi.c
- * Copyright (C) 2005, 2006 Nokia Corporation
- *
- * Modified by Ruslan Araslanov 
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#ifndef _OMAP3_SPI_H_
-#define _OMAP3_SPI_H_
-
-#if defined(CONFIG_AM3

[U-Boot] [PATCH v5 2/3] spi: omap3: Make local functions as static

2016-03-01 Thread Christophe Ricard
Attach static on local defined functions.

Cc: Tom Rini 
Cc: Simon Glass 
Cc: Christophe Ricard 
Signed-off-by: Jagan Teki 
Signed-off-by: Christophe Ricard 
---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/spi/omap3_spi.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index e2cfbac..4ae2471 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -304,8 +304,8 @@ void spi_release_bus(struct spi_slave *slave)
spi_reset(ds);
 }
 
-int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
-   unsigned long flags)
+static int omap3_spi_write(struct spi_slave *slave, unsigned int len,
+  const void *txp, unsigned long flags)
 {
struct omap3_spi_slave *ds = to_omap3_spi(slave);
int i;
@@ -358,8 +358,8 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int 
len, const void *txp,
return 0;
 }
 
-int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
-  unsigned long flags)
+static int omap3_spi_read(struct spi_slave *slave, unsigned int len,
+ void *rxp, unsigned long flags)
 {
struct omap3_spi_slave *ds = to_omap3_spi(slave);
int i;
@@ -412,8 +412,8 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int 
len, void *rxp,
 }
 
 /*McSPI Transmit Receive Mode*/
-int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
-  const void *txp, void *rxp, unsigned long flags)
+static int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
+ const void *txp, void *rxp, unsigned long flags)
 {
struct omap3_spi_slave *ds = to_omap3_spi(slave);
ulong start;
-- 
2.5.0

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


[U-Boot] [PATCH v5 3/3] spi: omap3: Convert to driver model

2016-03-01 Thread Christophe Ricard
After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini 
Reviewed-by: Simon Glass 
Acked-by: Christophe Ricard 
Tested-by: Christophe Ricard 
Signed-off-by: Jagan Teki 
Signed-off-by: Christophe Ricard 
---

Changes in v5:
- Adding Christophe Ricard credit on omap3_spi driver dm conversion
- Set priv->wordlen in omap3_spi_probe
- Add OMAP3_SPI in drivers/spi/Kconfig

Changes in v4:
- rebase to master

Changes in v3:
- Add DECLARE_GLOBAL_DATA_PTR

Changes in v2:
- Added dm pindir-d0-out-d1-in logic
- Updated comment about 4-wire master mode as per Linux.

 drivers/spi/Kconfig |   7 +
 drivers/spi/omap3_spi.c | 675 +---
 2 files changed, 414 insertions(+), 268 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 2cdb110..f0258f8 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -155,6 +155,13 @@ config ZYNQ_QSPI
  Zynq QSPI IP core. This IP is used to connect the flash in
  4-bit qspi, 8-bit dual stacked and shared 4-bit dual parallel.
 
+config OMAP3_SPI
+   bool "McSPI driver for OMAP"
+   help
+ SPI master controller for OMAP24XX and later Multichannel SPI
+ (McSPI). This driver be used to access SPI chips on platforms
+ embedding this OMAP3 McSPI IP core.
+
 endif # if DM_SPI
 
 config FSL_ESPI
diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 4ae2471..dd51ba2 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2016 Jagan Teki 
+ *       Christophe Ricard 
+ *
  * Copyright (C) 2010 Dirk Behme 
  *
  * Driver for McSPI controller on OMAP3. Based on davinci_spi.c
@@ -15,10 +18,13 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #if defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX)
 #define OMAP3_MCSPI1_BASE  0x48030100
 #define OMAP3_MCSPI2_BASE  0x481A0100
@@ -65,6 +71,8 @@
 #define OMAP3_MCSPI_CHCTRL_DIS (0 << 0)
 
 #define OMAP3_MCSPI_WAKEUPENABLE_WKEN  BIT(0)
+#define MCSPI_PINDIR_D0_IN_D1_OUT  0
+#define MCSPI_PINDIR_D0_OUT_D1_IN  1
 
 #define OMAP3_MCSPI_MAX_FREQ   4800
 #define SPI_WAIT_TIMEOUT   10
@@ -94,310 +102,124 @@ struct mcspi {
/* channel3: 0x68 - 0x78, bus 0 */
 };
 
-struct omap3_spi_slave {
-   struct spi_slave slave;
+struct omap3_spi_priv {
struct mcspi *regs;
+   unsigned int cs;
unsigned int freq;
unsigned int mode;
+   unsigned int wordlen;
+   unsigned int pin_dir:1;
 };
 
-static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave)
-{ return container_of(slave, struct omap3_spi_slave, slave); }
-
-static void spi_reset(struct omap3_spi_slave *ds)
+static void omap3_spi_write_chconf(struct omap3_spi_priv *priv, int val)
 {
-   unsigned int tmp;
-
-   writel(OMAP3_MCSPI_SYSCONFIG_SOFTRESET, &ds->regs->sysconfig);
-   do {
-   tmp = readl(&ds->regs->sysstatus);
-   } while (!(tmp & OMAP3_MCSPI_SYSSTATUS_RESETDONE));
-
-   writel(OMAP3_MCSPI_SYSCONFIG_AUTOIDLE |
-OMAP3_MCSPI_SYSCONFIG_ENAWAKEUP |
-OMAP3_MCSPI_SYSCONFIG_SMARTIDLE,
-&ds->regs->sysconfig);
-
-   writel(OMAP3_MCSPI_WAKEUPENABLE_WKEN, &ds->regs->wakeupenable);
-}
-
-static void omap3_spi_write_chconf(struct omap3_spi_slave *ds, int val)
-{
-   writel(val, &ds->regs->channel[ds->slave.cs].chconf);
+   writel(val, &priv->regs->channel[priv->cs].chconf);
/* Flash post writes to make immediate effect */
-   readl(&ds->regs->channel[ds->slave.cs].chconf);
+   readl(&priv->regs->channel[priv->cs].chconf);
 }
 
-static void omap3_spi_set_enable(struct omap3_spi_slave *ds, int enable)
+static void omap3_spi_set_enable(struct omap3_spi_priv *priv, int enable)
 {
-   writel(enable, &ds->regs->channel[ds->slave.cs].chctrl);
+   writel(enable, &priv->regs->channel[priv->cs].chctrl);
/* Flash post writes to make immediate effect */
-   readl(&ds->regs->channel[ds->slave.cs].chctrl);
+   readl(&priv->regs->channel[priv->cs].chctrl);
 }
 
-void spi_init()
-{
-   /* do nothing */
-}
-
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
- unsigned int max_hz, unsigned int mode)
-{
-   struct omap3_spi_slave  *ds;
-   struct mcspi *regs;
-
-   /*
-* OMAP3 McSPI (MultiChannel SPI) has 4 busses (modules)
-* with different number of chip selects (CS, ch

Re: [U-Boot] [PATCH 1/3] tpm: Move tpm_tis_i2c to tpm_i2c_infineon

2015-09-02 Thread Christophe Ricard

Hi Simon,

Apologies for the delay. I will try to rework this patch end of this 
week and send it back to you middle of next week.


Best Regards
Christophe

Le 31/08/2015 00:45, Simon Glass a écrit :

Hi Chrisophe,

On 13 August 2015 at 09:55, Simon Glass  wrote:

On 9 August 2015 at 07:19, Christophe Ricard
 wrote:

As there is no TCG specification or recommendation for i2c TPM 1.2, move
tpm_tis_i2c driver to tpm_i2c_infineon. Other tpm vendors like atmel or
stmicroelectronics may have a different transport protocol for i2c.

Signed-off-by: Christophe Ricard 
---

  README| 4 ++--
  drivers/tpm/Makefile  | 2 +-
  drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} | 0
  3 files changed, 3 insertions(+), 3 deletions(-)
  rename drivers/tpm/{tpm_tis_i2c.c => tpm_i2c_infineon.c} (100%)

Reviewed-by: Simon Glass 

Can you please take another look at this patch?

You need to change existing users of this config to use your renamed
Kconfig. This means updating things in the configs/ directory.

Regards,
Simon


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


[U-Boot] [PATCH v2 0/4] Move tpm_tis_i2c to tpm_tis_infineon and convert last tpm driver to use DM_TPM

2015-09-15 Thread Christophe Ricard
Hi Simon,

This patch serie move tpm_tis_i2c driver to tpm_tis_infineon.
It also convert the latest tpm driver tpm_atmel_twi to DM_TPM.

Apologies again for the delay :(.

Best Regards
Christophe

Changes in v2:
- Change existing users of config to use renamed Kconfig

Christophe Ricard (4):
  dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon
  dm: tpm: Add Driver Model support for tpm_atmel_twi driver
  dm: tpm: Remove every compilation switch for TPM driver model
  dm: tpm: Every TPM drivers should depends on DM_TPM

 README|  4 +-
 common/cmd_tpm.c  | 13 +---
 configs/nyan-big_defconfig|  2 +-
 configs/peach-pi_defconfig|  2 +-
 configs/peach-pit_defconfig   |  2 +-
 configs/snow_defconfig|  2 +-
 configs/spring_defconfig  |  2 +-
 drivers/tpm/Kconfig   | 10 +--
 drivers/tpm/Makefile  |  2 +-
 drivers/tpm/tpm_atmel_twi.c   | 74 ---
 drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} |  5 +-
 drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} |  0
 include/tis.h | 60 --
 include/tpm.h |  6 --
 lib/tpm.c | 20 +-
 15 files changed, 72 insertions(+), 132 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
 rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)
 delete mode 100644 include/tis.h

-- 
2.1.4

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


[U-Boot] [PATCH v2 1/4] dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon

2015-09-15 Thread Christophe Ricard
As there is no TCG specification or recommendation for i2c TPM 1.2,
move tpm_tis_i2c driver to tpm_i2c_infineon. Other tpm vendors like Atmel
or STMicroelectronics may have a different transport protocol for i2c.

Signed-off-by: Christophe Ricard 
---

Changes in v2:
- Change existing users of config to use renamed Kconfig

 README| 4 ++--
 configs/nyan-big_defconfig| 2 +-
 configs/peach-pi_defconfig| 2 +-
 configs/peach-pit_defconfig   | 2 +-
 configs/snow_defconfig| 2 +-
 configs/spring_defconfig  | 2 +-
 drivers/tpm/Kconfig   | 4 ++--
 drivers/tpm/Makefile  | 2 +-
 drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} | 4 ++--
 drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} | 0
 10 files changed, 12 insertions(+), 12 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
 rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)

diff --git a/README b/README
index 1acc355..f8fb46a 100644
--- a/README
+++ b/README
@@ -1490,8 +1490,8 @@ The following options need to be configured:
CONFIG_TPM
Support TPM devices.
 
-   CONFIG_TPM_TIS_I2C
-   Support for i2c bus TPM devices. Only one device
+   CONFIG_TPM_TIS_INFINEON
+   Support for Infineon i2c bus TPM devices. Only one device
per system is supported at this time.
 
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
diff --git a/configs/nyan-big_defconfig b/configs/nyan-big_defconfig
index 6464c37..04c6a21 100644
--- a/configs/nyan-big_defconfig
+++ b/configs/nyan-big_defconfig
@@ -18,7 +18,7 @@ CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_DISPLAY_PORT=y
 CONFIG_VIDEO_TEGRA124=y
diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index 56a5185..1a0837e 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -15,7 +15,7 @@ CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig
index 1934bf3..6567226 100644
--- a/configs/peach-pit_defconfig
+++ b/configs/peach-pit_defconfig
@@ -15,7 +15,7 @@ CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index 32c7c5d..583a838 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -20,7 +20,7 @@ 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_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_LDO=y
diff --git a/configs/spring_defconfig b/configs/spring_defconfig
index b20bfed..112afa1 100644
--- a/configs/spring_defconfig
+++ b/configs/spring_defconfig
@@ -20,7 +20,7 @@ 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_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_LDO=y
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 6bc8fdd..dacb847 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -31,7 +31,7 @@ config TPM_ATMEL_TWI
  to the device using the standard TPM Interface Specification (TIS)
  protocol
 
-config TPM_TIS_I2C
+config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
depends on TPM && DM_I2C
help
@@ -42,7 +42,7 @@ config TPM_TIS_I2C
 
 config TPM_TIS_I2C_BURST_LIMITATION
bool "Enable I2C burst length limitation"
-   depends on TPM_TIS_I2C
+   depends on TPM_TIS_INFINEON
help
  Some broken TPMs have a limitation on the number of bytes they can
  receive in one message. Enable this option to allow you to set this
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 0d328f8..5748145 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -6,6 +6,6 @@
 obj-$(CONFIG_DM_TPM) += tpm-uclass.o
 
 obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
-obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
+obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_tis_infineon.c
similarity index 99%
rename from drivers/tpm/tpm_tis_i2c.c
rename

[U-Boot] [PATCH v2 2/4] dm: tpm: Add Driver Model support for tpm_atmel_twi driver

2015-09-15 Thread Christophe Ricard
tpm_atmel_twi can fit perfectly to the new UCLASS_TPM class.

Signed-off-by: Christophe Ricard 
---

Changes in v2: None

 drivers/tpm/Kconfig |  2 +-
 drivers/tpm/tpm_atmel_twi.c | 74 -
 2 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index dacb847..ff2cdbe 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
 
 config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
-   depends on TPM
+   depends on TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
diff --git a/drivers/tpm/tpm_atmel_twi.c b/drivers/tpm/tpm_atmel_twi.c
index 205d7a5..361291d 100644
--- a/drivers/tpm/tpm_atmel_twi.c
+++ b/drivers/tpm/tpm_atmel_twi.c
@@ -7,51 +7,56 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+#include "tpm_internal.h"
+
 #define ATMEL_TPM_TIMEOUT_MS 5000 /* sufficient for anything but
 generating/exporting keys */
 
 /*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void)
-{
-   return 0;
-}
-
-/*
- * tis_open()
+ * tpm_atmel_twi_open()
  *
  * Requests access to locality 0 for the caller. After all commands have been
  * completed the caller is supposed to call tis_close().
  *
  * Returns 0 on success, -1 on failure.
  */
-int tis_open(void)
+static int tpm_atmel_twi_open(struct udevice *dev)
 {
return 0;
 }
 
 /*
- * tis_close()
+ * tpm_atmel_twi_close()
  *
  * terminate the currect session with the TPM by releasing the locked
  * locality. Returns 0 on success of -1 on failure (in case lock
  * removal did not succeed).
  */
-int tis_close(void)
+static int tpm_atmel_twi_close(struct udevice *dev)
+{
+   return 0;
+}
+
+/*
+ * tpm_atmel_twi_get_desc()
+ *
+ * @dev:Device to check
+ * @buf:Buffer to put the string
+ * @size:   Maximum size of buffer
+ * @return length of string, or -ENOSPC it no space
+ */
+static int tpm_atmel_twi_get_desc(struct udevice *dev, char *buf, int size)
 {
return 0;
 }
 
 /*
- * tis_sendrecv()
+ * tpm_atmel_twi_xfer()
  *
  * Send the requested data to the TPM and then try to get its response
  *
@@ -63,8 +68,9 @@ int tis_close(void)
  * Returns 0 on success (and places the number of response bytes at recv_len)
  * or -1 on failure.
  */
-int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
-   size_t *recv_len)
+static int tpm_atmel_twi_xfer(struct udevice *dev,
+ const uint8_t *sendbuf, size_t send_size,
+ uint8_t *recvbuf, size_t *recv_len)
 {
int res;
unsigned long start;
@@ -75,14 +81,15 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, 
uint8_t *recvbuf,
print_buffer(0, (void *)sendbuf, 1, send_size, 0);
 #endif
 
-   res = i2c_write(0x29, 0, 0, (uchar *)sendbuf, send_size);
+   res = dm_i2c_write(dev, 0, (uchar *)sendbuf, send_size);
if (res) {
printf("i2c_write returned %d\n", res);
return -1;
}
 
start = get_timer(0);
-   while ((res = i2c_read(0x29, 0, 0, recvbuf, 10))) {
+   while ((res = dm_i2c_read(dev, 0, recvbuf, TPM_HEADER_SIZE))) {
+   /* TODO Use TIS_TIMEOUT from tpm_tis_infineon.h */
if (get_timer(start) > ATMEL_TPM_TIMEOUT_MS) {
puts("tpm timed out\n");
return -1;
@@ -92,7 +99,7 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, 
uint8_t *recvbuf,
if (!res) {
*recv_len = get_unaligned_be32(recvbuf + 2);
if (*recv_len > 10)
-   res = i2c_read(0x29, 0, 0, recvbuf, *recv_len);
+   res = dm_i2c_read(dev, 0, recvbuf, *recv_len);
}
if (res) {
printf("i2c_read returned %d (rlen=%d)\n", res, *recv_len);
@@ -110,3 +117,28 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, 
uint8_t *recvbuf,
 
return res;
 }
+
+static int tpm_atmel_twi_probe(struct udevice *dev)
+{
+   return 0;
+}
+
+static const struct udevice_id tpm_atmel_twi_ids[] = {
+   { .compatible = "atmel,at97sc3204t"},
+   { }
+};
+
+static const struct tpm_ops tpm_atmel_twi_ops = {
+   .open = tpm_atmel_twi_open,
+   .close = tpm_atmel_twi_close,
+   .xfer = tpm_atmel_twi_xfer,
+   .get_desc = tpm_atmel_twi_get_desc,
+};
+
+U_BOOT_DRIVER(tpm_atmel_twi) = {
+   .name = "tpm_atmel_twi",
+   .id = UCLASS_TPM,
+   .of_match = tpm_atmel_t

[U-Boot] [PATCH v2 4/4] dm: tpm: Every TPM drivers should depends on DM_TPM

2015-09-15 Thread Christophe Ricard
Every TPM drivers should now depends on DM_TPM and not only TPM.

Signed-off-by: Christophe Ricard 
---

Changes in v2: None

 drivers/tpm/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index ff2cdbe..3ab652c 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
 
 config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
-   depends on TPM && DM_I2C
+   depends on DM_TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -33,7 +33,7 @@ config TPM_ATMEL_TWI
 
 config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
-   depends on TPM && DM_I2C
+   depends on DM_TPM && DM_I2C
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -57,7 +57,7 @@ config TPM_TIS_I2C_BURST_LIMITATION_LEN
 
 config TPM_TIS_LPC
bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
-   depends on TPM && X86
+   depends on DM_TPM && X86
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
-- 
2.1.4

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


[U-Boot] [PATCH v2 3/4] dm: tpm: Remove every compilation switch for TPM driver model

2015-09-15 Thread Christophe Ricard
As every TPM drivers support UCLASS_TPM, we can only rely on DM_TPM
functions.

This simplify a bit the code.

Signed-off-by: Christophe Ricard 
---

Changes in v2: None

 common/cmd_tpm.c   | 13 +
 drivers/tpm/tpm_tis_infineon.c |  1 -
 include/tis.h  | 60 --
 include/tpm.h  |  6 -
 lib/tpm.c  | 20 +++---
 5 files changed, 4 insertions(+), 96 deletions(-)
 delete mode 100644 include/tis.h

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 97501cc..add6bfb 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -443,7 +443,6 @@ TPM_COMMAND_NO_ARG(tpm_force_clear)
 TPM_COMMAND_NO_ARG(tpm_physical_enable)
 TPM_COMMAND_NO_ARG(tpm_physical_disable)
 
-#ifdef CONFIG_DM_TPM
 static int get_tpm(struct udevice **devp)
 {
int rc;
@@ -476,11 +475,11 @@ static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int 
argc,
 
return 0;
 }
-#endif
 
 static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
 {
+   struct udevice *dev;
void *command;
uint8_t response[1024];
size_t count, response_length = sizeof(response);
@@ -492,17 +491,11 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}
 
-#ifdef CONFIG_DM_TPM
-   struct udevice *dev;
-
rc = get_tpm(&dev);
if (rc)
return rc;
 
rc = tpm_xfer(dev, command, count, response, &response_length);
-#else
-   rc = tis_sendrecv(command, count, response, &response_length);
-#endif
free(command);
if (!rc) {
puts("tpm response:\n");
@@ -657,9 +650,7 @@ TPM_COMMAND_NO_ARG(tpm_end_oiap)
U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
 
 static cmd_tbl_t tpm_commands[] = {
-#ifdef CONFIG_DM_TPM
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
-#endif
U_BOOT_CMD_MKENT(init, 0, 1,
do_tpm_init, "", ""),
U_BOOT_CMD_MKENT(startup, 0, 1,
@@ -730,9 +721,7 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
 "cmd args...\n"
 "- Issue TPM command  with arguments .\n"
 "Admin Startup and State Commands:\n"
-#ifdef CONFIG_DM_TPM
 "  info - Show information about the TPM\n"
-#endif
 "  init\n"
 "- Put TPM into a state where it waits for 'startup' command.\n"
 "  startup mode\n"
diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c
index 88eb786..f57c328 100644
--- a/drivers/tpm/tpm_tis_infineon.c
+++ b/drivers/tpm/tpm_tis_infineon.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/include/tis.h b/include/tis.h
deleted file mode 100644
index 1985d9e..000
--- a/include/tis.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#ifndef __TIS_H
-#define __TIS_H
-
-#ifndef CONFIG_DM_TPM
-
-#include 
-
-/* Low-level interface to access TPM */
-
-/*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void);
-
-/*
- * tis_open()
- *
- * Requests access to locality 0 for the caller. After all commands have been
- * completed the caller is supposed to call tis_close().
- *
- * Returns 0 on success, -1 on failure.
- */
-int tis_open(void);
-
-/*
- * tis_close()
- *
- * terminate the currect session with the TPM by releasing the locked
- * locality. Returns 0 on success of -1 on failure (in case lock
- * removal did not succeed).
- */
-int tis_close(void);
-
-/*
- * tis_sendrecv()
- *
- * Send the requested data to the TPM and then try to get its response
- *
- * @sendbuf - buffer of the data to send
- * @send_size size of the data to send
- * @recvbuf - memory to save the response to
- * @recv_len - pointer to the size of the response buffer
- *
- * Returns 0 on success (and places the number of response bytes at recv_len)
- * or -1 on failure.
- */
-int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
-   size_t *recv_len);
-#endif
-
-#endif /* __TIS_H */
diff --git a/include/tpm.h b/include/tpm.h
index 086b672..9a6585d 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -8,8 +8,6 @@
 #ifndef __TPM_H
 #define __TPM_H
 
-#include 
-
 /*
  * Here is a partial implementation of TPM commands.  Please consult TCG Main
  * Specification for definitions of TPM commands.
@@ -196,8 +194,6 @@ struct tpm_permanent_flags {
u8  disable_full_da_logic_info;
 } __packed;
 
-#ifdef CONFIG_DM_TPM
-
 /* Max buffer size supported by our tpm */
 #define TPM_DEV_BUFSIZE1260
 
@@ -375,8 +371,6 @@ int tpm_get_

[U-Boot] [PATCH v3 1/4] dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon

2015-09-20 Thread Christophe Ricard
As there is no TCG specification or recommendation for i2c TPM 1.2,
move tpm_tis_i2c driver to tpm_i2c_infineon. Other tpm vendors like Atmel
or STMicroelectronics may have a different transport protocol for i2c.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v3:
- Adding mention to Tom Rini review

 README| 4 ++--
 configs/nyan-big_defconfig| 2 +-
 configs/peach-pi_defconfig| 2 +-
 configs/peach-pit_defconfig   | 2 +-
 configs/snow_defconfig| 2 +-
 configs/spring_defconfig  | 2 +-
 drivers/tpm/Kconfig   | 4 ++--
 drivers/tpm/Makefile  | 2 +-
 drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} | 4 ++--
 drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} | 0
 10 files changed, 12 insertions(+), 12 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
 rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)

diff --git a/README b/README
index 1acc355..f8fb46a 100644
--- a/README
+++ b/README
@@ -1490,8 +1490,8 @@ The following options need to be configured:
CONFIG_TPM
Support TPM devices.
 
-   CONFIG_TPM_TIS_I2C
-   Support for i2c bus TPM devices. Only one device
+   CONFIG_TPM_TIS_INFINEON
+   Support for Infineon i2c bus TPM devices. Only one device
per system is supported at this time.
 
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
diff --git a/configs/nyan-big_defconfig b/configs/nyan-big_defconfig
index 6464c37..04c6a21 100644
--- a/configs/nyan-big_defconfig
+++ b/configs/nyan-big_defconfig
@@ -18,7 +18,7 @@ CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_DISPLAY_PORT=y
 CONFIG_VIDEO_TEGRA124=y
diff --git a/configs/peach-pi_defconfig b/configs/peach-pi_defconfig
index 56a5185..1a0837e 100644
--- a/configs/peach-pi_defconfig
+++ b/configs/peach-pi_defconfig
@@ -15,7 +15,7 @@ CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/configs/peach-pit_defconfig b/configs/peach-pit_defconfig
index 1934bf3..6567226 100644
--- a/configs/peach-pit_defconfig
+++ b/configs/peach-pit_defconfig
@@ -15,7 +15,7 @@ CONFIG_CROS_EC=y
 CONFIG_CROS_EC_SPI=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_DM_TPM=y
-CONFIG_TPM_TIS_I2C=y
+CONFIG_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index 32c7c5d..583a838 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -20,7 +20,7 @@ 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_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_LDO=y
diff --git a/configs/spring_defconfig b/configs/spring_defconfig
index b20bfed..112afa1 100644
--- a/configs/spring_defconfig
+++ b/configs/spring_defconfig
@@ -20,7 +20,7 @@ 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_TPM_TIS_INFINEON=y
 CONFIG_DM_I2C=y
 CONFIG_DM_I2C_COMPAT=y
 CONFIG_I2C_CROS_EC_LDO=y
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 6bc8fdd..dacb847 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -31,7 +31,7 @@ config TPM_ATMEL_TWI
  to the device using the standard TPM Interface Specification (TIS)
  protocol
 
-config TPM_TIS_I2C
+config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
depends on TPM && DM_I2C
help
@@ -42,7 +42,7 @@ config TPM_TIS_I2C
 
 config TPM_TIS_I2C_BURST_LIMITATION
bool "Enable I2C burst length limitation"
-   depends on TPM_TIS_I2C
+   depends on TPM_TIS_INFINEON
help
  Some broken TPMs have a limitation on the number of bytes they can
  receive in one message. Enable this option to allow you to set this
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 0d328f8..5748145 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -6,6 +6,6 @@
 obj-$(CONFIG_DM_TPM) += tpm-uclass.o
 
 obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
-obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
+obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
diff --git a/drivers/tpm/tpm_tis_i2c.c b/drivers/tpm/tpm_tis_infineon.c
similarity index 99%
rename from drivers/tpm/tpm_tis_i2c.c
rename

[U-Boot] [PATCH v3 2/4] dm: tpm: Add Driver Model support for tpm_atmel_twi driver

2015-09-20 Thread Christophe Ricard
tpm_atmel_twi can fit perfectly to the new UCLASS_TPM class.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v3: None

 drivers/tpm/Kconfig |  2 +-
 drivers/tpm/tpm_atmel_twi.c | 74 -
 2 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index dacb847..ff2cdbe 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
 
 config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
-   depends on TPM
+   depends on TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
diff --git a/drivers/tpm/tpm_atmel_twi.c b/drivers/tpm/tpm_atmel_twi.c
index 205d7a5..361291d 100644
--- a/drivers/tpm/tpm_atmel_twi.c
+++ b/drivers/tpm/tpm_atmel_twi.c
@@ -7,51 +7,56 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+#include "tpm_internal.h"
+
 #define ATMEL_TPM_TIMEOUT_MS 5000 /* sufficient for anything but
 generating/exporting keys */
 
 /*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void)
-{
-   return 0;
-}
-
-/*
- * tis_open()
+ * tpm_atmel_twi_open()
  *
  * Requests access to locality 0 for the caller. After all commands have been
  * completed the caller is supposed to call tis_close().
  *
  * Returns 0 on success, -1 on failure.
  */
-int tis_open(void)
+static int tpm_atmel_twi_open(struct udevice *dev)
 {
return 0;
 }
 
 /*
- * tis_close()
+ * tpm_atmel_twi_close()
  *
  * terminate the currect session with the TPM by releasing the locked
  * locality. Returns 0 on success of -1 on failure (in case lock
  * removal did not succeed).
  */
-int tis_close(void)
+static int tpm_atmel_twi_close(struct udevice *dev)
+{
+   return 0;
+}
+
+/*
+ * tpm_atmel_twi_get_desc()
+ *
+ * @dev:Device to check
+ * @buf:Buffer to put the string
+ * @size:   Maximum size of buffer
+ * @return length of string, or -ENOSPC it no space
+ */
+static int tpm_atmel_twi_get_desc(struct udevice *dev, char *buf, int size)
 {
return 0;
 }
 
 /*
- * tis_sendrecv()
+ * tpm_atmel_twi_xfer()
  *
  * Send the requested data to the TPM and then try to get its response
  *
@@ -63,8 +68,9 @@ int tis_close(void)
  * Returns 0 on success (and places the number of response bytes at recv_len)
  * or -1 on failure.
  */
-int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
-   size_t *recv_len)
+static int tpm_atmel_twi_xfer(struct udevice *dev,
+ const uint8_t *sendbuf, size_t send_size,
+ uint8_t *recvbuf, size_t *recv_len)
 {
int res;
unsigned long start;
@@ -75,14 +81,15 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, 
uint8_t *recvbuf,
print_buffer(0, (void *)sendbuf, 1, send_size, 0);
 #endif
 
-   res = i2c_write(0x29, 0, 0, (uchar *)sendbuf, send_size);
+   res = dm_i2c_write(dev, 0, (uchar *)sendbuf, send_size);
if (res) {
printf("i2c_write returned %d\n", res);
return -1;
}
 
start = get_timer(0);
-   while ((res = i2c_read(0x29, 0, 0, recvbuf, 10))) {
+   while ((res = dm_i2c_read(dev, 0, recvbuf, TPM_HEADER_SIZE))) {
+   /* TODO Use TIS_TIMEOUT from tpm_tis_infineon.h */
if (get_timer(start) > ATMEL_TPM_TIMEOUT_MS) {
puts("tpm timed out\n");
return -1;
@@ -92,7 +99,7 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, 
uint8_t *recvbuf,
if (!res) {
*recv_len = get_unaligned_be32(recvbuf + 2);
if (*recv_len > 10)
-   res = i2c_read(0x29, 0, 0, recvbuf, *recv_len);
+   res = dm_i2c_read(dev, 0, recvbuf, *recv_len);
}
if (res) {
printf("i2c_read returned %d (rlen=%d)\n", res, *recv_len);
@@ -110,3 +117,28 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, 
uint8_t *recvbuf,
 
return res;
 }
+
+static int tpm_atmel_twi_probe(struct udevice *dev)
+{
+   return 0;
+}
+
+static const struct udevice_id tpm_atmel_twi_ids[] = {
+   { .compatible = "atmel,at97sc3204t"},
+   { }
+};
+
+static const struct tpm_ops tpm_atmel_twi_ops = {
+   .open = tpm_atmel_twi_open,
+   .close = tpm_atmel_twi_close,
+   .xfer = tpm_atmel_twi_xfer,
+   .get_desc = tpm_atmel_twi_get_desc,
+};
+
+U_BOOT_DRIVER(tpm_atmel_twi) = {
+   .name = "tpm_atmel_twi",
+   .id = UCLASS_TPM,
+   .of_match = tpm_atmel_t

[U-Boot] [PATCH v3 3/4] dm: tpm: Remove every compilation switch for TPM driver model

2015-09-20 Thread Christophe Ricard
As every TPM drivers support UCLASS_TPM, we can only rely on DM_TPM
functions.

This simplify a bit the code.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v3: None

 common/cmd_tpm.c   | 13 +
 drivers/tpm/tpm_tis_infineon.c |  1 -
 include/tis.h  | 60 --
 include/tpm.h  |  6 -
 lib/tpm.c  | 20 +++---
 5 files changed, 4 insertions(+), 96 deletions(-)
 delete mode 100644 include/tis.h

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 97501cc..add6bfb 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -443,7 +443,6 @@ TPM_COMMAND_NO_ARG(tpm_force_clear)
 TPM_COMMAND_NO_ARG(tpm_physical_enable)
 TPM_COMMAND_NO_ARG(tpm_physical_disable)
 
-#ifdef CONFIG_DM_TPM
 static int get_tpm(struct udevice **devp)
 {
int rc;
@@ -476,11 +475,11 @@ static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int 
argc,
 
return 0;
 }
-#endif
 
 static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
 {
+   struct udevice *dev;
void *command;
uint8_t response[1024];
size_t count, response_length = sizeof(response);
@@ -492,17 +491,11 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}
 
-#ifdef CONFIG_DM_TPM
-   struct udevice *dev;
-
rc = get_tpm(&dev);
if (rc)
return rc;
 
rc = tpm_xfer(dev, command, count, response, &response_length);
-#else
-   rc = tis_sendrecv(command, count, response, &response_length);
-#endif
free(command);
if (!rc) {
puts("tpm response:\n");
@@ -657,9 +650,7 @@ TPM_COMMAND_NO_ARG(tpm_end_oiap)
U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
 
 static cmd_tbl_t tpm_commands[] = {
-#ifdef CONFIG_DM_TPM
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
-#endif
U_BOOT_CMD_MKENT(init, 0, 1,
do_tpm_init, "", ""),
U_BOOT_CMD_MKENT(startup, 0, 1,
@@ -730,9 +721,7 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
 "cmd args...\n"
 "- Issue TPM command  with arguments .\n"
 "Admin Startup and State Commands:\n"
-#ifdef CONFIG_DM_TPM
 "  info - Show information about the TPM\n"
-#endif
 "  init\n"
 "- Put TPM into a state where it waits for 'startup' command.\n"
 "  startup mode\n"
diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c
index 88eb786..f57c328 100644
--- a/drivers/tpm/tpm_tis_infineon.c
+++ b/drivers/tpm/tpm_tis_infineon.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/include/tis.h b/include/tis.h
deleted file mode 100644
index 1985d9e..000
--- a/include/tis.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#ifndef __TIS_H
-#define __TIS_H
-
-#ifndef CONFIG_DM_TPM
-
-#include 
-
-/* Low-level interface to access TPM */
-
-/*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void);
-
-/*
- * tis_open()
- *
- * Requests access to locality 0 for the caller. After all commands have been
- * completed the caller is supposed to call tis_close().
- *
- * Returns 0 on success, -1 on failure.
- */
-int tis_open(void);
-
-/*
- * tis_close()
- *
- * terminate the currect session with the TPM by releasing the locked
- * locality. Returns 0 on success of -1 on failure (in case lock
- * removal did not succeed).
- */
-int tis_close(void);
-
-/*
- * tis_sendrecv()
- *
- * Send the requested data to the TPM and then try to get its response
- *
- * @sendbuf - buffer of the data to send
- * @send_size size of the data to send
- * @recvbuf - memory to save the response to
- * @recv_len - pointer to the size of the response buffer
- *
- * Returns 0 on success (and places the number of response bytes at recv_len)
- * or -1 on failure.
- */
-int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
-   size_t *recv_len);
-#endif
-
-#endif /* __TIS_H */
diff --git a/include/tpm.h b/include/tpm.h
index 086b672..9a6585d 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -8,8 +8,6 @@
 #ifndef __TPM_H
 #define __TPM_H
 
-#include 
-
 /*
  * Here is a partial implementation of TPM commands.  Please consult TCG Main
  * Specification for definitions of TPM commands.
@@ -196,8 +194,6 @@ struct tpm_permanent_flags {
u8  disable_full_da_logic_info;
 } __packed;
 
-#ifdef CONFIG_DM_TPM
-
 /* Max buffer size supported by our tpm */
 #define TPM_DEV_BUFSIZE1260
 
@@ -375,8 +371,

[U-Boot] [PATCH v3 4/4] dm: tpm: Every TPM drivers should depends on DM_TPM

2015-09-20 Thread Christophe Ricard
Every TPM drivers should now depends on DM_TPM and not only TPM.

Signed-off-by: Christophe Ricard 
Reviewed-by: Tom Rini 
---

Changes in v3: None

 drivers/tpm/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index ff2cdbe..3ab652c 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
 
 config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
-   depends on TPM && DM_I2C
+   depends on DM_TPM && DM_I2C
help
  This driver supports an Atmel TPM device connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -33,7 +33,7 @@ config TPM_ATMEL_TWI
 
 config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
-   depends on TPM && DM_I2C
+   depends on DM_TPM && DM_I2C
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
@@ -57,7 +57,7 @@ config TPM_TIS_I2C_BURST_LIMITATION_LEN
 
 config TPM_TIS_LPC
bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
-   depends on TPM && X86
+   depends on DM_TPM && X86
help
  This driver supports Infineon TPM devices connected on the I2C bus.
  The usual tpm operations and the 'tpm' command can be used to talk
-- 
2.1.4

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


[U-Boot] [PATCH v3 0/4] Move tpm_tis_i2c to tpm_tis_infineon and convert last tpm driver to use DM_TPM

2015-09-20 Thread Christophe Ricard
Hi Simon,

This patch serie move tpm_tis_i2c driver to tpm_tis_infineon.
It also convert the latest tpm driver tpm_atmel_twi to DM_TPM.

In this version i am only adding mention to Tom Rini review

Best Regards
Christophe

Changes in v3:
- Adding mention to Tom Rini review

Christophe Ricard (4):
  dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon
  dm: tpm: Add Driver Model support for tpm_atmel_twi driver
  dm: tpm: Remove every compilation switch for TPM driver model
  dm: tpm: Every TPM drivers should depends on DM_TPM

 README|  4 +-
 common/cmd_tpm.c  | 13 +---
 configs/nyan-big_defconfig|  2 +-
 configs/peach-pi_defconfig|  2 +-
 configs/peach-pit_defconfig   |  2 +-
 configs/snow_defconfig|  2 +-
 configs/spring_defconfig  |  2 +-
 drivers/tpm/Kconfig   | 10 +--
 drivers/tpm/Makefile  |  2 +-
 drivers/tpm/tpm_atmel_twi.c   | 74 ---
 drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} |  5 +-
 drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} |  0
 include/tis.h | 60 --
 include/tpm.h |  6 --
 lib/tpm.c | 20 +-
 15 files changed, 72 insertions(+), 132 deletions(-)
 rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
 rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)
 delete mode 100644 include/tis.h

-- 
2.1.4

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


Re: [U-Boot] [PATCH v3 0/4] Move tpm_tis_i2c to tpm_tis_infineon and convert last tpm driver to use DM_TPM

2015-09-27 Thread Christophe Ricard

Hi Simon,

Any news on this patch serie ?

Best Regards
Christophe

On 20/09/2015 22:00, Christophe Ricard wrote:

Hi Simon,

This patch serie move tpm_tis_i2c driver to tpm_tis_infineon.
It also convert the latest tpm driver tpm_atmel_twi to DM_TPM.

In this version i am only adding mention to Tom Rini review

Best Regards
Christophe

Changes in v3:
- Adding mention to Tom Rini review

Christophe Ricard (4):
   dm: tpm: Move tpm_tis_i2c to tpm_i2c_infineon
   dm: tpm: Add Driver Model support for tpm_atmel_twi driver
   dm: tpm: Remove every compilation switch for TPM driver model
   dm: tpm: Every TPM drivers should depends on DM_TPM

  README|  4 +-
  common/cmd_tpm.c  | 13 +---
  configs/nyan-big_defconfig|  2 +-
  configs/peach-pi_defconfig|  2 +-
  configs/peach-pit_defconfig   |  2 +-
  configs/snow_defconfig|  2 +-
  configs/spring_defconfig  |  2 +-
  drivers/tpm/Kconfig   | 10 +--
  drivers/tpm/Makefile  |  2 +-
  drivers/tpm/tpm_atmel_twi.c   | 74 ---
  drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} |  5 +-
  drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} |  0
  include/tis.h | 60 --
  include/tpm.h |  6 --
  lib/tpm.c | 20 +-
  15 files changed, 72 insertions(+), 132 deletions(-)
  rename drivers/tpm/{tpm_tis_i2c.c => tpm_tis_infineon.c} (99%)
  rename drivers/tpm/{tpm_tis_i2c.h => tpm_tis_infineon.h} (100%)
  delete mode 100644 include/tis.h



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


[U-Boot] [PATCH 0/3] Add support for st33zp24 i2c and spi TPMs

2016-01-16 Thread Christophe Ricard

Hi Simon,

After a first tentative in August 2015:
http://lists.denx.de/pipermail/u-boot/2015-August/222596.html

I finally found some spare time for a new round to send a new patchset version
bringing support for ST33ZP24 TPM 1.2 with i2c and spi support.

I have been able to follow all your guidance from my previous tentative
and got able to convert omap24xx_i2c and omap3_spi drivers to DM.
I will send them in a separate patchset as an RFC for your review.

Best Regards
Christophe



Christophe Ricard (3):
  tpm: Rename tpm_tis_infineon.h to tpm_tis.h and move infineon specific
stuff in tpm_infineon.c
  tpm: st33zp24: Add tpm st33zp24 support with i2c
  tpm: st33zp24: Add tpm st33zp24 spi support

 README|  11 +
 drivers/tpm/Kconfig   |  18 +
 drivers/tpm/Makefile  |   2 +
 drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} |  17 +-
 drivers/tpm/tpm_tis_infineon.c|  17 +-
 drivers/tpm/tpm_tis_st33zp24_i2c.c| 543 +
 drivers/tpm/tpm_tis_st33zp24_spi.c| 672 ++
 7 files changed, 1263 insertions(+), 17 deletions(-)
 rename drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} (86%)
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_i2c.c
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_spi.c

-- 
2.5.0

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


[U-Boot] [PATCH 2/3] tpm: st33zp24: Add tpm st33zp24 support with i2c

2016-01-16 Thread Christophe Ricard
Add support for TPM ST33ZP24 family with i2c.

For i2c we are relying only on DM_I2C.

Signed-off-by: Christophe Ricard 
---

 README |   7 +
 drivers/tpm/Kconfig|   9 +
 drivers/tpm/Makefile   |   1 +
 drivers/tpm/tpm_tis_st33zp24_i2c.c | 543 +
 4 files changed, 560 insertions(+)
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_i2c.c

diff --git a/README b/README
index 9423c34..e7c41c3 100644
--- a/README
+++ b/README
@@ -1432,6 +1432,13 @@ The following options need to be configured:
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
Define the burst count bytes upper limit
 
+   CONFIG_TPM_ST33ZP24
+   Support for STMicroelectronics TPM devices. Requires DM_TPM 
support.
+
+   CONFIG_TPM_ST33ZP24_I2C
+   Support for STMicroelectronics ST33ZP24 I2C devices.
+   Requires TPM_ST33ZP24 and I2C.
+
CONFIG_TPM_ATMEL_TWI
Support for Atmel TWI TPM device. Requires I2C support.
 
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 5a75f85..9432160 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -64,4 +64,13 @@ config TPM_AUTH_SESSIONS
  TPM_LoadKey2 and TPM_GetPubKey are provided. Both features are
  available using the 'tpm' command, too.
 
+config TPM_ST33ZP24_I2C
+   bool "STMicroelectronics ST33ZP24 I2C TPM"
+   depends on TPM && DM_I2C
+   ---help---
+ This driver supports STMicroelectronics TPM devices connected on the 
I2C bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
 endmenu
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 1d49e95..cb066d7 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
 obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
+obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
diff --git a/drivers/tpm/tpm_tis_st33zp24_i2c.c 
b/drivers/tpm/tpm_tis_st33zp24_i2c.c
new file mode 100644
index 000..9e4829f
--- /dev/null
+++ b/drivers/tpm/tpm_tis_st33zp24_i2c.c
@@ -0,0 +1,543 @@
+/*
+ * STMicroelectronics TPM ST33ZP24 I2C UBOOT driver
+ *
+ * Copyright (C) 2016 STMicroelectronics
+ *
+ * Description: Device driver for ST33ZP24 I2C TPM TCG.
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
+ * STMicroelectronics Protocol Stack Specification version 1.2.0.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm_tis.h"
+#include "tpm_internal.h"
+
+#define TPM_ACCESS 0x0
+#define TPM_STS0x18
+#define TPM_DATA_FIFO  0x24
+
+#define LOCALITY0  0
+
+#define TPM_DUMMY_BYTE 0xAA
+#define TPM_ST33ZP24_I2C_SLAVE_ADDR0x13
+
+#define TPM_WRITE_DIRECTION 0x80
+
+/*
+ * st33zp24_i2c_write8_reg
+ * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
+ * @param: tpm_register, the tpm tis register where the data should be written
+ * @param: tpm_data, the tpm_data to write inside the tpm_register
+ * @param: tpm_size, The length of the data
+ * @return: Number of byte written successfully else an error code.
+ */
+static int st33zp24_i2c_write8_reg(struct udevice *dev, u8 tpm_register,
+  const u8 *tpm_data, size_t tpm_size)
+{
+   struct tpm_chip_priv *chip_priv = dev_get_uclass_priv(dev);
+
+   chip_priv->buf[0] = tpm_register;
+   memcpy(chip_priv->buf + 1, tpm_data, tpm_size);
+
+   return dm_i2c_write(dev, 0, chip_priv->buf, tpm_size + 1);
+}
+
+/*
+* st33zp24_i2c_read8_reg
+* Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
+* @param: tpm_register, the tpm tis register where the data should be read
+* @param: tpm_data, the TPM response
+* @param: tpm_size, tpm TPM response size to read.
+* @return: Number of byte read successfully else an error code.
+*/
+static int st33zp24_i2c_read8_reg(struct udevice *dev, u8 tpm_register,
+ u8 *tpm_data, size_t tpm_size)
+{
+   int status;
+   u8 data;
+
+   data = TPM_DUMMY_BYTE;
+   status = st33zp24_i2c_write8_reg(dev, tpm_register, &data, 1);
+   if (status < 0)
+   return status;
+
+   return dm_i2c_read(dev, 0, tpm_data, tpm_size);
+}
+
+/*
+ * st33zp24_i2c_write
+ * Send byte to the TIS register according to the

[U-Boot] [PATCH 3/3] tpm: st33zp24: Add tpm st33zp24 spi support

2016-01-16 Thread Christophe Ricard
Add support for TPM ST33ZP24 spi.

The ST33ZP24 does have a spi interface.
The transport protocol is proprietary.

For spi we are relying only on DM_SPI.

Signed-off-by: Christophe Ricard 
---

 README |   4 +
 drivers/tpm/Kconfig|   9 +
 drivers/tpm/Makefile   |   1 +
 drivers/tpm/tpm_tis_st33zp24_spi.c | 672 +
 4 files changed, 686 insertions(+)
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_spi.c

diff --git a/README b/README
index e7c41c3..dc2917c 100644
--- a/README
+++ b/README
@@ -1439,6 +1439,10 @@ The following options need to be configured:
Support for STMicroelectronics ST33ZP24 I2C devices.
Requires TPM_ST33ZP24 and I2C.
 
+   CONFIG_TPM_ST33ZP24_SPI
+   Support for STMicroelectronics ST33ZP24 SPI devices.
+   Requires TPM_ST33ZP24 and SPI.
+
CONFIG_TPM_ATMEL_TWI
Support for Atmel TWI TPM device. Requires I2C support.
 
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 9432160..9a7b7f5 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -73,4 +73,13 @@ config TPM_ST33ZP24_I2C
  to the device using the standard TPM Interface Specification (TIS)
  protocol
 
+config TPM_ST33ZP24_SPI
+   bool "STMicroelectronics ST33ZP24 SPI TPM"
+   depends on TPM && DM_SPI
+   ---help---
+ This driver supports STMicroelectronics TPM devices connected on the 
SPI bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
 endmenu
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index cb066d7..c42a93f 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
 obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
+obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
diff --git a/drivers/tpm/tpm_tis_st33zp24_spi.c 
b/drivers/tpm/tpm_tis_st33zp24_spi.c
new file mode 100644
index 000..417bbf1
--- /dev/null
+++ b/drivers/tpm/tpm_tis_st33zp24_spi.c
@@ -0,0 +1,672 @@
+/*
+ * STMicroelectronics TPM ST33ZP24 SPI UBOOT driver
+ *
+ * Copyright (C) 2016 STMicroelectronics
+ *
+ * Description: Device driver for ST33ZP24 SPI TPM TCG.
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
+ * STMicroelectronics Protocol Stack Specification version 1.2.0.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm_tis.h"
+#include "tpm_internal.h"
+
+#define TPM_ACCESS 0x0
+#define TPM_STS0x18
+#define TPM_DATA_FIFO  0x24
+
+#define LOCALITY0  0
+
+#define TPM_DATA_FIFO  0x24
+#define TPM_INTF_CAPABILITY0x14
+
+#define TPM_DUMMY_BYTE 0x00
+#define TPM_WRITE_DIRECTION0x80
+
+#define MAX_SPI_LATENCY15
+#define LOCALITY0  0
+
+#define ST33ZP24_OK0x5A
+#define ST33ZP24_UNDEFINED_ERR 0x80
+#define ST33ZP24_BADLOCALITY   0x81
+#define ST33ZP24_TISREGISTER_UKNOWN0x82
+#define ST33ZP24_LOCALITY_NOT_ACTIVATED0x83
+#define ST33ZP24_HASH_END_BEFORE_HASH_START0x84
+#define ST33ZP24_BAD_COMMAND_ORDER 0x85
+#define ST33ZP24_INCORECT_RECEIVED_LENGTH  0x86
+#define ST33ZP24_TPM_FIFO_OVERFLOW 0x89
+#define ST33ZP24_UNEXPECTED_READ_FIFO  0x8A
+#define ST33ZP24_UNEXPECTED_WRITE_FIFO 0x8B
+#define ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END   0x90
+#define ST33ZP24_DUMMY_BYTES   0x00
+
+/*
+ * TPM command can be up to 2048 byte, A TPM response can be up to
+ * 1024 byte.
+ * Between command and response, there are latency byte (up to 15
+ * usually on st33zp24 2 are enough).
+ *
+ * Overall when sending a command and expecting an answer we need if
+ * worst case:
+ * 2048 (for the TPM command) + 1024 (for the TPM answer).  We need
+ * some latency byte before the answer is available (max 15).
+ * We have 2048 + 1024 + 15.
+ */
+#define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\
+ MAX_SPI_LATENCY)
+
+struct st33zp24_spi_phy {
+   int latency;
+
+   u8 tx_buf[ST33ZP24_SPI_BUFFER_S

[U-Boot] [PATCH 1/3] tpm: Rename tpm_tis_infineon.h to tpm_tis.h and move infineon specific stuff in tpm_infineon.c

2016-01-16 Thread Christophe Ricard
I2C protocol is not standardize for TPM 1.2.
TIS prococol is define by the Trusted Computing Group and potentially
available on several TPMs.

tpm_tis_infineon.h header is not generic enough.

Rename tpm_tis_infineon.h to tpm_tis.h and move infineon specific
defines/variables to tpm_tis_infineon.c

Signed-off-by: Christophe Ricard 
---

 drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} | 17 +
 drivers/tpm/tpm_tis_infineon.c| 17 -
 2 files changed, 17 insertions(+), 17 deletions(-)
 rename drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} (86%)

diff --git a/drivers/tpm/tpm_tis_infineon.h b/drivers/tpm/tpm_tis.h
similarity index 86%
rename from drivers/tpm/tpm_tis_infineon.h
rename to drivers/tpm/tpm_tis.h
index 3b510d1..25b152b 100644
--- a/drivers/tpm/tpm_tis_infineon.h
+++ b/drivers/tpm/tpm_tis.h
@@ -37,18 +37,12 @@ enum tpm_timeout {
 #define TPM_RSP_SIZE_BYTE  2
 #define TPM_RSP_RC_BYTE6
 
-enum i2c_chip_type {
-   SLB9635,
-   SLB9645,
-   UNKNOWN,
-};
-
 struct tpm_chip {
int is_open;
int locality;
u32 vend_dev;
unsigned long timeout_a, timeout_b, timeout_c, timeout_d;  /* msec */
-   enum i2c_chip_type chip_type;
+   ulong chip_type;
 };
 
 struct tpm_input_header {
@@ -134,13 +128,4 @@ enum tis_status {
TPM_STS_DATA_EXPECT = 0x08,
 };
 
-/* expected value for DIDVID register */
-#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
-#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
-
-#defineTPM_ACCESS(l)   (0x | ((l) << 4))
-#defineTPM_STS(l)  (0x0001 | ((l) << 4))
-#defineTPM_DATA_FIFO(l)(0x0005 | ((l) << 4))
-#defineTPM_DID_VID(l)  (0x0006 | ((l) << 4))
-
 #endif
diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c
index f57c328..a4b6741 100644
--- a/drivers/tpm/tpm_tis_infineon.c
+++ b/drivers/tpm/tpm_tis_infineon.c
@@ -30,17 +30,32 @@
 #include 
 #include 
 
-#include "tpm_tis_infineon.h"
+#include "tpm_tis.h"
 #include "tpm_internal.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
+enum i2c_chip_type {
+   SLB9635,
+   SLB9645,
+   UNKNOWN,
+};
+
+/* expected value for DIDVID register */
+#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
+#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
+
 static const char * const chip_name[] = {
[SLB9635] = "slb9635tt",
[SLB9645] = "slb9645tt",
[UNKNOWN] = "unknown/fallback to slb9635",
 };
 
+#defineTPM_ACCESS(l)   (0x | ((l) << 4))
+#defineTPM_STS(l)  (0x0001 | ((l) << 4))
+#defineTPM_DATA_FIFO(l)(0x0005 | ((l) << 4))
+#defineTPM_DID_VID(l)  (0x0006 | ((l) << 4))
+
 /*
  * tpm_tis_i2c_read() - read from TPM register
  * @addr: register address to read from
-- 
2.5.0

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


[U-Boot] [PATCH 0/2] TPM minor fixes

2016-01-16 Thread Christophe Ricard

Hi Simon,

Please find in this serie one bug fix and a typo cleanup.

Best Regards
Christophe



Christophe Ricard (2):
  tpm: Fix fault in case CONFIG_DM_TPM is set without any TPM
  tpm: tpm_tis_lpc: fix typo

 common/cmd_tpm.c| 2 +-
 drivers/tpm/Kconfig | 2 +-
 lib/tpm.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

-- 
2.5.0

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


[U-Boot] [PATCH 1/2] tpm: Fix fault in case CONFIG_DM_TPM is set without any TPM

2016-01-16 Thread Christophe Ricard
In case CONFIG_DM_TPM was set without any TPM chipset configured a fault
was generated (NULL pointer access).

Signed-off-by: Christophe Ricard 
---

 common/cmd_tpm.c | 2 +-
 lib/tpm.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index add6bfb..6edf3e9 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -448,7 +448,7 @@ static int get_tpm(struct udevice **devp)
int rc;
 
rc = uclass_first_device(UCLASS_TPM, devp);
-   if (rc) {
+   if (rc || !*devp) {
printf("Could not find TPM (ret=%d)\n", rc);
return CMD_RET_FAILURE;
}
diff --git a/lib/tpm.c b/lib/tpm.c
index 8a62216..f428d45 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -262,7 +262,7 @@ int tpm_init(void)
struct udevice *dev;
 
err = uclass_first_device(UCLASS_TPM, &dev);
-   if (err)
+   if (err || !dev)
return err;
return tpm_open(dev);
 }
-- 
2.5.0

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


[U-Boot] [PATCH 2/2] tpm: tpm_tis_lpc: fix typo

2016-01-16 Thread Christophe Ricard
TPM_TIS_LPC is connected to the LPC bus, not I2C.

Signed-off-by: Christophe Ricard 
---

 drivers/tpm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 31b35f7..5a75f85 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -50,7 +50,7 @@ config TPM_TIS_LPC
bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
depends on TPM && X86
help
- This driver supports Infineon TPM devices connected on the I2C bus.
+ This driver supports Infineon TPM devices connected on the LPC bus.
  The usual tpm operations and the 'tpm' command can be used to talk
  to the device using the standard TPM Interface Specification (TIS)
  protocol
-- 
2.5.0

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


[U-Boot] [PATCH 0/4] Convert omap3-spi driver to Driver Model

2016-01-17 Thread Christophe Ricard

Hi Simon,

This patchset tries to convert the TI omap3_spi driver to Driver Model.
It has been tested on a TI BeagleBoard xM.

Best Regards
Christophe



Christophe Ricard (4):
  spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx
  spi: spi-uclass: Set slave wordlen with SPI_DEFAULT_WORDLEN
  spi: omap3: Convert to DM
  spi: omap3: Convert fully to DM_SPI

 drivers/spi/Kconfig  |   6 +
 drivers/spi/omap3_spi.c  | 411 +++
 drivers/spi/omap3_spi.h  | 109 -
 drivers/spi/spi-uclass.c |   1 +
 4 files changed, 240 insertions(+), 287 deletions(-)
 delete mode 100644 drivers/spi/omap3_spi.h

-- 
2.5.0

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


[U-Boot] [PATCH 1/4] spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

2016-01-17 Thread Christophe Ricard
Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard 
---

 drivers/spi/omap3_spi.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 85f9e85..95cdfa3 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -336,7 +336,6 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int 
len,
struct omap3_spi_slave *ds = to_omap3_spi(slave);
ulong start;
int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
-   int irqstatus = readl(&ds->regs->irqstatus);
int i=0;
 
/*Enable SPI channel*/
@@ -351,7 +350,6 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int 
len,
/*Shift in and out 1 byte at time*/
for (i=0; i < len; i++){
/* Write: wait for TX empty (TXS == 1)*/
-   irqstatus |= (1<< (4*(ds->slave.bus)));
start = get_timer(0);
while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 OMAP3_MCSPI_CHSTAT_TXS)) {
-- 
2.5.0

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


[U-Boot] [PATCH 2/4] spi: spi-uclass: Set slave wordlen with SPI_DEFAULT_WORDLEN

2016-01-17 Thread Christophe Ricard
In some case wordlen may not be set. Use SPI_DEFAULT_WORDLEN as default.

Signed-off-by: Christophe Ricard 
---

 drivers/spi/spi-uclass.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 677c020..5561f36 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -158,6 +158,7 @@ static int spi_child_pre_probe(struct udevice *dev)
slave->max_hz = plat->max_hz;
slave->mode = plat->mode;
slave->mode_rx = plat->mode_rx;
+   slave->wordlen = SPI_DEFAULT_WORDLEN;
 
return 0;
 }
-- 
2.5.0

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


[U-Boot] [PATCH 3/4] spi: omap3: Convert to DM

2016-01-17 Thread Christophe Ricard
Convert omap3_spi driver to DM and keep compatibility with previous
mode.

Signed-off-by: Christophe Ricard 
---

 drivers/spi/Kconfig |   6 +
 drivers/spi/omap3_spi.c | 439 ++--
 drivers/spi/omap3_spi.h |  14 +-
 3 files changed, 402 insertions(+), 57 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 2cdb110..b8c2498 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -155,6 +155,12 @@ config ZYNQ_QSPI
  Zynq QSPI IP core. This IP is used to connect the flash in
  4-bit qspi, 8-bit dual stacked and shared 4-bit dual parallel.
 
+config OMAP3_SPI
+   bool "McSPI driver for OMAP"
+   help
+ SPI master controller for OMAP24XX and later Multichannel SPI
+ (McSPI) modules.
+
 endif # if DM_SPI
 
 config FSL_ESPI
diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 95cdfa3..09fb1ef 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -11,10 +11,14 @@
  *
  * Modified by Ruslan Araslanov 
  *
+ * Copyright (c) 2016 Christophe Ricard 
+ * - Added support for DM_SPI
+ *
  * SPDX-License-Identifier:GPL-2.0+
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -22,9 +26,17 @@
 
 #define SPI_WAIT_TIMEOUT 10
 
+#ifdef CONFIG_DM_SPI
+static void spi_reset(struct udevice *dev)
+#else
 static void spi_reset(struct omap3_spi_slave *ds)
+#endif
 {
unsigned int tmp;
+#ifdef CONFIG_DM_SPI
+   struct omap3_spi_slave *ds = dev_get_priv(dev->parent);
+
+#endif
 
writel(OMAP3_MCSPI_SYSCONFIG_SOFTRESET, &ds->regs->sysconfig);
do {
@@ -39,20 +51,50 @@ static void spi_reset(struct omap3_spi_slave *ds)
writel(OMAP3_MCSPI_WAKEUPENABLE_WKEN, &ds->regs->wakeupenable);
 }
 
+#ifdef CONFIG_DM_SPI
+static void omap3_spi_write_chconf(struct udevice *dev, int val)
+#else
 static void omap3_spi_write_chconf(struct omap3_spi_slave *ds, int val)
+#endif
 {
-   writel(val, &ds->regs->channel[ds->slave.cs].chconf);
+   unsigned int cs;
+#ifdef CONFIG_DM_SPI
+   struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev);
+   struct omap3_spi_slave *ds = dev_get_priv(dev->parent);
+
+
+   cs = platdata->cs;
+#else
+   cs = ds->slave.cs;
+#endif
+
+   writel(val, &ds->regs->channel[cs].chconf);
/* Flash post writes to make immediate effect */
-   readl(&ds->regs->channel[ds->slave.cs].chconf);
+   readl(&ds->regs->channel[cs].chconf);
 }
 
+#ifdef CONFIG_DM_SPI
+static void omap3_spi_set_enable(struct udevice *dev, int enable)
+#else
 static void omap3_spi_set_enable(struct omap3_spi_slave *ds, int enable)
+#endif
 {
-   writel(enable, &ds->regs->channel[ds->slave.cs].chctrl);
+   unsigned int cs;
+#ifdef CONFIG_DM_SPI
+   struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev);
+   struct omap3_spi_slave *ds = dev_get_priv(dev->parent);
+
+   cs = platdata->cs;
+#else
+   cs = ds->slave.cs;
+#endif
+
+   writel(enable, &ds->regs->channel[cs].chctrl);
/* Flash post writes to make immediate effect */
-   readl(&ds->regs->channel[ds->slave.cs].chctrl);
+   readl(&ds->regs->channel[cs].chctrl);
 }
 
+#ifndef CONFIG_DM_SPI
 void spi_init()
 {
/* do nothing */
@@ -138,10 +180,32 @@ void spi_free_slave(struct spi_slave *slave)
free(ds);
 }
 
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+   return 1;
+}
+#endif
+
+#ifdef CONFIG_DM_SPI
+static int omap3_spi_claim_bus(struct udevice *dev)
+#else
 int spi_claim_bus(struct spi_slave *slave)
+#endif
 {
-   struct omap3_spi_slave *ds = to_omap3_spi(slave);
+   unsigned int cs;
+   struct omap3_spi_slave *ds;
unsigned int conf, div = 0;
+#ifdef CONFIG_DM_SPI
+   struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev);
+   struct spi_slave *slave = dev_get_parent_priv(dev);
+
+   ds = dev_get_priv(dev->parent);
+   cs = platdata->cs;
+   ds->freq = slave->max_hz;
+#else
+   ds = to_omap3_spi(slave);
+   cs = ds->slave.cs;
+#endif
 
/* McSPI global module configuration */
 
@@ -149,7 +213,11 @@ int spi_claim_bus(struct spi_slave *slave)
 * setup when switching from (reset default) slave mode
 * to single-channel master mode
 */
+#ifdef CONFIG_DM_SPI
+   spi_reset(dev);
+#else
spi_reset(ds);
+#endif
conf = readl(&ds->regs->modulctrl);
conf &= ~(OMAP3_MCSPI_MODULCTRL_STEST | OMAP3_MCSPI_MODULCTRL_MS);
conf |= OMAP3_MCSPI_MODULCTRL_SINGLE;
@@ -165,8 +233,7 @@ int spi_claim_bus(struct spi_slave *slave)
} else
div = 0xC;
 
-   conf = readl(&ds->regs->channel[ds->slave.cs].chconf);
-
+   conf = readl(&ds->regs->channel[c

[U-Boot] [PATCH 4/4] spi: omap3: Convert fully to DM_SPI

2016-01-17 Thread Christophe Ricard
For several reasons:
- code clarity
- DM trends in u-boot
...

It is better to make omap3_spi driver 100% DM_SPI based.

Signed-off-by: Christophe Ricard 
---

 drivers/spi/omap3_spi.c | 474 +++-
 drivers/spi/omap3_spi.h | 121 
 2 files changed, 102 insertions(+), 493 deletions(-)
 delete mode 100644 drivers/spi/omap3_spi.h

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 09fb1ef..8ea2cc5 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -22,22 +22,93 @@
 #include 
 #include 
 #include 
-#include "omap3_spi.h"
+
+#if defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX)
+#define OMAP3_MCSPI1_BASE  0x48030100
+#define OMAP3_MCSPI2_BASE  0x481A0100
+#else
+#define OMAP3_MCSPI1_BASE  0x48098000
+#define OMAP3_MCSPI2_BASE  0x4809A000
+#define OMAP3_MCSPI3_BASE  0x480B8000
+#define OMAP3_MCSPI4_BASE  0x480BA000
+#endif
+
+#define OMAP3_MCSPI_MAX_FREQ   4800
+
+/* OMAP3 McSPI registers */
+struct mcspi_channel {
+   unsigned int chconf;/* 0x2C, 0x40, 0x54, 0x68 */
+   unsigned int chstat;/* 0x30, 0x44, 0x58, 0x6C */
+   unsigned int chctrl;/* 0x34, 0x48, 0x5C, 0x70 */
+   unsigned int tx;/* 0x38, 0x4C, 0x60, 0x74 */
+   unsigned int rx;/* 0x3C, 0x50, 0x64, 0x78 */
+};
+
+struct mcspi {
+   unsigned char res1[0x10];
+   unsigned int sysconfig; /* 0x10 */
+   unsigned int sysstatus; /* 0x14 */
+   unsigned int irqstatus; /* 0x18 */
+   unsigned int irqenable; /* 0x1C */
+   unsigned int wakeupenable;  /* 0x20 */
+   unsigned int syst;  /* 0x24 */
+   unsigned int modulctrl; /* 0x28 */
+   struct mcspi_channel channel[4]; /* channel0: 0x2C - 0x3C, bus 0 & 1 & 
2 & 3 */
+   /* channel1: 0x40 - 0x50, bus 0 & 1 */
+   /* channel2: 0x54 - 0x64, bus 0 & 1 */
+   /* channel3: 0x68 - 0x78, bus 0 */
+};
+
+/* per-register bitmasks */
+#define OMAP3_MCSPI_SYSCONFIG_SMARTIDLE (2 << 3)
+#define OMAP3_MCSPI_SYSCONFIG_ENAWAKEUP (1 << 2)
+#define OMAP3_MCSPI_SYSCONFIG_AUTOIDLE (1 << 0)
+#define OMAP3_MCSPI_SYSCONFIG_SOFTRESET (1 << 1)
+
+#define OMAP3_MCSPI_SYSSTATUS_RESETDONE (1 << 0)
+
+#define OMAP3_MCSPI_MODULCTRL_SINGLE   (1 << 0)
+#define OMAP3_MCSPI_MODULCTRL_MS   (1 << 2)
+#define OMAP3_MCSPI_MODULCTRL_STEST(1 << 3)
+
+#define OMAP3_MCSPI_CHCONF_PHA (1 << 0)
+#define OMAP3_MCSPI_CHCONF_POL (1 << 1)
+#define OMAP3_MCSPI_CHCONF_CLKD_MASK   (0x0f << 2)
+#define OMAP3_MCSPI_CHCONF_EPOL(1 << 6)
+#define OMAP3_MCSPI_CHCONF_WL_MASK (0x1f << 7)
+#define OMAP3_MCSPI_CHCONF_TRM_RX_ONLY (0x01 << 12)
+#define OMAP3_MCSPI_CHCONF_TRM_TX_ONLY (0x02 << 12)
+#define OMAP3_MCSPI_CHCONF_TRM_MASK(0x03 << 12)
+#define OMAP3_MCSPI_CHCONF_DMAW(1 << 14)
+#define OMAP3_MCSPI_CHCONF_DMAR(1 << 15)
+#define OMAP3_MCSPI_CHCONF_DPE0(1 << 16)
+#define OMAP3_MCSPI_CHCONF_DPE1(1 << 17)
+#define OMAP3_MCSPI_CHCONF_IS  (1 << 18)
+#define OMAP3_MCSPI_CHCONF_TURBO   (1 << 19)
+#define OMAP3_MCSPI_CHCONF_FORCE   (1 << 20)
+
+#define OMAP3_MCSPI_CHSTAT_RXS (1 << 0)
+#define OMAP3_MCSPI_CHSTAT_TXS (1 << 1)
+#define OMAP3_MCSPI_CHSTAT_EOT (1 << 2)
+
+#define OMAP3_MCSPI_CHCTRL_EN  (1 << 0)
+#define OMAP3_MCSPI_CHCTRL_DIS (0 << 0)
+
+#define OMAP3_MCSPI_WAKEUPENABLE_WKEN  (1 << 0)
+
+struct omap3_spi_slave {
+   struct mcspi *regs;
+   unsigned int freq;
+   unsigned int mode;
+};
 
 #define SPI_WAIT_TIMEOUT 10
 
-#ifdef CONFIG_DM_SPI
 static void spi_reset(struct udevice *dev)
-#else
-static void spi_reset(struct omap3_spi_slave *ds)
-#endif
 {
unsigned int tmp;
-#ifdef CONFIG_DM_SPI
struct omap3_spi_slave *ds = dev_get_priv(dev->parent);
 
-#endif
-
writel(OMAP3_MCSPI_SYSCONFIG_SOFTRESET, &ds->regs->sysconfig);
do {
tmp = readl(&ds->regs->sysstatus);
@@ -51,161 +122,37 @@ static void spi_reset(struct omap3_spi_slave *ds)
writel(OMAP3_MCSPI_WAKEUPENABLE_WKEN, &ds->regs->wakeupenable);
 }
 
-#ifdef CONFIG_DM_SPI
 static void omap3_spi_write_chconf(struct udevice *dev, int val)
-#else
-static void omap3_spi_write_chconf(struct omap3_spi_slave *ds, int val)
-#endif
 {
-   unsigned int cs;
-#ifdef CONFIG_DM_SPI
struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev);
struct omap3_spi_slave *ds = dev_get_priv(dev->parent);
-
-
-   cs = platdata->cs;
-#else
-

[U-Boot] [PATCH 3/5] i2c: omap24xx: Remove unused I2C_WAIT macro

2016-01-17 Thread Christophe Ricard
I2C_WAIT macro is not used in the code.
200 is bound to a fixed 10 Hz i2c speed based on an existing formula:
( 1000 / speed ) * 2 where speed = 100 000.

Signed-off-by: Christophe Ricard 
---

 drivers/i2c/omap24xx_i2c.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
index d6e5fe9..48ca446 100644
--- a/drivers/i2c/omap24xx_i2c.c
+++ b/drivers/i2c/omap24xx_i2c.c
@@ -55,9 +55,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define I2C_TIMEOUT1000
 
-/* Absolutely safe for status update at 100 kHz I2C: */
-#define I2C_WAIT   200
-
 #ifdef CONFIG_DM_I2C
 struct omap24_i2c_bus {
int bus_num;
-- 
2.5.0

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


[U-Boot] [PATCH 2/5] i2c: omap24xx: Fix waitdelay value for I2C HS

2016-01-17 Thread Christophe Ricard
After several testings and experiment, it appears that waitdelay calculation
formula was giving different behavior on the i2c status registers.

Experiment shows waitdelay needs to be extended at least 4 times to get
proper results.

Signed-off-by: Christophe Ricard 
---

 drivers/i2c/omap24xx_i2c.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
index f3a4d96..d6e5fe9 100644
--- a/drivers/i2c/omap24xx_i2c.c
+++ b/drivers/i2c/omap24xx_i2c.c
@@ -168,6 +168,13 @@ static int omap24_i2c_setspeed(struct udevice *adap, 
unsigned int speed)
scll = (unsigned int)hsscll << 8 | (unsigned int)fsscll;
sclh = (unsigned int)hssclh << 8 | (unsigned int)fssclh;
 
+#ifdef CONFIG_SYS_I2C
+   adap->speed = speed;
+   adap->waitdelay = (1000 / speed) * 8; /* wait for 20 
clkperiods */
+#else
+   i2c_bus->clock_frequency = speed;
+   i2c_bus->waitdelay = (1000 / speed) * 8; /* wait for 20 
clkperiods */
+#endif
} else {
/* Standard and fast speed */
psc = omap24_i2c_findpsc(&scll, &sclh, speed);
@@ -175,15 +182,15 @@ static int omap24_i2c_setspeed(struct udevice *adap, 
unsigned int speed)
puts("Error : I2C initializing clock\n");
return -1;
}
-   }
 
 #ifdef CONFIG_SYS_I2C
-   adap->speed = speed;
-   adap->waitdelay = (1000 / speed) * 2; /* wait for 20 clkperiods */
+   adap->speed = speed;
+   adap->waitdelay = (1000 / speed) * 2; /* wait for 20 
clkperiods */
 #else
-   i2c_bus->clock_frequency = speed;
-   i2c_bus->waitdelay = (1000 / speed) * 2; /* wait for 20 clkperiods 
*/
+   i2c_bus->clock_frequency = speed;
+   i2c_bus->waitdelay = (1000 / speed) * 2; /* wait for 20 
clkperiods */
 #endif
+   }
 
writew(0, &i2c_base->con);
writew(psc, &i2c_base->psc);
@@ -467,7 +474,6 @@ static int omap24_i2c_read(struct udevice *adap, uchar 
chip, uint addr,
i2c_bus = dev_get_priv(adap);
i2c_base = i2c_bus->i2c_base;
 #endif
-
if (alen < 0) {
puts("I2C read: addr len < 0\n");
return 1;
-- 
2.5.0

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


[U-Boot] [PATCH 4/5] i2c: omap24xx: Fix high speed trimming calculation

2016-01-17 Thread Christophe Ricard
Work based on i2c-omap.c from linux kernel.

fsscll/fssclh and hsscll/hssclh was always negative in high speed.

i2c high speed frequency start after 400Khz.

Signed-off-by: Christophe Ricard 
---

 drivers/i2c/omap24xx_i2c.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
index 48ca446..774edaf 100644
--- a/drivers/i2c/omap24xx_i2c.c
+++ b/drivers/i2c/omap24xx_i2c.c
@@ -129,7 +129,9 @@ static int omap24_i2c_setspeed(struct udevice *adap, 
unsigned int speed)
i2c_base = i2c_bus->i2c_base;
 #endif
 
-   if (speed >= OMAP_I2C_HIGH_SPEED) {
+   if (speed > 40) {
+   unsigned long scl;
+
/* High speed */
psc = I2C_IP_CLK / I2C_INTERNAL_SAMPLING_CLK;
psc -= 1;
@@ -139,12 +141,11 @@ static int omap24_i2c_setspeed(struct udevice *adap, 
unsigned int speed)
}
 
/* For first phase of HS mode */
-   fsscll = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
+   scl = I2C_INTERNAL_SAMPLING_CLK / 40;
 
-   fssclh = fsscll;
+   fsscll = scl - (scl / 3) - 7;
+   fssclh = (scl / 3)  - 5;
 
-   fsscll -= I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM;
-   fssclh -= I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM;
if (((fsscll < 0) || (fssclh < 0)) ||
((fsscll > 255) || (fssclh > 255))) {
puts("Error : I2C initializing first phase clock\n");
@@ -152,10 +153,10 @@ static int omap24_i2c_setspeed(struct udevice *adap, 
unsigned int speed)
}
 
/* For second phase of HS mode */
-   hsscll = hssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
+   scl = I2C_IP_CLK / speed;
+   hsscll = scl - (scl / 3) - 7;
+   hssclh = (scl / 3) - 5;
 
-   hsscll -= I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM;
-   hssclh -= I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM;
if (((fsscll < 0) || (fssclh < 0)) ||
((fsscll > 255) || (fssclh > 255))) {
puts("Error : I2C initializing second phase clock\n");
-- 
2.5.0

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


[U-Boot] [PATCH 1/5] i2c: omap24xx: Convert to DM

2016-01-17 Thread Christophe Ricard
Convert omap24xx_i2c driver to DM

Signed-off-by: Christophe Ricard 
---

 drivers/i2c/Kconfig|   8 ++
 drivers/i2c/omap24xx_i2c.c | 280 +++--
 2 files changed, 277 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 14adda2..3498af1 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -58,6 +58,14 @@ config DM_I2C_GPIO
  bindings are supported.
  Binding info: doc/device-tree-bindings/i2c/i2c-gpio.txt
 
+config SYS_I2C_OMAP24XX
+   bool "Texas Instrument OMAP I2C driver"
+   depends on DM_I2C
+   help
+ Enable support for the I2C interface on the Texas Instruments
+ OMAP1/2 family of processors. Like OMAP1510/1610/1710/5912 and 
OMAP242x.
+ For details see http://www.ti.com/omap.
+
 config SYS_I2C_ROCKCHIP
bool "Rockchip I2C driver"
depends on DM_I2C
diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
index 79a5c94..f3a4d96 100644
--- a/drivers/i2c/omap24xx_i2c.c
+++ b/drivers/i2c/omap24xx_i2c.c
@@ -36,13 +36,18 @@
  * Copyright (c) 2014 Hannes Schmelzer , B&R
  * - Added support for set_speed
  *
+ * Copyright (c) 2016 Christophe Ricard 
+ * - Added support for DM_I2C
+ *
  */
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
+#include 
 
 #include "omap24xx_i2c.h"
 
@@ -53,10 +58,26 @@ DECLARE_GLOBAL_DATA_PTR;
 /* Absolutely safe for status update at 100 kHz I2C: */
 #define I2C_WAIT   200
 
+#ifdef CONFIG_DM_I2C
+struct omap24_i2c_bus {
+   int bus_num;
+   int waitdelay;
+   unsigned clock_frequency;
+   struct i2c *i2c_base;
+};
+#endif
+
+#ifdef CONFIG_SYS_I2C
 static int wait_for_bb(struct i2c_adapter *adap);
 static struct i2c *omap24_get_base(struct i2c_adapter *adap);
 static u16 wait_for_event(struct i2c_adapter *adap);
 static void flush_fifo(struct i2c_adapter *adap);
+#else
+static int wait_for_bb(struct udevice *dev);
+static u16 wait_for_event(struct udevice *dev);
+static void flush_fifo(struct udevice *dev);
+#endif
+
 static int omap24_i2c_findpsc(u32 *pscl, u32 *psch, uint speed)
 {
unsigned int sampleclk, prescaler;
@@ -90,13 +111,27 @@ static int omap24_i2c_findpsc(u32 *pscl, u32 *psch, uint 
speed)
}
return -1;
 }
+
+#ifdef CONFIG_SYS_I2C
 static uint omap24_i2c_setspeed(struct i2c_adapter *adap, uint speed)
+#else
+static int omap24_i2c_setspeed(struct udevice *adap, unsigned int speed)
+#endif
 {
-   struct i2c *i2c_base = omap24_get_base(adap);
+   struct i2c *i2c_base;
int psc, fsscll = 0, fssclh = 0;
int hsscll = 0, hssclh = 0;
u32 scll = 0, sclh = 0;
 
+#ifdef CONFIG_SYS_I2C
+   i2c_base = omap24_get_base(adap);
+#else
+   struct omap24_i2c_bus *i2c_bus;
+
+   i2c_bus = dev_get_priv(adap);
+   i2c_base = i2c_bus->i2c_base;
+#endif
+
if (speed >= OMAP_I2C_HIGH_SPEED) {
/* High speed */
psc = I2C_IP_CLK / I2C_INTERNAL_SAMPLING_CLK;
@@ -142,8 +177,14 @@ static uint omap24_i2c_setspeed(struct i2c_adapter *adap, 
uint speed)
}
}
 
+#ifdef CONFIG_SYS_I2C
adap->speed = speed;
adap->waitdelay = (1000 / speed) * 2; /* wait for 20 clkperiods */
+#else
+   i2c_bus->clock_frequency = speed;
+   i2c_bus->waitdelay = (1000 / speed) * 2; /* wait for 20 clkperiods 
*/
+#endif
+
writew(0, &i2c_base->con);
writew(psc, &i2c_base->psc);
writew(scll, &i2c_base->scll);
@@ -154,13 +195,26 @@ static uint omap24_i2c_setspeed(struct i2c_adapter *adap, 
uint speed)
return 0;
 }
 
+#ifdef CONFIG_SYS_I2C
 static void omap24_i2c_deblock(struct i2c_adapter *adap)
+#else
+static int omap24_i2c_deblock(struct udevice *adap)
+#endif
 {
-   struct i2c *i2c_base = omap24_get_base(adap);
+   struct i2c *i2c_base;
int i;
u16 systest;
u16 orgsystest;
 
+#ifdef CONFIG_SYS_I2C
+   i2c_base = omap24_get_base(adap);
+#else
+   struct omap24_i2c_bus *i2c_bus;
+
+   i2c_bus = dev_get_priv(adap);
+   i2c_base = i2c_bus->i2c_base;
+#endif
+
/* set test mode ST_EN = 1 */
orgsystest = readw(&i2c_base->systest);
systest = orgsystest;
@@ -198,14 +252,31 @@ static void omap24_i2c_deblock(struct i2c_adapter *adap)
 
/* restore original mode */
writew(orgsystest, &i2c_base->systest);
+
+#ifdef CONFIG_DM_I2C
+   return 0;
+#endif
 }
 
+#ifdef CONFIG_SYS_I2C
 static void omap24_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
+#else
+static void omap24_i2c_init(struct udevice *adap, int speed, int slaveadd)
+#endif
 {
-   struct i2c *i2c_base = omap24_get_base(adap);
+   struct i2c *i2c_base;
int timeout = I2C_TIMEOUT;
int deblock = 1;
 
+#ifdef CONFIG_SYS_I2C
+   i2c_base = omap24_get_base(a

[U-Boot] [PATCH 0/5] Convert omap24xx-i2c driver to Driver Model

2016-01-17 Thread Christophe Ricard

Hi Simon,

This patchset tries to convert the TI omap24xx_i2c driver to Driver Model.
It has been tested on a TI BeagleBoard xM.

Best Regards
Christophe



Christophe Ricard (5):
  i2c: omap24xx: Convert to DM
  i2c: omap24xx: Fix waitdelay value for I2C HS
  i2c: omap24xx: Remove unused I2C_WAIT macro
  i2c: omap24xx: Fix high speed trimming calculation
  i2c: omap24xx: Convert fully to DM_I2C

 drivers/i2c/Kconfig|   8 +
 drivers/i2c/omap24xx_i2c.c | 395 ++---
 drivers/i2c/omap24xx_i2c.h | 154 --
 3 files changed, 276 insertions(+), 281 deletions(-)
 delete mode 100644 drivers/i2c/omap24xx_i2c.h

-- 
2.5.0

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


[U-Boot] [PATCH 5/5] i2c: omap24xx: Convert fully to DM_I2C

2016-01-17 Thread Christophe Ricard
For several reasons:
- code clarity
- DM trends in u-boot
...

It is better to make omap24xx_i2c driver 100% DM_I2C based.

Signed-off-by: Christophe Ricard 
---

 drivers/i2c/omap24xx_i2c.c | 447 +
 drivers/i2c/omap24xx_i2c.h | 154 
 2 files changed, 163 insertions(+), 438 deletions(-)
 delete mode 100644 drivers/i2c/omap24xx_i2c.h

diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
index 774edaf..baccb89 100644
--- a/drivers/i2c/omap24xx_i2c.c
+++ b/drivers/i2c/omap24xx_i2c.c
@@ -49,31 +49,164 @@
 #include 
 #include 
 
-#include "omap24xx_i2c.h"
-
 DECLARE_GLOBAL_DATA_PTR;
 
+/* I2C masks */
+
+/* I2C Interrupt Enable Register (I2C_IE): */
+#define I2C_IE_GC_IE   (1 << 5)
+#define I2C_IE_XRDY_IE (1 << 4) /* Transmit data ready interrupt enable */
+#define I2C_IE_RRDY_IE (1 << 3) /* Receive data ready interrupt enable */
+#define I2C_IE_ARDY_IE (1 << 2) /* Register access ready interrupt enable */
+#define I2C_IE_NACK_IE (1 << 1) /* No acknowledgment interrupt enable */
+#define I2C_IE_AL_IE   (1 << 0) /* Arbitration lost interrupt enable */
+
+/* I2C Status Register (I2C_STAT): */
+
+#define I2C_STAT_SBD   (1 << 15) /* Single byte data */
+#define I2C_STAT_BB(1 << 12) /* Bus busy */
+#define I2C_STAT_ROVR  (1 << 11) /* Receive overrun */
+#define I2C_STAT_XUDF  (1 << 10) /* Transmit underflow */
+#define I2C_STAT_AAS   (1 << 9)  /* Address as slave */
+#define I2C_STAT_GC(1 << 5)
+#define I2C_STAT_XRDY  (1 << 4)  /* Transmit data ready */
+#define I2C_STAT_RRDY  (1 << 3)  /* Receive data ready */
+#define I2C_STAT_ARDY  (1 << 2)  /* Register access ready */
+#define I2C_STAT_NACK  (1 << 1)  /* No acknowledgment interrupt enable */
+#define I2C_STAT_AL(1 << 0)  /* Arbitration lost interrupt enable */
+
+/* I2C Interrupt Code Register (I2C_INTCODE): */
+
+#define I2C_INTCODE_MASK   7
+#define I2C_INTCODE_NONE   0
+#define I2C_INTCODE_AL 1   /* Arbitration lost */
+#define I2C_INTCODE_NAK2   /* No acknowledgement/general 
call */
+#define I2C_INTCODE_ARDY   3   /* Register access ready */
+#define I2C_INTCODE_RRDY   4   /* Rcv data ready */
+#define I2C_INTCODE_XRDY   5   /* Xmit data ready */
+
+/* I2C Buffer Configuration Register (I2C_BUF): */
+
+#define I2C_BUF_RDMA_EN(1 << 15) /* Receive DMA channel enable 
*/
+#define I2C_BUF_XDMA_EN(1 << 7)  /* Transmit DMA channel 
enable */
+
+/* I2C Configuration Register (I2C_CON): */
+
+#define I2C_CON_EN (1 << 15)  /* I2C module enable */
+#define I2C_CON_BE (1 << 14)  /* Big endian mode */
+#define I2C_CON_STB(1 << 11)  /* Start byte mode (master mode only) */
+#define I2C_CON_MST(1 << 10)  /* Master/slave mode */
+#define I2C_CON_TRX(1 << 9)   /* Transmitter/receiver mode */
+  /* (master mode only) */
+#define I2C_CON_XA (1 << 8)   /* Expand address */
+#define I2C_CON_STP(1 << 1)   /* Stop condition (master mode only) */
+#define I2C_CON_STT(1 << 0)   /* Start condition (master mode only) */
+
+/* I2C System Test Register (I2C_SYSTEST): */
+
+#define I2C_SYSTEST_ST_EN  (1 << 15) /* System test enable */
+#define I2C_SYSTEST_FREE   (1 << 14) /* Free running mode, on brkpoint) */
+#define I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
+#define I2C_SYSTEST_TMODE_SHIFT(12)  /* Test mode select */
+#define I2C_SYSTEST_SCL_I  (1 << 3)  /* SCL line sense input value */
+#define I2C_SYSTEST_SCL_O  (1 << 2)  /* SCL line drive output value */
+#define I2C_SYSTEST_SDA_I  (1 << 1)  /* SDA line sense input value */
+#define I2C_SYSTEST_SDA_O  (1 << 0)  /* SDA line drive output value */
+
+/* I2C System Status Register (I2C_SYSS): */
+
+#define I2C_SYSS_RDONE  (1 << 0)  /* Internel reset monitoring */
+
+#define I2C_SCLL_SCLL  0
+#define I2C_SCLL_SCLL_M0xFF
+#define I2C_SCLL_HSSCLL8
+#define I2C_SCLH_HSSCLL_M  0xFF
+#define I2C_SCLH_SCLH  0
+#define I2C_SCLH_SCLH_M0xFF
+#define I2C_SCLH_HSSCLH8
+#define I2C_SCLH_HSSCLH_M  0xFF
+
+#define OMAP_I2C_STANDARD  10
+#define OMAP_I2C_FAST_MODE 40
+#define OMAP_I2C_HIGH_SPEED340
+
+#define SYSTEM_CLOCK_121200
+#define SYSTEM_CLOCK_131300
+#define SYSTEM_CLOCK_192   1920
+#define SYSTEM_CLOCK_969600
+
+/* Use the reference value of 96MHz if not explicitly set by the board */
+#ifndef I2C_IP_CLK
+#define I2C_IP_CLK SYSTEM_CLOCK_96
+#endif
+
+/*
+ * The reference minimum clock for high speed is 19.2MHz.
+ * The linux 2.6.

Re: [U-Boot] [PATCH 5/5] i2c: omap24xx: Convert fully to DM_I2C

2016-01-18 Thread Christophe Ricard
Hi Heiko,

I was expecting such kind of feedback on this one :).
I had myself to hack around between the MLO and the u-boot.img to get it
working.

For omap, i think twl drivers are kind of the main item to convert.

Would you accept to take the first 4 patches until the board are fully
ready for the 5th one ?

Best Regards
Christophe

2016-01-18 7:04 GMT+01:00 Heiko Schocher :

> Hello Christophe,
>
> Am 17.01.2016 um 12:09 schrieb Christophe Ricard:
>
>> For several reasons:
>> - code clarity
>> - DM trends in u-boot
>> ...
>>
>> It is better to make omap24xx_i2c driver 100% DM_I2C based.
>>
>> Signed-off-by: Christophe Ricard 
>> ---
>>
>>   drivers/i2c/omap24xx_i2c.c | 447
>> +
>>   drivers/i2c/omap24xx_i2c.h | 154 
>>   2 files changed, 163 insertions(+), 438 deletions(-)
>>   delete mode 100644 drivers/i2c/omap24xx_i2c.h
>>
>
> Full Ack .. but does this patch does not breeak boards, which use this
> driver, and are not converted to DM ? I think, we could remove the
> old style only, if all boards are converted ...
>
> bye,
> Heiko
>
>>
>> diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
>> index 774edaf..baccb89 100644
>> --- a/drivers/i2c/omap24xx_i2c.c
>> +++ b/drivers/i2c/omap24xx_i2c.c
>> @@ -49,31 +49,164 @@
>>   #include 
>>   #include 
>>
>> -#include "omap24xx_i2c.h"
>> -
>>
>
> ?
>
> Why do you remove the header file, and move all definitions into the
> c file?
>
>
>   DECLARE_GLOBAL_DATA_PTR;
>>
>> +/* I2C masks */
>> +
>> +/* I2C Interrupt Enable Register (I2C_IE): */
>> +#define I2C_IE_GC_IE   (1 << 5)
>> +#define I2C_IE_XRDY_IE (1 << 4) /* Transmit data ready interrupt enable
>> */
>> +#define I2C_IE_RRDY_IE (1 << 3) /* Receive data ready interrupt enable */
>> +#define I2C_IE_ARDY_IE (1 << 2) /* Register access ready interrupt
>> enable */
>> +#define I2C_IE_NACK_IE (1 << 1) /* No acknowledgment interrupt enable */
>> +#define I2C_IE_AL_IE   (1 << 0) /* Arbitration lost interrupt enable */
>> +
>> +/* I2C Status Register (I2C_STAT): */
>> +
>> +#define I2C_STAT_SBD   (1 << 15) /* Single byte data */
>> +#define I2C_STAT_BB(1 << 12) /* Bus busy */
>> +#define I2C_STAT_ROVR  (1 << 11) /* Receive overrun */
>> +#define I2C_STAT_XUDF  (1 << 10) /* Transmit underflow */
>> +#define I2C_STAT_AAS   (1 << 9)  /* Address as slave */
>> +#define I2C_STAT_GC(1 << 5)
>> +#define I2C_STAT_XRDY  (1 << 4)  /* Transmit data ready */
>> +#define I2C_STAT_RRDY  (1 << 3)  /* Receive data ready */
>> +#define I2C_STAT_ARDY  (1 << 2)  /* Register access ready */
>> +#define I2C_STAT_NACK  (1 << 1)  /* No acknowledgment interrupt enable */
>> +#define I2C_STAT_AL(1 << 0)  /* Arbitration lost interrupt enable */
>> +
>> +/* I2C Interrupt Code Register (I2C_INTCODE): */
>> +
>> +#define I2C_INTCODE_MASK   7
>> +#define I2C_INTCODE_NONE   0
>> +#define I2C_INTCODE_AL 1   /* Arbitration lost */
>> +#define I2C_INTCODE_NAK2   /* No
>> acknowledgement/general call */
>> +#define I2C_INTCODE_ARDY   3   /* Register access ready */
>> +#define I2C_INTCODE_RRDY   4   /* Rcv data ready */
>> +#define I2C_INTCODE_XRDY   5   /* Xmit data ready */
>> +
>> +/* I2C Buffer Configuration Register (I2C_BUF): */
>> +
>> +#define I2C_BUF_RDMA_EN(1 << 15) /* Receive DMA channel
>> enable */
>> +#define I2C_BUF_XDMA_EN(1 << 7)  /* Transmit DMA channel
>> enable */
>> +
>> +/* I2C Configuration Register (I2C_CON): */
>> +
>> +#define I2C_CON_EN (1 << 15)  /* I2C module enable */
>> +#define I2C_CON_BE (1 << 14)  /* Big endian mode */
>> +#define I2C_CON_STB(1 << 11)  /* Start byte mode (master mode only)
>> */
>> +#define I2C_CON_MST(1 << 10)  /* Master/slave mode */
>> +#define I2C_CON_TRX(1 << 9)   /* Transmitter/receiver mode */
>> +  /* (master mode only) */
>> +#define I2C_CON_XA (1 << 8)   /* Expand address */
>> +#define I2C_CON_STP(1 << 1)   /* Stop condition (master mode only) */
>> +#define I2C_CON_STT(1 << 0)   /* Start condition (master mode only)
>> */
>> +
>> +/* I2C System Test Register (I2C_SYSTEST): *

[U-Boot] [PATCH v2 2/2] tpm: tpm_tis_lpc: fix typo

2016-01-21 Thread Christophe Ricard
TPM_TIS_LPC is connected to the LPC bus, not I2C.

Reviewed-by: Simon Glass 
Signed-off-by: Christophe Ricard 
---

Changes in v2:
- Adding Reviewed-by: Simon Glass 

 drivers/tpm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 31b35f7..5a75f85 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -50,7 +50,7 @@ config TPM_TIS_LPC
bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
depends on TPM && X86
help
- This driver supports Infineon TPM devices connected on the I2C bus.
+ This driver supports Infineon TPM devices connected on the LPC bus.
  The usual tpm operations and the 'tpm' command can be used to talk
  to the device using the standard TPM Interface Specification (TIS)
  protocol
-- 
2.5.0

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


[U-Boot] [PATCH v2 0/2] TPM minor fixes

2016-01-21 Thread Christophe Ricard

Hi Simon,

Please find in this serie one bug fix and a typo cleanup.
This series is only adding mention to your review


Best Regards
Christophe


Changes in v2:
- Adding Reviewed-by: Simon Glass 

Christophe Ricard (2):
  tpm: Fix fault in case CONFIG_DM_TPM is set without any TPM
  tpm: tpm_tis_lpc: fix typo

 common/cmd_tpm.c| 2 +-
 drivers/tpm/Kconfig | 2 +-
 lib/tpm.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

-- 
2.5.0

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


[U-Boot] [PATCH v2 1/2] tpm: Fix fault in case CONFIG_DM_TPM is set without any TPM

2016-01-21 Thread Christophe Ricard
In case CONFIG_DM_TPM was set without any TPM chipset configured a fault
was generated (NULL pointer access).

Reviewed-by: Simon Glass 
Signed-off-by: Christophe Ricard 
---

Changes in v2:
- Adding Reviewed-by: Simon Glass 

 common/cmd_tpm.c | 2 +-
 lib/tpm.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index add6bfb..6edf3e9 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -448,7 +448,7 @@ static int get_tpm(struct udevice **devp)
int rc;
 
rc = uclass_first_device(UCLASS_TPM, devp);
-   if (rc) {
+   if (rc || !*devp) {
printf("Could not find TPM (ret=%d)\n", rc);
return CMD_RET_FAILURE;
}
diff --git a/lib/tpm.c b/lib/tpm.c
index 8a62216..f428d45 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -262,7 +262,7 @@ int tpm_init(void)
struct udevice *dev;
 
err = uclass_first_device(UCLASS_TPM, &dev);
-   if (err)
+   if (err || !dev)
return err;
return tpm_open(dev);
 }
-- 
2.5.0

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


[U-Boot] [PATCH v2 0/3] Add support for st33zp24 i2c and spi TPMs

2016-01-21 Thread Christophe Ricard

Hi Simon,

After a first tentative in August 2015:
http://lists.denx.de/pipermail/u-boot/2015-August/222596.html

I finally found some spare time for a new round to send a new version patch
version bringing support for ST33ZP24 TPM 1.2 with i2c and spi support.

I have been able to follow all your guidance from my previous tentative
and got able to convert omap24xx_i2c and omap3_spi drivers to DM.
I will send them in a separate patchset for your review.

Best Regards
Christophe


Changes in v2:
- Adding Reviewed-by: Simon Glass 

Christophe Ricard (3):
  tpm: Rename tpm_tis_infineon.h to tpm_tis.h and move infineon specific
stuff in tpm_infineon.c
  tpm: st33zp24: Add tpm st33zp24 support with i2c
  tpm: st33zp24: Add tpm st33zp24 spi support

 README|  11 +
 drivers/tpm/Kconfig   |  18 +
 drivers/tpm/Makefile  |   2 +
 drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} |  17 +-
 drivers/tpm/tpm_tis_infineon.c|  17 +-
 drivers/tpm/tpm_tis_st33zp24_i2c.c| 543 +
 drivers/tpm/tpm_tis_st33zp24_spi.c| 672 ++
 7 files changed, 1263 insertions(+), 17 deletions(-)
 rename drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} (86%)
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_i2c.c
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_spi.c

-- 
2.5.0

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


[U-Boot] [PATCH v2 2/3] tpm: st33zp24: Add tpm st33zp24 support with i2c

2016-01-21 Thread Christophe Ricard
Add support for TPM ST33ZP24 family with i2c.

For i2c we are relying only on DM_I2C.

Reviewed-by: Simon Glass 
Signed-off-by: Christophe Ricard 
---

Changes in v2:
- Adding Reviewed-by: Simon Glass 

 README |   7 +
 drivers/tpm/Kconfig|   9 +
 drivers/tpm/Makefile   |   1 +
 drivers/tpm/tpm_tis_st33zp24_i2c.c | 543 +
 4 files changed, 560 insertions(+)
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_i2c.c

diff --git a/README b/README
index 9423c34..e7c41c3 100644
--- a/README
+++ b/README
@@ -1432,6 +1432,13 @@ The following options need to be configured:
CONFIG_TPM_TIS_I2C_BURST_LIMITATION
Define the burst count bytes upper limit
 
+   CONFIG_TPM_ST33ZP24
+   Support for STMicroelectronics TPM devices. Requires DM_TPM 
support.
+
+   CONFIG_TPM_ST33ZP24_I2C
+   Support for STMicroelectronics ST33ZP24 I2C devices.
+   Requires TPM_ST33ZP24 and I2C.
+
CONFIG_TPM_ATMEL_TWI
Support for Atmel TWI TPM device. Requires I2C support.
 
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 5a75f85..9432160 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -64,4 +64,13 @@ config TPM_AUTH_SESSIONS
  TPM_LoadKey2 and TPM_GetPubKey are provided. Both features are
  available using the 'tpm' command, too.
 
+config TPM_ST33ZP24_I2C
+   bool "STMicroelectronics ST33ZP24 I2C TPM"
+   depends on TPM && DM_I2C
+   ---help---
+ This driver supports STMicroelectronics TPM devices connected on the 
I2C bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
 endmenu
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 1d49e95..cb066d7 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
 obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
+obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
diff --git a/drivers/tpm/tpm_tis_st33zp24_i2c.c 
b/drivers/tpm/tpm_tis_st33zp24_i2c.c
new file mode 100644
index 000..9e4829f
--- /dev/null
+++ b/drivers/tpm/tpm_tis_st33zp24_i2c.c
@@ -0,0 +1,543 @@
+/*
+ * STMicroelectronics TPM ST33ZP24 I2C UBOOT driver
+ *
+ * Copyright (C) 2016 STMicroelectronics
+ *
+ * Description: Device driver for ST33ZP24 I2C TPM TCG.
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
+ * STMicroelectronics Protocol Stack Specification version 1.2.0.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm_tis.h"
+#include "tpm_internal.h"
+
+#define TPM_ACCESS 0x0
+#define TPM_STS0x18
+#define TPM_DATA_FIFO  0x24
+
+#define LOCALITY0  0
+
+#define TPM_DUMMY_BYTE 0xAA
+#define TPM_ST33ZP24_I2C_SLAVE_ADDR0x13
+
+#define TPM_WRITE_DIRECTION 0x80
+
+/*
+ * st33zp24_i2c_write8_reg
+ * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
+ * @param: tpm_register, the tpm tis register where the data should be written
+ * @param: tpm_data, the tpm_data to write inside the tpm_register
+ * @param: tpm_size, The length of the data
+ * @return: Number of byte written successfully else an error code.
+ */
+static int st33zp24_i2c_write8_reg(struct udevice *dev, u8 tpm_register,
+  const u8 *tpm_data, size_t tpm_size)
+{
+   struct tpm_chip_priv *chip_priv = dev_get_uclass_priv(dev);
+
+   chip_priv->buf[0] = tpm_register;
+   memcpy(chip_priv->buf + 1, tpm_data, tpm_size);
+
+   return dm_i2c_write(dev, 0, chip_priv->buf, tpm_size + 1);
+}
+
+/*
+* st33zp24_i2c_read8_reg
+* Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
+* @param: tpm_register, the tpm tis register where the data should be read
+* @param: tpm_data, the TPM response
+* @param: tpm_size, tpm TPM response size to read.
+* @return: Number of byte read successfully else an error code.
+*/
+static int st33zp24_i2c_read8_reg(struct udevice *dev, u8 tpm_register,
+ u8 *tpm_data, size_t tpm_size)
+{
+   int status;
+   u8 data;
+
+   data = TPM_DUMMY_BYTE;
+   status = st33zp24_i2c_write8_reg(dev, tpm_register, &data, 1);
+   if (status < 0)
+   return status;
+
+   return dm_i2c_read(dev, 0, tpm_data, tpm_size);
+}
+
+/*

[U-Boot] [PATCH v2 1/3] tpm: Rename tpm_tis_infineon.h to tpm_tis.h and move infineon specific stuff in tpm_infineon.c

2016-01-21 Thread Christophe Ricard
I2C protocol is not standardize for TPM 1.2.
TIS prococol is define by the Trusted Computing Group and potentially
available on several TPMs.

tpm_tis_infineon.h header is not generic enough.

Rename tpm_tis_infineon.h to tpm_tis.h and move infineon specific
defines/variables to tpm_tis_infineon.c

Reviewed-by: Simon Glass 
Signed-off-by: Christophe Ricard 
---

Changes in v2:
- Adding Reviewed-by: Simon Glass 

 drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} | 17 +
 drivers/tpm/tpm_tis_infineon.c| 17 -
 2 files changed, 17 insertions(+), 17 deletions(-)
 rename drivers/tpm/{tpm_tis_infineon.h => tpm_tis.h} (86%)

diff --git a/drivers/tpm/tpm_tis_infineon.h b/drivers/tpm/tpm_tis.h
similarity index 86%
rename from drivers/tpm/tpm_tis_infineon.h
rename to drivers/tpm/tpm_tis.h
index 3b510d1..25b152b 100644
--- a/drivers/tpm/tpm_tis_infineon.h
+++ b/drivers/tpm/tpm_tis.h
@@ -37,18 +37,12 @@ enum tpm_timeout {
 #define TPM_RSP_SIZE_BYTE  2
 #define TPM_RSP_RC_BYTE6
 
-enum i2c_chip_type {
-   SLB9635,
-   SLB9645,
-   UNKNOWN,
-};
-
 struct tpm_chip {
int is_open;
int locality;
u32 vend_dev;
unsigned long timeout_a, timeout_b, timeout_c, timeout_d;  /* msec */
-   enum i2c_chip_type chip_type;
+   ulong chip_type;
 };
 
 struct tpm_input_header {
@@ -134,13 +128,4 @@ enum tis_status {
TPM_STS_DATA_EXPECT = 0x08,
 };
 
-/* expected value for DIDVID register */
-#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
-#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
-
-#defineTPM_ACCESS(l)   (0x | ((l) << 4))
-#defineTPM_STS(l)  (0x0001 | ((l) << 4))
-#defineTPM_DATA_FIFO(l)(0x0005 | ((l) << 4))
-#defineTPM_DID_VID(l)  (0x0006 | ((l) << 4))
-
 #endif
diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c
index f57c328..a4b6741 100644
--- a/drivers/tpm/tpm_tis_infineon.c
+++ b/drivers/tpm/tpm_tis_infineon.c
@@ -30,17 +30,32 @@
 #include 
 #include 
 
-#include "tpm_tis_infineon.h"
+#include "tpm_tis.h"
 #include "tpm_internal.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
+enum i2c_chip_type {
+   SLB9635,
+   SLB9645,
+   UNKNOWN,
+};
+
+/* expected value for DIDVID register */
+#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
+#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
+
 static const char * const chip_name[] = {
[SLB9635] = "slb9635tt",
[SLB9645] = "slb9645tt",
[UNKNOWN] = "unknown/fallback to slb9635",
 };
 
+#defineTPM_ACCESS(l)   (0x | ((l) << 4))
+#defineTPM_STS(l)  (0x0001 | ((l) << 4))
+#defineTPM_DATA_FIFO(l)(0x0005 | ((l) << 4))
+#defineTPM_DID_VID(l)  (0x0006 | ((l) << 4))
+
 /*
  * tpm_tis_i2c_read() - read from TPM register
  * @addr: register address to read from
-- 
2.5.0

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


[U-Boot] [PATCH v2 3/3] tpm: st33zp24: Add tpm st33zp24 spi support

2016-01-21 Thread Christophe Ricard
Add support for TPM ST33ZP24 spi.

The ST33ZP24 does have a spi interface.
The transport protocol is proprietary.

For spi we are relying only on DM_SPI.

Reviewed-by: Simon Glass 
Signed-off-by: Christophe Ricard 
---

Changes in v2:
- Adding Reviewed-by: Simon Glass 

 README |   4 +
 drivers/tpm/Kconfig|   9 +
 drivers/tpm/Makefile   |   1 +
 drivers/tpm/tpm_tis_st33zp24_spi.c | 672 +
 4 files changed, 686 insertions(+)
 create mode 100644 drivers/tpm/tpm_tis_st33zp24_spi.c

diff --git a/README b/README
index e7c41c3..dc2917c 100644
--- a/README
+++ b/README
@@ -1439,6 +1439,10 @@ The following options need to be configured:
Support for STMicroelectronics ST33ZP24 I2C devices.
Requires TPM_ST33ZP24 and I2C.
 
+   CONFIG_TPM_ST33ZP24_SPI
+   Support for STMicroelectronics ST33ZP24 SPI devices.
+   Requires TPM_ST33ZP24 and SPI.
+
CONFIG_TPM_ATMEL_TWI
Support for Atmel TWI TPM device. Requires I2C support.
 
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 9432160..9a7b7f5 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -73,4 +73,13 @@ config TPM_ST33ZP24_I2C
  to the device using the standard TPM Interface Specification (TIS)
  protocol
 
+config TPM_ST33ZP24_SPI
+   bool "STMicroelectronics ST33ZP24 SPI TPM"
+   depends on TPM && DM_SPI
+   ---help---
+ This driver supports STMicroelectronics TPM devices connected on the 
SPI bus.
+ The usual tpm operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol
+
 endmenu
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index cb066d7..c42a93f 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o
 obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
 obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
+obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
diff --git a/drivers/tpm/tpm_tis_st33zp24_spi.c 
b/drivers/tpm/tpm_tis_st33zp24_spi.c
new file mode 100644
index 000..417bbf1
--- /dev/null
+++ b/drivers/tpm/tpm_tis_st33zp24_spi.c
@@ -0,0 +1,672 @@
+/*
+ * STMicroelectronics TPM ST33ZP24 SPI UBOOT driver
+ *
+ * Copyright (C) 2016 STMicroelectronics
+ *
+ * Description: Device driver for ST33ZP24 SPI TPM TCG.
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
+ * STMicroelectronics Protocol Stack Specification version 1.2.0.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm_tis.h"
+#include "tpm_internal.h"
+
+#define TPM_ACCESS 0x0
+#define TPM_STS0x18
+#define TPM_DATA_FIFO  0x24
+
+#define LOCALITY0  0
+
+#define TPM_DATA_FIFO  0x24
+#define TPM_INTF_CAPABILITY0x14
+
+#define TPM_DUMMY_BYTE 0x00
+#define TPM_WRITE_DIRECTION0x80
+
+#define MAX_SPI_LATENCY15
+#define LOCALITY0  0
+
+#define ST33ZP24_OK0x5A
+#define ST33ZP24_UNDEFINED_ERR 0x80
+#define ST33ZP24_BADLOCALITY   0x81
+#define ST33ZP24_TISREGISTER_UKNOWN0x82
+#define ST33ZP24_LOCALITY_NOT_ACTIVATED0x83
+#define ST33ZP24_HASH_END_BEFORE_HASH_START0x84
+#define ST33ZP24_BAD_COMMAND_ORDER 0x85
+#define ST33ZP24_INCORECT_RECEIVED_LENGTH  0x86
+#define ST33ZP24_TPM_FIFO_OVERFLOW 0x89
+#define ST33ZP24_UNEXPECTED_READ_FIFO  0x8A
+#define ST33ZP24_UNEXPECTED_WRITE_FIFO 0x8B
+#define ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END   0x90
+#define ST33ZP24_DUMMY_BYTES   0x00
+
+/*
+ * TPM command can be up to 2048 byte, A TPM response can be up to
+ * 1024 byte.
+ * Between command and response, there are latency byte (up to 15
+ * usually on st33zp24 2 are enough).
+ *
+ * Overall when sending a command and expecting an answer we need if
+ * worst case:
+ * 2048 (for the TPM command) + 1024 (for the TPM answer).  We need
+ * some latency byte before the answer is available (max 15).
+ * We have 2048 + 1024 + 15.
+ */
+#define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\
+ MAX_SPI_LATENCY)
+
+struct st33zp24_sp