Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved. |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 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 | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 41 | #include "iwl-commands.h" |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 42 | #include "iwl-3945.h" |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 43 | #include "iwl-core.h" |
| 44 | #include "iwl-dev.h" |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 45 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 46 | |
| 47 | static const struct { |
| 48 | u16 brightness; |
| 49 | u8 on_time; |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 50 | u8 off_time; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 51 | } blink_tbl[] = |
| 52 | { |
| 53 | {300, 25, 25}, |
| 54 | {200, 40, 40}, |
| 55 | {100, 55, 55}, |
| 56 | {70, 65, 65}, |
| 57 | {50, 75, 75}, |
| 58 | {20, 85, 85}, |
| 59 | {15, 95, 95 }, |
| 60 | {10, 110, 110}, |
| 61 | {5, 130, 130}, |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 62 | {0, 167, 167}, |
| 63 | /*SOLID_ON*/ |
| 64 | {-1, IWL_LED_SOLID, 0} |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 67 | #define IWL_1MB_RATE (128 * 1024) |
| 68 | #define IWL_LED_THRESHOLD (16) |
| 69 | #define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /*Exclude Solid on*/ |
| 70 | #define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1) |
| 71 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 72 | static int iwl3945_led_cmd_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 73 | struct iwl_cmd *cmd, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 74 | struct sk_buff *skb) |
| 75 | { |
| 76 | return 1; |
| 77 | } |
| 78 | |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 79 | static inline int iwl3945_brightness_to_idx(enum led_brightness brightness) |
| 80 | { |
| 81 | return fls(0x000000FF & (u32)brightness); |
| 82 | } |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 83 | |
| 84 | /* Send led command */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 85 | static int iwl_send_led_cmd(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 86 | struct iwl_led_cmd *led_cmd) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 87 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 88 | struct iwl_host_cmd cmd = { |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 89 | .id = REPLY_LEDS_CMD, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 90 | .len = sizeof(struct iwl_led_cmd), |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 91 | .data = led_cmd, |
| 92 | .meta.flags = CMD_ASYNC, |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 93 | .meta.u.callback = iwl3945_led_cmd_callback, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 96 | return iwl_send_cmd(priv, &cmd); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 100 | |
| 101 | /* Set led on command */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 102 | static int iwl3945_led_pattern(struct iwl_priv *priv, int led_id, |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 103 | unsigned int idx) |
| 104 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 105 | struct iwl_led_cmd led_cmd = { |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 106 | .id = led_id, |
| 107 | .interval = IWL_DEF_LED_INTRVL |
| 108 | }; |
| 109 | |
| 110 | BUG_ON(idx > IWL_MAX_BLINK_TBL); |
| 111 | |
| 112 | led_cmd.on = blink_tbl[idx].on_time; |
| 113 | led_cmd.off = blink_tbl[idx].off_time; |
| 114 | |
| 115 | return iwl_send_led_cmd(priv, &led_cmd); |
| 116 | } |
| 117 | |
| 118 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 119 | /* Set led on command */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 120 | static int iwl3945_led_on(struct iwl_priv *priv, int led_id) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 121 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 122 | struct iwl_led_cmd led_cmd = { |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 123 | .id = led_id, |
| 124 | .on = IWL_LED_SOLID, |
| 125 | .off = 0, |
| 126 | .interval = IWL_DEF_LED_INTRVL |
| 127 | }; |
| 128 | return iwl_send_led_cmd(priv, &led_cmd); |
| 129 | } |
| 130 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 131 | /* Set led off command */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 132 | static int iwl3945_led_off(struct iwl_priv *priv, int led_id) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 133 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 134 | struct iwl_led_cmd led_cmd = { |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 135 | .id = led_id, |
| 136 | .on = 0, |
| 137 | .off = 0, |
| 138 | .interval = IWL_DEF_LED_INTRVL |
| 139 | }; |
| 140 | IWL_DEBUG_LED("led off %d\n", led_id); |
| 141 | return iwl_send_led_cmd(priv, &led_cmd); |
| 142 | } |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * brightness call back function for Tx/Rx LED |
| 146 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 147 | static int iwl3945_led_associated(struct iwl_priv *priv, int led_id) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 148 | { |
| 149 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 150 | !test_bit(STATUS_READY, &priv->status)) |
| 151 | return 0; |
| 152 | |
| 153 | |
| 154 | /* start counting Tx/Rx bytes */ |
| 155 | if (!priv->last_blink_time && priv->allow_blinking) |
| 156 | priv->last_blink_time = jiffies; |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * brightness call back for association and radio |
| 162 | */ |
| 163 | static void iwl3945_led_brightness_set(struct led_classdev *led_cdev, |
| 164 | enum led_brightness brightness) |
| 165 | { |
| 166 | struct iwl3945_led *led = container_of(led_cdev, |
| 167 | struct iwl3945_led, led_dev); |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 168 | struct iwl_priv *priv = led->priv; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 169 | |
| 170 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 171 | return; |
| 172 | |
| 173 | switch (brightness) { |
| 174 | case LED_FULL: |
| 175 | if (led->type == IWL_LED_TRG_ASSOC) { |
| 176 | priv->allow_blinking = 1; |
| 177 | IWL_DEBUG_LED("MAC is associated\n"); |
| 178 | } |
| 179 | if (led->led_on) |
| 180 | led->led_on(priv, IWL_LED_LINK); |
| 181 | break; |
| 182 | case LED_OFF: |
| 183 | if (led->type == IWL_LED_TRG_ASSOC) { |
| 184 | priv->allow_blinking = 0; |
| 185 | IWL_DEBUG_LED("MAC is disassociated\n"); |
| 186 | } |
| 187 | if (led->led_off) |
| 188 | led->led_off(priv, IWL_LED_LINK); |
| 189 | break; |
| 190 | default: |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 191 | if (led->led_pattern) { |
| 192 | int idx = iwl3945_brightness_to_idx(brightness); |
| 193 | led->led_pattern(priv, IWL_LED_LINK, idx); |
| 194 | } |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 195 | break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | |
| 200 | |
| 201 | /* |
| 202 | * Register led class with the system |
| 203 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 204 | static int iwl3945_led_register_led(struct iwl_priv *priv, |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 205 | struct iwl3945_led *led, |
| 206 | enum led_type type, u8 set_led, |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 207 | char *trigger) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 208 | { |
| 209 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 210 | int ret; |
| 211 | |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 212 | led->led_dev.name = led->name; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 213 | led->led_dev.brightness_set = iwl3945_led_brightness_set; |
| 214 | led->led_dev.default_trigger = trigger; |
| 215 | |
Marcin Slusarz | b6b1619 | 2008-06-08 13:13:06 +0200 | [diff] [blame] | 216 | led->priv = priv; |
| 217 | led->type = type; |
| 218 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 219 | ret = led_classdev_register(device, &led->led_dev); |
| 220 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 221 | IWL_ERR(priv, "Error: failed to register led handler.\n"); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 222 | return ret; |
| 223 | } |
| 224 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 225 | led->registered = 1; |
| 226 | |
| 227 | if (set_led && led->led_on) |
| 228 | led->led_on(priv, IWL_LED_LINK); |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /* |
| 234 | * calculate blink rate according to last 2 sec Tx/Rx activities |
| 235 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 236 | static inline u8 get_blink_rate(struct iwl_priv *priv) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 237 | { |
| 238 | int index; |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 239 | u64 current_tpt = priv->rxtxpackets; |
| 240 | s64 tpt = current_tpt - priv->led_tpt; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 241 | |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 242 | if (tpt < 0) |
| 243 | tpt = -tpt; |
| 244 | priv->led_tpt = current_tpt; |
| 245 | |
| 246 | if (!priv->allow_blinking) |
| 247 | index = IWL_MAX_BLINK_TBL; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 248 | else |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 249 | for (index = 0; index < IWL_MAX_BLINK_TBL; index++) |
| 250 | if (tpt > (blink_tbl[index].brightness * IWL_1MB_RATE)) |
| 251 | break; |
| 252 | return index; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 255 | static inline int is_rf_kill(struct iwl_priv *priv) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 256 | { |
| 257 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 258 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * this function called from handler. Since setting Led command can |
| 263 | * happen very frequent we postpone led command to be called from |
| 264 | * REPLY handler so we know ucode is up |
| 265 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 266 | void iwl3945_led_background(struct iwl_priv *priv) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 267 | { |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 268 | u8 blink_idx; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 269 | |
| 270 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 271 | priv->last_blink_time = 0; |
| 272 | return; |
| 273 | } |
| 274 | if (is_rf_kill(priv)) { |
| 275 | priv->last_blink_time = 0; |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | if (!priv->allow_blinking) { |
| 280 | priv->last_blink_time = 0; |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 281 | if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) { |
| 282 | priv->last_blink_rate = IWL_SOLID_BLINK_IDX; |
| 283 | iwl3945_led_pattern(priv, IWL_LED_LINK, |
| 284 | IWL_SOLID_BLINK_IDX); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 285 | } |
| 286 | return; |
| 287 | } |
| 288 | if (!priv->last_blink_time || |
| 289 | !time_after(jiffies, priv->last_blink_time + |
| 290 | msecs_to_jiffies(1000))) |
| 291 | return; |
| 292 | |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 293 | blink_idx = get_blink_rate(priv); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 294 | |
| 295 | /* call only if blink rate change */ |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 296 | if (blink_idx != priv->last_blink_rate) |
| 297 | iwl3945_led_pattern(priv, IWL_LED_LINK, blink_idx); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 298 | |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 299 | priv->last_blink_time = jiffies; |
| 300 | priv->last_blink_rate = blink_idx; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 301 | priv->rxtxpackets = 0; |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /* Register all led handler */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 306 | int iwl3945_led_register(struct iwl_priv *priv) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 307 | { |
| 308 | char *trigger; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 309 | int ret; |
| 310 | |
| 311 | priv->last_blink_rate = 0; |
| 312 | priv->rxtxpackets = 0; |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 313 | priv->led_tpt = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 314 | priv->last_blink_time = 0; |
| 315 | priv->allow_blinking = 0; |
| 316 | |
| 317 | trigger = ieee80211_get_radio_led_name(priv->hw); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 318 | snprintf(priv->led39[IWL_LED_TRG_RADIO].name, |
| 319 | sizeof(priv->led39[IWL_LED_TRG_RADIO].name), "iwl-%s:radio", |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 320 | wiphy_name(priv->hw->wiphy)); |
| 321 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 322 | priv->led39[IWL_LED_TRG_RADIO].led_on = iwl3945_led_on; |
| 323 | priv->led39[IWL_LED_TRG_RADIO].led_off = iwl3945_led_off; |
| 324 | priv->led39[IWL_LED_TRG_RADIO].led_pattern = NULL; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 325 | |
| 326 | ret = iwl3945_led_register_led(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 327 | &priv->led39[IWL_LED_TRG_RADIO], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 328 | IWL_LED_TRG_RADIO, 1, trigger); |
| 329 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 330 | if (ret) |
| 331 | goto exit_fail; |
| 332 | |
| 333 | trigger = ieee80211_get_assoc_led_name(priv->hw); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 334 | snprintf(priv->led39[IWL_LED_TRG_ASSOC].name, |
| 335 | sizeof(priv->led39[IWL_LED_TRG_ASSOC].name), "iwl-%s:assoc", |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 336 | wiphy_name(priv->hw->wiphy)); |
| 337 | |
| 338 | ret = iwl3945_led_register_led(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 339 | &priv->led39[IWL_LED_TRG_ASSOC], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 340 | IWL_LED_TRG_ASSOC, 0, trigger); |
| 341 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 342 | /* for assoc always turn led on */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 343 | priv->led39[IWL_LED_TRG_ASSOC].led_on = iwl3945_led_on; |
| 344 | priv->led39[IWL_LED_TRG_ASSOC].led_off = iwl3945_led_on; |
| 345 | priv->led39[IWL_LED_TRG_ASSOC].led_pattern = NULL; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 346 | |
| 347 | if (ret) |
| 348 | goto exit_fail; |
| 349 | |
| 350 | trigger = ieee80211_get_rx_led_name(priv->hw); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 351 | snprintf(priv->led39[IWL_LED_TRG_RX].name, |
| 352 | sizeof(priv->led39[IWL_LED_TRG_RX].name), "iwl-%s:RX", |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 353 | wiphy_name(priv->hw->wiphy)); |
| 354 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 355 | ret = iwl3945_led_register_led(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 356 | &priv->led39[IWL_LED_TRG_RX], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 357 | IWL_LED_TRG_RX, 0, trigger); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 358 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 359 | priv->led39[IWL_LED_TRG_RX].led_on = iwl3945_led_associated; |
| 360 | priv->led39[IWL_LED_TRG_RX].led_off = iwl3945_led_associated; |
| 361 | priv->led39[IWL_LED_TRG_RX].led_pattern = iwl3945_led_pattern; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 362 | |
| 363 | if (ret) |
| 364 | goto exit_fail; |
| 365 | |
| 366 | trigger = ieee80211_get_tx_led_name(priv->hw); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 367 | snprintf(priv->led39[IWL_LED_TRG_TX].name, |
| 368 | sizeof(priv->led39[IWL_LED_TRG_TX].name), "iwl-%s:TX", |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 369 | wiphy_name(priv->hw->wiphy)); |
Abhijeet Kolekar | 9a9ad0c | 2008-07-11 11:53:41 +0800 | [diff] [blame] | 370 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 371 | ret = iwl3945_led_register_led(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 372 | &priv->led39[IWL_LED_TRG_TX], |
Sven Wegener | 5cbbb37 | 2008-08-01 21:57:16 +0200 | [diff] [blame] | 373 | IWL_LED_TRG_TX, 0, trigger); |
| 374 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 375 | priv->led39[IWL_LED_TRG_TX].led_on = iwl3945_led_associated; |
| 376 | priv->led39[IWL_LED_TRG_TX].led_off = iwl3945_led_associated; |
| 377 | priv->led39[IWL_LED_TRG_TX].led_pattern = iwl3945_led_pattern; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 378 | |
| 379 | if (ret) |
| 380 | goto exit_fail; |
| 381 | |
| 382 | return 0; |
| 383 | |
| 384 | exit_fail: |
| 385 | iwl3945_led_unregister(priv); |
| 386 | return ret; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | /* unregister led class */ |
| 391 | static void iwl3945_led_unregister_led(struct iwl3945_led *led, u8 set_led) |
| 392 | { |
| 393 | if (!led->registered) |
| 394 | return; |
| 395 | |
| 396 | led_classdev_unregister(&led->led_dev); |
| 397 | |
| 398 | if (set_led) |
| 399 | led->led_dev.brightness_set(&led->led_dev, LED_OFF); |
| 400 | led->registered = 0; |
| 401 | } |
| 402 | |
| 403 | /* Unregister all led handlers */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 404 | void iwl3945_led_unregister(struct iwl_priv *priv) |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 405 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 406 | iwl3945_led_unregister_led(&priv->led39[IWL_LED_TRG_ASSOC], 0); |
| 407 | iwl3945_led_unregister_led(&priv->led39[IWL_LED_TRG_RX], 0); |
| 408 | iwl3945_led_unregister_led(&priv->led39[IWL_LED_TRG_TX], 0); |
| 409 | iwl3945_led_unregister_led(&priv->led39[IWL_LED_TRG_RADIO], 1); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |