18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * RTL8XXXU mac80211 USB driver - 8723a 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_power_base rtl8723a_power_base = { 368c2ecf20Sopenharmony_ci .reg_0e00 = 0x0a0c0c0c, 378c2ecf20Sopenharmony_ci .reg_0e04 = 0x02040608, 388c2ecf20Sopenharmony_ci .reg_0e08 = 0x00000000, 398c2ecf20Sopenharmony_ci .reg_086c = 0x00000000, 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci .reg_0e10 = 0x0a0c0d0e, 428c2ecf20Sopenharmony_ci .reg_0e14 = 0x02040608, 438c2ecf20Sopenharmony_ci .reg_0e18 = 0x0a0c0d0e, 448c2ecf20Sopenharmony_ci .reg_0e1c = 0x02040608, 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci .reg_0830 = 0x0a0c0c0c, 478c2ecf20Sopenharmony_ci .reg_0834 = 0x02040608, 488c2ecf20Sopenharmony_ci .reg_0838 = 0x00000000, 498c2ecf20Sopenharmony_ci .reg_086c_2 = 0x00000000, 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci .reg_083c = 0x0a0c0d0e, 528c2ecf20Sopenharmony_ci .reg_0848 = 0x02040608, 538c2ecf20Sopenharmony_ci .reg_084c = 0x0a0c0d0e, 548c2ecf20Sopenharmony_ci .reg_0868 = 0x02040608, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = { 588c2ecf20Sopenharmony_ci {0x00, 0x00030159}, {0x01, 0x00031284}, 598c2ecf20Sopenharmony_ci {0x02, 0x00098000}, {0x03, 0x00039c63}, 608c2ecf20Sopenharmony_ci {0x04, 0x000210e7}, {0x09, 0x0002044f}, 618c2ecf20Sopenharmony_ci {0x0a, 0x0001a3f1}, {0x0b, 0x00014787}, 628c2ecf20Sopenharmony_ci {0x0c, 0x000896fe}, {0x0d, 0x0000e02c}, 638c2ecf20Sopenharmony_ci {0x0e, 0x00039ce7}, {0x0f, 0x00000451}, 648c2ecf20Sopenharmony_ci {0x19, 0x00000000}, {0x1a, 0x00030355}, 658c2ecf20Sopenharmony_ci {0x1b, 0x00060a00}, {0x1c, 0x000fc378}, 668c2ecf20Sopenharmony_ci {0x1d, 0x000a1250}, {0x1e, 0x0000024f}, 678c2ecf20Sopenharmony_ci {0x1f, 0x00000000}, {0x20, 0x0000b614}, 688c2ecf20Sopenharmony_ci {0x21, 0x0006c000}, {0x22, 0x00000000}, 698c2ecf20Sopenharmony_ci {0x23, 0x00001558}, {0x24, 0x00000060}, 708c2ecf20Sopenharmony_ci {0x25, 0x00000483}, {0x26, 0x0004f000}, 718c2ecf20Sopenharmony_ci {0x27, 0x000ec7d9}, {0x28, 0x00057730}, 728c2ecf20Sopenharmony_ci {0x29, 0x00004783}, {0x2a, 0x00000001}, 738c2ecf20Sopenharmony_ci {0x2b, 0x00021334}, {0x2a, 0x00000000}, 748c2ecf20Sopenharmony_ci {0x2b, 0x00000054}, {0x2a, 0x00000001}, 758c2ecf20Sopenharmony_ci {0x2b, 0x00000808}, {0x2b, 0x00053333}, 768c2ecf20Sopenharmony_ci {0x2c, 0x0000000c}, {0x2a, 0x00000002}, 778c2ecf20Sopenharmony_ci {0x2b, 0x00000808}, {0x2b, 0x0005b333}, 788c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000003}, 798c2ecf20Sopenharmony_ci {0x2b, 0x00000808}, {0x2b, 0x00063333}, 808c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000004}, 818c2ecf20Sopenharmony_ci {0x2b, 0x00000808}, {0x2b, 0x0006b333}, 828c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000005}, 838c2ecf20Sopenharmony_ci {0x2b, 0x00000808}, {0x2b, 0x00073333}, 848c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000006}, 858c2ecf20Sopenharmony_ci {0x2b, 0x00000709}, {0x2b, 0x0005b333}, 868c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000007}, 878c2ecf20Sopenharmony_ci {0x2b, 0x00000709}, {0x2b, 0x00063333}, 888c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000008}, 898c2ecf20Sopenharmony_ci {0x2b, 0x0000060a}, {0x2b, 0x0004b333}, 908c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x00000009}, 918c2ecf20Sopenharmony_ci {0x2b, 0x0000060a}, {0x2b, 0x00053333}, 928c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x0000000a}, 938c2ecf20Sopenharmony_ci {0x2b, 0x0000060a}, {0x2b, 0x0005b333}, 948c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x0000000b}, 958c2ecf20Sopenharmony_ci {0x2b, 0x0000060a}, {0x2b, 0x00063333}, 968c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x0000000c}, 978c2ecf20Sopenharmony_ci {0x2b, 0x0000060a}, {0x2b, 0x0006b333}, 988c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x0000000d}, 998c2ecf20Sopenharmony_ci {0x2b, 0x0000060a}, {0x2b, 0x00073333}, 1008c2ecf20Sopenharmony_ci {0x2c, 0x0000000d}, {0x2a, 0x0000000e}, 1018c2ecf20Sopenharmony_ci {0x2b, 0x0000050b}, {0x2b, 0x00066666}, 1028c2ecf20Sopenharmony_ci {0x2c, 0x0000001a}, {0x2a, 0x000e0000}, 1038c2ecf20Sopenharmony_ci {0x10, 0x0004000f}, {0x11, 0x000e31fc}, 1048c2ecf20Sopenharmony_ci {0x10, 0x0006000f}, {0x11, 0x000ff9f8}, 1058c2ecf20Sopenharmony_ci {0x10, 0x0002000f}, {0x11, 0x000203f9}, 1068c2ecf20Sopenharmony_ci {0x10, 0x0003000f}, {0x11, 0x000ff500}, 1078c2ecf20Sopenharmony_ci {0x10, 0x00000000}, {0x11, 0x00000000}, 1088c2ecf20Sopenharmony_ci {0x10, 0x0008000f}, {0x11, 0x0003f100}, 1098c2ecf20Sopenharmony_ci {0x10, 0x0009000f}, {0x11, 0x00023100}, 1108c2ecf20Sopenharmony_ci {0x12, 0x00032000}, {0x12, 0x00071000}, 1118c2ecf20Sopenharmony_ci {0x12, 0x000b0000}, {0x12, 0x000fc000}, 1128c2ecf20Sopenharmony_ci {0x13, 0x000287b3}, {0x13, 0x000244b7}, 1138c2ecf20Sopenharmony_ci {0x13, 0x000204ab}, {0x13, 0x0001c49f}, 1148c2ecf20Sopenharmony_ci {0x13, 0x00018493}, {0x13, 0x0001429b}, 1158c2ecf20Sopenharmony_ci {0x13, 0x00010299}, {0x13, 0x0000c29c}, 1168c2ecf20Sopenharmony_ci {0x13, 0x000081a0}, {0x13, 0x000040ac}, 1178c2ecf20Sopenharmony_ci {0x13, 0x00000020}, {0x14, 0x0001944c}, 1188c2ecf20Sopenharmony_ci {0x14, 0x00059444}, {0x14, 0x0009944c}, 1198c2ecf20Sopenharmony_ci {0x14, 0x000d9444}, {0x15, 0x0000f474}, 1208c2ecf20Sopenharmony_ci {0x15, 0x0004f477}, {0x15, 0x0008f455}, 1218c2ecf20Sopenharmony_ci {0x15, 0x000cf455}, {0x16, 0x00000339}, 1228c2ecf20Sopenharmony_ci {0x16, 0x00040339}, {0x16, 0x00080339}, 1238c2ecf20Sopenharmony_ci {0x16, 0x000c0366}, {0x00, 0x00010159}, 1248c2ecf20Sopenharmony_ci {0x18, 0x0000f401}, {0xfe, 0x00000000}, 1258c2ecf20Sopenharmony_ci {0xfe, 0x00000000}, {0x1f, 0x00000003}, 1268c2ecf20Sopenharmony_ci {0xfe, 0x00000000}, {0xfe, 0x00000000}, 1278c2ecf20Sopenharmony_ci {0x1e, 0x00000247}, {0x1f, 0x00000000}, 1288c2ecf20Sopenharmony_ci {0x00, 0x00030159}, 1298c2ecf20Sopenharmony_ci {0xff, 0xffffffff} 1308c2ecf20Sopenharmony_ci}; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistatic int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv) 1338c2ecf20Sopenharmony_ci{ 1348c2ecf20Sopenharmony_ci struct rtl8723au_efuse *efuse = &priv->efuse_wifi.efuse8723; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci if (efuse->rtl_id != cpu_to_le16(0x8129)) 1378c2ecf20Sopenharmony_ci return -EINVAL; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci ether_addr_copy(priv->mac_addr, efuse->mac_addr); 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci memcpy(priv->cck_tx_power_index_A, 1428c2ecf20Sopenharmony_ci efuse->cck_tx_power_index_A, 1438c2ecf20Sopenharmony_ci sizeof(efuse->cck_tx_power_index_A)); 1448c2ecf20Sopenharmony_ci memcpy(priv->cck_tx_power_index_B, 1458c2ecf20Sopenharmony_ci efuse->cck_tx_power_index_B, 1468c2ecf20Sopenharmony_ci sizeof(efuse->cck_tx_power_index_B)); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci memcpy(priv->ht40_1s_tx_power_index_A, 1498c2ecf20Sopenharmony_ci efuse->ht40_1s_tx_power_index_A, 1508c2ecf20Sopenharmony_ci sizeof(efuse->ht40_1s_tx_power_index_A)); 1518c2ecf20Sopenharmony_ci memcpy(priv->ht40_1s_tx_power_index_B, 1528c2ecf20Sopenharmony_ci efuse->ht40_1s_tx_power_index_B, 1538c2ecf20Sopenharmony_ci sizeof(efuse->ht40_1s_tx_power_index_B)); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci memcpy(priv->ht20_tx_power_index_diff, 1568c2ecf20Sopenharmony_ci efuse->ht20_tx_power_index_diff, 1578c2ecf20Sopenharmony_ci sizeof(efuse->ht20_tx_power_index_diff)); 1588c2ecf20Sopenharmony_ci memcpy(priv->ofdm_tx_power_index_diff, 1598c2ecf20Sopenharmony_ci efuse->ofdm_tx_power_index_diff, 1608c2ecf20Sopenharmony_ci sizeof(efuse->ofdm_tx_power_index_diff)); 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci memcpy(priv->ht40_max_power_offset, 1638c2ecf20Sopenharmony_ci efuse->ht40_max_power_offset, 1648c2ecf20Sopenharmony_ci sizeof(efuse->ht40_max_power_offset)); 1658c2ecf20Sopenharmony_ci memcpy(priv->ht20_max_power_offset, 1668c2ecf20Sopenharmony_ci efuse->ht20_max_power_offset, 1678c2ecf20Sopenharmony_ci sizeof(efuse->ht20_max_power_offset)); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci if (priv->efuse_wifi.efuse8723.version >= 0x01) { 1708c2ecf20Sopenharmony_ci priv->has_xtalk = 1; 1718c2ecf20Sopenharmony_ci priv->xtalk = priv->efuse_wifi.efuse8723.xtal_k & 0x3f; 1728c2ecf20Sopenharmony_ci } 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci priv->power_base = &rtl8723a_power_base; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci dev_info(&priv->udev->dev, "Vendor: %.7s\n", 1778c2ecf20Sopenharmony_ci efuse->vendor_name); 1788c2ecf20Sopenharmony_ci dev_info(&priv->udev->dev, "Product: %.41s\n", 1798c2ecf20Sopenharmony_ci efuse->device_name); 1808c2ecf20Sopenharmony_ci return 0; 1818c2ecf20Sopenharmony_ci} 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci char *fw_name; 1868c2ecf20Sopenharmony_ci int ret; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci switch (priv->chip_cut) { 1898c2ecf20Sopenharmony_ci case 0: 1908c2ecf20Sopenharmony_ci fw_name = "rtlwifi/rtl8723aufw_A.bin"; 1918c2ecf20Sopenharmony_ci break; 1928c2ecf20Sopenharmony_ci case 1: 1938c2ecf20Sopenharmony_ci if (priv->enable_bluetooth) 1948c2ecf20Sopenharmony_ci fw_name = "rtlwifi/rtl8723aufw_B.bin"; 1958c2ecf20Sopenharmony_ci else 1968c2ecf20Sopenharmony_ci fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin"; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci break; 1998c2ecf20Sopenharmony_ci default: 2008c2ecf20Sopenharmony_ci return -EINVAL; 2018c2ecf20Sopenharmony_ci } 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci ret = rtl8xxxu_load_firmware(priv, fw_name); 2048c2ecf20Sopenharmony_ci return ret; 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cistatic int rtl8723au_init_phy_rf(struct rtl8xxxu_priv *priv) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci int ret; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci ret = rtl8xxxu_init_phy_rf(priv, rtl8723au_radioa_1t_init_table, RF_A); 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci /* Reduce 80M spur */ 2148c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d); 2158c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83); 2168c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82); 2178c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83); 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci return ret; 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic int rtl8723a_emu_to_active(struct rtl8xxxu_priv *priv) 2238c2ecf20Sopenharmony_ci{ 2248c2ecf20Sopenharmony_ci u8 val8; 2258c2ecf20Sopenharmony_ci u32 val32; 2268c2ecf20Sopenharmony_ci int count, ret = 0; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface*/ 2298c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); 2308c2ecf20Sopenharmony_ci val8 |= LDOA15_ENABLE; 2318c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/ 2348c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, 0x0067); 2358c2ecf20Sopenharmony_ci val8 &= ~BIT(4); 2368c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, 0x0067, val8); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci mdelay(1); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */ 2418c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); 2428c2ecf20Sopenharmony_ci val8 &= ~SYS_ISO_ANALOG_IPS; 2438c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci /* disable SW LPS 0x04[10]= 0 */ 2468c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); 2478c2ecf20Sopenharmony_ci val8 &= ~BIT(2); 2488c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci /* wait till 0x04[17] = 1 power ready*/ 2518c2ecf20Sopenharmony_ci for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { 2528c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 2538c2ecf20Sopenharmony_ci if (val32 & BIT(17)) 2548c2ecf20Sopenharmony_ci break; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci udelay(10); 2578c2ecf20Sopenharmony_ci } 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci if (!count) { 2608c2ecf20Sopenharmony_ci ret = -EBUSY; 2618c2ecf20Sopenharmony_ci goto exit; 2628c2ecf20Sopenharmony_ci } 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci /* We should be able to optimize the following three entries into one */ 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci /* release WLON reset 0x04[16]= 1*/ 2678c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2); 2688c2ecf20Sopenharmony_ci val8 |= BIT(0); 2698c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci /* disable HWPDN 0x04[15]= 0*/ 2728c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); 2738c2ecf20Sopenharmony_ci val8 &= ~BIT(7); 2748c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* disable WL suspend*/ 2778c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); 2788c2ecf20Sopenharmony_ci val8 &= ~(BIT(3) | BIT(4)); 2798c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* set, then poll until 0 */ 2828c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 2838c2ecf20Sopenharmony_ci val32 |= APS_FSMCO_MAC_ENABLE; 2848c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { 2878c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); 2888c2ecf20Sopenharmony_ci if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) { 2898c2ecf20Sopenharmony_ci ret = 0; 2908c2ecf20Sopenharmony_ci break; 2918c2ecf20Sopenharmony_ci } 2928c2ecf20Sopenharmony_ci udelay(10); 2938c2ecf20Sopenharmony_ci } 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci if (!count) { 2968c2ecf20Sopenharmony_ci ret = -EBUSY; 2978c2ecf20Sopenharmony_ci goto exit; 2988c2ecf20Sopenharmony_ci } 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci /* 0x4C[23] = 0x4E[7] = 1, switch DPDT_SEL_P output from WL BB */ 3018c2ecf20Sopenharmony_ci /* 3028c2ecf20Sopenharmony_ci * Note: Vendor driver actually clears this bit, despite the 3038c2ecf20Sopenharmony_ci * documentation claims it's being set! 3048c2ecf20Sopenharmony_ci */ 3058c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_LEDCFG2); 3068c2ecf20Sopenharmony_ci val8 |= LEDCFG2_DPDT_SELECT; 3078c2ecf20Sopenharmony_ci val8 &= ~LEDCFG2_DPDT_SELECT; 3088c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_LEDCFG2, val8); 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ciexit: 3118c2ecf20Sopenharmony_ci return ret; 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic int rtl8723au_power_on(struct rtl8xxxu_priv *priv) 3158c2ecf20Sopenharmony_ci{ 3168c2ecf20Sopenharmony_ci u8 val8; 3178c2ecf20Sopenharmony_ci u16 val16; 3188c2ecf20Sopenharmony_ci u32 val32; 3198c2ecf20Sopenharmony_ci int ret; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci /* 3228c2ecf20Sopenharmony_ci * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register 3238c2ecf20Sopenharmony_ci */ 3248c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0); 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci rtl8xxxu_disabled_to_emu(priv); 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci ret = rtl8723a_emu_to_active(priv); 3298c2ecf20Sopenharmony_ci if (ret) 3308c2ecf20Sopenharmony_ci goto exit; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci /* 3338c2ecf20Sopenharmony_ci * 0x0004[19] = 1, reset 8051 3348c2ecf20Sopenharmony_ci */ 3358c2ecf20Sopenharmony_ci val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2); 3368c2ecf20Sopenharmony_ci val8 |= BIT(3); 3378c2ecf20Sopenharmony_ci rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8); 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci /* 3408c2ecf20Sopenharmony_ci * Enable MAC DMA/WMAC/SCHEDULE/SEC block 3418c2ecf20Sopenharmony_ci * Set CR bit10 to enable 32k calibration. 3428c2ecf20Sopenharmony_ci */ 3438c2ecf20Sopenharmony_ci val16 = rtl8xxxu_read16(priv, REG_CR); 3448c2ecf20Sopenharmony_ci val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE | 3458c2ecf20Sopenharmony_ci CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | 3468c2ecf20Sopenharmony_ci CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE | 3478c2ecf20Sopenharmony_ci CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE | 3488c2ecf20Sopenharmony_ci CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE); 3498c2ecf20Sopenharmony_ci rtl8xxxu_write16(priv, REG_CR, val16); 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci /* For EFuse PG */ 3528c2ecf20Sopenharmony_ci val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL); 3538c2ecf20Sopenharmony_ci val32 &= ~(BIT(28) | BIT(29) | BIT(30)); 3548c2ecf20Sopenharmony_ci val32 |= (0x06 << 28); 3558c2ecf20Sopenharmony_ci rtl8xxxu_write32(priv, REG_EFUSE_CTRL, val32); 3568c2ecf20Sopenharmony_ciexit: 3578c2ecf20Sopenharmony_ci return ret; 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_cistruct rtl8xxxu_fileops rtl8723au_fops = { 3618c2ecf20Sopenharmony_ci .parse_efuse = rtl8723au_parse_efuse, 3628c2ecf20Sopenharmony_ci .load_firmware = rtl8723au_load_firmware, 3638c2ecf20Sopenharmony_ci .power_on = rtl8723au_power_on, 3648c2ecf20Sopenharmony_ci .power_off = rtl8xxxu_power_off, 3658c2ecf20Sopenharmony_ci .reset_8051 = rtl8xxxu_reset_8051, 3668c2ecf20Sopenharmony_ci .llt_init = rtl8xxxu_init_llt_table, 3678c2ecf20Sopenharmony_ci .init_phy_bb = rtl8xxxu_gen1_init_phy_bb, 3688c2ecf20Sopenharmony_ci .init_phy_rf = rtl8723au_init_phy_rf, 3698c2ecf20Sopenharmony_ci .phy_iq_calibrate = rtl8xxxu_gen1_phy_iq_calibrate, 3708c2ecf20Sopenharmony_ci .config_channel = rtl8xxxu_gen1_config_channel, 3718c2ecf20Sopenharmony_ci .parse_rx_desc = rtl8xxxu_parse_rxdesc16, 3728c2ecf20Sopenharmony_ci .init_aggregation = rtl8xxxu_gen1_init_aggregation, 3738c2ecf20Sopenharmony_ci .enable_rf = rtl8xxxu_gen1_enable_rf, 3748c2ecf20Sopenharmony_ci .disable_rf = rtl8xxxu_gen1_disable_rf, 3758c2ecf20Sopenharmony_ci .usb_quirks = rtl8xxxu_gen1_usb_quirks, 3768c2ecf20Sopenharmony_ci .set_tx_power = rtl8xxxu_gen1_set_tx_power, 3778c2ecf20Sopenharmony_ci .update_rate_mask = rtl8xxxu_update_rate_mask, 3788c2ecf20Sopenharmony_ci .report_connect = rtl8xxxu_gen1_report_connect, 3798c2ecf20Sopenharmony_ci .fill_txdesc = rtl8xxxu_fill_txdesc_v1, 3808c2ecf20Sopenharmony_ci .writeN_block_size = 1024, 3818c2ecf20Sopenharmony_ci .rx_agg_buf_size = 16000, 3828c2ecf20Sopenharmony_ci .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32), 3838c2ecf20Sopenharmony_ci .rx_desc_size = sizeof(struct rtl8xxxu_rxdesc16), 3848c2ecf20Sopenharmony_ci .adda_1t_init = 0x0b1b25a0, 3858c2ecf20Sopenharmony_ci .adda_1t_path_on = 0x0bdb25a0, 3868c2ecf20Sopenharmony_ci .adda_2t_path_on_a = 0x04db25a4, 3878c2ecf20Sopenharmony_ci .adda_2t_path_on_b = 0x0b1b25a4, 3888c2ecf20Sopenharmony_ci .trxff_boundary = 0x27ff, 3898c2ecf20Sopenharmony_ci .pbp_rx = PBP_PAGE_SIZE_128, 3908c2ecf20Sopenharmony_ci .pbp_tx = PBP_PAGE_SIZE_128, 3918c2ecf20Sopenharmony_ci .mactable = rtl8xxxu_gen1_mac_init_table, 3928c2ecf20Sopenharmony_ci .total_page_num = TX_TOTAL_PAGE_NUM, 3938c2ecf20Sopenharmony_ci .page_num_hi = TX_PAGE_NUM_HI_PQ, 3948c2ecf20Sopenharmony_ci .page_num_lo = TX_PAGE_NUM_LO_PQ, 3958c2ecf20Sopenharmony_ci .page_num_norm = TX_PAGE_NUM_NORM_PQ, 3968c2ecf20Sopenharmony_ci}; 397