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
25 #include <linux/bits.h>
26 #include <linux/errno.h>
27 #include <linux/kernel.h>
34 static const u8 vnt_vt3184_agc
[] = {
35 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06,
36 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */
37 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16,
38 0x18, 0x18, 0x1a, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e, /* 0x1f */
39 0x20, 0x20, 0x22, 0x22, 0x24, 0x24, 0x26, 0x26,
40 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c, 0x2e, 0x2e, /* 0x2f */
41 0x30, 0x30, 0x32, 0x32, 0x34, 0x34, 0x36, 0x36,
42 0x38, 0x38, 0x3a, 0x3a, 0x3c, 0x3c, 0x3e, 0x3e /* 0x3f */
45 static u8 vnt_vt3184_al2230
[] = {
46 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
47 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
52 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
53 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
54 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
55 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
56 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
58 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
62 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
64 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
67 0x18, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x18, /* 0xaf */
68 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
69 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
70 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x0e, 0x0a,
71 0x0e, 0x00, 0x82, 0xa7, 0x3c, 0x10, 0x30, 0x05, /* 0xcf */
72 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
74 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12,
75 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x05, /* 0xef */
76 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
80 /* {{RobertYu:20060515, new BB setting for VT3226D0 */
81 static const u8 vnt_vt3184_vt3226d0
[] = {
82 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
83 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
88 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
89 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
90 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
91 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
92 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
94 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
98 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
100 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
103 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0xaf */
104 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
105 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
106 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x10, 0x0a,
107 0x0e, 0x00, 0x84, 0xa7, 0x3c, 0x10, 0x24, 0x05, /* 0xcf */
108 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
110 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10,
111 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x08, /* 0xef */
112 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
116 struct vnt_threshold
{
122 static const struct vnt_threshold al2230_vnt_threshold
[] = {
123 {0, 0x00, 0x30}, /* Max sensitivity */
146 static const struct vnt_threshold vt3226_vnt_threshold
[] = {
147 {0, 0x00, 0x24}, /* Max sensitivity */
172 static const struct vnt_threshold vt3342_vnt_threshold
[] = {
173 {0, 0x00, 0x38}, /* Max sensitivity */
197 * Description: Set Antenna mode
201 * priv - Device Structure
202 * antenna_mode - Antenna Mode
209 int vnt_set_antenna_mode(struct vnt_private
*priv
, u8 antenna_mode
)
211 switch (antenna_mode
) {
216 priv
->bb_rx_conf
&= 0xFC;
219 priv
->bb_rx_conf
&= 0xFE;
220 priv
->bb_rx_conf
|= 0x02;
224 return vnt_control_out(priv
, MESSAGE_TYPE_SET_ANTMD
,
225 (u16
)antenna_mode
, 0, 0, NULL
);
229 * Description: Set Antenna mode
233 * pDevice - Device Structure
234 * byAntennaMode - Antenna Mode
242 int vnt_vt3184_init(struct vnt_private
*priv
)
250 ret
= vnt_control_in(priv
, MESSAGE_TYPE_READ
, 0, MESSAGE_REQUEST_EEPROM
,
251 EEP_MAX_CONTEXT_SIZE
, priv
->eeprom
);
255 priv
->rf_type
= priv
->eeprom
[EEP_OFS_RFTYPE
];
257 dev_dbg(&priv
->usb
->dev
, "RF Type %d\n", priv
->rf_type
);
259 if ((priv
->rf_type
== RF_AL2230
) ||
260 (priv
->rf_type
== RF_AL2230S
) ||
261 (priv
->rf_type
== RF_AIROHA7230
)) {
262 priv
->bb_rx_conf
= vnt_vt3184_al2230
[10];
263 length
= sizeof(vnt_vt3184_al2230
);
264 addr
= vnt_vt3184_al2230
;
266 if (priv
->rf_type
== RF_AIROHA7230
)
269 priv
->bb_vga
[0] = 0x1c;
270 priv
->bb_vga
[1] = 0x10;
271 priv
->bb_vga
[2] = 0x0;
272 priv
->bb_vga
[3] = 0x0;
274 } else if ((priv
->rf_type
== RF_VT3226
) ||
275 (priv
->rf_type
== RF_VT3226D0
) ||
276 (priv
->rf_type
== RF_VT3342A0
)) {
277 priv
->bb_rx_conf
= vnt_vt3184_vt3226d0
[10];
278 length
= sizeof(vnt_vt3184_vt3226d0
);
279 c_addr
= vnt_vt3184_vt3226d0
;
281 priv
->bb_vga
[0] = 0x20;
282 priv
->bb_vga
[1] = 0x10;
283 priv
->bb_vga
[2] = 0x0;
284 priv
->bb_vga
[3] = 0x0;
286 /* Fix VT3226 DFC system timing issue */
287 ret
= vnt_mac_reg_bits_on(priv
, MAC_REG_SOFTPWRCTL2
,
298 ret
= vnt_control_out_blocks(priv
, VNT_REG_BLOCK_SIZE
,
299 MESSAGE_REQUEST_BBREG
, length
, c_addr
);
303 ret
= vnt_control_out(priv
, MESSAGE_TYPE_WRITE
, 0,
304 MESSAGE_REQUEST_BBAGC
,
305 sizeof(vnt_vt3184_agc
), vnt_vt3184_agc
);
309 if ((priv
->rf_type
== RF_VT3226
) ||
310 (priv
->rf_type
== RF_VT3342A0
) ||
311 (priv
->rf_type
== RF_VT3226D0
)) {
312 data
= (priv
->rf_type
== RF_VT3226D0
) ? 0x11 : 0x23;
314 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_MACREG
,
315 MAC_REG_ITRTMSET
, data
);
319 ret
= vnt_mac_reg_bits_on(priv
, MAC_REG_PAPEDELAY
, BIT(0));
324 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x04, 0x7f);
328 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0d, 0x01);
332 ret
= vnt_rf_table_download(priv
);
336 /* Fix for TX USB resets from vendors driver */
337 ret
= vnt_control_in(priv
, MESSAGE_TYPE_READ
, USB_REG4
,
338 MESSAGE_REQUEST_MEM
, sizeof(data
), &data
);
344 ret
= vnt_control_out(priv
, MESSAGE_TYPE_WRITE
, USB_REG4
,
345 MESSAGE_REQUEST_MEM
, sizeof(data
), &data
);
352 * Description: Set ShortSlotTime mode
356 * priv - Device Structure
363 int vnt_set_short_slot_time(struct vnt_private
*priv
)
368 if (priv
->short_slot_time
)
369 priv
->bb_rx_conf
&= 0xdf;
371 priv
->bb_rx_conf
|= 0x20;
373 ret
= vnt_control_in_u8(priv
, MESSAGE_REQUEST_BBREG
, 0xe7, &bb_vga
);
377 if (bb_vga
== priv
->bb_vga
[0])
378 priv
->bb_rx_conf
|= 0x20;
380 return vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0a,
384 int vnt_set_vga_gain_offset(struct vnt_private
*priv
, u8 data
)
388 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0xE7, data
);
392 /* patch for 3253B0 Baseband with Cardbus module */
393 if (priv
->short_slot_time
)
394 priv
->bb_rx_conf
&= 0xdf; /* 1101 1111 */
396 priv
->bb_rx_conf
|= 0x20; /* 0010 0000 */
398 return vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0a,
403 * Description: vnt_set_deep_sleep
407 * priv - Device Structure
414 int vnt_set_deep_sleep(struct vnt_private
*priv
)
419 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0c, 0x17);
424 return vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0d, 0xB9);
427 int vnt_exit_deep_sleep(struct vnt_private
*priv
)
432 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0c, 0x00);
437 return vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0x0d, 0x01);
440 int vnt_update_pre_ed_threshold(struct vnt_private
*priv
, int scanning
)
442 const struct vnt_threshold
*threshold
= NULL
;
448 switch (priv
->rf_type
) {
452 threshold
= al2230_vnt_threshold
;
453 length
= ARRAY_SIZE(al2230_vnt_threshold
);
458 threshold
= vt3226_vnt_threshold
;
459 length
= ARRAY_SIZE(vt3226_vnt_threshold
);
463 threshold
= vt3342_vnt_threshold
;
464 length
= ARRAY_SIZE(vt3342_vnt_threshold
);
471 for (ed_inx
= scanning
? 0 : length
- 1; ed_inx
> 0; ed_inx
--) {
472 if (priv
->bb_pre_ed_rssi
<= threshold
[ed_inx
].bb_pre_ed_rssi
)
476 cr_201
= threshold
[ed_inx
].cr_201
;
477 cr_206
= threshold
[ed_inx
].cr_206
;
479 if (ed_inx
== priv
->bb_pre_ed_index
&& !scanning
)
482 priv
->bb_pre_ed_index
= ed_inx
;
484 dev_dbg(&priv
->usb
->dev
, "%s bb_pre_ed_rssi %d\n",
485 __func__
, priv
->bb_pre_ed_rssi
);
487 ret
= vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0xc9, cr_201
);
491 return vnt_control_out_u8(priv
, MESSAGE_REQUEST_BBREG
, 0xce, cr_206
);