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 E05B4EB64DC for ; Thu, 20 Jul 2023 08:48:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CD4F8867BA; Thu, 20 Jul 2023 10:48:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="YdsPTgS9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 82541867B2; Thu, 20 Jul 2023 10:48:31 +0200 (CEST) Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) (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 60A0486332 for ; Thu, 20 Jul 2023 10:48:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4fcd615d7d6so796311e87.3 for ; Thu, 20 Jul 2023 01:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689842908; x=1690447708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nOVJSUTeVn7t7DcOBE5qjYZkx5BjhmaZ273IjAH5owE=; b=YdsPTgS9b2kT8sX8mDMO0s9EWewSLAvpWSgLT7h+CImN7JF6sw+/LnWH/0EKC6Wj85 nLPmgIGVGHoJFOSDEO95SDZASUsRSXDemYEk0+MMjC65MO1GVY3e+1L6jC8G6RGXw2Fe boL6bVHyUpoVPgu8BeRSytsS2SpMRLdbXD6XbU2ZU8akphk1JXNC0MsPGo/L0r1tNKds EuVgcXT/6nE/eZDMUoXs9brrXE2D8pYpVJuLin4xwZAsXDIEJKmrXTJuJ+0rFczFw0NQ inoz4GHYOUQA/2BtnVqb5RNM9MewFxMmQB/KTOCV8IeZDcMDhLKs+dlf/8JZRd2EWW9G KdlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689842908; x=1690447708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nOVJSUTeVn7t7DcOBE5qjYZkx5BjhmaZ273IjAH5owE=; b=a75OEyDOOM8rpfYjMPjMQtjJchYQpe8Rt8PcBgJNIsqpjbN8uBwvzEQc3Di0Y6YlAG R9X1nVpJUZGBUU31WLRSSM75b4j7UKyhP9x59Lsd9QZnA7I09MyIthdqhzxTF83+a/am +xxH+t8UjW4vLzZ9CkksGXHjJvd/TAfAtDk5WEqBroaP4qRJYoUwSUMcZbG3IUitZ23w vkyI9Sn7QECmSv4hzgNWVWkMaNezsgpAhaAmvUvSQPKDz7gHQh+jVDZT7SyIVax+RhJu 0177u141fSB7goi8xagtMQICnVq8IWy3imXVhfnmcRWDMbtrV7Op3F7Y93ZkMCbxNC3Y JvHg== X-Gm-Message-State: ABy/qLY2b2Z1ULKKDT4j/ktoRpe6/xLN2VguEHcRT0vtzHJB46xFn+ep ++F+N4NMKJRtVW4jBB3v7Hk= X-Google-Smtp-Source: APBJJlFkxK0/41SJd1ubF4SaAICOXXfq53TA+ofawVaYSYGQKckxJLy/JE1+IKYAEGi2mGqKPrd4zw== X-Received: by 2002:ac2:4e94:0:b0:4f9:dd30:1123 with SMTP id o20-20020ac24e94000000b004f9dd301123mr1500405lfr.49.1689842907395; Thu, 20 Jul 2023 01:48:27 -0700 (PDT) Received: from xeon.. ([188.163.112.64]) by smtp.gmail.com with ESMTPSA id x5-20020a19f605000000b004f21f196701sm94287lfe.203.2023.07.20.01.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 01:48:27 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Svyatoslav Ryhel Cc: u-boot@lists.denx.de Subject: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff Date: Thu, 20 Jul 2023 11:47:57 +0300 Message-Id: <20230720084804.77666-3-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720084804.77666-1-clamor95@gmail.com> References: <20230720084804.77666-1-clamor95@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Use new PMIC ops to perform device poweroff. Signed-off-by: Svyatoslav Ryhel --- cmd/Kconfig | 6 ++++++ cmd/boot.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index ecfd575237..47654297f8 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1439,6 +1439,12 @@ config CMD_POWEROFF help Poweroff/Shutdown the system +config CMD_PMIC_POWEROFF + bool "PMIC poweroff" + select CMD_POWEROFF + help + Shutdown the system using PMIC poweroff sequence. + config CMD_READ bool "read - Read binary data from a partition" help diff --git a/cmd/boot.c b/cmd/boot.c index 14839c1ced..4270034194 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -9,7 +9,13 @@ */ #include #include +#include +#include #include +#include +#include +#include +#include #ifdef CONFIG_CMD_GO @@ -64,6 +70,40 @@ U_BOOT_CMD( ); #ifdef CONFIG_CMD_POWEROFF +#ifdef CONFIG_CMD_PMIC_POWEROFF +int do_poweroff(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + struct uc_pmic_priv *pmic_priv; + struct udevice *dev; + int ret; + + for (uclass_find_first_device(UCLASS_PMIC, &dev); + dev; + uclass_find_next_device(&dev)) { + if (dev && !device_active(dev)) { + ret = device_probe(dev); + if (ret) + return ret; + } + + /* value we need to check is set after probe */ + pmic_priv = dev_get_uclass_priv(dev); + if (pmic_priv->sys_pow_ctrl) { + ret = pmic_poweroff(dev); + + /* wait some time and then print error */ + mdelay(5000); + log_err("Failed to power off!!!\n"); + return ret; + } + } + + /* no device should reach here */ + return 1; +} +#endif + U_BOOT_CMD( poweroff, 1, 0, do_poweroff, "Perform POWEROFF of the device", -- 2.39.2