18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * RTL8XXXU mac80211 USB driver - 8188c/8188r/8192c specific subdriver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2014 - 2017 Jes Sorensen <Jes.Sorensen@gmail.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Portions, notably calibration code:
88c2ecf20Sopenharmony_ci * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * This driver was written as a replacement for the vendor provided
118c2ecf20Sopenharmony_ci * rtl8723au driver. As the Realtek 8xxx chips are very similar in
128c2ecf20Sopenharmony_ci * their programming interface, I have started adding support for
138c2ecf20Sopenharmony_ci * additional 8xxx chips like the 8192cu, 8188cus, etc.
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/init.h>
178c2ecf20Sopenharmony_ci#include <linux/kernel.h>
188c2ecf20Sopenharmony_ci#include <linux/sched.h>
198c2ecf20Sopenharmony_ci#include <linux/errno.h>
208c2ecf20Sopenharmony_ci#include <linux/slab.h>
218c2ecf20Sopenharmony_ci#include <linux/module.h>
228c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
238c2ecf20Sopenharmony_ci#include <linux/list.h>
248c2ecf20Sopenharmony_ci#include <linux/usb.h>
258c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
268c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
278c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
288c2ecf20Sopenharmony_ci#include <linux/wireless.h>
298c2ecf20Sopenharmony_ci#include <linux/firmware.h>
308c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
318c2ecf20Sopenharmony_ci#include <net/mac80211.h>
328c2ecf20Sopenharmony_ci#include "rtl8xxxu.h"
338c2ecf20Sopenharmony_ci#include "rtl8xxxu_regs.h"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifdef CONFIG_RTL8XXXU_UNTESTED
368c2ecf20Sopenharmony_cistatic struct rtl8xxxu_power_base rtl8192c_power_base = {
378c2ecf20Sopenharmony_ci	.reg_0e00 = 0x07090c0c,
388c2ecf20Sopenharmony_ci	.reg_0e04 = 0x01020405,
398c2ecf20Sopenharmony_ci	.reg_0e08 = 0x00000000,
408c2ecf20Sopenharmony_ci	.reg_086c = 0x00000000,
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	.reg_0e10 = 0x0b0c0c0e,
438c2ecf20Sopenharmony_ci	.reg_0e14 = 0x01030506,
448c2ecf20Sopenharmony_ci	.reg_0e18 = 0x0b0c0d0e,
458c2ecf20Sopenharmony_ci	.reg_0e1c = 0x01030509,
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	.reg_0830 = 0x07090c0c,
488c2ecf20Sopenharmony_ci	.reg_0834 = 0x01020405,
498c2ecf20Sopenharmony_ci	.reg_0838 = 0x00000000,
508c2ecf20Sopenharmony_ci	.reg_086c_2 = 0x00000000,
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	.reg_083c = 0x0b0c0d0e,
538c2ecf20Sopenharmony_ci	.reg_0848 = 0x01030509,
548c2ecf20Sopenharmony_ci	.reg_084c = 0x0b0c0d0e,
558c2ecf20Sopenharmony_ci	.reg_0868 = 0x01030509,
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct rtl8xxxu_power_base rtl8188r_power_base = {
598c2ecf20Sopenharmony_ci	.reg_0e00 = 0x06080808,
608c2ecf20Sopenharmony_ci	.reg_0e04 = 0x00040406,
618c2ecf20Sopenharmony_ci	.reg_0e08 = 0x00000000,
628c2ecf20Sopenharmony_ci	.reg_086c = 0x00000000,
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	.reg_0e10 = 0x04060608,
658c2ecf20Sopenharmony_ci	.reg_0e14 = 0x00020204,
668c2ecf20Sopenharmony_ci	.reg_0e18 = 0x04060608,
678c2ecf20Sopenharmony_ci	.reg_0e1c = 0x00020204,
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	.reg_0830 = 0x06080808,
708c2ecf20Sopenharmony_ci	.reg_0834 = 0x00040406,
718c2ecf20Sopenharmony_ci	.reg_0838 = 0x00000000,
728c2ecf20Sopenharmony_ci	.reg_086c_2 = 0x00000000,
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	.reg_083c = 0x04060608,
758c2ecf20Sopenharmony_ci	.reg_0848 = 0x00020204,
768c2ecf20Sopenharmony_ci	.reg_084c = 0x04060608,
778c2ecf20Sopenharmony_ci	.reg_0868 = 0x00020204,
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic struct rtl8xxxu_rfregval rtl8192cu_radioa_2t_init_table[] = {
818c2ecf20Sopenharmony_ci	{0x00, 0x00030159}, {0x01, 0x00031284},
828c2ecf20Sopenharmony_ci	{0x02, 0x00098000}, {0x03, 0x00018c63},
838c2ecf20Sopenharmony_ci	{0x04, 0x000210e7}, {0x09, 0x0002044f},
848c2ecf20Sopenharmony_ci	{0x0a, 0x0001adb1}, {0x0b, 0x00054867},
858c2ecf20Sopenharmony_ci	{0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
868c2ecf20Sopenharmony_ci	{0x0e, 0x00039ce7}, {0x0f, 0x00000451},
878c2ecf20Sopenharmony_ci	{0x19, 0x00000000}, {0x1a, 0x00010255},
888c2ecf20Sopenharmony_ci	{0x1b, 0x00060a00}, {0x1c, 0x000fc378},
898c2ecf20Sopenharmony_ci	{0x1d, 0x000a1250}, {0x1e, 0x0004445f},
908c2ecf20Sopenharmony_ci	{0x1f, 0x00080001}, {0x20, 0x0000b614},
918c2ecf20Sopenharmony_ci	{0x21, 0x0006c000}, {0x22, 0x00000000},
928c2ecf20Sopenharmony_ci	{0x23, 0x00001558}, {0x24, 0x00000060},
938c2ecf20Sopenharmony_ci	{0x25, 0x00000483}, {0x26, 0x0004f000},
948c2ecf20Sopenharmony_ci	{0x27, 0x000ec7d9}, {0x28, 0x000577c0},
958c2ecf20Sopenharmony_ci	{0x29, 0x00004783}, {0x2a, 0x00000001},
968c2ecf20Sopenharmony_ci	{0x2b, 0x00021334}, {0x2a, 0x00000000},
978c2ecf20Sopenharmony_ci	{0x2b, 0x00000054}, {0x2a, 0x00000001},
988c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00053333},
998c2ecf20Sopenharmony_ci	{0x2c, 0x0000000c}, {0x2a, 0x00000002},
1008c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x0005b333},
1018c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000003},
1028c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00063333},
1038c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000004},
1048c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x0006b333},
1058c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000005},
1068c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00073333},
1078c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000006},
1088c2ecf20Sopenharmony_ci	{0x2b, 0x00000709}, {0x2b, 0x0005b333},
1098c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000007},
1108c2ecf20Sopenharmony_ci	{0x2b, 0x00000709}, {0x2b, 0x00063333},
1118c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000008},
1128c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0004b333},
1138c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000009},
1148c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00053333},
1158c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000a},
1168c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0005b333},
1178c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000b},
1188c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00063333},
1198c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000c},
1208c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0006b333},
1218c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000d},
1228c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00073333},
1238c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000e},
1248c2ecf20Sopenharmony_ci	{0x2b, 0x0000050b}, {0x2b, 0x00066666},
1258c2ecf20Sopenharmony_ci	{0x2c, 0x0000001a}, {0x2a, 0x000e0000},
1268c2ecf20Sopenharmony_ci	{0x10, 0x0004000f}, {0x11, 0x000e31fc},
1278c2ecf20Sopenharmony_ci	{0x10, 0x0006000f}, {0x11, 0x000ff9f8},
1288c2ecf20Sopenharmony_ci	{0x10, 0x0002000f}, {0x11, 0x000203f9},
1298c2ecf20Sopenharmony_ci	{0x10, 0x0003000f}, {0x11, 0x000ff500},
1308c2ecf20Sopenharmony_ci	{0x10, 0x00000000}, {0x11, 0x00000000},
1318c2ecf20Sopenharmony_ci	{0x10, 0x0008000f}, {0x11, 0x0003f100},
1328c2ecf20Sopenharmony_ci	{0x10, 0x0009000f}, {0x11, 0x00023100},
1338c2ecf20Sopenharmony_ci	{0x12, 0x00032000}, {0x12, 0x00071000},
1348c2ecf20Sopenharmony_ci	{0x12, 0x000b0000}, {0x12, 0x000fc000},
1358c2ecf20Sopenharmony_ci	{0x13, 0x000287b3}, {0x13, 0x000244b7},
1368c2ecf20Sopenharmony_ci	{0x13, 0x000204ab}, {0x13, 0x0001c49f},
1378c2ecf20Sopenharmony_ci	{0x13, 0x00018493}, {0x13, 0x0001429b},
1388c2ecf20Sopenharmony_ci	{0x13, 0x00010299}, {0x13, 0x0000c29c},
1398c2ecf20Sopenharmony_ci	{0x13, 0x000081a0}, {0x13, 0x000040ac},
1408c2ecf20Sopenharmony_ci	{0x13, 0x00000020}, {0x14, 0x0001944c},
1418c2ecf20Sopenharmony_ci	{0x14, 0x00059444}, {0x14, 0x0009944c},
1428c2ecf20Sopenharmony_ci	{0x14, 0x000d9444}, {0x15, 0x0000f424},
1438c2ecf20Sopenharmony_ci	{0x15, 0x0004f424}, {0x15, 0x0008f424},
1448c2ecf20Sopenharmony_ci	{0x15, 0x000cf424}, {0x16, 0x000e0330},
1458c2ecf20Sopenharmony_ci	{0x16, 0x000a0330}, {0x16, 0x00060330},
1468c2ecf20Sopenharmony_ci	{0x16, 0x00020330}, {0x00, 0x00010159},
1478c2ecf20Sopenharmony_ci	{0x18, 0x0000f401}, {0xfe, 0x00000000},
1488c2ecf20Sopenharmony_ci	{0xfe, 0x00000000}, {0x1f, 0x00080003},
1498c2ecf20Sopenharmony_ci	{0xfe, 0x00000000}, {0xfe, 0x00000000},
1508c2ecf20Sopenharmony_ci	{0x1e, 0x00044457}, {0x1f, 0x00080000},
1518c2ecf20Sopenharmony_ci	{0x00, 0x00030159},
1528c2ecf20Sopenharmony_ci	{0xff, 0xffffffff}
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic struct rtl8xxxu_rfregval rtl8192cu_radiob_2t_init_table[] = {
1568c2ecf20Sopenharmony_ci	{0x00, 0x00030159}, {0x01, 0x00031284},
1578c2ecf20Sopenharmony_ci	{0x02, 0x00098000}, {0x03, 0x00018c63},
1588c2ecf20Sopenharmony_ci	{0x04, 0x000210e7}, {0x09, 0x0002044f},
1598c2ecf20Sopenharmony_ci	{0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1608c2ecf20Sopenharmony_ci	{0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1618c2ecf20Sopenharmony_ci	{0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1628c2ecf20Sopenharmony_ci	{0x12, 0x00032000}, {0x12, 0x00071000},
1638c2ecf20Sopenharmony_ci	{0x12, 0x000b0000}, {0x12, 0x000fc000},
1648c2ecf20Sopenharmony_ci	{0x13, 0x000287af}, {0x13, 0x000244b7},
1658c2ecf20Sopenharmony_ci	{0x13, 0x000204ab}, {0x13, 0x0001c49f},
1668c2ecf20Sopenharmony_ci	{0x13, 0x00018493}, {0x13, 0x00014297},
1678c2ecf20Sopenharmony_ci	{0x13, 0x00010295}, {0x13, 0x0000c298},
1688c2ecf20Sopenharmony_ci	{0x13, 0x0000819c}, {0x13, 0x000040a8},
1698c2ecf20Sopenharmony_ci	{0x13, 0x0000001c}, {0x14, 0x0001944c},
1708c2ecf20Sopenharmony_ci	{0x14, 0x00059444}, {0x14, 0x0009944c},
1718c2ecf20Sopenharmony_ci	{0x14, 0x000d9444}, {0x15, 0x0000f424},
1728c2ecf20Sopenharmony_ci	{0x15, 0x0004f424}, {0x15, 0x0008f424},
1738c2ecf20Sopenharmony_ci	{0x15, 0x000cf424}, {0x16, 0x000e0330},
1748c2ecf20Sopenharmony_ci	{0x16, 0x000a0330}, {0x16, 0x00060330},
1758c2ecf20Sopenharmony_ci	{0x16, 0x00020330},
1768c2ecf20Sopenharmony_ci	{0xff, 0xffffffff}
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic struct rtl8xxxu_rfregval rtl8192cu_radioa_1t_init_table[] = {
1808c2ecf20Sopenharmony_ci	{0x00, 0x00030159}, {0x01, 0x00031284},
1818c2ecf20Sopenharmony_ci	{0x02, 0x00098000}, {0x03, 0x00018c63},
1828c2ecf20Sopenharmony_ci	{0x04, 0x000210e7}, {0x09, 0x0002044f},
1838c2ecf20Sopenharmony_ci	{0x0a, 0x0001adb1}, {0x0b, 0x00054867},
1848c2ecf20Sopenharmony_ci	{0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
1858c2ecf20Sopenharmony_ci	{0x0e, 0x00039ce7}, {0x0f, 0x00000451},
1868c2ecf20Sopenharmony_ci	{0x19, 0x00000000}, {0x1a, 0x00010255},
1878c2ecf20Sopenharmony_ci	{0x1b, 0x00060a00}, {0x1c, 0x000fc378},
1888c2ecf20Sopenharmony_ci	{0x1d, 0x000a1250}, {0x1e, 0x0004445f},
1898c2ecf20Sopenharmony_ci	{0x1f, 0x00080001}, {0x20, 0x0000b614},
1908c2ecf20Sopenharmony_ci	{0x21, 0x0006c000}, {0x22, 0x00000000},
1918c2ecf20Sopenharmony_ci	{0x23, 0x00001558}, {0x24, 0x00000060},
1928c2ecf20Sopenharmony_ci	{0x25, 0x00000483}, {0x26, 0x0004f000},
1938c2ecf20Sopenharmony_ci	{0x27, 0x000ec7d9}, {0x28, 0x000577c0},
1948c2ecf20Sopenharmony_ci	{0x29, 0x00004783}, {0x2a, 0x00000001},
1958c2ecf20Sopenharmony_ci	{0x2b, 0x00021334}, {0x2a, 0x00000000},
1968c2ecf20Sopenharmony_ci	{0x2b, 0x00000054}, {0x2a, 0x00000001},
1978c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00053333},
1988c2ecf20Sopenharmony_ci	{0x2c, 0x0000000c}, {0x2a, 0x00000002},
1998c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x0005b333},
2008c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000003},
2018c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00063333},
2028c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000004},
2038c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x0006b333},
2048c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000005},
2058c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00073333},
2068c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000006},
2078c2ecf20Sopenharmony_ci	{0x2b, 0x00000709}, {0x2b, 0x0005b333},
2088c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000007},
2098c2ecf20Sopenharmony_ci	{0x2b, 0x00000709}, {0x2b, 0x00063333},
2108c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000008},
2118c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0004b333},
2128c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000009},
2138c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00053333},
2148c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000a},
2158c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0005b333},
2168c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000b},
2178c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00063333},
2188c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000c},
2198c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0006b333},
2208c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000d},
2218c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00073333},
2228c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000e},
2238c2ecf20Sopenharmony_ci	{0x2b, 0x0000050b}, {0x2b, 0x00066666},
2248c2ecf20Sopenharmony_ci	{0x2c, 0x0000001a}, {0x2a, 0x000e0000},
2258c2ecf20Sopenharmony_ci	{0x10, 0x0004000f}, {0x11, 0x000e31fc},
2268c2ecf20Sopenharmony_ci	{0x10, 0x0006000f}, {0x11, 0x000ff9f8},
2278c2ecf20Sopenharmony_ci	{0x10, 0x0002000f}, {0x11, 0x000203f9},
2288c2ecf20Sopenharmony_ci	{0x10, 0x0003000f}, {0x11, 0x000ff500},
2298c2ecf20Sopenharmony_ci	{0x10, 0x00000000}, {0x11, 0x00000000},
2308c2ecf20Sopenharmony_ci	{0x10, 0x0008000f}, {0x11, 0x0003f100},
2318c2ecf20Sopenharmony_ci	{0x10, 0x0009000f}, {0x11, 0x00023100},
2328c2ecf20Sopenharmony_ci	{0x12, 0x00032000}, {0x12, 0x00071000},
2338c2ecf20Sopenharmony_ci	{0x12, 0x000b0000}, {0x12, 0x000fc000},
2348c2ecf20Sopenharmony_ci	{0x13, 0x000287b3}, {0x13, 0x000244b7},
2358c2ecf20Sopenharmony_ci	{0x13, 0x000204ab}, {0x13, 0x0001c49f},
2368c2ecf20Sopenharmony_ci	{0x13, 0x00018493}, {0x13, 0x0001429b},
2378c2ecf20Sopenharmony_ci	{0x13, 0x00010299}, {0x13, 0x0000c29c},
2388c2ecf20Sopenharmony_ci	{0x13, 0x000081a0}, {0x13, 0x000040ac},
2398c2ecf20Sopenharmony_ci	{0x13, 0x00000020}, {0x14, 0x0001944c},
2408c2ecf20Sopenharmony_ci	{0x14, 0x00059444}, {0x14, 0x0009944c},
2418c2ecf20Sopenharmony_ci	{0x14, 0x000d9444}, {0x15, 0x0000f405},
2428c2ecf20Sopenharmony_ci	{0x15, 0x0004f405}, {0x15, 0x0008f405},
2438c2ecf20Sopenharmony_ci	{0x15, 0x000cf405}, {0x16, 0x000e0330},
2448c2ecf20Sopenharmony_ci	{0x16, 0x000a0330}, {0x16, 0x00060330},
2458c2ecf20Sopenharmony_ci	{0x16, 0x00020330}, {0x00, 0x00010159},
2468c2ecf20Sopenharmony_ci	{0x18, 0x0000f401}, {0xfe, 0x00000000},
2478c2ecf20Sopenharmony_ci	{0xfe, 0x00000000}, {0x1f, 0x00080003},
2488c2ecf20Sopenharmony_ci	{0xfe, 0x00000000}, {0xfe, 0x00000000},
2498c2ecf20Sopenharmony_ci	{0x1e, 0x00044457}, {0x1f, 0x00080000},
2508c2ecf20Sopenharmony_ci	{0x00, 0x00030159},
2518c2ecf20Sopenharmony_ci	{0xff, 0xffffffff}
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_cistatic struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = {
2558c2ecf20Sopenharmony_ci	{0x00, 0x00030159}, {0x01, 0x00031284},
2568c2ecf20Sopenharmony_ci	{0x02, 0x00098000}, {0x03, 0x00018c63},
2578c2ecf20Sopenharmony_ci	{0x04, 0x000210e7}, {0x09, 0x0002044f},
2588c2ecf20Sopenharmony_ci	{0x0a, 0x0001adb0}, {0x0b, 0x00054867},
2598c2ecf20Sopenharmony_ci	{0x0c, 0x0008992e}, {0x0d, 0x0000e529},
2608c2ecf20Sopenharmony_ci	{0x0e, 0x00039ce7}, {0x0f, 0x00000451},
2618c2ecf20Sopenharmony_ci	{0x19, 0x00000000}, {0x1a, 0x00000255},
2628c2ecf20Sopenharmony_ci	{0x1b, 0x00060a00}, {0x1c, 0x000fc378},
2638c2ecf20Sopenharmony_ci	{0x1d, 0x000a1250}, {0x1e, 0x0004445f},
2648c2ecf20Sopenharmony_ci	{0x1f, 0x00080001}, {0x20, 0x0000b614},
2658c2ecf20Sopenharmony_ci	{0x21, 0x0006c000}, {0x22, 0x0000083c},
2668c2ecf20Sopenharmony_ci	{0x23, 0x00001558}, {0x24, 0x00000060},
2678c2ecf20Sopenharmony_ci	{0x25, 0x00000483}, {0x26, 0x0004f000},
2688c2ecf20Sopenharmony_ci	{0x27, 0x000ec7d9}, {0x28, 0x000977c0},
2698c2ecf20Sopenharmony_ci	{0x29, 0x00004783}, {0x2a, 0x00000001},
2708c2ecf20Sopenharmony_ci	{0x2b, 0x00021334}, {0x2a, 0x00000000},
2718c2ecf20Sopenharmony_ci	{0x2b, 0x00000054}, {0x2a, 0x00000001},
2728c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00053333},
2738c2ecf20Sopenharmony_ci	{0x2c, 0x0000000c}, {0x2a, 0x00000002},
2748c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x0005b333},
2758c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000003},
2768c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00063333},
2778c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000004},
2788c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x0006b333},
2798c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000005},
2808c2ecf20Sopenharmony_ci	{0x2b, 0x00000808}, {0x2b, 0x00073333},
2818c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000006},
2828c2ecf20Sopenharmony_ci	{0x2b, 0x00000709}, {0x2b, 0x0005b333},
2838c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000007},
2848c2ecf20Sopenharmony_ci	{0x2b, 0x00000709}, {0x2b, 0x00063333},
2858c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000008},
2868c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0004b333},
2878c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x00000009},
2888c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00053333},
2898c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000a},
2908c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0005b333},
2918c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000b},
2928c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00063333},
2938c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000c},
2948c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x0006b333},
2958c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000d},
2968c2ecf20Sopenharmony_ci	{0x2b, 0x0000060a}, {0x2b, 0x00073333},
2978c2ecf20Sopenharmony_ci	{0x2c, 0x0000000d}, {0x2a, 0x0000000e},
2988c2ecf20Sopenharmony_ci	{0x2b, 0x0000050b}, {0x2b, 0x00066666},
2998c2ecf20Sopenharmony_ci	{0x2c, 0x0000001a}, {0x2a, 0x000e0000},
3008c2ecf20Sopenharmony_ci	{0x10, 0x0004000f}, {0x11, 0x000e31fc},
3018c2ecf20Sopenharmony_ci	{0x10, 0x0006000f}, {0x11, 0x000ff9f8},
3028c2ecf20Sopenharmony_ci	{0x10, 0x0002000f}, {0x11, 0x000203f9},
3038c2ecf20Sopenharmony_ci	{0x10, 0x0003000f}, {0x11, 0x000ff500},
3048c2ecf20Sopenharmony_ci	{0x10, 0x00000000}, {0x11, 0x00000000},
3058c2ecf20Sopenharmony_ci	{0x10, 0x0008000f}, {0x11, 0x0003f100},
3068c2ecf20Sopenharmony_ci	{0x10, 0x0009000f}, {0x11, 0x00023100},
3078c2ecf20Sopenharmony_ci	{0x12, 0x000d8000}, {0x12, 0x00090000},
3088c2ecf20Sopenharmony_ci	{0x12, 0x00051000}, {0x12, 0x00012000},
3098c2ecf20Sopenharmony_ci	{0x13, 0x00028fb4}, {0x13, 0x00024fa8},
3108c2ecf20Sopenharmony_ci	{0x13, 0x000207a4}, {0x13, 0x0001c3b0},
3118c2ecf20Sopenharmony_ci	{0x13, 0x000183a4}, {0x13, 0x00014398},
3128c2ecf20Sopenharmony_ci	{0x13, 0x000101a4}, {0x13, 0x0000c198},
3138c2ecf20Sopenharmony_ci	{0x13, 0x000080a4}, {0x13, 0x00004098},
3148c2ecf20Sopenharmony_ci	{0x13, 0x00000000}, {0x14, 0x0001944c},
3158c2ecf20Sopenharmony_ci	{0x14, 0x00059444}, {0x14, 0x0009944c},
3168c2ecf20Sopenharmony_ci	{0x14, 0x000d9444}, {0x15, 0x0000f405},
3178c2ecf20Sopenharmony_ci	{0x15, 0x0004f405}, {0x15, 0x0008f405},
3188c2ecf20Sopenharmony_ci	{0x15, 0x000cf405}, {0x16, 0x000e0330},
3198c2ecf20Sopenharmony_ci	{0x16, 0x000a0330}, {0x16, 0x00060330},
3208c2ecf20Sopenharmony_ci	{0x16, 0x00020330}, {0x00, 0x00010159},
3218c2ecf20Sopenharmony_ci	{0x18, 0x0000f401}, {0xfe, 0x00000000},
3228c2ecf20Sopenharmony_ci	{0xfe, 0x00000000}, {0x1f, 0x00080003},
3238c2ecf20Sopenharmony_ci	{0xfe, 0x00000000}, {0xfe, 0x00000000},
3248c2ecf20Sopenharmony_ci	{0x1e, 0x00044457}, {0x1f, 0x00080000},
3258c2ecf20Sopenharmony_ci	{0x00, 0x00030159},
3268c2ecf20Sopenharmony_ci	{0xff, 0xffffffff}
3278c2ecf20Sopenharmony_ci};
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	char *fw_name;
3328c2ecf20Sopenharmony_ci	int ret;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	if (!priv->vendor_umc)
3358c2ecf20Sopenharmony_ci		fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
3368c2ecf20Sopenharmony_ci	else if (priv->chip_cut || priv->rtl_chip == RTL8192C)
3378c2ecf20Sopenharmony_ci		fw_name = "rtlwifi/rtl8192cufw_B.bin";
3388c2ecf20Sopenharmony_ci	else
3398c2ecf20Sopenharmony_ci		fw_name = "rtlwifi/rtl8192cufw_A.bin";
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	ret = rtl8xxxu_load_firmware(priv, fw_name);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	return ret;
3448c2ecf20Sopenharmony_ci}
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_cistatic int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
3478c2ecf20Sopenharmony_ci{
3488c2ecf20Sopenharmony_ci	struct rtl8192cu_efuse *efuse = &priv->efuse_wifi.efuse8192;
3498c2ecf20Sopenharmony_ci	int i;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	if (efuse->rtl_id != cpu_to_le16(0x8129))
3528c2ecf20Sopenharmony_ci		return -EINVAL;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	ether_addr_copy(priv->mac_addr, efuse->mac_addr);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	memcpy(priv->cck_tx_power_index_A,
3578c2ecf20Sopenharmony_ci	       efuse->cck_tx_power_index_A,
3588c2ecf20Sopenharmony_ci	       sizeof(efuse->cck_tx_power_index_A));
3598c2ecf20Sopenharmony_ci	memcpy(priv->cck_tx_power_index_B,
3608c2ecf20Sopenharmony_ci	       efuse->cck_tx_power_index_B,
3618c2ecf20Sopenharmony_ci	       sizeof(efuse->cck_tx_power_index_B));
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	memcpy(priv->ht40_1s_tx_power_index_A,
3648c2ecf20Sopenharmony_ci	       efuse->ht40_1s_tx_power_index_A,
3658c2ecf20Sopenharmony_ci	       sizeof(efuse->ht40_1s_tx_power_index_A));
3668c2ecf20Sopenharmony_ci	memcpy(priv->ht40_1s_tx_power_index_B,
3678c2ecf20Sopenharmony_ci	       efuse->ht40_1s_tx_power_index_B,
3688c2ecf20Sopenharmony_ci	       sizeof(efuse->ht40_1s_tx_power_index_B));
3698c2ecf20Sopenharmony_ci	memcpy(priv->ht40_2s_tx_power_index_diff,
3708c2ecf20Sopenharmony_ci	       efuse->ht40_2s_tx_power_index_diff,
3718c2ecf20Sopenharmony_ci	       sizeof(efuse->ht40_2s_tx_power_index_diff));
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	memcpy(priv->ht20_tx_power_index_diff,
3748c2ecf20Sopenharmony_ci	       efuse->ht20_tx_power_index_diff,
3758c2ecf20Sopenharmony_ci	       sizeof(efuse->ht20_tx_power_index_diff));
3768c2ecf20Sopenharmony_ci	memcpy(priv->ofdm_tx_power_index_diff,
3778c2ecf20Sopenharmony_ci	       efuse->ofdm_tx_power_index_diff,
3788c2ecf20Sopenharmony_ci	       sizeof(efuse->ofdm_tx_power_index_diff));
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	memcpy(priv->ht40_max_power_offset,
3818c2ecf20Sopenharmony_ci	       efuse->ht40_max_power_offset,
3828c2ecf20Sopenharmony_ci	       sizeof(efuse->ht40_max_power_offset));
3838c2ecf20Sopenharmony_ci	memcpy(priv->ht20_max_power_offset,
3848c2ecf20Sopenharmony_ci	       efuse->ht20_max_power_offset,
3858c2ecf20Sopenharmony_ci	       sizeof(efuse->ht20_max_power_offset));
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	dev_info(&priv->udev->dev, "Vendor: %.7s\n",
3888c2ecf20Sopenharmony_ci		 efuse->vendor_name);
3898c2ecf20Sopenharmony_ci	dev_info(&priv->udev->dev, "Product: %.20s\n",
3908c2ecf20Sopenharmony_ci		 efuse->device_name);
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci	priv->power_base = &rtl8192c_power_base;
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	if (efuse->rf_regulatory & 0x20) {
3958c2ecf20Sopenharmony_ci		sprintf(priv->chip_name, "8188RU");
3968c2ecf20Sopenharmony_ci		priv->rtl_chip = RTL8188R;
3978c2ecf20Sopenharmony_ci		priv->hi_pa = 1;
3988c2ecf20Sopenharmony_ci		priv->no_pape = 1;
3998c2ecf20Sopenharmony_ci		priv->power_base = &rtl8188r_power_base;
4008c2ecf20Sopenharmony_ci	}
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
4038c2ecf20Sopenharmony_ci		unsigned char *raw = priv->efuse_wifi.raw;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci		dev_info(&priv->udev->dev,
4068c2ecf20Sopenharmony_ci			 "%s: dumping efuse (0x%02zx bytes):\n",
4078c2ecf20Sopenharmony_ci			 __func__, sizeof(struct rtl8192cu_efuse));
4088c2ecf20Sopenharmony_ci		for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8)
4098c2ecf20Sopenharmony_ci			dev_info(&priv->udev->dev, "%02x: %8ph\n", i, &raw[i]);
4108c2ecf20Sopenharmony_ci	}
4118c2ecf20Sopenharmony_ci	return 0;
4128c2ecf20Sopenharmony_ci}
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_cistatic int rtl8192cu_init_phy_rf(struct rtl8xxxu_priv *priv)
4158c2ecf20Sopenharmony_ci{
4168c2ecf20Sopenharmony_ci	struct rtl8xxxu_rfregval *rftable;
4178c2ecf20Sopenharmony_ci	int ret;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	if (priv->rtl_chip == RTL8188R) {
4208c2ecf20Sopenharmony_ci		rftable = rtl8188ru_radioa_1t_highpa_table;
4218c2ecf20Sopenharmony_ci		ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4228c2ecf20Sopenharmony_ci	} else if (priv->rf_paths == 1) {
4238c2ecf20Sopenharmony_ci		rftable = rtl8192cu_radioa_1t_init_table;
4248c2ecf20Sopenharmony_ci		ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4258c2ecf20Sopenharmony_ci	} else {
4268c2ecf20Sopenharmony_ci		rftable = rtl8192cu_radioa_2t_init_table;
4278c2ecf20Sopenharmony_ci		ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4288c2ecf20Sopenharmony_ci		if (ret)
4298c2ecf20Sopenharmony_ci			goto exit;
4308c2ecf20Sopenharmony_ci		rftable = rtl8192cu_radiob_2t_init_table;
4318c2ecf20Sopenharmony_ci		ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B);
4328c2ecf20Sopenharmony_ci	}
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ciexit:
4358c2ecf20Sopenharmony_ci	return ret;
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_cistatic int rtl8192cu_power_on(struct rtl8xxxu_priv *priv)
4398c2ecf20Sopenharmony_ci{
4408c2ecf20Sopenharmony_ci	u8 val8;
4418c2ecf20Sopenharmony_ci	u16 val16;
4428c2ecf20Sopenharmony_ci	u32 val32;
4438c2ecf20Sopenharmony_ci	int i;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	for (i = 100; i; i--) {
4468c2ecf20Sopenharmony_ci		val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
4478c2ecf20Sopenharmony_ci		if (val8 & APS_FSMCO_PFM_ALDN)
4488c2ecf20Sopenharmony_ci			break;
4498c2ecf20Sopenharmony_ci	}
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	if (!i) {
4528c2ecf20Sopenharmony_ci		pr_info("%s: Poll failed\n", __func__);
4538c2ecf20Sopenharmony_ci		return -ENODEV;
4548c2ecf20Sopenharmony_ci	}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	/*
4578c2ecf20Sopenharmony_ci	 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
4588c2ecf20Sopenharmony_ci	 */
4598c2ecf20Sopenharmony_ci	rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
4608c2ecf20Sopenharmony_ci	rtl8xxxu_write8(priv, REG_SPS0_CTRL, 0x2b);
4618c2ecf20Sopenharmony_ci	udelay(100);
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	val8 = rtl8xxxu_read8(priv, REG_LDOV12D_CTRL);
4648c2ecf20Sopenharmony_ci	if (!(val8 & LDOV12D_ENABLE)) {
4658c2ecf20Sopenharmony_ci		pr_info("%s: Enabling LDOV12D (%02x)\n", __func__, val8);
4668c2ecf20Sopenharmony_ci		val8 |= LDOV12D_ENABLE;
4678c2ecf20Sopenharmony_ci		rtl8xxxu_write8(priv, REG_LDOV12D_CTRL, val8);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci		udelay(100);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci		val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
4728c2ecf20Sopenharmony_ci		val8 &= ~SYS_ISO_MD2PP;
4738c2ecf20Sopenharmony_ci		rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
4748c2ecf20Sopenharmony_ci	}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci	/*
4778c2ecf20Sopenharmony_ci	 * Auto enable WLAN
4788c2ecf20Sopenharmony_ci	 */
4798c2ecf20Sopenharmony_ci	val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
4808c2ecf20Sopenharmony_ci	val16 |= APS_FSMCO_MAC_ENABLE;
4818c2ecf20Sopenharmony_ci	rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	for (i = 1000; i; i--) {
4848c2ecf20Sopenharmony_ci		val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
4858c2ecf20Sopenharmony_ci		if (!(val16 & APS_FSMCO_MAC_ENABLE))
4868c2ecf20Sopenharmony_ci			break;
4878c2ecf20Sopenharmony_ci	}
4888c2ecf20Sopenharmony_ci	if (!i) {
4898c2ecf20Sopenharmony_ci		pr_info("%s: FSMCO_MAC_ENABLE poll failed\n", __func__);
4908c2ecf20Sopenharmony_ci		return -EBUSY;
4918c2ecf20Sopenharmony_ci	}
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	/*
4948c2ecf20Sopenharmony_ci	 * Enable radio, GPIO, LED
4958c2ecf20Sopenharmony_ci	 */
4968c2ecf20Sopenharmony_ci	val16 = APS_FSMCO_HW_SUSPEND | APS_FSMCO_ENABLE_POWERDOWN |
4978c2ecf20Sopenharmony_ci		APS_FSMCO_PFM_ALDN;
4988c2ecf20Sopenharmony_ci	rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci	/*
5018c2ecf20Sopenharmony_ci	 * Release RF digital isolation
5028c2ecf20Sopenharmony_ci	 */
5038c2ecf20Sopenharmony_ci	val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
5048c2ecf20Sopenharmony_ci	val16 &= ~SYS_ISO_DIOR;
5058c2ecf20Sopenharmony_ci	rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci	val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
5088c2ecf20Sopenharmony_ci	val8 &= ~APSD_CTRL_OFF;
5098c2ecf20Sopenharmony_ci	rtl8xxxu_write8(priv, REG_APSD_CTRL, val8);
5108c2ecf20Sopenharmony_ci	for (i = 200; i; i--) {
5118c2ecf20Sopenharmony_ci		val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
5128c2ecf20Sopenharmony_ci		if (!(val8 & APSD_CTRL_OFF_STATUS))
5138c2ecf20Sopenharmony_ci			break;
5148c2ecf20Sopenharmony_ci	}
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	if (!i) {
5178c2ecf20Sopenharmony_ci		pr_info("%s: APSD_CTRL poll failed\n", __func__);
5188c2ecf20Sopenharmony_ci		return -EBUSY;
5198c2ecf20Sopenharmony_ci	}
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	/*
5228c2ecf20Sopenharmony_ci	 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
5238c2ecf20Sopenharmony_ci	 */
5248c2ecf20Sopenharmony_ci	val16 = rtl8xxxu_read16(priv, REG_CR);
5258c2ecf20Sopenharmony_ci	val16 |= CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
5268c2ecf20Sopenharmony_ci		CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | CR_PROTOCOL_ENABLE |
5278c2ecf20Sopenharmony_ci		CR_SCHEDULE_ENABLE | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE;
5288c2ecf20Sopenharmony_ci	rtl8xxxu_write16(priv, REG_CR, val16);
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	rtl8xxxu_write8(priv, 0xfe10, 0x19);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci	/*
5338c2ecf20Sopenharmony_ci	 * Workaround for 8188RU LNA power leakage problem.
5348c2ecf20Sopenharmony_ci	 */
5358c2ecf20Sopenharmony_ci	if (priv->rtl_chip == RTL8188R) {
5368c2ecf20Sopenharmony_ci		val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
5378c2ecf20Sopenharmony_ci		val32 &= ~BIT(1);
5388c2ecf20Sopenharmony_ci		rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
5398c2ecf20Sopenharmony_ci	}
5408c2ecf20Sopenharmony_ci	return 0;
5418c2ecf20Sopenharmony_ci}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistruct rtl8xxxu_fileops rtl8192cu_fops = {
5448c2ecf20Sopenharmony_ci	.parse_efuse = rtl8192cu_parse_efuse,
5458c2ecf20Sopenharmony_ci	.load_firmware = rtl8192cu_load_firmware,
5468c2ecf20Sopenharmony_ci	.power_on = rtl8192cu_power_on,
5478c2ecf20Sopenharmony_ci	.power_off = rtl8xxxu_power_off,
5488c2ecf20Sopenharmony_ci	.reset_8051 = rtl8xxxu_reset_8051,
5498c2ecf20Sopenharmony_ci	.llt_init = rtl8xxxu_init_llt_table,
5508c2ecf20Sopenharmony_ci	.init_phy_bb = rtl8xxxu_gen1_init_phy_bb,
5518c2ecf20Sopenharmony_ci	.init_phy_rf = rtl8192cu_init_phy_rf,
5528c2ecf20Sopenharmony_ci	.phy_iq_calibrate = rtl8xxxu_gen1_phy_iq_calibrate,
5538c2ecf20Sopenharmony_ci	.config_channel = rtl8xxxu_gen1_config_channel,
5548c2ecf20Sopenharmony_ci	.parse_rx_desc = rtl8xxxu_parse_rxdesc16,
5558c2ecf20Sopenharmony_ci	.init_aggregation = rtl8xxxu_gen1_init_aggregation,
5568c2ecf20Sopenharmony_ci	.enable_rf = rtl8xxxu_gen1_enable_rf,
5578c2ecf20Sopenharmony_ci	.disable_rf = rtl8xxxu_gen1_disable_rf,
5588c2ecf20Sopenharmony_ci	.usb_quirks = rtl8xxxu_gen1_usb_quirks,
5598c2ecf20Sopenharmony_ci	.set_tx_power = rtl8xxxu_gen1_set_tx_power,
5608c2ecf20Sopenharmony_ci	.update_rate_mask = rtl8xxxu_update_rate_mask,
5618c2ecf20Sopenharmony_ci	.report_connect = rtl8xxxu_gen1_report_connect,
5628c2ecf20Sopenharmony_ci	.fill_txdesc = rtl8xxxu_fill_txdesc_v1,
5638c2ecf20Sopenharmony_ci	.writeN_block_size = 128,
5648c2ecf20Sopenharmony_ci	.rx_agg_buf_size = 16000,
5658c2ecf20Sopenharmony_ci	.tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
5668c2ecf20Sopenharmony_ci	.rx_desc_size = sizeof(struct rtl8xxxu_rxdesc16),
5678c2ecf20Sopenharmony_ci	.adda_1t_init = 0x0b1b25a0,
5688c2ecf20Sopenharmony_ci	.adda_1t_path_on = 0x0bdb25a0,
5698c2ecf20Sopenharmony_ci	.adda_2t_path_on_a = 0x04db25a4,
5708c2ecf20Sopenharmony_ci	.adda_2t_path_on_b = 0x0b1b25a4,
5718c2ecf20Sopenharmony_ci	.trxff_boundary = 0x27ff,
5728c2ecf20Sopenharmony_ci	.pbp_rx = PBP_PAGE_SIZE_128,
5738c2ecf20Sopenharmony_ci	.pbp_tx = PBP_PAGE_SIZE_128,
5748c2ecf20Sopenharmony_ci	.mactable = rtl8xxxu_gen1_mac_init_table,
5758c2ecf20Sopenharmony_ci	.total_page_num = TX_TOTAL_PAGE_NUM,
5768c2ecf20Sopenharmony_ci	.page_num_hi = TX_PAGE_NUM_HI_PQ,
5778c2ecf20Sopenharmony_ci	.page_num_lo = TX_PAGE_NUM_LO_PQ,
5788c2ecf20Sopenharmony_ci	.page_num_norm = TX_PAGE_NUM_NORM_PQ,
5798c2ecf20Sopenharmony_ci};
5808c2ecf20Sopenharmony_ci#endif
581