Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
| 4 | * |
| 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, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 23 | * 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 Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 30 | #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 Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 41 | #include "iwl-dev.h" |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 42 | #include "iwl-core.h" |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 43 | #include "iwl-io.h" |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 44 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 45 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 46 | static 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 Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 56 | static const struct { |
| 57 | u16 tpt; |
| 58 | u8 on_time; |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 59 | u8 off_time; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 60 | } 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}, |
| 68 | {15, 95, 95 }, |
| 69 | {10, 110, 110}, |
| 70 | {5, 130, 130}, |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 71 | {0, 167, 167}, |
| 72 | /* SOLID_ON */ |
| 73 | {-1, IWL_LED_SOLID, 0} |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 76 | #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] */ |
| 82 | static inline int iwl_brightness_to_idx(enum led_brightness brightness) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 83 | { |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 84 | return fls(0x000000FF & (u32)brightness); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 87 | /* Send led command */ |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 88 | static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 89 | { |
| 90 | struct iwl_host_cmd cmd = { |
| 91 | .id = REPLY_LEDS_CMD, |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 92 | .len = sizeof(struct iwl_led_cmd), |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 93 | .data = led_cmd, |
| 94 | .meta.flags = CMD_ASYNC, |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 95 | .meta.u.callback = NULL, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 96 | }; |
| 97 | u32 reg; |
| 98 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 99 | reg = iwl_read32(priv, CSR_LED_REG); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 100 | if (reg != (reg & CSR_LED_BSM_CTRL_MSK)) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 101 | iwl_write32(priv, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 102 | |
| 103 | return iwl_send_cmd(priv, &cmd); |
| 104 | } |
| 105 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 106 | /* Set led pattern command */ |
Abhijeet Kolekar | 3eb2011 | 2008-07-11 11:53:42 +0800 | [diff] [blame] | 107 | static int iwl4965_led_pattern(struct iwl_priv *priv, int led_id, |
| 108 | unsigned int idx) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 109 | { |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 110 | struct iwl_led_cmd led_cmd = { |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 111 | .id = led_id, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 112 | .interval = IWL_DEF_LED_INTRVL |
| 113 | }; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 114 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 115 | 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 Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 120 | return iwl_send_led_cmd(priv, &led_cmd); |
| 121 | } |
| 122 | |
| 123 | /* Set led register off */ |
| 124 | static int iwl4965_led_on_reg(struct iwl_priv *priv, int led_id) |
| 125 | { |
| 126 | IWL_DEBUG_LED("led on %d\n", led_id); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 127 | iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_ON); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | #if 0 |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 132 | /* Set led on command */ |
| 133 | static int iwl4965_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 | } |
| 143 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 144 | /* Set led off command */ |
| 145 | int iwl4965_led_off(struct iwl_priv *priv, int led_id) |
| 146 | { |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 147 | struct iwl_led_cmd led_cmd = { |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 148 | .id = led_id, |
| 149 | .on = 0, |
| 150 | .off = 0, |
| 151 | .interval = IWL_DEF_LED_INTRVL |
| 152 | }; |
| 153 | IWL_DEBUG_LED("led off %d\n", led_id); |
| 154 | return iwl_send_led_cmd(priv, &led_cmd); |
| 155 | } |
| 156 | #endif |
| 157 | |
| 158 | |
| 159 | /* Set led register off */ |
| 160 | static int iwl4965_led_off_reg(struct iwl_priv *priv, int led_id) |
| 161 | { |
Esti Kummer | c785d1d | 2008-07-18 13:53:07 +0800 | [diff] [blame] | 162 | IWL_DEBUG_LED("LED Reg off\n"); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 163 | iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_OFF); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 167 | /* |
Esti Kummer | c785d1d | 2008-07-18 13:53:07 +0800 | [diff] [blame] | 168 | * Set led register in case of disassociation according to rfkill state |
| 169 | */ |
| 170 | static int iwl_led_associate(struct iwl_priv *priv, int led_id) |
| 171 | { |
| 172 | IWL_DEBUG_LED("Associated\n"); |
| 173 | priv->allow_blinking = 1; |
| 174 | return iwl4965_led_on_reg(priv, led_id); |
| 175 | } |
| 176 | static int iwl_led_disassociate(struct iwl_priv *priv, int led_id) |
| 177 | { |
| 178 | priv->allow_blinking = 0; |
| 179 | if (iwl_is_rfkill(priv)) |
| 180 | iwl4965_led_off_reg(priv, led_id); |
| 181 | else |
| 182 | iwl4965_led_on_reg(priv, led_id); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /* |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 188 | * brightness call back function for Tx/Rx LED |
| 189 | */ |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 190 | static int iwl_led_associated(struct iwl_priv *priv, int led_id) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 191 | { |
| 192 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 193 | !test_bit(STATUS_READY, &priv->status)) |
| 194 | return 0; |
| 195 | |
| 196 | |
| 197 | /* start counting Tx/Rx bytes */ |
| 198 | if (!priv->last_blink_time && priv->allow_blinking) |
| 199 | priv->last_blink_time = jiffies; |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * brightness call back for association and radio |
| 205 | */ |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 206 | static void iwl_led_brightness_set(struct led_classdev *led_cdev, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 207 | enum led_brightness brightness) |
| 208 | { |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 209 | struct iwl_led *led = container_of(led_cdev, struct iwl_led, led_dev); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 210 | struct iwl_priv *priv = led->priv; |
| 211 | |
| 212 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 213 | return; |
| 214 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 215 | |
| 216 | IWL_DEBUG_LED("Led type = %s brightness = %d\n", |
| 217 | led_type_str[led->type], brightness); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 218 | switch (brightness) { |
| 219 | case LED_FULL: |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 220 | if (led->led_on) |
| 221 | led->led_on(priv, IWL_LED_LINK); |
| 222 | break; |
| 223 | case LED_OFF: |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 224 | if (led->led_off) |
| 225 | led->led_off(priv, IWL_LED_LINK); |
| 226 | break; |
| 227 | default: |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 228 | if (led->led_pattern) { |
| 229 | int idx = iwl_brightness_to_idx(brightness); |
| 230 | led->led_pattern(priv, IWL_LED_LINK, idx); |
| 231 | } |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | |
| 238 | /* |
| 239 | * Register led class with the system |
| 240 | */ |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 241 | static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 242 | enum led_type type, u8 set_led, |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 243 | char *trigger) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 244 | { |
| 245 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 246 | int ret; |
| 247 | |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 248 | led->led_dev.name = led->name; |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 249 | led->led_dev.brightness_set = iwl_led_brightness_set; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 250 | led->led_dev.default_trigger = trigger; |
| 251 | |
Tomas Winkler | a571ea4e | 2008-03-28 16:21:11 -0700 | [diff] [blame] | 252 | led->priv = priv; |
| 253 | led->type = type; |
| 254 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 255 | ret = led_classdev_register(device, &led->led_dev); |
| 256 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 257 | IWL_ERR(priv, "Error: failed to register led handler.\n"); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 258 | return ret; |
| 259 | } |
| 260 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 261 | led->registered = 1; |
| 262 | |
| 263 | if (set_led && led->led_on) |
| 264 | led->led_on(priv, IWL_LED_LINK); |
Tomas Winkler | a571ea4e | 2008-03-28 16:21:11 -0700 | [diff] [blame] | 265 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | /* |
| 271 | * calculate blink rate according to last 2 sec Tx/Rx activities |
| 272 | */ |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 273 | static int iwl_get_blink_rate(struct iwl_priv *priv) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 274 | { |
| 275 | int i; |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 276 | u64 current_tpt = priv->tx_stats[2].bytes; |
| 277 | /* FIXME: + priv->rx_stats[2].bytes; */ |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 278 | s64 tpt = current_tpt - priv->led_tpt; |
| 279 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 280 | if (tpt < 0) /* wraparound */ |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 281 | tpt = -tpt; |
| 282 | |
Andrew Morton | 0312110 | 2008-07-22 23:50:04 -0700 | [diff] [blame] | 283 | IWL_DEBUG_LED("tpt %lld current_tpt %llu\n", |
| 284 | (long long)tpt, |
| 285 | (unsigned long long)current_tpt); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 286 | priv->led_tpt = current_tpt; |
| 287 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 288 | if (!priv->allow_blinking) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 289 | i = IWL_MAX_BLINK_TBL; |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 290 | else |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 291 | for (i = 0; i < IWL_MAX_BLINK_TBL; i++) |
| 292 | if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE)) |
| 293 | break; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 294 | |
Wu, Fengguang | 5c11ec6 | 2008-12-17 16:52:28 +0800 | [diff] [blame] | 295 | IWL_DEBUG_LED("LED BLINK IDX=%d\n", i); |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 296 | return i; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 299 | /* |
| 300 | * this function called from handler. Since setting Led command can |
| 301 | * happen very frequent we postpone led command to be called from |
| 302 | * REPLY handler so we know ucode is up |
| 303 | */ |
| 304 | void iwl_leds_background(struct iwl_priv *priv) |
| 305 | { |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 306 | u8 blink_idx; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 307 | |
| 308 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 309 | priv->last_blink_time = 0; |
| 310 | return; |
| 311 | } |
Esti Kummer | c785d1d | 2008-07-18 13:53:07 +0800 | [diff] [blame] | 312 | if (iwl_is_rfkill(priv)) { |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 313 | priv->last_blink_time = 0; |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | if (!priv->allow_blinking) { |
| 318 | priv->last_blink_time = 0; |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 319 | if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) { |
| 320 | priv->last_blink_rate = IWL_SOLID_BLINK_IDX; |
| 321 | iwl4965_led_pattern(priv, IWL_LED_LINK, |
| 322 | IWL_SOLID_BLINK_IDX); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 323 | } |
| 324 | return; |
| 325 | } |
| 326 | if (!priv->last_blink_time || |
| 327 | !time_after(jiffies, priv->last_blink_time + |
| 328 | msecs_to_jiffies(1000))) |
| 329 | return; |
| 330 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 331 | blink_idx = iwl_get_blink_rate(priv); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 332 | |
| 333 | /* call only if blink rate change */ |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 334 | if (blink_idx != priv->last_blink_rate) |
| 335 | iwl4965_led_pattern(priv, IWL_LED_LINK, blink_idx); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 336 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 337 | priv->last_blink_time = jiffies; |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 338 | priv->last_blink_rate = blink_idx; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 339 | } |
| 340 | EXPORT_SYMBOL(iwl_leds_background); |
| 341 | |
| 342 | /* Register all led handler */ |
| 343 | int iwl_leds_register(struct iwl_priv *priv) |
| 344 | { |
| 345 | char *trigger; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 346 | int ret; |
| 347 | |
| 348 | priv->last_blink_rate = 0; |
| 349 | priv->led_tpt = 0; |
| 350 | priv->last_blink_time = 0; |
| 351 | priv->allow_blinking = 0; |
| 352 | |
| 353 | trigger = ieee80211_get_radio_led_name(priv->hw); |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 354 | snprintf(priv->led[IWL_LED_TRG_RADIO].name, |
| 355 | sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s:radio", |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 356 | wiphy_name(priv->hw->wiphy)); |
| 357 | |
| 358 | priv->led[IWL_LED_TRG_RADIO].led_on = iwl4965_led_on_reg; |
| 359 | priv->led[IWL_LED_TRG_RADIO].led_off = iwl4965_led_off_reg; |
| 360 | priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL; |
| 361 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 362 | ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RADIO], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 363 | IWL_LED_TRG_RADIO, 1, trigger); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 364 | if (ret) |
| 365 | goto exit_fail; |
| 366 | |
| 367 | trigger = ieee80211_get_assoc_led_name(priv->hw); |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 368 | snprintf(priv->led[IWL_LED_TRG_ASSOC].name, |
| 369 | sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s:assoc", |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 370 | wiphy_name(priv->hw->wiphy)); |
| 371 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 372 | ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_ASSOC], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 373 | IWL_LED_TRG_ASSOC, 0, trigger); |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 374 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 375 | /* for assoc always turn led on */ |
Esti Kummer | c785d1d | 2008-07-18 13:53:07 +0800 | [diff] [blame] | 376 | priv->led[IWL_LED_TRG_ASSOC].led_on = iwl_led_associate; |
| 377 | priv->led[IWL_LED_TRG_ASSOC].led_off = iwl_led_disassociate; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 378 | priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL; |
| 379 | |
| 380 | if (ret) |
| 381 | goto exit_fail; |
| 382 | |
| 383 | trigger = ieee80211_get_rx_led_name(priv->hw); |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 384 | snprintf(priv->led[IWL_LED_TRG_RX].name, |
| 385 | sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s:RX", |
| 386 | wiphy_name(priv->hw->wiphy)); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 387 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 388 | ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 389 | IWL_LED_TRG_RX, 0, trigger); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 390 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 391 | priv->led[IWL_LED_TRG_RX].led_on = iwl_led_associated; |
| 392 | priv->led[IWL_LED_TRG_RX].led_off = iwl_led_associated; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 393 | priv->led[IWL_LED_TRG_RX].led_pattern = iwl4965_led_pattern; |
| 394 | |
| 395 | if (ret) |
| 396 | goto exit_fail; |
| 397 | |
| 398 | trigger = ieee80211_get_tx_led_name(priv->hw); |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 399 | snprintf(priv->led[IWL_LED_TRG_TX].name, |
| 400 | sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s:TX", |
| 401 | wiphy_name(priv->hw->wiphy)); |
| 402 | |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 403 | ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 404 | IWL_LED_TRG_TX, 0, trigger); |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 405 | |
Tomas Winkler | ec1a746 | 2008-07-11 11:53:37 +0800 | [diff] [blame] | 406 | priv->led[IWL_LED_TRG_TX].led_on = iwl_led_associated; |
| 407 | priv->led[IWL_LED_TRG_TX].led_off = iwl_led_associated; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 408 | priv->led[IWL_LED_TRG_TX].led_pattern = iwl4965_led_pattern; |
| 409 | |
| 410 | if (ret) |
| 411 | goto exit_fail; |
| 412 | |
| 413 | return 0; |
| 414 | |
| 415 | exit_fail: |
| 416 | iwl_leds_unregister(priv); |
| 417 | return ret; |
| 418 | } |
| 419 | EXPORT_SYMBOL(iwl_leds_register); |
| 420 | |
| 421 | /* unregister led class */ |
Tomas Winkler | 0eee612 | 2008-07-11 11:53:36 +0800 | [diff] [blame] | 422 | static void iwl_leds_unregister_led(struct iwl_led *led, u8 set_led) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 423 | { |
| 424 | if (!led->registered) |
| 425 | return; |
| 426 | |
| 427 | led_classdev_unregister(&led->led_dev); |
| 428 | |
| 429 | if (set_led) |
| 430 | led->led_dev.brightness_set(&led->led_dev, LED_OFF); |
| 431 | led->registered = 0; |
| 432 | } |
| 433 | |
| 434 | /* Unregister all led handlers */ |
| 435 | void iwl_leds_unregister(struct iwl_priv *priv) |
| 436 | { |
| 437 | iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_ASSOC], 0); |
| 438 | iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_RX], 0); |
| 439 | iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_TX], 0); |
| 440 | iwl_leds_unregister_led(&priv->led[IWL_LED_TRG_RADIO], 1); |
| 441 | } |
| 442 | EXPORT_SYMBOL(iwl_leds_unregister); |
| 443 | |