Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp578612ybl; Wed, 28 Aug 2019 02:13:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoxJB4ViMjTR7zl4WMvSH28PhN0Ddc9PUfdZ46mSiKz1q4X7L10Ducwo56pbxv6+aY7FZi X-Received: by 2002:a17:902:2b87:: with SMTP id l7mr3059791plb.165.1566983632300; Wed, 28 Aug 2019 02:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566983632; cv=none; d=google.com; s=arc-20160816; b=skn3lX72MjDj5tSVANppAtj/E4Yzd6EfrI1sIV7fWQvWsF8lYEdFC6gKf5A9xnZvsE 55kNPz84eQ+f6Lidfb6ChQVXL3l2TayFoN1s7AKadxymu5mCXcB2KZ0EYvdmoGjFnVkr RF4wxih908vc8nnYOsYC7u+D36DTHB40PcriJN2YDu3LudMcoScH0ZeW1pRn51Wx38AT xJYr54MqDLqsR2+rxbQSng83ftOAB6jSFfADY1npuksobTqJissfLAd6pJqupon27A7f BFVBu4ZWJZb93BGHB1xBHNBzFoLccnx0zPDJXWV3IbMKUY4sJYqPgJxI2adnvuSZVY28 gH1w== 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=xmD+g87rYTqjtDQjz8aQY2EnKfiqBmdMEzqm/X0HzdU=; b=lBZ+HD6xvop4F8Y1jDW1UK2r/cHIj7XJDNN3OLRHfCBmV72yr5hjQ79nmE3UvLoxLH 4ZYHp0u/uXQsylPCCKhydwe8QO/u8o1RWlL6WyWOznYyp8OEzjcHD1RllfMfy6Xh1M4b UVFuf/aqMkHkn8LKd61fO1uMJ4kcX9ZVYb5Tl970wZf32RjaQhhAHHDvji/l3aVVilnm 2UfLaX1m4GQgXHPymknfPxn+YaYV6AHoqSde9bDq5/Bb0r0PQzNvj0je4zPdh/tp48FH kLgcIenXmRawre4/9RpMTKxX10olQztHTmj0UEWdEHriHhBiapkoXGKDdyjkXUkT5WV7 w1yg== 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 l94si1415495plb.161.2019.08.28.02.13.36; Wed, 28 Aug 2019 02:13:52 -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 S1726805AbfH1JMJ (ORCPT + 99 others); Wed, 28 Aug 2019 05:12:09 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:15642 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726591AbfH1JME (ORCPT ); Wed, 28 Aug 2019 05:12:04 -0400 X-UUID: 46ad4d2d333444c1ab1360fb7f5b3290-20190828 X-UUID: 46ad4d2d333444c1ab1360fb7f5b3290-20190828 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 154428683; Wed, 28 Aug 2019 17:11:58 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n1.mediatek.inc (172.21.101.77) 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 05/13] soc: mediatek: Refactor clock control Date: Wed, 28 Aug 2019 17:11:38 +0800 Message-ID: <1566983506-26598-6-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 clock enable and disable control in separate function. Signed-off-by: Weiyi Lu --- drivers/soc/mediatek/mtk-scpsys.c | 45 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c index aed540d..73e4a1a 100644 --- a/drivers/soc/mediatek/mtk-scpsys.c +++ b/drivers/soc/mediatek/mtk-scpsys.c @@ -207,6 +207,29 @@ static int scpsys_regulator_disable(struct scp_domain *scpd) return regulator_disable(scpd->supply); } +static void scpsys_clk_disable(struct clk *clk[], int max_num) +{ + int i; + + for (i = max_num - 1; i >= 0; i--) + clk_disable_unprepare(clk[i]); +} + +static int scpsys_clk_enable(struct clk *clk[], int max_num) +{ + int i, ret = 0; + + for (i = 0; i < max_num && clk[i]; i++) { + ret = clk_prepare_enable(clk[i]); + if (ret) { + scpsys_clk_disable(clk, i); + break; + } + } + + return ret; +} + static int scpsys_power_on(struct generic_pm_domain *genpd) { struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd); @@ -215,21 +238,14 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 val; int ret, tmp; - int i; ret = scpsys_regulator_enable(scpd); if (ret < 0) return ret; - for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++) { - ret = clk_prepare_enable(scpd->clk[i]); - if (ret) { - for (--i; i >= 0; i--) - clk_disable_unprepare(scpd->clk[i]); - - goto err_clk; - } - } + ret = scpsys_clk_enable(scpd->clk, MAX_CLKS); + if (ret) + goto err_clk; val = readl(ctl_addr); val |= PWR_ON_BIT; @@ -282,10 +298,7 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) return 0; err_pwr_ack: - for (i = MAX_CLKS - 1; i >= 0; i--) { - if (scpd->clk[i]) - clk_disable_unprepare(scpd->clk[i]); - } + scpsys_clk_disable(scpd->clk, MAX_CLKS); err_clk: scpsys_regulator_disable(scpd); @@ -302,7 +315,6 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 val; int ret, tmp; - int i; if (scpd->data->bus_prot_mask) { ret = mtk_infracfg_set_bus_protection(scp->infracfg, @@ -343,8 +355,7 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) if (ret < 0) goto out; - for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++) - clk_disable_unprepare(scpd->clk[i]); + scpsys_clk_disable(scpd->clk, MAX_CLKS); ret = scpsys_regulator_disable(scpd); if (ret < 0) -- 1.8.1.1.dirty