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: Implement functions to access baseband
25 * vnt_get_frame_time - Calculate data frame transmitting time
26 * vnt_get_phy_field - Calculate PhyLength, PhyService and Phy
27 * Signal parameter for baseband Tx
28 * vnt_vt3184_init - VIA VT3184 baseband chip init code
40 static u8 vnt_vt3184_agc[] = {
41 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06,
42 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */
43 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16,
44 0x18, 0x18, 0x1a, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e, /* 0x1f */
45 0x20, 0x20, 0x22, 0x22, 0x24, 0x24, 0x26, 0x26,
46 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c, 0x2e, 0x2e, /* 0x2f */
47 0x30, 0x30, 0x32, 0x32, 0x34, 0x34, 0x36, 0x36,
48 0x38, 0x38, 0x3a, 0x3a, 0x3c, 0x3c, 0x3e, 0x3e /* 0x3f */
51 static u8 vnt_vt3184_al2230[] = {
52 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
53 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
58 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
59 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
60 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
61 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
62 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
64 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
68 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
70 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
73 0x18, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x18, /* 0xaf */
74 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
75 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
76 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x0e, 0x0a,
77 0x0e, 0x00, 0x82, 0xa7, 0x3c, 0x10, 0x30, 0x05, /* 0xcf */
78 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
80 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12,
81 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x05, /* 0xef */
82 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
86 /* {{RobertYu:20060515, new BB setting for VT3226D0 */
87 static u8 vnt_vt3184_vt3226d0[] = {
88 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
89 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
94 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
95 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
96 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
97 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
98 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
100 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
104 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
105 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
106 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
109 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0xaf */
110 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
111 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
112 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x10, 0x0a,
113 0x0e, 0x00, 0x84, 0xa7, 0x3c, 0x10, 0x24, 0x05, /* 0xcf */
114 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
115 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
116 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10,
117 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x08, /* 0xef */
118 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
122 static const u16 vnt_frame_time[MAX_RATE] = {
123 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216
127 * Description: Calculate data frame transmitting time
131 * preamble_type - Preamble Type
132 * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
133 * frame_length - Baseband Type
137 * Return Value: FrameTime
140 unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type,
141 unsigned int frame_length, u16 tx_rate)
143 unsigned int frame_time;
144 unsigned int preamble;
146 unsigned int rate = 0;
148 if (tx_rate > RATE_54M)
151 rate = (unsigned int)vnt_frame_time[tx_rate];
154 if (preamble_type == 1)
159 frame_time = (frame_length * 80) / rate;
160 tmp = (frame_time * rate) / 80;
162 if (frame_length != tmp)
165 return preamble + frame_time;
167 frame_time = (frame_length * 8 + 22) / rate;
168 tmp = ((frame_time * rate) - 22) / 8;
170 if (frame_length != tmp)
173 frame_time = frame_time * 4;
175 if (pkt_type != PK_TYPE_11A)
177 return 20 + frame_time;
181 * Description: Calculate Length, Service, and Signal fields of Phy for Tx
185 * priv - Device Structure
186 * frame_length - Tx Frame Length
189 * struct vnt_phy_field *phy
190 * - pointer to Phy Length field
191 * - pointer to Phy Service field
192 * - pointer to Phy Signal field
197 void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
198 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy)
204 u8 preamble_type = priv->preamble_type;
206 bit_count = frame_length * 8;
217 count = bit_count / 2;
219 if (preamble_type == 1)
226 count = (bit_count * 10) / 55;
227 tmp = (count * 55) / 10;
229 if (tmp != bit_count)
232 if (preamble_type == 1)
239 count = bit_count / 11;
242 if (tmp != bit_count) {
245 if ((bit_count - tmp) <= 3)
249 if (preamble_type == 1)
256 if (pkt_type == PK_TYPE_11A)
263 if (pkt_type == PK_TYPE_11A)
270 if (pkt_type == PK_TYPE_11A)
277 if (pkt_type == PK_TYPE_11A)
284 if (pkt_type == PK_TYPE_11A)
291 if (pkt_type == PK_TYPE_11A)
298 if (pkt_type == PK_TYPE_11A)
305 if (pkt_type == PK_TYPE_11A)
311 if (pkt_type == PK_TYPE_11A)
318 if (pkt_type == PK_TYPE_11B) {
321 phy->service |= 0x80;
322 phy->len = cpu_to_le16((u16)count);
325 phy->len = cpu_to_le16((u16)frame_length);
330 * Description: Set Antenna mode
334 * priv - Device Structure
335 * antenna_mode - Antenna Mode
342 void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
344 switch (antenna_mode) {
349 priv->bb_rx_conf &= 0xFC;
352 priv->bb_rx_conf &= 0xFE;
353 priv->bb_rx_conf |= 0x02;
357 vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
358 (u16)antenna_mode, 0, 0, NULL);
362 * Description: Set Antenna mode
366 * pDevice - Device Structure
367 * byAntennaMode - Antenna Mode
375 int vnt_vt3184_init(struct vnt_private *priv)
385 status = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
386 MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE,
388 if (status != STATUS_SUCCESS)
391 priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE];
393 dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type);
395 if ((priv->rf_type == RF_AL2230) ||
396 (priv->rf_type == RF_AL2230S)) {
397 priv->bb_rx_conf = vnt_vt3184_al2230[10];
398 length = sizeof(vnt_vt3184_al2230);
399 addr = vnt_vt3184_al2230;
400 agc = vnt_vt3184_agc;
401 length_agc = sizeof(vnt_vt3184_agc);
403 priv->bb_vga[0] = 0x1C;
404 priv->bb_vga[1] = 0x10;
405 priv->bb_vga[2] = 0x0;
406 priv->bb_vga[3] = 0x0;
408 } else if (priv->rf_type == RF_AIROHA7230) {
409 priv->bb_rx_conf = vnt_vt3184_al2230[10];
410 length = sizeof(vnt_vt3184_al2230);
411 addr = vnt_vt3184_al2230;
412 agc = vnt_vt3184_agc;
413 length_agc = sizeof(vnt_vt3184_agc);
417 priv->bb_vga[0] = 0x1c;
418 priv->bb_vga[1] = 0x10;
419 priv->bb_vga[2] = 0x0;
420 priv->bb_vga[3] = 0x0;
422 } else if ((priv->rf_type == RF_VT3226) ||
423 (priv->rf_type == RF_VT3226D0)) {
424 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
425 length = sizeof(vnt_vt3184_vt3226d0);
426 addr = vnt_vt3184_vt3226d0;
427 agc = vnt_vt3184_agc;
428 length_agc = sizeof(vnt_vt3184_agc);
430 priv->bb_vga[0] = 0x20;
431 priv->bb_vga[1] = 0x10;
432 priv->bb_vga[2] = 0x0;
433 priv->bb_vga[3] = 0x0;
435 /* Fix VT3226 DFC system timing issue */
436 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
438 } else if (priv->rf_type == RF_VT3342A0) {
439 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
440 length = sizeof(vnt_vt3184_vt3226d0);
441 addr = vnt_vt3184_vt3226d0;
442 agc = vnt_vt3184_agc;
443 length_agc = sizeof(vnt_vt3184_agc);
445 priv->bb_vga[0] = 0x20;
446 priv->bb_vga[1] = 0x10;
447 priv->bb_vga[2] = 0x0;
448 priv->bb_vga[3] = 0x0;
450 /* Fix VT3226 DFC system timing issue */
451 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
457 memcpy(array, addr, length);
459 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
460 MESSAGE_REQUEST_BBREG, length, array);
462 memcpy(array, agc, length_agc);
464 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
465 MESSAGE_REQUEST_BBAGC, length_agc, array);
467 if ((priv->rf_type == RF_VT3226) ||
468 (priv->rf_type == RF_VT3342A0)) {
469 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
470 MAC_REG_ITRTMSET, 0x23);
471 vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
472 } else if (priv->rf_type == RF_VT3226D0) {
473 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
474 MAC_REG_ITRTMSET, 0x11);
475 vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
478 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
479 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
481 vnt_rf_table_download(priv);
483 /* Fix for TX USB resets from vendors driver */
484 vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
485 MESSAGE_REQUEST_MEM, sizeof(data), &data);
489 vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
490 MESSAGE_REQUEST_MEM, sizeof(data), &data);
496 * Description: Set ShortSlotTime mode
500 * priv - Device Structure
507 void vnt_set_short_slot_time(struct vnt_private *priv)
511 if (priv->short_slot_time)
512 priv->bb_rx_conf &= 0xdf;
514 priv->bb_rx_conf |= 0x20;
516 vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
518 if (bb_vga == priv->bb_vga[0])
519 priv->bb_rx_conf |= 0x20;
521 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
524 void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
526 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
528 /* patch for 3253B0 Baseband with Cardbus module */
529 if (priv->short_slot_time)
530 priv->bb_rx_conf &= 0xdf; /* 1101 1111 */
532 priv->bb_rx_conf |= 0x20; /* 0010 0000 */
534 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
538 * Description: vnt_set_deep_sleep
542 * priv - Device Structure
549 void vnt_set_deep_sleep(struct vnt_private *priv)
551 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */
552 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */
555 void vnt_exit_deep_sleep(struct vnt_private *priv)
557 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */
558 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */
561 void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
563 u8 cr_201 = 0x0, cr_206 = 0x0;
564 u8 ed_inx = priv->bb_pre_ed_index;
566 switch (priv->rf_type) {
570 if (scanning) { /* Max sensitivity */
576 if (priv->bb_pre_ed_rssi <= 45) {
579 } else if (priv->bb_pre_ed_rssi <= 46) {
582 } else if (priv->bb_pre_ed_rssi <= 47) {
585 } else if (priv->bb_pre_ed_rssi <= 49) {
588 } else if (priv->bb_pre_ed_rssi <= 51) {
591 } else if (priv->bb_pre_ed_rssi <= 53) {
594 } else if (priv->bb_pre_ed_rssi <= 55) {
597 } else if (priv->bb_pre_ed_rssi <= 56) {
601 } else if (priv->bb_pre_ed_rssi <= 57) {
605 } else if (priv->bb_pre_ed_rssi <= 58) {
609 } else if (priv->bb_pre_ed_rssi <= 59) {
613 } else if (priv->bb_pre_ed_rssi <= 60) {
617 } else if (priv->bb_pre_ed_rssi <= 61) {
620 } else if (priv->bb_pre_ed_rssi <= 62) {
623 } else if (priv->bb_pre_ed_rssi <= 63) {
626 } else if (priv->bb_pre_ed_rssi <= 64) {
629 } else if (priv->bb_pre_ed_rssi <= 65) {
632 } else if (priv->bb_pre_ed_rssi <= 66) {
635 } else if (priv->bb_pre_ed_rssi <= 67) {
638 } else if (priv->bb_pre_ed_rssi <= 68) {
649 if (scanning) { /* Max sensitivity */
655 if (priv->bb_pre_ed_rssi <= 41) {
658 } else if (priv->bb_pre_ed_rssi <= 42) {
661 } else if (priv->bb_pre_ed_rssi <= 43) {
664 } else if (priv->bb_pre_ed_rssi <= 45) {
667 } else if (priv->bb_pre_ed_rssi <= 47) {
670 } else if (priv->bb_pre_ed_rssi <= 49) {
673 } else if (priv->bb_pre_ed_rssi <= 51) {
676 } else if (priv->bb_pre_ed_rssi <= 53) {
679 } else if (priv->bb_pre_ed_rssi <= 55) {
683 } else if (priv->bb_pre_ed_rssi <= 56) {
687 } else if (priv->bb_pre_ed_rssi <= 57) {
691 } else if (priv->bb_pre_ed_rssi <= 58) {
695 } else if (priv->bb_pre_ed_rssi <= 59) {
699 } else if (priv->bb_pre_ed_rssi <= 60) {
702 } else if (priv->bb_pre_ed_rssi <= 61) {
705 } else if (priv->bb_pre_ed_rssi <= 62) {
708 } else if (priv->bb_pre_ed_rssi <= 63) {
711 } else if (priv->bb_pre_ed_rssi <= 64) {
714 } else if (priv->bb_pre_ed_rssi <= 65) {
717 } else if (priv->bb_pre_ed_rssi <= 66) {
720 } else if (priv->bb_pre_ed_rssi <= 67) {
723 } else if (priv->bb_pre_ed_rssi <= 68) {
733 if (scanning) { /* need Max sensitivity */
739 if (priv->bb_pre_ed_rssi <= 41) {
742 } else if (priv->bb_pre_ed_rssi <= 42) {
745 } else if (priv->bb_pre_ed_rssi <= 43) {
748 } else if (priv->bb_pre_ed_rssi <= 45) {
751 } else if (priv->bb_pre_ed_rssi <= 47) {
754 } else if (priv->bb_pre_ed_rssi <= 49) {
757 } else if (priv->bb_pre_ed_rssi <= 51) {
760 } else if (priv->bb_pre_ed_rssi <= 53) {
763 } else if (priv->bb_pre_ed_rssi <= 55) {
767 } else if (priv->bb_pre_ed_rssi <= 56) {
771 } else if (priv->bb_pre_ed_rssi <= 57) {
775 } else if (priv->bb_pre_ed_rssi <= 58) {
779 } else if (priv->bb_pre_ed_rssi <= 59) {
783 } else if (priv->bb_pre_ed_rssi <= 60) {
786 } else if (priv->bb_pre_ed_rssi <= 61) {
789 } else if (priv->bb_pre_ed_rssi <= 62) {
792 } else if (priv->bb_pre_ed_rssi <= 63) {
795 } else if (priv->bb_pre_ed_rssi <= 64) {
798 } else if (priv->bb_pre_ed_rssi <= 65) {
801 } else if (priv->bb_pre_ed_rssi <= 66) {
811 if (ed_inx == priv->bb_pre_ed_index && !scanning)
814 priv->bb_pre_ed_index = ed_inx;
816 dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n",
817 __func__, priv->bb_pre_ed_rssi);
819 if (!cr_201 && !cr_206)
822 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201);
823 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206);