.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Broadcom Northstar USB 3.0 PHY Driver |
---|
3 | 4 | * |
---|
.. | .. |
---|
7 | 8 | * All magic values used for initialization (and related comments) were obtained |
---|
8 | 9 | * from Broadcom's SDK: |
---|
9 | 10 | * Copyright (c) Broadcom Corp, 2012 |
---|
10 | | - * |
---|
11 | | - * This program is free software; you can redistribute it and/or modify |
---|
12 | | - * it under the terms of the GNU General Public License version 2 as |
---|
13 | | - * published by the Free Software Foundation. |
---|
14 | 11 | */ |
---|
15 | 12 | |
---|
16 | 13 | #include <linux/bcma/bcma.h> |
---|
17 | 14 | #include <linux/delay.h> |
---|
18 | 15 | #include <linux/err.h> |
---|
| 16 | +#include <linux/iopoll.h> |
---|
19 | 17 | #include <linux/mdio.h> |
---|
20 | 18 | #include <linux/module.h> |
---|
21 | 19 | #include <linux/of_address.h> |
---|
.. | .. |
---|
261 | 259 | **************************************************/ |
---|
262 | 260 | |
---|
263 | 261 | static int bcm_ns_usb3_wait_reg(struct bcm_ns_usb3 *usb3, void __iomem *addr, |
---|
264 | | - u32 mask, u32 value, unsigned long timeout) |
---|
| 262 | + u32 mask, u32 value, int usec) |
---|
265 | 263 | { |
---|
266 | | - unsigned long deadline = jiffies + timeout; |
---|
267 | 264 | u32 val; |
---|
| 265 | + int ret; |
---|
268 | 266 | |
---|
269 | | - do { |
---|
270 | | - val = readl(addr); |
---|
271 | | - if ((val & mask) == value) |
---|
272 | | - return 0; |
---|
273 | | - cpu_relax(); |
---|
274 | | - udelay(10); |
---|
275 | | - } while (!time_after_eq(jiffies, deadline)); |
---|
| 267 | + ret = readl_poll_timeout_atomic(addr, val, ((val & mask) == value), |
---|
| 268 | + 10, usec); |
---|
| 269 | + if (ret) |
---|
| 270 | + dev_err(usb3->dev, "Timeout waiting for register %p\n", addr); |
---|
276 | 271 | |
---|
277 | | - dev_err(usb3->dev, "Timeout waiting for register %p\n", addr); |
---|
278 | | - |
---|
279 | | - return -EBUSY; |
---|
| 272 | + return ret; |
---|
280 | 273 | } |
---|
281 | 274 | |
---|
282 | 275 | static inline int bcm_ns_usb3_mii_mng_wait_idle(struct bcm_ns_usb3 *usb3) |
---|
283 | 276 | { |
---|
284 | 277 | return bcm_ns_usb3_wait_reg(usb3, usb3->ccb_mii + BCMA_CCB_MII_MNG_CTL, |
---|
285 | 278 | 0x0100, 0x0000, |
---|
286 | | - usecs_to_jiffies(BCM_NS_USB3_MII_MNG_TIMEOUT_US)); |
---|
| 279 | + BCM_NS_USB3_MII_MNG_TIMEOUT_US); |
---|
287 | 280 | } |
---|
288 | 281 | |
---|
289 | 282 | static int bcm_ns_usb3_platform_phy_write(struct bcm_ns_usb3 *usb3, u16 reg, |
---|