[U-Boot] [PATCH 3/3] tpm: Add st33zp24 tpm with i2c and spi phy
Simon Glass
sjg at chromium.org
Fri Aug 14 00:53:27 CEST 2015
Hi Christophe,
On 13 August 2015 at 14:59, Christophe Ricard
<christophe.ricard at gmail.com> wrote:
> Hi Simon,
>
>
> On 13/08/2015 17:55, Simon Glass wrote:
>>
>> Hi Christophe,
>>
>> On 9 August 2015 at 07:19, Christophe Ricard
>> <christophe.ricard at gmail.com> 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 <christophe-h.ricard at st.com>
>>> ---
>>>
>>> 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 0000000..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 0000000..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 <common.h>
>>> +#include <i2c.h>
>>> +#include <dm.h>
>>> +#include <linux/types.h>
>>
>> That may not be needed, but if so should go after the dm/platform_data...
>>
>>> +#include <malloc.h>
>>> +#include <tpm.h>
>>> +#include <errno.h>
>>
>> Should go up under common.h
>
> ok.
>>>
>>> +#include <asm/unaligned.h>
>>> +#include <dm/platform_data/st33zp24_i2c.h>
>>> +
>>> +#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,
> };
We don't support I2C in driver model without device tree. We're trying
to encourage people to drop platform data and use device tree.
See am335x_boneblack_vboot. It should be fairly straightfoward to
convert over the omap_24xx driver if you have time.
[snip]
>>> +
>>> +#define TPM_ST33ZP24_SPI "st33zp24-spi"
>>> +
>>> +struct st33zp24_spi_platdata {
>>> + int bus_num;
>>> + int cs;
>>> + int max_speed;
>>> + int mode;
>>
>> Hopefully not needed.
>
> How to declare a SPI device using platform then ? On beagleboard i was doing
> this:
>
> static const struct st33zp24_spi_platdata beagle_tpm_spi = {
> .bus_num = 3,
> .cs = 0,
> .max_speed = 10000000,
> .mode = 0,
> };
>
> U_BOOT_DEVICE(beagle_tpm_spi) = {
> .name = TPM_ST33ZP24_SPI,
> .platdata = &beagle_tpm_spi,
> };
Again, you can't. There is a guide to porting SPI drivers in doc/driver-model.
>
>>
>>> +};
>>> +
>>> +#endif /* __ST33ZP24_SPI_H__ */
>>> diff --git a/include/fdtdec.h b/include/fdtdec.h
>>> index eac679e..9eb2b3d 100644
>>> --- a/include/fdtdec.h
>>> +++ b/include/fdtdec.h
>>> @@ -182,7 +182,10 @@ enum fdt_compat_id {
>>> COMPAT_INTEL_PCH, /* Intel PCH */
>>> COMPAT_INTEL_IRQ_ROUTER, /* Intel Interrupt Router */
>>> COMPAT_ALTERA_SOCFPGA_DWMAC, /* SoCFPGA Ethernet controller
>>> */
>>> -
>>> + COMPAT_STMICROELECTRONICS_ST33ZP24_I2C,
>>> + /* STMicroelectronics ST33ZP24
>>> I2C TPM */
>>> + COMPAT_STMICROELECTRONICS_ST33ZP24_SPI,
>>> + /* STMicroelectronics ST33ZP24
>>> SPI TPM */
>>
>> Shouldn't be needed.
>
> According to your previous comments, i think i understand why. Did you
> update Infineon id as well ?
>>
>>
>>> COMPAT_COUNT,
>>> };
>>>
>>> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
>>> index b201787..55c64a0 100644
>>> --- a/lib/fdtdec.c
>>> +++ b/lib/fdtdec.c
>>> @@ -76,6 +76,8 @@ static const char * const compat_names[COMPAT_COUNT] =
>>> {
>>> COMPAT(COMPAT_INTEL_PCH, "intel,bd82x6x"),
>>> COMPAT(COMPAT_INTEL_IRQ_ROUTER, "intel,irq-router"),
>>> COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"),
>>> + COMPAT(STMICROELECTRONICS_ST33ZP24_I2C, "st,st33zp24-i2c"),
>>> + COMPAT(STMICROELECTRONICS_ST33ZP24_SPI, "st,st33zp24-spi"),
>>> };
>>>
>>> const char *fdtdec_get_compatible(enum fdt_compat_id id)
>>> --
>>> 2.1.4
>>>
>> Regards,
>> Simon
>
> Best Regards
> Christophe
More information about the U-Boot
mailing list