From patchwork Wed Apr 13 19:55:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Ricard X-Patchwork-Id: 8827411 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C95629F36E for ; Wed, 13 Apr 2016 19:56:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3E3820357 for ; Wed, 13 Apr 2016 19:56:21 +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 8D27E20379 for ; Wed, 13 Apr 2016 19:56:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aqQtf-0002N9-FB; Wed, 13 Apr 2016 19:56:19 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aqQte-0002Mz-G3 for tpmdd-devel@lists.sourceforge.net; Wed, 13 Apr 2016 19:56:18 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of gmail.com designates 74.125.82.65 as permitted sender) client-ip=74.125.82.65; envelope-from=christophe.ricard@gmail.com; helo=mail-wm0-f65.google.com; Received: from mail-wm0-f65.google.com ([74.125.82.65]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1aqQtZ-0003lC-MK for tpmdd-devel@lists.sourceforge.net; Wed, 13 Apr 2016 19:56:18 +0000 Received: by mail-wm0-f65.google.com with SMTP id a140so17042002wma.2 for ; Wed, 13 Apr 2016 12:56:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2krwiIFv1eTr2W4jWhO+td2I3MNftaM9N1hys0rgaWU=; b=JRYG2p3CdO82EEcG50cS3LPkXyl8qYDVXfGVbI+sI20fBUrgiH9ZfcxjQtJN4Kg1e2 uSW1S3690YTb5OvHSnPB6jnGnTX521DPWhtI9UtJb5sCWJinr8Ie6ODSNRpmK7ztwaU1 oIYk2eZsrV1nrO6MdMT0kqLacpM5vZPXZyl9cFcHL1cDSFLLf7lgrnoMzZm1OuWfaaoK P9Rqlf/PIV14FPixCKAv5DIcPPEi5TYhH4YUebmwv+7swIelVJ2NYD4KmnEZ6k4IQ6H0 E5TkKcTNFUkeXdNYN2oE4Y5d6X8leTNSUXHNKO9+q6MQeGKc3Nv68WAuVCV40E9rz1EA ZkFw== X-Gm-Message-State: AOPr4FVDg1vQ7gEwHXDnY34lej0XCgZby+XHeH0xWeJg90GlUMHfT5OUCyf3QVkXZdVnnw== X-Received: by 10.194.202.195 with SMTP id kk3mr11544262wjc.159.1460577367702; Wed, 13 Apr 2016 12:56:07 -0700 (PDT) Received: from localhost.localdomain (ax113-6-78-236-204-66.fbx.proxad.net. [78.236.204.66]) by smtp.gmail.com with ESMTPSA id 202sm10488911wmw.5.2016.04.13.12.56.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 12:56:06 -0700 (PDT) From: Christophe Ricard X-Google-Original-From: Christophe Ricard To: jarkko.sakkinen@linux.intel.com Date: Wed, 13 Apr 2016 21:55:44 +0200 Message-Id: <1460577351-24632-6-git-send-email-christophe-h.ricard@st.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460577351-24632-1-git-send-email-christophe-h.ricard@st.com> References: <1460577351-24632-1-git-send-email-christophe-h.ricard@st.com> X-Spam-Score: -1.6 (-) X-Headers-End: 1aqQtZ-0003lC-MK Cc: jean-luc.blanc@st.com, ashley@ashleylai.com, tpmdd-devel@lists.sourceforge.net, christophe-h.ricard@st.com, benoit.houyere@st.com Subject: [tpmdd-devel] [PATCH v2 05/12] tpm: Use read/write_bytes for drivers without more specialized methods 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: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,HK_RANDOM_ENVFROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Some drivers might choose to implement only functions for transferring an arbitrary number of bytes, without special handling of word or dword transfers. Signed-off-by: Alexander Steffen Signed-off-by: Christophe Ricard --- drivers/char/tpm/tpm_tis_core.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index b0f1e3c..732f305 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -65,15 +65,31 @@ static inline int tpm_read8(struct tpm_chip *chip, u32 addr, u8 *result) static inline int tpm_read16(struct tpm_chip *chip, u32 addr, u16 *result) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + int rc; - return priv->lowlevel->read16(chip, addr, result); + if (priv->lowlevel->read16) + return priv->lowlevel->read16(chip, addr, result); + + rc = priv->lowlevel->read_bytes(chip, addr, sizeof(u16), (u8 *)result); + if (!rc) + *result = le16_to_cpu(*result); + + return rc; } static inline u32 tpm_read32(struct tpm_chip *chip, u32 addr, u32 *result) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + int rc; + + if (priv->lowlevel->read32) + return priv->lowlevel->read32(chip, addr, result); - return priv->lowlevel->read32(chip, addr, result); + rc = priv->lowlevel->read_bytes(chip, addr, sizeof(u32), (u8 *)result); + if (!rc) + *result = le32_to_cpu(*result); + + return rc; } static inline int tpm_write_bytes(struct tpm_chip *chip, u32 addr, u16 len, @@ -95,7 +111,12 @@ static inline int tpm_write32(struct tpm_chip *chip, u32 addr, u32 value) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - return priv->lowlevel->write32(chip, addr, value); + if (priv->lowlevel->write32) + return priv->lowlevel->write32(chip, addr, value); + + value = cpu_to_le32(value); + return priv->lowlevel->write_bytes(chip, addr, sizeof(u32), + (u8 *)&value); } #endif