From patchwork Mon Sep 18 09:37:48 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: 141346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2559649vqi; Mon, 18 Sep 2023 03:43:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkJY+LWzRDXloXGc3JK9h1PIN7AQh6jsWQsroc9uHND8lNouT5Yp/lcDlxAe41DlDjxMhF X-Received: by 2002:a05:6a21:3d89:b0:153:6e99:edbb with SMTP id bj9-20020a056a213d8900b001536e99edbbmr6812114pzc.31.1695033817336; Mon, 18 Sep 2023 03:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695033817; cv=none; d=google.com; s=arc-20160816; b=MXm9A3G6jqL76zl/Y7Xt2QLMkab17I3tXwNqF8DYG5Npe96pV8lI/u3pzDaqCIcFkk u6pz7T6sz2mKuhm1qIVIYh7iJD1bFB3FsAFMaUZqP6jU9KJOX1OA09pBNOOss42KChz9 hxnKRYKxo44nAVowhewvA9LPAkyqXy6qSYPndj+QM0r4heffKNM7uAWL0mkrT1UgPJME 0PrUnyyVXah/5FV80rwNgTfJsqJFT8TY/kiLE2MmFTfCHt2Fc8PNCub2ZE1zQjc2NT5B OLAyxOWVpO02TlEmvXDKlspbB9XvhcxOXULrXYXSd1azE2pKtuxVZ0Ag/Ov6jXt+PKeI EbzQ== 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=xmBaiRUeRt+55ioUYPSma19exdAZQxKKsEgvUwNh0oM=; fh=RUoqLuZuITlmATQNBnxyoemQD0RKvHH0dT8r5B4O084=; b=NLt4faILfvFjugWntdTSqZ4+DyzMkpztSjsJ58WKN5Knp4LlSx1tzVEFsMA7cSL+Hm BGVqUaNsvdLEaWufqHMEDQB86Fb38ydpsOxMkE7xOSAy+F3d3NaM7DaGQ44k9CDawB+r JQ+jbzZhPwISn9E+aPpYkd9vCnrXni6oHG5xicX64BTn3lvrCi9cCo5v5zrqNHR+t4/U kfUctK9ZF1mq2jTpp+p7XYHTbQjE5P9HwPxUDndXQH5+ZSpuRr1mfbHT0GAtpkfIMwXN 0SoNh3Y/ee+xdsSEyMZC2uY53KjKVoq0lVJ94YAAQP1QvInFaA0ylPXKpK60zMoQmS+r EyJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="c3ki/w0S"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ay7-20020a056a00300700b0068fdb00659bsi7930965pfb.366.2023.09.18.03.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:43:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="c3ki/w0S"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4CE5880B5A34; Mon, 18 Sep 2023 02:39:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241009AbjIRJjC (ORCPT + 27 others); Mon, 18 Sep 2023 05:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240956AbjIRJib (ORCPT ); Mon, 18 Sep 2023 05:38:31 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA1D12A for ; Mon, 18 Sep 2023 02:38:24 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9adb9fa7200so860869066b.0 for ; Mon, 18 Sep 2023 02:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695029902; x=1695634702; darn=vger.kernel.org; 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=xmBaiRUeRt+55ioUYPSma19exdAZQxKKsEgvUwNh0oM=; b=c3ki/w0S+YubNQMMl6TmdYKr7O5VTC/qC3iV0wB/dbkJd5Z9g2g9pNAsehpoVUqUoo zNqbD6ZpWFUJ/x1sZ/5lVDcD2fkztqZIowQsWt7h5cPnzUfV5dzlhm1YWLjWIu3gaqGF hoMfPaJe8Q8d57FhbdPD4sTdgme/S611Yz/0g2rlRqwabaKL78kBxfLMN/4bCoRnGgsY QcaU+EFkt4EW98cmIBzdChaZd1CjMyUji5myKa8XzdKIMHoZyL9aUhAWZb8ahLhTcvLT DJpILqW6TdKRdSCMPCAz7Qxeo3DXcvcqqqLXxNVk3fg+iAotuyO9d6ytZRGZHjYMAbZ8 +XlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695029902; x=1695634702; 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=xmBaiRUeRt+55ioUYPSma19exdAZQxKKsEgvUwNh0oM=; b=QG/g5RS03CqsZqcG6IDwQKYyu6SlmemrmEvNuxc8N8lJlXlP3eEIVKSSfj214lE7Dk csF4HYAJFtzwl9f6lMfMGMSFDheumHLa0SfGoGSWLqBv5oMOy5XVvNqf6KxYC7pCrF9P pKGsgWPewY8rnxz28tDtQH2JEn7i0BdN7Y8f+CRuHvJQxsVHB0UfXSFEPyzVxTguRkgI XJZKcb7Xz4+K4IDYCINF17Mi4Wugz0oDakvoZAXE/lzol5y4t6kut2s4Wo81TN8GQBJH 5XH+B1nAzDleIENifEi/nC3PKMqOsAmxlYzPGxChJEng9+YcBjJlTbuiSzjCkw9OCF7D wkGg== X-Gm-Message-State: AOJu0YzHYe1uGZS7xUqLnoIDu+UhcK4n2sCSqtIIh5APu/Tbq4YrEB/+ ix/rQmzKlrOIg5RvOA6vp4qv4A== X-Received: by 2002:a17:906:dc8b:b0:96f:9cea:a34d with SMTP id cs11-20020a170906dc8b00b0096f9ceaa34dmr15647396ejc.21.1695029902555; Mon, 18 Sep 2023 02:38:22 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a246:8222:872:4a5b:b69c:1318]) by smtp.gmail.com with ESMTPSA id o10-20020a1709061d4a00b0099293cdbc98sm6251164ejh.145.2023.09.18.02.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 02:38:22 -0700 (PDT) From: Markus Schneider-Pargmann To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger Cc: Ulf Hansson , Alexandre Mergnat , Chun-Jie Chen , AngeloGioacchino Del Regno , Tinghan Shen , Fabien Parent , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Markus Schneider-Pargmann Subject: [PATCH v8 4/8] soc: mediatek: pm-domains: Create bus protection operation functions Date: Mon, 18 Sep 2023 11:37:48 +0200 Message-Id: <20230918093751.1188668-5-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230918093751.1188668-1-msp@baylibre.com> References: <20230918093751.1188668-1-msp@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 02:39:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777371779969027497 X-GMAIL-MSGID: 1777371779969027497 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/pmdomain/mediatek/mtk-pm-domains.c | 68 +++++++++++++--------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c b/drivers/pmdomain/mediatek/mtk-pm-domains.c index dbb268e96310..5b694fde7b56 100644 --- a/drivers/pmdomain/mediatek/mtk-pm-domains.c +++ b/drivers/pmdomain/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; }