Linux 4.16.11
[linux/fpc-iii.git] / drivers / net / wireless / mediatek / mt7601u / core.c
blob0aabd790f985fb4f3716759c8ad4696b81ba0146
1 /*
2 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include "mt7601u.h"
17 int mt7601u_wait_asic_ready(struct mt7601u_dev *dev)
19 int i = 100;
20 u32 val;
22 do {
23 if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
24 return -EIO;
26 val = mt7601u_rr(dev, MT_MAC_CSR0);
27 if (val && ~val)
28 return 0;
30 udelay(10);
31 } while (i--);
33 return -EIO;
36 bool mt76_poll(struct mt7601u_dev *dev, u32 offset, u32 mask, u32 val,
37 int timeout)
39 u32 cur;
41 timeout /= 10;
42 do {
43 if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
44 return false;
46 cur = mt7601u_rr(dev, offset) & mask;
47 if (cur == val)
48 return true;
50 udelay(10);
51 } while (timeout-- > 0);
53 dev_err(dev->dev, "Error: Time out with reg %08x\n", offset);
55 return false;
58 bool mt76_poll_msec(struct mt7601u_dev *dev, u32 offset, u32 mask, u32 val,
59 int timeout)
61 u32 cur;
63 timeout /= 10;
64 do {
65 if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
66 return false;
68 cur = mt7601u_rr(dev, offset) & mask;
69 if (cur == val)
70 return true;
72 msleep(10);
73 } while (timeout-- > 0);
75 dev_err(dev->dev, "Error: Time out with reg %08x\n", offset);
77 return false;