653-0025-rtl8xxxu-Add-PHY-IQ-calibration-code-for-8188eu.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. From 9a3c53da5228607375ab69d6e3cbc375f18a4f82 Mon Sep 17 00:00:00 2001
  2. From: Jes Sorensen <Jes.Sorensen@redhat.com>
  3. Date: Thu, 21 Jul 2016 17:25:56 -0400
  4. Subject: [PATCH] rtl8xxxu: Add PHY IQ calibration code for 8188eu
  5. The vendor driver for 8188eu is a bizarre modern style code for path A
  6. and old-style code for path B. Most likely because the 8188eu is a
  7. 1T1R part which never gets to the path B code.
  8. Eventually we should look into unifying all the IQ calibration code.
  9. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
  10. ---
  11. .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c | 489 +++++++++++++++++++++
  12. 1 file changed, 489 insertions(+)
  13. --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
  14. +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
  15. @@ -384,6 +384,494 @@ static int rtl8188eu_init_phy_rf(struct
  16. return ret;
  17. }
  18. +static int rtl8188eu_iqk_path_a(struct rtl8xxxu_priv *priv)
  19. +{
  20. + u32 reg_eac, reg_e94, reg_e9c;
  21. + int result = 0;
  22. +
  23. + /* Path A IQK setting */
  24. + rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1c);
  25. + rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x30008c1c);
  26. +
  27. + rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x8214032a);
  28. + rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28160000);
  29. +
  30. + /* LO calibration setting */
  31. + rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x00462911);
  32. +
  33. + /* One shot, path A LOK & IQK */
  34. + rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
  35. + rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
  36. +
  37. + mdelay(10);
  38. +
  39. + /* Check failed */
  40. + reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
  41. + reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
  42. + reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
  43. +
  44. + if (!(reg_eac & BIT(28)) &&
  45. + ((reg_e94 & 0x03ff0000) != 0x01420000) &&
  46. + ((reg_e9c & 0x03ff0000) != 0x00420000))
  47. + result |= 0x01;
  48. +
  49. + return result;
  50. +}
  51. +
  52. +static int rtl8188eu_rx_iqk_path_a(struct rtl8xxxu_priv *priv)
  53. +{
  54. + u32 reg_ea4, reg_eac, reg_e94, reg_e9c, val32;
  55. + int result = 0;
  56. +
  57. + /* Leave IQK mode */
  58. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x00);
  59. +
  60. + /* Enable path A PA in TX IQK mode */
  61. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0x800a0);
  62. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
  63. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0000f);
  64. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf117b);
  65. +
  66. + /* PA/PAD control by 0x56, and set = 0x0 */
  67. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x00980);
  68. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_56, 0x51000);
  69. +
  70. + /* Enter IQK mode */
  71. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
  72. +
  73. + /* TX IQK setting */
  74. + rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
  75. + rtl8xxxu_write32(priv, REG_RX_IQK, 0x81004800);
  76. +
  77. + /* path-A IQK setting */
  78. + rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1c);
  79. + rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x30008c1c);
  80. +
  81. + rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82160c1f);
  82. + rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28160000);
  83. +
  84. + /* LO calibration setting */
  85. + rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a911);
  86. +
  87. + /* One shot, path A LOK & IQK */
  88. + rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
  89. + rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
  90. +
  91. + mdelay(10);
  92. +
  93. + /* Check failed */
  94. + reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
  95. + reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
  96. + reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
  97. +
  98. + if (!(reg_eac & BIT(28)) &&
  99. + ((reg_e94 & 0x03ff0000) != 0x01420000) &&
  100. + ((reg_e9c & 0x03ff0000) != 0x00420000)) {
  101. + result |= 0x01;
  102. + } else {
  103. + /* PA/PAD controlled by 0x0 */
  104. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x00000000);
  105. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x180);
  106. + goto out;
  107. + }
  108. +
  109. + val32 = 0x80007c00 |
  110. + (reg_e94 & 0x03ff0000) | ((reg_e9c >> 16) & 0x03ff);
  111. + rtl8xxxu_write32(priv, REG_TX_IQK, val32);
  112. +
  113. + /* Modify RX IQK mode table */
  114. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x00000000);
  115. +
  116. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0x800a0);
  117. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0x30000);
  118. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0x0000f);
  119. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0xf7ffa);
  120. +
  121. + /* Enter IQK mode */
  122. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
  123. +
  124. + /* IQK setting */
  125. + rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
  126. +
  127. + /* Path A IQK setting */
  128. + rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x38008c1c);
  129. + rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x18008c1c);
  130. +
  131. + rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82160c05);
  132. + rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0x28160c1f);
  133. +
  134. + /* LO calibration setting */
  135. + rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x0046a911);
  136. +
  137. + /* One shot, path A LOK & IQK */
  138. + rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
  139. + rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
  140. +
  141. + mdelay(10);
  142. +
  143. + reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
  144. + reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
  145. +
  146. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x00000000);
  147. + rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_UNKNOWN_DF, 0x180);
  148. +
  149. + if (!(reg_eac & BIT(27)) &&
  150. + ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
  151. + ((reg_eac & 0x03ff0000) != 0x00360000))
  152. + result |= 0x02;
  153. + else
  154. + dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n",
  155. + __func__);
  156. +
  157. +out:
  158. + return result;
  159. +}
  160. +
  161. +static int rtl8188eu_iqk_path_b(struct rtl8xxxu_priv *priv)
  162. +{
  163. + u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
  164. + int result = 0;
  165. +
  166. + rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
  167. + rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
  168. +
  169. + mdelay(1);
  170. +
  171. + /* Check failed */
  172. + reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
  173. + reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
  174. + reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
  175. + reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
  176. + reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
  177. +
  178. + if (!(reg_eac & BIT(31)) &&
  179. + ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
  180. + ((reg_ebc & 0x03ff0000) != 0x00420000))
  181. + result |= 0x01;
  182. + else
  183. + dev_warn(&priv->udev->dev, "%s: Path B IQK failed!\n",
  184. + __func__);
  185. +
  186. + if (!(reg_eac & BIT(30)) &&
  187. + ((reg_ec4 & 0x03ff0000) != 0x01320000) &&
  188. + ((reg_ecc & 0x03ff0000) != 0x00360000))
  189. + result |= 0x01;
  190. + else
  191. + dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
  192. + __func__);
  193. +
  194. + return result;
  195. +}
  196. +
  197. +static void rtl8188eu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
  198. + int result[][8], int t)
  199. +{
  200. + struct device *dev = &priv->udev->dev;
  201. + u32 i, val32;
  202. + int path_a_ok, path_b_ok;
  203. + int retry = 2;
  204. + const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
  205. + REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
  206. + REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
  207. + REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
  208. + REG_TX_OFDM_BBON, REG_TX_TO_RX,
  209. + REG_TX_TO_TX, REG_RX_CCK,
  210. + REG_RX_OFDM, REG_RX_WAIT_RIFS,
  211. + REG_RX_TO_RX, REG_STANDBY,
  212. + REG_SLEEP, REG_PMPD_ANAEN
  213. + };
  214. + const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
  215. + REG_TXPAUSE, REG_BEACON_CTRL,
  216. + REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
  217. + };
  218. + const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
  219. + REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
  220. + REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
  221. + REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
  222. + REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
  223. + };
  224. +
  225. + /*
  226. + * Note: IQ calibration must be performed after loading
  227. + * PHY_REG.txt , and radio_a, radio_b.txt
  228. + */
  229. +
  230. + if (t == 0) {
  231. + /* Save ADDA parameters, turn Path A ADDA on */
  232. + rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
  233. + RTL8XXXU_ADDA_REGS);
  234. + rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
  235. + rtl8xxxu_save_regs(priv, iqk_bb_regs,
  236. + priv->bb_backup, RTL8XXXU_BB_REGS);
  237. + }
  238. +
  239. + rtl8xxxu_path_adda_on(priv, adda_regs, true);
  240. +
  241. + if (t == 0) {
  242. + val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1);
  243. + if (val32 & FPGA0_HSSI_PARM1_PI)
  244. + priv->pi_enabled = 1;
  245. + }
  246. +
  247. + if (!priv->pi_enabled) {
  248. + /* Switch BB to PI mode to do IQ Calibration. */
  249. + rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0x01000100);
  250. + rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0x01000100);
  251. + }
  252. +
  253. + val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
  254. + val32 &= ~FPGA_RF_MODE_CCK;
  255. + rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
  256. +
  257. + rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
  258. + rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
  259. + rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
  260. +
  261. + if (!priv->no_pape) {
  262. + val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
  263. + val32 |= (FPGA0_RF_PAPE |
  264. + (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
  265. + rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
  266. + }
  267. +
  268. + val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
  269. + val32 &= ~BIT(10);
  270. + rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
  271. + val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
  272. + val32 &= ~BIT(10);
  273. + rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
  274. +
  275. + if (priv->tx_paths > 1) {
  276. + rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
  277. + rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, 0x00010000);
  278. + }
  279. +
  280. + /* MAC settings */
  281. + rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
  282. +
  283. + /* Page B init */
  284. + rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x0f600000);
  285. +
  286. + if (priv->tx_paths > 1)
  287. + rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x0f600000);
  288. +
  289. + /* IQ calibration setting */
  290. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
  291. + rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
  292. + rtl8xxxu_write32(priv, REG_RX_IQK, 0x81004800);
  293. +
  294. + for (i = 0; i < retry; i++) {
  295. + path_a_ok = rtl8188eu_iqk_path_a(priv);
  296. + if (path_a_ok == 0x01) {
  297. + val32 = rtl8xxxu_read32(priv,
  298. + REG_TX_POWER_BEFORE_IQK_A);
  299. + result[t][0] = (val32 >> 16) & 0x3ff;
  300. + val32 = rtl8xxxu_read32(priv,
  301. + REG_TX_POWER_AFTER_IQK_A);
  302. + result[t][1] = (val32 >> 16) & 0x3ff;
  303. + break;
  304. + }
  305. + }
  306. +
  307. + if (!path_a_ok)
  308. + dev_dbg(dev, "%s: Path A TX IQK failed!\n", __func__);
  309. +
  310. + for (i = 0; i < retry; i++) {
  311. + path_a_ok = rtl8188eu_rx_iqk_path_a(priv);
  312. + if (path_a_ok == 0x03) {
  313. + val32 = rtl8xxxu_read32(priv,
  314. + REG_RX_POWER_BEFORE_IQK_A_2);
  315. + result[t][2] = (val32 >> 16) & 0x3ff;
  316. + val32 = rtl8xxxu_read32(priv,
  317. + REG_RX_POWER_AFTER_IQK_A_2);
  318. + result[t][3] = (val32 >> 16) & 0x3ff;
  319. +
  320. + break;
  321. + }
  322. + }
  323. +
  324. + if (!path_a_ok)
  325. + dev_dbg(dev, "%s: Path A RX IQK failed!\n", __func__);
  326. +
  327. + /*
  328. + * Path B calibration code in the vendor driver seems to be
  329. + * old style and not updated for the 8188eu since it's a 1T1R
  330. + * part. Keeping the code here in sync with the vendor code
  331. + * to not divert unncessarily, but probably would be good to
  332. + * look into modernizing all the code including that for the
  333. + * old gen1 devices
  334. + */
  335. + if (priv->tx_paths > 1) {
  336. + /*
  337. + * Path A into standby
  338. + */
  339. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x0);
  340. + rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
  341. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
  342. +
  343. + /* Turn Path B ADDA on */
  344. + rtl8xxxu_path_adda_on(priv, adda_regs, false);
  345. +
  346. + for (i = 0; i < retry; i++) {
  347. + path_b_ok = rtl8188eu_iqk_path_b(priv);
  348. + if (path_b_ok == 0x03) {
  349. + val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
  350. + result[t][4] = (val32 >> 16) & 0x3ff;
  351. + val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
  352. + result[t][5] = (val32 >> 16) & 0x3ff;
  353. + val32 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
  354. + result[t][6] = (val32 >> 16) & 0x3ff;
  355. + val32 = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
  356. + result[t][7] = (val32 >> 16) & 0x3ff;
  357. + break;
  358. + } else if (i == (retry - 1) && path_b_ok == 0x01) {
  359. + /* TX IQK OK */
  360. + val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
  361. + result[t][4] = (val32 >> 16) & 0x3ff;
  362. + val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
  363. + result[t][5] = (val32 >> 16) & 0x3ff;
  364. + }
  365. + }
  366. +
  367. + if (!path_b_ok)
  368. + dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
  369. + }
  370. +
  371. + /* Back to BB mode, load original value */
  372. + rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0);
  373. +
  374. + if (t) {
  375. + if (!priv->pi_enabled) {
  376. + /*
  377. + * Switch back BB to SI mode after finishing
  378. + * IQ Calibration
  379. + */
  380. + val32 = 0x01000000;
  381. + rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, val32);
  382. + rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, val32);
  383. + }
  384. +
  385. + /* Reload ADDA power saving parameters */
  386. + rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
  387. + RTL8XXXU_ADDA_REGS);
  388. +
  389. + /* Reload MAC parameters */
  390. + rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
  391. +
  392. + /* Reload BB parameters */
  393. + rtl8xxxu_restore_regs(priv, iqk_bb_regs,
  394. + priv->bb_backup, RTL8XXXU_BB_REGS);
  395. +
  396. + /* Restore RX initial gain */
  397. + rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00032ed3);
  398. +
  399. + if (priv->tx_paths > 1) {
  400. + rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM,
  401. + 0x00032ed3);
  402. + }
  403. +
  404. + /* Load 0xe30 IQC default value */
  405. + rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
  406. + rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
  407. + }
  408. +}
  409. +
  410. +static void rtl8188eu_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
  411. +{
  412. + struct device *dev = &priv->udev->dev;
  413. + int result[4][8]; /* last is final result */
  414. + int i, candidate;
  415. + bool path_a_ok, path_b_ok;
  416. + u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
  417. + u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
  418. + bool simu;
  419. +
  420. + memset(result, 0, sizeof(result));
  421. + result[3][0] = 0x100;
  422. + result[3][2] = 0x100;
  423. + result[3][4] = 0x100;
  424. + result[3][6] = 0x100;
  425. +
  426. + candidate = -1;
  427. +
  428. + path_a_ok = false;
  429. + path_b_ok = false;
  430. +
  431. + for (i = 0; i < 3; i++) {
  432. + rtl8188eu_phy_iqcalibrate(priv, result, i);
  433. +
  434. + if (i == 1) {
  435. + simu = rtl8xxxu_gen2_simularity_compare(priv,
  436. + result, 0, 1);
  437. + if (simu) {
  438. + candidate = 0;
  439. + break;
  440. + }
  441. + }
  442. +
  443. + if (i == 2) {
  444. + simu = rtl8xxxu_gen2_simularity_compare(priv,
  445. + result, 0, 2);
  446. + if (simu) {
  447. + candidate = 0;
  448. + break;
  449. + }
  450. +
  451. + simu = rtl8xxxu_gen2_simularity_compare(priv,
  452. + result, 1, 2);
  453. + if (simu)
  454. + candidate = 1;
  455. + else
  456. + candidate = 3;
  457. + }
  458. + }
  459. +
  460. + for (i = 0; i < 4; i++) {
  461. + reg_e94 = result[i][0];
  462. + reg_e9c = result[i][1];
  463. + reg_ea4 = result[i][2];
  464. + reg_eb4 = result[i][4];
  465. + reg_ebc = result[i][5];
  466. + reg_ec4 = result[i][6];
  467. + }
  468. +
  469. + if (candidate >= 0) {
  470. + reg_e94 = result[candidate][0];
  471. + priv->rege94 = reg_e94;
  472. + reg_e9c = result[candidate][1];
  473. + priv->rege9c = reg_e9c;
  474. + reg_ea4 = result[candidate][2];
  475. + reg_eac = result[candidate][3];
  476. + reg_eb4 = result[candidate][4];
  477. + priv->regeb4 = reg_eb4;
  478. + reg_ebc = result[candidate][5];
  479. + priv->regebc = reg_ebc;
  480. + reg_ec4 = result[candidate][6];
  481. + reg_ecc = result[candidate][7];
  482. + dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
  483. + dev_dbg(dev,
  484. + "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
  485. + "ecc=%x\n ", __func__, reg_e94, reg_e9c,
  486. + reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
  487. + path_a_ok = true;
  488. + path_b_ok = true;
  489. + } else {
  490. + reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
  491. + reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
  492. + }
  493. +
  494. + if (reg_e94 && candidate >= 0)
  495. + rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
  496. + candidate, (reg_ea4 == 0));
  497. +
  498. + if (priv->rf_paths > 1 && reg_eb4)
  499. + rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
  500. + candidate, (reg_ec4 == 0));
  501. +
  502. + rtl8xxxu_save_regs(priv, rtl8xxxu_iqk_phy_iq_bb_reg,
  503. + priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
  504. +}
  505. +
  506. static void rtl8188e_disabled_to_emu(struct rtl8xxxu_priv *priv)
  507. {
  508. u16 val16;
  509. @@ -520,6 +1008,7 @@ struct rtl8xxxu_fileops rtl8188eu_fops =
  510. .llt_init = rtl8xxxu_auto_llt_table,
  511. .init_phy_bb = rtl8188eu_init_phy_bb,
  512. .init_phy_rf = rtl8188eu_init_phy_rf,
  513. + .phy_iq_calibrate = rtl8188eu_phy_iq_calibrate,
  514. .parse_rx_desc = rtl8xxxu_parse_rxdesc16,
  515. .usb_quirks = rtl8188e_usb_quirks,
  516. .writeN_block_size = 128,