|
17 | 17 | #include <linux/device.h> |
18 | 18 | #include <linux/init.h> |
19 | 19 | #include <linux/io.h> |
| 20 | +#include <linux/iopoll.h> |
20 | 21 | #include <linux/mod_devicetable.h> |
21 | 22 | #include <linux/module.h> |
22 | 23 | #include <linux/of_address.h> |
@@ -196,8 +197,8 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) |
196 | 197 | struct device *dev = priv->dev; |
197 | 198 | u32 bitmask = BIT(bit); |
198 | 199 | unsigned long flags; |
199 | | - unsigned int i; |
200 | 200 | u32 value; |
| 201 | + int error; |
201 | 202 |
|
202 | 203 | dev_dbg(dev, "MSTP %u%02u/%pC %s\n", reg, bit, hw->clk, |
203 | 204 | enable ? "ON" : "OFF"); |
@@ -228,19 +229,13 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) |
228 | 229 | if (!enable || priv->reg_layout == CLK_REG_LAYOUT_RZ_A) |
229 | 230 | return 0; |
230 | 231 |
|
231 | | - for (i = 1000; i > 0; --i) { |
232 | | - if (!(readl(priv->base + priv->status_regs[reg]) & bitmask)) |
233 | | - break; |
234 | | - cpu_relax(); |
235 | | - } |
236 | | - |
237 | | - if (!i) { |
| 232 | + error = readl_poll_timeout_atomic(priv->base + priv->status_regs[reg], |
| 233 | + value, !(value & bitmask), 0, 10); |
| 234 | + if (error) |
238 | 235 | dev_err(dev, "Failed to enable SMSTP %p[%d]\n", |
239 | 236 | priv->base + priv->control_regs[reg], bit); |
240 | | - return -ETIMEDOUT; |
241 | | - } |
242 | 237 |
|
243 | | - return 0; |
| 238 | + return error; |
244 | 239 | } |
245 | 240 |
|
246 | 241 | static int cpg_mstp_clock_enable(struct clk_hw *hw) |
@@ -896,8 +891,9 @@ static int cpg_mssr_suspend_noirq(struct device *dev) |
896 | 891 | static int cpg_mssr_resume_noirq(struct device *dev) |
897 | 892 | { |
898 | 893 | struct cpg_mssr_priv *priv = dev_get_drvdata(dev); |
899 | | - unsigned int reg, i; |
| 894 | + unsigned int reg; |
900 | 895 | u32 mask, oldval, newval; |
| 896 | + int error; |
901 | 897 |
|
902 | 898 | /* This is the best we can do to check for the presence of PSCI */ |
903 | 899 | if (!psci_ops.cpu_suspend) |
@@ -935,14 +931,9 @@ static int cpg_mssr_resume_noirq(struct device *dev) |
935 | 931 | if (!mask) |
936 | 932 | continue; |
937 | 933 |
|
938 | | - for (i = 1000; i > 0; --i) { |
939 | | - oldval = readl(priv->base + priv->status_regs[reg]); |
940 | | - if (!(oldval & mask)) |
941 | | - break; |
942 | | - cpu_relax(); |
943 | | - } |
944 | | - |
945 | | - if (!i) |
| 934 | + error = readl_poll_timeout_atomic(priv->base + priv->status_regs[reg], |
| 935 | + oldval, !(oldval & mask), 0, 10); |
| 936 | + if (error) |
946 | 937 | dev_warn(dev, "Failed to enable SMSTP%u[0x%x]\n", reg, |
947 | 938 | oldval & mask); |
948 | 939 | } |
|
0 commit comments