dm: tpm: Add Driver Model support for tpm_atmel_twi driver
tpm_atmel_twi can fit perfectly to the new UCLASS_TPM class. Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Reviewed-by: Tom Rini <trini@konsulko.com> Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
0766ad2f7f
commit
302c5dba0a
@ -6,6 +6,8 @@ CONFIG_SYS_EXTRA_OPTIONS="36BIT,SDCARD,DEVELOP"
|
|||||||
# CONFIG_CMD_FLASH is not set
|
# CONFIG_CMD_FLASH is not set
|
||||||
CONFIG_CMD_TPM=y
|
CONFIG_CMD_TPM=y
|
||||||
CONFIG_SPI_FLASH=y
|
CONFIG_SPI_FLASH=y
|
||||||
|
CONFIG_DM=y
|
||||||
|
CONFIG_DM_TPM=y
|
||||||
CONFIG_TPM_ATMEL_TWI=y
|
CONFIG_TPM_ATMEL_TWI=y
|
||||||
CONFIG_TPM_AUTH_SESSIONS=y
|
CONFIG_TPM_AUTH_SESSIONS=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
|
@ -6,6 +6,8 @@ CONFIG_SYS_EXTRA_OPTIONS="36BIT,SDCARD"
|
|||||||
# CONFIG_CMD_FLASH is not set
|
# CONFIG_CMD_FLASH is not set
|
||||||
CONFIG_CMD_TPM=y
|
CONFIG_CMD_TPM=y
|
||||||
CONFIG_SPI_FLASH=y
|
CONFIG_SPI_FLASH=y
|
||||||
|
CONFIG_DM=y
|
||||||
|
CONFIG_DM_TPM=y
|
||||||
CONFIG_TPM_ATMEL_TWI=y
|
CONFIG_TPM_ATMEL_TWI=y
|
||||||
CONFIG_TPM_AUTH_SESSIONS=y
|
CONFIG_TPM_AUTH_SESSIONS=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
|
@ -7,6 +7,8 @@ CONFIG_SYS_EXTRA_OPTIONS="TRAILBLAZER,SPIFLASH,DEVELOP"
|
|||||||
# CONFIG_CMD_FLASH is not set
|
# CONFIG_CMD_FLASH is not set
|
||||||
# CONFIG_CMD_SETEXPR is not set
|
# CONFIG_CMD_SETEXPR is not set
|
||||||
CONFIG_CMD_TPM=y
|
CONFIG_CMD_TPM=y
|
||||||
|
CONFIG_DM=y
|
||||||
|
CONFIG_DM_TPM=y
|
||||||
CONFIG_TPM_ATMEL_TWI=y
|
CONFIG_TPM_ATMEL_TWI=y
|
||||||
CONFIG_TPM_AUTH_SESSIONS=y
|
CONFIG_TPM_AUTH_SESSIONS=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
|
@ -7,6 +7,8 @@ CONFIG_SYS_EXTRA_OPTIONS="TRAILBLAZER,SPIFLASH"
|
|||||||
# CONFIG_CMD_FLASH is not set
|
# CONFIG_CMD_FLASH is not set
|
||||||
# CONFIG_CMD_SETEXPR is not set
|
# CONFIG_CMD_SETEXPR is not set
|
||||||
CONFIG_CMD_TPM=y
|
CONFIG_CMD_TPM=y
|
||||||
|
CONFIG_DM=y
|
||||||
|
CONFIG_DM_TPM=y
|
||||||
CONFIG_TPM_ATMEL_TWI=y
|
CONFIG_TPM_ATMEL_TWI=y
|
||||||
CONFIG_TPM_AUTH_SESSIONS=y
|
CONFIG_TPM_AUTH_SESSIONS=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
|
@ -24,7 +24,7 @@ config TPM_TIS_SANDBOX
|
|||||||
|
|
||||||
config TPM_ATMEL_TWI
|
config TPM_ATMEL_TWI
|
||||||
bool "Enable Atmel TWI TPM device driver"
|
bool "Enable Atmel TWI TPM device driver"
|
||||||
depends on TPM
|
depends on TPM && DM_I2C
|
||||||
help
|
help
|
||||||
This driver supports an Atmel TPM device connected on the I2C bus.
|
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
|
The usual tpm operations and the 'tpm' command can be used to talk
|
||||||
|
@ -7,51 +7,56 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <dm.h>
|
||||||
#include <tpm.h>
|
#include <tpm.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <asm/unaligned.h>
|
#include <asm/unaligned.h>
|
||||||
|
|
||||||
|
#include "tpm_internal.h"
|
||||||
|
|
||||||
#define ATMEL_TPM_TIMEOUT_MS 5000 /* sufficient for anything but
|
#define ATMEL_TPM_TIMEOUT_MS 5000 /* sufficient for anything but
|
||||||
generating/exporting keys */
|
generating/exporting keys */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tis_init()
|
* tpm_atmel_twi_open()
|
||||||
*
|
|
||||||
* 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()
|
|
||||||
*
|
*
|
||||||
* Requests access to locality 0 for the caller. After all commands have been
|
* Requests access to locality 0 for the caller. After all commands have been
|
||||||
* completed the caller is supposed to call tis_close().
|
* completed the caller is supposed to call tis_close().
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -1 on failure.
|
* Returns 0 on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tis_open(void)
|
static int tpm_atmel_twi_open(struct udevice *dev)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tis_close()
|
* tpm_atmel_twi_close()
|
||||||
*
|
*
|
||||||
* terminate the currect session with the TPM by releasing the locked
|
* terminate the currect session with the TPM by releasing the locked
|
||||||
* locality. Returns 0 on success of -1 on failure (in case lock
|
* locality. Returns 0 on success of -1 on failure (in case lock
|
||||||
* removal did not succeed).
|
* removal did not succeed).
|
||||||
*/
|
*/
|
||||||
int tis_close(void)
|
static int tpm_atmel_twi_close(struct udevice *dev)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tis_sendrecv()
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tpm_atmel_twi_xfer()
|
||||||
*
|
*
|
||||||
* Send the requested data to the TPM and then try to get its response
|
* 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)
|
* Returns 0 on success (and places the number of response bytes at recv_len)
|
||||||
* or -1 on failure.
|
* or -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
|
static int tpm_atmel_twi_xfer(struct udevice *dev,
|
||||||
size_t *recv_len)
|
const uint8_t *sendbuf, size_t send_size,
|
||||||
|
uint8_t *recvbuf, size_t *recv_len)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
unsigned long start;
|
unsigned long start;
|
||||||
@ -83,6 +89,7 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
|
|||||||
|
|
||||||
start = get_timer(0);
|
start = get_timer(0);
|
||||||
while ((res = i2c_read(0x29, 0, 0, recvbuf, 10))) {
|
while ((res = i2c_read(0x29, 0, 0, recvbuf, 10))) {
|
||||||
|
/* TODO Use TIS_TIMEOUT from tpm_tis_infineon.h */
|
||||||
if (get_timer(start) > ATMEL_TPM_TIMEOUT_MS) {
|
if (get_timer(start) > ATMEL_TPM_TIMEOUT_MS) {
|
||||||
puts("tpm timed out\n");
|
puts("tpm timed out\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -110,3 +117,28 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
|
|||||||
|
|
||||||
return res;
|
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_twi_ids,
|
||||||
|
.ops = &tpm_atmel_twi_ops,
|
||||||
|
.probe = tpm_atmel_twi_probe,
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user