1 // SPDX-License-Identifier: GPL-2.0
3 * driver for mmio TCG/TIS TPM (trusted platform module).
5 * Specifications at www.trustedcomputinggroup.org
12 #include <linux/bitops.h>
13 #include <linux/compiler.h>
14 #include <linux/delay.h>
15 #include <linux/errno.h>
16 #include <linux/types.h>
18 #include <linux/unaligned/be_byteshift.h>
20 #include "tpm_internal.h"
23 * struct tpm_tis_chip_data - Information about an MMIO TPM
24 * @pcr_count: Number of PCR per bank
25 * @pcr_select_min: Minimum size in bytes of the pcrSelect array
26 * @iobase: Base address
28 struct tpm_tis_chip_data {
29 unsigned int pcr_count;
30 unsigned int pcr_select_min;
34 static int mmio_read_bytes(struct udevice *dev, u32 addr, u16 len,
37 struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
40 *result++ = ioread8(drv_data->iobase + addr);
45 static int mmio_write_bytes(struct udevice *dev, u32 addr, u16 len,
48 struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
51 iowrite8(*value++, drv_data->iobase + addr);
56 static int mmio_read32(struct udevice *dev, u32 addr, u32 *result)
58 struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
60 *result = ioread32(drv_data->iobase + addr);
65 static int mmio_write32(struct udevice *dev, u32 addr, u32 value)
67 struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
69 iowrite32(value, drv_data->iobase + addr);
74 static struct tpm_tis_phy_ops phy_ops = {
75 .read_bytes = mmio_read_bytes,
76 .write_bytes = mmio_write_bytes,
77 .read32 = mmio_read32,
78 .write32 = mmio_write32,
81 static int tpm_tis_probe(struct udevice *dev)
83 struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
84 struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
89 ioaddr = dev_read_addr(dev);
90 if (ioaddr == FDT_ADDR_T_NONE)
91 return log_msg_ret("ioaddr", -EINVAL);
93 ret = dev_read_u64(dev, "reg", &sz);
97 drv_data->iobase = ioremap(ioaddr, sz);
98 tpm_tis_ops_register(dev, &phy_ops);
99 ret = tpm_tis_init(dev);
103 priv->pcr_count = drv_data->pcr_count;
104 priv->pcr_select_min = drv_data->pcr_select_min;
106 * Although the driver probably works with a TPMv1 our Kconfig
107 * limits the driver to TPMv2 only
109 priv->version = TPM_V2;
113 iounmap(drv_data->iobase);
118 static int tpm_tis_remove(struct udevice *dev)
120 struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
123 ret = tpm_tis_cleanup(dev);
125 iounmap(drv_data->iobase);
130 static const struct tpm_ops tpm_tis_ops = {
131 .open = tpm_tis_open,
132 .close = tpm_tis_close,
133 .get_desc = tpm_tis_get_desc,
134 .send = tpm_tis_send,
135 .recv = tpm_tis_recv,
136 .cleanup = tpm_tis_cleanup,
139 static const struct tpm_tis_chip_data tpm_tis_std_chip_data = {
144 static const struct udevice_id tpm_tis_ids[] = {
146 .compatible = "tcg,tpm-tis-mmio",
147 .data = (ulong)&tpm_tis_std_chip_data,
152 U_BOOT_DRIVER(tpm_tis_mmio) = {
153 .name = "tpm_tis_mmio",
155 .of_match = tpm_tis_ids,
157 .probe = tpm_tis_probe,
158 .remove = tpm_tis_remove,
159 .priv_auto = sizeof(struct tpm_chip),