aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinkler, Tomas <tomas.winkler@intel.com>2016-09-15 03:27:38 -0400
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>2016-11-27 18:31:29 -0500
commitba5287b6ef6a2ee91dc6cc0829649cecf7b70253 (patch)
tree931ec227dd3319ee00fad0d9e19aa276a19c6d17
parent0821e30cd2f246a93c5271f6c23d7134f809d70d (diff)
tpm/tpm_crb: implement tpm crb idle state
The register TPM_CRB_CTRL_REQ_x contains bits goIdle and cmdReady for SW to indicate that the device can enter or should exit the idle state. The legacy ACPI-start (SMI + DMA) based devices do not support these bits and the idle state management is not exposed to the host SW. Thus, this functionality only is enabled only for a CRB start (MMIO) based devices. Based on Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> original patch: 'tpm_crb: implement power tpm crb power management' To keep the implementation local to the hw we don't use wait_for_tpm_stat for polling the TPM_CRB_CTRL_REQ. [jarkko.sakkinen@linux.intel.com: removed cmdReady debug trace on a success case due the heavy amount of log traffic it causes.] 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> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r--drivers/char/tpm/tpm_crb.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index a7c870af916c..8dd0f20a839c 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -83,6 +83,72 @@ struct crb_priv {
83 u32 cmd_size; 83 u32 cmd_size;
84}; 84};
85 85
86/**
87 * crb_go_idle - request tpm crb device to go the idle state
88 *
89 * @dev: crb device
90 * @priv: crb private data
91 *
92 * Write CRB_CTRL_REQ_GO_IDLE to TPM_CRB_CTRL_REQ
93 * The device should respond within TIMEOUT_C by clearing the bit.
94 * Anyhow, we do not wait here as a consequent CMD_READY request
95 * will be handled correctly even if idle was not completed.
96 *
97 * The function does nothing for devices with ACPI-start method.
98 *
99 * Return: 0 always
100 */
101static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
102{
103 if (priv->flags & CRB_FL_ACPI_START)
104 return 0;
105
106 iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->cca->req);
107 /* we don't really care when this settles */
108
109 return 0;
110}
111
112/**
113 * crb_cmd_ready - request tpm crb device to enter ready state
114 *
115 * @dev: crb device
116 * @priv: crb private data
117 *
118 * Write CRB_CTRL_REQ_CMD_READY to TPM_CRB_CTRL_REQ
119 * and poll till the device acknowledge it by clearing the bit.
120 * The device should respond within TIMEOUT_C.
121 *
122 * The function does nothing for devices with ACPI-start method
123 *
124 * Return: 0 on success -ETIME on timeout;
125 */
126static int __maybe_unused crb_cmd_ready(struct device *dev,
127 struct crb_priv *priv)
128{
129 ktime_t stop, start;
130
131 if (priv->flags & CRB_FL_ACPI_START)
132 return 0;
133
134 iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->cca->req);
135
136 start = ktime_get();
137 stop = ktime_add(start, ms_to_ktime(TPM2_TIMEOUT_C));
138 do {
139 if (!(ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY))
140 return 0;
141 usleep_range(50, 100);
142 } while (ktime_before(ktime_get(), stop));
143
144 if (ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY) {
145 dev_warn(dev, "cmdReady timed out\n");
146 return -ETIME;
147 }
148
149 return 0;
150}
151
86static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume); 152static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume);
87 153
88static u8 crb_status(struct tpm_chip *chip) 154static u8 crb_status(struct tpm_chip *chip)