forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/phy/qualcomm/phy-qcom-apq8064-sata.c
....@@ -1,17 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 and
6
- * only version 2 as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
124 */
135
146 #include <linux/io.h>
7
+#include <linux/iopoll.h>
158 #include <linux/kernel.h>
169 #include <linux/module.h>
1710 #include <linux/of.h>
....@@ -80,18 +73,12 @@
8073 };
8174
8275 /* Helper function to do poll and timeout */
83
-static int read_poll_timeout(void __iomem *addr, u32 mask)
76
+static int poll_timeout(void __iomem *addr, u32 mask)
8477 {
85
- unsigned long timeout = jiffies + msecs_to_jiffies(TIMEOUT_MS);
78
+ u32 val;
8679
87
- do {
88
- if (readl_relaxed(addr) & mask)
89
- return 0;
90
-
91
- usleep_range(DELAY_INTERVAL_US, DELAY_INTERVAL_US + 50);
92
- } while (!time_after(jiffies, timeout));
93
-
94
- return (readl_relaxed(addr) & mask) ? 0 : -ETIMEDOUT;
80
+ return readl_relaxed_poll_timeout(addr, val, (val & mask),
81
+ DELAY_INTERVAL_US, TIMEOUT_MS * 1000);
9582 }
9683
9784 static int qcom_apq8064_sata_phy_init(struct phy *generic_phy)
....@@ -145,21 +132,21 @@
145132 writel_relaxed(0x05, base + UNIPHY_PLL_LKDET_CFG2);
146133
147134 /* PLL Lock wait */
148
- ret = read_poll_timeout(base + UNIPHY_PLL_STATUS, UNIPHY_PLL_LOCK);
135
+ ret = poll_timeout(base + UNIPHY_PLL_STATUS, UNIPHY_PLL_LOCK);
149136 if (ret) {
150137 dev_err(phy->dev, "poll timeout UNIPHY_PLL_STATUS\n");
151138 return ret;
152139 }
153140
154141 /* TX Calibration */
155
- ret = read_poll_timeout(base + SATA_PHY_TX_IMCAL_STAT, SATA_PHY_TX_CAL);
142
+ ret = poll_timeout(base + SATA_PHY_TX_IMCAL_STAT, SATA_PHY_TX_CAL);
156143 if (ret) {
157144 dev_err(phy->dev, "poll timeout SATA_PHY_TX_IMCAL_STAT\n");
158145 return ret;
159146 }
160147
161148 /* RX Calibration */
162
- ret = read_poll_timeout(base + SATA_PHY_RX_IMCAL_STAT, SATA_PHY_RX_CAL);
149
+ ret = poll_timeout(base + SATA_PHY_RX_IMCAL_STAT, SATA_PHY_RX_CAL);
163150 if (ret) {
164151 dev_err(phy->dev, "poll timeout SATA_PHY_RX_IMCAL_STAT\n");
165152 return ret;