Received: by 10.213.65.68 with SMTP id h4csp3207822imn; Tue, 3 Apr 2018 00:19:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/uU/aZqo1DYZFWt3G2jx772y1cDQoTpe+D7rFSGoA1BhTZa63yBP5W1yE1U6sUqmwlXnPL X-Received: by 2002:a17:902:7798:: with SMTP id o24-v6mr2176701pll.349.1522739959317; Tue, 03 Apr 2018 00:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522739959; cv=none; d=google.com; s=arc-20160816; b=hJ9FuGxsps/a4Y9XAjiLztlPKloQBxQV0aSJ20bteaIYHSPcFkrzCEspwd7G983O+V KkiK3YD/T8K9QWnG2Cdy7b1XdETisksKOOMVv4h1SCk5u810W7D+1Jkx4yuJNVdJVp1V ftCJT+2qqqLj8sxSfa+RglVR+sWApvpg46uSUIs8TK90ngx/B7elbS+sonnkM+SJUF1z AMmB/hnjncowRsOqcyDQHwAwIOs23Xyr0IB1eXR7VjTx6I52iAutn5730B6cf9TM48eG QAapVtbpxpW1R86Q6DCm/CiHoiY72/BtBxAilTOeYWF9xHjcGnu88BDI4XQt2eqxcL1K bQYQ== 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:arc-authentication-results; bh=g8YfhDWO/NMJvC7Sw188DBrciDtBfazp8Mm3jIE17DM=; b=q2GmmEcKethjN3VwyaIbDVPmTRrkbVOg3Vku7QRDskn+PUgBIOfPcUqpEKwooV0UE6 8J6DwHf7EM42I0U/m+Tjgu7HZYQdcw93rVq7w7m+y5zY5GrQVnXn8whY+lvonf0ooT75 peB5Sm13nnXKfiW2CvCYWgt/6aCums7tXIm5Qf2/0vDlHlDTwapghGSX+wnNj+7V/2uk 2gyPvkJBDip91dVs6AwpGSe+IASi1Cb90OSIsDeRART63YRvZQTDuCkmiAgBt0oplqQy eDcb8kFwj9ZER5UAyIgOZQGtCU5Da1nVQkRLjob1u5LhPMKYfHbM7PFQDz0ghTkrwp3Z +6xA== 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 z11si1692489pfi.406.2018.04.03.00.19.05; Tue, 03 Apr 2018 00:19:19 -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 S1755029AbeDCHRZ (ORCPT + 99 others); Tue, 3 Apr 2018 03:17:25 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:43704 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752845AbeDCHQM (ORCPT ); Tue, 3 Apr 2018 03:16:12 -0400 X-UUID: f256c21335124e59a93e97c1c294b6a5-20180403 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1217370115; Tue, 03 Apr 2018 15:16:08 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 3 Apr 2018 15:16:07 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 3 Apr 2018 15:16:07 +0800 From: To: , , , CC: , , , , , Sean Wang , "Matthias Brugger" , Ulf Hansson , "Weiyi Lu" Subject: [PATCH v1 3/7] soc: mediatek: reuse read[l,x]_poll_timeout helpers Date: Tue, 3 Apr 2018 15:15:53 +0800 Message-ID: <2c0d233c658fa6093a18a54e82a3e51340251bc9.1522736996.git.sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-Product-Ver: SMEX-12.5.0.5042-8.2.9001-23760.005 X-TM-AS-Result: No-4.829000-8.000000-10 X-TMASE-MatchedRID: Ei0WBMmFdJikwTZnxyBJ8wPZZctd3P4BCt59Uh3p/NXTNpsvj7/hy8EY HnJZxFh9E4XSoP7sKf/0p/NaRJTHE5pOsuuafTEbjtK7dC6UBnn/GH6wnR4D5rKMPhGFsui/Tjh be5bZI0g1aWq/d65GNYBStp5jwgJ5HxPMjOKY7A8LbigRnpKlKZvjAepGmdoORau7mly9HNQaJx 7Ynm9myhUImKtMZOWWaYov/6JcruQ/kA3Verb7Mm+Nqft+LUuWii2bTHk7bARygIJR9gUu5JcKK 5LU6un15APDq2B3cAxn2JWP8qFf9FKehBzm9vnO5B2Qzud0EsI35c5BnKCu9g== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.829000-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23760.005 X-TMASE-POSTMAN: 2-d; X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Wang Reuse the common helpers read[l,x]_poll_timeout provided by Linux core instead of an open-coded handling. The name of the local variable sram_pdn_ack in scpsys_power_on is renamed to pdn_ack in order to be consistent with the one used in scpsys_power_off. Signed-off-by: Sean Wang Cc: Matthias Brugger Cc: Ulf Hansson Cc: Weiyi Lu --- drivers/soc/mediatek/mtk-scpsys.c | 91 ++++++++++----------------------------- 1 file changed, 23 insertions(+), 68 deletions(-) diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c index d762a46..f9b7248 100644 --- a/drivers/soc/mediatek/mtk-scpsys.c +++ b/drivers/soc/mediatek/mtk-scpsys.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,9 @@ #include #include +#define MTK_POLL_DELAY_US 10 +#define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ)) + #define SPM_VDE_PWR_CON 0x0210 #define SPM_MFG_PWR_CON 0x0214 #define SPM_VEN_PWR_CON 0x0230 @@ -184,12 +188,10 @@ 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; - unsigned long timeout; - bool expired; void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; - u32 sram_pdn_ack = scpd->data->sram_pdn_ack_bits; + u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 val; - int ret; + int ret, tmp; int i; if (scpd->supply) { @@ -215,23 +217,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) writel(val, ctl_addr); /* wait until PWR_ACK = 1 */ - timeout = jiffies + HZ; - expired = false; - while (1) { - ret = scpsys_domain_is_on(scpd); - if (ret > 0) - break; - - if (expired) { - ret = -ETIMEDOUT; - goto err_pwr_ack; - } - - cpu_relax(); - - if (time_after(jiffies, timeout)) - expired = true; - } + ret = readx_poll_timeout(scpsys_domain_is_on, scpd, tmp, tmp > 0, + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + if (ret < 0) + goto err_pwr_ack; val &= ~PWR_CLK_DIS_BIT; writel(val, ctl_addr); @@ -246,20 +235,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) writel(val, ctl_addr); /* wait until SRAM_PDN_ACK all 0 */ - timeout = jiffies + HZ; - expired = false; - while (sram_pdn_ack && (readl(ctl_addr) & sram_pdn_ack)) { - - if (expired) { - ret = -ETIMEDOUT; - goto err_pwr_ack; - } - - cpu_relax(); - - if (time_after(jiffies, timeout)) - expired = true; - } + 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; if (scpd->data->bus_prot_mask) { ret = mtk_infracfg_clear_bus_protection(scp->infracfg, @@ -289,12 +268,10 @@ 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; - unsigned long timeout; - bool expired; void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 val; - int ret; + int ret, tmp; int i; if (scpd->data->bus_prot_mask) { @@ -310,19 +287,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) writel(val, ctl_addr); /* wait until SRAM_PDN_ACK all 1 */ - timeout = jiffies + HZ; - expired = false; - while (pdn_ack && (readl(ctl_addr) & pdn_ack) != pdn_ack) { - if (expired) { - ret = -ETIMEDOUT; - goto out; - } - - cpu_relax(); - - if (time_after(jiffies, timeout)) - expired = true; - } + ret = readl_poll_timeout(ctl_addr, tmp, (tmp & pdn_ack) == pdn_ack, + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + if (ret < 0) + goto out; val |= PWR_ISO_BIT; writel(val, ctl_addr); @@ -340,23 +308,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) writel(val, ctl_addr); /* wait until PWR_ACK = 0 */ - timeout = jiffies + HZ; - expired = false; - while (1) { - ret = scpsys_domain_is_on(scpd); - if (ret == 0) - break; - - if (expired) { - ret = -ETIMEDOUT; - goto out; - } - - cpu_relax(); - - if (time_after(jiffies, timeout)) - expired = true; - } + ret = readx_poll_timeout(scpsys_domain_is_on, scpd, tmp, tmp == 0, + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); + if (ret < 0) + goto out; for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++) clk_disable_unprepare(scpd->clk[i]); -- 2.7.4