diff mbox

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

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

Commit Message

Christophe Ricard April 16, 2016, 6:35 a.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.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Jason Gunthorpe April 18, 2016, 5:01 p.m. UTC | #1
On Sat, Apr 16, 2016 at 08:35:36AM +0200, Christophe Ricard wrote:

> +static inline int tpm_tis_common_read16(struct tpm_chip *chip, u32 addr,
> +					u16 *result)
> +{

These should not be inlines, but them in the common tis .c file

Jason

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
index 9dd6b41..4074c98 100644
--- a/drivers/char/tpm/tpm_tis_core.h
+++ b/drivers/char/tpm/tpm_tis_core.h
@@ -60,6 +60,18 @@  static inline int tpm_read8(struct tpm_chip *chip, u32 addr, u8 *result)
 	return priv->phy_ops->read_bytes(chip, addr, 1, result);
 }
 
+static inline 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;
+}
+
 static inline int tpm_read16(struct tpm_chip *chip, u32 addr, u16 *result)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
@@ -67,6 +79,18 @@  static inline int tpm_read16(struct tpm_chip *chip, u32 addr, u16 *result)
 	return priv->phy_ops->read16(chip, addr, result);
 }
 
+static inline 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;
+}
+
 static inline int tpm_read32(struct tpm_chip *chip, u32 addr, u32 *result)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
@@ -89,6 +113,16 @@  static inline int tpm_write8(struct tpm_chip *chip, u32 addr, u8 value)
 	return priv->phy_ops->write_bytes(chip, addr, 1, &value);
 }
 
+static inline 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);
+}
+
 static inline int tpm_write32(struct tpm_chip *chip, u32 addr, u32 value)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);