1 /******************************************************************************
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.
8 * Copyright(c) 2008 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
27 * Contact Information:
28 * Tomas Winkler <tomas.winkler@intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/module.h>
66 #include <linux/version.h>
67 #include <linux/init.h>
69 #include <net/mac80211.h>
71 #include "iwl-4965-commands.h"
74 #include "iwl-debug.h"
75 #include "iwl-eeprom.h"
76 #include "iwl-4965-io.h"
78 /******************************************************************************
80 * EEPROM related functions
82 ******************************************************************************/
84 int iwlcore_eeprom_verify_signature(struct iwl_priv *priv)
86 u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
87 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
88 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
93 EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
96 * The device's EEPROM semaphore prevents conflicts between driver and uCode
97 * when accessing the EEPROM; each access is a series of pulses to/from the
98 * EEPROM chip, not a single event, so even reads could conflict if they
99 * weren't arbitrated by the semaphore.
101 int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv)
106 for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
107 /* Request semaphore */
108 iwl4965_set_bit(priv, CSR_HW_IF_CONFIG_REG,
109 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
111 /* See if we got it */
112 ret = iwl4965_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
113 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
114 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
117 IWL_DEBUG_IO("Acquired semaphore after %d tries.\n",
125 EXPORT_SYMBOL(iwlcore_eeprom_acquire_semaphore);
127 void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
129 iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
130 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
133 EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
137 * iwl_eeprom_init - read EEPROM contents
139 * Load the EEPROM contents from adapter into priv->eeprom
141 * NOTE: This routine uses the non-debug IO access functions.
143 int iwl_eeprom_init(struct iwl_priv *priv)
145 u16 *e = (u16 *)&priv->eeprom;
146 u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
148 int sz = sizeof(priv->eeprom);
153 /* The EEPROM structure has several padding buffers within it
154 * and when adding new EEPROM maps is subject to programmer errors
155 * which may be very difficult to identify without explicitly
156 * checking the resulting size of the eeprom map. */
157 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
159 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
160 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
164 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
165 ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
167 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
171 /* eeprom is an array of 16bit values */
172 for (addr = 0; addr < sz; addr += sizeof(u16)) {
173 _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
174 _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
176 for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
177 i += IWL_EEPROM_ACCESS_DELAY) {
178 r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
179 if (r & CSR_EEPROM_REG_READ_VALID_MSK)
181 udelay(IWL_EEPROM_ACCESS_DELAY);
184 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
185 IWL_ERROR("Time out reading EEPROM[%d]", addr);
189 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
194 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
197 EXPORT_SYMBOL(iwl_eeprom_init);
200 void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
202 memcpy(mac, priv->eeprom.mac_address, 6);
204 EXPORT_SYMBOL(iwl_eeprom_get_mac);