From mboxrd@z Thu Jan 1 00:00:00 1970 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 78B22C433F5 for ; Mon, 23 May 2022 19:30:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BA8948425C; Mon, 23 May 2022 21:30:41 +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="K1QYjtmn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 911AF83B3C; Mon, 23 May 2022 21:30:19 +0200 (CEST) Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) (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 3D2908424A for ; Mon, 23 May 2022 21:30:12 +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=macroalpha82@gmail.com Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-e5e433d66dso19703374fac.5 for ; Mon, 23 May 2022 12:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uqMiGknsVsQ1Qnlv2SHk2bHO5OnZnxkgWGh2UrjoJiA=; b=K1QYjtmnCKe7knqlxptTyibfc1kfqdGEsQieDhs3p53x4UjhVMcw9kW/QI/NAA3zqG dOuljmSn2uHjzaJ0DS+iP2kZeyDPavyNFjrrvq/XGQjDJXqrkuhpECgYIxHsTNFg5XI2 f/S6yDhL+JQr7f91BXqAjcoO/ZVmAoZ2Qn7DAeNpct0tvv4/6w+x3sx/Sw4r6IfWkPDg edsI/F5VRgOzU/SpHoyqlONPkhYqimwqUx/YibNGOz4yO6uDQsNgC4zsVqR60ehBzUWX N6hjvvuUVZLqrcA34mYNDmc+y1cTvRKjX1dgCEdsd203ZI1FAdG8pG2tL+/LKVsL8CJR F/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uqMiGknsVsQ1Qnlv2SHk2bHO5OnZnxkgWGh2UrjoJiA=; b=fB+lcS797te1xdRYuwCIph59Z4hNJ2Y9VqGgqBzmbrKM2bJOWidVmRBvGEIO3pLIYC ocqs06JIp1mVhLarUI/a/yvkIMVOsQCeIM3kGG3WgNBlSYGk/rMX8BidSL3b4plvryOO zuAMRzc+acFyU+1QGztigd79f8UxZ5o+FHWXAJ7eqrh2RpKCYbze/WCLpr1W0qsJ09Yz cTJlyBVlIipVDatjiJBfk/1iLH9Yv5O9EuYkX9kd8gmSO7lWZ2fWq3cH5AuJGEjR5d6y yfOWirTUDnc3OR1eIyqbZlHNf8j/elhU32uxPClZ0gDbP0bV21ma4vNtxffb1UefedfJ koCQ== X-Gm-Message-State: AOAM532J21H8Po0icW4OKOH7wiBW8w62QJCNW6bD2vp3PNcGEqIAoqtD ogGB4zDHPA56X2Vm8qpaU1EABGJKqxZPEQ== X-Google-Smtp-Source: ABdhPJxrzVZk6br+e9wzNdJwEVc0iT9j6S+fsa9Sv9WqN8dJ1phCVx3v4AN2eT+MltmGqD4V4cZTjg== X-Received: by 2002:a05:6870:b152:b0:f1:b90b:2810 with SMTP id a18-20020a056870b15200b000f1b90b2810mr337473oal.231.1653334210578; Mon, 23 May 2022 12:30:10 -0700 (PDT) Received: from wintermute.localdomain (cpe-76-183-134-35.tx.res.rr.com. [76.183.134.35]) by smtp.gmail.com with ESMTPSA id s7-20020a05687087c700b000f2911d1987sm336626oam.39.2022.05.23.12.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 12:30:10 -0700 (PDT) From: Chris Morgan To: u-boot@lists.denx.de Cc: jh80.chung@samsung.com, kever.yang@rock-chips.com, philipp.tomsich@vrull.eu, sjg@chromium.org, Chris Morgan Subject: [PATCH 2/2] rockchip: Add option to prevent booting on power plug-in Date: Mon, 23 May 2022 14:30:01 -0500 Message-Id: <20220523193001.13715-3-macroalpha82@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523193001.13715-1-macroalpha82@gmail.com> References: <20220523193001.13715-1-macroalpha82@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.5 at phobos.denx.de X-Virus-Status: Clean From: Chris Morgan For Rockchip boards with the all rk8xx series PMICs (excluding the rk808), it is sometimes desirable to not boot whenever the device is plugged in. An example would be for the Odroid Go Advance. This provides a configurable option to check the PMIC says it was powered because of a plug-in event. If the value is 1 and this option is selected, the device shuts down shortly after printing a message to console stating the reason why it's shutting down. Powering up the board with the power button is not affected. This patch parallels the work done in the following patch series: https://lore.kernel.org/u-boot/20220121133732.2397273-1-andre.przywara@arm.com/ Signed-off-by: Chris Morgan --- arch/arm/mach-rockchip/Kconfig | 10 +++++++++ drivers/power/pmic/rk8xx.c | 37 ++++++++++++++++++++++++++++++++++ include/power/rk8xx_pmic.h | 3 +++ 3 files changed, 50 insertions(+) diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index 18aff5480b..c561a77e6a 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -361,6 +361,16 @@ config ROCKCHIP_BOOT_MODE_REG The Soc will enter to different boot mode(defined in asm/arch-rockchip/boot_mode.h) according to the value from this register. +config ROCKCHIP_RK8XX_DISABLE_BOOT_ON_POWERON + bool "Disable device boot on power plug-in" + depends on PMIC_RK8XX + default n + ---help--- + Say Y here to prevent the device from booting up because of a plug-in + event. When set, the device will boot briefly to determine why it was + powered on, and if it was determined because of a plug-in event + instead of a button press event it will shut back off. + config ROCKCHIP_STIMER bool "Rockchip STIMER support" default y diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c index 1ffbecc02a..b59675a10e 100644 --- a/drivers/power/pmic/rk8xx.c +++ b/drivers/power/pmic/rk8xx.c @@ -51,6 +51,41 @@ U_BOOT_DRIVER(rk8xx_sysreset) = { .ops = &rk8xx_sysreset_ops, }; +void rk8xx_off_for_plugin(struct udevice *dev) +/* In the event of a plug-in and the appropriate option has been + * selected, we simply shutdown instead of continue the normal boot + * process. Please note the rk808 is not supported as it doesn't + * have the appropriate register. + */ +{ + struct rk8xx_priv *priv = dev_get_priv(dev); + bool plug_in = 0; + + switch (priv->variant) { + case RK805_ID: + case RK816_ID: + case RK818_ID: + plug_in = pmic_reg_read(dev, RK8XX_ON_SOURCE) & RK8XX_ON_PLUG_IN; + if (plug_in) { + printf("Power Off due to plug-in event\n"); + pmic_clrsetbits(dev, REG_DEVCTRL, 0, BIT(0)); + } + break; + case RK809_ID: + case RK817_ID: + plug_in = pmic_reg_read(dev, RK817_ON_SOURCE) & RK8XX_ON_PLUG_IN; + if (plug_in) { + printf("Power Off due to plug-in event\n"); + pmic_clrsetbits(dev, RK817_REG_SYS_CFG3, 0, + BIT(0)); + } + break; + default: + printf("PMIC RK%x: Cannot read boot reason.\n", + priv->variant); + } +} + static struct reg_data rk817_init_reg[] = { /* enable the under-voltage protection, * the under-voltage protection will shutdown the LDO3 and reset the PMIC @@ -211,6 +246,8 @@ static int rk8xx_probe(struct udevice *dev) pmic_reg_read(dev, on_source), pmic_reg_read(dev, off_source)); printf("\n"); + if (CONFIG_IS_ENABLED(ROCKCHIP_RK8XX_DISABLE_BOOT_ON_POWERON)) + rk8xx_off_for_plugin(dev); return 0; } diff --git a/include/power/rk8xx_pmic.h b/include/power/rk8xx_pmic.h index 8ff0af35c5..3cbfc02195 100644 --- a/include/power/rk8xx_pmic.h +++ b/include/power/rk8xx_pmic.h @@ -214,6 +214,9 @@ enum { #define RK817_ON_SOURCE 0xf5 #define RK817_OFF_SOURCE 0xf6 +#define RK8XX_ON_PWRON BIT(7) +#define RK8XX_ON_PLUG_IN BIT(6) + struct reg_data { u8 reg; u8 val; -- 2.25.1