2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 * Purpose: rf function code
25 * vnt_rf_write_embedded - Embedded write RF register via MAC
28 * RF_VT3226: RobertYu:20051111, VT3226C0 and before
29 * RF_VT3226D0: RobertYu:20051228
30 * RF_VT3342A0: RobertYu:20060609
39 #define CB_AL2230_INIT_SEQ 15
40 #define AL2230_PWR_IDX_LEN 64
42 #define CB_AL7230_INIT_SEQ 16
43 #define AL7230_PWR_IDX_LEN 64
45 #define CB_VT3226_INIT_SEQ 11
46 #define VT3226_PWR_IDX_LEN 64
48 #define CB_VT3342_INIT_SEQ 13
49 #define VT3342_PWR_IDX_LEN 64
51 static u8 al2230_init_table[CB_AL2230_INIT_SEQ][3] = {
69 static u8 al2230_channel_table0[CB_MAX_CHANNEL_24G][3] = {
86 static u8 al2230_channel_table1[CB_MAX_CHANNEL_24G][3] = {
103 static u8 al7230_init_table[CB_AL7230_INIT_SEQ][3] = {
122 static u8 al7230_init_table_amode[CB_AL7230_INIT_SEQ][3] = {
141 static u8 al7230_channel_table0[CB_MAX_CHANNEL][3] = {
156 {0x0f, 0xf5, 0x20}, /* channel 15 Tf = 4915MHz */
200 static u8 al7230_channel_table1[CB_MAX_CHANNEL][3] = {
215 {0x1d, 0x55, 0x51}, /* channel = 15, Tf = 4915MHz */
259 static u8 al7230_channel_table2[CB_MAX_CHANNEL][3] = {
274 {0x7f, 0xd7, 0x84}, /* channel = 15 Tf = 4915MHz */
318 static u8 vt3226_init_table[CB_VT3226_INIT_SEQ][3] = {
332 static u8 vt3226d0_init_table[CB_VT3226_INIT_SEQ][3] = {
346 static u8 vt3226_channel_table0[CB_MAX_CHANNEL_24G][3] = {
363 static u8 vt3226_channel_table1[CB_MAX_CHANNEL_24G][3] = {
380 static const u32 vt3226d0_lo_current_table[CB_MAX_CHANNEL_24G] = {
397 static u8 vt3342a0_init_table[CB_VT3342_INIT_SEQ][3] = { /* 11b/g mode */
413 static u8 vt3342_channel_table0[CB_MAX_CHANNEL][3] = {
428 {0x01, 0x15, 0x13}, /* channel = 15 Tf = 4915MHz */
472 static u8 vt3342_channel_table1[CB_MAX_CHANNEL][3] = {
487 {0x00, 0x44, 0x44}, /* channel = 15 Tf = 4915MHz */
532 static const u32 al2230_power_table[AL2230_PWR_IDX_LEN] = {
600 * Description: Write to IF/RF, by embedded programming
602 int vnt_rf_write_embedded(struct vnt_private *priv, u32 data)
606 data |= (VNT_RF_REG_LEN << 3) | IFREGCTL_REGW;
608 reg_data[0] = (u8)data;
609 reg_data[1] = (u8)(data >> 8);
610 reg_data[2] = (u8)(data >> 16);
611 reg_data[3] = (u8)(data >> 24);
613 vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF,
614 0, 0, ARRAY_SIZE(reg_data), reg_data);
619 /* Set Tx power by rate and channel number */
620 int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel)
622 u8 power = priv->cck_pwr;
634 if (channel < sizeof(priv->cck_pwr_tbl))
635 power = priv->cck_pwr_tbl[channel];
645 if (channel > CB_MAX_CHANNEL_24G)
646 power = priv->ofdm_a_pwr_tbl[channel-15];
648 power = priv->ofdm_pwr_tbl[channel-1];
652 return vnt_rf_set_txpower(priv, power, rate);
655 static u8 vnt_rf_addpower(struct vnt_private *priv)
657 s32 rssi = -priv->current_rssi;
662 if (priv->rf_type == RF_VT3226D0) {
681 /* Set Tx power by power level and rate */
682 int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate)
684 u32 power_setting = 0;
687 power += vnt_rf_addpower(priv);
688 if (power > VNT_RF_MAX_POWER)
689 power = VNT_RF_MAX_POWER;
691 if (priv->power == power)
696 switch (priv->rf_type) {
698 if (power >= AL2230_PWR_IDX_LEN)
701 ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
703 if (rate <= RATE_11M)
704 ret &= vnt_rf_write_embedded(priv, 0x0001b400);
706 ret &= vnt_rf_write_embedded(priv, 0x0005a400);
709 if (power >= AL2230_PWR_IDX_LEN)
712 ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
714 if (rate <= RATE_11M) {
715 ret &= vnt_rf_write_embedded(priv, 0x040c1400);
716 ret &= vnt_rf_write_embedded(priv, 0x00299b00);
718 ret &= vnt_rf_write_embedded(priv, 0x0005a400);
719 ret &= vnt_rf_write_embedded(priv, 0x00099b00);
724 if (rate <= RATE_11M)
725 ret &= vnt_rf_write_embedded(priv, 0x111bb900);
727 ret &= vnt_rf_write_embedded(priv, 0x221bb900);
729 if (power >= AL7230_PWR_IDX_LEN)
733 * 0x080F1B00 for 3 wire control TxGain(D10)
734 * and 0x31 as TX Gain value
736 power_setting = 0x080c0b00 | (power << 12);
738 ret &= vnt_rf_write_embedded(priv, power_setting);
743 if (power >= VT3226_PWR_IDX_LEN)
745 power_setting = ((0x3f - power) << 20) | (0x17 << 8);
747 ret &= vnt_rf_write_embedded(priv, power_setting);
751 if (power >= VT3226_PWR_IDX_LEN)
754 if (rate <= RATE_11M) {
755 u16 hw_value = priv->hw->conf.chandef.chan->hw_value;
757 power_setting = ((0x3f - power) << 20) | (0xe07 << 8);
759 ret &= vnt_rf_write_embedded(priv, power_setting);
760 ret &= vnt_rf_write_embedded(priv, 0x03c6a200);
762 dev_dbg(&priv->usb->dev,
763 "%s 11b channel [%d]\n", __func__, hw_value);
767 if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table))
768 ret &= vnt_rf_write_embedded(priv,
769 vt3226d0_lo_current_table[hw_value]);
771 ret &= vnt_rf_write_embedded(priv, 0x015C0800);
773 dev_dbg(&priv->usb->dev,
774 "@@@@ vnt_rf_set_txpower> 11G mode\n");
776 power_setting = ((0x3f - power) << 20) | (0x7 << 8);
778 ret &= vnt_rf_write_embedded(priv, power_setting);
779 ret &= vnt_rf_write_embedded(priv, 0x00C6A200);
780 ret &= vnt_rf_write_embedded(priv, 0x016BC600);
781 ret &= vnt_rf_write_embedded(priv, 0x00900800);
786 if (power >= VT3342_PWR_IDX_LEN)
789 power_setting = ((0x3f - power) << 20) | (0x27 << 8);
791 ret &= vnt_rf_write_embedded(priv, power_setting);
800 /* Convert rssi to dbm */
801 void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm)
803 u8 idx = (((rssi & 0xc0) >> 6) & 0x03);
804 long b = (rssi & 0x3f);
806 u8 airoharf[4] = {0, 18, 0, 40};
808 switch (priv->rf_type) {
821 *dbm = -1 * (a + b * 2);
824 void vnt_rf_table_download(struct vnt_private *priv)
826 u16 length1 = 0, length2 = 0, length3 = 0;
827 u8 *addr1 = NULL, *addr2 = NULL, *addr3 = NULL;
831 switch (priv->rf_type) {
834 length1 = CB_AL2230_INIT_SEQ * 3;
835 length2 = CB_MAX_CHANNEL_24G * 3;
836 length3 = CB_MAX_CHANNEL_24G * 3;
837 addr1 = &al2230_init_table[0][0];
838 addr2 = &al2230_channel_table0[0][0];
839 addr3 = &al2230_channel_table1[0][0];
842 length1 = CB_AL7230_INIT_SEQ * 3;
843 length2 = CB_MAX_CHANNEL * 3;
844 length3 = CB_MAX_CHANNEL * 3;
845 addr1 = &al7230_init_table[0][0];
846 addr2 = &al7230_channel_table0[0][0];
847 addr3 = &al7230_channel_table1[0][0];
850 length1 = CB_VT3226_INIT_SEQ * 3;
851 length2 = CB_MAX_CHANNEL_24G * 3;
852 length3 = CB_MAX_CHANNEL_24G * 3;
853 addr1 = &vt3226_init_table[0][0];
854 addr2 = &vt3226_channel_table0[0][0];
855 addr3 = &vt3226_channel_table1[0][0];
858 length1 = CB_VT3226_INIT_SEQ * 3;
859 length2 = CB_MAX_CHANNEL_24G * 3;
860 length3 = CB_MAX_CHANNEL_24G * 3;
861 addr1 = &vt3226d0_init_table[0][0];
862 addr2 = &vt3226_channel_table0[0][0];
863 addr3 = &vt3226_channel_table1[0][0];
866 length1 = CB_VT3342_INIT_SEQ * 3;
867 length2 = CB_MAX_CHANNEL * 3;
868 length3 = CB_MAX_CHANNEL * 3;
869 addr1 = &vt3342a0_init_table[0][0];
870 addr2 = &vt3342_channel_table0[0][0];
871 addr3 = &vt3342_channel_table1[0][0];
876 memcpy(array, addr1, length1);
878 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
879 MESSAGE_REQUEST_RF_INIT, length1, array);
881 /* Channel Table 0 */
883 while (length2 > 0) {
889 memcpy(array, addr2, length);
891 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
892 value, MESSAGE_REQUEST_RF_CH0, length, array);
899 /* Channel table 1 */
901 while (length3 > 0) {
907 memcpy(array, addr3, length);
909 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
910 value, MESSAGE_REQUEST_RF_CH1, length, array);
917 if (priv->rf_type == RF_AIROHA7230) {
918 length1 = CB_AL7230_INIT_SEQ * 3;
919 length2 = CB_MAX_CHANNEL * 3;
920 addr1 = &al7230_init_table_amode[0][0];
921 addr2 = &al7230_channel_table2[0][0];
923 memcpy(array, addr1, length1);
926 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
927 0, MESSAGE_REQUEST_RF_INIT2, length1, array);
929 /* Channel Table 0 */
931 while (length2 > 0) {
937 memcpy(array, addr2, length);
939 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
940 value, MESSAGE_REQUEST_RF_CH2, length, array);