blob: 47ac32a826e81939a27862e6bc7be084161ce62a [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From daaf90f34aa73625585f56d766e51c7b718bebc3 Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:05 +0800
4Subject: [PATCH]
5 [slow-speed-io][999-2103-drivers-char-tpm-Add-calibration-example-for-SPI-TPM-module.patch]
developerd82d9fc2022-06-23 19:03:51 +08006
developerd82d9fc2022-06-23 19:03:51 +08007---
8 drivers/char/tpm/tpm_tis_core.c | 19 +++++++++++++++++++
9 drivers/char/tpm/tpm_tis_core.h | 2 ++
10 drivers/char/tpm/tpm_tis_spi.c | 7 +++++++
11 3 files changed, 28 insertions(+)
12
developer5d148cb2023-06-02 13:08:11 +080013diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
14index 70f785994..b9898a56d 100644
developerd82d9fc2022-06-23 19:03:51 +080015--- a/drivers/char/tpm/tpm_tis_core.c
16+++ b/drivers/char/tpm/tpm_tis_core.c
developer5d148cb2023-06-02 13:08:11 +080017@@ -817,6 +817,21 @@ static const struct tpm_class_ops tpm_tis = {
developerd82d9fc2022-06-23 19:03:51 +080018 .clk_enable = tpm_tis_clkrun_enable,
19 };
20
21+int tpm_tis_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen)
22+{
23+ int rc;
24+ u32 vendor;
25+
26+ rc = tpm_tis_read32((struct tpm_tis_data *)priv, TPM_DID_VID(0), &vendor);
27+ if (rc < 0)
28+ return -EIO;
29+
30+ buf[0] = (vendor >> 24) & 0xff;
31+ buf[1] = (vendor >> 16) & 0xff;
32+
33+ return 0;
34+}
35+
36 int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
37 const struct tpm_tis_phy_ops *phy_ops,
38 acpi_handle acpi_dev_handle)
developer5d148cb2023-06-02 13:08:11 +080039@@ -864,6 +879,10 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
developerd82d9fc2022-06-23 19:03:51 +080040 if (chip->ops->clk_enable != NULL)
41 chip->ops->clk_enable(chip, true);
42
43+ rc = priv->phy_ops->do_calibration(priv, dev);
44+ if (rc)
45+ goto out_err;
46+
47 if (wait_startup(chip, 0) != 0) {
48 rc = -ENODEV;
49 goto out_err;
developer5d148cb2023-06-02 13:08:11 +080050diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
51index 7337819f5..7bb0bc8b6 100644
developerd82d9fc2022-06-23 19:03:51 +080052--- a/drivers/char/tpm/tpm_tis_core.h
53+++ b/drivers/char/tpm/tpm_tis_core.h
54@@ -106,6 +106,7 @@ struct tpm_tis_phy_ops {
55 int (*read16)(struct tpm_tis_data *data, u32 addr, u16 *result);
56 int (*read32)(struct tpm_tis_data *data, u32 addr, u32 *result);
57 int (*write32)(struct tpm_tis_data *data, u32 addr, u32 src);
58+ int (*do_calibration)(struct tpm_tis_data *data, struct device *dev);
59 };
60
61 static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
62@@ -158,6 +159,7 @@ static inline bool is_bsw(void)
63 }
64
65 void tpm_tis_remove(struct tpm_chip *chip);
66+int tpm_tis_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen);
67 int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
68 const struct tpm_tis_phy_ops *phy_ops,
69 acpi_handle acpi_dev_handle);
developer5d148cb2023-06-02 13:08:11 +080070diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c
71index 19513e622..3be2d53a5 100644
developerd82d9fc2022-06-23 19:03:51 +080072--- a/drivers/char/tpm/tpm_tis_spi.c
73+++ b/drivers/char/tpm/tpm_tis_spi.c
developer5d148cb2023-06-02 13:08:11 +080074@@ -184,12 +184,19 @@ static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value)
developerd82d9fc2022-06-23 19:03:51 +080075 return rc;
76 }
77
78+int tpm_tis_spi_do_calibration(struct tpm_tis_data *priv, struct device *dev) {
79+ struct spi_device *spi = container_of(dev,
80+ struct spi_device, dev);
81+ return spi_do_calibration(spi->master, spi, tpm_tis_cal_read, priv);
82+}
83+
84 static const struct tpm_tis_phy_ops tpm_spi_phy_ops = {
85 .read_bytes = tpm_tis_spi_read_bytes,
86 .write_bytes = tpm_tis_spi_write_bytes,
87 .read16 = tpm_tis_spi_read16,
88 .read32 = tpm_tis_spi_read32,
89 .write32 = tpm_tis_spi_write32,
90+ .do_calibration = tpm_tis_spi_do_calibration,
91 };
92
93 static int tpm_tis_spi_probe(struct spi_device *dev)
developer5d148cb2023-06-02 13:08:11 +080094--
952.34.1
96