1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: Implement functions to access baseband
15 * vnt_get_frame_time - Calculate data frame transmitting time
16 * vnt_get_phy_field - Calculate PhyLength, PhyService and Phy
17 * Signal parameter for baseband Tx
18 * vnt_vt3184_init - VIA VT3184 baseband chip init code
30 static u8 vnt_vt3184_agc[] = {
31 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06,
32 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */
33 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16,
34 0x18, 0x18, 0x1a, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e, /* 0x1f */
35 0x20, 0x20, 0x22, 0x22, 0x24, 0x24, 0x26, 0x26,
36 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c, 0x2e, 0x2e, /* 0x2f */
37 0x30, 0x30, 0x32, 0x32, 0x34, 0x34, 0x36, 0x36,
38 0x38, 0x38, 0x3a, 0x3a, 0x3c, 0x3c, 0x3e, 0x3e /* 0x3f */
41 static u8 vnt_vt3184_al2230[] = {
42 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
43 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
48 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
49 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
50 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
51 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
52 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
54 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
58 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
60 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
63 0x18, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x18, /* 0xaf */
64 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
65 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
66 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x0e, 0x0a,
67 0x0e, 0x00, 0x82, 0xa7, 0x3c, 0x10, 0x30, 0x05, /* 0xcf */
68 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
70 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12,
71 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x05, /* 0xef */
72 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
76 /* {{RobertYu:20060515, new BB setting for VT3226D0 */
77 static u8 vnt_vt3184_vt3226d0[] = {
78 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
79 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
84 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
85 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
86 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
87 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
88 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
90 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
94 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
96 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
99 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0xaf */
100 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
101 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
102 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x10, 0x0a,
103 0x0e, 0x00, 0x84, 0xa7, 0x3c, 0x10, 0x24, 0x05, /* 0xcf */
104 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
106 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10,
107 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x08, /* 0xef */
108 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
112 static const u16 vnt_frame_time[MAX_RATE] = {
113 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216
117 * Description: Calculate data frame transmitting time
121 * preamble_type - Preamble Type
122 * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
123 * frame_length - Baseband Type
127 * Return Value: FrameTime
130 unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type,
131 unsigned int frame_length, u16 tx_rate)
133 unsigned int frame_time;
134 unsigned int preamble;
136 unsigned int rate = 0;
138 if (tx_rate > RATE_54M)
141 rate = (unsigned int)vnt_frame_time[tx_rate];
144 if (preamble_type == 1)
149 frame_time = (frame_length * 80) / rate;
150 tmp = (frame_time * rate) / 80;
152 if (frame_length != tmp)
155 return preamble + frame_time;
157 frame_time = (frame_length * 8 + 22) / rate;
158 tmp = ((frame_time * rate) - 22) / 8;
160 if (frame_length != tmp)
163 frame_time = frame_time * 4;
165 if (pkt_type != PK_TYPE_11A)
167 return 20 + frame_time;
171 * Description: Calculate Length, Service, and Signal fields of Phy for Tx
175 * priv - Device Structure
176 * frame_length - Tx Frame Length
179 * struct vnt_phy_field *phy
180 * - pointer to Phy Length field
181 * - pointer to Phy Service field
182 * - pointer to Phy Signal field
187 void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
188 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy)
194 u8 preamble_type = priv->preamble_type;
196 bit_count = frame_length * 8;
207 count = bit_count / 2;
209 if (preamble_type == 1)
216 count = (bit_count * 10) / 55;
217 tmp = (count * 55) / 10;
219 if (tmp != bit_count)
222 if (preamble_type == 1)
229 count = bit_count / 11;
232 if (tmp != bit_count) {
235 if ((bit_count - tmp) <= 3)
239 if (preamble_type == 1)
246 if (pkt_type == PK_TYPE_11A)
253 if (pkt_type == PK_TYPE_11A)
260 if (pkt_type == PK_TYPE_11A)
267 if (pkt_type == PK_TYPE_11A)
274 if (pkt_type == PK_TYPE_11A)
281 if (pkt_type == PK_TYPE_11A)
288 if (pkt_type == PK_TYPE_11A)
295 if (pkt_type == PK_TYPE_11A)
301 if (pkt_type == PK_TYPE_11A)
308 if (pkt_type == PK_TYPE_11B) {
311 phy->service |= 0x80;
312 phy->len = cpu_to_le16((u16)count);
315 phy->len = cpu_to_le16((u16)frame_length);
320 * Description: Set Antenna mode
324 * priv - Device Structure
325 * antenna_mode - Antenna Mode
332 int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
334 switch (antenna_mode) {
339 priv->bb_rx_conf &= 0xFC;
342 priv->bb_rx_conf &= 0xFE;
343 priv->bb_rx_conf |= 0x02;
347 return vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
348 (u16)antenna_mode, 0, 0, NULL);
352 * Description: Set Antenna mode
356 * pDevice - Device Structure
357 * byAntennaMode - Antenna Mode
365 int vnt_vt3184_init(struct vnt_private *priv)
375 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, MESSAGE_REQUEST_EEPROM,
376 EEP_MAX_CONTEXT_SIZE, priv->eeprom);
380 priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE];
382 dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type);
384 if ((priv->rf_type == RF_AL2230) ||
385 (priv->rf_type == RF_AL2230S)) {
386 priv->bb_rx_conf = vnt_vt3184_al2230[10];
387 length = sizeof(vnt_vt3184_al2230);
388 addr = vnt_vt3184_al2230;
389 agc = vnt_vt3184_agc;
390 length_agc = sizeof(vnt_vt3184_agc);
392 priv->bb_vga[0] = 0x1C;
393 priv->bb_vga[1] = 0x10;
394 priv->bb_vga[2] = 0x0;
395 priv->bb_vga[3] = 0x0;
397 } else if (priv->rf_type == RF_AIROHA7230) {
398 priv->bb_rx_conf = vnt_vt3184_al2230[10];
399 length = sizeof(vnt_vt3184_al2230);
400 addr = vnt_vt3184_al2230;
401 agc = vnt_vt3184_agc;
402 length_agc = sizeof(vnt_vt3184_agc);
406 priv->bb_vga[0] = 0x1c;
407 priv->bb_vga[1] = 0x10;
408 priv->bb_vga[2] = 0x0;
409 priv->bb_vga[3] = 0x0;
411 } else if ((priv->rf_type == RF_VT3226) ||
412 (priv->rf_type == RF_VT3226D0)) {
413 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
414 length = sizeof(vnt_vt3184_vt3226d0);
415 addr = vnt_vt3184_vt3226d0;
416 agc = vnt_vt3184_agc;
417 length_agc = sizeof(vnt_vt3184_agc);
419 priv->bb_vga[0] = 0x20;
420 priv->bb_vga[1] = 0x10;
421 priv->bb_vga[2] = 0x0;
422 priv->bb_vga[3] = 0x0;
424 /* Fix VT3226 DFC system timing issue */
425 ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
429 } else if (priv->rf_type == RF_VT3342A0) {
430 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
431 length = sizeof(vnt_vt3184_vt3226d0);
432 addr = vnt_vt3184_vt3226d0;
433 agc = vnt_vt3184_agc;
434 length_agc = sizeof(vnt_vt3184_agc);
436 priv->bb_vga[0] = 0x20;
437 priv->bb_vga[1] = 0x10;
438 priv->bb_vga[2] = 0x0;
439 priv->bb_vga[3] = 0x0;
441 /* Fix VT3226 DFC system timing issue */
442 ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
450 memcpy(array, addr, length);
452 ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
453 MESSAGE_REQUEST_BBREG, length, array);
457 memcpy(array, agc, length_agc);
459 ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
460 MESSAGE_REQUEST_BBAGC, length_agc, array);
464 if ((priv->rf_type == RF_VT3226) ||
465 (priv->rf_type == RF_VT3342A0)) {
466 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
467 MAC_REG_ITRTMSET, 0x23);
471 ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
474 } else if (priv->rf_type == RF_VT3226D0) {
475 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
476 MAC_REG_ITRTMSET, 0x11);
480 ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
485 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
489 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
493 ret = vnt_rf_table_download(priv);
497 /* Fix for TX USB resets from vendors driver */
498 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
499 MESSAGE_REQUEST_MEM, sizeof(data), &data);
505 ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
506 MESSAGE_REQUEST_MEM, sizeof(data), &data);
513 * Description: Set ShortSlotTime mode
517 * priv - Device Structure
524 int vnt_set_short_slot_time(struct vnt_private *priv)
529 if (priv->short_slot_time)
530 priv->bb_rx_conf &= 0xdf;
532 priv->bb_rx_conf |= 0x20;
534 ret = vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
538 if (bb_vga == priv->bb_vga[0])
539 priv->bb_rx_conf |= 0x20;
541 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a,
548 void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
550 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
552 /* patch for 3253B0 Baseband with Cardbus module */
553 if (priv->short_slot_time)
554 priv->bb_rx_conf &= 0xdf; /* 1101 1111 */
556 priv->bb_rx_conf |= 0x20; /* 0010 0000 */
558 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
562 * Description: vnt_set_deep_sleep
566 * priv - Device Structure
573 int vnt_set_deep_sleep(struct vnt_private *priv)
578 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);
583 return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);
586 int vnt_exit_deep_sleep(struct vnt_private *priv)
591 ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);
596 return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
599 void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
601 u8 cr_201 = 0x0, cr_206 = 0x0;
602 u8 ed_inx = priv->bb_pre_ed_index;
604 switch (priv->rf_type) {
608 if (scanning) { /* Max sensitivity */
614 if (priv->bb_pre_ed_rssi <= 45) {
617 } else if (priv->bb_pre_ed_rssi <= 46) {
620 } else if (priv->bb_pre_ed_rssi <= 47) {
623 } else if (priv->bb_pre_ed_rssi <= 49) {
626 } else if (priv->bb_pre_ed_rssi <= 51) {
629 } else if (priv->bb_pre_ed_rssi <= 53) {
632 } else if (priv->bb_pre_ed_rssi <= 55) {
635 } else if (priv->bb_pre_ed_rssi <= 56) {
639 } else if (priv->bb_pre_ed_rssi <= 57) {
643 } else if (priv->bb_pre_ed_rssi <= 58) {
647 } else if (priv->bb_pre_ed_rssi <= 59) {
651 } else if (priv->bb_pre_ed_rssi <= 60) {
655 } else if (priv->bb_pre_ed_rssi <= 61) {
658 } else if (priv->bb_pre_ed_rssi <= 62) {
661 } else if (priv->bb_pre_ed_rssi <= 63) {
664 } else if (priv->bb_pre_ed_rssi <= 64) {
667 } else if (priv->bb_pre_ed_rssi <= 65) {
670 } else if (priv->bb_pre_ed_rssi <= 66) {
673 } else if (priv->bb_pre_ed_rssi <= 67) {
676 } else if (priv->bb_pre_ed_rssi <= 68) {
687 if (scanning) { /* Max sensitivity */
693 if (priv->bb_pre_ed_rssi <= 41) {
696 } else if (priv->bb_pre_ed_rssi <= 42) {
699 } else if (priv->bb_pre_ed_rssi <= 43) {
702 } else if (priv->bb_pre_ed_rssi <= 45) {
705 } else if (priv->bb_pre_ed_rssi <= 47) {
708 } else if (priv->bb_pre_ed_rssi <= 49) {
711 } else if (priv->bb_pre_ed_rssi <= 51) {
714 } else if (priv->bb_pre_ed_rssi <= 53) {
717 } else if (priv->bb_pre_ed_rssi <= 55) {
721 } else if (priv->bb_pre_ed_rssi <= 56) {
725 } else if (priv->bb_pre_ed_rssi <= 57) {
729 } else if (priv->bb_pre_ed_rssi <= 58) {
733 } else if (priv->bb_pre_ed_rssi <= 59) {
737 } else if (priv->bb_pre_ed_rssi <= 60) {
740 } else if (priv->bb_pre_ed_rssi <= 61) {
743 } else if (priv->bb_pre_ed_rssi <= 62) {
746 } else if (priv->bb_pre_ed_rssi <= 63) {
749 } else if (priv->bb_pre_ed_rssi <= 64) {
752 } else if (priv->bb_pre_ed_rssi <= 65) {
755 } else if (priv->bb_pre_ed_rssi <= 66) {
758 } else if (priv->bb_pre_ed_rssi <= 67) {
761 } else if (priv->bb_pre_ed_rssi <= 68) {
771 if (scanning) { /* need Max sensitivity */
777 if (priv->bb_pre_ed_rssi <= 41) {
780 } else if (priv->bb_pre_ed_rssi <= 42) {
783 } else if (priv->bb_pre_ed_rssi <= 43) {
786 } else if (priv->bb_pre_ed_rssi <= 45) {
789 } else if (priv->bb_pre_ed_rssi <= 47) {
792 } else if (priv->bb_pre_ed_rssi <= 49) {
795 } else if (priv->bb_pre_ed_rssi <= 51) {
798 } else if (priv->bb_pre_ed_rssi <= 53) {
801 } else if (priv->bb_pre_ed_rssi <= 55) {
805 } else if (priv->bb_pre_ed_rssi <= 56) {
809 } else if (priv->bb_pre_ed_rssi <= 57) {
813 } else if (priv->bb_pre_ed_rssi <= 58) {
817 } else if (priv->bb_pre_ed_rssi <= 59) {
821 } else if (priv->bb_pre_ed_rssi <= 60) {
824 } else if (priv->bb_pre_ed_rssi <= 61) {
827 } else if (priv->bb_pre_ed_rssi <= 62) {
830 } else if (priv->bb_pre_ed_rssi <= 63) {
833 } else if (priv->bb_pre_ed_rssi <= 64) {
836 } else if (priv->bb_pre_ed_rssi <= 65) {
839 } else if (priv->bb_pre_ed_rssi <= 66) {
849 if (ed_inx == priv->bb_pre_ed_index && !scanning)
852 priv->bb_pre_ed_index = ed_inx;
854 dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n",
855 __func__, priv->bb_pre_ed_rssi);
857 if (!cr_201 && !cr_206)
860 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201);
861 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206);