developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1 | From daaf90f34aa73625585f56d766e51c7b718bebc3 Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam Shih <sam.shih@mediatek.com> |
| 3 | Date: Fri, 2 Jun 2023 13:06:05 +0800 |
| 4 | Subject: [PATCH] |
| 5 | [slow-speed-io][999-2103-drivers-char-tpm-Add-calibration-example-for-SPI-TPM-module.patch] |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 6 | |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 7 | --- |
| 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 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 13 | diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c |
| 14 | index 70f785994..b9898a56d 100644 |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 15 | --- a/drivers/char/tpm/tpm_tis_core.c |
| 16 | +++ b/drivers/char/tpm/tpm_tis_core.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 17 | @@ -817,6 +817,21 @@ static const struct tpm_class_ops tpm_tis = { |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 18 | .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) |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 39 | @@ -864,6 +879,10 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 40 | 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; |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 50 | diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h |
| 51 | index 7337819f5..7bb0bc8b6 100644 |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 52 | --- 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); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 70 | diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c |
| 71 | index 19513e622..3be2d53a5 100644 |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 72 | --- a/drivers/char/tpm/tpm_tis_spi.c |
| 73 | +++ b/drivers/char/tpm/tpm_tis_spi.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 74 | @@ -184,12 +184,19 @@ static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value) |
developer | d82d9fc | 2022-06-23 19:03:51 +0800 | [diff] [blame] | 75 | 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) |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 94 | -- |
| 95 | 2.34.1 |
| 96 | |