iwl-io.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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-drv.h"
  32. #include "iwl-io.h"
  33. #include "iwl-csr.h"
  34. #include "iwl-debug.h"
  35. #define IWL_POLL_INTERVAL 10 /* microseconds */
  36. int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
  37. u32 bits, u32 mask, int timeout)
  38. {
  39. int t = 0;
  40. do {
  41. if ((iwl_read32(trans, addr) & mask) == (bits & mask))
  42. return t;
  43. udelay(IWL_POLL_INTERVAL);
  44. t += IWL_POLL_INTERVAL;
  45. } while (t < timeout);
  46. return -ETIMEDOUT;
  47. }
  48. IWL_EXPORT_SYMBOL(iwl_poll_bit);
  49. u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
  50. {
  51. u32 value = 0x5a5a5a5a;
  52. unsigned long flags;
  53. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  54. value = iwl_read32(trans, reg);
  55. iwl_trans_release_nic_access(trans, &flags);
  56. }
  57. return value;
  58. }
  59. IWL_EXPORT_SYMBOL(iwl_read_direct32);
  60. void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
  61. {
  62. unsigned long flags;
  63. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  64. iwl_write32(trans, reg, value);
  65. iwl_trans_release_nic_access(trans, &flags);
  66. }
  67. }
  68. IWL_EXPORT_SYMBOL(iwl_write_direct32);
  69. int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
  70. int timeout)
  71. {
  72. int t = 0;
  73. do {
  74. if ((iwl_read_direct32(trans, addr) & mask) == mask)
  75. return t;
  76. udelay(IWL_POLL_INTERVAL);
  77. t += IWL_POLL_INTERVAL;
  78. } while (t < timeout);
  79. return -ETIMEDOUT;
  80. }
  81. IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
  82. static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
  83. {
  84. u32 val = iwl_trans_read_prph(trans, ofs);
  85. trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
  86. return val;
  87. }
  88. static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
  89. {
  90. trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
  91. iwl_trans_write_prph(trans, ofs, val);
  92. }
  93. u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
  94. {
  95. unsigned long flags;
  96. u32 val = 0x5a5a5a5a;
  97. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  98. val = __iwl_read_prph(trans, ofs);
  99. iwl_trans_release_nic_access(trans, &flags);
  100. }
  101. return val;
  102. }
  103. IWL_EXPORT_SYMBOL(iwl_read_prph);
  104. void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
  105. {
  106. unsigned long flags;
  107. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  108. __iwl_write_prph(trans, ofs, val);
  109. iwl_trans_release_nic_access(trans, &flags);
  110. }
  111. }
  112. IWL_EXPORT_SYMBOL(iwl_write_prph);
  113. void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  114. {
  115. unsigned long flags;
  116. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  117. __iwl_write_prph(trans, ofs,
  118. __iwl_read_prph(trans, ofs) | mask);
  119. iwl_trans_release_nic_access(trans, &flags);
  120. }
  121. }
  122. IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
  123. void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
  124. u32 bits, u32 mask)
  125. {
  126. unsigned long flags;
  127. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  128. __iwl_write_prph(trans, ofs,
  129. (__iwl_read_prph(trans, ofs) & mask) | bits);
  130. iwl_trans_release_nic_access(trans, &flags);
  131. }
  132. }
  133. IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
  134. void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  135. {
  136. unsigned long flags;
  137. u32 val;
  138. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  139. val = __iwl_read_prph(trans, ofs);
  140. __iwl_write_prph(trans, ofs, (val & ~mask));
  141. iwl_trans_release_nic_access(trans, &flags);
  142. }
  143. }
  144. IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);