1 /*
2  * Copyright (c) 2009-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 #ifndef BTCOEX_H
18 #define BTCOEX_H
19 
20 #include "hw.h"
21 
22 #define ATH_WLANACTIVE_GPIO_9280     5
23 #define ATH_BTACTIVE_GPIO_9280       6
24 #define ATH_BTPRIORITY_GPIO_9285     7
25 
26 #define ATH_WLANACTIVE_GPIO_9300     5
27 #define ATH_BTACTIVE_GPIO_9300       4
28 #define ATH_BTPRIORITY_GPIO_9300     8
29 
30 #define ATH_BTCOEX_DEF_BT_PERIOD  45
31 #define ATH_BTCOEX_DEF_DUTY_CYCLE 55
32 #define ATH_BTCOEX_BTSCAN_DUTY_CYCLE 90
33 #define ATH_BTCOEX_BMISS_THRESH   50
34 
35 #define ATH_BT_PRIORITY_TIME_THRESHOLD 1000 /* ms */
36 #define ATH_BT_CNT_THRESHOLD	       3
37 #define ATH_BT_CNT_SCAN_THRESHOLD      15
38 
39 #define ATH_BTCOEX_RX_WAIT_TIME       100
40 #define ATH_BTCOEX_STOMP_FTP_THRESH   5
41 
42 #define ATH_BTCOEX_HT20_MAX_TXPOWER   0x14
43 #define ATH_BTCOEX_HT40_MAX_TXPOWER   0x10
44 
45 #define AR9300_NUM_BT_WEIGHTS   4
46 #define AR9300_NUM_WLAN_WEIGHTS 4
47 /* Defines the BT AR_BT_COEX_WGHT used */
48 enum ath_stomp_type {
49 	ATH_BTCOEX_STOMP_ALL,
50 	ATH_BTCOEX_STOMP_LOW,
51 	ATH_BTCOEX_STOMP_NONE,
52 	ATH_BTCOEX_STOMP_LOW_FTP,
53 	ATH_BTCOEX_STOMP_AUDIO,
54 	ATH_BTCOEX_STOMP_MAX
55 };
56 
57 enum ath_btcoex_scheme {
58 	ATH_BTCOEX_CFG_NONE,
59 	ATH_BTCOEX_CFG_2WIRE,
60 	ATH_BTCOEX_CFG_3WIRE,
61 };
62 
63 struct ath9k_hw_mci {
64 	u32 raw_intr;
65 	u32 rx_msg_intr;
66 	u32 cont_status;
67 	u32 gpm_addr;
68 	u32 gpm_len;
69 	u32 gpm_idx;
70 	u32 sched_addr;
71 	u32 wlan_channels[4];
72 	u32 wlan_cal_seq;
73 	u32 wlan_cal_done;
74 	u32 config;
75 	u8 *gpm_buf;
76 	bool ready;
77 	bool update_2g5g;
78 	bool is_2g;
79 	bool query_bt;
80 	bool unhalt_bt_gpm; /* need send UNHALT */
81 	bool halted_bt_gpm; /* HALT sent */
82 	bool need_flush_btinfo;
83 	bool bt_version_known;
84 	bool wlan_channels_update;
85 	u8 wlan_ver_major;
86 	u8 wlan_ver_minor;
87 	u8 bt_ver_major;
88 	u8 bt_ver_minor;
89 	u8 bt_state;
90 	u8 stomp_ftp;
91 	bool concur_tx;
92 	u32 last_recovery;
93 };
94 
95 struct ath_btcoex_hw {
96 	enum ath_btcoex_scheme scheme;
97 	struct ath9k_hw_mci mci;
98 	bool enabled;
99 	u8 wlanactive_gpio;
100 	u8 btactive_gpio;
101 	u8 btpriority_gpio;
102 	u32 bt_coex_mode; 	/* Register setting for AR_BT_COEX_MODE */
103 	u32 bt_coex_weights; 	/* Register setting for AR_BT_COEX_WEIGHT */
104 	u32 bt_coex_mode2; 	/* Register setting for AR_BT_COEX_MODE2 */
105 	u32 bt_weight[AR9300_NUM_BT_WEIGHTS];
106 	u32 wlan_weight[AR9300_NUM_WLAN_WEIGHTS];
107 	u8 tx_prio[ATH_BTCOEX_STOMP_MAX];
108 };
109 
110 void ath9k_hw_btcoex_init_scheme(struct ath_hw *ah);
111 void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah);
112 void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah);
113 void ath9k_hw_btcoex_init_mci(struct ath_hw *ah);
114 void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum);
115 void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
116 				u32 bt_weight,
117 				u32 wlan_weight,
118 				enum ath_stomp_type stomp_type);
119 void ath9k_hw_btcoex_disable(struct ath_hw *ah);
120 void ath9k_hw_btcoex_bt_stomp(struct ath_hw *ah,
121 			      enum ath_stomp_type stomp_type);
122 void ath9k_hw_btcoex_set_concur_txprio(struct ath_hw *ah, u8 *stomp_txprio);
123 
124 #endif
125