blob: 5b2c1c80e49d2edeac8573c7d8503473d17da389 [file] [log] [blame]
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001/*
2 * RTL8XXXU mac80211 USB driver
3 *
4 * Copyright (c) 2014 - 2015 Jes Sorensen <Jes.Sorensen@redhat.com>
5 *
6 * Portions, notably calibration code:
7 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
8 *
9 * This driver was written as a replacement for the vendor provided
10 * rtl8723au driver. As the Realtek 8xxx chips are very similar in
11 * their programming interface, I have started adding support for
12 * additional 8xxx chips like the 8192cu, 8188cus, etc.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of version 2 of the GNU General Public License as
16 * published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * more details.
22 */
23
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/errno.h>
28#include <linux/slab.h>
29#include <linux/module.h>
30#include <linux/spinlock.h>
31#include <linux/list.h>
32#include <linux/usb.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/ethtool.h>
36#include <linux/wireless.h>
37#include <linux/firmware.h>
38#include <linux/moduleparam.h>
39#include <net/mac80211.h>
40#include "rtl8xxxu.h"
41#include "rtl8xxxu_regs.h"
42
43#define DRIVER_NAME "rtl8xxxu"
44
Jes Sorensen3307d842016-02-29 17:03:59 -050045static int rtl8xxxu_debug = RTL8XXXU_DEBUG_EFUSE;
Jes Sorensen26f1fad2015-10-14 20:44:51 -040046static bool rtl8xxxu_ht40_2g;
47
48MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@redhat.com>");
49MODULE_DESCRIPTION("RTL8XXXu USB mac80211 Wireless LAN Driver");
50MODULE_LICENSE("GPL");
51MODULE_FIRMWARE("rtlwifi/rtl8723aufw_A.bin");
52MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B.bin");
53MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B_NoBT.bin");
54MODULE_FIRMWARE("rtlwifi/rtl8192cufw_A.bin");
55MODULE_FIRMWARE("rtlwifi/rtl8192cufw_B.bin");
56MODULE_FIRMWARE("rtlwifi/rtl8192cufw_TMSC.bin");
Jes Sorensenb001e082016-02-29 17:04:02 -050057MODULE_FIRMWARE("rtlwifi/rtl8192eu_nic.bin");
Jes Sorensen35a741f2016-02-29 17:04:10 -050058MODULE_FIRMWARE("rtlwifi/rtl8723bu_nic.bin");
59MODULE_FIRMWARE("rtlwifi/rtl8723bu_bt.bin");
Jes Sorensen26f1fad2015-10-14 20:44:51 -040060
61module_param_named(debug, rtl8xxxu_debug, int, 0600);
62MODULE_PARM_DESC(debug, "Set debug mask");
63module_param_named(ht40_2g, rtl8xxxu_ht40_2g, bool, 0600);
64MODULE_PARM_DESC(ht40_2g, "Enable HT40 support on the 2.4GHz band");
65
66#define USB_VENDOR_ID_REALTEK 0x0bda
67/* Minimum IEEE80211_MAX_FRAME_LEN */
68#define RTL_RX_BUFFER_SIZE IEEE80211_MAX_FRAME_LEN
69#define RTL8XXXU_RX_URBS 32
70#define RTL8XXXU_RX_URB_PENDING_WATER 8
71#define RTL8XXXU_TX_URBS 64
72#define RTL8XXXU_TX_URB_LOW_WATER 25
73#define RTL8XXXU_TX_URB_HIGH_WATER 32
74
75static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
76 struct rtl8xxxu_rx_urb *rx_urb);
77
78static struct ieee80211_rate rtl8xxxu_rates[] = {
79 { .bitrate = 10, .hw_value = DESC_RATE_1M, .flags = 0 },
80 { .bitrate = 20, .hw_value = DESC_RATE_2M, .flags = 0 },
81 { .bitrate = 55, .hw_value = DESC_RATE_5_5M, .flags = 0 },
82 { .bitrate = 110, .hw_value = DESC_RATE_11M, .flags = 0 },
83 { .bitrate = 60, .hw_value = DESC_RATE_6M, .flags = 0 },
84 { .bitrate = 90, .hw_value = DESC_RATE_9M, .flags = 0 },
85 { .bitrate = 120, .hw_value = DESC_RATE_12M, .flags = 0 },
86 { .bitrate = 180, .hw_value = DESC_RATE_18M, .flags = 0 },
87 { .bitrate = 240, .hw_value = DESC_RATE_24M, .flags = 0 },
88 { .bitrate = 360, .hw_value = DESC_RATE_36M, .flags = 0 },
89 { .bitrate = 480, .hw_value = DESC_RATE_48M, .flags = 0 },
90 { .bitrate = 540, .hw_value = DESC_RATE_54M, .flags = 0 },
91};
92
93static struct ieee80211_channel rtl8xxxu_channels_2g[] = {
Johannes Berg57fbcce2016-04-12 15:56:15 +020094 { .band = NL80211_BAND_2GHZ, .center_freq = 2412,
Jes Sorensen26f1fad2015-10-14 20:44:51 -040095 .hw_value = 1, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +020096 { .band = NL80211_BAND_2GHZ, .center_freq = 2417,
Jes Sorensen26f1fad2015-10-14 20:44:51 -040097 .hw_value = 2, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +020098 { .band = NL80211_BAND_2GHZ, .center_freq = 2422,
Jes Sorensen26f1fad2015-10-14 20:44:51 -040099 .hw_value = 3, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200100 { .band = NL80211_BAND_2GHZ, .center_freq = 2427,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400101 .hw_value = 4, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200102 { .band = NL80211_BAND_2GHZ, .center_freq = 2432,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400103 .hw_value = 5, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200104 { .band = NL80211_BAND_2GHZ, .center_freq = 2437,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400105 .hw_value = 6, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200106 { .band = NL80211_BAND_2GHZ, .center_freq = 2442,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400107 .hw_value = 7, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200108 { .band = NL80211_BAND_2GHZ, .center_freq = 2447,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400109 .hw_value = 8, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200110 { .band = NL80211_BAND_2GHZ, .center_freq = 2452,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400111 .hw_value = 9, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200112 { .band = NL80211_BAND_2GHZ, .center_freq = 2457,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400113 .hw_value = 10, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200114 { .band = NL80211_BAND_2GHZ, .center_freq = 2462,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400115 .hw_value = 11, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200116 { .band = NL80211_BAND_2GHZ, .center_freq = 2467,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400117 .hw_value = 12, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200118 { .band = NL80211_BAND_2GHZ, .center_freq = 2472,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400119 .hw_value = 13, .max_power = 30 },
Johannes Berg57fbcce2016-04-12 15:56:15 +0200120 { .band = NL80211_BAND_2GHZ, .center_freq = 2484,
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400121 .hw_value = 14, .max_power = 30 }
122};
123
124static struct ieee80211_supported_band rtl8xxxu_supported_band = {
125 .channels = rtl8xxxu_channels_2g,
126 .n_channels = ARRAY_SIZE(rtl8xxxu_channels_2g),
127 .bitrates = rtl8xxxu_rates,
128 .n_bitrates = ARRAY_SIZE(rtl8xxxu_rates),
129};
130
131static struct rtl8xxxu_reg8val rtl8723a_mac_init_table[] = {
132 {0x420, 0x80}, {0x423, 0x00}, {0x430, 0x00}, {0x431, 0x00},
133 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
134 {0x436, 0x06}, {0x437, 0x07}, {0x438, 0x00}, {0x439, 0x00},
135 {0x43a, 0x00}, {0x43b, 0x01}, {0x43c, 0x04}, {0x43d, 0x05},
136 {0x43e, 0x06}, {0x43f, 0x07}, {0x440, 0x5d}, {0x441, 0x01},
137 {0x442, 0x00}, {0x444, 0x15}, {0x445, 0xf0}, {0x446, 0x0f},
138 {0x447, 0x00}, {0x458, 0x41}, {0x459, 0xa8}, {0x45a, 0x72},
139 {0x45b, 0xb9}, {0x460, 0x66}, {0x461, 0x66}, {0x462, 0x08},
140 {0x463, 0x03}, {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff},
141 {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2},
142 {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3},
143 {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4},
144 {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4},
145 {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a},
146 {0x515, 0x10}, {0x516, 0x0a}, {0x517, 0x10}, {0x51a, 0x16},
147 {0x524, 0x0f}, {0x525, 0x4f}, {0x546, 0x40}, {0x547, 0x00},
148 {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55a, 0x02},
149 {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a},
150 {0x652, 0x20}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e},
151 {0x63f, 0x0e}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43},
152 {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43},
153 {0x70a, 0x65}, {0x70b, 0x87}, {0xffff, 0xff},
154};
155
Jes Sorensenb7dd8ff2016-02-29 17:04:17 -0500156static struct rtl8xxxu_reg8val rtl8723b_mac_init_table[] = {
157 {0x02f, 0x30}, {0x035, 0x00}, {0x039, 0x08}, {0x04e, 0xe0},
158 {0x064, 0x00}, {0x067, 0x20}, {0x428, 0x0a}, {0x429, 0x10},
159 {0x430, 0x00}, {0x431, 0x00},
160 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
161 {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05},
162 {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01},
163 {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00},
164 {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f},
165 {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00},
166 {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f},
167 {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66},
168 {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff},
169 {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2},
170 {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3},
171 {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4},
172 {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4},
173 {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a},
174 {0x516, 0x0a}, {0x525, 0x4f},
175 {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50},
176 {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a},
177 {0x620, 0xff}, {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff},
178 {0x624, 0xff}, {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff},
179 {0x638, 0x50}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e},
180 {0x63f, 0x0e}, {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00},
181 {0x652, 0xc8}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43},
182 {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43},
183 {0x70a, 0x65}, {0x70b, 0x87}, {0x765, 0x18}, {0x76e, 0x04},
184 {0xffff, 0xff},
185};
186
Jes Sorensenc606e662016-04-07 14:19:16 -0400187static struct rtl8xxxu_reg8val rtl8192e_mac_init_table[] = {
188 {0x011, 0xeb}, {0x012, 0x07}, {0x014, 0x75}, {0x303, 0xa7},
189 {0x428, 0x0a}, {0x429, 0x10}, {0x430, 0x00}, {0x431, 0x00},
190 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
191 {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05},
192 {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01},
193 {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00},
194 {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f},
195 {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00},
196 {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f},
197 {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66},
198 {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff}, {0x4cd, 0xff},
199 {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2}, {0x502, 0x2f},
200 {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3}, {0x506, 0x5e},
201 {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4}, {0x50a, 0x5e},
202 {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4}, {0x50e, 0x00},
203 {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a}, {0x516, 0x0a},
204 {0x525, 0x4f}, {0x540, 0x12}, {0x541, 0x64}, {0x550, 0x10},
205 {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50}, {0x55d, 0xff},
206 {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a}, {0x620, 0xff},
207 {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff}, {0x624, 0xff},
208 {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff}, {0x638, 0x50},
209 {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e}, {0x63f, 0x0e},
210 {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00}, {0x652, 0xc8},
211 {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43}, {0x702, 0x65},
212 {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43}, {0x70a, 0x65},
213 {0x70b, 0x87},
214 {0xffff, 0xff},
215};
216
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400217static struct rtl8xxxu_reg32val rtl8723a_phy_1t_init_table[] = {
218 {0x800, 0x80040000}, {0x804, 0x00000003},
219 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
220 {0x810, 0x10001331}, {0x814, 0x020c3d10},
221 {0x818, 0x02200385}, {0x81c, 0x00000000},
222 {0x820, 0x01000100}, {0x824, 0x00390004},
223 {0x828, 0x00000000}, {0x82c, 0x00000000},
224 {0x830, 0x00000000}, {0x834, 0x00000000},
225 {0x838, 0x00000000}, {0x83c, 0x00000000},
226 {0x840, 0x00010000}, {0x844, 0x00000000},
227 {0x848, 0x00000000}, {0x84c, 0x00000000},
228 {0x850, 0x00000000}, {0x854, 0x00000000},
229 {0x858, 0x569a569a}, {0x85c, 0x001b25a4},
230 {0x860, 0x66f60110}, {0x864, 0x061f0130},
231 {0x868, 0x00000000}, {0x86c, 0x32323200},
232 {0x870, 0x07000760}, {0x874, 0x22004000},
233 {0x878, 0x00000808}, {0x87c, 0x00000000},
234 {0x880, 0xc0083070}, {0x884, 0x000004d5},
235 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
236 {0x890, 0x00000800}, {0x894, 0xfffffffe},
237 {0x898, 0x40302010}, {0x89c, 0x00706050},
238 {0x900, 0x00000000}, {0x904, 0x00000023},
239 {0x908, 0x00000000}, {0x90c, 0x81121111},
240 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
241 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
242 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
243 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
244 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
245 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
246 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
247 {0xa78, 0x00000900},
248 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
249 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
250 {0xc10, 0x08800000}, {0xc14, 0x40000100},
251 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
252 {0xc20, 0x00000000}, {0xc24, 0x00000000},
253 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
254 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
255 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
256 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
257 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
258 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
259 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
260 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
261 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
262 {0xc70, 0x2c7f000d}, {0xc74, 0x018610db},
263 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
264 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
265 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
266 {0xc90, 0x00121820}, {0xc94, 0x00000000},
267 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
268 {0xca0, 0x00000000}, {0xca4, 0x00000080},
269 {0xca8, 0x00000000}, {0xcac, 0x00000000},
270 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
271 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
272 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
273 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
274 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
275 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
276 {0xce0, 0x00222222}, {0xce4, 0x00000000},
277 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
278 {0xd00, 0x00080740}, {0xd04, 0x00020401},
279 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
280 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
281 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
282 {0xd30, 0x00000000}, {0xd34, 0x80608000},
283 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
284 {0xd40, 0x00000000}, {0xd44, 0x00000000},
285 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
286 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
287 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
288 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
289 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
290 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
291 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
292 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
293 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
294 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
295 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
296 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
297 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
298 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
299 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
300 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
301 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
302 {0xe68, 0x001b25a4}, {0xe6c, 0x631b25a0},
303 {0xe70, 0x631b25a0}, {0xe74, 0x081b25a0},
304 {0xe78, 0x081b25a0}, {0xe7c, 0x081b25a0},
305 {0xe80, 0x081b25a0}, {0xe84, 0x631b25a0},
306 {0xe88, 0x081b25a0}, {0xe8c, 0x631b25a0},
307 {0xed0, 0x631b25a0}, {0xed4, 0x631b25a0},
308 {0xed8, 0x631b25a0}, {0xedc, 0x001b25a0},
309 {0xee0, 0x001b25a0}, {0xeec, 0x6b1b25a0},
310 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
311 {0xf00, 0x00000300},
312 {0xffff, 0xffffffff},
313};
314
Jes Sorensen36c32582016-02-29 17:04:14 -0500315static struct rtl8xxxu_reg32val rtl8723b_phy_1t_init_table[] = {
316 {0x800, 0x80040000}, {0x804, 0x00000003},
317 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
318 {0x810, 0x10001331}, {0x814, 0x020c3d10},
319 {0x818, 0x02200385}, {0x81c, 0x00000000},
320 {0x820, 0x01000100}, {0x824, 0x00190204},
321 {0x828, 0x00000000}, {0x82c, 0x00000000},
322 {0x830, 0x00000000}, {0x834, 0x00000000},
323 {0x838, 0x00000000}, {0x83c, 0x00000000},
324 {0x840, 0x00010000}, {0x844, 0x00000000},
325 {0x848, 0x00000000}, {0x84c, 0x00000000},
326 {0x850, 0x00000000}, {0x854, 0x00000000},
327 {0x858, 0x569a11a9}, {0x85c, 0x01000014},
328 {0x860, 0x66f60110}, {0x864, 0x061f0649},
329 {0x868, 0x00000000}, {0x86c, 0x27272700},
330 {0x870, 0x07000760}, {0x874, 0x25004000},
331 {0x878, 0x00000808}, {0x87c, 0x00000000},
332 {0x880, 0xb0000c1c}, {0x884, 0x00000001},
333 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
334 {0x890, 0x00000800}, {0x894, 0xfffffffe},
335 {0x898, 0x40302010}, {0x89c, 0x00706050},
336 {0x900, 0x00000000}, {0x904, 0x00000023},
337 {0x908, 0x00000000}, {0x90c, 0x81121111},
338 {0x910, 0x00000002}, {0x914, 0x00000201},
339 {0xa00, 0x00d047c8}, {0xa04, 0x80ff800c},
340 {0xa08, 0x8c838300}, {0xa0c, 0x2e7f120f},
341 {0xa10, 0x9500bb78}, {0xa14, 0x1114d028},
342 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
343 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
344 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
345 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
346 {0xa78, 0x00000900}, {0xa7c, 0x225b0606},
347 {0xa80, 0x21806490}, {0xb2c, 0x00000000},
348 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
349 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
350 {0xc10, 0x08800000}, {0xc14, 0x40000100},
351 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
352 {0xc20, 0x00000000}, {0xc24, 0x00000000},
353 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
354 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
355 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
356 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
357 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
358 {0xc50, 0x69553420}, {0xc54, 0x43bc0094},
359 {0xc58, 0x00013149}, {0xc5c, 0x00250492},
360 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
361 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
362 {0xc70, 0x2c7f000d}, {0xc74, 0x020610db},
363 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
364 {0xc80, 0x390000e4}, {0xc84, 0x20f60000},
365 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
366 {0xc90, 0x00020e1a}, {0xc94, 0x00000000},
367 {0xc98, 0x00020e1a}, {0xc9c, 0x00007f7f},
368 {0xca0, 0x00000000}, {0xca4, 0x000300a0},
369 {0xca8, 0x00000000}, {0xcac, 0x00000000},
370 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
371 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
372 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
373 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
374 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
375 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
376 {0xce0, 0x00222222}, {0xce4, 0x00000000},
377 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
378 {0xd00, 0x00000740}, {0xd04, 0x40020401},
379 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
380 {0xd10, 0xa0633333}, {0xd14, 0x3333bc53},
381 {0xd18, 0x7a8f5b6f}, {0xd2c, 0xcc979975},
382 {0xd30, 0x00000000}, {0xd34, 0x80608000},
383 {0xd38, 0x00000000}, {0xd3c, 0x00127353},
384 {0xd40, 0x00000000}, {0xd44, 0x00000000},
385 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
386 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
387 {0xd58, 0x00000282}, {0xd5c, 0x30032064},
388 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
389 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
390 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
391 {0xd78, 0x000e3c24}, {0xe00, 0x2d2d2d2d},
392 {0xe04, 0x2d2d2d2d}, {0xe08, 0x0390272d},
393 {0xe10, 0x2d2d2d2d}, {0xe14, 0x2d2d2d2d},
394 {0xe18, 0x2d2d2d2d}, {0xe1c, 0x2d2d2d2d},
395 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
396 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
397 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
398 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
399 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
400 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
401 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
402 {0xe68, 0x001b2556}, {0xe6c, 0x00c00096},
403 {0xe70, 0x00c00096}, {0xe74, 0x01000056},
404 {0xe78, 0x01000014}, {0xe7c, 0x01000056},
405 {0xe80, 0x01000014}, {0xe84, 0x00c00096},
406 {0xe88, 0x01000056}, {0xe8c, 0x00c00096},
407 {0xed0, 0x00c00096}, {0xed4, 0x00c00096},
408 {0xed8, 0x00c00096}, {0xedc, 0x000000d6},
409 {0xee0, 0x000000d6}, {0xeec, 0x01c00016},
410 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
411 {0xf00, 0x00000300},
412 {0x820, 0x01000100}, {0x800, 0x83040000},
413 {0xffff, 0xffffffff},
414};
415
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400416static struct rtl8xxxu_reg32val rtl8192cu_phy_2t_init_table[] = {
417 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
418 {0x800, 0x80040002}, {0x804, 0x00000003},
419 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
420 {0x810, 0x10000330}, {0x814, 0x020c3d10},
421 {0x818, 0x02200385}, {0x81c, 0x00000000},
422 {0x820, 0x01000100}, {0x824, 0x00390004},
423 {0x828, 0x01000100}, {0x82c, 0x00390004},
424 {0x830, 0x27272727}, {0x834, 0x27272727},
425 {0x838, 0x27272727}, {0x83c, 0x27272727},
426 {0x840, 0x00010000}, {0x844, 0x00010000},
427 {0x848, 0x27272727}, {0x84c, 0x27272727},
428 {0x850, 0x00000000}, {0x854, 0x00000000},
429 {0x858, 0x569a569a}, {0x85c, 0x0c1b25a4},
430 {0x860, 0x66e60230}, {0x864, 0x061f0130},
431 {0x868, 0x27272727}, {0x86c, 0x2b2b2b27},
432 {0x870, 0x07000700}, {0x874, 0x22184000},
433 {0x878, 0x08080808}, {0x87c, 0x00000000},
434 {0x880, 0xc0083070}, {0x884, 0x000004d5},
435 {0x888, 0x00000000}, {0x88c, 0xcc0000c0},
436 {0x890, 0x00000800}, {0x894, 0xfffffffe},
437 {0x898, 0x40302010}, {0x89c, 0x00706050},
438 {0x900, 0x00000000}, {0x904, 0x00000023},
439 {0x908, 0x00000000}, {0x90c, 0x81121313},
440 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
441 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
442 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
443 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
444 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
445 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
446 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
447 {0xc00, 0x48071d40}, {0xc04, 0x03a05633},
448 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
449 {0xc10, 0x08800000}, {0xc14, 0x40000100},
450 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
451 {0xc20, 0x00000000}, {0xc24, 0x00000000},
452 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
453 {0xc30, 0x69e9ac44}, {0xc34, 0x469652cf},
454 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
455 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
456 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
457 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
458 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
459 {0xc60, 0x00000000}, {0xc64, 0x5116848b},
460 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
461 {0xc70, 0x2c7f000d}, {0xc74, 0x2186115b},
462 {0xc78, 0x0000001f}, {0xc7c, 0x00b99612},
463 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
464 {0xc88, 0x40000100}, {0xc8c, 0xa0e40000},
465 {0xc90, 0x00121820}, {0xc94, 0x00000000},
466 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
467 {0xca0, 0x00000000}, {0xca4, 0x00000080},
468 {0xca8, 0x00000000}, {0xcac, 0x00000000},
469 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
470 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
471 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
472 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
473 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
474 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
475 {0xce0, 0x00222222}, {0xce4, 0x00000000},
476 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
477 {0xd00, 0x00080740}, {0xd04, 0x00020403},
478 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
479 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
480 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
481 {0xd30, 0x00000000}, {0xd34, 0x80608000},
482 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
483 {0xd40, 0x00000000}, {0xd44, 0x00000000},
484 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
485 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
486 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
487 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
488 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
489 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
490 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
491 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
492 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
493 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
494 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
495 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
496 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
497 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
498 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
499 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
500 {0xe5c, 0x28160d05}, {0xe60, 0x00000010},
501 {0xe68, 0x001b25a4}, {0xe6c, 0x63db25a4},
502 {0xe70, 0x63db25a4}, {0xe74, 0x0c1b25a4},
503 {0xe78, 0x0c1b25a4}, {0xe7c, 0x0c1b25a4},
504 {0xe80, 0x0c1b25a4}, {0xe84, 0x63db25a4},
505 {0xe88, 0x0c1b25a4}, {0xe8c, 0x63db25a4},
506 {0xed0, 0x63db25a4}, {0xed4, 0x63db25a4},
507 {0xed8, 0x63db25a4}, {0xedc, 0x001b25a4},
508 {0xee0, 0x001b25a4}, {0xeec, 0x6fdb25a4},
509 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
510 {0xf00, 0x00000300},
511 {0xffff, 0xffffffff},
512};
513
514static struct rtl8xxxu_reg32val rtl8188ru_phy_1t_highpa_table[] = {
515 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
516 {0x040, 0x000c0004}, {0x800, 0x80040000},
517 {0x804, 0x00000001}, {0x808, 0x0000fc00},
518 {0x80c, 0x0000000a}, {0x810, 0x10005388},
519 {0x814, 0x020c3d10}, {0x818, 0x02200385},
520 {0x81c, 0x00000000}, {0x820, 0x01000100},
521 {0x824, 0x00390204}, {0x828, 0x00000000},
522 {0x82c, 0x00000000}, {0x830, 0x00000000},
523 {0x834, 0x00000000}, {0x838, 0x00000000},
524 {0x83c, 0x00000000}, {0x840, 0x00010000},
525 {0x844, 0x00000000}, {0x848, 0x00000000},
526 {0x84c, 0x00000000}, {0x850, 0x00000000},
527 {0x854, 0x00000000}, {0x858, 0x569a569a},
528 {0x85c, 0x001b25a4}, {0x860, 0x66e60230},
529 {0x864, 0x061f0130}, {0x868, 0x00000000},
530 {0x86c, 0x20202000}, {0x870, 0x03000300},
531 {0x874, 0x22004000}, {0x878, 0x00000808},
532 {0x87c, 0x00ffc3f1}, {0x880, 0xc0083070},
533 {0x884, 0x000004d5}, {0x888, 0x00000000},
534 {0x88c, 0xccc000c0}, {0x890, 0x00000800},
535 {0x894, 0xfffffffe}, {0x898, 0x40302010},
536 {0x89c, 0x00706050}, {0x900, 0x00000000},
537 {0x904, 0x00000023}, {0x908, 0x00000000},
538 {0x90c, 0x81121111}, {0xa00, 0x00d047c8},
539 {0xa04, 0x80ff000c}, {0xa08, 0x8c838300},
540 {0xa0c, 0x2e68120f}, {0xa10, 0x9500bb78},
541 {0xa14, 0x11144028}, {0xa18, 0x00881117},
542 {0xa1c, 0x89140f00}, {0xa20, 0x15160000},
543 {0xa24, 0x070b0f12}, {0xa28, 0x00000104},
544 {0xa2c, 0x00d30000}, {0xa70, 0x101fbf00},
545 {0xa74, 0x00000007}, {0xc00, 0x48071d40},
546 {0xc04, 0x03a05611}, {0xc08, 0x000000e4},
547 {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000},
548 {0xc14, 0x40000100}, {0xc18, 0x08800000},
549 {0xc1c, 0x40000100}, {0xc20, 0x00000000},
550 {0xc24, 0x00000000}, {0xc28, 0x00000000},
551 {0xc2c, 0x00000000}, {0xc30, 0x69e9ac44},
552 {0xc34, 0x469652cf}, {0xc38, 0x49795994},
553 {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f},
554 {0xc44, 0x000100b7}, {0xc48, 0xec020107},
555 {0xc4c, 0x007f037f}, {0xc50, 0x6954342e},
556 {0xc54, 0x43bc0094}, {0xc58, 0x6954342f},
557 {0xc5c, 0x433c0094}, {0xc60, 0x00000000},
558 {0xc64, 0x5116848b}, {0xc68, 0x47c00bff},
559 {0xc6c, 0x00000036}, {0xc70, 0x2c46000d},
560 {0xc74, 0x018610db}, {0xc78, 0x0000001f},
561 {0xc7c, 0x00b91612}, {0xc80, 0x24000090},
562 {0xc84, 0x20f60000}, {0xc88, 0x24000090},
563 {0xc8c, 0x20200000}, {0xc90, 0x00121820},
564 {0xc94, 0x00000000}, {0xc98, 0x00121820},
565 {0xc9c, 0x00007f7f}, {0xca0, 0x00000000},
566 {0xca4, 0x00000080}, {0xca8, 0x00000000},
567 {0xcac, 0x00000000}, {0xcb0, 0x00000000},
568 {0xcb4, 0x00000000}, {0xcb8, 0x00000000},
569 {0xcbc, 0x28000000}, {0xcc0, 0x00000000},
570 {0xcc4, 0x00000000}, {0xcc8, 0x00000000},
571 {0xccc, 0x00000000}, {0xcd0, 0x00000000},
572 {0xcd4, 0x00000000}, {0xcd8, 0x64b22427},
573 {0xcdc, 0x00766932}, {0xce0, 0x00222222},
574 {0xce4, 0x00000000}, {0xce8, 0x37644302},
575 {0xcec, 0x2f97d40c}, {0xd00, 0x00080740},
576 {0xd04, 0x00020401}, {0xd08, 0x0000907f},
577 {0xd0c, 0x20010201}, {0xd10, 0xa0633333},
578 {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b},
579 {0xd2c, 0xcc979975}, {0xd30, 0x00000000},
580 {0xd34, 0x80608000}, {0xd38, 0x00000000},
581 {0xd3c, 0x00027293}, {0xd40, 0x00000000},
582 {0xd44, 0x00000000}, {0xd48, 0x00000000},
583 {0xd4c, 0x00000000}, {0xd50, 0x6437140a},
584 {0xd54, 0x00000000}, {0xd58, 0x00000000},
585 {0xd5c, 0x30032064}, {0xd60, 0x4653de68},
586 {0xd64, 0x04518a3c}, {0xd68, 0x00002101},
587 {0xd6c, 0x2a201c16}, {0xd70, 0x1812362e},
588 {0xd74, 0x322c2220}, {0xd78, 0x000e3c24},
589 {0xe00, 0x24242424}, {0xe04, 0x24242424},
590 {0xe08, 0x03902024}, {0xe10, 0x24242424},
591 {0xe14, 0x24242424}, {0xe18, 0x24242424},
592 {0xe1c, 0x24242424}, {0xe28, 0x00000000},
593 {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f},
594 {0xe38, 0x02140102}, {0xe3c, 0x681604c2},
595 {0xe40, 0x01007c00}, {0xe44, 0x01004800},
596 {0xe48, 0xfb000000}, {0xe4c, 0x000028d1},
597 {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f},
598 {0xe58, 0x02140102}, {0xe5c, 0x28160d05},
599 {0xe60, 0x00000008}, {0xe68, 0x001b25a4},
600 {0xe6c, 0x631b25a0}, {0xe70, 0x631b25a0},
601 {0xe74, 0x081b25a0}, {0xe78, 0x081b25a0},
602 {0xe7c, 0x081b25a0}, {0xe80, 0x081b25a0},
603 {0xe84, 0x631b25a0}, {0xe88, 0x081b25a0},
604 {0xe8c, 0x631b25a0}, {0xed0, 0x631b25a0},
605 {0xed4, 0x631b25a0}, {0xed8, 0x631b25a0},
606 {0xedc, 0x001b25a0}, {0xee0, 0x001b25a0},
607 {0xeec, 0x6b1b25a0}, {0xee8, 0x31555448},
608 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
609 {0xf00, 0x00000300},
610 {0xffff, 0xffffffff},
611};
612
613static struct rtl8xxxu_reg32val rtl8xxx_agc_standard_table[] = {
614 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
615 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
616 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
617 {0xc78, 0x7a060001}, {0xc78, 0x79070001},
618 {0xc78, 0x78080001}, {0xc78, 0x77090001},
619 {0xc78, 0x760a0001}, {0xc78, 0x750b0001},
620 {0xc78, 0x740c0001}, {0xc78, 0x730d0001},
621 {0xc78, 0x720e0001}, {0xc78, 0x710f0001},
622 {0xc78, 0x70100001}, {0xc78, 0x6f110001},
623 {0xc78, 0x6e120001}, {0xc78, 0x6d130001},
624 {0xc78, 0x6c140001}, {0xc78, 0x6b150001},
625 {0xc78, 0x6a160001}, {0xc78, 0x69170001},
626 {0xc78, 0x68180001}, {0xc78, 0x67190001},
627 {0xc78, 0x661a0001}, {0xc78, 0x651b0001},
628 {0xc78, 0x641c0001}, {0xc78, 0x631d0001},
629 {0xc78, 0x621e0001}, {0xc78, 0x611f0001},
630 {0xc78, 0x60200001}, {0xc78, 0x49210001},
631 {0xc78, 0x48220001}, {0xc78, 0x47230001},
632 {0xc78, 0x46240001}, {0xc78, 0x45250001},
633 {0xc78, 0x44260001}, {0xc78, 0x43270001},
634 {0xc78, 0x42280001}, {0xc78, 0x41290001},
635 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
636 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
637 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
638 {0xc78, 0x21300001}, {0xc78, 0x20310001},
639 {0xc78, 0x06320001}, {0xc78, 0x05330001},
640 {0xc78, 0x04340001}, {0xc78, 0x03350001},
641 {0xc78, 0x02360001}, {0xc78, 0x01370001},
642 {0xc78, 0x00380001}, {0xc78, 0x00390001},
643 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
644 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
645 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
646 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
647 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
648 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
649 {0xc78, 0x7a460001}, {0xc78, 0x79470001},
650 {0xc78, 0x78480001}, {0xc78, 0x77490001},
651 {0xc78, 0x764a0001}, {0xc78, 0x754b0001},
652 {0xc78, 0x744c0001}, {0xc78, 0x734d0001},
653 {0xc78, 0x724e0001}, {0xc78, 0x714f0001},
654 {0xc78, 0x70500001}, {0xc78, 0x6f510001},
655 {0xc78, 0x6e520001}, {0xc78, 0x6d530001},
656 {0xc78, 0x6c540001}, {0xc78, 0x6b550001},
657 {0xc78, 0x6a560001}, {0xc78, 0x69570001},
658 {0xc78, 0x68580001}, {0xc78, 0x67590001},
659 {0xc78, 0x665a0001}, {0xc78, 0x655b0001},
660 {0xc78, 0x645c0001}, {0xc78, 0x635d0001},
661 {0xc78, 0x625e0001}, {0xc78, 0x615f0001},
662 {0xc78, 0x60600001}, {0xc78, 0x49610001},
663 {0xc78, 0x48620001}, {0xc78, 0x47630001},
664 {0xc78, 0x46640001}, {0xc78, 0x45650001},
665 {0xc78, 0x44660001}, {0xc78, 0x43670001},
666 {0xc78, 0x42680001}, {0xc78, 0x41690001},
667 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
668 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
669 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
670 {0xc78, 0x21700001}, {0xc78, 0x20710001},
671 {0xc78, 0x06720001}, {0xc78, 0x05730001},
672 {0xc78, 0x04740001}, {0xc78, 0x03750001},
673 {0xc78, 0x02760001}, {0xc78, 0x01770001},
674 {0xc78, 0x00780001}, {0xc78, 0x00790001},
675 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
676 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
677 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
678 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
679 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
680 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
681 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
682 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
683 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
684 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
685 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
686 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
687 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
688 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
689 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
690 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
691 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
692 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
693 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
694 {0xffff, 0xffffffff}
695};
696
697static struct rtl8xxxu_reg32val rtl8xxx_agc_highpa_table[] = {
698 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
699 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
700 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
701 {0xc78, 0x7b060001}, {0xc78, 0x7b070001},
702 {0xc78, 0x7b080001}, {0xc78, 0x7a090001},
703 {0xc78, 0x790a0001}, {0xc78, 0x780b0001},
704 {0xc78, 0x770c0001}, {0xc78, 0x760d0001},
705 {0xc78, 0x750e0001}, {0xc78, 0x740f0001},
706 {0xc78, 0x73100001}, {0xc78, 0x72110001},
707 {0xc78, 0x71120001}, {0xc78, 0x70130001},
708 {0xc78, 0x6f140001}, {0xc78, 0x6e150001},
709 {0xc78, 0x6d160001}, {0xc78, 0x6c170001},
710 {0xc78, 0x6b180001}, {0xc78, 0x6a190001},
711 {0xc78, 0x691a0001}, {0xc78, 0x681b0001},
712 {0xc78, 0x671c0001}, {0xc78, 0x661d0001},
713 {0xc78, 0x651e0001}, {0xc78, 0x641f0001},
714 {0xc78, 0x63200001}, {0xc78, 0x62210001},
715 {0xc78, 0x61220001}, {0xc78, 0x60230001},
716 {0xc78, 0x46240001}, {0xc78, 0x45250001},
717 {0xc78, 0x44260001}, {0xc78, 0x43270001},
718 {0xc78, 0x42280001}, {0xc78, 0x41290001},
719 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
720 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
721 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
722 {0xc78, 0x21300001}, {0xc78, 0x20310001},
723 {0xc78, 0x06320001}, {0xc78, 0x05330001},
724 {0xc78, 0x04340001}, {0xc78, 0x03350001},
725 {0xc78, 0x02360001}, {0xc78, 0x01370001},
726 {0xc78, 0x00380001}, {0xc78, 0x00390001},
727 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
728 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
729 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
730 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
731 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
732 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
733 {0xc78, 0x7b460001}, {0xc78, 0x7b470001},
734 {0xc78, 0x7b480001}, {0xc78, 0x7a490001},
735 {0xc78, 0x794a0001}, {0xc78, 0x784b0001},
736 {0xc78, 0x774c0001}, {0xc78, 0x764d0001},
737 {0xc78, 0x754e0001}, {0xc78, 0x744f0001},
738 {0xc78, 0x73500001}, {0xc78, 0x72510001},
739 {0xc78, 0x71520001}, {0xc78, 0x70530001},
740 {0xc78, 0x6f540001}, {0xc78, 0x6e550001},
741 {0xc78, 0x6d560001}, {0xc78, 0x6c570001},
742 {0xc78, 0x6b580001}, {0xc78, 0x6a590001},
743 {0xc78, 0x695a0001}, {0xc78, 0x685b0001},
744 {0xc78, 0x675c0001}, {0xc78, 0x665d0001},
745 {0xc78, 0x655e0001}, {0xc78, 0x645f0001},
746 {0xc78, 0x63600001}, {0xc78, 0x62610001},
747 {0xc78, 0x61620001}, {0xc78, 0x60630001},
748 {0xc78, 0x46640001}, {0xc78, 0x45650001},
749 {0xc78, 0x44660001}, {0xc78, 0x43670001},
750 {0xc78, 0x42680001}, {0xc78, 0x41690001},
751 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
752 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
753 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
754 {0xc78, 0x21700001}, {0xc78, 0x20710001},
755 {0xc78, 0x06720001}, {0xc78, 0x05730001},
756 {0xc78, 0x04740001}, {0xc78, 0x03750001},
757 {0xc78, 0x02760001}, {0xc78, 0x01770001},
758 {0xc78, 0x00780001}, {0xc78, 0x00790001},
759 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
760 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
761 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
762 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
763 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
764 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
765 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
766 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
767 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
768 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
769 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
770 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
771 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
772 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
773 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
774 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
775 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
776 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
777 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
778 {0xffff, 0xffffffff}
779};
780
Jes Sorensenb9f498e2016-02-29 17:04:18 -0500781static struct rtl8xxxu_reg32val rtl8xxx_agc_8723bu_table[] = {
782 {0xc78, 0xfd000001}, {0xc78, 0xfc010001},
783 {0xc78, 0xfb020001}, {0xc78, 0xfa030001},
784 {0xc78, 0xf9040001}, {0xc78, 0xf8050001},
785 {0xc78, 0xf7060001}, {0xc78, 0xf6070001},
786 {0xc78, 0xf5080001}, {0xc78, 0xf4090001},
787 {0xc78, 0xf30a0001}, {0xc78, 0xf20b0001},
788 {0xc78, 0xf10c0001}, {0xc78, 0xf00d0001},
789 {0xc78, 0xef0e0001}, {0xc78, 0xee0f0001},
790 {0xc78, 0xed100001}, {0xc78, 0xec110001},
791 {0xc78, 0xeb120001}, {0xc78, 0xea130001},
792 {0xc78, 0xe9140001}, {0xc78, 0xe8150001},
793 {0xc78, 0xe7160001}, {0xc78, 0xe6170001},
794 {0xc78, 0xe5180001}, {0xc78, 0xe4190001},
795 {0xc78, 0xe31a0001}, {0xc78, 0xa51b0001},
796 {0xc78, 0xa41c0001}, {0xc78, 0xa31d0001},
797 {0xc78, 0x671e0001}, {0xc78, 0x661f0001},
798 {0xc78, 0x65200001}, {0xc78, 0x64210001},
799 {0xc78, 0x63220001}, {0xc78, 0x4a230001},
800 {0xc78, 0x49240001}, {0xc78, 0x48250001},
801 {0xc78, 0x47260001}, {0xc78, 0x46270001},
802 {0xc78, 0x45280001}, {0xc78, 0x44290001},
803 {0xc78, 0x432a0001}, {0xc78, 0x422b0001},
804 {0xc78, 0x292c0001}, {0xc78, 0x282d0001},
805 {0xc78, 0x272e0001}, {0xc78, 0x262f0001},
806 {0xc78, 0x0a300001}, {0xc78, 0x09310001},
807 {0xc78, 0x08320001}, {0xc78, 0x07330001},
808 {0xc78, 0x06340001}, {0xc78, 0x05350001},
809 {0xc78, 0x04360001}, {0xc78, 0x03370001},
810 {0xc78, 0x02380001}, {0xc78, 0x01390001},
811 {0xc78, 0x013a0001}, {0xc78, 0x013b0001},
812 {0xc78, 0x013c0001}, {0xc78, 0x013d0001},
813 {0xc78, 0x013e0001}, {0xc78, 0x013f0001},
814 {0xc78, 0xfc400001}, {0xc78, 0xfb410001},
815 {0xc78, 0xfa420001}, {0xc78, 0xf9430001},
816 {0xc78, 0xf8440001}, {0xc78, 0xf7450001},
817 {0xc78, 0xf6460001}, {0xc78, 0xf5470001},
818 {0xc78, 0xf4480001}, {0xc78, 0xf3490001},
819 {0xc78, 0xf24a0001}, {0xc78, 0xf14b0001},
820 {0xc78, 0xf04c0001}, {0xc78, 0xef4d0001},
821 {0xc78, 0xee4e0001}, {0xc78, 0xed4f0001},
822 {0xc78, 0xec500001}, {0xc78, 0xeb510001},
823 {0xc78, 0xea520001}, {0xc78, 0xe9530001},
824 {0xc78, 0xe8540001}, {0xc78, 0xe7550001},
825 {0xc78, 0xe6560001}, {0xc78, 0xe5570001},
826 {0xc78, 0xe4580001}, {0xc78, 0xe3590001},
827 {0xc78, 0xa65a0001}, {0xc78, 0xa55b0001},
828 {0xc78, 0xa45c0001}, {0xc78, 0xa35d0001},
829 {0xc78, 0x675e0001}, {0xc78, 0x665f0001},
830 {0xc78, 0x65600001}, {0xc78, 0x64610001},
831 {0xc78, 0x63620001}, {0xc78, 0x62630001},
832 {0xc78, 0x61640001}, {0xc78, 0x48650001},
833 {0xc78, 0x47660001}, {0xc78, 0x46670001},
834 {0xc78, 0x45680001}, {0xc78, 0x44690001},
835 {0xc78, 0x436a0001}, {0xc78, 0x426b0001},
836 {0xc78, 0x286c0001}, {0xc78, 0x276d0001},
837 {0xc78, 0x266e0001}, {0xc78, 0x256f0001},
838 {0xc78, 0x24700001}, {0xc78, 0x09710001},
839 {0xc78, 0x08720001}, {0xc78, 0x07730001},
840 {0xc78, 0x06740001}, {0xc78, 0x05750001},
841 {0xc78, 0x04760001}, {0xc78, 0x03770001},
842 {0xc78, 0x02780001}, {0xc78, 0x01790001},
843 {0xc78, 0x017a0001}, {0xc78, 0x017b0001},
844 {0xc78, 0x017c0001}, {0xc78, 0x017d0001},
845 {0xc78, 0x017e0001}, {0xc78, 0x017f0001},
846 {0xc50, 0x69553422},
847 {0xc50, 0x69553420},
848 {0x824, 0x00390204},
849 {0xffff, 0xffffffff}
850};
851
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400852static struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = {
853 {0x00, 0x00030159}, {0x01, 0x00031284},
854 {0x02, 0x00098000}, {0x03, 0x00039c63},
855 {0x04, 0x000210e7}, {0x09, 0x0002044f},
856 {0x0a, 0x0001a3f1}, {0x0b, 0x00014787},
857 {0x0c, 0x000896fe}, {0x0d, 0x0000e02c},
858 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
859 {0x19, 0x00000000}, {0x1a, 0x00030355},
860 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
861 {0x1d, 0x000a1250}, {0x1e, 0x0000024f},
862 {0x1f, 0x00000000}, {0x20, 0x0000b614},
863 {0x21, 0x0006c000}, {0x22, 0x00000000},
864 {0x23, 0x00001558}, {0x24, 0x00000060},
865 {0x25, 0x00000483}, {0x26, 0x0004f000},
866 {0x27, 0x000ec7d9}, {0x28, 0x00057730},
867 {0x29, 0x00004783}, {0x2a, 0x00000001},
868 {0x2b, 0x00021334}, {0x2a, 0x00000000},
869 {0x2b, 0x00000054}, {0x2a, 0x00000001},
870 {0x2b, 0x00000808}, {0x2b, 0x00053333},
871 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
872 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
873 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
874 {0x2b, 0x00000808}, {0x2b, 0x00063333},
875 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
876 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
877 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
878 {0x2b, 0x00000808}, {0x2b, 0x00073333},
879 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
880 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
881 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
882 {0x2b, 0x00000709}, {0x2b, 0x00063333},
883 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
884 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
885 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
886 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
887 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
888 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
889 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
890 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
891 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
892 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
893 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
894 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
895 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
896 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
897 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
898 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
899 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
900 {0x10, 0x0002000f}, {0x11, 0x000203f9},
901 {0x10, 0x0003000f}, {0x11, 0x000ff500},
902 {0x10, 0x00000000}, {0x11, 0x00000000},
903 {0x10, 0x0008000f}, {0x11, 0x0003f100},
904 {0x10, 0x0009000f}, {0x11, 0x00023100},
905 {0x12, 0x00032000}, {0x12, 0x00071000},
906 {0x12, 0x000b0000}, {0x12, 0x000fc000},
907 {0x13, 0x000287b3}, {0x13, 0x000244b7},
908 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
909 {0x13, 0x00018493}, {0x13, 0x0001429b},
910 {0x13, 0x00010299}, {0x13, 0x0000c29c},
911 {0x13, 0x000081a0}, {0x13, 0x000040ac},
912 {0x13, 0x00000020}, {0x14, 0x0001944c},
913 {0x14, 0x00059444}, {0x14, 0x0009944c},
914 {0x14, 0x000d9444}, {0x15, 0x0000f474},
915 {0x15, 0x0004f477}, {0x15, 0x0008f455},
916 {0x15, 0x000cf455}, {0x16, 0x00000339},
917 {0x16, 0x00040339}, {0x16, 0x00080339},
918 {0x16, 0x000c0366}, {0x00, 0x00010159},
919 {0x18, 0x0000f401}, {0xfe, 0x00000000},
920 {0xfe, 0x00000000}, {0x1f, 0x00000003},
921 {0xfe, 0x00000000}, {0xfe, 0x00000000},
922 {0x1e, 0x00000247}, {0x1f, 0x00000000},
923 {0x00, 0x00030159},
924 {0xff, 0xffffffff}
925};
926
Jes Sorensen22a31d42016-02-29 17:04:15 -0500927static struct rtl8xxxu_rfregval rtl8723bu_radioa_1t_init_table[] = {
928 {0x00, 0x00010000}, {0xb0, 0x000dffe0},
929 {0xfe, 0x00000000}, {0xfe, 0x00000000},
930 {0xfe, 0x00000000}, {0xb1, 0x00000018},
931 {0xfe, 0x00000000}, {0xfe, 0x00000000},
932 {0xfe, 0x00000000}, {0xb2, 0x00084c00},
933 {0xb5, 0x0000d2cc}, {0xb6, 0x000925aa},
934 {0xb7, 0x00000010}, {0xb8, 0x0000907f},
935 {0x5c, 0x00000002}, {0x7c, 0x00000002},
936 {0x7e, 0x00000005}, {0x8b, 0x0006fc00},
937 {0xb0, 0x000ff9f0}, {0x1c, 0x000739d2},
938 {0x1e, 0x00000000}, {0xdf, 0x00000780},
939 {0x50, 0x00067435},
940 /*
941 * The 8723bu vendor driver indicates that bit 8 should be set in
942 * 0x51 for package types TFBGA90, TFBGA80, and TFBGA79. However
943 * they never actually check the package type - and just default
944 * to not setting it.
945 */
946 {0x51, 0x0006b04e},
947 {0x52, 0x000007d2}, {0x53, 0x00000000},
948 {0x54, 0x00050400}, {0x55, 0x0004026e},
949 {0xdd, 0x0000004c}, {0x70, 0x00067435},
950 /*
951 * 0x71 has same package type condition as for register 0x51
952 */
953 {0x71, 0x0006b04e},
954 {0x72, 0x000007d2}, {0x73, 0x00000000},
955 {0x74, 0x00050400}, {0x75, 0x0004026e},
956 {0xef, 0x00000100}, {0x34, 0x0000add7},
957 {0x35, 0x00005c00}, {0x34, 0x00009dd4},
958 {0x35, 0x00005000}, {0x34, 0x00008dd1},
959 {0x35, 0x00004400}, {0x34, 0x00007dce},
960 {0x35, 0x00003800}, {0x34, 0x00006cd1},
961 {0x35, 0x00004400}, {0x34, 0x00005cce},
962 {0x35, 0x00003800}, {0x34, 0x000048ce},
963 {0x35, 0x00004400}, {0x34, 0x000034ce},
964 {0x35, 0x00003800}, {0x34, 0x00002451},
965 {0x35, 0x00004400}, {0x34, 0x0000144e},
966 {0x35, 0x00003800}, {0x34, 0x00000051},
967 {0x35, 0x00004400}, {0xef, 0x00000000},
968 {0xef, 0x00000100}, {0xed, 0x00000010},
969 {0x44, 0x0000add7}, {0x44, 0x00009dd4},
970 {0x44, 0x00008dd1}, {0x44, 0x00007dce},
971 {0x44, 0x00006cc1}, {0x44, 0x00005cce},
972 {0x44, 0x000044d1}, {0x44, 0x000034ce},
973 {0x44, 0x00002451}, {0x44, 0x0000144e},
974 {0x44, 0x00000051}, {0xef, 0x00000000},
975 {0xed, 0x00000000}, {0x7f, 0x00020080},
976 {0xef, 0x00002000}, {0x3b, 0x000380ef},
977 {0x3b, 0x000302fe}, {0x3b, 0x00028ce6},
978 {0x3b, 0x000200bc}, {0x3b, 0x000188a5},
979 {0x3b, 0x00010fbc}, {0x3b, 0x00008f71},
980 {0x3b, 0x00000900}, {0xef, 0x00000000},
981 {0xed, 0x00000001}, {0x40, 0x000380ef},
982 {0x40, 0x000302fe}, {0x40, 0x00028ce6},
983 {0x40, 0x000200bc}, {0x40, 0x000188a5},
984 {0x40, 0x00010fbc}, {0x40, 0x00008f71},
985 {0x40, 0x00000900}, {0xed, 0x00000000},
986 {0x82, 0x00080000}, {0x83, 0x00008000},
987 {0x84, 0x00048d80}, {0x85, 0x00068000},
988 {0xa2, 0x00080000}, {0xa3, 0x00008000},
989 {0xa4, 0x00048d80}, {0xa5, 0x00068000},
990 {0xed, 0x00000002}, {0xef, 0x00000002},
991 {0x56, 0x00000032}, {0x76, 0x00000032},
992 {0x01, 0x00000780},
993 {0xff, 0xffffffff}
994};
995
Jes Sorensen26f1fad2015-10-14 20:44:51 -0400996static struct rtl8xxxu_rfregval rtl8192cu_radioa_2t_init_table[] = {
997 {0x00, 0x00030159}, {0x01, 0x00031284},
998 {0x02, 0x00098000}, {0x03, 0x00018c63},
999 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1000 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1001 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1002 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1003 {0x19, 0x00000000}, {0x1a, 0x00010255},
1004 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1005 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1006 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1007 {0x21, 0x0006c000}, {0x22, 0x00000000},
1008 {0x23, 0x00001558}, {0x24, 0x00000060},
1009 {0x25, 0x00000483}, {0x26, 0x0004f000},
1010 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
1011 {0x29, 0x00004783}, {0x2a, 0x00000001},
1012 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1013 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1014 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1015 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1016 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1017 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1018 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1019 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1020 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1021 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1022 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1023 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1024 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1025 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1026 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1027 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1028 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1029 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1030 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1031 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1032 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1033 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1034 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1035 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1036 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1037 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1038 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1039 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1040 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1041 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1042 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1043 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1044 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1045 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1046 {0x10, 0x00000000}, {0x11, 0x00000000},
1047 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1048 {0x10, 0x0009000f}, {0x11, 0x00023100},
1049 {0x12, 0x00032000}, {0x12, 0x00071000},
1050 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1051 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1052 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1053 {0x13, 0x00018493}, {0x13, 0x0001429b},
1054 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1055 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1056 {0x13, 0x00000020}, {0x14, 0x0001944c},
1057 {0x14, 0x00059444}, {0x14, 0x0009944c},
1058 {0x14, 0x000d9444}, {0x15, 0x0000f424},
1059 {0x15, 0x0004f424}, {0x15, 0x0008f424},
1060 {0x15, 0x000cf424}, {0x16, 0x000e0330},
1061 {0x16, 0x000a0330}, {0x16, 0x00060330},
1062 {0x16, 0x00020330}, {0x00, 0x00010159},
1063 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1064 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1065 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1066 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1067 {0x00, 0x00030159},
1068 {0xff, 0xffffffff}
1069};
1070
1071static struct rtl8xxxu_rfregval rtl8192cu_radiob_2t_init_table[] = {
1072 {0x00, 0x00030159}, {0x01, 0x00031284},
1073 {0x02, 0x00098000}, {0x03, 0x00018c63},
1074 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1075 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1076 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1077 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1078 {0x12, 0x00032000}, {0x12, 0x00071000},
1079 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1080 {0x13, 0x000287af}, {0x13, 0x000244b7},
1081 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1082 {0x13, 0x00018493}, {0x13, 0x00014297},
1083 {0x13, 0x00010295}, {0x13, 0x0000c298},
1084 {0x13, 0x0000819c}, {0x13, 0x000040a8},
1085 {0x13, 0x0000001c}, {0x14, 0x0001944c},
1086 {0x14, 0x00059444}, {0x14, 0x0009944c},
1087 {0x14, 0x000d9444}, {0x15, 0x0000f424},
1088 {0x15, 0x0004f424}, {0x15, 0x0008f424},
1089 {0x15, 0x000cf424}, {0x16, 0x000e0330},
1090 {0x16, 0x000a0330}, {0x16, 0x00060330},
1091 {0x16, 0x00020330},
1092 {0xff, 0xffffffff}
1093};
1094
1095static struct rtl8xxxu_rfregval rtl8192cu_radioa_1t_init_table[] = {
1096 {0x00, 0x00030159}, {0x01, 0x00031284},
1097 {0x02, 0x00098000}, {0x03, 0x00018c63},
1098 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1099 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1100 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1101 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1102 {0x19, 0x00000000}, {0x1a, 0x00010255},
1103 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1104 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1105 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1106 {0x21, 0x0006c000}, {0x22, 0x00000000},
1107 {0x23, 0x00001558}, {0x24, 0x00000060},
1108 {0x25, 0x00000483}, {0x26, 0x0004f000},
1109 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
1110 {0x29, 0x00004783}, {0x2a, 0x00000001},
1111 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1112 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1113 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1114 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1115 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1116 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1117 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1118 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1119 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1120 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1121 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1122 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1123 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1124 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1125 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1126 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1127 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1128 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1129 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1130 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1131 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1132 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1133 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1134 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1135 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1136 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1137 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1138 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1139 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1140 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1141 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1142 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1143 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1144 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1145 {0x10, 0x00000000}, {0x11, 0x00000000},
1146 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1147 {0x10, 0x0009000f}, {0x11, 0x00023100},
1148 {0x12, 0x00032000}, {0x12, 0x00071000},
1149 {0x12, 0x000b0000}, {0x12, 0x000fc000},
1150 {0x13, 0x000287b3}, {0x13, 0x000244b7},
1151 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
1152 {0x13, 0x00018493}, {0x13, 0x0001429b},
1153 {0x13, 0x00010299}, {0x13, 0x0000c29c},
1154 {0x13, 0x000081a0}, {0x13, 0x000040ac},
1155 {0x13, 0x00000020}, {0x14, 0x0001944c},
1156 {0x14, 0x00059444}, {0x14, 0x0009944c},
1157 {0x14, 0x000d9444}, {0x15, 0x0000f405},
1158 {0x15, 0x0004f405}, {0x15, 0x0008f405},
1159 {0x15, 0x000cf405}, {0x16, 0x000e0330},
1160 {0x16, 0x000a0330}, {0x16, 0x00060330},
1161 {0x16, 0x00020330}, {0x00, 0x00010159},
1162 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1163 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1164 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1165 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1166 {0x00, 0x00030159},
1167 {0xff, 0xffffffff}
1168};
1169
1170static struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = {
1171 {0x00, 0x00030159}, {0x01, 0x00031284},
1172 {0x02, 0x00098000}, {0x03, 0x00018c63},
1173 {0x04, 0x000210e7}, {0x09, 0x0002044f},
1174 {0x0a, 0x0001adb0}, {0x0b, 0x00054867},
1175 {0x0c, 0x0008992e}, {0x0d, 0x0000e529},
1176 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1177 {0x19, 0x00000000}, {0x1a, 0x00000255},
1178 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1179 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1180 {0x1f, 0x00080001}, {0x20, 0x0000b614},
1181 {0x21, 0x0006c000}, {0x22, 0x0000083c},
1182 {0x23, 0x00001558}, {0x24, 0x00000060},
1183 {0x25, 0x00000483}, {0x26, 0x0004f000},
1184 {0x27, 0x000ec7d9}, {0x28, 0x000977c0},
1185 {0x29, 0x00004783}, {0x2a, 0x00000001},
1186 {0x2b, 0x00021334}, {0x2a, 0x00000000},
1187 {0x2b, 0x00000054}, {0x2a, 0x00000001},
1188 {0x2b, 0x00000808}, {0x2b, 0x00053333},
1189 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
1190 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
1191 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
1192 {0x2b, 0x00000808}, {0x2b, 0x00063333},
1193 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
1194 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
1195 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
1196 {0x2b, 0x00000808}, {0x2b, 0x00073333},
1197 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
1198 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
1199 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
1200 {0x2b, 0x00000709}, {0x2b, 0x00063333},
1201 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
1202 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1203 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
1204 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
1205 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1206 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1207 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1208 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
1209 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1210 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1211 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1212 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
1213 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1214 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
1215 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1216 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
1217 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1218 {0x10, 0x0002000f}, {0x11, 0x000203f9},
1219 {0x10, 0x0003000f}, {0x11, 0x000ff500},
1220 {0x10, 0x00000000}, {0x11, 0x00000000},
1221 {0x10, 0x0008000f}, {0x11, 0x0003f100},
1222 {0x10, 0x0009000f}, {0x11, 0x00023100},
1223 {0x12, 0x000d8000}, {0x12, 0x00090000},
1224 {0x12, 0x00051000}, {0x12, 0x00012000},
1225 {0x13, 0x00028fb4}, {0x13, 0x00024fa8},
1226 {0x13, 0x000207a4}, {0x13, 0x0001c3b0},
1227 {0x13, 0x000183a4}, {0x13, 0x00014398},
1228 {0x13, 0x000101a4}, {0x13, 0x0000c198},
1229 {0x13, 0x000080a4}, {0x13, 0x00004098},
1230 {0x13, 0x00000000}, {0x14, 0x0001944c},
1231 {0x14, 0x00059444}, {0x14, 0x0009944c},
1232 {0x14, 0x000d9444}, {0x15, 0x0000f405},
1233 {0x15, 0x0004f405}, {0x15, 0x0008f405},
1234 {0x15, 0x000cf405}, {0x16, 0x000e0330},
1235 {0x16, 0x000a0330}, {0x16, 0x00060330},
1236 {0x16, 0x00020330}, {0x00, 0x00010159},
1237 {0x18, 0x0000f401}, {0xfe, 0x00000000},
1238 {0xfe, 0x00000000}, {0x1f, 0x00080003},
1239 {0xfe, 0x00000000}, {0xfe, 0x00000000},
1240 {0x1e, 0x00044457}, {0x1f, 0x00080000},
1241 {0x00, 0x00030159},
1242 {0xff, 0xffffffff}
1243};
1244
1245static struct rtl8xxxu_rfregs rtl8xxxu_rfregs[] = {
1246 { /* RF_A */
1247 .hssiparm1 = REG_FPGA0_XA_HSSI_PARM1,
1248 .hssiparm2 = REG_FPGA0_XA_HSSI_PARM2,
1249 .lssiparm = REG_FPGA0_XA_LSSI_PARM,
1250 .hspiread = REG_HSPI_XA_READBACK,
1251 .lssiread = REG_FPGA0_XA_LSSI_READBACK,
1252 .rf_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL,
1253 },
1254 { /* RF_B */
1255 .hssiparm1 = REG_FPGA0_XB_HSSI_PARM1,
1256 .hssiparm2 = REG_FPGA0_XB_HSSI_PARM2,
1257 .lssiparm = REG_FPGA0_XB_LSSI_PARM,
1258 .hspiread = REG_HSPI_XB_READBACK,
1259 .lssiread = REG_FPGA0_XB_LSSI_READBACK,
1260 .rf_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL,
1261 },
1262};
1263
1264static const u32 rtl8723au_iqk_phy_iq_bb_reg[RTL8XXXU_BB_REGS] = {
1265 REG_OFDM0_XA_RX_IQ_IMBALANCE,
1266 REG_OFDM0_XB_RX_IQ_IMBALANCE,
1267 REG_OFDM0_ENERGY_CCA_THRES,
1268 REG_OFDM0_AGCR_SSI_TABLE,
1269 REG_OFDM0_XA_TX_IQ_IMBALANCE,
1270 REG_OFDM0_XB_TX_IQ_IMBALANCE,
1271 REG_OFDM0_XC_TX_AFE,
1272 REG_OFDM0_XD_TX_AFE,
1273 REG_OFDM0_RX_IQ_EXT_ANTA
1274};
1275
1276static u8 rtl8xxxu_read8(struct rtl8xxxu_priv *priv, u16 addr)
1277{
1278 struct usb_device *udev = priv->udev;
1279 int len;
1280 u8 data;
1281
1282 mutex_lock(&priv->usb_buf_mutex);
1283 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1284 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1285 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1286 RTW_USB_CONTROL_MSG_TIMEOUT);
1287 data = priv->usb_buf.val8;
1288 mutex_unlock(&priv->usb_buf_mutex);
1289
1290 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1291 dev_info(&udev->dev, "%s(%04x) = 0x%02x, len %i\n",
1292 __func__, addr, data, len);
1293 return data;
1294}
1295
1296static u16 rtl8xxxu_read16(struct rtl8xxxu_priv *priv, u16 addr)
1297{
1298 struct usb_device *udev = priv->udev;
1299 int len;
1300 u16 data;
1301
1302 mutex_lock(&priv->usb_buf_mutex);
1303 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1304 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1305 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1306 RTW_USB_CONTROL_MSG_TIMEOUT);
1307 data = le16_to_cpu(priv->usb_buf.val16);
1308 mutex_unlock(&priv->usb_buf_mutex);
1309
1310 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1311 dev_info(&udev->dev, "%s(%04x) = 0x%04x, len %i\n",
1312 __func__, addr, data, len);
1313 return data;
1314}
1315
1316static u32 rtl8xxxu_read32(struct rtl8xxxu_priv *priv, u16 addr)
1317{
1318 struct usb_device *udev = priv->udev;
1319 int len;
1320 u32 data;
1321
1322 mutex_lock(&priv->usb_buf_mutex);
1323 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1324 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1325 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1326 RTW_USB_CONTROL_MSG_TIMEOUT);
1327 data = le32_to_cpu(priv->usb_buf.val32);
1328 mutex_unlock(&priv->usb_buf_mutex);
1329
1330 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1331 dev_info(&udev->dev, "%s(%04x) = 0x%08x, len %i\n",
1332 __func__, addr, data, len);
1333 return data;
1334}
1335
1336static int rtl8xxxu_write8(struct rtl8xxxu_priv *priv, u16 addr, u8 val)
1337{
1338 struct usb_device *udev = priv->udev;
1339 int ret;
1340
1341 mutex_lock(&priv->usb_buf_mutex);
1342 priv->usb_buf.val8 = val;
1343 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1344 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1345 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1346 RTW_USB_CONTROL_MSG_TIMEOUT);
1347
1348 mutex_unlock(&priv->usb_buf_mutex);
1349
1350 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1351 dev_info(&udev->dev, "%s(%04x) = 0x%02x\n",
1352 __func__, addr, val);
1353 return ret;
1354}
1355
1356static int rtl8xxxu_write16(struct rtl8xxxu_priv *priv, u16 addr, u16 val)
1357{
1358 struct usb_device *udev = priv->udev;
1359 int ret;
1360
1361 mutex_lock(&priv->usb_buf_mutex);
1362 priv->usb_buf.val16 = cpu_to_le16(val);
1363 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1364 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1365 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1366 RTW_USB_CONTROL_MSG_TIMEOUT);
1367 mutex_unlock(&priv->usb_buf_mutex);
1368
1369 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1370 dev_info(&udev->dev, "%s(%04x) = 0x%04x\n",
1371 __func__, addr, val);
1372 return ret;
1373}
1374
1375static int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val)
1376{
1377 struct usb_device *udev = priv->udev;
1378 int ret;
1379
1380 mutex_lock(&priv->usb_buf_mutex);
1381 priv->usb_buf.val32 = cpu_to_le32(val);
1382 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1383 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1384 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1385 RTW_USB_CONTROL_MSG_TIMEOUT);
1386 mutex_unlock(&priv->usb_buf_mutex);
1387
1388 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1389 dev_info(&udev->dev, "%s(%04x) = 0x%08x\n",
1390 __func__, addr, val);
1391 return ret;
1392}
1393
1394static int
1395rtl8xxxu_writeN(struct rtl8xxxu_priv *priv, u16 addr, u8 *buf, u16 len)
1396{
1397 struct usb_device *udev = priv->udev;
1398 int blocksize = priv->fops->writeN_block_size;
1399 int ret, i, count, remainder;
1400
1401 count = len / blocksize;
1402 remainder = len % blocksize;
1403
1404 for (i = 0; i < count; i++) {
1405 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1406 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1407 addr, 0, buf, blocksize,
1408 RTW_USB_CONTROL_MSG_TIMEOUT);
1409 if (ret != blocksize)
1410 goto write_error;
1411
1412 addr += blocksize;
1413 buf += blocksize;
1414 }
1415
1416 if (remainder) {
1417 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1418 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1419 addr, 0, buf, remainder,
1420 RTW_USB_CONTROL_MSG_TIMEOUT);
1421 if (ret != remainder)
1422 goto write_error;
1423 }
1424
1425 return len;
1426
1427write_error:
1428 dev_info(&udev->dev,
1429 "%s: Failed to write block at addr: %04x size: %04x\n",
1430 __func__, addr, blocksize);
1431 return -EAGAIN;
1432}
1433
1434static u32 rtl8xxxu_read_rfreg(struct rtl8xxxu_priv *priv,
1435 enum rtl8xxxu_rfpath path, u8 reg)
1436{
1437 u32 hssia, val32, retval;
1438
1439 hssia = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2);
1440 if (path != RF_A)
1441 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm2);
1442 else
1443 val32 = hssia;
1444
1445 val32 &= ~FPGA0_HSSI_PARM2_ADDR_MASK;
1446 val32 |= (reg << FPGA0_HSSI_PARM2_ADDR_SHIFT);
1447 val32 |= FPGA0_HSSI_PARM2_EDGE_READ;
1448 hssia &= ~FPGA0_HSSI_PARM2_EDGE_READ;
1449 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1450
1451 udelay(10);
1452
1453 rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].hssiparm2, val32);
1454 udelay(100);
1455
1456 hssia |= FPGA0_HSSI_PARM2_EDGE_READ;
1457 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1458 udelay(10);
1459
1460 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm1);
1461 if (val32 & FPGA0_HSSI_PARM1_PI)
1462 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hspiread);
1463 else
1464 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].lssiread);
1465
1466 retval &= 0xfffff;
1467
1468 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_READ)
1469 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1470 __func__, reg, retval);
1471 return retval;
1472}
1473
Jes Sorensen22a31d42016-02-29 17:04:15 -05001474/*
1475 * The RTL8723BU driver indicates that registers 0xb2 and 0xb6 can
1476 * have write issues in high temperature conditions. We may have to
1477 * retry writing them.
1478 */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001479static int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv *priv,
1480 enum rtl8xxxu_rfpath path, u8 reg, u32 data)
1481{
1482 int ret, retval;
1483 u32 dataaddr;
1484
1485 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_WRITE)
1486 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1487 __func__, reg, data);
1488
1489 data &= FPGA0_LSSI_PARM_DATA_MASK;
1490 dataaddr = (reg << FPGA0_LSSI_PARM_ADDR_SHIFT) | data;
1491
1492 /* Use XB for path B */
1493 ret = rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].lssiparm, dataaddr);
1494 if (ret != sizeof(dataaddr))
1495 retval = -EIO;
1496 else
1497 retval = 0;
1498
1499 udelay(1);
1500
1501 return retval;
1502}
1503
Jes Sorensen8da91572016-02-29 17:04:29 -05001504static int rtl8723a_h2c_cmd(struct rtl8xxxu_priv *priv,
1505 struct h2c_cmd *h2c, int len)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001506{
1507 struct device *dev = &priv->udev->dev;
1508 int mbox_nr, retry, retval = 0;
1509 int mbox_reg, mbox_ext_reg;
1510 u8 val8;
1511
1512 mutex_lock(&priv->h2c_mutex);
1513
1514 mbox_nr = priv->next_mbox;
1515 mbox_reg = REG_HMBOX_0 + (mbox_nr * 4);
Jes Sorensened35d092016-02-29 17:04:19 -05001516 mbox_ext_reg = priv->fops->mbox_ext_reg +
1517 (mbox_nr * priv->fops->mbox_ext_width);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001518
1519 /*
1520 * MBOX ready?
1521 */
1522 retry = 100;
1523 do {
1524 val8 = rtl8xxxu_read8(priv, REG_HMTFR);
1525 if (!(val8 & BIT(mbox_nr)))
1526 break;
1527 } while (retry--);
1528
1529 if (!retry) {
Jes Sorensenc7a5a192016-02-29 17:04:30 -05001530 dev_info(dev, "%s: Mailbox busy\n", __func__);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001531 retval = -EBUSY;
1532 goto error;
1533 }
1534
1535 /*
1536 * Need to swap as it's being swapped again by rtl8xxxu_write16/32()
1537 */
Jes Sorensen8da91572016-02-29 17:04:29 -05001538 if (len > sizeof(u32)) {
Jes Sorensened35d092016-02-29 17:04:19 -05001539 if (priv->fops->mbox_ext_width == 4) {
1540 rtl8xxxu_write32(priv, mbox_ext_reg,
1541 le32_to_cpu(h2c->raw_wide.ext));
1542 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1543 dev_info(dev, "H2C_EXT %08x\n",
1544 le32_to_cpu(h2c->raw_wide.ext));
1545 } else {
1546 rtl8xxxu_write16(priv, mbox_ext_reg,
1547 le16_to_cpu(h2c->raw.ext));
1548 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1549 dev_info(dev, "H2C_EXT %04x\n",
1550 le16_to_cpu(h2c->raw.ext));
1551 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001552 }
1553 rtl8xxxu_write32(priv, mbox_reg, le32_to_cpu(h2c->raw.data));
1554 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1555 dev_info(dev, "H2C %08x\n", le32_to_cpu(h2c->raw.data));
1556
1557 priv->next_mbox = (mbox_nr + 1) % H2C_MAX_MBOX;
1558
1559error:
1560 mutex_unlock(&priv->h2c_mutex);
1561 return retval;
1562}
1563
Jes Sorensen394f1bd2016-02-29 17:04:49 -05001564static void rtl8723bu_write_btreg(struct rtl8xxxu_priv *priv, u8 reg, u8 data)
1565{
1566 struct h2c_cmd h2c;
1567 int reqnum = 0;
1568
1569 memset(&h2c, 0, sizeof(struct h2c_cmd));
1570 h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER;
1571 h2c.bt_mp_oper.operreq = 0 | (reqnum << 4);
1572 h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE;
1573 h2c.bt_mp_oper.data = data;
1574 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper));
1575
1576 reqnum++;
1577 memset(&h2c, 0, sizeof(struct h2c_cmd));
1578 h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER;
1579 h2c.bt_mp_oper.operreq = 0 | (reqnum << 4);
1580 h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE;
1581 h2c.bt_mp_oper.addr = reg;
1582 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper));
1583}
1584
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001585static void rtl8723a_enable_rf(struct rtl8xxxu_priv *priv)
1586{
1587 u8 val8;
1588 u32 val32;
1589
1590 val8 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
1591 val8 |= BIT(0) | BIT(3);
1592 rtl8xxxu_write8(priv, REG_SPS0_CTRL, val8);
1593
1594 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
1595 val32 &= ~(BIT(4) | BIT(5));
1596 val32 |= BIT(3);
1597 if (priv->rf_paths == 2) {
1598 val32 &= ~(BIT(20) | BIT(21));
1599 val32 |= BIT(19);
1600 }
1601 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
1602
1603 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
1604 val32 &= ~OFDM_RF_PATH_TX_MASK;
1605 if (priv->tx_paths == 2)
1606 val32 |= OFDM_RF_PATH_TX_A | OFDM_RF_PATH_TX_B;
Jes Sorensenba17d822016-03-31 17:08:39 -04001607 else if (priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001608 val32 |= OFDM_RF_PATH_TX_B;
1609 else
1610 val32 |= OFDM_RF_PATH_TX_A;
1611 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
1612
1613 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1614 val32 &= ~FPGA_RF_MODE_JAPAN;
1615 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1616
1617 if (priv->rf_paths == 2)
1618 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x63db25a0);
1619 else
1620 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x631b25a0);
1621
1622 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x32d95);
1623 if (priv->rf_paths == 2)
1624 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x32d95);
1625
1626 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
1627}
1628
1629static void rtl8723a_disable_rf(struct rtl8xxxu_priv *priv)
1630{
1631 u8 sps0;
1632 u32 val32;
1633
1634 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
1635
1636 sps0 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
1637
1638 /* RF RX code for preamble power saving */
1639 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
1640 val32 &= ~(BIT(3) | BIT(4) | BIT(5));
1641 if (priv->rf_paths == 2)
1642 val32 &= ~(BIT(19) | BIT(20) | BIT(21));
1643 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
1644
1645 /* Disable TX for four paths */
1646 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
1647 val32 &= ~OFDM_RF_PATH_TX_MASK;
1648 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
1649
1650 /* Enable power saving */
1651 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1652 val32 |= FPGA_RF_MODE_JAPAN;
1653 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1654
1655 /* AFE control register to power down bits [30:22] */
1656 if (priv->rf_paths == 2)
1657 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x00db25a0);
1658 else
1659 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x001b25a0);
1660
1661 /* Power down RF module */
1662 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0);
1663 if (priv->rf_paths == 2)
1664 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0);
1665
1666 sps0 &= ~(BIT(0) | BIT(3));
1667 rtl8xxxu_write8(priv, REG_SPS0_CTRL, sps0);
1668}
1669
1670
1671static void rtl8723a_stop_tx_beacon(struct rtl8xxxu_priv *priv)
1672{
1673 u8 val8;
1674
1675 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL + 2);
1676 val8 &= ~BIT(6);
1677 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8);
1678
1679 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x64);
1680 val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
1681 val8 &= ~BIT(0);
1682 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8);
1683}
1684
1685
1686/*
1687 * The rtl8723a has 3 channel groups for it's efuse settings. It only
1688 * supports the 2.4GHz band, so channels 1 - 14:
1689 * group 0: channels 1 - 3
1690 * group 1: channels 4 - 9
1691 * group 2: channels 10 - 14
1692 *
1693 * Note: We index from 0 in the code
1694 */
1695static int rtl8723a_channel_to_group(int channel)
1696{
1697 int group;
1698
1699 if (channel < 4)
1700 group = 0;
1701 else if (channel < 10)
1702 group = 1;
1703 else
1704 group = 2;
1705
1706 return group;
1707}
1708
Jes Sorensene796dab2016-02-29 17:05:19 -05001709static int rtl8723b_channel_to_group(int channel)
1710{
1711 int group;
1712
1713 if (channel < 3)
1714 group = 0;
1715 else if (channel < 6)
1716 group = 1;
1717 else if (channel < 9)
1718 group = 2;
1719 else if (channel < 12)
1720 group = 3;
1721 else
1722 group = 4;
1723
1724 return group;
1725}
1726
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001727static void rtl8723au_config_channel(struct ieee80211_hw *hw)
1728{
1729 struct rtl8xxxu_priv *priv = hw->priv;
1730 u32 val32, rsr;
1731 u8 val8, opmode;
1732 bool ht = true;
1733 int sec_ch_above, channel;
1734 int i;
1735
1736 opmode = rtl8xxxu_read8(priv, REG_BW_OPMODE);
1737 rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
1738 channel = hw->conf.chandef.chan->hw_value;
1739
1740 switch (hw->conf.chandef.width) {
1741 case NL80211_CHAN_WIDTH_20_NOHT:
1742 ht = false;
1743 case NL80211_CHAN_WIDTH_20:
1744 opmode |= BW_OPMODE_20MHZ;
1745 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
1746
1747 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1748 val32 &= ~FPGA_RF_MODE;
1749 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1750
1751 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1752 val32 &= ~FPGA_RF_MODE;
1753 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1754
1755 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
1756 val32 |= FPGA0_ANALOG2_20MHZ;
1757 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
1758 break;
1759 case NL80211_CHAN_WIDTH_40:
1760 if (hw->conf.chandef.center_freq1 >
1761 hw->conf.chandef.chan->center_freq) {
1762 sec_ch_above = 1;
1763 channel += 2;
1764 } else {
1765 sec_ch_above = 0;
1766 channel -= 2;
1767 }
1768
1769 opmode &= ~BW_OPMODE_20MHZ;
1770 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
1771 rsr &= ~RSR_RSC_BANDWIDTH_40M;
1772 if (sec_ch_above)
1773 rsr |= RSR_RSC_UPPER_SUB_CHANNEL;
1774 else
1775 rsr |= RSR_RSC_LOWER_SUB_CHANNEL;
1776 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, rsr);
1777
1778 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1779 val32 |= FPGA_RF_MODE;
1780 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1781
1782 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1783 val32 |= FPGA_RF_MODE;
1784 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1785
1786 /*
1787 * Set Control channel to upper or lower. These settings
1788 * are required only for 40MHz
1789 */
1790 val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
1791 val32 &= ~CCK0_SIDEBAND;
1792 if (!sec_ch_above)
1793 val32 |= CCK0_SIDEBAND;
1794 rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
1795
1796 val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
1797 val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
1798 if (sec_ch_above)
1799 val32 |= OFDM_LSTF_PRIME_CH_LOW;
1800 else
1801 val32 |= OFDM_LSTF_PRIME_CH_HIGH;
1802 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
1803
1804 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
1805 val32 &= ~FPGA0_ANALOG2_20MHZ;
1806 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
1807
1808 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
1809 val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
1810 if (sec_ch_above)
1811 val32 |= FPGA0_PS_UPPER_CHANNEL;
1812 else
1813 val32 |= FPGA0_PS_LOWER_CHANNEL;
1814 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
1815 break;
1816
1817 default:
1818 break;
1819 }
1820
1821 for (i = RF_A; i < priv->rf_paths; i++) {
1822 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1823 val32 &= ~MODE_AG_CHANNEL_MASK;
1824 val32 |= channel;
1825 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1826 }
1827
1828 if (ht)
1829 val8 = 0x0e;
1830 else
1831 val8 = 0x0a;
1832
1833 rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8);
1834 rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8);
1835
1836 rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808);
1837 rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a);
1838
1839 for (i = RF_A; i < priv->rf_paths; i++) {
1840 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1841 if (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40)
1842 val32 &= ~MODE_AG_CHANNEL_20MHZ;
1843 else
1844 val32 |= MODE_AG_CHANNEL_20MHZ;
1845 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1846 }
1847}
1848
Jes Sorensenc3f95062016-02-29 17:04:40 -05001849static void rtl8723bu_config_channel(struct ieee80211_hw *hw)
1850{
1851 struct rtl8xxxu_priv *priv = hw->priv;
1852 u32 val32, rsr;
Jes Sorensen368633c2016-02-29 17:04:42 -05001853 u8 val8, subchannel;
Jes Sorensenc3f95062016-02-29 17:04:40 -05001854 u16 rf_mode_bw;
1855 bool ht = true;
1856 int sec_ch_above, channel;
1857 int i;
1858
1859 rf_mode_bw = rtl8xxxu_read16(priv, REG_WMAC_TRXPTCL_CTL);
1860 rf_mode_bw &= ~WMAC_TRXPTCL_CTL_BW_MASK;
1861 rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
1862 channel = hw->conf.chandef.chan->hw_value;
1863
1864/* Hack */
1865 subchannel = 0;
1866
1867 switch (hw->conf.chandef.width) {
1868 case NL80211_CHAN_WIDTH_20_NOHT:
1869 ht = false;
1870 case NL80211_CHAN_WIDTH_20:
1871 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_20;
1872 subchannel = 0;
1873
1874 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1875 val32 &= ~FPGA_RF_MODE;
1876 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1877
1878 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1879 val32 &= ~FPGA_RF_MODE;
1880 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1881
1882 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TX_PSDO_NOISE_WEIGHT);
1883 val32 &= ~(BIT(30) | BIT(31));
1884 rtl8xxxu_write32(priv, REG_OFDM0_TX_PSDO_NOISE_WEIGHT, val32);
1885
1886 break;
1887 case NL80211_CHAN_WIDTH_40:
1888 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_40;
1889
1890 if (hw->conf.chandef.center_freq1 >
1891 hw->conf.chandef.chan->center_freq) {
1892 sec_ch_above = 1;
1893 channel += 2;
1894 } else {
1895 sec_ch_above = 0;
1896 channel -= 2;
1897 }
1898
1899 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1900 val32 |= FPGA_RF_MODE;
1901 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1902
1903 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1904 val32 |= FPGA_RF_MODE;
1905 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1906
1907 /*
1908 * Set Control channel to upper or lower. These settings
1909 * are required only for 40MHz
1910 */
1911 val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
1912 val32 &= ~CCK0_SIDEBAND;
1913 if (!sec_ch_above)
1914 val32 |= CCK0_SIDEBAND;
1915 rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
1916
1917 val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
1918 val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
1919 if (sec_ch_above)
1920 val32 |= OFDM_LSTF_PRIME_CH_LOW;
1921 else
1922 val32 |= OFDM_LSTF_PRIME_CH_HIGH;
1923 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
1924
1925 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
1926 val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
1927 if (sec_ch_above)
1928 val32 |= FPGA0_PS_UPPER_CHANNEL;
1929 else
1930 val32 |= FPGA0_PS_LOWER_CHANNEL;
1931 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
1932 break;
1933 case NL80211_CHAN_WIDTH_80:
1934 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_80;
1935 break;
1936 default:
1937 break;
1938 }
1939
1940 for (i = RF_A; i < priv->rf_paths; i++) {
1941 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1942 val32 &= ~MODE_AG_CHANNEL_MASK;
1943 val32 |= channel;
1944 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1945 }
1946
1947 rtl8xxxu_write16(priv, REG_WMAC_TRXPTCL_CTL, rf_mode_bw);
1948 rtl8xxxu_write8(priv, REG_DATA_SUBCHANNEL, subchannel);
1949
1950 if (ht)
1951 val8 = 0x0e;
1952 else
1953 val8 = 0x0a;
1954
1955 rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8);
1956 rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8);
1957
1958 rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808);
1959 rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a);
1960
1961 for (i = RF_A; i < priv->rf_paths; i++) {
1962 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1963 val32 &= ~MODE_AG_BW_MASK;
1964 switch(hw->conf.chandef.width) {
1965 case NL80211_CHAN_WIDTH_80:
1966 val32 |= MODE_AG_BW_80MHZ_8723B;
1967 break;
1968 case NL80211_CHAN_WIDTH_40:
1969 val32 |= MODE_AG_BW_40MHZ_8723B;
1970 break;
1971 default:
1972 val32 |= MODE_AG_BW_20MHZ_8723B;
1973 break;
1974 }
1975 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1976 }
1977}
1978
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001979static void
1980rtl8723a_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
1981{
1982 u8 cck[RTL8723A_MAX_RF_PATHS], ofdm[RTL8723A_MAX_RF_PATHS];
1983 u8 ofdmbase[RTL8723A_MAX_RF_PATHS], mcsbase[RTL8723A_MAX_RF_PATHS];
1984 u32 val32, ofdm_a, ofdm_b, mcs_a, mcs_b;
1985 u8 val8;
1986 int group, i;
1987
1988 group = rtl8723a_channel_to_group(channel);
1989
1990 cck[0] = priv->cck_tx_power_index_A[group];
1991 cck[1] = priv->cck_tx_power_index_B[group];
1992
1993 ofdm[0] = priv->ht40_1s_tx_power_index_A[group];
1994 ofdm[1] = priv->ht40_1s_tx_power_index_B[group];
1995
1996 ofdmbase[0] = ofdm[0] + priv->ofdm_tx_power_index_diff[group].a;
1997 ofdmbase[1] = ofdm[1] + priv->ofdm_tx_power_index_diff[group].b;
1998
1999 mcsbase[0] = ofdm[0];
2000 mcsbase[1] = ofdm[1];
2001 if (!ht40) {
2002 mcsbase[0] += priv->ht20_tx_power_index_diff[group].a;
2003 mcsbase[1] += priv->ht20_tx_power_index_diff[group].b;
2004 }
2005
2006 if (priv->tx_paths > 1) {
2007 if (ofdm[0] > priv->ht40_2s_tx_power_index_diff[group].a)
2008 ofdm[0] -= priv->ht40_2s_tx_power_index_diff[group].a;
2009 if (ofdm[1] > priv->ht40_2s_tx_power_index_diff[group].b)
2010 ofdm[1] -= priv->ht40_2s_tx_power_index_diff[group].b;
2011 }
2012
2013 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
2014 dev_info(&priv->udev->dev,
2015 "%s: Setting TX power CCK A: %02x, "
2016 "CCK B: %02x, OFDM A: %02x, OFDM B: %02x\n",
2017 __func__, cck[0], cck[1], ofdm[0], ofdm[1]);
2018
2019 for (i = 0; i < RTL8723A_MAX_RF_PATHS; i++) {
2020 if (cck[i] > RF6052_MAX_TX_PWR)
2021 cck[i] = RF6052_MAX_TX_PWR;
2022 if (ofdm[i] > RF6052_MAX_TX_PWR)
2023 ofdm[i] = RF6052_MAX_TX_PWR;
2024 }
2025
2026 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
2027 val32 &= 0xffff00ff;
2028 val32 |= (cck[0] << 8);
2029 rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
2030
2031 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
2032 val32 &= 0xff;
2033 val32 |= ((cck[0] << 8) | (cck[0] << 16) | (cck[0] << 24));
2034 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
2035
2036 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
2037 val32 &= 0xffffff00;
2038 val32 |= cck[1];
2039 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
2040
2041 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK1_55_MCS32);
2042 val32 &= 0xff;
2043 val32 |= ((cck[1] << 8) | (cck[1] << 16) | (cck[1] << 24));
2044 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK1_55_MCS32, val32);
2045
2046 ofdm_a = ofdmbase[0] | ofdmbase[0] << 8 |
2047 ofdmbase[0] << 16 | ofdmbase[0] << 24;
2048 ofdm_b = ofdmbase[1] | ofdmbase[1] << 8 |
2049 ofdmbase[1] << 16 | ofdmbase[1] << 24;
2050 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm_a);
2051 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE18_06, ofdm_b);
2052
2053 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm_a);
2054 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE54_24, ofdm_b);
2055
2056 mcs_a = mcsbase[0] | mcsbase[0] << 8 |
2057 mcsbase[0] << 16 | mcsbase[0] << 24;
2058 mcs_b = mcsbase[1] | mcsbase[1] << 8 |
2059 mcsbase[1] << 16 | mcsbase[1] << 24;
2060
2061 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs_a);
2062 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS03_MCS00, mcs_b);
2063
2064 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs_a);
2065 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS07_MCS04, mcs_b);
2066
2067 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS11_MCS08, mcs_a);
2068 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS11_MCS08, mcs_b);
2069
2070 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12, mcs_a);
2071 for (i = 0; i < 3; i++) {
2072 if (i != 2)
2073 val8 = (mcsbase[0] > 8) ? (mcsbase[0] - 8) : 0;
2074 else
2075 val8 = (mcsbase[0] > 6) ? (mcsbase[0] - 6) : 0;
2076 rtl8xxxu_write8(priv, REG_OFDM0_XC_TX_IQ_IMBALANCE + i, val8);
2077 }
2078 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12, mcs_b);
2079 for (i = 0; i < 3; i++) {
2080 if (i != 2)
2081 val8 = (mcsbase[1] > 8) ? (mcsbase[1] - 8) : 0;
2082 else
2083 val8 = (mcsbase[1] > 6) ? (mcsbase[1] - 6) : 0;
2084 rtl8xxxu_write8(priv, REG_OFDM0_XD_TX_IQ_IMBALANCE + i, val8);
2085 }
2086}
2087
Jes Sorensene796dab2016-02-29 17:05:19 -05002088static void
2089rtl8723b_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
2090{
Jes Sorensen1d3cc442016-02-29 17:05:24 -05002091 u32 val32, ofdm, mcs;
2092 u8 cck, ofdmbase, mcsbase;
Jes Sorensen54bed432016-02-29 17:05:23 -05002093 int group, tx_idx;
Jes Sorensene796dab2016-02-29 17:05:19 -05002094
Jes Sorensen54bed432016-02-29 17:05:23 -05002095 tx_idx = 0;
Jes Sorensene796dab2016-02-29 17:05:19 -05002096 group = rtl8723b_channel_to_group(channel);
Jes Sorensen54bed432016-02-29 17:05:23 -05002097
2098 cck = priv->cck_tx_power_index_B[group];
2099 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
2100 val32 &= 0xffff00ff;
2101 val32 |= (cck << 8);
2102 rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
2103
2104 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
2105 val32 &= 0xff;
2106 val32 |= ((cck << 8) | (cck << 16) | (cck << 24));
2107 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
2108
2109 ofdmbase = priv->ht40_1s_tx_power_index_B[group];
2110 ofdmbase += priv->ofdm_tx_power_diff[tx_idx].b;
2111 ofdm = ofdmbase | ofdmbase << 8 | ofdmbase << 16 | ofdmbase << 24;
2112
2113 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm);
2114 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm);
Jes Sorensen1d3cc442016-02-29 17:05:24 -05002115
2116 mcsbase = priv->ht40_1s_tx_power_index_B[group];
2117 if (ht40)
2118 mcsbase += priv->ht40_tx_power_diff[tx_idx++].b;
2119 else
2120 mcsbase += priv->ht20_tx_power_diff[tx_idx++].b;
2121 mcs = mcsbase | mcsbase << 8 | mcsbase << 16 | mcsbase << 24;
2122
2123 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs);
2124 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs);
Jes Sorensene796dab2016-02-29 17:05:19 -05002125}
2126
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002127static void rtl8xxxu_set_linktype(struct rtl8xxxu_priv *priv,
2128 enum nl80211_iftype linktype)
2129{
Jes Sorensena26703f2016-02-03 13:39:56 -05002130 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002131
Jes Sorensena26703f2016-02-03 13:39:56 -05002132 val8 = rtl8xxxu_read8(priv, REG_MSR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002133 val8 &= ~MSR_LINKTYPE_MASK;
2134
2135 switch (linktype) {
2136 case NL80211_IFTYPE_UNSPECIFIED:
2137 val8 |= MSR_LINKTYPE_NONE;
2138 break;
2139 case NL80211_IFTYPE_ADHOC:
2140 val8 |= MSR_LINKTYPE_ADHOC;
2141 break;
2142 case NL80211_IFTYPE_STATION:
2143 val8 |= MSR_LINKTYPE_STATION;
2144 break;
2145 case NL80211_IFTYPE_AP:
2146 val8 |= MSR_LINKTYPE_AP;
2147 break;
2148 default:
2149 goto out;
2150 }
2151
2152 rtl8xxxu_write8(priv, REG_MSR, val8);
2153out:
2154 return;
2155}
2156
2157static void
2158rtl8xxxu_set_retry(struct rtl8xxxu_priv *priv, u16 short_retry, u16 long_retry)
2159{
2160 u16 val16;
2161
2162 val16 = ((short_retry << RETRY_LIMIT_SHORT_SHIFT) &
2163 RETRY_LIMIT_SHORT_MASK) |
2164 ((long_retry << RETRY_LIMIT_LONG_SHIFT) &
2165 RETRY_LIMIT_LONG_MASK);
2166
2167 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
2168}
2169
2170static void
2171rtl8xxxu_set_spec_sifs(struct rtl8xxxu_priv *priv, u16 cck, u16 ofdm)
2172{
2173 u16 val16;
2174
2175 val16 = ((cck << SPEC_SIFS_CCK_SHIFT) & SPEC_SIFS_CCK_MASK) |
2176 ((ofdm << SPEC_SIFS_OFDM_SHIFT) & SPEC_SIFS_OFDM_MASK);
2177
2178 rtl8xxxu_write16(priv, REG_SPEC_SIFS, val16);
2179}
2180
2181static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv)
2182{
2183 struct device *dev = &priv->udev->dev;
2184 char *cut;
2185
2186 switch (priv->chip_cut) {
2187 case 0:
2188 cut = "A";
2189 break;
2190 case 1:
2191 cut = "B";
2192 break;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002193 case 2:
2194 cut = "C";
2195 break;
2196 case 3:
2197 cut = "D";
2198 break;
2199 case 4:
2200 cut = "E";
2201 break;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002202 default:
2203 cut = "unknown";
2204 }
2205
2206 dev_info(dev,
2207 "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 -05002208 priv->chip_name, cut, priv->chip_vendor, priv->tx_paths,
2209 priv->rx_paths, priv->ep_tx_count, priv->has_wifi,
2210 priv->has_bluetooth, priv->has_gps, priv->hi_pa);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002211
2212 dev_info(dev, "RTL%s MAC: %pM\n", priv->chip_name, priv->mac_addr);
2213}
2214
2215static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
2216{
2217 struct device *dev = &priv->udev->dev;
2218 u32 val32, bonding;
2219 u16 val16;
2220
2221 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
2222 priv->chip_cut = (val32 & SYS_CFG_CHIP_VERSION_MASK) >>
2223 SYS_CFG_CHIP_VERSION_SHIFT;
2224 if (val32 & SYS_CFG_TRP_VAUX_EN) {
2225 dev_info(dev, "Unsupported test chip\n");
2226 return -ENOTSUPP;
2227 }
2228
2229 if (val32 & SYS_CFG_BT_FUNC) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05002230 if (priv->chip_cut >= 3) {
2231 sprintf(priv->chip_name, "8723BU");
Jes Sorensenba17d822016-03-31 17:08:39 -04002232 priv->rtl_chip = RTL8723B;
Jes Sorensen35a741f2016-02-29 17:04:10 -05002233 } else {
2234 sprintf(priv->chip_name, "8723AU");
Jes Sorensen0e28b972016-02-29 17:04:13 -05002235 priv->usb_interrupts = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002236 priv->rtl_chip = RTL8723A;
Jes Sorensen35a741f2016-02-29 17:04:10 -05002237 }
2238
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002239 priv->rf_paths = 1;
2240 priv->rx_paths = 1;
2241 priv->tx_paths = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002242
2243 val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL);
2244 if (val32 & MULTI_WIFI_FUNC_EN)
2245 priv->has_wifi = 1;
2246 if (val32 & MULTI_BT_FUNC_EN)
2247 priv->has_bluetooth = 1;
2248 if (val32 & MULTI_GPS_FUNC_EN)
2249 priv->has_gps = 1;
Jakub Sitnicki38451992016-02-03 13:39:49 -05002250 priv->is_multi_func = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002251 } else if (val32 & SYS_CFG_TYPE_ID) {
2252 bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
2253 bonding &= HPON_FSM_BONDING_MASK;
Jes Sorensenaf13faf2016-03-31 17:08:40 -04002254 if (priv->fops->has_s0s1) {
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002255 if (bonding == HPON_FSM_BONDING_1T2R) {
2256 sprintf(priv->chip_name, "8191EU");
2257 priv->rf_paths = 2;
2258 priv->rx_paths = 2;
2259 priv->tx_paths = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002260 priv->rtl_chip = RTL8191E;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002261 } else {
2262 sprintf(priv->chip_name, "8192EU");
2263 priv->rf_paths = 2;
2264 priv->rx_paths = 2;
2265 priv->tx_paths = 2;
Jes Sorensenba17d822016-03-31 17:08:39 -04002266 priv->rtl_chip = RTL8192E;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002267 }
2268 } else if (bonding == HPON_FSM_BONDING_1T2R) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002269 sprintf(priv->chip_name, "8191CU");
2270 priv->rf_paths = 2;
2271 priv->rx_paths = 2;
2272 priv->tx_paths = 1;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002273 priv->usb_interrupts = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002274 priv->rtl_chip = RTL8191C;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002275 } else {
2276 sprintf(priv->chip_name, "8192CU");
2277 priv->rf_paths = 2;
2278 priv->rx_paths = 2;
2279 priv->tx_paths = 2;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002280 priv->usb_interrupts = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002281 priv->rtl_chip = RTL8192C;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002282 }
2283 priv->has_wifi = 1;
2284 } else {
2285 sprintf(priv->chip_name, "8188CU");
2286 priv->rf_paths = 1;
2287 priv->rx_paths = 1;
2288 priv->tx_paths = 1;
Jes Sorensenba17d822016-03-31 17:08:39 -04002289 priv->rtl_chip = RTL8188C;
Jes Sorensen0e28b972016-02-29 17:04:13 -05002290 priv->usb_interrupts = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002291 priv->has_wifi = 1;
2292 }
2293
Jes Sorensenba17d822016-03-31 17:08:39 -04002294 switch (priv->rtl_chip) {
2295 case RTL8188E:
2296 case RTL8192E:
2297 case RTL8723B:
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002298 switch (val32 & SYS_CFG_VENDOR_EXT_MASK) {
2299 case SYS_CFG_VENDOR_ID_TSMC:
2300 sprintf(priv->chip_vendor, "TSMC");
2301 break;
2302 case SYS_CFG_VENDOR_ID_SMIC:
2303 sprintf(priv->chip_vendor, "SMIC");
2304 priv->vendor_smic = 1;
2305 break;
2306 case SYS_CFG_VENDOR_ID_UMC:
2307 sprintf(priv->chip_vendor, "UMC");
2308 priv->vendor_umc = 1;
2309 break;
2310 default:
2311 sprintf(priv->chip_vendor, "unknown");
2312 }
2313 break;
2314 default:
2315 if (val32 & SYS_CFG_VENDOR_ID) {
2316 sprintf(priv->chip_vendor, "UMC");
2317 priv->vendor_umc = 1;
2318 } else {
2319 sprintf(priv->chip_vendor, "TSMC");
2320 }
2321 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002322
2323 val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
2324 priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;
2325
2326 val16 = rtl8xxxu_read16(priv, REG_NORMAL_SIE_EP_TX);
2327 if (val16 & NORMAL_SIE_EP_TX_HIGH_MASK) {
2328 priv->ep_tx_high_queue = 1;
2329 priv->ep_tx_count++;
2330 }
2331
2332 if (val16 & NORMAL_SIE_EP_TX_NORMAL_MASK) {
2333 priv->ep_tx_normal_queue = 1;
2334 priv->ep_tx_count++;
2335 }
2336
2337 if (val16 & NORMAL_SIE_EP_TX_LOW_MASK) {
2338 priv->ep_tx_low_queue = 1;
2339 priv->ep_tx_count++;
2340 }
2341
2342 /*
2343 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
2344 */
2345 if (!priv->ep_tx_count) {
2346 switch (priv->nr_out_eps) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05002347 case 4:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002348 case 3:
2349 priv->ep_tx_low_queue = 1;
2350 priv->ep_tx_count++;
2351 case 2:
2352 priv->ep_tx_normal_queue = 1;
2353 priv->ep_tx_count++;
2354 case 1:
2355 priv->ep_tx_high_queue = 1;
2356 priv->ep_tx_count++;
2357 break;
2358 default:
2359 dev_info(dev, "Unsupported USB TX end-points\n");
2360 return -ENOTSUPP;
2361 }
2362 }
2363
2364 return 0;
2365}
2366
2367static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv)
2368{
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002369 struct rtl8723au_efuse *efuse = &priv->efuse_wifi.efuse8723;
2370
2371 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002372 return -EINVAL;
2373
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002374 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002375
2376 memcpy(priv->cck_tx_power_index_A,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002377 efuse->cck_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002378 sizeof(efuse->cck_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002379 memcpy(priv->cck_tx_power_index_B,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002380 efuse->cck_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002381 sizeof(efuse->cck_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002382
2383 memcpy(priv->ht40_1s_tx_power_index_A,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002384 efuse->ht40_1s_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002385 sizeof(efuse->ht40_1s_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002386 memcpy(priv->ht40_1s_tx_power_index_B,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002387 efuse->ht40_1s_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002388 sizeof(efuse->ht40_1s_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002389
2390 memcpy(priv->ht20_tx_power_index_diff,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002391 efuse->ht20_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002392 sizeof(efuse->ht20_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002393 memcpy(priv->ofdm_tx_power_index_diff,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002394 efuse->ofdm_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002395 sizeof(efuse->ofdm_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002396
2397 memcpy(priv->ht40_max_power_offset,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002398 efuse->ht40_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002399 sizeof(efuse->ht40_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002400 memcpy(priv->ht20_max_power_offset,
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002401 efuse->ht20_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002402 sizeof(efuse->ht20_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002403
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05002404 if (priv->efuse_wifi.efuse8723.version >= 0x01) {
2405 priv->has_xtalk = 1;
2406 priv->xtalk = priv->efuse_wifi.efuse8723.xtal_k & 0x3f;
2407 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002408 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002409 efuse->vendor_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002410 dev_info(&priv->udev->dev, "Product: %.41s\n",
Jakub Sitnickid38f1c32016-02-29 17:04:25 -05002411 efuse->device_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002412 return 0;
2413}
2414
Jes Sorensen3c836d62016-02-29 17:04:11 -05002415static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv)
2416{
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002417 struct rtl8723bu_efuse *efuse = &priv->efuse_wifi.efuse8723bu;
Jes Sorensen3be26992016-02-29 17:05:22 -05002418 int i;
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002419
2420 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen3c836d62016-02-29 17:04:11 -05002421 return -EINVAL;
2422
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002423 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen3c836d62016-02-29 17:04:11 -05002424
Jes Sorensen3be26992016-02-29 17:05:22 -05002425 memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base,
2426 sizeof(efuse->tx_power_index_A.cck_base));
2427 memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base,
2428 sizeof(efuse->tx_power_index_B.cck_base));
2429
2430 memcpy(priv->ht40_1s_tx_power_index_A,
2431 efuse->tx_power_index_A.ht40_base,
2432 sizeof(efuse->tx_power_index_A.ht40_base));
2433 memcpy(priv->ht40_1s_tx_power_index_B,
2434 efuse->tx_power_index_B.ht40_base,
2435 sizeof(efuse->tx_power_index_B.ht40_base));
2436
2437 priv->ofdm_tx_power_diff[0].a =
2438 efuse->tx_power_index_A.ht20_ofdm_1s_diff.a;
2439 priv->ofdm_tx_power_diff[0].b =
2440 efuse->tx_power_index_B.ht20_ofdm_1s_diff.a;
2441
2442 priv->ht20_tx_power_diff[0].a =
2443 efuse->tx_power_index_A.ht20_ofdm_1s_diff.b;
2444 priv->ht20_tx_power_diff[0].b =
2445 efuse->tx_power_index_B.ht20_ofdm_1s_diff.b;
2446
2447 priv->ht40_tx_power_diff[0].a = 0;
2448 priv->ht40_tx_power_diff[0].b = 0;
2449
2450 for (i = 1; i < RTL8723B_TX_COUNT; i++) {
2451 priv->ofdm_tx_power_diff[i].a =
2452 efuse->tx_power_index_A.pwr_diff[i - 1].ofdm;
2453 priv->ofdm_tx_power_diff[i].b =
2454 efuse->tx_power_index_B.pwr_diff[i - 1].ofdm;
2455
2456 priv->ht20_tx_power_diff[i].a =
2457 efuse->tx_power_index_A.pwr_diff[i - 1].ht20;
2458 priv->ht20_tx_power_diff[i].b =
2459 efuse->tx_power_index_B.pwr_diff[i - 1].ht20;
2460
2461 priv->ht40_tx_power_diff[i].a =
2462 efuse->tx_power_index_A.pwr_diff[i - 1].ht40;
2463 priv->ht40_tx_power_diff[i].b =
2464 efuse->tx_power_index_B.pwr_diff[i - 1].ht40;
2465 }
2466
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05002467 priv->has_xtalk = 1;
2468 priv->xtalk = priv->efuse_wifi.efuse8723bu.xtal_k & 0x3f;
2469
Jes Sorensenb8ba8602016-02-29 17:04:28 -05002470 dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name);
2471 dev_info(&priv->udev->dev, "Product: %.41s\n", efuse->device_name);
Jes Sorensen3c836d62016-02-29 17:04:11 -05002472
2473 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2474 int i;
2475 unsigned char *raw = priv->efuse_wifi.raw;
2476
2477 dev_info(&priv->udev->dev,
2478 "%s: dumping efuse (0x%02zx bytes):\n",
2479 __func__, sizeof(struct rtl8723bu_efuse));
2480 for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8) {
2481 dev_info(&priv->udev->dev, "%02x: "
2482 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2483 raw[i], raw[i + 1], raw[i + 2],
2484 raw[i + 3], raw[i + 4], raw[i + 5],
2485 raw[i + 6], raw[i + 7]);
2486 }
2487 }
2488
2489 return 0;
2490}
2491
Kalle Valoc0963772015-10-25 18:24:38 +02002492#ifdef CONFIG_RTL8XXXU_UNTESTED
2493
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002494static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
2495{
Jakub Sitnicki49594442016-02-29 17:04:26 -05002496 struct rtl8192cu_efuse *efuse = &priv->efuse_wifi.efuse8192;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002497 int i;
2498
Jakub Sitnicki49594442016-02-29 17:04:26 -05002499 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002500 return -EINVAL;
2501
Jakub Sitnicki49594442016-02-29 17:04:26 -05002502 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002503
2504 memcpy(priv->cck_tx_power_index_A,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002505 efuse->cck_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002506 sizeof(efuse->cck_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002507 memcpy(priv->cck_tx_power_index_B,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002508 efuse->cck_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002509 sizeof(efuse->cck_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002510
2511 memcpy(priv->ht40_1s_tx_power_index_A,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002512 efuse->ht40_1s_tx_power_index_A,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002513 sizeof(efuse->ht40_1s_tx_power_index_A));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002514 memcpy(priv->ht40_1s_tx_power_index_B,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002515 efuse->ht40_1s_tx_power_index_B,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002516 sizeof(efuse->ht40_1s_tx_power_index_B));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002517 memcpy(priv->ht40_2s_tx_power_index_diff,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002518 efuse->ht40_2s_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002519 sizeof(efuse->ht40_2s_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002520
2521 memcpy(priv->ht20_tx_power_index_diff,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002522 efuse->ht20_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002523 sizeof(efuse->ht20_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002524 memcpy(priv->ofdm_tx_power_index_diff,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002525 efuse->ofdm_tx_power_index_diff,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002526 sizeof(efuse->ofdm_tx_power_index_diff));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002527
2528 memcpy(priv->ht40_max_power_offset,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002529 efuse->ht40_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002530 sizeof(efuse->ht40_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002531 memcpy(priv->ht20_max_power_offset,
Jakub Sitnicki49594442016-02-29 17:04:26 -05002532 efuse->ht20_max_power_offset,
Jes Sorensen3e84f932016-02-29 17:05:20 -05002533 sizeof(efuse->ht20_max_power_offset));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002534
2535 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
Jakub Sitnicki49594442016-02-29 17:04:26 -05002536 efuse->vendor_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002537 dev_info(&priv->udev->dev, "Product: %.20s\n",
Jakub Sitnicki49594442016-02-29 17:04:26 -05002538 efuse->device_name);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002539
Jakub Sitnicki49594442016-02-29 17:04:26 -05002540 if (efuse->rf_regulatory & 0x20) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002541 sprintf(priv->chip_name, "8188RU");
2542 priv->hi_pa = 1;
2543 }
2544
2545 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2546 unsigned char *raw = priv->efuse_wifi.raw;
2547
2548 dev_info(&priv->udev->dev,
2549 "%s: dumping efuse (0x%02zx bytes):\n",
2550 __func__, sizeof(struct rtl8192cu_efuse));
2551 for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8) {
2552 dev_info(&priv->udev->dev, "%02x: "
2553 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2554 raw[i], raw[i + 1], raw[i + 2],
2555 raw[i + 3], raw[i + 4], raw[i + 5],
2556 raw[i + 6], raw[i + 7]);
2557 }
2558 }
2559 return 0;
2560}
2561
Kalle Valoc0963772015-10-25 18:24:38 +02002562#endif
2563
Jes Sorensen3307d842016-02-29 17:03:59 -05002564static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
2565{
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05002566 struct rtl8192eu_efuse *efuse = &priv->efuse_wifi.efuse8192eu;
Jes Sorensen3307d842016-02-29 17:03:59 -05002567 int i;
2568
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05002569 if (efuse->rtl_id != cpu_to_le16(0x8129))
Jes Sorensen3307d842016-02-29 17:03:59 -05002570 return -EINVAL;
2571
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05002572 ether_addr_copy(priv->mac_addr, efuse->mac_addr);
Jes Sorensen3307d842016-02-29 17:03:59 -05002573
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05002574 priv->has_xtalk = 1;
2575 priv->xtalk = priv->efuse_wifi.efuse8192eu.xtal_k & 0x3f;
2576
Jes Sorensenb7dda34d2016-02-29 17:04:27 -05002577 dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name);
2578 dev_info(&priv->udev->dev, "Product: %.11s\n", efuse->device_name);
2579 dev_info(&priv->udev->dev, "Serial: %.11s\n", efuse->serial);
Jes Sorensen3307d842016-02-29 17:03:59 -05002580
2581 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2582 unsigned char *raw = priv->efuse_wifi.raw;
2583
2584 dev_info(&priv->udev->dev,
2585 "%s: dumping efuse (0x%02zx bytes):\n",
2586 __func__, sizeof(struct rtl8192eu_efuse));
2587 for (i = 0; i < sizeof(struct rtl8192eu_efuse); i += 8) {
2588 dev_info(&priv->udev->dev, "%02x: "
2589 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2590 raw[i], raw[i + 1], raw[i + 2],
2591 raw[i + 3], raw[i + 4], raw[i + 5],
2592 raw[i + 6], raw[i + 7]);
2593 }
2594 }
Jes Sorensenccfe1e82016-02-29 17:05:51 -05002595 /*
2596 * Temporarily disable 8192eu support
2597 */
2598 return -EINVAL;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002599 return 0;
Jes Sorensen3307d842016-02-29 17:03:59 -05002600}
2601
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002602static int
2603rtl8xxxu_read_efuse8(struct rtl8xxxu_priv *priv, u16 offset, u8 *data)
2604{
2605 int i;
2606 u8 val8;
2607 u32 val32;
2608
2609 /* Write Address */
2610 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 1, offset & 0xff);
2611 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 2);
2612 val8 &= 0xfc;
2613 val8 |= (offset >> 8) & 0x03;
2614 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 2, val8);
2615
2616 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 3);
2617 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 3, val8 & 0x7f);
2618
2619 /* Poll for data read */
2620 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2621 for (i = 0; i < RTL8XXXU_MAX_REG_POLL; i++) {
2622 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2623 if (val32 & BIT(31))
2624 break;
2625 }
2626
2627 if (i == RTL8XXXU_MAX_REG_POLL)
2628 return -EIO;
2629
2630 udelay(50);
2631 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2632
2633 *data = val32 & 0xff;
2634 return 0;
2635}
2636
2637static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv)
2638{
2639 struct device *dev = &priv->udev->dev;
2640 int i, ret = 0;
2641 u8 val8, word_mask, header, extheader;
2642 u16 val16, efuse_addr, offset;
2643 u32 val32;
2644
2645 val16 = rtl8xxxu_read16(priv, REG_9346CR);
2646 if (val16 & EEPROM_ENABLE)
2647 priv->has_eeprom = 1;
2648 if (val16 & EEPROM_BOOT)
2649 priv->boot_eeprom = 1;
2650
Jakub Sitnicki38451992016-02-03 13:39:49 -05002651 if (priv->is_multi_func) {
2652 val32 = rtl8xxxu_read32(priv, REG_EFUSE_TEST);
2653 val32 = (val32 & ~EFUSE_SELECT_MASK) | EFUSE_WIFI_SELECT;
2654 rtl8xxxu_write32(priv, REG_EFUSE_TEST, val32);
2655 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002656
2657 dev_dbg(dev, "Booting from %s\n",
2658 priv->boot_eeprom ? "EEPROM" : "EFUSE");
2659
2660 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_ENABLE);
2661
2662 /* 1.2V Power: From VDDON with Power Cut(0x0000[15]), default valid */
2663 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
2664 if (!(val16 & SYS_ISO_PWC_EV12V)) {
2665 val16 |= SYS_ISO_PWC_EV12V;
2666 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
2667 }
2668 /* Reset: 0x0000[28], default valid */
2669 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2670 if (!(val16 & SYS_FUNC_ELDR)) {
2671 val16 |= SYS_FUNC_ELDR;
2672 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
2673 }
2674
2675 /*
2676 * Clock: Gated(0x0008[5]) 8M(0x0008[1]) clock from ANA, default valid
2677 */
2678 val16 = rtl8xxxu_read16(priv, REG_SYS_CLKR);
2679 if (!(val16 & SYS_CLK_LOADER_ENABLE) || !(val16 & SYS_CLK_ANA8M)) {
2680 val16 |= (SYS_CLK_LOADER_ENABLE | SYS_CLK_ANA8M);
2681 rtl8xxxu_write16(priv, REG_SYS_CLKR, val16);
2682 }
2683
2684 /* Default value is 0xff */
Jes Sorensen3307d842016-02-29 17:03:59 -05002685 memset(priv->efuse_wifi.raw, 0xff, EFUSE_MAP_LEN);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002686
2687 efuse_addr = 0;
2688 while (efuse_addr < EFUSE_REAL_CONTENT_LEN_8723A) {
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002689 u16 map_addr;
2690
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002691 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &header);
2692 if (ret || header == 0xff)
2693 goto exit;
2694
2695 if ((header & 0x1f) == 0x0f) { /* extended header */
2696 offset = (header & 0xe0) >> 5;
2697
2698 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++,
2699 &extheader);
2700 if (ret)
2701 goto exit;
2702 /* All words disabled */
2703 if ((extheader & 0x0f) == 0x0f)
2704 continue;
2705
2706 offset |= ((extheader & 0xf0) >> 1);
2707 word_mask = extheader & 0x0f;
2708 } else {
2709 offset = (header >> 4) & 0x0f;
2710 word_mask = header & 0x0f;
2711 }
2712
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002713 /* Get word enable value from PG header */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002714
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002715 /* We have 8 bits to indicate validity */
2716 map_addr = offset * 8;
2717 if (map_addr >= EFUSE_MAP_LEN) {
2718 dev_warn(dev, "%s: Illegal map_addr (%04x), "
2719 "efuse corrupt!\n",
2720 __func__, map_addr);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002721 ret = -EINVAL;
2722 goto exit;
2723 }
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002724 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
2725 /* Check word enable condition in the section */
Jakub Sitnicki32a39dd2016-02-29 17:04:24 -05002726 if (word_mask & BIT(i)) {
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002727 map_addr += 2;
Jakub Sitnicki32a39dd2016-02-29 17:04:24 -05002728 continue;
2729 }
2730
2731 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
2732 if (ret)
2733 goto exit;
2734 priv->efuse_wifi.raw[map_addr++] = val8;
2735
2736 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
2737 if (ret)
2738 goto exit;
2739 priv->efuse_wifi.raw[map_addr++] = val8;
Jakub Sitnickif6c47702016-02-29 17:04:23 -05002740 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002741 }
2742
2743exit:
2744 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_DISABLE);
2745
2746 return ret;
2747}
2748
Jes Sorensend48fe602016-02-03 13:39:44 -05002749static void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv)
2750{
2751 u8 val8;
2752 u16 sys_func;
2753
2754 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05002755 val8 &= ~BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05002756 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05002757
Jes Sorensend48fe602016-02-03 13:39:44 -05002758 sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2759 sys_func &= ~SYS_FUNC_CPU_ENABLE;
2760 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05002761
Jes Sorensend48fe602016-02-03 13:39:44 -05002762 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05002763 val8 |= BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05002764 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05002765
2766 sys_func |= SYS_FUNC_CPU_ENABLE;
2767 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2768}
2769
2770static void rtl8723bu_reset_8051(struct rtl8xxxu_priv *priv)
2771{
2772 u8 val8;
2773 u16 sys_func;
2774
2775 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
2776 val8 &= ~BIT(1);
2777 rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
2778
2779 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
2780 val8 &= ~BIT(0);
2781 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
2782
2783 sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2784 sys_func &= ~SYS_FUNC_CPU_ENABLE;
2785 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2786
2787 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
2788 val8 &= ~BIT(1);
2789 rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
2790
2791 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
2792 val8 |= BIT(0);
2793 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
2794
Jes Sorensend48fe602016-02-03 13:39:44 -05002795 sys_func |= SYS_FUNC_CPU_ENABLE;
2796 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2797}
2798
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002799static int rtl8xxxu_start_firmware(struct rtl8xxxu_priv *priv)
2800{
2801 struct device *dev = &priv->udev->dev;
2802 int ret = 0, i;
2803 u32 val32;
2804
2805 /* Poll checksum report */
2806 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
2807 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2808 if (val32 & MCU_FW_DL_CSUM_REPORT)
2809 break;
2810 }
2811
2812 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
2813 dev_warn(dev, "Firmware checksum poll timed out\n");
2814 ret = -EAGAIN;
2815 goto exit;
2816 }
2817
2818 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2819 val32 |= MCU_FW_DL_READY;
2820 val32 &= ~MCU_WINT_INIT_READY;
2821 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
2822
Jes Sorensend48fe602016-02-03 13:39:44 -05002823 /*
2824 * Reset the 8051 in order for the firmware to start running,
2825 * otherwise it won't come up on the 8192eu
2826 */
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05002827 priv->fops->reset_8051(priv);
Jes Sorensend48fe602016-02-03 13:39:44 -05002828
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002829 /* Wait for firmware to become ready */
2830 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
2831 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2832 if (val32 & MCU_WINT_INIT_READY)
2833 break;
2834
2835 udelay(100);
2836 }
2837
2838 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
2839 dev_warn(dev, "Firmware failed to start\n");
2840 ret = -EAGAIN;
2841 goto exit;
2842 }
2843
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05002844 /*
2845 * Init H2C command
2846 */
Jes Sorensenba17d822016-03-31 17:08:39 -04002847 if (priv->rtl_chip == RTL8723B)
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05002848 rtl8xxxu_write8(priv, REG_HMTFR, 0x0f);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002849exit:
2850 return ret;
2851}
2852
2853static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv)
2854{
2855 int pages, remainder, i, ret;
Jes Sorensend48fe602016-02-03 13:39:44 -05002856 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002857 u16 val16;
2858 u32 val32;
2859 u8 *fwptr;
2860
2861 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC + 1);
2862 val8 |= 4;
2863 rtl8xxxu_write8(priv, REG_SYS_FUNC + 1, val8);
2864
2865 /* 8051 enable */
2866 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
Jes Sorensen43154f62016-02-03 13:39:35 -05002867 val16 |= SYS_FUNC_CPU_ENABLE;
2868 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002869
Jes Sorensen216202a2016-02-03 13:39:37 -05002870 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
2871 if (val8 & MCU_FW_RAM_SEL) {
2872 pr_info("do the RAM reset\n");
2873 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05002874 priv->fops->reset_8051(priv);
Jes Sorensen216202a2016-02-03 13:39:37 -05002875 }
2876
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002877 /* MCU firmware download enable */
2878 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002879 val8 |= MCU_FW_DL_ENABLE;
2880 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002881
2882 /* 8051 reset */
2883 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002884 val32 &= ~BIT(19);
2885 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002886
2887 /* Reset firmware download checksum */
2888 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002889 val8 |= MCU_FW_DL_CSUM_REPORT;
2890 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002891
2892 pages = priv->fw_size / RTL_FW_PAGE_SIZE;
2893 remainder = priv->fw_size % RTL_FW_PAGE_SIZE;
2894
2895 fwptr = priv->fw_data->data;
2896
2897 for (i = 0; i < pages; i++) {
2898 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05002899 val8 |= i;
2900 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002901
2902 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
2903 fwptr, RTL_FW_PAGE_SIZE);
2904 if (ret != RTL_FW_PAGE_SIZE) {
2905 ret = -EAGAIN;
2906 goto fw_abort;
2907 }
2908
2909 fwptr += RTL_FW_PAGE_SIZE;
2910 }
2911
2912 if (remainder) {
2913 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05002914 val8 |= i;
2915 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002916 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
2917 fwptr, remainder);
2918 if (ret != remainder) {
2919 ret = -EAGAIN;
2920 goto fw_abort;
2921 }
2922 }
2923
2924 ret = 0;
2925fw_abort:
2926 /* MCU firmware download disable */
2927 val16 = rtl8xxxu_read16(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002928 val16 &= ~MCU_FW_DL_ENABLE;
2929 rtl8xxxu_write16(priv, REG_MCU_FW_DL, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002930
2931 return ret;
2932}
2933
2934static int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name)
2935{
2936 struct device *dev = &priv->udev->dev;
2937 const struct firmware *fw;
2938 int ret = 0;
2939 u16 signature;
2940
2941 dev_info(dev, "%s: Loading firmware %s\n", DRIVER_NAME, fw_name);
2942 if (request_firmware(&fw, fw_name, &priv->udev->dev)) {
2943 dev_warn(dev, "request_firmware(%s) failed\n", fw_name);
2944 ret = -EAGAIN;
2945 goto exit;
2946 }
2947 if (!fw) {
2948 dev_warn(dev, "Firmware data not available\n");
2949 ret = -EINVAL;
2950 goto exit;
2951 }
2952
2953 priv->fw_data = kmemdup(fw->data, fw->size, GFP_KERNEL);
Tobias Klauser98e27cb2016-02-03 13:39:43 -05002954 if (!priv->fw_data) {
2955 ret = -ENOMEM;
2956 goto exit;
2957 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002958 priv->fw_size = fw->size - sizeof(struct rtl8xxxu_firmware_header);
2959
2960 signature = le16_to_cpu(priv->fw_data->signature);
2961 switch (signature & 0xfff0) {
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002962 case 0x92e0:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002963 case 0x92c0:
2964 case 0x88c0:
Jes Sorensen35a741f2016-02-29 17:04:10 -05002965 case 0x5300:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002966 case 0x2300:
2967 break;
2968 default:
2969 ret = -EINVAL;
2970 dev_warn(dev, "%s: Invalid firmware signature: 0x%04x\n",
2971 __func__, signature);
2972 }
2973
2974 dev_info(dev, "Firmware revision %i.%i (signature 0x%04x)\n",
2975 le16_to_cpu(priv->fw_data->major_version),
2976 priv->fw_data->minor_version, signature);
2977
2978exit:
2979 release_firmware(fw);
2980 return ret;
2981}
2982
2983static int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv)
2984{
2985 char *fw_name;
2986 int ret;
2987
2988 switch (priv->chip_cut) {
2989 case 0:
2990 fw_name = "rtlwifi/rtl8723aufw_A.bin";
2991 break;
2992 case 1:
2993 if (priv->enable_bluetooth)
2994 fw_name = "rtlwifi/rtl8723aufw_B.bin";
2995 else
2996 fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin";
2997
2998 break;
2999 default:
3000 return -EINVAL;
3001 }
3002
3003 ret = rtl8xxxu_load_firmware(priv, fw_name);
3004 return ret;
3005}
3006
Jes Sorensen35a741f2016-02-29 17:04:10 -05003007static int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv)
3008{
3009 char *fw_name;
3010 int ret;
3011
3012 if (priv->enable_bluetooth)
3013 fw_name = "rtlwifi/rtl8723bu_bt.bin";
3014 else
3015 fw_name = "rtlwifi/rtl8723bu_nic.bin";
3016
3017 ret = rtl8xxxu_load_firmware(priv, fw_name);
3018 return ret;
3019}
3020
Kalle Valoc0963772015-10-25 18:24:38 +02003021#ifdef CONFIG_RTL8XXXU_UNTESTED
3022
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003023static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
3024{
3025 char *fw_name;
3026 int ret;
3027
3028 if (!priv->vendor_umc)
3029 fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
Jes Sorensenba17d822016-03-31 17:08:39 -04003030 else if (priv->chip_cut || priv->rtl_chip == RTL8192C)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003031 fw_name = "rtlwifi/rtl8192cufw_B.bin";
3032 else
3033 fw_name = "rtlwifi/rtl8192cufw_A.bin";
3034
3035 ret = rtl8xxxu_load_firmware(priv, fw_name);
3036
3037 return ret;
3038}
3039
Kalle Valoc0963772015-10-25 18:24:38 +02003040#endif
3041
Jes Sorensen3307d842016-02-29 17:03:59 -05003042static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv)
3043{
3044 char *fw_name;
3045 int ret;
3046
Jes Sorensen0e5d4352016-02-29 17:04:00 -05003047 fw_name = "rtlwifi/rtl8192eu_nic.bin";
Jes Sorensen3307d842016-02-29 17:03:59 -05003048
3049 ret = rtl8xxxu_load_firmware(priv, fw_name);
3050
3051 return ret;
3052}
3053
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003054static void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv)
3055{
3056 u16 val16;
3057 int i = 100;
3058
3059 /* Inform 8051 to perform reset */
3060 rtl8xxxu_write8(priv, REG_HMTFR + 3, 0x20);
3061
3062 for (i = 100; i > 0; i--) {
3063 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3064
3065 if (!(val16 & SYS_FUNC_CPU_ENABLE)) {
3066 dev_dbg(&priv->udev->dev,
3067 "%s: Firmware self reset success!\n", __func__);
3068 break;
3069 }
3070 udelay(50);
3071 }
3072
3073 if (!i) {
3074 /* Force firmware reset */
3075 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3076 val16 &= ~SYS_FUNC_CPU_ENABLE;
3077 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3078 }
3079}
3080
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003081static void rtl8723bu_phy_init_antenna_selection(struct rtl8xxxu_priv *priv)
3082{
3083 u32 val32;
3084
3085 val32 = rtl8xxxu_read32(priv, 0x64);
3086 val32 &= ~(BIT(20) | BIT(24));
3087 rtl8xxxu_write32(priv, 0x64, val32);
3088
3089 val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG);
3090 val32 &= ~BIT(4);
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003091 rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32);
3092
3093 val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003094 val32 |= BIT(3);
3095 rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32);
3096
3097 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003098 val32 |= BIT(24);
3099 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
3100
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003101 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
3102 val32 &= ~BIT(23);
3103 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
3104
Jes Sorensen120e6272016-02-29 17:05:14 -05003105 val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003106 val32 |= (BIT(0) | BIT(1));
Jes Sorensen120e6272016-02-29 17:05:14 -05003107 rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003108
Jes Sorensen59b74392016-02-29 17:05:15 -05003109 val32 = rtl8xxxu_read32(priv, REG_RFE_CTRL_ANTA_SRC);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003110 val32 &= 0xffffff00;
3111 val32 |= 0x77;
Jes Sorensen59b74392016-02-29 17:05:15 -05003112 rtl8xxxu_write32(priv, REG_RFE_CTRL_ANTA_SRC, val32);
Jes Sorensen3a4be6a2016-02-29 17:04:58 -05003113
3114 val32 = rtl8xxxu_read32(priv, REG_PWR_DATA);
3115 val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
3116 rtl8xxxu_write32(priv, REG_PWR_DATA, val32);
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05003117}
3118
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003119static int
Jes Sorensenc606e662016-04-07 14:19:16 -04003120rtl8xxxu_init_mac(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003121{
Jes Sorensenc606e662016-04-07 14:19:16 -04003122 struct rtl8xxxu_reg8val *array = priv->fops->mactable;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003123 int i, ret;
3124 u16 reg;
3125 u8 val;
3126
3127 for (i = 0; ; i++) {
3128 reg = array[i].reg;
3129 val = array[i].val;
3130
3131 if (reg == 0xffff && val == 0xff)
3132 break;
3133
3134 ret = rtl8xxxu_write8(priv, reg, val);
3135 if (ret != 1) {
3136 dev_warn(&priv->udev->dev,
Jes Sorensenc606e662016-04-07 14:19:16 -04003137 "Failed to initialize MAC "
3138 "(reg: %04x, val %02x)\n", reg, val);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003139 return -EAGAIN;
3140 }
3141 }
3142
Jes Sorensenba17d822016-03-31 17:08:39 -04003143 if (priv->rtl_chip != RTL8723B)
Jes Sorensen8baf6702016-02-29 17:04:54 -05003144 rtl8xxxu_write8(priv, REG_MAX_AGGR_NUM, 0x0a);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003145
3146 return 0;
3147}
3148
3149static int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv,
3150 struct rtl8xxxu_reg32val *array)
3151{
3152 int i, ret;
3153 u16 reg;
3154 u32 val;
3155
3156 for (i = 0; ; i++) {
3157 reg = array[i].reg;
3158 val = array[i].val;
3159
3160 if (reg == 0xffff && val == 0xffffffff)
3161 break;
3162
3163 ret = rtl8xxxu_write32(priv, reg, val);
3164 if (ret != sizeof(val)) {
3165 dev_warn(&priv->udev->dev,
3166 "Failed to initialize PHY\n");
3167 return -EAGAIN;
3168 }
3169 udelay(1);
3170 }
3171
3172 return 0;
3173}
3174
3175/*
3176 * Most of this is black magic retrieved from the old rtl8723au driver
3177 */
3178static int rtl8xxxu_init_phy_bb(struct rtl8xxxu_priv *priv)
3179{
3180 u8 val8, ldoa15, ldov12d, lpldo, ldohci12;
Jes Sorensen04313eb2016-02-29 17:04:51 -05003181 u16 val16;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003182 u32 val32;
3183
3184 /*
3185 * Todo: The vendor driver maintains a table of PHY register
3186 * addresses, which is initialized here. Do we need this?
3187 */
3188
Jes Sorensenba17d822016-03-31 17:08:39 -04003189 if (priv->rtl_chip == RTL8723B) {
Jes Sorensen8baf6702016-02-29 17:04:54 -05003190 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3191 val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB |
3192 SYS_FUNC_DIO_RF;
3193 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3194
Jes Sorensen3ca7b322016-02-29 17:04:43 -05003195 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00);
3196 } else {
3197 val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL);
3198 udelay(2);
3199 val8 |= AFE_PLL_320_ENABLE;
3200 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8);
3201 udelay(2);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003202
Jes Sorensen3ca7b322016-02-29 17:04:43 -05003203 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL + 1, 0xff);
3204 udelay(2);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003205
Jes Sorensen8baf6702016-02-29 17:04:54 -05003206 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
3207 val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB;
3208 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
3209 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003210
Jes Sorensen2ca73dc2016-04-07 14:19:17 -04003211 if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E) {
Jes Sorensen04313eb2016-02-29 17:04:51 -05003212 /* AFE_XTAL_RF_GATE (bit 14) if addressing as 32 bit register */
3213 val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL);
3214 val32 &= ~AFE_XTAL_RF_GATE;
3215 if (priv->has_bluetooth)
3216 val32 &= ~AFE_XTAL_BT_GATE;
3217 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32);
3218 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003219
3220 /* 6. 0x1f[7:0] = 0x07 */
3221 val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
3222 rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
3223
3224 if (priv->hi_pa)
3225 rtl8xxxu_init_phy_regs(priv, rtl8188ru_phy_1t_highpa_table);
3226 else if (priv->tx_paths == 2)
3227 rtl8xxxu_init_phy_regs(priv, rtl8192cu_phy_2t_init_table);
Jes Sorensenba17d822016-03-31 17:08:39 -04003228 else if (priv->rtl_chip == RTL8723B) {
Jes Sorensen8baf6702016-02-29 17:04:54 -05003229 /*
3230 * Why?
3231 */
3232 rtl8xxxu_write8(priv, REG_SYS_FUNC, 0xe3);
3233 rtl8xxxu_write8(priv, REG_AFE_XTAL_CTRL + 1, 0x80);
Jes Sorensen36c32582016-02-29 17:04:14 -05003234 rtl8xxxu_init_phy_regs(priv, rtl8723b_phy_1t_init_table);
Jes Sorensen8baf6702016-02-29 17:04:54 -05003235 } else
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003236 rtl8xxxu_init_phy_regs(priv, rtl8723a_phy_1t_init_table);
3237
3238
Jes Sorensenba17d822016-03-31 17:08:39 -04003239 if (priv->rtl_chip == RTL8188C && priv->hi_pa &&
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003240 priv->vendor_umc && priv->chip_cut == 1)
3241 rtl8xxxu_write8(priv, REG_OFDM0_AGC_PARM1 + 2, 0x50);
3242
3243 if (priv->tx_paths == 1 && priv->rx_paths == 2) {
3244 /*
3245 * For 1T2R boards, patch the registers.
3246 *
3247 * It looks like 8191/2 1T2R boards use path B for TX
3248 */
3249 val32 = rtl8xxxu_read32(priv, REG_FPGA0_TX_INFO);
3250 val32 &= ~(BIT(0) | BIT(1));
3251 val32 |= BIT(1);
3252 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, val32);
3253
3254 val32 = rtl8xxxu_read32(priv, REG_FPGA1_TX_INFO);
3255 val32 &= ~0x300033;
3256 val32 |= 0x200022;
3257 rtl8xxxu_write32(priv, REG_FPGA1_TX_INFO, val32);
3258
3259 val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
3260 val32 &= 0xff000000;
3261 val32 |= 0x45000000;
3262 rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
3263
3264 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
3265 val32 &= ~(OFDM_RF_PATH_RX_MASK | OFDM_RF_PATH_TX_MASK);
3266 val32 |= (OFDM_RF_PATH_RX_A | OFDM_RF_PATH_RX_B |
3267 OFDM_RF_PATH_TX_B);
3268 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
3269
3270 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGC_PARM1);
3271 val32 &= ~(BIT(4) | BIT(5));
3272 val32 |= BIT(4);
3273 rtl8xxxu_write32(priv, REG_OFDM0_AGC_PARM1, val32);
3274
3275 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_RFON);
3276 val32 &= ~(BIT(27) | BIT(26));
3277 val32 |= BIT(27);
3278 rtl8xxxu_write32(priv, REG_TX_CCK_RFON, val32);
3279
3280 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_BBON);
3281 val32 &= ~(BIT(27) | BIT(26));
3282 val32 |= BIT(27);
3283 rtl8xxxu_write32(priv, REG_TX_CCK_BBON, val32);
3284
3285 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_RFON);
3286 val32 &= ~(BIT(27) | BIT(26));
3287 val32 |= BIT(27);
3288 rtl8xxxu_write32(priv, REG_TX_OFDM_RFON, val32);
3289
3290 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_BBON);
3291 val32 &= ~(BIT(27) | BIT(26));
3292 val32 |= BIT(27);
3293 rtl8xxxu_write32(priv, REG_TX_OFDM_BBON, val32);
3294
3295 val32 = rtl8xxxu_read32(priv, REG_TX_TO_TX);
3296 val32 &= ~(BIT(27) | BIT(26));
3297 val32 |= BIT(27);
3298 rtl8xxxu_write32(priv, REG_TX_TO_TX, val32);
3299 }
3300
Jes Sorensenba17d822016-03-31 17:08:39 -04003301 if (priv->rtl_chip == RTL8723B)
Jes Sorensenb9f498e2016-02-29 17:04:18 -05003302 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8723bu_table);
3303 else if (priv->hi_pa)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003304 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_highpa_table);
3305 else
3306 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_standard_table);
3307
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05003308 if (priv->has_xtalk) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003309 val32 = rtl8xxxu_read32(priv, REG_MAC_PHY_CTRL);
3310
Jes Sorensen4ef22eb2016-02-29 17:04:55 -05003311 val8 = priv->xtalk;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003312 val32 &= 0xff000fff;
3313 val32 |= ((val8 | (val8 << 6)) << 12);
3314
3315 rtl8xxxu_write32(priv, REG_MAC_PHY_CTRL, val32);
3316 }
3317
Jes Sorensena069caa2016-03-31 17:08:42 -04003318 if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E) {
Jes Sorensena0e262b2016-02-29 17:04:56 -05003319 ldoa15 = LDOA15_ENABLE | LDOA15_OBUF;
3320 ldov12d = LDOV12D_ENABLE | BIT(2) | (2 << LDOV12D_VADJ_SHIFT);
3321 ldohci12 = 0x57;
3322 lpldo = 1;
3323 val32 = (lpldo << 24) | (ldohci12 << 16) |
3324 (ldov12d << 8) | ldoa15;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003325
Jes Sorensena0e262b2016-02-29 17:04:56 -05003326 rtl8xxxu_write32(priv, REG_LDOA15_CTRL, val32);
3327 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003328
3329 return 0;
3330}
3331
3332static int rtl8xxxu_init_rf_regs(struct rtl8xxxu_priv *priv,
3333 struct rtl8xxxu_rfregval *array,
3334 enum rtl8xxxu_rfpath path)
3335{
3336 int i, ret;
3337 u8 reg;
3338 u32 val;
3339
3340 for (i = 0; ; i++) {
3341 reg = array[i].reg;
3342 val = array[i].val;
3343
3344 if (reg == 0xff && val == 0xffffffff)
3345 break;
3346
3347 switch (reg) {
3348 case 0xfe:
3349 msleep(50);
3350 continue;
3351 case 0xfd:
3352 mdelay(5);
3353 continue;
3354 case 0xfc:
3355 mdelay(1);
3356 continue;
3357 case 0xfb:
3358 udelay(50);
3359 continue;
3360 case 0xfa:
3361 udelay(5);
3362 continue;
3363 case 0xf9:
3364 udelay(1);
3365 continue;
3366 }
3367
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003368 ret = rtl8xxxu_write_rfreg(priv, path, reg, val);
3369 if (ret) {
3370 dev_warn(&priv->udev->dev,
3371 "Failed to initialize RF\n");
3372 return -EAGAIN;
3373 }
3374 udelay(1);
3375 }
3376
3377 return 0;
3378}
3379
3380static int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv *priv,
3381 struct rtl8xxxu_rfregval *table,
3382 enum rtl8xxxu_rfpath path)
3383{
3384 u32 val32;
3385 u16 val16, rfsi_rfenv;
3386 u16 reg_sw_ctrl, reg_int_oe, reg_hssi_parm2;
3387
3388 switch (path) {
3389 case RF_A:
3390 reg_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL;
3391 reg_int_oe = REG_FPGA0_XA_RF_INT_OE;
3392 reg_hssi_parm2 = REG_FPGA0_XA_HSSI_PARM2;
3393 break;
3394 case RF_B:
3395 reg_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL;
3396 reg_int_oe = REG_FPGA0_XB_RF_INT_OE;
3397 reg_hssi_parm2 = REG_FPGA0_XB_HSSI_PARM2;
3398 break;
3399 default:
3400 dev_err(&priv->udev->dev, "%s:Unsupported RF path %c\n",
3401 __func__, path + 'A');
3402 return -EINVAL;
3403 }
3404 /* For path B, use XB */
3405 rfsi_rfenv = rtl8xxxu_read16(priv, reg_sw_ctrl);
3406 rfsi_rfenv &= FPGA0_RF_RFENV;
3407
3408 /*
3409 * These two we might be able to optimize into one
3410 */
3411 val32 = rtl8xxxu_read32(priv, reg_int_oe);
3412 val32 |= BIT(20); /* 0x10 << 16 */
3413 rtl8xxxu_write32(priv, reg_int_oe, val32);
3414 udelay(1);
3415
3416 val32 = rtl8xxxu_read32(priv, reg_int_oe);
3417 val32 |= BIT(4);
3418 rtl8xxxu_write32(priv, reg_int_oe, val32);
3419 udelay(1);
3420
3421 /*
3422 * These two we might be able to optimize into one
3423 */
3424 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
3425 val32 &= ~FPGA0_HSSI_3WIRE_ADDR_LEN;
3426 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
3427 udelay(1);
3428
3429 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
3430 val32 &= ~FPGA0_HSSI_3WIRE_DATA_LEN;
3431 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
3432 udelay(1);
3433
3434 rtl8xxxu_init_rf_regs(priv, table, path);
3435
3436 /* For path B, use XB */
3437 val16 = rtl8xxxu_read16(priv, reg_sw_ctrl);
3438 val16 &= ~FPGA0_RF_RFENV;
3439 val16 |= rfsi_rfenv;
3440 rtl8xxxu_write16(priv, reg_sw_ctrl, val16);
3441
3442 return 0;
3443}
3444
3445static int rtl8xxxu_llt_write(struct rtl8xxxu_priv *priv, u8 address, u8 data)
3446{
3447 int ret = -EBUSY;
3448 int count = 0;
3449 u32 value;
3450
3451 value = LLT_OP_WRITE | address << 8 | data;
3452
3453 rtl8xxxu_write32(priv, REG_LLT_INIT, value);
3454
3455 do {
3456 value = rtl8xxxu_read32(priv, REG_LLT_INIT);
3457 if ((value & LLT_OP_MASK) == LLT_OP_INACTIVE) {
3458 ret = 0;
3459 break;
3460 }
3461 } while (count++ < 20);
3462
3463 return ret;
3464}
3465
3466static int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
3467{
3468 int ret;
3469 int i;
3470
3471 for (i = 0; i < last_tx_page; i++) {
3472 ret = rtl8xxxu_llt_write(priv, i, i + 1);
3473 if (ret)
3474 goto exit;
3475 }
3476
3477 ret = rtl8xxxu_llt_write(priv, last_tx_page, 0xff);
3478 if (ret)
3479 goto exit;
3480
3481 /* Mark remaining pages as a ring buffer */
3482 for (i = last_tx_page + 1; i < 0xff; i++) {
3483 ret = rtl8xxxu_llt_write(priv, i, (i + 1));
3484 if (ret)
3485 goto exit;
3486 }
3487
3488 /* Let last entry point to the start entry of ring buffer */
3489 ret = rtl8xxxu_llt_write(priv, 0xff, last_tx_page + 1);
3490 if (ret)
3491 goto exit;
3492
3493exit:
3494 return ret;
3495}
3496
Jes Sorensen74b99be2016-02-29 17:04:04 -05003497static int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
3498{
3499 u32 val32;
3500 int ret = 0;
3501 int i;
3502
3503 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
Jes Sorensen74b99be2016-02-29 17:04:04 -05003504 val32 |= AUTO_LLT_INIT_LLT;
3505 rtl8xxxu_write32(priv, REG_AUTO_LLT, val32);
3506
3507 for (i = 500; i; i--) {
3508 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
3509 if (!(val32 & AUTO_LLT_INIT_LLT))
3510 break;
3511 usleep_range(2, 4);
3512 }
3513
Jes Sorensen4de24812016-02-29 17:04:07 -05003514 if (!i) {
Jes Sorensen74b99be2016-02-29 17:04:04 -05003515 ret = -EBUSY;
3516 dev_warn(&priv->udev->dev, "LLT table init failed\n");
3517 }
Jes Sorensen74b99be2016-02-29 17:04:04 -05003518
3519 return ret;
3520}
3521
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003522static int rtl8xxxu_init_queue_priority(struct rtl8xxxu_priv *priv)
3523{
3524 u16 val16, hi, lo;
3525 u16 hiq, mgq, bkq, beq, viq, voq;
3526 int hip, mgp, bkp, bep, vip, vop;
3527 int ret = 0;
3528
3529 switch (priv->ep_tx_count) {
3530 case 1:
3531 if (priv->ep_tx_high_queue) {
3532 hi = TRXDMA_QUEUE_HIGH;
3533 } else if (priv->ep_tx_low_queue) {
3534 hi = TRXDMA_QUEUE_LOW;
3535 } else if (priv->ep_tx_normal_queue) {
3536 hi = TRXDMA_QUEUE_NORMAL;
3537 } else {
3538 hi = 0;
3539 ret = -EINVAL;
3540 }
3541
3542 hiq = hi;
3543 mgq = hi;
3544 bkq = hi;
3545 beq = hi;
3546 viq = hi;
3547 voq = hi;
3548
3549 hip = 0;
3550 mgp = 0;
3551 bkp = 0;
3552 bep = 0;
3553 vip = 0;
3554 vop = 0;
3555 break;
3556 case 2:
3557 if (priv->ep_tx_high_queue && priv->ep_tx_low_queue) {
3558 hi = TRXDMA_QUEUE_HIGH;
3559 lo = TRXDMA_QUEUE_LOW;
3560 } else if (priv->ep_tx_normal_queue && priv->ep_tx_low_queue) {
3561 hi = TRXDMA_QUEUE_NORMAL;
3562 lo = TRXDMA_QUEUE_LOW;
3563 } else if (priv->ep_tx_high_queue && priv->ep_tx_normal_queue) {
3564 hi = TRXDMA_QUEUE_HIGH;
3565 lo = TRXDMA_QUEUE_NORMAL;
3566 } else {
3567 ret = -EINVAL;
3568 hi = 0;
3569 lo = 0;
3570 }
3571
3572 hiq = hi;
3573 mgq = hi;
3574 bkq = lo;
3575 beq = lo;
3576 viq = hi;
3577 voq = hi;
3578
3579 hip = 0;
3580 mgp = 0;
3581 bkp = 1;
3582 bep = 1;
3583 vip = 0;
3584 vop = 0;
3585 break;
3586 case 3:
3587 beq = TRXDMA_QUEUE_LOW;
3588 bkq = TRXDMA_QUEUE_LOW;
3589 viq = TRXDMA_QUEUE_NORMAL;
3590 voq = TRXDMA_QUEUE_HIGH;
3591 mgq = TRXDMA_QUEUE_HIGH;
3592 hiq = TRXDMA_QUEUE_HIGH;
3593
3594 hip = hiq ^ 3;
3595 mgp = mgq ^ 3;
3596 bkp = bkq ^ 3;
3597 bep = beq ^ 3;
3598 vip = viq ^ 3;
3599 vop = viq ^ 3;
3600 break;
3601 default:
3602 ret = -EINVAL;
3603 }
3604
3605 /*
3606 * None of the vendor drivers are configuring the beacon
3607 * queue here .... why?
3608 */
3609 if (!ret) {
3610 val16 = rtl8xxxu_read16(priv, REG_TRXDMA_CTRL);
3611 val16 &= 0x7;
3612 val16 |= (voq << TRXDMA_CTRL_VOQ_SHIFT) |
3613 (viq << TRXDMA_CTRL_VIQ_SHIFT) |
3614 (beq << TRXDMA_CTRL_BEQ_SHIFT) |
3615 (bkq << TRXDMA_CTRL_BKQ_SHIFT) |
3616 (mgq << TRXDMA_CTRL_MGQ_SHIFT) |
3617 (hiq << TRXDMA_CTRL_HIQ_SHIFT);
3618 rtl8xxxu_write16(priv, REG_TRXDMA_CTRL, val16);
3619
3620 priv->pipe_out[TXDESC_QUEUE_VO] =
3621 usb_sndbulkpipe(priv->udev, priv->out_ep[vop]);
3622 priv->pipe_out[TXDESC_QUEUE_VI] =
3623 usb_sndbulkpipe(priv->udev, priv->out_ep[vip]);
3624 priv->pipe_out[TXDESC_QUEUE_BE] =
3625 usb_sndbulkpipe(priv->udev, priv->out_ep[bep]);
3626 priv->pipe_out[TXDESC_QUEUE_BK] =
3627 usb_sndbulkpipe(priv->udev, priv->out_ep[bkp]);
3628 priv->pipe_out[TXDESC_QUEUE_BEACON] =
3629 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
3630 priv->pipe_out[TXDESC_QUEUE_MGNT] =
3631 usb_sndbulkpipe(priv->udev, priv->out_ep[mgp]);
3632 priv->pipe_out[TXDESC_QUEUE_HIGH] =
3633 usb_sndbulkpipe(priv->udev, priv->out_ep[hip]);
3634 priv->pipe_out[TXDESC_QUEUE_CMD] =
3635 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
3636 }
3637
3638 return ret;
3639}
3640
3641static void rtl8xxxu_fill_iqk_matrix_a(struct rtl8xxxu_priv *priv,
3642 bool iqk_ok, int result[][8],
3643 int candidate, bool tx_only)
3644{
3645 u32 oldval, x, tx0_a, reg;
3646 int y, tx0_c;
3647 u32 val32;
3648
3649 if (!iqk_ok)
3650 return;
3651
3652 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3653 oldval = val32 >> 22;
3654
3655 x = result[candidate][0];
3656 if ((x & 0x00000200) != 0)
3657 x = x | 0xfffffc00;
3658 tx0_a = (x * oldval) >> 8;
3659
3660 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3661 val32 &= ~0x3ff;
3662 val32 |= tx0_a;
3663 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
3664
3665 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3666 val32 &= ~BIT(31);
3667 if ((x * oldval >> 7) & 0x1)
3668 val32 |= BIT(31);
3669 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3670
3671 y = result[candidate][1];
3672 if ((y & 0x00000200) != 0)
3673 y = y | 0xfffffc00;
3674 tx0_c = (y * oldval) >> 8;
3675
3676 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XC_TX_AFE);
3677 val32 &= ~0xf0000000;
3678 val32 |= (((tx0_c & 0x3c0) >> 6) << 28);
3679 rtl8xxxu_write32(priv, REG_OFDM0_XC_TX_AFE, val32);
3680
3681 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3682 val32 &= ~0x003f0000;
3683 val32 |= ((tx0_c & 0x3f) << 16);
3684 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
3685
3686 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3687 val32 &= ~BIT(29);
3688 if ((y * oldval >> 7) & 0x1)
3689 val32 |= BIT(29);
3690 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3691
3692 if (tx_only) {
3693 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
3694 return;
3695 }
3696
3697 reg = result[candidate][2];
3698
3699 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
3700 val32 &= ~0x3ff;
3701 val32 |= (reg & 0x3ff);
3702 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
3703
3704 reg = result[candidate][3] & 0x3F;
3705
3706 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
3707 val32 &= ~0xfc00;
3708 val32 |= ((reg << 10) & 0xfc00);
3709 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
3710
3711 reg = (result[candidate][3] >> 6) & 0xF;
3712
3713 val32 = rtl8xxxu_read32(priv, REG_OFDM0_RX_IQ_EXT_ANTA);
3714 val32 &= ~0xf0000000;
3715 val32 |= (reg << 28);
3716 rtl8xxxu_write32(priv, REG_OFDM0_RX_IQ_EXT_ANTA, val32);
3717}
3718
3719static void rtl8xxxu_fill_iqk_matrix_b(struct rtl8xxxu_priv *priv,
3720 bool iqk_ok, int result[][8],
3721 int candidate, bool tx_only)
3722{
3723 u32 oldval, x, tx1_a, reg;
3724 int y, tx1_c;
3725 u32 val32;
3726
3727 if (!iqk_ok)
3728 return;
3729
3730 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3731 oldval = val32 >> 22;
3732
3733 x = result[candidate][4];
3734 if ((x & 0x00000200) != 0)
3735 x = x | 0xfffffc00;
3736 tx1_a = (x * oldval) >> 8;
3737
3738 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3739 val32 &= ~0x3ff;
3740 val32 |= tx1_a;
3741 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
3742
3743 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3744 val32 &= ~BIT(27);
3745 if ((x * oldval >> 7) & 0x1)
3746 val32 |= BIT(27);
3747 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3748
3749 y = result[candidate][5];
3750 if ((y & 0x00000200) != 0)
3751 y = y | 0xfffffc00;
3752 tx1_c = (y * oldval) >> 8;
3753
3754 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XD_TX_AFE);
3755 val32 &= ~0xf0000000;
3756 val32 |= (((tx1_c & 0x3c0) >> 6) << 28);
3757 rtl8xxxu_write32(priv, REG_OFDM0_XD_TX_AFE, val32);
3758
3759 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3760 val32 &= ~0x003f0000;
3761 val32 |= ((tx1_c & 0x3f) << 16);
3762 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
3763
3764 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3765 val32 &= ~BIT(25);
3766 if ((y * oldval >> 7) & 0x1)
3767 val32 |= BIT(25);
3768 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3769
3770 if (tx_only) {
3771 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
3772 return;
3773 }
3774
3775 reg = result[candidate][6];
3776
3777 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
3778 val32 &= ~0x3ff;
3779 val32 |= (reg & 0x3ff);
3780 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
3781
3782 reg = result[candidate][7] & 0x3f;
3783
3784 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
3785 val32 &= ~0xfc00;
3786 val32 |= ((reg << 10) & 0xfc00);
3787 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
3788
3789 reg = (result[candidate][7] >> 6) & 0xf;
3790
3791 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGCR_SSI_TABLE);
3792 val32 &= ~0x0000f000;
3793 val32 |= (reg << 12);
3794 rtl8xxxu_write32(priv, REG_OFDM0_AGCR_SSI_TABLE, val32);
3795}
3796
3797#define MAX_TOLERANCE 5
3798
3799static bool rtl8xxxu_simularity_compare(struct rtl8xxxu_priv *priv,
3800 int result[][8], int c1, int c2)
3801{
3802 u32 i, j, diff, simubitmap, bound = 0;
3803 int candidate[2] = {-1, -1}; /* for path A and path B */
3804 bool retval = true;
3805
3806 if (priv->tx_paths > 1)
3807 bound = 8;
3808 else
3809 bound = 4;
3810
3811 simubitmap = 0;
3812
3813 for (i = 0; i < bound; i++) {
3814 diff = (result[c1][i] > result[c2][i]) ?
3815 (result[c1][i] - result[c2][i]) :
3816 (result[c2][i] - result[c1][i]);
3817 if (diff > MAX_TOLERANCE) {
3818 if ((i == 2 || i == 6) && !simubitmap) {
3819 if (result[c1][i] + result[c1][i + 1] == 0)
3820 candidate[(i / 4)] = c2;
3821 else if (result[c2][i] + result[c2][i + 1] == 0)
3822 candidate[(i / 4)] = c1;
3823 else
3824 simubitmap = simubitmap | (1 << i);
3825 } else {
3826 simubitmap = simubitmap | (1 << i);
3827 }
3828 }
3829 }
3830
3831 if (simubitmap == 0) {
3832 for (i = 0; i < (bound / 4); i++) {
3833 if (candidate[i] >= 0) {
3834 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
3835 result[3][j] = result[candidate[i]][j];
3836 retval = false;
3837 }
3838 }
3839 return retval;
3840 } else if (!(simubitmap & 0x0f)) {
3841 /* path A OK */
3842 for (i = 0; i < 4; i++)
3843 result[3][i] = result[c1][i];
3844 } else if (!(simubitmap & 0xf0) && priv->tx_paths > 1) {
3845 /* path B OK */
3846 for (i = 4; i < 8; i++)
3847 result[3][i] = result[c1][i];
3848 }
3849
3850 return false;
3851}
3852
Jes Sorensene1547c52016-02-29 17:04:35 -05003853static bool rtl8723bu_simularity_compare(struct rtl8xxxu_priv *priv,
3854 int result[][8], int c1, int c2)
3855{
3856 u32 i, j, diff, simubitmap, bound = 0;
3857 int candidate[2] = {-1, -1}; /* for path A and path B */
3858 int tmp1, tmp2;
3859 bool retval = true;
3860
3861 if (priv->tx_paths > 1)
3862 bound = 8;
3863 else
3864 bound = 4;
3865
3866 simubitmap = 0;
3867
3868 for (i = 0; i < bound; i++) {
3869 if (i & 1) {
3870 if ((result[c1][i] & 0x00000200))
3871 tmp1 = result[c1][i] | 0xfffffc00;
3872 else
3873 tmp1 = result[c1][i];
3874
3875 if ((result[c2][i]& 0x00000200))
3876 tmp2 = result[c2][i] | 0xfffffc00;
3877 else
3878 tmp2 = result[c2][i];
3879 } else {
3880 tmp1 = result[c1][i];
3881 tmp2 = result[c2][i];
3882 }
3883
3884 diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1);
3885
3886 if (diff > MAX_TOLERANCE) {
3887 if ((i == 2 || i == 6) && !simubitmap) {
3888 if (result[c1][i] + result[c1][i + 1] == 0)
3889 candidate[(i / 4)] = c2;
3890 else if (result[c2][i] + result[c2][i + 1] == 0)
3891 candidate[(i / 4)] = c1;
3892 else
3893 simubitmap = simubitmap | (1 << i);
3894 } else {
3895 simubitmap = simubitmap | (1 << i);
3896 }
3897 }
3898 }
3899
3900 if (simubitmap == 0) {
3901 for (i = 0; i < (bound / 4); i++) {
3902 if (candidate[i] >= 0) {
3903 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
3904 result[3][j] = result[candidate[i]][j];
3905 retval = false;
3906 }
3907 }
3908 return retval;
3909 } else {
3910 if (!(simubitmap & 0x03)) {
3911 /* path A TX OK */
3912 for (i = 0; i < 2; i++)
3913 result[3][i] = result[c1][i];
3914 }
3915
3916 if (!(simubitmap & 0x0c)) {
3917 /* path A RX OK */
3918 for (i = 2; i < 4; i++)
3919 result[3][i] = result[c1][i];
3920 }
3921
3922 if (!(simubitmap & 0x30) && priv->tx_paths > 1) {
3923 /* path B RX OK */
3924 for (i = 4; i < 6; i++)
3925 result[3][i] = result[c1][i];
3926 }
3927
3928 if (!(simubitmap & 0x30) && priv->tx_paths > 1) {
3929 /* path B RX OK */
3930 for (i = 6; i < 8; i++)
3931 result[3][i] = result[c1][i];
3932 }
3933 }
3934
3935 return false;
3936}
3937
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003938static void
3939rtl8xxxu_save_mac_regs(struct rtl8xxxu_priv *priv, const u32 *reg, u32 *backup)
3940{
3941 int i;
3942
3943 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
3944 backup[i] = rtl8xxxu_read8(priv, reg[i]);
3945
3946 backup[i] = rtl8xxxu_read32(priv, reg[i]);
3947}
3948
3949static void rtl8xxxu_restore_mac_regs(struct rtl8xxxu_priv *priv,
3950 const u32 *reg, u32 *backup)
3951{
3952 int i;
3953
3954 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
3955 rtl8xxxu_write8(priv, reg[i], backup[i]);
3956
3957 rtl8xxxu_write32(priv, reg[i], backup[i]);
3958}
3959
3960static void rtl8xxxu_save_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
3961 u32 *backup, int count)
3962{
3963 int i;
3964
3965 for (i = 0; i < count; i++)
3966 backup[i] = rtl8xxxu_read32(priv, regs[i]);
3967}
3968
3969static void rtl8xxxu_restore_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
3970 u32 *backup, int count)
3971{
3972 int i;
3973
3974 for (i = 0; i < count; i++)
3975 rtl8xxxu_write32(priv, regs[i], backup[i]);
3976}
3977
3978
3979static void rtl8xxxu_path_adda_on(struct rtl8xxxu_priv *priv, const u32 *regs,
3980 bool path_a_on)
3981{
3982 u32 path_on;
3983 int i;
3984
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003985 if (priv->tx_paths == 1) {
Jes Sorensen8634af52016-02-29 17:04:33 -05003986 path_on = priv->fops->adda_1t_path_on;
3987 rtl8xxxu_write32(priv, regs[0], priv->fops->adda_1t_init);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003988 } else {
Jes Sorensen8634af52016-02-29 17:04:33 -05003989 path_on = path_a_on ? priv->fops->adda_2t_path_on_a :
3990 priv->fops->adda_2t_path_on_b;
3991
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003992 rtl8xxxu_write32(priv, regs[0], path_on);
3993 }
3994
3995 for (i = 1 ; i < RTL8XXXU_ADDA_REGS ; i++)
3996 rtl8xxxu_write32(priv, regs[i], path_on);
3997}
3998
3999static void rtl8xxxu_mac_calibration(struct rtl8xxxu_priv *priv,
4000 const u32 *regs, u32 *backup)
4001{
4002 int i = 0;
4003
4004 rtl8xxxu_write8(priv, regs[i], 0x3f);
4005
4006 for (i = 1 ; i < (RTL8XXXU_MAC_REGS - 1); i++)
4007 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(3)));
4008
4009 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(5)));
4010}
4011
4012static int rtl8xxxu_iqk_path_a(struct rtl8xxxu_priv *priv)
4013{
4014 u32 reg_eac, reg_e94, reg_e9c, reg_ea4, val32;
4015 int result = 0;
4016
4017 /* path-A IQK setting */
4018 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1f);
4019 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x10008c1f);
4020 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82140102);
4021
4022 val32 = (priv->rf_paths > 1) ? 0x28160202 :
4023 /*IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)?0x28160202: */
4024 0x28160502;
4025 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, val32);
4026
4027 /* path-B IQK setting */
4028 if (priv->rf_paths > 1) {
4029 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x10008c22);
4030 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x10008c22);
4031 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82140102);
4032 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28160202);
4033 }
4034
4035 /* LO calibration setting */
4036 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x001028d1);
4037
4038 /* One shot, path A LOK & IQK */
4039 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4040 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4041
4042 mdelay(1);
4043
4044 /* Check failed */
4045 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4046 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
4047 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
4048 reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
4049
4050 if (!(reg_eac & BIT(28)) &&
4051 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
4052 ((reg_e9c & 0x03ff0000) != 0x00420000))
4053 result |= 0x01;
4054 else /* If TX not OK, ignore RX */
4055 goto out;
4056
4057 /* If TX is OK, check whether RX is OK */
4058 if (!(reg_eac & BIT(27)) &&
4059 ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
4060 ((reg_eac & 0x03ff0000) != 0x00360000))
4061 result |= 0x02;
4062 else
4063 dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n",
4064 __func__);
4065out:
4066 return result;
4067}
4068
4069static int rtl8xxxu_iqk_path_b(struct rtl8xxxu_priv *priv)
4070{
4071 u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
4072 int result = 0;
4073
4074 /* One shot, path B LOK & IQK */
4075 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
4076 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
4077
4078 mdelay(1);
4079
4080 /* Check failed */
4081 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4082 reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4083 reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4084 reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
4085 reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
4086
4087 if (!(reg_eac & BIT(31)) &&
4088 ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
4089 ((reg_ebc & 0x03ff0000) != 0x00420000))
4090 result |= 0x01;
4091 else
4092 goto out;
4093
4094 if (!(reg_eac & BIT(30)) &&
4095 (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) &&
4096 (((reg_ecc & 0x03ff0000) >> 16) != 0x36))
4097 result |= 0x02;
4098 else
4099 dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
4100 __func__);
4101out:
4102 return result;
4103}
4104
Jes Sorensene1547c52016-02-29 17:04:35 -05004105static int rtl8723bu_iqk_path_a(struct rtl8xxxu_priv *priv)
4106{
4107 u32 reg_eac, reg_e94, reg_e9c, path_sel, val32;
4108 int result = 0;
4109
4110 path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH);
4111
4112 /*
4113 * Leave IQK mode
4114 */
4115 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4116 val32 &= 0x000000ff;
4117 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4118
4119 /*
4120 * Enable path A PA in TX IQK mode
4121 */
4122 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4123 val32 |= 0x80000;
4124 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4125 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x20000);
4126 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0003f);
4127 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xc7f87);
4128
4129 /*
4130 * Tx IQK setting
4131 */
4132 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
4133 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4134
4135 /* path-A IQK setting */
4136 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c);
4137 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c);
4138 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c);
4139 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c);
4140
4141 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x821403ea);
4142 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000);
4143 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000);
4144 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000);
4145
4146 /* LO calibration setting */
4147 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x00462911);
4148
4149 /*
4150 * Enter IQK mode
4151 */
4152 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4153 val32 &= 0x000000ff;
4154 val32 |= 0x80800000;
4155 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4156
4157 /*
4158 * The vendor driver indicates the USB module is always using
4159 * S0S1 path 1 for the 8723bu. This may be different for 8192eu
4160 */
4161 if (priv->rf_paths > 1)
4162 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000);
4163 else
4164 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280);
4165
4166 /*
4167 * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu.
4168 * No trace of this in the 8192eu or 8188eu vendor drivers.
4169 */
4170 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800);
4171
4172 /* One shot, path A LOK & IQK */
4173 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4174 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4175
4176 mdelay(1);
4177
4178 /* Restore Ant Path */
4179 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel);
4180#ifdef RTL8723BU_BT
4181 /* GNT_BT = 1 */
4182 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800);
4183#endif
4184
4185 /*
4186 * Leave IQK mode
4187 */
4188 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4189 val32 &= 0x000000ff;
4190 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4191
4192 /* Check failed */
4193 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4194 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
4195 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
4196
4197 val32 = (reg_e9c >> 16) & 0x3ff;
4198 if (val32 & 0x200)
4199 val32 = 0x400 - val32;
4200
4201 if (!(reg_eac & BIT(28)) &&
4202 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
4203 ((reg_e9c & 0x03ff0000) != 0x00420000) &&
4204 ((reg_e94 & 0x03ff0000) < 0x01100000) &&
4205 ((reg_e94 & 0x03ff0000) > 0x00f00000) &&
4206 val32 < 0xf)
4207 result |= 0x01;
4208 else /* If TX not OK, ignore RX */
4209 goto out;
4210
4211out:
4212 return result;
4213}
4214
4215static int rtl8723bu_rx_iqk_path_a(struct rtl8xxxu_priv *priv)
4216{
4217 u32 reg_ea4, reg_eac, reg_e94, reg_e9c, path_sel, val32;
4218 int result = 0;
4219
4220 path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH);
4221
4222 /*
4223 * Leave IQK mode
4224 */
4225 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4226 val32 &= 0x000000ff;
4227 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4228
4229 /*
4230 * Enable path A PA in TX IQK mode
4231 */
4232 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4233 val32 |= 0x80000;
4234 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4235 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
4236 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
4237 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7);
4238
4239 /*
4240 * Tx IQK setting
4241 */
4242 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
4243 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4244
4245 /* path-A IQK setting */
4246 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c);
4247 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c);
4248 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c);
4249 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c);
4250
4251 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82160ff0);
4252 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000);
4253 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000);
4254 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000);
4255
4256 /* LO calibration setting */
4257 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a911);
4258
4259 /*
4260 * Enter IQK mode
4261 */
4262 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4263 val32 &= 0x000000ff;
4264 val32 |= 0x80800000;
4265 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4266
4267 /*
4268 * The vendor driver indicates the USB module is always using
4269 * S0S1 path 1 for the 8723bu. This may be different for 8192eu
4270 */
4271 if (priv->rf_paths > 1)
4272 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000);
4273 else
4274 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280);
4275
4276 /*
4277 * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu.
4278 * No trace of this in the 8192eu or 8188eu vendor drivers.
4279 */
4280 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800);
4281
4282 /* One shot, path A LOK & IQK */
4283 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4284 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4285
4286 mdelay(1);
4287
4288 /* Restore Ant Path */
4289 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel);
4290#ifdef RTL8723BU_BT
4291 /* GNT_BT = 1 */
4292 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800);
4293#endif
4294
4295 /*
4296 * Leave IQK mode
4297 */
4298 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4299 val32 &= 0x000000ff;
4300 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4301
4302 /* Check failed */
4303 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4304 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
4305 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
4306
4307 val32 = (reg_e9c >> 16) & 0x3ff;
4308 if (val32 & 0x200)
4309 val32 = 0x400 - val32;
4310
4311 if (!(reg_eac & BIT(28)) &&
4312 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
4313 ((reg_e9c & 0x03ff0000) != 0x00420000) &&
4314 ((reg_e94 & 0x03ff0000) < 0x01100000) &&
4315 ((reg_e94 & 0x03ff0000) > 0x00f00000) &&
4316 val32 < 0xf)
4317 result |= 0x01;
4318 else /* If TX not OK, ignore RX */
4319 goto out;
4320
4321 val32 = 0x80007c00 | (reg_e94 &0x3ff0000) |
4322 ((reg_e9c & 0x3ff0000) >> 16);
4323 rtl8xxxu_write32(priv, REG_TX_IQK, val32);
4324
4325 /*
4326 * Modify RX IQK mode
4327 */
4328 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4329 val32 &= 0x000000ff;
4330 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4331 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4332 val32 |= 0x80000;
4333 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4334 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
4335 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
4336 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7d77);
4337
4338 /*
4339 * PA, PAD setting
4340 */
4341 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0xf80);
4342 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_55, 0x4021f);
4343
4344 /*
4345 * RX IQK setting
4346 */
4347 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4348
4349 /* path-A IQK setting */
4350 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x38008c1c);
4351 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x18008c1c);
4352 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c);
4353 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c);
4354
4355 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82110000);
4356 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x2816001f);
4357 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000);
4358 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000);
4359
4360 /* LO calibration setting */
4361 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a8d1);
4362
4363 /*
4364 * Enter IQK mode
4365 */
4366 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4367 val32 &= 0x000000ff;
4368 val32 |= 0x80800000;
4369 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4370
4371 if (priv->rf_paths > 1)
4372 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000);
4373 else
4374 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280);
4375
4376 /*
4377 * Disable BT
4378 */
4379 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800);
4380
4381 /* One shot, path A LOK & IQK */
4382 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
4383 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
4384
4385 mdelay(1);
4386
4387 /* Restore Ant Path */
4388 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel);
4389#ifdef RTL8723BU_BT
4390 /* GNT_BT = 1 */
4391 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800);
4392#endif
4393
4394 /*
4395 * Leave IQK mode
4396 */
4397 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4398 val32 &= 0x000000ff;
4399 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4400
4401 /* Check failed */
4402 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4403 reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
4404
4405 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x780);
4406
4407 val32 = (reg_eac >> 16) & 0x3ff;
4408 if (val32 & 0x200)
4409 val32 = 0x400 - val32;
4410
4411 if (!(reg_eac & BIT(27)) &&
4412 ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
4413 ((reg_eac & 0x03ff0000) != 0x00360000) &&
4414 ((reg_ea4 & 0x03ff0000) < 0x01100000) &&
4415 ((reg_ea4 & 0x03ff0000) > 0x00f00000) &&
4416 val32 < 0xf)
4417 result |= 0x02;
4418 else /* If TX not OK, ignore RX */
4419 goto out;
4420out:
4421 return result;
4422}
4423
4424#ifdef RTL8723BU_PATH_B
4425static int rtl8723bu_iqk_path_b(struct rtl8xxxu_priv *priv)
4426{
4427 u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc, path_sel;
4428 int result = 0;
4429
4430 path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH);
4431
4432 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4433 val32 &= 0x000000ff;
4434 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4435
4436 /* One shot, path B LOK & IQK */
4437 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
4438 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
4439
4440 mdelay(1);
4441
4442 /* Check failed */
4443 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
4444 reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4445 reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4446 reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
4447 reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
4448
4449 if (!(reg_eac & BIT(31)) &&
4450 ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
4451 ((reg_ebc & 0x03ff0000) != 0x00420000))
4452 result |= 0x01;
4453 else
4454 goto out;
4455
4456 if (!(reg_eac & BIT(30)) &&
4457 (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) &&
4458 (((reg_ecc & 0x03ff0000) >> 16) != 0x36))
4459 result |= 0x02;
4460 else
4461 dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
4462 __func__);
4463out:
4464 return result;
4465}
4466#endif
4467
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004468static void rtl8xxxu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
4469 int result[][8], int t)
4470{
4471 struct device *dev = &priv->udev->dev;
4472 u32 i, val32;
4473 int path_a_ok, path_b_ok;
4474 int retry = 2;
4475 const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
4476 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
4477 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
4478 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
4479 REG_TX_OFDM_BBON, REG_TX_TO_RX,
4480 REG_TX_TO_TX, REG_RX_CCK,
4481 REG_RX_OFDM, REG_RX_WAIT_RIFS,
4482 REG_RX_TO_RX, REG_STANDBY,
4483 REG_SLEEP, REG_PMPD_ANAEN
4484 };
4485 const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
4486 REG_TXPAUSE, REG_BEACON_CTRL,
4487 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
4488 };
4489 const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
4490 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
4491 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
4492 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
4493 REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
4494 };
4495
4496 /*
4497 * Note: IQ calibration must be performed after loading
4498 * PHY_REG.txt , and radio_a, radio_b.txt
4499 */
4500
4501 if (t == 0) {
4502 /* Save ADDA parameters, turn Path A ADDA on */
4503 rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
4504 RTL8XXXU_ADDA_REGS);
4505 rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
4506 rtl8xxxu_save_regs(priv, iqk_bb_regs,
4507 priv->bb_backup, RTL8XXXU_BB_REGS);
4508 }
4509
4510 rtl8xxxu_path_adda_on(priv, adda_regs, true);
4511
4512 if (t == 0) {
4513 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1);
4514 if (val32 & FPGA0_HSSI_PARM1_PI)
4515 priv->pi_enabled = 1;
4516 }
4517
4518 if (!priv->pi_enabled) {
4519 /* Switch BB to PI mode to do IQ Calibration. */
4520 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0x01000100);
4521 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0x01000100);
4522 }
4523
4524 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
4525 val32 &= ~FPGA_RF_MODE_CCK;
4526 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
4527
4528 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
4529 rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
4530 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
4531
4532 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
4533 val32 |= (FPGA0_RF_PAPE | (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
4534 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
4535
4536 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
4537 val32 &= ~BIT(10);
4538 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
4539 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
4540 val32 &= ~BIT(10);
4541 rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
4542
4543 if (priv->tx_paths > 1) {
4544 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
4545 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, 0x00010000);
4546 }
4547
4548 /* MAC settings */
4549 rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
4550
4551 /* Page B init */
4552 rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x00080000);
4553
4554 if (priv->tx_paths > 1)
4555 rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x00080000);
4556
4557 /* IQ calibration setting */
4558 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
4559 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
4560 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
4561
4562 for (i = 0; i < retry; i++) {
4563 path_a_ok = rtl8xxxu_iqk_path_a(priv);
4564 if (path_a_ok == 0x03) {
4565 val32 = rtl8xxxu_read32(priv,
4566 REG_TX_POWER_BEFORE_IQK_A);
4567 result[t][0] = (val32 >> 16) & 0x3ff;
4568 val32 = rtl8xxxu_read32(priv,
4569 REG_TX_POWER_AFTER_IQK_A);
4570 result[t][1] = (val32 >> 16) & 0x3ff;
4571 val32 = rtl8xxxu_read32(priv,
4572 REG_RX_POWER_BEFORE_IQK_A_2);
4573 result[t][2] = (val32 >> 16) & 0x3ff;
4574 val32 = rtl8xxxu_read32(priv,
4575 REG_RX_POWER_AFTER_IQK_A_2);
4576 result[t][3] = (val32 >> 16) & 0x3ff;
4577 break;
4578 } else if (i == (retry - 1) && path_a_ok == 0x01) {
4579 /* TX IQK OK */
4580 dev_dbg(dev, "%s: Path A IQK Only Tx Success!!\n",
4581 __func__);
4582
4583 val32 = rtl8xxxu_read32(priv,
4584 REG_TX_POWER_BEFORE_IQK_A);
4585 result[t][0] = (val32 >> 16) & 0x3ff;
4586 val32 = rtl8xxxu_read32(priv,
4587 REG_TX_POWER_AFTER_IQK_A);
4588 result[t][1] = (val32 >> 16) & 0x3ff;
4589 }
4590 }
4591
4592 if (!path_a_ok)
4593 dev_dbg(dev, "%s: Path A IQK failed!\n", __func__);
4594
4595 if (priv->tx_paths > 1) {
4596 /*
4597 * Path A into standby
4598 */
4599 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x0);
4600 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
4601 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
4602
4603 /* Turn Path B ADDA on */
4604 rtl8xxxu_path_adda_on(priv, adda_regs, false);
4605
4606 for (i = 0; i < retry; i++) {
4607 path_b_ok = rtl8xxxu_iqk_path_b(priv);
4608 if (path_b_ok == 0x03) {
4609 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4610 result[t][4] = (val32 >> 16) & 0x3ff;
4611 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4612 result[t][5] = (val32 >> 16) & 0x3ff;
4613 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
4614 result[t][6] = (val32 >> 16) & 0x3ff;
4615 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
4616 result[t][7] = (val32 >> 16) & 0x3ff;
4617 break;
4618 } else if (i == (retry - 1) && path_b_ok == 0x01) {
4619 /* TX IQK OK */
4620 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4621 result[t][4] = (val32 >> 16) & 0x3ff;
4622 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4623 result[t][5] = (val32 >> 16) & 0x3ff;
4624 }
4625 }
4626
4627 if (!path_b_ok)
4628 dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
4629 }
4630
4631 /* Back to BB mode, load original value */
4632 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0);
4633
4634 if (t) {
4635 if (!priv->pi_enabled) {
4636 /*
4637 * Switch back BB to SI mode after finishing
4638 * IQ Calibration
4639 */
4640 val32 = 0x01000000;
4641 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, val32);
4642 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, val32);
4643 }
4644
4645 /* Reload ADDA power saving parameters */
4646 rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
4647 RTL8XXXU_ADDA_REGS);
4648
4649 /* Reload MAC parameters */
4650 rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
4651
4652 /* Reload BB parameters */
4653 rtl8xxxu_restore_regs(priv, iqk_bb_regs,
4654 priv->bb_backup, RTL8XXXU_BB_REGS);
4655
4656 /* Restore RX initial gain */
4657 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00032ed3);
4658
4659 if (priv->tx_paths > 1) {
4660 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM,
4661 0x00032ed3);
4662 }
4663
4664 /* Load 0xe30 IQC default value */
4665 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
4666 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
4667 }
4668}
4669
Jes Sorensene1547c52016-02-29 17:04:35 -05004670static void rtl8723bu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
4671 int result[][8], int t)
4672{
4673 struct device *dev = &priv->udev->dev;
4674 u32 i, val32;
4675 int path_a_ok /*, path_b_ok */;
4676 int retry = 2;
4677 const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
4678 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
4679 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
4680 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
4681 REG_TX_OFDM_BBON, REG_TX_TO_RX,
4682 REG_TX_TO_TX, REG_RX_CCK,
4683 REG_RX_OFDM, REG_RX_WAIT_RIFS,
4684 REG_RX_TO_RX, REG_STANDBY,
4685 REG_SLEEP, REG_PMPD_ANAEN
4686 };
4687 const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
4688 REG_TXPAUSE, REG_BEACON_CTRL,
4689 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
4690 };
4691 const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
4692 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
4693 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
4694 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
4695 REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
4696 };
4697 u8 xa_agc = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1) & 0xff;
4698 u8 xb_agc = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1) & 0xff;
4699
4700 /*
4701 * Note: IQ calibration must be performed after loading
4702 * PHY_REG.txt , and radio_a, radio_b.txt
4703 */
4704
4705 if (t == 0) {
4706 /* Save ADDA parameters, turn Path A ADDA on */
4707 rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
4708 RTL8XXXU_ADDA_REGS);
4709 rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
4710 rtl8xxxu_save_regs(priv, iqk_bb_regs,
4711 priv->bb_backup, RTL8XXXU_BB_REGS);
4712 }
4713
4714 rtl8xxxu_path_adda_on(priv, adda_regs, true);
4715
4716 /* MAC settings */
4717 rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
4718
4719 val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
4720 val32 |= 0x0f000000;
4721 rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
4722
4723 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
4724 rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
4725 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
4726
4727#ifdef RTL8723BU_PATH_B
4728 /* Set RF mode to standby Path B */
4729 if (priv->tx_paths > 1)
4730 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x10000);
4731#endif
4732
4733#if 0
4734 /* Page B init */
4735 rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x0f600000);
4736
4737 if (priv->tx_paths > 1)
4738 rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x0f600000);
4739#endif
4740
4741 /*
4742 * RX IQ calibration setting for 8723B D cut large current issue
4743 * when leaving IPS
4744 */
4745 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4746 val32 &= 0x000000ff;
4747 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4748
4749 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
4750 val32 |= 0x80000;
4751 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
4752
4753 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
4754 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
4755 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7);
4756
4757 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED);
4758 val32 |= 0x20;
4759 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32);
4760
4761 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_43, 0x60fbd);
4762
4763 for (i = 0; i < retry; i++) {
4764 path_a_ok = rtl8723bu_iqk_path_a(priv);
4765 if (path_a_ok == 0x01) {
4766 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4767 val32 &= 0x000000ff;
4768 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4769
4770#if 0 /* Only needed in restore case, we may need this when going to suspend */
4771 priv->RFCalibrateInfo.TxLOK[RF_A] =
4772 rtl8xxxu_read_rfreg(priv, RF_A,
4773 RF6052_REG_TXM_IDAC);
4774#endif
4775
4776 val32 = rtl8xxxu_read32(priv,
4777 REG_TX_POWER_BEFORE_IQK_A);
4778 result[t][0] = (val32 >> 16) & 0x3ff;
4779 val32 = rtl8xxxu_read32(priv,
4780 REG_TX_POWER_AFTER_IQK_A);
4781 result[t][1] = (val32 >> 16) & 0x3ff;
4782
4783 break;
4784 }
4785 }
4786
4787 if (!path_a_ok)
4788 dev_dbg(dev, "%s: Path A TX IQK failed!\n", __func__);
4789
4790 for (i = 0; i < retry; i++) {
4791 path_a_ok = rtl8723bu_rx_iqk_path_a(priv);
4792 if (path_a_ok == 0x03) {
4793 val32 = rtl8xxxu_read32(priv,
4794 REG_RX_POWER_BEFORE_IQK_A_2);
4795 result[t][2] = (val32 >> 16) & 0x3ff;
4796 val32 = rtl8xxxu_read32(priv,
4797 REG_RX_POWER_AFTER_IQK_A_2);
4798 result[t][3] = (val32 >> 16) & 0x3ff;
4799
4800 break;
4801 }
4802 }
4803
4804 if (!path_a_ok)
4805 dev_dbg(dev, "%s: Path A RX IQK failed!\n", __func__);
4806
4807 if (priv->tx_paths > 1) {
4808#if 1
4809 dev_warn(dev, "%s: Path B not supported\n", __func__);
4810#else
4811
4812 /*
4813 * Path A into standby
4814 */
4815 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4816 val32 &= 0x000000ff;
4817 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4818 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x10000);
4819
4820 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4821 val32 &= 0x000000ff;
4822 val32 |= 0x80800000;
4823 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4824
4825 /* Turn Path B ADDA on */
4826 rtl8xxxu_path_adda_on(priv, adda_regs, false);
4827
4828 for (i = 0; i < retry; i++) {
4829 path_b_ok = rtl8xxxu_iqk_path_b(priv);
4830 if (path_b_ok == 0x03) {
4831 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
4832 result[t][4] = (val32 >> 16) & 0x3ff;
4833 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
4834 result[t][5] = (val32 >> 16) & 0x3ff;
4835 break;
4836 }
4837 }
4838
4839 if (!path_b_ok)
4840 dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
4841
4842 for (i = 0; i < retry; i++) {
4843 path_b_ok = rtl8723bu_rx_iqk_path_b(priv);
4844 if (path_a_ok == 0x03) {
4845 val32 = rtl8xxxu_read32(priv,
4846 REG_RX_POWER_BEFORE_IQK_B_2);
4847 result[t][6] = (val32 >> 16) & 0x3ff;
4848 val32 = rtl8xxxu_read32(priv,
4849 REG_RX_POWER_AFTER_IQK_B_2);
4850 result[t][7] = (val32 >> 16) & 0x3ff;
4851 break;
4852 }
4853 }
4854
4855 if (!path_b_ok)
4856 dev_dbg(dev, "%s: Path B RX IQK failed!\n", __func__);
4857#endif
4858 }
4859
4860 /* Back to BB mode, load original value */
4861 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
4862 val32 &= 0x000000ff;
4863 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
4864
4865 if (t) {
4866 /* Reload ADDA power saving parameters */
4867 rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
4868 RTL8XXXU_ADDA_REGS);
4869
4870 /* Reload MAC parameters */
4871 rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
4872
4873 /* Reload BB parameters */
4874 rtl8xxxu_restore_regs(priv, iqk_bb_regs,
4875 priv->bb_backup, RTL8XXXU_BB_REGS);
4876
4877 /* Restore RX initial gain */
4878 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1);
4879 val32 &= 0xffffff00;
4880 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | 0x50);
4881 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | xa_agc);
4882
4883 if (priv->tx_paths > 1) {
4884 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1);
4885 val32 &= 0xffffff00;
4886 rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1,
4887 val32 | 0x50);
4888 rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1,
4889 val32 | xb_agc);
4890 }
4891
4892 /* Load 0xe30 IQC default value */
4893 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
4894 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
4895 }
4896}
4897
Jes Sorensenc7a5a192016-02-29 17:04:30 -05004898static void rtl8xxxu_prepare_calibrate(struct rtl8xxxu_priv *priv, u8 start)
4899{
4900 struct h2c_cmd h2c;
4901
4902 if (priv->fops->mbox_ext_width < 4)
4903 return;
4904
4905 memset(&h2c, 0, sizeof(struct h2c_cmd));
4906 h2c.bt_wlan_calibration.cmd = H2C_8723B_BT_WLAN_CALIBRATION;
4907 h2c.bt_wlan_calibration.data = start;
4908
4909 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_wlan_calibration));
4910}
4911
Jes Sorensene1547c52016-02-29 17:04:35 -05004912static void rtl8723au_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004913{
4914 struct device *dev = &priv->udev->dev;
4915 int result[4][8]; /* last is final result */
4916 int i, candidate;
4917 bool path_a_ok, path_b_ok;
4918 u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
4919 u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
4920 s32 reg_tmp = 0;
4921 bool simu;
4922
Jes Sorensenc7a5a192016-02-29 17:04:30 -05004923 rtl8xxxu_prepare_calibrate(priv, 1);
4924
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004925 memset(result, 0, sizeof(result));
4926 candidate = -1;
4927
4928 path_a_ok = false;
4929 path_b_ok = false;
4930
4931 rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
4932
4933 for (i = 0; i < 3; i++) {
4934 rtl8xxxu_phy_iqcalibrate(priv, result, i);
4935
4936 if (i == 1) {
4937 simu = rtl8xxxu_simularity_compare(priv, result, 0, 1);
4938 if (simu) {
4939 candidate = 0;
4940 break;
4941 }
4942 }
4943
4944 if (i == 2) {
4945 simu = rtl8xxxu_simularity_compare(priv, result, 0, 2);
4946 if (simu) {
4947 candidate = 0;
4948 break;
4949 }
4950
4951 simu = rtl8xxxu_simularity_compare(priv, result, 1, 2);
4952 if (simu) {
4953 candidate = 1;
4954 } else {
4955 for (i = 0; i < 8; i++)
4956 reg_tmp += result[3][i];
4957
4958 if (reg_tmp)
4959 candidate = 3;
4960 else
4961 candidate = -1;
4962 }
4963 }
4964 }
4965
4966 for (i = 0; i < 4; i++) {
4967 reg_e94 = result[i][0];
4968 reg_e9c = result[i][1];
4969 reg_ea4 = result[i][2];
4970 reg_eac = result[i][3];
4971 reg_eb4 = result[i][4];
4972 reg_ebc = result[i][5];
4973 reg_ec4 = result[i][6];
4974 reg_ecc = result[i][7];
4975 }
4976
4977 if (candidate >= 0) {
4978 reg_e94 = result[candidate][0];
4979 priv->rege94 = reg_e94;
4980 reg_e9c = result[candidate][1];
4981 priv->rege9c = reg_e9c;
4982 reg_ea4 = result[candidate][2];
4983 reg_eac = result[candidate][3];
4984 reg_eb4 = result[candidate][4];
4985 priv->regeb4 = reg_eb4;
4986 reg_ebc = result[candidate][5];
4987 priv->regebc = reg_ebc;
4988 reg_ec4 = result[candidate][6];
4989 reg_ecc = result[candidate][7];
4990 dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
4991 dev_dbg(dev,
4992 "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
4993 "ecc=%x\n ", __func__, reg_e94, reg_e9c,
4994 reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
4995 path_a_ok = true;
4996 path_b_ok = true;
4997 } else {
4998 reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
4999 reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
5000 }
5001
5002 if (reg_e94 && candidate >= 0)
5003 rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
5004 candidate, (reg_ea4 == 0));
5005
5006 if (priv->tx_paths > 1 && reg_eb4)
5007 rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
5008 candidate, (reg_ec4 == 0));
5009
5010 rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg,
5011 priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
Jes Sorensenc7a5a192016-02-29 17:04:30 -05005012
5013 rtl8xxxu_prepare_calibrate(priv, 0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005014}
5015
Jes Sorensene1547c52016-02-29 17:04:35 -05005016static void rtl8723bu_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
5017{
5018 struct device *dev = &priv->udev->dev;
5019 int result[4][8]; /* last is final result */
5020 int i, candidate;
5021 bool path_a_ok, path_b_ok;
5022 u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
5023 u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
5024 u32 val32, bt_control;
5025 s32 reg_tmp = 0;
5026 bool simu;
5027
5028 rtl8xxxu_prepare_calibrate(priv, 1);
5029
5030 memset(result, 0, sizeof(result));
5031 candidate = -1;
5032
5033 path_a_ok = false;
5034 path_b_ok = false;
5035
5036 bt_control = rtl8xxxu_read32(priv, REG_BT_CONTROL_8723BU);
5037
5038 for (i = 0; i < 3; i++) {
5039 rtl8723bu_phy_iqcalibrate(priv, result, i);
5040
5041 if (i == 1) {
5042 simu = rtl8723bu_simularity_compare(priv, result, 0, 1);
5043 if (simu) {
5044 candidate = 0;
5045 break;
5046 }
5047 }
5048
5049 if (i == 2) {
5050 simu = rtl8723bu_simularity_compare(priv, result, 0, 2);
5051 if (simu) {
5052 candidate = 0;
5053 break;
5054 }
5055
5056 simu = rtl8723bu_simularity_compare(priv, result, 1, 2);
5057 if (simu) {
5058 candidate = 1;
5059 } else {
5060 for (i = 0; i < 8; i++)
5061 reg_tmp += result[3][i];
5062
5063 if (reg_tmp)
5064 candidate = 3;
5065 else
5066 candidate = -1;
5067 }
5068 }
5069 }
5070
5071 for (i = 0; i < 4; i++) {
5072 reg_e94 = result[i][0];
5073 reg_e9c = result[i][1];
5074 reg_ea4 = result[i][2];
5075 reg_eac = result[i][3];
5076 reg_eb4 = result[i][4];
5077 reg_ebc = result[i][5];
5078 reg_ec4 = result[i][6];
5079 reg_ecc = result[i][7];
5080 }
5081
5082 if (candidate >= 0) {
5083 reg_e94 = result[candidate][0];
5084 priv->rege94 = reg_e94;
5085 reg_e9c = result[candidate][1];
5086 priv->rege9c = reg_e9c;
5087 reg_ea4 = result[candidate][2];
5088 reg_eac = result[candidate][3];
5089 reg_eb4 = result[candidate][4];
5090 priv->regeb4 = reg_eb4;
5091 reg_ebc = result[candidate][5];
5092 priv->regebc = reg_ebc;
5093 reg_ec4 = result[candidate][6];
5094 reg_ecc = result[candidate][7];
5095 dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
5096 dev_dbg(dev,
5097 "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
5098 "ecc=%x\n ", __func__, reg_e94, reg_e9c,
5099 reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
5100 path_a_ok = true;
5101 path_b_ok = true;
5102 } else {
5103 reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
5104 reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
5105 }
5106
5107 if (reg_e94 && candidate >= 0)
5108 rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
5109 candidate, (reg_ea4 == 0));
5110
5111 if (priv->tx_paths > 1 && reg_eb4)
5112 rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
5113 candidate, (reg_ec4 == 0));
5114
5115 rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg,
5116 priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
5117
5118 rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, bt_control);
5119
5120 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT);
5121 val32 |= 0x80000;
5122 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32);
5123 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x18000);
5124 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f);
5125 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xe6177);
5126 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED);
5127 val32 |= 0x20;
5128 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32);
5129 rtl8xxxu_write_rfreg(priv, RF_A, 0x43, 0x300bd);
5130
5131 if (priv->rf_paths > 1) {
5132 dev_dbg(dev, "%s: beware 2T not yet supported\n", __func__);
5133#ifdef RTL8723BU_PATH_B
5134 if (RF_Path == 0x0) //S1
5135 ODM_SetIQCbyRFpath(pDM_Odm, 0);
5136 else //S0
5137 ODM_SetIQCbyRFpath(pDM_Odm, 1);
5138#endif
5139 }
5140 rtl8xxxu_prepare_calibrate(priv, 0);
5141}
5142
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005143static void rtl8723a_phy_lc_calibrate(struct rtl8xxxu_priv *priv)
5144{
5145 u32 val32;
5146 u32 rf_amode, rf_bmode = 0, lstf;
5147
5148 /* Check continuous TX and Packet TX */
5149 lstf = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
5150
5151 if (lstf & OFDM_LSTF_MASK) {
5152 /* Disable all continuous TX */
5153 val32 = lstf & ~OFDM_LSTF_MASK;
5154 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
5155
5156 /* Read original RF mode Path A */
5157 rf_amode = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_AC);
5158
5159 /* Set RF mode to standby Path A */
5160 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC,
5161 (rf_amode & 0x8ffff) | 0x10000);
5162
5163 /* Path-B */
5164 if (priv->tx_paths > 1) {
5165 rf_bmode = rtl8xxxu_read_rfreg(priv, RF_B,
5166 RF6052_REG_AC);
5167
5168 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
5169 (rf_bmode & 0x8ffff) | 0x10000);
5170 }
5171 } else {
5172 /* Deal with Packet TX case */
5173 /* block all queues */
5174 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
5175 }
5176
5177 /* Start LC calibration */
Jes Sorensen0d698de2016-02-29 17:04:36 -05005178 if (priv->fops->has_s0s1)
5179 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_S0S1, 0xdfbe0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005180 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_MODE_AG);
5181 val32 |= 0x08000;
5182 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, val32);
5183
5184 msleep(100);
5185
Jes Sorensen0d698de2016-02-29 17:04:36 -05005186 if (priv->fops->has_s0s1)
5187 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_S0S1, 0xdffe0);
5188
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005189 /* Restore original parameters */
5190 if (lstf & OFDM_LSTF_MASK) {
5191 /* Path-A */
5192 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, lstf);
5193 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, rf_amode);
5194
5195 /* Path-B */
5196 if (priv->tx_paths > 1)
5197 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
5198 rf_bmode);
5199 } else /* Deal with Packet TX case */
5200 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
5201}
5202
5203static int rtl8xxxu_set_mac(struct rtl8xxxu_priv *priv)
5204{
5205 int i;
5206 u16 reg;
5207
5208 reg = REG_MACID;
5209
5210 for (i = 0; i < ETH_ALEN; i++)
5211 rtl8xxxu_write8(priv, reg + i, priv->mac_addr[i]);
5212
5213 return 0;
5214}
5215
5216static int rtl8xxxu_set_bssid(struct rtl8xxxu_priv *priv, const u8 *bssid)
5217{
5218 int i;
5219 u16 reg;
5220
5221 dev_dbg(&priv->udev->dev, "%s: (%pM)\n", __func__, bssid);
5222
5223 reg = REG_BSSID;
5224
5225 for (i = 0; i < ETH_ALEN; i++)
5226 rtl8xxxu_write8(priv, reg + i, bssid[i]);
5227
5228 return 0;
5229}
5230
5231static void
5232rtl8xxxu_set_ampdu_factor(struct rtl8xxxu_priv *priv, u8 ampdu_factor)
5233{
5234 u8 vals[4] = { 0x41, 0xa8, 0x72, 0xb9 };
5235 u8 max_agg = 0xf;
5236 int i;
5237
5238 ampdu_factor = 1 << (ampdu_factor + 2);
5239 if (ampdu_factor > max_agg)
5240 ampdu_factor = max_agg;
5241
5242 for (i = 0; i < 4; i++) {
5243 if ((vals[i] & 0xf0) > (ampdu_factor << 4))
5244 vals[i] = (vals[i] & 0x0f) | (ampdu_factor << 4);
5245
5246 if ((vals[i] & 0x0f) > ampdu_factor)
5247 vals[i] = (vals[i] & 0xf0) | ampdu_factor;
5248
5249 rtl8xxxu_write8(priv, REG_AGGLEN_LMT + i, vals[i]);
5250 }
5251}
5252
5253static void rtl8xxxu_set_ampdu_min_space(struct rtl8xxxu_priv *priv, u8 density)
5254{
5255 u8 val8;
5256
5257 val8 = rtl8xxxu_read8(priv, REG_AMPDU_MIN_SPACE);
5258 val8 &= 0xf8;
5259 val8 |= density;
5260 rtl8xxxu_write8(priv, REG_AMPDU_MIN_SPACE, val8);
5261}
5262
5263static int rtl8xxxu_active_to_emu(struct rtl8xxxu_priv *priv)
5264{
5265 u8 val8;
5266 int count, ret;
5267
5268 /* Start of rtl8723AU_card_enable_flow */
5269 /* Act to Cardemu sequence*/
5270 /* Turn off RF */
5271 rtl8xxxu_write8(priv, REG_RF_CTRL, 0);
5272
5273 /* 0x004E[7] = 0, switch DPDT_SEL_P output from register 0x0065[2] */
5274 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
5275 val8 &= ~LEDCFG2_DPDT_SELECT;
5276 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
5277
5278 /* 0x0005[1] = 1 turn off MAC by HW state machine*/
5279 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5280 val8 |= BIT(1);
5281 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5282
5283 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5284 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5285 if ((val8 & BIT(1)) == 0)
5286 break;
5287 udelay(10);
5288 }
5289
5290 if (!count) {
5291 dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n",
5292 __func__);
5293 ret = -EBUSY;
5294 goto exit;
5295 }
5296
5297 /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */
5298 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5299 val8 |= SYS_ISO_ANALOG_IPS;
5300 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5301
5302 /* 0x0020[0] = 0 disable LDOA12 MACRO block*/
5303 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
5304 val8 &= ~LDOA15_ENABLE;
5305 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
5306
5307exit:
5308 return ret;
5309}
5310
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05005311static int rtl8723bu_active_to_emu(struct rtl8xxxu_priv *priv)
5312{
5313 u8 val8;
5314 u16 val16;
5315 u32 val32;
5316 int count, ret;
5317
5318 /* Turn off RF */
5319 rtl8xxxu_write8(priv, REG_RF_CTRL, 0);
5320
5321 /* Enable rising edge triggering interrupt */
5322 val16 = rtl8xxxu_read16(priv, REG_GPIO_INTM);
5323 val16 &= ~GPIO_INTM_EDGE_TRIG_IRQ;
5324 rtl8xxxu_write16(priv, REG_GPIO_INTM, val16);
5325
5326 /* Release WLON reset 0x04[16]= 1*/
5327 val32 = rtl8xxxu_read32(priv, REG_GPIO_INTM);
5328 val32 |= APS_FSMCO_WLON_RESET;
5329 rtl8xxxu_write32(priv, REG_GPIO_INTM, val32);
5330
5331 /* 0x0005[1] = 1 turn off MAC by HW state machine*/
5332 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5333 val8 |= BIT(1);
5334 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5335
5336 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5337 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5338 if ((val8 & BIT(1)) == 0)
5339 break;
5340 udelay(10);
5341 }
5342
5343 if (!count) {
5344 dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n",
5345 __func__);
5346 ret = -EBUSY;
5347 goto exit;
5348 }
5349
5350 /* Enable BT control XTAL setting */
5351 val8 = rtl8xxxu_read8(priv, REG_AFE_MISC);
5352 val8 &= ~AFE_MISC_WL_XTAL_CTRL;
5353 rtl8xxxu_write8(priv, REG_AFE_MISC, val8);
5354
5355 /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */
5356 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5357 val8 |= SYS_ISO_ANALOG_IPS;
5358 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5359
5360 /* 0x0020[0] = 0 disable LDOA12 MACRO block*/
5361 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
5362 val8 &= ~LDOA15_ENABLE;
5363 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
5364
5365exit:
5366 return ret;
5367}
5368
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005369static int rtl8xxxu_active_to_lps(struct rtl8xxxu_priv *priv)
5370{
5371 u8 val8;
5372 u8 val32;
5373 int count, ret;
5374
5375 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
5376
5377 /*
5378 * Poll - wait for RX packet to complete
5379 */
5380 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5381 val32 = rtl8xxxu_read32(priv, 0x5f8);
5382 if (!val32)
5383 break;
5384 udelay(10);
5385 }
5386
5387 if (!count) {
5388 dev_warn(&priv->udev->dev,
5389 "%s: RX poll timed out (0x05f8)\n", __func__);
5390 ret = -EBUSY;
5391 goto exit;
5392 }
5393
5394 /* Disable CCK and OFDM, clock gated */
5395 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
5396 val8 &= ~SYS_FUNC_BBRSTB;
5397 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
5398
5399 udelay(2);
5400
5401 /* Reset baseband */
5402 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
5403 val8 &= ~SYS_FUNC_BB_GLB_RSTN;
5404 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
5405
5406 /* Reset MAC TRX */
5407 val8 = rtl8xxxu_read8(priv, REG_CR);
5408 val8 = CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE;
5409 rtl8xxxu_write8(priv, REG_CR, val8);
5410
5411 /* Reset MAC TRX */
5412 val8 = rtl8xxxu_read8(priv, REG_CR + 1);
5413 val8 &= ~BIT(1); /* CR_SECURITY_ENABLE */
5414 rtl8xxxu_write8(priv, REG_CR + 1, val8);
5415
5416 /* Respond TX OK to scheduler */
5417 val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST);
5418 val8 |= DUAL_TSF_TX_OK;
5419 rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);
5420
5421exit:
5422 return ret;
5423}
5424
Jes Sorensenc05a9db2016-02-29 17:04:03 -05005425static void rtl8723a_disabled_to_emu(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005426{
5427 u8 val8;
5428
5429 /* Clear suspend enable and power down enable*/
5430 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5431 val8 &= ~(BIT(3) | BIT(7));
5432 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5433
5434 /* 0x48[16] = 0 to disable GPIO9 as EXT WAKEUP*/
5435 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
5436 val8 &= ~BIT(0);
5437 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
5438
5439 /* 0x04[12:11] = 11 enable WL suspend*/
5440 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5441 val8 &= ~(BIT(3) | BIT(4));
5442 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5443}
5444
Jes Sorensenc05a9db2016-02-29 17:04:03 -05005445static void rtl8192e_disabled_to_emu(struct rtl8xxxu_priv *priv)
5446{
5447 u8 val8;
5448
5449 /* Clear suspend enable and power down enable*/
5450 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5451 val8 &= ~(BIT(3) | BIT(4));
5452 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5453}
5454
5455static int rtl8192e_emu_to_active(struct rtl8xxxu_priv *priv)
5456{
5457 u8 val8;
5458 u32 val32;
5459 int count, ret = 0;
5460
5461 /* disable HWPDN 0x04[15]=0*/
5462 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5463 val8 &= ~BIT(7);
5464 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5465
5466 /* disable SW LPS 0x04[10]= 0 */
5467 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5468 val8 &= ~BIT(2);
5469 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5470
5471 /* disable WL suspend*/
5472 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5473 val8 &= ~(BIT(3) | BIT(4));
5474 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5475
5476 /* wait till 0x04[17] = 1 power ready*/
5477 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5478 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5479 if (val32 & BIT(17))
5480 break;
5481
5482 udelay(10);
5483 }
5484
5485 if (!count) {
5486 ret = -EBUSY;
5487 goto exit;
5488 }
5489
5490 /* We should be able to optimize the following three entries into one */
5491
5492 /* release WLON reset 0x04[16]= 1*/
5493 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
5494 val8 |= BIT(0);
5495 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
5496
5497 /* set, then poll until 0 */
5498 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5499 val32 |= APS_FSMCO_MAC_ENABLE;
5500 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5501
5502 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5503 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5504 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
5505 ret = 0;
5506 break;
5507 }
5508 udelay(10);
5509 }
5510
5511 if (!count) {
5512 ret = -EBUSY;
5513 goto exit;
5514 }
5515
5516exit:
5517 return ret;
5518}
5519
5520static int rtl8723a_emu_to_active(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005521{
5522 u8 val8;
5523 u32 val32;
5524 int count, ret = 0;
5525
5526 /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface*/
5527 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
5528 val8 |= LDOA15_ENABLE;
5529 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
5530
5531 /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/
5532 val8 = rtl8xxxu_read8(priv, 0x0067);
5533 val8 &= ~BIT(4);
5534 rtl8xxxu_write8(priv, 0x0067, val8);
5535
5536 mdelay(1);
5537
5538 /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */
5539 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5540 val8 &= ~SYS_ISO_ANALOG_IPS;
5541 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5542
5543 /* disable SW LPS 0x04[10]= 0 */
5544 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5545 val8 &= ~BIT(2);
5546 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5547
5548 /* wait till 0x04[17] = 1 power ready*/
5549 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5550 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5551 if (val32 & BIT(17))
5552 break;
5553
5554 udelay(10);
5555 }
5556
5557 if (!count) {
5558 ret = -EBUSY;
5559 goto exit;
5560 }
5561
5562 /* We should be able to optimize the following three entries into one */
5563
5564 /* release WLON reset 0x04[16]= 1*/
5565 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
5566 val8 |= BIT(0);
5567 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
5568
5569 /* disable HWPDN 0x04[15]= 0*/
5570 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5571 val8 &= ~BIT(7);
5572 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5573
5574 /* disable WL suspend*/
5575 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5576 val8 &= ~(BIT(3) | BIT(4));
5577 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5578
5579 /* set, then poll until 0 */
5580 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5581 val32 |= APS_FSMCO_MAC_ENABLE;
5582 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5583
5584 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5585 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5586 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
5587 ret = 0;
5588 break;
5589 }
5590 udelay(10);
5591 }
5592
5593 if (!count) {
5594 ret = -EBUSY;
5595 goto exit;
5596 }
5597
5598 /* 0x4C[23] = 0x4E[7] = 1, switch DPDT_SEL_P output from WL BB */
5599 /*
5600 * Note: Vendor driver actually clears this bit, despite the
5601 * documentation claims it's being set!
5602 */
5603 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
5604 val8 |= LEDCFG2_DPDT_SELECT;
5605 val8 &= ~LEDCFG2_DPDT_SELECT;
5606 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
5607
5608exit:
5609 return ret;
5610}
5611
Jes Sorensen42836db2016-02-29 17:04:52 -05005612static int rtl8723b_emu_to_active(struct rtl8xxxu_priv *priv)
5613{
5614 u8 val8;
5615 u32 val32;
5616 int count, ret = 0;
5617
5618 /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface */
5619 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
5620 val8 |= LDOA15_ENABLE;
5621 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
5622
5623 /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/
5624 val8 = rtl8xxxu_read8(priv, 0x0067);
5625 val8 &= ~BIT(4);
5626 rtl8xxxu_write8(priv, 0x0067, val8);
5627
5628 mdelay(1);
5629
5630 /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */
5631 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5632 val8 &= ~SYS_ISO_ANALOG_IPS;
5633 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5634
5635 /* Disable SW LPS 0x04[10]= 0 */
5636 val32 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
5637 val32 &= ~APS_FSMCO_SW_LPS;
5638 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5639
5640 /* Wait until 0x04[17] = 1 power ready */
5641 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5642 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5643 if (val32 & BIT(17))
5644 break;
5645
5646 udelay(10);
5647 }
5648
5649 if (!count) {
5650 ret = -EBUSY;
5651 goto exit;
5652 }
5653
5654 /* We should be able to optimize the following three entries into one */
5655
5656 /* Release WLON reset 0x04[16]= 1*/
5657 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5658 val32 |= APS_FSMCO_WLON_RESET;
5659 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5660
5661 /* Disable HWPDN 0x04[15]= 0*/
5662 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5663 val32 &= ~APS_FSMCO_HW_POWERDOWN;
5664 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5665
5666 /* Disable WL suspend*/
5667 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5668 val32 &= ~(APS_FSMCO_HW_SUSPEND | APS_FSMCO_PCIE);
5669 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5670
5671 /* Set, then poll until 0 */
5672 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5673 val32 |= APS_FSMCO_MAC_ENABLE;
5674 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
5675
5676 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
5677 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
5678 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
5679 ret = 0;
5680 break;
5681 }
5682 udelay(10);
5683 }
5684
5685 if (!count) {
5686 ret = -EBUSY;
5687 goto exit;
5688 }
5689
5690 /* Enable WL control XTAL setting */
5691 val8 = rtl8xxxu_read8(priv, REG_AFE_MISC);
5692 val8 |= AFE_MISC_WL_XTAL_CTRL;
5693 rtl8xxxu_write8(priv, REG_AFE_MISC, val8);
5694
5695 /* Enable falling edge triggering interrupt */
5696 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 1);
5697 val8 |= BIT(1);
5698 rtl8xxxu_write8(priv, REG_GPIO_INTM + 1, val8);
5699
5700 /* Enable GPIO9 interrupt mode */
5701 val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2 + 1);
5702 val8 |= BIT(1);
5703 rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2 + 1, val8);
5704
5705 /* Enable GPIO9 input mode */
5706 val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2);
5707 val8 &= ~BIT(1);
5708 rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2, val8);
5709
5710 /* Enable HSISR GPIO[C:0] interrupt */
5711 val8 = rtl8xxxu_read8(priv, REG_HSIMR);
5712 val8 |= BIT(0);
5713 rtl8xxxu_write8(priv, REG_HSIMR, val8);
5714
5715 /* Enable HSISR GPIO9 interrupt */
5716 val8 = rtl8xxxu_read8(priv, REG_HSIMR + 2);
5717 val8 |= BIT(1);
5718 rtl8xxxu_write8(priv, REG_HSIMR + 2, val8);
5719
5720 val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL);
5721 val8 |= MULTI_WIFI_HW_ROF_EN;
5722 rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL, val8);
5723
5724 /* For GPIO9 internal pull high setting BIT(14) */
5725 val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL + 1);
5726 val8 |= BIT(6);
5727 rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL + 1, val8);
5728
5729exit:
5730 return ret;
5731}
5732
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005733static int rtl8xxxu_emu_to_disabled(struct rtl8xxxu_priv *priv)
5734{
5735 u8 val8;
5736
5737 /* 0x0007[7:0] = 0x20 SOP option to disable BG/MB */
5738 rtl8xxxu_write8(priv, REG_APS_FSMCO + 3, 0x20);
5739
5740 /* 0x04[12:11] = 01 enable WL suspend */
5741 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5742 val8 &= ~BIT(4);
5743 val8 |= BIT(3);
5744 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5745
5746 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
5747 val8 |= BIT(7);
5748 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
5749
5750 /* 0x48[16] = 1 to enable GPIO9 as EXT wakeup */
5751 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
5752 val8 |= BIT(0);
5753 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
5754
5755 return 0;
5756}
5757
Jes Sorensen430b4542016-02-29 17:05:48 -05005758static int rtl8xxxu_flush_fifo(struct rtl8xxxu_priv *priv)
5759{
Jes Sorensen145428e2016-02-29 17:05:49 -05005760 struct device *dev = &priv->udev->dev;
Jes Sorensen430b4542016-02-29 17:05:48 -05005761 u32 val32;
5762 int retry, retval;
5763
5764 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
5765
5766 val32 = rtl8xxxu_read32(priv, REG_RXPKT_NUM);
5767 val32 |= RXPKT_NUM_RW_RELEASE_EN;
5768 rtl8xxxu_write32(priv, REG_RXPKT_NUM, val32);
5769
5770 retry = 100;
5771 retval = -EBUSY;
5772
5773 do {
5774 val32 = rtl8xxxu_read32(priv, REG_RXPKT_NUM);
5775 if (val32 & RXPKT_NUM_RXDMA_IDLE) {
5776 retval = 0;
5777 break;
5778 }
5779 } while (retry--);
5780
5781 rtl8xxxu_write16(priv, REG_RQPN_NPQ, 0);
5782 rtl8xxxu_write32(priv, REG_RQPN, 0x80000000);
5783 mdelay(2);
Jes Sorensen145428e2016-02-29 17:05:49 -05005784
5785 if (!retry)
5786 dev_warn(dev, "Failed to flush FIFO\n");
Jes Sorensen430b4542016-02-29 17:05:48 -05005787
5788 return retval;
5789}
5790
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005791static int rtl8723au_power_on(struct rtl8xxxu_priv *priv)
5792{
5793 u8 val8;
5794 u16 val16;
5795 u32 val32;
5796 int ret;
5797
5798 /*
5799 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
5800 */
5801 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
5802
Jes Sorensenc05a9db2016-02-29 17:04:03 -05005803 rtl8723a_disabled_to_emu(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005804
Jes Sorensenc05a9db2016-02-29 17:04:03 -05005805 ret = rtl8723a_emu_to_active(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005806 if (ret)
5807 goto exit;
5808
5809 /*
5810 * 0x0004[19] = 1, reset 8051
5811 */
5812 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
5813 val8 |= BIT(3);
5814 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
5815
5816 /*
5817 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
5818 * Set CR bit10 to enable 32k calibration.
5819 */
5820 val16 = rtl8xxxu_read16(priv, REG_CR);
5821 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
5822 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
5823 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
5824 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
5825 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
5826 rtl8xxxu_write16(priv, REG_CR, val16);
5827
5828 /* For EFuse PG */
5829 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
5830 val32 &= ~(BIT(28) | BIT(29) | BIT(30));
5831 val32 |= (0x06 << 28);
5832 rtl8xxxu_write32(priv, REG_EFUSE_CTRL, val32);
5833exit:
5834 return ret;
5835}
5836
Jes Sorensen42836db2016-02-29 17:04:52 -05005837static int rtl8723bu_power_on(struct rtl8xxxu_priv *priv)
5838{
5839 u8 val8;
5840 u16 val16;
5841 u32 val32;
5842 int ret;
5843
5844 rtl8723a_disabled_to_emu(priv);
5845
5846 ret = rtl8723b_emu_to_active(priv);
5847 if (ret)
5848 goto exit;
5849
5850 /*
5851 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
5852 * Set CR bit10 to enable 32k calibration.
5853 */
5854 val16 = rtl8xxxu_read16(priv, REG_CR);
5855 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
5856 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
5857 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
5858 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
5859 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
5860 rtl8xxxu_write16(priv, REG_CR, val16);
5861
5862 /*
5863 * BT coexist power on settings. This is identical for 1 and 2
5864 * antenna parts.
5865 */
5866 rtl8xxxu_write8(priv, REG_PAD_CTRL1 + 3, 0x20);
5867
5868 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
5869 val16 |= SYS_FUNC_BBRSTB | SYS_FUNC_BB_GLB_RSTN;
5870 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
5871
5872 rtl8xxxu_write8(priv, REG_BT_CONTROL_8723BU + 1, 0x18);
5873 rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04);
5874 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00);
5875 /* Antenna inverse */
5876 rtl8xxxu_write8(priv, 0xfe08, 0x01);
5877
5878 val16 = rtl8xxxu_read16(priv, REG_PWR_DATA);
5879 val16 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
5880 rtl8xxxu_write16(priv, REG_PWR_DATA, val16);
5881
5882 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
5883 val32 |= LEDCFG0_DPDT_SELECT;
5884 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
5885
5886 val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1);
5887 val8 &= ~PAD_CTRL1_SW_DPDT_SEL_DATA;
5888 rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8);
5889exit:
5890 return ret;
5891}
5892
Kalle Valoc0963772015-10-25 18:24:38 +02005893#ifdef CONFIG_RTL8XXXU_UNTESTED
5894
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005895static int rtl8192cu_power_on(struct rtl8xxxu_priv *priv)
5896{
5897 u8 val8;
5898 u16 val16;
5899 u32 val32;
5900 int i;
5901
5902 for (i = 100; i; i--) {
5903 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
5904 if (val8 & APS_FSMCO_PFM_ALDN)
5905 break;
5906 }
5907
5908 if (!i) {
5909 pr_info("%s: Poll failed\n", __func__);
5910 return -ENODEV;
5911 }
5912
5913 /*
5914 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
5915 */
5916 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
5917 rtl8xxxu_write8(priv, REG_SPS0_CTRL, 0x2b);
5918 udelay(100);
5919
5920 val8 = rtl8xxxu_read8(priv, REG_LDOV12D_CTRL);
5921 if (!(val8 & LDOV12D_ENABLE)) {
5922 pr_info("%s: Enabling LDOV12D (%02x)\n", __func__, val8);
5923 val8 |= LDOV12D_ENABLE;
5924 rtl8xxxu_write8(priv, REG_LDOV12D_CTRL, val8);
5925
5926 udelay(100);
5927
5928 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
5929 val8 &= ~SYS_ISO_MD2PP;
5930 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
5931 }
5932
5933 /*
5934 * Auto enable WLAN
5935 */
5936 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
5937 val16 |= APS_FSMCO_MAC_ENABLE;
5938 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
5939
5940 for (i = 1000; i; i--) {
5941 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
5942 if (!(val16 & APS_FSMCO_MAC_ENABLE))
5943 break;
5944 }
5945 if (!i) {
5946 pr_info("%s: FSMCO_MAC_ENABLE poll failed\n", __func__);
5947 return -EBUSY;
5948 }
5949
5950 /*
5951 * Enable radio, GPIO, LED
5952 */
5953 val16 = APS_FSMCO_HW_SUSPEND | APS_FSMCO_ENABLE_POWERDOWN |
5954 APS_FSMCO_PFM_ALDN;
5955 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
5956
5957 /*
5958 * Release RF digital isolation
5959 */
5960 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
5961 val16 &= ~SYS_ISO_DIOR;
5962 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
5963
5964 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
5965 val8 &= ~APSD_CTRL_OFF;
5966 rtl8xxxu_write8(priv, REG_APSD_CTRL, val8);
5967 for (i = 200; i; i--) {
5968 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
5969 if (!(val8 & APSD_CTRL_OFF_STATUS))
5970 break;
5971 }
5972
5973 if (!i) {
5974 pr_info("%s: APSD_CTRL poll failed\n", __func__);
5975 return -EBUSY;
5976 }
5977
5978 /*
5979 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
5980 */
5981 val16 = rtl8xxxu_read16(priv, REG_CR);
5982 val16 |= CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
5983 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | CR_PROTOCOL_ENABLE |
5984 CR_SCHEDULE_ENABLE | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE;
5985 rtl8xxxu_write16(priv, REG_CR, val16);
5986
5987 /*
5988 * Workaround for 8188RU LNA power leakage problem.
5989 */
Jes Sorensenba17d822016-03-31 17:08:39 -04005990 if (priv->rtl_chip == RTL8188C && priv->hi_pa) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005991 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
5992 val32 &= ~BIT(1);
5993 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
5994 }
5995 return 0;
5996}
5997
Kalle Valoc0963772015-10-25 18:24:38 +02005998#endif
5999
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006000static int rtl8192eu_power_on(struct rtl8xxxu_priv *priv)
6001{
6002 u16 val16;
6003 u32 val32;
6004 int ret;
6005
6006 ret = 0;
6007
6008 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
6009 if (val32 & SYS_CFG_SPS_LDO_SEL) {
6010 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0xc3);
6011 } else {
6012 /*
6013 * Raise 1.2V voltage
6014 */
6015 val32 = rtl8xxxu_read32(priv, REG_8192E_LDOV12_CTRL);
6016 val32 &= 0xff0fffff;
6017 val32 |= 0x00500000;
6018 rtl8xxxu_write32(priv, REG_8192E_LDOV12_CTRL, val32);
6019 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0x83);
6020 }
6021
6022 rtl8192e_disabled_to_emu(priv);
6023
6024 ret = rtl8192e_emu_to_active(priv);
6025 if (ret)
6026 goto exit;
6027
6028 rtl8xxxu_write16(priv, REG_CR, 0x0000);
6029
6030 /*
6031 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
6032 * Set CR bit10 to enable 32k calibration.
6033 */
6034 val16 = rtl8xxxu_read16(priv, REG_CR);
6035 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
6036 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
6037 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
6038 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
6039 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
6040 rtl8xxxu_write16(priv, REG_CR, val16);
6041
6042exit:
6043 return ret;
6044}
6045
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006046static void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv)
6047{
6048 u8 val8;
6049 u16 val16;
6050 u32 val32;
6051
6052 /*
6053 * Workaround for 8188RU LNA power leakage problem.
6054 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006055 if (priv->rtl_chip == RTL8188C && priv->hi_pa) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006056 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
6057 val32 |= BIT(1);
6058 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
6059 }
6060
Jes Sorensen430b4542016-02-29 17:05:48 -05006061 rtl8xxxu_flush_fifo(priv);
6062
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006063 rtl8xxxu_active_to_lps(priv);
6064
6065 /* Turn off RF */
6066 rtl8xxxu_write8(priv, REG_RF_CTRL, 0x00);
6067
6068 /* Reset Firmware if running in RAM */
6069 if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
6070 rtl8xxxu_firmware_self_reset(priv);
6071
6072 /* Reset MCU */
6073 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
6074 val16 &= ~SYS_FUNC_CPU_ENABLE;
6075 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
6076
6077 /* Reset MCU ready status */
6078 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
6079
6080 rtl8xxxu_active_to_emu(priv);
6081 rtl8xxxu_emu_to_disabled(priv);
6082
6083 /* Reset MCU IO Wrapper */
6084 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
6085 val8 &= ~BIT(0);
6086 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
6087
6088 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
6089 val8 |= BIT(0);
6090 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
6091
6092 /* RSV_CTRL 0x1C[7:0] = 0x0e lock ISO/CLK/Power control register */
6093 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0e);
6094}
6095
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006096static void rtl8723bu_power_off(struct rtl8xxxu_priv *priv)
6097{
6098 u8 val8;
6099 u16 val16;
6100
Jes Sorensen430b4542016-02-29 17:05:48 -05006101 rtl8xxxu_flush_fifo(priv);
6102
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006103 /*
6104 * Disable TX report timer
6105 */
6106 val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL);
6107 val8 &= ~TX_REPORT_CTRL_TIMER_ENABLE;
6108 rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8);
6109
6110 rtl8xxxu_write16(priv, REG_CR, 0x0000);
6111
6112 rtl8xxxu_active_to_lps(priv);
6113
6114 /* Reset Firmware if running in RAM */
6115 if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
6116 rtl8xxxu_firmware_self_reset(priv);
6117
6118 /* Reset MCU */
6119 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
6120 val16 &= ~SYS_FUNC_CPU_ENABLE;
6121 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
6122
6123 /* Reset MCU ready status */
6124 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
6125
6126 rtl8723bu_active_to_emu(priv);
6127 rtl8xxxu_emu_to_disabled(priv);
6128}
6129
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006130#ifdef NEED_PS_TDMA
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006131static void rtl8723bu_set_ps_tdma(struct rtl8xxxu_priv *priv,
6132 u8 arg1, u8 arg2, u8 arg3, u8 arg4, u8 arg5)
6133{
6134 struct h2c_cmd h2c;
6135
6136 memset(&h2c, 0, sizeof(struct h2c_cmd));
6137 h2c.b_type_dma.cmd = H2C_8723B_B_TYPE_TDMA;
6138 h2c.b_type_dma.data1 = arg1;
6139 h2c.b_type_dma.data2 = arg2;
6140 h2c.b_type_dma.data3 = arg3;
6141 h2c.b_type_dma.data4 = arg4;
6142 h2c.b_type_dma.data5 = arg5;
6143 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.b_type_dma));
6144}
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006145#endif
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006146
Jes Sorensen0290e7d2016-02-29 17:05:44 -05006147static void rtl8723b_enable_rf(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006148{
Jes Sorensenf37e9222016-02-29 17:04:41 -05006149 struct h2c_cmd h2c;
6150 u32 val32;
6151 u8 val8;
6152
6153 /*
6154 * No indication anywhere as to what 0x0790 does. The 2 antenna
6155 * vendor code preserves bits 6-7 here.
6156 */
6157 rtl8xxxu_write8(priv, 0x0790, 0x05);
6158 /*
6159 * 0x0778 seems to be related to enabling the number of antennas
6160 * In the vendor driver halbtc8723b2ant_InitHwConfig() sets it
6161 * to 0x03, while halbtc8723b1ant_InitHwConfig() sets it to 0x01
6162 */
6163 rtl8xxxu_write8(priv, 0x0778, 0x01);
6164
6165 val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG);
6166 val8 |= BIT(5);
6167 rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8);
6168
6169 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_IQADJ_G1, 0x780);
6170
Jes Sorensen394f1bd2016-02-29 17:04:49 -05006171 rtl8723bu_write_btreg(priv, 0x3c, 0x15); /* BT TRx Mask on */
6172
Jes Sorensenf37e9222016-02-29 17:04:41 -05006173 /*
6174 * Set BT grant to low
6175 */
6176 memset(&h2c, 0, sizeof(struct h2c_cmd));
6177 h2c.bt_grant.cmd = H2C_8723B_BT_GRANT;
6178 h2c.bt_grant.data = 0;
6179 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_grant));
6180
6181 /*
6182 * WLAN action by PTA
6183 */
Jes Sorensenfc1c89b2016-02-29 17:05:12 -05006184 rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04);
Jes Sorensenf37e9222016-02-29 17:04:41 -05006185
6186 /*
6187 * BT select S0/S1 controlled by WiFi
6188 */
6189 val8 = rtl8xxxu_read8(priv, 0x0067);
6190 val8 |= BIT(5);
6191 rtl8xxxu_write8(priv, 0x0067, val8);
6192
6193 val32 = rtl8xxxu_read32(priv, REG_PWR_DATA);
Jes Sorensen37f44dc2016-02-29 17:05:45 -05006194 val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
Jes Sorensenf37e9222016-02-29 17:04:41 -05006195 rtl8xxxu_write32(priv, REG_PWR_DATA, val32);
6196
6197 /*
6198 * Bits 6/7 are marked in/out ... but for what?
6199 */
6200 rtl8xxxu_write8(priv, 0x0974, 0xff);
6201
Jes Sorensen120e6272016-02-29 17:05:14 -05006202 val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER);
Jes Sorensenf37e9222016-02-29 17:04:41 -05006203 val32 |= (BIT(0) | BIT(1));
Jes Sorensen120e6272016-02-29 17:05:14 -05006204 rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32);
Jes Sorensenf37e9222016-02-29 17:04:41 -05006205
6206 rtl8xxxu_write8(priv, REG_RFE_CTRL_ANTA_SRC, 0x77);
6207
6208 val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
6209 val32 &= ~BIT(24);
6210 val32 |= BIT(23);
6211 rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
6212
6213 /*
6214 * Fix external switch Main->S1, Aux->S0
6215 */
6216 val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1);
6217 val8 &= ~BIT(0);
6218 rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8);
6219
6220 memset(&h2c, 0, sizeof(struct h2c_cmd));
6221 h2c.ant_sel_rsv.cmd = H2C_8723B_ANT_SEL_RSV;
6222 h2c.ant_sel_rsv.ant_inverse = 1;
6223 h2c.ant_sel_rsv.int_switch_type = 0;
6224 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ant_sel_rsv));
6225
6226 /*
6227 * 0x280, 0x00, 0x200, 0x80 - not clear
6228 */
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006229 rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00);
6230
6231 /*
6232 * Software control, antenna at WiFi side
6233 */
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006234#ifdef NEED_PS_TDMA
Jes Sorensena228a5d2016-02-29 17:04:45 -05006235 rtl8723bu_set_ps_tdma(priv, 0x08, 0x00, 0x00, 0x00, 0x00);
Jes Sorensena3a5dac2016-02-29 17:05:16 -05006236#endif
6237
6238 rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555);
6239 rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x55555555);
6240 rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
6241 rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
Jes Sorensen3ca7b322016-02-29 17:04:43 -05006242
Jes Sorensen6b9eae02016-02-29 17:04:50 -05006243 memset(&h2c, 0, sizeof(struct h2c_cmd));
6244 h2c.bt_info.cmd = H2C_8723B_BT_INFO;
6245 h2c.bt_info.data = BIT(0);
6246 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_info));
6247
Jes Sorensen6b9eae02016-02-29 17:04:50 -05006248 memset(&h2c, 0, sizeof(struct h2c_cmd));
6249 h2c.ignore_wlan.cmd = H2C_8723B_BT_IGNORE_WLANACT;
6250 h2c.ignore_wlan.data = 0;
6251 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ignore_wlan));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006252}
6253
Jes Sorensenfc89a412016-02-29 17:05:46 -05006254static void rtl8723b_disable_rf(struct rtl8xxxu_priv *priv)
6255{
6256 u32 val32;
6257
6258 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
6259
6260 val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA);
6261 val32 &= ~(BIT(22) | BIT(23));
6262 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32);
6263}
6264
Jes Sorensen3e88ca42016-02-29 17:05:08 -05006265static void rtl8723bu_init_aggregation(struct rtl8xxxu_priv *priv)
6266{
6267 u32 agg_rx;
6268 u8 agg_ctrl;
6269
6270 /*
6271 * For now simply disable RX aggregation
6272 */
6273 agg_ctrl = rtl8xxxu_read8(priv, REG_TRXDMA_CTRL);
6274 agg_ctrl &= ~TRXDMA_CTRL_RXDMA_AGG_EN;
6275
6276 agg_rx = rtl8xxxu_read32(priv, REG_RXDMA_AGG_PG_TH);
6277 agg_rx &= ~RXDMA_USB_AGG_ENABLE;
6278 agg_rx &= ~0xff0f;
6279
6280 rtl8xxxu_write8(priv, REG_TRXDMA_CTRL, agg_ctrl);
6281 rtl8xxxu_write32(priv, REG_RXDMA_AGG_PG_TH, agg_rx);
6282}
6283
Jes Sorensen9c79bf92016-02-29 17:05:10 -05006284static void rtl8723bu_init_statistics(struct rtl8xxxu_priv *priv)
6285{
6286 u32 val32;
6287
6288 /* Time duration for NHM unit: 4us, 0x2710=40ms */
6289 rtl8xxxu_write16(priv, REG_NHM_TIMER_8723B + 2, 0x2710);
6290 rtl8xxxu_write16(priv, REG_NHM_TH9_TH10_8723B + 2, 0xffff);
6291 rtl8xxxu_write32(priv, REG_NHM_TH3_TO_TH0_8723B, 0xffffff52);
6292 rtl8xxxu_write32(priv, REG_NHM_TH7_TO_TH4_8723B, 0xffffffff);
6293 /* TH8 */
6294 val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
6295 val32 |= 0xff;
6296 rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
6297 /* Enable CCK */
6298 val32 = rtl8xxxu_read32(priv, REG_NHM_TH9_TH10_8723B);
6299 val32 |= BIT(8) | BIT(9) | BIT(10);
6300 rtl8xxxu_write32(priv, REG_NHM_TH9_TH10_8723B, val32);
6301 /* Max power amongst all RX antennas */
6302 val32 = rtl8xxxu_read32(priv, REG_OFDM0_FA_RSTC);
6303 val32 |= BIT(7);
6304 rtl8xxxu_write32(priv, REG_OFDM0_FA_RSTC, val32);
6305}
6306
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006307static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
6308{
6309 struct rtl8xxxu_priv *priv = hw->priv;
6310 struct device *dev = &priv->udev->dev;
6311 struct rtl8xxxu_rfregval *rftable;
6312 bool macpower;
6313 int ret;
6314 u8 val8;
6315 u16 val16;
6316 u32 val32;
6317
6318 /* Check if MAC is already powered on */
6319 val8 = rtl8xxxu_read8(priv, REG_CR);
6320
6321 /*
6322 * Fix 92DU-VC S3 hang with the reason is that secondary mac is not
6323 * initialized. First MAC returns 0xea, second MAC returns 0x00
6324 */
6325 if (val8 == 0xea)
6326 macpower = false;
6327 else
6328 macpower = true;
6329
6330 ret = priv->fops->power_on(priv);
6331 if (ret < 0) {
6332 dev_warn(dev, "%s: Failed power on\n", __func__);
6333 goto exit;
6334 }
6335
6336 dev_dbg(dev, "%s: macpower %i\n", __func__, macpower);
6337 if (!macpower) {
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006338 ret = priv->fops->llt_init(priv, TX_TOTAL_PAGE_NUM);
6339 if (ret) {
6340 dev_warn(dev, "%s: LLT table init failed\n", __func__);
6341 goto exit;
6342 }
6343
6344 /*
6345 * Presumably this is for 8188EU as well
6346 * Enable TX report and TX report timer
6347 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006348 if (priv->rtl_chip == RTL8723B) {
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006349 val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL);
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006350 val8 |= TX_REPORT_CTRL_TIMER_ENABLE;
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006351 rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8);
6352 /* Set MAX RPT MACID */
6353 rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1, 0x02);
6354 /* TX report Timer. Unit: 32us */
6355 rtl8xxxu_write16(priv, REG_TX_REPORT_TIME, 0xcdf0);
Jes Sorensen360157e2016-02-29 17:04:57 -05006356
6357 /* tmp ps ? */
6358 val8 = rtl8xxxu_read8(priv, 0xa3);
6359 val8 &= 0xf8;
6360 rtl8xxxu_write8(priv, 0xa3, val8);
Jes Sorensen79fb5fe2016-02-29 17:04:53 -05006361 }
Jes Sorensen07bb46b2016-02-29 17:04:05 -05006362 }
6363
Jes Sorensena47b9d42016-02-29 17:04:06 -05006364 ret = rtl8xxxu_download_firmware(priv);
6365 dev_dbg(dev, "%s: download_fiwmare %i\n", __func__, ret);
6366 if (ret)
6367 goto exit;
6368 ret = rtl8xxxu_start_firmware(priv);
6369 dev_dbg(dev, "%s: start_fiwmare %i\n", __func__, ret);
6370 if (ret)
6371 goto exit;
6372
Jes Sorensen6431ea02016-02-29 17:04:21 -05006373 /* Solve too many protocol error on USB bus */
6374 /* Can't do this for 8188/8192 UMC A cut parts */
Jes Sorensenba17d822016-03-31 17:08:39 -04006375 if (priv->rtl_chip == RTL8723A ||
6376 ((priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C ||
6377 priv->rtl_chip == RTL8188C) &&
Jes Sorensen6431ea02016-02-29 17:04:21 -05006378 (priv->chip_cut || !priv->vendor_umc))) {
6379 rtl8xxxu_write8(priv, 0xfe40, 0xe6);
6380 rtl8xxxu_write8(priv, 0xfe41, 0x94);
6381 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6382
6383 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
6384 rtl8xxxu_write8(priv, 0xfe41, 0x19);
6385 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6386
6387 rtl8xxxu_write8(priv, 0xfe40, 0xe5);
6388 rtl8xxxu_write8(priv, 0xfe41, 0x91);
6389 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6390
6391 rtl8xxxu_write8(priv, 0xfe40, 0xe2);
6392 rtl8xxxu_write8(priv, 0xfe41, 0x81);
6393 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6394 }
6395
Jes Sorensenba17d822016-03-31 17:08:39 -04006396 if (priv->rtl_chip == RTL8192E) {
Jes Sorensen99ad16c2016-02-29 17:04:09 -05006397 rtl8xxxu_write32(priv, REG_HIMR0, 0x00);
6398 rtl8xxxu_write32(priv, REG_HIMR1, 0x00);
Jes Sorensenb63d0aa2016-02-29 17:04:08 -05006399 }
6400
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05006401 if (priv->fops->phy_init_antenna_selection)
6402 priv->fops->phy_init_antenna_selection(priv);
6403
Jes Sorensenc606e662016-04-07 14:19:16 -04006404 ret = rtl8xxxu_init_mac(priv);
Jes Sorensenb7dd8ff2016-02-29 17:04:17 -05006405
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006406 dev_dbg(dev, "%s: init_mac %i\n", __func__, ret);
6407 if (ret)
6408 goto exit;
6409
6410 ret = rtl8xxxu_init_phy_bb(priv);
6411 dev_dbg(dev, "%s: init_phy_bb %i\n", __func__, ret);
6412 if (ret)
6413 goto exit;
6414
Jes Sorensenba17d822016-03-31 17:08:39 -04006415 switch(priv->rtl_chip) {
6416 case RTL8723A:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006417 rftable = rtl8723au_radioa_1t_init_table;
6418 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6419 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006420 case RTL8723B:
Jes Sorensen22a31d42016-02-29 17:04:15 -05006421 rftable = rtl8723bu_radioa_1t_init_table;
6422 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
Jes Sorensen5ac61782016-02-29 17:05:05 -05006423 /*
6424 * PHY LCK
6425 */
6426 rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdfbe0);
6427 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, 0x8c01);
6428 msleep(200);
6429 rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdffe0);
Jes Sorensen22a31d42016-02-29 17:04:15 -05006430 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006431 case RTL8188C:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006432 if (priv->hi_pa)
6433 rftable = rtl8188ru_radioa_1t_highpa_table;
6434 else
6435 rftable = rtl8192cu_radioa_1t_init_table;
6436 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6437 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006438 case RTL8191C:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006439 rftable = rtl8192cu_radioa_1t_init_table;
6440 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6441 break;
Jes Sorensenba17d822016-03-31 17:08:39 -04006442 case RTL8192C:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006443 rftable = rtl8192cu_radioa_2t_init_table;
6444 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
6445 if (ret)
6446 break;
6447 rftable = rtl8192cu_radiob_2t_init_table;
6448 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B);
6449 break;
6450 default:
6451 ret = -EINVAL;
6452 }
6453
6454 if (ret)
6455 goto exit;
6456
Jes Sorensen2f109c82016-02-29 17:05:07 -05006457 /*
6458 * Chip specific quirks
6459 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006460 if (priv->rtl_chip == RTL8723A) {
Jes Sorensen2f109c82016-02-29 17:05:07 -05006461 /* Fix USB interface interference issue */
6462 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
6463 rtl8xxxu_write8(priv, 0xfe41, 0x8d);
6464 rtl8xxxu_write8(priv, 0xfe42, 0x80);
6465 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320);
6466
6467 /* Reduce 80M spur */
Jes Sorensenf30ed672016-02-29 17:04:59 -05006468 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d);
6469 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
6470 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82);
6471 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
Jes Sorensen2f109c82016-02-29 17:05:07 -05006472 } else {
6473 val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK);
6474 val32 |= TXDMA_OFFSET_DROP_DATA_EN;
6475 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32);
Jes Sorensenf30ed672016-02-29 17:04:59 -05006476 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006477
Jes Sorensenf2a41632016-02-29 17:05:09 -05006478 if (!macpower) {
Jes Sorensen1f1b20f2016-02-29 17:05:00 -05006479 if (priv->ep_tx_normal_queue)
6480 val8 = TX_PAGE_NUM_NORM_PQ;
6481 else
6482 val8 = 0;
6483
6484 rtl8xxxu_write8(priv, REG_RQPN_NPQ, val8);
6485
6486 val32 = (TX_PAGE_NUM_PUBQ << RQPN_NORM_PQ_SHIFT) | RQPN_LOAD;
6487
6488 if (priv->ep_tx_high_queue)
6489 val32 |= (TX_PAGE_NUM_HI_PQ << RQPN_HI_PQ_SHIFT);
6490 if (priv->ep_tx_low_queue)
6491 val32 |= (TX_PAGE_NUM_LO_PQ << RQPN_LO_PQ_SHIFT);
6492
6493 rtl8xxxu_write32(priv, REG_RQPN, val32);
6494
6495 /*
6496 * Set TX buffer boundary
6497 */
Jes Sorensen80805aa2016-04-07 14:19:18 -04006498 if (priv->rtl_chip == RTL8192E)
6499 val8 = TX_TOTAL_PAGE_NUM_8192E + 1;
6500 else
6501 val8 = TX_TOTAL_PAGE_NUM + 1;
Jes Sorensen1f1b20f2016-02-29 17:05:00 -05006502
Jes Sorensenba17d822016-03-31 17:08:39 -04006503 if (priv->rtl_chip == RTL8723B)
Jes Sorensen1f1b20f2016-02-29 17:05:00 -05006504 val8 -= 1;
6505
6506 rtl8xxxu_write8(priv, REG_TXPKTBUF_BCNQ_BDNY, val8);
6507 rtl8xxxu_write8(priv, REG_TXPKTBUF_MGQ_BDNY, val8);
6508 rtl8xxxu_write8(priv, REG_TXPKTBUF_WMAC_LBK_BF_HD, val8);
6509 rtl8xxxu_write8(priv, REG_TRXFF_BNDY, val8);
6510 rtl8xxxu_write8(priv, REG_TDECTRL + 1, val8);
6511 }
6512
6513 ret = rtl8xxxu_init_queue_priority(priv);
6514 dev_dbg(dev, "%s: init_queue_priority %i\n", __func__, ret);
6515 if (ret)
6516 goto exit;
6517
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006518 /* RFSW Control - clear bit 14 ?? */
Jes Sorensenba17d822016-03-31 17:08:39 -04006519 if (priv->rtl_chip != RTL8723B)
Jes Sorensenb87212c2016-02-29 17:05:01 -05006520 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, 0x00000003);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006521 /* 0x07000760 */
6522 val32 = FPGA0_RF_TRSW | FPGA0_RF_TRSWB | FPGA0_RF_ANTSW |
6523 FPGA0_RF_ANTSWB | FPGA0_RF_PAPE |
6524 ((FPGA0_RF_ANTSW | FPGA0_RF_ANTSWB | FPGA0_RF_PAPE) <<
6525 FPGA0_RF_BD_CTRL_SHIFT);
6526 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
6527 /* 0x860[6:5]= 00 - why? - this sets antenna B */
6528 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, 0x66F60210);
6529
6530 priv->rf_mode_ag[0] = rtl8xxxu_read_rfreg(priv, RF_A,
6531 RF6052_REG_MODE_AG);
6532
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006533 /*
6534 * Set RX page boundary
6535 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006536 if (priv->rtl_chip == RTL8723B)
Jes Sorensenfadfa042016-02-29 17:05:02 -05006537 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x3f7f);
Jes Sorensen80805aa2016-04-07 14:19:18 -04006538 else if (priv->rtl_chip == RTL8192E)
6539 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x3cff);
Jes Sorensenfadfa042016-02-29 17:05:02 -05006540 else
6541 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x27ff);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006542 /*
6543 * Transfer page size is always 128
6544 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006545 if (priv->rtl_chip == RTL8723B)
Jes Sorensenb87212c2016-02-29 17:05:01 -05006546 val8 = (PBP_PAGE_SIZE_256 << PBP_PAGE_SIZE_RX_SHIFT) |
6547 (PBP_PAGE_SIZE_256 << PBP_PAGE_SIZE_TX_SHIFT);
6548 else
6549 val8 = (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_RX_SHIFT) |
6550 (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_TX_SHIFT);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006551 rtl8xxxu_write8(priv, REG_PBP, val8);
6552
6553 /*
6554 * Unit in 8 bytes, not obvious what it is used for
6555 */
6556 rtl8xxxu_write8(priv, REG_RX_DRVINFO_SZ, 4);
6557
6558 /*
6559 * Enable all interrupts - not obvious USB needs to do this
6560 */
6561 rtl8xxxu_write32(priv, REG_HISR, 0xffffffff);
6562 rtl8xxxu_write32(priv, REG_HIMR, 0xffffffff);
6563
6564 rtl8xxxu_set_mac(priv);
6565 rtl8xxxu_set_linktype(priv, NL80211_IFTYPE_STATION);
6566
6567 /*
6568 * Configure initial WMAC settings
6569 */
6570 val32 = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_MCAST | RCR_ACCEPT_BCAST |
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006571 RCR_ACCEPT_MGMT_FRAME | RCR_HTC_LOC_CTRL |
6572 RCR_APPEND_PHYSTAT | RCR_APPEND_ICV | RCR_APPEND_MIC;
6573 rtl8xxxu_write32(priv, REG_RCR, val32);
6574
6575 /*
6576 * Accept all multicast
6577 */
6578 rtl8xxxu_write32(priv, REG_MAR, 0xffffffff);
6579 rtl8xxxu_write32(priv, REG_MAR + 4, 0xffffffff);
6580
6581 /*
6582 * Init adaptive controls
6583 */
6584 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
6585 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
6586 val32 |= RESPONSE_RATE_RRSR_CCK_ONLY_1M;
6587 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
6588
6589 /* CCK = 0x0a, OFDM = 0x10 */
6590 rtl8xxxu_set_spec_sifs(priv, 0x10, 0x10);
6591 rtl8xxxu_set_retry(priv, 0x30, 0x30);
6592 rtl8xxxu_set_spec_sifs(priv, 0x0a, 0x10);
6593
6594 /*
6595 * Init EDCA
6596 */
6597 rtl8xxxu_write16(priv, REG_MAC_SPEC_SIFS, 0x100a);
6598
6599 /* Set CCK SIFS */
6600 rtl8xxxu_write16(priv, REG_SIFS_CCK, 0x100a);
6601
6602 /* Set OFDM SIFS */
6603 rtl8xxxu_write16(priv, REG_SIFS_OFDM, 0x100a);
6604
6605 /* TXOP */
6606 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, 0x005ea42b);
6607 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, 0x0000a44f);
6608 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, 0x005ea324);
6609 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, 0x002fa226);
6610
6611 /* Set data auto rate fallback retry count */
6612 rtl8xxxu_write32(priv, REG_DARFRC, 0x00000000);
6613 rtl8xxxu_write32(priv, REG_DARFRC + 4, 0x10080404);
6614 rtl8xxxu_write32(priv, REG_RARFRC, 0x04030201);
6615 rtl8xxxu_write32(priv, REG_RARFRC + 4, 0x08070605);
6616
6617 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL);
6618 val8 |= FWHW_TXQ_CTRL_AMPDU_RETRY;
6619 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, val8);
6620
6621 /* Set ACK timeout */
6622 rtl8xxxu_write8(priv, REG_ACKTO, 0x40);
6623
6624 /*
6625 * Initialize beacon parameters
6626 */
6627 val16 = BEACON_DISABLE_TSF_UPDATE | (BEACON_DISABLE_TSF_UPDATE << 8);
6628 rtl8xxxu_write16(priv, REG_BEACON_CTRL, val16);
6629 rtl8xxxu_write16(priv, REG_TBTT_PROHIBIT, 0x6404);
6630 rtl8xxxu_write8(priv, REG_DRIVER_EARLY_INT, DRIVER_EARLY_INT_TIME);
6631 rtl8xxxu_write8(priv, REG_BEACON_DMA_TIME, BEACON_DMA_ATIME_INT_TIME);
6632 rtl8xxxu_write16(priv, REG_BEACON_TCFG, 0x660F);
6633
6634 /*
Jes Sorensenc3690602016-02-29 17:05:03 -05006635 * Initialize burst parameters
6636 */
Jes Sorensenba17d822016-03-31 17:08:39 -04006637 if (priv->rtl_chip == RTL8723B) {
Jes Sorensenc3690602016-02-29 17:05:03 -05006638 /*
6639 * For USB high speed set 512B packets
6640 */
6641 val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
6642 val8 &= ~(BIT(4) | BIT(5));
6643 val8 |= BIT(4);
6644 val8 |= BIT(1) | BIT(2) | BIT(3);
6645 rtl8xxxu_write8(priv, REG_RXDMA_PRO_8723B, val8);
6646
6647 /*
6648 * For USB high speed set 512B packets
6649 */
6650 val8 = rtl8xxxu_read8(priv, REG_HT_SINGLE_AMPDU_8723B);
6651 val8 |= BIT(7);
6652 rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8);
6653
6654 rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14);
6655 rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, 0x5e);
6656 rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff);
6657 rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18);
6658 rtl8xxxu_write8(priv, REG_PIFS, 0x00);
6659 rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, 0x50);
6660 rtl8xxxu_write8(priv, REG_USTIME_EDCA, 0x50);
6661
6662 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
6663 val8 |= BIT(5) | BIT(6);
6664 rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
6665 }
6666
Jes Sorensen3e88ca42016-02-29 17:05:08 -05006667 if (priv->fops->init_aggregation)
6668 priv->fops->init_aggregation(priv);
6669
Jes Sorensenc3690602016-02-29 17:05:03 -05006670 /*
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006671 * Enable CCK and OFDM block
6672 */
6673 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
6674 val32 |= (FPGA_RF_MODE_CCK | FPGA_RF_MODE_OFDM);
6675 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
6676
6677 /*
6678 * Invalidate all CAM entries - bit 30 is undocumented
6679 */
6680 rtl8xxxu_write32(priv, REG_CAM_CMD, CAM_CMD_POLLING | BIT(30));
6681
6682 /*
6683 * Start out with default power levels for channel 6, 20MHz
6684 */
Jes Sorensene796dab2016-02-29 17:05:19 -05006685 priv->fops->set_tx_power(priv, 1, false);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006686
6687 /* Let the 8051 take control of antenna setting */
6688 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
6689 val8 |= LEDCFG2_DPDT_SELECT;
6690 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
6691
6692 rtl8xxxu_write8(priv, REG_HWSEQ_CTRL, 0xff);
6693
6694 /* Disable BAR - not sure if this has any effect on USB */
6695 rtl8xxxu_write32(priv, REG_BAR_MODE_CTRL, 0x0201ffff);
6696
6697 rtl8xxxu_write16(priv, REG_FAST_EDCA_CTRL, 0);
6698
Jes Sorensen9c79bf92016-02-29 17:05:10 -05006699 if (priv->fops->init_statistics)
6700 priv->fops->init_statistics(priv);
6701
Jes Sorensenfa0f2d42016-02-29 17:04:37 -05006702 rtl8723a_phy_lc_calibrate(priv);
6703
Jes Sorensene1547c52016-02-29 17:04:35 -05006704 priv->fops->phy_iq_calibrate(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006705
6706 /*
6707 * This should enable thermal meter
6708 */
Jes Sorensen72143b92016-02-29 17:05:25 -05006709 if (priv->fops->has_s0s1)
6710 rtl8xxxu_write_rfreg(priv,
6711 RF_A, RF6052_REG_T_METER_8723B, 0x37cf8);
6712 else
6713 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_T_METER, 0x60);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006714
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006715 /* Set NAV_UPPER to 30000us */
6716 val8 = ((30000 + NAV_UPPER_UNIT - 1) / NAV_UPPER_UNIT);
6717 rtl8xxxu_write8(priv, REG_NAV_UPPER, val8);
6718
Jes Sorensenba17d822016-03-31 17:08:39 -04006719 if (priv->rtl_chip == RTL8723A) {
Jes Sorensen4042e612016-02-03 13:40:01 -05006720 /*
6721 * 2011/03/09 MH debug only, UMC-B cut pass 2500 S5 test,
6722 * but we need to find root cause.
6723 * This is 8723au only.
6724 */
6725 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
6726 if ((val32 & 0xff000000) != 0x83000000) {
6727 val32 |= FPGA_RF_MODE_CCK;
6728 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
6729 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006730 }
6731
6732 val32 = rtl8xxxu_read32(priv, REG_FWHW_TXQ_CTRL);
6733 val32 |= FWHW_TXQ_CTRL_XMIT_MGMT_ACK;
6734 /* ack for xmit mgmt frames. */
6735 rtl8xxxu_write32(priv, REG_FWHW_TXQ_CTRL, val32);
6736
6737exit:
6738 return ret;
6739}
6740
6741static void rtl8xxxu_disable_device(struct ieee80211_hw *hw)
6742{
6743 struct rtl8xxxu_priv *priv = hw->priv;
6744
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05006745 priv->fops->power_off(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006746}
6747
6748static void rtl8xxxu_cam_write(struct rtl8xxxu_priv *priv,
6749 struct ieee80211_key_conf *key, const u8 *mac)
6750{
6751 u32 cmd, val32, addr, ctrl;
6752 int j, i, tmp_debug;
6753
6754 tmp_debug = rtl8xxxu_debug;
6755 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_KEY)
6756 rtl8xxxu_debug |= RTL8XXXU_DEBUG_REG_WRITE;
6757
6758 /*
6759 * This is a bit of a hack - the lower bits of the cipher
6760 * suite selector happens to match the cipher index in the CAM
6761 */
6762 addr = key->keyidx << CAM_CMD_KEY_SHIFT;
6763 ctrl = (key->cipher & 0x0f) << 2 | key->keyidx | CAM_WRITE_VALID;
6764
6765 for (j = 5; j >= 0; j--) {
6766 switch (j) {
6767 case 0:
6768 val32 = ctrl | (mac[0] << 16) | (mac[1] << 24);
6769 break;
6770 case 1:
6771 val32 = mac[2] | (mac[3] << 8) |
6772 (mac[4] << 16) | (mac[5] << 24);
6773 break;
6774 default:
6775 i = (j - 2) << 2;
6776 val32 = key->key[i] | (key->key[i + 1] << 8) |
6777 key->key[i + 2] << 16 | key->key[i + 3] << 24;
6778 break;
6779 }
6780
6781 rtl8xxxu_write32(priv, REG_CAM_WRITE, val32);
6782 cmd = CAM_CMD_POLLING | CAM_CMD_WRITE | (addr + j);
6783 rtl8xxxu_write32(priv, REG_CAM_CMD, cmd);
6784 udelay(100);
6785 }
6786
6787 rtl8xxxu_debug = tmp_debug;
6788}
6789
6790static void rtl8xxxu_sw_scan_start(struct ieee80211_hw *hw,
Jes Sorensen56e43742016-02-03 13:39:50 -05006791 struct ieee80211_vif *vif, const u8 *mac)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006792{
6793 struct rtl8xxxu_priv *priv = hw->priv;
6794 u8 val8;
6795
6796 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
6797 val8 |= BEACON_DISABLE_TSF_UPDATE;
6798 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
6799}
6800
6801static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw,
6802 struct ieee80211_vif *vif)
6803{
6804 struct rtl8xxxu_priv *priv = hw->priv;
6805 u8 val8;
6806
6807 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
6808 val8 &= ~BEACON_DISABLE_TSF_UPDATE;
6809 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
6810}
6811
Jes Sorensenf653e692016-02-29 17:05:38 -05006812static void rtl8723au_update_rate_mask(struct rtl8xxxu_priv *priv,
6813 u32 ramask, int sgi)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006814{
6815 struct h2c_cmd h2c;
6816
Jes Sorensenf653e692016-02-29 17:05:38 -05006817 memset(&h2c, 0, sizeof(struct h2c_cmd));
6818
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006819 h2c.ramask.cmd = H2C_SET_RATE_MASK;
6820 h2c.ramask.mask_lo = cpu_to_le16(ramask & 0xffff);
6821 h2c.ramask.mask_hi = cpu_to_le16(ramask >> 16);
6822
6823 h2c.ramask.arg = 0x80;
6824 if (sgi)
6825 h2c.ramask.arg |= 0x20;
6826
Jes Sorensen7ff8c1a2016-02-29 17:04:32 -05006827 dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n",
Jes Sorensen8da91572016-02-29 17:04:29 -05006828 __func__, ramask, h2c.ramask.arg, sizeof(h2c.ramask));
6829 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ramask));
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006830}
6831
Jes Sorensenf653e692016-02-29 17:05:38 -05006832static void rtl8723bu_update_rate_mask(struct rtl8xxxu_priv *priv,
6833 u32 ramask, int sgi)
6834{
6835 struct h2c_cmd h2c;
6836 u8 bw = 0;
6837
6838 memset(&h2c, 0, sizeof(struct h2c_cmd));
6839
6840 h2c.b_macid_cfg.cmd = H2C_8723B_MACID_CFG_RAID;
6841 h2c.b_macid_cfg.ramask0 = ramask & 0xff;
6842 h2c.b_macid_cfg.ramask1 = (ramask >> 8) & 0xff;
6843 h2c.b_macid_cfg.ramask2 = (ramask >> 16) & 0xff;
6844 h2c.b_macid_cfg.ramask3 = (ramask >> 24) & 0xff;
6845
6846 h2c.ramask.arg = 0x80;
6847 h2c.b_macid_cfg.data1 = 0;
6848 if (sgi)
6849 h2c.b_macid_cfg.data1 |= BIT(7);
6850
6851 h2c.b_macid_cfg.data2 = bw;
6852
6853 dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n",
6854 __func__, ramask, h2c.ramask.arg, sizeof(h2c.b_macid_cfg));
6855 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.b_macid_cfg));
6856}
6857
Jes Sorensen7d794ea2016-02-29 17:05:39 -05006858static void rtl8723au_report_connect(struct rtl8xxxu_priv *priv,
6859 u8 macid, bool connect)
6860{
6861 struct h2c_cmd h2c;
6862
6863 memset(&h2c, 0, sizeof(struct h2c_cmd));
6864
6865 h2c.joinbss.cmd = H2C_JOIN_BSS_REPORT;
6866
6867 if (connect)
6868 h2c.joinbss.data = H2C_JOIN_BSS_CONNECT;
6869 else
6870 h2c.joinbss.data = H2C_JOIN_BSS_DISCONNECT;
6871
6872 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.joinbss));
6873}
6874
6875static void rtl8723bu_report_connect(struct rtl8xxxu_priv *priv,
6876 u8 macid, bool connect)
6877{
6878 struct h2c_cmd h2c;
6879
6880 memset(&h2c, 0, sizeof(struct h2c_cmd));
6881
6882 h2c.media_status_rpt.cmd = H2C_8723B_MEDIA_STATUS_RPT;
6883 if (connect)
6884 h2c.media_status_rpt.parm |= BIT(0);
6885 else
6886 h2c.media_status_rpt.parm &= ~BIT(0);
6887
6888 rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.media_status_rpt));
6889}
6890
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006891static void rtl8xxxu_set_basic_rates(struct rtl8xxxu_priv *priv, u32 rate_cfg)
6892{
6893 u32 val32;
6894 u8 rate_idx = 0;
6895
6896 rate_cfg &= RESPONSE_RATE_BITMAP_ALL;
6897
6898 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
6899 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
6900 val32 |= rate_cfg;
6901 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
6902
6903 dev_dbg(&priv->udev->dev, "%s: rates %08x\n", __func__, rate_cfg);
6904
6905 while (rate_cfg) {
6906 rate_cfg = (rate_cfg >> 1);
6907 rate_idx++;
6908 }
6909 rtl8xxxu_write8(priv, REG_INIRTS_RATE_SEL, rate_idx);
6910}
6911
6912static void
6913rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6914 struct ieee80211_bss_conf *bss_conf, u32 changed)
6915{
6916 struct rtl8xxxu_priv *priv = hw->priv;
6917 struct device *dev = &priv->udev->dev;
6918 struct ieee80211_sta *sta;
6919 u32 val32;
6920 u8 val8;
6921
6922 if (changed & BSS_CHANGED_ASSOC) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006923 dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc);
6924
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006925 rtl8xxxu_set_linktype(priv, vif->type);
6926
6927 if (bss_conf->assoc) {
6928 u32 ramask;
6929 int sgi = 0;
6930
6931 rcu_read_lock();
6932 sta = ieee80211_find_sta(vif, bss_conf->bssid);
6933 if (!sta) {
6934 dev_info(dev, "%s: ASSOC no sta found\n",
6935 __func__);
6936 rcu_read_unlock();
6937 goto error;
6938 }
6939
6940 if (sta->ht_cap.ht_supported)
6941 dev_info(dev, "%s: HT supported\n", __func__);
6942 if (sta->vht_cap.vht_supported)
6943 dev_info(dev, "%s: VHT supported\n", __func__);
6944
6945 /* TODO: Set bits 28-31 for rate adaptive id */
6946 ramask = (sta->supp_rates[0] & 0xfff) |
6947 sta->ht_cap.mcs.rx_mask[0] << 12 |
6948 sta->ht_cap.mcs.rx_mask[1] << 20;
6949 if (sta->ht_cap.cap &
6950 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))
6951 sgi = 1;
6952 rcu_read_unlock();
6953
Jes Sorensenf653e692016-02-29 17:05:38 -05006954 priv->fops->update_rate_mask(priv, ramask, sgi);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006955
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006956 rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
6957
6958 rtl8723a_stop_tx_beacon(priv);
6959
6960 /* joinbss sequence */
6961 rtl8xxxu_write16(priv, REG_BCN_PSR_RPT,
6962 0xc000 | bss_conf->aid);
6963
Jes Sorensen7d794ea2016-02-29 17:05:39 -05006964 priv->fops->report_connect(priv, 0, true);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006965 } else {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006966 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
6967 val8 |= BEACON_DISABLE_TSF_UPDATE;
6968 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
6969
Jes Sorensen7d794ea2016-02-29 17:05:39 -05006970 priv->fops->report_connect(priv, 0, false);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006971 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006972 }
6973
6974 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
6975 dev_dbg(dev, "Changed ERP_PREAMBLE: Use short preamble %i\n",
6976 bss_conf->use_short_preamble);
6977 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
6978 if (bss_conf->use_short_preamble)
6979 val32 |= RSR_ACK_SHORT_PREAMBLE;
6980 else
6981 val32 &= ~RSR_ACK_SHORT_PREAMBLE;
6982 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
6983 }
6984
6985 if (changed & BSS_CHANGED_ERP_SLOT) {
6986 dev_dbg(dev, "Changed ERP_SLOT: short_slot_time %i\n",
6987 bss_conf->use_short_slot);
6988
6989 if (bss_conf->use_short_slot)
6990 val8 = 9;
6991 else
6992 val8 = 20;
6993 rtl8xxxu_write8(priv, REG_SLOT, val8);
6994 }
6995
6996 if (changed & BSS_CHANGED_BSSID) {
6997 dev_dbg(dev, "Changed BSSID!\n");
6998 rtl8xxxu_set_bssid(priv, bss_conf->bssid);
6999 }
7000
7001 if (changed & BSS_CHANGED_BASIC_RATES) {
7002 dev_dbg(dev, "Changed BASIC_RATES!\n");
7003 rtl8xxxu_set_basic_rates(priv, bss_conf->basic_rates);
7004 }
7005error:
7006 return;
7007}
7008
7009static u32 rtl8xxxu_80211_to_rtl_queue(u32 queue)
7010{
7011 u32 rtlqueue;
7012
7013 switch (queue) {
7014 case IEEE80211_AC_VO:
7015 rtlqueue = TXDESC_QUEUE_VO;
7016 break;
7017 case IEEE80211_AC_VI:
7018 rtlqueue = TXDESC_QUEUE_VI;
7019 break;
7020 case IEEE80211_AC_BE:
7021 rtlqueue = TXDESC_QUEUE_BE;
7022 break;
7023 case IEEE80211_AC_BK:
7024 rtlqueue = TXDESC_QUEUE_BK;
7025 break;
7026 default:
7027 rtlqueue = TXDESC_QUEUE_BE;
7028 }
7029
7030 return rtlqueue;
7031}
7032
7033static u32 rtl8xxxu_queue_select(struct ieee80211_hw *hw, struct sk_buff *skb)
7034{
7035 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
7036 u32 queue;
7037
7038 if (ieee80211_is_mgmt(hdr->frame_control))
7039 queue = TXDESC_QUEUE_MGNT;
7040 else
7041 queue = rtl8xxxu_80211_to_rtl_queue(skb_get_queue_mapping(skb));
7042
7043 return queue;
7044}
7045
Jes Sorensen179e1742016-02-29 17:05:27 -05007046/*
7047 * Despite newer chips 8723b/8812/8821 having a larger TX descriptor
7048 * format. The descriptor checksum is still only calculated over the
7049 * initial 32 bytes of the descriptor!
7050 */
Jes Sorensendbb28962016-03-31 17:08:33 -04007051static void rtl8xxxu_calc_tx_desc_csum(struct rtl8xxxu_txdesc32 *tx_desc)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007052{
7053 __le16 *ptr = (__le16 *)tx_desc;
7054 u16 csum = 0;
7055 int i;
7056
7057 /*
7058 * Clear csum field before calculation, as the csum field is
7059 * in the middle of the struct.
7060 */
7061 tx_desc->csum = cpu_to_le16(0);
7062
Jes Sorensendbb28962016-03-31 17:08:33 -04007063 for (i = 0; i < (sizeof(struct rtl8xxxu_txdesc32) / sizeof(u16)); i++)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007064 csum = csum ^ le16_to_cpu(ptr[i]);
7065
7066 tx_desc->csum |= cpu_to_le16(csum);
7067}
7068
7069static void rtl8xxxu_free_tx_resources(struct rtl8xxxu_priv *priv)
7070{
7071 struct rtl8xxxu_tx_urb *tx_urb, *tmp;
7072 unsigned long flags;
7073
7074 spin_lock_irqsave(&priv->tx_urb_lock, flags);
7075 list_for_each_entry_safe(tx_urb, tmp, &priv->tx_urb_free_list, list) {
7076 list_del(&tx_urb->list);
7077 priv->tx_urb_free_count--;
7078 usb_free_urb(&tx_urb->urb);
7079 }
7080 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
7081}
7082
7083static struct rtl8xxxu_tx_urb *
7084rtl8xxxu_alloc_tx_urb(struct rtl8xxxu_priv *priv)
7085{
7086 struct rtl8xxxu_tx_urb *tx_urb;
7087 unsigned long flags;
7088
7089 spin_lock_irqsave(&priv->tx_urb_lock, flags);
7090 tx_urb = list_first_entry_or_null(&priv->tx_urb_free_list,
7091 struct rtl8xxxu_tx_urb, list);
7092 if (tx_urb) {
7093 list_del(&tx_urb->list);
7094 priv->tx_urb_free_count--;
7095 if (priv->tx_urb_free_count < RTL8XXXU_TX_URB_LOW_WATER &&
7096 !priv->tx_stopped) {
7097 priv->tx_stopped = true;
7098 ieee80211_stop_queues(priv->hw);
7099 }
7100 }
7101
7102 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
7103
7104 return tx_urb;
7105}
7106
7107static void rtl8xxxu_free_tx_urb(struct rtl8xxxu_priv *priv,
7108 struct rtl8xxxu_tx_urb *tx_urb)
7109{
7110 unsigned long flags;
7111
7112 INIT_LIST_HEAD(&tx_urb->list);
7113
7114 spin_lock_irqsave(&priv->tx_urb_lock, flags);
7115
7116 list_add(&tx_urb->list, &priv->tx_urb_free_list);
7117 priv->tx_urb_free_count++;
7118 if (priv->tx_urb_free_count > RTL8XXXU_TX_URB_HIGH_WATER &&
7119 priv->tx_stopped) {
7120 priv->tx_stopped = false;
7121 ieee80211_wake_queues(priv->hw);
7122 }
7123
7124 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
7125}
7126
7127static void rtl8xxxu_tx_complete(struct urb *urb)
7128{
7129 struct sk_buff *skb = (struct sk_buff *)urb->context;
7130 struct ieee80211_tx_info *tx_info;
7131 struct ieee80211_hw *hw;
Jes Sorensen179e1742016-02-29 17:05:27 -05007132 struct rtl8xxxu_priv *priv;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007133 struct rtl8xxxu_tx_urb *tx_urb =
7134 container_of(urb, struct rtl8xxxu_tx_urb, urb);
7135
7136 tx_info = IEEE80211_SKB_CB(skb);
7137 hw = tx_info->rate_driver_data[0];
Jes Sorensen179e1742016-02-29 17:05:27 -05007138 priv = hw->priv;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007139
Jes Sorensen179e1742016-02-29 17:05:27 -05007140 skb_pull(skb, priv->fops->tx_desc_size);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007141
7142 ieee80211_tx_info_clear_status(tx_info);
7143 tx_info->status.rates[0].idx = -1;
7144 tx_info->status.rates[0].count = 0;
7145
7146 if (!urb->status)
7147 tx_info->flags |= IEEE80211_TX_STAT_ACK;
7148
7149 ieee80211_tx_status_irqsafe(hw, skb);
7150
Jes Sorensen179e1742016-02-29 17:05:27 -05007151 rtl8xxxu_free_tx_urb(priv, tx_urb);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007152}
7153
7154static void rtl8xxxu_dump_action(struct device *dev,
7155 struct ieee80211_hdr *hdr)
7156{
7157 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
7158 u16 cap, timeout;
7159
7160 if (!(rtl8xxxu_debug & RTL8XXXU_DEBUG_ACTION))
7161 return;
7162
7163 switch (mgmt->u.action.u.addba_resp.action_code) {
7164 case WLAN_ACTION_ADDBA_RESP:
7165 cap = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
7166 timeout = le16_to_cpu(mgmt->u.action.u.addba_resp.timeout);
7167 dev_info(dev, "WLAN_ACTION_ADDBA_RESP: "
7168 "timeout %i, tid %02x, buf_size %02x, policy %02x, "
7169 "status %02x\n",
7170 timeout,
7171 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
7172 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
7173 (cap >> 1) & 0x1,
7174 le16_to_cpu(mgmt->u.action.u.addba_resp.status));
7175 break;
7176 case WLAN_ACTION_ADDBA_REQ:
7177 cap = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
7178 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
7179 dev_info(dev, "WLAN_ACTION_ADDBA_REQ: "
7180 "timeout %i, tid %02x, buf_size %02x, policy %02x\n",
7181 timeout,
7182 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
7183 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
7184 (cap >> 1) & 0x1);
7185 break;
7186 default:
7187 dev_info(dev, "action frame %02x\n",
7188 mgmt->u.action.u.addba_resp.action_code);
7189 break;
7190 }
7191}
7192
7193static void rtl8xxxu_tx(struct ieee80211_hw *hw,
7194 struct ieee80211_tx_control *control,
7195 struct sk_buff *skb)
7196{
7197 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
7198 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
7199 struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
7200 struct rtl8xxxu_priv *priv = hw->priv;
Jes Sorensendbb28962016-03-31 17:08:33 -04007201 struct rtl8xxxu_txdesc32 *tx_desc;
7202 struct rtl8xxxu_txdesc40 *tx_desc40;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007203 struct rtl8xxxu_tx_urb *tx_urb;
7204 struct ieee80211_sta *sta = NULL;
7205 struct ieee80211_vif *vif = tx_info->control.vif;
7206 struct device *dev = &priv->udev->dev;
7207 u32 queue, rate;
7208 u16 pktlen = skb->len;
7209 u16 seq_number;
7210 u16 rate_flag = tx_info->control.rates[0].flags;
Jes Sorensen179e1742016-02-29 17:05:27 -05007211 int tx_desc_size = priv->fops->tx_desc_size;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007212 int ret;
Jes Sorensencc2646d2016-02-29 17:05:32 -05007213 bool usedesc40, ampdu_enable;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007214
Jes Sorensen179e1742016-02-29 17:05:27 -05007215 if (skb_headroom(skb) < tx_desc_size) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007216 dev_warn(dev,
7217 "%s: Not enough headroom (%i) for tx descriptor\n",
7218 __func__, skb_headroom(skb));
7219 goto error;
7220 }
7221
Jes Sorensen179e1742016-02-29 17:05:27 -05007222 if (unlikely(skb->len > (65535 - tx_desc_size))) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007223 dev_warn(dev, "%s: Trying to send over-sized skb (%i)\n",
7224 __func__, skb->len);
7225 goto error;
7226 }
7227
7228 tx_urb = rtl8xxxu_alloc_tx_urb(priv);
7229 if (!tx_urb) {
7230 dev_warn(dev, "%s: Unable to allocate tx urb\n", __func__);
7231 goto error;
7232 }
7233
7234 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
7235 dev_info(dev, "%s: TX rate: %d (%d), pkt size %d\n",
7236 __func__, tx_rate->bitrate, tx_rate->hw_value, pktlen);
7237
7238 if (ieee80211_is_action(hdr->frame_control))
7239 rtl8xxxu_dump_action(dev, hdr);
7240
Jes Sorensencc2646d2016-02-29 17:05:32 -05007241 usedesc40 = (tx_desc_size == 40);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007242 tx_info->rate_driver_data[0] = hw;
7243
7244 if (control && control->sta)
7245 sta = control->sta;
7246
Jes Sorensendbb28962016-03-31 17:08:33 -04007247 tx_desc = (struct rtl8xxxu_txdesc32 *)skb_push(skb, tx_desc_size);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007248
Jes Sorensen179e1742016-02-29 17:05:27 -05007249 memset(tx_desc, 0, tx_desc_size);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007250 tx_desc->pkt_size = cpu_to_le16(pktlen);
Jes Sorensen179e1742016-02-29 17:05:27 -05007251 tx_desc->pkt_offset = tx_desc_size;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007252
7253 tx_desc->txdw0 =
7254 TXDESC_OWN | TXDESC_FIRST_SEGMENT | TXDESC_LAST_SEGMENT;
7255 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
7256 is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
7257 tx_desc->txdw0 |= TXDESC_BROADMULTICAST;
7258
7259 queue = rtl8xxxu_queue_select(hw, skb);
7260 tx_desc->txdw1 = cpu_to_le32(queue << TXDESC_QUEUE_SHIFT);
7261
7262 if (tx_info->control.hw_key) {
7263 switch (tx_info->control.hw_key->cipher) {
7264 case WLAN_CIPHER_SUITE_WEP40:
7265 case WLAN_CIPHER_SUITE_WEP104:
7266 case WLAN_CIPHER_SUITE_TKIP:
7267 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_RC4);
7268 break;
7269 case WLAN_CIPHER_SUITE_CCMP:
7270 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_AES);
7271 break;
7272 default:
7273 break;
7274 }
7275 }
7276
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007277 /* (tx_info->flags & IEEE80211_TX_CTL_AMPDU) && */
Jes Sorensena40ace42016-02-29 17:05:31 -05007278 ampdu_enable = false;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007279 if (ieee80211_is_data_qos(hdr->frame_control) && sta) {
7280 if (sta->ht_cap.ht_supported) {
7281 u32 ampdu, val32;
7282
7283 ampdu = (u32)sta->ht_cap.ampdu_density;
7284 val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT;
7285 tx_desc->txdw2 |= cpu_to_le32(val32);
Jes Sorensence2d1db2016-02-29 17:05:30 -05007286
Jes Sorensena40ace42016-02-29 17:05:31 -05007287 ampdu_enable = true;
7288 }
7289 }
7290
Jes Sorensen4c683602016-02-29 17:05:35 -05007291 if (rate_flag & IEEE80211_TX_RC_MCS)
7292 rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
7293 else
7294 rate = tx_rate->hw_value;
7295
Jes Sorensencc2646d2016-02-29 17:05:32 -05007296 seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
7297 if (!usedesc40) {
Jes Sorensen4c683602016-02-29 17:05:35 -05007298 tx_desc->txdw5 = cpu_to_le32(rate);
7299
7300 if (ieee80211_is_data(hdr->frame_control))
7301 tx_desc->txdw5 |= cpu_to_le32(0x0001ff00);
7302
Jes Sorensencc2646d2016-02-29 17:05:32 -05007303 tx_desc->txdw3 =
Jes Sorensen33f37242016-03-31 17:08:34 -04007304 cpu_to_le32((u32)seq_number << TXDESC32_SEQ_SHIFT);
Jes Sorensencc2646d2016-02-29 17:05:32 -05007305
Jes Sorensena40ace42016-02-29 17:05:31 -05007306 if (ampdu_enable)
Jes Sorensen33f37242016-03-31 17:08:34 -04007307 tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_ENABLE);
Jes Sorensena40ace42016-02-29 17:05:31 -05007308 else
Jes Sorensen33f37242016-03-31 17:08:34 -04007309 tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_BREAK);
Jes Sorensen4c683602016-02-29 17:05:35 -05007310
7311 if (ieee80211_is_mgmt(hdr->frame_control)) {
7312 tx_desc->txdw5 = cpu_to_le32(tx_rate->hw_value);
7313 tx_desc->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007314 cpu_to_le32(TXDESC32_USE_DRIVER_RATE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007315 tx_desc->txdw5 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007316 cpu_to_le32(6 << TXDESC32_RETRY_LIMIT_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007317 tx_desc->txdw5 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007318 cpu_to_le32(TXDESC32_RETRY_LIMIT_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007319 }
7320
7321 if (ieee80211_is_data_qos(hdr->frame_control))
Jes Sorensen33f37242016-03-31 17:08:34 -04007322 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_QOS);
Jes Sorensen4c683602016-02-29 17:05:35 -05007323
7324 if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ||
7325 (sta && vif && vif->bss_conf.use_short_preamble))
Jes Sorensen33f37242016-03-31 17:08:34 -04007326 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_SHORT_PREAMBLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007327
7328 if (rate_flag & IEEE80211_TX_RC_SHORT_GI ||
7329 (ieee80211_is_data_qos(hdr->frame_control) &&
7330 sta && sta->ht_cap.cap &
7331 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))) {
Jes Sorensen1df1de32016-03-31 17:08:36 -04007332 tx_desc->txdw5 |= cpu_to_le32(TXDESC32_SHORT_GI);
Jes Sorensen4c683602016-02-29 17:05:35 -05007333 }
7334
7335 if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
7336 /*
7337 * Use RTS rate 24M - does the mac80211 tell
7338 * us which to use?
7339 */
7340 tx_desc->txdw4 |=
7341 cpu_to_le32(DESC_RATE_24M <<
Jes Sorensen33f37242016-03-31 17:08:34 -04007342 TXDESC32_RTS_RATE_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007343 tx_desc->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007344 cpu_to_le32(TXDESC32_RTS_CTS_ENABLE);
7345 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_HW_RTS_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007346 }
Jes Sorensena40ace42016-02-29 17:05:31 -05007347 } else {
Jes Sorensendbb28962016-03-31 17:08:33 -04007348 tx_desc40 = (struct rtl8xxxu_txdesc40 *)tx_desc;
Jes Sorensencc2646d2016-02-29 17:05:32 -05007349
Jes Sorensen4c683602016-02-29 17:05:35 -05007350 tx_desc40->txdw4 = cpu_to_le32(rate);
7351 if (ieee80211_is_data(hdr->frame_control)) {
7352 tx_desc->txdw4 |=
7353 cpu_to_le32(0x1f <<
Jes Sorensen33f37242016-03-31 17:08:34 -04007354 TXDESC40_DATA_RATE_FB_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007355 }
7356
Jes Sorensencc2646d2016-02-29 17:05:32 -05007357 tx_desc40->txdw9 =
Jes Sorensen33f37242016-03-31 17:08:34 -04007358 cpu_to_le32((u32)seq_number << TXDESC40_SEQ_SHIFT);
Jes Sorensencc2646d2016-02-29 17:05:32 -05007359
Jes Sorensena40ace42016-02-29 17:05:31 -05007360 if (ampdu_enable)
Jes Sorensen33f37242016-03-31 17:08:34 -04007361 tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_ENABLE);
Jes Sorensena40ace42016-02-29 17:05:31 -05007362 else
Jes Sorensen33f37242016-03-31 17:08:34 -04007363 tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_BREAK);
Jes Sorensen4c683602016-02-29 17:05:35 -05007364
7365 if (ieee80211_is_mgmt(hdr->frame_control)) {
7366 tx_desc40->txdw4 = cpu_to_le32(tx_rate->hw_value);
7367 tx_desc40->txdw3 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007368 cpu_to_le32(TXDESC40_USE_DRIVER_RATE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007369 tx_desc40->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007370 cpu_to_le32(6 << TXDESC40_RETRY_LIMIT_SHIFT);
Jes Sorensen4c683602016-02-29 17:05:35 -05007371 tx_desc40->txdw4 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007372 cpu_to_le32(TXDESC40_RETRY_LIMIT_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007373 }
7374
7375 if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ||
7376 (sta && vif && vif->bss_conf.use_short_preamble))
7377 tx_desc40->txdw5 |=
Jes Sorensen33f37242016-03-31 17:08:34 -04007378 cpu_to_le32(TXDESC40_SHORT_PREAMBLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007379
7380 if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
7381 /*
7382 * Use RTS rate 24M - does the mac80211 tell
7383 * us which to use?
7384 */
7385 tx_desc->txdw4 |=
7386 cpu_to_le32(DESC_RATE_24M <<
Jes Sorensen33f37242016-03-31 17:08:34 -04007387 TXDESC40_RTS_RATE_SHIFT);
7388 tx_desc->txdw3 |= cpu_to_le32(TXDESC40_RTS_CTS_ENABLE);
7389 tx_desc->txdw3 |= cpu_to_le32(TXDESC40_HW_RTS_ENABLE);
Jes Sorensen4c683602016-02-29 17:05:35 -05007390 }
Jes Sorensen69794942016-02-29 17:05:43 -05007391 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007392
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007393 rtl8xxxu_calc_tx_desc_csum(tx_desc);
7394
7395 usb_fill_bulk_urb(&tx_urb->urb, priv->udev, priv->pipe_out[queue],
7396 skb->data, skb->len, rtl8xxxu_tx_complete, skb);
7397
7398 usb_anchor_urb(&tx_urb->urb, &priv->tx_anchor);
7399 ret = usb_submit_urb(&tx_urb->urb, GFP_ATOMIC);
7400 if (ret) {
7401 usb_unanchor_urb(&tx_urb->urb);
7402 rtl8xxxu_free_tx_urb(priv, tx_urb);
7403 goto error;
7404 }
7405 return;
7406error:
7407 dev_kfree_skb(skb);
7408}
7409
7410static void rtl8xxxu_rx_parse_phystats(struct rtl8xxxu_priv *priv,
7411 struct ieee80211_rx_status *rx_status,
Jes Sorensen87957082016-02-29 17:05:42 -05007412 struct rtl8723au_phy_stats *phy_stats,
7413 u32 rxmcs)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007414{
7415 if (phy_stats->sgi_en)
7416 rx_status->flag |= RX_FLAG_SHORT_GI;
7417
Jes Sorensen87957082016-02-29 17:05:42 -05007418 if (rxmcs < DESC_RATE_6M) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007419 /*
7420 * Handle PHY stats for CCK rates
7421 */
7422 u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;
7423
7424 switch (cck_agc_rpt & 0xc0) {
7425 case 0xc0:
7426 rx_status->signal = -46 - (cck_agc_rpt & 0x3e);
7427 break;
7428 case 0x80:
7429 rx_status->signal = -26 - (cck_agc_rpt & 0x3e);
7430 break;
7431 case 0x40:
7432 rx_status->signal = -12 - (cck_agc_rpt & 0x3e);
7433 break;
7434 case 0x00:
7435 rx_status->signal = 16 - (cck_agc_rpt & 0x3e);
7436 break;
7437 }
7438 } else {
7439 rx_status->signal =
7440 (phy_stats->cck_sig_qual_ofdm_pwdb_all >> 1) - 110;
7441 }
7442}
7443
7444static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv)
7445{
7446 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
7447 unsigned long flags;
7448
7449 spin_lock_irqsave(&priv->rx_urb_lock, flags);
7450
7451 list_for_each_entry_safe(rx_urb, tmp,
7452 &priv->rx_urb_pending_list, list) {
7453 list_del(&rx_urb->list);
7454 priv->rx_urb_pending_count--;
7455 usb_free_urb(&rx_urb->urb);
7456 }
7457
7458 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
7459}
7460
7461static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv,
7462 struct rtl8xxxu_rx_urb *rx_urb)
7463{
7464 struct sk_buff *skb;
7465 unsigned long flags;
7466 int pending = 0;
7467
7468 spin_lock_irqsave(&priv->rx_urb_lock, flags);
7469
7470 if (!priv->shutdown) {
7471 list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list);
7472 priv->rx_urb_pending_count++;
7473 pending = priv->rx_urb_pending_count;
7474 } else {
7475 skb = (struct sk_buff *)rx_urb->urb.context;
7476 dev_kfree_skb(skb);
7477 usb_free_urb(&rx_urb->urb);
7478 }
7479
7480 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
7481
7482 if (pending > RTL8XXXU_RX_URB_PENDING_WATER)
7483 schedule_work(&priv->rx_urb_wq);
7484}
7485
7486static void rtl8xxxu_rx_urb_work(struct work_struct *work)
7487{
7488 struct rtl8xxxu_priv *priv;
7489 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
7490 struct list_head local;
7491 struct sk_buff *skb;
7492 unsigned long flags;
7493 int ret;
7494
7495 priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq);
7496 INIT_LIST_HEAD(&local);
7497
7498 spin_lock_irqsave(&priv->rx_urb_lock, flags);
7499
7500 list_splice_init(&priv->rx_urb_pending_list, &local);
7501 priv->rx_urb_pending_count = 0;
7502
7503 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
7504
7505 list_for_each_entry_safe(rx_urb, tmp, &local, list) {
7506 list_del_init(&rx_urb->list);
7507 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
7508 /*
7509 * If out of memory or temporary error, put it back on the
7510 * queue and try again. Otherwise the device is dead/gone
7511 * and we should drop it.
7512 */
7513 switch (ret) {
7514 case 0:
7515 break;
7516 case -ENOMEM:
7517 case -EAGAIN:
7518 rtl8xxxu_queue_rx_urb(priv, rx_urb);
7519 break;
7520 default:
7521 pr_info("failed to requeue urb %i\n", ret);
7522 skb = (struct sk_buff *)rx_urb->urb.context;
7523 dev_kfree_skb(skb);
7524 usb_free_urb(&rx_urb->urb);
7525 }
7526 }
7527}
7528
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007529static int rtl8723au_parse_rx_desc(struct rtl8xxxu_priv *priv,
7530 struct sk_buff *skb,
7531 struct ieee80211_rx_status *rx_status)
7532{
7533 struct rtl8xxxu_rx_desc *rx_desc = (struct rtl8xxxu_rx_desc *)skb->data;
7534 struct rtl8723au_phy_stats *phy_stats;
7535 int drvinfo_sz, desc_shift;
7536
7537 skb_pull(skb, sizeof(struct rtl8xxxu_rx_desc));
7538
7539 phy_stats = (struct rtl8723au_phy_stats *)skb->data;
7540
7541 drvinfo_sz = rx_desc->drvinfo_sz * 8;
7542 desc_shift = rx_desc->shift;
7543 skb_pull(skb, drvinfo_sz + desc_shift);
7544
7545 if (rx_desc->phy_stats)
Jes Sorensen87957082016-02-29 17:05:42 -05007546 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats,
7547 rx_desc->rxmcs);
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007548
7549 rx_status->mactime = le32_to_cpu(rx_desc->tsfl);
7550 rx_status->flag |= RX_FLAG_MACTIME_START;
7551
7552 if (!rx_desc->swdec)
7553 rx_status->flag |= RX_FLAG_DECRYPTED;
7554 if (rx_desc->crc32)
7555 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
7556 if (rx_desc->bw)
7557 rx_status->flag |= RX_FLAG_40MHZ;
7558
7559 if (rx_desc->rxht) {
7560 rx_status->flag |= RX_FLAG_HT;
7561 rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0;
7562 } else {
7563 rx_status->rate_idx = rx_desc->rxmcs;
7564 }
7565
7566 return RX_TYPE_DATA_PKT;
7567}
7568
7569static int rtl8723bu_parse_rx_desc(struct rtl8xxxu_priv *priv,
7570 struct sk_buff *skb,
7571 struct ieee80211_rx_status *rx_status)
7572{
7573 struct rtl8723bu_rx_desc *rx_desc =
7574 (struct rtl8723bu_rx_desc *)skb->data;
7575 struct rtl8723au_phy_stats *phy_stats;
7576 int drvinfo_sz, desc_shift;
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007577
7578 skb_pull(skb, sizeof(struct rtl8723bu_rx_desc));
7579
7580 phy_stats = (struct rtl8723au_phy_stats *)skb->data;
7581
7582 drvinfo_sz = rx_desc->drvinfo_sz * 8;
7583 desc_shift = rx_desc->shift;
7584 skb_pull(skb, drvinfo_sz + desc_shift);
7585
Jes Sorensene975b872016-02-29 17:05:36 -05007586 if (rx_desc->rpt_sel) {
7587 struct device *dev = &priv->udev->dev;
7588 dev_dbg(dev, "%s: C2H packet\n", __func__);
7589 return RX_TYPE_C2H;
7590 }
7591
Jes Sorensen87957082016-02-29 17:05:42 -05007592 if (rx_desc->phy_stats)
7593 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats,
7594 rx_desc->rxmcs);
7595
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007596 rx_status->mactime = le32_to_cpu(rx_desc->tsfl);
7597 rx_status->flag |= RX_FLAG_MACTIME_START;
7598
7599 if (!rx_desc->swdec)
7600 rx_status->flag |= RX_FLAG_DECRYPTED;
7601 if (rx_desc->crc32)
7602 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
7603 if (rx_desc->bw)
7604 rx_status->flag |= RX_FLAG_40MHZ;
7605
7606 if (rx_desc->rxmcs >= DESC_RATE_MCS0) {
7607 rx_status->flag |= RX_FLAG_HT;
7608 rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0;
7609 } else {
7610 rx_status->rate_idx = rx_desc->rxmcs;
7611 }
7612
Jes Sorensene975b872016-02-29 17:05:36 -05007613 return RX_TYPE_DATA_PKT;
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007614}
7615
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007616static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv *priv,
7617 struct sk_buff *skb)
7618{
7619 struct rtl8723bu_c2h *c2h = (struct rtl8723bu_c2h *)skb->data;
7620 struct device *dev = &priv->udev->dev;
7621 int len;
7622
7623 len = skb->len - 2;
7624
Jes Sorensen5e00d502016-02-29 17:05:28 -05007625 dev_dbg(dev, "C2H ID %02x seq %02x, len %02x source %02x\n",
7626 c2h->id, c2h->seq, len, c2h->bt_info.response_source);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007627
7628 switch(c2h->id) {
7629 case C2H_8723B_BT_INFO:
7630 if (c2h->bt_info.response_source >
7631 BT_INFO_SRC_8723B_BT_ACTIVE_SEND)
Jes Sorensen5e00d502016-02-29 17:05:28 -05007632 dev_dbg(dev, "C2H_BT_INFO WiFi only firmware\n");
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007633 else
Jes Sorensen5e00d502016-02-29 17:05:28 -05007634 dev_dbg(dev, "C2H_BT_INFO BT/WiFi coexist firmware\n");
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007635
7636 if (c2h->bt_info.bt_has_reset)
Jes Sorensen5e00d502016-02-29 17:05:28 -05007637 dev_dbg(dev, "BT has been reset\n");
Jes Sorensen394f1bd2016-02-29 17:04:49 -05007638 if (c2h->bt_info.tx_rx_mask)
Jes Sorensen5e00d502016-02-29 17:05:28 -05007639 dev_dbg(dev, "BT TRx mask\n");
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007640
7641 break;
Jes Sorensen394f1bd2016-02-29 17:04:49 -05007642 case C2H_8723B_BT_MP_INFO:
Jes Sorensen5e00d502016-02-29 17:05:28 -05007643 dev_dbg(dev, "C2H_MP_INFO ext ID %02x, status %02x\n",
7644 c2h->bt_mp_info.ext_id, c2h->bt_mp_info.status);
Jes Sorensen394f1bd2016-02-29 17:04:49 -05007645 break;
Jes Sorensen55a18dd2016-02-29 17:05:41 -05007646 case C2H_8723B_RA_REPORT:
7647 dev_dbg(dev,
7648 "C2H RA RPT: rate %02x, unk %i, macid %02x, noise %i\n",
7649 c2h->ra_report.rate, c2h->ra_report.dummy0_0,
7650 c2h->ra_report.macid, c2h->ra_report.noisy_state);
7651 break;
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007652 default:
Jes Sorensen739dc9f2016-02-29 17:05:40 -05007653 dev_info(dev, "Unhandled C2H event %02x seq %02x\n",
7654 c2h->id, c2h->seq);
7655 print_hex_dump(KERN_INFO, "C2H content: ", DUMP_PREFIX_NONE,
7656 16, 1, c2h->raw.payload, len, false);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007657 break;
7658 }
7659}
7660
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007661static void rtl8xxxu_rx_complete(struct urb *urb)
7662{
7663 struct rtl8xxxu_rx_urb *rx_urb =
7664 container_of(urb, struct rtl8xxxu_rx_urb, urb);
7665 struct ieee80211_hw *hw = rx_urb->hw;
7666 struct rtl8xxxu_priv *priv = hw->priv;
7667 struct sk_buff *skb = (struct sk_buff *)urb->context;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007668 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007669 struct device *dev = &priv->udev->dev;
7670 __le32 *_rx_desc_le = (__le32 *)skb->data;
7671 u32 *_rx_desc = (u32 *)skb->data;
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007672 int rx_type, i;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007673
7674 for (i = 0; i < (sizeof(struct rtl8xxxu_rx_desc) / sizeof(u32)); i++)
7675 _rx_desc[i] = le32_to_cpu(_rx_desc_le[i]);
7676
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007677 skb_put(skb, urb->actual_length);
7678
7679 if (urb->status == 0) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007680 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
7681
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007682 rx_type = priv->fops->parse_rx_desc(priv, skb, rx_status);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007683
7684 rx_status->freq = hw->conf.chandef.chan->center_freq;
7685 rx_status->band = hw->conf.chandef.chan->band;
7686
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007687 if (rx_type == RX_TYPE_DATA_PKT)
7688 ieee80211_rx_irqsafe(hw, skb);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007689 else {
7690 rtl8723bu_handle_c2h(priv, skb);
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05007691 dev_kfree_skb(skb);
Jes Sorensenb2b43b72016-02-29 17:04:48 -05007692 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007693
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007694 skb = NULL;
7695 rx_urb->urb.context = NULL;
7696 rtl8xxxu_queue_rx_urb(priv, rx_urb);
7697 } else {
7698 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
7699 goto cleanup;
7700 }
7701 return;
7702
7703cleanup:
7704 usb_free_urb(urb);
7705 dev_kfree_skb(skb);
7706 return;
7707}
7708
7709static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
7710 struct rtl8xxxu_rx_urb *rx_urb)
7711{
7712 struct sk_buff *skb;
7713 int skb_size;
7714 int ret;
7715
7716 skb_size = sizeof(struct rtl8xxxu_rx_desc) + RTL_RX_BUFFER_SIZE;
7717 skb = __netdev_alloc_skb(NULL, skb_size, GFP_KERNEL);
7718 if (!skb)
7719 return -ENOMEM;
7720
7721 memset(skb->data, 0, sizeof(struct rtl8xxxu_rx_desc));
7722 usb_fill_bulk_urb(&rx_urb->urb, priv->udev, priv->pipe_in, skb->data,
7723 skb_size, rtl8xxxu_rx_complete, skb);
7724 usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor);
7725 ret = usb_submit_urb(&rx_urb->urb, GFP_ATOMIC);
7726 if (ret)
7727 usb_unanchor_urb(&rx_urb->urb);
7728 return ret;
7729}
7730
7731static void rtl8xxxu_int_complete(struct urb *urb)
7732{
7733 struct rtl8xxxu_priv *priv = (struct rtl8xxxu_priv *)urb->context;
7734 struct device *dev = &priv->udev->dev;
7735 int ret;
7736
7737 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
7738 if (urb->status == 0) {
7739 usb_anchor_urb(urb, &priv->int_anchor);
7740 ret = usb_submit_urb(urb, GFP_ATOMIC);
7741 if (ret)
7742 usb_unanchor_urb(urb);
7743 } else {
7744 dev_info(dev, "%s: Error %i\n", __func__, urb->status);
7745 }
7746}
7747
7748
7749static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw)
7750{
7751 struct rtl8xxxu_priv *priv = hw->priv;
7752 struct urb *urb;
7753 u32 val32;
7754 int ret;
7755
7756 urb = usb_alloc_urb(0, GFP_KERNEL);
7757 if (!urb)
7758 return -ENOMEM;
7759
7760 usb_fill_int_urb(urb, priv->udev, priv->pipe_interrupt,
7761 priv->int_buf, USB_INTR_CONTENT_LENGTH,
7762 rtl8xxxu_int_complete, priv, 1);
7763 usb_anchor_urb(urb, &priv->int_anchor);
7764 ret = usb_submit_urb(urb, GFP_KERNEL);
7765 if (ret) {
7766 usb_unanchor_urb(urb);
7767 goto error;
7768 }
7769
7770 val32 = rtl8xxxu_read32(priv, REG_USB_HIMR);
7771 val32 |= USB_HIMR_CPWM;
7772 rtl8xxxu_write32(priv, REG_USB_HIMR, val32);
7773
7774error:
7775 return ret;
7776}
7777
7778static int rtl8xxxu_add_interface(struct ieee80211_hw *hw,
7779 struct ieee80211_vif *vif)
7780{
7781 struct rtl8xxxu_priv *priv = hw->priv;
7782 int ret;
7783 u8 val8;
7784
7785 switch (vif->type) {
7786 case NL80211_IFTYPE_STATION:
7787 rtl8723a_stop_tx_beacon(priv);
7788
7789 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
7790 val8 |= BEACON_ATIM | BEACON_FUNCTION_ENABLE |
7791 BEACON_DISABLE_TSF_UPDATE;
7792 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
7793 ret = 0;
7794 break;
7795 default:
7796 ret = -EOPNOTSUPP;
7797 }
7798
7799 rtl8xxxu_set_linktype(priv, vif->type);
7800
7801 return ret;
7802}
7803
7804static void rtl8xxxu_remove_interface(struct ieee80211_hw *hw,
7805 struct ieee80211_vif *vif)
7806{
7807 struct rtl8xxxu_priv *priv = hw->priv;
7808
7809 dev_dbg(&priv->udev->dev, "%s\n", __func__);
7810}
7811
7812static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed)
7813{
7814 struct rtl8xxxu_priv *priv = hw->priv;
7815 struct device *dev = &priv->udev->dev;
7816 u16 val16;
7817 int ret = 0, channel;
7818 bool ht40;
7819
7820 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
7821 dev_info(dev,
7822 "%s: channel: %i (changed %08x chandef.width %02x)\n",
7823 __func__, hw->conf.chandef.chan->hw_value,
7824 changed, hw->conf.chandef.width);
7825
7826 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
7827 val16 = ((hw->conf.long_frame_max_tx_count <<
7828 RETRY_LIMIT_LONG_SHIFT) & RETRY_LIMIT_LONG_MASK) |
7829 ((hw->conf.short_frame_max_tx_count <<
7830 RETRY_LIMIT_SHORT_SHIFT) & RETRY_LIMIT_SHORT_MASK);
7831 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
7832 }
7833
7834 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
7835 switch (hw->conf.chandef.width) {
7836 case NL80211_CHAN_WIDTH_20_NOHT:
7837 case NL80211_CHAN_WIDTH_20:
7838 ht40 = false;
7839 break;
7840 case NL80211_CHAN_WIDTH_40:
7841 ht40 = true;
7842 break;
7843 default:
7844 ret = -ENOTSUPP;
7845 goto exit;
7846 }
7847
7848 channel = hw->conf.chandef.chan->hw_value;
7849
Jes Sorensene796dab2016-02-29 17:05:19 -05007850 priv->fops->set_tx_power(priv, channel, ht40);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007851
Jes Sorensen1ea8e842016-02-29 17:05:04 -05007852 priv->fops->config_channel(hw);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007853 }
7854
7855exit:
7856 return ret;
7857}
7858
7859static int rtl8xxxu_conf_tx(struct ieee80211_hw *hw,
7860 struct ieee80211_vif *vif, u16 queue,
7861 const struct ieee80211_tx_queue_params *param)
7862{
7863 struct rtl8xxxu_priv *priv = hw->priv;
7864 struct device *dev = &priv->udev->dev;
7865 u32 val32;
7866 u8 aifs, acm_ctrl, acm_bit;
7867
7868 aifs = param->aifs;
7869
7870 val32 = aifs |
7871 fls(param->cw_min) << EDCA_PARAM_ECW_MIN_SHIFT |
7872 fls(param->cw_max) << EDCA_PARAM_ECW_MAX_SHIFT |
7873 (u32)param->txop << EDCA_PARAM_TXOP_SHIFT;
7874
7875 acm_ctrl = rtl8xxxu_read8(priv, REG_ACM_HW_CTRL);
7876 dev_dbg(dev,
7877 "%s: IEEE80211 queue %02x val %08x, acm %i, acm_ctrl %02x\n",
7878 __func__, queue, val32, param->acm, acm_ctrl);
7879
7880 switch (queue) {
7881 case IEEE80211_AC_VO:
7882 acm_bit = ACM_HW_CTRL_VO;
7883 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, val32);
7884 break;
7885 case IEEE80211_AC_VI:
7886 acm_bit = ACM_HW_CTRL_VI;
7887 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, val32);
7888 break;
7889 case IEEE80211_AC_BE:
7890 acm_bit = ACM_HW_CTRL_BE;
7891 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, val32);
7892 break;
7893 case IEEE80211_AC_BK:
7894 acm_bit = ACM_HW_CTRL_BK;
7895 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, val32);
7896 break;
7897 default:
7898 acm_bit = 0;
7899 break;
7900 }
7901
7902 if (param->acm)
7903 acm_ctrl |= acm_bit;
7904 else
7905 acm_ctrl &= ~acm_bit;
7906 rtl8xxxu_write8(priv, REG_ACM_HW_CTRL, acm_ctrl);
7907
7908 return 0;
7909}
7910
7911static void rtl8xxxu_configure_filter(struct ieee80211_hw *hw,
7912 unsigned int changed_flags,
7913 unsigned int *total_flags, u64 multicast)
7914{
7915 struct rtl8xxxu_priv *priv = hw->priv;
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05007916 u32 rcr = rtl8xxxu_read32(priv, REG_RCR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007917
7918 dev_dbg(&priv->udev->dev, "%s: changed_flags %08x, total_flags %08x\n",
7919 __func__, changed_flags, *total_flags);
7920
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05007921 /*
7922 * FIF_ALLMULTI ignored as all multicast frames are accepted (REG_MAR)
7923 */
7924
7925 if (*total_flags & FIF_FCSFAIL)
7926 rcr |= RCR_ACCEPT_CRC32;
7927 else
7928 rcr &= ~RCR_ACCEPT_CRC32;
7929
7930 /*
7931 * FIF_PLCPFAIL not supported?
7932 */
7933
7934 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
7935 rcr &= ~RCR_CHECK_BSSID_BEACON;
7936 else
7937 rcr |= RCR_CHECK_BSSID_BEACON;
7938
7939 if (*total_flags & FIF_CONTROL)
7940 rcr |= RCR_ACCEPT_CTRL_FRAME;
7941 else
7942 rcr &= ~RCR_ACCEPT_CTRL_FRAME;
7943
7944 if (*total_flags & FIF_OTHER_BSS) {
7945 rcr |= RCR_ACCEPT_AP;
7946 rcr &= ~RCR_CHECK_BSSID_MATCH;
7947 } else {
7948 rcr &= ~RCR_ACCEPT_AP;
7949 rcr |= RCR_CHECK_BSSID_MATCH;
7950 }
7951
7952 if (*total_flags & FIF_PSPOLL)
7953 rcr |= RCR_ACCEPT_PM;
7954 else
7955 rcr &= ~RCR_ACCEPT_PM;
7956
7957 /*
7958 * FIF_PROBE_REQ ignored as probe requests always seem to be accepted
7959 */
7960
7961 rtl8xxxu_write32(priv, REG_RCR, rcr);
7962
Jes Sorensen755bda12016-02-03 13:39:54 -05007963 *total_flags &= (FIF_ALLMULTI | FIF_FCSFAIL | FIF_BCN_PRBRESP_PROMISC |
7964 FIF_CONTROL | FIF_OTHER_BSS | FIF_PSPOLL |
7965 FIF_PROBE_REQ);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04007966}
7967
7968static int rtl8xxxu_set_rts_threshold(struct ieee80211_hw *hw, u32 rts)
7969{
7970 if (rts > 2347)
7971 return -EINVAL;
7972
7973 return 0;
7974}
7975
7976static int rtl8xxxu_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
7977 struct ieee80211_vif *vif,
7978 struct ieee80211_sta *sta,
7979 struct ieee80211_key_conf *key)
7980{
7981 struct rtl8xxxu_priv *priv = hw->priv;
7982 struct device *dev = &priv->udev->dev;
7983 u8 mac_addr[ETH_ALEN];
7984 u8 val8;
7985 u16 val16;
7986 u32 val32;
7987 int retval = -EOPNOTSUPP;
7988
7989 dev_dbg(dev, "%s: cmd %02x, cipher %08x, index %i\n",
7990 __func__, cmd, key->cipher, key->keyidx);
7991
7992 if (vif->type != NL80211_IFTYPE_STATION)
7993 return -EOPNOTSUPP;
7994
7995 if (key->keyidx > 3)
7996 return -EOPNOTSUPP;
7997
7998 switch (key->cipher) {
7999 case WLAN_CIPHER_SUITE_WEP40:
8000 case WLAN_CIPHER_SUITE_WEP104:
8001
8002 break;
8003 case WLAN_CIPHER_SUITE_CCMP:
8004 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
8005 break;
8006 case WLAN_CIPHER_SUITE_TKIP:
8007 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
8008 default:
8009 return -EOPNOTSUPP;
8010 }
8011
8012 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
8013 dev_dbg(dev, "%s: pairwise key\n", __func__);
8014 ether_addr_copy(mac_addr, sta->addr);
8015 } else {
8016 dev_dbg(dev, "%s: group key\n", __func__);
8017 eth_broadcast_addr(mac_addr);
8018 }
8019
8020 val16 = rtl8xxxu_read16(priv, REG_CR);
8021 val16 |= CR_SECURITY_ENABLE;
8022 rtl8xxxu_write16(priv, REG_CR, val16);
8023
8024 val8 = SEC_CFG_TX_SEC_ENABLE | SEC_CFG_TXBC_USE_DEFKEY |
8025 SEC_CFG_RX_SEC_ENABLE | SEC_CFG_RXBC_USE_DEFKEY;
8026 val8 |= SEC_CFG_TX_USE_DEFKEY | SEC_CFG_RX_USE_DEFKEY;
8027 rtl8xxxu_write8(priv, REG_SECURITY_CFG, val8);
8028
8029 switch (cmd) {
8030 case SET_KEY:
8031 key->hw_key_idx = key->keyidx;
8032 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
8033 rtl8xxxu_cam_write(priv, key, mac_addr);
8034 retval = 0;
8035 break;
8036 case DISABLE_KEY:
8037 rtl8xxxu_write32(priv, REG_CAM_WRITE, 0x00000000);
8038 val32 = CAM_CMD_POLLING | CAM_CMD_WRITE |
8039 key->keyidx << CAM_CMD_KEY_SHIFT;
8040 rtl8xxxu_write32(priv, REG_CAM_CMD, val32);
8041 retval = 0;
8042 break;
8043 default:
8044 dev_warn(dev, "%s: Unsupported command %02x\n", __func__, cmd);
8045 }
8046
8047 return retval;
8048}
8049
8050static int
8051rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +02008052 struct ieee80211_ampdu_params *params)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008053{
8054 struct rtl8xxxu_priv *priv = hw->priv;
8055 struct device *dev = &priv->udev->dev;
8056 u8 ampdu_factor, ampdu_density;
Sara Sharon50ea05e2015-12-30 16:06:04 +02008057 struct ieee80211_sta *sta = params->sta;
8058 enum ieee80211_ampdu_mlme_action action = params->action;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008059
8060 switch (action) {
8061 case IEEE80211_AMPDU_TX_START:
8062 dev_info(dev, "%s: IEEE80211_AMPDU_TX_START\n", __func__);
8063 ampdu_factor = sta->ht_cap.ampdu_factor;
8064 ampdu_density = sta->ht_cap.ampdu_density;
8065 rtl8xxxu_set_ampdu_factor(priv, ampdu_factor);
8066 rtl8xxxu_set_ampdu_min_space(priv, ampdu_density);
8067 dev_dbg(dev,
8068 "Changed HT: ampdu_factor %02x, ampdu_density %02x\n",
8069 ampdu_factor, ampdu_density);
8070 break;
8071 case IEEE80211_AMPDU_TX_STOP_FLUSH:
8072 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__);
8073 rtl8xxxu_set_ampdu_factor(priv, 0);
8074 rtl8xxxu_set_ampdu_min_space(priv, 0);
8075 break;
8076 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
8077 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n",
8078 __func__);
8079 rtl8xxxu_set_ampdu_factor(priv, 0);
8080 rtl8xxxu_set_ampdu_min_space(priv, 0);
8081 break;
8082 case IEEE80211_AMPDU_RX_START:
8083 dev_info(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__);
8084 break;
8085 case IEEE80211_AMPDU_RX_STOP:
8086 dev_info(dev, "%s: IEEE80211_AMPDU_RX_STOP\n", __func__);
8087 break;
8088 default:
8089 break;
8090 }
8091 return 0;
8092}
8093
8094static int rtl8xxxu_start(struct ieee80211_hw *hw)
8095{
8096 struct rtl8xxxu_priv *priv = hw->priv;
8097 struct rtl8xxxu_rx_urb *rx_urb;
8098 struct rtl8xxxu_tx_urb *tx_urb;
8099 unsigned long flags;
8100 int ret, i;
8101
8102 ret = 0;
8103
8104 init_usb_anchor(&priv->rx_anchor);
8105 init_usb_anchor(&priv->tx_anchor);
8106 init_usb_anchor(&priv->int_anchor);
8107
Jes Sorensendb08de92016-02-29 17:05:17 -05008108 priv->fops->enable_rf(priv);
Jes Sorensen0e28b972016-02-29 17:04:13 -05008109 if (priv->usb_interrupts) {
8110 ret = rtl8xxxu_submit_int_urb(hw);
8111 if (ret)
8112 goto exit;
8113 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008114
8115 for (i = 0; i < RTL8XXXU_TX_URBS; i++) {
8116 tx_urb = kmalloc(sizeof(struct rtl8xxxu_tx_urb), GFP_KERNEL);
8117 if (!tx_urb) {
8118 if (!i)
8119 ret = -ENOMEM;
8120
8121 goto error_out;
8122 }
8123 usb_init_urb(&tx_urb->urb);
8124 INIT_LIST_HEAD(&tx_urb->list);
8125 tx_urb->hw = hw;
8126 list_add(&tx_urb->list, &priv->tx_urb_free_list);
8127 priv->tx_urb_free_count++;
8128 }
8129
8130 priv->tx_stopped = false;
8131
8132 spin_lock_irqsave(&priv->rx_urb_lock, flags);
8133 priv->shutdown = false;
8134 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
8135
8136 for (i = 0; i < RTL8XXXU_RX_URBS; i++) {
8137 rx_urb = kmalloc(sizeof(struct rtl8xxxu_rx_urb), GFP_KERNEL);
8138 if (!rx_urb) {
8139 if (!i)
8140 ret = -ENOMEM;
8141
8142 goto error_out;
8143 }
8144 usb_init_urb(&rx_urb->urb);
8145 INIT_LIST_HEAD(&rx_urb->list);
8146 rx_urb->hw = hw;
8147
8148 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
8149 }
8150exit:
8151 /*
Bruno Randolfc85ea112016-02-03 13:39:55 -05008152 * Accept all data and mgmt frames
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008153 */
Bruno Randolfc85ea112016-02-03 13:39:55 -05008154 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0xffff);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008155 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0xffff);
8156
8157 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, 0x6954341e);
8158
8159 return ret;
8160
8161error_out:
8162 rtl8xxxu_free_tx_resources(priv);
8163 /*
8164 * Disable all data and mgmt frames
8165 */
8166 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
8167 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
8168
8169 return ret;
8170}
8171
8172static void rtl8xxxu_stop(struct ieee80211_hw *hw)
8173{
8174 struct rtl8xxxu_priv *priv = hw->priv;
8175 unsigned long flags;
8176
8177 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
8178
8179 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
8180 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
8181
8182 spin_lock_irqsave(&priv->rx_urb_lock, flags);
8183 priv->shutdown = true;
8184 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
8185
8186 usb_kill_anchored_urbs(&priv->rx_anchor);
8187 usb_kill_anchored_urbs(&priv->tx_anchor);
Jes Sorensen0e28b972016-02-29 17:04:13 -05008188 if (priv->usb_interrupts)
8189 usb_kill_anchored_urbs(&priv->int_anchor);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008190
Jes Sorensenfc89a412016-02-29 17:05:46 -05008191 priv->fops->disable_rf(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008192
8193 /*
8194 * Disable interrupts
8195 */
Jes Sorensen0e28b972016-02-29 17:04:13 -05008196 if (priv->usb_interrupts)
8197 rtl8xxxu_write32(priv, REG_USB_HIMR, 0);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008198
8199 rtl8xxxu_free_rx_resources(priv);
8200 rtl8xxxu_free_tx_resources(priv);
8201}
8202
8203static const struct ieee80211_ops rtl8xxxu_ops = {
8204 .tx = rtl8xxxu_tx,
8205 .add_interface = rtl8xxxu_add_interface,
8206 .remove_interface = rtl8xxxu_remove_interface,
8207 .config = rtl8xxxu_config,
8208 .conf_tx = rtl8xxxu_conf_tx,
8209 .bss_info_changed = rtl8xxxu_bss_info_changed,
8210 .configure_filter = rtl8xxxu_configure_filter,
8211 .set_rts_threshold = rtl8xxxu_set_rts_threshold,
8212 .start = rtl8xxxu_start,
8213 .stop = rtl8xxxu_stop,
8214 .sw_scan_start = rtl8xxxu_sw_scan_start,
8215 .sw_scan_complete = rtl8xxxu_sw_scan_complete,
8216 .set_key = rtl8xxxu_set_key,
8217 .ampdu_action = rtl8xxxu_ampdu_action,
8218};
8219
8220static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv,
8221 struct usb_interface *interface)
8222{
8223 struct usb_interface_descriptor *interface_desc;
8224 struct usb_host_interface *host_interface;
8225 struct usb_endpoint_descriptor *endpoint;
8226 struct device *dev = &priv->udev->dev;
8227 int i, j = 0, endpoints;
8228 u8 dir, xtype, num;
8229 int ret = 0;
8230
8231 host_interface = &interface->altsetting[0];
8232 interface_desc = &host_interface->desc;
8233 endpoints = interface_desc->bNumEndpoints;
8234
8235 for (i = 0; i < endpoints; i++) {
8236 endpoint = &host_interface->endpoint[i].desc;
8237
8238 dir = endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
8239 num = usb_endpoint_num(endpoint);
8240 xtype = usb_endpoint_type(endpoint);
8241 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8242 dev_dbg(dev,
8243 "%s: endpoint: dir %02x, # %02x, type %02x\n",
8244 __func__, dir, num, xtype);
8245 if (usb_endpoint_dir_in(endpoint) &&
8246 usb_endpoint_xfer_bulk(endpoint)) {
8247 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8248 dev_dbg(dev, "%s: in endpoint num %i\n",
8249 __func__, num);
8250
8251 if (priv->pipe_in) {
8252 dev_warn(dev,
8253 "%s: Too many IN pipes\n", __func__);
8254 ret = -EINVAL;
8255 goto exit;
8256 }
8257
8258 priv->pipe_in = usb_rcvbulkpipe(priv->udev, num);
8259 }
8260
8261 if (usb_endpoint_dir_in(endpoint) &&
8262 usb_endpoint_xfer_int(endpoint)) {
8263 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8264 dev_dbg(dev, "%s: interrupt endpoint num %i\n",
8265 __func__, num);
8266
8267 if (priv->pipe_interrupt) {
8268 dev_warn(dev, "%s: Too many INTERRUPT pipes\n",
8269 __func__);
8270 ret = -EINVAL;
8271 goto exit;
8272 }
8273
8274 priv->pipe_interrupt = usb_rcvintpipe(priv->udev, num);
8275 }
8276
8277 if (usb_endpoint_dir_out(endpoint) &&
8278 usb_endpoint_xfer_bulk(endpoint)) {
8279 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
8280 dev_dbg(dev, "%s: out endpoint num %i\n",
8281 __func__, num);
8282 if (j >= RTL8XXXU_OUT_ENDPOINTS) {
8283 dev_warn(dev,
8284 "%s: Too many OUT pipes\n", __func__);
8285 ret = -EINVAL;
8286 goto exit;
8287 }
8288 priv->out_ep[j++] = num;
8289 }
8290 }
8291exit:
8292 priv->nr_out_eps = j;
8293 return ret;
8294}
8295
8296static int rtl8xxxu_probe(struct usb_interface *interface,
8297 const struct usb_device_id *id)
8298{
8299 struct rtl8xxxu_priv *priv;
8300 struct ieee80211_hw *hw;
8301 struct usb_device *udev;
8302 struct ieee80211_supported_band *sband;
8303 int ret = 0;
8304 int untested = 1;
8305
8306 udev = usb_get_dev(interface_to_usbdev(interface));
8307
8308 switch (id->idVendor) {
8309 case USB_VENDOR_ID_REALTEK:
8310 switch(id->idProduct) {
8311 case 0x1724:
8312 case 0x8176:
8313 case 0x8178:
8314 case 0x817f:
8315 untested = 0;
8316 break;
8317 }
8318 break;
8319 case 0x7392:
8320 if (id->idProduct == 0x7811)
8321 untested = 0;
8322 break;
8323 default:
8324 break;
8325 }
8326
8327 if (untested) {
Jes Sorenseneaa4d142016-02-29 17:04:31 -05008328 rtl8xxxu_debug |= RTL8XXXU_DEBUG_EFUSE;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008329 dev_info(&udev->dev,
8330 "This Realtek USB WiFi dongle (0x%04x:0x%04x) is untested!\n",
8331 id->idVendor, id->idProduct);
8332 dev_info(&udev->dev,
8333 "Please report results to Jes.Sorensen@gmail.com\n");
8334 }
8335
8336 hw = ieee80211_alloc_hw(sizeof(struct rtl8xxxu_priv), &rtl8xxxu_ops);
8337 if (!hw) {
8338 ret = -ENOMEM;
8339 goto exit;
8340 }
8341
8342 priv = hw->priv;
8343 priv->hw = hw;
8344 priv->udev = udev;
8345 priv->fops = (struct rtl8xxxu_fileops *)id->driver_info;
8346 mutex_init(&priv->usb_buf_mutex);
8347 mutex_init(&priv->h2c_mutex);
8348 INIT_LIST_HEAD(&priv->tx_urb_free_list);
8349 spin_lock_init(&priv->tx_urb_lock);
8350 INIT_LIST_HEAD(&priv->rx_urb_pending_list);
8351 spin_lock_init(&priv->rx_urb_lock);
8352 INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work);
8353
8354 usb_set_intfdata(interface, hw);
8355
8356 ret = rtl8xxxu_parse_usb(priv, interface);
8357 if (ret)
8358 goto exit;
8359
8360 ret = rtl8xxxu_identify_chip(priv);
8361 if (ret) {
8362 dev_err(&udev->dev, "Fatal - failed to identify chip\n");
8363 goto exit;
8364 }
8365
8366 ret = rtl8xxxu_read_efuse(priv);
8367 if (ret) {
8368 dev_err(&udev->dev, "Fatal - failed to read EFuse\n");
8369 goto exit;
8370 }
8371
8372 ret = priv->fops->parse_efuse(priv);
8373 if (ret) {
8374 dev_err(&udev->dev, "Fatal - failed to parse EFuse\n");
8375 goto exit;
8376 }
8377
8378 rtl8xxxu_print_chipinfo(priv);
8379
8380 ret = priv->fops->load_firmware(priv);
8381 if (ret) {
8382 dev_err(&udev->dev, "Fatal - failed to load firmware\n");
8383 goto exit;
8384 }
8385
8386 ret = rtl8xxxu_init_device(hw);
8387
8388 hw->wiphy->max_scan_ssids = 1;
8389 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
8390 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
8391 hw->queues = 4;
8392
8393 sband = &rtl8xxxu_supported_band;
8394 sband->ht_cap.ht_supported = true;
8395 sband->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
8396 sband->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
8397 sband->ht_cap.cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40;
8398 memset(&sband->ht_cap.mcs, 0, sizeof(sband->ht_cap.mcs));
8399 sband->ht_cap.mcs.rx_mask[0] = 0xff;
8400 sband->ht_cap.mcs.rx_mask[4] = 0x01;
8401 if (priv->rf_paths > 1) {
8402 sband->ht_cap.mcs.rx_mask[1] = 0xff;
8403 sband->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
8404 }
8405 sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
8406 /*
8407 * Some APs will negotiate HT20_40 in a noisy environment leading
8408 * to miserable performance. Rather than defaulting to this, only
8409 * enable it if explicitly requested at module load time.
8410 */
8411 if (rtl8xxxu_ht40_2g) {
8412 dev_info(&udev->dev, "Enabling HT_20_40 on the 2.4GHz band\n");
8413 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
8414 }
Johannes Berg57fbcce2016-04-12 15:56:15 +02008415 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008416
8417 hw->wiphy->rts_threshold = 2347;
8418
8419 SET_IEEE80211_DEV(priv->hw, &interface->dev);
8420 SET_IEEE80211_PERM_ADDR(hw, priv->mac_addr);
8421
Jes Sorensen179e1742016-02-29 17:05:27 -05008422 hw->extra_tx_headroom = priv->fops->tx_desc_size;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008423 ieee80211_hw_set(hw, SIGNAL_DBM);
8424 /*
8425 * The firmware handles rate control
8426 */
8427 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
8428 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
8429
8430 ret = ieee80211_register_hw(priv->hw);
8431 if (ret) {
8432 dev_err(&udev->dev, "%s: Failed to register: %i\n",
8433 __func__, ret);
8434 goto exit;
8435 }
8436
8437exit:
8438 if (ret < 0)
8439 usb_put_dev(udev);
8440 return ret;
8441}
8442
8443static void rtl8xxxu_disconnect(struct usb_interface *interface)
8444{
8445 struct rtl8xxxu_priv *priv;
8446 struct ieee80211_hw *hw;
8447
8448 hw = usb_get_intfdata(interface);
8449 priv = hw->priv;
8450
8451 rtl8xxxu_disable_device(hw);
8452 usb_set_intfdata(interface, NULL);
8453
8454 dev_info(&priv->udev->dev, "disconnecting\n");
8455
8456 ieee80211_unregister_hw(hw);
8457
8458 kfree(priv->fw_data);
8459 mutex_destroy(&priv->usb_buf_mutex);
8460 mutex_destroy(&priv->h2c_mutex);
8461
8462 usb_put_dev(priv->udev);
8463 ieee80211_free_hw(hw);
8464}
8465
8466static struct rtl8xxxu_fileops rtl8723au_fops = {
8467 .parse_efuse = rtl8723au_parse_efuse,
8468 .load_firmware = rtl8723au_load_firmware,
8469 .power_on = rtl8723au_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05008470 .power_off = rtl8xxxu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05008471 .reset_8051 = rtl8xxxu_reset_8051,
Jes Sorensen74b99be2016-02-29 17:04:04 -05008472 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensene1547c52016-02-29 17:04:35 -05008473 .phy_iq_calibrate = rtl8723au_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05008474 .config_channel = rtl8723au_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008475 .parse_rx_desc = rtl8723au_parse_rx_desc,
Jes Sorensendb08de92016-02-29 17:05:17 -05008476 .enable_rf = rtl8723a_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05008477 .disable_rf = rtl8723a_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05008478 .set_tx_power = rtl8723a_set_tx_power,
Jes Sorensenf653e692016-02-29 17:05:38 -05008479 .update_rate_mask = rtl8723au_update_rate_mask,
Jes Sorensen7d794ea2016-02-29 17:05:39 -05008480 .report_connect = rtl8723au_report_connect,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008481 .writeN_block_size = 1024,
Jes Sorensened35d092016-02-29 17:04:19 -05008482 .mbox_ext_reg = REG_HMBOX_EXT_0,
8483 .mbox_ext_width = 2,
Jes Sorensendbb28962016-03-31 17:08:33 -04008484 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
Jes Sorensen8634af52016-02-29 17:04:33 -05008485 .adda_1t_init = 0x0b1b25a0,
8486 .adda_1t_path_on = 0x0bdb25a0,
8487 .adda_2t_path_on_a = 0x04db25a4,
8488 .adda_2t_path_on_b = 0x0b1b25a4,
Jes Sorensenc606e662016-04-07 14:19:16 -04008489 .mactable = rtl8723a_mac_init_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008490};
8491
Jes Sorensen35a741f2016-02-29 17:04:10 -05008492static struct rtl8xxxu_fileops rtl8723bu_fops = {
Jes Sorensen3c836d62016-02-29 17:04:11 -05008493 .parse_efuse = rtl8723bu_parse_efuse,
Jes Sorensen35a741f2016-02-29 17:04:10 -05008494 .load_firmware = rtl8723bu_load_firmware,
Jes Sorensen42836db2016-02-29 17:04:52 -05008495 .power_on = rtl8723bu_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05008496 .power_off = rtl8723bu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05008497 .reset_8051 = rtl8723bu_reset_8051,
Jes Sorensen35a741f2016-02-29 17:04:10 -05008498 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensenf0d9f5e2016-02-29 17:04:16 -05008499 .phy_init_antenna_selection = rtl8723bu_phy_init_antenna_selection,
Jes Sorensene1547c52016-02-29 17:04:35 -05008500 .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05008501 .config_channel = rtl8723bu_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008502 .parse_rx_desc = rtl8723bu_parse_rx_desc,
Jes Sorensen3e88ca42016-02-29 17:05:08 -05008503 .init_aggregation = rtl8723bu_init_aggregation,
Jes Sorensen9c79bf92016-02-29 17:05:10 -05008504 .init_statistics = rtl8723bu_init_statistics,
Jes Sorensendb08de92016-02-29 17:05:17 -05008505 .enable_rf = rtl8723b_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05008506 .disable_rf = rtl8723b_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05008507 .set_tx_power = rtl8723b_set_tx_power,
Jes Sorensenf653e692016-02-29 17:05:38 -05008508 .update_rate_mask = rtl8723bu_update_rate_mask,
Jes Sorensen7d794ea2016-02-29 17:05:39 -05008509 .report_connect = rtl8723bu_report_connect,
Jes Sorensenadfc0122016-02-29 17:04:12 -05008510 .writeN_block_size = 1024,
Jes Sorensened35d092016-02-29 17:04:19 -05008511 .mbox_ext_reg = REG_HMBOX_EXT0_8723B,
8512 .mbox_ext_width = 4,
Jes Sorensendbb28962016-03-31 17:08:33 -04008513 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40),
Jes Sorensen0d698de2016-02-29 17:04:36 -05008514 .has_s0s1 = 1,
Jes Sorensen8634af52016-02-29 17:04:33 -05008515 .adda_1t_init = 0x01c00014,
8516 .adda_1t_path_on = 0x01c00014,
8517 .adda_2t_path_on_a = 0x01c00014,
8518 .adda_2t_path_on_b = 0x01c00014,
Jes Sorensenc606e662016-04-07 14:19:16 -04008519 .mactable = rtl8723b_mac_init_table,
Jes Sorensen35a741f2016-02-29 17:04:10 -05008520};
8521
Kalle Valoc0963772015-10-25 18:24:38 +02008522#ifdef CONFIG_RTL8XXXU_UNTESTED
8523
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008524static struct rtl8xxxu_fileops rtl8192cu_fops = {
8525 .parse_efuse = rtl8192cu_parse_efuse,
8526 .load_firmware = rtl8192cu_load_firmware,
8527 .power_on = rtl8192cu_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05008528 .power_off = rtl8xxxu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05008529 .reset_8051 = rtl8xxxu_reset_8051,
Jes Sorensen74b99be2016-02-29 17:04:04 -05008530 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensene1547c52016-02-29 17:04:35 -05008531 .phy_iq_calibrate = rtl8723au_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05008532 .config_channel = rtl8723au_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008533 .parse_rx_desc = rtl8723au_parse_rx_desc,
Jes Sorensendb08de92016-02-29 17:05:17 -05008534 .enable_rf = rtl8723a_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05008535 .disable_rf = rtl8723a_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05008536 .set_tx_power = rtl8723a_set_tx_power,
Jes Sorensenf653e692016-02-29 17:05:38 -05008537 .update_rate_mask = rtl8723au_update_rate_mask,
Jes Sorensen7d794ea2016-02-29 17:05:39 -05008538 .report_connect = rtl8723au_report_connect,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008539 .writeN_block_size = 128,
Jes Sorensened35d092016-02-29 17:04:19 -05008540 .mbox_ext_reg = REG_HMBOX_EXT_0,
8541 .mbox_ext_width = 2,
Jes Sorensendbb28962016-03-31 17:08:33 -04008542 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
Jes Sorensen8634af52016-02-29 17:04:33 -05008543 .adda_1t_init = 0x0b1b25a0,
8544 .adda_1t_path_on = 0x0bdb25a0,
8545 .adda_2t_path_on_a = 0x04db25a4,
8546 .adda_2t_path_on_b = 0x0b1b25a4,
Jes Sorensenc606e662016-04-07 14:19:16 -04008547 .mactable = rtl8723a_mac_init_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008548};
8549
Kalle Valoc0963772015-10-25 18:24:38 +02008550#endif
8551
Jes Sorensen3307d842016-02-29 17:03:59 -05008552static struct rtl8xxxu_fileops rtl8192eu_fops = {
8553 .parse_efuse = rtl8192eu_parse_efuse,
8554 .load_firmware = rtl8192eu_load_firmware,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05008555 .power_on = rtl8192eu_power_on,
Jes Sorensenfe37d5f2016-02-29 17:05:47 -05008556 .power_off = rtl8xxxu_power_off,
Jes Sorensen7d4ccb82016-02-29 17:05:50 -05008557 .reset_8051 = rtl8xxxu_reset_8051,
Jes Sorensen74b99be2016-02-29 17:04:04 -05008558 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensene1547c52016-02-29 17:04:35 -05008559 .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate,
Jes Sorensenc3f95062016-02-29 17:04:40 -05008560 .config_channel = rtl8723bu_config_channel,
Jes Sorensenb18cdfd2016-02-29 17:04:47 -05008561 .parse_rx_desc = rtl8723bu_parse_rx_desc,
Jes Sorensendb08de92016-02-29 17:05:17 -05008562 .enable_rf = rtl8723b_enable_rf,
Jes Sorensenfc89a412016-02-29 17:05:46 -05008563 .disable_rf = rtl8723b_disable_rf,
Jes Sorensene796dab2016-02-29 17:05:19 -05008564 .set_tx_power = rtl8723b_set_tx_power,
Jes Sorensen91cbe4e2016-03-31 17:08:41 -04008565 .update_rate_mask = rtl8723bu_update_rate_mask,
8566 .report_connect = rtl8723bu_report_connect,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05008567 .writeN_block_size = 128,
Jes Sorensened35d092016-02-29 17:04:19 -05008568 .mbox_ext_reg = REG_HMBOX_EXT0_8723B,
8569 .mbox_ext_width = 4,
Jes Sorensenf3fc2512016-03-31 17:08:37 -04008570 .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40),
Jes Sorensen0d698de2016-02-29 17:04:36 -05008571 .has_s0s1 = 1,
Jes Sorensen8634af52016-02-29 17:04:33 -05008572 .adda_1t_init = 0x0fc01616,
8573 .adda_1t_path_on = 0x0fc01616,
8574 .adda_2t_path_on_a = 0x0fc01616,
8575 .adda_2t_path_on_b = 0x0fc01616,
Jes Sorensenc606e662016-04-07 14:19:16 -04008576 .mactable = rtl8192e_mac_init_table,
Jes Sorensen3307d842016-02-29 17:03:59 -05008577};
8578
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008579static struct usb_device_id dev_table[] = {
8580{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8724, 0xff, 0xff, 0xff),
8581 .driver_info = (unsigned long)&rtl8723au_fops},
8582{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1724, 0xff, 0xff, 0xff),
8583 .driver_info = (unsigned long)&rtl8723au_fops},
8584{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x0724, 0xff, 0xff, 0xff),
8585 .driver_info = (unsigned long)&rtl8723au_fops},
Jes Sorensen3307d842016-02-29 17:03:59 -05008586{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818b, 0xff, 0xff, 0xff),
8587 .driver_info = (unsigned long)&rtl8192eu_fops},
Jes Sorensen35a741f2016-02-29 17:04:10 -05008588{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0xb720, 0xff, 0xff, 0xff),
8589 .driver_info = (unsigned long)&rtl8723bu_fops},
Kalle Valo033695b2015-10-23 20:27:58 +03008590#ifdef CONFIG_RTL8XXXU_UNTESTED
8591/* Still supported by rtlwifi */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008592{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8176, 0xff, 0xff, 0xff),
8593 .driver_info = (unsigned long)&rtl8192cu_fops},
8594{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8178, 0xff, 0xff, 0xff),
8595 .driver_info = (unsigned long)&rtl8192cu_fops},
8596{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817f, 0xff, 0xff, 0xff),
8597 .driver_info = (unsigned long)&rtl8192cu_fops},
8598/* Tested by Larry Finger */
8599{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7811, 0xff, 0xff, 0xff),
8600 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008601/* Currently untested 8188 series devices */
8602{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8191, 0xff, 0xff, 0xff),
8603 .driver_info = (unsigned long)&rtl8192cu_fops},
8604{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8170, 0xff, 0xff, 0xff),
8605 .driver_info = (unsigned long)&rtl8192cu_fops},
8606{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8177, 0xff, 0xff, 0xff),
8607 .driver_info = (unsigned long)&rtl8192cu_fops},
8608{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817a, 0xff, 0xff, 0xff),
8609 .driver_info = (unsigned long)&rtl8192cu_fops},
8610{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817b, 0xff, 0xff, 0xff),
8611 .driver_info = (unsigned long)&rtl8192cu_fops},
8612{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817d, 0xff, 0xff, 0xff),
8613 .driver_info = (unsigned long)&rtl8192cu_fops},
8614{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817e, 0xff, 0xff, 0xff),
8615 .driver_info = (unsigned long)&rtl8192cu_fops},
8616{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818a, 0xff, 0xff, 0xff),
8617 .driver_info = (unsigned long)&rtl8192cu_fops},
8618{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x317f, 0xff, 0xff, 0xff),
8619 .driver_info = (unsigned long)&rtl8192cu_fops},
8620{USB_DEVICE_AND_INTERFACE_INFO(0x1058, 0x0631, 0xff, 0xff, 0xff),
8621 .driver_info = (unsigned long)&rtl8192cu_fops},
8622{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x094c, 0xff, 0xff, 0xff),
8623 .driver_info = (unsigned long)&rtl8192cu_fops},
8624{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1102, 0xff, 0xff, 0xff),
8625 .driver_info = (unsigned long)&rtl8192cu_fops},
8626{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe033, 0xff, 0xff, 0xff),
8627 .driver_info = (unsigned long)&rtl8192cu_fops},
8628{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8189, 0xff, 0xff, 0xff),
8629 .driver_info = (unsigned long)&rtl8192cu_fops},
8630{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9041, 0xff, 0xff, 0xff),
8631 .driver_info = (unsigned long)&rtl8192cu_fops},
8632{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ba, 0xff, 0xff, 0xff),
8633 .driver_info = (unsigned long)&rtl8192cu_fops},
8634{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1e1e, 0xff, 0xff, 0xff),
8635 .driver_info = (unsigned long)&rtl8192cu_fops},
8636{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x5088, 0xff, 0xff, 0xff),
8637 .driver_info = (unsigned long)&rtl8192cu_fops},
8638{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0052, 0xff, 0xff, 0xff),
8639 .driver_info = (unsigned long)&rtl8192cu_fops},
8640{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x005c, 0xff, 0xff, 0xff),
8641 .driver_info = (unsigned long)&rtl8192cu_fops},
8642{USB_DEVICE_AND_INTERFACE_INFO(0x0eb0, 0x9071, 0xff, 0xff, 0xff),
8643 .driver_info = (unsigned long)&rtl8192cu_fops},
8644{USB_DEVICE_AND_INTERFACE_INFO(0x103c, 0x1629, 0xff, 0xff, 0xff),
8645 .driver_info = (unsigned long)&rtl8192cu_fops},
8646{USB_DEVICE_AND_INTERFACE_INFO(0x13d3, 0x3357, 0xff, 0xff, 0xff),
8647 .driver_info = (unsigned long)&rtl8192cu_fops},
8648{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3308, 0xff, 0xff, 0xff),
8649 .driver_info = (unsigned long)&rtl8192cu_fops},
8650{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330b, 0xff, 0xff, 0xff),
8651 .driver_info = (unsigned long)&rtl8192cu_fops},
8652{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x4902, 0xff, 0xff, 0xff),
8653 .driver_info = (unsigned long)&rtl8192cu_fops},
8654{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2a, 0xff, 0xff, 0xff),
8655 .driver_info = (unsigned long)&rtl8192cu_fops},
8656{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2e, 0xff, 0xff, 0xff),
8657 .driver_info = (unsigned long)&rtl8192cu_fops},
8658{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xed17, 0xff, 0xff, 0xff),
8659 .driver_info = (unsigned long)&rtl8192cu_fops},
8660{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x648b, 0xff, 0xff, 0xff),
8661 .driver_info = (unsigned long)&rtl8192cu_fops},
8662{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0090, 0xff, 0xff, 0xff),
8663 .driver_info = (unsigned long)&rtl8192cu_fops},
8664{USB_DEVICE_AND_INTERFACE_INFO(0x4856, 0x0091, 0xff, 0xff, 0xff),
8665 .driver_info = (unsigned long)&rtl8192cu_fops},
8666{USB_DEVICE_AND_INTERFACE_INFO(0xcdab, 0x8010, 0xff, 0xff, 0xff),
8667 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04008668{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff7, 0xff, 0xff, 0xff),
8669 .driver_info = (unsigned long)&rtl8192cu_fops},
8670{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff9, 0xff, 0xff, 0xff),
8671 .driver_info = (unsigned long)&rtl8192cu_fops},
8672{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffa, 0xff, 0xff, 0xff),
8673 .driver_info = (unsigned long)&rtl8192cu_fops},
8674{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff8, 0xff, 0xff, 0xff),
8675 .driver_info = (unsigned long)&rtl8192cu_fops},
8676{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffb, 0xff, 0xff, 0xff),
8677 .driver_info = (unsigned long)&rtl8192cu_fops},
8678{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffc, 0xff, 0xff, 0xff),
8679 .driver_info = (unsigned long)&rtl8192cu_fops},
8680{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x1201, 0xff, 0xff, 0xff),
8681 .driver_info = (unsigned long)&rtl8192cu_fops},
8682/* Currently untested 8192 series devices */
8683{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x0950, 0xff, 0xff, 0xff),
8684 .driver_info = (unsigned long)&rtl8192cu_fops},
8685{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1004, 0xff, 0xff, 0xff),
8686 .driver_info = (unsigned long)&rtl8192cu_fops},
8687{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2102, 0xff, 0xff, 0xff),
8688 .driver_info = (unsigned long)&rtl8192cu_fops},
8689{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2103, 0xff, 0xff, 0xff),
8690 .driver_info = (unsigned long)&rtl8192cu_fops},
8691{USB_DEVICE_AND_INTERFACE_INFO(0x0586, 0x341f, 0xff, 0xff, 0xff),
8692 .driver_info = (unsigned long)&rtl8192cu_fops},
8693{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe035, 0xff, 0xff, 0xff),
8694 .driver_info = (unsigned long)&rtl8192cu_fops},
8695{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ab, 0xff, 0xff, 0xff),
8696 .driver_info = (unsigned long)&rtl8192cu_fops},
8697{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0061, 0xff, 0xff, 0xff),
8698 .driver_info = (unsigned long)&rtl8192cu_fops},
8699{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0070, 0xff, 0xff, 0xff),
8700 .driver_info = (unsigned long)&rtl8192cu_fops},
8701{USB_DEVICE_AND_INTERFACE_INFO(0x0789, 0x016d, 0xff, 0xff, 0xff),
8702 .driver_info = (unsigned long)&rtl8192cu_fops},
8703{USB_DEVICE_AND_INTERFACE_INFO(0x07aa, 0x0056, 0xff, 0xff, 0xff),
8704 .driver_info = (unsigned long)&rtl8192cu_fops},
8705{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8178, 0xff, 0xff, 0xff),
8706 .driver_info = (unsigned long)&rtl8192cu_fops},
8707{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9021, 0xff, 0xff, 0xff),
8708 .driver_info = (unsigned long)&rtl8192cu_fops},
8709{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0xf001, 0xff, 0xff, 0xff),
8710 .driver_info = (unsigned long)&rtl8192cu_fops},
8711{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x2e2e, 0xff, 0xff, 0xff),
8712 .driver_info = (unsigned long)&rtl8192cu_fops},
8713{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0019, 0xff, 0xff, 0xff),
8714 .driver_info = (unsigned long)&rtl8192cu_fops},
8715{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0020, 0xff, 0xff, 0xff),
8716 .driver_info = (unsigned long)&rtl8192cu_fops},
8717{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3307, 0xff, 0xff, 0xff),
8718 .driver_info = (unsigned long)&rtl8192cu_fops},
8719{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3309, 0xff, 0xff, 0xff),
8720 .driver_info = (unsigned long)&rtl8192cu_fops},
8721{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330a, 0xff, 0xff, 0xff),
8722 .driver_info = (unsigned long)&rtl8192cu_fops},
8723{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2b, 0xff, 0xff, 0xff),
8724 .driver_info = (unsigned long)&rtl8192cu_fops},
8725{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x624d, 0xff, 0xff, 0xff),
8726 .driver_info = (unsigned long)&rtl8192cu_fops},
8727{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0100, 0xff, 0xff, 0xff),
8728 .driver_info = (unsigned long)&rtl8192cu_fops},
8729{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0091, 0xff, 0xff, 0xff),
8730 .driver_info = (unsigned long)&rtl8192cu_fops},
8731{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7822, 0xff, 0xff, 0xff),
8732 .driver_info = (unsigned long)&rtl8192cu_fops},
8733#endif
8734{ }
8735};
8736
8737static struct usb_driver rtl8xxxu_driver = {
8738 .name = DRIVER_NAME,
8739 .probe = rtl8xxxu_probe,
8740 .disconnect = rtl8xxxu_disconnect,
8741 .id_table = dev_table,
8742 .disable_hub_initiated_lpm = 1,
8743};
8744
8745static int __init rtl8xxxu_module_init(void)
8746{
8747 int res;
8748
8749 res = usb_register(&rtl8xxxu_driver);
8750 if (res < 0)
8751 pr_err(DRIVER_NAME ": usb_register() failed (%i)\n", res);
8752
8753 return res;
8754}
8755
8756static void __exit rtl8xxxu_module_exit(void)
8757{
8758 usb_deregister(&rtl8xxxu_driver);
8759}
8760
8761
8762MODULE_DEVICE_TABLE(usb, dev_table);
8763
8764module_init(rtl8xxxu_module_init);
8765module_exit(rtl8xxxu_module_exit);