2010-01-08 13:06:00 +08:00
|
|
|
/*
|
2011-05-17 16:06:18 +08:00
|
|
|
* Copyright (c) 2008-2011 Atheros Communications Inc.
|
2010-01-08 13:06:00 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ath9k.h"
|
|
|
|
|
|
|
|
/********************************/
|
|
|
|
/* LED functions */
|
|
|
|
/********************************/
|
|
|
|
|
2011-02-28 05:26:40 +08:00
|
|
|
#ifdef CONFIG_MAC80211_LEDS
|
2010-01-08 13:06:00 +08:00
|
|
|
static void ath_led_brightness(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness brightness)
|
|
|
|
{
|
2011-02-28 05:26:40 +08:00
|
|
|
struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
|
|
|
|
ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ath_deinit_leds(struct ath_softc *sc)
|
|
|
|
{
|
2011-02-28 05:26:40 +08:00
|
|
|
if (!sc->led_registered)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ath_led_brightness(&sc->led_cdev, LED_OFF);
|
|
|
|
led_classdev_unregister(&sc->led_cdev);
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ath_init_leds(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-03-19 20:55:40 +08:00
|
|
|
if (sc->sc_ah->led_pin < 0) {
|
|
|
|
if (AR_SREV_9287(sc->sc_ah))
|
|
|
|
sc->sc_ah->led_pin = ATH_LED_PIN_9287;
|
|
|
|
else if (AR_SREV_9485(sc->sc_ah))
|
|
|
|
sc->sc_ah->led_pin = ATH_LED_PIN_9485;
|
2011-04-22 14:02:08 +08:00
|
|
|
else if (AR_SREV_9300(sc->sc_ah))
|
|
|
|
sc->sc_ah->led_pin = ATH_LED_PIN_9300;
|
2011-10-13 13:30:44 +08:00
|
|
|
else if (AR_SREV_9462(sc->sc_ah))
|
|
|
|
sc->sc_ah->led_pin = ATH_LED_PIN_9462;
|
2011-03-19 20:55:40 +08:00
|
|
|
else
|
|
|
|
sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
|
|
|
|
}
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
/* Configure gpio 1 for output */
|
|
|
|
ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
|
|
|
|
AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
|
|
|
|
/* LED off, active low */
|
|
|
|
ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
|
|
|
|
|
2011-02-28 05:26:40 +08:00
|
|
|
if (!led_blink)
|
|
|
|
sc->led_cdev.default_trigger =
|
|
|
|
ieee80211_get_radio_led_name(sc->hw);
|
|
|
|
|
|
|
|
snprintf(sc->led_name, sizeof(sc->led_name),
|
|
|
|
"ath9k-%s", wiphy_name(sc->hw->wiphy));
|
|
|
|
sc->led_cdev.name = sc->led_name;
|
|
|
|
sc->led_cdev.brightness_set = ath_led_brightness;
|
|
|
|
|
|
|
|
ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
|
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sc->led_registered = true;
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
2011-02-28 05:26:40 +08:00
|
|
|
#endif
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
/*******************/
|
|
|
|
/* Rfkill */
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
static bool ath_is_rfkill_set(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
2011-09-28 19:26:10 +08:00
|
|
|
bool is_blocked;
|
2010-01-08 13:06:00 +08:00
|
|
|
|
2011-09-28 19:26:10 +08:00
|
|
|
ath9k_ps_wakeup(sc);
|
|
|
|
is_blocked = ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
|
2010-01-08 13:06:00 +08:00
|
|
|
ah->rfkill_polarity;
|
2011-09-28 19:26:10 +08:00
|
|
|
ath9k_ps_restore(sc);
|
|
|
|
|
|
|
|
return is_blocked;
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
|
|
|
|
{
|
2011-01-25 02:23:18 +08:00
|
|
|
struct ath_softc *sc = hw->priv;
|
2010-01-08 13:06:00 +08:00
|
|
|
bool blocked = !!ath_is_rfkill_set(sc);
|
|
|
|
|
|
|
|
wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ath_start_rfkill_poll(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
|
|
|
|
|
|
|
if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
|
|
|
|
wiphy_rfkill_start_polling(sc->hw->wiphy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************/
|
|
|
|
/* BTCOEX */
|
|
|
|
/******************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detects if there is any priority bt traffic
|
|
|
|
*/
|
|
|
|
static void ath_detect_bt_priority(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
|
|
|
|
|
|
|
if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
|
|
|
|
btcoex->bt_priority_cnt++;
|
|
|
|
|
|
|
|
if (time_after(jiffies, btcoex->bt_priority_time +
|
|
|
|
msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
|
2010-01-21 13:47:27 +08:00
|
|
|
sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
|
|
|
|
/* Detect if colocated bt started scanning */
|
|
|
|
if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
|
2010-12-03 11:12:37 +08:00
|
|
|
ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
|
|
|
|
"BT scan detected\n");
|
2010-01-21 13:47:27 +08:00
|
|
|
sc->sc_flags |= (SC_OP_BT_SCAN |
|
|
|
|
SC_OP_BT_PRIORITY_DETECTED);
|
|
|
|
} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
|
2010-12-03 11:12:37 +08:00
|
|
|
ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
|
|
|
|
"BT priority traffic detected\n");
|
2010-01-08 13:06:00 +08:00
|
|
|
sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
btcoex->bt_priority_cnt = 0;
|
|
|
|
btcoex->bt_priority_time = jiffies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ath9k_gen_timer_start(struct ath_hw *ah,
|
|
|
|
struct ath_gen_timer *timer,
|
2011-04-21 21:03:27 +08:00
|
|
|
u32 trig_timeout,
|
2010-01-08 13:06:00 +08:00
|
|
|
u32 timer_period)
|
|
|
|
{
|
2011-04-21 21:03:27 +08:00
|
|
|
ath9k_hw_gen_timer_start(ah, timer, trig_timeout, timer_period);
|
2010-01-08 13:06:00 +08:00
|
|
|
|
2010-04-01 06:05:31 +08:00
|
|
|
if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
|
2010-11-09 03:54:47 +08:00
|
|
|
ath9k_hw_disable_interrupts(ah);
|
2010-04-01 06:05:31 +08:00
|
|
|
ah->imask |= ATH9K_INT_GENTIMER;
|
2011-10-09 02:06:19 +08:00
|
|
|
ath9k_hw_set_interrupts(ah);
|
2011-08-05 21:29:40 +08:00
|
|
|
ath9k_hw_enable_interrupts(ah);
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
|
|
|
|
{
|
|
|
|
struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
|
|
|
|
|
|
|
|
ath9k_hw_gen_timer_stop(ah, timer);
|
|
|
|
|
|
|
|
/* if no timer is enabled, turn off interrupt mask */
|
|
|
|
if (timer_table->timer_mask.val == 0) {
|
2010-11-09 03:54:47 +08:00
|
|
|
ath9k_hw_disable_interrupts(ah);
|
2010-04-01 06:05:31 +08:00
|
|
|
ah->imask &= ~ATH9K_INT_GENTIMER;
|
2011-10-09 02:06:19 +08:00
|
|
|
ath9k_hw_set_interrupts(ah);
|
2011-08-05 21:29:40 +08:00
|
|
|
ath9k_hw_enable_interrupts(ah);
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the master bt coex timer which runs for every
|
|
|
|
* 45ms, bt traffic will be given priority during 55% of this
|
|
|
|
* period while wlan gets remaining 45%
|
|
|
|
*/
|
|
|
|
static void ath_btcoex_period_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct ath_softc *sc = (struct ath_softc *) data;
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
2010-01-21 13:47:27 +08:00
|
|
|
u32 timer_period;
|
|
|
|
bool is_btscan;
|
2010-01-08 13:06:00 +08:00
|
|
|
|
2011-04-26 13:09:55 +08:00
|
|
|
ath9k_ps_wakeup(sc);
|
2011-10-24 20:49:49 +08:00
|
|
|
if (!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI))
|
|
|
|
ath_detect_bt_priority(sc);
|
2010-01-21 13:47:27 +08:00
|
|
|
is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
|
|
|
|
|
2010-01-08 13:06:00 +08:00
|
|
|
spin_lock_bh(&btcoex->btcoex_lock);
|
|
|
|
|
2011-04-26 13:09:52 +08:00
|
|
|
ath9k_hw_btcoex_bt_stomp(ah, is_btscan ? ATH_BTCOEX_STOMP_ALL :
|
2010-01-21 13:47:27 +08:00
|
|
|
btcoex->bt_stomp_type);
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
spin_unlock_bh(&btcoex->btcoex_lock);
|
|
|
|
|
|
|
|
if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
|
|
|
|
if (btcoex->hw_timer_enabled)
|
|
|
|
ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
|
|
|
|
|
2010-01-21 13:47:27 +08:00
|
|
|
timer_period = is_btscan ? btcoex->btscan_no_stomp :
|
|
|
|
btcoex->btcoex_no_stomp;
|
2011-04-21 21:03:27 +08:00
|
|
|
ath9k_gen_timer_start(ah, btcoex->no_stomp_timer, timer_period,
|
2010-10-16 02:03:32 +08:00
|
|
|
timer_period * 10);
|
2010-01-08 13:06:00 +08:00
|
|
|
btcoex->hw_timer_enabled = true;
|
|
|
|
}
|
|
|
|
|
2011-04-26 13:09:55 +08:00
|
|
|
ath9k_ps_restore(sc);
|
2011-10-24 20:49:49 +08:00
|
|
|
timer_period = btcoex->btcoex_period / 1000;
|
2010-01-08 13:06:00 +08:00
|
|
|
mod_timer(&btcoex->period_timer, jiffies +
|
2011-10-24 20:49:49 +08:00
|
|
|
msecs_to_jiffies(timer_period));
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic tsf based hw timer which configures weight
|
|
|
|
* registers to time slice between wlan and bt traffic
|
|
|
|
*/
|
|
|
|
static void ath_btcoex_no_stomp_timer(void *arg)
|
|
|
|
{
|
|
|
|
struct ath_softc *sc = (struct ath_softc *)arg;
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
2010-08-18 22:27:48 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
2010-01-21 13:47:27 +08:00
|
|
|
bool is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
|
2010-01-08 13:06:00 +08:00
|
|
|
|
2010-12-03 11:12:37 +08:00
|
|
|
ath_dbg(common, ATH_DBG_BTCOEX,
|
|
|
|
"no stomp timer running\n");
|
2010-01-08 13:06:00 +08:00
|
|
|
|
2011-04-26 13:09:55 +08:00
|
|
|
ath9k_ps_wakeup(sc);
|
2010-01-08 13:06:00 +08:00
|
|
|
spin_lock_bh(&btcoex->btcoex_lock);
|
|
|
|
|
2010-01-21 13:47:27 +08:00
|
|
|
if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan)
|
2011-04-26 13:09:52 +08:00
|
|
|
ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
|
2010-01-08 13:06:00 +08:00
|
|
|
else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
|
2011-04-26 13:09:52 +08:00
|
|
|
ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
spin_unlock_bh(&btcoex->btcoex_lock);
|
2011-04-26 13:09:55 +08:00
|
|
|
ath9k_ps_restore(sc);
|
2010-01-08 13:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ath_init_btcoex_timer(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
|
|
|
|
btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
|
|
|
|
btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
|
|
|
|
btcoex->btcoex_period / 100;
|
2010-01-21 13:47:27 +08:00
|
|
|
btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
|
|
|
|
btcoex->btcoex_period / 100;
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
|
|
|
|
(unsigned long) sc);
|
|
|
|
|
|
|
|
spin_lock_init(&btcoex->btcoex_lock);
|
|
|
|
|
|
|
|
btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
|
|
|
|
ath_btcoex_no_stomp_timer,
|
|
|
|
ath_btcoex_no_stomp_timer,
|
|
|
|
(void *) sc, AR_FIRST_NDP_TIMER);
|
|
|
|
|
|
|
|
if (!btcoex->no_stomp_timer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (Re)start btcoex timers
|
|
|
|
*/
|
|
|
|
void ath9k_btcoex_timer_resume(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
|
|
|
|
2010-12-03 11:12:37 +08:00
|
|
|
ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
|
|
|
|
"Starting btcoex timers\n");
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
/* make sure duty cycle timer is also stopped when resuming */
|
|
|
|
if (btcoex->hw_timer_enabled)
|
|
|
|
ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
|
|
|
|
|
|
|
|
btcoex->bt_priority_cnt = 0;
|
|
|
|
btcoex->bt_priority_time = jiffies;
|
2010-01-21 13:47:27 +08:00
|
|
|
sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
|
2010-01-08 13:06:00 +08:00
|
|
|
|
|
|
|
mod_timer(&btcoex->period_timer, jiffies);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pause btcoex timer and bt duty cycle timer
|
|
|
|
*/
|
|
|
|
void ath9k_btcoex_timer_pause(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
struct ath_hw *ah = sc->sc_ah;
|
|
|
|
|
|
|
|
del_timer_sync(&btcoex->period_timer);
|
|
|
|
|
|
|
|
if (btcoex->hw_timer_enabled)
|
|
|
|
ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
|
|
|
|
|
|
|
|
btcoex->hw_timer_enabled = false;
|
|
|
|
}
|