Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / net / wireless / mediatek / mt7601u / core.c
blob907443b361efb377166b3ba0eb6e198927ae43b3
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
5 */
7 #include "mt7601u.h"
9 int mt7601u_wait_asic_ready(struct mt7601u_dev *dev)
11 int i = 100;
12 u32 val;
14 do {
15 if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
16 return -EIO;
18 val = mt7601u_rr(dev, MT_MAC_CSR0);
19 if (val && ~val)
20 return 0;
22 udelay(10);
23 } while (i--);
25 return -EIO;
28 bool mt76_poll(struct mt7601u_dev *dev, u32 offset, u32 mask, u32 val,
29 int timeout)
31 u32 cur;
33 timeout /= 10;
34 do {
35 if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
36 return false;
38 cur = mt7601u_rr(dev, offset) & mask;
39 if (cur == val)
40 return true;
42 udelay(10);
43 } while (timeout-- > 0);
45 dev_err(dev->dev, "Error: Time out with reg %08x\n", offset);
47 return false;
50 bool mt76_poll_msec(struct mt7601u_dev *dev, u32 offset, u32 mask, u32 val,
51 int timeout)
53 u32 cur;
55 timeout /= 10;
56 do {
57 if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
58 return false;
60 cur = mt7601u_rr(dev, offset) & mask;
61 if (cur == val)
62 return true;
64 msleep(10);
65 } while (timeout-- > 0);
67 dev_err(dev->dev, "Error: Time out with reg %08x\n", offset);
69 return false;