blob: 41addd1c726168fd0e0859dc7a0d1f8095bc9c7a [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
27
28#include <linux/kernel.h>
29#include <linux/module.h>
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070030#include <linux/init.h>
31#include <linux/pci.h>
32#include <linux/dma-mapping.h>
33#include <linux/delay.h>
34#include <linux/skbuff.h>
35#include <linux/netdevice.h>
36#include <linux/wireless.h>
37#include <net/mac80211.h>
38#include <linux/etherdevice.h>
39#include <asm/unaligned.h>
40
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070041#include "iwl-dev.h"
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070042#include "iwl-core.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070043#include "iwl-io.h"
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070044
Tomas Winkler0eee6122008-07-11 11:53:36 +080045#ifdef CONFIG_IWLWIFI_DEBUG
46static const char *led_type_str[] = {
47 __stringify(IWL_LED_TRG_TX),
48 __stringify(IWL_LED_TRG_RX),
49 __stringify(IWL_LED_TRG_ASSOC),
50 __stringify(IWL_LED_TRG_RADIO),
51 NULL
52};
53#endif /* CONFIG_IWLWIFI_DEBUG */
54
55
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070056static const struct {
Wey-Yi Guye5108d02009-07-17 09:30:20 -070057 u16 tpt; /* Mb/s */
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070058 u8 on_time;
Tomas Winkler0eee6122008-07-11 11:53:36 +080059 u8 off_time;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070060} blink_tbl[] =
61{
62 {300, 25, 25},
63 {200, 40, 40},
64 {100, 55, 55},
65 {70, 65, 65},
66 {50, 75, 75},
67 {20, 85, 85},
Wey-Yi Guy85fecff2009-09-11 10:38:07 -070068 {10, 95, 95},
69 {5, 110, 110},
70 {1, 130, 130},
Tomas Winklerec1a7462008-07-11 11:53:37 +080071 {0, 167, 167},
72/* SOLID_ON */
73 {-1, IWL_LED_SOLID, 0}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070074};
75
Tomas Winklerec1a7462008-07-11 11:53:37 +080076#define IWL_1MB_RATE (128 * 1024)
77#define IWL_LED_THRESHOLD (16)
78#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /* exclude SOLID_ON */
79#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
80
81/* [0-256] -> [0..8] FIXME: we need [0..10] */
82static inline int iwl_brightness_to_idx(enum led_brightness brightness)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070083{
Tomas Winklerec1a7462008-07-11 11:53:37 +080084 return fls(0x000000FF & (u32)brightness);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070085}
86
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070087/* Send led command */
Tomas Winklerec1a7462008-07-11 11:53:37 +080088static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070089{
90 struct iwl_host_cmd cmd = {
91 .id = REPLY_LEDS_CMD,
Tomas Winklerec1a7462008-07-11 11:53:37 +080092 .len = sizeof(struct iwl_led_cmd),
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070093 .data = led_cmd,
Johannes Bergc2acea82009-07-24 11:13:05 -070094 .flags = CMD_ASYNC,
95 .callback = NULL,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070096 };
97 u32 reg;
98
Tomas Winkler3395f6e2008-03-25 16:33:37 -070099 reg = iwl_read32(priv, CSR_LED_REG);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700100 if (reg != (reg & CSR_LED_BSM_CTRL_MSK))
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700101 iwl_write32(priv, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700102
103 return iwl_send_cmd(priv, &cmd);
104}
105
Tomas Winklerec1a7462008-07-11 11:53:37 +0800106/* Set led pattern command */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700107static int iwl_led_pattern(struct iwl_priv *priv, int led_id,
Abhijeet Kolekar3eb20112008-07-11 11:53:42 +0800108 unsigned int idx)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700109{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800110 struct iwl_led_cmd led_cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700111 .id = led_id,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700112 .interval = IWL_DEF_LED_INTRVL
113 };
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700114
Tomas Winklerec1a7462008-07-11 11:53:37 +0800115 BUG_ON(idx > IWL_MAX_BLINK_TBL);
116
117 led_cmd.on = blink_tbl[idx].on_time;
118 led_cmd.off = blink_tbl[idx].off_time;
119
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700120 return iwl_send_led_cmd(priv, &led_cmd);
121}
122
123/* Set led register off */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700124static int iwl_led_on_reg(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700125{
Tomas Winklere1623442009-01-27 14:27:56 -0800126 IWL_DEBUG_LED(priv, "led on %d\n", led_id);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700127 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_ON);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700128 return 0;
129}
130
131#if 0
Tomas Winklerec1a7462008-07-11 11:53:37 +0800132/* Set led on command */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700133static int iwl_led_on(struct iwl_priv *priv, int led_id)
Tomas Winklerec1a7462008-07-11 11:53:37 +0800134{
135 struct iwl_led_cmd led_cmd = {
136 .id = led_id,
137 .on = IWL_LED_SOLID,
138 .off = 0,
139 .interval = IWL_DEF_LED_INTRVL
140 };
141 return iwl_send_led_cmd(priv, &led_cmd);
142}
143
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700144/* Set led off command */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700145int iwl_led_off(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700146{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800147 struct iwl_led_cmd led_cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700148 .id = led_id,
149 .on = 0,
150 .off = 0,
151 .interval = IWL_DEF_LED_INTRVL
152 };
Tomas Winklere1623442009-01-27 14:27:56 -0800153 IWL_DEBUG_LED(priv, "led off %d\n", led_id);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700154 return iwl_send_led_cmd(priv, &led_cmd);
155}
156#endif
157
158
159/* Set led register off */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700160static int iwl_led_off_reg(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700161{
Tomas Winklere1623442009-01-27 14:27:56 -0800162 IWL_DEBUG_LED(priv, "LED Reg off\n");
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700163 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_OFF);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700164 return 0;
165}
166
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700167/*
Esti Kummerc785d1d2008-07-18 13:53:07 +0800168 * Set led register in case of disassociation according to rfkill state
169 */
170static int iwl_led_associate(struct iwl_priv *priv, int led_id)
171{
Tomas Winklere1623442009-01-27 14:27:56 -0800172 IWL_DEBUG_LED(priv, "Associated\n");
Esti Kummerc785d1d2008-07-18 13:53:07 +0800173 priv->allow_blinking = 1;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700174 return iwl_led_on_reg(priv, led_id);
Esti Kummerc785d1d2008-07-18 13:53:07 +0800175}
176static int iwl_led_disassociate(struct iwl_priv *priv, int led_id)
177{
178 priv->allow_blinking = 0;
Esti Kummerc785d1d2008-07-18 13:53:07 +0800179
180 return 0;
181}
182
183/*
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700184 * brightness call back function for Tx/Rx LED
185 */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800186static int iwl_led_associated(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700187{
188 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
189 !test_bit(STATUS_READY, &priv->status))
190 return 0;
191
192
193 /* start counting Tx/Rx bytes */
194 if (!priv->last_blink_time && priv->allow_blinking)
195 priv->last_blink_time = jiffies;
196 return 0;
197}
198
199/*
200 * brightness call back for association and radio
201 */
Tomas Winkler0eee6122008-07-11 11:53:36 +0800202static void iwl_led_brightness_set(struct led_classdev *led_cdev,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700203 enum led_brightness brightness)
204{
Tomas Winkler0eee6122008-07-11 11:53:36 +0800205 struct iwl_led *led = container_of(led_cdev, struct iwl_led, led_dev);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700206 struct iwl_priv *priv = led->priv;
207
208 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
209 return;
210
Tomas Winkler0eee6122008-07-11 11:53:36 +0800211
Tomas Winklere1623442009-01-27 14:27:56 -0800212 IWL_DEBUG_LED(priv, "Led type = %s brightness = %d\n",
Tomas Winkler0eee6122008-07-11 11:53:36 +0800213 led_type_str[led->type], brightness);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700214 switch (brightness) {
215 case LED_FULL:
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700216 if (led->led_on)
217 led->led_on(priv, IWL_LED_LINK);
218 break;
219 case LED_OFF:
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700220 if (led->led_off)
221 led->led_off(priv, IWL_LED_LINK);
222 break;
223 default:
Tomas Winklerec1a7462008-07-11 11:53:37 +0800224 if (led->led_pattern) {
225 int idx = iwl_brightness_to_idx(brightness);
226 led->led_pattern(priv, IWL_LED_LINK, idx);
227 }
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700228 break;
229 }
230}
231
232
233
234/*
235 * Register led class with the system
236 */
Tomas Winkler0eee6122008-07-11 11:53:36 +0800237static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700238 enum led_type type, u8 set_led,
Sven Wegener5cbbb372008-08-01 21:57:16 +0200239 char *trigger)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700240{
241 struct device *device = wiphy_dev(priv->hw->wiphy);
242 int ret;
243
Sven Wegener5cbbb372008-08-01 21:57:16 +0200244 led->led_dev.name = led->name;
Tomas Winkler0eee6122008-07-11 11:53:36 +0800245 led->led_dev.brightness_set = iwl_led_brightness_set;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700246 led->led_dev.default_trigger = trigger;
247
Tomas Winklera571ea4e2008-03-28 16:21:11 -0700248 led->priv = priv;
249 led->type = type;
250
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700251 ret = led_classdev_register(device, &led->led_dev);
252 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800253 IWL_ERR(priv, "Error: failed to register led handler.\n");
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700254 return ret;
255 }
256
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700257 led->registered = 1;
258
259 if (set_led && led->led_on)
260 led->led_on(priv, IWL_LED_LINK);
Tomas Winklera571ea4e2008-03-28 16:21:11 -0700261
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700262 return 0;
263}
264
265
266/*
Wey-Yi Guye5108d02009-07-17 09:30:20 -0700267 * calculate blink rate according to last second Tx/Rx activities
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700268 */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800269static int iwl_get_blink_rate(struct iwl_priv *priv)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700270{
271 int i;
Wey-Yi Guye5108d02009-07-17 09:30:20 -0700272 /* count both tx and rx traffic to be able to
273 * handle traffic in either direction
274 */
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700275 u64 current_tpt = priv->tx_stats.data_bytes +
276 priv->rx_stats.data_bytes;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700277 s64 tpt = current_tpt - priv->led_tpt;
278
Tomas Winklera96a27f2008-10-23 23:48:56 -0700279 if (tpt < 0) /* wraparound */
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700280 tpt = -tpt;
281
Tomas Winklere1623442009-01-27 14:27:56 -0800282 IWL_DEBUG_LED(priv, "tpt %lld current_tpt %llu\n",
Andrew Morton03121102008-07-22 23:50:04 -0700283 (long long)tpt,
284 (unsigned long long)current_tpt);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700285 priv->led_tpt = current_tpt;
286
Tomas Winklerec1a7462008-07-11 11:53:37 +0800287 if (!priv->allow_blinking)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700288 i = IWL_MAX_BLINK_TBL;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800289 else
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700290 for (i = 0; i < IWL_MAX_BLINK_TBL; i++)
291 if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE))
292 break;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700293
Tomas Winklere1623442009-01-27 14:27:56 -0800294 IWL_DEBUG_LED(priv, "LED BLINK IDX=%d\n", i);
Tomas Winklerec1a7462008-07-11 11:53:37 +0800295 return i;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700296}
297
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700298/*
299 * this function called from handler. Since setting Led command can
300 * happen very frequent we postpone led command to be called from
301 * REPLY handler so we know ucode is up
302 */
303void iwl_leds_background(struct iwl_priv *priv)
304{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800305 u8 blink_idx;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700306
307 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
308 priv->last_blink_time = 0;
309 return;
310 }
Esti Kummerc785d1d2008-07-18 13:53:07 +0800311 if (iwl_is_rfkill(priv)) {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700312 priv->last_blink_time = 0;
313 return;
314 }
315
316 if (!priv->allow_blinking) {
317 priv->last_blink_time = 0;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800318 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
319 priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700320 iwl_led_pattern(priv, IWL_LED_LINK,
Tomas Winklerec1a7462008-07-11 11:53:37 +0800321 IWL_SOLID_BLINK_IDX);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700322 }
323 return;
324 }
325 if (!priv->last_blink_time ||
326 !time_after(jiffies, priv->last_blink_time +
327 msecs_to_jiffies(1000)))
328 return;
329
Tomas Winklerec1a7462008-07-11 11:53:37 +0800330 blink_idx = iwl_get_blink_rate(priv);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700331
332 /* call only if blink rate change */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800333 if (blink_idx != priv->last_blink_rate)
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700334 iwl_led_pattern(priv, IWL_LED_LINK, blink_idx);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700335
Tomas Winkler0eee6122008-07-11 11:53:36 +0800336 priv->last_blink_time = jiffies;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800337 priv->last_blink_rate = blink_idx;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700338}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700339
340/* Register all led handler */
341int iwl_leds_register(struct iwl_priv *priv)
342{
343 char *trigger;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700344 int ret;
345
346 priv->last_blink_rate = 0;
347 priv->led_tpt = 0;
348 priv->last_blink_time = 0;
349 priv->allow_blinking = 0;
350
351 trigger = ieee80211_get_radio_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200352 snprintf(priv->led[IWL_LED_TRG_RADIO].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100353 sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s::radio",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700354 wiphy_name(priv->hw->wiphy));
355
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700356 priv->led[IWL_LED_TRG_RADIO].led_on = iwl_led_on_reg;
357 priv->led[IWL_LED_TRG_RADIO].led_off = iwl_led_off_reg;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700358 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL;
359
Tomas Winkler0eee6122008-07-11 11:53:36 +0800360 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RADIO],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200361 IWL_LED_TRG_RADIO, 1, trigger);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700362 if (ret)
363 goto exit_fail;
364
365 trigger = ieee80211_get_assoc_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200366 snprintf(priv->led[IWL_LED_TRG_ASSOC].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100367 sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s::assoc",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700368 wiphy_name(priv->hw->wiphy));
369
Tomas Winkler0eee6122008-07-11 11:53:36 +0800370 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_ASSOC],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200371 IWL_LED_TRG_ASSOC, 0, trigger);
Tomas Winkler0eee6122008-07-11 11:53:36 +0800372
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700373 /* for assoc always turn led on */
Esti Kummerc785d1d2008-07-18 13:53:07 +0800374 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl_led_associate;
375 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl_led_disassociate;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700376 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL;
377
378 if (ret)
379 goto exit_fail;
380
381 trigger = ieee80211_get_rx_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200382 snprintf(priv->led[IWL_LED_TRG_RX].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100383 sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s::RX",
Sven Wegener5cbbb372008-08-01 21:57:16 +0200384 wiphy_name(priv->hw->wiphy));
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700385
Tomas Winkler0eee6122008-07-11 11:53:36 +0800386 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200387 IWL_LED_TRG_RX, 0, trigger);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700388
Tomas Winklerec1a7462008-07-11 11:53:37 +0800389 priv->led[IWL_LED_TRG_RX].led_on = iwl_led_associated;
390 priv->led[IWL_LED_TRG_RX].led_off = iwl_led_associated;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700391 priv->led[IWL_LED_TRG_RX].led_pattern = iwl_led_pattern;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700392
393 if (ret)
394 goto exit_fail;
395
396 trigger = ieee80211_get_tx_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200397 snprintf(priv->led[IWL_LED_TRG_TX].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100398 sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s::TX",
Sven Wegener5cbbb372008-08-01 21:57:16 +0200399 wiphy_name(priv->hw->wiphy));
400
Tomas Winkler0eee6122008-07-11 11:53:36 +0800401 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200402 IWL_LED_TRG_TX, 0, trigger);
Tomas Winkler0eee6122008-07-11 11:53:36 +0800403
Tomas Winklerec1a7462008-07-11 11:53:37 +0800404 priv->led[IWL_LED_TRG_TX].led_on = iwl_led_associated;
405 priv->led[IWL_LED_TRG_TX].led_off = iwl_led_associated;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700406 priv->led[IWL_LED_TRG_TX].led_pattern = iwl_led_pattern;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700407
408 if (ret)
409 goto exit_fail;
410
411 return 0;
412
413exit_fail:
414 iwl_leds_unregister(priv);
415 return ret;
416}
417EXPORT_SYMBOL(iwl_leds_register);
418
419/* unregister led class */
Tomas Winkler0eee6122008-07-11 11:53:36 +0800420static void iwl_leds_unregister_led(struct iwl_led *led, u8 set_led)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700421{
422 if (!led->registered)
423 return;
424
425 led_classdev_unregister(&led->led_dev);
426
427 if (set_led)
428 led->led_dev.brightness_set(&led->led_dev, LED_OFF);
429 led->registered = 0;
430}
431
432/* Unregister all led handlers */
433void iwl_leds_unregister(struct iwl_priv *priv)
434{
435 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_ASSOC], 0);
436 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_RX], 0);
437 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_TX], 0);
438 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_RADIO], 1);
439}
440EXPORT_SYMBOL(iwl_leds_unregister);
441