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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0013CC433FE for ; Tue, 12 Oct 2021 10:50:18 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 738F961039 for ; Tue, 12 Oct 2021 10:50:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 738F961039 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF9B88371D; Tue, 12 Oct 2021 12:50:16 +0200 (CEST) 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 069B08371D; Tue, 12 Oct 2021 12:50:15 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id EECA68373A for ; Tue, 12 Oct 2021 12:49:54 +0200 (CEST) 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 24D34101E; Tue, 12 Oct 2021 03:49:54 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1EBE83F694; Tue, 12 Oct 2021 03:49:52 -0700 (PDT) Date: Tue, 12 Oct 2021 11:49:49 +0100 From: Andre Przywara To: Samuel Holland Cc: u-boot@lists.denx.de, Jagan Teki , Jaehoon Chung , Heiko Schocher , Anatolij Gustschin , Arnaud Ferraris , Bharat Gooty , Igor Opaniuk , Jernej Skrabec , Minkyu Kang , Rayagonda Kokatanur , Simon Glass , Stephan Gerhold , Tim Harvey , Tom Rini Subject: Re: [PATCH v2 10/12] sunxi: pmic_bus: Use the DM PMIC interface when possible Message-ID: <20211012114949.0e100fc7@donnerap.cambridge.arm.com> In-Reply-To: <20211008051725.29401-11-samuel@sholland.org> References: <20211008051725.29401-1-samuel@sholland.org> <20211008051725.29401-11-samuel@sholland.org> Organization: ARM X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; aarch64-unknown-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.34 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, 8 Oct 2021 00:17:23 -0500 Samuel Holland wrote: Hi, > The pmic_bus functions are used in both SPL (for regulator setup) and > U-Boot proper (for regulator setup, SID access, GPIO, and poweroff). > > Currently, pmic_bus conflicts with DM_I2C because it uses the legacy I2C > interface. This commit makes pmic_bus dual-compatible with either the > legacy I2C functions or the newly-added PMIC_AXP driver (which uses > DM_I2C). In turn, this allows platforms to start transitioning to DM_I2C > in U-Boot proper, without breaking boards that still depend on the > legacy I2C interface for other reasons. > > Signed-off-by: Samuel Holland Reviewed-by: Andre Przywara Cheers, Andre > --- > > Changes in v2: > - No changes > > arch/arm/mach-sunxi/Kconfig | 2 ++ > arch/arm/mach-sunxi/pmic_bus.c | 19 +++++++++++++++++++ > 2 files changed, 21 insertions(+) > > diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig > index df160c9a775..cfd95b09498 100644 > --- a/arch/arm/mach-sunxi/Kconfig > +++ b/arch/arm/mach-sunxi/Kconfig > @@ -96,6 +96,8 @@ config SUN6I_PRCM > > config AXP_PMIC_BUS > bool > + select DM_PMIC if DM_I2C > + select PMIC_AXP if DM_I2C > help > Select this PMIC bus access helpers for Sunxi platform PRCM or other > AXP family PMIC devices. > diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c > index 20ded436cd2..c0908406370 100644 > --- a/arch/arm/mach-sunxi/pmic_bus.c > +++ b/arch/arm/mach-sunxi/pmic_bus.c > @@ -10,9 +10,11 @@ > > #include > #include > +#include > #include > #include > #include > +#include > #include > > #define AXP152_I2C_ADDR 0x30 > @@ -23,6 +25,9 @@ > > #define AXP221_CHIP_ADDR 0x68 > > +#if CONFIG_IS_ENABLED(PMIC_AXP) > +static struct udevice *pmic; > +#else > static int pmic_i2c_address(void) > { > if (IS_ENABLED(CONFIG_AXP152_POWER)) > @@ -33,6 +38,7 @@ static int pmic_i2c_address(void) > /* Other AXP2xx and AXP8xx variants */ > return AXP209_I2C_ADDR; > } > +#endif > > int pmic_bus_init(void) > { > @@ -43,6 +49,10 @@ int pmic_bus_init(void) > if (!needs_init) > return 0; > > +#if CONFIG_IS_ENABLED(PMIC_AXP) > + ret = uclass_get_device_by_driver(UCLASS_PMIC, DM_DRIVER_GET(axp_pmic), > + &pmic); > +#else > if (IS_ENABLED(CONFIG_SYS_I2C_SUN6I_P2WI)) { > p2wi_init(); > ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR, > @@ -56,6 +66,7 @@ int pmic_bus_init(void) > ret = rsb_set_device_address(AXP_PMIC_PRI_DEVICE_ADDR, > AXP_PMIC_PRI_RUNTIME_ADDR); > } > +#endif > > needs_init = ret; > > @@ -64,22 +75,30 @@ int pmic_bus_init(void) > > int pmic_bus_read(u8 reg, u8 *data) > { > +#if CONFIG_IS_ENABLED(PMIC_AXP) > + return pmic_read(pmic, reg, data, 1); > +#else > if (IS_ENABLED(CONFIG_SYS_I2C_SUN6I_P2WI)) > return p2wi_read(reg, data); > if (IS_ENABLED(CONFIG_SYS_I2C_SUN8I_RSB)) > return rsb_read(AXP_PMIC_PRI_RUNTIME_ADDR, reg, data); > > return i2c_read(pmic_i2c_address(), reg, 1, data, 1); > +#endif > } > > int pmic_bus_write(u8 reg, u8 data) > { > +#if CONFIG_IS_ENABLED(PMIC_AXP) > + return pmic_write(pmic, reg, &data, 1); > +#else > if (IS_ENABLED(CONFIG_SYS_I2C_SUN6I_P2WI)) > return p2wi_write(reg, data); > if (IS_ENABLED(CONFIG_SYS_I2C_SUN8I_RSB)) > return rsb_write(AXP_PMIC_PRI_RUNTIME_ADDR, reg, data); > > return i2c_write(pmic_i2c_address(), reg, 1, &data, 1); > +#endif > } > > int pmic_bus_setbits(u8 reg, u8 bits)