Blob Blame History Raw
From b078b94e5262e01a22491c7ba417569c0522de49 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Tue, 28 Aug 2018 16:53:11 +0200
Subject: [PATCH 7/7] KABI: tpm: do keep the cmd_ready and go_idle as pm ops.

References: bsc#1082555
Patch-mainline: no, kabi

This basically reverts the interface change of commit
627448e85c766587f6fdde1ea3886d6615081c77

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 drivers/char/tpm/tpm-interface.c | 11 +++++++----
 drivers/char/tpm/tpm_crb.c       | 35 +++++++++++++++++------------------
 include/linux/tpm.h              |  2 --
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index f5436151070f..58bb5f8a0e4f 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -29,6 +29,7 @@
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
 #include <linux/freezer.h>
+#include <linux/pm_runtime.h>
 
 #include "tpm.h"
 #include "tpm_eventlog.h"
@@ -405,10 +406,11 @@ static int tpm_cmd_ready(struct tpm_chip *chip, unsigned int flags)
 	if (flags & TPM_TRANSMIT_RAW)
 		return 0;
 
-	if (!chip->ops->cmd_ready)
+	if (!chip->dev.driver || !chip->dev.driver->pm || !chip->dev.driver->pm
+			|| ! chip->dev.driver->pm->runtime_resume)
 		return 0;
 
-	return chip->ops->cmd_ready(chip);
+	return chip->dev.driver->pm->runtime_resume(&chip->dev);
 }
 
 static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
@@ -416,10 +418,11 @@ static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
 	if (flags & TPM_TRANSMIT_RAW)
 		return 0;
 
-	if (!chip->ops->go_idle)
+	if (!chip->dev.driver || !chip->dev.driver->pm || !chip->dev.driver->pm
+			|| ! chip->dev.driver->pm->runtime_suspend)
 		return 0;
 
-	return chip->ops->go_idle(chip);
+	return chip->dev.driver->pm->runtime_suspend(&chip->dev);
 }
 
 static ssize_t tpm_try_transmit(struct tpm_chip *chip,
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 2057a7490c74..27044529690e 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -167,14 +167,6 @@ static int __crb_go_idle(struct device *dev, struct crb_priv *priv)
 	return 0;
 }
 
-static int crb_go_idle(struct tpm_chip *chip)
-{
-	struct device *dev = &chip->dev;
-	struct crb_priv *priv = dev_get_drvdata(dev);
-
-	return __crb_go_idle(dev, priv);
-}
-
 /**
  * __crb_cmd_ready - request tpm crb device to enter ready state
  *
@@ -209,14 +201,6 @@ static int __crb_cmd_ready(struct device *dev, struct crb_priv *priv)
 	return 0;
 }
 
-static int crb_cmd_ready(struct tpm_chip *chip)
-{
-	struct device *dev = &chip->dev;
-	struct crb_priv *priv = dev_get_drvdata(dev);
-
-	return __crb_cmd_ready(dev, priv);
-}
-
 static int __crb_request_locality(struct device *dev,
 				  struct crb_priv *priv, int loc)
 {
@@ -416,8 +400,6 @@ static const struct tpm_class_ops tpm_crb = {
 	.send = crb_send,
 	.cancel = crb_cancel,
 	.req_canceled = crb_req_canceled,
-	.go_idle  = crb_go_idle,
-	.cmd_ready = crb_cmd_ready,
 	.request_locality = crb_request_locality,
 	.relinquish_locality = crb_relinquish_locality,
 	.req_complete_mask = CRB_DRV_STS_COMPLETE,
@@ -657,8 +639,25 @@ static int crb_acpi_remove(struct acpi_device *device)
 	return 0;
 }
 
+static int __maybe_unused crb_pm_runtime_suspend(struct device *dev)
+{
+	struct tpm_chip *chip = dev_get_drvdata(dev);
+	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+	return __crb_go_idle(dev, priv);
+}
+
+static int __maybe_unused crb_pm_runtime_resume(struct device *dev)
+{
+	struct tpm_chip *chip = dev_get_drvdata(dev);
+	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+	return __crb_cmd_ready(dev, priv);
+}
+
 static const struct dev_pm_ops crb_pm = {
 	SET_SYSTEM_SLEEP_PM_OPS(tpm_pm_suspend, tpm_pm_resume)
+	SET_RUNTIME_PM_OPS(crb_pm_runtime_suspend, crb_pm_runtime_resume, NULL)
 };
 
 static struct acpi_device_id crb_device_ids[] = {
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
index 0add5b2d560a..5a090f5ab335 100644
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -48,8 +48,6 @@ struct tpm_class_ops {
 	u8 (*status) (struct tpm_chip *chip);
 	bool (*update_timeouts)(struct tpm_chip *chip,
 				unsigned long *timeout_cap);
-	int (*go_idle)(struct tpm_chip *chip);
-	int (*cmd_ready)(struct tpm_chip *chip);
 	int (*request_locality)(struct tpm_chip *chip, int loc);
 	void (*relinquish_locality)(struct tpm_chip *chip, int loc);
 };
-- 
2.13.7