iwl-io.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19. *
  20. * The full GNU General Public License is included in this distribution in the
  21. * file called LICENSE.
  22. *
  23. * Contact Information:
  24. * Intel Linux Wireless <ilw@linux.intel.com>
  25. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  26. *
  27. *****************************************************************************/
  28. #include <linux/delay.h>
  29. #include <linux/device.h>
  30. #include <linux/export.h>
  31. #include "iwl-io.h"
  32. #include "iwl-csr.h"
  33. #include "iwl-debug.h"
  34. #define IWL_POLL_INTERVAL 10 /* microseconds */
  35. int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
  36. u32 bits, u32 mask, int timeout)
  37. {
  38. int t = 0;
  39. do {
  40. if ((iwl_read32(trans, addr) & mask) == (bits & mask))
  41. return t;
  42. udelay(IWL_POLL_INTERVAL);
  43. t += IWL_POLL_INTERVAL;
  44. } while (t < timeout);
  45. return -ETIMEDOUT;
  46. }
  47. EXPORT_SYMBOL_GPL(iwl_poll_bit);
  48. u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
  49. {
  50. u32 value = 0x5a5a5a5a;
  51. unsigned long flags;
  52. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  53. value = iwl_read32(trans, reg);
  54. iwl_trans_release_nic_access(trans, &flags);
  55. }
  56. return value;
  57. }
  58. EXPORT_SYMBOL_GPL(iwl_read_direct32);
  59. void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
  60. {
  61. unsigned long flags;
  62. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  63. iwl_write32(trans, reg, value);
  64. iwl_trans_release_nic_access(trans, &flags);
  65. }
  66. }
  67. EXPORT_SYMBOL_GPL(iwl_write_direct32);
  68. int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
  69. int timeout)
  70. {
  71. int t = 0;
  72. do {
  73. if ((iwl_read_direct32(trans, addr) & mask) == mask)
  74. return t;
  75. udelay(IWL_POLL_INTERVAL);
  76. t += IWL_POLL_INTERVAL;
  77. } while (t < timeout);
  78. return -ETIMEDOUT;
  79. }
  80. EXPORT_SYMBOL_GPL(iwl_poll_direct_bit);
  81. static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
  82. {
  83. u32 val = iwl_trans_read_prph(trans, ofs);
  84. trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
  85. return val;
  86. }
  87. static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
  88. {
  89. trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
  90. iwl_trans_write_prph(trans, ofs, val);
  91. }
  92. u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
  93. {
  94. unsigned long flags;
  95. u32 val = 0x5a5a5a5a;
  96. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  97. val = __iwl_read_prph(trans, ofs);
  98. iwl_trans_release_nic_access(trans, &flags);
  99. }
  100. return val;
  101. }
  102. EXPORT_SYMBOL_GPL(iwl_read_prph);
  103. void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
  104. {
  105. unsigned long flags;
  106. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  107. __iwl_write_prph(trans, ofs, val);
  108. iwl_trans_release_nic_access(trans, &flags);
  109. }
  110. }
  111. EXPORT_SYMBOL_GPL(iwl_write_prph);
  112. void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  113. {
  114. unsigned long flags;
  115. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  116. __iwl_write_prph(trans, ofs,
  117. __iwl_read_prph(trans, ofs) | mask);
  118. iwl_trans_release_nic_access(trans, &flags);
  119. }
  120. }
  121. EXPORT_SYMBOL_GPL(iwl_set_bits_prph);
  122. void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
  123. u32 bits, u32 mask)
  124. {
  125. unsigned long flags;
  126. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  127. __iwl_write_prph(trans, ofs,
  128. (__iwl_read_prph(trans, ofs) & mask) | bits);
  129. iwl_trans_release_nic_access(trans, &flags);
  130. }
  131. }
  132. EXPORT_SYMBOL_GPL(iwl_set_bits_mask_prph);
  133. void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  134. {
  135. unsigned long flags;
  136. u32 val;
  137. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  138. val = __iwl_read_prph(trans, ofs);
  139. __iwl_write_prph(trans, ofs, (val & ~mask));
  140. iwl_trans_release_nic_access(trans, &flags);
  141. }
  142. }
  143. EXPORT_SYMBOL_GPL(iwl_clear_bits_prph);