2 * Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
11 #include "slb9635_i2c/tpm.h"
13 DECLARE_GLOBAL_DATA_PTR;
15 /* TPM configuration */
24 static int tpm_select(void)
28 tpm.old_bus = i2c_get_bus_num();
29 if (tpm.old_bus != tpm.i2c_bus) {
30 ret = i2c_set_bus_num(tpm.i2c_bus);
32 debug("%s: Fail to set i2c bus %d\n", __func__,
40 static int tpm_deselect(void)
44 if (tpm.old_bus != i2c_get_bus_num()) {
45 ret = i2c_set_bus_num(tpm.old_bus);
47 debug("%s: Fail to restore i2c bus %d\n",
48 __func__, tpm.old_bus);
57 * Decode TPM configuration.
59 * @param dev Returns a configuration of TPM device
60 * @return 0 if ok, -1 on error
62 static int tpm_decode_config(struct tpm *dev)
64 #ifdef CONFIG_OF_CONTROL
65 const void *blob = gd->fdt_blob;
69 node = fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9635_TPM);
71 debug("%s: Node not found\n", __func__);
74 parent = fdt_parent_offset(blob, node);
76 debug("%s: Cannot find node parent\n", __func__);
79 i2c_bus = i2c_get_bus_num_fdt(parent);
82 dev->i2c_bus = i2c_bus;
83 dev->slave_addr = fdtdec_get_addr(blob, node, "reg");
85 dev->i2c_bus = CONFIG_INFINEON_TPM_I2C_BUS;
86 dev->slave_addr = CONFIG_INFINEON_TPM_I2C_ADDR;
96 if (tpm_decode_config(&tpm))
103 * Probe TPM twice; the first probing might fail because TPM is asleep,
104 * and the probing can wake up TPM.
106 if (i2c_probe(tpm.slave_addr) && i2c_probe(tpm.slave_addr)) {
107 debug("%s: fail to probe i2c addr 0x%x\n", __func__,
129 rc = tpm_open(tpm.slave_addr);
151 int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
152 uint8_t *recvbuf, size_t *rbuf_len)
160 if (sizeof(buf) < sbuf_size)
163 memcpy(buf, sendbuf, sbuf_size);
168 len = tpm_transmit(buf, sbuf_size);
177 memcpy(recvbuf, buf, len);