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: Implement functions to access baseband
29 * BBuGetFrameTime - Calculate data frame transmitting time
30 * BBvCalculateParameter - Calculate PhyLength, PhyService and Phy Signal parameter for baseband Tx
31 * BBbVT3184Init - VIA VT3184 baseband chip init code
46 static u8 abyVT3184_AGC[] = {
50 0x02, //3 //RobertYu:20060505, 0x04, //3
52 0x04, //5 //RobertYu:20060505, 0x06, //5
113 static u8 abyVT3184_AL2230[] = {
123 0x45,//tx //0x64 for FPGA
141 0x8e, //RobertYu:20060522, //0x8d,
142 0x0a, //RobertYu:20060515, //0x09,
161 0x0c, //RobertYu:20060522, //0x10,
194 0x00,//50 //RobertYu:20060505, //0x15,//50
203 0xd0, //RobertYu:20060505, //0xb0,
222 0x00, //0x80 for FPGA
252 0x1f, //RobertYu:20060516, //0x0f,
257 0x00, //RobertYu:20060505, //0x02,
258 0x20,//90 //RobertYu:20060505, //0x22,//90
287 0x15, //RobertYu:20060516, //0x00,
311 0xff, //RobertYu:20060509, //0x2c,
312 0x0e, //RobertYu:20060530, //0x0c,
315 0x00, //RobertYu:20060505, //0x01,
316 0x82, //RobertYu:20060516, //0x8f,
320 0x30, //RobertYu:20060627, //0x0b,
321 0x05, //RobertYu:20060516, //0x25,
339 0xf3, //RobertYu:20060516, //0xd3,
345 0x12, //RobertYu:20060627, //0x10,
353 0x05, //RobertYu:20060516, //0x0c,
372 //{{RobertYu:20060515, new BB setting for VT3226D0
373 static u8 abyVT3184_VT3226D0[] = {
383 0x45,//tx //0x64 for FPGA
401 0x8e, //RobertYu:20060525, //0x8d,
402 0x0a, //RobertYu:20060515, //0x09,
421 0x0c, //RobertYu:20060525, //0x10,
454 0x00,//50 //RobertYu:20060505, //0x15,//50
463 0xd0, //RobertYu:20060505, //0xb0,
482 0x00, //0x80 for FPGA
512 0x1f, //RobertYu:20060515, //0x0f,
517 0x00, //RobertYu:20060505, //0x02,
518 0x20,//90 //RobertYu:20060505, //0x22,//90
571 0xff, //RobertYu:20060509, //0x2c,
572 0x10, //RobertYu:20060525, //0x0c,
575 0x00, //RobertYu:20060505, //0x01,
576 0x84, //RobertYu:20060525, //0x8f,
580 0x24, //RobertYu:20060627, //0x18,
581 0x05, //RobertYu:20060515, //0x25,
599 0xf3, //RobertYu:20060515, //0xd3,
605 0x10, //RobertYu:20060627, //0x0e,
613 0x08, //RobertYu:20060515, //0x0c,
632 static const u16 awcFrameTime[MAX_RATE] =
633 {10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216};
636 * Description: Calculate data frame transmitting time
640 * preamble_type - Preamble Type
641 * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
642 * frame_length - Baseband Type
646 * Return Value: FrameTime
649 unsigned int BBuGetFrameTime(u8 preamble_type, u8 pkt_type,
650 unsigned int frame_length, u16 tx_rate)
652 unsigned int frame_time;
653 unsigned int preamble;
655 unsigned int rate = 0;
657 if (tx_rate > RATE_54M)
660 rate = (unsigned int)awcFrameTime[tx_rate];
663 if (preamble_type == 1)
668 frame_time = (frame_length * 80) / rate;
669 tmp = (frame_time * rate) / 80;
671 if (frame_length != tmp)
674 return preamble + frame_time;
676 frame_time = (frame_length * 8 + 22) / rate;
677 tmp = ((frame_time * rate) - 22) / 8;
679 if (frame_length != tmp)
682 frame_time = frame_time * 4;
684 if (pkt_type != PK_TYPE_11A)
687 return 20 + frame_time;
692 * Description: Calculate Length, Service, and Signal fields of Phy for Tx
696 * priv - Device Structure
697 * frame_length - Tx Frame Length
700 * struct vnt_phy_field *phy
701 * - pointer to Phy Length field
702 * - pointer to Phy Service field
703 * - pointer to Phy Signal field
708 void BBvCalculateParameter(struct vnt_private *priv, u32 frame_length,
709 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy)
715 u8 preamble_type = priv->byPreambleType;
717 bit_count = frame_length * 8;
728 count = bit_count / 2;
730 if (preamble_type == 1)
737 count = (bit_count * 10) / 55;
738 tmp = (count * 55) / 10;
740 if (tmp != bit_count)
743 if (preamble_type == 1)
750 count = bit_count / 11;
753 if (tmp != bit_count) {
756 if ((bit_count - tmp) <= 3)
760 if (preamble_type == 1)
767 if (pkt_type == PK_TYPE_11A)
774 if (pkt_type == PK_TYPE_11A)
781 if (pkt_type == PK_TYPE_11A)
788 if (pkt_type == PK_TYPE_11A)
795 if (pkt_type == PK_TYPE_11A)
802 if (pkt_type == PK_TYPE_11A)
809 if (pkt_type == PK_TYPE_11A)
816 if (pkt_type == PK_TYPE_11A)
822 if (pkt_type == PK_TYPE_11A)
829 if (pkt_type == PK_TYPE_11B) {
832 phy->service |= 0x80;
833 phy->len = cpu_to_le16((u16)count);
836 phy->len = cpu_to_le16((u16)frame_length);
841 * Description: Set Antenna mode
845 * priv - Device Structure
846 * antenna_mode - Antenna Mode
853 void BBvSetAntennaMode(struct vnt_private *priv, u8 antenna_mode)
855 switch (antenna_mode) {
860 priv->byBBRxConf &= 0xFC;
863 priv->byBBRxConf &= 0xFE;
864 priv->byBBRxConf |= 0x02;
868 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SET_ANTMD,
869 (u16)antenna_mode, 0, 0, NULL);
873 * Description: Set Antenna mode
877 * pDevice - Device Structure
878 * byAntennaMode - Antenna Mode
886 int BBbVT3184Init(struct vnt_private *priv)
896 status = CONTROLnsRequestIn(priv, MESSAGE_TYPE_READ, 0,
897 MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE,
899 if (status != STATUS_SUCCESS)
902 /* zonetype initial */
903 priv->byOriginalZonetype = priv->abyEEPROM[EEP_OFS_ZONETYPE];
905 if (priv->config_file.ZoneType >= 0) {
906 if ((priv->config_file.ZoneType == 0) &&
907 (priv->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {
908 priv->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
909 priv->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
911 dev_dbg(&priv->usb->dev, "Init Zone Type :USA\n");
912 } else if ((priv->config_file.ZoneType == 1) &&
913 (priv->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {
914 priv->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
915 priv->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
917 dev_dbg(&priv->usb->dev, "Init Zone Type :Japan\n");
918 } else if ((priv->config_file.ZoneType == 2) &&
919 (priv->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {
920 priv->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
921 priv->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
923 dev_dbg(&priv->usb->dev, "Init Zone Type :Europe\n");
925 if (priv->config_file.ZoneType !=
926 priv->abyEEPROM[EEP_OFS_ZONETYPE])
927 printk("zonetype in file[%02x]\
928 mismatch with in EEPROM[%02x]\n",
929 priv->config_file.ZoneType,
930 priv->abyEEPROM[EEP_OFS_ZONETYPE]);
932 printk("Read Zonetype file success,\
933 use default zonetype setting[%02x]\n",
934 priv->config_file.ZoneType);
938 if (!priv->bZoneRegExist)
939 priv->byZoneType = priv->abyEEPROM[EEP_OFS_ZONETYPE];
941 priv->byRFType = priv->abyEEPROM[EEP_OFS_RFTYPE];
943 dev_dbg(&priv->usb->dev, "Zone Type %x\n", priv->byZoneType);
945 dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->byRFType);
947 if ((priv->byRFType == RF_AL2230) ||
948 (priv->byRFType == RF_AL2230S)) {
949 priv->byBBRxConf = abyVT3184_AL2230[10];
950 length = sizeof(abyVT3184_AL2230);
951 addr = abyVT3184_AL2230;
953 length_agc = sizeof(abyVT3184_AGC);
955 priv->abyBBVGA[0] = 0x1C;
956 priv->abyBBVGA[1] = 0x10;
957 priv->abyBBVGA[2] = 0x0;
958 priv->abyBBVGA[3] = 0x0;
959 priv->ldBmThreshold[0] = -70;
960 priv->ldBmThreshold[1] = -48;
961 priv->ldBmThreshold[2] = 0;
962 priv->ldBmThreshold[3] = 0;
963 } else if (priv->byRFType == RF_AIROHA7230) {
964 priv->byBBRxConf = abyVT3184_AL2230[10];
965 length = sizeof(abyVT3184_AL2230);
966 addr = abyVT3184_AL2230;
968 length_agc = sizeof(abyVT3184_AGC);
972 priv->abyBBVGA[0] = 0x1c;
973 priv->abyBBVGA[1] = 0x10;
974 priv->abyBBVGA[2] = 0x0;
975 priv->abyBBVGA[3] = 0x0;
976 priv->ldBmThreshold[0] = -70;
977 priv->ldBmThreshold[1] = -48;
978 priv->ldBmThreshold[2] = 0;
979 priv->ldBmThreshold[3] = 0;
980 } else if ((priv->byRFType == RF_VT3226) ||
981 (priv->byRFType == RF_VT3226D0)) {
982 priv->byBBRxConf = abyVT3184_VT3226D0[10];
983 length = sizeof(abyVT3184_VT3226D0);
984 addr = abyVT3184_VT3226D0;
986 length_agc = sizeof(abyVT3184_AGC);
988 priv->abyBBVGA[0] = 0x20;
989 priv->abyBBVGA[1] = 0x10;
990 priv->abyBBVGA[2] = 0x0;
991 priv->abyBBVGA[3] = 0x0;
992 priv->ldBmThreshold[0] = -70;
993 priv->ldBmThreshold[1] = -48;
994 priv->ldBmThreshold[2] = 0;
995 priv->ldBmThreshold[3] = 0;
996 /* Fix VT3226 DFC system timing issue */
997 MACvRegBitsOn(priv, MAC_REG_SOFTPWRCTL2, SOFTPWRCTL_RFLEOPT);
998 } else if ((priv->byRFType == RF_VT3342A0)) {
999 priv->byBBRxConf = abyVT3184_VT3226D0[10];
1000 length = sizeof(abyVT3184_VT3226D0);
1001 addr = abyVT3184_VT3226D0;
1002 agc = abyVT3184_AGC;
1003 length_agc = sizeof(abyVT3184_AGC);
1005 priv->abyBBVGA[0] = 0x20;
1006 priv->abyBBVGA[1] = 0x10;
1007 priv->abyBBVGA[2] = 0x0;
1008 priv->abyBBVGA[3] = 0x0;
1009 priv->ldBmThreshold[0] = -70;
1010 priv->ldBmThreshold[1] = -48;
1011 priv->ldBmThreshold[2] = 0;
1012 priv->ldBmThreshold[3] = 0;
1013 /* Fix VT3226 DFC system timing issue */
1014 MACvRegBitsOn(priv, MAC_REG_SOFTPWRCTL2, SOFTPWRCTL_RFLEOPT);
1019 memcpy(array, addr, length);
1021 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE, 0,
1022 MESSAGE_REQUEST_BBREG, length, array);
1024 memcpy(array, agc, length_agc);
1026 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE, 0,
1027 MESSAGE_REQUEST_BBAGC, length_agc, array);
1029 if ((priv->byRFType == RF_VT3226) ||
1030 (priv->byRFType == RF_VT3342A0)) {
1031 ControlvWriteByte(priv, MESSAGE_REQUEST_MACREG,
1032 MAC_REG_ITRTMSET, 0x23);
1033 MACvRegBitsOn(priv, MAC_REG_PAPEDELAY, 0x01);
1034 } else if (priv->byRFType == RF_VT3226D0) {
1035 ControlvWriteByte(priv, MESSAGE_REQUEST_MACREG,
1036 MAC_REG_ITRTMSET, 0x11);
1037 MACvRegBitsOn(priv, MAC_REG_PAPEDELAY, 0x01);
1040 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
1041 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
1043 RFbRFTableDownload(priv);
1046 /* Fix for TX USB resets from vendors driver */
1047 CONTROLnsRequestIn(priv, MESSAGE_TYPE_READ, USB_REG4,
1048 MESSAGE_REQUEST_MEM, sizeof(data), &data);
1052 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE, USB_REG4,
1053 MESSAGE_REQUEST_MEM, sizeof(data), &data);
1059 * Description: Set ShortSlotTime mode
1063 * priv - Device Structure
1067 * Return Value: none
1070 void BBvSetShortSlotTime(struct vnt_private *priv)
1074 if (priv->bShortSlotTime)
1075 priv->byBBRxConf &= 0xdf;
1077 priv->byBBRxConf |= 0x20;
1079 ControlvReadByte(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
1081 if (bb_vga == priv->abyBBVGA[0])
1082 priv->byBBRxConf |= 0x20;
1084 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->byBBRxConf);
1087 void BBvSetVGAGainOffset(struct vnt_private *priv, u8 data)
1090 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
1092 /* patch for 3253B0 Baseband with Cardbus module */
1093 if (priv->bShortSlotTime)
1094 priv->byBBRxConf &= 0xdf; /* 1101 1111 */
1096 priv->byBBRxConf |= 0x20; /* 0010 0000 */
1098 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->byBBRxConf);
1102 * Description: BBvSetDeepSleep
1106 * priv - Device Structure
1110 * Return Value: none
1113 void BBvSetDeepSleep(struct vnt_private *priv)
1115 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */
1116 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */
1119 void BBvExitDeepSleep(struct vnt_private *priv)
1121 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */
1122 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */
1125 void BBvUpdatePreEDThreshold(struct vnt_private *priv, int scanning)
1127 u8 cr_201 = 0x0, cr_206 = 0x0;
1128 u8 ed_inx = priv->byBBPreEDIndex;
1130 switch (priv->byRFType) {
1134 if (scanning) { /* Max sensitivity */
1140 if (priv->byBBPreEDRSSI <= 45) {
1143 } else if (priv->byBBPreEDRSSI <= 46) {
1146 } else if (priv->byBBPreEDRSSI <= 47) {
1149 } else if (priv->byBBPreEDRSSI <= 49) {
1152 } else if (priv->byBBPreEDRSSI <= 51) {
1155 } else if (priv->byBBPreEDRSSI <= 53) {
1158 } else if (priv->byBBPreEDRSSI <= 55) {
1161 } else if (priv->byBBPreEDRSSI <= 56) {
1165 } else if (priv->byBBPreEDRSSI <= 57) {
1169 } else if (priv->byBBPreEDRSSI <= 58) {
1173 } else if (priv->byBBPreEDRSSI <= 59) {
1177 } else if (priv->byBBPreEDRSSI <= 60) {
1181 } else if (priv->byBBPreEDRSSI <= 61) {
1184 } else if (priv->byBBPreEDRSSI <= 62) {
1187 } else if (priv->byBBPreEDRSSI <= 63) {
1190 } else if (priv->byBBPreEDRSSI <= 64) {
1193 } else if (priv->byBBPreEDRSSI <= 65) {
1196 } else if (priv->byBBPreEDRSSI <= 66) {
1199 } else if (priv->byBBPreEDRSSI <= 67) {
1202 } else if (priv->byBBPreEDRSSI <= 68) {
1213 if (scanning) { /* Max sensitivity */
1219 if (priv->byBBPreEDRSSI <= 41) {
1222 } else if (priv->byBBPreEDRSSI <= 42) {
1225 } else if (priv->byBBPreEDRSSI <= 43) {
1228 } else if (priv->byBBPreEDRSSI <= 45) {
1231 } else if (priv->byBBPreEDRSSI <= 47) {
1234 } else if (priv->byBBPreEDRSSI <= 49) {
1237 } else if (priv->byBBPreEDRSSI <= 51) {
1240 } else if (priv->byBBPreEDRSSI <= 53) {
1243 } else if (priv->byBBPreEDRSSI <= 55) {
1247 } else if (priv->byBBPreEDRSSI <= 56) {
1251 } else if (priv->byBBPreEDRSSI <= 57) {
1255 } else if (priv->byBBPreEDRSSI <= 58) {
1259 } else if (priv->byBBPreEDRSSI <= 59) {
1263 } else if (priv->byBBPreEDRSSI <= 60) {
1266 } else if (priv->byBBPreEDRSSI <= 61) {
1269 } else if (priv->byBBPreEDRSSI <= 62) {
1272 } else if (priv->byBBPreEDRSSI <= 63) {
1275 } else if (priv->byBBPreEDRSSI <= 64) {
1278 } else if (priv->byBBPreEDRSSI <= 65) {
1281 } else if (priv->byBBPreEDRSSI <= 66) {
1284 } else if (priv->byBBPreEDRSSI <= 67) {
1287 } else if (priv->byBBPreEDRSSI <= 68) {
1297 if (scanning) { /* need Max sensitivity */
1303 if (priv->byBBPreEDRSSI <= 41) {
1306 } else if (priv->byBBPreEDRSSI <= 42) {
1309 } else if (priv->byBBPreEDRSSI <= 43) {
1312 } else if (priv->byBBPreEDRSSI <= 45) {
1315 } else if (priv->byBBPreEDRSSI <= 47) {
1318 } else if (priv->byBBPreEDRSSI <= 49) {
1321 } else if (priv->byBBPreEDRSSI <= 51) {
1324 } else if (priv->byBBPreEDRSSI <= 53) {
1327 } else if (priv->byBBPreEDRSSI <= 55) {
1331 } else if (priv->byBBPreEDRSSI <= 56) {
1335 } else if (priv->byBBPreEDRSSI <= 57) {
1339 } else if (priv->byBBPreEDRSSI <= 58) {
1343 } else if (priv->byBBPreEDRSSI <= 59) {
1347 } else if (priv->byBBPreEDRSSI <= 60) {
1350 } else if (priv->byBBPreEDRSSI <= 61) {
1353 } else if (priv->byBBPreEDRSSI <= 62) {
1356 } else if (priv->byBBPreEDRSSI <= 63) {
1359 } else if (priv->byBBPreEDRSSI <= 64) {
1362 } else if (priv->byBBPreEDRSSI <= 65) {
1365 } else if (priv->byBBPreEDRSSI <= 66) {
1376 if (ed_inx == priv->byBBPreEDIndex && !scanning)
1379 priv->byBBPreEDIndex = ed_inx;
1381 dev_dbg(&priv->usb->dev, "%s byBBPreEDRSSI %d\n",
1382 __func__, priv->byBBPreEDRSSI);
1384 if (!cr_201 && !cr_206)
1387 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201);
1388 ControlvWriteByte(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206);