Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Winkler, Tomas and committed by
Jarkko Sakkinen
e350e246 0c22db43

+39 -3
+5
drivers/char/tpm/tpm-interface.c
··· 29 29 #include <linux/mutex.h> 30 30 #include <linux/spinlock.h> 31 31 #include <linux/freezer.h> 32 + #include <linux/pm_runtime.h> 32 33 33 34 #include "tpm.h" 34 35 #include "tpm_eventlog.h" ··· 357 356 if (!(flags & TPM_TRANSMIT_UNLOCKED)) 358 357 mutex_lock(&chip->tpm_mutex); 359 358 359 + pm_runtime_get_sync(chip->dev.parent); 360 + 360 361 rc = chip->ops->send(chip, (u8 *) buf, count); 361 362 if (rc < 0) { 362 363 dev_err(&chip->dev, ··· 400 397 dev_err(&chip->dev, 401 398 "tpm_transmit: tpm_recv: error %zd\n", rc); 402 399 out: 400 + pm_runtime_put(chip->dev.parent); 401 + 403 402 if (!(flags & TPM_TRANSMIT_UNLOCKED)) 404 403 mutex_unlock(&chip->tpm_mutex); 405 404 return rc;
+34 -3
drivers/char/tpm/tpm_crb.c
··· 19 19 #include <linux/highmem.h> 20 20 #include <linux/rculist.h> 21 21 #include <linux/module.h> 22 + #include <linux/pm_runtime.h> 22 23 #include "tpm.h" 23 24 24 25 #define ACPI_SIG_TPM2 "TPM2" ··· 152 151 153 152 return 0; 154 153 } 155 - 156 - static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume); 157 154 158 155 static u8 crb_status(struct tpm_chip *chip) 159 156 { ··· 435 436 if (rc) 436 437 return rc; 437 438 439 + pm_runtime_set_active(dev); 440 + pm_runtime_enable(dev); 441 + 438 442 rc = tpm_chip_register(chip); 439 - if (rc) 443 + if (rc) { 440 444 crb_go_idle(dev, priv); 445 + pm_runtime_disable(dev); 446 + } 447 + 448 + pm_runtime_put(dev); 441 449 442 450 return rc; 443 451 } ··· 456 450 457 451 tpm_chip_unregister(chip); 458 452 453 + pm_runtime_disable(dev); 454 + 459 455 return 0; 460 456 } 457 + 458 + #ifdef CONFIG_PM 459 + static int crb_pm_runtime_suspend(struct device *dev) 460 + { 461 + struct tpm_chip *chip = dev_get_drvdata(dev); 462 + struct crb_priv *priv = dev_get_drvdata(&chip->dev); 463 + 464 + return crb_go_idle(dev, priv); 465 + } 466 + 467 + static int crb_pm_runtime_resume(struct device *dev) 468 + { 469 + struct tpm_chip *chip = dev_get_drvdata(dev); 470 + struct crb_priv *priv = dev_get_drvdata(&chip->dev); 471 + 472 + return crb_cmd_ready(dev, priv); 473 + } 474 + #endif /* CONFIG_PM */ 475 + 476 + static const struct dev_pm_ops crb_pm = { 477 + SET_SYSTEM_SLEEP_PM_OPS(tpm_pm_suspend, tpm_pm_resume) 478 + SET_RUNTIME_PM_OPS(crb_pm_runtime_suspend, crb_pm_runtime_resume, NULL) 479 + }; 461 480 462 481 static struct acpi_device_id crb_device_ids[] = { 463 482 {"MSFT0101", 0},