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-09-16 08:47:36 -0400
commite17acbbb69d30836a8c12e2c09bbefab8656693e (patch)
treeec99a60f272655fbeb33d08eb6fd81183d819ede
parentebfd7532e985818a327906e011f3e43c8ddfdd74 (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. 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>
-rw-r--r--drivers/char/tpm/tpm_crb.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index a7c870af916c..466d12b7fd46 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -83,6 +83,75 @@ 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 dev_dbg(dev, "cmdReady in %lld usecs\n",
141 ktime_to_us(ktime_sub(ktime_get(), start)));
142 return 0;
143 }
144 usleep_range(50, 100);
145 } while (ktime_before(ktime_get(), stop));
146
147 if (ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY) {
148 dev_warn(dev, "cmdReady timed out\n");
149 return -ETIME;
150 }
151
152 return 0;
153}
154
86static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume); 155static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume);
87 156
88static u8 crb_status(struct tpm_chip *chip) 157static u8 crb_status(struct tpm_chip *chip)