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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3BC1AC3DA6E for ; Mon, 8 Jan 2024 16:58:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 799D787AAD; Mon, 8 Jan 2024 17:58:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=bootlin.com 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=bootlin.com header.i=@bootlin.com header.b="gGpR7Vz8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB28887AB1; Mon, 8 Jan 2024 17:58:19 +0100 (CET) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0BC9587AAD for ; Mon, 8 Jan 2024 17:58:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=thomas.richard@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 899DFFF803; Mon, 8 Jan 2024 16:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1704733097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tPrY5mw615o0ZDyi2YN23uoxXcL1Ky8xpTyZBcA8vNA=; b=gGpR7Vz8ac4vXoFrtNVIN61EQBIOaoH1+c95vbiyyqpsZnRBHa9QkOZJkkFOYNUA3QVAGG Nim4NTeXVAp/xclCLsQJomnHmxNgIbD4vaDRgocsLQA/X0/BIQmaTgCltZE08lCsgsxC6e FrS/A7l3yyX4Nr5DEarSPB5ue+3Bgx2d2zbbaygew0udMix1kZDlOvy+tIBmmhcLz/Ccf1 67zD1uxa8BVnFtajzuVRFj/LR7ITRzGEayoavgbLisNJhGcHJS33/7PDb/WrJ2aJ1OyED0 NCJKIfQwxDFTkIN4Si7dvqW8D3sR8ZSTNbG4YSNqaH0BK4NdhWnNtgQKTC62HA== From: Thomas Richard To: u-boot@lists.denx.de Cc: thomas.petazzoni@bootlin.com, thomas.richard@bootlin.com, nm@ti.com, u-kumar1@ti.com, gregory.clement@bootlin.com, Tom Rini Subject: [PATCH v3 4/8] board: ti: j721e: Add resume detection for J7200 Date: Mon, 8 Jan 2024 17:56:24 +0100 Message-Id: <20240108165628.3935756-5-thomas.richard@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240108165628.3935756-1-thomas.richard@bootlin.com> References: <20240108165628.3935756-1-thomas.richard@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: thomas.richard@bootlin.com 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.8 at phobos.denx.de X-Virus-Status: Clean Add the capability to detect a resume. To detect the resume, SPL searches a magic value (0xBA) in a register of PMICA. This value is set by DM-Firmware during the suspend sequence. Based on the work of Gregory CLEMENT Signed-off-by: Thomas Richard Signed-off-by: Gregory CLEMENT --- Changes in v3: - Remove if statement for pmic.h board/ti/j721e/evm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/board/ti/j721e/evm.c b/board/ti/j721e/evm.c index 38fe447d8f..c5404c014d 100644 --- a/board/ti/j721e/evm.c +++ b/board/ti/j721e/evm.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "../common/board_detect.h" @@ -528,6 +529,57 @@ err_free_gpio: } } +#if (IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_TARGET_J7200_R5_EVM)) + +#define SCRATCH_PAD_REG_3 0xCB + +#define MAGIC_SUSPEND 0xBA + +static int resuming = -1; + +int board_is_resuming(void) +{ + struct udevice *pmica, *pmicb; + int ret; + + if (resuming >= 0) + goto end; + + ret = uclass_get_device_by_name(UCLASS_PMIC, + "tps659413@48", &pmica); + if (ret) { + printf("Getting PMICA init failed: %d\n", ret); + resuming = 0; + goto end; + } + debug("%s: PMICA is detected (%s)\n", __func__, pmica->name); + + ret = uclass_get_device_by_name(UCLASS_PMIC, + "lp876441@4c", &pmicb); + if (ret) { + printf("Getting PMICB init failed: %d\n", ret); + resuming = 0; + goto end; + } + debug("%s: PMICB is detected (%s)\n", __func__, pmicb->name); + + if ((pmic_reg_read(pmica, SCRATCH_PAD_REG_3) == MAGIC_SUSPEND)) { + resuming = 1; + debug("%s: board is resuming\n", __func__); + + /* clean magic suspend */ + if (pmic_reg_write(pmica, SCRATCH_PAD_REG_3, 0)) + printf("Failed to clean magic value for suspend detection in PMICA\n"); + } else { + resuming = 0; + debug("%s: board is booting (no resume detected)\n", __func__); + } +end: + return resuming; +} + +#endif /* CONFIG_SPL_BUILD && CONFIG_TARGET_J7200_R5_EVM */ + void spl_board_init(void) { #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC) -- 2.39.2