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 7E040C433EF for ; Fri, 7 Jan 2022 17:54:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 746038374E; Fri, 7 Jan 2022 18:54:16 +0100 (CET) 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="NWZu1HuG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF41183751; Fri, 7 Jan 2022 18:54:14 +0100 (CET) Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) (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 183C18309C for ; Fri, 7 Jan 2022 18:54:12 +0100 (CET) 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-oi1-x22b.google.com with SMTP id u21so9170972oie.10 for ; Fri, 07 Jan 2022 09:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sA2K5dTP6H4QKK4lc5dKFGYxOFzIjeMQNYqAsjB7ytw=; b=NWZu1HuGrNkb56EuZZWYTMUdxcwglK5d6bZx4W+IYBjPMEudycfrp7c5YRVwa0XgK5 LgJ7qxutdfLbfQuGrGgyqvnTQlu2ThvIl5gFoZr1tnI60ouR6BzfbeGH/nNacoUsUIu8 AdHU2FiRW30R6ogBDFhhuD16ZYTVfOWkrmigHlFTT7BazZjWbaFvkNsG+enbwU1iDg5H H968ymhWXMArHK+4yo5jR3G0gf8XydsQNeto4ONaae9W8SE6dspf4gacFnQmUvAzvmWY Ft30uaaFpFNsnaSdPnsRyjcbXkO9xXR86gGBjlwdNpZPs0UVwWe7BMYVGBkaSa1K2nQl KT0Q== 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:mime-version :content-transfer-encoding; bh=sA2K5dTP6H4QKK4lc5dKFGYxOFzIjeMQNYqAsjB7ytw=; b=8In3TSvTAkHcvHi2Xb0baSHXoEmI/O99aE0xJz8QtH3144nsgl3F2g1y1J7a8FALmM q5paFgYp/nAAIUGWn3bGmg8dq3ZxJVMY8HEzFmAFzbj//PNVVKdMIhBaWBBRmo40WD6B wlJAlVNpTyg4YDONhZ+Rf3h3hQRtZkixFt3zjGjdpnmWUlqfIfU2PtOPEFjrKvUl1pXx XmDiOWOyIQiydCnUj79X/9v3xn96i/t2cCn64121iwPV42OtkOvWD93gvNAHk+SYl6tX deONm4x6zMkyivU0UgPGqOP9LsidZUk6D0HUHliw2W1ka9jPQN3rq1sXSjbS4W7dD0AF mTvA== X-Gm-Message-State: AOAM53215Haj8yhXV7nsk2KJUjLXRjCZAD2vaAffAS65XQwQXgdRQvK0 +DsP5nmyaRyaYOPZmRi/NtbpP6tz7r0= X-Google-Smtp-Source: ABdhPJzKZEx6HCLSBiYMCKGJmsYwN1ZbpKSQyWiE9vjLVUEYJ2BaHmY4+eCHxN8fI/xg36PeNu6HIQ== X-Received: by 2002:a05:6808:1a13:: with SMTP id bk19mr1741996oib.52.1641578048239; Fri, 07 Jan 2022 09:54:08 -0800 (PST) Received: from wintermute.localdomain (cpe-76-183-134-35.tx.res.rr.com. [76.183.134.35]) by smtp.gmail.com with ESMTPSA id k24sm993575otl.31.2022.01.07.09.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 09:54:07 -0800 (PST) From: Chris Morgan To: u-boot@lists.denx.de Cc: hdegoede@redhat.com, andre.przywara@arm.com, jagan@amarulasolutions.com, Chris Morgan Subject: [PATCH 1/1] sunxi: Add option to prevent power-on when plug in Date: Fri, 7 Jan 2022 11:54:06 -0600 Message-Id: <20220107175406.6095-1-macroalpha82@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 at phobos.denx.de X-Virus-Status: Clean From: Chris Morgan For sunxi boards with the AXP209, AXP221, AXP809, and AXP818 PMICs (plus possibly others, I only confirmed the datasheets for these), it is sometimes desirable to not power up whenever the device is plugged in. An example would be when using the NTC CHIP inside a PocketCHIP. This provides a configurable option to check if bit 0 of register 0 of the PMIC says it was powered because of a power button press (0) or a plug-in event (1). 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. Signed-off-by: Chris Morgan --- arch/arm/mach-sunxi/Kconfig | 10 ++++++++++ board/sunxi/board.c | 17 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index 2c18cf02d1..d94046dc54 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -785,6 +785,16 @@ config AXP_GPIO ---help--- Say Y here to enable support for the gpio pins of the axp PMIC ICs. +config AXP_DISABLE_POWERON_VIN + bool "Disable device power-on when plugged in" + depends on AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER + default n + ---help--- + Say Y here to prevent the device from powering up because of a plug-in + event. When set, the device will power on 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 VIDEO_SUNXI bool "Enable graphical uboot console on HDMI, LCD or VGA" depends on !MACH_SUN8I_A83T diff --git a/board/sunxi/board.c b/board/sunxi/board.c index fdbcd40269..9f656b56f1 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -586,6 +587,7 @@ static void sunxi_spl_store_dram_size(phys_addr_t dram_size) void sunxi_board_init(void) { int power_failed = 0; + __maybe_unused u8 boot_reason; #ifdef CONFIG_LED_STATUS if (IS_ENABLED(CONFIG_SPL_DRIVERS_MISC)) @@ -601,6 +603,21 @@ void sunxi_board_init(void) defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER power_failed = axp_init(); +#if IS_ENABLED(CONFIG_AXP_DISABLE_POWERON_VIN) +/* This behavior (bit(0) of register 0x00 and shutdown by setting bit(7) of + * register 0x32 appears to be common to many AXP chips, at least according to + * the datasheets of the AXP209, the AXP221, the AXP803, the AXP809, and the + * AXP818. + */ + if (!power_failed) { + pmic_bus_read(AXP_POWER_STATUS, &boot_reason); + if (boot_reason & BIT(0)) { + printf("Power on by charger, shutting down.\n"); + pmic_bus_write(0x32, BIT(7)); + } + } +#endif + #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ defined CONFIG_AXP818_POWER power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT); -- 2.30.2