Merge tag 'samsung-defconfig-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / char / tpm / tpm-chip.c
index d47ad10a35fe3362156fbdb15038eb4fda661a97..4838c6a9f0f2c702e932066fba62d7a336a87f36 100644 (file)
@@ -77,6 +77,18 @@ static int tpm_go_idle(struct tpm_chip *chip)
        return chip->ops->go_idle(chip);
 }
 
+static void tpm_clk_enable(struct tpm_chip *chip)
+{
+       if (chip->ops->clk_enable)
+               chip->ops->clk_enable(chip, true);
+}
+
+static void tpm_clk_disable(struct tpm_chip *chip)
+{
+       if (chip->ops->clk_enable)
+               chip->ops->clk_enable(chip, false);
+}
+
 /**
  * tpm_chip_start() - power on the TPM
  * @chip:      a TPM chip to use
@@ -89,13 +101,12 @@ int tpm_chip_start(struct tpm_chip *chip)
 {
        int ret;
 
-       if (chip->ops->clk_enable)
-               chip->ops->clk_enable(chip, true);
+       tpm_clk_enable(chip);
 
        if (chip->locality == -1) {
                ret = tpm_request_locality(chip);
                if (ret) {
-                       chip->ops->clk_enable(chip, false);
+                       tpm_clk_disable(chip);
                        return ret;
                }
        }
@@ -103,8 +114,7 @@ int tpm_chip_start(struct tpm_chip *chip)
        ret = tpm_cmd_ready(chip);
        if (ret) {
                tpm_relinquish_locality(chip);
-               if (chip->ops->clk_enable)
-                       chip->ops->clk_enable(chip, false);
+               tpm_clk_disable(chip);
                return ret;
        }
 
@@ -124,8 +134,7 @@ void tpm_chip_stop(struct tpm_chip *chip)
 {
        tpm_go_idle(chip);
        tpm_relinquish_locality(chip);
-       if (chip->ops->clk_enable)
-               chip->ops->clk_enable(chip, false);
+       tpm_clk_disable(chip);
 }
 EXPORT_SYMBOL_GPL(tpm_chip_stop);
 
@@ -545,6 +554,20 @@ static int tpm_add_hwrng(struct tpm_chip *chip)
        return hwrng_register(&chip->hwrng);
 }
 
+static int tpm_get_pcr_allocation(struct tpm_chip *chip)
+{
+       int rc;
+
+       rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ?
+            tpm2_get_pcr_allocation(chip) :
+            tpm1_get_pcr_allocation(chip);
+
+       if (rc > 0)
+               return -ENODEV;
+
+       return rc;
+}
+
 /*
  * tpm_chip_register() - create a character device for the TPM chip
  * @chip: TPM chip to use.
@@ -564,6 +587,12 @@ int tpm_chip_register(struct tpm_chip *chip)
        if (rc)
                return rc;
        rc = tpm_auto_startup(chip);
+       if (rc) {
+               tpm_chip_stop(chip);
+               return rc;
+       }
+
+       rc = tpm_get_pcr_allocation(chip);
        tpm_chip_stop(chip);
        if (rc)
                return rc;