blob: e5be261f2e69cb11319282d46e4f567257ab6102 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 *
20 * File: baseband.c
21 *
22 * Purpose: Implement functions to access baseband
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Jun. 5, 2002
27 *
28 * Functions:
Peter Senna Tschudin618d7d02014-07-15 23:23:25 +020029 * 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
Malcolm Priestley75341802014-07-16 22:21:53 +010032 * vnt_vt3184_init - VIA VT3184 baseband chip init code
Forest Bond92b96792009-06-13 07:38:31 -040033 *
34 * Revision History:
35 *
36 *
37 */
38
Forest Bond92b96792009-06-13 07:38:31 -040039#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040040#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "rf.h"
Malcolm Priestley62c85262014-05-26 13:59:07 +010042#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040043
Malcolm Priestley170ce6d2014-07-12 20:12:43 +010044static u8 vnt_vt3184_agc[] = {
Malcolm Priestley4fd6e9f2014-07-12 20:12:42 +010045 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 */
Forest Bond92b96792009-06-13 07:38:31 -040053};
54
Malcolm Priestleyab48ab22014-07-12 20:12:44 +010055static u8 vnt_vt3184_al2230[] = {
Malcolm Priestley4fd6e9f2014-07-12 20:12:42 +010056 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 */
Forest Bond92b96792009-06-13 07:38:31 -040088};
89
Peter Senna Tschudin618d7d02014-07-15 23:23:25 +020090/* {{RobertYu:20060515, new BB setting for VT3226D0 */
Malcolm Priestley0a16b632014-07-12 20:12:45 +010091static u8 vnt_vt3184_vt3226d0[] = {
Malcolm Priestley4fd6e9f2014-07-12 20:12:42 +010092 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 */
Forest Bond92b96792009-06-13 07:38:31 -0400124};
125
Malcolm Priestley231c6f12014-07-16 22:21:51 +0100126static const u16 vnt_frame_time[MAX_RATE] = {
Peter Senna Tschudin42b138d2014-07-15 23:23:26 +0200127 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216
128};
Forest Bond92b96792009-06-13 07:38:31 -0400129
Forest Bond92b96792009-06-13 07:38:31 -0400130/*
Forest Bond92b96792009-06-13 07:38:31 -0400131 * Description: Calculate data frame transmitting time
132 *
133 * Parameters:
134 * In:
Malcolm Priestley030ede12014-05-19 20:33:00 +0100135 * preamble_type - Preamble Type
136 * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
137 * frame_length - Baseband Type
Malcolm Priestley3b5a89c2014-05-19 20:32:59 +0100138 * tx_rate - Tx Rate
Forest Bond92b96792009-06-13 07:38:31 -0400139 * Out:
140 *
141 * Return Value: FrameTime
142 *
143 */
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100144unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type,
Malcolm Priestley030ede12014-05-19 20:33:00 +0100145 unsigned int frame_length, u16 tx_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400146{
Malcolm Priestley030ede12014-05-19 20:33:00 +0100147 unsigned int frame_time;
148 unsigned int preamble;
149 unsigned int tmp;
150 unsigned int rate = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400151
Malcolm Priestley3b5a89c2014-05-19 20:32:59 +0100152 if (tx_rate > RATE_54M)
Malcolm Priestley4d999522014-05-19 20:32:58 +0100153 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400154
Malcolm Priestley231c6f12014-07-16 22:21:51 +0100155 rate = (unsigned int)vnt_frame_time[tx_rate];
Forest Bond92b96792009-06-13 07:38:31 -0400156
Malcolm Priestley3b5a89c2014-05-19 20:32:59 +0100157 if (tx_rate <= 3) {
Malcolm Priestley030ede12014-05-19 20:33:00 +0100158 if (preamble_type == 1)
159 preamble = 96;
Malcolm Priestley4d999522014-05-19 20:32:58 +0100160 else
Malcolm Priestley030ede12014-05-19 20:33:00 +0100161 preamble = 192;
Forest Bond92b96792009-06-13 07:38:31 -0400162
Malcolm Priestley030ede12014-05-19 20:33:00 +0100163 frame_time = (frame_length * 80) / rate;
164 tmp = (frame_time * rate) / 80;
Forest Bond92b96792009-06-13 07:38:31 -0400165
Malcolm Priestley030ede12014-05-19 20:33:00 +0100166 if (frame_length != tmp)
167 frame_time++;
Malcolm Priestley4d999522014-05-19 20:32:58 +0100168
Malcolm Priestley030ede12014-05-19 20:33:00 +0100169 return preamble + frame_time;
Malcolm Priestley4d999522014-05-19 20:32:58 +0100170 }
Rajbinder Brarb377ed42014-09-17 21:27:03 +0530171 frame_time = (frame_length * 8 + 22) / rate;
172 tmp = ((frame_time * rate) - 22) / 8;
173
174 if (frame_length != tmp)
175 frame_time++;
176
177 frame_time = frame_time * 4;
178
179 if (pkt_type != PK_TYPE_11A)
180 frame_time += 6;
181 return 20 + frame_time;
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
184/*
Justin P. Mattocka0a1f612012-08-26 08:16:43 -0700185 * Description: Calculate Length, Service, and Signal fields of Phy for Tx
Forest Bond92b96792009-06-13 07:38:31 -0400186 *
187 * Parameters:
188 * In:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100189 * priv - Device Structure
190 * frame_length - Tx Frame Length
191 * tx_rate - Tx Rate
Forest Bond92b96792009-06-13 07:38:31 -0400192 * Out:
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100193 * struct vnt_phy_field *phy
Peter Senna Tschudin618d7d02014-07-15 23:23:25 +0200194 * - pointer to Phy Length field
195 * - pointer to Phy Service field
196 * - pointer to Phy Signal field
Forest Bond92b96792009-06-13 07:38:31 -0400197 *
198 * Return Value: none
199 *
200 */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100201void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100202 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy)
Forest Bond92b96792009-06-13 07:38:31 -0400203{
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100204 u32 bit_count;
205 u32 count = 0;
206 u32 tmp;
207 int ext_bit;
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100208 u8 preamble_type = priv->preamble_type;
Forest Bond92b96792009-06-13 07:38:31 -0400209
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100210 bit_count = frame_length * 8;
211 ext_bit = false;
Forest Bond92b96792009-06-13 07:38:31 -0400212
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100213 switch (tx_rate) {
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100214 case RATE_1M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100215 count = bit_count;
Forest Bond92b96792009-06-13 07:38:31 -0400216
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100217 phy->signal = 0x00;
Forest Bond92b96792009-06-13 07:38:31 -0400218
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100219 break;
220 case RATE_2M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100221 count = bit_count / 2;
Forest Bond92b96792009-06-13 07:38:31 -0400222
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100223 if (preamble_type == 1)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100224 phy->signal = 0x09;
225 else
226 phy->signal = 0x01;
Forest Bond92b96792009-06-13 07:38:31 -0400227
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100228 break;
229 case RATE_5M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100230 count = (bit_count * 10) / 55;
231 tmp = (count * 55) / 10;
Forest Bond92b96792009-06-13 07:38:31 -0400232
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100233 if (tmp != bit_count)
234 count++;
Forest Bond92b96792009-06-13 07:38:31 -0400235
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100236 if (preamble_type == 1)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100237 phy->signal = 0x0a;
238 else
239 phy->signal = 0x02;
Forest Bond92b96792009-06-13 07:38:31 -0400240
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100241 break;
242 case RATE_11M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100243 count = bit_count / 11;
244 tmp = count * 11;
Forest Bond92b96792009-06-13 07:38:31 -0400245
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100246 if (tmp != bit_count) {
247 count++;
Forest Bond92b96792009-06-13 07:38:31 -0400248
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100249 if ((bit_count - tmp) <= 3)
250 ext_bit = true;
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100251 }
Forest Bond92b96792009-06-13 07:38:31 -0400252
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100253 if (preamble_type == 1)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100254 phy->signal = 0x0b;
255 else
256 phy->signal = 0x03;
Forest Bond92b96792009-06-13 07:38:31 -0400257
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100258 break;
259 case RATE_6M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100260 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100261 phy->signal = 0x9b;
262 else
263 phy->signal = 0x8b;
Forest Bond92b96792009-06-13 07:38:31 -0400264
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100265 break;
266 case RATE_9M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100267 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100268 phy->signal = 0x9f;
269 else
270 phy->signal = 0x8f;
271
272 break;
273 case RATE_12M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100274 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100275 phy->signal = 0x9a;
276 else
277 phy->signal = 0x8a;
278
279 break;
280 case RATE_18M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100281 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100282 phy->signal = 0x9e;
283 else
284 phy->signal = 0x8e;
285
286 break;
287 case RATE_24M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100288 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100289 phy->signal = 0x99;
290 else
291 phy->signal = 0x89;
292
293 break;
294 case RATE_36M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100295 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100296 phy->signal = 0x9d;
297 else
298 phy->signal = 0x8d;
299
300 break;
301 case RATE_48M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100302 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100303 phy->signal = 0x98;
304 else
305 phy->signal = 0x88;
306
307 break;
308 case RATE_54M:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100309 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100310 phy->signal = 0x9c;
311 else
312 phy->signal = 0x8c;
313 break;
314 default:
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100315 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleya4fb3e72014-05-19 20:33:01 +0100316 phy->signal = 0x9c;
317 else
318 phy->signal = 0x8c;
319 break;
320 }
Forest Bond92b96792009-06-13 07:38:31 -0400321
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100322 if (pkt_type == PK_TYPE_11B) {
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100323 phy->service = 0x00;
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100324 if (ext_bit)
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100325 phy->service |= 0x80;
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100326 phy->len = cpu_to_le16((u16)count);
Malcolm Priestley4ac306e2013-08-20 22:49:26 +0100327 } else {
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100328 phy->service = 0x00;
Malcolm Priestleya1ff5432014-05-19 20:33:02 +0100329 phy->len = cpu_to_le16((u16)frame_length);
Malcolm Priestley4ac306e2013-08-20 22:49:26 +0100330 }
Forest Bond92b96792009-06-13 07:38:31 -0400331}
332
Forest Bond92b96792009-06-13 07:38:31 -0400333/*
334 * Description: Set Antenna mode
335 *
336 * Parameters:
337 * In:
Malcolm Priestley53dab322014-05-19 20:33:04 +0100338 * priv - Device Structure
339 * antenna_mode - Antenna Mode
Forest Bond92b96792009-06-13 07:38:31 -0400340 * Out:
341 * none
342 *
343 * Return Value: none
344 *
345 */
Malcolm Priestley41868bf2014-07-16 22:21:52 +0100346void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
Forest Bond92b96792009-06-13 07:38:31 -0400347{
Malcolm Priestley53dab322014-05-19 20:33:04 +0100348 switch (antenna_mode) {
Malcolm Priestleyefe40c02014-05-19 20:33:03 +0100349 case ANT_TXA:
350 case ANT_TXB:
351 break;
352 case ANT_RXA:
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100353 priv->bb_rx_conf &= 0xFC;
Malcolm Priestleyefe40c02014-05-19 20:33:03 +0100354 break;
355 case ANT_RXB:
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100356 priv->bb_rx_conf &= 0xFE;
357 priv->bb_rx_conf |= 0x02;
Malcolm Priestleyefe40c02014-05-19 20:33:03 +0100358 break;
359 }
Forest Bond92b96792009-06-13 07:38:31 -0400360
Malcolm Priestley1390b022014-05-26 13:59:01 +0100361 vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
Malcolm Priestley53dab322014-05-19 20:33:04 +0100362 (u16)antenna_mode, 0, 0, NULL);
Forest Bond92b96792009-06-13 07:38:31 -0400363}
364
365/*
366 * Description: Set Antenna mode
367 *
368 * Parameters:
369 * In:
370 * pDevice - Device Structure
371 * byAntennaMode - Antenna Mode
372 * Out:
373 * none
374 *
375 * Return Value: none
376 *
377 */
Andres More6487c492010-08-02 20:51:57 -0300378
Malcolm Priestley75341802014-07-16 22:21:53 +0100379int vnt_vt3184_init(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400380{
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000381 int status;
Malcolm Priestley4237fe42014-05-25 21:36:26 +0100382 u16 length;
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000383 u8 *addr;
384 u8 *agc;
Malcolm Priestley4237fe42014-05-25 21:36:26 +0100385 u16 length_agc;
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000386 u8 array[256];
Malcolm Priestley9df68292013-11-07 21:49:04 +0000387 u8 data;
Forest Bond92b96792009-06-13 07:38:31 -0400388
Malcolm Priestley441c21c2014-05-26 13:59:02 +0100389 status = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000390 MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE,
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100391 priv->eeprom);
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000392 if (status != STATUS_SUCCESS)
393 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400394
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100395 priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE];
Forest Bond92b96792009-06-13 07:38:31 -0400396
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100397 dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type);
Forest Bond92b96792009-06-13 07:38:31 -0400398
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100399 if ((priv->rf_type == RF_AL2230) ||
400 (priv->rf_type == RF_AL2230S)) {
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100401 priv->bb_rx_conf = vnt_vt3184_al2230[10];
Malcolm Priestleyab48ab22014-07-12 20:12:44 +0100402 length = sizeof(vnt_vt3184_al2230);
403 addr = vnt_vt3184_al2230;
Malcolm Priestley170ce6d2014-07-12 20:12:43 +0100404 agc = vnt_vt3184_agc;
405 length_agc = sizeof(vnt_vt3184_agc);
Forest Bond92b96792009-06-13 07:38:31 -0400406
Malcolm Priestleyc37cbd32014-07-20 15:33:25 +0100407 priv->bb_vga[0] = 0x1C;
408 priv->bb_vga[1] = 0x10;
409 priv->bb_vga[2] = 0x0;
410 priv->bb_vga[3] = 0x0;
Malcolm Priestley975c89f2014-07-20 15:33:26 +0100411
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100412 } else if (priv->rf_type == RF_AIROHA7230) {
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100413 priv->bb_rx_conf = vnt_vt3184_al2230[10];
Malcolm Priestleyab48ab22014-07-12 20:12:44 +0100414 length = sizeof(vnt_vt3184_al2230);
415 addr = vnt_vt3184_al2230;
Malcolm Priestley170ce6d2014-07-12 20:12:43 +0100416 agc = vnt_vt3184_agc;
417 length_agc = sizeof(vnt_vt3184_agc);
Forest Bond92b96792009-06-13 07:38:31 -0400418
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000419 addr[0xd7] = 0x06;
Forest Bond92b96792009-06-13 07:38:31 -0400420
Malcolm Priestleyc37cbd32014-07-20 15:33:25 +0100421 priv->bb_vga[0] = 0x1c;
422 priv->bb_vga[1] = 0x10;
423 priv->bb_vga[2] = 0x0;
424 priv->bb_vga[3] = 0x0;
Malcolm Priestley975c89f2014-07-20 15:33:26 +0100425
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100426 } else if ((priv->rf_type == RF_VT3226) ||
427 (priv->rf_type == RF_VT3226D0)) {
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100428 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
Malcolm Priestley0a16b632014-07-12 20:12:45 +0100429 length = sizeof(vnt_vt3184_vt3226d0);
430 addr = vnt_vt3184_vt3226d0;
Malcolm Priestley170ce6d2014-07-12 20:12:43 +0100431 agc = vnt_vt3184_agc;
432 length_agc = sizeof(vnt_vt3184_agc);
Forest Bond92b96792009-06-13 07:38:31 -0400433
Malcolm Priestleyc37cbd32014-07-20 15:33:25 +0100434 priv->bb_vga[0] = 0x20;
435 priv->bb_vga[1] = 0x10;
436 priv->bb_vga[2] = 0x0;
437 priv->bb_vga[3] = 0x0;
Malcolm Priestley975c89f2014-07-20 15:33:26 +0100438
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000439 /* Fix VT3226 DFC system timing issue */
Peter Senna Tschudin495e2be2014-07-14 21:15:29 +0200440 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
441 SOFTPWRCTL_RFLEOPT);
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100442 } else if (priv->rf_type == RF_VT3342A0) {
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100443 priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
Malcolm Priestley0a16b632014-07-12 20:12:45 +0100444 length = sizeof(vnt_vt3184_vt3226d0);
445 addr = vnt_vt3184_vt3226d0;
Malcolm Priestley170ce6d2014-07-12 20:12:43 +0100446 agc = vnt_vt3184_agc;
447 length_agc = sizeof(vnt_vt3184_agc);
Forest Bond92b96792009-06-13 07:38:31 -0400448
Malcolm Priestleyc37cbd32014-07-20 15:33:25 +0100449 priv->bb_vga[0] = 0x20;
450 priv->bb_vga[1] = 0x10;
451 priv->bb_vga[2] = 0x0;
452 priv->bb_vga[3] = 0x0;
Malcolm Priestley975c89f2014-07-20 15:33:26 +0100453
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000454 /* Fix VT3226 DFC system timing issue */
Peter Senna Tschudin42b138d2014-07-15 23:23:26 +0200455 vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
456 SOFTPWRCTL_RFLEOPT);
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000457 } else {
458 return true;
459 }
Forest Bond92b96792009-06-13 07:38:31 -0400460
Malcolm Priestley4237fe42014-05-25 21:36:26 +0100461 memcpy(array, addr, length);
Forest Bond92b96792009-06-13 07:38:31 -0400462
Malcolm Priestley1390b022014-05-26 13:59:01 +0100463 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
Malcolm Priestley4237fe42014-05-25 21:36:26 +0100464 MESSAGE_REQUEST_BBREG, length, array);
Forest Bond92b96792009-06-13 07:38:31 -0400465
Malcolm Priestley4237fe42014-05-25 21:36:26 +0100466 memcpy(array, agc, length_agc);
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000467
Malcolm Priestley1390b022014-05-26 13:59:01 +0100468 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
Malcolm Priestley4237fe42014-05-25 21:36:26 +0100469 MESSAGE_REQUEST_BBAGC, length_agc, array);
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000470
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100471 if ((priv->rf_type == RF_VT3226) ||
472 (priv->rf_type == RF_VT3342A0)) {
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100473 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000474 MAC_REG_ITRTMSET, 0x23);
Malcolm Priestley36957532014-05-31 11:50:42 +0100475 vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100476 } else if (priv->rf_type == RF_VT3226D0) {
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100477 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000478 MAC_REG_ITRTMSET, 0x11);
Malcolm Priestley36957532014-05-31 11:50:42 +0100479 vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000480 }
481
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100482 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
483 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000484
Malcolm Priestleyc49d7552014-05-27 21:05:24 +0100485 vnt_rf_table_download(priv);
Malcolm Priestley9df68292013-11-07 21:49:04 +0000486
487 /* Fix for TX USB resets from vendors driver */
Malcolm Priestley441c21c2014-05-26 13:59:02 +0100488 vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
Malcolm Priestley9df68292013-11-07 21:49:04 +0000489 MESSAGE_REQUEST_MEM, sizeof(data), &data);
490
491 data |= 0x2;
492
Malcolm Priestley1390b022014-05-26 13:59:01 +0100493 vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
Malcolm Priestley9df68292013-11-07 21:49:04 +0000494 MESSAGE_REQUEST_MEM, sizeof(data), &data);
495
Malcolm Priestley9b89b042013-12-07 11:40:28 +0000496 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400497}
498
Forest Bond92b96792009-06-13 07:38:31 -0400499/*
500 * Description: Set ShortSlotTime mode
501 *
502 * Parameters:
503 * In:
Malcolm Priestley4bdb3122014-05-19 20:33:05 +0100504 * priv - Device Structure
Forest Bond92b96792009-06-13 07:38:31 -0400505 * Out:
506 * none
507 *
508 * Return Value: none
509 *
510 */
Malcolm Priestley3c956cc2014-07-16 22:21:54 +0100511void vnt_set_short_slot_time(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400512{
Malcolm Priestley4bdb3122014-05-19 20:33:05 +0100513 u8 bb_vga = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400514
Malcolm Priestleya641c9e2014-07-20 15:33:21 +0100515 if (priv->short_slot_time)
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100516 priv->bb_rx_conf &= 0xdf;
Marcos Paulo de Souzaf001d7e2011-11-30 00:19:08 -0200517 else
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100518 priv->bb_rx_conf |= 0x20;
Forest Bond92b96792009-06-13 07:38:31 -0400519
Malcolm Priestley53742902014-05-26 13:59:06 +0100520 vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
Forest Bond92b96792009-06-13 07:38:31 -0400521
Malcolm Priestleyc37cbd32014-07-20 15:33:25 +0100522 if (bb_vga == priv->bb_vga[0])
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100523 priv->bb_rx_conf |= 0x20;
Malcolm Priestley4bdb3122014-05-19 20:33:05 +0100524
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100525 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
Forest Bond92b96792009-06-13 07:38:31 -0400526}
527
Malcolm Priestleyde8690a2014-07-16 22:21:55 +0100528void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
Forest Bond92b96792009-06-13 07:38:31 -0400529{
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100530 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
Forest Bond92b96792009-06-13 07:38:31 -0400531
Malcolm Priestley15897f62014-05-19 20:33:06 +0100532 /* patch for 3253B0 Baseband with Cardbus module */
Malcolm Priestleya641c9e2014-07-20 15:33:21 +0100533 if (priv->short_slot_time)
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100534 priv->bb_rx_conf &= 0xdf; /* 1101 1111 */
Marcos Paulo de Souzaf001d7e2011-11-30 00:19:08 -0200535 else
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100536 priv->bb_rx_conf |= 0x20; /* 0010 0000 */
Marcos Paulo de Souzaf001d7e2011-11-30 00:19:08 -0200537
Malcolm Priestleycd5856a2014-07-19 12:30:08 +0100538 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
Forest Bond92b96792009-06-13 07:38:31 -0400539}
540
Forest Bond92b96792009-06-13 07:38:31 -0400541/*
Malcolm Priestleye8e072d2014-07-16 22:21:56 +0100542 * Description: vnt_set_deep_sleep
Forest Bond92b96792009-06-13 07:38:31 -0400543 *
544 * Parameters:
545 * In:
Malcolm Priestley07c116f22014-05-19 20:33:07 +0100546 * priv - Device Structure
Forest Bond92b96792009-06-13 07:38:31 -0400547 * Out:
548 * none
549 *
550 * Return Value: none
551 *
552 */
Malcolm Priestleye8e072d2014-07-16 22:21:56 +0100553void vnt_set_deep_sleep(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400554{
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100555 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */
556 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */
Forest Bond92b96792009-06-13 07:38:31 -0400557}
558
Malcolm Priestley0e951752014-07-16 22:21:57 +0100559void vnt_exit_deep_sleep(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400560{
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100561 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */
562 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */
Forest Bond92b96792009-06-13 07:38:31 -0400563}
564
Malcolm Priestley80dcc0a2014-07-16 22:21:58 +0100565void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
Forest Bond92b96792009-06-13 07:38:31 -0400566{
Malcolm Priestley7794dad2014-05-19 20:33:10 +0100567 u8 cr_201 = 0x0, cr_206 = 0x0;
Malcolm Priestley43fd1922014-07-20 15:33:28 +0100568 u8 ed_inx = priv->bb_pre_ed_index;
Forest Bond92b96792009-06-13 07:38:31 -0400569
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100570 switch (priv->rf_type) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100571 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;
578 }
Forest Bond92b96792009-06-13 07:38:31 -0400579
Malcolm Priestley12687222014-07-20 15:33:27 +0100580 if (priv->bb_pre_ed_rssi <= 45) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100581 ed_inx = 20;
582 cr_201 = 0xff;
Malcolm Priestley12687222014-07-20 15:33:27 +0100583 } else if (priv->bb_pre_ed_rssi <= 46) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100584 ed_inx = 19;
585 cr_201 = 0x1a;
Malcolm Priestley12687222014-07-20 15:33:27 +0100586 } else if (priv->bb_pre_ed_rssi <= 47) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100587 ed_inx = 18;
588 cr_201 = 0x15;
Malcolm Priestley12687222014-07-20 15:33:27 +0100589 } else if (priv->bb_pre_ed_rssi <= 49) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100590 ed_inx = 17;
591 cr_201 = 0xe;
Malcolm Priestley12687222014-07-20 15:33:27 +0100592 } else if (priv->bb_pre_ed_rssi <= 51) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100593 ed_inx = 16;
594 cr_201 = 0x9;
Malcolm Priestley12687222014-07-20 15:33:27 +0100595 } else if (priv->bb_pre_ed_rssi <= 53) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100596 ed_inx = 15;
597 cr_201 = 0x6;
Malcolm Priestley12687222014-07-20 15:33:27 +0100598 } else if (priv->bb_pre_ed_rssi <= 55) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100599 ed_inx = 14;
600 cr_201 = 0x3;
Malcolm Priestley12687222014-07-20 15:33:27 +0100601 } else if (priv->bb_pre_ed_rssi <= 56) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100602 ed_inx = 13;
603 cr_201 = 0x2;
604 cr_206 = 0xa0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100605 } else if (priv->bb_pre_ed_rssi <= 57) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100606 ed_inx = 12;
607 cr_201 = 0x2;
608 cr_206 = 0x20;
Malcolm Priestley12687222014-07-20 15:33:27 +0100609 } else if (priv->bb_pre_ed_rssi <= 58) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100610 ed_inx = 11;
611 cr_201 = 0x1;
612 cr_206 = 0xa0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100613 } else if (priv->bb_pre_ed_rssi <= 59) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100614 ed_inx = 10;
615 cr_201 = 0x1;
616 cr_206 = 0x54;
Malcolm Priestley12687222014-07-20 15:33:27 +0100617 } else if (priv->bb_pre_ed_rssi <= 60) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100618 ed_inx = 9;
619 cr_201 = 0x1;
620 cr_206 = 0x18;
Malcolm Priestley12687222014-07-20 15:33:27 +0100621 } else if (priv->bb_pre_ed_rssi <= 61) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100622 ed_inx = 8;
623 cr_206 = 0xe3;
Malcolm Priestley12687222014-07-20 15:33:27 +0100624 } else if (priv->bb_pre_ed_rssi <= 62) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100625 ed_inx = 7;
626 cr_206 = 0xb9;
Malcolm Priestley12687222014-07-20 15:33:27 +0100627 } else if (priv->bb_pre_ed_rssi <= 63) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100628 ed_inx = 6;
629 cr_206 = 0x93;
Malcolm Priestley12687222014-07-20 15:33:27 +0100630 } else if (priv->bb_pre_ed_rssi <= 64) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100631 ed_inx = 5;
632 cr_206 = 0x79;
Malcolm Priestley12687222014-07-20 15:33:27 +0100633 } else if (priv->bb_pre_ed_rssi <= 65) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100634 ed_inx = 4;
635 cr_206 = 0x62;
Malcolm Priestley12687222014-07-20 15:33:27 +0100636 } else if (priv->bb_pre_ed_rssi <= 66) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100637 ed_inx = 3;
638 cr_206 = 0x51;
Malcolm Priestley12687222014-07-20 15:33:27 +0100639 } else if (priv->bb_pre_ed_rssi <= 67) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100640 ed_inx = 2;
641 cr_206 = 0x43;
Malcolm Priestley12687222014-07-20 15:33:27 +0100642 } else if (priv->bb_pre_ed_rssi <= 68) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100643 ed_inx = 1;
644 cr_206 = 0x36;
645 } else {
646 ed_inx = 0;
647 cr_206 = 0x30;
648 }
649 break;
Forest Bond92b96792009-06-13 07:38:31 -0400650
Malcolm Priestley19440262014-05-19 20:33:12 +0100651 case RF_VT3226:
652 case RF_VT3226D0:
653 if (scanning) { /* Max sensitivity */
654 ed_inx = 0;
655 cr_206 = 0x24;
656 break;
657 }
Forest Bond92b96792009-06-13 07:38:31 -0400658
Malcolm Priestley12687222014-07-20 15:33:27 +0100659 if (priv->bb_pre_ed_rssi <= 41) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100660 ed_inx = 22;
661 cr_201 = 0xff;
Malcolm Priestley12687222014-07-20 15:33:27 +0100662 } else if (priv->bb_pre_ed_rssi <= 42) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100663 ed_inx = 21;
664 cr_201 = 0x36;
Malcolm Priestley12687222014-07-20 15:33:27 +0100665 } else if (priv->bb_pre_ed_rssi <= 43) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100666 ed_inx = 20;
667 cr_201 = 0x26;
Malcolm Priestley12687222014-07-20 15:33:27 +0100668 } else if (priv->bb_pre_ed_rssi <= 45) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100669 ed_inx = 19;
670 cr_201 = 0x18;
Malcolm Priestley12687222014-07-20 15:33:27 +0100671 } else if (priv->bb_pre_ed_rssi <= 47) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100672 ed_inx = 18;
673 cr_201 = 0x11;
Malcolm Priestley12687222014-07-20 15:33:27 +0100674 } else if (priv->bb_pre_ed_rssi <= 49) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100675 ed_inx = 17;
676 cr_201 = 0xa;
Malcolm Priestley12687222014-07-20 15:33:27 +0100677 } else if (priv->bb_pre_ed_rssi <= 51) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100678 ed_inx = 16;
679 cr_201 = 0x7;
Malcolm Priestley12687222014-07-20 15:33:27 +0100680 } else if (priv->bb_pre_ed_rssi <= 53) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100681 ed_inx = 15;
682 cr_201 = 0x4;
Malcolm Priestley12687222014-07-20 15:33:27 +0100683 } else if (priv->bb_pre_ed_rssi <= 55) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100684 ed_inx = 14;
685 cr_201 = 0x2;
686 cr_206 = 0xc0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100687 } else if (priv->bb_pre_ed_rssi <= 56) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100688 ed_inx = 13;
689 cr_201 = 0x2;
690 cr_206 = 0x30;
Malcolm Priestley12687222014-07-20 15:33:27 +0100691 } else if (priv->bb_pre_ed_rssi <= 57) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100692 ed_inx = 12;
693 cr_201 = 0x1;
694 cr_206 = 0xb0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100695 } else if (priv->bb_pre_ed_rssi <= 58) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100696 ed_inx = 11;
697 cr_201 = 0x1;
698 cr_206 = 0x70;
Malcolm Priestley12687222014-07-20 15:33:27 +0100699 } else if (priv->bb_pre_ed_rssi <= 59) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100700 ed_inx = 10;
701 cr_201 = 0x1;
702 cr_206 = 0x30;
Malcolm Priestley12687222014-07-20 15:33:27 +0100703 } else if (priv->bb_pre_ed_rssi <= 60) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100704 ed_inx = 9;
705 cr_206 = 0xea;
Malcolm Priestley12687222014-07-20 15:33:27 +0100706 } else if (priv->bb_pre_ed_rssi <= 61) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100707 ed_inx = 8;
708 cr_206 = 0xc0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100709 } else if (priv->bb_pre_ed_rssi <= 62) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100710 ed_inx = 7;
711 cr_206 = 0x9c;
Malcolm Priestley12687222014-07-20 15:33:27 +0100712 } else if (priv->bb_pre_ed_rssi <= 63) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100713 ed_inx = 6;
714 cr_206 = 0x80;
Malcolm Priestley12687222014-07-20 15:33:27 +0100715 } else if (priv->bb_pre_ed_rssi <= 64) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100716 ed_inx = 5;
717 cr_206 = 0x68;
Malcolm Priestley12687222014-07-20 15:33:27 +0100718 } else if (priv->bb_pre_ed_rssi <= 65) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100719 ed_inx = 4;
720 cr_206 = 0x52;
Malcolm Priestley12687222014-07-20 15:33:27 +0100721 } else if (priv->bb_pre_ed_rssi <= 66) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100722 ed_inx = 3;
723 cr_206 = 0x43;
Malcolm Priestley12687222014-07-20 15:33:27 +0100724 } else if (priv->bb_pre_ed_rssi <= 67) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100725 ed_inx = 2;
726 cr_206 = 0x36;
Malcolm Priestley12687222014-07-20 15:33:27 +0100727 } else if (priv->bb_pre_ed_rssi <= 68) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100728 ed_inx = 1;
729 cr_206 = 0x2d;
730 } else {
731 ed_inx = 0;
732 cr_206 = 0x24;
733 }
734 break;
Forest Bond92b96792009-06-13 07:38:31 -0400735
Malcolm Priestley19440262014-05-19 20:33:12 +0100736 case RF_VT3342A0:
737 if (scanning) { /* need Max sensitivity */
738 ed_inx = 0;
739 cr_206 = 0x38;
740 break;
741 }
Forest Bond92b96792009-06-13 07:38:31 -0400742
Malcolm Priestley12687222014-07-20 15:33:27 +0100743 if (priv->bb_pre_ed_rssi <= 41) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100744 ed_inx = 20;
745 cr_201 = 0xff;
Malcolm Priestley12687222014-07-20 15:33:27 +0100746 } else if (priv->bb_pre_ed_rssi <= 42) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100747 ed_inx = 19;
748 cr_201 = 0x36;
Malcolm Priestley12687222014-07-20 15:33:27 +0100749 } else if (priv->bb_pre_ed_rssi <= 43) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100750 ed_inx = 18;
751 cr_201 = 0x26;
Malcolm Priestley12687222014-07-20 15:33:27 +0100752 } else if (priv->bb_pre_ed_rssi <= 45) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100753 ed_inx = 17;
754 cr_201 = 0x18;
Malcolm Priestley12687222014-07-20 15:33:27 +0100755 } else if (priv->bb_pre_ed_rssi <= 47) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100756 ed_inx = 16;
757 cr_201 = 0x11;
Malcolm Priestley12687222014-07-20 15:33:27 +0100758 } else if (priv->bb_pre_ed_rssi <= 49) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100759 ed_inx = 15;
760 cr_201 = 0xa;
Malcolm Priestley12687222014-07-20 15:33:27 +0100761 } else if (priv->bb_pre_ed_rssi <= 51) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100762 ed_inx = 14;
763 cr_201 = 0x7;
Malcolm Priestley12687222014-07-20 15:33:27 +0100764 } else if (priv->bb_pre_ed_rssi <= 53) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100765 ed_inx = 13;
766 cr_201 = 0x4;
Malcolm Priestley12687222014-07-20 15:33:27 +0100767 } else if (priv->bb_pre_ed_rssi <= 55) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100768 ed_inx = 12;
769 cr_201 = 0x2;
770 cr_206 = 0xc0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100771 } else if (priv->bb_pre_ed_rssi <= 56) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100772 ed_inx = 11;
773 cr_201 = 0x2;
774 cr_206 = 0x30;
Malcolm Priestley12687222014-07-20 15:33:27 +0100775 } else if (priv->bb_pre_ed_rssi <= 57) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100776 ed_inx = 10;
777 cr_201 = 0x1;
778 cr_206 = 0xb0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100779 } else if (priv->bb_pre_ed_rssi <= 58) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100780 ed_inx = 9;
781 cr_201 = 0x1;
782 cr_206 = 0x70;
Malcolm Priestley12687222014-07-20 15:33:27 +0100783 } else if (priv->bb_pre_ed_rssi <= 59) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100784 ed_inx = 8;
785 cr_201 = 0x1;
786 cr_206 = 0x30;
Malcolm Priestley12687222014-07-20 15:33:27 +0100787 } else if (priv->bb_pre_ed_rssi <= 60) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100788 ed_inx = 7;
789 cr_206 = 0xea;
Malcolm Priestley12687222014-07-20 15:33:27 +0100790 } else if (priv->bb_pre_ed_rssi <= 61) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100791 ed_inx = 6;
792 cr_206 = 0xc0;
Malcolm Priestley12687222014-07-20 15:33:27 +0100793 } else if (priv->bb_pre_ed_rssi <= 62) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100794 ed_inx = 5;
795 cr_206 = 0x9c;
Malcolm Priestley12687222014-07-20 15:33:27 +0100796 } else if (priv->bb_pre_ed_rssi <= 63) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100797 ed_inx = 4;
798 cr_206 = 0x80;
Malcolm Priestley12687222014-07-20 15:33:27 +0100799 } else if (priv->bb_pre_ed_rssi <= 64) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100800 ed_inx = 3;
801 cr_206 = 0x68;
Malcolm Priestley12687222014-07-20 15:33:27 +0100802 } else if (priv->bb_pre_ed_rssi <= 65) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100803 ed_inx = 2;
804 cr_206 = 0x52;
Malcolm Priestley12687222014-07-20 15:33:27 +0100805 } else if (priv->bb_pre_ed_rssi <= 66) {
Malcolm Priestley19440262014-05-19 20:33:12 +0100806 ed_inx = 1;
807 cr_206 = 0x43;
808 } else {
809 ed_inx = 0;
810 cr_206 = 0x38;
811 }
812 break;
Malcolm Priestley19440262014-05-19 20:33:12 +0100813 }
Forest Bond92b96792009-06-13 07:38:31 -0400814
Malcolm Priestley43fd1922014-07-20 15:33:28 +0100815 if (ed_inx == priv->bb_pre_ed_index && !scanning)
Malcolm Priestley6d5485a2014-05-19 20:33:11 +0100816 return;
817
Malcolm Priestley43fd1922014-07-20 15:33:28 +0100818 priv->bb_pre_ed_index = ed_inx;
Malcolm Priestley6d5485a2014-05-19 20:33:11 +0100819
Malcolm Priestley12687222014-07-20 15:33:27 +0100820 dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n",
821 __func__, priv->bb_pre_ed_rssi);
Malcolm Priestley0b7021f2014-05-19 20:33:09 +0100822
Malcolm Priestley7794dad2014-05-19 20:33:10 +0100823 if (!cr_201 && !cr_206)
824 return;
825
Malcolm Priestley285d58c2014-05-26 13:59:03 +0100826 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201);
827 vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206);
Forest Bond92b96792009-06-13 07:38:31 -0400828}
829