Received: by 10.192.165.156 with SMTP id m28csp1340354imm; Wed, 18 Apr 2018 08:10:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+9c65FDVH0PE4vYI66DxbNpTVEVoLEMLAR1shZOC+0ra6SyXSY0t7KTfsAwkMO1e5btKls X-Received: by 2002:a17:902:760c:: with SMTP id k12-v6mr2453296pll.338.1524064231369; Wed, 18 Apr 2018 08:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524064231; cv=none; d=google.com; s=arc-20160816; b=WIM8Eid9nMM8umZTjAiuGhIOFjG5vdo3qliqToQOFxSAVo4q6g1JVoemMrVHIi5/Kz 2aZfupATAZk8tGY0GAMCC9oU7WcTt/j9/4P7FAfNn6gs8YXGSFcurat47Dheg4hjez4V YNvppEC53nJ4/LS+yheopOpYKyP6wd5MP5VOfDHgz0ckyeO/PesfWM0inTI9kDIlLwCc sX5u4GAoO41QYMHK4LC75EC3pCGC82Aup/0J0l348Vc0vybeQNYNhOcQEP7YO4KN/dET XQMLVjFyaMyZsgNJJqIMWD2cUTGjTbS3PUJkYrNEymLwlatT0XImiPAedbsEt6nQZjQM iysg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=QWjh/oCkS9oqfsNGyIA0Ov689RBSpTlGEFscJB+0RtM=; b=Lh58gkdarduqTBAzRxWPstvWaQqtqekGDkRxaKDB5el5matbKPS6Prq1ozodvrzAyM ht1RfqlhEgLmEWrYOQ8TDJx2B06uq0MA7GYqyvu4qAl91k6KXuH2q4Z9iK/gT2jRi81v YKzzUytotx4TEFDuEhueBLbeYIaOmYGItNL0+XfXeR4fAOGlziGdDkHZebW2axWQNBz5 h7RjwpBNAIUCs0yaHss4PhmtjjTnseHnb63cQUafB1+5X11g7pndIHux9mYii552EsTo /3QvQoMUSLy8sHNWaGY5+XupsaKVqbO609HCdAvwFFdhbzdapHLC09fnMdjEpeezBejT o35A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZzjN99XS; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15si1252391pgf.541.2018.04.18.08.10.16; Wed, 18 Apr 2018 08:10:31 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZzjN99XS; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753394AbeDRPHA (ORCPT + 99 others); Wed, 18 Apr 2018 11:07:00 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:40915 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752326AbeDRPG4 (ORCPT ); Wed, 18 Apr 2018 11:06:56 -0400 Received: by mail-wr0-f193.google.com with SMTP id v60-v6so5779866wrc.7; Wed, 18 Apr 2018 08:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QWjh/oCkS9oqfsNGyIA0Ov689RBSpTlGEFscJB+0RtM=; b=ZzjN99XSeoKH7kdU51c8kgzncZn89MRyqzMXPlfAVzNxfxT4Ijzd6gizZlWmH1YF5Y /EXONZRVvUnWsPLK8DmwABkin0jc7RQzlgqQpNIF0aIbeBBpFE3Drib9csy83Rgd3/C5 GXmWzYfjtjfyyfcVGLT7ZxCCYuW06HQ1XyZqcGnIHyv/u6b3MgukU8eYztd4iQ0G3d2+ WUwV/CM40/yZosJMFPyOJMg6NdfbiHfrg27+nGwyMYCnvhVEAZ95+ltIU4l/2H1zn6v+ fs+lyDM44BjONPcJioeejL0cfl3He1odLqd9tiIlU8c2bCyK0GXrge2fbdVxbveAzU7t 4P7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=QWjh/oCkS9oqfsNGyIA0Ov689RBSpTlGEFscJB+0RtM=; b=C9c6iucsQD14obqbsookq0/ezvSlKXLd7sAfwoLGcV8ilmV7HNkgXv38qdPcbOX0SQ ayajuE2PP3f7FZ4q7fa3oyKWA95SgBRER+mfasZK4ihfbNM6ttMwIj/kvGXfa89gPae8 JF+Nk/rNWVqDoOBJ7Fa6VlCo1/Eq+F/OEhAxhWk2CExICEh5cpBKaMrgp8F5erWp610/ 6uunoIrQA6BbcRbZFwZJfHvcmVBBGtsUCfRw7LAW02bHqaRBy18FQXWSy2UqNLgkBafc QpLSOigesn+UeT8/xcQcBm07p5CeDx0mvakBPEZ6UzC/gRJvC1kpAKNIt8Ss0XhLuJlg JllQ== X-Gm-Message-State: ALQs6tC+ydcbKi6gUGYYC4aTFg10PgR3XpS1xbr+GbeFfCUPoVhZzz8n nFQsms4U2jCoCgFuELWtywE= X-Received: by 10.80.189.130 with SMTP id y2mr3749524edh.138.1524064015133; Wed, 18 Apr 2018 08:06:55 -0700 (PDT) Received: from ziggy.stardust ([37.223.140.222]) by smtp.gmail.com with ESMTPSA id j90sm1047134edb.12.2018.04.18.08.06.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Apr 2018 08:06:54 -0700 (PDT) Subject: Re: [PATCH v1 3/7] soc: mediatek: reuse read[l,x]_poll_timeout helpers To: sean.wang@mediatek.com, robh+dt@kernel.org, mark.rutland@arm.com, marcel@holtmann.org, johan.hedberg@gmail.com Cc: devicetree@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Ulf Hansson , Weiyi Lu References: <2c0d233c658fa6093a18a54e82a3e51340251bc9.1522736996.git.sean.wang@mediatek.com> From: Matthias Brugger Openpgp: preference=signencrypt Autocrypt: addr=matthias.bgg@gmail.com; prefer-encrypt=mutual; keydata= xsFNBFP1zgUBEAC21D6hk7//0kOmsUrE3eZ55kjc9DmFPKIz6l4NggqwQjBNRHIMh04BbCMY fL3eT7ZsYV5nur7zctmJ+vbszoOASXUpfq8M+S5hU2w7sBaVk5rpH9yW8CUWz2+ZpQXPJcFa OhLZuSKB1F5JcvLbETRjNzNU7B3TdS2+zkgQQdEyt7Ij2HXGLJ2w+yG2GuR9/iyCJRf10Okq gTh//XESJZ8S6KlOWbLXRE+yfkKDXQx2Jr1XuVvM3zPqH5FMg8reRVFsQ+vI0b+OlyekT/Xe 0Hwvqkev95GG6x7yseJwI+2ydDH6M5O7fPKFW5mzAdDE2g/K9B4e2tYK6/rA7Fq4cqiAw1+u EgO44+eFgv082xtBez5WNkGn18vtw0LW3ESmKh19u6kEGoi0WZwslCNaGFrS4M7OH+aOJeqK fx5dIv2CEbxc6xnHY7dwkcHikTA4QdbdFeUSuj4YhIZ+0QlDVtS1QEXyvZbZky7ur9rHkZvP ZqlUsLJ2nOqsmahMTIQ8Mgx9SLEShWqD4kOF4zNfPJsgEMB49KbS2o9jxbGB+JKupjNddfxZ HlH1KF8QwCMZEYaTNogrVazu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uEIuXx1SDnchsfHg18gCCrEtYZ9czwNjVoV1Tv2lpzTTk+6HEJaQpMnPeAKbOeehq3gY KcvmDL+bRCTjmXg8WrBZdUuj0BCDYqneaUgVnp+wQogA3mHGVs281v1XZmjlsVmM9Y8VPE61 4zSiZQBL5CinBTTI8ssYlV/aIKYi0dxRcj6vYnAfUImOsdZ5AQja5xIqw1rwWWUOYb99 Message-ID: <549e6adc-73c1-aa03-93dc-578138729750@gmail.com> Date: Wed, 18 Apr 2018 17:06:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <2c0d233c658fa6093a18a54e82a3e51340251bc9.1522736996.git.sean.wang@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/03/2018 09:15 AM, sean.wang@mediatek.com wrote: > 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 > --- pushed to v4.17-next/soc Thanks! > 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]); >