Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp578113ybl; Wed, 28 Aug 2019 02:13:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqWXzVyhclZZ0CThkj4ikBmyqIFDPCK8b6bR7lJf77COmmxUBvh21O+GiP0GcuPy3g3iB6 X-Received: by 2002:a17:90a:2047:: with SMTP id n65mr3286208pjc.5.1566983601093; Wed, 28 Aug 2019 02:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566983601; cv=none; d=google.com; s=arc-20160816; b=es9tMMmEZz4U4gHvHImXovJvcpr2D9FoNRYIsJV/HZp9tNmzCdE9HXQ45nj42d6WZN KL402rF2pltpNSqgrGFX7/l7FNNIGqux3H2HQyI45jRJLAOgANdr6wehPi4mdyb08POL O5KSbMUrlxS1Egn4QOO3X7S3dAOAXs1cpQPFDOlJM4sa9q+VoQruVN52xgK+OEyWkQdo GPpfOjJKUkmiOca585hsWwi4wA44Gyq3LjU5EAw9ww5QnPx6apvjV69Jf2NRS57WYeW2 T/bPhOobJrIM7tOPYyvg7o3u29bhAo9i7C3E98ZXb0oB/W0cokWoAO+n2Bn1eaPgTpuz m9gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=MnaQRaAxeYkX3plJUychWHcpH5zzJSzzcrcT6BOrLXo=; b=RGLZEwq6tlJIPJ6ZGUT9+XEuerwakjbit56zf/ZjKcIiQzpSsVvn/7i38uMvrl1mTz ziZbl2/YQ7Pct59fTq/WLCaMyuOhYa/Kw8gfHv+Z09KKtLkb9J2YpJLqoEybOgnLLTnB z1UM9XnGKsc0vW0GFDoeH5FjG0FotjivN+xVOgAWy5UhTRm3FG0RnsgAOARkj97C3myz 6fj0zSOW0ndPhXHYob4118I1McssZRyKp8bbzXVCelL164UEIfcHMZ4cN7SvOWLNBhl5 9EAiLdLAIvaAFqIPUmIOaYZ/ml9GAB9KSSAIlRPBZPwJsE83NZuJ2oKBIiJiFAaFvhgC qjog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11si1759460pga.407.2019.08.28.02.13.05; Wed, 28 Aug 2019 02:13:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726548AbfH1JMH (ORCPT + 99 others); Wed, 28 Aug 2019 05:12:07 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:52746 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726504AbfH1JME (ORCPT ); Wed, 28 Aug 2019 05:12:04 -0400 X-UUID: 6267c724433d4a96b2669eb7b9539ac7-20190828 X-UUID: 6267c724433d4a96b2669eb7b9539ac7-20190828 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 316778059; Wed, 28 Aug 2019 17:11:59 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 28 Aug 2019 17:12:04 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 28 Aug 2019 17:12:04 +0800 From: Weiyi Lu To: Nicolas Boichat , Matthias Brugger , Rob Herring CC: James Liao , Fan Chen , , , , , Weiyi Lu , Yong Wu Subject: [PATCH v7 06/13] soc: mediatek: Refactor sram control Date: Wed, 28 Aug 2019 17:11:39 +0800 Message-ID: <1566983506-26598-7-git-send-email-weiyi.lu@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1566983506-26598-1-git-send-email-weiyi.lu@mediatek.com> References: <1566983506-26598-1-git-send-email-weiyi.lu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Put sram enable and disable control in separate functions. Signed-off-by: Weiyi Lu Reviewed-by: Nicolas Boichat --- drivers/soc/mediatek/mtk-scpsys.c | 79 +++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c index 73e4a1a..ad0f619 100644 --- a/drivers/soc/mediatek/mtk-scpsys.c +++ b/drivers/soc/mediatek/mtk-scpsys.c @@ -230,12 +230,55 @@ static int scpsys_clk_enable(struct clk *clk[], int max_num) return ret; } +static int scpsys_sram_enable(struct scp_domain *scpd, void __iomem *ctl_addr) +{ + u32 val; + u32 pdn_ack = scpd->data->sram_pdn_ack_bits; + int tmp; + + val = readl(ctl_addr) & ~scpd->data->sram_pdn_bits; + writel(val, ctl_addr); + + /* Either wait until SRAM_PDN_ACK all 0 or have a force wait */ + if (MTK_SCPD_CAPS(scpd, MTK_SCPD_FWAIT_SRAM)) { + /* + * Currently, MTK_SCPD_FWAIT_SRAM is necessary only for + * MT7622_POWER_DOMAIN_WB and thus just a trivial setup + * is applied here. + */ + usleep_range(12000, 12100); + } else { + /* Either wait until SRAM_PDN_ACK all 1 or 0 */ + int ret = readl_poll_timeout(ctl_addr, tmp, + (tmp & pdn_ack) == 0, + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + if (ret < 0) + return ret; + } + + return 0; +} + +static int scpsys_sram_disable(struct scp_domain *scpd, void __iomem *ctl_addr) +{ + u32 val; + u32 pdn_ack = scpd->data->sram_pdn_ack_bits; + int tmp; + + val = readl(ctl_addr) | scpd->data->sram_pdn_bits; + writel(val, ctl_addr); + + /* Either wait until SRAM_PDN_ACK all 1 or 0 */ + return readl_poll_timeout(ctl_addr, tmp, + (tmp & pdn_ack) == pdn_ack, + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); +} + static int scpsys_power_on(struct generic_pm_domain *genpd) { struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd); struct scp *scp = scpd->scp; void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; - u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 val; int ret, tmp; @@ -247,6 +290,7 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) if (ret) goto err_clk; + /* subsys power on */ val = readl(ctl_addr); val |= PWR_ON_BIT; writel(val, ctl_addr); @@ -268,24 +312,9 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) val |= PWR_RST_B_BIT; writel(val, ctl_addr); - val &= ~scpd->data->sram_pdn_bits; - writel(val, ctl_addr); - - /* Either wait until SRAM_PDN_ACK all 0 or have a force wait */ - if (MTK_SCPD_CAPS(scpd, MTK_SCPD_FWAIT_SRAM)) { - /* - * Currently, MTK_SCPD_FWAIT_SRAM is necessary only for - * MT7622_POWER_DOMAIN_WB and thus just a trivial setup is - * applied here. - */ - usleep_range(12000, 12100); - - } else { - ret = readl_poll_timeout(ctl_addr, tmp, (tmp & pdn_ack) == 0, - MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); - if (ret < 0) - goto err_pwr_ack; - } + ret = scpsys_sram_enable(scpd, ctl_addr); + if (ret < 0) + goto err_pwr_ack; if (scpd->data->bus_prot_mask) { ret = mtk_infracfg_clear_bus_protection(scp->infracfg, @@ -312,7 +341,6 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd); struct scp *scp = scpd->scp; void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; - u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 val; int ret, tmp; @@ -324,17 +352,12 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) goto out; } - val = readl(ctl_addr); - val |= scpd->data->sram_pdn_bits; - writel(val, ctl_addr); - - /* wait until SRAM_PDN_ACK all 1 */ - ret = readl_poll_timeout(ctl_addr, tmp, (tmp & pdn_ack) == pdn_ack, - MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + ret = scpsys_sram_disable(scpd, ctl_addr); if (ret < 0) goto out; - val |= PWR_ISO_BIT; + /* subsys power off */ + val = readl(ctl_addr) | PWR_ISO_BIT; writel(val, ctl_addr); val &= ~PWR_RST_B_BIT; -- 1.8.1.1.dirty