diff options
author | Sujith Manoharan <Sujith.Manoharan@atheros.com> | 2010-12-28 03:58:52 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2011-01-04 14:43:00 -0500 |
commit | 1e1f4ad25fab29ca48b1166e74a81e9c89ddf0fb (patch) | |
tree | 64066131ba67cff6b4142e78aa8932fe4bad2078 /drivers/net/wireless | |
parent | 039a07215e0fca00c450f4bf1dc9b458bdfe8559 (diff) |
ath9k_htc: Move LED/RFKILL code to htc_drv_gpio.c
And add the copyright/license header.
Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless')
-rw-r--r-- | drivers/net/wireless/ath/ath9k/htc.h | 5 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/htc_drv_gpio.c | 327 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/htc_drv_main.c | 313 |
3 files changed, 333 insertions, 312 deletions
diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h index 34456a85ab77..a099b3e87ed3 100644 --- a/drivers/net/wireless/ath/ath9k/htc.h +++ b/drivers/net/wireless/ath/ath9k/htc.h | |||
@@ -459,8 +459,13 @@ void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv); | |||
459 | void ath9k_ps_work(struct work_struct *work); | 459 | void ath9k_ps_work(struct work_struct *work); |
460 | bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, | 460 | bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, |
461 | enum ath9k_power_mode mode); | 461 | enum ath9k_power_mode mode); |
462 | void ath_update_txpow(struct ath9k_htc_priv *priv); | ||
462 | 463 | ||
463 | void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv); | 464 | void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv); |
465 | void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw); | ||
466 | void ath9k_htc_radio_enable(struct ieee80211_hw *hw); | ||
467 | void ath9k_htc_radio_disable(struct ieee80211_hw *hw); | ||
468 | void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv); | ||
464 | void ath9k_init_leds(struct ath9k_htc_priv *priv); | 469 | void ath9k_init_leds(struct ath9k_htc_priv *priv); |
465 | void ath9k_deinit_leds(struct ath9k_htc_priv *priv); | 470 | void ath9k_deinit_leds(struct ath9k_htc_priv *priv); |
466 | 471 | ||
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_gpio.c b/drivers/net/wireless/ath/ath9k/htc_drv_gpio.c index 283ff97ed446..fe70f67aa088 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_gpio.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_gpio.c | |||
@@ -1,3 +1,19 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010 Atheros Communications Inc. | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
1 | #include "htc.h" | 17 | #include "htc.h" |
2 | 18 | ||
3 | /******************/ | 19 | /******************/ |
@@ -131,3 +147,314 @@ void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv) | |||
131 | cancel_delayed_work_sync(&priv->coex_period_work); | 147 | cancel_delayed_work_sync(&priv->coex_period_work); |
132 | cancel_delayed_work_sync(&priv->duty_cycle_work); | 148 | cancel_delayed_work_sync(&priv->duty_cycle_work); |
133 | } | 149 | } |
150 | |||
151 | /*******/ | ||
152 | /* LED */ | ||
153 | /*******/ | ||
154 | |||
155 | static void ath9k_led_blink_work(struct work_struct *work) | ||
156 | { | ||
157 | struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv, | ||
158 | ath9k_led_blink_work.work); | ||
159 | |||
160 | if (!(priv->op_flags & OP_LED_ASSOCIATED)) | ||
161 | return; | ||
162 | |||
163 | if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) || | ||
164 | (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE)) | ||
165 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0); | ||
166 | else | ||
167 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, | ||
168 | (priv->op_flags & OP_LED_ON) ? 1 : 0); | ||
169 | |||
170 | ieee80211_queue_delayed_work(priv->hw, | ||
171 | &priv->ath9k_led_blink_work, | ||
172 | (priv->op_flags & OP_LED_ON) ? | ||
173 | msecs_to_jiffies(priv->led_off_duration) : | ||
174 | msecs_to_jiffies(priv->led_on_duration)); | ||
175 | |||
176 | priv->led_on_duration = priv->led_on_cnt ? | ||
177 | max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) : | ||
178 | ATH_LED_ON_DURATION_IDLE; | ||
179 | priv->led_off_duration = priv->led_off_cnt ? | ||
180 | max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) : | ||
181 | ATH_LED_OFF_DURATION_IDLE; | ||
182 | priv->led_on_cnt = priv->led_off_cnt = 0; | ||
183 | |||
184 | if (priv->op_flags & OP_LED_ON) | ||
185 | priv->op_flags &= ~OP_LED_ON; | ||
186 | else | ||
187 | priv->op_flags |= OP_LED_ON; | ||
188 | } | ||
189 | |||
190 | static void ath9k_led_brightness_work(struct work_struct *work) | ||
191 | { | ||
192 | struct ath_led *led = container_of(work, struct ath_led, | ||
193 | brightness_work.work); | ||
194 | struct ath9k_htc_priv *priv = led->priv; | ||
195 | |||
196 | switch (led->brightness) { | ||
197 | case LED_OFF: | ||
198 | if (led->led_type == ATH_LED_ASSOC || | ||
199 | led->led_type == ATH_LED_RADIO) { | ||
200 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, | ||
201 | (led->led_type == ATH_LED_RADIO)); | ||
202 | priv->op_flags &= ~OP_LED_ASSOCIATED; | ||
203 | if (led->led_type == ATH_LED_RADIO) | ||
204 | priv->op_flags &= ~OP_LED_ON; | ||
205 | } else { | ||
206 | priv->led_off_cnt++; | ||
207 | } | ||
208 | break; | ||
209 | case LED_FULL: | ||
210 | if (led->led_type == ATH_LED_ASSOC) { | ||
211 | priv->op_flags |= OP_LED_ASSOCIATED; | ||
212 | ieee80211_queue_delayed_work(priv->hw, | ||
213 | &priv->ath9k_led_blink_work, 0); | ||
214 | } else if (led->led_type == ATH_LED_RADIO) { | ||
215 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0); | ||
216 | priv->op_flags |= OP_LED_ON; | ||
217 | } else { | ||
218 | priv->led_on_cnt++; | ||
219 | } | ||
220 | break; | ||
221 | default: | ||
222 | break; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | static void ath9k_led_brightness(struct led_classdev *led_cdev, | ||
227 | enum led_brightness brightness) | ||
228 | { | ||
229 | struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev); | ||
230 | struct ath9k_htc_priv *priv = led->priv; | ||
231 | |||
232 | led->brightness = brightness; | ||
233 | if (!(priv->op_flags & OP_LED_DEINIT)) | ||
234 | ieee80211_queue_delayed_work(priv->hw, | ||
235 | &led->brightness_work, 0); | ||
236 | } | ||
237 | |||
238 | void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv) | ||
239 | { | ||
240 | cancel_delayed_work_sync(&priv->radio_led.brightness_work); | ||
241 | cancel_delayed_work_sync(&priv->assoc_led.brightness_work); | ||
242 | cancel_delayed_work_sync(&priv->tx_led.brightness_work); | ||
243 | cancel_delayed_work_sync(&priv->rx_led.brightness_work); | ||
244 | } | ||
245 | |||
246 | static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led, | ||
247 | char *trigger) | ||
248 | { | ||
249 | int ret; | ||
250 | |||
251 | led->priv = priv; | ||
252 | led->led_cdev.name = led->name; | ||
253 | led->led_cdev.default_trigger = trigger; | ||
254 | led->led_cdev.brightness_set = ath9k_led_brightness; | ||
255 | |||
256 | ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev); | ||
257 | if (ret) | ||
258 | ath_err(ath9k_hw_common(priv->ah), | ||
259 | "Failed to register led:%s", led->name); | ||
260 | else | ||
261 | led->registered = 1; | ||
262 | |||
263 | INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work); | ||
264 | |||
265 | return ret; | ||
266 | } | ||
267 | |||
268 | static void ath9k_unregister_led(struct ath_led *led) | ||
269 | { | ||
270 | if (led->registered) { | ||
271 | led_classdev_unregister(&led->led_cdev); | ||
272 | led->registered = 0; | ||
273 | } | ||
274 | } | ||
275 | |||
276 | void ath9k_deinit_leds(struct ath9k_htc_priv *priv) | ||
277 | { | ||
278 | priv->op_flags |= OP_LED_DEINIT; | ||
279 | ath9k_unregister_led(&priv->assoc_led); | ||
280 | priv->op_flags &= ~OP_LED_ASSOCIATED; | ||
281 | ath9k_unregister_led(&priv->tx_led); | ||
282 | ath9k_unregister_led(&priv->rx_led); | ||
283 | ath9k_unregister_led(&priv->radio_led); | ||
284 | } | ||
285 | |||
286 | void ath9k_init_leds(struct ath9k_htc_priv *priv) | ||
287 | { | ||
288 | char *trigger; | ||
289 | int ret; | ||
290 | |||
291 | if (AR_SREV_9287(priv->ah)) | ||
292 | priv->ah->led_pin = ATH_LED_PIN_9287; | ||
293 | else if (AR_SREV_9271(priv->ah)) | ||
294 | priv->ah->led_pin = ATH_LED_PIN_9271; | ||
295 | else if (AR_DEVID_7010(priv->ah)) | ||
296 | priv->ah->led_pin = ATH_LED_PIN_7010; | ||
297 | else | ||
298 | priv->ah->led_pin = ATH_LED_PIN_DEF; | ||
299 | |||
300 | /* Configure gpio 1 for output */ | ||
301 | ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin, | ||
302 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); | ||
303 | /* LED off, active low */ | ||
304 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1); | ||
305 | |||
306 | INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work); | ||
307 | |||
308 | trigger = ieee80211_get_radio_led_name(priv->hw); | ||
309 | snprintf(priv->radio_led.name, sizeof(priv->radio_led.name), | ||
310 | "ath9k-%s::radio", wiphy_name(priv->hw->wiphy)); | ||
311 | ret = ath9k_register_led(priv, &priv->radio_led, trigger); | ||
312 | priv->radio_led.led_type = ATH_LED_RADIO; | ||
313 | if (ret) | ||
314 | goto fail; | ||
315 | |||
316 | trigger = ieee80211_get_assoc_led_name(priv->hw); | ||
317 | snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name), | ||
318 | "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy)); | ||
319 | ret = ath9k_register_led(priv, &priv->assoc_led, trigger); | ||
320 | priv->assoc_led.led_type = ATH_LED_ASSOC; | ||
321 | if (ret) | ||
322 | goto fail; | ||
323 | |||
324 | trigger = ieee80211_get_tx_led_name(priv->hw); | ||
325 | snprintf(priv->tx_led.name, sizeof(priv->tx_led.name), | ||
326 | "ath9k-%s::tx", wiphy_name(priv->hw->wiphy)); | ||
327 | ret = ath9k_register_led(priv, &priv->tx_led, trigger); | ||
328 | priv->tx_led.led_type = ATH_LED_TX; | ||
329 | if (ret) | ||
330 | goto fail; | ||
331 | |||
332 | trigger = ieee80211_get_rx_led_name(priv->hw); | ||
333 | snprintf(priv->rx_led.name, sizeof(priv->rx_led.name), | ||
334 | "ath9k-%s::rx", wiphy_name(priv->hw->wiphy)); | ||
335 | ret = ath9k_register_led(priv, &priv->rx_led, trigger); | ||
336 | priv->rx_led.led_type = ATH_LED_RX; | ||
337 | if (ret) | ||
338 | goto fail; | ||
339 | |||
340 | priv->op_flags &= ~OP_LED_DEINIT; | ||
341 | |||
342 | return; | ||
343 | |||
344 | fail: | ||
345 | cancel_delayed_work_sync(&priv->ath9k_led_blink_work); | ||
346 | ath9k_deinit_leds(priv); | ||
347 | } | ||
348 | |||
349 | /*******************/ | ||
350 | /* Rfkill */ | ||
351 | /*******************/ | ||
352 | |||
353 | static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv) | ||
354 | { | ||
355 | return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) == | ||
356 | priv->ah->rfkill_polarity; | ||
357 | } | ||
358 | |||
359 | void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw) | ||
360 | { | ||
361 | struct ath9k_htc_priv *priv = hw->priv; | ||
362 | bool blocked = !!ath_is_rfkill_set(priv); | ||
363 | |||
364 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); | ||
365 | } | ||
366 | |||
367 | void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv) | ||
368 | { | ||
369 | if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) | ||
370 | wiphy_rfkill_start_polling(priv->hw->wiphy); | ||
371 | } | ||
372 | |||
373 | void ath9k_htc_radio_enable(struct ieee80211_hw *hw) | ||
374 | { | ||
375 | struct ath9k_htc_priv *priv = hw->priv; | ||
376 | struct ath_hw *ah = priv->ah; | ||
377 | struct ath_common *common = ath9k_hw_common(ah); | ||
378 | int ret; | ||
379 | u8 cmd_rsp; | ||
380 | |||
381 | if (!ah->curchan) | ||
382 | ah->curchan = ath9k_cmn_get_curchannel(hw, ah); | ||
383 | |||
384 | /* Reset the HW */ | ||
385 | ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); | ||
386 | if (ret) { | ||
387 | ath_err(common, | ||
388 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", | ||
389 | ret, ah->curchan->channel); | ||
390 | } | ||
391 | |||
392 | ath_update_txpow(priv); | ||
393 | |||
394 | /* Start RX */ | ||
395 | WMI_CMD(WMI_START_RECV_CMDID); | ||
396 | ath9k_host_rx_init(priv); | ||
397 | |||
398 | /* Start TX */ | ||
399 | htc_start(priv->htc); | ||
400 | spin_lock_bh(&priv->tx_lock); | ||
401 | priv->tx_queues_stop = false; | ||
402 | spin_unlock_bh(&priv->tx_lock); | ||
403 | ieee80211_wake_queues(hw); | ||
404 | |||
405 | WMI_CMD(WMI_ENABLE_INTR_CMDID); | ||
406 | |||
407 | /* Enable LED */ | ||
408 | ath9k_hw_cfg_output(ah, ah->led_pin, | ||
409 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); | ||
410 | ath9k_hw_set_gpio(ah, ah->led_pin, 0); | ||
411 | } | ||
412 | |||
413 | void ath9k_htc_radio_disable(struct ieee80211_hw *hw) | ||
414 | { | ||
415 | struct ath9k_htc_priv *priv = hw->priv; | ||
416 | struct ath_hw *ah = priv->ah; | ||
417 | struct ath_common *common = ath9k_hw_common(ah); | ||
418 | int ret; | ||
419 | u8 cmd_rsp; | ||
420 | |||
421 | ath9k_htc_ps_wakeup(priv); | ||
422 | |||
423 | /* Disable LED */ | ||
424 | ath9k_hw_set_gpio(ah, ah->led_pin, 1); | ||
425 | ath9k_hw_cfg_gpio_input(ah, ah->led_pin); | ||
426 | |||
427 | WMI_CMD(WMI_DISABLE_INTR_CMDID); | ||
428 | |||
429 | /* Stop TX */ | ||
430 | ieee80211_stop_queues(hw); | ||
431 | htc_stop(priv->htc); | ||
432 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); | ||
433 | skb_queue_purge(&priv->tx_queue); | ||
434 | |||
435 | /* Stop RX */ | ||
436 | WMI_CMD(WMI_STOP_RECV_CMDID); | ||
437 | |||
438 | /* | ||
439 | * The MIB counters have to be disabled here, | ||
440 | * since the target doesn't do it. | ||
441 | */ | ||
442 | ath9k_hw_disable_mib_counters(ah); | ||
443 | |||
444 | if (!ah->curchan) | ||
445 | ah->curchan = ath9k_cmn_get_curchannel(hw, ah); | ||
446 | |||
447 | /* Reset the HW */ | ||
448 | ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); | ||
449 | if (ret) { | ||
450 | ath_err(common, | ||
451 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", | ||
452 | ret, ah->curchan->channel); | ||
453 | } | ||
454 | |||
455 | /* Disable the PHY */ | ||
456 | ath9k_hw_phy_disable(ah); | ||
457 | |||
458 | ath9k_htc_ps_restore(priv); | ||
459 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); | ||
460 | } | ||
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c index 6da5e8867309..ad3dd3186ad2 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c | |||
@@ -24,7 +24,7 @@ static struct dentry *ath9k_debugfs_root; | |||
24 | /* Utilities */ | 24 | /* Utilities */ |
25 | /*************/ | 25 | /*************/ |
26 | 26 | ||
27 | static void ath_update_txpow(struct ath9k_htc_priv *priv) | 27 | void ath_update_txpow(struct ath9k_htc_priv *priv) |
28 | { | 28 | { |
29 | struct ath_hw *ah = priv->ah; | 29 | struct ath_hw *ah = priv->ah; |
30 | 30 | ||
@@ -840,317 +840,6 @@ set_timer: | |||
840 | msecs_to_jiffies(cal_interval)); | 840 | msecs_to_jiffies(cal_interval)); |
841 | } | 841 | } |
842 | 842 | ||
843 | /*******/ | ||
844 | /* LED */ | ||
845 | /*******/ | ||
846 | |||
847 | static void ath9k_led_blink_work(struct work_struct *work) | ||
848 | { | ||
849 | struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv, | ||
850 | ath9k_led_blink_work.work); | ||
851 | |||
852 | if (!(priv->op_flags & OP_LED_ASSOCIATED)) | ||
853 | return; | ||
854 | |||
855 | if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) || | ||
856 | (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE)) | ||
857 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0); | ||
858 | else | ||
859 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, | ||
860 | (priv->op_flags & OP_LED_ON) ? 1 : 0); | ||
861 | |||
862 | ieee80211_queue_delayed_work(priv->hw, | ||
863 | &priv->ath9k_led_blink_work, | ||
864 | (priv->op_flags & OP_LED_ON) ? | ||
865 | msecs_to_jiffies(priv->led_off_duration) : | ||
866 | msecs_to_jiffies(priv->led_on_duration)); | ||
867 | |||
868 | priv->led_on_duration = priv->led_on_cnt ? | ||
869 | max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) : | ||
870 | ATH_LED_ON_DURATION_IDLE; | ||
871 | priv->led_off_duration = priv->led_off_cnt ? | ||
872 | max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) : | ||
873 | ATH_LED_OFF_DURATION_IDLE; | ||
874 | priv->led_on_cnt = priv->led_off_cnt = 0; | ||
875 | |||
876 | if (priv->op_flags & OP_LED_ON) | ||
877 | priv->op_flags &= ~OP_LED_ON; | ||
878 | else | ||
879 | priv->op_flags |= OP_LED_ON; | ||
880 | } | ||
881 | |||
882 | static void ath9k_led_brightness_work(struct work_struct *work) | ||
883 | { | ||
884 | struct ath_led *led = container_of(work, struct ath_led, | ||
885 | brightness_work.work); | ||
886 | struct ath9k_htc_priv *priv = led->priv; | ||
887 | |||
888 | switch (led->brightness) { | ||
889 | case LED_OFF: | ||
890 | if (led->led_type == ATH_LED_ASSOC || | ||
891 | led->led_type == ATH_LED_RADIO) { | ||
892 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, | ||
893 | (led->led_type == ATH_LED_RADIO)); | ||
894 | priv->op_flags &= ~OP_LED_ASSOCIATED; | ||
895 | if (led->led_type == ATH_LED_RADIO) | ||
896 | priv->op_flags &= ~OP_LED_ON; | ||
897 | } else { | ||
898 | priv->led_off_cnt++; | ||
899 | } | ||
900 | break; | ||
901 | case LED_FULL: | ||
902 | if (led->led_type == ATH_LED_ASSOC) { | ||
903 | priv->op_flags |= OP_LED_ASSOCIATED; | ||
904 | ieee80211_queue_delayed_work(priv->hw, | ||
905 | &priv->ath9k_led_blink_work, 0); | ||
906 | } else if (led->led_type == ATH_LED_RADIO) { | ||
907 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0); | ||
908 | priv->op_flags |= OP_LED_ON; | ||
909 | } else { | ||
910 | priv->led_on_cnt++; | ||
911 | } | ||
912 | break; | ||
913 | default: | ||
914 | break; | ||
915 | } | ||
916 | } | ||
917 | |||
918 | static void ath9k_led_brightness(struct led_classdev *led_cdev, | ||
919 | enum led_brightness brightness) | ||
920 | { | ||
921 | struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev); | ||
922 | struct ath9k_htc_priv *priv = led->priv; | ||
923 | |||
924 | led->brightness = brightness; | ||
925 | if (!(priv->op_flags & OP_LED_DEINIT)) | ||
926 | ieee80211_queue_delayed_work(priv->hw, | ||
927 | &led->brightness_work, 0); | ||
928 | } | ||
929 | |||
930 | static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv) | ||
931 | { | ||
932 | cancel_delayed_work_sync(&priv->radio_led.brightness_work); | ||
933 | cancel_delayed_work_sync(&priv->assoc_led.brightness_work); | ||
934 | cancel_delayed_work_sync(&priv->tx_led.brightness_work); | ||
935 | cancel_delayed_work_sync(&priv->rx_led.brightness_work); | ||
936 | } | ||
937 | |||
938 | static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led, | ||
939 | char *trigger) | ||
940 | { | ||
941 | int ret; | ||
942 | |||
943 | led->priv = priv; | ||
944 | led->led_cdev.name = led->name; | ||
945 | led->led_cdev.default_trigger = trigger; | ||
946 | led->led_cdev.brightness_set = ath9k_led_brightness; | ||
947 | |||
948 | ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev); | ||
949 | if (ret) | ||
950 | ath_err(ath9k_hw_common(priv->ah), | ||
951 | "Failed to register led:%s", led->name); | ||
952 | else | ||
953 | led->registered = 1; | ||
954 | |||
955 | INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work); | ||
956 | |||
957 | return ret; | ||
958 | } | ||
959 | |||
960 | static void ath9k_unregister_led(struct ath_led *led) | ||
961 | { | ||
962 | if (led->registered) { | ||
963 | led_classdev_unregister(&led->led_cdev); | ||
964 | led->registered = 0; | ||
965 | } | ||
966 | } | ||
967 | |||
968 | void ath9k_deinit_leds(struct ath9k_htc_priv *priv) | ||
969 | { | ||
970 | priv->op_flags |= OP_LED_DEINIT; | ||
971 | ath9k_unregister_led(&priv->assoc_led); | ||
972 | priv->op_flags &= ~OP_LED_ASSOCIATED; | ||
973 | ath9k_unregister_led(&priv->tx_led); | ||
974 | ath9k_unregister_led(&priv->rx_led); | ||
975 | ath9k_unregister_led(&priv->radio_led); | ||
976 | } | ||
977 | |||
978 | void ath9k_init_leds(struct ath9k_htc_priv *priv) | ||
979 | { | ||
980 | char *trigger; | ||
981 | int ret; | ||
982 | |||
983 | if (AR_SREV_9287(priv->ah)) | ||
984 | priv->ah->led_pin = ATH_LED_PIN_9287; | ||
985 | else if (AR_SREV_9271(priv->ah)) | ||
986 | priv->ah->led_pin = ATH_LED_PIN_9271; | ||
987 | else if (AR_DEVID_7010(priv->ah)) | ||
988 | priv->ah->led_pin = ATH_LED_PIN_7010; | ||
989 | else | ||
990 | priv->ah->led_pin = ATH_LED_PIN_DEF; | ||
991 | |||
992 | /* Configure gpio 1 for output */ | ||
993 | ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin, | ||
994 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); | ||
995 | /* LED off, active low */ | ||
996 | ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1); | ||
997 | |||
998 | INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work); | ||
999 | |||
1000 | trigger = ieee80211_get_radio_led_name(priv->hw); | ||
1001 | snprintf(priv->radio_led.name, sizeof(priv->radio_led.name), | ||
1002 | "ath9k-%s::radio", wiphy_name(priv->hw->wiphy)); | ||
1003 | ret = ath9k_register_led(priv, &priv->radio_led, trigger); | ||
1004 | priv->radio_led.led_type = ATH_LED_RADIO; | ||
1005 | if (ret) | ||
1006 | goto fail; | ||
1007 | |||
1008 | trigger = ieee80211_get_assoc_led_name(priv->hw); | ||
1009 | snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name), | ||
1010 | "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy)); | ||
1011 | ret = ath9k_register_led(priv, &priv->assoc_led, trigger); | ||
1012 | priv->assoc_led.led_type = ATH_LED_ASSOC; | ||
1013 | if (ret) | ||
1014 | goto fail; | ||
1015 | |||
1016 | trigger = ieee80211_get_tx_led_name(priv->hw); | ||
1017 | snprintf(priv->tx_led.name, sizeof(priv->tx_led.name), | ||
1018 | "ath9k-%s::tx", wiphy_name(priv->hw->wiphy)); | ||
1019 | ret = ath9k_register_led(priv, &priv->tx_led, trigger); | ||
1020 | priv->tx_led.led_type = ATH_LED_TX; | ||
1021 | if (ret) | ||
1022 | goto fail; | ||
1023 | |||
1024 | trigger = ieee80211_get_rx_led_name(priv->hw); | ||
1025 | snprintf(priv->rx_led.name, sizeof(priv->rx_led.name), | ||
1026 | "ath9k-%s::rx", wiphy_name(priv->hw->wiphy)); | ||
1027 | ret = ath9k_register_led(priv, &priv->rx_led, trigger); | ||
1028 | priv->rx_led.led_type = ATH_LED_RX; | ||
1029 | if (ret) | ||
1030 | goto fail; | ||
1031 | |||
1032 | priv->op_flags &= ~OP_LED_DEINIT; | ||
1033 | |||
1034 | return; | ||
1035 | |||
1036 | fail: | ||
1037 | cancel_delayed_work_sync(&priv->ath9k_led_blink_work); | ||
1038 | ath9k_deinit_leds(priv); | ||
1039 | } | ||
1040 | |||
1041 | /*******************/ | ||
1042 | /* Rfkill */ | ||
1043 | /*******************/ | ||
1044 | |||
1045 | static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv) | ||
1046 | { | ||
1047 | return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) == | ||
1048 | priv->ah->rfkill_polarity; | ||
1049 | } | ||
1050 | |||
1051 | static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw) | ||
1052 | { | ||
1053 | struct ath9k_htc_priv *priv = hw->priv; | ||
1054 | bool blocked = !!ath_is_rfkill_set(priv); | ||
1055 | |||
1056 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); | ||
1057 | } | ||
1058 | |||
1059 | void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv) | ||
1060 | { | ||
1061 | if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) | ||
1062 | wiphy_rfkill_start_polling(priv->hw->wiphy); | ||
1063 | } | ||
1064 | |||
1065 | static void ath9k_htc_radio_enable(struct ieee80211_hw *hw) | ||
1066 | { | ||
1067 | struct ath9k_htc_priv *priv = hw->priv; | ||
1068 | struct ath_hw *ah = priv->ah; | ||
1069 | struct ath_common *common = ath9k_hw_common(ah); | ||
1070 | int ret; | ||
1071 | u8 cmd_rsp; | ||
1072 | |||
1073 | if (!ah->curchan) | ||
1074 | ah->curchan = ath9k_cmn_get_curchannel(hw, ah); | ||
1075 | |||
1076 | /* Reset the HW */ | ||
1077 | ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); | ||
1078 | if (ret) { | ||
1079 | ath_err(common, | ||
1080 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", | ||
1081 | ret, ah->curchan->channel); | ||
1082 | } | ||
1083 | |||
1084 | ath_update_txpow(priv); | ||
1085 | |||
1086 | /* Start RX */ | ||
1087 | WMI_CMD(WMI_START_RECV_CMDID); | ||
1088 | ath9k_host_rx_init(priv); | ||
1089 | |||
1090 | /* Start TX */ | ||
1091 | htc_start(priv->htc); | ||
1092 | spin_lock_bh(&priv->tx_lock); | ||
1093 | priv->tx_queues_stop = false; | ||
1094 | spin_unlock_bh(&priv->tx_lock); | ||
1095 | ieee80211_wake_queues(hw); | ||
1096 | |||
1097 | WMI_CMD(WMI_ENABLE_INTR_CMDID); | ||
1098 | |||
1099 | /* Enable LED */ | ||
1100 | ath9k_hw_cfg_output(ah, ah->led_pin, | ||
1101 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); | ||
1102 | ath9k_hw_set_gpio(ah, ah->led_pin, 0); | ||
1103 | } | ||
1104 | |||
1105 | static void ath9k_htc_radio_disable(struct ieee80211_hw *hw) | ||
1106 | { | ||
1107 | struct ath9k_htc_priv *priv = hw->priv; | ||
1108 | struct ath_hw *ah = priv->ah; | ||
1109 | struct ath_common *common = ath9k_hw_common(ah); | ||
1110 | int ret; | ||
1111 | u8 cmd_rsp; | ||
1112 | |||
1113 | ath9k_htc_ps_wakeup(priv); | ||
1114 | |||
1115 | /* Disable LED */ | ||
1116 | ath9k_hw_set_gpio(ah, ah->led_pin, 1); | ||
1117 | ath9k_hw_cfg_gpio_input(ah, ah->led_pin); | ||
1118 | |||
1119 | WMI_CMD(WMI_DISABLE_INTR_CMDID); | ||
1120 | |||
1121 | /* Stop TX */ | ||
1122 | ieee80211_stop_queues(hw); | ||
1123 | htc_stop(priv->htc); | ||
1124 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); | ||
1125 | skb_queue_purge(&priv->tx_queue); | ||
1126 | |||
1127 | /* Stop RX */ | ||
1128 | WMI_CMD(WMI_STOP_RECV_CMDID); | ||
1129 | |||
1130 | /* | ||
1131 | * The MIB counters have to be disabled here, | ||
1132 | * since the target doesn't do it. | ||
1133 | */ | ||
1134 | ath9k_hw_disable_mib_counters(ah); | ||
1135 | |||
1136 | if (!ah->curchan) | ||
1137 | ah->curchan = ath9k_cmn_get_curchannel(hw, ah); | ||
1138 | |||
1139 | /* Reset the HW */ | ||
1140 | ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); | ||
1141 | if (ret) { | ||
1142 | ath_err(common, | ||
1143 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", | ||
1144 | ret, ah->curchan->channel); | ||
1145 | } | ||
1146 | |||
1147 | /* Disable the PHY */ | ||
1148 | ath9k_hw_phy_disable(ah); | ||
1149 | |||
1150 | ath9k_htc_ps_restore(priv); | ||
1151 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); | ||
1152 | } | ||
1153 | |||
1154 | /**********************/ | 843 | /**********************/ |
1155 | /* mac80211 Callbacks */ | 844 | /* mac80211 Callbacks */ |
1156 | /**********************/ | 845 | /**********************/ |