irqchip/s3c24xx: Mark init_eint as __maybe_unused
[linux/fpc-iii.git] / drivers / staging / vt6656 / baseband.c
blobe5be261f2e69cb11319282d46e4f567257ab6102
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
20 * File: baseband.c
22 * Purpose: Implement functions to access baseband
24 * Author: Jerry Chen
26 * Date: Jun. 5, 2002
28 * Functions:
29 * vnt_get_frame_time - Calculate data frame transmitting time
30 * vnt_get_phy_field - Calculate PhyLength, PhyService and Phy
31 * Signal parameter for baseband Tx
32 * vnt_vt3184_init - VIA VT3184 baseband chip init code
34 * Revision History:
39 #include "mac.h"
40 #include "baseband.h"
41 #include "rf.h"
42 #include "usbpipe.h"
44 static u8 vnt_vt3184_agc[] = {
45 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06,
46 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */
47 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16,
48 0x18, 0x18, 0x1a, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e, /* 0x1f */
49 0x20, 0x20, 0x22, 0x22, 0x24, 0x24, 0x26, 0x26,
50 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c, 0x2e, 0x2e, /* 0x2f */
51 0x30, 0x30, 0x32, 0x32, 0x34, 0x34, 0x36, 0x36,
52 0x38, 0x38, 0x3a, 0x3a, 0x3c, 0x3c, 0x3e, 0x3e /* 0x3f */
55 static u8 vnt_vt3184_al2230[] = {
56 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
57 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
62 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
63 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
64 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
65 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
66 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
68 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
72 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
74 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
77 0x18, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x18, /* 0xaf */
78 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
79 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
80 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x0e, 0x0a,
81 0x0e, 0x00, 0x82, 0xa7, 0x3c, 0x10, 0x30, 0x05, /* 0xcf */
82 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
84 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12,
85 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x05, /* 0xef */
86 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
90 /* {{RobertYu:20060515, new BB setting for VT3226D0 */
91 static u8 vnt_vt3184_vt3226d0[] = {
92 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
93 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
98 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
99 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
100 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
101 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
102 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
104 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
108 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
109 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
110 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
113 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0xaf */
114 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
115 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
116 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x10, 0x0a,
117 0x0e, 0x00, 0x84, 0xa7, 0x3c, 0x10, 0x24, 0x05, /* 0xcf */
118 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
120 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10,
121 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x08, /* 0xef */
122 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
126 static const u16 vnt_frame_time[MAX_RATE] = {
127 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216
131 * Description: Calculate data frame transmitting time
133 * Parameters:
134 * In:
135 * preamble_type - Preamble Type
136 * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
137 * frame_length - Baseband Type
138 * tx_rate - Tx Rate
139 * Out:
141 * Return Value: FrameTime
144 unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type,
145 unsigned int frame_length, u16 tx_rate)
147 unsigned int frame_time;
148 unsigned int preamble;
149 unsigned int tmp;
150 unsigned int rate = 0;
152 if (tx_rate > RATE_54M)
153 return 0;
155 rate = (unsigned int)vnt_frame_time[tx_rate];
157 if (tx_rate <= 3) {
158 if (preamble_type == 1)
159 preamble = 96;
160 else
161 preamble = 192;
163 frame_time = (frame_length * 80) / rate;
164 tmp = (frame_time * rate) / 80;
166 if (frame_length != tmp)
167 frame_time++;
169 return preamble + frame_time;
171 frame_time = (frame_length * 8 + 22) / rate;
172 tmp = ((frame_time * rate) - 22) / 8;
174 if (frame_length != tmp)
175 frame_time++;
177 frame_time = frame_time * 4;
179 if (pkt_type != PK_TYPE_11A)
180 frame_time += 6;
181 return 20 + frame_time;
185 * Description: Calculate Length, Service, and Signal fields of Phy for Tx
187 * Parameters:
188 * In:
189 * priv - Device Structure
190 * frame_length - Tx Frame Length
191 * tx_rate - Tx Rate
192 * Out:
193 * struct vnt_phy_field *phy
194 * - pointer to Phy Length field
195 * - pointer to Phy Service field
196 * - pointer to Phy Signal field
198 * Return Value: none
201 void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
202 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy)
204 u32 bit_count;
205 u32 count = 0;
206 u32 tmp;
207 int ext_bit;
208 u8 preamble_type = priv->preamble_type;
210 bit_count = frame_length * 8;
211 ext_bit = false;
213 switch (tx_rate) {
214 case RATE_1M:
215 count = bit_count;
217 phy->signal = 0x00;
219 break;
220 case RATE_2M:
221 count = bit_count / 2;
223 if (preamble_type == 1)
224 phy->signal = 0x09;
225 else
226 phy->signal = 0x01;
228 break;
229 case RATE_5M:
230 count = (bit_count * 10) / 55;
231 tmp = (count * 55) / 10;
233 if (tmp != bit_count)
234 count++;
236 if (preamble_type == 1)
237 phy->signal = 0x0a;
238 else
239 phy->signal = 0x02;
241 break;
242 case RATE_11M:
243 count = bit_count / 11;
244 tmp = count * 11;
246 if (tmp != bit_count) {
247 count++;
249 if ((bit_count - tmp) <= 3)
250 ext_bit = true;
253 if (preamble_type == 1)
254 phy->signal = 0x0b;
255 else
256 phy->signal = 0x03;
258 break;
259 case RATE_6M:
260 if (pkt_type == PK_TYPE_11A)
261 phy->signal = 0x9b;
262 else
263 phy->signal = 0x8b;
265 break;
266 case RATE_9M:
267 if (pkt_type == PK_TYPE_11A)
268 phy->signal = 0x9f;
269 else
270 phy->signal = 0x8f;
272 break;
273 case RATE_12M:
274 if (pkt_type == PK_TYPE_11A)
275 phy->signal = 0x9a;
276 else
277 phy->signal = 0x8a;
279 break;
280 case RATE_18M:
281 if (pkt_type == PK_TYPE_11A)
282 phy->signal = 0x9e;
283 else
284 phy->signal = 0x8e;
286 break;
287 case RATE_24M:
288 if (pkt_type == PK_TYPE_11A)
289 phy->signal = 0x99;
290 else
291 phy->signal = 0x89;
293 break;
294 case RATE_36M:
295 if (pkt_type == PK_TYPE_11A)
296 phy->signal = 0x9d;
297 else
298 phy->signal = 0x8d;
300 break;
301 case RATE_48M:
302 if (pkt_type == PK_TYPE_11A)
303 phy->signal = 0x98;
304 else
305 phy->signal = 0x88;
307 break;
308 case RATE_54M:
309 if (pkt_type == PK_TYPE_11A)
310 phy->signal = 0x9c;
311 else
312 phy->signal = 0x8c;
313 break;
314 default:
315 if (pkt_type == PK_TYPE_11A)
316 phy->signal = 0x9c;
317 else
318 phy->signal = 0x8c;
319 break;
322 if (pkt_type == PK_TYPE_11B) {
323 phy->service = 0x00;
324 if (ext_bit)
325 phy->service |= 0x80;
326 phy->len = cpu_to_le16((u16)count);
327 } else {
328 phy->service = 0x00;
329 phy->len = cpu_to_le16((u16)frame_length);
334 * Description: Set Antenna mode
336 * Parameters:
337 * In:
338 * priv - Device Structure
339 * antenna_mode - Antenna Mode
340 * Out:
341 * none
343 * Return Value: none
346 void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
348 switch (antenna_mode) {
349 case ANT_TXA:
350 case ANT_TXB:
351 break;
352 case ANT_RXA:
353 priv->bb_rx_conf &= 0xFC;
354 break;
355 case ANT_RXB:
356 priv->bb_rx_conf &= 0xFE;
357 priv->bb_rx_conf |= 0x02;
358 break;
361 vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
362 (u16)antenna_mode, 0, 0, NULL);
366 * Description: Set Antenna mode
368 * Parameters:
369 * In:
370 * pDevice - Device Structure
371 * byAntennaMode - Antenna Mode
372 * Out:
373 * none
375 * Return Value: none
379 int vnt_vt3184_init(struct vnt_private *priv)
381 int status;
382 u16 length;
383 u8 *addr;
384 u8 *agc;
385 u16 length_agc;
386 u8 array[256];
387 u8 data;
389 status = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
390 MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE,
391 priv->eeprom);
392 if (status != STATUS_SUCCESS)
393 return false;
395 priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE];
397 dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type);
399 if ((priv->rf_type == RF_AL2230) ||
400 (priv->rf_type == RF_AL2230S)) {
401 priv->bb_rx_conf = vnt_vt3184_al2230[10];
402 length = sizeof(vnt_vt3184_al2230);
403 addr = vnt_vt3184_al2230;
404 agc = vnt_vt3184_agc;
405 length_agc = sizeof(vnt_vt3184_agc);
407 priv->bb_vga[0] = 0x1C;
408 priv->bb_vga[1] = 0x10;
409 priv->bb_vga[2] = 0x0;
410 priv->bb_vga[3] = 0x0;
412 } else if (priv->rf_type == RF_AIROHA7230) {
413 priv->bb_rx_conf = vnt_vt3184_al2230[10];
414 length = sizeof(vnt_vt3184_al2230);
415 addr = vnt_vt3184_al2230;
416 agc = vnt_vt3184_agc;
417 length_agc = sizeof(vnt_vt3184_agc);
419 addr[0xd7] = 0x06;
421 priv->bb_vga[0] = 0x1c;
422 priv->bb_vga[1] = 0x10;
423 priv->bb_vga[2] = 0x0;
424 priv->bb_vga[3] = 0x0;
426 } else if ((priv->rf_type == RF_VT3226) ||
427 (priv->rf_type == RF_VT3226D0)) {
428 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
429 length = sizeof(vnt_vt3184_vt3226d0);
430 addr = vnt_vt3184_vt3226d0;
431 agc = vnt_vt3184_agc;
432 length_agc = sizeof(vnt_vt3184_agc);
434 priv->bb_vga[0] = 0x20;
435 priv->bb_vga[1] = 0x10;
436 priv->bb_vga[2] = 0x0;
437 priv->bb_vga[3] = 0x0;
439 /* Fix VT3226 DFC system timing issue */
440 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
441 SOFTPWRCTL_RFLEOPT);
442 } else if (priv->rf_type == RF_VT3342A0) {
443 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
444 length = sizeof(vnt_vt3184_vt3226d0);
445 addr = vnt_vt3184_vt3226d0;
446 agc = vnt_vt3184_agc;
447 length_agc = sizeof(vnt_vt3184_agc);
449 priv->bb_vga[0] = 0x20;
450 priv->bb_vga[1] = 0x10;
451 priv->bb_vga[2] = 0x0;
452 priv->bb_vga[3] = 0x0;
454 /* Fix VT3226 DFC system timing issue */
455 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
456 SOFTPWRCTL_RFLEOPT);
457 } else {
458 return true;
461 memcpy(array, addr, length);
463 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
464 MESSAGE_REQUEST_BBREG, length, array);
466 memcpy(array, agc, length_agc);
468 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
469 MESSAGE_REQUEST_BBAGC, length_agc, array);
471 if ((priv->rf_type == RF_VT3226) ||
472 (priv->rf_type == RF_VT3342A0)) {
473 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
474 MAC_REG_ITRTMSET, 0x23);
475 vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
476 } else if (priv->rf_type == RF_VT3226D0) {
477 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
478 MAC_REG_ITRTMSET, 0x11);
479 vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
482 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
483 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
485 vnt_rf_table_download(priv);
487 /* Fix for TX USB resets from vendors driver */
488 vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
489 MESSAGE_REQUEST_MEM, sizeof(data), &data);
491 data |= 0x2;
493 vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
494 MESSAGE_REQUEST_MEM, sizeof(data), &data);
496 return true;
500 * Description: Set ShortSlotTime mode
502 * Parameters:
503 * In:
504 * priv - Device Structure
505 * Out:
506 * none
508 * Return Value: none
511 void vnt_set_short_slot_time(struct vnt_private *priv)
513 u8 bb_vga = 0;
515 if (priv->short_slot_time)
516 priv->bb_rx_conf &= 0xdf;
517 else
518 priv->bb_rx_conf |= 0x20;
520 vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
522 if (bb_vga == priv->bb_vga[0])
523 priv->bb_rx_conf |= 0x20;
525 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
528 void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
530 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
532 /* patch for 3253B0 Baseband with Cardbus module */
533 if (priv->short_slot_time)
534 priv->bb_rx_conf &= 0xdf; /* 1101 1111 */
535 else
536 priv->bb_rx_conf |= 0x20; /* 0010 0000 */
538 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
542 * Description: vnt_set_deep_sleep
544 * Parameters:
545 * In:
546 * priv - Device Structure
547 * Out:
548 * none
550 * Return Value: none
553 void vnt_set_deep_sleep(struct vnt_private *priv)
555 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */
556 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */
559 void vnt_exit_deep_sleep(struct vnt_private *priv)
561 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */
562 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */
565 void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
567 u8 cr_201 = 0x0, cr_206 = 0x0;
568 u8 ed_inx = priv->bb_pre_ed_index;
570 switch (priv->rf_type) {
571 case RF_AL2230:
572 case RF_AL2230S:
573 case RF_AIROHA7230:
574 if (scanning) { /* Max sensitivity */
575 ed_inx = 0;
576 cr_206 = 0x30;
577 break;
580 if (priv->bb_pre_ed_rssi <= 45) {
581 ed_inx = 20;
582 cr_201 = 0xff;
583 } else if (priv->bb_pre_ed_rssi <= 46) {
584 ed_inx = 19;
585 cr_201 = 0x1a;
586 } else if (priv->bb_pre_ed_rssi <= 47) {
587 ed_inx = 18;
588 cr_201 = 0x15;
589 } else if (priv->bb_pre_ed_rssi <= 49) {
590 ed_inx = 17;
591 cr_201 = 0xe;
592 } else if (priv->bb_pre_ed_rssi <= 51) {
593 ed_inx = 16;
594 cr_201 = 0x9;
595 } else if (priv->bb_pre_ed_rssi <= 53) {
596 ed_inx = 15;
597 cr_201 = 0x6;
598 } else if (priv->bb_pre_ed_rssi <= 55) {
599 ed_inx = 14;
600 cr_201 = 0x3;
601 } else if (priv->bb_pre_ed_rssi <= 56) {
602 ed_inx = 13;
603 cr_201 = 0x2;
604 cr_206 = 0xa0;
605 } else if (priv->bb_pre_ed_rssi <= 57) {
606 ed_inx = 12;
607 cr_201 = 0x2;
608 cr_206 = 0x20;
609 } else if (priv->bb_pre_ed_rssi <= 58) {
610 ed_inx = 11;
611 cr_201 = 0x1;
612 cr_206 = 0xa0;
613 } else if (priv->bb_pre_ed_rssi <= 59) {
614 ed_inx = 10;
615 cr_201 = 0x1;
616 cr_206 = 0x54;
617 } else if (priv->bb_pre_ed_rssi <= 60) {
618 ed_inx = 9;
619 cr_201 = 0x1;
620 cr_206 = 0x18;
621 } else if (priv->bb_pre_ed_rssi <= 61) {
622 ed_inx = 8;
623 cr_206 = 0xe3;
624 } else if (priv->bb_pre_ed_rssi <= 62) {
625 ed_inx = 7;
626 cr_206 = 0xb9;
627 } else if (priv->bb_pre_ed_rssi <= 63) {
628 ed_inx = 6;
629 cr_206 = 0x93;
630 } else if (priv->bb_pre_ed_rssi <= 64) {
631 ed_inx = 5;
632 cr_206 = 0x79;
633 } else if (priv->bb_pre_ed_rssi <= 65) {
634 ed_inx = 4;
635 cr_206 = 0x62;
636 } else if (priv->bb_pre_ed_rssi <= 66) {
637 ed_inx = 3;
638 cr_206 = 0x51;
639 } else if (priv->bb_pre_ed_rssi <= 67) {
640 ed_inx = 2;
641 cr_206 = 0x43;
642 } else if (priv->bb_pre_ed_rssi <= 68) {
643 ed_inx = 1;
644 cr_206 = 0x36;
645 } else {
646 ed_inx = 0;
647 cr_206 = 0x30;
649 break;
651 case RF_VT3226:
652 case RF_VT3226D0:
653 if (scanning) { /* Max sensitivity */
654 ed_inx = 0;
655 cr_206 = 0x24;
656 break;
659 if (priv->bb_pre_ed_rssi <= 41) {
660 ed_inx = 22;
661 cr_201 = 0xff;
662 } else if (priv->bb_pre_ed_rssi <= 42) {
663 ed_inx = 21;
664 cr_201 = 0x36;
665 } else if (priv->bb_pre_ed_rssi <= 43) {
666 ed_inx = 20;
667 cr_201 = 0x26;
668 } else if (priv->bb_pre_ed_rssi <= 45) {
669 ed_inx = 19;
670 cr_201 = 0x18;
671 } else if (priv->bb_pre_ed_rssi <= 47) {
672 ed_inx = 18;
673 cr_201 = 0x11;
674 } else if (priv->bb_pre_ed_rssi <= 49) {
675 ed_inx = 17;
676 cr_201 = 0xa;
677 } else if (priv->bb_pre_ed_rssi <= 51) {
678 ed_inx = 16;
679 cr_201 = 0x7;
680 } else if (priv->bb_pre_ed_rssi <= 53) {
681 ed_inx = 15;
682 cr_201 = 0x4;
683 } else if (priv->bb_pre_ed_rssi <= 55) {
684 ed_inx = 14;
685 cr_201 = 0x2;
686 cr_206 = 0xc0;
687 } else if (priv->bb_pre_ed_rssi <= 56) {
688 ed_inx = 13;
689 cr_201 = 0x2;
690 cr_206 = 0x30;
691 } else if (priv->bb_pre_ed_rssi <= 57) {
692 ed_inx = 12;
693 cr_201 = 0x1;
694 cr_206 = 0xb0;
695 } else if (priv->bb_pre_ed_rssi <= 58) {
696 ed_inx = 11;
697 cr_201 = 0x1;
698 cr_206 = 0x70;
699 } else if (priv->bb_pre_ed_rssi <= 59) {
700 ed_inx = 10;
701 cr_201 = 0x1;
702 cr_206 = 0x30;
703 } else if (priv->bb_pre_ed_rssi <= 60) {
704 ed_inx = 9;
705 cr_206 = 0xea;
706 } else if (priv->bb_pre_ed_rssi <= 61) {
707 ed_inx = 8;
708 cr_206 = 0xc0;
709 } else if (priv->bb_pre_ed_rssi <= 62) {
710 ed_inx = 7;
711 cr_206 = 0x9c;
712 } else if (priv->bb_pre_ed_rssi <= 63) {
713 ed_inx = 6;
714 cr_206 = 0x80;
715 } else if (priv->bb_pre_ed_rssi <= 64) {
716 ed_inx = 5;
717 cr_206 = 0x68;
718 } else if (priv->bb_pre_ed_rssi <= 65) {
719 ed_inx = 4;
720 cr_206 = 0x52;
721 } else if (priv->bb_pre_ed_rssi <= 66) {
722 ed_inx = 3;
723 cr_206 = 0x43;
724 } else if (priv->bb_pre_ed_rssi <= 67) {
725 ed_inx = 2;
726 cr_206 = 0x36;
727 } else if (priv->bb_pre_ed_rssi <= 68) {
728 ed_inx = 1;
729 cr_206 = 0x2d;
730 } else {
731 ed_inx = 0;
732 cr_206 = 0x24;
734 break;
736 case RF_VT3342A0:
737 if (scanning) { /* need Max sensitivity */
738 ed_inx = 0;
739 cr_206 = 0x38;
740 break;
743 if (priv->bb_pre_ed_rssi <= 41) {
744 ed_inx = 20;
745 cr_201 = 0xff;
746 } else if (priv->bb_pre_ed_rssi <= 42) {
747 ed_inx = 19;
748 cr_201 = 0x36;
749 } else if (priv->bb_pre_ed_rssi <= 43) {
750 ed_inx = 18;
751 cr_201 = 0x26;
752 } else if (priv->bb_pre_ed_rssi <= 45) {
753 ed_inx = 17;
754 cr_201 = 0x18;
755 } else if (priv->bb_pre_ed_rssi <= 47) {
756 ed_inx = 16;
757 cr_201 = 0x11;
758 } else if (priv->bb_pre_ed_rssi <= 49) {
759 ed_inx = 15;
760 cr_201 = 0xa;
761 } else if (priv->bb_pre_ed_rssi <= 51) {
762 ed_inx = 14;
763 cr_201 = 0x7;
764 } else if (priv->bb_pre_ed_rssi <= 53) {
765 ed_inx = 13;
766 cr_201 = 0x4;
767 } else if (priv->bb_pre_ed_rssi <= 55) {
768 ed_inx = 12;
769 cr_201 = 0x2;
770 cr_206 = 0xc0;
771 } else if (priv->bb_pre_ed_rssi <= 56) {
772 ed_inx = 11;
773 cr_201 = 0x2;
774 cr_206 = 0x30;
775 } else if (priv->bb_pre_ed_rssi <= 57) {
776 ed_inx = 10;
777 cr_201 = 0x1;
778 cr_206 = 0xb0;
779 } else if (priv->bb_pre_ed_rssi <= 58) {
780 ed_inx = 9;
781 cr_201 = 0x1;
782 cr_206 = 0x70;
783 } else if (priv->bb_pre_ed_rssi <= 59) {
784 ed_inx = 8;
785 cr_201 = 0x1;
786 cr_206 = 0x30;
787 } else if (priv->bb_pre_ed_rssi <= 60) {
788 ed_inx = 7;
789 cr_206 = 0xea;
790 } else if (priv->bb_pre_ed_rssi <= 61) {
791 ed_inx = 6;
792 cr_206 = 0xc0;
793 } else if (priv->bb_pre_ed_rssi <= 62) {
794 ed_inx = 5;
795 cr_206 = 0x9c;
796 } else if (priv->bb_pre_ed_rssi <= 63) {
797 ed_inx = 4;
798 cr_206 = 0x80;
799 } else if (priv->bb_pre_ed_rssi <= 64) {
800 ed_inx = 3;
801 cr_206 = 0x68;
802 } else if (priv->bb_pre_ed_rssi <= 65) {
803 ed_inx = 2;
804 cr_206 = 0x52;
805 } else if (priv->bb_pre_ed_rssi <= 66) {
806 ed_inx = 1;
807 cr_206 = 0x43;
808 } else {
809 ed_inx = 0;
810 cr_206 = 0x38;
812 break;
815 if (ed_inx == priv->bb_pre_ed_index && !scanning)
816 return;
818 priv->bb_pre_ed_index = ed_inx;
820 dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n",
821 __func__, priv->bb_pre_ed_rssi);
823 if (!cr_201 && !cr_206)
824 return;
826 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201);
827 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206);