diff options
-rw-r--r-- | drivers/char/tpm/tpm-interface.c | 5 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_crb.c | 37 |
2 files changed, 39 insertions, 3 deletions
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 8de61876f633..77d83c98d67f 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/mutex.h> | 29 | #include <linux/mutex.h> |
30 | #include <linux/spinlock.h> | 30 | #include <linux/spinlock.h> |
31 | #include <linux/freezer.h> | 31 | #include <linux/freezer.h> |
32 | #include <linux/pm_runtime.h> | ||
32 | 33 | ||
33 | #include "tpm.h" | 34 | #include "tpm.h" |
34 | #include "tpm_eventlog.h" | 35 | #include "tpm_eventlog.h" |
@@ -356,6 +357,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz, | |||
356 | if (!(flags & TPM_TRANSMIT_UNLOCKED)) | 357 | if (!(flags & TPM_TRANSMIT_UNLOCKED)) |
357 | mutex_lock(&chip->tpm_mutex); | 358 | mutex_lock(&chip->tpm_mutex); |
358 | 359 | ||
360 | pm_runtime_get_sync(chip->dev.parent); | ||
361 | |||
359 | rc = chip->ops->send(chip, (u8 *) buf, count); | 362 | rc = chip->ops->send(chip, (u8 *) buf, count); |
360 | if (rc < 0) { | 363 | if (rc < 0) { |
361 | dev_err(&chip->dev, | 364 | dev_err(&chip->dev, |
@@ -397,6 +400,8 @@ out_recv: | |||
397 | dev_err(&chip->dev, | 400 | dev_err(&chip->dev, |
398 | "tpm_transmit: tpm_recv: error %zd\n", rc); | 401 | "tpm_transmit: tpm_recv: error %zd\n", rc); |
399 | out: | 402 | out: |
403 | pm_runtime_put(chip->dev.parent); | ||
404 | |||
400 | if (!(flags & TPM_TRANSMIT_UNLOCKED)) | 405 | if (!(flags & TPM_TRANSMIT_UNLOCKED)) |
401 | mutex_unlock(&chip->tpm_mutex); | 406 | mutex_unlock(&chip->tpm_mutex); |
402 | return rc; | 407 | return rc; |
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index d385e63008a6..aa0ef742ac03 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/highmem.h> | 19 | #include <linux/highmem.h> |
20 | #include <linux/rculist.h> | 20 | #include <linux/rculist.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/pm_runtime.h> | ||
22 | #include "tpm.h" | 23 | #include "tpm.h" |
23 | 24 | ||
24 | #define ACPI_SIG_TPM2 "TPM2" | 25 | #define ACPI_SIG_TPM2 "TPM2" |
@@ -152,8 +153,6 @@ static int __maybe_unused crb_cmd_ready(struct device *dev, | |||
152 | return 0; | 153 | return 0; |
153 | } | 154 | } |
154 | 155 | ||
155 | static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume); | ||
156 | |||
157 | static u8 crb_status(struct tpm_chip *chip) | 156 | static u8 crb_status(struct tpm_chip *chip) |
158 | { | 157 | { |
159 | struct crb_priv *priv = dev_get_drvdata(&chip->dev); | 158 | struct crb_priv *priv = dev_get_drvdata(&chip->dev); |
@@ -436,9 +435,16 @@ static int crb_acpi_add(struct acpi_device *device) | |||
436 | if (rc) | 435 | if (rc) |
437 | return rc; | 436 | return rc; |
438 | 437 | ||
438 | pm_runtime_set_active(dev); | ||
439 | pm_runtime_enable(dev); | ||
440 | |||
439 | rc = tpm_chip_register(chip); | 441 | rc = tpm_chip_register(chip); |
440 | if (rc) | 442 | if (rc) { |
441 | crb_go_idle(dev, priv); | 443 | crb_go_idle(dev, priv); |
444 | pm_runtime_disable(dev); | ||
445 | } | ||
446 | |||
447 | pm_runtime_put(dev); | ||
442 | 448 | ||
443 | return rc; | 449 | return rc; |
444 | } | 450 | } |
@@ -450,9 +456,34 @@ static int crb_acpi_remove(struct acpi_device *device) | |||
450 | 456 | ||
451 | tpm_chip_unregister(chip); | 457 | tpm_chip_unregister(chip); |
452 | 458 | ||
459 | pm_runtime_disable(dev); | ||
460 | |||
453 | return 0; | 461 | return 0; |
454 | } | 462 | } |
455 | 463 | ||
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 | |||
456 | static struct acpi_device_id crb_device_ids[] = { | 487 | static struct acpi_device_id crb_device_ids[] = { |
457 | {"MSFT0101", 0}, | 488 | {"MSFT0101", 0}, |
458 | {"", 0}, | 489 | {"", 0}, |