soc: mediatek: reuse regmap_read_poll_timeout helpers
Reuse the common helpers regmap_read_poll_timeout provided by Linux core instead of an open-coded handling. 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> Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
This commit is contained in:
parent
4a58732c7c
commit
090c6243b1
|
@ -17,6 +17,9 @@
|
||||||
#include <linux/soc/mediatek/infracfg.h>
|
#include <linux/soc/mediatek/infracfg.h>
|
||||||
#include <asm/processor.h>
|
#include <asm/processor.h>
|
||||||
|
|
||||||
|
#define MTK_POLL_DELAY_US 10
|
||||||
|
#define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
|
||||||
|
|
||||||
#define INFRA_TOPAXI_PROTECTEN 0x0220
|
#define INFRA_TOPAXI_PROTECTEN 0x0220
|
||||||
#define INFRA_TOPAXI_PROTECTSTA1 0x0228
|
#define INFRA_TOPAXI_PROTECTSTA1 0x0228
|
||||||
#define INFRA_TOPAXI_PROTECTEN_SET 0x0260
|
#define INFRA_TOPAXI_PROTECTEN_SET 0x0260
|
||||||
|
@ -37,7 +40,6 @@
|
||||||
int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
|
int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
|
||||||
bool reg_update)
|
bool reg_update)
|
||||||
{
|
{
|
||||||
unsigned long expired;
|
|
||||||
u32 val;
|
u32 val;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -47,22 +49,11 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
|
||||||
else
|
else
|
||||||
regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask);
|
regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask);
|
||||||
|
|
||||||
expired = jiffies + HZ;
|
ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
|
||||||
|
val, (val & mask) == mask,
|
||||||
|
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
|
||||||
|
|
||||||
while (1) {
|
return ret;
|
||||||
ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if ((val & mask) == mask)
|
|
||||||
break;
|
|
||||||
|
|
||||||
cpu_relax();
|
|
||||||
if (time_after(jiffies, expired))
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,30 +71,17 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
|
||||||
int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask,
|
int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask,
|
||||||
bool reg_update)
|
bool reg_update)
|
||||||
{
|
{
|
||||||
unsigned long expired;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
u32 val;
|
||||||
|
|
||||||
if (reg_update)
|
if (reg_update)
|
||||||
regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
|
regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
|
||||||
else
|
else
|
||||||
regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask);
|
regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask);
|
||||||
|
|
||||||
expired = jiffies + HZ;
|
ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
|
||||||
|
val, !(val & mask),
|
||||||
|
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
|
||||||
|
|
||||||
while (1) {
|
return ret;
|
||||||
u32 val;
|
|
||||||
|
|
||||||
ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!(val & mask))
|
|
||||||
break;
|
|
||||||
|
|
||||||
cpu_relax();
|
|
||||||
if (time_after(jiffies, expired))
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue