From patchwork Thu Jul 13 15:04:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 13312348 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 954ACC001B0 for ; Thu, 13 Jul 2023 15:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i7iC0EeNbzDODvzOC5o7PEOkz/XEGnPlT/ul2s+XgFY=; b=XCni4tqPthuzhI upPOnqACSh3TJaOFHbndS91DG3VdcR/NKnFkTJfDGy5JXhs8/UhY4yrk87XOoxNfWpgHpQEdVl5ac agClyp4D99pcBmFZKlNlEgMiDswwMyicQoVhgK0Vrod+jNASw70B/v15G+Uq4nwAIhXYdQXXu73yv u5q/h4aC8r6+AtzP/Z1c69MEBHQdv7wg4qEMtFxTGrQVVat3+GA3U9U8JkfZq4YyXIGT7Sz5JJ4/c ElSgxmZ3M8vpzRop0PCDd8g7SbpUfrQkbWE90bExI/ZtApynwXdzYyMWyXJZhd13WL7Ay+/RIFyH2 SDVia4bchVgtShntsoKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJxs8-003f3p-0U; Thu, 13 Jul 2023 15:04:48 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJxrr-003esX-20 for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 15:04:35 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-991c786369cso121762166b.1 for ; Thu, 13 Jul 2023 08:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1689260670; x=1691852670; 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=KZuj2vYwtu1q+1KUWNq9Rx/83sQjYgOtd/pHC+rLp7M=; b=RkOwDzpMuH2Q9wEvS+/gVNzvc/el3qTstPACqXVvJhgiFkyO7cPmPhjkqX8bY/QLbu u9SKdly9DwBumaoDqWYPBQ1978dW7/fouv1P0eozmwURIR0aJdPnUEa58U448y9oBKxB 5RBWiTAwtqECxcetJeECbX6/8qH6UTWahp0ZvOJ/6EJL6gEnol6jN4/Xw/0nbB8N4X+H Q48XYb8vfaAo7S2vdE0XM29Sx8zQeMXxUeM+gaUt5dlVONtiIoMr82nXBCef7KUcMgF+ XXBldbQz5isMQVIjGEw041lqXVa/Z3YxOYloRIFOMXVLhS4wnj0CpRzqFO+RMKQeNl5/ 8mcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689260670; x=1691852670; 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=KZuj2vYwtu1q+1KUWNq9Rx/83sQjYgOtd/pHC+rLp7M=; b=Z2RrucdcaC7jNYcidygT4AqqmLR01TVqoDodWS6poLB5a2geARu8T6Kc9Gy5npPZlz Mcejx/8XiARQduRFkTFN6OQBQFudxdl1v5gPlwvUSBVpa3ERcSiI9HgCLj1VMr0FsBle 8diuw3fKvV/NqxizTEGJeWPpK4BM/+W2nbQNs9DSUYm7WNDNXjFpwAyVr6ukO5rzmNpX IxPC02+qrM5fVeE0h7upisSiQlq9p2H4vZWx4UFQcv5scGEcYj7OijtGdrX+RrtX43OC ocHSYmoPxdpND4ccCn3s/3cREFKSvTka8b6E6DvvkO4QDq3Ct+Qci1amhsZZLKBVHlsg zX9A== X-Gm-Message-State: ABy/qLYbYJ+kSQOgB7tOHXzMUnQ2cnyYbhTWbHcChISlV3Gl/LR/3GAS vz8Zl00sIZyiDbUbq4max1S3lg== X-Google-Smtp-Source: APBJJlGQBOniWxQQ0p4125shOSawu+R4zWBBkYj1MASWCD7uyRwcaZd75TijtpdYHX2tDjuhURKpQw== X-Received: by 2002:a17:906:10d9:b0:98e:2b01:ab97 with SMTP id v25-20020a17090610d900b0098e2b01ab97mr1739243ejv.68.1689260670406; Thu, 13 Jul 2023 08:04:30 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a247:82fa:1d6d:d215:e7c4:dd5e]) by smtp.gmail.com with ESMTPSA id cd26-20020a170906b35a00b009929c39d5c4sm4102939ejb.36.2023.07.13.08.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 08:04:30 -0700 (PDT) From: Markus Schneider-Pargmann To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger Cc: Chun-Jie Chen , AngeloGioacchino Del Regno , Tinghan Shen , Fabien Parent , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Markus Schneider-Pargmann , Alexandre Mergnat Subject: [PATCH v7 4/8] soc: mediatek: pm-domains: Create bus protection operation functions Date: Thu, 13 Jul 2023 17:04:10 +0200 Message-Id: <20230713150414.891893-5-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713150414.891893-1-msp@baylibre.com> References: <20230713150414.891893-1-msp@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_080431_660700_3B5DEA32 X-CRM114-Status: GOOD ( 13.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Separate the register access used for bus protection enable/disable into their own functions. These will be used later for WAY_EN support. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Alexandre Mergnat Tested-by: Alexandre Mergnat --- drivers/soc/mediatek/mtk-pm-domains.c | 68 +++++++++++++++------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c index a2c8f5313124..a7a46fb132ee 100644 --- a/drivers/soc/mediatek/mtk-pm-domains.c +++ b/drivers/soc/mediatek/mtk-pm-domains.c @@ -118,26 +118,50 @@ static int scpsys_sram_disable(struct scpsys_domain *pd) MTK_POLL_TIMEOUT); } +static int scpsys_bus_protect_clear(const struct scpsys_bus_prot_data *bpd, + struct regmap *regmap) +{ + u32 sta_mask = bpd->bus_prot_sta_mask; + u32 val; + + if (bpd->flags & BUS_PROT_REG_UPDATE) + regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); + else + regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); + + if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) + return 0; + + return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, + val, !(val & sta_mask), + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); +} + +static int scpsys_bus_protect_set(const struct scpsys_bus_prot_data *bpd, + struct regmap *regmap) +{ + u32 sta_mask = bpd->bus_prot_sta_mask; + u32 val; + + if (bpd->flags & BUS_PROT_REG_UPDATE) + regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); + else + regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); + + return regmap_read_poll_timeout(regmap, bpd->bus_prot_sta, + val, (val & sta_mask) == sta_mask, + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); +} + static int _scpsys_bus_protect_enable(const struct scpsys_bus_prot_data *bpd, struct regmap *regmap) { int i, ret; for (i = 0; i < SPM_MAX_BUS_PROT_DATA; i++) { - u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask; - u32 sta_mask = bpd[i].bus_prot_sta_mask; - u32 val; - - if (!set_clr_mask) + if (!bpd[i].bus_prot_set_clr_mask) break; - if (bpd[i].flags & BUS_PROT_REG_UPDATE) - regmap_set_bits(regmap, bpd[i].bus_prot_set, set_clr_mask); - else - regmap_write(regmap, bpd[i].bus_prot_set, set_clr_mask); - - ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta, - val, (val & sta_mask) == sta_mask, - MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + ret = scpsys_bus_protect_set(&bpd[i], regmap); if (ret) return ret; } @@ -162,24 +186,10 @@ static int _scpsys_bus_protect_disable(const struct scpsys_bus_prot_data *bpd, int i, ret; for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) { - u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask; - u32 sta_mask = bpd[i].bus_prot_sta_mask; - u32 val; - - if (!set_clr_mask) - continue; - - if (bpd[i].flags & BUS_PROT_REG_UPDATE) - regmap_clear_bits(regmap, bpd[i].bus_prot_clr, set_clr_mask); - else - regmap_write(regmap, bpd[i].bus_prot_clr, set_clr_mask); - - if (bpd[i].flags & BUS_PROT_IGNORE_CLR_ACK) + if (!bpd[i].bus_prot_set_clr_mask) continue; - ret = regmap_read_poll_timeout(regmap, bpd[i].bus_prot_sta, - val, !(val & sta_mask), - MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + ret = scpsys_bus_protect_clear(&bpd[i], regmap); if (ret) return ret; }