18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * RTL8XXXU mac80211 USB driver - 8723b 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_cistatic struct rtl8xxxu_reg8val rtl8723b_mac_init_table[] = { 368c2ecf20Sopenharmony_ci {0x02f, 0x30}, {0x035, 0x00}, {0x039, 0x08}, {0x04e, 0xe0}, 378c2ecf20Sopenharmony_ci {0x064, 0x00}, {0x067, 0x20}, {0x428, 0x0a}, {0x429, 0x10}, 388c2ecf20Sopenharmony_ci {0x430, 0x00}, {0x431, 0x00}, 398c2ecf20Sopenharmony_ci {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05}, 408c2ecf20Sopenharmony_ci {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05}, 418c2ecf20Sopenharmony_ci {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01}, 428c2ecf20Sopenharmony_ci {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00}, 438c2ecf20Sopenharmony_ci {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f}, 448c2ecf20Sopenharmony_ci {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00}, 458c2ecf20Sopenharmony_ci {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f}, 468c2ecf20Sopenharmony_ci {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66}, 478c2ecf20Sopenharmony_ci {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff}, 488c2ecf20Sopenharmony_ci {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2}, 498c2ecf20Sopenharmony_ci {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3}, 508c2ecf20Sopenharmony_ci {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4}, 518c2ecf20Sopenharmony_ci {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4}, 528c2ecf20Sopenharmony_ci {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a}, 538c2ecf20Sopenharmony_ci {0x516, 0x0a}, {0x525, 0x4f}, 548c2ecf20Sopenharmony_ci {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50}, 558c2ecf20Sopenharmony_ci {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a}, 568c2ecf20Sopenharmony_ci {0x620, 0xff}, {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff}, 578c2ecf20Sopenharmony_ci {0x624, 0xff}, {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff}, 588c2ecf20Sopenharmony_ci {0x638, 0x50}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e}, 598c2ecf20Sopenharmony_ci {0x63f, 0x0e}, {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00}, 608c2ecf20Sopenharmony_ci {0x652, 0xc8}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43}, 618c2ecf20Sopenharmony_ci {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43}, 628c2ecf20Sopenharmony_ci {0x70a, 0x65}, {0x70b, 0x87}, {0x765, 0x18}, {0x76e, 0x04}, 638c2ecf20Sopenharmony_ci {0xffff, 0xff}, 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic struct rtl8xxxu_reg32val rtl8723b_phy_1t_init_table[] = { 678c2ecf20Sopenharmony_ci {0x800, 0x80040000}, {0x804, 0x00000003}, 688c2ecf20Sopenharmony_ci {0x808, 0x0000fc00}, {0x80c, 0x0000000a}, 698c2ecf20Sopenharmony_ci {0x810, 0x10001331}, {0x814, 0x020c3d10}, 708c2ecf20Sopenharmony_ci {0x818, 0x02200385}, {0x81c, 0x00000000}, 718c2ecf20Sopenharmony_ci {0x820, 0x01000100}, {0x824, 0x00190204}, 728c2ecf20Sopenharmony_ci {0x828, 0x00000000}, {0x82c, 0x00000000}, 738c2ecf20Sopenharmony_ci {0x830, 0x00000000}, {0x834, 0x00000000}, 748c2ecf20Sopenharmony_ci {0x838, 0x00000000}, {0x83c, 0x00000000}, 758c2ecf20Sopenharmony_ci {0x840, 0x00010000}, {0x844, 0x00000000}, 768c2ecf20Sopenharmony_ci {0x848, 0x00000000}, {0x84c, 0x00000000}, 778c2ecf20Sopenharmony_ci {0x850, 0x00000000}, {0x854, 0x00000000}, 788c2ecf20Sopenharmony_ci {0x858, 0x569a11a9}, {0x85c, 0x01000014}, 798c2ecf20Sopenharmony_ci {0x860, 0x66f60110}, {0x864, 0x061f0649}, 808c2ecf20Sopenharmony_ci {0x868, 0x00000000}, {0x86c, 0x27272700}, 818c2ecf20Sopenharmony_ci {0x870, 0x07000760}, {0x874, 0x25004000}, 828c2ecf20Sopenharmony_ci {0x878, 0x00000808}, {0x87c, 0x00000000}, 838c2ecf20Sopenharmony_ci {0x880, 0xb0000c1c}, {0x884, 0x00000001}, 848c2ecf20Sopenharmony_ci {0x888, 0x00000000}, {0x88c, 0xccc000c0}, 858c2ecf20Sopenharmony_ci {0x890, 0x00000800}, {0x894, 0xfffffffe}, 868c2ecf20Sopenharmony_ci {0x898, 0x40302010}, {0x89c, 0x00706050}, 878c2ecf20Sopenharmony_ci {0x900, 0x00000000}, {0x904, 0x00000023}, 888c2ecf20Sopenharmony_ci {0x908, 0x00000000}, {0x90c, 0x81121111}, 898c2ecf20Sopenharmony_ci {0x910, 0x00000002}, {0x914, 0x00000201}, 908c2ecf20Sopenharmony_ci {0xa00, 0x00d047c8}, {0xa04, 0x80ff800c}, 918c2ecf20Sopenharmony_ci {0xa08, 0x8c838300}, {0xa0c, 0x2e7f120f}, 928c2ecf20Sopenharmony_ci {0xa10, 0x9500bb78}, {0xa14, 0x1114d028}, 938c2ecf20Sopenharmony_ci {0xa18, 0x00881117}, {0xa1c, 0x89140f00}, 948c2ecf20Sopenharmony_ci {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317}, 958c2ecf20Sopenharmony_ci {0xa28, 0x00000204}, {0xa2c, 0x00d30000}, 968c2ecf20Sopenharmony_ci {0xa70, 0x101fbf00}, {0xa74, 0x00000007}, 978c2ecf20Sopenharmony_ci {0xa78, 0x00000900}, {0xa7c, 0x225b0606}, 988c2ecf20Sopenharmony_ci {0xa80, 0x21806490}, {0xb2c, 0x00000000}, 998c2ecf20Sopenharmony_ci {0xc00, 0x48071d40}, {0xc04, 0x03a05611}, 1008c2ecf20Sopenharmony_ci {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c}, 1018c2ecf20Sopenharmony_ci {0xc10, 0x08800000}, {0xc14, 0x40000100}, 1028c2ecf20Sopenharmony_ci {0xc18, 0x08800000}, {0xc1c, 0x40000100}, 1038c2ecf20Sopenharmony_ci {0xc20, 0x00000000}, {0xc24, 0x00000000}, 1048c2ecf20Sopenharmony_ci {0xc28, 0x00000000}, {0xc2c, 0x00000000}, 1058c2ecf20Sopenharmony_ci {0xc30, 0x69e9ac44}, {0xc34, 0x469652af}, 1068c2ecf20Sopenharmony_ci {0xc38, 0x49795994}, {0xc3c, 0x0a97971c}, 1078c2ecf20Sopenharmony_ci {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7}, 1088c2ecf20Sopenharmony_ci {0xc48, 0xec020107}, {0xc4c, 0x007f037f}, 1098c2ecf20Sopenharmony_ci {0xc50, 0x69553420}, {0xc54, 0x43bc0094}, 1108c2ecf20Sopenharmony_ci {0xc58, 0x00013149}, {0xc5c, 0x00250492}, 1118c2ecf20Sopenharmony_ci {0xc60, 0x00000000}, {0xc64, 0x7112848b}, 1128c2ecf20Sopenharmony_ci {0xc68, 0x47c00bff}, {0xc6c, 0x00000036}, 1138c2ecf20Sopenharmony_ci {0xc70, 0x2c7f000d}, {0xc74, 0x020610db}, 1148c2ecf20Sopenharmony_ci {0xc78, 0x0000001f}, {0xc7c, 0x00b91612}, 1158c2ecf20Sopenharmony_ci {0xc80, 0x390000e4}, {0xc84, 0x20f60000}, 1168c2ecf20Sopenharmony_ci {0xc88, 0x40000100}, {0xc8c, 0x20200000}, 1178c2ecf20Sopenharmony_ci {0xc90, 0x00020e1a}, {0xc94, 0x00000000}, 1188c2ecf20Sopenharmony_ci {0xc98, 0x00020e1a}, {0xc9c, 0x00007f7f}, 1198c2ecf20Sopenharmony_ci {0xca0, 0x00000000}, {0xca4, 0x000300a0}, 1208c2ecf20Sopenharmony_ci {0xca8, 0x00000000}, {0xcac, 0x00000000}, 1218c2ecf20Sopenharmony_ci {0xcb0, 0x00000000}, {0xcb4, 0x00000000}, 1228c2ecf20Sopenharmony_ci {0xcb8, 0x00000000}, {0xcbc, 0x28000000}, 1238c2ecf20Sopenharmony_ci {0xcc0, 0x00000000}, {0xcc4, 0x00000000}, 1248c2ecf20Sopenharmony_ci {0xcc8, 0x00000000}, {0xccc, 0x00000000}, 1258c2ecf20Sopenharmony_ci {0xcd0, 0x00000000}, {0xcd4, 0x00000000}, 1268c2ecf20Sopenharmony_ci {0xcd8, 0x64b22427}, {0xcdc, 0x00766932}, 1278c2ecf20Sopenharmony_ci {0xce0, 0x00222222}, {0xce4, 0x00000000}, 1288c2ecf20Sopenharmony_ci {0xce8, 0x37644302}, {0xcec, 0x2f97d40c}, 1298c2ecf20Sopenharmony_ci {0xd00, 0x00000740}, {0xd04, 0x40020401}, 1308c2ecf20Sopenharmony_ci {0xd08, 0x0000907f}, {0xd0c, 0x20010201}, 1318c2ecf20Sopenharmony_ci {0xd10, 0xa0633333}, {0xd14, 0x3333bc53}, 1328c2ecf20Sopenharmony_ci {0xd18, 0x7a8f5b6f}, {0xd2c, 0xcc979975}, 1338c2ecf20Sopenharmony_ci {0xd30, 0x00000000}, {0xd34, 0x80608000}, 1348c2ecf20Sopenharmony_ci {0xd38, 0x00000000}, {0xd3c, 0x00127353}, 1358c2ecf20Sopenharmony_ci {0xd40, 0x00000000}, {0xd44, 0x00000000}, 1368c2ecf20Sopenharmony_ci {0xd48, 0x00000000}, {0xd4c, 0x00000000}, 1378c2ecf20Sopenharmony_ci {0xd50, 0x6437140a}, {0xd54, 0x00000000}, 1388c2ecf20Sopenharmony_ci {0xd58, 0x00000282}, {0xd5c, 0x30032064}, 1398c2ecf20Sopenharmony_ci {0xd60, 0x4653de68}, {0xd64, 0x04518a3c}, 1408c2ecf20Sopenharmony_ci {0xd68, 0x00002101}, {0xd6c, 0x2a201c16}, 1418c2ecf20Sopenharmony_ci {0xd70, 0x1812362e}, {0xd74, 0x322c2220}, 1428c2ecf20Sopenharmony_ci {0xd78, 0x000e3c24}, {0xe00, 0x2d2d2d2d}, 1438c2ecf20Sopenharmony_ci {0xe04, 0x2d2d2d2d}, {0xe08, 0x0390272d}, 1448c2ecf20Sopenharmony_ci {0xe10, 0x2d2d2d2d}, {0xe14, 0x2d2d2d2d}, 1458c2ecf20Sopenharmony_ci {0xe18, 0x2d2d2d2d}, {0xe1c, 0x2d2d2d2d}, 1468c2ecf20Sopenharmony_ci {0xe28, 0x00000000}, {0xe30, 0x1000dc1f}, 1478c2ecf20Sopenharmony_ci {0xe34, 0x10008c1f}, {0xe38, 0x02140102}, 1488c2ecf20Sopenharmony_ci {0xe3c, 0x681604c2}, {0xe40, 0x01007c00}, 1498c2ecf20Sopenharmony_ci {0xe44, 0x01004800}, {0xe48, 0xfb000000}, 1508c2ecf20Sopenharmony_ci {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f}, 1518c2ecf20Sopenharmony_ci {0xe54, 0x10008c1f}, {0xe58, 0x02140102}, 1528c2ecf20Sopenharmony_ci {0xe5c, 0x28160d05}, {0xe60, 0x00000008}, 1538c2ecf20Sopenharmony_ci {0xe68, 0x001b2556}, {0xe6c, 0x00c00096}, 1548c2ecf20Sopenharmony_ci {0xe70, 0x00c00096}, {0xe74, 0x01000056}, 1558c2ecf20Sopenharmony_ci {0xe78, 0x01000014}, {0xe7c, 0x01000056}, 1568c2ecf20Sopenharmony_ci {0xe80, 0x01000014}, {0xe84, 0x00c00096}, 1578c2ecf20Sopenharmony_ci {0xe88, 0x01000056}, {0xe8c, 0x00c00096}, 1588c2ecf20Sopenharmony_ci {0xed0, 0x00c00096}, {0xed4, 0x00c00096}, 1598c2ecf20Sopenharmony_ci {0xed8, 0x00c00096}, {0xedc, 0x000000d6}, 1608c2ecf20Sopenharmony_ci {0xee0, 0x000000d6}, {0xeec, 0x01c00016}, 1618c2ecf20Sopenharmony_ci {0xf14, 0x00000003}, {0xf4c, 0x00000000}, 1628c2ecf20Sopenharmony_ci {0xf00, 0x00000300}, 1638c2ecf20Sopenharmony_ci {0x820, 0x01000100}, {0x800, 0x83040000}, 1648c2ecf20Sopenharmony_ci {0xffff, 0xffffffff}, 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic struct rtl8xxxu_reg32val rtl8xxx_agc_8723bu_table[] = { 1688c2ecf20Sopenharmony_ci {0xc78, 0xfd000001}, {0xc78, 0xfc010001}, 1698c2ecf20Sopenharmony_ci {0xc78, 0xfb020001}, {0xc78, 0xfa030001}, 1708c2ecf20Sopenharmony_ci {0xc78, 0xf9040001}, {0xc78, 0xf8050001}, 1718c2ecf20Sopenharmony_ci {0xc78, 0xf7060001}, {0xc78, 0xf6070001}, 1728c2ecf20Sopenharmony_ci {0xc78, 0xf5080001}, {0xc78, 0xf4090001}, 1738c2ecf20Sopenharmony_ci {0xc78, 0xf30a0001}, {0xc78, 0xf20b0001}, 1748c2ecf20Sopenharmony_ci {0xc78, 0xf10c0001}, {0xc78, 0xf00d0001}, 1758c2ecf20Sopenharmony_ci {0xc78, 0xef0e0001}, {0xc78, 0xee0f0001}, 1768c2ecf20Sopenharmony_ci {0xc78, 0xed100001}, {0xc78, 0xec110001}, 1778c2ecf20Sopenharmony_ci {0xc78, 0xeb120001}, {0xc78, 0xea130001}, 1788c2ecf20Sopenharmony_ci {0xc78, 0xe9140001}, {0xc78, 0xe8150001}, 1798c2ecf20Sopenharmony_ci {0xc78, 0xe7160001}, {0xc78, 0xe6170001}, 1808c2ecf20Sopenharmony_ci {0xc78, 0xe5180001}, {0xc78, 0xe4190001}, 1818c2ecf20Sopenharmony_ci {0xc78, 0xe31a0001}, {0xc78, 0xa51b0001}, 1828c2ecf20Sopenharmony_ci {0xc78, 0xa41c0001}, {0xc78, 0xa31d0001}, 1838c2ecf20Sopenharmony_ci {0xc78, 0x671e0001}, {0xc78, 0x661f0001}, 1848c2ecf20Sopenharmony_ci {0xc78, 0x65200001}, {0xc78, 0x64210001}, 1858c2ecf20Sopenharmony_ci {0xc78, 0x63220001}, {0xc78, 0x4a230001}, 1868c2ecf20Sopenharmony_ci {0xc78, 0x49240001}, {0xc78, 0x48250001}, 1878c2ecf20Sopenharmony_ci {0xc78, 0x47260001}, {0xc78, 0x46270001}, 1888c2ecf20Sopenharmony_ci {0xc78, 0x45280001}, {0xc78, 0x44290001}, 1898c2ecf20Sopenharmony_ci {0xc78, 0x432a0001}, {0xc78, 0x422b0001}, 1908c2ecf20Sopenharmony_ci {0xc78, 0x292c0001}, {0xc78, 0x282d0001}, 1918c2ecf20Sopenharmony_ci {0xc78, 0x272e0001}, {0xc78, 0x262f0001}, 1928c2ecf20Sopenharmony_ci {0xc78, 0x0a300001}, {0xc78, 0x09310001}, 1938c2ecf20Sopenharmony_ci {0xc78, 0x08320001}, {0xc78, 0x07330001}, 1948c2ecf20Sopenharmony_ci {0xc78, 0x06340001}, {0xc78, 0x05350001}, 1958c2ecf20Sopenharmony_ci {0xc78, 0x04360001}, {0xc78, 0x03370001}, 1968c2ecf20Sopenharmony_ci {0xc78, 0x02380001}, {0xc78, 0x01390001}, 1978c2ecf20Sopenharmony_ci {0xc78, 0x013a0001}, {0xc78, 0x013b0001}, 1988c2ecf20Sopenharmony_ci {0xc78, 0x013c0001}, {0xc78, 0x013d0001}, 1998c2ecf20Sopenharmony_ci {0xc78, 0x013e0001}, {0xc78, 0x013f0001}, 2008c2ecf20Sopenharmony_ci {0xc78, 0xfc400001}, {0xc78, 0xfb410001}, 2018c2ecf20Sopenharmony_ci {0xc78, 0xfa420001}, {0xc78, 0xf9430001}, 2028c2ecf20Sopenharmony_ci {0xc78, 0xf8440001}, {0xc78, 0xf7450001}, 2038c2ecf20Sopenharmony_ci {0xc78, 0xf6460001}, {0xc78, 0xf5470001}, 2048c2ecf20Sopenharmony_ci {0xc78, 0xf4480001}, {0xc78, 0xf3490001}, 2058c2ecf20Sopenharmony_ci {0xc78, 0xf24a0001}, {0xc78, 0xf14b0001}, 2068c2ecf20Sopenharmony_ci {0xc78, 0xf04c0001}, {0xc78, 0xef4d0001}, 2078c2ecf20Sopenharmony_ci {0xc78, 0xee4e0001}, {0xc78, 0xed4f0001}, 2088c2ecf20Sopenharmony_ci {0xc78, 0xec500001}, {0xc78, 0xeb510001}, 2098c2ecf20Sopenharmony_ci {0xc78, 0xea520001}, {0xc78, 0xe9530001}, 2108c2ecf20Sopenharmony_ci {0xc78, 0xe8540001}, {0xc78, 0xe7550001}, 2118c2ecf20Sopenharmony_ci {0xc78, 0xe6560001}, {0xc78, 0xe5570001}, 2128c2ecf20Sopenharmony_ci {0xc78, 0xe4580001}, {0xc78, 0xe3590001}, 2138c2ecf20Sopenharmony_ci {0xc78, 0xa65a0001}, {0xc78, 0xa55b0001}, 2148c2ecf20Sopenharmony_ci {0xc78, 0xa45c0001}, {0xc78, 0xa35d0001}, 2158c2ecf20Sopenharmony_ci {0xc78, 0x675e0001}, {0xc78, 0x665f0001}, 2168c2ecf20Sopenharmony_ci {0xc78, 0x65600001}, {0xc78, 0x64610001}, 2178c2ecf20Sopenharmony_ci {0xc78, 0x63620001}, {0xc78, 0x62630001}, 2188c2ecf20Sopenharmony_ci {0xc78, 0x61640001}, {0xc78, 0x48650001}, 2198c2ecf20Sopenharmony_ci {0xc78, 0x47660001}, {0xc78, 0x46670001}, 2208c2ecf20Sopenharmony_ci {0xc78, 0x45680001}, {0xc78, 0x44690001}, 2218c2ecf20Sopenharmony_ci {0xc78, 0x436a0001}, {0xc78, 0x426b0001}, 2228c2ecf20Sopenharmony_ci {0xc78, 0x286c0001}, {0xc78, 0x276d0001}, 2238c2ecf20Sopenharmony_ci {0xc78, 0x266e0001}, {0xc78, 0x256f0001}, 2248c2ecf20Sopenharmony_ci {0xc78, 0x24700001}, {0xc78, 0x09710001}, 2258c2ecf20Sopenharmony_ci {0xc78, 0x08720001}, {0xc78, 0x07730001}, 2268c2ecf20Sopenharmony_ci {0xc78, 0x06740001}, {0xc78, 0x05750001}, 2278c2ecf20Sopenharmony_ci {0xc78, 0x04760001}, {0xc78, 0x03770001}, 2288c2ecf20Sopenharmony_ci {0xc78, 0x02780001}, {0xc78, 0x01790001}, 2298c2ecf20Sopenharmony_ci {0xc78, 0x017a0001}, {0xc78, 0x017b0001}, 2308c2ecf20Sopenharmony_ci {0xc78, 0x017c0001}, {0xc78, 0x017d0001}, 2318c2ecf20Sopenharmony_ci {0xc78, 0x017e0001}, {0xc78, 0x017f0001}, 2328c2ecf20Sopenharmony_ci {0xc50, 0x69553422}, 2338c2ecf20Sopenharmony_ci {0xc50, 0x69553420}, 2348c2ecf20Sopenharmony_ci {0x824, 0x00390204}, 2358c2ecf20Sopenharmony_ci {0xffff, 0xffffffff} 2368c2ecf20Sopenharmony_ci}; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_cistatic struct rtl8xxxu_rfregval rtl8723bu_radioa_1t_init_table[] = { 2398c2ecf20Sopenharmony_ci {0x00, 0x00010000}, {0xb0, 0x000dffe0}, 2408c2ecf20Sopenharmony_ci {0xfe, 0x00000000}, {0xfe, 0x00000000}, 2418c2ecf20Sopenharmony_ci {0xfe, 0x00000000}, {0xb1, 0x00000018}, 2428c2ecf20Sopenharmony_ci {0xfe, 0x00000000}, {0xfe, 0x00000000}, 2438c2ecf20Sopenharmony_ci {0xfe, 0x00000000}, {0xb2, 0x00084c00}, 2448c2ecf20Sopenharmony_ci {0xb5, 0x0000d2cc}, {0xb6, 0x000925aa}, 2458c2ecf20Sopenharmony_ci {0xb7, 0x00000010}, {0xb8, 0x0000907f}, 2468c2ecf20Sopenharmony_ci {0x5c, 0x00000002}, {0x7c, 0x00000002}, 2478c2ecf20Sopenharmony_ci {0x7e, 0x00000005}, {0x8b, 0x0006fc00}, 2488c2ecf20Sopenharmony_ci {0xb0, 0x000ff9f0}, {0x1c, 0x000739d2}, 2498c2ecf20Sopenharmony_ci {0x1e, 0x00000000}, {0xdf, 0x00000780}, 2508c2ecf20Sopenharmony_ci {0x50, 0x00067435}, 2518c2ecf20Sopenharmony_ci /* 2528c2ecf20Sopenharmony_ci * The 8723bu vendor driver indicates that bit 8 should be set in 2538c2ecf20Sopenharmony_ci * 0x51 for package types TFBGA90, TFBGA80, and TFBGA79. However 2548c2ecf20Sopenharmony_ci * they never actually check the package type - and just default 2558c2ecf20Sopenharmony_ci * to not setting it. 2568c2ecf20Sopenharmony_ci */ 2578c2ecf20Sopenharmony_ci {0x51, 0x0006b04e}, 2588c2ecf20Sopenharmony_ci {0x52, 0x000007d2}, {0x53, 0x00000000}, 2598c2ecf20Sopenharmony_ci {0x54, 0x00050400}, {0x55, 0x0004026e}, 2608c2ecf20Sopenharmony_ci {0xdd, 0x0000004c}, {0x70, 0x00067435}, 2618c2ecf20Sopenharmony_ci /* 2628c2ecf20Sopenharmony_ci * 0x71 has same package type condition as for register 0x51 2638c2ecf20Sopenharmony_ci */ 2648c2ecf20Sopenharmony_ci {0x71, 0x0006b04e}, 2658c2ecf20Sopenharmony_ci {0x72, 0x000007d2}, {0x73, 0x00000000}, 2668c2ecf20Sopenharmony_ci {0x74, 0x00050400}, {0x75, 0x0004026e}, 2678c2ecf20Sopenharmony_ci {0xef, 0x00000100}, {0x34, 0x0000add7}, 2688c2ecf20Sopenharmony_ci {0x35, 0x00005c00}, {0x34, 0x00009dd4}, 2698c2ecf20Sopenharmony_ci {0x35, 0x00005000}, {0x34, 0x00008dd1}, 2708c2ecf20Sopenharmony_ci {0x35, 0x00004400}, {0x34, 0x00007dce}, 2718c2ecf20Sopenharmony_ci {0x35, 0x00003800}, {0x34, 0x00006cd1}, 2728c2ecf20Sopenharmony_ci {0x35, 0x00004400}, {0x34, 0x00005cce}, 2738c2ecf20Sopenharmony_ci {0x35, 0x00003800}, {0x34, 0x000048ce}, 2748c2ecf20Sopenharmony_ci {0x35, 0x00004400}, {0x34, 0x000034ce}, 2758c2ecf20Sopenharmony_ci {0x35, 0x00003800}, {0x34, 0x00002451}, 2768c2ecf20Sopenharmony_ci {0x35, 0x00004400}, {0x34, 0x0000144e}, 2778c2ecf20Sopenharmony_ci {0x35, 0x00003800}, {0x34, 0x00000051}, 2788c2ecf20Sopenharmony_ci {0x35, 0x00004400}, {0xef, 0x00000000}, 2798c2ecf20Sopenharmony_ci {0xef, 0x00000100}, {0xed, 0x00000010}, 2808c2ecf20Sopenharmony_ci {0x44, 0x0000add7}, {0x44, 0x00009dd4}, 2818c2ecf20Sopenharmony_ci {0x44, 0x00008dd1}, {0x44, 0x00007dce}, 2828c2ecf20Sopenharmony_ci {0x44, 0x00006cc1}, {0x44, 0x00005cce}, 2838c2ecf20Sopenharmony_ci {0x44, 0x000044d1}, {0x44, 0x000034ce}, 2848c2ecf20Sopenharmony_ci {0x44, 0x00002451}, {0x44, 0x0000144e}, 2858c2ecf20Sopenharmony_ci {0x44, 0x00000051}, {0xef, 0x00000000}, 2868c2ecf20Sopenharmony_ci {0xed, 0x00000000}, {0x7f, 0x00020080}, 2878c2ecf20Sopenharmony_ci {0xef, 0x00002000}, {0x3b, 0x000380ef}, 2888c2ecf20Sopenharmony_ci {0x3b, 0x000302fe}, {0x3b, 0x00028ce6}, 2898c2ecf20Sopenharmony_ci {0x3b, 0x000200bc}, {0x3b, 0x000188a5}, 2908c2ecf20Sopenharmony_ci {0x3b, 0x00010fbc}, {0x3b, 0x00008f71}, 2918c2ecf20Sopenharmony_ci {0x3b, 0x00000900}, {0xef, 0x00000000}, 2928c2ecf20Sopenharmony_ci {0xed, 0x00000001}, {0x40, 0x000380ef}, 2938c2ecf20Sopenharmony_ci {0x40, 0x000302fe}, {0x40, 0x00028ce6}, 2948c2ecf20Sopenharmony_ci {0x40, 0x000200bc}, {0x40, 0x000188a5}, 2958c2ecf20Sopenharmony_ci {0x40, 0x00010fbc}, {0x40, 0x00008f71}, 2968c2ecf20Sopenharmony_ci {0x40, 0x00000900}, {0xed, 0x00000000}, 2978c2ecf20Sopenharmony_ci {0x82, 0x00080000}, {0x83, 0x00008000}, 2988c2ecf20Sopenharmony_ci {0x84, 0x00048d80}, {0x85, 0x00068000}, 2998c2ecf20Sopenharmony_ci {0xa2, 0x00080000}, {0xa3, 0x00008000}, 3008c2ecf20Sopenharmony_ci {0xa4, 0x00048d80}, {0xa5, 0x00068000}, 3018c2ecf20Sopenharmony_ci {0xed, 0x00000002}, {0xef, 0x00000002}, 3028c2ecf20Sopenharmony_ci {0x56, 0x00000032}, {0x76, 0x00000032}, 3038c2ecf20Sopenharmony_ci {0x01, 0x00000780}, 3048c2ecf20Sopenharmony_ci {0xff, 0xffffffff} 3058c2ecf20Sopenharmony_ci}; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_cistatic void rtl8723bu_write_btreg(struct rtl8xxxu_priv *priv, u8 reg, u8 data) 3088c2ecf20Sopenharmony_ci{ 3098c2ecf20Sopenharmony_ci struct h2c_cmd h2c; 3108c2ecf20Sopenharmony_ci int reqnum = 0; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci memset(&h2c, 0, sizeof(struct h2c_cmd)); 3138c2ecf20Sopenharmony_ci h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER; 3148c2ecf20Sopenharmony_ci h2c.bt_mp_oper.operreq = 0 | (reqnum << 4); 3158c2ecf20Sopenharmony_ci h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE; 3168c2ecf20Sopenharmony_ci h2c.bt_mp_oper.data = data; 3178c2ecf20Sopenharmony_ci rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper)); 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci reqnum++; 3208c2ecf20Sopenharmony_ci memset(&h2c, 0, sizeof(struct h2c_cmd)); 3218c2ecf20Sopenharmony_ci h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER; 3228c2ecf20Sopenharmony_ci h2c.bt_mp_oper.operreq = 0 | (reqnum << 4); 3238c2ecf20Sopenharmony_ci h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE; 3248c2ecf20Sopenharmony_ci h2c.bt_mp_oper.addr = reg; 3258c2ecf20Sopenharmony_ci rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper)); 3268c2ecf20Sopenharmony_ci} 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic void rtl8723bu_reset_8051(struct rtl8xxxu_priv *priv) 3298c2ecf20Sopenharmony_ci{ 3308c2ecf20Sopenharmony_ci u8 val8; 3318c2ecf20Sopenharmony_ci u16 sys_func; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL); 3348c2ecf20Sopenharmony_ci val8 &= ~BIT(1); 3358c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RSV_CTRL, val8); 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); 3388c2ecf20Sopenharmony_ci val8 &= ~BIT(0); 3398c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC); 3428c2ecf20Sopenharmony_ci sys_func &= ~SYS_FUNC_CPU_ENABLE; 3438c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL); 3468c2ecf20Sopenharmony_ci val8 &= ~BIT(1); 3478c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RSV_CTRL, val8); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); 3508c2ecf20Sopenharmony_ci val8 |= BIT(0); 3518c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci sys_func |= SYS_FUNC_CPU_ENABLE; 3548c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func); 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_cistatic void 3588c2ecf20Sopenharmony_cirtl8723b_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40) 3598c2ecf20Sopenharmony_ci{ 3608c2ecf20Sopenharmony_ci u32 val32, ofdm, mcs; 3618c2ecf20Sopenharmony_ci u8 cck, ofdmbase, mcsbase; 3628c2ecf20Sopenharmony_ci int group, tx_idx; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci tx_idx = 0; 3658c2ecf20Sopenharmony_ci group = rtl8xxxu_gen2_channel_to_group(channel); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci cck = priv->cck_tx_power_index_B[group]; 3688c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32); 3698c2ecf20Sopenharmony_ci val32 &= 0xffff00ff; 3708c2ecf20Sopenharmony_ci val32 |= (cck << 8); 3718c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11); 3748c2ecf20Sopenharmony_ci val32 &= 0xff; 3758c2ecf20Sopenharmony_ci val32 |= ((cck << 8) | (cck << 16) | (cck << 24)); 3768c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32); 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci ofdmbase = priv->ht40_1s_tx_power_index_B[group]; 3798c2ecf20Sopenharmony_ci ofdmbase += priv->ofdm_tx_power_diff[tx_idx].b; 3808c2ecf20Sopenharmony_ci ofdm = ofdmbase | ofdmbase << 8 | ofdmbase << 16 | ofdmbase << 24; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm); 3838c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci mcsbase = priv->ht40_1s_tx_power_index_B[group]; 3868c2ecf20Sopenharmony_ci if (ht40) 3878c2ecf20Sopenharmony_ci mcsbase += priv->ht40_tx_power_diff[tx_idx++].b; 3888c2ecf20Sopenharmony_ci else 3898c2ecf20Sopenharmony_ci mcsbase += priv->ht20_tx_power_diff[tx_idx++].b; 3908c2ecf20Sopenharmony_ci mcs = mcsbase | mcsbase << 8 | mcsbase << 16 | mcsbase << 24; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs); 3938c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs); 3948c2ecf20Sopenharmony_ci} 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_cistatic int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv) 3978c2ecf20Sopenharmony_ci{ 3988c2ecf20Sopenharmony_ci struct rtl8723bu_efuse *efuse = &priv->efuse_wifi.efuse8723bu; 3998c2ecf20Sopenharmony_ci int i; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci if (efuse->rtl_id != cpu_to_le16(0x8129)) 4028c2ecf20Sopenharmony_ci return -EINVAL; 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci ether_addr_copy(priv->mac_addr, efuse->mac_addr); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base, 4078c2ecf20Sopenharmony_ci sizeof(efuse->tx_power_index_A.cck_base)); 4088c2ecf20Sopenharmony_ci memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base, 4098c2ecf20Sopenharmony_ci sizeof(efuse->tx_power_index_B.cck_base)); 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci memcpy(priv->ht40_1s_tx_power_index_A, 4128c2ecf20Sopenharmony_ci efuse->tx_power_index_A.ht40_base, 4138c2ecf20Sopenharmony_ci sizeof(efuse->tx_power_index_A.ht40_base)); 4148c2ecf20Sopenharmony_ci memcpy(priv->ht40_1s_tx_power_index_B, 4158c2ecf20Sopenharmony_ci efuse->tx_power_index_B.ht40_base, 4168c2ecf20Sopenharmony_ci sizeof(efuse->tx_power_index_B.ht40_base)); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci priv->ofdm_tx_power_diff[0].a = 4198c2ecf20Sopenharmony_ci efuse->tx_power_index_A.ht20_ofdm_1s_diff.a; 4208c2ecf20Sopenharmony_ci priv->ofdm_tx_power_diff[0].b = 4218c2ecf20Sopenharmony_ci efuse->tx_power_index_B.ht20_ofdm_1s_diff.a; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci priv->ht20_tx_power_diff[0].a = 4248c2ecf20Sopenharmony_ci efuse->tx_power_index_A.ht20_ofdm_1s_diff.b; 4258c2ecf20Sopenharmony_ci priv->ht20_tx_power_diff[0].b = 4268c2ecf20Sopenharmony_ci efuse->tx_power_index_B.ht20_ofdm_1s_diff.b; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci priv->ht40_tx_power_diff[0].a = 0; 4298c2ecf20Sopenharmony_ci priv->ht40_tx_power_diff[0].b = 0; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci for (i = 1; i < RTL8723B_TX_COUNT; i++) { 4328c2ecf20Sopenharmony_ci priv->ofdm_tx_power_diff[i].a = 4338c2ecf20Sopenharmony_ci efuse->tx_power_index_A.pwr_diff[i - 1].ofdm; 4348c2ecf20Sopenharmony_ci priv->ofdm_tx_power_diff[i].b = 4358c2ecf20Sopenharmony_ci efuse->tx_power_index_B.pwr_diff[i - 1].ofdm; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci priv->ht20_tx_power_diff[i].a = 4388c2ecf20Sopenharmony_ci efuse->tx_power_index_A.pwr_diff[i - 1].ht20; 4398c2ecf20Sopenharmony_ci priv->ht20_tx_power_diff[i].b = 4408c2ecf20Sopenharmony_ci efuse->tx_power_index_B.pwr_diff[i - 1].ht20; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci priv->ht40_tx_power_diff[i].a = 4438c2ecf20Sopenharmony_ci efuse->tx_power_index_A.pwr_diff[i - 1].ht40; 4448c2ecf20Sopenharmony_ci priv->ht40_tx_power_diff[i].b = 4458c2ecf20Sopenharmony_ci efuse->tx_power_index_B.pwr_diff[i - 1].ht40; 4468c2ecf20Sopenharmony_ci } 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci priv->has_xtalk = 1; 4498c2ecf20Sopenharmony_ci priv->xtalk = priv->efuse_wifi.efuse8723bu.xtal_k & 0x3f; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name); 4528c2ecf20Sopenharmony_ci dev_info(&priv->udev->dev, "Product: %.41s\n", efuse->device_name); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) { 4558c2ecf20Sopenharmony_ci int i; 4568c2ecf20Sopenharmony_ci unsigned char *raw = priv->efuse_wifi.raw; 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci dev_info(&priv->udev->dev, 4598c2ecf20Sopenharmony_ci "%s: dumping efuse (0x%02zx bytes):\n", 4608c2ecf20Sopenharmony_ci __func__, sizeof(struct rtl8723bu_efuse)); 4618c2ecf20Sopenharmony_ci for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8) 4628c2ecf20Sopenharmony_ci dev_info(&priv->udev->dev, "%02x: %8ph\n", i, &raw[i]); 4638c2ecf20Sopenharmony_ci } 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci return 0; 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_cistatic int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci char *fw_name; 4718c2ecf20Sopenharmony_ci int ret; 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci if (priv->enable_bluetooth) 4748c2ecf20Sopenharmony_ci fw_name = "rtlwifi/rtl8723bu_bt.bin"; 4758c2ecf20Sopenharmony_ci else 4768c2ecf20Sopenharmony_ci fw_name = "rtlwifi/rtl8723bu_nic.bin"; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci ret = rtl8xxxu_load_firmware(priv, fw_name); 4798c2ecf20Sopenharmony_ci return ret; 4808c2ecf20Sopenharmony_ci} 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_cistatic void rtl8723bu_init_phy_bb(struct rtl8xxxu_priv *priv) 4838c2ecf20Sopenharmony_ci{ 4848c2ecf20Sopenharmony_ci u8 val8; 4858c2ecf20Sopenharmony_ci u16 val16; 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); 4888c2ecf20Sopenharmony_ci val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB | SYS_FUNC_DIO_RF; 4898c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00); 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci /* 6. 0x1f[7:0] = 0x07 */ 4948c2ecf20Sopenharmony_ci val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB; 4958c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RF_CTRL, val8); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci /* Why? */ 4988c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_SYS_FUNC, 0xe3); 4998c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_AFE_XTAL_CTRL + 1, 0x80); 5008c2ecf20Sopenharmony_ci rtl8xxxu_init_phy_regs(priv, rtl8723b_phy_1t_init_table); 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8723bu_table); 5038c2ecf20Sopenharmony_ci} 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_cistatic int rtl8723bu_init_phy_rf(struct rtl8xxxu_priv *priv) 5068c2ecf20Sopenharmony_ci{ 5078c2ecf20Sopenharmony_ci int ret; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci ret = rtl8xxxu_init_phy_rf(priv, rtl8723bu_radioa_1t_init_table, RF_A); 5108c2ecf20Sopenharmony_ci /* 5118c2ecf20Sopenharmony_ci * PHY LCK 5128c2ecf20Sopenharmony_ci */ 5138c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdfbe0); 5148c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, 0x8c01); 5158c2ecf20Sopenharmony_ci msleep(200); 5168c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdffe0); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci return ret; 5198c2ecf20Sopenharmony_ci} 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_cistatic void rtl8723bu_phy_init_antenna_selection(struct rtl8xxxu_priv *priv) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci u32 val32; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_PAD_CTRL1); 5268c2ecf20Sopenharmony_ci val32 &= ~(BIT(20) | BIT(24)); 5278c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_PAD_CTRL1, val32); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG); 5308c2ecf20Sopenharmony_ci val32 &= ~BIT(4); 5318c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32); 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG); 5348c2ecf20Sopenharmony_ci val32 |= BIT(3); 5358c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32); 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); 5388c2ecf20Sopenharmony_ci val32 |= BIT(24); 5398c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_LEDCFG0, val32); 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); 5428c2ecf20Sopenharmony_ci val32 &= ~BIT(23); 5438c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_LEDCFG0, val32); 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER); 5468c2ecf20Sopenharmony_ci val32 |= (BIT(0) | BIT(1)); 5478c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32); 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_RFE_CTRL_ANTA_SRC); 5508c2ecf20Sopenharmony_ci val32 &= 0xffffff00; 5518c2ecf20Sopenharmony_ci val32 |= 0x77; 5528c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RFE_CTRL_ANTA_SRC, val32); 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_PWR_DATA); 5558c2ecf20Sopenharmony_ci val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN; 5568c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_PWR_DATA, val32); 5578c2ecf20Sopenharmony_ci} 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_cistatic int rtl8723bu_iqk_path_a(struct rtl8xxxu_priv *priv) 5608c2ecf20Sopenharmony_ci{ 5618c2ecf20Sopenharmony_ci u32 reg_eac, reg_e94, reg_e9c, path_sel, val32; 5628c2ecf20Sopenharmony_ci int result = 0; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH); 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci /* 5678c2ecf20Sopenharmony_ci * Leave IQK mode 5688c2ecf20Sopenharmony_ci */ 5698c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 5708c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 5718c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci /* 5748c2ecf20Sopenharmony_ci * Enable path A PA in TX IQK mode 5758c2ecf20Sopenharmony_ci */ 5768c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); 5778c2ecf20Sopenharmony_ci val32 |= 0x80000; 5788c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); 5798c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x20000); 5808c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0003f); 5818c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xc7f87); 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci /* 5848c2ecf20Sopenharmony_ci * Tx IQK setting 5858c2ecf20Sopenharmony_ci */ 5868c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00); 5878c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci /* path-A IQK setting */ 5908c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c); 5918c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c); 5928c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c); 5938c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x821403ea); 5968c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000); 5978c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000); 5988c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci /* LO calibration setting */ 6018c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x00462911); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci /* 6048c2ecf20Sopenharmony_ci * Enter IQK mode 6058c2ecf20Sopenharmony_ci */ 6068c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 6078c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 6088c2ecf20Sopenharmony_ci val32 |= 0x80800000; 6098c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci /* 6128c2ecf20Sopenharmony_ci * The vendor driver indicates the USB module is always using 6138c2ecf20Sopenharmony_ci * S0S1 path 1 for the 8723bu. This may be different for 8192eu 6148c2ecf20Sopenharmony_ci */ 6158c2ecf20Sopenharmony_ci if (priv->rf_paths > 1) 6168c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000); 6178c2ecf20Sopenharmony_ci else 6188c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280); 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci /* 6218c2ecf20Sopenharmony_ci * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu. 6228c2ecf20Sopenharmony_ci * No trace of this in the 8192eu or 8188eu vendor drivers. 6238c2ecf20Sopenharmony_ci */ 6248c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci /* One shot, path A LOK & IQK */ 6278c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); 6288c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci mdelay(1); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci /* Restore Ant Path */ 6338c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel); 6348c2ecf20Sopenharmony_ci#ifdef RTL8723BU_BT 6358c2ecf20Sopenharmony_ci /* GNT_BT = 1 */ 6368c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800); 6378c2ecf20Sopenharmony_ci#endif 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci /* 6408c2ecf20Sopenharmony_ci * Leave IQK mode 6418c2ecf20Sopenharmony_ci */ 6428c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 6438c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 6448c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci /* Check failed */ 6478c2ecf20Sopenharmony_ci reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); 6488c2ecf20Sopenharmony_ci reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A); 6498c2ecf20Sopenharmony_ci reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A); 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci val32 = (reg_e9c >> 16) & 0x3ff; 6528c2ecf20Sopenharmony_ci if (val32 & 0x200) 6538c2ecf20Sopenharmony_ci val32 = 0x400 - val32; 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(28)) && 6568c2ecf20Sopenharmony_ci ((reg_e94 & 0x03ff0000) != 0x01420000) && 6578c2ecf20Sopenharmony_ci ((reg_e9c & 0x03ff0000) != 0x00420000) && 6588c2ecf20Sopenharmony_ci ((reg_e94 & 0x03ff0000) < 0x01100000) && 6598c2ecf20Sopenharmony_ci ((reg_e94 & 0x03ff0000) > 0x00f00000) && 6608c2ecf20Sopenharmony_ci val32 < 0xf) 6618c2ecf20Sopenharmony_ci result |= 0x01; 6628c2ecf20Sopenharmony_ci else /* If TX not OK, ignore RX */ 6638c2ecf20Sopenharmony_ci goto out; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ciout: 6668c2ecf20Sopenharmony_ci return result; 6678c2ecf20Sopenharmony_ci} 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_cistatic int rtl8723bu_rx_iqk_path_a(struct rtl8xxxu_priv *priv) 6708c2ecf20Sopenharmony_ci{ 6718c2ecf20Sopenharmony_ci u32 reg_ea4, reg_eac, reg_e94, reg_e9c, path_sel, val32; 6728c2ecf20Sopenharmony_ci int result = 0; 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci /* 6778c2ecf20Sopenharmony_ci * Leave IQK mode 6788c2ecf20Sopenharmony_ci */ 6798c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 6808c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 6818c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci /* 6848c2ecf20Sopenharmony_ci * Enable path A PA in TX IQK mode 6858c2ecf20Sopenharmony_ci */ 6868c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); 6878c2ecf20Sopenharmony_ci val32 |= 0x80000; 6888c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); 6898c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000); 6908c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); 6918c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci /* 6948c2ecf20Sopenharmony_ci * Tx IQK setting 6958c2ecf20Sopenharmony_ci */ 6968c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00); 6978c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci /* path-A IQK setting */ 7008c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c); 7018c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c); 7028c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c); 7038c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c); 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82160ff0); 7068c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000); 7078c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000); 7088c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci /* LO calibration setting */ 7118c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a911); 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci /* 7148c2ecf20Sopenharmony_ci * Enter IQK mode 7158c2ecf20Sopenharmony_ci */ 7168c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 7178c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 7188c2ecf20Sopenharmony_ci val32 |= 0x80800000; 7198c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci /* 7228c2ecf20Sopenharmony_ci * The vendor driver indicates the USB module is always using 7238c2ecf20Sopenharmony_ci * S0S1 path 1 for the 8723bu. This may be different for 8192eu 7248c2ecf20Sopenharmony_ci */ 7258c2ecf20Sopenharmony_ci if (priv->rf_paths > 1) 7268c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000); 7278c2ecf20Sopenharmony_ci else 7288c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280); 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci /* 7318c2ecf20Sopenharmony_ci * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu. 7328c2ecf20Sopenharmony_ci * No trace of this in the 8192eu or 8188eu vendor drivers. 7338c2ecf20Sopenharmony_ci */ 7348c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800); 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci /* One shot, path A LOK & IQK */ 7378c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); 7388c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci mdelay(1); 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci /* Restore Ant Path */ 7438c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel); 7448c2ecf20Sopenharmony_ci#ifdef RTL8723BU_BT 7458c2ecf20Sopenharmony_ci /* GNT_BT = 1 */ 7468c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800); 7478c2ecf20Sopenharmony_ci#endif 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci /* 7508c2ecf20Sopenharmony_ci * Leave IQK mode 7518c2ecf20Sopenharmony_ci */ 7528c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 7538c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 7548c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci /* Check failed */ 7578c2ecf20Sopenharmony_ci reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); 7588c2ecf20Sopenharmony_ci reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A); 7598c2ecf20Sopenharmony_ci reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A); 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci val32 = (reg_e9c >> 16) & 0x3ff; 7628c2ecf20Sopenharmony_ci if (val32 & 0x200) 7638c2ecf20Sopenharmony_ci val32 = 0x400 - val32; 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(28)) && 7668c2ecf20Sopenharmony_ci ((reg_e94 & 0x03ff0000) != 0x01420000) && 7678c2ecf20Sopenharmony_ci ((reg_e9c & 0x03ff0000) != 0x00420000) && 7688c2ecf20Sopenharmony_ci ((reg_e94 & 0x03ff0000) < 0x01100000) && 7698c2ecf20Sopenharmony_ci ((reg_e94 & 0x03ff0000) > 0x00f00000) && 7708c2ecf20Sopenharmony_ci val32 < 0xf) 7718c2ecf20Sopenharmony_ci result |= 0x01; 7728c2ecf20Sopenharmony_ci else /* If TX not OK, ignore RX */ 7738c2ecf20Sopenharmony_ci goto out; 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci val32 = 0x80007c00 | (reg_e94 &0x3ff0000) | 7768c2ecf20Sopenharmony_ci ((reg_e9c & 0x3ff0000) >> 16); 7778c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK, val32); 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci /* 7808c2ecf20Sopenharmony_ci * Modify RX IQK mode 7818c2ecf20Sopenharmony_ci */ 7828c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 7838c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 7848c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 7858c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); 7868c2ecf20Sopenharmony_ci val32 |= 0x80000; 7878c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); 7888c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000); 7898c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); 7908c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7d77); 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci /* 7938c2ecf20Sopenharmony_ci * PA, PAD setting 7948c2ecf20Sopenharmony_ci */ 7958c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0xf80); 7968c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_55, 0x4021f); 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci /* 7998c2ecf20Sopenharmony_ci * RX IQK setting 8008c2ecf20Sopenharmony_ci */ 8018c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci /* path-A IQK setting */ 8048c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x38008c1c); 8058c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x18008c1c); 8068c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c); 8078c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c); 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82110000); 8108c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x2816001f); 8118c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000); 8128c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000); 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci /* LO calibration setting */ 8158c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a8d1); 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci /* 8188c2ecf20Sopenharmony_ci * Enter IQK mode 8198c2ecf20Sopenharmony_ci */ 8208c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 8218c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 8228c2ecf20Sopenharmony_ci val32 |= 0x80800000; 8238c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci if (priv->rf_paths > 1) 8268c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000); 8278c2ecf20Sopenharmony_ci else 8288c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280); 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci /* 8318c2ecf20Sopenharmony_ci * Disable BT 8328c2ecf20Sopenharmony_ci */ 8338c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800); 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci /* One shot, path A LOK & IQK */ 8368c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); 8378c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci mdelay(1); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci /* Restore Ant Path */ 8428c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel); 8438c2ecf20Sopenharmony_ci#ifdef RTL8723BU_BT 8448c2ecf20Sopenharmony_ci /* GNT_BT = 1 */ 8458c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800); 8468c2ecf20Sopenharmony_ci#endif 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci /* 8498c2ecf20Sopenharmony_ci * Leave IQK mode 8508c2ecf20Sopenharmony_ci */ 8518c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 8528c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 8538c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci /* Check failed */ 8568c2ecf20Sopenharmony_ci reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); 8578c2ecf20Sopenharmony_ci reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2); 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x780); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci val32 = (reg_eac >> 16) & 0x3ff; 8628c2ecf20Sopenharmony_ci if (val32 & 0x200) 8638c2ecf20Sopenharmony_ci val32 = 0x400 - val32; 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(27)) && 8668c2ecf20Sopenharmony_ci ((reg_ea4 & 0x03ff0000) != 0x01320000) && 8678c2ecf20Sopenharmony_ci ((reg_eac & 0x03ff0000) != 0x00360000) && 8688c2ecf20Sopenharmony_ci ((reg_ea4 & 0x03ff0000) < 0x01100000) && 8698c2ecf20Sopenharmony_ci ((reg_ea4 & 0x03ff0000) > 0x00f00000) && 8708c2ecf20Sopenharmony_ci val32 < 0xf) 8718c2ecf20Sopenharmony_ci result |= 0x02; 8728c2ecf20Sopenharmony_ci else /* If TX not OK, ignore RX */ 8738c2ecf20Sopenharmony_ci goto out; 8748c2ecf20Sopenharmony_ciout: 8758c2ecf20Sopenharmony_ci return result; 8768c2ecf20Sopenharmony_ci} 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_cistatic void rtl8723bu_phy_iqcalibrate(struct rtl8xxxu_priv *priv, 8798c2ecf20Sopenharmony_ci int result[][8], int t) 8808c2ecf20Sopenharmony_ci{ 8818c2ecf20Sopenharmony_ci struct device *dev = &priv->udev->dev; 8828c2ecf20Sopenharmony_ci u32 i, val32; 8838c2ecf20Sopenharmony_ci int path_a_ok /*, path_b_ok */; 8848c2ecf20Sopenharmony_ci int retry = 2; 8858c2ecf20Sopenharmony_ci static const u32 adda_regs[RTL8XXXU_ADDA_REGS] = { 8868c2ecf20Sopenharmony_ci REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH, 8878c2ecf20Sopenharmony_ci REG_RX_WAIT_CCA, REG_TX_CCK_RFON, 8888c2ecf20Sopenharmony_ci REG_TX_CCK_BBON, REG_TX_OFDM_RFON, 8898c2ecf20Sopenharmony_ci REG_TX_OFDM_BBON, REG_TX_TO_RX, 8908c2ecf20Sopenharmony_ci REG_TX_TO_TX, REG_RX_CCK, 8918c2ecf20Sopenharmony_ci REG_RX_OFDM, REG_RX_WAIT_RIFS, 8928c2ecf20Sopenharmony_ci REG_RX_TO_RX, REG_STANDBY, 8938c2ecf20Sopenharmony_ci REG_SLEEP, REG_PMPD_ANAEN 8948c2ecf20Sopenharmony_ci }; 8958c2ecf20Sopenharmony_ci static const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = { 8968c2ecf20Sopenharmony_ci REG_TXPAUSE, REG_BEACON_CTRL, 8978c2ecf20Sopenharmony_ci REG_BEACON_CTRL_1, REG_GPIO_MUXCFG 8988c2ecf20Sopenharmony_ci }; 8998c2ecf20Sopenharmony_ci static const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = { 9008c2ecf20Sopenharmony_ci REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR, 9018c2ecf20Sopenharmony_ci REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B, 9028c2ecf20Sopenharmony_ci REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE, 9038c2ecf20Sopenharmony_ci REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE 9048c2ecf20Sopenharmony_ci }; 9058c2ecf20Sopenharmony_ci u8 xa_agc = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1) & 0xff; 9068c2ecf20Sopenharmony_ci u8 xb_agc = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1) & 0xff; 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci /* 9098c2ecf20Sopenharmony_ci * Note: IQ calibration must be performed after loading 9108c2ecf20Sopenharmony_ci * PHY_REG.txt , and radio_a, radio_b.txt 9118c2ecf20Sopenharmony_ci */ 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci if (t == 0) { 9148c2ecf20Sopenharmony_ci /* Save ADDA parameters, turn Path A ADDA on */ 9158c2ecf20Sopenharmony_ci rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup, 9168c2ecf20Sopenharmony_ci RTL8XXXU_ADDA_REGS); 9178c2ecf20Sopenharmony_ci rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup); 9188c2ecf20Sopenharmony_ci rtl8xxxu_save_regs(priv, iqk_bb_regs, 9198c2ecf20Sopenharmony_ci priv->bb_backup, RTL8XXXU_BB_REGS); 9208c2ecf20Sopenharmony_ci } 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci rtl8xxxu_path_adda_on(priv, adda_regs, true); 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci /* MAC settings */ 9258c2ecf20Sopenharmony_ci rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup); 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING); 9288c2ecf20Sopenharmony_ci val32 |= 0x0f000000; 9298c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32); 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600); 9328c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4); 9338c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000); 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_ci /* 9368c2ecf20Sopenharmony_ci * RX IQ calibration setting for 8723B D cut large current issue 9378c2ecf20Sopenharmony_ci * when leaving IPS 9388c2ecf20Sopenharmony_ci */ 9398c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 9408c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 9418c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); 9448c2ecf20Sopenharmony_ci val32 |= 0x80000; 9458c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000); 9488c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); 9498c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7); 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED); 9528c2ecf20Sopenharmony_ci val32 |= 0x20; 9538c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32); 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_43, 0x60fbd); 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci for (i = 0; i < retry; i++) { 9588c2ecf20Sopenharmony_ci path_a_ok = rtl8723bu_iqk_path_a(priv); 9598c2ecf20Sopenharmony_ci if (path_a_ok == 0x01) { 9608c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 9618c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 9628c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, 9658c2ecf20Sopenharmony_ci REG_TX_POWER_BEFORE_IQK_A); 9668c2ecf20Sopenharmony_ci result[t][0] = (val32 >> 16) & 0x3ff; 9678c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, 9688c2ecf20Sopenharmony_ci REG_TX_POWER_AFTER_IQK_A); 9698c2ecf20Sopenharmony_ci result[t][1] = (val32 >> 16) & 0x3ff; 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci break; 9728c2ecf20Sopenharmony_ci } 9738c2ecf20Sopenharmony_ci } 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci if (!path_a_ok) 9768c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: Path A TX IQK failed!\n", __func__); 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci for (i = 0; i < retry; i++) { 9798c2ecf20Sopenharmony_ci path_a_ok = rtl8723bu_rx_iqk_path_a(priv); 9808c2ecf20Sopenharmony_ci if (path_a_ok == 0x03) { 9818c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, 9828c2ecf20Sopenharmony_ci REG_RX_POWER_BEFORE_IQK_A_2); 9838c2ecf20Sopenharmony_ci result[t][2] = (val32 >> 16) & 0x3ff; 9848c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, 9858c2ecf20Sopenharmony_ci REG_RX_POWER_AFTER_IQK_A_2); 9868c2ecf20Sopenharmony_ci result[t][3] = (val32 >> 16) & 0x3ff; 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci break; 9898c2ecf20Sopenharmony_ci } 9908c2ecf20Sopenharmony_ci } 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ci if (!path_a_ok) 9938c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: Path A RX IQK failed!\n", __func__); 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci if (priv->tx_paths > 1) { 9968c2ecf20Sopenharmony_ci#if 1 9978c2ecf20Sopenharmony_ci dev_warn(dev, "%s: Path B not supported\n", __func__); 9988c2ecf20Sopenharmony_ci#else 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci /* 10018c2ecf20Sopenharmony_ci * Path A into standby 10028c2ecf20Sopenharmony_ci */ 10038c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 10048c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 10058c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 10068c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x10000); 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 10098c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 10108c2ecf20Sopenharmony_ci val32 |= 0x80800000; 10118c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci /* Turn Path B ADDA on */ 10148c2ecf20Sopenharmony_ci rtl8xxxu_path_adda_on(priv, adda_regs, false); 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci for (i = 0; i < retry; i++) { 10178c2ecf20Sopenharmony_ci path_b_ok = rtl8xxxu_iqk_path_b(priv); 10188c2ecf20Sopenharmony_ci if (path_b_ok == 0x03) { 10198c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B); 10208c2ecf20Sopenharmony_ci result[t][4] = (val32 >> 16) & 0x3ff; 10218c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B); 10228c2ecf20Sopenharmony_ci result[t][5] = (val32 >> 16) & 0x3ff; 10238c2ecf20Sopenharmony_ci break; 10248c2ecf20Sopenharmony_ci } 10258c2ecf20Sopenharmony_ci } 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci if (!path_b_ok) 10288c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: Path B IQK failed!\n", __func__); 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci for (i = 0; i < retry; i++) { 10318c2ecf20Sopenharmony_ci path_b_ok = rtl8723bu_rx_iqk_path_b(priv); 10328c2ecf20Sopenharmony_ci if (path_a_ok == 0x03) { 10338c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, 10348c2ecf20Sopenharmony_ci REG_RX_POWER_BEFORE_IQK_B_2); 10358c2ecf20Sopenharmony_ci result[t][6] = (val32 >> 16) & 0x3ff; 10368c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, 10378c2ecf20Sopenharmony_ci REG_RX_POWER_AFTER_IQK_B_2); 10388c2ecf20Sopenharmony_ci result[t][7] = (val32 >> 16) & 0x3ff; 10398c2ecf20Sopenharmony_ci break; 10408c2ecf20Sopenharmony_ci } 10418c2ecf20Sopenharmony_ci } 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci if (!path_b_ok) 10448c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: Path B RX IQK failed!\n", __func__); 10458c2ecf20Sopenharmony_ci#endif 10468c2ecf20Sopenharmony_ci } 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci /* Back to BB mode, load original value */ 10498c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 10508c2ecf20Sopenharmony_ci val32 &= 0x000000ff; 10518c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci if (t) { 10548c2ecf20Sopenharmony_ci /* Reload ADDA power saving parameters */ 10558c2ecf20Sopenharmony_ci rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup, 10568c2ecf20Sopenharmony_ci RTL8XXXU_ADDA_REGS); 10578c2ecf20Sopenharmony_ci 10588c2ecf20Sopenharmony_ci /* Reload MAC parameters */ 10598c2ecf20Sopenharmony_ci rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup); 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci /* Reload BB parameters */ 10628c2ecf20Sopenharmony_ci rtl8xxxu_restore_regs(priv, iqk_bb_regs, 10638c2ecf20Sopenharmony_ci priv->bb_backup, RTL8XXXU_BB_REGS); 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci /* Restore RX initial gain */ 10668c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1); 10678c2ecf20Sopenharmony_ci val32 &= 0xffffff00; 10688c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | 0x50); 10698c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | xa_agc); 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci if (priv->tx_paths > 1) { 10728c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1); 10738c2ecf20Sopenharmony_ci val32 &= 0xffffff00; 10748c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1, 10758c2ecf20Sopenharmony_ci val32 | 0x50); 10768c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1, 10778c2ecf20Sopenharmony_ci val32 | xb_agc); 10788c2ecf20Sopenharmony_ci } 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci /* Load 0xe30 IQC default value */ 10818c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00); 10828c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00); 10838c2ecf20Sopenharmony_ci } 10848c2ecf20Sopenharmony_ci} 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_cistatic void rtl8723bu_phy_iq_calibrate(struct rtl8xxxu_priv *priv) 10878c2ecf20Sopenharmony_ci{ 10888c2ecf20Sopenharmony_ci struct device *dev = &priv->udev->dev; 10898c2ecf20Sopenharmony_ci int result[4][8]; /* last is final result */ 10908c2ecf20Sopenharmony_ci int i, candidate; 10918c2ecf20Sopenharmony_ci bool path_a_ok, path_b_ok; 10928c2ecf20Sopenharmony_ci u32 reg_e94, reg_e9c, reg_ea4, reg_eac; 10938c2ecf20Sopenharmony_ci u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc; 10948c2ecf20Sopenharmony_ci u32 val32, bt_control; 10958c2ecf20Sopenharmony_ci s32 reg_tmp = 0; 10968c2ecf20Sopenharmony_ci bool simu; 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci rtl8xxxu_gen2_prepare_calibrate(priv, 1); 10998c2ecf20Sopenharmony_ci 11008c2ecf20Sopenharmony_ci memset(result, 0, sizeof(result)); 11018c2ecf20Sopenharmony_ci candidate = -1; 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_ci path_a_ok = false; 11048c2ecf20Sopenharmony_ci path_b_ok = false; 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_ci bt_control = rtl8xxxu_read32(priv, REG_BT_CONTROL_8723BU); 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci for (i = 0; i < 3; i++) { 11098c2ecf20Sopenharmony_ci rtl8723bu_phy_iqcalibrate(priv, result, i); 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci if (i == 1) { 11128c2ecf20Sopenharmony_ci simu = rtl8xxxu_gen2_simularity_compare(priv, 11138c2ecf20Sopenharmony_ci result, 0, 1); 11148c2ecf20Sopenharmony_ci if (simu) { 11158c2ecf20Sopenharmony_ci candidate = 0; 11168c2ecf20Sopenharmony_ci break; 11178c2ecf20Sopenharmony_ci } 11188c2ecf20Sopenharmony_ci } 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci if (i == 2) { 11218c2ecf20Sopenharmony_ci simu = rtl8xxxu_gen2_simularity_compare(priv, 11228c2ecf20Sopenharmony_ci result, 0, 2); 11238c2ecf20Sopenharmony_ci if (simu) { 11248c2ecf20Sopenharmony_ci candidate = 0; 11258c2ecf20Sopenharmony_ci break; 11268c2ecf20Sopenharmony_ci } 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci simu = rtl8xxxu_gen2_simularity_compare(priv, 11298c2ecf20Sopenharmony_ci result, 1, 2); 11308c2ecf20Sopenharmony_ci if (simu) { 11318c2ecf20Sopenharmony_ci candidate = 1; 11328c2ecf20Sopenharmony_ci } else { 11338c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) 11348c2ecf20Sopenharmony_ci reg_tmp += result[3][i]; 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci if (reg_tmp) 11378c2ecf20Sopenharmony_ci candidate = 3; 11388c2ecf20Sopenharmony_ci else 11398c2ecf20Sopenharmony_ci candidate = -1; 11408c2ecf20Sopenharmony_ci } 11418c2ecf20Sopenharmony_ci } 11428c2ecf20Sopenharmony_ci } 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 11458c2ecf20Sopenharmony_ci reg_e94 = result[i][0]; 11468c2ecf20Sopenharmony_ci reg_e9c = result[i][1]; 11478c2ecf20Sopenharmony_ci reg_ea4 = result[i][2]; 11488c2ecf20Sopenharmony_ci reg_eac = result[i][3]; 11498c2ecf20Sopenharmony_ci reg_eb4 = result[i][4]; 11508c2ecf20Sopenharmony_ci reg_ebc = result[i][5]; 11518c2ecf20Sopenharmony_ci reg_ec4 = result[i][6]; 11528c2ecf20Sopenharmony_ci reg_ecc = result[i][7]; 11538c2ecf20Sopenharmony_ci } 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci if (candidate >= 0) { 11568c2ecf20Sopenharmony_ci reg_e94 = result[candidate][0]; 11578c2ecf20Sopenharmony_ci priv->rege94 = reg_e94; 11588c2ecf20Sopenharmony_ci reg_e9c = result[candidate][1]; 11598c2ecf20Sopenharmony_ci priv->rege9c = reg_e9c; 11608c2ecf20Sopenharmony_ci reg_ea4 = result[candidate][2]; 11618c2ecf20Sopenharmony_ci reg_eac = result[candidate][3]; 11628c2ecf20Sopenharmony_ci reg_eb4 = result[candidate][4]; 11638c2ecf20Sopenharmony_ci priv->regeb4 = reg_eb4; 11648c2ecf20Sopenharmony_ci reg_ebc = result[candidate][5]; 11658c2ecf20Sopenharmony_ci priv->regebc = reg_ebc; 11668c2ecf20Sopenharmony_ci reg_ec4 = result[candidate][6]; 11678c2ecf20Sopenharmony_ci reg_ecc = result[candidate][7]; 11688c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate); 11698c2ecf20Sopenharmony_ci dev_dbg(dev, 11708c2ecf20Sopenharmony_ci "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x ecc=%x\n", 11718c2ecf20Sopenharmony_ci __func__, reg_e94, reg_e9c, 11728c2ecf20Sopenharmony_ci reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc); 11738c2ecf20Sopenharmony_ci path_a_ok = true; 11748c2ecf20Sopenharmony_ci path_b_ok = true; 11758c2ecf20Sopenharmony_ci } else { 11768c2ecf20Sopenharmony_ci reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100; 11778c2ecf20Sopenharmony_ci reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0; 11788c2ecf20Sopenharmony_ci } 11798c2ecf20Sopenharmony_ci 11808c2ecf20Sopenharmony_ci if (reg_e94 && candidate >= 0) 11818c2ecf20Sopenharmony_ci rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result, 11828c2ecf20Sopenharmony_ci candidate, (reg_ea4 == 0)); 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci if (priv->tx_paths > 1 && reg_eb4) 11858c2ecf20Sopenharmony_ci rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result, 11868c2ecf20Sopenharmony_ci candidate, (reg_ec4 == 0)); 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci rtl8xxxu_save_regs(priv, rtl8xxxu_iqk_phy_iq_bb_reg, 11898c2ecf20Sopenharmony_ci priv->bb_recovery_backup, RTL8XXXU_BB_REGS); 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, bt_control); 11928c2ecf20Sopenharmony_ci 11938c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); 11948c2ecf20Sopenharmony_ci val32 |= 0x80000; 11958c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); 11968c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x18000); 11978c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); 11988c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xe6177); 11998c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED); 12008c2ecf20Sopenharmony_ci val32 |= 0x20; 12018c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32); 12028c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, 0x43, 0x300bd); 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci if (priv->rf_paths > 1) 12058c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: 8723BU 2T not supported\n", __func__); 12068c2ecf20Sopenharmony_ci 12078c2ecf20Sopenharmony_ci rtl8xxxu_gen2_prepare_calibrate(priv, 0); 12088c2ecf20Sopenharmony_ci} 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_cistatic int rtl8723bu_active_to_emu(struct rtl8xxxu_priv *priv) 12118c2ecf20Sopenharmony_ci{ 12128c2ecf20Sopenharmony_ci u8 val8; 12138c2ecf20Sopenharmony_ci u16 val16; 12148c2ecf20Sopenharmony_ci u32 val32; 12158c2ecf20Sopenharmony_ci int count, ret = 0; 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_ci /* Turn off RF */ 12188c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RF_CTRL, 0); 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci /* Enable rising edge triggering interrupt */ 12218c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_GPIO_INTM); 12228c2ecf20Sopenharmony_ci val16 &= ~GPIO_INTM_EDGE_TRIG_IRQ; 12238c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_GPIO_INTM, val16); 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci /* Release WLON reset 0x04[16]= 1*/ 12268c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 12278c2ecf20Sopenharmony_ci val32 |= APS_FSMCO_WLON_RESET; 12288c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 12298c2ecf20Sopenharmony_ci 12308c2ecf20Sopenharmony_ci /* 0x0005[1] = 1 turn off MAC by HW state machine*/ 12318c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); 12328c2ecf20Sopenharmony_ci val8 |= BIT(1); 12338c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_ci for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { 12368c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); 12378c2ecf20Sopenharmony_ci if ((val8 & BIT(1)) == 0) 12388c2ecf20Sopenharmony_ci break; 12398c2ecf20Sopenharmony_ci udelay(10); 12408c2ecf20Sopenharmony_ci } 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ci if (!count) { 12438c2ecf20Sopenharmony_ci dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n", 12448c2ecf20Sopenharmony_ci __func__); 12458c2ecf20Sopenharmony_ci ret = -EBUSY; 12468c2ecf20Sopenharmony_ci goto exit; 12478c2ecf20Sopenharmony_ci } 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci /* Enable BT control XTAL setting */ 12508c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_AFE_MISC); 12518c2ecf20Sopenharmony_ci val8 &= ~AFE_MISC_WL_XTAL_CTRL; 12528c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_AFE_MISC, val8); 12538c2ecf20Sopenharmony_ci 12548c2ecf20Sopenharmony_ci /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */ 12558c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); 12568c2ecf20Sopenharmony_ci val8 |= SYS_ISO_ANALOG_IPS; 12578c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); 12588c2ecf20Sopenharmony_ci 12598c2ecf20Sopenharmony_ci /* 0x0020[0] = 0 disable LDOA12 MACRO block*/ 12608c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); 12618c2ecf20Sopenharmony_ci val8 &= ~LDOA15_ENABLE; 12628c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ciexit: 12658c2ecf20Sopenharmony_ci return ret; 12668c2ecf20Sopenharmony_ci} 12678c2ecf20Sopenharmony_ci 12688c2ecf20Sopenharmony_cistatic int rtl8723b_emu_to_active(struct rtl8xxxu_priv *priv) 12698c2ecf20Sopenharmony_ci{ 12708c2ecf20Sopenharmony_ci u8 val8; 12718c2ecf20Sopenharmony_ci u32 val32; 12728c2ecf20Sopenharmony_ci int count, ret = 0; 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_ci /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface */ 12758c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); 12768c2ecf20Sopenharmony_ci val8 |= LDOA15_ENABLE; 12778c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_ci /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/ 12808c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, 0x0067); 12818c2ecf20Sopenharmony_ci val8 &= ~BIT(4); 12828c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0x0067, val8); 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci mdelay(1); 12858c2ecf20Sopenharmony_ci 12868c2ecf20Sopenharmony_ci /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */ 12878c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); 12888c2ecf20Sopenharmony_ci val8 &= ~SYS_ISO_ANALOG_IPS; 12898c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); 12908c2ecf20Sopenharmony_ci 12918c2ecf20Sopenharmony_ci /* Disable SW LPS 0x04[10]= 0 */ 12928c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read8(priv, REG_APS_FSMCO); 12938c2ecf20Sopenharmony_ci val32 &= ~APS_FSMCO_SW_LPS; 12948c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 12958c2ecf20Sopenharmony_ci 12968c2ecf20Sopenharmony_ci /* Wait until 0x04[17] = 1 power ready */ 12978c2ecf20Sopenharmony_ci for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { 12988c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 12998c2ecf20Sopenharmony_ci if (val32 & BIT(17)) 13008c2ecf20Sopenharmony_ci break; 13018c2ecf20Sopenharmony_ci 13028c2ecf20Sopenharmony_ci udelay(10); 13038c2ecf20Sopenharmony_ci } 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci if (!count) { 13068c2ecf20Sopenharmony_ci ret = -EBUSY; 13078c2ecf20Sopenharmony_ci goto exit; 13088c2ecf20Sopenharmony_ci } 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_ci /* We should be able to optimize the following three entries into one */ 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci /* Release WLON reset 0x04[16]= 1*/ 13138c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 13148c2ecf20Sopenharmony_ci val32 |= APS_FSMCO_WLON_RESET; 13158c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci /* Disable HWPDN 0x04[15]= 0*/ 13188c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 13198c2ecf20Sopenharmony_ci val32 &= ~APS_FSMCO_HW_POWERDOWN; 13208c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_ci /* Disable WL suspend*/ 13238c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 13248c2ecf20Sopenharmony_ci val32 &= ~(APS_FSMCO_HW_SUSPEND | APS_FSMCO_PCIE); 13258c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_ci /* Set, then poll until 0 */ 13288c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 13298c2ecf20Sopenharmony_ci val32 |= APS_FSMCO_MAC_ENABLE; 13308c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { 13338c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 13348c2ecf20Sopenharmony_ci if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) { 13358c2ecf20Sopenharmony_ci ret = 0; 13368c2ecf20Sopenharmony_ci break; 13378c2ecf20Sopenharmony_ci } 13388c2ecf20Sopenharmony_ci udelay(10); 13398c2ecf20Sopenharmony_ci } 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_ci if (!count) { 13428c2ecf20Sopenharmony_ci ret = -EBUSY; 13438c2ecf20Sopenharmony_ci goto exit; 13448c2ecf20Sopenharmony_ci } 13458c2ecf20Sopenharmony_ci 13468c2ecf20Sopenharmony_ci /* Enable WL control XTAL setting */ 13478c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_AFE_MISC); 13488c2ecf20Sopenharmony_ci val8 |= AFE_MISC_WL_XTAL_CTRL; 13498c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_AFE_MISC, val8); 13508c2ecf20Sopenharmony_ci 13518c2ecf20Sopenharmony_ci /* Enable falling edge triggering interrupt */ 13528c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 1); 13538c2ecf20Sopenharmony_ci val8 |= BIT(1); 13548c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_GPIO_INTM + 1, val8); 13558c2ecf20Sopenharmony_ci 13568c2ecf20Sopenharmony_ci /* Enable GPIO9 interrupt mode */ 13578c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2 + 1); 13588c2ecf20Sopenharmony_ci val8 |= BIT(1); 13598c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2 + 1, val8); 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_ci /* Enable GPIO9 input mode */ 13628c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2); 13638c2ecf20Sopenharmony_ci val8 &= ~BIT(1); 13648c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2, val8); 13658c2ecf20Sopenharmony_ci 13668c2ecf20Sopenharmony_ci /* Enable HSISR GPIO[C:0] interrupt */ 13678c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_HSIMR); 13688c2ecf20Sopenharmony_ci val8 |= BIT(0); 13698c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_HSIMR, val8); 13708c2ecf20Sopenharmony_ci 13718c2ecf20Sopenharmony_ci /* Enable HSISR GPIO9 interrupt */ 13728c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_HSIMR + 2); 13738c2ecf20Sopenharmony_ci val8 |= BIT(1); 13748c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_HSIMR + 2, val8); 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL); 13778c2ecf20Sopenharmony_ci val8 |= MULTI_WIFI_HW_ROF_EN; 13788c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL, val8); 13798c2ecf20Sopenharmony_ci 13808c2ecf20Sopenharmony_ci /* For GPIO9 internal pull high setting BIT(14) */ 13818c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL + 1); 13828c2ecf20Sopenharmony_ci val8 |= BIT(6); 13838c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL + 1, val8); 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ciexit: 13868c2ecf20Sopenharmony_ci return ret; 13878c2ecf20Sopenharmony_ci} 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_cistatic int rtl8723bu_power_on(struct rtl8xxxu_priv *priv) 13908c2ecf20Sopenharmony_ci{ 13918c2ecf20Sopenharmony_ci u8 val8; 13928c2ecf20Sopenharmony_ci u16 val16; 13938c2ecf20Sopenharmony_ci u32 val32; 13948c2ecf20Sopenharmony_ci int ret; 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci rtl8xxxu_disabled_to_emu(priv); 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci ret = rtl8723b_emu_to_active(priv); 13998c2ecf20Sopenharmony_ci if (ret) 14008c2ecf20Sopenharmony_ci goto exit; 14018c2ecf20Sopenharmony_ci 14028c2ecf20Sopenharmony_ci /* 14038c2ecf20Sopenharmony_ci * Enable MAC DMA/WMAC/SCHEDULE/SEC block 14048c2ecf20Sopenharmony_ci * Set CR bit10 to enable 32k calibration. 14058c2ecf20Sopenharmony_ci */ 14068c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_CR); 14078c2ecf20Sopenharmony_ci val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE | 14088c2ecf20Sopenharmony_ci CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | 14098c2ecf20Sopenharmony_ci CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE | 14108c2ecf20Sopenharmony_ci CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE | 14118c2ecf20Sopenharmony_ci CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE); 14128c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_CR, val16); 14138c2ecf20Sopenharmony_ci 14148c2ecf20Sopenharmony_ci /* 14158c2ecf20Sopenharmony_ci * BT coexist power on settings. This is identical for 1 and 2 14168c2ecf20Sopenharmony_ci * antenna parts. 14178c2ecf20Sopenharmony_ci */ 14188c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_PAD_CTRL1 + 3, 0x20); 14198c2ecf20Sopenharmony_ci 14208c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); 14218c2ecf20Sopenharmony_ci val16 |= SYS_FUNC_BBRSTB | SYS_FUNC_BB_GLB_RSTN; 14228c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_BT_CONTROL_8723BU + 1, 0x18); 14258c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04); 14268c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00); 14278c2ecf20Sopenharmony_ci /* Antenna inverse */ 14288c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0xfe08, 0x01); 14298c2ecf20Sopenharmony_ci 14308c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_PWR_DATA); 14318c2ecf20Sopenharmony_ci val16 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN; 14328c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_PWR_DATA, val16); 14338c2ecf20Sopenharmony_ci 14348c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); 14358c2ecf20Sopenharmony_ci val32 |= LEDCFG0_DPDT_SELECT; 14368c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_LEDCFG0, val32); 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1); 14398c2ecf20Sopenharmony_ci val8 &= ~PAD_CTRL1_SW_DPDT_SEL_DATA; 14408c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8); 14418c2ecf20Sopenharmony_ciexit: 14428c2ecf20Sopenharmony_ci return ret; 14438c2ecf20Sopenharmony_ci} 14448c2ecf20Sopenharmony_ci 14458c2ecf20Sopenharmony_cistatic void rtl8723bu_power_off(struct rtl8xxxu_priv *priv) 14468c2ecf20Sopenharmony_ci{ 14478c2ecf20Sopenharmony_ci u8 val8; 14488c2ecf20Sopenharmony_ci u16 val16; 14498c2ecf20Sopenharmony_ci 14508c2ecf20Sopenharmony_ci rtl8xxxu_flush_fifo(priv); 14518c2ecf20Sopenharmony_ci 14528c2ecf20Sopenharmony_ci /* 14538c2ecf20Sopenharmony_ci * Disable TX report timer 14548c2ecf20Sopenharmony_ci */ 14558c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL); 14568c2ecf20Sopenharmony_ci val8 &= ~TX_REPORT_CTRL_TIMER_ENABLE; 14578c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8); 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_CR, 0x0000); 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci rtl8xxxu_active_to_lps(priv); 14628c2ecf20Sopenharmony_ci 14638c2ecf20Sopenharmony_ci /* Reset Firmware if running in RAM */ 14648c2ecf20Sopenharmony_ci if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL) 14658c2ecf20Sopenharmony_ci rtl8xxxu_firmware_self_reset(priv); 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_ci /* Reset MCU */ 14688c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); 14698c2ecf20Sopenharmony_ci val16 &= ~SYS_FUNC_CPU_ENABLE; 14708c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_ci /* Reset MCU ready status */ 14738c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00); 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_ci rtl8723bu_active_to_emu(priv); 14768c2ecf20Sopenharmony_ci 14778c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); 14788c2ecf20Sopenharmony_ci val8 |= BIT(3); /* APS_FSMCO_HW_SUSPEND */ 14798c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_ci /* 0x48[16] = 1 to enable GPIO9 as EXT wakeup */ 14828c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2); 14838c2ecf20Sopenharmony_ci val8 |= BIT(0); 14848c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8); 14858c2ecf20Sopenharmony_ci} 14868c2ecf20Sopenharmony_ci 14878c2ecf20Sopenharmony_cistatic void rtl8723b_enable_rf(struct rtl8xxxu_priv *priv) 14888c2ecf20Sopenharmony_ci{ 14898c2ecf20Sopenharmony_ci struct h2c_cmd h2c; 14908c2ecf20Sopenharmony_ci u32 val32; 14918c2ecf20Sopenharmony_ci u8 val8; 14928c2ecf20Sopenharmony_ci 14938c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA); 14948c2ecf20Sopenharmony_ci val32 |= (BIT(22) | BIT(23)); 14958c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32); 14968c2ecf20Sopenharmony_ci 14978c2ecf20Sopenharmony_ci /* 14988c2ecf20Sopenharmony_ci * No indication anywhere as to what 0x0790 does. The 2 antenna 14998c2ecf20Sopenharmony_ci * vendor code preserves bits 6-7 here. 15008c2ecf20Sopenharmony_ci */ 15018c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0x0790, 0x05); 15028c2ecf20Sopenharmony_ci /* 15038c2ecf20Sopenharmony_ci * 0x0778 seems to be related to enabling the number of antennas 15048c2ecf20Sopenharmony_ci * In the vendor driver halbtc8723b2ant_InitHwConfig() sets it 15058c2ecf20Sopenharmony_ci * to 0x03, while halbtc8723b1ant_InitHwConfig() sets it to 0x01 15068c2ecf20Sopenharmony_ci */ 15078c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0x0778, 0x01); 15088c2ecf20Sopenharmony_ci 15098c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG); 15108c2ecf20Sopenharmony_ci val8 |= BIT(5); 15118c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8); 15128c2ecf20Sopenharmony_ci 15138c2ecf20Sopenharmony_ci rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_IQADJ_G1, 0x780); 15148c2ecf20Sopenharmony_ci 15158c2ecf20Sopenharmony_ci rtl8723bu_write_btreg(priv, 0x3c, 0x15); /* BT TRx Mask on */ 15168c2ecf20Sopenharmony_ci 15178c2ecf20Sopenharmony_ci /* 15188c2ecf20Sopenharmony_ci * Set BT grant to low 15198c2ecf20Sopenharmony_ci */ 15208c2ecf20Sopenharmony_ci memset(&h2c, 0, sizeof(struct h2c_cmd)); 15218c2ecf20Sopenharmony_ci h2c.bt_grant.cmd = H2C_8723B_BT_GRANT; 15228c2ecf20Sopenharmony_ci h2c.bt_grant.data = 0; 15238c2ecf20Sopenharmony_ci rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.bt_grant)); 15248c2ecf20Sopenharmony_ci 15258c2ecf20Sopenharmony_ci /* 15268c2ecf20Sopenharmony_ci * WLAN action by PTA 15278c2ecf20Sopenharmony_ci */ 15288c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x0c); 15298c2ecf20Sopenharmony_ci 15308c2ecf20Sopenharmony_ci /* 15318c2ecf20Sopenharmony_ci * BT select S0/S1 controlled by WiFi 15328c2ecf20Sopenharmony_ci */ 15338c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, 0x0067); 15348c2ecf20Sopenharmony_ci val8 |= BIT(5); 15358c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0x0067, val8); 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_PWR_DATA); 15388c2ecf20Sopenharmony_ci val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN; 15398c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_PWR_DATA, val32); 15408c2ecf20Sopenharmony_ci 15418c2ecf20Sopenharmony_ci /* 15428c2ecf20Sopenharmony_ci * Bits 6/7 are marked in/out ... but for what? 15438c2ecf20Sopenharmony_ci */ 15448c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0x0974, 0xff); 15458c2ecf20Sopenharmony_ci 15468c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER); 15478c2ecf20Sopenharmony_ci val32 |= (BIT(0) | BIT(1)); 15488c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32); 15498c2ecf20Sopenharmony_ci 15508c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RFE_CTRL_ANTA_SRC, 0x77); 15518c2ecf20Sopenharmony_ci 15528c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); 15538c2ecf20Sopenharmony_ci val32 &= ~BIT(24); 15548c2ecf20Sopenharmony_ci val32 |= BIT(23); 15558c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_LEDCFG0, val32); 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci /* 15588c2ecf20Sopenharmony_ci * Fix external switch Main->S1, Aux->S0 15598c2ecf20Sopenharmony_ci */ 15608c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1); 15618c2ecf20Sopenharmony_ci val8 &= ~BIT(0); 15628c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8); 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ci memset(&h2c, 0, sizeof(struct h2c_cmd)); 15658c2ecf20Sopenharmony_ci h2c.ant_sel_rsv.cmd = H2C_8723B_ANT_SEL_RSV; 15668c2ecf20Sopenharmony_ci h2c.ant_sel_rsv.ant_inverse = 1; 15678c2ecf20Sopenharmony_ci h2c.ant_sel_rsv.int_switch_type = 0; 15688c2ecf20Sopenharmony_ci rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.ant_sel_rsv)); 15698c2ecf20Sopenharmony_ci 15708c2ecf20Sopenharmony_ci /* 15718c2ecf20Sopenharmony_ci * Different settings per different antenna position. 15728c2ecf20Sopenharmony_ci * Antenna Position: | Normal Inverse 15738c2ecf20Sopenharmony_ci * -------------------------------------------------- 15748c2ecf20Sopenharmony_ci * Antenna switch to BT: | 0x280, 0x00 15758c2ecf20Sopenharmony_ci * Antenna switch to WiFi: | 0x0, 0x280 15768c2ecf20Sopenharmony_ci * Antenna switch to PTA: | 0x200, 0x80 15778c2ecf20Sopenharmony_ci */ 15788c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x80); 15798c2ecf20Sopenharmony_ci 15808c2ecf20Sopenharmony_ci /* 15818c2ecf20Sopenharmony_ci * Software control, antenna at WiFi side 15828c2ecf20Sopenharmony_ci */ 15838c2ecf20Sopenharmony_ci rtl8723bu_set_ps_tdma(priv, 0x08, 0x00, 0x00, 0x00, 0x00); 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555); 15868c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x55555555); 15878c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff); 15888c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03); 15898c2ecf20Sopenharmony_ci 15908c2ecf20Sopenharmony_ci memset(&h2c, 0, sizeof(struct h2c_cmd)); 15918c2ecf20Sopenharmony_ci h2c.bt_info.cmd = H2C_8723B_BT_INFO; 15928c2ecf20Sopenharmony_ci h2c.bt_info.data = BIT(0); 15938c2ecf20Sopenharmony_ci rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.bt_info)); 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_ci memset(&h2c, 0, sizeof(struct h2c_cmd)); 15968c2ecf20Sopenharmony_ci h2c.ignore_wlan.cmd = H2C_8723B_BT_IGNORE_WLANACT; 15978c2ecf20Sopenharmony_ci h2c.ignore_wlan.data = 0; 15988c2ecf20Sopenharmony_ci rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.ignore_wlan)); 15998c2ecf20Sopenharmony_ci} 16008c2ecf20Sopenharmony_ci 16018c2ecf20Sopenharmony_cistatic void rtl8723bu_init_aggregation(struct rtl8xxxu_priv *priv) 16028c2ecf20Sopenharmony_ci{ 16038c2ecf20Sopenharmony_ci u32 agg_rx; 16048c2ecf20Sopenharmony_ci u8 agg_ctrl; 16058c2ecf20Sopenharmony_ci 16068c2ecf20Sopenharmony_ci /* 16078c2ecf20Sopenharmony_ci * For now simply disable RX aggregation 16088c2ecf20Sopenharmony_ci */ 16098c2ecf20Sopenharmony_ci agg_ctrl = rtl8xxxu_read8(priv, REG_TRXDMA_CTRL); 16108c2ecf20Sopenharmony_ci agg_ctrl &= ~TRXDMA_CTRL_RXDMA_AGG_EN; 16118c2ecf20Sopenharmony_ci 16128c2ecf20Sopenharmony_ci agg_rx = rtl8xxxu_read32(priv, REG_RXDMA_AGG_PG_TH); 16138c2ecf20Sopenharmony_ci agg_rx &= ~RXDMA_USB_AGG_ENABLE; 16148c2ecf20Sopenharmony_ci agg_rx &= ~0xff0f; 16158c2ecf20Sopenharmony_ci 16168c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_TRXDMA_CTRL, agg_ctrl); 16178c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_RXDMA_AGG_PG_TH, agg_rx); 16188c2ecf20Sopenharmony_ci} 16198c2ecf20Sopenharmony_ci 16208c2ecf20Sopenharmony_cistatic void rtl8723bu_init_statistics(struct rtl8xxxu_priv *priv) 16218c2ecf20Sopenharmony_ci{ 16228c2ecf20Sopenharmony_ci u32 val32; 16238c2ecf20Sopenharmony_ci 16248c2ecf20Sopenharmony_ci /* Time duration for NHM unit: 4us, 0x2710=40ms */ 16258c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_NHM_TIMER_8723B + 2, 0x2710); 16268c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_NHM_TH9_TH10_8723B + 2, 0xffff); 16278c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_NHM_TH3_TO_TH0_8723B, 0xffffff52); 16288c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_NHM_TH7_TO_TH4_8723B, 0xffffffff); 16298c2ecf20Sopenharmony_ci /* TH8 */ 16308c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); 16318c2ecf20Sopenharmony_ci val32 |= 0xff; 16328c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); 16338c2ecf20Sopenharmony_ci /* Enable CCK */ 16348c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_NHM_TH9_TH10_8723B); 16358c2ecf20Sopenharmony_ci val32 |= BIT(8) | BIT(9) | BIT(10); 16368c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_NHM_TH9_TH10_8723B, val32); 16378c2ecf20Sopenharmony_ci /* Max power amongst all RX antennas */ 16388c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_OFDM0_FA_RSTC); 16398c2ecf20Sopenharmony_ci val32 |= BIT(7); 16408c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_OFDM0_FA_RSTC, val32); 16418c2ecf20Sopenharmony_ci} 16428c2ecf20Sopenharmony_ci 16438c2ecf20Sopenharmony_cistruct rtl8xxxu_fileops rtl8723bu_fops = { 16448c2ecf20Sopenharmony_ci .parse_efuse = rtl8723bu_parse_efuse, 16458c2ecf20Sopenharmony_ci .load_firmware = rtl8723bu_load_firmware, 16468c2ecf20Sopenharmony_ci .power_on = rtl8723bu_power_on, 16478c2ecf20Sopenharmony_ci .power_off = rtl8723bu_power_off, 16488c2ecf20Sopenharmony_ci .reset_8051 = rtl8723bu_reset_8051, 16498c2ecf20Sopenharmony_ci .llt_init = rtl8xxxu_auto_llt_table, 16508c2ecf20Sopenharmony_ci .init_phy_bb = rtl8723bu_init_phy_bb, 16518c2ecf20Sopenharmony_ci .init_phy_rf = rtl8723bu_init_phy_rf, 16528c2ecf20Sopenharmony_ci .phy_init_antenna_selection = rtl8723bu_phy_init_antenna_selection, 16538c2ecf20Sopenharmony_ci .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate, 16548c2ecf20Sopenharmony_ci .config_channel = rtl8xxxu_gen2_config_channel, 16558c2ecf20Sopenharmony_ci .parse_rx_desc = rtl8xxxu_parse_rxdesc24, 16568c2ecf20Sopenharmony_ci .init_aggregation = rtl8723bu_init_aggregation, 16578c2ecf20Sopenharmony_ci .init_statistics = rtl8723bu_init_statistics, 16588c2ecf20Sopenharmony_ci .enable_rf = rtl8723b_enable_rf, 16598c2ecf20Sopenharmony_ci .disable_rf = rtl8xxxu_gen2_disable_rf, 16608c2ecf20Sopenharmony_ci .usb_quirks = rtl8xxxu_gen2_usb_quirks, 16618c2ecf20Sopenharmony_ci .set_tx_power = rtl8723b_set_tx_power, 16628c2ecf20Sopenharmony_ci .update_rate_mask = rtl8xxxu_gen2_update_rate_mask, 16638c2ecf20Sopenharmony_ci .report_connect = rtl8xxxu_gen2_report_connect, 16648c2ecf20Sopenharmony_ci .fill_txdesc = rtl8xxxu_fill_txdesc_v2, 16658c2ecf20Sopenharmony_ci .writeN_block_size = 1024, 16668c2ecf20Sopenharmony_ci .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40), 16678c2ecf20Sopenharmony_ci .rx_desc_size = sizeof(struct rtl8xxxu_rxdesc24), 16688c2ecf20Sopenharmony_ci .has_s0s1 = 1, 16698c2ecf20Sopenharmony_ci .has_tx_report = 1, 16708c2ecf20Sopenharmony_ci .gen2_thermal_meter = 1, 16718c2ecf20Sopenharmony_ci .needs_full_init = 1, 16728c2ecf20Sopenharmony_ci .adda_1t_init = 0x01c00014, 16738c2ecf20Sopenharmony_ci .adda_1t_path_on = 0x01c00014, 16748c2ecf20Sopenharmony_ci .adda_2t_path_on_a = 0x01c00014, 16758c2ecf20Sopenharmony_ci .adda_2t_path_on_b = 0x01c00014, 16768c2ecf20Sopenharmony_ci .trxff_boundary = 0x3f7f, 16778c2ecf20Sopenharmony_ci .pbp_rx = PBP_PAGE_SIZE_256, 16788c2ecf20Sopenharmony_ci .pbp_tx = PBP_PAGE_SIZE_256, 16798c2ecf20Sopenharmony_ci .mactable = rtl8723b_mac_init_table, 16808c2ecf20Sopenharmony_ci .total_page_num = TX_TOTAL_PAGE_NUM_8723B, 16818c2ecf20Sopenharmony_ci .page_num_hi = TX_PAGE_NUM_HI_PQ_8723B, 16828c2ecf20Sopenharmony_ci .page_num_lo = TX_PAGE_NUM_LO_PQ_8723B, 16838c2ecf20Sopenharmony_ci .page_num_norm = TX_PAGE_NUM_NORM_PQ_8723B, 16848c2ecf20Sopenharmony_ci}; 1685