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 08430C433EF for ; Mon, 10 Jan 2022 02:08:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DD2F3811DF; Mon, 10 Jan 2022 03:08:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C6C37811E0; Mon, 10 Jan 2022 03:08:30 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 727FF81112 for ; Mon, 10 Jan 2022 03:08:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9FD94ED1; Sun, 9 Jan 2022 18:08:26 -0800 (PST) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A4E353F774; Sun, 9 Jan 2022 18:08:25 -0800 (PST) Date: Mon, 10 Jan 2022 02:07:55 +0000 From: Andre Przywara To: Chris Morgan Cc: u-boot@lists.denx.de, hdegoede@redhat.com, jagan@amarulasolutions.com, Chris Morgan Subject: Re: [PATCH 1/1] sunxi: Add option to prevent power-on when plug in Message-ID: <20220110020755.56e0a70d@slackpad.fritz.box> In-Reply-To: <20220107175406.6095-1-macroalpha82@gmail.com> References: <20220107175406.6095-1-macroalpha82@gmail.com> Organization: Arm Ltd. X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.31; x86_64-slackware-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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.2 at phobos.denx.de X-Virus-Status: Clean On Fri, 7 Jan 2022 11:54:06 -0600 Chris Morgan wrote: Hi Chris, > 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. Looks OK, as it's well protected, but maybe you can reword the commit message (and the code) to not speak of preventing "power-on", but to "prevent booting", as this is more what the patch does? I was initially puzzled how you would achieve to no power-on in software. One small thing below: > 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; If you move this declaration ... > > #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) { ... to here, you can save the __maybe_unused tag. Cheers, Andre > + 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);