From patchwork Tue Aug 16 16:14:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jorge Ramirez-Ortiz, Foundries" X-Patchwork-Id: 1666907 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foundries.io header.i=@foundries.io header.a=rsa-sha256 header.s=google header.b=diPWL9GV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4M6bpP2Jrrz1yfd for ; Wed, 17 Aug 2022 02:15:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 63C9D848F0; Tue, 16 Aug 2022 18:15:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=foundries.io Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foundries.io header.i=@foundries.io header.b="diPWL9GV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 53859848FF; Tue, 16 Aug 2022 18:15:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3879B84899 for ; Tue, 16 Aug 2022 18:14:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=foundries.io Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jorge@foundries.io Received: by mail-wm1-x329.google.com with SMTP id p12-20020a7bcc8c000000b003a5360f218fso9644448wma.3 for ; Tue, 16 Aug 2022 09:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foundries.io; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=R7cFaoWGKWqjHslMWUM3bWuQebCybdczpIm1zRXKeSg=; b=diPWL9GV2YaNXblSOPYpujOEiimEvBQTp0CGWgtM/y2em2XNZ7OA1XlD7zdaIC/R9q yuWnwYeDFCPG04rKa3OWmq+wV2zxuLVp5CM4OJ/36u50JRS97P0gFyNlv5JKI+1ERsKe 1HmrC0NDOpJduQQIHTMqr7y7Kghc/9wAREXvUn96hy4bV7rCP1WciQpG0kuSKyeDAsD5 zeycSr6jsddVnpe86k//zcgimVxzM+Us5JuWlO6KrZ+No89rVbqiu3v/fbg7trHFNMYi idJfRDq+oQzgcrzVI7nLPqW7m1X+c+a7ajJYuPqJ7feH0d10pvzsz1cCc6QlVNleCqOK zxoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=R7cFaoWGKWqjHslMWUM3bWuQebCybdczpIm1zRXKeSg=; b=y8P/duIkJiPcfx6dHx4RK/I+IzDuVIwyOZv2z3O5I8Qqf8sbceAw/GSfUr+tsk6Zdc eoj/3xAVeKnOikDlEpOl6eDPicVe7ZtJ/Wcywy1adN2PaNYUCHgqs3wMlBC2QVDlgiQ8 vCBfo6W3Lr1CiKnrfycMqZ/X4X6OuTGr5BRT/zbNioWa5WMCQdQS6gTGA6xJGbfBk8x3 siroTrE2fAtvkyHMOL40Yld5x38yJG42n+nVAuXYbb89ptOsNjDGZdZMvi90Z0gTX9Ls CzEDaesqbAF2/2HP19i7uC+yR3ZtVijuNbDBosAY8syYNPlUwjzoxtaKRz61JyABBZQP sdJg== X-Gm-Message-State: ACgBeo2f6PSFw3gTx2trzSOfkWAEBQNw27qFWp/aT698s0dGOmJa7y9L Oi/wyXF+bhmpM6jQeL2DnMSDTg== X-Google-Smtp-Source: AA6agR7sfniy540Qt1ym/Q0c4qGeCbDdp/7BnACCIWtKjravK83OGGTLEhXp2qSDZ6/WxIgU6hdOKQ== X-Received: by 2002:a1c:f019:0:b0:3a5:ac4:aff0 with SMTP id a25-20020a1cf019000000b003a50ac4aff0mr14005248wmb.164.1660666496695; Tue, 16 Aug 2022 09:14:56 -0700 (PDT) Received: from localhost.localdomain (78.red-83-60-92.dynamicip.rima-tde.net. [83.60.92.78]) by smtp.gmail.com with ESMTPSA id l14-20020a05600c4f0e00b003a1980d55c4sm14086138wmq.47.2022.08.16.09.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 09:14:56 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge@foundries.io, jens.wiklander@linaro.org, oleksandr.suvorov@foundries.io Cc: u-boot@lists.denx.de Subject: [PATCHv3] drivers: tee: i2c: support the NXP SE05x probe errata Date: Tue, 16 Aug 2022 18:14:53 +0200 Message-Id: <20220816161453.1037991-1-jorge@foundries.io> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Early instantiation of this I2C device would lock up when being probed. https://www.nxp.com/docs/en/errata/SE050_Erratasheet.pdf 3.2.2 In scenarios of detecting I2C ICs on the bus using an empty I2C frame containing only the address the SE050 will block the I2C bus. Tested on STM32MP1 Signed-off-by: Jorge Ramirez-Ortiz Acked-by: Oleksandr Suvorov --- drivers/tee/optee/Kconfig | 14 +++++++++++++ drivers/tee/optee/i2c.c | 44 +++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig index d03028070b..a80ddaed2c 100644 --- a/drivers/tee/optee/Kconfig +++ b/drivers/tee/optee/Kconfig @@ -37,6 +37,20 @@ config OPTEE_TA_SCP03 help Enables support for controlling (enabling, provisioning) the Secure Channel Protocol 03 operation in the OP-TEE SCP03 TA. + +config TEE_I2C_NXP_SE05X_ERRATA + bool "Enable NXP SE05X Errata" + select TEE_I2C_NXP_SE05X_ERRATA_IN_BUS + default n + help + This config prevents the I2C trampoline driver from probing + on every transfer. + +config TEE_I2C_NXP_SE05X_ERRATA_IN_BUS + int "I2C bus where to apply the NXP SE05X errata" + depends on TEE_I2C_NXP_SE05X_ERRATA + default 0 + endmenu endif diff --git a/drivers/tee/optee/i2c.c b/drivers/tee/optee/i2c.c index ef4e10f991..a3ea34d4a2 100644 --- a/drivers/tee/optee/i2c.c +++ b/drivers/tee/optee/i2c.c @@ -3,13 +3,18 @@ * Copyright (c) 2020 Foundries.io Ltd */ +#define LOG_CATEGORY UCLASS_I2C + #include #include #include +#include #include #include "optee_msg.h" #include "optee_private.h" +#define NXP_SE05X_ADDR 0x48 + static int check_xfer_flags(struct udevice *chip, uint tee_flags) { uint flags; @@ -30,6 +35,30 @@ static int check_xfer_flags(struct udevice *chip, uint tee_flags) return 0; } +static struct udevice *get_chip_dev(int bnum, int addr) +{ + struct udevice *chip; + struct udevice *bus; + + if (IS_ENABLED(CONFIG_TEE_I2C_NXP_SE05X_ERRATA)) { + if (bnum == CONFIG_TEE_I2C_NXP_SE05X_ERRATA_IN_BUS && + addr == NXP_SE05X_ADDR) { + if (uclass_get_device_by_seq(UCLASS_I2C, bnum, &bus)) + return NULL; + + if (i2c_get_chip(bus, addr, 0, &chip)) + return NULL; + + return chip; + } + } + + if (i2c_get_chip_for_busnum(bnum, addr, 0, &chip)) + return NULL; + + return chip; +} + void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg) { const u8 attr[] = { @@ -38,7 +67,8 @@ void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg) OPTEE_MSG_ATTR_TYPE_RMEM_INOUT, OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT, }; - struct udevice *chip_dev; + struct udevice *chip_dev = NULL; + struct tee_shm *shm; u8 *buf; int ret; @@ -56,9 +86,9 @@ void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg) if (!buf) goto bad; - if (i2c_get_chip_for_busnum((int)arg->params[0].u.value.b, - (int)arg->params[0].u.value.c, - 0, &chip_dev)) + chip_dev = get_chip_dev((int)arg->params[0].u.value.b, + (int)arg->params[0].u.value.c); + if (!chip_dev) goto bad; if (check_xfer_flags(chip_dev, arg->params[1].u.value.a)) @@ -66,10 +96,16 @@ void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg) switch (arg->params[0].u.value.a) { case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD: + log_debug("OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD %d\n", + (size_t)arg->params[2].u.rmem.size); + ret = dm_i2c_read(chip_dev, 0, buf, (size_t)arg->params[2].u.rmem.size); break; case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR: + log_debug("OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR %d\n", + (size_t)arg->params[2].u.rmem.size); + ret = dm_i2c_write(chip_dev, 0, buf, (size_t)arg->params[2].u.rmem.size); break;