Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005, 2006 IBM Corporation |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 3 | * Copyright (C) 2014, 2015 Intel Corporation |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 4 | * |
| 5 | * Authors: |
| 6 | * Leendert van Doorn <leendert@watson.ibm.com> |
| 7 | * Kylene Hall <kjhall@us.ibm.com> |
| 8 | * |
Kent Yoder | 8e81cc1 | 2007-08-22 14:01:04 -0700 | [diff] [blame] | 9 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
| 10 | * |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 11 | * Device driver for TCG/TCPA TPM (trusted platform module). |
| 12 | * Specifications at www.trustedcomputinggroup.org |
| 13 | * |
| 14 | * This device driver implements the TPM interface as defined in |
| 15 | * the TCG TPM Interface Spec version 1.2, revision 1.0. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or |
| 18 | * modify it under the terms of the GNU General Public License as |
| 19 | * published by the Free Software Foundation, version 2 of the |
| 20 | * License. |
| 21 | */ |
Kylene Jo Hall | 5713556 | 2006-04-22 02:39:44 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/moduleparam.h> |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 25 | #include <linux/pnp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/wait.h> |
Matthew Garrett | 3f0d3d0 | 2010-10-21 17:42:40 -0400 | [diff] [blame] | 29 | #include <linux/acpi.h> |
Stefan Berger | 20b87bb | 2011-03-30 12:13:31 -0400 | [diff] [blame] | 30 | #include <linux/freezer.h> |
Jason Gunthorpe | 420d439 | 2016-11-07 15:44:31 -0700 | [diff] [blame] | 31 | #include <linux/of.h> |
| 32 | #include <linux/of_device.h> |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 33 | #include "tpm.h" |
Christophe Ricard | 57dacc2 | 2016-05-19 00:35:48 +0200 | [diff] [blame] | 34 | #include "tpm_tis_core.h" |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 35 | |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 36 | struct tpm_info { |
Jason Gunthorpe | 51dd43d | 2016-01-07 17:36:23 -0700 | [diff] [blame] | 37 | struct resource res; |
Jason Gunthorpe | ef7b81d | 2016-01-07 17:36:21 -0700 | [diff] [blame] | 38 | /* irq > 0 means: use irq $irq; |
| 39 | * irq = 0 means: autoprobe for an irq; |
| 40 | * irq = -1 means: no irq support |
| 41 | */ |
| 42 | int irq; |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 43 | }; |
| 44 | |
Christophe Ricard | 57dacc2 | 2016-05-19 00:35:48 +0200 | [diff] [blame] | 45 | struct tpm_tis_tcg_phy { |
| 46 | struct tpm_tis_data priv; |
Christophe Ricard | 4eea703 | 2016-03-31 22:56:55 +0200 | [diff] [blame] | 47 | void __iomem *iobase; |
Scot Doyle | 448e9c5 | 2014-09-24 22:41:10 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Christophe Ricard | 57dacc2 | 2016-05-19 00:35:48 +0200 | [diff] [blame] | 50 | static inline struct tpm_tis_tcg_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data) |
| 51 | { |
| 52 | return container_of(data, struct tpm_tis_tcg_phy, priv); |
| 53 | } |
| 54 | |
Christophe Ricard | 41a5e1c | 2016-05-19 00:35:52 +0200 | [diff] [blame] | 55 | static bool interrupts = true; |
| 56 | module_param(interrupts, bool, 0444); |
| 57 | MODULE_PARM_DESC(interrupts, "Enable interrupts"); |
| 58 | |
| 59 | static bool itpm; |
| 60 | module_param(itpm, bool, 0444); |
| 61 | MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)"); |
| 62 | |
| 63 | static bool force; |
| 64 | #ifdef CONFIG_X86 |
| 65 | module_param(force, bool, 0444); |
| 66 | MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry"); |
| 67 | #endif |
| 68 | |
Randy Dunlap | 1560ffe6 | 2011-08-03 16:21:11 -0700 | [diff] [blame] | 69 | #if defined(CONFIG_PNP) && defined(CONFIG_ACPI) |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 70 | static int has_hid(struct acpi_device *dev, const char *hid) |
Matthew Garrett | 3f0d3d0 | 2010-10-21 17:42:40 -0400 | [diff] [blame] | 71 | { |
Matthew Garrett | 3f0d3d0 | 2010-10-21 17:42:40 -0400 | [diff] [blame] | 72 | struct acpi_hardware_id *id; |
| 73 | |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 74 | list_for_each_entry(id, &dev->pnp.ids, list) |
| 75 | if (!strcmp(hid, id->id)) |
Matthew Garrett | 3f0d3d0 | 2010-10-21 17:42:40 -0400 | [diff] [blame] | 76 | return 1; |
Matthew Garrett | 3f0d3d0 | 2010-10-21 17:42:40 -0400 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | } |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 80 | |
| 81 | static inline int is_itpm(struct acpi_device *dev) |
| 82 | { |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 83 | if (!dev) |
| 84 | return 0; |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 85 | return has_hid(dev, "INTC0102"); |
| 86 | } |
Randy Dunlap | 1560ffe6 | 2011-08-03 16:21:11 -0700 | [diff] [blame] | 87 | #else |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 88 | static inline int is_itpm(struct acpi_device *dev) |
Randy Dunlap | 1560ffe6 | 2011-08-03 16:21:11 -0700 | [diff] [blame] | 89 | { |
| 90 | return 0; |
| 91 | } |
Matthew Garrett | 3f0d3d0 | 2010-10-21 17:42:40 -0400 | [diff] [blame] | 92 | #endif |
| 93 | |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 94 | #if defined(CONFIG_ACPI) |
| 95 | #define DEVICE_IS_TPM2 1 |
| 96 | |
| 97 | static const struct acpi_device_id tpm_acpi_tbl[] = { |
| 98 | {"MSFT0101", DEVICE_IS_TPM2}, |
| 99 | {}, |
| 100 | }; |
| 101 | MODULE_DEVICE_TABLE(acpi, tpm_acpi_tbl); |
| 102 | |
| 103 | static int check_acpi_tpm2(struct device *dev) |
| 104 | { |
| 105 | const struct acpi_device_id *aid = acpi_match_device(tpm_acpi_tbl, dev); |
| 106 | struct acpi_table_tpm2 *tbl; |
| 107 | acpi_status st; |
| 108 | |
| 109 | if (!aid || aid->driver_data != DEVICE_IS_TPM2) |
| 110 | return 0; |
| 111 | |
| 112 | /* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2 |
| 113 | * table is mandatory |
| 114 | */ |
| 115 | st = |
| 116 | acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **)&tbl); |
| 117 | if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) { |
| 118 | dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n"); |
| 119 | return -EINVAL; |
| 120 | } |
| 121 | |
| 122 | /* The tpm2_crb driver handles this device */ |
| 123 | if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED) |
| 124 | return -ENODEV; |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | #else |
| 129 | static int check_acpi_tpm2(struct device *dev) |
| 130 | { |
| 131 | return 0; |
| 132 | } |
| 133 | #endif |
| 134 | |
Christophe Ricard | 1107d06 | 2016-05-19 00:35:49 +0200 | [diff] [blame] | 135 | static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len, |
| 136 | u8 *result) |
| 137 | { |
| 138 | struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data); |
| 139 | |
| 140 | while (len--) |
| 141 | *result++ = ioread8(phy->iobase + addr); |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int tpm_tcg_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len, |
| 146 | u8 *value) |
| 147 | { |
| 148 | struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data); |
| 149 | |
| 150 | while (len--) |
| 151 | iowrite8(*value++, phy->iobase + addr); |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int tpm_tcg_read16(struct tpm_tis_data *data, u32 addr, u16 *result) |
| 156 | { |
| 157 | struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data); |
| 158 | |
| 159 | *result = ioread16(phy->iobase + addr); |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int tpm_tcg_read32(struct tpm_tis_data *data, u32 addr, u32 *result) |
| 164 | { |
| 165 | struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data); |
| 166 | |
| 167 | *result = ioread32(phy->iobase + addr); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int tpm_tcg_write32(struct tpm_tis_data *data, u32 addr, u32 value) |
| 172 | { |
| 173 | struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data); |
| 174 | |
| 175 | iowrite32(value, phy->iobase + addr); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static const struct tpm_tis_phy_ops tpm_tcg = { |
| 180 | .read_bytes = tpm_tcg_read_bytes, |
| 181 | .write_bytes = tpm_tcg_write_bytes, |
| 182 | .read16 = tpm_tcg_read16, |
| 183 | .read32 = tpm_tcg_read32, |
| 184 | .write32 = tpm_tcg_write32, |
| 185 | }; |
| 186 | |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 187 | static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info) |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 188 | { |
Christophe Ricard | 57dacc2 | 2016-05-19 00:35:48 +0200 | [diff] [blame] | 189 | struct tpm_tis_tcg_phy *phy; |
Christophe Ricard | 41a5e1c | 2016-05-19 00:35:52 +0200 | [diff] [blame] | 190 | int irq = -1; |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 191 | int rc; |
| 192 | |
| 193 | rc = check_acpi_tpm2(dev); |
| 194 | if (rc) |
| 195 | return rc; |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 196 | |
Christophe Ricard | 57dacc2 | 2016-05-19 00:35:48 +0200 | [diff] [blame] | 197 | phy = devm_kzalloc(dev, sizeof(struct tpm_tis_tcg_phy), GFP_KERNEL); |
| 198 | if (phy == NULL) |
Scot Doyle | 448e9c5 | 2014-09-24 22:41:10 +0000 | [diff] [blame] | 199 | return -ENOMEM; |
Jarkko Sakkinen | afb5abc | 2014-12-12 11:46:34 -0800 | [diff] [blame] | 200 | |
Christophe Ricard | 57dacc2 | 2016-05-19 00:35:48 +0200 | [diff] [blame] | 201 | phy->iobase = devm_ioremap_resource(dev, &tpm_info->res); |
| 202 | if (IS_ERR(phy->iobase)) |
| 203 | return PTR_ERR(phy->iobase); |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 204 | |
Christophe Ricard | 41a5e1c | 2016-05-19 00:35:52 +0200 | [diff] [blame] | 205 | if (interrupts) |
| 206 | irq = tpm_info->irq; |
Stefan Berger | 9519de3 | 2011-03-30 12:13:33 -0400 | [diff] [blame] | 207 | |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 208 | if (itpm || is_itpm(ACPI_COMPANION(dev))) |
Maciej S. Szmigiero | 1d70fe9 | 2017-01-13 22:37:00 +0100 | [diff] [blame] | 209 | phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND; |
Rajiv Andrade | 3507d61 | 2009-09-10 17:09:35 -0300 | [diff] [blame] | 210 | |
Christophe Ricard | 41a5e1c | 2016-05-19 00:35:52 +0200 | [diff] [blame] | 211 | return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg, |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 212 | ACPI_HANDLE(dev)); |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 213 | } |
Stefan Berger | 9685431 | 2011-07-17 01:04:24 -0400 | [diff] [blame] | 214 | |
Shuah Khan | a2fa3fb | 2013-09-11 14:23:13 -0700 | [diff] [blame] | 215 | static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume); |
| 216 | |
Bill Pemberton | afc6d36 | 2012-11-19 13:22:42 -0500 | [diff] [blame] | 217 | static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev, |
Jason Gunthorpe | ef7b81d | 2016-01-07 17:36:21 -0700 | [diff] [blame] | 218 | const struct pnp_device_id *pnp_id) |
Kylene Jo Hall | 9e323d3 | 2006-07-14 00:24:31 -0700 | [diff] [blame] | 219 | { |
Jason Gunthorpe | ef7b81d | 2016-01-07 17:36:21 -0700 | [diff] [blame] | 220 | struct tpm_info tpm_info = {}; |
Jason Gunthorpe | 51dd43d | 2016-01-07 17:36:23 -0700 | [diff] [blame] | 221 | struct resource *res; |
Bjorn Helgaas | 7917ff9 | 2007-10-16 23:26:46 -0700 | [diff] [blame] | 222 | |
Jason Gunthorpe | 51dd43d | 2016-01-07 17:36:23 -0700 | [diff] [blame] | 223 | res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0); |
| 224 | if (!res) |
| 225 | return -ENODEV; |
| 226 | tpm_info.res = *res; |
Kylene Jo Hall | 9e323d3 | 2006-07-14 00:24:31 -0700 | [diff] [blame] | 227 | |
Bjorn Helgaas | 7917ff9 | 2007-10-16 23:26:46 -0700 | [diff] [blame] | 228 | if (pnp_irq_valid(pnp_dev, 0)) |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 229 | tpm_info.irq = pnp_irq(pnp_dev, 0); |
Bjorn Helgaas | 7917ff9 | 2007-10-16 23:26:46 -0700 | [diff] [blame] | 230 | else |
Jason Gunthorpe | ef7b81d | 2016-01-07 17:36:21 -0700 | [diff] [blame] | 231 | tpm_info.irq = -1; |
Bjorn Helgaas | 7917ff9 | 2007-10-16 23:26:46 -0700 | [diff] [blame] | 232 | |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 233 | return tpm_tis_init(&pnp_dev->dev, &tpm_info); |
Kylene Jo Hall | 9e323d3 | 2006-07-14 00:24:31 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Bill Pemberton | 0bbed20 | 2012-11-19 13:24:36 -0500 | [diff] [blame] | 236 | static struct pnp_device_id tpm_pnp_tbl[] = { |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 237 | {"PNP0C31", 0}, /* TPM */ |
Kylene Jo Hall | 93e1b7d | 2006-04-22 02:39:52 -0700 | [diff] [blame] | 238 | {"ATM1200", 0}, /* Atmel */ |
| 239 | {"IFX0102", 0}, /* Infineon */ |
| 240 | {"BCM0101", 0}, /* Broadcom */ |
LE DISEZ Erwan | 061991e | 2008-07-25 19:44:56 -0700 | [diff] [blame] | 241 | {"BCM0102", 0}, /* Broadcom */ |
Kylene Jo Hall | 93e1b7d | 2006-04-22 02:39:52 -0700 | [diff] [blame] | 242 | {"NSC1200", 0}, /* National */ |
Marcin Obara | fb0e7e1 | 2008-07-10 17:30:42 -0700 | [diff] [blame] | 243 | {"ICO0102", 0}, /* Intel */ |
Kylene Jo Hall | 93e1b7d | 2006-04-22 02:39:52 -0700 | [diff] [blame] | 244 | /* Add new here */ |
| 245 | {"", 0}, /* User Specified */ |
| 246 | {"", 0} /* Terminator */ |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 247 | }; |
Matt Domsch | 31bde71 | 2009-11-03 12:05:50 +1100 | [diff] [blame] | 248 | MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl); |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 249 | |
Bill Pemberton | 39af33f | 2012-11-19 13:26:26 -0500 | [diff] [blame] | 250 | static void tpm_tis_pnp_remove(struct pnp_dev *dev) |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame] | 251 | { |
| 252 | struct tpm_chip *chip = pnp_get_drvdata(dev); |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 253 | |
Jarkko Sakkinen | afb5abc | 2014-12-12 11:46:34 -0800 | [diff] [blame] | 254 | tpm_chip_unregister(chip); |
| 255 | tpm_tis_remove(chip); |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame] | 256 | } |
| 257 | |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 258 | static struct pnp_driver tis_pnp_driver = { |
| 259 | .name = "tpm_tis", |
| 260 | .id_table = tpm_pnp_tbl, |
| 261 | .probe = tpm_tis_pnp_init, |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame] | 262 | .remove = tpm_tis_pnp_remove, |
Shuah Khan | a2fa3fb | 2013-09-11 14:23:13 -0700 | [diff] [blame] | 263 | .driver = { |
| 264 | .pm = &tpm_tis_pm, |
| 265 | }, |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 266 | }; |
| 267 | |
Kylene Jo Hall | 93e1b7d | 2006-04-22 02:39:52 -0700 | [diff] [blame] | 268 | #define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2 |
| 269 | module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id, |
| 270 | sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); |
| 271 | MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 272 | |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 273 | static struct platform_device *force_pdev; |
| 274 | |
| 275 | static int tpm_tis_plat_probe(struct platform_device *pdev) |
| 276 | { |
| 277 | struct tpm_info tpm_info = {}; |
| 278 | struct resource *res; |
| 279 | |
| 280 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 281 | if (res == NULL) { |
| 282 | dev_err(&pdev->dev, "no memory resource defined\n"); |
| 283 | return -ENODEV; |
| 284 | } |
| 285 | tpm_info.res = *res; |
| 286 | |
Jason Gunthorpe | fc0e132 | 2017-05-04 09:53:24 -0600 | [diff] [blame] | 287 | tpm_info.irq = platform_get_irq(pdev, 0); |
| 288 | if (tpm_info.irq <= 0) { |
Jason Gunthorpe | d27f81f | 2017-05-04 09:53:23 -0600 | [diff] [blame] | 289 | if (pdev != force_pdev) |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 290 | tpm_info.irq = -1; |
| 291 | else |
| 292 | /* When forcing auto probe the IRQ */ |
| 293 | tpm_info.irq = 0; |
| 294 | } |
| 295 | |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 296 | return tpm_tis_init(&pdev->dev, &tpm_info); |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static int tpm_tis_plat_remove(struct platform_device *pdev) |
| 300 | { |
| 301 | struct tpm_chip *chip = dev_get_drvdata(&pdev->dev); |
| 302 | |
| 303 | tpm_chip_unregister(chip); |
| 304 | tpm_tis_remove(chip); |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Jason Gunthorpe | 420d439 | 2016-11-07 15:44:31 -0700 | [diff] [blame] | 309 | #ifdef CONFIG_OF |
| 310 | static const struct of_device_id tis_of_platform_match[] = { |
| 311 | {.compatible = "tcg,tpm-tis-mmio"}, |
| 312 | {}, |
| 313 | }; |
| 314 | MODULE_DEVICE_TABLE(of, tis_of_platform_match); |
| 315 | #endif |
| 316 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 317 | static struct platform_driver tis_drv = { |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 318 | .probe = tpm_tis_plat_probe, |
| 319 | .remove = tpm_tis_plat_remove, |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 320 | .driver = { |
Jarkko Sakkinen | afb5abc | 2014-12-12 11:46:34 -0800 | [diff] [blame] | 321 | .name = "tpm_tis", |
Rafael J. Wysocki | b633f05 | 2012-07-06 19:09:20 +0200 | [diff] [blame] | 322 | .pm = &tpm_tis_pm, |
Jason Gunthorpe | 420d439 | 2016-11-07 15:44:31 -0700 | [diff] [blame] | 323 | .of_match_table = of_match_ptr(tis_of_platform_match), |
Jason Gunthorpe | 4cb586a | 2017-05-04 09:53:25 -0600 | [diff] [blame] | 324 | .acpi_match_table = ACPI_PTR(tpm_acpi_tbl), |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 325 | }, |
Kylene Jo Hall | 9e323d3 | 2006-07-14 00:24:31 -0700 | [diff] [blame] | 326 | }; |
| 327 | |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 328 | static int tpm_tis_force_device(void) |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 329 | { |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 330 | struct platform_device *pdev; |
| 331 | static const struct resource x86_resources[] = { |
| 332 | { |
| 333 | .start = 0xFED40000, |
| 334 | .end = 0xFED40000 + TIS_MEM_LEN - 1, |
| 335 | .flags = IORESOURCE_MEM, |
| 336 | }, |
| 337 | }; |
| 338 | |
Jarkko Sakkinen | 399235d | 2015-09-29 00:32:19 +0300 | [diff] [blame] | 339 | if (!force) |
| 340 | return 0; |
Kylene Jo Hall | 9e323d3 | 2006-07-14 00:24:31 -0700 | [diff] [blame] | 341 | |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 342 | /* The driver core will match the name tpm_tis of the device to |
| 343 | * the tpm_tis platform driver and complete the setup via |
| 344 | * tpm_tis_plat_probe |
| 345 | */ |
| 346 | pdev = platform_device_register_simple("tpm_tis", -1, x86_resources, |
| 347 | ARRAY_SIZE(x86_resources)); |
| 348 | if (IS_ERR(pdev)) |
| 349 | return PTR_ERR(pdev); |
| 350 | force_pdev = pdev; |
| 351 | |
Wei Yongjun | 4fba3c3 | 2013-04-25 15:07:47 +0800 | [diff] [blame] | 352 | return 0; |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static int __init init_tis(void) |
| 356 | { |
| 357 | int rc; |
| 358 | |
| 359 | rc = tpm_tis_force_device(); |
| 360 | if (rc) |
| 361 | goto err_force; |
| 362 | |
| 363 | rc = platform_driver_register(&tis_drv); |
| 364 | if (rc) |
| 365 | goto err_platform; |
| 366 | |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 367 | |
| 368 | if (IS_ENABLED(CONFIG_PNP)) { |
| 369 | rc = pnp_register_driver(&tis_pnp_driver); |
| 370 | if (rc) |
| 371 | goto err_pnp; |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | |
| 376 | err_pnp: |
Wei Yongjun | 5939eaf | 2017-02-07 15:51:47 +0000 | [diff] [blame] | 377 | platform_driver_unregister(&tis_drv); |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 378 | err_platform: |
| 379 | if (force_pdev) |
| 380 | platform_device_unregister(force_pdev); |
| 381 | err_force: |
Rajiv Andrade | 7f2ab00 | 2010-05-13 17:37:54 -0300 | [diff] [blame] | 382 | return rc; |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static void __exit cleanup_tis(void) |
| 386 | { |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 387 | pnp_unregister_driver(&tis_pnp_driver); |
Rajiv Andrade | 7f2ab00 | 2010-05-13 17:37:54 -0300 | [diff] [blame] | 388 | platform_driver_unregister(&tis_drv); |
Jason Gunthorpe | 0019482 | 2016-01-07 17:36:24 -0700 | [diff] [blame] | 389 | |
| 390 | if (force_pdev) |
| 391 | platform_device_unregister(force_pdev); |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | module_init(init_tis); |
| 395 | module_exit(cleanup_tis); |
| 396 | MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); |
| 397 | MODULE_DESCRIPTION("TPM Driver"); |
| 398 | MODULE_VERSION("2.0"); |
| 399 | MODULE_LICENSE("GPL"); |