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 BACDBC77B73 for ; Fri, 28 Apr 2023 00:33:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 54C6886177; Fri, 28 Apr 2023 02:33:45 +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 A1CC186176; Fri, 28 Apr 2023 02:33:43 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id AA87785D0B for ; Fri, 28 Apr 2023 02:33:40 +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 F32F1C14; Thu, 27 Apr 2023 17:34:23 -0700 (PDT) Received: from slackpad.lan (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A1913F587; Thu, 27 Apr 2023 17:33:38 -0700 (PDT) Date: Fri, 28 Apr 2023 01:15:30 +0100 From: Andre Przywara To: Samuel Holland Cc: Jagan Teki , Jaehoon Chung , u-boot@lists.denx.de Subject: Re: [PATCH 1/3] power: regulator: Add a driver for the AXP USB power supply Message-ID: <20230428011530.5d0bdaa0@slackpad.lan> In-Reply-To: <20230122234623.1636-2-samuel@sholland.org> References: <20230122234623.1636-1-samuel@sholland.org> <20230122234623.1636-2-samuel@sholland.org> Organization: Arm Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.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.8 at phobos.denx.de X-Virus-Status: Clean On Sun, 22 Jan 2023 17:46:20 -0600 Samuel Holland wrote: > This driver reports the presence/absence of voltage on the PMIC's USB > VBUS pin. This information is used by the USB PHY driver. The > corresponding Linux driver uses the power supply class, which does not > exist in U-Boot. UCLASS_REGULATOR seems to be the closest match. That's a quite clever and lean solution, since the USB PHY already checks for such a regulator enable status. The bits match up, so: Acked-by: Andre Przywara queued for sunxi/master Cheers, Andre > Signed-off-by: Samuel Holland > --- > > drivers/power/regulator/Kconfig | 7 ++++ > drivers/power/regulator/Makefile | 1 + > drivers/power/regulator/axp_usb_power.c | 49 +++++++++++++++++++++++++ > 3 files changed, 57 insertions(+) > create mode 100644 drivers/power/regulator/axp_usb_power.c > > diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig > index c346d03507..eb5aa38c1c 100644 > --- a/drivers/power/regulator/Kconfig > +++ b/drivers/power/regulator/Kconfig > @@ -57,6 +57,13 @@ config SPL_REGULATOR_AXP > Enable support in SPL for the regulators (DCDCs, LDOs) in the > X-Powers AXP152, AXP2xx, and AXP8xx PMICs. > > +config REGULATOR_AXP_USB_POWER > + bool "Enable driver for X-Powers AXP PMIC USB power supply" > + depends on DM_REGULATOR && PMIC_AXP > + help > + Enable support for reading the USB power supply status from > + X-Powers AXP2xx and AXP8xx PMICs. > + > config DM_REGULATOR_BD71837 > bool "Enable Driver Model for ROHM BD71837/BD71847 regulators" > depends on DM_REGULATOR && DM_PMIC_BD71837 > diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile > index 2d97e1033a..d9e0cd5949 100644 > --- a/drivers/power/regulator/Makefile > +++ b/drivers/power/regulator/Makefile > @@ -8,6 +8,7 @@ obj-$(CONFIG_$(SPL_)DM_REGULATOR) += regulator-uclass.o > obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o > obj-$(CONFIG_REGULATOR_AS3722) += as3722_regulator.o > obj-$(CONFIG_$(SPL_)REGULATOR_AXP) += axp_regulator.o > +obj-$(CONFIG_$(SPL_)REGULATOR_AXP_USB_POWER) += axp_usb_power.o > obj-$(CONFIG_$(SPL_)DM_REGULATOR_DA9063) += da9063.o > obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o > obj-$(CONFIG_DM_REGULATOR_NPCM8XX) += npcm8xx_regulator.o > diff --git a/drivers/power/regulator/axp_usb_power.c b/drivers/power/regulator/axp_usb_power.c > new file mode 100644 > index 0000000000..f32fb6a92d > --- /dev/null > +++ b/drivers/power/regulator/axp_usb_power.c > @@ -0,0 +1,49 @@ > +// SPDX-License-Identifier: GPL-2.0+ > + > +#include > +#include > +#include > +#include > + > +#define AXP_POWER_STATUS 0x00 > +#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5) > + > +static int axp_usb_power_get_enable(struct udevice *dev) > +{ > + int ret; > + > + ret = pmic_reg_read(dev->parent, AXP_POWER_STATUS); > + if (ret < 0) > + return ret; > + > + return !!(ret & AXP_POWER_STATUS_VBUS_PRESENT); > +} > + > +static const struct dm_regulator_ops axp_usb_power_ops = { > + .get_enable = axp_usb_power_get_enable, > +}; > + > +static int axp_usb_power_probe(struct udevice *dev) > +{ > + struct dm_regulator_uclass_plat *uc_plat = dev_get_uclass_plat(dev); > + > + uc_plat->type = REGULATOR_TYPE_FIXED; > + > + return 0; > +} > + > +static const struct udevice_id axp_usb_power_ids[] = { > + { .compatible = "x-powers,axp202-usb-power-supply" }, > + { .compatible = "x-powers,axp221-usb-power-supply" }, > + { .compatible = "x-powers,axp223-usb-power-supply" }, > + { .compatible = "x-powers,axp813-usb-power-supply" }, > + { } > +}; > + > +U_BOOT_DRIVER(axp_usb_power) = { > + .name = "axp_usb_power", > + .id = UCLASS_REGULATOR, > + .of_match = axp_usb_power_ids, > + .probe = axp_usb_power_probe, > + .ops = &axp_usb_power_ops, > +};