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 E4059C433F5 for ; Mon, 10 Jan 2022 19:59:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A56A83294; Mon, 10 Jan 2022 20:59:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=kpnmail.nl header.i=@kpnmail.nl header.b="hm64jzPy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5431883201; Mon, 10 Jan 2022 20:59:04 +0100 (CET) Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6E79583264 for ; Mon, 10 Jan 2022 20:58:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=kettenis@openbsd.org X-KPN-MessageId: 920ec3ad-724f-11ec-8a6e-005056ab378f Received: from smtp.kpnmail.nl (unknown [10.31.155.40]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 920ec3ad-724f-11ec-8a6e-005056ab378f; Mon, 10 Jan 2022 20:57:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kpnmail.nl; s=kpnmail01; h=mime-version:message-id:date:subject:to:from; bh=TjBhW7nBkzCNf687Wct0O1xlDlMrTpTR0fwuz6854Zw=; b=hm64jzPyR3sLkZtEIx30ybkHgZQT1dKmbuezpY7yH8p87C3pSpWElybwu4Bn5N+B2VXCXooPwnKXz YoSIy4mUXPPU13JpnuYIVbiboj/R+VyGLs2cHY5rfSIIR1VUlD+SGjlfPzi8SGLs++61jvS06a2TW4 aWTJsIHFUk4Ylte4= X-KPN-VerifiedSender: No X-CMASSUN: 33|qaQ1zBakQ2cJfUdEEh7Z3zDwO4JStDGXF6JPQPGNQuifw00ylM9lMtAi0xleTDY c6XWMUw/HAO0NpiTtPAIIOw== X-Originating-IP: 83.163.83.176 Received: from copland.sibelius.xs4all.nl (sibelius.xs4all.nl [83.163.83.176]) by smtp.xs4all.nl (Halon) with ESMTPSA id bf4a7193-724f-11ec-b76f-005056ab7584; Mon, 10 Jan 2022 20:58:57 +0100 (CET) From: Mark Kettenis To: u-boot@lists.denx.de Cc: sjg@chromium.org, jh80.chung@samsung.com, Mark Kettenis Subject: [PATCH v3 3/3] power: domain: Add Apple pmgr driver Date: Mon, 10 Jan 2022 20:58:44 +0100 Message-Id: <20220110195844.2458-4-kettenis@openbsd.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220110195844.2458-1-kettenis@openbsd.org> References: <20220110195844.2458-1-kettenis@openbsd.org> 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.2 at phobos.denx.de X-Virus-Status: Clean This driver supports power domains for the power management controller found on Apple SoCs. Signed-off-by: Mark Kettenis Reviewed-by: Jaehoon Chung Reviewed-by: Simon Glass --- ChangeLog: v3: - Extend Kconfig description - Add comment on driver priv struct member arch/arm/Kconfig | 3 + drivers/power/domain/Kconfig | 9 +++ drivers/power/domain/Makefile | 1 + drivers/power/domain/apple-pmgr.c | 113 ++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 drivers/power/domain/apple-pmgr.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 78c6b2e92d..44954977b6 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -942,6 +942,9 @@ config ARCH_APPLE select OF_CONTROL select PINCTRL select POSITION_INDEPENDENT + select POWER_DOMAIN + select REGMAP + select SYSCON select SYSRESET select SYSRESET_WATCHDOG select SYSRESET_WATCHDOG_AUTO diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig index 99b3f9ae71..9aea5fcdf0 100644 --- a/drivers/power/domain/Kconfig +++ b/drivers/power/domain/Kconfig @@ -9,6 +9,15 @@ config POWER_DOMAIN domains). This may be used to save power. This API provides the means to control such power management hardware. +config APPLE_PMGR_POWER_DOMAIN + bool "Enable the Apple PMGR power domain driver" + depends on POWER_DOMAIN + default y if ARCH_APPLE + help + Enable support for manipulating power domains on Apple SoCs. + This driver is needed to power on parts of the SoC that have + not been powered on by previous boot stages. + config BCM6328_POWER_DOMAIN bool "Enable the BCM6328 power domain driver" depends on POWER_DOMAIN && ARCH_BMIPS diff --git a/drivers/power/domain/Makefile b/drivers/power/domain/Makefile index 3d1e5f073c..530ae35671 100644 --- a/drivers/power/domain/Makefile +++ b/drivers/power/domain/Makefile @@ -4,6 +4,7 @@ # obj-$(CONFIG_$(SPL_)POWER_DOMAIN) += power-domain-uclass.o +obj-$(CONFIG_APPLE_PMGR_POWER_DOMAIN) += apple-pmgr.o obj-$(CONFIG_BCM6328_POWER_DOMAIN) += bcm6328-power-domain.o obj-$(CONFIG_IMX8_POWER_DOMAIN) += imx8-power-domain-legacy.o imx8-power-domain.o obj-$(CONFIG_IMX8M_POWER_DOMAIN) += imx8m-power-domain.o diff --git a/drivers/power/domain/apple-pmgr.c b/drivers/power/domain/apple-pmgr.c new file mode 100644 index 0000000000..d25f136b9d --- /dev/null +++ b/drivers/power/domain/apple-pmgr.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Mark Kettenis + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_PMGR_PS_TARGET GENMASK(3, 0) +#define APPLE_PMGR_PS_ACTUAL GENMASK(7, 4) + +#define APPLE_PMGR_PS_ACTIVE 0xf +#define APPLE_PMGR_PS_PWRGATE 0x0 + +#define APPLE_PMGR_PS_SET_TIMEOUT_US 100 + +struct apple_pmgr_priv { + struct regmap *regmap; + u32 offset; /* offset within regmap for this domain */ +}; + +static int apple_pmgr_request(struct power_domain *power_domain) +{ + return 0; +} + +static int apple_pmgr_rfree(struct power_domain *power_domain) +{ + return 0; +} + +static int apple_pmgr_ps_set(struct power_domain *power_domain, u32 pstate) +{ + struct apple_pmgr_priv *priv = dev_get_priv(power_domain->dev); + uint reg; + + regmap_update_bits(priv->regmap, priv->offset, APPLE_PMGR_PS_TARGET, + FIELD_PREP(APPLE_PMGR_PS_TARGET, pstate)); + + return regmap_read_poll_timeout( + priv->regmap, priv->offset, reg, + (FIELD_GET(APPLE_PMGR_PS_ACTUAL, reg) == pstate), 1, + APPLE_PMGR_PS_SET_TIMEOUT_US); +} + +static int apple_pmgr_on(struct power_domain *power_domain) +{ + return apple_pmgr_ps_set(power_domain, APPLE_PMGR_PS_ACTIVE); +} + +static int apple_pmgr_off(struct power_domain *power_domain) +{ + return 0; +} + +static int apple_pmgr_of_xlate(struct power_domain *power_domain, + struct ofnode_phandle_args *args) +{ + if (args->args_count != 0) { + debug("Invalid args_count: %d\n", args->args_count); + return -EINVAL; + } + + return 0; +} + +static const struct udevice_id apple_pmgr_ids[] = { + { .compatible = "apple,pmgr-pwrstate" }, + { /* sentinel */ } +}; + +static int apple_pmgr_probe(struct udevice *dev) +{ + struct apple_pmgr_priv *priv = dev_get_priv(dev); + int ret; + + ret = dev_power_domain_on(dev); + if (ret) + return ret; + + priv->regmap = syscon_get_regmap(dev->parent); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + ret = dev_read_u32(dev, "reg", &priv->offset); + if (ret < 0) + return ret; + + return 0; +} + +struct power_domain_ops apple_pmgr_ops = { + .request = apple_pmgr_request, + .rfree = apple_pmgr_rfree, + .on = apple_pmgr_on, + .off = apple_pmgr_off, + .of_xlate = apple_pmgr_of_xlate, +}; + +U_BOOT_DRIVER(apple_pmgr) = { + .name = "apple_pmgr", + .id = UCLASS_POWER_DOMAIN, + .of_match = apple_pmgr_ids, + .ops = &apple_pmgr_ops, + .probe = apple_pmgr_probe, + .priv_auto = sizeof(struct apple_pmgr_priv), +}; -- 2.34.1