iwl-eeprom.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Tomas Winkler <tomas.winkler@intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *****************************************************************************/
  62. #include <linux/kernel.h>
  63. #include <linux/module.h>
  64. #include <linux/version.h>
  65. #include <linux/init.h>
  66. #include <net/mac80211.h>
  67. #include "iwl-4965-commands.h"
  68. #include "iwl-4965.h"
  69. #include "iwl-core.h"
  70. #include "iwl-4965-debug.h"
  71. #include "iwl-eeprom.h"
  72. #include "iwl-4965-io.h"
  73. /******************************************************************************
  74. *
  75. * EEPROM related functions
  76. *
  77. ******************************************************************************/
  78. int iwlcore_eeprom_verify_signature(struct iwl4965_priv *priv)
  79. {
  80. u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
  81. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  82. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  83. return -ENOENT;
  84. }
  85. return 0;
  86. }
  87. EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
  88. /*
  89. * The device's EEPROM semaphore prevents conflicts between driver and uCode
  90. * when accessing the EEPROM; each access is a series of pulses to/from the
  91. * EEPROM chip, not a single event, so even reads could conflict if they
  92. * weren't arbitrated by the semaphore.
  93. */
  94. int iwlcore_eeprom_acquire_semaphore(struct iwl4965_priv *priv)
  95. {
  96. u16 count;
  97. int ret;
  98. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  99. /* Request semaphore */
  100. iwl4965_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  101. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  102. /* See if we got it */
  103. ret = iwl4965_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  104. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  105. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  106. EEPROM_SEM_TIMEOUT);
  107. if (ret >= 0) {
  108. IWL_DEBUG_IO("Acquired semaphore after %d tries.\n",
  109. count+1);
  110. return ret;
  111. }
  112. }
  113. return ret;
  114. }
  115. EXPORT_SYMBOL(iwlcore_eeprom_acquire_semaphore);
  116. void iwlcore_eeprom_release_semaphore(struct iwl4965_priv *priv)
  117. {
  118. iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
  119. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  120. }
  121. EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
  122. /**
  123. * iwl_eeprom_init - read EEPROM contents
  124. *
  125. * Load the EEPROM contents from adapter into priv->eeprom
  126. *
  127. * NOTE: This routine uses the non-debug IO access functions.
  128. */
  129. int iwl_eeprom_init(struct iwl4965_priv *priv)
  130. {
  131. u16 *e = (u16 *)&priv->eeprom;
  132. u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
  133. u32 r;
  134. int sz = sizeof(priv->eeprom);
  135. int ret;
  136. int i;
  137. u16 addr;
  138. /* The EEPROM structure has several padding buffers within it
  139. * and when adding new EEPROM maps is subject to programmer errors
  140. * which may be very difficult to identify without explicitly
  141. * checking the resulting size of the eeprom map. */
  142. BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
  143. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  144. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  145. return -ENOENT;
  146. }
  147. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  148. ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
  149. if (ret < 0) {
  150. IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
  151. return -ENOENT;
  152. }
  153. /* eeprom is an array of 16bit values */
  154. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  155. _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
  156. _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
  157. for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
  158. i += IWL_EEPROM_ACCESS_DELAY) {
  159. r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
  160. if (r & CSR_EEPROM_REG_READ_VALID_MSK)
  161. break;
  162. udelay(IWL_EEPROM_ACCESS_DELAY);
  163. }
  164. if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
  165. IWL_ERROR("Time out reading EEPROM[%d]", addr);
  166. ret = -ETIMEDOUT;
  167. goto done;
  168. }
  169. e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
  170. }
  171. ret = 0;
  172. done:
  173. priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
  174. return ret;
  175. }
  176. EXPORT_SYMBOL(iwl_eeprom_init);
  177. void iwl_eeprom_get_mac(const struct iwl4965_priv *priv, u8 *mac)
  178. {
  179. memcpy(mac, priv->eeprom.mac_address, 6);
  180. }
  181. EXPORT_SYMBOL(iwl_eeprom_get_mac);