18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015 Infineon Technologies AG
48c2ecf20Sopenharmony_ci * Copyright (C) 2016 STMicroelectronics SAS
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef TPM_TIS_SPI_H
88c2ecf20Sopenharmony_ci#define TPM_TIS_SPI_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "tpm_tis_core.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct tpm_tis_spi_phy {
138c2ecf20Sopenharmony_ci	struct tpm_tis_data priv;
148c2ecf20Sopenharmony_ci	struct spi_device *spi_device;
158c2ecf20Sopenharmony_ci	int (*flow_control)(struct tpm_tis_spi_phy *phy,
168c2ecf20Sopenharmony_ci			     struct spi_transfer *xfer);
178c2ecf20Sopenharmony_ci	struct completion ready;
188c2ecf20Sopenharmony_ci	unsigned long wake_after;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	u8 *iobuf;
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *data)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	return container_of(data, struct tpm_tis_spi_phy, priv);
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciextern int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
298c2ecf20Sopenharmony_ci			    int irq, const struct tpm_tis_phy_ops *phy_ops);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciextern int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
328c2ecf20Sopenharmony_ci				u8 *in, const u8 *out);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciextern int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result);
358c2ecf20Sopenharmony_ciextern int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result);
368c2ecf20Sopenharmony_ciextern int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#ifdef CONFIG_TCG_TIS_SPI_CR50
398c2ecf20Sopenharmony_ciextern int cr50_spi_probe(struct spi_device *spi);
408c2ecf20Sopenharmony_ci#else
418c2ecf20Sopenharmony_cistatic inline int cr50_spi_probe(struct spi_device *spi)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	return -ENODEV;
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci#endif
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_TCG_TIS_SPI_CR50)
488c2ecf20Sopenharmony_ciextern int tpm_tis_spi_resume(struct device *dev);
498c2ecf20Sopenharmony_ci#else
508c2ecf20Sopenharmony_ci#define tpm_tis_spi_resume	NULL
518c2ecf20Sopenharmony_ci#endif
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif
54