@@ -475,17 +475,35 @@ static inline int tpm_read_bytes(struct tpm_chip *chip, u32 addr, u16 len,
static inline int tpm_read8(struct tpm_chip *chip, u32 addr, u8 *result)
{
- return chip->lowlevel->read_bytes(chip, addr, 1, result);
+ return chip->lowlevel->read_bytes(chip, addr, sizeof(u8), result);
}
static inline int tpm_read16(struct tpm_chip *chip, u32 addr, u16 *result)
{
- return chip->lowlevel->read16(chip, addr, result);
+ int rc;
+
+ if (chip->lowlevel->read16)
+ return chip->lowlevel->read16(chip, addr, result);
+
+ rc = chip->lowlevel->read_bytes(chip, addr, sizeof(u16), (u8 *)result);
+ if (!rc)
+ *result = le16_to_cpu(*result);
+
+ return rc;
}
static inline int tpm_read32(struct tpm_chip *chip, u32 addr, u32 *result)
{
- return chip->lowlevel->read32(chip, addr, result);
+ int rc;
+
+ if (chip->lowlevel->read32)
+ return chip->lowlevel->read32(chip, addr, result);
+
+ rc = chip->lowlevel->read_bytes(chip, addr, sizeof(u32), (u8 *)result);
+ if (!rc)
+ *result = le32_to_cpu(*result);
+
+ return rc;
}
static inline int tpm_write_bytes(struct tpm_chip *chip, u32 addr, u16 len,
@@ -496,12 +514,17 @@ static inline int tpm_write_bytes(struct tpm_chip *chip, u32 addr, u16 len,
static inline int tpm_write8(struct tpm_chip *chip, u32 addr, u8 value)
{
- return chip->lowlevel->write_bytes(chip, addr, 1, &value);
+ return chip->lowlevel->write_bytes(chip, addr, sizeof(u8), &value);
}
static inline int tpm_write32(struct tpm_chip *chip, u32 addr, u32 value)
{
- return chip->lowlevel->write32(chip, addr, value);
+ if (chip->lowlevel->write32)
+ return chip->lowlevel->write32(chip, addr, value);
+
+ value = cpu_to_le32(value);
+ return chip->lowlevel->write_bytes(chip, addr, sizeof(u32),
+ (u8 *)&value);
}
extern struct class *tpm_class;