gpio.c revision bc6d5c29afa724901c2feb7e4446c6eec7788cec
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;
51423e38e8079f8f4fe0bf66d4f9a7d61beb232acaRajkumar Manoharan		else if (AR_SREV_9462(sc->sc_ah))
52423e38e8079f8f4fe0bf66d4f9a7d61beb232acaRajkumar Manoharan			sc->sc_ah->led_pin = ATH_LED_PIN_9462;
536de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau		else
546de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau			sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
556de66dd963ddd669667a81a2401f2fd6472ff55cFelix Fietkau	}
560fca65c1c0569d6a143e978b6f4974c519033e63Sujith
570fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* Configure gpio 1 for output */
580fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
590fca65c1c0569d6a143e978b6f4974c519033e63Sujith			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
600fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* LED off, active low */
610fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
620fca65c1c0569d6a143e978b6f4974c519033e63Sujith
630cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	if (!led_blink)
640cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		sc->led_cdev.default_trigger =
650cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau			ieee80211_get_radio_led_name(sc->hw);
660cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
670cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	snprintf(sc->led_name, sizeof(sc->led_name),
680cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		"ath9k-%s", wiphy_name(sc->hw->wiphy));
690cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	sc->led_cdev.name = sc->led_name;
700cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	sc->led_cdev.brightness_set = ath_led_brightness;
710cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
720cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
730cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	if (ret < 0)
740cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau		return;
750cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau
760cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau	sc->led_registered = true;
770fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
780cf55c21ec401632043db2b8acb7cd3bef64c9e6Felix Fietkau#endif
790fca65c1c0569d6a143e978b6f4974c519033e63Sujith
800fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*******************/
810fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*	Rfkill	   */
820fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*******************/
830fca65c1c0569d6a143e978b6f4974c519033e63Sujith
840fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic bool ath_is_rfkill_set(struct ath_softc *sc)
850fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
860fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
8790826313fd69d198da7574779460f793765abfa5Mohammed Shafi Shajakhan	bool is_blocked;
880fca65c1c0569d6a143e978b6f4974c519033e63Sujith
8990826313fd69d198da7574779460f793765abfa5Mohammed Shafi Shajakhan	ath9k_ps_wakeup(sc);
9090826313fd69d198da7574779460f793765abfa5Mohammed Shafi Shajakhan	is_blocked = ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
910fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  ah->rfkill_polarity;
9290826313fd69d198da7574779460f793765abfa5Mohammed Shafi Shajakhan	ath9k_ps_restore(sc);
9390826313fd69d198da7574779460f793765abfa5Mohammed Shafi Shajakhan
9490826313fd69d198da7574779460f793765abfa5Mohammed Shafi Shajakhan	return is_blocked;
950fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
960fca65c1c0569d6a143e978b6f4974c519033e63Sujith
970fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
980fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
999ac58615d93c8a28b1c649a90a5e2ede4dfd368aFelix Fietkau	struct ath_softc *sc = hw->priv;
1000fca65c1c0569d6a143e978b6f4974c519033e63Sujith	bool blocked = !!ath_is_rfkill_set(sc);
1010fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1020fca65c1c0569d6a143e978b6f4974c519033e63Sujith	wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1030fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1040fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1050fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath_start_rfkill_poll(struct ath_softc *sc)
1060fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1070fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
1080fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1090fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1100fca65c1c0569d6a143e978b6f4974c519033e63Sujith		wiphy_rfkill_start_polling(sc->hw->wiphy);
1110fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1120fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1130fca65c1c0569d6a143e978b6f4974c519033e63Sujith/******************/
1140fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*     BTCOEX     */
1150fca65c1c0569d6a143e978b6f4974c519033e63Sujith/******************/
1160fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1170fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
1180fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Detects if there is any priority bt traffic
1190fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
1200fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_detect_bt_priority(struct ath_softc *sc)
1210fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1220fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
1230fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
1240fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1250fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
1260fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->bt_priority_cnt++;
1270fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1280fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (time_after(jiffies, btcoex->bt_priority_time +
1290fca65c1c0569d6a143e978b6f4974c519033e63Sujith			msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
13058da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
13158da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		/* Detect if colocated bt started scanning */
13258da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
133226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches			ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
134226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches				"BT scan detected\n");
13558da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan			sc->sc_flags |= (SC_OP_BT_SCAN |
13658da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan					 SC_OP_BT_PRIORITY_DETECTED);
13758da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
138226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches			ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
139226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches				"BT priority traffic detected\n");
1400fca65c1c0569d6a143e978b6f4974c519033e63Sujith			sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1410fca65c1c0569d6a143e978b6f4974c519033e63Sujith		}
1420fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1430fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->bt_priority_cnt = 0;
1440fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->bt_priority_time = jiffies;
1450fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
1460fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1470fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1480fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath9k_gen_timer_start(struct ath_hw *ah,
1490fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  struct ath_gen_timer *timer,
150788f6875fcf5d2bce221fbfd2318ac48df299031Vasanthakumar Thiagarajan				  u32 trig_timeout,
1510fca65c1c0569d6a143e978b6f4974c519033e63Sujith				  u32 timer_period)
1520fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
153788f6875fcf5d2bce221fbfd2318ac48df299031Vasanthakumar Thiagarajan	ath9k_hw_gen_timer_start(ah, timer, trig_timeout, timer_period);
1540fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1553069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin	if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
1564df3071ebd92ef7115b409da64d0eb405d24a631Felix Fietkau		ath9k_hw_disable_interrupts(ah);
1573069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin		ah->imask |= ATH9K_INT_GENTIMER;
15872d874c67c3cdf21ca95045baabac6a5843222d8Felix Fietkau		ath9k_hw_set_interrupts(ah);
159b037b693265e5c83ddc3f003a713d19b9832bf24Rajkumar Manoharan		ath9k_hw_enable_interrupts(ah);
1600fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
1610fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1620fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1630fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
1640fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1650fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
1660fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1670fca65c1c0569d6a143e978b6f4974c519033e63Sujith	ath9k_hw_gen_timer_stop(ah, timer);
1680fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1690fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* if no timer is enabled, turn off interrupt mask */
1700fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (timer_table->timer_mask.val == 0) {
1714df3071ebd92ef7115b409da64d0eb405d24a631Felix Fietkau		ath9k_hw_disable_interrupts(ah);
1723069168c82d65f88e4ac76eda09baff02adfd743Pavel Roskin		ah->imask &= ~ATH9K_INT_GENTIMER;
17372d874c67c3cdf21ca95045baabac6a5843222d8Felix Fietkau		ath9k_hw_set_interrupts(ah);
174b037b693265e5c83ddc3f003a713d19b9832bf24Rajkumar Manoharan		ath9k_hw_enable_interrupts(ah);
1750fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
1760fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
1770fca65c1c0569d6a143e978b6f4974c519033e63Sujith
1780fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
1790fca65c1c0569d6a143e978b6f4974c519033e63Sujith * This is the master bt coex timer which runs for every
1800fca65c1c0569d6a143e978b6f4974c519033e63Sujith * 45ms, bt traffic will be given priority during 55% of this
1810fca65c1c0569d6a143e978b6f4974c519033e63Sujith * period while wlan gets remaining 45%
1820fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
1830fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_btcoex_period_timer(unsigned long data)
1840fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
1850fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_softc *sc = (struct ath_softc *) data;
1860fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
1870fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
18858da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	u32 timer_period;
18958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	bool is_btscan;
1900fca65c1c0569d6a143e978b6f4974c519033e63Sujith
191a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_wakeup(sc);
1927dc181c273861c4d96991f59a4fdcda3a3eaccaeRajkumar Manoharan	if (!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI))
1937dc181c273861c4d96991f59a4fdcda3a3eaccaeRajkumar Manoharan		ath_detect_bt_priority(sc);
19458da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
19558da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan
1960fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_lock_bh(&btcoex->btcoex_lock);
1970fca65c1c0569d6a143e978b6f4974c519033e63Sujith
198978f78bf71372a48785ac9407ebc10170f14f56cVivek Natarajan	ath9k_hw_btcoex_bt_stomp(ah, is_btscan ? ATH_BTCOEX_STOMP_ALL :
19958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan			      btcoex->bt_stomp_type);
2000fca65c1c0569d6a143e978b6f4974c519033e63Sujith
201bc6d5c29afa724901c2feb7e4446c6eec7788cecRajkumar Manoharan	ath9k_hw_btcoex_enable(ah);
2020fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_unlock_bh(&btcoex->btcoex_lock);
2030fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2040fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
2050fca65c1c0569d6a143e978b6f4974c519033e63Sujith		if (btcoex->hw_timer_enabled)
2060fca65c1c0569d6a143e978b6f4974c519033e63Sujith			ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
2070fca65c1c0569d6a143e978b6f4974c519033e63Sujith
20858da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan		timer_period = is_btscan ? btcoex->btscan_no_stomp :
20958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan					   btcoex->btcoex_no_stomp;
210788f6875fcf5d2bce221fbfd2318ac48df299031Vasanthakumar Thiagarajan		ath9k_gen_timer_start(ah, btcoex->no_stomp_timer, timer_period,
2118eb1dabbd10e067cff671935d3e0c819f8e80d54Felix Fietkau				      timer_period * 10);
2120fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->hw_timer_enabled = true;
2130fca65c1c0569d6a143e978b6f4974c519033e63Sujith	}
2140fca65c1c0569d6a143e978b6f4974c519033e63Sujith
215a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_restore(sc);
2167dc181c273861c4d96991f59a4fdcda3a3eaccaeRajkumar Manoharan	timer_period = btcoex->btcoex_period / 1000;
2170fca65c1c0569d6a143e978b6f4974c519033e63Sujith	mod_timer(&btcoex->period_timer, jiffies +
2187dc181c273861c4d96991f59a4fdcda3a3eaccaeRajkumar Manoharan				  msecs_to_jiffies(timer_period));
2190fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2200fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2210fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
2220fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Generic tsf based hw timer which configures weight
2230fca65c1c0569d6a143e978b6f4974c519033e63Sujith * registers to time slice between wlan and bt traffic
2240fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
2250fca65c1c0569d6a143e978b6f4974c519033e63Sujithstatic void ath_btcoex_no_stomp_timer(void *arg)
2260fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2270fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_softc *sc = (struct ath_softc *)arg;
2280fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
2290fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
230d99eeb87420a6da1f87064c7fa70bdf299699d90Vivek Natarajan	struct ath_common *common = ath9k_hw_common(ah);
23158da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	bool is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
2320fca65c1c0569d6a143e978b6f4974c519033e63Sujith
233226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches	ath_dbg(common, ATH_DBG_BTCOEX,
234226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches		"no stomp timer running\n");
2350fca65c1c0569d6a143e978b6f4974c519033e63Sujith
236a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_wakeup(sc);
2370fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_lock_bh(&btcoex->btcoex_lock);
2380fca65c1c0569d6a143e978b6f4974c519033e63Sujith
23958da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan)
240978f78bf71372a48785ac9407ebc10170f14f56cVivek Natarajan		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
2410fca65c1c0569d6a143e978b6f4974c519033e63Sujith	 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
242978f78bf71372a48785ac9407ebc10170f14f56cVivek Natarajan		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
2430fca65c1c0569d6a143e978b6f4974c519033e63Sujith
244bc6d5c29afa724901c2feb7e4446c6eec7788cecRajkumar Manoharan	ath9k_hw_btcoex_enable(ah);
2450fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_unlock_bh(&btcoex->btcoex_lock);
246a039a993496d79d09ae9709c82b545b9800954c9Vivek Natarajan	ath9k_ps_restore(sc);
2470fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2480fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2490fca65c1c0569d6a143e978b6f4974c519033e63Sujithint ath_init_btcoex_timer(struct ath_softc *sc)
2500fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2510fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
2520fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2530fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
2540fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
2550fca65c1c0569d6a143e978b6f4974c519033e63Sujith		btcoex->btcoex_period / 100;
25658da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
25758da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan				   btcoex->btcoex_period / 100;
2580fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2590fca65c1c0569d6a143e978b6f4974c519033e63Sujith	setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
2600fca65c1c0569d6a143e978b6f4974c519033e63Sujith			(unsigned long) sc);
2610fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2620fca65c1c0569d6a143e978b6f4974c519033e63Sujith	spin_lock_init(&btcoex->btcoex_lock);
2630fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2640fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
2650fca65c1c0569d6a143e978b6f4974c519033e63Sujith			ath_btcoex_no_stomp_timer,
2660fca65c1c0569d6a143e978b6f4974c519033e63Sujith			ath_btcoex_no_stomp_timer,
2670fca65c1c0569d6a143e978b6f4974c519033e63Sujith			(void *) sc, AR_FIRST_NDP_TIMER);
2680fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2690fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (!btcoex->no_stomp_timer)
2700fca65c1c0569d6a143e978b6f4974c519033e63Sujith		return -ENOMEM;
2710fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2720fca65c1c0569d6a143e978b6f4974c519033e63Sujith	return 0;
2730fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2740fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2750fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
2760fca65c1c0569d6a143e978b6f4974c519033e63Sujith * (Re)start btcoex timers
2770fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
2780fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath9k_btcoex_timer_resume(struct ath_softc *sc)
2790fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
2800fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
2810fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
2820fca65c1c0569d6a143e978b6f4974c519033e63Sujith
283226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches	ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
284226afe68fdbd1aa3680158aca0a3631cbd019626Joe Perches		"Starting btcoex timers\n");
2850fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2860fca65c1c0569d6a143e978b6f4974c519033e63Sujith	/* make sure duty cycle timer is also stopped when resuming */
2870fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (btcoex->hw_timer_enabled)
2880fca65c1c0569d6a143e978b6f4974c519033e63Sujith		ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
2890fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2900fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->bt_priority_cnt = 0;
2910fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->bt_priority_time = jiffies;
29258da1318ee92ad3fe7917278d596768bbe441850Vasanthakumar Thiagarajan	sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
2930fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2940fca65c1c0569d6a143e978b6f4974c519033e63Sujith	mod_timer(&btcoex->period_timer, jiffies);
2950fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
2960fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2970fca65c1c0569d6a143e978b6f4974c519033e63Sujith
2980fca65c1c0569d6a143e978b6f4974c519033e63Sujith/*
2990fca65c1c0569d6a143e978b6f4974c519033e63Sujith * Pause btcoex timer and bt duty cycle timer
3000fca65c1c0569d6a143e978b6f4974c519033e63Sujith */
3010fca65c1c0569d6a143e978b6f4974c519033e63Sujithvoid ath9k_btcoex_timer_pause(struct ath_softc *sc)
3020fca65c1c0569d6a143e978b6f4974c519033e63Sujith{
3030fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_btcoex *btcoex = &sc->btcoex;
3040fca65c1c0569d6a143e978b6f4974c519033e63Sujith	struct ath_hw *ah = sc->sc_ah;
3050fca65c1c0569d6a143e978b6f4974c519033e63Sujith
3060fca65c1c0569d6a143e978b6f4974c519033e63Sujith	del_timer_sync(&btcoex->period_timer);
3070fca65c1c0569d6a143e978b6f4974c519033e63Sujith
3080fca65c1c0569d6a143e978b6f4974c519033e63Sujith	if (btcoex->hw_timer_enabled)
3090fca65c1c0569d6a143e978b6f4974c519033e63Sujith		ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
3100fca65c1c0569d6a143e978b6f4974c519033e63Sujith
3110fca65c1c0569d6a143e978b6f4974c519033e63Sujith	btcoex->hw_timer_enabled = false;
3120fca65c1c0569d6a143e978b6f4974c519033e63Sujith}
313