Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 * Copyright (c) 2010-2011 Atheros Communications Inc.
  3 *
  4 * Permission to use, copy, modify, and/or distribute this software for any
  5 * purpose with or without fee is hereby granted, provided that the above
  6 * copyright notice and this permission notice appear in all copies.
  7 *
  8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15 */
 16
 17#include "htc.h"
 18
 19/******************/
 20/*     BTCOEX     */
 21/******************/
 22
 
 
 
 
 23/*
 24 * Detects if there is any priority bt traffic
 25 */
 26static void ath_detect_bt_priority(struct ath9k_htc_priv *priv)
 27{
 28	struct ath_btcoex *btcoex = &priv->btcoex;
 29	struct ath_hw *ah = priv->ah;
 30
 31	if (ath9k_hw_gpio_get(ah, ah->btcoex_hw.btpriority_gpio))
 32		btcoex->bt_priority_cnt++;
 33
 34	if (time_after(jiffies, btcoex->bt_priority_time +
 35			msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
 36		priv->op_flags &= ~(OP_BT_PRIORITY_DETECTED | OP_BT_SCAN);
 
 37		/* Detect if colocated bt started scanning */
 38		if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
 39			ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
 40				"BT scan detected\n");
 41			priv->op_flags |= (OP_BT_SCAN |
 42					 OP_BT_PRIORITY_DETECTED);
 43		} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
 44			ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
 45				"BT priority traffic detected\n");
 46			priv->op_flags |= OP_BT_PRIORITY_DETECTED;
 47		}
 48
 49		btcoex->bt_priority_cnt = 0;
 50		btcoex->bt_priority_time = jiffies;
 51	}
 52}
 53
 54/*
 55 * This is the master bt coex work which runs for every
 56 * 45ms, bt traffic will be given priority during 55% of this
 57 * period while wlan gets remaining 45%
 58 */
 59static void ath_btcoex_period_work(struct work_struct *work)
 60{
 61	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
 62						   coex_period_work.work);
 63	struct ath_btcoex *btcoex = &priv->btcoex;
 64	struct ath_common *common = ath9k_hw_common(priv->ah);
 65	u32 timer_period;
 66	bool is_btscan;
 67	int ret;
 68
 69	ath_detect_bt_priority(priv);
 70
 71	is_btscan = !!(priv->op_flags & OP_BT_SCAN);
 72
 73	ret = ath9k_htc_update_cap_target(priv,
 74				  !!(priv->op_flags & OP_BT_PRIORITY_DETECTED));
 75	if (ret) {
 76		ath_err(common, "Unable to set BTCOEX parameters\n");
 77		return;
 78	}
 79
 80	ath9k_hw_btcoex_bt_stomp(priv->ah, is_btscan ? ATH_BTCOEX_STOMP_ALL :
 81			btcoex->bt_stomp_type);
 82
 83	timer_period = is_btscan ? btcoex->btscan_no_stomp :
 84		btcoex->btcoex_no_stomp;
 
 85	ieee80211_queue_delayed_work(priv->hw, &priv->duty_cycle_work,
 86				     msecs_to_jiffies(timer_period));
 87	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work,
 88				     msecs_to_jiffies(btcoex->btcoex_period));
 89}
 90
 91/*
 92 * Work to time slice between wlan and bt traffic and
 93 * configure weight registers
 94 */
 95static void ath_btcoex_duty_cycle_work(struct work_struct *work)
 96{
 97	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
 98						   duty_cycle_work.work);
 99	struct ath_hw *ah = priv->ah;
100	struct ath_btcoex *btcoex = &priv->btcoex;
101	struct ath_common *common = ath9k_hw_common(ah);
102	bool is_btscan = priv->op_flags & OP_BT_SCAN;
103
104	ath_dbg(common, ATH_DBG_BTCOEX,
105		"time slice work for bt and wlan\n");
106
107	if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan)
 
108		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
109	else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
110		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
 
 
111}
112
113void ath_htc_init_btcoex_work(struct ath9k_htc_priv *priv)
114{
115	struct ath_btcoex *btcoex = &priv->btcoex;
116
117	btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD;
118	btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
119		btcoex->btcoex_period / 100;
120	btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
121				   btcoex->btcoex_period / 100;
122	INIT_DELAYED_WORK(&priv->coex_period_work, ath_btcoex_period_work);
123	INIT_DELAYED_WORK(&priv->duty_cycle_work, ath_btcoex_duty_cycle_work);
124}
125
126/*
127 * (Re)start btcoex work
128 */
129
130void ath_htc_resume_btcoex_work(struct ath9k_htc_priv *priv)
131{
132	struct ath_btcoex *btcoex = &priv->btcoex;
133	struct ath_hw *ah = priv->ah;
134
135	ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX, "Starting btcoex work\n");
136
137	btcoex->bt_priority_cnt = 0;
138	btcoex->bt_priority_time = jiffies;
139	priv->op_flags &= ~(OP_BT_PRIORITY_DETECTED | OP_BT_SCAN);
 
140	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 0);
141}
142
143
144/*
145 * Cancel btcoex and bt duty cycle work.
146 */
147void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv)
148{
149	cancel_delayed_work_sync(&priv->coex_period_work);
150	cancel_delayed_work_sync(&priv->duty_cycle_work);
151}
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153/*******/
154/* LED */
155/*******/
156
157#ifdef CONFIG_MAC80211_LEDS
158void ath9k_led_work(struct work_struct *work)
159{
160	struct ath9k_htc_priv *priv = container_of(work,
161						   struct ath9k_htc_priv,
162						   led_work);
163
164	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
165			  (priv->brightness == LED_OFF));
166}
167
168static void ath9k_led_brightness(struct led_classdev *led_cdev,
169				 enum led_brightness brightness)
170{
171	struct ath9k_htc_priv *priv = container_of(led_cdev,
172						   struct ath9k_htc_priv,
173						   led_cdev);
174
175	/* Not locked, but it's just a tiny green light..*/
176	priv->brightness = brightness;
177	ieee80211_queue_work(priv->hw, &priv->led_work);
178}
179
180void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
181{
182	if (!priv->led_registered)
183		return;
184
185	ath9k_led_brightness(&priv->led_cdev, LED_OFF);
186	led_classdev_unregister(&priv->led_cdev);
187	cancel_work_sync(&priv->led_work);
188}
189
 
 
 
 
 
 
 
 
 
 
 
190void ath9k_init_leds(struct ath9k_htc_priv *priv)
191{
192	int ret;
193
194	if (AR_SREV_9287(priv->ah))
195		priv->ah->led_pin = ATH_LED_PIN_9287;
196	else if (AR_SREV_9271(priv->ah))
197		priv->ah->led_pin = ATH_LED_PIN_9271;
198	else if (AR_DEVID_7010(priv->ah))
199		priv->ah->led_pin = ATH_LED_PIN_7010;
200	else
201		priv->ah->led_pin = ATH_LED_PIN_DEF;
202
203	/* Configure gpio 1 for output */
204	ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
205			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
206	/* LED off, active low */
207	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
208
209	snprintf(priv->led_name, sizeof(priv->led_name),
210		"ath9k_htc-%s", wiphy_name(priv->hw->wiphy));
211	priv->led_cdev.name = priv->led_name;
212	priv->led_cdev.brightness_set = ath9k_led_brightness;
213
214	ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &priv->led_cdev);
215	if (ret < 0)
216		return;
217
218	INIT_WORK(&priv->led_work, ath9k_led_work);
219	priv->led_registered = true;
220
221	return;
222}
223#endif
224
225/*******************/
226/*	Rfkill	   */
227/*******************/
228
229static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
230{
231	return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
232		priv->ah->rfkill_polarity;
 
 
 
 
 
 
233}
234
235void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
236{
237	struct ath9k_htc_priv *priv = hw->priv;
238	bool blocked = !!ath_is_rfkill_set(priv);
239
240	wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
241}
242
243void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
244{
245	if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
246		wiphy_rfkill_start_polling(priv->hw->wiphy);
247}
248
249void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
250{
251	struct ath9k_htc_priv *priv = hw->priv;
252	struct ath_hw *ah = priv->ah;
253	struct ath_common *common = ath9k_hw_common(ah);
254	int ret;
255	u8 cmd_rsp;
256
257	if (!ah->curchan)
258		ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
259
260	/* Reset the HW */
261	ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
262	if (ret) {
263		ath_err(common,
264			"Unable to reset hardware; reset status %d (freq %u MHz)\n",
265			ret, ah->curchan->channel);
266	}
267
268	ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
269			       &priv->curtxpow);
270
271	/* Start RX */
272	WMI_CMD(WMI_START_RECV_CMDID);
273	ath9k_host_rx_init(priv);
274
275	/* Start TX */
276	htc_start(priv->htc);
277	spin_lock_bh(&priv->tx.tx_lock);
278	priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
279	spin_unlock_bh(&priv->tx.tx_lock);
280	ieee80211_wake_queues(hw);
281
282	WMI_CMD(WMI_ENABLE_INTR_CMDID);
283
284	/* Enable LED */
285	ath9k_hw_cfg_output(ah, ah->led_pin,
286			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
287	ath9k_hw_set_gpio(ah, ah->led_pin, 0);
288}
289
290void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
291{
292	struct ath9k_htc_priv *priv = hw->priv;
293	struct ath_hw *ah = priv->ah;
294	struct ath_common *common = ath9k_hw_common(ah);
295	int ret;
296	u8 cmd_rsp;
297
298	ath9k_htc_ps_wakeup(priv);
299
300	/* Disable LED */
301	ath9k_hw_set_gpio(ah, ah->led_pin, 1);
302	ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
303
304	WMI_CMD(WMI_DISABLE_INTR_CMDID);
305
306	/* Stop TX */
307	ieee80211_stop_queues(hw);
308	ath9k_htc_tx_drain(priv);
309	WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
310
311	/* Stop RX */
312	WMI_CMD(WMI_STOP_RECV_CMDID);
313
314	/* Clear the WMI event queue */
315	ath9k_wmi_event_drain(priv);
316
317	/*
318	 * The MIB counters have to be disabled here,
319	 * since the target doesn't do it.
320	 */
321	ath9k_hw_disable_mib_counters(ah);
322
323	if (!ah->curchan)
324		ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
325
326	/* Reset the HW */
327	ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
328	if (ret) {
329		ath_err(common,
330			"Unable to reset hardware; reset status %d (freq %u MHz)\n",
331			ret, ah->curchan->channel);
332	}
333
334	/* Disable the PHY */
335	ath9k_hw_phy_disable(ah);
336
337	ath9k_htc_ps_restore(priv);
338	ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
339}
v4.6
  1/*
  2 * Copyright (c) 2010-2011 Atheros Communications Inc.
  3 *
  4 * Permission to use, copy, modify, and/or distribute this software for any
  5 * purpose with or without fee is hereby granted, provided that the above
  6 * copyright notice and this permission notice appear in all copies.
  7 *
  8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15 */
 16
 17#include "htc.h"
 18
 19/******************/
 20/*     BTCOEX     */
 21/******************/
 22
 23#define ATH_HTC_BTCOEX_PRODUCT_ID "wb193"
 24
 25#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
 26
 27/*
 28 * Detects if there is any priority bt traffic
 29 */
 30static void ath_detect_bt_priority(struct ath9k_htc_priv *priv)
 31{
 32	struct ath_btcoex *btcoex = &priv->btcoex;
 33	struct ath_hw *ah = priv->ah;
 34
 35	if (ath9k_hw_gpio_get(ah, ah->btcoex_hw.btpriority_gpio))
 36		btcoex->bt_priority_cnt++;
 37
 38	if (time_after(jiffies, btcoex->bt_priority_time +
 39			msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
 40		clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
 41		clear_bit(OP_BT_SCAN, &priv->op_flags);
 42		/* Detect if colocated bt started scanning */
 43		if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
 44			ath_dbg(ath9k_hw_common(ah), BTCOEX,
 45				"BT scan detected\n");
 46			set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
 47			set_bit(OP_BT_SCAN, &priv->op_flags);
 48		} else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
 49			ath_dbg(ath9k_hw_common(ah), BTCOEX,
 50				"BT priority traffic detected\n");
 51			set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
 52		}
 53
 54		btcoex->bt_priority_cnt = 0;
 55		btcoex->bt_priority_time = jiffies;
 56	}
 57}
 58
 59/*
 60 * This is the master bt coex work which runs for every
 61 * 45ms, bt traffic will be given priority during 55% of this
 62 * period while wlan gets remaining 45%
 63 */
 64static void ath_btcoex_period_work(struct work_struct *work)
 65{
 66	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
 67						   coex_period_work.work);
 68	struct ath_btcoex *btcoex = &priv->btcoex;
 69	struct ath_common *common = ath9k_hw_common(priv->ah);
 70	u32 timer_period;
 
 71	int ret;
 72
 73	ath_detect_bt_priority(priv);
 74
 
 
 75	ret = ath9k_htc_update_cap_target(priv,
 76			  test_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags));
 77	if (ret) {
 78		ath_err(common, "Unable to set BTCOEX parameters\n");
 79		return;
 80	}
 81
 82	ath9k_hw_btcoex_bt_stomp(priv->ah, test_bit(OP_BT_SCAN, &priv->op_flags) ?
 83				 ATH_BTCOEX_STOMP_ALL : btcoex->bt_stomp_type);
 84
 85	ath9k_hw_btcoex_enable(priv->ah);
 86	timer_period = test_bit(OP_BT_SCAN, &priv->op_flags) ?
 87		btcoex->btscan_no_stomp : btcoex->btcoex_no_stomp;
 88	ieee80211_queue_delayed_work(priv->hw, &priv->duty_cycle_work,
 89				     msecs_to_jiffies(timer_period));
 90	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work,
 91				     msecs_to_jiffies(btcoex->btcoex_period));
 92}
 93
 94/*
 95 * Work to time slice between wlan and bt traffic and
 96 * configure weight registers
 97 */
 98static void ath_btcoex_duty_cycle_work(struct work_struct *work)
 99{
100	struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
101						   duty_cycle_work.work);
102	struct ath_hw *ah = priv->ah;
103	struct ath_btcoex *btcoex = &priv->btcoex;
104	struct ath_common *common = ath9k_hw_common(ah);
 
105
106	ath_dbg(common, BTCOEX, "time slice work for bt and wlan\n");
 
107
108	if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW ||
109	    test_bit(OP_BT_SCAN, &priv->op_flags))
110		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
111	else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
112		ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
113
114	ath9k_hw_btcoex_enable(priv->ah);
115}
116
117static void ath_htc_init_btcoex_work(struct ath9k_htc_priv *priv)
118{
119	struct ath_btcoex *btcoex = &priv->btcoex;
120
121	btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD;
122	btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
123		btcoex->btcoex_period / 100;
124	btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) *
125				   btcoex->btcoex_period / 100;
126	INIT_DELAYED_WORK(&priv->coex_period_work, ath_btcoex_period_work);
127	INIT_DELAYED_WORK(&priv->duty_cycle_work, ath_btcoex_duty_cycle_work);
128}
129
130/*
131 * (Re)start btcoex work
132 */
133
134static void ath_htc_resume_btcoex_work(struct ath9k_htc_priv *priv)
135{
136	struct ath_btcoex *btcoex = &priv->btcoex;
137	struct ath_hw *ah = priv->ah;
138
139	ath_dbg(ath9k_hw_common(ah), BTCOEX, "Starting btcoex work\n");
140
141	btcoex->bt_priority_cnt = 0;
142	btcoex->bt_priority_time = jiffies;
143	clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags);
144	clear_bit(OP_BT_SCAN, &priv->op_flags);
145	ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 0);
146}
147
148
149/*
150 * Cancel btcoex and bt duty cycle work.
151 */
152static void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv)
153{
154	cancel_delayed_work_sync(&priv->coex_period_work);
155	cancel_delayed_work_sync(&priv->duty_cycle_work);
156}
157
158void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv)
159{
160	struct ath_hw *ah = priv->ah;
161
162	if (ath9k_hw_get_btcoex_scheme(ah) == ATH_BTCOEX_CFG_3WIRE) {
163		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
164					   AR_STOMP_LOW_WLAN_WGHT, 0);
165		ath9k_hw_btcoex_enable(ah);
166		ath_htc_resume_btcoex_work(priv);
167	}
168}
169
170void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv)
171{
172	struct ath_hw *ah = priv->ah;
173
174	if (ah->btcoex_hw.enabled &&
175	    ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) {
176		if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
177			ath_htc_cancel_btcoex_work(priv);
178		ath9k_hw_btcoex_disable(ah);
179	}
180}
181
182void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product)
183{
184	struct ath_hw *ah = priv->ah;
185	struct ath_common *common = ath9k_hw_common(ah);
186	int qnum;
187
188	/*
189	 * Check if BTCOEX is globally disabled.
190	 */
191	if (!common->btcoex_enabled) {
192		ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_NONE;
193		return;
194	}
195
196	if (product && strncmp(product, ATH_HTC_BTCOEX_PRODUCT_ID, 5) == 0) {
197		ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_3WIRE;
198	}
199
200	switch (ath9k_hw_get_btcoex_scheme(priv->ah)) {
201	case ATH_BTCOEX_CFG_NONE:
202		break;
203	case ATH_BTCOEX_CFG_3WIRE:
204		priv->ah->btcoex_hw.btactive_gpio = 7;
205		priv->ah->btcoex_hw.btpriority_gpio = 6;
206		priv->ah->btcoex_hw.wlanactive_gpio = 8;
207		priv->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
208		ath9k_hw_btcoex_init_3wire(priv->ah);
209		ath_htc_init_btcoex_work(priv);
210		qnum = priv->hwq_map[IEEE80211_AC_BE];
211		ath9k_hw_init_btcoex_hw(priv->ah, qnum);
212		break;
213	default:
214		WARN_ON(1);
215		break;
216	}
217}
218
219#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
220
221/*******/
222/* LED */
223/*******/
224
225#ifdef CONFIG_MAC80211_LEDS
226void ath9k_led_work(struct work_struct *work)
227{
228	struct ath9k_htc_priv *priv = container_of(work,
229						   struct ath9k_htc_priv,
230						   led_work);
231
232	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
233			  (priv->brightness == LED_OFF));
234}
235
236static void ath9k_led_brightness(struct led_classdev *led_cdev,
237				 enum led_brightness brightness)
238{
239	struct ath9k_htc_priv *priv = container_of(led_cdev,
240						   struct ath9k_htc_priv,
241						   led_cdev);
242
243	/* Not locked, but it's just a tiny green light..*/
244	priv->brightness = brightness;
245	ieee80211_queue_work(priv->hw, &priv->led_work);
246}
247
248void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
249{
250	if (!priv->led_registered)
251		return;
252
253	ath9k_led_brightness(&priv->led_cdev, LED_OFF);
254	led_classdev_unregister(&priv->led_cdev);
255	cancel_work_sync(&priv->led_work);
256}
257
258
259void ath9k_configure_leds(struct ath9k_htc_priv *priv)
260{
261	/* Configure gpio 1 for output */
262	ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
263			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
264	/* LED off, active low */
265	ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
266
267}
268
269void ath9k_init_leds(struct ath9k_htc_priv *priv)
270{
271	int ret;
272
273	if (AR_SREV_9287(priv->ah))
274		priv->ah->led_pin = ATH_LED_PIN_9287;
275	else if (AR_SREV_9271(priv->ah))
276		priv->ah->led_pin = ATH_LED_PIN_9271;
277	else if (AR_DEVID_7010(priv->ah))
278		priv->ah->led_pin = ATH_LED_PIN_7010;
279	else
280		priv->ah->led_pin = ATH_LED_PIN_DEF;
281
282	if (!ath9k_htc_led_blink)
283		priv->led_cdev.default_trigger =
284			ieee80211_get_radio_led_name(priv->hw);
285
286	ath9k_configure_leds(priv);
287
288	snprintf(priv->led_name, sizeof(priv->led_name),
289		"ath9k_htc-%s", wiphy_name(priv->hw->wiphy));
290	priv->led_cdev.name = priv->led_name;
291	priv->led_cdev.brightness_set = ath9k_led_brightness;
292
293	ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &priv->led_cdev);
294	if (ret < 0)
295		return;
296
297	INIT_WORK(&priv->led_work, ath9k_led_work);
298	priv->led_registered = true;
299
300	return;
301}
302#endif
303
304/*******************/
305/*	Rfkill	   */
306/*******************/
307
308static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
309{
310	bool is_blocked;
311
312	ath9k_htc_ps_wakeup(priv);
313	is_blocked = ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
314						 priv->ah->rfkill_polarity;
315	ath9k_htc_ps_restore(priv);
316
317	return is_blocked;
318}
319
320void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
321{
322	struct ath9k_htc_priv *priv = hw->priv;
323	bool blocked = !!ath_is_rfkill_set(priv);
324
325	wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
326}
327
328void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
329{
330	if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
331		wiphy_rfkill_start_polling(priv->hw->wiphy);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332}