Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1 | /* |
| 2 | * RTL8XXXU mac80211 USB driver |
| 3 | * |
| 4 | * Copyright (c) 2014 - 2015 Jes Sorensen <Jes.Sorensen@redhat.com> |
| 5 | * |
| 6 | * Portions, notably calibration code: |
| 7 | * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. |
| 8 | * |
| 9 | * This driver was written as a replacement for the vendor provided |
| 10 | * rtl8723au driver. As the Realtek 8xxx chips are very similar in |
| 11 | * their programming interface, I have started adding support for |
| 12 | * additional 8xxx chips like the 8192cu, 8188cus, etc. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify it |
| 15 | * under the terms of version 2 of the GNU General Public License as |
| 16 | * published by the Free Software Foundation. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 19 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 21 | * more details. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/list.h> |
| 32 | #include <linux/usb.h> |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/ethtool.h> |
| 36 | #include <linux/wireless.h> |
| 37 | #include <linux/firmware.h> |
| 38 | #include <linux/moduleparam.h> |
| 39 | #include <net/mac80211.h> |
| 40 | #include "rtl8xxxu.h" |
| 41 | #include "rtl8xxxu_regs.h" |
| 42 | |
| 43 | #define DRIVER_NAME "rtl8xxxu" |
| 44 | |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 45 | static int rtl8xxxu_debug = RTL8XXXU_DEBUG_EFUSE; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 46 | static bool rtl8xxxu_ht40_2g; |
| 47 | |
| 48 | MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@redhat.com>"); |
| 49 | MODULE_DESCRIPTION("RTL8XXXu USB mac80211 Wireless LAN Driver"); |
| 50 | MODULE_LICENSE("GPL"); |
| 51 | MODULE_FIRMWARE("rtlwifi/rtl8723aufw_A.bin"); |
| 52 | MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B.bin"); |
| 53 | MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B_NoBT.bin"); |
| 54 | MODULE_FIRMWARE("rtlwifi/rtl8192cufw_A.bin"); |
| 55 | MODULE_FIRMWARE("rtlwifi/rtl8192cufw_B.bin"); |
| 56 | MODULE_FIRMWARE("rtlwifi/rtl8192cufw_TMSC.bin"); |
Jes Sorensen | b001e08 | 2016-02-29 17:04:02 -0500 | [diff] [blame] | 57 | MODULE_FIRMWARE("rtlwifi/rtl8192eu_nic.bin"); |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 58 | MODULE_FIRMWARE("rtlwifi/rtl8723bu_nic.bin"); |
| 59 | MODULE_FIRMWARE("rtlwifi/rtl8723bu_bt.bin"); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 60 | |
| 61 | module_param_named(debug, rtl8xxxu_debug, int, 0600); |
| 62 | MODULE_PARM_DESC(debug, "Set debug mask"); |
| 63 | module_param_named(ht40_2g, rtl8xxxu_ht40_2g, bool, 0600); |
| 64 | MODULE_PARM_DESC(ht40_2g, "Enable HT40 support on the 2.4GHz band"); |
| 65 | |
| 66 | #define USB_VENDOR_ID_REALTEK 0x0bda |
| 67 | /* Minimum IEEE80211_MAX_FRAME_LEN */ |
| 68 | #define RTL_RX_BUFFER_SIZE IEEE80211_MAX_FRAME_LEN |
| 69 | #define RTL8XXXU_RX_URBS 32 |
| 70 | #define RTL8XXXU_RX_URB_PENDING_WATER 8 |
| 71 | #define RTL8XXXU_TX_URBS 64 |
| 72 | #define RTL8XXXU_TX_URB_LOW_WATER 25 |
| 73 | #define RTL8XXXU_TX_URB_HIGH_WATER 32 |
| 74 | |
| 75 | static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv, |
| 76 | struct rtl8xxxu_rx_urb *rx_urb); |
| 77 | |
| 78 | static struct ieee80211_rate rtl8xxxu_rates[] = { |
| 79 | { .bitrate = 10, .hw_value = DESC_RATE_1M, .flags = 0 }, |
| 80 | { .bitrate = 20, .hw_value = DESC_RATE_2M, .flags = 0 }, |
| 81 | { .bitrate = 55, .hw_value = DESC_RATE_5_5M, .flags = 0 }, |
| 82 | { .bitrate = 110, .hw_value = DESC_RATE_11M, .flags = 0 }, |
| 83 | { .bitrate = 60, .hw_value = DESC_RATE_6M, .flags = 0 }, |
| 84 | { .bitrate = 90, .hw_value = DESC_RATE_9M, .flags = 0 }, |
| 85 | { .bitrate = 120, .hw_value = DESC_RATE_12M, .flags = 0 }, |
| 86 | { .bitrate = 180, .hw_value = DESC_RATE_18M, .flags = 0 }, |
| 87 | { .bitrate = 240, .hw_value = DESC_RATE_24M, .flags = 0 }, |
| 88 | { .bitrate = 360, .hw_value = DESC_RATE_36M, .flags = 0 }, |
| 89 | { .bitrate = 480, .hw_value = DESC_RATE_48M, .flags = 0 }, |
| 90 | { .bitrate = 540, .hw_value = DESC_RATE_54M, .flags = 0 }, |
| 91 | }; |
| 92 | |
| 93 | static struct ieee80211_channel rtl8xxxu_channels_2g[] = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 94 | { .band = NL80211_BAND_2GHZ, .center_freq = 2412, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 95 | .hw_value = 1, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 96 | { .band = NL80211_BAND_2GHZ, .center_freq = 2417, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 97 | .hw_value = 2, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 98 | { .band = NL80211_BAND_2GHZ, .center_freq = 2422, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 99 | .hw_value = 3, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 100 | { .band = NL80211_BAND_2GHZ, .center_freq = 2427, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 101 | .hw_value = 4, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 102 | { .band = NL80211_BAND_2GHZ, .center_freq = 2432, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 103 | .hw_value = 5, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 104 | { .band = NL80211_BAND_2GHZ, .center_freq = 2437, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 105 | .hw_value = 6, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 106 | { .band = NL80211_BAND_2GHZ, .center_freq = 2442, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 107 | .hw_value = 7, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 108 | { .band = NL80211_BAND_2GHZ, .center_freq = 2447, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 109 | .hw_value = 8, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 110 | { .band = NL80211_BAND_2GHZ, .center_freq = 2452, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 111 | .hw_value = 9, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 112 | { .band = NL80211_BAND_2GHZ, .center_freq = 2457, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 113 | .hw_value = 10, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 114 | { .band = NL80211_BAND_2GHZ, .center_freq = 2462, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 115 | .hw_value = 11, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 116 | { .band = NL80211_BAND_2GHZ, .center_freq = 2467, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 117 | .hw_value = 12, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 118 | { .band = NL80211_BAND_2GHZ, .center_freq = 2472, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 119 | .hw_value = 13, .max_power = 30 }, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 120 | { .band = NL80211_BAND_2GHZ, .center_freq = 2484, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 121 | .hw_value = 14, .max_power = 30 } |
| 122 | }; |
| 123 | |
| 124 | static struct ieee80211_supported_band rtl8xxxu_supported_band = { |
| 125 | .channels = rtl8xxxu_channels_2g, |
| 126 | .n_channels = ARRAY_SIZE(rtl8xxxu_channels_2g), |
| 127 | .bitrates = rtl8xxxu_rates, |
| 128 | .n_bitrates = ARRAY_SIZE(rtl8xxxu_rates), |
| 129 | }; |
| 130 | |
| 131 | static struct rtl8xxxu_reg8val rtl8723a_mac_init_table[] = { |
| 132 | {0x420, 0x80}, {0x423, 0x00}, {0x430, 0x00}, {0x431, 0x00}, |
| 133 | {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05}, |
| 134 | {0x436, 0x06}, {0x437, 0x07}, {0x438, 0x00}, {0x439, 0x00}, |
| 135 | {0x43a, 0x00}, {0x43b, 0x01}, {0x43c, 0x04}, {0x43d, 0x05}, |
| 136 | {0x43e, 0x06}, {0x43f, 0x07}, {0x440, 0x5d}, {0x441, 0x01}, |
| 137 | {0x442, 0x00}, {0x444, 0x15}, {0x445, 0xf0}, {0x446, 0x0f}, |
| 138 | {0x447, 0x00}, {0x458, 0x41}, {0x459, 0xa8}, {0x45a, 0x72}, |
| 139 | {0x45b, 0xb9}, {0x460, 0x66}, {0x461, 0x66}, {0x462, 0x08}, |
| 140 | {0x463, 0x03}, {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff}, |
| 141 | {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2}, |
| 142 | {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3}, |
| 143 | {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4}, |
| 144 | {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4}, |
| 145 | {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a}, |
| 146 | {0x515, 0x10}, {0x516, 0x0a}, {0x517, 0x10}, {0x51a, 0x16}, |
| 147 | {0x524, 0x0f}, {0x525, 0x4f}, {0x546, 0x40}, {0x547, 0x00}, |
| 148 | {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55a, 0x02}, |
| 149 | {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a}, |
| 150 | {0x652, 0x20}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e}, |
| 151 | {0x63f, 0x0e}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43}, |
| 152 | {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43}, |
| 153 | {0x70a, 0x65}, {0x70b, 0x87}, {0xffff, 0xff}, |
| 154 | }; |
| 155 | |
Jes Sorensen | b7dd8ff | 2016-02-29 17:04:17 -0500 | [diff] [blame] | 156 | static struct rtl8xxxu_reg8val rtl8723b_mac_init_table[] = { |
| 157 | {0x02f, 0x30}, {0x035, 0x00}, {0x039, 0x08}, {0x04e, 0xe0}, |
| 158 | {0x064, 0x00}, {0x067, 0x20}, {0x428, 0x0a}, {0x429, 0x10}, |
| 159 | {0x430, 0x00}, {0x431, 0x00}, |
| 160 | {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05}, |
| 161 | {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05}, |
| 162 | {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01}, |
| 163 | {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00}, |
| 164 | {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f}, |
| 165 | {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00}, |
| 166 | {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f}, |
| 167 | {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66}, |
| 168 | {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff}, |
| 169 | {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2}, |
| 170 | {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3}, |
| 171 | {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4}, |
| 172 | {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4}, |
| 173 | {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a}, |
| 174 | {0x516, 0x0a}, {0x525, 0x4f}, |
| 175 | {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50}, |
| 176 | {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a}, |
| 177 | {0x620, 0xff}, {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff}, |
| 178 | {0x624, 0xff}, {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff}, |
| 179 | {0x638, 0x50}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e}, |
| 180 | {0x63f, 0x0e}, {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00}, |
| 181 | {0x652, 0xc8}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43}, |
| 182 | {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43}, |
| 183 | {0x70a, 0x65}, {0x70b, 0x87}, {0x765, 0x18}, {0x76e, 0x04}, |
| 184 | {0xffff, 0xff}, |
| 185 | }; |
| 186 | |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 187 | static struct rtl8xxxu_reg8val rtl8192e_mac_init_table[] = { |
| 188 | {0x011, 0xeb}, {0x012, 0x07}, {0x014, 0x75}, {0x303, 0xa7}, |
| 189 | {0x428, 0x0a}, {0x429, 0x10}, {0x430, 0x00}, {0x431, 0x00}, |
| 190 | {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05}, |
| 191 | {0x436, 0x07}, {0x437, 0x08}, {0x43c, 0x04}, {0x43d, 0x05}, |
| 192 | {0x43e, 0x07}, {0x43f, 0x08}, {0x440, 0x5d}, {0x441, 0x01}, |
| 193 | {0x442, 0x00}, {0x444, 0x10}, {0x445, 0x00}, {0x446, 0x00}, |
| 194 | {0x447, 0x00}, {0x448, 0x00}, {0x449, 0xf0}, {0x44a, 0x0f}, |
| 195 | {0x44b, 0x3e}, {0x44c, 0x10}, {0x44d, 0x00}, {0x44e, 0x00}, |
| 196 | {0x44f, 0x00}, {0x450, 0x00}, {0x451, 0xf0}, {0x452, 0x0f}, |
| 197 | {0x453, 0x00}, {0x456, 0x5e}, {0x460, 0x66}, {0x461, 0x66}, |
| 198 | {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff}, {0x4cd, 0xff}, |
| 199 | {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2}, {0x502, 0x2f}, |
| 200 | {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3}, {0x506, 0x5e}, |
| 201 | {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4}, {0x50a, 0x5e}, |
| 202 | {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4}, {0x50e, 0x00}, |
| 203 | {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a}, {0x516, 0x0a}, |
| 204 | {0x525, 0x4f}, {0x540, 0x12}, {0x541, 0x64}, {0x550, 0x10}, |
| 205 | {0x551, 0x10}, {0x559, 0x02}, {0x55c, 0x50}, {0x55d, 0xff}, |
| 206 | {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a}, {0x620, 0xff}, |
| 207 | {0x621, 0xff}, {0x622, 0xff}, {0x623, 0xff}, {0x624, 0xff}, |
| 208 | {0x625, 0xff}, {0x626, 0xff}, {0x627, 0xff}, {0x638, 0x50}, |
| 209 | {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e}, {0x63f, 0x0e}, |
| 210 | {0x640, 0x40}, {0x642, 0x40}, {0x643, 0x00}, {0x652, 0xc8}, |
| 211 | {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43}, {0x702, 0x65}, |
| 212 | {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43}, {0x70a, 0x65}, |
| 213 | {0x70b, 0x87}, |
| 214 | {0xffff, 0xff}, |
| 215 | }; |
| 216 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 217 | static struct rtl8xxxu_reg32val rtl8723a_phy_1t_init_table[] = { |
| 218 | {0x800, 0x80040000}, {0x804, 0x00000003}, |
| 219 | {0x808, 0x0000fc00}, {0x80c, 0x0000000a}, |
| 220 | {0x810, 0x10001331}, {0x814, 0x020c3d10}, |
| 221 | {0x818, 0x02200385}, {0x81c, 0x00000000}, |
| 222 | {0x820, 0x01000100}, {0x824, 0x00390004}, |
| 223 | {0x828, 0x00000000}, {0x82c, 0x00000000}, |
| 224 | {0x830, 0x00000000}, {0x834, 0x00000000}, |
| 225 | {0x838, 0x00000000}, {0x83c, 0x00000000}, |
| 226 | {0x840, 0x00010000}, {0x844, 0x00000000}, |
| 227 | {0x848, 0x00000000}, {0x84c, 0x00000000}, |
| 228 | {0x850, 0x00000000}, {0x854, 0x00000000}, |
| 229 | {0x858, 0x569a569a}, {0x85c, 0x001b25a4}, |
| 230 | {0x860, 0x66f60110}, {0x864, 0x061f0130}, |
| 231 | {0x868, 0x00000000}, {0x86c, 0x32323200}, |
| 232 | {0x870, 0x07000760}, {0x874, 0x22004000}, |
| 233 | {0x878, 0x00000808}, {0x87c, 0x00000000}, |
| 234 | {0x880, 0xc0083070}, {0x884, 0x000004d5}, |
| 235 | {0x888, 0x00000000}, {0x88c, 0xccc000c0}, |
| 236 | {0x890, 0x00000800}, {0x894, 0xfffffffe}, |
| 237 | {0x898, 0x40302010}, {0x89c, 0x00706050}, |
| 238 | {0x900, 0x00000000}, {0x904, 0x00000023}, |
| 239 | {0x908, 0x00000000}, {0x90c, 0x81121111}, |
| 240 | {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c}, |
| 241 | {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f}, |
| 242 | {0xa10, 0x9500bb78}, {0xa14, 0x11144028}, |
| 243 | {0xa18, 0x00881117}, {0xa1c, 0x89140f00}, |
| 244 | {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317}, |
| 245 | {0xa28, 0x00000204}, {0xa2c, 0x00d30000}, |
| 246 | {0xa70, 0x101fbf00}, {0xa74, 0x00000007}, |
| 247 | {0xa78, 0x00000900}, |
| 248 | {0xc00, 0x48071d40}, {0xc04, 0x03a05611}, |
| 249 | {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c}, |
| 250 | {0xc10, 0x08800000}, {0xc14, 0x40000100}, |
| 251 | {0xc18, 0x08800000}, {0xc1c, 0x40000100}, |
| 252 | {0xc20, 0x00000000}, {0xc24, 0x00000000}, |
| 253 | {0xc28, 0x00000000}, {0xc2c, 0x00000000}, |
| 254 | {0xc30, 0x69e9ac44}, {0xc34, 0x469652af}, |
| 255 | {0xc38, 0x49795994}, {0xc3c, 0x0a97971c}, |
| 256 | {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7}, |
| 257 | {0xc48, 0xec020107}, {0xc4c, 0x007f037f}, |
| 258 | {0xc50, 0x69543420}, {0xc54, 0x43bc0094}, |
| 259 | {0xc58, 0x69543420}, {0xc5c, 0x433c0094}, |
| 260 | {0xc60, 0x00000000}, {0xc64, 0x7112848b}, |
| 261 | {0xc68, 0x47c00bff}, {0xc6c, 0x00000036}, |
| 262 | {0xc70, 0x2c7f000d}, {0xc74, 0x018610db}, |
| 263 | {0xc78, 0x0000001f}, {0xc7c, 0x00b91612}, |
| 264 | {0xc80, 0x40000100}, {0xc84, 0x20f60000}, |
| 265 | {0xc88, 0x40000100}, {0xc8c, 0x20200000}, |
| 266 | {0xc90, 0x00121820}, {0xc94, 0x00000000}, |
| 267 | {0xc98, 0x00121820}, {0xc9c, 0x00007f7f}, |
| 268 | {0xca0, 0x00000000}, {0xca4, 0x00000080}, |
| 269 | {0xca8, 0x00000000}, {0xcac, 0x00000000}, |
| 270 | {0xcb0, 0x00000000}, {0xcb4, 0x00000000}, |
| 271 | {0xcb8, 0x00000000}, {0xcbc, 0x28000000}, |
| 272 | {0xcc0, 0x00000000}, {0xcc4, 0x00000000}, |
| 273 | {0xcc8, 0x00000000}, {0xccc, 0x00000000}, |
| 274 | {0xcd0, 0x00000000}, {0xcd4, 0x00000000}, |
| 275 | {0xcd8, 0x64b22427}, {0xcdc, 0x00766932}, |
| 276 | {0xce0, 0x00222222}, {0xce4, 0x00000000}, |
| 277 | {0xce8, 0x37644302}, {0xcec, 0x2f97d40c}, |
| 278 | {0xd00, 0x00080740}, {0xd04, 0x00020401}, |
| 279 | {0xd08, 0x0000907f}, {0xd0c, 0x20010201}, |
| 280 | {0xd10, 0xa0633333}, {0xd14, 0x3333bc43}, |
| 281 | {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975}, |
| 282 | {0xd30, 0x00000000}, {0xd34, 0x80608000}, |
| 283 | {0xd38, 0x00000000}, {0xd3c, 0x00027293}, |
| 284 | {0xd40, 0x00000000}, {0xd44, 0x00000000}, |
| 285 | {0xd48, 0x00000000}, {0xd4c, 0x00000000}, |
| 286 | {0xd50, 0x6437140a}, {0xd54, 0x00000000}, |
| 287 | {0xd58, 0x00000000}, {0xd5c, 0x30032064}, |
| 288 | {0xd60, 0x4653de68}, {0xd64, 0x04518a3c}, |
| 289 | {0xd68, 0x00002101}, {0xd6c, 0x2a201c16}, |
| 290 | {0xd70, 0x1812362e}, {0xd74, 0x322c2220}, |
| 291 | {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a}, |
| 292 | {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a}, |
| 293 | {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a}, |
| 294 | {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a}, |
| 295 | {0xe28, 0x00000000}, {0xe30, 0x1000dc1f}, |
| 296 | {0xe34, 0x10008c1f}, {0xe38, 0x02140102}, |
| 297 | {0xe3c, 0x681604c2}, {0xe40, 0x01007c00}, |
| 298 | {0xe44, 0x01004800}, {0xe48, 0xfb000000}, |
| 299 | {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f}, |
| 300 | {0xe54, 0x10008c1f}, {0xe58, 0x02140102}, |
| 301 | {0xe5c, 0x28160d05}, {0xe60, 0x00000008}, |
| 302 | {0xe68, 0x001b25a4}, {0xe6c, 0x631b25a0}, |
| 303 | {0xe70, 0x631b25a0}, {0xe74, 0x081b25a0}, |
| 304 | {0xe78, 0x081b25a0}, {0xe7c, 0x081b25a0}, |
| 305 | {0xe80, 0x081b25a0}, {0xe84, 0x631b25a0}, |
| 306 | {0xe88, 0x081b25a0}, {0xe8c, 0x631b25a0}, |
| 307 | {0xed0, 0x631b25a0}, {0xed4, 0x631b25a0}, |
| 308 | {0xed8, 0x631b25a0}, {0xedc, 0x001b25a0}, |
| 309 | {0xee0, 0x001b25a0}, {0xeec, 0x6b1b25a0}, |
| 310 | {0xf14, 0x00000003}, {0xf4c, 0x00000000}, |
| 311 | {0xf00, 0x00000300}, |
| 312 | {0xffff, 0xffffffff}, |
| 313 | }; |
| 314 | |
Jes Sorensen | 36c3258 | 2016-02-29 17:04:14 -0500 | [diff] [blame] | 315 | static struct rtl8xxxu_reg32val rtl8723b_phy_1t_init_table[] = { |
| 316 | {0x800, 0x80040000}, {0x804, 0x00000003}, |
| 317 | {0x808, 0x0000fc00}, {0x80c, 0x0000000a}, |
| 318 | {0x810, 0x10001331}, {0x814, 0x020c3d10}, |
| 319 | {0x818, 0x02200385}, {0x81c, 0x00000000}, |
| 320 | {0x820, 0x01000100}, {0x824, 0x00190204}, |
| 321 | {0x828, 0x00000000}, {0x82c, 0x00000000}, |
| 322 | {0x830, 0x00000000}, {0x834, 0x00000000}, |
| 323 | {0x838, 0x00000000}, {0x83c, 0x00000000}, |
| 324 | {0x840, 0x00010000}, {0x844, 0x00000000}, |
| 325 | {0x848, 0x00000000}, {0x84c, 0x00000000}, |
| 326 | {0x850, 0x00000000}, {0x854, 0x00000000}, |
| 327 | {0x858, 0x569a11a9}, {0x85c, 0x01000014}, |
| 328 | {0x860, 0x66f60110}, {0x864, 0x061f0649}, |
| 329 | {0x868, 0x00000000}, {0x86c, 0x27272700}, |
| 330 | {0x870, 0x07000760}, {0x874, 0x25004000}, |
| 331 | {0x878, 0x00000808}, {0x87c, 0x00000000}, |
| 332 | {0x880, 0xb0000c1c}, {0x884, 0x00000001}, |
| 333 | {0x888, 0x00000000}, {0x88c, 0xccc000c0}, |
| 334 | {0x890, 0x00000800}, {0x894, 0xfffffffe}, |
| 335 | {0x898, 0x40302010}, {0x89c, 0x00706050}, |
| 336 | {0x900, 0x00000000}, {0x904, 0x00000023}, |
| 337 | {0x908, 0x00000000}, {0x90c, 0x81121111}, |
| 338 | {0x910, 0x00000002}, {0x914, 0x00000201}, |
| 339 | {0xa00, 0x00d047c8}, {0xa04, 0x80ff800c}, |
| 340 | {0xa08, 0x8c838300}, {0xa0c, 0x2e7f120f}, |
| 341 | {0xa10, 0x9500bb78}, {0xa14, 0x1114d028}, |
| 342 | {0xa18, 0x00881117}, {0xa1c, 0x89140f00}, |
| 343 | {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317}, |
| 344 | {0xa28, 0x00000204}, {0xa2c, 0x00d30000}, |
| 345 | {0xa70, 0x101fbf00}, {0xa74, 0x00000007}, |
| 346 | {0xa78, 0x00000900}, {0xa7c, 0x225b0606}, |
| 347 | {0xa80, 0x21806490}, {0xb2c, 0x00000000}, |
| 348 | {0xc00, 0x48071d40}, {0xc04, 0x03a05611}, |
| 349 | {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c}, |
| 350 | {0xc10, 0x08800000}, {0xc14, 0x40000100}, |
| 351 | {0xc18, 0x08800000}, {0xc1c, 0x40000100}, |
| 352 | {0xc20, 0x00000000}, {0xc24, 0x00000000}, |
| 353 | {0xc28, 0x00000000}, {0xc2c, 0x00000000}, |
| 354 | {0xc30, 0x69e9ac44}, {0xc34, 0x469652af}, |
| 355 | {0xc38, 0x49795994}, {0xc3c, 0x0a97971c}, |
| 356 | {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7}, |
| 357 | {0xc48, 0xec020107}, {0xc4c, 0x007f037f}, |
| 358 | {0xc50, 0x69553420}, {0xc54, 0x43bc0094}, |
| 359 | {0xc58, 0x00013149}, {0xc5c, 0x00250492}, |
| 360 | {0xc60, 0x00000000}, {0xc64, 0x7112848b}, |
| 361 | {0xc68, 0x47c00bff}, {0xc6c, 0x00000036}, |
| 362 | {0xc70, 0x2c7f000d}, {0xc74, 0x020610db}, |
| 363 | {0xc78, 0x0000001f}, {0xc7c, 0x00b91612}, |
| 364 | {0xc80, 0x390000e4}, {0xc84, 0x20f60000}, |
| 365 | {0xc88, 0x40000100}, {0xc8c, 0x20200000}, |
| 366 | {0xc90, 0x00020e1a}, {0xc94, 0x00000000}, |
| 367 | {0xc98, 0x00020e1a}, {0xc9c, 0x00007f7f}, |
| 368 | {0xca0, 0x00000000}, {0xca4, 0x000300a0}, |
| 369 | {0xca8, 0x00000000}, {0xcac, 0x00000000}, |
| 370 | {0xcb0, 0x00000000}, {0xcb4, 0x00000000}, |
| 371 | {0xcb8, 0x00000000}, {0xcbc, 0x28000000}, |
| 372 | {0xcc0, 0x00000000}, {0xcc4, 0x00000000}, |
| 373 | {0xcc8, 0x00000000}, {0xccc, 0x00000000}, |
| 374 | {0xcd0, 0x00000000}, {0xcd4, 0x00000000}, |
| 375 | {0xcd8, 0x64b22427}, {0xcdc, 0x00766932}, |
| 376 | {0xce0, 0x00222222}, {0xce4, 0x00000000}, |
| 377 | {0xce8, 0x37644302}, {0xcec, 0x2f97d40c}, |
| 378 | {0xd00, 0x00000740}, {0xd04, 0x40020401}, |
| 379 | {0xd08, 0x0000907f}, {0xd0c, 0x20010201}, |
| 380 | {0xd10, 0xa0633333}, {0xd14, 0x3333bc53}, |
| 381 | {0xd18, 0x7a8f5b6f}, {0xd2c, 0xcc979975}, |
| 382 | {0xd30, 0x00000000}, {0xd34, 0x80608000}, |
| 383 | {0xd38, 0x00000000}, {0xd3c, 0x00127353}, |
| 384 | {0xd40, 0x00000000}, {0xd44, 0x00000000}, |
| 385 | {0xd48, 0x00000000}, {0xd4c, 0x00000000}, |
| 386 | {0xd50, 0x6437140a}, {0xd54, 0x00000000}, |
| 387 | {0xd58, 0x00000282}, {0xd5c, 0x30032064}, |
| 388 | {0xd60, 0x4653de68}, {0xd64, 0x04518a3c}, |
| 389 | {0xd68, 0x00002101}, {0xd6c, 0x2a201c16}, |
| 390 | {0xd70, 0x1812362e}, {0xd74, 0x322c2220}, |
| 391 | {0xd78, 0x000e3c24}, {0xe00, 0x2d2d2d2d}, |
| 392 | {0xe04, 0x2d2d2d2d}, {0xe08, 0x0390272d}, |
| 393 | {0xe10, 0x2d2d2d2d}, {0xe14, 0x2d2d2d2d}, |
| 394 | {0xe18, 0x2d2d2d2d}, {0xe1c, 0x2d2d2d2d}, |
| 395 | {0xe28, 0x00000000}, {0xe30, 0x1000dc1f}, |
| 396 | {0xe34, 0x10008c1f}, {0xe38, 0x02140102}, |
| 397 | {0xe3c, 0x681604c2}, {0xe40, 0x01007c00}, |
| 398 | {0xe44, 0x01004800}, {0xe48, 0xfb000000}, |
| 399 | {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f}, |
| 400 | {0xe54, 0x10008c1f}, {0xe58, 0x02140102}, |
| 401 | {0xe5c, 0x28160d05}, {0xe60, 0x00000008}, |
| 402 | {0xe68, 0x001b2556}, {0xe6c, 0x00c00096}, |
| 403 | {0xe70, 0x00c00096}, {0xe74, 0x01000056}, |
| 404 | {0xe78, 0x01000014}, {0xe7c, 0x01000056}, |
| 405 | {0xe80, 0x01000014}, {0xe84, 0x00c00096}, |
| 406 | {0xe88, 0x01000056}, {0xe8c, 0x00c00096}, |
| 407 | {0xed0, 0x00c00096}, {0xed4, 0x00c00096}, |
| 408 | {0xed8, 0x00c00096}, {0xedc, 0x000000d6}, |
| 409 | {0xee0, 0x000000d6}, {0xeec, 0x01c00016}, |
| 410 | {0xf14, 0x00000003}, {0xf4c, 0x00000000}, |
| 411 | {0xf00, 0x00000300}, |
| 412 | {0x820, 0x01000100}, {0x800, 0x83040000}, |
| 413 | {0xffff, 0xffffffff}, |
| 414 | }; |
| 415 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 416 | static struct rtl8xxxu_reg32val rtl8192cu_phy_2t_init_table[] = { |
| 417 | {0x024, 0x0011800f}, {0x028, 0x00ffdb83}, |
| 418 | {0x800, 0x80040002}, {0x804, 0x00000003}, |
| 419 | {0x808, 0x0000fc00}, {0x80c, 0x0000000a}, |
| 420 | {0x810, 0x10000330}, {0x814, 0x020c3d10}, |
| 421 | {0x818, 0x02200385}, {0x81c, 0x00000000}, |
| 422 | {0x820, 0x01000100}, {0x824, 0x00390004}, |
| 423 | {0x828, 0x01000100}, {0x82c, 0x00390004}, |
| 424 | {0x830, 0x27272727}, {0x834, 0x27272727}, |
| 425 | {0x838, 0x27272727}, {0x83c, 0x27272727}, |
| 426 | {0x840, 0x00010000}, {0x844, 0x00010000}, |
| 427 | {0x848, 0x27272727}, {0x84c, 0x27272727}, |
| 428 | {0x850, 0x00000000}, {0x854, 0x00000000}, |
| 429 | {0x858, 0x569a569a}, {0x85c, 0x0c1b25a4}, |
| 430 | {0x860, 0x66e60230}, {0x864, 0x061f0130}, |
| 431 | {0x868, 0x27272727}, {0x86c, 0x2b2b2b27}, |
| 432 | {0x870, 0x07000700}, {0x874, 0x22184000}, |
| 433 | {0x878, 0x08080808}, {0x87c, 0x00000000}, |
| 434 | {0x880, 0xc0083070}, {0x884, 0x000004d5}, |
| 435 | {0x888, 0x00000000}, {0x88c, 0xcc0000c0}, |
| 436 | {0x890, 0x00000800}, {0x894, 0xfffffffe}, |
| 437 | {0x898, 0x40302010}, {0x89c, 0x00706050}, |
| 438 | {0x900, 0x00000000}, {0x904, 0x00000023}, |
| 439 | {0x908, 0x00000000}, {0x90c, 0x81121313}, |
| 440 | {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c}, |
| 441 | {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f}, |
| 442 | {0xa10, 0x9500bb78}, {0xa14, 0x11144028}, |
| 443 | {0xa18, 0x00881117}, {0xa1c, 0x89140f00}, |
| 444 | {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317}, |
| 445 | {0xa28, 0x00000204}, {0xa2c, 0x00d30000}, |
| 446 | {0xa70, 0x101fbf00}, {0xa74, 0x00000007}, |
| 447 | {0xc00, 0x48071d40}, {0xc04, 0x03a05633}, |
| 448 | {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c}, |
| 449 | {0xc10, 0x08800000}, {0xc14, 0x40000100}, |
| 450 | {0xc18, 0x08800000}, {0xc1c, 0x40000100}, |
| 451 | {0xc20, 0x00000000}, {0xc24, 0x00000000}, |
| 452 | {0xc28, 0x00000000}, {0xc2c, 0x00000000}, |
| 453 | {0xc30, 0x69e9ac44}, {0xc34, 0x469652cf}, |
| 454 | {0xc38, 0x49795994}, {0xc3c, 0x0a97971c}, |
| 455 | {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7}, |
| 456 | {0xc48, 0xec020107}, {0xc4c, 0x007f037f}, |
| 457 | {0xc50, 0x69543420}, {0xc54, 0x43bc0094}, |
| 458 | {0xc58, 0x69543420}, {0xc5c, 0x433c0094}, |
| 459 | {0xc60, 0x00000000}, {0xc64, 0x5116848b}, |
| 460 | {0xc68, 0x47c00bff}, {0xc6c, 0x00000036}, |
| 461 | {0xc70, 0x2c7f000d}, {0xc74, 0x2186115b}, |
| 462 | {0xc78, 0x0000001f}, {0xc7c, 0x00b99612}, |
| 463 | {0xc80, 0x40000100}, {0xc84, 0x20f60000}, |
| 464 | {0xc88, 0x40000100}, {0xc8c, 0xa0e40000}, |
| 465 | {0xc90, 0x00121820}, {0xc94, 0x00000000}, |
| 466 | {0xc98, 0x00121820}, {0xc9c, 0x00007f7f}, |
| 467 | {0xca0, 0x00000000}, {0xca4, 0x00000080}, |
| 468 | {0xca8, 0x00000000}, {0xcac, 0x00000000}, |
| 469 | {0xcb0, 0x00000000}, {0xcb4, 0x00000000}, |
| 470 | {0xcb8, 0x00000000}, {0xcbc, 0x28000000}, |
| 471 | {0xcc0, 0x00000000}, {0xcc4, 0x00000000}, |
| 472 | {0xcc8, 0x00000000}, {0xccc, 0x00000000}, |
| 473 | {0xcd0, 0x00000000}, {0xcd4, 0x00000000}, |
| 474 | {0xcd8, 0x64b22427}, {0xcdc, 0x00766932}, |
| 475 | {0xce0, 0x00222222}, {0xce4, 0x00000000}, |
| 476 | {0xce8, 0x37644302}, {0xcec, 0x2f97d40c}, |
| 477 | {0xd00, 0x00080740}, {0xd04, 0x00020403}, |
| 478 | {0xd08, 0x0000907f}, {0xd0c, 0x20010201}, |
| 479 | {0xd10, 0xa0633333}, {0xd14, 0x3333bc43}, |
| 480 | {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975}, |
| 481 | {0xd30, 0x00000000}, {0xd34, 0x80608000}, |
| 482 | {0xd38, 0x00000000}, {0xd3c, 0x00027293}, |
| 483 | {0xd40, 0x00000000}, {0xd44, 0x00000000}, |
| 484 | {0xd48, 0x00000000}, {0xd4c, 0x00000000}, |
| 485 | {0xd50, 0x6437140a}, {0xd54, 0x00000000}, |
| 486 | {0xd58, 0x00000000}, {0xd5c, 0x30032064}, |
| 487 | {0xd60, 0x4653de68}, {0xd64, 0x04518a3c}, |
| 488 | {0xd68, 0x00002101}, {0xd6c, 0x2a201c16}, |
| 489 | {0xd70, 0x1812362e}, {0xd74, 0x322c2220}, |
| 490 | {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a}, |
| 491 | {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a}, |
| 492 | {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a}, |
| 493 | {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a}, |
| 494 | {0xe28, 0x00000000}, {0xe30, 0x1000dc1f}, |
| 495 | {0xe34, 0x10008c1f}, {0xe38, 0x02140102}, |
| 496 | {0xe3c, 0x681604c2}, {0xe40, 0x01007c00}, |
| 497 | {0xe44, 0x01004800}, {0xe48, 0xfb000000}, |
| 498 | {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f}, |
| 499 | {0xe54, 0x10008c1f}, {0xe58, 0x02140102}, |
| 500 | {0xe5c, 0x28160d05}, {0xe60, 0x00000010}, |
| 501 | {0xe68, 0x001b25a4}, {0xe6c, 0x63db25a4}, |
| 502 | {0xe70, 0x63db25a4}, {0xe74, 0x0c1b25a4}, |
| 503 | {0xe78, 0x0c1b25a4}, {0xe7c, 0x0c1b25a4}, |
| 504 | {0xe80, 0x0c1b25a4}, {0xe84, 0x63db25a4}, |
| 505 | {0xe88, 0x0c1b25a4}, {0xe8c, 0x63db25a4}, |
| 506 | {0xed0, 0x63db25a4}, {0xed4, 0x63db25a4}, |
| 507 | {0xed8, 0x63db25a4}, {0xedc, 0x001b25a4}, |
| 508 | {0xee0, 0x001b25a4}, {0xeec, 0x6fdb25a4}, |
| 509 | {0xf14, 0x00000003}, {0xf4c, 0x00000000}, |
| 510 | {0xf00, 0x00000300}, |
| 511 | {0xffff, 0xffffffff}, |
| 512 | }; |
| 513 | |
| 514 | static struct rtl8xxxu_reg32val rtl8188ru_phy_1t_highpa_table[] = { |
| 515 | {0x024, 0x0011800f}, {0x028, 0x00ffdb83}, |
| 516 | {0x040, 0x000c0004}, {0x800, 0x80040000}, |
| 517 | {0x804, 0x00000001}, {0x808, 0x0000fc00}, |
| 518 | {0x80c, 0x0000000a}, {0x810, 0x10005388}, |
| 519 | {0x814, 0x020c3d10}, {0x818, 0x02200385}, |
| 520 | {0x81c, 0x00000000}, {0x820, 0x01000100}, |
| 521 | {0x824, 0x00390204}, {0x828, 0x00000000}, |
| 522 | {0x82c, 0x00000000}, {0x830, 0x00000000}, |
| 523 | {0x834, 0x00000000}, {0x838, 0x00000000}, |
| 524 | {0x83c, 0x00000000}, {0x840, 0x00010000}, |
| 525 | {0x844, 0x00000000}, {0x848, 0x00000000}, |
| 526 | {0x84c, 0x00000000}, {0x850, 0x00000000}, |
| 527 | {0x854, 0x00000000}, {0x858, 0x569a569a}, |
| 528 | {0x85c, 0x001b25a4}, {0x860, 0x66e60230}, |
| 529 | {0x864, 0x061f0130}, {0x868, 0x00000000}, |
| 530 | {0x86c, 0x20202000}, {0x870, 0x03000300}, |
| 531 | {0x874, 0x22004000}, {0x878, 0x00000808}, |
| 532 | {0x87c, 0x00ffc3f1}, {0x880, 0xc0083070}, |
| 533 | {0x884, 0x000004d5}, {0x888, 0x00000000}, |
| 534 | {0x88c, 0xccc000c0}, {0x890, 0x00000800}, |
| 535 | {0x894, 0xfffffffe}, {0x898, 0x40302010}, |
| 536 | {0x89c, 0x00706050}, {0x900, 0x00000000}, |
| 537 | {0x904, 0x00000023}, {0x908, 0x00000000}, |
| 538 | {0x90c, 0x81121111}, {0xa00, 0x00d047c8}, |
| 539 | {0xa04, 0x80ff000c}, {0xa08, 0x8c838300}, |
| 540 | {0xa0c, 0x2e68120f}, {0xa10, 0x9500bb78}, |
| 541 | {0xa14, 0x11144028}, {0xa18, 0x00881117}, |
| 542 | {0xa1c, 0x89140f00}, {0xa20, 0x15160000}, |
| 543 | {0xa24, 0x070b0f12}, {0xa28, 0x00000104}, |
| 544 | {0xa2c, 0x00d30000}, {0xa70, 0x101fbf00}, |
| 545 | {0xa74, 0x00000007}, {0xc00, 0x48071d40}, |
| 546 | {0xc04, 0x03a05611}, {0xc08, 0x000000e4}, |
| 547 | {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000}, |
| 548 | {0xc14, 0x40000100}, {0xc18, 0x08800000}, |
| 549 | {0xc1c, 0x40000100}, {0xc20, 0x00000000}, |
| 550 | {0xc24, 0x00000000}, {0xc28, 0x00000000}, |
| 551 | {0xc2c, 0x00000000}, {0xc30, 0x69e9ac44}, |
| 552 | {0xc34, 0x469652cf}, {0xc38, 0x49795994}, |
| 553 | {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f}, |
| 554 | {0xc44, 0x000100b7}, {0xc48, 0xec020107}, |
| 555 | {0xc4c, 0x007f037f}, {0xc50, 0x6954342e}, |
| 556 | {0xc54, 0x43bc0094}, {0xc58, 0x6954342f}, |
| 557 | {0xc5c, 0x433c0094}, {0xc60, 0x00000000}, |
| 558 | {0xc64, 0x5116848b}, {0xc68, 0x47c00bff}, |
| 559 | {0xc6c, 0x00000036}, {0xc70, 0x2c46000d}, |
| 560 | {0xc74, 0x018610db}, {0xc78, 0x0000001f}, |
| 561 | {0xc7c, 0x00b91612}, {0xc80, 0x24000090}, |
| 562 | {0xc84, 0x20f60000}, {0xc88, 0x24000090}, |
| 563 | {0xc8c, 0x20200000}, {0xc90, 0x00121820}, |
| 564 | {0xc94, 0x00000000}, {0xc98, 0x00121820}, |
| 565 | {0xc9c, 0x00007f7f}, {0xca0, 0x00000000}, |
| 566 | {0xca4, 0x00000080}, {0xca8, 0x00000000}, |
| 567 | {0xcac, 0x00000000}, {0xcb0, 0x00000000}, |
| 568 | {0xcb4, 0x00000000}, {0xcb8, 0x00000000}, |
| 569 | {0xcbc, 0x28000000}, {0xcc0, 0x00000000}, |
| 570 | {0xcc4, 0x00000000}, {0xcc8, 0x00000000}, |
| 571 | {0xccc, 0x00000000}, {0xcd0, 0x00000000}, |
| 572 | {0xcd4, 0x00000000}, {0xcd8, 0x64b22427}, |
| 573 | {0xcdc, 0x00766932}, {0xce0, 0x00222222}, |
| 574 | {0xce4, 0x00000000}, {0xce8, 0x37644302}, |
| 575 | {0xcec, 0x2f97d40c}, {0xd00, 0x00080740}, |
| 576 | {0xd04, 0x00020401}, {0xd08, 0x0000907f}, |
| 577 | {0xd0c, 0x20010201}, {0xd10, 0xa0633333}, |
| 578 | {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b}, |
| 579 | {0xd2c, 0xcc979975}, {0xd30, 0x00000000}, |
| 580 | {0xd34, 0x80608000}, {0xd38, 0x00000000}, |
| 581 | {0xd3c, 0x00027293}, {0xd40, 0x00000000}, |
| 582 | {0xd44, 0x00000000}, {0xd48, 0x00000000}, |
| 583 | {0xd4c, 0x00000000}, {0xd50, 0x6437140a}, |
| 584 | {0xd54, 0x00000000}, {0xd58, 0x00000000}, |
| 585 | {0xd5c, 0x30032064}, {0xd60, 0x4653de68}, |
| 586 | {0xd64, 0x04518a3c}, {0xd68, 0x00002101}, |
| 587 | {0xd6c, 0x2a201c16}, {0xd70, 0x1812362e}, |
| 588 | {0xd74, 0x322c2220}, {0xd78, 0x000e3c24}, |
| 589 | {0xe00, 0x24242424}, {0xe04, 0x24242424}, |
| 590 | {0xe08, 0x03902024}, {0xe10, 0x24242424}, |
| 591 | {0xe14, 0x24242424}, {0xe18, 0x24242424}, |
| 592 | {0xe1c, 0x24242424}, {0xe28, 0x00000000}, |
| 593 | {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f}, |
| 594 | {0xe38, 0x02140102}, {0xe3c, 0x681604c2}, |
| 595 | {0xe40, 0x01007c00}, {0xe44, 0x01004800}, |
| 596 | {0xe48, 0xfb000000}, {0xe4c, 0x000028d1}, |
| 597 | {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f}, |
| 598 | {0xe58, 0x02140102}, {0xe5c, 0x28160d05}, |
| 599 | {0xe60, 0x00000008}, {0xe68, 0x001b25a4}, |
| 600 | {0xe6c, 0x631b25a0}, {0xe70, 0x631b25a0}, |
| 601 | {0xe74, 0x081b25a0}, {0xe78, 0x081b25a0}, |
| 602 | {0xe7c, 0x081b25a0}, {0xe80, 0x081b25a0}, |
| 603 | {0xe84, 0x631b25a0}, {0xe88, 0x081b25a0}, |
| 604 | {0xe8c, 0x631b25a0}, {0xed0, 0x631b25a0}, |
| 605 | {0xed4, 0x631b25a0}, {0xed8, 0x631b25a0}, |
| 606 | {0xedc, 0x001b25a0}, {0xee0, 0x001b25a0}, |
| 607 | {0xeec, 0x6b1b25a0}, {0xee8, 0x31555448}, |
| 608 | {0xf14, 0x00000003}, {0xf4c, 0x00000000}, |
| 609 | {0xf00, 0x00000300}, |
| 610 | {0xffff, 0xffffffff}, |
| 611 | }; |
| 612 | |
Jes Sorensen | ae14c5d | 2016-04-07 14:19:21 -0400 | [diff] [blame] | 613 | static struct rtl8xxxu_reg32val rtl8192eu_phy_init_table[] = { |
| 614 | {0x800, 0x80040000}, {0x804, 0x00000003}, |
| 615 | {0x808, 0x0000fc00}, {0x80c, 0x0000000a}, |
| 616 | {0x810, 0x10001331}, {0x814, 0x020c3d10}, |
| 617 | {0x818, 0x02220385}, {0x81c, 0x00000000}, |
| 618 | {0x820, 0x01000100}, {0x824, 0x00390204}, |
| 619 | {0x828, 0x01000100}, {0x82c, 0x00390204}, |
| 620 | {0x830, 0x32323232}, {0x834, 0x30303030}, |
| 621 | {0x838, 0x30303030}, {0x83c, 0x30303030}, |
| 622 | {0x840, 0x00010000}, {0x844, 0x00010000}, |
| 623 | {0x848, 0x28282828}, {0x84c, 0x28282828}, |
| 624 | {0x850, 0x00000000}, {0x854, 0x00000000}, |
| 625 | {0x858, 0x009a009a}, {0x85c, 0x01000014}, |
| 626 | {0x860, 0x66f60000}, {0x864, 0x061f0000}, |
| 627 | {0x868, 0x30303030}, {0x86c, 0x30303030}, |
| 628 | {0x870, 0x00000000}, {0x874, 0x55004200}, |
| 629 | {0x878, 0x08080808}, {0x87c, 0x00000000}, |
| 630 | {0x880, 0xb0000c1c}, {0x884, 0x00000001}, |
| 631 | {0x888, 0x00000000}, {0x88c, 0xcc0000c0}, |
| 632 | {0x890, 0x00000800}, {0x894, 0xfffffffe}, |
| 633 | {0x898, 0x40302010}, {0x900, 0x00000000}, |
| 634 | {0x904, 0x00000023}, {0x908, 0x00000000}, |
| 635 | {0x90c, 0x81121313}, {0x910, 0x806c0001}, |
| 636 | {0x914, 0x00000001}, {0x918, 0x00000000}, |
| 637 | {0x91c, 0x00010000}, {0x924, 0x00000001}, |
| 638 | {0x928, 0x00000000}, {0x92c, 0x00000000}, |
| 639 | {0x930, 0x00000000}, {0x934, 0x00000000}, |
| 640 | {0x938, 0x00000000}, {0x93c, 0x00000000}, |
| 641 | {0x940, 0x00000000}, {0x944, 0x00000000}, |
| 642 | {0x94c, 0x00000008}, {0xa00, 0x00d0c7c8}, |
| 643 | {0xa04, 0x81ff000c}, {0xa08, 0x8c838300}, |
| 644 | {0xa0c, 0x2e68120f}, {0xa10, 0x95009b78}, |
| 645 | {0xa14, 0x1114d028}, {0xa18, 0x00881117}, |
| 646 | {0xa1c, 0x89140f00}, {0xa20, 0x1a1b0000}, |
| 647 | {0xa24, 0x090e1317}, {0xa28, 0x00000204}, |
| 648 | {0xa2c, 0x00d30000}, {0xa70, 0x101fff00}, |
| 649 | {0xa74, 0x00000007}, {0xa78, 0x00000900}, |
| 650 | {0xa7c, 0x225b0606}, {0xa80, 0x218075b1}, |
| 651 | {0xb38, 0x00000000}, {0xc00, 0x48071d40}, |
| 652 | {0xc04, 0x03a05633}, {0xc08, 0x000000e4}, |
| 653 | {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000}, |
| 654 | {0xc14, 0x40000100}, {0xc18, 0x08800000}, |
| 655 | {0xc1c, 0x40000100}, {0xc20, 0x00000000}, |
| 656 | {0xc24, 0x00000000}, {0xc28, 0x00000000}, |
| 657 | {0xc2c, 0x00000000}, {0xc30, 0x69e9ac47}, |
| 658 | {0xc34, 0x469652af}, {0xc38, 0x49795994}, |
| 659 | {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f}, |
| 660 | {0xc44, 0x000100b7}, {0xc48, 0xec020107}, |
| 661 | {0xc4c, 0x007f037f}, |
| 662 | #ifdef EXT_PA_8192EU |
| 663 | /* External PA or external LNA */ |
| 664 | {0xc50, 0x00340220}, |
| 665 | #else |
| 666 | {0xc50, 0x00340020}, |
| 667 | #endif |
| 668 | {0xc54, 0x0080801f}, |
| 669 | #ifdef EXT_PA_8192EU |
| 670 | /* External PA or external LNA */ |
| 671 | {0xc58, 0x00000220}, |
| 672 | #else |
| 673 | {0xc58, 0x00000020}, |
| 674 | #endif |
| 675 | {0xc5c, 0x00248492}, {0xc60, 0x00000000}, |
| 676 | {0xc64, 0x7112848b}, {0xc68, 0x47c00bff}, |
| 677 | {0xc6c, 0x00000036}, {0xc70, 0x00000600}, |
| 678 | {0xc74, 0x02013169}, {0xc78, 0x0000001f}, |
| 679 | {0xc7c, 0x00b91612}, |
| 680 | #ifdef EXT_PA_8192EU |
| 681 | /* External PA or external LNA */ |
| 682 | {0xc80, 0x2d4000b5}, |
| 683 | #else |
| 684 | {0xc80, 0x40000100}, |
| 685 | #endif |
| 686 | {0xc84, 0x21f60000}, |
| 687 | #ifdef EXT_PA_8192EU |
| 688 | /* External PA or external LNA */ |
| 689 | {0xc88, 0x2d4000b5}, |
| 690 | #else |
| 691 | {0xc88, 0x40000100}, |
| 692 | #endif |
| 693 | {0xc8c, 0xa0e40000}, {0xc90, 0x00121820}, |
| 694 | {0xc94, 0x00000000}, {0xc98, 0x00121820}, |
| 695 | {0xc9c, 0x00007f7f}, {0xca0, 0x00000000}, |
| 696 | {0xca4, 0x000300a0}, {0xca8, 0x00000000}, |
| 697 | {0xcac, 0x00000000}, {0xcb0, 0x00000000}, |
| 698 | {0xcb4, 0x00000000}, {0xcb8, 0x00000000}, |
| 699 | {0xcbc, 0x28000000}, {0xcc0, 0x00000000}, |
| 700 | {0xcc4, 0x00000000}, {0xcc8, 0x00000000}, |
| 701 | {0xccc, 0x00000000}, {0xcd0, 0x00000000}, |
| 702 | {0xcd4, 0x00000000}, {0xcd8, 0x64b22427}, |
| 703 | {0xcdc, 0x00766932}, {0xce0, 0x00222222}, |
| 704 | {0xce4, 0x00040000}, {0xce8, 0x77644302}, |
| 705 | {0xcec, 0x2f97d40c}, {0xd00, 0x00080740}, |
| 706 | {0xd04, 0x00020403}, {0xd08, 0x0000907f}, |
| 707 | {0xd0c, 0x20010201}, {0xd10, 0xa0633333}, |
| 708 | {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b}, |
| 709 | {0xd1c, 0x0000007f}, {0xd2c, 0xcc979975}, |
| 710 | {0xd30, 0x00000000}, {0xd34, 0x80608000}, |
| 711 | {0xd38, 0x00000000}, {0xd3c, 0x00127353}, |
| 712 | {0xd40, 0x00000000}, {0xd44, 0x00000000}, |
| 713 | {0xd48, 0x00000000}, {0xd4c, 0x00000000}, |
| 714 | {0xd50, 0x6437140a}, {0xd54, 0x00000000}, |
| 715 | {0xd58, 0x00000282}, {0xd5c, 0x30032064}, |
| 716 | {0xd60, 0x4653de68}, {0xd64, 0x04518a3c}, |
| 717 | {0xd68, 0x00002101}, {0xd6c, 0x2a201c16}, |
| 718 | {0xd70, 0x1812362e}, {0xd74, 0x322c2220}, |
| 719 | {0xd78, 0x000e3c24}, {0xd80, 0x01081008}, |
| 720 | {0xd84, 0x00000800}, {0xd88, 0xf0b50000}, |
| 721 | {0xe00, 0x30303030}, {0xe04, 0x30303030}, |
| 722 | {0xe08, 0x03903030}, {0xe10, 0x30303030}, |
| 723 | {0xe14, 0x30303030}, {0xe18, 0x30303030}, |
| 724 | {0xe1c, 0x30303030}, {0xe28, 0x00000000}, |
| 725 | {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f}, |
| 726 | {0xe38, 0x02140102}, {0xe3c, 0x681604c2}, |
| 727 | {0xe40, 0x01007c00}, {0xe44, 0x01004800}, |
| 728 | {0xe48, 0xfb000000}, {0xe4c, 0x000028d1}, |
| 729 | {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f}, |
| 730 | {0xe58, 0x02140102}, {0xe5c, 0x28160d05}, |
| 731 | {0xe60, 0x00000008}, {0xe68, 0x0fc05656}, |
| 732 | {0xe6c, 0x03c09696}, {0xe70, 0x03c09696}, |
| 733 | {0xe74, 0x0c005656}, {0xe78, 0x0c005656}, |
| 734 | {0xe7c, 0x0c005656}, {0xe80, 0x0c005656}, |
| 735 | {0xe84, 0x03c09696}, {0xe88, 0x0c005656}, |
| 736 | {0xe8c, 0x03c09696}, {0xed0, 0x03c09696}, |
| 737 | {0xed4, 0x03c09696}, {0xed8, 0x03c09696}, |
| 738 | {0xedc, 0x0000d6d6}, {0xee0, 0x0000d6d6}, |
| 739 | {0xeec, 0x0fc01616}, {0xee4, 0xb0000c1c}, |
| 740 | {0xee8, 0x00000001}, {0xf14, 0x00000003}, |
| 741 | {0xf4c, 0x00000000}, {0xf00, 0x00000300}, |
| 742 | {0xffff, 0xffffffff}, |
| 743 | }; |
| 744 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 745 | static struct rtl8xxxu_reg32val rtl8xxx_agc_standard_table[] = { |
| 746 | {0xc78, 0x7b000001}, {0xc78, 0x7b010001}, |
| 747 | {0xc78, 0x7b020001}, {0xc78, 0x7b030001}, |
| 748 | {0xc78, 0x7b040001}, {0xc78, 0x7b050001}, |
| 749 | {0xc78, 0x7a060001}, {0xc78, 0x79070001}, |
| 750 | {0xc78, 0x78080001}, {0xc78, 0x77090001}, |
| 751 | {0xc78, 0x760a0001}, {0xc78, 0x750b0001}, |
| 752 | {0xc78, 0x740c0001}, {0xc78, 0x730d0001}, |
| 753 | {0xc78, 0x720e0001}, {0xc78, 0x710f0001}, |
| 754 | {0xc78, 0x70100001}, {0xc78, 0x6f110001}, |
| 755 | {0xc78, 0x6e120001}, {0xc78, 0x6d130001}, |
| 756 | {0xc78, 0x6c140001}, {0xc78, 0x6b150001}, |
| 757 | {0xc78, 0x6a160001}, {0xc78, 0x69170001}, |
| 758 | {0xc78, 0x68180001}, {0xc78, 0x67190001}, |
| 759 | {0xc78, 0x661a0001}, {0xc78, 0x651b0001}, |
| 760 | {0xc78, 0x641c0001}, {0xc78, 0x631d0001}, |
| 761 | {0xc78, 0x621e0001}, {0xc78, 0x611f0001}, |
| 762 | {0xc78, 0x60200001}, {0xc78, 0x49210001}, |
| 763 | {0xc78, 0x48220001}, {0xc78, 0x47230001}, |
| 764 | {0xc78, 0x46240001}, {0xc78, 0x45250001}, |
| 765 | {0xc78, 0x44260001}, {0xc78, 0x43270001}, |
| 766 | {0xc78, 0x42280001}, {0xc78, 0x41290001}, |
| 767 | {0xc78, 0x402a0001}, {0xc78, 0x262b0001}, |
| 768 | {0xc78, 0x252c0001}, {0xc78, 0x242d0001}, |
| 769 | {0xc78, 0x232e0001}, {0xc78, 0x222f0001}, |
| 770 | {0xc78, 0x21300001}, {0xc78, 0x20310001}, |
| 771 | {0xc78, 0x06320001}, {0xc78, 0x05330001}, |
| 772 | {0xc78, 0x04340001}, {0xc78, 0x03350001}, |
| 773 | {0xc78, 0x02360001}, {0xc78, 0x01370001}, |
| 774 | {0xc78, 0x00380001}, {0xc78, 0x00390001}, |
| 775 | {0xc78, 0x003a0001}, {0xc78, 0x003b0001}, |
| 776 | {0xc78, 0x003c0001}, {0xc78, 0x003d0001}, |
| 777 | {0xc78, 0x003e0001}, {0xc78, 0x003f0001}, |
| 778 | {0xc78, 0x7b400001}, {0xc78, 0x7b410001}, |
| 779 | {0xc78, 0x7b420001}, {0xc78, 0x7b430001}, |
| 780 | {0xc78, 0x7b440001}, {0xc78, 0x7b450001}, |
| 781 | {0xc78, 0x7a460001}, {0xc78, 0x79470001}, |
| 782 | {0xc78, 0x78480001}, {0xc78, 0x77490001}, |
| 783 | {0xc78, 0x764a0001}, {0xc78, 0x754b0001}, |
| 784 | {0xc78, 0x744c0001}, {0xc78, 0x734d0001}, |
| 785 | {0xc78, 0x724e0001}, {0xc78, 0x714f0001}, |
| 786 | {0xc78, 0x70500001}, {0xc78, 0x6f510001}, |
| 787 | {0xc78, 0x6e520001}, {0xc78, 0x6d530001}, |
| 788 | {0xc78, 0x6c540001}, {0xc78, 0x6b550001}, |
| 789 | {0xc78, 0x6a560001}, {0xc78, 0x69570001}, |
| 790 | {0xc78, 0x68580001}, {0xc78, 0x67590001}, |
| 791 | {0xc78, 0x665a0001}, {0xc78, 0x655b0001}, |
| 792 | {0xc78, 0x645c0001}, {0xc78, 0x635d0001}, |
| 793 | {0xc78, 0x625e0001}, {0xc78, 0x615f0001}, |
| 794 | {0xc78, 0x60600001}, {0xc78, 0x49610001}, |
| 795 | {0xc78, 0x48620001}, {0xc78, 0x47630001}, |
| 796 | {0xc78, 0x46640001}, {0xc78, 0x45650001}, |
| 797 | {0xc78, 0x44660001}, {0xc78, 0x43670001}, |
| 798 | {0xc78, 0x42680001}, {0xc78, 0x41690001}, |
| 799 | {0xc78, 0x406a0001}, {0xc78, 0x266b0001}, |
| 800 | {0xc78, 0x256c0001}, {0xc78, 0x246d0001}, |
| 801 | {0xc78, 0x236e0001}, {0xc78, 0x226f0001}, |
| 802 | {0xc78, 0x21700001}, {0xc78, 0x20710001}, |
| 803 | {0xc78, 0x06720001}, {0xc78, 0x05730001}, |
| 804 | {0xc78, 0x04740001}, {0xc78, 0x03750001}, |
| 805 | {0xc78, 0x02760001}, {0xc78, 0x01770001}, |
| 806 | {0xc78, 0x00780001}, {0xc78, 0x00790001}, |
| 807 | {0xc78, 0x007a0001}, {0xc78, 0x007b0001}, |
| 808 | {0xc78, 0x007c0001}, {0xc78, 0x007d0001}, |
| 809 | {0xc78, 0x007e0001}, {0xc78, 0x007f0001}, |
| 810 | {0xc78, 0x3800001e}, {0xc78, 0x3801001e}, |
| 811 | {0xc78, 0x3802001e}, {0xc78, 0x3803001e}, |
| 812 | {0xc78, 0x3804001e}, {0xc78, 0x3805001e}, |
| 813 | {0xc78, 0x3806001e}, {0xc78, 0x3807001e}, |
| 814 | {0xc78, 0x3808001e}, {0xc78, 0x3c09001e}, |
| 815 | {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e}, |
| 816 | {0xc78, 0x440c001e}, {0xc78, 0x480d001e}, |
| 817 | {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e}, |
| 818 | {0xc78, 0x5210001e}, {0xc78, 0x5611001e}, |
| 819 | {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e}, |
| 820 | {0xc78, 0x6014001e}, {0xc78, 0x6015001e}, |
| 821 | {0xc78, 0x6016001e}, {0xc78, 0x6217001e}, |
| 822 | {0xc78, 0x6218001e}, {0xc78, 0x6219001e}, |
| 823 | {0xc78, 0x621a001e}, {0xc78, 0x621b001e}, |
| 824 | {0xc78, 0x621c001e}, {0xc78, 0x621d001e}, |
| 825 | {0xc78, 0x621e001e}, {0xc78, 0x621f001e}, |
| 826 | {0xffff, 0xffffffff} |
| 827 | }; |
| 828 | |
| 829 | static struct rtl8xxxu_reg32val rtl8xxx_agc_highpa_table[] = { |
| 830 | {0xc78, 0x7b000001}, {0xc78, 0x7b010001}, |
| 831 | {0xc78, 0x7b020001}, {0xc78, 0x7b030001}, |
| 832 | {0xc78, 0x7b040001}, {0xc78, 0x7b050001}, |
| 833 | {0xc78, 0x7b060001}, {0xc78, 0x7b070001}, |
| 834 | {0xc78, 0x7b080001}, {0xc78, 0x7a090001}, |
| 835 | {0xc78, 0x790a0001}, {0xc78, 0x780b0001}, |
| 836 | {0xc78, 0x770c0001}, {0xc78, 0x760d0001}, |
| 837 | {0xc78, 0x750e0001}, {0xc78, 0x740f0001}, |
| 838 | {0xc78, 0x73100001}, {0xc78, 0x72110001}, |
| 839 | {0xc78, 0x71120001}, {0xc78, 0x70130001}, |
| 840 | {0xc78, 0x6f140001}, {0xc78, 0x6e150001}, |
| 841 | {0xc78, 0x6d160001}, {0xc78, 0x6c170001}, |
| 842 | {0xc78, 0x6b180001}, {0xc78, 0x6a190001}, |
| 843 | {0xc78, 0x691a0001}, {0xc78, 0x681b0001}, |
| 844 | {0xc78, 0x671c0001}, {0xc78, 0x661d0001}, |
| 845 | {0xc78, 0x651e0001}, {0xc78, 0x641f0001}, |
| 846 | {0xc78, 0x63200001}, {0xc78, 0x62210001}, |
| 847 | {0xc78, 0x61220001}, {0xc78, 0x60230001}, |
| 848 | {0xc78, 0x46240001}, {0xc78, 0x45250001}, |
| 849 | {0xc78, 0x44260001}, {0xc78, 0x43270001}, |
| 850 | {0xc78, 0x42280001}, {0xc78, 0x41290001}, |
| 851 | {0xc78, 0x402a0001}, {0xc78, 0x262b0001}, |
| 852 | {0xc78, 0x252c0001}, {0xc78, 0x242d0001}, |
| 853 | {0xc78, 0x232e0001}, {0xc78, 0x222f0001}, |
| 854 | {0xc78, 0x21300001}, {0xc78, 0x20310001}, |
| 855 | {0xc78, 0x06320001}, {0xc78, 0x05330001}, |
| 856 | {0xc78, 0x04340001}, {0xc78, 0x03350001}, |
| 857 | {0xc78, 0x02360001}, {0xc78, 0x01370001}, |
| 858 | {0xc78, 0x00380001}, {0xc78, 0x00390001}, |
| 859 | {0xc78, 0x003a0001}, {0xc78, 0x003b0001}, |
| 860 | {0xc78, 0x003c0001}, {0xc78, 0x003d0001}, |
| 861 | {0xc78, 0x003e0001}, {0xc78, 0x003f0001}, |
| 862 | {0xc78, 0x7b400001}, {0xc78, 0x7b410001}, |
| 863 | {0xc78, 0x7b420001}, {0xc78, 0x7b430001}, |
| 864 | {0xc78, 0x7b440001}, {0xc78, 0x7b450001}, |
| 865 | {0xc78, 0x7b460001}, {0xc78, 0x7b470001}, |
| 866 | {0xc78, 0x7b480001}, {0xc78, 0x7a490001}, |
| 867 | {0xc78, 0x794a0001}, {0xc78, 0x784b0001}, |
| 868 | {0xc78, 0x774c0001}, {0xc78, 0x764d0001}, |
| 869 | {0xc78, 0x754e0001}, {0xc78, 0x744f0001}, |
| 870 | {0xc78, 0x73500001}, {0xc78, 0x72510001}, |
| 871 | {0xc78, 0x71520001}, {0xc78, 0x70530001}, |
| 872 | {0xc78, 0x6f540001}, {0xc78, 0x6e550001}, |
| 873 | {0xc78, 0x6d560001}, {0xc78, 0x6c570001}, |
| 874 | {0xc78, 0x6b580001}, {0xc78, 0x6a590001}, |
| 875 | {0xc78, 0x695a0001}, {0xc78, 0x685b0001}, |
| 876 | {0xc78, 0x675c0001}, {0xc78, 0x665d0001}, |
| 877 | {0xc78, 0x655e0001}, {0xc78, 0x645f0001}, |
| 878 | {0xc78, 0x63600001}, {0xc78, 0x62610001}, |
| 879 | {0xc78, 0x61620001}, {0xc78, 0x60630001}, |
| 880 | {0xc78, 0x46640001}, {0xc78, 0x45650001}, |
| 881 | {0xc78, 0x44660001}, {0xc78, 0x43670001}, |
| 882 | {0xc78, 0x42680001}, {0xc78, 0x41690001}, |
| 883 | {0xc78, 0x406a0001}, {0xc78, 0x266b0001}, |
| 884 | {0xc78, 0x256c0001}, {0xc78, 0x246d0001}, |
| 885 | {0xc78, 0x236e0001}, {0xc78, 0x226f0001}, |
| 886 | {0xc78, 0x21700001}, {0xc78, 0x20710001}, |
| 887 | {0xc78, 0x06720001}, {0xc78, 0x05730001}, |
| 888 | {0xc78, 0x04740001}, {0xc78, 0x03750001}, |
| 889 | {0xc78, 0x02760001}, {0xc78, 0x01770001}, |
| 890 | {0xc78, 0x00780001}, {0xc78, 0x00790001}, |
| 891 | {0xc78, 0x007a0001}, {0xc78, 0x007b0001}, |
| 892 | {0xc78, 0x007c0001}, {0xc78, 0x007d0001}, |
| 893 | {0xc78, 0x007e0001}, {0xc78, 0x007f0001}, |
| 894 | {0xc78, 0x3800001e}, {0xc78, 0x3801001e}, |
| 895 | {0xc78, 0x3802001e}, {0xc78, 0x3803001e}, |
| 896 | {0xc78, 0x3804001e}, {0xc78, 0x3805001e}, |
| 897 | {0xc78, 0x3806001e}, {0xc78, 0x3807001e}, |
| 898 | {0xc78, 0x3808001e}, {0xc78, 0x3c09001e}, |
| 899 | {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e}, |
| 900 | {0xc78, 0x440c001e}, {0xc78, 0x480d001e}, |
| 901 | {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e}, |
| 902 | {0xc78, 0x5210001e}, {0xc78, 0x5611001e}, |
| 903 | {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e}, |
| 904 | {0xc78, 0x6014001e}, {0xc78, 0x6015001e}, |
| 905 | {0xc78, 0x6016001e}, {0xc78, 0x6217001e}, |
| 906 | {0xc78, 0x6218001e}, {0xc78, 0x6219001e}, |
| 907 | {0xc78, 0x621a001e}, {0xc78, 0x621b001e}, |
| 908 | {0xc78, 0x621c001e}, {0xc78, 0x621d001e}, |
| 909 | {0xc78, 0x621e001e}, {0xc78, 0x621f001e}, |
| 910 | {0xffff, 0xffffffff} |
| 911 | }; |
| 912 | |
Jes Sorensen | b9f498e | 2016-02-29 17:04:18 -0500 | [diff] [blame] | 913 | static struct rtl8xxxu_reg32val rtl8xxx_agc_8723bu_table[] = { |
| 914 | {0xc78, 0xfd000001}, {0xc78, 0xfc010001}, |
| 915 | {0xc78, 0xfb020001}, {0xc78, 0xfa030001}, |
| 916 | {0xc78, 0xf9040001}, {0xc78, 0xf8050001}, |
| 917 | {0xc78, 0xf7060001}, {0xc78, 0xf6070001}, |
| 918 | {0xc78, 0xf5080001}, {0xc78, 0xf4090001}, |
| 919 | {0xc78, 0xf30a0001}, {0xc78, 0xf20b0001}, |
| 920 | {0xc78, 0xf10c0001}, {0xc78, 0xf00d0001}, |
| 921 | {0xc78, 0xef0e0001}, {0xc78, 0xee0f0001}, |
| 922 | {0xc78, 0xed100001}, {0xc78, 0xec110001}, |
| 923 | {0xc78, 0xeb120001}, {0xc78, 0xea130001}, |
| 924 | {0xc78, 0xe9140001}, {0xc78, 0xe8150001}, |
| 925 | {0xc78, 0xe7160001}, {0xc78, 0xe6170001}, |
| 926 | {0xc78, 0xe5180001}, {0xc78, 0xe4190001}, |
| 927 | {0xc78, 0xe31a0001}, {0xc78, 0xa51b0001}, |
| 928 | {0xc78, 0xa41c0001}, {0xc78, 0xa31d0001}, |
| 929 | {0xc78, 0x671e0001}, {0xc78, 0x661f0001}, |
| 930 | {0xc78, 0x65200001}, {0xc78, 0x64210001}, |
| 931 | {0xc78, 0x63220001}, {0xc78, 0x4a230001}, |
| 932 | {0xc78, 0x49240001}, {0xc78, 0x48250001}, |
| 933 | {0xc78, 0x47260001}, {0xc78, 0x46270001}, |
| 934 | {0xc78, 0x45280001}, {0xc78, 0x44290001}, |
| 935 | {0xc78, 0x432a0001}, {0xc78, 0x422b0001}, |
| 936 | {0xc78, 0x292c0001}, {0xc78, 0x282d0001}, |
| 937 | {0xc78, 0x272e0001}, {0xc78, 0x262f0001}, |
| 938 | {0xc78, 0x0a300001}, {0xc78, 0x09310001}, |
| 939 | {0xc78, 0x08320001}, {0xc78, 0x07330001}, |
| 940 | {0xc78, 0x06340001}, {0xc78, 0x05350001}, |
| 941 | {0xc78, 0x04360001}, {0xc78, 0x03370001}, |
| 942 | {0xc78, 0x02380001}, {0xc78, 0x01390001}, |
| 943 | {0xc78, 0x013a0001}, {0xc78, 0x013b0001}, |
| 944 | {0xc78, 0x013c0001}, {0xc78, 0x013d0001}, |
| 945 | {0xc78, 0x013e0001}, {0xc78, 0x013f0001}, |
| 946 | {0xc78, 0xfc400001}, {0xc78, 0xfb410001}, |
| 947 | {0xc78, 0xfa420001}, {0xc78, 0xf9430001}, |
| 948 | {0xc78, 0xf8440001}, {0xc78, 0xf7450001}, |
| 949 | {0xc78, 0xf6460001}, {0xc78, 0xf5470001}, |
| 950 | {0xc78, 0xf4480001}, {0xc78, 0xf3490001}, |
| 951 | {0xc78, 0xf24a0001}, {0xc78, 0xf14b0001}, |
| 952 | {0xc78, 0xf04c0001}, {0xc78, 0xef4d0001}, |
| 953 | {0xc78, 0xee4e0001}, {0xc78, 0xed4f0001}, |
| 954 | {0xc78, 0xec500001}, {0xc78, 0xeb510001}, |
| 955 | {0xc78, 0xea520001}, {0xc78, 0xe9530001}, |
| 956 | {0xc78, 0xe8540001}, {0xc78, 0xe7550001}, |
| 957 | {0xc78, 0xe6560001}, {0xc78, 0xe5570001}, |
| 958 | {0xc78, 0xe4580001}, {0xc78, 0xe3590001}, |
| 959 | {0xc78, 0xa65a0001}, {0xc78, 0xa55b0001}, |
| 960 | {0xc78, 0xa45c0001}, {0xc78, 0xa35d0001}, |
| 961 | {0xc78, 0x675e0001}, {0xc78, 0x665f0001}, |
| 962 | {0xc78, 0x65600001}, {0xc78, 0x64610001}, |
| 963 | {0xc78, 0x63620001}, {0xc78, 0x62630001}, |
| 964 | {0xc78, 0x61640001}, {0xc78, 0x48650001}, |
| 965 | {0xc78, 0x47660001}, {0xc78, 0x46670001}, |
| 966 | {0xc78, 0x45680001}, {0xc78, 0x44690001}, |
| 967 | {0xc78, 0x436a0001}, {0xc78, 0x426b0001}, |
| 968 | {0xc78, 0x286c0001}, {0xc78, 0x276d0001}, |
| 969 | {0xc78, 0x266e0001}, {0xc78, 0x256f0001}, |
| 970 | {0xc78, 0x24700001}, {0xc78, 0x09710001}, |
| 971 | {0xc78, 0x08720001}, {0xc78, 0x07730001}, |
| 972 | {0xc78, 0x06740001}, {0xc78, 0x05750001}, |
| 973 | {0xc78, 0x04760001}, {0xc78, 0x03770001}, |
| 974 | {0xc78, 0x02780001}, {0xc78, 0x01790001}, |
| 975 | {0xc78, 0x017a0001}, {0xc78, 0x017b0001}, |
| 976 | {0xc78, 0x017c0001}, {0xc78, 0x017d0001}, |
| 977 | {0xc78, 0x017e0001}, {0xc78, 0x017f0001}, |
| 978 | {0xc50, 0x69553422}, |
| 979 | {0xc50, 0x69553420}, |
| 980 | {0x824, 0x00390204}, |
| 981 | {0xffff, 0xffffffff} |
| 982 | }; |
| 983 | |
Jes Sorensen | e293278 | 2016-04-07 14:19:20 -0400 | [diff] [blame] | 984 | static struct rtl8xxxu_reg32val rtl8xxx_agc_8192eu_std_table[] = { |
| 985 | {0xc78, 0xfb000001}, {0xc78, 0xfb010001}, |
| 986 | {0xc78, 0xfb020001}, {0xc78, 0xfb030001}, |
| 987 | {0xc78, 0xfb040001}, {0xc78, 0xfb050001}, |
| 988 | {0xc78, 0xfa060001}, {0xc78, 0xf9070001}, |
| 989 | {0xc78, 0xf8080001}, {0xc78, 0xf7090001}, |
| 990 | {0xc78, 0xf60a0001}, {0xc78, 0xf50b0001}, |
| 991 | {0xc78, 0xf40c0001}, {0xc78, 0xf30d0001}, |
| 992 | {0xc78, 0xf20e0001}, {0xc78, 0xf10f0001}, |
| 993 | {0xc78, 0xf0100001}, {0xc78, 0xef110001}, |
| 994 | {0xc78, 0xee120001}, {0xc78, 0xed130001}, |
| 995 | {0xc78, 0xec140001}, {0xc78, 0xeb150001}, |
| 996 | {0xc78, 0xea160001}, {0xc78, 0xe9170001}, |
| 997 | {0xc78, 0xe8180001}, {0xc78, 0xe7190001}, |
| 998 | {0xc78, 0xc81a0001}, {0xc78, 0xc71b0001}, |
| 999 | {0xc78, 0xc61c0001}, {0xc78, 0x071d0001}, |
| 1000 | {0xc78, 0x061e0001}, {0xc78, 0x051f0001}, |
| 1001 | {0xc78, 0x04200001}, {0xc78, 0x03210001}, |
| 1002 | {0xc78, 0xaa220001}, {0xc78, 0xa9230001}, |
| 1003 | {0xc78, 0xa8240001}, {0xc78, 0xa7250001}, |
| 1004 | {0xc78, 0xa6260001}, {0xc78, 0x85270001}, |
| 1005 | {0xc78, 0x84280001}, {0xc78, 0x83290001}, |
| 1006 | {0xc78, 0x252a0001}, {0xc78, 0x242b0001}, |
| 1007 | {0xc78, 0x232c0001}, {0xc78, 0x222d0001}, |
| 1008 | {0xc78, 0x672e0001}, {0xc78, 0x662f0001}, |
| 1009 | {0xc78, 0x65300001}, {0xc78, 0x64310001}, |
| 1010 | {0xc78, 0x63320001}, {0xc78, 0x62330001}, |
| 1011 | {0xc78, 0x61340001}, {0xc78, 0x45350001}, |
| 1012 | {0xc78, 0x44360001}, {0xc78, 0x43370001}, |
| 1013 | {0xc78, 0x42380001}, {0xc78, 0x41390001}, |
| 1014 | {0xc78, 0x403a0001}, {0xc78, 0x403b0001}, |
| 1015 | {0xc78, 0x403c0001}, {0xc78, 0x403d0001}, |
| 1016 | {0xc78, 0x403e0001}, {0xc78, 0x403f0001}, |
| 1017 | {0xc78, 0xfb400001}, {0xc78, 0xfb410001}, |
| 1018 | {0xc78, 0xfb420001}, {0xc78, 0xfb430001}, |
| 1019 | {0xc78, 0xfb440001}, {0xc78, 0xfb450001}, |
| 1020 | {0xc78, 0xfa460001}, {0xc78, 0xf9470001}, |
| 1021 | {0xc78, 0xf8480001}, {0xc78, 0xf7490001}, |
| 1022 | {0xc78, 0xf64a0001}, {0xc78, 0xf54b0001}, |
| 1023 | {0xc78, 0xf44c0001}, {0xc78, 0xf34d0001}, |
| 1024 | {0xc78, 0xf24e0001}, {0xc78, 0xf14f0001}, |
| 1025 | {0xc78, 0xf0500001}, {0xc78, 0xef510001}, |
| 1026 | {0xc78, 0xee520001}, {0xc78, 0xed530001}, |
| 1027 | {0xc78, 0xec540001}, {0xc78, 0xeb550001}, |
| 1028 | {0xc78, 0xea560001}, {0xc78, 0xe9570001}, |
| 1029 | {0xc78, 0xe8580001}, {0xc78, 0xe7590001}, |
| 1030 | {0xc78, 0xe65a0001}, {0xc78, 0xe55b0001}, |
| 1031 | {0xc78, 0xe45c0001}, {0xc78, 0xe35d0001}, |
| 1032 | {0xc78, 0xe25e0001}, {0xc78, 0xe15f0001}, |
| 1033 | {0xc78, 0x8a600001}, {0xc78, 0x89610001}, |
| 1034 | {0xc78, 0x88620001}, {0xc78, 0x87630001}, |
| 1035 | {0xc78, 0x86640001}, {0xc78, 0x85650001}, |
| 1036 | {0xc78, 0x84660001}, {0xc78, 0x83670001}, |
| 1037 | {0xc78, 0x82680001}, {0xc78, 0x6b690001}, |
| 1038 | {0xc78, 0x6a6a0001}, {0xc78, 0x696b0001}, |
| 1039 | {0xc78, 0x686c0001}, {0xc78, 0x676d0001}, |
| 1040 | {0xc78, 0x666e0001}, {0xc78, 0x656f0001}, |
| 1041 | {0xc78, 0x64700001}, {0xc78, 0x63710001}, |
| 1042 | {0xc78, 0x62720001}, {0xc78, 0x61730001}, |
| 1043 | {0xc78, 0x49740001}, {0xc78, 0x48750001}, |
| 1044 | {0xc78, 0x47760001}, {0xc78, 0x46770001}, |
| 1045 | {0xc78, 0x45780001}, {0xc78, 0x44790001}, |
| 1046 | {0xc78, 0x437a0001}, {0xc78, 0x427b0001}, |
| 1047 | {0xc78, 0x417c0001}, {0xc78, 0x407d0001}, |
| 1048 | {0xc78, 0x407e0001}, {0xc78, 0x407f0001}, |
| 1049 | {0xc50, 0x00040022}, {0xc50, 0x00040020}, |
| 1050 | {0xffff, 0xffffffff} |
| 1051 | }; |
| 1052 | |
| 1053 | static struct rtl8xxxu_reg32val rtl8xxx_agc_8192eu_highpa_table[] = { |
| 1054 | {0xc78, 0xfa000001}, {0xc78, 0xf9010001}, |
| 1055 | {0xc78, 0xf8020001}, {0xc78, 0xf7030001}, |
| 1056 | {0xc78, 0xf6040001}, {0xc78, 0xf5050001}, |
| 1057 | {0xc78, 0xf4060001}, {0xc78, 0xf3070001}, |
| 1058 | {0xc78, 0xf2080001}, {0xc78, 0xf1090001}, |
| 1059 | {0xc78, 0xf00a0001}, {0xc78, 0xef0b0001}, |
| 1060 | {0xc78, 0xee0c0001}, {0xc78, 0xed0d0001}, |
| 1061 | {0xc78, 0xec0e0001}, {0xc78, 0xeb0f0001}, |
| 1062 | {0xc78, 0xea100001}, {0xc78, 0xe9110001}, |
| 1063 | {0xc78, 0xe8120001}, {0xc78, 0xe7130001}, |
| 1064 | {0xc78, 0xe6140001}, {0xc78, 0xe5150001}, |
| 1065 | {0xc78, 0xe4160001}, {0xc78, 0xe3170001}, |
| 1066 | {0xc78, 0xe2180001}, {0xc78, 0xe1190001}, |
| 1067 | {0xc78, 0x8a1a0001}, {0xc78, 0x891b0001}, |
| 1068 | {0xc78, 0x881c0001}, {0xc78, 0x871d0001}, |
| 1069 | {0xc78, 0x861e0001}, {0xc78, 0x851f0001}, |
| 1070 | {0xc78, 0x84200001}, {0xc78, 0x83210001}, |
| 1071 | {0xc78, 0x82220001}, {0xc78, 0x6a230001}, |
| 1072 | {0xc78, 0x69240001}, {0xc78, 0x68250001}, |
| 1073 | {0xc78, 0x67260001}, {0xc78, 0x66270001}, |
| 1074 | {0xc78, 0x65280001}, {0xc78, 0x64290001}, |
| 1075 | {0xc78, 0x632a0001}, {0xc78, 0x622b0001}, |
| 1076 | {0xc78, 0x612c0001}, {0xc78, 0x602d0001}, |
| 1077 | {0xc78, 0x472e0001}, {0xc78, 0x462f0001}, |
| 1078 | {0xc78, 0x45300001}, {0xc78, 0x44310001}, |
| 1079 | {0xc78, 0x43320001}, {0xc78, 0x42330001}, |
| 1080 | {0xc78, 0x41340001}, {0xc78, 0x40350001}, |
| 1081 | {0xc78, 0x40360001}, {0xc78, 0x40370001}, |
| 1082 | {0xc78, 0x40380001}, {0xc78, 0x40390001}, |
| 1083 | {0xc78, 0x403a0001}, {0xc78, 0x403b0001}, |
| 1084 | {0xc78, 0x403c0001}, {0xc78, 0x403d0001}, |
| 1085 | {0xc78, 0x403e0001}, {0xc78, 0x403f0001}, |
| 1086 | {0xc78, 0xfa400001}, {0xc78, 0xf9410001}, |
| 1087 | {0xc78, 0xf8420001}, {0xc78, 0xf7430001}, |
| 1088 | {0xc78, 0xf6440001}, {0xc78, 0xf5450001}, |
| 1089 | {0xc78, 0xf4460001}, {0xc78, 0xf3470001}, |
| 1090 | {0xc78, 0xf2480001}, {0xc78, 0xf1490001}, |
| 1091 | {0xc78, 0xf04a0001}, {0xc78, 0xef4b0001}, |
| 1092 | {0xc78, 0xee4c0001}, {0xc78, 0xed4d0001}, |
| 1093 | {0xc78, 0xec4e0001}, {0xc78, 0xeb4f0001}, |
| 1094 | {0xc78, 0xea500001}, {0xc78, 0xe9510001}, |
| 1095 | {0xc78, 0xe8520001}, {0xc78, 0xe7530001}, |
| 1096 | {0xc78, 0xe6540001}, {0xc78, 0xe5550001}, |
| 1097 | {0xc78, 0xe4560001}, {0xc78, 0xe3570001}, |
| 1098 | {0xc78, 0xe2580001}, {0xc78, 0xe1590001}, |
| 1099 | {0xc78, 0x8a5a0001}, {0xc78, 0x895b0001}, |
| 1100 | {0xc78, 0x885c0001}, {0xc78, 0x875d0001}, |
| 1101 | {0xc78, 0x865e0001}, {0xc78, 0x855f0001}, |
| 1102 | {0xc78, 0x84600001}, {0xc78, 0x83610001}, |
| 1103 | {0xc78, 0x82620001}, {0xc78, 0x6a630001}, |
| 1104 | {0xc78, 0x69640001}, {0xc78, 0x68650001}, |
| 1105 | {0xc78, 0x67660001}, {0xc78, 0x66670001}, |
| 1106 | {0xc78, 0x65680001}, {0xc78, 0x64690001}, |
| 1107 | {0xc78, 0x636a0001}, {0xc78, 0x626b0001}, |
| 1108 | {0xc78, 0x616c0001}, {0xc78, 0x606d0001}, |
| 1109 | {0xc78, 0x476e0001}, {0xc78, 0x466f0001}, |
| 1110 | {0xc78, 0x45700001}, {0xc78, 0x44710001}, |
| 1111 | {0xc78, 0x43720001}, {0xc78, 0x42730001}, |
| 1112 | {0xc78, 0x41740001}, {0xc78, 0x40750001}, |
| 1113 | {0xc78, 0x40760001}, {0xc78, 0x40770001}, |
| 1114 | {0xc78, 0x40780001}, {0xc78, 0x40790001}, |
| 1115 | {0xc78, 0x407a0001}, {0xc78, 0x407b0001}, |
| 1116 | {0xc78, 0x407c0001}, {0xc78, 0x407d0001}, |
| 1117 | {0xc78, 0x407e0001}, {0xc78, 0x407f0001}, |
| 1118 | {0xc50, 0x00040222}, {0xc50, 0x00040220}, |
| 1119 | {0xffff, 0xffffffff} |
| 1120 | }; |
| 1121 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1122 | static struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = { |
| 1123 | {0x00, 0x00030159}, {0x01, 0x00031284}, |
| 1124 | {0x02, 0x00098000}, {0x03, 0x00039c63}, |
| 1125 | {0x04, 0x000210e7}, {0x09, 0x0002044f}, |
| 1126 | {0x0a, 0x0001a3f1}, {0x0b, 0x00014787}, |
| 1127 | {0x0c, 0x000896fe}, {0x0d, 0x0000e02c}, |
| 1128 | {0x0e, 0x00039ce7}, {0x0f, 0x00000451}, |
| 1129 | {0x19, 0x00000000}, {0x1a, 0x00030355}, |
| 1130 | {0x1b, 0x00060a00}, {0x1c, 0x000fc378}, |
| 1131 | {0x1d, 0x000a1250}, {0x1e, 0x0000024f}, |
| 1132 | {0x1f, 0x00000000}, {0x20, 0x0000b614}, |
| 1133 | {0x21, 0x0006c000}, {0x22, 0x00000000}, |
| 1134 | {0x23, 0x00001558}, {0x24, 0x00000060}, |
| 1135 | {0x25, 0x00000483}, {0x26, 0x0004f000}, |
| 1136 | {0x27, 0x000ec7d9}, {0x28, 0x00057730}, |
| 1137 | {0x29, 0x00004783}, {0x2a, 0x00000001}, |
| 1138 | {0x2b, 0x00021334}, {0x2a, 0x00000000}, |
| 1139 | {0x2b, 0x00000054}, {0x2a, 0x00000001}, |
| 1140 | {0x2b, 0x00000808}, {0x2b, 0x00053333}, |
| 1141 | {0x2c, 0x0000000c}, {0x2a, 0x00000002}, |
| 1142 | {0x2b, 0x00000808}, {0x2b, 0x0005b333}, |
| 1143 | {0x2c, 0x0000000d}, {0x2a, 0x00000003}, |
| 1144 | {0x2b, 0x00000808}, {0x2b, 0x00063333}, |
| 1145 | {0x2c, 0x0000000d}, {0x2a, 0x00000004}, |
| 1146 | {0x2b, 0x00000808}, {0x2b, 0x0006b333}, |
| 1147 | {0x2c, 0x0000000d}, {0x2a, 0x00000005}, |
| 1148 | {0x2b, 0x00000808}, {0x2b, 0x00073333}, |
| 1149 | {0x2c, 0x0000000d}, {0x2a, 0x00000006}, |
| 1150 | {0x2b, 0x00000709}, {0x2b, 0x0005b333}, |
| 1151 | {0x2c, 0x0000000d}, {0x2a, 0x00000007}, |
| 1152 | {0x2b, 0x00000709}, {0x2b, 0x00063333}, |
| 1153 | {0x2c, 0x0000000d}, {0x2a, 0x00000008}, |
| 1154 | {0x2b, 0x0000060a}, {0x2b, 0x0004b333}, |
| 1155 | {0x2c, 0x0000000d}, {0x2a, 0x00000009}, |
| 1156 | {0x2b, 0x0000060a}, {0x2b, 0x00053333}, |
| 1157 | {0x2c, 0x0000000d}, {0x2a, 0x0000000a}, |
| 1158 | {0x2b, 0x0000060a}, {0x2b, 0x0005b333}, |
| 1159 | {0x2c, 0x0000000d}, {0x2a, 0x0000000b}, |
| 1160 | {0x2b, 0x0000060a}, {0x2b, 0x00063333}, |
| 1161 | {0x2c, 0x0000000d}, {0x2a, 0x0000000c}, |
| 1162 | {0x2b, 0x0000060a}, {0x2b, 0x0006b333}, |
| 1163 | {0x2c, 0x0000000d}, {0x2a, 0x0000000d}, |
| 1164 | {0x2b, 0x0000060a}, {0x2b, 0x00073333}, |
| 1165 | {0x2c, 0x0000000d}, {0x2a, 0x0000000e}, |
| 1166 | {0x2b, 0x0000050b}, {0x2b, 0x00066666}, |
| 1167 | {0x2c, 0x0000001a}, {0x2a, 0x000e0000}, |
| 1168 | {0x10, 0x0004000f}, {0x11, 0x000e31fc}, |
| 1169 | {0x10, 0x0006000f}, {0x11, 0x000ff9f8}, |
| 1170 | {0x10, 0x0002000f}, {0x11, 0x000203f9}, |
| 1171 | {0x10, 0x0003000f}, {0x11, 0x000ff500}, |
| 1172 | {0x10, 0x00000000}, {0x11, 0x00000000}, |
| 1173 | {0x10, 0x0008000f}, {0x11, 0x0003f100}, |
| 1174 | {0x10, 0x0009000f}, {0x11, 0x00023100}, |
| 1175 | {0x12, 0x00032000}, {0x12, 0x00071000}, |
| 1176 | {0x12, 0x000b0000}, {0x12, 0x000fc000}, |
| 1177 | {0x13, 0x000287b3}, {0x13, 0x000244b7}, |
| 1178 | {0x13, 0x000204ab}, {0x13, 0x0001c49f}, |
| 1179 | {0x13, 0x00018493}, {0x13, 0x0001429b}, |
| 1180 | {0x13, 0x00010299}, {0x13, 0x0000c29c}, |
| 1181 | {0x13, 0x000081a0}, {0x13, 0x000040ac}, |
| 1182 | {0x13, 0x00000020}, {0x14, 0x0001944c}, |
| 1183 | {0x14, 0x00059444}, {0x14, 0x0009944c}, |
| 1184 | {0x14, 0x000d9444}, {0x15, 0x0000f474}, |
| 1185 | {0x15, 0x0004f477}, {0x15, 0x0008f455}, |
| 1186 | {0x15, 0x000cf455}, {0x16, 0x00000339}, |
| 1187 | {0x16, 0x00040339}, {0x16, 0x00080339}, |
| 1188 | {0x16, 0x000c0366}, {0x00, 0x00010159}, |
| 1189 | {0x18, 0x0000f401}, {0xfe, 0x00000000}, |
| 1190 | {0xfe, 0x00000000}, {0x1f, 0x00000003}, |
| 1191 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1192 | {0x1e, 0x00000247}, {0x1f, 0x00000000}, |
| 1193 | {0x00, 0x00030159}, |
| 1194 | {0xff, 0xffffffff} |
| 1195 | }; |
| 1196 | |
Jes Sorensen | 22a31d4 | 2016-02-29 17:04:15 -0500 | [diff] [blame] | 1197 | static struct rtl8xxxu_rfregval rtl8723bu_radioa_1t_init_table[] = { |
| 1198 | {0x00, 0x00010000}, {0xb0, 0x000dffe0}, |
| 1199 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1200 | {0xfe, 0x00000000}, {0xb1, 0x00000018}, |
| 1201 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1202 | {0xfe, 0x00000000}, {0xb2, 0x00084c00}, |
| 1203 | {0xb5, 0x0000d2cc}, {0xb6, 0x000925aa}, |
| 1204 | {0xb7, 0x00000010}, {0xb8, 0x0000907f}, |
| 1205 | {0x5c, 0x00000002}, {0x7c, 0x00000002}, |
| 1206 | {0x7e, 0x00000005}, {0x8b, 0x0006fc00}, |
| 1207 | {0xb0, 0x000ff9f0}, {0x1c, 0x000739d2}, |
| 1208 | {0x1e, 0x00000000}, {0xdf, 0x00000780}, |
| 1209 | {0x50, 0x00067435}, |
| 1210 | /* |
| 1211 | * The 8723bu vendor driver indicates that bit 8 should be set in |
| 1212 | * 0x51 for package types TFBGA90, TFBGA80, and TFBGA79. However |
| 1213 | * they never actually check the package type - and just default |
| 1214 | * to not setting it. |
| 1215 | */ |
| 1216 | {0x51, 0x0006b04e}, |
| 1217 | {0x52, 0x000007d2}, {0x53, 0x00000000}, |
| 1218 | {0x54, 0x00050400}, {0x55, 0x0004026e}, |
| 1219 | {0xdd, 0x0000004c}, {0x70, 0x00067435}, |
| 1220 | /* |
| 1221 | * 0x71 has same package type condition as for register 0x51 |
| 1222 | */ |
| 1223 | {0x71, 0x0006b04e}, |
| 1224 | {0x72, 0x000007d2}, {0x73, 0x00000000}, |
| 1225 | {0x74, 0x00050400}, {0x75, 0x0004026e}, |
| 1226 | {0xef, 0x00000100}, {0x34, 0x0000add7}, |
| 1227 | {0x35, 0x00005c00}, {0x34, 0x00009dd4}, |
| 1228 | {0x35, 0x00005000}, {0x34, 0x00008dd1}, |
| 1229 | {0x35, 0x00004400}, {0x34, 0x00007dce}, |
| 1230 | {0x35, 0x00003800}, {0x34, 0x00006cd1}, |
| 1231 | {0x35, 0x00004400}, {0x34, 0x00005cce}, |
| 1232 | {0x35, 0x00003800}, {0x34, 0x000048ce}, |
| 1233 | {0x35, 0x00004400}, {0x34, 0x000034ce}, |
| 1234 | {0x35, 0x00003800}, {0x34, 0x00002451}, |
| 1235 | {0x35, 0x00004400}, {0x34, 0x0000144e}, |
| 1236 | {0x35, 0x00003800}, {0x34, 0x00000051}, |
| 1237 | {0x35, 0x00004400}, {0xef, 0x00000000}, |
| 1238 | {0xef, 0x00000100}, {0xed, 0x00000010}, |
| 1239 | {0x44, 0x0000add7}, {0x44, 0x00009dd4}, |
| 1240 | {0x44, 0x00008dd1}, {0x44, 0x00007dce}, |
| 1241 | {0x44, 0x00006cc1}, {0x44, 0x00005cce}, |
| 1242 | {0x44, 0x000044d1}, {0x44, 0x000034ce}, |
| 1243 | {0x44, 0x00002451}, {0x44, 0x0000144e}, |
| 1244 | {0x44, 0x00000051}, {0xef, 0x00000000}, |
| 1245 | {0xed, 0x00000000}, {0x7f, 0x00020080}, |
| 1246 | {0xef, 0x00002000}, {0x3b, 0x000380ef}, |
| 1247 | {0x3b, 0x000302fe}, {0x3b, 0x00028ce6}, |
| 1248 | {0x3b, 0x000200bc}, {0x3b, 0x000188a5}, |
| 1249 | {0x3b, 0x00010fbc}, {0x3b, 0x00008f71}, |
| 1250 | {0x3b, 0x00000900}, {0xef, 0x00000000}, |
| 1251 | {0xed, 0x00000001}, {0x40, 0x000380ef}, |
| 1252 | {0x40, 0x000302fe}, {0x40, 0x00028ce6}, |
| 1253 | {0x40, 0x000200bc}, {0x40, 0x000188a5}, |
| 1254 | {0x40, 0x00010fbc}, {0x40, 0x00008f71}, |
| 1255 | {0x40, 0x00000900}, {0xed, 0x00000000}, |
| 1256 | {0x82, 0x00080000}, {0x83, 0x00008000}, |
| 1257 | {0x84, 0x00048d80}, {0x85, 0x00068000}, |
| 1258 | {0xa2, 0x00080000}, {0xa3, 0x00008000}, |
| 1259 | {0xa4, 0x00048d80}, {0xa5, 0x00068000}, |
| 1260 | {0xed, 0x00000002}, {0xef, 0x00000002}, |
| 1261 | {0x56, 0x00000032}, {0x76, 0x00000032}, |
| 1262 | {0x01, 0x00000780}, |
| 1263 | {0xff, 0xffffffff} |
| 1264 | }; |
| 1265 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1266 | static struct rtl8xxxu_rfregval rtl8192cu_radioa_2t_init_table[] = { |
| 1267 | {0x00, 0x00030159}, {0x01, 0x00031284}, |
| 1268 | {0x02, 0x00098000}, {0x03, 0x00018c63}, |
| 1269 | {0x04, 0x000210e7}, {0x09, 0x0002044f}, |
| 1270 | {0x0a, 0x0001adb1}, {0x0b, 0x00054867}, |
| 1271 | {0x0c, 0x0008992e}, {0x0d, 0x0000e52c}, |
| 1272 | {0x0e, 0x00039ce7}, {0x0f, 0x00000451}, |
| 1273 | {0x19, 0x00000000}, {0x1a, 0x00010255}, |
| 1274 | {0x1b, 0x00060a00}, {0x1c, 0x000fc378}, |
| 1275 | {0x1d, 0x000a1250}, {0x1e, 0x0004445f}, |
| 1276 | {0x1f, 0x00080001}, {0x20, 0x0000b614}, |
| 1277 | {0x21, 0x0006c000}, {0x22, 0x00000000}, |
| 1278 | {0x23, 0x00001558}, {0x24, 0x00000060}, |
| 1279 | {0x25, 0x00000483}, {0x26, 0x0004f000}, |
| 1280 | {0x27, 0x000ec7d9}, {0x28, 0x000577c0}, |
| 1281 | {0x29, 0x00004783}, {0x2a, 0x00000001}, |
| 1282 | {0x2b, 0x00021334}, {0x2a, 0x00000000}, |
| 1283 | {0x2b, 0x00000054}, {0x2a, 0x00000001}, |
| 1284 | {0x2b, 0x00000808}, {0x2b, 0x00053333}, |
| 1285 | {0x2c, 0x0000000c}, {0x2a, 0x00000002}, |
| 1286 | {0x2b, 0x00000808}, {0x2b, 0x0005b333}, |
| 1287 | {0x2c, 0x0000000d}, {0x2a, 0x00000003}, |
| 1288 | {0x2b, 0x00000808}, {0x2b, 0x00063333}, |
| 1289 | {0x2c, 0x0000000d}, {0x2a, 0x00000004}, |
| 1290 | {0x2b, 0x00000808}, {0x2b, 0x0006b333}, |
| 1291 | {0x2c, 0x0000000d}, {0x2a, 0x00000005}, |
| 1292 | {0x2b, 0x00000808}, {0x2b, 0x00073333}, |
| 1293 | {0x2c, 0x0000000d}, {0x2a, 0x00000006}, |
| 1294 | {0x2b, 0x00000709}, {0x2b, 0x0005b333}, |
| 1295 | {0x2c, 0x0000000d}, {0x2a, 0x00000007}, |
| 1296 | {0x2b, 0x00000709}, {0x2b, 0x00063333}, |
| 1297 | {0x2c, 0x0000000d}, {0x2a, 0x00000008}, |
| 1298 | {0x2b, 0x0000060a}, {0x2b, 0x0004b333}, |
| 1299 | {0x2c, 0x0000000d}, {0x2a, 0x00000009}, |
| 1300 | {0x2b, 0x0000060a}, {0x2b, 0x00053333}, |
| 1301 | {0x2c, 0x0000000d}, {0x2a, 0x0000000a}, |
| 1302 | {0x2b, 0x0000060a}, {0x2b, 0x0005b333}, |
| 1303 | {0x2c, 0x0000000d}, {0x2a, 0x0000000b}, |
| 1304 | {0x2b, 0x0000060a}, {0x2b, 0x00063333}, |
| 1305 | {0x2c, 0x0000000d}, {0x2a, 0x0000000c}, |
| 1306 | {0x2b, 0x0000060a}, {0x2b, 0x0006b333}, |
| 1307 | {0x2c, 0x0000000d}, {0x2a, 0x0000000d}, |
| 1308 | {0x2b, 0x0000060a}, {0x2b, 0x00073333}, |
| 1309 | {0x2c, 0x0000000d}, {0x2a, 0x0000000e}, |
| 1310 | {0x2b, 0x0000050b}, {0x2b, 0x00066666}, |
| 1311 | {0x2c, 0x0000001a}, {0x2a, 0x000e0000}, |
| 1312 | {0x10, 0x0004000f}, {0x11, 0x000e31fc}, |
| 1313 | {0x10, 0x0006000f}, {0x11, 0x000ff9f8}, |
| 1314 | {0x10, 0x0002000f}, {0x11, 0x000203f9}, |
| 1315 | {0x10, 0x0003000f}, {0x11, 0x000ff500}, |
| 1316 | {0x10, 0x00000000}, {0x11, 0x00000000}, |
| 1317 | {0x10, 0x0008000f}, {0x11, 0x0003f100}, |
| 1318 | {0x10, 0x0009000f}, {0x11, 0x00023100}, |
| 1319 | {0x12, 0x00032000}, {0x12, 0x00071000}, |
| 1320 | {0x12, 0x000b0000}, {0x12, 0x000fc000}, |
| 1321 | {0x13, 0x000287b3}, {0x13, 0x000244b7}, |
| 1322 | {0x13, 0x000204ab}, {0x13, 0x0001c49f}, |
| 1323 | {0x13, 0x00018493}, {0x13, 0x0001429b}, |
| 1324 | {0x13, 0x00010299}, {0x13, 0x0000c29c}, |
| 1325 | {0x13, 0x000081a0}, {0x13, 0x000040ac}, |
| 1326 | {0x13, 0x00000020}, {0x14, 0x0001944c}, |
| 1327 | {0x14, 0x00059444}, {0x14, 0x0009944c}, |
| 1328 | {0x14, 0x000d9444}, {0x15, 0x0000f424}, |
| 1329 | {0x15, 0x0004f424}, {0x15, 0x0008f424}, |
| 1330 | {0x15, 0x000cf424}, {0x16, 0x000e0330}, |
| 1331 | {0x16, 0x000a0330}, {0x16, 0x00060330}, |
| 1332 | {0x16, 0x00020330}, {0x00, 0x00010159}, |
| 1333 | {0x18, 0x0000f401}, {0xfe, 0x00000000}, |
| 1334 | {0xfe, 0x00000000}, {0x1f, 0x00080003}, |
| 1335 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1336 | {0x1e, 0x00044457}, {0x1f, 0x00080000}, |
| 1337 | {0x00, 0x00030159}, |
| 1338 | {0xff, 0xffffffff} |
| 1339 | }; |
| 1340 | |
| 1341 | static struct rtl8xxxu_rfregval rtl8192cu_radiob_2t_init_table[] = { |
| 1342 | {0x00, 0x00030159}, {0x01, 0x00031284}, |
| 1343 | {0x02, 0x00098000}, {0x03, 0x00018c63}, |
| 1344 | {0x04, 0x000210e7}, {0x09, 0x0002044f}, |
| 1345 | {0x0a, 0x0001adb1}, {0x0b, 0x00054867}, |
| 1346 | {0x0c, 0x0008992e}, {0x0d, 0x0000e52c}, |
| 1347 | {0x0e, 0x00039ce7}, {0x0f, 0x00000451}, |
| 1348 | {0x12, 0x00032000}, {0x12, 0x00071000}, |
| 1349 | {0x12, 0x000b0000}, {0x12, 0x000fc000}, |
| 1350 | {0x13, 0x000287af}, {0x13, 0x000244b7}, |
| 1351 | {0x13, 0x000204ab}, {0x13, 0x0001c49f}, |
| 1352 | {0x13, 0x00018493}, {0x13, 0x00014297}, |
| 1353 | {0x13, 0x00010295}, {0x13, 0x0000c298}, |
| 1354 | {0x13, 0x0000819c}, {0x13, 0x000040a8}, |
| 1355 | {0x13, 0x0000001c}, {0x14, 0x0001944c}, |
| 1356 | {0x14, 0x00059444}, {0x14, 0x0009944c}, |
| 1357 | {0x14, 0x000d9444}, {0x15, 0x0000f424}, |
| 1358 | {0x15, 0x0004f424}, {0x15, 0x0008f424}, |
| 1359 | {0x15, 0x000cf424}, {0x16, 0x000e0330}, |
| 1360 | {0x16, 0x000a0330}, {0x16, 0x00060330}, |
| 1361 | {0x16, 0x00020330}, |
| 1362 | {0xff, 0xffffffff} |
| 1363 | }; |
| 1364 | |
| 1365 | static struct rtl8xxxu_rfregval rtl8192cu_radioa_1t_init_table[] = { |
| 1366 | {0x00, 0x00030159}, {0x01, 0x00031284}, |
| 1367 | {0x02, 0x00098000}, {0x03, 0x00018c63}, |
| 1368 | {0x04, 0x000210e7}, {0x09, 0x0002044f}, |
| 1369 | {0x0a, 0x0001adb1}, {0x0b, 0x00054867}, |
| 1370 | {0x0c, 0x0008992e}, {0x0d, 0x0000e52c}, |
| 1371 | {0x0e, 0x00039ce7}, {0x0f, 0x00000451}, |
| 1372 | {0x19, 0x00000000}, {0x1a, 0x00010255}, |
| 1373 | {0x1b, 0x00060a00}, {0x1c, 0x000fc378}, |
| 1374 | {0x1d, 0x000a1250}, {0x1e, 0x0004445f}, |
| 1375 | {0x1f, 0x00080001}, {0x20, 0x0000b614}, |
| 1376 | {0x21, 0x0006c000}, {0x22, 0x00000000}, |
| 1377 | {0x23, 0x00001558}, {0x24, 0x00000060}, |
| 1378 | {0x25, 0x00000483}, {0x26, 0x0004f000}, |
| 1379 | {0x27, 0x000ec7d9}, {0x28, 0x000577c0}, |
| 1380 | {0x29, 0x00004783}, {0x2a, 0x00000001}, |
| 1381 | {0x2b, 0x00021334}, {0x2a, 0x00000000}, |
| 1382 | {0x2b, 0x00000054}, {0x2a, 0x00000001}, |
| 1383 | {0x2b, 0x00000808}, {0x2b, 0x00053333}, |
| 1384 | {0x2c, 0x0000000c}, {0x2a, 0x00000002}, |
| 1385 | {0x2b, 0x00000808}, {0x2b, 0x0005b333}, |
| 1386 | {0x2c, 0x0000000d}, {0x2a, 0x00000003}, |
| 1387 | {0x2b, 0x00000808}, {0x2b, 0x00063333}, |
| 1388 | {0x2c, 0x0000000d}, {0x2a, 0x00000004}, |
| 1389 | {0x2b, 0x00000808}, {0x2b, 0x0006b333}, |
| 1390 | {0x2c, 0x0000000d}, {0x2a, 0x00000005}, |
| 1391 | {0x2b, 0x00000808}, {0x2b, 0x00073333}, |
| 1392 | {0x2c, 0x0000000d}, {0x2a, 0x00000006}, |
| 1393 | {0x2b, 0x00000709}, {0x2b, 0x0005b333}, |
| 1394 | {0x2c, 0x0000000d}, {0x2a, 0x00000007}, |
| 1395 | {0x2b, 0x00000709}, {0x2b, 0x00063333}, |
| 1396 | {0x2c, 0x0000000d}, {0x2a, 0x00000008}, |
| 1397 | {0x2b, 0x0000060a}, {0x2b, 0x0004b333}, |
| 1398 | {0x2c, 0x0000000d}, {0x2a, 0x00000009}, |
| 1399 | {0x2b, 0x0000060a}, {0x2b, 0x00053333}, |
| 1400 | {0x2c, 0x0000000d}, {0x2a, 0x0000000a}, |
| 1401 | {0x2b, 0x0000060a}, {0x2b, 0x0005b333}, |
| 1402 | {0x2c, 0x0000000d}, {0x2a, 0x0000000b}, |
| 1403 | {0x2b, 0x0000060a}, {0x2b, 0x00063333}, |
| 1404 | {0x2c, 0x0000000d}, {0x2a, 0x0000000c}, |
| 1405 | {0x2b, 0x0000060a}, {0x2b, 0x0006b333}, |
| 1406 | {0x2c, 0x0000000d}, {0x2a, 0x0000000d}, |
| 1407 | {0x2b, 0x0000060a}, {0x2b, 0x00073333}, |
| 1408 | {0x2c, 0x0000000d}, {0x2a, 0x0000000e}, |
| 1409 | {0x2b, 0x0000050b}, {0x2b, 0x00066666}, |
| 1410 | {0x2c, 0x0000001a}, {0x2a, 0x000e0000}, |
| 1411 | {0x10, 0x0004000f}, {0x11, 0x000e31fc}, |
| 1412 | {0x10, 0x0006000f}, {0x11, 0x000ff9f8}, |
| 1413 | {0x10, 0x0002000f}, {0x11, 0x000203f9}, |
| 1414 | {0x10, 0x0003000f}, {0x11, 0x000ff500}, |
| 1415 | {0x10, 0x00000000}, {0x11, 0x00000000}, |
| 1416 | {0x10, 0x0008000f}, {0x11, 0x0003f100}, |
| 1417 | {0x10, 0x0009000f}, {0x11, 0x00023100}, |
| 1418 | {0x12, 0x00032000}, {0x12, 0x00071000}, |
| 1419 | {0x12, 0x000b0000}, {0x12, 0x000fc000}, |
| 1420 | {0x13, 0x000287b3}, {0x13, 0x000244b7}, |
| 1421 | {0x13, 0x000204ab}, {0x13, 0x0001c49f}, |
| 1422 | {0x13, 0x00018493}, {0x13, 0x0001429b}, |
| 1423 | {0x13, 0x00010299}, {0x13, 0x0000c29c}, |
| 1424 | {0x13, 0x000081a0}, {0x13, 0x000040ac}, |
| 1425 | {0x13, 0x00000020}, {0x14, 0x0001944c}, |
| 1426 | {0x14, 0x00059444}, {0x14, 0x0009944c}, |
| 1427 | {0x14, 0x000d9444}, {0x15, 0x0000f405}, |
| 1428 | {0x15, 0x0004f405}, {0x15, 0x0008f405}, |
| 1429 | {0x15, 0x000cf405}, {0x16, 0x000e0330}, |
| 1430 | {0x16, 0x000a0330}, {0x16, 0x00060330}, |
| 1431 | {0x16, 0x00020330}, {0x00, 0x00010159}, |
| 1432 | {0x18, 0x0000f401}, {0xfe, 0x00000000}, |
| 1433 | {0xfe, 0x00000000}, {0x1f, 0x00080003}, |
| 1434 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1435 | {0x1e, 0x00044457}, {0x1f, 0x00080000}, |
| 1436 | {0x00, 0x00030159}, |
| 1437 | {0xff, 0xffffffff} |
| 1438 | }; |
| 1439 | |
| 1440 | static struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = { |
| 1441 | {0x00, 0x00030159}, {0x01, 0x00031284}, |
| 1442 | {0x02, 0x00098000}, {0x03, 0x00018c63}, |
| 1443 | {0x04, 0x000210e7}, {0x09, 0x0002044f}, |
| 1444 | {0x0a, 0x0001adb0}, {0x0b, 0x00054867}, |
| 1445 | {0x0c, 0x0008992e}, {0x0d, 0x0000e529}, |
| 1446 | {0x0e, 0x00039ce7}, {0x0f, 0x00000451}, |
| 1447 | {0x19, 0x00000000}, {0x1a, 0x00000255}, |
| 1448 | {0x1b, 0x00060a00}, {0x1c, 0x000fc378}, |
| 1449 | {0x1d, 0x000a1250}, {0x1e, 0x0004445f}, |
| 1450 | {0x1f, 0x00080001}, {0x20, 0x0000b614}, |
| 1451 | {0x21, 0x0006c000}, {0x22, 0x0000083c}, |
| 1452 | {0x23, 0x00001558}, {0x24, 0x00000060}, |
| 1453 | {0x25, 0x00000483}, {0x26, 0x0004f000}, |
| 1454 | {0x27, 0x000ec7d9}, {0x28, 0x000977c0}, |
| 1455 | {0x29, 0x00004783}, {0x2a, 0x00000001}, |
| 1456 | {0x2b, 0x00021334}, {0x2a, 0x00000000}, |
| 1457 | {0x2b, 0x00000054}, {0x2a, 0x00000001}, |
| 1458 | {0x2b, 0x00000808}, {0x2b, 0x00053333}, |
| 1459 | {0x2c, 0x0000000c}, {0x2a, 0x00000002}, |
| 1460 | {0x2b, 0x00000808}, {0x2b, 0x0005b333}, |
| 1461 | {0x2c, 0x0000000d}, {0x2a, 0x00000003}, |
| 1462 | {0x2b, 0x00000808}, {0x2b, 0x00063333}, |
| 1463 | {0x2c, 0x0000000d}, {0x2a, 0x00000004}, |
| 1464 | {0x2b, 0x00000808}, {0x2b, 0x0006b333}, |
| 1465 | {0x2c, 0x0000000d}, {0x2a, 0x00000005}, |
| 1466 | {0x2b, 0x00000808}, {0x2b, 0x00073333}, |
| 1467 | {0x2c, 0x0000000d}, {0x2a, 0x00000006}, |
| 1468 | {0x2b, 0x00000709}, {0x2b, 0x0005b333}, |
| 1469 | {0x2c, 0x0000000d}, {0x2a, 0x00000007}, |
| 1470 | {0x2b, 0x00000709}, {0x2b, 0x00063333}, |
| 1471 | {0x2c, 0x0000000d}, {0x2a, 0x00000008}, |
| 1472 | {0x2b, 0x0000060a}, {0x2b, 0x0004b333}, |
| 1473 | {0x2c, 0x0000000d}, {0x2a, 0x00000009}, |
| 1474 | {0x2b, 0x0000060a}, {0x2b, 0x00053333}, |
| 1475 | {0x2c, 0x0000000d}, {0x2a, 0x0000000a}, |
| 1476 | {0x2b, 0x0000060a}, {0x2b, 0x0005b333}, |
| 1477 | {0x2c, 0x0000000d}, {0x2a, 0x0000000b}, |
| 1478 | {0x2b, 0x0000060a}, {0x2b, 0x00063333}, |
| 1479 | {0x2c, 0x0000000d}, {0x2a, 0x0000000c}, |
| 1480 | {0x2b, 0x0000060a}, {0x2b, 0x0006b333}, |
| 1481 | {0x2c, 0x0000000d}, {0x2a, 0x0000000d}, |
| 1482 | {0x2b, 0x0000060a}, {0x2b, 0x00073333}, |
| 1483 | {0x2c, 0x0000000d}, {0x2a, 0x0000000e}, |
| 1484 | {0x2b, 0x0000050b}, {0x2b, 0x00066666}, |
| 1485 | {0x2c, 0x0000001a}, {0x2a, 0x000e0000}, |
| 1486 | {0x10, 0x0004000f}, {0x11, 0x000e31fc}, |
| 1487 | {0x10, 0x0006000f}, {0x11, 0x000ff9f8}, |
| 1488 | {0x10, 0x0002000f}, {0x11, 0x000203f9}, |
| 1489 | {0x10, 0x0003000f}, {0x11, 0x000ff500}, |
| 1490 | {0x10, 0x00000000}, {0x11, 0x00000000}, |
| 1491 | {0x10, 0x0008000f}, {0x11, 0x0003f100}, |
| 1492 | {0x10, 0x0009000f}, {0x11, 0x00023100}, |
| 1493 | {0x12, 0x000d8000}, {0x12, 0x00090000}, |
| 1494 | {0x12, 0x00051000}, {0x12, 0x00012000}, |
| 1495 | {0x13, 0x00028fb4}, {0x13, 0x00024fa8}, |
| 1496 | {0x13, 0x000207a4}, {0x13, 0x0001c3b0}, |
| 1497 | {0x13, 0x000183a4}, {0x13, 0x00014398}, |
| 1498 | {0x13, 0x000101a4}, {0x13, 0x0000c198}, |
| 1499 | {0x13, 0x000080a4}, {0x13, 0x00004098}, |
| 1500 | {0x13, 0x00000000}, {0x14, 0x0001944c}, |
| 1501 | {0x14, 0x00059444}, {0x14, 0x0009944c}, |
| 1502 | {0x14, 0x000d9444}, {0x15, 0x0000f405}, |
| 1503 | {0x15, 0x0004f405}, {0x15, 0x0008f405}, |
| 1504 | {0x15, 0x000cf405}, {0x16, 0x000e0330}, |
| 1505 | {0x16, 0x000a0330}, {0x16, 0x00060330}, |
| 1506 | {0x16, 0x00020330}, {0x00, 0x00010159}, |
| 1507 | {0x18, 0x0000f401}, {0xfe, 0x00000000}, |
| 1508 | {0xfe, 0x00000000}, {0x1f, 0x00080003}, |
| 1509 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1510 | {0x1e, 0x00044457}, {0x1f, 0x00080000}, |
| 1511 | {0x00, 0x00030159}, |
| 1512 | {0xff, 0xffffffff} |
| 1513 | }; |
| 1514 | |
Jes Sorensen | 19102f8 | 2016-04-07 14:19:19 -0400 | [diff] [blame] | 1515 | static struct rtl8xxxu_rfregval rtl8192eu_radioa_init_table[] = { |
| 1516 | {0x7f, 0x00000082}, {0x81, 0x0003fc00}, |
| 1517 | {0x00, 0x00030000}, {0x08, 0x00008400}, |
| 1518 | {0x18, 0x00000407}, {0x19, 0x00000012}, |
| 1519 | {0x1b, 0x00000064}, {0x1e, 0x00080009}, |
| 1520 | {0x1f, 0x00000880}, {0x2f, 0x0001a060}, |
| 1521 | {0x3f, 0x00000000}, {0x42, 0x000060c0}, |
| 1522 | {0x57, 0x000d0000}, {0x58, 0x000be180}, |
| 1523 | {0x67, 0x00001552}, {0x83, 0x00000000}, |
| 1524 | {0xb0, 0x000ff9f1}, {0xb1, 0x00055418}, |
| 1525 | {0xb2, 0x0008cc00}, {0xb4, 0x00043083}, |
| 1526 | {0xb5, 0x00008166}, {0xb6, 0x0000803e}, |
| 1527 | {0xb7, 0x0001c69f}, {0xb8, 0x0000407f}, |
| 1528 | {0xb9, 0x00080001}, {0xba, 0x00040001}, |
| 1529 | {0xbb, 0x00000400}, {0xbf, 0x000c0000}, |
| 1530 | {0xc2, 0x00002400}, {0xc3, 0x00000009}, |
| 1531 | {0xc4, 0x00040c91}, {0xc5, 0x00099999}, |
| 1532 | {0xc6, 0x000000a3}, {0xc7, 0x00088820}, |
| 1533 | {0xc8, 0x00076c06}, {0xc9, 0x00000000}, |
| 1534 | {0xca, 0x00080000}, {0xdf, 0x00000180}, |
| 1535 | {0xef, 0x000001a0}, {0x51, 0x00069545}, |
| 1536 | {0x52, 0x0007e45e}, {0x53, 0x00000071}, |
| 1537 | {0x56, 0x00051ff3}, {0x35, 0x000000a8}, |
| 1538 | {0x35, 0x000001e2}, {0x35, 0x000002a8}, |
| 1539 | {0x36, 0x00001c24}, {0x36, 0x00009c24}, |
| 1540 | {0x36, 0x00011c24}, {0x36, 0x00019c24}, |
| 1541 | {0x18, 0x00000c07}, {0x5a, 0x00048000}, |
| 1542 | {0x19, 0x000739d0}, |
| 1543 | #ifdef EXT_PA_8192EU |
| 1544 | /* External PA or external LNA */ |
| 1545 | {0x34, 0x0000a093}, {0x34, 0x0000908f}, |
| 1546 | {0x34, 0x0000808c}, {0x34, 0x0000704d}, |
| 1547 | {0x34, 0x0000604a}, {0x34, 0x00005047}, |
| 1548 | {0x34, 0x0000400a}, {0x34, 0x00003007}, |
| 1549 | {0x34, 0x00002004}, {0x34, 0x00001001}, |
| 1550 | {0x34, 0x00000000}, |
| 1551 | #else |
| 1552 | /* Regular */ |
| 1553 | {0x34, 0x0000add7}, {0x34, 0x00009dd4}, |
| 1554 | {0x34, 0x00008dd1}, {0x34, 0x00007dce}, |
| 1555 | {0x34, 0x00006dcb}, {0x34, 0x00005dc8}, |
| 1556 | {0x34, 0x00004dc5}, {0x34, 0x000034cc}, |
| 1557 | {0x34, 0x0000244f}, {0x34, 0x0000144c}, |
| 1558 | {0x34, 0x00000014}, |
| 1559 | #endif |
| 1560 | {0x00, 0x00030159}, |
| 1561 | {0x84, 0x00068180}, |
| 1562 | {0x86, 0x0000014e}, |
| 1563 | {0x87, 0x00048e00}, |
| 1564 | {0x8e, 0x00065540}, |
| 1565 | {0x8f, 0x00088000}, |
| 1566 | {0xef, 0x000020a0}, |
| 1567 | #ifdef EXT_PA_8192EU |
| 1568 | /* External PA or external LNA */ |
| 1569 | {0x3b, 0x000f07b0}, |
| 1570 | #else |
| 1571 | {0x3b, 0x000f02b0}, |
| 1572 | #endif |
| 1573 | {0x3b, 0x000ef7b0}, {0x3b, 0x000d4fb0}, |
| 1574 | {0x3b, 0x000cf060}, {0x3b, 0x000b0090}, |
| 1575 | {0x3b, 0x000a0080}, {0x3b, 0x00090080}, |
| 1576 | {0x3b, 0x0008f780}, |
| 1577 | #ifdef EXT_PA_8192EU |
| 1578 | /* External PA or external LNA */ |
| 1579 | {0x3b, 0x000787b0}, |
| 1580 | #else |
| 1581 | {0x3b, 0x00078730}, |
| 1582 | #endif |
| 1583 | {0x3b, 0x00060fb0}, {0x3b, 0x0005ffa0}, |
| 1584 | {0x3b, 0x00040620}, {0x3b, 0x00037090}, |
| 1585 | {0x3b, 0x00020080}, {0x3b, 0x0001f060}, |
| 1586 | {0x3b, 0x0000ffb0}, {0xef, 0x000000a0}, |
| 1587 | {0xfe, 0x00000000}, {0x18, 0x0000fc07}, |
| 1588 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1589 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1590 | {0x1e, 0x00000001}, {0x1f, 0x00080000}, |
| 1591 | {0x00, 0x00033e70}, |
| 1592 | {0xff, 0xffffffff} |
| 1593 | }; |
| 1594 | |
| 1595 | static struct rtl8xxxu_rfregval rtl8192eu_radiob_init_table[] = { |
| 1596 | {0x7f, 0x00000082}, {0x81, 0x0003fc00}, |
| 1597 | {0x00, 0x00030000}, {0x08, 0x00008400}, |
| 1598 | {0x18, 0x00000407}, {0x19, 0x00000012}, |
| 1599 | {0x1b, 0x00000064}, {0x1e, 0x00080009}, |
| 1600 | {0x1f, 0x00000880}, {0x2f, 0x0001a060}, |
| 1601 | {0x3f, 0x00000000}, {0x42, 0x000060c0}, |
| 1602 | {0x57, 0x000d0000}, {0x58, 0x000be180}, |
| 1603 | {0x67, 0x00001552}, {0x7f, 0x00000082}, |
| 1604 | {0x81, 0x0003f000}, {0x83, 0x00000000}, |
| 1605 | {0xdf, 0x00000180}, {0xef, 0x000001a0}, |
| 1606 | {0x51, 0x00069545}, {0x52, 0x0007e42e}, |
| 1607 | {0x53, 0x00000071}, {0x56, 0x00051ff3}, |
| 1608 | {0x35, 0x000000a8}, {0x35, 0x000001e0}, |
| 1609 | {0x35, 0x000002a8}, {0x36, 0x00001ca8}, |
| 1610 | {0x36, 0x00009c24}, {0x36, 0x00011c24}, |
| 1611 | {0x36, 0x00019c24}, {0x18, 0x00000c07}, |
| 1612 | {0x5a, 0x00048000}, {0x19, 0x000739d0}, |
| 1613 | #ifdef EXT_PA_8192EU |
| 1614 | /* External PA or external LNA */ |
| 1615 | {0x34, 0x0000a093}, {0x34, 0x0000908f}, |
| 1616 | {0x34, 0x0000808c}, {0x34, 0x0000704d}, |
| 1617 | {0x34, 0x0000604a}, {0x34, 0x00005047}, |
| 1618 | {0x34, 0x0000400a}, {0x34, 0x00003007}, |
| 1619 | {0x34, 0x00002004}, {0x34, 0x00001001}, |
| 1620 | {0x34, 0x00000000}, |
| 1621 | #else |
| 1622 | {0x34, 0x0000add7}, {0x34, 0x00009dd4}, |
| 1623 | {0x34, 0x00008dd1}, {0x34, 0x00007dce}, |
| 1624 | {0x34, 0x00006dcb}, {0x34, 0x00005dc8}, |
| 1625 | {0x34, 0x00004dc5}, {0x34, 0x000034cc}, |
| 1626 | {0x34, 0x0000244f}, {0x34, 0x0000144c}, |
| 1627 | {0x34, 0x00000014}, |
| 1628 | #endif |
| 1629 | {0x00, 0x00030159}, {0x84, 0x00068180}, |
| 1630 | {0x86, 0x000000ce}, {0x87, 0x00048a00}, |
| 1631 | {0x8e, 0x00065540}, {0x8f, 0x00088000}, |
| 1632 | {0xef, 0x000020a0}, |
| 1633 | #ifdef EXT_PA_8192EU |
| 1634 | /* External PA or external LNA */ |
| 1635 | {0x3b, 0x000f07b0}, |
| 1636 | #else |
| 1637 | {0x3b, 0x000f02b0}, |
| 1638 | #endif |
| 1639 | |
| 1640 | {0x3b, 0x000ef7b0}, {0x3b, 0x000d4fb0}, |
| 1641 | {0x3b, 0x000cf060}, {0x3b, 0x000b0090}, |
| 1642 | {0x3b, 0x000a0080}, {0x3b, 0x00090080}, |
| 1643 | {0x3b, 0x0008f780}, |
| 1644 | #ifdef EXT_PA_8192EU |
| 1645 | /* External PA or external LNA */ |
| 1646 | {0x3b, 0x000787b0}, |
| 1647 | #else |
| 1648 | {0x3b, 0x00078730}, |
| 1649 | #endif |
| 1650 | {0x3b, 0x00060fb0}, {0x3b, 0x0005ffa0}, |
| 1651 | {0x3b, 0x00040620}, {0x3b, 0x00037090}, |
| 1652 | {0x3b, 0x00020080}, {0x3b, 0x0001f060}, |
| 1653 | {0x3b, 0x0000ffb0}, {0xef, 0x000000a0}, |
| 1654 | {0x00, 0x00010159}, {0xfe, 0x00000000}, |
| 1655 | {0xfe, 0x00000000}, {0xfe, 0x00000000}, |
| 1656 | {0xfe, 0x00000000}, {0x1e, 0x00000001}, |
| 1657 | {0x1f, 0x00080000}, {0x00, 0x00033e70}, |
| 1658 | {0xff, 0xffffffff} |
| 1659 | }; |
| 1660 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1661 | static struct rtl8xxxu_rfregs rtl8xxxu_rfregs[] = { |
| 1662 | { /* RF_A */ |
| 1663 | .hssiparm1 = REG_FPGA0_XA_HSSI_PARM1, |
| 1664 | .hssiparm2 = REG_FPGA0_XA_HSSI_PARM2, |
| 1665 | .lssiparm = REG_FPGA0_XA_LSSI_PARM, |
| 1666 | .hspiread = REG_HSPI_XA_READBACK, |
| 1667 | .lssiread = REG_FPGA0_XA_LSSI_READBACK, |
| 1668 | .rf_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL, |
| 1669 | }, |
| 1670 | { /* RF_B */ |
| 1671 | .hssiparm1 = REG_FPGA0_XB_HSSI_PARM1, |
| 1672 | .hssiparm2 = REG_FPGA0_XB_HSSI_PARM2, |
| 1673 | .lssiparm = REG_FPGA0_XB_LSSI_PARM, |
| 1674 | .hspiread = REG_HSPI_XB_READBACK, |
| 1675 | .lssiread = REG_FPGA0_XB_LSSI_READBACK, |
| 1676 | .rf_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL, |
| 1677 | }, |
| 1678 | }; |
| 1679 | |
| 1680 | static const u32 rtl8723au_iqk_phy_iq_bb_reg[RTL8XXXU_BB_REGS] = { |
| 1681 | REG_OFDM0_XA_RX_IQ_IMBALANCE, |
| 1682 | REG_OFDM0_XB_RX_IQ_IMBALANCE, |
| 1683 | REG_OFDM0_ENERGY_CCA_THRES, |
| 1684 | REG_OFDM0_AGCR_SSI_TABLE, |
| 1685 | REG_OFDM0_XA_TX_IQ_IMBALANCE, |
| 1686 | REG_OFDM0_XB_TX_IQ_IMBALANCE, |
| 1687 | REG_OFDM0_XC_TX_AFE, |
| 1688 | REG_OFDM0_XD_TX_AFE, |
| 1689 | REG_OFDM0_RX_IQ_EXT_ANTA |
| 1690 | }; |
| 1691 | |
| 1692 | static u8 rtl8xxxu_read8(struct rtl8xxxu_priv *priv, u16 addr) |
| 1693 | { |
| 1694 | struct usb_device *udev = priv->udev; |
| 1695 | int len; |
| 1696 | u8 data; |
| 1697 | |
| 1698 | mutex_lock(&priv->usb_buf_mutex); |
| 1699 | len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
| 1700 | REALTEK_USB_CMD_REQ, REALTEK_USB_READ, |
| 1701 | addr, 0, &priv->usb_buf.val8, sizeof(u8), |
| 1702 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1703 | data = priv->usb_buf.val8; |
| 1704 | mutex_unlock(&priv->usb_buf_mutex); |
| 1705 | |
| 1706 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ) |
| 1707 | dev_info(&udev->dev, "%s(%04x) = 0x%02x, len %i\n", |
| 1708 | __func__, addr, data, len); |
| 1709 | return data; |
| 1710 | } |
| 1711 | |
| 1712 | static u16 rtl8xxxu_read16(struct rtl8xxxu_priv *priv, u16 addr) |
| 1713 | { |
| 1714 | struct usb_device *udev = priv->udev; |
| 1715 | int len; |
| 1716 | u16 data; |
| 1717 | |
| 1718 | mutex_lock(&priv->usb_buf_mutex); |
| 1719 | len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
| 1720 | REALTEK_USB_CMD_REQ, REALTEK_USB_READ, |
| 1721 | addr, 0, &priv->usb_buf.val16, sizeof(u16), |
| 1722 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1723 | data = le16_to_cpu(priv->usb_buf.val16); |
| 1724 | mutex_unlock(&priv->usb_buf_mutex); |
| 1725 | |
| 1726 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ) |
| 1727 | dev_info(&udev->dev, "%s(%04x) = 0x%04x, len %i\n", |
| 1728 | __func__, addr, data, len); |
| 1729 | return data; |
| 1730 | } |
| 1731 | |
| 1732 | static u32 rtl8xxxu_read32(struct rtl8xxxu_priv *priv, u16 addr) |
| 1733 | { |
| 1734 | struct usb_device *udev = priv->udev; |
| 1735 | int len; |
| 1736 | u32 data; |
| 1737 | |
| 1738 | mutex_lock(&priv->usb_buf_mutex); |
| 1739 | len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
| 1740 | REALTEK_USB_CMD_REQ, REALTEK_USB_READ, |
| 1741 | addr, 0, &priv->usb_buf.val32, sizeof(u32), |
| 1742 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1743 | data = le32_to_cpu(priv->usb_buf.val32); |
| 1744 | mutex_unlock(&priv->usb_buf_mutex); |
| 1745 | |
| 1746 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ) |
| 1747 | dev_info(&udev->dev, "%s(%04x) = 0x%08x, len %i\n", |
| 1748 | __func__, addr, data, len); |
| 1749 | return data; |
| 1750 | } |
| 1751 | |
| 1752 | static int rtl8xxxu_write8(struct rtl8xxxu_priv *priv, u16 addr, u8 val) |
| 1753 | { |
| 1754 | struct usb_device *udev = priv->udev; |
| 1755 | int ret; |
| 1756 | |
| 1757 | mutex_lock(&priv->usb_buf_mutex); |
| 1758 | priv->usb_buf.val8 = val; |
| 1759 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 1760 | REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE, |
| 1761 | addr, 0, &priv->usb_buf.val8, sizeof(u8), |
| 1762 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1763 | |
| 1764 | mutex_unlock(&priv->usb_buf_mutex); |
| 1765 | |
| 1766 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE) |
| 1767 | dev_info(&udev->dev, "%s(%04x) = 0x%02x\n", |
| 1768 | __func__, addr, val); |
| 1769 | return ret; |
| 1770 | } |
| 1771 | |
| 1772 | static int rtl8xxxu_write16(struct rtl8xxxu_priv *priv, u16 addr, u16 val) |
| 1773 | { |
| 1774 | struct usb_device *udev = priv->udev; |
| 1775 | int ret; |
| 1776 | |
| 1777 | mutex_lock(&priv->usb_buf_mutex); |
| 1778 | priv->usb_buf.val16 = cpu_to_le16(val); |
| 1779 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 1780 | REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE, |
| 1781 | addr, 0, &priv->usb_buf.val16, sizeof(u16), |
| 1782 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1783 | mutex_unlock(&priv->usb_buf_mutex); |
| 1784 | |
| 1785 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE) |
| 1786 | dev_info(&udev->dev, "%s(%04x) = 0x%04x\n", |
| 1787 | __func__, addr, val); |
| 1788 | return ret; |
| 1789 | } |
| 1790 | |
| 1791 | static int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val) |
| 1792 | { |
| 1793 | struct usb_device *udev = priv->udev; |
| 1794 | int ret; |
| 1795 | |
| 1796 | mutex_lock(&priv->usb_buf_mutex); |
| 1797 | priv->usb_buf.val32 = cpu_to_le32(val); |
| 1798 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 1799 | REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE, |
| 1800 | addr, 0, &priv->usb_buf.val32, sizeof(u32), |
| 1801 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1802 | mutex_unlock(&priv->usb_buf_mutex); |
| 1803 | |
| 1804 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE) |
| 1805 | dev_info(&udev->dev, "%s(%04x) = 0x%08x\n", |
| 1806 | __func__, addr, val); |
| 1807 | return ret; |
| 1808 | } |
| 1809 | |
| 1810 | static int |
| 1811 | rtl8xxxu_writeN(struct rtl8xxxu_priv *priv, u16 addr, u8 *buf, u16 len) |
| 1812 | { |
| 1813 | struct usb_device *udev = priv->udev; |
| 1814 | int blocksize = priv->fops->writeN_block_size; |
| 1815 | int ret, i, count, remainder; |
| 1816 | |
| 1817 | count = len / blocksize; |
| 1818 | remainder = len % blocksize; |
| 1819 | |
| 1820 | for (i = 0; i < count; i++) { |
| 1821 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 1822 | REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE, |
| 1823 | addr, 0, buf, blocksize, |
| 1824 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1825 | if (ret != blocksize) |
| 1826 | goto write_error; |
| 1827 | |
| 1828 | addr += blocksize; |
| 1829 | buf += blocksize; |
| 1830 | } |
| 1831 | |
| 1832 | if (remainder) { |
| 1833 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 1834 | REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE, |
| 1835 | addr, 0, buf, remainder, |
| 1836 | RTW_USB_CONTROL_MSG_TIMEOUT); |
| 1837 | if (ret != remainder) |
| 1838 | goto write_error; |
| 1839 | } |
| 1840 | |
| 1841 | return len; |
| 1842 | |
| 1843 | write_error: |
| 1844 | dev_info(&udev->dev, |
| 1845 | "%s: Failed to write block at addr: %04x size: %04x\n", |
| 1846 | __func__, addr, blocksize); |
| 1847 | return -EAGAIN; |
| 1848 | } |
| 1849 | |
| 1850 | static u32 rtl8xxxu_read_rfreg(struct rtl8xxxu_priv *priv, |
| 1851 | enum rtl8xxxu_rfpath path, u8 reg) |
| 1852 | { |
| 1853 | u32 hssia, val32, retval; |
| 1854 | |
| 1855 | hssia = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2); |
| 1856 | if (path != RF_A) |
| 1857 | val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm2); |
| 1858 | else |
| 1859 | val32 = hssia; |
| 1860 | |
| 1861 | val32 &= ~FPGA0_HSSI_PARM2_ADDR_MASK; |
| 1862 | val32 |= (reg << FPGA0_HSSI_PARM2_ADDR_SHIFT); |
| 1863 | val32 |= FPGA0_HSSI_PARM2_EDGE_READ; |
| 1864 | hssia &= ~FPGA0_HSSI_PARM2_EDGE_READ; |
| 1865 | rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia); |
| 1866 | |
| 1867 | udelay(10); |
| 1868 | |
| 1869 | rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].hssiparm2, val32); |
| 1870 | udelay(100); |
| 1871 | |
| 1872 | hssia |= FPGA0_HSSI_PARM2_EDGE_READ; |
| 1873 | rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia); |
| 1874 | udelay(10); |
| 1875 | |
| 1876 | val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm1); |
| 1877 | if (val32 & FPGA0_HSSI_PARM1_PI) |
| 1878 | retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hspiread); |
| 1879 | else |
| 1880 | retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].lssiread); |
| 1881 | |
| 1882 | retval &= 0xfffff; |
| 1883 | |
| 1884 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_READ) |
| 1885 | dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n", |
| 1886 | __func__, reg, retval); |
| 1887 | return retval; |
| 1888 | } |
| 1889 | |
Jes Sorensen | 22a31d4 | 2016-02-29 17:04:15 -0500 | [diff] [blame] | 1890 | /* |
| 1891 | * The RTL8723BU driver indicates that registers 0xb2 and 0xb6 can |
| 1892 | * have write issues in high temperature conditions. We may have to |
| 1893 | * retry writing them. |
| 1894 | */ |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1895 | static int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv *priv, |
| 1896 | enum rtl8xxxu_rfpath path, u8 reg, u32 data) |
| 1897 | { |
| 1898 | int ret, retval; |
Jes Sorensen | 2949b9e | 2016-04-07 14:19:25 -0400 | [diff] [blame^] | 1899 | u32 dataaddr, val32; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1900 | |
| 1901 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_WRITE) |
| 1902 | dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n", |
| 1903 | __func__, reg, data); |
| 1904 | |
| 1905 | data &= FPGA0_LSSI_PARM_DATA_MASK; |
| 1906 | dataaddr = (reg << FPGA0_LSSI_PARM_ADDR_SHIFT) | data; |
| 1907 | |
Jes Sorensen | 2949b9e | 2016-04-07 14:19:25 -0400 | [diff] [blame^] | 1908 | if (priv->rtl_chip == RTL8192E) { |
| 1909 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE); |
| 1910 | val32 &= ~0x20000; |
| 1911 | rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32); |
| 1912 | } |
| 1913 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1914 | /* Use XB for path B */ |
| 1915 | ret = rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].lssiparm, dataaddr); |
| 1916 | if (ret != sizeof(dataaddr)) |
| 1917 | retval = -EIO; |
| 1918 | else |
| 1919 | retval = 0; |
| 1920 | |
| 1921 | udelay(1); |
| 1922 | |
Jes Sorensen | 2949b9e | 2016-04-07 14:19:25 -0400 | [diff] [blame^] | 1923 | if (priv->rtl_chip == RTL8192E) { |
| 1924 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE); |
| 1925 | val32 |= 0x20000; |
| 1926 | rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32); |
| 1927 | } |
| 1928 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1929 | return retval; |
| 1930 | } |
| 1931 | |
Jes Sorensen | 8da9157 | 2016-02-29 17:04:29 -0500 | [diff] [blame] | 1932 | static int rtl8723a_h2c_cmd(struct rtl8xxxu_priv *priv, |
| 1933 | struct h2c_cmd *h2c, int len) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1934 | { |
| 1935 | struct device *dev = &priv->udev->dev; |
| 1936 | int mbox_nr, retry, retval = 0; |
| 1937 | int mbox_reg, mbox_ext_reg; |
| 1938 | u8 val8; |
| 1939 | |
| 1940 | mutex_lock(&priv->h2c_mutex); |
| 1941 | |
| 1942 | mbox_nr = priv->next_mbox; |
| 1943 | mbox_reg = REG_HMBOX_0 + (mbox_nr * 4); |
Jes Sorensen | ed35d09 | 2016-02-29 17:04:19 -0500 | [diff] [blame] | 1944 | mbox_ext_reg = priv->fops->mbox_ext_reg + |
| 1945 | (mbox_nr * priv->fops->mbox_ext_width); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1946 | |
| 1947 | /* |
| 1948 | * MBOX ready? |
| 1949 | */ |
| 1950 | retry = 100; |
| 1951 | do { |
| 1952 | val8 = rtl8xxxu_read8(priv, REG_HMTFR); |
| 1953 | if (!(val8 & BIT(mbox_nr))) |
| 1954 | break; |
| 1955 | } while (retry--); |
| 1956 | |
| 1957 | if (!retry) { |
Jes Sorensen | c7a5a19 | 2016-02-29 17:04:30 -0500 | [diff] [blame] | 1958 | dev_info(dev, "%s: Mailbox busy\n", __func__); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1959 | retval = -EBUSY; |
| 1960 | goto error; |
| 1961 | } |
| 1962 | |
| 1963 | /* |
| 1964 | * Need to swap as it's being swapped again by rtl8xxxu_write16/32() |
| 1965 | */ |
Jes Sorensen | 8da9157 | 2016-02-29 17:04:29 -0500 | [diff] [blame] | 1966 | if (len > sizeof(u32)) { |
Jes Sorensen | ed35d09 | 2016-02-29 17:04:19 -0500 | [diff] [blame] | 1967 | if (priv->fops->mbox_ext_width == 4) { |
| 1968 | rtl8xxxu_write32(priv, mbox_ext_reg, |
| 1969 | le32_to_cpu(h2c->raw_wide.ext)); |
| 1970 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C) |
| 1971 | dev_info(dev, "H2C_EXT %08x\n", |
| 1972 | le32_to_cpu(h2c->raw_wide.ext)); |
| 1973 | } else { |
| 1974 | rtl8xxxu_write16(priv, mbox_ext_reg, |
| 1975 | le16_to_cpu(h2c->raw.ext)); |
| 1976 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C) |
| 1977 | dev_info(dev, "H2C_EXT %04x\n", |
| 1978 | le16_to_cpu(h2c->raw.ext)); |
| 1979 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 1980 | } |
| 1981 | rtl8xxxu_write32(priv, mbox_reg, le32_to_cpu(h2c->raw.data)); |
| 1982 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C) |
| 1983 | dev_info(dev, "H2C %08x\n", le32_to_cpu(h2c->raw.data)); |
| 1984 | |
| 1985 | priv->next_mbox = (mbox_nr + 1) % H2C_MAX_MBOX; |
| 1986 | |
| 1987 | error: |
| 1988 | mutex_unlock(&priv->h2c_mutex); |
| 1989 | return retval; |
| 1990 | } |
| 1991 | |
Jes Sorensen | 394f1bd | 2016-02-29 17:04:49 -0500 | [diff] [blame] | 1992 | static void rtl8723bu_write_btreg(struct rtl8xxxu_priv *priv, u8 reg, u8 data) |
| 1993 | { |
| 1994 | struct h2c_cmd h2c; |
| 1995 | int reqnum = 0; |
| 1996 | |
| 1997 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 1998 | h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER; |
| 1999 | h2c.bt_mp_oper.operreq = 0 | (reqnum << 4); |
| 2000 | h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE; |
| 2001 | h2c.bt_mp_oper.data = data; |
| 2002 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper)); |
| 2003 | |
| 2004 | reqnum++; |
| 2005 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 2006 | h2c.bt_mp_oper.cmd = H2C_8723B_BT_MP_OPER; |
| 2007 | h2c.bt_mp_oper.operreq = 0 | (reqnum << 4); |
| 2008 | h2c.bt_mp_oper.opcode = BT_MP_OP_WRITE_REG_VALUE; |
| 2009 | h2c.bt_mp_oper.addr = reg; |
| 2010 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_mp_oper)); |
| 2011 | } |
| 2012 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2013 | static void rtl8723a_enable_rf(struct rtl8xxxu_priv *priv) |
| 2014 | { |
| 2015 | u8 val8; |
| 2016 | u32 val32; |
| 2017 | |
| 2018 | val8 = rtl8xxxu_read8(priv, REG_SPS0_CTRL); |
| 2019 | val8 |= BIT(0) | BIT(3); |
| 2020 | rtl8xxxu_write8(priv, REG_SPS0_CTRL, val8); |
| 2021 | |
| 2022 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM); |
| 2023 | val32 &= ~(BIT(4) | BIT(5)); |
| 2024 | val32 |= BIT(3); |
| 2025 | if (priv->rf_paths == 2) { |
| 2026 | val32 &= ~(BIT(20) | BIT(21)); |
| 2027 | val32 |= BIT(19); |
| 2028 | } |
| 2029 | rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32); |
| 2030 | |
| 2031 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE); |
| 2032 | val32 &= ~OFDM_RF_PATH_TX_MASK; |
| 2033 | if (priv->tx_paths == 2) |
| 2034 | val32 |= OFDM_RF_PATH_TX_A | OFDM_RF_PATH_TX_B; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2035 | else if (priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2036 | val32 |= OFDM_RF_PATH_TX_B; |
| 2037 | else |
| 2038 | val32 |= OFDM_RF_PATH_TX_A; |
| 2039 | rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32); |
| 2040 | |
| 2041 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 2042 | val32 &= ~FPGA_RF_MODE_JAPAN; |
| 2043 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 2044 | |
| 2045 | if (priv->rf_paths == 2) |
| 2046 | rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x63db25a0); |
| 2047 | else |
| 2048 | rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x631b25a0); |
| 2049 | |
| 2050 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x32d95); |
| 2051 | if (priv->rf_paths == 2) |
| 2052 | rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x32d95); |
| 2053 | |
| 2054 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00); |
| 2055 | } |
| 2056 | |
| 2057 | static void rtl8723a_disable_rf(struct rtl8xxxu_priv *priv) |
| 2058 | { |
| 2059 | u8 sps0; |
| 2060 | u32 val32; |
| 2061 | |
| 2062 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); |
| 2063 | |
| 2064 | sps0 = rtl8xxxu_read8(priv, REG_SPS0_CTRL); |
| 2065 | |
| 2066 | /* RF RX code for preamble power saving */ |
| 2067 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM); |
| 2068 | val32 &= ~(BIT(3) | BIT(4) | BIT(5)); |
| 2069 | if (priv->rf_paths == 2) |
| 2070 | val32 &= ~(BIT(19) | BIT(20) | BIT(21)); |
| 2071 | rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32); |
| 2072 | |
| 2073 | /* Disable TX for four paths */ |
| 2074 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE); |
| 2075 | val32 &= ~OFDM_RF_PATH_TX_MASK; |
| 2076 | rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32); |
| 2077 | |
| 2078 | /* Enable power saving */ |
| 2079 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 2080 | val32 |= FPGA_RF_MODE_JAPAN; |
| 2081 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 2082 | |
| 2083 | /* AFE control register to power down bits [30:22] */ |
| 2084 | if (priv->rf_paths == 2) |
| 2085 | rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x00db25a0); |
| 2086 | else |
| 2087 | rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x001b25a0); |
| 2088 | |
| 2089 | /* Power down RF module */ |
| 2090 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0); |
| 2091 | if (priv->rf_paths == 2) |
| 2092 | rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0); |
| 2093 | |
| 2094 | sps0 &= ~(BIT(0) | BIT(3)); |
| 2095 | rtl8xxxu_write8(priv, REG_SPS0_CTRL, sps0); |
| 2096 | } |
| 2097 | |
| 2098 | |
| 2099 | static void rtl8723a_stop_tx_beacon(struct rtl8xxxu_priv *priv) |
| 2100 | { |
| 2101 | u8 val8; |
| 2102 | |
| 2103 | val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL + 2); |
| 2104 | val8 &= ~BIT(6); |
| 2105 | rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8); |
| 2106 | |
| 2107 | rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x64); |
| 2108 | val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2); |
| 2109 | val8 &= ~BIT(0); |
| 2110 | rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8); |
| 2111 | } |
| 2112 | |
| 2113 | |
| 2114 | /* |
| 2115 | * The rtl8723a has 3 channel groups for it's efuse settings. It only |
| 2116 | * supports the 2.4GHz band, so channels 1 - 14: |
| 2117 | * group 0: channels 1 - 3 |
| 2118 | * group 1: channels 4 - 9 |
| 2119 | * group 2: channels 10 - 14 |
| 2120 | * |
| 2121 | * Note: We index from 0 in the code |
| 2122 | */ |
| 2123 | static int rtl8723a_channel_to_group(int channel) |
| 2124 | { |
| 2125 | int group; |
| 2126 | |
| 2127 | if (channel < 4) |
| 2128 | group = 0; |
| 2129 | else if (channel < 10) |
| 2130 | group = 1; |
| 2131 | else |
| 2132 | group = 2; |
| 2133 | |
| 2134 | return group; |
| 2135 | } |
| 2136 | |
Jes Sorensen | 9e24772 | 2016-04-07 14:19:23 -0400 | [diff] [blame] | 2137 | /* |
| 2138 | * Valid for rtl8723bu and rtl8192eu |
| 2139 | */ |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 2140 | static int rtl8723b_channel_to_group(int channel) |
| 2141 | { |
| 2142 | int group; |
| 2143 | |
| 2144 | if (channel < 3) |
| 2145 | group = 0; |
| 2146 | else if (channel < 6) |
| 2147 | group = 1; |
| 2148 | else if (channel < 9) |
| 2149 | group = 2; |
| 2150 | else if (channel < 12) |
| 2151 | group = 3; |
| 2152 | else |
| 2153 | group = 4; |
| 2154 | |
| 2155 | return group; |
| 2156 | } |
| 2157 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2158 | static void rtl8723au_config_channel(struct ieee80211_hw *hw) |
| 2159 | { |
| 2160 | struct rtl8xxxu_priv *priv = hw->priv; |
| 2161 | u32 val32, rsr; |
| 2162 | u8 val8, opmode; |
| 2163 | bool ht = true; |
| 2164 | int sec_ch_above, channel; |
| 2165 | int i; |
| 2166 | |
| 2167 | opmode = rtl8xxxu_read8(priv, REG_BW_OPMODE); |
| 2168 | rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET); |
| 2169 | channel = hw->conf.chandef.chan->hw_value; |
| 2170 | |
| 2171 | switch (hw->conf.chandef.width) { |
| 2172 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2173 | ht = false; |
| 2174 | case NL80211_CHAN_WIDTH_20: |
| 2175 | opmode |= BW_OPMODE_20MHZ; |
| 2176 | rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode); |
| 2177 | |
| 2178 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 2179 | val32 &= ~FPGA_RF_MODE; |
| 2180 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 2181 | |
| 2182 | val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE); |
| 2183 | val32 &= ~FPGA_RF_MODE; |
| 2184 | rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32); |
| 2185 | |
| 2186 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2); |
| 2187 | val32 |= FPGA0_ANALOG2_20MHZ; |
| 2188 | rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32); |
| 2189 | break; |
| 2190 | case NL80211_CHAN_WIDTH_40: |
| 2191 | if (hw->conf.chandef.center_freq1 > |
| 2192 | hw->conf.chandef.chan->center_freq) { |
| 2193 | sec_ch_above = 1; |
| 2194 | channel += 2; |
| 2195 | } else { |
| 2196 | sec_ch_above = 0; |
| 2197 | channel -= 2; |
| 2198 | } |
| 2199 | |
| 2200 | opmode &= ~BW_OPMODE_20MHZ; |
| 2201 | rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode); |
| 2202 | rsr &= ~RSR_RSC_BANDWIDTH_40M; |
| 2203 | if (sec_ch_above) |
| 2204 | rsr |= RSR_RSC_UPPER_SUB_CHANNEL; |
| 2205 | else |
| 2206 | rsr |= RSR_RSC_LOWER_SUB_CHANNEL; |
| 2207 | rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, rsr); |
| 2208 | |
| 2209 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 2210 | val32 |= FPGA_RF_MODE; |
| 2211 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 2212 | |
| 2213 | val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE); |
| 2214 | val32 |= FPGA_RF_MODE; |
| 2215 | rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32); |
| 2216 | |
| 2217 | /* |
| 2218 | * Set Control channel to upper or lower. These settings |
| 2219 | * are required only for 40MHz |
| 2220 | */ |
| 2221 | val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM); |
| 2222 | val32 &= ~CCK0_SIDEBAND; |
| 2223 | if (!sec_ch_above) |
| 2224 | val32 |= CCK0_SIDEBAND; |
| 2225 | rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32); |
| 2226 | |
| 2227 | val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF); |
| 2228 | val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */ |
| 2229 | if (sec_ch_above) |
| 2230 | val32 |= OFDM_LSTF_PRIME_CH_LOW; |
| 2231 | else |
| 2232 | val32 |= OFDM_LSTF_PRIME_CH_HIGH; |
| 2233 | rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32); |
| 2234 | |
| 2235 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2); |
| 2236 | val32 &= ~FPGA0_ANALOG2_20MHZ; |
| 2237 | rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32); |
| 2238 | |
| 2239 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE); |
| 2240 | val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL); |
| 2241 | if (sec_ch_above) |
| 2242 | val32 |= FPGA0_PS_UPPER_CHANNEL; |
| 2243 | else |
| 2244 | val32 |= FPGA0_PS_LOWER_CHANNEL; |
| 2245 | rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32); |
| 2246 | break; |
| 2247 | |
| 2248 | default: |
| 2249 | break; |
| 2250 | } |
| 2251 | |
| 2252 | for (i = RF_A; i < priv->rf_paths; i++) { |
| 2253 | val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG); |
| 2254 | val32 &= ~MODE_AG_CHANNEL_MASK; |
| 2255 | val32 |= channel; |
| 2256 | rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32); |
| 2257 | } |
| 2258 | |
| 2259 | if (ht) |
| 2260 | val8 = 0x0e; |
| 2261 | else |
| 2262 | val8 = 0x0a; |
| 2263 | |
| 2264 | rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8); |
| 2265 | rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8); |
| 2266 | |
| 2267 | rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808); |
| 2268 | rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a); |
| 2269 | |
| 2270 | for (i = RF_A; i < priv->rf_paths; i++) { |
| 2271 | val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG); |
| 2272 | if (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40) |
| 2273 | val32 &= ~MODE_AG_CHANNEL_20MHZ; |
| 2274 | else |
| 2275 | val32 |= MODE_AG_CHANNEL_20MHZ; |
| 2276 | rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32); |
| 2277 | } |
| 2278 | } |
| 2279 | |
Jes Sorensen | c3f9506 | 2016-02-29 17:04:40 -0500 | [diff] [blame] | 2280 | static void rtl8723bu_config_channel(struct ieee80211_hw *hw) |
| 2281 | { |
| 2282 | struct rtl8xxxu_priv *priv = hw->priv; |
| 2283 | u32 val32, rsr; |
Jes Sorensen | 368633c | 2016-02-29 17:04:42 -0500 | [diff] [blame] | 2284 | u8 val8, subchannel; |
Jes Sorensen | c3f9506 | 2016-02-29 17:04:40 -0500 | [diff] [blame] | 2285 | u16 rf_mode_bw; |
| 2286 | bool ht = true; |
| 2287 | int sec_ch_above, channel; |
| 2288 | int i; |
| 2289 | |
| 2290 | rf_mode_bw = rtl8xxxu_read16(priv, REG_WMAC_TRXPTCL_CTL); |
| 2291 | rf_mode_bw &= ~WMAC_TRXPTCL_CTL_BW_MASK; |
| 2292 | rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET); |
| 2293 | channel = hw->conf.chandef.chan->hw_value; |
| 2294 | |
| 2295 | /* Hack */ |
| 2296 | subchannel = 0; |
| 2297 | |
| 2298 | switch (hw->conf.chandef.width) { |
| 2299 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2300 | ht = false; |
| 2301 | case NL80211_CHAN_WIDTH_20: |
| 2302 | rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_20; |
| 2303 | subchannel = 0; |
| 2304 | |
| 2305 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 2306 | val32 &= ~FPGA_RF_MODE; |
| 2307 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 2308 | |
| 2309 | val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE); |
| 2310 | val32 &= ~FPGA_RF_MODE; |
| 2311 | rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32); |
| 2312 | |
| 2313 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_TX_PSDO_NOISE_WEIGHT); |
| 2314 | val32 &= ~(BIT(30) | BIT(31)); |
| 2315 | rtl8xxxu_write32(priv, REG_OFDM0_TX_PSDO_NOISE_WEIGHT, val32); |
| 2316 | |
| 2317 | break; |
| 2318 | case NL80211_CHAN_WIDTH_40: |
| 2319 | rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_40; |
| 2320 | |
| 2321 | if (hw->conf.chandef.center_freq1 > |
| 2322 | hw->conf.chandef.chan->center_freq) { |
| 2323 | sec_ch_above = 1; |
| 2324 | channel += 2; |
| 2325 | } else { |
| 2326 | sec_ch_above = 0; |
| 2327 | channel -= 2; |
| 2328 | } |
| 2329 | |
| 2330 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 2331 | val32 |= FPGA_RF_MODE; |
| 2332 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 2333 | |
| 2334 | val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE); |
| 2335 | val32 |= FPGA_RF_MODE; |
| 2336 | rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32); |
| 2337 | |
| 2338 | /* |
| 2339 | * Set Control channel to upper or lower. These settings |
| 2340 | * are required only for 40MHz |
| 2341 | */ |
| 2342 | val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM); |
| 2343 | val32 &= ~CCK0_SIDEBAND; |
| 2344 | if (!sec_ch_above) |
| 2345 | val32 |= CCK0_SIDEBAND; |
| 2346 | rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32); |
| 2347 | |
| 2348 | val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF); |
| 2349 | val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */ |
| 2350 | if (sec_ch_above) |
| 2351 | val32 |= OFDM_LSTF_PRIME_CH_LOW; |
| 2352 | else |
| 2353 | val32 |= OFDM_LSTF_PRIME_CH_HIGH; |
| 2354 | rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32); |
| 2355 | |
| 2356 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE); |
| 2357 | val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL); |
| 2358 | if (sec_ch_above) |
| 2359 | val32 |= FPGA0_PS_UPPER_CHANNEL; |
| 2360 | else |
| 2361 | val32 |= FPGA0_PS_LOWER_CHANNEL; |
| 2362 | rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32); |
| 2363 | break; |
| 2364 | case NL80211_CHAN_WIDTH_80: |
| 2365 | rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_80; |
| 2366 | break; |
| 2367 | default: |
| 2368 | break; |
| 2369 | } |
| 2370 | |
| 2371 | for (i = RF_A; i < priv->rf_paths; i++) { |
| 2372 | val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG); |
| 2373 | val32 &= ~MODE_AG_CHANNEL_MASK; |
| 2374 | val32 |= channel; |
| 2375 | rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32); |
| 2376 | } |
| 2377 | |
| 2378 | rtl8xxxu_write16(priv, REG_WMAC_TRXPTCL_CTL, rf_mode_bw); |
| 2379 | rtl8xxxu_write8(priv, REG_DATA_SUBCHANNEL, subchannel); |
| 2380 | |
| 2381 | if (ht) |
| 2382 | val8 = 0x0e; |
| 2383 | else |
| 2384 | val8 = 0x0a; |
| 2385 | |
| 2386 | rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8); |
| 2387 | rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8); |
| 2388 | |
| 2389 | rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808); |
| 2390 | rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a); |
| 2391 | |
| 2392 | for (i = RF_A; i < priv->rf_paths; i++) { |
| 2393 | val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG); |
| 2394 | val32 &= ~MODE_AG_BW_MASK; |
| 2395 | switch(hw->conf.chandef.width) { |
| 2396 | case NL80211_CHAN_WIDTH_80: |
| 2397 | val32 |= MODE_AG_BW_80MHZ_8723B; |
| 2398 | break; |
| 2399 | case NL80211_CHAN_WIDTH_40: |
| 2400 | val32 |= MODE_AG_BW_40MHZ_8723B; |
| 2401 | break; |
| 2402 | default: |
| 2403 | val32 |= MODE_AG_BW_20MHZ_8723B; |
| 2404 | break; |
| 2405 | } |
| 2406 | rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32); |
| 2407 | } |
| 2408 | } |
| 2409 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2410 | static void |
| 2411 | rtl8723a_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40) |
| 2412 | { |
| 2413 | u8 cck[RTL8723A_MAX_RF_PATHS], ofdm[RTL8723A_MAX_RF_PATHS]; |
| 2414 | u8 ofdmbase[RTL8723A_MAX_RF_PATHS], mcsbase[RTL8723A_MAX_RF_PATHS]; |
| 2415 | u32 val32, ofdm_a, ofdm_b, mcs_a, mcs_b; |
| 2416 | u8 val8; |
| 2417 | int group, i; |
| 2418 | |
| 2419 | group = rtl8723a_channel_to_group(channel); |
| 2420 | |
| 2421 | cck[0] = priv->cck_tx_power_index_A[group]; |
| 2422 | cck[1] = priv->cck_tx_power_index_B[group]; |
| 2423 | |
| 2424 | ofdm[0] = priv->ht40_1s_tx_power_index_A[group]; |
| 2425 | ofdm[1] = priv->ht40_1s_tx_power_index_B[group]; |
| 2426 | |
| 2427 | ofdmbase[0] = ofdm[0] + priv->ofdm_tx_power_index_diff[group].a; |
| 2428 | ofdmbase[1] = ofdm[1] + priv->ofdm_tx_power_index_diff[group].b; |
| 2429 | |
| 2430 | mcsbase[0] = ofdm[0]; |
| 2431 | mcsbase[1] = ofdm[1]; |
| 2432 | if (!ht40) { |
| 2433 | mcsbase[0] += priv->ht20_tx_power_index_diff[group].a; |
| 2434 | mcsbase[1] += priv->ht20_tx_power_index_diff[group].b; |
| 2435 | } |
| 2436 | |
| 2437 | if (priv->tx_paths > 1) { |
| 2438 | if (ofdm[0] > priv->ht40_2s_tx_power_index_diff[group].a) |
| 2439 | ofdm[0] -= priv->ht40_2s_tx_power_index_diff[group].a; |
| 2440 | if (ofdm[1] > priv->ht40_2s_tx_power_index_diff[group].b) |
| 2441 | ofdm[1] -= priv->ht40_2s_tx_power_index_diff[group].b; |
| 2442 | } |
| 2443 | |
| 2444 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL) |
| 2445 | dev_info(&priv->udev->dev, |
| 2446 | "%s: Setting TX power CCK A: %02x, " |
| 2447 | "CCK B: %02x, OFDM A: %02x, OFDM B: %02x\n", |
| 2448 | __func__, cck[0], cck[1], ofdm[0], ofdm[1]); |
| 2449 | |
| 2450 | for (i = 0; i < RTL8723A_MAX_RF_PATHS; i++) { |
| 2451 | if (cck[i] > RF6052_MAX_TX_PWR) |
| 2452 | cck[i] = RF6052_MAX_TX_PWR; |
| 2453 | if (ofdm[i] > RF6052_MAX_TX_PWR) |
| 2454 | ofdm[i] = RF6052_MAX_TX_PWR; |
| 2455 | } |
| 2456 | |
| 2457 | val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32); |
| 2458 | val32 &= 0xffff00ff; |
| 2459 | val32 |= (cck[0] << 8); |
| 2460 | rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32); |
| 2461 | |
| 2462 | val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11); |
| 2463 | val32 &= 0xff; |
| 2464 | val32 |= ((cck[0] << 8) | (cck[0] << 16) | (cck[0] << 24)); |
| 2465 | rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32); |
| 2466 | |
| 2467 | val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11); |
| 2468 | val32 &= 0xffffff00; |
| 2469 | val32 |= cck[1]; |
| 2470 | rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32); |
| 2471 | |
| 2472 | val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK1_55_MCS32); |
| 2473 | val32 &= 0xff; |
| 2474 | val32 |= ((cck[1] << 8) | (cck[1] << 16) | (cck[1] << 24)); |
| 2475 | rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK1_55_MCS32, val32); |
| 2476 | |
| 2477 | ofdm_a = ofdmbase[0] | ofdmbase[0] << 8 | |
| 2478 | ofdmbase[0] << 16 | ofdmbase[0] << 24; |
| 2479 | ofdm_b = ofdmbase[1] | ofdmbase[1] << 8 | |
| 2480 | ofdmbase[1] << 16 | ofdmbase[1] << 24; |
| 2481 | rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm_a); |
| 2482 | rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE18_06, ofdm_b); |
| 2483 | |
| 2484 | rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm_a); |
| 2485 | rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE54_24, ofdm_b); |
| 2486 | |
| 2487 | mcs_a = mcsbase[0] | mcsbase[0] << 8 | |
| 2488 | mcsbase[0] << 16 | mcsbase[0] << 24; |
| 2489 | mcs_b = mcsbase[1] | mcsbase[1] << 8 | |
| 2490 | mcsbase[1] << 16 | mcsbase[1] << 24; |
| 2491 | |
| 2492 | rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs_a); |
| 2493 | rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS03_MCS00, mcs_b); |
| 2494 | |
| 2495 | rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs_a); |
| 2496 | rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS07_MCS04, mcs_b); |
| 2497 | |
| 2498 | rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS11_MCS08, mcs_a); |
| 2499 | rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS11_MCS08, mcs_b); |
| 2500 | |
| 2501 | rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12, mcs_a); |
| 2502 | for (i = 0; i < 3; i++) { |
| 2503 | if (i != 2) |
| 2504 | val8 = (mcsbase[0] > 8) ? (mcsbase[0] - 8) : 0; |
| 2505 | else |
| 2506 | val8 = (mcsbase[0] > 6) ? (mcsbase[0] - 6) : 0; |
| 2507 | rtl8xxxu_write8(priv, REG_OFDM0_XC_TX_IQ_IMBALANCE + i, val8); |
| 2508 | } |
| 2509 | rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12, mcs_b); |
| 2510 | for (i = 0; i < 3; i++) { |
| 2511 | if (i != 2) |
| 2512 | val8 = (mcsbase[1] > 8) ? (mcsbase[1] - 8) : 0; |
| 2513 | else |
| 2514 | val8 = (mcsbase[1] > 6) ? (mcsbase[1] - 6) : 0; |
| 2515 | rtl8xxxu_write8(priv, REG_OFDM0_XD_TX_IQ_IMBALANCE + i, val8); |
| 2516 | } |
| 2517 | } |
| 2518 | |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 2519 | static void |
| 2520 | rtl8723b_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40) |
| 2521 | { |
Jes Sorensen | 1d3cc44 | 2016-02-29 17:05:24 -0500 | [diff] [blame] | 2522 | u32 val32, ofdm, mcs; |
| 2523 | u8 cck, ofdmbase, mcsbase; |
Jes Sorensen | 54bed43 | 2016-02-29 17:05:23 -0500 | [diff] [blame] | 2524 | int group, tx_idx; |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 2525 | |
Jes Sorensen | 54bed43 | 2016-02-29 17:05:23 -0500 | [diff] [blame] | 2526 | tx_idx = 0; |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 2527 | group = rtl8723b_channel_to_group(channel); |
Jes Sorensen | 54bed43 | 2016-02-29 17:05:23 -0500 | [diff] [blame] | 2528 | |
| 2529 | cck = priv->cck_tx_power_index_B[group]; |
| 2530 | val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32); |
| 2531 | val32 &= 0xffff00ff; |
| 2532 | val32 |= (cck << 8); |
| 2533 | rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32); |
| 2534 | |
| 2535 | val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11); |
| 2536 | val32 &= 0xff; |
| 2537 | val32 |= ((cck << 8) | (cck << 16) | (cck << 24)); |
| 2538 | rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32); |
| 2539 | |
| 2540 | ofdmbase = priv->ht40_1s_tx_power_index_B[group]; |
| 2541 | ofdmbase += priv->ofdm_tx_power_diff[tx_idx].b; |
| 2542 | ofdm = ofdmbase | ofdmbase << 8 | ofdmbase << 16 | ofdmbase << 24; |
| 2543 | |
| 2544 | rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm); |
| 2545 | rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm); |
Jes Sorensen | 1d3cc44 | 2016-02-29 17:05:24 -0500 | [diff] [blame] | 2546 | |
| 2547 | mcsbase = priv->ht40_1s_tx_power_index_B[group]; |
| 2548 | if (ht40) |
| 2549 | mcsbase += priv->ht40_tx_power_diff[tx_idx++].b; |
| 2550 | else |
| 2551 | mcsbase += priv->ht20_tx_power_diff[tx_idx++].b; |
| 2552 | mcs = mcsbase | mcsbase << 8 | mcsbase << 16 | mcsbase << 24; |
| 2553 | |
| 2554 | rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs); |
| 2555 | rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs); |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 2556 | } |
| 2557 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2558 | static void rtl8xxxu_set_linktype(struct rtl8xxxu_priv *priv, |
| 2559 | enum nl80211_iftype linktype) |
| 2560 | { |
Jes Sorensen | a26703f | 2016-02-03 13:39:56 -0500 | [diff] [blame] | 2561 | u8 val8; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2562 | |
Jes Sorensen | a26703f | 2016-02-03 13:39:56 -0500 | [diff] [blame] | 2563 | val8 = rtl8xxxu_read8(priv, REG_MSR); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2564 | val8 &= ~MSR_LINKTYPE_MASK; |
| 2565 | |
| 2566 | switch (linktype) { |
| 2567 | case NL80211_IFTYPE_UNSPECIFIED: |
| 2568 | val8 |= MSR_LINKTYPE_NONE; |
| 2569 | break; |
| 2570 | case NL80211_IFTYPE_ADHOC: |
| 2571 | val8 |= MSR_LINKTYPE_ADHOC; |
| 2572 | break; |
| 2573 | case NL80211_IFTYPE_STATION: |
| 2574 | val8 |= MSR_LINKTYPE_STATION; |
| 2575 | break; |
| 2576 | case NL80211_IFTYPE_AP: |
| 2577 | val8 |= MSR_LINKTYPE_AP; |
| 2578 | break; |
| 2579 | default: |
| 2580 | goto out; |
| 2581 | } |
| 2582 | |
| 2583 | rtl8xxxu_write8(priv, REG_MSR, val8); |
| 2584 | out: |
| 2585 | return; |
| 2586 | } |
| 2587 | |
| 2588 | static void |
| 2589 | rtl8xxxu_set_retry(struct rtl8xxxu_priv *priv, u16 short_retry, u16 long_retry) |
| 2590 | { |
| 2591 | u16 val16; |
| 2592 | |
| 2593 | val16 = ((short_retry << RETRY_LIMIT_SHORT_SHIFT) & |
| 2594 | RETRY_LIMIT_SHORT_MASK) | |
| 2595 | ((long_retry << RETRY_LIMIT_LONG_SHIFT) & |
| 2596 | RETRY_LIMIT_LONG_MASK); |
| 2597 | |
| 2598 | rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16); |
| 2599 | } |
| 2600 | |
| 2601 | static void |
| 2602 | rtl8xxxu_set_spec_sifs(struct rtl8xxxu_priv *priv, u16 cck, u16 ofdm) |
| 2603 | { |
| 2604 | u16 val16; |
| 2605 | |
| 2606 | val16 = ((cck << SPEC_SIFS_CCK_SHIFT) & SPEC_SIFS_CCK_MASK) | |
| 2607 | ((ofdm << SPEC_SIFS_OFDM_SHIFT) & SPEC_SIFS_OFDM_MASK); |
| 2608 | |
| 2609 | rtl8xxxu_write16(priv, REG_SPEC_SIFS, val16); |
| 2610 | } |
| 2611 | |
| 2612 | static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv) |
| 2613 | { |
| 2614 | struct device *dev = &priv->udev->dev; |
| 2615 | char *cut; |
| 2616 | |
| 2617 | switch (priv->chip_cut) { |
| 2618 | case 0: |
| 2619 | cut = "A"; |
| 2620 | break; |
| 2621 | case 1: |
| 2622 | cut = "B"; |
| 2623 | break; |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 2624 | case 2: |
| 2625 | cut = "C"; |
| 2626 | break; |
| 2627 | case 3: |
| 2628 | cut = "D"; |
| 2629 | break; |
| 2630 | case 4: |
| 2631 | cut = "E"; |
| 2632 | break; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2633 | default: |
| 2634 | cut = "unknown"; |
| 2635 | } |
| 2636 | |
| 2637 | dev_info(dev, |
| 2638 | "RTL%s rev %s (%s) %iT%iR, TX queues %i, WiFi=%i, BT=%i, GPS=%i, HI PA=%i\n", |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 2639 | priv->chip_name, cut, priv->chip_vendor, priv->tx_paths, |
| 2640 | priv->rx_paths, priv->ep_tx_count, priv->has_wifi, |
| 2641 | priv->has_bluetooth, priv->has_gps, priv->hi_pa); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2642 | |
| 2643 | dev_info(dev, "RTL%s MAC: %pM\n", priv->chip_name, priv->mac_addr); |
| 2644 | } |
| 2645 | |
| 2646 | static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv) |
| 2647 | { |
| 2648 | struct device *dev = &priv->udev->dev; |
| 2649 | u32 val32, bonding; |
| 2650 | u16 val16; |
| 2651 | |
| 2652 | val32 = rtl8xxxu_read32(priv, REG_SYS_CFG); |
| 2653 | priv->chip_cut = (val32 & SYS_CFG_CHIP_VERSION_MASK) >> |
| 2654 | SYS_CFG_CHIP_VERSION_SHIFT; |
| 2655 | if (val32 & SYS_CFG_TRP_VAUX_EN) { |
| 2656 | dev_info(dev, "Unsupported test chip\n"); |
| 2657 | return -ENOTSUPP; |
| 2658 | } |
| 2659 | |
| 2660 | if (val32 & SYS_CFG_BT_FUNC) { |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 2661 | if (priv->chip_cut >= 3) { |
| 2662 | sprintf(priv->chip_name, "8723BU"); |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2663 | priv->rtl_chip = RTL8723B; |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 2664 | } else { |
| 2665 | sprintf(priv->chip_name, "8723AU"); |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 2666 | priv->usb_interrupts = 1; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2667 | priv->rtl_chip = RTL8723A; |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 2668 | } |
| 2669 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2670 | priv->rf_paths = 1; |
| 2671 | priv->rx_paths = 1; |
| 2672 | priv->tx_paths = 1; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2673 | |
| 2674 | val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL); |
| 2675 | if (val32 & MULTI_WIFI_FUNC_EN) |
| 2676 | priv->has_wifi = 1; |
| 2677 | if (val32 & MULTI_BT_FUNC_EN) |
| 2678 | priv->has_bluetooth = 1; |
| 2679 | if (val32 & MULTI_GPS_FUNC_EN) |
| 2680 | priv->has_gps = 1; |
Jakub Sitnicki | 3845199 | 2016-02-03 13:39:49 -0500 | [diff] [blame] | 2681 | priv->is_multi_func = 1; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2682 | } else if (val32 & SYS_CFG_TYPE_ID) { |
| 2683 | bonding = rtl8xxxu_read32(priv, REG_HPON_FSM); |
| 2684 | bonding &= HPON_FSM_BONDING_MASK; |
Jes Sorensen | af13faf | 2016-03-31 17:08:40 -0400 | [diff] [blame] | 2685 | if (priv->fops->has_s0s1) { |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 2686 | if (bonding == HPON_FSM_BONDING_1T2R) { |
| 2687 | sprintf(priv->chip_name, "8191EU"); |
| 2688 | priv->rf_paths = 2; |
| 2689 | priv->rx_paths = 2; |
| 2690 | priv->tx_paths = 1; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2691 | priv->rtl_chip = RTL8191E; |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 2692 | } else { |
| 2693 | sprintf(priv->chip_name, "8192EU"); |
| 2694 | priv->rf_paths = 2; |
| 2695 | priv->rx_paths = 2; |
| 2696 | priv->tx_paths = 2; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2697 | priv->rtl_chip = RTL8192E; |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 2698 | } |
| 2699 | } else if (bonding == HPON_FSM_BONDING_1T2R) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2700 | sprintf(priv->chip_name, "8191CU"); |
| 2701 | priv->rf_paths = 2; |
| 2702 | priv->rx_paths = 2; |
| 2703 | priv->tx_paths = 1; |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 2704 | priv->usb_interrupts = 1; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2705 | priv->rtl_chip = RTL8191C; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2706 | } else { |
| 2707 | sprintf(priv->chip_name, "8192CU"); |
| 2708 | priv->rf_paths = 2; |
| 2709 | priv->rx_paths = 2; |
| 2710 | priv->tx_paths = 2; |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 2711 | priv->usb_interrupts = 1; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2712 | priv->rtl_chip = RTL8192C; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2713 | } |
| 2714 | priv->has_wifi = 1; |
| 2715 | } else { |
| 2716 | sprintf(priv->chip_name, "8188CU"); |
| 2717 | priv->rf_paths = 1; |
| 2718 | priv->rx_paths = 1; |
| 2719 | priv->tx_paths = 1; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2720 | priv->rtl_chip = RTL8188C; |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 2721 | priv->usb_interrupts = 1; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2722 | priv->has_wifi = 1; |
| 2723 | } |
| 2724 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 2725 | switch (priv->rtl_chip) { |
| 2726 | case RTL8188E: |
| 2727 | case RTL8192E: |
| 2728 | case RTL8723B: |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 2729 | switch (val32 & SYS_CFG_VENDOR_EXT_MASK) { |
| 2730 | case SYS_CFG_VENDOR_ID_TSMC: |
| 2731 | sprintf(priv->chip_vendor, "TSMC"); |
| 2732 | break; |
| 2733 | case SYS_CFG_VENDOR_ID_SMIC: |
| 2734 | sprintf(priv->chip_vendor, "SMIC"); |
| 2735 | priv->vendor_smic = 1; |
| 2736 | break; |
| 2737 | case SYS_CFG_VENDOR_ID_UMC: |
| 2738 | sprintf(priv->chip_vendor, "UMC"); |
| 2739 | priv->vendor_umc = 1; |
| 2740 | break; |
| 2741 | default: |
| 2742 | sprintf(priv->chip_vendor, "unknown"); |
| 2743 | } |
| 2744 | break; |
| 2745 | default: |
| 2746 | if (val32 & SYS_CFG_VENDOR_ID) { |
| 2747 | sprintf(priv->chip_vendor, "UMC"); |
| 2748 | priv->vendor_umc = 1; |
| 2749 | } else { |
| 2750 | sprintf(priv->chip_vendor, "TSMC"); |
| 2751 | } |
| 2752 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2753 | |
| 2754 | val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS); |
| 2755 | priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28; |
| 2756 | |
| 2757 | val16 = rtl8xxxu_read16(priv, REG_NORMAL_SIE_EP_TX); |
| 2758 | if (val16 & NORMAL_SIE_EP_TX_HIGH_MASK) { |
| 2759 | priv->ep_tx_high_queue = 1; |
| 2760 | priv->ep_tx_count++; |
| 2761 | } |
| 2762 | |
| 2763 | if (val16 & NORMAL_SIE_EP_TX_NORMAL_MASK) { |
| 2764 | priv->ep_tx_normal_queue = 1; |
| 2765 | priv->ep_tx_count++; |
| 2766 | } |
| 2767 | |
| 2768 | if (val16 & NORMAL_SIE_EP_TX_LOW_MASK) { |
| 2769 | priv->ep_tx_low_queue = 1; |
| 2770 | priv->ep_tx_count++; |
| 2771 | } |
| 2772 | |
| 2773 | /* |
| 2774 | * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX |
| 2775 | */ |
| 2776 | if (!priv->ep_tx_count) { |
| 2777 | switch (priv->nr_out_eps) { |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 2778 | case 4: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2779 | case 3: |
| 2780 | priv->ep_tx_low_queue = 1; |
| 2781 | priv->ep_tx_count++; |
| 2782 | case 2: |
| 2783 | priv->ep_tx_normal_queue = 1; |
| 2784 | priv->ep_tx_count++; |
| 2785 | case 1: |
| 2786 | priv->ep_tx_high_queue = 1; |
| 2787 | priv->ep_tx_count++; |
| 2788 | break; |
| 2789 | default: |
| 2790 | dev_info(dev, "Unsupported USB TX end-points\n"); |
| 2791 | return -ENOTSUPP; |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | return 0; |
| 2796 | } |
| 2797 | |
| 2798 | static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv) |
| 2799 | { |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2800 | struct rtl8723au_efuse *efuse = &priv->efuse_wifi.efuse8723; |
| 2801 | |
| 2802 | if (efuse->rtl_id != cpu_to_le16(0x8129)) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2803 | return -EINVAL; |
| 2804 | |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2805 | ether_addr_copy(priv->mac_addr, efuse->mac_addr); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2806 | |
| 2807 | memcpy(priv->cck_tx_power_index_A, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2808 | efuse->cck_tx_power_index_A, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2809 | sizeof(efuse->cck_tx_power_index_A)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2810 | memcpy(priv->cck_tx_power_index_B, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2811 | efuse->cck_tx_power_index_B, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2812 | sizeof(efuse->cck_tx_power_index_B)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2813 | |
| 2814 | memcpy(priv->ht40_1s_tx_power_index_A, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2815 | efuse->ht40_1s_tx_power_index_A, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2816 | sizeof(efuse->ht40_1s_tx_power_index_A)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2817 | memcpy(priv->ht40_1s_tx_power_index_B, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2818 | efuse->ht40_1s_tx_power_index_B, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2819 | sizeof(efuse->ht40_1s_tx_power_index_B)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2820 | |
| 2821 | memcpy(priv->ht20_tx_power_index_diff, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2822 | efuse->ht20_tx_power_index_diff, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2823 | sizeof(efuse->ht20_tx_power_index_diff)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2824 | memcpy(priv->ofdm_tx_power_index_diff, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2825 | efuse->ofdm_tx_power_index_diff, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2826 | sizeof(efuse->ofdm_tx_power_index_diff)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2827 | |
| 2828 | memcpy(priv->ht40_max_power_offset, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2829 | efuse->ht40_max_power_offset, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2830 | sizeof(efuse->ht40_max_power_offset)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2831 | memcpy(priv->ht20_max_power_offset, |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2832 | efuse->ht20_max_power_offset, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2833 | sizeof(efuse->ht20_max_power_offset)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2834 | |
Jes Sorensen | 4ef22eb | 2016-02-29 17:04:55 -0500 | [diff] [blame] | 2835 | if (priv->efuse_wifi.efuse8723.version >= 0x01) { |
| 2836 | priv->has_xtalk = 1; |
| 2837 | priv->xtalk = priv->efuse_wifi.efuse8723.xtal_k & 0x3f; |
| 2838 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2839 | dev_info(&priv->udev->dev, "Vendor: %.7s\n", |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2840 | efuse->vendor_name); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2841 | dev_info(&priv->udev->dev, "Product: %.41s\n", |
Jakub Sitnicki | d38f1c3 | 2016-02-29 17:04:25 -0500 | [diff] [blame] | 2842 | efuse->device_name); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2843 | return 0; |
| 2844 | } |
| 2845 | |
Jes Sorensen | 3c836d6 | 2016-02-29 17:04:11 -0500 | [diff] [blame] | 2846 | static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv) |
| 2847 | { |
Jes Sorensen | b8ba860 | 2016-02-29 17:04:28 -0500 | [diff] [blame] | 2848 | struct rtl8723bu_efuse *efuse = &priv->efuse_wifi.efuse8723bu; |
Jes Sorensen | 3be2699 | 2016-02-29 17:05:22 -0500 | [diff] [blame] | 2849 | int i; |
Jes Sorensen | b8ba860 | 2016-02-29 17:04:28 -0500 | [diff] [blame] | 2850 | |
| 2851 | if (efuse->rtl_id != cpu_to_le16(0x8129)) |
Jes Sorensen | 3c836d6 | 2016-02-29 17:04:11 -0500 | [diff] [blame] | 2852 | return -EINVAL; |
| 2853 | |
Jes Sorensen | b8ba860 | 2016-02-29 17:04:28 -0500 | [diff] [blame] | 2854 | ether_addr_copy(priv->mac_addr, efuse->mac_addr); |
Jes Sorensen | 3c836d6 | 2016-02-29 17:04:11 -0500 | [diff] [blame] | 2855 | |
Jes Sorensen | 3be2699 | 2016-02-29 17:05:22 -0500 | [diff] [blame] | 2856 | memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base, |
| 2857 | sizeof(efuse->tx_power_index_A.cck_base)); |
| 2858 | memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base, |
| 2859 | sizeof(efuse->tx_power_index_B.cck_base)); |
| 2860 | |
| 2861 | memcpy(priv->ht40_1s_tx_power_index_A, |
| 2862 | efuse->tx_power_index_A.ht40_base, |
| 2863 | sizeof(efuse->tx_power_index_A.ht40_base)); |
| 2864 | memcpy(priv->ht40_1s_tx_power_index_B, |
| 2865 | efuse->tx_power_index_B.ht40_base, |
| 2866 | sizeof(efuse->tx_power_index_B.ht40_base)); |
| 2867 | |
| 2868 | priv->ofdm_tx_power_diff[0].a = |
| 2869 | efuse->tx_power_index_A.ht20_ofdm_1s_diff.a; |
| 2870 | priv->ofdm_tx_power_diff[0].b = |
| 2871 | efuse->tx_power_index_B.ht20_ofdm_1s_diff.a; |
| 2872 | |
| 2873 | priv->ht20_tx_power_diff[0].a = |
| 2874 | efuse->tx_power_index_A.ht20_ofdm_1s_diff.b; |
| 2875 | priv->ht20_tx_power_diff[0].b = |
| 2876 | efuse->tx_power_index_B.ht20_ofdm_1s_diff.b; |
| 2877 | |
| 2878 | priv->ht40_tx_power_diff[0].a = 0; |
| 2879 | priv->ht40_tx_power_diff[0].b = 0; |
| 2880 | |
| 2881 | for (i = 1; i < RTL8723B_TX_COUNT; i++) { |
| 2882 | priv->ofdm_tx_power_diff[i].a = |
| 2883 | efuse->tx_power_index_A.pwr_diff[i - 1].ofdm; |
| 2884 | priv->ofdm_tx_power_diff[i].b = |
| 2885 | efuse->tx_power_index_B.pwr_diff[i - 1].ofdm; |
| 2886 | |
| 2887 | priv->ht20_tx_power_diff[i].a = |
| 2888 | efuse->tx_power_index_A.pwr_diff[i - 1].ht20; |
| 2889 | priv->ht20_tx_power_diff[i].b = |
| 2890 | efuse->tx_power_index_B.pwr_diff[i - 1].ht20; |
| 2891 | |
| 2892 | priv->ht40_tx_power_diff[i].a = |
| 2893 | efuse->tx_power_index_A.pwr_diff[i - 1].ht40; |
| 2894 | priv->ht40_tx_power_diff[i].b = |
| 2895 | efuse->tx_power_index_B.pwr_diff[i - 1].ht40; |
| 2896 | } |
| 2897 | |
Jes Sorensen | 4ef22eb | 2016-02-29 17:04:55 -0500 | [diff] [blame] | 2898 | priv->has_xtalk = 1; |
| 2899 | priv->xtalk = priv->efuse_wifi.efuse8723bu.xtal_k & 0x3f; |
| 2900 | |
Jes Sorensen | b8ba860 | 2016-02-29 17:04:28 -0500 | [diff] [blame] | 2901 | dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name); |
| 2902 | dev_info(&priv->udev->dev, "Product: %.41s\n", efuse->device_name); |
Jes Sorensen | 3c836d6 | 2016-02-29 17:04:11 -0500 | [diff] [blame] | 2903 | |
| 2904 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) { |
| 2905 | int i; |
| 2906 | unsigned char *raw = priv->efuse_wifi.raw; |
| 2907 | |
| 2908 | dev_info(&priv->udev->dev, |
| 2909 | "%s: dumping efuse (0x%02zx bytes):\n", |
| 2910 | __func__, sizeof(struct rtl8723bu_efuse)); |
| 2911 | for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8) { |
| 2912 | dev_info(&priv->udev->dev, "%02x: " |
| 2913 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", i, |
| 2914 | raw[i], raw[i + 1], raw[i + 2], |
| 2915 | raw[i + 3], raw[i + 4], raw[i + 5], |
| 2916 | raw[i + 6], raw[i + 7]); |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | return 0; |
| 2921 | } |
| 2922 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 2923 | #ifdef CONFIG_RTL8XXXU_UNTESTED |
| 2924 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2925 | static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv) |
| 2926 | { |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2927 | struct rtl8192cu_efuse *efuse = &priv->efuse_wifi.efuse8192; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2928 | int i; |
| 2929 | |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2930 | if (efuse->rtl_id != cpu_to_le16(0x8129)) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2931 | return -EINVAL; |
| 2932 | |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2933 | ether_addr_copy(priv->mac_addr, efuse->mac_addr); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2934 | |
| 2935 | memcpy(priv->cck_tx_power_index_A, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2936 | efuse->cck_tx_power_index_A, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2937 | sizeof(efuse->cck_tx_power_index_A)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2938 | memcpy(priv->cck_tx_power_index_B, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2939 | efuse->cck_tx_power_index_B, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2940 | sizeof(efuse->cck_tx_power_index_B)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2941 | |
| 2942 | memcpy(priv->ht40_1s_tx_power_index_A, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2943 | efuse->ht40_1s_tx_power_index_A, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2944 | sizeof(efuse->ht40_1s_tx_power_index_A)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2945 | memcpy(priv->ht40_1s_tx_power_index_B, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2946 | efuse->ht40_1s_tx_power_index_B, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2947 | sizeof(efuse->ht40_1s_tx_power_index_B)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2948 | memcpy(priv->ht40_2s_tx_power_index_diff, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2949 | efuse->ht40_2s_tx_power_index_diff, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2950 | sizeof(efuse->ht40_2s_tx_power_index_diff)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2951 | |
| 2952 | memcpy(priv->ht20_tx_power_index_diff, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2953 | efuse->ht20_tx_power_index_diff, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2954 | sizeof(efuse->ht20_tx_power_index_diff)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2955 | memcpy(priv->ofdm_tx_power_index_diff, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2956 | efuse->ofdm_tx_power_index_diff, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2957 | sizeof(efuse->ofdm_tx_power_index_diff)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2958 | |
| 2959 | memcpy(priv->ht40_max_power_offset, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2960 | efuse->ht40_max_power_offset, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2961 | sizeof(efuse->ht40_max_power_offset)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2962 | memcpy(priv->ht20_max_power_offset, |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2963 | efuse->ht20_max_power_offset, |
Jes Sorensen | 3e84f93 | 2016-02-29 17:05:20 -0500 | [diff] [blame] | 2964 | sizeof(efuse->ht20_max_power_offset)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2965 | |
| 2966 | dev_info(&priv->udev->dev, "Vendor: %.7s\n", |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2967 | efuse->vendor_name); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2968 | dev_info(&priv->udev->dev, "Product: %.20s\n", |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2969 | efuse->device_name); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2970 | |
Jakub Sitnicki | 4959444 | 2016-02-29 17:04:26 -0500 | [diff] [blame] | 2971 | if (efuse->rf_regulatory & 0x20) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 2972 | sprintf(priv->chip_name, "8188RU"); |
| 2973 | priv->hi_pa = 1; |
| 2974 | } |
| 2975 | |
| 2976 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) { |
| 2977 | unsigned char *raw = priv->efuse_wifi.raw; |
| 2978 | |
| 2979 | dev_info(&priv->udev->dev, |
| 2980 | "%s: dumping efuse (0x%02zx bytes):\n", |
| 2981 | __func__, sizeof(struct rtl8192cu_efuse)); |
| 2982 | for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8) { |
| 2983 | dev_info(&priv->udev->dev, "%02x: " |
| 2984 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", i, |
| 2985 | raw[i], raw[i + 1], raw[i + 2], |
| 2986 | raw[i + 3], raw[i + 4], raw[i + 5], |
| 2987 | raw[i + 6], raw[i + 7]); |
| 2988 | } |
| 2989 | } |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 2993 | #endif |
| 2994 | |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 2995 | static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv) |
| 2996 | { |
Jes Sorensen | b7dda34d | 2016-02-29 17:04:27 -0500 | [diff] [blame] | 2997 | struct rtl8192eu_efuse *efuse = &priv->efuse_wifi.efuse8192eu; |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 2998 | int i; |
| 2999 | |
Jes Sorensen | b7dda34d | 2016-02-29 17:04:27 -0500 | [diff] [blame] | 3000 | if (efuse->rtl_id != cpu_to_le16(0x8129)) |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3001 | return -EINVAL; |
| 3002 | |
Jes Sorensen | b7dda34d | 2016-02-29 17:04:27 -0500 | [diff] [blame] | 3003 | ether_addr_copy(priv->mac_addr, efuse->mac_addr); |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3004 | |
Jes Sorensen | 9e24772 | 2016-04-07 14:19:23 -0400 | [diff] [blame] | 3005 | memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base, |
| 3006 | sizeof(efuse->tx_power_index_A.cck_base)); |
| 3007 | memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base, |
| 3008 | sizeof(efuse->tx_power_index_B.cck_base)); |
| 3009 | |
| 3010 | memcpy(priv->ht40_1s_tx_power_index_A, |
| 3011 | efuse->tx_power_index_A.ht40_base, |
| 3012 | sizeof(efuse->tx_power_index_A.ht40_base)); |
| 3013 | memcpy(priv->ht40_1s_tx_power_index_B, |
| 3014 | efuse->tx_power_index_B.ht40_base, |
| 3015 | sizeof(efuse->tx_power_index_B.ht40_base)); |
| 3016 | |
| 3017 | priv->ht20_tx_power_diff[0].a = |
| 3018 | efuse->tx_power_index_A.ht20_ofdm_1s_diff.b; |
| 3019 | priv->ht20_tx_power_diff[0].b = |
| 3020 | efuse->tx_power_index_B.ht20_ofdm_1s_diff.b; |
| 3021 | |
| 3022 | priv->ht40_tx_power_diff[0].a = 0; |
| 3023 | priv->ht40_tx_power_diff[0].b = 0; |
| 3024 | |
| 3025 | for (i = 1; i < RTL8723B_TX_COUNT; i++) { |
| 3026 | priv->ofdm_tx_power_diff[i].a = |
| 3027 | efuse->tx_power_index_A.pwr_diff[i - 1].ofdm; |
| 3028 | priv->ofdm_tx_power_diff[i].b = |
| 3029 | efuse->tx_power_index_B.pwr_diff[i - 1].ofdm; |
| 3030 | |
| 3031 | priv->ht20_tx_power_diff[i].a = |
| 3032 | efuse->tx_power_index_A.pwr_diff[i - 1].ht20; |
| 3033 | priv->ht20_tx_power_diff[i].b = |
| 3034 | efuse->tx_power_index_B.pwr_diff[i - 1].ht20; |
| 3035 | |
| 3036 | priv->ht40_tx_power_diff[i].a = |
| 3037 | efuse->tx_power_index_A.pwr_diff[i - 1].ht40; |
| 3038 | priv->ht40_tx_power_diff[i].b = |
| 3039 | efuse->tx_power_index_B.pwr_diff[i - 1].ht40; |
| 3040 | } |
| 3041 | |
Jes Sorensen | 4ef22eb | 2016-02-29 17:04:55 -0500 | [diff] [blame] | 3042 | priv->has_xtalk = 1; |
| 3043 | priv->xtalk = priv->efuse_wifi.efuse8192eu.xtal_k & 0x3f; |
| 3044 | |
Jes Sorensen | b7dda34d | 2016-02-29 17:04:27 -0500 | [diff] [blame] | 3045 | dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name); |
| 3046 | dev_info(&priv->udev->dev, "Product: %.11s\n", efuse->device_name); |
| 3047 | dev_info(&priv->udev->dev, "Serial: %.11s\n", efuse->serial); |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3048 | |
| 3049 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) { |
| 3050 | unsigned char *raw = priv->efuse_wifi.raw; |
| 3051 | |
| 3052 | dev_info(&priv->udev->dev, |
| 3053 | "%s: dumping efuse (0x%02zx bytes):\n", |
| 3054 | __func__, sizeof(struct rtl8192eu_efuse)); |
| 3055 | for (i = 0; i < sizeof(struct rtl8192eu_efuse); i += 8) { |
| 3056 | dev_info(&priv->udev->dev, "%02x: " |
| 3057 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", i, |
| 3058 | raw[i], raw[i + 1], raw[i + 2], |
| 3059 | raw[i + 3], raw[i + 4], raw[i + 5], |
| 3060 | raw[i + 6], raw[i + 7]); |
| 3061 | } |
| 3062 | } |
Jes Sorensen | ccfe1e8 | 2016-02-29 17:05:51 -0500 | [diff] [blame] | 3063 | /* |
| 3064 | * Temporarily disable 8192eu support |
| 3065 | */ |
| 3066 | return -EINVAL; |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 3067 | return 0; |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3068 | } |
| 3069 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3070 | static int |
| 3071 | rtl8xxxu_read_efuse8(struct rtl8xxxu_priv *priv, u16 offset, u8 *data) |
| 3072 | { |
| 3073 | int i; |
| 3074 | u8 val8; |
| 3075 | u32 val32; |
| 3076 | |
| 3077 | /* Write Address */ |
| 3078 | rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 1, offset & 0xff); |
| 3079 | val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 2); |
| 3080 | val8 &= 0xfc; |
| 3081 | val8 |= (offset >> 8) & 0x03; |
| 3082 | rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 2, val8); |
| 3083 | |
| 3084 | val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 3); |
| 3085 | rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 3, val8 & 0x7f); |
| 3086 | |
| 3087 | /* Poll for data read */ |
| 3088 | val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL); |
| 3089 | for (i = 0; i < RTL8XXXU_MAX_REG_POLL; i++) { |
| 3090 | val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL); |
| 3091 | if (val32 & BIT(31)) |
| 3092 | break; |
| 3093 | } |
| 3094 | |
| 3095 | if (i == RTL8XXXU_MAX_REG_POLL) |
| 3096 | return -EIO; |
| 3097 | |
| 3098 | udelay(50); |
| 3099 | val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL); |
| 3100 | |
| 3101 | *data = val32 & 0xff; |
| 3102 | return 0; |
| 3103 | } |
| 3104 | |
| 3105 | static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv) |
| 3106 | { |
| 3107 | struct device *dev = &priv->udev->dev; |
| 3108 | int i, ret = 0; |
| 3109 | u8 val8, word_mask, header, extheader; |
| 3110 | u16 val16, efuse_addr, offset; |
| 3111 | u32 val32; |
| 3112 | |
| 3113 | val16 = rtl8xxxu_read16(priv, REG_9346CR); |
| 3114 | if (val16 & EEPROM_ENABLE) |
| 3115 | priv->has_eeprom = 1; |
| 3116 | if (val16 & EEPROM_BOOT) |
| 3117 | priv->boot_eeprom = 1; |
| 3118 | |
Jakub Sitnicki | 3845199 | 2016-02-03 13:39:49 -0500 | [diff] [blame] | 3119 | if (priv->is_multi_func) { |
| 3120 | val32 = rtl8xxxu_read32(priv, REG_EFUSE_TEST); |
| 3121 | val32 = (val32 & ~EFUSE_SELECT_MASK) | EFUSE_WIFI_SELECT; |
| 3122 | rtl8xxxu_write32(priv, REG_EFUSE_TEST, val32); |
| 3123 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3124 | |
| 3125 | dev_dbg(dev, "Booting from %s\n", |
| 3126 | priv->boot_eeprom ? "EEPROM" : "EFUSE"); |
| 3127 | |
| 3128 | rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_ENABLE); |
| 3129 | |
| 3130 | /* 1.2V Power: From VDDON with Power Cut(0x0000[15]), default valid */ |
| 3131 | val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL); |
| 3132 | if (!(val16 & SYS_ISO_PWC_EV12V)) { |
| 3133 | val16 |= SYS_ISO_PWC_EV12V; |
| 3134 | rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16); |
| 3135 | } |
| 3136 | /* Reset: 0x0000[28], default valid */ |
| 3137 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3138 | if (!(val16 & SYS_FUNC_ELDR)) { |
| 3139 | val16 |= SYS_FUNC_ELDR; |
| 3140 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 3141 | } |
| 3142 | |
| 3143 | /* |
| 3144 | * Clock: Gated(0x0008[5]) 8M(0x0008[1]) clock from ANA, default valid |
| 3145 | */ |
| 3146 | val16 = rtl8xxxu_read16(priv, REG_SYS_CLKR); |
| 3147 | if (!(val16 & SYS_CLK_LOADER_ENABLE) || !(val16 & SYS_CLK_ANA8M)) { |
| 3148 | val16 |= (SYS_CLK_LOADER_ENABLE | SYS_CLK_ANA8M); |
| 3149 | rtl8xxxu_write16(priv, REG_SYS_CLKR, val16); |
| 3150 | } |
| 3151 | |
| 3152 | /* Default value is 0xff */ |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3153 | memset(priv->efuse_wifi.raw, 0xff, EFUSE_MAP_LEN); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3154 | |
| 3155 | efuse_addr = 0; |
| 3156 | while (efuse_addr < EFUSE_REAL_CONTENT_LEN_8723A) { |
Jakub Sitnicki | f6c4770 | 2016-02-29 17:04:23 -0500 | [diff] [blame] | 3157 | u16 map_addr; |
| 3158 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3159 | ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &header); |
| 3160 | if (ret || header == 0xff) |
| 3161 | goto exit; |
| 3162 | |
| 3163 | if ((header & 0x1f) == 0x0f) { /* extended header */ |
| 3164 | offset = (header & 0xe0) >> 5; |
| 3165 | |
| 3166 | ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, |
| 3167 | &extheader); |
| 3168 | if (ret) |
| 3169 | goto exit; |
| 3170 | /* All words disabled */ |
| 3171 | if ((extheader & 0x0f) == 0x0f) |
| 3172 | continue; |
| 3173 | |
| 3174 | offset |= ((extheader & 0xf0) >> 1); |
| 3175 | word_mask = extheader & 0x0f; |
| 3176 | } else { |
| 3177 | offset = (header >> 4) & 0x0f; |
| 3178 | word_mask = header & 0x0f; |
| 3179 | } |
| 3180 | |
Jakub Sitnicki | f6c4770 | 2016-02-29 17:04:23 -0500 | [diff] [blame] | 3181 | /* Get word enable value from PG header */ |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3182 | |
Jakub Sitnicki | f6c4770 | 2016-02-29 17:04:23 -0500 | [diff] [blame] | 3183 | /* We have 8 bits to indicate validity */ |
| 3184 | map_addr = offset * 8; |
| 3185 | if (map_addr >= EFUSE_MAP_LEN) { |
| 3186 | dev_warn(dev, "%s: Illegal map_addr (%04x), " |
| 3187 | "efuse corrupt!\n", |
| 3188 | __func__, map_addr); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3189 | ret = -EINVAL; |
| 3190 | goto exit; |
| 3191 | } |
Jakub Sitnicki | f6c4770 | 2016-02-29 17:04:23 -0500 | [diff] [blame] | 3192 | for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { |
| 3193 | /* Check word enable condition in the section */ |
Jakub Sitnicki | 32a39dd | 2016-02-29 17:04:24 -0500 | [diff] [blame] | 3194 | if (word_mask & BIT(i)) { |
Jakub Sitnicki | f6c4770 | 2016-02-29 17:04:23 -0500 | [diff] [blame] | 3195 | map_addr += 2; |
Jakub Sitnicki | 32a39dd | 2016-02-29 17:04:24 -0500 | [diff] [blame] | 3196 | continue; |
| 3197 | } |
| 3198 | |
| 3199 | ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8); |
| 3200 | if (ret) |
| 3201 | goto exit; |
| 3202 | priv->efuse_wifi.raw[map_addr++] = val8; |
| 3203 | |
| 3204 | ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8); |
| 3205 | if (ret) |
| 3206 | goto exit; |
| 3207 | priv->efuse_wifi.raw[map_addr++] = val8; |
Jakub Sitnicki | f6c4770 | 2016-02-29 17:04:23 -0500 | [diff] [blame] | 3208 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | exit: |
| 3212 | rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_DISABLE); |
| 3213 | |
| 3214 | return ret; |
| 3215 | } |
| 3216 | |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3217 | static void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv) |
| 3218 | { |
| 3219 | u8 val8; |
| 3220 | u16 sys_func; |
| 3221 | |
| 3222 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); |
Jes Sorensen | 53b381c | 2016-02-03 13:39:57 -0500 | [diff] [blame] | 3223 | val8 &= ~BIT(0); |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3224 | rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 3225 | |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3226 | sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3227 | sys_func &= ~SYS_FUNC_CPU_ENABLE; |
| 3228 | rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func); |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 3229 | |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3230 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); |
Jes Sorensen | 53b381c | 2016-02-03 13:39:57 -0500 | [diff] [blame] | 3231 | val8 |= BIT(0); |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3232 | rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 3233 | |
| 3234 | sys_func |= SYS_FUNC_CPU_ENABLE; |
| 3235 | rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func); |
| 3236 | } |
| 3237 | |
| 3238 | static void rtl8723bu_reset_8051(struct rtl8xxxu_priv *priv) |
| 3239 | { |
| 3240 | u8 val8; |
| 3241 | u16 sys_func; |
| 3242 | |
| 3243 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL); |
| 3244 | val8 &= ~BIT(1); |
| 3245 | rtl8xxxu_write8(priv, REG_RSV_CTRL, val8); |
| 3246 | |
| 3247 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); |
| 3248 | val8 &= ~BIT(0); |
| 3249 | rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); |
| 3250 | |
| 3251 | sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3252 | sys_func &= ~SYS_FUNC_CPU_ENABLE; |
| 3253 | rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func); |
| 3254 | |
| 3255 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL); |
| 3256 | val8 &= ~BIT(1); |
| 3257 | rtl8xxxu_write8(priv, REG_RSV_CTRL, val8); |
| 3258 | |
| 3259 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); |
| 3260 | val8 |= BIT(0); |
| 3261 | rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); |
| 3262 | |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3263 | sys_func |= SYS_FUNC_CPU_ENABLE; |
| 3264 | rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func); |
| 3265 | } |
| 3266 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3267 | static int rtl8xxxu_start_firmware(struct rtl8xxxu_priv *priv) |
| 3268 | { |
| 3269 | struct device *dev = &priv->udev->dev; |
| 3270 | int ret = 0, i; |
| 3271 | u32 val32; |
| 3272 | |
| 3273 | /* Poll checksum report */ |
| 3274 | for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) { |
| 3275 | val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL); |
| 3276 | if (val32 & MCU_FW_DL_CSUM_REPORT) |
| 3277 | break; |
| 3278 | } |
| 3279 | |
| 3280 | if (i == RTL8XXXU_FIRMWARE_POLL_MAX) { |
| 3281 | dev_warn(dev, "Firmware checksum poll timed out\n"); |
| 3282 | ret = -EAGAIN; |
| 3283 | goto exit; |
| 3284 | } |
| 3285 | |
| 3286 | val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL); |
| 3287 | val32 |= MCU_FW_DL_READY; |
| 3288 | val32 &= ~MCU_WINT_INIT_READY; |
| 3289 | rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32); |
| 3290 | |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3291 | /* |
| 3292 | * Reset the 8051 in order for the firmware to start running, |
| 3293 | * otherwise it won't come up on the 8192eu |
| 3294 | */ |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 3295 | priv->fops->reset_8051(priv); |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3296 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3297 | /* Wait for firmware to become ready */ |
| 3298 | for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) { |
| 3299 | val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL); |
| 3300 | if (val32 & MCU_WINT_INIT_READY) |
| 3301 | break; |
| 3302 | |
| 3303 | udelay(100); |
| 3304 | } |
| 3305 | |
| 3306 | if (i == RTL8XXXU_FIRMWARE_POLL_MAX) { |
| 3307 | dev_warn(dev, "Firmware failed to start\n"); |
| 3308 | ret = -EAGAIN; |
| 3309 | goto exit; |
| 3310 | } |
| 3311 | |
Jes Sorensen | 3a4be6a | 2016-02-29 17:04:58 -0500 | [diff] [blame] | 3312 | /* |
| 3313 | * Init H2C command |
| 3314 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 3315 | if (priv->rtl_chip == RTL8723B) |
Jes Sorensen | 3a4be6a | 2016-02-29 17:04:58 -0500 | [diff] [blame] | 3316 | rtl8xxxu_write8(priv, REG_HMTFR, 0x0f); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3317 | exit: |
| 3318 | return ret; |
| 3319 | } |
| 3320 | |
| 3321 | static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) |
| 3322 | { |
| 3323 | int pages, remainder, i, ret; |
Jes Sorensen | d48fe60 | 2016-02-03 13:39:44 -0500 | [diff] [blame] | 3324 | u8 val8; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3325 | u16 val16; |
| 3326 | u32 val32; |
| 3327 | u8 *fwptr; |
| 3328 | |
| 3329 | val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC + 1); |
| 3330 | val8 |= 4; |
| 3331 | rtl8xxxu_write8(priv, REG_SYS_FUNC + 1, val8); |
| 3332 | |
| 3333 | /* 8051 enable */ |
| 3334 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
Jes Sorensen | 43154f6 | 2016-02-03 13:39:35 -0500 | [diff] [blame] | 3335 | val16 |= SYS_FUNC_CPU_ENABLE; |
| 3336 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3337 | |
Jes Sorensen | 216202a | 2016-02-03 13:39:37 -0500 | [diff] [blame] | 3338 | val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL); |
| 3339 | if (val8 & MCU_FW_RAM_SEL) { |
| 3340 | pr_info("do the RAM reset\n"); |
| 3341 | rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00); |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 3342 | priv->fops->reset_8051(priv); |
Jes Sorensen | 216202a | 2016-02-03 13:39:37 -0500 | [diff] [blame] | 3343 | } |
| 3344 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3345 | /* MCU firmware download enable */ |
| 3346 | val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL); |
Jes Sorensen | ef1c049 | 2016-02-03 13:39:36 -0500 | [diff] [blame] | 3347 | val8 |= MCU_FW_DL_ENABLE; |
| 3348 | rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3349 | |
| 3350 | /* 8051 reset */ |
| 3351 | val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL); |
Jes Sorensen | ef1c049 | 2016-02-03 13:39:36 -0500 | [diff] [blame] | 3352 | val32 &= ~BIT(19); |
| 3353 | rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3354 | |
| 3355 | /* Reset firmware download checksum */ |
| 3356 | val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL); |
Jes Sorensen | ef1c049 | 2016-02-03 13:39:36 -0500 | [diff] [blame] | 3357 | val8 |= MCU_FW_DL_CSUM_REPORT; |
| 3358 | rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3359 | |
| 3360 | pages = priv->fw_size / RTL_FW_PAGE_SIZE; |
| 3361 | remainder = priv->fw_size % RTL_FW_PAGE_SIZE; |
| 3362 | |
| 3363 | fwptr = priv->fw_data->data; |
| 3364 | |
| 3365 | for (i = 0; i < pages; i++) { |
| 3366 | val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8; |
Jes Sorensen | ef1c049 | 2016-02-03 13:39:36 -0500 | [diff] [blame] | 3367 | val8 |= i; |
| 3368 | rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3369 | |
| 3370 | ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS, |
| 3371 | fwptr, RTL_FW_PAGE_SIZE); |
| 3372 | if (ret != RTL_FW_PAGE_SIZE) { |
| 3373 | ret = -EAGAIN; |
| 3374 | goto fw_abort; |
| 3375 | } |
| 3376 | |
| 3377 | fwptr += RTL_FW_PAGE_SIZE; |
| 3378 | } |
| 3379 | |
| 3380 | if (remainder) { |
| 3381 | val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8; |
Jes Sorensen | ef1c049 | 2016-02-03 13:39:36 -0500 | [diff] [blame] | 3382 | val8 |= i; |
| 3383 | rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3384 | ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS, |
| 3385 | fwptr, remainder); |
| 3386 | if (ret != remainder) { |
| 3387 | ret = -EAGAIN; |
| 3388 | goto fw_abort; |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | ret = 0; |
| 3393 | fw_abort: |
| 3394 | /* MCU firmware download disable */ |
| 3395 | val16 = rtl8xxxu_read16(priv, REG_MCU_FW_DL); |
Jes Sorensen | ef1c049 | 2016-02-03 13:39:36 -0500 | [diff] [blame] | 3396 | val16 &= ~MCU_FW_DL_ENABLE; |
| 3397 | rtl8xxxu_write16(priv, REG_MCU_FW_DL, val16); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3398 | |
| 3399 | return ret; |
| 3400 | } |
| 3401 | |
| 3402 | static int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name) |
| 3403 | { |
| 3404 | struct device *dev = &priv->udev->dev; |
| 3405 | const struct firmware *fw; |
| 3406 | int ret = 0; |
| 3407 | u16 signature; |
| 3408 | |
| 3409 | dev_info(dev, "%s: Loading firmware %s\n", DRIVER_NAME, fw_name); |
| 3410 | if (request_firmware(&fw, fw_name, &priv->udev->dev)) { |
| 3411 | dev_warn(dev, "request_firmware(%s) failed\n", fw_name); |
| 3412 | ret = -EAGAIN; |
| 3413 | goto exit; |
| 3414 | } |
| 3415 | if (!fw) { |
| 3416 | dev_warn(dev, "Firmware data not available\n"); |
| 3417 | ret = -EINVAL; |
| 3418 | goto exit; |
| 3419 | } |
| 3420 | |
| 3421 | priv->fw_data = kmemdup(fw->data, fw->size, GFP_KERNEL); |
Tobias Klauser | 98e27cb | 2016-02-03 13:39:43 -0500 | [diff] [blame] | 3422 | if (!priv->fw_data) { |
| 3423 | ret = -ENOMEM; |
| 3424 | goto exit; |
| 3425 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3426 | priv->fw_size = fw->size - sizeof(struct rtl8xxxu_firmware_header); |
| 3427 | |
| 3428 | signature = le16_to_cpu(priv->fw_data->signature); |
| 3429 | switch (signature & 0xfff0) { |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 3430 | case 0x92e0: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3431 | case 0x92c0: |
| 3432 | case 0x88c0: |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 3433 | case 0x5300: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3434 | case 0x2300: |
| 3435 | break; |
| 3436 | default: |
| 3437 | ret = -EINVAL; |
| 3438 | dev_warn(dev, "%s: Invalid firmware signature: 0x%04x\n", |
| 3439 | __func__, signature); |
| 3440 | } |
| 3441 | |
| 3442 | dev_info(dev, "Firmware revision %i.%i (signature 0x%04x)\n", |
| 3443 | le16_to_cpu(priv->fw_data->major_version), |
| 3444 | priv->fw_data->minor_version, signature); |
| 3445 | |
| 3446 | exit: |
| 3447 | release_firmware(fw); |
| 3448 | return ret; |
| 3449 | } |
| 3450 | |
| 3451 | static int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv) |
| 3452 | { |
| 3453 | char *fw_name; |
| 3454 | int ret; |
| 3455 | |
| 3456 | switch (priv->chip_cut) { |
| 3457 | case 0: |
| 3458 | fw_name = "rtlwifi/rtl8723aufw_A.bin"; |
| 3459 | break; |
| 3460 | case 1: |
| 3461 | if (priv->enable_bluetooth) |
| 3462 | fw_name = "rtlwifi/rtl8723aufw_B.bin"; |
| 3463 | else |
| 3464 | fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin"; |
| 3465 | |
| 3466 | break; |
| 3467 | default: |
| 3468 | return -EINVAL; |
| 3469 | } |
| 3470 | |
| 3471 | ret = rtl8xxxu_load_firmware(priv, fw_name); |
| 3472 | return ret; |
| 3473 | } |
| 3474 | |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 3475 | static int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv) |
| 3476 | { |
| 3477 | char *fw_name; |
| 3478 | int ret; |
| 3479 | |
| 3480 | if (priv->enable_bluetooth) |
| 3481 | fw_name = "rtlwifi/rtl8723bu_bt.bin"; |
| 3482 | else |
| 3483 | fw_name = "rtlwifi/rtl8723bu_nic.bin"; |
| 3484 | |
| 3485 | ret = rtl8xxxu_load_firmware(priv, fw_name); |
| 3486 | return ret; |
| 3487 | } |
| 3488 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 3489 | #ifdef CONFIG_RTL8XXXU_UNTESTED |
| 3490 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3491 | static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv) |
| 3492 | { |
| 3493 | char *fw_name; |
| 3494 | int ret; |
| 3495 | |
| 3496 | if (!priv->vendor_umc) |
| 3497 | fw_name = "rtlwifi/rtl8192cufw_TMSC.bin"; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 3498 | else if (priv->chip_cut || priv->rtl_chip == RTL8192C) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3499 | fw_name = "rtlwifi/rtl8192cufw_B.bin"; |
| 3500 | else |
| 3501 | fw_name = "rtlwifi/rtl8192cufw_A.bin"; |
| 3502 | |
| 3503 | ret = rtl8xxxu_load_firmware(priv, fw_name); |
| 3504 | |
| 3505 | return ret; |
| 3506 | } |
| 3507 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 3508 | #endif |
| 3509 | |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3510 | static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv) |
| 3511 | { |
| 3512 | char *fw_name; |
| 3513 | int ret; |
| 3514 | |
Jes Sorensen | 0e5d435 | 2016-02-29 17:04:00 -0500 | [diff] [blame] | 3515 | fw_name = "rtlwifi/rtl8192eu_nic.bin"; |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 3516 | |
| 3517 | ret = rtl8xxxu_load_firmware(priv, fw_name); |
| 3518 | |
| 3519 | return ret; |
| 3520 | } |
| 3521 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3522 | static void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv) |
| 3523 | { |
| 3524 | u16 val16; |
| 3525 | int i = 100; |
| 3526 | |
| 3527 | /* Inform 8051 to perform reset */ |
| 3528 | rtl8xxxu_write8(priv, REG_HMTFR + 3, 0x20); |
| 3529 | |
| 3530 | for (i = 100; i > 0; i--) { |
| 3531 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3532 | |
| 3533 | if (!(val16 & SYS_FUNC_CPU_ENABLE)) { |
| 3534 | dev_dbg(&priv->udev->dev, |
| 3535 | "%s: Firmware self reset success!\n", __func__); |
| 3536 | break; |
| 3537 | } |
| 3538 | udelay(50); |
| 3539 | } |
| 3540 | |
| 3541 | if (!i) { |
| 3542 | /* Force firmware reset */ |
| 3543 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3544 | val16 &= ~SYS_FUNC_CPU_ENABLE; |
| 3545 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 3546 | } |
| 3547 | } |
| 3548 | |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3549 | static void rtl8723bu_phy_init_antenna_selection(struct rtl8xxxu_priv *priv) |
| 3550 | { |
| 3551 | u32 val32; |
| 3552 | |
| 3553 | val32 = rtl8xxxu_read32(priv, 0x64); |
| 3554 | val32 &= ~(BIT(20) | BIT(24)); |
| 3555 | rtl8xxxu_write32(priv, 0x64, val32); |
| 3556 | |
| 3557 | val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG); |
| 3558 | val32 &= ~BIT(4); |
Jes Sorensen | 3a4be6a | 2016-02-29 17:04:58 -0500 | [diff] [blame] | 3559 | rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32); |
| 3560 | |
| 3561 | val32 = rtl8xxxu_read32(priv, REG_GPIO_MUXCFG); |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3562 | val32 |= BIT(3); |
| 3563 | rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, val32); |
| 3564 | |
| 3565 | val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3566 | val32 |= BIT(24); |
| 3567 | rtl8xxxu_write32(priv, REG_LEDCFG0, val32); |
| 3568 | |
Jes Sorensen | 3a4be6a | 2016-02-29 17:04:58 -0500 | [diff] [blame] | 3569 | val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); |
| 3570 | val32 &= ~BIT(23); |
| 3571 | rtl8xxxu_write32(priv, REG_LEDCFG0, val32); |
| 3572 | |
Jes Sorensen | 120e627 | 2016-02-29 17:05:14 -0500 | [diff] [blame] | 3573 | val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER); |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3574 | val32 |= (BIT(0) | BIT(1)); |
Jes Sorensen | 120e627 | 2016-02-29 17:05:14 -0500 | [diff] [blame] | 3575 | rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32); |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3576 | |
Jes Sorensen | 59b7439 | 2016-02-29 17:05:15 -0500 | [diff] [blame] | 3577 | val32 = rtl8xxxu_read32(priv, REG_RFE_CTRL_ANTA_SRC); |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3578 | val32 &= 0xffffff00; |
| 3579 | val32 |= 0x77; |
Jes Sorensen | 59b7439 | 2016-02-29 17:05:15 -0500 | [diff] [blame] | 3580 | rtl8xxxu_write32(priv, REG_RFE_CTRL_ANTA_SRC, val32); |
Jes Sorensen | 3a4be6a | 2016-02-29 17:04:58 -0500 | [diff] [blame] | 3581 | |
| 3582 | val32 = rtl8xxxu_read32(priv, REG_PWR_DATA); |
| 3583 | val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN; |
| 3584 | rtl8xxxu_write32(priv, REG_PWR_DATA, val32); |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 3585 | } |
| 3586 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3587 | static int |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 3588 | rtl8xxxu_init_mac(struct rtl8xxxu_priv *priv) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3589 | { |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 3590 | struct rtl8xxxu_reg8val *array = priv->fops->mactable; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3591 | int i, ret; |
| 3592 | u16 reg; |
| 3593 | u8 val; |
| 3594 | |
| 3595 | for (i = 0; ; i++) { |
| 3596 | reg = array[i].reg; |
| 3597 | val = array[i].val; |
| 3598 | |
| 3599 | if (reg == 0xffff && val == 0xff) |
| 3600 | break; |
| 3601 | |
| 3602 | ret = rtl8xxxu_write8(priv, reg, val); |
| 3603 | if (ret != 1) { |
| 3604 | dev_warn(&priv->udev->dev, |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 3605 | "Failed to initialize MAC " |
| 3606 | "(reg: %04x, val %02x)\n", reg, val); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3607 | return -EAGAIN; |
| 3608 | } |
| 3609 | } |
| 3610 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 3611 | if (priv->rtl_chip != RTL8723B) |
Jes Sorensen | 8baf670 | 2016-02-29 17:04:54 -0500 | [diff] [blame] | 3612 | rtl8xxxu_write8(priv, REG_MAX_AGGR_NUM, 0x0a); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3613 | |
| 3614 | return 0; |
| 3615 | } |
| 3616 | |
| 3617 | static int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv, |
| 3618 | struct rtl8xxxu_reg32val *array) |
| 3619 | { |
| 3620 | int i, ret; |
| 3621 | u16 reg; |
| 3622 | u32 val; |
| 3623 | |
| 3624 | for (i = 0; ; i++) { |
| 3625 | reg = array[i].reg; |
| 3626 | val = array[i].val; |
| 3627 | |
| 3628 | if (reg == 0xffff && val == 0xffffffff) |
| 3629 | break; |
| 3630 | |
| 3631 | ret = rtl8xxxu_write32(priv, reg, val); |
| 3632 | if (ret != sizeof(val)) { |
| 3633 | dev_warn(&priv->udev->dev, |
| 3634 | "Failed to initialize PHY\n"); |
| 3635 | return -EAGAIN; |
| 3636 | } |
| 3637 | udelay(1); |
| 3638 | } |
| 3639 | |
| 3640 | return 0; |
| 3641 | } |
| 3642 | |
| 3643 | /* |
| 3644 | * Most of this is black magic retrieved from the old rtl8723au driver |
| 3645 | */ |
| 3646 | static int rtl8xxxu_init_phy_bb(struct rtl8xxxu_priv *priv) |
| 3647 | { |
| 3648 | u8 val8, ldoa15, ldov12d, lpldo, ldohci12; |
Jes Sorensen | 04313eb | 2016-02-29 17:04:51 -0500 | [diff] [blame] | 3649 | u16 val16; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3650 | u32 val32; |
| 3651 | |
| 3652 | /* |
| 3653 | * Todo: The vendor driver maintains a table of PHY register |
| 3654 | * addresses, which is initialized here. Do we need this? |
| 3655 | */ |
| 3656 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 3657 | if (priv->rtl_chip == RTL8723B) { |
Jes Sorensen | 8baf670 | 2016-02-29 17:04:54 -0500 | [diff] [blame] | 3658 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3659 | val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB | |
| 3660 | SYS_FUNC_DIO_RF; |
| 3661 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 3662 | |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 3663 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00); |
Jes Sorensen | 444004b | 2016-04-07 14:19:24 -0400 | [diff] [blame] | 3664 | } else if (priv->rtl_chip == RTL8192E) { |
| 3665 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3666 | val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB | |
| 3667 | SYS_FUNC_DIO_RF; |
| 3668 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 3669 | } else { |
| 3670 | val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL); |
| 3671 | udelay(2); |
| 3672 | val8 |= AFE_PLL_320_ENABLE; |
| 3673 | rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8); |
| 3674 | udelay(2); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3675 | |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 3676 | rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL + 1, 0xff); |
| 3677 | udelay(2); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3678 | |
Jes Sorensen | 8baf670 | 2016-02-29 17:04:54 -0500 | [diff] [blame] | 3679 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3680 | val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB; |
| 3681 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 3682 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3683 | |
Jes Sorensen | 2ca73dc | 2016-04-07 14:19:17 -0400 | [diff] [blame] | 3684 | if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E) { |
Jes Sorensen | 04313eb | 2016-02-29 17:04:51 -0500 | [diff] [blame] | 3685 | /* AFE_XTAL_RF_GATE (bit 14) if addressing as 32 bit register */ |
| 3686 | val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL); |
| 3687 | val32 &= ~AFE_XTAL_RF_GATE; |
| 3688 | if (priv->has_bluetooth) |
| 3689 | val32 &= ~AFE_XTAL_BT_GATE; |
| 3690 | rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32); |
| 3691 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3692 | |
| 3693 | /* 6. 0x1f[7:0] = 0x07 */ |
| 3694 | val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB; |
| 3695 | rtl8xxxu_write8(priv, REG_RF_CTRL, val8); |
| 3696 | |
Jes Sorensen | abd71bd | 2016-04-07 14:19:22 -0400 | [diff] [blame] | 3697 | if (priv->rtl_chip == RTL8723B) { |
Jes Sorensen | 8baf670 | 2016-02-29 17:04:54 -0500 | [diff] [blame] | 3698 | /* |
| 3699 | * Why? |
| 3700 | */ |
| 3701 | rtl8xxxu_write8(priv, REG_SYS_FUNC, 0xe3); |
| 3702 | rtl8xxxu_write8(priv, REG_AFE_XTAL_CTRL + 1, 0x80); |
Jes Sorensen | 36c3258 | 2016-02-29 17:04:14 -0500 | [diff] [blame] | 3703 | rtl8xxxu_init_phy_regs(priv, rtl8723b_phy_1t_init_table); |
Jes Sorensen | ae14c5d | 2016-04-07 14:19:21 -0400 | [diff] [blame] | 3704 | } else if (priv->rtl_chip == RTL8192E) { |
| 3705 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 3706 | val16 |= (SYS_FUNC_USBA | SYS_FUNC_USBD | SYS_FUNC_DIO_RF | |
| 3707 | SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB); |
| 3708 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 3709 | val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB; |
| 3710 | rtl8xxxu_write8(priv, REG_RF_CTRL, val8); |
| 3711 | rtl8xxxu_init_phy_regs(priv, rtl8192eu_phy_init_table); |
Jes Sorensen | abd71bd | 2016-04-07 14:19:22 -0400 | [diff] [blame] | 3712 | } else if (priv->hi_pa) |
| 3713 | rtl8xxxu_init_phy_regs(priv, rtl8188ru_phy_1t_highpa_table); |
| 3714 | else if (priv->tx_paths == 2) |
| 3715 | rtl8xxxu_init_phy_regs(priv, rtl8192cu_phy_2t_init_table); |
| 3716 | else |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3717 | rtl8xxxu_init_phy_regs(priv, rtl8723a_phy_1t_init_table); |
| 3718 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 3719 | if (priv->rtl_chip == RTL8188C && priv->hi_pa && |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3720 | priv->vendor_umc && priv->chip_cut == 1) |
| 3721 | rtl8xxxu_write8(priv, REG_OFDM0_AGC_PARM1 + 2, 0x50); |
| 3722 | |
| 3723 | if (priv->tx_paths == 1 && priv->rx_paths == 2) { |
| 3724 | /* |
| 3725 | * For 1T2R boards, patch the registers. |
| 3726 | * |
| 3727 | * It looks like 8191/2 1T2R boards use path B for TX |
| 3728 | */ |
| 3729 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_TX_INFO); |
| 3730 | val32 &= ~(BIT(0) | BIT(1)); |
| 3731 | val32 |= BIT(1); |
| 3732 | rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, val32); |
| 3733 | |
| 3734 | val32 = rtl8xxxu_read32(priv, REG_FPGA1_TX_INFO); |
| 3735 | val32 &= ~0x300033; |
| 3736 | val32 |= 0x200022; |
| 3737 | rtl8xxxu_write32(priv, REG_FPGA1_TX_INFO, val32); |
| 3738 | |
| 3739 | val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING); |
| 3740 | val32 &= 0xff000000; |
| 3741 | val32 |= 0x45000000; |
| 3742 | rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32); |
| 3743 | |
| 3744 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE); |
| 3745 | val32 &= ~(OFDM_RF_PATH_RX_MASK | OFDM_RF_PATH_TX_MASK); |
| 3746 | val32 |= (OFDM_RF_PATH_RX_A | OFDM_RF_PATH_RX_B | |
| 3747 | OFDM_RF_PATH_TX_B); |
| 3748 | rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32); |
| 3749 | |
| 3750 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGC_PARM1); |
| 3751 | val32 &= ~(BIT(4) | BIT(5)); |
| 3752 | val32 |= BIT(4); |
| 3753 | rtl8xxxu_write32(priv, REG_OFDM0_AGC_PARM1, val32); |
| 3754 | |
| 3755 | val32 = rtl8xxxu_read32(priv, REG_TX_CCK_RFON); |
| 3756 | val32 &= ~(BIT(27) | BIT(26)); |
| 3757 | val32 |= BIT(27); |
| 3758 | rtl8xxxu_write32(priv, REG_TX_CCK_RFON, val32); |
| 3759 | |
| 3760 | val32 = rtl8xxxu_read32(priv, REG_TX_CCK_BBON); |
| 3761 | val32 &= ~(BIT(27) | BIT(26)); |
| 3762 | val32 |= BIT(27); |
| 3763 | rtl8xxxu_write32(priv, REG_TX_CCK_BBON, val32); |
| 3764 | |
| 3765 | val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_RFON); |
| 3766 | val32 &= ~(BIT(27) | BIT(26)); |
| 3767 | val32 |= BIT(27); |
| 3768 | rtl8xxxu_write32(priv, REG_TX_OFDM_RFON, val32); |
| 3769 | |
| 3770 | val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_BBON); |
| 3771 | val32 &= ~(BIT(27) | BIT(26)); |
| 3772 | val32 |= BIT(27); |
| 3773 | rtl8xxxu_write32(priv, REG_TX_OFDM_BBON, val32); |
| 3774 | |
| 3775 | val32 = rtl8xxxu_read32(priv, REG_TX_TO_TX); |
| 3776 | val32 &= ~(BIT(27) | BIT(26)); |
| 3777 | val32 |= BIT(27); |
| 3778 | rtl8xxxu_write32(priv, REG_TX_TO_TX, val32); |
| 3779 | } |
| 3780 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 3781 | if (priv->rtl_chip == RTL8723B) |
Jes Sorensen | b9f498e | 2016-02-29 17:04:18 -0500 | [diff] [blame] | 3782 | rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8723bu_table); |
Jes Sorensen | e293278 | 2016-04-07 14:19:20 -0400 | [diff] [blame] | 3783 | else if (priv->rtl_chip == RTL8192E) { |
| 3784 | if (priv->hi_pa) |
| 3785 | rtl8xxxu_init_phy_regs(priv, |
| 3786 | rtl8xxx_agc_8192eu_highpa_table); |
| 3787 | else |
| 3788 | rtl8xxxu_init_phy_regs(priv, |
| 3789 | rtl8xxx_agc_8192eu_std_table); |
| 3790 | } else if (priv->hi_pa) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3791 | rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_highpa_table); |
| 3792 | else |
| 3793 | rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_standard_table); |
| 3794 | |
Jes Sorensen | 4ef22eb | 2016-02-29 17:04:55 -0500 | [diff] [blame] | 3795 | if (priv->has_xtalk) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3796 | val32 = rtl8xxxu_read32(priv, REG_MAC_PHY_CTRL); |
| 3797 | |
Jes Sorensen | 4ef22eb | 2016-02-29 17:04:55 -0500 | [diff] [blame] | 3798 | val8 = priv->xtalk; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3799 | val32 &= 0xff000fff; |
| 3800 | val32 |= ((val8 | (val8 << 6)) << 12); |
| 3801 | |
| 3802 | rtl8xxxu_write32(priv, REG_MAC_PHY_CTRL, val32); |
| 3803 | } |
| 3804 | |
Jes Sorensen | a069caa | 2016-03-31 17:08:42 -0400 | [diff] [blame] | 3805 | if (priv->rtl_chip != RTL8723B && priv->rtl_chip != RTL8192E) { |
Jes Sorensen | a0e262b | 2016-02-29 17:04:56 -0500 | [diff] [blame] | 3806 | ldoa15 = LDOA15_ENABLE | LDOA15_OBUF; |
| 3807 | ldov12d = LDOV12D_ENABLE | BIT(2) | (2 << LDOV12D_VADJ_SHIFT); |
| 3808 | ldohci12 = 0x57; |
| 3809 | lpldo = 1; |
| 3810 | val32 = (lpldo << 24) | (ldohci12 << 16) | |
| 3811 | (ldov12d << 8) | ldoa15; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3812 | |
Jes Sorensen | a0e262b | 2016-02-29 17:04:56 -0500 | [diff] [blame] | 3813 | rtl8xxxu_write32(priv, REG_LDOA15_CTRL, val32); |
| 3814 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3815 | |
| 3816 | return 0; |
| 3817 | } |
| 3818 | |
| 3819 | static int rtl8xxxu_init_rf_regs(struct rtl8xxxu_priv *priv, |
| 3820 | struct rtl8xxxu_rfregval *array, |
| 3821 | enum rtl8xxxu_rfpath path) |
| 3822 | { |
| 3823 | int i, ret; |
| 3824 | u8 reg; |
| 3825 | u32 val; |
| 3826 | |
| 3827 | for (i = 0; ; i++) { |
| 3828 | reg = array[i].reg; |
| 3829 | val = array[i].val; |
| 3830 | |
| 3831 | if (reg == 0xff && val == 0xffffffff) |
| 3832 | break; |
| 3833 | |
| 3834 | switch (reg) { |
| 3835 | case 0xfe: |
| 3836 | msleep(50); |
| 3837 | continue; |
| 3838 | case 0xfd: |
| 3839 | mdelay(5); |
| 3840 | continue; |
| 3841 | case 0xfc: |
| 3842 | mdelay(1); |
| 3843 | continue; |
| 3844 | case 0xfb: |
| 3845 | udelay(50); |
| 3846 | continue; |
| 3847 | case 0xfa: |
| 3848 | udelay(5); |
| 3849 | continue; |
| 3850 | case 0xf9: |
| 3851 | udelay(1); |
| 3852 | continue; |
| 3853 | } |
| 3854 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 3855 | ret = rtl8xxxu_write_rfreg(priv, path, reg, val); |
| 3856 | if (ret) { |
| 3857 | dev_warn(&priv->udev->dev, |
| 3858 | "Failed to initialize RF\n"); |
| 3859 | return -EAGAIN; |
| 3860 | } |
| 3861 | udelay(1); |
| 3862 | } |
| 3863 | |
| 3864 | return 0; |
| 3865 | } |
| 3866 | |
| 3867 | static int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv *priv, |
| 3868 | struct rtl8xxxu_rfregval *table, |
| 3869 | enum rtl8xxxu_rfpath path) |
| 3870 | { |
| 3871 | u32 val32; |
| 3872 | u16 val16, rfsi_rfenv; |
| 3873 | u16 reg_sw_ctrl, reg_int_oe, reg_hssi_parm2; |
| 3874 | |
| 3875 | switch (path) { |
| 3876 | case RF_A: |
| 3877 | reg_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL; |
| 3878 | reg_int_oe = REG_FPGA0_XA_RF_INT_OE; |
| 3879 | reg_hssi_parm2 = REG_FPGA0_XA_HSSI_PARM2; |
| 3880 | break; |
| 3881 | case RF_B: |
| 3882 | reg_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL; |
| 3883 | reg_int_oe = REG_FPGA0_XB_RF_INT_OE; |
| 3884 | reg_hssi_parm2 = REG_FPGA0_XB_HSSI_PARM2; |
| 3885 | break; |
| 3886 | default: |
| 3887 | dev_err(&priv->udev->dev, "%s:Unsupported RF path %c\n", |
| 3888 | __func__, path + 'A'); |
| 3889 | return -EINVAL; |
| 3890 | } |
| 3891 | /* For path B, use XB */ |
| 3892 | rfsi_rfenv = rtl8xxxu_read16(priv, reg_sw_ctrl); |
| 3893 | rfsi_rfenv &= FPGA0_RF_RFENV; |
| 3894 | |
| 3895 | /* |
| 3896 | * These two we might be able to optimize into one |
| 3897 | */ |
| 3898 | val32 = rtl8xxxu_read32(priv, reg_int_oe); |
| 3899 | val32 |= BIT(20); /* 0x10 << 16 */ |
| 3900 | rtl8xxxu_write32(priv, reg_int_oe, val32); |
| 3901 | udelay(1); |
| 3902 | |
| 3903 | val32 = rtl8xxxu_read32(priv, reg_int_oe); |
| 3904 | val32 |= BIT(4); |
| 3905 | rtl8xxxu_write32(priv, reg_int_oe, val32); |
| 3906 | udelay(1); |
| 3907 | |
| 3908 | /* |
| 3909 | * These two we might be able to optimize into one |
| 3910 | */ |
| 3911 | val32 = rtl8xxxu_read32(priv, reg_hssi_parm2); |
| 3912 | val32 &= ~FPGA0_HSSI_3WIRE_ADDR_LEN; |
| 3913 | rtl8xxxu_write32(priv, reg_hssi_parm2, val32); |
| 3914 | udelay(1); |
| 3915 | |
| 3916 | val32 = rtl8xxxu_read32(priv, reg_hssi_parm2); |
| 3917 | val32 &= ~FPGA0_HSSI_3WIRE_DATA_LEN; |
| 3918 | rtl8xxxu_write32(priv, reg_hssi_parm2, val32); |
| 3919 | udelay(1); |
| 3920 | |
| 3921 | rtl8xxxu_init_rf_regs(priv, table, path); |
| 3922 | |
| 3923 | /* For path B, use XB */ |
| 3924 | val16 = rtl8xxxu_read16(priv, reg_sw_ctrl); |
| 3925 | val16 &= ~FPGA0_RF_RFENV; |
| 3926 | val16 |= rfsi_rfenv; |
| 3927 | rtl8xxxu_write16(priv, reg_sw_ctrl, val16); |
| 3928 | |
| 3929 | return 0; |
| 3930 | } |
| 3931 | |
| 3932 | static int rtl8xxxu_llt_write(struct rtl8xxxu_priv *priv, u8 address, u8 data) |
| 3933 | { |
| 3934 | int ret = -EBUSY; |
| 3935 | int count = 0; |
| 3936 | u32 value; |
| 3937 | |
| 3938 | value = LLT_OP_WRITE | address << 8 | data; |
| 3939 | |
| 3940 | rtl8xxxu_write32(priv, REG_LLT_INIT, value); |
| 3941 | |
| 3942 | do { |
| 3943 | value = rtl8xxxu_read32(priv, REG_LLT_INIT); |
| 3944 | if ((value & LLT_OP_MASK) == LLT_OP_INACTIVE) { |
| 3945 | ret = 0; |
| 3946 | break; |
| 3947 | } |
| 3948 | } while (count++ < 20); |
| 3949 | |
| 3950 | return ret; |
| 3951 | } |
| 3952 | |
| 3953 | static int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page) |
| 3954 | { |
| 3955 | int ret; |
| 3956 | int i; |
| 3957 | |
| 3958 | for (i = 0; i < last_tx_page; i++) { |
| 3959 | ret = rtl8xxxu_llt_write(priv, i, i + 1); |
| 3960 | if (ret) |
| 3961 | goto exit; |
| 3962 | } |
| 3963 | |
| 3964 | ret = rtl8xxxu_llt_write(priv, last_tx_page, 0xff); |
| 3965 | if (ret) |
| 3966 | goto exit; |
| 3967 | |
| 3968 | /* Mark remaining pages as a ring buffer */ |
| 3969 | for (i = last_tx_page + 1; i < 0xff; i++) { |
| 3970 | ret = rtl8xxxu_llt_write(priv, i, (i + 1)); |
| 3971 | if (ret) |
| 3972 | goto exit; |
| 3973 | } |
| 3974 | |
| 3975 | /* Let last entry point to the start entry of ring buffer */ |
| 3976 | ret = rtl8xxxu_llt_write(priv, 0xff, last_tx_page + 1); |
| 3977 | if (ret) |
| 3978 | goto exit; |
| 3979 | |
| 3980 | exit: |
| 3981 | return ret; |
| 3982 | } |
| 3983 | |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 3984 | static int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page) |
| 3985 | { |
| 3986 | u32 val32; |
| 3987 | int ret = 0; |
| 3988 | int i; |
| 3989 | |
| 3990 | val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT); |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 3991 | val32 |= AUTO_LLT_INIT_LLT; |
| 3992 | rtl8xxxu_write32(priv, REG_AUTO_LLT, val32); |
| 3993 | |
| 3994 | for (i = 500; i; i--) { |
| 3995 | val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT); |
| 3996 | if (!(val32 & AUTO_LLT_INIT_LLT)) |
| 3997 | break; |
| 3998 | usleep_range(2, 4); |
| 3999 | } |
| 4000 | |
Jes Sorensen | 4de2481 | 2016-02-29 17:04:07 -0500 | [diff] [blame] | 4001 | if (!i) { |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 4002 | ret = -EBUSY; |
| 4003 | dev_warn(&priv->udev->dev, "LLT table init failed\n"); |
| 4004 | } |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 4005 | |
| 4006 | return ret; |
| 4007 | } |
| 4008 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 4009 | static int rtl8xxxu_init_queue_priority(struct rtl8xxxu_priv *priv) |
| 4010 | { |
| 4011 | u16 val16, hi, lo; |
| 4012 | u16 hiq, mgq, bkq, beq, viq, voq; |
| 4013 | int hip, mgp, bkp, bep, vip, vop; |
| 4014 | int ret = 0; |
| 4015 | |
| 4016 | switch (priv->ep_tx_count) { |
| 4017 | case 1: |
| 4018 | if (priv->ep_tx_high_queue) { |
| 4019 | hi = TRXDMA_QUEUE_HIGH; |
| 4020 | } else if (priv->ep_tx_low_queue) { |
| 4021 | hi = TRXDMA_QUEUE_LOW; |
| 4022 | } else if (priv->ep_tx_normal_queue) { |
| 4023 | hi = TRXDMA_QUEUE_NORMAL; |
| 4024 | } else { |
| 4025 | hi = 0; |
| 4026 | ret = -EINVAL; |
| 4027 | } |
| 4028 | |
| 4029 | hiq = hi; |
| 4030 | mgq = hi; |
| 4031 | bkq = hi; |
| 4032 | beq = hi; |
| 4033 | viq = hi; |
| 4034 | voq = hi; |
| 4035 | |
| 4036 | hip = 0; |
| 4037 | mgp = 0; |
| 4038 | bkp = 0; |
| 4039 | bep = 0; |
| 4040 | vip = 0; |
| 4041 | vop = 0; |
| 4042 | break; |
| 4043 | case 2: |
| 4044 | if (priv->ep_tx_high_queue && priv->ep_tx_low_queue) { |
| 4045 | hi = TRXDMA_QUEUE_HIGH; |
| 4046 | lo = TRXDMA_QUEUE_LOW; |
| 4047 | } else if (priv->ep_tx_normal_queue && priv->ep_tx_low_queue) { |
| 4048 | hi = TRXDMA_QUEUE_NORMAL; |
| 4049 | lo = TRXDMA_QUEUE_LOW; |
| 4050 | } else if (priv->ep_tx_high_queue && priv->ep_tx_normal_queue) { |
| 4051 | hi = TRXDMA_QUEUE_HIGH; |
| 4052 | lo = TRXDMA_QUEUE_NORMAL; |
| 4053 | } else { |
| 4054 | ret = -EINVAL; |
| 4055 | hi = 0; |
| 4056 | lo = 0; |
| 4057 | } |
| 4058 | |
| 4059 | hiq = hi; |
| 4060 | mgq = hi; |
| 4061 | bkq = lo; |
| 4062 | beq = lo; |
| 4063 | viq = hi; |
| 4064 | voq = hi; |
| 4065 | |
| 4066 | hip = 0; |
| 4067 | mgp = 0; |
| 4068 | bkp = 1; |
| 4069 | bep = 1; |
| 4070 | vip = 0; |
| 4071 | vop = 0; |
| 4072 | break; |
| 4073 | case 3: |
| 4074 | beq = TRXDMA_QUEUE_LOW; |
| 4075 | bkq = TRXDMA_QUEUE_LOW; |
| 4076 | viq = TRXDMA_QUEUE_NORMAL; |
| 4077 | voq = TRXDMA_QUEUE_HIGH; |
| 4078 | mgq = TRXDMA_QUEUE_HIGH; |
| 4079 | hiq = TRXDMA_QUEUE_HIGH; |
| 4080 | |
| 4081 | hip = hiq ^ 3; |
| 4082 | mgp = mgq ^ 3; |
| 4083 | bkp = bkq ^ 3; |
| 4084 | bep = beq ^ 3; |
| 4085 | vip = viq ^ 3; |
| 4086 | vop = viq ^ 3; |
| 4087 | break; |
| 4088 | default: |
| 4089 | ret = -EINVAL; |
| 4090 | } |
| 4091 | |
| 4092 | /* |
| 4093 | * None of the vendor drivers are configuring the beacon |
| 4094 | * queue here .... why? |
| 4095 | */ |
| 4096 | if (!ret) { |
| 4097 | val16 = rtl8xxxu_read16(priv, REG_TRXDMA_CTRL); |
| 4098 | val16 &= 0x7; |
| 4099 | val16 |= (voq << TRXDMA_CTRL_VOQ_SHIFT) | |
| 4100 | (viq << TRXDMA_CTRL_VIQ_SHIFT) | |
| 4101 | (beq << TRXDMA_CTRL_BEQ_SHIFT) | |
| 4102 | (bkq << TRXDMA_CTRL_BKQ_SHIFT) | |
| 4103 | (mgq << TRXDMA_CTRL_MGQ_SHIFT) | |
| 4104 | (hiq << TRXDMA_CTRL_HIQ_SHIFT); |
| 4105 | rtl8xxxu_write16(priv, REG_TRXDMA_CTRL, val16); |
| 4106 | |
| 4107 | priv->pipe_out[TXDESC_QUEUE_VO] = |
| 4108 | usb_sndbulkpipe(priv->udev, priv->out_ep[vop]); |
| 4109 | priv->pipe_out[TXDESC_QUEUE_VI] = |
| 4110 | usb_sndbulkpipe(priv->udev, priv->out_ep[vip]); |
| 4111 | priv->pipe_out[TXDESC_QUEUE_BE] = |
| 4112 | usb_sndbulkpipe(priv->udev, priv->out_ep[bep]); |
| 4113 | priv->pipe_out[TXDESC_QUEUE_BK] = |
| 4114 | usb_sndbulkpipe(priv->udev, priv->out_ep[bkp]); |
| 4115 | priv->pipe_out[TXDESC_QUEUE_BEACON] = |
| 4116 | usb_sndbulkpipe(priv->udev, priv->out_ep[0]); |
| 4117 | priv->pipe_out[TXDESC_QUEUE_MGNT] = |
| 4118 | usb_sndbulkpipe(priv->udev, priv->out_ep[mgp]); |
| 4119 | priv->pipe_out[TXDESC_QUEUE_HIGH] = |
| 4120 | usb_sndbulkpipe(priv->udev, priv->out_ep[hip]); |
| 4121 | priv->pipe_out[TXDESC_QUEUE_CMD] = |
| 4122 | usb_sndbulkpipe(priv->udev, priv->out_ep[0]); |
| 4123 | } |
| 4124 | |
| 4125 | return ret; |
| 4126 | } |
| 4127 | |
| 4128 | static void rtl8xxxu_fill_iqk_matrix_a(struct rtl8xxxu_priv *priv, |
| 4129 | bool iqk_ok, int result[][8], |
| 4130 | int candidate, bool tx_only) |
| 4131 | { |
| 4132 | u32 oldval, x, tx0_a, reg; |
| 4133 | int y, tx0_c; |
| 4134 | u32 val32; |
| 4135 | |
| 4136 | if (!iqk_ok) |
| 4137 | return; |
| 4138 | |
| 4139 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE); |
| 4140 | oldval = val32 >> 22; |
| 4141 | |
| 4142 | x = result[candidate][0]; |
| 4143 | if ((x & 0x00000200) != 0) |
| 4144 | x = x | 0xfffffc00; |
| 4145 | tx0_a = (x * oldval) >> 8; |
| 4146 | |
| 4147 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE); |
| 4148 | val32 &= ~0x3ff; |
| 4149 | val32 |= tx0_a; |
| 4150 | rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32); |
| 4151 | |
| 4152 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES); |
| 4153 | val32 &= ~BIT(31); |
| 4154 | if ((x * oldval >> 7) & 0x1) |
| 4155 | val32 |= BIT(31); |
| 4156 | rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32); |
| 4157 | |
| 4158 | y = result[candidate][1]; |
| 4159 | if ((y & 0x00000200) != 0) |
| 4160 | y = y | 0xfffffc00; |
| 4161 | tx0_c = (y * oldval) >> 8; |
| 4162 | |
| 4163 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XC_TX_AFE); |
| 4164 | val32 &= ~0xf0000000; |
| 4165 | val32 |= (((tx0_c & 0x3c0) >> 6) << 28); |
| 4166 | rtl8xxxu_write32(priv, REG_OFDM0_XC_TX_AFE, val32); |
| 4167 | |
| 4168 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE); |
| 4169 | val32 &= ~0x003f0000; |
| 4170 | val32 |= ((tx0_c & 0x3f) << 16); |
| 4171 | rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32); |
| 4172 | |
| 4173 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES); |
| 4174 | val32 &= ~BIT(29); |
| 4175 | if ((y * oldval >> 7) & 0x1) |
| 4176 | val32 |= BIT(29); |
| 4177 | rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32); |
| 4178 | |
| 4179 | if (tx_only) { |
| 4180 | dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__); |
| 4181 | return; |
| 4182 | } |
| 4183 | |
| 4184 | reg = result[candidate][2]; |
| 4185 | |
| 4186 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE); |
| 4187 | val32 &= ~0x3ff; |
| 4188 | val32 |= (reg & 0x3ff); |
| 4189 | rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32); |
| 4190 | |
| 4191 | reg = result[candidate][3] & 0x3F; |
| 4192 | |
| 4193 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE); |
| 4194 | val32 &= ~0xfc00; |
| 4195 | val32 |= ((reg << 10) & 0xfc00); |
| 4196 | rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32); |
| 4197 | |
| 4198 | reg = (result[candidate][3] >> 6) & 0xF; |
| 4199 | |
| 4200 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_RX_IQ_EXT_ANTA); |
| 4201 | val32 &= ~0xf0000000; |
| 4202 | val32 |= (reg << 28); |
| 4203 | rtl8xxxu_write32(priv, REG_OFDM0_RX_IQ_EXT_ANTA, val32); |
| 4204 | } |
| 4205 | |
| 4206 | static void rtl8xxxu_fill_iqk_matrix_b(struct rtl8xxxu_priv *priv, |
| 4207 | bool iqk_ok, int result[][8], |
| 4208 | int candidate, bool tx_only) |
| 4209 | { |
| 4210 | u32 oldval, x, tx1_a, reg; |
| 4211 | int y, tx1_c; |
| 4212 | u32 val32; |
| 4213 | |
| 4214 | if (!iqk_ok) |
| 4215 | return; |
| 4216 | |
| 4217 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE); |
| 4218 | oldval = val32 >> 22; |
| 4219 | |
| 4220 | x = result[candidate][4]; |
| 4221 | if ((x & 0x00000200) != 0) |
| 4222 | x = x | 0xfffffc00; |
| 4223 | tx1_a = (x * oldval) >> 8; |
| 4224 | |
| 4225 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE); |
| 4226 | val32 &= ~0x3ff; |
| 4227 | val32 |= tx1_a; |
| 4228 | rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32); |
| 4229 | |
| 4230 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES); |
| 4231 | val32 &= ~BIT(27); |
| 4232 | if ((x * oldval >> 7) & 0x1) |
| 4233 | val32 |= BIT(27); |
| 4234 | rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32); |
| 4235 | |
| 4236 | y = result[candidate][5]; |
| 4237 | if ((y & 0x00000200) != 0) |
| 4238 | y = y | 0xfffffc00; |
| 4239 | tx1_c = (y * oldval) >> 8; |
| 4240 | |
| 4241 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XD_TX_AFE); |
| 4242 | val32 &= ~0xf0000000; |
| 4243 | val32 |= (((tx1_c & 0x3c0) >> 6) << 28); |
| 4244 | rtl8xxxu_write32(priv, REG_OFDM0_XD_TX_AFE, val32); |
| 4245 | |
| 4246 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE); |
| 4247 | val32 &= ~0x003f0000; |
| 4248 | val32 |= ((tx1_c & 0x3f) << 16); |
| 4249 | rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32); |
| 4250 | |
| 4251 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES); |
| 4252 | val32 &= ~BIT(25); |
| 4253 | if ((y * oldval >> 7) & 0x1) |
| 4254 | val32 |= BIT(25); |
| 4255 | rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32); |
| 4256 | |
| 4257 | if (tx_only) { |
| 4258 | dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__); |
| 4259 | return; |
| 4260 | } |
| 4261 | |
| 4262 | reg = result[candidate][6]; |
| 4263 | |
| 4264 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE); |
| 4265 | val32 &= ~0x3ff; |
| 4266 | val32 |= (reg & 0x3ff); |
| 4267 | rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32); |
| 4268 | |
| 4269 | reg = result[candidate][7] & 0x3f; |
| 4270 | |
| 4271 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE); |
| 4272 | val32 &= ~0xfc00; |
| 4273 | val32 |= ((reg << 10) & 0xfc00); |
| 4274 | rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32); |
| 4275 | |
| 4276 | reg = (result[candidate][7] >> 6) & 0xf; |
| 4277 | |
| 4278 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGCR_SSI_TABLE); |
| 4279 | val32 &= ~0x0000f000; |
| 4280 | val32 |= (reg << 12); |
| 4281 | rtl8xxxu_write32(priv, REG_OFDM0_AGCR_SSI_TABLE, val32); |
| 4282 | } |
| 4283 | |
| 4284 | #define MAX_TOLERANCE 5 |
| 4285 | |
| 4286 | static bool rtl8xxxu_simularity_compare(struct rtl8xxxu_priv *priv, |
| 4287 | int result[][8], int c1, int c2) |
| 4288 | { |
| 4289 | u32 i, j, diff, simubitmap, bound = 0; |
| 4290 | int candidate[2] = {-1, -1}; /* for path A and path B */ |
| 4291 | bool retval = true; |
| 4292 | |
| 4293 | if (priv->tx_paths > 1) |
| 4294 | bound = 8; |
| 4295 | else |
| 4296 | bound = 4; |
| 4297 | |
| 4298 | simubitmap = 0; |
| 4299 | |
| 4300 | for (i = 0; i < bound; i++) { |
| 4301 | diff = (result[c1][i] > result[c2][i]) ? |
| 4302 | (result[c1][i] - result[c2][i]) : |
| 4303 | (result[c2][i] - result[c1][i]); |
| 4304 | if (diff > MAX_TOLERANCE) { |
| 4305 | if ((i == 2 || i == 6) && !simubitmap) { |
| 4306 | if (result[c1][i] + result[c1][i + 1] == 0) |
| 4307 | candidate[(i / 4)] = c2; |
| 4308 | else if (result[c2][i] + result[c2][i + 1] == 0) |
| 4309 | candidate[(i / 4)] = c1; |
| 4310 | else |
| 4311 | simubitmap = simubitmap | (1 << i); |
| 4312 | } else { |
| 4313 | simubitmap = simubitmap | (1 << i); |
| 4314 | } |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | if (simubitmap == 0) { |
| 4319 | for (i = 0; i < (bound / 4); i++) { |
| 4320 | if (candidate[i] >= 0) { |
| 4321 | for (j = i * 4; j < (i + 1) * 4 - 2; j++) |
| 4322 | result[3][j] = result[candidate[i]][j]; |
| 4323 | retval = false; |
| 4324 | } |
| 4325 | } |
| 4326 | return retval; |
| 4327 | } else if (!(simubitmap & 0x0f)) { |
| 4328 | /* path A OK */ |
| 4329 | for (i = 0; i < 4; i++) |
| 4330 | result[3][i] = result[c1][i]; |
| 4331 | } else if (!(simubitmap & 0xf0) && priv->tx_paths > 1) { |
| 4332 | /* path B OK */ |
| 4333 | for (i = 4; i < 8; i++) |
| 4334 | result[3][i] = result[c1][i]; |
| 4335 | } |
| 4336 | |
| 4337 | return false; |
| 4338 | } |
| 4339 | |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 4340 | static bool rtl8723bu_simularity_compare(struct rtl8xxxu_priv *priv, |
| 4341 | int result[][8], int c1, int c2) |
| 4342 | { |
| 4343 | u32 i, j, diff, simubitmap, bound = 0; |
| 4344 | int candidate[2] = {-1, -1}; /* for path A and path B */ |
| 4345 | int tmp1, tmp2; |
| 4346 | bool retval = true; |
| 4347 | |
| 4348 | if (priv->tx_paths > 1) |
| 4349 | bound = 8; |
| 4350 | else |
| 4351 | bound = 4; |
| 4352 | |
| 4353 | simubitmap = 0; |
| 4354 | |
| 4355 | for (i = 0; i < bound; i++) { |
| 4356 | if (i & 1) { |
| 4357 | if ((result[c1][i] & 0x00000200)) |
| 4358 | tmp1 = result[c1][i] | 0xfffffc00; |
| 4359 | else |
| 4360 | tmp1 = result[c1][i]; |
| 4361 | |
| 4362 | if ((result[c2][i]& 0x00000200)) |
| 4363 | tmp2 = result[c2][i] | 0xfffffc00; |
| 4364 | else |
| 4365 | tmp2 = result[c2][i]; |
| 4366 | } else { |
| 4367 | tmp1 = result[c1][i]; |
| 4368 | tmp2 = result[c2][i]; |
| 4369 | } |
| 4370 | |
| 4371 | diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1); |
| 4372 | |
| 4373 | if (diff > MAX_TOLERANCE) { |
| 4374 | if ((i == 2 || i == 6) && !simubitmap) { |
| 4375 | if (result[c1][i] + result[c1][i + 1] == 0) |
| 4376 | candidate[(i / 4)] = c2; |
| 4377 | else if (result[c2][i] + result[c2][i + 1] == 0) |
| 4378 | candidate[(i / 4)] = c1; |
| 4379 | else |
| 4380 | simubitmap = simubitmap | (1 << i); |
| 4381 | } else { |
| 4382 | simubitmap = simubitmap | (1 << i); |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | if (simubitmap == 0) { |
| 4388 | for (i = 0; i < (bound / 4); i++) { |
| 4389 | if (candidate[i] >= 0) { |
| 4390 | for (j = i * 4; j < (i + 1) * 4 - 2; j++) |
| 4391 | result[3][j] = result[candidate[i]][j]; |
| 4392 | retval = false; |
| 4393 | } |
| 4394 | } |
| 4395 | return retval; |
| 4396 | } else { |
| 4397 | if (!(simubitmap & 0x03)) { |
| 4398 | /* path A TX OK */ |
| 4399 | for (i = 0; i < 2; i++) |
| 4400 | result[3][i] = result[c1][i]; |
| 4401 | } |
| 4402 | |
| 4403 | if (!(simubitmap & 0x0c)) { |
| 4404 | /* path A RX OK */ |
| 4405 | for (i = 2; i < 4; i++) |
| 4406 | result[3][i] = result[c1][i]; |
| 4407 | } |
| 4408 | |
| 4409 | if (!(simubitmap & 0x30) && priv->tx_paths > 1) { |
| 4410 | /* path B RX OK */ |
| 4411 | for (i = 4; i < 6; i++) |
| 4412 | result[3][i] = result[c1][i]; |
| 4413 | } |
| 4414 | |
| 4415 | if (!(simubitmap & 0x30) && priv->tx_paths > 1) { |
| 4416 | /* path B RX OK */ |
| 4417 | for (i = 6; i < 8; i++) |
| 4418 | result[3][i] = result[c1][i]; |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | return false; |
| 4423 | } |
| 4424 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 4425 | static void |
| 4426 | rtl8xxxu_save_mac_regs(struct rtl8xxxu_priv *priv, const u32 *reg, u32 *backup) |
| 4427 | { |
| 4428 | int i; |
| 4429 | |
| 4430 | for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++) |
| 4431 | backup[i] = rtl8xxxu_read8(priv, reg[i]); |
| 4432 | |
| 4433 | backup[i] = rtl8xxxu_read32(priv, reg[i]); |
| 4434 | } |
| 4435 | |
| 4436 | static void rtl8xxxu_restore_mac_regs(struct rtl8xxxu_priv *priv, |
| 4437 | const u32 *reg, u32 *backup) |
| 4438 | { |
| 4439 | int i; |
| 4440 | |
| 4441 | for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++) |
| 4442 | rtl8xxxu_write8(priv, reg[i], backup[i]); |
| 4443 | |
| 4444 | rtl8xxxu_write32(priv, reg[i], backup[i]); |
| 4445 | } |
| 4446 | |
| 4447 | static void rtl8xxxu_save_regs(struct rtl8xxxu_priv *priv, const u32 *regs, |
| 4448 | u32 *backup, int count) |
| 4449 | { |
| 4450 | int i; |
| 4451 | |
| 4452 | for (i = 0; i < count; i++) |
| 4453 | backup[i] = rtl8xxxu_read32(priv, regs[i]); |
| 4454 | } |
| 4455 | |
| 4456 | static void rtl8xxxu_restore_regs(struct rtl8xxxu_priv *priv, const u32 *regs, |
| 4457 | u32 *backup, int count) |
| 4458 | { |
| 4459 | int i; |
| 4460 | |
| 4461 | for (i = 0; i < count; i++) |
| 4462 | rtl8xxxu_write32(priv, regs[i], backup[i]); |
| 4463 | } |
| 4464 | |
| 4465 | |
| 4466 | static void rtl8xxxu_path_adda_on(struct rtl8xxxu_priv *priv, const u32 *regs, |
| 4467 | bool path_a_on) |
| 4468 | { |
| 4469 | u32 path_on; |
| 4470 | int i; |
| 4471 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 4472 | if (priv->tx_paths == 1) { |
Jes Sorensen | 8634af5 | 2016-02-29 17:04:33 -0500 | [diff] [blame] | 4473 | path_on = priv->fops->adda_1t_path_on; |
| 4474 | rtl8xxxu_write32(priv, regs[0], priv->fops->adda_1t_init); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 4475 | } else { |
Jes Sorensen | 8634af5 | 2016-02-29 17:04:33 -0500 | [diff] [blame] | 4476 | path_on = path_a_on ? priv->fops->adda_2t_path_on_a : |
| 4477 | priv->fops->adda_2t_path_on_b; |
| 4478 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 4479 | rtl8xxxu_write32(priv, regs[0], path_on); |
| 4480 | } |
| 4481 | |
| 4482 | for (i = 1 ; i < RTL8XXXU_ADDA_REGS ; i++) |
| 4483 | rtl8xxxu_write32(priv, regs[i], path_on); |
| 4484 | } |
| 4485 | |
| 4486 | static void rtl8xxxu_mac_calibration(struct rtl8xxxu_priv *priv, |
| 4487 | const u32 *regs, u32 *backup) |
| 4488 | { |
| 4489 | int i = 0; |
| 4490 | |
| 4491 | rtl8xxxu_write8(priv, regs[i], 0x3f); |
| 4492 | |
| 4493 | for (i = 1 ; i < (RTL8XXXU_MAC_REGS - 1); i++) |
| 4494 | rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(3))); |
| 4495 | |
| 4496 | rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(5))); |
| 4497 | } |
| 4498 | |
| 4499 | static int rtl8xxxu_iqk_path_a(struct rtl8xxxu_priv *priv) |
| 4500 | { |
| 4501 | u32 reg_eac, reg_e94, reg_e9c, reg_ea4, val32; |
| 4502 | int result = 0; |
| 4503 | |
| 4504 | /* path-A IQK setting */ |
| 4505 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1f); |
| 4506 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x10008c1f); |
| 4507 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82140102); |
| 4508 | |
| 4509 | val32 = (priv->rf_paths > 1) ? 0x28160202 : |
| 4510 | /*IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)?0x28160202: */ |
| 4511 | 0x28160502; |
| 4512 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, val32); |
| 4513 | |
| 4514 | /* path-B IQK setting */ |
| 4515 | if (priv->rf_paths > 1) { |
| 4516 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x10008c22); |
| 4517 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x10008c22); |
| 4518 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82140102); |
| 4519 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28160202); |
| 4520 | } |
| 4521 | |
| 4522 | /* LO calibration setting */ |
| 4523 | rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x001028d1); |
| 4524 | |
| 4525 | /* One shot, path A LOK & IQK */ |
| 4526 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); |
| 4527 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); |
| 4528 | |
| 4529 | mdelay(1); |
| 4530 | |
| 4531 | /* Check failed */ |
| 4532 | reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); |
| 4533 | reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A); |
| 4534 | reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A); |
| 4535 | reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2); |
| 4536 | |
| 4537 | if (!(reg_eac & BIT(28)) && |
| 4538 | ((reg_e94 & 0x03ff0000) != 0x01420000) && |
| 4539 | ((reg_e9c & 0x03ff0000) != 0x00420000)) |
| 4540 | result |= 0x01; |
| 4541 | else /* If TX not OK, ignore RX */ |
| 4542 | goto out; |
| 4543 | |
| 4544 | /* If TX is OK, check whether RX is OK */ |
| 4545 | if (!(reg_eac & BIT(27)) && |
| 4546 | ((reg_ea4 & 0x03ff0000) != 0x01320000) && |
| 4547 | ((reg_eac & 0x03ff0000) != 0x00360000)) |
| 4548 | result |= 0x02; |
| 4549 | else |
| 4550 | dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n", |
| 4551 | __func__); |
| 4552 | out: |
| 4553 | return result; |
| 4554 | } |
| 4555 | |
| 4556 | static int rtl8xxxu_iqk_path_b(struct rtl8xxxu_priv *priv) |
| 4557 | { |
| 4558 | u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc; |
| 4559 | int result = 0; |
| 4560 | |
| 4561 | /* One shot, path B LOK & IQK */ |
| 4562 | rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002); |
| 4563 | rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000); |
| 4564 | |
| 4565 | mdelay(1); |
| 4566 | |
| 4567 | /* Check failed */ |
| 4568 | reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); |
| 4569 | reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B); |
| 4570 | reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B); |
| 4571 | reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2); |
| 4572 | reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2); |
| 4573 | |
| 4574 | if (!(reg_eac & BIT(31)) && |
| 4575 | ((reg_eb4 & 0x03ff0000) != 0x01420000) && |
| 4576 | ((reg_ebc & 0x03ff0000) != 0x00420000)) |
| 4577 | result |= 0x01; |
| 4578 | else |
| 4579 | goto out; |
| 4580 | |
| 4581 | if (!(reg_eac & BIT(30)) && |
| 4582 | (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) && |
| 4583 | (((reg_ecc & 0x03ff0000) >> 16) != 0x36)) |
| 4584 | result |= 0x02; |
| 4585 | else |
| 4586 | dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n", |
| 4587 | __func__); |
| 4588 | out: |
| 4589 | return result; |
| 4590 | } |
| 4591 | |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 4592 | static int rtl8723bu_iqk_path_a(struct rtl8xxxu_priv *priv) |
| 4593 | { |
| 4594 | u32 reg_eac, reg_e94, reg_e9c, path_sel, val32; |
| 4595 | int result = 0; |
| 4596 | |
| 4597 | path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH); |
| 4598 | |
| 4599 | /* |
| 4600 | * Leave IQK mode |
| 4601 | */ |
| 4602 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4603 | val32 &= 0x000000ff; |
| 4604 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4605 | |
| 4606 | /* |
| 4607 | * Enable path A PA in TX IQK mode |
| 4608 | */ |
| 4609 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); |
| 4610 | val32 |= 0x80000; |
| 4611 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); |
| 4612 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x20000); |
| 4613 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0003f); |
| 4614 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xc7f87); |
| 4615 | |
| 4616 | /* |
| 4617 | * Tx IQK setting |
| 4618 | */ |
| 4619 | rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00); |
| 4620 | rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); |
| 4621 | |
| 4622 | /* path-A IQK setting */ |
| 4623 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c); |
| 4624 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c); |
| 4625 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c); |
| 4626 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c); |
| 4627 | |
| 4628 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x821403ea); |
| 4629 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000); |
| 4630 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000); |
| 4631 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000); |
| 4632 | |
| 4633 | /* LO calibration setting */ |
| 4634 | rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x00462911); |
| 4635 | |
| 4636 | /* |
| 4637 | * Enter IQK mode |
| 4638 | */ |
| 4639 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4640 | val32 &= 0x000000ff; |
| 4641 | val32 |= 0x80800000; |
| 4642 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4643 | |
| 4644 | /* |
| 4645 | * The vendor driver indicates the USB module is always using |
| 4646 | * S0S1 path 1 for the 8723bu. This may be different for 8192eu |
| 4647 | */ |
| 4648 | if (priv->rf_paths > 1) |
| 4649 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000); |
| 4650 | else |
| 4651 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280); |
| 4652 | |
| 4653 | /* |
| 4654 | * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu. |
| 4655 | * No trace of this in the 8192eu or 8188eu vendor drivers. |
| 4656 | */ |
| 4657 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800); |
| 4658 | |
| 4659 | /* One shot, path A LOK & IQK */ |
| 4660 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); |
| 4661 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); |
| 4662 | |
| 4663 | mdelay(1); |
| 4664 | |
| 4665 | /* Restore Ant Path */ |
| 4666 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel); |
| 4667 | #ifdef RTL8723BU_BT |
| 4668 | /* GNT_BT = 1 */ |
| 4669 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800); |
| 4670 | #endif |
| 4671 | |
| 4672 | /* |
| 4673 | * Leave IQK mode |
| 4674 | */ |
| 4675 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4676 | val32 &= 0x000000ff; |
| 4677 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4678 | |
| 4679 | /* Check failed */ |
| 4680 | reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); |
| 4681 | reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A); |
| 4682 | reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A); |
| 4683 | |
| 4684 | val32 = (reg_e9c >> 16) & 0x3ff; |
| 4685 | if (val32 & 0x200) |
| 4686 | val32 = 0x400 - val32; |
| 4687 | |
| 4688 | if (!(reg_eac & BIT(28)) && |
| 4689 | ((reg_e94 & 0x03ff0000) != 0x01420000) && |
| 4690 | ((reg_e9c & 0x03ff0000) != 0x00420000) && |
| 4691 | ((reg_e94 & 0x03ff0000) < 0x01100000) && |
| 4692 | ((reg_e94 & 0x03ff0000) > 0x00f00000) && |
| 4693 | val32 < 0xf) |
| 4694 | result |= 0x01; |
| 4695 | else /* If TX not OK, ignore RX */ |
| 4696 | goto out; |
| 4697 | |
| 4698 | out: |
| 4699 | return result; |
| 4700 | } |
| 4701 | |
| 4702 | static int rtl8723bu_rx_iqk_path_a(struct rtl8xxxu_priv *priv) |
| 4703 | { |
| 4704 | u32 reg_ea4, reg_eac, reg_e94, reg_e9c, path_sel, val32; |
| 4705 | int result = 0; |
| 4706 | |
| 4707 | path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH); |
| 4708 | |
| 4709 | /* |
| 4710 | * Leave IQK mode |
| 4711 | */ |
| 4712 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4713 | val32 &= 0x000000ff; |
| 4714 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4715 | |
| 4716 | /* |
| 4717 | * Enable path A PA in TX IQK mode |
| 4718 | */ |
| 4719 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); |
| 4720 | val32 |= 0x80000; |
| 4721 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); |
| 4722 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000); |
| 4723 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); |
| 4724 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7); |
| 4725 | |
| 4726 | /* |
| 4727 | * Tx IQK setting |
| 4728 | */ |
| 4729 | rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00); |
| 4730 | rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); |
| 4731 | |
| 4732 | /* path-A IQK setting */ |
| 4733 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x18008c1c); |
| 4734 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x38008c1c); |
| 4735 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c); |
| 4736 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c); |
| 4737 | |
| 4738 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82160ff0); |
| 4739 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28110000); |
| 4740 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000); |
| 4741 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000); |
| 4742 | |
| 4743 | /* LO calibration setting */ |
| 4744 | rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a911); |
| 4745 | |
| 4746 | /* |
| 4747 | * Enter IQK mode |
| 4748 | */ |
| 4749 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4750 | val32 &= 0x000000ff; |
| 4751 | val32 |= 0x80800000; |
| 4752 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4753 | |
| 4754 | /* |
| 4755 | * The vendor driver indicates the USB module is always using |
| 4756 | * S0S1 path 1 for the 8723bu. This may be different for 8192eu |
| 4757 | */ |
| 4758 | if (priv->rf_paths > 1) |
| 4759 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000); |
| 4760 | else |
| 4761 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280); |
| 4762 | |
| 4763 | /* |
| 4764 | * Bit 12 seems to be BT_GRANT, and is only found in the 8723bu. |
| 4765 | * No trace of this in the 8192eu or 8188eu vendor drivers. |
| 4766 | */ |
| 4767 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800); |
| 4768 | |
| 4769 | /* One shot, path A LOK & IQK */ |
| 4770 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); |
| 4771 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); |
| 4772 | |
| 4773 | mdelay(1); |
| 4774 | |
| 4775 | /* Restore Ant Path */ |
| 4776 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel); |
| 4777 | #ifdef RTL8723BU_BT |
| 4778 | /* GNT_BT = 1 */ |
| 4779 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800); |
| 4780 | #endif |
| 4781 | |
| 4782 | /* |
| 4783 | * Leave IQK mode |
| 4784 | */ |
| 4785 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4786 | val32 &= 0x000000ff; |
| 4787 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4788 | |
| 4789 | /* Check failed */ |
| 4790 | reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); |
| 4791 | reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A); |
| 4792 | reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A); |
| 4793 | |
| 4794 | val32 = (reg_e9c >> 16) & 0x3ff; |
| 4795 | if (val32 & 0x200) |
| 4796 | val32 = 0x400 - val32; |
| 4797 | |
| 4798 | if (!(reg_eac & BIT(28)) && |
| 4799 | ((reg_e94 & 0x03ff0000) != 0x01420000) && |
| 4800 | ((reg_e9c & 0x03ff0000) != 0x00420000) && |
| 4801 | ((reg_e94 & 0x03ff0000) < 0x01100000) && |
| 4802 | ((reg_e94 & 0x03ff0000) > 0x00f00000) && |
| 4803 | val32 < 0xf) |
| 4804 | result |= 0x01; |
| 4805 | else /* If TX not OK, ignore RX */ |
| 4806 | goto out; |
| 4807 | |
| 4808 | val32 = 0x80007c00 | (reg_e94 &0x3ff0000) | |
| 4809 | ((reg_e9c & 0x3ff0000) >> 16); |
| 4810 | rtl8xxxu_write32(priv, REG_TX_IQK, val32); |
| 4811 | |
| 4812 | /* |
| 4813 | * Modify RX IQK mode |
| 4814 | */ |
| 4815 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4816 | val32 &= 0x000000ff; |
| 4817 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4818 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); |
| 4819 | val32 |= 0x80000; |
| 4820 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); |
| 4821 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000); |
| 4822 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); |
| 4823 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7d77); |
| 4824 | |
| 4825 | /* |
| 4826 | * PA, PAD setting |
| 4827 | */ |
| 4828 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0xf80); |
| 4829 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_55, 0x4021f); |
| 4830 | |
| 4831 | /* |
| 4832 | * RX IQK setting |
| 4833 | */ |
| 4834 | rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); |
| 4835 | |
| 4836 | /* path-A IQK setting */ |
| 4837 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x38008c1c); |
| 4838 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x18008c1c); |
| 4839 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x38008c1c); |
| 4840 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x38008c1c); |
| 4841 | |
| 4842 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82110000); |
| 4843 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x2816001f); |
| 4844 | rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82110000); |
| 4845 | rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28110000); |
| 4846 | |
| 4847 | /* LO calibration setting */ |
| 4848 | rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a8d1); |
| 4849 | |
| 4850 | /* |
| 4851 | * Enter IQK mode |
| 4852 | */ |
| 4853 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4854 | val32 &= 0x000000ff; |
| 4855 | val32 |= 0x80800000; |
| 4856 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4857 | |
| 4858 | if (priv->rf_paths > 1) |
| 4859 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000000); |
| 4860 | else |
| 4861 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00000280); |
| 4862 | |
| 4863 | /* |
| 4864 | * Disable BT |
| 4865 | */ |
| 4866 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00000800); |
| 4867 | |
| 4868 | /* One shot, path A LOK & IQK */ |
| 4869 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000); |
| 4870 | rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000); |
| 4871 | |
| 4872 | mdelay(1); |
| 4873 | |
| 4874 | /* Restore Ant Path */ |
| 4875 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, path_sel); |
| 4876 | #ifdef RTL8723BU_BT |
| 4877 | /* GNT_BT = 1 */ |
| 4878 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, 0x00001800); |
| 4879 | #endif |
| 4880 | |
| 4881 | /* |
| 4882 | * Leave IQK mode |
| 4883 | */ |
| 4884 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4885 | val32 &= 0x000000ff; |
| 4886 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4887 | |
| 4888 | /* Check failed */ |
| 4889 | reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); |
| 4890 | reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2); |
| 4891 | |
| 4892 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x780); |
| 4893 | |
| 4894 | val32 = (reg_eac >> 16) & 0x3ff; |
| 4895 | if (val32 & 0x200) |
| 4896 | val32 = 0x400 - val32; |
| 4897 | |
| 4898 | if (!(reg_eac & BIT(27)) && |
| 4899 | ((reg_ea4 & 0x03ff0000) != 0x01320000) && |
| 4900 | ((reg_eac & 0x03ff0000) != 0x00360000) && |
| 4901 | ((reg_ea4 & 0x03ff0000) < 0x01100000) && |
| 4902 | ((reg_ea4 & 0x03ff0000) > 0x00f00000) && |
| 4903 | val32 < 0xf) |
| 4904 | result |= 0x02; |
| 4905 | else /* If TX not OK, ignore RX */ |
| 4906 | goto out; |
| 4907 | out: |
| 4908 | return result; |
| 4909 | } |
| 4910 | |
| 4911 | #ifdef RTL8723BU_PATH_B |
| 4912 | static int rtl8723bu_iqk_path_b(struct rtl8xxxu_priv *priv) |
| 4913 | { |
| 4914 | u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc, path_sel; |
| 4915 | int result = 0; |
| 4916 | |
| 4917 | path_sel = rtl8xxxu_read32(priv, REG_S0S1_PATH_SWITCH); |
| 4918 | |
| 4919 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 4920 | val32 &= 0x000000ff; |
| 4921 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 4922 | |
| 4923 | /* One shot, path B LOK & IQK */ |
| 4924 | rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002); |
| 4925 | rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000); |
| 4926 | |
| 4927 | mdelay(1); |
| 4928 | |
| 4929 | /* Check failed */ |
| 4930 | reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2); |
| 4931 | reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B); |
| 4932 | reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B); |
| 4933 | reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2); |
| 4934 | reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2); |
| 4935 | |
| 4936 | if (!(reg_eac & BIT(31)) && |
| 4937 | ((reg_eb4 & 0x03ff0000) != 0x01420000) && |
| 4938 | ((reg_ebc & 0x03ff0000) != 0x00420000)) |
| 4939 | result |= 0x01; |
| 4940 | else |
| 4941 | goto out; |
| 4942 | |
| 4943 | if (!(reg_eac & BIT(30)) && |
| 4944 | (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) && |
| 4945 | (((reg_ecc & 0x03ff0000) >> 16) != 0x36)) |
| 4946 | result |= 0x02; |
| 4947 | else |
| 4948 | dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n", |
| 4949 | __func__); |
| 4950 | out: |
| 4951 | return result; |
| 4952 | } |
| 4953 | #endif |
| 4954 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 4955 | static void rtl8xxxu_phy_iqcalibrate(struct rtl8xxxu_priv *priv, |
| 4956 | int result[][8], int t) |
| 4957 | { |
| 4958 | struct device *dev = &priv->udev->dev; |
| 4959 | u32 i, val32; |
| 4960 | int path_a_ok, path_b_ok; |
| 4961 | int retry = 2; |
| 4962 | const u32 adda_regs[RTL8XXXU_ADDA_REGS] = { |
| 4963 | REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH, |
| 4964 | REG_RX_WAIT_CCA, REG_TX_CCK_RFON, |
| 4965 | REG_TX_CCK_BBON, REG_TX_OFDM_RFON, |
| 4966 | REG_TX_OFDM_BBON, REG_TX_TO_RX, |
| 4967 | REG_TX_TO_TX, REG_RX_CCK, |
| 4968 | REG_RX_OFDM, REG_RX_WAIT_RIFS, |
| 4969 | REG_RX_TO_RX, REG_STANDBY, |
| 4970 | REG_SLEEP, REG_PMPD_ANAEN |
| 4971 | }; |
| 4972 | const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = { |
| 4973 | REG_TXPAUSE, REG_BEACON_CTRL, |
| 4974 | REG_BEACON_CTRL_1, REG_GPIO_MUXCFG |
| 4975 | }; |
| 4976 | const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = { |
| 4977 | REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR, |
| 4978 | REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B, |
| 4979 | REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE, |
| 4980 | REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE |
| 4981 | }; |
| 4982 | |
| 4983 | /* |
| 4984 | * Note: IQ calibration must be performed after loading |
| 4985 | * PHY_REG.txt , and radio_a, radio_b.txt |
| 4986 | */ |
| 4987 | |
| 4988 | if (t == 0) { |
| 4989 | /* Save ADDA parameters, turn Path A ADDA on */ |
| 4990 | rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup, |
| 4991 | RTL8XXXU_ADDA_REGS); |
| 4992 | rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup); |
| 4993 | rtl8xxxu_save_regs(priv, iqk_bb_regs, |
| 4994 | priv->bb_backup, RTL8XXXU_BB_REGS); |
| 4995 | } |
| 4996 | |
| 4997 | rtl8xxxu_path_adda_on(priv, adda_regs, true); |
| 4998 | |
| 4999 | if (t == 0) { |
| 5000 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1); |
| 5001 | if (val32 & FPGA0_HSSI_PARM1_PI) |
| 5002 | priv->pi_enabled = 1; |
| 5003 | } |
| 5004 | |
| 5005 | if (!priv->pi_enabled) { |
| 5006 | /* Switch BB to PI mode to do IQ Calibration. */ |
| 5007 | rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0x01000100); |
| 5008 | rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0x01000100); |
| 5009 | } |
| 5010 | |
| 5011 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 5012 | val32 &= ~FPGA_RF_MODE_CCK; |
| 5013 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 5014 | |
| 5015 | rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600); |
| 5016 | rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4); |
| 5017 | rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000); |
| 5018 | |
| 5019 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL); |
| 5020 | val32 |= (FPGA0_RF_PAPE | (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT)); |
| 5021 | rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32); |
| 5022 | |
| 5023 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE); |
| 5024 | val32 &= ~BIT(10); |
| 5025 | rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32); |
| 5026 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE); |
| 5027 | val32 &= ~BIT(10); |
| 5028 | rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32); |
| 5029 | |
| 5030 | if (priv->tx_paths > 1) { |
| 5031 | rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000); |
| 5032 | rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, 0x00010000); |
| 5033 | } |
| 5034 | |
| 5035 | /* MAC settings */ |
| 5036 | rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup); |
| 5037 | |
| 5038 | /* Page B init */ |
| 5039 | rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x00080000); |
| 5040 | |
| 5041 | if (priv->tx_paths > 1) |
| 5042 | rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x00080000); |
| 5043 | |
| 5044 | /* IQ calibration setting */ |
| 5045 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000); |
| 5046 | rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00); |
| 5047 | rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800); |
| 5048 | |
| 5049 | for (i = 0; i < retry; i++) { |
| 5050 | path_a_ok = rtl8xxxu_iqk_path_a(priv); |
| 5051 | if (path_a_ok == 0x03) { |
| 5052 | val32 = rtl8xxxu_read32(priv, |
| 5053 | REG_TX_POWER_BEFORE_IQK_A); |
| 5054 | result[t][0] = (val32 >> 16) & 0x3ff; |
| 5055 | val32 = rtl8xxxu_read32(priv, |
| 5056 | REG_TX_POWER_AFTER_IQK_A); |
| 5057 | result[t][1] = (val32 >> 16) & 0x3ff; |
| 5058 | val32 = rtl8xxxu_read32(priv, |
| 5059 | REG_RX_POWER_BEFORE_IQK_A_2); |
| 5060 | result[t][2] = (val32 >> 16) & 0x3ff; |
| 5061 | val32 = rtl8xxxu_read32(priv, |
| 5062 | REG_RX_POWER_AFTER_IQK_A_2); |
| 5063 | result[t][3] = (val32 >> 16) & 0x3ff; |
| 5064 | break; |
| 5065 | } else if (i == (retry - 1) && path_a_ok == 0x01) { |
| 5066 | /* TX IQK OK */ |
| 5067 | dev_dbg(dev, "%s: Path A IQK Only Tx Success!!\n", |
| 5068 | __func__); |
| 5069 | |
| 5070 | val32 = rtl8xxxu_read32(priv, |
| 5071 | REG_TX_POWER_BEFORE_IQK_A); |
| 5072 | result[t][0] = (val32 >> 16) & 0x3ff; |
| 5073 | val32 = rtl8xxxu_read32(priv, |
| 5074 | REG_TX_POWER_AFTER_IQK_A); |
| 5075 | result[t][1] = (val32 >> 16) & 0x3ff; |
| 5076 | } |
| 5077 | } |
| 5078 | |
| 5079 | if (!path_a_ok) |
| 5080 | dev_dbg(dev, "%s: Path A IQK failed!\n", __func__); |
| 5081 | |
| 5082 | if (priv->tx_paths > 1) { |
| 5083 | /* |
| 5084 | * Path A into standby |
| 5085 | */ |
| 5086 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x0); |
| 5087 | rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000); |
| 5088 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000); |
| 5089 | |
| 5090 | /* Turn Path B ADDA on */ |
| 5091 | rtl8xxxu_path_adda_on(priv, adda_regs, false); |
| 5092 | |
| 5093 | for (i = 0; i < retry; i++) { |
| 5094 | path_b_ok = rtl8xxxu_iqk_path_b(priv); |
| 5095 | if (path_b_ok == 0x03) { |
| 5096 | val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B); |
| 5097 | result[t][4] = (val32 >> 16) & 0x3ff; |
| 5098 | val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B); |
| 5099 | result[t][5] = (val32 >> 16) & 0x3ff; |
| 5100 | val32 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2); |
| 5101 | result[t][6] = (val32 >> 16) & 0x3ff; |
| 5102 | val32 = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2); |
| 5103 | result[t][7] = (val32 >> 16) & 0x3ff; |
| 5104 | break; |
| 5105 | } else if (i == (retry - 1) && path_b_ok == 0x01) { |
| 5106 | /* TX IQK OK */ |
| 5107 | val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B); |
| 5108 | result[t][4] = (val32 >> 16) & 0x3ff; |
| 5109 | val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B); |
| 5110 | result[t][5] = (val32 >> 16) & 0x3ff; |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | if (!path_b_ok) |
| 5115 | dev_dbg(dev, "%s: Path B IQK failed!\n", __func__); |
| 5116 | } |
| 5117 | |
| 5118 | /* Back to BB mode, load original value */ |
| 5119 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0); |
| 5120 | |
| 5121 | if (t) { |
| 5122 | if (!priv->pi_enabled) { |
| 5123 | /* |
| 5124 | * Switch back BB to SI mode after finishing |
| 5125 | * IQ Calibration |
| 5126 | */ |
| 5127 | val32 = 0x01000000; |
| 5128 | rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, val32); |
| 5129 | rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, val32); |
| 5130 | } |
| 5131 | |
| 5132 | /* Reload ADDA power saving parameters */ |
| 5133 | rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup, |
| 5134 | RTL8XXXU_ADDA_REGS); |
| 5135 | |
| 5136 | /* Reload MAC parameters */ |
| 5137 | rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup); |
| 5138 | |
| 5139 | /* Reload BB parameters */ |
| 5140 | rtl8xxxu_restore_regs(priv, iqk_bb_regs, |
| 5141 | priv->bb_backup, RTL8XXXU_BB_REGS); |
| 5142 | |
| 5143 | /* Restore RX initial gain */ |
| 5144 | rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00032ed3); |
| 5145 | |
| 5146 | if (priv->tx_paths > 1) { |
| 5147 | rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, |
| 5148 | 0x00032ed3); |
| 5149 | } |
| 5150 | |
| 5151 | /* Load 0xe30 IQC default value */ |
| 5152 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00); |
| 5153 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00); |
| 5154 | } |
| 5155 | } |
| 5156 | |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 5157 | static void rtl8723bu_phy_iqcalibrate(struct rtl8xxxu_priv *priv, |
| 5158 | int result[][8], int t) |
| 5159 | { |
| 5160 | struct device *dev = &priv->udev->dev; |
| 5161 | u32 i, val32; |
| 5162 | int path_a_ok /*, path_b_ok */; |
| 5163 | int retry = 2; |
| 5164 | const u32 adda_regs[RTL8XXXU_ADDA_REGS] = { |
| 5165 | REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH, |
| 5166 | REG_RX_WAIT_CCA, REG_TX_CCK_RFON, |
| 5167 | REG_TX_CCK_BBON, REG_TX_OFDM_RFON, |
| 5168 | REG_TX_OFDM_BBON, REG_TX_TO_RX, |
| 5169 | REG_TX_TO_TX, REG_RX_CCK, |
| 5170 | REG_RX_OFDM, REG_RX_WAIT_RIFS, |
| 5171 | REG_RX_TO_RX, REG_STANDBY, |
| 5172 | REG_SLEEP, REG_PMPD_ANAEN |
| 5173 | }; |
| 5174 | const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = { |
| 5175 | REG_TXPAUSE, REG_BEACON_CTRL, |
| 5176 | REG_BEACON_CTRL_1, REG_GPIO_MUXCFG |
| 5177 | }; |
| 5178 | const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = { |
| 5179 | REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR, |
| 5180 | REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B, |
| 5181 | REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE, |
| 5182 | REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE |
| 5183 | }; |
| 5184 | u8 xa_agc = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1) & 0xff; |
| 5185 | u8 xb_agc = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1) & 0xff; |
| 5186 | |
| 5187 | /* |
| 5188 | * Note: IQ calibration must be performed after loading |
| 5189 | * PHY_REG.txt , and radio_a, radio_b.txt |
| 5190 | */ |
| 5191 | |
| 5192 | if (t == 0) { |
| 5193 | /* Save ADDA parameters, turn Path A ADDA on */ |
| 5194 | rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup, |
| 5195 | RTL8XXXU_ADDA_REGS); |
| 5196 | rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup); |
| 5197 | rtl8xxxu_save_regs(priv, iqk_bb_regs, |
| 5198 | priv->bb_backup, RTL8XXXU_BB_REGS); |
| 5199 | } |
| 5200 | |
| 5201 | rtl8xxxu_path_adda_on(priv, adda_regs, true); |
| 5202 | |
| 5203 | /* MAC settings */ |
| 5204 | rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup); |
| 5205 | |
| 5206 | val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING); |
| 5207 | val32 |= 0x0f000000; |
| 5208 | rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32); |
| 5209 | |
| 5210 | rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600); |
| 5211 | rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4); |
| 5212 | rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000); |
| 5213 | |
| 5214 | #ifdef RTL8723BU_PATH_B |
| 5215 | /* Set RF mode to standby Path B */ |
| 5216 | if (priv->tx_paths > 1) |
| 5217 | rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x10000); |
| 5218 | #endif |
| 5219 | |
| 5220 | #if 0 |
| 5221 | /* Page B init */ |
| 5222 | rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x0f600000); |
| 5223 | |
| 5224 | if (priv->tx_paths > 1) |
| 5225 | rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x0f600000); |
| 5226 | #endif |
| 5227 | |
| 5228 | /* |
| 5229 | * RX IQ calibration setting for 8723B D cut large current issue |
| 5230 | * when leaving IPS |
| 5231 | */ |
| 5232 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 5233 | val32 &= 0x000000ff; |
| 5234 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 5235 | |
| 5236 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); |
| 5237 | val32 |= 0x80000; |
| 5238 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); |
| 5239 | |
| 5240 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000); |
| 5241 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); |
| 5242 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7fb7); |
| 5243 | |
| 5244 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED); |
| 5245 | val32 |= 0x20; |
| 5246 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32); |
| 5247 | |
| 5248 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_43, 0x60fbd); |
| 5249 | |
| 5250 | for (i = 0; i < retry; i++) { |
| 5251 | path_a_ok = rtl8723bu_iqk_path_a(priv); |
| 5252 | if (path_a_ok == 0x01) { |
| 5253 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 5254 | val32 &= 0x000000ff; |
| 5255 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 5256 | |
| 5257 | #if 0 /* Only needed in restore case, we may need this when going to suspend */ |
| 5258 | priv->RFCalibrateInfo.TxLOK[RF_A] = |
| 5259 | rtl8xxxu_read_rfreg(priv, RF_A, |
| 5260 | RF6052_REG_TXM_IDAC); |
| 5261 | #endif |
| 5262 | |
| 5263 | val32 = rtl8xxxu_read32(priv, |
| 5264 | REG_TX_POWER_BEFORE_IQK_A); |
| 5265 | result[t][0] = (val32 >> 16) & 0x3ff; |
| 5266 | val32 = rtl8xxxu_read32(priv, |
| 5267 | REG_TX_POWER_AFTER_IQK_A); |
| 5268 | result[t][1] = (val32 >> 16) & 0x3ff; |
| 5269 | |
| 5270 | break; |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | if (!path_a_ok) |
| 5275 | dev_dbg(dev, "%s: Path A TX IQK failed!\n", __func__); |
| 5276 | |
| 5277 | for (i = 0; i < retry; i++) { |
| 5278 | path_a_ok = rtl8723bu_rx_iqk_path_a(priv); |
| 5279 | if (path_a_ok == 0x03) { |
| 5280 | val32 = rtl8xxxu_read32(priv, |
| 5281 | REG_RX_POWER_BEFORE_IQK_A_2); |
| 5282 | result[t][2] = (val32 >> 16) & 0x3ff; |
| 5283 | val32 = rtl8xxxu_read32(priv, |
| 5284 | REG_RX_POWER_AFTER_IQK_A_2); |
| 5285 | result[t][3] = (val32 >> 16) & 0x3ff; |
| 5286 | |
| 5287 | break; |
| 5288 | } |
| 5289 | } |
| 5290 | |
| 5291 | if (!path_a_ok) |
| 5292 | dev_dbg(dev, "%s: Path A RX IQK failed!\n", __func__); |
| 5293 | |
| 5294 | if (priv->tx_paths > 1) { |
| 5295 | #if 1 |
| 5296 | dev_warn(dev, "%s: Path B not supported\n", __func__); |
| 5297 | #else |
| 5298 | |
| 5299 | /* |
| 5300 | * Path A into standby |
| 5301 | */ |
| 5302 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 5303 | val32 &= 0x000000ff; |
| 5304 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 5305 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x10000); |
| 5306 | |
| 5307 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 5308 | val32 &= 0x000000ff; |
| 5309 | val32 |= 0x80800000; |
| 5310 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 5311 | |
| 5312 | /* Turn Path B ADDA on */ |
| 5313 | rtl8xxxu_path_adda_on(priv, adda_regs, false); |
| 5314 | |
| 5315 | for (i = 0; i < retry; i++) { |
| 5316 | path_b_ok = rtl8xxxu_iqk_path_b(priv); |
| 5317 | if (path_b_ok == 0x03) { |
| 5318 | val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B); |
| 5319 | result[t][4] = (val32 >> 16) & 0x3ff; |
| 5320 | val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B); |
| 5321 | result[t][5] = (val32 >> 16) & 0x3ff; |
| 5322 | break; |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | if (!path_b_ok) |
| 5327 | dev_dbg(dev, "%s: Path B IQK failed!\n", __func__); |
| 5328 | |
| 5329 | for (i = 0; i < retry; i++) { |
| 5330 | path_b_ok = rtl8723bu_rx_iqk_path_b(priv); |
| 5331 | if (path_a_ok == 0x03) { |
| 5332 | val32 = rtl8xxxu_read32(priv, |
| 5333 | REG_RX_POWER_BEFORE_IQK_B_2); |
| 5334 | result[t][6] = (val32 >> 16) & 0x3ff; |
| 5335 | val32 = rtl8xxxu_read32(priv, |
| 5336 | REG_RX_POWER_AFTER_IQK_B_2); |
| 5337 | result[t][7] = (val32 >> 16) & 0x3ff; |
| 5338 | break; |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | if (!path_b_ok) |
| 5343 | dev_dbg(dev, "%s: Path B RX IQK failed!\n", __func__); |
| 5344 | #endif |
| 5345 | } |
| 5346 | |
| 5347 | /* Back to BB mode, load original value */ |
| 5348 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 5349 | val32 &= 0x000000ff; |
| 5350 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 5351 | |
| 5352 | if (t) { |
| 5353 | /* Reload ADDA power saving parameters */ |
| 5354 | rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup, |
| 5355 | RTL8XXXU_ADDA_REGS); |
| 5356 | |
| 5357 | /* Reload MAC parameters */ |
| 5358 | rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup); |
| 5359 | |
| 5360 | /* Reload BB parameters */ |
| 5361 | rtl8xxxu_restore_regs(priv, iqk_bb_regs, |
| 5362 | priv->bb_backup, RTL8XXXU_BB_REGS); |
| 5363 | |
| 5364 | /* Restore RX initial gain */ |
| 5365 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1); |
| 5366 | val32 &= 0xffffff00; |
| 5367 | rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | 0x50); |
| 5368 | rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | xa_agc); |
| 5369 | |
| 5370 | if (priv->tx_paths > 1) { |
| 5371 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1); |
| 5372 | val32 &= 0xffffff00; |
| 5373 | rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1, |
| 5374 | val32 | 0x50); |
| 5375 | rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1, |
| 5376 | val32 | xb_agc); |
| 5377 | } |
| 5378 | |
| 5379 | /* Load 0xe30 IQC default value */ |
| 5380 | rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00); |
| 5381 | rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00); |
| 5382 | } |
| 5383 | } |
| 5384 | |
Jes Sorensen | c7a5a19 | 2016-02-29 17:04:30 -0500 | [diff] [blame] | 5385 | static void rtl8xxxu_prepare_calibrate(struct rtl8xxxu_priv *priv, u8 start) |
| 5386 | { |
| 5387 | struct h2c_cmd h2c; |
| 5388 | |
| 5389 | if (priv->fops->mbox_ext_width < 4) |
| 5390 | return; |
| 5391 | |
| 5392 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 5393 | h2c.bt_wlan_calibration.cmd = H2C_8723B_BT_WLAN_CALIBRATION; |
| 5394 | h2c.bt_wlan_calibration.data = start; |
| 5395 | |
| 5396 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_wlan_calibration)); |
| 5397 | } |
| 5398 | |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 5399 | static void rtl8723au_phy_iq_calibrate(struct rtl8xxxu_priv *priv) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5400 | { |
| 5401 | struct device *dev = &priv->udev->dev; |
| 5402 | int result[4][8]; /* last is final result */ |
| 5403 | int i, candidate; |
| 5404 | bool path_a_ok, path_b_ok; |
| 5405 | u32 reg_e94, reg_e9c, reg_ea4, reg_eac; |
| 5406 | u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc; |
| 5407 | s32 reg_tmp = 0; |
| 5408 | bool simu; |
| 5409 | |
Jes Sorensen | c7a5a19 | 2016-02-29 17:04:30 -0500 | [diff] [blame] | 5410 | rtl8xxxu_prepare_calibrate(priv, 1); |
| 5411 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5412 | memset(result, 0, sizeof(result)); |
| 5413 | candidate = -1; |
| 5414 | |
| 5415 | path_a_ok = false; |
| 5416 | path_b_ok = false; |
| 5417 | |
| 5418 | rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 5419 | |
| 5420 | for (i = 0; i < 3; i++) { |
| 5421 | rtl8xxxu_phy_iqcalibrate(priv, result, i); |
| 5422 | |
| 5423 | if (i == 1) { |
| 5424 | simu = rtl8xxxu_simularity_compare(priv, result, 0, 1); |
| 5425 | if (simu) { |
| 5426 | candidate = 0; |
| 5427 | break; |
| 5428 | } |
| 5429 | } |
| 5430 | |
| 5431 | if (i == 2) { |
| 5432 | simu = rtl8xxxu_simularity_compare(priv, result, 0, 2); |
| 5433 | if (simu) { |
| 5434 | candidate = 0; |
| 5435 | break; |
| 5436 | } |
| 5437 | |
| 5438 | simu = rtl8xxxu_simularity_compare(priv, result, 1, 2); |
| 5439 | if (simu) { |
| 5440 | candidate = 1; |
| 5441 | } else { |
| 5442 | for (i = 0; i < 8; i++) |
| 5443 | reg_tmp += result[3][i]; |
| 5444 | |
| 5445 | if (reg_tmp) |
| 5446 | candidate = 3; |
| 5447 | else |
| 5448 | candidate = -1; |
| 5449 | } |
| 5450 | } |
| 5451 | } |
| 5452 | |
| 5453 | for (i = 0; i < 4; i++) { |
| 5454 | reg_e94 = result[i][0]; |
| 5455 | reg_e9c = result[i][1]; |
| 5456 | reg_ea4 = result[i][2]; |
| 5457 | reg_eac = result[i][3]; |
| 5458 | reg_eb4 = result[i][4]; |
| 5459 | reg_ebc = result[i][5]; |
| 5460 | reg_ec4 = result[i][6]; |
| 5461 | reg_ecc = result[i][7]; |
| 5462 | } |
| 5463 | |
| 5464 | if (candidate >= 0) { |
| 5465 | reg_e94 = result[candidate][0]; |
| 5466 | priv->rege94 = reg_e94; |
| 5467 | reg_e9c = result[candidate][1]; |
| 5468 | priv->rege9c = reg_e9c; |
| 5469 | reg_ea4 = result[candidate][2]; |
| 5470 | reg_eac = result[candidate][3]; |
| 5471 | reg_eb4 = result[candidate][4]; |
| 5472 | priv->regeb4 = reg_eb4; |
| 5473 | reg_ebc = result[candidate][5]; |
| 5474 | priv->regebc = reg_ebc; |
| 5475 | reg_ec4 = result[candidate][6]; |
| 5476 | reg_ecc = result[candidate][7]; |
| 5477 | dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate); |
| 5478 | dev_dbg(dev, |
| 5479 | "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x " |
| 5480 | "ecc=%x\n ", __func__, reg_e94, reg_e9c, |
| 5481 | reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc); |
| 5482 | path_a_ok = true; |
| 5483 | path_b_ok = true; |
| 5484 | } else { |
| 5485 | reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100; |
| 5486 | reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0; |
| 5487 | } |
| 5488 | |
| 5489 | if (reg_e94 && candidate >= 0) |
| 5490 | rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result, |
| 5491 | candidate, (reg_ea4 == 0)); |
| 5492 | |
| 5493 | if (priv->tx_paths > 1 && reg_eb4) |
| 5494 | rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result, |
| 5495 | candidate, (reg_ec4 == 0)); |
| 5496 | |
| 5497 | rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg, |
| 5498 | priv->bb_recovery_backup, RTL8XXXU_BB_REGS); |
Jes Sorensen | c7a5a19 | 2016-02-29 17:04:30 -0500 | [diff] [blame] | 5499 | |
| 5500 | rtl8xxxu_prepare_calibrate(priv, 0); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5501 | } |
| 5502 | |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 5503 | static void rtl8723bu_phy_iq_calibrate(struct rtl8xxxu_priv *priv) |
| 5504 | { |
| 5505 | struct device *dev = &priv->udev->dev; |
| 5506 | int result[4][8]; /* last is final result */ |
| 5507 | int i, candidate; |
| 5508 | bool path_a_ok, path_b_ok; |
| 5509 | u32 reg_e94, reg_e9c, reg_ea4, reg_eac; |
| 5510 | u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc; |
| 5511 | u32 val32, bt_control; |
| 5512 | s32 reg_tmp = 0; |
| 5513 | bool simu; |
| 5514 | |
| 5515 | rtl8xxxu_prepare_calibrate(priv, 1); |
| 5516 | |
| 5517 | memset(result, 0, sizeof(result)); |
| 5518 | candidate = -1; |
| 5519 | |
| 5520 | path_a_ok = false; |
| 5521 | path_b_ok = false; |
| 5522 | |
| 5523 | bt_control = rtl8xxxu_read32(priv, REG_BT_CONTROL_8723BU); |
| 5524 | |
| 5525 | for (i = 0; i < 3; i++) { |
| 5526 | rtl8723bu_phy_iqcalibrate(priv, result, i); |
| 5527 | |
| 5528 | if (i == 1) { |
| 5529 | simu = rtl8723bu_simularity_compare(priv, result, 0, 1); |
| 5530 | if (simu) { |
| 5531 | candidate = 0; |
| 5532 | break; |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | if (i == 2) { |
| 5537 | simu = rtl8723bu_simularity_compare(priv, result, 0, 2); |
| 5538 | if (simu) { |
| 5539 | candidate = 0; |
| 5540 | break; |
| 5541 | } |
| 5542 | |
| 5543 | simu = rtl8723bu_simularity_compare(priv, result, 1, 2); |
| 5544 | if (simu) { |
| 5545 | candidate = 1; |
| 5546 | } else { |
| 5547 | for (i = 0; i < 8; i++) |
| 5548 | reg_tmp += result[3][i]; |
| 5549 | |
| 5550 | if (reg_tmp) |
| 5551 | candidate = 3; |
| 5552 | else |
| 5553 | candidate = -1; |
| 5554 | } |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | for (i = 0; i < 4; i++) { |
| 5559 | reg_e94 = result[i][0]; |
| 5560 | reg_e9c = result[i][1]; |
| 5561 | reg_ea4 = result[i][2]; |
| 5562 | reg_eac = result[i][3]; |
| 5563 | reg_eb4 = result[i][4]; |
| 5564 | reg_ebc = result[i][5]; |
| 5565 | reg_ec4 = result[i][6]; |
| 5566 | reg_ecc = result[i][7]; |
| 5567 | } |
| 5568 | |
| 5569 | if (candidate >= 0) { |
| 5570 | reg_e94 = result[candidate][0]; |
| 5571 | priv->rege94 = reg_e94; |
| 5572 | reg_e9c = result[candidate][1]; |
| 5573 | priv->rege9c = reg_e9c; |
| 5574 | reg_ea4 = result[candidate][2]; |
| 5575 | reg_eac = result[candidate][3]; |
| 5576 | reg_eb4 = result[candidate][4]; |
| 5577 | priv->regeb4 = reg_eb4; |
| 5578 | reg_ebc = result[candidate][5]; |
| 5579 | priv->regebc = reg_ebc; |
| 5580 | reg_ec4 = result[candidate][6]; |
| 5581 | reg_ecc = result[candidate][7]; |
| 5582 | dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate); |
| 5583 | dev_dbg(dev, |
| 5584 | "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x " |
| 5585 | "ecc=%x\n ", __func__, reg_e94, reg_e9c, |
| 5586 | reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc); |
| 5587 | path_a_ok = true; |
| 5588 | path_b_ok = true; |
| 5589 | } else { |
| 5590 | reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100; |
| 5591 | reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0; |
| 5592 | } |
| 5593 | |
| 5594 | if (reg_e94 && candidate >= 0) |
| 5595 | rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result, |
| 5596 | candidate, (reg_ea4 == 0)); |
| 5597 | |
| 5598 | if (priv->tx_paths > 1 && reg_eb4) |
| 5599 | rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result, |
| 5600 | candidate, (reg_ec4 == 0)); |
| 5601 | |
| 5602 | rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg, |
| 5603 | priv->bb_recovery_backup, RTL8XXXU_BB_REGS); |
| 5604 | |
| 5605 | rtl8xxxu_write32(priv, REG_BT_CONTROL_8723BU, bt_control); |
| 5606 | |
| 5607 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_WE_LUT); |
| 5608 | val32 |= 0x80000; |
| 5609 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, val32); |
| 5610 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x18000); |
| 5611 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0001f); |
| 5612 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xe6177); |
| 5613 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED); |
| 5614 | val32 |= 0x20; |
| 5615 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_ED, val32); |
| 5616 | rtl8xxxu_write_rfreg(priv, RF_A, 0x43, 0x300bd); |
| 5617 | |
| 5618 | if (priv->rf_paths > 1) { |
| 5619 | dev_dbg(dev, "%s: beware 2T not yet supported\n", __func__); |
| 5620 | #ifdef RTL8723BU_PATH_B |
| 5621 | if (RF_Path == 0x0) //S1 |
| 5622 | ODM_SetIQCbyRFpath(pDM_Odm, 0); |
| 5623 | else //S0 |
| 5624 | ODM_SetIQCbyRFpath(pDM_Odm, 1); |
| 5625 | #endif |
| 5626 | } |
| 5627 | rtl8xxxu_prepare_calibrate(priv, 0); |
| 5628 | } |
| 5629 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5630 | static void rtl8723a_phy_lc_calibrate(struct rtl8xxxu_priv *priv) |
| 5631 | { |
| 5632 | u32 val32; |
| 5633 | u32 rf_amode, rf_bmode = 0, lstf; |
| 5634 | |
| 5635 | /* Check continuous TX and Packet TX */ |
| 5636 | lstf = rtl8xxxu_read32(priv, REG_OFDM1_LSTF); |
| 5637 | |
| 5638 | if (lstf & OFDM_LSTF_MASK) { |
| 5639 | /* Disable all continuous TX */ |
| 5640 | val32 = lstf & ~OFDM_LSTF_MASK; |
| 5641 | rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32); |
| 5642 | |
| 5643 | /* Read original RF mode Path A */ |
| 5644 | rf_amode = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_AC); |
| 5645 | |
| 5646 | /* Set RF mode to standby Path A */ |
| 5647 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, |
| 5648 | (rf_amode & 0x8ffff) | 0x10000); |
| 5649 | |
| 5650 | /* Path-B */ |
| 5651 | if (priv->tx_paths > 1) { |
| 5652 | rf_bmode = rtl8xxxu_read_rfreg(priv, RF_B, |
| 5653 | RF6052_REG_AC); |
| 5654 | |
| 5655 | rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, |
| 5656 | (rf_bmode & 0x8ffff) | 0x10000); |
| 5657 | } |
| 5658 | } else { |
| 5659 | /* Deal with Packet TX case */ |
| 5660 | /* block all queues */ |
| 5661 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); |
| 5662 | } |
| 5663 | |
| 5664 | /* Start LC calibration */ |
Jes Sorensen | 0d698de | 2016-02-29 17:04:36 -0500 | [diff] [blame] | 5665 | if (priv->fops->has_s0s1) |
| 5666 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_S0S1, 0xdfbe0); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5667 | val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_MODE_AG); |
| 5668 | val32 |= 0x08000; |
| 5669 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, val32); |
| 5670 | |
| 5671 | msleep(100); |
| 5672 | |
Jes Sorensen | 0d698de | 2016-02-29 17:04:36 -0500 | [diff] [blame] | 5673 | if (priv->fops->has_s0s1) |
| 5674 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_S0S1, 0xdffe0); |
| 5675 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5676 | /* Restore original parameters */ |
| 5677 | if (lstf & OFDM_LSTF_MASK) { |
| 5678 | /* Path-A */ |
| 5679 | rtl8xxxu_write32(priv, REG_OFDM1_LSTF, lstf); |
| 5680 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, rf_amode); |
| 5681 | |
| 5682 | /* Path-B */ |
| 5683 | if (priv->tx_paths > 1) |
| 5684 | rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, |
| 5685 | rf_bmode); |
| 5686 | } else /* Deal with Packet TX case */ |
| 5687 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00); |
| 5688 | } |
| 5689 | |
| 5690 | static int rtl8xxxu_set_mac(struct rtl8xxxu_priv *priv) |
| 5691 | { |
| 5692 | int i; |
| 5693 | u16 reg; |
| 5694 | |
| 5695 | reg = REG_MACID; |
| 5696 | |
| 5697 | for (i = 0; i < ETH_ALEN; i++) |
| 5698 | rtl8xxxu_write8(priv, reg + i, priv->mac_addr[i]); |
| 5699 | |
| 5700 | return 0; |
| 5701 | } |
| 5702 | |
| 5703 | static int rtl8xxxu_set_bssid(struct rtl8xxxu_priv *priv, const u8 *bssid) |
| 5704 | { |
| 5705 | int i; |
| 5706 | u16 reg; |
| 5707 | |
| 5708 | dev_dbg(&priv->udev->dev, "%s: (%pM)\n", __func__, bssid); |
| 5709 | |
| 5710 | reg = REG_BSSID; |
| 5711 | |
| 5712 | for (i = 0; i < ETH_ALEN; i++) |
| 5713 | rtl8xxxu_write8(priv, reg + i, bssid[i]); |
| 5714 | |
| 5715 | return 0; |
| 5716 | } |
| 5717 | |
| 5718 | static void |
| 5719 | rtl8xxxu_set_ampdu_factor(struct rtl8xxxu_priv *priv, u8 ampdu_factor) |
| 5720 | { |
| 5721 | u8 vals[4] = { 0x41, 0xa8, 0x72, 0xb9 }; |
| 5722 | u8 max_agg = 0xf; |
| 5723 | int i; |
| 5724 | |
| 5725 | ampdu_factor = 1 << (ampdu_factor + 2); |
| 5726 | if (ampdu_factor > max_agg) |
| 5727 | ampdu_factor = max_agg; |
| 5728 | |
| 5729 | for (i = 0; i < 4; i++) { |
| 5730 | if ((vals[i] & 0xf0) > (ampdu_factor << 4)) |
| 5731 | vals[i] = (vals[i] & 0x0f) | (ampdu_factor << 4); |
| 5732 | |
| 5733 | if ((vals[i] & 0x0f) > ampdu_factor) |
| 5734 | vals[i] = (vals[i] & 0xf0) | ampdu_factor; |
| 5735 | |
| 5736 | rtl8xxxu_write8(priv, REG_AGGLEN_LMT + i, vals[i]); |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | static void rtl8xxxu_set_ampdu_min_space(struct rtl8xxxu_priv *priv, u8 density) |
| 5741 | { |
| 5742 | u8 val8; |
| 5743 | |
| 5744 | val8 = rtl8xxxu_read8(priv, REG_AMPDU_MIN_SPACE); |
| 5745 | val8 &= 0xf8; |
| 5746 | val8 |= density; |
| 5747 | rtl8xxxu_write8(priv, REG_AMPDU_MIN_SPACE, val8); |
| 5748 | } |
| 5749 | |
| 5750 | static int rtl8xxxu_active_to_emu(struct rtl8xxxu_priv *priv) |
| 5751 | { |
| 5752 | u8 val8; |
| 5753 | int count, ret; |
| 5754 | |
| 5755 | /* Start of rtl8723AU_card_enable_flow */ |
| 5756 | /* Act to Cardemu sequence*/ |
| 5757 | /* Turn off RF */ |
| 5758 | rtl8xxxu_write8(priv, REG_RF_CTRL, 0); |
| 5759 | |
| 5760 | /* 0x004E[7] = 0, switch DPDT_SEL_P output from register 0x0065[2] */ |
| 5761 | val8 = rtl8xxxu_read8(priv, REG_LEDCFG2); |
| 5762 | val8 &= ~LEDCFG2_DPDT_SELECT; |
| 5763 | rtl8xxxu_write8(priv, REG_LEDCFG2, val8); |
| 5764 | |
| 5765 | /* 0x0005[1] = 1 turn off MAC by HW state machine*/ |
| 5766 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5767 | val8 |= BIT(1); |
| 5768 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5769 | |
| 5770 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 5771 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5772 | if ((val8 & BIT(1)) == 0) |
| 5773 | break; |
| 5774 | udelay(10); |
| 5775 | } |
| 5776 | |
| 5777 | if (!count) { |
| 5778 | dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n", |
| 5779 | __func__); |
| 5780 | ret = -EBUSY; |
| 5781 | goto exit; |
| 5782 | } |
| 5783 | |
| 5784 | /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */ |
| 5785 | val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); |
| 5786 | val8 |= SYS_ISO_ANALOG_IPS; |
| 5787 | rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); |
| 5788 | |
| 5789 | /* 0x0020[0] = 0 disable LDOA12 MACRO block*/ |
| 5790 | val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); |
| 5791 | val8 &= ~LDOA15_ENABLE; |
| 5792 | rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); |
| 5793 | |
| 5794 | exit: |
| 5795 | return ret; |
| 5796 | } |
| 5797 | |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 5798 | static int rtl8723bu_active_to_emu(struct rtl8xxxu_priv *priv) |
| 5799 | { |
| 5800 | u8 val8; |
| 5801 | u16 val16; |
| 5802 | u32 val32; |
| 5803 | int count, ret; |
| 5804 | |
| 5805 | /* Turn off RF */ |
| 5806 | rtl8xxxu_write8(priv, REG_RF_CTRL, 0); |
| 5807 | |
| 5808 | /* Enable rising edge triggering interrupt */ |
| 5809 | val16 = rtl8xxxu_read16(priv, REG_GPIO_INTM); |
| 5810 | val16 &= ~GPIO_INTM_EDGE_TRIG_IRQ; |
| 5811 | rtl8xxxu_write16(priv, REG_GPIO_INTM, val16); |
| 5812 | |
| 5813 | /* Release WLON reset 0x04[16]= 1*/ |
| 5814 | val32 = rtl8xxxu_read32(priv, REG_GPIO_INTM); |
| 5815 | val32 |= APS_FSMCO_WLON_RESET; |
| 5816 | rtl8xxxu_write32(priv, REG_GPIO_INTM, val32); |
| 5817 | |
| 5818 | /* 0x0005[1] = 1 turn off MAC by HW state machine*/ |
| 5819 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5820 | val8 |= BIT(1); |
| 5821 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5822 | |
| 5823 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 5824 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5825 | if ((val8 & BIT(1)) == 0) |
| 5826 | break; |
| 5827 | udelay(10); |
| 5828 | } |
| 5829 | |
| 5830 | if (!count) { |
| 5831 | dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n", |
| 5832 | __func__); |
| 5833 | ret = -EBUSY; |
| 5834 | goto exit; |
| 5835 | } |
| 5836 | |
| 5837 | /* Enable BT control XTAL setting */ |
| 5838 | val8 = rtl8xxxu_read8(priv, REG_AFE_MISC); |
| 5839 | val8 &= ~AFE_MISC_WL_XTAL_CTRL; |
| 5840 | rtl8xxxu_write8(priv, REG_AFE_MISC, val8); |
| 5841 | |
| 5842 | /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */ |
| 5843 | val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); |
| 5844 | val8 |= SYS_ISO_ANALOG_IPS; |
| 5845 | rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); |
| 5846 | |
| 5847 | /* 0x0020[0] = 0 disable LDOA12 MACRO block*/ |
| 5848 | val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); |
| 5849 | val8 &= ~LDOA15_ENABLE; |
| 5850 | rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); |
| 5851 | |
| 5852 | exit: |
| 5853 | return ret; |
| 5854 | } |
| 5855 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5856 | static int rtl8xxxu_active_to_lps(struct rtl8xxxu_priv *priv) |
| 5857 | { |
| 5858 | u8 val8; |
| 5859 | u8 val32; |
| 5860 | int count, ret; |
| 5861 | |
| 5862 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); |
| 5863 | |
| 5864 | /* |
| 5865 | * Poll - wait for RX packet to complete |
| 5866 | */ |
| 5867 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 5868 | val32 = rtl8xxxu_read32(priv, 0x5f8); |
| 5869 | if (!val32) |
| 5870 | break; |
| 5871 | udelay(10); |
| 5872 | } |
| 5873 | |
| 5874 | if (!count) { |
| 5875 | dev_warn(&priv->udev->dev, |
| 5876 | "%s: RX poll timed out (0x05f8)\n", __func__); |
| 5877 | ret = -EBUSY; |
| 5878 | goto exit; |
| 5879 | } |
| 5880 | |
| 5881 | /* Disable CCK and OFDM, clock gated */ |
| 5882 | val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC); |
| 5883 | val8 &= ~SYS_FUNC_BBRSTB; |
| 5884 | rtl8xxxu_write8(priv, REG_SYS_FUNC, val8); |
| 5885 | |
| 5886 | udelay(2); |
| 5887 | |
| 5888 | /* Reset baseband */ |
| 5889 | val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC); |
| 5890 | val8 &= ~SYS_FUNC_BB_GLB_RSTN; |
| 5891 | rtl8xxxu_write8(priv, REG_SYS_FUNC, val8); |
| 5892 | |
| 5893 | /* Reset MAC TRX */ |
| 5894 | val8 = rtl8xxxu_read8(priv, REG_CR); |
| 5895 | val8 = CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE; |
| 5896 | rtl8xxxu_write8(priv, REG_CR, val8); |
| 5897 | |
| 5898 | /* Reset MAC TRX */ |
| 5899 | val8 = rtl8xxxu_read8(priv, REG_CR + 1); |
| 5900 | val8 &= ~BIT(1); /* CR_SECURITY_ENABLE */ |
| 5901 | rtl8xxxu_write8(priv, REG_CR + 1, val8); |
| 5902 | |
| 5903 | /* Respond TX OK to scheduler */ |
| 5904 | val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST); |
| 5905 | val8 |= DUAL_TSF_TX_OK; |
| 5906 | rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8); |
| 5907 | |
| 5908 | exit: |
| 5909 | return ret; |
| 5910 | } |
| 5911 | |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 5912 | static void rtl8723a_disabled_to_emu(struct rtl8xxxu_priv *priv) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 5913 | { |
| 5914 | u8 val8; |
| 5915 | |
| 5916 | /* Clear suspend enable and power down enable*/ |
| 5917 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5918 | val8 &= ~(BIT(3) | BIT(7)); |
| 5919 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5920 | |
| 5921 | /* 0x48[16] = 0 to disable GPIO9 as EXT WAKEUP*/ |
| 5922 | val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2); |
| 5923 | val8 &= ~BIT(0); |
| 5924 | rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8); |
| 5925 | |
| 5926 | /* 0x04[12:11] = 11 enable WL suspend*/ |
| 5927 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5928 | val8 &= ~(BIT(3) | BIT(4)); |
| 5929 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5930 | } |
| 5931 | |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 5932 | static void rtl8192e_disabled_to_emu(struct rtl8xxxu_priv *priv) |
| 5933 | { |
| 5934 | u8 val8; |
| 5935 | |
| 5936 | /* Clear suspend enable and power down enable*/ |
| 5937 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5938 | val8 &= ~(BIT(3) | BIT(4)); |
| 5939 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5940 | } |
| 5941 | |
| 5942 | static int rtl8192e_emu_to_active(struct rtl8xxxu_priv *priv) |
| 5943 | { |
| 5944 | u8 val8; |
| 5945 | u32 val32; |
| 5946 | int count, ret = 0; |
| 5947 | |
| 5948 | /* disable HWPDN 0x04[15]=0*/ |
| 5949 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5950 | val8 &= ~BIT(7); |
| 5951 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5952 | |
| 5953 | /* disable SW LPS 0x04[10]= 0 */ |
| 5954 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5955 | val8 &= ~BIT(2); |
| 5956 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5957 | |
| 5958 | /* disable WL suspend*/ |
| 5959 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 5960 | val8 &= ~(BIT(3) | BIT(4)); |
| 5961 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 5962 | |
| 5963 | /* wait till 0x04[17] = 1 power ready*/ |
| 5964 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 5965 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 5966 | if (val32 & BIT(17)) |
| 5967 | break; |
| 5968 | |
| 5969 | udelay(10); |
| 5970 | } |
| 5971 | |
| 5972 | if (!count) { |
| 5973 | ret = -EBUSY; |
| 5974 | goto exit; |
| 5975 | } |
| 5976 | |
| 5977 | /* We should be able to optimize the following three entries into one */ |
| 5978 | |
| 5979 | /* release WLON reset 0x04[16]= 1*/ |
| 5980 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2); |
| 5981 | val8 |= BIT(0); |
| 5982 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8); |
| 5983 | |
| 5984 | /* set, then poll until 0 */ |
| 5985 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 5986 | val32 |= APS_FSMCO_MAC_ENABLE; |
| 5987 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 5988 | |
| 5989 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 5990 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 5991 | if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) { |
| 5992 | ret = 0; |
| 5993 | break; |
| 5994 | } |
| 5995 | udelay(10); |
| 5996 | } |
| 5997 | |
| 5998 | if (!count) { |
| 5999 | ret = -EBUSY; |
| 6000 | goto exit; |
| 6001 | } |
| 6002 | |
| 6003 | exit: |
| 6004 | return ret; |
| 6005 | } |
| 6006 | |
| 6007 | static int rtl8723a_emu_to_active(struct rtl8xxxu_priv *priv) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6008 | { |
| 6009 | u8 val8; |
| 6010 | u32 val32; |
| 6011 | int count, ret = 0; |
| 6012 | |
| 6013 | /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface*/ |
| 6014 | val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); |
| 6015 | val8 |= LDOA15_ENABLE; |
| 6016 | rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); |
| 6017 | |
| 6018 | /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/ |
| 6019 | val8 = rtl8xxxu_read8(priv, 0x0067); |
| 6020 | val8 &= ~BIT(4); |
| 6021 | rtl8xxxu_write8(priv, 0x0067, val8); |
| 6022 | |
| 6023 | mdelay(1); |
| 6024 | |
| 6025 | /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */ |
| 6026 | val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); |
| 6027 | val8 &= ~SYS_ISO_ANALOG_IPS; |
| 6028 | rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); |
| 6029 | |
| 6030 | /* disable SW LPS 0x04[10]= 0 */ |
| 6031 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 6032 | val8 &= ~BIT(2); |
| 6033 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 6034 | |
| 6035 | /* wait till 0x04[17] = 1 power ready*/ |
| 6036 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 6037 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6038 | if (val32 & BIT(17)) |
| 6039 | break; |
| 6040 | |
| 6041 | udelay(10); |
| 6042 | } |
| 6043 | |
| 6044 | if (!count) { |
| 6045 | ret = -EBUSY; |
| 6046 | goto exit; |
| 6047 | } |
| 6048 | |
| 6049 | /* We should be able to optimize the following three entries into one */ |
| 6050 | |
| 6051 | /* release WLON reset 0x04[16]= 1*/ |
| 6052 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2); |
| 6053 | val8 |= BIT(0); |
| 6054 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8); |
| 6055 | |
| 6056 | /* disable HWPDN 0x04[15]= 0*/ |
| 6057 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 6058 | val8 &= ~BIT(7); |
| 6059 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 6060 | |
| 6061 | /* disable WL suspend*/ |
| 6062 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 6063 | val8 &= ~(BIT(3) | BIT(4)); |
| 6064 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 6065 | |
| 6066 | /* set, then poll until 0 */ |
| 6067 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6068 | val32 |= APS_FSMCO_MAC_ENABLE; |
| 6069 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 6070 | |
| 6071 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 6072 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6073 | if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) { |
| 6074 | ret = 0; |
| 6075 | break; |
| 6076 | } |
| 6077 | udelay(10); |
| 6078 | } |
| 6079 | |
| 6080 | if (!count) { |
| 6081 | ret = -EBUSY; |
| 6082 | goto exit; |
| 6083 | } |
| 6084 | |
| 6085 | /* 0x4C[23] = 0x4E[7] = 1, switch DPDT_SEL_P output from WL BB */ |
| 6086 | /* |
| 6087 | * Note: Vendor driver actually clears this bit, despite the |
| 6088 | * documentation claims it's being set! |
| 6089 | */ |
| 6090 | val8 = rtl8xxxu_read8(priv, REG_LEDCFG2); |
| 6091 | val8 |= LEDCFG2_DPDT_SELECT; |
| 6092 | val8 &= ~LEDCFG2_DPDT_SELECT; |
| 6093 | rtl8xxxu_write8(priv, REG_LEDCFG2, val8); |
| 6094 | |
| 6095 | exit: |
| 6096 | return ret; |
| 6097 | } |
| 6098 | |
Jes Sorensen | 42836db | 2016-02-29 17:04:52 -0500 | [diff] [blame] | 6099 | static int rtl8723b_emu_to_active(struct rtl8xxxu_priv *priv) |
| 6100 | { |
| 6101 | u8 val8; |
| 6102 | u32 val32; |
| 6103 | int count, ret = 0; |
| 6104 | |
| 6105 | /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface */ |
| 6106 | val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL); |
| 6107 | val8 |= LDOA15_ENABLE; |
| 6108 | rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8); |
| 6109 | |
| 6110 | /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/ |
| 6111 | val8 = rtl8xxxu_read8(priv, 0x0067); |
| 6112 | val8 &= ~BIT(4); |
| 6113 | rtl8xxxu_write8(priv, 0x0067, val8); |
| 6114 | |
| 6115 | mdelay(1); |
| 6116 | |
| 6117 | /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */ |
| 6118 | val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); |
| 6119 | val8 &= ~SYS_ISO_ANALOG_IPS; |
| 6120 | rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); |
| 6121 | |
| 6122 | /* Disable SW LPS 0x04[10]= 0 */ |
| 6123 | val32 = rtl8xxxu_read8(priv, REG_APS_FSMCO); |
| 6124 | val32 &= ~APS_FSMCO_SW_LPS; |
| 6125 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 6126 | |
| 6127 | /* Wait until 0x04[17] = 1 power ready */ |
| 6128 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 6129 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6130 | if (val32 & BIT(17)) |
| 6131 | break; |
| 6132 | |
| 6133 | udelay(10); |
| 6134 | } |
| 6135 | |
| 6136 | if (!count) { |
| 6137 | ret = -EBUSY; |
| 6138 | goto exit; |
| 6139 | } |
| 6140 | |
| 6141 | /* We should be able to optimize the following three entries into one */ |
| 6142 | |
| 6143 | /* Release WLON reset 0x04[16]= 1*/ |
| 6144 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6145 | val32 |= APS_FSMCO_WLON_RESET; |
| 6146 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 6147 | |
| 6148 | /* Disable HWPDN 0x04[15]= 0*/ |
| 6149 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6150 | val32 &= ~APS_FSMCO_HW_POWERDOWN; |
| 6151 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 6152 | |
| 6153 | /* Disable WL suspend*/ |
| 6154 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6155 | val32 &= ~(APS_FSMCO_HW_SUSPEND | APS_FSMCO_PCIE); |
| 6156 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 6157 | |
| 6158 | /* Set, then poll until 0 */ |
| 6159 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6160 | val32 |= APS_FSMCO_MAC_ENABLE; |
| 6161 | rtl8xxxu_write32(priv, REG_APS_FSMCO, val32); |
| 6162 | |
| 6163 | for (count = RTL8XXXU_MAX_REG_POLL; count; count--) { |
| 6164 | val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO); |
| 6165 | if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) { |
| 6166 | ret = 0; |
| 6167 | break; |
| 6168 | } |
| 6169 | udelay(10); |
| 6170 | } |
| 6171 | |
| 6172 | if (!count) { |
| 6173 | ret = -EBUSY; |
| 6174 | goto exit; |
| 6175 | } |
| 6176 | |
| 6177 | /* Enable WL control XTAL setting */ |
| 6178 | val8 = rtl8xxxu_read8(priv, REG_AFE_MISC); |
| 6179 | val8 |= AFE_MISC_WL_XTAL_CTRL; |
| 6180 | rtl8xxxu_write8(priv, REG_AFE_MISC, val8); |
| 6181 | |
| 6182 | /* Enable falling edge triggering interrupt */ |
| 6183 | val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 1); |
| 6184 | val8 |= BIT(1); |
| 6185 | rtl8xxxu_write8(priv, REG_GPIO_INTM + 1, val8); |
| 6186 | |
| 6187 | /* Enable GPIO9 interrupt mode */ |
| 6188 | val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2 + 1); |
| 6189 | val8 |= BIT(1); |
| 6190 | rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2 + 1, val8); |
| 6191 | |
| 6192 | /* Enable GPIO9 input mode */ |
| 6193 | val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL_2); |
| 6194 | val8 &= ~BIT(1); |
| 6195 | rtl8xxxu_write8(priv, REG_GPIO_IO_SEL_2, val8); |
| 6196 | |
| 6197 | /* Enable HSISR GPIO[C:0] interrupt */ |
| 6198 | val8 = rtl8xxxu_read8(priv, REG_HSIMR); |
| 6199 | val8 |= BIT(0); |
| 6200 | rtl8xxxu_write8(priv, REG_HSIMR, val8); |
| 6201 | |
| 6202 | /* Enable HSISR GPIO9 interrupt */ |
| 6203 | val8 = rtl8xxxu_read8(priv, REG_HSIMR + 2); |
| 6204 | val8 |= BIT(1); |
| 6205 | rtl8xxxu_write8(priv, REG_HSIMR + 2, val8); |
| 6206 | |
| 6207 | val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL); |
| 6208 | val8 |= MULTI_WIFI_HW_ROF_EN; |
| 6209 | rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL, val8); |
| 6210 | |
| 6211 | /* For GPIO9 internal pull high setting BIT(14) */ |
| 6212 | val8 = rtl8xxxu_read8(priv, REG_MULTI_FUNC_CTRL + 1); |
| 6213 | val8 |= BIT(6); |
| 6214 | rtl8xxxu_write8(priv, REG_MULTI_FUNC_CTRL + 1, val8); |
| 6215 | |
| 6216 | exit: |
| 6217 | return ret; |
| 6218 | } |
| 6219 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6220 | static int rtl8xxxu_emu_to_disabled(struct rtl8xxxu_priv *priv) |
| 6221 | { |
| 6222 | u8 val8; |
| 6223 | |
| 6224 | /* 0x0007[7:0] = 0x20 SOP option to disable BG/MB */ |
| 6225 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 3, 0x20); |
| 6226 | |
| 6227 | /* 0x04[12:11] = 01 enable WL suspend */ |
| 6228 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 6229 | val8 &= ~BIT(4); |
| 6230 | val8 |= BIT(3); |
| 6231 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 6232 | |
| 6233 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1); |
| 6234 | val8 |= BIT(7); |
| 6235 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8); |
| 6236 | |
| 6237 | /* 0x48[16] = 1 to enable GPIO9 as EXT wakeup */ |
| 6238 | val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2); |
| 6239 | val8 |= BIT(0); |
| 6240 | rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8); |
| 6241 | |
| 6242 | return 0; |
| 6243 | } |
| 6244 | |
Jes Sorensen | 430b454 | 2016-02-29 17:05:48 -0500 | [diff] [blame] | 6245 | static int rtl8xxxu_flush_fifo(struct rtl8xxxu_priv *priv) |
| 6246 | { |
Jes Sorensen | 145428e | 2016-02-29 17:05:49 -0500 | [diff] [blame] | 6247 | struct device *dev = &priv->udev->dev; |
Jes Sorensen | 430b454 | 2016-02-29 17:05:48 -0500 | [diff] [blame] | 6248 | u32 val32; |
| 6249 | int retry, retval; |
| 6250 | |
| 6251 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); |
| 6252 | |
| 6253 | val32 = rtl8xxxu_read32(priv, REG_RXPKT_NUM); |
| 6254 | val32 |= RXPKT_NUM_RW_RELEASE_EN; |
| 6255 | rtl8xxxu_write32(priv, REG_RXPKT_NUM, val32); |
| 6256 | |
| 6257 | retry = 100; |
| 6258 | retval = -EBUSY; |
| 6259 | |
| 6260 | do { |
| 6261 | val32 = rtl8xxxu_read32(priv, REG_RXPKT_NUM); |
| 6262 | if (val32 & RXPKT_NUM_RXDMA_IDLE) { |
| 6263 | retval = 0; |
| 6264 | break; |
| 6265 | } |
| 6266 | } while (retry--); |
| 6267 | |
| 6268 | rtl8xxxu_write16(priv, REG_RQPN_NPQ, 0); |
| 6269 | rtl8xxxu_write32(priv, REG_RQPN, 0x80000000); |
| 6270 | mdelay(2); |
Jes Sorensen | 145428e | 2016-02-29 17:05:49 -0500 | [diff] [blame] | 6271 | |
| 6272 | if (!retry) |
| 6273 | dev_warn(dev, "Failed to flush FIFO\n"); |
Jes Sorensen | 430b454 | 2016-02-29 17:05:48 -0500 | [diff] [blame] | 6274 | |
| 6275 | return retval; |
| 6276 | } |
| 6277 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6278 | static int rtl8723au_power_on(struct rtl8xxxu_priv *priv) |
| 6279 | { |
| 6280 | u8 val8; |
| 6281 | u16 val16; |
| 6282 | u32 val32; |
| 6283 | int ret; |
| 6284 | |
| 6285 | /* |
| 6286 | * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register |
| 6287 | */ |
| 6288 | rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0); |
| 6289 | |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 6290 | rtl8723a_disabled_to_emu(priv); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6291 | |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 6292 | ret = rtl8723a_emu_to_active(priv); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6293 | if (ret) |
| 6294 | goto exit; |
| 6295 | |
| 6296 | /* |
| 6297 | * 0x0004[19] = 1, reset 8051 |
| 6298 | */ |
| 6299 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2); |
| 6300 | val8 |= BIT(3); |
| 6301 | rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8); |
| 6302 | |
| 6303 | /* |
| 6304 | * Enable MAC DMA/WMAC/SCHEDULE/SEC block |
| 6305 | * Set CR bit10 to enable 32k calibration. |
| 6306 | */ |
| 6307 | val16 = rtl8xxxu_read16(priv, REG_CR); |
| 6308 | val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE | |
| 6309 | CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | |
| 6310 | CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE | |
| 6311 | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE | |
| 6312 | CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE); |
| 6313 | rtl8xxxu_write16(priv, REG_CR, val16); |
| 6314 | |
| 6315 | /* For EFuse PG */ |
| 6316 | val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL); |
| 6317 | val32 &= ~(BIT(28) | BIT(29) | BIT(30)); |
| 6318 | val32 |= (0x06 << 28); |
| 6319 | rtl8xxxu_write32(priv, REG_EFUSE_CTRL, val32); |
| 6320 | exit: |
| 6321 | return ret; |
| 6322 | } |
| 6323 | |
Jes Sorensen | 42836db | 2016-02-29 17:04:52 -0500 | [diff] [blame] | 6324 | static int rtl8723bu_power_on(struct rtl8xxxu_priv *priv) |
| 6325 | { |
| 6326 | u8 val8; |
| 6327 | u16 val16; |
| 6328 | u32 val32; |
| 6329 | int ret; |
| 6330 | |
| 6331 | rtl8723a_disabled_to_emu(priv); |
| 6332 | |
| 6333 | ret = rtl8723b_emu_to_active(priv); |
| 6334 | if (ret) |
| 6335 | goto exit; |
| 6336 | |
| 6337 | /* |
| 6338 | * Enable MAC DMA/WMAC/SCHEDULE/SEC block |
| 6339 | * Set CR bit10 to enable 32k calibration. |
| 6340 | */ |
| 6341 | val16 = rtl8xxxu_read16(priv, REG_CR); |
| 6342 | val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE | |
| 6343 | CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | |
| 6344 | CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE | |
| 6345 | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE | |
| 6346 | CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE); |
| 6347 | rtl8xxxu_write16(priv, REG_CR, val16); |
| 6348 | |
| 6349 | /* |
| 6350 | * BT coexist power on settings. This is identical for 1 and 2 |
| 6351 | * antenna parts. |
| 6352 | */ |
| 6353 | rtl8xxxu_write8(priv, REG_PAD_CTRL1 + 3, 0x20); |
| 6354 | |
| 6355 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 6356 | val16 |= SYS_FUNC_BBRSTB | SYS_FUNC_BB_GLB_RSTN; |
| 6357 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 6358 | |
| 6359 | rtl8xxxu_write8(priv, REG_BT_CONTROL_8723BU + 1, 0x18); |
| 6360 | rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04); |
| 6361 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00); |
| 6362 | /* Antenna inverse */ |
| 6363 | rtl8xxxu_write8(priv, 0xfe08, 0x01); |
| 6364 | |
| 6365 | val16 = rtl8xxxu_read16(priv, REG_PWR_DATA); |
| 6366 | val16 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN; |
| 6367 | rtl8xxxu_write16(priv, REG_PWR_DATA, val16); |
| 6368 | |
| 6369 | val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); |
| 6370 | val32 |= LEDCFG0_DPDT_SELECT; |
| 6371 | rtl8xxxu_write32(priv, REG_LEDCFG0, val32); |
| 6372 | |
| 6373 | val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1); |
| 6374 | val8 &= ~PAD_CTRL1_SW_DPDT_SEL_DATA; |
| 6375 | rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8); |
| 6376 | exit: |
| 6377 | return ret; |
| 6378 | } |
| 6379 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 6380 | #ifdef CONFIG_RTL8XXXU_UNTESTED |
| 6381 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6382 | static int rtl8192cu_power_on(struct rtl8xxxu_priv *priv) |
| 6383 | { |
| 6384 | u8 val8; |
| 6385 | u16 val16; |
| 6386 | u32 val32; |
| 6387 | int i; |
| 6388 | |
| 6389 | for (i = 100; i; i--) { |
| 6390 | val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO); |
| 6391 | if (val8 & APS_FSMCO_PFM_ALDN) |
| 6392 | break; |
| 6393 | } |
| 6394 | |
| 6395 | if (!i) { |
| 6396 | pr_info("%s: Poll failed\n", __func__); |
| 6397 | return -ENODEV; |
| 6398 | } |
| 6399 | |
| 6400 | /* |
| 6401 | * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register |
| 6402 | */ |
| 6403 | rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0); |
| 6404 | rtl8xxxu_write8(priv, REG_SPS0_CTRL, 0x2b); |
| 6405 | udelay(100); |
| 6406 | |
| 6407 | val8 = rtl8xxxu_read8(priv, REG_LDOV12D_CTRL); |
| 6408 | if (!(val8 & LDOV12D_ENABLE)) { |
| 6409 | pr_info("%s: Enabling LDOV12D (%02x)\n", __func__, val8); |
| 6410 | val8 |= LDOV12D_ENABLE; |
| 6411 | rtl8xxxu_write8(priv, REG_LDOV12D_CTRL, val8); |
| 6412 | |
| 6413 | udelay(100); |
| 6414 | |
| 6415 | val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL); |
| 6416 | val8 &= ~SYS_ISO_MD2PP; |
| 6417 | rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8); |
| 6418 | } |
| 6419 | |
| 6420 | /* |
| 6421 | * Auto enable WLAN |
| 6422 | */ |
| 6423 | val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO); |
| 6424 | val16 |= APS_FSMCO_MAC_ENABLE; |
| 6425 | rtl8xxxu_write16(priv, REG_APS_FSMCO, val16); |
| 6426 | |
| 6427 | for (i = 1000; i; i--) { |
| 6428 | val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO); |
| 6429 | if (!(val16 & APS_FSMCO_MAC_ENABLE)) |
| 6430 | break; |
| 6431 | } |
| 6432 | if (!i) { |
| 6433 | pr_info("%s: FSMCO_MAC_ENABLE poll failed\n", __func__); |
| 6434 | return -EBUSY; |
| 6435 | } |
| 6436 | |
| 6437 | /* |
| 6438 | * Enable radio, GPIO, LED |
| 6439 | */ |
| 6440 | val16 = APS_FSMCO_HW_SUSPEND | APS_FSMCO_ENABLE_POWERDOWN | |
| 6441 | APS_FSMCO_PFM_ALDN; |
| 6442 | rtl8xxxu_write16(priv, REG_APS_FSMCO, val16); |
| 6443 | |
| 6444 | /* |
| 6445 | * Release RF digital isolation |
| 6446 | */ |
| 6447 | val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL); |
| 6448 | val16 &= ~SYS_ISO_DIOR; |
| 6449 | rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16); |
| 6450 | |
| 6451 | val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL); |
| 6452 | val8 &= ~APSD_CTRL_OFF; |
| 6453 | rtl8xxxu_write8(priv, REG_APSD_CTRL, val8); |
| 6454 | for (i = 200; i; i--) { |
| 6455 | val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL); |
| 6456 | if (!(val8 & APSD_CTRL_OFF_STATUS)) |
| 6457 | break; |
| 6458 | } |
| 6459 | |
| 6460 | if (!i) { |
| 6461 | pr_info("%s: APSD_CTRL poll failed\n", __func__); |
| 6462 | return -EBUSY; |
| 6463 | } |
| 6464 | |
| 6465 | /* |
| 6466 | * Enable MAC DMA/WMAC/SCHEDULE/SEC block |
| 6467 | */ |
| 6468 | val16 = rtl8xxxu_read16(priv, REG_CR); |
| 6469 | val16 |= CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE | |
| 6470 | CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | CR_PROTOCOL_ENABLE | |
| 6471 | CR_SCHEDULE_ENABLE | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE; |
| 6472 | rtl8xxxu_write16(priv, REG_CR, val16); |
| 6473 | |
| 6474 | /* |
| 6475 | * Workaround for 8188RU LNA power leakage problem. |
| 6476 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6477 | if (priv->rtl_chip == RTL8188C && priv->hi_pa) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6478 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM); |
| 6479 | val32 &= ~BIT(1); |
| 6480 | rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32); |
| 6481 | } |
| 6482 | return 0; |
| 6483 | } |
| 6484 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 6485 | #endif |
| 6486 | |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 6487 | static int rtl8192eu_power_on(struct rtl8xxxu_priv *priv) |
| 6488 | { |
| 6489 | u16 val16; |
| 6490 | u32 val32; |
| 6491 | int ret; |
| 6492 | |
| 6493 | ret = 0; |
| 6494 | |
| 6495 | val32 = rtl8xxxu_read32(priv, REG_SYS_CFG); |
| 6496 | if (val32 & SYS_CFG_SPS_LDO_SEL) { |
| 6497 | rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0xc3); |
| 6498 | } else { |
| 6499 | /* |
| 6500 | * Raise 1.2V voltage |
| 6501 | */ |
| 6502 | val32 = rtl8xxxu_read32(priv, REG_8192E_LDOV12_CTRL); |
| 6503 | val32 &= 0xff0fffff; |
| 6504 | val32 |= 0x00500000; |
| 6505 | rtl8xxxu_write32(priv, REG_8192E_LDOV12_CTRL, val32); |
| 6506 | rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0x83); |
| 6507 | } |
| 6508 | |
| 6509 | rtl8192e_disabled_to_emu(priv); |
| 6510 | |
| 6511 | ret = rtl8192e_emu_to_active(priv); |
| 6512 | if (ret) |
| 6513 | goto exit; |
| 6514 | |
| 6515 | rtl8xxxu_write16(priv, REG_CR, 0x0000); |
| 6516 | |
| 6517 | /* |
| 6518 | * Enable MAC DMA/WMAC/SCHEDULE/SEC block |
| 6519 | * Set CR bit10 to enable 32k calibration. |
| 6520 | */ |
| 6521 | val16 = rtl8xxxu_read16(priv, REG_CR); |
| 6522 | val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE | |
| 6523 | CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | |
| 6524 | CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE | |
| 6525 | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE | |
| 6526 | CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE); |
| 6527 | rtl8xxxu_write16(priv, REG_CR, val16); |
| 6528 | |
| 6529 | exit: |
| 6530 | return ret; |
| 6531 | } |
| 6532 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6533 | static void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv) |
| 6534 | { |
| 6535 | u8 val8; |
| 6536 | u16 val16; |
| 6537 | u32 val32; |
| 6538 | |
| 6539 | /* |
| 6540 | * Workaround for 8188RU LNA power leakage problem. |
| 6541 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6542 | if (priv->rtl_chip == RTL8188C && priv->hi_pa) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6543 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM); |
| 6544 | val32 |= BIT(1); |
| 6545 | rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32); |
| 6546 | } |
| 6547 | |
Jes Sorensen | 430b454 | 2016-02-29 17:05:48 -0500 | [diff] [blame] | 6548 | rtl8xxxu_flush_fifo(priv); |
| 6549 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6550 | rtl8xxxu_active_to_lps(priv); |
| 6551 | |
| 6552 | /* Turn off RF */ |
| 6553 | rtl8xxxu_write8(priv, REG_RF_CTRL, 0x00); |
| 6554 | |
| 6555 | /* Reset Firmware if running in RAM */ |
| 6556 | if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL) |
| 6557 | rtl8xxxu_firmware_self_reset(priv); |
| 6558 | |
| 6559 | /* Reset MCU */ |
| 6560 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 6561 | val16 &= ~SYS_FUNC_CPU_ENABLE; |
| 6562 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 6563 | |
| 6564 | /* Reset MCU ready status */ |
| 6565 | rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00); |
| 6566 | |
| 6567 | rtl8xxxu_active_to_emu(priv); |
| 6568 | rtl8xxxu_emu_to_disabled(priv); |
| 6569 | |
| 6570 | /* Reset MCU IO Wrapper */ |
| 6571 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); |
| 6572 | val8 &= ~BIT(0); |
| 6573 | rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); |
| 6574 | |
| 6575 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1); |
| 6576 | val8 |= BIT(0); |
| 6577 | rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8); |
| 6578 | |
| 6579 | /* RSV_CTRL 0x1C[7:0] = 0x0e lock ISO/CLK/Power control register */ |
| 6580 | rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0e); |
| 6581 | } |
| 6582 | |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 6583 | static void rtl8723bu_power_off(struct rtl8xxxu_priv *priv) |
| 6584 | { |
| 6585 | u8 val8; |
| 6586 | u16 val16; |
| 6587 | |
Jes Sorensen | 430b454 | 2016-02-29 17:05:48 -0500 | [diff] [blame] | 6588 | rtl8xxxu_flush_fifo(priv); |
| 6589 | |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 6590 | /* |
| 6591 | * Disable TX report timer |
| 6592 | */ |
| 6593 | val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL); |
| 6594 | val8 &= ~TX_REPORT_CTRL_TIMER_ENABLE; |
| 6595 | rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8); |
| 6596 | |
| 6597 | rtl8xxxu_write16(priv, REG_CR, 0x0000); |
| 6598 | |
| 6599 | rtl8xxxu_active_to_lps(priv); |
| 6600 | |
| 6601 | /* Reset Firmware if running in RAM */ |
| 6602 | if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL) |
| 6603 | rtl8xxxu_firmware_self_reset(priv); |
| 6604 | |
| 6605 | /* Reset MCU */ |
| 6606 | val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC); |
| 6607 | val16 &= ~SYS_FUNC_CPU_ENABLE; |
| 6608 | rtl8xxxu_write16(priv, REG_SYS_FUNC, val16); |
| 6609 | |
| 6610 | /* Reset MCU ready status */ |
| 6611 | rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00); |
| 6612 | |
| 6613 | rtl8723bu_active_to_emu(priv); |
| 6614 | rtl8xxxu_emu_to_disabled(priv); |
| 6615 | } |
| 6616 | |
Jes Sorensen | a3a5dac | 2016-02-29 17:05:16 -0500 | [diff] [blame] | 6617 | #ifdef NEED_PS_TDMA |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 6618 | static void rtl8723bu_set_ps_tdma(struct rtl8xxxu_priv *priv, |
| 6619 | u8 arg1, u8 arg2, u8 arg3, u8 arg4, u8 arg5) |
| 6620 | { |
| 6621 | struct h2c_cmd h2c; |
| 6622 | |
| 6623 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 6624 | h2c.b_type_dma.cmd = H2C_8723B_B_TYPE_TDMA; |
| 6625 | h2c.b_type_dma.data1 = arg1; |
| 6626 | h2c.b_type_dma.data2 = arg2; |
| 6627 | h2c.b_type_dma.data3 = arg3; |
| 6628 | h2c.b_type_dma.data4 = arg4; |
| 6629 | h2c.b_type_dma.data5 = arg5; |
| 6630 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.b_type_dma)); |
| 6631 | } |
Jes Sorensen | a3a5dac | 2016-02-29 17:05:16 -0500 | [diff] [blame] | 6632 | #endif |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 6633 | |
Jes Sorensen | 0290e7d | 2016-02-29 17:05:44 -0500 | [diff] [blame] | 6634 | static void rtl8723b_enable_rf(struct rtl8xxxu_priv *priv) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6635 | { |
Jes Sorensen | f37e922 | 2016-02-29 17:04:41 -0500 | [diff] [blame] | 6636 | struct h2c_cmd h2c; |
| 6637 | u32 val32; |
| 6638 | u8 val8; |
| 6639 | |
| 6640 | /* |
| 6641 | * No indication anywhere as to what 0x0790 does. The 2 antenna |
| 6642 | * vendor code preserves bits 6-7 here. |
| 6643 | */ |
| 6644 | rtl8xxxu_write8(priv, 0x0790, 0x05); |
| 6645 | /* |
| 6646 | * 0x0778 seems to be related to enabling the number of antennas |
| 6647 | * In the vendor driver halbtc8723b2ant_InitHwConfig() sets it |
| 6648 | * to 0x03, while halbtc8723b1ant_InitHwConfig() sets it to 0x01 |
| 6649 | */ |
| 6650 | rtl8xxxu_write8(priv, 0x0778, 0x01); |
| 6651 | |
| 6652 | val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG); |
| 6653 | val8 |= BIT(5); |
| 6654 | rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8); |
| 6655 | |
| 6656 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_IQADJ_G1, 0x780); |
| 6657 | |
Jes Sorensen | 394f1bd | 2016-02-29 17:04:49 -0500 | [diff] [blame] | 6658 | rtl8723bu_write_btreg(priv, 0x3c, 0x15); /* BT TRx Mask on */ |
| 6659 | |
Jes Sorensen | f37e922 | 2016-02-29 17:04:41 -0500 | [diff] [blame] | 6660 | /* |
| 6661 | * Set BT grant to low |
| 6662 | */ |
| 6663 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 6664 | h2c.bt_grant.cmd = H2C_8723B_BT_GRANT; |
| 6665 | h2c.bt_grant.data = 0; |
| 6666 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_grant)); |
| 6667 | |
| 6668 | /* |
| 6669 | * WLAN action by PTA |
| 6670 | */ |
Jes Sorensen | fc1c89b | 2016-02-29 17:05:12 -0500 | [diff] [blame] | 6671 | rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0x04); |
Jes Sorensen | f37e922 | 2016-02-29 17:04:41 -0500 | [diff] [blame] | 6672 | |
| 6673 | /* |
| 6674 | * BT select S0/S1 controlled by WiFi |
| 6675 | */ |
| 6676 | val8 = rtl8xxxu_read8(priv, 0x0067); |
| 6677 | val8 |= BIT(5); |
| 6678 | rtl8xxxu_write8(priv, 0x0067, val8); |
| 6679 | |
| 6680 | val32 = rtl8xxxu_read32(priv, REG_PWR_DATA); |
Jes Sorensen | 37f44dc | 2016-02-29 17:05:45 -0500 | [diff] [blame] | 6681 | val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN; |
Jes Sorensen | f37e922 | 2016-02-29 17:04:41 -0500 | [diff] [blame] | 6682 | rtl8xxxu_write32(priv, REG_PWR_DATA, val32); |
| 6683 | |
| 6684 | /* |
| 6685 | * Bits 6/7 are marked in/out ... but for what? |
| 6686 | */ |
| 6687 | rtl8xxxu_write8(priv, 0x0974, 0xff); |
| 6688 | |
Jes Sorensen | 120e627 | 2016-02-29 17:05:14 -0500 | [diff] [blame] | 6689 | val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER); |
Jes Sorensen | f37e922 | 2016-02-29 17:04:41 -0500 | [diff] [blame] | 6690 | val32 |= (BIT(0) | BIT(1)); |
Jes Sorensen | 120e627 | 2016-02-29 17:05:14 -0500 | [diff] [blame] | 6691 | rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32); |
Jes Sorensen | f37e922 | 2016-02-29 17:04:41 -0500 | [diff] [blame] | 6692 | |
| 6693 | rtl8xxxu_write8(priv, REG_RFE_CTRL_ANTA_SRC, 0x77); |
| 6694 | |
| 6695 | val32 = rtl8xxxu_read32(priv, REG_LEDCFG0); |
| 6696 | val32 &= ~BIT(24); |
| 6697 | val32 |= BIT(23); |
| 6698 | rtl8xxxu_write32(priv, REG_LEDCFG0, val32); |
| 6699 | |
| 6700 | /* |
| 6701 | * Fix external switch Main->S1, Aux->S0 |
| 6702 | */ |
| 6703 | val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1); |
| 6704 | val8 &= ~BIT(0); |
| 6705 | rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8); |
| 6706 | |
| 6707 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 6708 | h2c.ant_sel_rsv.cmd = H2C_8723B_ANT_SEL_RSV; |
| 6709 | h2c.ant_sel_rsv.ant_inverse = 1; |
| 6710 | h2c.ant_sel_rsv.int_switch_type = 0; |
| 6711 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ant_sel_rsv)); |
| 6712 | |
| 6713 | /* |
| 6714 | * 0x280, 0x00, 0x200, 0x80 - not clear |
| 6715 | */ |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 6716 | rtl8xxxu_write32(priv, REG_S0S1_PATH_SWITCH, 0x00); |
| 6717 | |
| 6718 | /* |
| 6719 | * Software control, antenna at WiFi side |
| 6720 | */ |
Jes Sorensen | a3a5dac | 2016-02-29 17:05:16 -0500 | [diff] [blame] | 6721 | #ifdef NEED_PS_TDMA |
Jes Sorensen | a228a5d | 2016-02-29 17:04:45 -0500 | [diff] [blame] | 6722 | rtl8723bu_set_ps_tdma(priv, 0x08, 0x00, 0x00, 0x00, 0x00); |
Jes Sorensen | a3a5dac | 2016-02-29 17:05:16 -0500 | [diff] [blame] | 6723 | #endif |
| 6724 | |
| 6725 | rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555); |
| 6726 | rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x55555555); |
| 6727 | rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff); |
| 6728 | rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03); |
Jes Sorensen | 3ca7b32 | 2016-02-29 17:04:43 -0500 | [diff] [blame] | 6729 | |
Jes Sorensen | 6b9eae0 | 2016-02-29 17:04:50 -0500 | [diff] [blame] | 6730 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 6731 | h2c.bt_info.cmd = H2C_8723B_BT_INFO; |
| 6732 | h2c.bt_info.data = BIT(0); |
| 6733 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.bt_info)); |
| 6734 | |
Jes Sorensen | 6b9eae0 | 2016-02-29 17:04:50 -0500 | [diff] [blame] | 6735 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 6736 | h2c.ignore_wlan.cmd = H2C_8723B_BT_IGNORE_WLANACT; |
| 6737 | h2c.ignore_wlan.data = 0; |
| 6738 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ignore_wlan)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6739 | } |
| 6740 | |
Jes Sorensen | fc89a41 | 2016-02-29 17:05:46 -0500 | [diff] [blame] | 6741 | static void rtl8723b_disable_rf(struct rtl8xxxu_priv *priv) |
| 6742 | { |
| 6743 | u32 val32; |
| 6744 | |
| 6745 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); |
| 6746 | |
| 6747 | val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA); |
| 6748 | val32 &= ~(BIT(22) | BIT(23)); |
| 6749 | rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32); |
| 6750 | } |
| 6751 | |
Jes Sorensen | 3e88ca4 | 2016-02-29 17:05:08 -0500 | [diff] [blame] | 6752 | static void rtl8723bu_init_aggregation(struct rtl8xxxu_priv *priv) |
| 6753 | { |
| 6754 | u32 agg_rx; |
| 6755 | u8 agg_ctrl; |
| 6756 | |
| 6757 | /* |
| 6758 | * For now simply disable RX aggregation |
| 6759 | */ |
| 6760 | agg_ctrl = rtl8xxxu_read8(priv, REG_TRXDMA_CTRL); |
| 6761 | agg_ctrl &= ~TRXDMA_CTRL_RXDMA_AGG_EN; |
| 6762 | |
| 6763 | agg_rx = rtl8xxxu_read32(priv, REG_RXDMA_AGG_PG_TH); |
| 6764 | agg_rx &= ~RXDMA_USB_AGG_ENABLE; |
| 6765 | agg_rx &= ~0xff0f; |
| 6766 | |
| 6767 | rtl8xxxu_write8(priv, REG_TRXDMA_CTRL, agg_ctrl); |
| 6768 | rtl8xxxu_write32(priv, REG_RXDMA_AGG_PG_TH, agg_rx); |
| 6769 | } |
| 6770 | |
Jes Sorensen | 9c79bf9 | 2016-02-29 17:05:10 -0500 | [diff] [blame] | 6771 | static void rtl8723bu_init_statistics(struct rtl8xxxu_priv *priv) |
| 6772 | { |
| 6773 | u32 val32; |
| 6774 | |
| 6775 | /* Time duration for NHM unit: 4us, 0x2710=40ms */ |
| 6776 | rtl8xxxu_write16(priv, REG_NHM_TIMER_8723B + 2, 0x2710); |
| 6777 | rtl8xxxu_write16(priv, REG_NHM_TH9_TH10_8723B + 2, 0xffff); |
| 6778 | rtl8xxxu_write32(priv, REG_NHM_TH3_TO_TH0_8723B, 0xffffff52); |
| 6779 | rtl8xxxu_write32(priv, REG_NHM_TH7_TO_TH4_8723B, 0xffffffff); |
| 6780 | /* TH8 */ |
| 6781 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK); |
| 6782 | val32 |= 0xff; |
| 6783 | rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32); |
| 6784 | /* Enable CCK */ |
| 6785 | val32 = rtl8xxxu_read32(priv, REG_NHM_TH9_TH10_8723B); |
| 6786 | val32 |= BIT(8) | BIT(9) | BIT(10); |
| 6787 | rtl8xxxu_write32(priv, REG_NHM_TH9_TH10_8723B, val32); |
| 6788 | /* Max power amongst all RX antennas */ |
| 6789 | val32 = rtl8xxxu_read32(priv, REG_OFDM0_FA_RSTC); |
| 6790 | val32 |= BIT(7); |
| 6791 | rtl8xxxu_write32(priv, REG_OFDM0_FA_RSTC, val32); |
| 6792 | } |
| 6793 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6794 | static int rtl8xxxu_init_device(struct ieee80211_hw *hw) |
| 6795 | { |
| 6796 | struct rtl8xxxu_priv *priv = hw->priv; |
| 6797 | struct device *dev = &priv->udev->dev; |
| 6798 | struct rtl8xxxu_rfregval *rftable; |
| 6799 | bool macpower; |
| 6800 | int ret; |
| 6801 | u8 val8; |
| 6802 | u16 val16; |
| 6803 | u32 val32; |
| 6804 | |
| 6805 | /* Check if MAC is already powered on */ |
| 6806 | val8 = rtl8xxxu_read8(priv, REG_CR); |
| 6807 | |
| 6808 | /* |
| 6809 | * Fix 92DU-VC S3 hang with the reason is that secondary mac is not |
| 6810 | * initialized. First MAC returns 0xea, second MAC returns 0x00 |
| 6811 | */ |
| 6812 | if (val8 == 0xea) |
| 6813 | macpower = false; |
| 6814 | else |
| 6815 | macpower = true; |
| 6816 | |
| 6817 | ret = priv->fops->power_on(priv); |
| 6818 | if (ret < 0) { |
| 6819 | dev_warn(dev, "%s: Failed power on\n", __func__); |
| 6820 | goto exit; |
| 6821 | } |
| 6822 | |
| 6823 | dev_dbg(dev, "%s: macpower %i\n", __func__, macpower); |
| 6824 | if (!macpower) { |
Jes Sorensen | 79fb5fe | 2016-02-29 17:04:53 -0500 | [diff] [blame] | 6825 | ret = priv->fops->llt_init(priv, TX_TOTAL_PAGE_NUM); |
| 6826 | if (ret) { |
| 6827 | dev_warn(dev, "%s: LLT table init failed\n", __func__); |
| 6828 | goto exit; |
| 6829 | } |
| 6830 | |
| 6831 | /* |
| 6832 | * Presumably this is for 8188EU as well |
| 6833 | * Enable TX report and TX report timer |
| 6834 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6835 | if (priv->rtl_chip == RTL8723B) { |
Jes Sorensen | 79fb5fe | 2016-02-29 17:04:53 -0500 | [diff] [blame] | 6836 | val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL); |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 6837 | val8 |= TX_REPORT_CTRL_TIMER_ENABLE; |
Jes Sorensen | 79fb5fe | 2016-02-29 17:04:53 -0500 | [diff] [blame] | 6838 | rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8); |
| 6839 | /* Set MAX RPT MACID */ |
| 6840 | rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1, 0x02); |
| 6841 | /* TX report Timer. Unit: 32us */ |
| 6842 | rtl8xxxu_write16(priv, REG_TX_REPORT_TIME, 0xcdf0); |
Jes Sorensen | 360157e | 2016-02-29 17:04:57 -0500 | [diff] [blame] | 6843 | |
| 6844 | /* tmp ps ? */ |
| 6845 | val8 = rtl8xxxu_read8(priv, 0xa3); |
| 6846 | val8 &= 0xf8; |
| 6847 | rtl8xxxu_write8(priv, 0xa3, val8); |
Jes Sorensen | 79fb5fe | 2016-02-29 17:04:53 -0500 | [diff] [blame] | 6848 | } |
Jes Sorensen | 07bb46b | 2016-02-29 17:04:05 -0500 | [diff] [blame] | 6849 | } |
| 6850 | |
Jes Sorensen | a47b9d4 | 2016-02-29 17:04:06 -0500 | [diff] [blame] | 6851 | ret = rtl8xxxu_download_firmware(priv); |
| 6852 | dev_dbg(dev, "%s: download_fiwmare %i\n", __func__, ret); |
| 6853 | if (ret) |
| 6854 | goto exit; |
| 6855 | ret = rtl8xxxu_start_firmware(priv); |
| 6856 | dev_dbg(dev, "%s: start_fiwmare %i\n", __func__, ret); |
| 6857 | if (ret) |
| 6858 | goto exit; |
| 6859 | |
Jes Sorensen | 6431ea0 | 2016-02-29 17:04:21 -0500 | [diff] [blame] | 6860 | /* Solve too many protocol error on USB bus */ |
| 6861 | /* Can't do this for 8188/8192 UMC A cut parts */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6862 | if (priv->rtl_chip == RTL8723A || |
| 6863 | ((priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C || |
| 6864 | priv->rtl_chip == RTL8188C) && |
Jes Sorensen | 6431ea0 | 2016-02-29 17:04:21 -0500 | [diff] [blame] | 6865 | (priv->chip_cut || !priv->vendor_umc))) { |
| 6866 | rtl8xxxu_write8(priv, 0xfe40, 0xe6); |
| 6867 | rtl8xxxu_write8(priv, 0xfe41, 0x94); |
| 6868 | rtl8xxxu_write8(priv, 0xfe42, 0x80); |
| 6869 | |
| 6870 | rtl8xxxu_write8(priv, 0xfe40, 0xe0); |
| 6871 | rtl8xxxu_write8(priv, 0xfe41, 0x19); |
| 6872 | rtl8xxxu_write8(priv, 0xfe42, 0x80); |
| 6873 | |
| 6874 | rtl8xxxu_write8(priv, 0xfe40, 0xe5); |
| 6875 | rtl8xxxu_write8(priv, 0xfe41, 0x91); |
| 6876 | rtl8xxxu_write8(priv, 0xfe42, 0x80); |
| 6877 | |
| 6878 | rtl8xxxu_write8(priv, 0xfe40, 0xe2); |
| 6879 | rtl8xxxu_write8(priv, 0xfe41, 0x81); |
| 6880 | rtl8xxxu_write8(priv, 0xfe42, 0x80); |
| 6881 | } |
| 6882 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6883 | if (priv->rtl_chip == RTL8192E) { |
Jes Sorensen | 99ad16c | 2016-02-29 17:04:09 -0500 | [diff] [blame] | 6884 | rtl8xxxu_write32(priv, REG_HIMR0, 0x00); |
| 6885 | rtl8xxxu_write32(priv, REG_HIMR1, 0x00); |
Jes Sorensen | b63d0aa | 2016-02-29 17:04:08 -0500 | [diff] [blame] | 6886 | } |
| 6887 | |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 6888 | if (priv->fops->phy_init_antenna_selection) |
| 6889 | priv->fops->phy_init_antenna_selection(priv); |
| 6890 | |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 6891 | ret = rtl8xxxu_init_mac(priv); |
Jes Sorensen | b7dd8ff | 2016-02-29 17:04:17 -0500 | [diff] [blame] | 6892 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6893 | dev_dbg(dev, "%s: init_mac %i\n", __func__, ret); |
| 6894 | if (ret) |
| 6895 | goto exit; |
| 6896 | |
| 6897 | ret = rtl8xxxu_init_phy_bb(priv); |
| 6898 | dev_dbg(dev, "%s: init_phy_bb %i\n", __func__, ret); |
| 6899 | if (ret) |
| 6900 | goto exit; |
| 6901 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6902 | switch(priv->rtl_chip) { |
| 6903 | case RTL8723A: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6904 | rftable = rtl8723au_radioa_1t_init_table; |
| 6905 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A); |
| 6906 | break; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6907 | case RTL8723B: |
Jes Sorensen | 22a31d4 | 2016-02-29 17:04:15 -0500 | [diff] [blame] | 6908 | rftable = rtl8723bu_radioa_1t_init_table; |
| 6909 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A); |
Jes Sorensen | 5ac6178 | 2016-02-29 17:05:05 -0500 | [diff] [blame] | 6910 | /* |
| 6911 | * PHY LCK |
| 6912 | */ |
| 6913 | rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdfbe0); |
| 6914 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, 0x8c01); |
| 6915 | msleep(200); |
| 6916 | rtl8xxxu_write_rfreg(priv, RF_A, 0xb0, 0xdffe0); |
Jes Sorensen | 22a31d4 | 2016-02-29 17:04:15 -0500 | [diff] [blame] | 6917 | break; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6918 | case RTL8188C: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6919 | if (priv->hi_pa) |
| 6920 | rftable = rtl8188ru_radioa_1t_highpa_table; |
| 6921 | else |
| 6922 | rftable = rtl8192cu_radioa_1t_init_table; |
| 6923 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A); |
| 6924 | break; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6925 | case RTL8191C: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6926 | rftable = rtl8192cu_radioa_1t_init_table; |
| 6927 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A); |
| 6928 | break; |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6929 | case RTL8192C: |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6930 | rftable = rtl8192cu_radioa_2t_init_table; |
| 6931 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A); |
| 6932 | if (ret) |
| 6933 | break; |
| 6934 | rftable = rtl8192cu_radiob_2t_init_table; |
| 6935 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B); |
| 6936 | break; |
Jes Sorensen | 19102f8 | 2016-04-07 14:19:19 -0400 | [diff] [blame] | 6937 | case RTL8192E: |
| 6938 | rftable = rtl8192eu_radioa_init_table; |
| 6939 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A); |
| 6940 | if (ret) |
| 6941 | break; |
| 6942 | rftable = rtl8192eu_radiob_init_table; |
| 6943 | ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B); |
| 6944 | break; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6945 | default: |
| 6946 | ret = -EINVAL; |
| 6947 | } |
| 6948 | |
| 6949 | if (ret) |
| 6950 | goto exit; |
| 6951 | |
Jes Sorensen | 2f109c8 | 2016-02-29 17:05:07 -0500 | [diff] [blame] | 6952 | /* |
| 6953 | * Chip specific quirks |
| 6954 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6955 | if (priv->rtl_chip == RTL8723A) { |
Jes Sorensen | 2f109c8 | 2016-02-29 17:05:07 -0500 | [diff] [blame] | 6956 | /* Fix USB interface interference issue */ |
| 6957 | rtl8xxxu_write8(priv, 0xfe40, 0xe0); |
| 6958 | rtl8xxxu_write8(priv, 0xfe41, 0x8d); |
| 6959 | rtl8xxxu_write8(priv, 0xfe42, 0x80); |
| 6960 | rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320); |
| 6961 | |
| 6962 | /* Reduce 80M spur */ |
Jes Sorensen | f30ed67 | 2016-02-29 17:04:59 -0500 | [diff] [blame] | 6963 | rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d); |
| 6964 | rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83); |
| 6965 | rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82); |
| 6966 | rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83); |
Jes Sorensen | 2f109c8 | 2016-02-29 17:05:07 -0500 | [diff] [blame] | 6967 | } else { |
| 6968 | val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK); |
| 6969 | val32 |= TXDMA_OFFSET_DROP_DATA_EN; |
| 6970 | rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32); |
Jes Sorensen | f30ed67 | 2016-02-29 17:04:59 -0500 | [diff] [blame] | 6971 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 6972 | |
Jes Sorensen | f2a4163 | 2016-02-29 17:05:09 -0500 | [diff] [blame] | 6973 | if (!macpower) { |
Jes Sorensen | 1f1b20f | 2016-02-29 17:05:00 -0500 | [diff] [blame] | 6974 | if (priv->ep_tx_normal_queue) |
| 6975 | val8 = TX_PAGE_NUM_NORM_PQ; |
| 6976 | else |
| 6977 | val8 = 0; |
| 6978 | |
| 6979 | rtl8xxxu_write8(priv, REG_RQPN_NPQ, val8); |
| 6980 | |
| 6981 | val32 = (TX_PAGE_NUM_PUBQ << RQPN_NORM_PQ_SHIFT) | RQPN_LOAD; |
| 6982 | |
| 6983 | if (priv->ep_tx_high_queue) |
| 6984 | val32 |= (TX_PAGE_NUM_HI_PQ << RQPN_HI_PQ_SHIFT); |
| 6985 | if (priv->ep_tx_low_queue) |
| 6986 | val32 |= (TX_PAGE_NUM_LO_PQ << RQPN_LO_PQ_SHIFT); |
| 6987 | |
| 6988 | rtl8xxxu_write32(priv, REG_RQPN, val32); |
| 6989 | |
| 6990 | /* |
| 6991 | * Set TX buffer boundary |
| 6992 | */ |
Jes Sorensen | 80805aa | 2016-04-07 14:19:18 -0400 | [diff] [blame] | 6993 | if (priv->rtl_chip == RTL8192E) |
| 6994 | val8 = TX_TOTAL_PAGE_NUM_8192E + 1; |
| 6995 | else |
| 6996 | val8 = TX_TOTAL_PAGE_NUM + 1; |
Jes Sorensen | 1f1b20f | 2016-02-29 17:05:00 -0500 | [diff] [blame] | 6997 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 6998 | if (priv->rtl_chip == RTL8723B) |
Jes Sorensen | 1f1b20f | 2016-02-29 17:05:00 -0500 | [diff] [blame] | 6999 | val8 -= 1; |
| 7000 | |
| 7001 | rtl8xxxu_write8(priv, REG_TXPKTBUF_BCNQ_BDNY, val8); |
| 7002 | rtl8xxxu_write8(priv, REG_TXPKTBUF_MGQ_BDNY, val8); |
| 7003 | rtl8xxxu_write8(priv, REG_TXPKTBUF_WMAC_LBK_BF_HD, val8); |
| 7004 | rtl8xxxu_write8(priv, REG_TRXFF_BNDY, val8); |
| 7005 | rtl8xxxu_write8(priv, REG_TDECTRL + 1, val8); |
| 7006 | } |
| 7007 | |
| 7008 | ret = rtl8xxxu_init_queue_priority(priv); |
| 7009 | dev_dbg(dev, "%s: init_queue_priority %i\n", __func__, ret); |
| 7010 | if (ret) |
| 7011 | goto exit; |
| 7012 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7013 | /* RFSW Control - clear bit 14 ?? */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 7014 | if (priv->rtl_chip != RTL8723B) |
Jes Sorensen | b87212c | 2016-02-29 17:05:01 -0500 | [diff] [blame] | 7015 | rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, 0x00000003); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7016 | /* 0x07000760 */ |
| 7017 | val32 = FPGA0_RF_TRSW | FPGA0_RF_TRSWB | FPGA0_RF_ANTSW | |
| 7018 | FPGA0_RF_ANTSWB | FPGA0_RF_PAPE | |
| 7019 | ((FPGA0_RF_ANTSW | FPGA0_RF_ANTSWB | FPGA0_RF_PAPE) << |
| 7020 | FPGA0_RF_BD_CTRL_SHIFT); |
| 7021 | rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32); |
| 7022 | /* 0x860[6:5]= 00 - why? - this sets antenna B */ |
| 7023 | rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, 0x66F60210); |
| 7024 | |
| 7025 | priv->rf_mode_ag[0] = rtl8xxxu_read_rfreg(priv, RF_A, |
| 7026 | RF6052_REG_MODE_AG); |
| 7027 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7028 | /* |
| 7029 | * Set RX page boundary |
| 7030 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 7031 | if (priv->rtl_chip == RTL8723B) |
Jes Sorensen | fadfa04 | 2016-02-29 17:05:02 -0500 | [diff] [blame] | 7032 | rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x3f7f); |
Jes Sorensen | 80805aa | 2016-04-07 14:19:18 -0400 | [diff] [blame] | 7033 | else if (priv->rtl_chip == RTL8192E) |
| 7034 | rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x3cff); |
Jes Sorensen | fadfa04 | 2016-02-29 17:05:02 -0500 | [diff] [blame] | 7035 | else |
| 7036 | rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x27ff); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7037 | /* |
| 7038 | * Transfer page size is always 128 |
| 7039 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 7040 | if (priv->rtl_chip == RTL8723B) |
Jes Sorensen | b87212c | 2016-02-29 17:05:01 -0500 | [diff] [blame] | 7041 | val8 = (PBP_PAGE_SIZE_256 << PBP_PAGE_SIZE_RX_SHIFT) | |
| 7042 | (PBP_PAGE_SIZE_256 << PBP_PAGE_SIZE_TX_SHIFT); |
| 7043 | else |
| 7044 | val8 = (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_RX_SHIFT) | |
| 7045 | (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_TX_SHIFT); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7046 | rtl8xxxu_write8(priv, REG_PBP, val8); |
| 7047 | |
| 7048 | /* |
| 7049 | * Unit in 8 bytes, not obvious what it is used for |
| 7050 | */ |
| 7051 | rtl8xxxu_write8(priv, REG_RX_DRVINFO_SZ, 4); |
| 7052 | |
| 7053 | /* |
| 7054 | * Enable all interrupts - not obvious USB needs to do this |
| 7055 | */ |
| 7056 | rtl8xxxu_write32(priv, REG_HISR, 0xffffffff); |
| 7057 | rtl8xxxu_write32(priv, REG_HIMR, 0xffffffff); |
| 7058 | |
| 7059 | rtl8xxxu_set_mac(priv); |
| 7060 | rtl8xxxu_set_linktype(priv, NL80211_IFTYPE_STATION); |
| 7061 | |
| 7062 | /* |
| 7063 | * Configure initial WMAC settings |
| 7064 | */ |
| 7065 | val32 = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_MCAST | RCR_ACCEPT_BCAST | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7066 | RCR_ACCEPT_MGMT_FRAME | RCR_HTC_LOC_CTRL | |
| 7067 | RCR_APPEND_PHYSTAT | RCR_APPEND_ICV | RCR_APPEND_MIC; |
| 7068 | rtl8xxxu_write32(priv, REG_RCR, val32); |
| 7069 | |
| 7070 | /* |
| 7071 | * Accept all multicast |
| 7072 | */ |
| 7073 | rtl8xxxu_write32(priv, REG_MAR, 0xffffffff); |
| 7074 | rtl8xxxu_write32(priv, REG_MAR + 4, 0xffffffff); |
| 7075 | |
| 7076 | /* |
| 7077 | * Init adaptive controls |
| 7078 | */ |
| 7079 | val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET); |
| 7080 | val32 &= ~RESPONSE_RATE_BITMAP_ALL; |
| 7081 | val32 |= RESPONSE_RATE_RRSR_CCK_ONLY_1M; |
| 7082 | rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32); |
| 7083 | |
| 7084 | /* CCK = 0x0a, OFDM = 0x10 */ |
| 7085 | rtl8xxxu_set_spec_sifs(priv, 0x10, 0x10); |
| 7086 | rtl8xxxu_set_retry(priv, 0x30, 0x30); |
| 7087 | rtl8xxxu_set_spec_sifs(priv, 0x0a, 0x10); |
| 7088 | |
| 7089 | /* |
| 7090 | * Init EDCA |
| 7091 | */ |
| 7092 | rtl8xxxu_write16(priv, REG_MAC_SPEC_SIFS, 0x100a); |
| 7093 | |
| 7094 | /* Set CCK SIFS */ |
| 7095 | rtl8xxxu_write16(priv, REG_SIFS_CCK, 0x100a); |
| 7096 | |
| 7097 | /* Set OFDM SIFS */ |
| 7098 | rtl8xxxu_write16(priv, REG_SIFS_OFDM, 0x100a); |
| 7099 | |
| 7100 | /* TXOP */ |
| 7101 | rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, 0x005ea42b); |
| 7102 | rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, 0x0000a44f); |
| 7103 | rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, 0x005ea324); |
| 7104 | rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, 0x002fa226); |
| 7105 | |
| 7106 | /* Set data auto rate fallback retry count */ |
| 7107 | rtl8xxxu_write32(priv, REG_DARFRC, 0x00000000); |
| 7108 | rtl8xxxu_write32(priv, REG_DARFRC + 4, 0x10080404); |
| 7109 | rtl8xxxu_write32(priv, REG_RARFRC, 0x04030201); |
| 7110 | rtl8xxxu_write32(priv, REG_RARFRC + 4, 0x08070605); |
| 7111 | |
| 7112 | val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL); |
| 7113 | val8 |= FWHW_TXQ_CTRL_AMPDU_RETRY; |
| 7114 | rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, val8); |
| 7115 | |
| 7116 | /* Set ACK timeout */ |
| 7117 | rtl8xxxu_write8(priv, REG_ACKTO, 0x40); |
| 7118 | |
| 7119 | /* |
| 7120 | * Initialize beacon parameters |
| 7121 | */ |
| 7122 | val16 = BEACON_DISABLE_TSF_UPDATE | (BEACON_DISABLE_TSF_UPDATE << 8); |
| 7123 | rtl8xxxu_write16(priv, REG_BEACON_CTRL, val16); |
| 7124 | rtl8xxxu_write16(priv, REG_TBTT_PROHIBIT, 0x6404); |
| 7125 | rtl8xxxu_write8(priv, REG_DRIVER_EARLY_INT, DRIVER_EARLY_INT_TIME); |
| 7126 | rtl8xxxu_write8(priv, REG_BEACON_DMA_TIME, BEACON_DMA_ATIME_INT_TIME); |
| 7127 | rtl8xxxu_write16(priv, REG_BEACON_TCFG, 0x660F); |
| 7128 | |
| 7129 | /* |
Jes Sorensen | c369060 | 2016-02-29 17:05:03 -0500 | [diff] [blame] | 7130 | * Initialize burst parameters |
| 7131 | */ |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 7132 | if (priv->rtl_chip == RTL8723B) { |
Jes Sorensen | c369060 | 2016-02-29 17:05:03 -0500 | [diff] [blame] | 7133 | /* |
| 7134 | * For USB high speed set 512B packets |
| 7135 | */ |
| 7136 | val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B); |
| 7137 | val8 &= ~(BIT(4) | BIT(5)); |
| 7138 | val8 |= BIT(4); |
| 7139 | val8 |= BIT(1) | BIT(2) | BIT(3); |
| 7140 | rtl8xxxu_write8(priv, REG_RXDMA_PRO_8723B, val8); |
| 7141 | |
| 7142 | /* |
| 7143 | * For USB high speed set 512B packets |
| 7144 | */ |
| 7145 | val8 = rtl8xxxu_read8(priv, REG_HT_SINGLE_AMPDU_8723B); |
| 7146 | val8 |= BIT(7); |
| 7147 | rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8); |
| 7148 | |
| 7149 | rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14); |
| 7150 | rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, 0x5e); |
| 7151 | rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff); |
| 7152 | rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18); |
| 7153 | rtl8xxxu_write8(priv, REG_PIFS, 0x00); |
| 7154 | rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, 0x50); |
| 7155 | rtl8xxxu_write8(priv, REG_USTIME_EDCA, 0x50); |
| 7156 | |
| 7157 | val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL); |
| 7158 | val8 |= BIT(5) | BIT(6); |
| 7159 | rtl8xxxu_write8(priv, REG_RSV_CTRL, val8); |
| 7160 | } |
| 7161 | |
Jes Sorensen | 3e88ca4 | 2016-02-29 17:05:08 -0500 | [diff] [blame] | 7162 | if (priv->fops->init_aggregation) |
| 7163 | priv->fops->init_aggregation(priv); |
| 7164 | |
Jes Sorensen | c369060 | 2016-02-29 17:05:03 -0500 | [diff] [blame] | 7165 | /* |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7166 | * Enable CCK and OFDM block |
| 7167 | */ |
| 7168 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 7169 | val32 |= (FPGA_RF_MODE_CCK | FPGA_RF_MODE_OFDM); |
| 7170 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 7171 | |
| 7172 | /* |
| 7173 | * Invalidate all CAM entries - bit 30 is undocumented |
| 7174 | */ |
| 7175 | rtl8xxxu_write32(priv, REG_CAM_CMD, CAM_CMD_POLLING | BIT(30)); |
| 7176 | |
| 7177 | /* |
| 7178 | * Start out with default power levels for channel 6, 20MHz |
| 7179 | */ |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 7180 | priv->fops->set_tx_power(priv, 1, false); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7181 | |
| 7182 | /* Let the 8051 take control of antenna setting */ |
| 7183 | val8 = rtl8xxxu_read8(priv, REG_LEDCFG2); |
| 7184 | val8 |= LEDCFG2_DPDT_SELECT; |
| 7185 | rtl8xxxu_write8(priv, REG_LEDCFG2, val8); |
| 7186 | |
| 7187 | rtl8xxxu_write8(priv, REG_HWSEQ_CTRL, 0xff); |
| 7188 | |
| 7189 | /* Disable BAR - not sure if this has any effect on USB */ |
| 7190 | rtl8xxxu_write32(priv, REG_BAR_MODE_CTRL, 0x0201ffff); |
| 7191 | |
| 7192 | rtl8xxxu_write16(priv, REG_FAST_EDCA_CTRL, 0); |
| 7193 | |
Jes Sorensen | 9c79bf9 | 2016-02-29 17:05:10 -0500 | [diff] [blame] | 7194 | if (priv->fops->init_statistics) |
| 7195 | priv->fops->init_statistics(priv); |
| 7196 | |
Jes Sorensen | fa0f2d4 | 2016-02-29 17:04:37 -0500 | [diff] [blame] | 7197 | rtl8723a_phy_lc_calibrate(priv); |
| 7198 | |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 7199 | priv->fops->phy_iq_calibrate(priv); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7200 | |
| 7201 | /* |
| 7202 | * This should enable thermal meter |
| 7203 | */ |
Jes Sorensen | 72143b9 | 2016-02-29 17:05:25 -0500 | [diff] [blame] | 7204 | if (priv->fops->has_s0s1) |
| 7205 | rtl8xxxu_write_rfreg(priv, |
| 7206 | RF_A, RF6052_REG_T_METER_8723B, 0x37cf8); |
| 7207 | else |
| 7208 | rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_T_METER, 0x60); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7209 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7210 | /* Set NAV_UPPER to 30000us */ |
| 7211 | val8 = ((30000 + NAV_UPPER_UNIT - 1) / NAV_UPPER_UNIT); |
| 7212 | rtl8xxxu_write8(priv, REG_NAV_UPPER, val8); |
| 7213 | |
Jes Sorensen | ba17d82 | 2016-03-31 17:08:39 -0400 | [diff] [blame] | 7214 | if (priv->rtl_chip == RTL8723A) { |
Jes Sorensen | 4042e61 | 2016-02-03 13:40:01 -0500 | [diff] [blame] | 7215 | /* |
| 7216 | * 2011/03/09 MH debug only, UMC-B cut pass 2500 S5 test, |
| 7217 | * but we need to find root cause. |
| 7218 | * This is 8723au only. |
| 7219 | */ |
| 7220 | val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE); |
| 7221 | if ((val32 & 0xff000000) != 0x83000000) { |
| 7222 | val32 |= FPGA_RF_MODE_CCK; |
| 7223 | rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32); |
| 7224 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | val32 = rtl8xxxu_read32(priv, REG_FWHW_TXQ_CTRL); |
| 7228 | val32 |= FWHW_TXQ_CTRL_XMIT_MGMT_ACK; |
| 7229 | /* ack for xmit mgmt frames. */ |
| 7230 | rtl8xxxu_write32(priv, REG_FWHW_TXQ_CTRL, val32); |
| 7231 | |
| 7232 | exit: |
| 7233 | return ret; |
| 7234 | } |
| 7235 | |
| 7236 | static void rtl8xxxu_disable_device(struct ieee80211_hw *hw) |
| 7237 | { |
| 7238 | struct rtl8xxxu_priv *priv = hw->priv; |
| 7239 | |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 7240 | priv->fops->power_off(priv); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | static void rtl8xxxu_cam_write(struct rtl8xxxu_priv *priv, |
| 7244 | struct ieee80211_key_conf *key, const u8 *mac) |
| 7245 | { |
| 7246 | u32 cmd, val32, addr, ctrl; |
| 7247 | int j, i, tmp_debug; |
| 7248 | |
| 7249 | tmp_debug = rtl8xxxu_debug; |
| 7250 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_KEY) |
| 7251 | rtl8xxxu_debug |= RTL8XXXU_DEBUG_REG_WRITE; |
| 7252 | |
| 7253 | /* |
| 7254 | * This is a bit of a hack - the lower bits of the cipher |
| 7255 | * suite selector happens to match the cipher index in the CAM |
| 7256 | */ |
| 7257 | addr = key->keyidx << CAM_CMD_KEY_SHIFT; |
| 7258 | ctrl = (key->cipher & 0x0f) << 2 | key->keyidx | CAM_WRITE_VALID; |
| 7259 | |
| 7260 | for (j = 5; j >= 0; j--) { |
| 7261 | switch (j) { |
| 7262 | case 0: |
| 7263 | val32 = ctrl | (mac[0] << 16) | (mac[1] << 24); |
| 7264 | break; |
| 7265 | case 1: |
| 7266 | val32 = mac[2] | (mac[3] << 8) | |
| 7267 | (mac[4] << 16) | (mac[5] << 24); |
| 7268 | break; |
| 7269 | default: |
| 7270 | i = (j - 2) << 2; |
| 7271 | val32 = key->key[i] | (key->key[i + 1] << 8) | |
| 7272 | key->key[i + 2] << 16 | key->key[i + 3] << 24; |
| 7273 | break; |
| 7274 | } |
| 7275 | |
| 7276 | rtl8xxxu_write32(priv, REG_CAM_WRITE, val32); |
| 7277 | cmd = CAM_CMD_POLLING | CAM_CMD_WRITE | (addr + j); |
| 7278 | rtl8xxxu_write32(priv, REG_CAM_CMD, cmd); |
| 7279 | udelay(100); |
| 7280 | } |
| 7281 | |
| 7282 | rtl8xxxu_debug = tmp_debug; |
| 7283 | } |
| 7284 | |
| 7285 | static void rtl8xxxu_sw_scan_start(struct ieee80211_hw *hw, |
Jes Sorensen | 56e4374 | 2016-02-03 13:39:50 -0500 | [diff] [blame] | 7286 | struct ieee80211_vif *vif, const u8 *mac) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7287 | { |
| 7288 | struct rtl8xxxu_priv *priv = hw->priv; |
| 7289 | u8 val8; |
| 7290 | |
| 7291 | val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL); |
| 7292 | val8 |= BEACON_DISABLE_TSF_UPDATE; |
| 7293 | rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8); |
| 7294 | } |
| 7295 | |
| 7296 | static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw, |
| 7297 | struct ieee80211_vif *vif) |
| 7298 | { |
| 7299 | struct rtl8xxxu_priv *priv = hw->priv; |
| 7300 | u8 val8; |
| 7301 | |
| 7302 | val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL); |
| 7303 | val8 &= ~BEACON_DISABLE_TSF_UPDATE; |
| 7304 | rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8); |
| 7305 | } |
| 7306 | |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 7307 | static void rtl8723au_update_rate_mask(struct rtl8xxxu_priv *priv, |
| 7308 | u32 ramask, int sgi) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7309 | { |
| 7310 | struct h2c_cmd h2c; |
| 7311 | |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 7312 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 7313 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7314 | h2c.ramask.cmd = H2C_SET_RATE_MASK; |
| 7315 | h2c.ramask.mask_lo = cpu_to_le16(ramask & 0xffff); |
| 7316 | h2c.ramask.mask_hi = cpu_to_le16(ramask >> 16); |
| 7317 | |
| 7318 | h2c.ramask.arg = 0x80; |
| 7319 | if (sgi) |
| 7320 | h2c.ramask.arg |= 0x20; |
| 7321 | |
Jes Sorensen | 7ff8c1a | 2016-02-29 17:04:32 -0500 | [diff] [blame] | 7322 | dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n", |
Jes Sorensen | 8da9157 | 2016-02-29 17:04:29 -0500 | [diff] [blame] | 7323 | __func__, ramask, h2c.ramask.arg, sizeof(h2c.ramask)); |
| 7324 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.ramask)); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7325 | } |
| 7326 | |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 7327 | static void rtl8723bu_update_rate_mask(struct rtl8xxxu_priv *priv, |
| 7328 | u32 ramask, int sgi) |
| 7329 | { |
| 7330 | struct h2c_cmd h2c; |
| 7331 | u8 bw = 0; |
| 7332 | |
| 7333 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 7334 | |
| 7335 | h2c.b_macid_cfg.cmd = H2C_8723B_MACID_CFG_RAID; |
| 7336 | h2c.b_macid_cfg.ramask0 = ramask & 0xff; |
| 7337 | h2c.b_macid_cfg.ramask1 = (ramask >> 8) & 0xff; |
| 7338 | h2c.b_macid_cfg.ramask2 = (ramask >> 16) & 0xff; |
| 7339 | h2c.b_macid_cfg.ramask3 = (ramask >> 24) & 0xff; |
| 7340 | |
| 7341 | h2c.ramask.arg = 0x80; |
| 7342 | h2c.b_macid_cfg.data1 = 0; |
| 7343 | if (sgi) |
| 7344 | h2c.b_macid_cfg.data1 |= BIT(7); |
| 7345 | |
| 7346 | h2c.b_macid_cfg.data2 = bw; |
| 7347 | |
| 7348 | dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n", |
| 7349 | __func__, ramask, h2c.ramask.arg, sizeof(h2c.b_macid_cfg)); |
| 7350 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.b_macid_cfg)); |
| 7351 | } |
| 7352 | |
Jes Sorensen | 7d794ea | 2016-02-29 17:05:39 -0500 | [diff] [blame] | 7353 | static void rtl8723au_report_connect(struct rtl8xxxu_priv *priv, |
| 7354 | u8 macid, bool connect) |
| 7355 | { |
| 7356 | struct h2c_cmd h2c; |
| 7357 | |
| 7358 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 7359 | |
| 7360 | h2c.joinbss.cmd = H2C_JOIN_BSS_REPORT; |
| 7361 | |
| 7362 | if (connect) |
| 7363 | h2c.joinbss.data = H2C_JOIN_BSS_CONNECT; |
| 7364 | else |
| 7365 | h2c.joinbss.data = H2C_JOIN_BSS_DISCONNECT; |
| 7366 | |
| 7367 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.joinbss)); |
| 7368 | } |
| 7369 | |
| 7370 | static void rtl8723bu_report_connect(struct rtl8xxxu_priv *priv, |
| 7371 | u8 macid, bool connect) |
| 7372 | { |
| 7373 | struct h2c_cmd h2c; |
| 7374 | |
| 7375 | memset(&h2c, 0, sizeof(struct h2c_cmd)); |
| 7376 | |
| 7377 | h2c.media_status_rpt.cmd = H2C_8723B_MEDIA_STATUS_RPT; |
| 7378 | if (connect) |
| 7379 | h2c.media_status_rpt.parm |= BIT(0); |
| 7380 | else |
| 7381 | h2c.media_status_rpt.parm &= ~BIT(0); |
| 7382 | |
| 7383 | rtl8723a_h2c_cmd(priv, &h2c, sizeof(h2c.media_status_rpt)); |
| 7384 | } |
| 7385 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7386 | static void rtl8xxxu_set_basic_rates(struct rtl8xxxu_priv *priv, u32 rate_cfg) |
| 7387 | { |
| 7388 | u32 val32; |
| 7389 | u8 rate_idx = 0; |
| 7390 | |
| 7391 | rate_cfg &= RESPONSE_RATE_BITMAP_ALL; |
| 7392 | |
| 7393 | val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET); |
| 7394 | val32 &= ~RESPONSE_RATE_BITMAP_ALL; |
| 7395 | val32 |= rate_cfg; |
| 7396 | rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32); |
| 7397 | |
| 7398 | dev_dbg(&priv->udev->dev, "%s: rates %08x\n", __func__, rate_cfg); |
| 7399 | |
| 7400 | while (rate_cfg) { |
| 7401 | rate_cfg = (rate_cfg >> 1); |
| 7402 | rate_idx++; |
| 7403 | } |
| 7404 | rtl8xxxu_write8(priv, REG_INIRTS_RATE_SEL, rate_idx); |
| 7405 | } |
| 7406 | |
| 7407 | static void |
| 7408 | rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 7409 | struct ieee80211_bss_conf *bss_conf, u32 changed) |
| 7410 | { |
| 7411 | struct rtl8xxxu_priv *priv = hw->priv; |
| 7412 | struct device *dev = &priv->udev->dev; |
| 7413 | struct ieee80211_sta *sta; |
| 7414 | u32 val32; |
| 7415 | u8 val8; |
| 7416 | |
| 7417 | if (changed & BSS_CHANGED_ASSOC) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7418 | dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc); |
| 7419 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7420 | rtl8xxxu_set_linktype(priv, vif->type); |
| 7421 | |
| 7422 | if (bss_conf->assoc) { |
| 7423 | u32 ramask; |
| 7424 | int sgi = 0; |
| 7425 | |
| 7426 | rcu_read_lock(); |
| 7427 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 7428 | if (!sta) { |
| 7429 | dev_info(dev, "%s: ASSOC no sta found\n", |
| 7430 | __func__); |
| 7431 | rcu_read_unlock(); |
| 7432 | goto error; |
| 7433 | } |
| 7434 | |
| 7435 | if (sta->ht_cap.ht_supported) |
| 7436 | dev_info(dev, "%s: HT supported\n", __func__); |
| 7437 | if (sta->vht_cap.vht_supported) |
| 7438 | dev_info(dev, "%s: VHT supported\n", __func__); |
| 7439 | |
| 7440 | /* TODO: Set bits 28-31 for rate adaptive id */ |
| 7441 | ramask = (sta->supp_rates[0] & 0xfff) | |
| 7442 | sta->ht_cap.mcs.rx_mask[0] << 12 | |
| 7443 | sta->ht_cap.mcs.rx_mask[1] << 20; |
| 7444 | if (sta->ht_cap.cap & |
| 7445 | (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20)) |
| 7446 | sgi = 1; |
| 7447 | rcu_read_unlock(); |
| 7448 | |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 7449 | priv->fops->update_rate_mask(priv, ramask, sgi); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7450 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7451 | rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff); |
| 7452 | |
| 7453 | rtl8723a_stop_tx_beacon(priv); |
| 7454 | |
| 7455 | /* joinbss sequence */ |
| 7456 | rtl8xxxu_write16(priv, REG_BCN_PSR_RPT, |
| 7457 | 0xc000 | bss_conf->aid); |
| 7458 | |
Jes Sorensen | 7d794ea | 2016-02-29 17:05:39 -0500 | [diff] [blame] | 7459 | priv->fops->report_connect(priv, 0, true); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7460 | } else { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7461 | val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL); |
| 7462 | val8 |= BEACON_DISABLE_TSF_UPDATE; |
| 7463 | rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8); |
| 7464 | |
Jes Sorensen | 7d794ea | 2016-02-29 17:05:39 -0500 | [diff] [blame] | 7465 | priv->fops->report_connect(priv, 0, false); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7466 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7467 | } |
| 7468 | |
| 7469 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 7470 | dev_dbg(dev, "Changed ERP_PREAMBLE: Use short preamble %i\n", |
| 7471 | bss_conf->use_short_preamble); |
| 7472 | val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET); |
| 7473 | if (bss_conf->use_short_preamble) |
| 7474 | val32 |= RSR_ACK_SHORT_PREAMBLE; |
| 7475 | else |
| 7476 | val32 &= ~RSR_ACK_SHORT_PREAMBLE; |
| 7477 | rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32); |
| 7478 | } |
| 7479 | |
| 7480 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 7481 | dev_dbg(dev, "Changed ERP_SLOT: short_slot_time %i\n", |
| 7482 | bss_conf->use_short_slot); |
| 7483 | |
| 7484 | if (bss_conf->use_short_slot) |
| 7485 | val8 = 9; |
| 7486 | else |
| 7487 | val8 = 20; |
| 7488 | rtl8xxxu_write8(priv, REG_SLOT, val8); |
| 7489 | } |
| 7490 | |
| 7491 | if (changed & BSS_CHANGED_BSSID) { |
| 7492 | dev_dbg(dev, "Changed BSSID!\n"); |
| 7493 | rtl8xxxu_set_bssid(priv, bss_conf->bssid); |
| 7494 | } |
| 7495 | |
| 7496 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 7497 | dev_dbg(dev, "Changed BASIC_RATES!\n"); |
| 7498 | rtl8xxxu_set_basic_rates(priv, bss_conf->basic_rates); |
| 7499 | } |
| 7500 | error: |
| 7501 | return; |
| 7502 | } |
| 7503 | |
| 7504 | static u32 rtl8xxxu_80211_to_rtl_queue(u32 queue) |
| 7505 | { |
| 7506 | u32 rtlqueue; |
| 7507 | |
| 7508 | switch (queue) { |
| 7509 | case IEEE80211_AC_VO: |
| 7510 | rtlqueue = TXDESC_QUEUE_VO; |
| 7511 | break; |
| 7512 | case IEEE80211_AC_VI: |
| 7513 | rtlqueue = TXDESC_QUEUE_VI; |
| 7514 | break; |
| 7515 | case IEEE80211_AC_BE: |
| 7516 | rtlqueue = TXDESC_QUEUE_BE; |
| 7517 | break; |
| 7518 | case IEEE80211_AC_BK: |
| 7519 | rtlqueue = TXDESC_QUEUE_BK; |
| 7520 | break; |
| 7521 | default: |
| 7522 | rtlqueue = TXDESC_QUEUE_BE; |
| 7523 | } |
| 7524 | |
| 7525 | return rtlqueue; |
| 7526 | } |
| 7527 | |
| 7528 | static u32 rtl8xxxu_queue_select(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 7529 | { |
| 7530 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 7531 | u32 queue; |
| 7532 | |
| 7533 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 7534 | queue = TXDESC_QUEUE_MGNT; |
| 7535 | else |
| 7536 | queue = rtl8xxxu_80211_to_rtl_queue(skb_get_queue_mapping(skb)); |
| 7537 | |
| 7538 | return queue; |
| 7539 | } |
| 7540 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7541 | /* |
| 7542 | * Despite newer chips 8723b/8812/8821 having a larger TX descriptor |
| 7543 | * format. The descriptor checksum is still only calculated over the |
| 7544 | * initial 32 bytes of the descriptor! |
| 7545 | */ |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 7546 | static void rtl8xxxu_calc_tx_desc_csum(struct rtl8xxxu_txdesc32 *tx_desc) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7547 | { |
| 7548 | __le16 *ptr = (__le16 *)tx_desc; |
| 7549 | u16 csum = 0; |
| 7550 | int i; |
| 7551 | |
| 7552 | /* |
| 7553 | * Clear csum field before calculation, as the csum field is |
| 7554 | * in the middle of the struct. |
| 7555 | */ |
| 7556 | tx_desc->csum = cpu_to_le16(0); |
| 7557 | |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 7558 | for (i = 0; i < (sizeof(struct rtl8xxxu_txdesc32) / sizeof(u16)); i++) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7559 | csum = csum ^ le16_to_cpu(ptr[i]); |
| 7560 | |
| 7561 | tx_desc->csum |= cpu_to_le16(csum); |
| 7562 | } |
| 7563 | |
| 7564 | static void rtl8xxxu_free_tx_resources(struct rtl8xxxu_priv *priv) |
| 7565 | { |
| 7566 | struct rtl8xxxu_tx_urb *tx_urb, *tmp; |
| 7567 | unsigned long flags; |
| 7568 | |
| 7569 | spin_lock_irqsave(&priv->tx_urb_lock, flags); |
| 7570 | list_for_each_entry_safe(tx_urb, tmp, &priv->tx_urb_free_list, list) { |
| 7571 | list_del(&tx_urb->list); |
| 7572 | priv->tx_urb_free_count--; |
| 7573 | usb_free_urb(&tx_urb->urb); |
| 7574 | } |
| 7575 | spin_unlock_irqrestore(&priv->tx_urb_lock, flags); |
| 7576 | } |
| 7577 | |
| 7578 | static struct rtl8xxxu_tx_urb * |
| 7579 | rtl8xxxu_alloc_tx_urb(struct rtl8xxxu_priv *priv) |
| 7580 | { |
| 7581 | struct rtl8xxxu_tx_urb *tx_urb; |
| 7582 | unsigned long flags; |
| 7583 | |
| 7584 | spin_lock_irqsave(&priv->tx_urb_lock, flags); |
| 7585 | tx_urb = list_first_entry_or_null(&priv->tx_urb_free_list, |
| 7586 | struct rtl8xxxu_tx_urb, list); |
| 7587 | if (tx_urb) { |
| 7588 | list_del(&tx_urb->list); |
| 7589 | priv->tx_urb_free_count--; |
| 7590 | if (priv->tx_urb_free_count < RTL8XXXU_TX_URB_LOW_WATER && |
| 7591 | !priv->tx_stopped) { |
| 7592 | priv->tx_stopped = true; |
| 7593 | ieee80211_stop_queues(priv->hw); |
| 7594 | } |
| 7595 | } |
| 7596 | |
| 7597 | spin_unlock_irqrestore(&priv->tx_urb_lock, flags); |
| 7598 | |
| 7599 | return tx_urb; |
| 7600 | } |
| 7601 | |
| 7602 | static void rtl8xxxu_free_tx_urb(struct rtl8xxxu_priv *priv, |
| 7603 | struct rtl8xxxu_tx_urb *tx_urb) |
| 7604 | { |
| 7605 | unsigned long flags; |
| 7606 | |
| 7607 | INIT_LIST_HEAD(&tx_urb->list); |
| 7608 | |
| 7609 | spin_lock_irqsave(&priv->tx_urb_lock, flags); |
| 7610 | |
| 7611 | list_add(&tx_urb->list, &priv->tx_urb_free_list); |
| 7612 | priv->tx_urb_free_count++; |
| 7613 | if (priv->tx_urb_free_count > RTL8XXXU_TX_URB_HIGH_WATER && |
| 7614 | priv->tx_stopped) { |
| 7615 | priv->tx_stopped = false; |
| 7616 | ieee80211_wake_queues(priv->hw); |
| 7617 | } |
| 7618 | |
| 7619 | spin_unlock_irqrestore(&priv->tx_urb_lock, flags); |
| 7620 | } |
| 7621 | |
| 7622 | static void rtl8xxxu_tx_complete(struct urb *urb) |
| 7623 | { |
| 7624 | struct sk_buff *skb = (struct sk_buff *)urb->context; |
| 7625 | struct ieee80211_tx_info *tx_info; |
| 7626 | struct ieee80211_hw *hw; |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7627 | struct rtl8xxxu_priv *priv; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7628 | struct rtl8xxxu_tx_urb *tx_urb = |
| 7629 | container_of(urb, struct rtl8xxxu_tx_urb, urb); |
| 7630 | |
| 7631 | tx_info = IEEE80211_SKB_CB(skb); |
| 7632 | hw = tx_info->rate_driver_data[0]; |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7633 | priv = hw->priv; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7634 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7635 | skb_pull(skb, priv->fops->tx_desc_size); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7636 | |
| 7637 | ieee80211_tx_info_clear_status(tx_info); |
| 7638 | tx_info->status.rates[0].idx = -1; |
| 7639 | tx_info->status.rates[0].count = 0; |
| 7640 | |
| 7641 | if (!urb->status) |
| 7642 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
| 7643 | |
| 7644 | ieee80211_tx_status_irqsafe(hw, skb); |
| 7645 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7646 | rtl8xxxu_free_tx_urb(priv, tx_urb); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7647 | } |
| 7648 | |
| 7649 | static void rtl8xxxu_dump_action(struct device *dev, |
| 7650 | struct ieee80211_hdr *hdr) |
| 7651 | { |
| 7652 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr; |
| 7653 | u16 cap, timeout; |
| 7654 | |
| 7655 | if (!(rtl8xxxu_debug & RTL8XXXU_DEBUG_ACTION)) |
| 7656 | return; |
| 7657 | |
| 7658 | switch (mgmt->u.action.u.addba_resp.action_code) { |
| 7659 | case WLAN_ACTION_ADDBA_RESP: |
| 7660 | cap = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); |
| 7661 | timeout = le16_to_cpu(mgmt->u.action.u.addba_resp.timeout); |
| 7662 | dev_info(dev, "WLAN_ACTION_ADDBA_RESP: " |
| 7663 | "timeout %i, tid %02x, buf_size %02x, policy %02x, " |
| 7664 | "status %02x\n", |
| 7665 | timeout, |
| 7666 | (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2, |
| 7667 | (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6, |
| 7668 | (cap >> 1) & 0x1, |
| 7669 | le16_to_cpu(mgmt->u.action.u.addba_resp.status)); |
| 7670 | break; |
| 7671 | case WLAN_ACTION_ADDBA_REQ: |
| 7672 | cap = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 7673 | timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout); |
| 7674 | dev_info(dev, "WLAN_ACTION_ADDBA_REQ: " |
| 7675 | "timeout %i, tid %02x, buf_size %02x, policy %02x\n", |
| 7676 | timeout, |
| 7677 | (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2, |
| 7678 | (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6, |
| 7679 | (cap >> 1) & 0x1); |
| 7680 | break; |
| 7681 | default: |
| 7682 | dev_info(dev, "action frame %02x\n", |
| 7683 | mgmt->u.action.u.addba_resp.action_code); |
| 7684 | break; |
| 7685 | } |
| 7686 | } |
| 7687 | |
| 7688 | static void rtl8xxxu_tx(struct ieee80211_hw *hw, |
| 7689 | struct ieee80211_tx_control *control, |
| 7690 | struct sk_buff *skb) |
| 7691 | { |
| 7692 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 7693 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 7694 | struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info); |
| 7695 | struct rtl8xxxu_priv *priv = hw->priv; |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 7696 | struct rtl8xxxu_txdesc32 *tx_desc; |
| 7697 | struct rtl8xxxu_txdesc40 *tx_desc40; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7698 | struct rtl8xxxu_tx_urb *tx_urb; |
| 7699 | struct ieee80211_sta *sta = NULL; |
| 7700 | struct ieee80211_vif *vif = tx_info->control.vif; |
| 7701 | struct device *dev = &priv->udev->dev; |
| 7702 | u32 queue, rate; |
| 7703 | u16 pktlen = skb->len; |
| 7704 | u16 seq_number; |
| 7705 | u16 rate_flag = tx_info->control.rates[0].flags; |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7706 | int tx_desc_size = priv->fops->tx_desc_size; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7707 | int ret; |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7708 | bool usedesc40, ampdu_enable; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7709 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7710 | if (skb_headroom(skb) < tx_desc_size) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7711 | dev_warn(dev, |
| 7712 | "%s: Not enough headroom (%i) for tx descriptor\n", |
| 7713 | __func__, skb_headroom(skb)); |
| 7714 | goto error; |
| 7715 | } |
| 7716 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7717 | if (unlikely(skb->len > (65535 - tx_desc_size))) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7718 | dev_warn(dev, "%s: Trying to send over-sized skb (%i)\n", |
| 7719 | __func__, skb->len); |
| 7720 | goto error; |
| 7721 | } |
| 7722 | |
| 7723 | tx_urb = rtl8xxxu_alloc_tx_urb(priv); |
| 7724 | if (!tx_urb) { |
| 7725 | dev_warn(dev, "%s: Unable to allocate tx urb\n", __func__); |
| 7726 | goto error; |
| 7727 | } |
| 7728 | |
| 7729 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX) |
| 7730 | dev_info(dev, "%s: TX rate: %d (%d), pkt size %d\n", |
| 7731 | __func__, tx_rate->bitrate, tx_rate->hw_value, pktlen); |
| 7732 | |
| 7733 | if (ieee80211_is_action(hdr->frame_control)) |
| 7734 | rtl8xxxu_dump_action(dev, hdr); |
| 7735 | |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7736 | usedesc40 = (tx_desc_size == 40); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7737 | tx_info->rate_driver_data[0] = hw; |
| 7738 | |
| 7739 | if (control && control->sta) |
| 7740 | sta = control->sta; |
| 7741 | |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 7742 | tx_desc = (struct rtl8xxxu_txdesc32 *)skb_push(skb, tx_desc_size); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7743 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7744 | memset(tx_desc, 0, tx_desc_size); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7745 | tx_desc->pkt_size = cpu_to_le16(pktlen); |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 7746 | tx_desc->pkt_offset = tx_desc_size; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7747 | |
| 7748 | tx_desc->txdw0 = |
| 7749 | TXDESC_OWN | TXDESC_FIRST_SEGMENT | TXDESC_LAST_SEGMENT; |
| 7750 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) || |
| 7751 | is_broadcast_ether_addr(ieee80211_get_DA(hdr))) |
| 7752 | tx_desc->txdw0 |= TXDESC_BROADMULTICAST; |
| 7753 | |
| 7754 | queue = rtl8xxxu_queue_select(hw, skb); |
| 7755 | tx_desc->txdw1 = cpu_to_le32(queue << TXDESC_QUEUE_SHIFT); |
| 7756 | |
| 7757 | if (tx_info->control.hw_key) { |
| 7758 | switch (tx_info->control.hw_key->cipher) { |
| 7759 | case WLAN_CIPHER_SUITE_WEP40: |
| 7760 | case WLAN_CIPHER_SUITE_WEP104: |
| 7761 | case WLAN_CIPHER_SUITE_TKIP: |
| 7762 | tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_RC4); |
| 7763 | break; |
| 7764 | case WLAN_CIPHER_SUITE_CCMP: |
| 7765 | tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_AES); |
| 7766 | break; |
| 7767 | default: |
| 7768 | break; |
| 7769 | } |
| 7770 | } |
| 7771 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7772 | /* (tx_info->flags & IEEE80211_TX_CTL_AMPDU) && */ |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7773 | ampdu_enable = false; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7774 | if (ieee80211_is_data_qos(hdr->frame_control) && sta) { |
| 7775 | if (sta->ht_cap.ht_supported) { |
| 7776 | u32 ampdu, val32; |
| 7777 | |
| 7778 | ampdu = (u32)sta->ht_cap.ampdu_density; |
| 7779 | val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT; |
| 7780 | tx_desc->txdw2 |= cpu_to_le32(val32); |
Jes Sorensen | ce2d1db | 2016-02-29 17:05:30 -0500 | [diff] [blame] | 7781 | |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7782 | ampdu_enable = true; |
| 7783 | } |
| 7784 | } |
| 7785 | |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7786 | if (rate_flag & IEEE80211_TX_RC_MCS) |
| 7787 | rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0; |
| 7788 | else |
| 7789 | rate = tx_rate->hw_value; |
| 7790 | |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7791 | seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)); |
| 7792 | if (!usedesc40) { |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7793 | tx_desc->txdw5 = cpu_to_le32(rate); |
| 7794 | |
| 7795 | if (ieee80211_is_data(hdr->frame_control)) |
| 7796 | tx_desc->txdw5 |= cpu_to_le32(0x0001ff00); |
| 7797 | |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7798 | tx_desc->txdw3 = |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7799 | cpu_to_le32((u32)seq_number << TXDESC32_SEQ_SHIFT); |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7800 | |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7801 | if (ampdu_enable) |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7802 | tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_ENABLE); |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7803 | else |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7804 | tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_BREAK); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7805 | |
| 7806 | if (ieee80211_is_mgmt(hdr->frame_control)) { |
| 7807 | tx_desc->txdw5 = cpu_to_le32(tx_rate->hw_value); |
| 7808 | tx_desc->txdw4 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7809 | cpu_to_le32(TXDESC32_USE_DRIVER_RATE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7810 | tx_desc->txdw5 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7811 | cpu_to_le32(6 << TXDESC32_RETRY_LIMIT_SHIFT); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7812 | tx_desc->txdw5 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7813 | cpu_to_le32(TXDESC32_RETRY_LIMIT_ENABLE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7814 | } |
| 7815 | |
| 7816 | if (ieee80211_is_data_qos(hdr->frame_control)) |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7817 | tx_desc->txdw4 |= cpu_to_le32(TXDESC32_QOS); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7818 | |
| 7819 | if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE || |
| 7820 | (sta && vif && vif->bss_conf.use_short_preamble)) |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7821 | tx_desc->txdw4 |= cpu_to_le32(TXDESC32_SHORT_PREAMBLE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7822 | |
| 7823 | if (rate_flag & IEEE80211_TX_RC_SHORT_GI || |
| 7824 | (ieee80211_is_data_qos(hdr->frame_control) && |
| 7825 | sta && sta->ht_cap.cap & |
| 7826 | (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))) { |
Jes Sorensen | 1df1de3 | 2016-03-31 17:08:36 -0400 | [diff] [blame] | 7827 | tx_desc->txdw5 |= cpu_to_le32(TXDESC32_SHORT_GI); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7828 | } |
| 7829 | |
| 7830 | if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 7831 | /* |
| 7832 | * Use RTS rate 24M - does the mac80211 tell |
| 7833 | * us which to use? |
| 7834 | */ |
| 7835 | tx_desc->txdw4 |= |
| 7836 | cpu_to_le32(DESC_RATE_24M << |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7837 | TXDESC32_RTS_RATE_SHIFT); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7838 | tx_desc->txdw4 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7839 | cpu_to_le32(TXDESC32_RTS_CTS_ENABLE); |
| 7840 | tx_desc->txdw4 |= cpu_to_le32(TXDESC32_HW_RTS_ENABLE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7841 | } |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7842 | } else { |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 7843 | tx_desc40 = (struct rtl8xxxu_txdesc40 *)tx_desc; |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7844 | |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7845 | tx_desc40->txdw4 = cpu_to_le32(rate); |
| 7846 | if (ieee80211_is_data(hdr->frame_control)) { |
| 7847 | tx_desc->txdw4 |= |
| 7848 | cpu_to_le32(0x1f << |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7849 | TXDESC40_DATA_RATE_FB_SHIFT); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7850 | } |
| 7851 | |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7852 | tx_desc40->txdw9 = |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7853 | cpu_to_le32((u32)seq_number << TXDESC40_SEQ_SHIFT); |
Jes Sorensen | cc2646d | 2016-02-29 17:05:32 -0500 | [diff] [blame] | 7854 | |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7855 | if (ampdu_enable) |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7856 | tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_ENABLE); |
Jes Sorensen | a40ace4 | 2016-02-29 17:05:31 -0500 | [diff] [blame] | 7857 | else |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7858 | tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_BREAK); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7859 | |
| 7860 | if (ieee80211_is_mgmt(hdr->frame_control)) { |
| 7861 | tx_desc40->txdw4 = cpu_to_le32(tx_rate->hw_value); |
| 7862 | tx_desc40->txdw3 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7863 | cpu_to_le32(TXDESC40_USE_DRIVER_RATE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7864 | tx_desc40->txdw4 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7865 | cpu_to_le32(6 << TXDESC40_RETRY_LIMIT_SHIFT); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7866 | tx_desc40->txdw4 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7867 | cpu_to_le32(TXDESC40_RETRY_LIMIT_ENABLE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7868 | } |
| 7869 | |
| 7870 | if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE || |
| 7871 | (sta && vif && vif->bss_conf.use_short_preamble)) |
| 7872 | tx_desc40->txdw5 |= |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7873 | cpu_to_le32(TXDESC40_SHORT_PREAMBLE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7874 | |
| 7875 | if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 7876 | /* |
| 7877 | * Use RTS rate 24M - does the mac80211 tell |
| 7878 | * us which to use? |
| 7879 | */ |
| 7880 | tx_desc->txdw4 |= |
| 7881 | cpu_to_le32(DESC_RATE_24M << |
Jes Sorensen | 33f3724 | 2016-03-31 17:08:34 -0400 | [diff] [blame] | 7882 | TXDESC40_RTS_RATE_SHIFT); |
| 7883 | tx_desc->txdw3 |= cpu_to_le32(TXDESC40_RTS_CTS_ENABLE); |
| 7884 | tx_desc->txdw3 |= cpu_to_le32(TXDESC40_HW_RTS_ENABLE); |
Jes Sorensen | 4c68360 | 2016-02-29 17:05:35 -0500 | [diff] [blame] | 7885 | } |
Jes Sorensen | 6979494 | 2016-02-29 17:05:43 -0500 | [diff] [blame] | 7886 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7887 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7888 | rtl8xxxu_calc_tx_desc_csum(tx_desc); |
| 7889 | |
| 7890 | usb_fill_bulk_urb(&tx_urb->urb, priv->udev, priv->pipe_out[queue], |
| 7891 | skb->data, skb->len, rtl8xxxu_tx_complete, skb); |
| 7892 | |
| 7893 | usb_anchor_urb(&tx_urb->urb, &priv->tx_anchor); |
| 7894 | ret = usb_submit_urb(&tx_urb->urb, GFP_ATOMIC); |
| 7895 | if (ret) { |
| 7896 | usb_unanchor_urb(&tx_urb->urb); |
| 7897 | rtl8xxxu_free_tx_urb(priv, tx_urb); |
| 7898 | goto error; |
| 7899 | } |
| 7900 | return; |
| 7901 | error: |
| 7902 | dev_kfree_skb(skb); |
| 7903 | } |
| 7904 | |
| 7905 | static void rtl8xxxu_rx_parse_phystats(struct rtl8xxxu_priv *priv, |
| 7906 | struct ieee80211_rx_status *rx_status, |
Jes Sorensen | 8795708 | 2016-02-29 17:05:42 -0500 | [diff] [blame] | 7907 | struct rtl8723au_phy_stats *phy_stats, |
| 7908 | u32 rxmcs) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7909 | { |
| 7910 | if (phy_stats->sgi_en) |
| 7911 | rx_status->flag |= RX_FLAG_SHORT_GI; |
| 7912 | |
Jes Sorensen | 8795708 | 2016-02-29 17:05:42 -0500 | [diff] [blame] | 7913 | if (rxmcs < DESC_RATE_6M) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 7914 | /* |
| 7915 | * Handle PHY stats for CCK rates |
| 7916 | */ |
| 7917 | u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a; |
| 7918 | |
| 7919 | switch (cck_agc_rpt & 0xc0) { |
| 7920 | case 0xc0: |
| 7921 | rx_status->signal = -46 - (cck_agc_rpt & 0x3e); |
| 7922 | break; |
| 7923 | case 0x80: |
| 7924 | rx_status->signal = -26 - (cck_agc_rpt & 0x3e); |
| 7925 | break; |
| 7926 | case 0x40: |
| 7927 | rx_status->signal = -12 - (cck_agc_rpt & 0x3e); |
| 7928 | break; |
| 7929 | case 0x00: |
| 7930 | rx_status->signal = 16 - (cck_agc_rpt & 0x3e); |
| 7931 | break; |
| 7932 | } |
| 7933 | } else { |
| 7934 | rx_status->signal = |
| 7935 | (phy_stats->cck_sig_qual_ofdm_pwdb_all >> 1) - 110; |
| 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv) |
| 7940 | { |
| 7941 | struct rtl8xxxu_rx_urb *rx_urb, *tmp; |
| 7942 | unsigned long flags; |
| 7943 | |
| 7944 | spin_lock_irqsave(&priv->rx_urb_lock, flags); |
| 7945 | |
| 7946 | list_for_each_entry_safe(rx_urb, tmp, |
| 7947 | &priv->rx_urb_pending_list, list) { |
| 7948 | list_del(&rx_urb->list); |
| 7949 | priv->rx_urb_pending_count--; |
| 7950 | usb_free_urb(&rx_urb->urb); |
| 7951 | } |
| 7952 | |
| 7953 | spin_unlock_irqrestore(&priv->rx_urb_lock, flags); |
| 7954 | } |
| 7955 | |
| 7956 | static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, |
| 7957 | struct rtl8xxxu_rx_urb *rx_urb) |
| 7958 | { |
| 7959 | struct sk_buff *skb; |
| 7960 | unsigned long flags; |
| 7961 | int pending = 0; |
| 7962 | |
| 7963 | spin_lock_irqsave(&priv->rx_urb_lock, flags); |
| 7964 | |
| 7965 | if (!priv->shutdown) { |
| 7966 | list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list); |
| 7967 | priv->rx_urb_pending_count++; |
| 7968 | pending = priv->rx_urb_pending_count; |
| 7969 | } else { |
| 7970 | skb = (struct sk_buff *)rx_urb->urb.context; |
| 7971 | dev_kfree_skb(skb); |
| 7972 | usb_free_urb(&rx_urb->urb); |
| 7973 | } |
| 7974 | |
| 7975 | spin_unlock_irqrestore(&priv->rx_urb_lock, flags); |
| 7976 | |
| 7977 | if (pending > RTL8XXXU_RX_URB_PENDING_WATER) |
| 7978 | schedule_work(&priv->rx_urb_wq); |
| 7979 | } |
| 7980 | |
| 7981 | static void rtl8xxxu_rx_urb_work(struct work_struct *work) |
| 7982 | { |
| 7983 | struct rtl8xxxu_priv *priv; |
| 7984 | struct rtl8xxxu_rx_urb *rx_urb, *tmp; |
| 7985 | struct list_head local; |
| 7986 | struct sk_buff *skb; |
| 7987 | unsigned long flags; |
| 7988 | int ret; |
| 7989 | |
| 7990 | priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); |
| 7991 | INIT_LIST_HEAD(&local); |
| 7992 | |
| 7993 | spin_lock_irqsave(&priv->rx_urb_lock, flags); |
| 7994 | |
| 7995 | list_splice_init(&priv->rx_urb_pending_list, &local); |
| 7996 | priv->rx_urb_pending_count = 0; |
| 7997 | |
| 7998 | spin_unlock_irqrestore(&priv->rx_urb_lock, flags); |
| 7999 | |
| 8000 | list_for_each_entry_safe(rx_urb, tmp, &local, list) { |
| 8001 | list_del_init(&rx_urb->list); |
| 8002 | ret = rtl8xxxu_submit_rx_urb(priv, rx_urb); |
| 8003 | /* |
| 8004 | * If out of memory or temporary error, put it back on the |
| 8005 | * queue and try again. Otherwise the device is dead/gone |
| 8006 | * and we should drop it. |
| 8007 | */ |
| 8008 | switch (ret) { |
| 8009 | case 0: |
| 8010 | break; |
| 8011 | case -ENOMEM: |
| 8012 | case -EAGAIN: |
| 8013 | rtl8xxxu_queue_rx_urb(priv, rx_urb); |
| 8014 | break; |
| 8015 | default: |
| 8016 | pr_info("failed to requeue urb %i\n", ret); |
| 8017 | skb = (struct sk_buff *)rx_urb->urb.context; |
| 8018 | dev_kfree_skb(skb); |
| 8019 | usb_free_urb(&rx_urb->urb); |
| 8020 | } |
| 8021 | } |
| 8022 | } |
| 8023 | |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8024 | static int rtl8723au_parse_rx_desc(struct rtl8xxxu_priv *priv, |
| 8025 | struct sk_buff *skb, |
| 8026 | struct ieee80211_rx_status *rx_status) |
| 8027 | { |
| 8028 | struct rtl8xxxu_rx_desc *rx_desc = (struct rtl8xxxu_rx_desc *)skb->data; |
| 8029 | struct rtl8723au_phy_stats *phy_stats; |
| 8030 | int drvinfo_sz, desc_shift; |
| 8031 | |
| 8032 | skb_pull(skb, sizeof(struct rtl8xxxu_rx_desc)); |
| 8033 | |
| 8034 | phy_stats = (struct rtl8723au_phy_stats *)skb->data; |
| 8035 | |
| 8036 | drvinfo_sz = rx_desc->drvinfo_sz * 8; |
| 8037 | desc_shift = rx_desc->shift; |
| 8038 | skb_pull(skb, drvinfo_sz + desc_shift); |
| 8039 | |
| 8040 | if (rx_desc->phy_stats) |
Jes Sorensen | 8795708 | 2016-02-29 17:05:42 -0500 | [diff] [blame] | 8041 | rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats, |
| 8042 | rx_desc->rxmcs); |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8043 | |
| 8044 | rx_status->mactime = le32_to_cpu(rx_desc->tsfl); |
| 8045 | rx_status->flag |= RX_FLAG_MACTIME_START; |
| 8046 | |
| 8047 | if (!rx_desc->swdec) |
| 8048 | rx_status->flag |= RX_FLAG_DECRYPTED; |
| 8049 | if (rx_desc->crc32) |
| 8050 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 8051 | if (rx_desc->bw) |
| 8052 | rx_status->flag |= RX_FLAG_40MHZ; |
| 8053 | |
| 8054 | if (rx_desc->rxht) { |
| 8055 | rx_status->flag |= RX_FLAG_HT; |
| 8056 | rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0; |
| 8057 | } else { |
| 8058 | rx_status->rate_idx = rx_desc->rxmcs; |
| 8059 | } |
| 8060 | |
| 8061 | return RX_TYPE_DATA_PKT; |
| 8062 | } |
| 8063 | |
| 8064 | static int rtl8723bu_parse_rx_desc(struct rtl8xxxu_priv *priv, |
| 8065 | struct sk_buff *skb, |
| 8066 | struct ieee80211_rx_status *rx_status) |
| 8067 | { |
| 8068 | struct rtl8723bu_rx_desc *rx_desc = |
| 8069 | (struct rtl8723bu_rx_desc *)skb->data; |
| 8070 | struct rtl8723au_phy_stats *phy_stats; |
| 8071 | int drvinfo_sz, desc_shift; |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8072 | |
| 8073 | skb_pull(skb, sizeof(struct rtl8723bu_rx_desc)); |
| 8074 | |
| 8075 | phy_stats = (struct rtl8723au_phy_stats *)skb->data; |
| 8076 | |
| 8077 | drvinfo_sz = rx_desc->drvinfo_sz * 8; |
| 8078 | desc_shift = rx_desc->shift; |
| 8079 | skb_pull(skb, drvinfo_sz + desc_shift); |
| 8080 | |
Jes Sorensen | e975b87 | 2016-02-29 17:05:36 -0500 | [diff] [blame] | 8081 | if (rx_desc->rpt_sel) { |
| 8082 | struct device *dev = &priv->udev->dev; |
| 8083 | dev_dbg(dev, "%s: C2H packet\n", __func__); |
| 8084 | return RX_TYPE_C2H; |
| 8085 | } |
| 8086 | |
Jes Sorensen | 8795708 | 2016-02-29 17:05:42 -0500 | [diff] [blame] | 8087 | if (rx_desc->phy_stats) |
| 8088 | rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats, |
| 8089 | rx_desc->rxmcs); |
| 8090 | |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8091 | rx_status->mactime = le32_to_cpu(rx_desc->tsfl); |
| 8092 | rx_status->flag |= RX_FLAG_MACTIME_START; |
| 8093 | |
| 8094 | if (!rx_desc->swdec) |
| 8095 | rx_status->flag |= RX_FLAG_DECRYPTED; |
| 8096 | if (rx_desc->crc32) |
| 8097 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 8098 | if (rx_desc->bw) |
| 8099 | rx_status->flag |= RX_FLAG_40MHZ; |
| 8100 | |
| 8101 | if (rx_desc->rxmcs >= DESC_RATE_MCS0) { |
| 8102 | rx_status->flag |= RX_FLAG_HT; |
| 8103 | rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0; |
| 8104 | } else { |
| 8105 | rx_status->rate_idx = rx_desc->rxmcs; |
| 8106 | } |
| 8107 | |
Jes Sorensen | e975b87 | 2016-02-29 17:05:36 -0500 | [diff] [blame] | 8108 | return RX_TYPE_DATA_PKT; |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8109 | } |
| 8110 | |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8111 | static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv *priv, |
| 8112 | struct sk_buff *skb) |
| 8113 | { |
| 8114 | struct rtl8723bu_c2h *c2h = (struct rtl8723bu_c2h *)skb->data; |
| 8115 | struct device *dev = &priv->udev->dev; |
| 8116 | int len; |
| 8117 | |
| 8118 | len = skb->len - 2; |
| 8119 | |
Jes Sorensen | 5e00d50 | 2016-02-29 17:05:28 -0500 | [diff] [blame] | 8120 | dev_dbg(dev, "C2H ID %02x seq %02x, len %02x source %02x\n", |
| 8121 | c2h->id, c2h->seq, len, c2h->bt_info.response_source); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8122 | |
| 8123 | switch(c2h->id) { |
| 8124 | case C2H_8723B_BT_INFO: |
| 8125 | if (c2h->bt_info.response_source > |
| 8126 | BT_INFO_SRC_8723B_BT_ACTIVE_SEND) |
Jes Sorensen | 5e00d50 | 2016-02-29 17:05:28 -0500 | [diff] [blame] | 8127 | dev_dbg(dev, "C2H_BT_INFO WiFi only firmware\n"); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8128 | else |
Jes Sorensen | 5e00d50 | 2016-02-29 17:05:28 -0500 | [diff] [blame] | 8129 | dev_dbg(dev, "C2H_BT_INFO BT/WiFi coexist firmware\n"); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8130 | |
| 8131 | if (c2h->bt_info.bt_has_reset) |
Jes Sorensen | 5e00d50 | 2016-02-29 17:05:28 -0500 | [diff] [blame] | 8132 | dev_dbg(dev, "BT has been reset\n"); |
Jes Sorensen | 394f1bd | 2016-02-29 17:04:49 -0500 | [diff] [blame] | 8133 | if (c2h->bt_info.tx_rx_mask) |
Jes Sorensen | 5e00d50 | 2016-02-29 17:05:28 -0500 | [diff] [blame] | 8134 | dev_dbg(dev, "BT TRx mask\n"); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8135 | |
| 8136 | break; |
Jes Sorensen | 394f1bd | 2016-02-29 17:04:49 -0500 | [diff] [blame] | 8137 | case C2H_8723B_BT_MP_INFO: |
Jes Sorensen | 5e00d50 | 2016-02-29 17:05:28 -0500 | [diff] [blame] | 8138 | dev_dbg(dev, "C2H_MP_INFO ext ID %02x, status %02x\n", |
| 8139 | c2h->bt_mp_info.ext_id, c2h->bt_mp_info.status); |
Jes Sorensen | 394f1bd | 2016-02-29 17:04:49 -0500 | [diff] [blame] | 8140 | break; |
Jes Sorensen | 55a18dd | 2016-02-29 17:05:41 -0500 | [diff] [blame] | 8141 | case C2H_8723B_RA_REPORT: |
| 8142 | dev_dbg(dev, |
| 8143 | "C2H RA RPT: rate %02x, unk %i, macid %02x, noise %i\n", |
| 8144 | c2h->ra_report.rate, c2h->ra_report.dummy0_0, |
| 8145 | c2h->ra_report.macid, c2h->ra_report.noisy_state); |
| 8146 | break; |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8147 | default: |
Jes Sorensen | 739dc9f | 2016-02-29 17:05:40 -0500 | [diff] [blame] | 8148 | dev_info(dev, "Unhandled C2H event %02x seq %02x\n", |
| 8149 | c2h->id, c2h->seq); |
| 8150 | print_hex_dump(KERN_INFO, "C2H content: ", DUMP_PREFIX_NONE, |
| 8151 | 16, 1, c2h->raw.payload, len, false); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8152 | break; |
| 8153 | } |
| 8154 | } |
| 8155 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8156 | static void rtl8xxxu_rx_complete(struct urb *urb) |
| 8157 | { |
| 8158 | struct rtl8xxxu_rx_urb *rx_urb = |
| 8159 | container_of(urb, struct rtl8xxxu_rx_urb, urb); |
| 8160 | struct ieee80211_hw *hw = rx_urb->hw; |
| 8161 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8162 | struct sk_buff *skb = (struct sk_buff *)urb->context; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8163 | struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8164 | struct device *dev = &priv->udev->dev; |
| 8165 | __le32 *_rx_desc_le = (__le32 *)skb->data; |
| 8166 | u32 *_rx_desc = (u32 *)skb->data; |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8167 | int rx_type, i; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8168 | |
| 8169 | for (i = 0; i < (sizeof(struct rtl8xxxu_rx_desc) / sizeof(u32)); i++) |
| 8170 | _rx_desc[i] = le32_to_cpu(_rx_desc_le[i]); |
| 8171 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8172 | skb_put(skb, urb->actual_length); |
| 8173 | |
| 8174 | if (urb->status == 0) { |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8175 | memset(rx_status, 0, sizeof(struct ieee80211_rx_status)); |
| 8176 | |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8177 | rx_type = priv->fops->parse_rx_desc(priv, skb, rx_status); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8178 | |
| 8179 | rx_status->freq = hw->conf.chandef.chan->center_freq; |
| 8180 | rx_status->band = hw->conf.chandef.chan->band; |
| 8181 | |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8182 | if (rx_type == RX_TYPE_DATA_PKT) |
| 8183 | ieee80211_rx_irqsafe(hw, skb); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8184 | else { |
| 8185 | rtl8723bu_handle_c2h(priv, skb); |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8186 | dev_kfree_skb(skb); |
Jes Sorensen | b2b43b7 | 2016-02-29 17:04:48 -0500 | [diff] [blame] | 8187 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8188 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8189 | skb = NULL; |
| 8190 | rx_urb->urb.context = NULL; |
| 8191 | rtl8xxxu_queue_rx_urb(priv, rx_urb); |
| 8192 | } else { |
| 8193 | dev_dbg(dev, "%s: status %i\n", __func__, urb->status); |
| 8194 | goto cleanup; |
| 8195 | } |
| 8196 | return; |
| 8197 | |
| 8198 | cleanup: |
| 8199 | usb_free_urb(urb); |
| 8200 | dev_kfree_skb(skb); |
| 8201 | return; |
| 8202 | } |
| 8203 | |
| 8204 | static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv, |
| 8205 | struct rtl8xxxu_rx_urb *rx_urb) |
| 8206 | { |
| 8207 | struct sk_buff *skb; |
| 8208 | int skb_size; |
| 8209 | int ret; |
| 8210 | |
| 8211 | skb_size = sizeof(struct rtl8xxxu_rx_desc) + RTL_RX_BUFFER_SIZE; |
| 8212 | skb = __netdev_alloc_skb(NULL, skb_size, GFP_KERNEL); |
| 8213 | if (!skb) |
| 8214 | return -ENOMEM; |
| 8215 | |
| 8216 | memset(skb->data, 0, sizeof(struct rtl8xxxu_rx_desc)); |
| 8217 | usb_fill_bulk_urb(&rx_urb->urb, priv->udev, priv->pipe_in, skb->data, |
| 8218 | skb_size, rtl8xxxu_rx_complete, skb); |
| 8219 | usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor); |
| 8220 | ret = usb_submit_urb(&rx_urb->urb, GFP_ATOMIC); |
| 8221 | if (ret) |
| 8222 | usb_unanchor_urb(&rx_urb->urb); |
| 8223 | return ret; |
| 8224 | } |
| 8225 | |
| 8226 | static void rtl8xxxu_int_complete(struct urb *urb) |
| 8227 | { |
| 8228 | struct rtl8xxxu_priv *priv = (struct rtl8xxxu_priv *)urb->context; |
| 8229 | struct device *dev = &priv->udev->dev; |
| 8230 | int ret; |
| 8231 | |
| 8232 | dev_dbg(dev, "%s: status %i\n", __func__, urb->status); |
| 8233 | if (urb->status == 0) { |
| 8234 | usb_anchor_urb(urb, &priv->int_anchor); |
| 8235 | ret = usb_submit_urb(urb, GFP_ATOMIC); |
| 8236 | if (ret) |
| 8237 | usb_unanchor_urb(urb); |
| 8238 | } else { |
| 8239 | dev_info(dev, "%s: Error %i\n", __func__, urb->status); |
| 8240 | } |
| 8241 | } |
| 8242 | |
| 8243 | |
| 8244 | static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw) |
| 8245 | { |
| 8246 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8247 | struct urb *urb; |
| 8248 | u32 val32; |
| 8249 | int ret; |
| 8250 | |
| 8251 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 8252 | if (!urb) |
| 8253 | return -ENOMEM; |
| 8254 | |
| 8255 | usb_fill_int_urb(urb, priv->udev, priv->pipe_interrupt, |
| 8256 | priv->int_buf, USB_INTR_CONTENT_LENGTH, |
| 8257 | rtl8xxxu_int_complete, priv, 1); |
| 8258 | usb_anchor_urb(urb, &priv->int_anchor); |
| 8259 | ret = usb_submit_urb(urb, GFP_KERNEL); |
| 8260 | if (ret) { |
| 8261 | usb_unanchor_urb(urb); |
| 8262 | goto error; |
| 8263 | } |
| 8264 | |
| 8265 | val32 = rtl8xxxu_read32(priv, REG_USB_HIMR); |
| 8266 | val32 |= USB_HIMR_CPWM; |
| 8267 | rtl8xxxu_write32(priv, REG_USB_HIMR, val32); |
| 8268 | |
| 8269 | error: |
| 8270 | return ret; |
| 8271 | } |
| 8272 | |
| 8273 | static int rtl8xxxu_add_interface(struct ieee80211_hw *hw, |
| 8274 | struct ieee80211_vif *vif) |
| 8275 | { |
| 8276 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8277 | int ret; |
| 8278 | u8 val8; |
| 8279 | |
| 8280 | switch (vif->type) { |
| 8281 | case NL80211_IFTYPE_STATION: |
| 8282 | rtl8723a_stop_tx_beacon(priv); |
| 8283 | |
| 8284 | val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL); |
| 8285 | val8 |= BEACON_ATIM | BEACON_FUNCTION_ENABLE | |
| 8286 | BEACON_DISABLE_TSF_UPDATE; |
| 8287 | rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8); |
| 8288 | ret = 0; |
| 8289 | break; |
| 8290 | default: |
| 8291 | ret = -EOPNOTSUPP; |
| 8292 | } |
| 8293 | |
| 8294 | rtl8xxxu_set_linktype(priv, vif->type); |
| 8295 | |
| 8296 | return ret; |
| 8297 | } |
| 8298 | |
| 8299 | static void rtl8xxxu_remove_interface(struct ieee80211_hw *hw, |
| 8300 | struct ieee80211_vif *vif) |
| 8301 | { |
| 8302 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8303 | |
| 8304 | dev_dbg(&priv->udev->dev, "%s\n", __func__); |
| 8305 | } |
| 8306 | |
| 8307 | static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed) |
| 8308 | { |
| 8309 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8310 | struct device *dev = &priv->udev->dev; |
| 8311 | u16 val16; |
| 8312 | int ret = 0, channel; |
| 8313 | bool ht40; |
| 8314 | |
| 8315 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL) |
| 8316 | dev_info(dev, |
| 8317 | "%s: channel: %i (changed %08x chandef.width %02x)\n", |
| 8318 | __func__, hw->conf.chandef.chan->hw_value, |
| 8319 | changed, hw->conf.chandef.width); |
| 8320 | |
| 8321 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { |
| 8322 | val16 = ((hw->conf.long_frame_max_tx_count << |
| 8323 | RETRY_LIMIT_LONG_SHIFT) & RETRY_LIMIT_LONG_MASK) | |
| 8324 | ((hw->conf.short_frame_max_tx_count << |
| 8325 | RETRY_LIMIT_SHORT_SHIFT) & RETRY_LIMIT_SHORT_MASK); |
| 8326 | rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16); |
| 8327 | } |
| 8328 | |
| 8329 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 8330 | switch (hw->conf.chandef.width) { |
| 8331 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8332 | case NL80211_CHAN_WIDTH_20: |
| 8333 | ht40 = false; |
| 8334 | break; |
| 8335 | case NL80211_CHAN_WIDTH_40: |
| 8336 | ht40 = true; |
| 8337 | break; |
| 8338 | default: |
| 8339 | ret = -ENOTSUPP; |
| 8340 | goto exit; |
| 8341 | } |
| 8342 | |
| 8343 | channel = hw->conf.chandef.chan->hw_value; |
| 8344 | |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 8345 | priv->fops->set_tx_power(priv, channel, ht40); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8346 | |
Jes Sorensen | 1ea8e84 | 2016-02-29 17:05:04 -0500 | [diff] [blame] | 8347 | priv->fops->config_channel(hw); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8348 | } |
| 8349 | |
| 8350 | exit: |
| 8351 | return ret; |
| 8352 | } |
| 8353 | |
| 8354 | static int rtl8xxxu_conf_tx(struct ieee80211_hw *hw, |
| 8355 | struct ieee80211_vif *vif, u16 queue, |
| 8356 | const struct ieee80211_tx_queue_params *param) |
| 8357 | { |
| 8358 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8359 | struct device *dev = &priv->udev->dev; |
| 8360 | u32 val32; |
| 8361 | u8 aifs, acm_ctrl, acm_bit; |
| 8362 | |
| 8363 | aifs = param->aifs; |
| 8364 | |
| 8365 | val32 = aifs | |
| 8366 | fls(param->cw_min) << EDCA_PARAM_ECW_MIN_SHIFT | |
| 8367 | fls(param->cw_max) << EDCA_PARAM_ECW_MAX_SHIFT | |
| 8368 | (u32)param->txop << EDCA_PARAM_TXOP_SHIFT; |
| 8369 | |
| 8370 | acm_ctrl = rtl8xxxu_read8(priv, REG_ACM_HW_CTRL); |
| 8371 | dev_dbg(dev, |
| 8372 | "%s: IEEE80211 queue %02x val %08x, acm %i, acm_ctrl %02x\n", |
| 8373 | __func__, queue, val32, param->acm, acm_ctrl); |
| 8374 | |
| 8375 | switch (queue) { |
| 8376 | case IEEE80211_AC_VO: |
| 8377 | acm_bit = ACM_HW_CTRL_VO; |
| 8378 | rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, val32); |
| 8379 | break; |
| 8380 | case IEEE80211_AC_VI: |
| 8381 | acm_bit = ACM_HW_CTRL_VI; |
| 8382 | rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, val32); |
| 8383 | break; |
| 8384 | case IEEE80211_AC_BE: |
| 8385 | acm_bit = ACM_HW_CTRL_BE; |
| 8386 | rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, val32); |
| 8387 | break; |
| 8388 | case IEEE80211_AC_BK: |
| 8389 | acm_bit = ACM_HW_CTRL_BK; |
| 8390 | rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, val32); |
| 8391 | break; |
| 8392 | default: |
| 8393 | acm_bit = 0; |
| 8394 | break; |
| 8395 | } |
| 8396 | |
| 8397 | if (param->acm) |
| 8398 | acm_ctrl |= acm_bit; |
| 8399 | else |
| 8400 | acm_ctrl &= ~acm_bit; |
| 8401 | rtl8xxxu_write8(priv, REG_ACM_HW_CTRL, acm_ctrl); |
| 8402 | |
| 8403 | return 0; |
| 8404 | } |
| 8405 | |
| 8406 | static void rtl8xxxu_configure_filter(struct ieee80211_hw *hw, |
| 8407 | unsigned int changed_flags, |
| 8408 | unsigned int *total_flags, u64 multicast) |
| 8409 | { |
| 8410 | struct rtl8xxxu_priv *priv = hw->priv; |
Bruno Randolf | 3bed4bf | 2016-02-03 13:39:51 -0500 | [diff] [blame] | 8411 | u32 rcr = rtl8xxxu_read32(priv, REG_RCR); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8412 | |
| 8413 | dev_dbg(&priv->udev->dev, "%s: changed_flags %08x, total_flags %08x\n", |
| 8414 | __func__, changed_flags, *total_flags); |
| 8415 | |
Bruno Randolf | 3bed4bf | 2016-02-03 13:39:51 -0500 | [diff] [blame] | 8416 | /* |
| 8417 | * FIF_ALLMULTI ignored as all multicast frames are accepted (REG_MAR) |
| 8418 | */ |
| 8419 | |
| 8420 | if (*total_flags & FIF_FCSFAIL) |
| 8421 | rcr |= RCR_ACCEPT_CRC32; |
| 8422 | else |
| 8423 | rcr &= ~RCR_ACCEPT_CRC32; |
| 8424 | |
| 8425 | /* |
| 8426 | * FIF_PLCPFAIL not supported? |
| 8427 | */ |
| 8428 | |
| 8429 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 8430 | rcr &= ~RCR_CHECK_BSSID_BEACON; |
| 8431 | else |
| 8432 | rcr |= RCR_CHECK_BSSID_BEACON; |
| 8433 | |
| 8434 | if (*total_flags & FIF_CONTROL) |
| 8435 | rcr |= RCR_ACCEPT_CTRL_FRAME; |
| 8436 | else |
| 8437 | rcr &= ~RCR_ACCEPT_CTRL_FRAME; |
| 8438 | |
| 8439 | if (*total_flags & FIF_OTHER_BSS) { |
| 8440 | rcr |= RCR_ACCEPT_AP; |
| 8441 | rcr &= ~RCR_CHECK_BSSID_MATCH; |
| 8442 | } else { |
| 8443 | rcr &= ~RCR_ACCEPT_AP; |
| 8444 | rcr |= RCR_CHECK_BSSID_MATCH; |
| 8445 | } |
| 8446 | |
| 8447 | if (*total_flags & FIF_PSPOLL) |
| 8448 | rcr |= RCR_ACCEPT_PM; |
| 8449 | else |
| 8450 | rcr &= ~RCR_ACCEPT_PM; |
| 8451 | |
| 8452 | /* |
| 8453 | * FIF_PROBE_REQ ignored as probe requests always seem to be accepted |
| 8454 | */ |
| 8455 | |
| 8456 | rtl8xxxu_write32(priv, REG_RCR, rcr); |
| 8457 | |
Jes Sorensen | 755bda1 | 2016-02-03 13:39:54 -0500 | [diff] [blame] | 8458 | *total_flags &= (FIF_ALLMULTI | FIF_FCSFAIL | FIF_BCN_PRBRESP_PROMISC | |
| 8459 | FIF_CONTROL | FIF_OTHER_BSS | FIF_PSPOLL | |
| 8460 | FIF_PROBE_REQ); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8461 | } |
| 8462 | |
| 8463 | static int rtl8xxxu_set_rts_threshold(struct ieee80211_hw *hw, u32 rts) |
| 8464 | { |
| 8465 | if (rts > 2347) |
| 8466 | return -EINVAL; |
| 8467 | |
| 8468 | return 0; |
| 8469 | } |
| 8470 | |
| 8471 | static int rtl8xxxu_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 8472 | struct ieee80211_vif *vif, |
| 8473 | struct ieee80211_sta *sta, |
| 8474 | struct ieee80211_key_conf *key) |
| 8475 | { |
| 8476 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8477 | struct device *dev = &priv->udev->dev; |
| 8478 | u8 mac_addr[ETH_ALEN]; |
| 8479 | u8 val8; |
| 8480 | u16 val16; |
| 8481 | u32 val32; |
| 8482 | int retval = -EOPNOTSUPP; |
| 8483 | |
| 8484 | dev_dbg(dev, "%s: cmd %02x, cipher %08x, index %i\n", |
| 8485 | __func__, cmd, key->cipher, key->keyidx); |
| 8486 | |
| 8487 | if (vif->type != NL80211_IFTYPE_STATION) |
| 8488 | return -EOPNOTSUPP; |
| 8489 | |
| 8490 | if (key->keyidx > 3) |
| 8491 | return -EOPNOTSUPP; |
| 8492 | |
| 8493 | switch (key->cipher) { |
| 8494 | case WLAN_CIPHER_SUITE_WEP40: |
| 8495 | case WLAN_CIPHER_SUITE_WEP104: |
| 8496 | |
| 8497 | break; |
| 8498 | case WLAN_CIPHER_SUITE_CCMP: |
| 8499 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
| 8500 | break; |
| 8501 | case WLAN_CIPHER_SUITE_TKIP: |
| 8502 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 8503 | default: |
| 8504 | return -EOPNOTSUPP; |
| 8505 | } |
| 8506 | |
| 8507 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 8508 | dev_dbg(dev, "%s: pairwise key\n", __func__); |
| 8509 | ether_addr_copy(mac_addr, sta->addr); |
| 8510 | } else { |
| 8511 | dev_dbg(dev, "%s: group key\n", __func__); |
| 8512 | eth_broadcast_addr(mac_addr); |
| 8513 | } |
| 8514 | |
| 8515 | val16 = rtl8xxxu_read16(priv, REG_CR); |
| 8516 | val16 |= CR_SECURITY_ENABLE; |
| 8517 | rtl8xxxu_write16(priv, REG_CR, val16); |
| 8518 | |
| 8519 | val8 = SEC_CFG_TX_SEC_ENABLE | SEC_CFG_TXBC_USE_DEFKEY | |
| 8520 | SEC_CFG_RX_SEC_ENABLE | SEC_CFG_RXBC_USE_DEFKEY; |
| 8521 | val8 |= SEC_CFG_TX_USE_DEFKEY | SEC_CFG_RX_USE_DEFKEY; |
| 8522 | rtl8xxxu_write8(priv, REG_SECURITY_CFG, val8); |
| 8523 | |
| 8524 | switch (cmd) { |
| 8525 | case SET_KEY: |
| 8526 | key->hw_key_idx = key->keyidx; |
| 8527 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 8528 | rtl8xxxu_cam_write(priv, key, mac_addr); |
| 8529 | retval = 0; |
| 8530 | break; |
| 8531 | case DISABLE_KEY: |
| 8532 | rtl8xxxu_write32(priv, REG_CAM_WRITE, 0x00000000); |
| 8533 | val32 = CAM_CMD_POLLING | CAM_CMD_WRITE | |
| 8534 | key->keyidx << CAM_CMD_KEY_SHIFT; |
| 8535 | rtl8xxxu_write32(priv, REG_CAM_CMD, val32); |
| 8536 | retval = 0; |
| 8537 | break; |
| 8538 | default: |
| 8539 | dev_warn(dev, "%s: Unsupported command %02x\n", __func__, cmd); |
| 8540 | } |
| 8541 | |
| 8542 | return retval; |
| 8543 | } |
| 8544 | |
| 8545 | static int |
| 8546 | rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 8547 | struct ieee80211_ampdu_params *params) |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8548 | { |
| 8549 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8550 | struct device *dev = &priv->udev->dev; |
| 8551 | u8 ampdu_factor, ampdu_density; |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 8552 | struct ieee80211_sta *sta = params->sta; |
| 8553 | enum ieee80211_ampdu_mlme_action action = params->action; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8554 | |
| 8555 | switch (action) { |
| 8556 | case IEEE80211_AMPDU_TX_START: |
| 8557 | dev_info(dev, "%s: IEEE80211_AMPDU_TX_START\n", __func__); |
| 8558 | ampdu_factor = sta->ht_cap.ampdu_factor; |
| 8559 | ampdu_density = sta->ht_cap.ampdu_density; |
| 8560 | rtl8xxxu_set_ampdu_factor(priv, ampdu_factor); |
| 8561 | rtl8xxxu_set_ampdu_min_space(priv, ampdu_density); |
| 8562 | dev_dbg(dev, |
| 8563 | "Changed HT: ampdu_factor %02x, ampdu_density %02x\n", |
| 8564 | ampdu_factor, ampdu_density); |
| 8565 | break; |
| 8566 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 8567 | dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__); |
| 8568 | rtl8xxxu_set_ampdu_factor(priv, 0); |
| 8569 | rtl8xxxu_set_ampdu_min_space(priv, 0); |
| 8570 | break; |
| 8571 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 8572 | dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n", |
| 8573 | __func__); |
| 8574 | rtl8xxxu_set_ampdu_factor(priv, 0); |
| 8575 | rtl8xxxu_set_ampdu_min_space(priv, 0); |
| 8576 | break; |
| 8577 | case IEEE80211_AMPDU_RX_START: |
| 8578 | dev_info(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__); |
| 8579 | break; |
| 8580 | case IEEE80211_AMPDU_RX_STOP: |
| 8581 | dev_info(dev, "%s: IEEE80211_AMPDU_RX_STOP\n", __func__); |
| 8582 | break; |
| 8583 | default: |
| 8584 | break; |
| 8585 | } |
| 8586 | return 0; |
| 8587 | } |
| 8588 | |
| 8589 | static int rtl8xxxu_start(struct ieee80211_hw *hw) |
| 8590 | { |
| 8591 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8592 | struct rtl8xxxu_rx_urb *rx_urb; |
| 8593 | struct rtl8xxxu_tx_urb *tx_urb; |
| 8594 | unsigned long flags; |
| 8595 | int ret, i; |
| 8596 | |
| 8597 | ret = 0; |
| 8598 | |
| 8599 | init_usb_anchor(&priv->rx_anchor); |
| 8600 | init_usb_anchor(&priv->tx_anchor); |
| 8601 | init_usb_anchor(&priv->int_anchor); |
| 8602 | |
Jes Sorensen | db08de9 | 2016-02-29 17:05:17 -0500 | [diff] [blame] | 8603 | priv->fops->enable_rf(priv); |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 8604 | if (priv->usb_interrupts) { |
| 8605 | ret = rtl8xxxu_submit_int_urb(hw); |
| 8606 | if (ret) |
| 8607 | goto exit; |
| 8608 | } |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8609 | |
| 8610 | for (i = 0; i < RTL8XXXU_TX_URBS; i++) { |
| 8611 | tx_urb = kmalloc(sizeof(struct rtl8xxxu_tx_urb), GFP_KERNEL); |
| 8612 | if (!tx_urb) { |
| 8613 | if (!i) |
| 8614 | ret = -ENOMEM; |
| 8615 | |
| 8616 | goto error_out; |
| 8617 | } |
| 8618 | usb_init_urb(&tx_urb->urb); |
| 8619 | INIT_LIST_HEAD(&tx_urb->list); |
| 8620 | tx_urb->hw = hw; |
| 8621 | list_add(&tx_urb->list, &priv->tx_urb_free_list); |
| 8622 | priv->tx_urb_free_count++; |
| 8623 | } |
| 8624 | |
| 8625 | priv->tx_stopped = false; |
| 8626 | |
| 8627 | spin_lock_irqsave(&priv->rx_urb_lock, flags); |
| 8628 | priv->shutdown = false; |
| 8629 | spin_unlock_irqrestore(&priv->rx_urb_lock, flags); |
| 8630 | |
| 8631 | for (i = 0; i < RTL8XXXU_RX_URBS; i++) { |
| 8632 | rx_urb = kmalloc(sizeof(struct rtl8xxxu_rx_urb), GFP_KERNEL); |
| 8633 | if (!rx_urb) { |
| 8634 | if (!i) |
| 8635 | ret = -ENOMEM; |
| 8636 | |
| 8637 | goto error_out; |
| 8638 | } |
| 8639 | usb_init_urb(&rx_urb->urb); |
| 8640 | INIT_LIST_HEAD(&rx_urb->list); |
| 8641 | rx_urb->hw = hw; |
| 8642 | |
| 8643 | ret = rtl8xxxu_submit_rx_urb(priv, rx_urb); |
| 8644 | } |
| 8645 | exit: |
| 8646 | /* |
Bruno Randolf | c85ea11 | 2016-02-03 13:39:55 -0500 | [diff] [blame] | 8647 | * Accept all data and mgmt frames |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8648 | */ |
Bruno Randolf | c85ea11 | 2016-02-03 13:39:55 -0500 | [diff] [blame] | 8649 | rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0xffff); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8650 | rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0xffff); |
| 8651 | |
| 8652 | rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, 0x6954341e); |
| 8653 | |
| 8654 | return ret; |
| 8655 | |
| 8656 | error_out: |
| 8657 | rtl8xxxu_free_tx_resources(priv); |
| 8658 | /* |
| 8659 | * Disable all data and mgmt frames |
| 8660 | */ |
| 8661 | rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000); |
| 8662 | rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000); |
| 8663 | |
| 8664 | return ret; |
| 8665 | } |
| 8666 | |
| 8667 | static void rtl8xxxu_stop(struct ieee80211_hw *hw) |
| 8668 | { |
| 8669 | struct rtl8xxxu_priv *priv = hw->priv; |
| 8670 | unsigned long flags; |
| 8671 | |
| 8672 | rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); |
| 8673 | |
| 8674 | rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000); |
| 8675 | rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000); |
| 8676 | |
| 8677 | spin_lock_irqsave(&priv->rx_urb_lock, flags); |
| 8678 | priv->shutdown = true; |
| 8679 | spin_unlock_irqrestore(&priv->rx_urb_lock, flags); |
| 8680 | |
| 8681 | usb_kill_anchored_urbs(&priv->rx_anchor); |
| 8682 | usb_kill_anchored_urbs(&priv->tx_anchor); |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 8683 | if (priv->usb_interrupts) |
| 8684 | usb_kill_anchored_urbs(&priv->int_anchor); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8685 | |
Jes Sorensen | fc89a41 | 2016-02-29 17:05:46 -0500 | [diff] [blame] | 8686 | priv->fops->disable_rf(priv); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8687 | |
| 8688 | /* |
| 8689 | * Disable interrupts |
| 8690 | */ |
Jes Sorensen | 0e28b97 | 2016-02-29 17:04:13 -0500 | [diff] [blame] | 8691 | if (priv->usb_interrupts) |
| 8692 | rtl8xxxu_write32(priv, REG_USB_HIMR, 0); |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8693 | |
| 8694 | rtl8xxxu_free_rx_resources(priv); |
| 8695 | rtl8xxxu_free_tx_resources(priv); |
| 8696 | } |
| 8697 | |
| 8698 | static const struct ieee80211_ops rtl8xxxu_ops = { |
| 8699 | .tx = rtl8xxxu_tx, |
| 8700 | .add_interface = rtl8xxxu_add_interface, |
| 8701 | .remove_interface = rtl8xxxu_remove_interface, |
| 8702 | .config = rtl8xxxu_config, |
| 8703 | .conf_tx = rtl8xxxu_conf_tx, |
| 8704 | .bss_info_changed = rtl8xxxu_bss_info_changed, |
| 8705 | .configure_filter = rtl8xxxu_configure_filter, |
| 8706 | .set_rts_threshold = rtl8xxxu_set_rts_threshold, |
| 8707 | .start = rtl8xxxu_start, |
| 8708 | .stop = rtl8xxxu_stop, |
| 8709 | .sw_scan_start = rtl8xxxu_sw_scan_start, |
| 8710 | .sw_scan_complete = rtl8xxxu_sw_scan_complete, |
| 8711 | .set_key = rtl8xxxu_set_key, |
| 8712 | .ampdu_action = rtl8xxxu_ampdu_action, |
| 8713 | }; |
| 8714 | |
| 8715 | static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv, |
| 8716 | struct usb_interface *interface) |
| 8717 | { |
| 8718 | struct usb_interface_descriptor *interface_desc; |
| 8719 | struct usb_host_interface *host_interface; |
| 8720 | struct usb_endpoint_descriptor *endpoint; |
| 8721 | struct device *dev = &priv->udev->dev; |
| 8722 | int i, j = 0, endpoints; |
| 8723 | u8 dir, xtype, num; |
| 8724 | int ret = 0; |
| 8725 | |
| 8726 | host_interface = &interface->altsetting[0]; |
| 8727 | interface_desc = &host_interface->desc; |
| 8728 | endpoints = interface_desc->bNumEndpoints; |
| 8729 | |
| 8730 | for (i = 0; i < endpoints; i++) { |
| 8731 | endpoint = &host_interface->endpoint[i].desc; |
| 8732 | |
| 8733 | dir = endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK; |
| 8734 | num = usb_endpoint_num(endpoint); |
| 8735 | xtype = usb_endpoint_type(endpoint); |
| 8736 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB) |
| 8737 | dev_dbg(dev, |
| 8738 | "%s: endpoint: dir %02x, # %02x, type %02x\n", |
| 8739 | __func__, dir, num, xtype); |
| 8740 | if (usb_endpoint_dir_in(endpoint) && |
| 8741 | usb_endpoint_xfer_bulk(endpoint)) { |
| 8742 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB) |
| 8743 | dev_dbg(dev, "%s: in endpoint num %i\n", |
| 8744 | __func__, num); |
| 8745 | |
| 8746 | if (priv->pipe_in) { |
| 8747 | dev_warn(dev, |
| 8748 | "%s: Too many IN pipes\n", __func__); |
| 8749 | ret = -EINVAL; |
| 8750 | goto exit; |
| 8751 | } |
| 8752 | |
| 8753 | priv->pipe_in = usb_rcvbulkpipe(priv->udev, num); |
| 8754 | } |
| 8755 | |
| 8756 | if (usb_endpoint_dir_in(endpoint) && |
| 8757 | usb_endpoint_xfer_int(endpoint)) { |
| 8758 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB) |
| 8759 | dev_dbg(dev, "%s: interrupt endpoint num %i\n", |
| 8760 | __func__, num); |
| 8761 | |
| 8762 | if (priv->pipe_interrupt) { |
| 8763 | dev_warn(dev, "%s: Too many INTERRUPT pipes\n", |
| 8764 | __func__); |
| 8765 | ret = -EINVAL; |
| 8766 | goto exit; |
| 8767 | } |
| 8768 | |
| 8769 | priv->pipe_interrupt = usb_rcvintpipe(priv->udev, num); |
| 8770 | } |
| 8771 | |
| 8772 | if (usb_endpoint_dir_out(endpoint) && |
| 8773 | usb_endpoint_xfer_bulk(endpoint)) { |
| 8774 | if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB) |
| 8775 | dev_dbg(dev, "%s: out endpoint num %i\n", |
| 8776 | __func__, num); |
| 8777 | if (j >= RTL8XXXU_OUT_ENDPOINTS) { |
| 8778 | dev_warn(dev, |
| 8779 | "%s: Too many OUT pipes\n", __func__); |
| 8780 | ret = -EINVAL; |
| 8781 | goto exit; |
| 8782 | } |
| 8783 | priv->out_ep[j++] = num; |
| 8784 | } |
| 8785 | } |
| 8786 | exit: |
| 8787 | priv->nr_out_eps = j; |
| 8788 | return ret; |
| 8789 | } |
| 8790 | |
| 8791 | static int rtl8xxxu_probe(struct usb_interface *interface, |
| 8792 | const struct usb_device_id *id) |
| 8793 | { |
| 8794 | struct rtl8xxxu_priv *priv; |
| 8795 | struct ieee80211_hw *hw; |
| 8796 | struct usb_device *udev; |
| 8797 | struct ieee80211_supported_band *sband; |
| 8798 | int ret = 0; |
| 8799 | int untested = 1; |
| 8800 | |
| 8801 | udev = usb_get_dev(interface_to_usbdev(interface)); |
| 8802 | |
| 8803 | switch (id->idVendor) { |
| 8804 | case USB_VENDOR_ID_REALTEK: |
| 8805 | switch(id->idProduct) { |
| 8806 | case 0x1724: |
| 8807 | case 0x8176: |
| 8808 | case 0x8178: |
| 8809 | case 0x817f: |
| 8810 | untested = 0; |
| 8811 | break; |
| 8812 | } |
| 8813 | break; |
| 8814 | case 0x7392: |
| 8815 | if (id->idProduct == 0x7811) |
| 8816 | untested = 0; |
| 8817 | break; |
| 8818 | default: |
| 8819 | break; |
| 8820 | } |
| 8821 | |
| 8822 | if (untested) { |
Jes Sorensen | eaa4d14 | 2016-02-29 17:04:31 -0500 | [diff] [blame] | 8823 | rtl8xxxu_debug |= RTL8XXXU_DEBUG_EFUSE; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8824 | dev_info(&udev->dev, |
| 8825 | "This Realtek USB WiFi dongle (0x%04x:0x%04x) is untested!\n", |
| 8826 | id->idVendor, id->idProduct); |
| 8827 | dev_info(&udev->dev, |
| 8828 | "Please report results to Jes.Sorensen@gmail.com\n"); |
| 8829 | } |
| 8830 | |
| 8831 | hw = ieee80211_alloc_hw(sizeof(struct rtl8xxxu_priv), &rtl8xxxu_ops); |
| 8832 | if (!hw) { |
| 8833 | ret = -ENOMEM; |
| 8834 | goto exit; |
| 8835 | } |
| 8836 | |
| 8837 | priv = hw->priv; |
| 8838 | priv->hw = hw; |
| 8839 | priv->udev = udev; |
| 8840 | priv->fops = (struct rtl8xxxu_fileops *)id->driver_info; |
| 8841 | mutex_init(&priv->usb_buf_mutex); |
| 8842 | mutex_init(&priv->h2c_mutex); |
| 8843 | INIT_LIST_HEAD(&priv->tx_urb_free_list); |
| 8844 | spin_lock_init(&priv->tx_urb_lock); |
| 8845 | INIT_LIST_HEAD(&priv->rx_urb_pending_list); |
| 8846 | spin_lock_init(&priv->rx_urb_lock); |
| 8847 | INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work); |
| 8848 | |
| 8849 | usb_set_intfdata(interface, hw); |
| 8850 | |
| 8851 | ret = rtl8xxxu_parse_usb(priv, interface); |
| 8852 | if (ret) |
| 8853 | goto exit; |
| 8854 | |
| 8855 | ret = rtl8xxxu_identify_chip(priv); |
| 8856 | if (ret) { |
| 8857 | dev_err(&udev->dev, "Fatal - failed to identify chip\n"); |
| 8858 | goto exit; |
| 8859 | } |
| 8860 | |
| 8861 | ret = rtl8xxxu_read_efuse(priv); |
| 8862 | if (ret) { |
| 8863 | dev_err(&udev->dev, "Fatal - failed to read EFuse\n"); |
| 8864 | goto exit; |
| 8865 | } |
| 8866 | |
| 8867 | ret = priv->fops->parse_efuse(priv); |
| 8868 | if (ret) { |
| 8869 | dev_err(&udev->dev, "Fatal - failed to parse EFuse\n"); |
| 8870 | goto exit; |
| 8871 | } |
| 8872 | |
| 8873 | rtl8xxxu_print_chipinfo(priv); |
| 8874 | |
| 8875 | ret = priv->fops->load_firmware(priv); |
| 8876 | if (ret) { |
| 8877 | dev_err(&udev->dev, "Fatal - failed to load firmware\n"); |
| 8878 | goto exit; |
| 8879 | } |
| 8880 | |
| 8881 | ret = rtl8xxxu_init_device(hw); |
| 8882 | |
| 8883 | hw->wiphy->max_scan_ssids = 1; |
| 8884 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; |
| 8885 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
| 8886 | hw->queues = 4; |
| 8887 | |
| 8888 | sband = &rtl8xxxu_supported_band; |
| 8889 | sband->ht_cap.ht_supported = true; |
| 8890 | sband->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 8891 | sband->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 8892 | sband->ht_cap.cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40; |
| 8893 | memset(&sband->ht_cap.mcs, 0, sizeof(sband->ht_cap.mcs)); |
| 8894 | sband->ht_cap.mcs.rx_mask[0] = 0xff; |
| 8895 | sband->ht_cap.mcs.rx_mask[4] = 0x01; |
| 8896 | if (priv->rf_paths > 1) { |
| 8897 | sband->ht_cap.mcs.rx_mask[1] = 0xff; |
| 8898 | sband->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 8899 | } |
| 8900 | sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 8901 | /* |
| 8902 | * Some APs will negotiate HT20_40 in a noisy environment leading |
| 8903 | * to miserable performance. Rather than defaulting to this, only |
| 8904 | * enable it if explicitly requested at module load time. |
| 8905 | */ |
| 8906 | if (rtl8xxxu_ht40_2g) { |
| 8907 | dev_info(&udev->dev, "Enabling HT_20_40 on the 2.4GHz band\n"); |
| 8908 | sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 8909 | } |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8910 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8911 | |
| 8912 | hw->wiphy->rts_threshold = 2347; |
| 8913 | |
| 8914 | SET_IEEE80211_DEV(priv->hw, &interface->dev); |
| 8915 | SET_IEEE80211_PERM_ADDR(hw, priv->mac_addr); |
| 8916 | |
Jes Sorensen | 179e174 | 2016-02-29 17:05:27 -0500 | [diff] [blame] | 8917 | hw->extra_tx_headroom = priv->fops->tx_desc_size; |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8918 | ieee80211_hw_set(hw, SIGNAL_DBM); |
| 8919 | /* |
| 8920 | * The firmware handles rate control |
| 8921 | */ |
| 8922 | ieee80211_hw_set(hw, HAS_RATE_CONTROL); |
| 8923 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
| 8924 | |
| 8925 | ret = ieee80211_register_hw(priv->hw); |
| 8926 | if (ret) { |
| 8927 | dev_err(&udev->dev, "%s: Failed to register: %i\n", |
| 8928 | __func__, ret); |
| 8929 | goto exit; |
| 8930 | } |
| 8931 | |
| 8932 | exit: |
| 8933 | if (ret < 0) |
| 8934 | usb_put_dev(udev); |
| 8935 | return ret; |
| 8936 | } |
| 8937 | |
| 8938 | static void rtl8xxxu_disconnect(struct usb_interface *interface) |
| 8939 | { |
| 8940 | struct rtl8xxxu_priv *priv; |
| 8941 | struct ieee80211_hw *hw; |
| 8942 | |
| 8943 | hw = usb_get_intfdata(interface); |
| 8944 | priv = hw->priv; |
| 8945 | |
| 8946 | rtl8xxxu_disable_device(hw); |
| 8947 | usb_set_intfdata(interface, NULL); |
| 8948 | |
| 8949 | dev_info(&priv->udev->dev, "disconnecting\n"); |
| 8950 | |
| 8951 | ieee80211_unregister_hw(hw); |
| 8952 | |
| 8953 | kfree(priv->fw_data); |
| 8954 | mutex_destroy(&priv->usb_buf_mutex); |
| 8955 | mutex_destroy(&priv->h2c_mutex); |
| 8956 | |
| 8957 | usb_put_dev(priv->udev); |
| 8958 | ieee80211_free_hw(hw); |
| 8959 | } |
| 8960 | |
| 8961 | static struct rtl8xxxu_fileops rtl8723au_fops = { |
| 8962 | .parse_efuse = rtl8723au_parse_efuse, |
| 8963 | .load_firmware = rtl8723au_load_firmware, |
| 8964 | .power_on = rtl8723au_power_on, |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 8965 | .power_off = rtl8xxxu_power_off, |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 8966 | .reset_8051 = rtl8xxxu_reset_8051, |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 8967 | .llt_init = rtl8xxxu_init_llt_table, |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 8968 | .phy_iq_calibrate = rtl8723au_phy_iq_calibrate, |
Jes Sorensen | c3f9506 | 2016-02-29 17:04:40 -0500 | [diff] [blame] | 8969 | .config_channel = rtl8723au_config_channel, |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8970 | .parse_rx_desc = rtl8723au_parse_rx_desc, |
Jes Sorensen | db08de9 | 2016-02-29 17:05:17 -0500 | [diff] [blame] | 8971 | .enable_rf = rtl8723a_enable_rf, |
Jes Sorensen | fc89a41 | 2016-02-29 17:05:46 -0500 | [diff] [blame] | 8972 | .disable_rf = rtl8723a_disable_rf, |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 8973 | .set_tx_power = rtl8723a_set_tx_power, |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 8974 | .update_rate_mask = rtl8723au_update_rate_mask, |
Jes Sorensen | 7d794ea | 2016-02-29 17:05:39 -0500 | [diff] [blame] | 8975 | .report_connect = rtl8723au_report_connect, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8976 | .writeN_block_size = 1024, |
Jes Sorensen | ed35d09 | 2016-02-29 17:04:19 -0500 | [diff] [blame] | 8977 | .mbox_ext_reg = REG_HMBOX_EXT_0, |
| 8978 | .mbox_ext_width = 2, |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 8979 | .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32), |
Jes Sorensen | 8634af5 | 2016-02-29 17:04:33 -0500 | [diff] [blame] | 8980 | .adda_1t_init = 0x0b1b25a0, |
| 8981 | .adda_1t_path_on = 0x0bdb25a0, |
| 8982 | .adda_2t_path_on_a = 0x04db25a4, |
| 8983 | .adda_2t_path_on_b = 0x0b1b25a4, |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 8984 | .mactable = rtl8723a_mac_init_table, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 8985 | }; |
| 8986 | |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 8987 | static struct rtl8xxxu_fileops rtl8723bu_fops = { |
Jes Sorensen | 3c836d6 | 2016-02-29 17:04:11 -0500 | [diff] [blame] | 8988 | .parse_efuse = rtl8723bu_parse_efuse, |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 8989 | .load_firmware = rtl8723bu_load_firmware, |
Jes Sorensen | 42836db | 2016-02-29 17:04:52 -0500 | [diff] [blame] | 8990 | .power_on = rtl8723bu_power_on, |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 8991 | .power_off = rtl8723bu_power_off, |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 8992 | .reset_8051 = rtl8723bu_reset_8051, |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 8993 | .llt_init = rtl8xxxu_auto_llt_table, |
Jes Sorensen | f0d9f5e | 2016-02-29 17:04:16 -0500 | [diff] [blame] | 8994 | .phy_init_antenna_selection = rtl8723bu_phy_init_antenna_selection, |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 8995 | .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate, |
Jes Sorensen | c3f9506 | 2016-02-29 17:04:40 -0500 | [diff] [blame] | 8996 | .config_channel = rtl8723bu_config_channel, |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 8997 | .parse_rx_desc = rtl8723bu_parse_rx_desc, |
Jes Sorensen | 3e88ca4 | 2016-02-29 17:05:08 -0500 | [diff] [blame] | 8998 | .init_aggregation = rtl8723bu_init_aggregation, |
Jes Sorensen | 9c79bf9 | 2016-02-29 17:05:10 -0500 | [diff] [blame] | 8999 | .init_statistics = rtl8723bu_init_statistics, |
Jes Sorensen | db08de9 | 2016-02-29 17:05:17 -0500 | [diff] [blame] | 9000 | .enable_rf = rtl8723b_enable_rf, |
Jes Sorensen | fc89a41 | 2016-02-29 17:05:46 -0500 | [diff] [blame] | 9001 | .disable_rf = rtl8723b_disable_rf, |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 9002 | .set_tx_power = rtl8723b_set_tx_power, |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 9003 | .update_rate_mask = rtl8723bu_update_rate_mask, |
Jes Sorensen | 7d794ea | 2016-02-29 17:05:39 -0500 | [diff] [blame] | 9004 | .report_connect = rtl8723bu_report_connect, |
Jes Sorensen | adfc012 | 2016-02-29 17:04:12 -0500 | [diff] [blame] | 9005 | .writeN_block_size = 1024, |
Jes Sorensen | ed35d09 | 2016-02-29 17:04:19 -0500 | [diff] [blame] | 9006 | .mbox_ext_reg = REG_HMBOX_EXT0_8723B, |
| 9007 | .mbox_ext_width = 4, |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 9008 | .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40), |
Jes Sorensen | 0d698de | 2016-02-29 17:04:36 -0500 | [diff] [blame] | 9009 | .has_s0s1 = 1, |
Jes Sorensen | 8634af5 | 2016-02-29 17:04:33 -0500 | [diff] [blame] | 9010 | .adda_1t_init = 0x01c00014, |
| 9011 | .adda_1t_path_on = 0x01c00014, |
| 9012 | .adda_2t_path_on_a = 0x01c00014, |
| 9013 | .adda_2t_path_on_b = 0x01c00014, |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 9014 | .mactable = rtl8723b_mac_init_table, |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 9015 | }; |
| 9016 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 9017 | #ifdef CONFIG_RTL8XXXU_UNTESTED |
| 9018 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9019 | static struct rtl8xxxu_fileops rtl8192cu_fops = { |
| 9020 | .parse_efuse = rtl8192cu_parse_efuse, |
| 9021 | .load_firmware = rtl8192cu_load_firmware, |
| 9022 | .power_on = rtl8192cu_power_on, |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 9023 | .power_off = rtl8xxxu_power_off, |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 9024 | .reset_8051 = rtl8xxxu_reset_8051, |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 9025 | .llt_init = rtl8xxxu_init_llt_table, |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 9026 | .phy_iq_calibrate = rtl8723au_phy_iq_calibrate, |
Jes Sorensen | c3f9506 | 2016-02-29 17:04:40 -0500 | [diff] [blame] | 9027 | .config_channel = rtl8723au_config_channel, |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 9028 | .parse_rx_desc = rtl8723au_parse_rx_desc, |
Jes Sorensen | db08de9 | 2016-02-29 17:05:17 -0500 | [diff] [blame] | 9029 | .enable_rf = rtl8723a_enable_rf, |
Jes Sorensen | fc89a41 | 2016-02-29 17:05:46 -0500 | [diff] [blame] | 9030 | .disable_rf = rtl8723a_disable_rf, |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 9031 | .set_tx_power = rtl8723a_set_tx_power, |
Jes Sorensen | f653e69 | 2016-02-29 17:05:38 -0500 | [diff] [blame] | 9032 | .update_rate_mask = rtl8723au_update_rate_mask, |
Jes Sorensen | 7d794ea | 2016-02-29 17:05:39 -0500 | [diff] [blame] | 9033 | .report_connect = rtl8723au_report_connect, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9034 | .writeN_block_size = 128, |
Jes Sorensen | ed35d09 | 2016-02-29 17:04:19 -0500 | [diff] [blame] | 9035 | .mbox_ext_reg = REG_HMBOX_EXT_0, |
| 9036 | .mbox_ext_width = 2, |
Jes Sorensen | dbb2896 | 2016-03-31 17:08:33 -0400 | [diff] [blame] | 9037 | .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32), |
Jes Sorensen | 8634af5 | 2016-02-29 17:04:33 -0500 | [diff] [blame] | 9038 | .adda_1t_init = 0x0b1b25a0, |
| 9039 | .adda_1t_path_on = 0x0bdb25a0, |
| 9040 | .adda_2t_path_on_a = 0x04db25a4, |
| 9041 | .adda_2t_path_on_b = 0x0b1b25a4, |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 9042 | .mactable = rtl8723a_mac_init_table, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9043 | }; |
| 9044 | |
Kalle Valo | c096377 | 2015-10-25 18:24:38 +0200 | [diff] [blame] | 9045 | #endif |
| 9046 | |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 9047 | static struct rtl8xxxu_fileops rtl8192eu_fops = { |
| 9048 | .parse_efuse = rtl8192eu_parse_efuse, |
| 9049 | .load_firmware = rtl8192eu_load_firmware, |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 9050 | .power_on = rtl8192eu_power_on, |
Jes Sorensen | fe37d5f | 2016-02-29 17:05:47 -0500 | [diff] [blame] | 9051 | .power_off = rtl8xxxu_power_off, |
Jes Sorensen | 7d4ccb8 | 2016-02-29 17:05:50 -0500 | [diff] [blame] | 9052 | .reset_8051 = rtl8xxxu_reset_8051, |
Jes Sorensen | 74b99be | 2016-02-29 17:04:04 -0500 | [diff] [blame] | 9053 | .llt_init = rtl8xxxu_auto_llt_table, |
Jes Sorensen | e1547c5 | 2016-02-29 17:04:35 -0500 | [diff] [blame] | 9054 | .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate, |
Jes Sorensen | c3f9506 | 2016-02-29 17:04:40 -0500 | [diff] [blame] | 9055 | .config_channel = rtl8723bu_config_channel, |
Jes Sorensen | b18cdfd | 2016-02-29 17:04:47 -0500 | [diff] [blame] | 9056 | .parse_rx_desc = rtl8723bu_parse_rx_desc, |
Jes Sorensen | db08de9 | 2016-02-29 17:05:17 -0500 | [diff] [blame] | 9057 | .enable_rf = rtl8723b_enable_rf, |
Jes Sorensen | fc89a41 | 2016-02-29 17:05:46 -0500 | [diff] [blame] | 9058 | .disable_rf = rtl8723b_disable_rf, |
Jes Sorensen | e796dab | 2016-02-29 17:05:19 -0500 | [diff] [blame] | 9059 | .set_tx_power = rtl8723b_set_tx_power, |
Jes Sorensen | 91cbe4e | 2016-03-31 17:08:41 -0400 | [diff] [blame] | 9060 | .update_rate_mask = rtl8723bu_update_rate_mask, |
| 9061 | .report_connect = rtl8723bu_report_connect, |
Jes Sorensen | c05a9db | 2016-02-29 17:04:03 -0500 | [diff] [blame] | 9062 | .writeN_block_size = 128, |
Jes Sorensen | ed35d09 | 2016-02-29 17:04:19 -0500 | [diff] [blame] | 9063 | .mbox_ext_reg = REG_HMBOX_EXT0_8723B, |
| 9064 | .mbox_ext_width = 4, |
Jes Sorensen | f3fc251 | 2016-03-31 17:08:37 -0400 | [diff] [blame] | 9065 | .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40), |
Jes Sorensen | 0d698de | 2016-02-29 17:04:36 -0500 | [diff] [blame] | 9066 | .has_s0s1 = 1, |
Jes Sorensen | 8634af5 | 2016-02-29 17:04:33 -0500 | [diff] [blame] | 9067 | .adda_1t_init = 0x0fc01616, |
| 9068 | .adda_1t_path_on = 0x0fc01616, |
| 9069 | .adda_2t_path_on_a = 0x0fc01616, |
| 9070 | .adda_2t_path_on_b = 0x0fc01616, |
Jes Sorensen | c606e66 | 2016-04-07 14:19:16 -0400 | [diff] [blame] | 9071 | .mactable = rtl8192e_mac_init_table, |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 9072 | }; |
| 9073 | |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9074 | static struct usb_device_id dev_table[] = { |
| 9075 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8724, 0xff, 0xff, 0xff), |
| 9076 | .driver_info = (unsigned long)&rtl8723au_fops}, |
| 9077 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1724, 0xff, 0xff, 0xff), |
| 9078 | .driver_info = (unsigned long)&rtl8723au_fops}, |
| 9079 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x0724, 0xff, 0xff, 0xff), |
| 9080 | .driver_info = (unsigned long)&rtl8723au_fops}, |
Jes Sorensen | 3307d84 | 2016-02-29 17:03:59 -0500 | [diff] [blame] | 9081 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818b, 0xff, 0xff, 0xff), |
| 9082 | .driver_info = (unsigned long)&rtl8192eu_fops}, |
Jes Sorensen | 35a741f | 2016-02-29 17:04:10 -0500 | [diff] [blame] | 9083 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0xb720, 0xff, 0xff, 0xff), |
| 9084 | .driver_info = (unsigned long)&rtl8723bu_fops}, |
Kalle Valo | 033695b | 2015-10-23 20:27:58 +0300 | [diff] [blame] | 9085 | #ifdef CONFIG_RTL8XXXU_UNTESTED |
| 9086 | /* Still supported by rtlwifi */ |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9087 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8176, 0xff, 0xff, 0xff), |
| 9088 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9089 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8178, 0xff, 0xff, 0xff), |
| 9090 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9091 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817f, 0xff, 0xff, 0xff), |
| 9092 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9093 | /* Tested by Larry Finger */ |
| 9094 | {USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7811, 0xff, 0xff, 0xff), |
| 9095 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9096 | /* Currently untested 8188 series devices */ |
| 9097 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8191, 0xff, 0xff, 0xff), |
| 9098 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9099 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8170, 0xff, 0xff, 0xff), |
| 9100 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9101 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8177, 0xff, 0xff, 0xff), |
| 9102 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9103 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817a, 0xff, 0xff, 0xff), |
| 9104 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9105 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817b, 0xff, 0xff, 0xff), |
| 9106 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9107 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817d, 0xff, 0xff, 0xff), |
| 9108 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9109 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817e, 0xff, 0xff, 0xff), |
| 9110 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9111 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818a, 0xff, 0xff, 0xff), |
| 9112 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9113 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x317f, 0xff, 0xff, 0xff), |
| 9114 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9115 | {USB_DEVICE_AND_INTERFACE_INFO(0x1058, 0x0631, 0xff, 0xff, 0xff), |
| 9116 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9117 | {USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x094c, 0xff, 0xff, 0xff), |
| 9118 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9119 | {USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1102, 0xff, 0xff, 0xff), |
| 9120 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9121 | {USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe033, 0xff, 0xff, 0xff), |
| 9122 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9123 | {USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8189, 0xff, 0xff, 0xff), |
| 9124 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9125 | {USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9041, 0xff, 0xff, 0xff), |
| 9126 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9127 | {USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ba, 0xff, 0xff, 0xff), |
| 9128 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9129 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1e1e, 0xff, 0xff, 0xff), |
| 9130 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9131 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x5088, 0xff, 0xff, 0xff), |
| 9132 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9133 | {USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0052, 0xff, 0xff, 0xff), |
| 9134 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9135 | {USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x005c, 0xff, 0xff, 0xff), |
| 9136 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9137 | {USB_DEVICE_AND_INTERFACE_INFO(0x0eb0, 0x9071, 0xff, 0xff, 0xff), |
| 9138 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9139 | {USB_DEVICE_AND_INTERFACE_INFO(0x103c, 0x1629, 0xff, 0xff, 0xff), |
| 9140 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9141 | {USB_DEVICE_AND_INTERFACE_INFO(0x13d3, 0x3357, 0xff, 0xff, 0xff), |
| 9142 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9143 | {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3308, 0xff, 0xff, 0xff), |
| 9144 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9145 | {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330b, 0xff, 0xff, 0xff), |
| 9146 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9147 | {USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x4902, 0xff, 0xff, 0xff), |
| 9148 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9149 | {USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2a, 0xff, 0xff, 0xff), |
| 9150 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9151 | {USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2e, 0xff, 0xff, 0xff), |
| 9152 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9153 | {USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xed17, 0xff, 0xff, 0xff), |
| 9154 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9155 | {USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x648b, 0xff, 0xff, 0xff), |
| 9156 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9157 | {USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0090, 0xff, 0xff, 0xff), |
| 9158 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9159 | {USB_DEVICE_AND_INTERFACE_INFO(0x4856, 0x0091, 0xff, 0xff, 0xff), |
| 9160 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9161 | {USB_DEVICE_AND_INTERFACE_INFO(0xcdab, 0x8010, 0xff, 0xff, 0xff), |
| 9162 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
Jes Sorensen | 26f1fad | 2015-10-14 20:44:51 -0400 | [diff] [blame] | 9163 | {USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff7, 0xff, 0xff, 0xff), |
| 9164 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9165 | {USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff9, 0xff, 0xff, 0xff), |
| 9166 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9167 | {USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffa, 0xff, 0xff, 0xff), |
| 9168 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9169 | {USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff8, 0xff, 0xff, 0xff), |
| 9170 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9171 | {USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffb, 0xff, 0xff, 0xff), |
| 9172 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9173 | {USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffc, 0xff, 0xff, 0xff), |
| 9174 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9175 | {USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x1201, 0xff, 0xff, 0xff), |
| 9176 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9177 | /* Currently untested 8192 series devices */ |
| 9178 | {USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x0950, 0xff, 0xff, 0xff), |
| 9179 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9180 | {USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1004, 0xff, 0xff, 0xff), |
| 9181 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9182 | {USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2102, 0xff, 0xff, 0xff), |
| 9183 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9184 | {USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2103, 0xff, 0xff, 0xff), |
| 9185 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9186 | {USB_DEVICE_AND_INTERFACE_INFO(0x0586, 0x341f, 0xff, 0xff, 0xff), |
| 9187 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9188 | {USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe035, 0xff, 0xff, 0xff), |
| 9189 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9190 | {USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ab, 0xff, 0xff, 0xff), |
| 9191 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9192 | {USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0061, 0xff, 0xff, 0xff), |
| 9193 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9194 | {USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0070, 0xff, 0xff, 0xff), |
| 9195 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9196 | {USB_DEVICE_AND_INTERFACE_INFO(0x0789, 0x016d, 0xff, 0xff, 0xff), |
| 9197 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9198 | {USB_DEVICE_AND_INTERFACE_INFO(0x07aa, 0x0056, 0xff, 0xff, 0xff), |
| 9199 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9200 | {USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8178, 0xff, 0xff, 0xff), |
| 9201 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9202 | {USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9021, 0xff, 0xff, 0xff), |
| 9203 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9204 | {USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0xf001, 0xff, 0xff, 0xff), |
| 9205 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9206 | {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x2e2e, 0xff, 0xff, 0xff), |
| 9207 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9208 | {USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0019, 0xff, 0xff, 0xff), |
| 9209 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9210 | {USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0020, 0xff, 0xff, 0xff), |
| 9211 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9212 | {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3307, 0xff, 0xff, 0xff), |
| 9213 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9214 | {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3309, 0xff, 0xff, 0xff), |
| 9215 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9216 | {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330a, 0xff, 0xff, 0xff), |
| 9217 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9218 | {USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2b, 0xff, 0xff, 0xff), |
| 9219 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9220 | {USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x624d, 0xff, 0xff, 0xff), |
| 9221 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9222 | {USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0100, 0xff, 0xff, 0xff), |
| 9223 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9224 | {USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0091, 0xff, 0xff, 0xff), |
| 9225 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9226 | {USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7822, 0xff, 0xff, 0xff), |
| 9227 | .driver_info = (unsigned long)&rtl8192cu_fops}, |
| 9228 | #endif |
| 9229 | { } |
| 9230 | }; |
| 9231 | |
| 9232 | static struct usb_driver rtl8xxxu_driver = { |
| 9233 | .name = DRIVER_NAME, |
| 9234 | .probe = rtl8xxxu_probe, |
| 9235 | .disconnect = rtl8xxxu_disconnect, |
| 9236 | .id_table = dev_table, |
| 9237 | .disable_hub_initiated_lpm = 1, |
| 9238 | }; |
| 9239 | |
| 9240 | static int __init rtl8xxxu_module_init(void) |
| 9241 | { |
| 9242 | int res; |
| 9243 | |
| 9244 | res = usb_register(&rtl8xxxu_driver); |
| 9245 | if (res < 0) |
| 9246 | pr_err(DRIVER_NAME ": usb_register() failed (%i)\n", res); |
| 9247 | |
| 9248 | return res; |
| 9249 | } |
| 9250 | |
| 9251 | static void __exit rtl8xxxu_module_exit(void) |
| 9252 | { |
| 9253 | usb_deregister(&rtl8xxxu_driver); |
| 9254 | } |
| 9255 | |
| 9256 | |
| 9257 | MODULE_DEVICE_TABLE(usb, dev_table); |
| 9258 | |
| 9259 | module_init(rtl8xxxu_module_init); |
| 9260 | module_exit(rtl8xxxu_module_exit); |