aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-led.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-led.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-led.c324
1 files changed, 54 insertions, 270 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.c b/drivers/net/wireless/iwlwifi/iwl-led.c
index f420c99e7240..46c7a95b88f0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.c
+++ b/drivers/net/wireless/iwlwifi/iwl-led.c
@@ -42,15 +42,11 @@
42#include "iwl-core.h" 42#include "iwl-core.h"
43#include "iwl-io.h" 43#include "iwl-io.h"
44 44
45#ifdef CONFIG_IWLWIFI_DEBUG 45/* default: IWL_LED_BLINK(0) using blinking index table */
46static const char *led_type_str[] = { 46static int led_mode;
47 __stringify(IWL_LED_TRG_TX), 47module_param(led_mode, int, S_IRUGO);
48 __stringify(IWL_LED_TRG_RX), 48MODULE_PARM_DESC(led_mode, "led mode: 0=blinking, 1=On(RF On)/Off(RF Off), "
49 __stringify(IWL_LED_TRG_ASSOC), 49 "(default 0)\n");
50 __stringify(IWL_LED_TRG_RADIO),
51 NULL
52};
53#endif /* CONFIG_IWLWIFI_DEBUG */
54 50
55 51
56static const struct { 52static const struct {
@@ -65,11 +61,11 @@ static const struct {
65 {70, 65, 65}, 61 {70, 65, 65},
66 {50, 75, 75}, 62 {50, 75, 75},
67 {20, 85, 85}, 63 {20, 85, 85},
68 {15, 95, 95 }, 64 {10, 95, 95},
69 {10, 110, 110}, 65 {5, 110, 110},
70 {5, 130, 130}, 66 {1, 130, 130},
71 {0, 167, 167}, 67 {0, 167, 167},
72/* SOLID_ON */ 68 /* SOLID_ON */
73 {-1, IWL_LED_SOLID, 0} 69 {-1, IWL_LED_SOLID, 0}
74}; 70};
75 71
@@ -78,191 +74,74 @@ static const struct {
78#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /* exclude SOLID_ON */ 74#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /* exclude SOLID_ON */
79#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1) 75#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
80 76
81/* [0-256] -> [0..8] FIXME: we need [0..10] */ 77/*
82static inline int iwl_brightness_to_idx(enum led_brightness brightness) 78 * Adjust led blink rate to compensate on a MAC Clock difference on every HW
83{ 79 * Led blink rate analysis showed an average deviation of 0% on 3945,
84 return fls(0x000000FF & (u32)brightness); 80 * 5% on 4965 HW and 20% on 5000 series and up.
85} 81 * Need to compensate on the led on/off time per HW according to the deviation
86 82 * to achieve the desired led frequency
87/* Send led command */ 83 * The calculation is: (100-averageDeviation)/100 * blinkTime
88static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd) 84 * For code efficiency the calculation will be:
85 * compensation = (100 - averageDeviation) * 64 / 100
86 * NewBlinkTime = (compensation * BlinkTime) / 64
87 */
88static inline u8 iwl_blink_compensation(struct iwl_priv *priv,
89 u8 time, u16 compensation)
89{ 90{
90 struct iwl_host_cmd cmd = { 91 if (!compensation) {
91 .id = REPLY_LEDS_CMD, 92 IWL_ERR(priv, "undefined blink compensation: "
92 .len = sizeof(struct iwl_led_cmd), 93 "use pre-defined blinking time\n");
93 .data = led_cmd, 94 return time;
94 .flags = CMD_ASYNC, 95 }
95 .callback = NULL,
96 };
97 u32 reg;
98
99 reg = iwl_read32(priv, CSR_LED_REG);
100 if (reg != (reg & CSR_LED_BSM_CTRL_MSK))
101 iwl_write32(priv, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK);
102 96
103 return iwl_send_cmd(priv, &cmd); 97 return (u8)((time * compensation) >> 6);
104} 98}
105 99
106/* Set led pattern command */ 100/* Set led pattern command */
107static int iwl_led_pattern(struct iwl_priv *priv, int led_id, 101static int iwl_led_pattern(struct iwl_priv *priv, unsigned int idx)
108 unsigned int idx)
109{ 102{
110 struct iwl_led_cmd led_cmd = { 103 struct iwl_led_cmd led_cmd = {
111 .id = led_id, 104 .id = IWL_LED_LINK,
112 .interval = IWL_DEF_LED_INTRVL 105 .interval = IWL_DEF_LED_INTRVL
113 }; 106 };
114 107
115 BUG_ON(idx > IWL_MAX_BLINK_TBL); 108 BUG_ON(idx > IWL_MAX_BLINK_TBL);
116 109
117 led_cmd.on = blink_tbl[idx].on_time; 110 IWL_DEBUG_LED(priv, "Led blink time compensation= %u\n",
118 led_cmd.off = blink_tbl[idx].off_time; 111 priv->cfg->led_compensation);
119 112 led_cmd.on =
120 return iwl_send_led_cmd(priv, &led_cmd); 113 iwl_blink_compensation(priv, blink_tbl[idx].on_time,
121} 114 priv->cfg->led_compensation);
122 115 led_cmd.off =
123/* Set led register off */ 116 iwl_blink_compensation(priv, blink_tbl[idx].off_time,
124static int iwl_led_on_reg(struct iwl_priv *priv, int led_id) 117 priv->cfg->led_compensation);
125{
126 IWL_DEBUG_LED(priv, "led on %d\n", led_id);
127 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_ON);
128 return 0;
129}
130 118
131#if 0 119 return priv->cfg->ops->led->cmd(priv, &led_cmd);
132/* Set led on command */
133static int iwl_led_on(struct iwl_priv *priv, int led_id)
134{
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} 120}
143 121
144/* Set led off command */ 122int iwl_led_start(struct iwl_priv *priv)
145int iwl_led_off(struct iwl_priv *priv, int led_id)
146{ 123{
147 struct iwl_led_cmd led_cmd = { 124 return priv->cfg->ops->led->on(priv);
148 .id = led_id,
149 .on = 0,
150 .off = 0,
151 .interval = IWL_DEF_LED_INTRVL
152 };
153 IWL_DEBUG_LED(priv, "led off %d\n", led_id);
154 return iwl_send_led_cmd(priv, &led_cmd);
155} 125}
156#endif 126EXPORT_SYMBOL(iwl_led_start);
157
158 127
159/* Set led register off */ 128int iwl_led_associate(struct iwl_priv *priv)
160static int iwl_led_off_reg(struct iwl_priv *priv, int led_id)
161{
162 IWL_DEBUG_LED(priv, "LED Reg off\n");
163 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_OFF);
164 return 0;
165}
166
167/*
168 * 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{ 129{
172 IWL_DEBUG_LED(priv, "Associated\n"); 130 IWL_DEBUG_LED(priv, "Associated\n");
173 priv->allow_blinking = 1; 131 if (led_mode == IWL_LED_BLINK)
174 return iwl_led_on_reg(priv, led_id); 132 priv->allow_blinking = 1;
175} 133 priv->last_blink_time = jiffies;
176static int iwl_led_disassociate(struct iwl_priv *priv, int led_id)
177{
178 priv->allow_blinking = 0;
179
180 return 0;
181}
182
183/*
184 * brightness call back function for Tx/Rx LED
185 */
186static int iwl_led_associated(struct iwl_priv *priv, int led_id)
187{
188 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
189 !test_bit(STATUS_READY, &priv->status))
190 return 0;
191
192 134
193 /* start counting Tx/Rx bytes */
194 if (!priv->last_blink_time && priv->allow_blinking)
195 priv->last_blink_time = jiffies;
196 return 0; 135 return 0;
197} 136}
198 137
199/* 138int iwl_led_disassociate(struct iwl_priv *priv)
200 * brightness call back for association and radio
201 */
202static void iwl_led_brightness_set(struct led_classdev *led_cdev,
203 enum led_brightness brightness)
204{ 139{
205 struct iwl_led *led = container_of(led_cdev, struct iwl_led, led_dev); 140 priv->allow_blinking = 0;
206 struct iwl_priv *priv = led->priv;
207
208 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
209 return;
210
211
212 IWL_DEBUG_LED(priv, "Led type = %s brightness = %d\n",
213 led_type_str[led->type], brightness);
214 switch (brightness) {
215 case LED_FULL:
216 if (led->led_on)
217 led->led_on(priv, IWL_LED_LINK);
218 break;
219 case LED_OFF:
220 if (led->led_off)
221 led->led_off(priv, IWL_LED_LINK);
222 break;
223 default:
224 if (led->led_pattern) {
225 int idx = iwl_brightness_to_idx(brightness);
226 led->led_pattern(priv, IWL_LED_LINK, idx);
227 }
228 break;
229 }
230}
231
232
233
234/*
235 * Register led class with the system
236 */
237static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led,
238 enum led_type type, u8 set_led,
239 char *trigger)
240{
241 struct device *device = wiphy_dev(priv->hw->wiphy);
242 int ret;
243
244 led->led_dev.name = led->name;
245 led->led_dev.brightness_set = iwl_led_brightness_set;
246 led->led_dev.default_trigger = trigger;
247
248 led->priv = priv;
249 led->type = type;
250
251 ret = led_classdev_register(device, &led->led_dev);
252 if (ret) {
253 IWL_ERR(priv, "Error: failed to register led handler.\n");
254 return ret;
255 }
256
257 led->registered = 1;
258
259 if (set_led && led->led_on)
260 led->led_on(priv, IWL_LED_LINK);
261 141
262 return 0; 142 return 0;
263} 143}
264 144
265
266/* 145/*
267 * calculate blink rate according to last second Tx/Rx activities 146 * calculate blink rate according to last second Tx/Rx activities
268 */ 147 */
@@ -288,7 +167,7 @@ static int iwl_get_blink_rate(struct iwl_priv *priv)
288 i = IWL_MAX_BLINK_TBL; 167 i = IWL_MAX_BLINK_TBL;
289 else 168 else
290 for (i = 0; i < IWL_MAX_BLINK_TBL; i++) 169 for (i = 0; i < IWL_MAX_BLINK_TBL; i++)
291 if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE)) 170 if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE))
292 break; 171 break;
293 172
294 IWL_DEBUG_LED(priv, "LED BLINK IDX=%d\n", i); 173 IWL_DEBUG_LED(priv, "LED BLINK IDX=%d\n", i);
@@ -317,8 +196,7 @@ void iwl_leds_background(struct iwl_priv *priv)
317 priv->last_blink_time = 0; 196 priv->last_blink_time = 0;
318 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) { 197 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
319 priv->last_blink_rate = IWL_SOLID_BLINK_IDX; 198 priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
320 iwl_led_pattern(priv, IWL_LED_LINK, 199 iwl_led_pattern(priv, IWL_SOLID_BLINK_IDX);
321 IWL_SOLID_BLINK_IDX);
322 } 200 }
323 return; 201 return;
324 } 202 }
@@ -331,111 +209,17 @@ void iwl_leds_background(struct iwl_priv *priv)
331 209
332 /* call only if blink rate change */ 210 /* call only if blink rate change */
333 if (blink_idx != priv->last_blink_rate) 211 if (blink_idx != priv->last_blink_rate)
334 iwl_led_pattern(priv, IWL_LED_LINK, blink_idx); 212 iwl_led_pattern(priv, blink_idx);
335 213
336 priv->last_blink_time = jiffies; 214 priv->last_blink_time = jiffies;
337 priv->last_blink_rate = blink_idx; 215 priv->last_blink_rate = blink_idx;
338} 216}
217EXPORT_SYMBOL(iwl_leds_background);
339 218
340/* Register all led handler */ 219void iwl_leds_init(struct iwl_priv *priv)
341int iwl_leds_register(struct iwl_priv *priv)
342{ 220{
343 char *trigger;
344 int ret;
345
346 priv->last_blink_rate = 0; 221 priv->last_blink_rate = 0;
347 priv->led_tpt = 0;
348 priv->last_blink_time = 0; 222 priv->last_blink_time = 0;
349 priv->allow_blinking = 0; 223 priv->allow_blinking = 0;
350
351 trigger = ieee80211_get_radio_led_name(priv->hw);
352 snprintf(priv->led[IWL_LED_TRG_RADIO].name,
353 sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s::radio",
354 wiphy_name(priv->hw->wiphy));
355
356 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;
358 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL;
359
360 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RADIO],
361 IWL_LED_TRG_RADIO, 1, trigger);
362 if (ret)
363 goto exit_fail;
364
365 trigger = ieee80211_get_assoc_led_name(priv->hw);
366 snprintf(priv->led[IWL_LED_TRG_ASSOC].name,
367 sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s::assoc",
368 wiphy_name(priv->hw->wiphy));
369
370 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_ASSOC],
371 IWL_LED_TRG_ASSOC, 0, trigger);
372
373 /* for assoc always turn led on */
374 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl_led_associate;
375 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl_led_disassociate;
376 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);
382 snprintf(priv->led[IWL_LED_TRG_RX].name,
383 sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s::RX",
384 wiphy_name(priv->hw->wiphy));
385
386 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX],
387 IWL_LED_TRG_RX, 0, trigger);
388
389 priv->led[IWL_LED_TRG_RX].led_on = iwl_led_associated;
390 priv->led[IWL_LED_TRG_RX].led_off = iwl_led_associated;
391 priv->led[IWL_LED_TRG_RX].led_pattern = iwl_led_pattern;
392
393 if (ret)
394 goto exit_fail;
395
396 trigger = ieee80211_get_tx_led_name(priv->hw);
397 snprintf(priv->led[IWL_LED_TRG_TX].name,
398 sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s::TX",
399 wiphy_name(priv->hw->wiphy));
400
401 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX],
402 IWL_LED_TRG_TX, 0, trigger);
403
404 priv->led[IWL_LED_TRG_TX].led_on = iwl_led_associated;
405 priv->led[IWL_LED_TRG_TX].led_off = iwl_led_associated;
406 priv->led[IWL_LED_TRG_TX].led_pattern = iwl_led_pattern;
407
408 if (ret)
409 goto exit_fail;
410
411 return 0;
412
413exit_fail:
414 iwl_leds_unregister(priv);
415 return ret;
416} 224}
417EXPORT_SYMBOL(iwl_leds_register); 225EXPORT_SYMBOL(iwl_leds_init);
418
419/* unregister led class */
420static void iwl_leds_unregister_led(struct iwl_led *led, u8 set_led)
421{
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