blob: 7a1c094f1f88af4f70263d541da48c729dd955dd [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[] = {
94 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2412,
95 .hw_value = 1, .max_power = 30 },
96 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417,
97 .hw_value = 2, .max_power = 30 },
98 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422,
99 .hw_value = 3, .max_power = 30 },
100 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427,
101 .hw_value = 4, .max_power = 30 },
102 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432,
103 .hw_value = 5, .max_power = 30 },
104 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437,
105 .hw_value = 6, .max_power = 30 },
106 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442,
107 .hw_value = 7, .max_power = 30 },
108 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447,
109 .hw_value = 8, .max_power = 30 },
110 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452,
111 .hw_value = 9, .max_power = 30 },
112 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457,
113 .hw_value = 10, .max_power = 30 },
114 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462,
115 .hw_value = 11, .max_power = 30 },
116 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467,
117 .hw_value = 12, .max_power = 30 },
118 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472,
119 .hw_value = 13, .max_power = 30 },
120 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484,
121 .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 Sorensen26f1fad2015-10-14 20:44:51 -0400187static struct rtl8xxxu_reg32val rtl8723a_phy_1t_init_table[] = {
188 {0x800, 0x80040000}, {0x804, 0x00000003},
189 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
190 {0x810, 0x10001331}, {0x814, 0x020c3d10},
191 {0x818, 0x02200385}, {0x81c, 0x00000000},
192 {0x820, 0x01000100}, {0x824, 0x00390004},
193 {0x828, 0x00000000}, {0x82c, 0x00000000},
194 {0x830, 0x00000000}, {0x834, 0x00000000},
195 {0x838, 0x00000000}, {0x83c, 0x00000000},
196 {0x840, 0x00010000}, {0x844, 0x00000000},
197 {0x848, 0x00000000}, {0x84c, 0x00000000},
198 {0x850, 0x00000000}, {0x854, 0x00000000},
199 {0x858, 0x569a569a}, {0x85c, 0x001b25a4},
200 {0x860, 0x66f60110}, {0x864, 0x061f0130},
201 {0x868, 0x00000000}, {0x86c, 0x32323200},
202 {0x870, 0x07000760}, {0x874, 0x22004000},
203 {0x878, 0x00000808}, {0x87c, 0x00000000},
204 {0x880, 0xc0083070}, {0x884, 0x000004d5},
205 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
206 {0x890, 0x00000800}, {0x894, 0xfffffffe},
207 {0x898, 0x40302010}, {0x89c, 0x00706050},
208 {0x900, 0x00000000}, {0x904, 0x00000023},
209 {0x908, 0x00000000}, {0x90c, 0x81121111},
210 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
211 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
212 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
213 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
214 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
215 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
216 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
217 {0xa78, 0x00000900},
218 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
219 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
220 {0xc10, 0x08800000}, {0xc14, 0x40000100},
221 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
222 {0xc20, 0x00000000}, {0xc24, 0x00000000},
223 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
224 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
225 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
226 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
227 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
228 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
229 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
230 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
231 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
232 {0xc70, 0x2c7f000d}, {0xc74, 0x018610db},
233 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
234 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
235 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
236 {0xc90, 0x00121820}, {0xc94, 0x00000000},
237 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
238 {0xca0, 0x00000000}, {0xca4, 0x00000080},
239 {0xca8, 0x00000000}, {0xcac, 0x00000000},
240 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
241 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
242 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
243 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
244 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
245 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
246 {0xce0, 0x00222222}, {0xce4, 0x00000000},
247 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
248 {0xd00, 0x00080740}, {0xd04, 0x00020401},
249 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
250 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
251 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
252 {0xd30, 0x00000000}, {0xd34, 0x80608000},
253 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
254 {0xd40, 0x00000000}, {0xd44, 0x00000000},
255 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
256 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
257 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
258 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
259 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
260 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
261 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
262 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
263 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
264 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
265 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
266 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
267 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
268 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
269 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
270 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
271 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
272 {0xe68, 0x001b25a4}, {0xe6c, 0x631b25a0},
273 {0xe70, 0x631b25a0}, {0xe74, 0x081b25a0},
274 {0xe78, 0x081b25a0}, {0xe7c, 0x081b25a0},
275 {0xe80, 0x081b25a0}, {0xe84, 0x631b25a0},
276 {0xe88, 0x081b25a0}, {0xe8c, 0x631b25a0},
277 {0xed0, 0x631b25a0}, {0xed4, 0x631b25a0},
278 {0xed8, 0x631b25a0}, {0xedc, 0x001b25a0},
279 {0xee0, 0x001b25a0}, {0xeec, 0x6b1b25a0},
280 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
281 {0xf00, 0x00000300},
282 {0xffff, 0xffffffff},
283};
284
Jes Sorensen36c32582016-02-29 17:04:14 -0500285static struct rtl8xxxu_reg32val rtl8723b_phy_1t_init_table[] = {
286 {0x800, 0x80040000}, {0x804, 0x00000003},
287 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
288 {0x810, 0x10001331}, {0x814, 0x020c3d10},
289 {0x818, 0x02200385}, {0x81c, 0x00000000},
290 {0x820, 0x01000100}, {0x824, 0x00190204},
291 {0x828, 0x00000000}, {0x82c, 0x00000000},
292 {0x830, 0x00000000}, {0x834, 0x00000000},
293 {0x838, 0x00000000}, {0x83c, 0x00000000},
294 {0x840, 0x00010000}, {0x844, 0x00000000},
295 {0x848, 0x00000000}, {0x84c, 0x00000000},
296 {0x850, 0x00000000}, {0x854, 0x00000000},
297 {0x858, 0x569a11a9}, {0x85c, 0x01000014},
298 {0x860, 0x66f60110}, {0x864, 0x061f0649},
299 {0x868, 0x00000000}, {0x86c, 0x27272700},
300 {0x870, 0x07000760}, {0x874, 0x25004000},
301 {0x878, 0x00000808}, {0x87c, 0x00000000},
302 {0x880, 0xb0000c1c}, {0x884, 0x00000001},
303 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
304 {0x890, 0x00000800}, {0x894, 0xfffffffe},
305 {0x898, 0x40302010}, {0x89c, 0x00706050},
306 {0x900, 0x00000000}, {0x904, 0x00000023},
307 {0x908, 0x00000000}, {0x90c, 0x81121111},
308 {0x910, 0x00000002}, {0x914, 0x00000201},
309 {0xa00, 0x00d047c8}, {0xa04, 0x80ff800c},
310 {0xa08, 0x8c838300}, {0xa0c, 0x2e7f120f},
311 {0xa10, 0x9500bb78}, {0xa14, 0x1114d028},
312 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
313 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
314 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
315 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
316 {0xa78, 0x00000900}, {0xa7c, 0x225b0606},
317 {0xa80, 0x21806490}, {0xb2c, 0x00000000},
318 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
319 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
320 {0xc10, 0x08800000}, {0xc14, 0x40000100},
321 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
322 {0xc20, 0x00000000}, {0xc24, 0x00000000},
323 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
324 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
325 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
326 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
327 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
328 {0xc50, 0x69553420}, {0xc54, 0x43bc0094},
329 {0xc58, 0x00013149}, {0xc5c, 0x00250492},
330 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
331 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
332 {0xc70, 0x2c7f000d}, {0xc74, 0x020610db},
333 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
334 {0xc80, 0x390000e4}, {0xc84, 0x20f60000},
335 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
336 {0xc90, 0x00020e1a}, {0xc94, 0x00000000},
337 {0xc98, 0x00020e1a}, {0xc9c, 0x00007f7f},
338 {0xca0, 0x00000000}, {0xca4, 0x000300a0},
339 {0xca8, 0x00000000}, {0xcac, 0x00000000},
340 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
341 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
342 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
343 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
344 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
345 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
346 {0xce0, 0x00222222}, {0xce4, 0x00000000},
347 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
348 {0xd00, 0x00000740}, {0xd04, 0x40020401},
349 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
350 {0xd10, 0xa0633333}, {0xd14, 0x3333bc53},
351 {0xd18, 0x7a8f5b6f}, {0xd2c, 0xcc979975},
352 {0xd30, 0x00000000}, {0xd34, 0x80608000},
353 {0xd38, 0x00000000}, {0xd3c, 0x00127353},
354 {0xd40, 0x00000000}, {0xd44, 0x00000000},
355 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
356 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
357 {0xd58, 0x00000282}, {0xd5c, 0x30032064},
358 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
359 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
360 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
361 {0xd78, 0x000e3c24}, {0xe00, 0x2d2d2d2d},
362 {0xe04, 0x2d2d2d2d}, {0xe08, 0x0390272d},
363 {0xe10, 0x2d2d2d2d}, {0xe14, 0x2d2d2d2d},
364 {0xe18, 0x2d2d2d2d}, {0xe1c, 0x2d2d2d2d},
365 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
366 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
367 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
368 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
369 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
370 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
371 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
372 {0xe68, 0x001b2556}, {0xe6c, 0x00c00096},
373 {0xe70, 0x00c00096}, {0xe74, 0x01000056},
374 {0xe78, 0x01000014}, {0xe7c, 0x01000056},
375 {0xe80, 0x01000014}, {0xe84, 0x00c00096},
376 {0xe88, 0x01000056}, {0xe8c, 0x00c00096},
377 {0xed0, 0x00c00096}, {0xed4, 0x00c00096},
378 {0xed8, 0x00c00096}, {0xedc, 0x000000d6},
379 {0xee0, 0x000000d6}, {0xeec, 0x01c00016},
380 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
381 {0xf00, 0x00000300},
382 {0x820, 0x01000100}, {0x800, 0x83040000},
383 {0xffff, 0xffffffff},
384};
385
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400386static struct rtl8xxxu_reg32val rtl8192cu_phy_2t_init_table[] = {
387 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
388 {0x800, 0x80040002}, {0x804, 0x00000003},
389 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
390 {0x810, 0x10000330}, {0x814, 0x020c3d10},
391 {0x818, 0x02200385}, {0x81c, 0x00000000},
392 {0x820, 0x01000100}, {0x824, 0x00390004},
393 {0x828, 0x01000100}, {0x82c, 0x00390004},
394 {0x830, 0x27272727}, {0x834, 0x27272727},
395 {0x838, 0x27272727}, {0x83c, 0x27272727},
396 {0x840, 0x00010000}, {0x844, 0x00010000},
397 {0x848, 0x27272727}, {0x84c, 0x27272727},
398 {0x850, 0x00000000}, {0x854, 0x00000000},
399 {0x858, 0x569a569a}, {0x85c, 0x0c1b25a4},
400 {0x860, 0x66e60230}, {0x864, 0x061f0130},
401 {0x868, 0x27272727}, {0x86c, 0x2b2b2b27},
402 {0x870, 0x07000700}, {0x874, 0x22184000},
403 {0x878, 0x08080808}, {0x87c, 0x00000000},
404 {0x880, 0xc0083070}, {0x884, 0x000004d5},
405 {0x888, 0x00000000}, {0x88c, 0xcc0000c0},
406 {0x890, 0x00000800}, {0x894, 0xfffffffe},
407 {0x898, 0x40302010}, {0x89c, 0x00706050},
408 {0x900, 0x00000000}, {0x904, 0x00000023},
409 {0x908, 0x00000000}, {0x90c, 0x81121313},
410 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
411 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
412 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
413 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
414 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
415 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
416 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
417 {0xc00, 0x48071d40}, {0xc04, 0x03a05633},
418 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
419 {0xc10, 0x08800000}, {0xc14, 0x40000100},
420 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
421 {0xc20, 0x00000000}, {0xc24, 0x00000000},
422 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
423 {0xc30, 0x69e9ac44}, {0xc34, 0x469652cf},
424 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
425 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
426 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
427 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
428 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
429 {0xc60, 0x00000000}, {0xc64, 0x5116848b},
430 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
431 {0xc70, 0x2c7f000d}, {0xc74, 0x2186115b},
432 {0xc78, 0x0000001f}, {0xc7c, 0x00b99612},
433 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
434 {0xc88, 0x40000100}, {0xc8c, 0xa0e40000},
435 {0xc90, 0x00121820}, {0xc94, 0x00000000},
436 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
437 {0xca0, 0x00000000}, {0xca4, 0x00000080},
438 {0xca8, 0x00000000}, {0xcac, 0x00000000},
439 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
440 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
441 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
442 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
443 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
444 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
445 {0xce0, 0x00222222}, {0xce4, 0x00000000},
446 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
447 {0xd00, 0x00080740}, {0xd04, 0x00020403},
448 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
449 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
450 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
451 {0xd30, 0x00000000}, {0xd34, 0x80608000},
452 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
453 {0xd40, 0x00000000}, {0xd44, 0x00000000},
454 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
455 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
456 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
457 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
458 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
459 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
460 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
461 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
462 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
463 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
464 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
465 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
466 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
467 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
468 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
469 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
470 {0xe5c, 0x28160d05}, {0xe60, 0x00000010},
471 {0xe68, 0x001b25a4}, {0xe6c, 0x63db25a4},
472 {0xe70, 0x63db25a4}, {0xe74, 0x0c1b25a4},
473 {0xe78, 0x0c1b25a4}, {0xe7c, 0x0c1b25a4},
474 {0xe80, 0x0c1b25a4}, {0xe84, 0x63db25a4},
475 {0xe88, 0x0c1b25a4}, {0xe8c, 0x63db25a4},
476 {0xed0, 0x63db25a4}, {0xed4, 0x63db25a4},
477 {0xed8, 0x63db25a4}, {0xedc, 0x001b25a4},
478 {0xee0, 0x001b25a4}, {0xeec, 0x6fdb25a4},
479 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
480 {0xf00, 0x00000300},
481 {0xffff, 0xffffffff},
482};
483
484static struct rtl8xxxu_reg32val rtl8188ru_phy_1t_highpa_table[] = {
485 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
486 {0x040, 0x000c0004}, {0x800, 0x80040000},
487 {0x804, 0x00000001}, {0x808, 0x0000fc00},
488 {0x80c, 0x0000000a}, {0x810, 0x10005388},
489 {0x814, 0x020c3d10}, {0x818, 0x02200385},
490 {0x81c, 0x00000000}, {0x820, 0x01000100},
491 {0x824, 0x00390204}, {0x828, 0x00000000},
492 {0x82c, 0x00000000}, {0x830, 0x00000000},
493 {0x834, 0x00000000}, {0x838, 0x00000000},
494 {0x83c, 0x00000000}, {0x840, 0x00010000},
495 {0x844, 0x00000000}, {0x848, 0x00000000},
496 {0x84c, 0x00000000}, {0x850, 0x00000000},
497 {0x854, 0x00000000}, {0x858, 0x569a569a},
498 {0x85c, 0x001b25a4}, {0x860, 0x66e60230},
499 {0x864, 0x061f0130}, {0x868, 0x00000000},
500 {0x86c, 0x20202000}, {0x870, 0x03000300},
501 {0x874, 0x22004000}, {0x878, 0x00000808},
502 {0x87c, 0x00ffc3f1}, {0x880, 0xc0083070},
503 {0x884, 0x000004d5}, {0x888, 0x00000000},
504 {0x88c, 0xccc000c0}, {0x890, 0x00000800},
505 {0x894, 0xfffffffe}, {0x898, 0x40302010},
506 {0x89c, 0x00706050}, {0x900, 0x00000000},
507 {0x904, 0x00000023}, {0x908, 0x00000000},
508 {0x90c, 0x81121111}, {0xa00, 0x00d047c8},
509 {0xa04, 0x80ff000c}, {0xa08, 0x8c838300},
510 {0xa0c, 0x2e68120f}, {0xa10, 0x9500bb78},
511 {0xa14, 0x11144028}, {0xa18, 0x00881117},
512 {0xa1c, 0x89140f00}, {0xa20, 0x15160000},
513 {0xa24, 0x070b0f12}, {0xa28, 0x00000104},
514 {0xa2c, 0x00d30000}, {0xa70, 0x101fbf00},
515 {0xa74, 0x00000007}, {0xc00, 0x48071d40},
516 {0xc04, 0x03a05611}, {0xc08, 0x000000e4},
517 {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000},
518 {0xc14, 0x40000100}, {0xc18, 0x08800000},
519 {0xc1c, 0x40000100}, {0xc20, 0x00000000},
520 {0xc24, 0x00000000}, {0xc28, 0x00000000},
521 {0xc2c, 0x00000000}, {0xc30, 0x69e9ac44},
522 {0xc34, 0x469652cf}, {0xc38, 0x49795994},
523 {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f},
524 {0xc44, 0x000100b7}, {0xc48, 0xec020107},
525 {0xc4c, 0x007f037f}, {0xc50, 0x6954342e},
526 {0xc54, 0x43bc0094}, {0xc58, 0x6954342f},
527 {0xc5c, 0x433c0094}, {0xc60, 0x00000000},
528 {0xc64, 0x5116848b}, {0xc68, 0x47c00bff},
529 {0xc6c, 0x00000036}, {0xc70, 0x2c46000d},
530 {0xc74, 0x018610db}, {0xc78, 0x0000001f},
531 {0xc7c, 0x00b91612}, {0xc80, 0x24000090},
532 {0xc84, 0x20f60000}, {0xc88, 0x24000090},
533 {0xc8c, 0x20200000}, {0xc90, 0x00121820},
534 {0xc94, 0x00000000}, {0xc98, 0x00121820},
535 {0xc9c, 0x00007f7f}, {0xca0, 0x00000000},
536 {0xca4, 0x00000080}, {0xca8, 0x00000000},
537 {0xcac, 0x00000000}, {0xcb0, 0x00000000},
538 {0xcb4, 0x00000000}, {0xcb8, 0x00000000},
539 {0xcbc, 0x28000000}, {0xcc0, 0x00000000},
540 {0xcc4, 0x00000000}, {0xcc8, 0x00000000},
541 {0xccc, 0x00000000}, {0xcd0, 0x00000000},
542 {0xcd4, 0x00000000}, {0xcd8, 0x64b22427},
543 {0xcdc, 0x00766932}, {0xce0, 0x00222222},
544 {0xce4, 0x00000000}, {0xce8, 0x37644302},
545 {0xcec, 0x2f97d40c}, {0xd00, 0x00080740},
546 {0xd04, 0x00020401}, {0xd08, 0x0000907f},
547 {0xd0c, 0x20010201}, {0xd10, 0xa0633333},
548 {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b},
549 {0xd2c, 0xcc979975}, {0xd30, 0x00000000},
550 {0xd34, 0x80608000}, {0xd38, 0x00000000},
551 {0xd3c, 0x00027293}, {0xd40, 0x00000000},
552 {0xd44, 0x00000000}, {0xd48, 0x00000000},
553 {0xd4c, 0x00000000}, {0xd50, 0x6437140a},
554 {0xd54, 0x00000000}, {0xd58, 0x00000000},
555 {0xd5c, 0x30032064}, {0xd60, 0x4653de68},
556 {0xd64, 0x04518a3c}, {0xd68, 0x00002101},
557 {0xd6c, 0x2a201c16}, {0xd70, 0x1812362e},
558 {0xd74, 0x322c2220}, {0xd78, 0x000e3c24},
559 {0xe00, 0x24242424}, {0xe04, 0x24242424},
560 {0xe08, 0x03902024}, {0xe10, 0x24242424},
561 {0xe14, 0x24242424}, {0xe18, 0x24242424},
562 {0xe1c, 0x24242424}, {0xe28, 0x00000000},
563 {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f},
564 {0xe38, 0x02140102}, {0xe3c, 0x681604c2},
565 {0xe40, 0x01007c00}, {0xe44, 0x01004800},
566 {0xe48, 0xfb000000}, {0xe4c, 0x000028d1},
567 {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f},
568 {0xe58, 0x02140102}, {0xe5c, 0x28160d05},
569 {0xe60, 0x00000008}, {0xe68, 0x001b25a4},
570 {0xe6c, 0x631b25a0}, {0xe70, 0x631b25a0},
571 {0xe74, 0x081b25a0}, {0xe78, 0x081b25a0},
572 {0xe7c, 0x081b25a0}, {0xe80, 0x081b25a0},
573 {0xe84, 0x631b25a0}, {0xe88, 0x081b25a0},
574 {0xe8c, 0x631b25a0}, {0xed0, 0x631b25a0},
575 {0xed4, 0x631b25a0}, {0xed8, 0x631b25a0},
576 {0xedc, 0x001b25a0}, {0xee0, 0x001b25a0},
577 {0xeec, 0x6b1b25a0}, {0xee8, 0x31555448},
578 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
579 {0xf00, 0x00000300},
580 {0xffff, 0xffffffff},
581};
582
583static struct rtl8xxxu_reg32val rtl8xxx_agc_standard_table[] = {
584 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
585 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
586 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
587 {0xc78, 0x7a060001}, {0xc78, 0x79070001},
588 {0xc78, 0x78080001}, {0xc78, 0x77090001},
589 {0xc78, 0x760a0001}, {0xc78, 0x750b0001},
590 {0xc78, 0x740c0001}, {0xc78, 0x730d0001},
591 {0xc78, 0x720e0001}, {0xc78, 0x710f0001},
592 {0xc78, 0x70100001}, {0xc78, 0x6f110001},
593 {0xc78, 0x6e120001}, {0xc78, 0x6d130001},
594 {0xc78, 0x6c140001}, {0xc78, 0x6b150001},
595 {0xc78, 0x6a160001}, {0xc78, 0x69170001},
596 {0xc78, 0x68180001}, {0xc78, 0x67190001},
597 {0xc78, 0x661a0001}, {0xc78, 0x651b0001},
598 {0xc78, 0x641c0001}, {0xc78, 0x631d0001},
599 {0xc78, 0x621e0001}, {0xc78, 0x611f0001},
600 {0xc78, 0x60200001}, {0xc78, 0x49210001},
601 {0xc78, 0x48220001}, {0xc78, 0x47230001},
602 {0xc78, 0x46240001}, {0xc78, 0x45250001},
603 {0xc78, 0x44260001}, {0xc78, 0x43270001},
604 {0xc78, 0x42280001}, {0xc78, 0x41290001},
605 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
606 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
607 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
608 {0xc78, 0x21300001}, {0xc78, 0x20310001},
609 {0xc78, 0x06320001}, {0xc78, 0x05330001},
610 {0xc78, 0x04340001}, {0xc78, 0x03350001},
611 {0xc78, 0x02360001}, {0xc78, 0x01370001},
612 {0xc78, 0x00380001}, {0xc78, 0x00390001},
613 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
614 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
615 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
616 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
617 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
618 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
619 {0xc78, 0x7a460001}, {0xc78, 0x79470001},
620 {0xc78, 0x78480001}, {0xc78, 0x77490001},
621 {0xc78, 0x764a0001}, {0xc78, 0x754b0001},
622 {0xc78, 0x744c0001}, {0xc78, 0x734d0001},
623 {0xc78, 0x724e0001}, {0xc78, 0x714f0001},
624 {0xc78, 0x70500001}, {0xc78, 0x6f510001},
625 {0xc78, 0x6e520001}, {0xc78, 0x6d530001},
626 {0xc78, 0x6c540001}, {0xc78, 0x6b550001},
627 {0xc78, 0x6a560001}, {0xc78, 0x69570001},
628 {0xc78, 0x68580001}, {0xc78, 0x67590001},
629 {0xc78, 0x665a0001}, {0xc78, 0x655b0001},
630 {0xc78, 0x645c0001}, {0xc78, 0x635d0001},
631 {0xc78, 0x625e0001}, {0xc78, 0x615f0001},
632 {0xc78, 0x60600001}, {0xc78, 0x49610001},
633 {0xc78, 0x48620001}, {0xc78, 0x47630001},
634 {0xc78, 0x46640001}, {0xc78, 0x45650001},
635 {0xc78, 0x44660001}, {0xc78, 0x43670001},
636 {0xc78, 0x42680001}, {0xc78, 0x41690001},
637 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
638 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
639 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
640 {0xc78, 0x21700001}, {0xc78, 0x20710001},
641 {0xc78, 0x06720001}, {0xc78, 0x05730001},
642 {0xc78, 0x04740001}, {0xc78, 0x03750001},
643 {0xc78, 0x02760001}, {0xc78, 0x01770001},
644 {0xc78, 0x00780001}, {0xc78, 0x00790001},
645 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
646 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
647 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
648 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
649 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
650 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
651 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
652 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
653 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
654 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
655 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
656 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
657 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
658 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
659 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
660 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
661 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
662 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
663 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
664 {0xffff, 0xffffffff}
665};
666
667static struct rtl8xxxu_reg32val rtl8xxx_agc_highpa_table[] = {
668 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
669 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
670 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
671 {0xc78, 0x7b060001}, {0xc78, 0x7b070001},
672 {0xc78, 0x7b080001}, {0xc78, 0x7a090001},
673 {0xc78, 0x790a0001}, {0xc78, 0x780b0001},
674 {0xc78, 0x770c0001}, {0xc78, 0x760d0001},
675 {0xc78, 0x750e0001}, {0xc78, 0x740f0001},
676 {0xc78, 0x73100001}, {0xc78, 0x72110001},
677 {0xc78, 0x71120001}, {0xc78, 0x70130001},
678 {0xc78, 0x6f140001}, {0xc78, 0x6e150001},
679 {0xc78, 0x6d160001}, {0xc78, 0x6c170001},
680 {0xc78, 0x6b180001}, {0xc78, 0x6a190001},
681 {0xc78, 0x691a0001}, {0xc78, 0x681b0001},
682 {0xc78, 0x671c0001}, {0xc78, 0x661d0001},
683 {0xc78, 0x651e0001}, {0xc78, 0x641f0001},
684 {0xc78, 0x63200001}, {0xc78, 0x62210001},
685 {0xc78, 0x61220001}, {0xc78, 0x60230001},
686 {0xc78, 0x46240001}, {0xc78, 0x45250001},
687 {0xc78, 0x44260001}, {0xc78, 0x43270001},
688 {0xc78, 0x42280001}, {0xc78, 0x41290001},
689 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
690 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
691 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
692 {0xc78, 0x21300001}, {0xc78, 0x20310001},
693 {0xc78, 0x06320001}, {0xc78, 0x05330001},
694 {0xc78, 0x04340001}, {0xc78, 0x03350001},
695 {0xc78, 0x02360001}, {0xc78, 0x01370001},
696 {0xc78, 0x00380001}, {0xc78, 0x00390001},
697 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
698 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
699 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
700 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
701 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
702 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
703 {0xc78, 0x7b460001}, {0xc78, 0x7b470001},
704 {0xc78, 0x7b480001}, {0xc78, 0x7a490001},
705 {0xc78, 0x794a0001}, {0xc78, 0x784b0001},
706 {0xc78, 0x774c0001}, {0xc78, 0x764d0001},
707 {0xc78, 0x754e0001}, {0xc78, 0x744f0001},
708 {0xc78, 0x73500001}, {0xc78, 0x72510001},
709 {0xc78, 0x71520001}, {0xc78, 0x70530001},
710 {0xc78, 0x6f540001}, {0xc78, 0x6e550001},
711 {0xc78, 0x6d560001}, {0xc78, 0x6c570001},
712 {0xc78, 0x6b580001}, {0xc78, 0x6a590001},
713 {0xc78, 0x695a0001}, {0xc78, 0x685b0001},
714 {0xc78, 0x675c0001}, {0xc78, 0x665d0001},
715 {0xc78, 0x655e0001}, {0xc78, 0x645f0001},
716 {0xc78, 0x63600001}, {0xc78, 0x62610001},
717 {0xc78, 0x61620001}, {0xc78, 0x60630001},
718 {0xc78, 0x46640001}, {0xc78, 0x45650001},
719 {0xc78, 0x44660001}, {0xc78, 0x43670001},
720 {0xc78, 0x42680001}, {0xc78, 0x41690001},
721 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
722 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
723 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
724 {0xc78, 0x21700001}, {0xc78, 0x20710001},
725 {0xc78, 0x06720001}, {0xc78, 0x05730001},
726 {0xc78, 0x04740001}, {0xc78, 0x03750001},
727 {0xc78, 0x02760001}, {0xc78, 0x01770001},
728 {0xc78, 0x00780001}, {0xc78, 0x00790001},
729 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
730 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
731 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
732 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
733 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
734 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
735 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
736 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
737 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
738 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
739 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
740 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
741 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
742 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
743 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
744 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
745 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
746 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
747 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
748 {0xffff, 0xffffffff}
749};
750
Jes Sorensenb9f498e2016-02-29 17:04:18 -0500751static struct rtl8xxxu_reg32val rtl8xxx_agc_8723bu_table[] = {
752 {0xc78, 0xfd000001}, {0xc78, 0xfc010001},
753 {0xc78, 0xfb020001}, {0xc78, 0xfa030001},
754 {0xc78, 0xf9040001}, {0xc78, 0xf8050001},
755 {0xc78, 0xf7060001}, {0xc78, 0xf6070001},
756 {0xc78, 0xf5080001}, {0xc78, 0xf4090001},
757 {0xc78, 0xf30a0001}, {0xc78, 0xf20b0001},
758 {0xc78, 0xf10c0001}, {0xc78, 0xf00d0001},
759 {0xc78, 0xef0e0001}, {0xc78, 0xee0f0001},
760 {0xc78, 0xed100001}, {0xc78, 0xec110001},
761 {0xc78, 0xeb120001}, {0xc78, 0xea130001},
762 {0xc78, 0xe9140001}, {0xc78, 0xe8150001},
763 {0xc78, 0xe7160001}, {0xc78, 0xe6170001},
764 {0xc78, 0xe5180001}, {0xc78, 0xe4190001},
765 {0xc78, 0xe31a0001}, {0xc78, 0xa51b0001},
766 {0xc78, 0xa41c0001}, {0xc78, 0xa31d0001},
767 {0xc78, 0x671e0001}, {0xc78, 0x661f0001},
768 {0xc78, 0x65200001}, {0xc78, 0x64210001},
769 {0xc78, 0x63220001}, {0xc78, 0x4a230001},
770 {0xc78, 0x49240001}, {0xc78, 0x48250001},
771 {0xc78, 0x47260001}, {0xc78, 0x46270001},
772 {0xc78, 0x45280001}, {0xc78, 0x44290001},
773 {0xc78, 0x432a0001}, {0xc78, 0x422b0001},
774 {0xc78, 0x292c0001}, {0xc78, 0x282d0001},
775 {0xc78, 0x272e0001}, {0xc78, 0x262f0001},
776 {0xc78, 0x0a300001}, {0xc78, 0x09310001},
777 {0xc78, 0x08320001}, {0xc78, 0x07330001},
778 {0xc78, 0x06340001}, {0xc78, 0x05350001},
779 {0xc78, 0x04360001}, {0xc78, 0x03370001},
780 {0xc78, 0x02380001}, {0xc78, 0x01390001},
781 {0xc78, 0x013a0001}, {0xc78, 0x013b0001},
782 {0xc78, 0x013c0001}, {0xc78, 0x013d0001},
783 {0xc78, 0x013e0001}, {0xc78, 0x013f0001},
784 {0xc78, 0xfc400001}, {0xc78, 0xfb410001},
785 {0xc78, 0xfa420001}, {0xc78, 0xf9430001},
786 {0xc78, 0xf8440001}, {0xc78, 0xf7450001},
787 {0xc78, 0xf6460001}, {0xc78, 0xf5470001},
788 {0xc78, 0xf4480001}, {0xc78, 0xf3490001},
789 {0xc78, 0xf24a0001}, {0xc78, 0xf14b0001},
790 {0xc78, 0xf04c0001}, {0xc78, 0xef4d0001},
791 {0xc78, 0xee4e0001}, {0xc78, 0xed4f0001},
792 {0xc78, 0xec500001}, {0xc78, 0xeb510001},
793 {0xc78, 0xea520001}, {0xc78, 0xe9530001},
794 {0xc78, 0xe8540001}, {0xc78, 0xe7550001},
795 {0xc78, 0xe6560001}, {0xc78, 0xe5570001},
796 {0xc78, 0xe4580001}, {0xc78, 0xe3590001},
797 {0xc78, 0xa65a0001}, {0xc78, 0xa55b0001},
798 {0xc78, 0xa45c0001}, {0xc78, 0xa35d0001},
799 {0xc78, 0x675e0001}, {0xc78, 0x665f0001},
800 {0xc78, 0x65600001}, {0xc78, 0x64610001},
801 {0xc78, 0x63620001}, {0xc78, 0x62630001},
802 {0xc78, 0x61640001}, {0xc78, 0x48650001},
803 {0xc78, 0x47660001}, {0xc78, 0x46670001},
804 {0xc78, 0x45680001}, {0xc78, 0x44690001},
805 {0xc78, 0x436a0001}, {0xc78, 0x426b0001},
806 {0xc78, 0x286c0001}, {0xc78, 0x276d0001},
807 {0xc78, 0x266e0001}, {0xc78, 0x256f0001},
808 {0xc78, 0x24700001}, {0xc78, 0x09710001},
809 {0xc78, 0x08720001}, {0xc78, 0x07730001},
810 {0xc78, 0x06740001}, {0xc78, 0x05750001},
811 {0xc78, 0x04760001}, {0xc78, 0x03770001},
812 {0xc78, 0x02780001}, {0xc78, 0x01790001},
813 {0xc78, 0x017a0001}, {0xc78, 0x017b0001},
814 {0xc78, 0x017c0001}, {0xc78, 0x017d0001},
815 {0xc78, 0x017e0001}, {0xc78, 0x017f0001},
816 {0xc50, 0x69553422},
817 {0xc50, 0x69553420},
818 {0x824, 0x00390204},
819 {0xffff, 0xffffffff}
820};
821
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400822static struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = {
823 {0x00, 0x00030159}, {0x01, 0x00031284},
824 {0x02, 0x00098000}, {0x03, 0x00039c63},
825 {0x04, 0x000210e7}, {0x09, 0x0002044f},
826 {0x0a, 0x0001a3f1}, {0x0b, 0x00014787},
827 {0x0c, 0x000896fe}, {0x0d, 0x0000e02c},
828 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
829 {0x19, 0x00000000}, {0x1a, 0x00030355},
830 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
831 {0x1d, 0x000a1250}, {0x1e, 0x0000024f},
832 {0x1f, 0x00000000}, {0x20, 0x0000b614},
833 {0x21, 0x0006c000}, {0x22, 0x00000000},
834 {0x23, 0x00001558}, {0x24, 0x00000060},
835 {0x25, 0x00000483}, {0x26, 0x0004f000},
836 {0x27, 0x000ec7d9}, {0x28, 0x00057730},
837 {0x29, 0x00004783}, {0x2a, 0x00000001},
838 {0x2b, 0x00021334}, {0x2a, 0x00000000},
839 {0x2b, 0x00000054}, {0x2a, 0x00000001},
840 {0x2b, 0x00000808}, {0x2b, 0x00053333},
841 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
842 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
843 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
844 {0x2b, 0x00000808}, {0x2b, 0x00063333},
845 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
846 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
847 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
848 {0x2b, 0x00000808}, {0x2b, 0x00073333},
849 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
850 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
851 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
852 {0x2b, 0x00000709}, {0x2b, 0x00063333},
853 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
854 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
855 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
856 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
857 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
858 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
859 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
860 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
861 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
862 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
863 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
864 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
865 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
866 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
867 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
868 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
869 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
870 {0x10, 0x0002000f}, {0x11, 0x000203f9},
871 {0x10, 0x0003000f}, {0x11, 0x000ff500},
872 {0x10, 0x00000000}, {0x11, 0x00000000},
873 {0x10, 0x0008000f}, {0x11, 0x0003f100},
874 {0x10, 0x0009000f}, {0x11, 0x00023100},
875 {0x12, 0x00032000}, {0x12, 0x00071000},
876 {0x12, 0x000b0000}, {0x12, 0x000fc000},
877 {0x13, 0x000287b3}, {0x13, 0x000244b7},
878 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
879 {0x13, 0x00018493}, {0x13, 0x0001429b},
880 {0x13, 0x00010299}, {0x13, 0x0000c29c},
881 {0x13, 0x000081a0}, {0x13, 0x000040ac},
882 {0x13, 0x00000020}, {0x14, 0x0001944c},
883 {0x14, 0x00059444}, {0x14, 0x0009944c},
884 {0x14, 0x000d9444}, {0x15, 0x0000f474},
885 {0x15, 0x0004f477}, {0x15, 0x0008f455},
886 {0x15, 0x000cf455}, {0x16, 0x00000339},
887 {0x16, 0x00040339}, {0x16, 0x00080339},
888 {0x16, 0x000c0366}, {0x00, 0x00010159},
889 {0x18, 0x0000f401}, {0xfe, 0x00000000},
890 {0xfe, 0x00000000}, {0x1f, 0x00000003},
891 {0xfe, 0x00000000}, {0xfe, 0x00000000},
892 {0x1e, 0x00000247}, {0x1f, 0x00000000},
893 {0x00, 0x00030159},
894 {0xff, 0xffffffff}
895};
896
Jes Sorensen22a31d42016-02-29 17:04:15 -0500897static struct rtl8xxxu_rfregval rtl8723bu_radioa_1t_init_table[] = {
898 {0x00, 0x00010000}, {0xb0, 0x000dffe0},
899 {0xfe, 0x00000000}, {0xfe, 0x00000000},
900 {0xfe, 0x00000000}, {0xb1, 0x00000018},
901 {0xfe, 0x00000000}, {0xfe, 0x00000000},
902 {0xfe, 0x00000000}, {0xb2, 0x00084c00},
903 {0xb5, 0x0000d2cc}, {0xb6, 0x000925aa},
904 {0xb7, 0x00000010}, {0xb8, 0x0000907f},
905 {0x5c, 0x00000002}, {0x7c, 0x00000002},
906 {0x7e, 0x00000005}, {0x8b, 0x0006fc00},
907 {0xb0, 0x000ff9f0}, {0x1c, 0x000739d2},
908 {0x1e, 0x00000000}, {0xdf, 0x00000780},
909 {0x50, 0x00067435},
910 /*
911 * The 8723bu vendor driver indicates that bit 8 should be set in
912 * 0x51 for package types TFBGA90, TFBGA80, and TFBGA79. However
913 * they never actually check the package type - and just default
914 * to not setting it.
915 */
916 {0x51, 0x0006b04e},
917 {0x52, 0x000007d2}, {0x53, 0x00000000},
918 {0x54, 0x00050400}, {0x55, 0x0004026e},
919 {0xdd, 0x0000004c}, {0x70, 0x00067435},
920 /*
921 * 0x71 has same package type condition as for register 0x51
922 */
923 {0x71, 0x0006b04e},
924 {0x72, 0x000007d2}, {0x73, 0x00000000},
925 {0x74, 0x00050400}, {0x75, 0x0004026e},
926 {0xef, 0x00000100}, {0x34, 0x0000add7},
927 {0x35, 0x00005c00}, {0x34, 0x00009dd4},
928 {0x35, 0x00005000}, {0x34, 0x00008dd1},
929 {0x35, 0x00004400}, {0x34, 0x00007dce},
930 {0x35, 0x00003800}, {0x34, 0x00006cd1},
931 {0x35, 0x00004400}, {0x34, 0x00005cce},
932 {0x35, 0x00003800}, {0x34, 0x000048ce},
933 {0x35, 0x00004400}, {0x34, 0x000034ce},
934 {0x35, 0x00003800}, {0x34, 0x00002451},
935 {0x35, 0x00004400}, {0x34, 0x0000144e},
936 {0x35, 0x00003800}, {0x34, 0x00000051},
937 {0x35, 0x00004400}, {0xef, 0x00000000},
938 {0xef, 0x00000100}, {0xed, 0x00000010},
939 {0x44, 0x0000add7}, {0x44, 0x00009dd4},
940 {0x44, 0x00008dd1}, {0x44, 0x00007dce},
941 {0x44, 0x00006cc1}, {0x44, 0x00005cce},
942 {0x44, 0x000044d1}, {0x44, 0x000034ce},
943 {0x44, 0x00002451}, {0x44, 0x0000144e},
944 {0x44, 0x00000051}, {0xef, 0x00000000},
945 {0xed, 0x00000000}, {0x7f, 0x00020080},
946 {0xef, 0x00002000}, {0x3b, 0x000380ef},
947 {0x3b, 0x000302fe}, {0x3b, 0x00028ce6},
948 {0x3b, 0x000200bc}, {0x3b, 0x000188a5},
949 {0x3b, 0x00010fbc}, {0x3b, 0x00008f71},
950 {0x3b, 0x00000900}, {0xef, 0x00000000},
951 {0xed, 0x00000001}, {0x40, 0x000380ef},
952 {0x40, 0x000302fe}, {0x40, 0x00028ce6},
953 {0x40, 0x000200bc}, {0x40, 0x000188a5},
954 {0x40, 0x00010fbc}, {0x40, 0x00008f71},
955 {0x40, 0x00000900}, {0xed, 0x00000000},
956 {0x82, 0x00080000}, {0x83, 0x00008000},
957 {0x84, 0x00048d80}, {0x85, 0x00068000},
958 {0xa2, 0x00080000}, {0xa3, 0x00008000},
959 {0xa4, 0x00048d80}, {0xa5, 0x00068000},
960 {0xed, 0x00000002}, {0xef, 0x00000002},
961 {0x56, 0x00000032}, {0x76, 0x00000032},
962 {0x01, 0x00000780},
963 {0xff, 0xffffffff}
964};
965
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400966static struct rtl8xxxu_rfregval rtl8192cu_radioa_2t_init_table[] = {
967 {0x00, 0x00030159}, {0x01, 0x00031284},
968 {0x02, 0x00098000}, {0x03, 0x00018c63},
969 {0x04, 0x000210e7}, {0x09, 0x0002044f},
970 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
971 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
972 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
973 {0x19, 0x00000000}, {0x1a, 0x00010255},
974 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
975 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
976 {0x1f, 0x00080001}, {0x20, 0x0000b614},
977 {0x21, 0x0006c000}, {0x22, 0x00000000},
978 {0x23, 0x00001558}, {0x24, 0x00000060},
979 {0x25, 0x00000483}, {0x26, 0x0004f000},
980 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
981 {0x29, 0x00004783}, {0x2a, 0x00000001},
982 {0x2b, 0x00021334}, {0x2a, 0x00000000},
983 {0x2b, 0x00000054}, {0x2a, 0x00000001},
984 {0x2b, 0x00000808}, {0x2b, 0x00053333},
985 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
986 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
987 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
988 {0x2b, 0x00000808}, {0x2b, 0x00063333},
989 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
990 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
991 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
992 {0x2b, 0x00000808}, {0x2b, 0x00073333},
993 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
994 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
995 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
996 {0x2b, 0x00000709}, {0x2b, 0x00063333},
997 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
998 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
999 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1000 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1001 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1002 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1003 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1004 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1005 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1006 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1007 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1008 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1009 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1010 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1011 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1012 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1013 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1014 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1015 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1016 {0x10, 0x00000000}, {0x11, 0x00000000},
1017 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1018 {0x10, 0x0009000f}, {0x11, 0x00023100},
1019 {0x12, 0x00032000}, {0x12, 0x00071000},
1020 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1021 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1022 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1023 {0x13, 0x00018493}, {0x13, 0x0001429b},
1024 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1025 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1026 {0x13, 0x00000020}, {0x14, 0x0001944c},
1027 {0x14, 0x00059444}, {0x14, 0x0009944c},
1028 {0x14, 0x000d9444}, {0x15, 0x0000f424},
1029 {0x15, 0x0004f424}, {0x15, 0x0008f424},
1030 {0x15, 0x000cf424}, {0x16, 0x000e0330},
1031 {0x16, 0x000a0330}, {0x16, 0x00060330},
1032 {0x16, 0x00020330}, {0x00, 0x00010159},
1033 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1034 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1035 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1036 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1037 {0x00, 0x00030159},
1038 {0xff, 0xffffffff}
1039};
1040
1041static struct rtl8xxxu_rfregval rtl8192cu_radiob_2t_init_table[] = {
1042 {0x00, 0x00030159}, {0x01, 0x00031284},
1043 {0x02, 0x00098000}, {0x03, 0x00018c63},
1044 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1045 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1046 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1047 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1048 {0x12, 0x00032000}, {0x12, 0x00071000},
1049 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1050 {0x13, 0x000287af}, {0x13, 0x000244b7},
1051 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1052 {0x13, 0x00018493}, {0x13, 0x00014297},
1053 {0x13, 0x00010295}, {0x13, 0x0000c298},
1054 {0x13, 0x0000819c}, {0x13, 0x000040a8},
1055 {0x13, 0x0000001c}, {0x14, 0x0001944c},
1056 {0x14, 0x00059444}, {0x14, 0x0009944c},
1057 {0x14, 0x000d9444}, {0x15, 0x0000f424},
1058 {0x15, 0x0004f424}, {0x15, 0x0008f424},
1059 {0x15, 0x000cf424}, {0x16, 0x000e0330},
1060 {0x16, 0x000a0330}, {0x16, 0x00060330},
1061 {0x16, 0x00020330},
1062 {0xff, 0xffffffff}
1063};
1064
1065static struct rtl8xxxu_rfregval rtl8192cu_radioa_1t_init_table[] = {
1066 {0x00, 0x00030159}, {0x01, 0x00031284},
1067 {0x02, 0x00098000}, {0x03, 0x00018c63},
1068 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1069 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1070 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1071 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1072 {0x19, 0x00000000}, {0x1a, 0x00010255},
1073 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1074 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1075 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1076 {0x21, 0x0006c000}, {0x22, 0x00000000},
1077 {0x23, 0x00001558}, {0x24, 0x00000060},
1078 {0x25, 0x00000483}, {0x26, 0x0004f000},
1079 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
1080 {0x29, 0x00004783}, {0x2a, 0x00000001},
1081 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1082 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1083 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1084 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1085 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1086 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1087 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1088 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1089 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1090 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1091 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1092 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1093 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1094 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1095 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1096 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1097 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1098 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1099 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1100 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1101 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1102 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1103 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1104 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1105 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1106 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1107 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1108 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1109 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1110 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1111 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1112 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1113 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1114 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1115 {0x10, 0x00000000}, {0x11, 0x00000000},
1116 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1117 {0x10, 0x0009000f}, {0x11, 0x00023100},
1118 {0x12, 0x00032000}, {0x12, 0x00071000},
1119 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1120 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1121 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1122 {0x13, 0x00018493}, {0x13, 0x0001429b},
1123 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1124 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1125 {0x13, 0x00000020}, {0x14, 0x0001944c},
1126 {0x14, 0x00059444}, {0x14, 0x0009944c},
1127 {0x14, 0x000d9444}, {0x15, 0x0000f405},
1128 {0x15, 0x0004f405}, {0x15, 0x0008f405},
1129 {0x15, 0x000cf405}, {0x16, 0x000e0330},
1130 {0x16, 0x000a0330}, {0x16, 0x00060330},
1131 {0x16, 0x00020330}, {0x00, 0x00010159},
1132 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1133 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1134 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1135 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1136 {0x00, 0x00030159},
1137 {0xff, 0xffffffff}
1138};
1139
1140static struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = {
1141 {0x00, 0x00030159}, {0x01, 0x00031284},
1142 {0x02, 0x00098000}, {0x03, 0x00018c63},
1143 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1144 {0x0a, 0x0001adb0}, {0x0b, 0x00054867},
1145 {0x0c, 0x0008992e}, {0x0d, 0x0000e529},
1146 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1147 {0x19, 0x00000000}, {0x1a, 0x00000255},
1148 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1149 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1150 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1151 {0x21, 0x0006c000}, {0x22, 0x0000083c},
1152 {0x23, 0x00001558}, {0x24, 0x00000060},
1153 {0x25, 0x00000483}, {0x26, 0x0004f000},
1154 {0x27, 0x000ec7d9}, {0x28, 0x000977c0},
1155 {0x29, 0x00004783}, {0x2a, 0x00000001},
1156 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1157 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1158 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1159 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1160 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1161 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1162 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1163 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1164 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1165 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1166 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1167 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1168 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1169 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1170 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1171 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1172 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1173 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1174 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1175 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1176 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1177 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1178 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1179 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1180 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1181 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1182 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1183 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1184 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1185 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1186 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1187 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1188 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1189 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1190 {0x10, 0x00000000}, {0x11, 0x00000000},
1191 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1192 {0x10, 0x0009000f}, {0x11, 0x00023100},
1193 {0x12, 0x000d8000}, {0x12, 0x00090000},
1194 {0x12, 0x00051000}, {0x12, 0x00012000},
1195 {0x13, 0x00028fb4}, {0x13, 0x00024fa8},
1196 {0x13, 0x000207a4}, {0x13, 0x0001c3b0},
1197 {0x13, 0x000183a4}, {0x13, 0x00014398},
1198 {0x13, 0x000101a4}, {0x13, 0x0000c198},
1199 {0x13, 0x000080a4}, {0x13, 0x00004098},
1200 {0x13, 0x00000000}, {0x14, 0x0001944c},
1201 {0x14, 0x00059444}, {0x14, 0x0009944c},
1202 {0x14, 0x000d9444}, {0x15, 0x0000f405},
1203 {0x15, 0x0004f405}, {0x15, 0x0008f405},
1204 {0x15, 0x000cf405}, {0x16, 0x000e0330},
1205 {0x16, 0x000a0330}, {0x16, 0x00060330},
1206 {0x16, 0x00020330}, {0x00, 0x00010159},
1207 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1208 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1209 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1210 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1211 {0x00, 0x00030159},
1212 {0xff, 0xffffffff}
1213};
1214
1215static struct rtl8xxxu_rfregs rtl8xxxu_rfregs[] = {
1216 { /* RF_A */
1217 .hssiparm1 = REG_FPGA0_XA_HSSI_PARM1,
1218 .hssiparm2 = REG_FPGA0_XA_HSSI_PARM2,
1219 .lssiparm = REG_FPGA0_XA_LSSI_PARM,
1220 .hspiread = REG_HSPI_XA_READBACK,
1221 .lssiread = REG_FPGA0_XA_LSSI_READBACK,
1222 .rf_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL,
1223 },
1224 { /* RF_B */
1225 .hssiparm1 = REG_FPGA0_XB_HSSI_PARM1,
1226 .hssiparm2 = REG_FPGA0_XB_HSSI_PARM2,
1227 .lssiparm = REG_FPGA0_XB_LSSI_PARM,
1228 .hspiread = REG_HSPI_XB_READBACK,
1229 .lssiread = REG_FPGA0_XB_LSSI_READBACK,
1230 .rf_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL,
1231 },
1232};
1233
1234static const u32 rtl8723au_iqk_phy_iq_bb_reg[RTL8XXXU_BB_REGS] = {
1235 REG_OFDM0_XA_RX_IQ_IMBALANCE,
1236 REG_OFDM0_XB_RX_IQ_IMBALANCE,
1237 REG_OFDM0_ENERGY_CCA_THRES,
1238 REG_OFDM0_AGCR_SSI_TABLE,
1239 REG_OFDM0_XA_TX_IQ_IMBALANCE,
1240 REG_OFDM0_XB_TX_IQ_IMBALANCE,
1241 REG_OFDM0_XC_TX_AFE,
1242 REG_OFDM0_XD_TX_AFE,
1243 REG_OFDM0_RX_IQ_EXT_ANTA
1244};
1245
1246static u8 rtl8xxxu_read8(struct rtl8xxxu_priv *priv, u16 addr)
1247{
1248 struct usb_device *udev = priv->udev;
1249 int len;
1250 u8 data;
1251
1252 mutex_lock(&priv->usb_buf_mutex);
1253 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1254 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1255 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1256 RTW_USB_CONTROL_MSG_TIMEOUT);
1257 data = priv->usb_buf.val8;
1258 mutex_unlock(&priv->usb_buf_mutex);
1259
1260 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1261 dev_info(&udev->dev, "%s(%04x) = 0x%02x, len %i\n",
1262 __func__, addr, data, len);
1263 return data;
1264}
1265
1266static u16 rtl8xxxu_read16(struct rtl8xxxu_priv *priv, u16 addr)
1267{
1268 struct usb_device *udev = priv->udev;
1269 int len;
1270 u16 data;
1271
1272 mutex_lock(&priv->usb_buf_mutex);
1273 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1274 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1275 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1276 RTW_USB_CONTROL_MSG_TIMEOUT);
1277 data = le16_to_cpu(priv->usb_buf.val16);
1278 mutex_unlock(&priv->usb_buf_mutex);
1279
1280 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1281 dev_info(&udev->dev, "%s(%04x) = 0x%04x, len %i\n",
1282 __func__, addr, data, len);
1283 return data;
1284}
1285
1286static u32 rtl8xxxu_read32(struct rtl8xxxu_priv *priv, u16 addr)
1287{
1288 struct usb_device *udev = priv->udev;
1289 int len;
1290 u32 data;
1291
1292 mutex_lock(&priv->usb_buf_mutex);
1293 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1294 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1295 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1296 RTW_USB_CONTROL_MSG_TIMEOUT);
1297 data = le32_to_cpu(priv->usb_buf.val32);
1298 mutex_unlock(&priv->usb_buf_mutex);
1299
1300 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1301 dev_info(&udev->dev, "%s(%04x) = 0x%08x, len %i\n",
1302 __func__, addr, data, len);
1303 return data;
1304}
1305
1306static int rtl8xxxu_write8(struct rtl8xxxu_priv *priv, u16 addr, u8 val)
1307{
1308 struct usb_device *udev = priv->udev;
1309 int ret;
1310
1311 mutex_lock(&priv->usb_buf_mutex);
1312 priv->usb_buf.val8 = val;
1313 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1314 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1315 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1316 RTW_USB_CONTROL_MSG_TIMEOUT);
1317
1318 mutex_unlock(&priv->usb_buf_mutex);
1319
1320 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1321 dev_info(&udev->dev, "%s(%04x) = 0x%02x\n",
1322 __func__, addr, val);
1323 return ret;
1324}
1325
1326static int rtl8xxxu_write16(struct rtl8xxxu_priv *priv, u16 addr, u16 val)
1327{
1328 struct usb_device *udev = priv->udev;
1329 int ret;
1330
1331 mutex_lock(&priv->usb_buf_mutex);
1332 priv->usb_buf.val16 = cpu_to_le16(val);
1333 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1334 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1335 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1336 RTW_USB_CONTROL_MSG_TIMEOUT);
1337 mutex_unlock(&priv->usb_buf_mutex);
1338
1339 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1340 dev_info(&udev->dev, "%s(%04x) = 0x%04x\n",
1341 __func__, addr, val);
1342 return ret;
1343}
1344
1345static int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val)
1346{
1347 struct usb_device *udev = priv->udev;
1348 int ret;
1349
1350 mutex_lock(&priv->usb_buf_mutex);
1351 priv->usb_buf.val32 = cpu_to_le32(val);
1352 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1353 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1354 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1355 RTW_USB_CONTROL_MSG_TIMEOUT);
1356 mutex_unlock(&priv->usb_buf_mutex);
1357
1358 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1359 dev_info(&udev->dev, "%s(%04x) = 0x%08x\n",
1360 __func__, addr, val);
1361 return ret;
1362}
1363
1364static int
1365rtl8xxxu_writeN(struct rtl8xxxu_priv *priv, u16 addr, u8 *buf, u16 len)
1366{
1367 struct usb_device *udev = priv->udev;
1368 int blocksize = priv->fops->writeN_block_size;
1369 int ret, i, count, remainder;
1370
1371 count = len / blocksize;
1372 remainder = len % blocksize;
1373
1374 for (i = 0; i < count; i++) {
1375 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1376 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1377 addr, 0, buf, blocksize,
1378 RTW_USB_CONTROL_MSG_TIMEOUT);
1379 if (ret != blocksize)
1380 goto write_error;
1381
1382 addr += blocksize;
1383 buf += blocksize;
1384 }
1385
1386 if (remainder) {
1387 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1388 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1389 addr, 0, buf, remainder,
1390 RTW_USB_CONTROL_MSG_TIMEOUT);
1391 if (ret != remainder)
1392 goto write_error;
1393 }
1394
1395 return len;
1396
1397write_error:
1398 dev_info(&udev->dev,
1399 "%s: Failed to write block at addr: %04x size: %04x\n",
1400 __func__, addr, blocksize);
1401 return -EAGAIN;
1402}
1403
1404static u32 rtl8xxxu_read_rfreg(struct rtl8xxxu_priv *priv,
1405 enum rtl8xxxu_rfpath path, u8 reg)
1406{
1407 u32 hssia, val32, retval;
1408
1409 hssia = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2);
1410 if (path != RF_A)
1411 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm2);
1412 else
1413 val32 = hssia;
1414
1415 val32 &= ~FPGA0_HSSI_PARM2_ADDR_MASK;
1416 val32 |= (reg << FPGA0_HSSI_PARM2_ADDR_SHIFT);
1417 val32 |= FPGA0_HSSI_PARM2_EDGE_READ;
1418 hssia &= ~FPGA0_HSSI_PARM2_EDGE_READ;
1419 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1420
1421 udelay(10);
1422
1423 rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].hssiparm2, val32);
1424 udelay(100);
1425
1426 hssia |= FPGA0_HSSI_PARM2_EDGE_READ;
1427 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1428 udelay(10);
1429
1430 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm1);
1431 if (val32 & FPGA0_HSSI_PARM1_PI)
1432 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hspiread);
1433 else
1434 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].lssiread);
1435
1436 retval &= 0xfffff;
1437
1438 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_READ)
1439 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1440 __func__, reg, retval);
1441 return retval;
1442}
1443
Jes Sorensen22a31d42016-02-29 17:04:15 -05001444/*
1445 * The RTL8723BU driver indicates that registers 0xb2 and 0xb6 can
1446 * have write issues in high temperature conditions. We may have to
1447 * retry writing them.
1448 */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001449static int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv *priv,
1450 enum rtl8xxxu_rfpath path, u8 reg, u32 data)
1451{
1452 int ret, retval;
1453 u32 dataaddr;
1454
1455 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_WRITE)
1456 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1457 __func__, reg, data);
1458
1459 data &= FPGA0_LSSI_PARM_DATA_MASK;
1460 dataaddr = (reg << FPGA0_LSSI_PARM_ADDR_SHIFT) | data;
1461
1462 /* Use XB for path B */
1463 ret = rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].lssiparm, dataaddr);
1464 if (ret != sizeof(dataaddr))
1465 retval = -EIO;
1466 else
1467 retval = 0;
1468
1469 udelay(1);
1470
1471 return retval;
1472}
1473
1474static int rtl8723a_h2c_cmd(struct rtl8xxxu_priv *priv, struct h2c_cmd *h2c)
1475{
1476 struct device *dev = &priv->udev->dev;
1477 int mbox_nr, retry, retval = 0;
1478 int mbox_reg, mbox_ext_reg;
1479 u8 val8;
1480
1481 mutex_lock(&priv->h2c_mutex);
1482
1483 mbox_nr = priv->next_mbox;
1484 mbox_reg = REG_HMBOX_0 + (mbox_nr * 4);
Jes Sorensened35d092016-02-29 17:04:19 -05001485 mbox_ext_reg = priv->fops->mbox_ext_reg +
1486 (mbox_nr * priv->fops->mbox_ext_width);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001487
1488 /*
1489 * MBOX ready?
1490 */
1491 retry = 100;
1492 do {
1493 val8 = rtl8xxxu_read8(priv, REG_HMTFR);
1494 if (!(val8 & BIT(mbox_nr)))
1495 break;
1496 } while (retry--);
1497
1498 if (!retry) {
1499 dev_dbg(dev, "%s: Mailbox busy\n", __func__);
1500 retval = -EBUSY;
1501 goto error;
1502 }
1503
1504 /*
1505 * Need to swap as it's being swapped again by rtl8xxxu_write16/32()
1506 */
1507 if (h2c->cmd.cmd & H2C_EXT) {
Jes Sorensened35d092016-02-29 17:04:19 -05001508 if (priv->fops->mbox_ext_width == 4) {
1509 rtl8xxxu_write32(priv, mbox_ext_reg,
1510 le32_to_cpu(h2c->raw_wide.ext));
1511 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1512 dev_info(dev, "H2C_EXT %08x\n",
1513 le32_to_cpu(h2c->raw_wide.ext));
1514 } else {
1515 rtl8xxxu_write16(priv, mbox_ext_reg,
1516 le16_to_cpu(h2c->raw.ext));
1517 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1518 dev_info(dev, "H2C_EXT %04x\n",
1519 le16_to_cpu(h2c->raw.ext));
1520 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001521 }
1522 rtl8xxxu_write32(priv, mbox_reg, le32_to_cpu(h2c->raw.data));
1523 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1524 dev_info(dev, "H2C %08x\n", le32_to_cpu(h2c->raw.data));
1525
1526 priv->next_mbox = (mbox_nr + 1) % H2C_MAX_MBOX;
1527
1528error:
1529 mutex_unlock(&priv->h2c_mutex);
1530 return retval;
1531}
1532
1533static void rtl8723a_enable_rf(struct rtl8xxxu_priv *priv)
1534{
1535 u8 val8;
1536 u32 val32;
1537
1538 val8 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
1539 val8 |= BIT(0) | BIT(3);
1540 rtl8xxxu_write8(priv, REG_SPS0_CTRL, val8);
1541
1542 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
1543 val32 &= ~(BIT(4) | BIT(5));
1544 val32 |= BIT(3);
1545 if (priv->rf_paths == 2) {
1546 val32 &= ~(BIT(20) | BIT(21));
1547 val32 |= BIT(19);
1548 }
1549 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
1550
1551 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
1552 val32 &= ~OFDM_RF_PATH_TX_MASK;
1553 if (priv->tx_paths == 2)
1554 val32 |= OFDM_RF_PATH_TX_A | OFDM_RF_PATH_TX_B;
1555 else if (priv->rtlchip == 0x8192c || priv->rtlchip == 0x8191c)
1556 val32 |= OFDM_RF_PATH_TX_B;
1557 else
1558 val32 |= OFDM_RF_PATH_TX_A;
1559 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
1560
1561 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1562 val32 &= ~FPGA_RF_MODE_JAPAN;
1563 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1564
1565 if (priv->rf_paths == 2)
1566 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x63db25a0);
1567 else
1568 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x631b25a0);
1569
1570 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x32d95);
1571 if (priv->rf_paths == 2)
1572 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x32d95);
1573
1574 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
1575}
1576
1577static void rtl8723a_disable_rf(struct rtl8xxxu_priv *priv)
1578{
1579 u8 sps0;
1580 u32 val32;
1581
1582 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
1583
1584 sps0 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
1585
1586 /* RF RX code for preamble power saving */
1587 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
1588 val32 &= ~(BIT(3) | BIT(4) | BIT(5));
1589 if (priv->rf_paths == 2)
1590 val32 &= ~(BIT(19) | BIT(20) | BIT(21));
1591 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
1592
1593 /* Disable TX for four paths */
1594 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
1595 val32 &= ~OFDM_RF_PATH_TX_MASK;
1596 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
1597
1598 /* Enable power saving */
1599 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1600 val32 |= FPGA_RF_MODE_JAPAN;
1601 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1602
1603 /* AFE control register to power down bits [30:22] */
1604 if (priv->rf_paths == 2)
1605 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x00db25a0);
1606 else
1607 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x001b25a0);
1608
1609 /* Power down RF module */
1610 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0);
1611 if (priv->rf_paths == 2)
1612 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0);
1613
1614 sps0 &= ~(BIT(0) | BIT(3));
1615 rtl8xxxu_write8(priv, REG_SPS0_CTRL, sps0);
1616}
1617
1618
1619static void rtl8723a_stop_tx_beacon(struct rtl8xxxu_priv *priv)
1620{
1621 u8 val8;
1622
1623 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL + 2);
1624 val8 &= ~BIT(6);
1625 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8);
1626
1627 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x64);
1628 val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
1629 val8 &= ~BIT(0);
1630 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8);
1631}
1632
1633
1634/*
1635 * The rtl8723a has 3 channel groups for it's efuse settings. It only
1636 * supports the 2.4GHz band, so channels 1 - 14:
1637 * group 0: channels 1 - 3
1638 * group 1: channels 4 - 9
1639 * group 2: channels 10 - 14
1640 *
1641 * Note: We index from 0 in the code
1642 */
1643static int rtl8723a_channel_to_group(int channel)
1644{
1645 int group;
1646
1647 if (channel < 4)
1648 group = 0;
1649 else if (channel < 10)
1650 group = 1;
1651 else
1652 group = 2;
1653
1654 return group;
1655}
1656
1657static void rtl8723au_config_channel(struct ieee80211_hw *hw)
1658{
1659 struct rtl8xxxu_priv *priv = hw->priv;
1660 u32 val32, rsr;
1661 u8 val8, opmode;
1662 bool ht = true;
1663 int sec_ch_above, channel;
1664 int i;
1665
1666 opmode = rtl8xxxu_read8(priv, REG_BW_OPMODE);
1667 rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
1668 channel = hw->conf.chandef.chan->hw_value;
1669
1670 switch (hw->conf.chandef.width) {
1671 case NL80211_CHAN_WIDTH_20_NOHT:
1672 ht = false;
1673 case NL80211_CHAN_WIDTH_20:
1674 opmode |= BW_OPMODE_20MHZ;
1675 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
1676
1677 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1678 val32 &= ~FPGA_RF_MODE;
1679 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1680
1681 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1682 val32 &= ~FPGA_RF_MODE;
1683 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1684
1685 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
1686 val32 |= FPGA0_ANALOG2_20MHZ;
1687 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
1688 break;
1689 case NL80211_CHAN_WIDTH_40:
1690 if (hw->conf.chandef.center_freq1 >
1691 hw->conf.chandef.chan->center_freq) {
1692 sec_ch_above = 1;
1693 channel += 2;
1694 } else {
1695 sec_ch_above = 0;
1696 channel -= 2;
1697 }
1698
1699 opmode &= ~BW_OPMODE_20MHZ;
1700 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
1701 rsr &= ~RSR_RSC_BANDWIDTH_40M;
1702 if (sec_ch_above)
1703 rsr |= RSR_RSC_UPPER_SUB_CHANNEL;
1704 else
1705 rsr |= RSR_RSC_LOWER_SUB_CHANNEL;
1706 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, rsr);
1707
1708 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1709 val32 |= FPGA_RF_MODE;
1710 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1711
1712 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1713 val32 |= FPGA_RF_MODE;
1714 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1715
1716 /*
1717 * Set Control channel to upper or lower. These settings
1718 * are required only for 40MHz
1719 */
1720 val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
1721 val32 &= ~CCK0_SIDEBAND;
1722 if (!sec_ch_above)
1723 val32 |= CCK0_SIDEBAND;
1724 rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
1725
1726 val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
1727 val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
1728 if (sec_ch_above)
1729 val32 |= OFDM_LSTF_PRIME_CH_LOW;
1730 else
1731 val32 |= OFDM_LSTF_PRIME_CH_HIGH;
1732 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
1733
1734 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
1735 val32 &= ~FPGA0_ANALOG2_20MHZ;
1736 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
1737
1738 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
1739 val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
1740 if (sec_ch_above)
1741 val32 |= FPGA0_PS_UPPER_CHANNEL;
1742 else
1743 val32 |= FPGA0_PS_LOWER_CHANNEL;
1744 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
1745 break;
1746
1747 default:
1748 break;
1749 }
1750
1751 for (i = RF_A; i < priv->rf_paths; i++) {
1752 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1753 val32 &= ~MODE_AG_CHANNEL_MASK;
1754 val32 |= channel;
1755 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1756 }
1757
1758 if (ht)
1759 val8 = 0x0e;
1760 else
1761 val8 = 0x0a;
1762
1763 rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8);
1764 rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8);
1765
1766 rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808);
1767 rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a);
1768
1769 for (i = RF_A; i < priv->rf_paths; i++) {
1770 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1771 if (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40)
1772 val32 &= ~MODE_AG_CHANNEL_20MHZ;
1773 else
1774 val32 |= MODE_AG_CHANNEL_20MHZ;
1775 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1776 }
1777}
1778
1779static void
1780rtl8723a_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
1781{
1782 u8 cck[RTL8723A_MAX_RF_PATHS], ofdm[RTL8723A_MAX_RF_PATHS];
1783 u8 ofdmbase[RTL8723A_MAX_RF_PATHS], mcsbase[RTL8723A_MAX_RF_PATHS];
1784 u32 val32, ofdm_a, ofdm_b, mcs_a, mcs_b;
1785 u8 val8;
1786 int group, i;
1787
1788 group = rtl8723a_channel_to_group(channel);
1789
1790 cck[0] = priv->cck_tx_power_index_A[group];
1791 cck[1] = priv->cck_tx_power_index_B[group];
1792
1793 ofdm[0] = priv->ht40_1s_tx_power_index_A[group];
1794 ofdm[1] = priv->ht40_1s_tx_power_index_B[group];
1795
1796 ofdmbase[0] = ofdm[0] + priv->ofdm_tx_power_index_diff[group].a;
1797 ofdmbase[1] = ofdm[1] + priv->ofdm_tx_power_index_diff[group].b;
1798
1799 mcsbase[0] = ofdm[0];
1800 mcsbase[1] = ofdm[1];
1801 if (!ht40) {
1802 mcsbase[0] += priv->ht20_tx_power_index_diff[group].a;
1803 mcsbase[1] += priv->ht20_tx_power_index_diff[group].b;
1804 }
1805
1806 if (priv->tx_paths > 1) {
1807 if (ofdm[0] > priv->ht40_2s_tx_power_index_diff[group].a)
1808 ofdm[0] -= priv->ht40_2s_tx_power_index_diff[group].a;
1809 if (ofdm[1] > priv->ht40_2s_tx_power_index_diff[group].b)
1810 ofdm[1] -= priv->ht40_2s_tx_power_index_diff[group].b;
1811 }
1812
1813 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
1814 dev_info(&priv->udev->dev,
1815 "%s: Setting TX power CCK A: %02x, "
1816 "CCK B: %02x, OFDM A: %02x, OFDM B: %02x\n",
1817 __func__, cck[0], cck[1], ofdm[0], ofdm[1]);
1818
1819 for (i = 0; i < RTL8723A_MAX_RF_PATHS; i++) {
1820 if (cck[i] > RF6052_MAX_TX_PWR)
1821 cck[i] = RF6052_MAX_TX_PWR;
1822 if (ofdm[i] > RF6052_MAX_TX_PWR)
1823 ofdm[i] = RF6052_MAX_TX_PWR;
1824 }
1825
1826 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
1827 val32 &= 0xffff00ff;
1828 val32 |= (cck[0] << 8);
1829 rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
1830
1831 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
1832 val32 &= 0xff;
1833 val32 |= ((cck[0] << 8) | (cck[0] << 16) | (cck[0] << 24));
1834 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
1835
1836 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
1837 val32 &= 0xffffff00;
1838 val32 |= cck[1];
1839 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
1840
1841 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK1_55_MCS32);
1842 val32 &= 0xff;
1843 val32 |= ((cck[1] << 8) | (cck[1] << 16) | (cck[1] << 24));
1844 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK1_55_MCS32, val32);
1845
1846 ofdm_a = ofdmbase[0] | ofdmbase[0] << 8 |
1847 ofdmbase[0] << 16 | ofdmbase[0] << 24;
1848 ofdm_b = ofdmbase[1] | ofdmbase[1] << 8 |
1849 ofdmbase[1] << 16 | ofdmbase[1] << 24;
1850 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm_a);
1851 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE18_06, ofdm_b);
1852
1853 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm_a);
1854 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE54_24, ofdm_b);
1855
1856 mcs_a = mcsbase[0] | mcsbase[0] << 8 |
1857 mcsbase[0] << 16 | mcsbase[0] << 24;
1858 mcs_b = mcsbase[1] | mcsbase[1] << 8 |
1859 mcsbase[1] << 16 | mcsbase[1] << 24;
1860
1861 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs_a);
1862 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS03_MCS00, mcs_b);
1863
1864 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs_a);
1865 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS07_MCS04, mcs_b);
1866
1867 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS11_MCS08, mcs_a);
1868 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS11_MCS08, mcs_b);
1869
1870 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12, mcs_a);
1871 for (i = 0; i < 3; i++) {
1872 if (i != 2)
1873 val8 = (mcsbase[0] > 8) ? (mcsbase[0] - 8) : 0;
1874 else
1875 val8 = (mcsbase[0] > 6) ? (mcsbase[0] - 6) : 0;
1876 rtl8xxxu_write8(priv, REG_OFDM0_XC_TX_IQ_IMBALANCE + i, val8);
1877 }
1878 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12, mcs_b);
1879 for (i = 0; i < 3; i++) {
1880 if (i != 2)
1881 val8 = (mcsbase[1] > 8) ? (mcsbase[1] - 8) : 0;
1882 else
1883 val8 = (mcsbase[1] > 6) ? (mcsbase[1] - 6) : 0;
1884 rtl8xxxu_write8(priv, REG_OFDM0_XD_TX_IQ_IMBALANCE + i, val8);
1885 }
1886}
1887
1888static void rtl8xxxu_set_linktype(struct rtl8xxxu_priv *priv,
1889 enum nl80211_iftype linktype)
1890{
Jes Sorensena26703f2016-02-03 13:39:56 -05001891 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001892
Jes Sorensena26703f2016-02-03 13:39:56 -05001893 val8 = rtl8xxxu_read8(priv, REG_MSR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001894 val8 &= ~MSR_LINKTYPE_MASK;
1895
1896 switch (linktype) {
1897 case NL80211_IFTYPE_UNSPECIFIED:
1898 val8 |= MSR_LINKTYPE_NONE;
1899 break;
1900 case NL80211_IFTYPE_ADHOC:
1901 val8 |= MSR_LINKTYPE_ADHOC;
1902 break;
1903 case NL80211_IFTYPE_STATION:
1904 val8 |= MSR_LINKTYPE_STATION;
1905 break;
1906 case NL80211_IFTYPE_AP:
1907 val8 |= MSR_LINKTYPE_AP;
1908 break;
1909 default:
1910 goto out;
1911 }
1912
1913 rtl8xxxu_write8(priv, REG_MSR, val8);
1914out:
1915 return;
1916}
1917
1918static void
1919rtl8xxxu_set_retry(struct rtl8xxxu_priv *priv, u16 short_retry, u16 long_retry)
1920{
1921 u16 val16;
1922
1923 val16 = ((short_retry << RETRY_LIMIT_SHORT_SHIFT) &
1924 RETRY_LIMIT_SHORT_MASK) |
1925 ((long_retry << RETRY_LIMIT_LONG_SHIFT) &
1926 RETRY_LIMIT_LONG_MASK);
1927
1928 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
1929}
1930
1931static void
1932rtl8xxxu_set_spec_sifs(struct rtl8xxxu_priv *priv, u16 cck, u16 ofdm)
1933{
1934 u16 val16;
1935
1936 val16 = ((cck << SPEC_SIFS_CCK_SHIFT) & SPEC_SIFS_CCK_MASK) |
1937 ((ofdm << SPEC_SIFS_OFDM_SHIFT) & SPEC_SIFS_OFDM_MASK);
1938
1939 rtl8xxxu_write16(priv, REG_SPEC_SIFS, val16);
1940}
1941
1942static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv)
1943{
1944 struct device *dev = &priv->udev->dev;
1945 char *cut;
1946
1947 switch (priv->chip_cut) {
1948 case 0:
1949 cut = "A";
1950 break;
1951 case 1:
1952 cut = "B";
1953 break;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001954 case 2:
1955 cut = "C";
1956 break;
1957 case 3:
1958 cut = "D";
1959 break;
1960 case 4:
1961 cut = "E";
1962 break;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001963 default:
1964 cut = "unknown";
1965 }
1966
1967 dev_info(dev,
1968 "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 -05001969 priv->chip_name, cut, priv->chip_vendor, priv->tx_paths,
1970 priv->rx_paths, priv->ep_tx_count, priv->has_wifi,
1971 priv->has_bluetooth, priv->has_gps, priv->hi_pa);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001972
1973 dev_info(dev, "RTL%s MAC: %pM\n", priv->chip_name, priv->mac_addr);
1974}
1975
1976static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
1977{
1978 struct device *dev = &priv->udev->dev;
1979 u32 val32, bonding;
1980 u16 val16;
1981
1982 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
1983 priv->chip_cut = (val32 & SYS_CFG_CHIP_VERSION_MASK) >>
1984 SYS_CFG_CHIP_VERSION_SHIFT;
1985 if (val32 & SYS_CFG_TRP_VAUX_EN) {
1986 dev_info(dev, "Unsupported test chip\n");
1987 return -ENOTSUPP;
1988 }
1989
1990 if (val32 & SYS_CFG_BT_FUNC) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05001991 if (priv->chip_cut >= 3) {
1992 sprintf(priv->chip_name, "8723BU");
1993 priv->rtlchip = 0x8723b;
1994 } else {
1995 sprintf(priv->chip_name, "8723AU");
Jes Sorensen0e28b972016-02-29 17:04:13 -05001996 priv->usb_interrupts = 1;
Jes Sorensen35a741f2016-02-29 17:04:10 -05001997 priv->rtlchip = 0x8723a;
1998 }
1999
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002000 priv->rf_paths = 1;
2001 priv->rx_paths = 1;
2002 priv->tx_paths = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002003
2004 val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL);
2005 if (val32 & MULTI_WIFI_FUNC_EN)
2006 priv->has_wifi = 1;
2007 if (val32 & MULTI_BT_FUNC_EN)
2008 priv->has_bluetooth = 1;
2009 if (val32 & MULTI_GPS_FUNC_EN)
2010 priv->has_gps = 1;
Jakub Sitnicki38451992016-02-03 13:39:49 -05002011 priv->is_multi_func = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002012 } else if (val32 & SYS_CFG_TYPE_ID) {
2013 bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
2014 bonding &= HPON_FSM_BONDING_MASK;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002015 if (priv->chip_cut >= 3) {
2016 if (bonding == HPON_FSM_BONDING_1T2R) {
2017 sprintf(priv->chip_name, "8191EU");
2018 priv->rf_paths = 2;
2019 priv->rx_paths = 2;
2020 priv->tx_paths = 1;
2021 priv->rtlchip = 0x8191e;
2022 } else {
2023 sprintf(priv->chip_name, "8192EU");
2024 priv->rf_paths = 2;
2025 priv->rx_paths = 2;
2026 priv->tx_paths = 2;
2027 priv->rtlchip = 0x8192e;
2028 }
2029 } else if (bonding == HPON_FSM_BONDING_1T2R) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002030 sprintf(priv->chip_name, "8191CU");
2031 priv->rf_paths = 2;
2032 priv->rx_paths = 2;
2033 priv->tx_paths = 1;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002034 priv->usb_interrupts = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002035 priv->rtlchip = 0x8191c;
2036 } else {
2037 sprintf(priv->chip_name, "8192CU");
2038 priv->rf_paths = 2;
2039 priv->rx_paths = 2;
2040 priv->tx_paths = 2;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002041 priv->usb_interrupts = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002042 priv->rtlchip = 0x8192c;
2043 }
2044 priv->has_wifi = 1;
2045 } else {
2046 sprintf(priv->chip_name, "8188CU");
2047 priv->rf_paths = 1;
2048 priv->rx_paths = 1;
2049 priv->tx_paths = 1;
2050 priv->rtlchip = 0x8188c;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002051 priv->usb_interrupts = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002052 priv->has_wifi = 1;
2053 }
2054
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002055 switch (priv->rtlchip) {
2056 case 0x8188e:
2057 case 0x8192e:
2058 case 0x8723b:
2059 switch (val32 & SYS_CFG_VENDOR_EXT_MASK) {
2060 case SYS_CFG_VENDOR_ID_TSMC:
2061 sprintf(priv->chip_vendor, "TSMC");
2062 break;
2063 case SYS_CFG_VENDOR_ID_SMIC:
2064 sprintf(priv->chip_vendor, "SMIC");
2065 priv->vendor_smic = 1;
2066 break;
2067 case SYS_CFG_VENDOR_ID_UMC:
2068 sprintf(priv->chip_vendor, "UMC");
2069 priv->vendor_umc = 1;
2070 break;
2071 default:
2072 sprintf(priv->chip_vendor, "unknown");
2073 }
2074 break;
2075 default:
2076 if (val32 & SYS_CFG_VENDOR_ID) {
2077 sprintf(priv->chip_vendor, "UMC");
2078 priv->vendor_umc = 1;
2079 } else {
2080 sprintf(priv->chip_vendor, "TSMC");
2081 }
2082 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002083
2084 val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
2085 priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;
2086
2087 val16 = rtl8xxxu_read16(priv, REG_NORMAL_SIE_EP_TX);
2088 if (val16 & NORMAL_SIE_EP_TX_HIGH_MASK) {
2089 priv->ep_tx_high_queue = 1;
2090 priv->ep_tx_count++;
2091 }
2092
2093 if (val16 & NORMAL_SIE_EP_TX_NORMAL_MASK) {
2094 priv->ep_tx_normal_queue = 1;
2095 priv->ep_tx_count++;
2096 }
2097
2098 if (val16 & NORMAL_SIE_EP_TX_LOW_MASK) {
2099 priv->ep_tx_low_queue = 1;
2100 priv->ep_tx_count++;
2101 }
2102
2103 /*
2104 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
2105 */
2106 if (!priv->ep_tx_count) {
2107 switch (priv->nr_out_eps) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05002108 case 4:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002109 case 3:
2110 priv->ep_tx_low_queue = 1;
2111 priv->ep_tx_count++;
2112 case 2:
2113 priv->ep_tx_normal_queue = 1;
2114 priv->ep_tx_count++;
2115 case 1:
2116 priv->ep_tx_high_queue = 1;
2117 priv->ep_tx_count++;
2118 break;
2119 default:
2120 dev_info(dev, "Unsupported USB TX end-points\n");
2121 return -ENOTSUPP;
2122 }
2123 }
2124
2125 return 0;
2126}
2127
2128static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv)
2129{
2130 if (priv->efuse_wifi.efuse8723.rtl_id != cpu_to_le16(0x8129))
2131 return -EINVAL;
2132
2133 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8723.mac_addr);
2134
2135 memcpy(priv->cck_tx_power_index_A,
2136 priv->efuse_wifi.efuse8723.cck_tx_power_index_A,
2137 sizeof(priv->cck_tx_power_index_A));
2138 memcpy(priv->cck_tx_power_index_B,
2139 priv->efuse_wifi.efuse8723.cck_tx_power_index_B,
2140 sizeof(priv->cck_tx_power_index_B));
2141
2142 memcpy(priv->ht40_1s_tx_power_index_A,
2143 priv->efuse_wifi.efuse8723.ht40_1s_tx_power_index_A,
2144 sizeof(priv->ht40_1s_tx_power_index_A));
2145 memcpy(priv->ht40_1s_tx_power_index_B,
2146 priv->efuse_wifi.efuse8723.ht40_1s_tx_power_index_B,
2147 sizeof(priv->ht40_1s_tx_power_index_B));
2148
2149 memcpy(priv->ht20_tx_power_index_diff,
2150 priv->efuse_wifi.efuse8723.ht20_tx_power_index_diff,
2151 sizeof(priv->ht20_tx_power_index_diff));
2152 memcpy(priv->ofdm_tx_power_index_diff,
2153 priv->efuse_wifi.efuse8723.ofdm_tx_power_index_diff,
2154 sizeof(priv->ofdm_tx_power_index_diff));
2155
2156 memcpy(priv->ht40_max_power_offset,
2157 priv->efuse_wifi.efuse8723.ht40_max_power_offset,
2158 sizeof(priv->ht40_max_power_offset));
2159 memcpy(priv->ht20_max_power_offset,
2160 priv->efuse_wifi.efuse8723.ht20_max_power_offset,
2161 sizeof(priv->ht20_max_power_offset));
2162
2163 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
2164 priv->efuse_wifi.efuse8723.vendor_name);
2165 dev_info(&priv->udev->dev, "Product: %.41s\n",
2166 priv->efuse_wifi.efuse8723.device_name);
2167 return 0;
2168}
2169
Jes Sorensen3c836d62016-02-29 17:04:11 -05002170static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv)
2171{
2172 if (priv->efuse_wifi.efuse8723bu.rtl_id != cpu_to_le16(0x8129))
2173 return -EINVAL;
2174
2175 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8723bu.mac_addr);
2176
2177 memcpy(priv->cck_tx_power_index_A,
2178 priv->efuse_wifi.efuse8723bu.cck_tx_power_index_A,
2179 sizeof(priv->cck_tx_power_index_A));
2180 memcpy(priv->cck_tx_power_index_B,
2181 priv->efuse_wifi.efuse8723bu.cck_tx_power_index_B,
2182 sizeof(priv->cck_tx_power_index_B));
2183
2184 memcpy(priv->ht40_1s_tx_power_index_A,
2185 priv->efuse_wifi.efuse8723bu.ht40_1s_tx_power_index_A,
2186 sizeof(priv->ht40_1s_tx_power_index_A));
2187 memcpy(priv->ht40_1s_tx_power_index_B,
2188 priv->efuse_wifi.efuse8723bu.ht40_1s_tx_power_index_B,
2189 sizeof(priv->ht40_1s_tx_power_index_B));
2190
2191 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
2192 priv->efuse_wifi.efuse8723bu.vendor_name);
2193 dev_info(&priv->udev->dev, "Product: %.41s\n",
2194 priv->efuse_wifi.efuse8723bu.device_name);
2195
2196 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2197 int i;
2198 unsigned char *raw = priv->efuse_wifi.raw;
2199
2200 dev_info(&priv->udev->dev,
2201 "%s: dumping efuse (0x%02zx bytes):\n",
2202 __func__, sizeof(struct rtl8723bu_efuse));
2203 for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8) {
2204 dev_info(&priv->udev->dev, "%02x: "
2205 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2206 raw[i], raw[i + 1], raw[i + 2],
2207 raw[i + 3], raw[i + 4], raw[i + 5],
2208 raw[i + 6], raw[i + 7]);
2209 }
2210 }
2211
2212 return 0;
2213}
2214
Kalle Valoc0963772015-10-25 18:24:38 +02002215#ifdef CONFIG_RTL8XXXU_UNTESTED
2216
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002217static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
2218{
2219 int i;
2220
2221 if (priv->efuse_wifi.efuse8192.rtl_id != cpu_to_le16(0x8129))
2222 return -EINVAL;
2223
2224 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8192.mac_addr);
2225
2226 memcpy(priv->cck_tx_power_index_A,
2227 priv->efuse_wifi.efuse8192.cck_tx_power_index_A,
2228 sizeof(priv->cck_tx_power_index_A));
2229 memcpy(priv->cck_tx_power_index_B,
2230 priv->efuse_wifi.efuse8192.cck_tx_power_index_B,
2231 sizeof(priv->cck_tx_power_index_B));
2232
2233 memcpy(priv->ht40_1s_tx_power_index_A,
2234 priv->efuse_wifi.efuse8192.ht40_1s_tx_power_index_A,
2235 sizeof(priv->ht40_1s_tx_power_index_A));
2236 memcpy(priv->ht40_1s_tx_power_index_B,
2237 priv->efuse_wifi.efuse8192.ht40_1s_tx_power_index_B,
2238 sizeof(priv->ht40_1s_tx_power_index_B));
2239 memcpy(priv->ht40_2s_tx_power_index_diff,
2240 priv->efuse_wifi.efuse8192.ht40_2s_tx_power_index_diff,
2241 sizeof(priv->ht40_2s_tx_power_index_diff));
2242
2243 memcpy(priv->ht20_tx_power_index_diff,
2244 priv->efuse_wifi.efuse8192.ht20_tx_power_index_diff,
2245 sizeof(priv->ht20_tx_power_index_diff));
2246 memcpy(priv->ofdm_tx_power_index_diff,
2247 priv->efuse_wifi.efuse8192.ofdm_tx_power_index_diff,
2248 sizeof(priv->ofdm_tx_power_index_diff));
2249
2250 memcpy(priv->ht40_max_power_offset,
2251 priv->efuse_wifi.efuse8192.ht40_max_power_offset,
2252 sizeof(priv->ht40_max_power_offset));
2253 memcpy(priv->ht20_max_power_offset,
2254 priv->efuse_wifi.efuse8192.ht20_max_power_offset,
2255 sizeof(priv->ht20_max_power_offset));
2256
2257 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
2258 priv->efuse_wifi.efuse8192.vendor_name);
2259 dev_info(&priv->udev->dev, "Product: %.20s\n",
2260 priv->efuse_wifi.efuse8192.device_name);
2261
2262 if (priv->efuse_wifi.efuse8192.rf_regulatory & 0x20) {
2263 sprintf(priv->chip_name, "8188RU");
2264 priv->hi_pa = 1;
2265 }
2266
2267 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2268 unsigned char *raw = priv->efuse_wifi.raw;
2269
2270 dev_info(&priv->udev->dev,
2271 "%s: dumping efuse (0x%02zx bytes):\n",
2272 __func__, sizeof(struct rtl8192cu_efuse));
2273 for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8) {
2274 dev_info(&priv->udev->dev, "%02x: "
2275 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2276 raw[i], raw[i + 1], raw[i + 2],
2277 raw[i + 3], raw[i + 4], raw[i + 5],
2278 raw[i + 6], raw[i + 7]);
2279 }
2280 }
2281 return 0;
2282}
2283
Kalle Valoc0963772015-10-25 18:24:38 +02002284#endif
2285
Jes Sorensen3307d842016-02-29 17:03:59 -05002286static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
2287{
2288 int i;
2289
2290 if (priv->efuse_wifi.efuse8192eu.rtl_id != cpu_to_le16(0x8129))
2291 return -EINVAL;
2292
2293 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8192eu.mac_addr);
2294
2295 memcpy(priv->cck_tx_power_index_A,
2296 priv->efuse_wifi.efuse8192eu.cck_tx_power_index_A,
2297 sizeof(priv->cck_tx_power_index_A));
2298 memcpy(priv->cck_tx_power_index_B,
2299 priv->efuse_wifi.efuse8192eu.cck_tx_power_index_B,
2300 sizeof(priv->cck_tx_power_index_B));
2301
2302 memcpy(priv->ht40_1s_tx_power_index_A,
2303 priv->efuse_wifi.efuse8192eu.ht40_1s_tx_power_index_A,
2304 sizeof(priv->ht40_1s_tx_power_index_A));
2305 memcpy(priv->ht40_1s_tx_power_index_B,
2306 priv->efuse_wifi.efuse8192eu.ht40_1s_tx_power_index_B,
2307 sizeof(priv->ht40_1s_tx_power_index_B));
2308
2309 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
2310 priv->efuse_wifi.efuse8192eu.vendor_name);
2311 dev_info(&priv->udev->dev, "Product: %.11s\n",
2312 priv->efuse_wifi.efuse8192eu.device_name);
2313 dev_info(&priv->udev->dev, "Serial: %.11s\n",
2314 priv->efuse_wifi.efuse8192eu.serial);
2315
2316 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2317 unsigned char *raw = priv->efuse_wifi.raw;
2318
2319 dev_info(&priv->udev->dev,
2320 "%s: dumping efuse (0x%02zx bytes):\n",
2321 __func__, sizeof(struct rtl8192eu_efuse));
2322 for (i = 0; i < sizeof(struct rtl8192eu_efuse); i += 8) {
2323 dev_info(&priv->udev->dev, "%02x: "
2324 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2325 raw[i], raw[i + 1], raw[i + 2],
2326 raw[i + 3], raw[i + 4], raw[i + 5],
2327 raw[i + 6], raw[i + 7]);
2328 }
2329 }
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002330 return 0;
Jes Sorensen3307d842016-02-29 17:03:59 -05002331}
2332
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002333static int
2334rtl8xxxu_read_efuse8(struct rtl8xxxu_priv *priv, u16 offset, u8 *data)
2335{
2336 int i;
2337 u8 val8;
2338 u32 val32;
2339
2340 /* Write Address */
2341 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 1, offset & 0xff);
2342 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 2);
2343 val8 &= 0xfc;
2344 val8 |= (offset >> 8) & 0x03;
2345 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 2, val8);
2346
2347 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 3);
2348 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 3, val8 & 0x7f);
2349
2350 /* Poll for data read */
2351 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2352 for (i = 0; i < RTL8XXXU_MAX_REG_POLL; i++) {
2353 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2354 if (val32 & BIT(31))
2355 break;
2356 }
2357
2358 if (i == RTL8XXXU_MAX_REG_POLL)
2359 return -EIO;
2360
2361 udelay(50);
2362 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2363
2364 *data = val32 & 0xff;
2365 return 0;
2366}
2367
2368static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv)
2369{
2370 struct device *dev = &priv->udev->dev;
2371 int i, ret = 0;
2372 u8 val8, word_mask, header, extheader;
2373 u16 val16, efuse_addr, offset;
2374 u32 val32;
2375
2376 val16 = rtl8xxxu_read16(priv, REG_9346CR);
2377 if (val16 & EEPROM_ENABLE)
2378 priv->has_eeprom = 1;
2379 if (val16 & EEPROM_BOOT)
2380 priv->boot_eeprom = 1;
2381
Jakub Sitnicki38451992016-02-03 13:39:49 -05002382 if (priv->is_multi_func) {
2383 val32 = rtl8xxxu_read32(priv, REG_EFUSE_TEST);
2384 val32 = (val32 & ~EFUSE_SELECT_MASK) | EFUSE_WIFI_SELECT;
2385 rtl8xxxu_write32(priv, REG_EFUSE_TEST, val32);
2386 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002387
2388 dev_dbg(dev, "Booting from %s\n",
2389 priv->boot_eeprom ? "EEPROM" : "EFUSE");
2390
2391 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_ENABLE);
2392
2393 /* 1.2V Power: From VDDON with Power Cut(0x0000[15]), default valid */
2394 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
2395 if (!(val16 & SYS_ISO_PWC_EV12V)) {
2396 val16 |= SYS_ISO_PWC_EV12V;
2397 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
2398 }
2399 /* Reset: 0x0000[28], default valid */
2400 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2401 if (!(val16 & SYS_FUNC_ELDR)) {
2402 val16 |= SYS_FUNC_ELDR;
2403 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
2404 }
2405
2406 /*
2407 * Clock: Gated(0x0008[5]) 8M(0x0008[1]) clock from ANA, default valid
2408 */
2409 val16 = rtl8xxxu_read16(priv, REG_SYS_CLKR);
2410 if (!(val16 & SYS_CLK_LOADER_ENABLE) || !(val16 & SYS_CLK_ANA8M)) {
2411 val16 |= (SYS_CLK_LOADER_ENABLE | SYS_CLK_ANA8M);
2412 rtl8xxxu_write16(priv, REG_SYS_CLKR, val16);
2413 }
2414
2415 /* Default value is 0xff */
Jes Sorensen3307d842016-02-29 17:03:59 -05002416 memset(priv->efuse_wifi.raw, 0xff, EFUSE_MAP_LEN);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002417
2418 efuse_addr = 0;
2419 while (efuse_addr < EFUSE_REAL_CONTENT_LEN_8723A) {
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002420 u16 map_addr;
2421
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002422 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &header);
2423 if (ret || header == 0xff)
2424 goto exit;
2425
2426 if ((header & 0x1f) == 0x0f) { /* extended header */
2427 offset = (header & 0xe0) >> 5;
2428
2429 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++,
2430 &extheader);
2431 if (ret)
2432 goto exit;
2433 /* All words disabled */
2434 if ((extheader & 0x0f) == 0x0f)
2435 continue;
2436
2437 offset |= ((extheader & 0xf0) >> 1);
2438 word_mask = extheader & 0x0f;
2439 } else {
2440 offset = (header >> 4) & 0x0f;
2441 word_mask = header & 0x0f;
2442 }
2443
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002444 /* Get word enable value from PG header */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002445
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002446 /* We have 8 bits to indicate validity */
2447 map_addr = offset * 8;
2448 if (map_addr >= EFUSE_MAP_LEN) {
2449 dev_warn(dev, "%s: Illegal map_addr (%04x), "
2450 "efuse corrupt!\n",
2451 __func__, map_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002452 ret = -EINVAL;
2453 goto exit;
2454 }
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002455 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
2456 /* Check word enable condition in the section */
Jakub Sitnicki32a39dd2016-02-29 17:04:24 -05002457 if (word_mask & BIT(i)) {
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002458 map_addr += 2;
Jakub Sitnicki32a39dd2016-02-29 17:04:24 -05002459 continue;
2460 }
2461
2462 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
2463 if (ret)
2464 goto exit;
2465 priv->efuse_wifi.raw[map_addr++] = val8;
2466
2467 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
2468 if (ret)
2469 goto exit;
2470 priv->efuse_wifi.raw[map_addr++] = val8;
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002471 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002472 }
2473
2474exit:
2475 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_DISABLE);
2476
2477 return ret;
2478}
2479
Jes Sorensend48fe602016-02-03 13:39:44 -05002480static void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv)
2481{
2482 u8 val8;
2483 u16 sys_func;
2484
2485 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05002486 val8 &= ~BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05002487 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
2488 sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2489 sys_func &= ~SYS_FUNC_CPU_ENABLE;
2490 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2491 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05002492 val8 |= BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05002493 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
2494 sys_func |= SYS_FUNC_CPU_ENABLE;
2495 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2496}
2497
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002498static int rtl8xxxu_start_firmware(struct rtl8xxxu_priv *priv)
2499{
2500 struct device *dev = &priv->udev->dev;
2501 int ret = 0, i;
2502 u32 val32;
2503
2504 /* Poll checksum report */
2505 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
2506 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2507 if (val32 & MCU_FW_DL_CSUM_REPORT)
2508 break;
2509 }
2510
2511 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
2512 dev_warn(dev, "Firmware checksum poll timed out\n");
2513 ret = -EAGAIN;
2514 goto exit;
2515 }
2516
2517 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2518 val32 |= MCU_FW_DL_READY;
2519 val32 &= ~MCU_WINT_INIT_READY;
2520 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
2521
Jes Sorensend48fe602016-02-03 13:39:44 -05002522 /*
2523 * Reset the 8051 in order for the firmware to start running,
2524 * otherwise it won't come up on the 8192eu
2525 */
2526 rtl8xxxu_reset_8051(priv);
2527
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002528 /* Wait for firmware to become ready */
2529 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
2530 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2531 if (val32 & MCU_WINT_INIT_READY)
2532 break;
2533
2534 udelay(100);
2535 }
2536
2537 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
2538 dev_warn(dev, "Firmware failed to start\n");
2539 ret = -EAGAIN;
2540 goto exit;
2541 }
2542
2543exit:
2544 return ret;
2545}
2546
2547static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv)
2548{
2549 int pages, remainder, i, ret;
Jes Sorensend48fe602016-02-03 13:39:44 -05002550 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002551 u16 val16;
2552 u32 val32;
2553 u8 *fwptr;
2554
2555 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC + 1);
2556 val8 |= 4;
2557 rtl8xxxu_write8(priv, REG_SYS_FUNC + 1, val8);
2558
2559 /* 8051 enable */
2560 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
Jes Sorensen43154f62016-02-03 13:39:35 -05002561 val16 |= SYS_FUNC_CPU_ENABLE;
2562 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002563
Jes Sorensen216202a2016-02-03 13:39:37 -05002564 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
2565 if (val8 & MCU_FW_RAM_SEL) {
2566 pr_info("do the RAM reset\n");
2567 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
Jes Sorensend48fe602016-02-03 13:39:44 -05002568 rtl8xxxu_reset_8051(priv);
Jes Sorensen216202a2016-02-03 13:39:37 -05002569 }
2570
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002571 /* MCU firmware download enable */
2572 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002573 val8 |= MCU_FW_DL_ENABLE;
2574 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002575
2576 /* 8051 reset */
2577 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002578 val32 &= ~BIT(19);
2579 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002580
2581 /* Reset firmware download checksum */
2582 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002583 val8 |= MCU_FW_DL_CSUM_REPORT;
2584 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002585
2586 pages = priv->fw_size / RTL_FW_PAGE_SIZE;
2587 remainder = priv->fw_size % RTL_FW_PAGE_SIZE;
2588
2589 fwptr = priv->fw_data->data;
2590
2591 for (i = 0; i < pages; i++) {
2592 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05002593 val8 |= i;
2594 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002595
2596 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
2597 fwptr, RTL_FW_PAGE_SIZE);
2598 if (ret != RTL_FW_PAGE_SIZE) {
2599 ret = -EAGAIN;
2600 goto fw_abort;
2601 }
2602
2603 fwptr += RTL_FW_PAGE_SIZE;
2604 }
2605
2606 if (remainder) {
2607 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05002608 val8 |= i;
2609 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002610 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
2611 fwptr, remainder);
2612 if (ret != remainder) {
2613 ret = -EAGAIN;
2614 goto fw_abort;
2615 }
2616 }
2617
2618 ret = 0;
2619fw_abort:
2620 /* MCU firmware download disable */
2621 val16 = rtl8xxxu_read16(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002622 val16 &= ~MCU_FW_DL_ENABLE;
2623 rtl8xxxu_write16(priv, REG_MCU_FW_DL, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002624
2625 return ret;
2626}
2627
2628static int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name)
2629{
2630 struct device *dev = &priv->udev->dev;
2631 const struct firmware *fw;
2632 int ret = 0;
2633 u16 signature;
2634
2635 dev_info(dev, "%s: Loading firmware %s\n", DRIVER_NAME, fw_name);
2636 if (request_firmware(&fw, fw_name, &priv->udev->dev)) {
2637 dev_warn(dev, "request_firmware(%s) failed\n", fw_name);
2638 ret = -EAGAIN;
2639 goto exit;
2640 }
2641 if (!fw) {
2642 dev_warn(dev, "Firmware data not available\n");
2643 ret = -EINVAL;
2644 goto exit;
2645 }
2646
2647 priv->fw_data = kmemdup(fw->data, fw->size, GFP_KERNEL);
Tobias Klauser98e27cb2016-02-03 13:39:43 -05002648 if (!priv->fw_data) {
2649 ret = -ENOMEM;
2650 goto exit;
2651 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002652 priv->fw_size = fw->size - sizeof(struct rtl8xxxu_firmware_header);
2653
2654 signature = le16_to_cpu(priv->fw_data->signature);
2655 switch (signature & 0xfff0) {
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002656 case 0x92e0:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002657 case 0x92c0:
2658 case 0x88c0:
Jes Sorensen35a741f2016-02-29 17:04:10 -05002659 case 0x5300:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002660 case 0x2300:
2661 break;
2662 default:
2663 ret = -EINVAL;
2664 dev_warn(dev, "%s: Invalid firmware signature: 0x%04x\n",
2665 __func__, signature);
2666 }
2667
2668 dev_info(dev, "Firmware revision %i.%i (signature 0x%04x)\n",
2669 le16_to_cpu(priv->fw_data->major_version),
2670 priv->fw_data->minor_version, signature);
2671
2672exit:
2673 release_firmware(fw);
2674 return ret;
2675}
2676
2677static int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv)
2678{
2679 char *fw_name;
2680 int ret;
2681
2682 switch (priv->chip_cut) {
2683 case 0:
2684 fw_name = "rtlwifi/rtl8723aufw_A.bin";
2685 break;
2686 case 1:
2687 if (priv->enable_bluetooth)
2688 fw_name = "rtlwifi/rtl8723aufw_B.bin";
2689 else
2690 fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin";
2691
2692 break;
2693 default:
2694 return -EINVAL;
2695 }
2696
2697 ret = rtl8xxxu_load_firmware(priv, fw_name);
2698 return ret;
2699}
2700
Jes Sorensen35a741f2016-02-29 17:04:10 -05002701static int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv)
2702{
2703 char *fw_name;
2704 int ret;
2705
2706 if (priv->enable_bluetooth)
2707 fw_name = "rtlwifi/rtl8723bu_bt.bin";
2708 else
2709 fw_name = "rtlwifi/rtl8723bu_nic.bin";
2710
2711 ret = rtl8xxxu_load_firmware(priv, fw_name);
2712 return ret;
2713}
2714
Kalle Valoc0963772015-10-25 18:24:38 +02002715#ifdef CONFIG_RTL8XXXU_UNTESTED
2716
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002717static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
2718{
2719 char *fw_name;
2720 int ret;
2721
2722 if (!priv->vendor_umc)
2723 fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
2724 else if (priv->chip_cut || priv->rtlchip == 0x8192c)
2725 fw_name = "rtlwifi/rtl8192cufw_B.bin";
2726 else
2727 fw_name = "rtlwifi/rtl8192cufw_A.bin";
2728
2729 ret = rtl8xxxu_load_firmware(priv, fw_name);
2730
2731 return ret;
2732}
2733
Kalle Valoc0963772015-10-25 18:24:38 +02002734#endif
2735
Jes Sorensen3307d842016-02-29 17:03:59 -05002736static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv)
2737{
2738 char *fw_name;
2739 int ret;
2740
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002741 fw_name = "rtlwifi/rtl8192eu_nic.bin";
Jes Sorensen3307d842016-02-29 17:03:59 -05002742
2743 ret = rtl8xxxu_load_firmware(priv, fw_name);
2744
2745 return ret;
2746}
2747
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002748static void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv)
2749{
2750 u16 val16;
2751 int i = 100;
2752
2753 /* Inform 8051 to perform reset */
2754 rtl8xxxu_write8(priv, REG_HMTFR + 3, 0x20);
2755
2756 for (i = 100; i > 0; i--) {
2757 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2758
2759 if (!(val16 & SYS_FUNC_CPU_ENABLE)) {
2760 dev_dbg(&priv->udev->dev,
2761 "%s: Firmware self reset success!\n", __func__);
2762 break;
2763 }
2764 udelay(50);
2765 }
2766
2767 if (!i) {
2768 /* Force firmware reset */
2769 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2770 val16 &= ~SYS_FUNC_CPU_ENABLE;
2771 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
2772 }
2773}
2774
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05002775static void rtl8723bu_phy_init_antenna_selection(struct rtl8xxxu_priv *priv)
2776{
2777 u32 val32;
2778
2779 val32 = rtl8xxxu_read32(priv, 0x64);
2780 val32 &= ~(BIT(20) | BIT(24));
2781 rtl8xxxu_write32(priv, 0x64, val32);
2782
2783 val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG);
2784 val32 &= ~BIT(4);
2785 val32 |= BIT(3);
2786 rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32);
2787
2788 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
2789 val32 &= ~BIT(23);
2790 val32 |= BIT(24);
2791 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
2792
2793 val32 = rtl8xxxu_read32(priv, 0x0944);
2794 val32 |= (BIT(0) | BIT(1));
2795 rtl8xxxu_write32(priv, 0x0944, val32);
2796
2797 val32 = rtl8xxxu_read32(priv, 0x0930);
2798 val32 &= 0xffffff00;
2799 val32 |= 0x77;
2800 rtl8xxxu_write32(priv, 0x0930, val32);
2801
2802 val32 = rtl8xxxu_read32(priv, REG_PWR_DATA);
2803 val32 |= BIT(11);
2804 rtl8xxxu_write32(priv, REG_PWR_DATA, val32);
2805}
2806
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002807static int
2808rtl8xxxu_init_mac(struct rtl8xxxu_priv *priv, struct rtl8xxxu_reg8val *array)
2809{
2810 int i, ret;
2811 u16 reg;
2812 u8 val;
2813
2814 for (i = 0; ; i++) {
2815 reg = array[i].reg;
2816 val = array[i].val;
2817
2818 if (reg == 0xffff && val == 0xff)
2819 break;
2820
2821 ret = rtl8xxxu_write8(priv, reg, val);
2822 if (ret != 1) {
2823 dev_warn(&priv->udev->dev,
2824 "Failed to initialize MAC\n");
2825 return -EAGAIN;
2826 }
2827 }
2828
2829 rtl8xxxu_write8(priv, REG_MAX_AGGR_NUM, 0x0a);
2830
2831 return 0;
2832}
2833
2834static int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv,
2835 struct rtl8xxxu_reg32val *array)
2836{
2837 int i, ret;
2838 u16 reg;
2839 u32 val;
2840
2841 for (i = 0; ; i++) {
2842 reg = array[i].reg;
2843 val = array[i].val;
2844
2845 if (reg == 0xffff && val == 0xffffffff)
2846 break;
2847
2848 ret = rtl8xxxu_write32(priv, reg, val);
2849 if (ret != sizeof(val)) {
2850 dev_warn(&priv->udev->dev,
2851 "Failed to initialize PHY\n");
2852 return -EAGAIN;
2853 }
2854 udelay(1);
2855 }
2856
2857 return 0;
2858}
2859
2860/*
2861 * Most of this is black magic retrieved from the old rtl8723au driver
2862 */
2863static int rtl8xxxu_init_phy_bb(struct rtl8xxxu_priv *priv)
2864{
2865 u8 val8, ldoa15, ldov12d, lpldo, ldohci12;
2866 u32 val32;
2867
2868 /*
2869 * Todo: The vendor driver maintains a table of PHY register
2870 * addresses, which is initialized here. Do we need this?
2871 */
2872
2873 val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL);
2874 udelay(2);
2875 val8 |= AFE_PLL_320_ENABLE;
2876 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8);
2877 udelay(2);
2878
2879 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL + 1, 0xff);
2880 udelay(2);
2881
2882 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
2883 val8 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB;
2884 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
2885
2886 /* AFE_XTAL_RF_GATE (bit 14) if addressing as 32 bit register */
2887 val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL);
2888 val32 &= ~AFE_XTAL_RF_GATE;
2889 if (priv->has_bluetooth)
2890 val32 &= ~AFE_XTAL_BT_GATE;
2891 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32);
2892
2893 /* 6. 0x1f[7:0] = 0x07 */
2894 val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
2895 rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
2896
2897 if (priv->hi_pa)
2898 rtl8xxxu_init_phy_regs(priv, rtl8188ru_phy_1t_highpa_table);
2899 else if (priv->tx_paths == 2)
2900 rtl8xxxu_init_phy_regs(priv, rtl8192cu_phy_2t_init_table);
Jes Sorensen36c32582016-02-29 17:04:14 -05002901 else if (priv->rtlchip == 0x8723b)
2902 rtl8xxxu_init_phy_regs(priv, rtl8723b_phy_1t_init_table);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002903 else
2904 rtl8xxxu_init_phy_regs(priv, rtl8723a_phy_1t_init_table);
2905
2906
2907 if (priv->rtlchip == 0x8188c && priv->hi_pa &&
2908 priv->vendor_umc && priv->chip_cut == 1)
2909 rtl8xxxu_write8(priv, REG_OFDM0_AGC_PARM1 + 2, 0x50);
2910
2911 if (priv->tx_paths == 1 && priv->rx_paths == 2) {
2912 /*
2913 * For 1T2R boards, patch the registers.
2914 *
2915 * It looks like 8191/2 1T2R boards use path B for TX
2916 */
2917 val32 = rtl8xxxu_read32(priv, REG_FPGA0_TX_INFO);
2918 val32 &= ~(BIT(0) | BIT(1));
2919 val32 |= BIT(1);
2920 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, val32);
2921
2922 val32 = rtl8xxxu_read32(priv, REG_FPGA1_TX_INFO);
2923 val32 &= ~0x300033;
2924 val32 |= 0x200022;
2925 rtl8xxxu_write32(priv, REG_FPGA1_TX_INFO, val32);
2926
2927 val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
2928 val32 &= 0xff000000;
2929 val32 |= 0x45000000;
2930 rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
2931
2932 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
2933 val32 &= ~(OFDM_RF_PATH_RX_MASK | OFDM_RF_PATH_TX_MASK);
2934 val32 |= (OFDM_RF_PATH_RX_A | OFDM_RF_PATH_RX_B |
2935 OFDM_RF_PATH_TX_B);
2936 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
2937
2938 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGC_PARM1);
2939 val32 &= ~(BIT(4) | BIT(5));
2940 val32 |= BIT(4);
2941 rtl8xxxu_write32(priv, REG_OFDM0_AGC_PARM1, val32);
2942
2943 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_RFON);
2944 val32 &= ~(BIT(27) | BIT(26));
2945 val32 |= BIT(27);
2946 rtl8xxxu_write32(priv, REG_TX_CCK_RFON, val32);
2947
2948 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_BBON);
2949 val32 &= ~(BIT(27) | BIT(26));
2950 val32 |= BIT(27);
2951 rtl8xxxu_write32(priv, REG_TX_CCK_BBON, val32);
2952
2953 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_RFON);
2954 val32 &= ~(BIT(27) | BIT(26));
2955 val32 |= BIT(27);
2956 rtl8xxxu_write32(priv, REG_TX_OFDM_RFON, val32);
2957
2958 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_BBON);
2959 val32 &= ~(BIT(27) | BIT(26));
2960 val32 |= BIT(27);
2961 rtl8xxxu_write32(priv, REG_TX_OFDM_BBON, val32);
2962
2963 val32 = rtl8xxxu_read32(priv, REG_TX_TO_TX);
2964 val32 &= ~(BIT(27) | BIT(26));
2965 val32 |= BIT(27);
2966 rtl8xxxu_write32(priv, REG_TX_TO_TX, val32);
2967 }
2968
Jes Sorensenb9f498e2016-02-29 17:04:18 -05002969 if (priv->rtlchip == 0x8723b)
2970 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8723bu_table);
2971 else if (priv->hi_pa)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002972 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_highpa_table);
2973 else
2974 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_standard_table);
2975
Jes Sorensen35a741f2016-02-29 17:04:10 -05002976 if ((priv->rtlchip == 0x8723a || priv->rtlchip == 0x8723b) &&
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002977 priv->efuse_wifi.efuse8723.version >= 0x01) {
2978 val32 = rtl8xxxu_read32(priv, REG_MAC_PHY_CTRL);
2979
2980 val8 = priv->efuse_wifi.efuse8723.xtal_k & 0x3f;
2981 val32 &= 0xff000fff;
2982 val32 |= ((val8 | (val8 << 6)) << 12);
2983
2984 rtl8xxxu_write32(priv, REG_MAC_PHY_CTRL, val32);
2985 }
2986
2987 ldoa15 = LDOA15_ENABLE | LDOA15_OBUF;
2988 ldov12d = LDOV12D_ENABLE | BIT(2) | (2 << LDOV12D_VADJ_SHIFT);
2989 ldohci12 = 0x57;
2990 lpldo = 1;
2991 val32 = (lpldo << 24) | (ldohci12 << 16) | (ldov12d << 8) | ldoa15;
2992
2993 rtl8xxxu_write32(priv, REG_LDOA15_CTRL, val32);
2994
2995 return 0;
2996}
2997
2998static int rtl8xxxu_init_rf_regs(struct rtl8xxxu_priv *priv,
2999 struct rtl8xxxu_rfregval *array,
3000 enum rtl8xxxu_rfpath path)
3001{
3002 int i, ret;
3003 u8 reg;
3004 u32 val;
3005
3006 for (i = 0; ; i++) {
3007 reg = array[i].reg;
3008 val = array[i].val;
3009
3010 if (reg == 0xff && val == 0xffffffff)
3011 break;
3012
3013 switch (reg) {
3014 case 0xfe:
3015 msleep(50);
3016 continue;
3017 case 0xfd:
3018 mdelay(5);
3019 continue;
3020 case 0xfc:
3021 mdelay(1);
3022 continue;
3023 case 0xfb:
3024 udelay(50);
3025 continue;
3026 case 0xfa:
3027 udelay(5);
3028 continue;
3029 case 0xf9:
3030 udelay(1);
3031 continue;
3032 }
3033
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003034 ret = rtl8xxxu_write_rfreg(priv, path, reg, val);
3035 if (ret) {
3036 dev_warn(&priv->udev->dev,
3037 "Failed to initialize RF\n");
3038 return -EAGAIN;
3039 }
3040 udelay(1);
3041 }
3042
3043 return 0;
3044}
3045
3046static int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv *priv,
3047 struct rtl8xxxu_rfregval *table,
3048 enum rtl8xxxu_rfpath path)
3049{
3050 u32 val32;
3051 u16 val16, rfsi_rfenv;
3052 u16 reg_sw_ctrl, reg_int_oe, reg_hssi_parm2;
3053
3054 switch (path) {
3055 case RF_A:
3056 reg_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL;
3057 reg_int_oe = REG_FPGA0_XA_RF_INT_OE;
3058 reg_hssi_parm2 = REG_FPGA0_XA_HSSI_PARM2;
3059 break;
3060 case RF_B:
3061 reg_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL;
3062 reg_int_oe = REG_FPGA0_XB_RF_INT_OE;
3063 reg_hssi_parm2 = REG_FPGA0_XB_HSSI_PARM2;
3064 break;
3065 default:
3066 dev_err(&priv->udev->dev, "%s:Unsupported RF path %c\n",
3067 __func__, path + 'A');
3068 return -EINVAL;
3069 }
3070 /* For path B, use XB */
3071 rfsi_rfenv = rtl8xxxu_read16(priv, reg_sw_ctrl);
3072 rfsi_rfenv &= FPGA0_RF_RFENV;
3073
3074 /*
3075 * These two we might be able to optimize into one
3076 */
3077 val32 = rtl8xxxu_read32(priv, reg_int_oe);
3078 val32 |= BIT(20); /* 0x10 << 16 */
3079 rtl8xxxu_write32(priv, reg_int_oe, val32);
3080 udelay(1);
3081
3082 val32 = rtl8xxxu_read32(priv, reg_int_oe);
3083 val32 |= BIT(4);
3084 rtl8xxxu_write32(priv, reg_int_oe, val32);
3085 udelay(1);
3086
3087 /*
3088 * These two we might be able to optimize into one
3089 */
3090 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
3091 val32 &= ~FPGA0_HSSI_3WIRE_ADDR_LEN;
3092 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
3093 udelay(1);
3094
3095 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
3096 val32 &= ~FPGA0_HSSI_3WIRE_DATA_LEN;
3097 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
3098 udelay(1);
3099
3100 rtl8xxxu_init_rf_regs(priv, table, path);
3101
3102 /* For path B, use XB */
3103 val16 = rtl8xxxu_read16(priv, reg_sw_ctrl);
3104 val16 &= ~FPGA0_RF_RFENV;
3105 val16 |= rfsi_rfenv;
3106 rtl8xxxu_write16(priv, reg_sw_ctrl, val16);
3107
3108 return 0;
3109}
3110
3111static int rtl8xxxu_llt_write(struct rtl8xxxu_priv *priv, u8 address, u8 data)
3112{
3113 int ret = -EBUSY;
3114 int count = 0;
3115 u32 value;
3116
3117 value = LLT_OP_WRITE | address << 8 | data;
3118
3119 rtl8xxxu_write32(priv, REG_LLT_INIT, value);
3120
3121 do {
3122 value = rtl8xxxu_read32(priv, REG_LLT_INIT);
3123 if ((value & LLT_OP_MASK) == LLT_OP_INACTIVE) {
3124 ret = 0;
3125 break;
3126 }
3127 } while (count++ < 20);
3128
3129 return ret;
3130}
3131
3132static int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
3133{
3134 int ret;
3135 int i;
3136
3137 for (i = 0; i < last_tx_page; i++) {
3138 ret = rtl8xxxu_llt_write(priv, i, i + 1);
3139 if (ret)
3140 goto exit;
3141 }
3142
3143 ret = rtl8xxxu_llt_write(priv, last_tx_page, 0xff);
3144 if (ret)
3145 goto exit;
3146
3147 /* Mark remaining pages as a ring buffer */
3148 for (i = last_tx_page + 1; i < 0xff; i++) {
3149 ret = rtl8xxxu_llt_write(priv, i, (i + 1));
3150 if (ret)
3151 goto exit;
3152 }
3153
3154 /* Let last entry point to the start entry of ring buffer */
3155 ret = rtl8xxxu_llt_write(priv, 0xff, last_tx_page + 1);
3156 if (ret)
3157 goto exit;
3158
3159exit:
3160 return ret;
3161}
3162
Jes Sorensen74b99be2016-02-29 17:04:04 -05003163static int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
3164{
3165 u32 val32;
3166 int ret = 0;
3167 int i;
3168
3169 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
Jes Sorensen74b99be2016-02-29 17:04:04 -05003170 val32 |= AUTO_LLT_INIT_LLT;
3171 rtl8xxxu_write32(priv, REG_AUTO_LLT, val32);
3172
3173 for (i = 500; i; i--) {
3174 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
3175 if (!(val32 & AUTO_LLT_INIT_LLT))
3176 break;
3177 usleep_range(2, 4);
3178 }
3179
Jes Sorensen4de24812016-02-29 17:04:07 -05003180 if (!i) {
Jes Sorensen74b99be2016-02-29 17:04:04 -05003181 ret = -EBUSY;
3182 dev_warn(&priv->udev->dev, "LLT table init failed\n");
3183 }
Jes Sorensen74b99be2016-02-29 17:04:04 -05003184
3185 return ret;
3186}
3187
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003188static int rtl8xxxu_init_queue_priority(struct rtl8xxxu_priv *priv)
3189{
3190 u16 val16, hi, lo;
3191 u16 hiq, mgq, bkq, beq, viq, voq;
3192 int hip, mgp, bkp, bep, vip, vop;
3193 int ret = 0;
3194
3195 switch (priv->ep_tx_count) {
3196 case 1:
3197 if (priv->ep_tx_high_queue) {
3198 hi = TRXDMA_QUEUE_HIGH;
3199 } else if (priv->ep_tx_low_queue) {
3200 hi = TRXDMA_QUEUE_LOW;
3201 } else if (priv->ep_tx_normal_queue) {
3202 hi = TRXDMA_QUEUE_NORMAL;
3203 } else {
3204 hi = 0;
3205 ret = -EINVAL;
3206 }
3207
3208 hiq = hi;
3209 mgq = hi;
3210 bkq = hi;
3211 beq = hi;
3212 viq = hi;
3213 voq = hi;
3214
3215 hip = 0;
3216 mgp = 0;
3217 bkp = 0;
3218 bep = 0;
3219 vip = 0;
3220 vop = 0;
3221 break;
3222 case 2:
3223 if (priv->ep_tx_high_queue && priv->ep_tx_low_queue) {
3224 hi = TRXDMA_QUEUE_HIGH;
3225 lo = TRXDMA_QUEUE_LOW;
3226 } else if (priv->ep_tx_normal_queue && priv->ep_tx_low_queue) {
3227 hi = TRXDMA_QUEUE_NORMAL;
3228 lo = TRXDMA_QUEUE_LOW;
3229 } else if (priv->ep_tx_high_queue && priv->ep_tx_normal_queue) {
3230 hi = TRXDMA_QUEUE_HIGH;
3231 lo = TRXDMA_QUEUE_NORMAL;
3232 } else {
3233 ret = -EINVAL;
3234 hi = 0;
3235 lo = 0;
3236 }
3237
3238 hiq = hi;
3239 mgq = hi;
3240 bkq = lo;
3241 beq = lo;
3242 viq = hi;
3243 voq = hi;
3244
3245 hip = 0;
3246 mgp = 0;
3247 bkp = 1;
3248 bep = 1;
3249 vip = 0;
3250 vop = 0;
3251 break;
3252 case 3:
3253 beq = TRXDMA_QUEUE_LOW;
3254 bkq = TRXDMA_QUEUE_LOW;
3255 viq = TRXDMA_QUEUE_NORMAL;
3256 voq = TRXDMA_QUEUE_HIGH;
3257 mgq = TRXDMA_QUEUE_HIGH;
3258 hiq = TRXDMA_QUEUE_HIGH;
3259
3260 hip = hiq ^ 3;
3261 mgp = mgq ^ 3;
3262 bkp = bkq ^ 3;
3263 bep = beq ^ 3;
3264 vip = viq ^ 3;
3265 vop = viq ^ 3;
3266 break;
3267 default:
3268 ret = -EINVAL;
3269 }
3270
3271 /*
3272 * None of the vendor drivers are configuring the beacon
3273 * queue here .... why?
3274 */
3275 if (!ret) {
3276 val16 = rtl8xxxu_read16(priv, REG_TRXDMA_CTRL);
3277 val16 &= 0x7;
3278 val16 |= (voq << TRXDMA_CTRL_VOQ_SHIFT) |
3279 (viq << TRXDMA_CTRL_VIQ_SHIFT) |
3280 (beq << TRXDMA_CTRL_BEQ_SHIFT) |
3281 (bkq << TRXDMA_CTRL_BKQ_SHIFT) |
3282 (mgq << TRXDMA_CTRL_MGQ_SHIFT) |
3283 (hiq << TRXDMA_CTRL_HIQ_SHIFT);
3284 rtl8xxxu_write16(priv, REG_TRXDMA_CTRL, val16);
3285
3286 priv->pipe_out[TXDESC_QUEUE_VO] =
3287 usb_sndbulkpipe(priv->udev, priv->out_ep[vop]);
3288 priv->pipe_out[TXDESC_QUEUE_VI] =
3289 usb_sndbulkpipe(priv->udev, priv->out_ep[vip]);
3290 priv->pipe_out[TXDESC_QUEUE_BE] =
3291 usb_sndbulkpipe(priv->udev, priv->out_ep[bep]);
3292 priv->pipe_out[TXDESC_QUEUE_BK] =
3293 usb_sndbulkpipe(priv->udev, priv->out_ep[bkp]);
3294 priv->pipe_out[TXDESC_QUEUE_BEACON] =
3295 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
3296 priv->pipe_out[TXDESC_QUEUE_MGNT] =
3297 usb_sndbulkpipe(priv->udev, priv->out_ep[mgp]);
3298 priv->pipe_out[TXDESC_QUEUE_HIGH] =
3299 usb_sndbulkpipe(priv->udev, priv->out_ep[hip]);
3300 priv->pipe_out[TXDESC_QUEUE_CMD] =
3301 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
3302 }
3303
3304 return ret;
3305}
3306
3307static void rtl8xxxu_fill_iqk_matrix_a(struct rtl8xxxu_priv *priv,
3308 bool iqk_ok, int result[][8],
3309 int candidate, bool tx_only)
3310{
3311 u32 oldval, x, tx0_a, reg;
3312 int y, tx0_c;
3313 u32 val32;
3314
3315 if (!iqk_ok)
3316 return;
3317
3318 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3319 oldval = val32 >> 22;
3320
3321 x = result[candidate][0];
3322 if ((x & 0x00000200) != 0)
3323 x = x | 0xfffffc00;
3324 tx0_a = (x * oldval) >> 8;
3325
3326 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3327 val32 &= ~0x3ff;
3328 val32 |= tx0_a;
3329 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
3330
3331 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3332 val32 &= ~BIT(31);
3333 if ((x * oldval >> 7) & 0x1)
3334 val32 |= BIT(31);
3335 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3336
3337 y = result[candidate][1];
3338 if ((y & 0x00000200) != 0)
3339 y = y | 0xfffffc00;
3340 tx0_c = (y * oldval) >> 8;
3341
3342 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XC_TX_AFE);
3343 val32 &= ~0xf0000000;
3344 val32 |= (((tx0_c & 0x3c0) >> 6) << 28);
3345 rtl8xxxu_write32(priv, REG_OFDM0_XC_TX_AFE, val32);
3346
3347 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3348 val32 &= ~0x003f0000;
3349 val32 |= ((tx0_c & 0x3f) << 16);
3350 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
3351
3352 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3353 val32 &= ~BIT(29);
3354 if ((y * oldval >> 7) & 0x1)
3355 val32 |= BIT(29);
3356 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3357
3358 if (tx_only) {
3359 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
3360 return;
3361 }
3362
3363 reg = result[candidate][2];
3364
3365 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
3366 val32 &= ~0x3ff;
3367 val32 |= (reg & 0x3ff);
3368 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
3369
3370 reg = result[candidate][3] & 0x3F;
3371
3372 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
3373 val32 &= ~0xfc00;
3374 val32 |= ((reg << 10) & 0xfc00);
3375 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
3376
3377 reg = (result[candidate][3] >> 6) & 0xF;
3378
3379 val32 = rtl8xxxu_read32(priv, REG_OFDM0_RX_IQ_EXT_ANTA);
3380 val32 &= ~0xf0000000;
3381 val32 |= (reg << 28);
3382 rtl8xxxu_write32(priv, REG_OFDM0_RX_IQ_EXT_ANTA, val32);
3383}
3384
3385static void rtl8xxxu_fill_iqk_matrix_b(struct rtl8xxxu_priv *priv,
3386 bool iqk_ok, int result[][8],
3387 int candidate, bool tx_only)
3388{
3389 u32 oldval, x, tx1_a, reg;
3390 int y, tx1_c;
3391 u32 val32;
3392
3393 if (!iqk_ok)
3394 return;
3395
3396 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3397 oldval = val32 >> 22;
3398
3399 x = result[candidate][4];
3400 if ((x & 0x00000200) != 0)
3401 x = x | 0xfffffc00;
3402 tx1_a = (x * oldval) >> 8;
3403
3404 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3405 val32 &= ~0x3ff;
3406 val32 |= tx1_a;
3407 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
3408
3409 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3410 val32 &= ~BIT(27);
3411 if ((x * oldval >> 7) & 0x1)
3412 val32 |= BIT(27);
3413 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3414
3415 y = result[candidate][5];
3416 if ((y & 0x00000200) != 0)
3417 y = y | 0xfffffc00;
3418 tx1_c = (y * oldval) >> 8;
3419
3420 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XD_TX_AFE);
3421 val32 &= ~0xf0000000;
3422 val32 |= (((tx1_c & 0x3c0) >> 6) << 28);
3423 rtl8xxxu_write32(priv, REG_OFDM0_XD_TX_AFE, val32);
3424
3425 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3426 val32 &= ~0x003f0000;
3427 val32 |= ((tx1_c & 0x3f) << 16);
3428 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
3429
3430 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3431 val32 &= ~BIT(25);
3432 if ((y * oldval >> 7) & 0x1)
3433 val32 |= BIT(25);
3434 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3435
3436 if (tx_only) {
3437 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
3438 return;
3439 }
3440
3441 reg = result[candidate][6];
3442
3443 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
3444 val32 &= ~0x3ff;
3445 val32 |= (reg & 0x3ff);
3446 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
3447
3448 reg = result[candidate][7] & 0x3f;
3449
3450 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
3451 val32 &= ~0xfc00;
3452 val32 |= ((reg << 10) & 0xfc00);
3453 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
3454
3455 reg = (result[candidate][7] >> 6) & 0xf;
3456
3457 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGCR_SSI_TABLE);
3458 val32 &= ~0x0000f000;
3459 val32 |= (reg << 12);
3460 rtl8xxxu_write32(priv, REG_OFDM0_AGCR_SSI_TABLE, val32);
3461}
3462
3463#define MAX_TOLERANCE 5
3464
3465static bool rtl8xxxu_simularity_compare(struct rtl8xxxu_priv *priv,
3466 int result[][8], int c1, int c2)
3467{
3468 u32 i, j, diff, simubitmap, bound = 0;
3469 int candidate[2] = {-1, -1}; /* for path A and path B */
3470 bool retval = true;
3471
3472 if (priv->tx_paths > 1)
3473 bound = 8;
3474 else
3475 bound = 4;
3476
3477 simubitmap = 0;
3478
3479 for (i = 0; i < bound; i++) {
3480 diff = (result[c1][i] > result[c2][i]) ?
3481 (result[c1][i] - result[c2][i]) :
3482 (result[c2][i] - result[c1][i]);
3483 if (diff > MAX_TOLERANCE) {
3484 if ((i == 2 || i == 6) && !simubitmap) {
3485 if (result[c1][i] + result[c1][i + 1] == 0)
3486 candidate[(i / 4)] = c2;
3487 else if (result[c2][i] + result[c2][i + 1] == 0)
3488 candidate[(i / 4)] = c1;
3489 else
3490 simubitmap = simubitmap | (1 << i);
3491 } else {
3492 simubitmap = simubitmap | (1 << i);
3493 }
3494 }
3495 }
3496
3497 if (simubitmap == 0) {
3498 for (i = 0; i < (bound / 4); i++) {
3499 if (candidate[i] >= 0) {
3500 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
3501 result[3][j] = result[candidate[i]][j];
3502 retval = false;
3503 }
3504 }
3505 return retval;
3506 } else if (!(simubitmap & 0x0f)) {
3507 /* path A OK */
3508 for (i = 0; i < 4; i++)
3509 result[3][i] = result[c1][i];
3510 } else if (!(simubitmap & 0xf0) && priv->tx_paths > 1) {
3511 /* path B OK */
3512 for (i = 4; i < 8; i++)
3513 result[3][i] = result[c1][i];
3514 }
3515
3516 return false;
3517}
3518
3519static void
3520rtl8xxxu_save_mac_regs(struct rtl8xxxu_priv *priv, const u32 *reg, u32 *backup)
3521{
3522 int i;
3523
3524 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
3525 backup[i] = rtl8xxxu_read8(priv, reg[i]);
3526
3527 backup[i] = rtl8xxxu_read32(priv, reg[i]);
3528}
3529
3530static void rtl8xxxu_restore_mac_regs(struct rtl8xxxu_priv *priv,
3531 const u32 *reg, u32 *backup)
3532{
3533 int i;
3534
3535 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
3536 rtl8xxxu_write8(priv, reg[i], backup[i]);
3537
3538 rtl8xxxu_write32(priv, reg[i], backup[i]);
3539}
3540
3541static void rtl8xxxu_save_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
3542 u32 *backup, int count)
3543{
3544 int i;
3545
3546 for (i = 0; i < count; i++)
3547 backup[i] = rtl8xxxu_read32(priv, regs[i]);
3548}
3549
3550static void rtl8xxxu_restore_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
3551 u32 *backup, int count)
3552{
3553 int i;
3554
3555 for (i = 0; i < count; i++)
3556 rtl8xxxu_write32(priv, regs[i], backup[i]);
3557}
3558
3559
3560static void rtl8xxxu_path_adda_on(struct rtl8xxxu_priv *priv, const u32 *regs,
3561 bool path_a_on)
3562{
3563 u32 path_on;
3564 int i;
3565
3566 path_on = path_a_on ? 0x04db25a4 : 0x0b1b25a4;
3567 if (priv->tx_paths == 1) {
3568 path_on = 0x0bdb25a0;
3569 rtl8xxxu_write32(priv, regs[0], 0x0b1b25a0);
3570 } else {
3571 rtl8xxxu_write32(priv, regs[0], path_on);
3572 }
3573
3574 for (i = 1 ; i < RTL8XXXU_ADDA_REGS ; i++)
3575 rtl8xxxu_write32(priv, regs[i], path_on);
3576}
3577
3578static void rtl8xxxu_mac_calibration(struct rtl8xxxu_priv *priv,
3579 const u32 *regs, u32 *backup)
3580{
3581 int i = 0;
3582
3583 rtl8xxxu_write8(priv, regs[i], 0x3f);
3584
3585 for (i = 1 ; i < (RTL8XXXU_MAC_REGS - 1); i++)
3586 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(3)));
3587
3588 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(5)));
3589}
3590
3591static int rtl8xxxu_iqk_path_a(struct rtl8xxxu_priv *priv)
3592{
3593 u32 reg_eac, reg_e94, reg_e9c, reg_ea4, val32;
3594 int result = 0;
3595
3596 /* path-A IQK setting */
3597 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1f);
3598 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x10008c1f);
3599 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82140102);
3600
3601 val32 = (priv->rf_paths > 1) ? 0x28160202 :
3602 /*IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)?0x28160202: */
3603 0x28160502;
3604 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, val32);
3605
3606 /* path-B IQK setting */
3607 if (priv->rf_paths > 1) {
3608 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x10008c22);
3609 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x10008c22);
3610 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82140102);
3611 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28160202);
3612 }
3613
3614 /* LO calibration setting */
3615 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x001028d1);
3616
3617 /* One shot, path A LOK & IQK */
3618 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
3619 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
3620
3621 mdelay(1);
3622
3623 /* Check failed */
3624 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
3625 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
3626 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
3627 reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
3628
3629 if (!(reg_eac & BIT(28)) &&
3630 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
3631 ((reg_e9c & 0x03ff0000) != 0x00420000))
3632 result |= 0x01;
3633 else /* If TX not OK, ignore RX */
3634 goto out;
3635
3636 /* If TX is OK, check whether RX is OK */
3637 if (!(reg_eac & BIT(27)) &&
3638 ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
3639 ((reg_eac & 0x03ff0000) != 0x00360000))
3640 result |= 0x02;
3641 else
3642 dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n",
3643 __func__);
3644out:
3645 return result;
3646}
3647
3648static int rtl8xxxu_iqk_path_b(struct rtl8xxxu_priv *priv)
3649{
3650 u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
3651 int result = 0;
3652
3653 /* One shot, path B LOK & IQK */
3654 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
3655 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
3656
3657 mdelay(1);
3658
3659 /* Check failed */
3660 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
3661 reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
3662 reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
3663 reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
3664 reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
3665
3666 if (!(reg_eac & BIT(31)) &&
3667 ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
3668 ((reg_ebc & 0x03ff0000) != 0x00420000))
3669 result |= 0x01;
3670 else
3671 goto out;
3672
3673 if (!(reg_eac & BIT(30)) &&
3674 (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) &&
3675 (((reg_ecc & 0x03ff0000) >> 16) != 0x36))
3676 result |= 0x02;
3677 else
3678 dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
3679 __func__);
3680out:
3681 return result;
3682}
3683
3684static void rtl8xxxu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
3685 int result[][8], int t)
3686{
3687 struct device *dev = &priv->udev->dev;
3688 u32 i, val32;
3689 int path_a_ok, path_b_ok;
3690 int retry = 2;
3691 const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
3692 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
3693 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
3694 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
3695 REG_TX_OFDM_BBON, REG_TX_TO_RX,
3696 REG_TX_TO_TX, REG_RX_CCK,
3697 REG_RX_OFDM, REG_RX_WAIT_RIFS,
3698 REG_RX_TO_RX, REG_STANDBY,
3699 REG_SLEEP, REG_PMPD_ANAEN
3700 };
3701 const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
3702 REG_TXPAUSE, REG_BEACON_CTRL,
3703 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
3704 };
3705 const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
3706 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
3707 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
3708 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
3709 REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
3710 };
3711
3712 /*
3713 * Note: IQ calibration must be performed after loading
3714 * PHY_REG.txt , and radio_a, radio_b.txt
3715 */
3716
3717 if (t == 0) {
3718 /* Save ADDA parameters, turn Path A ADDA on */
3719 rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
3720 RTL8XXXU_ADDA_REGS);
3721 rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
3722 rtl8xxxu_save_regs(priv, iqk_bb_regs,
3723 priv->bb_backup, RTL8XXXU_BB_REGS);
3724 }
3725
3726 rtl8xxxu_path_adda_on(priv, adda_regs, true);
3727
3728 if (t == 0) {
3729 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1);
3730 if (val32 & FPGA0_HSSI_PARM1_PI)
3731 priv->pi_enabled = 1;
3732 }
3733
3734 if (!priv->pi_enabled) {
3735 /* Switch BB to PI mode to do IQ Calibration. */
3736 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0x01000100);
3737 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0x01000100);
3738 }
3739
3740 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
3741 val32 &= ~FPGA_RF_MODE_CCK;
3742 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
3743
3744 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
3745 rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
3746 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
3747
3748 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
3749 val32 |= (FPGA0_RF_PAPE | (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
3750 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
3751
3752 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
3753 val32 &= ~BIT(10);
3754 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
3755 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
3756 val32 &= ~BIT(10);
3757 rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
3758
3759 if (priv->tx_paths > 1) {
3760 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
3761 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, 0x00010000);
3762 }
3763
3764 /* MAC settings */
3765 rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
3766
3767 /* Page B init */
3768 rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x00080000);
3769
3770 if (priv->tx_paths > 1)
3771 rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x00080000);
3772
3773 /* IQ calibration setting */
3774 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
3775 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
3776 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
3777
3778 for (i = 0; i < retry; i++) {
3779 path_a_ok = rtl8xxxu_iqk_path_a(priv);
3780 if (path_a_ok == 0x03) {
3781 val32 = rtl8xxxu_read32(priv,
3782 REG_TX_POWER_BEFORE_IQK_A);
3783 result[t][0] = (val32 >> 16) & 0x3ff;
3784 val32 = rtl8xxxu_read32(priv,
3785 REG_TX_POWER_AFTER_IQK_A);
3786 result[t][1] = (val32 >> 16) & 0x3ff;
3787 val32 = rtl8xxxu_read32(priv,
3788 REG_RX_POWER_BEFORE_IQK_A_2);
3789 result[t][2] = (val32 >> 16) & 0x3ff;
3790 val32 = rtl8xxxu_read32(priv,
3791 REG_RX_POWER_AFTER_IQK_A_2);
3792 result[t][3] = (val32 >> 16) & 0x3ff;
3793 break;
3794 } else if (i == (retry - 1) && path_a_ok == 0x01) {
3795 /* TX IQK OK */
3796 dev_dbg(dev, "%s: Path A IQK Only Tx Success!!\n",
3797 __func__);
3798
3799 val32 = rtl8xxxu_read32(priv,
3800 REG_TX_POWER_BEFORE_IQK_A);
3801 result[t][0] = (val32 >> 16) & 0x3ff;
3802 val32 = rtl8xxxu_read32(priv,
3803 REG_TX_POWER_AFTER_IQK_A);
3804 result[t][1] = (val32 >> 16) & 0x3ff;
3805 }
3806 }
3807
3808 if (!path_a_ok)
3809 dev_dbg(dev, "%s: Path A IQK failed!\n", __func__);
3810
3811 if (priv->tx_paths > 1) {
3812 /*
3813 * Path A into standby
3814 */
3815 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x0);
3816 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
3817 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
3818
3819 /* Turn Path B ADDA on */
3820 rtl8xxxu_path_adda_on(priv, adda_regs, false);
3821
3822 for (i = 0; i < retry; i++) {
3823 path_b_ok = rtl8xxxu_iqk_path_b(priv);
3824 if (path_b_ok == 0x03) {
3825 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
3826 result[t][4] = (val32 >> 16) & 0x3ff;
3827 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
3828 result[t][5] = (val32 >> 16) & 0x3ff;
3829 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
3830 result[t][6] = (val32 >> 16) & 0x3ff;
3831 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
3832 result[t][7] = (val32 >> 16) & 0x3ff;
3833 break;
3834 } else if (i == (retry - 1) && path_b_ok == 0x01) {
3835 /* TX IQK OK */
3836 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
3837 result[t][4] = (val32 >> 16) & 0x3ff;
3838 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
3839 result[t][5] = (val32 >> 16) & 0x3ff;
3840 }
3841 }
3842
3843 if (!path_b_ok)
3844 dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
3845 }
3846
3847 /* Back to BB mode, load original value */
3848 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0);
3849
3850 if (t) {
3851 if (!priv->pi_enabled) {
3852 /*
3853 * Switch back BB to SI mode after finishing
3854 * IQ Calibration
3855 */
3856 val32 = 0x01000000;
3857 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, val32);
3858 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, val32);
3859 }
3860
3861 /* Reload ADDA power saving parameters */
3862 rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
3863 RTL8XXXU_ADDA_REGS);
3864
3865 /* Reload MAC parameters */
3866 rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
3867
3868 /* Reload BB parameters */
3869 rtl8xxxu_restore_regs(priv, iqk_bb_regs,
3870 priv->bb_backup, RTL8XXXU_BB_REGS);
3871
3872 /* Restore RX initial gain */
3873 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00032ed3);
3874
3875 if (priv->tx_paths > 1) {
3876 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM,
3877 0x00032ed3);
3878 }
3879
3880 /* Load 0xe30 IQC default value */
3881 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
3882 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
3883 }
3884}
3885
3886static void rtl8723a_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
3887{
3888 struct device *dev = &priv->udev->dev;
3889 int result[4][8]; /* last is final result */
3890 int i, candidate;
3891 bool path_a_ok, path_b_ok;
3892 u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
3893 u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
3894 s32 reg_tmp = 0;
3895 bool simu;
3896
3897 memset(result, 0, sizeof(result));
3898 candidate = -1;
3899
3900 path_a_ok = false;
3901 path_b_ok = false;
3902
3903 rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
3904
3905 for (i = 0; i < 3; i++) {
3906 rtl8xxxu_phy_iqcalibrate(priv, result, i);
3907
3908 if (i == 1) {
3909 simu = rtl8xxxu_simularity_compare(priv, result, 0, 1);
3910 if (simu) {
3911 candidate = 0;
3912 break;
3913 }
3914 }
3915
3916 if (i == 2) {
3917 simu = rtl8xxxu_simularity_compare(priv, result, 0, 2);
3918 if (simu) {
3919 candidate = 0;
3920 break;
3921 }
3922
3923 simu = rtl8xxxu_simularity_compare(priv, result, 1, 2);
3924 if (simu) {
3925 candidate = 1;
3926 } else {
3927 for (i = 0; i < 8; i++)
3928 reg_tmp += result[3][i];
3929
3930 if (reg_tmp)
3931 candidate = 3;
3932 else
3933 candidate = -1;
3934 }
3935 }
3936 }
3937
3938 for (i = 0; i < 4; i++) {
3939 reg_e94 = result[i][0];
3940 reg_e9c = result[i][1];
3941 reg_ea4 = result[i][2];
3942 reg_eac = result[i][3];
3943 reg_eb4 = result[i][4];
3944 reg_ebc = result[i][5];
3945 reg_ec4 = result[i][6];
3946 reg_ecc = result[i][7];
3947 }
3948
3949 if (candidate >= 0) {
3950 reg_e94 = result[candidate][0];
3951 priv->rege94 = reg_e94;
3952 reg_e9c = result[candidate][1];
3953 priv->rege9c = reg_e9c;
3954 reg_ea4 = result[candidate][2];
3955 reg_eac = result[candidate][3];
3956 reg_eb4 = result[candidate][4];
3957 priv->regeb4 = reg_eb4;
3958 reg_ebc = result[candidate][5];
3959 priv->regebc = reg_ebc;
3960 reg_ec4 = result[candidate][6];
3961 reg_ecc = result[candidate][7];
3962 dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
3963 dev_dbg(dev,
3964 "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
3965 "ecc=%x\n ", __func__, reg_e94, reg_e9c,
3966 reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
3967 path_a_ok = true;
3968 path_b_ok = true;
3969 } else {
3970 reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
3971 reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
3972 }
3973
3974 if (reg_e94 && candidate >= 0)
3975 rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
3976 candidate, (reg_ea4 == 0));
3977
3978 if (priv->tx_paths > 1 && reg_eb4)
3979 rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
3980 candidate, (reg_ec4 == 0));
3981
3982 rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg,
3983 priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
3984}
3985
3986static void rtl8723a_phy_lc_calibrate(struct rtl8xxxu_priv *priv)
3987{
3988 u32 val32;
3989 u32 rf_amode, rf_bmode = 0, lstf;
3990
3991 /* Check continuous TX and Packet TX */
3992 lstf = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
3993
3994 if (lstf & OFDM_LSTF_MASK) {
3995 /* Disable all continuous TX */
3996 val32 = lstf & ~OFDM_LSTF_MASK;
3997 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
3998
3999 /* Read original RF mode Path A */
4000 rf_amode = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_AC);
4001
4002 /* Set RF mode to standby Path A */
4003 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC,
4004 (rf_amode & 0x8ffff) | 0x10000);
4005
4006 /* Path-B */
4007 if (priv->tx_paths > 1) {
4008 rf_bmode = rtl8xxxu_read_rfreg(priv, RF_B,
4009 RF6052_REG_AC);
4010
4011 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
4012 (rf_bmode & 0x8ffff) | 0x10000);
4013 }
4014 } else {
4015 /* Deal with Packet TX case */
4016 /* block all queues */
4017 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
4018 }
4019
4020 /* Start LC calibration */
4021 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_MODE_AG);
4022 val32 |= 0x08000;
4023 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, val32);
4024
4025 msleep(100);
4026
4027 /* Restore original parameters */
4028 if (lstf & OFDM_LSTF_MASK) {
4029 /* Path-A */
4030 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, lstf);
4031 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, rf_amode);
4032
4033 /* Path-B */
4034 if (priv->tx_paths > 1)
4035 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
4036 rf_bmode);
4037 } else /* Deal with Packet TX case */
4038 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
4039}
4040
4041static int rtl8xxxu_set_mac(struct rtl8xxxu_priv *priv)
4042{
4043 int i;
4044 u16 reg;
4045
4046 reg = REG_MACID;
4047
4048 for (i = 0; i < ETH_ALEN; i++)
4049 rtl8xxxu_write8(priv, reg + i, priv->mac_addr[i]);
4050
4051 return 0;
4052}
4053
4054static int rtl8xxxu_set_bssid(struct rtl8xxxu_priv *priv, const u8 *bssid)
4055{
4056 int i;
4057 u16 reg;
4058
4059 dev_dbg(&priv->udev->dev, "%s: (%pM)\n", __func__, bssid);
4060
4061 reg = REG_BSSID;
4062
4063 for (i = 0; i < ETH_ALEN; i++)
4064 rtl8xxxu_write8(priv, reg + i, bssid[i]);
4065
4066 return 0;
4067}
4068
4069static void
4070rtl8xxxu_set_ampdu_factor(struct rtl8xxxu_priv *priv, u8 ampdu_factor)
4071{
4072 u8 vals[4] = { 0x41, 0xa8, 0x72, 0xb9 };
4073 u8 max_agg = 0xf;
4074 int i;
4075
4076 ampdu_factor = 1 << (ampdu_factor + 2);
4077 if (ampdu_factor > max_agg)
4078 ampdu_factor = max_agg;
4079
4080 for (i = 0; i < 4; i++) {
4081 if ((vals[i] & 0xf0) > (ampdu_factor << 4))
4082 vals[i] = (vals[i] & 0x0f) | (ampdu_factor << 4);
4083
4084 if ((vals[i] & 0x0f) > ampdu_factor)
4085 vals[i] = (vals[i] & 0xf0) | ampdu_factor;
4086
4087 rtl8xxxu_write8(priv, REG_AGGLEN_LMT + i, vals[i]);
4088 }
4089}
4090
4091static void rtl8xxxu_set_ampdu_min_space(struct rtl8xxxu_priv *priv, u8 density)
4092{
4093 u8 val8;
4094
4095 val8 = rtl8xxxu_read8(priv, REG_AMPDU_MIN_SPACE);
4096 val8 &= 0xf8;
4097 val8 |= density;
4098 rtl8xxxu_write8(priv, REG_AMPDU_MIN_SPACE, val8);
4099}
4100
4101static int rtl8xxxu_active_to_emu(struct rtl8xxxu_priv *priv)
4102{
4103 u8 val8;
4104 int count, ret;
4105
4106 /* Start of rtl8723AU_card_enable_flow */
4107 /* Act to Cardemu sequence*/
4108 /* Turn off RF */
4109 rtl8xxxu_write8(priv, REG_RF_CTRL, 0);
4110
4111 /* 0x004E[7] = 0, switch DPDT_SEL_P output from register 0x0065[2] */
4112 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
4113 val8 &= ~LEDCFG2_DPDT_SELECT;
4114 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
4115
4116 /* 0x0005[1] = 1 turn off MAC by HW state machine*/
4117 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4118 val8 |= BIT(1);
4119 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4120
4121 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4122 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4123 if ((val8 & BIT(1)) == 0)
4124 break;
4125 udelay(10);
4126 }
4127
4128 if (!count) {
4129 dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n",
4130 __func__);
4131 ret = -EBUSY;
4132 goto exit;
4133 }
4134
4135 /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */
4136 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
4137 val8 |= SYS_ISO_ANALOG_IPS;
4138 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
4139
4140 /* 0x0020[0] = 0 disable LDOA12 MACRO block*/
4141 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
4142 val8 &= ~LDOA15_ENABLE;
4143 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
4144
4145exit:
4146 return ret;
4147}
4148
4149static int rtl8xxxu_active_to_lps(struct rtl8xxxu_priv *priv)
4150{
4151 u8 val8;
4152 u8 val32;
4153 int count, ret;
4154
4155 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
4156
4157 /*
4158 * Poll - wait for RX packet to complete
4159 */
4160 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4161 val32 = rtl8xxxu_read32(priv, 0x5f8);
4162 if (!val32)
4163 break;
4164 udelay(10);
4165 }
4166
4167 if (!count) {
4168 dev_warn(&priv->udev->dev,
4169 "%s: RX poll timed out (0x05f8)\n", __func__);
4170 ret = -EBUSY;
4171 goto exit;
4172 }
4173
4174 /* Disable CCK and OFDM, clock gated */
4175 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
4176 val8 &= ~SYS_FUNC_BBRSTB;
4177 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
4178
4179 udelay(2);
4180
4181 /* Reset baseband */
4182 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
4183 val8 &= ~SYS_FUNC_BB_GLB_RSTN;
4184 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
4185
4186 /* Reset MAC TRX */
4187 val8 = rtl8xxxu_read8(priv, REG_CR);
4188 val8 = CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE;
4189 rtl8xxxu_write8(priv, REG_CR, val8);
4190
4191 /* Reset MAC TRX */
4192 val8 = rtl8xxxu_read8(priv, REG_CR + 1);
4193 val8 &= ~BIT(1); /* CR_SECURITY_ENABLE */
4194 rtl8xxxu_write8(priv, REG_CR + 1, val8);
4195
4196 /* Respond TX OK to scheduler */
4197 val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST);
4198 val8 |= DUAL_TSF_TX_OK;
4199 rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);
4200
4201exit:
4202 return ret;
4203}
4204
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004205static void rtl8723a_disabled_to_emu(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004206{
4207 u8 val8;
4208
4209 /* Clear suspend enable and power down enable*/
4210 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4211 val8 &= ~(BIT(3) | BIT(7));
4212 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4213
4214 /* 0x48[16] = 0 to disable GPIO9 as EXT WAKEUP*/
4215 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
4216 val8 &= ~BIT(0);
4217 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
4218
4219 /* 0x04[12:11] = 11 enable WL suspend*/
4220 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4221 val8 &= ~(BIT(3) | BIT(4));
4222 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4223}
4224
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004225static void rtl8192e_disabled_to_emu(struct rtl8xxxu_priv *priv)
4226{
4227 u8 val8;
4228
4229 /* Clear suspend enable and power down enable*/
4230 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4231 val8 &= ~(BIT(3) | BIT(4));
4232 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4233}
4234
4235static int rtl8192e_emu_to_active(struct rtl8xxxu_priv *priv)
4236{
4237 u8 val8;
4238 u32 val32;
4239 int count, ret = 0;
4240
4241 /* disable HWPDN 0x04[15]=0*/
4242 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4243 val8 &= ~BIT(7);
4244 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4245
4246 /* disable SW LPS 0x04[10]= 0 */
4247 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4248 val8 &= ~BIT(2);
4249 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4250
4251 /* disable WL suspend*/
4252 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4253 val8 &= ~(BIT(3) | BIT(4));
4254 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4255
4256 /* wait till 0x04[17] = 1 power ready*/
4257 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4258 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4259 if (val32 & BIT(17))
4260 break;
4261
4262 udelay(10);
4263 }
4264
4265 if (!count) {
4266 ret = -EBUSY;
4267 goto exit;
4268 }
4269
4270 /* We should be able to optimize the following three entries into one */
4271
4272 /* release WLON reset 0x04[16]= 1*/
4273 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
4274 val8 |= BIT(0);
4275 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
4276
4277 /* set, then poll until 0 */
4278 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4279 val32 |= APS_FSMCO_MAC_ENABLE;
4280 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
4281
4282 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4283 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4284 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
4285 ret = 0;
4286 break;
4287 }
4288 udelay(10);
4289 }
4290
4291 if (!count) {
4292 ret = -EBUSY;
4293 goto exit;
4294 }
4295
4296exit:
4297 return ret;
4298}
4299
4300static int rtl8723a_emu_to_active(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004301{
4302 u8 val8;
4303 u32 val32;
4304 int count, ret = 0;
4305
4306 /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface*/
4307 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
4308 val8 |= LDOA15_ENABLE;
4309 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
4310
4311 /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/
4312 val8 = rtl8xxxu_read8(priv, 0x0067);
4313 val8 &= ~BIT(4);
4314 rtl8xxxu_write8(priv, 0x0067, val8);
4315
4316 mdelay(1);
4317
4318 /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */
4319 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
4320 val8 &= ~SYS_ISO_ANALOG_IPS;
4321 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
4322
4323 /* disable SW LPS 0x04[10]= 0 */
4324 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4325 val8 &= ~BIT(2);
4326 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4327
4328 /* wait till 0x04[17] = 1 power ready*/
4329 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4330 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4331 if (val32 & BIT(17))
4332 break;
4333
4334 udelay(10);
4335 }
4336
4337 if (!count) {
4338 ret = -EBUSY;
4339 goto exit;
4340 }
4341
4342 /* We should be able to optimize the following three entries into one */
4343
4344 /* release WLON reset 0x04[16]= 1*/
4345 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
4346 val8 |= BIT(0);
4347 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
4348
4349 /* disable HWPDN 0x04[15]= 0*/
4350 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4351 val8 &= ~BIT(7);
4352 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4353
4354 /* disable WL suspend*/
4355 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4356 val8 &= ~(BIT(3) | BIT(4));
4357 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4358
4359 /* set, then poll until 0 */
4360 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4361 val32 |= APS_FSMCO_MAC_ENABLE;
4362 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
4363
4364 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4365 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4366 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
4367 ret = 0;
4368 break;
4369 }
4370 udelay(10);
4371 }
4372
4373 if (!count) {
4374 ret = -EBUSY;
4375 goto exit;
4376 }
4377
4378 /* 0x4C[23] = 0x4E[7] = 1, switch DPDT_SEL_P output from WL BB */
4379 /*
4380 * Note: Vendor driver actually clears this bit, despite the
4381 * documentation claims it's being set!
4382 */
4383 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
4384 val8 |= LEDCFG2_DPDT_SELECT;
4385 val8 &= ~LEDCFG2_DPDT_SELECT;
4386 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
4387
4388exit:
4389 return ret;
4390}
4391
4392static int rtl8xxxu_emu_to_disabled(struct rtl8xxxu_priv *priv)
4393{
4394 u8 val8;
4395
4396 /* 0x0007[7:0] = 0x20 SOP option to disable BG/MB */
4397 rtl8xxxu_write8(priv, REG_APS_FSMCO + 3, 0x20);
4398
4399 /* 0x04[12:11] = 01 enable WL suspend */
4400 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4401 val8 &= ~BIT(4);
4402 val8 |= BIT(3);
4403 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4404
4405 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4406 val8 |= BIT(7);
4407 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4408
4409 /* 0x48[16] = 1 to enable GPIO9 as EXT wakeup */
4410 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
4411 val8 |= BIT(0);
4412 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
4413
4414 return 0;
4415}
4416
4417static int rtl8723au_power_on(struct rtl8xxxu_priv *priv)
4418{
4419 u8 val8;
4420 u16 val16;
4421 u32 val32;
4422 int ret;
4423
4424 /*
4425 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
4426 */
4427 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
4428
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004429 rtl8723a_disabled_to_emu(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004430
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004431 ret = rtl8723a_emu_to_active(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004432 if (ret)
4433 goto exit;
4434
4435 /*
4436 * 0x0004[19] = 1, reset 8051
4437 */
4438 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
4439 val8 |= BIT(3);
4440 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
4441
4442 /*
4443 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
4444 * Set CR bit10 to enable 32k calibration.
4445 */
4446 val16 = rtl8xxxu_read16(priv, REG_CR);
4447 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
4448 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
4449 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
4450 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
4451 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
4452 rtl8xxxu_write16(priv, REG_CR, val16);
4453
4454 /* For EFuse PG */
4455 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
4456 val32 &= ~(BIT(28) | BIT(29) | BIT(30));
4457 val32 |= (0x06 << 28);
4458 rtl8xxxu_write32(priv, REG_EFUSE_CTRL, val32);
4459exit:
4460 return ret;
4461}
4462
Kalle Valoc0963772015-10-25 18:24:38 +02004463#ifdef CONFIG_RTL8XXXU_UNTESTED
4464
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004465static int rtl8192cu_power_on(struct rtl8xxxu_priv *priv)
4466{
4467 u8 val8;
4468 u16 val16;
4469 u32 val32;
4470 int i;
4471
4472 for (i = 100; i; i--) {
4473 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
4474 if (val8 & APS_FSMCO_PFM_ALDN)
4475 break;
4476 }
4477
4478 if (!i) {
4479 pr_info("%s: Poll failed\n", __func__);
4480 return -ENODEV;
4481 }
4482
4483 /*
4484 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
4485 */
4486 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
4487 rtl8xxxu_write8(priv, REG_SPS0_CTRL, 0x2b);
4488 udelay(100);
4489
4490 val8 = rtl8xxxu_read8(priv, REG_LDOV12D_CTRL);
4491 if (!(val8 & LDOV12D_ENABLE)) {
4492 pr_info("%s: Enabling LDOV12D (%02x)\n", __func__, val8);
4493 val8 |= LDOV12D_ENABLE;
4494 rtl8xxxu_write8(priv, REG_LDOV12D_CTRL, val8);
4495
4496 udelay(100);
4497
4498 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
4499 val8 &= ~SYS_ISO_MD2PP;
4500 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
4501 }
4502
4503 /*
4504 * Auto enable WLAN
4505 */
4506 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
4507 val16 |= APS_FSMCO_MAC_ENABLE;
4508 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
4509
4510 for (i = 1000; i; i--) {
4511 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
4512 if (!(val16 & APS_FSMCO_MAC_ENABLE))
4513 break;
4514 }
4515 if (!i) {
4516 pr_info("%s: FSMCO_MAC_ENABLE poll failed\n", __func__);
4517 return -EBUSY;
4518 }
4519
4520 /*
4521 * Enable radio, GPIO, LED
4522 */
4523 val16 = APS_FSMCO_HW_SUSPEND | APS_FSMCO_ENABLE_POWERDOWN |
4524 APS_FSMCO_PFM_ALDN;
4525 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
4526
4527 /*
4528 * Release RF digital isolation
4529 */
4530 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
4531 val16 &= ~SYS_ISO_DIOR;
4532 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
4533
4534 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
4535 val8 &= ~APSD_CTRL_OFF;
4536 rtl8xxxu_write8(priv, REG_APSD_CTRL, val8);
4537 for (i = 200; i; i--) {
4538 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
4539 if (!(val8 & APSD_CTRL_OFF_STATUS))
4540 break;
4541 }
4542
4543 if (!i) {
4544 pr_info("%s: APSD_CTRL poll failed\n", __func__);
4545 return -EBUSY;
4546 }
4547
4548 /*
4549 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
4550 */
4551 val16 = rtl8xxxu_read16(priv, REG_CR);
4552 val16 |= CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
4553 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | CR_PROTOCOL_ENABLE |
4554 CR_SCHEDULE_ENABLE | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE;
4555 rtl8xxxu_write16(priv, REG_CR, val16);
4556
4557 /*
4558 * Workaround for 8188RU LNA power leakage problem.
4559 */
4560 if (priv->rtlchip == 0x8188c && priv->hi_pa) {
4561 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
4562 val32 &= ~BIT(1);
4563 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
4564 }
4565 return 0;
4566}
4567
Kalle Valoc0963772015-10-25 18:24:38 +02004568#endif
4569
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004570static int rtl8192eu_power_on(struct rtl8xxxu_priv *priv)
4571{
4572 u16 val16;
4573 u32 val32;
4574 int ret;
4575
4576 ret = 0;
4577
4578 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
4579 if (val32 & SYS_CFG_SPS_LDO_SEL) {
4580 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0xc3);
4581 } else {
4582 /*
4583 * Raise 1.2V voltage
4584 */
4585 val32 = rtl8xxxu_read32(priv, REG_8192E_LDOV12_CTRL);
4586 val32 &= 0xff0fffff;
4587 val32 |= 0x00500000;
4588 rtl8xxxu_write32(priv, REG_8192E_LDOV12_CTRL, val32);
4589 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0x83);
4590 }
4591
4592 rtl8192e_disabled_to_emu(priv);
4593
4594 ret = rtl8192e_emu_to_active(priv);
4595 if (ret)
4596 goto exit;
4597
4598 rtl8xxxu_write16(priv, REG_CR, 0x0000);
4599
4600 /*
4601 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
4602 * Set CR bit10 to enable 32k calibration.
4603 */
4604 val16 = rtl8xxxu_read16(priv, REG_CR);
4605 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
4606 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
4607 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
4608 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
4609 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
4610 rtl8xxxu_write16(priv, REG_CR, val16);
4611
4612exit:
4613 return ret;
4614}
4615
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004616static void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv)
4617{
4618 u8 val8;
4619 u16 val16;
4620 u32 val32;
4621
4622 /*
4623 * Workaround for 8188RU LNA power leakage problem.
4624 */
4625 if (priv->rtlchip == 0x8188c && priv->hi_pa) {
4626 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
4627 val32 |= BIT(1);
4628 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
4629 }
4630
4631 rtl8xxxu_active_to_lps(priv);
4632
4633 /* Turn off RF */
4634 rtl8xxxu_write8(priv, REG_RF_CTRL, 0x00);
4635
4636 /* Reset Firmware if running in RAM */
4637 if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
4638 rtl8xxxu_firmware_self_reset(priv);
4639
4640 /* Reset MCU */
4641 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
4642 val16 &= ~SYS_FUNC_CPU_ENABLE;
4643 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
4644
4645 /* Reset MCU ready status */
4646 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
4647
4648 rtl8xxxu_active_to_emu(priv);
4649 rtl8xxxu_emu_to_disabled(priv);
4650
4651 /* Reset MCU IO Wrapper */
4652 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
4653 val8 &= ~BIT(0);
4654 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
4655
4656 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
4657 val8 |= BIT(0);
4658 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
4659
4660 /* RSV_CTRL 0x1C[7:0] = 0x0e lock ISO/CLK/Power control register */
4661 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0e);
4662}
4663
4664static void rtl8xxxu_init_bt(struct rtl8xxxu_priv *priv)
4665{
4666 if (!priv->has_bluetooth)
4667 return;
4668}
4669
4670static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
4671{
4672 struct rtl8xxxu_priv *priv = hw->priv;
4673 struct device *dev = &priv->udev->dev;
4674 struct rtl8xxxu_rfregval *rftable;
4675 bool macpower;
4676 int ret;
4677 u8 val8;
4678 u16 val16;
4679 u32 val32;
4680
4681 /* Check if MAC is already powered on */
4682 val8 = rtl8xxxu_read8(priv, REG_CR);
4683
4684 /*
4685 * Fix 92DU-VC S3 hang with the reason is that secondary mac is not
4686 * initialized. First MAC returns 0xea, second MAC returns 0x00
4687 */
4688 if (val8 == 0xea)
4689 macpower = false;
4690 else
4691 macpower = true;
4692
4693 ret = priv->fops->power_on(priv);
4694 if (ret < 0) {
4695 dev_warn(dev, "%s: Failed power on\n", __func__);
4696 goto exit;
4697 }
4698
4699 dev_dbg(dev, "%s: macpower %i\n", __func__, macpower);
4700 if (!macpower) {
Jes Sorensen07bb46b2016-02-29 17:04:05 -05004701 if (priv->ep_tx_normal_queue)
4702 val8 = TX_PAGE_NUM_NORM_PQ;
4703 else
4704 val8 = 0;
4705
4706 rtl8xxxu_write8(priv, REG_RQPN_NPQ, val8);
4707
4708 val32 = (TX_PAGE_NUM_PUBQ << RQPN_NORM_PQ_SHIFT) | RQPN_LOAD;
4709
4710 if (priv->ep_tx_high_queue)
4711 val32 |= (TX_PAGE_NUM_HI_PQ << RQPN_HI_PQ_SHIFT);
4712 if (priv->ep_tx_low_queue)
4713 val32 |= (TX_PAGE_NUM_LO_PQ << RQPN_LO_PQ_SHIFT);
4714
4715 rtl8xxxu_write32(priv, REG_RQPN, val32);
4716
4717 /*
4718 * Set TX buffer boundary
4719 */
4720 val8 = TX_TOTAL_PAGE_NUM + 1;
4721 rtl8xxxu_write8(priv, REG_TXPKTBUF_BCNQ_BDNY, val8);
4722 rtl8xxxu_write8(priv, REG_TXPKTBUF_MGQ_BDNY, val8);
4723 rtl8xxxu_write8(priv, REG_TXPKTBUF_WMAC_LBK_BF_HD, val8);
4724 rtl8xxxu_write8(priv, REG_TRXFF_BNDY, val8);
4725 rtl8xxxu_write8(priv, REG_TDECTRL + 1, val8);
4726 }
4727
Jes Sorensena47b9d42016-02-29 17:04:06 -05004728 ret = rtl8xxxu_download_firmware(priv);
4729 dev_dbg(dev, "%s: download_fiwmare %i\n", __func__, ret);
4730 if (ret)
4731 goto exit;
4732 ret = rtl8xxxu_start_firmware(priv);
4733 dev_dbg(dev, "%s: start_fiwmare %i\n", __func__, ret);
4734 if (ret)
4735 goto exit;
4736
Jes Sorensen07bb46b2016-02-29 17:04:05 -05004737 ret = rtl8xxxu_init_queue_priority(priv);
4738 dev_dbg(dev, "%s: init_queue_priority %i\n", __func__, ret);
4739 if (ret)
4740 goto exit;
4741
4742 dev_dbg(dev, "%s: macpower %i\n", __func__, macpower);
4743 if (!macpower) {
Jes Sorensen74b99be2016-02-29 17:04:04 -05004744 ret = priv->fops->llt_init(priv, TX_TOTAL_PAGE_NUM);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004745 if (ret) {
4746 dev_warn(dev, "%s: LLT table init failed\n", __func__);
4747 goto exit;
4748 }
4749 }
4750
Jes Sorensen6431ea02016-02-29 17:04:21 -05004751 /* Fix USB interface interference issue */
4752 if (priv->rtlchip == 0x8723a) {
4753 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
4754 rtl8xxxu_write8(priv, 0xfe41, 0x8d);
4755 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4756 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320);
4757 } else {
Jes Sorensenb63d0aa2016-02-29 17:04:08 -05004758 val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK);
4759 val32 |= TXDMA_OFFSET_DROP_DATA_EN;
4760 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32);
Jes Sorensen6431ea02016-02-29 17:04:21 -05004761 }
Jes Sorensen99ad16c2016-02-29 17:04:09 -05004762
Jes Sorensen6431ea02016-02-29 17:04:21 -05004763 /* Solve too many protocol error on USB bus */
4764 /* Can't do this for 8188/8192 UMC A cut parts */
4765 if (priv->rtlchip == 0x8723a ||
4766 ((priv->rtlchip == 0x8192c || priv->rtlchip == 0x8191c ||
4767 priv->rtlchip == 0x8188c) &&
4768 (priv->chip_cut || !priv->vendor_umc))) {
4769 rtl8xxxu_write8(priv, 0xfe40, 0xe6);
4770 rtl8xxxu_write8(priv, 0xfe41, 0x94);
4771 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4772
4773 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
4774 rtl8xxxu_write8(priv, 0xfe41, 0x19);
4775 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4776
4777 rtl8xxxu_write8(priv, 0xfe40, 0xe5);
4778 rtl8xxxu_write8(priv, 0xfe41, 0x91);
4779 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4780
4781 rtl8xxxu_write8(priv, 0xfe40, 0xe2);
4782 rtl8xxxu_write8(priv, 0xfe41, 0x81);
4783 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4784 }
4785
4786 if (priv->rtlchip == 0x8192e || priv->rtlchip == 0x8723b) {
Jes Sorensen99ad16c2016-02-29 17:04:09 -05004787 rtl8xxxu_write32(priv, REG_HIMR0, 0x00);
4788 rtl8xxxu_write32(priv, REG_HIMR1, 0x00);
Jes Sorensenb63d0aa2016-02-29 17:04:08 -05004789 }
4790
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05004791 if (priv->fops->phy_init_antenna_selection)
4792 priv->fops->phy_init_antenna_selection(priv);
4793
Jes Sorensenb7dd8ff2016-02-29 17:04:17 -05004794 if (priv->rtlchip == 0x8723b)
4795 ret = rtl8xxxu_init_mac(priv, rtl8723b_mac_init_table);
4796 else
4797 ret = rtl8xxxu_init_mac(priv, rtl8723a_mac_init_table);
4798
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004799 dev_dbg(dev, "%s: init_mac %i\n", __func__, ret);
4800 if (ret)
4801 goto exit;
4802
4803 ret = rtl8xxxu_init_phy_bb(priv);
4804 dev_dbg(dev, "%s: init_phy_bb %i\n", __func__, ret);
4805 if (ret)
4806 goto exit;
4807
4808 switch(priv->rtlchip) {
4809 case 0x8723a:
4810 rftable = rtl8723au_radioa_1t_init_table;
4811 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4812 break;
Jes Sorensen22a31d42016-02-29 17:04:15 -05004813 case 0x8723b:
4814 rftable = rtl8723bu_radioa_1t_init_table;
4815 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4816 break;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004817 case 0x8188c:
4818 if (priv->hi_pa)
4819 rftable = rtl8188ru_radioa_1t_highpa_table;
4820 else
4821 rftable = rtl8192cu_radioa_1t_init_table;
4822 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4823 break;
4824 case 0x8191c:
4825 rftable = rtl8192cu_radioa_1t_init_table;
4826 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4827 break;
4828 case 0x8192c:
4829 rftable = rtl8192cu_radioa_2t_init_table;
4830 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4831 if (ret)
4832 break;
4833 rftable = rtl8192cu_radiob_2t_init_table;
4834 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B);
4835 break;
4836 default:
4837 ret = -EINVAL;
4838 }
4839
4840 if (ret)
4841 goto exit;
4842
4843 /* Reduce 80M spur */
4844 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d);
4845 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
4846 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82);
4847 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
4848
4849 /* RFSW Control - clear bit 14 ?? */
4850 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, 0x00000003);
4851 /* 0x07000760 */
4852 val32 = FPGA0_RF_TRSW | FPGA0_RF_TRSWB | FPGA0_RF_ANTSW |
4853 FPGA0_RF_ANTSWB | FPGA0_RF_PAPE |
4854 ((FPGA0_RF_ANTSW | FPGA0_RF_ANTSWB | FPGA0_RF_PAPE) <<
4855 FPGA0_RF_BD_CTRL_SHIFT);
4856 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
4857 /* 0x860[6:5]= 00 - why? - this sets antenna B */
4858 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, 0x66F60210);
4859
4860 priv->rf_mode_ag[0] = rtl8xxxu_read_rfreg(priv, RF_A,
4861 RF6052_REG_MODE_AG);
4862
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004863 /*
4864 * Set RX page boundary
4865 */
4866 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x27ff);
4867 /*
4868 * Transfer page size is always 128
4869 */
4870 val8 = (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_RX_SHIFT) |
4871 (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_TX_SHIFT);
4872 rtl8xxxu_write8(priv, REG_PBP, val8);
4873
4874 /*
4875 * Unit in 8 bytes, not obvious what it is used for
4876 */
4877 rtl8xxxu_write8(priv, REG_RX_DRVINFO_SZ, 4);
4878
4879 /*
4880 * Enable all interrupts - not obvious USB needs to do this
4881 */
4882 rtl8xxxu_write32(priv, REG_HISR, 0xffffffff);
4883 rtl8xxxu_write32(priv, REG_HIMR, 0xffffffff);
4884
4885 rtl8xxxu_set_mac(priv);
4886 rtl8xxxu_set_linktype(priv, NL80211_IFTYPE_STATION);
4887
4888 /*
4889 * Configure initial WMAC settings
4890 */
4891 val32 = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_MCAST | RCR_ACCEPT_BCAST |
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004892 RCR_ACCEPT_MGMT_FRAME | RCR_HTC_LOC_CTRL |
4893 RCR_APPEND_PHYSTAT | RCR_APPEND_ICV | RCR_APPEND_MIC;
4894 rtl8xxxu_write32(priv, REG_RCR, val32);
4895
4896 /*
4897 * Accept all multicast
4898 */
4899 rtl8xxxu_write32(priv, REG_MAR, 0xffffffff);
4900 rtl8xxxu_write32(priv, REG_MAR + 4, 0xffffffff);
4901
4902 /*
4903 * Init adaptive controls
4904 */
4905 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
4906 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
4907 val32 |= RESPONSE_RATE_RRSR_CCK_ONLY_1M;
4908 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
4909
4910 /* CCK = 0x0a, OFDM = 0x10 */
4911 rtl8xxxu_set_spec_sifs(priv, 0x10, 0x10);
4912 rtl8xxxu_set_retry(priv, 0x30, 0x30);
4913 rtl8xxxu_set_spec_sifs(priv, 0x0a, 0x10);
4914
4915 /*
4916 * Init EDCA
4917 */
4918 rtl8xxxu_write16(priv, REG_MAC_SPEC_SIFS, 0x100a);
4919
4920 /* Set CCK SIFS */
4921 rtl8xxxu_write16(priv, REG_SIFS_CCK, 0x100a);
4922
4923 /* Set OFDM SIFS */
4924 rtl8xxxu_write16(priv, REG_SIFS_OFDM, 0x100a);
4925
4926 /* TXOP */
4927 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, 0x005ea42b);
4928 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, 0x0000a44f);
4929 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, 0x005ea324);
4930 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, 0x002fa226);
4931
4932 /* Set data auto rate fallback retry count */
4933 rtl8xxxu_write32(priv, REG_DARFRC, 0x00000000);
4934 rtl8xxxu_write32(priv, REG_DARFRC + 4, 0x10080404);
4935 rtl8xxxu_write32(priv, REG_RARFRC, 0x04030201);
4936 rtl8xxxu_write32(priv, REG_RARFRC + 4, 0x08070605);
4937
4938 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL);
4939 val8 |= FWHW_TXQ_CTRL_AMPDU_RETRY;
4940 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, val8);
4941
4942 /* Set ACK timeout */
4943 rtl8xxxu_write8(priv, REG_ACKTO, 0x40);
4944
4945 /*
4946 * Initialize beacon parameters
4947 */
4948 val16 = BEACON_DISABLE_TSF_UPDATE | (BEACON_DISABLE_TSF_UPDATE << 8);
4949 rtl8xxxu_write16(priv, REG_BEACON_CTRL, val16);
4950 rtl8xxxu_write16(priv, REG_TBTT_PROHIBIT, 0x6404);
4951 rtl8xxxu_write8(priv, REG_DRIVER_EARLY_INT, DRIVER_EARLY_INT_TIME);
4952 rtl8xxxu_write8(priv, REG_BEACON_DMA_TIME, BEACON_DMA_ATIME_INT_TIME);
4953 rtl8xxxu_write16(priv, REG_BEACON_TCFG, 0x660F);
4954
4955 /*
4956 * Enable CCK and OFDM block
4957 */
4958 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
4959 val32 |= (FPGA_RF_MODE_CCK | FPGA_RF_MODE_OFDM);
4960 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
4961
4962 /*
4963 * Invalidate all CAM entries - bit 30 is undocumented
4964 */
4965 rtl8xxxu_write32(priv, REG_CAM_CMD, CAM_CMD_POLLING | BIT(30));
4966
4967 /*
4968 * Start out with default power levels for channel 6, 20MHz
4969 */
4970 rtl8723a_set_tx_power(priv, 1, false);
4971
4972 /* Let the 8051 take control of antenna setting */
4973 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
4974 val8 |= LEDCFG2_DPDT_SELECT;
4975 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
4976
4977 rtl8xxxu_write8(priv, REG_HWSEQ_CTRL, 0xff);
4978
4979 /* Disable BAR - not sure if this has any effect on USB */
4980 rtl8xxxu_write32(priv, REG_BAR_MODE_CTRL, 0x0201ffff);
4981
4982 rtl8xxxu_write16(priv, REG_FAST_EDCA_CTRL, 0);
4983
Jes Sorensene5c447c2016-02-03 13:39:48 -05004984 rtl8723a_phy_iq_calibrate(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004985
4986 /*
4987 * This should enable thermal meter
4988 */
4989 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_T_METER, 0x60);
4990
4991 rtl8723a_phy_lc_calibrate(priv);
4992
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004993 /* Init BT hw config. */
4994 rtl8xxxu_init_bt(priv);
4995
4996 /*
4997 * Not sure if we really need to save these parameters, but the
4998 * vendor driver does
4999 */
5000 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2);
5001 if (val32 & FPGA0_HSSI_PARM2_CCK_HIGH_PWR)
5002 priv->path_a_hi_power = 1;
5003
5004 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
5005 priv->path_a_rf_paths = val32 & OFDM_RF_PATH_RX_MASK;
5006
5007 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1);
5008 priv->path_a_ig_value = val32 & OFDM0_X_AGC_CORE1_IGI_MASK;
5009
5010 /* Set NAV_UPPER to 30000us */
5011 val8 = ((30000 + NAV_UPPER_UNIT - 1) / NAV_UPPER_UNIT);
5012 rtl8xxxu_write8(priv, REG_NAV_UPPER, val8);
5013
Jes Sorensen4042e612016-02-03 13:40:01 -05005014 if (priv->rtlchip == 0x8723a) {
5015 /*
5016 * 2011/03/09 MH debug only, UMC-B cut pass 2500 S5 test,
5017 * but we need to find root cause.
5018 * This is 8723au only.
5019 */
5020 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
5021 if ((val32 & 0xff000000) != 0x83000000) {
5022 val32 |= FPGA_RF_MODE_CCK;
5023 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
5024 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005025 }
5026
5027 val32 = rtl8xxxu_read32(priv, REG_FWHW_TXQ_CTRL);
5028 val32 |= FWHW_TXQ_CTRL_XMIT_MGMT_ACK;
5029 /* ack for xmit mgmt frames. */
5030 rtl8xxxu_write32(priv, REG_FWHW_TXQ_CTRL, val32);
5031
5032exit:
5033 return ret;
5034}
5035
5036static void rtl8xxxu_disable_device(struct ieee80211_hw *hw)
5037{
5038 struct rtl8xxxu_priv *priv = hw->priv;
5039
5040 rtl8xxxu_power_off(priv);
5041}
5042
5043static void rtl8xxxu_cam_write(struct rtl8xxxu_priv *priv,
5044 struct ieee80211_key_conf *key, const u8 *mac)
5045{
5046 u32 cmd, val32, addr, ctrl;
5047 int j, i, tmp_debug;
5048
5049 tmp_debug = rtl8xxxu_debug;
5050 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_KEY)
5051 rtl8xxxu_debug |= RTL8XXXU_DEBUG_REG_WRITE;
5052
5053 /*
5054 * This is a bit of a hack - the lower bits of the cipher
5055 * suite selector happens to match the cipher index in the CAM
5056 */
5057 addr = key->keyidx << CAM_CMD_KEY_SHIFT;
5058 ctrl = (key->cipher & 0x0f) << 2 | key->keyidx | CAM_WRITE_VALID;
5059
5060 for (j = 5; j >= 0; j--) {
5061 switch (j) {
5062 case 0:
5063 val32 = ctrl | (mac[0] << 16) | (mac[1] << 24);
5064 break;
5065 case 1:
5066 val32 = mac[2] | (mac[3] << 8) |
5067 (mac[4] << 16) | (mac[5] << 24);
5068 break;
5069 default:
5070 i = (j - 2) << 2;
5071 val32 = key->key[i] | (key->key[i + 1] << 8) |
5072 key->key[i + 2] << 16 | key->key[i + 3] << 24;
5073 break;
5074 }
5075
5076 rtl8xxxu_write32(priv, REG_CAM_WRITE, val32);
5077 cmd = CAM_CMD_POLLING | CAM_CMD_WRITE | (addr + j);
5078 rtl8xxxu_write32(priv, REG_CAM_CMD, cmd);
5079 udelay(100);
5080 }
5081
5082 rtl8xxxu_debug = tmp_debug;
5083}
5084
5085static void rtl8xxxu_sw_scan_start(struct ieee80211_hw *hw,
Jes Sorensen56e43742016-02-03 13:39:50 -05005086 struct ieee80211_vif *vif, const u8 *mac)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005087{
5088 struct rtl8xxxu_priv *priv = hw->priv;
5089 u8 val8;
5090
5091 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
5092 val8 |= BEACON_DISABLE_TSF_UPDATE;
5093 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
5094}
5095
5096static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw,
5097 struct ieee80211_vif *vif)
5098{
5099 struct rtl8xxxu_priv *priv = hw->priv;
5100 u8 val8;
5101
5102 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
5103 val8 &= ~BEACON_DISABLE_TSF_UPDATE;
5104 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
5105}
5106
5107static void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
5108 u32 ramask, int sgi)
5109{
5110 struct h2c_cmd h2c;
5111
5112 h2c.ramask.cmd = H2C_SET_RATE_MASK;
5113 h2c.ramask.mask_lo = cpu_to_le16(ramask & 0xffff);
5114 h2c.ramask.mask_hi = cpu_to_le16(ramask >> 16);
5115
5116 h2c.ramask.arg = 0x80;
5117 if (sgi)
5118 h2c.ramask.arg |= 0x20;
5119
5120 dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x\n", __func__,
5121 ramask, h2c.ramask.arg);
5122 rtl8723a_h2c_cmd(priv, &h2c);
5123}
5124
5125static void rtl8xxxu_set_basic_rates(struct rtl8xxxu_priv *priv, u32 rate_cfg)
5126{
5127 u32 val32;
5128 u8 rate_idx = 0;
5129
5130 rate_cfg &= RESPONSE_RATE_BITMAP_ALL;
5131
5132 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
5133 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
5134 val32 |= rate_cfg;
5135 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
5136
5137 dev_dbg(&priv->udev->dev, "%s: rates %08x\n", __func__, rate_cfg);
5138
5139 while (rate_cfg) {
5140 rate_cfg = (rate_cfg >> 1);
5141 rate_idx++;
5142 }
5143 rtl8xxxu_write8(priv, REG_INIRTS_RATE_SEL, rate_idx);
5144}
5145
5146static void
5147rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5148 struct ieee80211_bss_conf *bss_conf, u32 changed)
5149{
5150 struct rtl8xxxu_priv *priv = hw->priv;
5151 struct device *dev = &priv->udev->dev;
5152 struct ieee80211_sta *sta;
5153 u32 val32;
5154 u8 val8;
5155
5156 if (changed & BSS_CHANGED_ASSOC) {
5157 struct h2c_cmd h2c;
5158
5159 dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc);
5160
5161 memset(&h2c, 0, sizeof(struct h2c_cmd));
5162 rtl8xxxu_set_linktype(priv, vif->type);
5163
5164 if (bss_conf->assoc) {
5165 u32 ramask;
5166 int sgi = 0;
5167
5168 rcu_read_lock();
5169 sta = ieee80211_find_sta(vif, bss_conf->bssid);
5170 if (!sta) {
5171 dev_info(dev, "%s: ASSOC no sta found\n",
5172 __func__);
5173 rcu_read_unlock();
5174 goto error;
5175 }
5176
5177 if (sta->ht_cap.ht_supported)
5178 dev_info(dev, "%s: HT supported\n", __func__);
5179 if (sta->vht_cap.vht_supported)
5180 dev_info(dev, "%s: VHT supported\n", __func__);
5181
5182 /* TODO: Set bits 28-31 for rate adaptive id */
5183 ramask = (sta->supp_rates[0] & 0xfff) |
5184 sta->ht_cap.mcs.rx_mask[0] << 12 |
5185 sta->ht_cap.mcs.rx_mask[1] << 20;
5186 if (sta->ht_cap.cap &
5187 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))
5188 sgi = 1;
5189 rcu_read_unlock();
5190
5191 rtl8xxxu_update_rate_mask(priv, ramask, sgi);
5192
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005193 rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
5194
5195 rtl8723a_stop_tx_beacon(priv);
5196
5197 /* joinbss sequence */
5198 rtl8xxxu_write16(priv, REG_BCN_PSR_RPT,
5199 0xc000 | bss_conf->aid);
5200
5201 h2c.joinbss.data = H2C_JOIN_BSS_CONNECT;
5202 } else {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005203 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
5204 val8 |= BEACON_DISABLE_TSF_UPDATE;
5205 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
5206
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005207 h2c.joinbss.data = H2C_JOIN_BSS_DISCONNECT;
5208 }
5209 h2c.joinbss.cmd = H2C_JOIN_BSS_REPORT;
5210 rtl8723a_h2c_cmd(priv, &h2c);
5211 }
5212
5213 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5214 dev_dbg(dev, "Changed ERP_PREAMBLE: Use short preamble %i\n",
5215 bss_conf->use_short_preamble);
5216 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
5217 if (bss_conf->use_short_preamble)
5218 val32 |= RSR_ACK_SHORT_PREAMBLE;
5219 else
5220 val32 &= ~RSR_ACK_SHORT_PREAMBLE;
5221 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
5222 }
5223
5224 if (changed & BSS_CHANGED_ERP_SLOT) {
5225 dev_dbg(dev, "Changed ERP_SLOT: short_slot_time %i\n",
5226 bss_conf->use_short_slot);
5227
5228 if (bss_conf->use_short_slot)
5229 val8 = 9;
5230 else
5231 val8 = 20;
5232 rtl8xxxu_write8(priv, REG_SLOT, val8);
5233 }
5234
5235 if (changed & BSS_CHANGED_BSSID) {
5236 dev_dbg(dev, "Changed BSSID!\n");
5237 rtl8xxxu_set_bssid(priv, bss_conf->bssid);
5238 }
5239
5240 if (changed & BSS_CHANGED_BASIC_RATES) {
5241 dev_dbg(dev, "Changed BASIC_RATES!\n");
5242 rtl8xxxu_set_basic_rates(priv, bss_conf->basic_rates);
5243 }
5244error:
5245 return;
5246}
5247
5248static u32 rtl8xxxu_80211_to_rtl_queue(u32 queue)
5249{
5250 u32 rtlqueue;
5251
5252 switch (queue) {
5253 case IEEE80211_AC_VO:
5254 rtlqueue = TXDESC_QUEUE_VO;
5255 break;
5256 case IEEE80211_AC_VI:
5257 rtlqueue = TXDESC_QUEUE_VI;
5258 break;
5259 case IEEE80211_AC_BE:
5260 rtlqueue = TXDESC_QUEUE_BE;
5261 break;
5262 case IEEE80211_AC_BK:
5263 rtlqueue = TXDESC_QUEUE_BK;
5264 break;
5265 default:
5266 rtlqueue = TXDESC_QUEUE_BE;
5267 }
5268
5269 return rtlqueue;
5270}
5271
5272static u32 rtl8xxxu_queue_select(struct ieee80211_hw *hw, struct sk_buff *skb)
5273{
5274 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5275 u32 queue;
5276
5277 if (ieee80211_is_mgmt(hdr->frame_control))
5278 queue = TXDESC_QUEUE_MGNT;
5279 else
5280 queue = rtl8xxxu_80211_to_rtl_queue(skb_get_queue_mapping(skb));
5281
5282 return queue;
5283}
5284
5285static void rtl8xxxu_calc_tx_desc_csum(struct rtl8xxxu_tx_desc *tx_desc)
5286{
5287 __le16 *ptr = (__le16 *)tx_desc;
5288 u16 csum = 0;
5289 int i;
5290
5291 /*
5292 * Clear csum field before calculation, as the csum field is
5293 * in the middle of the struct.
5294 */
5295 tx_desc->csum = cpu_to_le16(0);
5296
5297 for (i = 0; i < (sizeof(struct rtl8xxxu_tx_desc) / sizeof(u16)); i++)
5298 csum = csum ^ le16_to_cpu(ptr[i]);
5299
5300 tx_desc->csum |= cpu_to_le16(csum);
5301}
5302
5303static void rtl8xxxu_free_tx_resources(struct rtl8xxxu_priv *priv)
5304{
5305 struct rtl8xxxu_tx_urb *tx_urb, *tmp;
5306 unsigned long flags;
5307
5308 spin_lock_irqsave(&priv->tx_urb_lock, flags);
5309 list_for_each_entry_safe(tx_urb, tmp, &priv->tx_urb_free_list, list) {
5310 list_del(&tx_urb->list);
5311 priv->tx_urb_free_count--;
5312 usb_free_urb(&tx_urb->urb);
5313 }
5314 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
5315}
5316
5317static struct rtl8xxxu_tx_urb *
5318rtl8xxxu_alloc_tx_urb(struct rtl8xxxu_priv *priv)
5319{
5320 struct rtl8xxxu_tx_urb *tx_urb;
5321 unsigned long flags;
5322
5323 spin_lock_irqsave(&priv->tx_urb_lock, flags);
5324 tx_urb = list_first_entry_or_null(&priv->tx_urb_free_list,
5325 struct rtl8xxxu_tx_urb, list);
5326 if (tx_urb) {
5327 list_del(&tx_urb->list);
5328 priv->tx_urb_free_count--;
5329 if (priv->tx_urb_free_count < RTL8XXXU_TX_URB_LOW_WATER &&
5330 !priv->tx_stopped) {
5331 priv->tx_stopped = true;
5332 ieee80211_stop_queues(priv->hw);
5333 }
5334 }
5335
5336 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
5337
5338 return tx_urb;
5339}
5340
5341static void rtl8xxxu_free_tx_urb(struct rtl8xxxu_priv *priv,
5342 struct rtl8xxxu_tx_urb *tx_urb)
5343{
5344 unsigned long flags;
5345
5346 INIT_LIST_HEAD(&tx_urb->list);
5347
5348 spin_lock_irqsave(&priv->tx_urb_lock, flags);
5349
5350 list_add(&tx_urb->list, &priv->tx_urb_free_list);
5351 priv->tx_urb_free_count++;
5352 if (priv->tx_urb_free_count > RTL8XXXU_TX_URB_HIGH_WATER &&
5353 priv->tx_stopped) {
5354 priv->tx_stopped = false;
5355 ieee80211_wake_queues(priv->hw);
5356 }
5357
5358 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
5359}
5360
5361static void rtl8xxxu_tx_complete(struct urb *urb)
5362{
5363 struct sk_buff *skb = (struct sk_buff *)urb->context;
5364 struct ieee80211_tx_info *tx_info;
5365 struct ieee80211_hw *hw;
5366 struct rtl8xxxu_tx_urb *tx_urb =
5367 container_of(urb, struct rtl8xxxu_tx_urb, urb);
5368
5369 tx_info = IEEE80211_SKB_CB(skb);
5370 hw = tx_info->rate_driver_data[0];
5371
5372 skb_pull(skb, sizeof(struct rtl8xxxu_tx_desc));
5373
5374 ieee80211_tx_info_clear_status(tx_info);
5375 tx_info->status.rates[0].idx = -1;
5376 tx_info->status.rates[0].count = 0;
5377
5378 if (!urb->status)
5379 tx_info->flags |= IEEE80211_TX_STAT_ACK;
5380
5381 ieee80211_tx_status_irqsafe(hw, skb);
5382
5383 rtl8xxxu_free_tx_urb(hw->priv, tx_urb);
5384}
5385
5386static void rtl8xxxu_dump_action(struct device *dev,
5387 struct ieee80211_hdr *hdr)
5388{
5389 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
5390 u16 cap, timeout;
5391
5392 if (!(rtl8xxxu_debug & RTL8XXXU_DEBUG_ACTION))
5393 return;
5394
5395 switch (mgmt->u.action.u.addba_resp.action_code) {
5396 case WLAN_ACTION_ADDBA_RESP:
5397 cap = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
5398 timeout = le16_to_cpu(mgmt->u.action.u.addba_resp.timeout);
5399 dev_info(dev, "WLAN_ACTION_ADDBA_RESP: "
5400 "timeout %i, tid %02x, buf_size %02x, policy %02x, "
5401 "status %02x\n",
5402 timeout,
5403 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
5404 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
5405 (cap >> 1) & 0x1,
5406 le16_to_cpu(mgmt->u.action.u.addba_resp.status));
5407 break;
5408 case WLAN_ACTION_ADDBA_REQ:
5409 cap = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
5410 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
5411 dev_info(dev, "WLAN_ACTION_ADDBA_REQ: "
5412 "timeout %i, tid %02x, buf_size %02x, policy %02x\n",
5413 timeout,
5414 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
5415 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
5416 (cap >> 1) & 0x1);
5417 break;
5418 default:
5419 dev_info(dev, "action frame %02x\n",
5420 mgmt->u.action.u.addba_resp.action_code);
5421 break;
5422 }
5423}
5424
5425static void rtl8xxxu_tx(struct ieee80211_hw *hw,
5426 struct ieee80211_tx_control *control,
5427 struct sk_buff *skb)
5428{
5429 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5430 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
5431 struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
5432 struct rtl8xxxu_priv *priv = hw->priv;
5433 struct rtl8xxxu_tx_desc *tx_desc;
5434 struct rtl8xxxu_tx_urb *tx_urb;
5435 struct ieee80211_sta *sta = NULL;
5436 struct ieee80211_vif *vif = tx_info->control.vif;
5437 struct device *dev = &priv->udev->dev;
5438 u32 queue, rate;
5439 u16 pktlen = skb->len;
5440 u16 seq_number;
5441 u16 rate_flag = tx_info->control.rates[0].flags;
5442 int ret;
5443
5444 if (skb_headroom(skb) < sizeof(struct rtl8xxxu_tx_desc)) {
5445 dev_warn(dev,
5446 "%s: Not enough headroom (%i) for tx descriptor\n",
5447 __func__, skb_headroom(skb));
5448 goto error;
5449 }
5450
5451 if (unlikely(skb->len > (65535 - sizeof(struct rtl8xxxu_tx_desc)))) {
5452 dev_warn(dev, "%s: Trying to send over-sized skb (%i)\n",
5453 __func__, skb->len);
5454 goto error;
5455 }
5456
5457 tx_urb = rtl8xxxu_alloc_tx_urb(priv);
5458 if (!tx_urb) {
5459 dev_warn(dev, "%s: Unable to allocate tx urb\n", __func__);
5460 goto error;
5461 }
5462
5463 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
5464 dev_info(dev, "%s: TX rate: %d (%d), pkt size %d\n",
5465 __func__, tx_rate->bitrate, tx_rate->hw_value, pktlen);
5466
5467 if (ieee80211_is_action(hdr->frame_control))
5468 rtl8xxxu_dump_action(dev, hdr);
5469
5470 tx_info->rate_driver_data[0] = hw;
5471
5472 if (control && control->sta)
5473 sta = control->sta;
5474
5475 tx_desc = (struct rtl8xxxu_tx_desc *)
5476 skb_push(skb, sizeof(struct rtl8xxxu_tx_desc));
5477
5478 memset(tx_desc, 0, sizeof(struct rtl8xxxu_tx_desc));
5479 tx_desc->pkt_size = cpu_to_le16(pktlen);
5480 tx_desc->pkt_offset = sizeof(struct rtl8xxxu_tx_desc);
5481
5482 tx_desc->txdw0 =
5483 TXDESC_OWN | TXDESC_FIRST_SEGMENT | TXDESC_LAST_SEGMENT;
5484 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
5485 is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
5486 tx_desc->txdw0 |= TXDESC_BROADMULTICAST;
5487
5488 queue = rtl8xxxu_queue_select(hw, skb);
5489 tx_desc->txdw1 = cpu_to_le32(queue << TXDESC_QUEUE_SHIFT);
5490
5491 if (tx_info->control.hw_key) {
5492 switch (tx_info->control.hw_key->cipher) {
5493 case WLAN_CIPHER_SUITE_WEP40:
5494 case WLAN_CIPHER_SUITE_WEP104:
5495 case WLAN_CIPHER_SUITE_TKIP:
5496 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_RC4);
5497 break;
5498 case WLAN_CIPHER_SUITE_CCMP:
5499 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_AES);
5500 break;
5501 default:
5502 break;
5503 }
5504 }
5505
5506 seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
5507 tx_desc->txdw3 = cpu_to_le32((u32)seq_number << TXDESC_SEQ_SHIFT);
5508
5509 if (rate_flag & IEEE80211_TX_RC_MCS)
5510 rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
5511 else
5512 rate = tx_rate->hw_value;
5513 tx_desc->txdw5 = cpu_to_le32(rate);
5514
5515 if (ieee80211_is_data(hdr->frame_control))
5516 tx_desc->txdw5 |= cpu_to_le32(0x0001ff00);
5517
5518 /* (tx_info->flags & IEEE80211_TX_CTL_AMPDU) && */
5519 if (ieee80211_is_data_qos(hdr->frame_control) && sta) {
5520 if (sta->ht_cap.ht_supported) {
5521 u32 ampdu, val32;
5522
5523 ampdu = (u32)sta->ht_cap.ampdu_density;
5524 val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT;
5525 tx_desc->txdw2 |= cpu_to_le32(val32);
5526 tx_desc->txdw1 |= cpu_to_le32(TXDESC_AGG_ENABLE);
5527 } else
5528 tx_desc->txdw1 |= cpu_to_le32(TXDESC_BK);
5529 } else
5530 tx_desc->txdw1 |= cpu_to_le32(TXDESC_BK);
5531
5532 if (ieee80211_is_data_qos(hdr->frame_control))
5533 tx_desc->txdw4 |= cpu_to_le32(TXDESC_QOS);
5534 if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ||
5535 (sta && vif && vif->bss_conf.use_short_preamble))
5536 tx_desc->txdw4 |= cpu_to_le32(TXDESC_SHORT_PREAMBLE);
5537 if (rate_flag & IEEE80211_TX_RC_SHORT_GI ||
5538 (ieee80211_is_data_qos(hdr->frame_control) &&
5539 sta && sta->ht_cap.cap &
5540 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))) {
5541 tx_desc->txdw5 |= cpu_to_le32(TXDESC_SHORT_GI);
5542 }
5543 if (ieee80211_is_mgmt(hdr->frame_control)) {
5544 tx_desc->txdw5 = cpu_to_le32(tx_rate->hw_value);
5545 tx_desc->txdw4 |= cpu_to_le32(TXDESC_USE_DRIVER_RATE);
5546 tx_desc->txdw5 |= cpu_to_le32(6 << TXDESC_RETRY_LIMIT_SHIFT);
5547 tx_desc->txdw5 |= cpu_to_le32(TXDESC_RETRY_LIMIT_ENABLE);
5548 }
5549
5550 if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
5551 /* Use RTS rate 24M - does the mac80211 tell us which to use? */
5552 tx_desc->txdw4 |= cpu_to_le32(DESC_RATE_24M);
5553 tx_desc->txdw4 |= cpu_to_le32(TXDESC_RTS_CTS_ENABLE);
5554 tx_desc->txdw4 |= cpu_to_le32(TXDESC_HW_RTS_ENABLE);
5555 }
5556
5557 rtl8xxxu_calc_tx_desc_csum(tx_desc);
5558
5559 usb_fill_bulk_urb(&tx_urb->urb, priv->udev, priv->pipe_out[queue],
5560 skb->data, skb->len, rtl8xxxu_tx_complete, skb);
5561
5562 usb_anchor_urb(&tx_urb->urb, &priv->tx_anchor);
5563 ret = usb_submit_urb(&tx_urb->urb, GFP_ATOMIC);
5564 if (ret) {
5565 usb_unanchor_urb(&tx_urb->urb);
5566 rtl8xxxu_free_tx_urb(priv, tx_urb);
5567 goto error;
5568 }
5569 return;
5570error:
5571 dev_kfree_skb(skb);
5572}
5573
5574static void rtl8xxxu_rx_parse_phystats(struct rtl8xxxu_priv *priv,
5575 struct ieee80211_rx_status *rx_status,
5576 struct rtl8xxxu_rx_desc *rx_desc,
5577 struct rtl8723au_phy_stats *phy_stats)
5578{
5579 if (phy_stats->sgi_en)
5580 rx_status->flag |= RX_FLAG_SHORT_GI;
5581
5582 if (rx_desc->rxmcs < DESC_RATE_6M) {
5583 /*
5584 * Handle PHY stats for CCK rates
5585 */
5586 u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;
5587
5588 switch (cck_agc_rpt & 0xc0) {
5589 case 0xc0:
5590 rx_status->signal = -46 - (cck_agc_rpt & 0x3e);
5591 break;
5592 case 0x80:
5593 rx_status->signal = -26 - (cck_agc_rpt & 0x3e);
5594 break;
5595 case 0x40:
5596 rx_status->signal = -12 - (cck_agc_rpt & 0x3e);
5597 break;
5598 case 0x00:
5599 rx_status->signal = 16 - (cck_agc_rpt & 0x3e);
5600 break;
5601 }
5602 } else {
5603 rx_status->signal =
5604 (phy_stats->cck_sig_qual_ofdm_pwdb_all >> 1) - 110;
5605 }
5606}
5607
5608static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv)
5609{
5610 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
5611 unsigned long flags;
5612
5613 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5614
5615 list_for_each_entry_safe(rx_urb, tmp,
5616 &priv->rx_urb_pending_list, list) {
5617 list_del(&rx_urb->list);
5618 priv->rx_urb_pending_count--;
5619 usb_free_urb(&rx_urb->urb);
5620 }
5621
5622 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5623}
5624
5625static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv,
5626 struct rtl8xxxu_rx_urb *rx_urb)
5627{
5628 struct sk_buff *skb;
5629 unsigned long flags;
5630 int pending = 0;
5631
5632 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5633
5634 if (!priv->shutdown) {
5635 list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list);
5636 priv->rx_urb_pending_count++;
5637 pending = priv->rx_urb_pending_count;
5638 } else {
5639 skb = (struct sk_buff *)rx_urb->urb.context;
5640 dev_kfree_skb(skb);
5641 usb_free_urb(&rx_urb->urb);
5642 }
5643
5644 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5645
5646 if (pending > RTL8XXXU_RX_URB_PENDING_WATER)
5647 schedule_work(&priv->rx_urb_wq);
5648}
5649
5650static void rtl8xxxu_rx_urb_work(struct work_struct *work)
5651{
5652 struct rtl8xxxu_priv *priv;
5653 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
5654 struct list_head local;
5655 struct sk_buff *skb;
5656 unsigned long flags;
5657 int ret;
5658
5659 priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq);
5660 INIT_LIST_HEAD(&local);
5661
5662 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5663
5664 list_splice_init(&priv->rx_urb_pending_list, &local);
5665 priv->rx_urb_pending_count = 0;
5666
5667 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5668
5669 list_for_each_entry_safe(rx_urb, tmp, &local, list) {
5670 list_del_init(&rx_urb->list);
5671 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
5672 /*
5673 * If out of memory or temporary error, put it back on the
5674 * queue and try again. Otherwise the device is dead/gone
5675 * and we should drop it.
5676 */
5677 switch (ret) {
5678 case 0:
5679 break;
5680 case -ENOMEM:
5681 case -EAGAIN:
5682 rtl8xxxu_queue_rx_urb(priv, rx_urb);
5683 break;
5684 default:
5685 pr_info("failed to requeue urb %i\n", ret);
5686 skb = (struct sk_buff *)rx_urb->urb.context;
5687 dev_kfree_skb(skb);
5688 usb_free_urb(&rx_urb->urb);
5689 }
5690 }
5691}
5692
5693static void rtl8xxxu_rx_complete(struct urb *urb)
5694{
5695 struct rtl8xxxu_rx_urb *rx_urb =
5696 container_of(urb, struct rtl8xxxu_rx_urb, urb);
5697 struct ieee80211_hw *hw = rx_urb->hw;
5698 struct rtl8xxxu_priv *priv = hw->priv;
5699 struct sk_buff *skb = (struct sk_buff *)urb->context;
5700 struct rtl8xxxu_rx_desc *rx_desc = (struct rtl8xxxu_rx_desc *)skb->data;
5701 struct rtl8723au_phy_stats *phy_stats;
5702 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005703 struct device *dev = &priv->udev->dev;
5704 __le32 *_rx_desc_le = (__le32 *)skb->data;
5705 u32 *_rx_desc = (u32 *)skb->data;
Jes Sorensena9ffa612016-02-03 13:39:59 -05005706 int drvinfo_sz, desc_shift, i;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005707
5708 for (i = 0; i < (sizeof(struct rtl8xxxu_rx_desc) / sizeof(u32)); i++)
5709 _rx_desc[i] = le32_to_cpu(_rx_desc_le[i]);
5710
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005711 drvinfo_sz = rx_desc->drvinfo_sz * 8;
5712 desc_shift = rx_desc->shift;
5713 skb_put(skb, urb->actual_length);
5714
5715 if (urb->status == 0) {
5716 skb_pull(skb, sizeof(struct rtl8xxxu_rx_desc));
5717 phy_stats = (struct rtl8723au_phy_stats *)skb->data;
5718
5719 skb_pull(skb, drvinfo_sz + desc_shift);
5720
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005721 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
5722
5723 if (rx_desc->phy_stats)
5724 rtl8xxxu_rx_parse_phystats(priv, rx_status,
5725 rx_desc, phy_stats);
5726
5727 rx_status->freq = hw->conf.chandef.chan->center_freq;
5728 rx_status->band = hw->conf.chandef.chan->band;
5729
5730 rx_status->mactime = le32_to_cpu(rx_desc->tsfl);
5731 rx_status->flag |= RX_FLAG_MACTIME_START;
5732
5733 if (!rx_desc->swdec)
5734 rx_status->flag |= RX_FLAG_DECRYPTED;
5735 if (rx_desc->crc32)
5736 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
5737 if (rx_desc->bw)
5738 rx_status->flag |= RX_FLAG_40MHZ;
5739
5740 if (rx_desc->rxht) {
5741 rx_status->flag |= RX_FLAG_HT;
5742 rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0;
5743 } else {
5744 rx_status->rate_idx = rx_desc->rxmcs;
5745 }
5746
5747 ieee80211_rx_irqsafe(hw, skb);
5748 skb = NULL;
5749 rx_urb->urb.context = NULL;
5750 rtl8xxxu_queue_rx_urb(priv, rx_urb);
5751 } else {
5752 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
5753 goto cleanup;
5754 }
5755 return;
5756
5757cleanup:
5758 usb_free_urb(urb);
5759 dev_kfree_skb(skb);
5760 return;
5761}
5762
5763static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
5764 struct rtl8xxxu_rx_urb *rx_urb)
5765{
5766 struct sk_buff *skb;
5767 int skb_size;
5768 int ret;
5769
5770 skb_size = sizeof(struct rtl8xxxu_rx_desc) + RTL_RX_BUFFER_SIZE;
5771 skb = __netdev_alloc_skb(NULL, skb_size, GFP_KERNEL);
5772 if (!skb)
5773 return -ENOMEM;
5774
5775 memset(skb->data, 0, sizeof(struct rtl8xxxu_rx_desc));
5776 usb_fill_bulk_urb(&rx_urb->urb, priv->udev, priv->pipe_in, skb->data,
5777 skb_size, rtl8xxxu_rx_complete, skb);
5778 usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor);
5779 ret = usb_submit_urb(&rx_urb->urb, GFP_ATOMIC);
5780 if (ret)
5781 usb_unanchor_urb(&rx_urb->urb);
5782 return ret;
5783}
5784
5785static void rtl8xxxu_int_complete(struct urb *urb)
5786{
5787 struct rtl8xxxu_priv *priv = (struct rtl8xxxu_priv *)urb->context;
5788 struct device *dev = &priv->udev->dev;
5789 int ret;
5790
5791 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
5792 if (urb->status == 0) {
5793 usb_anchor_urb(urb, &priv->int_anchor);
5794 ret = usb_submit_urb(urb, GFP_ATOMIC);
5795 if (ret)
5796 usb_unanchor_urb(urb);
5797 } else {
5798 dev_info(dev, "%s: Error %i\n", __func__, urb->status);
5799 }
5800}
5801
5802
5803static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw)
5804{
5805 struct rtl8xxxu_priv *priv = hw->priv;
5806 struct urb *urb;
5807 u32 val32;
5808 int ret;
5809
5810 urb = usb_alloc_urb(0, GFP_KERNEL);
5811 if (!urb)
5812 return -ENOMEM;
5813
5814 usb_fill_int_urb(urb, priv->udev, priv->pipe_interrupt,
5815 priv->int_buf, USB_INTR_CONTENT_LENGTH,
5816 rtl8xxxu_int_complete, priv, 1);
5817 usb_anchor_urb(urb, &priv->int_anchor);
5818 ret = usb_submit_urb(urb, GFP_KERNEL);
5819 if (ret) {
5820 usb_unanchor_urb(urb);
5821 goto error;
5822 }
5823
5824 val32 = rtl8xxxu_read32(priv, REG_USB_HIMR);
5825 val32 |= USB_HIMR_CPWM;
5826 rtl8xxxu_write32(priv, REG_USB_HIMR, val32);
5827
5828error:
5829 return ret;
5830}
5831
5832static int rtl8xxxu_add_interface(struct ieee80211_hw *hw,
5833 struct ieee80211_vif *vif)
5834{
5835 struct rtl8xxxu_priv *priv = hw->priv;
5836 int ret;
5837 u8 val8;
5838
5839 switch (vif->type) {
5840 case NL80211_IFTYPE_STATION:
5841 rtl8723a_stop_tx_beacon(priv);
5842
5843 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
5844 val8 |= BEACON_ATIM | BEACON_FUNCTION_ENABLE |
5845 BEACON_DISABLE_TSF_UPDATE;
5846 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
5847 ret = 0;
5848 break;
5849 default:
5850 ret = -EOPNOTSUPP;
5851 }
5852
5853 rtl8xxxu_set_linktype(priv, vif->type);
5854
5855 return ret;
5856}
5857
5858static void rtl8xxxu_remove_interface(struct ieee80211_hw *hw,
5859 struct ieee80211_vif *vif)
5860{
5861 struct rtl8xxxu_priv *priv = hw->priv;
5862
5863 dev_dbg(&priv->udev->dev, "%s\n", __func__);
5864}
5865
5866static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed)
5867{
5868 struct rtl8xxxu_priv *priv = hw->priv;
5869 struct device *dev = &priv->udev->dev;
5870 u16 val16;
5871 int ret = 0, channel;
5872 bool ht40;
5873
5874 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
5875 dev_info(dev,
5876 "%s: channel: %i (changed %08x chandef.width %02x)\n",
5877 __func__, hw->conf.chandef.chan->hw_value,
5878 changed, hw->conf.chandef.width);
5879
5880 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
5881 val16 = ((hw->conf.long_frame_max_tx_count <<
5882 RETRY_LIMIT_LONG_SHIFT) & RETRY_LIMIT_LONG_MASK) |
5883 ((hw->conf.short_frame_max_tx_count <<
5884 RETRY_LIMIT_SHORT_SHIFT) & RETRY_LIMIT_SHORT_MASK);
5885 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
5886 }
5887
5888 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
5889 switch (hw->conf.chandef.width) {
5890 case NL80211_CHAN_WIDTH_20_NOHT:
5891 case NL80211_CHAN_WIDTH_20:
5892 ht40 = false;
5893 break;
5894 case NL80211_CHAN_WIDTH_40:
5895 ht40 = true;
5896 break;
5897 default:
5898 ret = -ENOTSUPP;
5899 goto exit;
5900 }
5901
5902 channel = hw->conf.chandef.chan->hw_value;
5903
5904 rtl8723a_set_tx_power(priv, channel, ht40);
5905
5906 rtl8723au_config_channel(hw);
5907 }
5908
5909exit:
5910 return ret;
5911}
5912
5913static int rtl8xxxu_conf_tx(struct ieee80211_hw *hw,
5914 struct ieee80211_vif *vif, u16 queue,
5915 const struct ieee80211_tx_queue_params *param)
5916{
5917 struct rtl8xxxu_priv *priv = hw->priv;
5918 struct device *dev = &priv->udev->dev;
5919 u32 val32;
5920 u8 aifs, acm_ctrl, acm_bit;
5921
5922 aifs = param->aifs;
5923
5924 val32 = aifs |
5925 fls(param->cw_min) << EDCA_PARAM_ECW_MIN_SHIFT |
5926 fls(param->cw_max) << EDCA_PARAM_ECW_MAX_SHIFT |
5927 (u32)param->txop << EDCA_PARAM_TXOP_SHIFT;
5928
5929 acm_ctrl = rtl8xxxu_read8(priv, REG_ACM_HW_CTRL);
5930 dev_dbg(dev,
5931 "%s: IEEE80211 queue %02x val %08x, acm %i, acm_ctrl %02x\n",
5932 __func__, queue, val32, param->acm, acm_ctrl);
5933
5934 switch (queue) {
5935 case IEEE80211_AC_VO:
5936 acm_bit = ACM_HW_CTRL_VO;
5937 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, val32);
5938 break;
5939 case IEEE80211_AC_VI:
5940 acm_bit = ACM_HW_CTRL_VI;
5941 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, val32);
5942 break;
5943 case IEEE80211_AC_BE:
5944 acm_bit = ACM_HW_CTRL_BE;
5945 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, val32);
5946 break;
5947 case IEEE80211_AC_BK:
5948 acm_bit = ACM_HW_CTRL_BK;
5949 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, val32);
5950 break;
5951 default:
5952 acm_bit = 0;
5953 break;
5954 }
5955
5956 if (param->acm)
5957 acm_ctrl |= acm_bit;
5958 else
5959 acm_ctrl &= ~acm_bit;
5960 rtl8xxxu_write8(priv, REG_ACM_HW_CTRL, acm_ctrl);
5961
5962 return 0;
5963}
5964
5965static void rtl8xxxu_configure_filter(struct ieee80211_hw *hw,
5966 unsigned int changed_flags,
5967 unsigned int *total_flags, u64 multicast)
5968{
5969 struct rtl8xxxu_priv *priv = hw->priv;
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05005970 u32 rcr = rtl8xxxu_read32(priv, REG_RCR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005971
5972 dev_dbg(&priv->udev->dev, "%s: changed_flags %08x, total_flags %08x\n",
5973 __func__, changed_flags, *total_flags);
5974
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05005975 /*
5976 * FIF_ALLMULTI ignored as all multicast frames are accepted (REG_MAR)
5977 */
5978
5979 if (*total_flags & FIF_FCSFAIL)
5980 rcr |= RCR_ACCEPT_CRC32;
5981 else
5982 rcr &= ~RCR_ACCEPT_CRC32;
5983
5984 /*
5985 * FIF_PLCPFAIL not supported?
5986 */
5987
5988 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
5989 rcr &= ~RCR_CHECK_BSSID_BEACON;
5990 else
5991 rcr |= RCR_CHECK_BSSID_BEACON;
5992
5993 if (*total_flags & FIF_CONTROL)
5994 rcr |= RCR_ACCEPT_CTRL_FRAME;
5995 else
5996 rcr &= ~RCR_ACCEPT_CTRL_FRAME;
5997
5998 if (*total_flags & FIF_OTHER_BSS) {
5999 rcr |= RCR_ACCEPT_AP;
6000 rcr &= ~RCR_CHECK_BSSID_MATCH;
6001 } else {
6002 rcr &= ~RCR_ACCEPT_AP;
6003 rcr |= RCR_CHECK_BSSID_MATCH;
6004 }
6005
6006 if (*total_flags & FIF_PSPOLL)
6007 rcr |= RCR_ACCEPT_PM;
6008 else
6009 rcr &= ~RCR_ACCEPT_PM;
6010
6011 /*
6012 * FIF_PROBE_REQ ignored as probe requests always seem to be accepted
6013 */
6014
6015 rtl8xxxu_write32(priv, REG_RCR, rcr);
6016
Jes Sorensen755bda12016-02-03 13:39:54 -05006017 *total_flags &= (FIF_ALLMULTI | FIF_FCSFAIL | FIF_BCN_PRBRESP_PROMISC |
6018 FIF_CONTROL | FIF_OTHER_BSS | FIF_PSPOLL |
6019 FIF_PROBE_REQ);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006020}
6021
6022static int rtl8xxxu_set_rts_threshold(struct ieee80211_hw *hw, u32 rts)
6023{
6024 if (rts > 2347)
6025 return -EINVAL;
6026
6027 return 0;
6028}
6029
6030static int rtl8xxxu_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6031 struct ieee80211_vif *vif,
6032 struct ieee80211_sta *sta,
6033 struct ieee80211_key_conf *key)
6034{
6035 struct rtl8xxxu_priv *priv = hw->priv;
6036 struct device *dev = &priv->udev->dev;
6037 u8 mac_addr[ETH_ALEN];
6038 u8 val8;
6039 u16 val16;
6040 u32 val32;
6041 int retval = -EOPNOTSUPP;
6042
6043 dev_dbg(dev, "%s: cmd %02x, cipher %08x, index %i\n",
6044 __func__, cmd, key->cipher, key->keyidx);
6045
6046 if (vif->type != NL80211_IFTYPE_STATION)
6047 return -EOPNOTSUPP;
6048
6049 if (key->keyidx > 3)
6050 return -EOPNOTSUPP;
6051
6052 switch (key->cipher) {
6053 case WLAN_CIPHER_SUITE_WEP40:
6054 case WLAN_CIPHER_SUITE_WEP104:
6055
6056 break;
6057 case WLAN_CIPHER_SUITE_CCMP:
6058 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
6059 break;
6060 case WLAN_CIPHER_SUITE_TKIP:
6061 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
6062 default:
6063 return -EOPNOTSUPP;
6064 }
6065
6066 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
6067 dev_dbg(dev, "%s: pairwise key\n", __func__);
6068 ether_addr_copy(mac_addr, sta->addr);
6069 } else {
6070 dev_dbg(dev, "%s: group key\n", __func__);
6071 eth_broadcast_addr(mac_addr);
6072 }
6073
6074 val16 = rtl8xxxu_read16(priv, REG_CR);
6075 val16 |= CR_SECURITY_ENABLE;
6076 rtl8xxxu_write16(priv, REG_CR, val16);
6077
6078 val8 = SEC_CFG_TX_SEC_ENABLE | SEC_CFG_TXBC_USE_DEFKEY |
6079 SEC_CFG_RX_SEC_ENABLE | SEC_CFG_RXBC_USE_DEFKEY;
6080 val8 |= SEC_CFG_TX_USE_DEFKEY | SEC_CFG_RX_USE_DEFKEY;
6081 rtl8xxxu_write8(priv, REG_SECURITY_CFG, val8);
6082
6083 switch (cmd) {
6084 case SET_KEY:
6085 key->hw_key_idx = key->keyidx;
6086 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
6087 rtl8xxxu_cam_write(priv, key, mac_addr);
6088 retval = 0;
6089 break;
6090 case DISABLE_KEY:
6091 rtl8xxxu_write32(priv, REG_CAM_WRITE, 0x00000000);
6092 val32 = CAM_CMD_POLLING | CAM_CMD_WRITE |
6093 key->keyidx << CAM_CMD_KEY_SHIFT;
6094 rtl8xxxu_write32(priv, REG_CAM_CMD, val32);
6095 retval = 0;
6096 break;
6097 default:
6098 dev_warn(dev, "%s: Unsupported command %02x\n", __func__, cmd);
6099 }
6100
6101 return retval;
6102}
6103
6104static int
6105rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +02006106 struct ieee80211_ampdu_params *params)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006107{
6108 struct rtl8xxxu_priv *priv = hw->priv;
6109 struct device *dev = &priv->udev->dev;
6110 u8 ampdu_factor, ampdu_density;
Sara Sharon50ea05e2015-12-30 16:06:04 +02006111 struct ieee80211_sta *sta = params->sta;
6112 enum ieee80211_ampdu_mlme_action action = params->action;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006113
6114 switch (action) {
6115 case IEEE80211_AMPDU_TX_START:
6116 dev_info(dev, "%s: IEEE80211_AMPDU_TX_START\n", __func__);
6117 ampdu_factor = sta->ht_cap.ampdu_factor;
6118 ampdu_density = sta->ht_cap.ampdu_density;
6119 rtl8xxxu_set_ampdu_factor(priv, ampdu_factor);
6120 rtl8xxxu_set_ampdu_min_space(priv, ampdu_density);
6121 dev_dbg(dev,
6122 "Changed HT: ampdu_factor %02x, ampdu_density %02x\n",
6123 ampdu_factor, ampdu_density);
6124 break;
6125 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6126 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__);
6127 rtl8xxxu_set_ampdu_factor(priv, 0);
6128 rtl8xxxu_set_ampdu_min_space(priv, 0);
6129 break;
6130 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6131 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n",
6132 __func__);
6133 rtl8xxxu_set_ampdu_factor(priv, 0);
6134 rtl8xxxu_set_ampdu_min_space(priv, 0);
6135 break;
6136 case IEEE80211_AMPDU_RX_START:
6137 dev_info(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__);
6138 break;
6139 case IEEE80211_AMPDU_RX_STOP:
6140 dev_info(dev, "%s: IEEE80211_AMPDU_RX_STOP\n", __func__);
6141 break;
6142 default:
6143 break;
6144 }
6145 return 0;
6146}
6147
6148static int rtl8xxxu_start(struct ieee80211_hw *hw)
6149{
6150 struct rtl8xxxu_priv *priv = hw->priv;
6151 struct rtl8xxxu_rx_urb *rx_urb;
6152 struct rtl8xxxu_tx_urb *tx_urb;
6153 unsigned long flags;
6154 int ret, i;
6155
6156 ret = 0;
6157
6158 init_usb_anchor(&priv->rx_anchor);
6159 init_usb_anchor(&priv->tx_anchor);
6160 init_usb_anchor(&priv->int_anchor);
6161
6162 rtl8723a_enable_rf(priv);
Jes Sorensen0e28b972016-02-29 17:04:13 -05006163 if (priv->usb_interrupts) {
6164 ret = rtl8xxxu_submit_int_urb(hw);
6165 if (ret)
6166 goto exit;
6167 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006168
6169 for (i = 0; i < RTL8XXXU_TX_URBS; i++) {
6170 tx_urb = kmalloc(sizeof(struct rtl8xxxu_tx_urb), GFP_KERNEL);
6171 if (!tx_urb) {
6172 if (!i)
6173 ret = -ENOMEM;
6174
6175 goto error_out;
6176 }
6177 usb_init_urb(&tx_urb->urb);
6178 INIT_LIST_HEAD(&tx_urb->list);
6179 tx_urb->hw = hw;
6180 list_add(&tx_urb->list, &priv->tx_urb_free_list);
6181 priv->tx_urb_free_count++;
6182 }
6183
6184 priv->tx_stopped = false;
6185
6186 spin_lock_irqsave(&priv->rx_urb_lock, flags);
6187 priv->shutdown = false;
6188 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
6189
6190 for (i = 0; i < RTL8XXXU_RX_URBS; i++) {
6191 rx_urb = kmalloc(sizeof(struct rtl8xxxu_rx_urb), GFP_KERNEL);
6192 if (!rx_urb) {
6193 if (!i)
6194 ret = -ENOMEM;
6195
6196 goto error_out;
6197 }
6198 usb_init_urb(&rx_urb->urb);
6199 INIT_LIST_HEAD(&rx_urb->list);
6200 rx_urb->hw = hw;
6201
6202 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
6203 }
6204exit:
6205 /*
Bruno Randolfc85ea112016-02-03 13:39:55 -05006206 * Accept all data and mgmt frames
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006207 */
Bruno Randolfc85ea112016-02-03 13:39:55 -05006208 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0xffff);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006209 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0xffff);
6210
6211 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, 0x6954341e);
6212
6213 return ret;
6214
6215error_out:
6216 rtl8xxxu_free_tx_resources(priv);
6217 /*
6218 * Disable all data and mgmt frames
6219 */
6220 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
6221 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
6222
6223 return ret;
6224}
6225
6226static void rtl8xxxu_stop(struct ieee80211_hw *hw)
6227{
6228 struct rtl8xxxu_priv *priv = hw->priv;
6229 unsigned long flags;
6230
6231 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
6232
6233 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
6234 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
6235
6236 spin_lock_irqsave(&priv->rx_urb_lock, flags);
6237 priv->shutdown = true;
6238 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
6239
6240 usb_kill_anchored_urbs(&priv->rx_anchor);
6241 usb_kill_anchored_urbs(&priv->tx_anchor);
Jes Sorensen0e28b972016-02-29 17:04:13 -05006242 if (priv->usb_interrupts)
6243 usb_kill_anchored_urbs(&priv->int_anchor);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006244
6245 rtl8723a_disable_rf(priv);
6246
6247 /*
6248 * Disable interrupts
6249 */
Jes Sorensen0e28b972016-02-29 17:04:13 -05006250 if (priv->usb_interrupts)
6251 rtl8xxxu_write32(priv, REG_USB_HIMR, 0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006252
6253 rtl8xxxu_free_rx_resources(priv);
6254 rtl8xxxu_free_tx_resources(priv);
6255}
6256
6257static const struct ieee80211_ops rtl8xxxu_ops = {
6258 .tx = rtl8xxxu_tx,
6259 .add_interface = rtl8xxxu_add_interface,
6260 .remove_interface = rtl8xxxu_remove_interface,
6261 .config = rtl8xxxu_config,
6262 .conf_tx = rtl8xxxu_conf_tx,
6263 .bss_info_changed = rtl8xxxu_bss_info_changed,
6264 .configure_filter = rtl8xxxu_configure_filter,
6265 .set_rts_threshold = rtl8xxxu_set_rts_threshold,
6266 .start = rtl8xxxu_start,
6267 .stop = rtl8xxxu_stop,
6268 .sw_scan_start = rtl8xxxu_sw_scan_start,
6269 .sw_scan_complete = rtl8xxxu_sw_scan_complete,
6270 .set_key = rtl8xxxu_set_key,
6271 .ampdu_action = rtl8xxxu_ampdu_action,
6272};
6273
6274static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv,
6275 struct usb_interface *interface)
6276{
6277 struct usb_interface_descriptor *interface_desc;
6278 struct usb_host_interface *host_interface;
6279 struct usb_endpoint_descriptor *endpoint;
6280 struct device *dev = &priv->udev->dev;
6281 int i, j = 0, endpoints;
6282 u8 dir, xtype, num;
6283 int ret = 0;
6284
6285 host_interface = &interface->altsetting[0];
6286 interface_desc = &host_interface->desc;
6287 endpoints = interface_desc->bNumEndpoints;
6288
6289 for (i = 0; i < endpoints; i++) {
6290 endpoint = &host_interface->endpoint[i].desc;
6291
6292 dir = endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
6293 num = usb_endpoint_num(endpoint);
6294 xtype = usb_endpoint_type(endpoint);
6295 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
6296 dev_dbg(dev,
6297 "%s: endpoint: dir %02x, # %02x, type %02x\n",
6298 __func__, dir, num, xtype);
6299 if (usb_endpoint_dir_in(endpoint) &&
6300 usb_endpoint_xfer_bulk(endpoint)) {
6301 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
6302 dev_dbg(dev, "%s: in endpoint num %i\n",
6303 __func__, num);
6304
6305 if (priv->pipe_in) {
6306 dev_warn(dev,
6307 "%s: Too many IN pipes\n", __func__);
6308 ret = -EINVAL;
6309 goto exit;
6310 }
6311
6312 priv->pipe_in = usb_rcvbulkpipe(priv->udev, num);
6313 }
6314
6315 if (usb_endpoint_dir_in(endpoint) &&
6316 usb_endpoint_xfer_int(endpoint)) {
6317 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
6318 dev_dbg(dev, "%s: interrupt endpoint num %i\n",
6319 __func__, num);
6320
6321 if (priv->pipe_interrupt) {
6322 dev_warn(dev, "%s: Too many INTERRUPT pipes\n",
6323 __func__);
6324 ret = -EINVAL;
6325 goto exit;
6326 }
6327
6328 priv->pipe_interrupt = usb_rcvintpipe(priv->udev, num);
6329 }
6330
6331 if (usb_endpoint_dir_out(endpoint) &&
6332 usb_endpoint_xfer_bulk(endpoint)) {
6333 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
6334 dev_dbg(dev, "%s: out endpoint num %i\n",
6335 __func__, num);
6336 if (j >= RTL8XXXU_OUT_ENDPOINTS) {
6337 dev_warn(dev,
6338 "%s: Too many OUT pipes\n", __func__);
6339 ret = -EINVAL;
6340 goto exit;
6341 }
6342 priv->out_ep[j++] = num;
6343 }
6344 }
6345exit:
6346 priv->nr_out_eps = j;
6347 return ret;
6348}
6349
6350static int rtl8xxxu_probe(struct usb_interface *interface,
6351 const struct usb_device_id *id)
6352{
6353 struct rtl8xxxu_priv *priv;
6354 struct ieee80211_hw *hw;
6355 struct usb_device *udev;
6356 struct ieee80211_supported_band *sband;
6357 int ret = 0;
6358 int untested = 1;
6359
6360 udev = usb_get_dev(interface_to_usbdev(interface));
6361
6362 switch (id->idVendor) {
6363 case USB_VENDOR_ID_REALTEK:
6364 switch(id->idProduct) {
6365 case 0x1724:
6366 case 0x8176:
6367 case 0x8178:
6368 case 0x817f:
6369 untested = 0;
6370 break;
6371 }
6372 break;
6373 case 0x7392:
6374 if (id->idProduct == 0x7811)
6375 untested = 0;
6376 break;
6377 default:
6378 break;
6379 }
6380
6381 if (untested) {
6382 rtl8xxxu_debug = RTL8XXXU_DEBUG_EFUSE;
6383 dev_info(&udev->dev,
6384 "This Realtek USB WiFi dongle (0x%04x:0x%04x) is untested!\n",
6385 id->idVendor, id->idProduct);
6386 dev_info(&udev->dev,
6387 "Please report results to Jes.Sorensen@gmail.com\n");
6388 }
6389
6390 hw = ieee80211_alloc_hw(sizeof(struct rtl8xxxu_priv), &rtl8xxxu_ops);
6391 if (!hw) {
6392 ret = -ENOMEM;
6393 goto exit;
6394 }
6395
6396 priv = hw->priv;
6397 priv->hw = hw;
6398 priv->udev = udev;
6399 priv->fops = (struct rtl8xxxu_fileops *)id->driver_info;
6400 mutex_init(&priv->usb_buf_mutex);
6401 mutex_init(&priv->h2c_mutex);
6402 INIT_LIST_HEAD(&priv->tx_urb_free_list);
6403 spin_lock_init(&priv->tx_urb_lock);
6404 INIT_LIST_HEAD(&priv->rx_urb_pending_list);
6405 spin_lock_init(&priv->rx_urb_lock);
6406 INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work);
6407
6408 usb_set_intfdata(interface, hw);
6409
6410 ret = rtl8xxxu_parse_usb(priv, interface);
6411 if (ret)
6412 goto exit;
6413
6414 ret = rtl8xxxu_identify_chip(priv);
6415 if (ret) {
6416 dev_err(&udev->dev, "Fatal - failed to identify chip\n");
6417 goto exit;
6418 }
6419
6420 ret = rtl8xxxu_read_efuse(priv);
6421 if (ret) {
6422 dev_err(&udev->dev, "Fatal - failed to read EFuse\n");
6423 goto exit;
6424 }
6425
6426 ret = priv->fops->parse_efuse(priv);
6427 if (ret) {
6428 dev_err(&udev->dev, "Fatal - failed to parse EFuse\n");
6429 goto exit;
6430 }
6431
6432 rtl8xxxu_print_chipinfo(priv);
6433
6434 ret = priv->fops->load_firmware(priv);
6435 if (ret) {
6436 dev_err(&udev->dev, "Fatal - failed to load firmware\n");
6437 goto exit;
6438 }
6439
6440 ret = rtl8xxxu_init_device(hw);
6441
6442 hw->wiphy->max_scan_ssids = 1;
6443 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
6444 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
6445 hw->queues = 4;
6446
6447 sband = &rtl8xxxu_supported_band;
6448 sband->ht_cap.ht_supported = true;
6449 sband->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6450 sband->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
6451 sband->ht_cap.cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40;
6452 memset(&sband->ht_cap.mcs, 0, sizeof(sband->ht_cap.mcs));
6453 sband->ht_cap.mcs.rx_mask[0] = 0xff;
6454 sband->ht_cap.mcs.rx_mask[4] = 0x01;
6455 if (priv->rf_paths > 1) {
6456 sband->ht_cap.mcs.rx_mask[1] = 0xff;
6457 sband->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6458 }
6459 sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
6460 /*
6461 * Some APs will negotiate HT20_40 in a noisy environment leading
6462 * to miserable performance. Rather than defaulting to this, only
6463 * enable it if explicitly requested at module load time.
6464 */
6465 if (rtl8xxxu_ht40_2g) {
6466 dev_info(&udev->dev, "Enabling HT_20_40 on the 2.4GHz band\n");
6467 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6468 }
6469 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
6470
6471 hw->wiphy->rts_threshold = 2347;
6472
6473 SET_IEEE80211_DEV(priv->hw, &interface->dev);
6474 SET_IEEE80211_PERM_ADDR(hw, priv->mac_addr);
6475
6476 hw->extra_tx_headroom = sizeof(struct rtl8xxxu_tx_desc);
6477 ieee80211_hw_set(hw, SIGNAL_DBM);
6478 /*
6479 * The firmware handles rate control
6480 */
6481 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
6482 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
6483
6484 ret = ieee80211_register_hw(priv->hw);
6485 if (ret) {
6486 dev_err(&udev->dev, "%s: Failed to register: %i\n",
6487 __func__, ret);
6488 goto exit;
6489 }
6490
6491exit:
6492 if (ret < 0)
6493 usb_put_dev(udev);
6494 return ret;
6495}
6496
6497static void rtl8xxxu_disconnect(struct usb_interface *interface)
6498{
6499 struct rtl8xxxu_priv *priv;
6500 struct ieee80211_hw *hw;
6501
6502 hw = usb_get_intfdata(interface);
6503 priv = hw->priv;
6504
6505 rtl8xxxu_disable_device(hw);
6506 usb_set_intfdata(interface, NULL);
6507
6508 dev_info(&priv->udev->dev, "disconnecting\n");
6509
6510 ieee80211_unregister_hw(hw);
6511
6512 kfree(priv->fw_data);
6513 mutex_destroy(&priv->usb_buf_mutex);
6514 mutex_destroy(&priv->h2c_mutex);
6515
6516 usb_put_dev(priv->udev);
6517 ieee80211_free_hw(hw);
6518}
6519
6520static struct rtl8xxxu_fileops rtl8723au_fops = {
6521 .parse_efuse = rtl8723au_parse_efuse,
6522 .load_firmware = rtl8723au_load_firmware,
6523 .power_on = rtl8723au_power_on,
Jes Sorensen74b99be2016-02-29 17:04:04 -05006524 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006525 .writeN_block_size = 1024,
Jes Sorensened35d092016-02-29 17:04:19 -05006526 .mbox_ext_reg = REG_HMBOX_EXT_0,
6527 .mbox_ext_width = 2,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006528};
6529
Jes Sorensen35a741f2016-02-29 17:04:10 -05006530static struct rtl8xxxu_fileops rtl8723bu_fops = {
Jes Sorensen3c836d62016-02-29 17:04:11 -05006531 .parse_efuse = rtl8723bu_parse_efuse,
Jes Sorensen35a741f2016-02-29 17:04:10 -05006532 .load_firmware = rtl8723bu_load_firmware,
6533 .power_on = rtl8723au_power_on,
6534 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05006535 .phy_init_antenna_selection = rtl8723bu_phy_init_antenna_selection,
Jes Sorensenadfc0122016-02-29 17:04:12 -05006536 .writeN_block_size = 1024,
Jes Sorensened35d092016-02-29 17:04:19 -05006537 .mbox_ext_reg = REG_HMBOX_EXT0_8723B,
6538 .mbox_ext_width = 4,
Jes Sorensen35a741f2016-02-29 17:04:10 -05006539};
6540
Kalle Valoc0963772015-10-25 18:24:38 +02006541#ifdef CONFIG_RTL8XXXU_UNTESTED
6542
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006543static struct rtl8xxxu_fileops rtl8192cu_fops = {
6544 .parse_efuse = rtl8192cu_parse_efuse,
6545 .load_firmware = rtl8192cu_load_firmware,
6546 .power_on = rtl8192cu_power_on,
Jes Sorensen74b99be2016-02-29 17:04:04 -05006547 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006548 .writeN_block_size = 128,
Jes Sorensened35d092016-02-29 17:04:19 -05006549 .mbox_ext_reg = REG_HMBOX_EXT_0,
6550 .mbox_ext_width = 2,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006551};
6552
Kalle Valoc0963772015-10-25 18:24:38 +02006553#endif
6554
Jes Sorensen3307d842016-02-29 17:03:59 -05006555static struct rtl8xxxu_fileops rtl8192eu_fops = {
6556 .parse_efuse = rtl8192eu_parse_efuse,
6557 .load_firmware = rtl8192eu_load_firmware,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006558 .power_on = rtl8192eu_power_on,
Jes Sorensen74b99be2016-02-29 17:04:04 -05006559 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006560 .writeN_block_size = 128,
Jes Sorensened35d092016-02-29 17:04:19 -05006561 .mbox_ext_reg = REG_HMBOX_EXT0_8723B,
6562 .mbox_ext_width = 4,
Jes Sorensen3307d842016-02-29 17:03:59 -05006563};
6564
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006565static struct usb_device_id dev_table[] = {
6566{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8724, 0xff, 0xff, 0xff),
6567 .driver_info = (unsigned long)&rtl8723au_fops},
6568{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1724, 0xff, 0xff, 0xff),
6569 .driver_info = (unsigned long)&rtl8723au_fops},
6570{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x0724, 0xff, 0xff, 0xff),
6571 .driver_info = (unsigned long)&rtl8723au_fops},
Jes Sorensen3307d842016-02-29 17:03:59 -05006572{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818b, 0xff, 0xff, 0xff),
6573 .driver_info = (unsigned long)&rtl8192eu_fops},
Jes Sorensen35a741f2016-02-29 17:04:10 -05006574{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0xb720, 0xff, 0xff, 0xff),
6575 .driver_info = (unsigned long)&rtl8723bu_fops},
Kalle Valo033695b2015-10-23 20:27:58 +03006576#ifdef CONFIG_RTL8XXXU_UNTESTED
6577/* Still supported by rtlwifi */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006578{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8176, 0xff, 0xff, 0xff),
6579 .driver_info = (unsigned long)&rtl8192cu_fops},
6580{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8178, 0xff, 0xff, 0xff),
6581 .driver_info = (unsigned long)&rtl8192cu_fops},
6582{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817f, 0xff, 0xff, 0xff),
6583 .driver_info = (unsigned long)&rtl8192cu_fops},
6584/* Tested by Larry Finger */
6585{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7811, 0xff, 0xff, 0xff),
6586 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006587/* Currently untested 8188 series devices */
6588{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8191, 0xff, 0xff, 0xff),
6589 .driver_info = (unsigned long)&rtl8192cu_fops},
6590{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8170, 0xff, 0xff, 0xff),
6591 .driver_info = (unsigned long)&rtl8192cu_fops},
6592{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8177, 0xff, 0xff, 0xff),
6593 .driver_info = (unsigned long)&rtl8192cu_fops},
6594{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817a, 0xff, 0xff, 0xff),
6595 .driver_info = (unsigned long)&rtl8192cu_fops},
6596{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817b, 0xff, 0xff, 0xff),
6597 .driver_info = (unsigned long)&rtl8192cu_fops},
6598{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817d, 0xff, 0xff, 0xff),
6599 .driver_info = (unsigned long)&rtl8192cu_fops},
6600{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817e, 0xff, 0xff, 0xff),
6601 .driver_info = (unsigned long)&rtl8192cu_fops},
6602{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818a, 0xff, 0xff, 0xff),
6603 .driver_info = (unsigned long)&rtl8192cu_fops},
6604{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x317f, 0xff, 0xff, 0xff),
6605 .driver_info = (unsigned long)&rtl8192cu_fops},
6606{USB_DEVICE_AND_INTERFACE_INFO(0x1058, 0x0631, 0xff, 0xff, 0xff),
6607 .driver_info = (unsigned long)&rtl8192cu_fops},
6608{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x094c, 0xff, 0xff, 0xff),
6609 .driver_info = (unsigned long)&rtl8192cu_fops},
6610{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1102, 0xff, 0xff, 0xff),
6611 .driver_info = (unsigned long)&rtl8192cu_fops},
6612{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe033, 0xff, 0xff, 0xff),
6613 .driver_info = (unsigned long)&rtl8192cu_fops},
6614{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8189, 0xff, 0xff, 0xff),
6615 .driver_info = (unsigned long)&rtl8192cu_fops},
6616{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9041, 0xff, 0xff, 0xff),
6617 .driver_info = (unsigned long)&rtl8192cu_fops},
6618{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ba, 0xff, 0xff, 0xff),
6619 .driver_info = (unsigned long)&rtl8192cu_fops},
6620{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1e1e, 0xff, 0xff, 0xff),
6621 .driver_info = (unsigned long)&rtl8192cu_fops},
6622{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x5088, 0xff, 0xff, 0xff),
6623 .driver_info = (unsigned long)&rtl8192cu_fops},
6624{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0052, 0xff, 0xff, 0xff),
6625 .driver_info = (unsigned long)&rtl8192cu_fops},
6626{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x005c, 0xff, 0xff, 0xff),
6627 .driver_info = (unsigned long)&rtl8192cu_fops},
6628{USB_DEVICE_AND_INTERFACE_INFO(0x0eb0, 0x9071, 0xff, 0xff, 0xff),
6629 .driver_info = (unsigned long)&rtl8192cu_fops},
6630{USB_DEVICE_AND_INTERFACE_INFO(0x103c, 0x1629, 0xff, 0xff, 0xff),
6631 .driver_info = (unsigned long)&rtl8192cu_fops},
6632{USB_DEVICE_AND_INTERFACE_INFO(0x13d3, 0x3357, 0xff, 0xff, 0xff),
6633 .driver_info = (unsigned long)&rtl8192cu_fops},
6634{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3308, 0xff, 0xff, 0xff),
6635 .driver_info = (unsigned long)&rtl8192cu_fops},
6636{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330b, 0xff, 0xff, 0xff),
6637 .driver_info = (unsigned long)&rtl8192cu_fops},
6638{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x4902, 0xff, 0xff, 0xff),
6639 .driver_info = (unsigned long)&rtl8192cu_fops},
6640{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2a, 0xff, 0xff, 0xff),
6641 .driver_info = (unsigned long)&rtl8192cu_fops},
6642{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2e, 0xff, 0xff, 0xff),
6643 .driver_info = (unsigned long)&rtl8192cu_fops},
6644{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xed17, 0xff, 0xff, 0xff),
6645 .driver_info = (unsigned long)&rtl8192cu_fops},
6646{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x648b, 0xff, 0xff, 0xff),
6647 .driver_info = (unsigned long)&rtl8192cu_fops},
6648{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0090, 0xff, 0xff, 0xff),
6649 .driver_info = (unsigned long)&rtl8192cu_fops},
6650{USB_DEVICE_AND_INTERFACE_INFO(0x4856, 0x0091, 0xff, 0xff, 0xff),
6651 .driver_info = (unsigned long)&rtl8192cu_fops},
6652{USB_DEVICE_AND_INTERFACE_INFO(0xcdab, 0x8010, 0xff, 0xff, 0xff),
6653 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006654{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff7, 0xff, 0xff, 0xff),
6655 .driver_info = (unsigned long)&rtl8192cu_fops},
6656{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff9, 0xff, 0xff, 0xff),
6657 .driver_info = (unsigned long)&rtl8192cu_fops},
6658{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffa, 0xff, 0xff, 0xff),
6659 .driver_info = (unsigned long)&rtl8192cu_fops},
6660{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff8, 0xff, 0xff, 0xff),
6661 .driver_info = (unsigned long)&rtl8192cu_fops},
6662{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffb, 0xff, 0xff, 0xff),
6663 .driver_info = (unsigned long)&rtl8192cu_fops},
6664{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffc, 0xff, 0xff, 0xff),
6665 .driver_info = (unsigned long)&rtl8192cu_fops},
6666{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x1201, 0xff, 0xff, 0xff),
6667 .driver_info = (unsigned long)&rtl8192cu_fops},
6668/* Currently untested 8192 series devices */
6669{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x0950, 0xff, 0xff, 0xff),
6670 .driver_info = (unsigned long)&rtl8192cu_fops},
6671{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1004, 0xff, 0xff, 0xff),
6672 .driver_info = (unsigned long)&rtl8192cu_fops},
6673{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2102, 0xff, 0xff, 0xff),
6674 .driver_info = (unsigned long)&rtl8192cu_fops},
6675{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2103, 0xff, 0xff, 0xff),
6676 .driver_info = (unsigned long)&rtl8192cu_fops},
6677{USB_DEVICE_AND_INTERFACE_INFO(0x0586, 0x341f, 0xff, 0xff, 0xff),
6678 .driver_info = (unsigned long)&rtl8192cu_fops},
6679{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe035, 0xff, 0xff, 0xff),
6680 .driver_info = (unsigned long)&rtl8192cu_fops},
6681{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ab, 0xff, 0xff, 0xff),
6682 .driver_info = (unsigned long)&rtl8192cu_fops},
6683{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0061, 0xff, 0xff, 0xff),
6684 .driver_info = (unsigned long)&rtl8192cu_fops},
6685{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0070, 0xff, 0xff, 0xff),
6686 .driver_info = (unsigned long)&rtl8192cu_fops},
6687{USB_DEVICE_AND_INTERFACE_INFO(0x0789, 0x016d, 0xff, 0xff, 0xff),
6688 .driver_info = (unsigned long)&rtl8192cu_fops},
6689{USB_DEVICE_AND_INTERFACE_INFO(0x07aa, 0x0056, 0xff, 0xff, 0xff),
6690 .driver_info = (unsigned long)&rtl8192cu_fops},
6691{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8178, 0xff, 0xff, 0xff),
6692 .driver_info = (unsigned long)&rtl8192cu_fops},
6693{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9021, 0xff, 0xff, 0xff),
6694 .driver_info = (unsigned long)&rtl8192cu_fops},
6695{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0xf001, 0xff, 0xff, 0xff),
6696 .driver_info = (unsigned long)&rtl8192cu_fops},
6697{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x2e2e, 0xff, 0xff, 0xff),
6698 .driver_info = (unsigned long)&rtl8192cu_fops},
6699{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0019, 0xff, 0xff, 0xff),
6700 .driver_info = (unsigned long)&rtl8192cu_fops},
6701{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0020, 0xff, 0xff, 0xff),
6702 .driver_info = (unsigned long)&rtl8192cu_fops},
6703{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3307, 0xff, 0xff, 0xff),
6704 .driver_info = (unsigned long)&rtl8192cu_fops},
6705{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3309, 0xff, 0xff, 0xff),
6706 .driver_info = (unsigned long)&rtl8192cu_fops},
6707{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330a, 0xff, 0xff, 0xff),
6708 .driver_info = (unsigned long)&rtl8192cu_fops},
6709{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2b, 0xff, 0xff, 0xff),
6710 .driver_info = (unsigned long)&rtl8192cu_fops},
6711{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x624d, 0xff, 0xff, 0xff),
6712 .driver_info = (unsigned long)&rtl8192cu_fops},
6713{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0100, 0xff, 0xff, 0xff),
6714 .driver_info = (unsigned long)&rtl8192cu_fops},
6715{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0091, 0xff, 0xff, 0xff),
6716 .driver_info = (unsigned long)&rtl8192cu_fops},
6717{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7822, 0xff, 0xff, 0xff),
6718 .driver_info = (unsigned long)&rtl8192cu_fops},
6719#endif
6720{ }
6721};
6722
6723static struct usb_driver rtl8xxxu_driver = {
6724 .name = DRIVER_NAME,
6725 .probe = rtl8xxxu_probe,
6726 .disconnect = rtl8xxxu_disconnect,
6727 .id_table = dev_table,
6728 .disable_hub_initiated_lpm = 1,
6729};
6730
6731static int __init rtl8xxxu_module_init(void)
6732{
6733 int res;
6734
6735 res = usb_register(&rtl8xxxu_driver);
6736 if (res < 0)
6737 pr_err(DRIVER_NAME ": usb_register() failed (%i)\n", res);
6738
6739 return res;
6740}
6741
6742static void __exit rtl8xxxu_module_exit(void)
6743{
6744 usb_deregister(&rtl8xxxu_driver);
6745}
6746
6747
6748MODULE_DEVICE_TABLE(usb, dev_table);
6749
6750module_init(rtl8xxxu_module_init);
6751module_exit(rtl8xxxu_module_exit);