blob: e77019256c61bd28d85a10a8f91c5e0c9d5aa322 [file] [log] [blame]
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001/*
2 * RTL8XXXU mac80211 USB driver
3 *
4 * Copyright (c) 2014 - 2015 Jes Sorensen <Jes.Sorensen@redhat.com>
5 *
6 * Portions, notably calibration code:
7 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
8 *
9 * This driver was written as a replacement for the vendor provided
10 * rtl8723au driver. As the Realtek 8xxx chips are very similar in
11 * their programming interface, I have started adding support for
12 * additional 8xxx chips like the 8192cu, 8188cus, etc.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of version 2 of the GNU General Public License as
16 * published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * more details.
22 */
23
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/errno.h>
28#include <linux/slab.h>
29#include <linux/module.h>
30#include <linux/spinlock.h>
31#include <linux/list.h>
32#include <linux/usb.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/ethtool.h>
36#include <linux/wireless.h>
37#include <linux/firmware.h>
38#include <linux/moduleparam.h>
39#include <net/mac80211.h>
40#include "rtl8xxxu.h"
41#include "rtl8xxxu_regs.h"
42
43#define DRIVER_NAME "rtl8xxxu"
44
Jes Sorensen3307d842016-02-29 17:03:59 -050045static int rtl8xxxu_debug = RTL8XXXU_DEBUG_EFUSE;
Jes Sorensen26f1fad2015-10-14 20:44:51 -040046static bool rtl8xxxu_ht40_2g;
47
48MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@redhat.com>");
49MODULE_DESCRIPTION("RTL8XXXu USB mac80211 Wireless LAN Driver");
50MODULE_LICENSE("GPL");
51MODULE_FIRMWARE("rtlwifi/rtl8723aufw_A.bin");
52MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B.bin");
53MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B_NoBT.bin");
54MODULE_FIRMWARE("rtlwifi/rtl8192cufw_A.bin");
55MODULE_FIRMWARE("rtlwifi/rtl8192cufw_B.bin");
56MODULE_FIRMWARE("rtlwifi/rtl8192cufw_TMSC.bin");
Jes Sorensenb001e082016-02-29 17:04:02 -050057MODULE_FIRMWARE("rtlwifi/rtl8192eu_nic.bin");
Jes Sorensen35a741f2016-02-29 17:04:10 -050058MODULE_FIRMWARE("rtlwifi/rtl8723bu_nic.bin");
59MODULE_FIRMWARE("rtlwifi/rtl8723bu_bt.bin");
Jes Sorensen26f1fad2015-10-14 20:44:51 -040060
61module_param_named(debug, rtl8xxxu_debug, int, 0600);
62MODULE_PARM_DESC(debug, "Set debug mask");
63module_param_named(ht40_2g, rtl8xxxu_ht40_2g, bool, 0600);
64MODULE_PARM_DESC(ht40_2g, "Enable HT40 support on the 2.4GHz band");
65
66#define USB_VENDOR_ID_REALTEK 0x0bda
67/* Minimum IEEE80211_MAX_FRAME_LEN */
68#define RTL_RX_BUFFER_SIZE IEEE80211_MAX_FRAME_LEN
69#define RTL8XXXU_RX_URBS 32
70#define RTL8XXXU_RX_URB_PENDING_WATER 8
71#define RTL8XXXU_TX_URBS 64
72#define RTL8XXXU_TX_URB_LOW_WATER 25
73#define RTL8XXXU_TX_URB_HIGH_WATER 32
74
75static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
76 struct rtl8xxxu_rx_urb *rx_urb);
77
78static struct ieee80211_rate rtl8xxxu_rates[] = {
79 { .bitrate = 10, .hw_value = DESC_RATE_1M, .flags = 0 },
80 { .bitrate = 20, .hw_value = DESC_RATE_2M, .flags = 0 },
81 { .bitrate = 55, .hw_value = DESC_RATE_5_5M, .flags = 0 },
82 { .bitrate = 110, .hw_value = DESC_RATE_11M, .flags = 0 },
83 { .bitrate = 60, .hw_value = DESC_RATE_6M, .flags = 0 },
84 { .bitrate = 90, .hw_value = DESC_RATE_9M, .flags = 0 },
85 { .bitrate = 120, .hw_value = DESC_RATE_12M, .flags = 0 },
86 { .bitrate = 180, .hw_value = DESC_RATE_18M, .flags = 0 },
87 { .bitrate = 240, .hw_value = DESC_RATE_24M, .flags = 0 },
88 { .bitrate = 360, .hw_value = DESC_RATE_36M, .flags = 0 },
89 { .bitrate = 480, .hw_value = DESC_RATE_48M, .flags = 0 },
90 { .bitrate = 540, .hw_value = DESC_RATE_54M, .flags = 0 },
91};
92
93static struct ieee80211_channel rtl8xxxu_channels_2g[] = {
Johannes Berg57fbcce2016-04-12 15:56:15 +020094 { .band = NL80211_BAND_2GHZ, .center_freq = 2412,
Jes Sorensen26f1fad2015-10-14 20:44:51 -040095 .hw_value = 1, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +020096 { .band = NL80211_BAND_2GHZ, .center_freq = 2417,
Jes Sorensen26f1fad2015-10-14 20:44:51 -040097 .hw_value = 2, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +020098 { .band = NL80211_BAND_2GHZ, .center_freq = 2422,
Jes Sorensen26f1fad2015-10-14 20:44:51 -040099 .hw_value = 3, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200100 { .band = NL80211_BAND_2GHZ, .center_freq = 2427,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400101 .hw_value = 4, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200102 { .band = NL80211_BAND_2GHZ, .center_freq = 2432,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400103 .hw_value = 5, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200104 { .band = NL80211_BAND_2GHZ, .center_freq = 2437,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400105 .hw_value = 6, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200106 { .band = NL80211_BAND_2GHZ, .center_freq = 2442,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400107 .hw_value = 7, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200108 { .band = NL80211_BAND_2GHZ, .center_freq = 2447,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400109 .hw_value = 8, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200110 { .band = NL80211_BAND_2GHZ, .center_freq = 2452,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400111 .hw_value = 9, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200112 { .band = NL80211_BAND_2GHZ, .center_freq = 2457,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400113 .hw_value = 10, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200114 { .band = NL80211_BAND_2GHZ, .center_freq = 2462,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400115 .hw_value = 11, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200116 { .band = NL80211_BAND_2GHZ, .center_freq = 2467,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400117 .hw_value = 12, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200118 { .band = NL80211_BAND_2GHZ, .center_freq = 2472,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400119 .hw_value = 13, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200120 { .band = NL80211_BAND_2GHZ, .center_freq = 2484,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400121 .hw_value = 14, .max_power = 30 }
122};
123
124static struct ieee80211_supported_band rtl8xxxu_supported_band = {
125 .channels = rtl8xxxu_channels_2g,
126 .n_channels = ARRAY_SIZE(rtl8xxxu_channels_2g),
127 .bitrates = rtl8xxxu_rates,
128 .n_bitrates = ARRAY_SIZE(rtl8xxxu_rates),
129};
130
131static struct rtl8xxxu_reg8val rtl8723a_mac_init_table[] = {
132 {0x420, 0x80}, {0x423, 0x00}, {0x430, 0x00}, {0x431, 0x00},
133 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
134 {0x436, 0x06}, {0x437, 0x07}, {0x438, 0x00}, {0x439, 0x00},
135 {0x43a, 0x00}, {0x43b, 0x01}, {0x43c, 0x04}, {0x43d, 0x05},
136 {0x43e, 0x06}, {0x43f, 0x07}, {0x440, 0x5d}, {0x441, 0x01},
137 {0x442, 0x00}, {0x444, 0x15}, {0x445, 0xf0}, {0x446, 0x0f},
138 {0x447, 0x00}, {0x458, 0x41}, {0x459, 0xa8}, {0x45a, 0x72},
139 {0x45b, 0xb9}, {0x460, 0x66}, {0x461, 0x66}, {0x462, 0x08},
140 {0x463, 0x03}, {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff},
141 {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2},
142 {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3},
143 {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4},
144 {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4},
145 {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a},
146 {0x515, 0x10}, {0x516, 0x0a}, {0x517, 0x10}, {0x51a, 0x16},
147 {0x524, 0x0f}, {0x525, 0x4f}, {0x546, 0x40}, {0x547, 0x00},
148 {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55a, 0x02},
149 {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a},
150 {0x652, 0x20}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e},
151 {0x63f, 0x0e}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43},
152 {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43},
153 {0x70a, 0x65}, {0x70b, 0x87}, {0xffff, 0xff},
154};
155
Jes Sorensenb7dd8ff2016-02-29 17:04:17 -0500156static struct rtl8xxxu_reg8val rtl8723b_mac_init_table[] = {
157 {0x02f, 0x30}, {0x035, 0x00}, {0x039, 0x08}, {0x04e, 0xe0},
158 {0x064, 0x00}, {0x067, 0x20}, {0x428, 0x0a}, {0x429, 0x10},
159 {0x430, 0x00}, {0x431, 0x00},
160 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
161 {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05},
162 {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01},
163 {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00},
164 {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f},
165 {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00},
166 {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f},
167 {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66},
168 {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff},
169 {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2},
170 {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3},
171 {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4},
172 {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4},
173 {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a},
174 {0x516, 0x0a}, {0x525, 0x4f},
175 {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50},
176 {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a},
177 {0x620, 0xff}, {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff},
178 {0x624, 0xff}, {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff},
179 {0x638, 0x50}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e},
180 {0x63f, 0x0e}, {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00},
181 {0x652, 0xc8}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43},
182 {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43},
183 {0x70a, 0x65}, {0x70b, 0x87}, {0x765, 0x18}, {0x76e, 0x04},
184 {0xffff, 0xff},
185};
186
Jes Sorensenc606e662016-04-07 14:19:16 -0400187static struct rtl8xxxu_reg8val rtl8192e_mac_init_table[] = {
188 {0x011, 0xeb}, {0x012, 0x07}, {0x014, 0x75}, {0x303, 0xa7},
189 {0x428, 0x0a}, {0x429, 0x10}, {0x430, 0x00}, {0x431, 0x00},
190 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
191 {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05},
192 {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01},
193 {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00},
194 {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f},
195 {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00},
196 {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f},
197 {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66},
198 {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff}, {0x4cd, 0xff},
199 {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2}, {0x502, 0x2f},
200 {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3}, {0x506, 0x5e},
201 {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4}, {0x50a, 0x5e},
202 {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4}, {0x50e, 0x00},
203 {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a}, {0x516, 0x0a},
204 {0x525, 0x4f}, {0x540, 0x12}, {0x541, 0x64}, {0x550, 0x10},
205 {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50}, {0x55d, 0xff},
206 {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a}, {0x620, 0xff},
207 {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff}, {0x624, 0xff},
208 {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff}, {0x638, 0x50},
209 {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e}, {0x63f, 0x0e},
210 {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00}, {0x652, 0xc8},
211 {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43}, {0x702, 0x65},
212 {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43}, {0x70a, 0x65},
213 {0x70b, 0x87},
214 {0xffff, 0xff},
215};
216
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400217static struct rtl8xxxu_reg32val rtl8723a_phy_1t_init_table[] = {
218 {0x800, 0x80040000}, {0x804, 0x00000003},
219 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
220 {0x810, 0x10001331}, {0x814, 0x020c3d10},
221 {0x818, 0x02200385}, {0x81c, 0x00000000},
222 {0x820, 0x01000100}, {0x824, 0x00390004},
223 {0x828, 0x00000000}, {0x82c, 0x00000000},
224 {0x830, 0x00000000}, {0x834, 0x00000000},
225 {0x838, 0x00000000}, {0x83c, 0x00000000},
226 {0x840, 0x00010000}, {0x844, 0x00000000},
227 {0x848, 0x00000000}, {0x84c, 0x00000000},
228 {0x850, 0x00000000}, {0x854, 0x00000000},
229 {0x858, 0x569a569a}, {0x85c, 0x001b25a4},
230 {0x860, 0x66f60110}, {0x864, 0x061f0130},
231 {0x868, 0x00000000}, {0x86c, 0x32323200},
232 {0x870, 0x07000760}, {0x874, 0x22004000},
233 {0x878, 0x00000808}, {0x87c, 0x00000000},
234 {0x880, 0xc0083070}, {0x884, 0x000004d5},
235 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
236 {0x890, 0x00000800}, {0x894, 0xfffffffe},
237 {0x898, 0x40302010}, {0x89c, 0x00706050},
238 {0x900, 0x00000000}, {0x904, 0x00000023},
239 {0x908, 0x00000000}, {0x90c, 0x81121111},
240 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
241 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
242 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
243 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
244 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
245 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
246 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
247 {0xa78, 0x00000900},
248 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
249 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
250 {0xc10, 0x08800000}, {0xc14, 0x40000100},
251 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
252 {0xc20, 0x00000000}, {0xc24, 0x00000000},
253 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
254 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
255 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
256 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
257 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
258 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
259 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
260 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
261 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
262 {0xc70, 0x2c7f000d}, {0xc74, 0x018610db},
263 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
264 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
265 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
266 {0xc90, 0x00121820}, {0xc94, 0x00000000},
267 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
268 {0xca0, 0x00000000}, {0xca4, 0x00000080},
269 {0xca8, 0x00000000}, {0xcac, 0x00000000},
270 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
271 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
272 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
273 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
274 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
275 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
276 {0xce0, 0x00222222}, {0xce4, 0x00000000},
277 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
278 {0xd00, 0x00080740}, {0xd04, 0x00020401},
279 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
280 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
281 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
282 {0xd30, 0x00000000}, {0xd34, 0x80608000},
283 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
284 {0xd40, 0x00000000}, {0xd44, 0x00000000},
285 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
286 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
287 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
288 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
289 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
290 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
291 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
292 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
293 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
294 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
295 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
296 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
297 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
298 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
299 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
300 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
301 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
302 {0xe68, 0x001b25a4}, {0xe6c, 0x631b25a0},
303 {0xe70, 0x631b25a0}, {0xe74, 0x081b25a0},
304 {0xe78, 0x081b25a0}, {0xe7c, 0x081b25a0},
305 {0xe80, 0x081b25a0}, {0xe84, 0x631b25a0},
306 {0xe88, 0x081b25a0}, {0xe8c, 0x631b25a0},
307 {0xed0, 0x631b25a0}, {0xed4, 0x631b25a0},
308 {0xed8, 0x631b25a0}, {0xedc, 0x001b25a0},
309 {0xee0, 0x001b25a0}, {0xeec, 0x6b1b25a0},
310 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
311 {0xf00, 0x00000300},
312 {0xffff, 0xffffffff},
313};
314
Jes Sorensen36c32582016-02-29 17:04:14 -0500315static struct rtl8xxxu_reg32val rtl8723b_phy_1t_init_table[] = {
316 {0x800, 0x80040000}, {0x804, 0x00000003},
317 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
318 {0x810, 0x10001331}, {0x814, 0x020c3d10},
319 {0x818, 0x02200385}, {0x81c, 0x00000000},
320 {0x820, 0x01000100}, {0x824, 0x00190204},
321 {0x828, 0x00000000}, {0x82c, 0x00000000},
322 {0x830, 0x00000000}, {0x834, 0x00000000},
323 {0x838, 0x00000000}, {0x83c, 0x00000000},
324 {0x840, 0x00010000}, {0x844, 0x00000000},
325 {0x848, 0x00000000}, {0x84c, 0x00000000},
326 {0x850, 0x00000000}, {0x854, 0x00000000},
327 {0x858, 0x569a11a9}, {0x85c, 0x01000014},
328 {0x860, 0x66f60110}, {0x864, 0x061f0649},
329 {0x868, 0x00000000}, {0x86c, 0x27272700},
330 {0x870, 0x07000760}, {0x874, 0x25004000},
331 {0x878, 0x00000808}, {0x87c, 0x00000000},
332 {0x880, 0xb0000c1c}, {0x884, 0x00000001},
333 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
334 {0x890, 0x00000800}, {0x894, 0xfffffffe},
335 {0x898, 0x40302010}, {0x89c, 0x00706050},
336 {0x900, 0x00000000}, {0x904, 0x00000023},
337 {0x908, 0x00000000}, {0x90c, 0x81121111},
338 {0x910, 0x00000002}, {0x914, 0x00000201},
339 {0xa00, 0x00d047c8}, {0xa04, 0x80ff800c},
340 {0xa08, 0x8c838300}, {0xa0c, 0x2e7f120f},
341 {0xa10, 0x9500bb78}, {0xa14, 0x1114d028},
342 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
343 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
344 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
345 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
346 {0xa78, 0x00000900}, {0xa7c, 0x225b0606},
347 {0xa80, 0x21806490}, {0xb2c, 0x00000000},
348 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
349 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
350 {0xc10, 0x08800000}, {0xc14, 0x40000100},
351 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
352 {0xc20, 0x00000000}, {0xc24, 0x00000000},
353 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
354 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
355 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
356 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
357 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
358 {0xc50, 0x69553420}, {0xc54, 0x43bc0094},
359 {0xc58, 0x00013149}, {0xc5c, 0x00250492},
360 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
361 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
362 {0xc70, 0x2c7f000d}, {0xc74, 0x020610db},
363 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
364 {0xc80, 0x390000e4}, {0xc84, 0x20f60000},
365 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
366 {0xc90, 0x00020e1a}, {0xc94, 0x00000000},
367 {0xc98, 0x00020e1a}, {0xc9c, 0x00007f7f},
368 {0xca0, 0x00000000}, {0xca4, 0x000300a0},
369 {0xca8, 0x00000000}, {0xcac, 0x00000000},
370 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
371 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
372 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
373 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
374 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
375 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
376 {0xce0, 0x00222222}, {0xce4, 0x00000000},
377 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
378 {0xd00, 0x00000740}, {0xd04, 0x40020401},
379 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
380 {0xd10, 0xa0633333}, {0xd14, 0x3333bc53},
381 {0xd18, 0x7a8f5b6f}, {0xd2c, 0xcc979975},
382 {0xd30, 0x00000000}, {0xd34, 0x80608000},
383 {0xd38, 0x00000000}, {0xd3c, 0x00127353},
384 {0xd40, 0x00000000}, {0xd44, 0x00000000},
385 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
386 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
387 {0xd58, 0x00000282}, {0xd5c, 0x30032064},
388 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
389 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
390 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
391 {0xd78, 0x000e3c24}, {0xe00, 0x2d2d2d2d},
392 {0xe04, 0x2d2d2d2d}, {0xe08, 0x0390272d},
393 {0xe10, 0x2d2d2d2d}, {0xe14, 0x2d2d2d2d},
394 {0xe18, 0x2d2d2d2d}, {0xe1c, 0x2d2d2d2d},
395 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
396 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
397 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
398 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
399 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
400 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
401 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
402 {0xe68, 0x001b2556}, {0xe6c, 0x00c00096},
403 {0xe70, 0x00c00096}, {0xe74, 0x01000056},
404 {0xe78, 0x01000014}, {0xe7c, 0x01000056},
405 {0xe80, 0x01000014}, {0xe84, 0x00c00096},
406 {0xe88, 0x01000056}, {0xe8c, 0x00c00096},
407 {0xed0, 0x00c00096}, {0xed4, 0x00c00096},
408 {0xed8, 0x00c00096}, {0xedc, 0x000000d6},
409 {0xee0, 0x000000d6}, {0xeec, 0x01c00016},
410 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
411 {0xf00, 0x00000300},
412 {0x820, 0x01000100}, {0x800, 0x83040000},
413 {0xffff, 0xffffffff},
414};
415
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400416static struct rtl8xxxu_reg32val rtl8192cu_phy_2t_init_table[] = {
417 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
418 {0x800, 0x80040002}, {0x804, 0x00000003},
419 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
420 {0x810, 0x10000330}, {0x814, 0x020c3d10},
421 {0x818, 0x02200385}, {0x81c, 0x00000000},
422 {0x820, 0x01000100}, {0x824, 0x00390004},
423 {0x828, 0x01000100}, {0x82c, 0x00390004},
424 {0x830, 0x27272727}, {0x834, 0x27272727},
425 {0x838, 0x27272727}, {0x83c, 0x27272727},
426 {0x840, 0x00010000}, {0x844, 0x00010000},
427 {0x848, 0x27272727}, {0x84c, 0x27272727},
428 {0x850, 0x00000000}, {0x854, 0x00000000},
429 {0x858, 0x569a569a}, {0x85c, 0x0c1b25a4},
430 {0x860, 0x66e60230}, {0x864, 0x061f0130},
431 {0x868, 0x27272727}, {0x86c, 0x2b2b2b27},
432 {0x870, 0x07000700}, {0x874, 0x22184000},
433 {0x878, 0x08080808}, {0x87c, 0x00000000},
434 {0x880, 0xc0083070}, {0x884, 0x000004d5},
435 {0x888, 0x00000000}, {0x88c, 0xcc0000c0},
436 {0x890, 0x00000800}, {0x894, 0xfffffffe},
437 {0x898, 0x40302010}, {0x89c, 0x00706050},
438 {0x900, 0x00000000}, {0x904, 0x00000023},
439 {0x908, 0x00000000}, {0x90c, 0x81121313},
440 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
441 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
442 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
443 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
444 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
445 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
446 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
447 {0xc00, 0x48071d40}, {0xc04, 0x03a05633},
448 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
449 {0xc10, 0x08800000}, {0xc14, 0x40000100},
450 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
451 {0xc20, 0x00000000}, {0xc24, 0x00000000},
452 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
453 {0xc30, 0x69e9ac44}, {0xc34, 0x469652cf},
454 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
455 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
456 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
457 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
458 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
459 {0xc60, 0x00000000}, {0xc64, 0x5116848b},
460 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
461 {0xc70, 0x2c7f000d}, {0xc74, 0x2186115b},
462 {0xc78, 0x0000001f}, {0xc7c, 0x00b99612},
463 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
464 {0xc88, 0x40000100}, {0xc8c, 0xa0e40000},
465 {0xc90, 0x00121820}, {0xc94, 0x00000000},
466 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
467 {0xca0, 0x00000000}, {0xca4, 0x00000080},
468 {0xca8, 0x00000000}, {0xcac, 0x00000000},
469 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
470 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
471 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
472 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
473 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
474 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
475 {0xce0, 0x00222222}, {0xce4, 0x00000000},
476 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
477 {0xd00, 0x00080740}, {0xd04, 0x00020403},
478 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
479 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
480 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
481 {0xd30, 0x00000000}, {0xd34, 0x80608000},
482 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
483 {0xd40, 0x00000000}, {0xd44, 0x00000000},
484 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
485 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
486 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
487 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
488 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
489 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
490 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
491 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
492 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
493 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
494 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
495 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
496 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
497 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
498 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
499 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
500 {0xe5c, 0x28160d05}, {0xe60, 0x00000010},
501 {0xe68, 0x001b25a4}, {0xe6c, 0x63db25a4},
502 {0xe70, 0x63db25a4}, {0xe74, 0x0c1b25a4},
503 {0xe78, 0x0c1b25a4}, {0xe7c, 0x0c1b25a4},
504 {0xe80, 0x0c1b25a4}, {0xe84, 0x63db25a4},
505 {0xe88, 0x0c1b25a4}, {0xe8c, 0x63db25a4},
506 {0xed0, 0x63db25a4}, {0xed4, 0x63db25a4},
507 {0xed8, 0x63db25a4}, {0xedc, 0x001b25a4},
508 {0xee0, 0x001b25a4}, {0xeec, 0x6fdb25a4},
509 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
510 {0xf00, 0x00000300},
511 {0xffff, 0xffffffff},
512};
513
514static struct rtl8xxxu_reg32val rtl8188ru_phy_1t_highpa_table[] = {
515 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
516 {0x040, 0x000c0004}, {0x800, 0x80040000},
517 {0x804, 0x00000001}, {0x808, 0x0000fc00},
518 {0x80c, 0x0000000a}, {0x810, 0x10005388},
519 {0x814, 0x020c3d10}, {0x818, 0x02200385},
520 {0x81c, 0x00000000}, {0x820, 0x01000100},
521 {0x824, 0x00390204}, {0x828, 0x00000000},
522 {0x82c, 0x00000000}, {0x830, 0x00000000},
523 {0x834, 0x00000000}, {0x838, 0x00000000},
524 {0x83c, 0x00000000}, {0x840, 0x00010000},
525 {0x844, 0x00000000}, {0x848, 0x00000000},
526 {0x84c, 0x00000000}, {0x850, 0x00000000},
527 {0x854, 0x00000000}, {0x858, 0x569a569a},
528 {0x85c, 0x001b25a4}, {0x860, 0x66e60230},
529 {0x864, 0x061f0130}, {0x868, 0x00000000},
530 {0x86c, 0x20202000}, {0x870, 0x03000300},
531 {0x874, 0x22004000}, {0x878, 0x00000808},
532 {0x87c, 0x00ffc3f1}, {0x880, 0xc0083070},
533 {0x884, 0x000004d5}, {0x888, 0x00000000},
534 {0x88c, 0xccc000c0}, {0x890, 0x00000800},
535 {0x894, 0xfffffffe}, {0x898, 0x40302010},
536 {0x89c, 0x00706050}, {0x900, 0x00000000},
537 {0x904, 0x00000023}, {0x908, 0x00000000},
538 {0x90c, 0x81121111}, {0xa00, 0x00d047c8},
539 {0xa04, 0x80ff000c}, {0xa08, 0x8c838300},
540 {0xa0c, 0x2e68120f}, {0xa10, 0x9500bb78},
541 {0xa14, 0x11144028}, {0xa18, 0x00881117},
542 {0xa1c, 0x89140f00}, {0xa20, 0x15160000},
543 {0xa24, 0x070b0f12}, {0xa28, 0x00000104},
544 {0xa2c, 0x00d30000}, {0xa70, 0x101fbf00},
545 {0xa74, 0x00000007}, {0xc00, 0x48071d40},
546 {0xc04, 0x03a05611}, {0xc08, 0x000000e4},
547 {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000},
548 {0xc14, 0x40000100}, {0xc18, 0x08800000},
549 {0xc1c, 0x40000100}, {0xc20, 0x00000000},
550 {0xc24, 0x00000000}, {0xc28, 0x00000000},
551 {0xc2c, 0x00000000}, {0xc30, 0x69e9ac44},
552 {0xc34, 0x469652cf}, {0xc38, 0x49795994},
553 {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f},
554 {0xc44, 0x000100b7}, {0xc48, 0xec020107},
555 {0xc4c, 0x007f037f}, {0xc50, 0x6954342e},
556 {0xc54, 0x43bc0094}, {0xc58, 0x6954342f},
557 {0xc5c, 0x433c0094}, {0xc60, 0x00000000},
558 {0xc64, 0x5116848b}, {0xc68, 0x47c00bff},
559 {0xc6c, 0x00000036}, {0xc70, 0x2c46000d},
560 {0xc74, 0x018610db}, {0xc78, 0x0000001f},
561 {0xc7c, 0x00b91612}, {0xc80, 0x24000090},
562 {0xc84, 0x20f60000}, {0xc88, 0x24000090},
563 {0xc8c, 0x20200000}, {0xc90, 0x00121820},
564 {0xc94, 0x00000000}, {0xc98, 0x00121820},
565 {0xc9c, 0x00007f7f}, {0xca0, 0x00000000},
566 {0xca4, 0x00000080}, {0xca8, 0x00000000},
567 {0xcac, 0x00000000}, {0xcb0, 0x00000000},
568 {0xcb4, 0x00000000}, {0xcb8, 0x00000000},
569 {0xcbc, 0x28000000}, {0xcc0, 0x00000000},
570 {0xcc4, 0x00000000}, {0xcc8, 0x00000000},
571 {0xccc, 0x00000000}, {0xcd0, 0x00000000},
572 {0xcd4, 0x00000000}, {0xcd8, 0x64b22427},
573 {0xcdc, 0x00766932}, {0xce0, 0x00222222},
574 {0xce4, 0x00000000}, {0xce8, 0x37644302},
575 {0xcec, 0x2f97d40c}, {0xd00, 0x00080740},
576 {0xd04, 0x00020401}, {0xd08, 0x0000907f},
577 {0xd0c, 0x20010201}, {0xd10, 0xa0633333},
578 {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b},
579 {0xd2c, 0xcc979975}, {0xd30, 0x00000000},
580 {0xd34, 0x80608000}, {0xd38, 0x00000000},
581 {0xd3c, 0x00027293}, {0xd40, 0x00000000},
582 {0xd44, 0x00000000}, {0xd48, 0x00000000},
583 {0xd4c, 0x00000000}, {0xd50, 0x6437140a},
584 {0xd54, 0x00000000}, {0xd58, 0x00000000},
585 {0xd5c, 0x30032064}, {0xd60, 0x4653de68},
586 {0xd64, 0x04518a3c}, {0xd68, 0x00002101},
587 {0xd6c, 0x2a201c16}, {0xd70, 0x1812362e},
588 {0xd74, 0x322c2220}, {0xd78, 0x000e3c24},
589 {0xe00, 0x24242424}, {0xe04, 0x24242424},
590 {0xe08, 0x03902024}, {0xe10, 0x24242424},
591 {0xe14, 0x24242424}, {0xe18, 0x24242424},
592 {0xe1c, 0x24242424}, {0xe28, 0x00000000},
593 {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f},
594 {0xe38, 0x02140102}, {0xe3c, 0x681604c2},
595 {0xe40, 0x01007c00}, {0xe44, 0x01004800},
596 {0xe48, 0xfb000000}, {0xe4c, 0x000028d1},
597 {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f},
598 {0xe58, 0x02140102}, {0xe5c, 0x28160d05},
599 {0xe60, 0x00000008}, {0xe68, 0x001b25a4},
600 {0xe6c, 0x631b25a0}, {0xe70, 0x631b25a0},
601 {0xe74, 0x081b25a0}, {0xe78, 0x081b25a0},
602 {0xe7c, 0x081b25a0}, {0xe80, 0x081b25a0},
603 {0xe84, 0x631b25a0}, {0xe88, 0x081b25a0},
604 {0xe8c, 0x631b25a0}, {0xed0, 0x631b25a0},
605 {0xed4, 0x631b25a0}, {0xed8, 0x631b25a0},
606 {0xedc, 0x001b25a0}, {0xee0, 0x001b25a0},
607 {0xeec, 0x6b1b25a0}, {0xee8, 0x31555448},
608 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
609 {0xf00, 0x00000300},
610 {0xffff, 0xffffffff},
611};
612
Jes Sorensenae14c5d2016-04-07 14:19:21 -0400613static struct rtl8xxxu_reg32val rtl8192eu_phy_init_table[] = {
614 {0x800, 0x80040000}, {0x804, 0x00000003},
615 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
616 {0x810, 0x10001331}, {0x814, 0x020c3d10},
617 {0x818, 0x02220385}, {0x81c, 0x00000000},
618 {0x820, 0x01000100}, {0x824, 0x00390204},
619 {0x828, 0x01000100}, {0x82c, 0x00390204},
620 {0x830, 0x32323232}, {0x834, 0x30303030},
621 {0x838, 0x30303030}, {0x83c, 0x30303030},
622 {0x840, 0x00010000}, {0x844, 0x00010000},
623 {0x848, 0x28282828}, {0x84c, 0x28282828},
624 {0x850, 0x00000000}, {0x854, 0x00000000},
625 {0x858, 0x009a009a}, {0x85c, 0x01000014},
626 {0x860, 0x66f60000}, {0x864, 0x061f0000},
627 {0x868, 0x30303030}, {0x86c, 0x30303030},
628 {0x870, 0x00000000}, {0x874, 0x55004200},
629 {0x878, 0x08080808}, {0x87c, 0x00000000},
630 {0x880, 0xb0000c1c}, {0x884, 0x00000001},
631 {0x888, 0x00000000}, {0x88c, 0xcc0000c0},
632 {0x890, 0x00000800}, {0x894, 0xfffffffe},
633 {0x898, 0x40302010}, {0x900, 0x00000000},
634 {0x904, 0x00000023}, {0x908, 0x00000000},
635 {0x90c, 0x81121313}, {0x910, 0x806c0001},
636 {0x914, 0x00000001}, {0x918, 0x00000000},
637 {0x91c, 0x00010000}, {0x924, 0x00000001},
638 {0x928, 0x00000000}, {0x92c, 0x00000000},
639 {0x930, 0x00000000}, {0x934, 0x00000000},
640 {0x938, 0x00000000}, {0x93c, 0x00000000},
641 {0x940, 0x00000000}, {0x944, 0x00000000},
642 {0x94c, 0x00000008}, {0xa00, 0x00d0c7c8},
643 {0xa04, 0x81ff000c}, {0xa08, 0x8c838300},
644 {0xa0c, 0x2e68120f}, {0xa10, 0x95009b78},
645 {0xa14, 0x1114d028}, {0xa18, 0x00881117},
646 {0xa1c, 0x89140f00}, {0xa20, 0x1a1b0000},
647 {0xa24, 0x090e1317}, {0xa28, 0x00000204},
648 {0xa2c, 0x00d30000}, {0xa70, 0x101fff00},
649 {0xa74, 0x00000007}, {0xa78, 0x00000900},
650 {0xa7c, 0x225b0606}, {0xa80, 0x218075b1},
651 {0xb38, 0x00000000}, {0xc00, 0x48071d40},
652 {0xc04, 0x03a05633}, {0xc08, 0x000000e4},
653 {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000},
654 {0xc14, 0x40000100}, {0xc18, 0x08800000},
655 {0xc1c, 0x40000100}, {0xc20, 0x00000000},
656 {0xc24, 0x00000000}, {0xc28, 0x00000000},
657 {0xc2c, 0x00000000}, {0xc30, 0x69e9ac47},
658 {0xc34, 0x469652af}, {0xc38, 0x49795994},
659 {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f},
660 {0xc44, 0x000100b7}, {0xc48, 0xec020107},
661 {0xc4c, 0x007f037f},
662#ifdef EXT_PA_8192EU
663 /* External PA or external LNA */
664 {0xc50, 0x00340220},
665#else
666 {0xc50, 0x00340020},
667#endif
668 {0xc54, 0x0080801f},
669#ifdef EXT_PA_8192EU
670 /* External PA or external LNA */
671 {0xc58, 0x00000220},
672#else
673 {0xc58, 0x00000020},
674#endif
675 {0xc5c, 0x00248492}, {0xc60, 0x00000000},
676 {0xc64, 0x7112848b}, {0xc68, 0x47c00bff},
677 {0xc6c, 0x00000036}, {0xc70, 0x00000600},
678 {0xc74, 0x02013169}, {0xc78, 0x0000001f},
679 {0xc7c, 0x00b91612},
680#ifdef EXT_PA_8192EU
681 /* External PA or external LNA */
682 {0xc80, 0x2d4000b5},
683#else
684 {0xc80, 0x40000100},
685#endif
686 {0xc84, 0x21f60000},
687#ifdef EXT_PA_8192EU
688 /* External PA or external LNA */
689 {0xc88, 0x2d4000b5},
690#else
691 {0xc88, 0x40000100},
692#endif
693 {0xc8c, 0xa0e40000}, {0xc90, 0x00121820},
694 {0xc94, 0x00000000}, {0xc98, 0x00121820},
695 {0xc9c, 0x00007f7f}, {0xca0, 0x00000000},
696 {0xca4, 0x000300a0}, {0xca8, 0x00000000},
697 {0xcac, 0x00000000}, {0xcb0, 0x00000000},
698 {0xcb4, 0x00000000}, {0xcb8, 0x00000000},
699 {0xcbc, 0x28000000}, {0xcc0, 0x00000000},
700 {0xcc4, 0x00000000}, {0xcc8, 0x00000000},
701 {0xccc, 0x00000000}, {0xcd0, 0x00000000},
702 {0xcd4, 0x00000000}, {0xcd8, 0x64b22427},
703 {0xcdc, 0x00766932}, {0xce0, 0x00222222},
704 {0xce4, 0x00040000}, {0xce8, 0x77644302},
705 {0xcec, 0x2f97d40c}, {0xd00, 0x00080740},
706 {0xd04, 0x00020403}, {0xd08, 0x0000907f},
707 {0xd0c, 0x20010201}, {0xd10, 0xa0633333},
708 {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b},
709 {0xd1c, 0x0000007f}, {0xd2c, 0xcc979975},
710 {0xd30, 0x00000000}, {0xd34, 0x80608000},
711 {0xd38, 0x00000000}, {0xd3c, 0x00127353},
712 {0xd40, 0x00000000}, {0xd44, 0x00000000},
713 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
714 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
715 {0xd58, 0x00000282}, {0xd5c, 0x30032064},
716 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
717 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
718 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
719 {0xd78, 0x000e3c24}, {0xd80, 0x01081008},
720 {0xd84, 0x00000800}, {0xd88, 0xf0b50000},
721 {0xe00, 0x30303030}, {0xe04, 0x30303030},
722 {0xe08, 0x03903030}, {0xe10, 0x30303030},
723 {0xe14, 0x30303030}, {0xe18, 0x30303030},
724 {0xe1c, 0x30303030}, {0xe28, 0x00000000},
725 {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f},
726 {0xe38, 0x02140102}, {0xe3c, 0x681604c2},
727 {0xe40, 0x01007c00}, {0xe44, 0x01004800},
728 {0xe48, 0xfb000000}, {0xe4c, 0x000028d1},
729 {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f},
730 {0xe58, 0x02140102}, {0xe5c, 0x28160d05},
731 {0xe60, 0x00000008}, {0xe68, 0x0fc05656},
732 {0xe6c, 0x03c09696}, {0xe70, 0x03c09696},
733 {0xe74, 0x0c005656}, {0xe78, 0x0c005656},
734 {0xe7c, 0x0c005656}, {0xe80, 0x0c005656},
735 {0xe84, 0x03c09696}, {0xe88, 0x0c005656},
736 {0xe8c, 0x03c09696}, {0xed0, 0x03c09696},
737 {0xed4, 0x03c09696}, {0xed8, 0x03c09696},
738 {0xedc, 0x0000d6d6}, {0xee0, 0x0000d6d6},
739 {0xeec, 0x0fc01616}, {0xee4, 0xb0000c1c},
740 {0xee8, 0x00000001}, {0xf14, 0x00000003},
741 {0xf4c, 0x00000000}, {0xf00, 0x00000300},
742 {0xffff, 0xffffffff},
743};
744
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400745static struct rtl8xxxu_reg32val rtl8xxx_agc_standard_table[] = {
746 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
747 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
748 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
749 {0xc78, 0x7a060001}, {0xc78, 0x79070001},
750 {0xc78, 0x78080001}, {0xc78, 0x77090001},
751 {0xc78, 0x760a0001}, {0xc78, 0x750b0001},
752 {0xc78, 0x740c0001}, {0xc78, 0x730d0001},
753 {0xc78, 0x720e0001}, {0xc78, 0x710f0001},
754 {0xc78, 0x70100001}, {0xc78, 0x6f110001},
755 {0xc78, 0x6e120001}, {0xc78, 0x6d130001},
756 {0xc78, 0x6c140001}, {0xc78, 0x6b150001},
757 {0xc78, 0x6a160001}, {0xc78, 0x69170001},
758 {0xc78, 0x68180001}, {0xc78, 0x67190001},
759 {0xc78, 0x661a0001}, {0xc78, 0x651b0001},
760 {0xc78, 0x641c0001}, {0xc78, 0x631d0001},
761 {0xc78, 0x621e0001}, {0xc78, 0x611f0001},
762 {0xc78, 0x60200001}, {0xc78, 0x49210001},
763 {0xc78, 0x48220001}, {0xc78, 0x47230001},
764 {0xc78, 0x46240001}, {0xc78, 0x45250001},
765 {0xc78, 0x44260001}, {0xc78, 0x43270001},
766 {0xc78, 0x42280001}, {0xc78, 0x41290001},
767 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
768 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
769 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
770 {0xc78, 0x21300001}, {0xc78, 0x20310001},
771 {0xc78, 0x06320001}, {0xc78, 0x05330001},
772 {0xc78, 0x04340001}, {0xc78, 0x03350001},
773 {0xc78, 0x02360001}, {0xc78, 0x01370001},
774 {0xc78, 0x00380001}, {0xc78, 0x00390001},
775 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
776 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
777 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
778 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
779 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
780 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
781 {0xc78, 0x7a460001}, {0xc78, 0x79470001},
782 {0xc78, 0x78480001}, {0xc78, 0x77490001},
783 {0xc78, 0x764a0001}, {0xc78, 0x754b0001},
784 {0xc78, 0x744c0001}, {0xc78, 0x734d0001},
785 {0xc78, 0x724e0001}, {0xc78, 0x714f0001},
786 {0xc78, 0x70500001}, {0xc78, 0x6f510001},
787 {0xc78, 0x6e520001}, {0xc78, 0x6d530001},
788 {0xc78, 0x6c540001}, {0xc78, 0x6b550001},
789 {0xc78, 0x6a560001}, {0xc78, 0x69570001},
790 {0xc78, 0x68580001}, {0xc78, 0x67590001},
791 {0xc78, 0x665a0001}, {0xc78, 0x655b0001},
792 {0xc78, 0x645c0001}, {0xc78, 0x635d0001},
793 {0xc78, 0x625e0001}, {0xc78, 0x615f0001},
794 {0xc78, 0x60600001}, {0xc78, 0x49610001},
795 {0xc78, 0x48620001}, {0xc78, 0x47630001},
796 {0xc78, 0x46640001}, {0xc78, 0x45650001},
797 {0xc78, 0x44660001}, {0xc78, 0x43670001},
798 {0xc78, 0x42680001}, {0xc78, 0x41690001},
799 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
800 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
801 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
802 {0xc78, 0x21700001}, {0xc78, 0x20710001},
803 {0xc78, 0x06720001}, {0xc78, 0x05730001},
804 {0xc78, 0x04740001}, {0xc78, 0x03750001},
805 {0xc78, 0x02760001}, {0xc78, 0x01770001},
806 {0xc78, 0x00780001}, {0xc78, 0x00790001},
807 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
808 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
809 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
810 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
811 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
812 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
813 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
814 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
815 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
816 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
817 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
818 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
819 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
820 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
821 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
822 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
823 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
824 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
825 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
826 {0xffff, 0xffffffff}
827};
828
829static struct rtl8xxxu_reg32val rtl8xxx_agc_highpa_table[] = {
830 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
831 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
832 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
833 {0xc78, 0x7b060001}, {0xc78, 0x7b070001},
834 {0xc78, 0x7b080001}, {0xc78, 0x7a090001},
835 {0xc78, 0x790a0001}, {0xc78, 0x780b0001},
836 {0xc78, 0x770c0001}, {0xc78, 0x760d0001},
837 {0xc78, 0x750e0001}, {0xc78, 0x740f0001},
838 {0xc78, 0x73100001}, {0xc78, 0x72110001},
839 {0xc78, 0x71120001}, {0xc78, 0x70130001},
840 {0xc78, 0x6f140001}, {0xc78, 0x6e150001},
841 {0xc78, 0x6d160001}, {0xc78, 0x6c170001},
842 {0xc78, 0x6b180001}, {0xc78, 0x6a190001},
843 {0xc78, 0x691a0001}, {0xc78, 0x681b0001},
844 {0xc78, 0x671c0001}, {0xc78, 0x661d0001},
845 {0xc78, 0x651e0001}, {0xc78, 0x641f0001},
846 {0xc78, 0x63200001}, {0xc78, 0x62210001},
847 {0xc78, 0x61220001}, {0xc78, 0x60230001},
848 {0xc78, 0x46240001}, {0xc78, 0x45250001},
849 {0xc78, 0x44260001}, {0xc78, 0x43270001},
850 {0xc78, 0x42280001}, {0xc78, 0x41290001},
851 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
852 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
853 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
854 {0xc78, 0x21300001}, {0xc78, 0x20310001},
855 {0xc78, 0x06320001}, {0xc78, 0x05330001},
856 {0xc78, 0x04340001}, {0xc78, 0x03350001},
857 {0xc78, 0x02360001}, {0xc78, 0x01370001},
858 {0xc78, 0x00380001}, {0xc78, 0x00390001},
859 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
860 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
861 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
862 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
863 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
864 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
865 {0xc78, 0x7b460001}, {0xc78, 0x7b470001},
866 {0xc78, 0x7b480001}, {0xc78, 0x7a490001},
867 {0xc78, 0x794a0001}, {0xc78, 0x784b0001},
868 {0xc78, 0x774c0001}, {0xc78, 0x764d0001},
869 {0xc78, 0x754e0001}, {0xc78, 0x744f0001},
870 {0xc78, 0x73500001}, {0xc78, 0x72510001},
871 {0xc78, 0x71520001}, {0xc78, 0x70530001},
872 {0xc78, 0x6f540001}, {0xc78, 0x6e550001},
873 {0xc78, 0x6d560001}, {0xc78, 0x6c570001},
874 {0xc78, 0x6b580001}, {0xc78, 0x6a590001},
875 {0xc78, 0x695a0001}, {0xc78, 0x685b0001},
876 {0xc78, 0x675c0001}, {0xc78, 0x665d0001},
877 {0xc78, 0x655e0001}, {0xc78, 0x645f0001},
878 {0xc78, 0x63600001}, {0xc78, 0x62610001},
879 {0xc78, 0x61620001}, {0xc78, 0x60630001},
880 {0xc78, 0x46640001}, {0xc78, 0x45650001},
881 {0xc78, 0x44660001}, {0xc78, 0x43670001},
882 {0xc78, 0x42680001}, {0xc78, 0x41690001},
883 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
884 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
885 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
886 {0xc78, 0x21700001}, {0xc78, 0x20710001},
887 {0xc78, 0x06720001}, {0xc78, 0x05730001},
888 {0xc78, 0x04740001}, {0xc78, 0x03750001},
889 {0xc78, 0x02760001}, {0xc78, 0x01770001},
890 {0xc78, 0x00780001}, {0xc78, 0x00790001},
891 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
892 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
893 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
894 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
895 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
896 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
897 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
898 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
899 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
900 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
901 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
902 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
903 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
904 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
905 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
906 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
907 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
908 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
909 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
910 {0xffff, 0xffffffff}
911};
912
Jes Sorensenb9f498e2016-02-29 17:04:18 -0500913static struct rtl8xxxu_reg32val rtl8xxx_agc_8723bu_table[] = {
914 {0xc78, 0xfd000001}, {0xc78, 0xfc010001},
915 {0xc78, 0xfb020001}, {0xc78, 0xfa030001},
916 {0xc78, 0xf9040001}, {0xc78, 0xf8050001},
917 {0xc78, 0xf7060001}, {0xc78, 0xf6070001},
918 {0xc78, 0xf5080001}, {0xc78, 0xf4090001},
919 {0xc78, 0xf30a0001}, {0xc78, 0xf20b0001},
920 {0xc78, 0xf10c0001}, {0xc78, 0xf00d0001},
921 {0xc78, 0xef0e0001}, {0xc78, 0xee0f0001},
922 {0xc78, 0xed100001}, {0xc78, 0xec110001},
923 {0xc78, 0xeb120001}, {0xc78, 0xea130001},
924 {0xc78, 0xe9140001}, {0xc78, 0xe8150001},
925 {0xc78, 0xe7160001}, {0xc78, 0xe6170001},
926 {0xc78, 0xe5180001}, {0xc78, 0xe4190001},
927 {0xc78, 0xe31a0001}, {0xc78, 0xa51b0001},
928 {0xc78, 0xa41c0001}, {0xc78, 0xa31d0001},
929 {0xc78, 0x671e0001}, {0xc78, 0x661f0001},
930 {0xc78, 0x65200001}, {0xc78, 0x64210001},
931 {0xc78, 0x63220001}, {0xc78, 0x4a230001},
932 {0xc78, 0x49240001}, {0xc78, 0x48250001},
933 {0xc78, 0x47260001}, {0xc78, 0x46270001},
934 {0xc78, 0x45280001}, {0xc78, 0x44290001},
935 {0xc78, 0x432a0001}, {0xc78, 0x422b0001},
936 {0xc78, 0x292c0001}, {0xc78, 0x282d0001},
937 {0xc78, 0x272e0001}, {0xc78, 0x262f0001},
938 {0xc78, 0x0a300001}, {0xc78, 0x09310001},
939 {0xc78, 0x08320001}, {0xc78, 0x07330001},
940 {0xc78, 0x06340001}, {0xc78, 0x05350001},
941 {0xc78, 0x04360001}, {0xc78, 0x03370001},
942 {0xc78, 0x02380001}, {0xc78, 0x01390001},
943 {0xc78, 0x013a0001}, {0xc78, 0x013b0001},
944 {0xc78, 0x013c0001}, {0xc78, 0x013d0001},
945 {0xc78, 0x013e0001}, {0xc78, 0x013f0001},
946 {0xc78, 0xfc400001}, {0xc78, 0xfb410001},
947 {0xc78, 0xfa420001}, {0xc78, 0xf9430001},
948 {0xc78, 0xf8440001}, {0xc78, 0xf7450001},
949 {0xc78, 0xf6460001}, {0xc78, 0xf5470001},
950 {0xc78, 0xf4480001}, {0xc78, 0xf3490001},
951 {0xc78, 0xf24a0001}, {0xc78, 0xf14b0001},
952 {0xc78, 0xf04c0001}, {0xc78, 0xef4d0001},
953 {0xc78, 0xee4e0001}, {0xc78, 0xed4f0001},
954 {0xc78, 0xec500001}, {0xc78, 0xeb510001},
955 {0xc78, 0xea520001}, {0xc78, 0xe9530001},
956 {0xc78, 0xe8540001}, {0xc78, 0xe7550001},
957 {0xc78, 0xe6560001}, {0xc78, 0xe5570001},
958 {0xc78, 0xe4580001}, {0xc78, 0xe3590001},
959 {0xc78, 0xa65a0001}, {0xc78, 0xa55b0001},
960 {0xc78, 0xa45c0001}, {0xc78, 0xa35d0001},
961 {0xc78, 0x675e0001}, {0xc78, 0x665f0001},
962 {0xc78, 0x65600001}, {0xc78, 0x64610001},
963 {0xc78, 0x63620001}, {0xc78, 0x62630001},
964 {0xc78, 0x61640001}, {0xc78, 0x48650001},
965 {0xc78, 0x47660001}, {0xc78, 0x46670001},
966 {0xc78, 0x45680001}, {0xc78, 0x44690001},
967 {0xc78, 0x436a0001}, {0xc78, 0x426b0001},
968 {0xc78, 0x286c0001}, {0xc78, 0x276d0001},
969 {0xc78, 0x266e0001}, {0xc78, 0x256f0001},
970 {0xc78, 0x24700001}, {0xc78, 0x09710001},
971 {0xc78, 0x08720001}, {0xc78, 0x07730001},
972 {0xc78, 0x06740001}, {0xc78, 0x05750001},
973 {0xc78, 0x04760001}, {0xc78, 0x03770001},
974 {0xc78, 0x02780001}, {0xc78, 0x01790001},
975 {0xc78, 0x017a0001}, {0xc78, 0x017b0001},
976 {0xc78, 0x017c0001}, {0xc78, 0x017d0001},
977 {0xc78, 0x017e0001}, {0xc78, 0x017f0001},
978 {0xc50, 0x69553422},
979 {0xc50, 0x69553420},
980 {0x824, 0x00390204},
981 {0xffff, 0xffffffff}
982};
983
Jes Sorensene2932782016-04-07 14:19:20 -0400984static struct rtl8xxxu_reg32val rtl8xxx_agc_8192eu_std_table[] = {
985 {0xc78, 0xfb000001}, {0xc78, 0xfb010001},
986 {0xc78, 0xfb020001}, {0xc78, 0xfb030001},
987 {0xc78, 0xfb040001}, {0xc78, 0xfb050001},
988 {0xc78, 0xfa060001}, {0xc78, 0xf9070001},
989 {0xc78, 0xf8080001}, {0xc78, 0xf7090001},
990 {0xc78, 0xf60a0001}, {0xc78, 0xf50b0001},
991 {0xc78, 0xf40c0001}, {0xc78, 0xf30d0001},
992 {0xc78, 0xf20e0001}, {0xc78, 0xf10f0001},
993 {0xc78, 0xf0100001}, {0xc78, 0xef110001},
994 {0xc78, 0xee120001}, {0xc78, 0xed130001},
995 {0xc78, 0xec140001}, {0xc78, 0xeb150001},
996 {0xc78, 0xea160001}, {0xc78, 0xe9170001},
997 {0xc78, 0xe8180001}, {0xc78, 0xe7190001},
998 {0xc78, 0xc81a0001}, {0xc78, 0xc71b0001},
999 {0xc78, 0xc61c0001}, {0xc78, 0x071d0001},
1000 {0xc78, 0x061e0001}, {0xc78, 0x051f0001},
1001 {0xc78, 0x04200001}, {0xc78, 0x03210001},
1002 {0xc78, 0xaa220001}, {0xc78, 0xa9230001},
1003 {0xc78, 0xa8240001}, {0xc78, 0xa7250001},
1004 {0xc78, 0xa6260001}, {0xc78, 0x85270001},
1005 {0xc78, 0x84280001}, {0xc78, 0x83290001},
1006 {0xc78, 0x252a0001}, {0xc78, 0x242b0001},
1007 {0xc78, 0x232c0001}, {0xc78, 0x222d0001},
1008 {0xc78, 0x672e0001}, {0xc78, 0x662f0001},
1009 {0xc78, 0x65300001}, {0xc78, 0x64310001},
1010 {0xc78, 0x63320001}, {0xc78, 0x62330001},
1011 {0xc78, 0x61340001}, {0xc78, 0x45350001},
1012 {0xc78, 0x44360001}, {0xc78, 0x43370001},
1013 {0xc78, 0x42380001}, {0xc78, 0x41390001},
1014 {0xc78, 0x403a0001}, {0xc78, 0x403b0001},
1015 {0xc78, 0x403c0001}, {0xc78, 0x403d0001},
1016 {0xc78, 0x403e0001}, {0xc78, 0x403f0001},
1017 {0xc78, 0xfb400001}, {0xc78, 0xfb410001},
1018 {0xc78, 0xfb420001}, {0xc78, 0xfb430001},
1019 {0xc78, 0xfb440001}, {0xc78, 0xfb450001},
1020 {0xc78, 0xfa460001}, {0xc78, 0xf9470001},
1021 {0xc78, 0xf8480001}, {0xc78, 0xf7490001},
1022 {0xc78, 0xf64a0001}, {0xc78, 0xf54b0001},
1023 {0xc78, 0xf44c0001}, {0xc78, 0xf34d0001},
1024 {0xc78, 0xf24e0001}, {0xc78, 0xf14f0001},
1025 {0xc78, 0xf0500001}, {0xc78, 0xef510001},
1026 {0xc78, 0xee520001}, {0xc78, 0xed530001},
1027 {0xc78, 0xec540001}, {0xc78, 0xeb550001},
1028 {0xc78, 0xea560001}, {0xc78, 0xe9570001},
1029 {0xc78, 0xe8580001}, {0xc78, 0xe7590001},
1030 {0xc78, 0xe65a0001}, {0xc78, 0xe55b0001},
1031 {0xc78, 0xe45c0001}, {0xc78, 0xe35d0001},
1032 {0xc78, 0xe25e0001}, {0xc78, 0xe15f0001},
1033 {0xc78, 0x8a600001}, {0xc78, 0x89610001},
1034 {0xc78, 0x88620001}, {0xc78, 0x87630001},
1035 {0xc78, 0x86640001}, {0xc78, 0x85650001},
1036 {0xc78, 0x84660001}, {0xc78, 0x83670001},
1037 {0xc78, 0x82680001}, {0xc78, 0x6b690001},
1038 {0xc78, 0x6a6a0001}, {0xc78, 0x696b0001},
1039 {0xc78, 0x686c0001}, {0xc78, 0x676d0001},
1040 {0xc78, 0x666e0001}, {0xc78, 0x656f0001},
1041 {0xc78, 0x64700001}, {0xc78, 0x63710001},
1042 {0xc78, 0x62720001}, {0xc78, 0x61730001},
1043 {0xc78, 0x49740001}, {0xc78, 0x48750001},
1044 {0xc78, 0x47760001}, {0xc78, 0x46770001},
1045 {0xc78, 0x45780001}, {0xc78, 0x44790001},
1046 {0xc78, 0x437a0001}, {0xc78, 0x427b0001},
1047 {0xc78, 0x417c0001}, {0xc78, 0x407d0001},
1048 {0xc78, 0x407e0001}, {0xc78, 0x407f0001},
1049 {0xc50, 0x00040022}, {0xc50, 0x00040020},
1050 {0xffff, 0xffffffff}
1051};
1052
1053static struct rtl8xxxu_reg32val rtl8xxx_agc_8192eu_highpa_table[] = {
1054 {0xc78, 0xfa000001}, {0xc78, 0xf9010001},
1055 {0xc78, 0xf8020001}, {0xc78, 0xf7030001},
1056 {0xc78, 0xf6040001}, {0xc78, 0xf5050001},
1057 {0xc78, 0xf4060001}, {0xc78, 0xf3070001},
1058 {0xc78, 0xf2080001}, {0xc78, 0xf1090001},
1059 {0xc78, 0xf00a0001}, {0xc78, 0xef0b0001},
1060 {0xc78, 0xee0c0001}, {0xc78, 0xed0d0001},
1061 {0xc78, 0xec0e0001}, {0xc78, 0xeb0f0001},
1062 {0xc78, 0xea100001}, {0xc78, 0xe9110001},
1063 {0xc78, 0xe8120001}, {0xc78, 0xe7130001},
1064 {0xc78, 0xe6140001}, {0xc78, 0xe5150001},
1065 {0xc78, 0xe4160001}, {0xc78, 0xe3170001},
1066 {0xc78, 0xe2180001}, {0xc78, 0xe1190001},
1067 {0xc78, 0x8a1a0001}, {0xc78, 0x891b0001},
1068 {0xc78, 0x881c0001}, {0xc78, 0x871d0001},
1069 {0xc78, 0x861e0001}, {0xc78, 0x851f0001},
1070 {0xc78, 0x84200001}, {0xc78, 0x83210001},
1071 {0xc78, 0x82220001}, {0xc78, 0x6a230001},
1072 {0xc78, 0x69240001}, {0xc78, 0x68250001},
1073 {0xc78, 0x67260001}, {0xc78, 0x66270001},
1074 {0xc78, 0x65280001}, {0xc78, 0x64290001},
1075 {0xc78, 0x632a0001}, {0xc78, 0x622b0001},
1076 {0xc78, 0x612c0001}, {0xc78, 0x602d0001},
1077 {0xc78, 0x472e0001}, {0xc78, 0x462f0001},
1078 {0xc78, 0x45300001}, {0xc78, 0x44310001},
1079 {0xc78, 0x43320001}, {0xc78, 0x42330001},
1080 {0xc78, 0x41340001}, {0xc78, 0x40350001},
1081 {0xc78, 0x40360001}, {0xc78, 0x40370001},
1082 {0xc78, 0x40380001}, {0xc78, 0x40390001},
1083 {0xc78, 0x403a0001}, {0xc78, 0x403b0001},
1084 {0xc78, 0x403c0001}, {0xc78, 0x403d0001},
1085 {0xc78, 0x403e0001}, {0xc78, 0x403f0001},
1086 {0xc78, 0xfa400001}, {0xc78, 0xf9410001},
1087 {0xc78, 0xf8420001}, {0xc78, 0xf7430001},
1088 {0xc78, 0xf6440001}, {0xc78, 0xf5450001},
1089 {0xc78, 0xf4460001}, {0xc78, 0xf3470001},
1090 {0xc78, 0xf2480001}, {0xc78, 0xf1490001},
1091 {0xc78, 0xf04a0001}, {0xc78, 0xef4b0001},
1092 {0xc78, 0xee4c0001}, {0xc78, 0xed4d0001},
1093 {0xc78, 0xec4e0001}, {0xc78, 0xeb4f0001},
1094 {0xc78, 0xea500001}, {0xc78, 0xe9510001},
1095 {0xc78, 0xe8520001}, {0xc78, 0xe7530001},
1096 {0xc78, 0xe6540001}, {0xc78, 0xe5550001},
1097 {0xc78, 0xe4560001}, {0xc78, 0xe3570001},
1098 {0xc78, 0xe2580001}, {0xc78, 0xe1590001},
1099 {0xc78, 0x8a5a0001}, {0xc78, 0x895b0001},
1100 {0xc78, 0x885c0001}, {0xc78, 0x875d0001},
1101 {0xc78, 0x865e0001}, {0xc78, 0x855f0001},
1102 {0xc78, 0x84600001}, {0xc78, 0x83610001},
1103 {0xc78, 0x82620001}, {0xc78, 0x6a630001},
1104 {0xc78, 0x69640001}, {0xc78, 0x68650001},
1105 {0xc78, 0x67660001}, {0xc78, 0x66670001},
1106 {0xc78, 0x65680001}, {0xc78, 0x64690001},
1107 {0xc78, 0x636a0001}, {0xc78, 0x626b0001},
1108 {0xc78, 0x616c0001}, {0xc78, 0x606d0001},
1109 {0xc78, 0x476e0001}, {0xc78, 0x466f0001},
1110 {0xc78, 0x45700001}, {0xc78, 0x44710001},
1111 {0xc78, 0x43720001}, {0xc78, 0x42730001},
1112 {0xc78, 0x41740001}, {0xc78, 0x40750001},
1113 {0xc78, 0x40760001}, {0xc78, 0x40770001},
1114 {0xc78, 0x40780001}, {0xc78, 0x40790001},
1115 {0xc78, 0x407a0001}, {0xc78, 0x407b0001},
1116 {0xc78, 0x407c0001}, {0xc78, 0x407d0001},
1117 {0xc78, 0x407e0001}, {0xc78, 0x407f0001},
1118 {0xc50, 0x00040222}, {0xc50, 0x00040220},
1119 {0xffff, 0xffffffff}
1120};
1121
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001122static struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = {
1123 {0x00, 0x00030159}, {0x01, 0x00031284},
1124 {0x02, 0x00098000}, {0x03, 0x00039c63},
1125 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1126 {0x0a, 0x0001a3f1}, {0x0b, 0x00014787},
1127 {0x0c, 0x000896fe}, {0x0d, 0x0000e02c},
1128 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1129 {0x19, 0x00000000}, {0x1a, 0x00030355},
1130 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1131 {0x1d, 0x000a1250}, {0x1e, 0x0000024f},
1132 {0x1f, 0x00000000}, {0x20, 0x0000b614},
1133 {0x21, 0x0006c000}, {0x22, 0x00000000},
1134 {0x23, 0x00001558}, {0x24, 0x00000060},
1135 {0x25, 0x00000483}, {0x26, 0x0004f000},
1136 {0x27, 0x000ec7d9}, {0x28, 0x00057730},
1137 {0x29, 0x00004783}, {0x2a, 0x00000001},
1138 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1139 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1140 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1141 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1142 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1143 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1144 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1145 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1146 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1147 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1148 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1149 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1150 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1151 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1152 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1153 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1154 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1155 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1156 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1157 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1158 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1159 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1160 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1161 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1162 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1163 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1164 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1165 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1166 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1167 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1168 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1169 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1170 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1171 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1172 {0x10, 0x00000000}, {0x11, 0x00000000},
1173 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1174 {0x10, 0x0009000f}, {0x11, 0x00023100},
1175 {0x12, 0x00032000}, {0x12, 0x00071000},
1176 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1177 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1178 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1179 {0x13, 0x00018493}, {0x13, 0x0001429b},
1180 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1181 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1182 {0x13, 0x00000020}, {0x14, 0x0001944c},
1183 {0x14, 0x00059444}, {0x14, 0x0009944c},
1184 {0x14, 0x000d9444}, {0x15, 0x0000f474},
1185 {0x15, 0x0004f477}, {0x15, 0x0008f455},
1186 {0x15, 0x000cf455}, {0x16, 0x00000339},
1187 {0x16, 0x00040339}, {0x16, 0x00080339},
1188 {0x16, 0x000c0366}, {0x00, 0x00010159},
1189 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1190 {0xfe, 0x00000000}, {0x1f, 0x00000003},
1191 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1192 {0x1e, 0x00000247}, {0x1f, 0x00000000},
1193 {0x00, 0x00030159},
1194 {0xff, 0xffffffff}
1195};
1196
Jes Sorensen22a31d42016-02-29 17:04:15 -05001197static struct rtl8xxxu_rfregval rtl8723bu_radioa_1t_init_table[] = {
1198 {0x00, 0x00010000}, {0xb0, 0x000dffe0},
1199 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1200 {0xfe, 0x00000000}, {0xb1, 0x00000018},
1201 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1202 {0xfe, 0x00000000}, {0xb2, 0x00084c00},
1203 {0xb5, 0x0000d2cc}, {0xb6, 0x000925aa},
1204 {0xb7, 0x00000010}, {0xb8, 0x0000907f},
1205 {0x5c, 0x00000002}, {0x7c, 0x00000002},
1206 {0x7e, 0x00000005}, {0x8b, 0x0006fc00},
1207 {0xb0, 0x000ff9f0}, {0x1c, 0x000739d2},
1208 {0x1e, 0x00000000}, {0xdf, 0x00000780},
1209 {0x50, 0x00067435},
1210 /*
1211 * The 8723bu vendor driver indicates that bit 8 should be set in
1212 * 0x51 for package types TFBGA90, TFBGA80, and TFBGA79. However
1213 * they never actually check the package type - and just default
1214 * to not setting it.
1215 */
1216 {0x51, 0x0006b04e},
1217 {0x52, 0x000007d2}, {0x53, 0x00000000},
1218 {0x54, 0x00050400}, {0x55, 0x0004026e},
1219 {0xdd, 0x0000004c}, {0x70, 0x00067435},
1220 /*
1221 * 0x71 has same package type condition as for register 0x51
1222 */
1223 {0x71, 0x0006b04e},
1224 {0x72, 0x000007d2}, {0x73, 0x00000000},
1225 {0x74, 0x00050400}, {0x75, 0x0004026e},
1226 {0xef, 0x00000100}, {0x34, 0x0000add7},
1227 {0x35, 0x00005c00}, {0x34, 0x00009dd4},
1228 {0x35, 0x00005000}, {0x34, 0x00008dd1},
1229 {0x35, 0x00004400}, {0x34, 0x00007dce},
1230 {0x35, 0x00003800}, {0x34, 0x00006cd1},
1231 {0x35, 0x00004400}, {0x34, 0x00005cce},
1232 {0x35, 0x00003800}, {0x34, 0x000048ce},
1233 {0x35, 0x00004400}, {0x34, 0x000034ce},
1234 {0x35, 0x00003800}, {0x34, 0x00002451},
1235 {0x35, 0x00004400}, {0x34, 0x0000144e},
1236 {0x35, 0x00003800}, {0x34, 0x00000051},
1237 {0x35, 0x00004400}, {0xef, 0x00000000},
1238 {0xef, 0x00000100}, {0xed, 0x00000010},
1239 {0x44, 0x0000add7}, {0x44, 0x00009dd4},
1240 {0x44, 0x00008dd1}, {0x44, 0x00007dce},
1241 {0x44, 0x00006cc1}, {0x44, 0x00005cce},
1242 {0x44, 0x000044d1}, {0x44, 0x000034ce},
1243 {0x44, 0x00002451}, {0x44, 0x0000144e},
1244 {0x44, 0x00000051}, {0xef, 0x00000000},
1245 {0xed, 0x00000000}, {0x7f, 0x00020080},
1246 {0xef, 0x00002000}, {0x3b, 0x000380ef},
1247 {0x3b, 0x000302fe}, {0x3b, 0x00028ce6},
1248 {0x3b, 0x000200bc}, {0x3b, 0x000188a5},
1249 {0x3b, 0x00010fbc}, {0x3b, 0x00008f71},
1250 {0x3b, 0x00000900}, {0xef, 0x00000000},
1251 {0xed, 0x00000001}, {0x40, 0x000380ef},
1252 {0x40, 0x000302fe}, {0x40, 0x00028ce6},
1253 {0x40, 0x000200bc}, {0x40, 0x000188a5},
1254 {0x40, 0x00010fbc}, {0x40, 0x00008f71},
1255 {0x40, 0x00000900}, {0xed, 0x00000000},
1256 {0x82, 0x00080000}, {0x83, 0x00008000},
1257 {0x84, 0x00048d80}, {0x85, 0x00068000},
1258 {0xa2, 0x00080000}, {0xa3, 0x00008000},
1259 {0xa4, 0x00048d80}, {0xa5, 0x00068000},
1260 {0xed, 0x00000002}, {0xef, 0x00000002},
1261 {0x56, 0x00000032}, {0x76, 0x00000032},
1262 {0x01, 0x00000780},
1263 {0xff, 0xffffffff}
1264};
1265
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001266static struct rtl8xxxu_rfregval rtl8192cu_radioa_2t_init_table[] = {
1267 {0x00, 0x00030159}, {0x01, 0x00031284},
1268 {0x02, 0x00098000}, {0x03, 0x00018c63},
1269 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1270 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1271 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1272 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1273 {0x19, 0x00000000}, {0x1a, 0x00010255},
1274 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1275 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1276 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1277 {0x21, 0x0006c000}, {0x22, 0x00000000},
1278 {0x23, 0x00001558}, {0x24, 0x00000060},
1279 {0x25, 0x00000483}, {0x26, 0x0004f000},
1280 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
1281 {0x29, 0x00004783}, {0x2a, 0x00000001},
1282 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1283 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1284 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1285 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1286 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1287 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1288 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1289 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1290 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1291 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1292 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1293 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1294 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1295 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1296 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1297 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1298 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1299 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1300 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1301 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1302 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1303 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1304 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1305 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1306 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1307 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1308 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1309 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1310 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1311 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1312 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1313 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1314 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1315 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1316 {0x10, 0x00000000}, {0x11, 0x00000000},
1317 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1318 {0x10, 0x0009000f}, {0x11, 0x00023100},
1319 {0x12, 0x00032000}, {0x12, 0x00071000},
1320 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1321 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1322 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1323 {0x13, 0x00018493}, {0x13, 0x0001429b},
1324 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1325 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1326 {0x13, 0x00000020}, {0x14, 0x0001944c},
1327 {0x14, 0x00059444}, {0x14, 0x0009944c},
1328 {0x14, 0x000d9444}, {0x15, 0x0000f424},
1329 {0x15, 0x0004f424}, {0x15, 0x0008f424},
1330 {0x15, 0x000cf424}, {0x16, 0x000e0330},
1331 {0x16, 0x000a0330}, {0x16, 0x00060330},
1332 {0x16, 0x00020330}, {0x00, 0x00010159},
1333 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1334 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1335 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1336 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1337 {0x00, 0x00030159},
1338 {0xff, 0xffffffff}
1339};
1340
1341static struct rtl8xxxu_rfregval rtl8192cu_radiob_2t_init_table[] = {
1342 {0x00, 0x00030159}, {0x01, 0x00031284},
1343 {0x02, 0x00098000}, {0x03, 0x00018c63},
1344 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1345 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1346 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1347 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1348 {0x12, 0x00032000}, {0x12, 0x00071000},
1349 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1350 {0x13, 0x000287af}, {0x13, 0x000244b7},
1351 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1352 {0x13, 0x00018493}, {0x13, 0x00014297},
1353 {0x13, 0x00010295}, {0x13, 0x0000c298},
1354 {0x13, 0x0000819c}, {0x13, 0x000040a8},
1355 {0x13, 0x0000001c}, {0x14, 0x0001944c},
1356 {0x14, 0x00059444}, {0x14, 0x0009944c},
1357 {0x14, 0x000d9444}, {0x15, 0x0000f424},
1358 {0x15, 0x0004f424}, {0x15, 0x0008f424},
1359 {0x15, 0x000cf424}, {0x16, 0x000e0330},
1360 {0x16, 0x000a0330}, {0x16, 0x00060330},
1361 {0x16, 0x00020330},
1362 {0xff, 0xffffffff}
1363};
1364
1365static struct rtl8xxxu_rfregval rtl8192cu_radioa_1t_init_table[] = {
1366 {0x00, 0x00030159}, {0x01, 0x00031284},
1367 {0x02, 0x00098000}, {0x03, 0x00018c63},
1368 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1369 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1370 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1371 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1372 {0x19, 0x00000000}, {0x1a, 0x00010255},
1373 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1374 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1375 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1376 {0x21, 0x0006c000}, {0x22, 0x00000000},
1377 {0x23, 0x00001558}, {0x24, 0x00000060},
1378 {0x25, 0x00000483}, {0x26, 0x0004f000},
1379 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
1380 {0x29, 0x00004783}, {0x2a, 0x00000001},
1381 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1382 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1383 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1384 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1385 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1386 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1387 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1388 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1389 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1390 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1391 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1392 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1393 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1394 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1395 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1396 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1397 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1398 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1399 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1400 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1401 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1402 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1403 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1404 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1405 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1406 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1407 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1408 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1409 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1410 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1411 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1412 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1413 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1414 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1415 {0x10, 0x00000000}, {0x11, 0x00000000},
1416 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1417 {0x10, 0x0009000f}, {0x11, 0x00023100},
1418 {0x12, 0x00032000}, {0x12, 0x00071000},
1419 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1420 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1421 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1422 {0x13, 0x00018493}, {0x13, 0x0001429b},
1423 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1424 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1425 {0x13, 0x00000020}, {0x14, 0x0001944c},
1426 {0x14, 0x00059444}, {0x14, 0x0009944c},
1427 {0x14, 0x000d9444}, {0x15, 0x0000f405},
1428 {0x15, 0x0004f405}, {0x15, 0x0008f405},
1429 {0x15, 0x000cf405}, {0x16, 0x000e0330},
1430 {0x16, 0x000a0330}, {0x16, 0x00060330},
1431 {0x16, 0x00020330}, {0x00, 0x00010159},
1432 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1433 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1434 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1435 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1436 {0x00, 0x00030159},
1437 {0xff, 0xffffffff}
1438};
1439
1440static struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = {
1441 {0x00, 0x00030159}, {0x01, 0x00031284},
1442 {0x02, 0x00098000}, {0x03, 0x00018c63},
1443 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1444 {0x0a, 0x0001adb0}, {0x0b, 0x00054867},
1445 {0x0c, 0x0008992e}, {0x0d, 0x0000e529},
1446 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1447 {0x19, 0x00000000}, {0x1a, 0x00000255},
1448 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1449 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1450 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1451 {0x21, 0x0006c000}, {0x22, 0x0000083c},
1452 {0x23, 0x00001558}, {0x24, 0x00000060},
1453 {0x25, 0x00000483}, {0x26, 0x0004f000},
1454 {0x27, 0x000ec7d9}, {0x28, 0x000977c0},
1455 {0x29, 0x00004783}, {0x2a, 0x00000001},
1456 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1457 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1458 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1459 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1460 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1461 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1462 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1463 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1464 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1465 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1466 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1467 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1468 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1469 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1470 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1471 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1472 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1473 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1474 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1475 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1476 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1477 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1478 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1479 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1480 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1481 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1482 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1483 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1484 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1485 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1486 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1487 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1488 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1489 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1490 {0x10, 0x00000000}, {0x11, 0x00000000},
1491 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1492 {0x10, 0x0009000f}, {0x11, 0x00023100},
1493 {0x12, 0x000d8000}, {0x12, 0x00090000},
1494 {0x12, 0x00051000}, {0x12, 0x00012000},
1495 {0x13, 0x00028fb4}, {0x13, 0x00024fa8},
1496 {0x13, 0x000207a4}, {0x13, 0x0001c3b0},
1497 {0x13, 0x000183a4}, {0x13, 0x00014398},
1498 {0x13, 0x000101a4}, {0x13, 0x0000c198},
1499 {0x13, 0x000080a4}, {0x13, 0x00004098},
1500 {0x13, 0x00000000}, {0x14, 0x0001944c},
1501 {0x14, 0x00059444}, {0x14, 0x0009944c},
1502 {0x14, 0x000d9444}, {0x15, 0x0000f405},
1503 {0x15, 0x0004f405}, {0x15, 0x0008f405},
1504 {0x15, 0x000cf405}, {0x16, 0x000e0330},
1505 {0x16, 0x000a0330}, {0x16, 0x00060330},
1506 {0x16, 0x00020330}, {0x00, 0x00010159},
1507 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1508 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1509 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1510 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1511 {0x00, 0x00030159},
1512 {0xff, 0xffffffff}
1513};
1514
Jes Sorensen19102f82016-04-07 14:19:19 -04001515static struct rtl8xxxu_rfregval rtl8192eu_radioa_init_table[] = {
1516 {0x7f, 0x00000082}, {0x81, 0x0003fc00},
1517 {0x00, 0x00030000}, {0x08, 0x00008400},
1518 {0x18, 0x00000407}, {0x19, 0x00000012},
1519 {0x1b, 0x00000064}, {0x1e, 0x00080009},
1520 {0x1f, 0x00000880}, {0x2f, 0x0001a060},
1521 {0x3f, 0x00000000}, {0x42, 0x000060c0},
1522 {0x57, 0x000d0000}, {0x58, 0x000be180},
1523 {0x67, 0x00001552}, {0x83, 0x00000000},
1524 {0xb0, 0x000ff9f1}, {0xb1, 0x00055418},
1525 {0xb2, 0x0008cc00}, {0xb4, 0x00043083},
1526 {0xb5, 0x00008166}, {0xb6, 0x0000803e},
1527 {0xb7, 0x0001c69f}, {0xb8, 0x0000407f},
1528 {0xb9, 0x00080001}, {0xba, 0x00040001},
1529 {0xbb, 0x00000400}, {0xbf, 0x000c0000},
1530 {0xc2, 0x00002400}, {0xc3, 0x00000009},
1531 {0xc4, 0x00040c91}, {0xc5, 0x00099999},
1532 {0xc6, 0x000000a3}, {0xc7, 0x00088820},
1533 {0xc8, 0x00076c06}, {0xc9, 0x00000000},
1534 {0xca, 0x00080000}, {0xdf, 0x00000180},
1535 {0xef, 0x000001a0}, {0x51, 0x00069545},
1536 {0x52, 0x0007e45e}, {0x53, 0x00000071},
1537 {0x56, 0x00051ff3}, {0x35, 0x000000a8},
1538 {0x35, 0x000001e2}, {0x35, 0x000002a8},
1539 {0x36, 0x00001c24}, {0x36, 0x00009c24},
1540 {0x36, 0x00011c24}, {0x36, 0x00019c24},
1541 {0x18, 0x00000c07}, {0x5a, 0x00048000},
1542 {0x19, 0x000739d0},
1543#ifdef EXT_PA_8192EU
1544 /* External PA or external LNA */
1545 {0x34, 0x0000a093}, {0x34, 0x0000908f},
1546 {0x34, 0x0000808c}, {0x34, 0x0000704d},
1547 {0x34, 0x0000604a}, {0x34, 0x00005047},
1548 {0x34, 0x0000400a}, {0x34, 0x00003007},
1549 {0x34, 0x00002004}, {0x34, 0x00001001},
1550 {0x34, 0x00000000},
1551#else
1552 /* Regular */
1553 {0x34, 0x0000add7}, {0x34, 0x00009dd4},
1554 {0x34, 0x00008dd1}, {0x34, 0x00007dce},
1555 {0x34, 0x00006dcb}, {0x34, 0x00005dc8},
1556 {0x34, 0x00004dc5}, {0x34, 0x000034cc},
1557 {0x34, 0x0000244f}, {0x34, 0x0000144c},
1558 {0x34, 0x00000014},
1559#endif
1560 {0x00, 0x00030159},
1561 {0x84, 0x00068180},
1562 {0x86, 0x0000014e},
1563 {0x87, 0x00048e00},
1564 {0x8e, 0x00065540},
1565 {0x8f, 0x00088000},
1566 {0xef, 0x000020a0},
1567#ifdef EXT_PA_8192EU
1568 /* External PA or external LNA */
1569 {0x3b, 0x000f07b0},
1570#else
1571 {0x3b, 0x000f02b0},
1572#endif
1573 {0x3b, 0x000ef7b0}, {0x3b, 0x000d4fb0},
1574 {0x3b, 0x000cf060}, {0x3b, 0x000b0090},
1575 {0x3b, 0x000a0080}, {0x3b, 0x00090080},
1576 {0x3b, 0x0008f780},
1577#ifdef EXT_PA_8192EU
1578 /* External PA or external LNA */
1579 {0x3b, 0x000787b0},
1580#else
1581 {0x3b, 0x00078730},
1582#endif
1583 {0x3b, 0x00060fb0}, {0x3b, 0x0005ffa0},
1584 {0x3b, 0x00040620}, {0x3b, 0x00037090},
1585 {0x3b, 0x00020080}, {0x3b, 0x0001f060},
1586 {0x3b, 0x0000ffb0}, {0xef, 0x000000a0},
1587 {0xfe, 0x00000000}, {0x18, 0x0000fc07},
1588 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1589 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1590 {0x1e, 0x00000001}, {0x1f, 0x00080000},
1591 {0x00, 0x00033e70},
1592 {0xff, 0xffffffff}
1593};
1594
1595static struct rtl8xxxu_rfregval rtl8192eu_radiob_init_table[] = {
1596 {0x7f, 0x00000082}, {0x81, 0x0003fc00},
1597 {0x00, 0x00030000}, {0x08, 0x00008400},
1598 {0x18, 0x00000407}, {0x19, 0x00000012},
1599 {0x1b, 0x00000064}, {0x1e, 0x00080009},
1600 {0x1f, 0x00000880}, {0x2f, 0x0001a060},
1601 {0x3f, 0x00000000}, {0x42, 0x000060c0},
1602 {0x57, 0x000d0000}, {0x58, 0x000be180},
1603 {0x67, 0x00001552}, {0x7f, 0x00000082},
1604 {0x81, 0x0003f000}, {0x83, 0x00000000},
1605 {0xdf, 0x00000180}, {0xef, 0x000001a0},
1606 {0x51, 0x00069545}, {0x52, 0x0007e42e},
1607 {0x53, 0x00000071}, {0x56, 0x00051ff3},
1608 {0x35, 0x000000a8}, {0x35, 0x000001e0},
1609 {0x35, 0x000002a8}, {0x36, 0x00001ca8},
1610 {0x36, 0x00009c24}, {0x36, 0x00011c24},
1611 {0x36, 0x00019c24}, {0x18, 0x00000c07},
1612 {0x5a, 0x00048000}, {0x19, 0x000739d0},
1613#ifdef EXT_PA_8192EU
1614 /* External PA or external LNA */
1615 {0x34, 0x0000a093}, {0x34, 0x0000908f},
1616 {0x34, 0x0000808c}, {0x34, 0x0000704d},
1617 {0x34, 0x0000604a}, {0x34, 0x00005047},
1618 {0x34, 0x0000400a}, {0x34, 0x00003007},
1619 {0x34, 0x00002004}, {0x34, 0x00001001},
1620 {0x34, 0x00000000},
1621#else
1622 {0x34, 0x0000add7}, {0x34, 0x00009dd4},
1623 {0x34, 0x00008dd1}, {0x34, 0x00007dce},
1624 {0x34, 0x00006dcb}, {0x34, 0x00005dc8},
1625 {0x34, 0x00004dc5}, {0x34, 0x000034cc},
1626 {0x34, 0x0000244f}, {0x34, 0x0000144c},
1627 {0x34, 0x00000014},
1628#endif
1629 {0x00, 0x00030159}, {0x84, 0x00068180},
1630 {0x86, 0x000000ce}, {0x87, 0x00048a00},
1631 {0x8e, 0x00065540}, {0x8f, 0x00088000},
1632 {0xef, 0x000020a0},
1633#ifdef EXT_PA_8192EU
1634 /* External PA or external LNA */
1635 {0x3b, 0x000f07b0},
1636#else
1637 {0x3b, 0x000f02b0},
1638#endif
1639
1640 {0x3b, 0x000ef7b0}, {0x3b, 0x000d4fb0},
1641 {0x3b, 0x000cf060}, {0x3b, 0x000b0090},
1642 {0x3b, 0x000a0080}, {0x3b, 0x00090080},
1643 {0x3b, 0x0008f780},
1644#ifdef EXT_PA_8192EU
1645 /* External PA or external LNA */
1646 {0x3b, 0x000787b0},
1647#else
1648 {0x3b, 0x00078730},
1649#endif
1650 {0x3b, 0x00060fb0}, {0x3b, 0x0005ffa0},
1651 {0x3b, 0x00040620}, {0x3b, 0x00037090},
1652 {0x3b, 0x00020080}, {0x3b, 0x0001f060},
1653 {0x3b, 0x0000ffb0}, {0xef, 0x000000a0},
1654 {0x00, 0x00010159}, {0xfe, 0x00000000},
1655 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1656 {0xfe, 0x00000000}, {0x1e, 0x00000001},
1657 {0x1f, 0x00080000}, {0x00, 0x00033e70},
1658 {0xff, 0xffffffff}
1659};
1660
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001661static struct rtl8xxxu_rfregs rtl8xxxu_rfregs[] = {
1662 { /* RF_A */
1663 .hssiparm1 = REG_FPGA0_XA_HSSI_PARM1,
1664 .hssiparm2 = REG_FPGA0_XA_HSSI_PARM2,
1665 .lssiparm = REG_FPGA0_XA_LSSI_PARM,
1666 .hspiread = REG_HSPI_XA_READBACK,
1667 .lssiread = REG_FPGA0_XA_LSSI_READBACK,
1668 .rf_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL,
1669 },
1670 { /* RF_B */
1671 .hssiparm1 = REG_FPGA0_XB_HSSI_PARM1,
1672 .hssiparm2 = REG_FPGA0_XB_HSSI_PARM2,
1673 .lssiparm = REG_FPGA0_XB_LSSI_PARM,
1674 .hspiread = REG_HSPI_XB_READBACK,
1675 .lssiread = REG_FPGA0_XB_LSSI_READBACK,
1676 .rf_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL,
1677 },
1678};
1679
1680static const u32 rtl8723au_iqk_phy_iq_bb_reg[RTL8XXXU_BB_REGS] = {
1681 REG_OFDM0_XA_RX_IQ_IMBALANCE,
1682 REG_OFDM0_XB_RX_IQ_IMBALANCE,
1683 REG_OFDM0_ENERGY_CCA_THRES,
1684 REG_OFDM0_AGCR_SSI_TABLE,
1685 REG_OFDM0_XA_TX_IQ_IMBALANCE,
1686 REG_OFDM0_XB_TX_IQ_IMBALANCE,
1687 REG_OFDM0_XC_TX_AFE,
1688 REG_OFDM0_XD_TX_AFE,
1689 REG_OFDM0_RX_IQ_EXT_ANTA
1690};
1691
1692static u8 rtl8xxxu_read8(struct rtl8xxxu_priv *priv, u16 addr)
1693{
1694 struct usb_device *udev = priv->udev;
1695 int len;
1696 u8 data;
1697
1698 mutex_lock(&priv->usb_buf_mutex);
1699 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1700 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1701 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1702 RTW_USB_CONTROL_MSG_TIMEOUT);
1703 data = priv->usb_buf.val8;
1704 mutex_unlock(&priv->usb_buf_mutex);
1705
1706 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1707 dev_info(&udev->dev, "%s(%04x) = 0x%02x, len %i\n",
1708 __func__, addr, data, len);
1709 return data;
1710}
1711
1712static u16 rtl8xxxu_read16(struct rtl8xxxu_priv *priv, u16 addr)
1713{
1714 struct usb_device *udev = priv->udev;
1715 int len;
1716 u16 data;
1717
1718 mutex_lock(&priv->usb_buf_mutex);
1719 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1720 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1721 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1722 RTW_USB_CONTROL_MSG_TIMEOUT);
1723 data = le16_to_cpu(priv->usb_buf.val16);
1724 mutex_unlock(&priv->usb_buf_mutex);
1725
1726 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1727 dev_info(&udev->dev, "%s(%04x) = 0x%04x, len %i\n",
1728 __func__, addr, data, len);
1729 return data;
1730}
1731
1732static u32 rtl8xxxu_read32(struct rtl8xxxu_priv *priv, u16 addr)
1733{
1734 struct usb_device *udev = priv->udev;
1735 int len;
1736 u32 data;
1737
1738 mutex_lock(&priv->usb_buf_mutex);
1739 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1740 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1741 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1742 RTW_USB_CONTROL_MSG_TIMEOUT);
1743 data = le32_to_cpu(priv->usb_buf.val32);
1744 mutex_unlock(&priv->usb_buf_mutex);
1745
1746 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1747 dev_info(&udev->dev, "%s(%04x) = 0x%08x, len %i\n",
1748 __func__, addr, data, len);
1749 return data;
1750}
1751
1752static int rtl8xxxu_write8(struct rtl8xxxu_priv *priv, u16 addr, u8 val)
1753{
1754 struct usb_device *udev = priv->udev;
1755 int ret;
1756
1757 mutex_lock(&priv->usb_buf_mutex);
1758 priv->usb_buf.val8 = val;
1759 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1760 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1761 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1762 RTW_USB_CONTROL_MSG_TIMEOUT);
1763
1764 mutex_unlock(&priv->usb_buf_mutex);
1765
1766 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1767 dev_info(&udev->dev, "%s(%04x) = 0x%02x\n",
1768 __func__, addr, val);
1769 return ret;
1770}
1771
1772static int rtl8xxxu_write16(struct rtl8xxxu_priv *priv, u16 addr, u16 val)
1773{
1774 struct usb_device *udev = priv->udev;
1775 int ret;
1776
1777 mutex_lock(&priv->usb_buf_mutex);
1778 priv->usb_buf.val16 = cpu_to_le16(val);
1779 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1780 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1781 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1782 RTW_USB_CONTROL_MSG_TIMEOUT);
1783 mutex_unlock(&priv->usb_buf_mutex);
1784
1785 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1786 dev_info(&udev->dev, "%s(%04x) = 0x%04x\n",
1787 __func__, addr, val);
1788 return ret;
1789}
1790
1791static int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val)
1792{
1793 struct usb_device *udev = priv->udev;
1794 int ret;
1795
1796 mutex_lock(&priv->usb_buf_mutex);
1797 priv->usb_buf.val32 = cpu_to_le32(val);
1798 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1799 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1800 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1801 RTW_USB_CONTROL_MSG_TIMEOUT);
1802 mutex_unlock(&priv->usb_buf_mutex);
1803
1804 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1805 dev_info(&udev->dev, "%s(%04x) = 0x%08x\n",
1806 __func__, addr, val);
1807 return ret;
1808}
1809
1810static int
1811rtl8xxxu_writeN(struct rtl8xxxu_priv *priv, u16 addr, u8 *buf, u16 len)
1812{
1813 struct usb_device *udev = priv->udev;
1814 int blocksize = priv->fops->writeN_block_size;
1815 int ret, i, count, remainder;
1816
1817 count = len / blocksize;
1818 remainder = len % blocksize;
1819
1820 for (i = 0; i < count; i++) {
1821 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1822 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1823 addr, 0, buf, blocksize,
1824 RTW_USB_CONTROL_MSG_TIMEOUT);
1825 if (ret != blocksize)
1826 goto write_error;
1827
1828 addr += blocksize;
1829 buf += blocksize;
1830 }
1831
1832 if (remainder) {
1833 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1834 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1835 addr, 0, buf, remainder,
1836 RTW_USB_CONTROL_MSG_TIMEOUT);
1837 if (ret != remainder)
1838 goto write_error;
1839 }
1840
1841 return len;
1842
1843write_error:
1844 dev_info(&udev->dev,
1845 "%s: Failed to write block at addr: %04x size: %04x\n",
1846 __func__, addr, blocksize);
1847 return -EAGAIN;
1848}
1849
1850static u32 rtl8xxxu_read_rfreg(struct rtl8xxxu_priv *priv,
1851 enum rtl8xxxu_rfpath path, u8 reg)
1852{
1853 u32 hssia, val32, retval;
1854
1855 hssia = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2);
1856 if (path != RF_A)
1857 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm2);
1858 else
1859 val32 = hssia;
1860
1861 val32 &= ~FPGA0_HSSI_PARM2_ADDR_MASK;
1862 val32 |= (reg << FPGA0_HSSI_PARM2_ADDR_SHIFT);
1863 val32 |= FPGA0_HSSI_PARM2_EDGE_READ;
1864 hssia &= ~FPGA0_HSSI_PARM2_EDGE_READ;
1865 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1866
1867 udelay(10);
1868
1869 rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].hssiparm2, val32);
1870 udelay(100);
1871
1872 hssia |= FPGA0_HSSI_PARM2_EDGE_READ;
1873 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1874 udelay(10);
1875
1876 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm1);
1877 if (val32 & FPGA0_HSSI_PARM1_PI)
1878 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hspiread);
1879 else
1880 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].lssiread);
1881
1882 retval &= 0xfffff;
1883
1884 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_READ)
1885 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1886 __func__, reg, retval);
1887 return retval;
1888}
1889
Jes Sorensen22a31d42016-02-29 17:04:15 -05001890/*
1891 * The RTL8723BU driver indicates that registers 0xb2 and 0xb6 can
1892 * have write issues in high temperature conditions. We may have to
1893 * retry writing them.
1894 */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001895static int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv *priv,
1896 enum rtl8xxxu_rfpath path, u8 reg, u32 data)
1897{
1898 int ret, retval;
Jes Sorensen2949b9e2016-04-07 14:19:25 -04001899 u32 dataaddr, val32;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001900
1901 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_WRITE)
1902 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1903 __func__, reg, data);
1904
1905 data &= FPGA0_LSSI_PARM_DATA_MASK;
1906 dataaddr = (reg << FPGA0_LSSI_PARM_ADDR_SHIFT) | data;
1907
Jes Sorensen2949b9e2016-04-07 14:19:25 -04001908 if (priv->rtl_chip == RTL8192E) {
1909 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
1910 val32 &= ~0x20000;
1911 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
1912 }
1913
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001914 /* Use XB for path B */
1915 ret = rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].lssiparm, dataaddr);
1916 if (ret != sizeof(dataaddr))
1917 retval = -EIO;
1918 else
1919 retval = 0;
1920
1921 udelay(1);
1922
Jes Sorensen2949b9e2016-04-07 14:19:25 -04001923 if (priv->rtl_chip == RTL8192E) {
1924 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
1925 val32 |= 0x20000;
1926 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
1927 }
1928
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001929 return retval;
1930}
1931
Jes Sorensen8da91572016-02-29 17:04:29 -05001932static int rtl8723a_h2c_cmd(struct rtl8xxxu_priv *priv,
1933 struct h2c_cmd *h2c, int len)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001934{
1935 struct device *dev = &priv->udev->dev;
1936 int mbox_nr, retry, retval = 0;
1937 int mbox_reg, mbox_ext_reg;
1938 u8 val8;
1939
1940 mutex_lock(&priv->h2c_mutex);
1941
1942 mbox_nr = priv->next_mbox;
1943 mbox_reg = REG_HMBOX_0 + (mbox_nr * 4);
Jes Sorensened35d092016-02-29 17:04:19 -05001944 mbox_ext_reg = priv->fops->mbox_ext_reg +
1945 (mbox_nr * priv->fops->mbox_ext_width);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001946
1947 /*
1948 * MBOX ready?
1949 */
1950 retry = 100;
1951 do {
1952 val8 = rtl8xxxu_read8(priv, REG_HMTFR);
1953 if (!(val8 & BIT(mbox_nr)))
1954 break;
1955 } while (retry--);
1956
1957 if (!retry) {
Jes Sorensenc7a5a192016-02-29 17:04:30 -05001958 dev_info(dev, "%s: Mailbox busy\n", __func__);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001959 retval = -EBUSY;
1960 goto error;
1961 }
1962
1963 /*
1964 * Need to swap as it's being swapped again by rtl8xxxu_write16/32()
1965 */
Jes Sorensen8da91572016-02-29 17:04:29 -05001966 if (len > sizeof(u32)) {
Jes Sorensened35d092016-02-29 17:04:19 -05001967 if (priv->fops->mbox_ext_width == 4) {
1968 rtl8xxxu_write32(priv, mbox_ext_reg,
1969 le32_to_cpu(h2c->raw_wide.ext));
1970 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1971 dev_info(dev, "H2C_EXT %08x\n",
1972 le32_to_cpu(h2c->raw_wide.ext));
1973 } else {
1974 rtl8xxxu_write16(priv, mbox_ext_reg,
1975 le16_to_cpu(h2c->raw.ext));
1976 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1977 dev_info(dev, "H2C_EXT %04x\n",
1978 le16_to_cpu(h2c->raw.ext));
1979 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001980 }
1981 rtl8xxxu_write32(priv, mbox_reg, le32_to_cpu(h2c->raw.data));
1982 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1983 dev_info(dev, "H2C %08x\n", le32_to_cpu(h2c->raw.data));
1984
1985 priv->next_mbox = (mbox_nr + 1) % H2C_MAX_MBOX;
1986
1987error:
1988 mutex_unlock(&priv->h2c_mutex);
1989 return retval;
1990}
1991
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001992static void rtl8723bu_write_btreg(struct rtl8xxxu_priv *priv, u8 reg, u8 data)
1993{
1994 struct h2c_cmd h2c;
1995 int reqnum = 0;
1996
1997 memset(&h2c, 0, sizeof(struct h2c_cmd));
1998 h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER;
1999 h2c.bt_mp_oper.operreq = 0 | (reqnum << 4);
2000 h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE;
2001 h2c.bt_mp_oper.data = data;
2002 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper));
2003
2004 reqnum++;
2005 memset(&h2c, 0, sizeof(struct h2c_cmd));
2006 h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER;
2007 h2c.bt_mp_oper.operreq = 0 | (reqnum << 4);
2008 h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE;
2009 h2c.bt_mp_oper.addr = reg;
2010 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper));
2011}
2012
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002013static void rtl8723a_enable_rf(struct rtl8xxxu_priv *priv)
2014{
2015 u8 val8;
2016 u32 val32;
2017
2018 val8 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
2019 val8 |= BIT(0) | BIT(3);
2020 rtl8xxxu_write8(priv, REG_SPS0_CTRL, val8);
2021
2022 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
2023 val32 &= ~(BIT(4) | BIT(5));
2024 val32 |= BIT(3);
2025 if (priv->rf_paths == 2) {
2026 val32 &= ~(BIT(20) | BIT(21));
2027 val32 |= BIT(19);
2028 }
2029 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
2030
2031 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
2032 val32 &= ~OFDM_RF_PATH_TX_MASK;
2033 if (priv->tx_paths == 2)
2034 val32 |= OFDM_RF_PATH_TX_A | OFDM_RF_PATH_TX_B;
Jes Sorensenba17d822016-03-31 17:08:39 -04002035 else if (priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002036 val32 |= OFDM_RF_PATH_TX_B;
2037 else
2038 val32 |= OFDM_RF_PATH_TX_A;
2039 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
2040
2041 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
2042 val32 &= ~FPGA_RF_MODE_JAPAN;
2043 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
2044
2045 if (priv->rf_paths == 2)
2046 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x63db25a0);
2047 else
2048 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x631b25a0);
2049
2050 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x32d95);
2051 if (priv->rf_paths == 2)
2052 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x32d95);
2053
2054 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
2055}
2056
2057static void rtl8723a_disable_rf(struct rtl8xxxu_priv *priv)
2058{
2059 u8 sps0;
2060 u32 val32;
2061
2062 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
2063
2064 sps0 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
2065
2066 /* RF RX code for preamble power saving */
2067 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
2068 val32 &= ~(BIT(3) | BIT(4) | BIT(5));
2069 if (priv->rf_paths == 2)
2070 val32 &= ~(BIT(19) | BIT(20) | BIT(21));
2071 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
2072
2073 /* Disable TX for four paths */
2074 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
2075 val32 &= ~OFDM_RF_PATH_TX_MASK;
2076 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
2077
2078 /* Enable power saving */
2079 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
2080 val32 |= FPGA_RF_MODE_JAPAN;
2081 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
2082
2083 /* AFE control register to power down bits [30:22] */
2084 if (priv->rf_paths == 2)
2085 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x00db25a0);
2086 else
2087 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x001b25a0);
2088
2089 /* Power down RF module */
2090 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0);
2091 if (priv->rf_paths == 2)
2092 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0);
2093
2094 sps0 &= ~(BIT(0) | BIT(3));
2095 rtl8xxxu_write8(priv, REG_SPS0_CTRL, sps0);
2096}
2097
2098
2099static void rtl8723a_stop_tx_beacon(struct rtl8xxxu_priv *priv)
2100{
2101 u8 val8;
2102
2103 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL + 2);
2104 val8 &= ~BIT(6);
2105 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8);
2106
2107 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x64);
2108 val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
2109 val8 &= ~BIT(0);
2110 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8);
2111}
2112
2113
2114/*
2115 * The rtl8723a has 3 channel groups for it's efuse settings. It only
2116 * supports the 2.4GHz band, so channels 1 - 14:
2117 * group 0: channels 1 - 3
2118 * group 1: channels 4 - 9
2119 * group 2: channels 10 - 14
2120 *
2121 * Note: We index from 0 in the code
2122 */
2123static int rtl8723a_channel_to_group(int channel)
2124{
2125 int group;
2126
2127 if (channel < 4)
2128 group = 0;
2129 else if (channel < 10)
2130 group = 1;
2131 else
2132 group = 2;
2133
2134 return group;
2135}
2136
Jes Sorensen9e247722016-04-07 14:19:23 -04002137/*
2138 * Valid for rtl8723bu and rtl8192eu
2139 */
Jes Sorensene796dab2016-02-29 17:05:19 -05002140static int rtl8723b_channel_to_group(int channel)
2141{
2142 int group;
2143
2144 if (channel < 3)
2145 group = 0;
2146 else if (channel < 6)
2147 group = 1;
2148 else if (channel < 9)
2149 group = 2;
2150 else if (channel < 12)
2151 group = 3;
2152 else
2153 group = 4;
2154
2155 return group;
2156}
2157
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002158static void rtl8723au_config_channel(struct ieee80211_hw *hw)
2159{
2160 struct rtl8xxxu_priv *priv = hw->priv;
2161 u32 val32, rsr;
2162 u8 val8, opmode;
2163 bool ht = true;
2164 int sec_ch_above, channel;
2165 int i;
2166
2167 opmode = rtl8xxxu_read8(priv, REG_BW_OPMODE);
2168 rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
2169 channel = hw->conf.chandef.chan->hw_value;
2170
2171 switch (hw->conf.chandef.width) {
2172 case NL80211_CHAN_WIDTH_20_NOHT:
2173 ht = false;
2174 case NL80211_CHAN_WIDTH_20:
2175 opmode |= BW_OPMODE_20MHZ;
2176 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
2177
2178 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
2179 val32 &= ~FPGA_RF_MODE;
2180 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
2181
2182 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
2183 val32 &= ~FPGA_RF_MODE;
2184 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
2185
2186 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
2187 val32 |= FPGA0_ANALOG2_20MHZ;
2188 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
2189 break;
2190 case NL80211_CHAN_WIDTH_40:
2191 if (hw->conf.chandef.center_freq1 >
2192 hw->conf.chandef.chan->center_freq) {
2193 sec_ch_above = 1;
2194 channel += 2;
2195 } else {
2196 sec_ch_above = 0;
2197 channel -= 2;
2198 }
2199
2200 opmode &= ~BW_OPMODE_20MHZ;
2201 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
2202 rsr &= ~RSR_RSC_BANDWIDTH_40M;
2203 if (sec_ch_above)
2204 rsr |= RSR_RSC_UPPER_SUB_CHANNEL;
2205 else
2206 rsr |= RSR_RSC_LOWER_SUB_CHANNEL;
2207 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, rsr);
2208
2209 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
2210 val32 |= FPGA_RF_MODE;
2211 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
2212
2213 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
2214 val32 |= FPGA_RF_MODE;
2215 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
2216
2217 /*
2218 * Set Control channel to upper or lower. These settings
2219 * are required only for 40MHz
2220 */
2221 val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
2222 val32 &= ~CCK0_SIDEBAND;
2223 if (!sec_ch_above)
2224 val32 |= CCK0_SIDEBAND;
2225 rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
2226
2227 val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
2228 val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
2229 if (sec_ch_above)
2230 val32 |= OFDM_LSTF_PRIME_CH_LOW;
2231 else
2232 val32 |= OFDM_LSTF_PRIME_CH_HIGH;
2233 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
2234
2235 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
2236 val32 &= ~FPGA0_ANALOG2_20MHZ;
2237 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
2238
2239 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
2240 val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
2241 if (sec_ch_above)
2242 val32 |= FPGA0_PS_UPPER_CHANNEL;
2243 else
2244 val32 |= FPGA0_PS_LOWER_CHANNEL;
2245 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
2246 break;
2247
2248 default:
2249 break;
2250 }
2251
2252 for (i = RF_A; i < priv->rf_paths; i++) {
2253 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
2254 val32 &= ~MODE_AG_CHANNEL_MASK;
2255 val32 |= channel;
2256 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
2257 }
2258
2259 if (ht)
2260 val8 = 0x0e;
2261 else
2262 val8 = 0x0a;
2263
2264 rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8);
2265 rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8);
2266
2267 rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808);
2268 rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a);
2269
2270 for (i = RF_A; i < priv->rf_paths; i++) {
2271 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
2272 if (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40)
2273 val32 &= ~MODE_AG_CHANNEL_20MHZ;
2274 else
2275 val32 |= MODE_AG_CHANNEL_20MHZ;
2276 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
2277 }
2278}
2279
Jes Sorensenc3f95062016-02-29 17:04:40 -05002280static void rtl8723bu_config_channel(struct ieee80211_hw *hw)
2281{
2282 struct rtl8xxxu_priv *priv = hw->priv;
2283 u32 val32, rsr;
Jes Sorensen368633c2016-02-29 17:04:42 -05002284 u8 val8, subchannel;
Jes Sorensenc3f95062016-02-29 17:04:40 -05002285 u16 rf_mode_bw;
2286 bool ht = true;
2287 int sec_ch_above, channel;
2288 int i;
2289
2290 rf_mode_bw = rtl8xxxu_read16(priv, REG_WMAC_TRXPTCL_CTL);
2291 rf_mode_bw &= ~WMAC_TRXPTCL_CTL_BW_MASK;
2292 rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
2293 channel = hw->conf.chandef.chan->hw_value;
2294
2295/* Hack */
2296 subchannel = 0;
2297
2298 switch (hw->conf.chandef.width) {
2299 case NL80211_CHAN_WIDTH_20_NOHT:
2300 ht = false;
2301 case NL80211_CHAN_WIDTH_20:
2302 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_20;
2303 subchannel = 0;
2304
2305 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
2306 val32 &= ~FPGA_RF_MODE;
2307 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
2308
2309 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
2310 val32 &= ~FPGA_RF_MODE;
2311 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
2312
2313 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TX_PSDO_NOISE_WEIGHT);
2314 val32 &= ~(BIT(30) | BIT(31));
2315 rtl8xxxu_write32(priv, REG_OFDM0_TX_PSDO_NOISE_WEIGHT, val32);
2316
2317 break;
2318 case NL80211_CHAN_WIDTH_40:
2319 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_40;
2320
2321 if (hw->conf.chandef.center_freq1 >
2322 hw->conf.chandef.chan->center_freq) {
2323 sec_ch_above = 1;
2324 channel += 2;
2325 } else {
2326 sec_ch_above = 0;
2327 channel -= 2;
2328 }
2329
2330 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
2331 val32 |= FPGA_RF_MODE;
2332 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
2333
2334 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
2335 val32 |= FPGA_RF_MODE;
2336 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
2337
2338 /*
2339 * Set Control channel to upper or lower. These settings
2340 * are required only for 40MHz
2341 */
2342 val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
2343 val32 &= ~CCK0_SIDEBAND;
2344 if (!sec_ch_above)
2345 val32 |= CCK0_SIDEBAND;
2346 rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
2347
2348 val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
2349 val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
2350 if (sec_ch_above)
2351 val32 |= OFDM_LSTF_PRIME_CH_LOW;
2352 else
2353 val32 |= OFDM_LSTF_PRIME_CH_HIGH;
2354 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
2355
2356 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
2357 val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
2358 if (sec_ch_above)
2359 val32 |= FPGA0_PS_UPPER_CHANNEL;
2360 else
2361 val32 |= FPGA0_PS_LOWER_CHANNEL;
2362 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
2363 break;
2364 case NL80211_CHAN_WIDTH_80:
2365 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_80;
2366 break;
2367 default:
2368 break;
2369 }
2370
2371 for (i = RF_A; i < priv->rf_paths; i++) {
2372 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
2373 val32 &= ~MODE_AG_CHANNEL_MASK;
2374 val32 |= channel;
2375 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
2376 }
2377
2378 rtl8xxxu_write16(priv, REG_WMAC_TRXPTCL_CTL, rf_mode_bw);
2379 rtl8xxxu_write8(priv, REG_DATA_SUBCHANNEL, subchannel);
2380
2381 if (ht)
2382 val8 = 0x0e;
2383 else
2384 val8 = 0x0a;
2385
2386 rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8);
2387 rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8);
2388
2389 rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808);
2390 rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a);
2391
2392 for (i = RF_A; i < priv->rf_paths; i++) {
2393 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
2394 val32 &= ~MODE_AG_BW_MASK;
2395 switch(hw->conf.chandef.width) {
2396 case NL80211_CHAN_WIDTH_80:
2397 val32 |= MODE_AG_BW_80MHZ_8723B;
2398 break;
2399 case NL80211_CHAN_WIDTH_40:
2400 val32 |= MODE_AG_BW_40MHZ_8723B;
2401 break;
2402 default:
2403 val32 |= MODE_AG_BW_20MHZ_8723B;
2404 break;
2405 }
2406 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
2407 }
2408}
2409
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002410static void
2411rtl8723a_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
2412{
2413 u8 cck[RTL8723A_MAX_RF_PATHS], ofdm[RTL8723A_MAX_RF_PATHS];
2414 u8 ofdmbase[RTL8723A_MAX_RF_PATHS], mcsbase[RTL8723A_MAX_RF_PATHS];
2415 u32 val32, ofdm_a, ofdm_b, mcs_a, mcs_b;
2416 u8 val8;
2417 int group, i;
2418
2419 group = rtl8723a_channel_to_group(channel);
2420
2421 cck[0] = priv->cck_tx_power_index_A[group];
2422 cck[1] = priv->cck_tx_power_index_B[group];
2423
2424 ofdm[0] = priv->ht40_1s_tx_power_index_A[group];
2425 ofdm[1] = priv->ht40_1s_tx_power_index_B[group];
2426
2427 ofdmbase[0] = ofdm[0] + priv->ofdm_tx_power_index_diff[group].a;
2428 ofdmbase[1] = ofdm[1] + priv->ofdm_tx_power_index_diff[group].b;
2429
2430 mcsbase[0] = ofdm[0];
2431 mcsbase[1] = ofdm[1];
2432 if (!ht40) {
2433 mcsbase[0] += priv->ht20_tx_power_index_diff[group].a;
2434 mcsbase[1] += priv->ht20_tx_power_index_diff[group].b;
2435 }
2436
2437 if (priv->tx_paths > 1) {
2438 if (ofdm[0] > priv->ht40_2s_tx_power_index_diff[group].a)
2439 ofdm[0] -= priv->ht40_2s_tx_power_index_diff[group].a;
2440 if (ofdm[1] > priv->ht40_2s_tx_power_index_diff[group].b)
2441 ofdm[1] -= priv->ht40_2s_tx_power_index_diff[group].b;
2442 }
2443
2444 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
2445 dev_info(&priv->udev->dev,
2446 "%s: Setting TX power CCK A: %02x, "
2447 "CCK B: %02x, OFDM A: %02x, OFDM B: %02x\n",
2448 __func__, cck[0], cck[1], ofdm[0], ofdm[1]);
2449
2450 for (i = 0; i < RTL8723A_MAX_RF_PATHS; i++) {
2451 if (cck[i] > RF6052_MAX_TX_PWR)
2452 cck[i] = RF6052_MAX_TX_PWR;
2453 if (ofdm[i] > RF6052_MAX_TX_PWR)
2454 ofdm[i] = RF6052_MAX_TX_PWR;
2455 }
2456
2457 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
2458 val32 &= 0xffff00ff;
2459 val32 |= (cck[0] << 8);
2460 rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
2461
2462 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
2463 val32 &= 0xff;
2464 val32 |= ((cck[0] << 8) | (cck[0] << 16) | (cck[0] << 24));
2465 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
2466
2467 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
2468 val32 &= 0xffffff00;
2469 val32 |= cck[1];
2470 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
2471
2472 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK1_55_MCS32);
2473 val32 &= 0xff;
2474 val32 |= ((cck[1] << 8) | (cck[1] << 16) | (cck[1] << 24));
2475 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK1_55_MCS32, val32);
2476
2477 ofdm_a = ofdmbase[0] | ofdmbase[0] << 8 |
2478 ofdmbase[0] << 16 | ofdmbase[0] << 24;
2479 ofdm_b = ofdmbase[1] | ofdmbase[1] << 8 |
2480 ofdmbase[1] << 16 | ofdmbase[1] << 24;
2481 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm_a);
2482 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE18_06, ofdm_b);
2483
2484 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm_a);
2485 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE54_24, ofdm_b);
2486
2487 mcs_a = mcsbase[0] | mcsbase[0] << 8 |
2488 mcsbase[0] << 16 | mcsbase[0] << 24;
2489 mcs_b = mcsbase[1] | mcsbase[1] << 8 |
2490 mcsbase[1] << 16 | mcsbase[1] << 24;
2491
2492 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs_a);
2493 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS03_MCS00, mcs_b);
2494
2495 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs_a);
2496 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS07_MCS04, mcs_b);
2497
2498 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS11_MCS08, mcs_a);
2499 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS11_MCS08, mcs_b);
2500
2501 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12, mcs_a);
2502 for (i = 0; i < 3; i++) {
2503 if (i != 2)
2504 val8 = (mcsbase[0] > 8) ? (mcsbase[0] - 8) : 0;
2505 else
2506 val8 = (mcsbase[0] > 6) ? (mcsbase[0] - 6) : 0;
2507 rtl8xxxu_write8(priv, REG_OFDM0_XC_TX_IQ_IMBALANCE + i, val8);
2508 }
2509 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12, mcs_b);
2510 for (i = 0; i < 3; i++) {
2511 if (i != 2)
2512 val8 = (mcsbase[1] > 8) ? (mcsbase[1] - 8) : 0;
2513 else
2514 val8 = (mcsbase[1] > 6) ? (mcsbase[1] - 6) : 0;
2515 rtl8xxxu_write8(priv, REG_OFDM0_XD_TX_IQ_IMBALANCE + i, val8);
2516 }
2517}
2518
Jes Sorensene796dab2016-02-29 17:05:19 -05002519static void
2520rtl8723b_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
2521{
Jes Sorensen1d3cc442016-02-29 17:05:24 -05002522 u32 val32, ofdm, mcs;
2523 u8 cck, ofdmbase, mcsbase;
Jes Sorensen54bed432016-02-29 17:05:23 -05002524 int group, tx_idx;
Jes Sorensene796dab2016-02-29 17:05:19 -05002525
Jes Sorensen54bed432016-02-29 17:05:23 -05002526 tx_idx = 0;
Jes Sorensene796dab2016-02-29 17:05:19 -05002527 group = rtl8723b_channel_to_group(channel);
Jes Sorensen54bed432016-02-29 17:05:23 -05002528
2529 cck = priv->cck_tx_power_index_B[group];
2530 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
2531 val32 &= 0xffff00ff;
2532 val32 |= (cck << 8);
2533 rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
2534
2535 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
2536 val32 &= 0xff;
2537 val32 |= ((cck << 8) | (cck << 16) | (cck << 24));
2538 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
2539
2540 ofdmbase = priv->ht40_1s_tx_power_index_B[group];
2541 ofdmbase += priv->ofdm_tx_power_diff[tx_idx].b;
2542 ofdm = ofdmbase | ofdmbase << 8 | ofdmbase << 16 | ofdmbase << 24;
2543
2544 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm);
2545 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm);
Jes Sorensen1d3cc442016-02-29 17:05:24 -05002546
2547 mcsbase = priv->ht40_1s_tx_power_index_B[group];
2548 if (ht40)
2549 mcsbase += priv->ht40_tx_power_diff[tx_idx++].b;
2550 else
2551 mcsbase += priv->ht20_tx_power_diff[tx_idx++].b;
2552 mcs = mcsbase | mcsbase << 8 | mcsbase << 16 | mcsbase << 24;
2553
2554 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs);
2555 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs);
Jes Sorensene796dab2016-02-29 17:05:19 -05002556}
2557
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002558static void rtl8xxxu_set_linktype(struct rtl8xxxu_priv *priv,
2559 enum nl80211_iftype linktype)
2560{
Jes Sorensena26703f2016-02-03 13:39:56 -05002561 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002562
Jes Sorensena26703f2016-02-03 13:39:56 -05002563 val8 = rtl8xxxu_read8(priv, REG_MSR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002564 val8 &= ~MSR_LINKTYPE_MASK;
2565
2566 switch (linktype) {
2567 case NL80211_IFTYPE_UNSPECIFIED:
2568 val8 |= MSR_LINKTYPE_NONE;
2569 break;
2570 case NL80211_IFTYPE_ADHOC:
2571 val8 |= MSR_LINKTYPE_ADHOC;
2572 break;
2573 case NL80211_IFTYPE_STATION:
2574 val8 |= MSR_LINKTYPE_STATION;
2575 break;
2576 case NL80211_IFTYPE_AP:
2577 val8 |= MSR_LINKTYPE_AP;
2578 break;
2579 default:
2580 goto out;
2581 }
2582
2583 rtl8xxxu_write8(priv, REG_MSR, val8);
2584out:
2585 return;
2586}
2587
2588static void
2589rtl8xxxu_set_retry(struct rtl8xxxu_priv *priv, u16 short_retry, u16 long_retry)
2590{
2591 u16 val16;
2592
2593 val16 = ((short_retry << RETRY_LIMIT_SHORT_SHIFT) &
2594 RETRY_LIMIT_SHORT_MASK) |
2595 ((long_retry << RETRY_LIMIT_LONG_SHIFT) &
2596 RETRY_LIMIT_LONG_MASK);
2597
2598 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
2599}
2600
2601static void
2602rtl8xxxu_set_spec_sifs(struct rtl8xxxu_priv *priv, u16 cck, u16 ofdm)
2603{
2604 u16 val16;
2605
2606 val16 = ((cck << SPEC_SIFS_CCK_SHIFT) & SPEC_SIFS_CCK_MASK) |
2607 ((ofdm << SPEC_SIFS_OFDM_SHIFT) & SPEC_SIFS_OFDM_MASK);
2608
2609 rtl8xxxu_write16(priv, REG_SPEC_SIFS, val16);
2610}
2611
2612static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv)
2613{
2614 struct device *dev = &priv->udev->dev;
2615 char *cut;
2616
2617 switch (priv->chip_cut) {
2618 case 0:
2619 cut = "A";
2620 break;
2621 case 1:
2622 cut = "B";
2623 break;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002624 case 2:
2625 cut = "C";
2626 break;
2627 case 3:
2628 cut = "D";
2629 break;
2630 case 4:
2631 cut = "E";
2632 break;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002633 default:
2634 cut = "unknown";
2635 }
2636
2637 dev_info(dev,
2638 "RTL%s rev %s (%s) %iT%iR, TX queues %i, WiFi=%i, BT=%i, GPS=%i, HI PA=%i\n",
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002639 priv->chip_name, cut, priv->chip_vendor, priv->tx_paths,
2640 priv->rx_paths, priv->ep_tx_count, priv->has_wifi,
2641 priv->has_bluetooth, priv->has_gps, priv->hi_pa);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002642
2643 dev_info(dev, "RTL%s MAC: %pM\n", priv->chip_name, priv->mac_addr);
2644}
2645
2646static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
2647{
2648 struct device *dev = &priv->udev->dev;
2649 u32 val32, bonding;
2650 u16 val16;
2651
2652 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
2653 priv->chip_cut = (val32 & SYS_CFG_CHIP_VERSION_MASK) >>
2654 SYS_CFG_CHIP_VERSION_SHIFT;
2655 if (val32 & SYS_CFG_TRP_VAUX_EN) {
2656 dev_info(dev, "Unsupported test chip\n");
2657 return -ENOTSUPP;
2658 }
2659
2660 if (val32 & SYS_CFG_BT_FUNC) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05002661 if (priv->chip_cut >= 3) {
2662 sprintf(priv->chip_name, "8723BU");
Jes Sorensenba17d822016-03-31 17:08:39 -04002663 priv->rtl_chip = RTL8723B;
Jes Sorensen35a741f2016-02-29 17:04:10 -05002664 } else {
2665 sprintf(priv->chip_name, "8723AU");
Jes Sorensen0e28b972016-02-29 17:04:13 -05002666 priv->usb_interrupts = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002667 priv->rtl_chip = RTL8723A;
Jes Sorensen35a741f2016-02-29 17:04:10 -05002668 }
2669
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002670 priv->rf_paths = 1;
2671 priv->rx_paths = 1;
2672 priv->tx_paths = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002673
2674 val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL);
2675 if (val32 & MULTI_WIFI_FUNC_EN)
2676 priv->has_wifi = 1;
2677 if (val32 & MULTI_BT_FUNC_EN)
2678 priv->has_bluetooth = 1;
2679 if (val32 & MULTI_GPS_FUNC_EN)
2680 priv->has_gps = 1;
Jakub Sitnicki38451992016-02-03 13:39:49 -05002681 priv->is_multi_func = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002682 } else if (val32 & SYS_CFG_TYPE_ID) {
2683 bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
2684 bonding &= HPON_FSM_BONDING_MASK;
Jes Sorensenaf13faf2016-03-31 17:08:40 -04002685 if (priv->fops->has_s0s1) {
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002686 if (bonding == HPON_FSM_BONDING_1T2R) {
2687 sprintf(priv->chip_name, "8191EU");
2688 priv->rf_paths = 2;
2689 priv->rx_paths = 2;
2690 priv->tx_paths = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002691 priv->rtl_chip = RTL8191E;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002692 } else {
2693 sprintf(priv->chip_name, "8192EU");
2694 priv->rf_paths = 2;
2695 priv->rx_paths = 2;
2696 priv->tx_paths = 2;
Jes Sorensenba17d822016-03-31 17:08:39 -04002697 priv->rtl_chip = RTL8192E;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002698 }
2699 } else if (bonding == HPON_FSM_BONDING_1T2R) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002700 sprintf(priv->chip_name, "8191CU");
2701 priv->rf_paths = 2;
2702 priv->rx_paths = 2;
2703 priv->tx_paths = 1;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002704 priv->usb_interrupts = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002705 priv->rtl_chip = RTL8191C;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002706 } else {
2707 sprintf(priv->chip_name, "8192CU");
2708 priv->rf_paths = 2;
2709 priv->rx_paths = 2;
2710 priv->tx_paths = 2;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002711 priv->usb_interrupts = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002712 priv->rtl_chip = RTL8192C;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002713 }
2714 priv->has_wifi = 1;
2715 } else {
2716 sprintf(priv->chip_name, "8188CU");
2717 priv->rf_paths = 1;
2718 priv->rx_paths = 1;
2719 priv->tx_paths = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002720 priv->rtl_chip = RTL8188C;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002721 priv->usb_interrupts = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002722 priv->has_wifi = 1;
2723 }
2724
Jes Sorensenba17d822016-03-31 17:08:39 -04002725 switch (priv->rtl_chip) {
2726 case RTL8188E:
2727 case RTL8192E:
2728 case RTL8723B:
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002729 switch (val32 & SYS_CFG_VENDOR_EXT_MASK) {
2730 case SYS_CFG_VENDOR_ID_TSMC:
2731 sprintf(priv->chip_vendor, "TSMC");
2732 break;
2733 case SYS_CFG_VENDOR_ID_SMIC:
2734 sprintf(priv->chip_vendor, "SMIC");
2735 priv->vendor_smic = 1;
2736 break;
2737 case SYS_CFG_VENDOR_ID_UMC:
2738 sprintf(priv->chip_vendor, "UMC");
2739 priv->vendor_umc = 1;
2740 break;
2741 default:
2742 sprintf(priv->chip_vendor, "unknown");
2743 }
2744 break;
2745 default:
2746 if (val32 & SYS_CFG_VENDOR_ID) {
2747 sprintf(priv->chip_vendor, "UMC");
2748 priv->vendor_umc = 1;
2749 } else {
2750 sprintf(priv->chip_vendor, "TSMC");
2751 }
2752 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002753
2754 val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
2755 priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;
2756
2757 val16 = rtl8xxxu_read16(priv, REG_NORMAL_SIE_EP_TX);
2758 if (val16 & NORMAL_SIE_EP_TX_HIGH_MASK) {
2759 priv->ep_tx_high_queue = 1;
2760 priv->ep_tx_count++;
2761 }
2762
2763 if (val16 & NORMAL_SIE_EP_TX_NORMAL_MASK) {
2764 priv->ep_tx_normal_queue = 1;
2765 priv->ep_tx_count++;
2766 }
2767
2768 if (val16 & NORMAL_SIE_EP_TX_LOW_MASK) {
2769 priv->ep_tx_low_queue = 1;
2770 priv->ep_tx_count++;
2771 }
2772
2773 /*
2774 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
2775 */
2776 if (!priv->ep_tx_count) {
2777 switch (priv->nr_out_eps) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05002778 case 4:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002779 case 3:
2780 priv->ep_tx_low_queue = 1;
2781 priv->ep_tx_count++;
2782 case 2:
2783 priv->ep_tx_normal_queue = 1;
2784 priv->ep_tx_count++;
2785 case 1:
2786 priv->ep_tx_high_queue = 1;
2787 priv->ep_tx_count++;
2788 break;
2789 default:
2790 dev_info(dev, "Unsupported USB TX end-points\n");
2791 return -ENOTSUPP;
2792 }
2793 }
2794
2795 return 0;
2796}
2797
2798static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv)
2799{
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002800 struct rtl8723au_efuse *efuse = &priv->efuse_wifi.efuse8723;
2801
2802 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002803 return -EINVAL;
2804
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002805 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002806
2807 memcpy(priv->cck_tx_power_index_A,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002808 efuse->cck_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002809 sizeof(efuse->cck_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002810 memcpy(priv->cck_tx_power_index_B,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002811 efuse->cck_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002812 sizeof(efuse->cck_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002813
2814 memcpy(priv->ht40_1s_tx_power_index_A,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002815 efuse->ht40_1s_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002816 sizeof(efuse->ht40_1s_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002817 memcpy(priv->ht40_1s_tx_power_index_B,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002818 efuse->ht40_1s_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002819 sizeof(efuse->ht40_1s_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002820
2821 memcpy(priv->ht20_tx_power_index_diff,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002822 efuse->ht20_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002823 sizeof(efuse->ht20_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002824 memcpy(priv->ofdm_tx_power_index_diff,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002825 efuse->ofdm_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002826 sizeof(efuse->ofdm_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002827
2828 memcpy(priv->ht40_max_power_offset,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002829 efuse->ht40_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002830 sizeof(efuse->ht40_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002831 memcpy(priv->ht20_max_power_offset,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002832 efuse->ht20_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002833 sizeof(efuse->ht20_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002834
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05002835 if (priv->efuse_wifi.efuse8723.version >= 0x01) {
2836 priv->has_xtalk = 1;
2837 priv->xtalk = priv->efuse_wifi.efuse8723.xtal_k & 0x3f;
2838 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002839 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002840 efuse->vendor_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002841 dev_info(&priv->udev->dev, "Product: %.41s\n",
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002842 efuse->device_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002843 return 0;
2844}
2845
Jes Sorensen3c836d62016-02-29 17:04:11 -05002846static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv)
2847{
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002848 struct rtl8723bu_efuse *efuse = &priv->efuse_wifi.efuse8723bu;
Jes Sorensen3be26992016-02-29 17:05:22 -05002849 int i;
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002850
2851 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen3c836d62016-02-29 17:04:11 -05002852 return -EINVAL;
2853
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002854 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen3c836d62016-02-29 17:04:11 -05002855
Jes Sorensen3be26992016-02-29 17:05:22 -05002856 memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base,
2857 sizeof(efuse->tx_power_index_A.cck_base));
2858 memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base,
2859 sizeof(efuse->tx_power_index_B.cck_base));
2860
2861 memcpy(priv->ht40_1s_tx_power_index_A,
2862 efuse->tx_power_index_A.ht40_base,
2863 sizeof(efuse->tx_power_index_A.ht40_base));
2864 memcpy(priv->ht40_1s_tx_power_index_B,
2865 efuse->tx_power_index_B.ht40_base,
2866 sizeof(efuse->tx_power_index_B.ht40_base));
2867
2868 priv->ofdm_tx_power_diff[0].a =
2869 efuse->tx_power_index_A.ht20_ofdm_1s_diff.a;
2870 priv->ofdm_tx_power_diff[0].b =
2871 efuse->tx_power_index_B.ht20_ofdm_1s_diff.a;
2872
2873 priv->ht20_tx_power_diff[0].a =
2874 efuse->tx_power_index_A.ht20_ofdm_1s_diff.b;
2875 priv->ht20_tx_power_diff[0].b =
2876 efuse->tx_power_index_B.ht20_ofdm_1s_diff.b;
2877
2878 priv->ht40_tx_power_diff[0].a = 0;
2879 priv->ht40_tx_power_diff[0].b = 0;
2880
2881 for (i = 1; i < RTL8723B_TX_COUNT; i++) {
2882 priv->ofdm_tx_power_diff[i].a =
2883 efuse->tx_power_index_A.pwr_diff[i - 1].ofdm;
2884 priv->ofdm_tx_power_diff[i].b =
2885 efuse->tx_power_index_B.pwr_diff[i - 1].ofdm;
2886
2887 priv->ht20_tx_power_diff[i].a =
2888 efuse->tx_power_index_A.pwr_diff[i - 1].ht20;
2889 priv->ht20_tx_power_diff[i].b =
2890 efuse->tx_power_index_B.pwr_diff[i - 1].ht20;
2891
2892 priv->ht40_tx_power_diff[i].a =
2893 efuse->tx_power_index_A.pwr_diff[i - 1].ht40;
2894 priv->ht40_tx_power_diff[i].b =
2895 efuse->tx_power_index_B.pwr_diff[i - 1].ht40;
2896 }
2897
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05002898 priv->has_xtalk = 1;
2899 priv->xtalk = priv->efuse_wifi.efuse8723bu.xtal_k & 0x3f;
2900
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002901 dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name);
2902 dev_info(&priv->udev->dev, "Product: %.41s\n", efuse->device_name);
Jes Sorensen3c836d62016-02-29 17:04:11 -05002903
2904 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2905 int i;
2906 unsigned char *raw = priv->efuse_wifi.raw;
2907
2908 dev_info(&priv->udev->dev,
2909 "%s: dumping efuse (0x%02zx bytes):\n",
2910 __func__, sizeof(struct rtl8723bu_efuse));
2911 for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8) {
2912 dev_info(&priv->udev->dev, "%02x: "
2913 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2914 raw[i], raw[i + 1], raw[i + 2],
2915 raw[i + 3], raw[i + 4], raw[i + 5],
2916 raw[i + 6], raw[i + 7]);
2917 }
2918 }
2919
2920 return 0;
2921}
2922
Kalle Valoc0963772015-10-25 18:24:38 +02002923#ifdef CONFIG_RTL8XXXU_UNTESTED
2924
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002925static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
2926{
Jakub Sitnicki49594442016-02-29 17:04:26 -05002927 struct rtl8192cu_efuse *efuse = &priv->efuse_wifi.efuse8192;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002928 int i;
2929
Jakub Sitnicki49594442016-02-29 17:04:26 -05002930 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002931 return -EINVAL;
2932
Jakub Sitnicki49594442016-02-29 17:04:26 -05002933 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002934
2935 memcpy(priv->cck_tx_power_index_A,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002936 efuse->cck_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002937 sizeof(efuse->cck_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002938 memcpy(priv->cck_tx_power_index_B,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002939 efuse->cck_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002940 sizeof(efuse->cck_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002941
2942 memcpy(priv->ht40_1s_tx_power_index_A,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002943 efuse->ht40_1s_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002944 sizeof(efuse->ht40_1s_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002945 memcpy(priv->ht40_1s_tx_power_index_B,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002946 efuse->ht40_1s_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002947 sizeof(efuse->ht40_1s_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002948 memcpy(priv->ht40_2s_tx_power_index_diff,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002949 efuse->ht40_2s_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002950 sizeof(efuse->ht40_2s_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002951
2952 memcpy(priv->ht20_tx_power_index_diff,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002953 efuse->ht20_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002954 sizeof(efuse->ht20_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002955 memcpy(priv->ofdm_tx_power_index_diff,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002956 efuse->ofdm_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002957 sizeof(efuse->ofdm_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002958
2959 memcpy(priv->ht40_max_power_offset,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002960 efuse->ht40_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002961 sizeof(efuse->ht40_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002962 memcpy(priv->ht20_max_power_offset,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002963 efuse->ht20_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002964 sizeof(efuse->ht20_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002965
2966 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
Jakub Sitnicki49594442016-02-29 17:04:26 -05002967 efuse->vendor_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002968 dev_info(&priv->udev->dev, "Product: %.20s\n",
Jakub Sitnicki49594442016-02-29 17:04:26 -05002969 efuse->device_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002970
Jakub Sitnicki49594442016-02-29 17:04:26 -05002971 if (efuse->rf_regulatory & 0x20) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002972 sprintf(priv->chip_name, "8188RU");
2973 priv->hi_pa = 1;
2974 }
2975
2976 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2977 unsigned char *raw = priv->efuse_wifi.raw;
2978
2979 dev_info(&priv->udev->dev,
2980 "%s: dumping efuse (0x%02zx bytes):\n",
2981 __func__, sizeof(struct rtl8192cu_efuse));
2982 for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8) {
2983 dev_info(&priv->udev->dev, "%02x: "
2984 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2985 raw[i], raw[i + 1], raw[i + 2],
2986 raw[i + 3], raw[i + 4], raw[i + 5],
2987 raw[i + 6], raw[i + 7]);
2988 }
2989 }
2990 return 0;
2991}
2992
Kalle Valoc0963772015-10-25 18:24:38 +02002993#endif
2994
Jes Sorensen3307d842016-02-29 17:03:59 -05002995static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
2996{
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05002997 struct rtl8192eu_efuse *efuse = &priv->efuse_wifi.efuse8192eu;
Jes Sorensen3307d842016-02-29 17:03:59 -05002998 int i;
2999
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05003000 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen3307d842016-02-29 17:03:59 -05003001 return -EINVAL;
3002
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05003003 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen3307d842016-02-29 17:03:59 -05003004
Jes Sorensen9e247722016-04-07 14:19:23 -04003005 memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base,
3006 sizeof(efuse->tx_power_index_A.cck_base));
3007 memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base,
3008 sizeof(efuse->tx_power_index_B.cck_base));
3009
3010 memcpy(priv->ht40_1s_tx_power_index_A,
3011 efuse->tx_power_index_A.ht40_base,
3012 sizeof(efuse->tx_power_index_A.ht40_base));
3013 memcpy(priv->ht40_1s_tx_power_index_B,
3014 efuse->tx_power_index_B.ht40_base,
3015 sizeof(efuse->tx_power_index_B.ht40_base));
3016
3017 priv->ht20_tx_power_diff[0].a =
3018 efuse->tx_power_index_A.ht20_ofdm_1s_diff.b;
3019 priv->ht20_tx_power_diff[0].b =
3020 efuse->tx_power_index_B.ht20_ofdm_1s_diff.b;
3021
3022 priv->ht40_tx_power_diff[0].a = 0;
3023 priv->ht40_tx_power_diff[0].b = 0;
3024
3025 for (i = 1; i < RTL8723B_TX_COUNT; i++) {
3026 priv->ofdm_tx_power_diff[i].a =
3027 efuse->tx_power_index_A.pwr_diff[i - 1].ofdm;
3028 priv->ofdm_tx_power_diff[i].b =
3029 efuse->tx_power_index_B.pwr_diff[i - 1].ofdm;
3030
3031 priv->ht20_tx_power_diff[i].a =
3032 efuse->tx_power_index_A.pwr_diff[i - 1].ht20;
3033 priv->ht20_tx_power_diff[i].b =
3034 efuse->tx_power_index_B.pwr_diff[i - 1].ht20;
3035
3036 priv->ht40_tx_power_diff[i].a =
3037 efuse->tx_power_index_A.pwr_diff[i - 1].ht40;
3038 priv->ht40_tx_power_diff[i].b =
3039 efuse->tx_power_index_B.pwr_diff[i - 1].ht40;
3040 }
3041
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05003042 priv->has_xtalk = 1;
3043 priv->xtalk = priv->efuse_wifi.efuse8192eu.xtal_k & 0x3f;
3044
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05003045 dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name);
3046 dev_info(&priv->udev->dev, "Product: %.11s\n", efuse->device_name);
3047 dev_info(&priv->udev->dev, "Serial: %.11s\n", efuse->serial);
Jes Sorensen3307d842016-02-29 17:03:59 -05003048
3049 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
3050 unsigned char *raw = priv->efuse_wifi.raw;
3051
3052 dev_info(&priv->udev->dev,
3053 "%s: dumping efuse (0x%02zx bytes):\n",
3054 __func__, sizeof(struct rtl8192eu_efuse));
3055 for (i = 0; i < sizeof(struct rtl8192eu_efuse); i += 8) {
3056 dev_info(&priv->udev->dev, "%02x: "
3057 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
3058 raw[i], raw[i + 1], raw[i + 2],
3059 raw[i + 3], raw[i + 4], raw[i + 5],
3060 raw[i + 6], raw[i + 7]);
3061 }
3062 }
Jes Sorensenccfe1e82016-02-29 17:05:51 -05003063 /*
3064 * Temporarily disable 8192eu support
3065 */
3066 return -EINVAL;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05003067 return 0;
Jes Sorensen3307d842016-02-29 17:03:59 -05003068}
3069
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003070static int
3071rtl8xxxu_read_efuse8(struct rtl8xxxu_priv *priv, u16 offset, u8 *data)
3072{
3073 int i;
3074 u8 val8;
3075 u32 val32;
3076
3077 /* Write Address */
3078 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 1, offset & 0xff);
3079 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 2);
3080 val8 &= 0xfc;
3081 val8 |= (offset >> 8) & 0x03;
3082 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 2, val8);
3083
3084 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 3);
3085 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 3, val8 & 0x7f);
3086
3087 /* Poll for data read */
3088 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
3089 for (i = 0; i < RTL8XXXU_MAX_REG_POLL; i++) {
3090 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
3091 if (val32 & BIT(31))
3092 break;
3093 }
3094
3095 if (i == RTL8XXXU_MAX_REG_POLL)
3096 return -EIO;
3097
3098 udelay(50);
3099 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
3100
3101 *data = val32 & 0xff;
3102 return 0;
3103}
3104
3105static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv)
3106{
3107 struct device *dev = &priv->udev->dev;
3108 int i, ret = 0;
3109 u8 val8, word_mask, header, extheader;
3110 u16 val16, efuse_addr, offset;
3111 u32 val32;
3112
3113 val16 = rtl8xxxu_read16(priv, REG_9346CR);
3114 if (val16 & EEPROM_ENABLE)
3115 priv->has_eeprom = 1;
3116 if (val16 & EEPROM_BOOT)
3117 priv->boot_eeprom = 1;
3118
Jakub Sitnicki38451992016-02-03 13:39:49 -05003119 if (priv->is_multi_func) {
3120 val32 = rtl8xxxu_read32(priv, REG_EFUSE_TEST);
3121 val32 = (val32 & ~EFUSE_SELECT_MASK) | EFUSE_WIFI_SELECT;
3122 rtl8xxxu_write32(priv, REG_EFUSE_TEST, val32);
3123 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003124
3125 dev_dbg(dev, "Booting from %s\n",
3126 priv->boot_eeprom ? "EEPROM" : "EFUSE");
3127
3128 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_ENABLE);
3129
3130 /* 1.2V Power: From VDDON with Power Cut(0x0000[15]), default valid */
3131 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
3132 if (!(val16 & SYS_ISO_PWC_EV12V)) {
3133 val16 |= SYS_ISO_PWC_EV12V;
3134 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
3135 }
3136 /* Reset: 0x0000[28], default valid */
3137 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3138 if (!(val16 & SYS_FUNC_ELDR)) {
3139 val16 |= SYS_FUNC_ELDR;
3140 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3141 }
3142
3143 /*
3144 * Clock: Gated(0x0008[5]) 8M(0x0008[1]) clock from ANA, default valid
3145 */
3146 val16 = rtl8xxxu_read16(priv, REG_SYS_CLKR);
3147 if (!(val16 & SYS_CLK_LOADER_ENABLE) || !(val16 & SYS_CLK_ANA8M)) {
3148 val16 |= (SYS_CLK_LOADER_ENABLE | SYS_CLK_ANA8M);
3149 rtl8xxxu_write16(priv, REG_SYS_CLKR, val16);
3150 }
3151
3152 /* Default value is 0xff */
Jes Sorensen3307d842016-02-29 17:03:59 -05003153 memset(priv->efuse_wifi.raw, 0xff, EFUSE_MAP_LEN);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003154
3155 efuse_addr = 0;
3156 while (efuse_addr < EFUSE_REAL_CONTENT_LEN_8723A) {
Jakub Sitnickif6c47702016-02-29 17:04:23 -05003157 u16 map_addr;
3158
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003159 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &header);
3160 if (ret || header == 0xff)
3161 goto exit;
3162
3163 if ((header & 0x1f) == 0x0f) { /* extended header */
3164 offset = (header & 0xe0) >> 5;
3165
3166 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++,
3167 &extheader);
3168 if (ret)
3169 goto exit;
3170 /* All words disabled */
3171 if ((extheader & 0x0f) == 0x0f)
3172 continue;
3173
3174 offset |= ((extheader & 0xf0) >> 1);
3175 word_mask = extheader & 0x0f;
3176 } else {
3177 offset = (header >> 4) & 0x0f;
3178 word_mask = header & 0x0f;
3179 }
3180
Jakub Sitnickif6c47702016-02-29 17:04:23 -05003181 /* Get word enable value from PG header */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003182
Jakub Sitnickif6c47702016-02-29 17:04:23 -05003183 /* We have 8 bits to indicate validity */
3184 map_addr = offset * 8;
3185 if (map_addr >= EFUSE_MAP_LEN) {
3186 dev_warn(dev, "%s: Illegal map_addr (%04x), "
3187 "efuse corrupt!\n",
3188 __func__, map_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003189 ret = -EINVAL;
3190 goto exit;
3191 }
Jakub Sitnickif6c47702016-02-29 17:04:23 -05003192 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
3193 /* Check word enable condition in the section */
Jakub Sitnicki32a39dd2016-02-29 17:04:24 -05003194 if (word_mask & BIT(i)) {
Jakub Sitnickif6c47702016-02-29 17:04:23 -05003195 map_addr += 2;
Jakub Sitnicki32a39dd2016-02-29 17:04:24 -05003196 continue;
3197 }
3198
3199 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
3200 if (ret)
3201 goto exit;
3202 priv->efuse_wifi.raw[map_addr++] = val8;
3203
3204 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
3205 if (ret)
3206 goto exit;
3207 priv->efuse_wifi.raw[map_addr++] = val8;
Jakub Sitnickif6c47702016-02-29 17:04:23 -05003208 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003209 }
3210
3211exit:
3212 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_DISABLE);
3213
3214 return ret;
3215}
3216
Jes Sorensend48fe602016-02-03 13:39:44 -05003217static void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv)
3218{
3219 u8 val8;
3220 u16 sys_func;
3221
3222 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05003223 val8 &= ~BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05003224 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05003225
Jes Sorensend48fe602016-02-03 13:39:44 -05003226 sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3227 sys_func &= ~SYS_FUNC_CPU_ENABLE;
3228 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05003229
Jes Sorensend48fe602016-02-03 13:39:44 -05003230 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05003231 val8 |= BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05003232 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05003233
3234 sys_func |= SYS_FUNC_CPU_ENABLE;
3235 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
3236}
3237
3238static void rtl8723bu_reset_8051(struct rtl8xxxu_priv *priv)
3239{
3240 u8 val8;
3241 u16 sys_func;
3242
3243 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
3244 val8 &= ~BIT(1);
3245 rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
3246
3247 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
3248 val8 &= ~BIT(0);
3249 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
3250
3251 sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3252 sys_func &= ~SYS_FUNC_CPU_ENABLE;
3253 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
3254
3255 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
3256 val8 &= ~BIT(1);
3257 rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
3258
3259 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
3260 val8 |= BIT(0);
3261 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
3262
Jes Sorensend48fe602016-02-03 13:39:44 -05003263 sys_func |= SYS_FUNC_CPU_ENABLE;
3264 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
3265}
3266
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003267static int rtl8xxxu_start_firmware(struct rtl8xxxu_priv *priv)
3268{
3269 struct device *dev = &priv->udev->dev;
3270 int ret = 0, i;
3271 u32 val32;
3272
3273 /* Poll checksum report */
3274 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
3275 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
3276 if (val32 & MCU_FW_DL_CSUM_REPORT)
3277 break;
3278 }
3279
3280 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
3281 dev_warn(dev, "Firmware checksum poll timed out\n");
3282 ret = -EAGAIN;
3283 goto exit;
3284 }
3285
3286 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
3287 val32 |= MCU_FW_DL_READY;
3288 val32 &= ~MCU_WINT_INIT_READY;
3289 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
3290
Jes Sorensend48fe602016-02-03 13:39:44 -05003291 /*
3292 * Reset the 8051 in order for the firmware to start running,
3293 * otherwise it won't come up on the 8192eu
3294 */
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05003295 priv->fops->reset_8051(priv);
Jes Sorensend48fe602016-02-03 13:39:44 -05003296
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003297 /* Wait for firmware to become ready */
3298 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
3299 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
3300 if (val32 & MCU_WINT_INIT_READY)
3301 break;
3302
3303 udelay(100);
3304 }
3305
3306 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
3307 dev_warn(dev, "Firmware failed to start\n");
3308 ret = -EAGAIN;
3309 goto exit;
3310 }
3311
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003312 /*
3313 * Init H2C command
3314 */
Jes Sorensenba17d822016-03-31 17:08:39 -04003315 if (priv->rtl_chip == RTL8723B)
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003316 rtl8xxxu_write8(priv, REG_HMTFR, 0x0f);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003317exit:
3318 return ret;
3319}
3320
3321static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv)
3322{
3323 int pages, remainder, i, ret;
Jes Sorensend48fe602016-02-03 13:39:44 -05003324 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003325 u16 val16;
3326 u32 val32;
3327 u8 *fwptr;
3328
3329 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC + 1);
3330 val8 |= 4;
3331 rtl8xxxu_write8(priv, REG_SYS_FUNC + 1, val8);
3332
3333 /* 8051 enable */
3334 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
Jes Sorensen43154f62016-02-03 13:39:35 -05003335 val16 |= SYS_FUNC_CPU_ENABLE;
3336 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003337
Jes Sorensen216202a2016-02-03 13:39:37 -05003338 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
3339 if (val8 & MCU_FW_RAM_SEL) {
3340 pr_info("do the RAM reset\n");
3341 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05003342 priv->fops->reset_8051(priv);
Jes Sorensen216202a2016-02-03 13:39:37 -05003343 }
3344
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003345 /* MCU firmware download enable */
3346 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05003347 val8 |= MCU_FW_DL_ENABLE;
3348 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003349
3350 /* 8051 reset */
3351 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05003352 val32 &= ~BIT(19);
3353 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003354
3355 /* Reset firmware download checksum */
3356 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05003357 val8 |= MCU_FW_DL_CSUM_REPORT;
3358 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003359
3360 pages = priv->fw_size / RTL_FW_PAGE_SIZE;
3361 remainder = priv->fw_size % RTL_FW_PAGE_SIZE;
3362
3363 fwptr = priv->fw_data->data;
3364
3365 for (i = 0; i < pages; i++) {
3366 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05003367 val8 |= i;
3368 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003369
3370 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
3371 fwptr, RTL_FW_PAGE_SIZE);
3372 if (ret != RTL_FW_PAGE_SIZE) {
3373 ret = -EAGAIN;
3374 goto fw_abort;
3375 }
3376
3377 fwptr += RTL_FW_PAGE_SIZE;
3378 }
3379
3380 if (remainder) {
3381 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05003382 val8 |= i;
3383 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003384 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
3385 fwptr, remainder);
3386 if (ret != remainder) {
3387 ret = -EAGAIN;
3388 goto fw_abort;
3389 }
3390 }
3391
3392 ret = 0;
3393fw_abort:
3394 /* MCU firmware download disable */
3395 val16 = rtl8xxxu_read16(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05003396 val16 &= ~MCU_FW_DL_ENABLE;
3397 rtl8xxxu_write16(priv, REG_MCU_FW_DL, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003398
3399 return ret;
3400}
3401
3402static int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name)
3403{
3404 struct device *dev = &priv->udev->dev;
3405 const struct firmware *fw;
3406 int ret = 0;
3407 u16 signature;
3408
3409 dev_info(dev, "%s: Loading firmware %s\n", DRIVER_NAME, fw_name);
3410 if (request_firmware(&fw, fw_name, &priv->udev->dev)) {
3411 dev_warn(dev, "request_firmware(%s) failed\n", fw_name);
3412 ret = -EAGAIN;
3413 goto exit;
3414 }
3415 if (!fw) {
3416 dev_warn(dev, "Firmware data not available\n");
3417 ret = -EINVAL;
3418 goto exit;
3419 }
3420
3421 priv->fw_data = kmemdup(fw->data, fw->size, GFP_KERNEL);
Tobias Klauser98e27cb2016-02-03 13:39:43 -05003422 if (!priv->fw_data) {
3423 ret = -ENOMEM;
3424 goto exit;
3425 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003426 priv->fw_size = fw->size - sizeof(struct rtl8xxxu_firmware_header);
3427
3428 signature = le16_to_cpu(priv->fw_data->signature);
3429 switch (signature & 0xfff0) {
Jes Sorensen0e5d4352016-02-29 17:04:00 -05003430 case 0x92e0:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003431 case 0x92c0:
3432 case 0x88c0:
Jes Sorensen35a741f2016-02-29 17:04:10 -05003433 case 0x5300:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003434 case 0x2300:
3435 break;
3436 default:
3437 ret = -EINVAL;
3438 dev_warn(dev, "%s: Invalid firmware signature: 0x%04x\n",
3439 __func__, signature);
3440 }
3441
3442 dev_info(dev, "Firmware revision %i.%i (signature 0x%04x)\n",
3443 le16_to_cpu(priv->fw_data->major_version),
3444 priv->fw_data->minor_version, signature);
3445
3446exit:
3447 release_firmware(fw);
3448 return ret;
3449}
3450
3451static int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv)
3452{
3453 char *fw_name;
3454 int ret;
3455
3456 switch (priv->chip_cut) {
3457 case 0:
3458 fw_name = "rtlwifi/rtl8723aufw_A.bin";
3459 break;
3460 case 1:
3461 if (priv->enable_bluetooth)
3462 fw_name = "rtlwifi/rtl8723aufw_B.bin";
3463 else
3464 fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin";
3465
3466 break;
3467 default:
3468 return -EINVAL;
3469 }
3470
3471 ret = rtl8xxxu_load_firmware(priv, fw_name);
3472 return ret;
3473}
3474
Jes Sorensen35a741f2016-02-29 17:04:10 -05003475static int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv)
3476{
3477 char *fw_name;
3478 int ret;
3479
3480 if (priv->enable_bluetooth)
3481 fw_name = "rtlwifi/rtl8723bu_bt.bin";
3482 else
3483 fw_name = "rtlwifi/rtl8723bu_nic.bin";
3484
3485 ret = rtl8xxxu_load_firmware(priv, fw_name);
3486 return ret;
3487}
3488
Kalle Valoc0963772015-10-25 18:24:38 +02003489#ifdef CONFIG_RTL8XXXU_UNTESTED
3490
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003491static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
3492{
3493 char *fw_name;
3494 int ret;
3495
3496 if (!priv->vendor_umc)
3497 fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
Jes Sorensenba17d822016-03-31 17:08:39 -04003498 else if (priv->chip_cut || priv->rtl_chip == RTL8192C)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003499 fw_name = "rtlwifi/rtl8192cufw_B.bin";
3500 else
3501 fw_name = "rtlwifi/rtl8192cufw_A.bin";
3502
3503 ret = rtl8xxxu_load_firmware(priv, fw_name);
3504
3505 return ret;
3506}
3507
Kalle Valoc0963772015-10-25 18:24:38 +02003508#endif
3509
Jes Sorensen3307d842016-02-29 17:03:59 -05003510static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv)
3511{
3512 char *fw_name;
3513 int ret;
3514
Jes Sorensen0e5d4352016-02-29 17:04:00 -05003515 fw_name = "rtlwifi/rtl8192eu_nic.bin";
Jes Sorensen3307d842016-02-29 17:03:59 -05003516
3517 ret = rtl8xxxu_load_firmware(priv, fw_name);
3518
3519 return ret;
3520}
3521
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003522static void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv)
3523{
3524 u16 val16;
3525 int i = 100;
3526
3527 /* Inform 8051 to perform reset */
3528 rtl8xxxu_write8(priv, REG_HMTFR + 3, 0x20);
3529
3530 for (i = 100; i > 0; i--) {
3531 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3532
3533 if (!(val16 & SYS_FUNC_CPU_ENABLE)) {
3534 dev_dbg(&priv->udev->dev,
3535 "%s: Firmware self reset success!\n", __func__);
3536 break;
3537 }
3538 udelay(50);
3539 }
3540
3541 if (!i) {
3542 /* Force firmware reset */
3543 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3544 val16 &= ~SYS_FUNC_CPU_ENABLE;
3545 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3546 }
3547}
3548
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003549static void rtl8723bu_phy_init_antenna_selection(struct rtl8xxxu_priv *priv)
3550{
3551 u32 val32;
3552
3553 val32 = rtl8xxxu_read32(priv, 0x64);
3554 val32 &= ~(BIT(20) | BIT(24));
3555 rtl8xxxu_write32(priv, 0x64, val32);
3556
3557 val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG);
3558 val32 &= ~BIT(4);
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003559 rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32);
3560
3561 val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003562 val32 |= BIT(3);
3563 rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32);
3564
3565 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003566 val32 |= BIT(24);
3567 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
3568
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003569 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
3570 val32 &= ~BIT(23);
3571 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
3572
Jes Sorensen120e6272016-02-29 17:05:14 -05003573 val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003574 val32 |= (BIT(0) | BIT(1));
Jes Sorensen120e6272016-02-29 17:05:14 -05003575 rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003576
Jes Sorensen59b74392016-02-29 17:05:15 -05003577 val32 = rtl8xxxu_read32(priv, REG_RFE_CTRL_ANTA_SRC);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003578 val32 &= 0xffffff00;
3579 val32 |= 0x77;
Jes Sorensen59b74392016-02-29 17:05:15 -05003580 rtl8xxxu_write32(priv, REG_RFE_CTRL_ANTA_SRC, val32);
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003581
3582 val32 = rtl8xxxu_read32(priv, REG_PWR_DATA);
3583 val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
3584 rtl8xxxu_write32(priv, REG_PWR_DATA, val32);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003585}
3586
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003587static int
Jes Sorensenc606e662016-04-07 14:19:16 -04003588rtl8xxxu_init_mac(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003589{
Jes Sorensenc606e662016-04-07 14:19:16 -04003590 struct rtl8xxxu_reg8val *array = priv->fops->mactable;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003591 int i, ret;
3592 u16 reg;
3593 u8 val;
3594
3595 for (i = 0; ; i++) {
3596 reg = array[i].reg;
3597 val = array[i].val;
3598
3599 if (reg == 0xffff && val == 0xff)
3600 break;
3601
3602 ret = rtl8xxxu_write8(priv, reg, val);
3603 if (ret != 1) {
3604 dev_warn(&priv->udev->dev,
Jes Sorensenc606e662016-04-07 14:19:16 -04003605 "Failed to initialize MAC "
3606 "(reg: %04x, val %02x)\n", reg, val);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003607 return -EAGAIN;
3608 }
3609 }
3610
Jes Sorensen8a594852016-04-07 14:19:26 -04003611 if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E)
Jes Sorensen8baf6702016-02-29 17:04:54 -05003612 rtl8xxxu_write8(priv, REG_MAX_AGGR_NUM, 0x0a);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003613
3614 return 0;
3615}
3616
3617static int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv,
3618 struct rtl8xxxu_reg32val *array)
3619{
3620 int i, ret;
3621 u16 reg;
3622 u32 val;
3623
3624 for (i = 0; ; i++) {
3625 reg = array[i].reg;
3626 val = array[i].val;
3627
3628 if (reg == 0xffff && val == 0xffffffff)
3629 break;
3630
3631 ret = rtl8xxxu_write32(priv, reg, val);
3632 if (ret != sizeof(val)) {
3633 dev_warn(&priv->udev->dev,
3634 "Failed to initialize PHY\n");
3635 return -EAGAIN;
3636 }
3637 udelay(1);
3638 }
3639
3640 return 0;
3641}
3642
3643/*
3644 * Most of this is black magic retrieved from the old rtl8723au driver
3645 */
3646static int rtl8xxxu_init_phy_bb(struct rtl8xxxu_priv *priv)
3647{
3648 u8 val8, ldoa15, ldov12d, lpldo, ldohci12;
Jes Sorensen04313eb2016-02-29 17:04:51 -05003649 u16 val16;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003650 u32 val32;
3651
3652 /*
3653 * Todo: The vendor driver maintains a table of PHY register
3654 * addresses, which is initialized here. Do we need this?
3655 */
3656
Jes Sorensenba17d822016-03-31 17:08:39 -04003657 if (priv->rtl_chip == RTL8723B) {
Jes Sorensen8baf6702016-02-29 17:04:54 -05003658 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3659 val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB |
3660 SYS_FUNC_DIO_RF;
3661 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3662
Jes Sorensen3ca7b322016-02-29 17:04:43 -05003663 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00);
Jes Sorensen444004b2016-04-07 14:19:24 -04003664 } else if (priv->rtl_chip == RTL8192E) {
3665 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3666 val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB |
3667 SYS_FUNC_DIO_RF;
3668 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
Jes Sorensen3ca7b322016-02-29 17:04:43 -05003669 } else {
3670 val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL);
3671 udelay(2);
3672 val8 |= AFE_PLL_320_ENABLE;
3673 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8);
3674 udelay(2);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003675
Jes Sorensen3ca7b322016-02-29 17:04:43 -05003676 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL + 1, 0xff);
3677 udelay(2);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003678
Jes Sorensen8baf6702016-02-29 17:04:54 -05003679 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3680 val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB;
3681 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3682 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003683
Jes Sorensen2ca73dc2016-04-07 14:19:17 -04003684 if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E) {
Jes Sorensen04313eb2016-02-29 17:04:51 -05003685 /* AFE_XTAL_RF_GATE (bit 14) if addressing as 32 bit register */
3686 val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL);
3687 val32 &= ~AFE_XTAL_RF_GATE;
3688 if (priv->has_bluetooth)
3689 val32 &= ~AFE_XTAL_BT_GATE;
3690 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32);
3691 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003692
3693 /* 6. 0x1f[7:0] = 0x07 */
3694 val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
3695 rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
3696
Jes Sorensenabd71bd2016-04-07 14:19:22 -04003697 if (priv->rtl_chip == RTL8723B) {
Jes Sorensen8baf6702016-02-29 17:04:54 -05003698 /*
3699 * Why?
3700 */
3701 rtl8xxxu_write8(priv, REG_SYS_FUNC, 0xe3);
3702 rtl8xxxu_write8(priv, REG_AFE_XTAL_CTRL + 1, 0x80);
Jes Sorensen36c32582016-02-29 17:04:14 -05003703 rtl8xxxu_init_phy_regs(priv, rtl8723b_phy_1t_init_table);
Jes Sorensenae14c5d2016-04-07 14:19:21 -04003704 } else if (priv->rtl_chip == RTL8192E) {
3705 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3706 val16 |= (SYS_FUNC_USBA | SYS_FUNC_USBD | SYS_FUNC_DIO_RF |
3707 SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB);
3708 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3709 val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
3710 rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
3711 rtl8xxxu_init_phy_regs(priv, rtl8192eu_phy_init_table);
Jes Sorensenabd71bd2016-04-07 14:19:22 -04003712 } else if (priv->hi_pa)
3713 rtl8xxxu_init_phy_regs(priv, rtl8188ru_phy_1t_highpa_table);
3714 else if (priv->tx_paths == 2)
3715 rtl8xxxu_init_phy_regs(priv, rtl8192cu_phy_2t_init_table);
3716 else
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003717 rtl8xxxu_init_phy_regs(priv, rtl8723a_phy_1t_init_table);
3718
Jes Sorensenba17d822016-03-31 17:08:39 -04003719 if (priv->rtl_chip == RTL8188C && priv->hi_pa &&
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003720 priv->vendor_umc && priv->chip_cut == 1)
3721 rtl8xxxu_write8(priv, REG_OFDM0_AGC_PARM1 + 2, 0x50);
3722
3723 if (priv->tx_paths == 1 && priv->rx_paths == 2) {
3724 /*
3725 * For 1T2R boards, patch the registers.
3726 *
3727 * It looks like 8191/2 1T2R boards use path B for TX
3728 */
3729 val32 = rtl8xxxu_read32(priv, REG_FPGA0_TX_INFO);
3730 val32 &= ~(BIT(0) | BIT(1));
3731 val32 |= BIT(1);
3732 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, val32);
3733
3734 val32 = rtl8xxxu_read32(priv, REG_FPGA1_TX_INFO);
3735 val32 &= ~0x300033;
3736 val32 |= 0x200022;
3737 rtl8xxxu_write32(priv, REG_FPGA1_TX_INFO, val32);
3738
3739 val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
3740 val32 &= 0xff000000;
3741 val32 |= 0x45000000;
3742 rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
3743
3744 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
3745 val32 &= ~(OFDM_RF_PATH_RX_MASK | OFDM_RF_PATH_TX_MASK);
3746 val32 |= (OFDM_RF_PATH_RX_A | OFDM_RF_PATH_RX_B |
3747 OFDM_RF_PATH_TX_B);
3748 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
3749
3750 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGC_PARM1);
3751 val32 &= ~(BIT(4) | BIT(5));
3752 val32 |= BIT(4);
3753 rtl8xxxu_write32(priv, REG_OFDM0_AGC_PARM1, val32);
3754
3755 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_RFON);
3756 val32 &= ~(BIT(27) | BIT(26));
3757 val32 |= BIT(27);
3758 rtl8xxxu_write32(priv, REG_TX_CCK_RFON, val32);
3759
3760 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_BBON);
3761 val32 &= ~(BIT(27) | BIT(26));
3762 val32 |= BIT(27);
3763 rtl8xxxu_write32(priv, REG_TX_CCK_BBON, val32);
3764
3765 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_RFON);
3766 val32 &= ~(BIT(27) | BIT(26));
3767 val32 |= BIT(27);
3768 rtl8xxxu_write32(priv, REG_TX_OFDM_RFON, val32);
3769
3770 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_BBON);
3771 val32 &= ~(BIT(27) | BIT(26));
3772 val32 |= BIT(27);
3773 rtl8xxxu_write32(priv, REG_TX_OFDM_BBON, val32);
3774
3775 val32 = rtl8xxxu_read32(priv, REG_TX_TO_TX);
3776 val32 &= ~(BIT(27) | BIT(26));
3777 val32 |= BIT(27);
3778 rtl8xxxu_write32(priv, REG_TX_TO_TX, val32);
3779 }
3780
Jes Sorensenba17d822016-03-31 17:08:39 -04003781 if (priv->rtl_chip == RTL8723B)
Jes Sorensenb9f498e2016-02-29 17:04:18 -05003782 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8723bu_table);
Jes Sorensene2932782016-04-07 14:19:20 -04003783 else if (priv->rtl_chip == RTL8192E) {
3784 if (priv->hi_pa)
3785 rtl8xxxu_init_phy_regs(priv,
3786 rtl8xxx_agc_8192eu_highpa_table);
3787 else
3788 rtl8xxxu_init_phy_regs(priv,
3789 rtl8xxx_agc_8192eu_std_table);
3790 } else if (priv->hi_pa)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003791 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_highpa_table);
3792 else
3793 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_standard_table);
3794
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05003795 if (priv->has_xtalk) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003796 val32 = rtl8xxxu_read32(priv, REG_MAC_PHY_CTRL);
3797
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05003798 val8 = priv->xtalk;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003799 val32 &= 0xff000fff;
3800 val32 |= ((val8 | (val8 << 6)) << 12);
3801
3802 rtl8xxxu_write32(priv, REG_MAC_PHY_CTRL, val32);
3803 }
3804
Jes Sorensena069caa2016-03-31 17:08:42 -04003805 if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E) {
Jes Sorensena0e262b2016-02-29 17:04:56 -05003806 ldoa15 = LDOA15_ENABLE | LDOA15_OBUF;
3807 ldov12d = LDOV12D_ENABLE | BIT(2) | (2 << LDOV12D_VADJ_SHIFT);
3808 ldohci12 = 0x57;
3809 lpldo = 1;
3810 val32 = (lpldo << 24) | (ldohci12 << 16) |
3811 (ldov12d << 8) | ldoa15;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003812
Jes Sorensena0e262b2016-02-29 17:04:56 -05003813 rtl8xxxu_write32(priv, REG_LDOA15_CTRL, val32);
3814 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003815
Jes Sorensen8a594852016-04-07 14:19:26 -04003816 if (priv->rtl_chip == RTL8192E)
3817 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x000f81fb);
3818
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003819 return 0;
3820}
3821
3822static int rtl8xxxu_init_rf_regs(struct rtl8xxxu_priv *priv,
3823 struct rtl8xxxu_rfregval *array,
3824 enum rtl8xxxu_rfpath path)
3825{
3826 int i, ret;
3827 u8 reg;
3828 u32 val;
3829
3830 for (i = 0; ; i++) {
3831 reg = array[i].reg;
3832 val = array[i].val;
3833
3834 if (reg == 0xff && val == 0xffffffff)
3835 break;
3836
3837 switch (reg) {
3838 case 0xfe:
3839 msleep(50);
3840 continue;
3841 case 0xfd:
3842 mdelay(5);
3843 continue;
3844 case 0xfc:
3845 mdelay(1);
3846 continue;
3847 case 0xfb:
3848 udelay(50);
3849 continue;
3850 case 0xfa:
3851 udelay(5);
3852 continue;
3853 case 0xf9:
3854 udelay(1);
3855 continue;
3856 }
3857
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003858 ret = rtl8xxxu_write_rfreg(priv, path, reg, val);
3859 if (ret) {
3860 dev_warn(&priv->udev->dev,
3861 "Failed to initialize RF\n");
3862 return -EAGAIN;
3863 }
3864 udelay(1);
3865 }
3866
3867 return 0;
3868}
3869
3870static int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv *priv,
3871 struct rtl8xxxu_rfregval *table,
3872 enum rtl8xxxu_rfpath path)
3873{
3874 u32 val32;
3875 u16 val16, rfsi_rfenv;
3876 u16 reg_sw_ctrl, reg_int_oe, reg_hssi_parm2;
3877
3878 switch (path) {
3879 case RF_A:
3880 reg_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL;
3881 reg_int_oe = REG_FPGA0_XA_RF_INT_OE;
3882 reg_hssi_parm2 = REG_FPGA0_XA_HSSI_PARM2;
3883 break;
3884 case RF_B:
3885 reg_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL;
3886 reg_int_oe = REG_FPGA0_XB_RF_INT_OE;
3887 reg_hssi_parm2 = REG_FPGA0_XB_HSSI_PARM2;
3888 break;
3889 default:
3890 dev_err(&priv->udev->dev, "%s:Unsupported RF path %c\n",
3891 __func__, path + 'A');
3892 return -EINVAL;
3893 }
3894 /* For path B, use XB */
3895 rfsi_rfenv = rtl8xxxu_read16(priv, reg_sw_ctrl);
3896 rfsi_rfenv &= FPGA0_RF_RFENV;
3897
3898 /*
3899 * These two we might be able to optimize into one
3900 */
3901 val32 = rtl8xxxu_read32(priv, reg_int_oe);
3902 val32 |= BIT(20); /* 0x10 << 16 */
3903 rtl8xxxu_write32(priv, reg_int_oe, val32);
3904 udelay(1);
3905
3906 val32 = rtl8xxxu_read32(priv, reg_int_oe);
3907 val32 |= BIT(4);
3908 rtl8xxxu_write32(priv, reg_int_oe, val32);
3909 udelay(1);
3910
3911 /*
3912 * These two we might be able to optimize into one
3913 */
3914 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
3915 val32 &= ~FPGA0_HSSI_3WIRE_ADDR_LEN;
3916 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
3917 udelay(1);
3918
3919 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
3920 val32 &= ~FPGA0_HSSI_3WIRE_DATA_LEN;
3921 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
3922 udelay(1);
3923
3924 rtl8xxxu_init_rf_regs(priv, table, path);
3925
3926 /* For path B, use XB */
3927 val16 = rtl8xxxu_read16(priv, reg_sw_ctrl);
3928 val16 &= ~FPGA0_RF_RFENV;
3929 val16 |= rfsi_rfenv;
3930 rtl8xxxu_write16(priv, reg_sw_ctrl, val16);
3931
3932 return 0;
3933}
3934
3935static int rtl8xxxu_llt_write(struct rtl8xxxu_priv *priv, u8 address, u8 data)
3936{
3937 int ret = -EBUSY;
3938 int count = 0;
3939 u32 value;
3940
3941 value = LLT_OP_WRITE | address << 8 | data;
3942
3943 rtl8xxxu_write32(priv, REG_LLT_INIT, value);
3944
3945 do {
3946 value = rtl8xxxu_read32(priv, REG_LLT_INIT);
3947 if ((value & LLT_OP_MASK) == LLT_OP_INACTIVE) {
3948 ret = 0;
3949 break;
3950 }
3951 } while (count++ < 20);
3952
3953 return ret;
3954}
3955
3956static int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
3957{
3958 int ret;
3959 int i;
3960
3961 for (i = 0; i < last_tx_page; i++) {
3962 ret = rtl8xxxu_llt_write(priv, i, i + 1);
3963 if (ret)
3964 goto exit;
3965 }
3966
3967 ret = rtl8xxxu_llt_write(priv, last_tx_page, 0xff);
3968 if (ret)
3969 goto exit;
3970
3971 /* Mark remaining pages as a ring buffer */
3972 for (i = last_tx_page + 1; i < 0xff; i++) {
3973 ret = rtl8xxxu_llt_write(priv, i, (i + 1));
3974 if (ret)
3975 goto exit;
3976 }
3977
3978 /* Let last entry point to the start entry of ring buffer */
3979 ret = rtl8xxxu_llt_write(priv, 0xff, last_tx_page + 1);
3980 if (ret)
3981 goto exit;
3982
3983exit:
3984 return ret;
3985}
3986
Jes Sorensen74b99be2016-02-29 17:04:04 -05003987static int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
3988{
3989 u32 val32;
3990 int ret = 0;
3991 int i;
3992
3993 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
Jes Sorensen74b99be2016-02-29 17:04:04 -05003994 val32 |= AUTO_LLT_INIT_LLT;
3995 rtl8xxxu_write32(priv, REG_AUTO_LLT, val32);
3996
3997 for (i = 500; i; i--) {
3998 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
3999 if (!(val32 & AUTO_LLT_INIT_LLT))
4000 break;
4001 usleep_range(2, 4);
4002 }
4003
Jes Sorensen4de24812016-02-29 17:04:07 -05004004 if (!i) {
Jes Sorensen74b99be2016-02-29 17:04:04 -05004005 ret = -EBUSY;
4006 dev_warn(&priv->udev->dev, "LLT table init failed\n");
4007 }
Jes Sorensen74b99be2016-02-29 17:04:04 -05004008
4009 return ret;
4010}
4011
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004012static int rtl8xxxu_init_queue_priority(struct rtl8xxxu_priv *priv)
4013{
4014 u16 val16, hi, lo;
4015 u16 hiq, mgq, bkq, beq, viq, voq;
4016 int hip, mgp, bkp, bep, vip, vop;
4017 int ret = 0;
4018
4019 switch (priv->ep_tx_count) {
4020 case 1:
4021 if (priv->ep_tx_high_queue) {
4022 hi = TRXDMA_QUEUE_HIGH;
4023 } else if (priv->ep_tx_low_queue) {
4024 hi = TRXDMA_QUEUE_LOW;
4025 } else if (priv->ep_tx_normal_queue) {
4026 hi = TRXDMA_QUEUE_NORMAL;
4027 } else {
4028 hi = 0;
4029 ret = -EINVAL;
4030 }
4031
4032 hiq = hi;
4033 mgq = hi;
4034 bkq = hi;
4035 beq = hi;
4036 viq = hi;
4037 voq = hi;
4038
4039 hip = 0;
4040 mgp = 0;
4041 bkp = 0;
4042 bep = 0;
4043 vip = 0;
4044 vop = 0;
4045 break;
4046 case 2:
4047 if (priv->ep_tx_high_queue && priv->ep_tx_low_queue) {
4048 hi = TRXDMA_QUEUE_HIGH;
4049 lo = TRXDMA_QUEUE_LOW;
4050 } else if (priv->ep_tx_normal_queue && priv->ep_tx_low_queue) {
4051 hi = TRXDMA_QUEUE_NORMAL;
4052 lo = TRXDMA_QUEUE_LOW;
4053 } else if (priv->ep_tx_high_queue && priv->ep_tx_normal_queue) {
4054 hi = TRXDMA_QUEUE_HIGH;
4055 lo = TRXDMA_QUEUE_NORMAL;
4056 } else {
4057 ret = -EINVAL;
4058 hi = 0;
4059 lo = 0;
4060 }
4061
4062 hiq = hi;
4063 mgq = hi;
4064 bkq = lo;
4065 beq = lo;
4066 viq = hi;
4067 voq = hi;
4068
4069 hip = 0;
4070 mgp = 0;
4071 bkp = 1;
4072 bep = 1;
4073 vip = 0;
4074 vop = 0;
4075 break;
4076 case 3:
4077 beq = TRXDMA_QUEUE_LOW;
4078 bkq = TRXDMA_QUEUE_LOW;
4079 viq = TRXDMA_QUEUE_NORMAL;
4080 voq = TRXDMA_QUEUE_HIGH;
4081 mgq = TRXDMA_QUEUE_HIGH;
4082 hiq = TRXDMA_QUEUE_HIGH;
4083
4084 hip = hiq ^ 3;
4085 mgp = mgq ^ 3;
4086 bkp = bkq ^ 3;
4087 bep = beq ^ 3;
4088 vip = viq ^ 3;
4089 vop = viq ^ 3;
4090 break;
4091 default:
4092 ret = -EINVAL;
4093 }
4094
4095 /*
4096 * None of the vendor drivers are configuring the beacon
4097 * queue here .... why?
4098 */
4099 if (!ret) {
4100 val16 = rtl8xxxu_read16(priv, REG_TRXDMA_CTRL);
4101 val16 &= 0x7;
4102 val16 |= (voq << TRXDMA_CTRL_VOQ_SHIFT) |
4103 (viq << TRXDMA_CTRL_VIQ_SHIFT) |
4104 (beq << TRXDMA_CTRL_BEQ_SHIFT) |
4105 (bkq << TRXDMA_CTRL_BKQ_SHIFT) |
4106 (mgq << TRXDMA_CTRL_MGQ_SHIFT) |
4107 (hiq << TRXDMA_CTRL_HIQ_SHIFT);
4108 rtl8xxxu_write16(priv, REG_TRXDMA_CTRL, val16);
4109
4110 priv->pipe_out[TXDESC_QUEUE_VO] =
4111 usb_sndbulkpipe(priv->udev, priv->out_ep[vop]);
4112 priv->pipe_out[TXDESC_QUEUE_VI] =
4113 usb_sndbulkpipe(priv->udev, priv->out_ep[vip]);
4114 priv->pipe_out[TXDESC_QUEUE_BE] =
4115 usb_sndbulkpipe(priv->udev, priv->out_ep[bep]);
4116 priv->pipe_out[TXDESC_QUEUE_BK] =
4117 usb_sndbulkpipe(priv->udev, priv->out_ep[bkp]);
4118 priv->pipe_out[TXDESC_QUEUE_BEACON] =
4119 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
4120 priv->pipe_out[TXDESC_QUEUE_MGNT] =
4121 usb_sndbulkpipe(priv->udev, priv->out_ep[mgp]);
4122 priv->pipe_out[TXDESC_QUEUE_HIGH] =
4123 usb_sndbulkpipe(priv->udev, priv->out_ep[hip]);
4124 priv->pipe_out[TXDESC_QUEUE_CMD] =
4125 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
4126 }
4127
4128 return ret;
4129}
4130
4131static void rtl8xxxu_fill_iqk_matrix_a(struct rtl8xxxu_priv *priv,
4132 bool iqk_ok, int result[][8],
4133 int candidate, bool tx_only)
4134{
4135 u32 oldval, x, tx0_a, reg;
4136 int y, tx0_c;
4137 u32 val32;
4138
4139 if (!iqk_ok)
4140 return;
4141
4142 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
4143 oldval = val32 >> 22;
4144
4145 x = result[candidate][0];
4146 if ((x & 0x00000200) != 0)
4147 x = x | 0xfffffc00;
4148 tx0_a = (x * oldval) >> 8;
4149
4150 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
4151 val32 &= ~0x3ff;
4152 val32 |= tx0_a;
4153 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
4154
4155 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
4156 val32 &= ~BIT(31);
4157 if ((x * oldval >> 7) & 0x1)
4158 val32 |= BIT(31);
4159 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
4160
4161 y = result[candidate][1];
4162 if ((y & 0x00000200) != 0)
4163 y = y | 0xfffffc00;
4164 tx0_c = (y * oldval) >> 8;
4165
4166 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XC_TX_AFE);
4167 val32 &= ~0xf0000000;
4168 val32 |= (((tx0_c & 0x3c0) >> 6) << 28);
4169 rtl8xxxu_write32(priv, REG_OFDM0_XC_TX_AFE, val32);
4170
4171 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
4172 val32 &= ~0x003f0000;
4173 val32 |= ((tx0_c & 0x3f) << 16);
4174 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
4175
4176 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
4177 val32 &= ~BIT(29);
4178 if ((y * oldval >> 7) & 0x1)
4179 val32 |= BIT(29);
4180 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
4181
4182 if (tx_only) {
4183 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
4184 return;
4185 }
4186
4187 reg = result[candidate][2];
4188
4189 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
4190 val32 &= ~0x3ff;
4191 val32 |= (reg & 0x3ff);
4192 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
4193
4194 reg = result[candidate][3] & 0x3F;
4195
4196 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
4197 val32 &= ~0xfc00;
4198 val32 |= ((reg << 10) & 0xfc00);
4199 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
4200
4201 reg = (result[candidate][3] >> 6) & 0xF;
4202
4203 val32 = rtl8xxxu_read32(priv, REG_OFDM0_RX_IQ_EXT_ANTA);
4204 val32 &= ~0xf0000000;
4205 val32 |= (reg << 28);
4206 rtl8xxxu_write32(priv, REG_OFDM0_RX_IQ_EXT_ANTA, val32);
4207}
4208
4209static void rtl8xxxu_fill_iqk_matrix_b(struct rtl8xxxu_priv *priv,
4210 bool iqk_ok, int result[][8],
4211 int candidate, bool tx_only)
4212{
4213 u32 oldval, x, tx1_a, reg;
4214 int y, tx1_c;
4215 u32 val32;
4216
4217 if (!iqk_ok)
4218 return;
4219
4220 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
4221 oldval = val32 >> 22;
4222
4223 x = result[candidate][4];
4224 if ((x & 0x00000200) != 0)
4225 x = x | 0xfffffc00;
4226 tx1_a = (x * oldval) >> 8;
4227
4228 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
4229 val32 &= ~0x3ff;
4230 val32 |= tx1_a;
4231 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
4232
4233 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
4234 val32 &= ~BIT(27);
4235 if ((x * oldval >> 7) & 0x1)
4236 val32 |= BIT(27);
4237 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
4238
4239 y = result[candidate][5];
4240 if ((y & 0x00000200) != 0)
4241 y = y | 0xfffffc00;
4242 tx1_c = (y * oldval) >> 8;
4243
4244 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XD_TX_AFE);
4245 val32 &= ~0xf0000000;
4246 val32 |= (((tx1_c & 0x3c0) >> 6) << 28);
4247 rtl8xxxu_write32(priv, REG_OFDM0_XD_TX_AFE, val32);
4248
4249 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
4250 val32 &= ~0x003f0000;
4251 val32 |= ((tx1_c & 0x3f) << 16);
4252 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
4253
4254 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
4255 val32 &= ~BIT(25);
4256 if ((y * oldval >> 7) & 0x1)
4257 val32 |= BIT(25);
4258 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
4259
4260 if (tx_only) {
4261 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
4262 return;
4263 }
4264
4265 reg = result[candidate][6];
4266
4267 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
4268 val32 &= ~0x3ff;
4269 val32 |= (reg & 0x3ff);
4270 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
4271
4272 reg = result[candidate][7] & 0x3f;
4273
4274 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
4275 val32 &= ~0xfc00;
4276 val32 |= ((reg << 10) & 0xfc00);
4277 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
4278
4279 reg = (result[candidate][7] >> 6) & 0xf;
4280
4281 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGCR_SSI_TABLE);
4282 val32 &= ~0x0000f000;
4283 val32 |= (reg << 12);
4284 rtl8xxxu_write32(priv, REG_OFDM0_AGCR_SSI_TABLE, val32);
4285}
4286
4287#define MAX_TOLERANCE 5
4288
4289static bool rtl8xxxu_simularity_compare(struct rtl8xxxu_priv *priv,
4290 int result[][8], int c1, int c2)
4291{
4292 u32 i, j, diff, simubitmap, bound = 0;
4293 int candidate[2] = {-1, -1}; /* for path A and path B */
4294 bool retval = true;
4295
4296 if (priv->tx_paths > 1)
4297 bound = 8;
4298 else
4299 bound = 4;
4300
4301 simubitmap = 0;
4302
4303 for (i = 0; i < bound; i++) {
4304 diff = (result[c1][i] > result[c2][i]) ?
4305 (result[c1][i] - result[c2][i]) :
4306 (result[c2][i] - result[c1][i]);
4307 if (diff > MAX_TOLERANCE) {
4308 if ((i == 2 || i == 6) && !simubitmap) {
4309 if (result[c1][i] + result[c1][i + 1] == 0)
4310 candidate[(i / 4)] = c2;
4311 else if (result[c2][i] + result[c2][i + 1] == 0)
4312 candidate[(i / 4)] = c1;
4313 else
4314 simubitmap = simubitmap | (1 << i);
4315 } else {
4316 simubitmap = simubitmap | (1 << i);
4317 }
4318 }
4319 }
4320
4321 if (simubitmap == 0) {
4322 for (i = 0; i < (bound / 4); i++) {
4323 if (candidate[i] >= 0) {
4324 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
4325 result[3][j] = result[candidate[i]][j];
4326 retval = false;
4327 }
4328 }
4329 return retval;
4330 } else if (!(simubitmap & 0x0f)) {
4331 /* path A OK */
4332 for (i = 0; i < 4; i++)
4333 result[3][i] = result[c1][i];
4334 } else if (!(simubitmap & 0xf0) && priv->tx_paths > 1) {
4335 /* path B OK */
4336 for (i = 4; i < 8; i++)
4337 result[3][i] = result[c1][i];
4338 }
4339
4340 return false;
4341}
4342
Jes Sorensene1547c52016-02-29 17:04:35 -05004343static bool rtl8723bu_simularity_compare(struct rtl8xxxu_priv *priv,
4344 int result[][8], int c1, int c2)
4345{
4346 u32 i, j, diff, simubitmap, bound = 0;
4347 int candidate[2] = {-1, -1}; /* for path A and path B */
4348 int tmp1, tmp2;
4349 bool retval = true;
4350
4351 if (priv->tx_paths > 1)
4352 bound = 8;
4353 else
4354 bound = 4;
4355
4356 simubitmap = 0;
4357
4358 for (i = 0; i < bound; i++) {
4359 if (i & 1) {
4360 if ((result[c1][i] & 0x00000200))
4361 tmp1 = result[c1][i] | 0xfffffc00;
4362 else
4363 tmp1 = result[c1][i];
4364
4365 if ((result[c2][i]& 0x00000200))
4366 tmp2 = result[c2][i] | 0xfffffc00;
4367 else
4368 tmp2 = result[c2][i];
4369 } else {
4370 tmp1 = result[c1][i];
4371 tmp2 = result[c2][i];
4372 }
4373
4374 diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1);
4375
4376 if (diff > MAX_TOLERANCE) {
4377 if ((i == 2 || i == 6) && !simubitmap) {
4378 if (result[c1][i] + result[c1][i + 1] == 0)
4379 candidate[(i / 4)] = c2;
4380 else if (result[c2][i] + result[c2][i + 1] == 0)
4381 candidate[(i / 4)] = c1;
4382 else
4383 simubitmap = simubitmap | (1 << i);
4384 } else {
4385 simubitmap = simubitmap | (1 << i);
4386 }
4387 }
4388 }
4389
4390 if (simubitmap == 0) {
4391 for (i = 0; i < (bound / 4); i++) {
4392 if (candidate[i] >= 0) {
4393 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
4394 result[3][j] = result[candidate[i]][j];
4395 retval = false;
4396 }
4397 }
4398 return retval;
4399 } else {
4400 if (!(simubitmap & 0x03)) {
4401 /* path A TX OK */
4402 for (i = 0; i < 2; i++)
4403 result[3][i] = result[c1][i];
4404 }
4405
4406 if (!(simubitmap & 0x0c)) {
4407 /* path A RX OK */
4408 for (i = 2; i < 4; i++)
4409 result[3][i] = result[c1][i];
4410 }
4411
4412 if (!(simubitmap & 0x30) && priv->tx_paths > 1) {
4413 /* path B RX OK */
4414 for (i = 4; i < 6; i++)
4415 result[3][i] = result[c1][i];
4416 }
4417
4418 if (!(simubitmap & 0x30) && priv->tx_paths > 1) {
4419 /* path B RX OK */
4420 for (i = 6; i < 8; i++)
4421 result[3][i] = result[c1][i];
4422 }
4423 }
4424
4425 return false;
4426}
4427
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004428static void
4429rtl8xxxu_save_mac_regs(struct rtl8xxxu_priv *priv, const u32 *reg, u32 *backup)
4430{
4431 int i;
4432
4433 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
4434 backup[i] = rtl8xxxu_read8(priv, reg[i]);
4435
4436 backup[i] = rtl8xxxu_read32(priv, reg[i]);
4437}
4438
4439static void rtl8xxxu_restore_mac_regs(struct rtl8xxxu_priv *priv,
4440 const u32 *reg, u32 *backup)
4441{
4442 int i;
4443
4444 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
4445 rtl8xxxu_write8(priv, reg[i], backup[i]);
4446
4447 rtl8xxxu_write32(priv, reg[i], backup[i]);
4448}
4449
4450static void rtl8xxxu_save_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
4451 u32 *backup, int count)
4452{
4453 int i;
4454
4455 for (i = 0; i < count; i++)
4456 backup[i] = rtl8xxxu_read32(priv, regs[i]);
4457}
4458
4459static void rtl8xxxu_restore_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
4460 u32 *backup, int count)
4461{
4462 int i;
4463
4464 for (i = 0; i < count; i++)
4465 rtl8xxxu_write32(priv, regs[i], backup[i]);
4466}
4467
4468
4469static void rtl8xxxu_path_adda_on(struct rtl8xxxu_priv *priv, const u32 *regs,
4470 bool path_a_on)
4471{
4472 u32 path_on;
4473 int i;
4474
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004475 if (priv->tx_paths == 1) {
Jes Sorensen8634af52016-02-29 17:04:33 -05004476 path_on = priv->fops->adda_1t_path_on;
4477 rtl8xxxu_write32(priv, regs[0], priv->fops->adda_1t_init);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004478 } else {
Jes Sorensen8634af52016-02-29 17:04:33 -05004479 path_on = path_a_on ? priv->fops->adda_2t_path_on_a :
4480 priv->fops->adda_2t_path_on_b;
4481
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004482 rtl8xxxu_write32(priv, regs[0], path_on);
4483 }
4484
4485 for (i = 1 ; i < RTL8XXXU_ADDA_REGS ; i++)
4486 rtl8xxxu_write32(priv, regs[i], path_on);
4487}
4488
4489static void rtl8xxxu_mac_calibration(struct rtl8xxxu_priv *priv,
4490 const u32 *regs, u32 *backup)
4491{
4492 int i = 0;
4493
4494 rtl8xxxu_write8(priv, regs[i], 0x3f);
4495
4496 for (i = 1 ; i < (RTL8XXXU_MAC_REGS - 1); i++)
4497 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(3)));
4498
4499 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(5)));
4500}
4501
4502static int rtl8xxxu_iqk_path_a(struct rtl8xxxu_priv *priv)
4503{
4504 u32 reg_eac, reg_e94, reg_e9c, reg_ea4, val32;
4505 int result = 0;
4506
4507 /* path-A IQK setting */
4508 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1f);
4509 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x10008c1f);
4510 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82140102);
4511
4512 val32 = (priv->rf_paths > 1) ? 0x28160202 :
4513 /*IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)?0x28160202: */
4514 0x28160502;
4515 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, val32);
4516
4517 /* path-B IQK setting */
4518 if (priv->rf_paths > 1) {
4519 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x10008c22);
4520 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x10008c22);
4521 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82140102);
4522 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28160202);
4523 }
4524
4525 /* LO calibration setting */
4526 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x001028d1);
4527
4528 /* One shot, path A LOK & IQK */
4529 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4530 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4531
4532 mdelay(1);
4533
4534 /* Check failed */
4535 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4536 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
4537 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
4538 reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
4539
4540 if (!(reg_eac & BIT(28)) &&
4541 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
4542 ((reg_e9c & 0x03ff0000) != 0x00420000))
4543 result |= 0x01;
4544 else /* If TX not OK, ignore RX */
4545 goto out;
4546
4547 /* If TX is OK, check whether RX is OK */
4548 if (!(reg_eac & BIT(27)) &&
4549 ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
4550 ((reg_eac & 0x03ff0000) != 0x00360000))
4551 result |= 0x02;
4552 else
4553 dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n",
4554 __func__);
4555out:
4556 return result;
4557}
4558
4559static int rtl8xxxu_iqk_path_b(struct rtl8xxxu_priv *priv)
4560{
4561 u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
4562 int result = 0;
4563
4564 /* One shot, path B LOK & IQK */
4565 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
4566 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
4567
4568 mdelay(1);
4569
4570 /* Check failed */
4571 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4572 reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4573 reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4574 reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
4575 reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
4576
4577 if (!(reg_eac & BIT(31)) &&
4578 ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
4579 ((reg_ebc & 0x03ff0000) != 0x00420000))
4580 result |= 0x01;
4581 else
4582 goto out;
4583
4584 if (!(reg_eac & BIT(30)) &&
4585 (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) &&
4586 (((reg_ecc & 0x03ff0000) >> 16) != 0x36))
4587 result |= 0x02;
4588 else
4589 dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
4590 __func__);
4591out:
4592 return result;
4593}
4594
Jes Sorensene1547c52016-02-29 17:04:35 -05004595static int rtl8723bu_iqk_path_a(struct rtl8xxxu_priv *priv)
4596{
4597 u32 reg_eac, reg_e94, reg_e9c, path_sel, val32;
4598 int result = 0;
4599
4600 path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH);
4601
4602 /*
4603 * Leave IQK mode
4604 */
4605 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4606 val32 &= 0x000000ff;
4607 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4608
4609 /*
4610 * Enable path A PA in TX IQK mode
4611 */
4612 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4613 val32 |= 0x80000;
4614 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4615 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x20000);
4616 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0003f);
4617 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xc7f87);
4618
4619 /*
4620 * Tx IQK setting
4621 */
4622 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
4623 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4624
4625 /* path-A IQK setting */
4626 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c);
4627 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c);
4628 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c);
4629 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c);
4630
4631 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x821403ea);
4632 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000);
4633 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000);
4634 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000);
4635
4636 /* LO calibration setting */
4637 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x00462911);
4638
4639 /*
4640 * Enter IQK mode
4641 */
4642 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4643 val32 &= 0x000000ff;
4644 val32 |= 0x80800000;
4645 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4646
4647 /*
4648 * The vendor driver indicates the USB module is always using
4649 * S0S1 path 1 for the 8723bu. This may be different for 8192eu
4650 */
4651 if (priv->rf_paths > 1)
4652 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000);
4653 else
4654 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280);
4655
4656 /*
4657 * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu.
4658 * No trace of this in the 8192eu or 8188eu vendor drivers.
4659 */
4660 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800);
4661
4662 /* One shot, path A LOK & IQK */
4663 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4664 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4665
4666 mdelay(1);
4667
4668 /* Restore Ant Path */
4669 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel);
4670#ifdef RTL8723BU_BT
4671 /* GNT_BT = 1 */
4672 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800);
4673#endif
4674
4675 /*
4676 * Leave IQK mode
4677 */
4678 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4679 val32 &= 0x000000ff;
4680 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4681
4682 /* Check failed */
4683 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4684 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
4685 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
4686
4687 val32 = (reg_e9c >> 16) & 0x3ff;
4688 if (val32 & 0x200)
4689 val32 = 0x400 - val32;
4690
4691 if (!(reg_eac & BIT(28)) &&
4692 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
4693 ((reg_e9c & 0x03ff0000) != 0x00420000) &&
4694 ((reg_e94 & 0x03ff0000) < 0x01100000) &&
4695 ((reg_e94 & 0x03ff0000) > 0x00f00000) &&
4696 val32 < 0xf)
4697 result |= 0x01;
4698 else /* If TX not OK, ignore RX */
4699 goto out;
4700
4701out:
4702 return result;
4703}
4704
4705static int rtl8723bu_rx_iqk_path_a(struct rtl8xxxu_priv *priv)
4706{
4707 u32 reg_ea4, reg_eac, reg_e94, reg_e9c, path_sel, val32;
4708 int result = 0;
4709
4710 path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH);
4711
4712 /*
4713 * Leave IQK mode
4714 */
4715 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4716 val32 &= 0x000000ff;
4717 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4718
4719 /*
4720 * Enable path A PA in TX IQK mode
4721 */
4722 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4723 val32 |= 0x80000;
4724 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4725 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
4726 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
4727 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7);
4728
4729 /*
4730 * Tx IQK setting
4731 */
4732 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
4733 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4734
4735 /* path-A IQK setting */
4736 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c);
4737 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c);
4738 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c);
4739 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c);
4740
4741 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82160ff0);
4742 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000);
4743 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000);
4744 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000);
4745
4746 /* LO calibration setting */
4747 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a911);
4748
4749 /*
4750 * Enter IQK mode
4751 */
4752 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4753 val32 &= 0x000000ff;
4754 val32 |= 0x80800000;
4755 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4756
4757 /*
4758 * The vendor driver indicates the USB module is always using
4759 * S0S1 path 1 for the 8723bu. This may be different for 8192eu
4760 */
4761 if (priv->rf_paths > 1)
4762 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000);
4763 else
4764 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280);
4765
4766 /*
4767 * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu.
4768 * No trace of this in the 8192eu or 8188eu vendor drivers.
4769 */
4770 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800);
4771
4772 /* One shot, path A LOK & IQK */
4773 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4774 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4775
4776 mdelay(1);
4777
4778 /* Restore Ant Path */
4779 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel);
4780#ifdef RTL8723BU_BT
4781 /* GNT_BT = 1 */
4782 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800);
4783#endif
4784
4785 /*
4786 * Leave IQK mode
4787 */
4788 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4789 val32 &= 0x000000ff;
4790 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4791
4792 /* Check failed */
4793 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4794 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
4795 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
4796
4797 val32 = (reg_e9c >> 16) & 0x3ff;
4798 if (val32 & 0x200)
4799 val32 = 0x400 - val32;
4800
4801 if (!(reg_eac & BIT(28)) &&
4802 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
4803 ((reg_e9c & 0x03ff0000) != 0x00420000) &&
4804 ((reg_e94 & 0x03ff0000) < 0x01100000) &&
4805 ((reg_e94 & 0x03ff0000) > 0x00f00000) &&
4806 val32 < 0xf)
4807 result |= 0x01;
4808 else /* If TX not OK, ignore RX */
4809 goto out;
4810
4811 val32 = 0x80007c00 | (reg_e94 &0x3ff0000) |
4812 ((reg_e9c & 0x3ff0000) >> 16);
4813 rtl8xxxu_write32(priv, REG_TX_IQK, val32);
4814
4815 /*
4816 * Modify RX IQK mode
4817 */
4818 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4819 val32 &= 0x000000ff;
4820 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4821 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4822 val32 |= 0x80000;
4823 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4824 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
4825 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
4826 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7d77);
4827
4828 /*
4829 * PA, PAD setting
4830 */
4831 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0xf80);
4832 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_55, 0x4021f);
4833
4834 /*
4835 * RX IQK setting
4836 */
4837 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4838
4839 /* path-A IQK setting */
4840 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x38008c1c);
4841 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x18008c1c);
4842 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c);
4843 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c);
4844
4845 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82110000);
4846 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x2816001f);
4847 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000);
4848 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000);
4849
4850 /* LO calibration setting */
4851 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a8d1);
4852
4853 /*
4854 * Enter IQK mode
4855 */
4856 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4857 val32 &= 0x000000ff;
4858 val32 |= 0x80800000;
4859 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4860
4861 if (priv->rf_paths > 1)
4862 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000);
4863 else
4864 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280);
4865
4866 /*
4867 * Disable BT
4868 */
4869 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800);
4870
4871 /* One shot, path A LOK & IQK */
4872 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4873 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4874
4875 mdelay(1);
4876
4877 /* Restore Ant Path */
4878 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel);
4879#ifdef RTL8723BU_BT
4880 /* GNT_BT = 1 */
4881 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800);
4882#endif
4883
4884 /*
4885 * Leave IQK mode
4886 */
4887 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4888 val32 &= 0x000000ff;
4889 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4890
4891 /* Check failed */
4892 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4893 reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
4894
4895 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x780);
4896
4897 val32 = (reg_eac >> 16) & 0x3ff;
4898 if (val32 & 0x200)
4899 val32 = 0x400 - val32;
4900
4901 if (!(reg_eac & BIT(27)) &&
4902 ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
4903 ((reg_eac & 0x03ff0000) != 0x00360000) &&
4904 ((reg_ea4 & 0x03ff0000) < 0x01100000) &&
4905 ((reg_ea4 & 0x03ff0000) > 0x00f00000) &&
4906 val32 < 0xf)
4907 result |= 0x02;
4908 else /* If TX not OK, ignore RX */
4909 goto out;
4910out:
4911 return result;
4912}
4913
4914#ifdef RTL8723BU_PATH_B
4915static int rtl8723bu_iqk_path_b(struct rtl8xxxu_priv *priv)
4916{
4917 u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc, path_sel;
4918 int result = 0;
4919
4920 path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH);
4921
4922 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4923 val32 &= 0x000000ff;
4924 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4925
4926 /* One shot, path B LOK & IQK */
4927 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
4928 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
4929
4930 mdelay(1);
4931
4932 /* Check failed */
4933 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4934 reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4935 reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4936 reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
4937 reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
4938
4939 if (!(reg_eac & BIT(31)) &&
4940 ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
4941 ((reg_ebc & 0x03ff0000) != 0x00420000))
4942 result |= 0x01;
4943 else
4944 goto out;
4945
4946 if (!(reg_eac & BIT(30)) &&
4947 (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) &&
4948 (((reg_ecc & 0x03ff0000) >> 16) != 0x36))
4949 result |= 0x02;
4950 else
4951 dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
4952 __func__);
4953out:
4954 return result;
4955}
4956#endif
4957
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004958static void rtl8xxxu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
4959 int result[][8], int t)
4960{
4961 struct device *dev = &priv->udev->dev;
4962 u32 i, val32;
4963 int path_a_ok, path_b_ok;
4964 int retry = 2;
4965 const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
4966 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
4967 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
4968 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
4969 REG_TX_OFDM_BBON, REG_TX_TO_RX,
4970 REG_TX_TO_TX, REG_RX_CCK,
4971 REG_RX_OFDM, REG_RX_WAIT_RIFS,
4972 REG_RX_TO_RX, REG_STANDBY,
4973 REG_SLEEP, REG_PMPD_ANAEN
4974 };
4975 const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
4976 REG_TXPAUSE, REG_BEACON_CTRL,
4977 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
4978 };
4979 const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
4980 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
4981 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
4982 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
4983 REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
4984 };
4985
4986 /*
4987 * Note: IQ calibration must be performed after loading
4988 * PHY_REG.txt , and radio_a, radio_b.txt
4989 */
4990
4991 if (t == 0) {
4992 /* Save ADDA parameters, turn Path A ADDA on */
4993 rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
4994 RTL8XXXU_ADDA_REGS);
4995 rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
4996 rtl8xxxu_save_regs(priv, iqk_bb_regs,
4997 priv->bb_backup, RTL8XXXU_BB_REGS);
4998 }
4999
5000 rtl8xxxu_path_adda_on(priv, adda_regs, true);
5001
5002 if (t == 0) {
5003 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1);
5004 if (val32 & FPGA0_HSSI_PARM1_PI)
5005 priv->pi_enabled = 1;
5006 }
5007
5008 if (!priv->pi_enabled) {
5009 /* Switch BB to PI mode to do IQ Calibration. */
5010 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0x01000100);
5011 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0x01000100);
5012 }
5013
5014 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
5015 val32 &= ~FPGA_RF_MODE_CCK;
5016 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
5017
5018 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
5019 rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
5020 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
5021
5022 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
5023 val32 |= (FPGA0_RF_PAPE | (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
5024 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
5025
5026 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
5027 val32 &= ~BIT(10);
5028 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
5029 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
5030 val32 &= ~BIT(10);
5031 rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
5032
5033 if (priv->tx_paths > 1) {
5034 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
5035 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, 0x00010000);
5036 }
5037
5038 /* MAC settings */
5039 rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
5040
5041 /* Page B init */
5042 rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x00080000);
5043
5044 if (priv->tx_paths > 1)
5045 rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x00080000);
5046
5047 /* IQ calibration setting */
5048 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
5049 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
5050 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
5051
5052 for (i = 0; i < retry; i++) {
5053 path_a_ok = rtl8xxxu_iqk_path_a(priv);
5054 if (path_a_ok == 0x03) {
5055 val32 = rtl8xxxu_read32(priv,
5056 REG_TX_POWER_BEFORE_IQK_A);
5057 result[t][0] = (val32 >> 16) & 0x3ff;
5058 val32 = rtl8xxxu_read32(priv,
5059 REG_TX_POWER_AFTER_IQK_A);
5060 result[t][1] = (val32 >> 16) & 0x3ff;
5061 val32 = rtl8xxxu_read32(priv,
5062 REG_RX_POWER_BEFORE_IQK_A_2);
5063 result[t][2] = (val32 >> 16) & 0x3ff;
5064 val32 = rtl8xxxu_read32(priv,
5065 REG_RX_POWER_AFTER_IQK_A_2);
5066 result[t][3] = (val32 >> 16) & 0x3ff;
5067 break;
5068 } else if (i == (retry - 1) && path_a_ok == 0x01) {
5069 /* TX IQK OK */
5070 dev_dbg(dev, "%s: Path A IQK Only Tx Success!!\n",
5071 __func__);
5072
5073 val32 = rtl8xxxu_read32(priv,
5074 REG_TX_POWER_BEFORE_IQK_A);
5075 result[t][0] = (val32 >> 16) & 0x3ff;
5076 val32 = rtl8xxxu_read32(priv,
5077 REG_TX_POWER_AFTER_IQK_A);
5078 result[t][1] = (val32 >> 16) & 0x3ff;
5079 }
5080 }
5081
5082 if (!path_a_ok)
5083 dev_dbg(dev, "%s: Path A IQK failed!\n", __func__);
5084
5085 if (priv->tx_paths > 1) {
5086 /*
5087 * Path A into standby
5088 */
5089 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x0);
5090 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
5091 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
5092
5093 /* Turn Path B ADDA on */
5094 rtl8xxxu_path_adda_on(priv, adda_regs, false);
5095
5096 for (i = 0; i < retry; i++) {
5097 path_b_ok = rtl8xxxu_iqk_path_b(priv);
5098 if (path_b_ok == 0x03) {
5099 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
5100 result[t][4] = (val32 >> 16) & 0x3ff;
5101 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
5102 result[t][5] = (val32 >> 16) & 0x3ff;
5103 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
5104 result[t][6] = (val32 >> 16) & 0x3ff;
5105 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
5106 result[t][7] = (val32 >> 16) & 0x3ff;
5107 break;
5108 } else if (i == (retry - 1) && path_b_ok == 0x01) {
5109 /* TX IQK OK */
5110 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
5111 result[t][4] = (val32 >> 16) & 0x3ff;
5112 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
5113 result[t][5] = (val32 >> 16) & 0x3ff;
5114 }
5115 }
5116
5117 if (!path_b_ok)
5118 dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
5119 }
5120
5121 /* Back to BB mode, load original value */
5122 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0);
5123
5124 if (t) {
5125 if (!priv->pi_enabled) {
5126 /*
5127 * Switch back BB to SI mode after finishing
5128 * IQ Calibration
5129 */
5130 val32 = 0x01000000;
5131 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, val32);
5132 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, val32);
5133 }
5134
5135 /* Reload ADDA power saving parameters */
5136 rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
5137 RTL8XXXU_ADDA_REGS);
5138
5139 /* Reload MAC parameters */
5140 rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
5141
5142 /* Reload BB parameters */
5143 rtl8xxxu_restore_regs(priv, iqk_bb_regs,
5144 priv->bb_backup, RTL8XXXU_BB_REGS);
5145
5146 /* Restore RX initial gain */
5147 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00032ed3);
5148
5149 if (priv->tx_paths > 1) {
5150 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM,
5151 0x00032ed3);
5152 }
5153
5154 /* Load 0xe30 IQC default value */
5155 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
5156 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
5157 }
5158}
5159
Jes Sorensene1547c52016-02-29 17:04:35 -05005160static void rtl8723bu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
5161 int result[][8], int t)
5162{
5163 struct device *dev = &priv->udev->dev;
5164 u32 i, val32;
5165 int path_a_ok /*, path_b_ok */;
5166 int retry = 2;
5167 const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
5168 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
5169 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
5170 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
5171 REG_TX_OFDM_BBON, REG_TX_TO_RX,
5172 REG_TX_TO_TX, REG_RX_CCK,
5173 REG_RX_OFDM, REG_RX_WAIT_RIFS,
5174 REG_RX_TO_RX, REG_STANDBY,
5175 REG_SLEEP, REG_PMPD_ANAEN
5176 };
5177 const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
5178 REG_TXPAUSE, REG_BEACON_CTRL,
5179 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
5180 };
5181 const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
5182 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
5183 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
5184 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
5185 REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
5186 };
5187 u8 xa_agc = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1) & 0xff;
5188 u8 xb_agc = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1) & 0xff;
5189
5190 /*
5191 * Note: IQ calibration must be performed after loading
5192 * PHY_REG.txt , and radio_a, radio_b.txt
5193 */
5194
5195 if (t == 0) {
5196 /* Save ADDA parameters, turn Path A ADDA on */
5197 rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
5198 RTL8XXXU_ADDA_REGS);
5199 rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
5200 rtl8xxxu_save_regs(priv, iqk_bb_regs,
5201 priv->bb_backup, RTL8XXXU_BB_REGS);
5202 }
5203
5204 rtl8xxxu_path_adda_on(priv, adda_regs, true);
5205
5206 /* MAC settings */
5207 rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
5208
5209 val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
5210 val32 |= 0x0f000000;
5211 rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
5212
5213 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
5214 rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
5215 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
5216
5217#ifdef RTL8723BU_PATH_B
5218 /* Set RF mode to standby Path B */
5219 if (priv->tx_paths > 1)
5220 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x10000);
5221#endif
5222
5223#if 0
5224 /* Page B init */
5225 rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x0f600000);
5226
5227 if (priv->tx_paths > 1)
5228 rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x0f600000);
5229#endif
5230
5231 /*
5232 * RX IQ calibration setting for 8723B D cut large current issue
5233 * when leaving IPS
5234 */
5235 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
5236 val32 &= 0x000000ff;
5237 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
5238
5239 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
5240 val32 |= 0x80000;
5241 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
5242
5243 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
5244 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
5245 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7);
5246
5247 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED);
5248 val32 |= 0x20;
5249 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32);
5250
5251 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_43, 0x60fbd);
5252
5253 for (i = 0; i < retry; i++) {
5254 path_a_ok = rtl8723bu_iqk_path_a(priv);
5255 if (path_a_ok == 0x01) {
5256 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
5257 val32 &= 0x000000ff;
5258 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
5259
5260#if 0 /* Only needed in restore case, we may need this when going to suspend */
5261 priv->RFCalibrateInfo.TxLOK[RF_A] =
5262 rtl8xxxu_read_rfreg(priv, RF_A,
5263 RF6052_REG_TXM_IDAC);
5264#endif
5265
5266 val32 = rtl8xxxu_read32(priv,
5267 REG_TX_POWER_BEFORE_IQK_A);
5268 result[t][0] = (val32 >> 16) & 0x3ff;
5269 val32 = rtl8xxxu_read32(priv,
5270 REG_TX_POWER_AFTER_IQK_A);
5271 result[t][1] = (val32 >> 16) & 0x3ff;
5272
5273 break;
5274 }
5275 }
5276
5277 if (!path_a_ok)
5278 dev_dbg(dev, "%s: Path A TX IQK failed!\n", __func__);
5279
5280 for (i = 0; i < retry; i++) {
5281 path_a_ok = rtl8723bu_rx_iqk_path_a(priv);
5282 if (path_a_ok == 0x03) {
5283 val32 = rtl8xxxu_read32(priv,
5284 REG_RX_POWER_BEFORE_IQK_A_2);
5285 result[t][2] = (val32 >> 16) & 0x3ff;
5286 val32 = rtl8xxxu_read32(priv,
5287 REG_RX_POWER_AFTER_IQK_A_2);
5288 result[t][3] = (val32 >> 16) & 0x3ff;
5289
5290 break;
5291 }
5292 }
5293
5294 if (!path_a_ok)
5295 dev_dbg(dev, "%s: Path A RX IQK failed!\n", __func__);
5296
5297 if (priv->tx_paths > 1) {
5298#if 1
5299 dev_warn(dev, "%s: Path B not supported\n", __func__);
5300#else
5301
5302 /*
5303 * Path A into standby
5304 */
5305 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
5306 val32 &= 0x000000ff;
5307 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
5308 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x10000);
5309
5310 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
5311 val32 &= 0x000000ff;
5312 val32 |= 0x80800000;
5313 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
5314
5315 /* Turn Path B ADDA on */
5316 rtl8xxxu_path_adda_on(priv, adda_regs, false);
5317
5318 for (i = 0; i < retry; i++) {
5319 path_b_ok = rtl8xxxu_iqk_path_b(priv);
5320 if (path_b_ok == 0x03) {
5321 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
5322 result[t][4] = (val32 >> 16) & 0x3ff;
5323 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
5324 result[t][5] = (val32 >> 16) & 0x3ff;
5325 break;
5326 }
5327 }
5328
5329 if (!path_b_ok)
5330 dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
5331
5332 for (i = 0; i < retry; i++) {
5333 path_b_ok = rtl8723bu_rx_iqk_path_b(priv);
5334 if (path_a_ok == 0x03) {
5335 val32 = rtl8xxxu_read32(priv,
5336 REG_RX_POWER_BEFORE_IQK_B_2);
5337 result[t][6] = (val32 >> 16) & 0x3ff;
5338 val32 = rtl8xxxu_read32(priv,
5339 REG_RX_POWER_AFTER_IQK_B_2);
5340 result[t][7] = (val32 >> 16) & 0x3ff;
5341 break;
5342 }
5343 }
5344
5345 if (!path_b_ok)
5346 dev_dbg(dev, "%s: Path B RX IQK failed!\n", __func__);
5347#endif
5348 }
5349
5350 /* Back to BB mode, load original value */
5351 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
5352 val32 &= 0x000000ff;
5353 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
5354
5355 if (t) {
5356 /* Reload ADDA power saving parameters */
5357 rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
5358 RTL8XXXU_ADDA_REGS);
5359
5360 /* Reload MAC parameters */
5361 rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
5362
5363 /* Reload BB parameters */
5364 rtl8xxxu_restore_regs(priv, iqk_bb_regs,
5365 priv->bb_backup, RTL8XXXU_BB_REGS);
5366
5367 /* Restore RX initial gain */
5368 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1);
5369 val32 &= 0xffffff00;
5370 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | 0x50);
5371 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | xa_agc);
5372
5373 if (priv->tx_paths > 1) {
5374 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1);
5375 val32 &= 0xffffff00;
5376 rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1,
5377 val32 | 0x50);
5378 rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1,
5379 val32 | xb_agc);
5380 }
5381
5382 /* Load 0xe30 IQC default value */
5383 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
5384 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
5385 }
5386}
5387
Jes Sorensenc7a5a192016-02-29 17:04:30 -05005388static void rtl8xxxu_prepare_calibrate(struct rtl8xxxu_priv *priv, u8 start)
5389{
5390 struct h2c_cmd h2c;
5391
5392 if (priv->fops->mbox_ext_width < 4)
5393 return;
5394
5395 memset(&h2c, 0, sizeof(struct h2c_cmd));
5396 h2c.bt_wlan_calibration.cmd = H2C_8723B_BT_WLAN_CALIBRATION;
5397 h2c.bt_wlan_calibration.data = start;
5398
5399 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_wlan_calibration));
5400}
5401
Jes Sorensene1547c52016-02-29 17:04:35 -05005402static void rtl8723au_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005403{
5404 struct device *dev = &priv->udev->dev;
5405 int result[4][8]; /* last is final result */
5406 int i, candidate;
5407 bool path_a_ok, path_b_ok;
5408 u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
5409 u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
5410 s32 reg_tmp = 0;
5411 bool simu;
5412
Jes Sorensenc7a5a192016-02-29 17:04:30 -05005413 rtl8xxxu_prepare_calibrate(priv, 1);
5414
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005415 memset(result, 0, sizeof(result));
5416 candidate = -1;
5417
5418 path_a_ok = false;
5419 path_b_ok = false;
5420
5421 rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
5422
5423 for (i = 0; i < 3; i++) {
5424 rtl8xxxu_phy_iqcalibrate(priv, result, i);
5425
5426 if (i == 1) {
5427 simu = rtl8xxxu_simularity_compare(priv, result, 0, 1);
5428 if (simu) {
5429 candidate = 0;
5430 break;
5431 }
5432 }
5433
5434 if (i == 2) {
5435 simu = rtl8xxxu_simularity_compare(priv, result, 0, 2);
5436 if (simu) {
5437 candidate = 0;
5438 break;
5439 }
5440
5441 simu = rtl8xxxu_simularity_compare(priv, result, 1, 2);
5442 if (simu) {
5443 candidate = 1;
5444 } else {
5445 for (i = 0; i < 8; i++)
5446 reg_tmp += result[3][i];
5447
5448 if (reg_tmp)
5449 candidate = 3;
5450 else
5451 candidate = -1;
5452 }
5453 }
5454 }
5455
5456 for (i = 0; i < 4; i++) {
5457 reg_e94 = result[i][0];
5458 reg_e9c = result[i][1];
5459 reg_ea4 = result[i][2];
5460 reg_eac = result[i][3];
5461 reg_eb4 = result[i][4];
5462 reg_ebc = result[i][5];
5463 reg_ec4 = result[i][6];
5464 reg_ecc = result[i][7];
5465 }
5466
5467 if (candidate >= 0) {
5468 reg_e94 = result[candidate][0];
5469 priv->rege94 = reg_e94;
5470 reg_e9c = result[candidate][1];
5471 priv->rege9c = reg_e9c;
5472 reg_ea4 = result[candidate][2];
5473 reg_eac = result[candidate][3];
5474 reg_eb4 = result[candidate][4];
5475 priv->regeb4 = reg_eb4;
5476 reg_ebc = result[candidate][5];
5477 priv->regebc = reg_ebc;
5478 reg_ec4 = result[candidate][6];
5479 reg_ecc = result[candidate][7];
5480 dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
5481 dev_dbg(dev,
5482 "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
5483 "ecc=%x\n ", __func__, reg_e94, reg_e9c,
5484 reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
5485 path_a_ok = true;
5486 path_b_ok = true;
5487 } else {
5488 reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
5489 reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
5490 }
5491
5492 if (reg_e94 && candidate >= 0)
5493 rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
5494 candidate, (reg_ea4 == 0));
5495
5496 if (priv->tx_paths > 1 && reg_eb4)
5497 rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
5498 candidate, (reg_ec4 == 0));
5499
5500 rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg,
5501 priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
Jes Sorensenc7a5a192016-02-29 17:04:30 -05005502
5503 rtl8xxxu_prepare_calibrate(priv, 0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005504}
5505
Jes Sorensene1547c52016-02-29 17:04:35 -05005506static void rtl8723bu_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
5507{
5508 struct device *dev = &priv->udev->dev;
5509 int result[4][8]; /* last is final result */
5510 int i, candidate;
5511 bool path_a_ok, path_b_ok;
5512 u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
5513 u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
5514 u32 val32, bt_control;
5515 s32 reg_tmp = 0;
5516 bool simu;
5517
5518 rtl8xxxu_prepare_calibrate(priv, 1);
5519
5520 memset(result, 0, sizeof(result));
5521 candidate = -1;
5522
5523 path_a_ok = false;
5524 path_b_ok = false;
5525
5526 bt_control = rtl8xxxu_read32(priv, REG_BT_CONTROL_8723BU);
5527
5528 for (i = 0; i < 3; i++) {
5529 rtl8723bu_phy_iqcalibrate(priv, result, i);
5530
5531 if (i == 1) {
5532 simu = rtl8723bu_simularity_compare(priv, result, 0, 1);
5533 if (simu) {
5534 candidate = 0;
5535 break;
5536 }
5537 }
5538
5539 if (i == 2) {
5540 simu = rtl8723bu_simularity_compare(priv, result, 0, 2);
5541 if (simu) {
5542 candidate = 0;
5543 break;
5544 }
5545
5546 simu = rtl8723bu_simularity_compare(priv, result, 1, 2);
5547 if (simu) {
5548 candidate = 1;
5549 } else {
5550 for (i = 0; i < 8; i++)
5551 reg_tmp += result[3][i];
5552
5553 if (reg_tmp)
5554 candidate = 3;
5555 else
5556 candidate = -1;
5557 }
5558 }
5559 }
5560
5561 for (i = 0; i < 4; i++) {
5562 reg_e94 = result[i][0];
5563 reg_e9c = result[i][1];
5564 reg_ea4 = result[i][2];
5565 reg_eac = result[i][3];
5566 reg_eb4 = result[i][4];
5567 reg_ebc = result[i][5];
5568 reg_ec4 = result[i][6];
5569 reg_ecc = result[i][7];
5570 }
5571
5572 if (candidate >= 0) {
5573 reg_e94 = result[candidate][0];
5574 priv->rege94 = reg_e94;
5575 reg_e9c = result[candidate][1];
5576 priv->rege9c = reg_e9c;
5577 reg_ea4 = result[candidate][2];
5578 reg_eac = result[candidate][3];
5579 reg_eb4 = result[candidate][4];
5580 priv->regeb4 = reg_eb4;
5581 reg_ebc = result[candidate][5];
5582 priv->regebc = reg_ebc;
5583 reg_ec4 = result[candidate][6];
5584 reg_ecc = result[candidate][7];
5585 dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
5586 dev_dbg(dev,
5587 "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
5588 "ecc=%x\n ", __func__, reg_e94, reg_e9c,
5589 reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
5590 path_a_ok = true;
5591 path_b_ok = true;
5592 } else {
5593 reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
5594 reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
5595 }
5596
5597 if (reg_e94 && candidate >= 0)
5598 rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
5599 candidate, (reg_ea4 == 0));
5600
5601 if (priv->tx_paths > 1 && reg_eb4)
5602 rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
5603 candidate, (reg_ec4 == 0));
5604
5605 rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg,
5606 priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
5607
5608 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, bt_control);
5609
5610 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
5611 val32 |= 0x80000;
5612 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
5613 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x18000);
5614 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
5615 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xe6177);
5616 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED);
5617 val32 |= 0x20;
5618 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32);
5619 rtl8xxxu_write_rfreg(priv, RF_A, 0x43, 0x300bd);
5620
5621 if (priv->rf_paths > 1) {
5622 dev_dbg(dev, "%s: beware 2T not yet supported\n", __func__);
5623#ifdef RTL8723BU_PATH_B
5624 if (RF_Path == 0x0) //S1
5625 ODM_SetIQCbyRFpath(pDM_Odm, 0);
5626 else //S0
5627 ODM_SetIQCbyRFpath(pDM_Odm, 1);
5628#endif
5629 }
5630 rtl8xxxu_prepare_calibrate(priv, 0);
5631}
5632
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005633static void rtl8723a_phy_lc_calibrate(struct rtl8xxxu_priv *priv)
5634{
5635 u32 val32;
5636 u32 rf_amode, rf_bmode = 0, lstf;
5637
5638 /* Check continuous TX and Packet TX */
5639 lstf = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
5640
5641 if (lstf & OFDM_LSTF_MASK) {
5642 /* Disable all continuous TX */
5643 val32 = lstf & ~OFDM_LSTF_MASK;
5644 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
5645
5646 /* Read original RF mode Path A */
5647 rf_amode = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_AC);
5648
5649 /* Set RF mode to standby Path A */
5650 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC,
5651 (rf_amode & 0x8ffff) | 0x10000);
5652
5653 /* Path-B */
5654 if (priv->tx_paths > 1) {
5655 rf_bmode = rtl8xxxu_read_rfreg(priv, RF_B,
5656 RF6052_REG_AC);
5657
5658 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
5659 (rf_bmode & 0x8ffff) | 0x10000);
5660 }
5661 } else {
5662 /* Deal with Packet TX case */
5663 /* block all queues */
5664 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
5665 }
5666
5667 /* Start LC calibration */
Jes Sorensen0d698de2016-02-29 17:04:36 -05005668 if (priv->fops->has_s0s1)
5669 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_S0S1, 0xdfbe0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005670 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_MODE_AG);
5671 val32 |= 0x08000;
5672 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, val32);
5673
5674 msleep(100);
5675
Jes Sorensen0d698de2016-02-29 17:04:36 -05005676 if (priv->fops->has_s0s1)
5677 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_S0S1, 0xdffe0);
5678
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005679 /* Restore original parameters */
5680 if (lstf & OFDM_LSTF_MASK) {
5681 /* Path-A */
5682 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, lstf);
5683 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, rf_amode);
5684
5685 /* Path-B */
5686 if (priv->tx_paths > 1)
5687 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
5688 rf_bmode);
5689 } else /* Deal with Packet TX case */
5690 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
5691}
5692
5693static int rtl8xxxu_set_mac(struct rtl8xxxu_priv *priv)
5694{
5695 int i;
5696 u16 reg;
5697
5698 reg = REG_MACID;
5699
5700 for (i = 0; i < ETH_ALEN; i++)
5701 rtl8xxxu_write8(priv, reg + i, priv->mac_addr[i]);
5702
5703 return 0;
5704}
5705
5706static int rtl8xxxu_set_bssid(struct rtl8xxxu_priv *priv, const u8 *bssid)
5707{
5708 int i;
5709 u16 reg;
5710
5711 dev_dbg(&priv->udev->dev, "%s: (%pM)\n", __func__, bssid);
5712
5713 reg = REG_BSSID;
5714
5715 for (i = 0; i < ETH_ALEN; i++)
5716 rtl8xxxu_write8(priv, reg + i, bssid[i]);
5717
5718 return 0;
5719}
5720
5721static void
5722rtl8xxxu_set_ampdu_factor(struct rtl8xxxu_priv *priv, u8 ampdu_factor)
5723{
5724 u8 vals[4] = { 0x41, 0xa8, 0x72, 0xb9 };
5725 u8 max_agg = 0xf;
5726 int i;
5727
5728 ampdu_factor = 1 << (ampdu_factor + 2);
5729 if (ampdu_factor > max_agg)
5730 ampdu_factor = max_agg;
5731
5732 for (i = 0; i < 4; i++) {
5733 if ((vals[i] & 0xf0) > (ampdu_factor << 4))
5734 vals[i] = (vals[i] & 0x0f) | (ampdu_factor << 4);
5735
5736 if ((vals[i] & 0x0f) > ampdu_factor)
5737 vals[i] = (vals[i] & 0xf0) | ampdu_factor;
5738
5739 rtl8xxxu_write8(priv, REG_AGGLEN_LMT + i, vals[i]);
5740 }
5741}
5742
5743static void rtl8xxxu_set_ampdu_min_space(struct rtl8xxxu_priv *priv, u8 density)
5744{
5745 u8 val8;
5746
5747 val8 = rtl8xxxu_read8(priv, REG_AMPDU_MIN_SPACE);
5748 val8 &= 0xf8;
5749 val8 |= density;
5750 rtl8xxxu_write8(priv, REG_AMPDU_MIN_SPACE, val8);
5751}
5752
5753static int rtl8xxxu_active_to_emu(struct rtl8xxxu_priv *priv)
5754{
5755 u8 val8;
5756 int count, ret;
5757
5758 /* Start of rtl8723AU_card_enable_flow */
5759 /* Act to Cardemu sequence*/
5760 /* Turn off RF */
5761 rtl8xxxu_write8(priv, REG_RF_CTRL, 0);
5762
5763 /* 0x004E[7] = 0, switch DPDT_SEL_P output from register 0x0065[2] */
5764 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
5765 val8 &= ~LEDCFG2_DPDT_SELECT;
5766 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
5767
5768 /* 0x0005[1] = 1 turn off MAC by HW state machine*/
5769 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5770 val8 |= BIT(1);
5771 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5772
5773 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5774 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5775 if ((val8 & BIT(1)) == 0)
5776 break;
5777 udelay(10);
5778 }
5779
5780 if (!count) {
5781 dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n",
5782 __func__);
5783 ret = -EBUSY;
5784 goto exit;
5785 }
5786
5787 /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */
5788 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5789 val8 |= SYS_ISO_ANALOG_IPS;
5790 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5791
5792 /* 0x0020[0] = 0 disable LDOA12 MACRO block*/
5793 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
5794 val8 &= ~LDOA15_ENABLE;
5795 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
5796
5797exit:
5798 return ret;
5799}
5800
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05005801static int rtl8723bu_active_to_emu(struct rtl8xxxu_priv *priv)
5802{
5803 u8 val8;
5804 u16 val16;
5805 u32 val32;
5806 int count, ret;
5807
5808 /* Turn off RF */
5809 rtl8xxxu_write8(priv, REG_RF_CTRL, 0);
5810
5811 /* Enable rising edge triggering interrupt */
5812 val16 = rtl8xxxu_read16(priv, REG_GPIO_INTM);
5813 val16 &= ~GPIO_INTM_EDGE_TRIG_IRQ;
5814 rtl8xxxu_write16(priv, REG_GPIO_INTM, val16);
5815
5816 /* Release WLON reset 0x04[16]= 1*/
5817 val32 = rtl8xxxu_read32(priv, REG_GPIO_INTM);
5818 val32 |= APS_FSMCO_WLON_RESET;
5819 rtl8xxxu_write32(priv, REG_GPIO_INTM, val32);
5820
5821 /* 0x0005[1] = 1 turn off MAC by HW state machine*/
5822 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5823 val8 |= BIT(1);
5824 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5825
5826 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5827 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5828 if ((val8 & BIT(1)) == 0)
5829 break;
5830 udelay(10);
5831 }
5832
5833 if (!count) {
5834 dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n",
5835 __func__);
5836 ret = -EBUSY;
5837 goto exit;
5838 }
5839
5840 /* Enable BT control XTAL setting */
5841 val8 = rtl8xxxu_read8(priv, REG_AFE_MISC);
5842 val8 &= ~AFE_MISC_WL_XTAL_CTRL;
5843 rtl8xxxu_write8(priv, REG_AFE_MISC, val8);
5844
5845 /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */
5846 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5847 val8 |= SYS_ISO_ANALOG_IPS;
5848 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5849
5850 /* 0x0020[0] = 0 disable LDOA12 MACRO block*/
5851 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
5852 val8 &= ~LDOA15_ENABLE;
5853 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
5854
5855exit:
5856 return ret;
5857}
5858
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005859static int rtl8xxxu_active_to_lps(struct rtl8xxxu_priv *priv)
5860{
5861 u8 val8;
5862 u8 val32;
5863 int count, ret;
5864
5865 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
5866
5867 /*
5868 * Poll - wait for RX packet to complete
5869 */
5870 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5871 val32 = rtl8xxxu_read32(priv, 0x5f8);
5872 if (!val32)
5873 break;
5874 udelay(10);
5875 }
5876
5877 if (!count) {
5878 dev_warn(&priv->udev->dev,
5879 "%s: RX poll timed out (0x05f8)\n", __func__);
5880 ret = -EBUSY;
5881 goto exit;
5882 }
5883
5884 /* Disable CCK and OFDM, clock gated */
5885 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
5886 val8 &= ~SYS_FUNC_BBRSTB;
5887 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
5888
5889 udelay(2);
5890
5891 /* Reset baseband */
5892 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
5893 val8 &= ~SYS_FUNC_BB_GLB_RSTN;
5894 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
5895
5896 /* Reset MAC TRX */
5897 val8 = rtl8xxxu_read8(priv, REG_CR);
5898 val8 = CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE;
5899 rtl8xxxu_write8(priv, REG_CR, val8);
5900
5901 /* Reset MAC TRX */
5902 val8 = rtl8xxxu_read8(priv, REG_CR + 1);
5903 val8 &= ~BIT(1); /* CR_SECURITY_ENABLE */
5904 rtl8xxxu_write8(priv, REG_CR + 1, val8);
5905
5906 /* Respond TX OK to scheduler */
5907 val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST);
5908 val8 |= DUAL_TSF_TX_OK;
5909 rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);
5910
5911exit:
5912 return ret;
5913}
5914
Jes Sorensenc05a9db2016-02-29 17:04:03 -05005915static void rtl8723a_disabled_to_emu(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005916{
5917 u8 val8;
5918
5919 /* Clear suspend enable and power down enable*/
5920 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5921 val8 &= ~(BIT(3) | BIT(7));
5922 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5923
5924 /* 0x48[16] = 0 to disable GPIO9 as EXT WAKEUP*/
5925 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
5926 val8 &= ~BIT(0);
5927 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
5928
5929 /* 0x04[12:11] = 11 enable WL suspend*/
5930 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5931 val8 &= ~(BIT(3) | BIT(4));
5932 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5933}
5934
Jes Sorensenc05a9db2016-02-29 17:04:03 -05005935static void rtl8192e_disabled_to_emu(struct rtl8xxxu_priv *priv)
5936{
5937 u8 val8;
5938
5939 /* Clear suspend enable and power down enable*/
5940 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5941 val8 &= ~(BIT(3) | BIT(4));
5942 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5943}
5944
5945static int rtl8192e_emu_to_active(struct rtl8xxxu_priv *priv)
5946{
5947 u8 val8;
5948 u32 val32;
5949 int count, ret = 0;
5950
5951 /* disable HWPDN 0x04[15]=0*/
5952 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5953 val8 &= ~BIT(7);
5954 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5955
5956 /* disable SW LPS 0x04[10]= 0 */
5957 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5958 val8 &= ~BIT(2);
5959 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5960
5961 /* disable WL suspend*/
5962 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5963 val8 &= ~(BIT(3) | BIT(4));
5964 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5965
5966 /* wait till 0x04[17] = 1 power ready*/
5967 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5968 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5969 if (val32 & BIT(17))
5970 break;
5971
5972 udelay(10);
5973 }
5974
5975 if (!count) {
5976 ret = -EBUSY;
5977 goto exit;
5978 }
5979
5980 /* We should be able to optimize the following three entries into one */
5981
5982 /* release WLON reset 0x04[16]= 1*/
5983 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
5984 val8 |= BIT(0);
5985 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
5986
5987 /* set, then poll until 0 */
5988 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5989 val32 |= APS_FSMCO_MAC_ENABLE;
5990 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5991
5992 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5993 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5994 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
5995 ret = 0;
5996 break;
5997 }
5998 udelay(10);
5999 }
6000
6001 if (!count) {
6002 ret = -EBUSY;
6003 goto exit;
6004 }
6005
6006exit:
6007 return ret;
6008}
6009
6010static int rtl8723a_emu_to_active(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006011{
6012 u8 val8;
6013 u32 val32;
6014 int count, ret = 0;
6015
6016 /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface*/
6017 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
6018 val8 |= LDOA15_ENABLE;
6019 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
6020
6021 /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/
6022 val8 = rtl8xxxu_read8(priv, 0x0067);
6023 val8 &= ~BIT(4);
6024 rtl8xxxu_write8(priv, 0x0067, val8);
6025
6026 mdelay(1);
6027
6028 /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */
6029 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
6030 val8 &= ~SYS_ISO_ANALOG_IPS;
6031 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
6032
6033 /* disable SW LPS 0x04[10]= 0 */
6034 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
6035 val8 &= ~BIT(2);
6036 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
6037
6038 /* wait till 0x04[17] = 1 power ready*/
6039 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
6040 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6041 if (val32 & BIT(17))
6042 break;
6043
6044 udelay(10);
6045 }
6046
6047 if (!count) {
6048 ret = -EBUSY;
6049 goto exit;
6050 }
6051
6052 /* We should be able to optimize the following three entries into one */
6053
6054 /* release WLON reset 0x04[16]= 1*/
6055 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
6056 val8 |= BIT(0);
6057 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
6058
6059 /* disable HWPDN 0x04[15]= 0*/
6060 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
6061 val8 &= ~BIT(7);
6062 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
6063
6064 /* disable WL suspend*/
6065 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
6066 val8 &= ~(BIT(3) | BIT(4));
6067 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
6068
6069 /* set, then poll until 0 */
6070 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6071 val32 |= APS_FSMCO_MAC_ENABLE;
6072 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
6073
6074 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
6075 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6076 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
6077 ret = 0;
6078 break;
6079 }
6080 udelay(10);
6081 }
6082
6083 if (!count) {
6084 ret = -EBUSY;
6085 goto exit;
6086 }
6087
6088 /* 0x4C[23] = 0x4E[7] = 1, switch DPDT_SEL_P output from WL BB */
6089 /*
6090 * Note: Vendor driver actually clears this bit, despite the
6091 * documentation claims it's being set!
6092 */
6093 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
6094 val8 |= LEDCFG2_DPDT_SELECT;
6095 val8 &= ~LEDCFG2_DPDT_SELECT;
6096 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
6097
6098exit:
6099 return ret;
6100}
6101
Jes Sorensen42836db2016-02-29 17:04:52 -05006102static int rtl8723b_emu_to_active(struct rtl8xxxu_priv *priv)
6103{
6104 u8 val8;
6105 u32 val32;
6106 int count, ret = 0;
6107
6108 /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface */
6109 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
6110 val8 |= LDOA15_ENABLE;
6111 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
6112
6113 /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/
6114 val8 = rtl8xxxu_read8(priv, 0x0067);
6115 val8 &= ~BIT(4);
6116 rtl8xxxu_write8(priv, 0x0067, val8);
6117
6118 mdelay(1);
6119
6120 /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */
6121 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
6122 val8 &= ~SYS_ISO_ANALOG_IPS;
6123 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
6124
6125 /* Disable SW LPS 0x04[10]= 0 */
6126 val32 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
6127 val32 &= ~APS_FSMCO_SW_LPS;
6128 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
6129
6130 /* Wait until 0x04[17] = 1 power ready */
6131 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
6132 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6133 if (val32 & BIT(17))
6134 break;
6135
6136 udelay(10);
6137 }
6138
6139 if (!count) {
6140 ret = -EBUSY;
6141 goto exit;
6142 }
6143
6144 /* We should be able to optimize the following three entries into one */
6145
6146 /* Release WLON reset 0x04[16]= 1*/
6147 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6148 val32 |= APS_FSMCO_WLON_RESET;
6149 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
6150
6151 /* Disable HWPDN 0x04[15]= 0*/
6152 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6153 val32 &= ~APS_FSMCO_HW_POWERDOWN;
6154 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
6155
6156 /* Disable WL suspend*/
6157 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6158 val32 &= ~(APS_FSMCO_HW_SUSPEND | APS_FSMCO_PCIE);
6159 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
6160
6161 /* Set, then poll until 0 */
6162 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6163 val32 |= APS_FSMCO_MAC_ENABLE;
6164 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
6165
6166 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
6167 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
6168 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
6169 ret = 0;
6170 break;
6171 }
6172 udelay(10);
6173 }
6174
6175 if (!count) {
6176 ret = -EBUSY;
6177 goto exit;
6178 }
6179
6180 /* Enable WL control XTAL setting */
6181 val8 = rtl8xxxu_read8(priv, REG_AFE_MISC);
6182 val8 |= AFE_MISC_WL_XTAL_CTRL;
6183 rtl8xxxu_write8(priv, REG_AFE_MISC, val8);
6184
6185 /* Enable falling edge triggering interrupt */
6186 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 1);
6187 val8 |= BIT(1);
6188 rtl8xxxu_write8(priv, REG_GPIO_INTM + 1, val8);
6189
6190 /* Enable GPIO9 interrupt mode */
6191 val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2 + 1);
6192 val8 |= BIT(1);
6193 rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2 + 1, val8);
6194
6195 /* Enable GPIO9 input mode */
6196 val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2);
6197 val8 &= ~BIT(1);
6198 rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2, val8);
6199
6200 /* Enable HSISR GPIO[C:0] interrupt */
6201 val8 = rtl8xxxu_read8(priv, REG_HSIMR);
6202 val8 |= BIT(0);
6203 rtl8xxxu_write8(priv, REG_HSIMR, val8);
6204
6205 /* Enable HSISR GPIO9 interrupt */
6206 val8 = rtl8xxxu_read8(priv, REG_HSIMR + 2);
6207 val8 |= BIT(1);
6208 rtl8xxxu_write8(priv, REG_HSIMR + 2, val8);
6209
6210 val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL);
6211 val8 |= MULTI_WIFI_HW_ROF_EN;
6212 rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL, val8);
6213
6214 /* For GPIO9 internal pull high setting BIT(14) */
6215 val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL + 1);
6216 val8 |= BIT(6);
6217 rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL + 1, val8);
6218
6219exit:
6220 return ret;
6221}
6222
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006223static int rtl8xxxu_emu_to_disabled(struct rtl8xxxu_priv *priv)
6224{
6225 u8 val8;
6226
6227 /* 0x0007[7:0] = 0x20 SOP option to disable BG/MB */
6228 rtl8xxxu_write8(priv, REG_APS_FSMCO + 3, 0x20);
6229
6230 /* 0x04[12:11] = 01 enable WL suspend */
6231 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
6232 val8 &= ~BIT(4);
6233 val8 |= BIT(3);
6234 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
6235
6236 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
6237 val8 |= BIT(7);
6238 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
6239
6240 /* 0x48[16] = 1 to enable GPIO9 as EXT wakeup */
6241 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
6242 val8 |= BIT(0);
6243 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
6244
6245 return 0;
6246}
6247
Jes Sorensen430b4542016-02-29 17:05:48 -05006248static int rtl8xxxu_flush_fifo(struct rtl8xxxu_priv *priv)
6249{
Jes Sorensen145428e2016-02-29 17:05:49 -05006250 struct device *dev = &priv->udev->dev;
Jes Sorensen430b4542016-02-29 17:05:48 -05006251 u32 val32;
6252 int retry, retval;
6253
6254 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
6255
6256 val32 = rtl8xxxu_read32(priv, REG_RXPKT_NUM);
6257 val32 |= RXPKT_NUM_RW_RELEASE_EN;
6258 rtl8xxxu_write32(priv, REG_RXPKT_NUM, val32);
6259
6260 retry = 100;
6261 retval = -EBUSY;
6262
6263 do {
6264 val32 = rtl8xxxu_read32(priv, REG_RXPKT_NUM);
6265 if (val32 & RXPKT_NUM_RXDMA_IDLE) {
6266 retval = 0;
6267 break;
6268 }
6269 } while (retry--);
6270
6271 rtl8xxxu_write16(priv, REG_RQPN_NPQ, 0);
6272 rtl8xxxu_write32(priv, REG_RQPN, 0x80000000);
6273 mdelay(2);
Jes Sorensen145428e2016-02-29 17:05:49 -05006274
6275 if (!retry)
6276 dev_warn(dev, "Failed to flush FIFO\n");
Jes Sorensen430b4542016-02-29 17:05:48 -05006277
6278 return retval;
6279}
6280
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006281static int rtl8723au_power_on(struct rtl8xxxu_priv *priv)
6282{
6283 u8 val8;
6284 u16 val16;
6285 u32 val32;
6286 int ret;
6287
6288 /*
6289 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
6290 */
6291 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
6292
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006293 rtl8723a_disabled_to_emu(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006294
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006295 ret = rtl8723a_emu_to_active(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006296 if (ret)
6297 goto exit;
6298
6299 /*
6300 * 0x0004[19] = 1, reset 8051
6301 */
6302 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
6303 val8 |= BIT(3);
6304 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
6305
6306 /*
6307 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
6308 * Set CR bit10 to enable 32k calibration.
6309 */
6310 val16 = rtl8xxxu_read16(priv, REG_CR);
6311 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
6312 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
6313 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
6314 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
6315 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
6316 rtl8xxxu_write16(priv, REG_CR, val16);
6317
6318 /* For EFuse PG */
6319 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
6320 val32 &= ~(BIT(28) | BIT(29) | BIT(30));
6321 val32 |= (0x06 << 28);
6322 rtl8xxxu_write32(priv, REG_EFUSE_CTRL, val32);
6323exit:
6324 return ret;
6325}
6326
Jes Sorensen42836db2016-02-29 17:04:52 -05006327static int rtl8723bu_power_on(struct rtl8xxxu_priv *priv)
6328{
6329 u8 val8;
6330 u16 val16;
6331 u32 val32;
6332 int ret;
6333
6334 rtl8723a_disabled_to_emu(priv);
6335
6336 ret = rtl8723b_emu_to_active(priv);
6337 if (ret)
6338 goto exit;
6339
6340 /*
6341 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
6342 * Set CR bit10 to enable 32k calibration.
6343 */
6344 val16 = rtl8xxxu_read16(priv, REG_CR);
6345 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
6346 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
6347 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
6348 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
6349 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
6350 rtl8xxxu_write16(priv, REG_CR, val16);
6351
6352 /*
6353 * BT coexist power on settings. This is identical for 1 and 2
6354 * antenna parts.
6355 */
6356 rtl8xxxu_write8(priv, REG_PAD_CTRL1 + 3, 0x20);
6357
6358 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
6359 val16 |= SYS_FUNC_BBRSTB | SYS_FUNC_BB_GLB_RSTN;
6360 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
6361
6362 rtl8xxxu_write8(priv, REG_BT_CONTROL_8723BU + 1, 0x18);
6363 rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04);
6364 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00);
6365 /* Antenna inverse */
6366 rtl8xxxu_write8(priv, 0xfe08, 0x01);
6367
6368 val16 = rtl8xxxu_read16(priv, REG_PWR_DATA);
6369 val16 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
6370 rtl8xxxu_write16(priv, REG_PWR_DATA, val16);
6371
6372 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
6373 val32 |= LEDCFG0_DPDT_SELECT;
6374 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
6375
6376 val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1);
6377 val8 &= ~PAD_CTRL1_SW_DPDT_SEL_DATA;
6378 rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8);
6379exit:
6380 return ret;
6381}
6382
Kalle Valoc0963772015-10-25 18:24:38 +02006383#ifdef CONFIG_RTL8XXXU_UNTESTED
6384
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006385static int rtl8192cu_power_on(struct rtl8xxxu_priv *priv)
6386{
6387 u8 val8;
6388 u16 val16;
6389 u32 val32;
6390 int i;
6391
6392 for (i = 100; i; i--) {
6393 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
6394 if (val8 & APS_FSMCO_PFM_ALDN)
6395 break;
6396 }
6397
6398 if (!i) {
6399 pr_info("%s: Poll failed\n", __func__);
6400 return -ENODEV;
6401 }
6402
6403 /*
6404 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
6405 */
6406 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
6407 rtl8xxxu_write8(priv, REG_SPS0_CTRL, 0x2b);
6408 udelay(100);
6409
6410 val8 = rtl8xxxu_read8(priv, REG_LDOV12D_CTRL);
6411 if (!(val8 & LDOV12D_ENABLE)) {
6412 pr_info("%s: Enabling LDOV12D (%02x)\n", __func__, val8);
6413 val8 |= LDOV12D_ENABLE;
6414 rtl8xxxu_write8(priv, REG_LDOV12D_CTRL, val8);
6415
6416 udelay(100);
6417
6418 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
6419 val8 &= ~SYS_ISO_MD2PP;
6420 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
6421 }
6422
6423 /*
6424 * Auto enable WLAN
6425 */
6426 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
6427 val16 |= APS_FSMCO_MAC_ENABLE;
6428 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
6429
6430 for (i = 1000; i; i--) {
6431 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
6432 if (!(val16 & APS_FSMCO_MAC_ENABLE))
6433 break;
6434 }
6435 if (!i) {
6436 pr_info("%s: FSMCO_MAC_ENABLE poll failed\n", __func__);
6437 return -EBUSY;
6438 }
6439
6440 /*
6441 * Enable radio, GPIO, LED
6442 */
6443 val16 = APS_FSMCO_HW_SUSPEND | APS_FSMCO_ENABLE_POWERDOWN |
6444 APS_FSMCO_PFM_ALDN;
6445 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
6446
6447 /*
6448 * Release RF digital isolation
6449 */
6450 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
6451 val16 &= ~SYS_ISO_DIOR;
6452 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
6453
6454 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
6455 val8 &= ~APSD_CTRL_OFF;
6456 rtl8xxxu_write8(priv, REG_APSD_CTRL, val8);
6457 for (i = 200; i; i--) {
6458 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
6459 if (!(val8 & APSD_CTRL_OFF_STATUS))
6460 break;
6461 }
6462
6463 if (!i) {
6464 pr_info("%s: APSD_CTRL poll failed\n", __func__);
6465 return -EBUSY;
6466 }
6467
6468 /*
6469 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
6470 */
6471 val16 = rtl8xxxu_read16(priv, REG_CR);
6472 val16 |= CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
6473 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | CR_PROTOCOL_ENABLE |
6474 CR_SCHEDULE_ENABLE | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE;
6475 rtl8xxxu_write16(priv, REG_CR, val16);
6476
6477 /*
6478 * Workaround for 8188RU LNA power leakage problem.
6479 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006480 if (priv->rtl_chip == RTL8188C && priv->hi_pa) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006481 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
6482 val32 &= ~BIT(1);
6483 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
6484 }
6485 return 0;
6486}
6487
Kalle Valoc0963772015-10-25 18:24:38 +02006488#endif
6489
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006490static int rtl8192eu_power_on(struct rtl8xxxu_priv *priv)
6491{
6492 u16 val16;
6493 u32 val32;
6494 int ret;
6495
6496 ret = 0;
6497
6498 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
6499 if (val32 & SYS_CFG_SPS_LDO_SEL) {
6500 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0xc3);
6501 } else {
6502 /*
6503 * Raise 1.2V voltage
6504 */
6505 val32 = rtl8xxxu_read32(priv, REG_8192E_LDOV12_CTRL);
6506 val32 &= 0xff0fffff;
6507 val32 |= 0x00500000;
6508 rtl8xxxu_write32(priv, REG_8192E_LDOV12_CTRL, val32);
6509 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0x83);
6510 }
6511
6512 rtl8192e_disabled_to_emu(priv);
6513
6514 ret = rtl8192e_emu_to_active(priv);
6515 if (ret)
6516 goto exit;
6517
6518 rtl8xxxu_write16(priv, REG_CR, 0x0000);
6519
6520 /*
6521 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
6522 * Set CR bit10 to enable 32k calibration.
6523 */
6524 val16 = rtl8xxxu_read16(priv, REG_CR);
6525 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
6526 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
6527 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
6528 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
6529 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
6530 rtl8xxxu_write16(priv, REG_CR, val16);
6531
6532exit:
6533 return ret;
6534}
6535
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006536static void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv)
6537{
6538 u8 val8;
6539 u16 val16;
6540 u32 val32;
6541
6542 /*
6543 * Workaround for 8188RU LNA power leakage problem.
6544 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006545 if (priv->rtl_chip == RTL8188C && priv->hi_pa) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006546 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
6547 val32 |= BIT(1);
6548 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
6549 }
6550
Jes Sorensen430b4542016-02-29 17:05:48 -05006551 rtl8xxxu_flush_fifo(priv);
6552
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006553 rtl8xxxu_active_to_lps(priv);
6554
6555 /* Turn off RF */
6556 rtl8xxxu_write8(priv, REG_RF_CTRL, 0x00);
6557
6558 /* Reset Firmware if running in RAM */
6559 if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
6560 rtl8xxxu_firmware_self_reset(priv);
6561
6562 /* Reset MCU */
6563 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
6564 val16 &= ~SYS_FUNC_CPU_ENABLE;
6565 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
6566
6567 /* Reset MCU ready status */
6568 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
6569
6570 rtl8xxxu_active_to_emu(priv);
6571 rtl8xxxu_emu_to_disabled(priv);
6572
6573 /* Reset MCU IO Wrapper */
6574 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
6575 val8 &= ~BIT(0);
6576 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
6577
6578 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
6579 val8 |= BIT(0);
6580 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
6581
6582 /* RSV_CTRL 0x1C[7:0] = 0x0e lock ISO/CLK/Power control register */
6583 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0e);
6584}
6585
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006586static void rtl8723bu_power_off(struct rtl8xxxu_priv *priv)
6587{
6588 u8 val8;
6589 u16 val16;
6590
Jes Sorensen430b4542016-02-29 17:05:48 -05006591 rtl8xxxu_flush_fifo(priv);
6592
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006593 /*
6594 * Disable TX report timer
6595 */
6596 val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL);
6597 val8 &= ~TX_REPORT_CTRL_TIMER_ENABLE;
6598 rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8);
6599
6600 rtl8xxxu_write16(priv, REG_CR, 0x0000);
6601
6602 rtl8xxxu_active_to_lps(priv);
6603
6604 /* Reset Firmware if running in RAM */
6605 if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
6606 rtl8xxxu_firmware_self_reset(priv);
6607
6608 /* Reset MCU */
6609 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
6610 val16 &= ~SYS_FUNC_CPU_ENABLE;
6611 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
6612
6613 /* Reset MCU ready status */
6614 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
6615
6616 rtl8723bu_active_to_emu(priv);
6617 rtl8xxxu_emu_to_disabled(priv);
6618}
6619
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006620#ifdef NEED_PS_TDMA
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006621static void rtl8723bu_set_ps_tdma(struct rtl8xxxu_priv *priv,
6622 u8 arg1, u8 arg2, u8 arg3, u8 arg4, u8 arg5)
6623{
6624 struct h2c_cmd h2c;
6625
6626 memset(&h2c, 0, sizeof(struct h2c_cmd));
6627 h2c.b_type_dma.cmd = H2C_8723B_B_TYPE_TDMA;
6628 h2c.b_type_dma.data1 = arg1;
6629 h2c.b_type_dma.data2 = arg2;
6630 h2c.b_type_dma.data3 = arg3;
6631 h2c.b_type_dma.data4 = arg4;
6632 h2c.b_type_dma.data5 = arg5;
6633 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.b_type_dma));
6634}
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006635#endif
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006636
Jes Sorensen0290e7d2016-02-29 17:05:44 -05006637static void rtl8723b_enable_rf(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006638{
Jes Sorensenf37e9222016-02-29 17:04:41 -05006639 struct h2c_cmd h2c;
6640 u32 val32;
6641 u8 val8;
6642
6643 /*
6644 * No indication anywhere as to what 0x0790 does. The 2 antenna
6645 * vendor code preserves bits 6-7 here.
6646 */
6647 rtl8xxxu_write8(priv, 0x0790, 0x05);
6648 /*
6649 * 0x0778 seems to be related to enabling the number of antennas
6650 * In the vendor driver halbtc8723b2ant_InitHwConfig() sets it
6651 * to 0x03, while halbtc8723b1ant_InitHwConfig() sets it to 0x01
6652 */
6653 rtl8xxxu_write8(priv, 0x0778, 0x01);
6654
6655 val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG);
6656 val8 |= BIT(5);
6657 rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8);
6658
6659 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_IQADJ_G1, 0x780);
6660
Jes Sorensen394f1bd2016-02-29 17:04:49 -05006661 rtl8723bu_write_btreg(priv, 0x3c, 0x15); /* BT TRx Mask on */
6662
Jes Sorensenf37e9222016-02-29 17:04:41 -05006663 /*
6664 * Set BT grant to low
6665 */
6666 memset(&h2c, 0, sizeof(struct h2c_cmd));
6667 h2c.bt_grant.cmd = H2C_8723B_BT_GRANT;
6668 h2c.bt_grant.data = 0;
6669 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_grant));
6670
6671 /*
6672 * WLAN action by PTA
6673 */
Jes Sorensenfc1c89b2016-02-29 17:05:12 -05006674 rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04);
Jes Sorensenf37e9222016-02-29 17:04:41 -05006675
6676 /*
6677 * BT select S0/S1 controlled by WiFi
6678 */
6679 val8 = rtl8xxxu_read8(priv, 0x0067);
6680 val8 |= BIT(5);
6681 rtl8xxxu_write8(priv, 0x0067, val8);
6682
6683 val32 = rtl8xxxu_read32(priv, REG_PWR_DATA);
Jes Sorensen37f44dc2016-02-29 17:05:45 -05006684 val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
Jes Sorensenf37e9222016-02-29 17:04:41 -05006685 rtl8xxxu_write32(priv, REG_PWR_DATA, val32);
6686
6687 /*
6688 * Bits 6/7 are marked in/out ... but for what?
6689 */
6690 rtl8xxxu_write8(priv, 0x0974, 0xff);
6691
Jes Sorensen120e6272016-02-29 17:05:14 -05006692 val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER);
Jes Sorensenf37e9222016-02-29 17:04:41 -05006693 val32 |= (BIT(0) | BIT(1));
Jes Sorensen120e6272016-02-29 17:05:14 -05006694 rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32);
Jes Sorensenf37e9222016-02-29 17:04:41 -05006695
6696 rtl8xxxu_write8(priv, REG_RFE_CTRL_ANTA_SRC, 0x77);
6697
6698 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
6699 val32 &= ~BIT(24);
6700 val32 |= BIT(23);
6701 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
6702
6703 /*
6704 * Fix external switch Main->S1, Aux->S0
6705 */
6706 val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1);
6707 val8 &= ~BIT(0);
6708 rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8);
6709
6710 memset(&h2c, 0, sizeof(struct h2c_cmd));
6711 h2c.ant_sel_rsv.cmd = H2C_8723B_ANT_SEL_RSV;
6712 h2c.ant_sel_rsv.ant_inverse = 1;
6713 h2c.ant_sel_rsv.int_switch_type = 0;
6714 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ant_sel_rsv));
6715
6716 /*
6717 * 0x280, 0x00, 0x200, 0x80 - not clear
6718 */
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006719 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00);
6720
6721 /*
6722 * Software control, antenna at WiFi side
6723 */
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006724#ifdef NEED_PS_TDMA
Jes Sorensena228a5d2016-02-29 17:04:45 -05006725 rtl8723bu_set_ps_tdma(priv, 0x08, 0x00, 0x00, 0x00, 0x00);
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006726#endif
6727
6728 rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555);
6729 rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x55555555);
6730 rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
6731 rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006732
Jes Sorensen6b9eae02016-02-29 17:04:50 -05006733 memset(&h2c, 0, sizeof(struct h2c_cmd));
6734 h2c.bt_info.cmd = H2C_8723B_BT_INFO;
6735 h2c.bt_info.data = BIT(0);
6736 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_info));
6737
Jes Sorensen6b9eae02016-02-29 17:04:50 -05006738 memset(&h2c, 0, sizeof(struct h2c_cmd));
6739 h2c.ignore_wlan.cmd = H2C_8723B_BT_IGNORE_WLANACT;
6740 h2c.ignore_wlan.data = 0;
6741 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ignore_wlan));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006742}
6743
Jes Sorensenfc89a412016-02-29 17:05:46 -05006744static void rtl8723b_disable_rf(struct rtl8xxxu_priv *priv)
6745{
6746 u32 val32;
6747
6748 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
6749
6750 val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA);
6751 val32 &= ~(BIT(22) | BIT(23));
6752 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32);
6753}
6754
Jes Sorensen3e88ca42016-02-29 17:05:08 -05006755static void rtl8723bu_init_aggregation(struct rtl8xxxu_priv *priv)
6756{
6757 u32 agg_rx;
6758 u8 agg_ctrl;
6759
6760 /*
6761 * For now simply disable RX aggregation
6762 */
6763 agg_ctrl = rtl8xxxu_read8(priv, REG_TRXDMA_CTRL);
6764 agg_ctrl &= ~TRXDMA_CTRL_RXDMA_AGG_EN;
6765
6766 agg_rx = rtl8xxxu_read32(priv, REG_RXDMA_AGG_PG_TH);
6767 agg_rx &= ~RXDMA_USB_AGG_ENABLE;
6768 agg_rx &= ~0xff0f;
6769
6770 rtl8xxxu_write8(priv, REG_TRXDMA_CTRL, agg_ctrl);
6771 rtl8xxxu_write32(priv, REG_RXDMA_AGG_PG_TH, agg_rx);
6772}
6773
Jes Sorensen9c79bf92016-02-29 17:05:10 -05006774static void rtl8723bu_init_statistics(struct rtl8xxxu_priv *priv)
6775{
6776 u32 val32;
6777
6778 /* Time duration for NHM unit: 4us, 0x2710=40ms */
6779 rtl8xxxu_write16(priv, REG_NHM_TIMER_8723B + 2, 0x2710);
6780 rtl8xxxu_write16(priv, REG_NHM_TH9_TH10_8723B + 2, 0xffff);
6781 rtl8xxxu_write32(priv, REG_NHM_TH3_TO_TH0_8723B, 0xffffff52);
6782 rtl8xxxu_write32(priv, REG_NHM_TH7_TO_TH4_8723B, 0xffffffff);
6783 /* TH8 */
6784 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
6785 val32 |= 0xff;
6786 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
6787 /* Enable CCK */
6788 val32 = rtl8xxxu_read32(priv, REG_NHM_TH9_TH10_8723B);
6789 val32 |= BIT(8) | BIT(9) | BIT(10);
6790 rtl8xxxu_write32(priv, REG_NHM_TH9_TH10_8723B, val32);
6791 /* Max power amongst all RX antennas */
6792 val32 = rtl8xxxu_read32(priv, REG_OFDM0_FA_RSTC);
6793 val32 |= BIT(7);
6794 rtl8xxxu_write32(priv, REG_OFDM0_FA_RSTC, val32);
6795}
6796
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006797static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
6798{
6799 struct rtl8xxxu_priv *priv = hw->priv;
6800 struct device *dev = &priv->udev->dev;
6801 struct rtl8xxxu_rfregval *rftable;
6802 bool macpower;
6803 int ret;
6804 u8 val8;
6805 u16 val16;
6806 u32 val32;
6807
6808 /* Check if MAC is already powered on */
6809 val8 = rtl8xxxu_read8(priv, REG_CR);
6810
6811 /*
6812 * Fix 92DU-VC S3 hang with the reason is that secondary mac is not
6813 * initialized. First MAC returns 0xea, second MAC returns 0x00
6814 */
6815 if (val8 == 0xea)
6816 macpower = false;
6817 else
6818 macpower = true;
6819
6820 ret = priv->fops->power_on(priv);
6821 if (ret < 0) {
6822 dev_warn(dev, "%s: Failed power on\n", __func__);
6823 goto exit;
6824 }
6825
6826 dev_dbg(dev, "%s: macpower %i\n", __func__, macpower);
6827 if (!macpower) {
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006828 ret = priv->fops->llt_init(priv, TX_TOTAL_PAGE_NUM);
6829 if (ret) {
6830 dev_warn(dev, "%s: LLT table init failed\n", __func__);
6831 goto exit;
6832 }
6833
6834 /*
6835 * Presumably this is for 8188EU as well
6836 * Enable TX report and TX report timer
6837 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006838 if (priv->rtl_chip == RTL8723B) {
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006839 val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL);
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006840 val8 |= TX_REPORT_CTRL_TIMER_ENABLE;
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006841 rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8);
6842 /* Set MAX RPT MACID */
6843 rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1, 0x02);
6844 /* TX report Timer. Unit: 32us */
6845 rtl8xxxu_write16(priv, REG_TX_REPORT_TIME, 0xcdf0);
Jes Sorensen360157e2016-02-29 17:04:57 -05006846
6847 /* tmp ps ? */
6848 val8 = rtl8xxxu_read8(priv, 0xa3);
6849 val8 &= 0xf8;
6850 rtl8xxxu_write8(priv, 0xa3, val8);
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006851 }
Jes Sorensen07bb46b2016-02-29 17:04:05 -05006852 }
6853
Jes Sorensena47b9d42016-02-29 17:04:06 -05006854 ret = rtl8xxxu_download_firmware(priv);
6855 dev_dbg(dev, "%s: download_fiwmare %i\n", __func__, ret);
6856 if (ret)
6857 goto exit;
6858 ret = rtl8xxxu_start_firmware(priv);
6859 dev_dbg(dev, "%s: start_fiwmare %i\n", __func__, ret);
6860 if (ret)
6861 goto exit;
6862
Jes Sorensen6431ea02016-02-29 17:04:21 -05006863 /* Solve too many protocol error on USB bus */
6864 /* Can't do this for 8188/8192 UMC A cut parts */
Jes Sorensenba17d822016-03-31 17:08:39 -04006865 if (priv->rtl_chip == RTL8723A ||
6866 ((priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C ||
6867 priv->rtl_chip == RTL8188C) &&
Jes Sorensen6431ea02016-02-29 17:04:21 -05006868 (priv->chip_cut || !priv->vendor_umc))) {
6869 rtl8xxxu_write8(priv, 0xfe40, 0xe6);
6870 rtl8xxxu_write8(priv, 0xfe41, 0x94);
6871 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6872
6873 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
6874 rtl8xxxu_write8(priv, 0xfe41, 0x19);
6875 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6876
6877 rtl8xxxu_write8(priv, 0xfe40, 0xe5);
6878 rtl8xxxu_write8(priv, 0xfe41, 0x91);
6879 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6880
6881 rtl8xxxu_write8(priv, 0xfe40, 0xe2);
6882 rtl8xxxu_write8(priv, 0xfe41, 0x81);
6883 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6884 }
6885
Jes Sorensenba17d822016-03-31 17:08:39 -04006886 if (priv->rtl_chip == RTL8192E) {
Jes Sorensen99ad16c2016-02-29 17:04:09 -05006887 rtl8xxxu_write32(priv, REG_HIMR0, 0x00);
6888 rtl8xxxu_write32(priv, REG_HIMR1, 0x00);
Jes Sorensenb63d0aa2016-02-29 17:04:08 -05006889 }
6890
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05006891 if (priv->fops->phy_init_antenna_selection)
6892 priv->fops->phy_init_antenna_selection(priv);
6893
Jes Sorensenc606e662016-04-07 14:19:16 -04006894 ret = rtl8xxxu_init_mac(priv);
Jes Sorensenb7dd8ff2016-02-29 17:04:17 -05006895
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006896 dev_dbg(dev, "%s: init_mac %i\n", __func__, ret);
6897 if (ret)
6898 goto exit;
6899
6900 ret = rtl8xxxu_init_phy_bb(priv);
6901 dev_dbg(dev, "%s: init_phy_bb %i\n", __func__, ret);
6902 if (ret)
6903 goto exit;
6904
Jes Sorensenba17d822016-03-31 17:08:39 -04006905 switch(priv->rtl_chip) {
6906 case RTL8723A:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006907 rftable = rtl8723au_radioa_1t_init_table;
6908 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6909 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006910 case RTL8723B:
Jes Sorensen22a31d42016-02-29 17:04:15 -05006911 rftable = rtl8723bu_radioa_1t_init_table;
6912 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
Jes Sorensen5ac61782016-02-29 17:05:05 -05006913 /*
6914 * PHY LCK
6915 */
6916 rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdfbe0);
6917 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, 0x8c01);
6918 msleep(200);
6919 rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdffe0);
Jes Sorensen22a31d42016-02-29 17:04:15 -05006920 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006921 case RTL8188C:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006922 if (priv->hi_pa)
6923 rftable = rtl8188ru_radioa_1t_highpa_table;
6924 else
6925 rftable = rtl8192cu_radioa_1t_init_table;
6926 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6927 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006928 case RTL8191C:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006929 rftable = rtl8192cu_radioa_1t_init_table;
6930 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6931 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006932 case RTL8192C:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006933 rftable = rtl8192cu_radioa_2t_init_table;
6934 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6935 if (ret)
6936 break;
6937 rftable = rtl8192cu_radiob_2t_init_table;
6938 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B);
6939 break;
Jes Sorensen19102f82016-04-07 14:19:19 -04006940 case RTL8192E:
6941 rftable = rtl8192eu_radioa_init_table;
6942 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6943 if (ret)
6944 break;
6945 rftable = rtl8192eu_radiob_init_table;
6946 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B);
6947 break;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006948 default:
6949 ret = -EINVAL;
6950 }
6951
6952 if (ret)
6953 goto exit;
6954
Jes Sorensen2f109c82016-02-29 17:05:07 -05006955 /*
6956 * Chip specific quirks
6957 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006958 if (priv->rtl_chip == RTL8723A) {
Jes Sorensen2f109c82016-02-29 17:05:07 -05006959 /* Fix USB interface interference issue */
6960 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
6961 rtl8xxxu_write8(priv, 0xfe41, 0x8d);
6962 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6963 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320);
6964
6965 /* Reduce 80M spur */
Jes Sorensenf30ed672016-02-29 17:04:59 -05006966 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d);
6967 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
6968 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82);
6969 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
Jes Sorensen2f109c82016-02-29 17:05:07 -05006970 } else {
6971 val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK);
6972 val32 |= TXDMA_OFFSET_DROP_DATA_EN;
6973 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32);
Jes Sorensenf30ed672016-02-29 17:04:59 -05006974 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006975
Jes Sorensenf2a41632016-02-29 17:05:09 -05006976 if (!macpower) {
Jes Sorensen1f1b20f2016-02-29 17:05:00 -05006977 if (priv->ep_tx_normal_queue)
6978 val8 = TX_PAGE_NUM_NORM_PQ;
6979 else
6980 val8 = 0;
6981
6982 rtl8xxxu_write8(priv, REG_RQPN_NPQ, val8);
6983
6984 val32 = (TX_PAGE_NUM_PUBQ << RQPN_NORM_PQ_SHIFT) | RQPN_LOAD;
6985
6986 if (priv->ep_tx_high_queue)
6987 val32 |= (TX_PAGE_NUM_HI_PQ << RQPN_HI_PQ_SHIFT);
6988 if (priv->ep_tx_low_queue)
6989 val32 |= (TX_PAGE_NUM_LO_PQ << RQPN_LO_PQ_SHIFT);
6990
6991 rtl8xxxu_write32(priv, REG_RQPN, val32);
6992
6993 /*
6994 * Set TX buffer boundary
6995 */
Jes Sorensen80805aa2016-04-07 14:19:18 -04006996 if (priv->rtl_chip == RTL8192E)
6997 val8 = TX_TOTAL_PAGE_NUM_8192E + 1;
6998 else
6999 val8 = TX_TOTAL_PAGE_NUM + 1;
Jes Sorensen1f1b20f2016-02-29 17:05:00 -05007000
Jes Sorensenba17d822016-03-31 17:08:39 -04007001 if (priv->rtl_chip == RTL8723B)
Jes Sorensen1f1b20f2016-02-29 17:05:00 -05007002 val8 -= 1;
7003
7004 rtl8xxxu_write8(priv, REG_TXPKTBUF_BCNQ_BDNY, val8);
7005 rtl8xxxu_write8(priv, REG_TXPKTBUF_MGQ_BDNY, val8);
7006 rtl8xxxu_write8(priv, REG_TXPKTBUF_WMAC_LBK_BF_HD, val8);
7007 rtl8xxxu_write8(priv, REG_TRXFF_BNDY, val8);
7008 rtl8xxxu_write8(priv, REG_TDECTRL + 1, val8);
7009 }
7010
7011 ret = rtl8xxxu_init_queue_priority(priv);
7012 dev_dbg(dev, "%s: init_queue_priority %i\n", __func__, ret);
7013 if (ret)
7014 goto exit;
7015
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007016 /* RFSW Control - clear bit 14 ?? */
Jes Sorensenba17d822016-03-31 17:08:39 -04007017 if (priv->rtl_chip != RTL8723B)
Jes Sorensenb87212c2016-02-29 17:05:01 -05007018 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, 0x00000003);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007019 /* 0x07000760 */
7020 val32 = FPGA0_RF_TRSW | FPGA0_RF_TRSWB | FPGA0_RF_ANTSW |
7021 FPGA0_RF_ANTSWB | FPGA0_RF_PAPE |
7022 ((FPGA0_RF_ANTSW | FPGA0_RF_ANTSWB | FPGA0_RF_PAPE) <<
7023 FPGA0_RF_BD_CTRL_SHIFT);
7024 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
7025 /* 0x860[6:5]= 00 - why? - this sets antenna B */
7026 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, 0x66F60210);
7027
7028 priv->rf_mode_ag[0] = rtl8xxxu_read_rfreg(priv, RF_A,
7029 RF6052_REG_MODE_AG);
7030
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007031 /*
7032 * Set RX page boundary
7033 */
Jes Sorensenba17d822016-03-31 17:08:39 -04007034 if (priv->rtl_chip == RTL8723B)
Jes Sorensenfadfa042016-02-29 17:05:02 -05007035 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x3f7f);
Jes Sorensen80805aa2016-04-07 14:19:18 -04007036 else if (priv->rtl_chip == RTL8192E)
7037 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x3cff);
Jes Sorensenfadfa042016-02-29 17:05:02 -05007038 else
7039 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x27ff);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007040 /*
7041 * Transfer page size is always 128
7042 */
Jes Sorensenba17d822016-03-31 17:08:39 -04007043 if (priv->rtl_chip == RTL8723B)
Jes Sorensenb87212c2016-02-29 17:05:01 -05007044 val8 = (PBP_PAGE_SIZE_256 << PBP_PAGE_SIZE_RX_SHIFT) |
7045 (PBP_PAGE_SIZE_256 << PBP_PAGE_SIZE_TX_SHIFT);
7046 else
7047 val8 = (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_RX_SHIFT) |
7048 (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_TX_SHIFT);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007049 rtl8xxxu_write8(priv, REG_PBP, val8);
7050
7051 /*
7052 * Unit in 8 bytes, not obvious what it is used for
7053 */
7054 rtl8xxxu_write8(priv, REG_RX_DRVINFO_SZ, 4);
7055
7056 /*
7057 * Enable all interrupts - not obvious USB needs to do this
7058 */
7059 rtl8xxxu_write32(priv, REG_HISR, 0xffffffff);
7060 rtl8xxxu_write32(priv, REG_HIMR, 0xffffffff);
7061
7062 rtl8xxxu_set_mac(priv);
7063 rtl8xxxu_set_linktype(priv, NL80211_IFTYPE_STATION);
7064
7065 /*
7066 * Configure initial WMAC settings
7067 */
7068 val32 = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_MCAST | RCR_ACCEPT_BCAST |
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007069 RCR_ACCEPT_MGMT_FRAME | RCR_HTC_LOC_CTRL |
7070 RCR_APPEND_PHYSTAT | RCR_APPEND_ICV | RCR_APPEND_MIC;
7071 rtl8xxxu_write32(priv, REG_RCR, val32);
7072
7073 /*
7074 * Accept all multicast
7075 */
7076 rtl8xxxu_write32(priv, REG_MAR, 0xffffffff);
7077 rtl8xxxu_write32(priv, REG_MAR + 4, 0xffffffff);
7078
7079 /*
7080 * Init adaptive controls
7081 */
7082 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
7083 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
7084 val32 |= RESPONSE_RATE_RRSR_CCK_ONLY_1M;
7085 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
7086
7087 /* CCK = 0x0a, OFDM = 0x10 */
7088 rtl8xxxu_set_spec_sifs(priv, 0x10, 0x10);
7089 rtl8xxxu_set_retry(priv, 0x30, 0x30);
7090 rtl8xxxu_set_spec_sifs(priv, 0x0a, 0x10);
7091
7092 /*
7093 * Init EDCA
7094 */
7095 rtl8xxxu_write16(priv, REG_MAC_SPEC_SIFS, 0x100a);
7096
7097 /* Set CCK SIFS */
7098 rtl8xxxu_write16(priv, REG_SIFS_CCK, 0x100a);
7099
7100 /* Set OFDM SIFS */
7101 rtl8xxxu_write16(priv, REG_SIFS_OFDM, 0x100a);
7102
7103 /* TXOP */
7104 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, 0x005ea42b);
7105 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, 0x0000a44f);
7106 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, 0x005ea324);
7107 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, 0x002fa226);
7108
7109 /* Set data auto rate fallback retry count */
7110 rtl8xxxu_write32(priv, REG_DARFRC, 0x00000000);
7111 rtl8xxxu_write32(priv, REG_DARFRC + 4, 0x10080404);
7112 rtl8xxxu_write32(priv, REG_RARFRC, 0x04030201);
7113 rtl8xxxu_write32(priv, REG_RARFRC + 4, 0x08070605);
7114
7115 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL);
7116 val8 |= FWHW_TXQ_CTRL_AMPDU_RETRY;
7117 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, val8);
7118
7119 /* Set ACK timeout */
7120 rtl8xxxu_write8(priv, REG_ACKTO, 0x40);
7121
7122 /*
7123 * Initialize beacon parameters
7124 */
7125 val16 = BEACON_DISABLE_TSF_UPDATE | (BEACON_DISABLE_TSF_UPDATE << 8);
7126 rtl8xxxu_write16(priv, REG_BEACON_CTRL, val16);
7127 rtl8xxxu_write16(priv, REG_TBTT_PROHIBIT, 0x6404);
7128 rtl8xxxu_write8(priv, REG_DRIVER_EARLY_INT, DRIVER_EARLY_INT_TIME);
7129 rtl8xxxu_write8(priv, REG_BEACON_DMA_TIME, BEACON_DMA_ATIME_INT_TIME);
7130 rtl8xxxu_write16(priv, REG_BEACON_TCFG, 0x660F);
7131
7132 /*
Jes Sorensenc3690602016-02-29 17:05:03 -05007133 * Initialize burst parameters
7134 */
Jes Sorensenba17d822016-03-31 17:08:39 -04007135 if (priv->rtl_chip == RTL8723B) {
Jes Sorensenc3690602016-02-29 17:05:03 -05007136 /*
7137 * For USB high speed set 512B packets
7138 */
7139 val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
7140 val8 &= ~(BIT(4) | BIT(5));
7141 val8 |= BIT(4);
7142 val8 |= BIT(1) | BIT(2) | BIT(3);
7143 rtl8xxxu_write8(priv, REG_RXDMA_PRO_8723B, val8);
7144
7145 /*
7146 * For USB high speed set 512B packets
7147 */
7148 val8 = rtl8xxxu_read8(priv, REG_HT_SINGLE_AMPDU_8723B);
7149 val8 |= BIT(7);
7150 rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8);
7151
7152 rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14);
7153 rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, 0x5e);
7154 rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff);
7155 rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18);
7156 rtl8xxxu_write8(priv, REG_PIFS, 0x00);
7157 rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, 0x50);
7158 rtl8xxxu_write8(priv, REG_USTIME_EDCA, 0x50);
7159
7160 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
7161 val8 |= BIT(5) | BIT(6);
7162 rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
7163 }
7164
Jes Sorensen3e88ca42016-02-29 17:05:08 -05007165 if (priv->fops->init_aggregation)
7166 priv->fops->init_aggregation(priv);
7167
Jes Sorensenc3690602016-02-29 17:05:03 -05007168 /*
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007169 * Enable CCK and OFDM block
7170 */
7171 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
7172 val32 |= (FPGA_RF_MODE_CCK | FPGA_RF_MODE_OFDM);
7173 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
7174
7175 /*
7176 * Invalidate all CAM entries - bit 30 is undocumented
7177 */
7178 rtl8xxxu_write32(priv, REG_CAM_CMD, CAM_CMD_POLLING | BIT(30));
7179
7180 /*
7181 * Start out with default power levels for channel 6, 20MHz
7182 */
Jes Sorensene796dab2016-02-29 17:05:19 -05007183 priv->fops->set_tx_power(priv, 1, false);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007184
7185 /* Let the 8051 take control of antenna setting */
7186 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
7187 val8 |= LEDCFG2_DPDT_SELECT;
7188 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
7189
7190 rtl8xxxu_write8(priv, REG_HWSEQ_CTRL, 0xff);
7191
7192 /* Disable BAR - not sure if this has any effect on USB */
7193 rtl8xxxu_write32(priv, REG_BAR_MODE_CTRL, 0x0201ffff);
7194
7195 rtl8xxxu_write16(priv, REG_FAST_EDCA_CTRL, 0);
7196
Jes Sorensen9c79bf92016-02-29 17:05:10 -05007197 if (priv->fops->init_statistics)
7198 priv->fops->init_statistics(priv);
7199
Jes Sorensenfa0f2d42016-02-29 17:04:37 -05007200 rtl8723a_phy_lc_calibrate(priv);
7201
Jes Sorensene1547c52016-02-29 17:04:35 -05007202 priv->fops->phy_iq_calibrate(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007203
7204 /*
7205 * This should enable thermal meter
7206 */
Jes Sorensen72143b92016-02-29 17:05:25 -05007207 if (priv->fops->has_s0s1)
7208 rtl8xxxu_write_rfreg(priv,
7209 RF_A, RF6052_REG_T_METER_8723B, 0x37cf8);
7210 else
7211 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_T_METER, 0x60);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007212
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007213 /* Set NAV_UPPER to 30000us */
7214 val8 = ((30000 + NAV_UPPER_UNIT - 1) / NAV_UPPER_UNIT);
7215 rtl8xxxu_write8(priv, REG_NAV_UPPER, val8);
7216
Jes Sorensenba17d822016-03-31 17:08:39 -04007217 if (priv->rtl_chip == RTL8723A) {
Jes Sorensen4042e612016-02-03 13:40:01 -05007218 /*
7219 * 2011/03/09 MH debug only, UMC-B cut pass 2500 S5 test,
7220 * but we need to find root cause.
7221 * This is 8723au only.
7222 */
7223 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
7224 if ((val32 & 0xff000000) != 0x83000000) {
7225 val32 |= FPGA_RF_MODE_CCK;
7226 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
7227 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007228 }
7229
7230 val32 = rtl8xxxu_read32(priv, REG_FWHW_TXQ_CTRL);
7231 val32 |= FWHW_TXQ_CTRL_XMIT_MGMT_ACK;
7232 /* ack for xmit mgmt frames. */
7233 rtl8xxxu_write32(priv, REG_FWHW_TXQ_CTRL, val32);
7234
7235exit:
7236 return ret;
7237}
7238
7239static void rtl8xxxu_disable_device(struct ieee80211_hw *hw)
7240{
7241 struct rtl8xxxu_priv *priv = hw->priv;
7242
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05007243 priv->fops->power_off(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007244}
7245
7246static void rtl8xxxu_cam_write(struct rtl8xxxu_priv *priv,
7247 struct ieee80211_key_conf *key, const u8 *mac)
7248{
7249 u32 cmd, val32, addr, ctrl;
7250 int j, i, tmp_debug;
7251
7252 tmp_debug = rtl8xxxu_debug;
7253 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_KEY)
7254 rtl8xxxu_debug |= RTL8XXXU_DEBUG_REG_WRITE;
7255
7256 /*
7257 * This is a bit of a hack - the lower bits of the cipher
7258 * suite selector happens to match the cipher index in the CAM
7259 */
7260 addr = key->keyidx << CAM_CMD_KEY_SHIFT;
7261 ctrl = (key->cipher & 0x0f) << 2 | key->keyidx | CAM_WRITE_VALID;
7262
7263 for (j = 5; j >= 0; j--) {
7264 switch (j) {
7265 case 0:
7266 val32 = ctrl | (mac[0] << 16) | (mac[1] << 24);
7267 break;
7268 case 1:
7269 val32 = mac[2] | (mac[3] << 8) |
7270 (mac[4] << 16) | (mac[5] << 24);
7271 break;
7272 default:
7273 i = (j - 2) << 2;
7274 val32 = key->key[i] | (key->key[i + 1] << 8) |
7275 key->key[i + 2] << 16 | key->key[i + 3] << 24;
7276 break;
7277 }
7278
7279 rtl8xxxu_write32(priv, REG_CAM_WRITE, val32);
7280 cmd = CAM_CMD_POLLING | CAM_CMD_WRITE | (addr + j);
7281 rtl8xxxu_write32(priv, REG_CAM_CMD, cmd);
7282 udelay(100);
7283 }
7284
7285 rtl8xxxu_debug = tmp_debug;
7286}
7287
7288static void rtl8xxxu_sw_scan_start(struct ieee80211_hw *hw,
Jes Sorensen56e43742016-02-03 13:39:50 -05007289 struct ieee80211_vif *vif, const u8 *mac)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007290{
7291 struct rtl8xxxu_priv *priv = hw->priv;
7292 u8 val8;
7293
7294 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
7295 val8 |= BEACON_DISABLE_TSF_UPDATE;
7296 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
7297}
7298
7299static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw,
7300 struct ieee80211_vif *vif)
7301{
7302 struct rtl8xxxu_priv *priv = hw->priv;
7303 u8 val8;
7304
7305 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
7306 val8 &= ~BEACON_DISABLE_TSF_UPDATE;
7307 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
7308}
7309
Jes Sorensenf653e692016-02-29 17:05:38 -05007310static void rtl8723au_update_rate_mask(struct rtl8xxxu_priv *priv,
7311 u32 ramask, int sgi)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007312{
7313 struct h2c_cmd h2c;
7314
Jes Sorensenf653e692016-02-29 17:05:38 -05007315 memset(&h2c, 0, sizeof(struct h2c_cmd));
7316
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007317 h2c.ramask.cmd = H2C_SET_RATE_MASK;
7318 h2c.ramask.mask_lo = cpu_to_le16(ramask & 0xffff);
7319 h2c.ramask.mask_hi = cpu_to_le16(ramask >> 16);
7320
7321 h2c.ramask.arg = 0x80;
7322 if (sgi)
7323 h2c.ramask.arg |= 0x20;
7324
Jes Sorensen7ff8c1a2016-02-29 17:04:32 -05007325 dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n",
Jes Sorensen8da91572016-02-29 17:04:29 -05007326 __func__, ramask, h2c.ramask.arg, sizeof(h2c.ramask));
7327 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ramask));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007328}
7329
Jes Sorensenf653e692016-02-29 17:05:38 -05007330static void rtl8723bu_update_rate_mask(struct rtl8xxxu_priv *priv,
7331 u32 ramask, int sgi)
7332{
7333 struct h2c_cmd h2c;
7334 u8 bw = 0;
7335
7336 memset(&h2c, 0, sizeof(struct h2c_cmd));
7337
7338 h2c.b_macid_cfg.cmd = H2C_8723B_MACID_CFG_RAID;
7339 h2c.b_macid_cfg.ramask0 = ramask & 0xff;
7340 h2c.b_macid_cfg.ramask1 = (ramask >> 8) & 0xff;
7341 h2c.b_macid_cfg.ramask2 = (ramask >> 16) & 0xff;
7342 h2c.b_macid_cfg.ramask3 = (ramask >> 24) & 0xff;
7343
7344 h2c.ramask.arg = 0x80;
7345 h2c.b_macid_cfg.data1 = 0;
7346 if (sgi)
7347 h2c.b_macid_cfg.data1 |= BIT(7);
7348
7349 h2c.b_macid_cfg.data2 = bw;
7350
7351 dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n",
7352 __func__, ramask, h2c.ramask.arg, sizeof(h2c.b_macid_cfg));
7353 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.b_macid_cfg));
7354}
7355
Jes Sorensen7d794ea2016-02-29 17:05:39 -05007356static void rtl8723au_report_connect(struct rtl8xxxu_priv *priv,
7357 u8 macid, bool connect)
7358{
7359 struct h2c_cmd h2c;
7360
7361 memset(&h2c, 0, sizeof(struct h2c_cmd));
7362
7363 h2c.joinbss.cmd = H2C_JOIN_BSS_REPORT;
7364
7365 if (connect)
7366 h2c.joinbss.data = H2C_JOIN_BSS_CONNECT;
7367 else
7368 h2c.joinbss.data = H2C_JOIN_BSS_DISCONNECT;
7369
7370 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.joinbss));
7371}
7372
7373static void rtl8723bu_report_connect(struct rtl8xxxu_priv *priv,
7374 u8 macid, bool connect)
7375{
7376 struct h2c_cmd h2c;
7377
7378 memset(&h2c, 0, sizeof(struct h2c_cmd));
7379
7380 h2c.media_status_rpt.cmd = H2C_8723B_MEDIA_STATUS_RPT;
7381 if (connect)
7382 h2c.media_status_rpt.parm |= BIT(0);
7383 else
7384 h2c.media_status_rpt.parm &= ~BIT(0);
7385
7386 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.media_status_rpt));
7387}
7388
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007389static void rtl8xxxu_set_basic_rates(struct rtl8xxxu_priv *priv, u32 rate_cfg)
7390{
7391 u32 val32;
7392 u8 rate_idx = 0;
7393
7394 rate_cfg &= RESPONSE_RATE_BITMAP_ALL;
7395
7396 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
7397 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
7398 val32 |= rate_cfg;
7399 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
7400
7401 dev_dbg(&priv->udev->dev, "%s: rates %08x\n", __func__, rate_cfg);
7402
7403 while (rate_cfg) {
7404 rate_cfg = (rate_cfg >> 1);
7405 rate_idx++;
7406 }
7407 rtl8xxxu_write8(priv, REG_INIRTS_RATE_SEL, rate_idx);
7408}
7409
7410static void
7411rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7412 struct ieee80211_bss_conf *bss_conf, u32 changed)
7413{
7414 struct rtl8xxxu_priv *priv = hw->priv;
7415 struct device *dev = &priv->udev->dev;
7416 struct ieee80211_sta *sta;
7417 u32 val32;
7418 u8 val8;
7419
7420 if (changed & BSS_CHANGED_ASSOC) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007421 dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc);
7422
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007423 rtl8xxxu_set_linktype(priv, vif->type);
7424
7425 if (bss_conf->assoc) {
7426 u32 ramask;
7427 int sgi = 0;
7428
7429 rcu_read_lock();
7430 sta = ieee80211_find_sta(vif, bss_conf->bssid);
7431 if (!sta) {
7432 dev_info(dev, "%s: ASSOC no sta found\n",
7433 __func__);
7434 rcu_read_unlock();
7435 goto error;
7436 }
7437
7438 if (sta->ht_cap.ht_supported)
7439 dev_info(dev, "%s: HT supported\n", __func__);
7440 if (sta->vht_cap.vht_supported)
7441 dev_info(dev, "%s: VHT supported\n", __func__);
7442
7443 /* TODO: Set bits 28-31 for rate adaptive id */
7444 ramask = (sta->supp_rates[0] & 0xfff) |
7445 sta->ht_cap.mcs.rx_mask[0] << 12 |
7446 sta->ht_cap.mcs.rx_mask[1] << 20;
7447 if (sta->ht_cap.cap &
7448 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))
7449 sgi = 1;
7450 rcu_read_unlock();
7451
Jes Sorensenf653e692016-02-29 17:05:38 -05007452 priv->fops->update_rate_mask(priv, ramask, sgi);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007453
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007454 rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
7455
7456 rtl8723a_stop_tx_beacon(priv);
7457
7458 /* joinbss sequence */
7459 rtl8xxxu_write16(priv, REG_BCN_PSR_RPT,
7460 0xc000 | bss_conf->aid);
7461
Jes Sorensen7d794ea2016-02-29 17:05:39 -05007462 priv->fops->report_connect(priv, 0, true);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007463 } else {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007464 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
7465 val8 |= BEACON_DISABLE_TSF_UPDATE;
7466 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
7467
Jes Sorensen7d794ea2016-02-29 17:05:39 -05007468 priv->fops->report_connect(priv, 0, false);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007469 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007470 }
7471
7472 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
7473 dev_dbg(dev, "Changed ERP_PREAMBLE: Use short preamble %i\n",
7474 bss_conf->use_short_preamble);
7475 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
7476 if (bss_conf->use_short_preamble)
7477 val32 |= RSR_ACK_SHORT_PREAMBLE;
7478 else
7479 val32 &= ~RSR_ACK_SHORT_PREAMBLE;
7480 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
7481 }
7482
7483 if (changed & BSS_CHANGED_ERP_SLOT) {
7484 dev_dbg(dev, "Changed ERP_SLOT: short_slot_time %i\n",
7485 bss_conf->use_short_slot);
7486
7487 if (bss_conf->use_short_slot)
7488 val8 = 9;
7489 else
7490 val8 = 20;
7491 rtl8xxxu_write8(priv, REG_SLOT, val8);
7492 }
7493
7494 if (changed & BSS_CHANGED_BSSID) {
7495 dev_dbg(dev, "Changed BSSID!\n");
7496 rtl8xxxu_set_bssid(priv, bss_conf->bssid);
7497 }
7498
7499 if (changed & BSS_CHANGED_BASIC_RATES) {
7500 dev_dbg(dev, "Changed BASIC_RATES!\n");
7501 rtl8xxxu_set_basic_rates(priv, bss_conf->basic_rates);
7502 }
7503error:
7504 return;
7505}
7506
7507static u32 rtl8xxxu_80211_to_rtl_queue(u32 queue)
7508{
7509 u32 rtlqueue;
7510
7511 switch (queue) {
7512 case IEEE80211_AC_VO:
7513 rtlqueue = TXDESC_QUEUE_VO;
7514 break;
7515 case IEEE80211_AC_VI:
7516 rtlqueue = TXDESC_QUEUE_VI;
7517 break;
7518 case IEEE80211_AC_BE:
7519 rtlqueue = TXDESC_QUEUE_BE;
7520 break;
7521 case IEEE80211_AC_BK:
7522 rtlqueue = TXDESC_QUEUE_BK;
7523 break;
7524 default:
7525 rtlqueue = TXDESC_QUEUE_BE;
7526 }
7527
7528 return rtlqueue;
7529}
7530
7531static u32 rtl8xxxu_queue_select(struct ieee80211_hw *hw, struct sk_buff *skb)
7532{
7533 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
7534 u32 queue;
7535
7536 if (ieee80211_is_mgmt(hdr->frame_control))
7537 queue = TXDESC_QUEUE_MGNT;
7538 else
7539 queue = rtl8xxxu_80211_to_rtl_queue(skb_get_queue_mapping(skb));
7540
7541 return queue;
7542}
7543
Jes Sorensen179e1742016-02-29 17:05:27 -05007544/*
7545 * Despite newer chips 8723b/8812/8821 having a larger TX descriptor
7546 * format. The descriptor checksum is still only calculated over the
7547 * initial 32 bytes of the descriptor!
7548 */
Jes Sorensendbb28962016-03-31 17:08:33 -04007549static void rtl8xxxu_calc_tx_desc_csum(struct rtl8xxxu_txdesc32 *tx_desc)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007550{
7551 __le16 *ptr = (__le16 *)tx_desc;
7552 u16 csum = 0;
7553 int i;
7554
7555 /*
7556 * Clear csum field before calculation, as the csum field is
7557 * in the middle of the struct.
7558 */
7559 tx_desc->csum = cpu_to_le16(0);
7560
Jes Sorensendbb28962016-03-31 17:08:33 -04007561 for (i = 0; i < (sizeof(struct rtl8xxxu_txdesc32) / sizeof(u16)); i++)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007562 csum = csum ^ le16_to_cpu(ptr[i]);
7563
7564 tx_desc->csum |= cpu_to_le16(csum);
7565}
7566
7567static void rtl8xxxu_free_tx_resources(struct rtl8xxxu_priv *priv)
7568{
7569 struct rtl8xxxu_tx_urb *tx_urb, *tmp;
7570 unsigned long flags;
7571
7572 spin_lock_irqsave(&priv->tx_urb_lock, flags);
7573 list_for_each_entry_safe(tx_urb, tmp, &priv->tx_urb_free_list, list) {
7574 list_del(&tx_urb->list);
7575 priv->tx_urb_free_count--;
7576 usb_free_urb(&tx_urb->urb);
7577 }
7578 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
7579}
7580
7581static struct rtl8xxxu_tx_urb *
7582rtl8xxxu_alloc_tx_urb(struct rtl8xxxu_priv *priv)
7583{
7584 struct rtl8xxxu_tx_urb *tx_urb;
7585 unsigned long flags;
7586
7587 spin_lock_irqsave(&priv->tx_urb_lock, flags);
7588 tx_urb = list_first_entry_or_null(&priv->tx_urb_free_list,
7589 struct rtl8xxxu_tx_urb, list);
7590 if (tx_urb) {
7591 list_del(&tx_urb->list);
7592 priv->tx_urb_free_count--;
7593 if (priv->tx_urb_free_count < RTL8XXXU_TX_URB_LOW_WATER &&
7594 !priv->tx_stopped) {
7595 priv->tx_stopped = true;
7596 ieee80211_stop_queues(priv->hw);
7597 }
7598 }
7599
7600 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
7601
7602 return tx_urb;
7603}
7604
7605static void rtl8xxxu_free_tx_urb(struct rtl8xxxu_priv *priv,
7606 struct rtl8xxxu_tx_urb *tx_urb)
7607{
7608 unsigned long flags;
7609
7610 INIT_LIST_HEAD(&tx_urb->list);
7611
7612 spin_lock_irqsave(&priv->tx_urb_lock, flags);
7613
7614 list_add(&tx_urb->list, &priv->tx_urb_free_list);
7615 priv->tx_urb_free_count++;
7616 if (priv->tx_urb_free_count > RTL8XXXU_TX_URB_HIGH_WATER &&
7617 priv->tx_stopped) {
7618 priv->tx_stopped = false;
7619 ieee80211_wake_queues(priv->hw);
7620 }
7621
7622 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
7623}
7624
7625static void rtl8xxxu_tx_complete(struct urb *urb)
7626{
7627 struct sk_buff *skb = (struct sk_buff *)urb->context;
7628 struct ieee80211_tx_info *tx_info;
7629 struct ieee80211_hw *hw;
Jes Sorensen179e1742016-02-29 17:05:27 -05007630 struct rtl8xxxu_priv *priv;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007631 struct rtl8xxxu_tx_urb *tx_urb =
7632 container_of(urb, struct rtl8xxxu_tx_urb, urb);
7633
7634 tx_info = IEEE80211_SKB_CB(skb);
7635 hw = tx_info->rate_driver_data[0];
Jes Sorensen179e1742016-02-29 17:05:27 -05007636 priv = hw->priv;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007637
Jes Sorensen179e1742016-02-29 17:05:27 -05007638 skb_pull(skb, priv->fops->tx_desc_size);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007639
7640 ieee80211_tx_info_clear_status(tx_info);
7641 tx_info->status.rates[0].idx = -1;
7642 tx_info->status.rates[0].count = 0;
7643
7644 if (!urb->status)
7645 tx_info->flags |= IEEE80211_TX_STAT_ACK;
7646
7647 ieee80211_tx_status_irqsafe(hw, skb);
7648
Jes Sorensen179e1742016-02-29 17:05:27 -05007649 rtl8xxxu_free_tx_urb(priv, tx_urb);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007650}
7651
7652static void rtl8xxxu_dump_action(struct device *dev,
7653 struct ieee80211_hdr *hdr)
7654{
7655 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
7656 u16 cap, timeout;
7657
7658 if (!(rtl8xxxu_debug & RTL8XXXU_DEBUG_ACTION))
7659 return;
7660
7661 switch (mgmt->u.action.u.addba_resp.action_code) {
7662 case WLAN_ACTION_ADDBA_RESP:
7663 cap = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
7664 timeout = le16_to_cpu(mgmt->u.action.u.addba_resp.timeout);
7665 dev_info(dev, "WLAN_ACTION_ADDBA_RESP: "
7666 "timeout %i, tid %02x, buf_size %02x, policy %02x, "
7667 "status %02x\n",
7668 timeout,
7669 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
7670 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
7671 (cap >> 1) & 0x1,
7672 le16_to_cpu(mgmt->u.action.u.addba_resp.status));
7673 break;
7674 case WLAN_ACTION_ADDBA_REQ:
7675 cap = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
7676 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
7677 dev_info(dev, "WLAN_ACTION_ADDBA_REQ: "
7678 "timeout %i, tid %02x, buf_size %02x, policy %02x\n",
7679 timeout,
7680 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
7681 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
7682 (cap >> 1) & 0x1);
7683 break;
7684 default:
7685 dev_info(dev, "action frame %02x\n",
7686 mgmt->u.action.u.addba_resp.action_code);
7687 break;
7688 }
7689}
7690
7691static void rtl8xxxu_tx(struct ieee80211_hw *hw,
7692 struct ieee80211_tx_control *control,
7693 struct sk_buff *skb)
7694{
7695 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
7696 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
7697 struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
7698 struct rtl8xxxu_priv *priv = hw->priv;
Jes Sorensendbb28962016-03-31 17:08:33 -04007699 struct rtl8xxxu_txdesc32 *tx_desc;
7700 struct rtl8xxxu_txdesc40 *tx_desc40;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007701 struct rtl8xxxu_tx_urb *tx_urb;
7702 struct ieee80211_sta *sta = NULL;
7703 struct ieee80211_vif *vif = tx_info->control.vif;
7704 struct device *dev = &priv->udev->dev;
7705 u32 queue, rate;
7706 u16 pktlen = skb->len;
7707 u16 seq_number;
7708 u16 rate_flag = tx_info->control.rates[0].flags;
Jes Sorensen179e1742016-02-29 17:05:27 -05007709 int tx_desc_size = priv->fops->tx_desc_size;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007710 int ret;
Jes Sorensencc2646d2016-02-29 17:05:32 -05007711 bool usedesc40, ampdu_enable;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007712
Jes Sorensen179e1742016-02-29 17:05:27 -05007713 if (skb_headroom(skb) < tx_desc_size) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007714 dev_warn(dev,
7715 "%s: Not enough headroom (%i) for tx descriptor\n",
7716 __func__, skb_headroom(skb));
7717 goto error;
7718 }
7719
Jes Sorensen179e1742016-02-29 17:05:27 -05007720 if (unlikely(skb->len > (65535 - tx_desc_size))) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007721 dev_warn(dev, "%s: Trying to send over-sized skb (%i)\n",
7722 __func__, skb->len);
7723 goto error;
7724 }
7725
7726 tx_urb = rtl8xxxu_alloc_tx_urb(priv);
7727 if (!tx_urb) {
7728 dev_warn(dev, "%s: Unable to allocate tx urb\n", __func__);
7729 goto error;
7730 }
7731
7732 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
7733 dev_info(dev, "%s: TX rate: %d (%d), pkt size %d\n",
7734 __func__, tx_rate->bitrate, tx_rate->hw_value, pktlen);
7735
7736 if (ieee80211_is_action(hdr->frame_control))
7737 rtl8xxxu_dump_action(dev, hdr);
7738
Jes Sorensencc2646d2016-02-29 17:05:32 -05007739 usedesc40 = (tx_desc_size == 40);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007740 tx_info->rate_driver_data[0] = hw;
7741
7742 if (control && control->sta)
7743 sta = control->sta;
7744
Jes Sorensendbb28962016-03-31 17:08:33 -04007745 tx_desc = (struct rtl8xxxu_txdesc32 *)skb_push(skb, tx_desc_size);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007746
Jes Sorensen179e1742016-02-29 17:05:27 -05007747 memset(tx_desc, 0, tx_desc_size);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007748 tx_desc->pkt_size = cpu_to_le16(pktlen);
Jes Sorensen179e1742016-02-29 17:05:27 -05007749 tx_desc->pkt_offset = tx_desc_size;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007750
7751 tx_desc->txdw0 =
7752 TXDESC_OWN | TXDESC_FIRST_SEGMENT | TXDESC_LAST_SEGMENT;
7753 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
7754 is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
7755 tx_desc->txdw0 |= TXDESC_BROADMULTICAST;
7756
7757 queue = rtl8xxxu_queue_select(hw, skb);
7758 tx_desc->txdw1 = cpu_to_le32(queue << TXDESC_QUEUE_SHIFT);
7759
7760 if (tx_info->control.hw_key) {
7761 switch (tx_info->control.hw_key->cipher) {
7762 case WLAN_CIPHER_SUITE_WEP40:
7763 case WLAN_CIPHER_SUITE_WEP104:
7764 case WLAN_CIPHER_SUITE_TKIP:
7765 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_RC4);
7766 break;
7767 case WLAN_CIPHER_SUITE_CCMP:
7768 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_AES);
7769 break;
7770 default:
7771 break;
7772 }
7773 }
7774
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007775 /* (tx_info->flags & IEEE80211_TX_CTL_AMPDU) && */
Jes Sorensena40ace42016-02-29 17:05:31 -05007776 ampdu_enable = false;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007777 if (ieee80211_is_data_qos(hdr->frame_control) && sta) {
7778 if (sta->ht_cap.ht_supported) {
7779 u32 ampdu, val32;
7780
7781 ampdu = (u32)sta->ht_cap.ampdu_density;
7782 val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT;
7783 tx_desc->txdw2 |= cpu_to_le32(val32);
Jes Sorensence2d1db2016-02-29 17:05:30 -05007784
Jes Sorensena40ace42016-02-29 17:05:31 -05007785 ampdu_enable = true;
7786 }
7787 }
7788
Jes Sorensen4c683602016-02-29 17:05:35 -05007789 if (rate_flag & IEEE80211_TX_RC_MCS)
7790 rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
7791 else
7792 rate = tx_rate->hw_value;
7793
Jes Sorensencc2646d2016-02-29 17:05:32 -05007794 seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
7795 if (!usedesc40) {
Jes Sorensen4c683602016-02-29 17:05:35 -05007796 tx_desc->txdw5 = cpu_to_le32(rate);
7797
7798 if (ieee80211_is_data(hdr->frame_control))
7799 tx_desc->txdw5 |= cpu_to_le32(0x0001ff00);
7800
Jes Sorensencc2646d2016-02-29 17:05:32 -05007801 tx_desc->txdw3 =
Jes Sorensen33f37242016-03-31 17:08:34 -04007802 cpu_to_le32((u32)seq_number << TXDESC32_SEQ_SHIFT);
Jes Sorensencc2646d2016-02-29 17:05:32 -05007803
Jes Sorensena40ace42016-02-29 17:05:31 -05007804 if (ampdu_enable)
Jes Sorensen33f37242016-03-31 17:08:34 -04007805 tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_ENABLE);
Jes Sorensena40ace42016-02-29 17:05:31 -05007806 else
Jes Sorensen33f37242016-03-31 17:08:34 -04007807 tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_BREAK);
Jes Sorensen4c683602016-02-29 17:05:35 -05007808
7809 if (ieee80211_is_mgmt(hdr->frame_control)) {
7810 tx_desc->txdw5 = cpu_to_le32(tx_rate->hw_value);
7811 tx_desc->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007812 cpu_to_le32(TXDESC32_USE_DRIVER_RATE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007813 tx_desc->txdw5 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007814 cpu_to_le32(6 << TXDESC32_RETRY_LIMIT_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007815 tx_desc->txdw5 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007816 cpu_to_le32(TXDESC32_RETRY_LIMIT_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007817 }
7818
7819 if (ieee80211_is_data_qos(hdr->frame_control))
Jes Sorensen33f37242016-03-31 17:08:34 -04007820 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_QOS);
Jes Sorensen4c683602016-02-29 17:05:35 -05007821
7822 if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ||
7823 (sta && vif && vif->bss_conf.use_short_preamble))
Jes Sorensen33f37242016-03-31 17:08:34 -04007824 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_SHORT_PREAMBLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007825
7826 if (rate_flag & IEEE80211_TX_RC_SHORT_GI ||
7827 (ieee80211_is_data_qos(hdr->frame_control) &&
7828 sta && sta->ht_cap.cap &
7829 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))) {
Jes Sorensen1df1de32016-03-31 17:08:36 -04007830 tx_desc->txdw5 |= cpu_to_le32(TXDESC32_SHORT_GI);
Jes Sorensen4c683602016-02-29 17:05:35 -05007831 }
7832
7833 if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
7834 /*
7835 * Use RTS rate 24M - does the mac80211 tell
7836 * us which to use?
7837 */
7838 tx_desc->txdw4 |=
7839 cpu_to_le32(DESC_RATE_24M <<
Jes Sorensen33f37242016-03-31 17:08:34 -04007840 TXDESC32_RTS_RATE_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007841 tx_desc->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007842 cpu_to_le32(TXDESC32_RTS_CTS_ENABLE);
7843 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_HW_RTS_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007844 }
Jes Sorensena40ace42016-02-29 17:05:31 -05007845 } else {
Jes Sorensendbb28962016-03-31 17:08:33 -04007846 tx_desc40 = (struct rtl8xxxu_txdesc40 *)tx_desc;
Jes Sorensencc2646d2016-02-29 17:05:32 -05007847
Jes Sorensen4c683602016-02-29 17:05:35 -05007848 tx_desc40->txdw4 = cpu_to_le32(rate);
7849 if (ieee80211_is_data(hdr->frame_control)) {
7850 tx_desc->txdw4 |=
7851 cpu_to_le32(0x1f <<
Jes Sorensen33f37242016-03-31 17:08:34 -04007852 TXDESC40_DATA_RATE_FB_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007853 }
7854
Jes Sorensencc2646d2016-02-29 17:05:32 -05007855 tx_desc40->txdw9 =
Jes Sorensen33f37242016-03-31 17:08:34 -04007856 cpu_to_le32((u32)seq_number << TXDESC40_SEQ_SHIFT);
Jes Sorensencc2646d2016-02-29 17:05:32 -05007857
Jes Sorensena40ace42016-02-29 17:05:31 -05007858 if (ampdu_enable)
Jes Sorensen33f37242016-03-31 17:08:34 -04007859 tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_ENABLE);
Jes Sorensena40ace42016-02-29 17:05:31 -05007860 else
Jes Sorensen33f37242016-03-31 17:08:34 -04007861 tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_BREAK);
Jes Sorensen4c683602016-02-29 17:05:35 -05007862
7863 if (ieee80211_is_mgmt(hdr->frame_control)) {
7864 tx_desc40->txdw4 = cpu_to_le32(tx_rate->hw_value);
7865 tx_desc40->txdw3 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007866 cpu_to_le32(TXDESC40_USE_DRIVER_RATE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007867 tx_desc40->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007868 cpu_to_le32(6 << TXDESC40_RETRY_LIMIT_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007869 tx_desc40->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007870 cpu_to_le32(TXDESC40_RETRY_LIMIT_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007871 }
7872
7873 if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ||
7874 (sta && vif && vif->bss_conf.use_short_preamble))
7875 tx_desc40->txdw5 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007876 cpu_to_le32(TXDESC40_SHORT_PREAMBLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007877
7878 if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
7879 /*
7880 * Use RTS rate 24M - does the mac80211 tell
7881 * us which to use?
7882 */
7883 tx_desc->txdw4 |=
7884 cpu_to_le32(DESC_RATE_24M <<
Jes Sorensen33f37242016-03-31 17:08:34 -04007885 TXDESC40_RTS_RATE_SHIFT);
7886 tx_desc->txdw3 |= cpu_to_le32(TXDESC40_RTS_CTS_ENABLE);
7887 tx_desc->txdw3 |= cpu_to_le32(TXDESC40_HW_RTS_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007888 }
Jes Sorensen69794942016-02-29 17:05:43 -05007889 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007890
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007891 rtl8xxxu_calc_tx_desc_csum(tx_desc);
7892
7893 usb_fill_bulk_urb(&tx_urb->urb, priv->udev, priv->pipe_out[queue],
7894 skb->data, skb->len, rtl8xxxu_tx_complete, skb);
7895
7896 usb_anchor_urb(&tx_urb->urb, &priv->tx_anchor);
7897 ret = usb_submit_urb(&tx_urb->urb, GFP_ATOMIC);
7898 if (ret) {
7899 usb_unanchor_urb(&tx_urb->urb);
7900 rtl8xxxu_free_tx_urb(priv, tx_urb);
7901 goto error;
7902 }
7903 return;
7904error:
7905 dev_kfree_skb(skb);
7906}
7907
7908static void rtl8xxxu_rx_parse_phystats(struct rtl8xxxu_priv *priv,
7909 struct ieee80211_rx_status *rx_status,
Jes Sorensen87957082016-02-29 17:05:42 -05007910 struct rtl8723au_phy_stats *phy_stats,
7911 u32 rxmcs)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007912{
7913 if (phy_stats->sgi_en)
7914 rx_status->flag |= RX_FLAG_SHORT_GI;
7915
Jes Sorensen87957082016-02-29 17:05:42 -05007916 if (rxmcs < DESC_RATE_6M) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007917 /*
7918 * Handle PHY stats for CCK rates
7919 */
7920 u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;
7921
7922 switch (cck_agc_rpt & 0xc0) {
7923 case 0xc0:
7924 rx_status->signal = -46 - (cck_agc_rpt & 0x3e);
7925 break;
7926 case 0x80:
7927 rx_status->signal = -26 - (cck_agc_rpt & 0x3e);
7928 break;
7929 case 0x40:
7930 rx_status->signal = -12 - (cck_agc_rpt & 0x3e);
7931 break;
7932 case 0x00:
7933 rx_status->signal = 16 - (cck_agc_rpt & 0x3e);
7934 break;
7935 }
7936 } else {
7937 rx_status->signal =
7938 (phy_stats->cck_sig_qual_ofdm_pwdb_all >> 1) - 110;
7939 }
7940}
7941
7942static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv)
7943{
7944 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
7945 unsigned long flags;
7946
7947 spin_lock_irqsave(&priv->rx_urb_lock, flags);
7948
7949 list_for_each_entry_safe(rx_urb, tmp,
7950 &priv->rx_urb_pending_list, list) {
7951 list_del(&rx_urb->list);
7952 priv->rx_urb_pending_count--;
7953 usb_free_urb(&rx_urb->urb);
7954 }
7955
7956 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
7957}
7958
7959static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv,
7960 struct rtl8xxxu_rx_urb *rx_urb)
7961{
7962 struct sk_buff *skb;
7963 unsigned long flags;
7964 int pending = 0;
7965
7966 spin_lock_irqsave(&priv->rx_urb_lock, flags);
7967
7968 if (!priv->shutdown) {
7969 list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list);
7970 priv->rx_urb_pending_count++;
7971 pending = priv->rx_urb_pending_count;
7972 } else {
7973 skb = (struct sk_buff *)rx_urb->urb.context;
7974 dev_kfree_skb(skb);
7975 usb_free_urb(&rx_urb->urb);
7976 }
7977
7978 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
7979
7980 if (pending > RTL8XXXU_RX_URB_PENDING_WATER)
7981 schedule_work(&priv->rx_urb_wq);
7982}
7983
7984static void rtl8xxxu_rx_urb_work(struct work_struct *work)
7985{
7986 struct rtl8xxxu_priv *priv;
7987 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
7988 struct list_head local;
7989 struct sk_buff *skb;
7990 unsigned long flags;
7991 int ret;
7992
7993 priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq);
7994 INIT_LIST_HEAD(&local);
7995
7996 spin_lock_irqsave(&priv->rx_urb_lock, flags);
7997
7998 list_splice_init(&priv->rx_urb_pending_list, &local);
7999 priv->rx_urb_pending_count = 0;
8000
8001 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
8002
8003 list_for_each_entry_safe(rx_urb, tmp, &local, list) {
8004 list_del_init(&rx_urb->list);
8005 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
8006 /*
8007 * If out of memory or temporary error, put it back on the
8008 * queue and try again. Otherwise the device is dead/gone
8009 * and we should drop it.
8010 */
8011 switch (ret) {
8012 case 0:
8013 break;
8014 case -ENOMEM:
8015 case -EAGAIN:
8016 rtl8xxxu_queue_rx_urb(priv, rx_urb);
8017 break;
8018 default:
8019 pr_info("failed to requeue urb %i\n", ret);
8020 skb = (struct sk_buff *)rx_urb->urb.context;
8021 dev_kfree_skb(skb);
8022 usb_free_urb(&rx_urb->urb);
8023 }
8024 }
8025}
8026
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008027static int rtl8723au_parse_rx_desc(struct rtl8xxxu_priv *priv,
8028 struct sk_buff *skb,
8029 struct ieee80211_rx_status *rx_status)
8030{
8031 struct rtl8xxxu_rx_desc *rx_desc = (struct rtl8xxxu_rx_desc *)skb->data;
8032 struct rtl8723au_phy_stats *phy_stats;
8033 int drvinfo_sz, desc_shift;
8034
8035 skb_pull(skb, sizeof(struct rtl8xxxu_rx_desc));
8036
8037 phy_stats = (struct rtl8723au_phy_stats *)skb->data;
8038
8039 drvinfo_sz = rx_desc->drvinfo_sz * 8;
8040 desc_shift = rx_desc->shift;
8041 skb_pull(skb, drvinfo_sz + desc_shift);
8042
8043 if (rx_desc->phy_stats)
Jes Sorensen87957082016-02-29 17:05:42 -05008044 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats,
8045 rx_desc->rxmcs);
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008046
8047 rx_status->mactime = le32_to_cpu(rx_desc->tsfl);
8048 rx_status->flag |= RX_FLAG_MACTIME_START;
8049
8050 if (!rx_desc->swdec)
8051 rx_status->flag |= RX_FLAG_DECRYPTED;
8052 if (rx_desc->crc32)
8053 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
8054 if (rx_desc->bw)
8055 rx_status->flag |= RX_FLAG_40MHZ;
8056
8057 if (rx_desc->rxht) {
8058 rx_status->flag |= RX_FLAG_HT;
8059 rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0;
8060 } else {
8061 rx_status->rate_idx = rx_desc->rxmcs;
8062 }
8063
8064 return RX_TYPE_DATA_PKT;
8065}
8066
8067static int rtl8723bu_parse_rx_desc(struct rtl8xxxu_priv *priv,
8068 struct sk_buff *skb,
8069 struct ieee80211_rx_status *rx_status)
8070{
8071 struct rtl8723bu_rx_desc *rx_desc =
8072 (struct rtl8723bu_rx_desc *)skb->data;
8073 struct rtl8723au_phy_stats *phy_stats;
8074 int drvinfo_sz, desc_shift;
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008075
8076 skb_pull(skb, sizeof(struct rtl8723bu_rx_desc));
8077
8078 phy_stats = (struct rtl8723au_phy_stats *)skb->data;
8079
8080 drvinfo_sz = rx_desc->drvinfo_sz * 8;
8081 desc_shift = rx_desc->shift;
8082 skb_pull(skb, drvinfo_sz + desc_shift);
8083
Jes Sorensene975b872016-02-29 17:05:36 -05008084 if (rx_desc->rpt_sel) {
8085 struct device *dev = &priv->udev->dev;
8086 dev_dbg(dev, "%s: C2H packet\n", __func__);
8087 return RX_TYPE_C2H;
8088 }
8089
Jes Sorensen87957082016-02-29 17:05:42 -05008090 if (rx_desc->phy_stats)
8091 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats,
8092 rx_desc->rxmcs);
8093
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008094 rx_status->mactime = le32_to_cpu(rx_desc->tsfl);
8095 rx_status->flag |= RX_FLAG_MACTIME_START;
8096
8097 if (!rx_desc->swdec)
8098 rx_status->flag |= RX_FLAG_DECRYPTED;
8099 if (rx_desc->crc32)
8100 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
8101 if (rx_desc->bw)
8102 rx_status->flag |= RX_FLAG_40MHZ;
8103
8104 if (rx_desc->rxmcs >= DESC_RATE_MCS0) {
8105 rx_status->flag |= RX_FLAG_HT;
8106 rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0;
8107 } else {
8108 rx_status->rate_idx = rx_desc->rxmcs;
8109 }
8110
Jes Sorensene975b872016-02-29 17:05:36 -05008111 return RX_TYPE_DATA_PKT;
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008112}
8113
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008114static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv *priv,
8115 struct sk_buff *skb)
8116{
8117 struct rtl8723bu_c2h *c2h = (struct rtl8723bu_c2h *)skb->data;
8118 struct device *dev = &priv->udev->dev;
8119 int len;
8120
8121 len = skb->len - 2;
8122
Jes Sorensen5e00d502016-02-29 17:05:28 -05008123 dev_dbg(dev, "C2H ID %02x seq %02x, len %02x source %02x\n",
8124 c2h->id, c2h->seq, len, c2h->bt_info.response_source);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008125
8126 switch(c2h->id) {
8127 case C2H_8723B_BT_INFO:
8128 if (c2h->bt_info.response_source >
8129 BT_INFO_SRC_8723B_BT_ACTIVE_SEND)
Jes Sorensen5e00d502016-02-29 17:05:28 -05008130 dev_dbg(dev, "C2H_BT_INFO WiFi only firmware\n");
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008131 else
Jes Sorensen5e00d502016-02-29 17:05:28 -05008132 dev_dbg(dev, "C2H_BT_INFO BT/WiFi coexist firmware\n");
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008133
8134 if (c2h->bt_info.bt_has_reset)
Jes Sorensen5e00d502016-02-29 17:05:28 -05008135 dev_dbg(dev, "BT has been reset\n");
Jes Sorensen394f1bd2016-02-29 17:04:49 -05008136 if (c2h->bt_info.tx_rx_mask)
Jes Sorensen5e00d502016-02-29 17:05:28 -05008137 dev_dbg(dev, "BT TRx mask\n");
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008138
8139 break;
Jes Sorensen394f1bd2016-02-29 17:04:49 -05008140 case C2H_8723B_BT_MP_INFO:
Jes Sorensen5e00d502016-02-29 17:05:28 -05008141 dev_dbg(dev, "C2H_MP_INFO ext ID %02x, status %02x\n",
8142 c2h->bt_mp_info.ext_id, c2h->bt_mp_info.status);
Jes Sorensen394f1bd2016-02-29 17:04:49 -05008143 break;
Jes Sorensen55a18dd2016-02-29 17:05:41 -05008144 case C2H_8723B_RA_REPORT:
8145 dev_dbg(dev,
8146 "C2H RA RPT: rate %02x, unk %i, macid %02x, noise %i\n",
8147 c2h->ra_report.rate, c2h->ra_report.dummy0_0,
8148 c2h->ra_report.macid, c2h->ra_report.noisy_state);
8149 break;
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008150 default:
Jes Sorensen739dc9f2016-02-29 17:05:40 -05008151 dev_info(dev, "Unhandled C2H event %02x seq %02x\n",
8152 c2h->id, c2h->seq);
8153 print_hex_dump(KERN_INFO, "C2H content: ", DUMP_PREFIX_NONE,
8154 16, 1, c2h->raw.payload, len, false);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008155 break;
8156 }
8157}
8158
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008159static void rtl8xxxu_rx_complete(struct urb *urb)
8160{
8161 struct rtl8xxxu_rx_urb *rx_urb =
8162 container_of(urb, struct rtl8xxxu_rx_urb, urb);
8163 struct ieee80211_hw *hw = rx_urb->hw;
8164 struct rtl8xxxu_priv *priv = hw->priv;
8165 struct sk_buff *skb = (struct sk_buff *)urb->context;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008166 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008167 struct device *dev = &priv->udev->dev;
8168 __le32 *_rx_desc_le = (__le32 *)skb->data;
8169 u32 *_rx_desc = (u32 *)skb->data;
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008170 int rx_type, i;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008171
8172 for (i = 0; i < (sizeof(struct rtl8xxxu_rx_desc) / sizeof(u32)); i++)
8173 _rx_desc[i] = le32_to_cpu(_rx_desc_le[i]);
8174
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008175 skb_put(skb, urb->actual_length);
8176
8177 if (urb->status == 0) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008178 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
8179
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008180 rx_type = priv->fops->parse_rx_desc(priv, skb, rx_status);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008181
8182 rx_status->freq = hw->conf.chandef.chan->center_freq;
8183 rx_status->band = hw->conf.chandef.chan->band;
8184
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008185 if (rx_type == RX_TYPE_DATA_PKT)
8186 ieee80211_rx_irqsafe(hw, skb);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008187 else {
8188 rtl8723bu_handle_c2h(priv, skb);
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008189 dev_kfree_skb(skb);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05008190 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008191
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008192 skb = NULL;
8193 rx_urb->urb.context = NULL;
8194 rtl8xxxu_queue_rx_urb(priv, rx_urb);
8195 } else {
8196 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
8197 goto cleanup;
8198 }
8199 return;
8200
8201cleanup:
8202 usb_free_urb(urb);
8203 dev_kfree_skb(skb);
8204 return;
8205}
8206
8207static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
8208 struct rtl8xxxu_rx_urb *rx_urb)
8209{
8210 struct sk_buff *skb;
8211 int skb_size;
8212 int ret;
8213
8214 skb_size = sizeof(struct rtl8xxxu_rx_desc) + RTL_RX_BUFFER_SIZE;
8215 skb = __netdev_alloc_skb(NULL, skb_size, GFP_KERNEL);
8216 if (!skb)
8217 return -ENOMEM;
8218
8219 memset(skb->data, 0, sizeof(struct rtl8xxxu_rx_desc));
8220 usb_fill_bulk_urb(&rx_urb->urb, priv->udev, priv->pipe_in, skb->data,
8221 skb_size, rtl8xxxu_rx_complete, skb);
8222 usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor);
8223 ret = usb_submit_urb(&rx_urb->urb, GFP_ATOMIC);
8224 if (ret)
8225 usb_unanchor_urb(&rx_urb->urb);
8226 return ret;
8227}
8228
8229static void rtl8xxxu_int_complete(struct urb *urb)
8230{
8231 struct rtl8xxxu_priv *priv = (struct rtl8xxxu_priv *)urb->context;
8232 struct device *dev = &priv->udev->dev;
8233 int ret;
8234
8235 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
8236 if (urb->status == 0) {
8237 usb_anchor_urb(urb, &priv->int_anchor);
8238 ret = usb_submit_urb(urb, GFP_ATOMIC);
8239 if (ret)
8240 usb_unanchor_urb(urb);
8241 } else {
8242 dev_info(dev, "%s: Error %i\n", __func__, urb->status);
8243 }
8244}
8245
8246
8247static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw)
8248{
8249 struct rtl8xxxu_priv *priv = hw->priv;
8250 struct urb *urb;
8251 u32 val32;
8252 int ret;
8253
8254 urb = usb_alloc_urb(0, GFP_KERNEL);
8255 if (!urb)
8256 return -ENOMEM;
8257
8258 usb_fill_int_urb(urb, priv->udev, priv->pipe_interrupt,
8259 priv->int_buf, USB_INTR_CONTENT_LENGTH,
8260 rtl8xxxu_int_complete, priv, 1);
8261 usb_anchor_urb(urb, &priv->int_anchor);
8262 ret = usb_submit_urb(urb, GFP_KERNEL);
8263 if (ret) {
8264 usb_unanchor_urb(urb);
8265 goto error;
8266 }
8267
8268 val32 = rtl8xxxu_read32(priv, REG_USB_HIMR);
8269 val32 |= USB_HIMR_CPWM;
8270 rtl8xxxu_write32(priv, REG_USB_HIMR, val32);
8271
8272error:
8273 return ret;
8274}
8275
8276static int rtl8xxxu_add_interface(struct ieee80211_hw *hw,
8277 struct ieee80211_vif *vif)
8278{
8279 struct rtl8xxxu_priv *priv = hw->priv;
8280 int ret;
8281 u8 val8;
8282
8283 switch (vif->type) {
8284 case NL80211_IFTYPE_STATION:
8285 rtl8723a_stop_tx_beacon(priv);
8286
8287 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
8288 val8 |= BEACON_ATIM | BEACON_FUNCTION_ENABLE |
8289 BEACON_DISABLE_TSF_UPDATE;
8290 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
8291 ret = 0;
8292 break;
8293 default:
8294 ret = -EOPNOTSUPP;
8295 }
8296
8297 rtl8xxxu_set_linktype(priv, vif->type);
8298
8299 return ret;
8300}
8301
8302static void rtl8xxxu_remove_interface(struct ieee80211_hw *hw,
8303 struct ieee80211_vif *vif)
8304{
8305 struct rtl8xxxu_priv *priv = hw->priv;
8306
8307 dev_dbg(&priv->udev->dev, "%s\n", __func__);
8308}
8309
8310static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed)
8311{
8312 struct rtl8xxxu_priv *priv = hw->priv;
8313 struct device *dev = &priv->udev->dev;
8314 u16 val16;
8315 int ret = 0, channel;
8316 bool ht40;
8317
8318 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
8319 dev_info(dev,
8320 "%s: channel: %i (changed %08x chandef.width %02x)\n",
8321 __func__, hw->conf.chandef.chan->hw_value,
8322 changed, hw->conf.chandef.width);
8323
8324 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
8325 val16 = ((hw->conf.long_frame_max_tx_count <<
8326 RETRY_LIMIT_LONG_SHIFT) & RETRY_LIMIT_LONG_MASK) |
8327 ((hw->conf.short_frame_max_tx_count <<
8328 RETRY_LIMIT_SHORT_SHIFT) & RETRY_LIMIT_SHORT_MASK);
8329 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
8330 }
8331
8332 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
8333 switch (hw->conf.chandef.width) {
8334 case NL80211_CHAN_WIDTH_20_NOHT:
8335 case NL80211_CHAN_WIDTH_20:
8336 ht40 = false;
8337 break;
8338 case NL80211_CHAN_WIDTH_40:
8339 ht40 = true;
8340 break;
8341 default:
8342 ret = -ENOTSUPP;
8343 goto exit;
8344 }
8345
8346 channel = hw->conf.chandef.chan->hw_value;
8347
Jes Sorensene796dab2016-02-29 17:05:19 -05008348 priv->fops->set_tx_power(priv, channel, ht40);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008349
Jes Sorensen1ea8e842016-02-29 17:05:04 -05008350 priv->fops->config_channel(hw);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008351 }
8352
8353exit:
8354 return ret;
8355}
8356
8357static int rtl8xxxu_conf_tx(struct ieee80211_hw *hw,
8358 struct ieee80211_vif *vif, u16 queue,
8359 const struct ieee80211_tx_queue_params *param)
8360{
8361 struct rtl8xxxu_priv *priv = hw->priv;
8362 struct device *dev = &priv->udev->dev;
8363 u32 val32;
8364 u8 aifs, acm_ctrl, acm_bit;
8365
8366 aifs = param->aifs;
8367
8368 val32 = aifs |
8369 fls(param->cw_min) << EDCA_PARAM_ECW_MIN_SHIFT |
8370 fls(param->cw_max) << EDCA_PARAM_ECW_MAX_SHIFT |
8371 (u32)param->txop << EDCA_PARAM_TXOP_SHIFT;
8372
8373 acm_ctrl = rtl8xxxu_read8(priv, REG_ACM_HW_CTRL);
8374 dev_dbg(dev,
8375 "%s: IEEE80211 queue %02x val %08x, acm %i, acm_ctrl %02x\n",
8376 __func__, queue, val32, param->acm, acm_ctrl);
8377
8378 switch (queue) {
8379 case IEEE80211_AC_VO:
8380 acm_bit = ACM_HW_CTRL_VO;
8381 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, val32);
8382 break;
8383 case IEEE80211_AC_VI:
8384 acm_bit = ACM_HW_CTRL_VI;
8385 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, val32);
8386 break;
8387 case IEEE80211_AC_BE:
8388 acm_bit = ACM_HW_CTRL_BE;
8389 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, val32);
8390 break;
8391 case IEEE80211_AC_BK:
8392 acm_bit = ACM_HW_CTRL_BK;
8393 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, val32);
8394 break;
8395 default:
8396 acm_bit = 0;
8397 break;
8398 }
8399
8400 if (param->acm)
8401 acm_ctrl |= acm_bit;
8402 else
8403 acm_ctrl &= ~acm_bit;
8404 rtl8xxxu_write8(priv, REG_ACM_HW_CTRL, acm_ctrl);
8405
8406 return 0;
8407}
8408
8409static void rtl8xxxu_configure_filter(struct ieee80211_hw *hw,
8410 unsigned int changed_flags,
8411 unsigned int *total_flags, u64 multicast)
8412{
8413 struct rtl8xxxu_priv *priv = hw->priv;
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05008414 u32 rcr = rtl8xxxu_read32(priv, REG_RCR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008415
8416 dev_dbg(&priv->udev->dev, "%s: changed_flags %08x, total_flags %08x\n",
8417 __func__, changed_flags, *total_flags);
8418
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05008419 /*
8420 * FIF_ALLMULTI ignored as all multicast frames are accepted (REG_MAR)
8421 */
8422
8423 if (*total_flags & FIF_FCSFAIL)
8424 rcr |= RCR_ACCEPT_CRC32;
8425 else
8426 rcr &= ~RCR_ACCEPT_CRC32;
8427
8428 /*
8429 * FIF_PLCPFAIL not supported?
8430 */
8431
8432 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
8433 rcr &= ~RCR_CHECK_BSSID_BEACON;
8434 else
8435 rcr |= RCR_CHECK_BSSID_BEACON;
8436
8437 if (*total_flags & FIF_CONTROL)
8438 rcr |= RCR_ACCEPT_CTRL_FRAME;
8439 else
8440 rcr &= ~RCR_ACCEPT_CTRL_FRAME;
8441
8442 if (*total_flags & FIF_OTHER_BSS) {
8443 rcr |= RCR_ACCEPT_AP;
8444 rcr &= ~RCR_CHECK_BSSID_MATCH;
8445 } else {
8446 rcr &= ~RCR_ACCEPT_AP;
8447 rcr |= RCR_CHECK_BSSID_MATCH;
8448 }
8449
8450 if (*total_flags & FIF_PSPOLL)
8451 rcr |= RCR_ACCEPT_PM;
8452 else
8453 rcr &= ~RCR_ACCEPT_PM;
8454
8455 /*
8456 * FIF_PROBE_REQ ignored as probe requests always seem to be accepted
8457 */
8458
8459 rtl8xxxu_write32(priv, REG_RCR, rcr);
8460
Jes Sorensen755bda12016-02-03 13:39:54 -05008461 *total_flags &= (FIF_ALLMULTI | FIF_FCSFAIL | FIF_BCN_PRBRESP_PROMISC |
8462 FIF_CONTROL | FIF_OTHER_BSS | FIF_PSPOLL |
8463 FIF_PROBE_REQ);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008464}
8465
8466static int rtl8xxxu_set_rts_threshold(struct ieee80211_hw *hw, u32 rts)
8467{
8468 if (rts > 2347)
8469 return -EINVAL;
8470
8471 return 0;
8472}
8473
8474static int rtl8xxxu_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
8475 struct ieee80211_vif *vif,
8476 struct ieee80211_sta *sta,
8477 struct ieee80211_key_conf *key)
8478{
8479 struct rtl8xxxu_priv *priv = hw->priv;
8480 struct device *dev = &priv->udev->dev;
8481 u8 mac_addr[ETH_ALEN];
8482 u8 val8;
8483 u16 val16;
8484 u32 val32;
8485 int retval = -EOPNOTSUPP;
8486
8487 dev_dbg(dev, "%s: cmd %02x, cipher %08x, index %i\n",
8488 __func__, cmd, key->cipher, key->keyidx);
8489
8490 if (vif->type != NL80211_IFTYPE_STATION)
8491 return -EOPNOTSUPP;
8492
8493 if (key->keyidx > 3)
8494 return -EOPNOTSUPP;
8495
8496 switch (key->cipher) {
8497 case WLAN_CIPHER_SUITE_WEP40:
8498 case WLAN_CIPHER_SUITE_WEP104:
8499
8500 break;
8501 case WLAN_CIPHER_SUITE_CCMP:
8502 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
8503 break;
8504 case WLAN_CIPHER_SUITE_TKIP:
8505 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
8506 default:
8507 return -EOPNOTSUPP;
8508 }
8509
8510 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
8511 dev_dbg(dev, "%s: pairwise key\n", __func__);
8512 ether_addr_copy(mac_addr, sta->addr);
8513 } else {
8514 dev_dbg(dev, "%s: group key\n", __func__);
8515 eth_broadcast_addr(mac_addr);
8516 }
8517
8518 val16 = rtl8xxxu_read16(priv, REG_CR);
8519 val16 |= CR_SECURITY_ENABLE;
8520 rtl8xxxu_write16(priv, REG_CR, val16);
8521
8522 val8 = SEC_CFG_TX_SEC_ENABLE | SEC_CFG_TXBC_USE_DEFKEY |
8523 SEC_CFG_RX_SEC_ENABLE | SEC_CFG_RXBC_USE_DEFKEY;
8524 val8 |= SEC_CFG_TX_USE_DEFKEY | SEC_CFG_RX_USE_DEFKEY;
8525 rtl8xxxu_write8(priv, REG_SECURITY_CFG, val8);
8526
8527 switch (cmd) {
8528 case SET_KEY:
8529 key->hw_key_idx = key->keyidx;
8530 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
8531 rtl8xxxu_cam_write(priv, key, mac_addr);
8532 retval = 0;
8533 break;
8534 case DISABLE_KEY:
8535 rtl8xxxu_write32(priv, REG_CAM_WRITE, 0x00000000);
8536 val32 = CAM_CMD_POLLING | CAM_CMD_WRITE |
8537 key->keyidx << CAM_CMD_KEY_SHIFT;
8538 rtl8xxxu_write32(priv, REG_CAM_CMD, val32);
8539 retval = 0;
8540 break;
8541 default:
8542 dev_warn(dev, "%s: Unsupported command %02x\n", __func__, cmd);
8543 }
8544
8545 return retval;
8546}
8547
8548static int
8549rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +02008550 struct ieee80211_ampdu_params *params)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008551{
8552 struct rtl8xxxu_priv *priv = hw->priv;
8553 struct device *dev = &priv->udev->dev;
8554 u8 ampdu_factor, ampdu_density;
Sara Sharon50ea05e2015-12-30 16:06:04 +02008555 struct ieee80211_sta *sta = params->sta;
8556 enum ieee80211_ampdu_mlme_action action = params->action;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008557
8558 switch (action) {
8559 case IEEE80211_AMPDU_TX_START:
8560 dev_info(dev, "%s: IEEE80211_AMPDU_TX_START\n", __func__);
8561 ampdu_factor = sta->ht_cap.ampdu_factor;
8562 ampdu_density = sta->ht_cap.ampdu_density;
8563 rtl8xxxu_set_ampdu_factor(priv, ampdu_factor);
8564 rtl8xxxu_set_ampdu_min_space(priv, ampdu_density);
8565 dev_dbg(dev,
8566 "Changed HT: ampdu_factor %02x, ampdu_density %02x\n",
8567 ampdu_factor, ampdu_density);
8568 break;
8569 case IEEE80211_AMPDU_TX_STOP_FLUSH:
8570 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__);
8571 rtl8xxxu_set_ampdu_factor(priv, 0);
8572 rtl8xxxu_set_ampdu_min_space(priv, 0);
8573 break;
8574 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
8575 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n",
8576 __func__);
8577 rtl8xxxu_set_ampdu_factor(priv, 0);
8578 rtl8xxxu_set_ampdu_min_space(priv, 0);
8579 break;
8580 case IEEE80211_AMPDU_RX_START:
8581 dev_info(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__);
8582 break;
8583 case IEEE80211_AMPDU_RX_STOP:
8584 dev_info(dev, "%s: IEEE80211_AMPDU_RX_STOP\n", __func__);
8585 break;
8586 default:
8587 break;
8588 }
8589 return 0;
8590}
8591
8592static int rtl8xxxu_start(struct ieee80211_hw *hw)
8593{
8594 struct rtl8xxxu_priv *priv = hw->priv;
8595 struct rtl8xxxu_rx_urb *rx_urb;
8596 struct rtl8xxxu_tx_urb *tx_urb;
8597 unsigned long flags;
8598 int ret, i;
8599
8600 ret = 0;
8601
8602 init_usb_anchor(&priv->rx_anchor);
8603 init_usb_anchor(&priv->tx_anchor);
8604 init_usb_anchor(&priv->int_anchor);
8605
Jes Sorensendb08de92016-02-29 17:05:17 -05008606 priv->fops->enable_rf(priv);
Jes Sorensen0e28b972016-02-29 17:04:13 -05008607 if (priv->usb_interrupts) {
8608 ret = rtl8xxxu_submit_int_urb(hw);
8609 if (ret)
8610 goto exit;
8611 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008612
8613 for (i = 0; i < RTL8XXXU_TX_URBS; i++) {
8614 tx_urb = kmalloc(sizeof(struct rtl8xxxu_tx_urb), GFP_KERNEL);
8615 if (!tx_urb) {
8616 if (!i)
8617 ret = -ENOMEM;
8618
8619 goto error_out;
8620 }
8621 usb_init_urb(&tx_urb->urb);
8622 INIT_LIST_HEAD(&tx_urb->list);
8623 tx_urb->hw = hw;
8624 list_add(&tx_urb->list, &priv->tx_urb_free_list);
8625 priv->tx_urb_free_count++;
8626 }
8627
8628 priv->tx_stopped = false;
8629
8630 spin_lock_irqsave(&priv->rx_urb_lock, flags);
8631 priv->shutdown = false;
8632 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
8633
8634 for (i = 0; i < RTL8XXXU_RX_URBS; i++) {
8635 rx_urb = kmalloc(sizeof(struct rtl8xxxu_rx_urb), GFP_KERNEL);
8636 if (!rx_urb) {
8637 if (!i)
8638 ret = -ENOMEM;
8639
8640 goto error_out;
8641 }
8642 usb_init_urb(&rx_urb->urb);
8643 INIT_LIST_HEAD(&rx_urb->list);
8644 rx_urb->hw = hw;
8645
8646 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
8647 }
8648exit:
8649 /*
Bruno Randolfc85ea112016-02-03 13:39:55 -05008650 * Accept all data and mgmt frames
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008651 */
Bruno Randolfc85ea112016-02-03 13:39:55 -05008652 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0xffff);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008653 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0xffff);
8654
8655 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, 0x6954341e);
8656
8657 return ret;
8658
8659error_out:
8660 rtl8xxxu_free_tx_resources(priv);
8661 /*
8662 * Disable all data and mgmt frames
8663 */
8664 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
8665 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
8666
8667 return ret;
8668}
8669
8670static void rtl8xxxu_stop(struct ieee80211_hw *hw)
8671{
8672 struct rtl8xxxu_priv *priv = hw->priv;
8673 unsigned long flags;
8674
8675 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
8676
8677 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
8678 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
8679
8680 spin_lock_irqsave(&priv->rx_urb_lock, flags);
8681 priv->shutdown = true;
8682 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
8683
8684 usb_kill_anchored_urbs(&priv->rx_anchor);
8685 usb_kill_anchored_urbs(&priv->tx_anchor);
Jes Sorensen0e28b972016-02-29 17:04:13 -05008686 if (priv->usb_interrupts)
8687 usb_kill_anchored_urbs(&priv->int_anchor);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008688
Jes Sorensenfc89a412016-02-29 17:05:46 -05008689 priv->fops->disable_rf(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008690
8691 /*
8692 * Disable interrupts
8693 */
Jes Sorensen0e28b972016-02-29 17:04:13 -05008694 if (priv->usb_interrupts)
8695 rtl8xxxu_write32(priv, REG_USB_HIMR, 0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008696
8697 rtl8xxxu_free_rx_resources(priv);
8698 rtl8xxxu_free_tx_resources(priv);
8699}
8700
8701static const struct ieee80211_ops rtl8xxxu_ops = {
8702 .tx = rtl8xxxu_tx,
8703 .add_interface = rtl8xxxu_add_interface,
8704 .remove_interface = rtl8xxxu_remove_interface,
8705 .config = rtl8xxxu_config,
8706 .conf_tx = rtl8xxxu_conf_tx,
8707 .bss_info_changed = rtl8xxxu_bss_info_changed,
8708 .configure_filter = rtl8xxxu_configure_filter,
8709 .set_rts_threshold = rtl8xxxu_set_rts_threshold,
8710 .start = rtl8xxxu_start,
8711 .stop = rtl8xxxu_stop,
8712 .sw_scan_start = rtl8xxxu_sw_scan_start,
8713 .sw_scan_complete = rtl8xxxu_sw_scan_complete,
8714 .set_key = rtl8xxxu_set_key,
8715 .ampdu_action = rtl8xxxu_ampdu_action,
8716};
8717
8718static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv,
8719 struct usb_interface *interface)
8720{
8721 struct usb_interface_descriptor *interface_desc;
8722 struct usb_host_interface *host_interface;
8723 struct usb_endpoint_descriptor *endpoint;
8724 struct device *dev = &priv->udev->dev;
8725 int i, j = 0, endpoints;
8726 u8 dir, xtype, num;
8727 int ret = 0;
8728
8729 host_interface = &interface->altsetting[0];
8730 interface_desc = &host_interface->desc;
8731 endpoints = interface_desc->bNumEndpoints;
8732
8733 for (i = 0; i < endpoints; i++) {
8734 endpoint = &host_interface->endpoint[i].desc;
8735
8736 dir = endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
8737 num = usb_endpoint_num(endpoint);
8738 xtype = usb_endpoint_type(endpoint);
8739 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8740 dev_dbg(dev,
8741 "%s: endpoint: dir %02x, # %02x, type %02x\n",
8742 __func__, dir, num, xtype);
8743 if (usb_endpoint_dir_in(endpoint) &&
8744 usb_endpoint_xfer_bulk(endpoint)) {
8745 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8746 dev_dbg(dev, "%s: in endpoint num %i\n",
8747 __func__, num);
8748
8749 if (priv->pipe_in) {
8750 dev_warn(dev,
8751 "%s: Too many IN pipes\n", __func__);
8752 ret = -EINVAL;
8753 goto exit;
8754 }
8755
8756 priv->pipe_in = usb_rcvbulkpipe(priv->udev, num);
8757 }
8758
8759 if (usb_endpoint_dir_in(endpoint) &&
8760 usb_endpoint_xfer_int(endpoint)) {
8761 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8762 dev_dbg(dev, "%s: interrupt endpoint num %i\n",
8763 __func__, num);
8764
8765 if (priv->pipe_interrupt) {
8766 dev_warn(dev, "%s: Too many INTERRUPT pipes\n",
8767 __func__);
8768 ret = -EINVAL;
8769 goto exit;
8770 }
8771
8772 priv->pipe_interrupt = usb_rcvintpipe(priv->udev, num);
8773 }
8774
8775 if (usb_endpoint_dir_out(endpoint) &&
8776 usb_endpoint_xfer_bulk(endpoint)) {
8777 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8778 dev_dbg(dev, "%s: out endpoint num %i\n",
8779 __func__, num);
8780 if (j >= RTL8XXXU_OUT_ENDPOINTS) {
8781 dev_warn(dev,
8782 "%s: Too many OUT pipes\n", __func__);
8783 ret = -EINVAL;
8784 goto exit;
8785 }
8786 priv->out_ep[j++] = num;
8787 }
8788 }
8789exit:
8790 priv->nr_out_eps = j;
8791 return ret;
8792}
8793
8794static int rtl8xxxu_probe(struct usb_interface *interface,
8795 const struct usb_device_id *id)
8796{
8797 struct rtl8xxxu_priv *priv;
8798 struct ieee80211_hw *hw;
8799 struct usb_device *udev;
8800 struct ieee80211_supported_band *sband;
8801 int ret = 0;
8802 int untested = 1;
8803
8804 udev = usb_get_dev(interface_to_usbdev(interface));
8805
8806 switch (id->idVendor) {
8807 case USB_VENDOR_ID_REALTEK:
8808 switch(id->idProduct) {
8809 case 0x1724:
8810 case 0x8176:
8811 case 0x8178:
8812 case 0x817f:
8813 untested = 0;
8814 break;
8815 }
8816 break;
8817 case 0x7392:
8818 if (id->idProduct == 0x7811)
8819 untested = 0;
8820 break;
8821 default:
8822 break;
8823 }
8824
8825 if (untested) {
Jes Sorenseneaa4d142016-02-29 17:04:31 -05008826 rtl8xxxu_debug |= RTL8XXXU_DEBUG_EFUSE;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008827 dev_info(&udev->dev,
8828 "This Realtek USB WiFi dongle (0x%04x:0x%04x) is untested!\n",
8829 id->idVendor, id->idProduct);
8830 dev_info(&udev->dev,
8831 "Please report results to Jes.Sorensen@gmail.com\n");
8832 }
8833
8834 hw = ieee80211_alloc_hw(sizeof(struct rtl8xxxu_priv), &rtl8xxxu_ops);
8835 if (!hw) {
8836 ret = -ENOMEM;
8837 goto exit;
8838 }
8839
8840 priv = hw->priv;
8841 priv->hw = hw;
8842 priv->udev = udev;
8843 priv->fops = (struct rtl8xxxu_fileops *)id->driver_info;
8844 mutex_init(&priv->usb_buf_mutex);
8845 mutex_init(&priv->h2c_mutex);
8846 INIT_LIST_HEAD(&priv->tx_urb_free_list);
8847 spin_lock_init(&priv->tx_urb_lock);
8848 INIT_LIST_HEAD(&priv->rx_urb_pending_list);
8849 spin_lock_init(&priv->rx_urb_lock);
8850 INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work);
8851
8852 usb_set_intfdata(interface, hw);
8853
8854 ret = rtl8xxxu_parse_usb(priv, interface);
8855 if (ret)
8856 goto exit;
8857
8858 ret = rtl8xxxu_identify_chip(priv);
8859 if (ret) {
8860 dev_err(&udev->dev, "Fatal - failed to identify chip\n");
8861 goto exit;
8862 }
8863
8864 ret = rtl8xxxu_read_efuse(priv);
8865 if (ret) {
8866 dev_err(&udev->dev, "Fatal - failed to read EFuse\n");
8867 goto exit;
8868 }
8869
8870 ret = priv->fops->parse_efuse(priv);
8871 if (ret) {
8872 dev_err(&udev->dev, "Fatal - failed to parse EFuse\n");
8873 goto exit;
8874 }
8875
8876 rtl8xxxu_print_chipinfo(priv);
8877
8878 ret = priv->fops->load_firmware(priv);
8879 if (ret) {
8880 dev_err(&udev->dev, "Fatal - failed to load firmware\n");
8881 goto exit;
8882 }
8883
8884 ret = rtl8xxxu_init_device(hw);
8885
8886 hw->wiphy->max_scan_ssids = 1;
8887 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
8888 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
8889 hw->queues = 4;
8890
8891 sband = &rtl8xxxu_supported_band;
8892 sband->ht_cap.ht_supported = true;
8893 sband->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
8894 sband->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
8895 sband->ht_cap.cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40;
8896 memset(&sband->ht_cap.mcs, 0, sizeof(sband->ht_cap.mcs));
8897 sband->ht_cap.mcs.rx_mask[0] = 0xff;
8898 sband->ht_cap.mcs.rx_mask[4] = 0x01;
8899 if (priv->rf_paths > 1) {
8900 sband->ht_cap.mcs.rx_mask[1] = 0xff;
8901 sband->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
8902 }
8903 sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
8904 /*
8905 * Some APs will negotiate HT20_40 in a noisy environment leading
8906 * to miserable performance. Rather than defaulting to this, only
8907 * enable it if explicitly requested at module load time.
8908 */
8909 if (rtl8xxxu_ht40_2g) {
8910 dev_info(&udev->dev, "Enabling HT_20_40 on the 2.4GHz band\n");
8911 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
8912 }
Johannes Berg57fbcce2016-04-12 15:56:15 +02008913 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008914
8915 hw->wiphy->rts_threshold = 2347;
8916
8917 SET_IEEE80211_DEV(priv->hw, &interface->dev);
8918 SET_IEEE80211_PERM_ADDR(hw, priv->mac_addr);
8919
Jes Sorensen179e1742016-02-29 17:05:27 -05008920 hw->extra_tx_headroom = priv->fops->tx_desc_size;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008921 ieee80211_hw_set(hw, SIGNAL_DBM);
8922 /*
8923 * The firmware handles rate control
8924 */
8925 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
8926 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
8927
8928 ret = ieee80211_register_hw(priv->hw);
8929 if (ret) {
8930 dev_err(&udev->dev, "%s: Failed to register: %i\n",
8931 __func__, ret);
8932 goto exit;
8933 }
8934
8935exit:
8936 if (ret < 0)
8937 usb_put_dev(udev);
8938 return ret;
8939}
8940
8941static void rtl8xxxu_disconnect(struct usb_interface *interface)
8942{
8943 struct rtl8xxxu_priv *priv;
8944 struct ieee80211_hw *hw;
8945
8946 hw = usb_get_intfdata(interface);
8947 priv = hw->priv;
8948
8949 rtl8xxxu_disable_device(hw);
8950 usb_set_intfdata(interface, NULL);
8951
8952 dev_info(&priv->udev->dev, "disconnecting\n");
8953
8954 ieee80211_unregister_hw(hw);
8955
8956 kfree(priv->fw_data);
8957 mutex_destroy(&priv->usb_buf_mutex);
8958 mutex_destroy(&priv->h2c_mutex);
8959
8960 usb_put_dev(priv->udev);
8961 ieee80211_free_hw(hw);
8962}
8963
8964static struct rtl8xxxu_fileops rtl8723au_fops = {
8965 .parse_efuse = rtl8723au_parse_efuse,
8966 .load_firmware = rtl8723au_load_firmware,
8967 .power_on = rtl8723au_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05008968 .power_off = rtl8xxxu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05008969 .reset_8051 = rtl8xxxu_reset_8051,
Jes Sorensen74b99be2016-02-29 17:04:04 -05008970 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensene1547c52016-02-29 17:04:35 -05008971 .phy_iq_calibrate = rtl8723au_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05008972 .config_channel = rtl8723au_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008973 .parse_rx_desc = rtl8723au_parse_rx_desc,
Jes Sorensendb08de92016-02-29 17:05:17 -05008974 .enable_rf = rtl8723a_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05008975 .disable_rf = rtl8723a_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05008976 .set_tx_power = rtl8723a_set_tx_power,
Jes Sorensenf653e692016-02-29 17:05:38 -05008977 .update_rate_mask = rtl8723au_update_rate_mask,
Jes Sorensen7d794ea2016-02-29 17:05:39 -05008978 .report_connect = rtl8723au_report_connect,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008979 .writeN_block_size = 1024,
Jes Sorensened35d092016-02-29 17:04:19 -05008980 .mbox_ext_reg = REG_HMBOX_EXT_0,
8981 .mbox_ext_width = 2,
Jes Sorensendbb28962016-03-31 17:08:33 -04008982 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
Jes Sorensen8634af52016-02-29 17:04:33 -05008983 .adda_1t_init = 0x0b1b25a0,
8984 .adda_1t_path_on = 0x0bdb25a0,
8985 .adda_2t_path_on_a = 0x04db25a4,
8986 .adda_2t_path_on_b = 0x0b1b25a4,
Jes Sorensenc606e662016-04-07 14:19:16 -04008987 .mactable = rtl8723a_mac_init_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008988};
8989
Jes Sorensen35a741f2016-02-29 17:04:10 -05008990static struct rtl8xxxu_fileops rtl8723bu_fops = {
Jes Sorensen3c836d62016-02-29 17:04:11 -05008991 .parse_efuse = rtl8723bu_parse_efuse,
Jes Sorensen35a741f2016-02-29 17:04:10 -05008992 .load_firmware = rtl8723bu_load_firmware,
Jes Sorensen42836db2016-02-29 17:04:52 -05008993 .power_on = rtl8723bu_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05008994 .power_off = rtl8723bu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05008995 .reset_8051 = rtl8723bu_reset_8051,
Jes Sorensen35a741f2016-02-29 17:04:10 -05008996 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05008997 .phy_init_antenna_selection = rtl8723bu_phy_init_antenna_selection,
Jes Sorensene1547c52016-02-29 17:04:35 -05008998 .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05008999 .config_channel = rtl8723bu_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05009000 .parse_rx_desc = rtl8723bu_parse_rx_desc,
Jes Sorensen3e88ca42016-02-29 17:05:08 -05009001 .init_aggregation = rtl8723bu_init_aggregation,
Jes Sorensen9c79bf92016-02-29 17:05:10 -05009002 .init_statistics = rtl8723bu_init_statistics,
Jes Sorensendb08de92016-02-29 17:05:17 -05009003 .enable_rf = rtl8723b_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05009004 .disable_rf = rtl8723b_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05009005 .set_tx_power = rtl8723b_set_tx_power,
Jes Sorensenf653e692016-02-29 17:05:38 -05009006 .update_rate_mask = rtl8723bu_update_rate_mask,
Jes Sorensen7d794ea2016-02-29 17:05:39 -05009007 .report_connect = rtl8723bu_report_connect,
Jes Sorensenadfc0122016-02-29 17:04:12 -05009008 .writeN_block_size = 1024,
Jes Sorensened35d092016-02-29 17:04:19 -05009009 .mbox_ext_reg = REG_HMBOX_EXT0_8723B,
9010 .mbox_ext_width = 4,
Jes Sorensendbb28962016-03-31 17:08:33 -04009011 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40),
Jes Sorensen0d698de2016-02-29 17:04:36 -05009012 .has_s0s1 = 1,
Jes Sorensen8634af52016-02-29 17:04:33 -05009013 .adda_1t_init = 0x01c00014,
9014 .adda_1t_path_on = 0x01c00014,
9015 .adda_2t_path_on_a = 0x01c00014,
9016 .adda_2t_path_on_b = 0x01c00014,
Jes Sorensenc606e662016-04-07 14:19:16 -04009017 .mactable = rtl8723b_mac_init_table,
Jes Sorensen35a741f2016-02-29 17:04:10 -05009018};
9019
Kalle Valoc0963772015-10-25 18:24:38 +02009020#ifdef CONFIG_RTL8XXXU_UNTESTED
9021
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009022static struct rtl8xxxu_fileops rtl8192cu_fops = {
9023 .parse_efuse = rtl8192cu_parse_efuse,
9024 .load_firmware = rtl8192cu_load_firmware,
9025 .power_on = rtl8192cu_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05009026 .power_off = rtl8xxxu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05009027 .reset_8051 = rtl8xxxu_reset_8051,
Jes Sorensen74b99be2016-02-29 17:04:04 -05009028 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensene1547c52016-02-29 17:04:35 -05009029 .phy_iq_calibrate = rtl8723au_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05009030 .config_channel = rtl8723au_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05009031 .parse_rx_desc = rtl8723au_parse_rx_desc,
Jes Sorensendb08de92016-02-29 17:05:17 -05009032 .enable_rf = rtl8723a_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05009033 .disable_rf = rtl8723a_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05009034 .set_tx_power = rtl8723a_set_tx_power,
Jes Sorensenf653e692016-02-29 17:05:38 -05009035 .update_rate_mask = rtl8723au_update_rate_mask,
Jes Sorensen7d794ea2016-02-29 17:05:39 -05009036 .report_connect = rtl8723au_report_connect,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009037 .writeN_block_size = 128,
Jes Sorensened35d092016-02-29 17:04:19 -05009038 .mbox_ext_reg = REG_HMBOX_EXT_0,
9039 .mbox_ext_width = 2,
Jes Sorensendbb28962016-03-31 17:08:33 -04009040 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
Jes Sorensen8634af52016-02-29 17:04:33 -05009041 .adda_1t_init = 0x0b1b25a0,
9042 .adda_1t_path_on = 0x0bdb25a0,
9043 .adda_2t_path_on_a = 0x04db25a4,
9044 .adda_2t_path_on_b = 0x0b1b25a4,
Jes Sorensenc606e662016-04-07 14:19:16 -04009045 .mactable = rtl8723a_mac_init_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009046};
9047
Kalle Valoc0963772015-10-25 18:24:38 +02009048#endif
9049
Jes Sorensen3307d842016-02-29 17:03:59 -05009050static struct rtl8xxxu_fileops rtl8192eu_fops = {
9051 .parse_efuse = rtl8192eu_parse_efuse,
9052 .load_firmware = rtl8192eu_load_firmware,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05009053 .power_on = rtl8192eu_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05009054 .power_off = rtl8xxxu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05009055 .reset_8051 = rtl8xxxu_reset_8051,
Jes Sorensen74b99be2016-02-29 17:04:04 -05009056 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensene1547c52016-02-29 17:04:35 -05009057 .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05009058 .config_channel = rtl8723bu_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05009059 .parse_rx_desc = rtl8723bu_parse_rx_desc,
Jes Sorensendb08de92016-02-29 17:05:17 -05009060 .enable_rf = rtl8723b_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05009061 .disable_rf = rtl8723b_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05009062 .set_tx_power = rtl8723b_set_tx_power,
Jes Sorensen91cbe4e2016-03-31 17:08:41 -04009063 .update_rate_mask = rtl8723bu_update_rate_mask,
9064 .report_connect = rtl8723bu_report_connect,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05009065 .writeN_block_size = 128,
Jes Sorensened35d092016-02-29 17:04:19 -05009066 .mbox_ext_reg = REG_HMBOX_EXT0_8723B,
9067 .mbox_ext_width = 4,
Jes Sorensenf3fc2512016-03-31 17:08:37 -04009068 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40),
Jes Sorensen0d698de2016-02-29 17:04:36 -05009069 .has_s0s1 = 1,
Jes Sorensen8634af52016-02-29 17:04:33 -05009070 .adda_1t_init = 0x0fc01616,
9071 .adda_1t_path_on = 0x0fc01616,
9072 .adda_2t_path_on_a = 0x0fc01616,
9073 .adda_2t_path_on_b = 0x0fc01616,
Jes Sorensenc606e662016-04-07 14:19:16 -04009074 .mactable = rtl8192e_mac_init_table,
Jes Sorensen3307d842016-02-29 17:03:59 -05009075};
9076
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009077static struct usb_device_id dev_table[] = {
9078{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8724, 0xff, 0xff, 0xff),
9079 .driver_info = (unsigned long)&rtl8723au_fops},
9080{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1724, 0xff, 0xff, 0xff),
9081 .driver_info = (unsigned long)&rtl8723au_fops},
9082{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x0724, 0xff, 0xff, 0xff),
9083 .driver_info = (unsigned long)&rtl8723au_fops},
Jes Sorensen3307d842016-02-29 17:03:59 -05009084{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818b, 0xff, 0xff, 0xff),
9085 .driver_info = (unsigned long)&rtl8192eu_fops},
Jes Sorensen35a741f2016-02-29 17:04:10 -05009086{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0xb720, 0xff, 0xff, 0xff),
9087 .driver_info = (unsigned long)&rtl8723bu_fops},
Kalle Valo033695b2015-10-23 20:27:58 +03009088#ifdef CONFIG_RTL8XXXU_UNTESTED
9089/* Still supported by rtlwifi */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009090{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8176, 0xff, 0xff, 0xff),
9091 .driver_info = (unsigned long)&rtl8192cu_fops},
9092{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8178, 0xff, 0xff, 0xff),
9093 .driver_info = (unsigned long)&rtl8192cu_fops},
9094{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817f, 0xff, 0xff, 0xff),
9095 .driver_info = (unsigned long)&rtl8192cu_fops},
9096/* Tested by Larry Finger */
9097{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7811, 0xff, 0xff, 0xff),
9098 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009099/* Currently untested 8188 series devices */
9100{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8191, 0xff, 0xff, 0xff),
9101 .driver_info = (unsigned long)&rtl8192cu_fops},
9102{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8170, 0xff, 0xff, 0xff),
9103 .driver_info = (unsigned long)&rtl8192cu_fops},
9104{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8177, 0xff, 0xff, 0xff),
9105 .driver_info = (unsigned long)&rtl8192cu_fops},
9106{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817a, 0xff, 0xff, 0xff),
9107 .driver_info = (unsigned long)&rtl8192cu_fops},
9108{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817b, 0xff, 0xff, 0xff),
9109 .driver_info = (unsigned long)&rtl8192cu_fops},
9110{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817d, 0xff, 0xff, 0xff),
9111 .driver_info = (unsigned long)&rtl8192cu_fops},
9112{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817e, 0xff, 0xff, 0xff),
9113 .driver_info = (unsigned long)&rtl8192cu_fops},
9114{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818a, 0xff, 0xff, 0xff),
9115 .driver_info = (unsigned long)&rtl8192cu_fops},
9116{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x317f, 0xff, 0xff, 0xff),
9117 .driver_info = (unsigned long)&rtl8192cu_fops},
9118{USB_DEVICE_AND_INTERFACE_INFO(0x1058, 0x0631, 0xff, 0xff, 0xff),
9119 .driver_info = (unsigned long)&rtl8192cu_fops},
9120{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x094c, 0xff, 0xff, 0xff),
9121 .driver_info = (unsigned long)&rtl8192cu_fops},
9122{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1102, 0xff, 0xff, 0xff),
9123 .driver_info = (unsigned long)&rtl8192cu_fops},
9124{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe033, 0xff, 0xff, 0xff),
9125 .driver_info = (unsigned long)&rtl8192cu_fops},
9126{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8189, 0xff, 0xff, 0xff),
9127 .driver_info = (unsigned long)&rtl8192cu_fops},
9128{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9041, 0xff, 0xff, 0xff),
9129 .driver_info = (unsigned long)&rtl8192cu_fops},
9130{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ba, 0xff, 0xff, 0xff),
9131 .driver_info = (unsigned long)&rtl8192cu_fops},
9132{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1e1e, 0xff, 0xff, 0xff),
9133 .driver_info = (unsigned long)&rtl8192cu_fops},
9134{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x5088, 0xff, 0xff, 0xff),
9135 .driver_info = (unsigned long)&rtl8192cu_fops},
9136{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0052, 0xff, 0xff, 0xff),
9137 .driver_info = (unsigned long)&rtl8192cu_fops},
9138{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x005c, 0xff, 0xff, 0xff),
9139 .driver_info = (unsigned long)&rtl8192cu_fops},
9140{USB_DEVICE_AND_INTERFACE_INFO(0x0eb0, 0x9071, 0xff, 0xff, 0xff),
9141 .driver_info = (unsigned long)&rtl8192cu_fops},
9142{USB_DEVICE_AND_INTERFACE_INFO(0x103c, 0x1629, 0xff, 0xff, 0xff),
9143 .driver_info = (unsigned long)&rtl8192cu_fops},
9144{USB_DEVICE_AND_INTERFACE_INFO(0x13d3, 0x3357, 0xff, 0xff, 0xff),
9145 .driver_info = (unsigned long)&rtl8192cu_fops},
9146{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3308, 0xff, 0xff, 0xff),
9147 .driver_info = (unsigned long)&rtl8192cu_fops},
9148{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330b, 0xff, 0xff, 0xff),
9149 .driver_info = (unsigned long)&rtl8192cu_fops},
9150{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x4902, 0xff, 0xff, 0xff),
9151 .driver_info = (unsigned long)&rtl8192cu_fops},
9152{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2a, 0xff, 0xff, 0xff),
9153 .driver_info = (unsigned long)&rtl8192cu_fops},
9154{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2e, 0xff, 0xff, 0xff),
9155 .driver_info = (unsigned long)&rtl8192cu_fops},
9156{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xed17, 0xff, 0xff, 0xff),
9157 .driver_info = (unsigned long)&rtl8192cu_fops},
9158{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x648b, 0xff, 0xff, 0xff),
9159 .driver_info = (unsigned long)&rtl8192cu_fops},
9160{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0090, 0xff, 0xff, 0xff),
9161 .driver_info = (unsigned long)&rtl8192cu_fops},
9162{USB_DEVICE_AND_INTERFACE_INFO(0x4856, 0x0091, 0xff, 0xff, 0xff),
9163 .driver_info = (unsigned long)&rtl8192cu_fops},
9164{USB_DEVICE_AND_INTERFACE_INFO(0xcdab, 0x8010, 0xff, 0xff, 0xff),
9165 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04009166{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff7, 0xff, 0xff, 0xff),
9167 .driver_info = (unsigned long)&rtl8192cu_fops},
9168{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff9, 0xff, 0xff, 0xff),
9169 .driver_info = (unsigned long)&rtl8192cu_fops},
9170{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffa, 0xff, 0xff, 0xff),
9171 .driver_info = (unsigned long)&rtl8192cu_fops},
9172{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff8, 0xff, 0xff, 0xff),
9173 .driver_info = (unsigned long)&rtl8192cu_fops},
9174{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffb, 0xff, 0xff, 0xff),
9175 .driver_info = (unsigned long)&rtl8192cu_fops},
9176{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffc, 0xff, 0xff, 0xff),
9177 .driver_info = (unsigned long)&rtl8192cu_fops},
9178{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x1201, 0xff, 0xff, 0xff),
9179 .driver_info = (unsigned long)&rtl8192cu_fops},
9180/* Currently untested 8192 series devices */
9181{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x0950, 0xff, 0xff, 0xff),
9182 .driver_info = (unsigned long)&rtl8192cu_fops},
9183{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1004, 0xff, 0xff, 0xff),
9184 .driver_info = (unsigned long)&rtl8192cu_fops},
9185{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2102, 0xff, 0xff, 0xff),
9186 .driver_info = (unsigned long)&rtl8192cu_fops},
9187{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2103, 0xff, 0xff, 0xff),
9188 .driver_info = (unsigned long)&rtl8192cu_fops},
9189{USB_DEVICE_AND_INTERFACE_INFO(0x0586, 0x341f, 0xff, 0xff, 0xff),
9190 .driver_info = (unsigned long)&rtl8192cu_fops},
9191{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe035, 0xff, 0xff, 0xff),
9192 .driver_info = (unsigned long)&rtl8192cu_fops},
9193{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ab, 0xff, 0xff, 0xff),
9194 .driver_info = (unsigned long)&rtl8192cu_fops},
9195{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0061, 0xff, 0xff, 0xff),
9196 .driver_info = (unsigned long)&rtl8192cu_fops},
9197{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0070, 0xff, 0xff, 0xff),
9198 .driver_info = (unsigned long)&rtl8192cu_fops},
9199{USB_DEVICE_AND_INTERFACE_INFO(0x0789, 0x016d, 0xff, 0xff, 0xff),
9200 .driver_info = (unsigned long)&rtl8192cu_fops},
9201{USB_DEVICE_AND_INTERFACE_INFO(0x07aa, 0x0056, 0xff, 0xff, 0xff),
9202 .driver_info = (unsigned long)&rtl8192cu_fops},
9203{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8178, 0xff, 0xff, 0xff),
9204 .driver_info = (unsigned long)&rtl8192cu_fops},
9205{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9021, 0xff, 0xff, 0xff),
9206 .driver_info = (unsigned long)&rtl8192cu_fops},
9207{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0xf001, 0xff, 0xff, 0xff),
9208 .driver_info = (unsigned long)&rtl8192cu_fops},
9209{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x2e2e, 0xff, 0xff, 0xff),
9210 .driver_info = (unsigned long)&rtl8192cu_fops},
9211{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0019, 0xff, 0xff, 0xff),
9212 .driver_info = (unsigned long)&rtl8192cu_fops},
9213{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0020, 0xff, 0xff, 0xff),
9214 .driver_info = (unsigned long)&rtl8192cu_fops},
9215{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3307, 0xff, 0xff, 0xff),
9216 .driver_info = (unsigned long)&rtl8192cu_fops},
9217{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3309, 0xff, 0xff, 0xff),
9218 .driver_info = (unsigned long)&rtl8192cu_fops},
9219{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330a, 0xff, 0xff, 0xff),
9220 .driver_info = (unsigned long)&rtl8192cu_fops},
9221{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2b, 0xff, 0xff, 0xff),
9222 .driver_info = (unsigned long)&rtl8192cu_fops},
9223{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x624d, 0xff, 0xff, 0xff),
9224 .driver_info = (unsigned long)&rtl8192cu_fops},
9225{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0100, 0xff, 0xff, 0xff),
9226 .driver_info = (unsigned long)&rtl8192cu_fops},
9227{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0091, 0xff, 0xff, 0xff),
9228 .driver_info = (unsigned long)&rtl8192cu_fops},
9229{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7822, 0xff, 0xff, 0xff),
9230 .driver_info = (unsigned long)&rtl8192cu_fops},
9231#endif
9232{ }
9233};
9234
9235static struct usb_driver rtl8xxxu_driver = {
9236 .name = DRIVER_NAME,
9237 .probe = rtl8xxxu_probe,
9238 .disconnect = rtl8xxxu_disconnect,
9239 .id_table = dev_table,
9240 .disable_hub_initiated_lpm = 1,
9241};
9242
9243static int __init rtl8xxxu_module_init(void)
9244{
9245 int res;
9246
9247 res = usb_register(&rtl8xxxu_driver);
9248 if (res < 0)
9249 pr_err(DRIVER_NAME ": usb_register() failed (%i)\n", res);
9250
9251 return res;
9252}
9253
9254static void __exit rtl8xxxu_module_exit(void)
9255{
9256 usb_deregister(&rtl8xxxu_driver);
9257}
9258
9259
9260MODULE_DEVICE_TABLE(usb, dev_table);
9261
9262module_init(rtl8xxxu_module_init);
9263module_exit(rtl8xxxu_module_exit);