2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 firmware loading specific routines.
24 Supported chipsets: rt2561, rt2561s, rt2661, rt2571W & rt2671.
28 * Set enviroment defines for rt2x00.h
30 #define DRV_NAME "rt2x00lib"
32 #include <linux/delay.h>
33 #include <linux/crc-itu-t.h>
34 #include <linux/firmware.h>
37 #include "rt2x00lib.h"
38 #include "rt2x00firmware.h"
40 static void rt2x00lib_load_firmware_continued(const struct firmware
*fw
,
43 struct rt2x00_dev
*rt2x00dev
= context
;
47 if (!fw
|| !fw
->size
|| !fw
->data
) {
48 ERROR(rt2x00dev
, "Failed to read Firmware.\n");
53 * Validate the firmware using 16 bit CRC.
54 * The last 2 bytes of the firmware are the CRC
55 * so substract those 2 bytes from the CRC checksum,
56 * and set those 2 bytes to 0 when calculating CRC.
59 crc
= crc_itu_t(0, fw
->data
, fw
->size
- 2);
60 crc
= crc_itu_t(crc
, (u8
*)&tmp
, 2);
62 if (crc
!= (fw
->data
[fw
->size
- 2] << 8 | fw
->data
[fw
->size
- 1])) {
63 ERROR(rt2x00dev
, "Firmware CRC error.\n");
68 * Send firmware to the device.
70 if (rt2x00dev
->ops
->lib
->load_firmware(rt2x00dev
, fw
->data
, fw
->size
))
73 INFO(rt2x00dev
, "Firmware detected - version: %d.%d.\n",
74 fw
->data
[fw
->size
- 4], fw
->data
[fw
->size
- 3]);
76 __set_bit(FIRMWARE_LOADED
, &rt2x00dev
->flags
);
81 rt2x00debug_deregister(rt2x00dev
);
83 __set_bit(FIRMWARE_FAILED
, &rt2x00dev
->flags
);
86 int rt2x00lib_load_firmware(struct rt2x00_dev
*rt2x00dev
)
92 * Read correct firmware from harddisk.
94 fw_name
= rt2x00dev
->ops
->lib
->get_fw_name(rt2x00dev
);
97 "Invalid firmware filename.\n"
98 "Please file bug report to %s.\n", DRV_PROJECT
);
102 INFO(rt2x00dev
, "Loading firmware file '%s'.\n", fw_name
);
104 status
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
105 fw_name
, wiphy_dev(rt2x00dev
->hw
->wiphy
), rt2x00dev
,
106 &rt2x00lib_load_firmware_continued
);
109 ERROR(rt2x00dev
, "Failed to request Firmware.\n");
114 int rt2x00lib_load_firmware_wait(struct rt2x00_dev
*rt2x00dev
)
118 if (!test_bit(FIRMWARE_REQUIRED
, &rt2x00dev
->flags
))
121 for (i
= 0; i
< 150; i
++) {
122 if (test_bit(FIRMWARE_FAILED
, &rt2x00dev
->flags
))
124 if (test_bit(FIRMWARE_LOADED
, &rt2x00dev
->flags
))
129 ERROR(rt2x00dev
, "Firmware loading timed out.\n");