25 #define AG_CONST 0.6072529350
26 #define FIXED(X) ((s32)((X) * 32768.0))
27 #define DEG2RAD(X) (0.017453 * (X))
29 static const s32 Angles[] = {
49 val = (data & 0x0FFF);
51 if ((data &
BIT(12)) != 0)
63 else if (data < -4096)
76 val = (data & 0x0007);
78 if ((data &
BIT(3)) != 0)
103 val = (data & 0x000F);
105 if ((data &
BIT(4)) != 0)
130 val = (data & 0x001F);
132 if ((data &
BIT(5)) != 0)
159 if ((data &
BIT(8)) != 0)
171 else if (data < -256)
200 int g0, g1, g2, g3, g4;
205 g4 = sqsum / 100000000;
206 g3 = (sqsum - g4*100000000) / 1000000;
207 g2 = (sqsum - g4*100000000 - g3*1000000) / 10000;
208 g1 = (sqsum - g4*100000000 - g3*1000000 - g2*10000) / 100;
209 g0 = (sqsum - g4*100000000 - g3*1000000 - g2*10000 - g1*100);
214 while (((seed+1)*(step+1)) <=
next) {
219 sq_rt = seed * 10000;
220 next = (next-(seed*
step))*100 + g3;
223 seed = 2 * seed * 10;
224 while (((seed+1)*(step+1)) <=
next) {
229 sq_rt = sq_rt + step * 1000;
230 next = (next - seed *
step) * 100 + g2;
231 seed = (seed +
step) * 10;
233 while (((seed+1)*(step+1)) <=
next) {
238 sq_rt = sq_rt + step * 100;
239 next = (next - seed *
step) * 100 + g1;
240 seed = (seed +
step) * 10;
243 while (((seed+1)*(step+1)) <=
next) {
248 sq_rt = sq_rt + step * 10;
249 next = (next - seed *
step) * 100 + g0;
250 seed = (seed +
step) * 10;
253 while (((seed+1)*(step+1)) <=
next) {
258 sq_rt = sq_rt +
step;
266 s32 X, Y, TargetAngle, CurrAngle;
271 TargetAngle =
abs(angle);
274 for (Step = 0; Step < 12; Step++) {
277 if (TargetAngle > CurrAngle) {
278 NewX = X - (Y >> Step);
281 CurrAngle += Angles[Step];
283 NewX = X + (Y >> Step);
284 Y = -(X >> Step) + Y;
286 CurrAngle -= Angles[Step];
299 static unsigned char hal_get_dxx_reg(
struct hw_data *pHwData,
u16 number,
u32 * pValue)
305 #define hw_get_dxx_reg(_A, _B, _C) hal_get_dxx_reg(_A, _B, (u32 *)_C)
316 #define hw_set_dxx_reg(_A, _B, _C) hal_set_dxx_reg(_A, _B, (u32)_C)
346 PHY_DEBUG((
"[CAL] -> [1]_rxadc_dc_offset_cancellation()\n"));
352 if ((frequency >= 2412) && (frequency <= 2484)) {
354 PHY_DEBUG((
"[CAL] W89RF242/11G/Channel=2390Mhz\n"));
375 reg_agc_ctrl3 &= ~
BIT(2);
405 PHY_DEBUG((
"[CAL] REG_OFFSET_READ = 0x%08X\n", val));
407 PHY_DEBUG((
"[CAL] ** adc_dc_cal_i = %d (0x%04X)\n",
409 PHY_DEBUG((
"[CAL] ** adc_dc_cal_q = %d (0x%04X)\n",
410 _s9_to_s32((val&0x0003FE00)>>9), (val&0x0003FE00)>>9));
428 reg_agc_ctrl3 |=
BIT(2);
444 s32 fix_cancel_dc_i = 0;
448 PHY_DEBUG((
"[CAL] -> [2]_txidac_dc_offset_cancellation()\n"));
467 reg_agc_ctrl3 &= ~
BIT(2);
478 PHY_DEBUG((
"[CAL] MODE_CTRL (read) = 0x%08X\n", reg_mode_ctrl));
490 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
493 PHY_DEBUG((
"[CAL] DC_CANCEL (read) = 0x%08X\n", reg_dc_cancel));
496 PHY_DEBUG((
"[CAL] [%d.] ==================================\n", loop));
499 reg_dc_cancel &= ~(0x03FF);
500 PHY_DEBUG((
"[CAL] DC_CANCEL (write) = 0x%08X\n", reg_dc_cancel));
504 PHY_DEBUG((
"[CAL] CALIB_READ2 = 0x%08X\n", val));
507 iqcal_image_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
508 sqsum = iqcal_image_i*iqcal_image_i + iqcal_image_q*iqcal_image_q;
510 PHY_DEBUG((
"[CAL] mag_0=%d (iqcal_image_i=%d, iqcal_image_q=%d)\n",
511 mag_0, iqcal_image_i, iqcal_image_q));
515 PHY_DEBUG((
"[CAL] DC_CANCEL (write) = 0x%08X\n", reg_dc_cancel));
519 PHY_DEBUG((
"[CAL] CALIB_READ2 = 0x%08X\n", val));
522 iqcal_image_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
523 sqsum = iqcal_image_i*iqcal_image_i + iqcal_image_q*iqcal_image_q;
525 PHY_DEBUG((
"[CAL] mag_1=%d (iqcal_image_i=%d, iqcal_image_q=%d)\n",
526 mag_1, iqcal_image_i, iqcal_image_q));
530 fix_cancel_dc_i = (mag_0*10000) / (mag_0*10000 - mag_1*10000);
533 PHY_DEBUG((
"[CAL] ***** mag_0 = mag_1 !!\n"));
537 PHY_DEBUG((
"[CAL] ** fix_cancel_dc_i = %d (0x%04X)\n",
538 fix_cancel_dc_i,
_s32_to_s5(fix_cancel_dc_i)));
540 if ((
abs(mag_1-mag_0)*6) > mag_0)
547 reg_dc_cancel &= ~(0x03FF);
550 PHY_DEBUG((
"[CAL] DC_CANCEL (write) = 0x%08X\n", reg_dc_cancel));
555 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
569 s32 fix_cancel_dc_q = 0;
573 PHY_DEBUG((
"[CAL] -> [3]_txqdac_dc_offset_cacellation()\n"));
589 reg_agc_ctrl3 &= ~
BIT(2);
599 PHY_DEBUG((
"[CAL] MODE_CTRL (read) = 0x%08X\n", reg_mode_ctrl));
605 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
608 PHY_DEBUG((
"[CAL] DC_CANCEL (read) = 0x%08X\n", reg_dc_cancel));
611 PHY_DEBUG((
"[CAL] [%d.] ==================================\n", loop));
614 reg_dc_cancel &= ~(0x001F);
615 PHY_DEBUG((
"[CAL] DC_CANCEL (write) = 0x%08X\n", reg_dc_cancel));
619 PHY_DEBUG((
"[CAL] CALIB_READ2 = 0x%08X\n", val));
622 iqcal_image_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
623 sqsum = iqcal_image_i*iqcal_image_i + iqcal_image_q*iqcal_image_q;
624 mag_0 =
_sqrt(sqsum);
625 PHY_DEBUG((
"[CAL] mag_0=%d (iqcal_image_i=%d, iqcal_image_q=%d)\n",
626 mag_0, iqcal_image_i, iqcal_image_q));
630 PHY_DEBUG((
"[CAL] DC_CANCEL (write) = 0x%08X\n", reg_dc_cancel));
634 PHY_DEBUG((
"[CAL] CALIB_READ2 = 0x%08X\n", val));
637 iqcal_image_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
638 sqsum = iqcal_image_i*iqcal_image_i + iqcal_image_q*iqcal_image_q;
639 mag_1 =
_sqrt(sqsum);
640 PHY_DEBUG((
"[CAL] mag_1=%d (iqcal_image_i=%d, iqcal_image_q=%d)\n",
641 mag_1, iqcal_image_i, iqcal_image_q));
645 fix_cancel_dc_q = (mag_0*10000) / (mag_0*10000 - mag_1*10000);
648 PHY_DEBUG((
"[CAL] ***** mag_0 = mag_1 !!\n"));
652 PHY_DEBUG((
"[CAL] ** fix_cancel_dc_q = %d (0x%04X)\n",
653 fix_cancel_dc_q,
_s32_to_s5(fix_cancel_dc_q)));
655 if ((
abs(mag_1-mag_0)*6) > mag_0)
662 reg_dc_cancel &= ~(0x001F);
665 PHY_DEBUG((
"[CAL] DC_CANCEL (write) = 0x%08X\n", reg_dc_cancel));
671 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
698 s32 iqcal_tone_i_avg, iqcal_tone_q_avg;
702 PHY_DEBUG((
"[CAL] -> _tx_iq_calibration_loop()\n"));
703 PHY_DEBUG((
"[CAL] ** a_2_threshold = %d\n", a_2_threshold));
704 PHY_DEBUG((
"[CAL] ** b_2_threshold = %d\n", b_2_threshold));
709 PHY_DEBUG((
"[CAL] MODE_CTRL (read) = 0x%08X\n", reg_mode_ctrl));
716 iqcal_tone_i_avg = 0;
717 iqcal_tone_q_avg = 0;
720 for (capture_time = 0; capture_time < 10; capture_time++) {
730 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
734 PHY_DEBUG((
"[CAL] CALIB_READ1 = 0x%08X\n", val));
737 iqcal_tone_q0 =
_s13_to_s32((val & 0x03FFE000) >> 13);
738 PHY_DEBUG((
"[CAL] ** iqcal_tone_i0=%d, iqcal_tone_q0=%d\n",
739 iqcal_tone_i0, iqcal_tone_q0));
741 sqsum = iqcal_tone_i0*iqcal_tone_i0 +
742 iqcal_tone_q0*iqcal_tone_q0;
744 PHY_DEBUG((
"[CAL] ** iq_mag_0_tx=%d\n", iq_mag_0_tx));
749 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
760 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
764 PHY_DEBUG((
"[CAL] CALIB_READ1 = 0x%08X\n", val));
767 iqcal_tone_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
768 PHY_DEBUG((
"[CAL] ** iqcal_tone_i = %d, iqcal_tone_q = %d\n",
769 iqcal_tone_i, iqcal_tone_q));
770 if (capture_time == 0)
773 iqcal_tone_i_avg = (iqcal_tone_i_avg*(capture_time-1) + iqcal_tone_i)/capture_time;
774 iqcal_tone_q_avg = (iqcal_tone_q_avg*(capture_time-1) + iqcal_tone_q)/capture_time;
778 iqcal_tone_i = iqcal_tone_i_avg;
779 iqcal_tone_q = iqcal_tone_q_avg;
782 rot_i_b = (iqcal_tone_i * iqcal_tone_i0 +
783 iqcal_tone_q * iqcal_tone_q0) / 1024;
784 rot_q_b = (iqcal_tone_i * iqcal_tone_q0 * (-1) +
785 iqcal_tone_q * iqcal_tone_i0) / 1024;
786 PHY_DEBUG((
"[CAL] ** rot_i_b = %d, rot_q_b = %d\n",
790 divisor = ((iq_mag_0_tx * iq_mag_0_tx * 2)/1024 - rot_i_b) * 2;
793 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration_loop> ERROR *******\n"));
794 PHY_DEBUG((
"[CAL] ** divisor=0 to calculate EPS and THETA !!\n"));
795 PHY_DEBUG((
"[CAL] ******************************************\n"));
799 a_2 = (rot_i_b * 32768) / divisor;
800 b_2 = (rot_q_b * (-32768)) /
divisor;
801 PHY_DEBUG((
"[CAL] ***** EPSILON/2 = %d\n", a_2));
802 PHY_DEBUG((
"[CAL] ***** THETA/2 = %d\n", b_2));
809 if ((
abs(a_2) < a_2_threshold) && (
abs(b_2) < b_2_threshold)) {
812 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration_loop> *************\n"));
813 PHY_DEBUG((
"[CAL] ** VERIFY OK # %d !!\n", verify_count));
814 PHY_DEBUG((
"[CAL] ******************************************\n"));
816 if (verify_count > 2) {
817 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration_loop> *********\n"));
818 PHY_DEBUG((
"[CAL] ** TX_IQ_CALIBRATION (EPS,THETA) OK !!\n"));
819 PHY_DEBUG((
"[CAL] **************************************\n"));
829 PHY_DEBUG((
"[CAL] ** sin(b/2)=%d, cos(b/2)=%d\n", sin_b, cos_b));
830 PHY_DEBUG((
"[CAL] ** sin(b)=%d, cos(b)=%d\n", sin_2b, cos_2b));
833 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration_loop> ERROR *******\n"));
835 PHY_DEBUG((
"[CAL] ******************************************\n"));
840 temp1 = (41943040/cos_2b)*cos_b;
844 temp2 = (41943040/cos_2b)*sin_b*(-1);
846 temp2 = (41943040*4/cos_2b)*sin_b*(-1);
848 tx_cal_flt_b[0] =
_floor(temp1/(32768+a_2));
849 tx_cal_flt_b[1] =
_floor(temp2/(32768+a_2));
850 tx_cal_flt_b[2] =
_floor(temp2/(32768-a_2));
851 tx_cal_flt_b[3] =
_floor(temp1/(32768-a_2));
852 PHY_DEBUG((
"[CAL] ** tx_cal_flt_b[0] = %d\n", tx_cal_flt_b[0]));
853 PHY_DEBUG((
"[CAL] tx_cal_flt_b[1] = %d\n", tx_cal_flt_b[1]));
854 PHY_DEBUG((
"[CAL] tx_cal_flt_b[2] = %d\n", tx_cal_flt_b[2]));
855 PHY_DEBUG((
"[CAL] tx_cal_flt_b[3] = %d\n", tx_cal_flt_b[3]));
857 tx_cal[2] = tx_cal_flt_b[2];
858 tx_cal[2] = tx_cal[2] + 3;
859 tx_cal[1] = tx_cal[2];
860 tx_cal[3] = tx_cal_flt_b[3] - 128;
861 tx_cal[0] = -tx_cal[3] + 1;
863 PHY_DEBUG((
"[CAL] tx_cal[0] = %d\n", tx_cal[0]));
864 PHY_DEBUG((
"[CAL] tx_cal[1] = %d\n", tx_cal[1]));
865 PHY_DEBUG((
"[CAL] tx_cal[2] = %d\n", tx_cal[2]));
866 PHY_DEBUG((
"[CAL] tx_cal[3] = %d\n", tx_cal[3]));
880 PHY_DEBUG((
"[CAL] ** 0x54 = 0x%08X\n", val));
881 tx_cal_reg[0] =
_s4_to_s32((val & 0xF0000000) >> 28);
882 tx_cal_reg[1] =
_s4_to_s32((val & 0x0F000000) >> 24);
883 tx_cal_reg[2] =
_s4_to_s32((val & 0x00F00000) >> 20);
884 tx_cal_reg[3] =
_s4_to_s32((val & 0x000F0000) >> 16);
887 PHY_DEBUG((
"[CAL] ** 0x3C = 0x%08X\n", val));
888 tx_cal_reg[0] =
_s5_to_s32((val & 0xF8000000) >> 27);
889 tx_cal_reg[1] =
_s6_to_s32((val & 0x07E00000) >> 21);
890 tx_cal_reg[2] =
_s6_to_s32((val & 0x001F8000) >> 15);
891 tx_cal_reg[3] =
_s5_to_s32((val & 0x00007C00) >> 10);
895 PHY_DEBUG((
"[CAL] ** tx_cal_reg[0] = %d\n", tx_cal_reg[0]));
896 PHY_DEBUG((
"[CAL] tx_cal_reg[1] = %d\n", tx_cal_reg[1]));
897 PHY_DEBUG((
"[CAL] tx_cal_reg[2] = %d\n", tx_cal_reg[2]));
898 PHY_DEBUG((
"[CAL] tx_cal_reg[3] = %d\n", tx_cal_reg[3]));
901 if (((tx_cal_reg[0] == 7) || (tx_cal_reg[0] == (-8))) &&
902 ((tx_cal_reg[3] == 7) || (tx_cal_reg[3] == (-8)))) {
903 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration_loop> *********\n"));
904 PHY_DEBUG((
"[CAL] ** TX_IQ_CALIBRATION SATUATION !!\n"));
905 PHY_DEBUG((
"[CAL] **************************************\n"));
909 if (((tx_cal_reg[0] == 31) || (tx_cal_reg[0] == (-32))) &&
910 ((tx_cal_reg[3] == 31) || (tx_cal_reg[3] == (-32)))) {
911 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration_loop> *********\n"));
912 PHY_DEBUG((
"[CAL] ** TX_IQ_CALIBRATION SATUATION !!\n"));
913 PHY_DEBUG((
"[CAL] **************************************\n"));
918 tx_cal[0] = tx_cal[0] + tx_cal_reg[0];
919 tx_cal[1] = tx_cal[1] + tx_cal_reg[1];
920 tx_cal[2] = tx_cal[2] + tx_cal_reg[2];
921 tx_cal[3] = tx_cal[3] + tx_cal_reg[3];
922 PHY_DEBUG((
"[CAL] ** apply tx_cal[0] = %d\n", tx_cal[0]));
923 PHY_DEBUG((
"[CAL] apply tx_cal[1] = %d\n", tx_cal[1]));
924 PHY_DEBUG((
"[CAL] apply tx_cal[2] = %d\n", tx_cal[2]));
925 PHY_DEBUG((
"[CAL] apply tx_cal[3] = %d\n", tx_cal[3]));
934 PHY_DEBUG((
"[CAL] ** CALIB_DATA = 0x%08X\n", val));
943 PHY_DEBUG((
"[CAL] ** TX_IQ_CALIBRATION = 0x%08X\n", val));
950 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
969 PHY_DEBUG((
"[CAL] -> [4]_tx_iq_calibration()\n"));
992 reg_agc_ctrl3 &= ~
BIT(2);
1003 if (phw_data->
revision == 0x2002) {
1016 if (phw_data->
revision == 0x2002) {
1028 if (phw_data->
revision == 0x2002) {
1042 PHY_DEBUG((
"[CAL] ** <_tx_iq_calibration> **************\n"));
1043 PHY_DEBUG((
"[CAL] ** TX_IQ_CALIBRATION FAILURE !!\n"));
1044 PHY_DEBUG((
"[CAL] **************************************\n"));
1046 if (phw_data->
revision == 0x2002) {
1064 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
1068 reg_agc_ctrl3 |=
BIT(2);
1073 if (phw_data->
revision == 0x2002) {
1075 PHY_DEBUG((
"[CAL] ** 0x54 = 0x%08X\n", val));
1076 tx_cal_reg[0] =
_s4_to_s32((val & 0xF0000000) >> 28);
1077 tx_cal_reg[1] =
_s4_to_s32((val & 0x0F000000) >> 24);
1078 tx_cal_reg[2] =
_s4_to_s32((val & 0x00F00000) >> 20);
1079 tx_cal_reg[3] =
_s4_to_s32((val & 0x000F0000) >> 16);
1082 PHY_DEBUG((
"[CAL] ** 0x3C = 0x%08X\n", val));
1083 tx_cal_reg[0] =
_s5_to_s32((val & 0xF8000000) >> 27);
1084 tx_cal_reg[1] =
_s6_to_s32((val & 0x07E00000) >> 21);
1085 tx_cal_reg[2] =
_s6_to_s32((val & 0x001F8000) >> 15);
1086 tx_cal_reg[3] =
_s5_to_s32((val & 0x00007C00) >> 10);
1090 PHY_DEBUG((
"[CAL] ** tx_cal_reg[0] = %d\n", tx_cal_reg[0]));
1091 PHY_DEBUG((
"[CAL] tx_cal_reg[1] = %d\n", tx_cal_reg[1]));
1092 PHY_DEBUG((
"[CAL] tx_cal_reg[2] = %d\n", tx_cal_reg[2]));
1093 PHY_DEBUG((
"[CAL] tx_cal_reg[3] = %d\n", tx_cal_reg[3]));
1115 s32 rx_cal_flt_b[4];
1129 s32 iqcal_tone_i_avg, iqcal_tone_q_avg;
1130 s32 iqcal_image_i_avg, iqcal_image_q_avg;
1133 PHY_DEBUG((
"[CAL] -> [5]_rx_iq_calibration_loop()\n"));
1134 PHY_DEBUG((
"[CAL] ** factor = %d\n", factor));
1141 PHY_DEBUG((
"[CAL] MODE_CTRL (read) = 0x%08X\n", reg_mode_ctrl));
1150 iqcal_tone_i_avg = 0;
1151 iqcal_tone_q_avg = 0;
1152 iqcal_image_i_avg = 0;
1153 iqcal_image_q_avg = 0;
1156 for (capture_time = 0; capture_time < 10; capture_time++) {
1161 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
1166 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
1170 PHY_DEBUG((
"[CAL] CALIB_READ1 = 0x%08X\n", val));
1173 iqcal_tone_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
1174 PHY_DEBUG((
"[CAL] ** iqcal_tone_i = %d, iqcal_tone_q = %d\n",
1175 iqcal_tone_i, iqcal_tone_q));
1178 PHY_DEBUG((
"[CAL] CALIB_READ2 = 0x%08X\n", val));
1181 iqcal_image_q =
_s13_to_s32((val & 0x03FFE000) >> 13);
1182 PHY_DEBUG((
"[CAL] ** iqcal_image_i = %d, iqcal_image_q = %d\n",
1183 iqcal_image_i, iqcal_image_q));
1184 if (capture_time == 0)
1187 iqcal_image_i_avg = (iqcal_image_i_avg*(capture_time-1) + iqcal_image_i)/capture_time;
1188 iqcal_image_q_avg = (iqcal_image_q_avg*(capture_time-1) + iqcal_image_q)/capture_time;
1189 iqcal_tone_i_avg = (iqcal_tone_i_avg*(capture_time-1) + iqcal_tone_i)/capture_time;
1190 iqcal_tone_q_avg = (iqcal_tone_q_avg*(capture_time-1) + iqcal_tone_q)/capture_time;
1195 iqcal_image_i = iqcal_image_i_avg;
1196 iqcal_image_q = iqcal_image_q_avg;
1197 iqcal_tone_i = iqcal_tone_i_avg;
1198 iqcal_tone_q = iqcal_tone_q_avg;
1201 rot_tone_i_b = (iqcal_tone_i * iqcal_tone_i +
1202 iqcal_tone_q * iqcal_tone_q) / 1024;
1203 rot_tone_q_b = (iqcal_tone_i * iqcal_tone_q * (-1) +
1204 iqcal_tone_q * iqcal_tone_i) / 1024;
1205 rot_image_i_b = (iqcal_image_i * iqcal_tone_i -
1206 iqcal_image_q * iqcal_tone_q) / 1024;
1207 rot_image_q_b = (iqcal_image_i * iqcal_tone_q +
1208 iqcal_image_q * iqcal_tone_i) / 1024;
1210 PHY_DEBUG((
"[CAL] ** rot_tone_i_b = %d\n", rot_tone_i_b));
1211 PHY_DEBUG((
"[CAL] ** rot_tone_q_b = %d\n", rot_tone_q_b));
1212 PHY_DEBUG((
"[CAL] ** rot_image_i_b = %d\n", rot_image_i_b));
1213 PHY_DEBUG((
"[CAL] ** rot_image_q_b = %d\n", rot_image_q_b));
1216 if (rot_tone_i_b == 0) {
1217 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration_loop> ERROR *******\n"));
1218 PHY_DEBUG((
"[CAL] ** rot_tone_i_b=0 to calculate EPS and THETA !!\n"));
1219 PHY_DEBUG((
"[CAL] ******************************************\n"));
1223 a_2 = (rot_image_i_b * 32768) / rot_tone_i_b -
1225 b_2 = (rot_image_q_b * 32768) / rot_tone_i_b -
1230 PHY_DEBUG((
"[CAL] ***** EPSILON/2 = %d\n", a_2));
1231 PHY_DEBUG((
"[CAL] ***** THETA/2 = %d\n", b_2));
1235 PHY_DEBUG((
"[CAL] ** sin(b/2)=%d, cos(b/2)=%d\n", sin_b, cos_b));
1236 PHY_DEBUG((
"[CAL] ** sin(b)=%d, cos(b)=%d\n", sin_2b, cos_2b));
1239 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration_loop> ERROR *******\n"));
1241 PHY_DEBUG((
"[CAL] ******************************************\n"));
1246 temp1 = (41943040/cos_2b)*cos_b;
1250 temp2 = (41943040/cos_2b)*sin_b*(-1);
1252 temp2 = (41943040*4/cos_2b)*sin_b*(-1);
1254 rx_cal_flt_b[0] =
_floor(temp1/(32768+a_2));
1255 rx_cal_flt_b[1] =
_floor(temp2/(32768-a_2));
1256 rx_cal_flt_b[2] =
_floor(temp2/(32768+a_2));
1257 rx_cal_flt_b[3] =
_floor(temp1/(32768-a_2));
1259 PHY_DEBUG((
"[CAL] ** rx_cal_flt_b[0] = %d\n", rx_cal_flt_b[0]));
1260 PHY_DEBUG((
"[CAL] rx_cal_flt_b[1] = %d\n", rx_cal_flt_b[1]));
1261 PHY_DEBUG((
"[CAL] rx_cal_flt_b[2] = %d\n", rx_cal_flt_b[2]));
1262 PHY_DEBUG((
"[CAL] rx_cal_flt_b[3] = %d\n", rx_cal_flt_b[3]));
1264 rx_cal[0] = rx_cal_flt_b[0] - 128;
1265 rx_cal[1] = rx_cal_flt_b[1];
1266 rx_cal[2] = rx_cal_flt_b[2];
1267 rx_cal[3] = rx_cal_flt_b[3] - 128;
1268 PHY_DEBUG((
"[CAL] ** rx_cal[0] = %d\n", rx_cal[0]));
1269 PHY_DEBUG((
"[CAL] rx_cal[1] = %d\n", rx_cal[1]));
1270 PHY_DEBUG((
"[CAL] rx_cal[2] = %d\n", rx_cal[2]));
1271 PHY_DEBUG((
"[CAL] rx_cal[3] = %d\n", rx_cal[3]));
1274 pwr_tone = (iqcal_tone_i*iqcal_tone_i + iqcal_tone_q*iqcal_tone_q);
1275 pwr_image = (iqcal_image_i*iqcal_image_i + iqcal_image_q*iqcal_image_q)*factor;
1277 PHY_DEBUG((
"[CAL] ** pwr_tone = %d\n", pwr_tone));
1278 PHY_DEBUG((
"[CAL] ** pwr_image = %d\n", pwr_image));
1280 if (pwr_tone > pwr_image) {
1283 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration_loop> *************\n"));
1284 PHY_DEBUG((
"[CAL] ** VERIFY OK # %d !!\n", verify_count));
1285 PHY_DEBUG((
"[CAL] ******************************************\n"));
1287 if (verify_count > 2) {
1288 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration_loop> *********\n"));
1289 PHY_DEBUG((
"[CAL] ** RX_IQ_CALIBRATION OK !!\n"));
1290 PHY_DEBUG((
"[CAL] **************************************\n"));
1298 PHY_DEBUG((
"[CAL] ** 0x54 = 0x%08X\n", val));
1300 if (phw_data->
revision == 0x2002) {
1301 rx_cal_reg[0] =
_s4_to_s32((val & 0x0000F000) >> 12);
1302 rx_cal_reg[1] =
_s4_to_s32((val & 0x00000F00) >> 8);
1303 rx_cal_reg[2] =
_s4_to_s32((val & 0x000000F0) >> 4);
1304 rx_cal_reg[3] =
_s4_to_s32((val & 0x0000000F));
1306 rx_cal_reg[0] =
_s5_to_s32((val & 0xF8000000) >> 27);
1307 rx_cal_reg[1] =
_s6_to_s32((val & 0x07E00000) >> 21);
1308 rx_cal_reg[2] =
_s6_to_s32((val & 0x001F8000) >> 15);
1309 rx_cal_reg[3] =
_s5_to_s32((val & 0x00007C00) >> 10);
1312 PHY_DEBUG((
"[CAL] ** rx_cal_reg[0] = %d\n", rx_cal_reg[0]));
1313 PHY_DEBUG((
"[CAL] rx_cal_reg[1] = %d\n", rx_cal_reg[1]));
1314 PHY_DEBUG((
"[CAL] rx_cal_reg[2] = %d\n", rx_cal_reg[2]));
1315 PHY_DEBUG((
"[CAL] rx_cal_reg[3] = %d\n", rx_cal_reg[3]));
1317 if (phw_data->
revision == 0x2002) {
1318 if (((rx_cal_reg[0] == 7) || (rx_cal_reg[0] == (-8))) &&
1319 ((rx_cal_reg[3] == 7) || (rx_cal_reg[3] == (-8)))) {
1320 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration_loop> *********\n"));
1321 PHY_DEBUG((
"[CAL] ** RX_IQ_CALIBRATION SATUATION !!\n"));
1322 PHY_DEBUG((
"[CAL] **************************************\n"));
1326 if (((rx_cal_reg[0] == 31) || (rx_cal_reg[0] == (-32))) &&
1327 ((rx_cal_reg[3] == 31) || (rx_cal_reg[3] == (-32)))) {
1328 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration_loop> *********\n"));
1329 PHY_DEBUG((
"[CAL] ** RX_IQ_CALIBRATION SATUATION !!\n"));
1330 PHY_DEBUG((
"[CAL] **************************************\n"));
1335 rx_cal[0] = rx_cal[0] + rx_cal_reg[0];
1336 rx_cal[1] = rx_cal[1] + rx_cal_reg[1];
1337 rx_cal[2] = rx_cal[2] + rx_cal_reg[2];
1338 rx_cal[3] = rx_cal[3] + rx_cal_reg[3];
1339 PHY_DEBUG((
"[CAL] ** apply rx_cal[0] = %d\n", rx_cal[0]));
1340 PHY_DEBUG((
"[CAL] apply rx_cal[1] = %d\n", rx_cal[1]));
1341 PHY_DEBUG((
"[CAL] apply rx_cal[2] = %d\n", rx_cal[2]));
1342 PHY_DEBUG((
"[CAL] apply rx_cal[3] = %d\n", rx_cal[3]));
1345 if (phw_data->
revision == 0x2002) {
1363 PHY_DEBUG((
"[CAL] ** CALIB_DATA = 0x%08X\n", val));
1384 PHY_DEBUG((
"[CAL] -> [5]_rx_iq_calibration()\n"));
1413 PHY_DEBUG((
"[CAL] ** <_rx_iq_calibration> **************\n"));
1414 PHY_DEBUG((
"[CAL] ** RX_IQ_CALIBRATION FAILURE !!\n"));
1415 PHY_DEBUG((
"[CAL] **************************************\n"));
1423 PHY_DEBUG((
"[CAL] ** 0x54 = 0x%08X\n", val));
1425 if (phw_data->
revision == 0x2002) {
1426 rx_cal_reg[0] =
_s4_to_s32((val & 0x0000F000) >> 12);
1427 rx_cal_reg[1] =
_s4_to_s32((val & 0x00000F00) >> 8);
1428 rx_cal_reg[2] =
_s4_to_s32((val & 0x000000F0) >> 4);
1429 rx_cal_reg[3] =
_s4_to_s32((val & 0x0000000F));
1431 rx_cal_reg[0] =
_s5_to_s32((val & 0xF8000000) >> 27);
1432 rx_cal_reg[1] =
_s6_to_s32((val & 0x07E00000) >> 21);
1433 rx_cal_reg[2] =
_s6_to_s32((val & 0x001F8000) >> 15);
1434 rx_cal_reg[3] =
_s5_to_s32((val & 0x00007C00) >> 10);
1437 PHY_DEBUG((
"[CAL] ** rx_cal_reg[0] = %d\n", rx_cal_reg[0]));
1438 PHY_DEBUG((
"[CAL] rx_cal_reg[1] = %d\n", rx_cal_reg[1]));
1439 PHY_DEBUG((
"[CAL] rx_cal_reg[2] = %d\n", rx_cal_reg[2]));
1440 PHY_DEBUG((
"[CAL] rx_cal_reg[3] = %d\n", rx_cal_reg[3]));
1451 PHY_DEBUG((
"[CAL] -> phy_calibration_winbond()\n"));
1466 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
1484 ltmp = (1 << 31) | (0 << 30) | (18 << 24) |
BitReverse(value, 18);
1488 ltmp = (1 << 31) | (0 << 30) | (18 << 24) |
BitReverse(value, 18);
1492 ltmp = (1 << 31) | (0 << 30) | (18 << 24) |
BitReverse(value, 18);
1496 ltmp = (1 << 31) | (0 << 30) | (18 << 24) |
BitReverse(value, 18);
1501 ltmp = (1 << 31) | (0 << 30) | (20 << 24) |
BitReverse(value, 20);
1505 ltmp = (1 << 31) | (0 << 30) | (24 << 24) | (value&0xffffff);
1510 ltmp = (1 << 31) | (0 << 30) | (24 << 24) |
BitReverse(value, 24);
1532 for (init_txvga = 0; init_txvga < 10; init_txvga++) {
1533 current_txvga = (0x24C40A|(init_txvga<<6));
1542 PHY_DEBUG((
"[CAL] MODE_CTRL (read) = 0x%08X\n", reg_mode_ctrl));
1553 PHY_DEBUG((
"[CAL] MODE_CTRL (write) = 0x%08X\n", reg_mode_ctrl));
1562 PHY_DEBUG((
"[CAL] CALIB_READ1 = 0x%08X\n", val));
1566 iqcal_tone_q0 =
_s13_to_s32((val & 0x03FFE000) >> 13);
1567 PHY_DEBUG((
"[CAL] ** iqcal_tone_i0=%d, iqcal_tone_q0=%d\n",
1568 iqcal_tone_i0, iqcal_tone_q0));
1570 sqsum = iqcal_tone_i0*iqcal_tone_i0 + iqcal_tone_q0*iqcal_tone_q0;
1572 PHY_DEBUG((
"[CAL] ** auto_adjust_txvga_for_iq_mag_0_tx=%d\n", iq_mag_0_tx));
1574 if (iq_mag_0_tx >= 700 && iq_mag_0_tx <= 1750)
1576 else if (iq_mag_0_tx > 1750) {
1584 if (iq_mag_0_tx >= 700 && iq_mag_0_tx <= 1750)