diff mbox

[v4,11/12] tpm: Use read/write_bytes for drivers without more specialized methods

Message ID 1461017864-3903-12-git-send-email-christophe-h.ricard@st.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christophe Ricard April 18, 2016, 10:17 p.m. UTC
Some drivers might need to implement only functions for transferring an
arbitrary number of bytes. Provides a generic functions for handling  of
word or dword transfers to be dump into driver functions pointers.

Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
---
 drivers/char/tpm/tpm_tis_core.c | 34 ++++++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm_tis_core.h |  4 ++++
 2 files changed, 38 insertions(+)
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 09f7822..5933781 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -803,6 +803,40 @@  int tpm_tis_resume(struct device *dev)
 EXPORT_SYMBOL_GPL(tpm_tis_resume);
 #endif
 
+int tpm_tis_common_read16(struct tpm_chip *chip, u32 addr, u16 *result)
+{
+	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+	int rc;
+
+	rc = priv->phy_ops->read_bytes(chip, addr, sizeof(u16), (u8 *)result);
+	if (!rc)
+		*result = le16_to_cpu(*result);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(tpm_tis_common_read16);
+
+int tpm_tis_common_read32(struct tpm_chip *chip, u32 addr, u32 *result)
+{
+	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+	int rc;
+
+	rc = priv->phy_ops->read_bytes(chip, addr, sizeof(u32), (u8 *)result);
+	if (!rc)
+		*result = le32_to_cpu(*result);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(tpm_tis_common_read32);
+
+int tpm_tis_common_write32(struct tpm_chip *chip, u32 addr, u32 value)
+{
+	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+
+	value = cpu_to_le32(value);
+	return priv->phy_ops->write_bytes(chip, addr, sizeof(u32),
+					   (u8 *)&value);
+}
+EXPORT_SYMBOL_GPL(tpm_tis_common_write32);
+
 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
 MODULE_DESCRIPTION("TPM Driver");
 MODULE_VERSION("2.0");
diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
index 157c5c3..6b82944 100644
--- a/drivers/char/tpm/tpm_tis_core.h
+++ b/drivers/char/tpm/tpm_tis_core.h
@@ -153,6 +153,10 @@  static inline int tpm_write32(struct tpm_chip *chip, u32 addr, u32 value)
 	return priv->phy_ops->write32(chip, addr, value);
 }
 
+int tpm_tis_common_read16(struct tpm_chip *chip, u32 addr, u16 *result);
+int tpm_tis_common_read32(struct tpm_chip *chip, u32 addr, u32 *result);
+int tpm_tis_common_write32(struct tpm_chip *chip, u32 addr, u32 value);
+
 void tpm_tis_ready(struct tpm_chip *chip);
 void release_locality(struct tpm_chip *chip, int l, int force);
 int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len);