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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: rf function code
29 * vnt_rf_write_embedded - Embedded write RF register via MAC
32 * RF_VT3226: RobertYu:20051111, VT3226C0 and before
33 * RF_VT3226D0: RobertYu:20051228
34 * RF_VT3342A0: RobertYu:20060609
43 #define CB_AL2230_INIT_SEQ 15
44 #define AL2230_PWR_IDX_LEN 64
46 #define CB_AL7230_INIT_SEQ 16
47 #define AL7230_PWR_IDX_LEN 64
49 #define CB_VT3226_INIT_SEQ 11
50 #define VT3226_PWR_IDX_LEN 64
52 #define CB_VT3342_INIT_SEQ 13
53 #define VT3342_PWR_IDX_LEN 64
55 static u8 al2230_init_table[CB_AL2230_INIT_SEQ][3] = {
73 static u8 al2230_channel_table0[CB_MAX_CHANNEL_24G][3] = {
90 static u8 al2230_channel_table1[CB_MAX_CHANNEL_24G][3] = {
107 static u8 al7230_init_table[CB_AL7230_INIT_SEQ][3] = {
126 static u8 al7230_init_table_amode[CB_AL7230_INIT_SEQ][3] = {
145 static u8 al7230_channel_table0[CB_MAX_CHANNEL][3] = {
160 {0x0f, 0xf5, 0x20}, /* channel 15 Tf = 4915MHz */
204 static u8 al7230_channel_table1[CB_MAX_CHANNEL][3] = {
219 {0x1d, 0x55, 0x51}, /* channel = 15, Tf = 4915MHz */
263 static u8 al7230_channel_table2[CB_MAX_CHANNEL][3] = {
278 {0x7f, 0xd7, 0x84}, /* channel = 15 Tf = 4915MHz */
322 static u8 vt3226_init_table[CB_VT3226_INIT_SEQ][3] = {
336 static u8 vt3226d0_init_table[CB_VT3226_INIT_SEQ][3] = {
350 static u8 vt3226_channel_table0[CB_MAX_CHANNEL_24G][3] = {
367 static u8 vt3226_channel_table1[CB_MAX_CHANNEL_24G][3] = {
384 static const u32 vt3226d0_lo_current_table[CB_MAX_CHANNEL_24G] = {
401 static u8 vt3342a0_init_table[CB_VT3342_INIT_SEQ][3] = { /* 11b/g mode */
417 static u8 vt3342_channel_table0[CB_MAX_CHANNEL][3] = {
432 {0x01, 0x15, 0x13}, /* channel = 15 Tf = 4915MHz */
476 static u8 vt3342_channel_table1[CB_MAX_CHANNEL][3] = {
491 {0x00, 0x44, 0x44}, /* channel = 15 Tf = 4915MHz */
536 static const u32 al2230_power_table[AL2230_PWR_IDX_LEN] = {
604 * Description: Write to IF/RF, by embedded programming
606 int vnt_rf_write_embedded(struct vnt_private *priv, u32 data)
610 data |= (VNT_RF_REG_LEN << 3) | IFREGCTL_REGW;
612 reg_data[0] = (u8)data;
613 reg_data[1] = (u8)(data >> 8);
614 reg_data[2] = (u8)(data >> 16);
615 reg_data[3] = (u8)(data >> 24);
617 vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF,
618 0, 0, ARRAY_SIZE(reg_data), reg_data);
623 /* Set Tx power by rate and channel number */
624 int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel)
626 u8 power = priv->cck_pwr;
638 if (channel < sizeof(priv->cck_pwr_tbl))
639 power = priv->cck_pwr_tbl[channel];
648 if (channel > CB_MAX_CHANNEL_24G)
649 power = priv->ofdm_a_pwr_tbl[channel-15];
651 power = priv->ofdm_pwr_tbl[channel-1];
655 return vnt_rf_set_txpower(priv, power, rate);
658 static u8 vnt_rf_addpower(struct vnt_private *priv)
660 s32 rssi = -priv->current_rssi;
665 if (priv->rf_type == RF_VT3226D0) {
684 /* Set Tx power by power level and rate */
685 int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate)
687 u32 power_setting = 0;
690 power += vnt_rf_addpower(priv);
691 if (power > VNT_RF_MAX_POWER)
692 power = VNT_RF_MAX_POWER;
694 if (priv->power == power)
699 switch (priv->rf_type) {
701 if (power >= AL2230_PWR_IDX_LEN)
704 ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
706 if (rate <= RATE_11M)
707 ret &= vnt_rf_write_embedded(priv, 0x0001b400);
709 ret &= vnt_rf_write_embedded(priv, 0x0005a400);
712 if (power >= AL2230_PWR_IDX_LEN)
715 ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
717 if (rate <= RATE_11M) {
718 ret &= vnt_rf_write_embedded(priv, 0x040c1400);
719 ret &= vnt_rf_write_embedded(priv, 0x00299b00);
721 ret &= vnt_rf_write_embedded(priv, 0x0005a400);
722 ret &= vnt_rf_write_embedded(priv, 0x00099b00);
727 if (rate <= RATE_11M)
728 ret &= vnt_rf_write_embedded(priv, 0x111bb900);
730 ret &= vnt_rf_write_embedded(priv, 0x221bb900);
732 if (power >= AL7230_PWR_IDX_LEN)
736 * 0x080F1B00 for 3 wire control TxGain(D10)
737 * and 0x31 as TX Gain value
739 power_setting = 0x080c0b00 | (power << 12);
741 ret &= vnt_rf_write_embedded(priv, power_setting);
746 if (power >= VT3226_PWR_IDX_LEN)
748 power_setting = ((0x3f - power) << 20) | (0x17 << 8);
750 ret &= vnt_rf_write_embedded(priv, power_setting);
754 if (power >= VT3226_PWR_IDX_LEN)
757 if (rate <= RATE_11M) {
758 u16 hw_value = priv->hw->conf.chandef.chan->hw_value;
760 power_setting = ((0x3f - power) << 20) | (0xe07 << 8);
762 ret &= vnt_rf_write_embedded(priv, power_setting);
763 ret &= vnt_rf_write_embedded(priv, 0x03c6a200);
765 dev_dbg(&priv->usb->dev,
766 "%s 11b channel [%d]\n", __func__, hw_value);
770 if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table))
771 ret &= vnt_rf_write_embedded(priv,
772 vt3226d0_lo_current_table[hw_value]);
774 ret &= vnt_rf_write_embedded(priv, 0x015C0800);
776 dev_dbg(&priv->usb->dev,
777 "@@@@ vnt_rf_set_txpower> 11G mode\n");
779 power_setting = ((0x3f - power) << 20) | (0x7 << 8);
781 ret &= vnt_rf_write_embedded(priv, power_setting);
782 ret &= vnt_rf_write_embedded(priv, 0x00C6A200);
783 ret &= vnt_rf_write_embedded(priv, 0x016BC600);
784 ret &= vnt_rf_write_embedded(priv, 0x00900800);
789 if (power >= VT3342_PWR_IDX_LEN)
792 power_setting = ((0x3f - power) << 20) | (0x27 << 8);
794 ret &= vnt_rf_write_embedded(priv, power_setting);
803 /* Convert rssi to dbm */
804 void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm)
806 u8 idx = (((rssi & 0xc0) >> 6) & 0x03);
807 long b = (rssi & 0x3f);
809 u8 airoharf[4] = {0, 18, 0, 40};
811 switch (priv->rf_type) {
824 *dbm = -1 * (a + b * 2);
827 void vnt_rf_table_download(struct vnt_private *priv)
829 u16 length1 = 0, length2 = 0, length3 = 0;
830 u8 *addr1 = NULL, *addr2 = NULL, *addr3 = NULL;
834 switch (priv->rf_type) {
837 length1 = CB_AL2230_INIT_SEQ * 3;
838 length2 = CB_MAX_CHANNEL_24G * 3;
839 length3 = CB_MAX_CHANNEL_24G * 3;
840 addr1 = &al2230_init_table[0][0];
841 addr2 = &al2230_channel_table0[0][0];
842 addr3 = &al2230_channel_table1[0][0];
845 length1 = CB_AL7230_INIT_SEQ * 3;
846 length2 = CB_MAX_CHANNEL * 3;
847 length3 = CB_MAX_CHANNEL * 3;
848 addr1 = &al7230_init_table[0][0];
849 addr2 = &al7230_channel_table0[0][0];
850 addr3 = &al7230_channel_table1[0][0];
853 length1 = CB_VT3226_INIT_SEQ * 3;
854 length2 = CB_MAX_CHANNEL_24G * 3;
855 length3 = CB_MAX_CHANNEL_24G * 3;
856 addr1 = &vt3226_init_table[0][0];
857 addr2 = &vt3226_channel_table0[0][0];
858 addr3 = &vt3226_channel_table1[0][0];
861 length1 = CB_VT3226_INIT_SEQ * 3;
862 length2 = CB_MAX_CHANNEL_24G * 3;
863 length3 = CB_MAX_CHANNEL_24G * 3;
864 addr1 = &vt3226d0_init_table[0][0];
865 addr2 = &vt3226_channel_table0[0][0];
866 addr3 = &vt3226_channel_table1[0][0];
869 length1 = CB_VT3342_INIT_SEQ * 3;
870 length2 = CB_MAX_CHANNEL * 3;
871 length3 = CB_MAX_CHANNEL * 3;
872 addr1 = &vt3342a0_init_table[0][0];
873 addr2 = &vt3342_channel_table0[0][0];
874 addr3 = &vt3342_channel_table1[0][0];
879 memcpy(array, addr1, length1);
881 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
882 MESSAGE_REQUEST_RF_INIT, length1, array);
884 /* Channel Table 0 */
886 while (length2 > 0) {
892 memcpy(array, addr2, length);
894 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
895 value, MESSAGE_REQUEST_RF_CH0, length, array);
902 /* Channel table 1 */
904 while (length3 > 0) {
910 memcpy(array, addr3, length);
912 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
913 value, MESSAGE_REQUEST_RF_CH1, length, array);
920 if (priv->rf_type == RF_AIROHA7230) {
921 length1 = CB_AL7230_INIT_SEQ * 3;
922 length2 = CB_MAX_CHANNEL * 3;
923 addr1 = &(al7230_init_table_amode[0][0]);
924 addr2 = &(al7230_channel_table2[0][0]);
926 memcpy(array, addr1, length1);
929 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
930 0, MESSAGE_REQUEST_RF_INIT2, length1, array);
932 /* Channel Table 0 */
934 while (length2 > 0) {
940 memcpy(array, addr2, length);
942 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
943 value, MESSAGE_REQUEST_RF_CH2, length, array);