Commit | Line | Data |
---|---|---|
95ea3627 | 1 | /* |
9c9a0d14 GW |
2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
3 | Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com> | |
95ea3627 ID |
4 | <http://rt2x00.serialmonkey.com> |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
a05b8c58 | 17 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
95ea3627 ID |
18 | */ |
19 | ||
20 | /* | |
21 | Module: rt2x00lib | |
22 | Abstract: rt2x00 firmware loading routines. | |
23 | */ | |
24 | ||
95ea3627 ID |
25 | #include <linux/kernel.h> |
26 | #include <linux/module.h> | |
27 | ||
28 | #include "rt2x00.h" | |
29 | #include "rt2x00lib.h" | |
30 | ||
31 | static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev) | |
32 | { | |
33 | struct device *device = wiphy_dev(rt2x00dev->hw->wiphy); | |
34 | const struct firmware *fw; | |
35 | char *fw_name; | |
36 | int retval; | |
95ea3627 ID |
37 | |
38 | /* | |
39 | * Read correct firmware from harddisk. | |
40 | */ | |
41 | fw_name = rt2x00dev->ops->lib->get_firmware_name(rt2x00dev); | |
42 | if (!fw_name) { | |
ec9c4989 JP |
43 | rt2x00_err(rt2x00dev, |
44 | "Invalid firmware filename\n" | |
45 | "Please file bug report to %s\n", DRV_PROJECT); | |
95ea3627 ID |
46 | return -EINVAL; |
47 | } | |
48 | ||
ec9c4989 | 49 | rt2x00_info(rt2x00dev, "Loading firmware file '%s'\n", fw_name); |
95ea3627 ID |
50 | |
51 | retval = request_firmware(&fw, fw_name, device); | |
52 | if (retval) { | |
ec9c4989 | 53 | rt2x00_err(rt2x00dev, "Failed to request Firmware\n"); |
95ea3627 ID |
54 | return retval; |
55 | } | |
56 | ||
57 | if (!fw || !fw->size || !fw->data) { | |
ec9c4989 | 58 | rt2x00_err(rt2x00dev, "Failed to read Firmware\n"); |
ccbd4d41 | 59 | release_firmware(fw); |
95ea3627 ID |
60 | return -ENOENT; |
61 | } | |
62 | ||
ec9c4989 JP |
63 | rt2x00_info(rt2x00dev, "Firmware detected - version: %d.%d\n", |
64 | fw->data[fw->size - 4], fw->data[fw->size - 3]); | |
dd358c9a JL |
65 | snprintf(rt2x00dev->hw->wiphy->fw_version, |
66 | sizeof(rt2x00dev->hw->wiphy->fw_version), "%d.%d", | |
67 | fw->data[fw->size - 4], fw->data[fw->size - 3]); | |
95ea3627 | 68 | |
0cbe0064 ID |
69 | retval = rt2x00dev->ops->lib->check_firmware(rt2x00dev, fw->data, fw->size); |
70 | switch (retval) { | |
71 | case FW_OK: | |
72 | break; | |
73 | case FW_BAD_CRC: | |
ec9c4989 | 74 | rt2x00_err(rt2x00dev, "Firmware checksum error\n"); |
0cbe0064 ID |
75 | goto exit; |
76 | case FW_BAD_LENGTH: | |
ec9c4989 JP |
77 | rt2x00_err(rt2x00dev, "Invalid firmware file length (len=%zu)\n", |
78 | fw->size); | |
0cbe0064 ID |
79 | goto exit; |
80 | case FW_BAD_VERSION: | |
ec9c4989 | 81 | rt2x00_err(rt2x00dev, "Current firmware does not support detected chipset\n"); |
0cbe0064 | 82 | goto exit; |
ee289b64 | 83 | } |
0cbe0064 | 84 | |
95ea3627 ID |
85 | rt2x00dev->fw = fw; |
86 | ||
87 | return 0; | |
88 | ||
89 | exit: | |
90 | release_firmware(fw); | |
91 | ||
0cbe0064 | 92 | return -ENOENT; |
95ea3627 ID |
93 | } |
94 | ||
95 | int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev) | |
96 | { | |
97 | int retval; | |
98 | ||
b9d305cc | 99 | if (!rt2x00_has_cap_flag(rt2x00dev, REQUIRE_FIRMWARE)) |
9404ef34 ID |
100 | return 0; |
101 | ||
95ea3627 ID |
102 | if (!rt2x00dev->fw) { |
103 | retval = rt2x00lib_request_firmware(rt2x00dev); | |
104 | if (retval) | |
105 | return retval; | |
106 | } | |
107 | ||
108 | /* | |
109 | * Send firmware to the device. | |
110 | */ | |
111 | retval = rt2x00dev->ops->lib->load_firmware(rt2x00dev, | |
112 | rt2x00dev->fw->data, | |
113 | rt2x00dev->fw->size); | |
4c9adaff ID |
114 | |
115 | /* | |
116 | * When the firmware is uploaded to the hardware the LED | |
117 | * association status might have been triggered, for correct | |
118 | * LED handling it should now be reset. | |
119 | */ | |
120 | rt2x00leds_led_assoc(rt2x00dev, false); | |
121 | ||
95ea3627 ID |
122 | return retval; |
123 | } | |
124 | ||
125 | void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev) | |
126 | { | |
127 | release_firmware(rt2x00dev->fw); | |
128 | rt2x00dev->fw = NULL; | |
129 | } |