/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_lcn.c

http://github.com/mirrors/linux · C · 5247 lines · 4300 code · 931 blank · 16 comment · 485 complexity · 67242b860323bdcb4c12983832a1319f MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/delay.h>
  18. #include <linux/cordic.h>
  19. #include <pmu.h>
  20. #include <d11.h>
  21. #include <phy_shim.h>
  22. #include "phy_qmath.h"
  23. #include "phy_hal.h"
  24. #include "phy_radio.h"
  25. #include "phytbl_lcn.h"
  26. #include "phy_lcn.h"
  27. #define PLL_2064_NDIV 90
  28. #define PLL_2064_LOW_END_VCO 3000
  29. #define PLL_2064_LOW_END_KVCO 27
  30. #define PLL_2064_HIGH_END_VCO 4200
  31. #define PLL_2064_HIGH_END_KVCO 68
  32. #define PLL_2064_LOOP_BW_DOUBLER 200
  33. #define PLL_2064_D30_DOUBLER 10500
  34. #define PLL_2064_LOOP_BW 260
  35. #define PLL_2064_D30 8000
  36. #define PLL_2064_CAL_REF_TO 8
  37. #define PLL_2064_MHZ 1000000
  38. #define PLL_2064_OPEN_LOOP_DELAY 5
  39. #define TEMPSENSE 1
  40. #define VBATSENSE 2
  41. #define NOISE_IF_UPD_CHK_INTERVAL 1
  42. #define NOISE_IF_UPD_RST_INTERVAL 60
  43. #define NOISE_IF_UPD_THRESHOLD_CNT 1
  44. #define NOISE_IF_UPD_TRHRESHOLD 50
  45. #define NOISE_IF_UPD_TIMEOUT 1000
  46. #define NOISE_IF_OFF 0
  47. #define NOISE_IF_CHK 1
  48. #define NOISE_IF_ON 2
  49. #define PAPD_BLANKING_PROFILE 3
  50. #define PAPD2LUT 0
  51. #define PAPD_CORR_NORM 0
  52. #define PAPD_BLANKING_THRESHOLD 0
  53. #define PAPD_STOP_AFTER_LAST_UPDATE 0
  54. #define LCN_TARGET_PWR 60
  55. #define LCN_VBAT_OFFSET_433X 34649679
  56. #define LCN_VBAT_SLOPE_433X 8258032
  57. #define LCN_VBAT_SCALE_NOM 53
  58. #define LCN_VBAT_SCALE_DEN 432
  59. #define LCN_TEMPSENSE_OFFSET 80812
  60. #define LCN_TEMPSENSE_DEN 2647
  61. #define LCN_BW_LMT 200
  62. #define LCN_CUR_LMT 1250
  63. #define LCN_MULT 1
  64. #define LCN_VCO_DIV 30
  65. #define LCN_OFFSET 680
  66. #define LCN_FACT 490
  67. #define LCN_CUR_DIV 2640
  68. #define LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT \
  69. (0 + 8)
  70. #define LCNPHY_txgainctrlovrval1_pagain_ovr_val1_MASK \
  71. (0x7f << LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT)
  72. #define LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT \
  73. (0 + 8)
  74. #define LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_MASK \
  75. (0x7f << LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT)
  76. #define wlc_lcnphy_enable_tx_gain_override(pi) \
  77. wlc_lcnphy_set_tx_gain_override(pi, true)
  78. #define wlc_lcnphy_disable_tx_gain_override(pi) \
  79. wlc_lcnphy_set_tx_gain_override(pi, false)
  80. #define wlc_lcnphy_iqcal_active(pi) \
  81. (read_phy_reg((pi), 0x451) & \
  82. ((0x1 << 15) | (0x1 << 14)))
  83. #define txpwrctrl_off(pi) (0x7 != ((read_phy_reg(pi, 0x4a4) & 0xE000) >> 13))
  84. #define wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi) \
  85. (pi->temppwrctrl_capable)
  86. #define wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi) \
  87. (pi->hwpwrctrl_capable)
  88. #define SWCTRL_BT_TX 0x18
  89. #define SWCTRL_OVR_DISABLE 0x40
  90. #define AFE_CLK_INIT_MODE_TXRX2X 1
  91. #define AFE_CLK_INIT_MODE_PAPD 0
  92. #define LCNPHY_TBL_ID_IQLOCAL 0x00
  93. #define LCNPHY_TBL_ID_RFSEQ 0x08
  94. #define LCNPHY_TBL_ID_GAIN_IDX 0x0d
  95. #define LCNPHY_TBL_ID_SW_CTRL 0x0f
  96. #define LCNPHY_TBL_ID_GAIN_TBL 0x12
  97. #define LCNPHY_TBL_ID_SPUR 0x14
  98. #define LCNPHY_TBL_ID_SAMPLEPLAY 0x15
  99. #define LCNPHY_TBL_ID_SAMPLEPLAY1 0x16
  100. #define LCNPHY_TX_PWR_CTRL_RATE_OFFSET 832
  101. #define LCNPHY_TX_PWR_CTRL_MAC_OFFSET 128
  102. #define LCNPHY_TX_PWR_CTRL_GAIN_OFFSET 192
  103. #define LCNPHY_TX_PWR_CTRL_IQ_OFFSET 320
  104. #define LCNPHY_TX_PWR_CTRL_LO_OFFSET 448
  105. #define LCNPHY_TX_PWR_CTRL_PWR_OFFSET 576
  106. #define LCNPHY_TX_PWR_CTRL_START_INDEX_2G_4313 140
  107. #define LCNPHY_TX_PWR_CTRL_START_NPT 1
  108. #define LCNPHY_TX_PWR_CTRL_MAX_NPT 7
  109. #define LCNPHY_NOISE_SAMPLES_DEFAULT 5000
  110. #define LCNPHY_ACI_DETECT_START 1
  111. #define LCNPHY_ACI_DETECT_PROGRESS 2
  112. #define LCNPHY_ACI_DETECT_STOP 3
  113. #define LCNPHY_ACI_CRSHIFRMLO_TRSH 100
  114. #define LCNPHY_ACI_GLITCH_TRSH 2000
  115. #define LCNPHY_ACI_TMOUT 250
  116. #define LCNPHY_ACI_DETECT_TIMEOUT 2
  117. #define LCNPHY_ACI_START_DELAY 0
  118. #define wlc_lcnphy_tx_gain_override_enabled(pi) \
  119. (0 != (read_phy_reg((pi), 0x43b) & (0x1 << 6)))
  120. #define wlc_lcnphy_total_tx_frames(pi) \
  121. wlapi_bmac_read_shm((pi)->sh->physhim, M_UCODE_MACSTAT + \
  122. offsetof(struct macstat, txallfrm))
  123. struct lcnphy_txgains {
  124. u16 gm_gain;
  125. u16 pga_gain;
  126. u16 pad_gain;
  127. u16 dac_gain;
  128. };
  129. enum lcnphy_cal_mode {
  130. LCNPHY_CAL_FULL,
  131. LCNPHY_CAL_RECAL,
  132. LCNPHY_CAL_CURRECAL,
  133. LCNPHY_CAL_DIGCAL,
  134. LCNPHY_CAL_GCTRL
  135. };
  136. struct lcnphy_rx_iqcomp {
  137. u8 chan;
  138. s16 a;
  139. s16 b;
  140. };
  141. struct lcnphy_spb_tone {
  142. s16 re;
  143. s16 im;
  144. };
  145. struct lcnphy_unsign16_struct {
  146. u16 re;
  147. u16 im;
  148. };
  149. struct lcnphy_iq_est {
  150. u32 iq_prod;
  151. u32 i_pwr;
  152. u32 q_pwr;
  153. };
  154. struct lcnphy_sfo_cfg {
  155. u16 ptcentreTs20;
  156. u16 ptcentreFactor;
  157. };
  158. enum lcnphy_papd_cal_type {
  159. LCNPHY_PAPD_CAL_CW,
  160. LCNPHY_PAPD_CAL_OFDM
  161. };
  162. typedef u16 iqcal_gain_params_lcnphy[9];
  163. static const iqcal_gain_params_lcnphy tbl_iqcal_gainparams_lcnphy_2G[] = {
  164. {0, 0, 0, 0, 0, 0, 0, 0, 0},
  165. };
  166. static const iqcal_gain_params_lcnphy *tbl_iqcal_gainparams_lcnphy[1] = {
  167. tbl_iqcal_gainparams_lcnphy_2G,
  168. };
  169. static const u16 iqcal_gainparams_numgains_lcnphy[1] = {
  170. ARRAY_SIZE(tbl_iqcal_gainparams_lcnphy_2G),
  171. };
  172. static const struct lcnphy_sfo_cfg lcnphy_sfo_cfg[] = {
  173. {965, 1087},
  174. {967, 1085},
  175. {969, 1082},
  176. {971, 1080},
  177. {973, 1078},
  178. {975, 1076},
  179. {977, 1073},
  180. {979, 1071},
  181. {981, 1069},
  182. {983, 1067},
  183. {985, 1065},
  184. {987, 1063},
  185. {989, 1060},
  186. {994, 1055}
  187. };
  188. static const
  189. u16 lcnphy_iqcal_loft_gainladder[] = {
  190. ((2 << 8) | 0),
  191. ((3 << 8) | 0),
  192. ((4 << 8) | 0),
  193. ((6 << 8) | 0),
  194. ((8 << 8) | 0),
  195. ((11 << 8) | 0),
  196. ((16 << 8) | 0),
  197. ((16 << 8) | 1),
  198. ((16 << 8) | 2),
  199. ((16 << 8) | 3),
  200. ((16 << 8) | 4),
  201. ((16 << 8) | 5),
  202. ((16 << 8) | 6),
  203. ((16 << 8) | 7),
  204. ((23 << 8) | 7),
  205. ((32 << 8) | 7),
  206. ((45 << 8) | 7),
  207. ((64 << 8) | 7),
  208. ((91 << 8) | 7),
  209. ((128 << 8) | 7)
  210. };
  211. static const
  212. u16 lcnphy_iqcal_ir_gainladder[] = {
  213. ((1 << 8) | 0),
  214. ((2 << 8) | 0),
  215. ((4 << 8) | 0),
  216. ((6 << 8) | 0),
  217. ((8 << 8) | 0),
  218. ((11 << 8) | 0),
  219. ((16 << 8) | 0),
  220. ((23 << 8) | 0),
  221. ((32 << 8) | 0),
  222. ((45 << 8) | 0),
  223. ((64 << 8) | 0),
  224. ((64 << 8) | 1),
  225. ((64 << 8) | 2),
  226. ((64 << 8) | 3),
  227. ((64 << 8) | 4),
  228. ((64 << 8) | 5),
  229. ((64 << 8) | 6),
  230. ((64 << 8) | 7),
  231. ((91 << 8) | 7),
  232. ((128 << 8) | 7)
  233. };
  234. static const
  235. struct lcnphy_spb_tone lcnphy_spb_tone_3750[] = {
  236. {88, 0},
  237. {73, 49},
  238. {34, 81},
  239. {-17, 86},
  240. {-62, 62},
  241. {-86, 17},
  242. {-81, -34},
  243. {-49, -73},
  244. {0, -88},
  245. {49, -73},
  246. {81, -34},
  247. {86, 17},
  248. {62, 62},
  249. {17, 86},
  250. {-34, 81},
  251. {-73, 49},
  252. {-88, 0},
  253. {-73, -49},
  254. {-34, -81},
  255. {17, -86},
  256. {62, -62},
  257. {86, -17},
  258. {81, 34},
  259. {49, 73},
  260. {0, 88},
  261. {-49, 73},
  262. {-81, 34},
  263. {-86, -17},
  264. {-62, -62},
  265. {-17, -86},
  266. {34, -81},
  267. {73, -49},
  268. };
  269. static const
  270. u16 iqlo_loopback_rf_regs[20] = {
  271. RADIO_2064_REG036,
  272. RADIO_2064_REG11A,
  273. RADIO_2064_REG03A,
  274. RADIO_2064_REG025,
  275. RADIO_2064_REG028,
  276. RADIO_2064_REG005,
  277. RADIO_2064_REG112,
  278. RADIO_2064_REG0FF,
  279. RADIO_2064_REG11F,
  280. RADIO_2064_REG00B,
  281. RADIO_2064_REG113,
  282. RADIO_2064_REG007,
  283. RADIO_2064_REG0FC,
  284. RADIO_2064_REG0FD,
  285. RADIO_2064_REG012,
  286. RADIO_2064_REG057,
  287. RADIO_2064_REG059,
  288. RADIO_2064_REG05C,
  289. RADIO_2064_REG078,
  290. RADIO_2064_REG092,
  291. };
  292. static const
  293. u16 tempsense_phy_regs[14] = {
  294. 0x503,
  295. 0x4a4,
  296. 0x4d0,
  297. 0x4d9,
  298. 0x4da,
  299. 0x4a6,
  300. 0x938,
  301. 0x939,
  302. 0x4d8,
  303. 0x4d0,
  304. 0x4d7,
  305. 0x4a5,
  306. 0x40d,
  307. 0x4a2,
  308. };
  309. static const
  310. u16 rxiq_cal_rf_reg[11] = {
  311. RADIO_2064_REG098,
  312. RADIO_2064_REG116,
  313. RADIO_2064_REG12C,
  314. RADIO_2064_REG06A,
  315. RADIO_2064_REG00B,
  316. RADIO_2064_REG01B,
  317. RADIO_2064_REG113,
  318. RADIO_2064_REG01D,
  319. RADIO_2064_REG114,
  320. RADIO_2064_REG02E,
  321. RADIO_2064_REG12A,
  322. };
  323. static const
  324. struct lcnphy_rx_iqcomp lcnphy_rx_iqcomp_table_rev0[] = {
  325. {1, 0, 0},
  326. {2, 0, 0},
  327. {3, 0, 0},
  328. {4, 0, 0},
  329. {5, 0, 0},
  330. {6, 0, 0},
  331. {7, 0, 0},
  332. {8, 0, 0},
  333. {9, 0, 0},
  334. {10, 0, 0},
  335. {11, 0, 0},
  336. {12, 0, 0},
  337. {13, 0, 0},
  338. {14, 0, 0},
  339. {34, 0, 0},
  340. {38, 0, 0},
  341. {42, 0, 0},
  342. {46, 0, 0},
  343. {36, 0, 0},
  344. {40, 0, 0},
  345. {44, 0, 0},
  346. {48, 0, 0},
  347. {52, 0, 0},
  348. {56, 0, 0},
  349. {60, 0, 0},
  350. {64, 0, 0},
  351. {100, 0, 0},
  352. {104, 0, 0},
  353. {108, 0, 0},
  354. {112, 0, 0},
  355. {116, 0, 0},
  356. {120, 0, 0},
  357. {124, 0, 0},
  358. {128, 0, 0},
  359. {132, 0, 0},
  360. {136, 0, 0},
  361. {140, 0, 0},
  362. {149, 0, 0},
  363. {153, 0, 0},
  364. {157, 0, 0},
  365. {161, 0, 0},
  366. {165, 0, 0},
  367. {184, 0, 0},
  368. {188, 0, 0},
  369. {192, 0, 0},
  370. {196, 0, 0},
  371. {200, 0, 0},
  372. {204, 0, 0},
  373. {208, 0, 0},
  374. {212, 0, 0},
  375. {216, 0, 0},
  376. };
  377. static const u32 lcnphy_23bitgaincode_table[] = {
  378. 0x200100,
  379. 0x200200,
  380. 0x200004,
  381. 0x200014,
  382. 0x200024,
  383. 0x200034,
  384. 0x200134,
  385. 0x200234,
  386. 0x200334,
  387. 0x200434,
  388. 0x200037,
  389. 0x200137,
  390. 0x200237,
  391. 0x200337,
  392. 0x200437,
  393. 0x000035,
  394. 0x000135,
  395. 0x000235,
  396. 0x000037,
  397. 0x000137,
  398. 0x000237,
  399. 0x000337,
  400. 0x00013f,
  401. 0x00023f,
  402. 0x00033f,
  403. 0x00034f,
  404. 0x00044f,
  405. 0x00144f,
  406. 0x00244f,
  407. 0x00254f,
  408. 0x00354f,
  409. 0x00454f,
  410. 0x00464f,
  411. 0x01464f,
  412. 0x02464f,
  413. 0x03464f,
  414. 0x04464f,
  415. };
  416. static const s8 lcnphy_gain_table[] = {
  417. -16,
  418. -13,
  419. 10,
  420. 7,
  421. 4,
  422. 0,
  423. 3,
  424. 6,
  425. 9,
  426. 12,
  427. 15,
  428. 18,
  429. 21,
  430. 24,
  431. 27,
  432. 30,
  433. 33,
  434. 36,
  435. 39,
  436. 42,
  437. 45,
  438. 48,
  439. 50,
  440. 53,
  441. 56,
  442. 59,
  443. 62,
  444. 65,
  445. 68,
  446. 71,
  447. 74,
  448. 77,
  449. 80,
  450. 83,
  451. 86,
  452. 89,
  453. 92,
  454. };
  455. static const s8 lcnphy_gain_index_offset_for_rssi[] = {
  456. 7,
  457. 7,
  458. 7,
  459. 7,
  460. 7,
  461. 7,
  462. 7,
  463. 8,
  464. 7,
  465. 7,
  466. 6,
  467. 7,
  468. 7,
  469. 4,
  470. 4,
  471. 4,
  472. 4,
  473. 4,
  474. 4,
  475. 4,
  476. 4,
  477. 3,
  478. 3,
  479. 3,
  480. 3,
  481. 3,
  482. 3,
  483. 4,
  484. 2,
  485. 2,
  486. 2,
  487. 2,
  488. 2,
  489. 2,
  490. -1,
  491. -2,
  492. -2,
  493. -2
  494. };
  495. struct chan_info_2064_lcnphy {
  496. uint chan;
  497. uint freq;
  498. u8 logen_buftune;
  499. u8 logen_rccr_tx;
  500. u8 txrf_mix_tune_ctrl;
  501. u8 pa_input_tune_g;
  502. u8 logen_rccr_rx;
  503. u8 pa_rxrf_lna1_freq_tune;
  504. u8 pa_rxrf_lna2_freq_tune;
  505. u8 rxrf_rxrf_spare1;
  506. };
  507. static const struct chan_info_2064_lcnphy chan_info_2064_lcnphy[] = {
  508. {1, 2412, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  509. {2, 2417, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  510. {3, 2422, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  511. {4, 2427, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  512. {5, 2432, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  513. {6, 2437, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  514. {7, 2442, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  515. {8, 2447, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  516. {9, 2452, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  517. {10, 2457, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  518. {11, 2462, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  519. {12, 2467, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  520. {13, 2472, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  521. {14, 2484, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  522. };
  523. static const struct lcnphy_radio_regs lcnphy_radio_regs_2064[] = {
  524. {0x00, 0, 0, 0, 0},
  525. {0x01, 0x64, 0x64, 0, 0},
  526. {0x02, 0x20, 0x20, 0, 0},
  527. {0x03, 0x66, 0x66, 0, 0},
  528. {0x04, 0xf8, 0xf8, 0, 0},
  529. {0x05, 0, 0, 0, 0},
  530. {0x06, 0x10, 0x10, 0, 0},
  531. {0x07, 0, 0, 0, 0},
  532. {0x08, 0, 0, 0, 0},
  533. {0x09, 0, 0, 0, 0},
  534. {0x0A, 0x37, 0x37, 0, 0},
  535. {0x0B, 0x6, 0x6, 0, 0},
  536. {0x0C, 0x55, 0x55, 0, 0},
  537. {0x0D, 0x8b, 0x8b, 0, 0},
  538. {0x0E, 0, 0, 0, 0},
  539. {0x0F, 0x5, 0x5, 0, 0},
  540. {0x10, 0, 0, 0, 0},
  541. {0x11, 0xe, 0xe, 0, 0},
  542. {0x12, 0, 0, 0, 0},
  543. {0x13, 0xb, 0xb, 0, 0},
  544. {0x14, 0x2, 0x2, 0, 0},
  545. {0x15, 0x12, 0x12, 0, 0},
  546. {0x16, 0x12, 0x12, 0, 0},
  547. {0x17, 0xc, 0xc, 0, 0},
  548. {0x18, 0xc, 0xc, 0, 0},
  549. {0x19, 0xc, 0xc, 0, 0},
  550. {0x1A, 0x8, 0x8, 0, 0},
  551. {0x1B, 0x2, 0x2, 0, 0},
  552. {0x1C, 0, 0, 0, 0},
  553. {0x1D, 0x1, 0x1, 0, 0},
  554. {0x1E, 0x12, 0x12, 0, 0},
  555. {0x1F, 0x6e, 0x6e, 0, 0},
  556. {0x20, 0x2, 0x2, 0, 0},
  557. {0x21, 0x23, 0x23, 0, 0},
  558. {0x22, 0x8, 0x8, 0, 0},
  559. {0x23, 0, 0, 0, 0},
  560. {0x24, 0, 0, 0, 0},
  561. {0x25, 0xc, 0xc, 0, 0},
  562. {0x26, 0x33, 0x33, 0, 0},
  563. {0x27, 0x55, 0x55, 0, 0},
  564. {0x28, 0, 0, 0, 0},
  565. {0x29, 0x30, 0x30, 0, 0},
  566. {0x2A, 0xb, 0xb, 0, 0},
  567. {0x2B, 0x1b, 0x1b, 0, 0},
  568. {0x2C, 0x3, 0x3, 0, 0},
  569. {0x2D, 0x1b, 0x1b, 0, 0},
  570. {0x2E, 0, 0, 0, 0},
  571. {0x2F, 0x20, 0x20, 0, 0},
  572. {0x30, 0xa, 0xa, 0, 0},
  573. {0x31, 0, 0, 0, 0},
  574. {0x32, 0x62, 0x62, 0, 0},
  575. {0x33, 0x19, 0x19, 0, 0},
  576. {0x34, 0x33, 0x33, 0, 0},
  577. {0x35, 0x77, 0x77, 0, 0},
  578. {0x36, 0, 0, 0, 0},
  579. {0x37, 0x70, 0x70, 0, 0},
  580. {0x38, 0x3, 0x3, 0, 0},
  581. {0x39, 0xf, 0xf, 0, 0},
  582. {0x3A, 0x6, 0x6, 0, 0},
  583. {0x3B, 0xcf, 0xcf, 0, 0},
  584. {0x3C, 0x1a, 0x1a, 0, 0},
  585. {0x3D, 0x6, 0x6, 0, 0},
  586. {0x3E, 0x42, 0x42, 0, 0},
  587. {0x3F, 0, 0, 0, 0},
  588. {0x40, 0xfb, 0xfb, 0, 0},
  589. {0x41, 0x9a, 0x9a, 0, 0},
  590. {0x42, 0x7a, 0x7a, 0, 0},
  591. {0x43, 0x29, 0x29, 0, 0},
  592. {0x44, 0, 0, 0, 0},
  593. {0x45, 0x8, 0x8, 0, 0},
  594. {0x46, 0xce, 0xce, 0, 0},
  595. {0x47, 0x27, 0x27, 0, 0},
  596. {0x48, 0x62, 0x62, 0, 0},
  597. {0x49, 0x6, 0x6, 0, 0},
  598. {0x4A, 0x58, 0x58, 0, 0},
  599. {0x4B, 0xf7, 0xf7, 0, 0},
  600. {0x4C, 0, 0, 0, 0},
  601. {0x4D, 0xb3, 0xb3, 0, 0},
  602. {0x4E, 0, 0, 0, 0},
  603. {0x4F, 0x2, 0x2, 0, 0},
  604. {0x50, 0, 0, 0, 0},
  605. {0x51, 0x9, 0x9, 0, 0},
  606. {0x52, 0x5, 0x5, 0, 0},
  607. {0x53, 0x17, 0x17, 0, 0},
  608. {0x54, 0x38, 0x38, 0, 0},
  609. {0x55, 0, 0, 0, 0},
  610. {0x56, 0, 0, 0, 0},
  611. {0x57, 0xb, 0xb, 0, 0},
  612. {0x58, 0, 0, 0, 0},
  613. {0x59, 0, 0, 0, 0},
  614. {0x5A, 0, 0, 0, 0},
  615. {0x5B, 0, 0, 0, 0},
  616. {0x5C, 0, 0, 0, 0},
  617. {0x5D, 0, 0, 0, 0},
  618. {0x5E, 0x88, 0x88, 0, 0},
  619. {0x5F, 0xcc, 0xcc, 0, 0},
  620. {0x60, 0x74, 0x74, 0, 0},
  621. {0x61, 0x74, 0x74, 0, 0},
  622. {0x62, 0x74, 0x74, 0, 0},
  623. {0x63, 0x44, 0x44, 0, 0},
  624. {0x64, 0x77, 0x77, 0, 0},
  625. {0x65, 0x44, 0x44, 0, 0},
  626. {0x66, 0x77, 0x77, 0, 0},
  627. {0x67, 0x55, 0x55, 0, 0},
  628. {0x68, 0x77, 0x77, 0, 0},
  629. {0x69, 0x77, 0x77, 0, 0},
  630. {0x6A, 0, 0, 0, 0},
  631. {0x6B, 0x7f, 0x7f, 0, 0},
  632. {0x6C, 0x8, 0x8, 0, 0},
  633. {0x6D, 0, 0, 0, 0},
  634. {0x6E, 0x88, 0x88, 0, 0},
  635. {0x6F, 0x66, 0x66, 0, 0},
  636. {0x70, 0x66, 0x66, 0, 0},
  637. {0x71, 0x28, 0x28, 0, 0},
  638. {0x72, 0x55, 0x55, 0, 0},
  639. {0x73, 0x4, 0x4, 0, 0},
  640. {0x74, 0, 0, 0, 0},
  641. {0x75, 0, 0, 0, 0},
  642. {0x76, 0, 0, 0, 0},
  643. {0x77, 0x1, 0x1, 0, 0},
  644. {0x78, 0xd6, 0xd6, 0, 0},
  645. {0x79, 0, 0, 0, 0},
  646. {0x7A, 0, 0, 0, 0},
  647. {0x7B, 0, 0, 0, 0},
  648. {0x7C, 0, 0, 0, 0},
  649. {0x7D, 0, 0, 0, 0},
  650. {0x7E, 0, 0, 0, 0},
  651. {0x7F, 0, 0, 0, 0},
  652. {0x80, 0, 0, 0, 0},
  653. {0x81, 0, 0, 0, 0},
  654. {0x82, 0, 0, 0, 0},
  655. {0x83, 0xb4, 0xb4, 0, 0},
  656. {0x84, 0x1, 0x1, 0, 0},
  657. {0x85, 0x20, 0x20, 0, 0},
  658. {0x86, 0x5, 0x5, 0, 0},
  659. {0x87, 0xff, 0xff, 0, 0},
  660. {0x88, 0x7, 0x7, 0, 0},
  661. {0x89, 0x77, 0x77, 0, 0},
  662. {0x8A, 0x77, 0x77, 0, 0},
  663. {0x8B, 0x77, 0x77, 0, 0},
  664. {0x8C, 0x77, 0x77, 0, 0},
  665. {0x8D, 0x8, 0x8, 0, 0},
  666. {0x8E, 0xa, 0xa, 0, 0},
  667. {0x8F, 0x8, 0x8, 0, 0},
  668. {0x90, 0x18, 0x18, 0, 0},
  669. {0x91, 0x5, 0x5, 0, 0},
  670. {0x92, 0x1f, 0x1f, 0, 0},
  671. {0x93, 0x10, 0x10, 0, 0},
  672. {0x94, 0x3, 0x3, 0, 0},
  673. {0x95, 0, 0, 0, 0},
  674. {0x96, 0, 0, 0, 0},
  675. {0x97, 0xaa, 0xaa, 0, 0},
  676. {0x98, 0, 0, 0, 0},
  677. {0x99, 0x23, 0x23, 0, 0},
  678. {0x9A, 0x7, 0x7, 0, 0},
  679. {0x9B, 0xf, 0xf, 0, 0},
  680. {0x9C, 0x10, 0x10, 0, 0},
  681. {0x9D, 0x3, 0x3, 0, 0},
  682. {0x9E, 0x4, 0x4, 0, 0},
  683. {0x9F, 0x20, 0x20, 0, 0},
  684. {0xA0, 0, 0, 0, 0},
  685. {0xA1, 0, 0, 0, 0},
  686. {0xA2, 0, 0, 0, 0},
  687. {0xA3, 0, 0, 0, 0},
  688. {0xA4, 0x1, 0x1, 0, 0},
  689. {0xA5, 0x77, 0x77, 0, 0},
  690. {0xA6, 0x77, 0x77, 0, 0},
  691. {0xA7, 0x77, 0x77, 0, 0},
  692. {0xA8, 0x77, 0x77, 0, 0},
  693. {0xA9, 0x8c, 0x8c, 0, 0},
  694. {0xAA, 0x88, 0x88, 0, 0},
  695. {0xAB, 0x78, 0x78, 0, 0},
  696. {0xAC, 0x57, 0x57, 0, 0},
  697. {0xAD, 0x88, 0x88, 0, 0},
  698. {0xAE, 0, 0, 0, 0},
  699. {0xAF, 0x8, 0x8, 0, 0},
  700. {0xB0, 0x88, 0x88, 0, 0},
  701. {0xB1, 0, 0, 0, 0},
  702. {0xB2, 0x1b, 0x1b, 0, 0},
  703. {0xB3, 0x3, 0x3, 0, 0},
  704. {0xB4, 0x24, 0x24, 0, 0},
  705. {0xB5, 0x3, 0x3, 0, 0},
  706. {0xB6, 0x1b, 0x1b, 0, 0},
  707. {0xB7, 0x24, 0x24, 0, 0},
  708. {0xB8, 0x3, 0x3, 0, 0},
  709. {0xB9, 0, 0, 0, 0},
  710. {0xBA, 0xaa, 0xaa, 0, 0},
  711. {0xBB, 0, 0, 0, 0},
  712. {0xBC, 0x4, 0x4, 0, 0},
  713. {0xBD, 0, 0, 0, 0},
  714. {0xBE, 0x8, 0x8, 0, 0},
  715. {0xBF, 0x11, 0x11, 0, 0},
  716. {0xC0, 0, 0, 0, 0},
  717. {0xC1, 0, 0, 0, 0},
  718. {0xC2, 0x62, 0x62, 0, 0},
  719. {0xC3, 0x1e, 0x1e, 0, 0},
  720. {0xC4, 0x33, 0x33, 0, 0},
  721. {0xC5, 0x37, 0x37, 0, 0},
  722. {0xC6, 0, 0, 0, 0},
  723. {0xC7, 0x70, 0x70, 0, 0},
  724. {0xC8, 0x1e, 0x1e, 0, 0},
  725. {0xC9, 0x6, 0x6, 0, 0},
  726. {0xCA, 0x4, 0x4, 0, 0},
  727. {0xCB, 0x2f, 0x2f, 0, 0},
  728. {0xCC, 0xf, 0xf, 0, 0},
  729. {0xCD, 0, 0, 0, 0},
  730. {0xCE, 0xff, 0xff, 0, 0},
  731. {0xCF, 0x8, 0x8, 0, 0},
  732. {0xD0, 0x3f, 0x3f, 0, 0},
  733. {0xD1, 0x3f, 0x3f, 0, 0},
  734. {0xD2, 0x3f, 0x3f, 0, 0},
  735. {0xD3, 0, 0, 0, 0},
  736. {0xD4, 0, 0, 0, 0},
  737. {0xD5, 0, 0, 0, 0},
  738. {0xD6, 0xcc, 0xcc, 0, 0},
  739. {0xD7, 0, 0, 0, 0},
  740. {0xD8, 0x8, 0x8, 0, 0},
  741. {0xD9, 0x8, 0x8, 0, 0},
  742. {0xDA, 0x8, 0x8, 0, 0},
  743. {0xDB, 0x11, 0x11, 0, 0},
  744. {0xDC, 0, 0, 0, 0},
  745. {0xDD, 0x87, 0x87, 0, 0},
  746. {0xDE, 0x88, 0x88, 0, 0},
  747. {0xDF, 0x8, 0x8, 0, 0},
  748. {0xE0, 0x8, 0x8, 0, 0},
  749. {0xE1, 0x8, 0x8, 0, 0},
  750. {0xE2, 0, 0, 0, 0},
  751. {0xE3, 0, 0, 0, 0},
  752. {0xE4, 0, 0, 0, 0},
  753. {0xE5, 0xf5, 0xf5, 0, 0},
  754. {0xE6, 0x30, 0x30, 0, 0},
  755. {0xE7, 0x1, 0x1, 0, 0},
  756. {0xE8, 0, 0, 0, 0},
  757. {0xE9, 0xff, 0xff, 0, 0},
  758. {0xEA, 0, 0, 0, 0},
  759. {0xEB, 0, 0, 0, 0},
  760. {0xEC, 0x22, 0x22, 0, 0},
  761. {0xED, 0, 0, 0, 0},
  762. {0xEE, 0, 0, 0, 0},
  763. {0xEF, 0, 0, 0, 0},
  764. {0xF0, 0x3, 0x3, 0, 0},
  765. {0xF1, 0x1, 0x1, 0, 0},
  766. {0xF2, 0, 0, 0, 0},
  767. {0xF3, 0, 0, 0, 0},
  768. {0xF4, 0, 0, 0, 0},
  769. {0xF5, 0, 0, 0, 0},
  770. {0xF6, 0, 0, 0, 0},
  771. {0xF7, 0x6, 0x6, 0, 0},
  772. {0xF8, 0, 0, 0, 0},
  773. {0xF9, 0, 0, 0, 0},
  774. {0xFA, 0x40, 0x40, 0, 0},
  775. {0xFB, 0, 0, 0, 0},
  776. {0xFC, 0x1, 0x1, 0, 0},
  777. {0xFD, 0x80, 0x80, 0, 0},
  778. {0xFE, 0x2, 0x2, 0, 0},
  779. {0xFF, 0x10, 0x10, 0, 0},
  780. {0x100, 0x2, 0x2, 0, 0},
  781. {0x101, 0x1e, 0x1e, 0, 0},
  782. {0x102, 0x1e, 0x1e, 0, 0},
  783. {0x103, 0, 0, 0, 0},
  784. {0x104, 0x1f, 0x1f, 0, 0},
  785. {0x105, 0, 0x8, 0, 1},
  786. {0x106, 0x2a, 0x2a, 0, 0},
  787. {0x107, 0xf, 0xf, 0, 0},
  788. {0x108, 0, 0, 0, 0},
  789. {0x109, 0, 0, 0, 0},
  790. {0x10A, 0, 0, 0, 0},
  791. {0x10B, 0, 0, 0, 0},
  792. {0x10C, 0, 0, 0, 0},
  793. {0x10D, 0, 0, 0, 0},
  794. {0x10E, 0, 0, 0, 0},
  795. {0x10F, 0, 0, 0, 0},
  796. {0x110, 0, 0, 0, 0},
  797. {0x111, 0, 0, 0, 0},
  798. {0x112, 0, 0, 0, 0},
  799. {0x113, 0, 0, 0, 0},
  800. {0x114, 0, 0, 0, 0},
  801. {0x115, 0, 0, 0, 0},
  802. {0x116, 0, 0, 0, 0},
  803. {0x117, 0, 0, 0, 0},
  804. {0x118, 0, 0, 0, 0},
  805. {0x119, 0, 0, 0, 0},
  806. {0x11A, 0, 0, 0, 0},
  807. {0x11B, 0, 0, 0, 0},
  808. {0x11C, 0x1, 0x1, 0, 0},
  809. {0x11D, 0, 0, 0, 0},
  810. {0x11E, 0, 0, 0, 0},
  811. {0x11F, 0, 0, 0, 0},
  812. {0x120, 0, 0, 0, 0},
  813. {0x121, 0, 0, 0, 0},
  814. {0x122, 0x80, 0x80, 0, 0},
  815. {0x123, 0, 0, 0, 0},
  816. {0x124, 0xf8, 0xf8, 0, 0},
  817. {0x125, 0, 0, 0, 0},
  818. {0x126, 0, 0, 0, 0},
  819. {0x127, 0, 0, 0, 0},
  820. {0x128, 0, 0, 0, 0},
  821. {0x129, 0, 0, 0, 0},
  822. {0x12A, 0, 0, 0, 0},
  823. {0x12B, 0, 0, 0, 0},
  824. {0x12C, 0, 0, 0, 0},
  825. {0x12D, 0, 0, 0, 0},
  826. {0x12E, 0, 0, 0, 0},
  827. {0x12F, 0, 0, 0, 0},
  828. {0x130, 0, 0, 0, 0},
  829. {0xFFFF, 0, 0, 0, 0}
  830. };
  831. #define LCNPHY_NUM_DIG_FILT_COEFFS 16
  832. #define LCNPHY_NUM_TX_DIG_FILTERS_CCK 13
  833. static const u16 LCNPHY_txdigfiltcoeffs_cck[LCNPHY_NUM_TX_DIG_FILTERS_CCK]
  834. [LCNPHY_NUM_DIG_FILT_COEFFS + 1] = {
  835. {0, 1, 415, 1874, 64, 128, 64, 792, 1656, 64, 128, 64, 778, 1582, 64,
  836. 128, 64,},
  837. {1, 1, 402, 1847, 259, 59, 259, 671, 1794, 68, 54, 68, 608, 1863, 93,
  838. 167, 93,},
  839. {2, 1, 415, 1874, 64, 128, 64, 792, 1656, 192, 384, 192, 778, 1582, 64,
  840. 128, 64,},
  841. {3, 1, 302, 1841, 129, 258, 129, 658, 1720, 205, 410, 205, 754, 1760,
  842. 170, 340, 170,},
  843. {20, 1, 360, 1884, 242, 1734, 242, 752, 1720, 205, 1845, 205, 767, 1760,
  844. 256, 185, 256,},
  845. {21, 1, 360, 1884, 149, 1874, 149, 752, 1720, 205, 1883, 205, 767, 1760,
  846. 256, 273, 256,},
  847. {22, 1, 360, 1884, 98, 1948, 98, 752, 1720, 205, 1924, 205, 767, 1760,
  848. 256, 352, 256,},
  849. {23, 1, 350, 1884, 116, 1966, 116, 752, 1720, 205, 2008, 205, 767, 1760,
  850. 128, 233, 128,},
  851. {24, 1, 325, 1884, 32, 40, 32, 756, 1720, 256, 471, 256, 766, 1760, 256,
  852. 1881, 256,},
  853. {25, 1, 299, 1884, 51, 64, 51, 736, 1720, 256, 471, 256, 765, 1760, 256,
  854. 1881, 256,},
  855. {26, 1, 277, 1943, 39, 117, 88, 637, 1838, 64, 192, 144, 614, 1864, 128,
  856. 384, 288,},
  857. {27, 1, 245, 1943, 49, 147, 110, 626, 1838, 256, 768, 576, 613, 1864,
  858. 128, 384, 288,},
  859. {30, 1, 302, 1841, 61, 122, 61, 658, 1720, 205, 410, 205, 754, 1760,
  860. 170, 340, 170,},
  861. };
  862. #define LCNPHY_NUM_TX_DIG_FILTERS_OFDM 3
  863. static const u16 LCNPHY_txdigfiltcoeffs_ofdm[LCNPHY_NUM_TX_DIG_FILTERS_OFDM]
  864. [LCNPHY_NUM_DIG_FILT_COEFFS + 1] = {
  865. {0, 0, 0xa2, 0x0, 0x100, 0x100, 0x0, 0x0, 0x0, 0x100, 0x0, 0x0,
  866. 0x278, 0xfea0, 0x80, 0x100, 0x80,},
  867. {1, 0, 374, 0xFF79, 16, 32, 16, 799, 0xFE74, 50, 32, 50,
  868. 750, 0xFE2B, 212, 0xFFCE, 212,},
  869. {2, 0, 375, 0xFF16, 37, 76, 37, 799, 0xFE74, 32, 20, 32, 748,
  870. 0xFEF2, 128, 0xFFE2, 128}
  871. };
  872. #define wlc_lcnphy_set_start_tx_pwr_idx(pi, idx) \
  873. mod_phy_reg(pi, 0x4a4, \
  874. (0x1ff << 0), \
  875. (u16)(idx) << 0)
  876. #define wlc_lcnphy_set_tx_pwr_npt(pi, npt) \
  877. mod_phy_reg(pi, 0x4a5, \
  878. (0x7 << 8), \
  879. (u16)(npt) << 8)
  880. #define wlc_lcnphy_get_tx_pwr_ctrl(pi) \
  881. (read_phy_reg((pi), 0x4a4) & \
  882. ((0x1 << 15) | \
  883. (0x1 << 14) | \
  884. (0x1 << 13)))
  885. #define wlc_lcnphy_get_tx_pwr_npt(pi) \
  886. ((read_phy_reg(pi, 0x4a5) & \
  887. (0x7 << 8)) >> \
  888. 8)
  889. #define wlc_lcnphy_get_current_tx_pwr_idx_if_pwrctrl_on(pi) \
  890. (read_phy_reg(pi, 0x473) & 0x1ff)
  891. #define wlc_lcnphy_get_target_tx_pwr(pi) \
  892. ((read_phy_reg(pi, 0x4a7) & \
  893. (0xff << 0)) >> \
  894. 0)
  895. #define wlc_lcnphy_set_target_tx_pwr(pi, target) \
  896. mod_phy_reg(pi, 0x4a7, \
  897. (0xff << 0), \
  898. (u16)(target) << 0)
  899. #define wlc_radio_2064_rcal_done(pi) \
  900. (0 != (read_radio_reg(pi, RADIO_2064_REG05C) & 0x20))
  901. #define tempsense_done(pi) \
  902. (0x8000 == (read_phy_reg(pi, 0x476) & 0x8000))
  903. #define LCNPHY_IQLOCC_READ(val) \
  904. ((u8)(-(s8)(((val) & 0xf0) >> 4) + (s8)((val) & 0x0f)))
  905. #define FIXED_TXPWR 78
  906. #define LCNPHY_TEMPSENSE(val) ((s16)((val > 255) ? (val - 512) : val))
  907. void wlc_lcnphy_write_table(struct brcms_phy *pi, const struct phytbl_info *pti)
  908. {
  909. wlc_phy_write_table(pi, pti, 0x455, 0x457, 0x456);
  910. }
  911. void wlc_lcnphy_read_table(struct brcms_phy *pi, struct phytbl_info *pti)
  912. {
  913. wlc_phy_read_table(pi, pti, 0x455, 0x457, 0x456);
  914. }
  915. static void
  916. wlc_lcnphy_common_read_table(struct brcms_phy *pi, u32 tbl_id,
  917. const u16 *tbl_ptr, u32 tbl_len,
  918. u32 tbl_width, u32 tbl_offset)
  919. {
  920. struct phytbl_info tab;
  921. tab.tbl_id = tbl_id;
  922. tab.tbl_ptr = tbl_ptr;
  923. tab.tbl_len = tbl_len;
  924. tab.tbl_width = tbl_width;
  925. tab.tbl_offset = tbl_offset;
  926. wlc_lcnphy_read_table(pi, &tab);
  927. }
  928. static void
  929. wlc_lcnphy_common_write_table(struct brcms_phy *pi, u32 tbl_id,
  930. const u16 *tbl_ptr, u32 tbl_len,
  931. u32 tbl_width, u32 tbl_offset)
  932. {
  933. struct phytbl_info tab;
  934. tab.tbl_id = tbl_id;
  935. tab.tbl_ptr = tbl_ptr;
  936. tab.tbl_len = tbl_len;
  937. tab.tbl_width = tbl_width;
  938. tab.tbl_offset = tbl_offset;
  939. wlc_lcnphy_write_table(pi, &tab);
  940. }
  941. static u32
  942. wlc_lcnphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
  943. {
  944. u32 quotient, remainder, roundup, rbit;
  945. quotient = dividend / divisor;
  946. remainder = dividend % divisor;
  947. rbit = divisor & 1;
  948. roundup = (divisor >> 1) + rbit;
  949. while (precision--) {
  950. quotient <<= 1;
  951. if (remainder >= roundup) {
  952. quotient++;
  953. remainder = ((remainder - roundup) << 1) + rbit;
  954. } else {
  955. remainder <<= 1;
  956. }
  957. }
  958. if (remainder >= roundup)
  959. quotient++;
  960. return quotient;
  961. }
  962. static int wlc_lcnphy_calc_floor(s16 coeff_x, int type)
  963. {
  964. int k;
  965. k = 0;
  966. if (type == 0) {
  967. if (coeff_x < 0)
  968. k = (coeff_x - 1) / 2;
  969. else
  970. k = coeff_x / 2;
  971. }
  972. if (type == 1) {
  973. if ((coeff_x + 1) < 0)
  974. k = (coeff_x) / 2;
  975. else
  976. k = (coeff_x + 1) / 2;
  977. }
  978. return k;
  979. }
  980. static void
  981. wlc_lcnphy_get_tx_gain(struct brcms_phy *pi, struct lcnphy_txgains *gains)
  982. {
  983. u16 dac_gain, rfgain0, rfgain1;
  984. dac_gain = read_phy_reg(pi, 0x439) >> 0;
  985. gains->dac_gain = (dac_gain & 0x380) >> 7;
  986. rfgain0 = (read_phy_reg(pi, 0x4b5) & (0xffff << 0)) >> 0;
  987. rfgain1 = (read_phy_reg(pi, 0x4fb) & (0x7fff << 0)) >> 0;
  988. gains->gm_gain = rfgain0 & 0xff;
  989. gains->pga_gain = (rfgain0 >> 8) & 0xff;
  990. gains->pad_gain = rfgain1 & 0xff;
  991. }
  992. static void wlc_lcnphy_set_dac_gain(struct brcms_phy *pi, u16 dac_gain)
  993. {
  994. u16 dac_ctrl;
  995. dac_ctrl = (read_phy_reg(pi, 0x439) >> 0);
  996. dac_ctrl = dac_ctrl & 0xc7f;
  997. dac_ctrl = dac_ctrl | (dac_gain << 7);
  998. mod_phy_reg(pi, 0x439, (0xfff << 0), (dac_ctrl) << 0);
  999. }
  1000. static void wlc_lcnphy_set_tx_gain_override(struct brcms_phy *pi, bool bEnable)
  1001. {
  1002. u16 bit = bEnable ? 1 : 0;
  1003. mod_phy_reg(pi, 0x4b0, (0x1 << 7), bit << 7);
  1004. mod_phy_reg(pi, 0x4b0, (0x1 << 14), bit << 14);
  1005. mod_phy_reg(pi, 0x43b, (0x1 << 6), bit << 6);
  1006. }
  1007. static void
  1008. wlc_lcnphy_rx_gain_override_enable(struct brcms_phy *pi, bool enable)
  1009. {
  1010. u16 ebit = enable ? 1 : 0;
  1011. mod_phy_reg(pi, 0x4b0, (0x1 << 8), ebit << 8);
  1012. mod_phy_reg(pi, 0x44c, (0x1 << 0), ebit << 0);
  1013. if (LCNREV_LT(pi->pubpi.phy_rev, 2)) {
  1014. mod_phy_reg(pi, 0x44c, (0x1 << 4), ebit << 4);
  1015. mod_phy_reg(pi, 0x44c, (0x1 << 6), ebit << 6);
  1016. mod_phy_reg(pi, 0x4b0, (0x1 << 5), ebit << 5);
  1017. mod_phy_reg(pi, 0x4b0, (0x1 << 6), ebit << 6);
  1018. } else {
  1019. mod_phy_reg(pi, 0x4b0, (0x1 << 12), ebit << 12);
  1020. mod_phy_reg(pi, 0x4b0, (0x1 << 13), ebit << 13);
  1021. mod_phy_reg(pi, 0x4b0, (0x1 << 5), ebit << 5);
  1022. }
  1023. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  1024. mod_phy_reg(pi, 0x4b0, (0x1 << 10), ebit << 10);
  1025. mod_phy_reg(pi, 0x4e5, (0x1 << 3), ebit << 3);
  1026. }
  1027. }
  1028. static void
  1029. wlc_lcnphy_set_rx_gain_by_distribution(struct brcms_phy *pi,
  1030. u16 trsw,
  1031. u16 ext_lna,
  1032. u16 biq2,
  1033. u16 biq1,
  1034. u16 tia, u16 lna2, u16 lna1)
  1035. {
  1036. u16 gain0_15, gain16_19;
  1037. gain16_19 = biq2 & 0xf;
  1038. gain0_15 = ((biq1 & 0xf) << 12) |
  1039. ((tia & 0xf) << 8) |
  1040. ((lna2 & 0x3) << 6) |
  1041. ((lna2 & 0x3) << 4) |
  1042. ((lna1 & 0x3) << 2) |
  1043. ((lna1 & 0x3) << 0);
  1044. mod_phy_reg(pi, 0x4b6, (0xffff << 0), gain0_15 << 0);
  1045. mod_phy_reg(pi, 0x4b7, (0xf << 0), gain16_19 << 0);
  1046. mod_phy_reg(pi, 0x4b1, (0x3 << 11), lna1 << 11);
  1047. if (LCNREV_LT(pi->pubpi.phy_rev, 2)) {
  1048. mod_phy_reg(pi, 0x4b1, (0x1 << 9), ext_lna << 9);
  1049. mod_phy_reg(pi, 0x4b1, (0x1 << 10), ext_lna << 10);
  1050. } else {
  1051. mod_phy_reg(pi, 0x4b1, (0x1 << 10), 0 << 10);
  1052. mod_phy_reg(pi, 0x4b1, (0x1 << 15), 0 << 15);
  1053. mod_phy_reg(pi, 0x4b1, (0x1 << 9), ext_lna << 9);
  1054. }
  1055. mod_phy_reg(pi, 0x44d, (0x1 << 0), (!trsw) << 0);
  1056. }
  1057. static void wlc_lcnphy_set_trsw_override(struct brcms_phy *pi, bool tx, bool rx)
  1058. {
  1059. mod_phy_reg(pi, 0x44d,
  1060. (0x1 << 1) |
  1061. (0x1 << 0), (tx ? (0x1 << 1) : 0) | (rx ? (0x1 << 0) : 0));
  1062. or_phy_reg(pi, 0x44c, (0x1 << 1) | (0x1 << 0));
  1063. }
  1064. static void wlc_lcnphy_clear_trsw_override(struct brcms_phy *pi)
  1065. {
  1066. and_phy_reg(pi, 0x44c, (u16) ~((0x1 << 1) | (0x1 << 0)));
  1067. }
  1068. static void wlc_lcnphy_set_rx_iq_comp(struct brcms_phy *pi, u16 a, u16 b)
  1069. {
  1070. mod_phy_reg(pi, 0x645, (0x3ff << 0), (a) << 0);
  1071. mod_phy_reg(pi, 0x646, (0x3ff << 0), (b) << 0);
  1072. mod_phy_reg(pi, 0x647, (0x3ff << 0), (a) << 0);
  1073. mod_phy_reg(pi, 0x648, (0x3ff << 0), (b) << 0);
  1074. mod_phy_reg(pi, 0x649, (0x3ff << 0), (a) << 0);
  1075. mod_phy_reg(pi, 0x64a, (0x3ff << 0), (b) << 0);
  1076. }
  1077. static bool
  1078. wlc_lcnphy_rx_iq_est(struct brcms_phy *pi,
  1079. u16 num_samps,
  1080. u8 wait_time, struct lcnphy_iq_est *iq_est)
  1081. {
  1082. int wait_count = 0;
  1083. bool result = true;
  1084. u8 phybw40;
  1085. phybw40 = CHSPEC_IS40(pi->radio_chanspec);
  1086. mod_phy_reg(pi, 0x6da, (0x1 << 5), (1) << 5);
  1087. mod_phy_reg(pi, 0x410, (0x1 << 3), (0) << 3);
  1088. mod_phy_reg(pi, 0x482, (0xffff << 0), (num_samps) << 0);
  1089. mod_phy_reg(pi, 0x481, (0xff << 0), ((u16) wait_time) << 0);
  1090. mod_phy_reg(pi, 0x481, (0x1 << 8), (0) << 8);
  1091. mod_phy_reg(pi, 0x481, (0x1 << 9), (1) << 9);
  1092. while (read_phy_reg(pi, 0x481) & (0x1 << 9)) {
  1093. if (wait_count > (10 * 500)) {
  1094. result = false;
  1095. goto cleanup;
  1096. }
  1097. udelay(100);
  1098. wait_count++;
  1099. }
  1100. iq_est->iq_prod = ((u32) read_phy_reg(pi, 0x483) << 16) |
  1101. (u32) read_phy_reg(pi, 0x484);
  1102. iq_est->i_pwr = ((u32) read_phy_reg(pi, 0x485) << 16) |
  1103. (u32) read_phy_reg(pi, 0x486);
  1104. iq_est->q_pwr = ((u32) read_phy_reg(pi, 0x487) << 16) |
  1105. (u32) read_phy_reg(pi, 0x488);
  1106. cleanup:
  1107. mod_phy_reg(pi, 0x410, (0x1 << 3), (1) << 3);
  1108. mod_phy_reg(pi, 0x6da, (0x1 << 5), (0) << 5);
  1109. return result;
  1110. }
  1111. static bool wlc_lcnphy_calc_rx_iq_comp(struct brcms_phy *pi, u16 num_samps)
  1112. {
  1113. #define LCNPHY_MIN_RXIQ_PWR 2
  1114. bool result;
  1115. u16 a0_new, b0_new;
  1116. struct lcnphy_iq_est iq_est = { 0, 0, 0 };
  1117. s32 a, b, temp;
  1118. s16 iq_nbits, qq_nbits, arsh, brsh;
  1119. s32 iq;
  1120. u32 ii, qq;
  1121. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1122. a0_new = ((read_phy_reg(pi, 0x645) & (0x3ff << 0)) >> 0);
  1123. b0_new = ((read_phy_reg(pi, 0x646) & (0x3ff << 0)) >> 0);
  1124. mod_phy_reg(pi, 0x6d1, (0x1 << 2), (0) << 2);
  1125. mod_phy_reg(pi, 0x64b, (0x1 << 6), (1) << 6);
  1126. wlc_lcnphy_set_rx_iq_comp(pi, 0, 0);
  1127. result = wlc_lcnphy_rx_iq_est(pi, num_samps, 32, &iq_est);
  1128. if (!result)
  1129. goto cleanup;
  1130. iq = (s32) iq_est.iq_prod;
  1131. ii = iq_est.i_pwr;
  1132. qq = iq_est.q_pwr;
  1133. if ((ii + qq) < LCNPHY_MIN_RXIQ_PWR) {
  1134. result = false;
  1135. goto cleanup;
  1136. }
  1137. iq_nbits = wlc_phy_nbits(iq);
  1138. qq_nbits = wlc_phy_nbits(qq);
  1139. arsh = 10 - (30 - iq_nbits);
  1140. if (arsh >= 0) {
  1141. a = (-(iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
  1142. temp = (s32) (ii >> arsh);
  1143. if (temp == 0)
  1144. return false;
  1145. } else {
  1146. a = (-(iq << (30 - iq_nbits)) + (ii << (-1 - arsh)));
  1147. temp = (s32) (ii << -arsh);
  1148. if (temp == 0)
  1149. return false;
  1150. }
  1151. a /= temp;
  1152. brsh = qq_nbits - 31 + 20;
  1153. if (brsh >= 0) {
  1154. b = (qq << (31 - qq_nbits));
  1155. temp = (s32) (ii >> brsh);
  1156. if (temp == 0)
  1157. return false;
  1158. } else {
  1159. b = (qq << (31 - qq_nbits));
  1160. temp = (s32) (ii << -brsh);
  1161. if (temp == 0)
  1162. return false;
  1163. }
  1164. b /= temp;
  1165. b -= a * a;
  1166. b = (s32) int_sqrt((unsigned long) b);
  1167. b -= (1 << 10);
  1168. a0_new = (u16) (a & 0x3ff);
  1169. b0_new = (u16) (b & 0x3ff);
  1170. cleanup:
  1171. wlc_lcnphy_set_rx_iq_comp(pi, a0_new, b0_new);
  1172. mod_phy_reg(pi, 0x64b, (0x1 << 0), (1) << 0);
  1173. mod_phy_reg(pi, 0x64b, (0x1 << 3), (1) << 3);
  1174. pi_lcn->lcnphy_cal_results.rxiqcal_coeff_a0 = a0_new;
  1175. pi_lcn->lcnphy_cal_results.rxiqcal_coeff_b0 = b0_new;
  1176. return result;
  1177. }
  1178. static u32 wlc_lcnphy_measure_digital_power(struct brcms_phy *pi, u16 nsamples)
  1179. {
  1180. struct lcnphy_iq_est iq_est = { 0, 0, 0 };
  1181. if (!wlc_lcnphy_rx_iq_est(pi, nsamples, 32, &iq_est))
  1182. return 0;
  1183. return (iq_est.i_pwr + iq_est.q_pwr) / nsamples;
  1184. }
  1185. static bool wlc_lcnphy_rx_iq_cal_gain(struct brcms_phy *pi, u16 biq1_gain,
  1186. u16 tia_gain, u16 lna2_gain)
  1187. {
  1188. u32 i_thresh_l, q_thresh_l;
  1189. u32 i_thresh_h, q_thresh_h;
  1190. struct lcnphy_iq_est iq_est_h, iq_est_l;
  1191. wlc_lcnphy_set_rx_gain_by_distribution(pi, 0, 0, 0, biq1_gain, tia_gain,
  1192. lna2_gain, 0);
  1193. wlc_lcnphy_rx_gain_override_enable(pi, true);
  1194. wlc_lcnphy_start_tx_tone(pi, 2000, (40 >> 1), 0);
  1195. udelay(500);
  1196. write_radio_reg(pi, RADIO_2064_REG112, 0);
  1197. if (!wlc_lcnphy_rx_iq_est(pi, 1024, 32, &iq_est_l))
  1198. return false;
  1199. wlc_lcnphy_start_tx_tone(pi, 2000, 40, 0);
  1200. udelay(500);
  1201. write_radio_reg(pi, RADIO_2064_REG112, 0);
  1202. if (!wlc_lcnphy_rx_iq_est(pi, 1024, 32, &iq_est_h))
  1203. return false;
  1204. i_thresh_l = (iq_est_l.i_pwr << 1);
  1205. i_thresh_h = (iq_est_l.i_pwr << 2) + iq_est_l.i_pwr;
  1206. q_thresh_l = (iq_est_l.q_pwr << 1);
  1207. q_thresh_h = (iq_est_l.q_pwr << 2) + iq_est_l.q_pwr;
  1208. if ((iq_est_h.i_pwr > i_thresh_l) &&
  1209. (iq_est_h.i_pwr < i_thresh_h) &&
  1210. (iq_est_h.q_pwr > q_thresh_l) &&
  1211. (iq_est_h.q_pwr < q_thresh_h))
  1212. return true;
  1213. return false;
  1214. }
  1215. static bool
  1216. wlc_lcnphy_rx_iq_cal(struct brcms_phy *pi,
  1217. const struct lcnphy_rx_iqcomp *iqcomp,
  1218. int iqcomp_sz, bool tx_switch, bool rx_switch, int module,
  1219. int tx_gain_idx)
  1220. {
  1221. struct lcnphy_txgains old_gains;
  1222. u16 tx_pwr_ctrl;
  1223. u8 tx_gain_index_old = 0;
  1224. bool result = false, tx_gain_override_old = false;
  1225. u16 i, Core1TxControl_old, RFOverride0_old,
  1226. RFOverrideVal0_old, rfoverride2_old, rfoverride2val_old,
  1227. rfoverride3_old, rfoverride3val_old, rfoverride4_old,
  1228. rfoverride4val_old, afectrlovr_old, afectrlovrval_old;
  1229. int tia_gain, lna2_gain, biq1_gain;
  1230. bool set_gain;
  1231. u16 old_sslpnCalibClkEnCtrl, old_sslpnRxFeClkEnCtrl;
  1232. u16 values_to_save[11];
  1233. s16 *ptr;
  1234. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1235. ptr = kmalloc(sizeof(s16) * 131, GFP_ATOMIC);
  1236. if (NULL == ptr)
  1237. return false;
  1238. if (module == 2) {
  1239. while (iqcomp_sz--) {
  1240. if (iqcomp[iqcomp_sz].chan ==
  1241. CHSPEC_CHANNEL(pi->radio_chanspec)) {
  1242. wlc_lcnphy_set_rx_iq_comp(pi,
  1243. (u16)
  1244. iqcomp[iqcomp_sz].a,
  1245. (u16)
  1246. iqcomp[iqcomp_sz].b);
  1247. result = true;
  1248. break;
  1249. }
  1250. }
  1251. goto cal_done;
  1252. }
  1253. WARN_ON(module != 1);
  1254. tx_pwr_ctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  1255. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  1256. for (i = 0; i < 11; i++)
  1257. values_to_save[i] =
  1258. read_radio_reg(pi, rxiq_cal_rf_reg[i]);
  1259. Core1TxControl_old = read_phy_reg(pi, 0x631);
  1260. or_phy_reg(pi, 0x631, 0x0015);
  1261. RFOverride0_old = read_phy_reg(pi, 0x44c);
  1262. RFOverrideVal0_old = read_phy_reg(pi, 0x44d);
  1263. rfoverride2_old = read_phy_reg(pi, 0x4b0);
  1264. rfoverride2val_old = read_phy_reg(pi, 0x4b1);
  1265. rfoverride3_old = read_phy_reg(pi, 0x4f9);
  1266. rfoverride3val_old = read_phy_reg(pi, 0x4fa);
  1267. rfoverride4_old = read_phy_reg(pi, 0x938);
  1268. rfoverride4val_old = read_phy_reg(pi, 0x939);
  1269. afectrlovr_old = read_phy_reg(pi, 0x43b);
  1270. afectrlovrval_old = read_phy_reg(pi, 0x43c);
  1271. old_sslpnCalibClkEnCtrl = read_phy_reg(pi, 0x6da);
  1272. old_sslpnRxFeClkEnCtrl = read_phy_reg(pi, 0x6db);
  1273. tx_gain_override_old = wlc_lcnphy_tx_gain_override_enabled(pi);
  1274. if (tx_gain_override_old) {
  1275. wlc_lcnphy_get_tx_gain(pi, &old_gains);
  1276. tx_gain_index_old = pi_lcn->lcnphy_current_index;
  1277. }
  1278. wlc_lcnphy_set_tx_pwr_by_index(pi, tx_gain_idx);
  1279. mod_phy_reg(pi, 0x4f9, (0x1 << 0), 1 << 0);
  1280. mod_phy_reg(pi, 0x4fa, (0x1 << 0), 0 << 0);
  1281. mod_phy_reg(pi, 0x43b, (0x1 << 1), 1 << 1);
  1282. mod_phy_reg(pi, 0x43c, (0x1 << 1), 0 << 1);
  1283. write_radio_reg(pi, RADIO_2064_REG116, 0x06);
  1284. write_radio_reg(pi, RADIO_2064_REG12C, 0x07);
  1285. write_radio_reg(pi, RADIO_2064_REG06A, 0xd3);
  1286. write_radio_reg(pi, RADIO_2064_REG098, 0x03);
  1287. write_radio_reg(pi, RADIO_2064_REG00B, 0x7);
  1288. mod_radio_reg(pi, RADIO_2064_REG113, 1 << 4, 1 << 4);
  1289. write_radio_reg(pi, RADIO_2064_REG01D, 0x01);
  1290. write_radio_reg(pi, RADIO_2064_REG114, 0x01);
  1291. write_radio_reg(pi, RADIO_2064_REG02E, 0x10);
  1292. write_radio_reg(pi, RADIO_2064_REG12A, 0x08);
  1293. mod_phy_reg(pi, 0x938, (0x1 << 0), 1 << 0);
  1294. mod_phy_reg(pi, 0x939, (0x1 << 0), 0 << 0);
  1295. mod_phy_reg(pi, 0x938, (0x1 << 1), 1 << 1);
  1296. mod_phy_reg(pi, 0x939, (0x1 << 1), 1 << 1);
  1297. mod_phy_reg(pi, 0x938, (0x1 << 2), 1 << 2);
  1298. mod_phy_reg(pi, 0x939, (0x1 << 2), 1 << 2);
  1299. mod_phy_reg(pi, 0x938, (0x1 << 3), 1 << 3);
  1300. mod_phy_reg(pi, 0x939, (0x1 << 3), 1 << 3);
  1301. mod_phy_reg(pi, 0x938, (0x1 << 5), 1 << 5);
  1302. mod_phy_reg(pi, 0x939, (0x1 << 5), 0 << 5);
  1303. mod_phy_reg(pi, 0x43b, (0x1 << 0), 1 << 0);
  1304. mod_phy_reg(pi, 0x43c, (0x1 << 0), 0 << 0);
  1305. write_phy_reg(pi, 0x6da, 0xffff);
  1306. or_phy_reg(pi, 0x6db, 0x3);
  1307. wlc_lcnphy_set_trsw_override(pi, tx_switch, rx_switch);
  1308. for (lna2_gain = 3; lna2_gain >= 0; lna2_gain--) {
  1309. for (tia_gain = 4; tia_gain >= 0; tia_gain--) {
  1310. for (biq1_gain = 6; biq1_gain >= 0; biq1_gain--) {
  1311. set_gain = wlc_lcnphy_rx_iq_cal_gain(pi,
  1312. (u16)
  1313. biq1_gain,
  1314. (u16)
  1315. tia_gain,
  1316. (u16)
  1317. lna2_gain);
  1318. if (!set_gain)
  1319. continue;
  1320. result = wlc_lcnphy_calc_rx_iq_comp(pi, 1024);
  1321. goto stop_tone;
  1322. }
  1323. }
  1324. }
  1325. stop_tone:
  1326. wlc_lcnphy_stop_tx_tone(pi);
  1327. write_phy_reg(pi, 0x631, Core1TxControl_old);
  1328. write_phy_reg(pi, 0x44c, RFOverrideVal0_old);
  1329. write_phy_reg(pi, 0x44d, RFOverrideVal0_old);
  1330. write_phy_reg(pi, 0x4b0, rfoverride2_old);
  1331. write_phy_reg(pi, 0x4b1, rfoverride2val_old);
  1332. write_phy_reg(pi, 0x4f9, rfoverride3_old);
  1333. write_phy_reg(pi, 0x4fa, rfoverride3val_old);
  1334. write_phy_reg(pi, 0x938, rfoverride4_old);
  1335. write_phy_reg(pi, 0x939, rfoverride4val_old);
  1336. write_phy_reg(pi, 0x43b, afectrlovr_old);
  1337. write_phy_reg(pi, 0x43c, afectrlovrval_old);
  1338. write_phy_reg(pi, 0x6da, old_sslpnCalibClkEnCtrl);
  1339. write_phy_reg(pi, 0x6db, old_sslpnRxFeClkEnCtrl);
  1340. wlc_lcnphy_clear_trsw_override(pi);
  1341. mod_phy_reg(pi, 0x44c, (0x1 << 2), 0 << 2);
  1342. for (i = 0; i < 11; i++)
  1343. write_radio_reg(pi, rxiq_cal_rf_reg[i],
  1344. values_to_save[i]);
  1345. if (tx_gain_override_old)
  1346. wlc_lcnphy_set_tx_pwr_by_index(pi, tx_gain_index_old);
  1347. else
  1348. wlc_lcnphy_disable_tx_gain_override(pi);
  1349. wlc_lcnphy_set_tx_pwr_ctrl(pi, tx_pwr_ctrl);
  1350. wlc_lcnphy_rx_gain_override_enable(pi, false);
  1351. cal_done:
  1352. kfree(ptr);
  1353. return result;
  1354. }
  1355. s8 wlc_lcnphy_get_current_tx_pwr_idx(struct brcms_phy *pi)
  1356. {
  1357. s8 index;
  1358. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1359. if (txpwrctrl_off(pi))
  1360. index = pi_lcn->lcnphy_current_index;
  1361. else if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi))
  1362. index = (s8) (wlc_lcnphy_get_current_tx_pwr_idx_if_pwrctrl_on(
  1363. pi) / 2);
  1364. else
  1365. index = pi_lcn->lcnphy_current_index;
  1366. return index;
  1367. }
  1368. void wlc_lcnphy_crsuprs(struct brcms_phy *pi, int channel)
  1369. {
  1370. u16 afectrlovr, afectrlovrval;
  1371. afectrlovr = read_phy_reg(pi, 0x43b);
  1372. afectrlovrval = read_phy_reg(pi, 0x43c);
  1373. if (channel != 0) {
  1374. mod_phy_reg(pi, 0x43b, (0x1 << 1), (1) << 1);
  1375. mod_phy_reg(pi, 0x43c, (0x1 << 1), (0) << 1);
  1376. mod_phy_reg(pi, 0x43b, (0x1 << 4), (1) << 4);
  1377. mod_phy_reg(pi, 0x43c, (0x1 << 6), (0) << 6);
  1378. write_phy_reg(pi, 0x44b, 0xffff);
  1379. wlc_lcnphy_tx_pu(pi, 1);
  1380. mod_phy_reg(pi, 0x634, (0xff << 8), (0) << 8);
  1381. or_phy_reg(pi, 0x6da, 0x0080);
  1382. or_phy_reg(pi, 0x00a, 0x228);
  1383. } else {
  1384. and_phy_reg(pi, 0x00a, ~(0x228));
  1385. and_phy_reg(pi, 0x6da, 0xFF7F);
  1386. write_phy_reg(pi, 0x43b, afectrlovr);
  1387. write_phy_reg(pi, 0x43c, afectrlovrval);
  1388. }
  1389. }
  1390. static void wlc_lcnphy_toggle_afe_pwdn(struct brcms_phy *pi)
  1391. {
  1392. u16 save_AfeCtrlOvrVal, save_AfeCtrlOvr;
  1393. save_AfeCtrlOvrVal = read_phy_reg(pi, 0x43c);
  1394. save_AfeCtrlOvr = read_phy_reg(pi, 0x43b);
  1395. write_phy_reg(pi, 0x43c, save_AfeCtrlOvrVal | 0x1);
  1396. write_phy_reg(pi, 0x43b, save_AfeCtrlOvr | 0x1);
  1397. write_phy_reg(pi, 0x43c, save_AfeCtrlOvrVal & 0xfffe);
  1398. write_phy_reg(pi, 0x43b, save_AfeCtrlOvr & 0xfffe);
  1399. write_phy_reg(pi, 0x43c, save_AfeCtrlOvrVal);
  1400. write_phy_reg(pi, 0x43b, save_AfeCtrlOvr);
  1401. }
  1402. static void
  1403. wlc_lcnphy_txrx_spur_avoidance_mode(struct brcms_phy *pi, bool enable)
  1404. {
  1405. if (enable) {
  1406. write_phy_reg(pi, 0x942, 0x7);
  1407. write_phy_reg(pi, 0x93b, ((1 << 13) + 23));
  1408. write_phy_reg(pi, 0x93c, ((1 << 13) + 1989));
  1409. write_phy_reg(pi, 0x44a, 0x084);
  1410. write_phy_reg(pi, 0x44a, 0x080);
  1411. write_phy_reg(pi, 0x6d3, 0x2222);
  1412. write_phy_reg(pi, 0x6d3, 0x2220);
  1413. } else {
  1414. write_phy_reg(pi, 0x942, 0x0);
  1415. write_phy_reg(pi, 0x93b, ((0 << 13) + 23));
  1416. write_phy_reg(pi, 0x93c, ((0 << 13) + 1989));
  1417. }
  1418. wlapi_switch_macfreq(pi->sh->physhim, enable);
  1419. }
  1420. static void
  1421. wlc_lcnphy_set_chanspec_tweaks(struct brcms_phy *pi, u16 chanspec)
  1422. {
  1423. u8 channel = CHSPEC_CHANNEL(chanspec);
  1424. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1425. if (channel == 14)
  1426. mod_phy_reg(pi, 0x448, (0x3 << 8), (2) << 8);
  1427. else
  1428. mod_phy_reg(pi, 0x448, (0x3 << 8), (1) << 8);
  1429. pi_lcn->lcnphy_bandedge_corr = 2;
  1430. if (channel == 1)
  1431. pi_lcn->lcnphy_bandedge_corr = 4;
  1432. if (channel == 1 || channel == 2 || channel == 3 ||
  1433. channel == 4 || channel == 9 ||
  1434. channel == 10 || channel == 11 || channel == 12) {
  1435. bcma_chipco_pll_write(&pi->d11core->bus->drv_cc, 0x2,
  1436. 0x03000c04);
  1437. bcma_chipco_pll_maskset(&pi->d11core->bus->drv_cc, 0x3,
  1438. ~0x00ffffff, 0x0);
  1439. bcma_chipco_pll_write(&pi->d11core->bus->drv_cc, 0x4,
  1440. 0x200005c0);
  1441. bcma_cc_set32(&pi->d11core->bus->drv_cc, BCMA_CC_PMU_CTL,
  1442. BCMA_CC_PMU_CTL_PLL_UPD);
  1443. write_phy_reg(pi, 0x942, 0);
  1444. wlc_lcnphy_txrx_spur_avoidance_mode(pi, false);
  1445. pi_lcn->lcnphy_spurmod = false;
  1446. mod_phy_reg(pi, 0x424, (0xff << 8), (0x1b) << 8);
  1447. write_phy_reg(pi, 0x425, 0x5907);
  1448. } else {
  1449. bcma_chipco_pll_write(&pi->d11core->bus->drv_cc, 0x2,
  1450. 0x03140c04);
  1451. bcma_chipco_pll_maskset(&pi->d11core->bus->drv_cc, 0x3,
  1452. ~0x00ffffff, 0x333333);
  1453. bcma_chipco_pll_write(&pi->d11core->bus->drv_cc, 0x4,
  1454. 0x202c2820);
  1455. bcma_cc_set32(&pi->d11core->bus->drv_cc, BCMA_CC_PMU_CTL,
  1456. BCMA_CC_PMU_CTL_PLL_UPD);
  1457. write_phy_reg(pi, 0x942, 0);
  1458. wlc_lcnphy_txrx_spur_avoidance_mode(pi, true);
  1459. pi_lcn->lcnphy_spurmod = false;
  1460. mod_phy_reg(pi, 0x424, (0xff << 8), (0x1f) << 8);
  1461. write_phy_reg(pi, 0x425, 0x590a);
  1462. }
  1463. or_phy_reg(pi, 0x44a, 0x44);
  1464. write_phy_reg(pi, 0x44a, 0x80);
  1465. }
  1466. static void
  1467. wlc_lcnphy_radio_2064_channel_tune_4313(struct brcms_phy *pi, u8 channel)
  1468. {
  1469. uint i;
  1470. const struct chan_info_2064_lcnphy *ci;
  1471. u8 rfpll_doubler = 0;
  1472. u8 pll_pwrup, pll_pwrup_ovr;
  1473. s32 qFxtal, qFref, qFvco, qFcal;
  1474. u8 d15, d16, f16, e44, e45;
  1475. u32 div_int, div_frac, fvco3, fpfd, fref3, fcal_div;
  1476. u16 loop_bw, d30, setCount;
  1477. u8 h29, h28_ten, e30, h30_ten, cp_current;
  1478. u16 g30, d28;
  1479. ci = &chan_info_2064_lcnphy[0];
  1480. rfpll_doubler = 1;
  1481. mod_radio_reg(pi, RADIO_2064_REG09D, 0x4, 0x1 << 2);
  1482. write_radio_reg(pi, RADIO_2064_REG09E, 0xf);
  1483. if (!rfpll_doubler) {
  1484. loop_bw = PLL_2064_LOOP_BW;
  1485. d30 = PLL_2064_D30;
  1486. } else {
  1487. loop_bw = PLL_2064_LOOP_BW_DOUBLER;
  1488. d30 = PLL_2064_D30_DOUBLER;
  1489. }
  1490. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  1491. for (i = 0; i < ARRAY_SIZE(chan_info_2064_lcnphy); i++)
  1492. if (chan_info_2064_lcnphy[i].chan == channel)
  1493. break;
  1494. if (i >= ARRAY_SIZE(chan_info_2064_lcnphy))
  1495. return;
  1496. ci = &chan_info_2064_lcnphy[i];
  1497. }
  1498. write_radio_reg(pi, RADIO_2064_REG02A, ci->logen_buftune);
  1499. mod_radio_reg(pi, RADIO_2064_REG030, 0x3, ci->logen_rccr_tx);
  1500. mod_radio_reg(pi, RADIO_2064_REG091, 0x3, ci->txrf_mix_tune_ctrl);
  1501. mod_radio_reg(pi, RADIO_2064_REG038, 0xf, ci->pa_input_tune_g);
  1502. mod_radio_reg(pi, RADIO_2064_REG030, 0x3 << 2,
  1503. (ci->logen_rccr_rx) << 2);
  1504. mod_radio_reg(pi, RADIO_2064_REG05E, 0xf, ci->pa_rxrf_lna1_freq_tune);
  1505. mod_radio_reg(pi, RADIO_2064_REG05E, (0xf) << 4,
  1506. (ci->pa_rxrf_lna2_freq_tune) << 4);
  1507. write_radio_reg(pi, RADIO_2064_REG06C, ci->rxrf_rxrf_spare1);
  1508. pll_pwrup = (u8) read_radio_reg(pi, RADIO_2064_REG044);
  1509. pll_pwrup_ovr = (u8) read_radio_reg(pi, RADIO_2064_REG12B);
  1510. or_radio_reg(pi, RADIO_2064_REG044, 0x07);
  1511. or_radio_reg(pi, RADIO_2064_REG12B, (0x07) << 1);
  1512. e44 = 0;
  1513. e45 = 0;
  1514. fpfd = rfpll_doubler ? (pi->xtalfreq << 1) : (pi->xtalfreq);
  1515. if (pi->xtalfreq > 26000000)
  1516. e44 = 1;
  1517. if (pi->xtalfreq > 52000000)
  1518. e45 = 1;
  1519. if (e44 == 0)
  1520. fcal_div = 1;
  1521. else if (e45 == 0)
  1522. fcal_div = 2;
  1523. else
  1524. fcal_div = 4;
  1525. fvco3 = (ci->freq * 3);
  1526. fref3 = 2 * fpfd;
  1527. qFxtal = wlc_lcnphy_qdiv_roundup(pi->xtalfreq, PLL_2064_MHZ, 16);
  1528. qFref = wlc_lcnphy_qdiv_roundup(fpfd, PLL_2064_MHZ, 16);
  1529. qFcal = pi->xtalfreq * fcal_div / PLL_2064_MHZ;
  1530. qFvco = wlc_lcnphy_qdiv_roundup(fvco3, 2, 16);
  1531. write_radio_reg(pi, RADIO_2064_REG04F, 0x02);
  1532. d15 = (pi->xtalfreq * fcal_div * 4 / 5) / PLL_2064_MHZ - 1;
  1533. write_radio_reg(pi, RADIO_2064_REG052, (0x07 & (d15 >> 2)));
  1534. write_radio_reg(pi, RADIO_2064_REG053, (d15 & 0x3) << 5);
  1535. d16 = (qFcal * 8 / (d15 + 1)) - 1;
  1536. write_radio_reg(pi, RADIO_2064_REG051, d16);
  1537. f16 = ((d16 + 1) * (d15 + 1)) / qFcal;
  1538. setCount = f16 * 3 * (ci->freq) / 32 - 1;
  1539. mod_radio_reg(pi, RADIO_2064_REG053, (0x0f << 0),
  1540. (u8) (setCount >> 8));
  1541. or_radio_reg(pi, RADIO_2064_REG053, 0x10);
  1542. write_radio_reg(pi, RADIO_2064_REG054, (u8) (setCount & 0xff));
  1543. div_int = ((fvco3 * (PLL_2064_MHZ >> 4)) / fref3) << 4;
  1544. div_frac = ((fvco3 * (PLL_2064_MHZ >> 4)) % fref3) << 4;
  1545. while (div_frac >= fref3) {
  1546. div_int++;
  1547. div_frac -= fref3;
  1548. }
  1549. div_frac = wlc_lcnphy_qdiv_roundup(div_frac, fref3, 20);
  1550. mod_radio_reg(pi, RADIO_2064_REG045, (0x1f << 0),
  1551. (u8) (div_int >> 4));
  1552. mod_radio_reg(pi, RADIO_2064_REG046, (0x1f << 4),
  1553. (u8) (div_int << 4));
  1554. mod_radio_reg(pi, RADIO_2064_REG046, (0x0f << 0),
  1555. (u8) (div_frac >> 16));
  1556. write_radio_reg(pi, RADIO_2064_REG047, (u8) (div_frac >> 8) & 0xff);
  1557. write_radio_reg(pi, RADIO_2064_REG048, (u8) div_frac & 0xff);
  1558. write_radio_reg(pi, RADIO_2064_REG040, 0xfb);
  1559. write_radio_reg(pi, RADIO_2064_REG041, 0x9A);
  1560. write_radio_reg(pi, RADIO_2064_REG042, 0xA3);
  1561. write_radio_reg(pi, RADIO_2064_REG043, 0x0C);
  1562. h29 = LCN_BW_LMT / loop_bw;
  1563. d28 = (((PLL_2064_HIGH_END_KVCO - PLL_2064_LOW_END_KVCO) *
  1564. (fvco3 / 2 - PLL_2064_LOW_END_VCO)) /
  1565. (PLL_2064_HIGH_END_VCO - PLL_2064_LOW_END_VCO))
  1566. + PLL_2064_LOW_END_KVCO;
  1567. h28_ten = (d28 * 10) / LCN_VCO_DIV;
  1568. e30 = (d30 - LCN_OFFSET) / LCN_FACT;
  1569. g30 = LCN_OFFSET + (e30 * LCN_FACT);
  1570. h30_ten = (g30 * 10) / LCN_CUR_DIV;
  1571. cp_current = ((LCN_CUR_LMT * h29 * LCN_MULT * 100) / h28_ten) / h30_ten;
  1572. mod_radio_reg(pi, RADIO_2064_REG03C, 0x3f, cp_current);
  1573. if (channel >= 1 && channel <= 5)
  1574. write_radio_reg(pi, RADIO_2064_REG03C, 0x8);
  1575. else
  1576. write_radio_reg(pi, RADIO_2064_REG03C, 0x7);
  1577. write_radio_reg(pi, RADIO_2064_REG03D, 0x3);
  1578. mod_radio_reg(pi, RADIO_2064_REG044, 0x0c, 0x0c);
  1579. udelay(1);
  1580. wlc_2064_vco_cal(pi);
  1581. write_radio_reg(pi, RADIO_2064_REG044, pll_pwrup);
  1582. write_radio_reg(pi, RADIO_2064_REG12B, pll_pwrup_ovr);
  1583. if (LCNREV_IS(pi->pubpi.phy_rev, 1)) {
  1584. write_radio_reg(pi, RADIO_2064_REG038, 3);
  1585. write_radio_reg(pi, RADIO_2064_REG091, 7);
  1586. }
  1587. if (!(pi->sh->boardflags & BFL_FEM)) {
  1588. static const u8 reg038[14] = {
  1589. 0xd, 0xe, 0xd, 0xd, 0xd, 0xc, 0xa,
  1590. 0xb, 0xb, 0x3, 0x3, 0x2, 0x0, 0x0
  1591. };
  1592. write_radio_reg(pi, RADIO_2064_REG02A, 0xf);
  1593. write_radio_reg(pi, RADIO_2064_REG091, 0x3);
  1594. write_radio_reg(pi, RADIO_2064_REG038, 0x3);
  1595. write_radio_reg(pi, RADIO_2064_REG038, reg038[channel - 1]);
  1596. }
  1597. }
  1598. static int
  1599. wlc_lcnphy_load_tx_iir_filter(struct brcms_phy *pi, bool is_ofdm, s16 filt_type)
  1600. {
  1601. s16 filt_index = -1;
  1602. int j;
  1603. u16 addr[] = {
  1604. 0x910,
  1605. 0x91e,
  1606. 0x91f,
  1607. 0x924,
  1608. 0x925,
  1609. 0x926,
  1610. 0x920,
  1611. 0x921,
  1612. 0x927,
  1613. 0x928,
  1614. 0x929,
  1615. 0x922,
  1616. 0x923,
  1617. 0x930,
  1618. 0x931,
  1619. 0x932
  1620. };
  1621. u16 addr_ofdm[] = {
  1622. 0x90f,
  1623. 0x900,
  1624. 0x901,
  1625. 0x906,
  1626. 0x907,
  1627. 0x908,
  1628. 0x902,
  1629. 0x903,
  1630. 0x909,
  1631. 0x90a,
  1632. 0x90b,
  1633. 0x904,
  1634. 0x905,
  1635. 0x90c,
  1636. 0x90d,
  1637. 0x90e
  1638. };
  1639. if (!is_ofdm) {
  1640. for (j = 0; j < LCNPHY_NUM_TX_DIG_FILTERS_CCK; j++) {
  1641. if (filt_type == LCNPHY_txdigfiltcoeffs_cck[j][0]) {
  1642. filt_index = (s16) j;
  1643. break;
  1644. }
  1645. }
  1646. if (filt_index != -1) {
  1647. for (j = 0; j < LCNPHY_NUM_DIG_FILT_COEFFS; j++)
  1648. write_phy_reg(pi, addr[j],
  1649. LCNPHY_txdigfiltcoeffs_cck
  1650. [filt_index][j + 1]);
  1651. }
  1652. } else {
  1653. for (j = 0; j < LCNPHY_NUM_TX_DIG_FILTERS_OFDM; j++) {
  1654. if (filt_type == LCNPHY_txdigfiltcoeffs_ofdm[j][0]) {
  1655. filt_index = (s16) j;
  1656. break;
  1657. }
  1658. }
  1659. if (filt_index != -1) {
  1660. for (j = 0; j < LCNPHY_NUM_DIG_FILT_COEFFS; j++)
  1661. write_phy_reg(pi, addr_ofdm[j],
  1662. LCNPHY_txdigfiltcoeffs_ofdm
  1663. [filt_index][j + 1]);
  1664. }
  1665. }
  1666. return (filt_index != -1) ? 0 : -1;
  1667. }
  1668. static u16 wlc_lcnphy_get_pa_gain(struct brcms_phy *pi)
  1669. {
  1670. u16 pa_gain;
  1671. pa_gain = (read_phy_reg(pi, 0x4fb) &
  1672. LCNPHY_txgainctrlovrval1_pagain_ovr_val1_MASK) >>
  1673. LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT;
  1674. return pa_gain;
  1675. }
  1676. static void wlc_lcnphy_set_tx_gain(struct brcms_phy *pi,
  1677. struct lcnphy_txgains *target_gains)
  1678. {
  1679. u16 pa_gain = wlc_lcnphy_get_pa_gain(pi);
  1680. mod_phy_reg(
  1681. pi, 0x4b5,
  1682. (0xffff << 0),
  1683. ((target_gains->gm_gain) |
  1684. (target_gains->pga_gain << 8)) <<
  1685. 0);
  1686. mod_phy_reg(pi, 0x4fb,
  1687. (0x7fff << 0),
  1688. ((target_gains->pad_gain) | (pa_gain << 8)) << 0);
  1689. mod_phy_reg(
  1690. pi, 0x4fc,
  1691. (0xffff << 0),
  1692. ((target_gains->gm_gain) |
  1693. (target_gains->pga_gain << 8)) <<
  1694. 0);
  1695. mod_phy_reg(pi, 0x4fd,
  1696. (0x7fff << 0),
  1697. ((target_gains->pad_gain) | (pa_gain << 8)) << 0);
  1698. wlc_lcnphy_set_dac_gain(pi, target_gains->dac_gain);
  1699. wlc_lcnphy_enable_tx_gain_override(pi);
  1700. }
  1701. static u8 wlc_lcnphy_get_bbmult(struct brcms_phy *pi)
  1702. {
  1703. u16 m0m1;
  1704. struct phytbl_info tab;
  1705. tab.tbl_ptr = &m0m1;
  1706. tab.tbl_len = 1;
  1707. tab.tbl_id = LCNPHY_TBL_ID_IQLOCAL;
  1708. tab.tbl_offset = 87;
  1709. tab.tbl_width = 16;
  1710. wlc_lcnphy_read_table(pi, &tab);
  1711. return (u8) ((m0m1 & 0xff00) >> 8);
  1712. }
  1713. static void wlc_lcnphy_set_bbmult(struct brcms_phy *pi, u8 m0)
  1714. {
  1715. u16 m0m1 = (u16) m0 << 8;
  1716. struct phytbl_info tab;
  1717. tab.tbl_ptr = &m0m1;
  1718. tab.tbl_len = 1;
  1719. tab.tbl_id = LCNPHY_TBL_ID_IQLOCAL;
  1720. tab.tbl_offset = 87;
  1721. tab.tbl_width = 16;
  1722. wlc_lcnphy_write_table(pi, &tab);
  1723. }
  1724. static void wlc_lcnphy_clear_tx_power_offsets(struct brcms_phy *pi)
  1725. {
  1726. u32 data_buf[64];
  1727. struct phytbl_info tab;
  1728. memset(data_buf, 0, sizeof(data_buf));
  1729. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  1730. tab.tbl_width = 32;
  1731. tab.tbl_ptr = data_buf;
  1732. if (!wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi)) {
  1733. tab.tbl_len = 30;
  1734. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_RATE_OFFSET;
  1735. wlc_lcnphy_write_table(pi, &tab);
  1736. }
  1737. tab.tbl_len = 64;
  1738. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_MAC_OFFSET;
  1739. wlc_lcnphy_write_table(pi, &tab);
  1740. }
  1741. enum lcnphy_tssi_mode {
  1742. LCNPHY_TSSI_PRE_PA,
  1743. LCNPHY_TSSI_POST_PA,
  1744. LCNPHY_TSSI_EXT
  1745. };
  1746. static void
  1747. wlc_lcnphy_set_tssi_mux(struct brcms_phy *pi, enum lcnphy_tssi_mode pos)
  1748. {
  1749. mod_phy_reg(pi, 0x4d7, (0x1 << 0), (0x1) << 0);
  1750. mod_phy_reg(pi, 0x4d7, (0x1 << 6), (1) << 6);
  1751. if (LCNPHY_TSSI_POST_PA == pos) {
  1752. mod_phy_reg(pi, 0x4d9, (0x1 << 2), (0) << 2);
  1753. mod_phy_reg(pi, 0x4d9, (0x1 << 3), (1) << 3);
  1754. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  1755. mod_radio_reg(pi, RADIO_2064_REG086, 0x4, 0x4);
  1756. } else {
  1757. mod_radio_reg(pi, RADIO_2064_REG03A, 1, 0x1);
  1758. mod_radio_reg(pi, RADIO_2064_REG11A, 0x8, 0x8);
  1759. mod_radio_reg(pi, RADIO_2064_REG028, 0x1, 0x0);
  1760. mod_radio_reg(pi, RADIO_2064_REG11A, 0x4, 1<<2);
  1761. mod_radio_reg(pi, RADIO_2064_REG036, 0x10, 0x0);
  1762. mod_radio_reg(pi, RADIO_2064_REG11A, 0x10, 1<<4);
  1763. mod_radio_reg(pi, RADIO_2064_REG036, 0x3, 0x0);
  1764. mod_radio_reg(pi, RADIO_2064_REG035, 0xff, 0x77);
  1765. mod_radio_reg(pi, RADIO_2064_REG028, 0x1e, 0xe<<1);
  1766. mod_radio_reg(pi, RADIO_2064_REG112, 0x80, 1<<7);
  1767. mod_radio_reg(pi, RADIO_2064_REG005, 0x7, 1<<1);
  1768. mod_radio_reg(pi, RADIO_2064_REG029, 0xf0, 0<<4);
  1769. }
  1770. } else {
  1771. mod_phy_reg(pi, 0x4d9, (0x1 << 2), (0x1) << 2);
  1772. mod_phy_reg(pi, 0x4d9, (0x1 << 3), (0) << 3);
  1773. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  1774. mod_radio_reg(pi, RADIO_2064_REG086, 0x4, 0x4);
  1775. } else {
  1776. mod_radio_reg(pi, RADIO_2064_REG03A, 1, 0);
  1777. mod_radio_reg(pi, RADIO_2064_REG11A, 0x8, 0x8);
  1778. }
  1779. }
  1780. mod_phy_reg(pi, 0x637, (0x3 << 14), (0) << 14);
  1781. if (LCNPHY_TSSI_EXT == pos) {
  1782. write_radio_reg(pi, RADIO_2064_REG07F, 1);
  1783. mod_radio_reg(pi, RADIO_2064_REG005, 0x7, 0x2);
  1784. mod_radio_reg(pi, RADIO_2064_REG112, 0x80, 0x1 << 7);
  1785. mod_radio_reg(pi, RADIO_2064_REG028, 0x1f, 0x3);
  1786. }
  1787. }
  1788. static u16 wlc_lcnphy_rfseq_tbl_adc_pwrup(struct brcms_phy *pi)
  1789. {
  1790. u16 N1, N2, N3, N4, N5, N6, N;
  1791. N1 = ((read_phy_reg(pi, 0x4a5) & (0xff << 0))
  1792. >> 0);
  1793. N2 = 1 << ((read_phy_reg(pi, 0x4a5) & (0x7 << 12))
  1794. >> 12);
  1795. N3 = ((read_phy_reg(pi, 0x40d) & (0xff << 0))
  1796. >> 0);
  1797. N4 = 1 << ((read_phy_reg(pi, 0x40d) &