Message ID | 20230619085344.2885311-7-msp@baylibre.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2874583vqr; Mon, 19 Jun 2023 02:37:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gLXBtGjUdr0oStqGcgzvxAGMeWD1oSTScRLwQBExaxsF+v65kuwfMM8eJdRmvADxvoH6N X-Received: by 2002:a1f:ca44:0:b0:46e:7158:1d02 with SMTP id a65-20020a1fca44000000b0046e71581d02mr1391603vkg.11.1687167420043; Mon, 19 Jun 2023 02:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687167419; cv=none; d=google.com; s=arc-20160816; b=t5Cai/rZQvD7eGkRELIMwaQ78ifsEzUQqLcBqnjo3Of6KaZ26Se4vIrVsusg1iVopl cCtRGY3an8scTsNTThuY1k7NNDVYABDKYthn4I2KPJTbOuNeqj6lK+Xtw9WsLQcuyddi keNykK1bqU0LhSO4pjlPu2WNjg2jKeK4SYR3MWiMUE58mEX2Bt2lm/AyyIMJ9oCJ7/42 xAMYTdIZ7jOsZC03EP9w/NwlKmCxmuZb37ViHVgGcF4jqagLi+5bJmgFvTgQ40gEbFi4 w8Upt9pln/+i86H6SVf8+dYB8yyJnJY2SpkeXS+Wyb4NQ3fL3QchJ6QfL9DB3KJ+ebl2 4b9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SPf+y2ctEZoMI72ckvhMmROgBE22+ZnhLuRaMNUscz8=; b=xczwK9gJrBrdUvUwCm+ZKVK2g3e0oUiM8EqqokMj4h5/R3TAeTGczzcYW2iylrmYF4 Zu59198EoCzLX4vF6W+Ng/ADvtHfA7WonKaRYmVSLepJ+krNGd5oa/neBpzgb++jmy0z m9tlbxtvkEjtYdEkpBWNBvLns8+migpixHgm4xR/pSX0xccaScqGAPjsRKCgSbEha5jv BwgowElInKO3WFGG11iXIR7IYQLdOMc4vXta2Itc6YAXkO5xDIRfiNmlwYBovVIA7oOj /XFHfXQkOU9c56nwBoP2wKdqn5b668abXZfq8LBoineSK+RMZmwFGj+ckaxLyO5fGYQa 18uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b="F64R/K5b"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e23-20020a63db17000000b0053ef95fa919si10113486pgg.458.2023.06.19.02.36.46; Mon, 19 Jun 2023 02:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b="F64R/K5b"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbjFSIz5 (ORCPT <rfc822;duw91626@gmail.com> + 99 others); Mon, 19 Jun 2023 04:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231407AbjFSIzD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 19 Jun 2023 04:55:03 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB67110CE for <linux-kernel@vger.kernel.org>; Mon, 19 Jun 2023 01:54:19 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-988a076a7d3so143618466b.3 for <linux-kernel@vger.kernel.org>; Mon, 19 Jun 2023 01:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687164858; x=1689756858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SPf+y2ctEZoMI72ckvhMmROgBE22+ZnhLuRaMNUscz8=; b=F64R/K5b0EadtnOiOYb2nUWFwjqy/DD2rMbote0vH67+ouDjC826VzJoxWZcGwsdnk 9muDCiKsoJbPer8L/kkf6N1BQZBkdBk3bvQimpZdfqUlsv6ajjnN+TkqeljkNVWhUYGQ OH0hhgNV1k04q8QJSk+XNGtE/YfK+AJXPrF0hUzL2CEZhYG4TYVhmq2daTJ1ywmtOy9Q nXLISjjAN9T4tkczbiXGulzCc+o+csIYSf24jd889J81rxdu5kGnPd7ST0lQvaHZAVJZ YpRa2A4UbS1YUmOWirRUwtskqEB65MjorIVlgWT2pu6JKSN5SEMGBPssR7doF3aXLkxC 83iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687164858; x=1689756858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SPf+y2ctEZoMI72ckvhMmROgBE22+ZnhLuRaMNUscz8=; b=QfH3q/rHjunel0FdIpsTZ3BXTvkKpLt5Qk8oOdhNxzB//A75SgjQd7JaBpAM5ZZVzq WGNOAhJHzc9FTMhm2TF/jZv2UlPT+FKHCbnVLz2KZ9G30YTC/nqA/N2fvGf2EWYN+EXY GfPQpc8fKpxa3YMjq/LRJp10MTpIaH2ESP0ZdnF4pDMwnjkkkY0ej0j452RapuG1ZvO3 tr33xUxix6YCt1kJHN2gIk2+OYa3be2a5uta0adV2DBGNHTlLpS/h3l6I7k44s11dQlU 40P4HIbWXOZ0iQf8Hc0vhYqf8iN3CMzvpOlgoYFywFtRvlIjJzVXvPOcH3K3n48+OPyw NjnQ== X-Gm-Message-State: AC+VfDyttvAk2OReJ7LIYb0qAB+eWuFCgcvEblt7SN6dvOuKTIBSxeRM NFlq+tLbrISJcqpL0G+H4Ml6iA== X-Received: by 2002:a17:907:2d94:b0:96f:f046:9a92 with SMTP id gt20-20020a1709072d9400b0096ff0469a92mr9526606ejc.37.1687164858251; Mon, 19 Jun 2023 01:54:18 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a245:802c:bc2b:8db8:9210:41eb]) by smtp.gmail.com with ESMTPSA id h27-20020a17090619db00b00987a6e01e94sm2994339ejd.214.2023.06.19.01.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 01:54:17 -0700 (PDT) From: Markus Schneider-Pargmann <msp@baylibre.com> To: Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Matthias Brugger <matthias.bgg@gmail.com> Cc: Chun-Jie Chen <chun-jie.chen@mediatek.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Tinghan Shen <tinghan.shen@mediatek.com>, Fabien Parent <parent.f@gmail.com>, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Alexandre Bailon <abailon@baylibre.com>, Fabien Parent <fparent@baylibre.com>, Markus Schneider-Pargmann <msp@baylibre.com> Subject: [PATCH v5 6/8] soc: mediatek: Add support for WAY_EN operations Date: Mon, 19 Jun 2023 10:53:42 +0200 Message-Id: <20230619085344.2885311-7-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230619085344.2885311-1-msp@baylibre.com> References: <20230619085344.2885311-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769123264512707535?= X-GMAIL-MSGID: =?utf-8?q?1769123264512707535?= |
Series |
soc: mediatek: MT8365 power support
|
|
Commit Message
Markus Schneider-Pargmann
June 19, 2023, 8:53 a.m. UTC
From: Alexandre Bailon <abailon@baylibre.com> This updates the power domain to support WAY_EN operations. WAY_EN operations on mt8365 are using a different component to check for the acknowledgment, namely the infracfg-nao component. Also to enable a way it the bit needs to be cleared while disabling a way needs a bit to be set. To support these two operations two flags are added, BUS_PROT_INVERTED and BUS_PROT_STA_COMPONENT_INFRA_NAO. Additionally another regmap is created if the INFRA_NAO capability is set. This operation is required by the mt8365 for the MM power domain. Signed-off-by: Alexandre Bailon <abailon@baylibre.com> Signed-off-by: Fabien Parent <fparent@baylibre.com> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> --- drivers/soc/mediatek/mtk-pm-domains.c | 39 +++++++++++++++++++++++---- drivers/soc/mediatek/mtk-pm-domains.h | 7 +++-- 2 files changed, 39 insertions(+), 7 deletions(-)
Comments
Il 19/06/23 10:53, Markus Schneider-Pargmann ha scritto: > From: Alexandre Bailon <abailon@baylibre.com> > > This updates the power domain to support WAY_EN operations. WAY_EN > operations on mt8365 are using a different component to check for the > acknowledgment, namely the infracfg-nao component. Also to enable a way > it the bit needs to be cleared while disabling a way needs a bit to be > set. To support these two operations two flags are added, > BUS_PROT_INVERTED and BUS_PROT_STA_COMPONENT_INFRA_NAO. Additionally > another regmap is created if the INFRA_NAO capability is set. > > This operation is required by the mt8365 for the MM power domain. > > Signed-off-by: Alexandre Bailon <abailon@baylibre.com> > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > --- > drivers/soc/mediatek/mtk-pm-domains.c | 39 +++++++++++++++++++++++---- > drivers/soc/mediatek/mtk-pm-domains.h | 7 +++-- > 2 files changed, 39 insertions(+), 7 deletions(-) > > diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c > index 3cdf62c0b6bd..4659f0a0aa08 100644 > --- a/drivers/soc/mediatek/mtk-pm-domains.c > +++ b/drivers/soc/mediatek/mtk-pm-domains.c > @@ -44,6 +44,7 @@ struct scpsys_domain { > struct clk_bulk_data *clks; > int num_subsys_clks; > struct clk_bulk_data *subsys_clks; > + struct regmap *infracfg_nao; > struct regmap *infracfg; > struct regmap *smi; > struct regulator *supply; > @@ -127,13 +128,26 @@ static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd, > return pd->infracfg; > } > > +static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_domain *pd, > + const struct scpsys_bus_prot_data *bpd) > +{ > + if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) > + return pd->infracfg_nao; > + else > + return scpsys_bus_protect_get_regmap(pd, bpd); > +} > + > static int scpsys_bus_protect_clear(struct scpsys_domain *pd, > const struct scpsys_bus_prot_data *bpd) > { > + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); > struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); > + u32 expected_ack; > u32 val; > u32 sta_mask = bpd->bus_prot_sta_mask; > > + expected_ack = (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO ? sta_mask : 0); > + > if (bpd->flags & BUS_PROT_REG_UPDATE) > regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); > else > @@ -142,14 +156,15 @@ static int scpsys_bus_protect_clear(struct scpsys_domain *pd, > if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) > return 0; > > - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, > - val, !(val & sta_mask), > + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, > + val, (val & sta_mask) == expected_ack, > MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); > } > > static int scpsys_bus_protect_set(struct scpsys_domain *pd, > const struct scpsys_bus_prot_data *bpd) > { > + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); > struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); > u32 val; > u32 sta_mask = bpd->bus_prot_sta_mask; > @@ -159,7 +174,7 @@ static int scpsys_bus_protect_set(struct scpsys_domain *pd, > else > regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); > > - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, > + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, > val, (val & sta_mask) == sta_mask, > MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); > } > @@ -173,7 +188,10 @@ static int scpsys_bus_protect_enable(struct scpsys_domain *pd) > if (!bpd->bus_prot_set_clr_mask) > break; > > - ret = scpsys_bus_protect_set(pd, bpd); > + if (bpd->flags & BUS_PROT_INVERTED) > + ret = scpsys_bus_protect_clear(pd, bpd); > + else > + ret = scpsys_bus_protect_set(pd, bpd); > if (ret) > return ret; > } > @@ -190,7 +208,10 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd) > if (!bpd->bus_prot_set_clr_mask) > continue; > > - ret = scpsys_bus_protect_clear(pd, bpd); > + if (bpd->flags & BUS_PROT_INVERTED) > + ret = scpsys_bus_protect_set(pd, bpd); > + else > + ret = scpsys_bus_protect_clear(pd, bpd); > if (ret) > return ret; > } > @@ -377,6 +398,14 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no > return ERR_CAST(pd->smi); > } > > + pd->infracfg_nao = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao"); If we don't expect infracfg-nao to be present, what's the point about trying to get a regmap handle and then failing only if we do expect it to be there? At this point you can just do... if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) { pd->infracfg_nao = syscon_regmap_lookup_by_phandle(...); if (IS_ERR(....)) return .... } > + if (IS_ERR(pd->infracfg_nao)) { > + if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) > + return ERR_CAST(pd->infracfg_nao); > + > + pd->infracfg_nao = NULL; > + } > + > num_clks = of_clk_get_parent_count(node); > if (num_clks > 0) { > /* Calculate number of subsys_clks */ > diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h > index 356788263db2..562d4e92ce16 100644 > --- a/drivers/soc/mediatek/mtk-pm-domains.h > +++ b/drivers/soc/mediatek/mtk-pm-domains.h > @@ -11,6 +11,7 @@ > /* can't set MTK_SCPD_KEEP_DEFAULT_OFF at the same time */ > #define MTK_SCPD_ALWAYS_ON BIT(5) > #define MTK_SCPD_EXT_BUCK_ISO BIT(6) > +#define MTK_SCPD_HAS_INFRA_NAO BIT(7) > #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x)) > > #define SPM_VDE_PWR_CON 0x0210 > @@ -45,8 +46,10 @@ > enum scpsys_bus_prot_flags { > BUS_PROT_REG_UPDATE = BIT(1), > BUS_PROT_IGNORE_CLR_ACK = BIT(2), > - BUS_PROT_COMPONENT_INFRA = BIT(3), > - BUS_PROT_COMPONENT_SMI = BIT(4), > + BUS_PROT_INVERTED = BIT(3), I get the reason why you're setting inverted as bit 3, but at that point you can just set BUS_PROT_COMPONENT_INFRA to bit 4 from the very beginning, instead of using bit 3 for that and then changing them all in a subsequent commit (this one). Cheers, Angelo
On Mon, Jun 19, 2023 at 11:29:18AM +0200, AngeloGioacchino Del Regno wrote: > Il 19/06/23 10:53, Markus Schneider-Pargmann ha scritto: > > From: Alexandre Bailon <abailon@baylibre.com> > > > > This updates the power domain to support WAY_EN operations. WAY_EN > > operations on mt8365 are using a different component to check for the > > acknowledgment, namely the infracfg-nao component. Also to enable a way > > it the bit needs to be cleared while disabling a way needs a bit to be > > set. To support these two operations two flags are added, > > BUS_PROT_INVERTED and BUS_PROT_STA_COMPONENT_INFRA_NAO. Additionally > > another regmap is created if the INFRA_NAO capability is set. > > > > This operation is required by the mt8365 for the MM power domain. > > > > Signed-off-by: Alexandre Bailon <abailon@baylibre.com> > > Signed-off-by: Fabien Parent <fparent@baylibre.com> > > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > > --- > > drivers/soc/mediatek/mtk-pm-domains.c | 39 +++++++++++++++++++++++---- > > drivers/soc/mediatek/mtk-pm-domains.h | 7 +++-- > > 2 files changed, 39 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c > > index 3cdf62c0b6bd..4659f0a0aa08 100644 > > --- a/drivers/soc/mediatek/mtk-pm-domains.c > > +++ b/drivers/soc/mediatek/mtk-pm-domains.c > > @@ -44,6 +44,7 @@ struct scpsys_domain { > > struct clk_bulk_data *clks; > > int num_subsys_clks; > > struct clk_bulk_data *subsys_clks; > > + struct regmap *infracfg_nao; > > struct regmap *infracfg; > > struct regmap *smi; > > struct regulator *supply; > > @@ -127,13 +128,26 @@ static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd, > > return pd->infracfg; > > } > > +static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_domain *pd, > > + const struct scpsys_bus_prot_data *bpd) > > +{ > > + if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) > > + return pd->infracfg_nao; > > + else > > + return scpsys_bus_protect_get_regmap(pd, bpd); > > +} > > + > > static int scpsys_bus_protect_clear(struct scpsys_domain *pd, > > const struct scpsys_bus_prot_data *bpd) > > { > > + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); > > struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); > > + u32 expected_ack; > > u32 val; > > u32 sta_mask = bpd->bus_prot_sta_mask; > > + expected_ack = (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO ? sta_mask : 0); > > + > > if (bpd->flags & BUS_PROT_REG_UPDATE) > > regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); > > else > > @@ -142,14 +156,15 @@ static int scpsys_bus_protect_clear(struct scpsys_domain *pd, > > if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) > > return 0; > > - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, > > - val, !(val & sta_mask), > > + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, > > + val, (val & sta_mask) == expected_ack, > > MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); > > } > > static int scpsys_bus_protect_set(struct scpsys_domain *pd, > > const struct scpsys_bus_prot_data *bpd) > > { > > + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); > > struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); > > u32 val; > > u32 sta_mask = bpd->bus_prot_sta_mask; > > @@ -159,7 +174,7 @@ static int scpsys_bus_protect_set(struct scpsys_domain *pd, > > else > > regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); > > - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, > > + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, > > val, (val & sta_mask) == sta_mask, > > MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); > > } > > @@ -173,7 +188,10 @@ static int scpsys_bus_protect_enable(struct scpsys_domain *pd) > > if (!bpd->bus_prot_set_clr_mask) > > break; > > - ret = scpsys_bus_protect_set(pd, bpd); > > + if (bpd->flags & BUS_PROT_INVERTED) > > + ret = scpsys_bus_protect_clear(pd, bpd); > > + else > > + ret = scpsys_bus_protect_set(pd, bpd); > > if (ret) > > return ret; > > } > > @@ -190,7 +208,10 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd) > > if (!bpd->bus_prot_set_clr_mask) > > continue; > > - ret = scpsys_bus_protect_clear(pd, bpd); > > + if (bpd->flags & BUS_PROT_INVERTED) > > + ret = scpsys_bus_protect_set(pd, bpd); > > + else > > + ret = scpsys_bus_protect_clear(pd, bpd); > > if (ret) > > return ret; > > } > > @@ -377,6 +398,14 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no > > return ERR_CAST(pd->smi); > > } > > + pd->infracfg_nao = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao"); > > If we don't expect infracfg-nao to be present, what's the point about trying to > get a regmap handle and then failing only if we do expect it to be there? > > At this point you can just do... > > if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) { > pd->infracfg_nao = syscon_regmap_lookup_by_phandle(...); > if (IS_ERR(....)) > return .... > } Yes! My code looks stupid. Thanks! > > > + if (IS_ERR(pd->infracfg_nao)) { > > + if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) > > + return ERR_CAST(pd->infracfg_nao); > > + > > + pd->infracfg_nao = NULL; > > + } > > + > > num_clks = of_clk_get_parent_count(node); > > if (num_clks > 0) { > > /* Calculate number of subsys_clks */ > > diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h > > index 356788263db2..562d4e92ce16 100644 > > --- a/drivers/soc/mediatek/mtk-pm-domains.h > > +++ b/drivers/soc/mediatek/mtk-pm-domains.h > > @@ -11,6 +11,7 @@ > > /* can't set MTK_SCPD_KEEP_DEFAULT_OFF at the same time */ > > #define MTK_SCPD_ALWAYS_ON BIT(5) > > #define MTK_SCPD_EXT_BUCK_ISO BIT(6) > > +#define MTK_SCPD_HAS_INFRA_NAO BIT(7) > > #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x)) > > #define SPM_VDE_PWR_CON 0x0210 > > @@ -45,8 +46,10 @@ > > enum scpsys_bus_prot_flags { > > BUS_PROT_REG_UPDATE = BIT(1), > > BUS_PROT_IGNORE_CLR_ACK = BIT(2), > > - BUS_PROT_COMPONENT_INFRA = BIT(3), > > - BUS_PROT_COMPONENT_SMI = BIT(4), > > + BUS_PROT_INVERTED = BIT(3), > > I get the reason why you're setting inverted as bit 3, but at that point you can > just set BUS_PROT_COMPONENT_INFRA to bit 4 from the very beginning, instead of > using bit 3 for that and then changing them all in a subsequent commit (this one). Yes, I was torn between making the commits independent and avoiding this move later on. I decided for the first. If you prefer I can set it to the correct bits right from the beginning. Best, Markus
Il 22/06/23 10:39, Markus Schneider-Pargmann ha scritto: > On Mon, Jun 19, 2023 at 11:29:18AM +0200, AngeloGioacchino Del Regno wrote: >> Il 19/06/23 10:53, Markus Schneider-Pargmann ha scritto: >>> From: Alexandre Bailon <abailon@baylibre.com> >>> >>> This updates the power domain to support WAY_EN operations. WAY_EN >>> operations on mt8365 are using a different component to check for the >>> acknowledgment, namely the infracfg-nao component. Also to enable a way >>> it the bit needs to be cleared while disabling a way needs a bit to be >>> set. To support these two operations two flags are added, >>> BUS_PROT_INVERTED and BUS_PROT_STA_COMPONENT_INFRA_NAO. Additionally >>> another regmap is created if the INFRA_NAO capability is set. >>> >>> This operation is required by the mt8365 for the MM power domain. >>> >>> Signed-off-by: Alexandre Bailon <abailon@baylibre.com> >>> Signed-off-by: Fabien Parent <fparent@baylibre.com> >>> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> >>> --- >>> drivers/soc/mediatek/mtk-pm-domains.c | 39 +++++++++++++++++++++++---- >>> drivers/soc/mediatek/mtk-pm-domains.h | 7 +++-- >>> 2 files changed, 39 insertions(+), 7 deletions(-) >>> >>> diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c >>> index 3cdf62c0b6bd..4659f0a0aa08 100644 >>> --- a/drivers/soc/mediatek/mtk-pm-domains.c >>> +++ b/drivers/soc/mediatek/mtk-pm-domains.c >>> @@ -44,6 +44,7 @@ struct scpsys_domain { >>> struct clk_bulk_data *clks; >>> int num_subsys_clks; >>> struct clk_bulk_data *subsys_clks; >>> + struct regmap *infracfg_nao; >>> struct regmap *infracfg; >>> struct regmap *smi; >>> struct regulator *supply; >>> @@ -127,13 +128,26 @@ static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd, >>> return pd->infracfg; >>> } >>> +static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_domain *pd, >>> + const struct scpsys_bus_prot_data *bpd) >>> +{ >>> + if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) >>> + return pd->infracfg_nao; >>> + else >>> + return scpsys_bus_protect_get_regmap(pd, bpd); >>> +} >>> + >>> static int scpsys_bus_protect_clear(struct scpsys_domain *pd, >>> const struct scpsys_bus_prot_data *bpd) >>> { >>> + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); >>> struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); >>> + u32 expected_ack; >>> u32 val; >>> u32 sta_mask = bpd->bus_prot_sta_mask; >>> + expected_ack = (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO ? sta_mask : 0); >>> + >>> if (bpd->flags & BUS_PROT_REG_UPDATE) >>> regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); >>> else >>> @@ -142,14 +156,15 @@ static int scpsys_bus_protect_clear(struct scpsys_domain *pd, >>> if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) >>> return 0; >>> - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, >>> - val, !(val & sta_mask), >>> + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, >>> + val, (val & sta_mask) == expected_ack, >>> MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); >>> } >>> static int scpsys_bus_protect_set(struct scpsys_domain *pd, >>> const struct scpsys_bus_prot_data *bpd) >>> { >>> + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); >>> struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); >>> u32 val; >>> u32 sta_mask = bpd->bus_prot_sta_mask; >>> @@ -159,7 +174,7 @@ static int scpsys_bus_protect_set(struct scpsys_domain *pd, >>> else >>> regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); >>> - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, >>> + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, >>> val, (val & sta_mask) == sta_mask, >>> MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); >>> } >>> @@ -173,7 +188,10 @@ static int scpsys_bus_protect_enable(struct scpsys_domain *pd) >>> if (!bpd->bus_prot_set_clr_mask) >>> break; >>> - ret = scpsys_bus_protect_set(pd, bpd); >>> + if (bpd->flags & BUS_PROT_INVERTED) >>> + ret = scpsys_bus_protect_clear(pd, bpd); >>> + else >>> + ret = scpsys_bus_protect_set(pd, bpd); >>> if (ret) >>> return ret; >>> } >>> @@ -190,7 +208,10 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd) >>> if (!bpd->bus_prot_set_clr_mask) >>> continue; >>> - ret = scpsys_bus_protect_clear(pd, bpd); >>> + if (bpd->flags & BUS_PROT_INVERTED) >>> + ret = scpsys_bus_protect_set(pd, bpd); >>> + else >>> + ret = scpsys_bus_protect_clear(pd, bpd); >>> if (ret) >>> return ret; >>> } >>> @@ -377,6 +398,14 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no >>> return ERR_CAST(pd->smi); >>> } >>> + pd->infracfg_nao = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao"); >> >> If we don't expect infracfg-nao to be present, what's the point about trying to >> get a regmap handle and then failing only if we do expect it to be there? >> >> At this point you can just do... >> >> if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) { >> pd->infracfg_nao = syscon_regmap_lookup_by_phandle(...); >> if (IS_ERR(....)) >> return .... >> } > > Yes! My code looks stupid. Thanks! > Hahaha, no worries! >> >>> + if (IS_ERR(pd->infracfg_nao)) { >>> + if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) >>> + return ERR_CAST(pd->infracfg_nao); >>> + >>> + pd->infracfg_nao = NULL; >>> + } >>> + >>> num_clks = of_clk_get_parent_count(node); >>> if (num_clks > 0) { >>> /* Calculate number of subsys_clks */ >>> diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h >>> index 356788263db2..562d4e92ce16 100644 >>> --- a/drivers/soc/mediatek/mtk-pm-domains.h >>> +++ b/drivers/soc/mediatek/mtk-pm-domains.h >>> @@ -11,6 +11,7 @@ >>> /* can't set MTK_SCPD_KEEP_DEFAULT_OFF at the same time */ >>> #define MTK_SCPD_ALWAYS_ON BIT(5) >>> #define MTK_SCPD_EXT_BUCK_ISO BIT(6) >>> +#define MTK_SCPD_HAS_INFRA_NAO BIT(7) >>> #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x)) >>> #define SPM_VDE_PWR_CON 0x0210 >>> @@ -45,8 +46,10 @@ >>> enum scpsys_bus_prot_flags { >>> BUS_PROT_REG_UPDATE = BIT(1), >>> BUS_PROT_IGNORE_CLR_ACK = BIT(2), >>> - BUS_PROT_COMPONENT_INFRA = BIT(3), >>> - BUS_PROT_COMPONENT_SMI = BIT(4), >>> + BUS_PROT_INVERTED = BIT(3), >> >> I get the reason why you're setting inverted as bit 3, but at that point you can >> just set BUS_PROT_COMPONENT_INFRA to bit 4 from the very beginning, instead of >> using bit 3 for that and then changing them all in a subsequent commit (this one). > > Yes, I was torn between making the commits independent and avoiding this > move later on. I decided for the first. If you prefer I can set it to > the correct bits right from the beginning. > I don't see how setting BUS_PROT_COMPONENT_INFRA to bit(4) from the beginning would add dependencies between commits. The first commit alone will still work, with the added benefit of less noise in this commit. You should, at that point, mention in the commit message that you're setting INFRA to BIT(4) because BIT(3) "is going to be populated in a later commit". That, unless anyone else has strong opinions against. Cheers, Angelo
diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c index 3cdf62c0b6bd..4659f0a0aa08 100644 --- a/drivers/soc/mediatek/mtk-pm-domains.c +++ b/drivers/soc/mediatek/mtk-pm-domains.c @@ -44,6 +44,7 @@ struct scpsys_domain { struct clk_bulk_data *clks; int num_subsys_clks; struct clk_bulk_data *subsys_clks; + struct regmap *infracfg_nao; struct regmap *infracfg; struct regmap *smi; struct regulator *supply; @@ -127,13 +128,26 @@ static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd, return pd->infracfg; } +static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_domain *pd, + const struct scpsys_bus_prot_data *bpd) +{ + if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) + return pd->infracfg_nao; + else + return scpsys_bus_protect_get_regmap(pd, bpd); +} + static int scpsys_bus_protect_clear(struct scpsys_domain *pd, const struct scpsys_bus_prot_data *bpd) { + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); + u32 expected_ack; u32 val; u32 sta_mask = bpd->bus_prot_sta_mask; + expected_ack = (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO ? sta_mask : 0); + if (bpd->flags & BUS_PROT_REG_UPDATE) regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); else @@ -142,14 +156,15 @@ static int scpsys_bus_protect_clear(struct scpsys_domain *pd, if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) return 0; - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, - val, !(val & sta_mask), + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, + val, (val & sta_mask) == expected_ack, MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); } static int scpsys_bus_protect_set(struct scpsys_domain *pd, const struct scpsys_bus_prot_data *bpd) { + struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); u32 val; u32 sta_mask = bpd->bus_prot_sta_mask; @@ -159,7 +174,7 @@ static int scpsys_bus_protect_set(struct scpsys_domain *pd, else regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); - return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, + return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, val, (val & sta_mask) == sta_mask, MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); } @@ -173,7 +188,10 @@ static int scpsys_bus_protect_enable(struct scpsys_domain *pd) if (!bpd->bus_prot_set_clr_mask) break; - ret = scpsys_bus_protect_set(pd, bpd); + if (bpd->flags & BUS_PROT_INVERTED) + ret = scpsys_bus_protect_clear(pd, bpd); + else + ret = scpsys_bus_protect_set(pd, bpd); if (ret) return ret; } @@ -190,7 +208,10 @@ static int scpsys_bus_protect_disable(struct scpsys_domain *pd) if (!bpd->bus_prot_set_clr_mask) continue; - ret = scpsys_bus_protect_clear(pd, bpd); + if (bpd->flags & BUS_PROT_INVERTED) + ret = scpsys_bus_protect_set(pd, bpd); + else + ret = scpsys_bus_protect_clear(pd, bpd); if (ret) return ret; } @@ -377,6 +398,14 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no return ERR_CAST(pd->smi); } + pd->infracfg_nao = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao"); + if (IS_ERR(pd->infracfg_nao)) { + if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) + return ERR_CAST(pd->infracfg_nao); + + pd->infracfg_nao = NULL; + } + num_clks = of_clk_get_parent_count(node); if (num_clks > 0) { /* Calculate number of subsys_clks */ diff --git a/drivers/soc/mediatek/mtk-pm-domains.h b/drivers/soc/mediatek/mtk-pm-domains.h index 356788263db2..562d4e92ce16 100644 --- a/drivers/soc/mediatek/mtk-pm-domains.h +++ b/drivers/soc/mediatek/mtk-pm-domains.h @@ -11,6 +11,7 @@ /* can't set MTK_SCPD_KEEP_DEFAULT_OFF at the same time */ #define MTK_SCPD_ALWAYS_ON BIT(5) #define MTK_SCPD_EXT_BUCK_ISO BIT(6) +#define MTK_SCPD_HAS_INFRA_NAO BIT(7) #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x)) #define SPM_VDE_PWR_CON 0x0210 @@ -45,8 +46,10 @@ enum scpsys_bus_prot_flags { BUS_PROT_REG_UPDATE = BIT(1), BUS_PROT_IGNORE_CLR_ACK = BIT(2), - BUS_PROT_COMPONENT_INFRA = BIT(3), - BUS_PROT_COMPONENT_SMI = BIT(4), + BUS_PROT_INVERTED = BIT(3), + BUS_PROT_COMPONENT_INFRA = BIT(4), + BUS_PROT_COMPONENT_SMI = BIT(5), + BUS_PROT_STA_COMPONENT_INFRA_NAO = BIT(6), }; #define _BUS_PROT(_set_clr_mask, _set, _clr, _sta_mask, _sta, _flags) { \