Skip to contentSkip to conversation

tpm: Rename generic_lpc_tpm to tpm_tis_lpc

PATCH New Simon Glass 1 participant 5 messages Apr 12, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 tpm: Rename generic_lpc_tpm to tpm_tis_lpc

From: Che-liang Chiou <[email protected]>

The new name is more aligned with Linux kernel's naming of TPM driver.

---
 README                                           | 5 ++++-
 drivers/tpm/Makefile                             | 2 +-
 drivers/tpm/{generic_lpc_tpm.c => tpm_tis_lpc.c} | 0
 3 files changed, 5 insertions(+), 2 deletions(-)
 rename drivers/tpm/{generic_lpc_tpm.c => tpm_tis_lpc.c} (100%)
README +4 -1
index 67a071f..abc8b55 100644
@@ -1209,7 +1209,10 @@ The following options need to be configured:
 			If this option is set, the driver enables cache flush.
 
 - TPM Support:
-		CONFIG_GENERIC_LPC_TPM
+		CONFIG_TPM
+		Support TPM devices.
+
+		CONFIG_TPM_TIS_LPC
 		Support for generic parallel port TPM devices. Only one device
 		per system is supported at this time.
 
drivers/tpm/Makefile +1 -1
index e8c159c..d1f9bbf 100644
@@ -25,7 +25,7 @@ LIB := $(obj)libtpm.o
 
 $(shell mkdir -p $(obj)slb9635_i2c)
 
-COBJS-$(CONFIG_GENERIC_LPC_TPM) = generic_lpc_tpm.o
+COBJS-$(CONFIG_TPM_TIS_LPC) = tpm_tis_lpc.o
 COBJS-$(CONFIG_INFINEON_TPM_I2C) += tis_i2c.o slb9635_i2c/tpm.o
 COBJS-$(CONFIG_INFINEON_TPM_I2C) += slb9635_i2c/tpm_tis_i2c.o
 
drivers/tpm/tpm_tis_lpc.c renamed from drivers/tpm/generic_lpc_tpm.c +0 -0
similarity index 100%
rename from drivers/tpm/generic_lpc_tpm.c
rename to drivers/tpm/tpm_tis_lpc.c
Signature · 1 line
1.8.1.3
#1 lore raw

PATCH 2/5 x86: config: Reflect the name changes of LPC TPM configs

From: Tom Wai-Hong Tam <[email protected]>

The new name is more aligned with Linux kernel's naming of TPM driver.

---
 include/configs/coreboot.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/configs/coreboot.h +2 -1
index a4aa8f7..9237dde 100644
@@ -77,7 +77,8 @@
 #endif
 
 /* Generic TPM interfaced through LPC bus */
-#define CONFIG_GENERIC_LPC_TPM
+#define CONFIG_TPM
+#define CONFIG_TPM_TIS_LPC
 #define CONFIG_TPM_TIS_BASE_ADDRESS        0xfed40000
 
 /*-----------------------------------------------------------------------
Signature · 1 line
1.8.1.3
#2 lore raw

PATCH 3/5 tpm: Add support for new Infineon I2C TPM (SLB 9645 TT 1.2 I2C)

In reply to Simon Glass

From: Vincent Palatin <[email protected]>

Add support for Infineon's new SLB 9645 TT 1.2 I2C TPMs, which supports clockstretching, combined reads and a bus speed of up to 400khz. The device also has a new device id.

This is based on the kernel patch provided by Infineon :
https://gerrit.chromium.org/gerrit/42332

---
 drivers/tpm/slb9635_i2c/tpm_tis_i2c.c | 109 +++++++++++++++++++++++++++-------
 drivers/tpm/tis_i2c.c                 |   4 ++
 include/fdtdec.h                      |   1 +
 lib/fdtdec.c                          |   1 +
 4 files changed, 92 insertions(+), 23 deletions(-)
drivers/tpm/slb9635_i2c/tpm_tis_i2c.c +86 -23
index 82a41bf..c2e1041 100644
@@ -37,12 +37,15 @@
  */
 
 #include <common.h>
+#include <fdtdec.h>
 #include <i2c.h>
 #include <linux/types.h>
 
 #include "compatibility.h"
 #include "tpm.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* max. buffer size supported by our tpm */
 #ifdef TPM_BUFSIZE
 #undef TPM_BUFSIZE
@@ -65,12 +68,26 @@
 #define SLEEP_DURATION_LONG 210 /* in usec */
 
 /* expected value for DIDVID register */
-#define TPM_TIS_I2C_DID_VID 0x000b15d1L
+#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
+#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
+
+enum i2c_chip_type {
+	SLB9635,
+	SLB9645,
+	UNKNOWN,
+};
+
+static const char * const chip_name[] = {
+	[SLB9635] = "slb9635tt",
+	[SLB9645] = "slb9645tt",
+	[UNKNOWN] = "unknown/fallback to slb9635",
+};
 
 /* Structure to store I2C TPM specific stuff */
 struct tpm_inf_dev {
 	uint addr;
 	u8 buf[TPM_BUFSIZE + sizeof(u8)];	/* max. buffer size + addr */
+	enum i2c_chip_type chip_type;
 };
 
 static struct tpm_inf_dev tpm_dev = {
@@ -98,27 +115,47 @@ int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
 	uint myaddr = addr;
 	/* we have to use uint here, uchar hangs the board */
 
-	for (count = 0; count < MAX_COUNT; count++) {
-		rc = i2c_write(tpm_dev.addr, 0, 0, (uchar *)&myaddr, 1);
-		if (rc == 0)
-			break; /*success, break to skip sleep*/
-
-		udelay(SLEEP_DURATION);
-	}
+	if ((tpm_dev.chip_type == SLB9635) || (tpm_dev.chip_type == UNKNOWN)) {
+		/* slb9635 protocol should work in both cases */
+		for (count = 0; count < MAX_COUNT; count++) {
+			rc = i2c_write(tpm_dev.addr, 0, 0,
+				       (uchar *)&myaddr, 1);
+			if (rc == 0)
+				break;  /* success, break to skip sleep */
 
-	if (rc)
-		return -rc;
+			udelay(SLEEP_DURATION);
+		}
 
-	/* After the TPM has successfully received the register address it needs
-	 * some time, thus we're sleeping here again, before retrieving the data
-	 */
-	for (count = 0; count < MAX_COUNT; count++) {
-		udelay(SLEEP_DURATION);
-		rc = i2c_read(tpm_dev.addr, 0, 0, buffer, len);
-		if (rc == 0)
-			break; /*success, break to skip sleep*/
+		if (rc)
+			return -rc;
+
+		/* After the TPM has successfully received the register address
+		 * it needs some time, thus we're sleeping here again, before
+		 * retrieving the data
+		 */
+		for (count = 0; count < MAX_COUNT; count++) {
+			udelay(SLEEP_DURATION);
+			rc = i2c_read(tpm_dev.addr, 0, 0, buffer, len);
+			if (rc == 0)
+				break;  /* success, break to skip sleep */
+		}
+	} else {
+		/* use a combined read for newer chips
+		 * unfortunately the smbus functions are not suitable due to
+		 * the 32 byte limit of the smbus.
+		 * retries should usually not be needed, but are kept just to
+		 * be safe on the safe side.
+		 */
+		for (count = 0; count < MAX_COUNT; count++) {
+			rc = i2c_read(tpm_dev.addr, addr, 1, buffer, len);
+			if (rc == 0)
+				break;  /* break here to skip sleep */
+			udelay(SLEEP_DURATION);
+		}
 	}
 
+	/* take care of 'guard time' */
+	udelay(SLEEP_DURATION);
 	if (rc)
 		return -rc;
 
@@ -139,11 +176,13 @@ static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
 	for (count = 0; count < max_count; count++) {
 		rc = i2c_write(tpm_dev.addr, 0, 0, tpm_dev.buf, len + 1);
 		if (rc == 0)
-			break; /*success, break to skip sleep*/
+			break;  /* success, break to skip sleep */
 
 		udelay(sleep_time);
 	}
 
+	/* take care of 'guard time' */
+	udelay(SLEEP_DURATION);
 	if (rc)
 		return -rc;
 
@@ -490,12 +529,27 @@ static struct tpm_vendor_specific tpm_tis_i2c = {
 	.req_canceled = TPM_STS_COMMAND_READY,
 };
 
+static enum i2c_chip_type tpm_vendor_chip_type(void)
+{
+#ifdef CONFIG_OF_CONTROL
+	const void *blob = gd->fdt_blob;
+
+	if (fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9645_TPM) >= 0)
+		return SLB9645;
+
+	if (fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9635_TPM) >= 0)
+		return SLB9635;
+#endif
+	return UNKNOWN;
+}
+
 /* initialisation of i2c tpm */
 
 
 int tpm_vendor_init(uint32_t dev_addr)
 {
 	u32 vendor;
+	u32 expected_did_vid;
 	uint old_addr;
 	int rc = 0;
 	struct tpm_chip *chip;
@@ -504,6 +558,8 @@ int tpm_vendor_init(uint32_t dev_addr)
 	if (dev_addr != 0)
 		tpm_dev.addr = dev_addr;
 
+	tpm_dev.chip_type = tpm_vendor_chip_type();
+
 	chip = tpm_register_hardware(&tpm_tis_i2c);
 	if (chip < 0) {
 		rc = -ENODEV;
@@ -530,15 +586,22 @@ int tpm_vendor_init(uint32_t dev_addr)
 		goto out_release;
 	}
 
-	/* create DID_VID register value, after swapping to little-endian */
-	vendor = be32_to_cpu(vendor);
+	if (tpm_dev.chip_type == SLB9635) {
+		vendor = be32_to_cpu(vendor);
+		expected_did_vid = TPM_TIS_I2C_DID_VID_9635;
+	} else {
+		/* device id and byte order has changed for newer i2c tpms */
+		expected_did_vid = TPM_TIS_I2C_DID_VID_9645;
+	}
 
-	if (vendor != TPM_TIS_I2C_DID_VID) {
+	if (tpm_dev.chip_type != UNKNOWN && vendor != expected_did_vid) {
+		dev_err(dev, "vendor id did not match! ID was %08x\n", vendor);
 		rc = -ENODEV;
 		goto out_release;
 	}
 
-	dev_info(dev, "1.2 TPM (device-id 0x%X)\n", vendor >> 16);
+	dev_info(dev, "1.2 TPM (chip type %s device-id 0x%X)\n",
+		 chip_name[tpm_dev.chip_type], vendor >> 16);
 
 	/*
 	 * A timeout query to TPM can be placed here.
drivers/tpm/tis_i2c.c +4 -0
index e818fba..22554e1 100644
@@ -68,6 +68,10 @@ static int tpm_decode_config(struct tpm *dev)
 
 	node = fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9635_TPM);
 	if (node < 0) {
+		node = fdtdec_next_compatible(blob, 0,
+					      COMPAT_INFINEON_SLB9645_TPM);
+	}
+	if (node < 0) {
 		debug("%s: Node not found\n", __func__);
 		return -1;
 	}
include/fdtdec.h +1 -0
index 39fbdf1..4c43650 100644
@@ -91,6 +91,7 @@ enum fdt_compat_id {
 	COMPAT_GENERIC_SPI_FLASH,	/* Generic SPI Flash chip */
 	COMPAT_MAXIM_98095_CODEC,	/* MAX98095 Codec */
 	COMPAT_INFINEON_SLB9635_TPM,	/* Infineon SLB9635 TPM */
+	COMPAT_INFINEON_SLB9645_TPM,	/* Infineon SLB9645 TPM */
 
 	COMPAT_COUNT,
 };
lib/fdtdec.c +1 -0
index e93743c..beb6399 100644
@@ -64,6 +64,7 @@ static const char * const compat_names[COMPAT_COUNT] = {
 	COMPAT(GENERIC_SPI_FLASH, "spi-flash"),
 	COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"),
 	COMPAT(INFINEON_SLB9635_TPM, "infineon,slb9635-tpm"),
+	COMPAT(INFINEON_SLB9645_TPM, "infineon,slb9645-tpm"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
Signature · 1 line
1.8.1.3
#3 lore raw

PATCH 4/5 tpm: Reorganize the I2C TPM driver

In reply to Simon Glass

From: Tom Wai-Hong Tam <[email protected]>

This patch does a similar code reogranzation from
http://patchwork.ozlabs.org/patch/132179/
which is based on an old version of code (fdt support and bus selection still not in). It merges this tidy-up on top of the recent code. It does not make any logical change.

tpm.c implements the interface defined in tpm.h based on underlying LPC or I2C TPM driver. tpm.c and the underlying driver communicate throught tpm_private.h.

Note: Merging the LPC driver with tpm.c is left to future patches.

---
 README                                           |  13 ++
 drivers/tpm/Makefile                             |   7 +-
 drivers/tpm/slb9635_i2c/compatibility.h          |  51 -----
 drivers/tpm/{slb9635_i2c => }/tpm.c              | 280 ++++++++++++++++++-----
 drivers/tpm/{slb9635_i2c/tpm.h => tpm_private.h} |  46 +---
 drivers/tpm/{slb9635_i2c => }/tpm_tis_i2c.c      | 267 +++++++++++----------
 6 files changed, 396 insertions(+), 268 deletions(-)
 delete mode 100644 drivers/tpm/slb9635_i2c/compatibility.h
 rename drivers/tpm/{slb9635_i2c => }/tpm.c (63%)
 rename drivers/tpm/{slb9635_i2c/tpm.h => tpm_private.h} (71%)
 rename drivers/tpm/{slb9635_i2c => }/tpm_tis_i2c.c (73%)
README +13 -0
index abc8b55..697962e 100644
@@ -1212,6 +1212,19 @@ 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
+		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
+
 		CONFIG_TPM_TIS_LPC
 		Support for generic parallel port TPM devices. Only one device
 		per system is supported at this time.
drivers/tpm/Makefile +4 -3
index d1f9bbf..913dd9c 100644
@@ -25,9 +25,10 @@ LIB := $(obj)libtpm.o
 
 $(shell mkdir -p $(obj)slb9635_i2c)
 
-COBJS-$(CONFIG_TPM_TIS_LPC) = tpm_tis_lpc.o
-COBJS-$(CONFIG_INFINEON_TPM_I2C) += tis_i2c.o slb9635_i2c/tpm.o
-COBJS-$(CONFIG_INFINEON_TPM_I2C) += slb9635_i2c/tpm_tis_i2c.o
+# TODO: Merge tpm_tis_lpc.c with tpm.c
+COBJS-$(CONFIG_TPM_TIS_I2C) += tpm.o
+COBJS-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
+COBJS-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/tpm/slb9635_i2c/compatibility.h deleted +0 -51

51 lines not on this page · raw message

drivers/tpm/tpm.c renamed from drivers/tpm/slb9635_i2c/tpm.c +228 -52

368 lines not on this page · raw message

drivers/tpm/tpm_private.h renamed from drivers/tpm/slb9635_i2c/tpm.h +11 -35

76 lines not on this page · raw message

drivers/tpm/tpm_tis_i2c.c renamed from drivers/tpm/slb9635_i2c/tpm_tis_i2c.c +140 -127

550 lines not on this page · raw message

Signature · 1 line
1.8.1.3
#4 lore raw

PATCH 5/5 exynos: config: Reflect the name changes of I2C TPM configs

In reply to Simon Glass

From: Tom Wai-Hong Tam <[email protected]>

The new name is more aligned with Linux kernel's naming of TPM driver.

---
 include/configs/exynos5250-dt.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/configs/exynos5250-dt.h +3 -3
index 7378487..4961403 100644
@@ -132,9 +132,9 @@
 /* TPM */
 #define CONFIG_TPM
 #define CONFIG_CMD_TPM
-#define CONFIG_INFINEON_TPM_I2C
-#define CONFIG_INFINEON_TPM_I2C_BUS 3
-#define CONFIG_INFINEON_TPM_I2C_ADDR 0x20
+#define CONFIG_TPM_TIS_I2C
+#define CONFIG_TPM_TIS_I2C_BUS_NUMBER	3
+#define CONFIG_TPM_TIS_I2C_SLAVE_ADDR	0x20
 
 /* MMC SPL */
 #define CONFIG_SPL
Signature · 1 line
1.8.1.3