Skip to content

Commit cb0ba26

Browse files
moonlinuxvinodkoul
authored andcommitted
phy: rockchip-pcie: Use regmap_read_poll_timeout() for PCIe reference clk PLL status
Replace open-coded phy PCIe reference clk PLL status polling with regmap_read_poll_timeout API. This change simplifies the code without altering functionality. Signed-off-by: Anand Moon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e96397d commit cb0ba26

File tree

1 file changed

+15
-41
lines changed

1 file changed

+15
-41
lines changed

drivers/phy/rockchip/phy-rockchip-pcie.c

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
162162
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
163163
int err = 0;
164164
u32 status;
165-
unsigned long timeout;
166165

167166
mutex_lock(&rk_phy->pcie_mutex);
168167

@@ -191,21 +190,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
191190
* so we make it large enough here. And we use loop-break
192191
* method which should not be harmful.
193192
*/
194-
timeout = jiffies + msecs_to_jiffies(1000);
195-
196-
err = -EINVAL;
197-
while (time_before(jiffies, timeout)) {
198-
regmap_read(rk_phy->reg_base,
199-
rk_phy->phy_data->pcie_status,
200-
&status);
201-
if (status & PHY_PLL_LOCKED) {
202-
dev_dbg(&phy->dev, "pll locked!\n");
203-
err = 0;
204-
break;
205-
}
206-
msleep(20);
207-
}
208-
193+
err = regmap_read_poll_timeout(rk_phy->reg_base,
194+
rk_phy->phy_data->pcie_status,
195+
status,
196+
status & PHY_PLL_LOCKED,
197+
200, 100000);
209198
if (err) {
210199
dev_err(&phy->dev, "pll lock timeout!\n");
211200
goto err_pll_lock;
@@ -214,19 +203,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
214203
phy_wr_cfg(rk_phy, PHY_CFG_CLK_TEST, PHY_CFG_SEPE_RATE);
215204
phy_wr_cfg(rk_phy, PHY_CFG_CLK_SCC, PHY_CFG_PLL_100M);
216205

217-
err = -ETIMEDOUT;
218-
while (time_before(jiffies, timeout)) {
219-
regmap_read(rk_phy->reg_base,
220-
rk_phy->phy_data->pcie_status,
221-
&status);
222-
if (!(status & PHY_PLL_OUTPUT)) {
223-
dev_dbg(&phy->dev, "pll output enable done!\n");
224-
err = 0;
225-
break;
226-
}
227-
msleep(20);
228-
}
229-
206+
err = regmap_read_poll_timeout(rk_phy->reg_base,
207+
rk_phy->phy_data->pcie_status,
208+
status,
209+
!(status & PHY_PLL_OUTPUT),
210+
200, 100000);
230211
if (err) {
231212
dev_err(&phy->dev, "pll output enable timeout!\n");
232213
goto err_pll_lock;
@@ -236,19 +217,12 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
236217
HIWORD_UPDATE(PHY_CFG_PLL_LOCK,
237218
PHY_CFG_ADDR_MASK,
238219
PHY_CFG_ADDR_SHIFT));
239-
err = -EINVAL;
240-
while (time_before(jiffies, timeout)) {
241-
regmap_read(rk_phy->reg_base,
242-
rk_phy->phy_data->pcie_status,
243-
&status);
244-
if (status & PHY_PLL_LOCKED) {
245-
dev_dbg(&phy->dev, "pll relocked!\n");
246-
err = 0;
247-
break;
248-
}
249-
msleep(20);
250-
}
251220

221+
err = regmap_read_poll_timeout(rk_phy->reg_base,
222+
rk_phy->phy_data->pcie_status,
223+
status,
224+
status & PHY_PLL_LOCKED,
225+
200, 100000);
252226
if (err) {
253227
dev_err(&phy->dev, "pll relock timeout!\n");
254228
goto err_pll_lock;

0 commit comments

Comments
 (0)