blob: 225e5f889346806203e2eab6e2a985e6dd74fe4e [file] [log] [blame]
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080022 * Intel Linux Wireless <ilw@linux.intel.com>
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070023 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
26
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -070027#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070028
29#include <linux/kernel.h>
30#include <linux/module.h>
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070031#include <linux/init.h>
32#include <linux/pci.h>
33#include <linux/dma-mapping.h>
34#include <linux/delay.h>
35#include <linux/skbuff.h>
36#include <linux/netdevice.h>
37#include <linux/wireless.h>
38#include <net/mac80211.h>
39#include <linux/etherdevice.h>
40#include <asm/unaligned.h>
41
Tomas Winkler600c0e12008-12-19 10:37:04 +080042#include "iwl-commands.h"
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070043#include "iwl-3945.h"
Samuel Ortiz518099a2009-01-19 15:30:27 -080044#include "iwl-core.h"
45#include "iwl-dev.h"
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070046
Abhijeet Kolekar749e0912009-05-21 13:44:21 -070047#ifdef CONFIG_IWLWIFI_DEBUG
48static const char *led_type_str[] = {
49 __stringify(IWL_LED_TRG_TX),
50 __stringify(IWL_LED_TRG_RX),
51 __stringify(IWL_LED_TRG_ASSOC),
52 __stringify(IWL_LED_TRG_RADIO),
53 NULL
54};
55#endif /* CONFIG_IWLWIFI_DEBUG */
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070056
57static const struct {
58 u16 brightness;
59 u8 on_time;
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +080060 u8 off_time;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070061} blink_tbl[] =
62{
63 {300, 25, 25},
64 {200, 40, 40},
65 {100, 55, 55},
66 {70, 65, 65},
67 {50, 75, 75},
68 {20, 85, 85},
69 {15, 95, 95 },
70 {10, 110, 110},
71 {5, 130, 130},
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +080072 {0, 167, 167},
Abhijeet Kolekar749e0912009-05-21 13:44:21 -070073 /* SOLID_ON */
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +080074 {-1, IWL_LED_SOLID, 0}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070075};
76
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +080077#define IWL_1MB_RATE (128 * 1024)
78#define IWL_LED_THRESHOLD (16)
79#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /*Exclude Solid on*/
80#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
81
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +080082static int iwl3945_led_cmd_callback(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +080083 struct iwl_cmd *cmd,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070084 struct sk_buff *skb)
85{
86 return 1;
87}
88
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +080089static inline int iwl3945_brightness_to_idx(enum led_brightness brightness)
90{
91 return fls(0x000000FF & (u32)brightness);
92}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070093
94/* Send led command */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +080095static int iwl_send_led_cmd(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +080096 struct iwl_led_cmd *led_cmd)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070097{
Winkler, Tomasc2d79b482008-12-19 10:37:34 +080098 struct iwl_host_cmd cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070099 .id = REPLY_LEDS_CMD,
Tomas Winkler4c897252008-12-19 10:37:05 +0800100 .len = sizeof(struct iwl_led_cmd),
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700101 .data = led_cmd,
102 .meta.flags = CMD_ASYNC,
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800103 .meta.u.callback = iwl3945_led_cmd_callback,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700104 };
105
Samuel Ortiz518099a2009-01-19 15:30:27 -0800106 return iwl_send_cmd(priv, &cmd);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700107}
108
109
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800110
111/* Set led on command */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800112static int iwl3945_led_pattern(struct iwl_priv *priv, int led_id,
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800113 unsigned int idx)
114{
Tomas Winkler4c897252008-12-19 10:37:05 +0800115 struct iwl_led_cmd led_cmd = {
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800116 .id = led_id,
117 .interval = IWL_DEF_LED_INTRVL
118 };
119
120 BUG_ON(idx > IWL_MAX_BLINK_TBL);
121
122 led_cmd.on = blink_tbl[idx].on_time;
123 led_cmd.off = blink_tbl[idx].off_time;
124
125 return iwl_send_led_cmd(priv, &led_cmd);
126}
127
128
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700129/* Set led on command */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800130static int iwl3945_led_on(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700131{
Tomas Winkler4c897252008-12-19 10:37:05 +0800132 struct iwl_led_cmd led_cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700133 .id = led_id,
134 .on = IWL_LED_SOLID,
135 .off = 0,
136 .interval = IWL_DEF_LED_INTRVL
137 };
138 return iwl_send_led_cmd(priv, &led_cmd);
139}
140
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700141/* Set led off command */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800142static int iwl3945_led_off(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700143{
Tomas Winkler4c897252008-12-19 10:37:05 +0800144 struct iwl_led_cmd led_cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700145 .id = led_id,
146 .on = 0,
147 .off = 0,
148 .interval = IWL_DEF_LED_INTRVL
149 };
Tomas Winklere1623442009-01-27 14:27:56 -0800150 IWL_DEBUG_LED(priv, "led off %d\n", led_id);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700151 return iwl_send_led_cmd(priv, &led_cmd);
152}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700153
154/*
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700155 * Set led on in case of association
156 * */
157static int iwl3945_led_associate(struct iwl_priv *priv, int led_id)
158{
159 IWL_DEBUG_LED(priv, "Associated\n");
160
161 priv->allow_blinking = 1;
162 return iwl3945_led_on(priv, led_id);
163}
164/* Set Led off in case of disassociation */
165static int iwl3945_led_disassociate(struct iwl_priv *priv, int led_id)
166{
167 IWL_DEBUG_LED(priv, "Disassociated\n");
168
169 priv->allow_blinking = 0;
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700170
171 return 0;
172}
173
174/*
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700175 * brightness call back function for Tx/Rx LED
176 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800177static int iwl3945_led_associated(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700178{
179 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
180 !test_bit(STATUS_READY, &priv->status))
181 return 0;
182
183
184 /* start counting Tx/Rx bytes */
185 if (!priv->last_blink_time && priv->allow_blinking)
186 priv->last_blink_time = jiffies;
187 return 0;
188}
189
190/*
191 * brightness call back for association and radio
192 */
193static void iwl3945_led_brightness_set(struct led_classdev *led_cdev,
194 enum led_brightness brightness)
195{
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700196 struct iwl_led *led = container_of(led_cdev,
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700197 struct iwl_led, led_dev);
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800198 struct iwl_priv *priv = led->priv;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700199
200 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
201 return;
202
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700203 IWL_DEBUG_LED(priv, "Led type = %s brightness = %d\n",
204 led_type_str[led->type], brightness);
205
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700206 switch (brightness) {
207 case LED_FULL:
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700208 if (led->led_on)
209 led->led_on(priv, IWL_LED_LINK);
210 break;
211 case LED_OFF:
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700212 if (led->led_off)
213 led->led_off(priv, IWL_LED_LINK);
214 break;
215 default:
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800216 if (led->led_pattern) {
217 int idx = iwl3945_brightness_to_idx(brightness);
218 led->led_pattern(priv, IWL_LED_LINK, idx);
219 }
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700220 break;
221 }
222}
223
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700224/*
225 * Register led class with the system
226 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800227static int iwl3945_led_register_led(struct iwl_priv *priv,
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700228 struct iwl_led *led,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700229 enum led_type type, u8 set_led,
Sven Wegener5cbbb372008-08-01 21:57:16 +0200230 char *trigger)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700231{
232 struct device *device = wiphy_dev(priv->hw->wiphy);
233 int ret;
234
Sven Wegener5cbbb372008-08-01 21:57:16 +0200235 led->led_dev.name = led->name;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700236 led->led_dev.brightness_set = iwl3945_led_brightness_set;
237 led->led_dev.default_trigger = trigger;
238
Marcin Slusarzb6b16192008-06-08 13:13:06 +0200239 led->priv = priv;
240 led->type = type;
241
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700242 ret = led_classdev_register(device, &led->led_dev);
243 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800244 IWL_ERR(priv, "Error: failed to register led handler.\n");
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700245 return ret;
246 }
247
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700248 led->registered = 1;
249
250 if (set_led && led->led_on)
251 led->led_on(priv, IWL_LED_LINK);
252 return 0;
253}
254
255
256/*
257 * calculate blink rate according to last 2 sec Tx/Rx activities
258 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800259static inline u8 get_blink_rate(struct iwl_priv *priv)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700260{
261 int index;
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700262 s64 tpt = priv->rxtxpackets;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700263
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800264 if (tpt < 0)
265 tpt = -tpt;
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700266
267 IWL_DEBUG_LED(priv, "tpt %lld \n", (long long)tpt);
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800268
269 if (!priv->allow_blinking)
270 index = IWL_MAX_BLINK_TBL;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700271 else
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800272 for (index = 0; index < IWL_MAX_BLINK_TBL; index++)
273 if (tpt > (blink_tbl[index].brightness * IWL_1MB_RATE))
274 break;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700275
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700276 IWL_DEBUG_LED(priv, "LED BLINK IDX=%d\n", index);
277 return index;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700278}
279
280/*
281 * this function called from handler. Since setting Led command can
282 * happen very frequent we postpone led command to be called from
283 * REPLY handler so we know ucode is up
284 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800285void iwl3945_led_background(struct iwl_priv *priv)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700286{
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800287 u8 blink_idx;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700288
289 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
290 priv->last_blink_time = 0;
291 return;
292 }
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700293 if (iwl_is_rfkill(priv)) {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700294 priv->last_blink_time = 0;
295 return;
296 }
297
298 if (!priv->allow_blinking) {
299 priv->last_blink_time = 0;
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800300 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
301 priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
302 iwl3945_led_pattern(priv, IWL_LED_LINK,
303 IWL_SOLID_BLINK_IDX);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700304 }
305 return;
306 }
307 if (!priv->last_blink_time ||
308 !time_after(jiffies, priv->last_blink_time +
309 msecs_to_jiffies(1000)))
310 return;
311
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800312 blink_idx = get_blink_rate(priv);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700313
314 /* call only if blink rate change */
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800315 if (blink_idx != priv->last_blink_rate)
316 iwl3945_led_pattern(priv, IWL_LED_LINK, blink_idx);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700317
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800318 priv->last_blink_time = jiffies;
319 priv->last_blink_rate = blink_idx;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700320 priv->rxtxpackets = 0;
321}
322
323
324/* Register all led handler */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325int iwl3945_led_register(struct iwl_priv *priv)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700326{
327 char *trigger;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700328 int ret;
329
330 priv->last_blink_rate = 0;
331 priv->rxtxpackets = 0;
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800332 priv->led_tpt = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700333 priv->last_blink_time = 0;
334 priv->allow_blinking = 0;
335
336 trigger = ieee80211_get_radio_led_name(priv->hw);
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700337 snprintf(priv->led[IWL_LED_TRG_RADIO].name,
338 sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s::radio",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700339 wiphy_name(priv->hw->wiphy));
340
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700341 priv->led[IWL_LED_TRG_RADIO].led_on = iwl3945_led_on;
342 priv->led[IWL_LED_TRG_RADIO].led_off = iwl3945_led_off;
343 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700344
345 ret = iwl3945_led_register_led(priv,
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700346 &priv->led[IWL_LED_TRG_RADIO],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200347 IWL_LED_TRG_RADIO, 1, trigger);
348
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700349 if (ret)
350 goto exit_fail;
351
352 trigger = ieee80211_get_assoc_led_name(priv->hw);
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700353 snprintf(priv->led[IWL_LED_TRG_ASSOC].name,
354 sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s::assoc",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700355 wiphy_name(priv->hw->wiphy));
356
357 ret = iwl3945_led_register_led(priv,
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700358 &priv->led[IWL_LED_TRG_ASSOC],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200359 IWL_LED_TRG_ASSOC, 0, trigger);
360
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700361 /* for assoc always turn led on */
Abhijeet Kolekar749e0912009-05-21 13:44:21 -0700362 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl3945_led_associate;
363 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl3945_led_disassociate;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700364 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700365
366 if (ret)
367 goto exit_fail;
368
369 trigger = ieee80211_get_rx_led_name(priv->hw);
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700370 snprintf(priv->led[IWL_LED_TRG_RX].name,
371 sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s::RX",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700372 wiphy_name(priv->hw->wiphy));
373
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700374 ret = iwl3945_led_register_led(priv,
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700375 &priv->led[IWL_LED_TRG_RX],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200376 IWL_LED_TRG_RX, 0, trigger);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700377
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700378 priv->led[IWL_LED_TRG_RX].led_on = iwl3945_led_associated;
379 priv->led[IWL_LED_TRG_RX].led_off = iwl3945_led_associated;
380 priv->led[IWL_LED_TRG_RX].led_pattern = iwl3945_led_pattern;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700381
382 if (ret)
383 goto exit_fail;
384
385 trigger = ieee80211_get_tx_led_name(priv->hw);
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700386 snprintf(priv->led[IWL_LED_TRG_TX].name,
387 sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s::TX",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700388 wiphy_name(priv->hw->wiphy));
Abhijeet Kolekar9a9ad0c2008-07-11 11:53:41 +0800389
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700390 ret = iwl3945_led_register_led(priv,
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700391 &priv->led[IWL_LED_TRG_TX],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200392 IWL_LED_TRG_TX, 0, trigger);
393
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700394 priv->led[IWL_LED_TRG_TX].led_on = iwl3945_led_associated;
395 priv->led[IWL_LED_TRG_TX].led_off = iwl3945_led_associated;
396 priv->led[IWL_LED_TRG_TX].led_pattern = iwl3945_led_pattern;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700397
398 if (ret)
399 goto exit_fail;
400
401 return 0;
402
403exit_fail:
404 iwl3945_led_unregister(priv);
405 return ret;
406}
407
408
409/* unregister led class */
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700410static void iwl3945_led_unregister_led(struct iwl_led *led, u8 set_led)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700411{
412 if (!led->registered)
413 return;
414
415 led_classdev_unregister(&led->led_dev);
416
417 if (set_led)
418 led->led_dev.brightness_set(&led->led_dev, LED_OFF);
419 led->registered = 0;
420}
421
422/* Unregister all led handlers */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800423void iwl3945_led_unregister(struct iwl_priv *priv)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700424{
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700425 iwl3945_led_unregister_led(&priv->led[IWL_LED_TRG_ASSOC], 0);
426 iwl3945_led_unregister_led(&priv->led[IWL_LED_TRG_RX], 0);
427 iwl3945_led_unregister_led(&priv->led[IWL_LED_TRG_TX], 0);
428 iwl3945_led_unregister_led(&priv->led[IWL_LED_TRG_RADIO], 1);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700429}
430
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700431#endif