gpio.c revision 5b68138e5659cbfd5df2879d17f9ba0b66477fec
10fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
25b68138e5659cbfd5df2879d17f9ba0b66477fecSujith Manoharan * Copyright (c) 2008-2011 Atheros Communications Inc.
30fca65c1c0569d6a143e978b6f4974c519033e63Sujith *
40fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Permission to use, copy, modify, and/or distribute this software for any
50fca65c1c0569d6a143e978b6f4974c519033e63Sujith * purpose with or without fee is hereby granted, provided that the above
60fca65c1c0569d6a143e978b6f4974c519033e63Sujith * copyright notice and this permission notice appear in all copies.
70fca65c1c0569d6a143e978b6f4974c519033e63Sujith *
80fca65c1c0569d6a143e978b6f4974c519033e63Sujith * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
90fca65c1c0569d6a143e978b6f4974c519033e63Sujith * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
100fca65c1c0569d6a143e978b6f4974c519033e63Sujith * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
110fca65c1c0569d6a143e978b6f4974c519033e63Sujith * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
120fca65c1c0569d6a143e978b6f4974c519033e63Sujith * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
130fca65c1c0569d6a143e978b6f4974c519033e63Sujith * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
140fca65c1c0569d6a143e978b6f4974c519033e63Sujith * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
150fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
160fca65c1c0569d6a143e978b6f4974c519033e63Sujith
170fca65c1c0569d6a143e978b6f4974c519033e63Sujith#include "ath9k.h"
180fca65c1c0569d6a143e978b6f4974c519033e63Sujith
190fca65c1c0569d6a143e978b6f4974c519033e63Sujith/********************************/
200fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*	 LED functions		*/
210fca65c1c0569d6a143e978b6f4974c519033e63Sujith/********************************/
220fca65c1c0569d6a143e978b6f4974c519033e63Sujith
230cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau#ifdef CONFIG_MAC80211_LEDS
240fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_led_brightness(struct led_classdev *led_cdev,
250fca65c1c0569d6a143e978b6f4974c519033e63Sujith			       enum led_brightness brightness)
260fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
270cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
280cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
290fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
300fca65c1c0569d6a143e978b6f4974c519033e63Sujith
310fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath_deinit_leds(struct ath_softc *sc)
320fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
330cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	if (!sc->led_registered)
340cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		return;
350cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
360cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	ath_led_brightness(&sc->led_cdev, LED_OFF);
370cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	led_classdev_unregister(&sc->led_cdev);
380fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
390fca65c1c0569d6a143e978b6f4974c519033e63Sujith
400fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath_init_leds(struct ath_softc *sc)
410fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
420fca65c1c0569d6a143e978b6f4974c519033e63Sujith	int ret;
430fca65c1c0569d6a143e978b6f4974c519033e63Sujith
446de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau	if (sc->sc_ah->led_pin < 0) {
456de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau		if (AR_SREV_9287(sc->sc_ah))
466de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau			sc->sc_ah->led_pin = ATH_LED_PIN_9287;
476de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau		else if (AR_SREV_9485(sc->sc_ah))
486de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau			sc->sc_ah->led_pin = ATH_LED_PIN_9485;
49353e5019e048562dc8f434c6237d41ef5e758922Senthil Balasubramanian		else if (AR_SREV_9300(sc->sc_ah))
50353e5019e048562dc8f434c6237d41ef5e758922Senthil Balasubramanian			sc->sc_ah->led_pin = ATH_LED_PIN_9300;
516de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau		else
526de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau			sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
536de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau	}
540fca65c1c0569d6a143e978b6f4974c519033e63Sujith
550fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* Configure gpio 1 for output */
560fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
570fca65c1c0569d6a143e978b6f4974c519033e63Sujith			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
580fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* LED off, active low */
590fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
600fca65c1c0569d6a143e978b6f4974c519033e63Sujith
610cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	if (!led_blink)
620cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		sc->led_cdev.default_trigger =
630cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau			ieee80211_get_radio_led_name(sc->hw);
640cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
650cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	snprintf(sc->led_name, sizeof(sc->led_name),
660cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		"ath9k-%s", wiphy_name(sc->hw->wiphy));
670cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	sc->led_cdev.name = sc->led_name;
680cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	sc->led_cdev.brightness_set = ath_led_brightness;
690cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
700cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
710cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	if (ret < 0)
720cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		return;
730cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
740cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	sc->led_registered = true;
750fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
760cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau#endif
770fca65c1c0569d6a143e978b6f4974c519033e63Sujith
780fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*******************/
790fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*	Rfkill	   */
800fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*******************/
810fca65c1c0569d6a143e978b6f4974c519033e63Sujith
820fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic bool ath_is_rfkill_set(struct ath_softc *sc)
830fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
840fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
850fca65c1c0569d6a143e978b6f4974c519033e63Sujith
860fca65c1c0569d6a143e978b6f4974c519033e63Sujith	return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
870fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  ah->rfkill_polarity;
880fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
890fca65c1c0569d6a143e978b6f4974c519033e63Sujith
900fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
910fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
929ac58615d93c8a28b1c649a90a5e2ede4dfd368aFelix Fietkau	struct ath_softc *sc = hw->priv;
930fca65c1c0569d6a143e978b6f4974c519033e63Sujith	bool blocked = !!ath_is_rfkill_set(sc);
940fca65c1c0569d6a143e978b6f4974c519033e63Sujith
950fca65c1c0569d6a143e978b6f4974c519033e63Sujith	wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
960fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
970fca65c1c0569d6a143e978b6f4974c519033e63Sujith
980fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath_start_rfkill_poll(struct ath_softc *sc)
990fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1000fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
1010fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1020fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1030fca65c1c0569d6a143e978b6f4974c519033e63Sujith		wiphy_rfkill_start_polling(sc->hw->wiphy);
1040fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1050fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1060fca65c1c0569d6a143e978b6f4974c519033e63Sujith/******************/
1070fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*     BTCOEX     */
1080fca65c1c0569d6a143e978b6f4974c519033e63Sujith/******************/
1090fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1100fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
1110fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Detects if there is any priority bt traffic
1120fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
1130fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_detect_bt_priority(struct ath_softc *sc)
1140fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1150fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
1160fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
1170fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1180fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
1190fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->bt_priority_cnt++;
1200fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1210fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (time_after(jiffies, btcoex->bt_priority_time +
1220fca65c1c0569d6a143e978b6f4974c519033e63Sujith			msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
12358da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
12458da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		/* Detect if colocated bt started scanning */
12558da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
126226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches			ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
127226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches				"BT scan detected\n");
12858da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan			sc->sc_flags |= (SC_OP_BT_SCAN |
12958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan					 SC_OP_BT_PRIORITY_DETECTED);
13058da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
131226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches			ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
132226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches				"BT priority traffic detected\n");
1330fca65c1c0569d6a143e978b6f4974c519033e63Sujith			sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1340fca65c1c0569d6a143e978b6f4974c519033e63Sujith		}
1350fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1360fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->bt_priority_cnt = 0;
1370fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->bt_priority_time = jiffies;
1380fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
1390fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1400fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1410fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath9k_gen_timer_start(struct ath_hw *ah,
1420fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  struct ath_gen_timer *timer,
143788f6875fcf5d2bce221fbfd2318ac48df299031Vasanthakumar Thiagarajan				  u32 trig_timeout,
1440fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  u32 timer_period)
1450fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
146788f6875fcf5d2bce221fbfd2318ac48df299031Vasanthakumar Thiagarajan	ath9k_hw_gen_timer_start(ah, timer, trig_timeout, timer_period);
1470fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1483069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin	if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
1494df3071ebd92ef7115b409da64d0eb405d24a631Felix Fietkau		ath9k_hw_disable_interrupts(ah);
1503069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin		ah->imask |= ATH9K_INT_GENTIMER;
1513069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin		ath9k_hw_set_interrupts(ah, ah->imask);
1520fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
1530fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1540fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1550fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
1560fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1570fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
1580fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1590fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath9k_hw_gen_timer_stop(ah, timer);
1600fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1610fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* if no timer is enabled, turn off interrupt mask */
1620fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (timer_table->timer_mask.val == 0) {
1634df3071ebd92ef7115b409da64d0eb405d24a631Felix Fietkau		ath9k_hw_disable_interrupts(ah);
1643069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin		ah->imask &= ~ATH9K_INT_GENTIMER;
1653069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin		ath9k_hw_set_interrupts(ah, ah->imask);
1660fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
1670fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1680fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1690fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
1700fca65c1c0569d6a143e978b6f4974c519033e63Sujith * This is the master bt coex timer which runs for every
1710fca65c1c0569d6a143e978b6f4974c519033e63Sujith * 45ms, bt traffic will be given priority during 55% of this
1720fca65c1c0569d6a143e978b6f4974c519033e63Sujith * period while wlan gets remaining 45%
1730fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
1740fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_btcoex_period_timer(unsigned long data)
1750fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1760fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_softc *sc = (struct ath_softc *) data;
1770fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
1780fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
17958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	u32 timer_period;
18058da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	bool is_btscan;
1810fca65c1c0569d6a143e978b6f4974c519033e63Sujith
182a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_wakeup(sc);
1830fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath_detect_bt_priority(sc);
1840fca65c1c0569d6a143e978b6f4974c519033e63Sujith
18558da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
18658da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan
1870fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_lock_bh(&btcoex->btcoex_lock);
1880fca65c1c0569d6a143e978b6f4974c519033e63Sujith
189978f78bf71372a48785ac9407ebc10170f14f56cVivek Natarajan	ath9k_hw_btcoex_bt_stomp(ah, is_btscan ? ATH_BTCOEX_STOMP_ALL :
19058da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan			      btcoex->bt_stomp_type);
1910fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1920fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_unlock_bh(&btcoex->btcoex_lock);
1930fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1940fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
1950fca65c1c0569d6a143e978b6f4974c519033e63Sujith		if (btcoex->hw_timer_enabled)
1960fca65c1c0569d6a143e978b6f4974c519033e63Sujith			ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
1970fca65c1c0569d6a143e978b6f4974c519033e63Sujith
19858da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		timer_period = is_btscan ? btcoex->btscan_no_stomp :
19958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan					   btcoex->btcoex_no_stomp;
200788f6875fcf5d2bce221fbfd2318ac48df299031Vasanthakumar Thiagarajan		ath9k_gen_timer_start(ah, btcoex->no_stomp_timer, timer_period,
2018eb1dabbd10e067cff671935d3e0c819f8e80d54Felix Fietkau				      timer_period * 10);
2020fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->hw_timer_enabled = true;
2030fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
2040fca65c1c0569d6a143e978b6f4974c519033e63Sujith
205a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_restore(sc);
2060fca65c1c0569d6a143e978b6f4974c519033e63Sujith	mod_timer(&btcoex->period_timer, jiffies +
2070fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
2080fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2090fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2100fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
2110fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Generic tsf based hw timer which configures weight
2120fca65c1c0569d6a143e978b6f4974c519033e63Sujith * registers to time slice between wlan and bt traffic
2130fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
2140fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_btcoex_no_stomp_timer(void *arg)
2150fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2160fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_softc *sc = (struct ath_softc *)arg;
2170fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
2180fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
219d99eeb87420a6da1f87064c7fa70bdf299699d90Vivek Natarajan	struct ath_common *common = ath9k_hw_common(ah);
22058da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	bool is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
2210fca65c1c0569d6a143e978b6f4974c519033e63Sujith
222226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches	ath_dbg(common, ATH_DBG_BTCOEX,
223226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches		"no stomp timer running\n");
2240fca65c1c0569d6a143e978b6f4974c519033e63Sujith
225a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_wakeup(sc);
2260fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_lock_bh(&btcoex->btcoex_lock);
2270fca65c1c0569d6a143e978b6f4974c519033e63Sujith
22858da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan)
229978f78bf71372a48785ac9407ebc10170f14f56cVivek Natarajan		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
2300fca65c1c0569d6a143e978b6f4974c519033e63Sujith	 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
231978f78bf71372a48785ac9407ebc10170f14f56cVivek Natarajan		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
2320fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2330fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_unlock_bh(&btcoex->btcoex_lock);
234a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_restore(sc);
2350fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2360fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2370fca65c1c0569d6a143e978b6f4974c519033e63Sujithint ath_init_btcoex_timer(struct ath_softc *sc)
2380fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2390fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
2400fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2410fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
2420fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
2430fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->btcoex_period / 100;
24458da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
24558da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan				   btcoex->btcoex_period / 100;
2460fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2470fca65c1c0569d6a143e978b6f4974c519033e63Sujith	setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
2480fca65c1c0569d6a143e978b6f4974c519033e63Sujith			(unsigned long) sc);
2490fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2500fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_lock_init(&btcoex->btcoex_lock);
2510fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2520fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
2530fca65c1c0569d6a143e978b6f4974c519033e63Sujith			ath_btcoex_no_stomp_timer,
2540fca65c1c0569d6a143e978b6f4974c519033e63Sujith			ath_btcoex_no_stomp_timer,
2550fca65c1c0569d6a143e978b6f4974c519033e63Sujith			(void *) sc, AR_FIRST_NDP_TIMER);
2560fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2570fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (!btcoex->no_stomp_timer)
2580fca65c1c0569d6a143e978b6f4974c519033e63Sujith		return -ENOMEM;
2590fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2600fca65c1c0569d6a143e978b6f4974c519033e63Sujith	return 0;
2610fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2620fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2630fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
2640fca65c1c0569d6a143e978b6f4974c519033e63Sujith * (Re)start btcoex timers
2650fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
2660fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath9k_btcoex_timer_resume(struct ath_softc *sc)
2670fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2680fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
2690fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
2700fca65c1c0569d6a143e978b6f4974c519033e63Sujith
271226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches	ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
272226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches		"Starting btcoex timers\n");
2730fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2740fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* make sure duty cycle timer is also stopped when resuming */
2750fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (btcoex->hw_timer_enabled)
2760fca65c1c0569d6a143e978b6f4974c519033e63Sujith		ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
2770fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2780fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->bt_priority_cnt = 0;
2790fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->bt_priority_time = jiffies;
28058da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
2810fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2820fca65c1c0569d6a143e978b6f4974c519033e63Sujith	mod_timer(&btcoex->period_timer, jiffies);
2830fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2840fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2850fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2860fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
2870fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Pause btcoex timer and bt duty cycle timer
2880fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
2890fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath9k_btcoex_timer_pause(struct ath_softc *sc)
2900fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2910fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
2920fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
2930fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2940fca65c1c0569d6a143e978b6f4974c519033e63Sujith	del_timer_sync(&btcoex->period_timer);
2950fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2960fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (btcoex->hw_timer_enabled)
2970fca65c1c0569d6a143e978b6f4974c519033e63Sujith		ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
2980fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2990fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->hw_timer_enabled = false;
3000fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
301