From patchwork Sun Mar 20 08:02:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrew.zamansky@nuvoton.com X-Patchwork-Id: 8646761 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 60AD8C0553 for ; Wed, 23 Mar 2016 02:14:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C0092038A for ; Wed, 23 Mar 2016 02:14:49 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73E6F2037F for ; Wed, 23 Mar 2016 02:14:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aiYJp-0008FA-1g; Wed, 23 Mar 2016 02:14:45 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ahYYx-0005ts-5u for tpmdd-devel@lists.sourceforge.net; Sun, 20 Mar 2016 08:18:15 +0000 Received: from maillog.nuvoton.com ([202.39.227.15]) by sog-mx-1.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1ahYYv-0001IF-3P for tpmdd-devel@lists.sourceforge.net; Sun, 20 Mar 2016 08:18:15 +0000 Received: from nthcims04.nuvoton.com (nthcims04.nuvoton.com [10.1.8.200]) by maillog.nuvoton.com (Postfix) with ESMTP id 64AE81C803A2; Sun, 20 Mar 2016 16:03:03 +0800 (CST) Received: from NTILML02.nuvoton.com (10.190.1.46) by nthcims04.nuvoton.com (10.1.8.200) with Microsoft SMTP Server (TLS) id 8.3.327.1; Sun, 20 Mar 2016 16:03:03 +0800 Received: from NTILML02.nuvoton.com (10.190.1.46) by NTILML02.nuvoton.com (10.190.1.46) with Microsoft SMTP Server (TLS) id 15.0.1130.7; Sun, 20 Mar 2016 10:02:59 +0200 Received: from NTILML02.nuvoton.com ([::1]) by NTILML02.nuvoton.com ([::1]) with mapi id 15.00.1130.005; Sun, 20 Mar 2016 10:02:59 +0200 From: To: , Thread-Topic: [PATCH 1/1] tpm: add tpm 2.0 support to nuvoton chips on i2c bus Thread-Index: AdGCfrogxihwjVfJSCeK/gOUy5PxrQ== Date: Sun, 20 Mar 2016 08:02:58 +0000 Message-ID: <510d6333a3fc49b297a82bd69c89a05e@NTILML02.nuvoton.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.191.10.97] MIME-Version: 1.0 X-Spam-Score: -0.0 (/) X-Headers-End: 1ahYYv-0001IF-3P X-Mailman-Approved-At: Wed, 23 Mar 2016 02:14:44 +0000 Cc: Dan.Morav@nuvoton.com, Eyal.Cohen@nuvoton.com, tpmdd-devel@lists.sourceforge.net, gcwilson@us.ibm.com, shmulik.hager@nuvoton.com Subject: [tpmdd-devel] [PATCH 1/1] tpm: add tpm 2.0 support to nuvoton chips on i2c bus X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP >From 40c94ed59330638da05932d14b91ebe886c4d33c Mon Sep 17 00:00:00 2001 From: andrew azmansky Date: Sun, 20 Mar 2016 09:01:46 +0200 Subject: [PATCH 1/1] tpm: add tpm 2.0 support to nuvoton chips on i2c bus prob of tpm_i2c_nuvoton check if chip tpm support tpm 2.0 specification . if chip support tpm 2.0 then run tmp 2.0 selftest and set timeouts according tpm 2.0 . otherwise run tpm 1.2 selftest and set timeouts according to tpm 1.2 Signed-off-by: andrew azmansky --- drivers/char/tpm/tpm_i2c_nuvoton.c | 48 ++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 7 deletions(-) -- 1.9.1 =========================================================================================== The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton. ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c index 847f159..4263911 100644 --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -138,7 +138,8 @@ static void i2c_nuvoton_ready(struct tpm_chip *chip) } /* read burstCount field from TPM_STS register - * return -1 on fail to read */ + * return -1 on fail to read +*/ static int i2c_nuvoton_get_burstcount(struct i2c_client *client, struct tpm_chip *chip) { @@ -170,6 +171,7 @@ static int i2c_nuvoton_get_burstcount(struct i2c_client *client, static bool i2c_nuvoton_check_status(struct tpm_chip *chip, u8 mask, u8 value) { u8 status = i2c_nuvoton_read_status(chip); + return (status != TPM_STS_ERR_VAL) && ((status & mask) == value); } @@ -188,7 +190,8 @@ static int i2c_nuvoton_wait_for_stat(struct tpm_chip *chip, u8 mask, u8 value, if (rc > 0) return 0; /* At this point we know that the SINT pin is asserted, so we - * do not need to do i2c_nuvoton_check_status */ + * do not need to do i2c_nuvoton_check_status +*/ } else { unsigned long ten_msec, stop; bool status_valid; @@ -469,7 +472,8 @@ static const struct tpm_class_ops tpm_i2c = { * the interrupt is currently being asserted. The driver does not do any * processing triggered by interrupts, and the chip provides no way to mask at * the source (plus that would be slow over I2C). Run the IRQ as a one-shot, - * this means it cannot be shared. */ + * this means it cannot be shared. +*/ static irqreturn_t i2c_nuvoton_int_handler(int dummy, void *dev_id) { struct tpm_chip *chip = dev_id; @@ -552,7 +556,8 @@ static int i2c_nuvoton_probe(struct i2c_client *client, * I2C intfcaps (interrupt capabilitieis) in the chip are hard coded to: * TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT * The IRQ should be set in the i2c_board_info (which is done - * automatically in of_i2c_register_devices, for device tree users */ + * automatically in of_i2c_register_devices, for device tree users +*/ chip->vendor.irq = client->irq; if (chip->vendor.irq) { @@ -601,10 +606,38 @@ static int i2c_nuvoton_probe(struct i2c_client *client, } } -if (tpm_get_timeouts(chip)) -return -ENODEV; +rc = tpm2_probe(chip); +if (rc) +return rc; -if (tpm_do_selftest(chip)) +if (chip->flags & TPM_CHIP_FLAG_TPM2) { +chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); +chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); +chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); +chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); +chip->vendor.duration[TPM_SHORT] = +msecs_to_jiffies(TPM2_DURATION_SHORT); +chip->vendor.duration[TPM_MEDIUM] = +msecs_to_jiffies(TPM2_DURATION_MEDIUM); +chip->vendor.duration[TPM_LONG] = +msecs_to_jiffies(TPM2_DURATION_LONG); + +rc = tpm2_do_selftest(chip); +if (rc == TPM2_RC_INITIALIZE) { +if (tpm2_startup(chip, TPM2_SU_CLEAR)) +return -ENODEV; + +rc = tpm2_do_selftest(chip); +} + +} else { +if (tpm_get_timeouts(chip)) +return -ENODEV; + +rc = tpm_do_selftest(chip); +} + +if (rc) return -ENODEV; return tpm_chip_register(chip); @@ -614,6 +647,7 @@ static int i2c_nuvoton_remove(struct i2c_client *client) { struct device *dev = &(client->dev); struct tpm_chip *chip = dev_get_drvdata(dev); + tpm_chip_unregister(chip); return 0; }