tpm: Implement tpm_auto_start() for TPMv1.2

Add an implementation of this, moving the common call to tpm_init() up
into the common API implementation.

Add a test.

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 5b2c11a..3ef5e81 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -37,10 +37,23 @@
 
 u32 tpm_auto_start(struct udevice *dev)
 {
-	if (tpm_is_v2(dev))
-		return tpm2_auto_start(dev);
+	u32 rc;
 
-	return -ENOSYS;
+	/*
+	 * the tpm_init() will return -EBUSY if the init has already happened
+	 * The selftest and startup code can run multiple times with no side
+	 * effects
+	 */
+	rc = tpm_init(dev);
+	if (rc && rc != -EBUSY)
+		return rc;
+
+	if (tpm_is_v1(dev))
+		return tpm1_auto_start(dev);
+	else if (tpm_is_v2(dev))
+		return tpm2_auto_start(dev);
+	else
+		return -ENOSYS;
 }
 
 u32 tpm_resume(struct udevice *dev)