blob: 685ba9d6f08255eb7e1747f97f0ce0155bbcb13a [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
Wey-Yi Guy02f5dac2009-09-17 10:43:54 -070045/* default: IWL_LED_BLINK(0) using blinking index table */
46static int led_mode;
47module_param(led_mode, int, S_IRUGO);
48MODULE_PARM_DESC(led_mode, "led mode: 0=blinking, 1=On(RF On)/Off(RF Off), "
49 "(default 0)\n");
50
Tomas Winkler0eee6122008-07-11 11:53:36 +080051#ifdef CONFIG_IWLWIFI_DEBUG
52static const char *led_type_str[] = {
53 __stringify(IWL_LED_TRG_TX),
54 __stringify(IWL_LED_TRG_RX),
55 __stringify(IWL_LED_TRG_ASSOC),
56 __stringify(IWL_LED_TRG_RADIO),
57 NULL
58};
59#endif /* CONFIG_IWLWIFI_DEBUG */
60
61
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070062static const struct {
Wey-Yi Guye5108d02009-07-17 09:30:20 -070063 u16 tpt; /* Mb/s */
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070064 u8 on_time;
Tomas Winkler0eee6122008-07-11 11:53:36 +080065 u8 off_time;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070066} blink_tbl[] =
67{
68 {300, 25, 25},
69 {200, 40, 40},
70 {100, 55, 55},
71 {70, 65, 65},
72 {50, 75, 75},
73 {20, 85, 85},
Wey-Yi Guy85fecff2009-09-11 10:38:07 -070074 {10, 95, 95},
75 {5, 110, 110},
76 {1, 130, 130},
Tomas Winklerec1a7462008-07-11 11:53:37 +080077 {0, 167, 167},
78/* SOLID_ON */
79 {-1, IWL_LED_SOLID, 0}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070080};
81
Tomas Winklerec1a7462008-07-11 11:53:37 +080082#define IWL_1MB_RATE (128 * 1024)
83#define IWL_LED_THRESHOLD (16)
84#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /* exclude SOLID_ON */
85#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
86
Wey-Yi Guyf2d0d0e2009-09-11 10:38:14 -070087/*
88 * Adjust led blink rate to compensate on a MAC Clock difference on every HW
89 * Led blink rate analysis showed an average deviation of 0% on 3945,
90 * 5% on 4965 HW and 20% on 5000 series and up.
91 * Need to compensate on the led on/off time per HW according to the deviation
92 * to achieve the desired led frequency
93 * The calculation is: (100-averageDeviation)/100 * blinkTime
94 * For code efficiency the calculation will be:
95 * compensation = (100 - averageDeviation) * 64 / 100
96 * NewBlinkTime = (compensation * BlinkTime) / 64
97 */
98static inline u8 iwl_blink_compensation(struct iwl_priv *priv,
99 u8 time, u16 compensation)
100{
101 if (!compensation) {
102 IWL_ERR(priv, "undefined blink compensation: "
103 "use pre-defined blinking time\n");
104 return time;
105 }
106
107 return (u8)((time * compensation) >> 6);
108}
109
Tomas Winklerec1a7462008-07-11 11:53:37 +0800110/* [0-256] -> [0..8] FIXME: we need [0..10] */
111static inline int iwl_brightness_to_idx(enum led_brightness brightness)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700112{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800113 return fls(0x000000FF & (u32)brightness);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700114}
115
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700116/* Send led command */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800117static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700118{
119 struct iwl_host_cmd cmd = {
120 .id = REPLY_LEDS_CMD,
Tomas Winklerec1a7462008-07-11 11:53:37 +0800121 .len = sizeof(struct iwl_led_cmd),
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700122 .data = led_cmd,
Johannes Bergc2acea82009-07-24 11:13:05 -0700123 .flags = CMD_ASYNC,
124 .callback = NULL,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700125 };
126 u32 reg;
127
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700128 reg = iwl_read32(priv, CSR_LED_REG);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700129 if (reg != (reg & CSR_LED_BSM_CTRL_MSK))
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700130 iwl_write32(priv, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700131
132 return iwl_send_cmd(priv, &cmd);
133}
134
Tomas Winklerec1a7462008-07-11 11:53:37 +0800135/* Set led pattern command */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700136static int iwl_led_pattern(struct iwl_priv *priv, int led_id,
Abhijeet Kolekar3eb20112008-07-11 11:53:42 +0800137 unsigned int idx)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700138{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800139 struct iwl_led_cmd led_cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700140 .id = led_id,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700141 .interval = IWL_DEF_LED_INTRVL
142 };
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700143
Tomas Winklerec1a7462008-07-11 11:53:37 +0800144 BUG_ON(idx > IWL_MAX_BLINK_TBL);
145
Wey-Yi Guyf2d0d0e2009-09-11 10:38:14 -0700146 IWL_DEBUG_LED(priv, "Led blink time compensation= %u\n",
147 priv->cfg->led_compensation);
148 led_cmd.on =
149 iwl_blink_compensation(priv, blink_tbl[idx].on_time,
150 priv->cfg->led_compensation);
151 led_cmd.off =
152 iwl_blink_compensation(priv, blink_tbl[idx].off_time,
153 priv->cfg->led_compensation);
Tomas Winklerec1a7462008-07-11 11:53:37 +0800154
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700155 return iwl_send_led_cmd(priv, &led_cmd);
156}
157
158/* Set led register off */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700159static int iwl_led_on_reg(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700160{
Tomas Winklere1623442009-01-27 14:27:56 -0800161 IWL_DEBUG_LED(priv, "led on %d\n", led_id);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700162 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_ON);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700163 return 0;
164}
165
166#if 0
Tomas Winklerec1a7462008-07-11 11:53:37 +0800167/* Set led on command */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700168static int iwl_led_on(struct iwl_priv *priv, int led_id)
Tomas Winklerec1a7462008-07-11 11:53:37 +0800169{
170 struct iwl_led_cmd led_cmd = {
171 .id = led_id,
172 .on = IWL_LED_SOLID,
173 .off = 0,
174 .interval = IWL_DEF_LED_INTRVL
175 };
176 return iwl_send_led_cmd(priv, &led_cmd);
177}
178
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700179/* Set led off command */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700180int iwl_led_off(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700181{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800182 struct iwl_led_cmd led_cmd = {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700183 .id = led_id,
184 .on = 0,
185 .off = 0,
186 .interval = IWL_DEF_LED_INTRVL
187 };
Tomas Winklere1623442009-01-27 14:27:56 -0800188 IWL_DEBUG_LED(priv, "led off %d\n", led_id);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700189 return iwl_send_led_cmd(priv, &led_cmd);
190}
191#endif
192
193
194/* Set led register off */
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700195static int iwl_led_off_reg(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700196{
Tomas Winklere1623442009-01-27 14:27:56 -0800197 IWL_DEBUG_LED(priv, "LED Reg off\n");
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700198 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_OFF);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700199 return 0;
200}
201
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700202/*
Esti Kummerc785d1d2008-07-18 13:53:07 +0800203 * Set led register in case of disassociation according to rfkill state
204 */
205static int iwl_led_associate(struct iwl_priv *priv, int led_id)
206{
Tomas Winklere1623442009-01-27 14:27:56 -0800207 IWL_DEBUG_LED(priv, "Associated\n");
Wey-Yi Guy02f5dac2009-09-17 10:43:54 -0700208 if (led_mode == IWL_LED_BLINK)
209 priv->allow_blinking = 1;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700210 return iwl_led_on_reg(priv, led_id);
Esti Kummerc785d1d2008-07-18 13:53:07 +0800211}
212static int iwl_led_disassociate(struct iwl_priv *priv, int led_id)
213{
214 priv->allow_blinking = 0;
Esti Kummerc785d1d2008-07-18 13:53:07 +0800215
216 return 0;
217}
218
219/*
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700220 * brightness call back function for Tx/Rx LED
221 */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800222static int iwl_led_associated(struct iwl_priv *priv, int led_id)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700223{
224 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
225 !test_bit(STATUS_READY, &priv->status))
226 return 0;
227
228
229 /* start counting Tx/Rx bytes */
230 if (!priv->last_blink_time && priv->allow_blinking)
231 priv->last_blink_time = jiffies;
232 return 0;
233}
234
235/*
236 * brightness call back for association and radio
237 */
Tomas Winkler0eee6122008-07-11 11:53:36 +0800238static void iwl_led_brightness_set(struct led_classdev *led_cdev,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700239 enum led_brightness brightness)
240{
Tomas Winkler0eee6122008-07-11 11:53:36 +0800241 struct iwl_led *led = container_of(led_cdev, struct iwl_led, led_dev);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700242 struct iwl_priv *priv = led->priv;
243
244 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
245 return;
246
Tomas Winkler0eee6122008-07-11 11:53:36 +0800247
Tomas Winklere1623442009-01-27 14:27:56 -0800248 IWL_DEBUG_LED(priv, "Led type = %s brightness = %d\n",
Tomas Winkler0eee6122008-07-11 11:53:36 +0800249 led_type_str[led->type], brightness);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700250 switch (brightness) {
251 case LED_FULL:
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700252 if (led->led_on)
253 led->led_on(priv, IWL_LED_LINK);
254 break;
255 case LED_OFF:
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700256 if (led->led_off)
257 led->led_off(priv, IWL_LED_LINK);
258 break;
259 default:
Tomas Winklerec1a7462008-07-11 11:53:37 +0800260 if (led->led_pattern) {
261 int idx = iwl_brightness_to_idx(brightness);
262 led->led_pattern(priv, IWL_LED_LINK, idx);
263 }
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700264 break;
265 }
266}
267
268
269
270/*
271 * Register led class with the system
272 */
Tomas Winkler0eee6122008-07-11 11:53:36 +0800273static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led,
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700274 enum led_type type, u8 set_led,
Sven Wegener5cbbb372008-08-01 21:57:16 +0200275 char *trigger)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700276{
277 struct device *device = wiphy_dev(priv->hw->wiphy);
278 int ret;
279
Sven Wegener5cbbb372008-08-01 21:57:16 +0200280 led->led_dev.name = led->name;
Tomas Winkler0eee6122008-07-11 11:53:36 +0800281 led->led_dev.brightness_set = iwl_led_brightness_set;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700282 led->led_dev.default_trigger = trigger;
283
Tomas Winklera571ea4e2008-03-28 16:21:11 -0700284 led->priv = priv;
285 led->type = type;
286
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700287 ret = led_classdev_register(device, &led->led_dev);
288 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800289 IWL_ERR(priv, "Error: failed to register led handler.\n");
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700290 return ret;
291 }
292
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700293 led->registered = 1;
294
295 if (set_led && led->led_on)
296 led->led_on(priv, IWL_LED_LINK);
Tomas Winklera571ea4e2008-03-28 16:21:11 -0700297
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700298 return 0;
299}
300
301
302/*
Wey-Yi Guye5108d02009-07-17 09:30:20 -0700303 * calculate blink rate according to last second Tx/Rx activities
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700304 */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800305static int iwl_get_blink_rate(struct iwl_priv *priv)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700306{
307 int i;
Wey-Yi Guye5108d02009-07-17 09:30:20 -0700308 /* count both tx and rx traffic to be able to
309 * handle traffic in either direction
310 */
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700311 u64 current_tpt = priv->tx_stats.data_bytes +
312 priv->rx_stats.data_bytes;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700313 s64 tpt = current_tpt - priv->led_tpt;
314
Tomas Winklera96a27f2008-10-23 23:48:56 -0700315 if (tpt < 0) /* wraparound */
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700316 tpt = -tpt;
317
Tomas Winklere1623442009-01-27 14:27:56 -0800318 IWL_DEBUG_LED(priv, "tpt %lld current_tpt %llu\n",
Andrew Morton03121102008-07-22 23:50:04 -0700319 (long long)tpt,
320 (unsigned long long)current_tpt);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700321 priv->led_tpt = current_tpt;
322
Tomas Winklerec1a7462008-07-11 11:53:37 +0800323 if (!priv->allow_blinking)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700324 i = IWL_MAX_BLINK_TBL;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800325 else
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700326 for (i = 0; i < IWL_MAX_BLINK_TBL; i++)
327 if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE))
328 break;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700329
Tomas Winklere1623442009-01-27 14:27:56 -0800330 IWL_DEBUG_LED(priv, "LED BLINK IDX=%d\n", i);
Tomas Winklerec1a7462008-07-11 11:53:37 +0800331 return i;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700332}
333
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700334/*
335 * this function called from handler. Since setting Led command can
336 * happen very frequent we postpone led command to be called from
337 * REPLY handler so we know ucode is up
338 */
339void iwl_leds_background(struct iwl_priv *priv)
340{
Tomas Winklerec1a7462008-07-11 11:53:37 +0800341 u8 blink_idx;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700342
343 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
344 priv->last_blink_time = 0;
345 return;
346 }
Esti Kummerc785d1d2008-07-18 13:53:07 +0800347 if (iwl_is_rfkill(priv)) {
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700348 priv->last_blink_time = 0;
349 return;
350 }
351
352 if (!priv->allow_blinking) {
353 priv->last_blink_time = 0;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800354 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
355 priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700356 iwl_led_pattern(priv, IWL_LED_LINK,
Tomas Winklerec1a7462008-07-11 11:53:37 +0800357 IWL_SOLID_BLINK_IDX);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700358 }
359 return;
360 }
361 if (!priv->last_blink_time ||
362 !time_after(jiffies, priv->last_blink_time +
363 msecs_to_jiffies(1000)))
364 return;
365
Tomas Winklerec1a7462008-07-11 11:53:37 +0800366 blink_idx = iwl_get_blink_rate(priv);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700367
368 /* call only if blink rate change */
Tomas Winklerec1a7462008-07-11 11:53:37 +0800369 if (blink_idx != priv->last_blink_rate)
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700370 iwl_led_pattern(priv, IWL_LED_LINK, blink_idx);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700371
Tomas Winkler0eee6122008-07-11 11:53:36 +0800372 priv->last_blink_time = jiffies;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800373 priv->last_blink_rate = blink_idx;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700374}
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700375
376/* Register all led handler */
377int iwl_leds_register(struct iwl_priv *priv)
378{
379 char *trigger;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700380 int ret;
381
382 priv->last_blink_rate = 0;
383 priv->led_tpt = 0;
384 priv->last_blink_time = 0;
385 priv->allow_blinking = 0;
386
387 trigger = ieee80211_get_radio_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200388 snprintf(priv->led[IWL_LED_TRG_RADIO].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100389 sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s::radio",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700390 wiphy_name(priv->hw->wiphy));
391
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700392 priv->led[IWL_LED_TRG_RADIO].led_on = iwl_led_on_reg;
393 priv->led[IWL_LED_TRG_RADIO].led_off = iwl_led_off_reg;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700394 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL;
395
Tomas Winkler0eee6122008-07-11 11:53:36 +0800396 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RADIO],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200397 IWL_LED_TRG_RADIO, 1, trigger);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700398 if (ret)
399 goto exit_fail;
400
401 trigger = ieee80211_get_assoc_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200402 snprintf(priv->led[IWL_LED_TRG_ASSOC].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100403 sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s::assoc",
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700404 wiphy_name(priv->hw->wiphy));
405
Tomas Winkler0eee6122008-07-11 11:53:36 +0800406 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_ASSOC],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200407 IWL_LED_TRG_ASSOC, 0, trigger);
Tomas Winkler0eee6122008-07-11 11:53:36 +0800408
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700409 /* for assoc always turn led on */
Esti Kummerc785d1d2008-07-18 13:53:07 +0800410 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl_led_associate;
411 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl_led_disassociate;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700412 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL;
413
414 if (ret)
415 goto exit_fail;
416
417 trigger = ieee80211_get_rx_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200418 snprintf(priv->led[IWL_LED_TRG_RX].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100419 sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s::RX",
Sven Wegener5cbbb372008-08-01 21:57:16 +0200420 wiphy_name(priv->hw->wiphy));
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700421
Tomas Winkler0eee6122008-07-11 11:53:36 +0800422 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200423 IWL_LED_TRG_RX, 0, trigger);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700424
Tomas Winklerec1a7462008-07-11 11:53:37 +0800425 priv->led[IWL_LED_TRG_RX].led_on = iwl_led_associated;
426 priv->led[IWL_LED_TRG_RX].led_off = iwl_led_associated;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700427 priv->led[IWL_LED_TRG_RX].led_pattern = iwl_led_pattern;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700428
429 if (ret)
430 goto exit_fail;
431
432 trigger = ieee80211_get_tx_led_name(priv->hw);
Sven Wegener5cbbb372008-08-01 21:57:16 +0200433 snprintf(priv->led[IWL_LED_TRG_TX].name,
Danny Kukawkae5d24ef2009-01-29 21:58:26 +0100434 sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s::TX",
Sven Wegener5cbbb372008-08-01 21:57:16 +0200435 wiphy_name(priv->hw->wiphy));
436
Tomas Winkler0eee6122008-07-11 11:53:36 +0800437 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX],
Sven Wegener5cbbb372008-08-01 21:57:16 +0200438 IWL_LED_TRG_TX, 0, trigger);
Tomas Winkler0eee6122008-07-11 11:53:36 +0800439
Tomas Winklerec1a7462008-07-11 11:53:37 +0800440 priv->led[IWL_LED_TRG_TX].led_on = iwl_led_associated;
441 priv->led[IWL_LED_TRG_TX].led_off = iwl_led_associated;
Wey-Yi Guy5e215162009-07-17 09:30:17 -0700442 priv->led[IWL_LED_TRG_TX].led_pattern = iwl_led_pattern;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700443
444 if (ret)
445 goto exit_fail;
446
447 return 0;
448
449exit_fail:
450 iwl_leds_unregister(priv);
451 return ret;
452}
453EXPORT_SYMBOL(iwl_leds_register);
454
455/* unregister led class */
Tomas Winkler0eee6122008-07-11 11:53:36 +0800456static void iwl_leds_unregister_led(struct iwl_led *led, u8 set_led)
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700457{
458 if (!led->registered)
459 return;
460
461 led_classdev_unregister(&led->led_dev);
462
463 if (set_led)
464 led->led_dev.brightness_set(&led->led_dev, LED_OFF);
465 led->registered = 0;
466}
467
468/* Unregister all led handlers */
469void iwl_leds_unregister(struct iwl_priv *priv)
470{
471 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_ASSOC], 0);
472 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_RX], 0);
473 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_TX], 0);
474 iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_RADIO], 1);
475}
476EXPORT_SYMBOL(iwl_leds_unregister);
477