blob: c8397962632c97f2a830205390a0c7350c54a48e [file] [log] [blame]
Assaf Krauss34cf6ff2008-03-06 10:40:20 -08001/******************************************************************************
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 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07008 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
Assaf Krauss34cf6ff2008-03-06 10:40:20 -08009 *
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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080028 * Intel Linux Wireless <ilw@linux.intel.com>
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080029 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -070033 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080034 * 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
63
64#include <linux/kernel.h>
65#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090066#include <linux/slab.h>
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080067#include <linux/init.h>
68
69#include <net/mac80211.h>
70
Tomas Winkler5a36ba02008-04-24 11:55:37 -070071#include "iwl-commands.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070072#include "iwl-dev.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080073#include "iwl-core.h"
Tomas Winkler0a6857e2008-03-12 16:58:49 -070074#include "iwl-debug.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080075#include "iwl-eeprom.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070076#include "iwl-io.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080077
Assaf Kraussbf85ea42008-03-14 10:38:49 -070078/************************** EEPROM BANDS ****************************
79 *
80 * The iwl_eeprom_band definitions below provide the mapping from the
81 * EEPROM contents to the specific channel number supported for each
82 * band.
83 *
84 * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
85 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
86 * The specific geography and calibration information for that channel
87 * is contained in the eeprom map itself.
88 *
89 * During init, we copy the eeprom information and channel map
90 * information into priv->channel_info_24/52 and priv->channel_map_24/52
91 *
92 * channel_map_24/52 provides the index in the channel_info array for a
93 * given channel. We have to have two separate maps as there is channel
94 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
95 * band_2
96 *
97 * A value of 0xff stored in the channel_map indicates that the channel
98 * is not supported by the hardware at all.
99 *
100 * A value of 0xfe in the channel_map indicates that the channel is not
101 * valid for Tx with the current hardware. This means that
102 * while the system can tune and receive on a given channel, it may not
103 * be able to associate or transmit any frames on that
104 * channel. There is no corresponding channel information for that
105 * entry.
106 *
107 *********************************************************************/
108
109/* 2.4 GHz */
110const u8 iwl_eeprom_band_1[14] = {
111 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
112};
113
114/* 5.2 GHz bands */
115static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
116 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
117};
118
119static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
120 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
121};
122
123static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
124 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
125};
126
127static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
128 145, 149, 153, 157, 161, 165
129};
130
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700131static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700132 1, 2, 3, 4, 5, 6, 7
133};
134
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700135static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700136 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
137};
138
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800139/******************************************************************************
140 *
141 * EEPROM related functions
142 *
143******************************************************************************/
144
Don Fry16b80b72011-04-20 15:25:14 -0700145/*
146 * The device's EEPROM semaphore prevents conflicts between driver and uCode
147 * when accessing the EEPROM; each access is a series of pulses to/from the
148 * EEPROM chip, not a single event, so even reads could conflict if they
149 * weren't arbitrated by the semaphore.
150 */
151static int iwl_eeprom_acquire_semaphore(struct iwl_priv *priv)
152{
153 u16 count;
154 int ret;
155
156 for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
157 /* Request semaphore */
158 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
159 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
160
161 /* See if we got it */
162 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
163 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
164 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
165 EEPROM_SEM_TIMEOUT);
166 if (ret >= 0) {
167 IWL_DEBUG_EEPROM(priv,
168 "Acquired semaphore after %d tries.\n",
169 count+1);
170 return ret;
171 }
172 }
173
174 return ret;
175}
176
177static void iwl_eeprom_release_semaphore(struct iwl_priv *priv)
178{
179 iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
180 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
181
182}
183
Johannes Bergd3f5ba92010-09-22 18:02:00 +0200184static int iwl_eeprom_verify_signature(struct iwl_priv *priv)
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800185{
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700186 u32 gp = iwl_read32(priv, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
187 int ret = 0;
188
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800189 IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700190 switch (gp) {
191 case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
192 if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
193 IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
194 gp);
195 ret = -ENOENT;
196 }
197 break;
198 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
199 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
200 if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
201 IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
202 ret = -ENOENT;
203 }
204 break;
205 case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
206 default:
207 IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
208 "EEPROM_GP=0x%08x\n",
209 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
210 ? "OTP" : "EEPROM", gp);
211 ret = -ENOENT;
212 break;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800213 }
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700214 return ret;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800215}
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800216
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700217static void iwl_set_otp_access(struct iwl_priv *priv, enum iwl_access_mode mode)
218{
219 u32 otpgp;
220
221 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
222 if (mode == IWL_OTP_ACCESS_ABSOLUTE)
223 iwl_clear_bit(priv, CSR_OTP_GP_REG,
224 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
225 else
226 iwl_set_bit(priv, CSR_OTP_GP_REG,
227 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
228}
229
Johannes Berge98a1302011-04-05 09:42:08 -0700230static int iwlcore_get_nvm_type(struct iwl_priv *priv, u32 hw_rev)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700231{
232 u32 otpgp;
233 int nvm_type;
234
235 /* OTP only valid for CP/PP and after */
Johannes Berge98a1302011-04-05 09:42:08 -0700236 switch (hw_rev & CSR_HW_REV_TYPE_MSK) {
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700237 case CSR_HW_REV_TYPE_NONE:
238 IWL_ERR(priv, "Unknown hardware type\n");
239 return -ENOENT;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700240 case CSR_HW_REV_TYPE_5300:
241 case CSR_HW_REV_TYPE_5350:
242 case CSR_HW_REV_TYPE_5100:
243 case CSR_HW_REV_TYPE_5150:
244 nvm_type = NVM_DEVICE_TYPE_EEPROM;
245 break;
246 default:
247 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
248 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
249 nvm_type = NVM_DEVICE_TYPE_OTP;
250 else
251 nvm_type = NVM_DEVICE_TYPE_EEPROM;
252 break;
253 }
254 return nvm_type;
255}
256
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700257static int iwl_init_otp_access(struct iwl_priv *priv)
258{
259 int ret;
260
261 /* Enable 40MHz radio clock */
Johannes Berg02a7fa02011-04-05 09:42:12 -0700262 iwl_write32(priv, CSR_GP_CNTRL,
263 iwl_read32(priv, CSR_GP_CNTRL) |
264 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700265
266 /* wait for clock to be ready */
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700267 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700268 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
269 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
270 25000);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700271 if (ret < 0)
272 IWL_ERR(priv, "Time out access OTP\n");
273 else {
Reinette Chatred77b0342009-05-22 14:37:55 -0700274 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
275 APMG_PS_CTRL_VAL_RESET_REQ);
276 udelay(5);
277 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
278 APMG_PS_CTRL_VAL_RESET_REQ);
Wey-Yi Guy32004ee2009-10-16 14:25:56 -0700279
280 /*
281 * CSR auto clock gate disable bit -
282 * this is only applicable for HW with OTP shadow RAM
283 */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700284 if (priv->cfg->base_params->shadow_ram_support)
Wey-Yi Guy32004ee2009-10-16 14:25:56 -0700285 iwl_set_bit(priv, CSR_DBG_LINK_PWR_MGMT_REG,
286 CSR_RESET_LINK_PWR_MGMT_DISABLED);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700287 }
288 return ret;
289}
290
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800291static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, __le16 *eeprom_data)
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700292{
293 int ret = 0;
294 u32 r;
295 u32 otpgp;
296
Johannes Berg02a7fa02011-04-05 09:42:12 -0700297 iwl_write32(priv, CSR_EEPROM_REG,
298 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700299 ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700300 CSR_EEPROM_REG_READ_VALID_MSK,
301 CSR_EEPROM_REG_READ_VALID_MSK,
302 IWL_EEPROM_ACCESS_TIMEOUT);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700303 if (ret < 0) {
304 IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
305 return ret;
306 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700307 r = iwl_read32(priv, CSR_EEPROM_REG);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700308 /* check for ECC errors: */
309 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
310 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
311 /* stop in this case */
312 /* set the uncorrectable OTP ECC bit for acknowledgement */
313 iwl_set_bit(priv, CSR_OTP_GP_REG,
314 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
315 IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
316 return -EINVAL;
317 }
318 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
319 /* continue in this case */
320 /* set the correctable OTP ECC bit for acknowledgement */
321 iwl_set_bit(priv, CSR_OTP_GP_REG,
322 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
323 IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
324 }
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800325 *eeprom_data = cpu_to_le16(r >> 16);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700326 return 0;
327}
328
329/*
330 * iwl_is_otp_empty: check for empty OTP
331 */
332static bool iwl_is_otp_empty(struct iwl_priv *priv)
333{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800334 u16 next_link_addr = 0;
335 __le16 link_value;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700336 bool is_empty = false;
337
338 /* locate the beginning of OTP link list */
339 if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
340 if (!link_value) {
341 IWL_ERR(priv, "OTP is empty\n");
342 is_empty = true;
343 }
344 } else {
345 IWL_ERR(priv, "Unable to read first block of OTP list.\n");
346 is_empty = true;
347 }
348
349 return is_empty;
350}
351
352
353/*
354 * iwl_find_otp_image: find EEPROM image in OTP
355 * finding the OTP block that contains the EEPROM image.
356 * the last valid block on the link list (the block _before_ the last block)
357 * is the block we should read and used to configure the device.
358 * If all the available OTP blocks are full, the last block will be the block
359 * we should read and used to configure the device.
360 * only perform this operation if shadow RAM is disabled
361 */
362static int iwl_find_otp_image(struct iwl_priv *priv,
363 u16 *validblockaddr)
364{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800365 u16 next_link_addr = 0, valid_addr;
366 __le16 link_value = 0;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700367 int usedblocks = 0;
368
369 /* set addressing mode to absolute to traverse the link list */
370 iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
371
372 /* checking for empty OTP or error */
373 if (iwl_is_otp_empty(priv))
374 return -EINVAL;
375
376 /*
377 * start traverse link list
378 * until reach the max number of OTP blocks
379 * different devices have different number of OTP blocks
380 */
381 do {
382 /* save current valid block address
383 * check for more block on the link list
384 */
385 valid_addr = next_link_addr;
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800386 next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800387 IWL_DEBUG_EEPROM(priv, "OTP blocks %d addr 0x%x\n",
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700388 usedblocks, next_link_addr);
389 if (iwl_read_otp_word(priv, next_link_addr, &link_value))
390 return -EINVAL;
391 if (!link_value) {
392 /*
Jay Sternberg2facba72009-10-02 13:43:55 -0700393 * reach the end of link list, return success and
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700394 * set address point to the starting address
395 * of the image
396 */
Jay Sternberg2facba72009-10-02 13:43:55 -0700397 *validblockaddr = valid_addr;
398 /* skip first 2 bytes (link list pointer) */
399 *validblockaddr += 2;
400 return 0;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700401 }
402 /* more in the link list, continue */
403 usedblocks++;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700404 } while (usedblocks <= priv->cfg->base_params->max_ll_items);
Jay Sternberg2facba72009-10-02 13:43:55 -0700405
406 /* OTP has no valid blocks */
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800407 IWL_DEBUG_EEPROM(priv, "OTP has no valid blocks\n");
Jay Sternberg2facba72009-10-02 13:43:55 -0700408 return -EINVAL;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700409}
410
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700411const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
412{
413 return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
414}
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700415
416u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
417{
418 if (!priv->eeprom)
419 return 0;
420 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
421}
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700422
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800423/**
424 * iwl_eeprom_init - read EEPROM contents
425 *
426 * Load the EEPROM contents from adapter into priv->eeprom
427 *
428 * NOTE: This routine uses the non-debug IO access functions.
429 */
Johannes Berge98a1302011-04-05 09:42:08 -0700430int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev)
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800431{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800432 __le16 *e;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700433 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700434 int sz;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800435 int ret;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800436 u16 addr;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700437 u16 validblockaddr = 0;
438 u16 cache_addr = 0;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700439
Johannes Berge98a1302011-04-05 09:42:08 -0700440 priv->nvm_device_type = iwlcore_get_nvm_type(priv, hw_rev);
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700441 if (priv->nvm_device_type == -ENOENT)
442 return -ENOENT;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700443 /* allocate eeprom */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700444 sz = priv->cfg->base_params->eeprom_size;
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800445 IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700446 priv->eeprom = kzalloc(sz, GFP_KERNEL);
447 if (!priv->eeprom) {
448 ret = -ENOMEM;
449 goto alloc_err;
450 }
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800451 e = (__le16 *)priv->eeprom;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800452
Reinette Chatref8701fe2009-12-10 14:37:22 -0800453 priv->cfg->ops->lib->apm_ops.init(priv);
Reinette Chatree43ab942009-11-13 11:56:32 -0800454
Johannes Bergd3f5ba92010-09-22 18:02:00 +0200455 ret = iwl_eeprom_verify_signature(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700456 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800457 IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700458 ret = -ENOENT;
459 goto err;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800460 }
461
462 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
Don Fry16b80b72011-04-20 15:25:14 -0700463 ret = iwl_eeprom_acquire_semaphore(priv);
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800464 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800465 IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -0700466 ret = -ENOENT;
467 goto err;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800468 }
Ben Cahill88521362009-10-30 14:36:06 -0700469
Reinette Chatree43ab942009-11-13 11:56:32 -0800470 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
Ben Cahill88521362009-10-30 14:36:06 -0700471
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700472 ret = iwl_init_otp_access(priv);
473 if (ret) {
474 IWL_ERR(priv, "Failed to initialize OTP access.\n");
475 ret = -ENOENT;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700476 goto done;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800477 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700478 iwl_write32(priv, CSR_EEPROM_GP,
479 iwl_read32(priv, CSR_EEPROM_GP) &
480 ~CSR_EEPROM_GP_IF_OWNER_MSK);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700481
482 iwl_set_bit(priv, CSR_OTP_GP_REG,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700483 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
484 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700485 /* traversing the linked list if no shadow ram supported */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700486 if (!priv->cfg->base_params->shadow_ram_support) {
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700487 if (iwl_find_otp_image(priv, &validblockaddr)) {
488 ret = -ENOENT;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700489 goto done;
490 }
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700491 }
492 for (addr = validblockaddr; addr < validblockaddr + sz;
493 addr += sizeof(u16)) {
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800494 __le16 eeprom_data;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700495
496 ret = iwl_read_otp_word(priv, addr, &eeprom_data);
497 if (ret)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700498 goto done;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700499 e[cache_addr / 2] = eeprom_data;
500 cache_addr += sizeof(u16);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700501 }
502 } else {
503 /* eeprom is an array of 16bit values */
504 for (addr = 0; addr < sz; addr += sizeof(u16)) {
505 u32 r;
506
Johannes Berg02a7fa02011-04-05 09:42:12 -0700507 iwl_write32(priv, CSR_EEPROM_REG,
508 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700509
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700510 ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
511 CSR_EEPROM_REG_READ_VALID_MSK,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700512 CSR_EEPROM_REG_READ_VALID_MSK,
513 IWL_EEPROM_ACCESS_TIMEOUT);
514 if (ret < 0) {
515 IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
516 goto done;
517 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700518 r = iwl_read32(priv, CSR_EEPROM_REG);
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800519 e[addr / 2] = cpu_to_le16(r >> 16);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700520 }
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800521 }
Johannes Bergd1358f62010-04-28 12:09:15 -0700522
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800523 IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
Johannes Bergd1358f62010-04-28 12:09:15 -0700524 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
525 ? "OTP" : "EEPROM",
526 iwl_eeprom_query16(priv, EEPROM_VERSION));
527
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800528 ret = 0;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800529done:
Don Fry16b80b72011-04-20 15:25:14 -0700530 iwl_eeprom_release_semaphore(priv);
Johannes Bergd1358f62010-04-28 12:09:15 -0700531
Tomas Winkler073d3f52008-04-21 15:41:52 -0700532err:
533 if (ret)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700534 iwl_eeprom_free(priv);
Reinette Chatref8701fe2009-12-10 14:37:22 -0800535 /* Reset chip to save power until we load uCode during "up". */
Johannes Berg14e8e4a2010-09-22 18:02:10 +0200536 iwl_apm_stop(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700537alloc_err:
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800538 return ret;
539}
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800540
Tomas Winkler073d3f52008-04-21 15:41:52 -0700541void iwl_eeprom_free(struct iwl_priv *priv)
542{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300543 kfree(priv->eeprom);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700544 priv->eeprom = NULL;
545}
Tomas Winkler073d3f52008-04-21 15:41:52 -0700546
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700547static void iwl_init_band_reference(const struct iwl_priv *priv,
Tomas Winkler073d3f52008-04-21 15:41:52 -0700548 int eep_band, int *eeprom_ch_count,
549 const struct iwl_eeprom_channel **eeprom_ch_info,
550 const u8 **eeprom_ch_index)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700551{
Tomas Winkler073d3f52008-04-21 15:41:52 -0700552 u32 offset = priv->cfg->ops->lib->
553 eeprom_ops.regulatory_bands[eep_band - 1];
554 switch (eep_band) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700555 case 1: /* 2.4GHz band */
556 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700557 *eeprom_ch_info = (struct iwl_eeprom_channel *)
558 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700559 *eeprom_ch_index = iwl_eeprom_band_1;
560 break;
561 case 2: /* 4.9GHz band */
562 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700563 *eeprom_ch_info = (struct iwl_eeprom_channel *)
564 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700565 *eeprom_ch_index = iwl_eeprom_band_2;
566 break;
567 case 3: /* 5.2GHz band */
568 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700569 *eeprom_ch_info = (struct iwl_eeprom_channel *)
570 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700571 *eeprom_ch_index = iwl_eeprom_band_3;
572 break;
573 case 4: /* 5.5GHz band */
574 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700575 *eeprom_ch_info = (struct iwl_eeprom_channel *)
576 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700577 *eeprom_ch_index = iwl_eeprom_band_4;
578 break;
579 case 5: /* 5.7GHz band */
580 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700581 *eeprom_ch_info = (struct iwl_eeprom_channel *)
582 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700583 *eeprom_ch_index = iwl_eeprom_band_5;
584 break;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700585 case 6: /* 2.4GHz ht40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700586 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700587 *eeprom_ch_info = (struct iwl_eeprom_channel *)
588 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700589 *eeprom_ch_index = iwl_eeprom_band_6;
590 break;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700591 case 7: /* 5 GHz ht40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700592 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700593 *eeprom_ch_info = (struct iwl_eeprom_channel *)
594 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700595 *eeprom_ch_index = iwl_eeprom_band_7;
596 break;
597 default:
598 BUG();
599 return;
600 }
601}
602
603#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
604 ? # x " " : "")
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700605/**
Zhu Yi3b247162009-08-13 13:30:53 -0700606 * iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700607 *
608 * Does not set up a command, or touch hardware.
609 */
Zhu Yi3b247162009-08-13 13:30:53 -0700610static int iwl_mod_ht40_chan_info(struct iwl_priv *priv,
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700611 enum ieee80211_band band, u16 channel,
Tomas Winkler073d3f52008-04-21 15:41:52 -0700612 const struct iwl_eeprom_channel *eeprom_ch,
Zhu Yi3b247162009-08-13 13:30:53 -0700613 u8 clear_ht40_extension_channel)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700614{
615 struct iwl_channel_info *ch_info;
616
617 ch_info = (struct iwl_channel_info *)
Assaf Krauss8622e702008-03-21 13:53:43 -0700618 iwl_get_channel_info(priv, band, channel);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700619
620 if (!is_channel_valid(ch_info))
621 return -1;
622
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800623 IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
Tomas Winkler630fe9b2008-06-12 09:47:08 +0800624 " Ad-Hoc %ssupported\n",
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700625 ch_info->channel,
626 is_channel_a_band(ch_info) ?
627 "5.2" : "2.4",
628 CHECK_AND_PRINT(IBSS),
629 CHECK_AND_PRINT(ACTIVE),
630 CHECK_AND_PRINT(RADAR),
631 CHECK_AND_PRINT(WIDE),
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700632 CHECK_AND_PRINT(DFS),
633 eeprom_ch->flags,
634 eeprom_ch->max_power_avg,
635 ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
636 && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
637 "" : "not ");
638
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700639 ch_info->ht40_eeprom = *eeprom_ch;
640 ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700641 ch_info->ht40_flags = eeprom_ch->flags;
Reinette Chatre6c3069b2009-12-14 14:12:13 -0800642 if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
643 ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700644
645 return 0;
646}
647
648#define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
649 ? # x " " : "")
650
651/**
652 * iwl_init_channel_map - Set up driver's info for all possible channels
653 */
654int iwl_init_channel_map(struct iwl_priv *priv)
655{
656 int eeprom_ch_count = 0;
657 const u8 *eeprom_ch_index = NULL;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700658 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700659 int band, ch;
660 struct iwl_channel_info *ch_info;
661
662 if (priv->channel_count) {
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800663 IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700664 return 0;
665 }
666
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800667 IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700668
669 priv->channel_count =
670 ARRAY_SIZE(iwl_eeprom_band_1) +
671 ARRAY_SIZE(iwl_eeprom_band_2) +
672 ARRAY_SIZE(iwl_eeprom_band_3) +
673 ARRAY_SIZE(iwl_eeprom_band_4) +
674 ARRAY_SIZE(iwl_eeprom_band_5);
675
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800676 IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
677 priv->channel_count);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700678
679 priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
680 priv->channel_count, GFP_KERNEL);
681 if (!priv->channel_info) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800682 IWL_ERR(priv, "Could not allocate channel_info\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700683 priv->channel_count = 0;
684 return -ENOMEM;
685 }
686
687 ch_info = priv->channel_info;
688
689 /* Loop through the 5 EEPROM bands adding them in order to the
690 * channel map we maintain (that contains additional information than
691 * what just in the EEPROM) */
692 for (band = 1; band <= 5; band++) {
693
694 iwl_init_band_reference(priv, band, &eeprom_ch_count,
695 &eeprom_ch_info, &eeprom_ch_index);
696
697 /* Loop through each band adding each of the channels */
698 for (ch = 0; ch < eeprom_ch_count; ch++) {
699 ch_info->channel = eeprom_ch_index[ch];
700 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
701 IEEE80211_BAND_5GHZ;
702
703 /* permanently store EEPROM's channel regulatory flags
704 * and max power in channel info database. */
705 ch_info->eeprom = eeprom_ch_info[ch];
706
707 /* Copy the run-time flags so they are there even on
708 * invalid channels */
709 ch_info->flags = eeprom_ch_info[ch].flags;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700710 /* First write that ht40 is not enabled, and then enable
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800711 * one by one */
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700712 ch_info->ht40_extension_channel =
Zhu Yi3b247162009-08-13 13:30:53 -0700713 IEEE80211_CHAN_NO_HT40;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700714
715 if (!(is_channel_valid(ch_info))) {
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800716 IWL_DEBUG_EEPROM(priv,
717 "Ch. %d Flags %x [%sGHz] - "
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700718 "No traffic\n",
719 ch_info->channel,
720 ch_info->flags,
721 is_channel_a_band(ch_info) ?
722 "5.2" : "2.4");
723 ch_info++;
724 continue;
725 }
726
727 /* Initialize regulatory-based run-time data */
728 ch_info->max_power_avg = ch_info->curr_txpow =
729 eeprom_ch_info[ch].max_power_avg;
730 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
731 ch_info->min_power = 0;
732
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800733 IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] "
734 "%s%s%s%s%s%s(0x%02x %ddBm):"
Tomas Winkler630fe9b2008-06-12 09:47:08 +0800735 " Ad-Hoc %ssupported\n",
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700736 ch_info->channel,
737 is_channel_a_band(ch_info) ?
738 "5.2" : "2.4",
739 CHECK_AND_PRINT_I(VALID),
740 CHECK_AND_PRINT_I(IBSS),
741 CHECK_AND_PRINT_I(ACTIVE),
742 CHECK_AND_PRINT_I(RADAR),
743 CHECK_AND_PRINT_I(WIDE),
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700744 CHECK_AND_PRINT_I(DFS),
745 eeprom_ch_info[ch].flags,
746 eeprom_ch_info[ch].max_power_avg,
747 ((eeprom_ch_info[ch].
748 flags & EEPROM_CHANNEL_IBSS)
749 && !(eeprom_ch_info[ch].
750 flags & EEPROM_CHANNEL_RADAR))
751 ? "" : "not ");
752
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700753 ch_info++;
754 }
755 }
756
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700757 /* Check if we do have HT40 channels */
Reinette Chatrea89d03c2009-02-10 15:19:04 -0800758 if (priv->cfg->ops->lib->eeprom_ops.regulatory_bands[5] ==
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700759 EEPROM_REGULATORY_BAND_NO_HT40 &&
Reinette Chatrea89d03c2009-02-10 15:19:04 -0800760 priv->cfg->ops->lib->eeprom_ops.regulatory_bands[6] ==
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700761 EEPROM_REGULATORY_BAND_NO_HT40)
Samuel Ortize6148912009-01-23 13:45:15 -0800762 return 0;
763
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700764 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700765 for (band = 6; band <= 7; band++) {
766 enum ieee80211_band ieeeband;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700767
768 iwl_init_band_reference(priv, band, &eeprom_ch_count,
769 &eeprom_ch_info, &eeprom_ch_index);
770
771 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
772 ieeeband =
773 (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
774
775 /* Loop through each band adding each of the channels */
776 for (ch = 0; ch < eeprom_ch_count; ch++) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700777 /* Set up driver's info for lower half */
Zhu Yi3b247162009-08-13 13:30:53 -0700778 iwl_mod_ht40_chan_info(priv, ieeeband,
Tomas Winklerda6833c2008-05-15 13:54:15 +0800779 eeprom_ch_index[ch],
Zhu Yi3b247162009-08-13 13:30:53 -0700780 &eeprom_ch_info[ch],
781 IEEE80211_CHAN_NO_HT40PLUS);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700782
783 /* Set up driver's info for upper half */
Zhu Yi3b247162009-08-13 13:30:53 -0700784 iwl_mod_ht40_chan_info(priv, ieeeband,
785 eeprom_ch_index[ch] + 4,
786 &eeprom_ch_info[ch],
787 IEEE80211_CHAN_NO_HT40MINUS);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700788 }
789 }
790
Wey-Yi Guyab9fd1b2009-08-21 13:34:23 -0700791 /* for newer device (6000 series and up)
792 * EEPROM contain enhanced tx power information
793 * driver need to process addition information
794 * to determine the max channel tx power limits
795 */
796 if (priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower)
797 priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower(priv);
798
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700799 return 0;
800}
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700801
802/*
Tomas Winklerda6833c2008-05-15 13:54:15 +0800803 * iwl_free_channel_map - undo allocations in iwl_init_channel_map
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700804 */
805void iwl_free_channel_map(struct iwl_priv *priv)
806{
807 kfree(priv->channel_info);
808 priv->channel_count = 0;
809}
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700810
811/**
812 * iwl_get_channel_info - Find driver's private channel info
813 *
814 * Based on band and channel number.
815 */
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800816const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
817 enum ieee80211_band band, u16 channel)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700818{
819 int i;
820
821 switch (band) {
822 case IEEE80211_BAND_5GHZ:
823 for (i = 14; i < priv->channel_count; i++) {
824 if (priv->channel_info[i].channel == channel)
825 return &priv->channel_info[i];
826 }
827 break;
828 case IEEE80211_BAND_2GHZ:
829 if (channel >= 1 && channel <= 14)
830 return &priv->channel_info[channel - 1];
831 break;
832 default:
833 BUG();
834 }
835
836 return NULL;
837}