18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2016 Google, Inc
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This device driver implements a TCG PTP FIFO interface over SPI for chips
68c2ecf20Sopenharmony_ci * with Cr50 firmware.
78c2ecf20Sopenharmony_ci * It is based on tpm_tis_spi driver by Peter Huewe and Christophe Ricard.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/completion.h>
118c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
128c2ecf20Sopenharmony_ci#include <linux/module.h>
138c2ecf20Sopenharmony_ci#include <linux/of.h>
148c2ecf20Sopenharmony_ci#include <linux/pm.h>
158c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
168c2ecf20Sopenharmony_ci#include <linux/wait.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include "tpm_tis_core.h"
198c2ecf20Sopenharmony_ci#include "tpm_tis_spi.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * Cr50 timing constants:
238c2ecf20Sopenharmony_ci * - can go to sleep not earlier than after CR50_SLEEP_DELAY_MSEC.
248c2ecf20Sopenharmony_ci * - needs up to CR50_WAKE_START_DELAY_USEC to wake after sleep.
258c2ecf20Sopenharmony_ci * - requires waiting for "ready" IRQ, if supported; or waiting for at least
268c2ecf20Sopenharmony_ci *   CR50_NOIRQ_ACCESS_DELAY_MSEC between transactions, if IRQ is not supported.
278c2ecf20Sopenharmony_ci * - waits for up to CR50_FLOW_CONTROL for flow control 'ready' indication.
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci#define CR50_SLEEP_DELAY_MSEC			1000
308c2ecf20Sopenharmony_ci#define CR50_WAKE_START_DELAY_USEC		1000
318c2ecf20Sopenharmony_ci#define CR50_NOIRQ_ACCESS_DELAY			msecs_to_jiffies(2)
328c2ecf20Sopenharmony_ci#define CR50_READY_IRQ_TIMEOUT			msecs_to_jiffies(TPM2_TIMEOUT_A)
338c2ecf20Sopenharmony_ci#define CR50_FLOW_CONTROL			msecs_to_jiffies(TPM2_TIMEOUT_A)
348c2ecf20Sopenharmony_ci#define MAX_IRQ_CONFIRMATION_ATTEMPTS		3
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define TPM_CR50_FW_VER(l)			(0x0f90 | ((l) << 12))
378c2ecf20Sopenharmony_ci#define TPM_CR50_MAX_FW_VER_LEN			64
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistruct cr50_spi_phy {
408c2ecf20Sopenharmony_ci	struct tpm_tis_spi_phy spi_phy;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	struct mutex time_track_mutex;
438c2ecf20Sopenharmony_ci	unsigned long last_access;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	unsigned long access_delay;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	unsigned int irq_confirmation_attempt;
488c2ecf20Sopenharmony_ci	bool irq_needs_confirmation;
498c2ecf20Sopenharmony_ci	bool irq_confirmed;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic inline struct cr50_spi_phy *to_cr50_spi_phy(struct tpm_tis_spi_phy *phy)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	return container_of(phy, struct cr50_spi_phy, spi_phy);
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/*
588c2ecf20Sopenharmony_ci * The cr50 interrupt handler just signals waiting threads that the
598c2ecf20Sopenharmony_ci * interrupt was asserted.  It does not do any processing triggered
608c2ecf20Sopenharmony_ci * by interrupts but is instead used to avoid fixed delays.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistatic irqreturn_t cr50_spi_irq_handler(int dummy, void *dev_id)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	struct cr50_spi_phy *cr50_phy = dev_id;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	cr50_phy->irq_confirmed = true;
678c2ecf20Sopenharmony_ci	complete(&cr50_phy->spi_phy.ready);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/*
738c2ecf20Sopenharmony_ci * Cr50 needs to have at least some delay between consecutive
748c2ecf20Sopenharmony_ci * transactions. Make sure we wait.
758c2ecf20Sopenharmony_ci */
768c2ecf20Sopenharmony_cistatic void cr50_ensure_access_delay(struct cr50_spi_phy *phy)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	unsigned long allowed_access = phy->last_access + phy->access_delay;
798c2ecf20Sopenharmony_ci	unsigned long time_now = jiffies;
808c2ecf20Sopenharmony_ci	struct device *dev = &phy->spi_phy.spi_device->dev;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/*
838c2ecf20Sopenharmony_ci	 * Note: There is a small chance, if Cr50 is not accessed in a few days,
848c2ecf20Sopenharmony_ci	 * that time_in_range will not provide the correct result after the wrap
858c2ecf20Sopenharmony_ci	 * around for jiffies. In this case, we'll have an unneeded short delay,
868c2ecf20Sopenharmony_ci	 * which is fine.
878c2ecf20Sopenharmony_ci	 */
888c2ecf20Sopenharmony_ci	if (time_in_range_open(time_now, phy->last_access, allowed_access)) {
898c2ecf20Sopenharmony_ci		unsigned long remaining, timeout = allowed_access - time_now;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci		remaining = wait_for_completion_timeout(&phy->spi_phy.ready,
928c2ecf20Sopenharmony_ci							timeout);
938c2ecf20Sopenharmony_ci		if (!remaining && phy->irq_confirmed)
948c2ecf20Sopenharmony_ci			dev_warn(dev, "Timeout waiting for TPM ready IRQ\n");
958c2ecf20Sopenharmony_ci	}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	if (phy->irq_needs_confirmation) {
988c2ecf20Sopenharmony_ci		unsigned int attempt = ++phy->irq_confirmation_attempt;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci		if (phy->irq_confirmed) {
1018c2ecf20Sopenharmony_ci			phy->irq_needs_confirmation = false;
1028c2ecf20Sopenharmony_ci			phy->access_delay = CR50_READY_IRQ_TIMEOUT;
1038c2ecf20Sopenharmony_ci			dev_info(dev, "TPM ready IRQ confirmed on attempt %u\n",
1048c2ecf20Sopenharmony_ci				 attempt);
1058c2ecf20Sopenharmony_ci		} else if (attempt > MAX_IRQ_CONFIRMATION_ATTEMPTS) {
1068c2ecf20Sopenharmony_ci			phy->irq_needs_confirmation = false;
1078c2ecf20Sopenharmony_ci			dev_warn(dev, "IRQ not confirmed - will use delays\n");
1088c2ecf20Sopenharmony_ci		}
1098c2ecf20Sopenharmony_ci	}
1108c2ecf20Sopenharmony_ci}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci * Cr50 might go to sleep if there is no SPI activity for some time and
1148c2ecf20Sopenharmony_ci * miss the first few bits/bytes on the bus. In such case, wake it up
1158c2ecf20Sopenharmony_ci * by asserting CS and give it time to start up.
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistatic bool cr50_needs_waking(struct cr50_spi_phy *phy)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	/*
1208c2ecf20Sopenharmony_ci	 * Note: There is a small chance, if Cr50 is not accessed in a few days,
1218c2ecf20Sopenharmony_ci	 * that time_in_range will not provide the correct result after the wrap
1228c2ecf20Sopenharmony_ci	 * around for jiffies. In this case, we'll probably timeout or read
1238c2ecf20Sopenharmony_ci	 * incorrect value from TPM_STS and just retry the operation.
1248c2ecf20Sopenharmony_ci	 */
1258c2ecf20Sopenharmony_ci	return !time_in_range_open(jiffies, phy->last_access,
1268c2ecf20Sopenharmony_ci				   phy->spi_phy.wake_after);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic void cr50_wake_if_needed(struct cr50_spi_phy *cr50_phy)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	struct tpm_tis_spi_phy *phy = &cr50_phy->spi_phy;
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	if (cr50_needs_waking(cr50_phy)) {
1348c2ecf20Sopenharmony_ci		/* Assert CS, wait 1 msec, deassert CS */
1358c2ecf20Sopenharmony_ci		struct spi_transfer spi_cs_wake = {
1368c2ecf20Sopenharmony_ci			.delay = {
1378c2ecf20Sopenharmony_ci				.value = 1000,
1388c2ecf20Sopenharmony_ci				.unit = SPI_DELAY_UNIT_USECS
1398c2ecf20Sopenharmony_ci			}
1408c2ecf20Sopenharmony_ci		};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci		spi_sync_transfer(phy->spi_device, &spi_cs_wake, 1);
1438c2ecf20Sopenharmony_ci		/* Wait for it to fully wake */
1448c2ecf20Sopenharmony_ci		usleep_range(CR50_WAKE_START_DELAY_USEC,
1458c2ecf20Sopenharmony_ci			     CR50_WAKE_START_DELAY_USEC * 2);
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	/* Reset the time when we need to wake Cr50 again */
1498c2ecf20Sopenharmony_ci	phy->wake_after = jiffies + msecs_to_jiffies(CR50_SLEEP_DELAY_MSEC);
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * Flow control: clock the bus and wait for cr50 to set LSB before
1548c2ecf20Sopenharmony_ci * sending/receiving data. TCG PTP spec allows it to happen during
1558c2ecf20Sopenharmony_ci * the last byte of header, but cr50 never does that in practice,
1568c2ecf20Sopenharmony_ci * and earlier versions had a bug when it was set too early, so don't
1578c2ecf20Sopenharmony_ci * check for it during header transfer.
1588c2ecf20Sopenharmony_ci */
1598c2ecf20Sopenharmony_cistatic int cr50_spi_flow_control(struct tpm_tis_spi_phy *phy,
1608c2ecf20Sopenharmony_ci				 struct spi_transfer *spi_xfer)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	struct device *dev = &phy->spi_device->dev;
1638c2ecf20Sopenharmony_ci	unsigned long timeout = jiffies + CR50_FLOW_CONTROL;
1648c2ecf20Sopenharmony_ci	struct spi_message m;
1658c2ecf20Sopenharmony_ci	int ret;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	spi_xfer->len = 1;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	do {
1708c2ecf20Sopenharmony_ci		spi_message_init(&m);
1718c2ecf20Sopenharmony_ci		spi_message_add_tail(spi_xfer, &m);
1728c2ecf20Sopenharmony_ci		ret = spi_sync_locked(phy->spi_device, &m);
1738c2ecf20Sopenharmony_ci		if (ret < 0)
1748c2ecf20Sopenharmony_ci			return ret;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci		if (time_after(jiffies, timeout)) {
1778c2ecf20Sopenharmony_ci			dev_warn(dev, "Timeout during flow control\n");
1788c2ecf20Sopenharmony_ci			return -EBUSY;
1798c2ecf20Sopenharmony_ci		}
1808c2ecf20Sopenharmony_ci	} while (!(phy->iobuf[0] & 0x01));
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	return 0;
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic int tpm_tis_spi_cr50_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
1868c2ecf20Sopenharmony_ci				     u8 *in, const u8 *out)
1878c2ecf20Sopenharmony_ci{
1888c2ecf20Sopenharmony_ci	struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data);
1898c2ecf20Sopenharmony_ci	struct cr50_spi_phy *cr50_phy = to_cr50_spi_phy(phy);
1908c2ecf20Sopenharmony_ci	int ret;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	mutex_lock(&cr50_phy->time_track_mutex);
1938c2ecf20Sopenharmony_ci	/*
1948c2ecf20Sopenharmony_ci	 * Do this outside of spi_bus_lock in case cr50 is not the
1958c2ecf20Sopenharmony_ci	 * only device on that spi bus.
1968c2ecf20Sopenharmony_ci	 */
1978c2ecf20Sopenharmony_ci	cr50_ensure_access_delay(cr50_phy);
1988c2ecf20Sopenharmony_ci	cr50_wake_if_needed(cr50_phy);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	ret = tpm_tis_spi_transfer(data, addr, len, in, out);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	cr50_phy->last_access = jiffies;
2038c2ecf20Sopenharmony_ci	mutex_unlock(&cr50_phy->time_track_mutex);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	return ret;
2068c2ecf20Sopenharmony_ci}
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic int tpm_tis_spi_cr50_read_bytes(struct tpm_tis_data *data, u32 addr,
2098c2ecf20Sopenharmony_ci				       u16 len, u8 *result)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	return tpm_tis_spi_cr50_transfer(data, addr, len, result, NULL);
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic int tpm_tis_spi_cr50_write_bytes(struct tpm_tis_data *data, u32 addr,
2158c2ecf20Sopenharmony_ci					u16 len, const u8 *value)
2168c2ecf20Sopenharmony_ci{
2178c2ecf20Sopenharmony_ci	return tpm_tis_spi_cr50_transfer(data, addr, len, NULL, value);
2188c2ecf20Sopenharmony_ci}
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic const struct tpm_tis_phy_ops tpm_spi_cr50_phy_ops = {
2218c2ecf20Sopenharmony_ci	.read_bytes = tpm_tis_spi_cr50_read_bytes,
2228c2ecf20Sopenharmony_ci	.write_bytes = tpm_tis_spi_cr50_write_bytes,
2238c2ecf20Sopenharmony_ci	.read16 = tpm_tis_spi_read16,
2248c2ecf20Sopenharmony_ci	.read32 = tpm_tis_spi_read32,
2258c2ecf20Sopenharmony_ci	.write32 = tpm_tis_spi_write32,
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic void cr50_print_fw_version(struct tpm_tis_data *data)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data);
2318c2ecf20Sopenharmony_ci	int i, len = 0;
2328c2ecf20Sopenharmony_ci	char fw_ver[TPM_CR50_MAX_FW_VER_LEN + 1];
2338c2ecf20Sopenharmony_ci	char fw_ver_block[4];
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	/*
2368c2ecf20Sopenharmony_ci	 * Write anything to TPM_CR50_FW_VER to start from the beginning
2378c2ecf20Sopenharmony_ci	 * of the version string
2388c2ecf20Sopenharmony_ci	 */
2398c2ecf20Sopenharmony_ci	tpm_tis_write8(data, TPM_CR50_FW_VER(data->locality), 0);
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	/* Read the string, 4 bytes at a time, until we get '\0' */
2428c2ecf20Sopenharmony_ci	do {
2438c2ecf20Sopenharmony_ci		tpm_tis_read_bytes(data, TPM_CR50_FW_VER(data->locality), 4,
2448c2ecf20Sopenharmony_ci				   fw_ver_block);
2458c2ecf20Sopenharmony_ci		for (i = 0; i < 4 && fw_ver_block[i]; ++len, ++i)
2468c2ecf20Sopenharmony_ci			fw_ver[len] = fw_ver_block[i];
2478c2ecf20Sopenharmony_ci	} while (i == 4 && len < TPM_CR50_MAX_FW_VER_LEN);
2488c2ecf20Sopenharmony_ci	fw_ver[len] = '\0';
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	dev_info(&phy->spi_device->dev, "Cr50 firmware version: %s\n", fw_ver);
2518c2ecf20Sopenharmony_ci}
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ciint cr50_spi_probe(struct spi_device *spi)
2548c2ecf20Sopenharmony_ci{
2558c2ecf20Sopenharmony_ci	struct tpm_tis_spi_phy *phy;
2568c2ecf20Sopenharmony_ci	struct cr50_spi_phy *cr50_phy;
2578c2ecf20Sopenharmony_ci	int ret;
2588c2ecf20Sopenharmony_ci	struct tpm_chip *chip;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	cr50_phy = devm_kzalloc(&spi->dev, sizeof(*cr50_phy), GFP_KERNEL);
2618c2ecf20Sopenharmony_ci	if (!cr50_phy)
2628c2ecf20Sopenharmony_ci		return -ENOMEM;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	phy = &cr50_phy->spi_phy;
2658c2ecf20Sopenharmony_ci	phy->flow_control = cr50_spi_flow_control;
2668c2ecf20Sopenharmony_ci	phy->wake_after = jiffies;
2678c2ecf20Sopenharmony_ci	init_completion(&phy->ready);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	cr50_phy->access_delay = CR50_NOIRQ_ACCESS_DELAY;
2708c2ecf20Sopenharmony_ci	cr50_phy->last_access = jiffies;
2718c2ecf20Sopenharmony_ci	mutex_init(&cr50_phy->time_track_mutex);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	if (spi->irq > 0) {
2748c2ecf20Sopenharmony_ci		ret = devm_request_irq(&spi->dev, spi->irq,
2758c2ecf20Sopenharmony_ci				       cr50_spi_irq_handler,
2768c2ecf20Sopenharmony_ci				       IRQF_TRIGGER_RISING | IRQF_ONESHOT,
2778c2ecf20Sopenharmony_ci				       "cr50_spi", cr50_phy);
2788c2ecf20Sopenharmony_ci		if (ret < 0) {
2798c2ecf20Sopenharmony_ci			if (ret == -EPROBE_DEFER)
2808c2ecf20Sopenharmony_ci				return ret;
2818c2ecf20Sopenharmony_ci			dev_warn(&spi->dev, "Requesting IRQ %d failed: %d\n",
2828c2ecf20Sopenharmony_ci				 spi->irq, ret);
2838c2ecf20Sopenharmony_ci			/*
2848c2ecf20Sopenharmony_ci			 * This is not fatal, the driver will fall back to
2858c2ecf20Sopenharmony_ci			 * delays automatically, since ready will never
2868c2ecf20Sopenharmony_ci			 * be completed without a registered irq handler.
2878c2ecf20Sopenharmony_ci			 * So, just fall through.
2888c2ecf20Sopenharmony_ci			 */
2898c2ecf20Sopenharmony_ci		} else {
2908c2ecf20Sopenharmony_ci			/*
2918c2ecf20Sopenharmony_ci			 * IRQ requested, let's verify that it is actually
2928c2ecf20Sopenharmony_ci			 * triggered, before relying on it.
2938c2ecf20Sopenharmony_ci			 */
2948c2ecf20Sopenharmony_ci			cr50_phy->irq_needs_confirmation = true;
2958c2ecf20Sopenharmony_ci		}
2968c2ecf20Sopenharmony_ci	} else {
2978c2ecf20Sopenharmony_ci		dev_warn(&spi->dev,
2988c2ecf20Sopenharmony_ci			 "No IRQ - will use delays between transactions.\n");
2998c2ecf20Sopenharmony_ci	}
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	ret = tpm_tis_spi_init(spi, phy, -1, &tpm_spi_cr50_phy_ops);
3028c2ecf20Sopenharmony_ci	if (ret)
3038c2ecf20Sopenharmony_ci		return ret;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	cr50_print_fw_version(&phy->priv);
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	chip = dev_get_drvdata(&spi->dev);
3088c2ecf20Sopenharmony_ci	chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	return 0;
3118c2ecf20Sopenharmony_ci}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
3148c2ecf20Sopenharmony_ciint tpm_tis_spi_resume(struct device *dev)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	struct tpm_chip *chip = dev_get_drvdata(dev);
3178c2ecf20Sopenharmony_ci	struct tpm_tis_data *data = dev_get_drvdata(&chip->dev);
3188c2ecf20Sopenharmony_ci	struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data);
3198c2ecf20Sopenharmony_ci	/*
3208c2ecf20Sopenharmony_ci	 * Jiffies not increased during suspend, so we need to reset
3218c2ecf20Sopenharmony_ci	 * the time to wake Cr50 after resume.
3228c2ecf20Sopenharmony_ci	 */
3238c2ecf20Sopenharmony_ci	phy->wake_after = jiffies;
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	return tpm_tis_resume(dev);
3268c2ecf20Sopenharmony_ci}
3278c2ecf20Sopenharmony_ci#endif
328