Release 4.7 drivers/net/wireless/ath/ath9k/htc_drv_gpio.c
  
  
/*
 * Copyright (c) 2010-2011 Atheros Communications Inc.
 *
 * 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 "htc.h"
/******************/
/*     BTCOEX     */
/******************/
#define ATH_HTC_BTCOEX_PRODUCT_ID "wb193"
#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
/*
 * Detects if there is any priority bt traffic
 */
static void ath_detect_bt_priority(struct ath9k_htc_priv *priv)
{
	struct ath_btcoex *btcoex = &priv->btcoex;
	struct ath_hw *ah = priv->ah;
	if (ath9k_hw_gpio_get(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))) {
		clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
		clear_bit(OP_BT_SCAN, &priv->op_flags);
		/* Detect if colocated bt started scanning */
		if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
			ath_dbg(ath9k_hw_common(ah), BTCOEX,
				"BT scan detected\n");
			set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
			set_bit(OP_BT_SCAN, &priv->op_flags);
		} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
			ath_dbg(ath9k_hw_common(ah), BTCOEX,
				"BT priority traffic detected\n");
			set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
		}
		btcoex->bt_priority_cnt = 0;
		btcoex->bt_priority_time = jiffies;
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| vivek natarajan | vivek natarajan | 132 | 75.86% | 1 | 25.00% | 
| sujith manoharan | sujith manoharan | 36 | 20.69% | 1 | 25.00% | 
| joe perches | joe perches | 6 | 3.45% | 2 | 50.00% | 
 | Total | 174 | 100.00% | 4 | 100.00% | 
/*
 * This is the master bt coex work 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_work(struct work_struct *work)
{
	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
						   coex_period_work.work);
	struct ath_btcoex *btcoex = &priv->btcoex;
	struct ath_common *common = ath9k_hw_common(priv->ah);
	u32 timer_period;
	int ret;
	ath_detect_bt_priority(priv);
	ret = ath9k_htc_update_cap_target(priv,
			  test_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags));
	if (ret) {
		ath_err(common, "Unable to set BTCOEX parameters\n");
		return;
	}
	ath9k_hw_btcoex_bt_stomp(priv->ah, test_bit(OP_BT_SCAN, &priv->op_flags) ?
				 ATH_BTCOEX_STOMP_ALL : btcoex->bt_stomp_type);
	ath9k_hw_btcoex_enable(priv->ah);
	timer_period = test_bit(OP_BT_SCAN, &priv->op_flags) ?
		btcoex->btscan_no_stomp : btcoex->btcoex_no_stomp;
	ieee80211_queue_delayed_work(priv->hw, &priv->duty_cycle_work,
				     msecs_to_jiffies(timer_period));
	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work,
				     msecs_to_jiffies(btcoex->btcoex_period));
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| vivek natarajan | vivek natarajan | 128 | 71.91% | 2 | 33.33% | 
| sujith manoharan | sujith manoharan | 43 | 24.16% | 3 | 50.00% | 
| rajkumar manoharan | rajkumar manoharan | 7 | 3.93% | 1 | 16.67% | 
 | Total | 178 | 100.00% | 6 | 100.00% | 
/*
 * Work to time slice between wlan and bt traffic and
 * configure weight registers
 */
static void ath_btcoex_duty_cycle_work(struct work_struct *work)
{
	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
						   duty_cycle_work.work);
	struct ath_hw *ah = priv->ah;
	struct ath_btcoex *btcoex = &priv->btcoex;
	struct ath_common *common = ath9k_hw_common(ah);
	ath_dbg(common, BTCOEX, "time slice work for bt and wlan\n");
	if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW ||
	    test_bit(OP_BT_SCAN, &priv->op_flags))
		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
	else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
	ath9k_hw_btcoex_enable(priv->ah);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| vivek natarajan | vivek natarajan | 96 | 84.21% | 2 | 33.33% | 
| sujith manoharan | sujith manoharan | 9 | 7.89% | 1 | 16.67% | 
| rajkumar manoharan | rajkumar manoharan | 7 | 6.14% | 1 | 16.67% | 
| joe perches | joe perches | 2 | 1.75% | 2 | 33.33% | 
 | Total | 114 | 100.00% | 6 | 100.00% | 
static void ath_htc_init_btcoex_work(struct ath9k_htc_priv *priv)
{
	struct ath_btcoex *btcoex = &priv->btcoex;
	btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD;
	btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
		btcoex->btcoex_period / 100;
	btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
				   btcoex->btcoex_period / 100;
	INIT_DELAYED_WORK(&priv->coex_period_work, ath_btcoex_period_work);
	INIT_DELAYED_WORK(&priv->duty_cycle_work, ath_btcoex_duty_cycle_work);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| vivek natarajan | vivek natarajan | 78 | 98.73% | 1 | 50.00% | 
| sujith manoharan | sujith manoharan | 1 | 1.27% | 1 | 50.00% | 
 | Total | 79 | 100.00% | 2 | 100.00% | 
/*
 * (Re)start btcoex work
 */
static void ath_htc_resume_btcoex_work(struct ath9k_htc_priv *priv)
{
	struct ath_btcoex *btcoex = &priv->btcoex;
	struct ath_hw *ah = priv->ah;
	ath_dbg(ath9k_hw_common(ah), BTCOEX, "Starting btcoex work\n");
	btcoex->bt_priority_cnt = 0;
	btcoex->bt_priority_time = jiffies;
	clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
	clear_bit(OP_BT_SCAN, &priv->op_flags);
	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 0);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| vivek natarajan | vivek natarajan | 69 | 78.41% | 1 | 20.00% | 
| sujith manoharan | sujith manoharan | 16 | 18.18% | 2 | 40.00% | 
| joe perches | joe perches | 3 | 3.41% | 2 | 40.00% | 
 | Total | 88 | 100.00% | 5 | 100.00% | 
/*
 * Cancel btcoex and bt duty cycle work.
 */
static void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv)
{
	cancel_delayed_work_sync(&priv->coex_period_work);
	cancel_delayed_work_sync(&priv->duty_cycle_work);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| vivek natarajan | vivek natarajan | 26 | 96.30% | 1 | 50.00% | 
| sujith manoharan | sujith manoharan | 1 | 3.70% | 1 | 50.00% | 
 | Total | 27 | 100.00% | 2 | 100.00% | 
void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv)
{
	struct ath_hw *ah = priv->ah;
	if (ath9k_hw_get_btcoex_scheme(ah) == ATH_BTCOEX_CFG_3WIRE) {
		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
					   AR_STOMP_LOW_WLAN_WGHT, 0);
		ath9k_hw_btcoex_enable(ah);
		ath_htc_resume_btcoex_work(priv);
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 51 | 100.00% | 2 | 100.00% | 
 | Total | 51 | 100.00% | 2 | 100.00% | 
void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv)
{
	struct ath_hw *ah = priv->ah;
	if (ah->btcoex_hw.enabled &&
	    ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) {
		if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
			ath_htc_cancel_btcoex_work(priv);
		ath9k_hw_btcoex_disable(ah);
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 51 | 91.07% | 1 | 50.00% | 
| mohammed shafi shajakhan | mohammed shafi shajakhan | 5 | 8.93% | 1 | 50.00% | 
 | Total | 56 | 100.00% | 2 | 100.00% | 
void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product)
{
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
	int qnum;
	/*
         * Check if BTCOEX is globally disabled.
         */
	if (!common->btcoex_enabled) {
		ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_NONE;
		return;
	}
	if (product && strncmp(product, ATH_HTC_BTCOEX_PRODUCT_ID, 5) == 0) {
		ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_3WIRE;
	}
	switch (ath9k_hw_get_btcoex_scheme(priv->ah)) {
	case ATH_BTCOEX_CFG_NONE:
		break;
	case ATH_BTCOEX_CFG_3WIRE:
		priv->ah->btcoex_hw.btactive_gpio = 7;
		priv->ah->btcoex_hw.btpriority_gpio = 6;
		priv->ah->btcoex_hw.wlanactive_gpio = 8;
		priv->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
		ath9k_hw_btcoex_init_3wire(priv->ah);
		ath_htc_init_btcoex_work(priv);
		qnum = priv->hwq_map[IEEE80211_AC_BE];
		ath9k_hw_init_btcoex_hw(priv->ah, qnum);
		break;
	default:
		WARN_ON(1);
		break;
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 145 | 83.33% | 2 | 66.67% | 
| mohammed shafi shajakhan | mohammed shafi shajakhan | 29 | 16.67% | 1 | 33.33% | 
 | Total | 174 | 100.00% | 3 | 100.00% | 
#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
/*******/
/* LED */
/*******/
#ifdef CONFIG_MAC80211_LEDS
void ath9k_led_work(struct work_struct *work)
{
	struct ath9k_htc_priv *priv = container_of(work,
						   struct ath9k_htc_priv,
						   led_work);
	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
			  (priv->brightness == LED_OFF));
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 46 | 100.00% | 2 | 100.00% | 
 | Total | 46 | 100.00% | 2 | 100.00% | 
static void ath9k_led_brightness(struct led_classdev *led_cdev,
				 enum led_brightness brightness)
{
	struct ath9k_htc_priv *priv = container_of(led_cdev,
						   struct ath9k_htc_priv,
						   led_cdev);
	/* Not locked, but it's just a tiny green light..*/
	priv->brightness = brightness;
	ieee80211_queue_work(priv->hw, &priv->led_work);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 49 | 100.00% | 2 | 100.00% | 
 | Total | 49 | 100.00% | 2 | 100.00% | 
void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
{
	if (!priv->led_registered)
		return;
	ath9k_led_brightness(&priv->led_cdev, LED_OFF);
	led_classdev_unregister(&priv->led_cdev);
	cancel_work_sync(&priv->led_work);
	ath9k_hw_gpio_free(priv->ah, priv->ah->led_pin);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 44 | 77.19% | 2 | 66.67% | 
| miaoqing pan | miaoqing pan | 13 | 22.81% | 1 | 33.33% | 
 | Total | 57 | 100.00% | 3 | 100.00% | 
void ath9k_configure_leds(struct ath9k_htc_priv *priv)
{
	/* Configure gpio 1 for output */
	ath9k_hw_gpio_request_out(priv->ah, priv->ah->led_pin,
				  "ath9k-led",
				  AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
	/* LED off, active low */
	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| oleksij rempel | oleksij rempel | 41 | 93.18% | 1 | 50.00% | 
| miaoqing pan | miaoqing pan | 3 | 6.82% | 1 | 50.00% | 
 | Total | 44 | 100.00% | 2 | 100.00% | 
void ath9k_init_leds(struct ath9k_htc_priv *priv)
{
	int ret;
	if (AR_SREV_9287(priv->ah))
		priv->ah->led_pin = ATH_LED_PIN_9287;
	else if (AR_SREV_9271(priv->ah))
		priv->ah->led_pin = ATH_LED_PIN_9271;
	else if (AR_DEVID_7010(priv->ah))
		priv->ah->led_pin = ATH_LED_PIN_7010;
	else
		priv->ah->led_pin = ATH_LED_PIN_DEF;
	if (!ath9k_htc_led_blink)
		priv->led_cdev.default_trigger =
			ieee80211_get_radio_led_name(priv->hw);
	ath9k_configure_leds(priv);
	snprintf(priv->led_name, sizeof(priv->led_name),
		"ath9k_htc-%s", wiphy_name(priv->hw->wiphy));
	priv->led_cdev.name = priv->led_name;
	priv->led_cdev.brightness_set = ath9k_led_brightness;
	ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &priv->led_cdev);
	if (ret < 0)
		return;
	INIT_WORK(&priv->led_work, ath9k_led_work);
	priv->led_registered = true;
	return;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 165 | 89.67% | 2 | 40.00% | 
| eric xu | eric xu | 18 | 9.78% | 2 | 40.00% | 
| oleksij rempel | oleksij rempel | 1 | 0.54% | 1 | 20.00% | 
 | Total | 184 | 100.00% | 5 | 100.00% | 
#endif
/*******************/
/*      Rfkill     */
/*******************/
static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
{
	bool is_blocked;
	ath9k_htc_ps_wakeup(priv);
	is_blocked = ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
						 priv->ah->rfkill_polarity;
	ath9k_htc_ps_restore(priv);
	return is_blocked;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 30 | 62.50% | 1 | 50.00% | 
| mohammed shafi shajakhan | mohammed shafi shajakhan | 18 | 37.50% | 1 | 50.00% | 
 | Total | 48 | 100.00% | 2 | 100.00% | 
void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
{
	struct ath9k_htc_priv *priv = hw->priv;
	bool blocked = !!ath_is_rfkill_set(priv);
	wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 38 | 100.00% | 1 | 100.00% | 
 | Total | 38 | 100.00% | 1 | 100.00% | 
void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
{
	if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
		wiphy_rfkill_start_polling(priv->hw->wiphy);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 31 | 100.00% | 1 | 100.00% | 
 | Total | 31 | 100.00% | 1 | 100.00% | 
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| sujith manoharan | sujith manoharan | 778 | 52.89% | 11 | 45.83% | 
| vivek natarajan | vivek natarajan | 540 | 36.71% | 2 | 8.33% | 
| mohammed shafi shajakhan | mohammed shafi shajakhan | 52 | 3.54% | 3 | 12.50% | 
| oleksij rempel | oleksij rempel | 42 | 2.86% | 1 | 4.17% | 
| eric xu | eric xu | 18 | 1.22% | 2 | 8.33% | 
| miaoqing pan | miaoqing pan | 16 | 1.09% | 2 | 8.33% | 
| rajkumar manoharan | rajkumar manoharan | 14 | 0.95% | 1 | 4.17% | 
| joe perches | joe perches | 11 | 0.75% | 2 | 8.33% | 
 | Total | 1471 | 100.00% | 24 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.