| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | |
|---|
| 14 | 6 | #include <linux/io.h> |
|---|
| 7 | +#include <linux/iopoll.h> |
|---|
| 15 | 8 | #include <linux/kernel.h> |
|---|
| 16 | 9 | #include <linux/module.h> |
|---|
| 17 | 10 | #include <linux/of.h> |
|---|
| .. | .. |
|---|
| 80 | 73 | }; |
|---|
| 81 | 74 | |
|---|
| 82 | 75 | /* 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) |
|---|
| 84 | 77 | { |
|---|
| 85 | | - unsigned long timeout = jiffies + msecs_to_jiffies(TIMEOUT_MS); |
|---|
| 78 | + u32 val; |
|---|
| 86 | 79 | |
|---|
| 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); |
|---|
| 95 | 82 | } |
|---|
| 96 | 83 | |
|---|
| 97 | 84 | static int qcom_apq8064_sata_phy_init(struct phy *generic_phy) |
|---|
| .. | .. |
|---|
| 145 | 132 | writel_relaxed(0x05, base + UNIPHY_PLL_LKDET_CFG2); |
|---|
| 146 | 133 | |
|---|
| 147 | 134 | /* 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); |
|---|
| 149 | 136 | if (ret) { |
|---|
| 150 | 137 | dev_err(phy->dev, "poll timeout UNIPHY_PLL_STATUS\n"); |
|---|
| 151 | 138 | return ret; |
|---|
| 152 | 139 | } |
|---|
| 153 | 140 | |
|---|
| 154 | 141 | /* 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); |
|---|
| 156 | 143 | if (ret) { |
|---|
| 157 | 144 | dev_err(phy->dev, "poll timeout SATA_PHY_TX_IMCAL_STAT\n"); |
|---|
| 158 | 145 | return ret; |
|---|
| 159 | 146 | } |
|---|
| 160 | 147 | |
|---|
| 161 | 148 | /* 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); |
|---|
| 163 | 150 | if (ret) { |
|---|
| 164 | 151 | dev_err(phy->dev, "poll timeout SATA_PHY_RX_IMCAL_STAT\n"); |
|---|
| 165 | 152 | return ret; |
|---|