From patchwork Mon Jun 19 08:53:40 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: 109837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2865809vqr; Mon, 19 Jun 2023 02:13:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6r688IE+5M0UvugYZQkIzgRw0jmkPPrIJj1crSa2VetLIVqrYISih99eLGdsDSBru8i2IX X-Received: by 2002:a17:90a:6f44:b0:25b:e747:103 with SMTP id d62-20020a17090a6f4400b0025be7470103mr6859796pjk.26.1687165984137; Mon, 19 Jun 2023 02:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687165984; cv=none; d=google.com; s=arc-20160816; b=M7hCHF5uSwupLy4Dn5UHaONJ1Y9TFzuOMbELMtoCtMwR5PYOX5uf2mSlujPnWrEtg+ +cRmKk39tNS8YwfH3USj9m8h8r7rpo2BeuPw3qcOzOY6ianCSHL0Nln8yn34/eRzwHTc qwcHGHPeNaelQ8b5fR4KtftEQ1mbiK1zYpWWgljhsCvrCeWWfATH5B7uloJ+Ky2II7zx zbfFkpVOvGrX1tbGpQbWOXDwC1ObsvCuQArcX4QpWvMuwZM6HQdT/nAgf/SLRNxBNorM AqlohFV08G84wncXpVOgWaEtSQ0onaKc03SdPs8wf8OmtwSkgiw1UO0GpcgT3kjn1gyE AfrA== 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=0VMYcJx4syxwuFnZnbvKqO4Q62miCTx6QaRJP3Gp1m0=; b=ynKBgRvGsC8DuqHZb7PCUNBK19lu7cnha4akAmWTUuYORf948jLtKZpJpHKDpJHECf wg2PwIuWflcnoei27M9fL1E6BqCLAV3JJCDBXpGbJkewZdId+XoAhHvlPd+80CMe8Bpp BzGFmh95JlW1EFPglT6sWlx0jhp27+ywy/rmWZ+hfR1KZi9ztOcYAj5hULjFUn2zn2yc xEEHKYY9nZJDSmVnqiFZkl8PyCJABHtTqcurkYW1Y2JsiSFAAwREZ9BuFgM7ENmbEhf8 T2ZzvNr7AdX8WO+ild4fN4oJr9kCK/P66hKBL8ibrrQH9jWS/HqWKQA0yy3tSW1hwlrc ACPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=QHUpnbLE; 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 k191-20020a6384c8000000b005539083748bsi4567516pgd.557.2023.06.19.02.12.52; Mon, 19 Jun 2023 02:13:04 -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=QHUpnbLE; 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 S230268AbjFSI4q (ORCPT + 99 others); Mon, 19 Jun 2023 04:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231377AbjFSIzA (ORCPT ); Mon, 19 Jun 2023 04:55:00 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A938F1FFF for ; Mon, 19 Jun 2023 01:54:17 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9875c2d949eso371350466b.0 for ; Mon, 19 Jun 2023 01:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687164856; x=1689756856; 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=0VMYcJx4syxwuFnZnbvKqO4Q62miCTx6QaRJP3Gp1m0=; b=QHUpnbLE4GpFmuCSRefmD3Pko5gtbPF4GpACs4WRcou1fnSIl+rblooEjH5kaeFrzr zPefZ3TrQI1aE6N4YXrYCvch9lUd4UG4M1jzDn8ef7oWHYbDEunqfvKMw6JqjPtIBLWj gVZLNvCIde0mhjMM0fCXCaB0r1r5F6SG0uSrtgxfUtR9cPDyAv0h2jFVYric3XvnnT7d BHzLZ+VARTIUGwbpQbirdhUQS7PtQp2lCLRzTOV6kG9BhCINzuo1EE6f0pqjryupyiUT 2Lhhm87/iwC6t0A1gp1iL6icJbMt/9MqbwT4+udoN0ckWmFPHgPTkRv1LcSHce7HVmuj HFQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687164856; x=1689756856; 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=0VMYcJx4syxwuFnZnbvKqO4Q62miCTx6QaRJP3Gp1m0=; b=gB6w71cZVCYg9VmwYD4Oc2CiCGQIqef7D1TA3/gXwrsmGdV9aoC85vcduwOEuMNBxP GyxjWutvOnmJjbAEw/a3RMBucgEqhfflvrVTS87P0XsQ/II0hmPh6lYhA0A+TVBS0CA/ J1C+JIASuVrSJpt5mqk6J158RpgzxZjPX/7UH5wXRNjHN2ZM3hNMZsav8ZYlf2Cc8jih dICHikkCcZCEt8eLRH+ebuwSPnAZ6qMY1lOYSKD20s2PrDLqWqtRT8SqB+QeM/io+hwk uLPwrn4lcEsiItLKi/qDGIgcUjWnH9YExIsidfjhsyoBMkPIPXjpxR1AMORkL7h3J90V MnIQ== X-Gm-Message-State: AC+VfDyuPq7n9ElTESQ5AaaGElX9jdXPCqSyzhOmRaugoAxpxfYoDFzc RalogLYmnFktJR9c3JHyjxIVmg== X-Received: by 2002:a17:907:3e16:b0:978:a186:464f with SMTP id hp22-20020a1709073e1600b00978a186464fmr9665265ejc.39.1687164856178; Mon, 19 Jun 2023 01:54:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 01:54:15 -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 Subject: [PATCH v5 4/8] soc: mediatek: pm-domains: Create bus protection operation functions Date: Mon, 19 Jun 2023 10:53:40 +0200 Message-Id: <20230619085344.2885311-5-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 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769121759047469346?= X-GMAIL-MSGID: =?utf-8?q?1769121759047469346?= 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 --- 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 c801fa763e89..69dc24a73ce9 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 val; + u32 sta_mask = bpd->bus_prot_sta_mask; + + 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 val; + u32 sta_mask = bpd->bus_prot_sta_mask; + + 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 val; - u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask; - u32 sta_mask = bpd[i].bus_prot_sta_mask; - - 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 val; - u32 set_clr_mask = bpd[i].bus_prot_set_clr_mask; - u32 sta_mask = bpd[i].bus_prot_sta_mask; - - 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; }