From patchwork Thu Apr 7 11:18:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12805082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26059C433F5 for ; Thu, 7 Apr 2022 11:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235405AbiDGLVb (ORCPT ); Thu, 7 Apr 2022 07:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiDGLVa (ORCPT ); Thu, 7 Apr 2022 07:21:30 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD95C19533A; Thu, 7 Apr 2022 04:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649330355; bh=+8FAwpjcDILWSNDx21CKUAniktty0diX3BBBPxBxwd4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=HQ7EXUW0mimX7QIrI44zFyjDh1CIh0dfexOujOd9tC4nKczWDM7KLVMS1i8p6jjsL n5MGBhKbaC36g95F/K4g/ttes1M4KPgbXK913YLQdOBfb//D6IvP8COwOO2RnB6m7Q 3pszwSvSQ7hDnM3J1JR7Kq0Z8gxaWMsDjpJlKcDc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.23]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mn2W5-1oIwmS1vaJ-00k9ZU; Thu, 07 Apr 2022 13:19:15 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, =robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo Subject: [PATCH 1/5] tpm: add functions to set and unset the tpm chips reset state Date: Thu, 7 Apr 2022 13:18:45 +0200 Message-Id: <20220407111849.5676-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407111849.5676-1-LinoSanfilippo@gmx.de> References: <20220407111849.5676-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:vsXneH/Z/sGRwRqqSWBf86QGc9y88g1044oI/ue+S4oOjAaxNqb CZDLh+ocCxBVvKtNTa8zcPm3jvF9NTUQLid2fGsZ5JhttpSBPCAMBaJHtKkeh2/ff1GcHsh ZO/65USFf5MPdLOAEVmhmFCVLs7vwC8ujUn5iCqXZJWyisu7QthBih+rtrhgH23WBVqWYws EzsD9GVfGv8Qn2v3gA2pQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:pNlkzPablvw=:/QgYjB7n+D6+tavd5UU/LT F/d8/GAxkJ5hYiBBQlPdml3OKDzUcWGrgydsqndoVFb8NUu7jrvL2NWkl9TUrIwcQAYLlUdlq UW/pvwERv47aNxozlZe6NOa1+eTr2O79+w3p8OcOIkkrRtwScRVqwyW23ZssOrN7ar93kfTjT LcNvVc9yzVYswD4y/YPpJFzbiQ9pHLxpp5cT0XBQqSxsGWlYxTzlpekx4A0jCToaLmBG2ucX+ LEJecDdvbHE+nTrXi4F5c9CnPO51VrqYVDk49bSY5S+YizkU/Ox9E/+GH8Zc08RNqXsHPjenK /nDrK/cVEzda36HEVbGA3uIuZewzCBYyxtGZh8n37/qPxeHDBRr/V7DFgDL2pbVVMOhBM/Lj7 z0vdFdtXDGadXfa6wHZMLXtmXeXRaQv0mmJinYOmpyHRCQXW1j25WF05TpJv0iVMiiZSnWZ44 TlSL5HPJsTyIdkq2CVFo2t8hGwp/ga0c/PQz4XM81W0Al3udM8nSude3cN6m28Ry5MQyThEBs nl9wHfkx78xStox1eQk3sq6LUO+/ZdsaWaPLOh+2mmklQnXfGn/Oohi8hKYosJy7JvUf/cqqI SNaSDioYjzEl7sl47eEp3rwr8Y7DH1Pp9k2iJ6mdztpvfqwxGJJhKE2orrWd9RCJVG08VmjyA DZwsMRqHiyqtIFapu3azOpeNCgbE6paFlTJ3sj6idSs2KvUgg2rjGFZ3IFgH9vjlq6lAFtbLh iMqMscVlGfQPz7ImS5kOv+etImzn8TmUzPfAfeEq3PHTDdp6V4rmQKbW3SA69YxA27h9dOtXY 7dx3bSeEJZfqXXYRTX4mDl1hxuqB0P8xAKDjmJHV1X8TC0rHE9hCEQvGDELE/J/jli7Gf8zav lp2K7M7xoSsdqTUUymKPrJSg7bso17x7USnn8KWpTrBUiHKSyhAce77Z2E5gQrn0y2r1lzuCE Y1tH9w9s4Tew1Vj4i0tz38bqH85oimDXf4Hs/dQlMKoB6V8C3aWuwb1ljZigroZdIqotBu4f4 JBXttiQVTW3CO6zJBw/gDRBHfgMDfpuu/FppuiH+uAR58ig1CR9y+dk4oRvF2PT/cMP34JJ9C sc5OlLBhbAYMGk= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Currently it is not possible to set the tpm chips reset state from within the driver. This is problematic if the chip is still in reset after the system comes up. This may e.g. happen if the reset line is pulled into reset state by a pin configuration in the device tree. To handle this case extend tpm_tis_phy_ops by the two functions "set_reset" and "unset_reset" which may optionally be defined by a tpm driver. If defined call "unset_reset" at chip startup before the first tpm command is issued. Also if defined call "set_reset" at chip shutdown after the tpm2 shutdown command has been sent. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm-chip.c | 5 +++++ drivers/char/tpm/tpm_tis_core.c | 3 +++ drivers/char/tpm/tpm_tis_core.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 783d65fc71f0..c1b79ba9159d 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -24,6 +24,7 @@ #include #include #include "tpm.h" +#include "tpm_tis_core.h" DEFINE_IDR(dev_nums_idr); static DEFINE_MUTEX(idr_lock); @@ -286,6 +287,7 @@ static void tpm_dev_release(struct device *dev) static int tpm_class_shutdown(struct device *dev) { struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); down_write(&chip->ops_sem); if (chip->flags & TPM_CHIP_FLAG_TPM2) { @@ -297,6 +299,9 @@ static int tpm_class_shutdown(struct device *dev) chip->ops = NULL; up_write(&chip->ops_sem); + if (priv->phy_ops->set_reset) + priv->phy_ops->set_reset(priv); + return 0; } diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index dc56b976d816..11e5e045f3a7 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -952,6 +952,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_set_drvdata(&chip->dev, priv); + if (priv->phy_ops->unset_reset) + priv->phy_ops->unset_reset(priv); + rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor); if (rc < 0) return rc; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 3be24f221e32..f1a67445a5c5 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -105,6 +105,8 @@ struct tpm_tis_data { }; struct tpm_tis_phy_ops { + int (*set_reset)(struct tpm_tis_data *data); + int (*unset_reset)(struct tpm_tis_data *data); int (*read_bytes)(struct tpm_tis_data *data, u32 addr, u16 len, u8 *result); int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len, From patchwork Thu Apr 7 11:18:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12805083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99133C433FE for ; Thu, 7 Apr 2022 11:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242859AbiDGLVc (ORCPT ); Thu, 7 Apr 2022 07:21:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbiDGLVb (ORCPT ); Thu, 7 Apr 2022 07:21:31 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9726C1959E8; Thu, 7 Apr 2022 04:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649330356; bh=8+Ed4/Sk7YmKxE2+H6gLFIszmuVfpTFo89GEwLDQvjM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=gwR+Su/wKww55S5KHPTSPALQNWHweiOUgaGMbWrGLCuNFiAhhtPEu/700nmiyweCA P/kXs/5hN5HVuAsBD2XPgKD6RoX4O+RBJmCsZLEfzoiIMZVlIVNzjj5OgXMdnamP7F OrUME/68IiKxIpCYSUM1h65sB2l1fP5YSeDzEyzQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.23]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MK3W0-1nGtyf3FoE-00LV7V; Thu, 07 Apr 2022 13:19:15 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, =robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo Subject: [PATCH 2/5] dt-bindings: tpm: document reset gpio property Date: Thu, 7 Apr 2022 13:18:46 +0200 Message-Id: <20220407111849.5676-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407111849.5676-1-LinoSanfilippo@gmx.de> References: <20220407111849.5676-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:KAyX7I1H2OH3HUkDXTIoswDEn5u9rTZYqAw5z/f9OeWo7DsSyVC wzcxumnnCuyV16A9fVoudFURznMgsRjnVWH3t4GEHA+D8TYdk31iSa0wcOdGOjZxhtcKO1V y/sfoPmu+PJ+lxZIxTbL9IVcy8gsTyNWgpnj3VSZ8SoZUHH+xkyV6wNTKh/592fZEybmrWC gZe0c6u3zCwktUFUamWHA== X-UI-Out-Filterresults: notjunk:1;V03:K0:6nE/fpNYvVA=:ejbA+nLwX8F5lxNNvY6cK8 00ed0WLTTJevJMgTBP18YK69yawHfN+XhSisJ81Ojp+BqG45t3pcI+mV9VV6UluxbBu6p9MEI QK5HX/dRWJz3TbiFDy/VPnmO0DrsfZKnukuq4JknRNE/PO0oguuoyh2ZTeFxtC6orNtrTaC9x UXlveMpZmKZNsQkWjOzZ5crg8lpamfRysLGsZQVqx5R6UR+vryRHRHEH9UBp+/MYuqfWfNPFy elVmw13NbhHKiOXmOW6Zmo0BSjicgKsMebg4fqFUfcJeJdFxs6zhtLrfsYcnKU+rydhPl5s6b gpTj9CxmltveeVJy4/zYPDErP+s4AWwR5BvyVHC/TwWEetXbi+6acFW7HODL23mj+ixmmRNCY qhaXIUbJtMMkdDBB0sT3Eb2bQAvRmtCu1SROxAwNZKvySoxLPUSRVkArx2lK6AH0+Mg+tlWZH 0lNkAcKlUYP1eHjhu0oEWjLJgIUYJMK8g3DtIU2APnUTrwGCPzkbv8r9EkIaYK7L+q6B9saI3 lzT6OYZT8631AuNk0y/BQmu9NN7hamZzWTRH+eO27uT6uA2h1rmt307Y3mx4+AJDikf8idf7V NK/lDslzcngulGr8vxUuTFERkMSnQ9tT8w16eitAEu7lLjWTpYxqCiWbrZsX1wC/RObaxL/tW dETvnaEDioHt6qzUs3weOpJt/evEjZjhP7hEHIKqguPfPz2foPbwBSf208ajJxk71vh1j6OOe lXWe1R4t4uxHQcdct6EGgnL8eLeJxeNhSE8YdqDiHppZRi23lbLtqaGNEDVvv2NAmOoOBC2NT KjN8MptTu88sDaaaA0rQ2tuFZ64vf/+D54YB0cet6cI61k8+FMiMx5349wavKhxTctP0sOGY7 3g3lSekGDHLExBBdaJN25Pvjpq1LV7q7KWQUKDMibyhROk2g+HL8b2ScT6HTBd5BLI9Iakx7w xdtvMP7waQl+MDGl71RtKpO6lFGeksrBPzdNpMsadNKMaOTdyXpQf9I2ZVxOd0JPf/IbzEPIV bOM3LZ1L5I0CZgrsyUmI6e0mKgHQ/49fS1ffrqB1N3exPTG5QN3WdpZ0l5+ZUuhajkaX/2/pu QYSxiAkqfU8CkM= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Add a despription for the property "reset-gpios" which can be used to specify the gpio connected to the tpm chips reset pin. Also add an example for how to use it within the tpm node. Signed-off-by: Lino Sanfilippo --- Documentation/devicetree/bindings/security/tpm/tpm_tis_spi.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/security/tpm/tpm_tis_spi.txt b/Documentation/devicetree/bindings/security/tpm/tpm_tis_spi.txt index b800667da92b..0090a1948ca5 100644 --- a/Documentation/devicetree/bindings/security/tpm/tpm_tis_spi.txt +++ b/Documentation/devicetree/bindings/security/tpm/tpm_tis_spi.txt @@ -8,6 +8,7 @@ Required properties: Optional SoC Specific Properties: - pinctrl-names: Contains only one value - "default". - pintctrl-0: Specifies the pin control groups used for this controller. +- reset-gpios: Specifies the reset GPIO. Example (for ARM-based BeagleBoard xM with TPM_TIS on SPI4): @@ -19,5 +20,6 @@ Example (for ARM-based BeagleBoard xM with TPM_TIS on SPI4): compatible = "tcg,tpm_tis-spi"; spi-max-frequency = <10000000>; + reset-gpios = <&gpio 3 GPIO_ACTIVE_LOW>; }; }; From patchwork Thu Apr 7 11:18:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12805085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40248C433F5 for ; Thu, 7 Apr 2022 11:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244690AbiDGLVi (ORCPT ); Thu, 7 Apr 2022 07:21:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234370AbiDGLVb (ORCPT ); Thu, 7 Apr 2022 07:21:31 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BD01959F1; Thu, 7 Apr 2022 04:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649330356; bh=qXAcVdb5+U1V68gy4WuSKtITy5q5Oa2Czfs+ThvCSaY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OIgX8ZVLYVBbUVTKosMn65lDqQV7nNJbX/gyX9ND4tpdrNm9OR9+xMECcaHs61ghf +GlwhfwIO9XFovd2woM6UUy3ukyobi7n6FFcn8+z9qpuseTDg8zXO8gY3fa20rHp8m jvWkLmj5HV16IKB3M1pulz858JfUDv5e89023LOk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.23]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M89Gj-1ngZAF0f1n-005LBY; Thu, 07 Apr 2022 13:19:16 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, =robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo Subject: [PATCH 3/5] tpm: tpm_tis: get optionally defined reset gpio Date: Thu, 7 Apr 2022 13:18:47 +0200 Message-Id: <20220407111849.5676-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407111849.5676-1-LinoSanfilippo@gmx.de> References: <20220407111849.5676-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VOa6nrOx58PxejZldnp8Sgli5Ic8TJYGKO/scam+aIiW/usfP3N Z7lJIkvmgfr4kctD3RHvlgy6npl6/+HPw4t/msp3wgxHW3t2To/OYftSQzEkl2ZB6Ec0ukC nmh1U7KpzoE6W5swBS9aqbSkg9CK/8fZ6lwTozA0UUvSA5MGRA4Pkzj0d3b2o1Id/puHBxx z+MUwHuuYLdnZEJrX4ZEg== X-UI-Out-Filterresults: notjunk:1;V03:K0:7RaNUTefLq8=:PeqP0exQKrSOr4/bM+56KG DOa5bUc9oR+3w5PwlEtawLhJ5G6nw56Kn1hy7GWxJRPBfb2tGdeo3WW9DfeDtztQrpJg9as/D CG5taQ+xMg971mAnjiZpQbN6Km1lJZcnkcrNJuHGQzpm7VXTS4Vi1/tYDQRrekGGH6meJ0Bnz cNou9/PeWaEH9Nxtl+C4ynhk8CdehuUfFIeOD8cB74V3iLNlXW7q+mXnX6wTXer9KaiJ6kQAS 1C4dmTMCa9BNvWHXBT/EuXkr5csYc2hlPGnR4+mT9sfpgg4kIwXN3P8wJ/bcqDb8fTlEX5kN0 ii/S4m9r1TdHFjaUawFi6m0l2Psxz2bCfociTMHk3LrMYRSs/Sj8EVdqVKNJ+g4y/qACjCIdG qipUFN6qqt/+qrtl2PEbpHmt4df/H3Cv4654vT7pHc5Ex8KXj75Pr64CUtMdDYFo4fMGZfKFN tbGJUzQgMBKS4We/1ylch61IlFlbprhzostpXOPpyixmtNJCxYKPBc0blbVDKoy0Zp3X/MzeU eF6lh0Z7cyAp7BHkNj9taiCXs6D331m4rnMkFnRb0An/lGCdHVQ9ig3j9hTCU06rKLuzpnL6U PBg8h6y/Z9nTa/nEJ1uiJgfTPhO5THTo1Lp3FyTOmj527P0xQfjN6xZ9xuhzt2IM545FjBppU 1uuaGBPPKX5tNo62r8ZmeILK1LbbAxLQgChoMHoL6TgEcc7lfUIWPEQkVzTFYIXGOQfqrvfs+ sX4K+bQpCp0LZbAhgtjMq4oi96KfFOCK8coHUKX36DW3eR133uZtyS05CZIDsYptE3hihubaK xlai2FD1VOxntji90tRxVCnVGEQFx0AmcVFeNR45Edii7BoCKzdBEUH/CJTBtLT3X3+xRhuAl ECNHde1IPy3YTnEletTioxWkP8dM/Au8y68pAPxP7qYSFGh9cpQpWx24DbJ163y2zTi2yJBZW svH2AEq9ewzjLsIrHeFjd9wGXQLUJtSYK9PuVg487YCBteSURFU/2HUGYQQEhvKk4eup2EZrp MODTjvqNeHHocCIdOWGuxtVc1Z8vDJBIeWPcRFToYj6d1rJXALt81cR3PZxt1NjhSv49g8F54 zgj5bjOwHZnXoE= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Get the optionally specified reset gpio. This property can be set with the con-id "reset-gpios". Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 20 ++++++++++++++++++++ drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 11e5e045f3a7..89bfee3cfb18 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "tpm.h" #include "tpm_tis_core.h" @@ -919,6 +920,21 @@ static const struct tpm_class_ops tpm_tis = { .clk_enable = tpm_tis_clkrun_enable, }; +/* + * Retrieve the reset GPIO if it is defined. + */ +static int tpm_tis_get_reset_gpio(struct device *dev, struct tpm_tis_data *data) +{ + data->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(data->reset_gpio)) + return PTR_ERR(data->reset_gpio); + + if (data->reset_gpio) + gpiod_set_consumer_name(data->reset_gpio, "TPM reset"); + + return 0; +} + int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, const struct tpm_tis_phy_ops *phy_ops, acpi_handle acpi_dev_handle) @@ -952,6 +968,10 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_set_drvdata(&chip->dev, priv); + rc = tpm_tis_get_reset_gpio(dev, priv); + if (rc) + return rc; + if (priv->phy_ops->unset_reset) priv->phy_ops->unset_reset(priv); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index f1a67445a5c5..502816d91353 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -94,6 +94,7 @@ struct tpm_tis_data { int irq; bool irq_tested; unsigned long flags; + struct gpio_desc *reset_gpio; void __iomem *ilb_base_addr; u16 clkrun_enabled; wait_queue_head_t int_queue; From patchwork Thu Apr 7 11:18:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12805086 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F836C433EF for ; Thu, 7 Apr 2022 11:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244712AbiDGLVj (ORCPT ); Thu, 7 Apr 2022 07:21:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234990AbiDGLVb (ORCPT ); Thu, 7 Apr 2022 07:21:31 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97E2F195D89; Thu, 7 Apr 2022 04:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649330356; bh=5/6ZzUueHS3SF2yHi16HZRPFVZW5IvH0j1r8wVbaYU0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=H3la3kpTpg4Z7uOzU0ZQHQenpdBHeB5IDlmTgTean2DfC7LOJuEEYSF4L+riovkIy 0cWqenq7eMaTwGdK+mX/MIsF7PK/Cg5UjvjZMR8Uy+OkYzi2TMizC8QTISoQaQY1Wg sZtl9nHKmRd2JNzw93qBIDzovgq+u5WSj4jTTQ2A= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.23]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MplXz-1oLhfN1wzN-00qBBW; Thu, 07 Apr 2022 13:19:16 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, =robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo Subject: [PATCH 4/5] tpm: tpm_tis: make functions available for external linkage Date: Thu, 7 Apr 2022 13:18:48 +0200 Message-Id: <20220407111849.5676-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407111849.5676-1-LinoSanfilippo@gmx.de> References: <20220407111849.5676-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:p5yGYHiR+LCe1gVoENeZriGuaH9Er4iA4m9Xa6QqaP/T7wAg51g ssafnceBC/S1gKqum8GjJA4guPukkYT14wZ65DXs5IrJ5ijaVZUKm5e2xsfQ8q3sxjGqp3Q aFxQDOl6+qTJE0Q4YK9JZeUV6SGwcKH7O5q7F6kW1rb51fEQ8qydzKn0WHz2abJIhhYjI3T Ts3cIhZ1fNYX2Po0p9QTw== X-UI-Out-Filterresults: notjunk:1;V03:K0:JWUi0rCOfiE=:2RHflXSnANxWyD6/rzfIIc Bjcsri+a9CzRXO2QpsUdmHFB9uWQor73qr4vxgcfYam7ybqNDDDaCWwE8SP9NVvQGmoBTKbQ9 fi0x46shfJt8DH1YMXRurg2JBZY/P4LhHP8mmYPmF5kM+lMIpM3qNGauI1d8E6Gc4mspiM+AB HEs64pDImgNAgNqss/fxjq5CSQqDPFWjbwEgXIiwHR7yVdcmkmpxhkDdqK92GNRWehYL+eC7K wGAk/oziryvcAe0scvWvbwD4hKSop8OyXBqqWeJFNHHO1PEzcaAUSjlI2czzO1svCYZNQbckz cHgAWxlRgoPWnybt7tPorhseElEko3ZpBf21GFKtuYLgmcw/rmbC0mzXQ3OtPfMlYyFMVUPqH ywH+18zITO5RaXM6S3yMuxY19h5M07dJMob+KAf+FEDlIUKYJep7WTWKFd1B+2H15Y++T44DB 0xHAyJ9ruZhtSJjdZ7KzQGieRi75hjAP8VdOofKtimG5Gg4OEhRug7yb/LkZbD28TClWNtmNz gLv+MqTMmBdMg150Risap3EfLvLwJMxdalwzcxNK4iiadSbMD7uLGI1yMIpgBCcB98sRBlxHH OgRfv1q57Ms1ZA0aKl/xrnvNTXPVJ2Co3k9fjr7xvqF9tED2pMnOT1yZIorNioNsFxtP8X9oA hf4XKqnYzVwRYcGAPHpByaWTCIGV9sovGHP+V1gMrSXD3U9DxSiwqFgQcVTLFAFCrdZ7MItjj rPBwpwzkri7gq2qOYjD6QEiHpguBO9P6NGUABuSFcdRp9DnKR0yXw59cxWcaoMSezvV8Q/GvU eLKVnSYy0E1U8MZOvcnE0gBz2caFlA1I6Kv/Oqo5DYcp1uzh3+m5cOekFMmQvHj9w8WiGpaCm K8GBqxAGeHLazD3uremT4KsLaDviyF132fXIIoldBoxlZNFH8gkK1BpD8G05AXmWrWLHIIMu+ ClGdTLZAwtfhZ6wTmFL5WClKp+qfBrq3QGyhMyWtfvaRmeIbTmTo21BjQOrziStxdppcf6/mA 00NIiFH7W6rGjBYk4Rbhqa+YKz/+qPA7VSZDs5DcZ0N1hYMLhodCrV7EIBFPC9Q9bY5URxAON 6hkas4z2PlDjXQ= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The tpm_tis_phy_ops functions tpm_tis_spi_read16, tpm_tis_spi_read32 and tpm_tis_spi_write32 are already declared extern to be used outside of tpm_tim_spi_main.c. Do the same with tpm_tis_spi_read_bytes and tpm_tis_spi_write_bytes to allow the external access to the complete set of tpm_tis_phy_ops. This is in preparation of the assignment of SLB9670 specific phy ops in a separate file. Furthermore declare tpm_tis_spi_flow_control extern, so that we can use it in a SLB9670 specific probe function in the same file. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_spi.h | 7 +++++++ drivers/char/tpm/tpm_tis_spi_main.c | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_spi.h b/drivers/char/tpm/tpm_tis_spi.h index bba73979c368..8f4331d8a4dd 100644 --- a/drivers/char/tpm/tpm_tis_spi.h +++ b/drivers/char/tpm/tpm_tis_spi.h @@ -25,6 +25,9 @@ static inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *da return container_of(data, struct tpm_tis_spi_phy, priv); } +extern int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, + struct spi_transfer *spi_xfer); + extern int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy, int irq, const struct tpm_tis_phy_ops *phy_ops); @@ -34,6 +37,10 @@ extern int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, extern int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result); extern int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result); extern int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value); +extern int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len, + u8 *result); +extern int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len, + const u8 *value); #ifdef CONFIG_TCG_TIS_SPI_CR50 extern int cr50_spi_probe(struct spi_device *spi); diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c index 184396b3af50..b2d13b844659 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -45,8 +45,8 @@ * * [1] https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profile-ptp-specification/ */ -static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, - struct spi_transfer *spi_xfer) +int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, + struct spi_transfer *spi_xfer) { struct spi_message m; int ret, i; @@ -140,14 +140,14 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, return ret; } -static int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr, - u16 len, u8 *result) +int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len, + u8 *result) { return tpm_tis_spi_transfer(data, addr, len, result, NULL); } -static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr, - u16 len, const u8 *value) +int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len, + const u8 *value) { return tpm_tis_spi_transfer(data, addr, len, NULL, value); } From patchwork Thu Apr 7 11:18:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12805084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28AC3C433F5 for ; Thu, 7 Apr 2022 11:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244241AbiDGLVe (ORCPT ); Thu, 7 Apr 2022 07:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233973AbiDGLVb (ORCPT ); Thu, 7 Apr 2022 07:21:31 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97A381959F0; Thu, 7 Apr 2022 04:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649330357; bh=1zrH+Ig9KZGn6a8jMH9j/YTpYklf3j0vedc54T6FD0M=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Cy5icd4tSFxtPW3R2ttANLK793/56WcdmmVC/yQAJ5+i3l8/lzx1WsbmzJ7J0eIgf K6JDeAIi9Cxgq8NUmGNd1CaeX0Tc9BKRqSMPFNFzYTI1emvvt0qhnwLcuwuiNtr/7g BGvebzDwZy5ofeUAznJRAV2DQYs57N7wkQkUvQNo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.23]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M8QWA-1ngq0q3K3U-004WEt; Thu, 07 Apr 2022 13:19:16 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, =robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo Subject: [PATCH 5/5] tpm: tpm_tis_spi_slb_9670: implement set_reset and unset_reset functions Date: Thu, 7 Apr 2022 13:18:49 +0200 Message-Id: <20220407111849.5676-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407111849.5676-1-LinoSanfilippo@gmx.de> References: <20220407111849.5676-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:FzMuKNvm6dS35SO6rkbhftmjLdUeXo2aqe2ZmdcqrQqrf0MokiI shHN1DzUjcnCv78nR1ksVywGQmCb5tjnexe8hVPeubK5GlAwxVPP3q9jqhMfCboQ60TO2I1 Gg8xYp6+2keopdrgJZwLSZZHLrTGRCZLsZ5Xt982SK2jxoPsXwCaxw0Jijm5KxfMn1MZw9H 6U1XuqVNTewXGyYcrqShw== X-UI-Out-Filterresults: notjunk:1;V03:K0:RIsNoZL7xWc=:8ygGBqWgNrkvYQpNvAyFzl OdpNnF52cSDMXnvcn5h57tBlwfo2L90zLjgUpyRnvIcBN4rNYEkKIgSazM3v6jDxwDsoyWYKc TcodKbGjPav5EZPnTv34v1zHjcP+W2k0jauNR5Kerqis4rXC4KDBhIUBRhm+aX+sXiK6xhlhb QuRK+yFCGDtXJSS6ylaSeW5dOqzHsPgyJFwHdfsAM8+3hvuKh6/E/cn7UQrDlBVgdTJXUeQbY nqkDFfHCd4RhHtloNCV0SkTbSSu4IOgaVy8XmAfwU6QMOWPRZGbrY2xPSk91RmAl4hlM3duK0 Qp8ufMIiG6576XG8MeF8MD38UfhMXDid6Vi45iQgFY2GNKaaHEgu8xjTYwLbnqVb9cYaDeN42 FQjqhw1I/HJGCSyK4Jt9+zPofk11htqq063x8yZaBQdqJbaRzkrNnE5K0betp94X/Tf/uRfRn M7nZ8ePilYcKCjZ+ZUH8OI9bDYweXKoiR5r4yY9F5VKywqAIRjG4bx4ogUvOIaJIQYjEr2ewz BILMDNQAdzK28m7HVsR+MvAbrr4uyuJaSuLuDyJdlA/f5P6PnGQJzn0InFcbu05K53kQjwV3Q saOpu7m6QENjujWkN6bCoi5tiVNLxrln2tGMaLWTBm7W3hNdaxmUv3rqJa6qVHPfFedoFekYZ mZymW4UaaP04cCjzXylnE+YMtEMJVzJq910oKTTW3Xg1nTribr18Ivk0xbVyn4v58+HuaIqmE 0rd6eNfqAVMl/Yp5bLcHc4YvYJ4USGvvOeLrio7ZK3Mmoomd1Xs5Mi6AGx8gPWxjH8evXbTaU NR9WTylJl83LJIvIWsgvHlshhYrBkFGCAbaOVwgMHVM8jQiv3QQELOl7+qR764bOZfU/cstzH D/DWtzyOz2XGHopShDd0iFegqRpeUzH841T8xmdbrwhAmGdk2CEupOJL69zF6luhisWZ3U/yj 3ezj8dYuyxST5nOHcLwDtomAh1t6N5/oi3qV7byA8UXHx09W7vD5QAgLYWRnWhfd0I3pZZ76Z /ULt0+nKxC8vPP+bXvfkGwFkh/FeQbsA4yDhaV3HwXHeJDVQxykKMnEfqXkBHj0lL2K1rKltH zj94hhKx+OQ98o= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Provide implementations for the tpm phy operations set_reset and unset_reset. Taking the chip out of reset requires a certain sequence of line assertions and deassertions with respective minimum wait intervals: deassert RST wait at least 60 ms assert RST wait at least 2 usecs deassert RST wait at least 60 ms assert RST wait at least 2 usecs deassert RST wait at least 60 ms before issuing the first TPM command According to the Infineon SLB 9670VQ2.0 datasheet this sequence is needed to avoid triggering the chips defense modes in which it protects itself from dictionary attacks in conjunction with resets. Since the generic probe function tpm_tis_spi_probe only sets the non-optional phy ops provide a custom version in which also set_reset and unset_reset are assigned. Move the implementation of these functions into a new file to separate the SLB9670 specific code from the generic code. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_tis_spi.h | 2 + drivers/char/tpm/tpm_tis_spi_main.c | 4 +- drivers/char/tpm/tpm_tis_spi_slb9670.c | 82 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 drivers/char/tpm/tpm_tis_spi_slb9670.c diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile index 66d39ea6bd10..22c82eb4e382 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_TCG_TIS_SYNQUACER) += tpm_tis_synquacer.o obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o tpm_tis_spi-y := tpm_tis_spi_main.o +tpm_tis_spi-y += tpm_tis_spi_slb9670.o tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o diff --git a/drivers/char/tpm/tpm_tis_spi.h b/drivers/char/tpm/tpm_tis_spi.h index 8f4331d8a4dd..b90848832da4 100644 --- a/drivers/char/tpm/tpm_tis_spi.h +++ b/drivers/char/tpm/tpm_tis_spi.h @@ -51,6 +51,8 @@ static inline int cr50_spi_probe(struct spi_device *spi) } #endif +extern int slb9670_spi_probe(struct spi_device *spi); + #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_TCG_TIS_SPI_CR50) extern int tpm_tis_spi_resume(struct device *dev); #else diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c index b2d13b844659..50da1f6eeaea 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -264,7 +264,7 @@ static void tpm_tis_spi_remove(struct spi_device *dev) static const struct spi_device_id tpm_tis_spi_id[] = { { "st33htpm-spi", (unsigned long)tpm_tis_spi_probe }, - { "slb9670", (unsigned long)tpm_tis_spi_probe }, + { "slb9670", (unsigned long)slb9670_spi_probe }, { "tpm_tis_spi", (unsigned long)tpm_tis_spi_probe }, { "tpm_tis-spi", (unsigned long)tpm_tis_spi_probe }, { "cr50", (unsigned long)cr50_spi_probe }, @@ -274,7 +274,7 @@ MODULE_DEVICE_TABLE(spi, tpm_tis_spi_id); static const struct of_device_id of_tis_spi_match[] = { { .compatible = "st,st33htpm-spi", .data = tpm_tis_spi_probe }, - { .compatible = "infineon,slb9670", .data = tpm_tis_spi_probe }, + { .compatible = "infineon,slb9670", .data = slb9670_spi_probe }, { .compatible = "tcg,tpm_tis-spi", .data = tpm_tis_spi_probe }, { .compatible = "google,cr50", .data = cr50_spi_probe }, {} diff --git a/drivers/char/tpm/tpm_tis_spi_slb9670.c b/drivers/char/tpm/tpm_tis_spi_slb9670.c new file mode 100644 index 000000000000..ba9cd54e8bff --- /dev/null +++ b/drivers/char/tpm/tpm_tis_spi_slb9670.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * tpm_tis_spi_slb9670.c + * + * Copyright (C) 2022 KUNBUS GmbH + * + */ + +#include +#include +#include + +#include "tpm_tis_core.h" +#include "tpm_tis_spi.h" + +/* + * Time intervals used in the reset sequence. + * RSTIN: minimum time to hold the reset line deasserted. + * WRST: minimum time to hold the reset line asserted. + */ +#define SLB9670_TIME_RSTIN 60 /* time in ms */ +#define SLB9670_TIME_WRST 2 /* time in usecs */ + +int slb9670_spi_unset_reset(struct tpm_tis_data *data) +{ + /* + * Perform the reset sequence: we have to deassert and assert the reset + * line two times and wait the respective time intervals. + * After a last wait interval of RSTIN the chip is ready to receive the + * first command. + */ + gpiod_set_value(data->reset_gpio, 0); + msleep(SLB9670_TIME_RSTIN); + gpiod_set_value(data->reset_gpio, 1); + udelay(SLB9670_TIME_WRST); + gpiod_set_value(data->reset_gpio, 0); + msleep(SLB9670_TIME_RSTIN); + gpiod_set_value(data->reset_gpio, 1); + udelay(SLB9670_TIME_WRST); + gpiod_set_value(data->reset_gpio, 0); + msleep(SLB9670_TIME_RSTIN); + + return 0; +} + +int slb9670_spi_set_reset(struct tpm_tis_data *data) +{ + gpiod_set_value(data->reset_gpio, 1); + return 0; +} + +static const struct tpm_tis_phy_ops slb9670_spi_phy_ops = { + .read_bytes = tpm_tis_spi_read_bytes, + .write_bytes = tpm_tis_spi_write_bytes, + .read16 = tpm_tis_spi_read16, + .read32 = tpm_tis_spi_read32, + .write32 = tpm_tis_spi_write32, + .set_reset = slb9670_spi_set_reset, + .unset_reset = slb9670_spi_unset_reset, +}; + +int slb9670_spi_probe(struct spi_device *spi) +{ + struct tpm_tis_spi_phy *phy; + int irq; + + phy = devm_kzalloc(&spi->dev, sizeof(struct tpm_tis_spi_phy), + GFP_KERNEL); + if (!phy) + return -ENOMEM; + + phy->flow_control = tpm_tis_spi_flow_control; + + /* If the SPI device has an IRQ then use that */ + if (spi->irq > 0) + irq = spi->irq; + else + irq = -1; + + init_completion(&phy->ready); + return tpm_tis_spi_init(spi, phy, irq, &slb9670_spi_phy_ops); +}