blob: 86f355b6df1d345ff9cf0874c40a29f5f986b0f2 [file] [log] [blame]
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -08001/*
2 * Copyright (C) 2014 Intel Corporation
3 *
4 * Authors:
5 * Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
6 *
7 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
8 *
9 * This device driver implements the TPM interface as defined in
10 * the TCG CRB 2.0 TPM specification.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; version 2
15 * of the License.
16 */
17
18#include <linux/acpi.h>
19#include <linux/highmem.h>
20#include <linux/rculist.h>
21#include <linux/module.h>
Winkler, Tomase74f2f72016-10-08 14:59:39 +030022#include <linux/pm_runtime.h>
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080023#include "tpm.h"
24
25#define ACPI_SIG_TPM2 "TPM2"
26
27static const u8 CRB_ACPI_START_UUID[] = {
28 /* 0000 */ 0xAB, 0x6C, 0xBF, 0x6B, 0x63, 0x54, 0x14, 0x47,
29 /* 0008 */ 0xB7, 0xCD, 0xF0, 0x20, 0x3C, 0x03, 0x68, 0xD4
30};
31
32enum crb_defaults {
33 CRB_ACPI_START_REVISION_ID = 1,
34 CRB_ACPI_START_INDEX = 1,
35};
36
Jarkko Sakkinen7fd10d62016-09-02 22:34:19 +030037enum crb_ctrl_req {
Jarkko Sakkinenf39a9e92016-09-02 22:34:20 +030038 CRB_CTRL_REQ_CMD_READY = BIT(0),
39 CRB_CTRL_REQ_GO_IDLE = BIT(1),
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080040};
41
Jarkko Sakkinen7fd10d62016-09-02 22:34:19 +030042enum crb_ctrl_sts {
43 CRB_CTRL_STS_ERROR = BIT(0),
44 CRB_CTRL_STS_TPM_IDLE = BIT(1),
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080045};
46
47enum crb_start {
48 CRB_START_INVOKE = BIT(0),
49};
50
51enum crb_cancel {
52 CRB_CANCEL_INVOKE = BIT(0),
53};
54
55struct crb_control_area {
56 u32 req;
57 u32 sts;
58 u32 cancel;
59 u32 start;
60 u32 int_enable;
61 u32 int_sts;
62 u32 cmd_size;
Jarkko Sakkinen149789c2015-09-15 20:05:40 +030063 u32 cmd_pa_low;
64 u32 cmd_pa_high;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080065 u32 rsp_size;
66 u64 rsp_pa;
67} __packed;
68
69enum crb_status {
Jarkko Sakkinen7fd10d62016-09-02 22:34:19 +030070 CRB_DRV_STS_COMPLETE = BIT(0),
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080071};
72
73enum crb_flags {
74 CRB_FL_ACPI_START = BIT(0),
75 CRB_FL_CRB_START = BIT(1),
76};
77
78struct crb_priv {
79 unsigned int flags;
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -070080 void __iomem *iobase;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080081 struct crb_control_area __iomem *cca;
82 u8 __iomem *cmd;
83 u8 __iomem *rsp;
Tomas Winkleraa77ea02016-09-12 13:52:10 +030084 u32 cmd_size;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -080085};
86
Winkler, Tomasba5287b2016-09-15 10:27:38 +030087/**
88 * crb_go_idle - request tpm crb device to go the idle state
89 *
90 * @dev: crb device
91 * @priv: crb private data
92 *
93 * Write CRB_CTRL_REQ_GO_IDLE to TPM_CRB_CTRL_REQ
94 * The device should respond within TIMEOUT_C by clearing the bit.
95 * Anyhow, we do not wait here as a consequent CMD_READY request
96 * will be handled correctly even if idle was not completed.
97 *
98 * The function does nothing for devices with ACPI-start method.
99 *
100 * Return: 0 always
101 */
102static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
103{
104 if (priv->flags & CRB_FL_ACPI_START)
105 return 0;
106
107 iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->cca->req);
108 /* we don't really care when this settles */
109
110 return 0;
111}
112
113/**
114 * crb_cmd_ready - request tpm crb device to enter ready state
115 *
116 * @dev: crb device
117 * @priv: crb private data
118 *
119 * Write CRB_CTRL_REQ_CMD_READY to TPM_CRB_CTRL_REQ
120 * and poll till the device acknowledge it by clearing the bit.
121 * The device should respond within TIMEOUT_C.
122 *
123 * The function does nothing for devices with ACPI-start method
124 *
125 * Return: 0 on success -ETIME on timeout;
126 */
127static int __maybe_unused crb_cmd_ready(struct device *dev,
128 struct crb_priv *priv)
129{
130 ktime_t stop, start;
131
132 if (priv->flags & CRB_FL_ACPI_START)
133 return 0;
134
135 iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->cca->req);
136
137 start = ktime_get();
138 stop = ktime_add(start, ms_to_ktime(TPM2_TIMEOUT_C));
139 do {
140 if (!(ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY))
141 return 0;
142 usleep_range(50, 100);
143 } while (ktime_before(ktime_get(), stop));
144
145 if (ioread32(&priv->cca->req) & CRB_CTRL_REQ_CMD_READY) {
146 dev_warn(dev, "cmdReady timed out\n");
147 return -ETIME;
148 }
149
150 return 0;
151}
152
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800153static u8 crb_status(struct tpm_chip *chip)
154{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200155 struct crb_priv *priv = dev_get_drvdata(&chip->dev);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800156 u8 sts = 0;
157
Jason Gunthorpe1e3ed59d2016-01-07 17:36:25 -0700158 if ((ioread32(&priv->cca->start) & CRB_START_INVOKE) !=
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800159 CRB_START_INVOKE)
Jarkko Sakkinen7fd10d62016-09-02 22:34:19 +0300160 sts |= CRB_DRV_STS_COMPLETE;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800161
162 return sts;
163}
164
165static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
166{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200167 struct crb_priv *priv = dev_get_drvdata(&chip->dev);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800168 unsigned int expected;
169
170 /* sanity check */
171 if (count < 6)
172 return -EIO;
173
Jarkko Sakkinen7fd10d62016-09-02 22:34:19 +0300174 if (ioread32(&priv->cca->sts) & CRB_CTRL_STS_ERROR)
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800175 return -EIO;
176
177 memcpy_fromio(buf, priv->rsp, 6);
178 expected = be32_to_cpup((__be32 *) &buf[2]);
179
180 if (expected > count)
181 return -EIO;
182
183 memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6);
184
185 return expected;
186}
187
188static int crb_do_acpi_start(struct tpm_chip *chip)
189{
190 union acpi_object *obj;
191 int rc;
192
193 obj = acpi_evaluate_dsm(chip->acpi_dev_handle,
194 CRB_ACPI_START_UUID,
195 CRB_ACPI_START_REVISION_ID,
196 CRB_ACPI_START_INDEX,
197 NULL);
198 if (!obj)
199 return -ENXIO;
200 rc = obj->integer.value == 0 ? 0 : -ENXIO;
201 ACPI_FREE(obj);
202 return rc;
203}
204
205static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
206{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200207 struct crb_priv *priv = dev_get_drvdata(&chip->dev);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800208 int rc = 0;
209
Jarkko Sakkinen72fd50e2016-09-02 22:34:17 +0300210 /* Zero the cancel register so that the next command will not get
211 * canceled.
212 */
213 iowrite32(0, &priv->cca->cancel);
214
Tomas Winkleraa77ea02016-09-12 13:52:10 +0300215 if (len > priv->cmd_size) {
216 dev_err(&chip->dev, "invalid command count value %zd %d\n",
217 len, priv->cmd_size);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800218 return -E2BIG;
219 }
220
221 memcpy_toio(priv->cmd, buf, len);
222
223 /* Make sure that cmd is populated before issuing start. */
224 wmb();
225
226 if (priv->flags & CRB_FL_CRB_START)
Tomas Winkler47de6832016-09-12 14:27:09 +0300227 iowrite32(CRB_START_INVOKE, &priv->cca->start);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800228
229 if (priv->flags & CRB_FL_ACPI_START)
230 rc = crb_do_acpi_start(chip);
231
232 return rc;
233}
234
235static void crb_cancel(struct tpm_chip *chip)
236{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200237 struct crb_priv *priv = dev_get_drvdata(&chip->dev);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800238
Tomas Winkler47de6832016-09-12 14:27:09 +0300239 iowrite32(CRB_CANCEL_INVOKE, &priv->cca->cancel);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800240
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800241 if ((priv->flags & CRB_FL_ACPI_START) && crb_do_acpi_start(chip))
242 dev_err(&chip->dev, "ACPI Start failed\n");
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800243}
244
245static bool crb_req_canceled(struct tpm_chip *chip, u8 status)
246{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200247 struct crb_priv *priv = dev_get_drvdata(&chip->dev);
Jason Gunthorpe1e3ed59d2016-01-07 17:36:25 -0700248 u32 cancel = ioread32(&priv->cca->cancel);
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800249
250 return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE;
251}
252
253static const struct tpm_class_ops tpm_crb = {
Jason Gunthorpecae8b442016-07-12 11:41:49 -0600254 .flags = TPM_OPS_AUTO_STARTUP,
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800255 .status = crb_status,
256 .recv = crb_recv,
257 .send = crb_send,
258 .cancel = crb_cancel,
259 .req_canceled = crb_req_canceled,
Jarkko Sakkinen7fd10d62016-09-02 22:34:19 +0300260 .req_complete_mask = CRB_DRV_STS_COMPLETE,
261 .req_complete_val = CRB_DRV_STS_COMPLETE,
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800262};
263
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700264static int crb_check_resource(struct acpi_resource *ares, void *data)
265{
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200266 struct resource *io_res = data;
Jiandi An19b7bf52016-12-18 22:20:53 -0600267 struct resource_win win;
268 struct resource *res = &(win.res);
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700269
Jiandi An19b7bf52016-12-18 22:20:53 -0600270 if (acpi_dev_resource_memory(ares, res) ||
271 acpi_dev_resource_address_space(ares, &win)) {
272 *io_res = *res;
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200273 io_res->name = NULL;
Jarkko Sakkinen30f9c8c2016-02-17 02:10:52 +0200274 }
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700275
276 return 1;
277}
278
279static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200280 struct resource *io_res, u64 start, u32 size)
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700281{
282 struct resource new_res = {
283 .start = start,
284 .end = start + size - 1,
285 .flags = IORESOURCE_MEM,
286 };
287
288 /* Detect a 64 bit address on a 32 bit system */
289 if (start != new_res.start)
Jarkko Sakkinenf786b752016-06-17 16:39:29 +0200290 return (void __iomem *) ERR_PTR(-EINVAL);
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700291
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200292 if (!resource_contains(io_res, &new_res))
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700293 return devm_ioremap_resource(dev, &new_res);
294
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200295 return priv->iobase + (new_res.start - io_res->start);
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700296}
297
298static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
299 struct acpi_table_tpm2 *buf)
300{
301 struct list_head resources;
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200302 struct resource io_res;
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700303 struct device *dev = &device->dev;
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300304 u32 pa_high, pa_low;
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300305 u64 cmd_pa;
306 u32 cmd_size;
307 u64 rsp_pa;
308 u32 rsp_size;
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700309 int ret;
310
311 INIT_LIST_HEAD(&resources);
312 ret = acpi_dev_get_resources(device, &resources, crb_check_resource,
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200313 &io_res);
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700314 if (ret < 0)
315 return ret;
316 acpi_dev_free_resource_list(&resources);
317
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200318 if (resource_type(&io_res) != IORESOURCE_MEM) {
Tomas Winkler64fba5302016-09-12 02:03:55 +0300319 dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n");
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700320 return -EINVAL;
321 }
322
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200323 priv->iobase = devm_ioremap_resource(dev, &io_res);
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700324 if (IS_ERR(priv->iobase))
325 return PTR_ERR(priv->iobase);
326
Jarkko Sakkinen14ddfbf2016-03-15 21:41:40 +0200327 priv->cca = crb_map_res(dev, priv, &io_res, buf->control_address,
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300328 sizeof(struct crb_control_area));
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700329 if (IS_ERR(priv->cca))
330 return PTR_ERR(priv->cca);
331
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300332 /*
333 * PTT HW bug w/a: wake up the device to access
334 * possibly not retained registers.
335 */
336 ret = crb_cmd_ready(dev, priv);
337 if (ret)
338 return ret;
339
340 pa_high = ioread32(&priv->cca->cmd_pa_high);
341 pa_low = ioread32(&priv->cca->cmd_pa_low);
342 cmd_pa = ((u64)pa_high << 32) | pa_low;
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300343 cmd_size = ioread32(&priv->cca->cmd_size);
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300344
345 dev_dbg(dev, "cmd_hi = %X cmd_low = %X cmd_size %X\n",
346 pa_high, pa_low, cmd_size);
347
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300348 priv->cmd = crb_map_res(dev, priv, &io_res, cmd_pa, cmd_size);
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300349 if (IS_ERR(priv->cmd)) {
350 ret = PTR_ERR(priv->cmd);
351 goto out;
352 }
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700353
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300354 memcpy_fromio(&rsp_pa, &priv->cca->rsp_pa, 8);
355 rsp_pa = le64_to_cpu(rsp_pa);
356 rsp_size = ioread32(&priv->cca->rsp_size);
357
358 if (cmd_pa != rsp_pa) {
359 priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size);
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300360 ret = PTR_ERR_OR_ZERO(priv->rsp);
361 goto out;
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300362 }
363
364 /* According to the PTP specification, overlapping command and response
365 * buffer sizes must be identical.
366 */
367 if (cmd_size != rsp_size) {
368 dev_err(dev, FW_BUG "overlapping command and response buffer sizes are not identical");
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300369 ret = -EINVAL;
370 goto out;
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300371 }
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300372
Tomas Winkleraa77ea02016-09-12 13:52:10 +0300373 priv->cmd_size = cmd_size;
Jarkko Sakkinen422eac32016-04-19 12:54:18 +0300374
375 priv->rsp = priv->cmd;
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300376
377out:
378 crb_go_idle(dev, priv);
379
380 return ret;
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700381}
382
383static int crb_acpi_add(struct acpi_device *device)
384{
Jason Gunthorpe55a889c2016-01-07 17:36:20 -0700385 struct acpi_table_tpm2 *buf;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800386 struct crb_priv *priv;
Winkler, Tomasc58bd34c2016-09-12 16:04:20 +0300387 struct tpm_chip *chip;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800388 struct device *dev = &device->dev;
389 acpi_status status;
390 u32 sm;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800391 int rc;
392
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800393 status = acpi_get_table(ACPI_SIG_TPM2, 1,
394 (struct acpi_table_header **) &buf);
Jason Gunthorpe55a889c2016-01-07 17:36:20 -0700395 if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) {
396 dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700397 return -EINVAL;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800398 }
399
Jarkko Sakkinen399235d2015-09-29 00:32:19 +0300400 /* Should the FIFO driver handle this? */
Jason Gunthorpe55a889c2016-01-07 17:36:20 -0700401 sm = buf->start_method;
402 if (sm == ACPI_TPM2_MEMORY_MAPPED)
Jarkko Sakkinen399235d2015-09-29 00:32:19 +0300403 return -ENODEV;
404
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700405 priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL);
406 if (!priv)
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800407 return -ENOMEM;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800408
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800409 /* The reason for the extra quirk is that the PTT in 4th Gen Core CPUs
410 * report only ACPI start but in practice seems to require both
411 * ACPI start and CRB start.
412 */
Jason Gunthorpe55a889c2016-01-07 17:36:20 -0700413 if (sm == ACPI_TPM2_COMMAND_BUFFER || sm == ACPI_TPM2_MEMORY_MAPPED ||
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800414 !strcmp(acpi_device_hid(device), "MSFT0101"))
415 priv->flags |= CRB_FL_CRB_START;
416
Jason Gunthorpe55a889c2016-01-07 17:36:20 -0700417 if (sm == ACPI_TPM2_START_METHOD ||
418 sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD)
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800419 priv->flags |= CRB_FL_ACPI_START;
420
Jason Gunthorpe1bd047b2016-01-07 17:36:26 -0700421 rc = crb_map_io(device, priv, buf);
Jason Gunthorpe25112042015-11-25 14:05:32 -0700422 if (rc)
423 return rc;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800424
Winkler, Tomasc58bd34c2016-09-12 16:04:20 +0300425 chip = tpmm_chip_alloc(dev, &tpm_crb);
426 if (IS_ERR(chip))
427 return PTR_ERR(chip);
428
429 dev_set_drvdata(&chip->dev, priv);
430 chip->acpi_dev_handle = device->handle;
431 chip->flags = TPM_CHIP_FLAG_TPM2;
432
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300433 rc = crb_cmd_ready(dev, priv);
434 if (rc)
435 return rc;
436
Winkler, Tomase74f2f72016-10-08 14:59:39 +0300437 pm_runtime_get_noresume(dev);
438 pm_runtime_set_active(dev);
439 pm_runtime_enable(dev);
Winkler, Tomasbc33c5d2016-09-12 16:04:19 +0300440
Winkler, Tomase74f2f72016-10-08 14:59:39 +0300441 rc = tpm_chip_register(chip);
442 if (rc) {
443 crb_go_idle(dev, priv);
444 pm_runtime_put_noidle(dev);
445 pm_runtime_disable(dev);
446 return rc;
447 }
448
449 pm_runtime_put(dev);
450
451 return 0;
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800452}
453
454static int crb_acpi_remove(struct acpi_device *device)
455{
456 struct device *dev = &device->dev;
457 struct tpm_chip *chip = dev_get_drvdata(dev);
458
Jarkko Sakkinen99cda8c2016-02-18 22:11:29 +0200459 tpm_chip_unregister(chip);
460
Winkler, Tomase74f2f72016-10-08 14:59:39 +0300461 pm_runtime_disable(dev);
462
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800463 return 0;
464}
465
Winkler, Tomase74f2f72016-10-08 14:59:39 +0300466#ifdef CONFIG_PM
467static int crb_pm_runtime_suspend(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_go_idle(dev, priv);
473}
474
475static int crb_pm_runtime_resume(struct device *dev)
476{
477 struct tpm_chip *chip = dev_get_drvdata(dev);
478 struct crb_priv *priv = dev_get_drvdata(&chip->dev);
479
480 return crb_cmd_ready(dev, priv);
481}
482#endif /* CONFIG_PM */
483
484static const struct dev_pm_ops crb_pm = {
485 SET_SYSTEM_SLEEP_PM_OPS(tpm_pm_suspend, tpm_pm_resume)
486 SET_RUNTIME_PM_OPS(crb_pm_runtime_suspend, crb_pm_runtime_resume, NULL)
487};
488
Jarkko Sakkinen30fc8d12014-12-12 11:46:39 -0800489static struct acpi_device_id crb_device_ids[] = {
490 {"MSFT0101", 0},
491 {"", 0},
492};
493MODULE_DEVICE_TABLE(acpi, crb_device_ids);
494
495static struct acpi_driver crb_acpi_driver = {
496 .name = "tpm_crb",
497 .ids = crb_device_ids,
498 .ops = {
499 .add = crb_acpi_add,
500 .remove = crb_acpi_remove,
501 },
502 .drv = {
503 .pm = &crb_pm,
504 },
505};
506
507module_acpi_driver(crb_acpi_driver);
508MODULE_AUTHOR("Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>");
509MODULE_DESCRIPTION("TPM2 Driver");
510MODULE_VERSION("0.1");
511MODULE_LICENSE("GPL");