Commit 4a58732c authored by Sean Wang's avatar Sean Wang Committed by Matthias Brugger

soc: mediatek: reuse read[l,x]_poll_timeout helpers

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: default avatarSean 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>
Signed-off-by: default avatarMatthias Brugger <matthias.bgg@gmail.com>
parent 38d19752
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/mfd/syscon.h> #include <linux/mfd/syscon.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -27,6 +28,9 @@ ...@@ -27,6 +28,9 @@
#include <dt-bindings/power/mt7623a-power.h> #include <dt-bindings/power/mt7623a-power.h>
#include <dt-bindings/power/mt8173-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_VDE_PWR_CON 0x0210
#define SPM_MFG_PWR_CON 0x0214 #define SPM_MFG_PWR_CON 0x0214
#define SPM_VEN_PWR_CON 0x0230 #define SPM_VEN_PWR_CON 0x0230
...@@ -184,12 +188,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) ...@@ -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_domain *scpd = container_of(genpd, struct scp_domain, genpd);
struct scp *scp = scpd->scp; struct scp *scp = scpd->scp;
unsigned long timeout;
bool expired;
void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; 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; u32 val;
int ret; int ret, tmp;
int i; int i;
if (scpd->supply) { if (scpd->supply) {
...@@ -215,23 +217,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) ...@@ -215,23 +217,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
writel(val, ctl_addr); writel(val, ctl_addr);
/* wait until PWR_ACK = 1 */ /* wait until PWR_ACK = 1 */
timeout = jiffies + HZ; ret = readx_poll_timeout(scpsys_domain_is_on, scpd, tmp, tmp > 0,
expired = false; MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
while (1) { if (ret < 0)
ret = scpsys_domain_is_on(scpd);
if (ret > 0)
break;
if (expired) {
ret = -ETIMEDOUT;
goto err_pwr_ack; goto err_pwr_ack;
}
cpu_relax();
if (time_after(jiffies, timeout))
expired = true;
}
val &= ~PWR_CLK_DIS_BIT; val &= ~PWR_CLK_DIS_BIT;
writel(val, ctl_addr); writel(val, ctl_addr);
...@@ -246,20 +235,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd) ...@@ -246,20 +235,10 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
writel(val, ctl_addr); writel(val, ctl_addr);
/* wait until SRAM_PDN_ACK all 0 */ /* wait until SRAM_PDN_ACK all 0 */
timeout = jiffies + HZ; ret = readl_poll_timeout(ctl_addr, tmp, (tmp & pdn_ack) == 0,
expired = false; MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
while (sram_pdn_ack && (readl(ctl_addr) & sram_pdn_ack)) { if (ret < 0)
if (expired) {
ret = -ETIMEDOUT;
goto err_pwr_ack; goto err_pwr_ack;
}
cpu_relax();
if (time_after(jiffies, timeout))
expired = true;
}
if (scpd->data->bus_prot_mask) { if (scpd->data->bus_prot_mask) {
ret = mtk_infracfg_clear_bus_protection(scp->infracfg, ret = mtk_infracfg_clear_bus_protection(scp->infracfg,
...@@ -289,12 +268,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) ...@@ -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_domain *scpd = container_of(genpd, struct scp_domain, genpd);
struct scp *scp = scpd->scp; struct scp *scp = scpd->scp;
unsigned long timeout;
bool expired;
void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs;
u32 pdn_ack = scpd->data->sram_pdn_ack_bits; u32 pdn_ack = scpd->data->sram_pdn_ack_bits;
u32 val; u32 val;
int ret; int ret, tmp;
int i; int i;
if (scpd->data->bus_prot_mask) { if (scpd->data->bus_prot_mask) {
...@@ -310,19 +287,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) ...@@ -310,19 +287,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
writel(val, ctl_addr); writel(val, ctl_addr);
/* wait until SRAM_PDN_ACK all 1 */ /* wait until SRAM_PDN_ACK all 1 */
timeout = jiffies + HZ; ret = readl_poll_timeout(ctl_addr, tmp, (tmp & pdn_ack) == pdn_ack,
expired = false; MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
while (pdn_ack && (readl(ctl_addr) & pdn_ack) != pdn_ack) { if (ret < 0)
if (expired) {
ret = -ETIMEDOUT;
goto out; goto out;
}
cpu_relax();
if (time_after(jiffies, timeout))
expired = true;
}
val |= PWR_ISO_BIT; val |= PWR_ISO_BIT;
writel(val, ctl_addr); writel(val, ctl_addr);
...@@ -340,23 +308,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) ...@@ -340,23 +308,10 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
writel(val, ctl_addr); writel(val, ctl_addr);
/* wait until PWR_ACK = 0 */ /* wait until PWR_ACK = 0 */
timeout = jiffies + HZ; ret = readx_poll_timeout(scpsys_domain_is_on, scpd, tmp, tmp == 0,
expired = false; MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
while (1) { if (ret < 0)
ret = scpsys_domain_is_on(scpd);
if (ret == 0)
break;
if (expired) {
ret = -ETIMEDOUT;
goto out; goto out;
}
cpu_relax();
if (time_after(jiffies, timeout))
expired = true;
}
for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++) for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++)
clk_disable_unprepare(scpd->clk[i]); clk_disable_unprepare(scpd->clk[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment