blob: 5635f5543438f25d5c67283c6d2fab0da12f4862 [file] [log] [blame]
developerd82d9fc2022-06-23 19:03:51 +08001From 6110010f7b88392a3094f2aaec91ee54151cde2a Mon Sep 17 00:00:00 2001
2From: "SkyLake.Huang" <skylake.huang@mediatek.com>
3Date: Thu, 23 Jun 2022 18:43:02 +0800
4Subject: [PATCH] drivers: char: tpm: Add calibration example for SPI TPM
5 module
6
7Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
8---
9 drivers/char/tpm/tpm_tis_core.c | 19 +++++++++++++++++++
10 drivers/char/tpm/tpm_tis_core.h | 2 ++
11 drivers/char/tpm/tpm_tis_spi.c | 7 +++++++
12 3 files changed, 28 insertions(+)
13
developerd82d9fc2022-06-23 19:03:51 +080014--- a/drivers/char/tpm/tpm_tis_core.c
15+++ b/drivers/char/tpm/tpm_tis_core.c
developer2460ee72023-02-07 18:16:20 +080016@@ -817,6 +817,21 @@ static const struct tpm_class_ops tpm_ti
developerd82d9fc2022-06-23 19:03:51 +080017 .clk_enable = tpm_tis_clkrun_enable,
18 };
19
20+int tpm_tis_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen)
21+{
22+ int rc;
23+ u32 vendor;
24+
25+ rc = tpm_tis_read32((struct tpm_tis_data *)priv, TPM_DID_VID(0), &vendor);
26+ if (rc < 0)
27+ return -EIO;
28+
29+ buf[0] = (vendor >> 24) & 0xff;
30+ buf[1] = (vendor >> 16) & 0xff;
31+
32+ return 0;
33+}
34+
35 int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
36 const struct tpm_tis_phy_ops *phy_ops,
37 acpi_handle acpi_dev_handle)
developer2460ee72023-02-07 18:16:20 +080038@@ -864,6 +879,10 @@ int tpm_tis_core_init(struct device *dev
developerd82d9fc2022-06-23 19:03:51 +080039 if (chip->ops->clk_enable != NULL)
40 chip->ops->clk_enable(chip, true);
41
42+ rc = priv->phy_ops->do_calibration(priv, dev);
43+ if (rc)
44+ goto out_err;
45+
46 if (wait_startup(chip, 0) != 0) {
47 rc = -ENODEV;
48 goto out_err;
developerd82d9fc2022-06-23 19:03:51 +080049--- a/drivers/char/tpm/tpm_tis_core.h
50+++ b/drivers/char/tpm/tpm_tis_core.h
51@@ -106,6 +106,7 @@ struct tpm_tis_phy_ops {
52 int (*read16)(struct tpm_tis_data *data, u32 addr, u16 *result);
53 int (*read32)(struct tpm_tis_data *data, u32 addr, u32 *result);
54 int (*write32)(struct tpm_tis_data *data, u32 addr, u32 src);
55+ int (*do_calibration)(struct tpm_tis_data *data, struct device *dev);
56 };
57
58 static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
59@@ -158,6 +159,7 @@ static inline bool is_bsw(void)
60 }
61
62 void tpm_tis_remove(struct tpm_chip *chip);
63+int tpm_tis_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen);
64 int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
65 const struct tpm_tis_phy_ops *phy_ops,
66 acpi_handle acpi_dev_handle);
developerd82d9fc2022-06-23 19:03:51 +080067--- a/drivers/char/tpm/tpm_tis_spi.c
68+++ b/drivers/char/tpm/tpm_tis_spi.c
developer2460ee72023-02-07 18:16:20 +080069@@ -184,12 +184,19 @@ static int tpm_tis_spi_write32(struct tp
developerd82d9fc2022-06-23 19:03:51 +080070 return rc;
71 }
72
73+int tpm_tis_spi_do_calibration(struct tpm_tis_data *priv, struct device *dev) {
74+ struct spi_device *spi = container_of(dev,
75+ struct spi_device, dev);
76+ return spi_do_calibration(spi->master, spi, tpm_tis_cal_read, priv);
77+}
78+
79 static const struct tpm_tis_phy_ops tpm_spi_phy_ops = {
80 .read_bytes = tpm_tis_spi_read_bytes,
81 .write_bytes = tpm_tis_spi_write_bytes,
82 .read16 = tpm_tis_spi_read16,
83 .read32 = tpm_tis_spi_read32,
84 .write32 = tpm_tis_spi_write32,
85+ .do_calibration = tpm_tis_spi_do_calibration,
86 };
87
88 static int tpm_tis_spi_probe(struct spi_device *dev)