summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-08-22 18:31:35 -0600
committerSimon Glass <sjg@chromium.org>2015-08-31 07:57:28 -0600
commit21baf15b4e638cf7719994fe6ac86e0d0e93aa78 (patch)
treeafaa5f6616ccb121eb9ccfd202bc1e98a5486b00
parentf8f1fe1d5262d1d089bfa5bfdf703d5b2c5e0030 (diff)
downloadu-boot-imx-21baf15b4e638cf7719994fe6ac86e0d0e93aa78.zip
u-boot-imx-21baf15b4e638cf7719994fe6ac86e0d0e93aa78.tar.gz
u-boot-imx-21baf15b4e638cf7719994fe6ac86e0d0e93aa78.tar.bz2
dm: tpm: sandbox: Convert TPM driver to driver model
Convert the sandbox TPM driver to use driver model. Add it to the device tree so that it can be found on start-up. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Christophe Ricard <christophe-h.ricard@st.com> Reviewed-by: Heiko Schocher <hs@denx.de>
-rw-r--r--arch/sandbox/dts/sandbox.dts4
-rw-r--r--configs/sandbox_defconfig1
-rw-r--r--drivers/tpm/tpm_tis_sandbox.c57
3 files changed, 50 insertions, 12 deletions
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 8927527..758c4a5 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -156,6 +156,10 @@
sides = <4>;
};
+ tpm {
+ compatible = "google,sandbox-tpm";
+ };
+
triangle {
compatible = "demo-shape";
colour = "cyan";
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index b68d688..2600bf7 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -31,6 +31,7 @@ CONFIG_CROS_EC_KEYB=y
CONFIG_LED=y
CONFIG_LED_GPIO=y
CONFIG_SANDBOX_SERIAL=y
+CONFIG_DM_TPM=y
CONFIG_TPM_TIS_SANDBOX=y
CONFIG_SYS_I2C_SANDBOX=y
CONFIG_SANDBOX_SPI=y
diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c
index ed4b039..9ea9807 100644
--- a/drivers/tpm/tpm_tis_sandbox.c
+++ b/drivers/tpm/tpm_tis_sandbox.c
@@ -5,6 +5,8 @@
*/
#include <common.h>
+#include <dm.h>
+#include <tpm.h>
#include <asm/state.h>
#include <asm/unaligned.h>
#include <linux/crc8.h>
@@ -56,7 +58,7 @@ enum {
*/
static struct tpm_state {
uint8_t nvdata[NV_SEQ_COUNT][NV_DATA_SIZE];
-} state;
+} g_state;
/**
* sandbox_tpm_read_state() - read the sandbox EC state from the state file
@@ -82,7 +84,7 @@ static int sandbox_tpm_read_state(const void *blob, int node)
sprintf(prop_name, "nvdata%d", i);
prop = fdt_getprop(blob, node, prop_name, &len);
if (prop && len == NV_DATA_SIZE)
- memcpy(state.nvdata[i], prop, NV_DATA_SIZE);
+ memcpy(g_state.nvdata[i], prop, NV_DATA_SIZE);
}
return 0;
@@ -110,7 +112,7 @@ static int sandbox_tpm_write_state(void *blob, int node)
char prop_name[20];
sprintf(prop_name, "nvdata%d", i);
- fdt_setprop(blob, node, prop_name, state.nvdata[i],
+ fdt_setprop(blob, node, prop_name, g_state.nvdata[i],
NV_DATA_SIZE);
}
@@ -135,10 +137,11 @@ static int index_to_seq(uint32_t index)
return -1;
}
-int tis_sendrecv(const u8 *sendbuf, size_t send_size,
- u8 *recvbuf, size_t *recv_len)
+static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
+ size_t send_size, uint8_t *recvbuf,
+ size_t *recv_len)
{
- struct tpm_state *tpm = &state;
+ struct tpm_state *tpm = dev_get_priv(dev);
uint32_t code, index, length, type;
uint8_t *data;
int seq;
@@ -241,20 +244,50 @@ int tis_sendrecv(const u8 *sendbuf, size_t send_size,
return 0;
}
-int tis_open(void)
+static int sandbox_tpm_get_desc(struct udevice *dev, char *buf, int size)
{
- printf("%s\n", __func__);
+ if (size < 15)
+ return -ENOSPC;
+
+ return snprintf(buf, size, "sandbox TPM");
+}
+
+static int sandbox_tpm_probe(struct udevice *dev)
+{
+ struct tpm_state *tpm = dev_get_priv(dev);
+
+ memcpy(tpm, &g_state, sizeof(*tpm));
+
return 0;
}
-int tis_close(void)
+static int sandbox_tpm_open(struct udevice *dev)
{
- printf("%s\n", __func__);
return 0;
}
-int tis_init(void)
+static int sandbox_tpm_close(struct udevice *dev)
{
- printf("%s\n", __func__);
return 0;
}
+
+static const struct tpm_ops sandbox_tpm_ops = {
+ .open = sandbox_tpm_open,
+ .close = sandbox_tpm_close,
+ .get_desc = sandbox_tpm_get_desc,
+ .xfer = sandbox_tpm_xfer,
+};
+
+static const struct udevice_id sandbox_tpm_ids[] = {
+ { .compatible = "google,sandbox-tpm" },
+ { }
+};
+
+U_BOOT_DRIVER(sandbox_tpm) = {
+ .name = "sandbox_tpm",
+ .id = UCLASS_TPM,
+ .of_match = sandbox_tpm_ids,
+ .ops = &sandbox_tpm_ops,
+ .probe = sandbox_tpm_probe,
+ .priv_auto_alloc_size = sizeof(struct tpm_state),
+};