xref: /linux/drivers/net/wireless/ath/ath9k/htc_drv_gpio.c (revision f26e8817b235d8764363bffcc9cbfc61867371f2)
11e1f4ad2SSujith Manoharan /*
25b68138eSSujith Manoharan  * Copyright (c) 2010-2011 Atheros Communications Inc.
31e1f4ad2SSujith Manoharan  *
41e1f4ad2SSujith Manoharan  * Permission to use, copy, modify, and/or distribute this software for any
51e1f4ad2SSujith Manoharan  * purpose with or without fee is hereby granted, provided that the above
61e1f4ad2SSujith Manoharan  * copyright notice and this permission notice appear in all copies.
71e1f4ad2SSujith Manoharan  *
81e1f4ad2SSujith Manoharan  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
91e1f4ad2SSujith Manoharan  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
101e1f4ad2SSujith Manoharan  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
111e1f4ad2SSujith Manoharan  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
121e1f4ad2SSujith Manoharan  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
131e1f4ad2SSujith Manoharan  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
141e1f4ad2SSujith Manoharan  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
151e1f4ad2SSujith Manoharan  */
161e1f4ad2SSujith Manoharan 
1721cb9879SVivek Natarajan #include "htc.h"
1821cb9879SVivek Natarajan 
1921cb9879SVivek Natarajan /******************/
2021cb9879SVivek Natarajan /*     BTCOEX     */
2121cb9879SVivek Natarajan /******************/
2221cb9879SVivek Natarajan 
23cee5341dSSujith Manoharan #define ATH_HTC_BTCOEX_PRODUCT_ID "wb193"
24cee5341dSSujith Manoharan 
259d5b80fdSSujith Manoharan #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
269d5b80fdSSujith Manoharan 
2721cb9879SVivek Natarajan /*
2821cb9879SVivek Natarajan  * Detects if there is any priority bt traffic
2921cb9879SVivek Natarajan  */
ath_detect_bt_priority(struct ath9k_htc_priv * priv)3021cb9879SVivek Natarajan static void ath_detect_bt_priority(struct ath9k_htc_priv *priv)
3121cb9879SVivek Natarajan {
3221cb9879SVivek Natarajan 	struct ath_btcoex *btcoex = &priv->btcoex;
3321cb9879SVivek Natarajan 	struct ath_hw *ah = priv->ah;
3421cb9879SVivek Natarajan 
3521cb9879SVivek Natarajan 	if (ath9k_hw_gpio_get(ah, ah->btcoex_hw.btpriority_gpio))
3621cb9879SVivek Natarajan 		btcoex->bt_priority_cnt++;
3721cb9879SVivek Natarajan 
3821cb9879SVivek Natarajan 	if (time_after(jiffies, btcoex->bt_priority_time +
3921cb9879SVivek Natarajan 			msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
40d8a2c51cSSujith Manoharan 		clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
41d8a2c51cSSujith Manoharan 		clear_bit(OP_BT_SCAN, &priv->op_flags);
4221cb9879SVivek Natarajan 		/* Detect if colocated bt started scanning */
4321cb9879SVivek Natarajan 		if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
44d2182b69SJoe Perches 			ath_dbg(ath9k_hw_common(ah), BTCOEX,
45226afe68SJoe Perches 				"BT scan detected\n");
46d8a2c51cSSujith Manoharan 			set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
47d8a2c51cSSujith Manoharan 			set_bit(OP_BT_SCAN, &priv->op_flags);
4821cb9879SVivek Natarajan 		} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
49d2182b69SJoe Perches 			ath_dbg(ath9k_hw_common(ah), BTCOEX,
50226afe68SJoe Perches 				"BT priority traffic detected\n");
51d8a2c51cSSujith Manoharan 			set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
5221cb9879SVivek Natarajan 		}
5321cb9879SVivek Natarajan 
5421cb9879SVivek Natarajan 		btcoex->bt_priority_cnt = 0;
5521cb9879SVivek Natarajan 		btcoex->bt_priority_time = jiffies;
5621cb9879SVivek Natarajan 	}
5721cb9879SVivek Natarajan }
5821cb9879SVivek Natarajan 
5921cb9879SVivek Natarajan /*
6021cb9879SVivek Natarajan  * This is the master bt coex work which runs for every
6121cb9879SVivek Natarajan  * 45ms, bt traffic will be given priority during 55% of this
6221cb9879SVivek Natarajan  * period while wlan gets remaining 45%
6321cb9879SVivek Natarajan  */
ath_btcoex_period_work(struct work_struct * work)6421cb9879SVivek Natarajan static void ath_btcoex_period_work(struct work_struct *work)
6521cb9879SVivek Natarajan {
6621cb9879SVivek Natarajan 	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
6721cb9879SVivek Natarajan 						   coex_period_work.work);
6821cb9879SVivek Natarajan 	struct ath_btcoex *btcoex = &priv->btcoex;
6921cb9879SVivek Natarajan 	struct ath_common *common = ath9k_hw_common(priv->ah);
7021cb9879SVivek Natarajan 	u32 timer_period;
7121cb9879SVivek Natarajan 	int ret;
7221cb9879SVivek Natarajan 
7321cb9879SVivek Natarajan 	ath_detect_bt_priority(priv);
7421cb9879SVivek Natarajan 
753a0593efSSujith Manoharan 	ret = ath9k_htc_update_cap_target(priv,
76d8a2c51cSSujith Manoharan 			  test_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags));
770ff2b5c0SSujith Manoharan 	if (ret) {
780ff2b5c0SSujith Manoharan 		ath_err(common, "Unable to set BTCOEX parameters\n");
790ff2b5c0SSujith Manoharan 		return;
800ff2b5c0SSujith Manoharan 	}
8121cb9879SVivek Natarajan 
82d8a2c51cSSujith Manoharan 	ath9k_hw_btcoex_bt_stomp(priv->ah, test_bit(OP_BT_SCAN, &priv->op_flags) ?
83d8a2c51cSSujith Manoharan 				 ATH_BTCOEX_STOMP_ALL : btcoex->bt_stomp_type);
8421cb9879SVivek Natarajan 
85bc6d5c29SRajkumar Manoharan 	ath9k_hw_btcoex_enable(priv->ah);
86d8a2c51cSSujith Manoharan 	timer_period = test_bit(OP_BT_SCAN, &priv->op_flags) ?
87d8a2c51cSSujith Manoharan 		btcoex->btscan_no_stomp : btcoex->btcoex_no_stomp;
8821cb9879SVivek Natarajan 	ieee80211_queue_delayed_work(priv->hw, &priv->duty_cycle_work,
8921cb9879SVivek Natarajan 				     msecs_to_jiffies(timer_period));
9021cb9879SVivek Natarajan 	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work,
9121cb9879SVivek Natarajan 				     msecs_to_jiffies(btcoex->btcoex_period));
9221cb9879SVivek Natarajan }
9321cb9879SVivek Natarajan 
9421cb9879SVivek Natarajan /*
9521cb9879SVivek Natarajan  * Work to time slice between wlan and bt traffic and
9621cb9879SVivek Natarajan  * configure weight registers
9721cb9879SVivek Natarajan  */
ath_btcoex_duty_cycle_work(struct work_struct * work)9821cb9879SVivek Natarajan static void ath_btcoex_duty_cycle_work(struct work_struct *work)
9921cb9879SVivek Natarajan {
10021cb9879SVivek Natarajan 	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
10121cb9879SVivek Natarajan 						   duty_cycle_work.work);
10221cb9879SVivek Natarajan 	struct ath_hw *ah = priv->ah;
10321cb9879SVivek Natarajan 	struct ath_btcoex *btcoex = &priv->btcoex;
10421cb9879SVivek Natarajan 	struct ath_common *common = ath9k_hw_common(ah);
10521cb9879SVivek Natarajan 
106d2182b69SJoe Perches 	ath_dbg(common, BTCOEX, "time slice work for bt and wlan\n");
10721cb9879SVivek Natarajan 
108d8a2c51cSSujith Manoharan 	if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW ||
109d8a2c51cSSujith Manoharan 	    test_bit(OP_BT_SCAN, &priv->op_flags))
110978f78bfSVivek Natarajan 		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
11121cb9879SVivek Natarajan 	else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
112978f78bfSVivek Natarajan 		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
113d8a2c51cSSujith Manoharan 
114bc6d5c29SRajkumar Manoharan 	ath9k_hw_btcoex_enable(priv->ah);
11521cb9879SVivek Natarajan }
11621cb9879SVivek Natarajan 
ath_htc_init_btcoex_work(struct ath9k_htc_priv * priv)1179d5b80fdSSujith Manoharan static void ath_htc_init_btcoex_work(struct ath9k_htc_priv *priv)
11821cb9879SVivek Natarajan {
11921cb9879SVivek Natarajan 	struct ath_btcoex *btcoex = &priv->btcoex;
12021cb9879SVivek Natarajan 
12121cb9879SVivek Natarajan 	btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD;
12221cb9879SVivek Natarajan 	btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
12321cb9879SVivek Natarajan 		btcoex->btcoex_period / 100;
12421cb9879SVivek Natarajan 	btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
12521cb9879SVivek Natarajan 				   btcoex->btcoex_period / 100;
12621cb9879SVivek Natarajan 	INIT_DELAYED_WORK(&priv->coex_period_work, ath_btcoex_period_work);
12721cb9879SVivek Natarajan 	INIT_DELAYED_WORK(&priv->duty_cycle_work, ath_btcoex_duty_cycle_work);
12821cb9879SVivek Natarajan }
12921cb9879SVivek Natarajan 
13021cb9879SVivek Natarajan /*
13121cb9879SVivek Natarajan  * (Re)start btcoex work
13221cb9879SVivek Natarajan  */
13321cb9879SVivek Natarajan 
ath_htc_resume_btcoex_work(struct ath9k_htc_priv * priv)1349d5b80fdSSujith Manoharan static void ath_htc_resume_btcoex_work(struct ath9k_htc_priv *priv)
13521cb9879SVivek Natarajan {
13621cb9879SVivek Natarajan 	struct ath_btcoex *btcoex = &priv->btcoex;
13721cb9879SVivek Natarajan 	struct ath_hw *ah = priv->ah;
13821cb9879SVivek Natarajan 
139d2182b69SJoe Perches 	ath_dbg(ath9k_hw_common(ah), BTCOEX, "Starting btcoex work\n");
14021cb9879SVivek Natarajan 
14121cb9879SVivek Natarajan 	btcoex->bt_priority_cnt = 0;
14221cb9879SVivek Natarajan 	btcoex->bt_priority_time = jiffies;
143d8a2c51cSSujith Manoharan 	clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
144d8a2c51cSSujith Manoharan 	clear_bit(OP_BT_SCAN, &priv->op_flags);
14521cb9879SVivek Natarajan 	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 0);
14621cb9879SVivek Natarajan }
14721cb9879SVivek Natarajan 
14821cb9879SVivek Natarajan 
14921cb9879SVivek Natarajan /*
15021cb9879SVivek Natarajan  * Cancel btcoex and bt duty cycle work.
15121cb9879SVivek Natarajan  */
ath_htc_cancel_btcoex_work(struct ath9k_htc_priv * priv)1529d5b80fdSSujith Manoharan static void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv)
15321cb9879SVivek Natarajan {
15421cb9879SVivek Natarajan 	cancel_delayed_work_sync(&priv->coex_period_work);
15521cb9879SVivek Natarajan 	cancel_delayed_work_sync(&priv->duty_cycle_work);
15621cb9879SVivek Natarajan }
1571e1f4ad2SSujith Manoharan 
ath9k_htc_start_btcoex(struct ath9k_htc_priv * priv)158bf047fcdSSujith Manoharan void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv)
159bf047fcdSSujith Manoharan {
160bf047fcdSSujith Manoharan 	struct ath_hw *ah = priv->ah;
161bf047fcdSSujith Manoharan 
162bf047fcdSSujith Manoharan 	if (ath9k_hw_get_btcoex_scheme(ah) == ATH_BTCOEX_CFG_3WIRE) {
163bf047fcdSSujith Manoharan 		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1645160b46fSSujith Manoharan 					   AR_STOMP_LOW_WLAN_WGHT, 0);
165bf047fcdSSujith Manoharan 		ath9k_hw_btcoex_enable(ah);
166bf047fcdSSujith Manoharan 		ath_htc_resume_btcoex_work(priv);
167bf047fcdSSujith Manoharan 	}
168bf047fcdSSujith Manoharan }
169bf047fcdSSujith Manoharan 
ath9k_htc_stop_btcoex(struct ath9k_htc_priv * priv)170bf047fcdSSujith Manoharan void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv)
171bf047fcdSSujith Manoharan {
172bf047fcdSSujith Manoharan 	struct ath_hw *ah = priv->ah;
173bf047fcdSSujith Manoharan 
174bf047fcdSSujith Manoharan 	if (ah->btcoex_hw.enabled &&
175bf047fcdSSujith Manoharan 	    ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) {
176bf047fcdSSujith Manoharan 		if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
177bf047fcdSSujith Manoharan 			ath_htc_cancel_btcoex_work(priv);
17882781042SMohammed Shafi Shajakhan 		ath9k_hw_btcoex_disable(ah);
179bf047fcdSSujith Manoharan 	}
180bf047fcdSSujith Manoharan }
181bf047fcdSSujith Manoharan 
ath9k_htc_init_btcoex(struct ath9k_htc_priv * priv,char * product)182cee5341dSSujith Manoharan void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product)
183cee5341dSSujith Manoharan {
184cee5341dSSujith Manoharan 	struct ath_hw *ah = priv->ah;
1857f34778eSMohammed Shafi Shajakhan 	struct ath_common *common = ath9k_hw_common(ah);
186cee5341dSSujith Manoharan 	int qnum;
187cee5341dSSujith Manoharan 
1887f34778eSMohammed Shafi Shajakhan 	/*
1897f34778eSMohammed Shafi Shajakhan 	 * Check if BTCOEX is globally disabled.
1907f34778eSMohammed Shafi Shajakhan 	 */
1917f34778eSMohammed Shafi Shajakhan 	if (!common->btcoex_enabled) {
1927f34778eSMohammed Shafi Shajakhan 		ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_NONE;
1937f34778eSMohammed Shafi Shajakhan 		return;
1947f34778eSMohammed Shafi Shajakhan 	}
1957f34778eSMohammed Shafi Shajakhan 
196cee5341dSSujith Manoharan 	if (product && strncmp(product, ATH_HTC_BTCOEX_PRODUCT_ID, 5) == 0) {
197cee5341dSSujith Manoharan 		ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_3WIRE;
198cee5341dSSujith Manoharan 	}
199cee5341dSSujith Manoharan 
200cee5341dSSujith Manoharan 	switch (ath9k_hw_get_btcoex_scheme(priv->ah)) {
201cee5341dSSujith Manoharan 	case ATH_BTCOEX_CFG_NONE:
202cee5341dSSujith Manoharan 		break;
203cee5341dSSujith Manoharan 	case ATH_BTCOEX_CFG_3WIRE:
204cee5341dSSujith Manoharan 		priv->ah->btcoex_hw.btactive_gpio = 7;
205cee5341dSSujith Manoharan 		priv->ah->btcoex_hw.btpriority_gpio = 6;
206cee5341dSSujith Manoharan 		priv->ah->btcoex_hw.wlanactive_gpio = 8;
207cee5341dSSujith Manoharan 		priv->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
208cee5341dSSujith Manoharan 		ath9k_hw_btcoex_init_3wire(priv->ah);
209cee5341dSSujith Manoharan 		ath_htc_init_btcoex_work(priv);
210bea843c7SSujith Manoharan 		qnum = priv->hwq_map[IEEE80211_AC_BE];
211cee5341dSSujith Manoharan 		ath9k_hw_init_btcoex_hw(priv->ah, qnum);
212cee5341dSSujith Manoharan 		break;
213cee5341dSSujith Manoharan 	default:
214cee5341dSSujith Manoharan 		WARN_ON(1);
215cee5341dSSujith Manoharan 		break;
216cee5341dSSujith Manoharan 	}
217cee5341dSSujith Manoharan }
218cee5341dSSujith Manoharan 
2199d5b80fdSSujith Manoharan #endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
2209d5b80fdSSujith Manoharan 
2211e1f4ad2SSujith Manoharan /*******/
2221e1f4ad2SSujith Manoharan /* LED */
2231e1f4ad2SSujith Manoharan /*******/
2241e1f4ad2SSujith Manoharan 
225d244f21eSSujith Manoharan #ifdef CONFIG_MAC80211_LEDS
ath9k_led_work(struct work_struct * work)226d244f21eSSujith Manoharan void ath9k_led_work(struct work_struct *work)
2271e1f4ad2SSujith Manoharan {
228d244f21eSSujith Manoharan 	struct ath9k_htc_priv *priv = container_of(work,
229d244f21eSSujith Manoharan 						   struct ath9k_htc_priv,
230d244f21eSSujith Manoharan 						   led_work);
2311e1f4ad2SSujith Manoharan 
2321e1f4ad2SSujith Manoharan 	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
233d244f21eSSujith Manoharan 			  (priv->brightness == LED_OFF));
2341e1f4ad2SSujith Manoharan }
2351e1f4ad2SSujith Manoharan 
ath9k_led_brightness(struct led_classdev * led_cdev,enum led_brightness brightness)2361e1f4ad2SSujith Manoharan static void ath9k_led_brightness(struct led_classdev *led_cdev,
2371e1f4ad2SSujith Manoharan 				 enum led_brightness brightness)
2381e1f4ad2SSujith Manoharan {
239d244f21eSSujith Manoharan 	struct ath9k_htc_priv *priv = container_of(led_cdev,
240d244f21eSSujith Manoharan 						   struct ath9k_htc_priv,
241d244f21eSSujith Manoharan 						   led_cdev);
2421e1f4ad2SSujith Manoharan 
243d244f21eSSujith Manoharan 	/* Not locked, but it's just a tiny green light..*/
244d244f21eSSujith Manoharan 	priv->brightness = brightness;
245d244f21eSSujith Manoharan 	ieee80211_queue_work(priv->hw, &priv->led_work);
2461e1f4ad2SSujith Manoharan }
2471e1f4ad2SSujith Manoharan 
ath9k_deinit_leds(struct ath9k_htc_priv * priv)2481e1f4ad2SSujith Manoharan void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
2491e1f4ad2SSujith Manoharan {
250d244f21eSSujith Manoharan 	if (!priv->led_registered)
251d244f21eSSujith Manoharan 		return;
252d244f21eSSujith Manoharan 
253d244f21eSSujith Manoharan 	ath9k_led_brightness(&priv->led_cdev, LED_OFF);
254d244f21eSSujith Manoharan 	led_classdev_unregister(&priv->led_cdev);
255d244f21eSSujith Manoharan 	cancel_work_sync(&priv->led_work);
256*db222190SMiaoqing Pan 
257*db222190SMiaoqing Pan 	ath9k_hw_gpio_free(priv->ah, priv->ah->led_pin);
2581e1f4ad2SSujith Manoharan }
2591e1f4ad2SSujith Manoharan 
2601e51acaaSOleksij Rempel 
ath9k_configure_leds(struct ath9k_htc_priv * priv)2611e51acaaSOleksij Rempel void ath9k_configure_leds(struct ath9k_htc_priv *priv)
2621e51acaaSOleksij Rempel {
2631e51acaaSOleksij Rempel 	/* Configure gpio 1 for output */
264b2d70d49SMiaoqing Pan 	ath9k_hw_gpio_request_out(priv->ah, priv->ah->led_pin,
265b2d70d49SMiaoqing Pan 				  "ath9k-led",
2661e51acaaSOleksij Rempel 				  AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
2671e51acaaSOleksij Rempel 	/* LED off, active low */
2681e51acaaSOleksij Rempel 	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
2691e51acaaSOleksij Rempel }
2701e51acaaSOleksij Rempel 
ath9k_init_leds(struct ath9k_htc_priv * priv)2711e1f4ad2SSujith Manoharan void ath9k_init_leds(struct ath9k_htc_priv *priv)
2721e1f4ad2SSujith Manoharan {
2731e1f4ad2SSujith Manoharan 	int ret;
2741e1f4ad2SSujith Manoharan 
2751e1f4ad2SSujith Manoharan 	if (AR_SREV_9287(priv->ah))
2761e1f4ad2SSujith Manoharan 		priv->ah->led_pin = ATH_LED_PIN_9287;
2771e1f4ad2SSujith Manoharan 	else if (AR_SREV_9271(priv->ah))
2781e1f4ad2SSujith Manoharan 		priv->ah->led_pin = ATH_LED_PIN_9271;
2791e1f4ad2SSujith Manoharan 	else if (AR_DEVID_7010(priv->ah))
2801e1f4ad2SSujith Manoharan 		priv->ah->led_pin = ATH_LED_PIN_7010;
2811e1f4ad2SSujith Manoharan 	else
2821e1f4ad2SSujith Manoharan 		priv->ah->led_pin = ATH_LED_PIN_DEF;
2831e1f4ad2SSujith Manoharan 
2840c8a1e43SHong Xu 	if (!ath9k_htc_led_blink)
2853a939a67SHong Xu 		priv->led_cdev.default_trigger =
2863a939a67SHong Xu 			ieee80211_get_radio_led_name(priv->hw);
2873a939a67SHong Xu 
2881e51acaaSOleksij Rempel 	ath9k_configure_leds(priv);
2891e1f4ad2SSujith Manoharan 
290d244f21eSSujith Manoharan 	snprintf(priv->led_name, sizeof(priv->led_name),
291d244f21eSSujith Manoharan 		"ath9k_htc-%s", wiphy_name(priv->hw->wiphy));
292d244f21eSSujith Manoharan 	priv->led_cdev.name = priv->led_name;
293d244f21eSSujith Manoharan 	priv->led_cdev.brightness_set = ath9k_led_brightness;
2941e1f4ad2SSujith Manoharan 
295d244f21eSSujith Manoharan 	ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &priv->led_cdev);
296d244f21eSSujith Manoharan 	if (ret < 0)
2971e1f4ad2SSujith Manoharan 		return;
2981e1f4ad2SSujith Manoharan 
299d244f21eSSujith Manoharan 	INIT_WORK(&priv->led_work, ath9k_led_work);
300d244f21eSSujith Manoharan 	priv->led_registered = true;
301d244f21eSSujith Manoharan 
302d244f21eSSujith Manoharan 	return;
3031e1f4ad2SSujith Manoharan }
304d244f21eSSujith Manoharan #endif
3051e1f4ad2SSujith Manoharan 
3061e1f4ad2SSujith Manoharan /*******************/
3071e1f4ad2SSujith Manoharan /*	Rfkill	   */
3081e1f4ad2SSujith Manoharan /*******************/
3091e1f4ad2SSujith Manoharan 
ath_is_rfkill_set(struct ath9k_htc_priv * priv)3101e1f4ad2SSujith Manoharan static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
3111e1f4ad2SSujith Manoharan {
31290826313SMohammed Shafi Shajakhan 	bool is_blocked;
31390826313SMohammed Shafi Shajakhan 
31490826313SMohammed Shafi Shajakhan 	ath9k_htc_ps_wakeup(priv);
31590826313SMohammed Shafi Shajakhan 	is_blocked = ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
3161e1f4ad2SSujith Manoharan 						 priv->ah->rfkill_polarity;
31790826313SMohammed Shafi Shajakhan 	ath9k_htc_ps_restore(priv);
31890826313SMohammed Shafi Shajakhan 
31990826313SMohammed Shafi Shajakhan 	return is_blocked;
3201e1f4ad2SSujith Manoharan }
3211e1f4ad2SSujith Manoharan 
ath9k_htc_rfkill_poll_state(struct ieee80211_hw * hw)3221e1f4ad2SSujith Manoharan void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
3231e1f4ad2SSujith Manoharan {
3241e1f4ad2SSujith Manoharan 	struct ath9k_htc_priv *priv = hw->priv;
3251e1f4ad2SSujith Manoharan 	bool blocked = !!ath_is_rfkill_set(priv);
3261e1f4ad2SSujith Manoharan 
3271e1f4ad2SSujith Manoharan 	wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
3281e1f4ad2SSujith Manoharan }
3291e1f4ad2SSujith Manoharan 
ath9k_start_rfkill_poll(struct ath9k_htc_priv * priv)3301e1f4ad2SSujith Manoharan void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
3311e1f4ad2SSujith Manoharan {
3321e1f4ad2SSujith Manoharan 	if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
3331e1f4ad2SSujith Manoharan 		wiphy_rfkill_start_polling(priv->hw->wiphy);
3341e1f4ad2SSujith Manoharan }
335