| Linux kernel & device driver programming |
| [ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] |
1 /* 1
2 * phy_302_calibration.c
3 *
4 * Copyright (C) 2002, 2005 Winbond Electroni
5 *
6 * modification history
7 * -------------------------------------------
8 * 0.01.001, 2003-04-16, Kevin created
9 *
10 */
11
12 /****************** INCLUDE FILES SECTION ****
13 #include "sysdef.h"
14 #include "phy_calibration.h"
15 #include "wbhal_f.h"
16
17
18 /****************** DEBUG CONSTANT AND MACRO S
19
20 /****************** LOCAL CONSTANT AND MACRO S
21 #define LOOP_TIMES 20
22 #define US 1000//MICROSECOND
23
24 #define AG_CONST 0.6072529350
25 #define FIXED(X) ((s32)((X) * 32768.0))
26 #define DEG2RAD(X) 0.017453 * (X)
27
28 /****************** LOCAL TYPE DEFINITION SECT
29 typedef s32 fixed; /* 16.16 fixed-poin
30
31 static const fixed Angles[]=
32 {
33 FIXED(DEG2RAD(45.0)), FIXED(DEG2RAD(26.
34 FIXED(DEG2RAD(7.12502)), FIXED(DEG2RAD(3.5
35 FIXED(DEG2RAD(0.895174)),FIXED(DEG2RAD(0.4
36 FIXED(DEG2RAD(0.111906)),FIXED(DEG2RAD(0.0
37 };
38
39 /****************** LOCAL FUNCTION DECLARATION
40 //void _phy_rf_write_delay(struct hw_data *
41 //void phy_init_rf(struct hw_data *phw_data
42
43 /****************** FUNCTION DEFINITION SECTIO
44
45 s32 _s13_to_s32(u32 data)
46 {
47 u32 val;
48
49 val = (data & 0x0FFF);
50
51 if ((data & BIT(12)) != 0)
52 {
53 val |= 0xFFFFF000;
54 }
55
56 return ((s32) val);
57 }
58
59 u32 _s32_to_s13(s32 data)
60 {
61 u32 val;
62
63 if (data > 4095)
64 {
65 data = 4095;
66 }
67 else if (data < -4096)
68 {
69 data = -4096;
70 }
71
72 val = data & 0x1FFF;
73
74 return val;
75 }
76
77 /*********************************************
78 s32 _s4_to_s32(u32 data)
79 {
80 s32 val;
81
82 val = (data & 0x0007);
83
84 if ((data & BIT(3)) != 0)
85 {
86 val |= 0xFFFFFFF8;
87 }
88
89 return val;
90 }
91
92 u32 _s32_to_s4(s32 data)
93 {
94 u32 val;
95
96 if (data > 7)
97 {
98 data = 7;
99 }
100 else if (data < -8)
101 {
102 data = -8;
103 }
104
105 val = data & 0x000F;
106
107 return val;
108 }
109
110 /*********************************************
111 s32 _s5_to_s32(u32 data)
112 {
113 s32 val;
114
115 val = (data & 0x000F);
116
117 if ((data & BIT(4)) != 0)
118 {
119 val |= 0xFFFFFFF0;
120 }
121
122 return val;
123 }
124
125 u32 _s32_to_s5(s32 data)
126 {
127 u32 val;
128
129 if (data > 15)
130 {
131 data = 15;
132 }
133 else if (data < -16)
134 {
135 data = -16;
136 }
137
138 val = data & 0x001F;
139
140 return val;
141 }
142
143 /*********************************************
144 s32 _s6_to_s32(u32 data)
145 {
146 s32 val;
147
148 val = (data & 0x001F);
149
150 if ((data & BIT(5)) != 0)
151 {
152 val |= 0xFFFFFFE0;
153 }
154
155 return val;
156 }
157
158 u32 _s32_to_s6(s32 data)
159 {
160 u32 val;
161
162 if (data > 31)
163 {
164 data = 31;
165 }
166 else if (data < -32)
167 {
168 data = -32;
169 }
170
171 val = data & 0x003F;
172
173 return val;
174 }
175
176 /*********************************************
177 s32 _s9_to_s32(u32 data)
178 {
179 s32 val;
180
181 val = data & 0x00FF;
182
183 if ((data & BIT(8)) != 0)
184 {
185 val |= 0xFFFFFF00;
186 }
187
188 return val;
189 }
190
191 u32 _s32_to_s9(s32 data)
192 {
193 u32 val;
194
195 if (data > 255)
196 {
197 data = 255;
198 }
199 else if (data < -256)
200 {
201 data = -256;
202 }
203
204 val = data & 0x01FF;
205
206 return val;
207 }
208
209 /*********************************************
210 s32 _floor(s32 n)
211 {
212 if (n > 0)
213 {
214 n += 5;
215 }
216 else
217 {
218 n -= 5;
219 }
220
221 return (n/10);
222 }
223
224 /*********************************************
225 // The following code is sqare-root function.
226 // sqsum is the input and the output is sq_rt;
227 // The maximum of sqsum = 2^27 -1;
228 u32 _sqrt(u32 sqsum)
229 {
230 u32 sq_rt;
231
232 int g0, g1, g2, g3, g4;
233 int seed;
234 int next;
235 int step;
236
237 g4 = sqsum / 100000000;
238 g3 = (sqsum - g4*100000000) /1000000;
239 g2 = (sqsum - g4*100000000 - g3*1000000) /
240 g1 = (sqsum - g4*100000000 - g3*1000000 -
241 g0 = (sqsum - g4*100000000 - g3*1000000 -
242
243 next = g4;
244 step = 0;
245 seed = 0;
246 while (((seed+1)*(step+1)) <= next)
247 {
248 step++;
249 seed++;
250 }
251
252 sq_rt = seed * 10000;
253 next = (next-(seed*step))*100 + g3;
254
255 step = 0;
256 seed = 2 * seed * 10;
257 while (((seed+1)*(step+1)) <= next)
258 {
259 step++;
260 seed++;
261 }
262
263 sq_rt = sq_rt + step * 1000;
264 next = (next - seed * step) * 100 + g2;
265 seed = (seed + step) * 10;
266 step = 0;
267 while (((seed+1)*(step+1)) <= next)
268 {
269 step++;
270 seed++;
271 }
272
273 sq_rt = sq_rt + step * 100;
274 next = (next - seed * step) * 100 + g1;
275 seed = (seed + step) * 10;
276 step = 0;
277
278 while (((seed+1)*(step+1)) <= next)
279 {
280 step++;
281 seed++;
282 }
283
284 sq_rt = sq_rt + step * 10;
285 next = (next - seed* step) * 100 + g0;
286 seed = (seed + step) * 10;
287 step = 0;
288
289 while (((seed+1)*(step+1)) <= next)
290 {
291 step++;
292 seed++;
293 }
294
295 sq_rt = sq_rt + step;
296
297 return sq_rt;
298 }
299
300 /*********************************************
301 void _sin_cos(s32 angle, s32 *sin, s32 *cos)
302 {
303 fixed X, Y, TargetAngle, CurrAngle;
304 unsigned Step;
305
306 X=FIXED(AG_CONST); // AG_CONST * cos(
307 Y=0; // AG_CONST * sin(
308 TargetAngle=abs(angle);
309 CurrAngle=0;
310
311 for (Step=0; Step < 12; Step++)
312 {
313 fixed NewX;
314
315 if(TargetAngle > CurrAngle)
316 {
317 NewX=X - (Y >> Step);
318 Y=(X >> Step) + Y;
319 X=NewX;
320 CurrAngle += Angles[Step];
321 }
322 else
323 {
324 NewX=X + (Y >> Step);
325 Y=-(X >> Step) + Y;
326 X=NewX;
327 CurrAngle -= Angles[Step];
328 }
329 }
330
331 if (angle > 0)
332 {
333 *cos = X;
334 *sin = Y;
335 }
336 else
337 {
338 *cos = X;
339 *sin = -Y;
340 }
341 }
342
343 static unsigned char hal_get_dxx_reg(struct hw
344 {
345 if (number < 0x1000)
346 number += 0x1000;
347 return Wb35Reg_ReadSync(pHwData, numbe
348 }
349 #define hw_get_dxx_reg( _A, _B, _C ) hal_get_d
350
351 static unsigned char hal_set_dxx_reg(struct hw
352 {
353 unsigned char ret;
354
355 if (number < 0x1000)
356 number += 0x1000;
357 ret = Wb35Reg_WriteSync(pHwData, numbe
358 return ret;
359 }
360 #define hw_set_dxx_reg( _A, _B, _C ) hal_set_d
361
362
363 void _reset_rx_cal(struct hw_data *phw_data)
364 {
365 u32 val;
366
367 hw_get_dxx_reg(phw_data, 0x54, &val);
368
369 if (phw_data->revision == 0x2002) // 1
370 {
371 val &= 0xFFFF0000;
372 }
373 else // 2nd-cut
374 {
375 val &= 0x000003FF;
376 }
377
378 hw_set_dxx_reg(phw_data, 0x54, val);
379 }
380
381
382 // ************for winbond calibration********
383 //
384
385 //
386 //
387 // *******************************************
388 void _rxadc_dc_offset_cancellation_winbond(str
389 {
390 u32 reg_agc_ctrl3;
391 u32 reg_a_acq_ctrl;
392 u32 reg_b_acq_ctrl;
393 u32 val;
394
395 PHY_DEBUG(("[CAL] -> [1]_rxadc_dc_offset_c
396 phy_init_rf(phw_data);
397
398 // set calibration channel
399 if( (RF_WB_242 == phw_data->phy_type) ||
400 (RF_WB_242_1 == phw_data->phy_
401 {
402 if ((frequency >= 2412) && (frequency
403 {
404 // w89rf242 change frequency to 23
405 PHY_DEBUG(("[CAL] W89RF242/11G/Cha
406 phy_set_rf_data(phw_da
407
408 }
409 }
410 else
411 {
412
413 }
414
415 // reset cancel_dc_i[9:5] and cancel_d
416 hw_get_dxx_reg(phw_data, 0x5C, &val);
417 val &= ~(0x03FF);
418 hw_set_dxx_reg(phw_data, 0x5C, val);
419
420 // reset the TX and RX IQ calibration
421 hw_set_dxx_reg(phw_data, 0x3C, 0);
422 hw_set_dxx_reg(phw_data, 0x54, 0);
423
424 hw_set_dxx_reg(phw_data, 0x58, 0x30303
425
426 // a. Disable AGC
427 hw_get_dxx_reg(phw_data, REG_AGC_CTRL3
428 reg_agc_ctrl3 &= ~BIT(2);
429 reg_agc_ctrl3 |= (MASK_LNA_FIX_GAIN|MA
430 hw_set_dxx_reg(phw_data, REG_AGC_CTRL3
431
432 hw_get_dxx_reg(phw_data, REG_AGC_CTRL5
433 val |= MASK_AGC_FIX_GAIN;
434 hw_set_dxx_reg(phw_data, REG_AGC_CTRL5
435
436 // b. Turn off BB RX
437 hw_get_dxx_reg(phw_data, REG_A_ACQ_CTR
438 reg_a_acq_ctrl |= MASK_AMER_OFF_REG;
439 hw_set_dxx_reg(phw_data, REG_A_ACQ_CTR
440
441 hw_get_dxx_reg(phw_data, REG_B_ACQ_CTR
442 reg_b_acq_ctrl |= MASK_BMER_OFF_REG;
443 hw_set_dxx_reg(phw_data, REG_B_ACQ_CTR
444
445 // c. Make sure MAC is in receiving mo
446 // d. Turn ON ADC calibration
447 // - ADC calibrator is triggered by
448 hw_get_dxx_reg(phw_data, REG_MODE_CTRL
449 val &= ~MASK_ADC_DC_CAL_STR;
450 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
451
452 val |= MASK_ADC_DC_CAL_STR;
453 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
454
455 // e. The result are shown in "adc_dc_
456 #ifdef _DEBUG
457 hw_get_dxx_reg(phw_data, REG_OFFSET_RE
458 PHY_DEBUG(("[CAL] REG_OFFSET_READ =
459
460 PHY_DEBUG(("[CAL] ** adc_dc_cal_i =
461 _s9_to_s32(val&0x00
462 PHY_DEBUG(("[CAL] ** adc_dc_cal_q =
463 _s9_to_s32((val&0x0
464 #endif
465
466 hw_get_dxx_reg(phw_data, REG_MODE_CTRL
467 val &= ~MASK_ADC_DC_CAL_STR;
468 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
469
470 // f. Turn on BB RX
471 //hw_get_dxx_reg(phw_data, REG_A_ACQ_C
472 reg_a_acq_ctrl &= ~MASK_AMER_OFF_REG;
473 hw_set_dxx_reg(phw_data, REG_A_ACQ_CTR
474
475 //hw_get_dxx_reg(phw_data, REG_B_ACQ_C
476 reg_b_acq_ctrl &= ~MASK_BMER_OFF_REG;
477 hw_set_dxx_reg(phw_data, REG_B_ACQ_CTR
478
479 // g. Enable AGC
480 //hw_get_dxx_reg(phw_data, REG_AGC_CTR
481 reg_agc_ctrl3 |= BIT(2);
482 reg_agc_ctrl3 &= ~(MASK_LNA_FIX_GAIN|M
483 hw_set_dxx_reg(phw_data, REG_AGC_CTRL3
484 }
485
486 //////////////////////////////////////////////
487 void _txidac_dc_offset_cancellation_winbond(st
488 {
489 u32 reg_agc_ctrl3;
490 u32 reg_mode_ctrl;
491 u32 reg_dc_cancel;
492 s32 iqcal_image_i;
493 s32 iqcal_image_q;
494 u32 sqsum;
495 s32 mag_0;
496 s32 mag_1;
497 s32 fix_cancel_dc_i = 0;
498 u32 val;
499 int loop;
500
501 PHY_DEBUG(("[CAL] -> [2]_txidac_dc_off
502
503 // a. Set to "TX calibration mode"
504
505 //0x01 0xEE3FC2 ; 3B8FF ; Calibratio
506 phy_set_rf_data(phw_data, 1, (1<<24)|0
507 //0x0B 0x1905D6 ; 06417 ; Calibratio
508 phy_set_rf_data(phw_data, 11, (11<<24)
509 //0x05 0x24C60A ; 09318 ; Calibratio
510 phy_set_rf_data(phw_data, 5, (5<<24)|0
511 //0x06 0x06880C ; 01A20 ; Calibration (6
512 phy_set_rf_data(phw_data, 6, (6<<24)|0
513 //0x00 0xFDF1C0 ; 3F7C7 ; Calibratio
514 phy_set_rf_data(phw_data, 0, (0<<24)|0
515
516 hw_set_dxx_reg(phw_data, 0x58, 0x30303
517
518 // a. Disable AGC
519 hw_get_dxx_reg(phw_data, REG_AGC_CTRL3
520 reg_agc_ctrl3 &= ~BIT(2);
521 reg_agc_ctrl3 |= (MASK_LNA_FIX_GAIN|MA
522 hw_set_dxx_reg(phw_data, REG_AGC_CTRL3
523
524 hw_get_dxx_reg(phw_data, REG_AGC_CTRL5
525 val |= MASK_AGC_FIX_GAIN;
526 hw_set_dxx_reg(phw_data, REG_AGC_CTRL5
527
528 // b. set iqcal_mode[1:0] to 0x2 and s
529 hw_get_dxx_reg(phw_data, REG_MODE_CTRL
530
531 PHY_DEBUG(("[CAL] MODE_CTRL (read)
532 reg_mode_ctrl &= ~(MASK_IQCAL_TONE_SEL
533
534 // mode=2, tone=0
535 //reg_mode_ctrl |= (MASK_CALIB_START|2
536
537 // mode=2, tone=1
538 //reg_mode_ctrl |= (MASK_CALIB_START|2
539
540 // mode=2, tone=2
541 reg_mode_ctrl |= (MASK_CALIB_START|2|(
542 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
543 PHY_DEBUG(("[CAL] MODE_CTRL (write)
544
545 hw_get_dxx_reg(phw_data, 0x5C, ®_dc
546 PHY_DEBUG(("[CAL] DC_CANCEL (read)
547
548 for (loop = 0; loop < LOOP_TIMES; loop
549 {
550 PHY_DEBUG(("[CAL] [%d.] ======
551
552 // c.
553 // reset cancel_dc_i[9:5] and
554 reg_dc_cancel &= ~(0x03FF);
555 PHY_DEBUG(("[CAL] DC_CANCEL
556 hw_set_dxx_reg(phw_data, 0x5C,
557
558 hw_get_dxx_reg(phw_data, REG_C
559 PHY_DEBUG(("[CAL] CALIB_REA
560
561 iqcal_image_i = _s13_to_s32(va
562 iqcal_image_q = _s13_to_s32((v
563 sqsum = iqcal_image_i*iqcal_im
564 mag_0 = (s32) _sqrt(sqsum);
565 PHY_DEBUG(("[CAL] mag_0=%d
566 mag_0, iqca
567
568 // d.
569 reg_dc_cancel |= (1 << CANCEL_
570 PHY_DEBUG(("[CAL] DC_CANCEL
571 hw_set_dxx_reg(phw_data, 0x5C,
572
573 hw_get_dxx_reg(phw_data, REG_C
574 PHY_DEBUG(("[CAL] CALIB_REA
575
576 iqcal_image_i = _s13_to_s32(va
577 iqcal_image_q = _s13_to_s32((v
578 sqsum = iqcal_image_i*iqcal_im
579 mag_1 = (s32) _sqrt(sqsum);
580 PHY_DEBUG(("[CAL] mag_1=%d
581 mag_1, iqca
582
583 // e. Calculate the correct DC
584 if (mag_0 != mag_1)
585 {
586 fix_cancel_dc_i = (mag
587 }
588 else
589 {
590 if (mag_0 == mag_1)
591 {
592 PHY_DEBUG(("[C
593 }
594
595 fix_cancel_dc_i = 0;
596 }
597
598 PHY_DEBUG(("[CAL] ** fix_ca
599 fix_cancel_
600
601 if ((abs(mag_1-mag_0)*6) > mag
602 {
603 break;
604 }
605 }
606
607 if ( loop >= 19 )
608 fix_cancel_dc_i = 0;
609
610 reg_dc_cancel &= ~(0x03FF);
611 reg_dc_cancel |= (_s32_to_s5(fix_cance
612 hw_set_dxx_reg(phw_data, 0x5C, reg_dc_
613 PHY_DEBUG(("[CAL] DC_CANCEL (write)
614
615 // g.
616 reg_mode_ctrl &= ~MASK_CALIB_START;
617 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
618 PHY_DEBUG(("[CAL] MODE_CTRL (write)
619 }
620
621 //////////////////////////////////////////////
622 void _txqdac_dc_offset_cacellation_winbond(str
623 {
624 u32 reg_agc_ctrl3;
625 u32 reg_mode_ctrl;
626 u32 reg_dc_cancel;
627 s32 iqcal_image_i;
628 s32 iqcal_image_q;
629 u32 sqsum;
630 s32 mag_0;
631 s32 mag_1;
632 s32 fix_cancel_dc_q = 0;
633 u32 val;
634 int loop;
635
636 PHY_DEBUG(("[CAL] -> [3]_txqdac_dc_off
637 //0x01 0xEE3FC2 ; 3B8FF ; Calibratio
638 phy_set_rf_data(phw_data, 1, (1<<24)|0
639 //0x0B 0x1905D6 ; 06417 ; Calibratio
640 phy_set_rf_data(phw_data, 11, (11<<24)
641 //0x05 0x24C60A ; 09318 ; Calibratio
642 phy_set_rf_data(phw_data, 5, (5<<24)|0
643 //0x06 0x06880C ; 01A20 ; Calibration (6
644 phy_set_rf_data(phw_data, 6, (6<<24)|0
645 //0x00 0xFDF1C0 ; 3F7C7 ; Calibratio
646 phy_set_rf_data(phw_data, 0, (0<<24)|0
647
648 hw_set_dxx_reg(phw_data, 0x58, 0x30303
649
650 // a. Disable AGC
651 hw_get_dxx_reg(phw_data, REG_AGC_CTRL3
652 reg_agc_ctrl3 &= ~BIT(2);
653 reg_agc_ctrl3 |= (MASK_LNA_FIX_GAIN|MA
654 hw_set_dxx_reg(phw_data, REG_AGC_CTRL3
655
656 hw_get_dxx_reg(phw_data, REG_AGC_CTRL5
657 val |= MASK_AGC_FIX_GAIN;
658 hw_set_dxx_reg(phw_data, REG_AGC_CTRL5
659
660 // a. set iqcal_mode[1:0] to 0x3 and s
661 hw_get_dxx_reg(phw_data, REG_MODE_CTRL
662 PHY_DEBUG(("[CAL] MODE_CTRL (read)
663
664 //reg_mode_ctrl &= ~(MASK_IQCAL_TONE_S
665 reg_mode_ctrl &= ~(MASK_IQCAL_MODE);
666 reg_mode_ctrl |= (MASK_CALIB_START|3);
667 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
668 PHY_DEBUG(("[CAL] MODE_CTRL (write)
669
670 hw_get_dxx_reg(phw_data, 0x5C, ®_dc
671 PHY_DEBUG(("[CAL] DC_CANCEL (read)
672
673 for (loop = 0; loop < LOOP_TIMES; loop
674 {
675 PHY_DEBUG(("[CAL] [%d.] ======
676
677 // b.
678 // reset cancel_dc_q[4:0] in r
679 reg_dc_cancel &= ~(0x001F);
680 PHY_DEBUG(("[CAL] DC_CANCEL
681 hw_set_dxx_reg(phw_data, 0x5C,
682
683 hw_get_dxx_reg(phw_data, REG_C
684 PHY_DEBUG(("[CAL] CALIB_REA
685
686 iqcal_image_i = _s13_to_s32(va
687 iqcal_image_q = _s13_to_s32((v
688 sqsum = iqcal_image_i*iqcal_im
689 mag_0 = _sqrt(sqsum);
690 PHY_DEBUG(("[CAL] mag_0=%d
691 mag_0, iqca
692
693 // c.
694 reg_dc_cancel |= (1 << CANCEL_
695 PHY_DEBUG(("[CAL] DC_CANCEL
696 hw_set_dxx_reg(phw_data, 0x5C,
697
698 hw_get_dxx_reg(phw_data, REG_C
699 PHY_DEBUG(("[CAL] CALIB_REA
700
701 iqcal_image_i = _s13_to_s32(va
702 iqcal_image_q = _s13_to_s32((v
703 sqsum = iqcal_image_i*iqcal_im
704 mag_1 = _sqrt(sqsum);
705 PHY_DEBUG(("[CAL] mag_1=%d
706 mag_1, iqca
707
708 // d. Calculate the correct DC
709 if (mag_0 != mag_1)
710 {
711 fix_cancel_dc_q = (mag
712 }
713 else
714 {
715 if (mag_0 == mag_1)
716 {
717 PHY_DEBUG(("[C
718 }
719
720 fix_cancel_dc_q = 0;
721 }
722
723 PHY_DEBUG(("[CAL] ** fix_ca
724 fix_cancel_
725
726 if ((abs(mag_1-mag_0)*6) > mag
727 {
728 break;
729 }
730 }
731
732 if ( loop >= 19 )
733 fix_cancel_dc_q = 0;
734
735 reg_dc_cancel &= ~(0x001F);
736 reg_dc_cancel |= (_s32_to_s5(fix_cance
737 hw_set_dxx_reg(phw_data, 0x5C, reg_dc_
738 PHY_DEBUG(("[CAL] DC_CANCEL (write)
739
740
741 // f.
742 reg_mode_ctrl &= ~MASK_CALIB_START;
743 hw_set_dxx_reg(phw_data, REG_MODE_CTRL
744 PHY_DEBUG(("[CAL] MODE_CTRL (write)
745 }
746
747 //20060612.1.a 20060718.1 Modify
748 u8 _tx_iq_calibration_loop_winbond(struct hw_d
749
750
751 {
752 u32 reg_mode_ctrl;
753 s32 iq_mag_0_tx;
754 s32 iqcal_tone_i0;
755 s32 iqcal_tone_q0;
756 s32 iqcal_tone_i;
757 s32 iqcal_tone_q;
758 u32 sqsum;
759 s32 rot_i_b;
760 s32 rot_q_b;
761 s32 tx_cal_flt_b[4];
762 s32 tx_cal[4];
763 s32 tx_cal_reg[4];
764 s32 a_2, b_2;
765 s32 sin_b, sin_2b;
766 s32 cos_b, cos_2b;
767 s32 divisor;
768 s32 temp1, temp2;
769 u32 val;
770 u16 loop;
771 s32 iqcal_tone_i_avg,iqcal_tone_q_
772 u8 verify_count;
773 int capture_time;
774
775 PHY_DEBUG(("[CAL] -> _tx_iq_calibratio
776 PHY_DEBUG(("[CAL] ** a_2_threshold
777 PHY_DEBUG(("[CAL] ** b_2_threshold
778
779 verify_count = 0;
780
781 hw_get_dxx_reg(phw_data, REG_MODE_CTRL
782 PHY_DEBUG(("[CAL] MODE_CTRL (read)
783
784 loop = LOOP_TIMES;
785
786 while (loop > 0)
787 {
788 PHY_DEBUG(("[CAL] [%d.] <_tx_i
789
790 iqcal_tone_i_avg=0;
791 iqcal_tone_q_avg=0;
792 if( !hw_set_dxx_reg(phw_data,
793 return 0;
794 for(capture_time=0;capture_tim
795 {
796 // a. Set iqcal_mode[1
797 // enable "IQ alibr
798 reg_mode_ctrl &= ~(MAS
799 reg_mode_ctrl &= ~MASK
800 reg_mode_ctrl |= (MASK
801 reg_mode_ctrl |= (MASK
802 hw_set_dxx_reg(phw_dat
803 PHY_DEBUG(("[CAL] M
804
805 // b.
806 hw_get_dxx_reg(phw_dat
807 PHY_DEBUG(("[CAL] C
808
809 iqcal_tone_i0 = _s13_t
810 iqcal_tone_q0 = _s13_t
811 PHY_DEBUG(("[CAL] *
812 iqcal_tone_
813
814 sqsum = iqcal_tone_i0*
815 iqcal_tone_q0*iqcal_to
816 iq_mag_0_tx = (s32) _s
817 PHY_DEBUG(("[CAL] *
818
819 // c. Set "calib_start
820 reg_mode_ctrl &= ~MASK
821 hw_set_dxx_reg(phw_dat
822 PHY_DEBUG(("[CAL] M
823
824 // d. Set iqcal_mode[1
825 // enable "IQ alibr
826 //hw_get_dxx_reg(phw_d
827 hw_get_dxx_reg(phw_dat
828 reg_mode_ctrl &= ~MASK
829 reg_mode_ctrl |= (MASK
830 hw_set_dxx_reg(phw_dat
831 PHY_DEBUG(("[CAL] M
832
833 // e.
834 hw_get_dxx_reg(phw_dat
835 PHY_DEBUG(("[CAL] C
836
837 iqcal_tone_i = _s13_to
838 iqcal_tone_q = _s13_to
839 PHY_DEBUG(("[CAL] *
840 iqcal_tone_i, iqcal_to
841 if( capture_time == 0)
842 {
843 continue;
844 }
845 else
846 {
847 iqcal_tone_i_a
848 iqcal_tone_q_a
849 }
850 }
851
852 iqcal_tone_i = iqcal_tone_i_av
853 iqcal_tone_q = iqcal_tone_q_av
854
855
856 rot_i_b = (iqcal_tone_i * iqca
857 iqcal_tone_
858 rot_q_b = (iqcal_tone_i * iqca
859 iqcal_tone_
860 PHY_DEBUG(("[CAL] ** rot_i_
861 rot_i_b, ro
862
863 // f.
864 divisor = ((iq_mag_0_tx * iq_m
865
866 if (divisor == 0)
867 {
868 PHY_DEBUG(("[CAL] ** <
869 PHY_DEBUG(("[CAL] ** d
870 PHY_DEBUG(("[CAL] ****
871 break;
872 }
873
874 a_2 = (rot_i_b * 32768) / divi
875 b_2 = (rot_q_b * (-32768)) / d
876 PHY_DEBUG(("[CAL] ***** EPS
877 PHY_DEBUG(("[CAL] ***** THE
878
879 phw_data->iq_rsdl_gain_tx_d2 =
880 phw_data->iq_rsdl_phase_tx_d2
881
882 //if ((abs(a_2) < 150) && (abs
883 //if ((abs(a_2) < 200) && (abs
884 if ((abs(a_2) < a_2_threshold)
885 {
886 verify_count++;
887
888 PHY_DEBUG(("[CAL] ** <
889 PHY_DEBUG(("[CAL] ** V
890 PHY_DEBUG(("[CAL] ****
891
892 if (verify_count > 2)
893 {
894 PHY_DEBUG(("[C
895 PHY_DEBUG(("[C
896 PHY_DEBUG(("[C
897 return 0;
898 }
899
900 continue;
901 }
902 else
903 {
904 verify_count = 0;
905 }
906
907 _sin_cos(b_2, &sin_b, &cos_b);
908 _sin_cos(b_2*2, &sin_2b, &cos_
909 PHY_DEBUG(("[CAL] ** sin(b/
910 PHY_DEBUG(("[CAL] ** sin(b)
911
912 if (cos_2b == 0)
913 {
914 PHY_DEBUG(("[CAL] ** <
915 PHY_DEBUG(("[CAL] ** c
916 PHY_DEBUG(("[CAL] ****
917 break;
918 }
919
920 // 1280 * 32768 = 41943040
921 temp1 = (41943040/cos_2b)*cos_
922
923 //temp2 = (41943040/cos_2b)*si
924 if (phw_data->revision == 0x20
925 {
926 temp2 = (41943040/cos_
927 }
928 else // 2nd-cut
929 {
930 temp2 = (41943040*4/co
931 }
932
933 tx_cal_flt_b[0] = _floor(temp1
934 tx_cal_flt_b[1] = _floor(temp2
935 tx_cal_flt_b[2] = _floor(temp2
936 tx_cal_flt_b[3] = _floor(temp1
937 PHY_DEBUG(("[CAL] ** tx_cal
938 PHY_DEBUG(("[CAL] tx_cal
939 PHY_DEBUG(("[CAL] tx_cal
940 PHY_DEBUG(("[CAL] tx_cal
941
942 tx_cal[2] = tx_cal_flt_b[2];
943 tx_cal[2] = tx_cal[2] +3;
944 tx_cal[1] = tx_cal[2];
945 tx_cal[3] = tx_cal_flt_b[3] -
946 tx_cal[0] = -tx_cal[3]+1;
947
948 PHY_DEBUG(("[CAL] tx_cal
949 PHY_DEBUG(("[CAL] tx_cal
950 PHY_DEBUG(("[CAL] tx_cal
951 PHY_DEBUG(("[CAL] tx_cal
952
953 //if ((tx_cal[0] == 0) && (tx_
954 // (tx_cal[2] == 0) && (tx_
955 //{
956 // PHY_DEBUG(("[CAL] ** <_t
957 // PHY_DEBUG(("[CAL] ** TX_
958 // PHY_DEBUG(("[CAL] ******
959 // return 0;
960 //}
961
962 // g.
963 if (phw_data->revision == 0x20
964 {
965 hw_get_dxx_reg(phw_dat
966 PHY_DEBUG(("[CAL] *
967 tx_cal_reg[0] = _s4_to
968 tx_cal_reg[1] = _s4_to
969 tx_cal_reg[2] = _s4_to
970 tx_cal_reg[3] = _s4_to
971 }
972 else // 2nd-cut
973 {
974 hw_get_dxx_reg(phw_dat
975 PHY_DEBUG(("[CAL] *
976 tx_cal_reg[0] = _s5_to
977 tx_cal_reg[1] = _s6_to
978 tx_cal_reg[2] = _s6_to
979 tx_cal_reg[3] = _s5_to
980
981 }
982
983 PHY_DEBUG(("[CAL] ** tx_cal
984 PHY_DEBUG(("[CAL] tx_cal
985 PHY_DEBUG(("[CAL] tx_cal
986 PHY_DEBUG(("[CAL] tx_cal
987
988 if (phw_data->revision == 0x20
989 {
990 if (((tx_cal_reg[0]==7
991 ((tx_cal_reg[3
992 {
993 PHY_DEBUG(("[C
994 PHY_DEBUG(("[C
995 PHY_DEBUG(("[C
996 break;
997 }
998 }
999 else // 2nd-cut
1000 {
1001 if (((tx_cal_reg[0]==
1002 ((tx_cal_reg[
1003 {
1004 PHY_DEBUG(("[
1005 PHY_DEBUG(("[
1006 PHY_DEBUG(("[
1007 break;
1008 }
1009 }
1010
1011 tx_cal[0] = tx_cal[0] + tx_ca
1012 tx_cal[1] = tx_cal[1] + tx_ca
1013 tx_cal[2] = tx_cal[2] + tx_ca
1014 tx_cal[3] = tx_cal[3] + tx_ca
1015 PHY_DEBUG(("[CAL] ** apply
1016 PHY_DEBUG(("[CAL] apply
1017 PHY_DEBUG(("[CAL] apply
1018 PHY_DEBUG(("[CAL] apply
1019
1020 if (phw_data->revision == 0x2
1021 {
1022 val &= 0x0000FFFF;
1023 val |= ((_s32_to_s4(t
1024 (_s32
1025 (_s32
1026 (_s32
1027 hw_set_dxx_reg(phw_da
1028 PHY_DEBUG(("[CAL]
1029 return 0;
1030 }
1031 else // 2nd-cut
1032 {
1033 val &= 0x000003FF;
1034 val |= ((_s32_to_s5(t
1035 (_s32
1036 (_s32
1037 (_s32
1038 hw_set_dxx_reg(phw_da
1039 PHY_DEBUG(("[CAL]
1040 return 0;
1041 }
1042
1043 // i. Set "calib_start" to 0x
1044 reg_mode_ctrl &= ~MASK_CALIB_
1045 hw_set_dxx_reg(phw_data, REG_
1046 PHY_DEBUG(("[CAL] MODE_CTR
1047
1048 loop--;
1049 }
1050
1051 return 1;
1052 }
1053
1054 void _tx_iq_calibration_winbond(struct hw_dat
1055 {
1056 u32 reg_agc_ctrl3;
1057 #ifdef _DEBUG
1058 s32 tx_cal_reg[4];
1059
1060 #endif
1061 u32 reg_mode_ctrl;
1062 u32 val;
1063 u8 result;
1064
1065 PHY_DEBUG(("[CAL] -> [4]_tx_iq_calibr
1066
1067 //0x01 0xEE3FC2 ; 3B8FF ; Calibrati
1068 phy_set_rf_data(phw_data, 1, (1<<24)|
1069 //0x0B 0x1905D6 ; 06417 ; Calibrati
1070 phy_set_rf_data(phw_data, 11, (11<<24
1071 //0x05 0x24C60A ; 09318 ; Calibrati
1072 phy_set_rf_data(phw_data, 5, (5<<24)|
1073 //0x06 0x06880C ; 01A20 ; Calibration (
1074 phy_set_rf_data(phw_data, 6, (6<<24)|
1075 //0x00 0xFDF1C0 ; 3F7C7 ; Calibrati
1076 phy_set_rf_data(phw_data, 0, (0<<24)|
1077 //; [BB-chip]: Calibration (6f).Send
1078 //; [BB-chip]: Calibration (6g). Sear
1079 //; [BB-chip]: Calibration (6h). Cacu
1080 //phy_set_rf_data(phw_data, 3, (3<<24
1081
1082 msleep(30); // 20060612.1.a 30ms dela
1083 //To adjust TXVGA to fit iq_mag_0 ran
1084 adjust_TXVGA_for_iq_mag( phw_data );
1085
1086 // a. Disable AGC
1087 hw_get_dxx_reg(phw_data, REG_AGC_CTRL
1088 reg_agc_ctrl3 &= ~BIT(2);
1089 reg_agc_ctrl3 |= (MASK_LNA_FIX_GAIN|M
1090 hw_set_dxx_reg(phw_data, REG_AGC_CTRL
1091
1092 hw_get_dxx_reg(phw_data, REG_AGC_CTRL
1093 val |= MASK_AGC_FIX_GAIN;
1094 hw_set_dxx_reg(phw_data, REG_AGC_CTRL
1095
1096 result = _tx_iq_calibration_loop_winb
1097
1098 if (result > 0)
1099 {
1100 if (phw_data->revision == 0x2
1101 {
1102 hw_get_dxx_reg(phw_da
1103 val &= 0x0000FFFF;
1104 hw_set_dxx_reg(phw_da
1105 }
1106 else // 2nd-cut
1107 {
1108 hw_get_dxx_reg(phw_da
1109 val &= 0x000003FF;
1110 hw_set_dxx_reg(phw_da
1111 }
1112
1113 result = _tx_iq_calibration_l
1114
1115 if (result > 0)
1116 {
1117 if (phw_data->revisio
1118 {
1119 hw_get_dxx_re
1120 val &= 0x0000
1121 hw_set_dxx_re
1122 }
1123 else // 2nd-cut
1124 {
1125 hw_get_dxx_re
1126 val &= 0x0000
1127 hw_set_dxx_re
1128 }
1129
1130 result = _tx_iq_calib
1131 if (result > 0)
1132 {
1133 if (phw_data-
1134 {
1135 hw_ge
1136 val &
1137 hw_se
1138 }
1139 else // 2nd-c
1140 {
1141 hw_ge
1142 val &
1143 hw_se
1144 }
1145
1146
1147 result = _tx_
1148
1149 if (result >
1150 {
1151 PHY_D
1152 PHY_D
1153 PHY_D
1154
1155 if (p
1156 {
1157
1158
1159
1160 }
1161 else
1162 {
1163
1164
1165
1166 }
1167 }
1168 }
1169 }
1170 }
1171
1172 // i. Set "calib_start" to 0x0
1173 hw_get_dxx_reg(phw_data, REG_MODE_CTR
1174 reg_mode_ctrl &= ~MASK_CALIB_START;
1175 hw_set_dxx_reg(phw_data, REG_MODE_CTR
1176 PHY_DEBUG(("[CAL] MODE_CTRL (write
1177
1178 // g. Enable AGC
1179 //hw_get_dxx_reg(phw_data, REG_AGC_CT
1180 reg_agc_ctrl3 |= BIT(2);
1181 reg_agc_ctrl3 &= ~(MASK_LNA_FIX_GAIN|
1182 hw_set_dxx_reg(phw_data, REG_AGC_CTRL
1183
1184 #ifdef _DEBUG
1185 if (phw_data->revision == 0x2002) //
1186 {
1187 hw_get_dxx_reg(phw_data, 0x54
1188 PHY_DEBUG(("[CAL] ** 0x54
1189 tx_cal_reg[0] = _s4_to_s32((v
1190 tx_cal_reg[1] = _s4_to_s32((v
1191 tx_cal_reg[2] = _s4_to_s32((v
1192 tx_cal_reg[3] = _s4_to_s32((v
1193 }
1194 else // 2nd-cut
1195 {
1196 hw_get_dxx_reg(phw_data, 0x3C
1197 PHY_DEBUG(("[CAL] ** 0x3C
1198 tx_cal_reg[0] = _s5_to_s32((v
1199 tx_cal_reg[1] = _s6_to_s32((v
1200 tx_cal_reg[2] = _s6_to_s32((v
1201 tx_cal_reg[3] = _s5_to_s32((v
1202
1203 }
1204
1205 PHY_DEBUG(("[CAL] ** tx_cal_reg[0]
1206 PHY_DEBUG(("[CAL] tx_cal_reg[1]
1207 PHY_DEBUG(("[CAL] tx_cal_reg[2]
1208 PHY_DEBUG(("[CAL] tx_cal_reg[3]
1209 #endif
1210
1211
1212 // for test - BEN
1213 // RF Control Override
1214 }
1215
1216 /////////////////////////////////////////////
1217 u8 _rx_iq_calibration_loop_winbond(struct hw_
1218 {
1219 u32 reg_mode_ctrl;
1220 s32 iqcal_tone_i;
1221 s32 iqcal_tone_q;
1222 s32 iqcal_image_i;
1223 s32 iqcal_image_q;
1224 s32 rot_tone_i_b;
1225 s32 rot_tone_q_b;
1226 s32 rot_image_i_b;
1227 s32 rot_image_q_b;
1228 s32 rx_cal_flt_b[4];
1229 s32 rx_cal[4];
1230 s32 rx_cal_reg[4];
1231 s32 a_2, b_2;
1232 s32 sin_b, sin_2b;
1233 s32 cos_b, cos_2b;
1234 s32 temp1, temp2;
1235 u32 val;
1236 u16 loop;
1237
1238 u32 pwr_tone;
1239 u32 pwr_image;
1240 u8 verify_count;
1241
1242 s32 iqcal_tone_i_avg,iqcal_tone_q
1243 s32 iqcal_image_i_avg,iqcal_image
1244 u16 capture_time;
1245
1246 PHY_DEBUG(("[CAL] -> [5]_rx_iq_calibr
1247 PHY_DEBUG(("[CAL] ** factor = %d\n",
1248
1249
1250 // RF Control Override
1251 hw_get_cxx_reg(phw_data, 0x80, &val);
1252 val |= BIT(19);
1253 hw_set_cxx_reg(phw_data, 0x80, val);
1254
1255 // RF_Ctrl
1256 hw_get_cxx_reg(phw_data, 0xE4, &val);
1257 val |= BIT(0);
1258 hw_set_cxx_reg(phw_data, 0xE4, val);
1259 PHY_DEBUG(("[CAL] ** RF_CTRL(0xE4) =
1260
1261 hw_set_dxx_reg(phw_data, 0x58, 0x4444
1262
1263 // b.
1264
1265 hw_get_dxx_reg(phw_data, REG_MODE_CTR
1266 PHY_DEBUG(("[CAL] MODE_CTRL (read)
1267
1268 verify_count = 0;
1269
1270 //for (loop = 0; loop < 1; loop++)
1271 //for (loop = 0; loop < LOOP_TIMES; l
1272 loop = LOOP_TIMES;
1273 while (loop > 0)
1274 {
1275 PHY_DEBUG(("[CAL] [%d.] <_rx_
1276 iqcal_tone_i_avg=0;
1277 iqcal_tone_q_avg=0;
1278 iqcal_image_i_avg=0;
1279 iqcal_image_q_avg=0;
1280 capture_time=0;
1281
1282 for(capture_time=0; capture_t
1283 {
1284 // i. Set "calib_start" to 0x
1285 reg_mode_ctrl &= ~MASK_CALIB_
1286 if( !hw_set_dxx_reg(phw_data,
1287 return 0;
1288 PHY_DEBUG(("[CAL] MODE_CTR
1289
1290 reg_mode_ctrl &= ~MASK_IQCAL_
1291 reg_mode_ctrl |= (MASK_CALIB_
1292 hw_set_dxx_reg(phw_data, REG_
1293 PHY_DEBUG(("[CAL] MODE_CTR
1294
1295 // c.
1296 hw_get_dxx_reg(phw_data, REG_
1297 PHY_DEBUG(("[CAL] CALIB_RE
1298
1299 iqcal_tone_i = _s13_to_s32(va
1300 iqcal_tone_q = _s13_to_s32((v
1301 PHY_DEBUG(("[CAL] ** iqcal
1302 iqcal_tone
1303
1304 hw_get_dxx_reg(phw_data, REG_
1305 PHY_DEBUG(("[CAL] CALIB_RE
1306
1307 iqcal_image_i = _s13_to_s32(v
1308 iqcal_image_q = _s13_to_s32((
1309 PHY_DEBUG(("[CAL] ** iqcal
1310 iqcal_imag
1311 if( capture_time == 0
1312 {
1313 continue;
1314 }
1315 else
1316 {
1317 iqcal_image_i
1318 iqcal_image_q
1319 iqcal_tone_i_
1320 iqcal_tone_q_
1321 }
1322 }
1323
1324
1325 iqcal_image_i = iqcal_image_i
1326 iqcal_image_q = iqcal_image_q
1327 iqcal_tone_i = iqcal_tone_i_a
1328 iqcal_tone_q = iqcal_tone_q_a
1329
1330 // d.
1331 rot_tone_i_b = (iqcal_tone_i
1332
1333 rot_tone_q_b = (iqcal_tone_i
1334
1335 rot_image_i_b = (iqcal_image_
1336
1337 rot_image_q_b = (iqcal_image_
1338
1339
1340 PHY_DEBUG(("[CAL] ** rot_t
1341 PHY_DEBUG(("[CAL] ** rot_t
1342 PHY_DEBUG(("[CAL] ** rot_i
1343 PHY_DEBUG(("[CAL] ** rot_i
1344
1345 // f.
1346 if (rot_tone_i_b == 0)
1347 {
1348 PHY_DEBUG(("[CAL] **
1349 PHY_DEBUG(("[CAL] **
1350 PHY_DEBUG(("[CAL] ***
1351 break;
1352 }
1353
1354 a_2 = (rot_image_i_b * 32768)
1355 phw_data->iq_rsdl_gai
1356 b_2 = (rot_image_q_b * 32768)
1357 phw_data->iq_rsdl_pha
1358
1359 PHY_DEBUG(("[CAL] ** iq_rs
1360 PHY_DEBUG(("[CAL] ** iq_rs
1361 PHY_DEBUG(("[CAL] ***** EP
1362 PHY_DEBUG(("[CAL] ***** TH
1363
1364 _sin_cos(b_2, &sin_b, &cos_b)
1365 _sin_cos(b_2*2, &sin_2b, &cos
1366 PHY_DEBUG(("[CAL] ** sin(b
1367 PHY_DEBUG(("[CAL] ** sin(b
1368
1369 if (cos_2b == 0)
1370 {
1371 PHY_DEBUG(("[CAL] **
1372 PHY_DEBUG(("[CAL] **
1373 PHY_DEBUG(("[CAL] ***
1374 break;
1375 }
1376
1377 // 1280 * 32768 = 41943040
1378 temp1 = (41943040/cos_2b)*cos
1379
1380 //temp2 = (41943040/cos_2b)*s
1381 if (phw_data->revision == 0x2
1382 {
1383 temp2 = (41943040/cos
1384 }
1385 else // 2nd-cut
1386 {
1387 temp2 = (41943040*4/c
1388 }
1389
1390 rx_cal_flt_b[0] = _floor(temp
1391 rx_cal_flt_b[1] = _floor(temp
1392 rx_cal_flt_b[2] = _floor(temp
1393 rx_cal_flt_b[3] = _floor(temp
1394
1395 PHY_DEBUG(("[CAL] ** rx_ca
1396 PHY_DEBUG(("[CAL] rx_ca
1397 PHY_DEBUG(("[CAL] rx_ca
1398 PHY_DEBUG(("[CAL] rx_ca
1399
1400 rx_cal[0] = rx_cal_flt_b[0] -
1401 rx_cal[1] = rx_cal_flt_b[1];
1402 rx_cal[2] = rx_cal_flt_b[2];
1403 rx_cal[3] = rx_cal_flt_b[3] -
1404 PHY_DEBUG(("[CAL] ** rx_ca
1405 PHY_DEBUG(("[CAL] rx_ca
1406 PHY_DEBUG(("[CAL] rx_ca
1407 PHY_DEBUG(("[CAL] rx_ca
1408
1409 // e.
1410 pwr_tone = (iqcal_tone_i*iqca
1411 pwr_image = (iqcal_image_i*iq
1412
1413 PHY_DEBUG(("[CAL] ** pwr_t
1414 PHY_DEBUG(("[CAL] ** pwr_i
1415
1416 if (pwr_tone > pwr_image)
1417 {
1418 verify_count++;
1419
1420 PHY_DEBUG(("[CAL] **
1421 PHY_DEBUG(("[CAL] **
1422 PHY_DEBUG(("[CAL] ***
1423
1424 if (verify_count > 2)
1425 {
1426 PHY_DEBUG(("[
1427 PHY_DEBUG(("[
1428 PHY_DEBUG(("[
1429 return 0;
1430 }
1431
1432 continue;
1433 }
1434 // g.
1435 hw_get_dxx_reg(phw_data, 0x54
1436 PHY_DEBUG(("[CAL] ** 0x54
1437
1438 if (phw_data->revision == 0x2
1439 {
1440 rx_cal_reg[0] = _s4_t
1441 rx_cal_reg[1] = _s4_t
1442 rx_cal_reg[2] = _s4_t
1443 rx_cal_reg[3] = _s4_t
1444 }
1445 else // 2nd-cut
1446 {
1447 rx_cal_reg[0] = _s5_t
1448 rx_cal_reg[1] = _s6_t
1449 rx_cal_reg[2] = _s6_t
1450 rx_cal_reg[3] = _s5_t
1451 }
1452
1453 PHY_DEBUG(("[CAL] ** rx_ca
1454 PHY_DEBUG(("[CAL] rx_ca
1455 PHY_DEBUG(("[CAL] rx_ca
1456 PHY_DEBUG(("[CAL] rx_ca
1457
1458 if (phw_data->revision == 0x2
1459 {
1460 if (((rx_cal_reg[0]==
1461 ((rx_cal_reg[
1462 {
1463 PHY_DEBUG(("[
1464 PHY_DEBUG(("[
1465 PHY_DEBUG(("[
1466 break;
1467 }
1468 }
1469 else // 2nd-cut
1470 {
1471 if (((rx_cal_reg[0]==
1472 ((rx_cal_reg[
1473 {
1474 PHY_DEBUG(("[
1475 PHY_DEBUG(("[
1476 PHY_DEBUG(("[
1477 break;
1478 }
1479 }
1480
1481 rx_cal[0] = rx_cal[0] + rx_ca
1482 rx_cal[1] = rx_cal[1] + rx_ca
1483 rx_cal[2] = rx_cal[2] + rx_ca
1484 rx_cal[3] = rx_cal[3] + rx_ca
1485 PHY_DEBUG(("[CAL] ** apply
1486 PHY_DEBUG(("[CAL] apply
1487 PHY_DEBUG(("[CAL] apply
1488 PHY_DEBUG(("[CAL] apply
1489
1490 hw_get_dxx_reg(phw_data, 0x54
1491 if (phw_data->revision == 0x2
1492 {
1493 val &= 0x0000FFFF;
1494 val |= ((_s32_to_s4(r
1495 (_s32
1496 (_s32
1497 (_s32
1498 hw_set_dxx_reg(phw_da
1499 }
1500 else // 2nd-cut
1501 {
1502 val &= 0x000003FF;
1503 val |= ((_s32_to_s5(r
1504 (_s32
1505 (_s32
1506 (_s32
1507 hw_set_dxx_reg(phw_da
1508
1509 if( loop == 3 )
1510 return 0;
1511 }
1512 PHY_DEBUG(("[CAL] ** CALIB
1513
1514 loop--;
1515 }
1516
1517 return 1;
1518 }
1519
1520 /////////////////////////////////////////////
1521
1522 /////////////////////////////////////////////
1523 void _rx_iq_calibration_winbond(struct hw_dat
1524 {
1525 // figo 20050523 marked thsi flag for can't c
1526 #ifdef _DEBUG
1527 s32 rx_cal_reg[4];
1528 u32 val;
1529 #endif
1530
1531 u8 result;
1532
1533 PHY_DEBUG(("[CAL] -> [5]_rx_iq_calibr
1534 // a. Set RFIC to "RX calibration mode"
1535 //; ----- Calibration (7). RX path IQ
1536 // 0x01 0xFFBFC2 ; 3FEFF ; Cal
1537 phy_set_rf_data(phw_data, 1, (1<<24)|
1538 // 0x0B 0x1A01D6 ; 06817 ; Cal
1539 phy_set_rf_data(phw_data, 11, (11<<24
1540 //0x05 0x24848A ; 09212 ; Calibrati
1541 phy_set_rf_data(phw_data, 5, (5<<24)|
1542 //0x06 0x06840C ; 01A10 ; Calibrati
1543 phy_set_rf_data(phw_data, 6, (6<<24)|
1544 //0x00 0xFFF1C0 ; 3F7C7 ; Calibrati
1545 phy_set_rf_data(phw_data, 0, (0<<24)|
1546
1547 // ; [BB-chip]: Calibration (7f). Se
1548 // ; [BB-chip]: Calibration (7g)
1549 // ; [BB-chip]: Calibration (7h)
1550
1551 result = _rx_iq_calibration_loop_winb
1552
1553 if (result > 0)
1554 {
1555 _reset_rx_cal(phw_data);
1556 result = _rx_iq_calibration_l
1557
1558 if (result > 0)
1559 {
1560 _reset_rx_cal(phw_dat
1561 result = _rx_iq_calib
1562
1563 if (result > 0)
1564 {
1565 PHY_DEBUG(("[
1566 PHY_DEBUG(("[
1567 PHY_DEBUG(("[
1568 _reset_rx_cal
1569 }
1570 }
1571 }
1572
1573 #ifdef _DEBUG
1574 hw_get_dxx_reg(phw_data, 0x54, &val);
1575 PHY_DEBUG(("[CAL] ** 0x54 = 0x%08X
1576
1577 if (phw_data->revision == 0x2002) //
1578 {
1579 rx_cal_reg[0] = _s4_to_s32((v
1580 rx_cal_reg[1] = _s4_to_s32((v
1581 rx_cal_reg[2] = _s4_to_s32((v
1582 rx_cal_reg[3] = _s4_to_s32((v
1583 }
1584 else // 2nd-cut
1585 {
1586 rx_cal_reg[0] = _s5_to_s32((v
1587 rx_cal_reg[1] = _s6_to_s32((v
1588 rx_cal_reg[2] = _s6_to_s32((v
1589 rx_cal_reg[3] = _s5_to_s32((v
1590 }
1591
1592 PHY_DEBUG(("[CAL] ** rx_cal_reg[0]
1593 PHY_DEBUG(("[CAL] rx_cal_reg[1]
1594 PHY_DEBUG(("[CAL] rx_cal_reg[2]
1595 PHY_DEBUG(("[CAL] rx_cal_reg[3]
1596 #endif
1597
1598 }
1599
1600 /////////////////////////////////////////////
1601 void phy_calibration_winbond(struct hw_data *
1602 {
1603 u32 reg_mode_ctrl;
1604 u32 iq_alpha;
1605
1606 PHY_DEBUG(("[CAL] -> phy_calibration_
1607
1608 // 20040701 1.1.25.1000 kevin
1609 hw_get_cxx_reg(phw_data, 0x80, &mac_c
1610 hw_get_cxx_reg(phw_data, 0xE4, &rf_ct
1611 hw_get_dxx_reg(phw_data, 0x58, &iq_al
1612
1613
1614
1615 _rxadc_dc_offset_cancellation_winbond
1616 //_txidac_dc_offset_cancellation_winb
1617 //_txqdac_dc_offset_cacellation_winbo
1618
1619 _tx_iq_calibration_winbond(phw_data);
1620 _rx_iq_calibration_winbond(phw_data,
1621
1622 //-----------------------------------
1623 hw_get_dxx_reg(phw_data, REG_MODE_CTR
1624 reg_mode_ctrl &= ~(MASK_IQCAL_TONE_SE
1625 hw_set_dxx_reg(phw_data, REG_MODE_CTR
1626 PHY_DEBUG(("[CAL] MODE_CTRL (write
1627
1628 // i. Set RFIC to "Normal mode"
1629 hw_set_cxx_reg(phw_data, 0x80, mac_ct
1630 hw_set_cxx_reg(phw_data, 0xE4, rf_ctr
1631 hw_set_dxx_reg(phw_data, 0x58, iq_alp
1632
1633
1634 //-----------------------------------
1635 phy_init_rf(phw_data);
1636
1637 }
1638
1639 //===========================
1640 void phy_set_rf_data( struct hw_data * pHwDa
1641 {
1642 u32 ltmp=0;
1643
1644 switch( pHwData->phy_type )
1645 {
1646 case RF_MAXIM_2825:
1647 case RF_MAXIM_V1: // 11g Winb
1648 ltmp = (1 << 31) | (0
1649 break;
1650
1651 case RF_MAXIM_2827:
1652 ltmp = (1 << 31) | (0
1653 break;
1654
1655 case RF_MAXIM_2828:
1656 ltmp = (1 << 31) | (0
1657 break;
1658
1659 case RF_MAXIM_2829:
1660 ltmp = (1 << 31) | (0
1661 break;
1662
1663 case RF_AIROHA_2230:
1664 case RF_AIROHA_2230S: // 2006
1665 ltmp = (1 << 31) | (0
1666 break;
1667
1668 case RF_AIROHA_7230:
1669 ltmp = (1 << 31) | (0
1670 break;
1671
1672 case RF_WB_242:
1673 case RF_WB_242_1: // 20060619
1674 ltmp = (1 << 31) | (0
1675 break;
1676 }
1677
1678 Wb35Reg_WriteSync( pHwData, 0x0864, l
1679 }
1680
1681 // 20060717 modify as Bruce's mail
1682 unsigned char adjust_TXVGA_for_iq_mag(struct
1683 {
1684 int init_txvga = 0;
1685 u32 reg_mode_ctrl;
1686 u32 val;
1687 s32 iqcal_tone_i0;
1688 s32 iqcal_tone_q0;
1689 u32 sqsum;
1690 s32 iq_mag_0_tx;
1691 u8 reg_state;
1692 int current_txvga;
1693
1694
1695 reg_state = 0;
1696 for( init_txvga=0; init_txvga<10; ini
1697 {
1698 current_txvga = ( 0x24C40A|(i
1699 phy_set_rf_data(phw_data, 5,
1700 phw_data->txvga_setting_for_c
1701
1702 msleep(30); // 20060612.1.a
1703
1704 if( !hw_get_dxx_reg(phw_data,
1705 return false;
1706
1707 PHY_DEBUG(("[CAL] MODE_CTR
1708
1709 // a. Set iqcal_mode[1:0] to
1710 // enable "IQ alibration M
1711 reg_mode_ctrl &= ~(MASK_IQCAL
1712 reg_mode_ctrl &= ~MASK_IQCAL_
1713 reg_mode_ctrl |= (MASK_CALIB_
1714 reg_mode_ctrl |= (MASK_CALIB_
1715 hw_set_dxx_reg(phw_data, REG_
1716 PHY_DEBUG(("[CAL] MODE_CTR
1717
1718 udelay(1); // 20060612.1.a
1719
1720 udelay(300); // 20060612.1.a
1721
1722 // b.
1723 hw_get_dxx_reg(phw_data, REG_
1724
1725 PHY_DEBUG(("[CAL] CALIB_RE
1726 udelay(300); // 20060612.1.a
1727
1728 iqcal_tone_i0 = _s13_to_s32(v
1729 iqcal_tone_q0 = _s13_to_s32((
1730 PHY_DEBUG(("[CAL] ** iqcal
1731 iqcal_tone
1732
1733 sqsum = iqcal_tone_i0*iqcal_t
1734 iq_mag_0_tx = (s32) _sqrt(sqs
1735 PHY_DEBUG(("[CAL] ** auto_
1736
1737 if( iq_mag_0_tx>=700 && iq_ma
1738 break;
1739 else if(iq_mag_0_tx > 1750)
1740 {
1741 init_txvga=-2;
1742 continue;
1743 }
1744 else
1745 continue;
1746
1747 }
1748
1749 if( iq_mag_0_tx>=700 && iq_mag_0_tx<=
1750 return true;
1751 else
1752 return false;
1753 }
1754
1755
1756
1757
| This page was automatically generated by the LXR engine. |