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/crc-itu-t.h>
33 #include <linux/firmware.h>
36 #include "rt2x00firmware.h"
38 static void rt2x00lib_load_firmware_continued(const struct firmware
*fw
,
41 struct rt2x00_dev
*rt2x00dev
= context
;
45 if (!fw
|| !fw
->size
|| !fw
->data
) {
46 ERROR(rt2x00dev
, "Failed to read Firmware.\n");
51 * Validate the firmware using 16 bit CRC.
52 * The last 2 bytes of the firmware are the CRC
53 * so substract those 2 bytes from the CRC checksum,
54 * and set those 2 bytes to 0 when calculating CRC.
57 crc
= crc_itu_t(0, fw
->data
, fw
->size
- 2);
58 crc
= crc_itu_t(crc
, (u8
*)&tmp
, 2);
60 if (crc
!= (fw
->data
[fw
->size
- 2] << 8 | fw
->data
[fw
->size
- 1])) {
61 ERROR(rt2x00dev
, "Firmware CRC error.\n");
66 * Send firmware to the device.
68 if (rt2x00dev
->ops
->lib
->load_firmware(rt2x00dev
, fw
->data
, fw
->size
))
71 INFO(rt2x00dev
, "Firmware detected - version: %d.%d.\n",
72 fw
->data
[fw
->size
- 4], fw
->data
[fw
->size
- 3]);
74 __set_bit(FIRMWARE_LOADED
, &rt2x00dev
->flags
);
79 rt2x00debug_deregister(rt2x00dev
);
81 __set_bit(FIRMWARE_FAILED
, &rt2x00dev
->flags
);
84 int rt2x00lib_load_firmware(struct rt2x00_dev
*rt2x00dev
)
90 * Read correct firmware from harddisk.
92 fw_name
= rt2x00dev
->ops
->lib
->get_fw_name(rt2x00dev
);
93 BUG_ON(fw_name
== NULL
);
95 INFO(rt2x00dev
, "Loading firmware file '%s'.\n", fw_name
);
97 status
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
98 fw_name
, rt2x00dev
->device
, rt2x00dev
,
99 &rt2x00lib_load_firmware_continued
);
102 ERROR(rt2x00dev
, "Failed to request Firmware.\n");
107 int rt2x00lib_load_firmware_wait(struct rt2x00_dev
*rt2x00dev
)
111 if (!test_bit(FIRMWARE_REQUIRED
, &rt2x00dev
->flags
))
114 for (i
= 0; i
< 150; i
++) {
115 if (test_bit(FIRMWARE_FAILED
, &rt2x00dev
->flags
))
117 if (test_bit(FIRMWARE_LOADED
, &rt2x00dev
->flags
))
122 ERROR(rt2x00dev
, "Firmware loading timed out.\n");