linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Brugger <matthias.bgg@gmail.com>
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 <ulf.hansson@linaro.org>,
	Weiyi Lu <weiyi.lu@mediatek.com>
Subject: Re: [PATCH v1 3/7] soc: mediatek: reuse read[l,x]_poll_timeout helpers
Date: Wed, 18 Apr 2018 17:06:52 +0200	[thread overview]
Message-ID: <549e6adc-73c1-aa03-93dc-578138729750@gmail.com> (raw)
In-Reply-To: <2c0d233c658fa6093a18a54e82a3e51340251bc9.1522736996.git.sean.wang@mediatek.com>



On 04/03/2018 09:15 AM, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> 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 <sean.wang@mediatek.com>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Weiyi Lu <weiyi.lu@mediatek.com>
> ---

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 <linux/clk.h>
>  #include <linux/init.h>
>  #include <linux/io.h>
> +#include <linux/iopoll.h>
>  #include <linux/mfd/syscon.h>
>  #include <linux/of_device.h>
>  #include <linux/platform_device.h>
> @@ -27,6 +28,9 @@
>  #include <dt-bindings/power/mt7623a-power.h>
>  #include <dt-bindings/power/mt8173-power.h>
>  
> +#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]);
> 

  reply	other threads:[~2018-04-18 15:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03  7:15 [PATCH v1 0/7] add support for Bluetooth on MT7622 SoC sean.wang
2018-04-03  7:15 ` [PATCH v1 1/7] dt-bindings: net: bluetooth: Add mediatek-bluetooth sean.wang
2018-04-09 21:16   ` Rob Herring
2018-04-03  7:15 ` [PATCH v1 2/7] serdev: add dev_pm_domain_attach|detach() sean.wang
2018-04-03 10:29   ` Marcel Holtmann
2018-04-26  5:29     ` Sean Wang
2018-04-03  7:15 ` [PATCH v1 3/7] soc: mediatek: reuse read[l,x]_poll_timeout helpers sean.wang
2018-04-18 15:06   ` Matthias Brugger [this message]
2018-04-03  7:15 ` [PATCH v1 4/7] soc: mediatek: reuse regmap_read_poll_timeout helpers sean.wang
2018-04-19 10:23   ` Matthias Brugger
2018-04-20  3:42     ` Sean Wang
2018-04-03  7:15 ` [PATCH v1 5/7] soc: mediatek: add a fixed wait for SRAM stable sean.wang
2018-04-05 16:42   ` Sasha Levin
2018-04-19 10:33   ` Matthias Brugger
2018-04-20  3:49     ` Sean Wang
2018-04-23  8:58       ` Sean Wang
2018-04-03  7:15 ` [PATCH v1 6/7] Bluetooth: hci_mediatek: Add protocol support for MediaTek serial devices sean.wang
2018-04-03 10:27   ` Marcel Holtmann
2018-04-26  7:34     ` Sean Wang
2018-04-26  9:47       ` Marcel Holtmann
2018-04-27  4:13         ` Sean Wang
2018-04-27  5:25           ` Marcel Holtmann
2018-04-27  9:14             ` Sean Wang
2018-04-27 16:34               ` Marcel Holtmann
2018-05-08  6:48     ` Sean Wang
2018-05-08  7:27       ` Marcel Holtmann
2018-05-08  8:22         ` Sean Wang
2018-05-08 11:18           ` Marcel Holtmann
2018-05-10  6:45             ` Sean Wang
2018-04-03 12:13   ` [RFC PATCH] Bluetooth: hci_mediatek: mtk_recv_frame() can be static kbuild test robot
2018-04-03 12:13   ` [PATCH v1 6/7] Bluetooth: hci_mediatek: Add protocol support for MediaTek serial devices kbuild test robot
2018-04-03  7:15 ` [PATCH v1 7/7] MAINTAINERS: add an entry for MediaTek Bluetooth driver sean.wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=549e6adc-73c1-aa03-93dc-578138729750@gmail.com \
    --to=matthias.bgg@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=marcel@holtmann.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=sean.wang@mediatek.com \
    --cc=ulf.hansson@linaro.org \
    --cc=weiyi.lu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).