@@ -138,7 +138,8 @@ static void i2c_nuvoton_ready(struct tpm_chip *chip)
}
/* read burstCount field from TPM_STS register
- * return -1 on fail to read */
+ * return -1 on fail to read
+*/
static int i2c_nuvoton_get_burstcount(struct i2c_client *client,
struct tpm_chip *chip)
{
@@ -170,6 +171,7 @@ static int i2c_nuvoton_get_burstcount(struct i2c_client *client,
static bool i2c_nuvoton_check_status(struct tpm_chip *chip, u8 mask, u8 value)
{
u8 status = i2c_nuvoton_read_status(chip);
+
return (status != TPM_STS_ERR_VAL) && ((status & mask) == value);
}
@@ -188,7 +190,8 @@ static int i2c_nuvoton_wait_for_stat(struct tpm_chip *chip, u8 mask, u8 value,
if (rc > 0)
return 0;
/* At this point we know that the SINT pin is asserted, so we
- * do not need to do i2c_nuvoton_check_status */
+ * do not need to do i2c_nuvoton_check_status
+*/
} else {
unsigned long ten_msec, stop;
bool status_valid;
@@ -469,7 +472,8 @@ static const struct tpm_class_ops tpm_i2c = {
* the interrupt is currently being asserted. The driver does not do any
* processing triggered by interrupts, and the chip provides no way to mask at
* the source (plus that would be slow over I2C). Run the IRQ as a one-shot,
- * this means it cannot be shared. */
+ * this means it cannot be shared.
+*/
static irqreturn_t i2c_nuvoton_int_handler(int dummy, void *dev_id)
{
struct tpm_chip *chip = dev_id;
@@ -552,7 +556,8 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
* I2C intfcaps (interrupt capabilitieis) in the chip are hard coded to:
* TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
* The IRQ should be set in the i2c_board_info (which is done
- * automatically in of_i2c_register_devices, for device tree users */
+ * automatically in of_i2c_register_devices, for device tree users
+*/
chip->vendor.irq = client->irq;
if (chip->vendor.irq) {
@@ -601,10 +606,38 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
}
}
-if (tpm_get_timeouts(chip))
-return -ENODEV;
+rc = tpm2_probe(chip);
+if (rc)
+return rc;
-if (tpm_do_selftest(chip))
+if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
+chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
+chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
+chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
+chip->vendor.duration[TPM_SHORT] =
+msecs_to_jiffies(TPM2_DURATION_SHORT);
+chip->vendor.duration[TPM_MEDIUM] =
+msecs_to_jiffies(TPM2_DURATION_MEDIUM);
+chip->vendor.duration[TPM_LONG] =
+msecs_to_jiffies(TPM2_DURATION_LONG);
+
+rc = tpm2_do_selftest(chip);
+if (rc == TPM2_RC_INITIALIZE) {
+if (tpm2_startup(chip, TPM2_SU_CLEAR))
+return -ENODEV;
+
+rc = tpm2_do_selftest(chip);
+}
+
+} else {
+if (tpm_get_timeouts(chip))
+return -ENODEV;
+
+rc = tpm_do_selftest(chip);
+}
+
+if (rc)
return -ENODEV;
return tpm_chip_register(chip);
@@ -614,6 +647,7 @@ static int i2c_nuvoton_remove(struct i2c_client *client)
{
struct device *dev = &(client->dev);
struct tpm_chip *chip = dev_get_drvdata(dev);
+
tpm_chip_unregister(chip);
return 0;
}