hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/phy/marvell/phy-pxa-28nm-hsic.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2015 Linaro, Ltd.
34 * Rob Herring <robh@kernel.org>
....@@ -5,22 +6,13 @@
56 * Based on vendor driver:
67 * Copyright (C) 2013 Marvell Inc.
78 * Author: Chao Xie <xiechao.mail@gmail.com>
8
- *
9
- * This software is licensed under the terms of the GNU General Public
10
- * License version 2, as published by the Free Software Foundation, and
11
- * may be copied, distributed, and modified under those terms.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
189 */
1910
2011 #include <linux/delay.h>
2112 #include <linux/slab.h>
2213 #include <linux/of.h>
2314 #include <linux/io.h>
15
+#include <linux/iopoll.h>
2416 #include <linux/err.h>
2517 #include <linux/clk.h>
2618 #include <linux/module.h>
....@@ -53,15 +45,12 @@
5345 struct clk *clk;
5446 };
5547
56
-static bool wait_for_reg(void __iomem *reg, u32 mask, unsigned long timeout)
48
+static int wait_for_reg(void __iomem *reg, u32 mask, u32 ms)
5749 {
58
- timeout += jiffies;
59
- while (time_is_after_eq_jiffies(timeout)) {
60
- if ((readl(reg) & mask) == mask)
61
- return true;
62
- msleep(1);
63
- }
64
- return false;
50
+ u32 val;
51
+
52
+ return readl_poll_timeout(reg, val, ((val & mask) == mask),
53
+ 1000, 1000 * ms);
6554 }
6655
6756 static int mv_hsic_phy_init(struct phy *phy)
....@@ -69,6 +58,7 @@
6958 struct mv_hsic_phy *mv_phy = phy_get_drvdata(phy);
7059 struct platform_device *pdev = mv_phy->pdev;
7160 void __iomem *base = mv_phy->base;
61
+ int ret;
7262
7363 clk_prepare_enable(mv_phy->clk);
7464
....@@ -84,14 +74,14 @@
8474 base + PHY_28NM_HSIC_PLL_CTRL2);
8575
8676 /* Make sure PHY PLL is locked */
87
- if (!wait_for_reg(base + PHY_28NM_HSIC_PLL_CTRL2,
88
- PHY_28NM_HSIC_H2S_PLL_LOCK, HZ / 10)) {
77
+ ret = wait_for_reg(base + PHY_28NM_HSIC_PLL_CTRL2,
78
+ PHY_28NM_HSIC_H2S_PLL_LOCK, 100);
79
+ if (ret) {
8980 dev_err(&pdev->dev, "HSIC PHY PLL not locked after 100mS.");
9081 clk_disable_unprepare(mv_phy->clk);
91
- return -ETIMEDOUT;
9282 }
9383
94
- return 0;
84
+ return ret;
9585 }
9686
9787 static int mv_hsic_phy_power_on(struct phy *phy)
....@@ -100,6 +90,7 @@
10090 struct platform_device *pdev = mv_phy->pdev;
10191 void __iomem *base = mv_phy->base;
10292 u32 reg;
93
+ int ret;
10394
10495 reg = readl(base + PHY_28NM_HSIC_CTRL);
10596 /* Avoid SE0 state when resume for some device will take it as reset */
....@@ -117,20 +108,20 @@
117108 */
118109
119110 /* Make sure PHY Calibration is ready */
120
- if (!wait_for_reg(base + PHY_28NM_HSIC_IMPCAL_CAL,
121
- PHY_28NM_HSIC_H2S_IMPCAL_DONE, HZ / 10)) {
111
+ ret = wait_for_reg(base + PHY_28NM_HSIC_IMPCAL_CAL,
112
+ PHY_28NM_HSIC_H2S_IMPCAL_DONE, 100);
113
+ if (ret) {
122114 dev_warn(&pdev->dev, "HSIC PHY READY not set after 100mS.");
123
- return -ETIMEDOUT;
115
+ return ret;
124116 }
125117
126118 /* Waiting for HSIC connect int*/
127
- if (!wait_for_reg(base + PHY_28NM_HSIC_INT,
128
- PHY_28NM_HSIC_CONNECT_INT, HZ / 5)) {
119
+ ret = wait_for_reg(base + PHY_28NM_HSIC_INT,
120
+ PHY_28NM_HSIC_CONNECT_INT, 200);
121
+ if (ret)
129122 dev_warn(&pdev->dev, "HSIC wait for connect interrupt timeout.");
130
- return -ETIMEDOUT;
131
- }
132123
133
- return 0;
124
+ return ret;
134125 }
135126
136127 static int mv_hsic_phy_power_off(struct phy *phy)