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 75737C433EF for ; Thu, 27 Jan 2022 11:49:01 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CC28A83039; Thu, 27 Jan 2022 12:48:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xs4all.nl 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 4BB5C82BA6; Thu, 27 Jan 2022 12:48:57 +0100 (CET) Received: from sibelius.xs4all.nl (sibelius.xs4all.nl [83.163.83.176]) (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 711F880031 for ; Thu, 27 Jan 2022 12:48:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=mark.kettenis@xs4all.nl Received: from localhost (bloch.sibelius.xs4all.nl [local]) by bloch.sibelius.xs4all.nl (OpenSMTPD) with ESMTPA id 54ffc43c; Thu, 27 Jan 2022 12:48:53 +0100 (CET) Date: Thu, 27 Jan 2022 12:48:53 +0100 (CET) From: Mark Kettenis To: Jaehoon Chung Cc: kettenis@openbsd.org, u-boot@lists.denx.de, sjg@chromium.org, trini@konsulko.com, sven@svenpeter.dev, marcan@marcan.st, bmeng.cn@gmail.com In-Reply-To: <1e140d19-034a-6b06-5180-c268c55f5e15@samsung.com> (message from Jaehoon Chung on Thu, 27 Jan 2022 08:54:29 +0900) Subject: Re: [PATCH v2 7/9] power: domain: apple: Add reset support References: <20220122193819.84907-1-kettenis@openbsd.org> <20220122193819.84907-8-kettenis@openbsd.org> <1e140d19-034a-6b06-5180-c268c55f5e15@samsung.com> Message-ID: 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.5 at phobos.denx.de X-Virus-Status: Clean > Date: Thu, 27 Jan 2022 08:54:29 +0900 > From: Jaehoon Chung > > Hi, > > On 1/23/22 04:38, Mark Kettenis wrote: > > The power management controller found on Apple SoCs als provides > > a way to reset all devices within a power domain. This is needed > > to cleanly shutdown the NVMe controller before we hand over > > control to the OS. > > > > Signed-off-by: Mark Kettenis > > Reviewed-by: Simon Glass > > Tested on: Macbook Air M1 > > Tested-by: Simon Glass > > Reviewed-by: Jaehoon Chung > > Add minor comment. Hi Jaehoon, > > --- > > arch/arm/Kconfig | 1 + > > drivers/power/domain/apple-pmgr.c | 73 ++++++++++++++++++++++++++++++- > > 2 files changed, 73 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > > index ecacd6860b..14c83ea19e 100644 > > --- a/arch/arm/Kconfig > > +++ b/arch/arm/Kconfig > > @@ -935,6 +935,7 @@ config ARCH_APPLE > > select DM_GPIO > > select DM_KEYBOARD > > select DM_MAILBOX > > + select DM_RESET > > select DM_SERIAL > > select DM_USB > > select DM_VIDEO > > diff --git a/drivers/power/domain/apple-pmgr.c b/drivers/power/domain/apple-pmgr.c > > index d25f136b9d..4d06e76ff5 100644 > > --- a/drivers/power/domain/apple-pmgr.c > > +++ b/drivers/power/domain/apple-pmgr.c > > @@ -6,14 +6,22 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > +#include > > #include > > #include > > > > -#define APPLE_PMGR_PS_TARGET GENMASK(3, 0) > > +#define APPLE_PMGR_RESET BIT(31) > > +#define APPLE_PMGR_DEV_DISABLE BIT(10) > > +#define APPLE_PMGR_WAS_CLKGATED BIT(9) > > +#define APPLE_PMGR_WAS_PWRGATED BIT(8) > > Bit description is specified "WAS_CLKGATED"? > I think it can be removed "WAS". CLKGATED has already similar meaning. The names are taken from the Linux driver and I would prefer to keep them the same to make it easier to compare the two drivers since nobody outside of Apple has access to documentation for this block. > > #define APPLE_PMGR_PS_ACTUAL GENMASK(7, 4) > > +#define APPLE_PMGR_PS_TARGET GENMASK(3, 0) > > + > > +#define APPLE_PMGR_FLAGS (APPLE_PMGR_WAS_CLKGATED | APPLE_PMGR_WAS_PWRGATED) > > > > #define APPLE_PMGR_PS_ACTIVE 0xf > > #define APPLE_PMGR_PS_PWRGATE 0x0 > > @@ -25,6 +33,65 @@ struct apple_pmgr_priv { > > u32 offset; /* offset within regmap for this domain */ > > }; > > > > +static int apple_reset_of_xlate(struct reset_ctl *reset_ctl, > > + struct ofnode_phandle_args *args) > > +{ > > + if (args->args_count != 0) > > + return -EINVAL; > > + > > + return 0; > > +} > > + > > +static int apple_reset_request(struct reset_ctl *reset_ctl) > > +{ > > + return 0; > > +} > > + > > +static int apple_reset_free(struct reset_ctl *reset_ctl) > > +{ > > + return 0; > > +} > > + > > +static int apple_reset_assert(struct reset_ctl *reset_ctl) > > +{ > > + struct apple_pmgr_priv *priv = dev_get_priv(reset_ctl->dev->parent); > > + > > + regmap_update_bits(priv->regmap, priv->offset, > > + APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, > > + APPLE_PMGR_DEV_DISABLE); > > + regmap_update_bits(priv->regmap, priv->offset, > > + APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, > > + APPLE_PMGR_RESET); > > + > > + return 0; > > +} > > + > > +static int apple_reset_deassert(struct reset_ctl *reset_ctl) > > +{ > > + struct apple_pmgr_priv *priv = dev_get_priv(reset_ctl->dev->parent); > > + > > + regmap_update_bits(priv->regmap, priv->offset, > > + APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, 0); > > + regmap_update_bits(priv->regmap, priv->offset, > > + APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, 0); > > + > > + return 0; > > +} > > + > > +struct reset_ops apple_reset_ops = { > > + .of_xlate = apple_reset_of_xlate, > > + .request = apple_reset_request, > > + .rfree = apple_reset_free, > > + .rst_assert = apple_reset_assert, > > + .rst_deassert = apple_reset_deassert, > > +}; > > + > > +static struct driver apple_reset_driver = { > > + .name = "apple_reset", > > + .id = UCLASS_RESET, > > + .ops = &apple_reset_ops, > > +}; > > + > > static int apple_pmgr_request(struct power_domain *power_domain) > > { > > return 0; > > @@ -78,6 +145,7 @@ static const struct udevice_id apple_pmgr_ids[] = { > > static int apple_pmgr_probe(struct udevice *dev) > > { > > struct apple_pmgr_priv *priv = dev_get_priv(dev); > > + struct udevice *child; > > int ret; > > > > ret = dev_power_domain_on(dev); > > @@ -92,6 +160,9 @@ static int apple_pmgr_probe(struct udevice *dev) > > if (ret < 0) > > return ret; > > > > + device_bind(dev, &apple_reset_driver, "apple_reset", NULL, > > + dev_ofnode(dev), &child); > > + > > return 0; > > } > > > >