forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/staging/vt6656/rf.c
....@@ -21,22 +21,16 @@
2121 *
2222 */
2323
24
+#include <linux/errno.h>
2425 #include "mac.h"
2526 #include "rf.h"
2627 #include "baseband.h"
2728 #include "usbpipe.h"
2829
2930 #define CB_AL2230_INIT_SEQ 15
30
-#define AL2230_PWR_IDX_LEN 64
31
-
3231 #define CB_AL7230_INIT_SEQ 16
33
-#define AL7230_PWR_IDX_LEN 64
34
-
3532 #define CB_VT3226_INIT_SEQ 11
36
-#define VT3226_PWR_IDX_LEN 64
37
-
3833 #define CB_VT3342_INIT_SEQ 13
39
-#define VT3342_PWR_IDX_LEN 64
4034
4135 static u8 al2230_init_table[CB_AL2230_INIT_SEQ][3] = {
4236 {0x03, 0xf7, 0x90},
....@@ -518,72 +512,45 @@
518512 {0x03, 0x00, 0x04}
519513 };
520514
521
-/* Power Table */
522
-static const u32 al2230_power_table[AL2230_PWR_IDX_LEN] = {
523
- 0x04040900,
524
- 0x04041900,
525
- 0x04042900,
526
- 0x04043900,
527
- 0x04044900,
528
- 0x04045900,
529
- 0x04046900,
530
- 0x04047900,
531
- 0x04048900,
532
- 0x04049900,
533
- 0x0404a900,
534
- 0x0404b900,
535
- 0x0404c900,
536
- 0x0404d900,
537
- 0x0404e900,
538
- 0x0404f900,
539
- 0x04050900,
540
- 0x04051900,
541
- 0x04052900,
542
- 0x04053900,
543
- 0x04054900,
544
- 0x04055900,
545
- 0x04056900,
546
- 0x04057900,
547
- 0x04058900,
548
- 0x04059900,
549
- 0x0405a900,
550
- 0x0405b900,
551
- 0x0405c900,
552
- 0x0405d900,
553
- 0x0405e900,
554
- 0x0405f900,
555
- 0x04060900,
556
- 0x04061900,
557
- 0x04062900,
558
- 0x04063900,
559
- 0x04064900,
560
- 0x04065900,
561
- 0x04066900,
562
- 0x04067900,
563
- 0x04068900,
564
- 0x04069900,
565
- 0x0406a900,
566
- 0x0406b900,
567
- 0x0406c900,
568
- 0x0406d900,
569
- 0x0406e900,
570
- 0x0406f900,
571
- 0x04070900,
572
- 0x04071900,
573
- 0x04072900,
574
- 0x04073900,
575
- 0x04074900,
576
- 0x04075900,
577
- 0x04076900,
578
- 0x04077900,
579
- 0x04078900,
580
- 0x04079900,
581
- 0x0407a900,
582
- 0x0407b900,
583
- 0x0407c900,
584
- 0x0407d900,
585
- 0x0407e900,
586
- 0x0407f900
515
+enum {
516
+ VNT_TABLE_INIT = 0,
517
+ VNT_TABLE_INIT_2 = 0,
518
+ VNT_TABLE_0 = 1,
519
+ VNT_TABLE_1 = 2,
520
+ VNT_TABLE_2 = 1
521
+};
522
+
523
+struct vnt_table_info {
524
+ u8 *addr;
525
+ int length;
526
+};
527
+
528
+static const struct vnt_table_info vnt_table_seq[][3] = {
529
+ { /* RF_AL2230, RF_AL2230S init table, channel table 0 and 1 */
530
+ {&al2230_init_table[0][0], CB_AL2230_INIT_SEQ * 3},
531
+ {&al2230_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3},
532
+ {&al2230_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3}
533
+ }, { /* RF_AIROHA7230 init table, channel table 0 and 1 */
534
+ {&al7230_init_table[0][0], CB_AL7230_INIT_SEQ * 3},
535
+ {&al7230_channel_table0[0][0], CB_MAX_CHANNEL * 3},
536
+ {&al7230_channel_table1[0][0], CB_MAX_CHANNEL * 3}
537
+ }, { /* RF_VT3226 init table, channel table 0 and 1 */
538
+ {&vt3226_init_table[0][0], CB_VT3226_INIT_SEQ * 3},
539
+ {&vt3226_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3},
540
+ {&vt3226_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3}
541
+ }, { /* RF_VT3226D0 init table, channel table 0 and 1 */
542
+ {&vt3226d0_init_table[0][0], CB_VT3226_INIT_SEQ * 3},
543
+ {&vt3226_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3},
544
+ {&vt3226_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3}
545
+ }, { /* RF_VT3342A0 init table, channel table 0 and 1 */
546
+ {&vt3342a0_init_table[0][0], CB_VT3342_INIT_SEQ * 3},
547
+ {&vt3342_channel_table0[0][0], CB_MAX_CHANNEL * 3},
548
+ {&vt3342_channel_table1[0][0], CB_MAX_CHANNEL * 3}
549
+ }, { /* RF_AIROHA7230 init table 2 and channel table 2 */
550
+ {&al7230_init_table_amode[0][0], CB_AL7230_INIT_SEQ * 3},
551
+ {&al7230_channel_table2[0][0], CB_MAX_CHANNEL * 3},
552
+ {NULL, 0}
553
+ }
587554 };
588555
589556 /*
....@@ -600,124 +567,90 @@
600567 reg_data[2] = (u8)(data >> 16);
601568 reg_data[3] = (u8)(data >> 24);
602569
603
- vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF,
604
- 0, 0, ARRAY_SIZE(reg_data), reg_data);
605
-
606
- return true;
607
-}
608
-
609
-/* Set Tx power by rate and channel number */
610
-int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel)
611
-{
612
- u8 power = priv->cck_pwr;
613
-
614
- if (channel == 0)
615
- return -EINVAL;
616
-
617
- switch (rate) {
618
- case RATE_1M:
619
- case RATE_2M:
620
- case RATE_5M:
621
- case RATE_11M:
622
- channel--;
623
-
624
- if (channel < sizeof(priv->cck_pwr_tbl))
625
- power = priv->cck_pwr_tbl[channel];
626
- break;
627
- case RATE_6M:
628
- case RATE_9M:
629
- case RATE_12M:
630
- case RATE_18M:
631
- case RATE_24M:
632
- case RATE_36M:
633
- case RATE_48M:
634
- case RATE_54M:
635
- if (channel > CB_MAX_CHANNEL_24G)
636
- power = priv->ofdm_a_pwr_tbl[channel - 15];
637
- else
638
- power = priv->ofdm_pwr_tbl[channel - 1];
639
- break;
640
- }
641
-
642
- return vnt_rf_set_txpower(priv, power, rate);
570
+ return vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF, 0, 0,
571
+ ARRAY_SIZE(reg_data), reg_data);
643572 }
644573
645574 static u8 vnt_rf_addpower(struct vnt_private *priv)
646575 {
576
+ int base;
647577 s32 rssi = -priv->current_rssi;
648578
649579 if (!rssi)
650580 return 7;
651581
652
- if (priv->rf_type == RF_VT3226D0) {
653
- if (rssi < -70)
654
- return 9;
655
- else if (rssi < -65)
656
- return 7;
657
- else if (rssi < -60)
658
- return 5;
659
- } else {
660
- if (rssi < -80)
661
- return 9;
662
- else if (rssi < -75)
663
- return 7;
664
- else if (rssi < -70)
665
- return 5;
666
- }
582
+ if (priv->rf_type == RF_VT3226D0)
583
+ base = -60;
584
+ else
585
+ base = -70;
586
+
587
+ if (rssi < base)
588
+ return ((rssi - base + 1) / -5) * 2 + 5;
667589
668590 return 0;
669591 }
670592
671593 /* Set Tx power by power level and rate */
672
-int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate)
594
+static int vnt_rf_set_txpower(struct vnt_private *priv, u8 power,
595
+ struct ieee80211_channel *ch)
673596 {
674597 u32 power_setting = 0;
675
- int ret = true;
598
+ int ret = 0;
676599
677600 power += vnt_rf_addpower(priv);
678601 if (power > VNT_RF_MAX_POWER)
679602 power = VNT_RF_MAX_POWER;
680603
681604 if (priv->power == power)
682
- return true;
605
+ return 0;
683606
684607 priv->power = power;
685608
686609 switch (priv->rf_type) {
687610 case RF_AL2230:
688
- if (power >= AL2230_PWR_IDX_LEN)
689
- return false;
611
+ power_setting = 0x0404090 | (power << 12);
690612
691
- ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
613
+ ret = vnt_rf_write_embedded(priv, power_setting);
614
+ if (ret)
615
+ return ret;
692616
693
- if (rate <= RATE_11M)
694
- ret &= vnt_rf_write_embedded(priv, 0x0001b400);
617
+ if (ch->flags & IEEE80211_CHAN_NO_OFDM)
618
+ ret = vnt_rf_write_embedded(priv, 0x0001b400);
695619 else
696
- ret &= vnt_rf_write_embedded(priv, 0x0005a400);
620
+ ret = vnt_rf_write_embedded(priv, 0x0005a400);
621
+
697622 break;
698623 case RF_AL2230S:
699
- if (power >= AL2230_PWR_IDX_LEN)
700
- return false;
624
+ power_setting = 0x0404090 | (power << 12);
701625
702
- ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
626
+ ret = vnt_rf_write_embedded(priv, power_setting);
627
+ if (ret)
628
+ return ret;
703629
704
- if (rate <= RATE_11M) {
705
- ret &= vnt_rf_write_embedded(priv, 0x040c1400);
706
- ret &= vnt_rf_write_embedded(priv, 0x00299b00);
630
+ if (ch->flags & IEEE80211_CHAN_NO_OFDM) {
631
+ ret = vnt_rf_write_embedded(priv, 0x040c1400);
632
+ if (ret)
633
+ return ret;
634
+
635
+ ret = vnt_rf_write_embedded(priv, 0x00299b00);
707636 } else {
708
- ret &= vnt_rf_write_embedded(priv, 0x0005a400);
709
- ret &= vnt_rf_write_embedded(priv, 0x00099b00);
637
+ ret = vnt_rf_write_embedded(priv, 0x0005a400);
638
+ if (ret)
639
+ return ret;
640
+
641
+ ret = vnt_rf_write_embedded(priv, 0x00099b00);
710642 }
643
+
711644 break;
712645
713646 case RF_AIROHA7230:
714
- if (rate <= RATE_11M)
715
- ret &= vnt_rf_write_embedded(priv, 0x111bb900);
647
+ if (ch->flags & IEEE80211_CHAN_NO_OFDM)
648
+ ret = vnt_rf_write_embedded(priv, 0x111bb900);
716649 else
717
- ret &= vnt_rf_write_embedded(priv, 0x221bb900);
650
+ ret = vnt_rf_write_embedded(priv, 0x221bb900);
718651
719
- if (power >= AL7230_PWR_IDX_LEN)
720
- return false;
652
+ if (ret)
653
+ return ret;
721654
722655 /*
723656 * 0x080F1B00 for 3 wire control TxGain(D10)
....@@ -725,66 +658,103 @@
725658 */
726659 power_setting = 0x080c0b00 | (power << 12);
727660
728
- ret &= vnt_rf_write_embedded(priv, power_setting);
729
-
661
+ ret = vnt_rf_write_embedded(priv, power_setting);
730662 break;
731663
732664 case RF_VT3226:
733
- if (power >= VT3226_PWR_IDX_LEN)
734
- return false;
735665 power_setting = ((0x3f - power) << 20) | (0x17 << 8);
736666
737
- ret &= vnt_rf_write_embedded(priv, power_setting);
738
-
667
+ ret = vnt_rf_write_embedded(priv, power_setting);
739668 break;
740669 case RF_VT3226D0:
741
- if (power >= VT3226_PWR_IDX_LEN)
742
- return false;
743
-
744
- if (rate <= RATE_11M) {
745
- u16 hw_value = priv->hw->conf.chandef.chan->hw_value;
670
+ if (ch->flags & IEEE80211_CHAN_NO_OFDM) {
671
+ u16 hw_value = ch->hw_value;
746672
747673 power_setting = ((0x3f - power) << 20) | (0xe07 << 8);
748674
749
- ret &= vnt_rf_write_embedded(priv, power_setting);
750
- ret &= vnt_rf_write_embedded(priv, 0x03c6a200);
675
+ ret = vnt_rf_write_embedded(priv, power_setting);
676
+ if (ret)
677
+ return ret;
678
+
679
+ ret = vnt_rf_write_embedded(priv, 0x03c6a200);
680
+ if (ret)
681
+ return ret;
751682
752683 dev_dbg(&priv->usb->dev,
753684 "%s 11b channel [%d]\n", __func__, hw_value);
754685
755686 hw_value--;
756687
757
- if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table))
758
- ret &= vnt_rf_write_embedded(priv,
688
+ if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table)) {
689
+ ret = vnt_rf_write_embedded(priv,
759690 vt3226d0_lo_current_table[hw_value]);
691
+ if (ret)
692
+ return ret;
693
+ }
760694
761
- ret &= vnt_rf_write_embedded(priv, 0x015C0800);
695
+ ret = vnt_rf_write_embedded(priv, 0x015C0800);
762696 } else {
763697 dev_dbg(&priv->usb->dev,
764698 "@@@@ %s> 11G mode\n", __func__);
765699
766700 power_setting = ((0x3f - power) << 20) | (0x7 << 8);
767701
768
- ret &= vnt_rf_write_embedded(priv, power_setting);
769
- ret &= vnt_rf_write_embedded(priv, 0x00C6A200);
770
- ret &= vnt_rf_write_embedded(priv, 0x016BC600);
771
- ret &= vnt_rf_write_embedded(priv, 0x00900800);
702
+ ret = vnt_rf_write_embedded(priv, power_setting);
703
+ if (ret)
704
+ return ret;
705
+
706
+ ret = vnt_rf_write_embedded(priv, 0x00C6A200);
707
+ if (ret)
708
+ return ret;
709
+
710
+ ret = vnt_rf_write_embedded(priv, 0x016BC600);
711
+ if (ret)
712
+ return ret;
713
+
714
+ ret = vnt_rf_write_embedded(priv, 0x00900800);
772715 }
716
+
773717 break;
774718
775719 case RF_VT3342A0:
776
- if (power >= VT3342_PWR_IDX_LEN)
777
- return false;
778
-
779720 power_setting = ((0x3f - power) << 20) | (0x27 << 8);
780721
781
- ret &= vnt_rf_write_embedded(priv, power_setting);
782
-
722
+ ret = vnt_rf_write_embedded(priv, power_setting);
783723 break;
784724 default:
785725 break;
786726 }
787727 return ret;
728
+}
729
+
730
+/* Set Tx power by channel number type */
731
+int vnt_rf_setpower(struct vnt_private *priv,
732
+ struct ieee80211_channel *ch)
733
+{
734
+ u16 channel;
735
+ u8 power = priv->cck_pwr;
736
+
737
+ if (!ch)
738
+ return -EINVAL;
739
+
740
+ /* set channel number to array number */
741
+ channel = ch->hw_value - 1;
742
+
743
+ if (ch->flags & IEEE80211_CHAN_NO_OFDM) {
744
+ if (channel < ARRAY_SIZE(priv->cck_pwr_tbl))
745
+ power = priv->cck_pwr_tbl[channel];
746
+ } else if (ch->band == NL80211_BAND_5GHZ) {
747
+ /* remove 14 channels to array size */
748
+ channel -= 14;
749
+
750
+ if (channel < ARRAY_SIZE(priv->ofdm_a_pwr_tbl))
751
+ power = priv->ofdm_a_pwr_tbl[channel];
752
+ } else {
753
+ if (channel < ARRAY_SIZE(priv->ofdm_pwr_tbl))
754
+ power = priv->ofdm_pwr_tbl[channel];
755
+ }
756
+
757
+ return vnt_rf_set_txpower(priv, power, ch);
788758 }
789759
790760 /* Convert rssi to dbm */
....@@ -811,128 +781,75 @@
811781 *dbm = -1 * (a + b * 2);
812782 }
813783
814
-void vnt_rf_table_download(struct vnt_private *priv)
784
+int vnt_rf_table_download(struct vnt_private *priv)
815785 {
816
- u16 length1 = 0, length2 = 0, length3 = 0;
817
- u8 *addr1 = NULL, *addr2 = NULL, *addr3 = NULL;
818
- u16 length, value;
819
- u8 array[256];
786
+ int ret;
787
+ int idx = -1;
788
+ const struct vnt_table_info *table_seq;
820789
821790 switch (priv->rf_type) {
822791 case RF_AL2230:
823792 case RF_AL2230S:
824
- length1 = CB_AL2230_INIT_SEQ * 3;
825
- length2 = CB_MAX_CHANNEL_24G * 3;
826
- length3 = CB_MAX_CHANNEL_24G * 3;
827
- addr1 = &al2230_init_table[0][0];
828
- addr2 = &al2230_channel_table0[0][0];
829
- addr3 = &al2230_channel_table1[0][0];
793
+ idx = 0;
830794 break;
831795 case RF_AIROHA7230:
832
- length1 = CB_AL7230_INIT_SEQ * 3;
833
- length2 = CB_MAX_CHANNEL * 3;
834
- length3 = CB_MAX_CHANNEL * 3;
835
- addr1 = &al7230_init_table[0][0];
836
- addr2 = &al7230_channel_table0[0][0];
837
- addr3 = &al7230_channel_table1[0][0];
796
+ idx = 1;
838797 break;
839798 case RF_VT3226:
840
- length1 = CB_VT3226_INIT_SEQ * 3;
841
- length2 = CB_MAX_CHANNEL_24G * 3;
842
- length3 = CB_MAX_CHANNEL_24G * 3;
843
- addr1 = &vt3226_init_table[0][0];
844
- addr2 = &vt3226_channel_table0[0][0];
845
- addr3 = &vt3226_channel_table1[0][0];
799
+ idx = 2;
846800 break;
847801 case RF_VT3226D0:
848
- length1 = CB_VT3226_INIT_SEQ * 3;
849
- length2 = CB_MAX_CHANNEL_24G * 3;
850
- length3 = CB_MAX_CHANNEL_24G * 3;
851
- addr1 = &vt3226d0_init_table[0][0];
852
- addr2 = &vt3226_channel_table0[0][0];
853
- addr3 = &vt3226_channel_table1[0][0];
802
+ idx = 3;
854803 break;
855804 case RF_VT3342A0:
856
- length1 = CB_VT3342_INIT_SEQ * 3;
857
- length2 = CB_MAX_CHANNEL * 3;
858
- length3 = CB_MAX_CHANNEL * 3;
859
- addr1 = &vt3342a0_init_table[0][0];
860
- addr2 = &vt3342_channel_table0[0][0];
861
- addr3 = &vt3342_channel_table1[0][0];
805
+ idx = 4;
862806 break;
863807 }
864808
865
- /* Init Table */
866
- memcpy(array, addr1, length1);
809
+ if (idx < 0)
810
+ return 0;
867811
868
- vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
869
- MESSAGE_REQUEST_RF_INIT, length1, array);
812
+ table_seq = &vnt_table_seq[idx][0];
813
+
814
+ /* Init Table */
815
+ ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
816
+ MESSAGE_REQUEST_RF_INIT,
817
+ table_seq[VNT_TABLE_INIT].length,
818
+ table_seq[VNT_TABLE_INIT].addr);
819
+ if (ret)
820
+ return ret;
870821
871822 /* Channel Table 0 */
872
- value = 0;
873
- while (length2 > 0) {
874
- if (length2 >= 64)
875
- length = 64;
876
- else
877
- length = length2;
823
+ ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE,
824
+ MESSAGE_REQUEST_RF_CH0,
825
+ table_seq[VNT_TABLE_0].length,
826
+ table_seq[VNT_TABLE_0].addr);
827
+ if (ret)
828
+ return ret;
878829
879
- memcpy(array, addr2, length);
880
-
881
- vnt_control_out(priv, MESSAGE_TYPE_WRITE,
882
- value, MESSAGE_REQUEST_RF_CH0, length, array);
883
-
884
- length2 -= length;
885
- value += length;
886
- addr2 += length;
887
- }
888
-
889
- /* Channel table 1 */
890
- value = 0;
891
- while (length3 > 0) {
892
- if (length3 >= 64)
893
- length = 64;
894
- else
895
- length = length3;
896
-
897
- memcpy(array, addr3, length);
898
-
899
- vnt_control_out(priv, MESSAGE_TYPE_WRITE,
900
- value, MESSAGE_REQUEST_RF_CH1, length, array);
901
-
902
- length3 -= length;
903
- value += length;
904
- addr3 += length;
905
- }
830
+ /* Channel Table 1 */
831
+ ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE,
832
+ MESSAGE_REQUEST_RF_CH1,
833
+ table_seq[VNT_TABLE_1].length,
834
+ table_seq[VNT_TABLE_1].addr);
906835
907836 if (priv->rf_type == RF_AIROHA7230) {
908
- length1 = CB_AL7230_INIT_SEQ * 3;
909
- length2 = CB_MAX_CHANNEL * 3;
910
- addr1 = &al7230_init_table_amode[0][0];
911
- addr2 = &al7230_channel_table2[0][0];
912
-
913
- memcpy(array, addr1, length1);
837
+ table_seq = &vnt_table_seq[5][0];
914838
915839 /* Init Table 2 */
916
- vnt_control_out(priv, MESSAGE_TYPE_WRITE,
917
- 0, MESSAGE_REQUEST_RF_INIT2, length1, array);
840
+ ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
841
+ MESSAGE_REQUEST_RF_INIT2,
842
+ table_seq[VNT_TABLE_INIT_2].length,
843
+ table_seq[VNT_TABLE_INIT_2].addr);
844
+ if (ret)
845
+ return ret;
918846
919
- /* Channel Table 0 */
920
- value = 0;
921
- while (length2 > 0) {
922
- if (length2 >= 64)
923
- length = 64;
924
- else
925
- length = length2;
926
-
927
- memcpy(array, addr2, length);
928
-
929
- vnt_control_out(priv, MESSAGE_TYPE_WRITE,
930
- value, MESSAGE_REQUEST_RF_CH2,
931
- length, array);
932
-
933
- length2 -= length;
934
- value += length;
935
- addr2 += length;
936
- }
847
+ /* Channel Table 2 */
848
+ ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE,
849
+ MESSAGE_REQUEST_RF_CH2,
850
+ table_seq[VNT_TABLE_2].length,
851
+ table_seq[VNT_TABLE_2].addr);
937852 }
853
+
854
+ return ret;
938855 }