Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1378000ybi; Wed, 19 Jun 2019 19:39:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzoiq9ROxpBJao+aOTLeGikDGoEQfRvw0SvkJkoyz7KIGKjO93nWnrBEmyCMQ0XT9Rux3Fh X-Received: by 2002:a62:3c3:: with SMTP id 186mr10566039pfd.21.1560998354830; Wed, 19 Jun 2019 19:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560998354; cv=none; d=google.com; s=arc-20160816; b=tVvOetRO2r0HEPElfaeHKA6bbxzS1fSqtaXzhWY5Cr+9Y3Wnq+5Q3tCYHWUY42rTpv wdlk8Sd/zwn+yFsoIEVt/TmJu/ovg9J6FCTiAafToPUaNE6FZoolA5fcuCn1UKIZGQky LKQr6VKj1HAtpDMZdc56HnyqREGwXrc0TC1+xZn8k5sMEK5ocvthl5fyJqvOz1dm2jhF o5/Qr7eX/lCMl7DrpCHiX0HdNMtXwydS4mwQFACIMWYgo3G/thf5iY9LcAriGoPaSXXs 2a4xmo5Rc9dLIJ8hqyzsjOTVzXiQmZLCv9LATgu76Z3DbGIeUShKNYEph3SYZde5IfPn 01RA== 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=E98Xj+9R5T2RZsxSpDQ2iWHMi0LX1rAHMiZ4zQWZypA=; b=InfqMe9iC6bFBDL8ac3DABwzjxIbI0nin+SswIU0ixD5Pt31W65JSzp6H0IlD5hZ2W cf4Mo1aYaO1mpCCRu6EC5xA0agDZ4lVVVqyeZVqHN75j1FLmB7m9QJ1yX0Iy1b4Hrq6R /VbNX0zAKDQfM/FYWpOmdJ/iKTtomRoxfP0e73XD2qlMv9eTLJgmyQ0/chL3HAJARVjS BE6JHx3/boY1GQshnw2NO7tx7YAwjN3MZbEzCSOl6nUWcmFaPxF3P0fq9SHSyTgGt2D0 NILPBpDqCLxxRyiVvuPmaJ5JgIpZs8Hhb7jg/CYfbYE/k5CcRMILlJ9nOrO0SC0pXw1J nloQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si4638264pgh.253.2019.06.19.19.38.59; Wed, 19 Jun 2019 19:39:14 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731580AbfFTCim (ORCPT + 99 others); Wed, 19 Jun 2019 22:38:42 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:63894 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731393AbfFTCig (ORCPT ); Wed, 19 Jun 2019 22:38:36 -0400 X-UUID: 62ee20090a25452fac4c73e336be049e-20190620 X-UUID: 62ee20090a25452fac4c73e336be049e-20190620 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1491762159; Thu, 20 Jun 2019 10:38:20 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 20 Jun 2019 10:38:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 20 Jun 2019 10:38:19 +0800 From: Weiyi Lu To: Nicolas Boichat , Matthias Brugger , Rob Herring CC: James Liao , Fan Chen , , , , , Weiyi Lu , Yong Wu Subject: [PATCH v6 06/14] soc: mediatek: Refactor clock control Date: Thu, 20 Jun 2019 10:37:58 +0800 Message-ID: <1560998286-9189-7-git-send-email-weiyi.lu@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1560998286-9189-1-git-send-email-weiyi.lu@mediatek.com> References: <1560998286-9189-1-git-send-email-weiyi.lu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: C634D6192B9CAFB2B23B6D42EC8F5BCF7EEE8EC8F02001862F004CB784B1DF612000:8 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 1a6a4ab..5b73e4e 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