Skip to content

Commit e350e24

Browse files
Winkler, TomasJarkko Sakkinen
authored andcommitted
tmp/tpm_crb: implement runtime pm for tpm_crb
Utilize runtime_pm for driving tpm crb idle states. The framework calls cmd_ready from the pm_runtime_resume handler and go idle from the pm_runtime_suspend handler. The TPM framework should wake the device before transmit and receive. In case the runtime_pm framework is not enabled, the device will be in ready state. [jarkko.sakkinen@linux.intel.com: changed pm_runtime_put_sync() to pm_runtime_put()] Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent 0c22db4 commit e350e24

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎drivers/char/tpm/tpm-interface.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/mutex.h>
3030
#include <linux/spinlock.h>
3131
#include <linux/freezer.h>
32+
#include <linux/pm_runtime.h>
3233

3334
#include "tpm.h"
3435
#include "tpm_eventlog.h"
@@ -356,6 +357,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
356357
if (!(flags & TPM_TRANSMIT_UNLOCKED))
357358
mutex_lock(&chip->tpm_mutex);
358359

360+
pm_runtime_get_sync(chip->dev.parent);
361+
359362
rc = chip->ops->send(chip, (u8 *) buf, count);
360363
if (rc < 0) {
361364
dev_err(&chip->dev,
@@ -397,6 +400,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
397400
dev_err(&chip->dev,
398401
"tpm_transmit: tpm_recv: error %zd\n", rc);
399402
out:
403+
pm_runtime_put(chip->dev.parent);
404+
400405
if (!(flags & TPM_TRANSMIT_UNLOCKED))
401406
mutex_unlock(&chip->tpm_mutex);
402407
return rc;

‎drivers/char/tpm/tpm_crb.c‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/highmem.h>
2020
#include <linux/rculist.h>
2121
#include <linux/module.h>
22+
#include <linux/pm_runtime.h>
2223
#include "tpm.h"
2324

2425
#define ACPI_SIG_TPM2 "TPM2"
@@ -152,8 +153,6 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
152153
return 0;
153154
}
154155

155-
static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume);
156-
157156
static u8 crb_status(struct tpm_chip *chip)
158157
{
159158
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
@@ -436,9 +435,16 @@ static int crb_acpi_add(struct acpi_device *device)
436435
if (rc)
437436
return rc;
438437

438+
pm_runtime_set_active(dev);
439+
pm_runtime_enable(dev);
440+
439441
rc = tpm_chip_register(chip);
440-
if (rc)
442+
if (rc) {
441443
crb_go_idle(dev, priv);
444+
pm_runtime_disable(dev);
445+
}
446+
447+
pm_runtime_put(dev);
442448

443449
return rc;
444450
}
@@ -450,9 +456,34 @@ static int crb_acpi_remove(struct acpi_device *device)
450456

451457
tpm_chip_unregister(chip);
452458

459+
pm_runtime_disable(dev);
460+
453461
return 0;
454462
}
455463

464+
#ifdef CONFIG_PM
465+
static int crb_pm_runtime_suspend(struct device *dev)
466+
{
467+
struct tpm_chip *chip = dev_get_drvdata(dev);
468+
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
469+
470+
return crb_go_idle(dev, priv);
471+
}
472+
473+
static int crb_pm_runtime_resume(struct device *dev)
474+
{
475+
struct tpm_chip *chip = dev_get_drvdata(dev);
476+
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
477+
478+
return crb_cmd_ready(dev, priv);
479+
}
480+
#endif /* CONFIG_PM */
481+
482+
static const struct dev_pm_ops crb_pm = {
483+
SET_SYSTEM_SLEEP_PM_OPS(tpm_pm_suspend, tpm_pm_resume)
484+
SET_RUNTIME_PM_OPS(crb_pm_runtime_suspend, crb_pm_runtime_resume, NULL)
485+
};
486+
456487
static struct acpi_device_id crb_device_ids[] = {
457488
{"MSFT0101", 0},
458489
{"", 0},

0 commit comments

Comments
 (0)