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