| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2015 Linaro, Ltd. |
|---|
| 3 | 4 | * Rob Herring <robh@kernel.org> |
|---|
| .. | .. |
|---|
| 5 | 6 | * Based on vendor driver: |
|---|
| 6 | 7 | * Copyright (C) 2013 Marvell Inc. |
|---|
| 7 | 8 | * 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 | | - * |
|---|
| 18 | 9 | */ |
|---|
| 19 | 10 | |
|---|
| 20 | 11 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 22 | 13 | #include <linux/of.h> |
|---|
| 23 | 14 | #include <linux/of_device.h> |
|---|
| 24 | 15 | #include <linux/io.h> |
|---|
| 16 | +#include <linux/iopoll.h> |
|---|
| 25 | 17 | #include <linux/err.h> |
|---|
| 26 | 18 | #include <linux/clk.h> |
|---|
| 27 | 19 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 147 | 139 | struct clk *clk; |
|---|
| 148 | 140 | }; |
|---|
| 149 | 141 | |
|---|
| 150 | | -static bool wait_for_reg(void __iomem *reg, u32 mask, unsigned long timeout) |
|---|
| 142 | +static int wait_for_reg(void __iomem *reg, u32 mask, u32 ms) |
|---|
| 151 | 143 | { |
|---|
| 152 | | - timeout += jiffies; |
|---|
| 153 | | - while (time_is_after_eq_jiffies(timeout)) { |
|---|
| 154 | | - if ((readl(reg) & mask) == mask) |
|---|
| 155 | | - return true; |
|---|
| 156 | | - msleep(1); |
|---|
| 157 | | - } |
|---|
| 158 | | - return false; |
|---|
| 144 | + u32 val; |
|---|
| 145 | + |
|---|
| 146 | + return readl_poll_timeout(reg, val, ((val & mask) == mask), |
|---|
| 147 | + 1000, 1000 * ms); |
|---|
| 159 | 148 | } |
|---|
| 160 | 149 | |
|---|
| 161 | 150 | static int mv_usb2_phy_28nm_init(struct phy *phy) |
|---|
| .. | .. |
|---|
| 217 | 206 | */ |
|---|
| 218 | 207 | |
|---|
| 219 | 208 | /* Make sure PHY Calibration is ready */ |
|---|
| 220 | | - if (!wait_for_reg(base + PHY_28NM_CAL_REG, |
|---|
| 221 | | - PHY_28NM_PLL_PLLCAL_DONE | PHY_28NM_PLL_IMPCAL_DONE, |
|---|
| 222 | | - HZ / 10)) { |
|---|
| 209 | + ret = wait_for_reg(base + PHY_28NM_CAL_REG, |
|---|
| 210 | + PHY_28NM_PLL_PLLCAL_DONE | PHY_28NM_PLL_IMPCAL_DONE, |
|---|
| 211 | + 100); |
|---|
| 212 | + if (ret) { |
|---|
| 223 | 213 | dev_warn(&pdev->dev, "USB PHY PLL calibrate not done after 100mS."); |
|---|
| 224 | | - ret = -ETIMEDOUT; |
|---|
| 225 | 214 | goto err_clk; |
|---|
| 226 | 215 | } |
|---|
| 227 | | - if (!wait_for_reg(base + PHY_28NM_RX_REG1, |
|---|
| 228 | | - PHY_28NM_RX_SQCAL_DONE, HZ / 10)) { |
|---|
| 216 | + ret = wait_for_reg(base + PHY_28NM_RX_REG1, |
|---|
| 217 | + PHY_28NM_RX_SQCAL_DONE, 100); |
|---|
| 218 | + if (ret) { |
|---|
| 229 | 219 | dev_warn(&pdev->dev, "USB PHY RX SQ calibrate not done after 100mS."); |
|---|
| 230 | | - ret = -ETIMEDOUT; |
|---|
| 231 | 220 | goto err_clk; |
|---|
| 232 | 221 | } |
|---|
| 233 | 222 | /* Make sure PHY PLL is ready */ |
|---|
| 234 | | - if (!wait_for_reg(base + PHY_28NM_PLL_REG0, |
|---|
| 235 | | - PHY_28NM_PLL_READY, HZ / 10)) { |
|---|
| 223 | + ret = wait_for_reg(base + PHY_28NM_PLL_REG0, PHY_28NM_PLL_READY, 100); |
|---|
| 224 | + if (ret) { |
|---|
| 236 | 225 | dev_warn(&pdev->dev, "PLL_READY not set after 100mS."); |
|---|
| 237 | | - ret = -ETIMEDOUT; |
|---|
| 238 | 226 | goto err_clk; |
|---|
| 239 | 227 | } |
|---|
| 240 | 228 | |
|---|