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

tpm: Add TPM 2.0 support to the Nuvoton i2c driver (NPCT6xx family)

The command flow is exactly the same, the core simply needs to be
told to enable TPM2 mode when the compatible string indicates a
TPM2.

Signed-off-by: Andrew Azmansky <andrew.zamansky@nuvoton.com>
Tested-by: Andrew Zamansky <andrew.zamansky@nuvoton.com>
Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Acked-by: Rob Herring <robh@kernel.org>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

authored by

Jason Gunthorpe and committed by
Jarkko Sakkinen
82cc1a49 cae8b441

+21 -6
+1
Documentation/devicetree/bindings/i2c/trivial-devices.txt
··· 62 62 national,lm85 Temperature sensor with integrated fan control 63 63 national,lm92 ±0.33°C Accurate, 12-Bit + Sign Temperature Sensor and Thermal Window Comparator with Two-Wire Interface 64 64 nuvoton,npct501 i2c trusted platform module (TPM) 65 + nuvoton,npct601 i2c trusted platform module (TPM2) 65 66 nxp,pca9556 Octal SMBus and I2C registered interface 66 67 nxp,pca9557 8-bit I2C-bus and SMBus I/O port with reset 67 68 nxp,pcf8563 Real-time clock/calendar
+20 -6
drivers/char/tpm/tpm_i2c_nuvoton.c
··· 1 - /****************************************************************************** 2 - * Nuvoton TPM I2C Device Driver Interface for WPCT301/NPCT501, 1 + /****************************************************************************** 2 + * Nuvoton TPM I2C Device Driver Interface for WPCT301/NPCT501/NPCT6XX, 3 3 * based on the TCG TPM Interface Spec version 1.2. 4 4 * Specifications at www.trustedcomputinggroup.org 5 5 * ··· 31 31 #include <linux/interrupt.h> 32 32 #include <linux/wait.h> 33 33 #include <linux/i2c.h> 34 + #include <linux/of_device.h> 34 35 #include "tpm.h" 35 36 36 37 /* I2C interface offsets */ ··· 53 52 #define TPM_I2C_RETRY_DELAY_SHORT 2 /* msec */ 54 53 #define TPM_I2C_RETRY_DELAY_LONG 10 /* msec */ 55 54 56 - #define I2C_DRIVER_NAME "tpm_i2c_nuvoton" 55 + #define OF_IS_TPM2 ((void *)1) 56 + #define I2C_IS_TPM2 1 57 57 58 58 struct priv_data { 59 59 int irq; ··· 167 165 } 168 166 169 167 /* 170 - * WPCT301/NPCT501 SINT# supports only dataAvail 168 + * WPCT301/NPCT501/NPCT6XX SINT# supports only dataAvail 171 169 * any call to this function which is not waiting for dataAvail will 172 170 * set queue to NULL to avoid waiting for interrupt 173 171 */ ··· 547 545 if (!priv) 548 546 return -ENOMEM; 549 547 548 + if (dev->of_node) { 549 + const struct of_device_id *of_id; 550 + 551 + of_id = of_match_device(dev->driver->of_match_table, dev); 552 + if (of_id && of_id->data == OF_IS_TPM2) 553 + chip->flags |= TPM_CHIP_FLAG_TPM2; 554 + } else 555 + if (id->driver_data == I2C_IS_TPM2) 556 + chip->flags |= TPM_CHIP_FLAG_TPM2; 557 + 550 558 init_waitqueue_head(&priv->read_queue); 551 559 552 560 /* Default timeouts */ ··· 632 620 } 633 621 634 622 static const struct i2c_device_id i2c_nuvoton_id[] = { 635 - {I2C_DRIVER_NAME, 0}, 623 + {"tpm_i2c_nuvoton"}, 624 + {"tpm2_i2c_nuvoton", .driver_data = I2C_IS_TPM2}, 636 625 {} 637 626 }; 638 627 MODULE_DEVICE_TABLE(i2c, i2c_nuvoton_id); ··· 642 629 static const struct of_device_id i2c_nuvoton_of_match[] = { 643 630 {.compatible = "nuvoton,npct501"}, 644 631 {.compatible = "winbond,wpct301"}, 632 + {.compatible = "nuvoton,npct601", .data = OF_IS_TPM2}, 645 633 {}, 646 634 }; 647 635 MODULE_DEVICE_TABLE(of, i2c_nuvoton_of_match); ··· 655 641 .probe = i2c_nuvoton_probe, 656 642 .remove = i2c_nuvoton_remove, 657 643 .driver = { 658 - .name = I2C_DRIVER_NAME, 644 + .name = "tpm_i2c_nuvoton", 659 645 .pm = &i2c_nuvoton_pm_ops, 660 646 .of_match_table = of_match_ptr(i2c_nuvoton_of_match), 661 647 },