core.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
  4. *
  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
  8. *
  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.
  13. */
  14. #include "mt7601u.h"
  15. int mt7601u_wait_asic_ready(struct mt7601u_dev *dev)
  16. {
  17. int i = 100;
  18. u32 val;
  19. do {
  20. if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
  21. return -EIO;
  22. val = mt7601u_rr(dev, MT_MAC_CSR0);
  23. if (val && ~val)
  24. return 0;
  25. udelay(10);
  26. } while (i--);
  27. return -EIO;
  28. }
  29. bool mt76_poll(struct mt7601u_dev *dev, u32 offset, u32 mask, u32 val,
  30. int timeout)
  31. {
  32. u32 cur;
  33. timeout /= 10;
  34. do {
  35. if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
  36. return false;
  37. cur = mt7601u_rr(dev, offset) & mask;
  38. if (cur == val)
  39. return true;
  40. udelay(10);
  41. } while (timeout-- > 0);
  42. dev_err(dev->dev, "Error: Time out with reg %08x\n", offset);
  43. return false;
  44. }
  45. bool mt76_poll_msec(struct mt7601u_dev *dev, u32 offset, u32 mask, u32 val,
  46. int timeout)
  47. {
  48. u32 cur;
  49. timeout /= 10;
  50. do {
  51. if (test_bit(MT7601U_STATE_REMOVED, &dev->state))
  52. return false;
  53. cur = mt7601u_rr(dev, offset) & mask;
  54. if (cur == val)
  55. return true;
  56. msleep(10);
  57. } while (timeout-- > 0);
  58. dev_err(dev->dev, "Error: Time out with reg %08x\n", offset);
  59. return false;
  60. }